修改文件编码为utf-8

main
BlueMatthew 2 years ago
parent 76bf9006ab
commit 289e80888b

@ -7,12 +7,13 @@ set(CMAKE_CXX_STANDARD_REQUIRED On)
set(CMAKE_CXX_EXTENSIONS Off) set(CMAKE_CXX_EXTENSIONS Off)
set(CMAKE_CXX_FLAGS_DEBUG "-g") set(CMAKE_CXX_FLAGS_DEBUG "-g")
# SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) # SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
# list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
project ("iec103") project ("iec103")
set_property( GLOBAL PROPERTY CXX_STANDARD 11) set_property( GLOBAL PROPERTY CXX_STANDARD 11)
add_definitions(-DOS_UNIX) add_definitions(-DOS_UNIX)
add_definitions(-DUSING_MYSQL)
# Add source to this project's executable. # Add source to this project's executable.
add_executable (iec103 basefunc.cpp add_executable (iec103 basefunc.cpp
@ -32,6 +33,7 @@ add_executable (iec103 basefunc.cpp
os_heap.cpp os_heap.cpp
Profile_Hash.cpp Profile_Hash.cpp
scadaprotect.cpp scadaprotect.cpp
MySQLAdo.cpp
# tcphost.cpp # tcphost.cpp
# udpcomm.cpp # udpcomm.cpp
# udpping.cpp # udpping.cpp
@ -41,10 +43,18 @@ add_executable (iec103 basefunc.cpp
# find_package(Threads REQUIRED) # find_package(Threads REQUIRED)
#target_link_libraries(iec103 PUBLIC Threads::Threads) #target_link_libraries(iec103 PUBLIC Threads::Threads)
set_target_properties(iec103 PROPERTIES set_target_properties(iec103 PROPERTIES
COMPILE_FLAGS "-pthread" COMPILE_FLAGS "-pthread"
LINK_FLAGS "-pthread") LINK_FLAGS "-pthread")
link_directories(/usr/lib64/mysql/)
# find_package(MySQL MODULE REQUIRED)
#if (SQLITE3_FOUND)
# include_directories(${SQLITE3_INCLUDE_DIRS})
target_link_libraries (iec103 /usr/lib64/mysql/libmysqlclient.so)
# # target_link_libraries (${OUT_TARGET} ${SQLite3_LIBRARIES})
#endif (SQLITE3_FOUND)
# find_package (SQLite3) # find_package (SQLite3)
#if (SQLITE3_FOUND) #if (SQLITE3_FOUND)
@ -61,4 +71,5 @@ if (ZLIB_FOUND)
endif (ZLIB_FOUND) endif (ZLIB_FOUND)
# TODO: Add tests and install targets if needed. # TODO: Add tests and install targets if needed.

@ -3,7 +3,7 @@
* Programmer : AAAwen * * Programmer : AAAwen *
* Writen at : 2005.05.10 * * Writen at : 2005.05.10 *
* Version : 1.0 * * Version : 1.0 *
* Description: flash * * Description: flash *
* Last modify: 2005.05.10 * * Last modify: 2005.05.10 *
*****************************************************************************/ *****************************************************************************/
#ifdef OS_WINDOWS #ifdef OS_WINDOWS
@ -286,7 +286,7 @@ HDSFILE DSOpenFile(const char *szFileName)
hFile = (HDSFILE)HEAP_MALLOC(sizeof(DSFILE)); hFile = (HDSFILE)HEAP_MALLOC(sizeof(DSFILE));
memset(hFile, 0, sizeof(DSFILE)); memset(hFile, 0, sizeof(DSFILE));
#ifdef OS_LINUX #ifdef OS_LINUX
// 首4个字节文文件系统的长度 // 首4个字节文文件系统的长度
pFSAddr = (BYTE *)(MCF5272_FRAMBAR + DS_FILESYSTEM_ADDR+4); pFSAddr = (BYTE *)(MCF5272_FRAMBAR + DS_FILESYSTEM_ADDR+4);
hFile->m_lContentLen = LoadFileInDSFS(szFileName, &hFile->m_pContent, pFSAddr); hFile->m_lContentLen = LoadFileInDSFS(szFileName, &hFile->m_pContent, pFSAddr);
#else #else
@ -361,7 +361,7 @@ HDSFILE DSOpenFileEx3(const char *szRootDir, const char *szFileName)
hFile = (HDSFILE)HEAP_MALLOC(sizeof(DSFILE)); hFile = (HDSFILE)HEAP_MALLOC(sizeof(DSFILE));
memset(hFile, 0, sizeof(DSFILE)); memset(hFile, 0, sizeof(DSFILE));
#ifdef OS_LINUX #ifdef OS_LINUX
// 首4个字节文文件系统的长度 // 首4个字节文文件系统的长度
pFSAddr = (BYTE *)(MCF5272_FRAMBAR + DS_FILESYSTEM_ADDR+4); pFSAddr = (BYTE *)(MCF5272_FRAMBAR + DS_FILESYSTEM_ADDR+4);
hFile->m_lContentLen = LoadFileInDSFS(szFileName, &hFile->m_pContent, pFSAddr); hFile->m_lContentLen = LoadFileInDSFS(szFileName, &hFile->m_pContent, pFSAddr);
#else #else
@ -402,7 +402,7 @@ HDSFILE DSOpenFileEx2(const char *szRootDir, const char *szFSName, const char *s
hFile = (HDSFILE)HEAP_MALLOC(sizeof(DSFILE)); hFile = (HDSFILE)HEAP_MALLOC(sizeof(DSFILE));
memset(hFile, 0, sizeof(DSFILE)); memset(hFile, 0, sizeof(DSFILE));
#ifdef OS_LINUX #ifdef OS_LINUX
// 首4个字节文文件系统的长度 // 首4个字节文文件系统的长度
pFSAddr = (BYTE *)(MCF5272_FRAMBAR + DS_FILESYSTEM_ADDR+4); pFSAddr = (BYTE *)(MCF5272_FRAMBAR + DS_FILESYSTEM_ADDR+4);
hFile->m_lContentLen = LoadFileInDSFS(szFileName, &hFile->m_pContent, pFSAddr); hFile->m_lContentLen = LoadFileInDSFS(szFileName, &hFile->m_pContent, pFSAddr);
#else #else
@ -946,7 +946,7 @@ BOOL FsCombinAllFile(const char *szListFileName, const char *szDestFileName, con
iLen = strlen(szDestDir)+strlen(szList)+2; iLen = strlen(szDestDir)+strlen(szList)+2;
if(iLen > sizeof(szFileName)) if(iLen > sizeof(szFileName))
{ {
sprintf(szDbg, "文件名称长度(%d > %d)过长", iLen, sizeof(szFileName)); sprintf(szDbg, "文件名称长度(%d > %d)过长", iLen, sizeof(szFileName));
DebugPrint(szDbg); DebugPrint(szDbg);
bReturn = FALSE; bReturn = FALSE;
continue; continue;
@ -956,16 +956,16 @@ BOOL FsCombinAllFile(const char *szListFileName, const char *szDestFileName, con
fp_file = fopen(szFileName, "rb"); fp_file = fopen(szFileName, "rb");
if(NULL == fp_file) if(NULL == fp_file)
{ {
sprintf(szDbg, "文件<%s>不存在或者打开错误.", szFileName); sprintf(szDbg, "文件<%s>不存在或者打开错误.", szFileName);
DebugPrint(szDbg); DebugPrint(szDbg);
bReturn = FALSE; bReturn = FALSE;
continue; continue;
} }
// 写文件出错后,恢复的位置 // 写文件出错后,恢复的位置
iFileOffset = ftell(fp_dest); iFileOffset = ftell(fp_dest);
// 文件的头结构 // 文件的头结构
iFileLen = GetFileLen(fp_file); iFileLen = GetFileLen(fp_file);
fseek(fp_file, 0, SEEK_SET); fseek(fp_file, 0, SEEK_SET);
pBuf = (BYTE *)HEAP_MALLOC(iFileLen); pBuf = (BYTE *)HEAP_MALLOC(iFileLen);
@ -1015,7 +1015,7 @@ BOOL FsCombinAllFile(const char *szListFileName, const char *szDestFileName, con
fclose(fp_file); fclose(fp_file);
} }
// 文件系统的头结构 // 文件系统的头结构
fseek(fp_dest, 0, SEEK_SET); fseek(fp_dest, 0, SEEK_SET);
iOffset = sFileSystemHead.m_iOffset; iOffset = sFileSystemHead.m_iOffset;
if(bNetSequence == FALSE) if(bNetSequence == FALSE)
@ -1093,7 +1093,7 @@ BOOL FsSplitAllFile(const char *szCombinFile, const char *szDestDir)
iLen = pFileHead->m_iFileNameLen+strlen(szDestDir)+2; iLen = pFileHead->m_iFileNameLen+strlen(szDestDir)+2;
if(iLen > sizeof(szFileName)) if(iLen > sizeof(szFileName))
{ {
sprintf(szDbg, "文件名称长度(%d > %d)过长", iLen, sizeof(szFileName)); sprintf(szDbg, "文件名称长度(%d > %d)过长", iLen, sizeof(szFileName));
DebugPrint(szDbg); DebugPrint(szDbg);
bReturn = FALSE; bReturn = FALSE;
break; break;
@ -1102,7 +1102,7 @@ BOOL FsSplitAllFile(const char *szCombinFile, const char *szDestDir)
fp_dest = fopen(szFileName, "wb"); fp_dest = fopen(szFileName, "wb");
if(fp_dest == NULL) if(fp_dest == NULL)
{ {
sprintf(szDbg, "文件<%s>打开错误.", szFileName); sprintf(szDbg, "文件<%s>打开错误.", szFileName);
DebugPrint(szDbg); DebugPrint(szDbg);
bReturn = FALSE; bReturn = FALSE;
break; break;
@ -1161,7 +1161,7 @@ BYTE *FsReadCombinFile(const char *szCombinFile)
fclose(fp); fclose(fp);
// 将文件系统转换为主机字节格式 // 将文件系统转换为主机字节格式
FsNetToHost(pBuf); FsNetToHost(pBuf);
return pBuf; return pBuf;
@ -1203,7 +1203,7 @@ BYTE *FsReadCombinFileEx(const char *szCombinFile)
fclose(fp); fclose(fp);
// 将文件系统转换为主机字节格式 // 将文件系统转换为主机字节格式
FsNetToHost(pBuf); FsNetToHost(pBuf);
return pBuf; return pBuf;
@ -1241,7 +1241,7 @@ BOOL FsLoadFileSystem(const char *szFileSystem, BYTE **ppDestBuf)
*ppDestBuf = (BYTE *)(MCF5272_FRAMBAR + DS_FILESYSTEM_ADDR+4); *ppDestBuf = (BYTE *)(MCF5272_FRAMBAR + DS_FILESYSTEM_ADDR+4);
#endif*/ #endif*/
// 将文件系统转换为主机字节格式 // 将文件系统转换为主机字节格式
FsNetToHost(*ppDestBuf); FsNetToHost(*ppDestBuf);
return TRUE; return TRUE;

@ -14,58 +14,58 @@
//typedef char* HDSFILE; //typedef char* HDSFILE;
/*! /*!
*/ */
#define SEEK_CLR_RCNT SEEK_END+10 #define SEEK_CLR_RCNT SEEK_END+10
#define SEEK_CUR_EX SEEK_END+11 #define SEEK_CUR_EX SEEK_END+11
// 修改DS中的配置文件系统 // 修改DS中的配置文件系统
#define DS_FILESYSTEM_ADDR 0x3b0000 #define DS_FILESYSTEM_ADDR 0x3b0000
#define DS_FILESYSTEM_LEN (0x50000-4) #define DS_FILESYSTEM_LEN (0x50000-4)
#define DS_SECTION_OUT -1 // 段名称长度越限 #define DS_SECTION_OUT -1 // 段名称长度越限
#define DS_SECTION_NOEXIST 0 // 段名称不存在 #define DS_SECTION_NOEXIST 0 // 段名称不存在
#define DS_SECTION_EXIST 1 // 段名称存在 #define DS_SECTION_EXIST 1 // 段名称存在
#define DS_SECTION_SEARCH 2 // 段名称查找 #define DS_SECTION_SEARCH 2 // 段名称查找
typedef struct tsgDSFILE typedef struct tsgDSFILE
{ {
/*! /*!
*/ */
long m_lContentLen; long m_lContentLen;
/*! /*!
*/ */
long m_lOffset; long m_lOffset;
/*! /*!
*/ */
long m_lReadCount; long m_lReadCount;
// 增加优化配置文件读取项 // 增加优化配置文件读取项
/*! /*!
*/ */
long m_lSectionOk; long m_lSectionOk;
/*! /*!
*/ */
long m_lSectionLines; long m_lSectionLines;
/*! /*!
*/ */
long m_lSectionLinesAddFlag; long m_lSectionLinesAddFlag;
/*! /*!
*/ */
long m_lSectionOffset; long m_lSectionOffset;
/*! /*!
*/ */
char m_szSection[64]; char m_szSection[64];
/*! /*!
*/ */
char *m_pContent; char *m_pContent;
}DSFILE, *HDSFILE; }DSFILE, *HDSFILE;
@ -75,13 +75,13 @@ typedef struct tsgDSFILE
typedef struct tagDSFILESYSTEMHEAD typedef struct tagDSFILESYSTEMHEAD
{ {
/*! /*!
*/ */
int m_iFiles; int m_iFiles;
/*! /*!
\note \note
=this+m_iOffset =this+m_iOffset
*/ */
int m_iOffset; int m_iOffset;
}DSFILESYSTEMHEAD; }DSFILESYSTEMHEAD;
@ -89,19 +89,19 @@ typedef struct tagDSFILESYSTEMHEAD
typedef struct tagDSFILEHEAD typedef struct tagDSFILEHEAD
{ {
/*! /*!
(+) (+)
*/ */
int m_iFileSize; int m_iFileSize;
/*! /*!
*/ */
int m_iOffset; int m_iOffset;
/*! /*!
*/ */
int m_iFileNameLen; int m_iFileNameLen;
/*! /*!
*/ */
char m_FileName[1]; char m_FileName[1];
}DSFILEHEAD, *pDSFILEHEAD; }DSFILEHEAD, *pDSFILEHEAD;
@ -117,13 +117,13 @@ typedef struct tagFILECONTENT
typedef struct tagDSFILESYSTEMHEAD typedef struct tagDSFILESYSTEMHEAD
{ {
/*! /*!
*/ */
int m_iFiles ; int m_iFiles ;
/*! /*!
\note \note
=this+m_iOffset =this+m_iOffset
*/ */
int m_iOffset ; int m_iOffset ;
}DSFILESYSTEMHEAD; }DSFILESYSTEMHEAD;
@ -131,19 +131,19 @@ typedef struct tagDSFILESYSTEMHEAD
typedef struct tagDSFILEHEAD typedef struct tagDSFILEHEAD
{ {
/*! /*!
(+) (+)
*/ */
int m_iFileSize ; int m_iFileSize ;
/*! /*!
*/ */
int m_iOffset ; int m_iOffset ;
/*! /*!
*/ */
int m_iFileNameLen ; int m_iFileNameLen ;
/*! /*!
*/ */
char m_FileName[1] ; char m_FileName[1] ;
}DSFILEHEAD, *pDSFILEHEAD; }DSFILEHEAD, *pDSFILEHEAD;
@ -159,143 +159,143 @@ typedef struct tagFILECONTENT
/*! /*!
\brief \brief
\param szFileName -- \param szFileName --
\param ppDestMem -- \param ppDestMem --
\retval -- \retval --
\note \note
0\n 0\n
pDestMem使 pDestMem使
*/ */
long LoadFile(const char *szFileName, char **ppDestMem); long LoadFile(const char *szFileName, char **ppDestMem);
/*! /*!
\brief \brief
\param szFileName -- \param szFileName --
\param ppDestMem -- \param ppDestMem --
\param pFSAddr -- \param pFSAddr --
\retval -- \retval --
\note \note
0\n 0\n
pDestMem使 pDestMem使
*/ */
long LoadFileInDSFS(const char *szFileName, char **ppDestMem, BYTE *pFSAddr); long LoadFileInDSFS(const char *szFileName, char **ppDestMem, BYTE *pFSAddr);
/*! /*!
\brief \brief
\param stream -- \param stream --
\param offset -- origin \param offset -- origin
\param origin -- \param origin --
\retval -- 0 \retval -- 0
*/ */
DSLIB_API int DS_Seek(FILECONTENT *stream, long offset, int origin); DSLIB_API int DS_Seek(FILECONTENT *stream, long offset, int origin);
DSLIB_API char *DS_Gets(char *pDest, int iDestMax, FILECONTENT *stream); DSLIB_API char *DS_Gets(char *pDest, int iDestMax, FILECONTENT *stream);
/*! /*!
\brief \brief
\param fp -- \param fp --
\retval -- \retval --
*/ */
DSLIB_API int GetFileLen(FILE *fp); DSLIB_API int GetFileLen(FILE *fp);
/*! /*!
\brief \brief
\param szFileName -- \param szFileName --
\retval -- \retval --
\note \note
0\n 0\n
pDestMem使 pDestMem使
*/ */
DSLIB_API HDSFILE DSOpenFile(const char *szFileName); DSLIB_API HDSFILE DSOpenFile(const char *szFileName);
DSLIB_API HDSFILE DSOpenFileEx(const char *szFileName); DSLIB_API HDSFILE DSOpenFileEx(const char *szFileName);
/*! /*!
\brief \brief
\param szRootDir -- \param szRootDir --
\param szFileName -- \param szFileName --
\retval -- \retval --
\note \note
0\n 0\n
pDestMem使 pDestMem使
pc pc
1 1
*/ */
DSLIB_API HDSFILE DSOpenFileEx3(const char *szRootDir, const char *szFileName); DSLIB_API HDSFILE DSOpenFileEx3(const char *szRootDir, const char *szFileName);
DSLIB_API HDSFILE DSOpenFileEx2(const char *szRootDir, const char *szFSName, const char *szFileName); DSLIB_API HDSFILE DSOpenFileEx2(const char *szRootDir, const char *szFSName, const char *szFileName);
/*! /*!
\brief \brief
\param hFile -- \param hFile --
\note \note
0\n 0\n
pDestMem使 pDestMem使
*/ */
DSLIB_API BOOL DSCloseFile(HDSFILE hFile); DSLIB_API BOOL DSCloseFile(HDSFILE hFile);
/*! /*!
\brief \brief
\param buffer -- \param buffer --
\param size -- \param size --
\param count -- \param count --
\param hFile -- \param hFile --
\retval -- \retval --
*/ */
DSLIB_API size_t DSfread(void *buffer, size_t size, size_t count, HDSFILE hFile); DSLIB_API size_t DSfread(void *buffer, size_t size, size_t count, HDSFILE hFile);
/*! /*!
\brief () \brief ()
\param string -- \param string --
\param origin -- \param origin --
\param hFile -- \param hFile --
\retval -- \retval --
*/ */
DSLIB_API char *DSfgets(char *string, int iMaxSize, HDSFILE hFile); DSLIB_API char *DSfgets(char *string, int iMaxSize, HDSFILE hFile);
/*! /*!
\brief () \brief ()
\param string -- \param string --
\param origin -- \param origin --
\param hFile -- \param hFile --
\param ioffset -- \param ioffset --
\retval -- \retval --
\note \note
, ,
*/ */
DSLIB_API char *DSfgetsEx(char *string, int iMaxSize, HDSFILE hFile); DSLIB_API char *DSfgetsEx(char *string, int iMaxSize, HDSFILE hFile);
/*! /*!
\brief \brief
\param hFile -- \param hFile --
\retval -- \retval --
*/ */
DSLIB_API int DSfgetreadcount(HDSFILE hFile); DSLIB_API int DSfgetreadcount(HDSFILE hFile);
/*! /*!
\brief \brief
\param hFile -- \param hFile --
\param offset -- origin \param offset -- origin
\param origin -- \param origin --
\retval -- 0 \retval -- 0
*/ */
DSLIB_API int DSfseek(HDSFILE hFile, long offset, int origin); DSLIB_API int DSfseek(HDSFILE hFile, long offset, int origin);
/*! /*!
\brief \brief
\param hFile -- \param hFile --
\retval -- 0 \retval -- 0
*/ */
DSLIB_API int DSfeof(HDSFILE hFile); DSLIB_API int DSfeof(HDSFILE hFile);
/*! /*!
\brief \brief
\param hFile -- \param hFile --
\retval -- 0 \retval -- 0
*/ */
DSLIB_API int DSfeofEx(HDSFILE hFile); DSLIB_API int DSfeofEx(HDSFILE hFile);
/*! /*!
\brief \brief
\param hFile -- \param hFile --
\retval -- 0, \retval -- 0,
*/ */
DSLIB_API int DSfeob(HDSFILE hFile); DSLIB_API int DSfeob(HDSFILE hFile);
/*! /*!
\brief \brief
\param hFile -- \param hFile --
\retval -- \retval --
*/ */
DSLIB_API int DSftell(HDSFILE hFile); DSLIB_API int DSftell(HDSFILE hFile);
DSLIB_API int DSHaveSection(char *pSection, HDSFILE hFile); DSLIB_API int DSHaveSection(char *pSection, HDSFILE hFile);
@ -307,53 +307,53 @@ DSLIB_API int DSSetSectionLinesAddFlag(int iFlag, HDSFILE hFile);
DSLIB_API int DSSectionisOver(int iReadLines, HDSFILE hFile); DSLIB_API int DSSectionisOver(int iReadLines, HDSFILE hFile);
/*! /*!
\brief \brief
\param szListFileName -- \param szListFileName --
\param szDestFileName -- \param szDestFileName --
\param szDestDir -- \param szDestDir --
\retval -- TRUE \retval -- TRUE
\note \note
*/ */
DSLIB_API BOOL FsCombinAllFile(const char *szListFileName, const char *szDestFileName, const char *szDestDir); DSLIB_API BOOL FsCombinAllFile(const char *szListFileName, const char *szDestFileName, const char *szDestDir);
/*! /*!
\brief \brief
\param szCombinFile -- \param szCombinFile --
\param szDestDir -- \param szDestDir --
\retval -- TRUE \retval -- TRUE
*/ */
DSLIB_API BOOL FsSplitAllFile(const char *szCombinFile, const char *szDestDir); DSLIB_API BOOL FsSplitAllFile(const char *szCombinFile, const char *szDestDir);
//测试用 //测试用
/*! /*!
\brief () \brief ()
\param szCombinFile -- \param szCombinFile --
\retval -- TRUE \retval -- TRUE
*/ */
DSLIB_API BYTE *FsReadCombinFile(const char *szCombinFile); DSLIB_API BYTE *FsReadCombinFile(const char *szCombinFile);
DSLIB_API BYTE *FsReadCombinFileEx(const char *szCombinFile); DSLIB_API BYTE *FsReadCombinFileEx(const char *szCombinFile);
/*! /*!
\brief \brief
\param szFileSystem -- \param szFileSystem --
\param ppDestBuf -- \param ppDestBuf --
\retval -- TRUE \retval -- TRUE
*/ */
DSLIB_API BOOL FsLoadFileSystem(const char *szFileSystem, BYTE **ppDestBuf); DSLIB_API BOOL FsLoadFileSystem(const char *szFileSystem, BYTE **ppDestBuf);
/*! /*!
\brief \brief
\param ppDestBuf -- \param ppDestBuf --
\retval -- TRUE \retval -- TRUE
*/ */
DSLIB_API BOOL FsUnLoadFileSystem(BYTE **ppDestBuf); DSLIB_API BOOL FsUnLoadFileSystem(BYTE **ppDestBuf);
/*! /*!
\brief \brief
\param szPath -- \param szPath --
\param szFileSystem -- \param szFileSystem --
\retval -- TRUE \retval -- TRUE
*/ */
DSLIB_API BOOL FsDirFileName(const char *szPath, const char *szFileSystem); DSLIB_API BOOL FsDirFileName(const char *szPath, const char *szFileSystem);

@ -15,7 +15,7 @@
// Construction/Destruction // Construction/Destruction
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
const char* gColumnName[MAX_NET_NUM+1] = {"唗瘍","IP華硊1","IP華硊2","IP華硊3"}; const char* gColumnName[MAX_NET_NUM+1] = {"序号","IP地址1","IP地址2","IP地址3"};
CDlgDevListImpl::CDlgDevListImpl(DEV_DEF *pDevParam, int iDevNum, int iCurSel, QWidget* parent, const char* name, bool modal, WFlags fl) CDlgDevListImpl::CDlgDevListImpl(DEV_DEF *pDevParam, int iDevNum, int iCurSel, QWidget* parent, const char* name, bool modal, WFlags fl)
: DevList(parent, name, modal, fl) : DevList(parent, name, modal, fl)
@ -67,9 +67,9 @@ CDlgDevListImpl::~CDlgDevListImpl()
void CDlgDevListImpl::languageChange() void CDlgDevListImpl::languageChange()
{ {
setCaption(CHS("扢掘蹈桶")); setCaption(CHS("设备列表"));
m_BtnChange->setText(CHS("恁寁")); m_BtnChange->setText(CHS("选择"));
m_BtnCancel->setText(CHS("龰秏")); m_BtnCancel->setText(CHS("取消"));
} }
void CDlgDevListImpl::ChangeSelectSlot() void CDlgDevListImpl::ChangeSelectSlot()

@ -1,74 +1,74 @@
/*----------------------------------------------------------------------------------- /*-----------------------------------------------------------------------------------
INI V1.65 INI V1.65
2002.10.3 2002.10.3
----------------------------------------------------------------------------------*/ ----------------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------------- /*-----------------------------------------------------------------------------------
[]: []:
(1) V1.0 2002.8.13 仿windowsAPI (1) V1.0 2002.8.13 仿windowsAPI
(2) V1.1 2002.9.13 BUG (2) V1.1 2002.9.13 BUG
1. 1.
2. , 2. ,
(3) V1.2 2002.9.18 QGetPrivateProfileInt()16 (3) V1.2 2002.9.18 QGetPrivateProfileInt()16
(4) V1.3 2002.9.19 BUG (4) V1.3 2002.9.19 BUG
1. StrTrimLeft, StrTrimRightTAB(ASC9),Ini 1. StrTrimLeft, StrTrimRightTAB(ASC9),Ini
TAB TAB
2. ";"StrTrimAll() 2. ";"StrTrimAll()
TAB TAB
(5) V1.4a 2002.9.20 (5) V1.4a 2002.9.20
OpenPort()3016 OpenPort()3016
(6) V1.41a 2002.9.23 (6) V1.41a 2002.9.23
,OpenPort()1614 ,OpenPort()1614
,, ,沿- ,, ,沿-
(7) V1.5 2002.9.23 (7) V1.5 2002.9.23
1. QGetPrivateProfileString(), 1. QGetPrivateProfileString(),
,,,INI ,,,INI
, ,
INI使 INI使
使 使
使OpenPort()3-4. 使OpenPort()3-4.
2. WritePrivateProfileString()10, 2. WritePrivateProfileString()10,
(8) V1.6 2002.9.27 ini (8) V1.6 2002.9.27 ini
,(0x0A),fgets() ,(0x0A),fgets()
windowsini(0x0D), windowsini(0x0D),
0x0A,windows访unixini 0x0A,windows访unixini
(9) V1.65 2002.10.3 provdata.ini (9) V1.65 2002.10.3 provdata.ini
1. "//"";" 1. "//"";"
2. '\' 2. '\'
: :
1. () 1. ()
2. ,(';')('\') 2. ,(';')('\')
-----------------------------------------------------------------------------------*/ -----------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------- /*-------------------------------------------------------------------------------------
[使]: [使]:
(1) ,,unixOS_UNIX (1) ,,unixOS_UNIX
(2) INI,: (2) INI,:
'['']'INI"[ xxx ]" '['']'INI"[ xxx ]"
"[xxx]"访 "[xxx]"访
-------------------------------------------------------------------------------------*/ -------------------------------------------------------------------------------------*/
@ -79,86 +79,86 @@
#include <stdlib.h> #include <stdlib.h>
//#include <qglobal.h> //#include <qglobal.h>
/*------------------------------------------------------------------------------------- /*-------------------------------------------------------------------------------------
INI(),API,const char*char* INI(),API,const char*char*
DWORDint,(APIDWORD) DWORDint,(APIDWORD)
(int),使 (int),使
-------------------------------------------------------------------------------------*/ -------------------------------------------------------------------------------------*/
int QGetPrivateProfileString( int QGetPrivateProfileString(
const char* lpszSectionName, //段名 const char* lpszSectionName, //段名
const char* lpszKeyName, //键名 const char* lpszKeyName, //键名
const char* lpszDefault, //缺省字符串 const char* lpszDefault, //缺省字符串
char* lpszReturnedString, //结果字符串 char* lpszReturnedString, //结果字符串
u_32 nSize, //结果字符串长度 u_32 nSize, //结果字符串长度
const char* lpszFileName, //ini文件名 const char* lpszFileName, //ini文件名
const char* lpszRemarkInLineStr, //行内注释符 const char* lpszRemarkInLineStr, //行内注释符
const char chContinueLineChar //续行符号 const char chContinueLineChar //续行符号
) )
{ {
FILE* IniFile = NULL; FILE* IniFile = NULL;
BOOL bSecFoundFlag = FALSE; BOOL bSecFoundFlag = FALSE;
BOOL bKeyFoundFlag = FALSE; BOOL bKeyFoundFlag = FALSE;
BOOL bEOF = FALSE; BOOL bEOF = FALSE;
char szLineBuf[MAX_LINE_BUF_LENGTH]; //行缓冲区 char szLineBuf[MAX_LINE_BUF_LENGTH]; //行缓冲区
char szKeyItemBuf[MAX_LINE_BUF_LENGTH*4]; //最终内容缓冲区(因键所在行可能因使用续行符而占据多行) char szKeyItemBuf[MAX_LINE_BUF_LENGTH*4]; //最终内容缓冲区(因键所在行可能因使用续行符而占据多行)
char *lpszFileText = NULL; //放置INI文件全部内容的字符串 char *lpszFileText = NULL; //放置INI文件全部内容的字符串
char *lpszLineBegin = NULL; //一行开始指针 char *lpszLineBegin = NULL; //一行开始指针
char *lpszTmp = NULL; char *lpszTmp = NULL;
i_32 lFileSize = 0; i_32 lFileSize = 0;
int iPos, iRetVal; int iPos, iRetVal;
BOOL bLineContinue = FALSE; //2002.10.3 续行标志 BOOL bLineContinue = FALSE; //2002.10.3 续行标志
/*--------------------------------------------------------------------------------- /*---------------------------------------------------------------------------------
char szLineEndStr[3]; //行末尾换行符号 char szLineEndStr[3]; //行末尾换行符号
memset(szLineEndStr, 0, 3); memset(szLineEndStr, 0, 3);
#ifdef OS_UNIX #ifdef OS_UNIX
strcpy(szLineEndStr, "\n"); //UNIX文本文件行末只有一个换行符'\n' strcpy(szLineEndStr, "\n"); //UNIX文本文件行末只有一个换行符'\n'
#else #else
strcpy(szLineEndStr, "\r\n"); //Windows文本文件行末有一个回车符'\r',一个换行符'\n' strcpy(szLineEndStr, "\r\n"); //Windows文本文件行末有一个回车符'\r',一个换行符'\n'
#endif #endif
----------------------------------------------------------------------------------*/ ----------------------------------------------------------------------------------*/
IniFile = fopen(lpszFileName, "rb"); //二进制可读方式打开(文件必须存在) IniFile = fopen(lpszFileName, "rb"); //二进制可读方式打开(文件必须存在)
if(!IniFile) if(!IniFile)
{ {
//qDebug("fopen error, %s", lpszFileName); //qDebug("fopen error, %s", lpszFileName);
return FILE_OPEN_ERROR; return FILE_OPEN_ERROR;
} }
fseek(IniFile, 0, SEEK_END); //定位到文件尾部 fseek(IniFile, 0, SEEK_END); //定位到文件尾部
lFileSize = ftell(IniFile); //获取文件尾指针位置(该值=文件总长=文件指针位置最大值+1) lFileSize = ftell(IniFile); //获取文件尾指针位置(该值=文件总长=文件指针位置最大值+1)
lpszFileText = new char[lFileSize+1]; lpszFileText = new char[lFileSize+1];
memset(lpszFileText, 0, lFileSize+1); memset(lpszFileText, 0, lFileSize+1);
fseek(IniFile, 0, SEEK_SET); //重新定位到开头 fseek(IniFile, 0, SEEK_SET); //重新定位到开头
fread(lpszFileText, 1, lFileSize, IniFile); //将文件所有内容全部读入字符串 fread(lpszFileText, 1, lFileSize, IniFile); //将文件所有内容全部读入字符串
fclose(IniFile); //读入全部内容后立即关闭文件 fclose(IniFile); //读入全部内容后立即关闭文件
lpszLineBegin = lpszFileText; lpszLineBegin = lpszFileText;
//段搜索 //段搜索
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------
//while(!feof(IniFile)) //while(!feof(IniFile))
while(!bEOF) while(!bEOF)
{ {
//ReadLineFromFile(IniFile, szLineBuf, MAX_LINE_BUF_LENGTH); //读取一行 //ReadLineFromFile(IniFile, szLineBuf, MAX_LINE_BUF_LENGTH); //读取一行
memset(szLineBuf, 0, MAX_LINE_BUF_LENGTH); memset(szLineBuf, 0, MAX_LINE_BUF_LENGTH);
lpszTmp = strstr(lpszLineBegin, szLineEndStr); //搜索换行符号来定位行末 lpszTmp = strstr(lpszLineBegin, szLineEndStr); //搜索换行符号来定位行末
if(lpszTmp != NULL) if(lpszTmp != NULL)
{ {
strncpy(szLineBuf, lpszLineBegin, min(MAX_LINE_BUF_LENGTH-1, lpszTmp-lpszLineBegin)); strncpy(szLineBuf, lpszLineBegin, min(MAX_LINE_BUF_LENGTH-1, lpszTmp-lpszLineBegin));
lpszLineBegin = lpszTmp + strlen(szLineEndStr); lpszLineBegin = lpszTmp + strlen(szLineEndStr);
} }
else //最后一行 else //最后一行
{ {
strncpy(szLineBuf, lpszLineBegin, min(MAX_LINE_BUF_LENGTH-1, lpszFileText+lFileSize-lpszLineBegin)); strncpy(szLineBuf, lpszLineBegin, min(MAX_LINE_BUF_LENGTH-1, lpszFileText+lFileSize-lpszLineBegin));
bEOF = TRUE; bEOF = TRUE;
@ -166,21 +166,21 @@ int QGetPrivateProfileString(
StrTrimAll(szLineBuf); StrTrimAll(szLineBuf);
if( szLineBuf[0] == ';' || szLineBuf[0] == 0 ) continue; //注释行和空行不处理 if( szLineBuf[0] == ';' || szLineBuf[0] == 0 ) continue; //注释行和空行不处理
//将一行尾部可能存在的";"注释部分剔除(这样key=value的value中不能含有;否则将被当成注释而删除 //将一行尾部可能存在的";"注释部分剔除(这样key=value的value中不能含有;否则将被当成注释而删除
lpszTmp = strchr(szLineBuf, ';'); lpszTmp = strchr(szLineBuf, ';');
if(lpszTmp != NULL) *lpszTmp = 0; if(lpszTmp != NULL) *lpszTmp = 0;
StrTrimAll(szLineBuf); //zl 2002.9.19 ";"和有用内容间必有空格或TAB字符,必须删除这些分割字符 StrTrimAll(szLineBuf); //zl 2002.9.19 ";"和有用内容间必有空格或TAB字符,必须删除这些分割字符
iPos = strlen(szLineBuf) - 1; iPos = strlen(szLineBuf) - 1;
if(szLineBuf[0] == '[' && szLineBuf[iPos] == ']') //该行是一个段 if(szLineBuf[0] == '[' && szLineBuf[iPos] == ']') //该行是一个段
{ {
szLineBuf[iPos] = 0; //去掉"["和"]",便于比较 szLineBuf[iPos] = 0; //去掉"["和"]",便于比较
lpszTmp = &szLineBuf[1]; lpszTmp = &szLineBuf[1];
if( strcmp(lpszTmp, lpszSectionName) == 0 ) //指定的段找到了 if( strcmp(lpszTmp, lpszSectionName) == 0 ) //指定的段找到了
{ {
bSecFoundFlag = TRUE; bSecFoundFlag = TRUE;
break; break;
@ -190,31 +190,31 @@ int QGetPrivateProfileString(
----------------------------------------------------------------------------*/ ----------------------------------------------------------------------------*/
//zl 2002.9.23 新的段搜索算法(直接在包含整个ini文件内容的字符串中定位段名) //zl 2002.9.23 新的段搜索算法(直接在包含整个ini文件内容的字符串中定位段名)
char szFindStr[MAX_LINE_BUF_LENGTH]; //搜索字符串 char szFindStr[MAX_LINE_BUF_LENGTH]; //搜索字符串
sprintf(szFindStr, "[%s]", lpszSectionName); sprintf(szFindStr, "[%s]", lpszSectionName);
while(!bEOF) while(!bEOF)
{ {
lpszTmp = strstr(lpszLineBegin, szFindStr); lpszTmp = strstr(lpszLineBegin, szFindStr);
if( lpszTmp != NULL ) //找到段名,继续验证其是否合法 if( lpszTmp != NULL ) //找到段名,继续验证其是否合法
{ {
lpszLineBegin = lpszTmp + strlen(szFindStr); //计算新的查找起始位置 lpszLineBegin = lpszTmp + strlen(szFindStr); //计算新的查找起始位置
if( lpszLineBegin > (lpszFileText + lFileSize -1) ) bEOF = TRUE; if( lpszLineBegin > (lpszFileText + lFileSize -1) ) bEOF = TRUE;
if( lpszTmp == lpszFileText ) //"[xxx]"是文件的开头内容,为合法段名 if( lpszTmp == lpszFileText ) //"[xxx]"是文件的开头内容,为合法段名
{ {
bSecFoundFlag = TRUE; bSecFoundFlag = TRUE;
break; break;
} }
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------
'[',0xA,,tab(ASC9) '[',0xA,,tab(ASC9)
,,, ']' ,,, ']'
----------------------------------------------------------------------------*/ ----------------------------------------------------------------------------*/
lpszTmp--; lpszTmp--;
@ -232,10 +232,10 @@ int QGetPrivateProfileString(
break; break;
} }
if( bSecFoundFlag ) break; //退出外循环 if( bSecFoundFlag ) break; //退出外循环
} }
else else
break; //没找到段名,退出 break; //没找到段名,退出
} }
@ -245,29 +245,29 @@ int QGetPrivateProfileString(
goto func_end; goto func_end;
} }
//继续键搜索(定位段后,对于所属键的查找为逐行读取扫描方式,键可能占用多行) //继续键搜索(定位段后,对于所属键的查找为逐行读取扫描方式,键可能占用多行)
while(!bEOF) while(!bEOF)
{ {
if( !bLineContinue ) if( !bLineContinue )
memset(szKeyItemBuf, 0, sizeof(szKeyItemBuf)); //关键,控制多行连接 memset(szKeyItemBuf, 0, sizeof(szKeyItemBuf)); //关键,控制多行连接
memset(szLineBuf, 0, MAX_LINE_BUF_LENGTH); memset(szLineBuf, 0, MAX_LINE_BUF_LENGTH);
//zl 2002.9.27 为保证提取一行的操作与平台文件格式无关,只查找换行符(0x0A),这和fgets()类似 //zl 2002.9.27 为保证提取一行的操作与平台文件格式无关,只查找换行符(0x0A),这和fgets()类似
lpszTmp = strchr(lpszLineBegin, 0x0A); lpszTmp = strchr(lpszLineBegin, 0x0A);
if(lpszTmp != NULL) if(lpszTmp != NULL)
{ {
strncpy(szLineBuf, lpszLineBegin, min(MAX_LINE_BUF_LENGTH-1, lpszTmp-lpszLineBegin)); //从字符串中提取一行 strncpy(szLineBuf, lpszLineBegin, min(MAX_LINE_BUF_LENGTH-1, lpszTmp-lpszLineBegin)); //从字符串中提取一行
/* 读windows文本文件时,每行尾部多一个回车符(0x0D),必须去掉,否则后面连续出错 */ /* 读windows文本文件时,每行尾部多一个回车符(0x0D),必须去掉,否则后面连续出错 */
if( szLineBuf[strlen(szLineBuf)-1] == 0x0D ) if( szLineBuf[strlen(szLineBuf)-1] == 0x0D )
szLineBuf[strlen(szLineBuf)-1] = 0; szLineBuf[strlen(szLineBuf)-1] = 0;
lpszLineBegin = lpszTmp + 1; //1表示"0x0A"一个字符 lpszLineBegin = lpszTmp + 1; //1表示"0x0A"一个字符
} }
else //最后一行 else //最后一行
{ {
strncpy(szLineBuf, lpszLineBegin, min(MAX_LINE_BUF_LENGTH-1, lpszFileText+lFileSize-lpszLineBegin)); strncpy(szLineBuf, lpszLineBegin, min(MAX_LINE_BUF_LENGTH-1, lpszFileText+lFileSize-lpszLineBegin));
bEOF = TRUE; bEOF = TRUE;
@ -275,10 +275,10 @@ int QGetPrivateProfileString(
StrTrimAll(szLineBuf); StrTrimAll(szLineBuf);
//全注释行和空行不处理 //全注释行和空行不处理
if( szLineBuf[0] == ';' || szLineBuf[0] == 0 ) if( szLineBuf[0] == ';' || szLineBuf[0] == 0 )
{ {
if( bLineContinue && strlen(szKeyItemBuf) > 0 ) //2002.10.7 如果前面是续行,则继续处理szKeyItemBuf已有内容而不是continue重新读入一行,否则当前行(空行或注释行)上面的一个续行的全部内容将丢失 if( bLineContinue && strlen(szKeyItemBuf) > 0 ) //2002.10.7 如果前面是续行,则继续处理szKeyItemBuf已有内容而不是continue重新读入一行,否则当前行(空行或注释行)上面的一个续行的全部内容将丢失
bLineContinue = FALSE; bLineContinue = FALSE;
else else
{ {
@ -288,57 +288,57 @@ int QGetPrivateProfileString(
} }
else else
{ {
//2002.10.3 判断续行,续行符为行末最后的一个非空格或TAB字符,缺省为'\' //2002.10.3 判断续行,续行符为行末最后的一个非空格或TAB字符,缺省为'\'
if( szLineBuf[strlen(szLineBuf)-1] == chContinueLineChar ) if( szLineBuf[strlen(szLineBuf)-1] == chContinueLineChar )
{ {
bLineContinue = TRUE; bLineContinue = TRUE;
szLineBuf[strlen(szLineBuf)-1] = 0; //去掉续行符 szLineBuf[strlen(szLineBuf)-1] = 0; //去掉续行符
StrTrimAll(szLineBuf); StrTrimAll(szLineBuf);
strcat(szKeyItemBuf, szLineBuf); strcat(szKeyItemBuf, szLineBuf);
continue; continue;
} }
else //无续行字符行 else //无续行字符行
{ {
bLineContinue = FALSE; bLineContinue = FALSE;
strcat(szKeyItemBuf, szLineBuf); strcat(szKeyItemBuf, szLineBuf);
} }
} }
//将一行尾部可能存在的行内注释部分(缺省行内注释符是";")剔除 //将一行尾部可能存在的行内注释部分(缺省行内注释符是";")剔除
//lpszTmp = strchr(szLineBuf, ';'); //lpszTmp = strchr(szLineBuf, ';');
lpszTmp = strstr(szKeyItemBuf, lpszRemarkInLineStr); //2002.10.3 可以任意指定行内注释符 lpszTmp = strstr(szKeyItemBuf, lpszRemarkInLineStr); //2002.10.3 可以任意指定行内注释符
if(lpszTmp != NULL) *lpszTmp = 0; if(lpszTmp != NULL) *lpszTmp = 0;
StrTrimAll(szKeyItemBuf); //zl 2002.9.19 ";"和有用内容间必有空格或TAB字符,必须删除这些分割字符 StrTrimAll(szKeyItemBuf); //zl 2002.9.19 ";"和有用内容间必有空格或TAB字符,必须删除这些分割字符
iPos = strlen(szKeyItemBuf)-1; iPos = strlen(szKeyItemBuf)-1;
if(szKeyItemBuf[0] == '[' && szKeyItemBuf[iPos] == ']') //又到了一个段说明指定段下的指定key没有找到 if(szKeyItemBuf[0] == '[' && szKeyItemBuf[iPos] == ']') //又到了一个段说明指定段下的指定key没有找到
{ {
iRetVal = KEY_NOT_FOUND; iRetVal = KEY_NOT_FOUND;
goto func_end; goto func_end;
} }
lpszTmp = strchr(szKeyItemBuf, '='); //定位'=' lpszTmp = strchr(szKeyItemBuf, '='); //定位'='
if(lpszTmp == NULL) continue; //不含等号的非段行被视为无效行 if(lpszTmp == NULL) continue; //不含等号的非段行被视为无效行
*lpszTmp = 0; //为便于操作,在'='位置将szLineBuf从中间截断, 将szLineBuf分成key和value两个部分 *lpszTmp = 0; //为便于操作,在'='位置将szLineBuf从中间截断, 将szLineBuf分成key和value两个部分
StrTrimAll(szKeyItemBuf); //此时szLineBuf是key StrTrimAll(szKeyItemBuf); //此时szLineBuf是key
if(strcmp(szKeyItemBuf, lpszKeyName) == 0) //找到了指定key if(strcmp(szKeyItemBuf, lpszKeyName) == 0) //找到了指定key
{ {
lpszTmp++; lpszTmp++;
StrTrimAll(lpszTmp); //lpszTmp++是key对应的value StrTrimAll(lpszTmp); //lpszTmp++是key对应的value
if( strlen(lpszTmp) < nSize ) if( strlen(lpszTmp) < nSize )
strcpy(lpszReturnedString, lpszTmp); //返回key对应的value strcpy(lpszReturnedString, lpszTmp); //返回key对应的value
else else
strncpy(lpszReturnedString, lpszTmp, strlen(lpszTmp)); strncpy(lpszReturnedString, lpszTmp, strlen(lpszTmp));
iRetVal = 1; //1表示正确 iRetVal = 1; //1表示正确
bKeyFoundFlag = TRUE; bKeyFoundFlag = TRUE;
break; break;
@ -351,7 +351,7 @@ func_end:
delete [] lpszFileText; delete [] lpszFileText;
//如果出错同时缺省参数不为NULL则返回缺省参数 //如果出错同时缺省参数不为NULL则返回缺省参数
if( iRetVal < 0 && lpszDefault != NULL ) if( iRetVal < 0 && lpszDefault != NULL )
{ {
if( strlen(lpszDefault) < nSize ) if( strlen(lpszDefault) < nSize )
@ -364,41 +364,41 @@ func_end:
} }
/*------------------------------------------------------------------------------------- /*-------------------------------------------------------------------------------------
INI(),API,const char*char*, INI(),API,const char*char*,
UINTint UINTint
-------------------------------------------------------------------------------------*/ -------------------------------------------------------------------------------------*/
int QGetPrivateProfileInt( int QGetPrivateProfileInt(
const char* lpszSectionName, //段名 const char* lpszSectionName, //段名
const char* lpszKeyName, //键名 const char* lpszKeyName, //键名
int nDefault, //缺省值 int nDefault, //缺省值
const char* lpszFileName, //ini文件名 const char* lpszFileName, //ini文件名
const char* lpszRemarkInLineStr, //行内注释符 const char* lpszRemarkInLineStr, //行内注释符
const char chContinueLineChar //续行符号 const char chContinueLineChar //续行符号
) )
{ {
int iRet, iResult; int iRet, iResult;
char szNumStr[256]; //数字字符串 char szNumStr[256]; //数字字符串
iRet = QGetPrivateProfileString( iRet = QGetPrivateProfileString(
lpszSectionName, //段名 lpszSectionName, //段名
lpszKeyName, //键名 lpszKeyName, //键名
NULL, //缺省字符串 NULL, //缺省字符串
szNumStr, //结果字符串 szNumStr, //结果字符串
256, //结果字符串长度 256, //结果字符串长度
lpszFileName, //INI文件名 lpszFileName, //INI文件名
lpszRemarkInLineStr, //行内注释符 lpszRemarkInLineStr, //行内注释符
chContinueLineChar //续行符号 chContinueLineChar //续行符号
); );
//qDebug(lpszFileName); //qDebug(lpszFileName);
if(iRet < 0) return nDefault; //出错则返回缺省值 if(iRet < 0) return nDefault; //出错则返回缺省值
StrTrimAll(szNumStr); StrTrimAll(szNumStr);
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
ini"0x1801"16,,atoi16 ini"0x1801"16,,atoi16
2002.9.18 16,"0x数字" 2002.9.18 16,"0x数字"
--------------------------------------------------------------------------------*/ --------------------------------------------------------------------------------*/
BOOL bIsHexFlag = FALSE; BOOL bIsHexFlag = FALSE;
@ -409,82 +409,82 @@ int QGetPrivateProfileInt(
} }
if( bIsHexFlag ) if( bIsHexFlag )
iRet = sscanf(&szNumStr[2], "%x", &iResult); //16进制 iRet = sscanf(&szNumStr[2], "%x", &iResult); //16进制
else else
iRet = sscanf(szNumStr, "%d", &iResult); //10进制 iRet = sscanf(szNumStr, "%d", &iResult); //10进制
if( iRet != 1 ) //如数字字符串合法的话,应只转换一个field,故返回值不为1表示出错,此时返回缺省值 if( iRet != 1 ) //如数字字符串合法的话,应只转换一个field,故返回值不为1表示出错,此时返回缺省值
return nDefault; return nDefault;
else else
return iResult; //正确返回 return iResult; //正确返回
} }
/*------------------------------------------------------------------------------------- /*-------------------------------------------------------------------------------------
INI,API,const char*char* INI,API,const char*char*
-------------------------------------------------------------------------------------*/ -------------------------------------------------------------------------------------*/
BOOL QWritePrivateProfileString( BOOL QWritePrivateProfileString(
const char* lpszSectionName, //段名 const char* lpszSectionName, //段名
const char* lpszKeyName, //键名 const char* lpszKeyName, //键名
const char* lpszString, //要写入的字符串 const char* lpszString, //要写入的字符串
const char* lpszFileName //INI文件名 const char* lpszFileName //INI文件名
) )
{ {
FILE* IniFile; FILE* IniFile;
char szLineBuf[MAX_LINE_BUF_LENGTH]; char szLineBuf[MAX_LINE_BUF_LENGTH];
char *lpszFrontBlock = NULL, *lpszRearBlock = NULL; //装入前后两块文件各自所占的内存区指针 char *lpszFrontBlock = NULL, *lpszRearBlock = NULL; //装入前后两块文件各自所占的内存区指针
char *lpszTmp = NULL; char *lpszTmp = NULL;
i_32 lPrePos = 0, lCurPos = 0; //前一次读取及本次读取的文件指针位置 i_32 lPrePos = 0, lCurPos = 0; //前一次读取及本次读取的文件指针位置
bool bSecFoundFlag = FALSE; bool bSecFoundFlag = FALSE;
bool bKeyFoundFlag = FALSE; bool bKeyFoundFlag = FALSE;
bool bMeetAnotherBlock = FALSE; //遇到另外一个段 bool bMeetAnotherBlock = FALSE; //遇到另外一个段
i_32 lEndPos; i_32 lEndPos;
int iPos; int iPos;
char szLineEndStr[3]; //行末尾换行符号 char szLineEndStr[3]; //行末尾换行符号
#ifdef OS_UNIX #ifdef OS_UNIX
strcpy(szLineEndStr, "\n"); //UNIX文本文件行末只有一个换行符'\n' strcpy(szLineEndStr, "\n"); //UNIX文本文件行末只有一个换行符'\n'
#else #else
strcpy(szLineEndStr, "\r\n"); //Windows文本文件行末有一个回车符'\r',一个换行符'\n' strcpy(szLineEndStr, "\r\n"); //Windows文本文件行末有一个回车符'\r',一个换行符'\n'
#endif #endif
IniFile = fopen(lpszFileName, "r+b"); //二进制方式打开,可读可写(但文件必须存在) IniFile = fopen(lpszFileName, "r+b"); //二进制方式打开,可读可写(但文件必须存在)
if(!IniFile) return false; if(!IniFile) return false;
fseek(IniFile, 0, SEEK_END); //定位到文件尾部 fseek(IniFile, 0, SEEK_END); //定位到文件尾部
lEndPos = ftell(IniFile); //计算文件尾部指针位置(该值=文件总长=文件指针位置最大值+1) lEndPos = ftell(IniFile); //计算文件尾部指针位置(该值=文件总长=文件指针位置最大值+1)
fseek(IniFile, 0, SEEK_SET); //重新定位到开头 fseek(IniFile, 0, SEEK_SET); //重新定位到开头
//先找指定的section //先找指定的section
while(!feof(IniFile)) while(!feof(IniFile))
{ {
lPrePos = lCurPos; //保留上次文件指针位置 lPrePos = lCurPos; //保留上次文件指针位置
ReadLineFromFile(IniFile, szLineBuf, MAX_LINE_BUF_LENGTH); //读取一行 ReadLineFromFile(IniFile, szLineBuf, MAX_LINE_BUF_LENGTH); //读取一行
lCurPos = ftell(IniFile); //当前文件指针位置 lCurPos = ftell(IniFile); //当前文件指针位置
StrTrimAll(szLineBuf); StrTrimAll(szLineBuf);
if( szLineBuf[0] == ';' || szLineBuf[0] == 0 ) continue; //注释行和空行不处理 if( szLineBuf[0] == ';' || szLineBuf[0] == 0 ) continue; //注释行和空行不处理
//将一行尾部可能存在的";"注释部分剔除(这样key=value的value中不能含有;否则将被当成注释而删除 //将一行尾部可能存在的";"注释部分剔除(这样key=value的value中不能含有;否则将被当成注释而删除
lpszTmp = strchr(szLineBuf, ';'); lpszTmp = strchr(szLineBuf, ';');
if(lpszTmp != NULL) *lpszTmp = 0; if(lpszTmp != NULL) *lpszTmp = 0;
StrTrimAll(szLineBuf); //zl 2002.9.19 ";"和有用内容间必有空格或TAB字符,必须删除这些分割字符 StrTrimAll(szLineBuf); //zl 2002.9.19 ";"和有用内容间必有空格或TAB字符,必须删除这些分割字符
iPos = strlen(szLineBuf) - 1; iPos = strlen(szLineBuf) - 1;
if(szLineBuf[0] == '[' && szLineBuf[iPos] == ']') //该行是一个段 if(szLineBuf[0] == '[' && szLineBuf[iPos] == ']') //该行是一个段
{ {
szLineBuf[iPos] = 0; //去掉"["和"]",便于比较 szLineBuf[iPos] = 0; //去掉"["和"]",便于比较
lpszTmp = &szLineBuf[1]; lpszTmp = &szLineBuf[1];
if( strcmp(lpszTmp, lpszSectionName) == 0 ) //指定的段找到了 if( strcmp(lpszTmp, lpszSectionName) == 0 ) //指定的段找到了
{ {
bSecFoundFlag = TRUE; bSecFoundFlag = TRUE;
break; break;
@ -492,15 +492,15 @@ BOOL QWritePrivateProfileString(
} }
} }
//[情况一]:如果未找到指定段,则指定key肯定也不存在,因此即要新建section也要新建key, //[情况一]:如果未找到指定段,则指定key肯定也不存在,因此即要新建section也要新建key,
// 这些内容就直接追加到文件尾部,同时约定在文件尾部新建一个段时,默认在前面 // 这些内容就直接追加到文件尾部,同时约定在文件尾部新建一个段时,默认在前面
// 追加换行符号以确保和前面的其它内容不在一行 // 追加换行符号以确保和前面的其它内容不在一行
if( !bSecFoundFlag ) if( !bSecFoundFlag )
{ {
char szNewSection[2048]; char szNewSection[2048];
memset(szNewSection, 0, 2048); memset(szNewSection, 0, 2048);
//生成新的段字符串 //生成新的段字符串
sprintf(szNewSection, "%s[%s]%s%s = %s%s", szLineEndStr, lpszSectionName, szLineEndStr, lpszKeyName, lpszString, szLineEndStr); sprintf(szNewSection, "%s[%s]%s%s = %s%s", szLineEndStr, lpszSectionName, szLineEndStr, lpszKeyName, lpszString, szLineEndStr);
fseek(IniFile, 0, SEEK_END); fseek(IniFile, 0, SEEK_END);
@ -509,66 +509,66 @@ BOOL QWritePrivateProfileString(
goto func_end; goto func_end;
} }
//找到指定段后再继续找指定key //找到指定段后再继续找指定key
while(!feof(IniFile)) while(!feof(IniFile))
{ {
lPrePos = lCurPos; //保留上次文件指针位置 lPrePos = lCurPos; //保留上次文件指针位置
ReadLineFromFile(IniFile, szLineBuf, MAX_LINE_BUF_LENGTH); //读取一行 ReadLineFromFile(IniFile, szLineBuf, MAX_LINE_BUF_LENGTH); //读取一行
lCurPos = ftell(IniFile); //保留当前文件指针位置 lCurPos = ftell(IniFile); //保留当前文件指针位置
StrTrimAll(szLineBuf); StrTrimAll(szLineBuf);
if( szLineBuf[0] == ';' || szLineBuf[0] == 0 ) continue; //注释行和空行不处理 if( szLineBuf[0] == ';' || szLineBuf[0] == 0 ) continue; //注释行和空行不处理
//将一行尾部可能存在的";"注释部分剔除(这样key=value的value中不能含有;否则将被当成注释而删除 //将一行尾部可能存在的";"注释部分剔除(这样key=value的value中不能含有;否则将被当成注释而删除
lpszTmp = strchr(szLineBuf, ';'); lpszTmp = strchr(szLineBuf, ';');
if(lpszTmp != NULL) *lpszTmp = 0; if(lpszTmp != NULL) *lpszTmp = 0;
StrTrimAll(szLineBuf); //zl 2002.9.19 ";"和有用内容间必有空格或TAB字符,必须删除这些分割字符 StrTrimAll(szLineBuf); //zl 2002.9.19 ";"和有用内容间必有空格或TAB字符,必须删除这些分割字符
iPos = strlen(szLineBuf)-1; iPos = strlen(szLineBuf)-1;
if(szLineBuf[0] == '[' && szLineBuf[iPos] == ']') if(szLineBuf[0] == '[' && szLineBuf[iPos] == ']')
{ {
bMeetAnotherBlock = TRUE; //又到了一个段说明指定段下的指定key没有找到 bMeetAnotherBlock = TRUE; //又到了一个段说明指定段下的指定key没有找到
break; break;
} }
lpszTmp = strchr(szLineBuf, '='); //定位'=' lpszTmp = strchr(szLineBuf, '='); //定位'='
if(lpszTmp == NULL) continue; //不含等号的非段行被视为无效行 if(lpszTmp == NULL) continue; //不含等号的非段行被视为无效行
*lpszTmp = 0; //为便于操作,在'='位置将szLineBuf从中间截断, 将szLineBuf分成key和value两个部分 *lpszTmp = 0; //为便于操作,在'='位置将szLineBuf从中间截断, 将szLineBuf分成key和value两个部分
StrTrimAll(szLineBuf); //此时szLineBuf是key StrTrimAll(szLineBuf); //此时szLineBuf是key
/* 找到了指定key */ /* 找到了指定key */
if(strcmp(szLineBuf, lpszKeyName) == 0) //该比较大小写敏感 if(strcmp(szLineBuf, lpszKeyName) == 0) //该比较大小写敏感
{ {
char szKeyValBlock[2048]; char szKeyValBlock[2048];
memset(szKeyValBlock, 0, 2048); memset(szKeyValBlock, 0, 2048);
//重新组织key = value对实现修改目的 //重新组织key = value对实现修改目的
sprintf(szKeyValBlock, "%s = %s%s", szLineBuf, lpszString, szLineEndStr); sprintf(szKeyValBlock, "%s = %s%s", szLineBuf, lpszString, szLineEndStr);
//注意这里和下面的段前插入内容不同这里是要将原有的key=value对去掉 //注意这里和下面的段前插入内容不同这里是要将原有的key=value对去掉
//代之以新对,因此lPrePos和lCurPos之间的文件内容(即原有key=value对)不要, //代之以新对,因此lPrePos和lCurPos之间的文件内容(即原有key=value对)不要,
//该操作是替换而不是插入 //该操作是替换而不是插入
lpszRearBlock = new char[lEndPos-lCurPos+1]; lpszRearBlock = new char[lEndPos-lCurPos+1];
memset(lpszRearBlock, 0, lEndPos-lCurPos+1); memset(lpszRearBlock, 0, lEndPos-lCurPos+1);
fread(lpszRearBlock, sizeof(char), lEndPos-lCurPos, IniFile); //从当前位置开始读其后面的文件内容(长度为lEndPos-lCurPos, 注意lEndPos是end结尾符号的位置,等于文件长度,比最大有效文件指针位置大1) fread(lpszRearBlock, sizeof(char), lEndPos-lCurPos, IniFile); //从当前位置开始读其后面的文件内容(长度为lEndPos-lCurPos, 注意lEndPos是end结尾符号的位置,等于文件长度,比最大有效文件指针位置大1)
lpszFrontBlock = new char[lPrePos+1]; lpszFrontBlock = new char[lPrePos+1];
memset(lpszFrontBlock, 0, lPrePos+1); memset(lpszFrontBlock, 0, lPrePos+1);
fseek(IniFile, 0, SEEK_SET); fseek(IniFile, 0, SEEK_SET);
fread(lpszFrontBlock, sizeof(char), lPrePos, IniFile); //从头部开始读其后面的文件内容(长度为lPrePos,因为文件指针从0开始,lPrePos位置前的文件长度就是lPrePos) fread(lpszFrontBlock, sizeof(char), lPrePos, IniFile); //从头部开始读其后面的文件内容(长度为lPrePos,因为文件指针从0开始,lPrePos位置前的文件长度就是lPrePos)
//先关闭文件再用可写方式打开以清空原有内容,最后依次写文件的各个部分,如要不关闭 //先关闭文件再用可写方式打开以清空原有内容,最后依次写文件的各个部分,如要不关闭
//打开文件而是直接清空文件内容,因unix和windows中设置文件长度的调用不同,比较麻烦 //打开文件而是直接清空文件内容,因unix和windows中设置文件长度的调用不同,比较麻烦
fclose(IniFile); fclose(IniFile);
IniFile = fopen(lpszFileName, "wb"); //可写方式打开(如文件已存在,其所有内容被清空) IniFile = fopen(lpszFileName, "wb"); //可写方式打开(如文件已存在,其所有内容被清空)
if(!IniFile) return FALSE; if(!IniFile) return FALSE;
fwrite(lpszFrontBlock, sizeof(char), lPrePos, IniFile); fwrite(lpszFrontBlock, sizeof(char), lPrePos, IniFile);
@ -583,35 +583,35 @@ BOOL QWritePrivateProfileString(
} }
} }
//如果在指定段下未找到指定key,则要新建key=value对 //如果在指定段下未找到指定key,则要新建key=value对
if( !bKeyFoundFlag ) if( !bKeyFoundFlag )
{ {
char szKeyBlock[2048]; char szKeyBlock[2048];
memset(szKeyBlock, 0, 2048); memset(szKeyBlock, 0, 2048);
if(bMeetAnotherBlock) //遇到了另外一个段,此时要在该段前面插入新建的key=value对 if(bMeetAnotherBlock) //遇到了另外一个段,此时要在该段前面插入新建的key=value对
{ {
sprintf(szKeyBlock, "%s = %s%s", lpszKeyName, lpszString, szLineEndStr); sprintf(szKeyBlock, "%s = %s%s", lpszKeyName, lpszString, szLineEndStr);
//以下以lPrePos为界线将文件拆成两部分,和上面替换操作中lPrePos和lCurPos间内容 //以下以lPrePos为界线将文件拆成两部分,和上面替换操作中lPrePos和lCurPos间内容
//不要不同,这里是插入而不是替换, 因此直接以lPrePos为界将文件分开,进行插入操作 //不要不同,这里是插入而不是替换, 因此直接以lPrePos为界将文件分开,进行插入操作
fseek(IniFile, lPrePos, SEEK_SET); //定位到lPrePos(这里lPrePos是另一个段的开始字符,如"[") fseek(IniFile, lPrePos, SEEK_SET); //定位到lPrePos(这里lPrePos是另一个段的开始字符,如"[")
lpszRearBlock = new char[lEndPos-lPrePos+1]; lpszRearBlock = new char[lEndPos-lPrePos+1];
memset(lpszRearBlock, 0, lEndPos-lPrePos+1); memset(lpszRearBlock, 0, lEndPos-lPrePos+1);
fread(lpszRearBlock, sizeof(char), lEndPos-lPrePos, IniFile); //从当前位置开始读其后面的文件内容(长度为lEndPos-lPrePos) fread(lpszRearBlock, sizeof(char), lEndPos-lPrePos, IniFile); //从当前位置开始读其后面的文件内容(长度为lEndPos-lPrePos)
lpszFrontBlock = new char[lPrePos+1]; lpszFrontBlock = new char[lPrePos+1];
memset(lpszFrontBlock, 0, lPrePos+1); memset(lpszFrontBlock, 0, lPrePos+1);
fseek(IniFile, 0, SEEK_SET); fseek(IniFile, 0, SEEK_SET);
fread(lpszFrontBlock, sizeof(char), lPrePos, IniFile); //从头部开始读其后面的文件内容(长度为lPrePos) fread(lpszFrontBlock, sizeof(char), lPrePos, IniFile); //从头部开始读其后面的文件内容(长度为lPrePos)
//先关闭文件再用可写方式打开以清空原有内容,最后依次写文件的各个部分,如要不关闭 //先关闭文件再用可写方式打开以清空原有内容,最后依次写文件的各个部分,如要不关闭
//打开文件而是直接清空文件内容,因unix和windows中设置文件长度的调用不同,比较麻烦 //打开文件而是直接清空文件内容,因unix和windows中设置文件长度的调用不同,比较麻烦
fclose(IniFile); fclose(IniFile);
IniFile = fopen(lpszFileName, "wb"); //可写方式打开(如文件已存在,其所有内容被清空) IniFile = fopen(lpszFileName, "wb"); //可写方式打开(如文件已存在,其所有内容被清空)
if(!IniFile) return FALSE; if(!IniFile) return FALSE;
fwrite(lpszFrontBlock, sizeof(char), lPrePos, IniFile); fwrite(lpszFrontBlock, sizeof(char), lPrePos, IniFile);
@ -622,11 +622,11 @@ BOOL QWritePrivateProfileString(
delete [] lpszRearBlock; delete [] lpszRearBlock;
} }
else //如果连一个段都没有碰到,则肯定已到了文件尾部, 追加key=value块到尾部即可 else //如果连一个段都没有碰到,则肯定已到了文件尾部, 追加key=value块到尾部即可
{ {
fseek(IniFile, 0, SEEK_END); fseek(IniFile, 0, SEEK_END);
/* 如当前位置前已有换行符号则无需另行增加,此举可防止新增部分和上面一行连在一起 */ /* 如当前位置前已有换行符号则无需另行增加,此举可防止新增部分和上面一行连在一起 */
if( IfBeforeHasRet(IniFile) ) if( IfBeforeHasRet(IniFile) )
sprintf(szKeyBlock, "%s = %s%s", lpszKeyName, lpszString, szLineEndStr); sprintf(szKeyBlock, "%s = %s%s", lpszKeyName, lpszString, szLineEndStr);
else else
@ -642,7 +642,7 @@ func_end:
return true; return true;
} }
//辅助函数,判断文件中当前指针位置前面是否有换行符号,使用该函数前必须确保文件已经打开并将文件指针定位到应有的位置 //辅助函数,判断文件中当前指针位置前面是否有换行符号,使用该函数前必须确保文件已经打开并将文件指针定位到应有的位置
bool IfBeforeHasRet(FILE* pFile) bool IfBeforeHasRet(FILE* pFile)
{ {
char szTmp[3]; char szTmp[3];
@ -651,9 +651,9 @@ bool IfBeforeHasRet(FILE* pFile)
memset(szTmp, 0, 3); memset(szTmp, 0, 3);
lOldPos = ftell(pFile); //保存文件当前指针位置 lOldPos = ftell(pFile); //保存文件当前指针位置
/* 读当前位置前面的两个字节, 因为windows下是回车换行两个字节 */ /* 读当前位置前面的两个字节, 因为windows下是回车换行两个字节 */
fseek(pFile, -2, SEEK_CUR); fseek(pFile, -2, SEEK_CUR);
fread(szTmp, sizeof(char), 2, pFile); fread(szTmp, sizeof(char), 2, pFile);
@ -663,70 +663,70 @@ bool IfBeforeHasRet(FILE* pFile)
if( szTmp[0] == 0x0d && szTmp[1] == 0x0a ) bBeforeHasRet = TRUE; if( szTmp[0] == 0x0d && szTmp[1] == 0x0a ) bBeforeHasRet = TRUE;
#endif #endif
fseek(pFile, lOldPos, SEEK_SET); //恢复原先的文件指针位置 fseek(pFile, lOldPos, SEEK_SET); //恢复原先的文件指针位置
return bBeforeHasRet; return bBeforeHasRet;
} }
/*-----------------------------------工具函数----------------------------------*/ /*-----------------------------------工具函数----------------------------------*/
//从指定文件中读取一行 //从指定文件中读取一行
int ReadLineFromFile(FILE* IniFile, char* lpszLineBuf, int iLen) int ReadLineFromFile(FILE* IniFile, char* lpszLineBuf, int iLen)
{ {
int iPos; int iPos;
/*----------------------------------------------------------------------------- /*-----------------------------------------------------------------------------
ttextinput ttextinput
fgets()binary fgets()binary
fgets fgets
text text
binary binary
textbinary,WindowsUnix textbinary,WindowsUnix
(unix0A,) (unix0A,)
: fopen()"t"Ansi C "b" : fopen()"t"Ansi C "b"
----------------------------------------------------------------------------*/ ----------------------------------------------------------------------------*/
if(fgets(lpszLineBuf, iLen, IniFile) != NULL) //fgets()函数遇到第一个换行符(0x0A)后结束(包括换行符),然后在尾部追加一个NULL后返回,因此换行符总是倒数第二个字符 if(fgets(lpszLineBuf, iLen, IniFile) != NULL) //fgets()函数遇到第一个换行符(0x0A)后结束(包括换行符),然后在尾部追加一个NULL后返回,因此换行符总是倒数第二个字符
{ {
iPos = strlen(lpszLineBuf) - 1; iPos = strlen(lpszLineBuf) - 1;
if( lpszLineBuf[iPos-1] == 0x0D ) lpszLineBuf[iPos-1] = 0; //删除尾部可能存在的回车符(0x0D) if( lpszLineBuf[iPos-1] == 0x0D ) lpszLineBuf[iPos-1] = 0; //删除尾部可能存在的回车符(0x0D)
if( lpszLineBuf[iPos] == 0x0A ) lpszLineBuf[iPos] = 0; //删除尾部可能存在的换行符(0x0A) if( lpszLineBuf[iPos] == 0x0A ) lpszLineBuf[iPos] = 0; //删除尾部可能存在的换行符(0x0A)
} }
else else
return -1; return -1;
return 0; //0表示正确 return 0; //0表示正确
} }
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------
//从指定字符串中读取一行 //从指定字符串中读取一行
int ReadLineFromString(char* lpszText, char* lpszLineBuf, int iLen) int ReadLineFromString(char* lpszText, char* lpszLineBuf, int iLen)
{ {
int iPos; int iPos;
if(fgets(lpszLineBuf, iLen, IniFile) != NULL) //fgets()函数遇到第一个换行符(0x0A)后结束(包括换行符),然后在尾部追加一个NULL后返回,因此换行符总是倒数第二个字符 if(fgets(lpszLineBuf, iLen, IniFile) != NULL) //fgets()函数遇到第一个换行符(0x0A)后结束(包括换行符),然后在尾部追加一个NULL后返回,因此换行符总是倒数第二个字符
{ {
iPos = strlen(lpszLineBuf) - 1; iPos = strlen(lpszLineBuf) - 1;
if( lpszLineBuf[iPos-1] == 0x0D ) lpszLineBuf[iPos-1] = 0; //删除尾部可能存在的回车符(0x0D) if( lpszLineBuf[iPos-1] == 0x0D ) lpszLineBuf[iPos-1] = 0; //删除尾部可能存在的回车符(0x0D)
if( lpszLineBuf[iPos] == 0x0A ) lpszLineBuf[iPos] = 0; //删除尾部可能存在的换行符(0x0A) if( lpszLineBuf[iPos] == 0x0A ) lpszLineBuf[iPos] = 0; //删除尾部可能存在的换行符(0x0A)
} }
else else
return -1; return -1;
return 0; //0表示正确 return 0; //0表示正确
} }
---------------------------------------------------------------------------*/ ---------------------------------------------------------------------------*/
//删除字符串的左侧空格, 2002.9.19增加删除TAB字符(ASC码为9)功能 //删除字符串的左侧空格, 2002.9.19增加删除TAB字符(ASC码为9)功能
void StrTrimLeft(char* szBuf) void StrTrimLeft(char* szBuf)
{ {
char *szBak = NULL; char *szBak = NULL;
@ -736,20 +736,20 @@ void StrTrimLeft(char* szBuf)
while(*p == ' ' || *p == 9) { p++; } while(*p == ' ' || *p == 9) { p++; }
//qDebug("StrtrimLeft:p=%s",p); //qDebug("StrtrimLeft:p=%s",p);
if(p != szBuf) //头部有空格或TAB字符 if(p != szBuf) //头部有空格或TAB字符
{ {
szBak = _strdup(p); //strcpy()中如source和dest重合(overlap)则copy结果不可预料故另设一个缓冲区临时存放这个头部没有空格的字符串 szBak = _strdup(p); //strcpy()中如source和dest重合(overlap)则copy结果不可预料故另设一个缓冲区临时存放这个头部没有空格的字符串
strcpy(szBuf, szBak); //strcpy()肯定不会溢出因p是szBuf的一个子集同时strcpy会拷贝结尾的null因此无须人工截断szBuf strcpy(szBuf, szBak); //strcpy()肯定不会溢出因p是szBuf的一个子集同时strcpy会拷贝结尾的null因此无须人工截断szBuf
free(szBak); free(szBak);
} }
} }
//删除字符串的右侧空格, 2002.9.19增加删除TAB字符(ASC码为9)功能 //删除字符串的右侧空格, 2002.9.19增加删除TAB字符(ASC码为9)功能
void StrTrimRight(char* szBuf) void StrTrimRight(char* szBuf)
{ {
char *szBak = NULL; char *szBak = NULL;
int iPos = strlen(szBuf)-1; //最后一个非NULL字符的下标 int iPos = strlen(szBuf)-1; //最后一个非NULL字符的下标
if(!szBuf) return; if(!szBuf) return;
@ -757,30 +757,30 @@ void StrTrimRight(char* szBuf)
while(*p == ' ' || *p == 9) { p--; } while(*p == ' ' || *p == 9) { p--; }
if(p != &szBuf[iPos]) //尾部有空格 if(p != &szBuf[iPos]) //尾部有空格
{ {
p++; p++;
*p = 0; //直接尾部截断,比删除头部空格还简单 *p = 0; //直接尾部截断,比删除头部空格还简单
} }
} }
//删除左右两边所有空格 //删除左右两边所有空格
void StrTrimAll(char* szBuf) void StrTrimAll(char* szBuf)
{ {
StrTrimRight(szBuf); StrTrimRight(szBuf);
StrTrimLeft(szBuf); StrTrimLeft(szBuf);
} }
//获取指定文件的长度 //获取指定文件的长度
i_32 GetFileSize(char* lpszFileName) i_32 GetFileSize(char* lpszFileName)
{ {
FILE* pFile; FILE* pFile;
pFile = fopen(lpszFileName, "rb"); //二进制方式 pFile = fopen(lpszFileName, "rb"); //二进制方式
if(pFile == NULL) return -1; if(pFile == NULL) return -1;
fseek(pFile, 0, SEEK_END); //定位到文件尾部 fseek(pFile, 0, SEEK_END); //定位到文件尾部
i_32 lFileSize = ftell(pFile); //获取文件指针当前位置(此时文件指针指向EOF结束标志)[文件指针是从0开始计数的] i_32 lFileSize = ftell(pFile); //获取文件指针当前位置(此时文件指针指向EOF结束标志)[文件指针是从0开始计数的]
fclose(pFile); fclose(pFile);

@ -162,6 +162,30 @@ Inifile.cpp.s:
$(MAKE) -f CMakeFiles/iec103.dir/build.make CMakeFiles/iec103.dir/Inifile.cpp.s $(MAKE) -f CMakeFiles/iec103.dir/build.make CMakeFiles/iec103.dir/Inifile.cpp.s
.PHONY : Inifile.cpp.s .PHONY : Inifile.cpp.s
MySQLAdo.o: MySQLAdo.cpp.o
.PHONY : MySQLAdo.o
# target to build an object file
MySQLAdo.cpp.o:
$(MAKE) -f CMakeFiles/iec103.dir/build.make CMakeFiles/iec103.dir/MySQLAdo.cpp.o
.PHONY : MySQLAdo.cpp.o
MySQLAdo.i: MySQLAdo.cpp.i
.PHONY : MySQLAdo.i
# target to preprocess a source file
MySQLAdo.cpp.i:
$(MAKE) -f CMakeFiles/iec103.dir/build.make CMakeFiles/iec103.dir/MySQLAdo.cpp.i
.PHONY : MySQLAdo.cpp.i
MySQLAdo.s: MySQLAdo.cpp.s
.PHONY : MySQLAdo.s
# target to generate assembly for a file
MySQLAdo.cpp.s:
$(MAKE) -f CMakeFiles/iec103.dir/build.make CMakeFiles/iec103.dir/MySQLAdo.cpp.s
.PHONY : MySQLAdo.cpp.s
Profile_Hash.o: Profile_Hash.cpp.o Profile_Hash.o: Profile_Hash.cpp.o
.PHONY : Profile_Hash.o .PHONY : Profile_Hash.o
@ -561,6 +585,9 @@ help:
@echo "... Inifile.o" @echo "... Inifile.o"
@echo "... Inifile.i" @echo "... Inifile.i"
@echo "... Inifile.s" @echo "... Inifile.s"
@echo "... MySQLAdo.o"
@echo "... MySQLAdo.i"
@echo "... MySQLAdo.s"
@echo "... Profile_Hash.o" @echo "... Profile_Hash.o"
@echo "... Profile_Hash.i" @echo "... Profile_Hash.i"
@echo "... Profile_Hash.s" @echo "... Profile_Hash.s"

@ -3,7 +3,11 @@
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <string>
#include <time.h> #include <time.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std; using namespace std;
#ifdef USING_MYSQL #ifdef USING_MYSQL
@ -152,7 +156,7 @@ bool InitDatabase(int argc, char **argv, const char* host, const char* username,
} }
mysql_query(mysql, "SET NAMES utf8"); mysql_query(mysql, "SET NAMES utf8");
return true; return LoadIecPoints();
#else #else
return true; return true;
#endif // USING_MYSQL #endif // USING_MYSQL
@ -183,8 +187,8 @@ bool PingDatabase()
#ifdef USING_MYSQL #ifdef USING_MYSQL
bool LoadIecPoints() bool LoadIecPoints()
{ {
// const char* sql = "SELECT t1.`id`,t1.`site_id`,t1.`sensor_id`,t2.sensor_code,t2.grp_no FROM iec_points AS t1 LEFT JOIN iec_sensors AS t2 t1.sensor_id=t2.`id` WHERE t1.`status`=1 AND t2.`status`=1 ORDER BY t1.site_id,t2.sadr"; // const char* sql = "SELECT t1.`id`,t1.sadr,t1.`site_id`,t1.`sensor_id`,t1.item_no,t2.sensor_code,t2.grp_no FROM iec_points AS t1 LEFT JOIN iec_sensors AS t2 ON t1.sensor_id=t2.`id` WHERE t1.`status`=1 AND t2.`status`=1 ORDER BY t1.site_id,t1.sadr";
const char* sql = "SELECT t1.`id`,t1.`site_id`,t1.`sensor_id`,t2.sensor_code,t2.grp_no FROM niec_points AS t1 LEFT JOIN niec_sensors AS t2 t1.sensor_id=t2.`id` WHERE t1.`status`=1 AND t2.`status`=1 ORDER BY t1.site_id,t2.sadr"; const char* sql = "SELECT t1.`id`,t1.sadr,t1.`site_id`,t1.`sensor_id`,t1.item_no,t2.sensor_code,t2.grp_no FROM niec_points AS t1 LEFT JOIN niec_sensors AS t2 ON t1.sensor_id=t2.`id` WHERE t1.`status`=1 AND t2.`status`=1 ORDER BY t1.site_id,t1.sadr";
if (mysql_query(mysql, sql)) if (mysql_query(mysql, sql))
{ {
@ -208,8 +212,9 @@ bool LoadIecPoints()
// t1.`id`,t1.`site_id`,t1.`sensor_id`,t2.sensor_code,t2.grp_no // t1.`id`,t1.`site_id`,t1.`sensor_id`,t2.sensor_code,t2.grp_no
pt.sadr = strtoul(row[fieldIdx++], NULL, 10); pt.sadr = strtoul(row[fieldIdx++], NULL, 10);
pt.siteId = strtoul(row[fieldIdx++], NULL, 10); pt.siteId = strtoul(row[fieldIdx++], NULL, 10);
fieldIdx++; // sensor code 17位编码
pt.sensorId = strtoul(row[fieldIdx++], NULL, 10); pt.sensorId = strtoul(row[fieldIdx++], NULL, 10);
pt.itemNo = strtoul(row[fieldIdx++], NULL, 10);
fieldIdx++; // sensor code 17位编码
pt.sensorGroupNo = strtoul(row[fieldIdx++], NULL, 10); pt.sensorGroupNo = strtoul(row[fieldIdx++], NULL, 10);
g_iec_points.push_back(pt); g_iec_points.push_back(pt);
@ -238,12 +243,16 @@ int GetAIPntMsg(int j, unsigned int *igno, unsigned int* iItemNo, DAY_TIME* sCur
const IEC_POINT_TABLE& pt = g_iec_points[j]; const IEC_POINT_TABLE& pt = g_iec_points[j];
if (PingDatabase()) if (!PingDatabase())
{ {
return -1; return -1;
} }
std::string sql = "SELECT sadr,state,stype,ival,fval,d_time FROM niec_origin_data WHERE sadr=" + std::to_string(pt.sadr) + " ORDER BY `id` DESC LIMIT 1"; char buf[16] = { 0 };
sprintf(buf, "%u", pt.sadr);
std::string sql = "SELECT sadr,state,stype,ival,fval,d_time FROM niec_origin_data WHERE sadr=";
sql += buf;
sql += " ORDER BY `id` DESC LIMIT 1";
if (mysql_query(mysql, sql.c_str())) if (mysql_query(mysql, sql.c_str()))
{ {
@ -263,7 +272,7 @@ int GetAIPntMsg(int j, unsigned int *igno, unsigned int* iItemNo, DAY_TIME* sCur
{ {
if (igno != NULL) *igno = pt.sensorGroupNo; if (igno != NULL) *igno = pt.sensorGroupNo;
if (iItemNo != NULL) *iItemNo = pt.itemNo; if (iItemNo != NULL) *iItemNo = pt.itemNo;
if (iaddr != NULL) *iaddr = pt.sadr; if (iaddr != NULL) *iaddr = pt.sensorId;
if (pfValue != NULL) *pfValue = atof(row[4]); if (pfValue != NULL) *pfValue = atof(row[4]);
if (sCurTime != NULL && row[5] != NULL) if (sCurTime != NULL && row[5] != NULL)
{ {

@ -17,9 +17,9 @@ struct IEC_POINT_TABLE
unsigned int sadr; unsigned int sadr;
unsigned int siteId; unsigned int siteId;
unsigned int sensorId; unsigned int sensorId;
unsigned int sensorGroupNo; unsigned char sensorGroupNo;
unsigned char stype; // 1: 1:遥信 2:遥测 unsigned char stype; // 1: 1:遥信 2:遥测
unsigned int itemNo; unsigned char itemNo;
}; };
extern std::vector<IEC_POINT_TABLE> g_iec_points; extern std::vector<IEC_POINT_TABLE> g_iec_points;
@ -44,10 +44,10 @@ inline void BindValue(MYSQL_BIND& bind, const char* value, unsigned long& len);
bool InitDatabase(int argc, char **argv, const char* host, const char* username, const char* password, const char* database); bool InitDatabase(int argc, char **argv, const char* host, const char* username, const char* password, const char* database);
bool UninitDatabase(); bool UninitDatabase();
/* /*
1: 1:
0: 0:
-1: -1:
*/ */
int GetAIPntMsg(int j, unsigned int *igno, unsigned int* iItemNo, DAY_TIME* sCurTime, float* pfValue, unsigned int *iaddr); int GetAIPntMsg(int j, unsigned int *igno, unsigned int* iItemNo, DAY_TIME* sCurTime, float* pfValue, unsigned int *iaddr);

File diff suppressed because it is too large Load Diff

@ -1,8 +1,8 @@
/****************************************************************************************** /******************************************************************************************
* *
* : m.j.y * : m.j.y
* *
* Pgc-- * Pgc--
* *
* $Log: Profile_Hash.h,v $ * $Log: Profile_Hash.h,v $
* Revision 1.2 2006/08/04 03:37:33 zhuzhenhua * Revision 1.2 2006/08/04 03:37:33 zhuzhenhua
@ -12,10 +12,10 @@
* no message * no message
* *
* Revision 1.4 2003/07/14 01:56:23 scada * Revision 1.4 2003/07/14 01:56:23 scada
* 使def * 使def
* *
* Revision 1.3 2003/06/05 03:56:16 jehu * Revision 1.3 2003/06/05 03:56:16 jehu
* doxgen * doxgen
* *
* Revision 1.2 2002/12/04 07:47:36 scada * Revision 1.2 2002/12/04 07:47:36 scada
* for NT * for NT
@ -24,7 +24,7 @@
* temporarily import * temporarily import
* *
* Revision 1.14 2002/06/03 10:07:04 mhorse * Revision 1.14 2002/06/03 10:07:04 mhorse
* *
* *
* Revision 1.13 2002/03/20 03:40:02 harold * Revision 1.13 2002/03/20 03:40:02 harold
* no message * no message
@ -78,11 +78,11 @@
* \if developer_doc * \if developer_doc
* \file * \file
* *
* \brief Pgc-- * \brief Pgc--
* *
* id: $Id: Profile_Hash.h,v 1.2 2006/08/04 03:37:33 zhuzhenhua Exp $ * id: $Id: Profile_Hash.h,v 1.2 2006/08/04 03:37:33 zhuzhenhua Exp $
* *
* \author prcharold@sina.com.cn develop1@szscada.com * \author prcharold@sina.com.cn develop1@szscada.com
* \endif * \endif
*/ */
@ -109,10 +109,10 @@
*/ */
/*! /*!
* , * ,
*/ */
#define MAX_CONF_LINE_L (1024) #define MAX_CONF_LINE_L (1024)
//!< 定义每行(注释行的字符个数无限制)允许的最大字符个数, 包括换行符号'\r\n'及null字符 //!< 定义每行(注释行的字符个数无限制)允许的最大字符个数, 包括换行符号'\r\n'及null字符
#define MAX_CHAR_LINE (MAX_CONF_LINE_L) #define MAX_CHAR_LINE (MAX_CONF_LINE_L)
#ifndef PATH_MAX #ifndef PATH_MAX
@ -120,38 +120,38 @@
#endif #endif
#define MAX_PATH 260 #define MAX_PATH 260
//!< 定义存储文件路径的字符串数组的大小 //!< 定义存储文件路径的字符串数组的大小
#define MAX_PATH_NUM (MAX_PATH) #define MAX_PATH_NUM (MAX_PATH)
//在重新生成配置文件时,是否将'\r\n'作为行结束标志 //在重新生成配置文件时,是否将'\r\n'作为行结束标志
//#define REWRITEFILE_ADDCHAR_13 //#define REWRITEFILE_ADDCHAR_13
//!< 设置缓冲区的最大段数 //!< 设置缓冲区的最大段数
#define MAX_SEC_NUM 2500 #define MAX_SEC_NUM 2500
//!< 设置缓冲区的每一段的最大项目个数 //!< 设置缓冲区的每一段的最大项目个数
#define MAX_ITEM_NUM 30 #define MAX_ITEM_NUM 30
//!< 定义初始化缓冲区容纳项目的个数 //!< 定义初始化缓冲区容纳项目的个数
#define INITCACHE_ITEM_NUM 5000 #define INITCACHE_ITEM_NUM 5000
//!< 缓冲区增大时的递增项目的个数 //!< 缓冲区增大时的递增项目的个数
#define RESIZE_ITEM_NUM 5000 #define RESIZE_ITEM_NUM 5000
//!< 定义在一个进程中允许同时打开的配置文件缓冲句柄的个数 //!< 定义在一个进程中允许同时打开的配置文件缓冲句柄的个数
#define MAX_PROFILEHANDLE_NUM 50 #define MAX_PROFILEHANDLE_NUM 50
//!< 定义配置文件缓冲句柄 //!< 定义配置文件缓冲句柄
typedef pgc32 HPROFILE; typedef pgc32 HPROFILE;
//!< 保存注释的链表 //!< 保存注释的链表
typedef struct tagMemoChain typedef struct tagMemoChain
{ {
pgcchar *szMemo; pgcchar *szMemo;
tagMemoChain * NextNode; tagMemoChain * NextNode;
} SMemoChain; } SMemoChain;
//!< 缓冲项的结构 //!< 缓冲项的结构
typedef struct tagItemInCache typedef struct tagItemInCache
{ {
pgcchar szItemName[MAX_CHAR_LINE]; pgcchar szItemName[MAX_CHAR_LINE];
@ -166,7 +166,7 @@ typedef struct tagItemInCache
} }
} SItemInCache; } SItemInCache;
//!< 项目位置链表结构 //!< 项目位置链表结构
typedef struct tagItemSequence typedef struct tagItemSequence
{ {
pgc32 iPos; pgc32 iPos;
@ -177,29 +177,29 @@ typedef struct tagItemSequence
} }
} SItemSequence; } SItemSequence;
//!< 定义存储句柄对应的信息的结构 //!< 定义存储句柄对应的信息的结构
typedef struct tagProfileHanleInfo typedef struct tagProfileHanleInfo
{ {
FILE *fstream; FILE *fstream;
//!< 保存配置文件全路径名 //!< 保存配置文件全路径名
pgcchar szPathName[MAX_PATH_NUM]; pgcchar szPathName[MAX_PATH_NUM];
//!< 配置文件上一次被修改的时间 //!< 配置文件上一次被修改的时间
timeval tLastModify; timeval tLastModify;
//!< 哈希表指针 //!< 哈希表指针
TChainHash<SItemInCache> *pHashTable; TChainHash<SItemInCache> *pHashTable;
//!< 行位置链表头指针 //!< 行位置链表头指针
SItemSequence *pSequence; SItemSequence *pSequence;
//!< 行位置链表当前指针 //!< 行位置链表当前指针
SItemSequence *pCurSeq; SItemSequence *pCurSeq;
//!< 缓冲区数组入口 //!< 缓冲区数组入口
SItemInCache* pCacheEntry; SItemInCache* pCacheEntry;
//!< 段总数 //!< 段总数
pgc32 CurSecNum; pgc32 CurSecNum;
//!< 当前缓冲区能容纳的项目个数 //!< 当前缓冲区能容纳的项目个数
pgc32 CurItemCount; pgc32 CurItemCount;
//!< 已经使用的项目个数 //!< 已经使用的项目个数
pgc32 CurUseItems; pgc32 CurUseItems;
//!< 当前文件中的行数 //!< 当前文件中的行数
pgc32 CurLines; pgc32 CurLines;
tagProfileHanleInfo() tagProfileHanleInfo()
{ {
@ -208,14 +208,14 @@ typedef struct tagProfileHanleInfo
} SProfileHanleInfo; } SProfileHanleInfo;
/*! /*!
* \brief , . * \brief , .
* *
* \param pindex --[in] * \param pindex --[in]
* \param count --[in] pindex, pindex[0] -- pindex[count - 1] * \param count --[in] pindex, pindex[0] -- pindex[count - 1]
* \param pphash_of_index --[in] pindex, , , 使. * \param pphash_of_index --[in] pindex, , , 使.
* *
* \retval SUCCESS -- * \retval SUCCESS --
* \retval -- * \retval --
* *
*/ */
pgc32 profile_build_hash_index ( SItemInCache * pindex, pgc32 profile_build_hash_index ( SItemInCache * pindex,
@ -224,15 +224,15 @@ pgc32 profile_build_hash_index ( SItemInCache * pindex,
/*! /*!
* \brief * \brief
* *
* \param pindex_base --[in] * \param pindex_base --[in]
* \param phash_of_index --[in] * \param phash_of_index --[in]
* \param szSecName --[in] * \param szSecName --[in]
* \param szItemName --[in] * \param szItemName --[in]
* *
* \retval -- * \retval --
* \retval -1 -- * \retval -1 --
*/ */
pgc32 profile_search_sequence ( SItemInCache **pindex_base, pgc32 profile_search_sequence ( SItemInCache **pindex_base,
TChainHash<SItemInCache> *phash_of_index, TChainHash<SItemInCache> *phash_of_index,
@ -241,159 +241,159 @@ pgc32 profile_search_sequence ( SItemInCache **pindex_base,
/*! /*!
* \brief * \brief
* *
* \param szLine --[in] * \param szLine --[in]
* *
* \retval PGCTRUE * \retval PGCTRUE
* \retval PGCFALSE * \retval PGCFALSE
*/ */
PGCBOOL LineIsMark(pgcchar *szLine); PGCBOOL LineIsMark(pgcchar *szLine);
/*! /*!
* \brief * \brief
* *
* \param szString --[in] * \param szString --[in]
* *
* \retval * \retval
* \retval NULL * \retval NULL
*/ */
pgcchar* FindSecTail(pgcchar *szString); pgcchar* FindSecTail(pgcchar *szString);
/*! /*!
* \brief * \brief
* *
* \param szString --[in] * \param szString --[in]
* \param szRevBuffer --[out] * \param szRevBuffer --[out]
* \param iBufferLength --[in] * \param iBufferLength --[in]
* *
* \retval PGCTRUE * \retval PGCTRUE
* \retval PGCFALSE * \retval PGCFALSE
*/ */
PGCBOOL DigSecName(const pgcchar *szString, pgcchar *szRevBuffer, pgc32 iBufferLength); PGCBOOL DigSecName(const pgcchar *szString, pgcchar *szRevBuffer, pgc32 iBufferLength);
/*! /*!
* \brief * \brief
* *
* \param szString --[in] * \param szString --[in]
* \param szItemName --[in] * \param szItemName --[in]
* \param szItemVal --[out] * \param szItemVal --[out]
* \param iBufferLength --[in] * \param iBufferLength --[in]
* *
* \retval PGCTRUE * \retval PGCTRUE
* \retval PGCFALSE * \retval PGCFALSE
*/ */
PGCBOOL DigItemContent( pgcchar *szString, pgcchar *szItemName, pgcchar *szItemVal, pgc32 iBufferLength); PGCBOOL DigItemContent( pgcchar *szString, pgcchar *szItemName, pgcchar *szItemVal, pgc32 iBufferLength);
/*! /*!
* \brief * \brief
* *
* \param psHead --[in] * \param psHead --[in]
* \param iPos --[in] * \param iPos --[in]
* *
* \retval PGCTRUE * \retval PGCTRUE
* \retval PGCFALSE * \retval PGCFALSE
*/ */
PGCBOOL AddNode(SItemSequence * &psHead, pgc32 iPos); PGCBOOL AddNode(SItemSequence * &psHead, pgc32 iPos);
/*! /*!
* \brief * \brief
* *
* \param hProfile --[in] * \param hProfile --[in]
*/ */
void ReleaseProfileCache(HPROFILE hProfile); void ReleaseProfileCache(HPROFILE hProfile);
/*! /*!
* \brief * \brief
* *
* \param hProfile --[in] * \param hProfile --[in]
* *
* \retval SUCCESS * \retval SUCCESS
* \retval * \retval
*/ */
pgc32 ReWriteProfile(HPROFILE hProfile); pgc32 ReWriteProfile(HPROFILE hProfile);
/*! /*!
* \brief * \brief
* *
* \param hProfile --[in] * \param hProfile --[in]
* *
* \retval SUCCESS * \retval SUCCESS
* \retval * \retval
*/ */
pgc32 ProcessCreateCache(HPROFILE hProfile); pgc32 ProcessCreateCache(HPROFILE hProfile);
//----------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------
/*! /*!
*\verbatim *\verbatim
//以下为应用接口 //以下为应用接口
****************************************************************************************** ******************************************************************************************
* *
* : m.j.y * : m.j.y
* *
* Pgc--使 * Pgc--使
* *
****************************************************************************************** ******************************************************************************************
*\endverbaim *\endverbaim
*/ */
/*! /*!
* \brief * \brief
* *
* \param szProfileName --[in] * \param szProfileName --[in]
* \param phfile --[out] * \param phfile --[out]
* *
* \retval SUCCESS -- * \retval SUCCESS --
* \retval * \retval
* \retval ERROR_CONF_NOHANDLE -- * \retval ERROR_CONF_NOHANDLE --
* \retval ERROR_FOPEN -- * \retval ERROR_FOPEN --
* \retval ERROR_FREAD -- * \retval ERROR_FREAD --
* \retval ERROR_CONF_CREATEHASH -- * \retval ERROR_CONF_CREATEHASH --
* \retval ERROR_MEMORY_ALLOC -- * \retval ERROR_MEMORY_ALLOC --
*/ */
int create_profile_cache(pgcchar *szProfileName, int *phfile); int create_profile_cache(pgcchar *szProfileName, int *phfile);
/*! /*!
* \brief * \brief
* *
* . * .
* *
* \param hProfile --[in] * \param hProfile --[in]
* *
* \retval SUCCESS -- * \retval SUCCESS --
* \retval * \retval
* \retval ERROR_CONF_INVALIDHANDLE -- * \retval ERROR_CONF_INVALIDHANDLE --
*/ */
int close_profile_handle(HPROFILE hProfile); int close_profile_handle(HPROFILE hProfile);
/*! /*!
* \brief * \brief
* *
* :lpAppName lpKeyName * :lpAppName lpKeyName
* lpReturnedString * lpReturnedString
* (pdwSize) * (pdwSize)
* ('\0')pdwSize * ('\0')pdwSize
* lpDefault lpReturnedString; * lpDefault lpReturnedString;
* lpReturnedString1 * lpReturnedString1
* ('\0')pdwSize * ('\0')pdwSize
* *
* \param lpAppName --[in] * \param lpAppName --[in]
* \param lpDefault --[in] lpReturnedString * \param lpDefault --[in] lpReturnedString
* \param lpReturnedString --[out] * \param lpReturnedString --[out]
* \param pdwSize --[in][out] ('\0') * \param pdwSize --[in][out] ('\0')
* \param hProfile --[in] * \param hProfile --[in]
* *
* \retval SUCCESS -- lpReturnedString * \retval SUCCESS -- lpReturnedString
* SUCCESS * SUCCESS
* \retval ERROR_CONF_REVBUFFER -- ,, * \retval ERROR_CONF_REVBUFFER -- ,,
* ERROR_CONF_REVBUFFER * ERROR_CONF_REVBUFFER
* \retval SUCCESS_CONF_DEFCOPY -- lpDefaultlpDefaultlpReturnedString * \retval SUCCESS_CONF_DEFCOPY -- lpDefaultlpDefaultlpReturnedString
* lpDefaultlpDefault [ 1] * lpDefaultlpDefault [ 1]
* \retval ERROR_CONF_INVALIDHANDLE -- * \retval ERROR_CONF_INVALIDHANDLE --
* \retval ERROR_FAIL -- * \retval ERROR_FAIL --
*/ */
int get_pgcprofile_string( int get_pgcprofile_string(
const pgcchar * lpAppName, // points to section name const pgcchar * lpAppName, // points to section name
@ -405,26 +405,26 @@ int get_pgcprofile_string(
); );
/*! /*!
* \brief * \brief
* *
* : lpAppName lpKeyName * : lpAppName lpKeyName
* lpString * lpString
* , * ,
* SUCCESS;bInsertItem * SUCCESS;bInsertItem
* bInsertItem * bInsertItem
* SUCCESS; bInsertItemERROR_FAIL * SUCCESS; bInsertItemERROR_FAIL
* *
* \param lpAppName --[in] * \param lpAppName --[in]
* \param lpKeyName --[in] * \param lpKeyName --[in]
* \param lpString --[in] * \param lpString --[in]
* \param hProfile --[in] * \param hProfile --[in]
* \param bInsertItem --[in] PGCTRUE-PGCFALSE- * \param bInsertItem --[in] PGCTRUE-PGCFALSE-
* *
* \retval SUCCESS(0) -- lpString * \retval SUCCESS(0) -- lpString
* ,SUCCESS * ,SUCCESS
* \retval ERROR_FWRITE -- * \retval ERROR_FWRITE --
* \retval ERROR_CONF_INVALIDHANDLE -- * \retval ERROR_CONF_INVALIDHANDLE --
* \retval ERROR_FAIL -- * \retval ERROR_FAIL --
*/ */
int write_pgcprofile_string( int write_pgcprofile_string(
const pgcchar * lpAppName, // point to section name const pgcchar * lpAppName, // point to section name
@ -435,19 +435,19 @@ int write_pgcprofile_string(
); );
/*! /*!
* \brief * \brief
* *
* pdwSize * pdwSize
* *
* 1\02\0......\0\0 * 1\02\0......\0\0
* *
* \param lpszReturnBuffer --[out] * \param lpszReturnBuffer --[out]
* \param pdwSize --[in][out] * \param pdwSize --[in][out]
* \param nSecNum --[out] * \param nSecNum --[out]
* \param hProfile --[in] handle to Profile Cache * \param hProfile --[in] handle to Profile Cache
* *
* \retval SUCCESS -- * \retval SUCCESS --
* \retval -- * \retval --
*/ */
int get_pgcprofile_secnames( int get_pgcprofile_secnames(
pgcchar * lpszReturnBuffer, // address of return buffer pgcchar * lpszReturnBuffer, // address of return buffer
@ -457,16 +457,16 @@ int get_pgcprofile_secnames(
); );
/*! /*!
* \brief * \brief
* *
* *
* *
* \param lpAppName --[in] * \param lpAppName --[in]
* \param lpKeyName --[in] * \param lpKeyName --[in]
* \param hProfile --[in] * \param hProfile --[in]
* *
* \retval SUCCESS -- * \retval SUCCESS --
* \retval -- * \retval --
*/ */
int del_pgcprofile_key( const pgcchar * lpAppName, // point to section name int del_pgcprofile_key( const pgcchar * lpAppName, // point to section name
const pgcchar * lpKeyName, // point to key name const pgcchar * lpKeyName, // point to key name
@ -474,31 +474,31 @@ int del_pgcprofile_key( const pgcchar * lpAppName, // point to section name
); );
/*! /*!
* \brief * \brief
* *
* *
* *
* *
* \param lpAppName --[in] * \param lpAppName --[in]
* \param hProfile --[in] * \param hProfile --[in]
* *
* \retval SUCCESS -- * \retval SUCCESS --
* \retval -- * \retval --
*/ */
int del_pgcprofile_sec( const pgcchar * lpAppName, int del_pgcprofile_sec( const pgcchar * lpAppName,
HPROFILE hProfile HPROFILE hProfile
); );
/*! /*!
* \brief , * \brief ,
* *
* \param ptv1 --[in] 1 * \param ptv1 --[in] 1
* \param ptv2 --[in] 2 * \param ptv2 --[in] 2
* \param ptv_abs_delta --[out] , 0. * \param ptv_abs_delta --[out] , 0.
* *
* \retval 0 -- ptv1 () ptv2 * \retval 0 -- ptv1 () ptv2
* \retval 0 -- ptv1 () ptv2 * \retval 0 -- ptv1 () ptv2
* \retval 0 -- ptv1 () ptv2 * \retval 0 -- ptv1 () ptv2
*/ */
int timeval_compare ( int timeval_compare (
const timeval * ptv1, const timeval * ptv1,

@ -3,7 +3,7 @@
#include "common.h" #include "common.h"
// 设备信息定义 // 设备信息定义
#define DEVIVE_NAME "CAC-SERVER" #define DEVIVE_NAME "CAC-SERVER"
#define VERSION "V1.00" #define VERSION "V1.00"
#define VERSION_DATE "2023-11-10" #define VERSION_DATE "2023-11-10"
@ -33,7 +33,7 @@ extern DAY_TIME DayTime;
void ByPassRecvData( int commid, u_char *buf, int len ); void ByPassRecvData( int commid, u_char *buf, int len );
void WatchPortRecvData( void ); void WatchPortRecvData( void );
// 从 config.ini 或 portconfig.ini 读信息 // 从 config.ini 或 portconfig.ini 读信息
u_long GetPrivateProString( char * section, char * entry, char * deflautstr, char * reslut,int len, char *inifile ); u_long GetPrivateProString( char * section, char * entry, char * deflautstr, char * reslut,int len, char *inifile );
u_long atoul( u_char *buf ); u_long atoul( u_char *buf );
@ -51,7 +51,7 @@ void PortMemeryMalloc( int port, int type );
void YkYtCommandProcess( int port, u_char *buf, int len ); void YkYtCommandProcess( int port, u_char *buf, int len );
// 读设备信息,检查芯片状态和读芯片类型和频率 // 读设备信息,检查芯片状态和读芯片类型和频率
void ReadPortConfigInfo( u_short netport ); void ReadPortConfigInfo( u_short netport );
#ifdef OS_WINDOWS #ifdef OS_WINDOWS

@ -338,9 +338,9 @@ double SequenceHostToRtudouble(double dbValue)
} }
//******************************************************************** //********************************************************************
//* 获取系统时间函数 * //* 获取系统时间函数 *
//*参数: DAY_TIME : 系统时间缓冲区 * //*参数: DAY_TIME : 系统时间缓冲区 *
//*返回值BOOL retval : 是否成功 * //*返回值BOOL retval : 是否成功 *
//******************************************************************** //********************************************************************
BOOL GetLocalTimeEx(DAY_TIME *ptrDateTime) BOOL GetLocalTimeEx(DAY_TIME *ptrDateTime)
{ {
@ -360,9 +360,9 @@ BOOL GetLocalTimeEx(DAY_TIME *ptrDateTime)
#endif #endif
tm_t = time(NULL); tm_t = time(NULL);
// 格林威治时间 // 格林威治时间
//tmptr = gmtime(&tm_t); //tmptr = gmtime(&tm_t);
// 本地时间 // 本地时间
tmptr = localtime(&tm_t); tmptr = localtime(&tm_t);
if(!tmptr) if(!tmptr)
@ -384,9 +384,9 @@ BOOL GetLocalTimeEx(DAY_TIME *ptrDateTime)
} }
//******************************************************************** //********************************************************************
//* 设置系统时间函数 * //* 设置系统时间函数 *
//*参数: DAY_TIME : 时间缓冲区 * //*参数: DAY_TIME : 时间缓冲区 *
//*返回值BOOL retval : 是否成功 * //*返回值BOOL retval : 是否成功 *
//******************************************************************** //********************************************************************
//BOOL SetLocalTimeEx(DAY_TIME *ptrDateTime) //BOOL SetLocalTimeEx(DAY_TIME *ptrDateTime)
void SetLocalTimeEx(DAY_TIME *ptrDateTime) void SetLocalTimeEx(DAY_TIME *ptrDateTime)
@ -426,7 +426,7 @@ void SetLocalTimeEx(DAY_TIME *ptrDateTime)
//pid = vfork(); //pid = vfork();
//if(pid == 0) //if(pid == 0)
//{ //{
// ret = system (szCmdLine); //执行date命令设置时间 // ret = system (szCmdLine); //执行date命令设置时间
// exit(0); // exit(0);
// //return exit(0); // //return exit(0);
@ -632,7 +632,7 @@ WORD CalCheckout(u_char *buf, int len)
} }
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// wen 2005.10.19 增加基本函数 // wen 2005.10.19 增加基本函数
int IsHexChar(u_char c) int IsHexChar(u_char c)
{ {
if((c >= '0') && (c <= '9')) if((c >= '0') && (c <= '9'))
@ -705,9 +705,9 @@ u_long atoul(char *buf)
} }
/* ! /* !
\brief \brief
\param str[in/out] -- \param str[in/out] --
\ retval-- \ retval--
*/ */
int StringCutSpace(char *str) int StringCutSpace(char *str)
{ {
@ -725,7 +725,7 @@ int StringCutSpace(char *str)
flag = 0; flag = 0;
for(i = 0; i < len; i++) for(i = 0; i < len; i++)
{ {
// 在双引号" "中的字符串不进行去空格和制表符的处理 // 在双引号" "中的字符串不进行去空格和制表符的处理
if(str[i] == '\"') if(str[i] == '\"')
{ {
flag = flag ? 0 : 1; flag = flag ? 0 : 1;
@ -819,19 +819,19 @@ void PrintFormatMessage(int iMsgClass, char *ptrMsg)
} }
switch(iMsgClass) switch(iMsgClass)
{ {
// !输出信息级别为警告信息 // !输出信息级别为警告信息
case MSG_CLASS_WARN: case MSG_CLASS_WARN:
sprintf(szMsg, "WARN(%04d): %s\n", getpid(), ptrMsg); sprintf(szMsg, "WARN(%04d): %s\n", getpid(), ptrMsg);
break; break;
/* !输出信息级别为错误信息 /* !输出信息级别为错误信息
case MSG_CLASS_ERROR: case MSG_CLASS_ERROR:
sprintf(szMsg, "ERR_(%04d): %s\n", getpid(), ptrMsg); sprintf(szMsg, "ERR_(%04d): %s\n", getpid(), ptrMsg);
break; break;
/* !输出信息级别为提示信息 /* !输出信息级别为提示信息
case MSG_CLASS_TIP: case MSG_CLASS_TIP:
default: default:
@ -847,7 +847,7 @@ void PrintFormatMessage(int iMsgClass, char *ptrMsg)
} }
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// 超时判断 // 超时判断
BOOL JudgeTimeOut(DAY_TIME *pStartTime, int iTimeOutSeconds) BOOL JudgeTimeOut(DAY_TIME *pStartTime, int iTimeOutSeconds)
{ {
int iDays, iVal1, iVal2; int iDays, iVal1, iVal2;
@ -878,7 +878,7 @@ BOOL JudgeTimeOut(DAY_TIME *pStartTime, int iTimeOutSeconds)
return TRUE; return TRUE;
} }
// CRC校验表计算函数 // CRC校验表计算函数
void CalcCRCTableEx(WORD *pwCrcTable, WORD wDivisor) void CalcCRCTableEx(WORD *pwCrcTable, WORD wDivisor)
{ {
int i, j, k; int i, j, k;
@ -913,7 +913,7 @@ void CalcCRCTableEx(WORD *pwCrcTable, WORD wDivisor)
} }
} }
// 计算校验和 // 计算校验和
BYTE CalcAllDataLpc(BYTE *pData, int iLen) BYTE CalcAllDataLpc(BYTE *pData, int iLen)
{ {
int i; int i;

@ -7,22 +7,22 @@
DSLIB_API void DebugPrint(char *szDebug); DSLIB_API void DebugPrint(char *szDebug);
// 字符串操作 // 字符串操作
DSLIB_API int CmpString(const u_char *str1, const u_char *str2); DSLIB_API int CmpString(const u_char *str1, const u_char *str2);
DSLIB_API int CmpString2(const char *str1, const char *str2); DSLIB_API int CmpString2(const char *str1, const char *str2);
BOOL IsRemarkLine(const char *str); BOOL IsRemarkLine(const char *str);
// 字节转换 // 字节转换
/*! RTU字节顺序为低字节在前高字节在后 /*! RTU字节顺序为低字节在前高字节在后
NET NET
*/ */
DSLIB_API BOOL IsNetSequence(); DSLIB_API BOOL IsNetSequence();
DSLIB_API BOOL SequenceHostToRtu(char *pData, int ilen); DSLIB_API BOOL SequenceHostToRtu(char *pData, int ilen);
DSLIB_API BOOL SequenceRtuToHost(char *pData, int ilen); DSLIB_API BOOL SequenceRtuToHost(char *pData, int ilen);
DSLIB_API BOOL SequenceHostToNet(char *pData, int ilen); DSLIB_API BOOL SequenceHostToNet(char *pData, int ilen);
DSLIB_API BOOL SequenceNetToHost(char *pData, int ilen); DSLIB_API BOOL SequenceNetToHost(char *pData, int ilen);
// 超时判断 // 超时判断
BOOL JudgeTimeOut(DAY_TIME *pStartTime, int iTimeOutSeconds); BOOL JudgeTimeOut(DAY_TIME *pStartTime, int iTimeOutSeconds);
BOOL GetLocalTimeEx(DAY_TIME *ptrDateTime); BOOL GetLocalTimeEx(DAY_TIME *ptrDateTime);
void SetLocalTimeEx(DAY_TIME *ptrDateTime); void SetLocalTimeEx(DAY_TIME *ptrDateTime);

@ -31,8 +31,8 @@ typedef int BOOL;
typedef struct tagCMDDEF typedef struct tagCMDDEF
{ {
u_32 CmdTimerCnt; //命令时间计数 u_32 CmdTimerCnt; //命令时间计数
u_32 CmdTimerConst; //命令时间间隔 u_32 CmdTimerConst; //命令时间间隔
} CMDDEF, *pCMDDEF; } CMDDEF, *pCMDDEF;
#ifndef _WIN32 #ifndef _WIN32

File diff suppressed because it is too large Load Diff

@ -3,19 +3,19 @@
* Copyright (C) 2004-2005 SCADA Control Technology Co., Ltd. * Copyright (C) 2004-2005 SCADA Control Technology Co., Ltd.
* All rights reserved. * All rights reserved.
* *
* buban101.h * buban101.h
* 101 * 101
* 101 * 101
* *
* 1.0 * 1.0
* aaawen * aaawen
* 2005/09/08 * 2005/09/08
* *
* 1.0 * 1.0
* *
* *
* *
* *
* u8 --- BYTE(usigned char) * u8 --- BYTE(usigned char)
* ch --- char * ch --- char
* w --- WORD(u_short, usigned short) * w --- WORD(u_short, usigned short)
@ -31,14 +31,14 @@
* c --- class * c --- class
* s --- struct * s --- struct
* sta --- static * sta --- static
* g --- * g ---
* Array --- * Array ---
* a --- * a ---
* m_ --- * m_ ---
* p --- * p ---
* str --- * str ---
* --- * ---
* --- * ---
**************************************************************************************/ **************************************************************************************/
// buban101.h: interface for the buban101 class. // buban101.h: interface for the buban101 class.
// //
@ -52,71 +52,71 @@
#endif #endif
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// 宏定义 // // 宏定义 //
// WEN 2005.09.08 // // WEN 2005.09.08 //
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
//信息体地址 //信息体地址
#define INFO_DI_BASEADDR 0x001 // 单,双点遥信量 #define INFO_DI_BASEADDR 0x001 // 单,双点遥信量
#define INFO_PROTECT_BASEADDR 0x401 // 保护单个事件信息 #define INFO_PROTECT_BASEADDR 0x401 // 保护单个事件信息
#define INFO_PROTECT_STARTBASEADDR 0x501 // 保护启动事件 #define INFO_PROTECT_STARTBASEADDR 0x501 // 保护启动事件
#define INFO_PROTECT_GROUPBASEADDR 0x601 // 保护成组输出电路信息 #define INFO_PROTECT_GROUPBASEADDR 0x601 // 保护成组输出电路信息
#define INFO_AI_BASEADDR 0x701 // 遥测量 #define INFO_AI_BASEADDR 0x701 // 遥测量
#define INFO_PARA_BASEADDR 0x901 // 参数地址,和遥测量一一对应 #define INFO_PARA_BASEADDR 0x901 // 参数地址,和遥测量一一对应
#define INFO_YKYT_BASEADDR 0xB01 // 遥控、遥调 #define INFO_YKYT_BASEADDR 0xB01 // 遥控、遥调
#define INFO_SET_BASEADDR 0xB81 // 设定地址范围 #define INFO_SET_BASEADDR 0xB81 // 设定地址范围
#define INFO_PI_BASEADDR 0xC01 // 电度量 #define INFO_PI_BASEADDR 0xC01 // 电度量
#define INFO_STEP_BASEADDR 0xC81 // 步长量(如:变压器分接头) #define INFO_STEP_BASEADDR 0xC81 // 步长量(如:变压器分接头)
#define INFO_BIN_BASEADDR 0xCA1 // 二进制状态信息 #define INFO_BIN_BASEADDR 0xCA1 // 二进制状态信息
#define INFO_BCD_BASEADDR 0xCC1 // BCD码(水位,频率) #define INFO_BCD_BASEADDR 0xCC1 // BCD码(水位,频率)
#define INFO_STATUS_BASEADDR 0xCE9 // 子站远东终端状态 #define INFO_STATUS_BASEADDR 0xCE9 // 子站远东终端状态
#define INFO_FILE_BASEADDR 0xCEA // 文件传输 #define INFO_FILE_BASEADDR 0xCEA // 文件传输
//一组中的个类型数据最大个数 //一组中的个类型数据最大个数
#define MAX_GROUP_AINUM 128 #define MAX_GROUP_AINUM 128
//#define MAX_GROUP_FLOATAINUM 128 //#define MAX_GROUP_FLOATAINUM 128
#define MAX_GROUP_DINUM 128 #define MAX_GROUP_DINUM 128
#define MAX_GROUP_PINUM 32 #define MAX_GROUP_PINUM 32
//转发各种类型的数据的最大数量 //转发各种类型的数据的最大数量
#define MAX_AINUM 120 #define MAX_AINUM 120
#define MAX_FLOATAINUM 9 #define MAX_FLOATAINUM 9
#define MAX_DINUM 127 #define MAX_DINUM 127
#define MAX_PINUM 35 #define MAX_PINUM 35
#define MAX_POLL_CMD_BUF_NUM 32 // 最大命令缓冲区数目 #define MAX_POLL_CMD_BUF_NUM 32 // 最大命令缓冲区数目
// 命令类型定义 // 命令类型定义
#define ASK_LINK 0 // 请求链路 #define ASK_LINK 0 // 请求链路
#define RST_LINK 1 // 复位链路 #define RST_LINK 1 // 复位链路
#define RTU_TIME 2 // 对时时间 #define RTU_TIME 2 // 对时时间
#define ASK_DI_DATA 3 // 召唤2 级数据YX #define ASK_DI_DATA 3 // 召唤2 级数据YX
#define ASK_AI_DATA 4 // 召唤2 级数据YC #define ASK_AI_DATA 4 // 召唤2 级数据YC
#define ASK_PI_DATA 5 // 召唤2 级数据YM #define ASK_PI_DATA 5 // 召唤2 级数据YM
#define ASK_ALL_DATA 6 // 初始化总召唤 #define ASK_ALL_DATA 6 // 初始化总召唤
#define ASK_FIRST_DATA 7 // 召唤1 级数据 #define ASK_FIRST_DATA 7 // 召唤1 级数据
#define ASK_SECOND_DATA 8 // 召唤2 级数据 #define ASK_SECOND_DATA 8 // 召唤2 级数据
#define ACK 9 // 确认回答 #define ACK 9 // 确认回答
#define ANS_LINK 10 // 链路回答 #define ANS_LINK 10 // 链路回答
#define ASK_PI 11 // 召唤数据YM #define ASK_PI 11 // 召唤数据YM
#define ASK_DATA_NO 12 // 无所请求的数据 #define ASK_DATA_NO 12 // 无所请求的数据
#define ASK_ALLDATA_END 13 // 召唤数据结束(用于总召唤和电度召唤) #define ASK_ALLDATA_END 13 // 召唤数据结束(用于总召唤和电度召唤)
//#define ASK_ALLDATA_ACK 14 // 召唤数据确认(用于总召唤和电度召唤) //#define ASK_ALLDATA_ACK 14 // 召唤数据确认(用于总召唤和电度召唤)
// 定时召唤命令及命令名称 // 定时召唤命令及命令名称
#define BUBAN101_TIMER_CMD_NUM 2 // 最大命令数目 #define BUBAN101_TIMER_CMD_NUM 2 // 最大命令数目
#define MAX_POLLCMD_BUF_LEN 320 // 最大命令缓冲区数目 #define MAX_POLLCMD_BUF_LEN 320 // 最大命令缓冲区数目
// 控制模式 // 控制模式
#define CONTROL_DOUBLE 0 // 双点控制 #define CONTROL_DOUBLE 0 // 双点控制
#define CONTROL_SINGAL 1 // 单点控制 #define CONTROL_SINGAL 1 // 单点控制
#define CONTROL_DIRECT 2 // 直接控制 #define CONTROL_DIRECT 2 // 直接控制
// 规约版本号 // 规约版本号
#define VER_BUBAN_101 0 // 部颁101 #define VER_BUBAN_101 0 // 部颁101
#define VER_IEC870_5_101 1 // IEC101 #define VER_IEC870_5_101 1 // IEC101
/////////////////////////////结构定义///////////////////////////////// /////////////////////////////结构定义/////////////////////////////////
typedef struct typedef struct
{ {
long CmdTimerCnt; long CmdTimerCnt;
@ -125,149 +125,149 @@ typedef struct
typedef struct tagBUBAN101PORTPARAM typedef struct tagBUBAN101PORTPARAM
{ {
BOOL RstLinkOk; // 初始化时FALSE BOOL RstLinkOk; // 初始化时FALSE
BOOL LinkOk; // 主站初始化标志 1:ok; 0:no 初始化时FALSE BOOL LinkOk; // 主站初始化标志 1:ok; 0:no 初始化时FALSE
BOOL Initdata; // 初始化总召唤标志 TRUE收到总召唤结束帧 BOOL Initdata; // 初始化总召唤标志 TRUE收到总召唤结束帧
// FALSE未收到总召唤结束帧 // FALSE未收到总召唤结束帧
// 召唤电度标志 TRUE收到召唤结束帧 // 召唤电度标志 TRUE收到召唤结束帧
// FALSE未收到召唤结束帧 // FALSE未收到召唤结束帧
BYTE LinkAddr; // 地址域 BYTE LinkAddr; // 地址域
BYTE CtlByte; // 控制信息 BYTE CtlByte; // 控制信息
long LinkOkCnt; long LinkOkCnt;
long lTimeOutConst; // 超时时间间隔 long lTimeOutConst; // 超时时间间隔
short RtuVersion; // 版本号 short RtuVersion; // 版本号
short BalanceOrNot; //是否平衡式 =1:ok; =0:no short BalanceOrNot; //是否平衡式 =1:ok; =0:no
short CurCmdIdx; short CurCmdIdx;
short YkMode; // 遥控方式(=0双点遥控=1单点遥控=2直控方式) short YkMode; // 遥控方式(=0双点遥控=1单点遥控=2直控方式)
// wen 2005.01.15 修改数据信息体起始地址 // wen 2005.01.15 修改数据信息体起始地址
int iAiBaseAddr; //遥测起始地址 int iAiBaseAddr; //遥测起始地址
int iDiBaseAddr; //遥信起始地址 int iDiBaseAddr; //遥信起始地址
int iPiBaseAddr; //遥脉起始地址 int iPiBaseAddr; //遥脉起始地址
int iYkBaseAddr; //遥控起始地址 int iYkBaseAddr; //遥控起始地址
BYTE m_au8RecvBuf[300]; BYTE m_au8RecvBuf[300];
int m_iRecvLen; int m_iRecvLen;
BUBAN101CMDDEF CmdTime[BUBAN101_TIMER_CMD_NUM]; BUBAN101CMDDEF CmdTime[BUBAN101_TIMER_CMD_NUM];
SIO_PARAM_BAOHU_DEF *m_psBaoHu; // 该规约的端口数据指针 SIO_PARAM_BAOHU_DEF *m_psBaoHu; // 该规约的端口数据指针
} BUBAN101PORTPARAM, *pBUBAN101PORTPARAM; } BUBAN101PORTPARAM, *pBUBAN101PORTPARAM;
/////////////////////////以下为通用函数接口/////////////////////////// /////////////////////////以下为通用函数接口///////////////////////////
/*! /*!
\brief \brief
\param commid -- \param commid --
\note \note
0 -- MaxSerialPortNum + MaxNetPortNum -1\n 0 -- MaxSerialPortNum + MaxNetPortNum -1\n
*/ */
void Buban101ReadConfig(int commid); // 初始化处理 void Buban101ReadConfig(int commid); // 初始化处理
/*! /*!
\brief \brief
\param commid -- \param commid --
\note \note
0 -- MaxSerialPortNum + MaxNetPortNum -1\n 0 -- MaxSerialPortNum + MaxNetPortNum -1\n
\param buf -- \param buf --
\param len -- \param len --
*/ */
void Buban101RecvData(int commid, u_char *buf, int len);// 规约读数据处理 void Buban101RecvData(int commid, u_char *buf, int len);// 规约读数据处理
/*! /*!
\brief \brief
\param commid -- \param commid --
\note \note
0 -- MaxSerialPortNum + MaxNetPortNum -1\n 0 -- MaxSerialPortNum + MaxNetPortNum -1\n
*/ */
void Buban101Timer(int commid); // 定时器处理 void Buban101Timer(int commid); // 定时器处理
/*! /*!
\brief \brief
\param commid -- \param commid --
\note \note
0 -- MaxSerialPortNum + MaxNetPortNum -1\n 0 -- MaxSerialPortNum + MaxNetPortNum -1\n
\param buf -- \param buf --
\param len -- \param len --
*/ */
void Buban101YkYtProcess(int commid, u_char *buf, int len); // 遥控遥调处理 void Buban101YkYtProcess(int commid, u_char *buf, int len); // 遥控遥调处理
/*! /*!
\brief \brief
\param commid -- \param commid --
\note \note
0 -- MaxSerialPortNum + MaxNetPortNum -1\n 0 -- MaxSerialPortNum + MaxNetPortNum -1\n
*/ */
void Buban101SendSystemTime(int commid); // 系统对时 void Buban101SendSystemTime(int commid); // 系统对时
/*! /*!
\brief 退 \brief 退
\param commid -- \param commid --
\note \note
0 -- MaxSerialPortNum + MaxNetPortNum -1\n 0 -- MaxSerialPortNum + MaxNetPortNum -1\n
*/ */
void Buban101Exit(int commid); // 规约退出 void Buban101Exit(int commid); // 规约退出
/*! /*!
\brief \brief
\param commid -- \param commid --
\param rtumsg -- \param rtumsg --
\note \note
0 -- MaxSerialPortNum + MaxNetPortNum -1\n 0 -- MaxSerialPortNum + MaxNetPortNum -1\n
*/ */
void Buban101BaoHuCmdProcess(int commid, RTUMSG *rtumsg, BOOL bUpData); void Buban101BaoHuCmdProcess(int commid, RTUMSG *rtumsg, BOOL bUpData);
/*! /*!
\brief \brief
\param commid -- \param commid --
\param iProvAddr -- \param iProvAddr --
\param ppBaoHuDB -- \param ppBaoHuDB --
\retval -- \retval --
*/ */
int Buban101GetBaohuDataBase(int commid, int iProvAddr, GROUPDEF **ppBaoHuDB); int Buban101GetBaohuDataBase(int commid, int iProvAddr, GROUPDEF **ppBaoHuDB);
/////////////////////////通用函数接口结束/////////////////////////////// /////////////////////////通用函数接口结束///////////////////////////////
/////////////////////////buban101公共函数接口/////////////////////////// /////////////////////////buban101公共函数接口///////////////////////////
// 校验数据帧是否正确 // 校验数据帧是否正确
BOOL Buban101Check(u_char* msg, int len); BOOL Buban101Check(u_char* msg, int len);
//计算 Buban101 累加和检验码 //计算 Buban101 累加和检验码
u_char CalBuban101Lpc(u_char* msg, int len); u_char CalBuban101Lpc(u_char* msg, int len);
//指令缓冲区初始化 //指令缓冲区初始化
void InitBuban101CommandBuffer(int commid); void InitBuban101CommandBuffer(int commid);
/////////////////////////buban101公共函数接口结束/////////////////////// /////////////////////////buban101公共函数接口结束///////////////////////
/////////////////////////以下为通用函数支持接口///////////////////////// /////////////////////////以下为通用函数支持接口/////////////////////////
void Buban101ProvMakeYkYtCommand(int commid, u_char *buf, int len); void Buban101ProvMakeYkYtCommand(int commid, u_char *buf, int len);
/////////////////////////通用函数支持接口结束/////////////////////////// /////////////////////////通用函数支持接口结束///////////////////////////
///////////////////////////以下为指令生成函数/////////////////////////// ///////////////////////////以下为指令生成函数///////////////////////////
//生成 Buban101 命令? //生成 Buban101 命令?
void MakeBuban101Command(u_32 commid, u_char cmdidx); void MakeBuban101Command(u_32 commid, u_char cmdidx);
//生成遥控遥调指令 //生成遥控遥调指令
void MakeBuBan101YkYtCommand(u_32 commid, u_char *buf, int len); void MakeBuBan101YkYtCommand(u_32 commid, u_char *buf, int len);
///////////////////////////指令生成函数结束///////////////////////////// ///////////////////////////指令生成函数结束/////////////////////////////
/////////////////////以下为POLLING规约常规函数接口////////////////////// /////////////////////以下为POLLING规约常规函数接口//////////////////////
void Buban101FindNextCmd(int commid); void Buban101FindNextCmd(int commid);
BOOL Buban101FindNextCmdEx(int commid); BOOL Buban101FindNextCmdEx(int commid);
void Buban101SendCmdFormPollCmdBuf(int commid); void Buban101SendCmdFormPollCmdBuf(int commid);
//////////////////////POLLING规约常规函数接口结束/////////////////////// //////////////////////POLLING规约常规函数接口结束///////////////////////
///////////////////////以下为规约处理函数接口/////////////////////////// ///////////////////////以下为规约处理函数接口///////////////////////////
//======================以下为主站数据处理============================ //======================以下为主站数据处理============================
void Buban101ProcessData(u_32 commid, BUBAN101PORTPARAM *psPortParam, BOOL bProcess); void Buban101ProcessData(u_32 commid, BUBAN101PORTPARAM *psPortParam, BOOL bProcess);
void Buban101shortprocess(RTUMSG *rtumsg); void Buban101shortprocess(RTUMSG *rtumsg);
void Buban101longprocess(RTUMSG *rtumsg); void Buban101longprocess(RTUMSG *rtumsg);
void Buban101NoChanged(RTUMSG * rtumsg); void Buban101NoChanged(RTUMSG * rtumsg);
//Buban101 初始化数据处理 //Buban101 初始化数据处理
void Buban101InitdataProecss(RTUMSG * rtumsg); void Buban101InitdataProecss(RTUMSG * rtumsg);
//电度结束帧 //电度结束帧
void Buban101PidataEnd(RTUMSG * rtumsg); void Buban101PidataEnd(RTUMSG * rtumsg);
//设定确认 //设定确认
void Buban101SetAck(RTUMSG *rtumsg); void Buban101SetAck(RTUMSG *rtumsg);
//Buban101 遥控遥调返校程序 //Buban101 遥控遥调返校程序
void Buban101YkYtAck(RTUMSG * rtumsg); void Buban101YkYtAck(RTUMSG * rtumsg);
//Buban101 对时程序 //Buban101 对时程序
void Buban101SynTime(RTUMSG * rtumsg); void Buban101SynTime(RTUMSG * rtumsg);
// 子站主动传送遥信变位帧 // 子站主动传送遥信变位帧
void Buban101AutoSendDiProcess(RTUMSG *rtumsg); void Buban101AutoSendDiProcess(RTUMSG *rtumsg);
void Buban101AiWithPzDataProcess(RTUMSG *, int); void Buban101AiWithPzDataProcess(RTUMSG *, int);
@ -277,25 +277,25 @@ void Buban101SoeDataProcess(RTUMSG *rtumsg, int);
void Buban101PiDataProcess(RTUMSG * rtumsg); void Buban101PiDataProcess(RTUMSG * rtumsg);
void Buban101PiWithTimeDataProcess(RTUMSG *rtumsg); void Buban101PiWithTimeDataProcess(RTUMSG *rtumsg);
//保护数据处理 //保护数据处理
void Buban101BaoHuDataProcess(RTUMSG *rtumsg); void Buban101BaoHuDataProcess(RTUMSG *rtumsg);
void Buban101DefaultBaoHuDataProcess(RTUMSG *rtumsg); void Buban101DefaultBaoHuDataProcess(RTUMSG *rtumsg);
// 新增函数,含有 7 BYTE 的时标 // 新增函数,含有 7 BYTE 的时标
void Buban101SoeDataProcessWithCP56Time2a(RTUMSG *rtumsg, int flag); void Buban101SoeDataProcessWithCP56Time2a(RTUMSG *rtumsg, int flag);
void Buban101AiWithDataProcessWithM_ME_TD_1(RTUMSG * rtumsg); void Buban101AiWithDataProcessWithM_ME_TD_1(RTUMSG * rtumsg);
void Buban101AiWithDataProcessWithM_ME_TE_1(RTUMSG * rtumsg); void Buban101AiWithDataProcessWithM_ME_TE_1(RTUMSG * rtumsg);
void Buban101AiWithDataProcessWithM_ME_TF_1(RTUMSG * rtumsg); void Buban101AiWithDataProcessWithM_ME_TF_1(RTUMSG * rtumsg);
void Buban101PiWithTimeDataProcessWithM_IT_TB_1(RTUMSG *rtumsg); void Buban101PiWithTimeDataProcessWithM_IT_TB_1(RTUMSG *rtumsg);
//======================以下为子站数据处理============================ //======================以下为子站数据处理============================
void ProvBuban101dataProcess(int commid, RTUMSG *rtumsg); void ProvBuban101dataProcess(int commid, RTUMSG *rtumsg);
void ProvBuban101shortprocess(int commid, RTUMSG * rtumsg); void ProvBuban101shortprocess(int commid, RTUMSG * rtumsg);
void ProvBuban101longprocess(int commid, RTUMSG * rtumsg); void ProvBuban101longprocess(int commid, RTUMSG * rtumsg);
void ProvBuban101SendAllData(int commid, RTUMSG * rtumsg); void ProvBuban101SendAllData(int commid, RTUMSG * rtumsg);
void ProvBuban101SendPIData(int commid, RTUMSG * rtumsg); void ProvBuban101SendPIData(int commid, RTUMSG * rtumsg);
void ProvBuban101ProcessTime(int commid, RTUMSG *rtumsg); void ProvBuban101ProcessTime(int commid, RTUMSG *rtumsg);
//iGroupNo=0为响应总召唤 //iGroupNo=0为响应总召唤
void ProvBuban101SendPI(int commid, RTUMSG *rtumsg, int iGroupNo); void ProvBuban101SendPI(int commid, RTUMSG *rtumsg, int iGroupNo);
void ProvBuban101SendAI(int commid, RTUMSG *rtumsg, int iGroupNo); void ProvBuban101SendAI(int commid, RTUMSG *rtumsg, int iGroupNo);
void ProvBuban101SendDI(int commid, RTUMSG *rtumsg, int iGroupNo); void ProvBuban101SendDI(int commid, RTUMSG *rtumsg, int iGroupNo);
@ -306,6 +306,6 @@ void MakeProvBuban101YkYtAckMsg(int commid, int pnt, int op, int step);
void ProvBuban101SendClass1(int commid); void ProvBuban101SendClass1(int commid);
void ProvBuban101SendClass2(int commid); void ProvBuban101SendClass2(int commid);
void ProvMakeBuban101Command(int commid, u_char cmdidx); void ProvMakeBuban101Command(int commid, u_char cmdidx);
/////////////////////////规约处理函数接口结束/////////////////////////// /////////////////////////规约处理函数接口结束///////////////////////////
#endif // !defined(_BUBAN101_H_200509081012__INCLUDED_) #endif // !defined(_BUBAN101_H_200509081012__INCLUDED_)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -22,6 +22,8 @@
#include "buban104.h" #include "buban104.h"
#include "scadaprotect.h" #include "scadaprotect.h"
#include "MySQLAdo.h"
extern SIO_PARAM_DEF SioParam[]; extern SIO_PARAM_DEF SioParam[];
extern FUNCTION_CALL *FunCallPtr; extern FUNCTION_CALL *FunCallPtr;
extern void *pvconf_handle; extern void *pvconf_handle;
@ -32,9 +34,9 @@ extern char IniFilePath[256];
const char *gpStrBuban104Cmd[BUBAN104_TIMER_CMD_NUM] = const char *gpStrBuban104Cmd[BUBAN104_TIMER_CMD_NUM] =
{ {
"总召唤电度数据", "总召唤电度数据",
"召唤初始化数据", "召唤初始化数据",
"帧序应答" "帧序应答"
}; };
/*! /*!
@ -4671,9 +4673,11 @@ void ProvBuban104SendAIwithFloat(int commid, RTUMSG *rtumsg, int iGroupNo)
for( j = 0; j < iSendNum; j++ ) for( j = 0; j < iSendNum; j++ )
{ {
pfValue = (float *)&commandbuf[iLenth+14]; pfValue = (float *)&commandbuf[iLenth+14];
flag = GetAIPntMsg(j+iNo, &igno, &iItemNo, &sCurTime, pfValue, &iaddr1); flag = GetAIPntMsg(j+iNo, (unsigned int*)&igno, (unsigned int*)&iItemNo, &sCurTime, pfValue, (unsigned int*)&iaddr1);
if (0 == flag) if (0 == flag)
break; break;
if (-1 == flag)
continue;
if (iaddr1 == iaddr0) if (iaddr1 == iaddr0)
; ;
else else

@ -3,19 +3,19 @@
* Copyright (C) 2004-2005 SCADA Control Technology Co., Ltd. * Copyright (C) 2004-2005 SCADA Control Technology Co., Ltd.
* All rights reserved. * All rights reserved.
* *
* buban104.h * buban104.h
* 104 * 104
* 104 * 104
* *
* 1.0 * 1.0
* aaawen * aaawen
* 2005/09/14 * 2005/09/14
* *
* 1.0 * 1.0
* *
* *
* *
* *
* u8 --- BYTE(usigned char) * u8 --- BYTE(usigned char)
* ch --- char * ch --- char
* w --- WORD(u_short, usigned short) * w --- WORD(u_short, usigned short)
@ -31,14 +31,14 @@
* c --- class * c --- class
* s --- struct * s --- struct
* sta --- static * sta --- static
* g --- * g ---
* Array --- * Array ---
* a --- * a ---
* m_ --- * m_ ---
* p --- * p ---
* str --- * str ---
* --- * ---
* --- * ---
**************************************************************************************/ **************************************************************************************/
// buban104.h: interface for the buban104 class. // buban104.h: interface for the buban104 class.
// //
@ -52,30 +52,30 @@
#endif #endif
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// 宏定义 // // 宏定义 //
// WEN 2005.09.08 // // WEN 2005.09.08 //
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
#define MAX_104_PINUM 30 #define MAX_104_PINUM 30
#define FORMAT_I 14 // I-格式 #define FORMAT_I 14 // I-格式
#define FORMAT_S 15 // S-格式 #define FORMAT_S 15 // S-格式
#define FORMAT_U_START_ACT 16 // U-格式启动 #define FORMAT_U_START_ACT 16 // U-格式启动
#define FORMAT_U_START_CON 17 // U-格式启动应答 #define FORMAT_U_START_CON 17 // U-格式启动应答
#define FORMAT_U_STOP_ACT 18 // U-格式停止 #define FORMAT_U_STOP_ACT 18 // U-格式停止
#define FORMAT_U_STOP_CON 19 // U-格式停止应答 #define FORMAT_U_STOP_CON 19 // U-格式停止应答
#define FORMAT_U_TEST_ACT 20 // U-格式测试 #define FORMAT_U_TEST_ACT 20 // U-格式测试
#define FORMAT_U_TEST_CON 21 // U-格式测试应答 #define FORMAT_U_TEST_CON 21 // U-格式测试应答
// 定时召唤命令及命令名称 // 定时召唤命令及命令名称
#define BUBAN104_TIMER_CMD_NUM 3 // 最大命令数目 #define BUBAN104_TIMER_CMD_NUM 3 // 最大命令数目
#define MAX_SEQUENCE 0x7fff // 最大帧计数 #define MAX_SEQUENCE 0x7fff // 最大帧计数
#define MAX_FRAMEMATCHING_SIZE 2 // 帧序匹配最大尺寸 #define MAX_FRAMEMATCHING_SIZE 2 // 帧序匹配最大尺寸
// 规约版本号 // 规约版本号
#define VER_BUBAN_104 0 // 部颁104 #define VER_BUBAN_104 0 // 部颁104
#define VER_IEC870_5_104 1 // IEC104 #define VER_IEC870_5_104 1 // IEC104
/////////////////////////////结构定义///////////////////////////////// /////////////////////////////结构定义/////////////////////////////////
typedef struct typedef struct
{ {
long CmdTimerCnt; long CmdTimerCnt;
@ -84,166 +84,166 @@ typedef struct
typedef struct tagBUBAN104PORTPARAM typedef struct tagBUBAN104PORTPARAM
{ {
BOOL LinkOk; // 主站初始化标志 1:ok; 0:no 初始化时FALSE BOOL LinkOk; // 主站初始化标志 1:ok; 0:no 初始化时FALSE
BOOL Initdata; // 初始化总召唤标志 TRUE收到总召唤结束帧 BOOL Initdata; // 初始化总召唤标志 TRUE收到总召唤结束帧
// FALSE未收到总召唤结束帧 // FALSE未收到总召唤结束帧
// 召唤电度标志 TRUE收到召唤结束帧 // 召唤电度标志 TRUE收到召唤结束帧
// FALSE未收到召唤结束帧 // FALSE未收到召唤结束帧
WORD wLinkAddr; // 地址域 WORD wLinkAddr; // 地址域
WORD wSendSequence; // 发送帧计数 WORD wSendSequence; // 发送帧计数
WORD wRecvSequence; // 接收帧计数 WORD wRecvSequence; // 接收帧计数
WORD wAckSequence; // 应答帧计数 WORD wAckSequence; // 应答帧计数
BOOL bAckRight; // 应答帧是否同步 (子站端有效) BOOL bAckRight; // 应答帧是否同步 (子站端有效)
BOOL bStopComm; // 通讯停止 BOOL bStopComm; // 通讯停止
BOOL bSendFormatI; BOOL bSendFormatI;
BYTE ProvAckOrNot; // 转发是否要求应答 BYTE ProvAckOrNot; // 转发是否要求应答
long lTimeOutSendTest;// 超时发送测试帧 long lTimeOutSendTest;// 超时发送测试帧
long lTimeOutConst; // 超时时间间隔 long lTimeOutConst; // 超时时间间隔
long lTimeOutCnt; // 超时时间计数 long lTimeOutCnt; // 超时时间计数
long lYkYtAckTimeConst;// 返校超时时间间隔 long lYkYtAckTimeConst;// 返校超时时间间隔
long lYkYtAckTime; // 返校超时时间计数 long lYkYtAckTime; // 返校超时时间计数
BOOL bCloseSocket; // 关闭socket端口 BOOL bCloseSocket; // 关闭socket端口
char YkCmdBuf[32]; // 遥控延迟发送返校缓冲区 char YkCmdBuf[32]; // 遥控延迟发送返校缓冲区
long lYkCmdBuflen; // 遥控延迟发送返校缓冲区数据长 long lYkCmdBuflen; // 遥控延迟发送返校缓冲区数据长
long m_lNoDataCnt; // 无数据时间,超过超时时间发送测试帧 long m_lNoDataCnt; // 无数据时间,超过超时时间发送测试帧
short RtuVersion; // 版本号 short RtuVersion; // 版本号
int m_iPublishYear; // 发布时间(缺省为2000版) int m_iPublishYear; // 发布时间(缺省为2000版)
short CurCmdIdx; short CurCmdIdx;
short YkMode; // 遥控方式(=0双点遥控=1单点遥控=2直控方式) short YkMode; // 遥控方式(=0双点遥控=1单点遥控=2直控方式)
// wen 2005.01.15 修改数据信息体起始地址 // wen 2005.01.15 修改数据信息体起始地址
int iAiBaseAddr; // 遥测起始地址 int iAiBaseAddr; // 遥测起始地址
int iDiBaseAddr; // 遥信起始地址 int iDiBaseAddr; // 遥信起始地址
int iPiBaseAddr; // 遥脉起始地址 int iPiBaseAddr; // 遥脉起始地址
int iYkBaseAddr; // 遥控起始地址 int iYkBaseAddr; // 遥控起始地址
BYTE m_au8RecvBuf[300]; BYTE m_au8RecvBuf[300];
int m_iRecvLen; int m_iRecvLen;
int m_iFrameSize; // 帧序应答尺寸 int m_iFrameSize; // 帧序应答尺寸
BYTE m_bProvAiType; // 转发遥测类型标识 BYTE m_bProvAiType; // 转发遥测类型标识
BUBAN104CMDDEF CmdTime[BUBAN104_TIMER_CMD_NUM]; BUBAN104CMDDEF CmdTime[BUBAN104_TIMER_CMD_NUM];
SIO_PARAM_BAOHU_DEF *m_psBaoHu; // 该规约的端口数据指针 SIO_PARAM_BAOHU_DEF *m_psBaoHu; // 该规约的端口数据指针
} BUBAN104PORTPARAM, *pBUBAN104PORTPARAM; } BUBAN104PORTPARAM, *pBUBAN104PORTPARAM;
/////////////////////////以下为通用函数接口/////////////////////////// /////////////////////////以下为通用函数接口///////////////////////////
/*! /*!
\brief \brief
\param commid -- \param commid --
\note \note
0 -- MaxSerialPortNum + MaxNetPortNum -1\n 0 -- MaxSerialPortNum + MaxNetPortNum -1\n
*/ */
void Buban104ReadConfig(int commid); // 初始化处理 void Buban104ReadConfig(int commid); // 初始化处理
/*! /*!
\brief \brief
\param commid -- \param commid --
\note \note
0 -- MaxSerialPortNum + MaxNetPortNum -1\n 0 -- MaxSerialPortNum + MaxNetPortNum -1\n
\param buf -- \param buf --
\param len -- \param len --
*/ */
void Buban104RecvData(int commid, u_char *buf, int len);// 规约读数据处理 void Buban104RecvData(int commid, u_char *buf, int len);// 规约读数据处理
/*! /*!
\brief \brief
\param commid -- \param commid --
\note \note
0 -- MaxSerialPortNum + MaxNetPortNum -1\n 0 -- MaxSerialPortNum + MaxNetPortNum -1\n
*/ */
void Buban104Timer(int commid); // 定时器处理 void Buban104Timer(int commid); // 定时器处理
/*! /*!
\brief \brief
\param commid -- \param commid --
\note \note
0 -- MaxSerialPortNum + MaxNetPortNum -1\n 0 -- MaxSerialPortNum + MaxNetPortNum -1\n
\param buf -- \param buf --
\param len -- \param len --
*/ */
void Buban104YkYtProcess(int commid, u_char *buf, int len); // 遥控遥调处理 void Buban104YkYtProcess(int commid, u_char *buf, int len); // 遥控遥调处理
/*! /*!
\brief \brief
\param commid -- \param commid --
\note \note
0 -- MaxSerialPortNum + MaxNetPortNum -1\n 0 -- MaxSerialPortNum + MaxNetPortNum -1\n
*/ */
void Buban104SendSystemTime(int commid); // 系统对时 void Buban104SendSystemTime(int commid); // 系统对时
/*! /*!
\brief 退 \brief 退
\param commid -- \param commid --
\note \note
0 -- MaxSerialPortNum + MaxNetPortNum -1\n 0 -- MaxSerialPortNum + MaxNetPortNum -1\n
*/ */
void Buban104Exit(int commid); // 规约退出 void Buban104Exit(int commid); // 规约退出
/*! /*!
\brief \brief
\param commid -- \param commid --
\param rtumsg -- \param rtumsg --
\note \note
0 -- MaxSerialPortNum + MaxNetPortNum -1\n 0 -- MaxSerialPortNum + MaxNetPortNum -1\n
*/ */
void Buban104BaoHuCmdProcess(int commid, RTUMSG *rtumsg, BOOL bUpData); void Buban104BaoHuCmdProcess(int commid, RTUMSG *rtumsg, BOOL bUpData);
/*! /*!
\brief \brief
\param commid -- \param commid --
\param iProvAddr -- \param iProvAddr --
\param ppBaoHuDB -- \param ppBaoHuDB --
\retval -- \retval --
*/ */
int Buban104GetBaohuDataBase(int commid, int iProvAddr, GROUPDEF **ppBaoHuDB); int Buban104GetBaohuDataBase(int commid, int iProvAddr, GROUPDEF **ppBaoHuDB);
/////////////////////////通用函数接口结束/////////////////////////////// /////////////////////////通用函数接口结束///////////////////////////////
/////////////////////////buban104公共函数接口/////////////////////////// /////////////////////////buban104公共函数接口///////////////////////////
//指令缓冲区初始化 //指令缓冲区初始化
void InitBuban104CommandBuffer(int commid); void InitBuban104CommandBuffer(int commid);
//关闭socket通讯 //关闭socket通讯
void Buban104CloseSocket(u_32 commid); void Buban104CloseSocket(u_32 commid);
/////////////////////////buban104公共函数接口结束/////////////////////// /////////////////////////buban104公共函数接口结束///////////////////////
/////////////////////////以下为通用函数支持接口///////////////////////// /////////////////////////以下为通用函数支持接口/////////////////////////
void Buban104ProvMakeYkYtCommand(int commid, u_char *buf, int len); void Buban104ProvMakeYkYtCommand(int commid, u_char *buf, int len);
/////////////////////////通用函数支持接口结束/////////////////////////// /////////////////////////通用函数支持接口结束///////////////////////////
///////////////////////////以下为指令生成函数/////////////////////////// ///////////////////////////以下为指令生成函数///////////////////////////
//生成 Buban104 命令? //生成 Buban104 命令?
void MakeBuban104Command(u_32 commid, u_char cmdidx); void MakeBuban104Command(u_32 commid, u_char cmdidx);
//生成遥控遥调指令 //生成遥控遥调指令
void MakeBuBan104YkYtCommand(u_32 commid, u_char *buf, int len); void MakeBuBan104YkYtCommand(u_32 commid, u_char *buf, int len);
///////////////////////////指令生成函数结束///////////////////////////// ///////////////////////////指令生成函数结束/////////////////////////////
/////////////////////以下为POLLING规约常规函数接口////////////////////// /////////////////////以下为POLLING规约常规函数接口//////////////////////
void Buban104FindNextCmd(int commid); void Buban104FindNextCmd(int commid);
void Buban104FindNextProvCmd(int commid); void Buban104FindNextProvCmd(int commid);
void Buban104SendCmdFormPollCmdBuf(int commid); void Buban104SendCmdFormPollCmdBuf(int commid);
//////////////////////POLLING规约常规函数接口结束/////////////////////// //////////////////////POLLING规约常规函数接口结束///////////////////////
///////////////////////以下为规约处理函数接口/////////////////////////// ///////////////////////以下为规约处理函数接口///////////////////////////
//======================以下为主站数据处理============================ //======================以下为主站数据处理============================
void Buban104ProcessData(u_32 commid, BUBAN104PORTPARAM *psPortParam, BOOL bProcess); void Buban104ProcessData(u_32 commid, BUBAN104PORTPARAM *psPortParam, BOOL bProcess);
//处理数据格式I //处理数据格式I
void Buban104FormatI(RTUMSG *rtumsg); void Buban104FormatI(RTUMSG *rtumsg);
//处理数据格式U //处理数据格式U
void Buban104FormatU(RTUMSG *rtumsg); void Buban104FormatU(RTUMSG *rtumsg);
//Buban104 初始化数据处理 //Buban104 初始化数据处理
void Buban104InitdataProecss(RTUMSG * rtumsg); void Buban104InitdataProecss(RTUMSG * rtumsg);
//电度结束帧 //电度结束帧
void Buban104PidataEnd(RTUMSG * rtumsg); void Buban104PidataEnd(RTUMSG * rtumsg);
//设定确认 //设定确认
void Buban104SetAck(RTUMSG *rtumsg); void Buban104SetAck(RTUMSG *rtumsg);
//Buban104 遥控遥调返校程序 //Buban104 遥控遥调返校程序
void Buban104YkYtAck(RTUMSG * rtumsg); void Buban104YkYtAck(RTUMSG * rtumsg);
//Buban104 对时程序 //Buban104 对时程序
void Buban104SynTime(RTUMSG * rtumsg); void Buban104SynTime(RTUMSG * rtumsg);
// 子站主动传送遥信变位帧 // 子站主动传送遥信变位帧
void Buban104AutoSendDiProcess(RTUMSG *rtumsg); void Buban104AutoSendDiProcess(RTUMSG *rtumsg);
void Buban104AiWithPzDataProcess(RTUMSG *, int); void Buban104AiWithPzDataProcess(RTUMSG *, int);
@ -254,18 +254,18 @@ void Buban104SoeDataProcess(RTUMSG *rtumsg, int);
void Buban104PiDataProcess(RTUMSG * rtumsg); void Buban104PiDataProcess(RTUMSG * rtumsg);
void Buban104PiWithTimeDataProcess(RTUMSG *rtumsg); void Buban104PiWithTimeDataProcess(RTUMSG *rtumsg);
//保护数据处理 //保护数据处理
void Buban104BaoHuDataProcess(RTUMSG *rtumsg); void Buban104BaoHuDataProcess(RTUMSG *rtumsg);
void Buban104DefaultBaoHuDataProcess(RTUMSG *rtumsg); void Buban104DefaultBaoHuDataProcess(RTUMSG *rtumsg);
// 新增函数,含有 7 BYTE 的时标 // 新增函数,含有 7 BYTE 的时标
void Buban104SoeDataProcessWithCP56Time2a(RTUMSG *rtumsg, int flag); void Buban104SoeDataProcessWithCP56Time2a(RTUMSG *rtumsg, int flag);
void Buban104AiWithDataProcessWithM_ME_TD_1(RTUMSG * rtumsg); void Buban104AiWithDataProcessWithM_ME_TD_1(RTUMSG * rtumsg);
void Buban104AiWithDataProcessWithM_ME_TE_1(RTUMSG * rtumsg); void Buban104AiWithDataProcessWithM_ME_TE_1(RTUMSG * rtumsg);
void Buban104AiWithDataProcessWithM_ME_TF_1(RTUMSG * rtumsg); void Buban104AiWithDataProcessWithM_ME_TF_1(RTUMSG * rtumsg);
void Buban104PiWithTimeDataProcessWithM_IT_TB_1(RTUMSG *rtumsg); void Buban104PiWithTimeDataProcessWithM_IT_TB_1(RTUMSG *rtumsg);
//======================以下为子站数据处理============================ //======================以下为子站数据处理============================
void ProvBuban104dataProcess(int commid, RTUMSG *rtumsg); void ProvBuban104dataProcess(int commid, RTUMSG *rtumsg);
void ProvBuban104FormatI(int commid, RTUMSG *rtumsg); void ProvBuban104FormatI(int commid, RTUMSG *rtumsg);
void ProvBuban104FormatU(int commid, RTUMSG *rtumsg); void ProvBuban104FormatU(int commid, RTUMSG *rtumsg);
@ -273,7 +273,7 @@ void ProvBuban104FormatS(int commid, RTUMSG *rtumsg);
void ProvBuban104SendAllData(int commid, RTUMSG *rtumsg); void ProvBuban104SendAllData(int commid, RTUMSG *rtumsg);
void ProvBuban104SendPIData(int commid, RTUMSG *rtumsg); void ProvBuban104SendPIData(int commid, RTUMSG *rtumsg);
void ProvBuban104ProcessTime(int commid, RTUMSG *rtumsg); void ProvBuban104ProcessTime(int commid, RTUMSG *rtumsg);
//iGroupNo=0为响应总召唤 //iGroupNo=0为响应总召唤
void ProvBuban104SendPI(int commid, RTUMSG *rtumsg, int iGroupNo); void ProvBuban104SendPI(int commid, RTUMSG *rtumsg, int iGroupNo);
void ProvBuban104SendAI(int commid, RTUMSG *rtumsg, int iGroupNo); void ProvBuban104SendAI(int commid, RTUMSG *rtumsg, int iGroupNo);
void ProvBuban104SendDI(int commid, RTUMSG *rtumsg, int iGroupNo); void ProvBuban104SendDI(int commid, RTUMSG *rtumsg, int iGroupNo);
@ -287,5 +287,5 @@ void ProvMakeBuban104Command(int commid, u_char cmdidx);
void ProvBuban104SendAIwithFloat(int commid, RTUMSG *rtumsg, int iGroupNo); void ProvBuban104SendAIwithFloat(int commid, RTUMSG *rtumsg, int iGroupNo);
void ProvBuban104SendClass2withFloat(int commid); void ProvBuban104SendClass2withFloat(int commid);
/////////////////////////规约处理函数接口结束/////////////////////////// /////////////////////////规约处理函数接口结束///////////////////////////
#endif // !defined(_BUBAN104_H_200509141152__INCLUDED_) #endif // !defined(_BUBAN104_H_200509141152__INCLUDED_)

@ -4,17 +4,17 @@
#include "basetype.h" #include "basetype.h"
// 单向链表 // 单向链表
typedef struct tagSINGLELISTUNIT typedef struct tagSINGLELISTUNIT
{ {
int iLen; // 数据长度 int iLen; // 数据长度
BYTE *pBuf; // 存储内容 BYTE *pBuf; // 存储内容
struct tagSINGLELISTUNIT *pNext; // 单项链表的下一个 struct tagSINGLELISTUNIT *pNext; // 单项链表的下一个
}SINGLELISTUNIT; }SINGLELISTUNIT;
typedef struct tagSINGLELIST typedef struct tagSINGLELIST
{ {
int iDevId; // 端口号(高2个字节为端口号, 低2个字节为装置号) int iDevId; // 端口号(高2个字节为端口号, 低2个字节为装置号)
int iNum; int iNum;
int iMaxNum; int iMaxNum;
SINGLELISTUNIT *pHead; SINGLELISTUNIT *pHead;
@ -23,10 +23,10 @@ typedef struct tagSINGLELIST
typedef struct tagDOUBLELISTUNIT typedef struct tagDOUBLELISTUNIT
{ {
int iDataLen; // 数据长度 int iDataLen; // 数据长度
BYTE *pDataBuf; // 存储内容 BYTE *pDataBuf; // 存储内容
struct tagDOUBLELISTUNIT *pNext; // 双向链表的下一个 struct tagDOUBLELISTUNIT *pNext; // 双向链表的下一个
struct tagDOUBLELISTUNIT *pFore; // 双向链表的前一个 struct tagDOUBLELISTUNIT *pFore; // 双向链表的前一个
}DOUBLELISTUNIT; }DOUBLELISTUNIT;
typedef struct tagDOUBLELIST typedef struct tagDOUBLELIST

@ -0,0 +1,934 @@
# -*- indent-tabs-mode:nil; -*-
# vim: set expandtab:
#
# Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0, as
# published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation. The authors of MySQL hereby grant you an
# additional permission to link the program and your derivative works
# with the separately licensed software that they have included with
# MySQL.
#
# Without limiting anything contained in the foregoing, this file,
# which is part of MySQL Connector/ODBC, is also subject to the
# Universal FOSS Exception, version 1.0, a copy of which can be found at
# http://oss.oracle.com/licenses/universal-foss-exception.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
##########################################################################
##########################################################################
#
# Configuration variables, all optional, are
#
# MYSQL_DIR - Set in environment or as parameter to "cmake",
# this is the top directory of the MySQL Server or
# Connector/C install
# MYSQL_INCLUDE_DIR - Set in environment or as parameter to "cmake",
# this is the include directory where to find
# the client library
# MYSQL_LIB_DIR - Set in environment or as parameter to "cmake",
# this is the library directory where to find
# the client library
# MYSQLCLIENT_STATIC_LINKING
# - Specify that you want static linking, dynamic
# linking is the default
# MYSQLCLIENT_NO_THREADS
# - Specify to link against the single threaded
# library, "libmysqlclient". Note that in 5.5
# and up "libmysqlclient" is multithreaded and
# "libmysqlclient_r" just a soft link to it
# MYSQL_CONFIG_EXECUTABLE
# - "mysql_config" executable to use
# MYSQL_CXX_LINKAGE - Specify that client library needs C++ linking
# MYSQL_EXTRA_LIBRARIES
# - Libraries to add to the linkage
# MYSQL_CFLAGS - C compiler flags
# MYSQL_CXXFLAGS - C++ compiler flags
# MYSQL_LINK_FLAGS - User defined extra linkage flags
# FINDMYSQL_DEBUG - Set if want debug output from this script
#
# Note that most variables above, if not set by the user they will be
# set by this include file.
#
# In addition, the below CMake variables are set by this include file
#
# MYSQL_VERSION - Three position numeric version, like 5.6.41
# MYSQL_VERSION_ID - Numeric padded version, 5.13.4 => 51304
# MYSQL_NUM_VERSION - Same as MYSQL_VERSION_ID, for compatibility
# MYSQL_LIB - Path to the client library
# MYSQL_LIBRARIES - Library name, might be "-lmysqlclient" while
# MYSQL_LIB is the path to the library
# MYSQL_CLIENT_LIBS - Same as MYSQL_LIBRARIES, for compatibility
#
# (1) If MYSQL_INCLUDE_DIR or MYSQL_LIB_DIR are given, these are
# used and an error is reported if can't be used
# (2) If MYSQL_CONFIG_EXECUTABLE is given, it is used to get
# headers and libraries
# (3) If MYSQL_DIR is given and "${MYSQL_DIR}/bin/mysql_config" is
# found, then same as (2)
# (4) If MYSQL_DIR is given and no "${MYSQL_DIR}/bin/mysql_config",
# search MYSQL_DIR
#
# FIXME if we get a "mysql_config" on Windows, things needs to change
# FIXME rename the VERSION variables above
# FIXME let MYSQL_VERSION include "-beta" etc?
# FIXME can mysql_config --version be C/C verson?
# FIXME if no mysql_config, find version from include/mysql_version.h?
# #define MYSQL_SERVER_VERSION "5.7.5-m15"
# #define MYSQL_VERSION_ID 50705
# #define LIBMYSQL_VERSION "6.1.5"
# #define LIBMYSQL_VERSION_ID 60105
# FIXME can MYSQL_LIB_DIR be a list of paths?
# FIXME is MYSQLCLIENT_LIBS a better name?
# FIXME cache variables, makes them command line args?
# FIXME really do include_directories() and link_directories()? Likely
# FIXME add check that if not static, not picked up .a or mysqlclient.lib
# FIXME MYSQL_VERSION_ID need to take into account Cluster versions
# and Connector/C versions
# FIXME handle MYSQL_VERSION_ID, LIBMYSQL_VERSION and LIBMYSQL_VERSION_ID?
#
##########################################################################
##########################################################################
#
# Check the input data
#
##########################################################################
# If using both MYSQL_DIR as a cmake argument and set in environment,
# and not empty strings, they better be the same. Else stop and complain
set(ENV_OR_OPT_VARS
MYSQL_DIR
MYSQL_INCLUDE_DIR
MYSQL_LIB_DIR
MYSQL_LIB_DIR_LIST
MYSQL_PLUGIN_DIR
MYSQL_CFLAGS
MYSQL_CXXFLAGS
MYSQL_CONFIG_EXECUTABLE
MYSQLCLIENT_STATIC_LINKING
MYSQLCLIENT_NO_THREADS
MYSQL_CXX_LINKAGE
MYSQL_EXTRA_LIBRARIES
MYSQL_LINK_FLAGS
)
# Mark the variable names that have values that are paths
set(ENV_OR_OPT_PATH_VARS
MYSQL_DIR
MYSQL_INCLUDE_DIR
MYSQL_LIB_DIR
MYSQL_PLUGIN_DIR
)
foreach(_xvar ${ENV_OR_OPT_VARS})
if((DEFINED ${_xvar}) AND
(DEFINED ENV{${_xvar}}) AND
(NOT "${${_xvar}}" STREQUAL "") AND
(NOT "$ENV{${_xvar}}" STREQUAL "") AND
(NOT "$ENV{${_xvar}}" STREQUAL "${${_xvar}}"))
message(FATAL_ERROR "Please pass -D${_xvar}=... as an argument or "
"set ${_xvar} in the environment, but not both")
endif()
# Now we know both are not set, set the CMake variable if needed
if((DEFINED ENV{${_xvar}}) AND (NOT "$ENV{${_xvar}}" STREQUAL ""))
set(${_xvar} $ENV{${_xvar}})
endif()
# Notmalize the path if the variable is set and is a path
if(${_xvar})
list(FIND ENV_OR_OPT_PATH_VARS ${_xvar} _index)
if (${_index} GREATER -1)
file(TO_CMAKE_PATH "${${_xvar}}" ${_xvar})
get_filename_component(${_xvar} ${${_xvar}} ABSOLUTE)
endif()
endif()
endforeach()
# Bail out if both MYSQL_DIR/MYSQL_CONFIG_EXECUTABLE and MYSQL_INCLUDE/LIB_DIR
# were given
if(MYSQL_DIR AND (MYSQL_INCLUDE_DIR OR MYSQL_LIB_DIR OR MYSQL_PLUGIN_DIR))
message(FATAL_ERROR
"Both MYSQL_DIR and MYSQL_INCLUDE_DIR/MYSQL_LIB_DIR/MYSQL_PLUGIN_DIR were specified,"
" use either one or the other way of pointing at MySQL location."
)
endif()
if (MYSQL_CONFIG_EXECUTABLE AND (MYSQL_INCLUDE_DIR OR MYSQL_LIB_DIR OR MYSQL_PLUGIN_DIR))
message(FATAL_ERROR
"Both MYSQL_CONFIG_EXECUTABLE and MYSQL_INCLUDE_DIR/MYSQL_LIB_DIR/MYSQL_PLUGIN_DIR were specified,"
" mixing settings detected with mysql_config and manually set by variables"
" is not supported and would confuse our build logic."
)
endif()
if(MYSQL_CONFIG_EXECUTABLE)
set(_mysql_config_set_by_user 1)
else()
# If MYSQL_DIR is set, set MYSQL_CONFIG_EXECUTABLE
if((NOT WIN32) AND
(DEFINED MYSQL_DIR) AND
(EXISTS "${MYSQL_DIR}/bin/mysql_config"))
set(MYSQL_CONFIG_EXECUTABLE "${MYSQL_DIR}/bin/mysql_config")
set(_mysql_config_in_mysql_dir 1)
endif()
endif()
##########################################################################
#
# Data and basic settings
#
##########################################################################
# Set sub directory to search in
# dist = for mysql binary distributions
# build = for custom built tree
if(CMAKE_BUILD_TYPE STREQUAL Debug)
set(_lib_suffix_dist debug)
set(_lib_suffix_build Debug)
else()
set(_lib_suffix_dist opt)
set(_lib_suffix_build Release)
add_definitions(-DNDEBUG) # FIXME what?!
endif()
set(_exe_fallback_path
/usr/bin
/usr/local/bin
/opt/mysql/mysql/bin
/usr/local/mysql/bin
)
set(_include_fallback_path
/usr/include/mysql
/usr/local/include/mysql
/opt/mysql/mysql/include
/opt/mysql/mysql/include/mysql
/usr/local/mysql/include
/usr/local/mysql/include/mysql
$ENV{ProgramFiles}/MySQL/*/include
$ENV{SystemDrive}/MySQL/*/include
)
set(_lib_fallback_path
/usr/lib/mysql
/usr/local/lib/mysql
/usr/local/mysql/lib
/usr/local/mysql/lib/mysql
/opt/mysql/mysql/lib
/opt/mysql/mysql/lib/mysql
$ENV{ProgramFiles}/MySQL/*/lib/${_lib_suffix_dist}
$ENV{ProgramFiles}/MySQL/*/lib
$ENV{SystemDrive}/MySQL/*/lib/${_lib_suffix_dist}
$ENV{SystemDrive}/MySQL/*/lib
)
set(_lib_subdirs
# Paths in build tree, really being too nice
libmysql/${_lib_suffix_build}
client/${_lib_suffix_build}
libmysql_r/.libs
libmysql/.libs
libmysql
# Install sub directories
lib/mysql
lib/${_lib_suffix_dist} # Need to be before "lib"
lib
)
set(_static_subdirs
mysql
${_lib_suffix_dist}
)
if(MSVC90)
set(_vs_subdir vs9)
elseif(MSVC10)
set(_vs_subdir vs10)
elseif(MSVC11)
set(_vs_subdir vs11)
elseif(MSVC12)
set(_vs_subdir vs12)
elseif(MSVC13)
set(_vs_subdir vs13)
elseif(MSVC14)
set(_vs_subdir vs14)
elseif(MSVC15)
set(_vs_subdir vs15)
endif()
if(_vs_subdir)
if("${_lib_suffix_dist}" STREQUAL "debug")
set(_vs_subdir "${_vs_subdir}/debug")
endif()
list(INSERT _lib_subdirs 0 "lib/${_vs_subdir}")
endif()
# For Windows, the client library name differs, so easy to
# make sure find_library() picks the right one. For Unix, it
# is the file extension that differs. In the static library
# case we know it is ".a", so we add it to the library name
# we search for to make sure it is picked in the static case.
if(WIN32)
set(_dynamic_libs "libmysql")
set(_static_libs "mysqlclient")
set(_static_lib_ext ".lib") # Careful, can be import library for DLL
elseif(MYSQLCLIENT_NO_THREADS)
# In 5.1 and below there is a single threaded library
set(_dynamic_libs "mysqlclient")
set(_static_libs "libmysqlclient.a")
set(_static_lib_ext ".a")
else()
# We try the multithreaded "libmysqlclient_r" first and if not
# there, pick "libmysqlclient" that in 5.5 and up is multithreaded
# anyway (soft link "libmysqlclient_r" is not installed MySQL Server
# 5.6 and Debian/Ubuntu and might go in 5.7 for all installs)
set(_dynamic_libs "mysqlclient_r" "mysqlclient")
set(_static_libs "libmysqlclient_r.a" "libmysqlclient.a")
set(_static_lib_ext ".a")
endif()
if(MYSQLCLIENT_STATIC_LINKING)
set(_link_type "static")
set(_search_libs ${_static_libs})
else()
set(_link_type "dynamic")
set(_search_libs ${_dynamic_libs})
endif()
# Just to pretty print in error messages
string(REPLACE ";" " " _pp_search_libs "${_search_libs}")
string(REPLACE ";" " " _pp_lib_subdirs "${_lib_subdirs}")
string(REPLACE ";" " " _pp_lib_fallback_path "${_lib_fallback_path}")
string(REPLACE ";" " " _pp_include_fallback_path "${_include_fallback_path}")
message(STATUS "You will link ${_link_type}ally to the MySQL client"
" library (set with -DMYSQLCLIENT_STATIC_LINKING=<bool>)")
message(STATUS "Searching for ${_link_type} libraries with the base name(s) \"${_pp_search_libs}\"")
##########################################################################
#
# Macros
#
##########################################################################
# ----------------------------------------------------------------------
#
# Macro that runs "mysql_config ${_opt}" and return the line after
# trimming away ending space/newline.
#
# _mysql_conf(
# _var - output variable name, will contain a ';' separated list
# _opt - the flag to give to mysql_config
#
# ----------------------------------------------------------------------
macro(_mysql_conf _var _opt)
execute_process(
COMMAND ${MYSQL_CONFIG_EXECUTABLE} ${_opt}
OUTPUT_VARIABLE ${_var}
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endmacro()
# ----------------------------------------------------------------------
#
# Macro that runs "mysql_config ${_opt}", selects output args using a
# regex, and clean it up a bit removing space/tab/newline before
# setting it to a variable.
#
# _mysql_config(
# _var - output variable name, will contain a ';' separated list
# _regex - regular expression matching the prefix of args to select
# _opt - the flag to give to mysql_config
#
# ----------------------------------------------------------------------
macro(_mysql_config _var _regex _opt)
_mysql_conf(_mysql_config_output ${_opt})
string(REGEX MATCHALL "${_regex}([^ ]+)" _mysql_config_output "${_mysql_config_output}")
string(REGEX REPLACE "^[ \t]+" "" _mysql_config_output "${_mysql_config_output}")
IF(CMAKE_SYSTEM_NAME MATCHES "SunOS")
string(REGEX REPLACE " -latomic" "" _mysql_config_output "${_mysql_config_output}")
ENDIF()
string(REGEX REPLACE "${_regex}" "" _mysql_config_output "${_mysql_config_output}")
separate_arguments(_mysql_config_output)
set(${_var} ${_mysql_config_output})
endmacro()
# ----------------------------------------------------------------------
#
# Macro that runs "mysql_config ${_opt}" and selects output using a
# prefix regex. Cleans it up a bit removing space/tab/newline. Then
# removes the prefix on all in the list, and finally replace what
# matches another regular expression with a replacement string.
#
# _mysql_config_replace(
# _var - output variable name, will contain a ';' separated list
# _regex1 - regular expression to match out arguments
# _replace - what to replace match _regex1 with
# _regex2 - regular expression matching the prefix of args to select
# _opt - the flag to give to mysql_config
#
# ----------------------------------------------------------------------
macro(_mysql_config_replace _var _regex1 _replace _regex2 _opt)
_mysql_conf(_mysql_config_output ${_opt})
string(REGEX MATCHALL "${_regex2}([^ ]+)" _mysql_config_output "${_mysql_config_output}")
string(REGEX REPLACE "^[ \t]+" "" _mysql_config_output "${_mysql_config_output}")
IF(CMAKE_SYSTEM_NAME MATCHES "SunOS")
string(REGEX REPLACE " -latomic" "" _mysql_config_output "${_mysql_config_output}")
ENDIF()
string(REGEX REPLACE "${_regex2}" "" _mysql_config_output "${_mysql_config_output}")
string(REGEX REPLACE "${_regex1}" "${_replace}" _mysql_config_output "${_mysql_config_output}")
separate_arguments(_mysql_config_output)
set(${_var} ${_mysql_config_output})
endmacro()
# ----------------------------------------------------------------------
#
# Macro to check that we found a library and that we got the right type
#
# ----------------------------------------------------------------------
macro(_check_lib_search_error _lib_dir_var _lib_var _exta_err_string)
set(_lib "${${_lib_var}}")
set(_lib_dir "${${_lib_dir_var}}")
if(FINDMYSQL_DEBUG)
message("_lib \"${_lib}\"")
message("_lib_dir \"${_lib_dir}\"")
message("_lib_var \"${_lib_var}\"")
message("_lib_dir_var \"${_lib_dir_var}\"")
endif()
set(_err_string "Could not find ${_link_type} "
"\"${_pp_search_libs}\" in ${_lib_dir_var} "
"\"${_lib_dir}\" ${_exta_err_string}")
if(NOT ${_lib_var})
message(FATAL_ERROR ${_err_string})
endif()
# find_library() try find a shared library first, then a static
# one. For Windows the library has a different name, but for
# Unix only the extension differs. So we check here that we
# got the library kind we expected.
if(NOT WIN32)
if(NOT MYSQLCLIENT_STATIC_LINKING)
get_filename_component(_ext ${_lib} EXT)
if(${_ext} STREQUAL ${_static_lib_ext})
message(FATAL_ERROR ${_err_string})
endif()
endif()
endif()
endmacro()
##########################################################################
#
# Try find MYSQL_CONFIG_EXECUTABLE if not set, and find version
#
##########################################################################
if(NOT WIN32)
if(NOT MYSQL_CONFIG_EXECUTABLE)
find_program(MYSQL_CONFIG_EXECUTABLE
NAMES
mysql_config
DOC
"full path of mysql_config"
PATHS
${_exe_fallback_path}
)
endif()
if(MYSQL_CONFIG_EXECUTABLE)
message(STATUS "mysql_config was found ${MYSQL_CONFIG_EXECUTABLE}")
_mysql_conf(MYSQL_VERSION "--version")
endif()
endif()
##########################################################################
#
# Find MYSQL_INCLUDE_DIR
#
##########################################################################
if(FINDMYSQL_DEBUG AND MYSQL_INCLUDE_DIR)
message("DBG: User gave MYSQL_INCLUDE_DIR = \"${MYSQL_INCLUDE_DIR}\"")
endif()
if(FINDMYSQL_DEBUG AND MYSQL_DIR)
message("DBG: User gave MYSQL_DIR = \"${MYSQL_DIR}\"")
endif()
if(MYSQL_INCLUDE_DIR)
if(FINDMYSQL_DEBUG)
message("DBG: Using MYSQL_INCLUDE_DIR to find \"mysql.h\"")
endif()
if(NOT EXISTS "${MYSQL_INCLUDE_DIR}/mysql.h")
message(FATAL_ERROR "MYSQL_INCLUDE_DIR given, but no \"mysql.h\" "
"in \"${MYSQL_INCLUDE_DIR}\"")
endif()
elseif(MYSQL_DIR AND
(NOT _mysql_config_in_mysql_dir) AND
(NOT _mysql_config_set_by_user))
if(FINDMYSQL_DEBUG)
message("DBG: Using MYSQL_DIR without \"mysql_config\" to find \"mysql.h\"")
endif()
set(MYSQL_INCLUDE_DIR "${MYSQL_DIR}/include")
if(NOT EXISTS "${MYSQL_INCLUDE_DIR}/mysql.h")
message(FATAL_ERROR "MYSQL_DIR given, but no \"mysql.h\" "
"in \"${MYSQL_INCLUDE_DIR}\"")
endif()
elseif(MYSQL_CONFIG_EXECUTABLE)
if(FINDMYSQL_DEBUG)
message("DBG: Using \"mysql_config\" to find \"mysql.h\"")
endif()
# This code assumes there is just one "-I...." and that
# no space between "-I" and the path
_mysql_config(MYSQL_INCLUDE_DIR "(^| )-I" "--include")
if(NOT MYSQL_INCLUDE_DIR)
message(FATAL_ERROR "Could not find the include dir from running "
"\"${MYSQL_CONFIG_EXECUTABLE}\"")
endif()
if(NOT EXISTS "${MYSQL_INCLUDE_DIR}/mysql.h")
message(FATAL_ERROR "Could not find \"mysql.h\" in \"${MYSQL_INCLUDE_DIR}\" "
"found from running \"${MYSQL_CONFIG_EXECUTABLE}\"")
endif()
else()
if(FINDMYSQL_DEBUG)
message("DBG: Using find_path() searching "
"\"${_pp_include_fallback_path}\" to find \"mysql.h\"")
endif()
# No specific paths, try some common install paths
find_path(MYSQL_INCLUDE_DIR mysql.h ${_include_fallback_path})
if(NOT MYSQL_INCLUDE_DIR)
message(FATAL_ERROR "Could not find \"mysql.h\" from searching "
"\"${_pp_include_fallback_path}\"")
endif()
endif()
if(FINDMYSQL_DEBUG)
message("DBG: MYSQL_INCLUDE_DIR = \"${MYSQL_INCLUDE_DIR}\"")
endif()
##########################################################################
#
# Find MYSQL_LIB_DIR, MYSQL_LIB, MYSQL_PLUGIN_DIR and MYSQL_LIBRARIES
#
##########################################################################
if(FINDMYSQL_DEBUG AND MYSQL_LIB_DIR)
message("DBG: User gave MYSQL_LIB_DIR = \"${MYSQL_LIB_DIR}\"")
endif()
if(MYSQL_LIB_DIR)
if(FINDMYSQL_DEBUG)
message("DBG: Using find_library() searching MYSQL_LIB_DIR")
endif()
find_library(MYSQL_LIB
NAMES
${_search_libs}
PATHS
"${MYSQL_LIB_DIR}"
NO_DEFAULT_PATH
)
_check_lib_search_error(MYSQL_LIB_DIR MYSQL_LIB "")
set(MYSQL_LIBRARIES ${MYSQL_LIB})
if(NOT DEFINED MYSQL_PLUGIN_DIR)
set(MYSQL_PLUGIN_DIR "${MYSQL_LIB_DIR}/plugin")
endif()
elseif(MYSQL_DIR AND
(NOT _mysql_config_in_mysql_dir) AND
(NOT _mysql_config_set_by_user))
if(FINDMYSQL_DEBUG)
message("DBG: Using find_library() searching "
"MYSQL_DIR and \"${_pp_lib_subdirs}\"")
endif()
find_library(MYSQL_LIB
NAMES
${_search_libs}
PATHS
"${MYSQL_DIR}"
PATH_SUFFIXES
${_lib_subdirs}
NO_DEFAULT_PATH
)
_check_lib_search_error(MYSQL_DIR MYSQL_LIB "in \"${_pp_lib_subdirs}\"")
get_filename_component(MYSQL_LIB_DIR "${MYSQL_LIB}" PATH)
set(MYSQL_LIBRARIES "${MYSQL_LIB}")
if(((NOT DEFINED MYSQL_PLUGIN_DIR) OR (NOT ${MYSQL_PLUGIN_DIR})) AND MYSQL_LIB_DIR)
if(EXISTS "${MYSQL_LIB_DIR}/plugin")
set(MYSQL_PLUGIN_DIR "${MYSQL_LIB_DIR}/plugin")
else()
#If directory does not exist it must be a debug dir layout
if(EXISTS "${MYSQL_LIB_DIR}/../plugin/")
set(MYSQL_PLUGIN_DIR "${MYSQL_LIB_DIR}/../plugin")
endif()
endif()
endif()
elseif(MYSQL_CONFIG_EXECUTABLE)
if(FINDMYSQL_DEBUG)
message("DBG: Using \"mysql_config\" to find the libraries")
endif()
# This code assumes there is just one "-L...." and that
# no space between "-L" and the path
_mysql_config(MYSQL_LIB_DIR "(^| )-L" "--libs")
_mysql_conf(MYSQL_PLUGIN_DIR "--variable=plugindir")
IF(CMAKE_SYSTEM_NAME MATCHES "SunOS")
# This is needed to make Solaris binaries using the default runtime lib path
_mysql_config(DEV_STUDIO_RUNTIME_DIR "(^| )-R" "--libs")
ENDIF()
LIST(LENGTH MYSQL_LIB_DIR dir_cnt)
MESSAGE(STATUS "Libraries paths found: ${n}")
IF(${dir_cnt} GREATER 1)
SET(MYSQL_LIB_DIR_LIST ${MYSQL_LIB_DIR})
MESSAGE(STATUS "MYSQL_LIB_DIR_LIST = ${MYSQL_LIB_DIR_LIST}")
FOREACH(_path_to_check IN LISTS MYSQL_LIB_DIR)
FIND_LIBRARY(_mysql_client_lib_var
NAMES ${_search_libs}
PATHS ${_path_to_check}
NO_DEFAULT_PATH
)
IF(_mysql_client_lib_var)
MESSAGE(STATUS "CLIENT LIB VAR: ${_mysql_client_lib_var}")
unset(_mysql_client_lib_var CACHE)
set(MYSQL_LIB_DIR ${_path_to_check})
ENDIF()
ENDFOREACH(_path_to_check)
ENDIF()
if(NOT MYSQL_LIB_DIR)
message(FATAL_ERROR "Could not find the library dir from running "
"\"${MYSQL_CONFIG_EXECUTABLE}\"")
endif()
if(NOT EXISTS "${MYSQL_LIB_DIR}")
message(FATAL_ERROR "Could not find the directory \"${MYSQL_LIB_DIR}\" "
"found from running \"${MYSQL_CONFIG_EXECUTABLE}\"")
endif()
# We have the assumed MYSQL_LIB_DIR. The output from "mysql_config"
# might not be correct for static libraries, so we might need to
# adjust MYSQL_LIB_DIR later on.
if(MYSQLCLIENT_STATIC_LINKING)
# Find the static library, might be one level down
find_library(MYSQL_LIB
NAMES
${_search_libs}
PATHS
${MYSQL_LIB_DIR}
PATH_SUFFIXES
${_static_subdirs}
NO_DEFAULT_PATH
)
_check_lib_search_error(MYSQL_LIB_DIR MYSQL_LIB "in \"${_static_subdirs}\"")
# Adjust MYSQL_LIB_DIR in case it changes
get_filename_component(MYSQL_LIB_DIR "${MYSQL_LIB}" PATH)
# Replace the current library references with the full path
# to the library, i.e. the -L will be ignored
_mysql_config_replace(MYSQL_LIBRARIES
"(mysqlclient|mysqlclient_r)" "${MYSQL_LIB}" "(^| )-l" "--libs")
else()
_mysql_config(MYSQL_LIBRARIES "(^| )-l" "--libs")
FOREACH(__lib IN LISTS MYSQL_LIBRARIES)
string(REGEX MATCH "mysqlclient([^ ]*)" _matched_lib __lib)
IF(_matched_lib)
set(_search_libs ${matched_lib})
ENDIF()
ENDFOREACH()
# First library is assumed to be the client library
# list(GET MYSQL_LIBRARIES 0 _search_libs)
find_library(MYSQL_LIB
NAMES
${_search_libs}
PATHS
${MYSQL_LIB_DIR}
NO_DEFAULT_PATH
)
_check_lib_search_error(MYSQL_LIB_DIR MYSQL_LIB "")
endif()
else()
if(FINDMYSQL_DEBUG)
message("DBG: Using find_library() searching "
"\"${_pp_lib_fallback_path}\" to find the client library")
endif()
# Search standard places
find_library(MYSQL_LIB
NAMES
${_search_libs}
PATHS
${_lib_fallback_path}
)
if(NOT MYSQL_LIB)
message(FATAL_ERROR "Could not find \"${_pp_search_libs}\" from searching "
"\"${_pp_lib_fallback_path}\"")
endif()
get_filename_component(MYSQL_LIB_DIR "${MYSQL_LIB}" PATH)
endif()
##########################################################################
#
# Add more libraries to MYSQL_LIBRARIES
#
##########################################################################
# FIXME needed?!
if(MYSQLCLIENT_STATIC_LINKING AND
NOT WIN32 AND
NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
list(APPEND MYSQL_LIBRARIES "rt")
endif()
# For dynamic linking use the built-in sys and strings
if(NOT MYSQLCLIENT_STATIC_LINKING)
list(APPEND SYS_LIBRARIES "mysql_sys")
list(APPEND SYS_LIBRARIES "mysql_strings")
list(APPEND SYS_LIBRARIES ${MYSQL_LIBRARIES})
SET(MYSQL_LIBRARIES ${SYS_LIBRARIES})
#if(NOT MYSQLCLIENT_STATIC_LINKING AND ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# list(REVERSE MYSQL_LIBRARIES)
#endif()
endif()
if(MYSQL_EXTRA_LIBRARIES)
separate_arguments(MYSQL_EXTRA_LIBRARIES)
list(APPEND MYSQL_LIBRARIES ${MYSQL_EXTRA_LIBRARIES})
endif()
list(LENGTH MYSQL_LIBRARIES len)
if (MYSQL_STATIC_LINKING AND (len LESS 2))
message(WARNING
"Statically linking MySQL client library normally requires linking"
" additional libraries that the client library depends on. It seems"
" no extra libraries have been specified. Provide the list of required"
" dependencies through MYSQL_EXTRA_LIBRARIES."
)
endif()
# For compatibility
SET(MYSQL_CLIENT_LIBS ${MYSQL_LIBRARIES})
##########################################################################
#
# If not found MySQL Serverv version, compile a small client app
# and let it write a small cmake file with the settings
#
##########################################################################
if(MYSQL_INCLUDE_DIR AND NOT MYSQL_VERSION)
# Write the C source file that will include the MySQL headers
set(GETMYSQLVERSION_SOURCEFILE "${CMAKE_CURRENT_BINARY_DIR}/getmysqlversion.c")
file(WRITE "${GETMYSQLVERSION_SOURCEFILE}"
"#include <mysql.h>\n"
"#include <stdio.h>\n"
"int main() {\n"
" printf(\"%s\", MYSQL_SERVER_VERSION);\n"
"}\n"
)
# Compile and run the created executable, store output in MYSQL_VERSION
try_run(_run_result _compile_result
"${CMAKE_BINARY_DIR}"
"${GETMYSQLVERSION_SOURCEFILE}"
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${MYSQL_INCLUDE_DIR}"
RUN_OUTPUT_VARIABLE MYSQL_VERSION
)
if(FINDMYSQL_DEBUG)
if(NOT _compile_result)
message("DBG: Could not compile \"getmysqlversion.c\"")
endif()
if(_run_result)
message("DBG: Running \"getmysqlversion\" returned ${_run_result}")
endif()
endif()
endif()
##########################################################################
#
# Clean up MYSQL_VERSION and create MYSQL_VERSION_ID/MYSQL_NUM_VERSION
#
##########################################################################
if(NOT MYSQL_VERSION)
message(FATAL_ERROR "Could not determine the MySQL Server version")
endif()
# Clean up so only numeric, in case of "-alpha" or similar
string(REGEX MATCHALL "([0-9]+.[0-9]+.[0-9]+)" MYSQL_VERSION "${MYSQL_VERSION}")
# To create a fully numeric version, first normalize so N.NN.NN
string(REGEX REPLACE "[.]([0-9])[.]" ".0\\1." MYSQL_VERSION_ID "${MYSQL_VERSION}")
string(REGEX REPLACE "[.]([0-9])$" ".0\\1" MYSQL_VERSION_ID "${MYSQL_VERSION_ID}")
# Finally remove the dot
string(REGEX REPLACE "[.]" "" MYSQL_VERSION_ID "${MYSQL_VERSION_ID}")
set(MYSQL_NUM_VERSION ${MYSQL_VERSION_ID})
##########################################################################
#
# Try determine if to use C++ linkage, and also find C++ flags
#
##########################################################################
if(NOT WIN32)
if(MYSQL_CONFIG_EXECUTABLE)
if(NOT MYSQL_CFLAGS)
_mysql_conf(MYSQL_CFLAGS "--cflags")
endif()
if(NOT MYSQL_CXXFLAGS)
if(MYSQL_CXX_LINKAGE OR MYSQL_VERSION_ID GREATER 50603)
_mysql_conf(MYSQL_CXXFLAGS "--cxxflags")
set(MYSQL_CXX_LINKAGE 1)
else()
set(MYSQL_CXXFLAGS "${MYSQL_CFLAGS}")
endif()
endif()
# FIXME this should not be needed, caller of this module should set
# it's own flags and just use the library on it's on terms
# (change the infe message if enabling this code)
# if(NOT MYSQL_LINK_FLAGS)
# # Find -mcpu -march -mt -m32 -m64 and other flags starting with "-m"
# string(REGEX MATCHALL "(^| )-m([^\r\n ]+)" MYSQL_LINK_FLAGS "${MYSQL_CXXFLAGS}")
# string(REGEX REPLACE "^ " "" MYSQL_LINK_FLAGS "${MYSQL_LINK_FLAGS}")
# string(REGEX REPLACE "; " ";" MYSQL_LINK_FLAGS "${MYSQL_LINK_FLAGS}")
# endif()
endif()
endif()
##########################################################################
#
# Inform CMake where to look for headers and libraries
#
##########################################################################
# string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKEBT)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MYSQL_CXXFLAGS}")
# set(CMAKE_CXX_FLAGS_${CMAKEBT} "${CMAKE_CXX_FLAGS_${CMAKEBT}} ${MYSQL_CXXFLAGS}")
include_directories("${MYSQL_INCLUDE_DIR}")
link_directories("${MYSQL_LIB_DIR}")
MESSAGE(STATUS "MYSQL_LIB_DIR_LIST = ${MYSQL_LIB_DIR_LIST}")
IF(MYSQL_LIB_DIR_LIST)
FOREACH(__libpath IN LISTS MYSQL_LIB_DIR_LIST)
link_directories("${__libpath}")
ENDFOREACH()
ENDIF()
##########################################################################
#
# Report
#
##########################################################################
message(STATUS "MySQL client environment/cmake variables set that the user can override")
message(STATUS " MYSQL_DIR : ${MYSQL_DIR}")
message(STATUS " MYSQL_INCLUDE_DIR : ${MYSQL_INCLUDE_DIR}")
message(STATUS " MYSQL_LIB_DIR : ${MYSQL_LIB_DIR}")
message(STATUS " MYSQL_PLUGIN_DIR : ${MYSQL_PLUGIN_DIR}")
message(STATUS " MYSQL_CONFIG_EXECUTABLE : ${MYSQL_CONFIG_EXECUTABLE}")
message(STATUS " MYSQL_CXX_LINKAGE : ${MYSQL_CXX_LINKAGE}")
message(STATUS " MYSQL_CFLAGS : ${MYSQL_CFLAGS}")
message(STATUS " MYSQL_CXXFLAGS : ${MYSQL_CXXFLAGS}")
message(STATUS " MYSQLCLIENT_STATIC_LINKING : ${MYSQLCLIENT_STATIC_LINKING}")
message(STATUS " MYSQLCLIENT_NO_THREADS : ${MYSQLCLIENT_NO_THREADS}")
message(STATUS "MySQL client optional environment/cmake variables set by the user")
message(STATUS " MYSQL_EXTRA_LIBRARIES : ${MYSQL_EXTRA_LIBRARIES}")
message(STATUS " MYSQL_LINK_FLAGS : ${MYSQL_LINK_FLAGS}")
message(STATUS "MySQL client settings that the user can't override")
message(STATUS " MYSQL_VERSION : ${MYSQL_VERSION}")
message(STATUS " MYSQL_VERSION_ID : ${MYSQL_VERSION_ID}")
message(STATUS " MYSQL_LIB : ${MYSQL_LIB}")
message(STATUS " MYSQL_LIBRARIES : ${MYSQL_LIBRARIES}")

File diff suppressed because it is too large Load Diff

@ -10,7 +10,7 @@
#define MSGTYPE_BAOHU_SCADACMD MSGTYPE_BAOHU_BASE+2 #define MSGTYPE_BAOHU_SCADACMD MSGTYPE_BAOHU_BASE+2
#define MSGTYPE_BAOHU_SCADADATA MSGTYPE_BAOHU_BASE+3 #define MSGTYPE_BAOHU_SCADADATA MSGTYPE_BAOHU_BASE+3
// 从 config.ini 或 portconfig.ini 读信息 // 从 config.ini 或 portconfig.ini 读信息
u_long GetPrivateProString(const char *section, const char *entry, const char *defaultstr, char *result, int len, char *inifile); u_long GetPrivateProString(const char *section, const char *entry, const char *defaultstr, char *result, int len, char *inifile);
int GetPrivateProInt(const char *section, const char *entry, int idefault, char *inifile); int GetPrivateProInt(const char *section, const char *entry, int idefault, char *inifile);
u_long GetPrivateProString2(const char *section, const char *entry, const char *defaultstr, char *result, int len, HDSFILE hFile); u_long GetPrivateProString2(const char *section, const char *entry, const char *defaultstr, char *result, int len, HDSFILE hFile);
@ -19,7 +19,7 @@ int GetPrivateProInt2(const char *section, const char *entry, int idefault, HDSF
int PutDataToBuf( DATA_BUF *buf, u_char *msg, int len ); int PutDataToBuf( DATA_BUF *buf, u_char *msg, int len );
int GetDataFormBuf( DATA_BUF *databuf, u_char *buf, int len, int clrflag ); int GetDataFormBuf( DATA_BUF *databuf, u_char *buf, int len, int clrflag );
// 读设备信息,检查芯片状态和读芯片类型和频率 // 读设备信息,检查芯片状态和读芯片类型和频率
void ReadPortConfigInfo( u_short ); void ReadPortConfigInfo( u_short );
void ReadPortConfigInfoEx(u_short); void ReadPortConfigInfoEx(u_short);
@ -38,9 +38,9 @@ int CheckPollCmdBufEmpty( int port );
int PutPollCmdToBuf( int port, int type, WORD wait, char *buf, int len ); int PutPollCmdToBuf( int port, int type, WORD wait, char *buf, int len );
void SendCmdFormPollCmdBuf( int port ); void SendCmdFormPollCmdBuf( int port );
// wen 2005.09.08 清空指令缓冲区中的所有指令 // wen 2005.09.08 清空指令缓冲区中的所有指令
void ClearAllCmdFromPollCmdBuf(int port); void ClearAllCmdFromPollCmdBuf(int port);
// wen 2004.10.25 公布函数接口 // wen 2004.10.25 公布函数接口
void ClearCmdFormPollCmdBuf( int port ); void ClearCmdFormPollCmdBuf( int port );
void ClearCmdFormPollCmdBufEx( int port, char *file, int line ); void ClearCmdFormPollCmdBufEx( int port, char *file, int line );
void ClearCmdAllFlag( int port ); void ClearCmdAllFlag( int port );
@ -51,8 +51,8 @@ int GetMaxPort();
int GetPortProtocolIdx(char *name); int GetPortProtocolIdx(char *name);
char *GetPortProtocolName(int Idx); char *GetPortProtocolName(int Idx);
// wen 2004.11.16 增加转发soe数据的处理 // wen 2004.11.16 增加转发soe数据的处理
// 返回缓冲区中的soe数据数量 // 返回缓冲区中的soe数据数量
int ProvWriteSoeData( int provport, SOE_DEF *ptrSoe ); int ProvWriteSoeData( int provport, SOE_DEF *ptrSoe );
int ProvAndDelGetSoeData( int provport, SOE_DEF *ptrSoe ); int ProvAndDelGetSoeData( int provport, SOE_DEF *ptrSoe );
int ProvHaveSoeData( int provport ); int ProvHaveSoeData( int provport );
@ -69,7 +69,7 @@ BOOL IsProvYkYtAck(int commid, PROV_YKYT_DEF *pProvYkYt);
BOOL ShmGetDispYkYtFlag(); BOOL ShmGetDispYkYtFlag();
BOOL ShmGetDispHostLinkFlag(); BOOL ShmGetDispHostLinkFlag();
// wen 2005.04.18 内存的分配与释放 // wen 2005.04.18 内存的分配与释放
void PortMemoryMalloc( int commid, int type, SIO_PARAM_BAOHU_DEF *pBaohuParam ); void PortMemoryMalloc( int commid, int type, SIO_PARAM_BAOHU_DEF *pBaohuParam );
void PortMemoryMallocEx( int commid, int type, SIO_PARAM_BAOHU_DEF *pBaohuParam ); void PortMemoryMallocEx( int commid, int type, SIO_PARAM_BAOHU_DEF *pBaohuParam );
BOOL PortDataPntInit(int commid, int type, SIO_PARAM_BAOHU_DEF *pBaohuParam); BOOL PortDataPntInit(int commid, int type, SIO_PARAM_BAOHU_DEF *pBaohuParam);
@ -81,44 +81,44 @@ BOOL IsExtInfoPtr( int commid );
BOOL IsSerialPtr( int commid ); BOOL IsSerialPtr( int commid );
/*! /*!
\brief \brief
\param commid -- \param commid --
\param rwflag -- \param rwflag --
\ retval-- \ retval--
*/ */
int ShmGetPortFlag(int commid, int rwflag); int ShmGetPortFlag(int commid, int rwflag);
// 保护数据处理 // 保护数据处理
/*! /*!
\brief \brief
\param commid -- \param commid --
\param rtumsg -- \param rtumsg --
\note \note
103 103
*/ */
void SendProtectCmdToDev(int commid, RTUMSG *rtumsg); void SendProtectCmdToDev(int commid, RTUMSG *rtumsg);
/*! /*!
\brief \brief
\param rtumsg -- \param rtumsg --
\note \note
103 103
*/ */
void PutBaohuDataToPort(RTUMSG *rtumsg); void PutBaohuDataToPort(RTUMSG *rtumsg);
void PutBaohuDataToPortEx(int commid, RTUMSG *rtumsg); void PutBaohuDataToPortEx(int commid, RTUMSG *rtumsg);
/*! /*!
\brief scadaprotect \brief scadaprotect
\param rtumsg -- \param rtumsg --
*/ */
void SendDataToAllScadaProtectPort(RTUMSG *rtumsg); void SendDataToAllScadaProtectPort(RTUMSG *rtumsg);
/*! /*!
\brief \brief
\param commid -- \param commid --
\param iProvAddr -- \param iProvAddr --
\param ppBaoHuDB -- (PAI,PDI,PFIX...) \param ppBaoHuDB -- (PAI,PDI,PFIX...)
\retval \retval
*/ */
int GetBaohuDB(int commid, int iProvAddr, GROUPDEF **ppBaoHuDB); int GetBaohuDB(int commid, int iProvAddr, GROUPDEF **ppBaoHuDB);
@ -128,7 +128,7 @@ int SetCurPort(int PortNo);
int GetCurPortEx(); int GetCurPortEx();
int SetDispFlag(int iFlag); int SetDispFlag(int iFlag);
// 获取全局变量 // 获取全局变量
SIO_PARAM_DEF *GetSioParamPtr(); SIO_PARAM_DEF *GetSioParamPtr();
#endif #endif

@ -12,17 +12,17 @@
#include "Profile_Hash.h" #include "Profile_Hash.h"
/* /*
* *
* *
* *
* handle -- * handle --
* *
* *
* SUCCESS -- () * SUCCESS -- ()
* -- * --
* *
* *
* (), . * (), .
* *
*/ */
int conf_close ( void * handle ) int conf_close ( void * handle )

@ -11,15 +11,15 @@
/* /*
* , * ,
* *
* *
* pszfname -- ( char [MAX_PATH]) * pszfname -- ( char [MAX_PATH])
* ppvhandle -- , () * ppvhandle -- , ()
* *
* *
* SUCCESS -- , * SUCCESS -- ,
* -- * --
* *
*/ */
int conf_open ( const char * pszfname, void ** ppvhandle ) int conf_open ( const char * pszfname, void ** ppvhandle )

@ -2,10 +2,10 @@
* *
* Copyright (C) 1999-2000 SCADA Technology Control Co., Ltd. All rights reserved. * Copyright (C) 1999-2000 SCADA Technology Control Co., Ltd. All rights reserved.
* *
* *
* [], * [],
* *
* : 2002/01/21 * : 2002/01/21
* *
* *
* *
@ -75,20 +75,20 @@
/* /*
* [], * [],
* *
* *
* handle -- * handle --
* pszsec_name -- * pszsec_name --
* pszkey_name -- * pszkey_name --
* pszdefault -- , null, * pszdefault -- , null,
* , , , * , , ,
* pbuf -- * pbuf --
* buffer_length -- * buffer_length --
* *
* *
* SUCCESS -- * SUCCESS --
* -- * --
* *
*/ */
int conf_read_key ( void * handle, int conf_read_key ( void * handle,

@ -2,10 +2,10 @@
* *
* Copyright (C) 1999-2000 SCADA Technology Control Co., Ltd. All rights reserved. * Copyright (C) 1999-2000 SCADA Technology Control Co., Ltd. All rights reserved.
* *
* *
* / * /
* *
* : 2002/01/21 * : 2002/01/21
* *
* *
* *
@ -67,19 +67,19 @@
/* /*
* / * /
* *
* *
* handle -- * handle --
* pszsec_name -- * pszsec_name --
* pszkey_name -- * pszkey_name --
* pszkey_value -- * pszkey_value --
* force_insert -- (, ), (, ), * force_insert -- (, ), (, ),
* 0, , , . * 0, , , .
* *
* *
* SUCCESS -- * SUCCESS --
* -- * --
* *
*/ */
int conf_write_key ( void * handle, int conf_write_key ( void * handle,

@ -9,11 +9,11 @@
* \if developer_doc * \if developer_doc
* \file * \file
* *
* \brief ,:, * \brief ,:,
* *
* id: $Id: confrw.h,v 1.2 2006/08/04 03:37:33 zhuzhenhua Exp $ * id: $Id: confrw.h,v 1.2 2006/08/04 03:37:33 zhuzhenhua Exp $
* *
* \author prcharold@sina.com.cn develop1@szscada.com * \author prcharold@sina.com.cn develop1@szscada.com
* \endif * \endif
*/ */
@ -39,14 +39,14 @@
*/ */
/*! /*!
* \brief , * \brief ,
* *
* \param pszfname --[in] ( char [MAX_PATH]) * \param pszfname --[in] ( char [MAX_PATH])
* \param ppvhandle --[in] , () * \param ppvhandle --[in] , ()
* *
* \retval * \retval
* \retval SUCCESS -- , * \retval SUCCESS -- ,
* \retval -- * \retval --
* *
*/ */
CONFRWLIB_API int conf_open ( const char * pszfname, void ** ppvhandle ); CONFRWLIB_API int conf_open ( const char * pszfname, void ** ppvhandle );
@ -57,16 +57,16 @@ CONFRWLIB_API int conf_open ( const char * pszfname, void ** ppvhandle );
/*! /*!
* \brief * \brief
* *
* \param handle --[in] * \param handle --[in]
* *
* \retval SUCCESS -- () * \retval SUCCESS -- ()
* \retval ERROR_CONF_HANLDE -- * \retval ERROR_CONF_HANLDE --
* \retval -- * \retval --
* *
* \note * \note
* (), . * (), .
* *
*/ */
CONFRWLIB_API int conf_close ( void * handle ); CONFRWLIB_API int conf_close ( void * handle );
@ -76,20 +76,20 @@ CONFRWLIB_API int conf_close ( void * handle );
/*! /*!
* \brief [], * \brief [],
* *
* \param handle --[in] * \param handle --[in]
* \param pszsec_name --[in] , null * \param pszsec_name --[in] , null
* \param pszkey_name --[in] , null * \param pszkey_name --[in] , null
* \param pszdefault --[in] , null,, , , * \param pszdefault --[in] , null,, , ,
* \param pbuf --[out] * \param pbuf --[out]
* \param buffer_length --[in] * \param buffer_length --[in]
* *
* \retval SUCCESS -- , * \retval SUCCESS -- ,
* \retval , /, SUCCESS * \retval , /, SUCCESS
* \retval ERROR_CONF_SECTION -- * \retval ERROR_CONF_SECTION --
* \retval ERROR_CONF_KEY -- * \retval ERROR_CONF_KEY --
* \retval -- * \retval --
*/ */
CONFRWLIB_API int conf_read_key ( void * handle, CONFRWLIB_API int conf_read_key ( void * handle,
const char * pszsec_name, const char * pszsec_name,
@ -104,21 +104,21 @@ CONFRWLIB_API int conf_read_key ( void * handle,
/*! /*!
* \brief / * \brief /
* *
* \param handle --[in] * \param handle --[in]
* \param pszsec_name --[in] * \param pszsec_name --[in]
* \param pszkey_name --[in] * \param pszkey_name --[in]
* \param pszkey_value --[in] * \param pszkey_value --[in]
* \param force_insert --[in] (, ), (, ), * \param force_insert --[in] (, ), (, ),
* 0, , , . * 0, , , .
* *
* \retval SUCCESS -- * \retval SUCCESS --
* \retval -- * \retval --
* *
* \note * \note
* force_insert 0, , ERROR_CONF_SECTION; * force_insert 0, , ERROR_CONF_SECTION;
* (/), ERROR_CONF_KEY. * (/), ERROR_CONF_KEY.
*/ */
CONFRWLIB_API int conf_write_key ( void * handle, CONFRWLIB_API int conf_write_key ( void * handle,
const char * pszsec_name, const char * pszsec_name,
@ -131,18 +131,18 @@ CONFRWLIB_API int conf_write_key ( void * handle,
/*! /*!
* \brief (, ) * \brief (, )
* *
* \param handle --[in] * \param handle --[in]
* \param pszsec_name --[in] * \param pszsec_name --[in]
* \param pszkey_name --[in] * \param pszkey_name --[in]
* *
* \retval SUCCESS -- * \retval SUCCESS --
* \retval -- * \retval --
* *
* \note * \note
* , ERROR_CONF_SECTION * , ERROR_CONF_SECTION
* (, ), ERROR_CONF_KEY * (, ), ERROR_CONF_KEY
*/ */
CONFRWLIB_API int conf_delete_key ( void * handle, CONFRWLIB_API int conf_delete_key ( void * handle,
const char * pszsec_name, const char * pszsec_name,
@ -153,16 +153,16 @@ CONFRWLIB_API int conf_delete_key ( void * handle,
/*! /*!
* \brief * \brief
* *
* \param handle --[in] * \param handle --[in]
* \param pszsec_name --[in] , null * \param pszsec_name --[in] , null
* *
* \retval SUCCESS -- * \retval SUCCESS --
* \retval -- * \retval --
* *
* \note * \note
* , ERROR_CONF_SECTION * , ERROR_CONF_SECTION
*/ */
CONFRWLIB_API int conf_delete_section ( void * handle, CONFRWLIB_API int conf_delete_section ( void * handle,
const char * pszsec_name ); const char * pszsec_name );

@ -5,11 +5,11 @@
* \if developer_doc * \if developer_doc
* \file * \file
* *
* \brief * \brief
* *
* id: $Id: confrw_errno.h,v 1.2 2006/08/04 03:37:33 zhuzhenhua Exp $ * id: $Id: confrw_errno.h,v 1.2 2006/08/04 03:37:33 zhuzhenhua Exp $
* *
* \author prcharold@sina.com.cn develop1@szscada.com * \author prcharold@sina.com.cn develop1@szscada.com
* \endif * \endif
*/ */
@ -22,43 +22,43 @@
* \endif * \endif
*/ */
//!< 不能为当前打开的配置文件缓冲分配一个句柄,原因是句柄已经全被占用 //!< 不能为当前打开的配置文件缓冲分配一个句柄,原因是句柄已经全被占用
#define ERROR_CONF_NOHANDLE (ERROR_CONF_BASE + 1) #define ERROR_CONF_NOHANDLE (ERROR_CONF_BASE + 1)
//!< 创建哈希表失败 //!< 创建哈希表失败
#define ERROR_CONF_CREATEHASH (ERROR_CONF_BASE + 2) #define ERROR_CONF_CREATEHASH (ERROR_CONF_BASE + 2)
//!< 输入了非法的配置文件缓冲句柄 //!< 输入了非法的配置文件缓冲句柄
#define ERROR_CONF_INVALIDHANDLE (ERROR_CONF_BASE + 3) #define ERROR_CONF_INVALIDHANDLE (ERROR_CONF_BASE + 3)
//!< 在读配置文件时,用户开辟的接收缓冲区不够大 //!< 在读配置文件时,用户开辟的接收缓冲区不够大
#define ERROR_CONF_REVBUFFER (ERROR_CONF_BASE + 4) #define ERROR_CONF_REVBUFFER (ERROR_CONF_BASE + 4)
//!< 在读配置文件时,因指定的段的项目名不存在,函数执行缺省拷贝,并返回此结果 //!< 在读配置文件时,因指定的段的项目名不存在,函数执行缺省拷贝,并返回此结果
#define SUCCESS_CONF_DEFCOPY (ERROR_CONF_BASE + 5) #define SUCCESS_CONF_DEFCOPY (ERROR_CONF_BASE + 5)
//!< 不能输入一个空的句柄指针作参数 //!< 不能输入一个空的句柄指针作参数
#define ERROR_CONF_NULL_HANDEPTR (ERROR_CONF_BASE + 6) #define ERROR_CONF_NULL_HANDEPTR (ERROR_CONF_BASE + 6)
//!< 输入的段名,项目名,项目值的字符串长度超长 //!< 输入的段名,项目名,项目值的字符串长度超长
#define ERROR_CONF_INPUTSTRING_TOOLARGE (ERROR_CONF_BASE + 7) #define ERROR_CONF_INPUTSTRING_TOOLARGE (ERROR_CONF_BASE + 7)
//!< 指定的段或项目并不存在 //!< 指定的段或项目并不存在
#define ERROR_CONF_NOTEXIST (ERROR_CONF_BASE + 8) #define ERROR_CONF_NOTEXIST (ERROR_CONF_BASE + 8)
/*! /*!
*\verbatim *\verbatim
confrw_ex confrw_ex
*\endvervatim *\endvervatim
*/ */
//!< 无效的配置文件句柄 //!< 无效的配置文件句柄
#define ERROR_CONF_HANDLE (ERROR_CONF_BASE + 9) #define ERROR_CONF_HANDLE (ERROR_CONF_BASE + 9)
//!< 指定的段不存在 //!< 指定的段不存在
#define ERROR_CONF_SECTION (ERROR_CONF_BASE + 10) #define ERROR_CONF_SECTION (ERROR_CONF_BASE + 10)
//!< 指定的键值不存在 //!< 指定的键值不存在
#define ERROR_CONF_KEY (ERROR_CONF_BASE + 11) #define ERROR_CONF_KEY (ERROR_CONF_BASE + 11)
/*! /*!

@ -18,12 +18,12 @@ int RealDataDispFlag;
int CurPort; int CurPort;
int DispType = 0; int DispType = 0;
int ListIndex = 0; // 显示序号索引起始 int ListIndex = 0; // 显示序号索引起始
int ItemNumOfPage; // 页显示项目数 int ItemNumOfPage; // 页显示项目数
#ifdef _WIN32 #ifdef _WIN32
COLORREF dwColorVal[16] = // 显示颜色定义 COLORREF dwColorVal[16] = // 显示颜色定义
{ {
RGB(255,255,255), RGB(128,128,128), RGB(255,255,255), RGB(128,128,128),
RGB(255, 0, 0), RGB(255,255, 0), RGB(255, 0, 0), RGB(255,255, 0),
@ -50,38 +50,38 @@ void RealAiDataDisp( HDC hdc )
itemofline = 2; itemofline = 2;
CaculateWH( hdc, &xWd, &yHg, (char*)"行距" ); CaculateWH( hdc, &xWd, &yHg, (char*)"行距" );
lineh = yHg + 5; lineh = yHg + 5;
rc.top = 10; rc.top = 10;
SetTextColor( hdc, dwColorVal[BLUE] ); SetTextColor( hdc, dwColorVal[BLUE] );
// 显示标题 // 显示标题
sprintf( szbuf,"端口%02d 实时遥测数据信息", CurPort + 1 ); sprintf( szbuf,"端口%02d 实时遥测数据信息", CurPort + 1 );
DrawText(hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_CENTER ); DrawText(hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_CENTER );
rc.top += (lineh + 5); rc.top += (lineh + 5);
SetTextColor( hdc, dwColorVal[BLACK] ); SetTextColor( hdc, dwColorVal[BLACK] );
// 计算显示位置 // 计算显示位置
pos[0] = 0; pos[0] = 0;
pos[3] = rc.right / 2; pos[3] = rc.right / 2;
tmp = 0; tmp = 0;
CaculateWH( hdc, &xWd, &yHg, (char*)"序号" ); CaculateWH( hdc, &xWd, &yHg, (char*)"序号" );
tmp += xWd; tmp += xWd;
pos[1] = pos[0] + xWd; pos[1] = pos[0] + xWd;
pos[4] = pos[3] + xWd; pos[4] = pos[3] + xWd;
CaculateWH( hdc, &xWd, &yHg, (char*)"测点名称" ); CaculateWH( hdc, &xWd, &yHg, (char*)"测点名称" );
tmp += xWd; tmp += xWd;
pos[2] = pos[1] + xWd; pos[2] = pos[1] + xWd;
pos[5] = pos[4] + xWd; pos[5] = pos[4] + xWd;
CaculateWH( hdc, &xWd, &yHg, (char*)"测点原值" ); CaculateWH( hdc, &xWd, &yHg, (char*)"测点原值" );
tmp += xWd; tmp += xWd;
sp = ((float)rc.right - (float)tmp*itemofline) / (itemofline*4); sp = ((float)rc.right - (float)tmp*itemofline) / (itemofline*4);
pos[0] += (int)sp; pos[0] += (int)sp;
@ -91,16 +91,16 @@ void RealAiDataDisp( HDC hdc )
pos[4] += (int)(sp*2); pos[4] += (int)(sp*2);
pos[5] += (int)(sp*3); pos[5] += (int)(sp*3);
// 显示项目名称 // 显示项目名称
for ( i = 0; i < itemofline; i++ ) for ( i = 0; i < itemofline; i++ )
{ {
sprintf( szbuf, (char*)"序号" ); sprintf( szbuf, (char*)"序号" );
rc.left = pos[i*3]; rc.left = pos[i*3];
DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_LEFT ); DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_LEFT );
sprintf( szbuf, (char*)"测点名称" ); sprintf( szbuf, (char*)"测点名称" );
rc.left = pos[i*3+1]; rc.left = pos[i*3+1];
DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_LEFT ); DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_LEFT );
sprintf( szbuf, (char*)"测点原值" ); sprintf( szbuf, (char*)"测点原值" );
rc.left = pos[i*3+2]; rc.left = pos[i*3+2];
DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_LEFT ); DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_LEFT );
} }
@ -111,10 +111,10 @@ void RealAiDataDisp( HDC hdc )
if( !IsBaoHuPtr(CurPort) ) if( !IsBaoHuPtr(CurPort) )
return; return;
// 计算总行数 // 计算总行数
total = (SioParam[CurPort].m_psBaoHu->AiNum + itemofline - 1) / itemofline; total = (SioParam[CurPort].m_psBaoHu->AiNum + itemofline - 1) / itemofline;
// 调整显示的起始位置 // 调整显示的起始位置
if ( total < ItemNumOfPage ) if ( total < ItemNumOfPage )
ListIndex = 0; ListIndex = 0;
if ( (ListIndex + ItemNumOfPage) > total ) if ( (ListIndex + ItemNumOfPage) > total )
@ -122,7 +122,7 @@ void RealAiDataDisp( HDC hdc )
if ( ListIndex < 0 ) if ( ListIndex < 0 )
ListIndex = 0; ListIndex = 0;
// 显示输出 // 显示输出
idx = ListIndex * itemofline; idx = ListIndex * itemofline;
aiptr = (AI_DEF*)SioParam[CurPort].m_psBaoHu->AiPtr; aiptr = (AI_DEF*)SioParam[CurPort].m_psBaoHu->AiPtr;
if( !aiptr ) if( !aiptr )
@ -137,19 +137,19 @@ void RealAiDataDisp( HDC hdc )
sprintf( szbuf, "%03d", idx + j + 1 ); sprintf( szbuf, "%03d", idx + j + 1 );
rc.left = pos[j*3+0]; rc.left = pos[j*3+0];
CaculateWH( hdc, &xWd, &yHg, (char*)"序号" ); CaculateWH( hdc, &xWd, &yHg, (char*)"序号" );
rc.right = rc.left + xWd; rc.right = rc.left + xWd;
DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_CENTER ); DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_CENTER );
sprintf( szbuf, "遥测%03d", idx + j + 1 ); sprintf( szbuf, "遥测%03d", idx + j + 1 );
rc.left = pos[j*3+1]; rc.left = pos[j*3+1];
CaculateWH( hdc, &xWd, &yHg, (char*)"测点名称" ); CaculateWH( hdc, &xWd, &yHg, (char*)"测点名称" );
rc.right = rc.left + xWd; rc.right = rc.left + xWd;
DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_CENTER ); DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_CENTER );
sprintf( szbuf, "0x%04x", aiptr[idx+j].RawValue & 0xffff ); sprintf( szbuf, "0x%04x", aiptr[idx+j].RawValue & 0xffff );
rc.left = pos[j*3+2]; rc.left = pos[j*3+2];
CaculateWH( hdc, &xWd, &yHg, (char*)"测点原值" ); CaculateWH( hdc, &xWd, &yHg, (char*)"测点原值" );
rc.right = rc.left + xWd; rc.right = rc.left + xWd;
DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_CENTER ); DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_CENTER );
} }
@ -172,7 +172,7 @@ void RealDiDataDisp( HDC hdc )
GetClientRect( hMainWnd, &rc ); GetClientRect( hMainWnd, &rc );
CaculateWH( hdc, &xWd, &yHg, (char*)"行距" ); CaculateWH( hdc, &xWd, &yHg, (char*)"行距" );
lineh = yHg + 5; lineh = yHg + 5;
itemofline = 2; itemofline = 2;
@ -181,31 +181,31 @@ void RealDiDataDisp( HDC hdc )
SetTextColor( hdc, dwColorVal[BLUE] ); SetTextColor( hdc, dwColorVal[BLUE] );
// 显示标题 // 显示标题
sprintf( szbuf,"端口%02d 实时遥信数据信息", CurPort + 1 ); sprintf( szbuf,"端口%02d 实时遥信数据信息", CurPort + 1 );
DrawText(hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_CENTER ); DrawText(hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_CENTER );
rc.top += (lineh + 5); rc.top += (lineh + 5);
SetTextColor( hdc, dwColorVal[BLACK] ); SetTextColor( hdc, dwColorVal[BLACK] );
// 计算显示位置 // 计算显示位置
pos[0] = 0; pos[0] = 0;
pos[3] = rc.right / 2; pos[3] = rc.right / 2;
tmp = 0; tmp = 0;
CaculateWH( hdc, &xWd, &yHg, (char*)"序号" ); CaculateWH( hdc, &xWd, &yHg, (char*)"序号" );
tmp += xWd; tmp += xWd;
pos[1] = pos[0] + xWd; pos[1] = pos[0] + xWd;
pos[4] = pos[3] + xWd; pos[4] = pos[3] + xWd;
CaculateWH( hdc, &xWd, &yHg, (char*)"测点名称" ); CaculateWH( hdc, &xWd, &yHg, (char*)"测点名称" );
tmp += xWd; tmp += xWd;
pos[2] = pos[1] + xWd; pos[2] = pos[1] + xWd;
pos[5] = pos[4] + xWd; pos[5] = pos[4] + xWd;
CaculateWH( hdc, &xWd, &yHg, (char*)"状态" ); CaculateWH( hdc, &xWd, &yHg, (char*)"状态" );
tmp += xWd; tmp += xWd;
sp = ((float)rc.right - (float)tmp*itemofline) / (itemofline*4); sp = ((float)rc.right - (float)tmp*itemofline) / (itemofline*4);
pos[0] += (int)sp; pos[0] += (int)sp;
@ -215,18 +215,18 @@ void RealDiDataDisp( HDC hdc )
pos[4] += (int)(sp*2); pos[4] += (int)(sp*2);
pos[5] += (int)(sp*3); pos[5] += (int)(sp*3);
// 显示项目名称 // 显示项目名称
for ( i = 0; i < itemofline; i++ ) for ( i = 0; i < itemofline; i++ )
{ {
sprintf( szbuf, (char*)"序号" ); sprintf( szbuf, (char*)"序号" );
rc.left = pos[i*3+0]; rc.left = pos[i*3+0];
DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_LEFT ); DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_LEFT );
sprintf( szbuf, (char*)"测点名称" ); sprintf( szbuf, (char*)"测点名称" );
rc.left = pos[i*3+1]; rc.left = pos[i*3+1];
DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_LEFT ); DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_LEFT );
sprintf( szbuf, (char*)"状态" ); sprintf( szbuf, (char*)"状态" );
rc.left = pos[i*3+2]; rc.left = pos[i*3+2];
DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_LEFT ); DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_LEFT );
} }
@ -237,10 +237,10 @@ void RealDiDataDisp( HDC hdc )
if( !IsBaoHuPtr(CurPort) ) if( !IsBaoHuPtr(CurPort) )
return; return;
// 计算总行数 // 计算总行数
total = (SioParam[CurPort].m_psBaoHu->DiNum + itemofline - 1) / itemofline; total = (SioParam[CurPort].m_psBaoHu->DiNum + itemofline - 1) / itemofline;
// 调整显示的起始位置 // 调整显示的起始位置
if ( total < ItemNumOfPage ) if ( total < ItemNumOfPage )
ListIndex = 0; ListIndex = 0;
if ( (ListIndex + ItemNumOfPage) > total ) if ( (ListIndex + ItemNumOfPage) > total )
@ -248,7 +248,7 @@ void RealDiDataDisp( HDC hdc )
if ( ListIndex < 0 ) if ( ListIndex < 0 )
ListIndex = 0; ListIndex = 0;
// 显示输出 // 显示输出
idx = ListIndex * itemofline; idx = ListIndex * itemofline;
diptr = (DI_DEF*)SioParam[CurPort].m_psBaoHu->DiPtr; diptr = (DI_DEF*)SioParam[CurPort].m_psBaoHu->DiPtr;
if( !diptr ) if( !diptr )
@ -263,19 +263,19 @@ void RealDiDataDisp( HDC hdc )
sprintf( szbuf, "%03d", idx + j + 1 ); sprintf( szbuf, "%03d", idx + j + 1 );
rc.left = pos[j*3+0]; rc.left = pos[j*3+0];
CaculateWH( hdc, &xWd, &yHg, (char*)"序号" ); CaculateWH( hdc, &xWd, &yHg, (char*)"序号" );
rc.right = rc.left + xWd; rc.right = rc.left + xWd;
DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_CENTER ); DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_CENTER );
sprintf( szbuf, "遥信%03d", idx + j + 1 ); sprintf( szbuf, "遥信%03d", idx + j + 1 );
rc.left = pos[j*3+1]; rc.left = pos[j*3+1];
CaculateWH( hdc, &xWd, &yHg, (char*)"测点名称" ); CaculateWH( hdc, &xWd, &yHg, (char*)"测点名称" );
rc.right = rc.left + xWd; rc.right = rc.left + xWd;
DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_CENTER ); DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_CENTER );
sprintf( szbuf, "%s", diptr[idx+j].Status ? (char*)"" : (char*)"" ); sprintf( szbuf, "%s", diptr[idx+j].Status ? (char*)"" : (char*)"" );
rc.left = pos[j*3+2]; rc.left = pos[j*3+2];
CaculateWH( hdc, &xWd, &yHg, (char*)"状态" ); CaculateWH( hdc, &xWd, &yHg, (char*)"状态" );
rc.right = rc.left + xWd; rc.right = rc.left + xWd;
DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_CENTER ); DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_CENTER );
} }
@ -299,38 +299,38 @@ void RealPiDataDisp( HDC hdc )
GetClientRect( hMainWnd, &rc ); GetClientRect( hMainWnd, &rc );
itemofline = 2; itemofline = 2;
CaculateWH( hdc, &xWd, &yHg, (char*)"行距" ); CaculateWH( hdc, &xWd, &yHg, (char*)"行距" );
lineh = yHg + 5; lineh = yHg + 5;
rc.top = 10; rc.top = 10;
SetTextColor( hdc, dwColorVal[BLUE] ); SetTextColor( hdc, dwColorVal[BLUE] );
// 显示标题 // 显示标题
sprintf( szbuf,"端口%02d 实时电度数据信息", CurPort + 1 ); sprintf( szbuf,"端口%02d 实时电度数据信息", CurPort + 1 );
DrawText(hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_CENTER ); DrawText(hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_CENTER );
rc.top += (lineh + 5); rc.top += (lineh + 5);
SetTextColor( hdc, dwColorVal[BLACK] ); SetTextColor( hdc, dwColorVal[BLACK] );
// 计算显示位置 // 计算显示位置
pos[0] = 0; pos[0] = 0;
pos[3] = rc.right / 2; pos[3] = rc.right / 2;
tmp = 0; tmp = 0;
CaculateWH( hdc, &xWd, &yHg, (char*)"序号" ); CaculateWH( hdc, &xWd, &yHg, (char*)"序号" );
tmp += xWd; tmp += xWd;
pos[1] = pos[0] + xWd; pos[1] = pos[0] + xWd;
pos[4] = pos[3] + xWd; pos[4] = pos[3] + xWd;
CaculateWH( hdc, &xWd, &yHg, (char*)"测点名称" ); CaculateWH( hdc, &xWd, &yHg, (char*)"测点名称" );
tmp += xWd; tmp += xWd;
pos[2] = pos[1] + xWd; pos[2] = pos[1] + xWd;
pos[5] = pos[4] + xWd; pos[5] = pos[4] + xWd;
CaculateWH( hdc, &xWd, &yHg, (char*)"测点原值" ); CaculateWH( hdc, &xWd, &yHg, (char*)"测点原值" );
tmp += xWd; tmp += xWd;
sp = ((float)rc.right - (float)tmp*itemofline) / (itemofline*4); sp = ((float)rc.right - (float)tmp*itemofline) / (itemofline*4);
pos[0] += (int)sp; pos[0] += (int)sp;
@ -340,18 +340,18 @@ void RealPiDataDisp( HDC hdc )
pos[4] += (int)(sp*2); pos[4] += (int)(sp*2);
pos[5] += (int)(sp*3); pos[5] += (int)(sp*3);
// 显示项目名称 // 显示项目名称
for ( i = 0; i < itemofline; i++ ) for ( i = 0; i < itemofline; i++ )
{ {
sprintf( szbuf, (char*)"序号" ); sprintf( szbuf, (char*)"序号" );
rc.left = pos[i*3+0]; rc.left = pos[i*3+0];
DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_LEFT ); DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_LEFT );
sprintf( szbuf, (char*)"测点名称" ); sprintf( szbuf, (char*)"测点名称" );
rc.left = pos[i*3+1]; rc.left = pos[i*3+1];
DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_LEFT ); DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_LEFT );
sprintf( szbuf, (char*)"测点原值" ); sprintf( szbuf, (char*)"测点原值" );
rc.left = pos[i*3+2]; rc.left = pos[i*3+2];
DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_LEFT ); DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_LEFT );
} }
@ -362,10 +362,10 @@ void RealPiDataDisp( HDC hdc )
if( !IsBaoHuPtr(CurPort) ) if( !IsBaoHuPtr(CurPort) )
return; return;
// 计算总行数 // 计算总行数
total = (SioParam[CurPort].m_psBaoHu->PiNum + itemofline - 1) / itemofline; total = (SioParam[CurPort].m_psBaoHu->PiNum + itemofline - 1) / itemofline;
// 调整显示的起始位置 // 调整显示的起始位置
if ( total < ItemNumOfPage ) if ( total < ItemNumOfPage )
ListIndex = 0; ListIndex = 0;
if ( (ListIndex + ItemNumOfPage) > total ) if ( (ListIndex + ItemNumOfPage) > total )
@ -373,7 +373,7 @@ void RealPiDataDisp( HDC hdc )
if ( ListIndex < 0 ) if ( ListIndex < 0 )
ListIndex = 0; ListIndex = 0;
// 显示输出 // 显示输出
idx = ListIndex * itemofline; idx = ListIndex * itemofline;
piptr = (PI_DEF*)SioParam[CurPort].m_psBaoHu->PiPtr; piptr = (PI_DEF*)SioParam[CurPort].m_psBaoHu->PiPtr;
if( !piptr ) if( !piptr )
@ -388,20 +388,20 @@ void RealPiDataDisp( HDC hdc )
sprintf( szbuf, "%03d", idx + j + 1 ); sprintf( szbuf, "%03d", idx + j + 1 );
rc.left = pos[j*3+0]; rc.left = pos[j*3+0];
CaculateWH( hdc, &xWd, &yHg, (char*)"序号" ); CaculateWH( hdc, &xWd, &yHg, (char*)"序号" );
rc.right = rc.left + xWd; rc.right = rc.left + xWd;
DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_CENTER ); DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_CENTER );
sprintf( szbuf, "电度%03d", idx + j + 1); sprintf( szbuf, "电度%03d", idx + j + 1);
rc.left = pos[j*3+1]; rc.left = pos[j*3+1];
CaculateWH( hdc, &xWd, &yHg, (char*)"测点名称" ); CaculateWH( hdc, &xWd, &yHg, (char*)"测点名称" );
rc.right = rc.left + xWd; rc.right = rc.left + xWd;
DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_CENTER ); DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_CENTER );
sprintf( szbuf, "0x%08x", piptr[idx+j].RawValue ); sprintf( szbuf, "0x%08x", piptr[idx+j].RawValue );
rc.left = pos[j*3+2]; rc.left = pos[j*3+2];
CaculateWH( hdc, &xWd, &yHg, (char*)"测点原值" ); CaculateWH( hdc, &xWd, &yHg, (char*)"测点原值" );
// wen 2004.11.19 显示的长度是名称的1.5倍 // wen 2004.11.19 显示的长度是名称的1.5倍
//rc.right = rc.left + xWd; //rc.right = rc.left + xWd;
//DrawText( hdc, szbuf, strlen(szbuf), &rc, DT_CENTER ); //DrawText( hdc, szbuf, strlen(szbuf), &rc, DT_CENTER );
rc.right = rc.left + xWd/4*6; rc.right = rc.left + xWd/4*6;
@ -423,14 +423,14 @@ void WatchDataDisp( HDC hdc )
GetClientRect( hMainWnd, &rc ); GetClientRect( hMainWnd, &rc );
CaculateWH( hdc, &xWd, &yHg, (char*)"行距" ); CaculateWH( hdc, &xWd, &yHg, (char*)"行距" );
lineh = yHg + 5; lineh = yHg + 5;
rc.top = 10; rc.top = 10;
if ( DevParam[iCurDevIdx].WatchDispLine.LineCnt == 0 ) if ( DevParam[iCurDevIdx].WatchDispLine.LineCnt == 0 )
{ {
sprintf( szbuf, "当前没有数据....." ); sprintf( szbuf, "当前没有数据....." );
DrawText(hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_LEFT ); DrawText(hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_LEFT );
return; return;
} }
@ -441,7 +441,7 @@ void WatchDataDisp( HDC hdc )
if ( RealDataDispFlag ) if ( RealDataDispFlag )
ListIndex = 100000; ListIndex = 100000;
// 调整显示的起始位置 // 调整显示的起始位置
if ( total < ItemNumOfPage ) if ( total < ItemNumOfPage )
ListIndex = 0; ListIndex = 0;
if ( (ListIndex + ItemNumOfPage) > total ) if ( (ListIndex + ItemNumOfPage) > total )
@ -449,12 +449,12 @@ void WatchDataDisp( HDC hdc )
if ( ListIndex < 0 ) if ( ListIndex < 0 )
ListIndex = 0; ListIndex = 0;
// 寻找数据起始位置 // 寻找数据起始位置
idx = DevParam[iCurDevIdx].WatchDispLine.Rear - total; idx = DevParam[iCurDevIdx].WatchDispLine.Rear - total;
if ( idx < 0 ) if ( idx < 0 )
idx += MAX_DISP_LINE; idx += MAX_DISP_LINE;
// 显示起始位置 // 显示起始位置
idx += ListIndex; idx += ListIndex;
for ( i = 0; i < min(ItemNumOfPage, total); i++ ) for ( i = 0; i < min(ItemNumOfPage, total); i++ )
@ -462,7 +462,7 @@ void WatchDataDisp( HDC hdc )
j = (idx + i) % MAX_DISP_LINE; j = (idx + i) % MAX_DISP_LINE;
type = DevParam[iCurDevIdx].WatchDispLine.Line[j][0]; type = DevParam[iCurDevIdx].WatchDispLine.Line[j][0];
if ( type == 'R' ) // 接收数据 if ( type == 'R' ) // 接收数据
SetTextColor( hdc, dwColorVal[BLUE] ); SetTextColor( hdc, dwColorVal[BLUE] );
else else
SetTextColor( hdc, dwColorVal[MAGENTA] ); SetTextColor( hdc, dwColorVal[MAGENTA] );
@ -478,12 +478,12 @@ void WatchDataDisp( HDC hdc )
} }
//*************************************************************** //***************************************************************
//* 新字体函数? * //* 新字体函数? *
//*************************************************************** //***************************************************************
HFONT NewFont( int nFSize ) HFONT NewFont( int nFSize )
{ {
/* /*
WCHAR typeface[32] = (WCHAR *)"宋体"; WCHAR typeface[32] = (WCHAR *)"宋体";
LOGFONT LogFont = { 0, 0, 0, 0, LOGFONT LogFont = { 0, 0, 0, 0,
400, 400,
@ -497,18 +497,18 @@ HFONT NewFont( int nFSize )
PROOF_QUALITY, PROOF_QUALITY,
DEFAULT_PITCH, DEFAULT_PITCH,
typeface typeface
//"新宋体" //"新宋体"
//"黑体" //"黑体"
//"隶书" //"隶书"
//"幼圆" //"幼圆"
//"仿宋_GB2312" //"仿宋_GB2312"
}; };
LogFont.lfWidth = (LONG)((float)nFSize*.618); LogFont.lfWidth = (LONG)((float)nFSize*.618);
LogFont.lfHeight = (LONG)nFSize; LogFont.lfHeight = (LONG)nFSize;
strcpy( LogFont.lfFaceName, "Lee宋体" ); strcpy( LogFont.lfFaceName, "Lee宋体" );
return( CreateFontIndirect( &LogFont ));*/ return( CreateFontIndirect( &LogFont ));*/
return NULL; return NULL;
} }
@ -559,7 +559,7 @@ void DataDisp( HWND hWnd )
} }
//*************************************************************** //***************************************************************
//* 计算字串显示宽度和高度 * //* 计算字串显示宽度和高度 *
//*************************************************************** //***************************************************************
void CaculateWH( HDC hdc, UINT *xWidth, UINT *yHeight, char *szStr ) void CaculateWH( HDC hdc, UINT *xWidth, UINT *yHeight, char *szStr )
{ {
@ -573,7 +573,7 @@ void CaculateWH( HDC hdc, UINT *xWidth, UINT *yHeight, char *szStr )
#endif #endif
//**************************************************************** //****************************************************************
//* 显示数据上页? * //* 显示数据上页? *
//**************************************************************** //****************************************************************
void PageUp( void ) void PageUp( void )
{ {
@ -583,7 +583,7 @@ void PageUp( void )
} }
//*************************************************************** //***************************************************************
//* 显示数据下页? * //* 显示数据下页? *
//*************************************************************** //***************************************************************
void PageDown( void ) void PageDown( void )
{ {
@ -591,7 +591,7 @@ void PageDown( void )
} }
//*************************************************************** //***************************************************************
//* 显示端口最后一页数据 * //* 显示端口最后一页数据 *
//*************************************************************** //***************************************************************
void PageEnd( void ) void PageEnd( void )
{ {
@ -599,7 +599,7 @@ void PageEnd( void )
} }
//*************************************************************** //***************************************************************
//* 显示端口最前一页数据? * //* 显示端口最前一页数据? *
//*************************************************************** //***************************************************************
void PageHome( void ) void PageHome( void )
{ {
@ -615,7 +615,7 @@ void LineUp( void )
} }
//*************************************************************** //***************************************************************
//* 显示下移一行? * //* 显示下移一行? *
//*************************************************************** //***************************************************************
void LineDown( void ) void LineDown( void )
{ {

@ -4,8 +4,8 @@
* *
* 2001/11/3 * 2001/11/3
* *
* , "ERROR_" * , "ERROR_"
* 10xffff. * 10xffff.
* *
* *
* *
@ -23,13 +23,13 @@
* no message * no message
* *
* Revision 1.12 2003/09/17 15:00:37 scada * Revision 1.12 2003/09/17 15:00:37 scada
* : ERROR_MKDIR/ERROR_OPEN/ERROR_EXIST * : ERROR_MKDIR/ERROR_OPEN/ERROR_EXIST
* *
* Revision 1.11 2003/08/01 06:38:01 scada * Revision 1.11 2003/08/01 06:38:01 scada
* Windows, SYSV(unix) * Windows, SYSV(unix)
* *
* Revision 1.10 2003/06/05 03:56:15 jehu * Revision 1.10 2003/06/05 03:56:15 jehu
* doxgen * doxgen
* *
* Revision 1.9 2003/01/15 10:25:41 scada * Revision 1.9 2003/01/15 10:25:41 scada
* update thread dead lock * update thread dead lock
@ -59,10 +59,10 @@
* temporarily import * temporarily import
* *
* Revision 1.23 2002/07/26 13:07:55 scada * Revision 1.23 2002/07/26 13:07:55 scada
* fputs=>ERROR_FPUTS * fputs=>ERROR_FPUTS
* *
* Revision 1.22 2002/07/23 06:59:04 scada * Revision 1.22 2002/07/23 06:59:04 scada
* 使16bit0, (8bit) * 使16bit0, (8bit)
* *
* Revision 1.21 2002/07/12 10:01:47 harold * Revision 1.21 2002/07/12 10:01:47 harold
* add module errno base: ERROR_MISRELAY_BASE * add module errno base: ERROR_MISRELAY_BASE
@ -137,15 +137,15 @@
* no message * no message
* *
* Revision 1.2 2002/01/18 10:01:39 harold * Revision 1.2 2002/01/18 10:01:39 harold
* "读取配置文件函数库" * "读取配置文件函数库"
* *
* Revision 1.1.1.1 2001/12/24 09:33:23 harold * Revision 1.1.1.1 2001/12/24 09:33:23 harold
* no message * no message
* *
* Revision 1.2 2001/12/24 06:39:57 harold * Revision 1.2 2001/12/24 06:39:57 harold
* , CPU, , * , CPU, ,
* , , : * , , :
* HAVE__FUNCTION__, __OS__, __PLATFORM__,__TIMEZONE__. * HAVE__FUNCTION__, __OS__, __PLATFORM__,__TIMEZONE__.
* *
* *
*****************************************************************************/ *****************************************************************************/
@ -157,16 +157,16 @@
* \if developer_doc * \if developer_doc
* \file * \file
* *
* \brief , "ERROR_",10xffff. * \brief , "ERROR_",10xffff.
* *
* id: $Id: global_errno.h,v 1.2 2006/08/04 03:37:33 zhuzhenhua Exp $ * id: $Id: global_errno.h,v 1.2 2006/08/04 03:37:33 zhuzhenhua Exp $
* *
* \author prcharold@sina.com.cn develop1@szscada.com * \author prcharold@sina.com.cn develop1@szscada.com
* \endif * \endif
*/ */
/*! /*!
* *
*/ */
#define SUCCESS 0 #define SUCCESS 0
@ -177,44 +177,44 @@
#endif // end of defined(__unix) #endif // end of defined(__unix)
/*! /*!
* , * ,
*/ */
#define ERROR_FAIL 1 #define ERROR_FAIL 1
/*! /*!
* , * ,
*/ */
#define ERROR_FATAL 2 #define ERROR_FATAL 2
/*! /*!
* *
*/ */
#define ERROR_WARNING 3 #define ERROR_WARNING 3
/*! /*!
* *
*/ */
#define ERROR_TIPINFO 4 #define ERROR_TIPINFO 4
/*! /*!
* *
*/ */
#define ERROR_NOT_IMPLEMENT 5 #define ERROR_NOT_IMPLEMENT 5
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// 下面定义了各种库或者可执行模块中的错误代码基值 // 下面定义了各种库或者可执行模块中的错误代码基值
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*! /*!
* *
*/ */
#define ERROR_BASE 10 #define ERROR_BASE 10
/*! /*!
* Windows, SYSV(unix) * Windows, SYSV(unix)
* 0xfff * 0xfff
*/ */
//#ifndef __unix //#ifndef __unix
//# define ERROR_SYSV_BASE (ERROR_BASE + 0xfff) //# define ERROR_SYSV_BASE (ERROR_BASE + 0xfff)
@ -222,475 +222,475 @@
//#endif //#endif
/*! /*!
* *
*/ */
#define ERROR_RTDB_BASE (0x10001) #define ERROR_RTDB_BASE (0x10001)
/*! /*!
* *
*/ */
#define ERROR_HDB_BASE (0x20001) #define ERROR_HDB_BASE (0x20001)
/*! /*!
* *
*/ */
#define ERROR_DBG_BASE (0x30001) #define ERROR_DBG_BASE (0x30001)
/*! /*!
* WindowsWindows * WindowsWindows
* *
*/ */
#define ERROR_XTIME_BASE (0x40001) #define ERROR_XTIME_BASE (0x40001)
/*! /*!
* *
*/ */
#define ERROR_NET_BASE (0x50001) #define ERROR_NET_BASE (0x50001)
/*! /*!
* *
*/ */
#define ERROR_NET_WRITER_BASE (0x60001) #define ERROR_NET_WRITER_BASE (0x60001)
/*! /*!
* DATASERV * DATASERV
*/ */
#define ERROR_DATASERV_BASE (0x70001) #define ERROR_DATASERV_BASE (0x70001)
/*! /*!
* *
*/ */
#define ERROR_CONF_BASE (0x80001) #define ERROR_CONF_BASE (0x80001)
/*! /*!
* *
*/ */
#define ERROR_PDR_BASE (0x90001) #define ERROR_PDR_BASE (0x90001)
/*! /*!
* *
*/ */
#define ERROR_TRACE_BASE (0xA0001) #define ERROR_TRACE_BASE (0xA0001)
/*! /*!
* *
*/ */
#define ERROR_TMSERV_BASE (0xB0001) #define ERROR_TMSERV_BASE (0xB0001)
/*! /*!
* *
*/ */
#define ERROR_ALM_BASE (0xC0001) #define ERROR_ALM_BASE (0xC0001)
/*! /*!
* ICCP * ICCP
*/ */
#define ERROR_ICCP_BASE (0xD0001) #define ERROR_ICCP_BASE (0xD0001)
/*! /*!
* telectrl * telectrl
*/ */
#define ERROR_TELECTRL_BASE (0xE0001) #define ERROR_TELECTRL_BASE (0xE0001)
/*! /*!
* dbrw * dbrw
*/ */
#define ERROR_DBRW_BASE (0xF0001) #define ERROR_DBRW_BASE (0xF0001)
/*! /*!
* (libcal, cal, librmtcalc, rmtcalc) * (libcal, cal, librmtcalc, rmtcalc)
*/ */
#define ERROR_CALC_BASE (0x100001) #define ERROR_CALC_BASE (0x100001)
/*! /*!
* Misserver * Misserver
*/ */
#define ERROR_MISRELAY_BASE (0x110001) #define ERROR_MISRELAY_BASE (0x110001)
/*! /*!
* AUTHSERV * AUTHSERV
*/ */
#define ERROR_AUTHSERV_BASE (0x120001) #define ERROR_AUTHSERV_BASE (0x120001)
/*! /*!
* rtdbmdbstudio/rtattr_s * rtdbmdbstudio/rtattr_s
*/ */
#define ERROR_RTDBM_BASE (0x130001) #define ERROR_RTDBM_BASE (0x130001)
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// 下面定义了最基本的错误代码, 则整个系统中公用 // 下面定义了最基本的错误代码, 则整个系统中公用
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*! /*!
* *
*/ */
#define ERROR_UNEXPECTED (ERROR_BASE + 1) #define ERROR_UNEXPECTED (ERROR_BASE + 1)
/*! /*!
* , , * , ,
*/ */
#define ERROR_EXCEPTION (ERROR_BASE + 2) #define ERROR_EXCEPTION (ERROR_BASE + 2)
/*! /*!
* , 访 * , 访
*/ */
#define ERROR_EXCEPTION_ACCESS_VIOLATION (ERROR_BASE + 3) #define ERROR_EXCEPTION_ACCESS_VIOLATION (ERROR_BASE + 3)
/*! /*!
* , (), * , (),
* , . * , .
*/ */
#define ERROR_PARAMETER (ERROR_BASE + 4) #define ERROR_PARAMETER (ERROR_BASE + 4)
/*! /*!
* , NULL * , NULL
*/ */
#define ERROR_POINTER (ERROR_BASE + 5) #define ERROR_POINTER (ERROR_BASE + 5)
/*! /*!
* *
*/ */
#define ERROR_MEMORY_ALLOC (ERROR_BASE + 6) #define ERROR_MEMORY_ALLOC (ERROR_BASE + 6)
/*! /*!
* *
*/ */
#define ERROR_ENVIRONMENT_VARIABLE (ERROR_BASE + 7) #define ERROR_ENVIRONMENT_VARIABLE (ERROR_BASE + 7)
/*! /*!
* IPC, . * IPC, .
*/ */
#define ERROR_IPC_OBJECT_EXISTED (ERROR_BASE + 8) #define ERROR_IPC_OBJECT_EXISTED (ERROR_BASE + 8)
/*! /*!
* fopen * fopen
*/ */
#define ERROR_FOPEN (ERROR_BASE + 9) #define ERROR_FOPEN (ERROR_BASE + 9)
/*! /*!
* fread. * fread.
*/ */
#define ERROR_FREAD (ERROR_BASE + 10) #define ERROR_FREAD (ERROR_BASE + 10)
/*! /*!
* (shmat) * (shmat)
*/ */
#define ERROR_SHMAT (ERROR_BASE + 11) #define ERROR_SHMAT (ERROR_BASE + 11)
/*! /*!
* (shmdt) * (shmdt)
*/ */
#define ERROR_SHMDT (ERROR_BASE + 13) #define ERROR_SHMDT (ERROR_BASE + 13)
/*! /*!
* (semctl) * (semctl)
*/ */
#define ERROR_SEMCTL (ERROR_BASE + 14) #define ERROR_SEMCTL (ERROR_BASE + 14)
/*! /*!
* . * .
*/ */
#define ERROR_NO_MEMORY (ERROR_BASE + 15) #define ERROR_NO_MEMORY (ERROR_BASE + 15)
/*! /*!
* *
*/ */
#define ERROR_RAW_STREAM_QUEUE_IS_FULL (ERROR_BASE + 16) #define ERROR_RAW_STREAM_QUEUE_IS_FULL (ERROR_BASE + 16)
/*! /*!
* *
*/ */
#define ERROR_RAW_STREAM_QUEUE_IS_DELETE (ERROR_BASE + 17) #define ERROR_RAW_STREAM_QUEUE_IS_DELETE (ERROR_BASE + 17)
/*! /*!
* *
*/ */
#define ERROR_RAW_STREAM_QUEUE_NOT_ENOUGH_BYTE (ERROR_BASE + 18) #define ERROR_RAW_STREAM_QUEUE_NOT_ENOUGH_BYTE (ERROR_BASE + 18)
/*! /*!
* (dlopen) * (dlopen)
*/ */
#define ERROR_SHLIB_DLOPEN (ERROR_BASE + 19) #define ERROR_SHLIB_DLOPEN (ERROR_BASE + 19)
/*! /*!
* msgctl * msgctl
*/ */
#define ERROR_MSGCTL_RMID (ERROR_BASE + 20) #define ERROR_MSGCTL_RMID (ERROR_BASE + 20)
/*! /*!
* msggetipc * msggetipc
*/ */
#define ERROR_MSGGET_CREATE (ERROR_BASE + 21) #define ERROR_MSGGET_CREATE (ERROR_BASE + 21)
/*! /*!
* ipcid * ipcid
*/ */
#define ERROR_MSG_QUEUE_ID (ERROR_BASE + 22) #define ERROR_MSG_QUEUE_ID (ERROR_BASE + 22)
/*! /*!
* *
*/ */
#define ERROR_MSGRCV (ERROR_BASE + 23) #define ERROR_MSGRCV (ERROR_BASE + 23)
/*! /*!
* *
*/ */
#define ERROR_MSGRCV_TOO_BIG_ITEM (ERROR_BASE + 24) #define ERROR_MSGRCV_TOO_BIG_ITEM (ERROR_BASE + 24)
/*! /*!
* (, ) * (, )
*/ */
#define ERROR_MSG_QUEUE_REMOVED (ERROR_BASE + 25) #define ERROR_MSG_QUEUE_REMOVED (ERROR_BASE + 25)
/*! /*!
* *
*/ */
#define ERROR_MSGRCV_NO_MSG (ERROR_BASE + 26) #define ERROR_MSGRCV_NO_MSG (ERROR_BASE + 26)
/*! /*!
* msgget. * msgget.
*/ */
#define ERROR_MSGGET_REFER (ERROR_BASE + 27) #define ERROR_MSGGET_REFER (ERROR_BASE + 27)
/*! /*!
* SHMCTL * SHMCTL
*/ */
#define ERROR_SHMCTL_STAT (ERROR_BASE + 28) #define ERROR_SHMCTL_STAT (ERROR_BASE + 28)
/*! /*!
* . * .
*/ */
#define ERROR_DELETE_ATTACHED_SHM (ERROR_BASE + 29) #define ERROR_DELETE_ATTACHED_SHM (ERROR_BASE + 29)
/*! /*!
* shmctl * shmctl
*/ */
#define ERROR_SHMCTL_RMID (ERROR_BASE + 30) #define ERROR_SHMCTL_RMID (ERROR_BASE + 30)
/*! /*!
* shmctl * shmctl
*/ */
#define ERROR_SHMCTL_LOCK (ERROR_BASE + 31) #define ERROR_SHMCTL_LOCK (ERROR_BASE + 31)
/*! /*!
* shmctl * shmctl
*/ */
#define ERROR_SHMCTL_UNLOCK (ERROR_BASE + 32) #define ERROR_SHMCTL_UNLOCK (ERROR_BASE + 32)
/*! /*!
* semctl * semctl
*/ */
#define ERROR_SEMCTL_RMID (ERROR_BASE + 33) #define ERROR_SEMCTL_RMID (ERROR_BASE + 33)
/*! /*!
* shmget * shmget
*/ */
#define ERROR_SHMGET_REFER (ERROR_BASE + 34) #define ERROR_SHMGET_REFER (ERROR_BASE + 34)
/*! /*!
* shmget * shmget
*/ */
#define ERROR_SHMGET_CREATE (ERROR_BASE + 35) #define ERROR_SHMGET_CREATE (ERROR_BASE + 35)
/*! /*!
* *
*/ */
#define ERROR_SHM_ADDR_INVALID (ERROR_BASE + 36) #define ERROR_SHM_ADDR_INVALID (ERROR_BASE + 36)
/*! /*!
* semop * semop
*/ */
#define ERROR_SEMOP (ERROR_BASE + 37) #define ERROR_SEMOP (ERROR_BASE + 37)
/*! /*!
* *
*/ */
#define ERROR_NO_FILE (ERROR_BASE + 38) #define ERROR_NO_FILE (ERROR_BASE + 38)
/*! /*!
* stat * stat
*/ */
#define ERROR_STAT (ERROR_BASE + 39) #define ERROR_STAT (ERROR_BASE + 39)
/*! /*!
* shmget, * shmget,
*/ */
#define ERROR_SEMGET_CREATE (ERROR_BASE + 40) #define ERROR_SEMGET_CREATE (ERROR_BASE + 40)
/*! /*!
* shmget, * shmget,
*/ */
#define ERROR_SEMGET_REFER (ERROR_BASE + 41) #define ERROR_SEMGET_REFER (ERROR_BASE + 41)
/*! /*!
* fwrite * fwrite
*/ */
#define ERROR_FWRITE (ERROR_BASE + 42) #define ERROR_FWRITE (ERROR_BASE + 42)
/*! /*!
* *
*/ */
#define ERROR_BUFFER_LENGTH (ERROR_BASE + 43) #define ERROR_BUFFER_LENGTH (ERROR_BASE + 43)
/*! /*!
* *
*/ */
#define ERROR_ATTR_NO (ERROR_BASE + 44) #define ERROR_ATTR_NO (ERROR_BASE + 44)
/*! /*!
* SCADA(, * SCADA(,
* *
*/ */
#define ERROR_SCADA_DT_STRING (ERROR_BASE + 45) #define ERROR_SCADA_DT_STRING (ERROR_BASE + 45)
/*! /*!
* () * ()
*/ */
#define ERROR_BUFFER_INTEGRALITY (ERROR_BASE + 46) #define ERROR_BUFFER_INTEGRALITY (ERROR_BASE + 46)
/*! /*!
* gethostname * gethostname
*/ */
#define ERROR_GETHOSTNAME (ERROR_BASE + 47) #define ERROR_GETHOSTNAME (ERROR_BASE + 47)
/*! /*!
* gethostbyname * gethostbyname
*/ */
#define ERROR_GETHOSTBYNAME (ERROR_BASE + 48) #define ERROR_GETHOSTBYNAME (ERROR_BASE + 48)
/*! /*!
* sendto * sendto
*/ */
#define ERROR_SENDTO (ERROR_BASE + 49) #define ERROR_SENDTO (ERROR_BASE + 49)
/*! /*!
* . * .
*/ */
#define ERROR_MSG_UNEXPECTED_LENGTH (ERROR_BASE + 50) #define ERROR_MSG_UNEXPECTED_LENGTH (ERROR_BASE + 50)
/*! /*!
* . * .
*/ */
#define ERROR_MSG_UNEXPECTED_TYPE (ERROR_BASE + 51) #define ERROR_MSG_UNEXPECTED_TYPE (ERROR_BASE + 51)
/*! /*!
* socket * socket
*/ */
#define ERROR_SOCKET (ERROR_BASE + 52) #define ERROR_SOCKET (ERROR_BASE + 52)
/*! /*!
* bind * bind
*/ */
#define ERROR_BIND (ERROR_BASE + 53) #define ERROR_BIND (ERROR_BASE + 53)
/*! /*!
* fcntl * fcntl
*/ */
#define ERROR_FCNTL (ERROR_BASE + 54) #define ERROR_FCNTL (ERROR_BASE + 54)
/*! /*!
* setsockopt * setsockopt
*/ */
#define ERROR_SETSOCKOPT (ERROR_BASE + 55) #define ERROR_SETSOCKOPT (ERROR_BASE + 55)
/*! /*!
* getsockopt * getsockopt
*/ */
#define ERROR_GETSOCKOPT (ERROR_BASE + 56) #define ERROR_GETSOCKOPT (ERROR_BASE + 56)
/*! /*!
* connect * connect
*/ */
#define ERROR_CONNECT (ERROR_BASE + 57) #define ERROR_CONNECT (ERROR_BASE + 57)
/*! /*!
* read * read
*/ */
#define ERROR_READ (ERROR_BASE + 58) #define ERROR_READ (ERROR_BASE + 58)
/*! /*!
* write * write
*/ */
#define ERROR_WRITE (ERROR_BASE + 59) #define ERROR_WRITE (ERROR_BASE + 59)
/*! /*!
* select * select
*/ */
#define ERROR_SELECT (ERROR_BASE + 60) #define ERROR_SELECT (ERROR_BASE + 60)
/*! /*!
* listen * listen
*/ */
#define ERROR_LISTEN (ERROR_BASE + 61) #define ERROR_LISTEN (ERROR_BASE + 61)
/*! /*!
* fork * fork
*/ */
#define ERROR_FORK (ERROR_BASE + 62) #define ERROR_FORK (ERROR_BASE + 62)
/*! /*!
* execve * execve
*/ */
#define ERROR_EXECVE (ERROR_BASE + 63) #define ERROR_EXECVE (ERROR_BASE + 63)
/*! /*!
* execv * execv
*/ */
#define ERROR_EXECV (ERROR_BASE + 64) #define ERROR_EXECV (ERROR_BASE + 64)
/*! /*!
* 线pthread_create * 线pthread_create
*/ */
#define ERROR_PTHREAD_CREATE (ERROR_BASE + 65) #define ERROR_PTHREAD_CREATE (ERROR_BASE + 65)
#define ERROR_CREATE_THREAD ERROR_PTHREAD_CREATE #define ERROR_CREATE_THREAD ERROR_PTHREAD_CREATE
/*! /*!
* recv * recv
*/ */
#define ERROR_RECV (ERROR_BASE + 66) #define ERROR_RECV (ERROR_BASE + 66)
/*! /*!
* *
*/ */
#if defined(OS_LINUX) #if defined(OS_LINUX)
#ifndef ERROR_TIMEOUT #ifndef ERROR_TIMEOUT
@ -700,101 +700,101 @@
/*! /*!
* send * send
*/ */
#define ERROR_SEND (ERROR_BASE + 68) #define ERROR_SEND (ERROR_BASE + 68)
/*! /*!
* select, fdset. * select, fdset.
*/ */
#define ERROR_SELECT_EXCEPTION (ERROR_BASE + 69) #define ERROR_SELECT_EXCEPTION (ERROR_BASE + 69)
/*! /*!
* select, 0 * select, 0
*/ */
#define ERROR_READ_ZERO (ERROR_BASE + 70) #define ERROR_READ_ZERO (ERROR_BASE + 70)
/*! /*!
* select, 0 * select, 0
*/ */
#define ERROR_WRITE_ZERO (ERROR_BASE + 71) #define ERROR_WRITE_ZERO (ERROR_BASE + 71)
/*! /*!
* select, 0 * select, 0
*/ */
#define ERROR_RECV_ZERO (ERROR_BASE + 72) #define ERROR_RECV_ZERO (ERROR_BASE + 72)
/*! /*!
* select, 0 * select, 0
*/ */
#define ERROR_SEND_ZERO (ERROR_BASE + 73) #define ERROR_SEND_ZERO (ERROR_BASE + 73)
/*! /*!
* *
*/ */
#define ERROR_NOT_EXIST (ERROR_BASE + 74) #define ERROR_NOT_EXIST (ERROR_BASE + 74)
/*! /*!
* *
*/ */
#define ERROR_COMMIT (ERROR_BASE + 75) #define ERROR_COMMIT (ERROR_BASE + 75)
/*! /*!
* / * /
*/ */
#define ERROR_ROLLBACK (ERROR_BASE + 76) #define ERROR_ROLLBACK (ERROR_BASE + 76)
/*! /*!
* fputs * fputs
*/ */
#define ERROR_FPUTS (ERROR_BASE + 77) #define ERROR_FPUTS (ERROR_BASE + 77)
/*! /*!
* mkdir * mkdir
*/ */
#define ERROR_MKDIR (ERROR_BASE + 78) #define ERROR_MKDIR (ERROR_BASE + 78)
/*! /*!
* OPEN * OPEN
*/ */
#define ERROR_OPEN (ERROR_BASE + 79) #define ERROR_OPEN (ERROR_BASE + 79)
/*! /*!
* *
*/ */
#define ERROR_EXIST (ERROR_BASE + 80) #define ERROR_EXIST (ERROR_BASE + 80)
/*! /*!
* fseek * fseek
*/ */
#define ERROR_FSEEK (ERROR_BASE + 81) #define ERROR_FSEEK (ERROR_BASE + 81)
/*! /*!
* rename/MoveFile/MoveFileEx * rename/MoveFile/MoveFileEx
*/ */
#define ERROR_RENAME (ERROR_BASE + 82) #define ERROR_RENAME (ERROR_BASE + 82)
/*! /*!
* cpfile.execpfile.exe * cpfile.execpfile.exe
*/ */
#define ERROR_RUN_CPFILE_TCP_C_ON_PRAMIRY_HOST (ERROR_BASE + 83) #define ERROR_RUN_CPFILE_TCP_C_ON_PRAMIRY_HOST (ERROR_BASE + 83)
/*! /*!
* / * /
*/ */
#define ERROR_AUTHSERV_UNKNOWN_NET_FRAME (ERROR_AUTHSERV_BASE + 1) #define ERROR_AUTHSERV_UNKNOWN_NET_FRAME (ERROR_AUTHSERV_BASE + 1)

@ -1,12 +1,12 @@
/****************************************************************************************** /******************************************************************************************
* *
* : * :
* *
* *
* *
* : * :
* , . * , .
* . * .
* *
* $Id: harximoban.h,v 1.2 2006/08/04 03:37:33 zhuzhenhua Exp $ * $Id: harximoban.h,v 1.2 2006/08/04 03:37:33 zhuzhenhua Exp $
* *
@ -15,16 +15,16 @@
* no message * no message
* *
* Revision 1.5 2003/06/05 03:56:21 jehu * Revision 1.5 2003/06/05 03:56:21 jehu
* doxgen * doxgen
* *
* Revision 1.4 2003/05/06 02:31:31 scada * Revision 1.4 2003/05/06 02:31:31 scada
* : $Id: harximoban.h,v 1.2 2006/08/04 03:37:33 zhuzhenhua Exp $, $Log: harximoban.h,v $ * : $Id: harximoban.h,v 1.2 2006/08/04 03:37:33 zhuzhenhua Exp $, $Log: harximoban.h,v $
* : $Id: chain_hash.h,v 1.5 2003/06/05 03:56:21 jehu Exp $, Revision 1.2 2006/08/04 03:37:33 zhuzhenhua * : $Id: chain_hash.h,v 1.5 2003/06/05 03:56:21 jehu Exp $, Revision 1.2 2006/08/04 03:37:33 zhuzhenhua
* : $Id: chain_hash.h,v 1.5 2003/06/05 03:56:21 jehu Exp $, no message * : $Id: chain_hash.h,v 1.5 2003/06/05 03:56:21 jehu Exp $, no message
* : $Id: chain_hash.h,v 1.5 2003/06/05 03:56:21 jehu Exp $, * : $Id: chain_hash.h,v 1.5 2003/06/05 03:56:21 jehu Exp $,
* : $Id: harximoban.h,v 1.2 2006/08/04 03:37:33 zhuzhenhua Exp $, Revision 1.5 2003/06/05 03:56:21 jehu * : $Id: harximoban.h,v 1.2 2006/08/04 03:37:33 zhuzhenhua Exp $, Revision 1.5 2003/06/05 03:56:21 jehu
* : $Id: harximoban.h,v 1.2 2006/08/04 03:37:33 zhuzhenhua Exp $, doxgen * : $Id: harximoban.h,v 1.2 2006/08/04 03:37:33 zhuzhenhua Exp $, doxgen
* : $Id: harximoban.h,v 1.2 2006/08/04 03:37:33 zhuzhenhua Exp $, * : $Id: harximoban.h,v 1.2 2006/08/04 03:37:33 zhuzhenhua Exp $,
* *
* *
******************************************************************************************/ ******************************************************************************************/
@ -35,38 +35,38 @@
* \if developer_doc * \if developer_doc
* \file * \file
* *
* \brief * \brief
* *
* , , * , ,
* .\n * .\n
* id: $Id: harximoban.h,v 1.2 2006/08/04 03:37:33 zhuzhenhua Exp $ * id: $Id: harximoban.h,v 1.2 2006/08/04 03:37:33 zhuzhenhua Exp $
* *
* \author prcharold@sina.com.cn develop1@szscada.com * \author prcharold@sina.com.cn develop1@szscada.com
* \endif * \endif
*/ */
/*! /*!
* \brief * \brief
*/ */
#define CONST_CHAIN_HASH_DEFAULT_MIN_SIZE 0x10 #define CONST_CHAIN_HASH_DEFAULT_MIN_SIZE 0x10
/*! /*!
* \brief * \brief
*/ */
#define CONST_CHAIN_HASH_DEFAULT_MAX_SIZE 0xffff #define CONST_CHAIN_HASH_DEFAULT_MAX_SIZE 0xffff
/*! /*!
* \brief * \brief
* \param T ---- * \param T ----
* *
* \par * \par
* #include <util/util.h> * #include <util/util.h>
*/ */
#pragma pack (1) #pragma pack (1)
// 是pc机系统还是嵌入式系统 // 是pc机系统还是嵌入式系统
#ifdef PC_MACHINE #ifdef PC_MACHINE
@ -85,35 +85,35 @@
template <class T> class TChainHash template <class T> class TChainHash
{ {
public: public:
/*! 根据哈希表存储的元素的关键字以及哈希表的尺寸,求哈希序号的函数重定义 */ /*! 根据哈希表存储的元素的关键字以及哈希表的尺寸,求哈希序号的函数重定义 */
typedef u32 (* pfnindex_of_t)(const void * pKey, u32 hash_size); typedef u32 (* pfnindex_of_t)(const void * pKey, u32 hash_size);
/*! 根据哈希表存储的元素的关键字的函数重定义 */ /*! 根据哈希表存储的元素的关键字的函数重定义 */
typedef void * (* pfnkey_of_t)(const T * pItem); typedef void * (* pfnkey_of_t)(const T * pItem);
/*! 两个哈希表中存储的元素的关键字之间的比较,主要是比较是否相等 */ /*! 两个哈希表中存储的元素的关键字之间的比较,主要是比较是否相等 */
typedef int (* pfncompare_t)(const void * pKey1, const void * pKey2); typedef int (* pfncompare_t)(const void * pKey1, const void * pKey2);
/*! 根据已经一个已经存在的哈希元素,赋值一个新的对象 */ /*! 根据已经一个已经存在的哈希元素,赋值一个新的对象 */
typedef T * (* pfncreate_item_t)(const T * pItem); typedef T * (* pfncreate_item_t)(const T * pItem);
/*! 释放调用 *pfncreate_item_t 返回的对象 */ /*! 释放调用 *pfncreate_item_t 返回的对象 */
typedef void (* pfnfree_item_t)(T * pItem); typedef void (* pfnfree_item_t)(T * pItem);
/*! 哈希元素之间的拷贝 */ /*! 哈希元素之间的拷贝 */
typedef T * (* pfncopy_item_t)(T * pItemDest, const T * pItemSrc); typedef T * (* pfncopy_item_t)(T * pItemDest, const T * pItemSrc);
/*! 使用者提供的内存分配函数 */ /*! 使用者提供的内存分配函数 */
typedef void * (* pfnalloc_t)(u32 size); typedef void * (* pfnalloc_t)(u32 size);
/*! 释放调用 *pfnalloc_t 分配的内存 */ /*! 释放调用 *pfnalloc_t 分配的内存 */
typedef void (* pfndealloc_t)(void *); typedef void (* pfndealloc_t)(void *);
/*! /*!
* "数据" * "数据"
*/ */
typedef struct typedef struct
{ {
/*! /*!
* "数据" * "数据"
*/ */
T * pT; T * pT;
/*! /*!
* 使 * 使
*/ */
void * pvTKey; void * pvTKey;
@ -122,35 +122,35 @@ public:
/*! /*!
* , "同义", \n * , "同义", \n
* .\n * .\n
* 使线. * 使线.
*/ */
typedef struct typedef struct
{ {
/*! /*!
* -- * --
*/ */
u32 cntItems; u32 cntItems;
/*! /*!
* . * .
* pItems * pItems
*/ */
u32 cntAllocItems; u32 cntAllocItems;
/*! /*!
* *
*/ */
PITEM_t pItems; PITEM_t pItems;
/*! /*!
* "数据" * "数据"
*/ */
T * pT; T * pT;
/*! /*!
* *
*/ */
void * pvTKey; void * pvTKey;
@ -159,27 +159,27 @@ public:
private: private:
/*! /*!
* 使. * 使.
*/ */
TChainHash(){}; TChainHash(){};
public: public:
/*! /*!
* \brief * \brief
* *
* \param u32TableSize --[in] * \param u32TableSize --[in]
* \param pfnIndexOf --[in] 使 * \param pfnIndexOf --[in] 使
* \param pfnKeyOf --[in] 使. * \param pfnKeyOf --[in] 使.
* \param pfnCompare --[in] * \param pfnCompare --[in]
* \param pfnCreateItem --[in] 使 * \param pfnCreateItem --[in] 使
* \param pfnFreeItem --[in] 使 * \param pfnFreeItem --[in] 使
* \param pfnCopyItem --[in] 使. * \param pfnCopyItem --[in] 使.
* \param pfnAlloc --[in] 使. * \param pfnAlloc --[in] 使.
* \param pfnDeAlloc --[in] 使pfnAlloc * \param pfnDeAlloc --[in] 使pfnAlloc
* *
* \note * \note
* 使. * 使.
* . * .
*/ */
TChainHash( TChainHash(
u32 u32TableSize, u32 u32TableSize,
@ -194,7 +194,7 @@ public:
) )
{ {
/* /*
* 使 * 使
*/ */
if(pfnIndexOf) if(pfnIndexOf)
m_pfnIndexOf = pfnIndexOf; m_pfnIndexOf = pfnIndexOf;
@ -237,7 +237,7 @@ public:
m_pfnDeAlloc = NULL; m_pfnDeAlloc = NULL;
/* /*
* *
*/ */
m_uiSize = u32TableSize; m_uiSize = u32TableSize;
if(m_uiSize > (u32)CONST_CHAIN_HASH_DEFAULT_MAX_SIZE) if(m_uiSize > (u32)CONST_CHAIN_HASH_DEFAULT_MAX_SIZE)
@ -248,7 +248,7 @@ public:
/* /*
* *
*/ */
if(m_pfnAlloc && m_pfnDeAlloc) if(m_pfnAlloc && m_pfnDeAlloc)
m_pTable = (PTABLEENTRY_t)(*m_pfnAlloc)((u32)sizeof(TABLEENTRY_t) * m_uiSize); m_pTable = (PTABLEENTRY_t)(*m_pfnAlloc)((u32)sizeof(TABLEENTRY_t) * m_uiSize);
@ -261,7 +261,7 @@ public:
/*! /*!
* \brief * \brief
*/ */
virtual ~TChainHash() virtual ~TChainHash()
{ {
@ -269,7 +269,7 @@ public:
return; return;
/* /*
* . * .
*/ */
for(u32 i = 0; i < m_uiSize; i++) for(u32 i = 0; i < m_uiSize; i++)
{ {
@ -289,7 +289,7 @@ public:
} }
/* /*
* *
*/ */
if(m_pfnAlloc && m_pfnDeAlloc) if(m_pfnAlloc && m_pfnDeAlloc)
{ {
@ -306,126 +306,126 @@ public:
private: private:
/*! /*!
* *
*/ */
u32 m_uiSize; u32 m_uiSize;
/*! /*!
* *
*/ */
PTABLEENTRY_t m_pTable; PTABLEENTRY_t m_pTable;
/*! /*!
* \brief , * \brief ,
* *
* \param pKey --[in] * \param pKey --[in]
* \param hash_size --[in] * \param hash_size --[in]
* *
* \return * \return
* [0 -- hash_size - 1) * [0 -- hash_size - 1)
*/ */
u32 (* m_pfnIndexOf)(const void * pKey, u32 hash_size); u32 (* m_pfnIndexOf)(const void * pKey, u32 hash_size);
/*! /*!
* \brief * \brief
* *
* \param pItem --[in] * \param pItem --[in]
* *
* \return * \return
* *
*/ */
void * (* m_pfnKeyOf)(const T * pItem); void * (* m_pfnKeyOf)(const T * pItem);
/*! /*!
* \brief * \brief
* *
* \param pKey1 --[in] 1 * \param pKey1 --[in] 1
* \param pKey2 --[in] 2 * \param pKey2 --[in] 2
* *
* \return * \return
* 0 -- pKey1pKey2 * 0 -- pKey1pKey2
* 0 -- pKey1pKey2 * 0 -- pKey1pKey2
* 0 -- pKey1pKey2 * 0 -- pKey1pKey2
*/ */
int (* m_pfnCompare)(const void * pKey1, const void * pKey2); int (* m_pfnCompare)(const void * pKey1, const void * pKey2);
/*! /*!
* \brief , . * \brief , .
* *
* \param pItem --[in] * \param pItem --[in]
* *
* \return * \return
* *
*/ */
T * (* m_pfnCreateItem)(const T * pItem); T * (* m_pfnCreateItem)(const T * pItem);
/*! /*!
* \brief m_pfnCreateItem, m_pfnCreateItem * \brief m_pfnCreateItem, m_pfnCreateItem
* *
* \param pItem --[in] * \param pItem --[in]
*/ */
void (* m_pfnFreeItem)(T * pItem); void (* m_pfnFreeItem)(T * pItem);
/*! /*!
* \brief . * \brief .
* *
* \param pItemDest --[in] * \param pItemDest --[in]
* \param pItemSrc --[in] * \param pItemSrc --[in]
* *
* \return * \return
* *
*/ */
T * (* m_pfnCopyItem)(T * pItemDest, const T * pItemSrc); T * (* m_pfnCopyItem)(T * pItemDest, const T * pItemSrc);
/*! /*!
* \brief , 使, 使. * \brief , 使, 使.
* *
* \param size --[in] , * \param size --[in] ,
* *
* \return * \return
* *
*/ */
void * (* m_pfnAlloc)(u32 size); void * (* m_pfnAlloc)(u32 size);
/*! /*!
* \brief m_pfnAlloc, m_pfnAlloc, m_pfnAlloc. * \brief m_pfnAlloc, m_pfnAlloc, m_pfnAlloc.
* *
* \param pVoid --[in][out] m_pfnAlloc * \param pVoid --[in][out] m_pfnAlloc
*/ */
void (* m_pfnDeAlloc)(void * pVoid); void (* m_pfnDeAlloc)(void * pVoid);
/*! /*!
* \brief , , * \brief , ,
* , , . * , , .
* *
* \param pEntry -- . * \param pEntry -- .
* *
* \retval true -- * \retval true --
* \retval false -- * \retval false --
* *
* \note * \note
* 使 * 使
*/ */
bool increaseSynonyms(PTABLEENTRY_t pEntry) bool increaseSynonyms(PTABLEENTRY_t pEntry)
{ {
// 倍增式地分配内存 // 倍增式地分配内存
u32 count = pEntry->cntAllocItems; u32 count = pEntry->cntAllocItems;
if(0 == count) if(0 == count)
count = 2; count = 2;
else else
count = count * 2; count = count * 2;
// 首先分配目的尺寸的哈希项数组--同义词数组 // 首先分配目的尺寸的哈希项数组--同义词数组
PITEM_t pItems = NULL; PITEM_t pItems = NULL;
if(m_pfnAlloc && m_pfnDeAlloc) if(m_pfnAlloc && m_pfnDeAlloc)
pItems = (PITEM_t) (*m_pfnAlloc)(count * (u32)sizeof(ITEM_t)); pItems = (PITEM_t) (*m_pfnAlloc)(count * (u32)sizeof(ITEM_t));
@ -438,7 +438,7 @@ private:
return false; return false;
// 拷贝, 此处显然两块内存不会重叠, 所以使用memcpy内存拷贝, 而不是memmove // 拷贝, 此处显然两块内存不会重叠, 所以使用memcpy内存拷贝, 而不是memmove
memcpy((void *)pItems, (void *)pEntry->pItems, pEntry->cntItems * sizeof(ITEM_t)); memcpy((void *)pItems, (void *)pEntry->pItems, pEntry->cntItems * sizeof(ITEM_t));
if(m_pfnAlloc && m_pfnDeAlloc) if(m_pfnAlloc && m_pfnDeAlloc)
{ {
@ -458,17 +458,17 @@ private:
/*! /*!
* \brief "", , , . * \brief "", , , .
* *
* \param pEntry --[in] * \param pEntry --[in]
* \param pT --[in] * \param pT --[in]
* \param pvTKey --[in] . * \param pvTKey --[in] .
* *
* \retval true -- * \retval true --
* \retval false -- * \retval false --
* *
* \note * \note
* , . * , .
*/ */
bool insertIntoEntry(PTABLEENTRY_t pEntry, T * pT, void * pvTKey) bool insertIntoEntry(PTABLEENTRY_t pEntry, T * pT, void * pvTKey)
{ {
@ -495,7 +495,7 @@ private:
public: public:
/*! /*!
* \brief * \brief
*/ */
u32 hash_size() u32 hash_size()
{ {
@ -504,7 +504,7 @@ public:
/*! /*!
* \brief * \brief
*/ */
u32 count() u32 count()
{ {
@ -525,18 +525,18 @@ public:
/*! /*!
* \brief , , , . * \brief , , , .
* *
* \param pKey --[in] * \param pKey --[in]
* *
* \retval -- * \retval --
* \retval NULL -- , , * \retval NULL -- , ,
* *
* \note * \note
* ,\n * ,\n
* 使使:\n * 使使:\n
* pfnKeyOf -- 使;\n * pfnKeyOf -- 使;\n
* pfnCompare -- ;\n * pfnCompare -- ;\n
*/ */
T * searchItem(const void * pKey) T * searchItem(const void * pKey)
{ {
@ -544,24 +544,24 @@ public:
return NULL; return NULL;
/* /*
* . * .
*/ */
u32 u32index = (*m_pfnIndexOf)(pKey, m_uiSize); u32 u32index = (*m_pfnIndexOf)(pKey, m_uiSize);
if(u32index >= m_uiSize) if(u32index >= m_uiSize)
return NULL; return NULL;
// 找到同义词数组 // 找到同义词数组
PTABLEENTRY_t pEntry = &m_pTable[u32index]; PTABLEENTRY_t pEntry = &m_pTable[u32index];
if(NULL != pEntry->pT && 0 == (*m_pfnCompare)(pKey, pEntry->pvTKey)) if(NULL != pEntry->pT && 0 == (*m_pfnCompare)(pKey, pEntry->pvTKey))
return pEntry->pT; return pEntry->pT;
// 查看首项是否符合. // 查看首项是否符合.
u32 count = pEntry->cntItems; u32 count = pEntry->cntItems;
PITEM_t pSynonyms = pEntry->pItems; PITEM_t pSynonyms = pEntry->pItems;
if(0 == count || NULL == pSynonyms) if(0 == count || NULL == pSynonyms)
return NULL; return NULL;
// 在同义词数组中作线性搜索 // 在同义词数组中作线性搜索
for(u32 i = 0; i < count; i++) for(u32 i = 0; i < count; i++)
{ {
if(pSynonyms[i].pT) if(pSynonyms[i].pT)
@ -576,33 +576,33 @@ public:
/*! /*!
* \brief , , * \brief , ,
* , , , * , , ,
* *
* *
* \param size --[in] * \param size --[in]
* *
* \retval true -- * \retval true --
* \retval false -- * \retval false --
* *
* \note * \note
* , .\n * , .\n
* 使使, \n * 使使, \n
* pfnIndexOf -- 使. * pfnIndexOf -- 使.
*/ */
bool resize(u32 size) bool resize(u32 size)
{ {
if(size == m_uiSize || NULL == m_pfnIndexOf) if(size == m_uiSize || NULL == m_pfnIndexOf)
return true; return true;
// 设置新的尺寸 // 设置新的尺寸
u32 u32Size = size; u32 u32Size = size;
if(u32Size > CONST_CHAIN_HASH_DEFAULT_MAX_SIZE) if(u32Size > CONST_CHAIN_HASH_DEFAULT_MAX_SIZE)
u32Size = CONST_CHAIN_HASH_DEFAULT_MAX_SIZE; u32Size = CONST_CHAIN_HASH_DEFAULT_MAX_SIZE;
if(u32Size < CONST_CHAIN_HASH_DEFAULT_MIN_SIZE) if(u32Size < CONST_CHAIN_HASH_DEFAULT_MIN_SIZE)
u32Size = CONST_CHAIN_HASH_DEFAULT_MIN_SIZE; u32Size = CONST_CHAIN_HASH_DEFAULT_MIN_SIZE;
// 分配哈希表 // 分配哈希表
PTABLEENTRY_t pTable = NULL; PTABLEENTRY_t pTable = NULL;
if(m_pfnAlloc && m_pfnDeAlloc) if(m_pfnAlloc && m_pfnDeAlloc)
pTable = (PTABLEENTRY_t) (*m_pfnAlloc)(sizeof(TABLEENTRY_t) * size); pTable = (PTABLEENTRY_t) (*m_pfnAlloc)(sizeof(TABLEENTRY_t) * size);
@ -614,7 +614,7 @@ public:
memset((void *)pTable, 0, sizeof(TABLEENTRY_t) * size); memset((void *)pTable, 0, sizeof(TABLEENTRY_t) * size);
// 把原哈希表中的元素逐个插入到新的哈希表中去 // 把原哈希表中的元素逐个插入到新的哈希表中去
u32 u32Index = 0; u32 u32Index = 0;
PITEM_t pSynonyms = NULL; PITEM_t pSynonyms = NULL;
u32 i = 0, j = 0; u32 i = 0, j = 0;
@ -645,7 +645,7 @@ public:
} }
} }
// 释放原哈希表所扎内存 // 释放原哈希表所扎内存
for(i = 0; i < m_uiSize; i++) for(i = 0; i < m_uiSize; i++)
{ {
if(NULL != m_pTable[i].pItems) if(NULL != m_pTable[i].pItems)
@ -674,13 +674,13 @@ public:
m_pTable = NULL; m_pTable = NULL;
} }
// 置换新的哈希表及尺寸 // 置换新的哈希表及尺寸
m_pTable = pTable; m_pTable = pTable;
m_uiSize = u32Size; m_uiSize = u32Size;
return true; return true;
// 如果执行失败, 则释放执行过程中分配的内存 // 如果执行失败, 则释放执行过程中分配的内存
label_failed_resize: label_failed_resize:
for(i = 0; i < u32Size; i++) for(i = 0; i < u32Size; i++)
{ {
@ -715,25 +715,25 @@ public:
/*! /*!
* \brief * \brief
* *
* \param pT --[in] * \param pT --[in]
* *
* \retval true -- * \retval true --
* \retval false -- * \retval false --
* *
* \note * \note
* , .\n * , .\n
* 使使\n * 使使\n
* pfnIndexOf -- 使\n * pfnIndexOf -- 使\n
* pfnKeyOf -- 使. * pfnKeyOf -- 使.
*/ */
bool insertItem(T * pT) bool insertItem(T * pT)
{ {
if(NULL == pT || NULL == m_pTable || NULL == m_pfnKeyOf || NULL == m_pfnIndexOf) if(NULL == pT || NULL == m_pTable || NULL == m_pfnKeyOf || NULL == m_pfnIndexOf)
return false; return false;
// 求关键字及哈希值 // 求关键字及哈希值
void * pKey = (*m_pfnKeyOf)(pT); void * pKey = (*m_pfnKeyOf)(pT);
u32 index = (*m_pfnIndexOf)(pKey, m_uiSize); u32 index = (*m_pfnIndexOf)(pKey, m_uiSize);
if(index >= m_uiSize) if(index >= m_uiSize)
@ -747,7 +747,7 @@ public:
return true; return true;
} }
// 插入到同义词数组中去 // 插入到同义词数组中去
if(pEntry->cntItems == pEntry->cntAllocItems) if(pEntry->cntItems == pEntry->cntAllocItems)
{ {
if(false == this->increaseSynonyms(pEntry)) if(false == this->increaseSynonyms(pEntry))
@ -763,20 +763,20 @@ public:
} }
/*! /*!
* \brief * \brief
* *
* \param pT --[in] * \param pT --[in]
* *
* \retval true -- * \retval true --
* \retval false -- , , * \retval false -- , ,
* *
* \note * \note
* false, \n * false, \n
* 使使\n * 使使\n
* pfnIndexOf -- 使\n * pfnIndexOf -- 使\n
* pfnKeyOf -- 使. \n * pfnKeyOf -- 使. \n
* pfnCompare -- \n * pfnCompare -- \n
* pfnFreeItem-- 使pfnAlloc * pfnFreeItem-- 使pfnAlloc
*/ */
bool deleteItem(T * pT) bool deleteItem(T * pT)
{ {
@ -789,19 +789,19 @@ public:
} }
/*! /*!
* \brief * \brief
* *
* \param pKey --[in] * \param pKey --[in]
* *
* \retval true -- * \retval true --
* \retval false -- , , * \retval false -- , ,
* *
* \note * \note
* false, \n * false, \n
* 使使\n * 使使\n
* pfnIndexOf -- 使\n * pfnIndexOf -- 使\n
* pfnCompare -- \n * pfnCompare -- \n
* pfnFreeItem -- 使pfnAlloc * pfnFreeItem -- 使pfnAlloc
*/ */
bool deleteItem_with_key(void * pKey) bool deleteItem_with_key(void * pKey)
{ {
@ -810,7 +810,7 @@ public:
if(NULL == m_pTable || NULL == m_pfnIndexOf || NULL == m_pfnCompare || NULL == m_pfnFreeItem) if(NULL == m_pTable || NULL == m_pfnIndexOf || NULL == m_pfnCompare || NULL == m_pfnFreeItem)
return false; return false;
// 求哈希值 // 求哈希值
u32 index = (*m_pfnIndexOf)(pKey, m_uiSize); u32 index = (*m_pfnIndexOf)(pKey, m_uiSize);
if(index >= m_uiSize) if(index >= m_uiSize)
return false; return false;
@ -853,20 +853,20 @@ public:
} }
/*! /*!
* \brief * \brief
* *
* \param pT --[in] * \param pT --[in]
* *
* \retval -- * \retval --
* \retval NULL -- , , * \retval NULL -- , ,
* *
* \note * \note
* , .\n * , .\n
* NULL, \n * NULL, \n
* 使使\n * 使使\n
* pfnIndexOf -- 使\n * pfnIndexOf -- 使\n
* pfnKeyOf -- 使. \n * pfnKeyOf -- 使. \n
* pfnCompare -- \n * pfnCompare -- \n
*/ */
T * detachItem(T * pT) T * detachItem(T * pT)
{ {
@ -878,19 +878,19 @@ public:
} }
/*! /*!
* \brief * \brief
* *
* \param pKey --[in] * \param pKey --[in]
* *
* \retval -- * \retval --
* \retval NULL -- , , * \retval NULL -- , ,
* *
* \note * \note
* , .\n * , .\n
* NULL, \n * NULL, \n
* 使使\n * 使使\n
* pfnIndexOf -- 使\n * pfnIndexOf -- 使\n
* pfnCompare -- \n * pfnCompare -- \n
*/ */
T * detachItem_with_key(void * pKey) T * detachItem_with_key(void * pKey)
{ {
@ -936,11 +936,11 @@ public:
/*! /*!
* \brief * \brief
* *
* \note * \note
* 使使\n * 使使\n
* pfnFreeItem -- 使pfnAlloc * pfnFreeItem -- 使pfnAlloc
*/ */
bool deleteItems() bool deleteItems()
{ {
@ -980,7 +980,7 @@ public:
} }
/*! /*!
* \brief * \brief
*/ */
void detachItems() void detachItems()
{ {
@ -1002,7 +1002,7 @@ public:
} }
}; };
// 是pc机系统还是嵌入式系统 // 是pc机系统还是嵌入式系统
#ifdef PC_MACHINE #ifdef PC_MACHINE
#ifdef OS_WINDOWS #ifdef OS_WINDOWS

@ -1,7 +1,7 @@
/*---------------------------------------------------------- /*----------------------------------------------------------
INI V1.65 INI V1.65
2002.10.3 2002.10.3
----------------------------------------------------------*/ ----------------------------------------------------------*/
#ifndef INI_FILE_H #ifndef INI_FILE_H
@ -9,48 +9,48 @@
#include "platform_def.h" #include "platform_def.h"
#define MAX_LINE_BUF_LENGTH 2048 //最大行缓冲区长度 #define MAX_LINE_BUF_LENGTH 2048 //最大行缓冲区长度
#define FILE_OPEN_ERROR -1 //文件打开错误 #define FILE_OPEN_ERROR -1 //文件打开错误
#define SECTION_NOT_FOUND -2 //段没有找到 #define SECTION_NOT_FOUND -2 //段没有找到
#define KEY_NOT_FOUND -3 //键没有找到 #define KEY_NOT_FOUND -3 //键没有找到
//工具函数 //工具函数
void StrTrimLeft(char* szBuf); void StrTrimLeft(char* szBuf);
void StrTrimRight(char* szBuf); void StrTrimRight(char* szBuf);
void StrTrimAll(char* szBuf); void StrTrimAll(char* szBuf);
long GetFileSize(char* lpszFileName); long GetFileSize(char* lpszFileName);
int ReadLineFromFile(FILE* IniFile, char* lpszLineBuf, int iLen); //从指定文件中读取一行内容 int ReadLineFromFile(FILE* IniFile, char* lpszLineBuf, int iLen); //从指定文件中读取一行内容
bool IfBeforeHasRet(FILE* pFile); //辅助函数,判断当前文件位置前面是否是换行符号 bool IfBeforeHasRet(FILE* pFile); //辅助函数,判断当前文件位置前面是否是换行符号
//读配置文件中指定段下指定键的值(字符串) //读配置文件中指定段下指定键的值(字符串)
int QGetPrivateProfileString( int QGetPrivateProfileString(
const char* lpszSectionName, //段名 const char* lpszSectionName, //段名
const char* lpszKeyName, //键名 const char* lpszKeyName, //键名
const char* lpszDefault, //缺省字符串 const char* lpszDefault, //缺省字符串
char* lpszReturnedString, //结果字符串 char* lpszReturnedString, //结果字符串
u_32 nSize, //结果字符串长度 u_32 nSize, //结果字符串长度
const char* lpszFileName, //ini文件名 const char* lpszFileName, //ini文件名
const char* lpszRemarkInLineStr = (char*)";", //行内注释符 const char* lpszRemarkInLineStr = (char*)";", //行内注释符
const char chContinueLineChar = '\\' //续行符号 const char chContinueLineChar = '\\' //续行符号
); );
//读配置文件中指定段下指定键的值(整数) //读配置文件中指定段下指定键的值(整数)
int QGetPrivateProfileInt( int QGetPrivateProfileInt(
const char* lpszSectionName, //段名 const char* lpszSectionName, //段名
const char* lpszKeyName, //键名 const char* lpszKeyName, //键名
int nDefault, //缺省值 int nDefault, //缺省值
const char* lpszFileName, //ini文件名 const char* lpszFileName, //ini文件名
const char* lpszRemarkInLineStr = (char*)";", //行内注释符 const char* lpszRemarkInLineStr = (char*)";", //行内注释符
const char chContinueLineChar = '\\' //续行符号 const char chContinueLineChar = '\\' //续行符号
); );
//向配置文件写入指定段下指定键的值(字符串) //向配置文件写入指定段下指定键的值(字符串)
int QWritePrivateProfileString( int QWritePrivateProfileString(
const char* lpszSectionName, //段名 const char* lpszSectionName, //段名
const char* lpszKeyName, //键名 const char* lpszKeyName, //键名
const char* lpszString, //要写入的字符串 const char* lpszString, //要写入的字符串
const char* lpszFileName //INI文件名 const char* lpszFileName //INI文件名
); );
#endif #endif

@ -4,9 +4,9 @@
* Shenzhen SCADA Control Technology Co., Ltd. * Shenzhen SCADA Control Technology Co., Ltd.
* All rights reserved. * All rights reserved.
* *
* *
* *
* : 2004/01/10 * : 2004/01/10
* *
* $Id: list_entry.cpp,v 1.1.1.1 2006/07/05 07:31:43 jehu Exp $ * $Id: list_entry.cpp,v 1.1.1.1 2006/07/05 07:31:43 jehu Exp $
* *
@ -17,7 +17,7 @@
#include "list_entry.h" #include "list_entry.h"
/* /*
* *
*/ */
void Initialize_list_head ( list_entry_t * plist_head ) void Initialize_list_head ( list_entry_t * plist_head )
{ {
@ -25,10 +25,10 @@ void Initialize_list_head ( list_entry_t * plist_head )
} }
/* /*
* *
* *
* \retval 0 * \retval 0
* \retval 0 * \retval 0
*/ */
int is_list_empty ( list_entry_t * plist_head ) int is_list_empty ( list_entry_t * plist_head )
{ {
@ -36,7 +36,7 @@ int is_list_empty ( list_entry_t * plist_head )
} }
/* /*
* -- * --
*/ */
list_entry_t * remove_head_list ( list_entry_t * plist_head ) list_entry_t * remove_head_list ( list_entry_t * plist_head )
{ {
@ -47,7 +47,7 @@ list_entry_t * remove_head_list ( list_entry_t * plist_head )
/* /*
* -- * --
*/ */
list_entry_t * remove_tail_list ( list_entry_t * plist_head ) list_entry_t * remove_tail_list ( list_entry_t * plist_head )
{ {
@ -57,7 +57,7 @@ list_entry_t * remove_tail_list ( list_entry_t * plist_head )
} }
/* /*
* -- * --
*/ */
void remove_entry_list ( list_entry_t * pEntry ) void remove_entry_list ( list_entry_t * pEntry )
{ {
@ -71,7 +71,7 @@ void remove_entry_list ( list_entry_t * pEntry )
} }
/* /*
* *
*/ */
void insert_tail_list ( list_entry_t * plist_head, list_entry_t * pEntry ) void insert_tail_list ( list_entry_t * plist_head, list_entry_t * pEntry )
{ {
@ -87,7 +87,7 @@ void insert_tail_list ( list_entry_t * plist_head, list_entry_t * pEntry )
} }
/* /*
* *
*/ */
void insert_head_list ( list_entry_t * plist_head, list_entry_t * pEntry) void insert_head_list ( list_entry_t * plist_head, list_entry_t * pEntry)
{ {

@ -4,11 +4,11 @@
* Shenzhen SCADA Control Technology Co., Ltd. * Shenzhen SCADA Control Technology Co., Ltd.
* All rights reserved. * All rights reserved.
* *
* *
* *
* : 2004/01/10 * : 2004/01/10
* *
* Windoes $(DDKPATH)/inc/ntdef.h$(DDKPATH)/inc/ddk/ntddk.h * Windoes $(DDKPATH)/inc/ntdef.h$(DDKPATH)/inc/ddk/ntddk.h
* *
* $Id: list_entry.h,v 1.1.1.1 2006/07/05 07:31:43 jehu Exp $ * $Id: list_entry.h,v 1.1.1.1 2006/07/05 07:31:43 jehu Exp $
* *
@ -18,13 +18,13 @@
#define __LIST_ENTRY_H__SKLJFALKJZLJVADFHOPSHVPZIOXJHCVOIPADFDFNXVCQWEDAH #define __LIST_ENTRY_H__SKLJFALKJZLJVADFHOPSHVPZIOXJHCVOIPADFDFNXVCQWEDAH
/*! /*!
* , . * , .
*/ */
typedef struct tag_list_entry_t { typedef struct tag_list_entry_t {
struct tag_list_entry_t * flink; /*!< 指向链表元素的前驱元素 */ struct tag_list_entry_t * flink; /*!< 指向链表元素的前驱元素 */
struct tag_list_entry_t * blink; /*!< 指向链表元素的后继元素 */ struct tag_list_entry_t * blink; /*!< 指向链表元素的后继元素 */
} list_entry_t; } list_entry_t;
@ -33,30 +33,30 @@ typedef list_entry_t ** pplist_entry_t;
/* /*
* *
* *
* +---------------------------+-----------------------------------------------------+ * +---------------------------+-----------------------------------------------------+
* | Initialize_list_head | list_entry_t | * | Initialize_list_head | list_entry_t |
* +---------------------------+-----------------------------------------------------+ * +---------------------------+-----------------------------------------------------+
* | is_list_empty | | * | is_list_empty | |
* +---------------------------+-----------------------------------------------------+ * +---------------------------+-----------------------------------------------------+
* | remove_head_list | --| * | remove_head_list | --|
* +---------------------------+-----------------------------------------------------+ * +---------------------------+-----------------------------------------------------+
* | remove_tail_list | --| * | remove_tail_list | --|
* +---------------------------+-----------------------------------------------------+ * +---------------------------+-----------------------------------------------------+
* | remove_entry_list | -- | * | remove_entry_list | -- |
* +---------------------------+-----------------------------------------------------+ * +---------------------------+-----------------------------------------------------+
* | insert_tail_list | | * | insert_tail_list | |
* +---------------------------+-----------------------------------------------------+ * +---------------------------+-----------------------------------------------------+
* | insert_head_list | | * | insert_head_list | |
* +---------------------------+-----------------------------------------------------+ * +---------------------------+-----------------------------------------------------+
* | CONTAINING_RECORD | | * | CONTAINING_RECORD | |
* +---------------------------+-----------------------------------------------------+ * +---------------------------+-----------------------------------------------------+
* *
*/ */
/* /*
* *
*/ */
#ifdef CONTAINING_RECORD #ifdef CONTAINING_RECORD
#undef CONTAINING_RECORD #undef CONTAINING_RECORD
@ -64,43 +64,43 @@ typedef list_entry_t ** pplist_entry_t;
#define CONTAINING_RECORD(_addr, _type, _field) ((_type *)((char *)(_addr) - (char *)(&((_type *)0)->_field))) #define CONTAINING_RECORD(_addr, _type, _field) ((_type *)((char *)(_addr) - (char *)(&((_type *)0)->_field)))
/* /*
* *
* *
* \param plist_head * \param plist_head
*/ */
void Initialize_list_head ( list_entry_t * plist_head ); void Initialize_list_head ( list_entry_t * plist_head );
/* /*
* *
* *
* \retval 0 * \retval 0
* \retval 0 * \retval 0
*/ */
int is_list_empty ( list_entry_t * plist_head ); int is_list_empty ( list_entry_t * plist_head );
/* /*
* -- * --
*/ */
list_entry_t * remove_head_list ( list_entry_t * plist_head ); list_entry_t * remove_head_list ( list_entry_t * plist_head );
/* /*
* -- * --
*/ */
list_entry_t * remove_tail_list ( list_entry_t * plist_head ); list_entry_t * remove_tail_list ( list_entry_t * plist_head );
/* /*
* -- * --
*/ */
void remove_entry_list ( list_entry_t * pEntry); void remove_entry_list ( list_entry_t * pEntry);
/* /*
* *
*/ */
void insert_tail_list ( list_entry_t * plist_head, list_entry_t * pEntry ); void insert_tail_list ( list_entry_t * plist_head, list_entry_t * pEntry );
/* /*
* *
*/ */
void insert_head_list ( list_entry_t * plist_head, list_entry_t * pEntry); void insert_head_list ( list_entry_t * plist_head, list_entry_t * pEntry);

@ -16,7 +16,7 @@
BYTE CreateUdpSock(int *CommSock, DWORD NetPort, DWORD NetCommIpAddr); BYTE CreateUdpSock(int *CommSock, DWORD NetPort, DWORD NetCommIpAddr);
BYTE CreateTcpServerSock(int *LiSock, DWORD NetPort); BYTE CreateTcpServerSock(int *LiSock, DWORD NetPort);
BYTE CreateTcpClientSock(int *CommSock, DWORD NetPort, DWORD NetCommIpAddr); BYTE CreateTcpClientSock(int *CommSock, DWORD NetPort, DWORD NetCommIpAddr);
// 设置及时知道TCP非优雅的方式断开连接的socket属性 // 设置及时知道TCP非优雅的方式断开连接的socket属性
//void set_keepalive(int fd, int keep_alive, int keep_idle, int keep_interval, int keep_count); //void set_keepalive(int fd, int keep_alive, int keep_idle, int keep_interval, int keep_count);
void OpenNetPort( int commid); void OpenNetPort( int commid);
@ -28,7 +28,7 @@ void UdpSend(int commid);
BOOL TcpRecv(int commid, int fds, u_long ipaddr); BOOL TcpRecv(int commid, int fds, u_long ipaddr);
void TcpSend(int commid); void TcpSend(int commid);
// 检查连接服务器端口的客户端ip地址配置的端口 // 检查连接服务器端口的客户端ip地址配置的端口
void TcpAccept(int commid, int lisfds); void TcpAccept(int commid, int lisfds);
void PollAllPort(void); void PollAllPort(void);

@ -4,9 +4,9 @@
* Shenzhen SCADA Control Technology Co., Ltd. * Shenzhen SCADA Control Technology Co., Ltd.
* All rights reserved. * All rights reserved.
* *
* *
* *
* : 2005/04/12 * : 2005/04/12
* *
***********************************************************************/ ***********************************************************************/
/*#ifdef OS_LINUX /*#ifdef OS_LINUX
@ -36,102 +36,102 @@
#define _fclose(_fp) do {if (_fp) {while (EOF == fclose((_fp)) && EINTR == errno);}} while(0) #define _fclose(_fp) do {if (_fp) {while (EOF == fclose((_fp)) && EINTR == errno);}} while(0)
/*! /*!
* *
*/ */
typedef enum { typedef enum {
eMalloc = 0, /* 使用malloc分配的内存块 */ eMalloc = 0, /* 使用malloc分配的内存块 */
eCalloc = 1 /* 使用calloc分配的内存块 */ eCalloc = 1 /* 使用calloc分配的内存块 */
} heap_type_t; } heap_type_t;
/*! /*!
* *
* *
* \note * \note
* 16 * 16
*/ */
typedef struct tag_heap_head_t { typedef struct tag_heap_head_t {
/* 堆内存块附加头所在的链表的占位 */ /* 堆内存块附加头所在的链表的占位 */
list_entry_t anchor; list_entry_t anchor;
/*! 堆内存块分配发生的时间 */ /*! 堆内存块分配发生的时间 */
struct timeval tv; struct timeval tv;
/*! 堆内存块类型 */ /*! 堆内存块类型 */
heap_type_t type; heap_type_t type;
/*! 堆内存块分配发生的源文件名NULL表示匿名源文件。 */ /*! 堆内存块分配发生的源文件名NULL表示匿名源文件。 */
char * fl; char * fl;
/*! 堆内存块分配发生的源代码行 */ /*! 堆内存块分配发生的源代码行 */
int line; int line;
/*! 堆内存块的尺寸(字节) */ /*! 堆内存块的尺寸(字节) */
size_t size; size_t size;
} heap_list_t; } heap_list_t;
/* 边界对齐量 */ /* 边界对齐量 */
#define os_heap_alignment 16 #define os_heap_alignment 16
#define os_heap_pad ((sizeof(heap_list_t) % os_heap_alignment) ? (os_heap_alignment - (sizeof(heap_list_t) % os_heap_alignment)) : 0) #define os_heap_pad ((sizeof(heap_list_t) % os_heap_alignment) ? (os_heap_alignment - (sizeof(heap_list_t) % os_heap_alignment)) : 0)
/* 根据数据地址求os_heap块的起始地址 */ /* 根据数据地址求os_heap块的起始地址 */
#define os_heap_start_addr(_data) ((void *)(((unsigned char *)(_data)) - sizeof(heap_list_t) - os_heap_pad)) #define os_heap_start_addr(_data) ((void *)(((unsigned char *)(_data)) - sizeof(heap_list_t) - os_heap_pad))
/* 根据os_heap块的起始地址求数据地址 */ /* 根据os_heap块的起始地址求数据地址 */
#define os_heap_data_addr(_start) ((void *)(((unsigned char *)(_start)) + sizeof(heap_list_t) + os_heap_pad)) #define os_heap_data_addr(_start) ((void *)(((unsigned char *)(_start)) + sizeof(heap_list_t) + os_heap_pad))
/* 根据数据块的尺寸求os_heap块的尺寸 */ /* 根据数据块的尺寸求os_heap块的尺寸 */
#define os_heap_mb_size(_size) (sizeof(heap_list_t) + os_heap_pad + (_size)) #define os_heap_mb_size(_size) (sizeof(heap_list_t) + os_heap_pad + (_size))
/* /*
* *
* *
* 1. * 1.
* 2. 线 * 2. 线
* 3. * 3.
* 4. 访 * 4. 访
*/ */
/* 堆内存块设施是否已经初始化 */ /* 堆内存块设施是否已经初始化 */
static int g_heap_initialized = 0; static int g_heap_initialized = 0;
/* 堆内存块双向链表头 */ /* 堆内存块双向链表头 */
static list_entry_t g_heap_head; static list_entry_t g_heap_head;
/* /*
* 使heap_malloc/heap_calloc * 使heap_malloc/heap_calloc
* 使 * 使
*/ */
static size_t g_heap_item_counter = 0; static size_t g_heap_item_counter = 0;
/* /*
* 使heap_malloc/heap_calloc * 使heap_malloc/heap_calloc
* 使() * 使()
*/ */
static size_t g_heap_byte_counter = 0; static size_t g_heap_byte_counter = 0;
/* 初始化堆内存块设施 */ /* 初始化堆内存块设施 */
static void heap_intialize(); static void heap_intialize();
/*! /*!
* \brief * \brief
* *
* \param size * \param size
* \param file null * \param file null
* NULL (anony) * NULL (anony)
* \param line * \param line
* *
* \retutrn * \retutrn
* *
* NULL * NULL
* *
* \note * \note
* 使heap_free * 使heap_free
* *
* ANSI C malloc * ANSI C malloc
*/ */
void * heap_malloc ( void * heap_malloc (
size_t size, size_t size,
@ -187,24 +187,24 @@ void * heap_malloc (
} }
/*! /*!
* \brief , 0. * \brief , 0.
* *
* \param num * \param num
* \param elm_size () * \param elm_size ()
* \param file null * \param file null
* NULL (anony) * NULL (anony)
* \param line * \param line
* *
* \retutrn * \retutrn
* *
* NULL * NULL
* *
* \note * \note
* 使heap_free * 使heap_free
* *
* ANSI C calloc calloc * ANSI C calloc calloc
* callocelm_size * callocelm_size
* *
*/ */
void * heap_calloc ( void * heap_calloc (
size_t num, size_t num,
@ -261,12 +261,12 @@ void * heap_calloc (
} }
/*! /*!
* \brief * \brief
* *
* \param memblock heap_alloc/heap_calloc * \param memblock heap_alloc/heap_calloc
* *
* \return * \return
* *
*/ */
void heap_free (void * mb) void heap_free (void * mb)
{ {
@ -310,26 +310,26 @@ void heap_free (void * mb)
} }
/*! /*!
* \brief * \brief
* *
* *
* *
* \param fname fnameNULL * \param fname fnameNULL
* *
* *
* \retval -1 * \retval -1
* \retval 0 * \retval 0
* *
* \note * \note
* *
* : * :
* 使: * 使:
* ...... * ......
* i: * i:
* : tv * : tv
* : malloc/calloc, * : malloc/calloc,
* : fl(line) * : fl(line)
* : size * : size
* ...... * ......
*/ */
int heap_report(const char * fname) int heap_report(const char * fname)

@ -4,9 +4,9 @@
* Shenzhen SCADA Control Technology Co., Ltd. * Shenzhen SCADA Control Technology Co., Ltd.
* All rights reserved. * All rights reserved.
* *
* *
* *
* : 2005/04/12 * : 2005/04/12
* *
***********************************************************************/ ***********************************************************************/
@ -16,73 +16,73 @@
#include "basetype.h" #include "basetype.h"
/*! /*!
* \brief * \brief
* *
* \param size * \param size
* \param file null * \param file null
* NULL (anony) * NULL (anony)
* \param line * \param line
* *
* \retutrn * \retutrn
* *
* NULL * NULL
* *
* \note * \note
* 使heap_free * 使heap_free
* *
* ANSI C malloc * ANSI C malloc
*/ */
DSLIB_API void * heap_malloc (size_t size, const char * file, int line); DSLIB_API void * heap_malloc (size_t size, const char * file, int line);
/*! /*!
* \brief , 0. * \brief , 0.
* *
* \param num * \param num
* \param elm_size () * \param elm_size ()
* \param file null * \param file null
* NULL (anony) * NULL (anony)
* \param line * \param line
* *
* \retutrn * \retutrn
* *
* NULL * NULL
* *
* \note * \note
* 使heap_free * 使heap_free
* *
* ANSI C calloc calloc * ANSI C calloc calloc
* callocelm_size * callocelm_size
* *
*/ */
DSLIB_API void * heap_calloc (size_t num, size_t elm_size, DSLIB_API void * heap_calloc (size_t num, size_t elm_size,
const char * file, int line); const char * file, int line);
/*! /*!
* \brief * \brief
* *
* \param mb heap_alloc/heap_calloc * \param mb heap_alloc/heap_calloc
* *
* \return * \return
* *
*/ */
DSLIB_API void heap_free (void * mb); DSLIB_API void heap_free (void * mb);
/*! /*!
* \brief * \brief
* *
* *
* *
* \param fname fnameNULL * \param fname fnameNULL
* *
* *
* \retval -1 * \retval -1
* \retval 0 * \retval 0
*/ */
DSLIB_API int heap_report (const char * fname); DSLIB_API int heap_report (const char * fname);
/* /*
* , 便使 * , 便使
* *
* 1. HEAP_MALLOC(_size) * 1. HEAP_MALLOC(_size)
* 2. HEAP_CALLOC(_num, _elm_size) * 2. HEAP_CALLOC(_num, _elm_size)

@ -1,43 +1,43 @@
/*----------------------------------------------------------------------------- /*-----------------------------------------------------------------------------
platform_def.h zl 2002.11.5 platform_def.h zl 2002.11.5
-----------------------------------------------------------------------------*/ -----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------- /*-----------------------------------------------------------------------------
(1) Windows: OS_WINDOWS (1) Windows: OS_WINDOWS
(2) Unix(): OS_UNIX (2) Unix(): OS_UNIX
(3) Linux: _OS_UNIX_LINUX_ (3) Linux: _OS_UNIX_LINUX_
(4) True64: _OS_UNIX_TRUR64_ (4) True64: _OS_UNIX_TRUR64_
(5) Solaris: _OS_UNIX_SOLARIS_ (5) Solaris: _OS_UNIX_SOLARIS_
(6) 64: _OS_64BIT_ (6) 64: _OS_64BIT_
(7) Windows: _OS_WINDOWS_BYTEORDER_ (7) Windows: _OS_WINDOWS_BYTEORDER_
(8) Solaris: _OS_SOLARIS_BYTEORDER_ (8) Solaris: _OS_SOLARIS_BYTEORDER_
[] []
a. 64DEC True64, solaris(32,sizeof a. 64DEC True64, solaris(32,sizeof
(long)=8) (long)=8)
b. windows, linux, true64 solaris,Windows b. windows, linux, true64 solaris,Windows
solaris solaris
c. Unixunix c. Unixunix
-----------------------------------------------------------------------------*/ -----------------------------------------------------------------------------*/
#ifndef PLATFORM_DEF_H #ifndef PLATFORM_DEF_H
#define PLATFORM_DEF_H #define PLATFORM_DEF_H
/*------------------------------------ 头文件引用 --------------------------------*/ /*------------------------------------ 头文件引用 --------------------------------*/
#ifdef OS_WINDOWS //windows #ifdef OS_WINDOWS //windows
#include <windows.h> #include <windows.h>
@ -56,7 +56,7 @@ c. Unix
#include <sys/select.h> #include <sys/select.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <arpa/inet.h> //inet地址族的所有结构和常量定义都在这里 #include <arpa/inet.h> //inet地址族的所有结构和常量定义都在这里
#include <netinet/in.h> #include <netinet/in.h>
#include <errno.h> #include <errno.h>
// #include <stropts.h> // #include <stropts.h>
@ -69,12 +69,12 @@ c. Unix
#include <pthread.h> #include <pthread.h>
#include <string.h> #include <string.h>
// #include <time.h> // #include <time.h>
#include <netdb.h> //定义bsd socket的gethostbyname()函数 #include <netdb.h> //定义bsd socket的gethostbyname()函数
#endif #endif
/*------------------------------------ 名字定义 --------------------------------*/ /*------------------------------------ 名字定义 --------------------------------*/
//全局名字替换名字,为减少移植时大量修改结构及函数名的工作量而设置 //全局名字替换名字,为减少移植时大量修改结构及函数名的工作量而设置
#ifdef OS_UNIX #ifdef OS_UNIX
#define SYSTEMTIME QSYSTEMTIME #define SYSTEMTIME QSYSTEMTIME
@ -85,13 +85,13 @@ c. Unix
#define GetPrivateProfileInt QGetPrivateProfileInt #define GetPrivateProfileInt QGetPrivateProfileInt
#define WritePrivateProfileString QWritePrivateProfileString #define WritePrivateProfileString QWritePrivateProfileString
#define closesocket close //winsock中关闭socket用closesocket(),而bsd socket中用close() #define closesocket close //winsock中关闭socket用closesocket(),而bsd socket中用close()
#define _strdup strdup #define _strdup strdup
#define lstrcpyn strncpy #define lstrcpyn strncpy
#define _getcwd getcwd #define _getcwd getcwd
#endif #endif
/*-------------------------------- 类型定义 ------------------------------------*/ /*-------------------------------- 类型定义 ------------------------------------*/
#ifdef OS_UNIX #ifdef OS_UNIX
@ -109,7 +109,7 @@ c. Unix
typedef unsigned int u_int; typedef unsigned int u_int;
typedef unsigned int UINT; typedef unsigned int UINT;
typedef unsigned int SOCKET; //为编译通过而临时从Winsock.h中提取的类型定义 typedef unsigned int SOCKET; //为编译通过而临时从Winsock.h中提取的类型定义
typedef unsigned long u_long; typedef unsigned long u_long;
typedef unsigned long ULONG; typedef unsigned long ULONG;
@ -117,36 +117,36 @@ c. Unix
#endif #endif
#ifdef _OS_64BIT_ #ifdef _OS_64BIT_
typedef int i_32; //固定长度为4个字节的有符号整数类型 typedef int i_32; //固定长度为4个字节的有符号整数类型
typedef unsigned int u_32; //固定长度为4个字节的无符号整数类型 typedef unsigned int u_32; //固定长度为4个字节的无符号整数类型
typedef long _int64; //Vc中64位整数_int64在64位unix下对应long(8个字节), dnp30.cpp中引用 typedef long _int64; //Vc中64位整数_int64在64位unix下对应long(8个字节), dnp30.cpp中引用
#else #else
typedef long i_32; typedef long i_32;
typedef unsigned long u_32; typedef unsigned long u_32;
#ifdef OS_UNIX #ifdef OS_UNIX
typedef int64_t _int64; //Vc中64位整数_int64在32位unix下对应int64_t,在sys/types.h中定义 typedef int64_t _int64; //Vc中64位整数_int64在32位unix下对应int64_t,在sys/types.h中定义
#endif #endif
#endif #endif
#ifdef OS_UNIX #ifdef OS_UNIX
typedef u_32 DWORD; //DWORD为固定长度4个字节的无符号整数 typedef u_32 DWORD; //DWORD为固定长度4个字节的无符号整数
#endif #endif
/*----------------------------------- 常数定义 ----------------------------------*/ /*----------------------------------- 常数定义 ----------------------------------*/
#ifdef OS_UNIX #ifdef OS_UNIX
#define TRUE 1 #define TRUE 1
#define FALSE 0 #define FALSE 0
#define NULL 0 #define NULL 0
#define INVALID_SOCKET (SOCKET)(~0) //为编译通过而临时从Winsock.h中提取的类型定义 #define INVALID_SOCKET (SOCKET)(~0) //为编译通过而临时从Winsock.h中提取的类型定义
#define SOCKET_ERROR (-1) #define SOCKET_ERROR (-1)
#define INADDR_NONE 0xffffffff #define INADDR_NONE 0xffffffff
#endif #endif
/*------------------------------------ 宏定义 -----------------------------------*/ /*------------------------------------ 宏定义 -----------------------------------*/
#ifdef OS_UNIX #ifdef OS_UNIX
#define MAKEWORD(a, b) ((WORD)(((BYTE)(a)) | ((WORD)((BYTE)(b))) << 8)) #define MAKEWORD(a, b) ((WORD)(((BYTE)(a)) | ((WORD)((BYTE)(b))) << 8))

File diff suppressed because it is too large Load Diff

@ -3,19 +3,19 @@
* Copyright (C) 2004-2005 SCADA Control Technology Co., Ltd. * Copyright (C) 2004-2005 SCADA Control Technology Co., Ltd.
* All rights reserved. * All rights reserved.
* *
* scadaprotect.h * scadaprotect.h
* SCADA * SCADA
* *
* *
* 1.0 * 1.0
* aaawen * aaawen
* 2005/06/02 * 2005/06/02
* *
* 1.0 * 1.0
* aaawen * aaawen
* *
* *
* *
* u8 --- BYTE(usigned char) * u8 --- BYTE(usigned char)
* ch --- char * ch --- char
* w --- WORD(u_short, usigned short) * w --- WORD(u_short, usigned short)
@ -31,14 +31,14 @@
* c --- class * c --- class
* s --- struct * s --- struct
* sta --- static * sta --- static
* g --- * g ---
* Array --- * Array ---
* a --- * a ---
* m_ --- * m_ ---
* p --- * p ---
* str --- * str ---
* --- * ---
* --- * ---
**************************************************************************************/ **************************************************************************************/
// buban103.h: interface for the buban103 class. // buban103.h: interface for the buban103 class.
// //
@ -52,242 +52,242 @@
#endif #endif
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// 宏定义 // // 宏定义 //
// WEN 2005.06.02 // // WEN 2005.06.02 //
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
/*! /*!
(PROTECT->FEND) (PROTECT->FEND)
*/ */
#define pPFV_PROTECT_BYPASS 1 #define pPFV_PROTECT_BYPASS 1
/*! /*!
(FEND->PROTECT) (FEND->PROTECT)
*/ */
#define fPFV_PROTECT_BYPASS_ACK 2 #define fPFV_PROTECT_BYPASS_ACK 2
/*! /*!
(FEND->PROTECT) (FEND->PROTECT)
*/ */
#define fPFV_STATUS 3 #define fPFV_STATUS 3
/*! /*!
(FEND<->PROTECT) (FEND<->PROTECT)
*/ */
#define fPFV_NETACTIVE 0xF0 #define fPFV_NETACTIVE 0xF0
//指令包操作码 //指令包操作码
/*! /*!
*/ */
#define hREADFIX 0x01 #define hREADFIX 0x01
/*! /*!
*/ */
#define hREADFIXNO 0x07 #define hREADFIXNO 0x07
/*! /*!
*/ */
#define hREADPAI 0x09 #define hREADPAI 0x09
/*! /*!
*/ */
#define hREADPDI 0x0b #define hREADPDI 0x0b
/*! /*!
*/ */
#define hREADPWAVE 0x0d #define hREADPWAVE 0x0d
/*! /*!
*/ */
#define hQUERYFAULT 0x11 #define hQUERYFAULT 0x11
/*! /*!
*/ */
#define hQUERYSELFCHECK 0x12 #define hQUERYSELFCHECK 0x12
/*! /*!
*/ */
#define hWRITEALLFIX 0x15 #define hWRITEALLFIX 0x15
/*! /*!
*/ */
#define hWRITESPECIALFIX 0x16 #define hWRITESPECIALFIX 0x16
/*! /*!
*/ */
#define hWRITEFIXACK 0x17 #define hWRITEFIXACK 0x17
/*! /*!
*/ */
#define hWRITEFIXNAK 0x18 #define hWRITEFIXNAK 0x18
/*! /*!
*/ */
#define hWRITEFIXNO 0x19 #define hWRITEFIXNO 0x19
/*! /*!
*/ */
#define hWRITEFIXNOACK 0x1a #define hWRITEFIXNOACK 0x1a
/*! /*!
*/ */
#define hWRITEFIXNONAK 0x1b #define hWRITEFIXNONAK 0x1b
/*! /*!
*/ */
#define hRESETPROTECT 0x1c #define hRESETPROTECT 0x1c
/*! /*!
*/ */
#define hCHECKTIME 0x1d #define hCHECKTIME 0x1d
/*! /*!
广 广
*/ */
#define hBROADCASTCHECKTIME 0x1e #define hBROADCASTCHECKTIME 0x1e
/*! /*!
*/ */
#define hSTATUS 0x1f #define hSTATUS 0x1f
/*! /*!
*/ */
#define hCOMMAND 0x20 #define hCOMMAND 0x20
/*! /*!
*/ */
#define hDISTCOMMAND 0x21 #define hDISTCOMMAND 0x21
/*! /*!
*/ */
#define hCANCEL 0xFF #define hCANCEL 0xFF
//应答包操作码 //应答包操作码
/*! /*!
*/ */
#define hREADINGDATA 0x02 #define hREADINGDATA 0x02
/*! /*!
*/ */
#define hFIXDATA 0x03 #define hFIXDATA 0x03
/*! /*!
*/ */
#define hREADDATAEND 0x04 #define hREADDATAEND 0x04
/*! /*!
*/ */
#define hNORESPONSE 0x05 #define hNORESPONSE 0x05
/*! /*!
*/ */
#define hSYSTEMBUSY 0x06 #define hSYSTEMBUSY 0x06
/*! /*!
*/ */
#define hFIXNODATA 0x08 #define hFIXNODATA 0x08
/*! /*!
*/ */
#define hPAIDATA 0x0a #define hPAIDATA 0x0a
/*! /*!
*/ */
#define hPDIDATA 0x0c #define hPDIDATA 0x0c
/*! /*!
*/ */
#define hPWAVEDATASTART 0x0e #define hPWAVEDATASTART 0x0e
/*! /*!
*/ */
#define hPWAVEDATA 0x0f #define hPWAVEDATA 0x0f
/*! /*!
*/ */
#define hPWAVEDATAEND 0x10 #define hPWAVEDATAEND 0x10
/*! /*!
*/ */
#define hPEVENTDATAWITHID 0x13 #define hPEVENTDATAWITHID 0x13
/*! /*!
*/ */
#define hPEVENTDATAWITHSTRING 0x14 #define hPEVENTDATAWITHSTRING 0x14
/*! /*!
*/ */
#define hWRITEFIXACK 0x17 #define hWRITEFIXACK 0x17
/*! /*!
*/ */
#define hWRITEFIXNAK 0x18 #define hWRITEFIXNAK 0x18
/*! /*!
*/ */
#define hWRITEFIXNOACK 0x1a #define hWRITEFIXNOACK 0x1a
/*! /*!
*/ */
#define hWRITEFIXNONAK 0x1b #define hWRITEFIXNONAK 0x1b
/*! /*!
*/ */
#define hFIXDATAWITHNO 0x22 #define hFIXDATAWITHNO 0x22
/*! /*!
*/ */
#define hPAIDATAWITHNO 0x23 #define hPAIDATAWITHNO 0x23
/*! /*!
*/ */
#define hPDIDATAWITHNO 0x24 #define hPDIDATAWITHNO 0x24
// 数据项目属性 // 数据项目属性
/*! /*!
*/ */
#define ITEM_ATTR_REALVALUE 1 #define ITEM_ATTR_REALVALUE 1
/*! /*!
*/ */
#define ITEM_ATTR_DEFAULTVALUE 2 #define ITEM_ATTR_DEFAULTVALUE 2
/*! /*!
*/ */
#define ITEM_ATTR_MINMAXSTEP 3 #define ITEM_ATTR_MINMAXSTEP 3
/*! /*!
*/ */
#define ITEM_ATTR_STANDBY 4 #define ITEM_ATTR_STANDBY 4
/*! /*!
*/ */
#define ITEM_ATTR_PRECISION 5 #define ITEM_ATTR_PRECISION 5
/*! /*!
*/ */
#define ITEM_ATTR_FIGURE 6 #define ITEM_ATTR_FIGURE 6
/*! /*!
*/ */
#define ITEM_ATTR_RATE 7 #define ITEM_ATTR_RATE 7
/*! /*!
*/ */
#define ITEM_ATTR_LIST 8 #define ITEM_ATTR_LIST 8
/*! /*!
*/ */
#define ITEM_ATTR_UNIT 9 #define ITEM_ATTR_UNIT 9
/*! /*!
*/ */
#define ITEM_ATTR_DESCRIPTION 10 #define ITEM_ATTR_DESCRIPTION 10
/*! /*!
() ()
*/ */
#define OPERPROTECTTIMEOUT 15 #define OPERPROTECTTIMEOUT 15
// 是pc机系统还是嵌入式系统 // 是pc机系统还是嵌入式系统
#ifdef PC_MACHINE #ifdef PC_MACHINE
#ifdef OS_WINDOWS #ifdef OS_WINDOWS
#pragma pack (push,1) #pragma pack (push,1)
@ -298,31 +298,31 @@
typedef struct tagPROTECTCONTENTHEAD typedef struct tagPROTECTCONTENTHEAD
{ {
u_32 ummid __attribute__ ((packed));// 操作用户 u_32 ummid __attribute__ ((packed));// 操作用户
u_32 uAddr __attribute__ ((packed));// 保护地址 u_32 uAddr __attribute__ ((packed));// 保护地址
char cFixNo __attribute__ ((packed));// 定值区号 char cFixNo __attribute__ ((packed));// 定值区号
char cCPUNo __attribute__ ((packed));// CPU号 char cCPUNo __attribute__ ((packed));// CPU号
u_32 uFuncCode __attribute__ ((packed));// 操作功能码 u_32 uFuncCode __attribute__ ((packed));// 操作功能码
u_32 uReserved __attribute__ ((packed));// 保留 u_32 uReserved __attribute__ ((packed));// 保留
}PROTECTCONTENTHEAD, *pPROTECTCONTENTHEAD; }PROTECTCONTENTHEAD, *pPROTECTCONTENTHEAD;
typedef struct typedef struct
{ {
u_32 MsgType __attribute__ ((packed));// 信息类型 u_32 MsgType __attribute__ ((packed));// 信息类型
u_32 PortNumber __attribute__ ((packed));// 信息端口号 u_32 PortNumber __attribute__ ((packed));// 信息端口号
u_32 MsgLen __attribute__ ((packed));// 信息长度 u_32 MsgLen __attribute__ ((packed));// 信息长度
//u_char MsgData[1]; // 信息数据 //u_char MsgData[1]; // 信息数据
}PROTECTMSGHEAD; }PROTECTMSGHEAD;
typedef struct typedef struct
{ {
u_32 MsgType __attribute__ ((packed));// 信息类型 u_32 MsgType __attribute__ ((packed));// 信息类型
u_32 PortNumber __attribute__ ((packed));// 信息端口号 u_32 PortNumber __attribute__ ((packed));// 信息端口号
u_32 MsgLen __attribute__ ((packed));// 信息长度 u_32 MsgLen __attribute__ ((packed));// 信息长度
u_char MsgData[MAX_RTU_MSG_SIZE] __attribute__ ((packed));// 信息数据 u_char MsgData[MAX_RTU_MSG_SIZE] __attribute__ ((packed));// 信息数据
}PROTECTMSG; }PROTECTMSG;
// 是pc机系统还是嵌入式系统 // 是pc机系统还是嵌入式系统
#ifdef PC_MACHINE #ifdef PC_MACHINE
#ifdef OS_WINDOWS #ifdef OS_WINDOWS
#pragma pack (pop) #pragma pack (pop)
@ -333,25 +333,25 @@ typedef struct
typedef struct typedef struct
{ {
BOOL bPortIdle; // 端口保护操作空闲标识 BOOL bPortIdle; // 端口保护操作空闲标识
u_32 timeOut; // 保护操作超时时间 u_32 timeOut; // 保护操作超时时间
u_32 mmid; // 保护操作用户 u_32 mmid; // 保护操作用户
} PORTSTATUS, *pPORTSTATUS; } PORTSTATUS, *pPORTSTATUS;
typedef struct tagSCADAPROVDEVDEF typedef struct tagSCADAPROVDEVDEF
{ {
/*! /*!
\brief \brief
*/ */
i_32 m_iRealCommid; i_32 m_iRealCommid;
/*! /*!
\brief () \brief ()
*/ */
i_32 m_iProvAddr; i_32 m_iProvAddr;
/*! /*!
\brief SOE \brief SOE
\note \note
() ()
*/ */
DEVPROVSOE m_sProvSoe; DEVPROVSOE m_sProvSoe;
@ -365,34 +365,34 @@ typedef struct tagSCADAPROTECTPORTPARAM
{ {
/*! /*!
\var SCADAPROTECTPORTPARAM::m_achRecvBuf \var SCADAPROTECTPORTPARAM::m_achRecvBuf
\brief \brief
\note \note
MAX_RTU_MSG_SIZE+12() bytes\n MAX_RTU_MSG_SIZE+12() bytes\n
*/ */
char m_achRecvBuf[MAX_RTU_MSG_SIZE+12]; char m_achRecvBuf[MAX_RTU_MSG_SIZE+12];
/*! /*!
\var SCADAPROTECTPORTPARAM::m_iRecvLen \var SCADAPROTECTPORTPARAM::m_iRecvLen
\brief \brief
*/ */
int m_iRecvLen; int m_iRecvLen;
/*! /*!
\var SCADAPROTECTPORTPARAM::m_iRecvLen \var SCADAPROTECTPORTPARAM::m_iRecvLen
\brief \brief
*/ */
int m_iActiveTimeCnt; int m_iActiveTimeCnt;
int m_iActiveTimeConst; int m_iActiveTimeConst;
/*! /*!
\var SCADAPROTECTPORTPARAM::m_iRecvLen \var SCADAPROTECTPORTPARAM::m_iRecvLen
\brief \brief
*/ */
int m_iStatusTimeCnt; int m_iStatusTimeCnt;
int m_iStatusTimeConst; int m_iStatusTimeConst;
/*! /*!
*/ */
i_32 m_iDevNum; i_32 m_iDevNum;
@ -404,102 +404,102 @@ typedef struct tagSCADAPROTECTPORTPARAM
PORTSTATUS *m_pPrtPortStatus; PORTSTATUS *m_pPrtPortStatus;
/*! /*!
\brief \brief
*/ */
SIO_PARAM_BAOHU_DEF *m_psBaoHu; SIO_PARAM_BAOHU_DEF *m_psBaoHu;
}SCADAPROTECTPORTPARAM, *pSCADAPROTECTPORTPARAM; }SCADAPROTECTPORTPARAM, *pSCADAPROTECTPORTPARAM;
/////////////////////////以下为通用函数接口/////////////////////////// /////////////////////////以下为通用函数接口///////////////////////////
/*! /*!
\brief \brief
\param commid -- \param commid --
\note \note
0 -- MaxSerialPortNum + MaxNetPortNum -1\n 0 -- MaxSerialPortNum + MaxNetPortNum -1\n
*/ */
void ScadaProtectReadConfig(int commid); // 初始化处理 void ScadaProtectReadConfig(int commid); // 初始化处理
/*! /*!
\brief \brief
\param commid -- \param commid --
\note \note
0 -- MaxSerialPortNum + MaxNetPortNum -1\n 0 -- MaxSerialPortNum + MaxNetPortNum -1\n
\param buf -- \param buf --
\param len -- \param len --
*/ */
void ScadaProtectRecvData(int commid, u_char *buf, int len);// 规约读数据处理 void ScadaProtectRecvData(int commid, u_char *buf, int len);// 规约读数据处理
/*! /*!
\brief \brief
\param commid -- \param commid --
\note \note
0 -- MaxSerialPortNum + MaxNetPortNum -1\n 0 -- MaxSerialPortNum + MaxNetPortNum -1\n
*/ */
void ScadaProtectTimer(int commid); // 定时器处理 void ScadaProtectTimer(int commid); // 定时器处理
/*! /*!
\brief \brief
\param commid -- \param commid --
\note \note
0 -- MaxSerialPortNum + MaxNetPortNum -1\n 0 -- MaxSerialPortNum + MaxNetPortNum -1\n
\param buf -- \param buf --
\param len -- \param len --
*/ */
void ScadaProtectYkYtProcess(int commid, u_char *buf, int len); // 遥控遥调处理 void ScadaProtectYkYtProcess(int commid, u_char *buf, int len); // 遥控遥调处理
/*! /*!
\brief \brief
\param commid -- \param commid --
\note \note
0 -- MaxSerialPortNum + MaxNetPortNum -1\n 0 -- MaxSerialPortNum + MaxNetPortNum -1\n
*/ */
//void ScadaProtectSendSystemTime(int commid); // 系统对时 //void ScadaProtectSendSystemTime(int commid); // 系统对时
/*! /*!
\brief 退 \brief 退
\param commid -- \param commid --
\note \note
0 -- MaxSerialPortNum + MaxNetPortNum -1\n 0 -- MaxSerialPortNum + MaxNetPortNum -1\n
*/ */
void ScadaProtectExit(int commid); // 规约退出 void ScadaProtectExit(int commid); // 规约退出
/*! /*!
\brief \brief
\param commid -- \param commid --
\param rtumsg -- \param rtumsg --
\note \note
0 -- MaxSerialPortNum + MaxNetPortNum -1\n 0 -- MaxSerialPortNum + MaxNetPortNum -1\n
*/ */
void ScadaProtectBaoHuCmdProcess(int commid, RTUMSG *rtumsg, BOOL bUpData); void ScadaProtectBaoHuCmdProcess(int commid, RTUMSG *rtumsg, BOOL bUpData);
/*! /*!
\brief \brief
\param commid -- \param commid --
\param iProvAddr -- \param iProvAddr --
\param ppBaoHuDB -- \param ppBaoHuDB --
\retval -- \retval --
*/ */
int ScadaProtectGetBaohuDataBase(int commid, int iProvAddr, GROUPDEF **ppBaoHuDB); int ScadaProtectGetBaohuDataBase(int commid, int iProvAddr, GROUPDEF **ppBaoHuDB);
/////////////////////////通用函数接口结束/////////////////////////////// /////////////////////////通用函数接口结束///////////////////////////////
/////////////////////////以下为通用函数支持接口///////////////////////// /////////////////////////以下为通用函数支持接口/////////////////////////
void ScadaProtectProvMakeYkYtCommand(int commid, u_char *buf, int len); void ScadaProtectProvMakeYkYtCommand(int commid, u_char *buf, int len);
/////////////////////////通用函数支持接口结束/////////////////////////// /////////////////////////通用函数支持接口结束///////////////////////////
///////////////////////////以下为配置函数接口/////////////////////////// ///////////////////////////以下为配置函数接口///////////////////////////
BOOL InitScadaInfoFromTempletFile(int commid, SCADAPROTECTPORTPARAM *psPortParam,\ BOOL InitScadaInfoFromTempletFile(int commid, SCADAPROTECTPORTPARAM *psPortParam,\
char *ptrTemplate, BOOL bMaster); char *ptrTemplate, BOOL bMaster);
BOOL GetProvDevNumFromTemplateFileScada(int commid, HDSFILE hFile, SCADAPROTECTPORTPARAM *psPortParam); BOOL GetProvDevNumFromTemplateFileScada(int commid, HDSFILE hFile, SCADAPROTECTPORTPARAM *psPortParam);
BOOL GetProvDevParamFromTemplateFileScada(int commid, HDSFILE hFile, SCADAPROTECTPORTPARAM *psPortParam); BOOL GetProvDevParamFromTemplateFileScada(int commid, HDSFILE hFile, SCADAPROTECTPORTPARAM *psPortParam);
int FindProtectDevFromPntNoScada(SCADAPROTECTPORTPARAM *psPortParam, int iPntNo, int itype); int FindProtectDevFromPntNoScada(SCADAPROTECTPORTPARAM *psPortParam, int iPntNo, int itype);
/////////////////////////////配置函数接口结束/////////////////////////// /////////////////////////////配置函数接口结束///////////////////////////
///////////////////////以下为规约处理函数接口/////////////////////////// ///////////////////////以下为规约处理函数接口///////////////////////////
void ReduceTimeOut(SCADAPROTECTPORTPARAM *psPortParam); void ReduceTimeOut(SCADAPROTECTPORTPARAM *psPortParam);
BOOL IsProtectPortIdle(int commid, SCADAPROTECTPORTPARAM *psPortParam); BOOL IsProtectPortIdle(int commid, SCADAPROTECTPORTPARAM *psPortParam);
BOOL GetProtectPortIdle(int commid, SCADAPROTECTPORTPARAM *psPortParam, PORTSTATUS *pStatus); BOOL GetProtectPortIdle(int commid, SCADAPROTECTPORTPARAM *psPortParam, PORTSTATUS *pStatus);
BOOL SetProtectPortIdle(int commid, SCADAPROTECTPORTPARAM *psPortParam, PORTSTATUS *pStatus); BOOL SetProtectPortIdle(int commid, SCADAPROTECTPORTPARAM *psPortParam, PORTSTATUS *pStatus);
BOOL SetProtectPortIdleEx(int commid, int iBaoHuCommid, PORTSTATUS *pStatus); BOOL SetProtectPortIdleEx(int commid, int iBaoHuCommid, PORTSTATUS *pStatus);
void SendResponsetoMMI(int commid, int mmid, u_32 ResponseType, PROTECTMSG *pmsg); void SendResponsetoMMI(int commid, int mmid, u_32 ResponseType, PROTECTMSG *pmsg);
//将客户机报文所有的数据从网络字节循序转换成主机字节顺序函数 //将客户机报文所有的数据从网络字节循序转换成主机字节顺序函数
void AllNetToHostByteSequence(PROTECTMSG *userdata); void AllNetToHostByteSequence(PROTECTMSG *userdata);
//将客户机报文所有的数据从主机字节顺序转换成网络字节顺序函数 //将客户机报文所有的数据从主机字节顺序转换成网络字节顺序函数
void AllHostToNetByteSequence(PROTECTMSG *userdata); void AllHostToNetByteSequence(PROTECTMSG *userdata);
BOOL ScadaProtectConvertToScadaFrameAndSend(int commid); BOOL ScadaProtectConvertToScadaFrameAndSend(int commid);
BOOL ScadaProtectConvertTo103AndSend(int commid, PROTECTMSG *pmsg); BOOL ScadaProtectConvertTo103AndSend(int commid, PROTECTMSG *pmsg);
//数据处理函数总入口 //数据处理函数总入口
void ScadaProtectProcessData(int commid, SCADAPROTECTPORTPARAM *psPortParam, BOOL bProcess); void ScadaProtectProcessData(int commid, SCADAPROTECTPORTPARAM *psPortParam, BOOL bProcess);
void ScadaProtectByPassData(int commid, SCADAPROTECTPORTPARAM *psPortParam, PROTECTMSG *pmsg); void ScadaProtectByPassData(int commid, SCADAPROTECTPORTPARAM *psPortParam, PROTECTMSG *pmsg);
@ -508,9 +508,9 @@ void MakeInteractionCmd(int commid, int sourcommid, u_32 ResponseFunc, PROTECTCO
void MakeNetActivePacket(int commid); void MakeNetActivePacket(int commid);
void MakeStatusPacket(int commid); void MakeStatusPacket(int commid);
BOOL MakeSoeDataPacket(int commid); BOOL MakeSoeDataPacket(int commid);
/////////////////////////规约处理函数接口结束/////////////////////////// /////////////////////////规约处理函数接口结束///////////////////////////
/////////////////////////以下为调试函数接口///////////////////////////// /////////////////////////以下为调试函数接口/////////////////////////////
void DispPrtPortStatus(int commid, SCADAPROTECTPORTPARAM *psPortParam); void DispPrtPortStatus(int commid, SCADAPROTECTPORTPARAM *psPortParam);
///////////////////////////调试函数接口结束///////////////////////////// ///////////////////////////调试函数接口结束/////////////////////////////
#endif // !defined(_SCADABAOHU_H_200506020948__INCLUDED_) #endif // !defined(_SCADABAOHU_H_200506020948__INCLUDED_)

File diff suppressed because it is too large Load Diff

@ -21,19 +21,19 @@
* no message * no message
* *
* Revision 1.5 2006/05/26 10:38:03 administrator * Revision 1.5 2006/05/26 10:38:03 administrator
* 32 * 32
* *
* Revision 1.4 2006/04/22 07:49:26 administrator * Revision 1.4 2006/04/22 07:49:26 administrator
* *
* *
* Revision 1.2 2006/01/17 06:14:53 Administrator * Revision 1.2 2006/01/17 06:14:53 Administrator
* *
* *
* Revision 1.1 2005/10/20 06:20:34 Administrator * Revision 1.1 2005/10/20 06:20:34 Administrator
* *
* *
* Revision 1.1 2005/10/12 06:03:46 Administrator * Revision 1.1 2005/10/12 06:03:46 Administrator
* *
* *
* *
**************************************************************************************/ **************************************************************************************/
@ -47,7 +47,7 @@
#include "common.h" #include "common.h"
// 另外一个前置机装置是pc还是ds-3116 // 另外一个前置机装置是pc还是ds-3116
#define FEND_OTHERDEV_DS3116 1 #define FEND_OTHERDEV_DS3116 1
#define HOST_CLOSE_NET 1 #define HOST_CLOSE_NET 1
@ -57,62 +57,62 @@
#define CHECK_VERSION_FLAG 1 #define CHECK_VERSION_FLAG 1
// 运行方式是主备方式 // 运行方式是主备方式
#define RUN_MODE_STANDBY 0 #define RUN_MODE_STANDBY 0
// 并列方式,同时运行 // 并列方式,同时运行
#define RUN_MODE_ALLHOT 1 #define RUN_MODE_ALLHOT 1
//**************** 端口数据类型 ************************ //**************** 端口数据类型 ************************
#define iCOMM_DATA 0x10 // RTU数据包类型 #define iCOMM_DATA 0x10 // RTU数据包类型
//************ 前置机 --> 主机 数据类型 **************** //************ 前置机 --> 主机 数据类型 ****************
#define iREQUESTHOSTSTATUS 0x14 // 请求主机状态 #define iREQUESTHOSTSTATUS 0x14 // 请求主机状态
#define iTIMEINFORM 0x2c // 前置机对时 #define iTIMEINFORM 0x2c // 前置机对时
#define iAIDATA 0x31 // 变化遥测 #define iAIDATA 0x31 // 变化遥测
#define iDIDATA 0x32 // 变化遥信 #define iDIDATA 0x32 // 变化遥信
#define iPIDATA 0x33 // 变化电度 #define iPIDATA 0x33 // 变化电度
#define iSOEDATA 0x34 // SOE 数据 #define iSOEDATA 0x34 // SOE 数据
#define iACKDATA 0x35 // 遥控遥调返校 #define iACKDATA 0x35 // 遥控遥调返校
#define WUXI_ZHUANFA_AI_TO_HOST 0x36 #define WUXI_ZHUANFA_AI_TO_HOST 0x36
#define WUXI_ZHUANFA_DI_TO_HOST iDIALLDATA #define WUXI_ZHUANFA_DI_TO_HOST iDIALLDATA
#define WUXI_ZHUANFA_PI_TO_HOST 0x37 #define WUXI_ZHUANFA_PI_TO_HOST 0x37
#define iODDATA 0x38 // 离线遥信数据 #define iODDATA 0x38 // 离线遥信数据
#define iODALLDATA 0x39 // 离线遥信全数据 #define iODALLDATA 0x39 // 离线遥信全数据
#define iWUFANGYKYTREQ 0x3d // 五防遥控遥调请求 #define iWUFANGYKYTREQ 0x3d // 五防遥控遥调请求
#define iAIALLDATA 0x40 // 遥测全数据 #define iAIALLDATA 0x40 // 遥测全数据
#define iDIALLDATA 0x41 // 遥信全数据 #define iDIALLDATA 0x41 // 遥信全数据
#define iPIALLDATA 0x42 // 电度全数据 #define iPIALLDATA 0x42 // 电度全数据
// wen 2006.05.20 32bit传送模拟量数据 // wen 2006.05.20 32bit传送模拟量数据
#define PGC3_AI32DATA 0x45 // 变化32位遥测数据 #define PGC3_AI32DATA 0x45 // 变化32位遥测数据
#define PGC3_AI32ALLDATA 0x46 // 遥测32位全数据 #define PGC3_AI32ALLDATA 0x46 // 遥测32位全数据
#define iBYPASSDATA 0x50 // 直通数据 #define iBYPASSDATA 0x50 // 直通数据
#define iODPOINT 0x81 // 读离线量点数据 #define iODPOINT 0x81 // 读离线量点数据
#define iANPOINT 0x82 // 读模拟量点数据 #define iANPOINT 0x82 // 读模拟量点数据
#define iDIPOINT 0x83 // 读数字量点数据 #define iDIPOINT 0x83 // 读数字量点数据
#define iLINESTATUS 0x84 // 端口线路状态 #define iLINESTATUS 0x84 // 端口线路状态
#define iNETTESTMSG 0xf0 // 网络状态包 #define iNETTESTMSG 0xf0 // 网络状态包
#define iNETNAMEPLATE 0xef // 网络标示包 #define iNETNAMEPLATE 0xef // 网络标示包
//************ 主机 --> 前置机 数据类型 **************** //************ 主机 --> 前置机 数据类型 ****************
#define hHOSTSTATUS 0x15 // 主机状态 #define hHOSTSTATUS 0x15 // 主机状态
#define NET_PROFILE_UPDATE 0x1B // 主机下发更改数据库指令 #define NET_PROFILE_UPDATE 0x1B // 主机下发更改数据库指令
#define hTIMEINFORM 0x2c // 主机对时 #define hTIMEINFORM 0x2c // 主机对时
#define hYKYTCMD 0x35 // 遥控遥调命令 #define hYKYTCMD 0x35 // 遥控遥调命令
#define hBYPASSCMD 0x50 // 直通数据 #define hBYPASSCMD 0x50 // 直通数据
#define hMAPANDATA 0x82 // 模拟量点数据 #define hMAPANDATA 0x82 // 模拟量点数据
#define hMAPDIDATA 0x83 // 数字量点数据 #define hMAPDIDATA 0x83 // 数字量点数据
#define hDATA_OUTPUT_CTRL 0x85 // 数据输出控制 #define hDATA_OUTPUT_CTRL 0x85 // 数据输出控制
#define hRELOADDATABASE 0x86 // 重新装入数据库 #define hRELOADDATABASE 0x86 // 重新装入数据库
#define hNETTESTMSG 0xf0 // 网络状态包 #define hNETTESTMSG 0xf0 // 网络状态包
#define hMAPALLOP 0xf4 // 模拟盘全盘操作 #define hMAPALLOP 0xf4 // 模拟盘全盘操作
//*********************数据缓冲区************************ //*********************数据缓冲区************************
#define AIMSGNO 0 #define AIMSGNO 0
#define DIMSGNO 1 #define DIMSGNO 1
#define SOEMSGNO 2 #define SOEMSGNO 2
@ -131,10 +131,10 @@ typedef struct tagTCP_SEND_DATA_BUF
typedef struct tagTCP_RCV_DATA_BUF typedef struct tagTCP_RCV_DATA_BUF
{ {
int MsgCnt __attribute__ ((packed));// 信息内容计数 int MsgCnt __attribute__ ((packed));// 信息内容计数
int Front __attribute__ ((packed));// 信息取数指针 int Front __attribute__ ((packed));// 信息取数指针
int Rear __attribute__ ((packed));// 信息存入指针 int Rear __attribute__ ((packed));// 信息存入指针
BYTE MsgData[MAX_NET_BUF] __attribute__ ((packed));// 信息数据 BYTE MsgData[MAX_NET_BUF] __attribute__ ((packed));// 信息数据
} TCP_RCV_DATA_BUF; } TCP_RCV_DATA_BUF;
typedef struct tagFEND_DEF typedef struct tagFEND_DEF
@ -156,36 +156,36 @@ typedef struct tagFEND_DEF
int SendTxdDataFlag[MAX_FEND] __attribute__ ((packed)); int SendTxdDataFlag[MAX_FEND] __attribute__ ((packed));
// wen 2006.01.14 增加装置的起始厂站号的偏移 // wen 2006.01.14 增加装置的起始厂站号的偏移
int iPortOffset __attribute__ ((packed)); int iPortOffset __attribute__ ((packed));
int iRunMode __attribute__ ((packed)); int iRunMode __attribute__ ((packed));
// wen 2006.04.22 主备切换时,判断的端口通讯状态屏蔽字(按位屏蔽) // wen 2006.04.22 主备切换时,判断的端口通讯状态屏蔽字(按位屏蔽)
int iPortMask __attribute__ ((packed)); int iPortMask __attribute__ ((packed));
// wen 2006.05.20 32bit传送模拟量数据 // wen 2006.05.20 32bit传送模拟量数据
int iSendAiof32Bit __attribute__ ((packed)); int iSendAiof32Bit __attribute__ ((packed));
} FEND_DEF; } FEND_DEF;
typedef struct tagTCP_LINK_DEF typedef struct tagTCP_LINK_DEF
{ {
u_char InitFlag __attribute__ ((packed));// 初始化标志 u_char InitFlag __attribute__ ((packed));// 初始化标志
u_char InitOk __attribute__ ((packed));// 初始化成功标志 u_char InitOk __attribute__ ((packed));// 初始化成功标志
long InitLinkCnt __attribute__ ((packed));// 初始化计数 long InitLinkCnt __attribute__ ((packed));// 初始化计数
char ExistFlag __attribute__ ((packed));// 存在标志 char ExistFlag __attribute__ ((packed));// 存在标志
u_char CommFlag __attribute__ ((packed));// 通讯标志 u_char CommFlag __attribute__ ((packed));// 通讯标志
u_char Status __attribute__ ((packed));// 工作状态 u_char Status __attribute__ ((packed));// 工作状态
long StatusCnt __attribute__ ((packed));// 状态计数 long StatusCnt __attribute__ ((packed));// 状态计数
SOCKET SocketId __attribute__ ((packed));// 连接号 SOCKET SocketId __attribute__ ((packed));// 连接号
u_char LinkType __attribute__ ((packed));// 连接类型 u_char LinkType __attribute__ ((packed));// 连接类型
char CurLinkIdx __attribute__ ((packed)); char CurLinkIdx __attribute__ ((packed));
u_char TcpIpAddr[MAX_ADDR][TCPIP_ADDR_LEN] __attribute__ ((packed));// Tcp/Ip 地址 u_char TcpIpAddr[MAX_ADDR][TCPIP_ADDR_LEN] __attribute__ ((packed));// Tcp/Ip 地址
u_char VersionFalgByte __attribute__ ((packed));// 服务器版本号标志 u_char VersionFalgByte __attribute__ ((packed));// 服务器版本号标志
int RevHostStatusMsg __attribute__ ((packed));// 接收主机广播信息 int RevHostStatusMsg __attribute__ ((packed));// 接收主机广播信息
char NetNameplateFalg __attribute__ ((packed)); char NetNameplateFalg __attribute__ ((packed));
@ -193,37 +193,37 @@ typedef struct tagTCP_LINK_DEF
} TCP_LINK_DEF; } TCP_LINK_DEF;
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// 兼容老系统的RTUMSG结构 // 兼容老系统的RTUMSG结构
typedef struct tagORTUMSGHEAD typedef struct tagORTUMSGHEAD
{ {
u_char MsgType __attribute__ ((packed));// 信息类型 u_char MsgType __attribute__ ((packed));// 信息类型
u_char PortNumber __attribute__ ((packed));// 信息端口号 u_char PortNumber __attribute__ ((packed));// 信息端口号
short MsgLen __attribute__ ((packed));// 信息长度 short MsgLen __attribute__ ((packed));// 信息长度
} ORTUMSGHEAD; } ORTUMSGHEAD;
typedef struct tagORTUMSG typedef struct tagORTUMSG
{ {
u_char MsgType __attribute__ ((packed));// 信息类型 u_char MsgType __attribute__ ((packed));// 信息类型
u_char PortNumber __attribute__ ((packed));// 信息端口号 u_char PortNumber __attribute__ ((packed));// 信息端口号
short MsgLen __attribute__ ((packed));// 信息长度 short MsgLen __attribute__ ((packed));// 信息长度
u_char MsgData[MAX_RTU_MSG_SIZE] __attribute__ ((packed));// 信息数据 u_char MsgData[MAX_RTU_MSG_SIZE] __attribute__ ((packed));// 信息数据
} ORTUMSG; } ORTUMSG;
typedef struct tagHOSTMSGHEAD typedef struct tagHOSTMSGHEAD
{ {
WORD MsgType __attribute__ ((packed));// 信息类型 WORD MsgType __attribute__ ((packed));// 信息类型
WORD PortNumber __attribute__ ((packed));// 信息端口号 WORD PortNumber __attribute__ ((packed));// 信息端口号
WORD MsgLen __attribute__ ((packed));// 信息长度 WORD MsgLen __attribute__ ((packed));// 信息长度
WORD EMsgLen __attribute__ ((packed));// 扩展信息长度 WORD EMsgLen __attribute__ ((packed));// 扩展信息长度
} HOSTMSGHEAD; } HOSTMSGHEAD;
typedef struct tagHOSTMSG typedef struct tagHOSTMSG
{ {
WORD MsgType __attribute__ ((packed));// 信息类型 WORD MsgType __attribute__ ((packed));// 信息类型
WORD PortNumber __attribute__ ((packed));// 信息端口号 WORD PortNumber __attribute__ ((packed));// 信息端口号
WORD MsgLen __attribute__ ((packed));// 信息长度 WORD MsgLen __attribute__ ((packed));// 信息长度
WORD EMsgLen __attribute__ ((packed));// 扩展信息长度 WORD EMsgLen __attribute__ ((packed));// 扩展信息长度
u_char MsgData[MAX_RTU_MSG_SIZE] __attribute__ ((packed));// 信息数据 u_char MsgData[MAX_RTU_MSG_SIZE] __attribute__ ((packed));// 信息数据
} HOSTMSG; } HOSTMSG;
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
BOOL GetConfigName(char *szFileName, int iFileNameLen, int IsPortConfig); BOOL GetConfigName(char *szFileName, int iFileNameLen, int IsPortConfig);
@ -253,7 +253,7 @@ void SendHostSendBufToHost(void);
void ClearSendBuffer(int hostid); void ClearSendBuffer(int hostid);
void ClearRecvBuffer(int hostid); void ClearRecvBuffer(int hostid);
// 服务器数据处理及发送 // 服务器数据处理及发送
void HostDataProceWithSignalYkYt(HOSTMSG *hmsg); void HostDataProceWithSignalYkYt(HOSTMSG *hmsg);
void HostDataProce(HOSTMSG *hostmsg); void HostDataProce(HOSTMSG *hostmsg);
void SendRtuChangeDataToHost(void); void SendRtuChangeDataToHost(void);
@ -267,30 +267,30 @@ void SelectHostSocketEvent(void);
void SelectHostSocketEventEx(void); void SelectHostSocketEventEx(void);
void TcpHostTimer(void); void TcpHostTimer(void);
// 服务器模拟盘数据处理 // 服务器模拟盘数据处理
void MapAnPointToHost(int iMapOutPort, int iMapSavePort); void MapAnPointToHost(int iMapOutPort, int iMapSavePort);
void MapDiPointToHost(int iMapOutPort, int iMapSavePort); void MapDiPointToHost(int iMapOutPort, int iMapSavePort);
void FormHostMapDataProce(int iMapOutPort, int iMapSavePort, HOSTMSG *msg); void FormHostMapDataProce(int iMapOutPort, int iMapSavePort, HOSTMSG *msg);
// 获取前置机的下发标识 // 获取前置机的下发标识
int GetFendTxdFlag(void); int GetFendTxdFlag(void);
// 判断网络地址是否是前置机地址 // 判断网络地址是否是前置机地址
int CheckIsFendIpAddr(u_long addr); int CheckIsFendIpAddr(u_long addr);
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// 前置机功能函数 // 前置机功能函数
void WriteChangeData(int commidex, int point, void *pntmsg, BYTE type); void WriteChangeData(int commidex, int point, void *pntmsg, BYTE type);
BOOL IsSendDatatoPort(int port); BOOL IsSendDatatoPort(int port);
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// 获取全局变量 // 获取全局变量
TCP_LINK_DEF *GetHostLinkPtr(); TCP_LINK_DEF *GetHostLinkPtr();
FEND_DEF *GetFendMsgPtr(); FEND_DEF *GetFendMsgPtr();
HOSTMSG *GetRtuChangeMsgPtr(); HOSTMSG *GetRtuChangeMsgPtr();
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// 增加字节顺序转换函数 // 增加字节顺序转换函数
BOOL AllDataHostToRtuByteSequence(HOSTMSG *hmsg, ORTUMSG *pSendMsg); BOOL AllDataHostToRtuByteSequence(HOSTMSG *hmsg, ORTUMSG *pSendMsg);
BOOL AllDataRtuToHostByteSequence(HOSTMSG *hmsg); BOOL AllDataRtuToHostByteSequence(HOSTMSG *hmsg);
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

@ -2,14 +2,14 @@
* *
* Copyright (C) 1999-2000 SCADA Technology Control Co., Ltd. All rights reserved. * Copyright (C) 1999-2000 SCADA Technology Control Co., Ltd. All rights reserved.
* *
* : * :
* *
* : 2001/08/07 * : 2001/08/07
* *
* : * :
* . * .
* 1: () * 1: ()
* 2: * 2:
* *
*************************************************************************************/ *************************************************************************************/
@ -19,21 +19,21 @@
* \if developer_doc * \if developer_doc
* \file * \file
* *
* \brief * \brief
* *
* id: $Id: typedef.h,v 1.2 2006/08/04 03:37:33 zhuzhenhua Exp $ * id: $Id: typedef.h,v 1.2 2006/08/04 03:37:33 zhuzhenhua Exp $
* *
* \author prcharold@sina.com.cn develop1@szscada.com * \author prcharold@sina.com.cn develop1@szscada.com
* \endif * \endif
*/ */
#include <sys/types.h> #include <sys/types.h>
/*! /*!
* , , * , ,
* 便, PGC * 便, PGC
* *
* //(SIZE_OF_CHAR = sizeof(char)) * //(SIZE_OF_CHAR = sizeof(char))
*/ */
#define SIZE_OF_CHAR 1 #define SIZE_OF_CHAR 1
@ -56,7 +56,7 @@ typedef unsigned char BYTE;
#define SIZE_OF_SHORT 2 #define SIZE_OF_SHORT 2
/*! /*!
* //(SIZE_OF_SHORT = sizeof(short)) * //(SIZE_OF_SHORT = sizeof(short))
*/ */
#if SIZE_OF_SHORT == 2 #if SIZE_OF_SHORT == 2
typedef short pgc16; typedef short pgc16;
@ -75,7 +75,7 @@ typedef unsigned short WORD;
#define SIZE_OF_LONG 4 #define SIZE_OF_LONG 4
#define SIZE_OF_INT 4 #define SIZE_OF_INT 4
/*! /*!
* (SIZE_OF_LONG = sizeof(long)) * (SIZE_OF_LONG = sizeof(long))
*/ */
#if SIZE_OF_LONG == 4 && SIZE_OF_INT == 4 #if SIZE_OF_LONG == 4 && SIZE_OF_INT == 4
typedef int pgc32; typedef int pgc32;
@ -114,7 +114,7 @@ typedef unsigned int DWORD;
#define SIZE_OF_LONG 8 #define SIZE_OF_LONG 8
/*! /*!
* 8 (SIZE_OF_LONG == sizeof(long)) * 8 (SIZE_OF_LONG == sizeof(long))
*/ */
#if SIZE_OF_LONG == 8 #if SIZE_OF_LONG == 8
typedef long pgc64; typedef long pgc64;
@ -147,7 +147,7 @@ typedef u_int64_t DDWORD;
#define SIZE_OF_PTR 4 #define SIZE_OF_PTR 4
/*! /*!
* (SIZE_OF_PTR == sizeof(void *)) * (SIZE_OF_PTR == sizeof(void *))
*/ */
#if SIZE_OF_PTR == 4 #if SIZE_OF_PTR == 4
typedef pgc32 PGCPTR; typedef pgc32 PGCPTR;
@ -165,7 +165,7 @@ typedef pgcu64 UPTR;
/*! /*!
* PGCBOOL -- SCADA * PGCBOOL -- SCADA
*/ */
//#ifndef __PGCBOOL_DEF__ //#ifndef __PGCBOOL_DEF__
//#define __PGCBOOL_DEF__ //#define __PGCBOOL_DEF__
@ -181,64 +181,64 @@ typedef pgcu8 PGCBOOL;
//#endif // OS_WINDOWS //#endif // OS_WINDOWS
/*! /*!
* ipc. * ipc.
* *
* , id, , id, , id * , id, , id, , id
* *
*/ */
typedef key_t shmkey_t, SHMKEY_t; // 共享内存键值 typedef key_t shmkey_t, SHMKEY_t; // 共享内存键值
typedef int shmid_t, SHMID_t; // 共享内存id typedef int shmid_t, SHMID_t; // 共享内存id
typedef key_t semkey_t, SEMKEY_t; // 信号量键值 typedef key_t semkey_t, SEMKEY_t; // 信号量键值
typedef int semid_t, SEMID_t; // 信号量id typedef int semid_t, SEMID_t; // 信号量id
typedef key_t msgkey_t, MSGKEY_t; // 消息队列键值 typedef key_t msgkey_t, MSGKEY_t; // 消息队列键值
typedef int msgid_t, MSGID_t; // 消息队列id typedef int msgid_t, MSGID_t; // 消息队列id
/*! /*!
* (-1) * (-1)
*/ */
#define SHM_ADDR_INVALID ((void *)(-1)) #define SHM_ADDR_INVALID ((void *)(-1))
/*! /*!
* windowsBOOL * windowsBOOL
*/ */
typedef int BOOL; typedef int BOOL;
/*! CAUTIOUS /*! CAUTIOUS
* , , , * , , ,
* *
* , * ,
*/ */
typedef int32 stn_no_t; typedef int32 stn_no_t;
typedef int32 pnt_no_t; typedef int32 pnt_no_t;
/*! /*!
* *
*/ */
typedef i_8 sampling_type_t; typedef i_8 sampling_type_t;
/*! /*!
* TRU64, pthread_t8, linux(intel), pthread_t * TRU64, pthread_t8, linux(intel), pthread_t
* 4, , thd_id_t8, , 64 * 4, , thd_id_t8, , 64
* , 使 * , 使
* *
* 线(id) * 线(id)
*/ */
#if defined(OS_LINUX) // unix平台(肯定使用posix线程库) #if defined(OS_LINUX) // unix平台(肯定使用posix线程库)
#if SIZE_OF_PTHREAD_T == 8 #if SIZE_OF_PTHREAD_T == 8
typedef pthread_t thd_id_t; typedef pthread_t thd_id_t;
#elif SIZE_OF_PTHREAD_T == 4 #elif SIZE_OF_PTHREAD_T == 4
typedef struct typedef struct
{ {
//! 低32位上定义thd_id //! 低32位上定义thd_id
pthread_t thd_id; pthread_t thd_id;
//! 高32位保留 //! 高32位保留
i_32 reserved; i_32 reserved;
} thd_id_t; } thd_id_t;
@ -249,10 +249,10 @@ typedef i_8 sampling_type_t;
#elif SIZE_OF_PTHREAD_T == 4 #elif SIZE_OF_PTHREAD_T == 4
typedef struct typedef struct
{ {
//! 低32位上定义thd_id //! 低32位上定义thd_id
u_32 thd_id; u_32 thd_id;
//! 高32位保留 //! 高32位保留
i_32 reserved; i_32 reserved;
} thd_id_t; } thd_id_t;
@ -260,9 +260,9 @@ typedef i_8 sampling_type_t;
#endif #endif
/*! /*!
* 便. * 便.
* *
* *
*/ */
typedef int socket_t, SOCKET_t; typedef int socket_t, SOCKET_t;
@ -275,7 +275,7 @@ typedef int socket_t, SOCKET_t;
#endif //end of defined(__unix) #endif //end of defined(__unix)
/*! /*!
* ip * ip
*/ */
//typedef u_32 ip_addr_t; //typedef u_32 ip_addr_t;
@ -297,13 +297,13 @@ typedef int socket_t, SOCKET_t;
* no message * no message
* *
* Revision 1.10 2003/08/01 06:36:19 scada * Revision 1.10 2003/08/01 06:36:19 scada
* Win32__int6464bit * Win32__int6464bit
* *
* Revision 1.9 2003/07/01 01:31:01 scada * Revision 1.9 2003/07/01 01:31:01 scada
* no message * no message
* *
* Revision 1.8 2003/06/05 03:56:15 jehu * Revision 1.8 2003/06/05 03:56:15 jehu
* doxgen * doxgen
* *
* Revision 1.7 2003/01/10 10:38:40 scada * Revision 1.7 2003/01/10 10:38:40 scada
* no message * no message
@ -321,7 +321,7 @@ typedef int socket_t, SOCKET_t;
* revised errors and warning under solaris/CC environment * revised errors and warning under solaris/CC environment
* *
* Revision 1.2 2002/08/26 02:07:32 harold * Revision 1.2 2002/08/26 02:07:32 harold
* stn_no_t, pnt_no_t, sampling_type_t, --> * stn_no_t, pnt_no_t, sampling_type_t, -->
* *
* Revision 1.1.1.1 2002/08/21 07:16:36 harold * Revision 1.1.1.1 2002/08/21 07:16:36 harold
* temporarily import * temporarily import
@ -357,15 +357,15 @@ typedef int socket_t, SOCKET_t;
* no message * no message
* *
* Revision 1.2 2002/01/15 08:44:34 harold * Revision 1.2 2002/01/15 08:44:34 harold
* 线idthd_id_t * 线idthd_id_t
* *
* Revision 1.1.1.1 2001/12/24 09:33:23 harold * Revision 1.1.1.1 2001/12/24 09:33:23 harold
* no message * no message
* *
* Revision 1.2 2001/12/24 06:39:57 harold * Revision 1.2 2001/12/24 06:39:57 harold
* , CPU, , * , CPU, ,
* , , : * , , :
* HAVE__FUNCTION__, __OS__, __PLATFORM__,__TIMEZONE__. * HAVE__FUNCTION__, __OS__, __PLATFORM__,__TIMEZONE__.
* *
* *
* *

@ -65,19 +65,19 @@ void GetHostIpAddr(void)
HostIpAddr.AllIpAddr[i] = ntohl(inaddr.S_un.S_addr); HostIpAddr.AllIpAddr[i] = ntohl(inaddr.S_un.S_addr);
if(IN_CLASSA(HostIpAddr.AllIpAddr[i])) /*A类地址*/ if(IN_CLASSA(HostIpAddr.AllIpAddr[i])) /*A类地址*/
{ {
HostIpAddr.NetMaskIpAddr[i] = IN_CLASSA_NET; HostIpAddr.NetMaskIpAddr[i] = IN_CLASSA_NET;
HostIpAddr.MainIpAddr[i] = (HostIpAddr.AllIpAddr[i] & IN_CLASSA_NET); HostIpAddr.MainIpAddr[i] = (HostIpAddr.AllIpAddr[i] & IN_CLASSA_NET);
HostIpAddr.BroadCastIpAddr[i] = (HostIpAddr.AllIpAddr[i] & IN_CLASSA_NET) | IN_CLASSA_HOST; HostIpAddr.BroadCastIpAddr[i] = (HostIpAddr.AllIpAddr[i] & IN_CLASSA_NET) | IN_CLASSA_HOST;
} }
else if(IN_CLASSB(HostIpAddr.AllIpAddr[i])) /*B类地址*/ else if(IN_CLASSB(HostIpAddr.AllIpAddr[i])) /*B类地址*/
{ {
HostIpAddr.NetMaskIpAddr[i] = IN_CLASSB_NET; HostIpAddr.NetMaskIpAddr[i] = IN_CLASSB_NET;
HostIpAddr.MainIpAddr[i] = (HostIpAddr.AllIpAddr[i] & IN_CLASSB_NET); HostIpAddr.MainIpAddr[i] = (HostIpAddr.AllIpAddr[i] & IN_CLASSB_NET);
HostIpAddr.BroadCastIpAddr[i] = (HostIpAddr.AllIpAddr[i] & IN_CLASSB_NET) | IN_CLASSB_HOST; HostIpAddr.BroadCastIpAddr[i] = (HostIpAddr.AllIpAddr[i] & IN_CLASSB_NET) | IN_CLASSB_HOST;
} }
else if(IN_CLASSC(HostIpAddr.AllIpAddr[i])) /*C类地址*/ else if(IN_CLASSC(HostIpAddr.AllIpAddr[i])) /*C类地址*/
{ {
HostIpAddr.NetMaskIpAddr[i] = IN_CLASSC_NET; HostIpAddr.NetMaskIpAddr[i] = IN_CLASSC_NET;
HostIpAddr.MainIpAddr[i] = (HostIpAddr.AllIpAddr[i] & IN_CLASSC_NET); HostIpAddr.MainIpAddr[i] = (HostIpAddr.AllIpAddr[i] & IN_CLASSC_NET);
@ -86,7 +86,7 @@ void GetHostIpAddr(void)
} }
} }
//创建用于系统配置的UDP socket //创建用于系统配置的UDP socket
void CreatUdpSetSock(void) void CreatUdpSetSock(void)
{ {
int tmp; int tmp;
@ -119,24 +119,24 @@ void CreatUdpSetSock(void)
return; return;
} }
// wen 2005.12.01 在这里初始化数据 // wen 2005.12.01 在这里初始化数据
InitGlobalMember(); InitGlobalMember();
//设置socket输入输出绶冲 //设置socket输入输出绶冲
tmp = MAX_NET_BUF_SIZE; tmp = MAX_NET_BUF_SIZE;
setsockopt(UdpParam.Socket, SOL_SOCKET, SO_RCVBUF, (char*)&tmp, sizeof(tmp)); setsockopt(UdpParam.Socket, SOL_SOCKET, SO_RCVBUF, (char*)&tmp, sizeof(tmp));
tmp = MAX_NET_BUF_SIZE; tmp = MAX_NET_BUF_SIZE;
setsockopt(UdpParam.Socket, SOL_SOCKET, SO_SNDBUF, (char*)&tmp, sizeof(tmp)); setsockopt(UdpParam.Socket, SOL_SOCKET, SO_SNDBUF, (char*)&tmp, sizeof(tmp));
tmp = 1; tmp = 1;
setsockopt(UdpParam.Socket, SOL_SOCKET, SO_BROADCAST, (char*)&tmp, sizeof(tmp)); // 广播 setsockopt(UdpParam.Socket, SOL_SOCKET, SO_BROADCAST, (char*)&tmp, sizeof(tmp)); // 广播
//让配置socket 能收不同网段的配置命令 //让配置socket 能收不同网段的配置命令
memset(&UdpParam.Addr, 0, sizeof(UdpParam.Addr)); memset(&UdpParam.Addr, 0, sizeof(UdpParam.Addr));
UdpParam.Addr.sin_family = AF_INET; UdpParam.Addr.sin_family = AF_INET;
UdpParam.Addr.sin_port = htons(UdpParam.PortNumber); UdpParam.Addr.sin_port = htons(UdpParam.PortNumber);
// wen 2005.03.08 修改ip为指定的地址 // wen 2005.03.08 修改ip为指定的地址
UdpParam.Addr.sin_addr.s_addr = htonl(INADDR_ANY); UdpParam.Addr.sin_addr.s_addr = htonl(INADDR_ANY);
//UdpParam.Addr.sin_addr.s_addr = inet_addr("192.168.1.200"); //UdpParam.Addr.sin_addr.s_addr = inet_addr("192.168.1.200");
@ -172,10 +172,10 @@ int CheckIsMySelftIpAddr(u_long addr)
} }
} }
// 定义前置机功能 // 定义前置机功能
#ifdef FUNCTION_FEND #ifdef FUNCTION_FEND
#if (FEND_OTHERDEV_DS3116 == 0) #if (FEND_OTHERDEV_DS3116 == 0)
// 非ds-3116设备时需要用他来确定是否为另一个前置机 // 非ds-3116设备时需要用他来确定是否为另一个前置机
return CheckIsFendIpAddr(addr); return CheckIsFendIpAddr(addr);
#endif #endif
#endif #endif
@ -198,7 +198,7 @@ int CheckIsCurDevIpAddr(u_long addr)
return false; return false;
} }
//接收网络配置网络命令 //接收网络配置网络命令
void SetUdpRecv(void) void SetUdpRecv(void)
{ {
struct timeval outtime; struct timeval outtime;
@ -220,7 +220,7 @@ void SetUdpRecv(void)
for(; ;) for(; ;)
{ {
//异步收 //异步收
if(select(FD_SETSIZE, &set, NULL, NULL, &outtime) < 1) if(select(FD_SETSIZE, &set, NULL, NULL, &outtime) < 1)
break; break;
@ -230,7 +230,7 @@ void SetUdpRecv(void)
break; break;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// wen 2005.09.28 增加对udp通讯端口的显示 // wen 2005.09.28 增加对udp通讯端口的显示
if(RealDataDispFlag) if(RealDataDispFlag)
{ {
if((CurPort == GetMaxPort()) && (CheckIsCurDevIpAddr(ntohl(UdpParam.Addr.sin_addr.s_addr)))) if((CurPort == GetMaxPort()) && (CheckIsCurDevIpAddr(ntohl(UdpParam.Addr.sin_addr.s_addr))))
@ -282,7 +282,7 @@ void SetUdpRecv(void)
} }
} }
//发送配置命令引入IP地址可以自由采用点对点全网广播发送方式 //发送配置命令引入IP地址可以自由采用点对点全网广播发送方式
int SetUdpSend(u_long ipaddr, char *buf, int len) int SetUdpSend(u_long ipaddr, char *buf, int len)
{ {
struct sockaddr_in addr; struct sockaddr_in addr;
@ -293,9 +293,9 @@ int SetUdpSend(u_long ipaddr, char *buf, int len)
return false; return false;
} }
// 定义前置机功能 // 定义前置机功能
#ifdef FUNCTION_FEND #ifdef FUNCTION_FEND
// wen 2005.10.12 增加是否下发前置机的判断 // wen 2005.10.12 增加是否下发前置机的判断
#if (FEND_OTHERDEV_DS3116 == 0) #if (FEND_OTHERDEV_DS3116 == 0)
if(GetFendTxdFlag() == 0) if(GetFendTxdFlag() == 0)
{ {
@ -349,7 +349,7 @@ int SetUdpSend(u_long ipaddr, char *buf, int len)
} }
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// wen 2005.09.28 增加对udp通讯端口的显示 // wen 2005.09.28 增加对udp通讯端口的显示
/*if((CurPort == msg->PortIdx) && RealDataDispFlag) /*if((CurPort == msg->PortIdx) && RealDataDispFlag)
{ {
if(SDS_SIO_SEND_DATA == wType) if(SDS_SIO_SEND_DATA == wType)
@ -377,7 +377,7 @@ int SetUdpSend(u_long ipaddr, char *buf, int len)
return true; return true;
} }
//填充配置结果,返包到上行绶冲 //填充配置结果,返包到上行绶冲
int FillAndSendCmd(u_long ipaddr, u_char port, WORD cmd, u_char *retbuf, int len) int FillAndSendCmd(u_long ipaddr, u_char port, WORD cmd, u_char *retbuf, int len)
{ {
RTUMSG rtumsg; RTUMSG rtumsg;
@ -478,9 +478,9 @@ void AddDispLine(DISP_LINE_BUF *dispbuf, char *msg)
strcpy(dispbuf->Line[dispbuf->Rear], szbuf); strcpy(dispbuf->Line[dispbuf->Rear], szbuf);
dispbuf->Rear = (dispbuf->Rear + 1) % MAX_DISP_LINE; dispbuf->Rear = (dispbuf->Rear + 1) % MAX_DISP_LINE;
// 当缓冲区满后, 丢掉前半个缓冲区内数据,否则, // 当缓冲区满后, 丢掉前半个缓冲区内数据,否则,
// 我们无法停下来观看已有数据,它可能一直滚动, // 我们无法停下来观看已有数据,它可能一直滚动,
// 因为每添加一行我们的指针不得不退让一行 // 因为每添加一行我们的指针不得不退让一行
dispbuf->LineCnt = dispbuf->LineCnt + 1; dispbuf->LineCnt = dispbuf->LineCnt + 1;
if(dispbuf->LineCnt == MAX_DISP_LINE) if(dispbuf->LineCnt == MAX_DISP_LINE)
{ {
@ -507,9 +507,9 @@ void WatchDataPutDispBuf(int port, WORD type, u_char *buf, int len)
GetLocalTime(&st); GetLocalTime(&st);
szbuf[0] = tchar; szbuf[0] = tchar;
sprintf((char*)&szbuf[1], "%04d-%02d-%02d %02d:%02d:%02d.%03d 端口%d %s 数据, 长度 = %d", sprintf((char*)&szbuf[1], "%04d-%02d-%02d %02d:%02d:%02d.%03d 端口%d %s 数据, 长度 = %d",
st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds,
port + 1, type == SDS_SIO_SEND_DATA ? "发送" : "接收", len); port + 1, type == SDS_SIO_SEND_DATA ? "发送" : "接收", len);
AddDispLine(&DevParam[iCurDevIdx].WatchDispLine, szbuf); AddDispLine(&DevParam[iCurDevIdx].WatchDispLine, szbuf);
@ -556,9 +556,9 @@ void WatchDataPutDispBufToFile(int port, WORD type, u_char *buf, int len)
fp = fopen(szFileName, "a"); fp = fopen(szFileName, "a");
szbuf[0] = tchar; szbuf[0] = tchar;
sprintf((char*)&szbuf[1], "%04d-%02d-%02d %02d:%02d:%02d.%03d 端口%d %s 数据, 长度 = %d", sprintf((char*)&szbuf[1], "%04d-%02d-%02d %02d:%02d:%02d.%03d 端口%d %s 数据, 长度 = %d",
st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds,
port + 1, type == SDS_SIO_SEND_DATA ? "发送" : "接收", len); port + 1, type == SDS_SIO_SEND_DATA ? "发送" : "接收", len);
AddDispLine(&DevParam[iCurDevIdx].WatchDispLine, szbuf); AddDispLine(&DevParam[iCurDevIdx].WatchDispLine, szbuf);
@ -638,7 +638,7 @@ int AddDev( u_long *addr, int num )
} }
} }
// 新设备 // 新设备
iDevNum++; iDevNum++;
return iDevNum - 1; return iDevNum - 1;
@ -656,7 +656,7 @@ void SetUdpRecvDataProcess(u_long ipaddr, u_char *buf, int len)
for(plen = 0; plen < len;) for(plen = 0; plen < len;)
{ {
msg = (RTUMSG*)&buf[plen]; msg = (RTUMSG*)&buf[plen];
//让数值为高字节前,低字节后(但此处无特别的作用,仅为了与机器无关而设) //让数值为高字节前,低字节后(但此处无特别的作用,仅为了与机器无关而设)
tmp = BYTE1(buf[plen+1]) + BYTE0(buf[plen+2]); tmp = BYTE1(buf[plen+1]) + BYTE0(buf[plen+2]);
msg->MsgType = tmp; msg->MsgType = tmp;
tmp = BYTE1(buf[plen+3]) + BYTE0(buf[plen+4]); tmp = BYTE1(buf[plen+3]) + BYTE0(buf[plen+4]);
@ -671,17 +671,17 @@ void SetUdpRecvDataProcess(u_long ipaddr, u_char *buf, int len)
switch(msg->MsgType & 0x3fff) switch(msg->MsgType & 0x3fff)
{ {
// 获取系统IP到上行 // 获取系统IP到上行
// 0x00 - 0x03字节: 第一网卡地址IP地址 // 0x00 - 0x03字节: 第一网卡地址IP地址
// 0x044 - 0x07字节: 第二网卡地址IP地址 // 0x044 - 0x07字节: 第二网卡地址IP地址
// 0x08字节 端口数目总数,包括网络通讯端口 // 0x08字节 端口数目总数,包括网络通讯端口
// 0x09 - 0xd字节 保留 // 0x09 - 0xd字节 保留
// 0x0e字节 串行通讯端口数目 // 0x0e字节 串行通讯端口数目
// 0x0f字节 网络通讯端口数目 // 0x0f字节 网络通讯端口数目
// 0x10 - 4个带0x00结尾的字符串它们是设备名称、软件版本、 // 0x10 - 4个带0x00结尾的字符串它们是设备名称、软件版本、
// 软件版本日期和制造厂商名称 // 软件版本日期和制造厂商名称
// 接下来如果网卡数量多于2个接着填写从第三网卡 // 接下来如果网卡数量多于2个接着填写从第三网卡
// 开始的网络IP地址 // 开始的网络IP地址
case SDS_GET_IP_ADDR: case SDS_GET_IP_ADDR:
case SDS_N_GET_IP_ADDR: case SDS_N_GET_IP_ADDR:
if(!(msg->MsgType & 0x8000)) if(!(msg->MsgType & 0x8000))
@ -703,7 +703,7 @@ void SetUdpRecvDataProcess(u_long ipaddr, u_char *buf, int len)
OutputDebugString(szInfo);*/ OutputDebugString(szInfo);*/
} }
// 跳过4个字符串 // 跳过4个字符串
k = 0x10; k = 0x10;
ptr = (char*)&msg->MsgData[k]; ptr = (char*)&msg->MsgData[k];
k += (strlen(ptr) + 1); k += (strlen(ptr) + 1);
@ -774,7 +774,7 @@ void SetUdpRecvDataProcess(u_long ipaddr, u_char *buf, int len)
tmp = BYTE1(msg->MsgData[0]) + BYTE0(msg->MsgData[1]); tmp = BYTE1(msg->MsgData[0]) + BYTE0(msg->MsgData[1]);
// 传输错误, 重来 // 传输错误, 重来
if((msg->MsgType & 0xc000) == 0x4000) if((msg->MsgType & 0xc000) == 0x4000)
{ {
tmp = 0; tmp = 0;
@ -794,21 +794,21 @@ void SetUdpRecvDataProcess(u_long ipaddr, u_char *buf, int len)
//SioParam[msg->PortIdx].RecvCharNum += msg->MsgLen; //SioParam[msg->PortIdx].RecvCharNum += msg->MsgLen;
} }
// wen 2004.11.25 删除数据缓冲区数据长度(保持和5249中的程序一致) // wen 2004.11.25 删除数据缓冲区数据长度(保持和5249中的程序一致)
SioParam[msg->PortIdx].RecvBuf.MsgCnt = 0; SioParam[msg->PortIdx].RecvBuf.MsgCnt = 0;
SioParam[msg->PortIdx].RecvCharNum += msg->MsgLen; SioParam[msg->PortIdx].RecvCharNum += msg->MsgLen;
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// wen 2006.04.24 如果仅仅是接收到数据,不认为端口状态为正常, // wen 2006.04.24 如果仅仅是接收到数据,不认为端口状态为正常,
// 必须是修改了数据库点才认为是端口正常。子站除外。 // 必须是修改了数据库点才认为是端口正常。子站除外。
//SioParam[msg->PortIdx].LineCommCnt = 0; //SioParam[msg->PortIdx].LineCommCnt = 0;
//SioParam[msg->PortIdx].Status = TRUE; //SioParam[msg->PortIdx].Status = TRUE;
//============================================================= //=============================================================
SioParam[msg->PortIdx].LineCommCnt = 0; SioParam[msg->PortIdx].LineCommCnt = 0;
if(SioParam[msg->PortIdx].m_psBaoHu) if(SioParam[msg->PortIdx].m_psBaoHu)
{ {
// 如果为子站 // 如果为子站
if(SioParam[msg->PortIdx].m_psBaoHu->PortType) if(SioParam[msg->PortIdx].m_psBaoHu->PortType)
{ {
SioParam[msg->PortIdx].Status = TRUE; SioParam[msg->PortIdx].Status = TRUE;
@ -826,7 +826,7 @@ void SetUdpRecvDataProcess(u_long ipaddr, u_char *buf, int len)
//} //}
break; break;
case SDS_SIO_SEND_DATA: case SDS_SIO_SEND_DATA:
// 数据已经接收 // 数据已经接收
//sprintf(szInfo, "TIP_(%08d): port=%d Send Data is received.\n", //sprintf(szInfo, "TIP_(%08d): port=%d Send Data is received.\n",
// getpid(), msg->PortIdx+1); // getpid(), msg->PortIdx+1);
//DebugPrint(szInfo); //DebugPrint(szInfo);
@ -856,23 +856,23 @@ int SetDevConfigFileEx(char *szPortConfigName, int blk)
if(!DevParam[iCurDevIdx].CurCommIp) if(!DevParam[iCurDevIdx].CurCommIp)
{ {
////QTMessageBox("设备配置文件...", "无有效设备!!!"); ////QTMessageBox("设备配置文件...", "无有效设备!!!");
return -1; return -1;
} }
if(szPortConfigName == NULL) if(szPortConfigName == NULL)
{ {
//QTMessageBox("设备配置文件...", "下装设备配置文件名称错误!!!"); //QTMessageBox("设备配置文件...", "下装设备配置文件名称错误!!!");
return -1; return -1;
} }
if(strlen(szPortConfigName) == 0) if(strlen(szPortConfigName) == 0)
{ {
//QTMessageBox("设备配置文件...", "下装设备配置文件名称错误!!!"); //QTMessageBox("设备配置文件...", "下装设备配置文件名称错误!!!");
return -1; return -1;
} }
// wen 2005.12.01 在这里设置全局的配置文件名称 // wen 2005.12.01 在这里设置全局的配置文件名称
if(blk == 0) if(blk == 0)
{ {
strcpy(gCurConfigFileName, szPortConfigName); strcpy(gCurConfigFileName, szPortConfigName);
@ -900,7 +900,7 @@ int SetDevConfigFileEx(char *szPortConfigName, int blk)
fclose(fp); fclose(fp);
if(iSendLen == 0) if(iSendLen == 0)
{ {
//QTMessageBox("设备配置文件...", "下装设备配置文件失败!!!"); //QTMessageBox("设备配置文件...", "下装设备配置文件失败!!!");
return -1; return -1;
} }
return 0; return 0;
@ -908,8 +908,8 @@ int SetDevConfigFileEx(char *szPortConfigName, int blk)
} }
fclose(fp); fclose(fp);
//MessageBox(NULL, "设备配置文件设置完成!!!", "设备配置文件...", MB_OK | MB_ICONINFORMATION); //MessageBox(NULL, "设备配置文件设置完成!!!", "设备配置文件...", MB_OK | MB_ICONINFORMATION);
//QTMessageBox("设备配置文件...", "设备配置文件设置完成!!!"); //QTMessageBox("设备配置文件...", "设备配置文件设置完成!!!");
return 1; return 1;
} }

@ -21,17 +21,17 @@
//* udpping.cpp * //* udpping.cpp *
//* Liangchu Lee 1999.12.20 * //* Liangchu Lee 1999.12.20 *
//*************************************************************** //***************************************************************
//************************修 改 提 示**************************** //************************修 改 提 示****************************
//1. wen 2002.11.11 前置机为备用机B时主机退出无法进行切换 //1. wen 2002.11.11 前置机为备用机B时主机退出无法进行切换
// 问题当前置机A为主机下发退出系统后备用前置机无法把自身切换 // 问题当前置机A为主机下发退出系统后备用前置机无法把自身切换
// 为主机。 // 为主机。
// 描述:修改读取函数部分 UdpPingReaddata(void)。 // 描述:修改读取函数部分 UdpPingReaddata(void)。
// 结果增加判断长时间收不到对方PING包置其下发标志为FALSE。 // 结果增加判断长时间收不到对方PING包置其下发标志为FALSE。
//2. wen 2003.04.21 服务器和前置机共处一台机器中,会出现绑定失败。 //2. wen 2003.04.21 服务器和前置机共处一台机器中,会出现绑定失败。
// 问题前置机后启动ping接收端口不能正常工作。 // 问题前置机后启动ping接收端口不能正常工作。
// 描述:服务器、前置机共处一台机器,当前置机后启动,绑定失败, // 描述:服务器、前置机共处一台机器,当前置机后启动,绑定失败,
// 地址被服务器使用。错误信息=10048(套接字地址被使用)。 // 地址被服务器使用。错误信息=10048(套接字地址被使用)。
// 结果设置socket属性为SO_REUSEADDR地址可重用。 // 结果设置socket属性为SO_REUSEADDR地址可重用。
//*************************************************************** //***************************************************************
#include "commport.h" #include "commport.h"
#include "udpping.h" #include "udpping.h"
@ -74,9 +74,9 @@ BOOL UdpPingInit(void)
struct sockaddr_in *cliaddr; struct sockaddr_in *cliaddr;
//struct hostent *test; //struct hostent *test;
#ifndef MACRO_NETPING_P2P #ifndef MACRO_NETPING_P2P
BOOL bBroadcast = TRUE; // 是否广播方式发送数据报 BOOL bBroadcast = TRUE; // 是否广播方式发送数据报
#endif #endif
int timeout = 1000; // 超时 int timeout = 1000; // 超时
char szConfig[256]; char szConfig[256];
@ -87,8 +87,8 @@ BOOL UdpPingInit(void)
sprintf(szConfig, "%s/config.ini", IniFilePath); sprintf(szConfig, "%s/config.ini", IniFilePath);
#endif #endif
gUdpPingReadPort = GetPrivateProInt("网络设置", "PING接收端口", 8124, szConfig); gUdpPingReadPort = GetPrivateProInt("网络设置", "PING接收端口", 8124, szConfig);
gUdpPingWritePort = GetPrivateProInt("网络设置", "PING发送端口", 8123, szConfig); gUdpPingWritePort = GetPrivateProInt("网络设置", "PING发送端口", 8123, szConfig);
//test = gethostbyname(pFendMsg->Name); //test = gethostbyname(pFendMsg->Name);
for(i = 0; i < MAX_ADDR; i++) for(i = 0; i < MAX_ADDR; i++)
@ -115,13 +115,13 @@ BOOL UdpPingInit(void)
} }
#ifdef OS_LINUX #ifdef OS_LINUX
// wen 2005.07.08 将socket设置为非阻塞模式 // wen 2005.07.08 将socket设置为非阻塞模式
tmp = fcntl(UdpPing.sSocket[i], F_GETFL, 0); tmp = fcntl(UdpPing.sSocket[i], F_GETFL, 0);
fcntl(UdpPing.sSocket[i], F_SETFL, tmp|O_NONBLOCK); fcntl(UdpPing.sSocket[i], F_SETFL, tmp|O_NONBLOCK);
#endif #endif
#ifndef MACRO_NETPING_P2P #ifndef MACRO_NETPING_P2P
// wen 2006.04.28 不使用广播发送ping包 // wen 2006.04.28 不使用广播发送ping包
bBroadcast = TRUE; bBroadcast = TRUE;
setsockopt(UdpPing.sSocket[i], SOL_SOCKET, SO_BROADCAST, (char*)&bBroadcast, sizeof(bBroadcast)); setsockopt(UdpPing.sSocket[i], SOL_SOCKET, SO_BROADCAST, (char*)&bBroadcast, sizeof(bBroadcast));
#endif #endif
@ -164,7 +164,7 @@ BOOL UdpPingInit(void)
return FALSE; return FALSE;
} }
// wen 2003.04.21 服务器和前置机共处一台机器中,会出现绑定失败。套接字地址被使用 // wen 2003.04.21 服务器和前置机共处一台机器中,会出现绑定失败。套接字地址被使用
tmp_len = 1; tmp_len = 1;
setsockopt(UdpPing.rSocket, SOL_SOCKET, SO_REUSEADDR, (char*)&tmp_len, sizeof(int)); setsockopt(UdpPing.rSocket, SOL_SOCKET, SO_REUSEADDR, (char*)&tmp_len, sizeof(int));
@ -204,7 +204,7 @@ void UdpPingSendData(void)
} }
cnt = 0; cnt = 0;
// 获取全局变量,通过函数调用 // 获取全局变量,通过函数调用
pHostLink = GetHostLinkPtr(); pHostLink = GetHostLinkPtr();
pFendMsg = GetFendMsgPtr(); pFendMsg = GetFendMsgPtr();
@ -246,7 +246,7 @@ void UdpPingSendData(void)
&& (pFendMsg->SendTxdDataFlag[1] == 0)) && (pFendMsg->SendTxdDataFlag[1] == 0))
{ {
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// wen 2006.04.22 主备切换时,判断的端口通讯状态屏蔽字(按位屏蔽) // wen 2006.04.22 主备切换时,判断的端口通讯状态屏蔽字(按位屏蔽)
//pFendMsg->SendTxdDataFlag[0] = FALSE; //pFendMsg->SendTxdDataFlag[0] = FALSE;
//pFendMsg->SendTxdDataFlag[1] = FALSE; //pFendMsg->SendTxdDataFlag[1] = FALSE;
//pFendMsg->SendTxdDataFlag[pFendMsg->FendIdx] = TRUE; //pFendMsg->SendTxdDataFlag[pFendMsg->FendIdx] = TRUE;
@ -285,7 +285,7 @@ void UdpPingSendData(void)
&& (pFendMsg->SendTxdDataFlag[1] == 0)) && (pFendMsg->SendTxdDataFlag[1] == 0))
{ {
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// wen 2006.04.22 主备切换时,判断的端口通讯状态屏蔽字(按位屏蔽) // wen 2006.04.22 主备切换时,判断的端口通讯状态屏蔽字(按位屏蔽)
//pFendMsg->SendTxdDataFlag[0] = FALSE; //pFendMsg->SendTxdDataFlag[0] = FALSE;
//pFendMsg->SendTxdDataFlag[1] = FALSE; //pFendMsg->SendTxdDataFlag[1] = FALSE;
//pFendMsg->SendTxdDataFlag[pFendMsg->FendIdx] = TRUE; //pFendMsg->SendTxdDataFlag[pFendMsg->FendIdx] = TRUE;
@ -327,7 +327,7 @@ void UdpPingSendData(void)
pFendMsg->SendTxdDataFlag[1] = FALSE; pFendMsg->SendTxdDataFlag[1] = FALSE;
} }
// wen 2002.11.25 连接服务器慢的系统会出现切换不成功 // wen 2002.11.25 连接服务器慢的系统会出现切换不成功
/* /*
switch(pFendMsg->LinkStatus[1]*2 + pFendMsg->LinkStatus[0]) switch(pFendMsg->LinkStatus[1]*2 + pFendMsg->LinkStatus[0])
{ {
@ -344,7 +344,7 @@ void UdpPingSendData(void)
} }
//DebugPrint("UdpPingSendData Begin..."); //DebugPrint("UdpPingSendData Begin...");
// 字节顺序转换 // 字节顺序转换
PingData.wNodeID = SequenceHostToRtuWord(PingData.wNodeID); PingData.wNodeID = SequenceHostToRtuWord(PingData.wNodeID);
for(i = 0; i < MAX_ADDR; i++) for(i = 0; i < MAX_ADDR; i++)
{ {
@ -360,7 +360,7 @@ void UdpPingSendData(void)
switch(gSendTxdDataFendIdx) switch(gSendTxdDataFendIdx)
{ {
case 1: // 前置机 A 下发数据 case 1: // 前置机 A 下发数据
if(pFendMsg->SendTxdDataFlag[0] == 0) if(pFendMsg->SendTxdDataFlag[0] == 0)
{ {
pFendMsg->SendTxdDataFlag[1] = FALSE; pFendMsg->SendTxdDataFlag[1] = FALSE;
@ -377,7 +377,7 @@ void UdpPingSendData(void)
gSendTxdDataFendIdx = 0; gSendTxdDataFendIdx = 0;
} }
break; break;
case 2: // 前置机 B 下发数据 case 2: // 前置机 B 下发数据
if(pFendMsg->SendTxdDataFlag[1] == 0) if(pFendMsg->SendTxdDataFlag[1] == 0)
{ {
pFendMsg->SendTxdDataFlag[0] = FALSE; pFendMsg->SendTxdDataFlag[0] = FALSE;
@ -410,7 +410,7 @@ void UdpPingSendData(void)
// PingData.wNodeID, PingData.inetAddr, PingData.inetMask, PingData.dwStatus); // PingData.wNodeID, PingData.inetAddr, PingData.inetMask, PingData.dwStatus);
//DebugPrint(szDbg); //DebugPrint(szDbg);
// 字节顺序转换 // 字节顺序转换
//PingData.wNodeID = SequenceHostToRtuWord(PingData.wNodeID); //PingData.wNodeID = SequenceHostToRtuWord(PingData.wNodeID);
PingData.inetMask = SequenceHostToRtuDWord(PingData.inetMask); PingData.inetMask = SequenceHostToRtuDWord(PingData.inetMask);
PingData.inetAddr = SequenceHostToRtuDWord(PingData.inetAddr); PingData.inetAddr = SequenceHostToRtuDWord(PingData.inetAddr);
@ -459,7 +459,7 @@ void UdpPingSendDataP2P(void)
} }
cnt = 0; cnt = 0;
// 获取全局变量,通过函数调用 // 获取全局变量,通过函数调用
pHostLink = GetHostLinkPtr(); pHostLink = GetHostLinkPtr();
pFendMsg = GetFendMsgPtr(); pFendMsg = GetFendMsgPtr();
@ -501,7 +501,7 @@ void UdpPingSendDataP2P(void)
&& (pFendMsg->SendTxdDataFlag[1] == 0)) && (pFendMsg->SendTxdDataFlag[1] == 0))
{ {
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// wen 2006.04.22 主备切换时,判断的端口通讯状态屏蔽字(按位屏蔽) // wen 2006.04.22 主备切换时,判断的端口通讯状态屏蔽字(按位屏蔽)
//pFendMsg->SendTxdDataFlag[0] = FALSE; //pFendMsg->SendTxdDataFlag[0] = FALSE;
//pFendMsg->SendTxdDataFlag[1] = FALSE; //pFendMsg->SendTxdDataFlag[1] = FALSE;
//pFendMsg->SendTxdDataFlag[pFendMsg->FendIdx] = TRUE; //pFendMsg->SendTxdDataFlag[pFendMsg->FendIdx] = TRUE;
@ -540,7 +540,7 @@ void UdpPingSendDataP2P(void)
&& (pFendMsg->SendTxdDataFlag[1] == 0)) && (pFendMsg->SendTxdDataFlag[1] == 0))
{ {
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// wen 2006.04.22 主备切换时,判断的端口通讯状态屏蔽字(按位屏蔽) // wen 2006.04.22 主备切换时,判断的端口通讯状态屏蔽字(按位屏蔽)
//pFendMsg->SendTxdDataFlag[0] = FALSE; //pFendMsg->SendTxdDataFlag[0] = FALSE;
//pFendMsg->SendTxdDataFlag[1] = FALSE; //pFendMsg->SendTxdDataFlag[1] = FALSE;
//pFendMsg->SendTxdDataFlag[pFendMsg->FendIdx] = TRUE; //pFendMsg->SendTxdDataFlag[pFendMsg->FendIdx] = TRUE;
@ -572,7 +572,7 @@ void UdpPingSendDataP2P(void)
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
} }
// wen 2006.04.29 在uclinux下发送数据给自己无法接收的到。始终认为自己是存在的。 // wen 2006.04.29 在uclinux下发送数据给自己无法接收的到。始终认为自己是存在的。
#ifdef OS_LINUX #ifdef OS_LINUX
pFendMsg->FendExistFlag[pFendMsg->FendIdx] = TRUE; pFendMsg->FendExistFlag[pFendMsg->FendIdx] = TRUE;
pFendMsg->FendExistCnt[pFendMsg->FendIdx] = 0; pFendMsg->FendExistCnt[pFendMsg->FendIdx] = 0;
@ -588,7 +588,7 @@ void UdpPingSendDataP2P(void)
pFendMsg->SendTxdDataFlag[1] = FALSE; pFendMsg->SendTxdDataFlag[1] = FALSE;
} }
// wen 2002.11.25 连接服务器慢的系统会出现切换不成功 // wen 2002.11.25 连接服务器慢的系统会出现切换不成功
/* /*
switch(pFendMsg->LinkStatus[1]*2 + pFendMsg->LinkStatus[0]) switch(pFendMsg->LinkStatus[1]*2 + pFendMsg->LinkStatus[0])
{ {
@ -605,7 +605,7 @@ void UdpPingSendDataP2P(void)
} }
//DebugPrint("UdpPingSendDataP2P Begin..."); //DebugPrint("UdpPingSendDataP2P Begin...");
// 字节顺序转换 // 字节顺序转换
PingData.wNodeID = SequenceHostToRtuWord(PingData.wNodeID); PingData.wNodeID = SequenceHostToRtuWord(PingData.wNodeID);
for(i = 0; i < MAX_ADDR; i++) for(i = 0; i < MAX_ADDR; i++)
{ {
@ -621,7 +621,7 @@ void UdpPingSendDataP2P(void)
switch(gSendTxdDataFendIdx) switch(gSendTxdDataFendIdx)
{ {
case 1: // 前置机 A 下发数据 case 1: // 前置机 A 下发数据
if(pFendMsg->SendTxdDataFlag[0] == 0) if(pFendMsg->SendTxdDataFlag[0] == 0)
{ {
pFendMsg->SendTxdDataFlag[1] = FALSE; pFendMsg->SendTxdDataFlag[1] = FALSE;
@ -638,7 +638,7 @@ void UdpPingSendDataP2P(void)
gSendTxdDataFendIdx = 0; gSendTxdDataFendIdx = 0;
} }
break; break;
case 2: // 前置机 B 下发数据 case 2: // 前置机 B 下发数据
if(pFendMsg->SendTxdDataFlag[1] == 0) if(pFendMsg->SendTxdDataFlag[1] == 0)
{ {
pFendMsg->SendTxdDataFlag[0] = FALSE; pFendMsg->SendTxdDataFlag[0] = FALSE;
@ -661,15 +661,15 @@ void UdpPingSendDataP2P(void)
memset((char *)servaddr, 0, sizeof(struct sockaddr_in)); memset((char *)servaddr, 0, sizeof(struct sockaddr_in));
servaddr->sin_family = AF_INET; servaddr->sin_family = AF_INET;
//servaddr->sin_addr.s_addr = htonl(pFendMsg->SetTcpIpAddr[2*i]); //servaddr->sin_addr.s_addr = htonl(pFendMsg->SetTcpIpAddr[2*i]);
// 字节顺序转换 // 字节顺序转换
//PingData.wNodeID = SequenceHostToRtuWord(PingData.wNodeID); //PingData.wNodeID = SequenceHostToRtuWord(PingData.wNodeID);
PingData.inetMask = SequenceHostToRtuDWord(PingData.inetMask); PingData.inetMask = SequenceHostToRtuDWord(PingData.inetMask);
PingData.inetAddr = SequenceHostToRtuDWord(PingData.inetAddr); PingData.inetAddr = SequenceHostToRtuDWord(PingData.inetAddr);
PingData.dwStatus = SequenceHostToRtuDWord(PingData.dwStatus); PingData.dwStatus = SequenceHostToRtuDWord(PingData.dwStatus);
// 点对点发送给前置机 // 点对点发送给前置机
for(j=0; j<MAX_FEND; j++) for(j=0; j<MAX_FEND; j++)
{ {
// wen 2006.04.29 在uclinux下发送数据给自己无法接收的到。所以不发送数据给自己。 // wen 2006.04.29 在uclinux下发送数据给自己无法接收的到。所以不发送数据给自己。
#ifdef OS_LINUX #ifdef OS_LINUX
if(j == pFendMsg->FendIdx) if(j == pFendMsg->FendIdx)
{ {
@ -700,7 +700,7 @@ void UdpPingSendDataP2P(void)
} }
} }
// 点对点发送给服务器 // 点对点发送给服务器
for(j=0; j<MAX_HOST; j++) for(j=0; j<MAX_HOST; j++)
{ {
if(strlen((char *)pHostLink[j].TcpIpAddr[i]) > 0) if(strlen((char *)pHostLink[j].TcpIpAddr[i]) > 0)
@ -733,13 +733,13 @@ void UdpPingReaddata(void)
char revip[32]; char revip[32];
char szbuf[128]; char szbuf[128];
static int dflag = 0; static int dflag = 0;
// wen 2002.11.11 前置机为备用机B时主机退出无法进行切换 // wen 2002.11.11 前置机为备用机B时主机退出无法进行切换
static int recvtimeout = 0; static int recvtimeout = 0;
TCP_LINK_DEF *pHostLink; TCP_LINK_DEF *pHostLink;
FEND_DEF *pFendMsg; FEND_DEF *pFendMsg;
SIO_PARAM_DEF *pSioParam; SIO_PARAM_DEF *pSioParam;
// 获取全局变量,通过函数调用 // 获取全局变量,通过函数调用
pHostLink = GetHostLinkPtr(); pHostLink = GetHostLinkPtr();
pFendMsg = GetFendMsgPtr(); pFendMsg = GetFendMsgPtr();
//for(i = 0; i < MAX_ADDR; i++) //for(i = 0; i < MAX_ADDR; i++)
@ -778,7 +778,7 @@ void UdpPingReaddata(void)
//if(!CmpnString((char*)pingmsg->barrRandom, PINGRANDOM, MAX_RANDOM-1)) //if(!CmpnString((char*)pingmsg->barrRandom, PINGRANDOM, MAX_RANDOM-1))
// continue; // continue;
// 字节顺序转换 // 字节顺序转换
pingmsg->wNodeID = SequenceRtuToHostWord(pingmsg->wNodeID); pingmsg->wNodeID = SequenceRtuToHostWord(pingmsg->wNodeID);
pingmsg->inetAddr = SequenceRtuToHostDWord(pingmsg->inetAddr); pingmsg->inetAddr = SequenceRtuToHostDWord(pingmsg->inetAddr);
pingmsg->inetMask = SequenceRtuToHostDWord(pingmsg->inetMask); pingmsg->inetMask = SequenceRtuToHostDWord(pingmsg->inetMask);
@ -797,16 +797,16 @@ void UdpPingReaddata(void)
/* test /* test
if(gtestread == 0) if(gtestread == 0)
{ {
// 前置机a // 前置机a
if(pingmsg->wNodeID == 0) if(pingmsg->wNodeID == 0)
{ {
DebugPrint("屏蔽前置机a的ping包"); DebugPrint("屏蔽前置机a的ping包");
break; break;
} }
}*/ }*/
// wen 2002.11.11 前置机为备用机B时主机退出无法进行切换 // wen 2002.11.11 前置机为备用机B时主机退出无法进行切换
// 每一个ping 包 一秒钟发送一次 // 每一个ping 包 一秒钟发送一次
if(!pFendMsg->SendTxdDataFlag[pFendMsg->FendIdx]) if(!pFendMsg->SendTxdDataFlag[pFendMsg->FendIdx])
{ {
if(recvtimeout < 6) if(recvtimeout < 6)
@ -817,7 +817,7 @@ void UdpPingReaddata(void)
{ {
recvtimeout = 0; recvtimeout = 0;
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// wen 2006.04.22 主备切换时,判断的端口通讯状态屏蔽字(按位屏蔽) // wen 2006.04.22 主备切换时,判断的端口通讯状态屏蔽字(按位屏蔽)
//pFendMsg->SendTxdDataFlag[(pFendMsg->FendIdx+1)%MAX_ADDR] = FALSE; //pFendMsg->SendTxdDataFlag[(pFendMsg->FendIdx+1)%MAX_ADDR] = FALSE;
//pFendMsg->SendTxdDataFlag[pFendMsg->FendIdx] = TRUE; //pFendMsg->SendTxdDataFlag[pFendMsg->FendIdx] = TRUE;
//======================================================================= //=======================================================================
@ -861,7 +861,7 @@ void UdpPingReaddata(void)
continue; continue;
} }
// wen 2002.11.11 前置机为备用机B时主机退出无法进行切换 // wen 2002.11.11 前置机为备用机B时主机退出无法进行切换
recvtimeout = 0; recvtimeout = 0;
} }
@ -895,7 +895,7 @@ void UdpPingReaddata(void)
} }
break; break;
} }
// wen 2006.04.29 多余的指令,这种情况永远不会发生,上面已经消除了这种情况 // wen 2006.04.29 多余的指令,这种情况永远不会发生,上面已经消除了这种情况
//if(pFendMsg->SendTxdDataFlag[0] && pFendMsg->SendTxdDataFlag[1]) //if(pFendMsg->SendTxdDataFlag[0] && pFendMsg->SendTxdDataFlag[1])
//{ //{
// pFendMsg->SendTxdDataFlag[1] = FALSE; // pFendMsg->SendTxdDataFlag[1] = FALSE;
@ -927,7 +927,7 @@ void UdpPingReaddata(void)
{ {
if(dflag == 0) if(dflag == 0)
{ {
sprintf(szbuf, "接收服务器状态为双主机状态错误!!! 当前处理服务器 %c 状态包。", pingmsg->wNodeID + 'A'); sprintf(szbuf, "接收服务器状态为双主机状态错误!!! 当前处理服务器 %c 状态包。", pingmsg->wNodeID + 'A');
DebugPrint((char*)szbuf); DebugPrint((char*)szbuf);
} }
dflag = 1; dflag = 1;
@ -938,13 +938,13 @@ void UdpPingReaddata(void)
{ {
if(pHostLink[0].Status == 0) if(pHostLink[0].Status == 0)
{ {
sprintf(szbuf, "接收服务器状态 A 服务器为主机!!!"); sprintf(szbuf, "接收服务器状态 A 服务器为主机!!!");
DebugPrint((char*)szbuf); DebugPrint((char*)szbuf);
} }
if(pHostLink[1].Status == 0) if(pHostLink[1].Status == 0)
{ {
sprintf(szbuf, "接收服务器状态 B 服务器为主机!!!"); sprintf(szbuf, "接收服务器状态 B 服务器为主机!!!");
DebugPrint((char*)szbuf); DebugPrint((char*)szbuf);
} }
} }
@ -989,7 +989,7 @@ void UdpPingSwitch(void)
int i; int i;
FEND_DEF *pFendMsg; FEND_DEF *pFendMsg;
// 获取全局变量,通过函数调用 // 获取全局变量,通过函数调用
pFendMsg = GetFendMsgPtr(); pFendMsg = GetFendMsgPtr();
for(i=0; i<MAX_FEND; i++) for(i=0; i<MAX_FEND; i++)

@ -21,19 +21,19 @@
* no message * no message
* *
* Revision 1.4 2006/04/28 06:29:18 administrator * Revision 1.4 2006/04/28 06:29:18 administrator
* ping * ping
* *
* Revision 1.3 2006/04/22 07:51:07 administrator * Revision 1.3 2006/04/22 07:51:07 administrator
* *
* *
* Revision 1.2 2005/10/20 07:03:56 Administrator * Revision 1.2 2005/10/20 07:03:56 Administrator
* *
* *
* Revision 1.1 2005/10/12 06:03:47 Administrator * Revision 1.1 2005/10/12 06:03:47 Administrator
* *
* *
* *
* CVS, * CVS,
* *
**************************************************************************************/ **************************************************************************************/
//*************************************************************** //***************************************************************
@ -67,7 +67,7 @@ typedef struct tagUDP_PING_REV_DATA
} UDP_PING_REV_DATA; } UDP_PING_REV_DATA;
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// 是pc机系统还是嵌入式系统 // 是pc机系统还是嵌入式系统
#ifdef PC_MACHINE #ifdef PC_MACHINE
#ifdef OS_WINDOWS #ifdef OS_WINDOWS
#pragma pack (push,1) #pragma pack (push,1)
@ -80,14 +80,14 @@ typedef struct tagPINGINFORMATION
{ {
BYTE barrRandom[MAX_RANDOM] __attribute__ ((packed)); BYTE barrRandom[MAX_RANDOM] __attribute__ ((packed));
char szNodeName[MAX_NODENAME] __attribute__ ((packed)); char szNodeName[MAX_NODENAME] __attribute__ ((packed));
BYTE bNodeType __attribute__ ((packed)); /*节点类型*/ BYTE bNodeType __attribute__ ((packed)); /*节点类型*/
WORD wNodeID __attribute__ ((packed)); /*接点号*/ WORD wNodeID __attribute__ ((packed)); /*接点号*/
u_long inetMask __attribute__ ((packed)); /*网络掩码, 发送者, 主机字节顺序*/ u_long inetMask __attribute__ ((packed)); /*网络掩码, 发送者, 主机字节顺序*/
u_long inetAddr __attribute__ ((packed)); /*完整IP地址, 发送者, 主机字节顺序*/ u_long inetAddr __attribute__ ((packed)); /*完整IP地址, 发送者, 主机字节顺序*/
DWORD dwStatus __attribute__ ((packed)); /*该网络接口IP地址的状态*/ DWORD dwStatus __attribute__ ((packed)); /*该网络接口IP地址的状态*/
} PINGINFORMATION; } PINGINFORMATION;
// 是pc机系统还是嵌入式系统 // 是pc机系统还是嵌入式系统
#ifdef PC_MACHINE #ifdef PC_MACHINE
#ifdef OS_WINDOWS #ifdef OS_WINDOWS
#pragma pack (pop) #pragma pack (pop)

@ -1,6 +1,7 @@
// widgets.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 // widgets.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
// //
#include <iostream> #include <iostream>
#include "MySQLAdo.h"
#include "baohua.h" #include "baohua.h"
#include "buban103.h" #include "buban103.h"
#include "buban104.h" #include "buban104.h"
@ -51,7 +52,7 @@ int InitBaohuMainFlag = 0;
void BaohuLibMain(int netportnum); void BaohuLibMain(int netportnum);
int main(void) int main(int argc, char **argv)
{ {
std::cout << "Hello World!\n"; std::cout << "Hello World!\n";
@ -61,6 +62,8 @@ int main(void)
WSADATA WSAData; WSADATA WSAData;
#endif #endif
InitDatabase(argc, argv, "localhost", "root", "123456", "health");
//定时器指针置空 //定时器指针置空
//m_pMainTimer = NULL; //m_pMainTimer = NULL;
//该段代码进入环境变量KERNELFEND_ROOT所指定的目录 //该段代码进入环境变量KERNELFEND_ROOT所指定的目录
@ -143,6 +146,8 @@ int main(void)
conf_close(pvdataconf_handle); conf_close(pvdataconf_handle);
pvdataconf_handle = NULL; pvdataconf_handle = NULL;
} }
UninitDatabase();
} }
// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单 // 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单

@ -24,6 +24,7 @@
<Keyword>Win32Proj</Keyword> <Keyword>Win32Proj</Keyword>
<RootNamespace>widgets</RootNamespace> <RootNamespace>widgets</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion> <WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
<ProjectName>iec103</ProjectName>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
@ -75,8 +76,8 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental> <LinkIncremental>true</LinkIncremental>
<IncludePath>C:\Program Files\MariaDB 10.11\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath> <IncludePath>C:\Program Files\MariaDB 10.10\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<LibraryPath>C:\Program Files\MariaDB 10.11\lib;D:\Workspace\deps\x64\dbg;$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(NETFXKitsDir)Lib\um\x64</LibraryPath> <LibraryPath>C:\Program Files\MariaDB 10.10\lib;D:\Workspace\deps\x64\dbg;$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(NETFXKitsDir)Lib\um\x64</LibraryPath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental> <LinkIncremental>false</LinkIncremental>
@ -108,7 +109,7 @@
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>USING_MYSQL;_DEBUG;_CONSOLE;OS_WINDOWS;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS;DISABLE_OS_HEAP</PreprocessorDefinitions> <PreprocessorDefinitions>USING_MYSQL;_DEBUG;_CONSOLE;OS_WINDOWS;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS;DISABLE_OS_HEAP</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<AdditionalOptions>/UTF-8 %(AdditionalOptions)</AdditionalOptions> <AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>

Loading…
Cancel
Save