Global.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. #pragma once
  2. #include "stdafx.h"
  3. //#include <windows.h>
  4. #include "global.h"
  5. #include "SysLib.h"
  6. CRITICAL_SECTION g_csWrDataBase; //写日志和告警数据库操作
  7. CDevicesManager* g_pDevicesManager = NULL;
  8. #if 0
  9. CServerSocket* g_pTcpServer = NULL;
  10. #endif
  11. // 客户端在线Tick
  12. DWORD g_dwClientOnlineTick[MAX_CLIENT_NUM] = {0};
  13. //程序退出事件
  14. HANDLE g_hRunObject = NULL;
  15. //客户端数据
  16. INT g_nClientNum = 0;
  17. char g_strDirectory[256]={0};
  18. //DOG
  19. INT g_nUseTimeLimit = 0; //是否超过使用期限
  20. //WatchServer
  21. CHAR g_strWatchServerIP[MAX_EQUIP_IP + 1] = {0};
  22. CHAR g_strWatchServerPort[MAX_PORT + 1] = {0};
  23. //Database
  24. CADODatabase* g_pADODatabase = NULL; // Ado连接组件
  25. CHAR g_strConnectString[MAX_PATH + 1] = ""; // 数据连接字符串
  26. CHAR g_strDBType[MAX_SERVER_LENGTH + 1] = ""; // 数据库连接类型(如: SQL SERVER 、Access )
  27. CHAR g_strAccessFile[MAX_PATH_LENGTH + 1] = ""; // 如果是用Access数据库:Access文件名称
  28. // 如用其它数据库:为空
  29. CHAR g_strServerName[MAX_SERVER_LENGTH + 1] = ""; // 数据库服务器名称或IP
  30. CHAR g_strDataBaseName[MAX_DATABASE_LENGTH + 1] = ""; // 数据库名称
  31. CHAR g_strUserName[MAX_USER_LENGTH + 1] = ""; // 数据库用户名
  32. CHAR g_strPassword[MAX_PASSWORD_LENGTH + 1] = ""; // 数据库密码
  33. //用户信息
  34. CHAR g_strLoginUserID[MAX_USER_LENGTH + 1] = ""; // 当前使用该软件的用户名
  35. CHAR g_strLoginPwd[MAX_PASSWORD_LENGTH + 1] = ""; // 当前使用该软件的密码
  36. CHAR g_strDefaultUserID[MAX_USER_LENGTH + 1] = {0};
  37. CHAR g_strDefaultUserPwd[MAX_PASSWORD_LENGTH + 1] = {0};
  38. //提示
  39. CHAR g_strErrorDBDisConnection[MAX_ERROR_LEN + 1] = {0};
  40. CHAR g_strMsgDBConnectionSuccess[MAX_ERROR_LEN + 1] = {0};
  41. CHAR g_strErrorExecSql[MAX_ERROR_LEN + 1] = {0};
  42. //系统设置
  43. BOOL g_bEnableTimeLimited = FALSE; // TRUE:时间限制 FALSE:正式版
  44. INT g_iAutoRunSystem = 0; // 是否开机自启动该系统
  45. CHAR g_strLanguage[MAX_LANG_LENGTH + 1]={0}; // 默认语言
  46. //日志
  47. //CHAR g_strDirectory[MAX_PATH_LENGTH + 1]; // 软件所在路径
  48. CHAR g_strAppName[MAX_PATH_LENGTH + 1] = {0}; // 软件名称
  49. CHAR g_strSummaryLogPath[MAX_PATH_LENGTH + 1] = {0}; // 日志存放目录
  50. //环境参数配置
  51. CHAR g_strSNCode[MAX_PATH_LENGTH+1] = {0}; // SN序列号;
  52. INT g_nLevelWav = 0; // 语音通知级别
  53. INT g_nLevelSms = 0; // 发送短信级别
  54. INT g_nLevelEmail = 0; // 发送Email级别
  55. INT g_nLevelDevInterrupt = 0; // 通讯中断级别
  56. INT g_nLevelDlg = 0; // 本地报警提示框级别
  57. INT g_nLevelLocalWav = 0; // 本地声音提示级别
  58. INT g_nDBRecordDate = 0; // 数据库记录时间
  59. //Sms
  60. bool g_bSuccesOpen = false;
  61. INT g_nSendSms = 0; // 是否启动短信报警功能
  62. CHAR g_strSmsComPort[MAX_TEL_LENGTH + 1] = {0}; // 短信猫端口
  63. INT g_nSmsRate = 0; // 串口波特率
  64. INT g_nSmsDataBit = 8; // 数据位
  65. INT g_nSmsStopBit = 1; // 停止位
  66. INT g_nSmsParity = 0; // 检验位
  67. INT g_nSmsInterval = 100; // 间隔时间
  68. INT g_nSmsLanguageTrans = 0; // 是否需要繁简转换
  69. INT g_nSmsMaxChar = 70; // 短信猫支持最大字符个数
  70. INT g_nSmsMakeCall = 0; // 发送短信后,是否拔打电话提醒 本来是1,chn modify
  71. CHAR g_strSmsSMSC[MAX_TEL_LENGTH + 1] = {0}; // smsc号码
  72. INT g_nSmsTimOut = 0; // 短信发送超时
  73. INT g_nSmsCallTimes = 0;
  74. //Email
  75. INT g_nSendEmail = 0; // 是否启动Email报警功能
  76. CHAR g_strEmailSMTPSrv[MAX_MAILSERVER_LENGTH]={0}; // SMTPServer地址
  77. INT g_nEmailSMTPPort = 0; // SMTP端口
  78. INT g_nEmailIsNeed = 0; // 是否需要身份验证
  79. CHAR g_strEmailUserAcc[MAX_USER_LENGTH]={0}; // 用户名
  80. CHAR g_strEmailUserPwd[MAX_PASSWORD_LENGTH]={0}; // 密码
  81. INT g_nEmailTimeOut = 0; // 发送邮件超时
  82. CHAR g_strEmailFromAddr[MAX_MAILTO_LENGTH]={0}; // 发信人Email地址
  83. CHAR g_strEmailSubject[MAX_EMAIL_LENGTH]={0}; // Email标题
  84. INT g_nEmailCallTimes = 0;
  85. //语音通知
  86. INT g_nSendNotice = 0; // 是否启动语音通知功能
  87. INT g_nNoticeCardType = 1; // 板卡类型
  88. CHAR g_strNoticeTelPre[MAX_TEL_LENGTH + 1] = {0}; // 外线前缀
  89. INT g_nNoticeCallDelay = 0; // 两次呼叫间隔时间
  90. INT g_nNoticeCallTimes = 0; // 最大的呼叫次数
  91. vector<USERROLEINFO> g_vtUserRoleInfo;
  92. //TTS参数配置
  93. INT g_nTTSType = 5; // TTS格式类型
  94. // 报警参数设置
  95. INT g_nAlarmModeIsDlg = 0; // 是否弹出报警提示框
  96. INT g_nAlarmModeShowDlgTimes = 0; // 提示框显示次数
  97. INT g_nAlarmModeIsSound = 0; // 是否本地播放报警提示音
  98. INT g_nAlarmModeSoundNum = 0; // 声音播放次数,0:代表无限播放,直到报警被确认
  99. //定时发送短信和电话参数配置
  100. INT g_nTimingEnable = 0;
  101. INT g_nTimingWeeks = 0;
  102. INT g_nTimingHours = 0;
  103. INT g_nTimingMinutes = 0;
  104. //变量输出,特别为上海烟草局做的
  105. INT g_nOutputEnable = 0;
  106. CHAR g_strOutputPath[MAX_PATH_LENGTH + 1] = {0}; // 输出内容存放路径
  107. CHAR g_strOutputFileName[MAX_PATH_LENGTH + 1] = {0}; // 输出内容存放路径
  108. CHAR g_strOutputClock[MAX_PATH_LENGTH + 1] = {0}; // 输出内容存放路径
  109. INT g_nOutputLineCount1 = 0;
  110. CHAR g_strOutputLine1[MAX_MSG_LENGTH + 1] = {0}; // 第一行
  111. INT g_nOutputLineCount2 = 0;
  112. CHAR g_strOutputLine2[MAX_MSG_LENGTH + 1] = {0}; // 第二行
  113. INT g_nOutputLineCount3 = 0;
  114. CHAR g_strOutputLine3[MAX_MSG_LENGTH + 1] = {0}; // 第三行
  115. INT g_nOutputLineCount4 = 0;
  116. CHAR g_strOutputLine4[MAX_MSG_LENGTH + 1] = {0}; // 第四行
  117. INT g_nOutputLineCount5 = 0;
  118. CHAR g_strOutputLine5[MAX_MSG_LENGTH + 1] = {0}; // 第五行
  119. INT g_nOutputLineCount6 = 0;
  120. CHAR g_strOutputLine6[MAX_MSG_LENGTH + 1] = {0}; // 第六行
  121. INT g_nOutputLineCount7 = 0;
  122. CHAR g_strOutputLine7[MAX_MSG_LENGTH + 1] = {0}; // 第七行
  123. INT g_nOutputLineCount8 = 0;
  124. CHAR g_strOutputLine8[MAX_MSG_LENGTH + 1] = {0}; // 第八行
  125. INT g_nOutputLineCount9 = 0;
  126. CHAR g_strOutputLine9[MAX_MSG_LENGTH + 1] = {0}; // 第九行
  127. INT g_nOutputLineCount10 = 0;
  128. CHAR g_strOutputLine10[MAX_MSG_LENGTH + 1] = {0}; // 第十行
  129. CHAR g_strOutputLineUid1[MAX_UID + 1] = {0};
  130. CHAR g_strOutputLineUid2[MAX_UID + 1] = {0};
  131. CHAR g_strOutputLineUid3[MAX_UID + 1] = {0};
  132. CHAR g_strOutputLineUid4[MAX_UID + 1] = {0};
  133. CHAR g_strOutputLineUid5[MAX_UID + 1] = {0};
  134. CHAR g_strOutputLineUid6[MAX_UID + 1] = {0};
  135. CHAR g_strOutputLineUid7[MAX_UID + 1] = {0};
  136. CHAR g_strOutputLineUid8[MAX_UID + 1] = {0};
  137. CHAR g_strOutputLineUid9[MAX_UID + 1] = {0};
  138. CHAR g_strOutputLineUid10[MAX_UID + 1] = {0};
  139. //是否启用Snmp参数配置
  140. INT g_nSnmpEnable = 0;
  141. CHAR g_strSnmpObjOid[MAX_OBJ_OID + 1] = {0};
  142. CHAR g_strSnmpIP[MAX_EQUIP_IP + 1] = {0};
  143. CHAR g_strSnmpField[MAX_EQUIP_DESC + 1] = {0};
  144. //资源字符串
  145. CString g_strServiceName;
  146. CString g_strHintSysRun;
  147. CString g_strHintAlarmWelcome;
  148. CString g_strHintVoiceEnd;
  149. CString g_strHintReturnNormal;
  150. CString g_strHintUpperLimit;
  151. CString g_strHintLowerLimit;
  152. CString g_strHintCurrValue;
  153. LIST_VAR_NOTICE g_listVarNotice;
  154. //服务
  155. TCHAR g_szServiceName[] = _T("eBus-CMS IO Service");
  156. // TTS
  157. HINSTANCE hTTSModule = NULL;
  158. MySTONEU_DLLRegisterTTS pStoneUDllRegisterTTS = NULL;
  159. MySTONEU_DLLUnRegisterTTS pStoneUDllUnRegisterTTS = NULL;
  160. MySTONEU_DLLTxtToWav pStoneUDLLTxtToWav = NULL;
  161. // 语音通知动态库输出函数
  162. HINSTANCE g_hNoticeLibModule = NULL;
  163. STONEU_DLLRegisterVoice pStoneUDllRegisterVoice;
  164. STONEU_DLLUnRegisterVoice pStoneUDllUnRegisterVoice;
  165. STONEU_DLLAllocateChannel pStoneUDllAllocateChannel = NULL;
  166. // Email输出函数
  167. HINSTANCE g_hEmailLibModule = NULL;
  168. EMAIL_DLLInit pEmailDllInit = NULL;
  169. EMAIL_DLLUnInit pEmailDllUnInit = NULL;
  170. EMAIL_DLLSendEmail pEmailDllSendEmail = NULL;
  171. // Sms输出函数
  172. HINSTANCE g_hSmsLibModule = NULL;
  173. SMS_DLLInit pSmsDllInit = NULL;
  174. SMS_DLLUnInit pSmsDllUnInit = NULL;
  175. SMS_DLLSendSms pSmsDllSendSms = NULL;
  176. SMS_DLLGetCSQ pSmsDllGetCSQ = NULL;
  177. SMS_DLLSetCallBack pSmsDllSetCallBack = NULL;
  178. bool g_bAlarmNoticeFlag=true;//报警通知开头,由短信控制
  179. // Snmp输出函数
  180. HINSTANCE g_hSnmpLibModule = NULL;
  181. SNMP_DLL_GetVale pSnmpDllGetValue = NULL;
  182. SNMP_DLL_SetValue pSnmpDllSetValue = NULL;
  183. WORD AsciiToBYTE(BYTE btSrc);
  184. char ByteToAscii(BYTE btSrc);
  185. /*字符全转为大写*/
  186. void ByteToUpper(char *szMsg)
  187. {
  188. for (int i=0; i< strlen(szMsg); i++)
  189. {
  190. if ((szMsg[i]>='a') && (szMsg[i]<='z'))
  191. {
  192. szMsg[i] = szMsg[i] - 32;
  193. }
  194. else
  195. {
  196. szMsg[i] = szMsg[i];
  197. }
  198. }
  199. }
  200. WORD AsciiToBYTE(BYTE btSrc)
  201. {
  202. WORD chDest = (WORD)btSrc;
  203. if ((btSrc >= 'A')&&(btSrc <= 'F'))
  204. {
  205. chDest = chDest - 'A' + 10;
  206. }
  207. else if ((btSrc >= 'a')&&(btSrc <= 'f'))
  208. {
  209. chDest = chDest - 'a' + 10;
  210. }
  211. else if ((btSrc >= '0')&&(btSrc <= '9'))
  212. {
  213. chDest -= '0';
  214. }
  215. return chDest;
  216. }
  217. char lowercase2uppercase(BYTE btSrc)
  218. {
  219. if( btSrc >= 'a' && btSrc <= 'z' )
  220. {
  221. return btSrc - 'a' + 'A';
  222. }
  223. return btSrc;
  224. }
  225. char ByteToAscii(BYTE btSrc)
  226. {
  227. char chDest;
  228. if( btSrc < 10 )
  229. {
  230. chDest = (char)(btSrc % 10 + '0');
  231. chDest = lowercase2uppercase(chDest);
  232. return chDest;
  233. }
  234. else
  235. {
  236. chDest = ByteToAscii( btSrc / 10 ) + (char)( btSrc % 10 + '0' );
  237. chDest = lowercase2uppercase(chDest);
  238. return chDest;
  239. }
  240. }
  241. int DigitToBinary(WORD wdSource, char* pDes, int iBit)
  242. {
  243. char pTmpBuf[17] = {0};
  244. char chBuffer[17] = {0};
  245. //wdSource =htonl(wdSource);
  246. itoa(wdSource, pTmpBuf, 2);
  247. int iLen = strlen(pTmpBuf) - 1;
  248. char chValue[17] = {0};
  249. strcpy(chValue, pTmpBuf);
  250. for (int i =0; i<=iLen; i++)
  251. {
  252. pTmpBuf[i] = chValue[iLen - i];
  253. }
  254. for (int k = 0; k<iBit; k++)
  255. {
  256. if ( 0x00 == pTmpBuf[iBit - k - 1])
  257. chBuffer[k] = 0x30;
  258. else
  259. chBuffer[k] = pTmpBuf[iBit - k - 1];
  260. }
  261. memcpy(pDes, chBuffer, iBit);
  262. return 0;
  263. }
  264. int StrUpper(char *pSource, char *pDest)
  265. {
  266. int length, i;
  267. length = strlen(pSource);
  268. for (i = 0; i < length; i++) {
  269. if ((pSource[i] >= 'a') && (pSource[i] <= 'z')){
  270. pDest[i] = _toupper(pSource[i]);
  271. }
  272. else
  273. pDest[i] = pSource[i];
  274. }
  275. return 0;
  276. }
  277. int StrLower(char *pSource, char *pDest)
  278. {
  279. int length, i;
  280. length = strlen(pSource);
  281. for (i = 0; i < length; i++) {
  282. if ((pSource[i] >= 'A') && (pSource[i] <= 'Z')){
  283. pDest[i] = _tolower(pSource[i]);
  284. }
  285. else
  286. pDest[i] = pSource[i];
  287. }
  288. return 0;
  289. }
  290. char Hex16(char WillChangeNum[]) //该函数把四位二进制转换成十六进制数
  291. {
  292. int i;
  293. i = (WillChangeNum[3]) + (WillChangeNum[2] * 10) +
  294. (WillChangeNum[1] * 100) + (WillChangeNum[0] * 1000);
  295. switch(i)
  296. {
  297. case 0:
  298. return 0;
  299. case 1:
  300. return 1;
  301. case 10:
  302. return 2;
  303. case 11:
  304. return 3;
  305. case 100:
  306. return 4;
  307. case 101:
  308. return 5;
  309. case 110:
  310. return 6;
  311. case 111:
  312. return 7;
  313. case 1000:
  314. return 8;
  315. case 1001:
  316. return 9;
  317. case 1010:
  318. return 0x0A;
  319. case 1011:
  320. return 0x0B;
  321. case 1100:
  322. return 0x0C;
  323. case 1101:
  324. return 0x0D;
  325. case 1110:
  326. return 0x0E;
  327. case 1111:
  328. return 0x0F;
  329. }
  330. return -1;
  331. }
  332. void WriteSummaryLog(CHAR *pdevname, CHAR *pHappenTime, CHAR* memo, int id, CHAR *ptypedesc, double currvalue, CHAR* varuid, CHAR *varname)
  333. {
  334. struct tm *tim;
  335. long i=0;
  336. char tmp[32],tmpfile[64];
  337. char tmpPrint[8000]={0};
  338. FILE *fp;
  339. //if(iLogLevel<=WRITEDEBUG)
  340. {
  341. time(&i);
  342. tim=localtime(&i);
  343. #if 1 // 每天存一个文件
  344. sprintf(tmp,"summary%04d%02d%02d",tim->tm_year+1900,tim->tm_mon+1,tim->tm_mday);
  345. sprintf(tmpfile,"%s\\Log\\%s.log",g_strSummaryLogPath, tmp);
  346. #else // 每个月存一个文件
  347. sprintf(tmp,"summary%04d%02d",tim->tm_year+1900,tim->tm_mon+1);
  348. sprintf(tmpfile,"%s\\Log\\%s.log",g_strSummaryLogPath, tmp);
  349. #endif
  350. fp=fopen(tmpfile,"at");
  351. if (fp == NULL)
  352. {
  353. return;
  354. }
  355. sprintf(tmpPrint, "%c%s%c;%c%s%c;%c%s%c;%c%s%c;%.4f;%c%s%c;%c%s%c",
  356. '"', pdevname,'"', '"',pHappenTime,'"', '"',memo,'"', '"',ptypedesc,'"', currvalue,'"',varuid,'"', '"',varname,'"');
  357. fputs(tmpPrint,fp);
  358. fputs("\r\n", fp);
  359. fclose(fp);
  360. }
  361. //if(iLogLevel<=DISPDEBUG)
  362. // printf("%s\r\n",buf);
  363. }
  364. BYTE TwoByteToByte(BYTE b1, BYTE b2)//两个字符转换为一个字符
  365. {
  366. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  367. BYTE b = 0;
  368. if(b1 >= 'A' && b1 <= 'F')
  369. b += (b1 - 'A' + 10)*16;
  370. else if(b1 >= 'a' && b1 <= 'f')
  371. b += (b1 - 'a' + 10)*16;
  372. else
  373. b += (b1 - '0')*16;
  374. if(b2 >= 'A' && b2 <= 'F')
  375. b += b2 - 'A' + 10;
  376. else if(b2 >= 'a' && b2 <= 'f')
  377. b += b2 - 'a' + 10;
  378. else
  379. b += b2 - '0';
  380. return b;
  381. }
  382. void ByteToTwoByte(BYTE b, BYTE b2[])//一个字符转换为两个字符
  383. {
  384. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  385. char szBuf[3];
  386. int nData = b;
  387. sprintf(szBuf, "%02X", nData);
  388. memcpy(b2, szBuf, 2);
  389. }