|
@@ -1,7 +1,129 @@
|
|
|
#include "stdafx.h"
|
|
|
#include "AlarmFSM.h"
|
|
|
#include "Event.h"
|
|
|
+#include "json/json.h"
|
|
|
+namespace Task
|
|
|
+{
|
|
|
+ //发送告警
|
|
|
+ struct SendAlarmTask : public ITaskSp{
|
|
|
+ AlarmFSM* m_fsm;
|
|
|
+ explicit SendAlarmTask(AlarmFSM* f) : m_fsm(f) {}
|
|
|
+ void Process(){
|
|
|
+ LOG_FUNCTION();
|
|
|
+ //改为循环处理告警
|
|
|
+ int logSum=0;
|
|
|
+ while(true){
|
|
|
+
|
|
|
+ if(m_fsm->m_NewUploading_alarm.empty()&&m_fsm->m_unSendAlarm.IsNullOrEmpty()){
|
|
|
+ if(logSum>=120){
|
|
|
+ Dbg("no warn,wait 6min");
|
|
|
+ logSum=0;
|
|
|
+ }else{
|
|
|
+ logSum++;
|
|
|
+ }
|
|
|
+ Sleep(3000);//无重发和新的告警则等待
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ logSum=0;
|
|
|
+
|
|
|
+ IHttpFunc* client;
|
|
|
+ client = create_http(m_fsm->HttpsLogCallBack);
|
|
|
+
|
|
|
+ bool isSendSucc=false;//查询是否成功标志
|
|
|
+ if(SendAlarmTaskImpl(client)){
|
|
|
+ isSendSucc = true;
|
|
|
+ }else{
|
|
|
+ isSendSucc = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ client->Destory();
|
|
|
+
|
|
|
+ //m_fsm->PostEventFIFO(new SendAlarmEvent(isSendSucc));//返回处理结果
|
|
|
+ if(isSendSucc){
|
|
|
+ //成功
|
|
|
+ Dbg("send alarm statistic m_iRec=%d , m_iThrow=%d , UnSend=%d , m_iSucc=%d , m_iFail=%d",m_fsm->m_iRec,m_fsm->m_iThrow,m_fsm->m_NewUploading_alarm.size(),m_fsm->m_iSucc,m_fsm->m_iFail);
|
|
|
+ if(!m_fsm->m_NewUploading_alarm.empty()){
|
|
|
+ Sleep(2000);//赶紧发送
|
|
|
+ continue;
|
|
|
+ }else{
|
|
|
+ Sleep(3000);//等待
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ //失败,超过未发送成功的告警时间间隔,丢弃告警信息
|
|
|
+ CSmallDateTime endTime = CSmallDateTime::GetNow();
|
|
|
+ if(((DWORD)endTime-(DWORD)m_fsm->m_sendBeginTime)>m_fsm->m_maxResendTime){
|
|
|
+ m_fsm->m_unSendAlarm="";//置为空
|
|
|
+ m_fsm->m_iFail = m_fsm->m_iFail+ m_fsm->m_eachSum ;//发送失败
|
|
|
+ LogWarn(Severity_Low,Error_Exception,WARN_ALARM_SEND_FAIL,CSimpleStringA::Format("throw away alarm num= %d,m_iFail=%d,m_iThrow=%d",m_fsm->m_eachSum,m_fsm->m_iFail,m_fsm->m_iThrow));
|
|
|
+ m_fsm->m_eachSum =0;//清空批次数量
|
|
|
+ m_fsm->m_sendBeginTime = CSmallDateTime::GetNow();
|
|
|
+ Dbg("send alarm statistic m_iRec=%d , m_iThrow=%d , UnSend=%d , m_iSucc=%d , m_iFail=%d",m_fsm->m_iRec,m_fsm->m_iThrow,m_fsm->m_NewUploading_alarm.size(),m_fsm->m_iSucc,m_fsm->m_iFail);
|
|
|
+ }
|
|
|
+ Sleep(10*1000);//失败重发等待
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ bool SendAlarmTaskImpl(IHttpFunc* client){
|
|
|
+
|
|
|
+ HttpStruct::SendAlarmTaskReq qTempReq;
|
|
|
+ HttpStruct::SendAlarmTaskRet qTempRet;
|
|
|
+ if(m_fsm->m_unSendAlarm.IsNullOrEmpty()){
|
|
|
+ //组装新的json告警信息
|
|
|
+ string strJson = m_fsm->alarmJson();
|
|
|
+ if(strJson.empty()){
|
|
|
+ return true;
|
|
|
+ }else{
|
|
|
+ qTempReq.m_reqStr = strJson.c_str();//请求参数
|
|
|
+ m_fsm->m_unSendAlarm = strJson.c_str();
|
|
|
+ m_fsm->m_sendBeginTime = CSmallDateTime::GetNow();
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ //重发新的告警信息
|
|
|
+ qTempReq.m_reqStr = m_fsm->m_unSendAlarm.GetData();//请求参数
|
|
|
+ Dbg("alarm retry send");
|
|
|
+ }
|
|
|
+ qTempReq.m_url=m_fsm->m_sendUrl.GetData();//访问地址
|
|
|
+ //DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("alarm send =%s",qTempReq.m_reqStr.c_str());
|
|
|
+
|
|
|
+ if(!client->Post(qTempReq, qTempRet)){
|
|
|
+ Dbg("SendAlarmTask http req fail,url=%s",qTempReq.m_url.c_str());
|
|
|
+ return false;//失败
|
|
|
+ }
|
|
|
+ Json::Reader reader;
|
|
|
+ Json::Value rootRet;
|
|
|
+ if (!reader.parse(qTempRet.m_retStr, rootRet, false))
|
|
|
+ {
|
|
|
+ Dbg("SendAlarmTask parse resp is fail");
|
|
|
+ return false;//失败
|
|
|
+ }
|
|
|
|
|
|
+ bool isSucc = rootRet["success"].asBool();
|
|
|
+ if(isSucc){
|
|
|
+ Dbg("SendAlarmTask [success] is succ,m_eachSum=%d",m_fsm->m_eachSum);
|
|
|
+ m_fsm->m_unSendAlarm="";//置为空
|
|
|
+ m_fsm->m_iSucc = m_fsm->m_iSucc+ m_fsm->m_eachSum ;//发送成功
|
|
|
+ m_fsm->m_eachSum = 0;//清空批次数量
|
|
|
+ return true;//写入成功
|
|
|
+ }else{
|
|
|
+ CSimpleStringA errCode = rootRet["code"].asString().c_str();
|
|
|
+ if(!errCode.IsNullOrEmpty()||errCode == "10101"){
|
|
|
+ //DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("SendAlarmTaskImpl")("SendAlarmTask [success] is false,code = 10101");
|
|
|
+ m_fsm->m_unSendAlarm="";//置为空
|
|
|
+ m_fsm->m_iFail = m_fsm->m_iFail+ m_fsm->m_eachSum ;//发送失败
|
|
|
+ LogWarn(Severity_Low,Error_Exception,WARN_ALARM_PARSE_FAIL,CSimpleStringA::Format("SendAlarmTask [success] is false,code = 10101,throw away alarm num= %d,m_iFail=%d",m_fsm->m_eachSum,m_fsm->m_iFail));
|
|
|
+ m_fsm->m_eachSum = 0;//清空批次数量
|
|
|
+ return true;//中文乱码解析失败,默认成功
|
|
|
+ }else{
|
|
|
+ Dbg("SendAlarmTask [success] is false,code =%s",errCode);
|
|
|
+ return false;//写入失败
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+}
|
|
|
|
|
|
AlarmFSM::AlarmFSM() : m_pConnection(NULL),m_b_alarmstate(FALSE)
|
|
|
{
|
|
@@ -14,6 +136,12 @@ AlarmFSM::AlarmFSM() : m_pConnection(NULL),m_b_alarmstate(FALSE)
|
|
|
m_iThrow=0;//累计队列丢弃总数
|
|
|
m_iFail=0;//累计发送失败总次数
|
|
|
m_iSucc=0;//累计发送成功总次数
|
|
|
+
|
|
|
+ m_CenterModel=0;
|
|
|
+ m_maxResendTime=60;
|
|
|
+ m_eachSum=0;
|
|
|
+ m_initAlarm=false;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
AlarmFSM::~AlarmFSM()
|
|
@@ -50,6 +178,46 @@ ErrorCodeEnum AlarmFSM::OnInit()
|
|
|
{
|
|
|
Dbg("get DealWarningTime from CenterSetting.ini failed");
|
|
|
}
|
|
|
+ int iCenterModel =0;
|
|
|
+ Error = spConfig->ReadConfigValueInt("Alarm", "CenterModel", iCenterModel);
|
|
|
+ if(Error==Error_Succeed){
|
|
|
+ m_CenterModel = iCenterModel;
|
|
|
+ Dbg("init read CenterSetting.ini CenterModel=%d",m_CenterModel);
|
|
|
+ }else{
|
|
|
+ Dbg("init read CenterSetting.ini CenterModel failed");
|
|
|
+ }
|
|
|
+
|
|
|
+ Error = spConfig->ReadConfigValueInt("Alarm", "maxResendTime", m_maxResendTime);
|
|
|
+ if(Error==Error_Succeed){
|
|
|
+ Dbg("init read CenterSetting.ini maxResendTime=%d",m_maxResendTime);
|
|
|
+ }else{
|
|
|
+ Dbg("init read CenterSetting.ini maxResendTime failed");
|
|
|
+ }
|
|
|
+
|
|
|
+ CSimpleStringA str="";
|
|
|
+ Error = spConfig->ReadConfigValue("Alarm", "topic", str);
|
|
|
+ if(Error==Error_Succeed){
|
|
|
+ m_topic = str;
|
|
|
+ Dbg("init read CenterSetting.ini topic=%s",str.GetData());
|
|
|
+ }else{
|
|
|
+ Dbg("init read CenterSetting.ini topic failed");
|
|
|
+ }
|
|
|
+
|
|
|
+ Error = spConfig->ReadConfigValue("Alarm", "sendUrl", str);
|
|
|
+ if(Error==Error_Succeed){
|
|
|
+ m_sendUrl = str;
|
|
|
+ Dbg("init read CenterSetting.ini sendUrl=%s",str.GetData());
|
|
|
+ }else{
|
|
|
+ Dbg("init read CenterSetting.ini sendUrl failed");
|
|
|
+ }
|
|
|
+
|
|
|
+ Error = spConfig->ReadConfigValue("Alarm", "branchNo", str);
|
|
|
+ if(Error==Error_Succeed){
|
|
|
+ m_branchNo = str;
|
|
|
+ Dbg("init read CenterSetting.ini branchNo=%s",str.GetData());
|
|
|
+ }else{
|
|
|
+ Dbg("init read CenterSetting.ini branchNo failed");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (m_nDealWarningTime == 0)
|
|
@@ -57,6 +225,15 @@ ErrorCodeEnum AlarmFSM::OnInit()
|
|
|
m_nDealWarningTime = 10;
|
|
|
}
|
|
|
|
|
|
+ if(m_maxResendTime <= 0){
|
|
|
+ m_maxResendTime ==60;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(m_branchNo.IsNullOrEmpty()){
|
|
|
+ m_branchNo = "000";//默认是000总行分行号
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
return Error_Succeed;
|
|
|
}
|
|
|
|
|
@@ -67,86 +244,143 @@ ErrorCodeEnum AlarmFSM::OnExit()
|
|
|
|
|
|
void AlarmFSM::s0_on_entry()
|
|
|
{
|
|
|
- //if (m_b_alarmstate)
|
|
|
- //{
|
|
|
- // PostEventLIFO(new FSMEvent(USER_EVT_JMP_ALARMSTATEUP));
|
|
|
- //}
|
|
|
- //else if (!is_alarm_empty())
|
|
|
- //{
|
|
|
- // PostEventLIFO(new FSMEvent(USER_EVT_JMP_ALARMUP));
|
|
|
- //}
|
|
|
- //else
|
|
|
- //{
|
|
|
- // ScheduleTimer(1, 5000);
|
|
|
- //}
|
|
|
- //connect
|
|
|
- if (!m_pConnection)
|
|
|
- {
|
|
|
- m_pConnection = new AlarmConnection(m_pEntity, this);
|
|
|
- if (m_pConnection->ConnectFromCentralSetting()&& m_pConnection->IsConnectionOK())
|
|
|
- {
|
|
|
- //创建成功
|
|
|
+ if(!m_initAlarm){
|
|
|
+ m_initAlarm=true;
|
|
|
+ //添加集中配置参数读取和判断走分行还是总行
|
|
|
+ if(m_CenterModel==0){
|
|
|
+ LogWarn(Severity_Low,Error_Exception,WARN_ALARM_START_OLD_MODE,CSimpleStringA::Format("init alarm old model,model=%d",m_CenterModel));
|
|
|
}else{
|
|
|
- //创建失败
|
|
|
- Dbg("connect server fail,config or Servers Error!");
|
|
|
- closeClientConn();//断开连接
|
|
|
- }
|
|
|
- }
|
|
|
- if (!m_pConnection)
|
|
|
- {
|
|
|
- ScheduleTimer(1, 10000); // try 10 seconds later
|
|
|
+ LogWarn(Severity_Low,Error_Exception,WARN_ALARM_START_NEW_MODE,CSimpleStringA::Format("init alarm new model,model=%d",m_CenterModel));
|
|
|
+ }
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
- PostEventLIFO(new FSMEvent(USER_EVT_JMP_ALARMUP));//跳转S1状态
|
|
|
+ if(m_CenterModel==0){
|
|
|
+ //旧模式
|
|
|
+ //改造为先判断是否不为空,再创建连接,减少空连接数
|
|
|
+ if(m_NewUploading_alarm.empty()){
|
|
|
+ //DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("no warn,wait 3s");
|
|
|
+ ScheduleTimer(1, 3000);// try 3 seconds later
|
|
|
+ }else{
|
|
|
+ if (!m_pConnection)
|
|
|
+ {
|
|
|
+ m_pConnection = new AlarmConnection(m_pEntity, this);
|
|
|
+ if (m_pConnection->ConnectFromCentralSetting()&& m_pConnection->IsConnectionOK())
|
|
|
+ {
|
|
|
+ //创建成功
|
|
|
+ }else{
|
|
|
+ //创建失败
|
|
|
+ //Dbg("connect server fail,config or Servers Error!");
|
|
|
+ Dbg("connect server fail,config or Servers Error!");
|
|
|
+ closeClientConn();//断开连接
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!m_pConnection)
|
|
|
+ {
|
|
|
+ ScheduleTimer(1, 10000); // try 10 seconds later
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ PostEventLIFO(new FSMEvent(USER_EVT_JMP_ALARMUP));//跳转S1状态
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ //新模式
|
|
|
+ PostEventLIFO(new FSMEvent(USER_EVT_JMP_NEW_ALARM));//跳转新模式发送
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
void AlarmFSM::s0_on_exit()
|
|
|
{
|
|
|
CancelTimer(1);
|
|
|
+ CancelTimer(2);
|
|
|
}
|
|
|
|
|
|
unsigned int AlarmFSM::s0_on_event( FSMEvent* event )
|
|
|
{
|
|
|
- //if (event->iEvt == EVT_TIMER)
|
|
|
- //{
|
|
|
- // if (m_b_alarmstate)
|
|
|
- // {
|
|
|
- // PostEventLIFO(new FSMEvent(USER_EVT_JMP_ALARMSTATEUP));
|
|
|
- // }
|
|
|
- // else if (!is_alarm_empty())
|
|
|
- // {
|
|
|
- // PostEventLIFO(new FSMEvent(USER_EVT_JMP_ALARMUP));
|
|
|
- // }
|
|
|
- // else
|
|
|
- // {
|
|
|
- // ScheduleTimer(1, 5000);
|
|
|
- // }
|
|
|
- //}
|
|
|
if (event->iEvt == EVT_TIMER)
|
|
|
{
|
|
|
- if (!m_pConnection)
|
|
|
- {
|
|
|
- m_pConnection = new AlarmConnection(m_pEntity, this);
|
|
|
- if (m_pConnection->ConnectFromCentralSetting()&& m_pConnection->IsConnectionOK())
|
|
|
- {
|
|
|
- //创建成功
|
|
|
+ if(event->param1 == 1){
|
|
|
+ //改造为先判断是否不为空,再创建连接,减少空连接数
|
|
|
+ if(m_NewUploading_alarm.empty()){
|
|
|
+ //Dbg("no warn,wait 3s");
|
|
|
+ //DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("no warn,wait 3s");
|
|
|
+ ScheduleTimer(1, 3000);// try 3 seconds later
|
|
|
}else{
|
|
|
- //创建失败
|
|
|
- Dbg("connect server fail,config or Servers Error!");
|
|
|
- closeClientConn();//断开连接
|
|
|
- }
|
|
|
- }
|
|
|
- if (!m_pConnection)
|
|
|
- {
|
|
|
- ScheduleTimer(1, 10000); // try 10 seconds later
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- PostEventLIFO(new FSMEvent(USER_EVT_JMP_ALARMUP));//跳转S1状态
|
|
|
+ if (!m_pConnection)
|
|
|
+ {
|
|
|
+ m_pConnection = new AlarmConnection(m_pEntity, this);
|
|
|
+ if (m_pConnection->ConnectFromCentralSetting()&& m_pConnection->IsConnectionOK())
|
|
|
+ {
|
|
|
+ //创建成功
|
|
|
+ }else{
|
|
|
+ //创建失败
|
|
|
+ Dbg("connect server fail,config or Servers Error!");
|
|
|
+ closeClientConn();//断开连接
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!m_pConnection)
|
|
|
+ {
|
|
|
+ ScheduleTimer(1, 10000); // try 10 seconds later
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ PostEventLIFO(new FSMEvent(USER_EVT_JMP_ALARMUP));//跳转S1状态
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else if(event->param1 == 2){
|
|
|
+ //新模式
|
|
|
+ //if(m_NewUploading_alarm.empty()&&m_unSendAlarm.IsNullOrEmpty()){
|
|
|
+ // //DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("no warn,wait 3s");
|
|
|
+ // ScheduleTimer(2, 3000);// try 3 seconds later
|
|
|
+ //}else{
|
|
|
+ //开始启动调用发送线程
|
|
|
+ Task::SendAlarmTask* alarmTask = new Task::SendAlarmTask(this);
|
|
|
+ ErrorCodeEnum rc = m_pEntity->GetFunction()->PostThreadPoolTask(alarmTask);
|
|
|
+ if(rc!=Error_Succeed){
|
|
|
+ Dbg("s0 create SendAlarmTask is fail,%d",(int)rc);
|
|
|
+ ScheduleTimer(2, 10*1000);//等待一段时间
|
|
|
+ }
|
|
|
+ //}
|
|
|
}
|
|
|
+ }else if (event->iEvt == USER_EVT_JMP_NEW_ALARM){
|
|
|
+ //if(m_NewUploading_alarm.empty()&&m_unSendAlarm.IsNullOrEmpty()){
|
|
|
+ // //DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("no warn,wait 3s");
|
|
|
+ // ScheduleTimer(2, 3000);// try 3 seconds later
|
|
|
+ //}else{
|
|
|
+ //开始启动调用发送线程
|
|
|
+ Task::SendAlarmTask* alarmTask = new Task::SendAlarmTask(this);
|
|
|
+ ErrorCodeEnum rc = m_pEntity->GetFunction()->PostThreadPoolTask(alarmTask);
|
|
|
+ if(rc!=Error_Succeed){
|
|
|
+ Dbg("s0 create SendAlarmTask is fail,%d",(int)rc);
|
|
|
+ ScheduleTimer(2, 10*1000);//等待一段时间
|
|
|
+ }
|
|
|
+ //}
|
|
|
}
|
|
|
+ //else if (event->iEvt == USER_EVT_SEND_ALARM){
|
|
|
+ // SendAlarmEvent* pEvent = (SendAlarmEvent*)event;
|
|
|
+ // if(pEvent->isSucc){
|
|
|
+ // //成功
|
|
|
+ // DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("send alarm statistic m_iRec=%d , m_iThrow=%d , UnSend=%d , m_iSucc=%d , m_iFail=%d",m_iRec,m_iThrow,m_NewUploading_alarm.size(),m_iSucc,m_iFail);
|
|
|
+ // if(!m_NewUploading_alarm.empty()){
|
|
|
+ // ScheduleTimer(2,2000);
|
|
|
+ // }else{
|
|
|
+ // ScheduleTimer(2,3000);
|
|
|
+ // }
|
|
|
+ // }else{
|
|
|
+ // //失败
|
|
|
+ // //超过未发送成功的告警时间间隔,丢弃告警信息
|
|
|
+ // CSmallDateTime endTime = CSmallDateTime::GetNow();
|
|
|
+ // if(((DWORD)endTime-(DWORD)m_sendBeginTime)>m_maxResendTime){
|
|
|
+ // m_unSendAlarm="";//置为空
|
|
|
+ // m_iFail = m_iFail+ m_eachSum ;//发送失败
|
|
|
+ // LogWarn(Severity_Low,Error_Exception,WARN_ALARM_SEND_FAIL,CSimpleStringA::Format("throw away alarm num= %d,m_iFail=%d",m_eachSum,m_iFail));
|
|
|
+ // m_eachSum =0;//清空批次数量
|
|
|
+ // m_sendBeginTime = CSmallDateTime::GetNow();
|
|
|
+ // DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("send alarm statistic m_iRec=%d , m_iThrow=%d , UnSend=%d , m_iSucc=%d , m_iFail=%d",m_iRec,m_iThrow,m_NewUploading_alarm.size(),m_iSucc,m_iFail);
|
|
|
+ // }
|
|
|
+ // ScheduleTimer(2,10000);
|
|
|
+ // }
|
|
|
+ //}
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
@@ -579,6 +813,9 @@ void AlarmFSM::add_NewAlarm(alarm_t* alarm)
|
|
|
free(oldAlarm->SN);
|
|
|
oldAlarm->SN=NULL;
|
|
|
|
|
|
+ free(oldAlarm->warnTime);
|
|
|
+ oldAlarm->warnTime=NULL;
|
|
|
+
|
|
|
delete oldAlarm;
|
|
|
oldAlarm=NULL;
|
|
|
}
|
|
@@ -633,11 +870,114 @@ bool AlarmFSM::SendAlarm(){
|
|
|
free(alarm->SN);
|
|
|
alarm->SN=NULL;
|
|
|
|
|
|
+ free(alarm->warnTime);
|
|
|
+ alarm->warnTime=NULL;
|
|
|
+
|
|
|
delete alarm;
|
|
|
alarm=NULL;
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+void AlarmFSM::HttpsLogCallBack(const char* logtxt)
|
|
|
+{
|
|
|
+ Dbg("http dbg: %s",logtxt);
|
|
|
+}
|
|
|
+
|
|
|
+std::string AlarmFSM::alarmJson()
|
|
|
+{
|
|
|
+ vector<alarm_t*> unSendAlarm;
|
|
|
+ string jsonStr ="";
|
|
|
+ EnterCriticalSection(&cs);
|
|
|
+ alarm_t* dAlarm = NULL;
|
|
|
+ for(int i = 0 ;i<16;i++){
|
|
|
+ if(m_NewUploading_alarm.empty()){
|
|
|
+ break;
|
|
|
+ }else{
|
|
|
+ dAlarm = (alarm_t*)(*m_NewUploading_alarm.begin());//集合首个元素
|
|
|
+ m_NewUploading_alarm.erase(m_NewUploading_alarm.begin());//集合删除首元素
|
|
|
+ unSendAlarm.push_back(dAlarm);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ LeaveCriticalSection(&cs);
|
|
|
+
|
|
|
+ if(unSendAlarm.size()==0){
|
|
|
+ return jsonStr;//无发送直接返回空
|
|
|
+ }
|
|
|
+ Json::Value root;
|
|
|
+ Json::Value arraylist;//消息列表
|
|
|
+ Json::FastWriter fw;//写入对象
|
|
|
+ int i = 0;
|
|
|
+ CSystemStaticInfo si;
|
|
|
+ {
|
|
|
+ m_pEntity->GetFunction()->GetSystemStaticInfo(si);
|
|
|
+ }
|
|
|
+ for(auto iter = unSendAlarm.begin(); iter!=unSendAlarm.end(); iter++){
|
|
|
+ Json::Value rootAlarm;
|
|
|
+ Json::FastWriter fwAlarm;//写入对象
|
|
|
+ alarm_t* alarmt = *iter;
|
|
|
+ m_uuid =CUUID::Create(m_uuid);
|
|
|
+ rootAlarm["IDKey"] = m_uuid.ToString().GetData();
|
|
|
+ rootAlarm["BranchNo"] = m_branchNo.GetData();
|
|
|
+ rootAlarm["TerminalNo"] = si.strTerminalID.GetData();
|
|
|
+ rootAlarm["EntityName"] = alarmt->EntityName;
|
|
|
+ rootAlarm["Item"] = CSimpleStringA::Format("%016llx", alarmt->Item).SubString(8,8).GetData();//16进制取后面八位
|
|
|
+ char Level[2];
|
|
|
+ sprintf(Level, "%c", alarmt->Level);
|
|
|
+ rootAlarm["Level"] = CSimpleStringA::Format("%s",Level).GetData();
|
|
|
+ rootAlarm["LifeID"] = CSimpleStringA::Format("%016llx", alarmt->LifeID).SubString(8,8).GetData();//16进制取后面八位
|
|
|
+ rootAlarm["SN"] = alarmt->SN;
|
|
|
+ rootAlarm["UserCode"] = CSimpleStringA::Format("%016llx", alarmt->UserCode).SubString(8,8).GetData();//16进制取后面八位
|
|
|
+ rootAlarm["WarningTime"] = CSimpleStringA::Format("%s", alarmt->warnTime).GetData();
|
|
|
+ rootAlarm["Description"] = CSimpleStringA::Format("%s", alarmt->Description).GetData();
|
|
|
+ string alarmJsonStr = fwAlarm.write(rootAlarm);
|
|
|
+ //DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("alarmJsonStr=%s",alarmJsonStr.c_str());
|
|
|
+ arraylist[i]=alarmJsonStr.c_str();
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ root["message_list"] = arraylist;
|
|
|
+ root["topic"]=m_topic.GetData();
|
|
|
+ jsonStr = fw.write(root);
|
|
|
+ m_eachSum = i;
|
|
|
+
|
|
|
+ //清理内存
|
|
|
+ while(true){
|
|
|
+ if(unSendAlarm.empty()){
|
|
|
+ break;
|
|
|
+ }else{
|
|
|
+ dAlarm = (alarm_t*)(*unSendAlarm.begin());//集合首个元素
|
|
|
+ unSendAlarm.erase(unSendAlarm.begin());//集合删除首元素
|
|
|
+ }
|
|
|
+ free(dAlarm->Description);
|
|
|
+ dAlarm->Description=NULL;
|
|
|
+
|
|
|
+ free(dAlarm->EntityName);
|
|
|
+ dAlarm->EntityName=NULL;
|
|
|
+
|
|
|
+ free(dAlarm->SN);
|
|
|
+ dAlarm->SN=NULL;
|
|
|
+
|
|
|
+ free(dAlarm->warnTime);
|
|
|
+ dAlarm->warnTime=NULL;
|
|
|
+
|
|
|
+ delete dAlarm;
|
|
|
+ dAlarm=NULL;
|
|
|
+ }
|
|
|
+ return jsonStr;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+int AlarmFSM::HexBuf2StrBuf(PBYTE hexBuf, char** strBuf, DWORD len)
|
|
|
+{
|
|
|
+ char* tmpStr = *strBuf;
|
|
|
+ int count = 0;
|
|
|
+ for (int i = 0; i < len; ++i)
|
|
|
+ {
|
|
|
+ sprintf(tmpStr + count, "%0.2x", hexBuf[i]);
|
|
|
+ Dbg("strBut:%s", tmpStr);
|
|
|
+ count += 2;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+}
|
|
|
|
|
|
|