-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTscMsgQueue.cpp
More file actions
239 lines (210 loc) · 7.74 KB
/
Copy pathTscMsgQueue.cpp
File metadata and controls
239 lines (210 loc) · 7.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
//
// Created by sylar on 24-12-24.
//
/***************************************************************
Copyright(c) 2013 AITON. All rights reserved.
Author: AITON
FileName: TscMsgQueue.cpp
Date: 2013-1-1
Description: TSC消息队列处理类,包括各种TSC消息的接收和处理操作。
Version: V1.0
History:
***************************************************************/
#include "TscMsgQueue.h"
#include "ManaKernel.h"
#include "Dbinstance.h"
#include "ComFunc.h"
#include "WirelessButtons.h"
/**************************************************************
Function: CTscMsgQueue::CTscMsgQueue
Description: CTscMsgQueue类构造函数,初始化类
Input: 无
Output: 无
Return: 无
***************************************************************/
CTscMsgQueue::CTscMsgQueue()
{
Uint uiLogMaxId = 0;
Uint uiLogMinId = 0;
m_pMsgQue = ACE_Message_Queue_Factory<ACE_MT_SYNCH>::create_static_message_queue();
(CDbInstance::m_cGbtTscDb).GetLogMaxMin(&uiLogMaxId,&uiLogMinId);
m_logger.SetMaxMinId(uiLogMaxId,uiLogMinId);
//m_logger.activate(THR_NEW_LWP|THR_JOINABLE,1,1,ACE_THR_PRI_OTHER_MIN); //线程优先级最低
ACE_DEBUG((LM_DEBUG,"%s:%d Init TscMsgQueue object ok !\n",__FILE__,__LINE__));
}
/**************************************************************
Function: CTscMsgQueue::~CTscMsgQueue
Description: CTscMsgQueue类析构函数
Input: 无
Output: 无
Return: 无
***************************************************************/
CTscMsgQueue::~CTscMsgQueue()
{
if ( m_pMsgQue != NULL )
{
delete m_pMsgQue;
m_pMsgQue = NULL;
}
ACE_DEBUG((LM_DEBUG,"%s:%d Destruct TscMsgQueue object ok !\n",__FILE__,__LINE__));
}
/**************************************************************
Function: CTscMsgQueue::CreateInstance
Description: 创建CTscMsgQueue静态对象
Input: 无
Output: 无
Return: 静态对象指针
***************************************************************/
CTscMsgQueue* CTscMsgQueue::CreateInstance()
{
static CTscMsgQueue cTscMsgQueue;
return &cTscMsgQueue;
}
/**************************************************************
Function: CTscMsgQueue::SendMessage
Description: 将TSC消息放入队列等待处理
Input: pMsg - 消息内容结构体指针
iLen - 消息内容长度
Output: 无
Return: 0 -错误 1-正确
***************************************************************/
int CTscMsgQueue::SendMessage(SThreadMsg* pMsg,int iLen)
{
if ( pMsg==NULL || m_pMsgQue==NULL )
{
#ifdef TSC_DEBUG
ACE_DEBUG((LM_DEBUG,"pMsg or m_pMsgQue is NULL"));
#endif
return 0;
}
ACE_Message_Block *mb = new ACE_Message_Block(iLen); //构造消息块
mb->copy((char*)pMsg, iLen); // 将数据拷贝进消息块
ACE_Time_Value nowait(getCurrTime()+ACE_Time_Value(1));
m_pMsgQue->enqueue_tail(mb, &nowait); //向 ACE_Message_Queue中添加新数据块
#ifdef CHECK_MEMERY
TestMem(__FILE__,__LINE__);
#endif
return 1;
}
/**************************************************************
Function: CTscMsgQueue::DealData
Description: 接收TSC队列消息,并根据消息类型不同分别处理
Input: 无
Output: 无
Return: 无
***************************************************************/
void CTscMsgQueue::DealData()
{
int iLen = 0;
timeval tTmp;
ACE_Message_Block *mb = NULL;
SThreadMsg sMsg;
ACE_Time_Value nowait(getCurrTime());
tTmp.tv_sec = 0;
tTmp.tv_usec = 10000;
CManaKernel* pWorkParaManager = CManaKernel::CreateInstance();
CWirelessBtn* pWirelessBtn = CWirelessBtn::CreateInstance();
for(;;)
{
if(m_pMsgQue->dequeue_head(mb, &nowait) != -1) //从 ACE_Message_Queue 中弹出消息块
{
iLen = (int)mb->length();
memcpy((char*)&sMsg, mb->base(), iLen); //从消息块中读数据
mb->release();
}
else
{
ACE_OS::sleep(ACE_Time_Value(tTmp)); //暂停10毫秒
continue;
}
//ACE_DEBUG((LM_DEBUG,"%s:%d TscMsg Dealdata type:%d opt:%d dataLen:%d \n" ,__FILE__,__LINE__,sMsg.ulType,sMsg.ucMsgOpt,sMsg.uiMsgDataLen));//MOD:0515 17:00
switch ( sMsg.ulType ) //消息处理
{
case TSC_MSG_NEXT_STEP:
pWorkParaManager->GoNextStep();
break;
case TSC_MSG_OVER_CYCLE:
pWorkParaManager->OverCycle();
break;
case TSC_MSG_SWITCH_STATUS:
pWorkParaManager->SwitchStatus(*((Byte*)sMsg.pDataBuf));
break;
case TSC_MSG_SWITCH_CTRL:
//ACE_DEBUG((LM_DEBUG,"%s:%d 收到TSC改变控制方式!\n" ,__FILE__,__LINE__));
pWorkParaManager->SwitchCtrl(*((Byte*)sMsg.pDataBuf));
break;
case TSC_MSG_UPDATE_PARA:
pWorkParaManager->SetUpdateBit();
break;
case TSC_MSG_TIMEPATTERN:
pWorkParaManager->SpecTimePattern(*((Byte*)sMsg.pDataBuf));
break;
case TSC_MSG_LOCK_STEP:
pWorkParaManager->LockStep(*((Byte*)sMsg.pDataBuf));
break;
case TSC_MSG_LOCK_STAGE:
pWorkParaManager->LockStage(*((Byte*)sMsg.pDataBuf));
break;
case TSC_MSG_NEXT_STAGE:
pWorkParaManager->LockNextStage();
break;
case TSC_MSG_LOCK_PHASE:
pWorkParaManager->LockPhase(*((Byte*)sMsg.pDataBuf));
break;
case TSC_MSG_CORRECT_TIME:
pWorkParaManager->CorrectTime(sMsg.ucMsgOpt,(Byte*)sMsg.pDataBuf);
break;
case TSC_MSG_STATUS_READ:
pWorkParaManager->GetTscStatus(sMsg.ucMsgOpt);
break;
case TSC_MSG_EXSTATUS_READ:
pWorkParaManager->GetTscExStatus(sMsg.ucMsgOpt);
break;
case TSC_MSG_GREENCONFLICT:
pWorkParaManager->DealGreenConflict(sMsg.ucMsgOpt);
break;
case TSC_MSG_LOG_WRITE:
WriteEventLog(sMsg.ucMsgOpt,(Byte*)sMsg.pDataBuf);
break;
case TSC_MSG_EVENT_READ:
break;
case TSC_MSG_PATTER_RECOVER:
pWorkParaManager->ChangePatter(sMsg.ucMsgOpt);
break ;
case TSC_MSG_MANUALBUTTON_HANDLE:
pWirelessBtn->HandleSpecialDirec((Uint*)sMsg.pDataBuf);
break ;
default:
break;
}
if ( sMsg.pDataBuf != NULL )
{
ACE_OS::free(sMsg.pDataBuf); //删除申请的内存
sMsg.pDataBuf = NULL;
}
}
}
/**************************************************************
Function: CTscMsgQueue::WriteEventLog
Description: 接收到写日志消息后的处理函数
Input: uEvtType - 日志类型
pEvtValue -日志值地址指针
Output: 无
Return: 无
***************************************************************/
void CTscMsgQueue::WriteEventLog(Byte uEvtType, Byte* pEvtValue)
{
int iIndex = 0;
Uint iEvtValue = 0;
while ( iIndex < 4 )
{
//ACE_DEBUG((LM_DEBUG,"%s:%d pEvtValue[%d] = %d \n" ,__FILE__,__LINE__,iIndex,pEvtValue[iIndex]));//MOD:0515 17:00
iEvtValue |= ((pEvtValue[iIndex]&0xff)<<(8*(3-iIndex)));//值存储低字节到高位
iIndex++;
}
m_logger.WriteEventLogActive(uEvtType,iEvtValue);
/*
ACE_DEBUG((LM_DEBUG,"%s:%d %d-%d uEvtType:%d iTotalSec:%d\n"
,__FILE__,__LINE__,m_ucLogMaxId,m_ucLogMinId,uEvtType,iTotalSec));
*/
}