123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188 |
- #pragma once
- #include "stdafx.h"
- //#include <windows.h>
- #include "global.h"
- #include "SysLib.h"
- #include <io.h>
- #include "shlwapi.h"
- #include "ascprocess.h"
- #include "rtuprocess.h"
- #include "tcpprocess.h"
- #include "icpdasprocess.h"
- #include "SnmpProcess.h"
- #include "upsParadigmProcess.h"
- #include "stulzprocess.h"
- #include "PowerwareProcess.h"
- #include "greeprocess.h"
- #include "CarelProcess.h"
- #include "MostDevice.h"
- #include "MainPro.h"
- int READ_VAR_ERROR_MAX = 2;//一个设备如果连续这个数都没有数据,则不读后面的数据
- int g_nTryTimeLessToNotice = 10;//当试用期小于这个数时通知用户
- int g_nBlanceLessToNotice = 10;//当卡余额小于这个数时通知用户
- CRITICAL_SECTION g_csWrDataBase; //写日志和告警数据库操作
- CDevicesManager* g_pDevicesManager = NULL;
- CStringArray g_strAllVideoFile;
- #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};
- CString g_strVersion = "3.0.3.2";
- float g_fBlance =0.0;
- //ini文件名存在
- CStringArray g_saIniList;
- void g_FunReadAllIniName( 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( ".ini" ) )
- {
- CString sTemp = str;
- sTemp.Trim();
- sTemp.MakeLower();
- g_saIniList.Add( sTemp );
- //LOG4C((LOG_NOTICE, "%s",sTemp));
- }
- }
- }
- _findclose(hfile);
- }
- }
- bool g_FunIniOK( CString sIniName )
- {
- bool bRet=false;
- CString str;
- for( int i=0;i<g_saIniList.GetCount();i++ )
- {
- str = g_saIniList.GetAt( i );
- if( strcmp(str, sIniName) == 0 )
- {
- bRet = true;
- break;
- }
- }
- return bRet;
- }
- //声光报警
- bool IsPlanTime( CString sPlanTime,int iWeekday,int nHours )
- {
- bool bRet = false;
- if( sPlanTime=="" )
- return true;
- if( iWeekday==1 )
- iWeekday = 6;
- else
- iWeekday -= 2;
- if( sPlanTime[iWeekday*24+nHours]=='1' )
- {
- bRet = true;
- }
- return bRet;
- }
- AWA g_AWA[AWA_NUM_MAX];
- int g_nDealAWAStatus = -1;//处理声光报警状态 -1未初始化 0初始化 1在处理中 2处理完成 3新事件
- //a. 24小时 没变量
- // 不处理
- //b. 24小时 有变量
- // 声光报警
- //c. 12小时 没变量
- // 定时开关
- //d. 12小时 有变量
- // 在这段时间内由变量来控制开关
- bool g_FunSetAWA()//触发/取消 声光报警
- {
- bool bRet = false;
- CString TIME = "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111";
- for( int i=0;i<AWA_NUM_MAX;i++ )
- {
- if( g_AWA[i].sDoSet=="" )
- {
- g_nDealAWAStatus = 2;//处理声光报警状态 -1未初始化 0初始化 1在处理中 2处理完成 3新事件
- return false;
- }
-
- int nSetAWA = 0;//0取消 1设置 -1不处理
- CString str;
- CTime time = CTime::GetCurrentTime();
- int nWeekday = time.GetDayOfWeek();
- int nHours = time.GetHour();
- if( g_AWA[i].sPlanTime==TIME )//没时间限制
- {
- if( g_AWA[i].SA.GetCount()==0 )
- {
- nSetAWA = -1;
- continue;
- }
- else
- {
- if( g_nDealAWAStatus==2 )
- {
- nSetAWA = -1;
- continue;
- }
- for( int m=0;m<g_AWA[i].SA.GetCount();m++ )
- {
- str = g_AWA[i].SA.GetAt( m );
- if( g_pDevicesManager->AWA_VarIsAlarm( str ) )//变量是报警状态
- {
- nSetAWA = 1;
- break;
- }
- }
- }
- }
- else//有时间限制
- {
- if( g_AWA[i].SA.GetCount()==0 )
- {
- if( IsPlanTime( g_AWA[i].sPlanTime,nWeekday,nHours ) )
- nSetAWA = 1;
- }
- else
- {
- if( g_nDealAWAStatus==2 )
- {
- nSetAWA = -1;
- continue;
- }
- if( IsPlanTime( g_AWA[i].sPlanTime,nWeekday,nHours ) )
- {
- for( int m=0;m<g_AWA[i].SA.GetCount();m++ )
- {
- str = g_AWA[i].SA.GetAt( m );
- if( g_pDevicesManager->AWA_VarIsAlarm( str ) )//变量是报警状态
- {
- nSetAWA = 1;
- break;
- }
- }
- }
- else
- {
- nSetAWA = -1;
- }
- }
- }
- if( nSetAWA==1 )//触发声光报警
- {
- bool bAlarm = false;
- if( g_pDevicesManager->AWA_DoDataISData( g_AWA[i].sDoStatus,g_AWA[i].nResumeData ) )//不是声光报警状态
- {
- LOG4C((LOG_NOTICE, "触发声光报警( %s=%d )",g_AWA[i].sDoSet,g_AWA[i].nAlarmData ));
- bRet = true;
- bAlarm = true;
- ProcessResWriteSingleVarData( g_AWA[i].sDoSet,g_AWA[i].nAlarmData );
- }
- if( !bAlarm && (g_AWA[i].nStatus==0||g_AWA[i].nStatus==-1) )
- {
- LOG4C((LOG_NOTICE, "现在状态:正在声光报警( %s )",g_AWA[i].sDoSet ));
- g_AWA[i].nStatus = 1;
- }
- if( g_AWA[i].nStatus==-1 )
- g_AWA[i].nStatus = 1;
- }
- else if( nSetAWA==0 )//取消声光报警
- {
- bool bNormal = false;
- if( !g_pDevicesManager->AWA_DoDataISData( g_AWA[i].sDoStatus,g_AWA[i].nResumeData ) )//是声光报警状态
- {
- LOG4C((LOG_NOTICE, "取消声光报警( %s=%d )",g_AWA[i].sDoSet,g_AWA[i].nResumeData ));
- bRet = true;
- bNormal = true;
- ProcessResWriteSingleVarData( g_AWA[i].sDoSet,g_AWA[i].nResumeData );
- }
- if( !bNormal && (g_AWA[i].nStatus==1||g_AWA[i].nStatus==-1) )
- {
- //LOG4C((LOG_NOTICE, "现在状态:没有声光报警( %s )",g_AWA[i].sDoSet ));
- g_AWA[i].nStatus = 0;
- }
- if( g_AWA[i].nStatus==-1 )
- g_AWA[i].nStatus = 0;
- }
- }
- return bRet;
- }
- //结束 声光报警
- //DOG
- INT g_nUseTimeLimit = 0; //是否超过使用期限
- INT g_nSlaveVersion = 0; //版本子ID
- CString g_sPassDueInfo = "狗过期了"; //过期信息
- bool g_bSoftRegisterFileIsOfficial = false; //注册文件是正式版
- bool g_bGetBlanceReturn = false;
- //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}; // 日志存放目录
- INT g_nLogSaveTimes = 0; // 日志保存月数
- //环境参数配置
- 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; // 数据库记录时间
- CHAR g_strNoticePre[MAX_SERVER_LENGTH + 1] = ""; // 通知前辍
- INT g_nNoticeDelay = 0; // 通知延时
- INT g_nEncryptionType = 0; // 加密类型
- //Sms
- 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_nSendVoice = 0; // 是否启动语音通知功能
- INT g_nNoticeCardType = 1; // 板卡类型
- CHAR g_strNoticeTelPre[MAX_TEL_LENGTH + 1] = {0}; // 外线前缀
- INT g_nNoticeCallDelay = 0; // 两次呼叫间隔时间
- INT g_nNoticeCallTimes = 0; // 最大的呼叫次数
- vector<USERINFO> g_vtUserInfo;
- vector<USERROLEINFO> g_vtUserRoleInfo;
- //TTS参数配置
- INT g_nTTSType = 5; // TTS格式类型
- INT g_nTTSRate = 2; // TTS语速 (-10 - 10)
- INT g_nTTSVolume = 2; // TTS音量 (0 - 100)
- // 报警参数设置
- 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_nTimingPreiods = 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_strSnmpOidRoot[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;
- CString g_strHintBlance;
- CString g_strHintDateLimit;
- LIST_VAR_NOTICE g_listVarNotice;
- //服务
- TCHAR g_szServiceName[] = _T("DataBase Monitor Service");
- //软件加密
- HINSTANCE g_hSoftRegisterLibModule = NULL;
- Reg_DLLInit pRegdllInit = NULL;
- Reg_DLLJudgeIsRegister pRegdllJudgeIsRegister = NULL;
- Reg_DLLUnInit pRegdllUnInit = NULL;
- Reg_DLLGetHourToCount pRegdllGetHourToCount = NULL;
- Reg_DLLIsValidTime pRegdllIsValidTime = NULL;
- Reg_DLLAddUserDate pRegdllAddUserDate = NULL;
- // TTS
- HINSTANCE hTTSModule = NULL;
- MySTONEU_DLLRegisterTTS pStoneUDllRegisterTTS = NULL;
- MySTONEU_DLLUnRegisterTTS pStoneUDllUnRegisterTTS = NULL;
- MySTONEU_DLLTxtToWav pStoneUDLLTxtToWav = NULL;
- // 语音通知动态库输出函数
- HINSTANCE g_hVoiceLibModule = 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;
- SMS_DLLGetBalance pSmsGetBalance = 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;
- }
- bool CanDelLog( CString sLogPath,int iMonth )
- {
- bool bRet = false;
- int nYear=0,nMonth=0,nDay=0;
- nYear = atoi( sLogPath.Mid( sLogPath.GetLength()-12,4 ) );
- nMonth = atoi( sLogPath.Mid( sLogPath.GetLength()-8,2 ) );
- nDay = atoi( sLogPath.Mid( sLogPath.GetLength()-6,2 ) );
- CTime t1(CTime::GetCurrentTime());
- CTime t2( nYear, nMonth, nDay, 0, 0, 0 );
- CTimeSpan ts = t1 - t2;
- if( ts.GetTotalHours()/24/30 > iMonth )
- bRet = true;
- return bRet;
- }
- bool DeleteLog( 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( "summary" ) )
- {
- saFilePath.Add( sFileNameTemp );
- }
- }
- }
- _findclose(hfile);
- }
- for( int i=0;i<saFilePath.GetCount();i++ )//g_nLogSaveTimes summary20110929.log
- {
- CString s;
- s = saFilePath.GetAt( i );
- if( CanDelLog( s,g_nLogSaveTimes ) )
- DeleteFile( s );
- }
- return true;
- }
- void g_GetAllLogFile()
- {
- //DWORD returnValue;
- double dBegin=0.0,dEnd=0.0,dNow=0.0,dTemp=0.0;
-
- g_strAllVideoFile.RemoveAll();
- //LOG4C((LOG_NOTICE, "g_strSummaryLogPath = %s ", g_strSummaryLogPath ));
- //CString strPath, CString strFileName, int nLayer )
-
- CStringArray saFilePath;
- long hfile;
- struct _finddata_t fFile;
- CString strCurr;
- strCurr.Format( "%s\\Log\\*.*",g_strSummaryLogPath );
- 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;// = g_strSummaryLogPath + "\\" + str;
- sFileNameTemp.Format( "%s\\Log\\%s",g_strSummaryLogPath,str );
- //LOG4C((LOG_NOTICE, "%s ", sFileNameTemp ));
- if( -1 != str.Find( "summary" ) )
- {
- g_strAllVideoFile.Add( sFileNameTemp );
- CString str1,str2,s1,s2,sTemp;
- for( int i=0;i<g_strAllVideoFile.GetCount();i++ )//summary20110929.log
- {
- str1 = g_strAllVideoFile[i];
- s1 = str1.Mid( str1.GetLength()-12,8 );
- dBegin = atof(s1);
- for( int j=i+1;j<g_strAllVideoFile.GetCount();j++ )
- {
- str2 = g_strAllVideoFile[j];
- s2 = str2.Mid( str2.GetLength()-12,8 );
- dEnd = atof(s2);
-
- if( dEnd<dBegin )
- {
- dTemp = dBegin;
- dBegin = dEnd;
- dEnd = dTemp;
- sTemp = str1;
- str1 = str2;
- str2 = sTemp;
- g_strAllVideoFile[i] = str1;
- g_strAllVideoFile[j] = str2;
- }
- }
- }
- }
- }
- }
- _findclose(hfile);
- }
- }
- bool g_DiskVelumnIsEnough( int iDiskVolume,CString sPath )
- {
- bool bRet = false;
- double dVelume=0.0,dRemainVelume=0.0;
- dVelume = 1024*iDiskVolume;
- ULARGE_INTEGER lpuse;
- ULARGE_INTEGER lptotal;
- ULARGE_INTEGER lpfree;
- GetDiskFreeSpaceEx(sPath,&lpuse,&lptotal,&lpfree);
- CString s;
- s.Format("%4.4fGB\n",lpfree.QuadPart/1024.0/1024.0);
- dRemainVelume = lpfree.QuadPart/1024.0/1024.0;
- if( dRemainVelume>=dVelume )
- bRet = true;
-
- return bRet;
- }
- 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( !g_DiskVelumnIsEnough( 3,g_strSummaryLogPath ) )
- {
- CString str;
- for( int i=0;i<3;i++ )
- {
- if( g_strAllVideoFile.GetCount()>0 )
- {
- str = g_strAllVideoFile[0];
- if( PathFileExists(str) )
- DeleteFile( str );
- g_strAllVideoFile.RemoveAt( 0 );
- }
- }
- }
- //if(iLogLevel<=WRITEDEBUG)
- {
- time((time_t*)&i);
- tim=localtime((time_t*)&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);
- CTime ctNow = CTime::GetCurrentTime();
- int nHour;
- nHour = ctNow.GetHour();
- static bool bCanDelLog = true;
- if( nHour == 23 && bCanDelLog )
- {
- bCanDelLog = false;
- CString strDectory;
- strDectory.Format("%s\\Log", g_strSummaryLogPath );
- DeleteLog( strDectory,"*.*",0 );
- LOG4C((LOG_NOTICE, "删除Log文件" ));
- g_GetAllLogFile();
- }
- else if( nHour != 23 )
- {
- bCanDelLog = true;
- }
- }
- //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);
- }
- int ProcessResWriteSingleVarData( CString sVarName,int iData )
- {
- CString sUid;
- int nVarID = 0;
- iData = iData;
- int nDeviceIndex = -1, nVarIndex = -1;
- BOOL bFind = FindVar( sUid, nVarID,sVarName, nDeviceIndex, nVarIndex);
- //LOG4C((LOG_NOTICE, "sUid = %s, nVarID = %d, sVarName = %s,iData = %d ", sUid,nVarID,sVarName,iData));
- if( bFind == FALSE )
- {
- LOG4C((LOG_NOTICE, "FindVar return false" ));
- return -1;
- }
- g_nDealAWAStatus = 1;//处理声光报警状态 -1未初始化 0初始化 1在处理中 2处理完成 3新事件
- CDevice *pDev = g_pDevicesManager->m_Devices[nDeviceIndex];
- CBaseVar *pBaseVar = pDev->m_Vars[nVarIndex];
- SETBASEPARAM SetBasePara;
- memset( &SetBasePara, 0, sizeof(SETBASEPARAM) );
- //网络设备
- char chDllName[MAX_PATH] = {0};
- strcpy(chDllName, (char *)(LPCTSTR)pDev->m_strProtocoldllname);
- StrLower(chDllName,chDllName);
- char szIniName[MAX_PATH] = {0};
- strcpy(szIniName, (char *)(LPCTSTR)pDev->m_strIniName);
- StrLower(szIniName, szIniName);
- int nIndex = pDev->m_nThreadHandleIndex;
- if (pDev->m_bySpecialdevice == 0) // modbus rtu 设备
- {
- if( NULL != g_hRequestDataThread[nIndex] )
- SuspendThread(g_hRequestDataThread[nIndex]);
- int nSetCount = 0;
- // 写3次串口,如果不成功则放弃
- do
- {
- if( nSetCount > 5 ) break;
- if( RtuRequestWrData( (char *)(LPCTSTR)sUid, nVarID, iData) == 0)
- {
- break;
- }
- else
- {
- }
- nSetCount++;
- }while( WaitForSingleObject( g_hRunObject, 1250L ) == WAIT_TIMEOUT );
- if( NULL != g_hRequestDataThread[nIndex] )
- ResumeThread(g_hRequestDataThread[nIndex]);
- }
- else if( pDev->m_bySpecialdevice == 1 ) // modbus Ascii 设备
- {
- if( NULL != g_hRequestDataThread[nIndex] )
- SuspendThread(g_hRequestDataThread[nIndex]);
- int nSetCount = 0;
- // 写3次串口,如果不成功则放弃
- do
- {
- if( nSetCount > 5 ) break;
- if (AscRequestWrData((char*)(LPCTSTR)sUid, nVarID, iData) == 0)
- {
- AscSingleResponseWriteData((char*)(LPCTSTR)sUid,nVarID);
- if (pBaseVar->m_dbData != iData)//判断设置数据是否一致
- int a=0;
- break;
- }
- else
- {
- }
- nSetCount++;
- }while( WaitForSingleObject( g_hRunObject, 1250L ) == WAIT_TIMEOUT );
- if( NULL != g_hRequestDataThread[nIndex] )
- ResumeThread(g_hRequestDataThread[nIndex]);
- }
- else if( pDev->m_bySpecialdevice == 2 ) // modbus tcp 设备
- {
- int nSetCount = 0;
- // 写3次串口,如果不成功则放弃
- do
- {
- if( nSetCount > 5 ) break;
- //g_hRequestDataThread[g_nIcpdasIndex]
- #if 1
- ResetEvent( pDev->m_hSemNet );
- Sleep(5 * 1000); //等待5S,防止重置信号量之前,已经有变量在请求,保证变量已经读完
- #endif
- if( TcpRequestWriteData(pDev->m_iIpport,
- pDev->m_iDevideaddr,
- (char *)(LPCTSTR)pDev->m_strIp,
- pBaseVar->m_iRegisterNum,
- pBaseVar->m_nRegStartAddr,
- pBaseVar->m_iFuncID,
- (int)iData) == 0 )
- {
- SetEvent( pDev->m_hSemNet );
- break;
- }
- else
- {
- SetEvent( pDev->m_hSemNet );
- }
- nSetCount++;
- }while( WaitForSingleObject( g_hRunObject, 1250L ) == WAIT_TIMEOUT );
- }
- else if( pDev->m_bySpecialdevice == 3 ) // snmp 设备
- {
- CString strSetValue;
- strSetValue.Format("%.1f", iData);
- if( pSnmpDllSetValue(
- (char *)(LPCTSTR)pDev->m_strIp,
- (char *)(LPCTSTR)pBaseVar->m_strFields,
- (char *)(LPCTSTR)pBaseVar->m_strSnmpoi,
- "int",
- 1,
- 300,
- (char *)(LPCTSTR)strSetValue
- ) == 0 )
- {
- }
- else
- {
- }
- }
- else if( pDev->m_bySpecialdevice == 4 ) // RS232 设备
- {
- if (strcmp(chDllName, "icpdas.dll") ==0)
- {
- if( NULL != g_hRequestDataThread[nIndex] )
- int nRet = SuspendThread(g_hRequestDataThread[nIndex]);
- int nSetCount = 0;
- // 写3次串口,如果不成功则放弃
- do
- {
- if( nSetCount > 5 ) break;
- if (RequestWrIcpdasData((char*)(LPCTSTR)sUid, nVarID, iData) == 0)
- {
- break;
- }
- else
- {
- }
- nSetCount++;
- }while( WaitForSingleObject( g_hRunObject, 250L ) == WAIT_TIMEOUT );//1250L
- if( NULL != g_hRequestDataThread[nIndex] )
- int nRet = ResumeThread(g_hRequestDataThread[nIndex]);
- }
- else if (strcmp(chDllName, "stulz.dll") ==0)
- {
- if( NULL != g_hRequestDataThread[nIndex] )
- int nRet = SuspendThread(g_hRequestDataThread[nIndex]);
- int nSetCount = 0;
- // 写3次串口,如果不成功则放弃
- do
- {
- if( nSetCount > 5 ) break;
- if (RequestWrStulzData((char*)(LPCTSTR)sUid, nVarID, iData) == 0)
- {
- break;
- }
- else
- {
- }
- nSetCount++;
- }while( WaitForSingleObject( g_hRunObject, 250L ) == WAIT_TIMEOUT );//1250L
- if( NULL != g_hRequestDataThread[nIndex] )
- int nRet = ResumeThread(g_hRequestDataThread[nIndex]);
- }
-
- else if( strcmp(chDllName, "gree.dll") == 0 )
- {
- if( NULL != g_hRequestDataThread[nIndex] )
- int nRet = SuspendThread(g_hRequestDataThread[nIndex]);
- int nSetCount = 0;
- // 写10次串口,如果不成功则放弃
- do
- {
- if( nSetCount > 5 ) break;
- if (RequestGreeWrData( (char *)(LPCTSTR)sUid,
- nVarID, iData, (char *)(LPCTSTR)pBaseVar->m_strRs232cmd ) == 0 )
- {
- break;
- }
- else
- {
- }
- nSetCount++;
- }while( WaitForSingleObject( g_hRunObject, 250L ) == WAIT_TIMEOUT );//1250L
- if( NULL != g_hRequestDataThread[nIndex] )
- int nRet = ResumeThread(g_hRequestDataThread[nIndex]);
- }
- else if( strcmp(chDllName, "carel.dll") == 0 )
- {
- if( NULL != g_hRequestDataThread[nIndex] )
- int nRet = SuspendThread(g_hRequestDataThread[nIndex]);
- int nSetCount = 0;
- // 写3次串口,如果不成功则放弃
- do
- {
- if( nSetCount > 5 ) break;
- if (CarelControlRequest( (char *)(LPCTSTR)sUid,nVarID, iData, (char *)(LPCTSTR)pBaseVar->m_strRs232cmd ) == 0 )
- {
- break;
- }
- else
- {
- }
- nSetCount++;
- }while( WaitForSingleObject( g_hRunObject, 250L ) == WAIT_TIMEOUT );//1250L
- if( NULL != g_hRequestDataThread[nIndex] )
- int nRet = ResumeThread(g_hRequestDataThread[nIndex]);
- }
- else if( g_FunIniOK( szIniName ) )
- {
- if( NULL != g_hRequestDataThread[nIndex] )
- SuspendThread(g_hRequestDataThread[nIndex]);
- int nSetCount = 0;
- char szMsg[MAX_VAR_MSG] = {0};
- //memcpy(szMsg, &pWrSnVarData.VarData.Data, sizeof(double));
- itoa((int)iData, szMsg, 16);
- ByteToUpper(szMsg);
- // 写3次串口,如果不成功则放弃
- do
- {
- if( nSetCount > 5 ) break;
- if (MostDeviceRequestSet(pDev->m_iPort, pDev->m_iDevideaddr,
- (char*)(LPCTSTR)sUid, nVarID,
- (char*)(LPCTSTR)pBaseVar->m_strRs232cmd,
- szIniName, szMsg) == 0)
- //if (CarelControlRequest( (char *)sUid,
- // pWrSnVarData.ReqVarData.iVarid, pWrSnVarData.VarData.Data, (char *)(LPCTSTR)pBaseVar->m_strRs232cmd ) == 0 )
- {
- break;
- }
- else
- {
- }
- nSetCount++;
- }while( WaitForSingleObject( g_hRunObject, 250L ) == WAIT_TIMEOUT );//1250L
-
- if( NULL != g_hRequestDataThread[nIndex] )
- ResumeThread(g_hRequestDataThread[nIndex]);
- }
- else
- {
- LOG4C((LOG_NOTICE, "没有实现的设置 dll = %s ,ini = %s",chDllName,szIniName ));
- }
- }
- Sleep( 1000 );
- //g_nDealAWAStatus = 2;//处理声光报警状态 -1未初始化 0初始化 1在处理中 2处理完成 3新事件
-
- return 0;
- }
|