12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372 |
- //////////////////////////////////////////////////////////////////////////////
- ////// //////
- ////// 文 件: 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"
- #include <io.h>
- int g_nAlarmIndex=0;//报警索引,为了在IDE上面确认而设
- int g_nAlarmIndexLast=-1;//上一次的報警索引,確保每次報警生成Wav文件只一次
- // 发送通知
- 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; // 报警索引
- int nCallTimes; // 拨打次数
- int nNoticeDelayTime; // 通知延时
- SYSTEMTIME time;
- }SEND_NOTICE, *PSEND_NOTICE;
- typedef list<SEND_NOTICE> LIST_SEND_NOTICE;
- LIST_SEND_NOTICE g_listSendVoice;
- LIST_SEND_NOTICE g_listSendSms;
- LIST_SEND_NOTICE g_listSendEmail;
- HANDLE g_hSendVoiceThread = NULL;
- HANDLE g_hSendSmsThread = NULL;
- HANDLE g_hSendEmailThread = NULL;
- HANDLE g_hCreateWavThread = NULL;
- HANDLE g_hCheckReDetectTimeThread = NULL;
- HANDLE g_hAWAThread = NULL;
- CRITICAL_SECTION g_csVarNotice; // 临界区对ProcessVarNotice过程全局变量进行保护
- CRITICAL_SECTION g_csSendVoice; // 电话临界区
- CRITICAL_SECTION g_csSendSms; // 短信临界区
- CRITICAL_SECTION g_csSendEmali; // 邮件临界区
- CRITICAL_SECTION g_csCreateWav;
- HANDLE g_hDeleteVarSem; // 所有读变量list, 都要等这个信号量,保证变量出队列成功后,才能读
- CStringArray g_saWavPath,g_saWavContent;
- // 删除所有变量
- void DeleteAllSendVoiceList();
- void DeleteAllSendSmsList();
- void DeleteAllSendEmailList();
- // 添加变量到語音list
- void InsertSendVoiceList(char *pDevUid, int nVarID, char *pTel, char *pContent,int nAlarmIndex);
- //IDE 确认后从語音list删除
- int DeleteSendVoiceList( 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 );
- // 添加变量到邮件list
- void InsertSendEmailList(char *pDevUid, int nVarID, char *pContent,int nAlarmIndex);
- //IDE 确认后从邮件list删除
- int DeleteSendEmailList( char *pDevUid, int nVarID,int iAlarmIndex );
- static DWORD WINAPI SendVoiceThread(LPVOID lpParameter);
- static DWORD WINAPI SendSmsThread(LPVOID lpParameter);
- static DWORD WINAPI SendEmailThread(LPVOID lpParameter);
- static DWORD WINAPI CreateWavThread(LPVOID lpParameter);
- static DWORD WINAPI CheckReDetectTimeThread(LPVOID lpParameter);
- static DWORD WINAPI AWAThread(LPVOID lpParameter);
- void GetAWAData()
- {
- //LOG4C((LOG_NOTICE, "GetAllActionWithAlarm in"));
- CDBInterface::GetInstancePtr()->GetAllActionWithAlarm();
- if( g_AWA[0].sDoSet!="" )
- {
- DWORD dwThreadId;
- MTVERIFY( g_hAWAThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)AWAThread,NULL, 0, &dwThreadId) );
- //LOG4C((LOG_NOTICE, "GetAllActionWithAlarm OK"));
- }
- }
- /************************************************************************/
- /* 函数:[1/26/2017 Home];
- /* 描述:初始化通知库;
- /* 参数:;
- /* [IN] :;
- /* [OUT] :;
- /* [IN/OUT] :;
- /* 返回:void;
- /* 注意:;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- int InitNotice(void)// 1语音卡不存在 2动态库不存在
- {
- if( g_hCheckReDetectTimeThread==NULL )
- {
- DWORD dwThreadId2;
- MTVERIFY( g_hCheckReDetectTimeThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)CheckReDetectTimeThread,
- NULL, 0, &dwThreadId2) );
- }
- MTVERIFY( g_hDeleteVarSem = CreateEvent(NULL, TRUE, TRUE, "DeleteVarList") );
- // 语音卡;
- InitializeCriticalSection( &g_csVarNotice );
- // 短信猫;
- InitializeCriticalSection( &g_csSendVoice );
- // 语音文件;
- InitializeCriticalSection( &g_csCreateWav );
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // 初始化远程报警通知;
- if( g_bSendVoice )
- {
- g_hVoiceLibModule = NULL;
- CHAR strFile[MAX_LIST_LENGTH + 1] = "";
- if( g_nNoticeCardType == 1 )
- {
- wsprintf(strFile, "%s\\Dll\\Voice.dll", g_strDirectory);
- g_hVoiceLibModule = ::LoadLibrary(strFile);
- if (NULL != g_hVoiceLibModule)
- {
- pStoneUDllRegisterVoice = (STONEU_DLLRegisterVoice)::GetProcAddress(g_hVoiceLibModule, "STONEU_DLLRegisterVoice");
- pStoneUDllUnRegisterVoice = (STONEU_DLLUnRegisterVoice)::GetProcAddress(g_hVoiceLibModule, "STONEU_DLLUnRegisterVoice");
- pStoneUDllAllocateChannel = (STONEU_DLLAllocateChannel)::GetProcAddress(g_hVoiceLibModule, "STONEU_DLLAllocateChannel");
- }
- if( ( NULL != g_hVoiceLibModule ) && ( NULL != pStoneUDllRegisterVoice ) )
- {
- int nRet = pStoneUDllRegisterVoice(g_strDirectory, g_nTTSType);
- if( nRet != 0 )
- {
- AfxFreeLibrary( g_hVoiceLibModule );
- g_hVoiceLibModule = NULL;
- g_bSendVoice = FALSE;
- return 1;
- }
- }
- else
- {
- AfxFreeLibrary( g_hVoiceLibModule );
- g_hVoiceLibModule = NULL;
- g_bSendVoice = FALSE;
- return 2;
- }
- }
- else if( g_nNoticeCardType == 2 )
- {
- wsprintf(strFile, "%s\\Dll\\UsbVoice.dll", g_strDirectory);
- g_hVoiceLibModule = ::LoadLibrary(strFile);
- if( NULL != g_hVoiceLibModule )
- {
- pStoneUDllRegisterVoice = (STONEU_DLLRegisterVoice)::GetProcAddress(g_hVoiceLibModule, "STONEU_DLLRegisterVoice");
- pStoneUDllUnRegisterVoice = (STONEU_DLLUnRegisterVoice)::GetProcAddress(g_hVoiceLibModule, "STONEU_DLLUnRegisterVoice");
- pStoneUDllAllocateChannel = (STONEU_DLLAllocateChannel)::GetProcAddress(g_hVoiceLibModule, "STONEU_DLLAllocateChannel");
- }
- if( ( NULL != g_hVoiceLibModule ) && ( NULL != pStoneUDllRegisterVoice ) )
- {
- int nRet = pStoneUDllRegisterVoice(g_strDirectory, g_nTTSType);
- if( nRet != 0 )
- {
- AfxFreeLibrary( g_hVoiceLibModule );
- g_hVoiceLibModule = NULL;
- g_bSendVoice = 0;
- return 1;
- }
- }
- else
- {
- AfxFreeLibrary( g_hVoiceLibModule );
- g_hVoiceLibModule = NULL;
- g_bSendVoice = 0;
- return 2;
- }
- }
- DWORD dwThreadId;
- MTVERIFY( g_hSendVoiceThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)SendVoiceThread,
- NULL, 0, &dwThreadId) );
- MTVERIFY( g_hCreateWavThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)CreateWavThread,
- 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;
- g_bSendVoice = 0;
- return 1;
- }
- }
- else
- {
- FreeLibrary( hTTSModule );
- hTTSModule = NULL;
- g_bSendVoice = 0;
- return 2;
- }
- }
- return 0;
- }
- void UnInitNotice(void)
- {
- if( g_hCheckReDetectTimeThread )
- {
- MTVERIFY( WaitForSingleObject( g_hCheckReDetectTimeThread, INFINITE ) != WAIT_FAILED );
- MTVERIFY( CloseHandle(g_hCheckReDetectTimeThread) );
- g_hCheckReDetectTimeThread = NULL;
- }
- if( g_hSendVoiceThread )
- {
- //MTVERIFY( SetEvent( g_hDeleteVarSem ) );
- MTVERIFY( WaitForSingleObject( g_hSendVoiceThread, INFINITE ) != WAIT_FAILED );
- MTVERIFY( CloseHandle(g_hSendVoiceThread) );
- g_hSendVoiceThread = NULL;
- }
- if( g_hCreateWavThread )
- {
- //MTVERIFY( SetEvent( g_hDeleteVarSem ) );
- MTVERIFY( WaitForSingleObject( g_hCreateWavThread, INFINITE ) != WAIT_FAILED );
- MTVERIFY( CloseHandle(g_hCreateWavThread) );
- g_hCreateWavThread = NULL;
- }
- if( g_hDeleteVarSem )
- {
- MTVERIFY( CloseHandle( g_hDeleteVarSem) );
- g_hDeleteVarSem = NULL;
- }
- if( g_bSendVoice )
- {
- if( ( NULL != g_hVoiceLibModule ) && ( NULL != pStoneUDllUnRegisterVoice ) )
- pStoneUDllUnRegisterVoice();
- if( ( NULL != hTTSModule ) && ( NULL != pStoneUDllUnRegisterTTS ) )
- pStoneUDllUnRegisterTTS();
- }
- DeleteAllSendEmailList();
- DeleteAllSendSmsList();
- DeleteAllSendVoiceList();
- DeleteAllVarNoticeList();
- DeleteCriticalSection( &g_csVarNotice );
- DeleteCriticalSection( &g_csSendVoice );
- DeleteCriticalSection( &g_csCreateWav );
- if (g_hVoiceLibModule != NULL)
- {
- ::FreeLibrary(g_hVoiceLibModule);
- g_hVoiceLibModule = 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 // 超时
- )
- {
- InitializeCriticalSection( &g_csSendEmali );
- DWORD dwThreadId2;
- MTVERIFY( g_hSendEmailThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)SendEmailThread,NULL, 0, &dwThreadId2) );
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- g_hEmailLibModule = NULL;
- CHAR strFile[MAX_LIST_LENGTH + 1] = "";
- wsprintf(strFile, "%s\\Dll\\Email.dll", g_strDirectory);
- g_hEmailLibModule = AfxLoadLibrary(strFile);
- if ( g_hEmailLibModule == NULL)
- {
- printf("加载Email.dll失败,错误码:%d\n", GetLastError());
- return -1;
- }
- 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( g_hSendEmailThread )
- {
- MTVERIFY( WaitForSingleObject( g_hSendEmailThread, INFINITE ) != WAIT_FAILED );
- MTVERIFY( CloseHandle(g_hSendEmailThread) );
- g_hSendEmailThread = NULL;
- }
- if( NULL != g_hEmailLibModule && NULL != pEmailDllUnInit )
- {
- pEmailDllUnInit();
- AfxFreeLibrary( g_hEmailLibModule );
- g_hEmailLibModule = NULL;
- }
- DeleteCriticalSection( &g_csSendEmali );
- 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)
- {
- InitializeCriticalSection( &g_csSendSms );
- DWORD dwThreadId2;
- MTVERIFY( g_hSendSmsThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)SendSmsThread,NULL, 0, &dwThreadId2) );
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- g_hSmsLibModule = NULL;
- CHAR strFile[MAX_LIST_LENGTH + 1] = "";
- wsprintf(strFile, "%s\\Dll\\sms.dll", g_strDirectory);
- g_hSmsLibModule = AfxLoadLibrary(strFile);
- if ( g_hSmsLibModule == NULL )
- {
- printf("加载SMS.dll失败,错误码:%d\n", GetLastError());
- return -1;
- }
- 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");
- pSmsGetBalance = (SMS_DLLGetBalance)::GetProcAddress(g_hSmsLibModule, "SMS_DLLGetBalance");
- }
- if( ( NULL != g_hSmsLibModule ) && ( NULL != pSmsDllInit ) )
- {
- int nRet = pSmsDllInit(g_strDirectory,
- nAddr,
- nCommPort,
- nRate,
- nDataBit,
- nStopBit,
- nParity,
- nInterval,
- nNeedLanguageTrans,
- nMaxChar,
- nMakeCall
- );
- if( nRet != 0 )
- {
- LOG4C((LOG_NOTICE, "打开 COM%d 失败,不能进行短信操作",nCommPort));
- pSmsDllInit = NULL;
- pSmsDllUnInit = NULL;
- pSmsDllSendSms = NULL;
- pSmsDllGetCSQ = NULL;
- pSmsDllSetCallBack = NULL;
- pSmsGetBalance = NULL;
- AfxFreeLibrary( g_hSmsLibModule );
- g_hSmsLibModule = NULL;
- g_nSendSms = 0;
- return 1;
- }
- }
- else
- {
- LOG4C((LOG_NOTICE, "找不到 %s ,不能进行短信操作",strFile));
- pSmsDllInit = NULL;
- pSmsDllUnInit = NULL;
- pSmsDllSendSms = NULL;
- pSmsDllGetCSQ = NULL;
- pSmsDllSetCallBack = NULL;
- pSmsGetBalance = NULL;
- AfxFreeLibrary( g_hSmsLibModule );
- g_hSmsLibModule = NULL;
- g_nSendSms = 0;
- return 1;
- }
- 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;
- }
- DeleteCriticalSection( &g_csSendSms );
- 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.Format( "%s%s%s",g_strNoticePre,pContent,g_strHintVoiceEnd ); // g_strHintAlarmWelcome +
- //str = str + g_strHintVoiceEnd; //" 重新请按1,确认请按2,结束请直接挂机";
- if( ( NULL != g_hVoiceLibModule ) && (NULL != pStoneUDllAllocateChannel) )
- {
- //strMsg.Format("开始发送语音通知!", pTel);
- //AddToPrintQueue( MSG_OK, MSG_NOTICE_MD, (char*)(LPCTSTR)strMsg, strMsg.GetLength() );
- //LOG4C((LOG_NOTICE, "str = %s", str));
- 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 *pTel, CHAR *pContent)
- {
- CString strMobileTel;
- char szResultMsg[MAX_MSG_LENGTH + 1] = {0};
- int nResult = -1;
- memset(szResultMsg, 0, sizeof(szResultMsg));
- strMobileTel.Format( "%s",pTel );
- CTime time = CTime::GetCurrentTime();
- CString strTime;
- strTime = time.Format("%Y-%m-%d %H:%M:%S");
- if( pSmsDllSendSms != NULL && g_bAlarmNoticeFlag )
- {
- if( strMobileTel.GetLength()<11 )
- {
- LOG4C((LOG_NOTICE, "短信号码有误, tel: %s", strMobileTel));
- return 0; //判断是不是手机号码 只根据长度
- }
- CString sTemp;
- sTemp.Format( "%s%s",g_strNoticePre,pContent );
- nResult = pSmsDllSendSms((char *)(LPCTSTR)strMobileTel, (char *)(LPCTSTR)sTemp, szResultMsg);
- if( nResult != 0 ) // 发送失败
- {
- // 发送失败,重试5次,如果还是失败,则放弃
- for( int iReSend = 0; iReSend < 5; iReSend++ )
- {
- nResult = pSmsDllSendSms((char *)(LPCTSTR)strMobileTel, (char *)(LPCTSTR)sTemp, szResultMsg);
- if( nResult == 0 )
- {
- CString strTemp = "";
- strTemp.Format("send sms success, tel: %s, content: %s", strMobileTel, pContent);
- LOG4C((LOG_NOTICE, "send sms success, tel: %s, content: %s, code: %s,%d", strMobileTel, pContent,szResultMsg,iReSend+1));
- CDBInterface::GetInstancePtr()->InsertSmsRecord(
- (char *)(LPCTSTR)strMobileTel,
- "",
- (char *)(LPCTSTR)strTime,
- (char *)(LPCTSTR)strTemp,
- "");
- break;
- }
- else
- {
- if( iReSend==4 )
- {
- int nNowData=0;
- if( !pSmsDllGetCSQ( 15,31,nNowData ) )//短信猫信号弱
- {
- CDBInterface::GetInstancePtr()->InsertSmsRecord(
- "",
- "",
- (char *)(LPCTSTR)strTime,
- "send sms lost,Because the signal is too weak",
- "");
- LOG4C((LOG_NOTICE, "send sms tel: %s lost,Because the signal=%d is too weak",strMobileTel,nNowData ));
- return 0;
- }
- LOG4C((LOG_NOTICE, "send sms lost, tel: %s, content: %s, code: %s", strMobileTel, pContent, szResultMsg));
- }
- }
- 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)
- {
- int nRet = -1;
- 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 )
- {
- nRet = 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 )
- {
- CString sTemp;
- sTemp.Format( "%s%s",g_strNoticePre,pContent );
- nResult = pEmailDllSendEmail(
- (char *)(LPCSTR)strEmail,
- g_strEmailSubject,
- (char *)(LPCSTR)sTemp,
- (char *)(LPCTSTR)strTime,
- szResultMsg );
- if( nResult != 0 ) //发送失败
- {
- CString sError;
- sError.Format( "Contect:%s send lost: %s", pContent, szResultMsg );
- CDBInterface::GetInstancePtr()->InsertEmailRecord(
- (char *)(LPCTSTR)strEmail,
- "",
- (char *)(LPCTSTR)strTime,
- (char *)(LPCTSTR)sError,
- "");
- 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 nRet;
- }
- // 添加有管理某个设备所有用户的电话号码和手机号码
- void InsertUserTel(VAR_NOTICE *pVarNotice)
- {
- CString strTel;
- int nDevSize = (int)g_vtUserRoleInfo.size();
- for( int i = 0; i < nDevSize; i++ )
- {
- //LOG4C((LOG_NOTICE, "g_vtUserRoleInfo[i].szDevUID=%s", g_vtUserRoleInfo[i].szDevUID));
- //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);
- }
- #if 0 //移动电话 不打电话
- strTel = CString(g_vtUserRoleInfo[i].vtUserInfo[j].szMobileTel);
- if( strTel.Compare("") )
- {
- pVarNotice->listTel.insert(pVarNotice->listTel.end(), strTel);
- //TRACE1("手机号码:%s\r\n", strTel);
- }
- #endif
- }
- }
- }
- }
- // 更新要发送对象的手机号码
- 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,
- char *pDevArea,
- double dbData,
- char *pContent,
- VAR_NOTICE *pVarNotice,
- int nUpperLimit,
- int nLowerLimit,
- int nWarningLevel )
- {
- if( nNormalIsNotice ) // 恢复正常触发远程报警
- {
- 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_bSendVoice )
- {
- if( nWarningLevel>=g_nLevelWav )
- {
- 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));
- InsertSendVoiceList(pDevUid, nVarID, (char *)(LPCTSTR)*pStrTel, pContent,g_nAlarmIndex);
- //pVarNotice->listTel.erase(it);
- LeaveCriticalSection( &g_csVarNotice );
- }
- }
- else
- LOG4C((LOG_NOTICE, "没有达到语音通知级别 nWarningLevel = %d, g_nLevelWav = %d", nWarningLevel,g_nLevelWav ));
- }
- //发送恢复正常信息给客户端
- g_pServerSocket[1]->AutoSendAlarmDataToClient( pDevUid,nVarID,1,pContent,dbData,nUpperLimit,nLowerLimit,nNormalStatus,nAlarmStatus,nWarningLevel,g_nAlarmIndex,g_nNoticeDelay );
- g_nDealAWAStatus = 3;//处理声光报警状态 -1未初始化 0初始化 1在处理中 2处理完成 3新事件
- // 短信通知
- if( g_nSendSms==1 )
- {
- if( nWarningLevel>=g_nLevelSms )
- InsertSendSmsList( pDevUid, nVarID, pContent,g_nAlarmIndex );//SendSms(pDevUid, nVarID, pContent);
- else
- LOG4C((LOG_NOTICE, "没有达到短信通知级别 nWarningLevel = %d, g_nLevelWav = %d", nWarningLevel,g_nLevelSms ));
- }
- else if( g_nSendSms==2 )//支持短信平台
- {
- WriteToTxt(pDevUid, nVarID, pContent,g_nAlarmIndex);
- }
- // Email通知
- if( g_nSendEmail )
- {
- if( nWarningLevel>=g_nLevelEmail )
- InsertSendEmailList( pDevUid, nVarID, pContent,g_nAlarmIndex );//SendEmail(pDevUid, nVarID, pContent);
- else
- LOG4C((LOG_NOTICE, "没有达到邮件通知级别 nWarningLevel = %d, g_nLevelWav = %d", nWarningLevel,g_nLevelEmail ));
- }
- }
- g_nAlarmIndex++;
- if( g_nAlarmIndex>=5000 )
- 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, pDevArea, pContent);
- }
- void ProcessVarAlarm(char *pDevUid,
- int nVarID,
- int nAlarmStatus,
- int nNormalStatus,
- int nIdenfityTime,
- int nReDetectTime,
- int nNormalIsNotice,
- char *pDevName,
- char *pVarDesc,
- char *pDevArea,
- double dbData,
- char *pContent,
- VAR_NOTICE *pVarNotice,
- int nUpperLimit,
- int nLowerLimit,
- int nWarningLevel )
- {
- //// add 2011-09-30
- //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 );
- //}// add 2011-09-30
- //语音通知
- if( g_bSendVoice )
- {
- if( nWarningLevel>=g_nLevelWav )
- {
- 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));
- InsertSendVoiceList(pDevUid, nVarID, (char *)(LPCTSTR)*pStrTel, pContent,g_nAlarmIndex);
- LeaveCriticalSection( &g_csVarNotice );
- }
- }
- else
- LOG4C((LOG_NOTICE, "没有达到语音通知级别 nWarningLevel = %d, g_nLevelWav = %d", nWarningLevel,g_nLevelWav ));
- }
- //发送报警信息给客户端
- g_pServerSocket[1]->AutoSendAlarmDataToClient( pDevUid,nVarID,0,pContent,dbData,nUpperLimit,nLowerLimit,nNormalStatus,nAlarmStatus,nWarningLevel,g_nAlarmIndex,g_nNoticeDelay );
- g_nDealAWAStatus = 3;//处理声光报警状态 -1未初始化 0初始化 1在处理中 2处理完成 3新事件
- pVarNotice->dwReDetectTick = GetTickCount();
- //(M1)47=00(M4)24=00(W14)23=00()=00
- //(M1)014=00(M4)456=00()=01
- //短信通知
- if( g_nSendSms==1 )
- {
- if( nWarningLevel>=g_nLevelSms )
- InsertSendSmsList( pDevUid, nVarID, pContent,g_nAlarmIndex );//SendSms(pDevUid, nVarID, pContent);
- else
- LOG4C((LOG_NOTICE, "没有达到短信通知级别 nWarningLevel = %d, g_nLevelWav = %d", nWarningLevel,g_nLevelSms ));
- }
- else if( g_nSendSms==2 )//支持短信平台
- {
- WriteToTxt(pDevUid, nVarID, pContent,g_nAlarmIndex);
- }
- //邮件通知
- if( g_nSendEmail )
- {
- // 发送Email,所有用户一次性发完
- if( nWarningLevel>=g_nLevelEmail )
- InsertSendEmailList( pDevUid, nVarID, pContent,g_nAlarmIndex );//SendEmail(pDevUid, nVarID, pContent);
- else
- LOG4C((LOG_NOTICE, "没有达到邮件通知级别 nWarningLevel = %d, g_nLevelWav = %d", nWarningLevel,g_nLevelEmail ));
- }
- g_nAlarmIndex++;
- if( g_nAlarmIndex>=5000 )
- 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, pDevArea, pContent);
- }
- // 处理变量远程报警通知
- int ProcessVarNotice(char *pDevUid,
- int nVarID,
- int nUpperLimit,
- int nLowerLimit,
- int nOffSet,
- int nAlarmStatus,
- int nNormalStatus,
- int nIdenfityTime,
- int nReDetectTime,
- int nNormalIsNotice,
- int nWarningLevel,
- char *pDevName,
- char *pVarDesc,
- char *pDevArea,
- 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;
- tagVarNotice.nReDetectTime = nReDetectTime;
- // 添加有权限用户的电话号码和手机号码
- 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 );
- //LOG4C((LOG_NOTICE, "nLowerLimit=%d nUpperLimit=%d nOffSet=%d",nLowerLimit,nUpperLimit,nOffSet));
- //模拟量才有偏移量
- if( nOffSet > 0 )//当偏移量大于0时,判断当前值是否达到偏移量这个条件
- {
- //CString strTemp = CString(pContent);
- //if( strTemp.Find(g_strHintReturnNormal) != -1 )//chn modify
- {
- //LOG4C((LOG_NOTICE, "nLowerLimit=%d nUpperLimit=%d nOffSet=%d",nLowerLimit,nUpperLimit,nOffSet));
- if( dbData>=nLowerLimit+nOffSet && dbData<=nUpperLimit-nOffSet )
- {
- ProcessVarStatusReturnNormal(pDevUid, nVarID, nAlarmStatus, nNormalStatus, nIdenfityTime,
- nReDetectTime, nNormalIsNotice, pDevName, pVarDesc,pDevArea, dbData, pContent, pVarNotice,nUpperLimit,nLowerLimit,nWarningLevel );
- }
- }
- }
- else
- {
- ProcessVarStatusReturnNormal(pDevUid, nVarID, nAlarmStatus, nNormalStatus, nIdenfityTime,
- nReDetectTime, nNormalIsNotice, pDevName, pVarDesc,pDevArea, dbData, pContent, pVarNotice,nUpperLimit,nLowerLimit,nWarningLevel );
- }
- }
- 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,nWarningLevel );
- // }
- // }
- //}
- //else
- {
- ProcessVarAlarm(pDevUid, nVarID, nAlarmStatus, nNormalStatus, nIdenfityTime,
- nReDetectTime, nNormalIsNotice, pDevName, pVarDesc,pDevArea, dbData, pContent, pVarNotice,nUpperLimit,nLowerLimit,nWarningLevel );
- }
- }
- }
- 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_listSendVoice.begin(); it != g_listSendVoice.end(); it++ )
- {
- if( strcmp(it->szDevUID, pDevUid) == 0 && it->nVarID == nVarID )
- {
- pSendNotice = &(*it);
- }
- }
- return pSendNotice;
- }
- // 添加变量到list
- void InsertSendVoiceList(char *pDevUid, int nVarID, char *pTel, char *pContent,int nAlarmIndex )
- {
- //如果是短信确认关闭报警通知则退出
- if( !g_bAlarmNoticeFlag )
- return ;
- if( g_bSendVoice==0 )
- return;
- if( pStoneUDLLTxtToWav && g_nAlarmIndexLast!=nAlarmIndex )
- {
- g_nAlarmIndexLast = nAlarmIndex;
- CString strFileName,sContent;
- EnterCriticalSection( &g_csCreateWav );
- CString strFileName2;
- strFileName2.Format("%s\\wav\\temp_%s_%d_%d_IDE.wav", g_strDirectory, pDevUid, nVarID,nAlarmIndex );
- try
- {
- pStoneUDLLTxtToWav( pContent, (char *)(LPCTSTR)strFileName2, g_nTTSType, g_nTTSRate, g_nTTSVolume ); //设置音量,范围是 0 - 100
- }
- catch(...)
- {
- LOG4C((LOG_NOTICE, "pStoneUDLLTxtToWav1 出错"));
- }
- g_saWavPath.Add( strFileName2 );
- g_saWavContent.Add( pContent );
- CString sTemp;
- sTemp.Format( "%s%s%s",g_strNoticePre,pContent,g_strHintVoiceEnd );
- CString strFileName1;
- strFileName1.Format("%s\\wav\\temp_%s_%d_%d.wav", g_strDirectory, pDevUid, nVarID,nAlarmIndex );
- g_saWavPath.Add( strFileName1 );
- g_saWavContent.Add( sTemp );
- LeaveCriticalSection( &g_csCreateWav );
- }
- //LOG4C((LOG_NOTICE, "pDevUid = %s,nVarID = %d, pTel = %s, 内容:%s , nAlarmIndex = %d ", pDevUid,nVarID,pTel, pContent,nAlarmIndex ));
- SEND_NOTICE tagSendNotice;
- strcpy(tagSendNotice.szDevUID, pDevUid);
- tagSendNotice.nVarID = nVarID;
- strcpy(tagSendNotice.szTel, pTel);
- strcpy(tagSendNotice.szContect, pContent);
- tagSendNotice.nAlarmIndex = nAlarmIndex;
- GetLocalTime( &tagSendNotice.time );
- tagSendNotice.nCallTimes = 0;
- if( strcmp("0.0.0.0", pDevUid)==0 && nVarID==1 )
- tagSendNotice.nNoticeDelayTime = 0;
- else
- tagSendNotice.nNoticeDelayTime = g_nNoticeDelay+2;
- EnterCriticalSection( &g_csSendVoice );
- g_listSendVoice.insert(g_listSendVoice.end(), tagSendNotice);
- LeaveCriticalSection( &g_csSendVoice );
- }
- // 从list中移除变量
- int DeleteSendVoiceList(char *pDevUid, int nVarID)
- {
- int nRet = -1;
- SEND_NOTICE* pSendNotice = NULL;
- LIST_SEND_NOTICE::iterator it;
- for( it = g_listSendVoice.begin(); it != g_listSendVoice.end(); )
- {
- pSendNotice = &(*it);
- if( strcmp(pSendNotice->szDevUID, pDevUid) == 0 && pSendNotice->nVarID == nVarID )
- {
- EnterCriticalSection( &g_csSendVoice );
- g_listSendVoice.erase(it++);
- LeaveCriticalSection( &g_csSendVoice );
- nRet = 0;
- break;
- }
- else
- {
- it++;
- }
- }
- return nRet;
- }
- // IDE确认后从list中移除变量
- int DeleteSendVoiceList( char *pDevUid, int nVarID,int iAlarmIndex )
- {
- int nRet = -1;
- SEND_NOTICE* pSendNotice = NULL;
- LIST_SEND_NOTICE::iterator it;
- for( it = g_listSendVoice.begin(); it != g_listSendVoice.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_csSendVoice );
- g_listSendVoice.erase(it++);
- LeaveCriticalSection( &g_csSendVoice );
- }
- else
- {
- it++;
- }
- }
- return nRet;
- }
- // 删除所有变量
- void DeleteAllSendVoiceList()
- {
- #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_listSendVoice.begin(); it != g_listSendVoice.end(); )
- {
- g_listSendVoice.erase( it++ );
- }
- }
- // 添加变量到Sms list
- void InsertSendSmsList(char *pDevUid, int nVarID, char *pContent,int nAlarmIndex )
- {
- //如果是短信确认关闭报警通知则退出
- if( !g_bAlarmNoticeFlag || g_nSendSms==0 )
- return;
- //是自检
- if( strcmp("0.0.0.0", pDevUid)==0 )
- {
- char chTel[MAX_TEL_LENGTH] = {0};
- char chMobile[MAX_TEL_LENGTH] = {0};
- char chFax[MAX_TEL_LENGTH] = {0};
- char chEmail[MAX_EMAIL_LENGTH] = {0};
- for( int i=0;i<g_vtUserInfo.size();i++ )
- {
- strcpy(chTel, g_vtUserInfo[i].szTel);
- strcpy(chMobile, g_vtUserInfo[i].szMobileTel);
- CString sTemp;
- sTemp.Format( "%s",chMobile );
- if( sTemp.GetLength()>=11 )
- {
- CTime time = CTime::GetCurrentTime();
- CString strTime;
- strTime = time.Format("%Y-%m-%d %H:%M:%S");
- CString strMobileTel;
- strMobileTel.Format("%s",chMobile );
- SEND_NOTICE tagSendNotice;
- strcpy(tagSendNotice.szDevUID, pDevUid);
- tagSendNotice.nVarID = nVarID;
- strcpy(tagSendNotice.szTel, strMobileTel);
- strcpy(tagSendNotice.szContect, pContent);
- tagSendNotice.nAlarmIndex = nAlarmIndex;
- GetLocalTime( &tagSendNotice.time );
- tagSendNotice.nCallTimes = 0;
- tagSendNotice.nNoticeDelayTime = 0;
- EnterCriticalSection( &g_csSendSms );
- g_listSendSms.insert(g_listSendSms.end(), tagSendNotice);
- LeaveCriticalSection( &g_csSendSms );
- }
- }
- }
- else
- {
- 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++ )
- {
- CString strMobileTel = CString(g_vtUserRoleInfo[i].vtUserInfo[j].szMobileTel);
- if( strMobileTel.GetLength()<11 )
- continue;
- SEND_NOTICE tagSendNotice;
- strcpy(tagSendNotice.szDevUID, pDevUid);
- tagSendNotice.nVarID = nVarID;
- strcpy(tagSendNotice.szTel, strMobileTel);
- strcpy(tagSendNotice.szContect, pContent);
- tagSendNotice.nAlarmIndex = nAlarmIndex;
- GetLocalTime( &tagSendNotice.time );
- tagSendNotice.nCallTimes = 0;
- tagSendNotice.nNoticeDelayTime = g_nNoticeDelay+2;
- EnterCriticalSection( &g_csSendSms );
- g_listSendSms.insert(g_listSendSms.end(), tagSendNotice);
- LeaveCriticalSection( &g_csSendSms );
- }
- }
- }
- }
- }
- // 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_csSendSms );
- g_listSendSms.erase(it++);
- LeaveCriticalSection( &g_csSendSms );
- nRet = 0;
- //break;
- }
- else
- {
- it++;
- }
- }
- return nRet;
- }
- // 删除Sms所有变量
- void DeleteAllSendSmsList()
- {
- EnterCriticalSection( &g_csSendSms );
- LIST_SEND_NOTICE::iterator it;
- for( it = g_listSendSms.begin(); it != g_listSendSms.end(); )
- {
- g_listSendSms.erase( it++ );
- }
- LeaveCriticalSection( &g_csSendSms );
- }
- // 添加变量到Email list
- void InsertSendEmailList(char *pDevUid, int nVarID, char *pContent,int nAlarmIndex )
- {
- //如果是短信确认关闭报警通知则退出
- if( !g_bAlarmNoticeFlag )
- return ;
- //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 );
- tagSendNotice.nCallTimes = 0;
- if( strcmp("0.0.0.0", pDevUid)==0 && nVarID==1 )
- tagSendNotice.nNoticeDelayTime = 0;
- else
- tagSendNotice.nNoticeDelayTime = g_nNoticeDelay+2;
- EnterCriticalSection( &g_csSendEmali );
- g_listSendEmail.insert(g_listSendEmail.end(), tagSendNotice);
- LeaveCriticalSection( &g_csSendEmali );
- }
- // IDE确认后从Email list中移除变量
- int DeleteSendEmailList( char *pDevUid, int nVarID,int iAlarmIndex )
- {
- int nRet = -1;
- SEND_NOTICE* pSendNotice = NULL;
- LIST_SEND_NOTICE::iterator it;
- for( it = g_listSendEmail.begin(); it != g_listSendEmail.end(); )
- {
- pSendNotice = &(*it);
- if( strcmp(pSendNotice->szDevUID, pDevUid) == 0 && pSendNotice->nVarID == nVarID && pSendNotice->nAlarmIndex==iAlarmIndex )
- {
- LOG4C((LOG_NOTICE, "IDE确认Email %s",pSendNotice->szContect));
- EnterCriticalSection( &g_csSendEmali );
- g_listSendEmail.erase(it++);
- LeaveCriticalSection( &g_csSendEmali );
- nRet = 0;
- break;
- }
- else
- {
- it++;
- }
- }
- return nRet;
- }
- // 删除Sms所有变量
- void DeleteAllSendEmailList()
- {
- EnterCriticalSection( &g_csSendEmali );
- LIST_SEND_NOTICE::iterator it;
- for( it = g_listSendEmail.begin(); it != g_listSendEmail.end(); )
- {
- g_listSendEmail.erase( it++ );
- }
- LeaveCriticalSection( &g_csSendEmali );
- }
- 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()));
- 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;
- }
- ////////////////////////////////////////////////////////////////////////////////
- bool DeleteWav( CString strPath, CString strFileName, int nLayer )
- {
- CStringArray saFilePath;
- long hfile;
- struct _finddata_t fFile;
- CString strCurr = strPath + "\\" + strFileName;
- int nDone=0;
- hfile = _findfirst( (char *)(LPCTSTR)strCurr, &fFile );
- if( -1L != hfile )
- {
- while( !( nDone = _findnext(hfile, &fFile) ) )
- {
- if( !strcmp(fFile.name,"..") ) continue;
- if( ( fFile.attrib==16 || fFile.attrib==18 || fFile.attrib==48 || fFile.attrib==2064 ||
- fFile.attrib==2096 || fFile.attrib==2098 || fFile.attrib==16432 || fFile.attrib==16434 ) ) //_A_SUBDIR
- {
- }
- else
- {
- CString str = fFile.name;
- CString sFileNameTemp = strPath + "\\" + str;
- if( -1 != str.Find( "temp" ) )
- {
- saFilePath.Add( sFileNameTemp );
- }
- }
- }
- _findclose(hfile);
- }
- for( int i=0;i<saFilePath.GetCount();i++ )
- {
- DeleteFile( saFilePath.GetAt( i ) );
- }
- return true;
- }
- bool IsCreateWavOK( CString sWavPath )
- {
- bool bRet = true;
- CString sPath;
- for( int i=0;i<g_saWavPath.GetCount();i++ )
- {
- sPath = g_saWavPath.GetAt( 0 );
- if( sPath==sWavPath )
- {
- bRet = false;
- break;
- }
- }
- return bRet;
- }
- DWORD WINAPI SendVoiceThread(LPVOID lpParameter)
- {
- do
- {
- if( g_listSendVoice.size() == 0 )
- {
- CTime ctNow = CTime::GetCurrentTime();
- int nHour;
- nHour = ctNow.GetHour();
- static bool bCanDelWav = true;
- if( nHour == 23 && bCanDelWav )
- {
- bCanDelWav = false;
- CString strDectory;
- strDectory.Format("%s\\wav", g_strDirectory );
- DeleteWav( strDectory,"*.*",0 );
- //LOG4C((LOG_NOTICE, "清空语音文件" ));
- }
- else if( nHour != 23 )
- {
- bCanDelWav = true;
- }
- }
- else
- {
- SEND_NOTICE *pSendNotice;
- LIST_SEND_NOTICE::iterator it;
- it = g_listSendVoice.begin();
- pSendNotice = &(*it);
- CString sCurrentTel;
- CString sDevUID;
- CString sContent;
- int nVarID = 0;
- 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 > pSendNotice->nNoticeDelayTime )
- {
- CString strFileName;
- strFileName.Format("%s\\wav\\temp_%s_%d_%d.wav", g_strDirectory, pSendNotice->szDevUID, pSendNotice->nVarID,pSendNotice->nAlarmIndex );
- if( !IsCreateWavOK( strFileName ) )
- continue;
- LOG4C((LOG_NOTICE, "开始拨打 电话 %s%s",g_strNoticeTelPre,pSendNotice->szTel ));
- int nRet = SendNotice(pSendNotice->szDevUID, pSendNotice->nVarID,pSendNotice->nAlarmIndex, pSendNotice->szTel, pSendNotice->szContect);
- sCurrentTel.Format( "%s",pSendNotice->szTel );
- sDevUID.Format( "%s",pSendNotice->szDevUID );
- sContent.Format( "%s",pSendNotice->szContect);
- nVarID = pSendNotice->nVarID;
- if( nRet==CALL_SUCCESS_SINGLE_CONFIRM )//确认当前通知
- {
- LOG4C((LOG_NOTICE, "电话 %s%s 用户确认当前通知 (%d)内容:%s",g_strNoticeTelPre,pSendNotice->szTel,g_listSendVoice.size(),pSendNotice->szContect ));
- int nCurrentTelIndex=0,nTelIndex=0;
- nCurrentTelIndex = GetTelIndex( pSendNotice->szDevUID, pSendNotice->nVarID, sCurrentTel );
- //LOG4C((LOG_NOTICE, "nCurrentTelIndex = %d",nCurrentTelIndex));
- EnterCriticalSection( &g_csSendVoice );
- g_listSendVoice.erase(it++);//先把当前的删除
- LeaveCriticalSection( &g_csSendVoice );
- if( g_listSendVoice.size() > 0 )
- {
- CTime time = CTime::GetCurrentTime();
- CString strTime,sTemp;
- strTime = time.Format("%Y-%m-%d %H:%M:%S");
- sTemp.Format( "确认通知《%s》 ",sContent );
- CDBInterface::GetInstancePtr()->InsertNoticeRecord(
- (char *)(LPCTSTR)sCurrentTel,
- "",
- (char *)(LPCTSTR)strTime,
- (char *)(LPCTSTR)sTemp,
- "");
- EnterCriticalSection( &g_csSendVoice );
- LIST_SEND_NOTICE::iterator itTemp;
- for( itTemp = g_listSendVoice.begin(); itTemp != g_listSendVoice.end(); )
- {
- nTelIndex = GetTelIndex( itTemp->szDevUID,itTemp->nVarID,itTemp->szTel );
- //LOG4C((LOG_NOTICE, "%s,nCurrentTelIndex = %d,%s,nTelIndex=%d ",sCurrentTel,nCurrentTelIndex,itTemp->szTel,nTelIndex ));
- if( strcmp("0.0.0.0", sDevUID)==0 && nVarID==1 )//是自检
- {
- if( strcmp("0.0.0.0", itTemp->szDevUID)==0 && itTemp->nVarID==1 )
- {
- LOG4C((LOG_NOTICE, "自检通知已经被确认,跳过号码 %s",itTemp->szTel ));
- g_listSendVoice.erase(itTemp++);
- }
- else
- break;
- }
- else
- {
- if( nCurrentTelIndex<nTelIndex )
- {
- LOG4C((LOG_NOTICE, "通知已经被确认,跳过号码 %s",itTemp->szTel ));
- g_listSendVoice.erase(itTemp++);
- }
- else
- {
- break;
- }
- }
- }
- LeaveCriticalSection( &g_csSendVoice );
- }
- }
- else if( nRet==CALL_SUCCESS_ALL_CONFIRM )//确认全部通知
- {
- LOG4C((LOG_NOTICE, "电话 %s%s 用户确认所有通知 (%d)内容:%s",g_strNoticeTelPre,pSendNotice->szTel,g_listSendVoice.size(),pSendNotice->szContect ));
- EnterCriticalSection( &g_csSendVoice );
- g_listSendVoice.erase(it++);//先把当前的删除
- if( g_listSendVoice.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_listSendVoice.begin(); itTemp != g_listSendVoice.end(); )
- {
- LOG4C((LOG_NOTICE, "通知全部已经被确认,跳过号码 %s",itTemp->szTel ));
- g_listSendVoice.erase(itTemp++);
- }
- }
- LeaveCriticalSection( &g_csSendVoice );
- }
- else if( nRet == CALL_SUCCESS_NOT_CONFIRM )
- {
- LOG4C((LOG_NOTICE, "电话 %s%s 用户没有确认通知 (%d)内容:%s",g_strNoticeTelPre,pSendNotice->szTel,g_listSendVoice.size(),pSendNotice->szContect ));
- EnterCriticalSection( &g_csSendVoice );
- g_listSendVoice.erase(it++);
- LeaveCriticalSection( &g_csSendVoice );
- }
- else if( nRet == CALL_LOST )
- {
- LOG4C((LOG_NOTICE, "拨打电话 %s%s 失败 (%d)内容:%s",g_strNoticeTelPre,pSendNotice->szTel,g_listSendVoice.size(),pSendNotice->szContect ));
- EnterCriticalSection( &g_csSendVoice );
- pSendNotice->nCallTimes++;
- if( pSendNotice->nCallTimes >= g_nNoticeCallTimes )
- g_listSendVoice.erase(it++);
- LeaveCriticalSection( &g_csSendVoice );
- }
- }
- Sleep( 2 * 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;
- static bool bCanSendSms=false;
- if( pSendNotice && !bCanSendSms )
- {
- //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 > pSendNotice->nNoticeDelayTime )
- {
- LOG4C((LOG_NOTICE, "SendSmsThread %s",pSendNotice->szContect));
- bCanSendSms = true;
- SendSms( pSendNotice->szDevUID,pSendNotice->nVarID,pSendNotice->szTel,pSendNotice->szContect );
- bCanSendSms = false;
- EnterCriticalSection( &g_csSendSms );
- g_listSendSms.erase(it++);
- LeaveCriticalSection( &g_csSendSms );
- }
- }
- }
- }while( WaitForSingleObject(g_hRunObject, 200L) == WAIT_TIMEOUT );
- return 0;
- }
- DWORD WINAPI SendEmailThread(LPVOID lpParameter)
- {
- do
- {
- if( g_listSendEmail.size() > 0 )
- {
- SEND_NOTICE *pSendNotice=NULL;
- LIST_SEND_NOTICE::iterator it;
- it = g_listSendEmail.begin();
- pSendNotice = &(*it);
- static bool bCanSendEmail=false;
- if( pSendNotice && !bCanSendEmail )
- {
- 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 > pSendNotice->nNoticeDelayTime )
- {
- LOG4C((LOG_NOTICE, "*****开始一轮邮件通知*****" ));
- bCanSendEmail = true;
- int nRet = SendEmail( pSendNotice->szDevUID,pSendNotice->nVarID,pSendNotice->szContect );
- if( nRet==-1 )
- LOG4C((LOG_NOTICE, "没有分配设备" ));
- bCanSendEmail = false;
- LOG4C((LOG_NOTICE, "*****结束一轮邮件通知*****" ));
- EnterCriticalSection( &g_csSendEmali );
- g_listSendEmail.erase(it++);
- LeaveCriticalSection( &g_csSendEmali );
- }
- }
- }
- }while( WaitForSingleObject(g_hRunObject, 200L) == WAIT_TIMEOUT );
- return 0;
- }
- DWORD WINAPI CreateWavThread(LPVOID lpParameter)
- {
- do
- {
- static bool sbCreateNow = false;
- int nSize1 = g_saWavPath.GetCount();
- int nSize2 = g_saWavContent.GetCount();
- if( nSize1>0 && nSize2>0 && !sbCreateNow )
- {
- if( pStoneUDLLTxtToWav )
- {
- sbCreateNow = true;
- EnterCriticalSection( &g_csCreateWav );
- CString sPath = g_saWavPath.GetAt(0);
- CString sContent = g_saWavContent.GetAt(0);
- //LOG4C((LOG_NOTICE, "pStoneUDLLTxtToWav in"));
- try
- {
- pStoneUDLLTxtToWav( (char *)(LPCTSTR)sContent, (char *)(LPCTSTR)sPath,g_nTTSType,g_nTTSRate, g_nTTSVolume );
- }
- catch(...)
- {
- LOG4C((LOG_NOTICE, "pStoneUDLLTxtToWav2 出错"));
- }
- //LOG4C((LOG_NOTICE, "pStoneUDLLTxtToWav out"));
- g_saWavPath.RemoveAt(0);
- g_saWavContent.RemoveAt(0);
- sbCreateNow = false;
- LeaveCriticalSection( &g_csCreateWav );
- }
- }
- Sleep( 100 );
- }while( WaitForSingleObject( g_hRunObject, 125L ) == WAIT_TIMEOUT );
- return 0;
- }
- DWORD WINAPI AWAThread(LPVOID lpParameter)//声光报警线程
- {
- int nTimeTick=0;
- do
- {
- if( g_nDealAWAStatus==0 || g_nDealAWAStatus==2 || g_nDealAWAStatus==3 )
- {
- g_FunSetAWA();
- }
- if( nTimeTick++ >= 120 && g_nDealAWAStatus==-1 )
- g_nDealAWAStatus = 0;//处理声光报警状态 -1未初始化 0初始化 1在处理中 2处理完成 3新事件
- }while( WaitForSingleObject(g_hRunObject, 1000L) == WAIT_TIMEOUT );
- return 0;
- }
- //判断是否达到重新检测时间
- DWORD WINAPI CheckReDetectTimeThread(LPVOID lpParameter)
- {
- do
- {
- if( g_listVarNotice.size() > 0 )
- {
- VAR_NOTICE* pVarNotice = NULL;
- LIST_VAR_NOTICE::iterator it;
- for( it = g_listVarNotice.begin(); it != g_listVarNotice.end(); it++ )
- {
- pVarNotice = &(*it);
- if( pVarNotice->dwReDetectTick == 0 )
- {
- EnterCriticalSection( &g_csVarNotice );
- pVarNotice->dwReDetectTick = GetTickCount();
- LeaveCriticalSection( &g_csVarNotice );
- }
- // 超过重新检测等待时间,从list中删除该变量;
- if( GetTickCount() - pVarNotice->dwReDetectTick > (DWORD)(pVarNotice->nReDetectTime * 1000 * 60) )
- {
- int nDeviceIndex = -1, nVarIndex = -1;
- BOOL bFind = FindVar(pVarNotice->szDevUID, pVarNotice->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->nCallTime = 0;
- pVarNotice->nSmsTime = 0;
- pBaseVar->m_nAlarmStatus = 3;//设为恢复正常状态
- pVarNotice->bFirstDeal = true;
- pVarNotice->dwReDetectTick = GetTickCount();
- //LOG4C((LOG_NOTICE, "超过重新检测等待时间 设为恢复正常状态 %d",pVarNotice->nReDetectTime));
- LeaveCriticalSection( &g_csVarNotice );
- }
- //// 从list中删除变量时,要保证其它地方不去取list变量
- //EnterCriticalSection( &g_csVarNotice ); // ResetEvent时也不允许任何人进来,故此把临界区放在ResetEvent之前。
- //ResetEvent( g_hDeleteVarSem );
- ////DeleteVarNoticeList(pVarNotice->szDevUID, pVarNotice->nVarID);
- //SetEvent( g_hDeleteVarSem );
- //LeaveCriticalSection( &g_csVarNotice );
- }
- }
- }
- }while( WaitForSingleObject(g_hRunObject, 10000L) == 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_strReserved2.Compare("") != 0 )//报警描述 不为空
- {
- CString sLowerDesc,sUpperDesc,sData;
- sData.Format( "%d%s",(int)pBaseVar->m_dbData, pBaseVar->m_strUnit );
- int nPos = pBaseVar->m_strReserved2.Find( ";" );
- if( nPos!=-1 )
- {
- sLowerDesc = pBaseVar->m_strReserved2.Left( nPos );
- sUpperDesc = pBaseVar->m_strReserved2.Right( pBaseVar->m_strReserved2.GetLength()-nPos-1 );
- }
- else
- {
- sLowerDesc = pBaseVar->m_strReserved2;
- sUpperDesc = pBaseVar->m_strReserved2;
- }
- if( UPPER_LIMIT_ID == nTempStatus ) //上限
- {
- int nPosData = sUpperDesc.Find( "*" );
- if( nPosData!=-1 )
- sUpperDesc.Replace( "*",sData );
- strContect = sUpperDesc;
- }
- else if( LOWER_LIMIT_ID == nTempStatus ) //下限
- {
- int nPosData = sLowerDesc.Find( "*" );
- if( nPosData!=-1 )
- sLowerDesc.Replace( "*",sData );
- strContect = sLowerDesc;
- }
- else
- {
- int nPosData = sLowerDesc.Find( "*" );
- if( nPosData!=-1 )
- sLowerDesc.Replace( "*",sData );
- strContect = sLowerDesc;
- }
- }
- else
- {
- 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));
- EnterCriticalSection( &g_csVarNotice );
- pBaseVar->m_nAlarmStatus = 1;//设为第一次报警状态
- LeaveCriticalSection( &g_csVarNotice );
- 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,
- pBaseVar->m_nWaringLevel,
- (char *)(LPCTSTR)pDev->m_strDeviceName,
- (char *)(LPCTSTR)pBaseVar->m_strDesc,
- (char *)(LPCTSTR)pDev->m_strReserved1,
- pBaseVar->m_dbData,
- (char *)(LPCTSTR)strContect );
- EnterCriticalSection( &g_csVarNotice );
- 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( pBaseVar->m_nAlarmNumber < 10 )
- pBaseVar->m_nAlarmNumber++;
- EnterCriticalSection( &g_csVarNotice );
- pBaseVar->m_nAlarmStatus = 2;//设为第二次报警状态
- LeaveCriticalSection( &g_csVarNotice );
- 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,
- pBaseVar->m_nWaringLevel,
- (char *)(LPCTSTR)pDev->m_strDeviceName,
- (char *)(LPCTSTR)pBaseVar->m_strDesc,
- (char *)(LPCTSTR)pDev->m_strReserved1,
- pBaseVar->m_dbData,
- (char *)(LPCTSTR)strContect );
- EnterCriticalSection( &g_csVarNotice );
- pBaseVar->m_strContent = strContect;
- pBaseVar->m_nLastStatus = nTempStatus;
- pBaseVar->m_dwIdentityTick = 0;
- LeaveCriticalSection( &g_csVarNotice );
- if( 1 == g_nSnmpEnable )
- {
- if( pBaseVar->m_bReserved4==TRUE )
- {
- //LOG4C((LOG_NOTICE, "pBaseVar->m_bReserved4=%d pBaseVar->m_bIsChange=%d", pBaseVar->m_bReserved4,pBaseVar->m_bIsChange ));
- CString strSetValue;
- strSetValue.Format("1*%.1f#%s", pBaseVar->m_dbData,strContect);
- CString strObjID;
- strObjID.Format("%s.%d", g_strSnmpOidRoot, pBaseVar->m_nVarID);
- //LOG4C((LOG_NOTICE, "strObjID: %s", strObjID ));
- pSnmpDllSetValue(
- g_strSnmpIP,
- g_strSnmpField,
- (char *)(LPCTSTR)strObjID,
- "str",
- 1,
- 300,
- (char *)(LPCTSTR)strSetValue
- );
- }
- }
- }
- }
- }
- 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 )
- {
- if( pBaseVar->m_nUpperLimit>0 || pBaseVar->m_nLowerLimit>0 )//模拟量
- {
- //LOG4C((LOG_NOTICE, "m_dbData=%d m_nLowerLimit=%d m_nOffset=%d m_nUpperLimit=%d", (int)pBaseVar->m_dbData,pBaseVar->m_nLowerLimit,pBaseVar->m_nOffset,pBaseVar->m_nUpperLimit));
- if( pBaseVar->m_dbData<=pBaseVar->m_nLowerLimit+pBaseVar->m_nOffset ||
- pBaseVar->m_dbData>=pBaseVar->m_nUpperLimit-pBaseVar->m_nOffset )
- {
- //LOG4C((LOG_NOTICE, "偏移量作用"));
- return 0;
- }
- }
- if( pBaseVar->m_strReserved3.Compare("") != 0 )//恢复描述 不为空
- {
- CString sLowerDesc,sUpperDesc,sData;
- sData.Format( "%d%s",(int)pBaseVar->m_dbData, pBaseVar->m_strUnit );
- CString sDesc = pBaseVar->m_strReserved3;
- int nPosData = sDesc.Find( "*" );
- if( nPosData!=-1 )
- sDesc.Replace( "*",sData );
- strContect = sDesc;
- }
- else
- 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;
- EnterCriticalSection( &g_csVarNotice );
- pBaseVar->m_nAlarmStatus = 3;//设为恢复正常状态
- LeaveCriticalSection( &g_csVarNotice );
- //回复正常
- 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,
- pBaseVar->m_nWaringLevel,
- (char *)(LPCTSTR)pDev->m_strDeviceName,
- (char *)(LPCTSTR)pBaseVar->m_strDesc,
- (char *)(LPCTSTR)pDev->m_strReserved1,
- pBaseVar->m_dbData,
- (char *)(LPCTSTR)strContect );
- EnterCriticalSection( &g_csVarNotice );
- pBaseVar->m_strContent = strContect;
- pBaseVar->m_nLastStatus = nTempStatus;
- pBaseVar->m_dwReturnNormalIdentityTick = 0;
- LeaveCriticalSection( &g_csVarNotice );
- if( 1 == g_nSnmpEnable )
- {
- if( pBaseVar->m_bReserved4==TRUE )
- {
- //LOG4C((LOG_NOTICE, "pBaseVar->m_bReserved4=%d pBaseVar->m_bIsChange=%d", pBaseVar->m_bReserved4,pBaseVar->m_bIsChange ));
- CString strSetValue;
- strSetValue.Format("2*%.1f#%s", pBaseVar->m_dbData,strContect);
- CString strObjID;
- strObjID.Format("%s.%d", g_strSnmpOidRoot, pBaseVar->m_nVarID);
- //LOG4C((LOG_NOTICE, "strObjID: %s", strObjID ));
- pSnmpDllSetValue(
- g_strSnmpIP,
- g_strSnmpField,
- (char *)(LPCTSTR)strObjID,
- "str",
- 1,
- 300,
- (char *)(LPCTSTR)strSetValue
- );
- }
- }
- }
- }
- }
- return 0;
- }
|