| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827 |
- //////////////////////////////////////////////////////////////////////////////
- ////// //////
- ////// 文 件: NoticeQueue.cpp //////
- ////// 作 者: sailing //////
- ////// 创建时间: 2008-02-23 //////
- ////// 说 明: 1、主要语音通知 //////
- ////// 2、语音查询待完善 //////
- ////// 修改时间: //////
- ////// 修改说明: //////
- ////// //////
- //////////////////////////////////////////////////////////////////////////////
- #pragma once
- #include "stdafx.h"
- #include "NoticeQueue.h"
- #include "Global.h"
- #include "SysLib.h"
- #include "shlwapi.h"
- #define NOTICE_DELAY 35 //通知延时
- int g_nAlarmIndex=0;//报警索引,为了在IDE上面确认而设
- // 发送通知
- typedef struct _SEND_NOTICE
- {
- char szDevUID[20]; // 设备Uid
- int nVarID; // 变量ID
- char szTel[MAX_TEL_LENGTH + 1]; // 电话号码
- char szContect[MAX_NOTICE_CONTENT_LEN + 1]; // 内容
- int nAlarmIndex; // 报警索引
- SYSTEMTIME time;
- }SEND_NOTICE, *PSEND_NOTICE;
- typedef list<SEND_NOTICE> LIST_SEND_NOTICE;
- LIST_SEND_NOTICE g_listSendNotice;
- LIST_SEND_NOTICE g_listSendSms;
- HANDLE g_hSendNoticeThread = NULL;
- HANDLE g_hSendSmsThread = NULL;
- CRITICAL_SECTION g_csVarNotice; // 临界区对ProcessVarNotice过程全局变量进行保护
- CRITICAL_SECTION g_csSendNotice; // 临界区在发送线程里对全局变量进行保护
- HANDLE g_hDeleteVarSem; // 所有读变量list, 都要等这个信号量,保证变量出队列成功后,才能读
- // 删除所有变量
- void DeleteAllSendNoticeList();
- void DeleteAllSendSmsList();
- // 添加变量到語音list
- void InsertSendNoticeList(char *pDevUid, int nVarID, char *pTel, char *pContent,int nAlarmIndex);
- //IDE 确认后从語音list删除
- int DeleteSendNoticeList( char *pDevUid, int nVarID,int iAlarmIndex );
- // 添加变量到短信list
- void InsertSendSmsList(char *pDevUid, int nVarID, char *pContent,int nAlarmIndex);
- //IDE 确认后从短信list删除
- int DeleteSendSmsList( char *pDevUid, int nVarID,int iAlarmIndex );
- static DWORD WINAPI SendNoticeThread(LPVOID lpParameter);
- static DWORD WINAPI SendSmsThread(LPVOID lpParameter);
- // 获取报警状态ID对应的意义,用来组织报警内容 for Jesse 091119
- INT GetAlarmStatusDesc(char chDevUid[20], int nVarID, int nAlarmStatus, char *pStatusDesc);
- int InitNotice(void)
- {
- // 初始化远程报警通知
- if( g_nSendNotice )
- {
- g_hNoticeLibModule = NULL;
- CHAR strFile[MAX_LIST_LENGTH + 1] = "";
- if( g_nNoticeCardType == 1 )
- {
- wsprintf(strFile, "%s\\Dll\\Voice.dll", g_strDirectory);
- g_hNoticeLibModule = ::LoadLibrary(strFile);
- if (NULL != g_hNoticeLibModule)
- {
- pStoneUDllRegisterVoice = (STONEU_DLLRegisterVoice)::GetProcAddress(g_hNoticeLibModule, "STONEU_DLLRegisterVoice");
- pStoneUDllUnRegisterVoice = (STONEU_DLLUnRegisterVoice)::GetProcAddress(g_hNoticeLibModule, "STONEU_DLLUnRegisterVoice");
- pStoneUDllAllocateChannel = (STONEU_DLLAllocateChannel)::GetProcAddress(g_hNoticeLibModule, "STONEU_DLLAllocateChannel");
- }
- if( ( NULL != g_hNoticeLibModule ) && ( NULL != pStoneUDllRegisterVoice ) )
- {
- int nRet = pStoneUDllRegisterVoice(g_strDirectory, g_nTTSType);
- if( nRet != 0 )
- {
- AfxFreeLibrary( g_hNoticeLibModule );
- g_hNoticeLibModule = NULL;
- return 1;
- }
- }
- else
- {
- AfxFreeLibrary( g_hNoticeLibModule );
- g_hNoticeLibModule = NULL;
- }
- }
- else if( g_nNoticeCardType == 2 )
- {
- wsprintf(strFile, "%s\\Dll\\UsbVoice.dll", g_strDirectory);
- g_hNoticeLibModule = ::LoadLibrary(strFile);
- if( NULL != g_hNoticeLibModule )
- {
- pStoneUDllRegisterVoice = (STONEU_DLLRegisterVoice)::GetProcAddress(g_hNoticeLibModule, "STONEU_DLLRegisterVoice");
- pStoneUDllUnRegisterVoice = (STONEU_DLLUnRegisterVoice)::GetProcAddress(g_hNoticeLibModule, "STONEU_DLLUnRegisterVoice");
- pStoneUDllAllocateChannel = (STONEU_DLLAllocateChannel)::GetProcAddress(g_hNoticeLibModule, "STONEU_DLLAllocateChannel");
- }
- if( ( NULL != g_hNoticeLibModule ) && ( NULL != pStoneUDllRegisterVoice ) )
- {
- int nRet = pStoneUDllRegisterVoice(g_strDirectory, g_nTTSType);
- if( nRet != 0 )
- {
- AfxFreeLibrary( g_hNoticeLibModule );
- g_hNoticeLibModule = NULL;
- return 1;
- }
- }
- else
- {
- AfxFreeLibrary( g_hNoticeLibModule );
- g_hNoticeLibModule = NULL;
- }
- }
- DWORD dwThreadId;
- MTVERIFY( g_hSendNoticeThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)SendNoticeThread,
- NULL, 0, &dwThreadId) );
- //初始化TTS
- hTTSModule = NULL;
- wsprintf(strFile, "%s\\Dll\\TTSDll.dll", g_strDirectory);
- hTTSModule = ::LoadLibrary(strFile);
- if (NULL != hTTSModule)
- {
- pStoneUDllRegisterTTS = (MySTONEU_DLLRegisterTTS)::GetProcAddress(hTTSModule, "STONEU_DLLRegisterTTS");
- pStoneUDllUnRegisterTTS = (MySTONEU_DLLUnRegisterTTS)::GetProcAddress(hTTSModule, "STONEU_DLLUnRegisterTTS");
- pStoneUDLLTxtToWav = (MySTONEU_DLLTxtToWav)::GetProcAddress(hTTSModule, "STONEU_DLLTxtToWav");
- }
- if( ( NULL != hTTSModule ) && ( NULL != pStoneUDllRegisterTTS ) )
- {
- if( !pStoneUDllRegisterTTS() )
- {
- FreeLibrary( hTTSModule );
- hTTSModule = NULL;
- }
- }
- else
- {
- FreeLibrary( hTTSModule );
- hTTSModule = NULL;
- }
- }
- //MTVERIFY( g_hDeleteVarSem = CreateEvent(NULL, TRUE, TRUE, "DeleteVarList") );
- //InitializeCriticalSection( &g_csVarNotice );
- //InitializeCriticalSection( &g_csSendNotice );
- return 0;
- }
- void UnInitNotice(void)
- {
- if( g_hSendNoticeThread )
- {
- //MTVERIFY( SetEvent( g_hDeleteVarSem ) );
- MTVERIFY( WaitForSingleObject( g_hSendNoticeThread, INFINITE ) != WAIT_FAILED );
- MTVERIFY( CloseHandle(g_hSendNoticeThread) );
- g_hSendNoticeThread = NULL;
- }
- //DeleteCriticalSection( &g_csVarNotice );
- //DeleteCriticalSection( &g_csSendNotice );
- //
- //if( g_hDeleteVarSem )
- //{
- // MTVERIFY( CloseHandle( g_hDeleteVarSem) );
- // g_hDeleteVarSem = NULL;
- //}
- if( g_nSendNotice )
- {
- if( ( NULL != g_hNoticeLibModule ) && ( NULL != pStoneUDllUnRegisterVoice ) )
- pStoneUDllUnRegisterVoice();
- if( ( NULL != hTTSModule ) && ( NULL != pStoneUDllUnRegisterTTS ) )
- pStoneUDllUnRegisterTTS();
- }
- DeleteAllSendSmsList();
- DeleteAllSendNoticeList();
- DeleteAllVarNoticeList();
- if (g_hNoticeLibModule != NULL)
- {
- ::FreeLibrary(g_hNoticeLibModule);
- g_hNoticeLibModule = NULL;
- }
-
- if (hTTSModule != NULL)
- {
- FreeLibrary(hTTSModule);
- hTTSModule = NULL;
- }
- }
- int InitEmail(char *pSmtpServer, // Smtp服务器
- int nSmtpPort, // Smtp端口
- int nIsNeed, // 是否需要smtp身份验证
- char *pUserAcc, // Email帐号
- char *pUserPwd, // Email密码
- char *pFromEmailAddr, // 发送人Email地址
- int nTimeOut // 超时
- )
- {
- g_hEmailLibModule = NULL;
- CHAR strFile[MAX_LIST_LENGTH + 1] = "";
- wsprintf(strFile, "%s\\Dll\\Email.dll", g_strDirectory);
- g_hEmailLibModule = AfxLoadLibrary(strFile);
- if (NULL != g_hEmailLibModule)
- {
- pEmailDllInit = (EMAIL_DLLInit)::GetProcAddress(g_hEmailLibModule, "EMAIL_DLLInit");
- pEmailDllUnInit = (EMAIL_DLLUnInit)::GetProcAddress(g_hEmailLibModule, "EMAIL_DLLUnInit");
- pEmailDllSendEmail = (EMAIL_DLLSendEmail)::GetProcAddress(g_hEmailLibModule, "EMAIL_DLLSendEmail");
- }
- if( ( NULL != g_hEmailLibModule ) && ( NULL != pEmailDllInit ) )
- {
- int nRet = pEmailDllInit( g_strDirectory,
- pSmtpServer,
- nSmtpPort,
- nIsNeed,
- pUserAcc,
- pUserPwd,
- pFromEmailAddr,
- nTimeOut
- );
- if( nRet != 0 )
- {
- AfxFreeLibrary( g_hEmailLibModule );
- g_hEmailLibModule = NULL;
- return 1;
- }
- }
- else
- {
- AfxFreeLibrary( g_hEmailLibModule );
- g_hEmailLibModule = NULL;
- }
- return 0;
- }
- int UnInitEmail()
- {
- if( NULL != g_hEmailLibModule && NULL != pEmailDllUnInit )
- {
- pEmailDllUnInit();
- AfxFreeLibrary( g_hEmailLibModule );
- g_hEmailLibModule = NULL;
- }
- return 0;
- }
- int InitSms(int nAddr, // 保留,因为短信猫是串口232没有地址
- int nCommPort, // 串口号
- int nRate, // 波特率
- int nDataBit, // 数据位
- int nStopBit, // 停止位
- int nParity, // 校验位
- int nInterval, // 间隔时间
- int nNeedLanguageTrans, // 是否需要语言转换
- int nMaxChar, // 短信猫一条短信最大支持的字符个数
- int nMakeCall)
- {
- g_hSmsLibModule = NULL;
- CHAR strFile[MAX_LIST_LENGTH + 1] = "";
- wsprintf(strFile, "%s\\Dll\\sms.dll", g_strDirectory);
- g_hSmsLibModule = AfxLoadLibrary(strFile);
- if (NULL != g_hSmsLibModule)
- {
- pSmsDllInit = (SMS_DLLInit)::GetProcAddress(g_hSmsLibModule, "SMS_DLLInit");
- pSmsDllUnInit = (SMS_DLLUnInit)::GetProcAddress(g_hSmsLibModule, "SMS_DLLUnInit");
- pSmsDllSendSms = (SMS_DLLSendSms)::GetProcAddress(g_hSmsLibModule, "SMS_DLLSendSms");
- pSmsDllGetCSQ = (SMS_DLLGetCSQ)::GetProcAddress(g_hSmsLibModule, "SMS_DLLGetCSQ");
- pSmsDllSetCallBack = (SMS_DLLSetCallBack)::GetProcAddress(g_hSmsLibModule, "SMS_DLLSetCallBack");
- }
- if( ( NULL != g_hSmsLibModule ) && ( NULL != pSmsDllInit ) )
- {
- int nRet = pSmsDllInit(g_strDirectory,
- nAddr,
- nCommPort,
- nRate,
- nDataBit,
- nStopBit,
- nParity,
- nInterval,
- nNeedLanguageTrans,
- nMaxChar,
- nMakeCall
- );
- if( nRet != 0 )
- {
- pSmsDllInit = NULL;
- pSmsDllUnInit = NULL;
- pSmsDllSendSms = NULL;
- pSmsDllGetCSQ = NULL;
- AfxFreeLibrary( g_hSmsLibModule );
- g_hSmsLibModule = NULL;
- return 1;
- }
- }
- else
- {
- pSmsDllInit = NULL;
- pSmsDllUnInit = NULL;
- pSmsDllSendSms = NULL;
- pSmsDllGetCSQ = NULL;
- AfxFreeLibrary( g_hSmsLibModule );
- g_hSmsLibModule = NULL;
- }
- DWORD dwThreadId2;
- MTVERIFY( g_hSendSmsThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)SendSmsThread,
- NULL, 0, &dwThreadId2) );
- return 0;
- }
- int UnInitSms()
- {
- if( g_hSendSmsThread )
- {
- MTVERIFY( WaitForSingleObject( g_hSendSmsThread, INFINITE ) != WAIT_FAILED );
- MTVERIFY( CloseHandle(g_hSendSmsThread) );
- g_hSendSmsThread = NULL;
- }
- if( NULL != g_hSmsLibModule && NULL != pSmsDllUnInit )
- {
- pSmsDllUnInit();
- AfxFreeLibrary( g_hSmsLibModule );
- g_hSmsLibModule = NULL;
- }
- return 0;
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////
- // 把短信信息写入TXT,让短信模块读取
- INT WriteToTxt(CHAR *pDevUid, int nVarID, CHAR *pContent,int iAlarmIndex )
- {
- CString strMobileTel;
- char szResultMsg[MAX_MSG_LENGTH + 1] = {0};
- int nResult = -1;
- memset(szResultMsg, 0, sizeof(szResultMsg));
- CString sPathName;
- sPathName.Format( "%s\\Log\\SupportSmsPlatform.txt",g_strDirectory );
- CString strTemp;
- CStdioFile MyFile;
- if(!MyFile.Open(sPathName,CFile::modeWrite))
- MyFile.Open(sPathName,CFile::modeCreate|CFile::modeWrite);
- for( int i = 0; i < (int)g_vtUserRoleInfo.size(); i++ )
- {
- if( strcmp(g_vtUserRoleInfo[i].szDevUID, pDevUid) == 0 )
- {
- for( int j = 0; j < (int)g_vtUserRoleInfo[i].vtUserInfo.size(); j++ )
- {
- strMobileTel = CString(g_vtUserRoleInfo[i].vtUserInfo[j].szMobileTel);
- if( strMobileTel.GetLength()!=11 ) continue; //判断是不是手机号码 只根据长度
- if( strMobileTel.Compare("") )
- {
- CTime time = CTime::GetCurrentTime();
- CString strTime;
- strTime = time.Format("%Y-%m-%d %H:%M:%S");
- strTemp.Format("%d***%s***%s***%s\n",iAlarmIndex,strTime,strMobileTel,pContent);
- MyFile.SeekToEnd();
- MyFile.WriteString(strTemp);
- }
- }
- }
- }
- MyFile.Close();
- return 0;
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////////////////////////
- ////// 函数名称:SendNotice ///////
- ////// 函数说明:开始语音通知 ///////
- ////// 参数列表:strTel -- 待通知的电话号码 ///////
- ////// strContent -- 短信内容 ///////
- ////// 作 者:sailing ///////
- ////// 创者时间:2009-02-23 ///////
- ///////////////////////////////////////////////////////////////////////////////////////////////
- INT SendNotice(CHAR *pUid, int nVarID,int nAlarmIndex, CHAR *pTel, CHAR *pContent)
- {
- //如果是短信确认关闭报警通知则退出
- if( !g_bAlarmNoticeFlag )
- return -1;
- int nRet = 0;
- CString str, strMsg;
- str = CString(" ") + pContent; // g_strHintAlarmWelcome +
- str = str + g_strHintVoiceEnd; //" 重新请按1,确认请按2,结束请直接挂机";
- if( ( NULL != g_hNoticeLibModule ) && (NULL != pStoneUDllAllocateChannel) )
- {
- //strMsg.Format("开始发送语音通知!", pTel);
- //AddToPrintQueue( MSG_OK, MSG_NOTICE_MD, (char*)(LPCTSTR)strMsg, strMsg.GetLength() );
-
- int nResult = pStoneUDllAllocateChannel( pTel, g_strNoticeTelPre, pUid, nVarID,nAlarmIndex, (char *)(LPCTSTR)str );
- nRet = nResult;
- if( nRet != CALL_LOST )
- {
- CTime time = CTime::GetCurrentTime();
- CString strTime;
- strTime = time.Format("%Y-%m-%d %H:%M:%S");
- CDBInterface::GetInstancePtr()->InsertNoticeRecord(
- pTel,
- "",
- (char *)(LPCTSTR)strTime,
- (char *)(LPCTSTR)pContent,
- "");
- }
- }
- return nRet;
- }
- // 发送Sms
- INT SendSms(CHAR *pDevUid, int nVarID, CHAR *pContent)
- {
- CString strMobileTel;
- char szResultMsg[MAX_MSG_LENGTH + 1] = {0};
- int nResult = -1;
- memset(szResultMsg, 0, sizeof(szResultMsg));
- //如果是短信确认关闭报警通知则退出
- if( !g_bAlarmNoticeFlag )
- return 0;
- //LOG4C((LOG_NOTICE, "g_vtUserRoleInfo.size = %d", g_vtUserRoleInfo.size()));
- for( int i = 0; i < (int)g_vtUserRoleInfo.size(); i++ )
- {
- //LOG4C((LOG_NOTICE, "g_vtUserRoleInfo[i].szDevUID = %s, pDevUid = %s", g_vtUserRoleInfo[i].szDevUID, pDevUid));
- if( strcmp(g_vtUserRoleInfo[i].szDevUID, pDevUid) == 0 )
- {
- //LOG4C((LOG_NOTICE, "g_vtUserRoleInfo[i].vtUserInfo.size = %d", g_vtUserRoleInfo[i].vtUserInfo.size()));
- for( int j = 0; j < (int)g_vtUserRoleInfo[i].vtUserInfo.size(); j++ )
- {
- strMobileTel = CString(g_vtUserRoleInfo[i].vtUserInfo[j].szMobileTel);
- //LOG4C((LOG_NOTICE, "strMobileTel = %s", strMobileTel));
- if( strMobileTel.Compare("") )
- {
- CTime time = CTime::GetCurrentTime();
- CString strTime;
- strTime = time.Format("%Y-%m-%d %H:%M:%S");
- // 开始通知
- if( pSmsDllSendSms != NULL && g_bAlarmNoticeFlag )
- {
- //LogEvent("发送短信,号码:%s, 内容:%s", strTel, pContent);
- if( strMobileTel.GetLength()!=11 ) continue; //判断是不是手机号码 只根据长度
- //LOG4C((LOG_NOTICE, "pSmsDllSendSms %s,%s",strMobileTel, pContent ));
- nResult = pSmsDllSendSms((char *)(LPCTSTR)strMobileTel, pContent, szResultMsg);
- //LOG4C((LOG_NOTICE, "pSmsDllSendSms nResult = %d",nResult ));
- if( nResult != 0 ) // 发送失败
- {
- int nNowData=0;
- if( !pSmsDllGetCSQ( 15,30,nNowData ) )//短信猫信号弱
- {
- CDBInterface::GetInstancePtr()->InsertSmsRecord(
- "",
- "",
- (char *)(LPCTSTR)strTime,
- "send sms lost,Because the signal is too weak",
- "");
- LOG4C((LOG_NOTICE, "send sms lost,Because the signal is too weak" ));
- return 0;
- }
- LOG4C((LOG_NOTICE, "send sms lost, tel: %s, content: %s, code: %s", strMobileTel, pContent, szResultMsg));
- // 发送失败,重试十次,如果还是失败,则放弃
- for( int iReSend = 0; iReSend < 20; iReSend++ )
- {
- nResult = pSmsDllSendSms((char *)(LPCTSTR)strMobileTel, pContent, szResultMsg);
- if( nResult == 0 )
- {
- CString strTemp = "";
- strTemp.Format("The last may be sent lost, again sent: %s", pContent);
- LOG4C((LOG_NOTICE, "send sms success, tel: %s, content: %s", strMobileTel, pContent));
- CDBInterface::GetInstancePtr()->InsertSmsRecord(
- (char *)(LPCTSTR)strMobileTel,
- "",
- (char *)(LPCTSTR)strTime,
- (char *)(LPCTSTR)strTemp,
- "");
- break;
- }
- else
- {
- LOG4C((LOG_NOTICE, "send sms lost, tel: %s, content: %s", strMobileTel, pContent));
- }
- Sleep( 100 );
- }
- }
- else
- {
- CDBInterface::GetInstancePtr()->InsertSmsRecord(
- (char *)(LPCTSTR)strMobileTel,
- "",
- (char *)(LPCTSTR)strTime,
- pContent,
- "");
- LOG4C((LOG_NOTICE, "send sms success, tel: %s, content: %s, code: %s", strMobileTel, pContent, szResultMsg));
- }
- }
- }
- }
- }
- }
- return 0;
- }
- // 发送Email
- INT SendEmail(CHAR *pDevUid, int nVarID, CHAR *pContent)
- {
- CString strEmail;
- char szResultMsg[MAX_MSG_LENGTH + 1] = {0};
- int nResult = -1;
- memset( szResultMsg, 0, sizeof(szResultMsg) );
- for( int i = 0; i < (int)g_vtUserRoleInfo.size(); i++ )
- {
- if( strcmp(g_vtUserRoleInfo[i].szDevUID, pDevUid) == 0 )
- {
- for( int j = 0; j < (int)g_vtUserRoleInfo[i].vtUserInfo.size(); j++ )
- {
- strEmail = CString(g_vtUserRoleInfo[i].vtUserInfo[j].szEmail);
- if( strEmail.Compare("") )
- {
- CTime time = CTime::GetCurrentTime();
- CString strTime;
- strTime = time.Format("%Y-%m-%d %H:%M:%S");
- if( pEmailDllSendEmail )
- {
- //LOG4C((LOG_NOTICE, "start send email"));
- // 开始通知
- nResult = pEmailDllSendEmail(
- (char *)(LPCSTR)strEmail,
- g_strEmailSubject,
- pContent,
- (char *)(LPCTSTR)strTime,
- szResultMsg );
- if( nResult != 0 ) //发送失败
- {
- LOG4C((LOG_NOTICE, "Email to %s, Contect:%s send lost: %s", strEmail, pContent, szResultMsg));
- }
- else
- {
- CDBInterface::GetInstancePtr()->InsertEmailRecord(
- (char *)(LPCTSTR)strEmail,
- "",
- (char *)(LPCTSTR)strTime,
- pContent,
- "");
- LOG4C((LOG_NOTICE, "Email to %s, Contect:%s send success: %s", strEmail, pContent, szResultMsg));
- }
- }
- }
- }
- }
- }
- return 0;
- }
- // 添加有管理某个设备所有用户的电话号码和手机号码
- void InsertUserTel(VAR_NOTICE *pVarNotice)
- {
- CString strTel;
- int nDevSize = (int)g_vtUserRoleInfo.size();
- for( int i = 0; i < nDevSize; i++ )
- {
- //TRACE("设备UID=%s\r\n", g_vtUserRoleInfo[i].szDevUID);
- if( strcmp(g_vtUserRoleInfo[i].szDevUID, pVarNotice->szDevUID) == 0 )
- {
- int nUserSize = (int)g_vtUserRoleInfo[i].vtUserInfo.size();
- for( int j = 0; j < nUserSize; j++ )
- {
- // 加入电话号码
- strTel = CString(g_vtUserRoleInfo[i].vtUserInfo[j].szTel);
- if( strTel.Compare("") )
- {
- pVarNotice->listTel.insert(pVarNotice->listTel.end(), strTel);
- //TRACE1("电话号码:%s\r\n", strTel);
- }
- //// 加入手机号码
- //strTel = CString(g_vtUserRoleInfo[i].vtUserInfo[j].szMobileTel);
- //if( strTel.Compare("") )
- //{
- // pVarNotice->listTel.insert(pVarNotice->listTel.end(), strTel);
- // //TRACE1("手机号码:%s\r\n", strTel);
- //}
- }
- }
- }
- }
- // 更新要发送对象的手机号码
- INT UpdateActiveTel( CHAR *pDevUid, CHAR *pStrTel )
- {
- int nSize = g_vtUserRoleInfo.size();
- for( int i = 0; i < nSize; i++ )
- {
- if( strcmp(g_vtUserRoleInfo[i].szDevUID, pDevUid) == 0 )
- {
- //g_vtUserTelInfo[i].strActiveTel = pStrTel;
- }
- }
- return 0;
- }
- // 报警状态恢复正常处理
- void ProcessVarStatusReturnNormal(char *pDevUid,
- int nVarID,
- int nAlarmStatus,
- int nNormalStatus,
- int nIdenfityTime,
- int nReDetectTime,
- int nNormalIsNotice,
- char *pDevName,
- char *pVarDesc,
- double dbData,
- char *pContent,
- VAR_NOTICE *pVarNotice,
- int nUpperLimit,
- int nLowerLimit )
- {
- if( nNormalIsNotice ) // 恢复正常触发远程报警
- {
- if( g_nSendNotice )
- {
- LIST_TEL::iterator it;
- CString *pStrTel;
- for( it = pVarNotice->listTel.begin(); it != pVarNotice->listTel.end(); it++ )
- {
- pStrTel = &(*it);
- // 加入语音发送list
- EnterCriticalSection( &g_csVarNotice );
- //LOG4C((LOG_NOTICE, "拔打恢复正常电话,号码:%s, 内容:%s", (char *)(LPCTSTR)*pStrTel, pContent));
- InsertSendNoticeList(pDevUid, nVarID, (char *)(LPCTSTR)*pStrTel, pContent,g_nAlarmIndex);
- //pVarNotice->listTel.erase(it);
- LeaveCriticalSection( &g_csVarNotice );
- }
- }
-
- //发送恢复正常信息给客户端
- g_pServerSocket[1]->AutoSendAlarmDataToClient( pDevUid,nVarID,1,pContent,dbData,nUpperLimit,nLowerLimit,nNormalStatus,nAlarmStatus,g_nAlarmIndex );
- int nDeviceIndex = -1, nVarIndex = -1;
- BOOL bFind = FindVar(pDevUid, nVarID, nDeviceIndex, nVarIndex);
- if( bFind == TRUE )
- {
- CDevice *pDev = g_pDevicesManager->m_Devices[nDeviceIndex];
- CBaseVar *pBaseVar = pDev->m_Vars[nVarIndex];
- EnterCriticalSection( &g_csVarNotice );
- pBaseVar->m_nAlarmNumber = 0;
- pVarNotice->nLastStatus = nAlarmStatus;
- pVarNotice->nCallTime = 0;
- pVarNotice->nSmsTime = 0;
- LeaveCriticalSection( &g_csVarNotice );
- }
- if( g_nSendSms==1 )
- {
- // 发送短信
- InsertSendSmsList( pDevUid, nVarID, pContent,g_nAlarmIndex );
- //SendSms(pDevUid, nVarID, pContent);
- }
- else if( g_nSendSms==2 )//支持短信平台
- {
- WriteToTxt(pDevUid, nVarID, pContent,g_nAlarmIndex);
- }
- if( g_nSendEmail )
- {
- // 发送Email
- SendEmail(pDevUid, nVarID, pContent);
- }
- }
- g_nAlarmIndex++;
- if( g_nAlarmIndex>=1000 )
- g_nAlarmIndex = 0;
- CString strTime;
- CTime tm;
- tm = CTime::GetCurrentTime();
- strTime = tm.Format("%Y-%m-%d %H:%M:%S");
- CDBInterface::GetInstancePtr()->InsertWarningRecord(pDevName, pVarDesc, (char *)(LPCTSTR)strTime, nAlarmStatus, dbData, "", pContent);
- }
- void ProcessVarAlarm(char *pDevUid,
- int nVarID,
- int nAlarmStatus,
- int nNormalStatus,
- int nIdenfityTime,
- int nReDetectTime,
- int nNormalIsNotice,
- char *pDevName,
- char *pVarDesc,
- double dbData,
- char *pContent,
- VAR_NOTICE *pVarNotice,
- int nUpperLimit,
- int nLowerLimit )
- {
- if( pVarNotice->nCallTime > g_nNoticeCallTimes - 1 ) // 第一次拔打没算次数, 所以这里减1
- {
- if( pVarNotice->dwReDetectTick == 0 )
- {
- EnterCriticalSection( &g_csVarNotice );
- pVarNotice->dwReDetectTick = GetTickCount();
- LeaveCriticalSection( &g_csVarNotice );
- }
- // 超过重新检测等待时间,从list中删除该变量
- if( GetTickCount() - pVarNotice->dwReDetectTick > (DWORD)(nReDetectTime * 1000 * 60) )
- {
- int nDeviceIndex = -1, nVarIndex = -1;
- BOOL bFind = FindVar(pDevUid, nVarID, nDeviceIndex, nVarIndex);
- if( bFind == TRUE )
- {
- CDevice *pDev = g_pDevicesManager->m_Devices[nDeviceIndex];
- CBaseVar *pBaseVar = pDev->m_Vars[nVarIndex];
- EnterCriticalSection( &g_csVarNotice );
- pBaseVar->m_nAlarmNumber = 0;
- pBaseVar->m_nAlarmStatus = 0;
- LeaveCriticalSection( &g_csVarNotice );
- }
- // 从list中删除变量时,要保证其它地方不去取list变量
- EnterCriticalSection( &g_csVarNotice ); // ResetEvent时也不允许任何人进来,故此把临界区放在ResetEvent之前。
- ResetEvent( g_hDeleteVarSem );
- DeleteVarNoticeList(pDevUid, nVarID);
- SetEvent( g_hDeleteVarSem );
- LeaveCriticalSection( &g_csVarNotice );
- }
- return;
- }
-
- //语音通知
- if( g_nSendNotice )
- {
- LIST_TEL::iterator it;
- CString *pStrTel;
- for( it = pVarNotice->listTel.begin(); it != pVarNotice->listTel.end(); it++ )
- {
- pStrTel = &(*it);
- // 加入语音发送list
- EnterCriticalSection( &g_csVarNotice );
- //LOG4C((LOG_NOTICE, "拔打报警电话,号码:%s, 内容:%s", (char *)(LPCTSTR)*pStrTel, pContent));
- InsertSendNoticeList(pDevUid, nVarID, (char *)(LPCTSTR)*pStrTel, pContent,g_nAlarmIndex);
- LeaveCriticalSection( &g_csVarNotice );
- }
- }
-
- //发送报警信息给客户端
- g_pServerSocket[1]->AutoSendAlarmDataToClient( pDevUid,nVarID,0,pContent,dbData,nUpperLimit,nLowerLimit,nNormalStatus,nAlarmStatus,g_nAlarmIndex );
- EnterCriticalSection( &g_csVarNotice );
- pVarNotice->nCallTime++;
- LeaveCriticalSection( &g_csVarNotice );
- if( pVarNotice->nSmsTime > g_nSmsCallTimes - 1 ) // 第一次发送没算次数, 所以这里减1
- {
- if( g_nSendNotice == 0 )
- {
- if( pVarNotice->dwReDetectTick == 0 )
- {
- EnterCriticalSection( &g_csVarNotice );
- pVarNotice->dwReDetectTick = GetTickCount();
- LeaveCriticalSection( &g_csVarNotice );
- }
- // 超过重新检测等待时间,从list中删除该变量
- if( GetTickCount() - pVarNotice->dwReDetectTick > (DWORD)(nReDetectTime * 1000 * 60) )
- {
- int nDeviceIndex = -1, nVarIndex = -1;
- BOOL bFind = FindVar(pDevUid, nVarID, nDeviceIndex, nVarIndex);
- if( bFind == TRUE )
- {
- CDevice *pDev = g_pDevicesManager->m_Devices[nDeviceIndex];
- CBaseVar *pBaseVar = pDev->m_Vars[nVarIndex];
- EnterCriticalSection( &g_csVarNotice );
- pBaseVar->m_nAlarmNumber = 0;
- pBaseVar->m_nAlarmStatus = 0;
- LeaveCriticalSection( &g_csVarNotice );
- }
- // 从list中删除变量时,要保证其它地方不去取list变量
- EnterCriticalSection( &g_csVarNotice ); // ResetEvent时也不允许任何人进来,故此把临界区放在ResetEvent之前。
- ResetEvent( g_hDeleteVarSem );
- DeleteVarNoticeList(pDevUid, nVarID);
- SetEvent( g_hDeleteVarSem );
- LeaveCriticalSection( &g_csVarNotice );
- }
- }
- return;
- }
- //LOG4C((LOG_NOTICE, "send sms:%s", pContent));
- //短信通知
- if( g_nSendSms==1 )
- {
- // 发送短信,所有用户一次性发完
- InsertSendSmsList( pDevUid, nVarID, pContent,g_nAlarmIndex );
- //SendSms(pDevUid, nVarID, pContent);
- }
- else if( g_nSendSms==2 )//支持短信平台
- {
- WriteToTxt(pDevUid, nVarID, pContent,g_nAlarmIndex);
- }
- //邮件通知
- if( g_nSendEmail )
- {
- // 发送Email,所有用户一次性发完
- SendEmail(pDevUid, nVarID, pContent);
- }
- EnterCriticalSection( &g_csVarNotice );
- pVarNotice->nSmsTime++;
- LeaveCriticalSection( &g_csVarNotice );
- g_nAlarmIndex++;
- if( g_nAlarmIndex>=1000 )
- g_nAlarmIndex = 0;
- CString strTime;
- CTime tm;
- tm = CTime::GetCurrentTime();
- strTime = tm.Format("%Y-%m-%d %H:%M:%S");
- CDBInterface::GetInstancePtr()->InsertWarningRecord(pDevName, pVarDesc, (char *)(LPCTSTR)strTime, nAlarmStatus, dbData, "", pContent);
- }
- // 处理变量远程报警通知
- int ProcessVarNotice(char *pDevUid,
- int nVarID,
- int nUpperLimit,
- int nLowerLimit,
- int nOffSet,
- int nAlarmStatus,
- int nNormalStatus,
- int nIdenfityTime,
- int nReDetectTime,
- int nNormalIsNotice,
- char *pDevName,
- char *pVarDesc,
- double dbData,
- char *pContent)
- {
- VAR_NOTICE *pVarNotice = NULL;
- pVarNotice = FindVarNoticeList(pDevUid, nVarID);
- if( NULL == pVarNotice )
- {
- if( nAlarmStatus != nNormalStatus )
- {
- CString strTemp = CString(pContent);
- if( strTemp.Find(g_strHintReturnNormal) != -1 )
- {
- return 0;
- }
- VAR_NOTICE tagVarNotice;
- strcpy(tagVarNotice.szDevUID, pDevUid);
- tagVarNotice.nVarID = nVarID;
- tagVarNotice.nResult = 0;
- tagVarNotice.nCallTime = 0;
- tagVarNotice.nSmsTime = 0;
- tagVarNotice.bQueueExist = false;
- tagVarNotice.dwIdentityTick = GetTickCount(); // 记录辨识时间
- tagVarNotice.dwIntervalTick = 0;
- tagVarNotice.dwReDetectTick = 0;
- tagVarNotice.nLastStatus = nAlarmStatus;
- tagVarNotice.bFirstDeal = true;
- // 添加有权限用户的电话号码和手机号码
- InsertUserTel(&tagVarNotice);
- tagVarNotice.nTelInex = 0;
- // 加入list,第一次加入不进行任何处理
- EnterCriticalSection( &g_csVarNotice );
- InsertVarNoticeList(tagVarNotice);
- LeaveCriticalSection( &g_csVarNotice );
- }
- }
- else
- {
- if( nAlarmStatus == nNormalStatus ) // 正常状态
- {
- // 防止报警恢复正常之后会一直打电话
- if( nAlarmStatus == pVarNotice->nLastStatus )
- {
- EnterCriticalSection( &g_csVarNotice );
- pVarNotice->nLastStatus = nAlarmStatus;
- LeaveCriticalSection( &g_csVarNotice );
- return 0;
- }
- EnterCriticalSection( &g_csVarNotice );
- pVarNotice->nLastStatus = nAlarmStatus;
- LeaveCriticalSection( &g_csVarNotice );
- //模拟量才有偏移量
- if( nOffSet > 0 )//当偏移量大于0时,判断当前值是否达到偏移量这个条件
- {
- CString strTemp = CString(pContent);
- //if( strTemp.Find(g_strHintReturnNormal) != -1 )//chn modify
- {
- if( dbData <= nUpperLimit - nOffSet || dbData >= nLowerLimit + nOffSet )
- {
- ProcessVarStatusReturnNormal(pDevUid, nVarID, nAlarmStatus, nNormalStatus, nIdenfityTime,
- nReDetectTime, nNormalIsNotice, pDevName, pVarDesc, dbData, pContent, pVarNotice,nUpperLimit,nLowerLimit );
- }
- }
- }
- else
- {
- ProcessVarStatusReturnNormal(pDevUid, nVarID, nAlarmStatus, nNormalStatus, nIdenfityTime,
- nReDetectTime, nNormalIsNotice, pDevName, pVarDesc, dbData, pContent, pVarNotice,nUpperLimit,nLowerLimit );
- }
- }
- else if( nAlarmStatus != nNormalStatus ) // 报警状态
- {
- //因为第一次加入List不进行任何处理,但状态已经保存,所以要加一个标志来判断一下
- if( nAlarmStatus == pVarNotice->nLastStatus && !pVarNotice->bFirstDeal )
- {
- EnterCriticalSection( &g_csVarNotice );
- pVarNotice->nLastStatus = nAlarmStatus;
- LeaveCriticalSection( &g_csVarNotice );
- return 0;
- }
- pVarNotice->bFirstDeal = false;//
- EnterCriticalSection( &g_csVarNotice );
- pVarNotice->nLastStatus = nAlarmStatus;
- LeaveCriticalSection( &g_csVarNotice );
- if( nOffSet > 0 )
- {
- CString strTemp = CString(pContent);
- //if( strTemp.Find(g_strHintUpperLimit) != -1 || strTemp.Find(g_strHintLowerLimit) != -1 )
- {
- if( dbData > nUpperLimit + nOffSet || dbData < nLowerLimit - nOffSet )
- {
- ProcessVarAlarm(pDevUid, nVarID, nAlarmStatus, nNormalStatus, nIdenfityTime,
- nReDetectTime, nNormalIsNotice, pDevName, pVarDesc, dbData, pContent, pVarNotice,nUpperLimit,nLowerLimit );
- }
- }
- }
- else
- {
- ProcessVarAlarm(pDevUid, nVarID, nAlarmStatus, nNormalStatus, nIdenfityTime,
- nReDetectTime, nNormalIsNotice, pDevName, pVarDesc, dbData, pContent, pVarNotice,nUpperLimit,nLowerLimit );
- }
- }
- }
- return 1;
- }
- ///////////////////////////////////////////////////////////////////////
- // 报警变量list,主要报警处理,防止一直加入通知list中
- // 从list中查找变量,没找到返回空,找到返回相应的指针地址
- VAR_NOTICE* FindVarNoticeList(char *pDevUid, int nVarID)
- {
- VAR_NOTICE* pVarNotice = NULL;
- LIST_VAR_NOTICE::iterator it;
- for( it = g_listVarNotice.begin(); it != g_listVarNotice.end(); it++ )
- {
- if( strcmp(it->szDevUID, pDevUid) == 0 &&
- it->nVarID == nVarID )
- {
- pVarNotice = &(*it);
- }
- }
- return pVarNotice;
- }
- // 添加变量到list
- void InsertVarNoticeList(char *pDevUid, int nVarID)
- {
- VAR_NOTICE tagVarNotice;
- strcpy(tagVarNotice.szDevUID, pDevUid);
- tagVarNotice.nVarID = nVarID;
- g_listVarNotice.insert(g_listVarNotice.end(), tagVarNotice);
- }
- // 添加变量到list
- void InsertVarNoticeList(VAR_NOTICE varNotice)
- {
- g_listVarNotice.insert(g_listVarNotice.end(), varNotice);
- }
- // 从list中移除变量
- int DeleteVarNoticeList(char *pDevUid, int nVarID)
- {
- int nRet = -1;
- VAR_NOTICE* pVarNotice = NULL;
- LIST_VAR_NOTICE::iterator it;
- for( it = g_listVarNotice.begin(); it != g_listVarNotice.end(); )
- {
- pVarNotice = &(*it);
- if( strcmp(pVarNotice->szDevUID, pDevUid) == 0 &&
- pVarNotice->nVarID == nVarID )
- {
- g_listVarNotice.erase(it++);
- nRet = 0;
- break;
- }
- else
- {
- it++;
- }
- }
- return nRet;
- }
- // 删除所有变量
- void DeleteAllVarNoticeList()
- {
- LIST_VAR_NOTICE::iterator it;
- for( it = g_listVarNotice.begin(); it != g_listVarNotice.end(); )
- {
- g_listVarNotice.erase(it++);
- }
- }
- ///////////////////////////////////////////////////////////////////////////
- // 发送通知list, 和上面的设备变量不同
- // 从list中查找变量,没找到返回空,找到返回相应的指针地址
- SEND_NOTICE* FindSendNoticeList(char *pDevUid, int nVarID)
- {
- SEND_NOTICE* pSendNotice = NULL;
- LIST_SEND_NOTICE::iterator it;
- for( it = g_listSendNotice.begin(); it != g_listSendNotice.end(); it++ )
- {
- if( strcmp(it->szDevUID, pDevUid) == 0 && it->nVarID == nVarID )
- {
- pSendNotice = &(*it);
- }
- }
- return pSendNotice;
- }
- // 添加变量到list
- void InsertSendNoticeList(char *pDevUid, int nVarID, char *pTel, char *pContent,int nAlarmIndex )
- {
- if( pStoneUDLLTxtToWav )
- {
- //生成WAV
- CString sTemp;
- sTemp.Format( "%s%s",pContent,g_strHintVoiceEnd );
- CString strFileName1;
- strFileName1.Format("%s\\wav\\temp_%s_%d_%d.wav", g_strDirectory, pDevUid, nVarID,nAlarmIndex );
- pStoneUDLLTxtToWav( (char *)(LPCTSTR)sTemp, (char *)(LPCTSTR)strFileName1, g_nTTSType, -3, 100 ); //设置音量,范围是 0 - 100
- CString strFileName2;
- strFileName2.Format("%s\\wav\\temp_%s_%d_%d_IDE.wav", g_strDirectory, pDevUid, nVarID,nAlarmIndex );
- pStoneUDLLTxtToWav( pContent, (char *)(LPCTSTR)strFileName2, g_nTTSType, -3, 100 ); //设置音量,范围是 0 - 100
- //结束生成
- }
- SEND_NOTICE tagSendNotice;
- strcpy(tagSendNotice.szDevUID, pDevUid);
- tagSendNotice.nVarID = nVarID;
- strcpy(tagSendNotice.szTel, pTel);
- strcpy(tagSendNotice.szContect, pContent);
- tagSendNotice.nAlarmIndex = nAlarmIndex;
- GetLocalTime( &tagSendNotice.time );
- EnterCriticalSection( &g_csSendNotice );
- g_listSendNotice.insert(g_listSendNotice.end(), tagSendNotice);
- LeaveCriticalSection( &g_csSendNotice );
- }
- // 从list中移除变量
- int DeleteSendNoticeList(char *pDevUid, int nVarID)
- {
- int nRet = -1;
- SEND_NOTICE* pSendNotice = NULL;
- LIST_SEND_NOTICE::iterator it;
- for( it = g_listSendNotice.begin(); it != g_listSendNotice.end(); )
- {
- pSendNotice = &(*it);
- if( strcmp(pSendNotice->szDevUID, pDevUid) == 0 && pSendNotice->nVarID == nVarID )
- {
- EnterCriticalSection( &g_csSendNotice );
- g_listSendNotice.erase(it++);
- LeaveCriticalSection( &g_csSendNotice );
- nRet = 0;
- break;
- }
- else
- {
- it++;
- }
- }
- return nRet;
- }
- // IDE确认后从list中移除变量
- int DeleteSendNoticeList( char *pDevUid, int nVarID,int iAlarmIndex )
- {
- int nRet = -1;
- SEND_NOTICE* pSendNotice = NULL;
- LIST_SEND_NOTICE::iterator it;
- for( it = g_listSendNotice.begin(); it != g_listSendNotice.end(); )
- {
- pSendNotice = &(*it);
- if( strcmp(pSendNotice->szDevUID, pDevUid) == 0 && pSendNotice->nVarID == nVarID && pSendNotice->nAlarmIndex==iAlarmIndex )
- {
- //删除WAV
- CString strFileName1;
- strFileName1.Format("%s\\wav\\temp_%s_%d_%d.wav", g_strDirectory, pDevUid, nVarID,iAlarmIndex );
- if( PathFileExists(strFileName1) )
- DeleteFile( strFileName1 );
- CString strFileName2;
- strFileName2.Format("%s\\wav\\temp_%s_%d_%d_IDE.wav", g_strDirectory, pDevUid, nVarID,iAlarmIndex );
- if( PathFileExists(strFileName2) )
- DeleteFile( strFileName2 );
- //结束删除
- LOG4C((LOG_NOTICE, "IDE确认語音 %s %s",pSendNotice->szTel,pSendNotice->szContect));
-
- EnterCriticalSection( &g_csSendNotice );
- g_listSendNotice.erase(it++);
- LeaveCriticalSection( &g_csSendNotice );
- }
- else
- {
- it++;
- }
- }
- return nRet;
- }
- // 删除所有变量
- void DeleteAllSendNoticeList()
- {
- #if 0
- // 正确使用方法1
- std::list< int> List;
- std::list< int>::iterator itList;
- for( itList = List.begin(); itList != List.end(); )
- {
- if( WillDelete( *itList) )
- {
- itList = List.erase( itList);
- }
- else
- itList++;
- }
- // 正确使用方法2
- std::list< int> List;
- std::list< int>::iterator itList;
- for( itList = List.begin(); itList != List.end(); )
- {
- if( WillDelete( *itList) )
- {
- List.erase( itList++);
- }
- else
- itList++;
- }
- // 错误使用方法1
- std::list< int> List;
- std::list< int>::iterator itList;
- for( itList = List.begin(); itList != List.end(); itList++)
- {
- if( WillDelete( *itList) )
- {
- List.erase( itList);
- }
- }
- // 错误使用方法2
- std::list< int> List;
- std::list< int>::iterator itList;
- for( itList = List.begin(); itList != List.end(); )
- {
- if( WillDelete( *itList) )
- {
- itList = List.erase( ++itList);
- }
- else
- itList++;
- }
- #endif
- LIST_SEND_NOTICE::iterator it;
- for( it = g_listSendNotice.begin(); it != g_listSendNotice.end(); )
- {
- g_listSendNotice.erase( it++ );
- }
- }
- // 添加变量到Sms list
- void InsertSendSmsList(char *pDevUid, int nVarID, char *pContent,int nAlarmIndex )
- {
- //LOG4C((LOG_NOTICE, "InsertSendSmsList" ));
- SEND_NOTICE tagSendNotice;
- strcpy(tagSendNotice.szDevUID, pDevUid);
- tagSendNotice.nVarID = nVarID;
- strcpy(tagSendNotice.szTel, "");
- strcpy(tagSendNotice.szContect, pContent);
- tagSendNotice.nAlarmIndex = nAlarmIndex;
- GetLocalTime( &tagSendNotice.time );
- EnterCriticalSection( &g_csSendNotice );
- g_listSendSms.insert(g_listSendSms.end(), tagSendNotice);
- LeaveCriticalSection( &g_csSendNotice );
-
- }
- // IDE确认后从Sms list中移除变量
- int DeleteSendSmsList( char *pDevUid, int nVarID,int iAlarmIndex )
- {
- int nRet = -1;
- SEND_NOTICE* pSendNotice = NULL;
- LIST_SEND_NOTICE::iterator it;
- for( it = g_listSendSms.begin(); it != g_listSendSms.end(); )
- {
- pSendNotice = &(*it);
- if( strcmp(pSendNotice->szDevUID, pDevUid) == 0 && pSendNotice->nVarID == nVarID && pSendNotice->nAlarmIndex==iAlarmIndex )
- {
- LOG4C((LOG_NOTICE, "IDE确认短信 %s",pSendNotice->szContect));
- EnterCriticalSection( &g_csSendNotice );
- g_listSendSms.erase(it++);
- LeaveCriticalSection( &g_csSendNotice );
- nRet = 0;
- break;
- }
- else
- {
- it++;
- }
- }
- return nRet;
- }
- // 删除Sms所有变量
- void DeleteAllSendSmsList()
- {
- LIST_SEND_NOTICE::iterator it;
- for( it = g_listSendSms.begin(); it != g_listSendSms.end(); )
- {
- g_listSendSms.erase( it++ );
- }
- }
- int GetTelIndex( char *pDevUid, int nVarID, CString sTel )
- {
- int nRet=-1;
- if( g_listVarNotice.size()==0 )
- {
- LOG4C((LOG_NOTICE, "g_listVarNotice.size()= %d",g_listVarNotice.size()==0));
- return nRet;
- }
- VAR_NOTICE* pVarNotice = NULL;
- LIST_VAR_NOTICE::iterator it;
- for( it = g_listVarNotice.begin(); it != g_listVarNotice.end(); it++ )
- {
- if( strcmp(it->szDevUID, pDevUid) == 0 && it->nVarID == nVarID )
- {
- pVarNotice = &(*it);
- break;
- }
- }
-
- if( pVarNotice )
- {
- LIST_TEL::iterator itTel;
- CString *pStrTel;
- for( itTel = pVarNotice->listTel.begin(); itTel != pVarNotice->listTel.end(); itTel++ )
- {
- pStrTel = &(*itTel);
- nRet++;
- if( strcmp(sTel, *pStrTel) == 0 )
- {
- break;
- }
- }
- }
- else
- LOG4C((LOG_NOTICE, "pVarNotice=NULL g_listVarNotice.size() = %d",g_listVarNotice.size()));
- return nRet;
- }
- ////////////////////////////////////////////////////////////////////////////////
- DWORD WINAPI SendNoticeThread(LPVOID lpParameter)
- {
- do
- {
- if( g_listSendNotice.size() > 0 )
- {
- SEND_NOTICE *pSendNotice;
- LIST_SEND_NOTICE::iterator it;
- it = g_listSendNotice.begin();
- pSendNotice = &(*it);
- CString sCurrentTel;
- if( pSendNotice )
- {
- SYSTEMTIME st;
- GetLocalTime( &st );
- CTime time1(st);
- CTime time2(pSendNotice->time);
- CTimeSpan spantime = time1 - time2;
- int nSecNum = spantime.GetSeconds() + spantime.GetMinutes()*60 + spantime.GetHours()*60*60;
- if( nSecNum > NOTICE_DELAY )
- {
- LOG4C((LOG_NOTICE, "开始拨打电话 %s",pSendNotice->szTel));
- int nRet = SendNotice(pSendNotice->szDevUID, pSendNotice->nVarID,pSendNotice->nAlarmIndex, pSendNotice->szTel, pSendNotice->szContect);
- sCurrentTel.Format( "%s",pSendNotice->szTel );
- LOG4C((LOG_NOTICE, "结束拨打电话 %s",pSendNotice->szTel));
- //删除WAV
- CString strFileName1;
- strFileName1.Format("%s\\wav\\temp_%s_%d_%d.wav", g_strDirectory, pSendNotice->szDevUID, pSendNotice->nVarID,pSendNotice->nAlarmIndex );
- if( PathFileExists(strFileName1) )
- DeleteFile( strFileName1 );
- CString strFileName2;
- strFileName2.Format("%s\\wav\\temp_%s_%d_%d_IDE.wav", g_strDirectory, pSendNotice->szDevUID, pSendNotice->nVarID,pSendNotice->nAlarmIndex );
- if( PathFileExists(strFileName2) )
- DeleteFile( strFileName2 );
- //结束删除
- if( nRet==CALL_SUCCESS_SINGLE_CONFIRM )//确认当前通知
- {
- int nCurrentTelIndex=0,nTelIndex=0;
- nCurrentTelIndex = GetTelIndex( pSendNotice->szDevUID, pSendNotice->nVarID, sCurrentTel );
-
- EnterCriticalSection( &g_csSendNotice );
- g_listSendNotice.erase(it++);//先把当前的删除
- LeaveCriticalSection( &g_csSendNotice );
- if( g_listSendNotice.size() > 0 )
- {
- CTime time = CTime::GetCurrentTime();
- CString strTime;
- strTime = time.Format("%Y-%m-%d %H:%M:%S");
- CDBInterface::GetInstancePtr()->InsertNoticeRecord(
- (char *)(LPCTSTR)sCurrentTel,
- "",
- (char *)(LPCTSTR)strTime,
- "config one alert",
- "");
- EnterCriticalSection( &g_csSendNotice );
- LIST_SEND_NOTICE::iterator itTemp;
- for( itTemp = g_listSendNotice.begin(); itTemp != g_listSendNotice.end(); )
- {
- nTelIndex = GetTelIndex( itTemp->szDevUID,itTemp->nVarID,itTemp->szTel );
- //LOG4C((LOG_NOTICE, "%s,nCurrentTelIndex = %d,%s,nTelIndex=%d ",sCurrentTel,nCurrentTelIndex,itTemp->szTel,nTelIndex ));
- if( nCurrentTelIndex<nTelIndex )
- {
- LOG4C((LOG_NOTICE, "通知已经被确认,跳过号码 %s",itTemp->szTel ));
- g_listSendNotice.erase(itTemp++);
- }
- else
- {
- break;
- }
- }
- LeaveCriticalSection( &g_csSendNotice );
- }
- }
- else if( nRet==CALL_SUCCESS_ALL_CONFIRM )//确认全部通知
- {
- EnterCriticalSection( &g_csSendNotice );
- g_listSendNotice.erase(it++);//先把当前的删除
- if( g_listSendNotice.size() > 0 )
- {
- CTime time = CTime::GetCurrentTime();
- CString strTime;
- strTime = time.Format("%Y-%m-%d %H:%M:%S");
- CDBInterface::GetInstancePtr()->InsertNoticeRecord(
- (char *)(LPCTSTR)sCurrentTel,
- "",
- (char *)(LPCTSTR)strTime,
- "config all alert",
- "");
- LIST_SEND_NOTICE::iterator itTemp;
- for( itTemp = g_listSendNotice.begin(); itTemp != g_listSendNotice.end(); )
- {
- LOG4C((LOG_NOTICE, "通知全部已经被确认,跳过号码 %s",itTemp->szTel ));
- g_listSendNotice.erase(itTemp++);
- }
- }
- LeaveCriticalSection( &g_csSendNotice );
- }
- else if( nRet != CALL_LOST )
- {
- EnterCriticalSection( &g_csSendNotice );
- g_listSendNotice.erase(it++);
- LeaveCriticalSection( &g_csSendNotice );
- }
- }
- Sleep( 10 * 1000 );//Sleep( 30 * 1000 );
- }
- }
- }while( WaitForSingleObject(g_hRunObject, 200L) == WAIT_TIMEOUT );
- return 0;
- }
- DWORD WINAPI SendSmsThread(LPVOID lpParameter)
- {
- do
- {
- if( g_listSendSms.size() > 0 )
- {
- SEND_NOTICE *pSendNotice;
- LIST_SEND_NOTICE::iterator it;
- it = g_listSendSms.begin();
- pSendNotice = &(*it);
- CString sCurrentTel;
- if( pSendNotice )
- {
- //LOG4C((LOG_NOTICE, "SendSmsThread size>0" ));
- SYSTEMTIME st;
- GetLocalTime( &st );
- CTime time1(st);
- CTime time2(pSendNotice->time);
- CTimeSpan spantime = time1 - time2;
- int nSecNum = spantime.GetSeconds() + spantime.GetMinutes()*60 + spantime.GetHours()*60*60;
- if( nSecNum > NOTICE_DELAY )
- {
- //LOG4C((LOG_NOTICE, "SendSmsThread NOTICE_DELAY" ));
- SendSms( pSendNotice->szDevUID,pSendNotice->nVarID,pSendNotice->szContect );
- EnterCriticalSection( &g_csSendNotice );
- g_listSendSms.erase(it++);
- LeaveCriticalSection( &g_csSendNotice );
- }
- }
- }
- }while( WaitForSingleObject(g_hRunObject, 200L) == WAIT_TIMEOUT );
- return 0;
- }
- int GetVarstatus(double iParaValue, int iUpperLimit, int iLowerLimit, int iNormalState)
- {
- int iResult = iNormalState;
- if ( ( iUpperLimit >0 || iLowerLimit > 0 ) && iUpperLimit > iLowerLimit)
- {
- //iResult = (iParaValue >= iUpperLimit || iParaValue <= iLowerLimit);
- if( iParaValue > iUpperLimit )
- {
- iResult = UPPER_LIMIT_ID; // 上限告警
- }
- if( iParaValue < iLowerLimit )
- {
- iResult = LOWER_LIMIT_ID; // 下限告警
- }
- else
- {
- return iResult;
- }
- }
- else if( (int)iParaValue != iNormalState )
- {
- iResult = (int)iParaValue;
- }
- return iResult;
- }
- int VarAlarmNotice(CDevice *pDev, CBaseVar *pBaseVar)
- {
- // 组织报警内容
- CString strContect;
- char szStatusDesc[MAX_EQUIP_DESC + 1] = {0};
- char szStatusID[MAX_ID + 1] = {0};
- memset(szStatusDesc, 0, sizeof(szStatusDesc));
- if( pBaseVar->m_nWaringLevel == 0 ) return 1;
- int nTempStatus = GetVarstatus(pBaseVar->m_dbData, pBaseVar->m_nUpperLimit, pBaseVar->m_nLowerLimit, pBaseVar->m_nNormalState);
- if( UPPER_LIMIT_ID == nTempStatus ) // 上限告警
- {
- strcpy(szStatusDesc, g_strHintUpperLimit);
- //LOG4C((LOG_NOTICE, "var desc = %s, %s", pBaseVar->m_strDesc, szStatusDesc));
- }
- else if( LOWER_LIMIT_ID == nTempStatus ) // 下限告警
- {
- strcpy(szStatusDesc, g_strHintLowerLimit);
- }
- else if( nTempStatus != pBaseVar->m_nNormalState )
- {
- list<string>::iterator it_desc, it_id;
- if( pBaseVar->m_listStatusDesc.size() > 0 && pBaseVar->m_listStatusID.size() > 0 )
- {
- for( it_desc = pBaseVar->m_listStatusDesc.begin(), it_id = pBaseVar->m_listStatusID.begin();
- it_desc != pBaseVar->m_listStatusDesc.end(), it_id != pBaseVar->m_listStatusID.end(); )
- {
- CString strStatusID = (*it_id++).c_str();
- CString strStatusDesc = (*it_desc++).c_str();
- if( atoi(strStatusID) == nTempStatus )
- {
- //LOG4C((LOG_NOTICE, "var desc = %s, nTempStatus = %d, StatusID = %d statusdesc = %s, value = %d",pBaseVar->m_strDesc, nTempStatus, atoi(strStatusID), strStatusDesc, (int)pBaseVar->m_dbData));
- strcpy(szStatusDesc, (char *)(LPCTSTR)strStatusDesc);
- //LOG4C((LOG_NOTICE, "szStatusDesc=%s", szStatusDesc));
- break;
- }
- }
- }
- if( strcmp(szStatusDesc, "") == 0 )
- {
- //LOG4C((LOG_NOTICE, "VarAlarmNotice var = %s nTempStatus = %d NormalState = %d statudesc is null!", pBaseVar->m_strDesc, nTempStatus, pBaseVar->m_nNormalState));
- return 1;
- }
- }
- if( nTempStatus != pBaseVar->m_nNormalState ) // 报警状态
- {
- if( pBaseVar->m_bReserved1 == true )
- {
- if( pBaseVar->m_strReserved1.Compare("") == 0 )
- {
- strContect.Format("%s%s:%s, %s%d%s ", pDev->m_strReserved1, pBaseVar->m_strDesc, szStatusDesc, g_strHintCurrValue, (int)pBaseVar->m_dbData, pBaseVar->m_strUnit);
- }
- else
- {
- int nDeviceIndex = -1, nVarIndex = -1;
- BOOL bFind = FindVar(pBaseVar->m_strVarUID, pBaseVar->m_strReserved1, nDeviceIndex, nVarIndex);
- if( bFind == FALSE )
- {
- strContect.Format("%s%s:%s, %s%d%s ", pDev->m_strReserved1, pBaseVar->m_strDesc, szStatusDesc, g_strHintCurrValue, (int)pBaseVar->m_dbData, pBaseVar->m_strUnit);
- }
- else
- {
- CDevice *pDev = g_pDevicesManager->m_Devices[nDeviceIndex];
- CBaseVar *pTempBaseVar = pDev->m_Vars[nVarIndex];
- strContect.Format("%s%s:%s, %s%d%s ", pDev->m_strReserved1, pBaseVar->m_strDesc, szStatusDesc, g_strHintCurrValue, (int)pTempBaseVar->m_dbData, pBaseVar->m_strUnit);
- }
- }
- }
- else
- {
- strContect.Format("%s%s:%s ", pDev->m_strReserved1, pBaseVar->m_strDesc, szStatusDesc);
- }
- if( pBaseVar->m_bExistDatePlan )
- {
- if( pBaseVar->m_dwReturnNormalIdentityTick>0 )
- {
- pBaseVar->m_dwReturnNormalIdentityTick = 0;
- //LOG4C(( LOG_NOTICE,"var=%s 恢复正常未达到辩识时间条件又收到报警值,放弃加入",pBaseVar->m_strDesc));
- }
-
- if( pBaseVar->m_dwIdentityTick == 0 && pBaseVar->m_nAlarmStatus!=2 )
- {
- //EnterCriticalSection( &g_csVarNotice );
- pBaseVar->m_dwIdentityTick = GetTickCount();
- //LeaveCriticalSection( &g_csVarNotice );
- //LOG4C((LOG_NOTICE, "var=%s 达到报警条件", pBaseVar->m_strDesc));
- }
- else if( pBaseVar->m_nAlarmStatus==0 )
- {
- //LOG4C((LOG_NOTICE, "var=%s 第一次达到报警条件,不用判断辩识时间,直接加入", pBaseVar->m_strDesc));
- ProcessVarNotice(
- (char *)(LPCTSTR)pBaseVar->m_strVarUID,
- pBaseVar->m_nVarID,
- pBaseVar->m_nUpperLimit,
- pBaseVar->m_nLowerLimit,
- pBaseVar->m_nOffset,
- nTempStatus,
- pBaseVar->m_nNormalState,
- pBaseVar->m_nIdentifyTime,
- pBaseVar->m_nReDetectTime,
- pBaseVar->m_bNormalIsNotice,
- "",
- (char *)(LPCTSTR)pBaseVar->m_strDesc,
- pBaseVar->m_dbData,
- (char *)(LPCTSTR)strContect );
- EnterCriticalSection( &g_csVarNotice );
- pBaseVar->m_nAlarmStatus = 1;//设为第一次报警状态
- pBaseVar->m_strContent = strContect;
- pBaseVar->m_nLastStatus = nTempStatus;
- pBaseVar->m_dwIdentityTick = 0;
- LeaveCriticalSection( &g_csVarNotice );
- }
- else if( GetTickCount() - pBaseVar->m_dwIdentityTick > (DWORD)pBaseVar->m_nIdentifyTime * 1000 && pBaseVar->m_nAlarmStatus!=2 )
- {
- LOG4C((LOG_NOTICE, "var=%s 达到报警辩识时间条件,加入", pBaseVar->m_strDesc));
- if( 1 == g_nSnmpEnable )
- {
- CString strSetValue;
- strSetValue.Format("%.1f,A", pBaseVar->m_dbData);
- CString strTime;
- CTime tm;
- tm = CTime::GetCurrentTime();
- strTime = tm.Format("%Y-%m-%d %H:%M:%S");
- CString strTrapContent = "";
- strTrapContent.Format("%s_%s_%s,A", pDev->m_strDeviceName, strTime, strContect);
- //LOG4C((LOG_NOTICE, "%s", strSetValue));
- CString strObjID;
- strObjID.Format("%s.%d", g_strSnmpObjOid, pBaseVar->m_nVarID);
- pSnmpDllSetValue(
- g_strSnmpIP,
- g_strSnmpField,
- (char *)(LPCTSTR)strObjID,
- "str",
- 1,
- 300,
- (char *)(LPCTSTR)strTrapContent
- );
- }
- if( pBaseVar->m_nAlarmNumber < 10 )
- pBaseVar->m_nAlarmNumber++;
- ProcessVarNotice(
- (char *)(LPCTSTR)pBaseVar->m_strVarUID,
- pBaseVar->m_nVarID,
- pBaseVar->m_nUpperLimit,
- pBaseVar->m_nLowerLimit,
- pBaseVar->m_nOffset,
- nTempStatus,
- pBaseVar->m_nNormalState,
- pBaseVar->m_nIdentifyTime,
- pBaseVar->m_nReDetectTime,
- pBaseVar->m_bNormalIsNotice,
- "",
- (char *)(LPCTSTR)pBaseVar->m_strDesc,
- pBaseVar->m_dbData,
- (char *)(LPCTSTR)strContect );
-
- EnterCriticalSection( &g_csVarNotice );
- pBaseVar->m_nAlarmStatus = 2;//设为第二次报警状态
- pBaseVar->m_strContent = strContect;
- pBaseVar->m_nLastStatus = nTempStatus;
- pBaseVar->m_dwIdentityTick = 0;
- LeaveCriticalSection( &g_csVarNotice );
- }
- else
- {
- #if 0
- if( 1 == g_nSnmpEnable )
- {
- if( TRUE == pBaseVar->m_bIsChange )
- {
- CString strSetValue;
- strSetValue.Format("%.1f", pBaseVar->m_dbData);
- CString strObjID;
- strObjID.Format("%s.%d", g_strSnmpObjOid, pBaseVar->m_nVarID);
- pSnmpDllSetValue(
- g_strSnmpIP,
- g_strSnmpField,
- (char *)(LPCTSTR)strObjID,
- "str",
- 1,
- 300,
- (char *)(LPCTSTR)strSetValue
- );
- }
- }
- #endif
- }
- }
- }
- else
- {
- if( pBaseVar->m_dwIdentityTick>0 )
- {
- pBaseVar->m_dwIdentityTick = 0;
- //LOG4C(( LOG_NOTICE,"var=%s 报警未达到辩识时间条件又收到正常值,放弃加入",pBaseVar->m_strDesc));
- }
- if( pBaseVar->m_nAlarmNumber >= 1 && pBaseVar->m_nAlarmNumber < 11 )
- {
- strContect.Format("%s%s:%s ", pDev->m_strReserved1, pBaseVar->m_strDesc, g_strHintReturnNormal);
- if( pBaseVar->m_dwReturnNormalIdentityTick == 0 )
- {
- //EnterCriticalSection( &g_csVarNotice );
- pBaseVar->m_dwReturnNormalIdentityTick = GetTickCount();
- //LeaveCriticalSection( &g_csVarNotice );
- //LOG4C((LOG_NOTICE, "var=%s 达到恢复正常条件", pBaseVar->m_strDesc));
- }
- else if( GetTickCount() - pBaseVar->m_dwReturnNormalIdentityTick > (DWORD)pBaseVar->m_nIdentifyTime * 1000 )
- {
- LOG4C((LOG_NOTICE, "var=%s 达到恢复正常辩识时间条件,加入", pBaseVar->m_strDesc));
- pBaseVar->m_nAlarmNumber = 0;
- //回复正常
- ProcessVarNotice(
- (char *)(LPCTSTR)pBaseVar->m_strVarUID,
- pBaseVar->m_nVarID,
- pBaseVar->m_nUpperLimit,
- pBaseVar->m_nLowerLimit,
- pBaseVar->m_nOffset,
- nTempStatus,
- pBaseVar->m_nNormalState,
- pBaseVar->m_nIdentifyTime,
- pBaseVar->m_nReDetectTime,
- pBaseVar->m_bNormalIsNotice,
- "",
- (char *)(LPCTSTR)pBaseVar->m_strDesc,
- pBaseVar->m_dbData,
- (char *)(LPCTSTR)strContect );
-
- EnterCriticalSection( &g_csVarNotice );
- pBaseVar->m_nAlarmStatus = 3;//设为恢复正常状态
- pBaseVar->m_strContent = strContect;
- pBaseVar->m_nLastStatus = nTempStatus;
- pBaseVar->m_dwReturnNormalIdentityTick = 0;
- LeaveCriticalSection( &g_csVarNotice );
- if( 1 == g_nSnmpEnable )
- {
- CString strSetValue;
- strSetValue.Format("%.1f,N", pBaseVar->m_dbData);
- CString strTime;
- CTime tm;
- tm = CTime::GetCurrentTime();
- strTime = tm.Format("%Y-%m-%d %H:%M:%S");
- CString strTrapContent = "";
- strTrapContent.Format("%s_%s_%s,N", pDev->m_strDeviceName, strTime, strContect);
- //LOG4C((LOG_NOTICE, "%s", strTrapContent));
- CString strObjID;
- strObjID.Format("%s.%d", g_strSnmpObjOid, pBaseVar->m_nVarID);
- pSnmpDllSetValue(
- g_strSnmpIP,
- g_strSnmpField,
- (char *)(LPCTSTR)strObjID,
- "str",
- 1,
- 300,
- (char *)(LPCTSTR)strTrapContent
- );
- }
- }
- }
- else
- {
- #if 0
- if( 1 == g_nSnmpEnable )
- {
- if( TRUE == pBaseVar->m_bIsChange )
- {
- CString strSetValue;
- strSetValue.Format("%.1f", pBaseVar->m_dbData);
- CString strObjID;
- strObjID.Format("%s.%d", g_strSnmpObjOid, pBaseVar->m_nVarID);
- pSnmpDllSetValue(
- g_strSnmpIP,
- g_strSnmpField,
- (char *)(LPCTSTR)strObjID,
- "str",
- "str",
- 1,
- 300,
- (char *)(LPCTSTR)strSetValue
- );
- }
- }
- #endif
- }
- }
- return 0;
- }
|