From 034d5c504080cb6b48dda061911d43963f66394a Mon Sep 17 00:00:00 2001 From: Matthew Date: Wed, 15 Nov 2023 12:38:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dlinux=E4=B8=8B=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- basefunc.cpp | 82 +++++++++++++++++++------------------ basetype.h | 11 ++++- buban103.cpp | 15 +++++++ buban104.cpp | 45 +++++++++++++++++---- chainlist.cpp | 6 +++ common.h | 30 ++++++++++++-- commport.cpp | 109 ++++++++++++++++++++++++++++++++++++++++++++------ confrw.h | 6 +-- display.cpp | 3 ++ display.h | 3 ++ 10 files changed, 243 insertions(+), 67 deletions(-) diff --git a/basefunc.cpp b/basefunc.cpp index c73810c..16707b8 100644 --- a/basefunc.cpp +++ b/basefunc.cpp @@ -3,25 +3,32 @@ #include #include #include +#else +#include +#include +#include #endif /*#else -#include + #endif*/ #include +#include #include #include #include "basefunc.h" +#include extern char IniFilePath[256]; void DebugPrint(char *szDebug) { //#ifdef OS_WINDOWS +#ifdef _WIN32 OutputDebugString((WCHAR*)szDebug); OutputDebugString((WCHAR*)"\n"); -//#else -// printf("%s\n", szDebug); -//#endif +#else + printf("%s\n", szDebug); +#endif } int CmpString(const u_char *str1, const u_char *str2) @@ -29,8 +36,8 @@ int CmpString(const u_char *str1, const u_char *str2) size_t i, len; - len = strlen((char*)str1); - if(len != strlen((char*)str2)) + len = strlen((const char*)str1); + if(len != strlen((const char*)str2)) { return 0; } @@ -326,24 +333,22 @@ BOOL GetLocalTimeEx(DAY_TIME *ptrDateTime) struct tm *tmptr=NULL; time_t tm_t; -/*#if OS_LINUX +#ifdef _WIN32 + SYSTEMTIME sm; + GetLocalTime(&sm); + msec = sm.wMilliseconds; +#else struct timeval timeval; gettimeofday(&timeval, NULL); msec = timeval.tv_usec/1000; -#elif OS_WINDOWS*/ - SYSTEMTIME sm; - GetLocalTime(&sm); - msec = sm.wMilliseconds; -/*#else - msec = 0; -#endif*/ +#endif tm_t = time(NULL); // 格林威治时间 //tmptr = gmtime(&tm_t); // 本地时间 - localtime_s(tmptr, &tm_t); + tmptr = localtime(&tm_t); if(!tmptr) { @@ -371,7 +376,25 @@ BOOL GetLocalTimeEx(DAY_TIME *ptrDateTime) //BOOL SetLocalTimeEx(DAY_TIME *ptrDateTime) void SetLocalTimeEx(DAY_TIME *ptrDateTime) { -#/*if OS_LINUX +#ifdef _WIN32 + SYSTEMTIME systime; + BOOL bRetVal; + + systime.wYear = ptrDateTime->Year; + systime.wMonth = ptrDateTime->Month; + //systime.wDayOfWeek = ptrDateTime->wDayOfWeek; + systime.wDay = ptrDateTime->Day; + systime.wHour = ptrDateTime->Hour; + systime.wMinute = ptrDateTime->Min; + systime.wSecond = ptrDateTime->Sec; + systime.wMilliseconds = ptrDateTime->mSec; + + bRetVal = SetLocalTime(&systime); + + //if(!bRetVal) return FALSE; + //else return TRUE; + +#else //int ret; //pid_t pid; //char szCmdLine[256]; @@ -420,26 +443,7 @@ void SetLocalTimeEx(DAY_TIME *ptrDateTime) //printf("TIP_(%04d): set time is ok.\n", getpid()); } -#else */ //windows - - SYSTEMTIME systime; - BOOL bRetVal; - - systime.wYear = ptrDateTime->Year; - systime.wMonth = ptrDateTime->Month; - //systime.wDayOfWeek = ptrDateTime->wDayOfWeek; - systime.wDay = ptrDateTime->Day; - systime.wHour = ptrDateTime->Hour; - systime.wMinute = ptrDateTime->Min; - systime.wSecond = ptrDateTime->Sec; - systime.wMilliseconds = ptrDateTime->mSec; - - bRetVal = SetLocalTime(&systime); - - //if(!bRetVal) return FALSE; - //else return TRUE; - -//#endif +#endif } _int64 SystemTimeToMillseconds(DAY_TIME *lpTime, int i8HourOffset) @@ -475,7 +479,7 @@ void LogRunRecord(char *pstrLogMsg, char *pstrfilename) DAY_TIME sCurtime; char szFileName[256]; -//#if OS_WINDOWS +#ifdef _WIN32 FILE *fp; GetLocalTimeEx(&sCurtime); @@ -504,7 +508,7 @@ void LogRunRecord(char *pstrLogMsg, char *pstrfilename) fwrite(pstrLogMsg, sizeof(char), strlen(pstrLogMsg)+1, fp); fclose(fp); } -/*#else +#else int fp; GetLocalTimeEx(&sCurtime); @@ -538,7 +542,7 @@ void LogRunRecord(char *pstrLogMsg, char *pstrfilename) write(fp, pstrLogMsg, ilen); close(fp); } -#endif*/ +#endif } BOOL CheckTcpIpAddr(char *addr) diff --git a/basetype.h b/basetype.h index 2f048f8..1d1141e 100644 --- a/basetype.h +++ b/basetype.h @@ -35,6 +35,12 @@ typedef struct tagCMDDEF u_32 CmdTimerConst; //命令时间间隔 } CMDDEF, *pCMDDEF; +#ifndef _WIN32 +typedef long long _int64; +typedef unsigned long long _uint64; +typedef int SOCKET; +#endif + /*#ifndef OS_WINDOWS typedef int bool; typedef int64_t _int64; @@ -59,12 +65,15 @@ typedef struct #define DSLIB_API #else*/ +#ifdef _WIN32 #ifdef DSLIB_EXPORTS #define DSLIB_API __declspec(dllexport) #else #define DSLIB_API __declspec(dllimport) #endif// DSLIB_EXPORTS - +#else +#define DSLIB_API +#endif #pragma pack (push,1) typedef struct { diff --git a/buban103.cpp b/buban103.cpp index eaa9bfa..356b51d 100644 --- a/buban103.cpp +++ b/buban103.cpp @@ -7,12 +7,18 @@ #include "baohulib/commport.h" #include "baohulib/serialport.h" #else*/ +#include "common.h" #include "commport.h" #include "udpcomm.h" #include "display.h" //#endif #include #include +#include +#ifndef _WIN32 +#include +#include +#endif #include "buban103.h" #include "scadaprotect.h" @@ -111,8 +117,13 @@ void Buban103ReadConfig(int commid) if(!SioParam[commid].ExtInfo) { +#ifdef _WIN32 sprintf(szbuf, "WARN(%04d): commid_%02d ExtInfo=malloc(%d) failed.\n", _getpid(), commid, sizeof(BUBAN103PORTPARAM)); +#else + sprintf(szbuf, "WARN(%04d): commid_%02d ExtInfo=malloc(%d) failed.\n", + getpid(), commid, sizeof(BUBAN103PORTPARAM)); +#endif DebugPrint(szbuf); return; } @@ -509,7 +520,11 @@ void Buban103YkYtProcess(int commid, u_char *buf, int len) // 遥 YkYtParam.m_iYkYtUpDown = YKYT_SEND_UP; YkYtParam.m_iYkYtOperate = buf[9]; SendYkYtCommand2(commid, &YkYtParam); +#ifdef _WIN32 sprintf(szbuf, "WARN(%04d): 转发遥控预令反校成功.\n", _getpid()); +#else + sprintf(szbuf, "WARN(%04d): 转发遥控预令反校成功.\n", getpid()); +#endif DebugPrint(szbuf); return; } diff --git a/buban104.cpp b/buban104.cpp index cf067b7..7561e35 100644 --- a/buban104.cpp +++ b/buban104.cpp @@ -3,9 +3,13 @@ //* aaawen 2005.09.14 * //*************************************************************** //_DEBUG_MSG_,_OS_WINDOWS_DEBUG_ -#ifdef OS_LINUX -#include "baohulib/commport.h" -#include "baohulib/serialport.h" +#ifndef _WIN32 +#include +#include + +#include "commport.h" +// #include "baohulib/serialport.h" + #else #include "commport.h" #include "udpcomm.h" @@ -13,6 +17,7 @@ #endif #include #include +#include #include "buban101.h" #include "buban104.h" #include "scadaprotect.h" @@ -221,7 +226,7 @@ void Buban104RecvData(int commid, u_char *buf, int len)// Buban104ProcessData(commid, pPortParam, TRUE); pPortParam->m_psBaoHu->m_iRevStatus = 0; pPortParam->m_psBaoHu->RevCmdFlag = 1; -#ifndef OS_LINUX +#ifdef _WIN32 if((GetCurPort() == commid) && IsRealDataDisp()) { WatchDataPutDispBuf(commid, SDS_SIO_RECV_DATA, @@ -234,7 +239,7 @@ void Buban104RecvData(int commid, u_char *buf, int len)// default: if(buf[i] == 0x68) { -#ifndef OS_LINUX +#ifdef _WIN32 // wen 2004.11.22 增加显示 if((GetCurPort() == commid) && IsRealDataDisp()) { @@ -253,7 +258,7 @@ void Buban104RecvData(int commid, u_char *buf, int len)// pPortParam->m_au8RecvBuf[pPortParam->m_iRecvLen++] = buf[i]; if(pPortParam->m_iRecvLen > 200) { -#ifndef OS_LINUX +#ifdef _WIN32 // wen 2004.11.22 增加显示 if((GetCurPort() == commid) && IsRealDataDisp()) { @@ -1049,8 +1054,13 @@ void MakeBuBan104YkYtCommand( u_32 commid, u_char *buf, int len ) if(ShmGetDispYkYtFlag()) { +#ifdef _WIN32 printf("TIP_(%04d): commid =%d ykytpnt=%d, op=%d checked.\n", _getpid(), commid, ykpoint, (buf[9] & 0x7F)); +#else + printf("TIP_(%04d): commid =%d ykytpnt=%d, op=%d checked.\n", + getpid(), commid, ykpoint, (buf[9] & 0x7F)); +#endif } } @@ -1394,7 +1404,7 @@ void Buban104SendCmdFormPollCmdBuf(int commid) return; } -#ifndef OS_LINUX +#ifdef _WIN32 if(isUdpSocketExist() == TRUE) #endif { @@ -1430,7 +1440,7 @@ void Buban104SendCmdFormPollCmdBuf(int commid) pPortParam->m_psBaoHu->RetryTimeCnt = 0; } -#ifdef OS_LINUX +#ifndef _WIN32 if(pPortParam->m_psBaoHu->LastGetCmdBuf == FAST_CMD_TYPE) #else if((pPortParam->m_psBaoHu->LastGetCmdBuf == FAST_CMD_TYPE) @@ -2738,8 +2748,13 @@ void Buban104AiWithDataProcessWithM_ME_TD_1(RTUMSG * rtumsg) { if( ( i + istep ) > (2 + len)) { +#ifdef _WIN32 sprintf(szbuf, ">>>>>WARN(%04d): Commid_%02d (iLen=%d) is not enough in Buban104AiWithDataProcessWithM_ME_TD_1", _getpid(), commid, len); +#else + sprintf(szbuf, ">>>>>WARN(%04d): Commid_%02d (iLen=%d) is not enough in Buban104AiWithDataProcessWithM_ME_TD_1", + getpid(), commid, len); +#endif DebugPrint(szbuf); break; } @@ -2799,8 +2814,13 @@ void Buban104AiWithDataProcessWithM_ME_TF_1(RTUMSG * rtumsg) { if( ( i + istep ) > (2 + len)) { +#ifdef _WIN32 sprintf(szbuf, ">>>>>WARN(%04d): Commid_%02d (iLen=%d) is not enough in Buban104AiWithDataProcessWithM_ME_TF_1", _getpid(), commid, len); +#else + sprintf(szbuf, ">>>>>WARN(%04d): Commid_%02d (iLen=%d) is not enough in Buban104AiWithDataProcessWithM_ME_TF_1", + getpid(), commid, len); +#endif DebugPrint(szbuf); break; } @@ -2860,8 +2880,13 @@ void Buban104PiWithTimeDataProcessWithM_IT_TB_1(RTUMSG *rtumsg) { if( ( i + istep ) > (2 + len)) { +#ifdef _WIN32 sprintf(szbuf, ">>>>>WARN(%04d): Commid_%02d (iLen=%d) is not enough in Buban104PiWithTimeDataProcessWithM_IT_TB_1", _getpid(), commid, len); +#else + sprintf(szbuf, ">>>>>WARN(%04d): Commid_%02d (iLen=%d) is not enough in Buban104PiWithTimeDataProcessWithM_IT_TB_1", + getpid(), commid, len); +#endif DebugPrint(szbuf); break; } @@ -4045,7 +4070,11 @@ void ProvBuban104YkYtData(int commid, RTUMSG *rtumsg) if(ShmGetDispYkYtFlag()) { +#ifdef _WIN32 printf("TIP_(%04d): commid =%d recv ykyt select.\n", _getpid(), commid); +#else + printf("TIP_(%04d): commid =%d recv ykyt select.\n", getpid(), commid); +#endif } ykytpnt -= pPortParam->iYkBaseAddr; diff --git a/chainlist.cpp b/chainlist.cpp index 1e4325b..4dcc07d 100644 --- a/chainlist.cpp +++ b/chainlist.cpp @@ -4,11 +4,17 @@ //*************************************************************** //#ifdef OS_WINDOWS #include +#ifdef _WIN32 #include +#else +#include +#include +#endif //#endif #include #include #include "chainlist.h" +#include "common.h" #include "basefunc.h" #include "os_heap.h" diff --git a/common.h b/common.h index 679bf5c..c6cf72c 100644 --- a/common.h +++ b/common.h @@ -10,15 +10,27 @@ #ifndef __COMMON_H_ICL__ #define __COMMON_H_ICL__ +#ifdef _WIN32 + +#ifdef _DEBUG +// #define _OS_WINDOWS_DEBUG_ +#else // _DEBUG +#define _OS_WINDOWS_ +#endif // _DEBUG #include #include #include +#include +#include +#include +#else +#include +#include +#endif + #include #include -#include #include -#include -#include //#include "menu.h" @@ -77,7 +89,19 @@ typedef u_char BYTE; typedef u_short WORD; typedef u_long DWORD; +#ifndef _WIN32 +typedef unsigned long long ULONG_PTR, *PULONG_PTR; +typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR; +#define LOWORD(l) ((WORD)(((DWORD_PTR)(l)) & 0xffff)) +#define HIWORD(l) ((WORD)((((DWORD_PTR)(l)) >> 16) & 0xffff)) +#define LOBYTE(w) ((BYTE)(((DWORD_PTR)(w)) & 0xff)) +#define HIBYTE(w) ((BYTE)((((DWORD_PTR)(w)) >> 8) & 0xff)) + +#define _getpid getpid +#define _stricmp strcasecmp +#define Sleep(x) usleep(1000*x) +#endif #define BYTE3(a) (((a)&0xff)<<24) #define BYTE2(a) (((a)&0xff)<<16) #define BYTE1(a) (((a)&0xff)<<8) diff --git a/commport.cpp b/commport.cpp index c58aa6d..887c517 100644 --- a/commport.cpp +++ b/commport.cpp @@ -14,7 +14,16 @@ #include "udpping.h" #include "tcphost.h" #include "netport.h" +#ifdef _WIN32 #include +#else +#include +#include +#include +#include +#include +#include +#endif //#include "..\confrwlib\confrw.h" #define MAX_STRING_LEN 512 @@ -658,7 +667,7 @@ void ReadPortConfigInfo(u_short netport) sprintf(szbuf, "%02d_%02d:%02d:%02d.%03d 初始化端口%d... ...\n", sm.wDay, sm.wHour, sm.wMinute, sm.wSecond, sm.wMilliseconds, i+1); OutputDebugString((LPCWSTR)szbuf); -#elif _OS_WINDOWS_DEBUG_ +#elif _DEBUG printf("初始化端口%d... ...\n", i+1); #endif @@ -2375,8 +2384,6 @@ void BaohuLibMain(int netportnum) int msec, tmp1, tmp2; static int systimecnt = 0; - SYSTEMTIME stm; - if (InitBaohuLibMainFlag == 0) { systimecnt = 0; @@ -2392,15 +2399,15 @@ void BaohuLibMain(int netportnum) //msec = (msec + TIMER_CNT) % 1000; - GetLocalTime(&stm); + struct tm* ptm = localtime(NULL); - DayTime.Year = stm.wYear; - DayTime.Month = (stm.wMonth & 0xff); - DayTime.Day = (stm.wDay & 0xff); - DayTime.Hour = stm.wHour & 0xff; - DayTime.Min = stm.wMinute & 0xff; - DayTime.Sec = stm.wSecond & 0xff; - DayTime.mSec = stm.wMilliseconds; + DayTime.Year = ptm->tm_year + 1900; + DayTime.Month = ptm->tm_mon + 1; + DayTime.Day = ptm->tm_mday; + DayTime.Hour = ptm->tm_hour; + DayTime.Min = ptm->tm_min; + DayTime.Sec = ptm->tm_sec; + DayTime.mSec = 0; Sleep(100); // 网络端口写 //SetUdpRecv(); @@ -2419,9 +2426,9 @@ void BaohuLibMain(int netportnum) //CreatUdpSetSock(); OpenAllPort(); - if (stm.wSecond == 0) + if (ptm->tm_sec == 0) { - tmp2 = stm.wMinute * 60; + tmp2 = ptm->tm_min * 60; tmp1 = tmp2 - systimecnt; if (tmp1 < 0) tmp1 += 3600; @@ -2913,25 +2920,31 @@ void PortMemoryMalloc(int commid, int type, SIO_PARAM_BAOHU_DEF *pBaohuParam) //SioParam[commid].PortType = PROTOCOL_MASTER; if (pBaohuParam->AiPtr) { +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free(aiptr=0x%08x).\n", _getpid(), commid + 1, pBaohuParam->AiPtr); OutputDebugString((LPCWSTR)szDebugInfo); +#endif free(pBaohuParam->AiPtr); } if (pBaohuParam->DiPtr) { +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free(diptr=0x%08x).\n", _getpid(), commid + 1, pBaohuParam->DiPtr); OutputDebugString((LPCWSTR)szDebugInfo); +#endif free(pBaohuParam->DiPtr); } if (pBaohuParam->PiPtr) { +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free(piptr=0x%08x).\n", _getpid(), commid + 1, pBaohuParam->PiPtr); OutputDebugString((LPCWSTR)szDebugInfo); +#endif free(pBaohuParam->PiPtr); } @@ -2947,9 +2960,11 @@ void PortMemoryMalloc(int commid, int type, SIO_PARAM_BAOHU_DEF *pBaohuParam) } else { +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "ERR_(%04d): commid_%02d aiptr=malloc(%d) is failed.\n", _getpid(), commid + 1, sizeof(AI_DEF)*pBaohuParam->AiNum); OutputDebugString((LPCWSTR)szDebugInfo); +#endif pBaohuParam->AiNum = 0; } } @@ -2971,9 +2986,11 @@ void PortMemoryMalloc(int commid, int type, SIO_PARAM_BAOHU_DEF *pBaohuParam) } else { +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "ERR_(%04d): commid_%02d diptr=malloc(%d) is failed.\n", _getpid(), commid + 1, sizeof(DI_DEF)*pBaohuParam->DiNum); OutputDebugString((LPCWSTR)szDebugInfo); +#endif pBaohuParam->DiNum = 0; } @@ -2996,9 +3013,11 @@ void PortMemoryMalloc(int commid, int type, SIO_PARAM_BAOHU_DEF *pBaohuParam) } else { +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "ERR_(%04d): commid_%02d piptr=malloc(%d) is failed.\n", _getpid(), commid, sizeof(PI_DEF)*pBaohuParam->PiNum); OutputDebugString((LPCWSTR)szDebugInfo + 1); +#endif pBaohuParam->PiNum = 0; } } @@ -3099,9 +3118,11 @@ void PortMemoryMalloc(int commid, int type, SIO_PARAM_BAOHU_DEF *pBaohuParam) case PROTOCOL_SLAVE: if ((ProvPortCnt+1) > MAX_PROV_PORT_NUM) { +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "WARN(%04d): commid_%02d is error, the Prov Port is over !!!\n", _getpid(), commid + 1); OutputDebugString((LPCWSTR)szDebugInfo); +#endif break; } ProvPortCnt++; @@ -3109,33 +3130,41 @@ void PortMemoryMalloc(int commid, int type, SIO_PARAM_BAOHU_DEF *pBaohuParam) if (pBaohuParam->AiPtr) { +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free(aiptr=0x%08x).\n", _getpid(), commid + 1, pBaohuParam->AiPtr); OutputDebugString((LPCWSTR)szDebugInfo); +#endif free(pBaohuParam->AiPtr); } if (pBaohuParam->DiPtr) { +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free(diptr=0x%08x).\n", _getpid(), commid + 1, pBaohuParam->DiPtr); OutputDebugString((LPCWSTR)szDebugInfo); +#endif free(pBaohuParam->DiPtr); } if (pBaohuParam->PiPtr) { +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free(piptr=0x%08x).\n", _getpid(), commid + 1, pBaohuParam->PiPtr); OutputDebugString((LPCWSTR)szDebugInfo); +#endif free(pBaohuParam->PiPtr); } if(pBaohuParam->ProvSoeBuf.ptrProvSoe) { +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free(soeptr=0x%08x).\n", _getpid(), commid + 1, pBaohuParam->ProvSoeBuf.ptrProvSoe); OutputDebugString((LPCWSTR)szDebugInfo); +#endif free(pBaohuParam->ProvSoeBuf.ptrProvSoe); } @@ -3151,9 +3180,11 @@ void PortMemoryMalloc(int commid, int type, SIO_PARAM_BAOHU_DEF *pBaohuParam) } else { +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "ERR_(%04d): commid_%02d aiptr=malloc(%d) is failed.\n", _getpid(), commid + 1, sizeof(PROV_AI_PNT)*pBaohuParam->AiNum); OutputDebugString((LPCWSTR)szDebugInfo); +#endif pBaohuParam->AiNum = 0; } } @@ -3174,9 +3205,11 @@ void PortMemoryMalloc(int commid, int type, SIO_PARAM_BAOHU_DEF *pBaohuParam) } else { +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "ERR_(%04d): commid_%02d diptr=malloc(%d) is failed.\n", _getpid(), commid + 1, sizeof(PROV_DI_PNT)*pBaohuParam->DiNum); OutputDebugString((LPCWSTR)szDebugInfo); +#endif pBaohuParam->DiNum = 0; } @@ -3189,9 +3222,11 @@ void PortMemoryMalloc(int commid, int type, SIO_PARAM_BAOHU_DEF *pBaohuParam) } else { +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "ERR_(%04d): commid_%02d soeptr=malloc(%d) is failed.\n", _getpid(), commid + 1, sizeof(SOE_DEF)*MAX_PROV_SOE); OutputDebugString((LPCWSTR)szDebugInfo); +#endif } } else @@ -3212,9 +3247,11 @@ void PortMemoryMalloc(int commid, int type, SIO_PARAM_BAOHU_DEF *pBaohuParam) } else { +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "ERR_(%04d): commid_%02d piptr=malloc(%d) is failed.\n", _getpid(), commid + 1, sizeof(PROV_PI_PNT)*pBaohuParam->PiNum); OutputDebugString((LPCWSTR)szDebugInfo); +#endif pBaohuParam->PiNum = 0; } } @@ -3437,25 +3474,31 @@ void PortMemoryMallocEx(int commid, int type, SIO_PARAM_BAOHU_DEF *pBaohuParam) //SioParam[commid].PortType = PROTOCOL_MASTER; if (pBaohuParam->AiPtr) { +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free(aiptr=0x%08x).\n", _getpid(), commid + 1, pBaohuParam->AiPtr); OutputDebugString((LPCWSTR)szDebugInfo); +#endif free(pBaohuParam->AiPtr); } if (pBaohuParam->DiPtr) { +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free(diptr=0x%08x).\n", _getpid(), commid + 1, pBaohuParam->DiPtr); OutputDebugString((LPCWSTR)szDebugInfo); +#endif free(pBaohuParam->DiPtr); } if (pBaohuParam->PiPtr) { +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free(piptr=0x%08x).\n", _getpid(), commid + 1, pBaohuParam->PiPtr); OutputDebugString((LPCWSTR)szDebugInfo); +#endif free(pBaohuParam->PiPtr); } @@ -3471,9 +3514,11 @@ void PortMemoryMallocEx(int commid, int type, SIO_PARAM_BAOHU_DEF *pBaohuParam) } else { +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "ERR_(%04d): commid_%02d aiptr=malloc(%d) is failed.\n", _getpid(), commid + 1, sizeof(AI_DEF)*pBaohuParam->AiNum); OutputDebugString((LPCWSTR)szDebugInfo); +#endif pBaohuParam->AiNum = 0; } } @@ -3495,9 +3540,11 @@ void PortMemoryMallocEx(int commid, int type, SIO_PARAM_BAOHU_DEF *pBaohuParam) } else { +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "ERR_(%04d): commid_%02d diptr=malloc(%d) is failed.\n", _getpid(), commid + 1, sizeof(DI_DEF)*pBaohuParam->DiNum); OutputDebugString((LPCWSTR)szDebugInfo); +#endif pBaohuParam->DiNum = 0; } @@ -3520,9 +3567,11 @@ void PortMemoryMallocEx(int commid, int type, SIO_PARAM_BAOHU_DEF *pBaohuParam) } else { +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "ERR_(%04d): commid_%02d piptr=malloc(%d) is failed.\n", _getpid(), commid + 1, sizeof(PI_DEF)*pBaohuParam->PiNum); OutputDebugString((LPCWSTR)szDebugInfo); +#endif pBaohuParam->PiNum = 0; } } @@ -3536,42 +3585,52 @@ void PortMemoryMallocEx(int commid, int type, SIO_PARAM_BAOHU_DEF *pBaohuParam) case PROTOCOL_SLAVE: if ((ProvPortCnt+1) > MAX_PROV_PORT_NUM) { +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "WARN(%04d): commid_%02d is error, the Prov Port is over !!!\n", _getpid(), commid + 1); OutputDebugString((LPCWSTR)szDebugInfo); +#endif break; } ProvPortCnt++; if (pBaohuParam->AiPtr) { +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free(aiptr=0x%08x).\n", _getpid(), commid + 1, pBaohuParam->AiPtr); OutputDebugString((LPCWSTR)szDebugInfo); +#endif free(pBaohuParam->AiPtr); } if (pBaohuParam->DiPtr) { +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free(diptr=0x%08x).\n", _getpid(), commid + 1, pBaohuParam->DiPtr); OutputDebugString((LPCWSTR)szDebugInfo); +#endif free(pBaohuParam->DiPtr); } if (pBaohuParam->PiPtr) { +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free(piptr=0x%08x).\n", _getpid(), commid + 1, pBaohuParam->PiPtr); OutputDebugString((LPCWSTR)szDebugInfo); +#endif free(pBaohuParam->PiPtr); } if(pBaohuParam->ProvSoeBuf.ptrProvSoe) { +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free(soeptr=0x%08x).\n", _getpid(), commid + 1, pBaohuParam->ProvSoeBuf.ptrProvSoe); OutputDebugString((LPCWSTR)szDebugInfo); +#endif free(pBaohuParam->ProvSoeBuf.ptrProvSoe); } @@ -3587,9 +3646,11 @@ void PortMemoryMallocEx(int commid, int type, SIO_PARAM_BAOHU_DEF *pBaohuParam) } else { +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "ERR_(%04d): commid_%02d aiptr=malloc(%d) is failed.\n", _getpid(), commid + 1, sizeof(PROV_AI_PNT)*pBaohuParam->AiNum); OutputDebugString((LPCWSTR)szDebugInfo); +#endif pBaohuParam->AiNum = 0; } } @@ -3610,9 +3671,11 @@ void PortMemoryMallocEx(int commid, int type, SIO_PARAM_BAOHU_DEF *pBaohuParam) } else { +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "ERR_(%04d): commid_%02d diptr=malloc(%d) is failed.\n", _getpid(), commid + 1, sizeof(PROV_DI_PNT)*pBaohuParam->DiNum); OutputDebugString((LPCWSTR)szDebugInfo); +#endif pBaohuParam->DiNum = 0; } @@ -3625,9 +3688,11 @@ void PortMemoryMallocEx(int commid, int type, SIO_PARAM_BAOHU_DEF *pBaohuParam) } else { +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "ERR_(%04d): commid_%02d soeptr=malloc(%d) is failed.\n", _getpid(), commid + 1, sizeof(SOE_DEF)*MAX_PROV_SOE); OutputDebugString((LPCWSTR)szDebugInfo); +#endif } } else @@ -3648,9 +3713,11 @@ void PortMemoryMallocEx(int commid, int type, SIO_PARAM_BAOHU_DEF *pBaohuParam) } else { +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "ERR_(%04d): commid_%02d piptr=malloc(%d) is failed.\n", _getpid(), commid + 1, sizeof(PROV_PI_PNT)*pBaohuParam->PiNum); OutputDebugString((LPCWSTR)szDebugInfo); +#endif pBaohuParam->PiNum = 0; } } @@ -4009,41 +4076,53 @@ void PortMemoryFree(int commid, SIO_PARAM_DEF *pGenParam) if (pGenParam->m_psBaoHu->AiPtr) { free(pGenParam->m_psBaoHu->AiPtr); +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free ai memory.\n", _getpid(), commid + 1); OutputDebugString((LPCWSTR)szDebugInfo); +#endif } if (pGenParam->m_psBaoHu->DiPtr) { free(pGenParam->m_psBaoHu->DiPtr); +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free di memory.\n", _getpid(), commid + 1); OutputDebugString((LPCWSTR)szDebugInfo); +#endif } if (pGenParam->m_psBaoHu->PiPtr) { free(pGenParam->m_psBaoHu->PiPtr); +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free pi memory.\n", _getpid(), commid + 1); OutputDebugString((LPCWSTR)szDebugInfo); +#endif } if(pGenParam->m_psBaoHu->ProvSoeBuf.ptrProvSoe) { free(pGenParam->m_psBaoHu->ProvSoeBuf.ptrProvSoe); +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free ProvSoe memory.\n", _getpid(), commid + 1); OutputDebugString((LPCWSTR)szDebugInfo); +#endif } free(pGenParam->m_psBaoHu); +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free psBaohu memory.\n", _getpid(), commid + 1); OutputDebugString((LPCWSTR)szDebugInfo); +#endif } if (pGenParam->m_psSerial) { free(pGenParam->m_psSerial); +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free psSerial memory.\n", _getpid(), commid + 1); OutputDebugString((LPCWSTR)szDebugInfo); +#endif } if (pGenParam->ExtInfo) @@ -4052,14 +4131,18 @@ void PortMemoryFree(int commid, SIO_PARAM_DEF *pGenParam) if (FunCallPtr[SioParam[commid].ProtocolIdx].ProtocolExit) { FunCallPtr[SioParam[commid].ProtocolIdx].ProtocolExit(commid); +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "TIP_(%04d): commid_%02d Protocol Exit.\n", _getpid(), commid + 1); OutputDebugString((LPCWSTR)szDebugInfo); +#endif } HEAP_FREE(pGenParam->ExtInfo); //free(pGenParam->ExtInfo); +#ifdef _OS_WINDOWS_DEBUG_ sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free ExtInfo memory.\n", _getpid(), commid + 1); OutputDebugString((LPCWSTR)szDebugInfo); +#endif } PortWriteDataFree(commid); diff --git a/confrw.h b/confrw.h index 24d4e00..0318d0a 100644 --- a/confrw.h +++ b/confrw.h @@ -21,15 +21,15 @@ //#include #include "confrw_errno.h" -#ifdef OS_LINUX -#define DSLIB_API +#ifndef _WIN32 +#define CONFRWLIB_API #else #ifdef CONFRWLIB_EXPORTS #define CONFRWLIB_API __declspec(dllexport) #else #define CONFRWLIB_API __declspec(dllimport) #endif// CONFRWLIB_EXPORTS -#endif//OS_LINUX +#endif// _WIN32 /*! * \if by_group diff --git a/display.cpp b/display.cpp index 86fe9c9..a87779d 100644 --- a/display.cpp +++ b/display.cpp @@ -19,6 +19,7 @@ int DispType = 0; int ListIndex = 0; // 显示序号索引起始 int ItemNumOfPage; // 页显示项目数 +#ifdef _WIN32 COLORREF dwColorVal[16] = // 显示颜色定义 { @@ -564,6 +565,8 @@ void CaculateWH( HDC hdc, UINT *xWidth, UINT *yHeight, char *szStr ) *yHeight = rc.bottom - rc.top; } +#endif + //**************************************************************** //* 显示数据上页? * //**************************************************************** diff --git a/display.h b/display.h index 2c33bfb..7a37ec7 100644 --- a/display.h +++ b/display.h @@ -27,6 +27,7 @@ #define WATCH_DATA_DISP 8 +#ifdef _WIN32 void RealAiDataDisp( HDC hdc ); void RealDiDataDisp( HDC hdc ); void RealPiDataDisp( HDC hdc ); @@ -40,6 +41,8 @@ HFONT NewFont( int nFSize ); void CaculateWH( HDC hdc, UINT *xWidth, UINT *yHeight, char *szStr ); +#endif + void PageUp( void ); void PageDown( void ); void PageHome( void );