123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459 |
- #pragma once
- #include "stdafx.h"
- //#include <windows.h>
- #include "global.h"
- #include "SysLib.h"
- CRITICAL_SECTION g_csWrDataBase; //写日志和告警数据库操作
- CDevicesManager* g_pDevicesManager = NULL;
- #if 0
- CServerSocket* g_pTcpServer = NULL;
- #endif
- // 客户端在线Tick
- DWORD g_dwClientOnlineTick[MAX_CLIENT_NUM] = {0};
- //程序退出事件
- HANDLE g_hRunObject = NULL;
- //客户端数据
- INT g_nClientNum = 0;
- char g_strDirectory[256]={0};
- //DOG
- INT g_nUseTimeLimit = 0; //是否超过使用期限
- //WatchServer
- CHAR g_strWatchServerIP[MAX_EQUIP_IP + 1] = {0};
- CHAR g_strWatchServerPort[MAX_PORT + 1] = {0};
- //Database
- CADODatabase* g_pADODatabase = NULL; // Ado连接组件
- CHAR g_strConnectString[MAX_PATH + 1] = ""; // 数据连接字符串
- CHAR g_strDBType[MAX_SERVER_LENGTH + 1] = ""; // 数据库连接类型(如: SQL SERVER 、Access )
- CHAR g_strAccessFile[MAX_PATH_LENGTH + 1] = ""; // 如果是用Access数据库:Access文件名称
- // 如用其它数据库:为空
- CHAR g_strServerName[MAX_SERVER_LENGTH + 1] = ""; // 数据库服务器名称或IP
- CHAR g_strDataBaseName[MAX_DATABASE_LENGTH + 1] = ""; // 数据库名称
- CHAR g_strUserName[MAX_USER_LENGTH + 1] = ""; // 数据库用户名
- CHAR g_strPassword[MAX_PASSWORD_LENGTH + 1] = ""; // 数据库密码
- //用户信息
- CHAR g_strLoginUserID[MAX_USER_LENGTH + 1] = ""; // 当前使用该软件的用户名
- CHAR g_strLoginPwd[MAX_PASSWORD_LENGTH + 1] = ""; // 当前使用该软件的密码
- CHAR g_strDefaultUserID[MAX_USER_LENGTH + 1] = {0};
- CHAR g_strDefaultUserPwd[MAX_PASSWORD_LENGTH + 1] = {0};
- //提示
- CHAR g_strErrorDBDisConnection[MAX_ERROR_LEN + 1] = {0};
- CHAR g_strMsgDBConnectionSuccess[MAX_ERROR_LEN + 1] = {0};
- CHAR g_strErrorExecSql[MAX_ERROR_LEN + 1] = {0};
- //系统设置
- BOOL g_bEnableTimeLimited = FALSE; // TRUE:时间限制 FALSE:正式版
- INT g_iAutoRunSystem = 0; // 是否开机自启动该系统
- CHAR g_strLanguage[MAX_LANG_LENGTH + 1]={0}; // 默认语言
- //日志
- //CHAR g_strDirectory[MAX_PATH_LENGTH + 1]; // 软件所在路径
- CHAR g_strAppName[MAX_PATH_LENGTH + 1] = {0}; // 软件名称
- CHAR g_strSummaryLogPath[MAX_PATH_LENGTH + 1] = {0}; // 日志存放目录
- //环境参数配置
- CHAR g_strSNCode[MAX_PATH_LENGTH+1] = {0}; // SN序列号;
- INT g_nLevelWav = 0; // 语音通知级别
- INT g_nLevelSms = 0; // 发送短信级别
- INT g_nLevelEmail = 0; // 发送Email级别
- INT g_nLevelDevInterrupt = 0; // 通讯中断级别
- INT g_nLevelDlg = 0; // 本地报警提示框级别
- INT g_nLevelLocalWav = 0; // 本地声音提示级别
- INT g_nDBRecordDate = 0; // 数据库记录时间
- //Sms
- bool g_bSuccesOpen = false;
- INT g_nSendSms = 0; // 是否启动短信报警功能
- CHAR g_strSmsComPort[MAX_TEL_LENGTH + 1] = {0}; // 短信猫端口
- INT g_nSmsRate = 0; // 串口波特率
- INT g_nSmsDataBit = 8; // 数据位
- INT g_nSmsStopBit = 1; // 停止位
- INT g_nSmsParity = 0; // 检验位
- INT g_nSmsInterval = 100; // 间隔时间
- INT g_nSmsLanguageTrans = 0; // 是否需要繁简转换
- INT g_nSmsMaxChar = 70; // 短信猫支持最大字符个数
- INT g_nSmsMakeCall = 0; // 发送短信后,是否拔打电话提醒 本来是1,chn modify
- CHAR g_strSmsSMSC[MAX_TEL_LENGTH + 1] = {0}; // smsc号码
- INT g_nSmsTimOut = 0; // 短信发送超时
- INT g_nSmsCallTimes = 0;
- //Email
- INT g_nSendEmail = 0; // 是否启动Email报警功能
- CHAR g_strEmailSMTPSrv[MAX_MAILSERVER_LENGTH]={0}; // SMTPServer地址
- INT g_nEmailSMTPPort = 0; // SMTP端口
- INT g_nEmailIsNeed = 0; // 是否需要身份验证
- CHAR g_strEmailUserAcc[MAX_USER_LENGTH]={0}; // 用户名
- CHAR g_strEmailUserPwd[MAX_PASSWORD_LENGTH]={0}; // 密码
- INT g_nEmailTimeOut = 0; // 发送邮件超时
- CHAR g_strEmailFromAddr[MAX_MAILTO_LENGTH]={0}; // 发信人Email地址
- CHAR g_strEmailSubject[MAX_EMAIL_LENGTH]={0}; // Email标题
- INT g_nEmailCallTimes = 0;
- //语音通知
- INT g_nSendNotice = 0; // 是否启动语音通知功能
- INT g_nNoticeCardType = 1; // 板卡类型
- CHAR g_strNoticeTelPre[MAX_TEL_LENGTH + 1] = {0}; // 外线前缀
- INT g_nNoticeCallDelay = 0; // 两次呼叫间隔时间
- INT g_nNoticeCallTimes = 0; // 最大的呼叫次数
- vector<USERROLEINFO> g_vtUserRoleInfo;
- //TTS参数配置
- INT g_nTTSType = 5; // TTS格式类型
- // 报警参数设置
- INT g_nAlarmModeIsDlg = 0; // 是否弹出报警提示框
- INT g_nAlarmModeShowDlgTimes = 0; // 提示框显示次数
- INT g_nAlarmModeIsSound = 0; // 是否本地播放报警提示音
- INT g_nAlarmModeSoundNum = 0; // 声音播放次数,0:代表无限播放,直到报警被确认
- //定时发送短信和电话参数配置
- INT g_nTimingEnable = 0;
- INT g_nTimingWeeks = 0;
- INT g_nTimingHours = 0;
- INT g_nTimingMinutes = 0;
- //变量输出,特别为上海烟草局做的
- INT g_nOutputEnable = 0;
- CHAR g_strOutputPath[MAX_PATH_LENGTH + 1] = {0}; // 输出内容存放路径
- CHAR g_strOutputFileName[MAX_PATH_LENGTH + 1] = {0}; // 输出内容存放路径
- CHAR g_strOutputClock[MAX_PATH_LENGTH + 1] = {0}; // 输出内容存放路径
- INT g_nOutputLineCount1 = 0;
- CHAR g_strOutputLine1[MAX_MSG_LENGTH + 1] = {0}; // 第一行
- INT g_nOutputLineCount2 = 0;
- CHAR g_strOutputLine2[MAX_MSG_LENGTH + 1] = {0}; // 第二行
- INT g_nOutputLineCount3 = 0;
- CHAR g_strOutputLine3[MAX_MSG_LENGTH + 1] = {0}; // 第三行
- INT g_nOutputLineCount4 = 0;
- CHAR g_strOutputLine4[MAX_MSG_LENGTH + 1] = {0}; // 第四行
- INT g_nOutputLineCount5 = 0;
- CHAR g_strOutputLine5[MAX_MSG_LENGTH + 1] = {0}; // 第五行
- INT g_nOutputLineCount6 = 0;
- CHAR g_strOutputLine6[MAX_MSG_LENGTH + 1] = {0}; // 第六行
- INT g_nOutputLineCount7 = 0;
- CHAR g_strOutputLine7[MAX_MSG_LENGTH + 1] = {0}; // 第七行
- INT g_nOutputLineCount8 = 0;
- CHAR g_strOutputLine8[MAX_MSG_LENGTH + 1] = {0}; // 第八行
- INT g_nOutputLineCount9 = 0;
- CHAR g_strOutputLine9[MAX_MSG_LENGTH + 1] = {0}; // 第九行
- INT g_nOutputLineCount10 = 0;
- CHAR g_strOutputLine10[MAX_MSG_LENGTH + 1] = {0}; // 第十行
- CHAR g_strOutputLineUid1[MAX_UID + 1] = {0};
- CHAR g_strOutputLineUid2[MAX_UID + 1] = {0};
- CHAR g_strOutputLineUid3[MAX_UID + 1] = {0};
- CHAR g_strOutputLineUid4[MAX_UID + 1] = {0};
- CHAR g_strOutputLineUid5[MAX_UID + 1] = {0};
- CHAR g_strOutputLineUid6[MAX_UID + 1] = {0};
- CHAR g_strOutputLineUid7[MAX_UID + 1] = {0};
- CHAR g_strOutputLineUid8[MAX_UID + 1] = {0};
- CHAR g_strOutputLineUid9[MAX_UID + 1] = {0};
- CHAR g_strOutputLineUid10[MAX_UID + 1] = {0};
- //是否启用Snmp参数配置
- INT g_nSnmpEnable = 0;
- CHAR g_strSnmpObjOid[MAX_OBJ_OID + 1] = {0};
- CHAR g_strSnmpIP[MAX_EQUIP_IP + 1] = {0};
- CHAR g_strSnmpField[MAX_EQUIP_DESC + 1] = {0};
- //资源字符串
- CString g_strServiceName;
- CString g_strHintSysRun;
- CString g_strHintAlarmWelcome;
- CString g_strHintVoiceEnd;
- CString g_strHintReturnNormal;
- CString g_strHintUpperLimit;
- CString g_strHintLowerLimit;
- CString g_strHintCurrValue;
- LIST_VAR_NOTICE g_listVarNotice;
- //服务
- TCHAR g_szServiceName[] = _T("eBus-CMS IO Service");
- // TTS
- HINSTANCE hTTSModule = NULL;
- MySTONEU_DLLRegisterTTS pStoneUDllRegisterTTS = NULL;
- MySTONEU_DLLUnRegisterTTS pStoneUDllUnRegisterTTS = NULL;
- MySTONEU_DLLTxtToWav pStoneUDLLTxtToWav = NULL;
- // 语音通知动态库输出函数
- HINSTANCE g_hNoticeLibModule = NULL;
- STONEU_DLLRegisterVoice pStoneUDllRegisterVoice;
- STONEU_DLLUnRegisterVoice pStoneUDllUnRegisterVoice;
- STONEU_DLLAllocateChannel pStoneUDllAllocateChannel = NULL;
- // Email输出函数
- HINSTANCE g_hEmailLibModule = NULL;
- EMAIL_DLLInit pEmailDllInit = NULL;
- EMAIL_DLLUnInit pEmailDllUnInit = NULL;
- EMAIL_DLLSendEmail pEmailDllSendEmail = NULL;
- // Sms输出函数
- HINSTANCE g_hSmsLibModule = NULL;
- SMS_DLLInit pSmsDllInit = NULL;
- SMS_DLLUnInit pSmsDllUnInit = NULL;
- SMS_DLLSendSms pSmsDllSendSms = NULL;
- SMS_DLLGetCSQ pSmsDllGetCSQ = NULL;
- SMS_DLLSetCallBack pSmsDllSetCallBack = NULL;
- bool g_bAlarmNoticeFlag=true;//报警通知开头,由短信控制
- // Snmp输出函数
- HINSTANCE g_hSnmpLibModule = NULL;
- SNMP_DLL_GetVale pSnmpDllGetValue = NULL;
- SNMP_DLL_SetValue pSnmpDllSetValue = NULL;
- WORD AsciiToBYTE(BYTE btSrc);
- char ByteToAscii(BYTE btSrc);
- /*字符全转为大写*/
- void ByteToUpper(char *szMsg)
- {
- for (int i=0; i< strlen(szMsg); i++)
- {
- if ((szMsg[i]>='a') && (szMsg[i]<='z'))
- {
- szMsg[i] = szMsg[i] - 32;
- }
- else
- {
- szMsg[i] = szMsg[i];
- }
- }
- }
- WORD AsciiToBYTE(BYTE btSrc)
- {
- WORD chDest = (WORD)btSrc;
- if ((btSrc >= 'A')&&(btSrc <= 'F'))
- {
- chDest = chDest - 'A' + 10;
- }
- else if ((btSrc >= 'a')&&(btSrc <= 'f'))
- {
- chDest = chDest - 'a' + 10;
- }
- else if ((btSrc >= '0')&&(btSrc <= '9'))
- {
- chDest -= '0';
- }
- return chDest;
- }
- char lowercase2uppercase(BYTE btSrc)
- {
- if( btSrc >= 'a' && btSrc <= 'z' )
- {
- return btSrc - 'a' + 'A';
- }
- return btSrc;
- }
- char ByteToAscii(BYTE btSrc)
- {
- char chDest;
- if( btSrc < 10 )
- {
- chDest = (char)(btSrc % 10 + '0');
- chDest = lowercase2uppercase(chDest);
- return chDest;
- }
- else
- {
- chDest = ByteToAscii( btSrc / 10 ) + (char)( btSrc % 10 + '0' );
- chDest = lowercase2uppercase(chDest);
- return chDest;
- }
- }
- int DigitToBinary(WORD wdSource, char* pDes, int iBit)
- {
- char pTmpBuf[17] = {0};
- char chBuffer[17] = {0};
- //wdSource =htonl(wdSource);
- itoa(wdSource, pTmpBuf, 2);
- int iLen = strlen(pTmpBuf) - 1;
- char chValue[17] = {0};
- strcpy(chValue, pTmpBuf);
- for (int i =0; i<=iLen; i++)
- {
- pTmpBuf[i] = chValue[iLen - i];
- }
- for (int k = 0; k<iBit; k++)
- {
-
- if ( 0x00 == pTmpBuf[iBit - k - 1])
- chBuffer[k] = 0x30;
- else
- chBuffer[k] = pTmpBuf[iBit - k - 1];
- }
- memcpy(pDes, chBuffer, iBit);
- return 0;
- }
- int StrUpper(char *pSource, char *pDest)
- {
- int length, i;
- length = strlen(pSource);
- for (i = 0; i < length; i++) {
- if ((pSource[i] >= 'a') && (pSource[i] <= 'z')){
- pDest[i] = _toupper(pSource[i]);
- }
- else
- pDest[i] = pSource[i];
- }
- return 0;
- }
- int StrLower(char *pSource, char *pDest)
- {
- int length, i;
- length = strlen(pSource);
- for (i = 0; i < length; i++) {
- if ((pSource[i] >= 'A') && (pSource[i] <= 'Z')){
- pDest[i] = _tolower(pSource[i]);
- }
- else
- pDest[i] = pSource[i];
- }
- return 0;
- }
- char Hex16(char WillChangeNum[]) //该函数把四位二进制转换成十六进制数
- {
- int i;
- i = (WillChangeNum[3]) + (WillChangeNum[2] * 10) +
- (WillChangeNum[1] * 100) + (WillChangeNum[0] * 1000);
- switch(i)
- {
- case 0:
- return 0;
- case 1:
- return 1;
- case 10:
- return 2;
- case 11:
- return 3;
- case 100:
- return 4;
- case 101:
- return 5;
- case 110:
- return 6;
- case 111:
- return 7;
- case 1000:
- return 8;
- case 1001:
- return 9;
- case 1010:
- return 0x0A;
- case 1011:
- return 0x0B;
- case 1100:
- return 0x0C;
- case 1101:
- return 0x0D;
- case 1110:
- return 0x0E;
- case 1111:
- return 0x0F;
- }
- return -1;
- }
- void WriteSummaryLog(CHAR *pdevname, CHAR *pHappenTime, CHAR* memo, int id, CHAR *ptypedesc, double currvalue, CHAR* varuid, CHAR *varname)
- {
- struct tm *tim;
- long i=0;
- char tmp[32],tmpfile[64];
- char tmpPrint[8000]={0};
- FILE *fp;
- //if(iLogLevel<=WRITEDEBUG)
- {
- time(&i);
- tim=localtime(&i);
- #if 1 // 每天存一个文件
- sprintf(tmp,"summary%04d%02d%02d",tim->tm_year+1900,tim->tm_mon+1,tim->tm_mday);
- sprintf(tmpfile,"%s\\Log\\%s.log",g_strSummaryLogPath, tmp);
- #else // 每个月存一个文件
- sprintf(tmp,"summary%04d%02d",tim->tm_year+1900,tim->tm_mon+1);
- sprintf(tmpfile,"%s\\Log\\%s.log",g_strSummaryLogPath, tmp);
- #endif
- fp=fopen(tmpfile,"at");
- if (fp == NULL)
- {
- return;
- }
-
- sprintf(tmpPrint, "%c%s%c;%c%s%c;%c%s%c;%c%s%c;%.4f;%c%s%c;%c%s%c",
- '"', pdevname,'"', '"',pHappenTime,'"', '"',memo,'"', '"',ptypedesc,'"', currvalue,'"',varuid,'"', '"',varname,'"');
- fputs(tmpPrint,fp);
- fputs("\r\n", fp);
- fclose(fp);
-
- }
- //if(iLogLevel<=DISPDEBUG)
- // printf("%s\r\n",buf);
-
- }
- BYTE TwoByteToByte(BYTE b1, BYTE b2)//两个字符转换为一个字符
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
- BYTE b = 0;
- if(b1 >= 'A' && b1 <= 'F')
- b += (b1 - 'A' + 10)*16;
- else if(b1 >= 'a' && b1 <= 'f')
- b += (b1 - 'a' + 10)*16;
- else
- b += (b1 - '0')*16;
- if(b2 >= 'A' && b2 <= 'F')
- b += b2 - 'A' + 10;
- else if(b2 >= 'a' && b2 <= 'f')
- b += b2 - 'a' + 10;
- else
- b += b2 - '0';
- return b;
- }
- void ByteToTwoByte(BYTE b, BYTE b2[])//一个字符转换为两个字符
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
- char szBuf[3];
- int nData = b;
- sprintf(szBuf, "%02X", nData);
- memcpy(b2, szBuf, 2);
- }
|