Global.cpp 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188
  1. #pragma once
  2. #include "stdafx.h"
  3. //#include <windows.h>
  4. #include "global.h"
  5. #include "SysLib.h"
  6. #include <io.h>
  7. #include "shlwapi.h"
  8. #include "ascprocess.h"
  9. #include "rtuprocess.h"
  10. #include "tcpprocess.h"
  11. #include "icpdasprocess.h"
  12. #include "SnmpProcess.h"
  13. #include "upsParadigmProcess.h"
  14. #include "stulzprocess.h"
  15. #include "PowerwareProcess.h"
  16. #include "greeprocess.h"
  17. #include "CarelProcess.h"
  18. #include "MostDevice.h"
  19. #include "MainPro.h"
  20. int READ_VAR_ERROR_MAX = 2;//一个设备如果连续这个数都没有数据,则不读后面的数据
  21. int g_nTryTimeLessToNotice = 10;//当试用期小于这个数时通知用户
  22. int g_nBlanceLessToNotice = 10;//当卡余额小于这个数时通知用户
  23. CRITICAL_SECTION g_csWrDataBase; //写日志和告警数据库操作
  24. CDevicesManager* g_pDevicesManager = NULL;
  25. CStringArray g_strAllVideoFile;
  26. #if 0
  27. CServerSocket* g_pTcpServer = NULL;
  28. #endif
  29. // 客户端在线Tick
  30. DWORD g_dwClientOnlineTick[MAX_CLIENT_NUM] = {0};
  31. //程序退出事件
  32. HANDLE g_hRunObject = NULL;
  33. //客户端数据
  34. INT g_nClientNum = 0;
  35. char g_strDirectory[256]={0};
  36. CString g_strVersion = "3.0.3.2";
  37. float g_fBlance =0.0;
  38. //ini文件名存在
  39. CStringArray g_saIniList;
  40. void g_FunReadAllIniName( CString strPath, CString strFileName, int nLayer )
  41. {
  42. CStringArray saFilePath;
  43. long hfile;
  44. struct _finddata_t fFile;
  45. CString strCurr = strPath + "\\" + strFileName;
  46. int nDone=0;
  47. hfile = _findfirst( (char *)(LPCTSTR)strCurr, &fFile );
  48. if( -1L != hfile )
  49. {
  50. while( !( nDone = _findnext(hfile, &fFile) ) )
  51. {
  52. if( !strcmp(fFile.name,"..") ) continue;
  53. if( ( fFile.attrib==16 || fFile.attrib==18 || fFile.attrib==48 || fFile.attrib==2064 ||
  54. fFile.attrib==2096 || fFile.attrib==2098 || fFile.attrib==16432 || fFile.attrib==16434 ) ) //_A_SUBDIR
  55. {
  56. }
  57. else
  58. {
  59. CString str = fFile.name;
  60. CString sFileNameTemp = strPath + "\\" + str;
  61. if( -1 != str.Find( ".ini" ) )
  62. {
  63. CString sTemp = str;
  64. sTemp.Trim();
  65. sTemp.MakeLower();
  66. g_saIniList.Add( sTemp );
  67. //LOG4C((LOG_NOTICE, "%s",sTemp));
  68. }
  69. }
  70. }
  71. _findclose(hfile);
  72. }
  73. }
  74. bool g_FunIniOK( CString sIniName )
  75. {
  76. bool bRet=false;
  77. CString str;
  78. for( int i=0;i<g_saIniList.GetCount();i++ )
  79. {
  80. str = g_saIniList.GetAt( i );
  81. if( strcmp(str, sIniName) == 0 )
  82. {
  83. bRet = true;
  84. break;
  85. }
  86. }
  87. return bRet;
  88. }
  89. //声光报警
  90. bool IsPlanTime( CString sPlanTime,int iWeekday,int nHours )
  91. {
  92. bool bRet = false;
  93. if( sPlanTime=="" )
  94. return true;
  95. if( iWeekday==1 )
  96. iWeekday = 6;
  97. else
  98. iWeekday -= 2;
  99. if( sPlanTime[iWeekday*24+nHours]=='1' )
  100. {
  101. bRet = true;
  102. }
  103. return bRet;
  104. }
  105. AWA g_AWA[AWA_NUM_MAX];
  106. int g_nDealAWAStatus = -1;//处理声光报警状态 -1未初始化 0初始化 1在处理中 2处理完成 3新事件
  107. //a. 24小时 没变量
  108. // 不处理
  109. //b. 24小时 有变量
  110. // 声光报警
  111. //c. 12小时 没变量
  112. // 定时开关
  113. //d. 12小时 有变量
  114. // 在这段时间内由变量来控制开关
  115. bool g_FunSetAWA()//触发/取消 声光报警
  116. {
  117. bool bRet = false;
  118. CString TIME = "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111";
  119. for( int i=0;i<AWA_NUM_MAX;i++ )
  120. {
  121. if( g_AWA[i].sDoSet=="" )
  122. {
  123. g_nDealAWAStatus = 2;//处理声光报警状态 -1未初始化 0初始化 1在处理中 2处理完成 3新事件
  124. return false;
  125. }
  126. int nSetAWA = 0;//0取消 1设置 -1不处理
  127. CString str;
  128. CTime time = CTime::GetCurrentTime();
  129. int nWeekday = time.GetDayOfWeek();
  130. int nHours = time.GetHour();
  131. if( g_AWA[i].sPlanTime==TIME )//没时间限制
  132. {
  133. if( g_AWA[i].SA.GetCount()==0 )
  134. {
  135. nSetAWA = -1;
  136. continue;
  137. }
  138. else
  139. {
  140. if( g_nDealAWAStatus==2 )
  141. {
  142. nSetAWA = -1;
  143. continue;
  144. }
  145. for( int m=0;m<g_AWA[i].SA.GetCount();m++ )
  146. {
  147. str = g_AWA[i].SA.GetAt( m );
  148. if( g_pDevicesManager->AWA_VarIsAlarm( str ) )//变量是报警状态
  149. {
  150. nSetAWA = 1;
  151. break;
  152. }
  153. }
  154. }
  155. }
  156. else//有时间限制
  157. {
  158. if( g_AWA[i].SA.GetCount()==0 )
  159. {
  160. if( IsPlanTime( g_AWA[i].sPlanTime,nWeekday,nHours ) )
  161. nSetAWA = 1;
  162. }
  163. else
  164. {
  165. if( g_nDealAWAStatus==2 )
  166. {
  167. nSetAWA = -1;
  168. continue;
  169. }
  170. if( IsPlanTime( g_AWA[i].sPlanTime,nWeekday,nHours ) )
  171. {
  172. for( int m=0;m<g_AWA[i].SA.GetCount();m++ )
  173. {
  174. str = g_AWA[i].SA.GetAt( m );
  175. if( g_pDevicesManager->AWA_VarIsAlarm( str ) )//变量是报警状态
  176. {
  177. nSetAWA = 1;
  178. break;
  179. }
  180. }
  181. }
  182. else
  183. {
  184. nSetAWA = -1;
  185. }
  186. }
  187. }
  188. if( nSetAWA==1 )//触发声光报警
  189. {
  190. bool bAlarm = false;
  191. if( g_pDevicesManager->AWA_DoDataISData( g_AWA[i].sDoStatus,g_AWA[i].nResumeData ) )//不是声光报警状态
  192. {
  193. LOG4C((LOG_NOTICE, "触发声光报警( %s=%d )",g_AWA[i].sDoSet,g_AWA[i].nAlarmData ));
  194. bRet = true;
  195. bAlarm = true;
  196. ProcessResWriteSingleVarData( g_AWA[i].sDoSet,g_AWA[i].nAlarmData );
  197. }
  198. if( !bAlarm && (g_AWA[i].nStatus==0||g_AWA[i].nStatus==-1) )
  199. {
  200. LOG4C((LOG_NOTICE, "现在状态:正在声光报警( %s )",g_AWA[i].sDoSet ));
  201. g_AWA[i].nStatus = 1;
  202. }
  203. if( g_AWA[i].nStatus==-1 )
  204. g_AWA[i].nStatus = 1;
  205. }
  206. else if( nSetAWA==0 )//取消声光报警
  207. {
  208. bool bNormal = false;
  209. if( !g_pDevicesManager->AWA_DoDataISData( g_AWA[i].sDoStatus,g_AWA[i].nResumeData ) )//是声光报警状态
  210. {
  211. LOG4C((LOG_NOTICE, "取消声光报警( %s=%d )",g_AWA[i].sDoSet,g_AWA[i].nResumeData ));
  212. bRet = true;
  213. bNormal = true;
  214. ProcessResWriteSingleVarData( g_AWA[i].sDoSet,g_AWA[i].nResumeData );
  215. }
  216. if( !bNormal && (g_AWA[i].nStatus==1||g_AWA[i].nStatus==-1) )
  217. {
  218. //LOG4C((LOG_NOTICE, "现在状态:没有声光报警( %s )",g_AWA[i].sDoSet ));
  219. g_AWA[i].nStatus = 0;
  220. }
  221. if( g_AWA[i].nStatus==-1 )
  222. g_AWA[i].nStatus = 0;
  223. }
  224. }
  225. return bRet;
  226. }
  227. //结束 声光报警
  228. //DOG
  229. INT g_nUseTimeLimit = 0; //是否超过使用期限
  230. INT g_nSlaveVersion = 0; //版本子ID
  231. CString g_sPassDueInfo = "狗过期了"; //过期信息
  232. bool g_bSoftRegisterFileIsOfficial = false; //注册文件是正式版
  233. bool g_bGetBlanceReturn = false;
  234. //WatchServer
  235. CHAR g_strWatchServerIP[MAX_EQUIP_IP + 1] = {0};
  236. CHAR g_strWatchServerPort[MAX_PORT + 1] = {0};
  237. //Database
  238. CADODatabase* g_pADODatabase = NULL; // Ado连接组件
  239. CHAR g_strConnectString[MAX_PATH + 1] = ""; // 数据连接字符串
  240. CHAR g_strDBType[MAX_SERVER_LENGTH + 1] = ""; // 数据库连接类型(如: SQL SERVER 、Access )
  241. CHAR g_strAccessFile[MAX_PATH_LENGTH + 1] = ""; // 如果是用Access数据库:Access文件名称
  242. // 如用其它数据库:为空
  243. CHAR g_strServerName[MAX_SERVER_LENGTH + 1] = ""; // 数据库服务器名称或IP
  244. CHAR g_strDataBaseName[MAX_DATABASE_LENGTH + 1] = ""; // 数据库名称
  245. CHAR g_strUserName[MAX_USER_LENGTH + 1] = ""; // 数据库用户名
  246. CHAR g_strPassword[MAX_PASSWORD_LENGTH + 1] = ""; // 数据库密码
  247. //用户信息
  248. CHAR g_strLoginUserID[MAX_USER_LENGTH + 1] = ""; // 当前使用该软件的用户名
  249. CHAR g_strLoginPwd[MAX_PASSWORD_LENGTH + 1] = ""; // 当前使用该软件的密码
  250. CHAR g_strDefaultUserID[MAX_USER_LENGTH + 1] = {0};
  251. CHAR g_strDefaultUserPwd[MAX_PASSWORD_LENGTH + 1] = {0};
  252. //提示
  253. CHAR g_strErrorDBDisConnection[MAX_ERROR_LEN + 1] = {0};
  254. CHAR g_strMsgDBConnectionSuccess[MAX_ERROR_LEN + 1] = {0};
  255. CHAR g_strErrorExecSql[MAX_ERROR_LEN + 1] = {0};
  256. //系统设置
  257. BOOL g_bEnableTimeLimited = FALSE; // TRUE:时间限制 FALSE:正式版
  258. INT g_iAutoRunSystem = 0; // 是否开机自启动该系统
  259. CHAR g_strLanguage[MAX_LANG_LENGTH + 1]={0}; // 默认语言
  260. //日志
  261. //CHAR g_strDirectory[MAX_PATH_LENGTH + 1]; // 软件所在路径
  262. CHAR g_strAppName[MAX_PATH_LENGTH + 1] = {0}; // 软件名称
  263. CHAR g_strSummaryLogPath[MAX_PATH_LENGTH + 1] = {0}; // 日志存放目录
  264. INT g_nLogSaveTimes = 0; // 日志保存月数
  265. //环境参数配置
  266. INT g_nLevelWav = 0; // 语音通知级别
  267. INT g_nLevelSms = 0; // 发送短信级别
  268. INT g_nLevelEmail = 0; // 发送Email级别
  269. INT g_nLevelDevInterrupt = 0; // 通讯中断级别
  270. INT g_nLevelDlg = 0; // 本地报警提示框级别
  271. INT g_nLevelLocalWav = 0; // 本地声音提示级别
  272. INT g_nDBRecordDate = 0; // 数据库记录时间
  273. CHAR g_strNoticePre[MAX_SERVER_LENGTH + 1] = ""; // 通知前辍
  274. INT g_nNoticeDelay = 0; // 通知延时
  275. INT g_nEncryptionType = 0; // 加密类型
  276. //Sms
  277. INT g_nSendSms = 0; // 是否启动短信报警功能
  278. CHAR g_strSmsComPort[MAX_TEL_LENGTH + 1] = {0}; // 短信猫端口
  279. INT g_nSmsRate = 0; // 串口波特率
  280. INT g_nSmsDataBit = 8; // 数据位
  281. INT g_nSmsStopBit = 1; // 停止位
  282. INT g_nSmsParity = 0; // 检验位
  283. INT g_nSmsInterval = 100; // 间隔时间
  284. INT g_nSmsLanguageTrans = 0; // 是否需要繁简转换
  285. INT g_nSmsMaxChar = 70; // 短信猫支持最大字符个数
  286. INT g_nSmsMakeCall = 0; // 发送短信后,是否拔打电话提醒 本来是1,chn modify
  287. CHAR g_strSmsSMSC[MAX_TEL_LENGTH + 1] = {0}; // smsc号码
  288. INT g_nSmsTimOut = 0; // 短信发送超时
  289. INT g_nSmsCallTimes = 0;
  290. //Email
  291. INT g_nSendEmail = 0; // 是否启动Email报警功能
  292. CHAR g_strEmailSMTPSrv[MAX_MAILSERVER_LENGTH]={0}; // SMTPServer地址
  293. INT g_nEmailSMTPPort = 0; // SMTP端口
  294. INT g_nEmailIsNeed = 0; // 是否需要身份验证
  295. CHAR g_strEmailUserAcc[MAX_USER_LENGTH]={0}; // 用户名
  296. CHAR g_strEmailUserPwd[MAX_PASSWORD_LENGTH]={0}; // 密码
  297. INT g_nEmailTimeOut = 0; // 发送邮件超时
  298. CHAR g_strEmailFromAddr[MAX_MAILTO_LENGTH]={0}; // 发信人Email地址
  299. CHAR g_strEmailSubject[MAX_EMAIL_LENGTH]={0}; // Email标题
  300. INT g_nEmailCallTimes = 0;
  301. //语音通知
  302. INT g_nSendVoice = 0; // 是否启动语音通知功能
  303. INT g_nNoticeCardType = 1; // 板卡类型
  304. CHAR g_strNoticeTelPre[MAX_TEL_LENGTH + 1] = {0}; // 外线前缀
  305. INT g_nNoticeCallDelay = 0; // 两次呼叫间隔时间
  306. INT g_nNoticeCallTimes = 0; // 最大的呼叫次数
  307. vector<USERINFO> g_vtUserInfo;
  308. vector<USERROLEINFO> g_vtUserRoleInfo;
  309. //TTS参数配置
  310. INT g_nTTSType = 5; // TTS格式类型
  311. INT g_nTTSRate = 2; // TTS语速 (-10 - 10)
  312. INT g_nTTSVolume = 2; // TTS音量 (0 - 100)
  313. // 报警参数设置
  314. INT g_nAlarmModeIsDlg = 0; // 是否弹出报警提示框
  315. INT g_nAlarmModeShowDlgTimes = 0; // 提示框显示次数
  316. INT g_nAlarmModeIsSound = 0; // 是否本地播放报警提示音
  317. INT g_nAlarmModeSoundNum = 0; // 声音播放次数,0:代表无限播放,直到报警被确认
  318. //定时发送短信和电话参数配置
  319. INT g_nTimingEnable = 0;
  320. INT g_nTimingWeeks = 0;
  321. INT g_nTimingHours = 0;
  322. INT g_nTimingMinutes = 0;
  323. INT g_nTimingPreiods = 0;
  324. //变量输出,特别为上海烟草局做的
  325. INT g_nOutputEnable = 0;
  326. CHAR g_strOutputPath[MAX_PATH_LENGTH + 1] = {0}; // 输出内容存放路径
  327. CHAR g_strOutputFileName[MAX_PATH_LENGTH + 1] = {0}; // 输出内容存放路径
  328. CHAR g_strOutputClock[MAX_PATH_LENGTH + 1] = {0}; // 输出内容存放路径
  329. INT g_nOutputLineCount1 = 0;
  330. CHAR g_strOutputLine1[MAX_MSG_LENGTH + 1] = {0}; // 第一行
  331. INT g_nOutputLineCount2 = 0;
  332. CHAR g_strOutputLine2[MAX_MSG_LENGTH + 1] = {0}; // 第二行
  333. INT g_nOutputLineCount3 = 0;
  334. CHAR g_strOutputLine3[MAX_MSG_LENGTH + 1] = {0}; // 第三行
  335. INT g_nOutputLineCount4 = 0;
  336. CHAR g_strOutputLine4[MAX_MSG_LENGTH + 1] = {0}; // 第四行
  337. INT g_nOutputLineCount5 = 0;
  338. CHAR g_strOutputLine5[MAX_MSG_LENGTH + 1] = {0}; // 第五行
  339. INT g_nOutputLineCount6 = 0;
  340. CHAR g_strOutputLine6[MAX_MSG_LENGTH + 1] = {0}; // 第六行
  341. INT g_nOutputLineCount7 = 0;
  342. CHAR g_strOutputLine7[MAX_MSG_LENGTH + 1] = {0}; // 第七行
  343. INT g_nOutputLineCount8 = 0;
  344. CHAR g_strOutputLine8[MAX_MSG_LENGTH + 1] = {0}; // 第八行
  345. INT g_nOutputLineCount9 = 0;
  346. CHAR g_strOutputLine9[MAX_MSG_LENGTH + 1] = {0}; // 第九行
  347. INT g_nOutputLineCount10 = 0;
  348. CHAR g_strOutputLine10[MAX_MSG_LENGTH + 1] = {0}; // 第十行
  349. CHAR g_strOutputLineUid1[MAX_UID + 1] = {0};
  350. CHAR g_strOutputLineUid2[MAX_UID + 1] = {0};
  351. CHAR g_strOutputLineUid3[MAX_UID + 1] = {0};
  352. CHAR g_strOutputLineUid4[MAX_UID + 1] = {0};
  353. CHAR g_strOutputLineUid5[MAX_UID + 1] = {0};
  354. CHAR g_strOutputLineUid6[MAX_UID + 1] = {0};
  355. CHAR g_strOutputLineUid7[MAX_UID + 1] = {0};
  356. CHAR g_strOutputLineUid8[MAX_UID + 1] = {0};
  357. CHAR g_strOutputLineUid9[MAX_UID + 1] = {0};
  358. CHAR g_strOutputLineUid10[MAX_UID + 1] = {0};
  359. //是否启用Snmp参数配置
  360. INT g_nSnmpEnable = 0;
  361. CHAR g_strSnmpOidRoot[MAX_OBJ_OID + 1] = {0};
  362. CHAR g_strSnmpIP[MAX_EQUIP_IP + 1] = {0};
  363. CHAR g_strSnmpField[MAX_EQUIP_DESC + 1] = {0};
  364. //资源字符串
  365. CString g_strServiceName;
  366. CString g_strHintSysRun;
  367. CString g_strHintAlarmWelcome;
  368. CString g_strHintVoiceEnd;
  369. CString g_strHintReturnNormal;
  370. CString g_strHintUpperLimit;
  371. CString g_strHintLowerLimit;
  372. CString g_strHintCurrValue;
  373. CString g_strHintBlance;
  374. CString g_strHintDateLimit;
  375. LIST_VAR_NOTICE g_listVarNotice;
  376. //服务
  377. TCHAR g_szServiceName[] = _T("DataBase Monitor Service");
  378. //软件加密
  379. HINSTANCE g_hSoftRegisterLibModule = NULL;
  380. Reg_DLLInit pRegdllInit = NULL;
  381. Reg_DLLJudgeIsRegister pRegdllJudgeIsRegister = NULL;
  382. Reg_DLLUnInit pRegdllUnInit = NULL;
  383. Reg_DLLGetHourToCount pRegdllGetHourToCount = NULL;
  384. Reg_DLLIsValidTime pRegdllIsValidTime = NULL;
  385. Reg_DLLAddUserDate pRegdllAddUserDate = NULL;
  386. // TTS
  387. HINSTANCE hTTSModule = NULL;
  388. MySTONEU_DLLRegisterTTS pStoneUDllRegisterTTS = NULL;
  389. MySTONEU_DLLUnRegisterTTS pStoneUDllUnRegisterTTS = NULL;
  390. MySTONEU_DLLTxtToWav pStoneUDLLTxtToWav = NULL;
  391. // 语音通知动态库输出函数
  392. HINSTANCE g_hVoiceLibModule = NULL;
  393. STONEU_DLLRegisterVoice pStoneUDllRegisterVoice;
  394. STONEU_DLLUnRegisterVoice pStoneUDllUnRegisterVoice;
  395. STONEU_DLLAllocateChannel pStoneUDllAllocateChannel = NULL;
  396. // Email输出函数
  397. HINSTANCE g_hEmailLibModule = NULL;
  398. EMAIL_DLLInit pEmailDllInit = NULL;
  399. EMAIL_DLLUnInit pEmailDllUnInit = NULL;
  400. EMAIL_DLLSendEmail pEmailDllSendEmail = NULL;
  401. // Sms输出函数
  402. HINSTANCE g_hSmsLibModule = NULL;
  403. SMS_DLLInit pSmsDllInit = NULL;
  404. SMS_DLLUnInit pSmsDllUnInit = NULL;
  405. SMS_DLLSendSms pSmsDllSendSms = NULL;
  406. SMS_DLLGetCSQ pSmsDllGetCSQ = NULL;
  407. SMS_DLLSetCallBack pSmsDllSetCallBack = NULL;
  408. SMS_DLLGetBalance pSmsGetBalance = NULL;
  409. bool g_bAlarmNoticeFlag=true;//报警通知开头,由短信控制
  410. // Snmp输出函数
  411. HINSTANCE g_hSnmpLibModule = NULL;
  412. SNMP_DLL_GetVale pSnmpDllGetValue = NULL;
  413. SNMP_DLL_SetValue pSnmpDllSetValue = NULL;
  414. WORD AsciiToBYTE(BYTE btSrc);
  415. char ByteToAscii(BYTE btSrc);
  416. /*字符全转为大写*/
  417. void ByteToUpper(char *szMsg)
  418. {
  419. for (int i=0; i< strlen(szMsg); i++)
  420. {
  421. if ((szMsg[i]>='a') && (szMsg[i]<='z'))
  422. {
  423. szMsg[i] = szMsg[i] - 32;
  424. }
  425. else
  426. {
  427. szMsg[i] = szMsg[i];
  428. }
  429. }
  430. }
  431. WORD AsciiToBYTE(BYTE btSrc)
  432. {
  433. WORD chDest = (WORD)btSrc;
  434. if ((btSrc >= 'A')&&(btSrc <= 'F'))
  435. {
  436. chDest = chDest - 'A' + 10;
  437. }
  438. else if ((btSrc >= 'a')&&(btSrc <= 'f'))
  439. {
  440. chDest = chDest - 'a' + 10;
  441. }
  442. else if ((btSrc >= '0')&&(btSrc <= '9'))
  443. {
  444. chDest -= '0';
  445. }
  446. return chDest;
  447. }
  448. char lowercase2uppercase(BYTE btSrc)
  449. {
  450. if( btSrc >= 'a' && btSrc <= 'z' )
  451. {
  452. return btSrc - 'a' + 'A';
  453. }
  454. return btSrc;
  455. }
  456. char ByteToAscii(BYTE btSrc)
  457. {
  458. char chDest;
  459. if( btSrc < 10 )
  460. {
  461. chDest = (char)(btSrc % 10 + '0');
  462. chDest = lowercase2uppercase(chDest);
  463. return chDest;
  464. }
  465. else
  466. {
  467. chDest = ByteToAscii( btSrc / 10 ) + (char)( btSrc % 10 + '0' );
  468. chDest = lowercase2uppercase(chDest);
  469. return chDest;
  470. }
  471. }
  472. int DigitToBinary(WORD wdSource, char* pDes, int iBit)
  473. {
  474. char pTmpBuf[17] = {0};
  475. char chBuffer[17] = {0};
  476. //wdSource =htonl(wdSource);
  477. itoa(wdSource, pTmpBuf, 2);
  478. int iLen = strlen(pTmpBuf) - 1;
  479. char chValue[17] = {0};
  480. strcpy(chValue, pTmpBuf);
  481. for (int i =0; i<=iLen; i++)
  482. {
  483. pTmpBuf[i] = chValue[iLen - i];
  484. }
  485. for (int k = 0; k<iBit; k++)
  486. {
  487. if ( 0x00 == pTmpBuf[iBit - k - 1])
  488. chBuffer[k] = 0x30;
  489. else
  490. chBuffer[k] = pTmpBuf[iBit - k - 1];
  491. }
  492. memcpy(pDes, chBuffer, iBit);
  493. return 0;
  494. }
  495. int StrUpper(char *pSource, char *pDest)
  496. {
  497. int length, i;
  498. length = strlen(pSource);
  499. for (i = 0; i < length; i++) {
  500. if ((pSource[i] >= 'a') && (pSource[i] <= 'z')){
  501. pDest[i] = _toupper(pSource[i]);
  502. }
  503. else
  504. pDest[i] = pSource[i];
  505. }
  506. return 0;
  507. }
  508. int StrLower(char *pSource, char *pDest)
  509. {
  510. int length, i;
  511. length = strlen(pSource);
  512. for (i = 0; i < length; i++) {
  513. if ((pSource[i] >= 'A') && (pSource[i] <= 'Z')){
  514. pDest[i] = _tolower(pSource[i]);
  515. }
  516. else
  517. pDest[i] = pSource[i];
  518. }
  519. return 0;
  520. }
  521. char Hex16(char WillChangeNum[]) //该函数把四位二进制转换成十六进制数
  522. {
  523. int i;
  524. i = (WillChangeNum[3]) + (WillChangeNum[2] * 10) +
  525. (WillChangeNum[1] * 100) + (WillChangeNum[0] * 1000);
  526. switch(i)
  527. {
  528. case 0:
  529. return 0;
  530. case 1:
  531. return 1;
  532. case 10:
  533. return 2;
  534. case 11:
  535. return 3;
  536. case 100:
  537. return 4;
  538. case 101:
  539. return 5;
  540. case 110:
  541. return 6;
  542. case 111:
  543. return 7;
  544. case 1000:
  545. return 8;
  546. case 1001:
  547. return 9;
  548. case 1010:
  549. return 0x0A;
  550. case 1011:
  551. return 0x0B;
  552. case 1100:
  553. return 0x0C;
  554. case 1101:
  555. return 0x0D;
  556. case 1110:
  557. return 0x0E;
  558. case 1111:
  559. return 0x0F;
  560. }
  561. return -1;
  562. }
  563. bool CanDelLog( CString sLogPath,int iMonth )
  564. {
  565. bool bRet = false;
  566. int nYear=0,nMonth=0,nDay=0;
  567. nYear = atoi( sLogPath.Mid( sLogPath.GetLength()-12,4 ) );
  568. nMonth = atoi( sLogPath.Mid( sLogPath.GetLength()-8,2 ) );
  569. nDay = atoi( sLogPath.Mid( sLogPath.GetLength()-6,2 ) );
  570. CTime t1(CTime::GetCurrentTime());
  571. CTime t2( nYear, nMonth, nDay, 0, 0, 0 );
  572. CTimeSpan ts = t1 - t2;
  573. if( ts.GetTotalHours()/24/30 > iMonth )
  574. bRet = true;
  575. return bRet;
  576. }
  577. bool DeleteLog( CString strPath, CString strFileName, int nLayer )
  578. {
  579. CStringArray saFilePath;
  580. long hfile;
  581. struct _finddata_t fFile;
  582. CString strCurr = strPath + "\\" + strFileName;
  583. int nDone=0;
  584. hfile = _findfirst( (char *)(LPCTSTR)strCurr, &fFile );
  585. if( -1L != hfile )
  586. {
  587. while( !( nDone = _findnext(hfile, &fFile) ) )
  588. {
  589. if( !strcmp(fFile.name,"..") ) continue;
  590. if( ( fFile.attrib==16 || fFile.attrib==18 || fFile.attrib==48 || fFile.attrib==2064 ||
  591. fFile.attrib==2096 || fFile.attrib==2098 || fFile.attrib==16432 || fFile.attrib==16434 ) ) //_A_SUBDIR
  592. {
  593. }
  594. else
  595. {
  596. CString str = fFile.name;
  597. CString sFileNameTemp = strPath + "\\" + str;
  598. if( -1 != str.Find( "summary" ) )
  599. {
  600. saFilePath.Add( sFileNameTemp );
  601. }
  602. }
  603. }
  604. _findclose(hfile);
  605. }
  606. for( int i=0;i<saFilePath.GetCount();i++ )//g_nLogSaveTimes summary20110929.log
  607. {
  608. CString s;
  609. s = saFilePath.GetAt( i );
  610. if( CanDelLog( s,g_nLogSaveTimes ) )
  611. DeleteFile( s );
  612. }
  613. return true;
  614. }
  615. void g_GetAllLogFile()
  616. {
  617. //DWORD returnValue;
  618. double dBegin=0.0,dEnd=0.0,dNow=0.0,dTemp=0.0;
  619. g_strAllVideoFile.RemoveAll();
  620. //LOG4C((LOG_NOTICE, "g_strSummaryLogPath = %s ", g_strSummaryLogPath ));
  621. //CString strPath, CString strFileName, int nLayer )
  622. CStringArray saFilePath;
  623. long hfile;
  624. struct _finddata_t fFile;
  625. CString strCurr;
  626. strCurr.Format( "%s\\Log\\*.*",g_strSummaryLogPath );
  627. int nDone=0;
  628. hfile = _findfirst( (char *)(LPCTSTR)strCurr, &fFile );
  629. if( -1L != hfile )
  630. {
  631. while( !( nDone = _findnext(hfile, &fFile) ) )
  632. {
  633. if( !strcmp(fFile.name,"..") ) continue;
  634. if( ( fFile.attrib==16 || fFile.attrib==18 || fFile.attrib==48 || fFile.attrib==2064 ||
  635. fFile.attrib==2096 || fFile.attrib==2098 || fFile.attrib==16432 || fFile.attrib==16434 ) ) //_A_SUBDIR
  636. {
  637. }
  638. else
  639. {
  640. CString str = fFile.name;
  641. CString sFileNameTemp;// = g_strSummaryLogPath + "\\" + str;
  642. sFileNameTemp.Format( "%s\\Log\\%s",g_strSummaryLogPath,str );
  643. //LOG4C((LOG_NOTICE, "%s ", sFileNameTemp ));
  644. if( -1 != str.Find( "summary" ) )
  645. {
  646. g_strAllVideoFile.Add( sFileNameTemp );
  647. CString str1,str2,s1,s2,sTemp;
  648. for( int i=0;i<g_strAllVideoFile.GetCount();i++ )//summary20110929.log
  649. {
  650. str1 = g_strAllVideoFile[i];
  651. s1 = str1.Mid( str1.GetLength()-12,8 );
  652. dBegin = atof(s1);
  653. for( int j=i+1;j<g_strAllVideoFile.GetCount();j++ )
  654. {
  655. str2 = g_strAllVideoFile[j];
  656. s2 = str2.Mid( str2.GetLength()-12,8 );
  657. dEnd = atof(s2);
  658. if( dEnd<dBegin )
  659. {
  660. dTemp = dBegin;
  661. dBegin = dEnd;
  662. dEnd = dTemp;
  663. sTemp = str1;
  664. str1 = str2;
  665. str2 = sTemp;
  666. g_strAllVideoFile[i] = str1;
  667. g_strAllVideoFile[j] = str2;
  668. }
  669. }
  670. }
  671. }
  672. }
  673. }
  674. _findclose(hfile);
  675. }
  676. }
  677. bool g_DiskVelumnIsEnough( int iDiskVolume,CString sPath )
  678. {
  679. bool bRet = false;
  680. double dVelume=0.0,dRemainVelume=0.0;
  681. dVelume = 1024*iDiskVolume;
  682. ULARGE_INTEGER lpuse;
  683. ULARGE_INTEGER lptotal;
  684. ULARGE_INTEGER lpfree;
  685. GetDiskFreeSpaceEx(sPath,&lpuse,&lptotal,&lpfree);
  686. CString s;
  687. s.Format("%4.4fGB\n",lpfree.QuadPart/1024.0/1024.0);
  688. dRemainVelume = lpfree.QuadPart/1024.0/1024.0;
  689. if( dRemainVelume>=dVelume )
  690. bRet = true;
  691. return bRet;
  692. }
  693. void WriteSummaryLog(CHAR *pdevname, CHAR *pHappenTime, CHAR* memo, int id, CHAR *ptypedesc, double currvalue, CHAR* varuid, CHAR *varname)
  694. {
  695. struct tm *tim;
  696. long i=0;
  697. char tmp[32],tmpfile[64];
  698. char tmpPrint[8000]={0};
  699. FILE *fp;
  700. if( !g_DiskVelumnIsEnough( 3,g_strSummaryLogPath ) )
  701. {
  702. CString str;
  703. for( int i=0;i<3;i++ )
  704. {
  705. if( g_strAllVideoFile.GetCount()>0 )
  706. {
  707. str = g_strAllVideoFile[0];
  708. if( PathFileExists(str) )
  709. DeleteFile( str );
  710. g_strAllVideoFile.RemoveAt( 0 );
  711. }
  712. }
  713. }
  714. //if(iLogLevel<=WRITEDEBUG)
  715. {
  716. time((time_t*)&i);
  717. tim=localtime((time_t*)&i);
  718. #if 1 // 每天存一个文件
  719. sprintf(tmp,"summary%04d%02d%02d",tim->tm_year+1900,tim->tm_mon+1,tim->tm_mday);
  720. sprintf(tmpfile,"%s\\Log\\%s.log",g_strSummaryLogPath, tmp);
  721. #else // 每个月存一个文件
  722. sprintf(tmp,"summary%04d%02d",tim->tm_year+1900,tim->tm_mon+1);
  723. sprintf(tmpfile,"%s\\Log\\%s.log",g_strSummaryLogPath, tmp);
  724. #endif
  725. fp=fopen(tmpfile,"at");
  726. if (fp == NULL)
  727. {
  728. return;
  729. }
  730. sprintf(tmpPrint, "%c%s%c;%c%s%c;%c%s%c;%c%s%c;%.4f;%c%s%c;%c%s%c",
  731. '"', pdevname,'"', '"',pHappenTime,'"', '"',memo,'"', '"',ptypedesc,'"', currvalue,'"',varuid,'"', '"',varname,'"');
  732. fputs(tmpPrint,fp);
  733. fputs("\r\n", fp);
  734. fclose(fp);
  735. CTime ctNow = CTime::GetCurrentTime();
  736. int nHour;
  737. nHour = ctNow.GetHour();
  738. static bool bCanDelLog = true;
  739. if( nHour == 23 && bCanDelLog )
  740. {
  741. bCanDelLog = false;
  742. CString strDectory;
  743. strDectory.Format("%s\\Log", g_strSummaryLogPath );
  744. DeleteLog( strDectory,"*.*",0 );
  745. LOG4C((LOG_NOTICE, "删除Log文件" ));
  746. g_GetAllLogFile();
  747. }
  748. else if( nHour != 23 )
  749. {
  750. bCanDelLog = true;
  751. }
  752. }
  753. //if(iLogLevel<=DISPDEBUG)
  754. // printf("%s\r\n",buf);
  755. }
  756. BYTE TwoByteToByte(BYTE b1, BYTE b2)//两个字符转换为一个字符
  757. {
  758. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  759. BYTE b = 0;
  760. if(b1 >= 'A' && b1 <= 'F')
  761. b += (b1 - 'A' + 10)*16;
  762. else if(b1 >= 'a' && b1 <= 'f')
  763. b += (b1 - 'a' + 10)*16;
  764. else
  765. b += (b1 - '0')*16;
  766. if(b2 >= 'A' && b2 <= 'F')
  767. b += b2 - 'A' + 10;
  768. else if(b2 >= 'a' && b2 <= 'f')
  769. b += b2 - 'a' + 10;
  770. else
  771. b += b2 - '0';
  772. return b;
  773. }
  774. void ByteToTwoByte(BYTE b, BYTE b2[])//一个字符转换为两个字符
  775. {
  776. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  777. char szBuf[3];
  778. int nData = b;
  779. sprintf(szBuf, "%02X", nData);
  780. memcpy(b2, szBuf, 2);
  781. }
  782. int ProcessResWriteSingleVarData( CString sVarName,int iData )
  783. {
  784. CString sUid;
  785. int nVarID = 0;
  786. iData = iData;
  787. int nDeviceIndex = -1, nVarIndex = -1;
  788. BOOL bFind = FindVar( sUid, nVarID,sVarName, nDeviceIndex, nVarIndex);
  789. //LOG4C((LOG_NOTICE, "sUid = %s, nVarID = %d, sVarName = %s,iData = %d ", sUid,nVarID,sVarName,iData));
  790. if( bFind == FALSE )
  791. {
  792. LOG4C((LOG_NOTICE, "FindVar return false" ));
  793. return -1;
  794. }
  795. g_nDealAWAStatus = 1;//处理声光报警状态 -1未初始化 0初始化 1在处理中 2处理完成 3新事件
  796. CDevice *pDev = g_pDevicesManager->m_Devices[nDeviceIndex];
  797. CBaseVar *pBaseVar = pDev->m_Vars[nVarIndex];
  798. SETBASEPARAM SetBasePara;
  799. memset( &SetBasePara, 0, sizeof(SETBASEPARAM) );
  800. //网络设备
  801. char chDllName[MAX_PATH] = {0};
  802. strcpy(chDllName, (char *)(LPCTSTR)pDev->m_strProtocoldllname);
  803. StrLower(chDllName,chDllName);
  804. char szIniName[MAX_PATH] = {0};
  805. strcpy(szIniName, (char *)(LPCTSTR)pDev->m_strIniName);
  806. StrLower(szIniName, szIniName);
  807. int nIndex = pDev->m_nThreadHandleIndex;
  808. if (pDev->m_bySpecialdevice == 0) // modbus rtu 设备
  809. {
  810. if( NULL != g_hRequestDataThread[nIndex] )
  811. SuspendThread(g_hRequestDataThread[nIndex]);
  812. int nSetCount = 0;
  813. // 写3次串口,如果不成功则放弃
  814. do
  815. {
  816. if( nSetCount > 5 ) break;
  817. if( RtuRequestWrData( (char *)(LPCTSTR)sUid, nVarID, iData) == 0)
  818. {
  819. break;
  820. }
  821. else
  822. {
  823. }
  824. nSetCount++;
  825. }while( WaitForSingleObject( g_hRunObject, 1250L ) == WAIT_TIMEOUT );
  826. if( NULL != g_hRequestDataThread[nIndex] )
  827. ResumeThread(g_hRequestDataThread[nIndex]);
  828. }
  829. else if( pDev->m_bySpecialdevice == 1 ) // modbus Ascii 设备
  830. {
  831. if( NULL != g_hRequestDataThread[nIndex] )
  832. SuspendThread(g_hRequestDataThread[nIndex]);
  833. int nSetCount = 0;
  834. // 写3次串口,如果不成功则放弃
  835. do
  836. {
  837. if( nSetCount > 5 ) break;
  838. if (AscRequestWrData((char*)(LPCTSTR)sUid, nVarID, iData) == 0)
  839. {
  840. AscSingleResponseWriteData((char*)(LPCTSTR)sUid,nVarID);
  841. if (pBaseVar->m_dbData != iData)//判断设置数据是否一致
  842. int a=0;
  843. break;
  844. }
  845. else
  846. {
  847. }
  848. nSetCount++;
  849. }while( WaitForSingleObject( g_hRunObject, 1250L ) == WAIT_TIMEOUT );
  850. if( NULL != g_hRequestDataThread[nIndex] )
  851. ResumeThread(g_hRequestDataThread[nIndex]);
  852. }
  853. else if( pDev->m_bySpecialdevice == 2 ) // modbus tcp 设备
  854. {
  855. int nSetCount = 0;
  856. // 写3次串口,如果不成功则放弃
  857. do
  858. {
  859. if( nSetCount > 5 ) break;
  860. //g_hRequestDataThread[g_nIcpdasIndex]
  861. #if 1
  862. ResetEvent( pDev->m_hSemNet );
  863. Sleep(5 * 1000); //等待5S,防止重置信号量之前,已经有变量在请求,保证变量已经读完
  864. #endif
  865. if( TcpRequestWriteData(pDev->m_iIpport,
  866. pDev->m_iDevideaddr,
  867. (char *)(LPCTSTR)pDev->m_strIp,
  868. pBaseVar->m_iRegisterNum,
  869. pBaseVar->m_nRegStartAddr,
  870. pBaseVar->m_iFuncID,
  871. (int)iData) == 0 )
  872. {
  873. SetEvent( pDev->m_hSemNet );
  874. break;
  875. }
  876. else
  877. {
  878. SetEvent( pDev->m_hSemNet );
  879. }
  880. nSetCount++;
  881. }while( WaitForSingleObject( g_hRunObject, 1250L ) == WAIT_TIMEOUT );
  882. }
  883. else if( pDev->m_bySpecialdevice == 3 ) // snmp 设备
  884. {
  885. CString strSetValue;
  886. strSetValue.Format("%.1f", iData);
  887. if( pSnmpDllSetValue(
  888. (char *)(LPCTSTR)pDev->m_strIp,
  889. (char *)(LPCTSTR)pBaseVar->m_strFields,
  890. (char *)(LPCTSTR)pBaseVar->m_strSnmpoi,
  891. "int",
  892. 1,
  893. 300,
  894. (char *)(LPCTSTR)strSetValue
  895. ) == 0 )
  896. {
  897. }
  898. else
  899. {
  900. }
  901. }
  902. else if( pDev->m_bySpecialdevice == 4 ) // RS232 设备
  903. {
  904. if (strcmp(chDllName, "icpdas.dll") ==0)
  905. {
  906. if( NULL != g_hRequestDataThread[nIndex] )
  907. int nRet = SuspendThread(g_hRequestDataThread[nIndex]);
  908. int nSetCount = 0;
  909. // 写3次串口,如果不成功则放弃
  910. do
  911. {
  912. if( nSetCount > 5 ) break;
  913. if (RequestWrIcpdasData((char*)(LPCTSTR)sUid, nVarID, iData) == 0)
  914. {
  915. break;
  916. }
  917. else
  918. {
  919. }
  920. nSetCount++;
  921. }while( WaitForSingleObject( g_hRunObject, 250L ) == WAIT_TIMEOUT );//1250L
  922. if( NULL != g_hRequestDataThread[nIndex] )
  923. int nRet = ResumeThread(g_hRequestDataThread[nIndex]);
  924. }
  925. else if (strcmp(chDllName, "stulz.dll") ==0)
  926. {
  927. if( NULL != g_hRequestDataThread[nIndex] )
  928. int nRet = SuspendThread(g_hRequestDataThread[nIndex]);
  929. int nSetCount = 0;
  930. // 写3次串口,如果不成功则放弃
  931. do
  932. {
  933. if( nSetCount > 5 ) break;
  934. if (RequestWrStulzData((char*)(LPCTSTR)sUid, nVarID, iData) == 0)
  935. {
  936. break;
  937. }
  938. else
  939. {
  940. }
  941. nSetCount++;
  942. }while( WaitForSingleObject( g_hRunObject, 250L ) == WAIT_TIMEOUT );//1250L
  943. if( NULL != g_hRequestDataThread[nIndex] )
  944. int nRet = ResumeThread(g_hRequestDataThread[nIndex]);
  945. }
  946. else if( strcmp(chDllName, "gree.dll") == 0 )
  947. {
  948. if( NULL != g_hRequestDataThread[nIndex] )
  949. int nRet = SuspendThread(g_hRequestDataThread[nIndex]);
  950. int nSetCount = 0;
  951. // 写10次串口,如果不成功则放弃
  952. do
  953. {
  954. if( nSetCount > 5 ) break;
  955. if (RequestGreeWrData( (char *)(LPCTSTR)sUid,
  956. nVarID, iData, (char *)(LPCTSTR)pBaseVar->m_strRs232cmd ) == 0 )
  957. {
  958. break;
  959. }
  960. else
  961. {
  962. }
  963. nSetCount++;
  964. }while( WaitForSingleObject( g_hRunObject, 250L ) == WAIT_TIMEOUT );//1250L
  965. if( NULL != g_hRequestDataThread[nIndex] )
  966. int nRet = ResumeThread(g_hRequestDataThread[nIndex]);
  967. }
  968. else if( strcmp(chDllName, "carel.dll") == 0 )
  969. {
  970. if( NULL != g_hRequestDataThread[nIndex] )
  971. int nRet = SuspendThread(g_hRequestDataThread[nIndex]);
  972. int nSetCount = 0;
  973. // 写3次串口,如果不成功则放弃
  974. do
  975. {
  976. if( nSetCount > 5 ) break;
  977. if (CarelControlRequest( (char *)(LPCTSTR)sUid,nVarID, iData, (char *)(LPCTSTR)pBaseVar->m_strRs232cmd ) == 0 )
  978. {
  979. break;
  980. }
  981. else
  982. {
  983. }
  984. nSetCount++;
  985. }while( WaitForSingleObject( g_hRunObject, 250L ) == WAIT_TIMEOUT );//1250L
  986. if( NULL != g_hRequestDataThread[nIndex] )
  987. int nRet = ResumeThread(g_hRequestDataThread[nIndex]);
  988. }
  989. else if( g_FunIniOK( szIniName ) )
  990. {
  991. if( NULL != g_hRequestDataThread[nIndex] )
  992. SuspendThread(g_hRequestDataThread[nIndex]);
  993. int nSetCount = 0;
  994. char szMsg[MAX_VAR_MSG] = {0};
  995. //memcpy(szMsg, &pWrSnVarData.VarData.Data, sizeof(double));
  996. itoa((int)iData, szMsg, 16);
  997. ByteToUpper(szMsg);
  998. // 写3次串口,如果不成功则放弃
  999. do
  1000. {
  1001. if( nSetCount > 5 ) break;
  1002. if (MostDeviceRequestSet(pDev->m_iPort, pDev->m_iDevideaddr,
  1003. (char*)(LPCTSTR)sUid, nVarID,
  1004. (char*)(LPCTSTR)pBaseVar->m_strRs232cmd,
  1005. szIniName, szMsg) == 0)
  1006. //if (CarelControlRequest( (char *)sUid,
  1007. // pWrSnVarData.ReqVarData.iVarid, pWrSnVarData.VarData.Data, (char *)(LPCTSTR)pBaseVar->m_strRs232cmd ) == 0 )
  1008. {
  1009. break;
  1010. }
  1011. else
  1012. {
  1013. }
  1014. nSetCount++;
  1015. }while( WaitForSingleObject( g_hRunObject, 250L ) == WAIT_TIMEOUT );//1250L
  1016. if( NULL != g_hRequestDataThread[nIndex] )
  1017. ResumeThread(g_hRequestDataThread[nIndex]);
  1018. }
  1019. else
  1020. {
  1021. LOG4C((LOG_NOTICE, "没有实现的设置 dll = %s ,ini = %s",chDllName,szIniName ));
  1022. }
  1023. }
  1024. Sleep( 1000 );
  1025. //g_nDealAWAStatus = 2;//处理声光报警状态 -1未初始化 0初始化 1在处理中 2处理完成 3新事件
  1026. return 0;
  1027. }