|
|
/*****************************************************************************
|
|
|
* FileName : commport.c *
|
|
|
* Programmer : Li Liangchu *
|
|
|
* Writen at : 2004.07.22 *
|
|
|
* Version : *
|
|
|
* Description: *
|
|
|
* Last modify: 2002.11.6 *
|
|
|
*****************************************************************************/
|
|
|
|
|
|
//#include "stdafx.h"
|
|
|
//#include "resource.h"
|
|
|
#include "commport.h"
|
|
|
#include "udpcomm.h"
|
|
|
#include "udpping.h"
|
|
|
#include "tcphost.h"
|
|
|
#include "netport.h"
|
|
|
#include <winsock.h>
|
|
|
//#include "..\confrwlib\confrw.h"
|
|
|
|
|
|
#define MAX_STRING_LEN 512
|
|
|
|
|
|
extern int CurPort;
|
|
|
extern int RealDataDispFlag;
|
|
|
|
|
|
extern int iCurDevIdx;
|
|
|
extern DEV_DEF DevParam[];
|
|
|
|
|
|
extern UDP_SET_DEF UdpParam;
|
|
|
extern int RealDataDispFlag;
|
|
|
|
|
|
FUNCTION_CALL *FunCallPtr;
|
|
|
|
|
|
SIO_PARAM_DEF SioParam[DEFAULT_MAX_PORT_NUM];
|
|
|
|
|
|
int ProvPortCnt = 0;
|
|
|
|
|
|
u_short UdpCommPort;
|
|
|
|
|
|
u_short MaxSerialPortNum;
|
|
|
u_short MaxNetPortNum;
|
|
|
u_short MaxPortNum;
|
|
|
|
|
|
void * pvconf_handle = NULL;
|
|
|
void * pvportconf_handle = NULL;
|
|
|
void * pvdataconf_handle = NULL;
|
|
|
char pvDataFileName[256];
|
|
|
|
|
|
char DeviceName[256];
|
|
|
char Version[256];
|
|
|
char VersionDate[256];
|
|
|
char Manufacturer[256];
|
|
|
char IniFilePath[256];
|
|
|
|
|
|
DAY_TIME DayTime;
|
|
|
|
|
|
u_long GetPrivateProString(const char *section, const char *entry, const char *defaultstr, char *result, int len, char *inifile)
|
|
|
{
|
|
|
int ret = SUCCESS;
|
|
|
char szConfig[256], szPortConfig[256];
|
|
|
|
|
|
//GetCurrentDirectory(sizeof(szDir), szDir);
|
|
|
sprintf(szConfig, "%s/config.ini", IniFilePath);
|
|
|
sprintf(szPortConfig, "%s/portconfig.ini", IniFilePath);
|
|
|
|
|
|
//GetPrivateProfileString(section, entry, defaultstr, result, len, inifile);
|
|
|
if( (strcmp(inifile, szConfig) == 0) && (pvconf_handle != NULL) ) //config.ini
|
|
|
{
|
|
|
ret = conf_read_key ( pvconf_handle,
|
|
|
section,
|
|
|
entry,
|
|
|
defaultstr,
|
|
|
result,
|
|
|
len);
|
|
|
}
|
|
|
else if( (strcmp(inifile, szPortConfig) == 0) && (pvportconf_handle != NULL) ) //portconfig.ini
|
|
|
{
|
|
|
ret = conf_read_key ( pvportconf_handle,
|
|
|
section,
|
|
|
entry,
|
|
|
defaultstr,
|
|
|
result,
|
|
|
len);
|
|
|
}
|
|
|
else //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD>ϰ취<CFB0><ECB7A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
{
|
|
|
GetPrivateProfileString((LPWSTR)section, (LPWSTR)entry, (LPWSTR)defaultstr, (LPWSTR)result, len, (LPWSTR)inifile);
|
|
|
printf("\nTIP_(%04d): GetPrivateProString used GetPrivateProfileString(inifile=%s,section=%s, item=%s,result=%s)\n", inifile, section, entry, result);
|
|
|
result[0] = 0;
|
|
|
}
|
|
|
if( SUCCESS == ret )
|
|
|
StringCutSpace(result);
|
|
|
else
|
|
|
result[0] = 0;
|
|
|
|
|
|
return (u_long)strlen(result);
|
|
|
}
|
|
|
|
|
|
int GetPrivateProInt(const char *section, const char *entry, int idefault, char *inifile)
|
|
|
{
|
|
|
int i, ilen, iRetVal;
|
|
|
char szResult[128];
|
|
|
|
|
|
memset(szResult, 0, sizeof(szResult));
|
|
|
ilen = GetPrivateProString(section, entry, "", szResult, sizeof(szResult)-1, inifile);
|
|
|
if(ilen <= 0)
|
|
|
{
|
|
|
iRetVal = idefault;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if(ilen > 2)
|
|
|
{
|
|
|
if((szResult[0]=='0') && ((szResult[1]=='x') || (szResult[1]=='X')))
|
|
|
{
|
|
|
iRetVal = 0;
|
|
|
for(i=2; i<ilen; i++)
|
|
|
{
|
|
|
iRetVal = (iRetVal << 4) + HexCharToInt(szResult[i]);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//iRetVal = atoul(szResult);
|
|
|
iRetVal = atoi(szResult);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//iRetVal = atoul(szResult);
|
|
|
iRetVal = atoi(szResult);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return iRetVal;
|
|
|
}
|
|
|
|
|
|
u_long GetPrivateProString2(const char *section, const char *entry, const char *defaultstr, char *result, int len, HDSFILE hFile)
|
|
|
{
|
|
|
int end, rlen, SectionOk;
|
|
|
int ilinelen, iReadLines;
|
|
|
char *ptr;
|
|
|
|
|
|
char fstring[MAX_STRING_LEN];
|
|
|
char istring[MAX_STRING_LEN];
|
|
|
char tmp[MAX_STRING_LEN];
|
|
|
char retstr[MAX_STRING_LEN];
|
|
|
#if 0
|
|
|
FILE *fp;
|
|
|
char szfilename[128];
|
|
|
|
|
|
#ifdef OS_LINUX
|
|
|
strcpy(szfilename, "/log/dsdebug.txt");
|
|
|
#else
|
|
|
strcpy(szfilename, "dsdebug.txt");
|
|
|
#endif
|
|
|
fp = fopen(szfilename, "ab");
|
|
|
if(fp)
|
|
|
{
|
|
|
fwrite("#####begin#####\r\n", 1, strlen("#####begin#####\r\n"), fp);
|
|
|
fwrite(section, 1, strlen(section), fp);
|
|
|
fwrite("-------", 1, 7, fp);
|
|
|
fwrite(entry, 1, strlen(entry), fp);
|
|
|
fwrite("\r\n", 1, strlen("\r\n"), fp);
|
|
|
fclose(fp);
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
rlen = (len < MAX_STRING_LEN) ? len : MAX_STRING_LEN;
|
|
|
rlen--;
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>ȱʡֵ<CAA1>ij<EFBFBD><C4B3>ȴ<EFBFBD><C8B4>ڷ<EFBFBD><DAB7>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
if(!defaultstr)
|
|
|
{
|
|
|
retstr[0] = 0;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
ilinelen = (int)strlen(defaultstr);
|
|
|
if(ilinelen == 0)
|
|
|
{
|
|
|
retstr[0] = 0;
|
|
|
}
|
|
|
else if(ilinelen > rlen)
|
|
|
{
|
|
|
memcpy(retstr, defaultstr, rlen-1);
|
|
|
retstr[rlen] = 0;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strcpy(retstr, defaultstr);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// <20><><EFBFBD>Ƚ<EFBFBD><C8BD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>ֵΪȱʡֵ<CAA1><D6B5><EFBFBD><EFBFBD><EFBFBD>ҽ<EFBFBD><D2BD><EFBFBD><EFBFBD>ڴ˸<DAB4>ֵȱʡֵ
|
|
|
strcpy(result, retstr);
|
|
|
|
|
|
if(NULL == hFile)
|
|
|
{
|
|
|
goto ExitFlag2;
|
|
|
}
|
|
|
|
|
|
sprintf(istring, "[%s]", section);
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ݶ<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
|
|
DSfseek(hFile, 0, SEEK_CLR_RCNT);
|
|
|
SectionOk = DSHaveSection(istring, hFile);
|
|
|
if(DS_SECTION_SEARCH == SectionOk)
|
|
|
{
|
|
|
while(1)
|
|
|
{
|
|
|
ilinelen = DSfgetreadcount(hFile);
|
|
|
if(DSfgets(fstring, sizeof(fstring)-1, hFile) == NULL)
|
|
|
{
|
|
|
if(DSfeob(hFile) == 0)
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
DSfseek(hFile, 0, SEEK_SET);
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if(StringCutSpace(fstring) > 0)
|
|
|
{
|
|
|
fstring[strlen(istring)] = 0;
|
|
|
|
|
|
// if remark
|
|
|
if(IsRemarkLine(fstring) == TRUE)
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
//if find the section
|
|
|
if(strstr(istring, fstring) != NULL)
|
|
|
{
|
|
|
SectionOk = DS_SECTION_EXIST;
|
|
|
DSSaveSectionOffset(hFile);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if(DS_SECTION_SEARCH == SectionOk)
|
|
|
{
|
|
|
DSRestoreSectionOffset(hFile);
|
|
|
SectionOk = DS_SECTION_NOEXIST;
|
|
|
}
|
|
|
|
|
|
if(SectionOk <= DS_SECTION_NOEXIST)
|
|
|
{
|
|
|
goto ExitFlag2;
|
|
|
}
|
|
|
|
|
|
iReadLines = 0;
|
|
|
//after find the section, continue find the entry
|
|
|
sprintf(istring, "%s=", entry);
|
|
|
while(1)
|
|
|
{
|
|
|
if(DSSectionisOver(iReadLines, hFile))
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
if(DSfgets(fstring, sizeof(fstring)-1, hFile) == NULL)
|
|
|
{
|
|
|
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>öΣ<C3B6><CEA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[]<5D>ı߽<C4B1>
|
|
|
if(DSfeob(hFile) == 0)
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
DSSetSectionLinesAddFlag(0, hFile);
|
|
|
if(DSSectionisOver(iReadLines, hFile))
|
|
|
{
|
|
|
//goto ExitFlag2;
|
|
|
break;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
DSRestoreSectionOffset(hFile);
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
iReadLines++;
|
|
|
DSAddSectionLines(1, hFile);
|
|
|
|
|
|
if(StringCutSpace(fstring) == 0)
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
//just look for the string in current section
|
|
|
if((fstring[0] == '[') && (strstr(fstring,"]") != NULL))
|
|
|
{
|
|
|
iReadLines--;
|
|
|
DSSubSectionLines(1, hFile);
|
|
|
|
|
|
DSSetSectionLinesAddFlag(0, hFile);
|
|
|
if(DSSectionisOver(iReadLines, hFile))
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
DSRestoreSectionOffset(hFile);
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// if remark
|
|
|
if(IsRemarkLine(fstring) == TRUE)
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
strcpy(tmp, fstring);
|
|
|
tmp[strlen(istring)+1] = 0;
|
|
|
if(strstr(tmp, istring) != 0)
|
|
|
{
|
|
|
ptr = strstr(fstring, "=");
|
|
|
strcpy(retstr, ptr + 1);
|
|
|
|
|
|
end = strlen(retstr) - 1;
|
|
|
if(retstr[end] == '\\')
|
|
|
{
|
|
|
retstr[end] = 0;
|
|
|
for(; ;)
|
|
|
{
|
|
|
if(DSfgets(fstring, sizeof(fstring)-1, hFile) == NULL)
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
iReadLines++;
|
|
|
DSAddSectionLines(1, hFile);
|
|
|
|
|
|
if(StringCutSpace(fstring) == 0)
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
if((fstring[0] == '[') && (strstr(fstring,"]") != NULL))
|
|
|
{
|
|
|
iReadLines--;
|
|
|
DSSubSectionLines(1, hFile);
|
|
|
DSSetSectionLinesAddFlag(0, hFile);
|
|
|
if(!DSSectionisOver(iReadLines, hFile))
|
|
|
{
|
|
|
DSRestoreSectionOffset(hFile);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
end = strlen(fstring) - 1;
|
|
|
if(fstring[end] != '\\')
|
|
|
{
|
|
|
if((strlen(retstr)+strlen(fstring)) < sizeof(retstr))
|
|
|
{
|
|
|
strcat(retstr, fstring);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
fstring[end] = 0;
|
|
|
if((strlen(retstr)+strlen(fstring)) < sizeof(retstr))
|
|
|
{
|
|
|
strcat(retstr, fstring);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if((int)strlen(retstr) >= rlen)
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// <20>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD>ʵ<EFBFBD>ƥ<EFBFBD><C6A5><EFBFBD>ֱ<EEA3AC><D6B1><EFBFBD>˳<EFBFBD>
|
|
|
retstr[rlen] = 0;
|
|
|
strcpy(result, retstr);
|
|
|
goto ExitFlag2;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// û<><C3BB><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD>Ŀ<EFBFBD><C4BF>ʹ<EFBFBD><CAB9>ȱʡֵ
|
|
|
|
|
|
ExitFlag2:
|
|
|
#if 0
|
|
|
fp = fopen(szfilename, "ab");
|
|
|
if(fp)
|
|
|
{
|
|
|
fwrite("#####end#####\r\n", 1, strlen("#####end#####\r\n"), fp);
|
|
|
fclose(fp);
|
|
|
}
|
|
|
#endif
|
|
|
return strlen(result);
|
|
|
}
|
|
|
|
|
|
int GetPrivateProInt2(const char *section, const char *entry, int idefault, HDSFILE hFile)
|
|
|
{
|
|
|
int i, ilen, iRetVal;
|
|
|
char szResult[128];
|
|
|
|
|
|
memset(szResult, 0, sizeof(szResult));
|
|
|
ilen = GetPrivateProString2(section, entry, "", szResult, sizeof(szResult)-1, hFile);
|
|
|
if(ilen <= 0)
|
|
|
{
|
|
|
iRetVal = idefault;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if(ilen > 2)
|
|
|
{
|
|
|
if((szResult[0]=='0') && ((szResult[1]=='x') || (szResult[1]=='X')))
|
|
|
{
|
|
|
iRetVal = 0;
|
|
|
for(i=2; i<ilen; i++)
|
|
|
{
|
|
|
iRetVal = (iRetVal << 4) + HexCharToInt(szResult[i]);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//iRetVal = atoul(szResult);
|
|
|
iRetVal = atoi(szResult);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//iRetVal = atoul(szResult);
|
|
|
iRetVal = atoi(szResult);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return iRetVal;
|
|
|
}
|
|
|
|
|
|
int PutDataToBuf(DATA_BUF *buf, u_char *msg, int len)
|
|
|
{
|
|
|
int j;
|
|
|
|
|
|
if (len == 0)
|
|
|
return 0;
|
|
|
|
|
|
if ((buf->BufSize - buf->MsgCnt) < len)
|
|
|
return 0;
|
|
|
|
|
|
if (buf->MsgCnt == 0)
|
|
|
{
|
|
|
buf->Front = 0;
|
|
|
buf->Rear = 0;
|
|
|
}
|
|
|
|
|
|
j = buf->BufSize - buf->Rear;
|
|
|
if (j >= len)
|
|
|
{
|
|
|
memmove((char*)&buf->MsgData[buf->Rear], msg, len);
|
|
|
buf->Rear += len;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
memmove((char*)&buf->MsgData[buf->Rear], msg, j);
|
|
|
buf->Rear = (buf->Rear + j) % buf->BufSize;
|
|
|
memmove((char*)&buf->MsgData[buf->Rear], (char*)&msg[j], len - j);
|
|
|
buf->Rear = (buf->Rear + len - j) % buf->BufSize;
|
|
|
}
|
|
|
buf->MsgCnt += len;
|
|
|
|
|
|
return len;
|
|
|
}
|
|
|
|
|
|
int GetDataFormBuf(DATA_BUF *databuf, u_char *buf, int len, int clrflag)
|
|
|
{
|
|
|
int tmp, rdcnt;
|
|
|
|
|
|
buf[0] = 0;
|
|
|
if (databuf->MsgCnt == 0)
|
|
|
return 0;
|
|
|
|
|
|
rdcnt = min(databuf->MsgCnt, len);
|
|
|
if((databuf->BufSize - databuf->Front) >= rdcnt)
|
|
|
{
|
|
|
memmove((char *)buf, (char *)&databuf->MsgData[databuf->Front], rdcnt);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
tmp = databuf->BufSize - databuf->Front;
|
|
|
memmove((char *)buf, (char *)&databuf->MsgData[databuf->Front], tmp);
|
|
|
memmove((char *)&buf[tmp], (char *)&databuf->MsgData[0], rdcnt - tmp);
|
|
|
}
|
|
|
|
|
|
if (clrflag)
|
|
|
{
|
|
|
databuf->Front = (databuf->Front + rdcnt) % databuf->BufSize;
|
|
|
databuf->MsgCnt -= rdcnt;
|
|
|
}
|
|
|
|
|
|
return rdcnt;
|
|
|
}
|
|
|
|
|
|
void GetCommMode(int port, u_char *str)
|
|
|
{
|
|
|
char *ptr;
|
|
|
|
|
|
StringCutSpace((char*)str);
|
|
|
if (strlen((char*)str) == 0)
|
|
|
return;
|
|
|
|
|
|
SioParam[port].m_psSerial->Baud = atoi((char*)str);
|
|
|
|
|
|
ptr = strstr((char*)str, ",");
|
|
|
ptr++;
|
|
|
switch(*ptr)
|
|
|
{
|
|
|
case 'o':
|
|
|
case 'O': // <20><>У<EFBFBD><D0A3>
|
|
|
SioParam[port].m_psSerial->CommMode &= ~PARITYMASK;
|
|
|
SioParam[port].m_psSerial->CommMode |= PARITYODD;
|
|
|
break;
|
|
|
case 'e':
|
|
|
case 'E': // <20><>У<EFBFBD><D0A3>
|
|
|
SioParam[port].m_psSerial->CommMode &= ~PARITYMASK;
|
|
|
SioParam[port].m_psSerial->CommMode |= PARITYEVE;
|
|
|
break;
|
|
|
default: // <20><>У<EFBFBD><D0A3>
|
|
|
SioParam[port].m_psSerial->CommMode &= ~PARITYMASK;
|
|
|
SioParam[port].m_psSerial->CommMode |= PARITYNONE;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
ptr = strstr(ptr, ",");
|
|
|
ptr++;
|
|
|
switch(*ptr)
|
|
|
{
|
|
|
case '5':
|
|
|
SioParam[port].m_psSerial->CommMode &= ~BITMASK;
|
|
|
SioParam[port].m_psSerial->CommMode |= BIT5;
|
|
|
break;
|
|
|
case '6':
|
|
|
SioParam[port].m_psSerial->CommMode &= ~BITMASK;
|
|
|
SioParam[port].m_psSerial->CommMode |= BIT6;
|
|
|
break;
|
|
|
case '7':
|
|
|
SioParam[port].m_psSerial->CommMode &= ~BITMASK;
|
|
|
SioParam[port].m_psSerial->CommMode |= BIT7;
|
|
|
break;
|
|
|
default:
|
|
|
SioParam[port].m_psSerial->CommMode &= ~BITMASK;
|
|
|
SioParam[port].m_psSerial->CommMode |= BIT8;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
switch(str[strlen((char*)str)-1])
|
|
|
{
|
|
|
case '1':
|
|
|
SioParam[port].m_psSerial->CommMode &= ~STOPMASK;
|
|
|
SioParam[port].m_psSerial->CommMode |= STOP1;
|
|
|
break;
|
|
|
case '5':
|
|
|
SioParam[port].m_psSerial->CommMode &= ~STOPMASK;
|
|
|
SioParam[port].m_psSerial->CommMode |= STOP15;
|
|
|
break;
|
|
|
case '2':
|
|
|
SioParam[port].m_psSerial->CommMode &= ~STOPMASK;
|
|
|
SioParam[port].m_psSerial->CommMode |= STOP2;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
int GetPortProtocolIdx(char *name)
|
|
|
{
|
|
|
int i;
|
|
|
|
|
|
for (i = 0; ; i++)
|
|
|
{
|
|
|
if (FunCallPtr[i].ProtocolName == 0)
|
|
|
break;
|
|
|
|
|
|
if (CmpString((u_char*)FunCallPtr[i].ProtocolName, (u_char*)name))
|
|
|
{
|
|
|
return i;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
char *GetPortProtocolName(int Idx)
|
|
|
{
|
|
|
int i;
|
|
|
|
|
|
for(i=0; i<=Idx; i++)
|
|
|
{
|
|
|
if(FunCallPtr[i].ProtocolName == 0)
|
|
|
break;
|
|
|
|
|
|
if(i == Idx)
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if(FunCallPtr[i].ProtocolName == 0)
|
|
|
{
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
return FunCallPtr[i].ProtocolName;
|
|
|
}
|
|
|
|
|
|
void ReadPortConfigInfo(u_short netport)
|
|
|
{
|
|
|
int i, j;
|
|
|
char *ptr;
|
|
|
|
|
|
char entry[256], szbuf[128];
|
|
|
|
|
|
MaxSerialPortNum = DEFAULT_MAX_SERIAL_PORT_NUM;
|
|
|
MaxNetPortNum = netport;
|
|
|
if (MaxNetPortNum > DEFAULT_MAX_NET_PORT_NUM)
|
|
|
MaxNetPortNum = DEFAULT_MAX_NET_PORT_NUM;
|
|
|
|
|
|
MaxPortNum = MaxSerialPortNum + MaxNetPortNum;
|
|
|
|
|
|
char szConfig[256], szPortConfig[256];
|
|
|
//GetCurrentDirectory(sizeof(szDir), szDir);
|
|
|
sprintf(szConfig, "%s/config.ini", IniFilePath);
|
|
|
sprintf(szPortConfig, "%s/portconfig.ini", IniFilePath);
|
|
|
//GetPrivateProString("NetCommPort", "UdpCommPort", "", szbuf, 120, "./config.ini");
|
|
|
GetPrivateProString("NetCommPort", "UdpCommPort", "", szbuf, 120, szConfig);
|
|
|
|
|
|
if (strlen(szbuf))
|
|
|
UdpCommPort = (u_short)atoul(szbuf);
|
|
|
else
|
|
|
UdpCommPort = DEFAULT_UDP_COMM_PORT;
|
|
|
|
|
|
#ifdef _OS_WINDOWS_DEBUG_
|
|
|
SYSTEMTIME sm;
|
|
|
GetLocalTime(&sm);
|
|
|
#endif
|
|
|
|
|
|
memset((char*)SioParam, 0, sizeof(SIO_PARAM_DEF)*MaxPortNum);
|
|
|
// <20><><EFBFBD>˿<EFBFBD><CBBF><EFBFBD>Ϣ
|
|
|
for (i = 0; i < MaxPortNum; i++)
|
|
|
{
|
|
|
// wen test debug
|
|
|
#ifdef _OS_WINDOWS_DEBUG_
|
|
|
//sprintf(szbuf, "<22><>ʼ<EFBFBD><CABC><EFBFBD>˿<EFBFBD>%d... ...\n", i+1);
|
|
|
sprintf(szbuf, "%02d_%02d:%02d:%02d.%03d <20><>ʼ<EFBFBD><CABC><EFBFBD>˿<EFBFBD>%d... ...\n", sm.wDay, sm.wHour,
|
|
|
sm.wMinute, sm.wSecond, sm.wMilliseconds, i+1);
|
|
|
OutputDebugString((LPCWSTR)szbuf);
|
|
|
#elif _OS_WINDOWS_DEBUG_
|
|
|
printf("<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD>%d... ...\n", i+1);
|
|
|
#endif
|
|
|
|
|
|
SioParam[i].m_psBaoHu = (SIO_PARAM_BAOHU_DEF *)malloc(sizeof(SIO_PARAM_BAOHU_DEF));
|
|
|
memset((void *)SioParam[i].m_psBaoHu, 0, sizeof(SIO_PARAM_BAOHU_DEF));
|
|
|
|
|
|
SioParam[i].m_psSerial = (SIO_PARAM_SERIAL_DEF *)malloc(sizeof(SIO_PARAM_SERIAL_DEF));
|
|
|
memset((void *)SioParam[i].m_psSerial, 0, sizeof(SIO_PARAM_SERIAL_DEF));
|
|
|
|
|
|
SioParam[i].RecvBuf.BufSize = MAX_MSG_BUF_SIZE;
|
|
|
for (j = 0; j < POLL_CMD_TYPE_NUM; j++)
|
|
|
SioParam[i].m_psBaoHu->PollCmd[j].BufSize = MAX_MSG_BUF_SIZE;
|
|
|
|
|
|
sprintf(entry, "Port%d", i+1);
|
|
|
GetPrivateProString(entry, "Protocol", "", szbuf, 120, szPortConfig);
|
|
|
SioParam[i].ProtocolIdx = GetPortProtocolIdx(szbuf);
|
|
|
|
|
|
StringToUpper(szbuf);
|
|
|
SioParam[i].ByPassFlag = CmpString((u_char*)szbuf, (u_char*)"bypass");
|
|
|
|
|
|
// <20><><EFBFBD>ж˿<D0B6>
|
|
|
if (i < MaxSerialPortNum)
|
|
|
{
|
|
|
SioParam[i].m_psSerial->Baud = DEFAULT_BAUD;
|
|
|
SioParam[i].m_psSerial->CommMode = BIT8 | STOP1 | PARITYNONE;
|
|
|
SioParam[i].m_psSerial->WorkMode = RS232_COMM_MODE;
|
|
|
SioParam[i].m_psSerial->HandshakeMode = NO_HANDSHAKE_MODE;
|
|
|
|
|
|
SioParam[i].m_psSerial->ChSelect = 0;
|
|
|
SioParam[i].m_psSerial->FreqSelect = 0;
|
|
|
SioParam[i].m_psSerial->ChipCheckOk = 1;
|
|
|
|
|
|
GetPrivateProString("PortConfig", entry, "", szbuf, 16, szConfig);
|
|
|
if (strlen(szbuf))
|
|
|
{
|
|
|
SioParam[i].m_psSerial->ChSelect = atoi(szbuf);
|
|
|
ptr = strstr(szbuf, ",");
|
|
|
if (ptr)
|
|
|
{
|
|
|
ptr++;
|
|
|
SioParam[i].m_psSerial->FreqSelect = atoi(ptr);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
GetPrivateProString(entry, "CommMode", "", szbuf, 120, szPortConfig);
|
|
|
GetCommMode(i, (u_char*)szbuf);
|
|
|
|
|
|
GetPrivateProString(entry, "WorkMode", "", szbuf, 120, szPortConfig);
|
|
|
StringCutSpace(szbuf);
|
|
|
if (strstr(szbuf, "422"))
|
|
|
SioParam[i].m_psSerial->WorkMode = RS422_COMM_MODE;
|
|
|
if (strstr(szbuf, "485"))
|
|
|
SioParam[i].m_psSerial->WorkMode = RS485_COMM_MODE;
|
|
|
|
|
|
GetPrivateProString(entry, "HandshakeMode", "", szbuf, 120, szPortConfig);
|
|
|
StringCutSpace(szbuf);
|
|
|
StringToLower(szbuf);
|
|
|
if (strstr(szbuf, "HARDWARE"))
|
|
|
SioParam[i].m_psSerial->HandshakeMode = HARDWARE_MODE;
|
|
|
if (strstr(szbuf, "SOFTWARE"))
|
|
|
SioParam[i].m_psSerial->HandshakeMode = SOFTWARE_MODE;
|
|
|
|
|
|
GetPrivateProString(entry, "XonXoff", "",szbuf, 120, szPortConfig);
|
|
|
SioParam[i].m_psSerial->XonChar1 = HexCharToInt(szbuf[0]) * 16 + HexCharToInt(szbuf[1]);
|
|
|
SioParam[i].m_psSerial->XoffChar1 = HexCharToInt(szbuf[2]) * 16 + HexCharToInt(szbuf[3]);
|
|
|
SioParam[i].m_psSerial->XonChar2 = SioParam[i].m_psSerial->XonChar1;
|
|
|
SioParam[i].m_psSerial->XoffChar2 = SioParam[i].m_psSerial->XoffChar1;
|
|
|
|
|
|
// <20><>Ƕ<EFBFBD><C7B6>ʽϵͳ<CFB5>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>Ľ<EFBFBD><C4BD>̣<EFBFBD><CCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>ʱ<EFBFBD><CAB1>
|
|
|
// <20>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD>ͨѶ<CDA8>д<EFBFBD><D0B4>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̲<EFBFBD><CCB2><EFBFBD><EFBFBD>д<EFBFBD>
|
|
|
// <20><>ͨѶָ<D1B6><D6B8><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>¸<EFBFBD>ֵһ<D6B5>Ρ<EFBFBD>
|
|
|
SioParam[i].m_psBaoHu->Baud = SioParam[i].m_psSerial->Baud;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
SioParam[i].NetType = NO_COMM;
|
|
|
SioParam[i].m_psBaoHu->Baud = DEFAULT_BAUD;
|
|
|
|
|
|
GetPrivateProString(entry, "NetPort", "", szbuf, 120, szPortConfig);
|
|
|
StringToLower(szbuf);
|
|
|
if ((szbuf[0] == '0') && (szbuf[1] == 'X'))
|
|
|
{
|
|
|
SioParam[i].NetPort = (HexCharToInt(szbuf[2]) << 12)
|
|
|
| (HexCharToInt(szbuf[3]) << 8)
|
|
|
| (HexCharToInt(szbuf[4]) << 4)
|
|
|
| HexCharToInt(szbuf[5]);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
SioParam[i].NetPort = atoi(szbuf);
|
|
|
}
|
|
|
if (SioParam[i].NetPort == 0)
|
|
|
continue;
|
|
|
|
|
|
GetPrivateProString(entry, "NetCommAddr", "", szbuf, 120, szPortConfig);
|
|
|
SioParam[i].NetCommIpAddr = inet_addr(szbuf);
|
|
|
|
|
|
if ((SioParam[i].NetPort == 0) || (SioParam[i].NetCommIpAddr == 0))
|
|
|
{
|
|
|
SioParam[i].NetPort = 0;
|
|
|
SioParam[i].NetCommIpAddr = 0;
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
GetPrivateProString(entry, "NetCommMode", "", szbuf, 120, szPortConfig);
|
|
|
StringCutSpace(szbuf);
|
|
|
if (strlen(szbuf) == 0)
|
|
|
continue;
|
|
|
|
|
|
StringToLower(szbuf);
|
|
|
if (strstr(szbuf, "UDP"))
|
|
|
SioParam[i].NetType = UDP_COMM;
|
|
|
|
|
|
if (strstr(szbuf, "TCP,SERVER"))
|
|
|
SioParam[i].NetType = TCP_S_COMM;
|
|
|
|
|
|
if (strstr(szbuf, "TCP,CLIENT"))
|
|
|
SioParam[i].NetType = TCP_C_COMM;
|
|
|
}
|
|
|
|
|
|
// <20><><EFBFBD>˿ڲ<CBBF><DAB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
GetPrivateProString(entry, "AiNum", "0", szbuf, 120, szPortConfig);
|
|
|
SioParam[i].m_psBaoHu->AiNum = atoi(szbuf);
|
|
|
GetPrivateProString(entry, "DiNum", "0", szbuf, 120, szPortConfig);
|
|
|
SioParam[i].m_psBaoHu->DiNum = atoi(szbuf);
|
|
|
GetPrivateProString(entry, "PiNum", "0", szbuf, 120, szPortConfig);
|
|
|
SioParam[i].m_psBaoHu->PiNum = atoi(szbuf);
|
|
|
|
|
|
// <20><> Poll Command ʱ<>䳣<EFBFBD><E4B3A3>
|
|
|
GetPrivateProString(entry, "Retry", "", szbuf, 120, szPortConfig);
|
|
|
SioParam[i].m_psBaoHu->Retry = (u_long)atoi(szbuf);
|
|
|
GetPrivateProString(entry, "RetryTime", "3", szbuf, 120, szPortConfig);
|
|
|
SioParam[i].m_psBaoHu->RetryTime = (u_long)((atof(szbuf) * 1000) / TIMER_CNT);
|
|
|
GetPrivateProString(entry, "WaitTime", "", szbuf, 120, szPortConfig);
|
|
|
SioParam[i].m_psBaoHu->WaitTime = (u_long)((atof(szbuf) * 1000) / TIMER_CNT);
|
|
|
|
|
|
// wen 2004.10.26 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD>(<28>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD>ɽ<EFBFBD><C9BD>չ<EFBFBD>Լ<EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD>)
|
|
|
//PortMemoryMalloc(i, RECV_PROTOCOL);
|
|
|
GetPrivateProString(entry, "PortType", "0", szbuf, 120, szPortConfig);
|
|
|
SioParam[i].m_psBaoHu->PortType = (u_char)atoi(szbuf);
|
|
|
GetPrivateProString(entry, "CheckTime", "no", szbuf, 120, szPortConfig);
|
|
|
if(_stricmp(szbuf, "up") == 0)
|
|
|
SioParam[i].m_psBaoHu->CheckTime = 1;
|
|
|
else if(_stricmp(szbuf, "down") == 0)
|
|
|
SioParam[i].m_psBaoHu->CheckTime = 2;
|
|
|
else
|
|
|
SioParam[i].m_psBaoHu->CheckTime = 0;
|
|
|
|
|
|
// wen 2005.03.01 <20><><EFBFBD><EFBFBD>ң<EFBFBD><D2A3>ң<EFBFBD><D2A3>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
//"ProvYkYtTimeOut"="ת<><D7AA>ң<EFBFBD>س<EFBFBD>ʱʱ<CAB1><CAB1>"
|
|
|
GetPrivateProfileString((LPWSTR)entry, (LPWSTR)"ProvYkYtTimeOut", (LPWSTR)"10", (LPWSTR)szbuf, 120, (LPWSTR)szPortConfig);
|
|
|
SioParam[i].m_psBaoHu->ProvYkYtMsg.m_iTimeOut = atoi(szbuf);
|
|
|
|
|
|
#ifdef _OS_WINDOWS_DEBUG_
|
|
|
GetLocalTime(&sm);
|
|
|
sprintf(szbuf, "%02d_%02d:%02d:%02d.%03d <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD>%d<><64>ʼ\n", sm.wDay, sm.wHour,
|
|
|
sm.wMinute, sm.wSecond, sm.wMilliseconds, i+1);
|
|
|
OutputDebugString((LPCWSTR)szbuf);
|
|
|
#endif
|
|
|
// <20><><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD>
|
|
|
PortMemoryMalloc(i, SioParam[i].m_psBaoHu->PortType, SioParam[i].m_psBaoHu);
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD>
|
|
|
if (FunCallPtr[SioParam[i].ProtocolIdx].ReadConfig)
|
|
|
{
|
|
|
FunCallPtr[SioParam[i].ProtocolIdx].ReadConfig(i);
|
|
|
}
|
|
|
|
|
|
#ifdef _OS_WINDOWS_DEBUG_
|
|
|
GetLocalTime(&sm);
|
|
|
// wen test debug
|
|
|
//sprintf(szbuf, "<22><>ʼ<EFBFBD><CABC><EFBFBD>˿<EFBFBD>%d<>ɹ<EFBFBD>\n", i+1);
|
|
|
sprintf(szbuf, "%02d_%02d:%02d:%02d.%03d <20><>ʼ<EFBFBD><CABC><EFBFBD>˿<EFBFBD>%d<>ɹ<EFBFBD>\n", sm.wDay, sm.wHour,
|
|
|
sm.wMinute, sm.wSecond, sm.wMilliseconds, i+1);
|
|
|
OutputDebugString((LPCWSTR)szbuf);
|
|
|
OutputDebugString((LPCWSTR)"\n");
|
|
|
#elif _OS_WINDOWS_DEBUG_
|
|
|
printf("<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD>%d<>ɹ<EFBFBD>\n", i+1);
|
|
|
#endif
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void ReadPortConfigInfoEx(u_short netport)
|
|
|
{
|
|
|
int i, j;
|
|
|
char *ptr;
|
|
|
|
|
|
char entry[256], szbuf[128];
|
|
|
|
|
|
MaxSerialPortNum = DEFAULT_MAX_SERIAL_PORT_NUM;
|
|
|
MaxNetPortNum = netport;
|
|
|
if (MaxNetPortNum > DEFAULT_MAX_NET_PORT_NUM)
|
|
|
MaxNetPortNum = DEFAULT_MAX_NET_PORT_NUM;
|
|
|
|
|
|
MaxPortNum = MaxSerialPortNum + MaxNetPortNum;
|
|
|
|
|
|
char szConfig[256], szPortConfig[256];
|
|
|
//GetCurrentDirectory(sizeof(szDir), szDir);
|
|
|
sprintf(szConfig, "%s/config.ini", IniFilePath);
|
|
|
sprintf(szPortConfig, "%s/portconfig.ini", IniFilePath);
|
|
|
//GetPrivateProString("NetCommPort", "UdpCommPort", "", szbuf, 120, "./config.ini");
|
|
|
GetPrivateProString("NetCommPort", "UdpCommPort", "", szbuf, 120, szConfig);
|
|
|
|
|
|
if (strlen(szbuf))
|
|
|
UdpCommPort = (u_short)atoul(szbuf);
|
|
|
else
|
|
|
UdpCommPort = DEFAULT_UDP_COMM_PORT;
|
|
|
|
|
|
#ifdef _OS_WINDOWS_DEBUG_
|
|
|
SYSTEMTIME sm;
|
|
|
GetLocalTime(&sm);
|
|
|
#endif
|
|
|
|
|
|
memset((char*)SioParam, 0, sizeof(SIO_PARAM_DEF)*MaxPortNum);
|
|
|
// <20><><EFBFBD>˿<EFBFBD><CBBF><EFBFBD>Ϣ
|
|
|
for (i = 0; i < MaxPortNum; i++)
|
|
|
{
|
|
|
// wen test debug
|
|
|
#ifdef _OS_WINDOWS_DEBUG_
|
|
|
//sprintf(szbuf, "<22><>ʼ<EFBFBD><CABC><EFBFBD>˿<EFBFBD>%d... ...\n", i+1);
|
|
|
sprintf(szbuf, "%02d_%02d:%02d:%02d.%03d <20><>ʼ<EFBFBD><CABC><EFBFBD>˿<EFBFBD>%d... ...\n", sm.wDay, sm.wHour,
|
|
|
sm.wMinute, sm.wSecond, sm.wMilliseconds, i+1);
|
|
|
OutputDebugString((LPCWSTR)szbuf);
|
|
|
#elif _OS_WINDOWS_DEBUG_
|
|
|
printf("<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD>%d... ...\n", i+1);
|
|
|
#endif
|
|
|
|
|
|
SioParam[i].m_psBaoHu = (SIO_PARAM_BAOHU_DEF *)malloc(sizeof(SIO_PARAM_BAOHU_DEF));
|
|
|
memset((void *)SioParam[i].m_psBaoHu, 0, sizeof(SIO_PARAM_BAOHU_DEF));
|
|
|
|
|
|
SioParam[i].m_psSerial = (SIO_PARAM_SERIAL_DEF *)malloc(sizeof(SIO_PARAM_SERIAL_DEF));
|
|
|
memset((void *)SioParam[i].m_psSerial, 0, sizeof(SIO_PARAM_SERIAL_DEF));
|
|
|
|
|
|
SioParam[i].RecvBuf.BufSize = MAX_MSG_BUF_SIZE;
|
|
|
for (j = 0; j < POLL_CMD_TYPE_NUM; j++)
|
|
|
SioParam[i].m_psBaoHu->PollCmd[j].BufSize = MAX_MSG_BUF_SIZE;
|
|
|
|
|
|
sprintf(entry, "Port%d", i+1);
|
|
|
GetPrivateProString(entry, "Protocol", "", szbuf, 120, szPortConfig);
|
|
|
SioParam[i].ProtocolIdx = GetPortProtocolIdx(szbuf);
|
|
|
|
|
|
StringToUpper(szbuf);
|
|
|
SioParam[i].ByPassFlag = CmpString((u_char*)szbuf, (u_char*)"bypass");
|
|
|
|
|
|
// <20><><EFBFBD>ж˿<D0B6>
|
|
|
if (i < MaxSerialPortNum)
|
|
|
{
|
|
|
SioParam[i].m_psSerial->Baud = DEFAULT_BAUD;
|
|
|
SioParam[i].m_psSerial->CommMode = BIT8 | STOP1 | PARITYNONE;
|
|
|
SioParam[i].m_psSerial->WorkMode = RS232_COMM_MODE;
|
|
|
SioParam[i].m_psSerial->HandshakeMode = NO_HANDSHAKE_MODE;
|
|
|
|
|
|
SioParam[i].m_psSerial->ChSelect = 0;
|
|
|
SioParam[i].m_psSerial->FreqSelect = 0;
|
|
|
SioParam[i].m_psSerial->ChipCheckOk = 1;
|
|
|
|
|
|
GetPrivateProString("PortConfig", entry, "", szbuf, 16, szConfig);
|
|
|
if (strlen(szbuf))
|
|
|
{
|
|
|
SioParam[i].m_psSerial->ChSelect = atoi(szbuf);
|
|
|
ptr = strstr(szbuf, ",");
|
|
|
if (ptr)
|
|
|
{
|
|
|
ptr++;
|
|
|
SioParam[i].m_psSerial->FreqSelect = atoi(ptr);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
GetPrivateProString(entry, "CommMode", "", szbuf, 120, szPortConfig);
|
|
|
GetCommMode(i, (u_char*)szbuf);
|
|
|
|
|
|
GetPrivateProString(entry, "WorkMode", "", szbuf, 120, szPortConfig);
|
|
|
StringCutSpace(szbuf);
|
|
|
if (strstr(szbuf, "422"))
|
|
|
SioParam[i].m_psSerial->WorkMode = RS422_COMM_MODE;
|
|
|
if (strstr(szbuf, "485"))
|
|
|
SioParam[i].m_psSerial->WorkMode = RS485_COMM_MODE;
|
|
|
|
|
|
GetPrivateProString(entry, "HandshakeMode", "", szbuf, 120, szPortConfig);
|
|
|
StringCutSpace(szbuf);
|
|
|
StringToLower(szbuf);
|
|
|
if (strstr(szbuf, "HARDWARE"))
|
|
|
SioParam[i].m_psSerial->HandshakeMode = HARDWARE_MODE;
|
|
|
if (strstr(szbuf, "SOFTWARE"))
|
|
|
SioParam[i].m_psSerial->HandshakeMode = SOFTWARE_MODE;
|
|
|
|
|
|
GetPrivateProString(entry, "XonXoff", "",szbuf, 120, szPortConfig);
|
|
|
SioParam[i].m_psSerial->XonChar1 = HexCharToInt(szbuf[0]) * 16 + HexCharToInt(szbuf[1]);
|
|
|
SioParam[i].m_psSerial->XoffChar1 = HexCharToInt(szbuf[2]) * 16 + HexCharToInt(szbuf[3]);
|
|
|
SioParam[i].m_psSerial->XonChar2 = SioParam[i].m_psSerial->XonChar1;
|
|
|
SioParam[i].m_psSerial->XoffChar2 = SioParam[i].m_psSerial->XoffChar1;
|
|
|
|
|
|
// <20><>Ƕ<EFBFBD><C7B6>ʽϵͳ<CFB5>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>Ľ<EFBFBD><C4BD>̣<EFBFBD><CCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>ʱ<EFBFBD><CAB1>
|
|
|
// <20>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD>ͨѶ<CDA8>д<EFBFBD><D0B4>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̲<EFBFBD><CCB2><EFBFBD><EFBFBD>д<EFBFBD>
|
|
|
// <20><>ͨѶָ<D1B6><D6B8><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>¸<EFBFBD>ֵһ<D6B5>Ρ<EFBFBD>
|
|
|
SioParam[i].m_psBaoHu->Baud = SioParam[i].m_psSerial->Baud;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
SioParam[i].NetType = NO_COMM;
|
|
|
SioParam[i].m_psBaoHu->Baud = DEFAULT_BAUD;
|
|
|
SioParam[i].CommSock = -1;
|
|
|
SioParam[i].LiSock = -1;
|
|
|
|
|
|
GetPrivateProString(entry, "NetPort", "", szbuf, 120, szPortConfig);
|
|
|
StringToLower(szbuf);
|
|
|
if ((szbuf[0] == '0') && (szbuf[1] == 'X'))
|
|
|
{
|
|
|
SioParam[i].NetPort = (HexCharToInt(szbuf[2]) << 12)
|
|
|
| (HexCharToInt(szbuf[3]) << 8)
|
|
|
| (HexCharToInt(szbuf[4]) << 4)
|
|
|
| HexCharToInt(szbuf[5]);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
SioParam[i].NetPort = atoi(szbuf);
|
|
|
}
|
|
|
if (SioParam[i].NetPort == 0)
|
|
|
{
|
|
|
//continue;
|
|
|
goto mallocdbflag;
|
|
|
}
|
|
|
|
|
|
GetPrivateProString(entry, "NetCommAddr", "", szbuf, 120, szPortConfig);
|
|
|
SioParam[i].NetCommIpAddr = inet_addr(szbuf);
|
|
|
|
|
|
if ((SioParam[i].NetPort == 0) || (SioParam[i].NetCommIpAddr == 0))
|
|
|
{
|
|
|
SioParam[i].NetPort = 0;
|
|
|
SioParam[i].NetCommIpAddr = 0;
|
|
|
//continue;
|
|
|
goto mallocdbflag;
|
|
|
}
|
|
|
|
|
|
GetPrivateProString(entry, "NetCommMode", "", szbuf, 120, szPortConfig);
|
|
|
StringCutSpace(szbuf);
|
|
|
if(strlen(szbuf) == 0)
|
|
|
{
|
|
|
//continue;
|
|
|
goto mallocdbflag;
|
|
|
}
|
|
|
|
|
|
StringToUpper(szbuf);
|
|
|
if (strstr(szbuf, "UDP"))
|
|
|
SioParam[i].NetType = UDP_COMM;
|
|
|
|
|
|
if (strstr(szbuf, "TCP,SERVER"))
|
|
|
SioParam[i].NetType = TCP_S_COMM;
|
|
|
|
|
|
if (strstr(szbuf, "TCP,CLIENT"))
|
|
|
SioParam[i].NetType = TCP_C_COMM;
|
|
|
}
|
|
|
|
|
|
mallocdbflag:
|
|
|
|
|
|
// <20><><EFBFBD>˿ڲ<CBBF><DAB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
GetPrivateProString(entry, "AiNum", "0", szbuf, 120, szPortConfig);
|
|
|
SioParam[i].m_psBaoHu->AiNum = atoi(szbuf);
|
|
|
GetPrivateProString(entry, "DiNum", "0", szbuf, 120, szPortConfig);
|
|
|
SioParam[i].m_psBaoHu->DiNum = atoi(szbuf);
|
|
|
GetPrivateProString(entry, "PiNum", "0", szbuf, 120, szPortConfig);
|
|
|
SioParam[i].m_psBaoHu->PiNum = atoi(szbuf);
|
|
|
|
|
|
// <20><> Poll Command ʱ<>䳣<EFBFBD><E4B3A3>
|
|
|
GetPrivateProString(entry, "Retry", "", szbuf, 120, szPortConfig);
|
|
|
SioParam[i].m_psBaoHu->Retry = (u_long)atoi(szbuf);
|
|
|
GetPrivateProString(entry, "RetryTime", "3", szbuf, 120, szPortConfig);
|
|
|
SioParam[i].m_psBaoHu->RetryTime = (u_long)((atof(szbuf) * 1000) / TIMER_CNT);
|
|
|
GetPrivateProString(entry, "WaitTime", "", szbuf, 120, szPortConfig);
|
|
|
SioParam[i].m_psBaoHu->WaitTime = (u_long)((atof(szbuf) * 1000) / TIMER_CNT);
|
|
|
|
|
|
// wen 2004.10.26 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD>(<28>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD>ɽ<EFBFBD><C9BD>չ<EFBFBD>Լ<EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD>)
|
|
|
//PortMemoryMalloc(i, RECV_PROTOCOL);
|
|
|
GetPrivateProString(entry, "PortType", "0", szbuf, 120, szPortConfig);
|
|
|
SioParam[i].m_psBaoHu->PortType = (u_char)atoi(szbuf);
|
|
|
GetPrivateProString(entry, "CheckTime", "no", szbuf, 120, szPortConfig);
|
|
|
if(_stricmp(szbuf, "up") == 0)
|
|
|
SioParam[i].m_psBaoHu->CheckTime = 1;
|
|
|
else if(_stricmp((const char*)szbuf, "down") == 0)
|
|
|
SioParam[i].m_psBaoHu->CheckTime = 2;
|
|
|
else
|
|
|
SioParam[i].m_psBaoHu->CheckTime = 0;
|
|
|
|
|
|
// wen 2005.03.01 <20><><EFBFBD><EFBFBD>ң<EFBFBD><D2A3>ң<EFBFBD><D2A3>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
//"ProvYkYtTimeOut"="ת<><D7AA>ң<EFBFBD>س<EFBFBD>ʱʱ<CAB1><CAB1>"
|
|
|
GetPrivateProfileString((LPWSTR)entry, (LPWSTR)"ProvYkYtTimeOut", (LPWSTR)"10", (LPWSTR)szbuf, 120, (LPWSTR)szPortConfig);
|
|
|
SioParam[i].m_psBaoHu->ProvYkYtMsg.m_iTimeOut = atoi(szbuf);
|
|
|
|
|
|
#ifdef _OS_WINDOWS_DEBUG_
|
|
|
GetLocalTime(&sm);
|
|
|
sprintf(szbuf, "%02d_%02d:%02d:%02d.%03d <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD>%d<><64>ʼ\n", sm.wDay, sm.wHour,
|
|
|
sm.wMinute, sm.wSecond, sm.wMilliseconds, i+1);
|
|
|
OutputDebugString((LPCWSTR)szbuf);
|
|
|
#endif
|
|
|
// <20><><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD>
|
|
|
PortMemoryMallocEx(i, SioParam[i].m_psBaoHu->PortType, SioParam[i].m_psBaoHu);
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD>
|
|
|
if (FunCallPtr[SioParam[i].ProtocolIdx].ReadConfig)
|
|
|
{
|
|
|
FunCallPtr[SioParam[i].ProtocolIdx].ReadConfig(i);
|
|
|
}
|
|
|
|
|
|
#ifdef _OS_WINDOWS_DEBUG_
|
|
|
GetLocalTime(&sm);
|
|
|
// wen test debug
|
|
|
//sprintf(szbuf, "<22><>ʼ<EFBFBD><CABC><EFBFBD>˿<EFBFBD>%d<>ɹ<EFBFBD>\n", i+1);
|
|
|
sprintf(szbuf, "%02d_%02d:%02d:%02d.%03d <20><>ʼ<EFBFBD><CABC><EFBFBD>˿<EFBFBD>%d<>ɹ<EFBFBD>\n", sm.wDay, sm.wHour,
|
|
|
sm.wMinute, sm.wSecond, sm.wMilliseconds, i+1);
|
|
|
OutputDebugString((LPCWSTR)szbuf);
|
|
|
OutputDebugString((LPCWSTR)"\n");
|
|
|
#elif _OS_WINDOWS_DEBUG_
|
|
|
printf("<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD>%d<>ɹ<EFBFBD>\n", i+1);
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
|
|
|
for(i = 0; i < MaxPortNum; i++)
|
|
|
{
|
|
|
#ifdef _OS_WINDOWS_DEBUG_
|
|
|
//sprintf(szbuf, "<22><>ʼ<EFBFBD><CABC><EFBFBD>˿<EFBFBD>%d... ...\n", i+1);
|
|
|
sprintf(szbuf, "%02d_%02d:%02d:%02d.%03d <20><>ʼ<EFBFBD><CABC><EFBFBD>˿<EFBFBD>%d<><64><EFBFBD>ݿ<EFBFBD>... ...\n", sm.wDay, sm.wHour,
|
|
|
sm.wMinute, sm.wSecond, sm.wMilliseconds, i+1);
|
|
|
OutputDebugString((LPCWSTR)szbuf);
|
|
|
#elif _OS_WINDOWS_DEBUG_
|
|
|
printf("<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD>%d<><64><EFBFBD>ݿ<EFBFBD>... ...\n", i+1);
|
|
|
#endif
|
|
|
PortDataPntInit(i, SioParam[i].m_psBaoHu->PortType, SioParam[i].m_psBaoHu);
|
|
|
|
|
|
#ifdef _OS_WINDOWS_DEBUG_
|
|
|
GetLocalTime(&sm);
|
|
|
// wen test debug
|
|
|
//sprintf(szbuf, "<22><>ʼ<EFBFBD><CABC><EFBFBD>˿<EFBFBD>%d<>ɹ<EFBFBD>\n", i+1);
|
|
|
sprintf(szbuf, "%02d_%02d:%02d:%02d.%03d <20><>ʼ<EFBFBD><CABC><EFBFBD>˿<EFBFBD>%d<><64><EFBFBD>ݿ<EFBFBD><DDBF>ɹ<EFBFBD>\n", sm.wDay, sm.wHour,
|
|
|
sm.wMinute, sm.wSecond, sm.wMilliseconds, i+1);
|
|
|
OutputDebugString((LPCWSTR)szbuf);
|
|
|
OutputDebugString((LPCWSTR)"\n");
|
|
|
#elif _OS_WINDOWS_DEBUG_
|
|
|
printf("<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD>%d<><64><EFBFBD>ݿ<EFBFBD><DDBF>ɹ<EFBFBD>\n", i+1);
|
|
|
#endif
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/*void OpenAllPort(void)
|
|
|
{
|
|
|
int i;
|
|
|
|
|
|
for (i = 0; i < MaxPortNum; i++)
|
|
|
{
|
|
|
//if (SioParam[i].OpenFlag)
|
|
|
if(ShmGetPortFlag(i, FLAG_OPEN))
|
|
|
continue;
|
|
|
|
|
|
if (SioParam[i].ProtocolIdx == 0)
|
|
|
continue;
|
|
|
|
|
|
SioParam[i].OpenFlag = 1;
|
|
|
}
|
|
|
}
|
|
|
*/
|
|
|
void OpenAllPort(void)
|
|
|
{
|
|
|
int i;
|
|
|
|
|
|
// ֻ<><D6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Чʹ<D0A7>õĶ˿ڣ<CBBF><DAA3><EFBFBD>ԼΪ"none"<22><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>Ч<EFBFBD>˿<EFBFBD>
|
|
|
for (i = 0; i < MaxPortNum; i++)
|
|
|
{
|
|
|
//commid = ValidPort[i];
|
|
|
if (ShmGetPortFlag(i, FLAG_OPEN))
|
|
|
continue;
|
|
|
/*if (OPEN_PORT == SioParam[commid].OpenFlag)
|
|
|
{
|
|
|
SioParam[commid].iCreateFailCnt = 0;
|
|
|
continue;
|
|
|
}*/
|
|
|
if (SioParam[i].ProtocolIdx == 0)
|
|
|
continue;
|
|
|
|
|
|
if (i < MaxSerialPortNum)
|
|
|
{
|
|
|
//OpenAllSerialPort(commid);
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
// <20><><EFBFBD>Ӷ˿<D3B6><CBBF><EFBFBD><EFBFBD><EFBFBD>10<31><30><EFBFBD><EFBFBD><EFBFBD>Ӳ<EFBFBD><D3B2>ϵĴ<CFB5><C4B4><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>10<31><30>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
/*if ((SioParam[commid].iCreateFailCnt > 10) && (SioParam[commid].iCreateFailCnt < 120))
|
|
|
{
|
|
|
SioParam[commid].iCreateFailCnt++;
|
|
|
continue;
|
|
|
}
|
|
|
if (SioParam[commid].iCreateFailCnt >= 120)
|
|
|
SioParam[commid].iCreateFailCnt = 0;*/
|
|
|
OpenNetPort(i);
|
|
|
//SioParam[commid].iCreateFailCnt++;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void CloseOnePort(int commid)
|
|
|
{
|
|
|
SioParam[commid].OpenFlag = 0;
|
|
|
|
|
|
// wen 2004.10.26 ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4>ռ<EFBFBD>
|
|
|
//PortMemoryFree(commid);
|
|
|
PortMemoryFree(commid, &SioParam[commid]);
|
|
|
}
|
|
|
|
|
|
void CloseAllPort(void)
|
|
|
{
|
|
|
int i;
|
|
|
|
|
|
for (i = 0; i < MaxPortNum; i++)
|
|
|
CloseOnePort(i);
|
|
|
}
|
|
|
|
|
|
//*******************************************************************
|
|
|
// ͨѶ<CDA8><D1B6><EFBFBD><EFBFBD> *
|
|
|
//*******************************************************************
|
|
|
|
|
|
int SetPntMsg(int port, int point, void *pntmsg, BYTE type, BYTE attr)
|
|
|
{
|
|
|
int i, j, k;
|
|
|
AI_DEF *aiptr, *aipntmsg;
|
|
|
DI_DEF *diptr, *dipntmsg;
|
|
|
PI_DEF *piptr, *pipntmsg;
|
|
|
PROV_AI_PNT *aiprovptr;
|
|
|
PROV_DI_PNT *diprovptr;
|
|
|
PROV_PI_PNT *piprovptr;
|
|
|
SOE_DEF SoeData, *pSoeMsg;
|
|
|
BOOL bRetVal;
|
|
|
|
|
|
bRetVal = false;
|
|
|
if ((port < 0) || (port >= MaxPortNum))
|
|
|
return bRetVal;
|
|
|
|
|
|
if (!IsBaoHuPtr(port))
|
|
|
return bRetVal;
|
|
|
|
|
|
if (RECV_PROTOCOL != SioParam[port].m_psBaoHu->PortType )
|
|
|
return bRetVal;
|
|
|
|
|
|
switch (type)
|
|
|
{
|
|
|
case AI_PNT_TYPE:
|
|
|
if(!SioParam[port].m_psBaoHu->AiPtr)
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
if ((point < 0) || (point >= SioParam[port].m_psBaoHu->AiNum))
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
aipntmsg = (AI_DEF*)pntmsg;
|
|
|
aiptr = (AI_DEF*)SioParam[port].m_psBaoHu->AiPtr;
|
|
|
|
|
|
switch (attr)
|
|
|
{
|
|
|
case PNT_ENABLE:
|
|
|
aiptr[point].Enable = aipntmsg->Enable;
|
|
|
bRetVal = true;
|
|
|
break;
|
|
|
|
|
|
case PNT_STATE:
|
|
|
aiptr[point].State = aipntmsg->State;
|
|
|
bRetVal = true;
|
|
|
break;
|
|
|
|
|
|
case PNT_POLAR:
|
|
|
aiptr[point].Polar = aipntmsg->Polar;
|
|
|
bRetVal = true;
|
|
|
break;
|
|
|
|
|
|
case PNT_RAWVALUE:
|
|
|
//SioParam[port].Status = TRUE;
|
|
|
|
|
|
if (abs((long)(aiptr[point].RawValue - aipntmsg->RawValue)) >= 1)
|
|
|
{
|
|
|
aiptr[point].RawValue = aipntmsg->RawValue;
|
|
|
aiptr[point].State = 1;
|
|
|
// <20><><EFBFBD><EFBFBD>ǰ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
|
|
|
#ifdef FUNCTION_FEND
|
|
|
WriteChangeData(port, point, aipntmsg, AI_PNT_TYPE);
|
|
|
#endif
|
|
|
|
|
|
for (i = 0; i < MAX_PROV_PORT_NUM; i++)
|
|
|
{
|
|
|
if (aiptr[point].Prov[i].Enable == 0)
|
|
|
continue;
|
|
|
|
|
|
j = aiptr[point].Prov[i].PortNo;
|
|
|
k = aiptr[point].Prov[i].PntNo;
|
|
|
if((PROV_PROTOCOL == SioParam[j].m_psBaoHu->PortType)
|
|
|
&& SioParam[j].m_psBaoHu)
|
|
|
{
|
|
|
if(SioParam[j].m_psBaoHu->AiPtr)
|
|
|
{
|
|
|
aiprovptr = (PROV_AI_PNT*)SioParam[j].m_psBaoHu->AiPtr;
|
|
|
aiprovptr[k].ChangeFlag = 1;
|
|
|
// wen 2004.11.19 <20><><EFBFBD><EFBFBD>ң<EFBFBD><D2A3><EFBFBD>仯<EFBFBD><E4BBAF><EFBFBD>ݵĴ<DDB5><C4B4><EFBFBD>
|
|
|
SioParam[j].m_psBaoHu->AiChange = TRUE;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// wen 2004.11.19 <20><><EFBFBD><EFBFBD>ң<EFBFBD><D2A3><EFBFBD>仯<EFBFBD><E4BBAF><EFBFBD>ݵĴ<DDB5><C4B4><EFBFBD>
|
|
|
SioParam[port].m_psBaoHu->AiChange = TRUE;
|
|
|
}
|
|
|
|
|
|
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
// wen 2005.12.15 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>ֵʱ<D6B5><CAB1><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD>˿<EFBFBD>״̬
|
|
|
SioParam[port].LineCommCnt = 0;
|
|
|
SioParam[port].Status = TRUE;
|
|
|
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
bRetVal = true;
|
|
|
break;
|
|
|
|
|
|
case PNT_PROV_MSG:
|
|
|
for (i = 0; i < MAX_PROV_PORT_NUM; i++)
|
|
|
{
|
|
|
if (aiptr[point].Prov[i].Enable == 0)
|
|
|
continue;
|
|
|
|
|
|
if (aiptr[point].Prov[i].PortNo == aipntmsg->Prov[0].PortNo)
|
|
|
{
|
|
|
aiptr[point].Prov[i].PntNo = aipntmsg->Prov[0].PntNo;
|
|
|
aiptr[point].Prov[i].Enable = 1;
|
|
|
bRetVal = true;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if(bRetVal)
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
for (i = 0; i < MAX_PROV_PORT_NUM; i++)
|
|
|
{
|
|
|
if (aiptr[point].Prov[i].Enable)
|
|
|
continue;
|
|
|
|
|
|
aiptr[point].Prov[i].PortNo = aipntmsg->Prov[0].PortNo;
|
|
|
aiptr[point].Prov[i].PntNo = aipntmsg->Prov[0].PntNo;
|
|
|
aiptr[point].Prov[i].Enable = 1;
|
|
|
bRetVal = true;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
case DI_PNT_TYPE:
|
|
|
if (!SioParam[port].m_psBaoHu->DiPtr)
|
|
|
break;
|
|
|
|
|
|
// wen 2005.09.19
|
|
|
if((point < 0) || (point >= SioParam[port].m_psBaoHu->DiNum))
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
dipntmsg = (DI_DEF*)pntmsg;
|
|
|
diptr = (DI_DEF*)SioParam[port].m_psBaoHu->DiPtr;
|
|
|
|
|
|
switch (attr)
|
|
|
{
|
|
|
case PNT_ENABLE:
|
|
|
diptr[point].Enable = dipntmsg->Enable;
|
|
|
bRetVal = true;
|
|
|
break;
|
|
|
|
|
|
case PNT_STATE:
|
|
|
diptr[point].State = dipntmsg->State;
|
|
|
bRetVal = true;
|
|
|
break;
|
|
|
|
|
|
case PNT_SOE_TIME:
|
|
|
memmove((char*)&diptr[point].SoeTime, (char*)&dipntmsg->SoeTime,
|
|
|
sizeof(DAY_TIME));
|
|
|
// wen 2004.11.16 <20><><EFBFBD><EFBFBD>soe<6F><65><EFBFBD>ݵ<EFBFBD>ת<EFBFBD><D7AA><EFBFBD>洢(<28>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>soe<6F><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>???)
|
|
|
memset((void *)&SoeData, 0, sizeof(SOE_DEF));
|
|
|
memcpy((void *)&SoeData.SoeTime, (void*)&dipntmsg->SoeTime,
|
|
|
sizeof(DAY_TIME));
|
|
|
SoeData.bStatus = dipntmsg->Status;
|
|
|
// һ<><D2BB>ΪASDU1, <20><><EFBFBD><EFBFBD>չ<EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
SoeData.u8Type = 1;
|
|
|
for(i=0; i<MAX_PROV_PORT_NUM; i++)
|
|
|
{
|
|
|
if(diptr[point].Prov[i].Enable == 0)
|
|
|
continue;
|
|
|
|
|
|
SoeData.iPntNo = diptr[point].Prov[i].PntNo;
|
|
|
ProvWriteSoeData(diptr[point].Prov[i].PortNo, &SoeData);
|
|
|
}
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>ǰ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
|
|
|
#ifdef FUNCTION_FEND
|
|
|
SoeData.iPntNo = point;
|
|
|
SetSoeData(port, &SoeData);
|
|
|
#endif
|
|
|
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
// wen 2005.12.15 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>ֵʱ<D6B5><CAB1><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD>˿<EFBFBD>״̬
|
|
|
SioParam[port].LineCommCnt = 0;
|
|
|
SioParam[port].Status = TRUE;
|
|
|
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
bRetVal = true;
|
|
|
break;
|
|
|
|
|
|
case PNT_SOE_TIME_EX:
|
|
|
pSoeMsg = (SOE_DEF*)pntmsg;
|
|
|
|
|
|
// test
|
|
|
if(pSoeMsg->SoeTime.Hour == 6)
|
|
|
{
|
|
|
pSoeMsg->SoeTime.Hour = 6;
|
|
|
}
|
|
|
|
|
|
memmove((char *)&diptr[point].SoeTime, (char *)&pSoeMsg->SoeTime,
|
|
|
sizeof(DAY_TIME));
|
|
|
|
|
|
memcpy((void *)&SoeData, (void*)pSoeMsg, sizeof(SOE_DEF));
|
|
|
for(i=0; i<MAX_PROV_PORT_NUM; i++)
|
|
|
{
|
|
|
if(diptr[point].Prov[i].Enable == 0)
|
|
|
continue;
|
|
|
|
|
|
SoeData.iPntNo = diptr[point].Prov[i].PntNo;
|
|
|
ProvWriteSoeData(diptr[point].Prov[i].PortNo, &SoeData);
|
|
|
}
|
|
|
// <20><><EFBFBD><EFBFBD>ǰ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
|
|
|
#ifdef FUNCTION_FEND
|
|
|
SoeData.iPntNo = point;
|
|
|
SetSoeData(port, &SoeData);
|
|
|
#endif
|
|
|
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
// wen 2005.12.15 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>ֵʱ<D6B5><CAB1><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD>˿<EFBFBD>״̬
|
|
|
SioParam[port].LineCommCnt = 0;
|
|
|
SioParam[port].Status = TRUE;
|
|
|
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
bRetVal = true;
|
|
|
break;
|
|
|
|
|
|
case PNT_STATUS:
|
|
|
//SioParam[port].Status = TRUE;
|
|
|
|
|
|
dipntmsg->Status &= 0x01;
|
|
|
|
|
|
if (diptr[point].Status != dipntmsg->Status)
|
|
|
{
|
|
|
for (i = 0; i < MAX_PROV_PORT_NUM; i++)
|
|
|
{
|
|
|
if (diptr[point].Prov[i].Enable == 0)
|
|
|
continue;
|
|
|
|
|
|
j = diptr[point].Prov[i].PortNo;
|
|
|
k = diptr[point].Prov[i].PntNo;
|
|
|
if((SioParam[j].m_psBaoHu->PortType == PROV_PROTOCOL)
|
|
|
&& SioParam[j].m_psBaoHu)
|
|
|
{
|
|
|
if(SioParam[j].m_psBaoHu->DiPtr)
|
|
|
{
|
|
|
diprovptr = (PROV_DI_PNT*)SioParam[j].m_psBaoHu->DiPtr;
|
|
|
diprovptr[k].ChangeFlag = 1;
|
|
|
|
|
|
// wen 2004.11.19 <20><><EFBFBD><EFBFBD>ң<EFBFBD>ű仯<C5B1><E4BBAF><EFBFBD>ݵĴ<DDB5><C4B4><EFBFBD>
|
|
|
SioParam[j].m_psBaoHu->DiChange = TRUE;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// wen 2004.11.19 <20><><EFBFBD><EFBFBD>ң<EFBFBD>ű仯<C5B1><E4BBAF><EFBFBD>ݵĴ<DDB5><C4B4><EFBFBD>
|
|
|
SioParam[port].m_psBaoHu->DiChange = TRUE;
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>ǰ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
|
|
|
#ifdef FUNCTION_FEND
|
|
|
WriteChangeData(port, point, dipntmsg, DI_PNT_TYPE);
|
|
|
#endif
|
|
|
}
|
|
|
diptr[point].Status = dipntmsg->Status;
|
|
|
diptr[point].State = 1;
|
|
|
|
|
|
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
// wen 2005.12.15 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>ֵʱ<D6B5><CAB1><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD>˿<EFBFBD>״̬
|
|
|
SioParam[port].LineCommCnt = 0;
|
|
|
SioParam[port].Status = TRUE;
|
|
|
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
bRetVal = true;
|
|
|
break;
|
|
|
|
|
|
case PNT_CTRL_NO:
|
|
|
diptr[point].ControlNo = dipntmsg->ControlNo;
|
|
|
diptr[point].CtrlEnable = true;
|
|
|
bRetVal = true;
|
|
|
break;
|
|
|
|
|
|
case PNT_PROV_MSG:
|
|
|
for (i = 0; i < MAX_PROV_PORT_NUM; i++)
|
|
|
{
|
|
|
if (diptr[point].Prov[i].Enable == 0)
|
|
|
continue;
|
|
|
|
|
|
if (diptr[point].Prov[i].PortNo == dipntmsg->Prov[0].PortNo)
|
|
|
{
|
|
|
diptr[point].Prov[i].PntNo = dipntmsg->Prov[0].PntNo;
|
|
|
diptr[point].Prov[i].Enable = 1;
|
|
|
bRetVal = true;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if(bRetVal)
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
for (i = 0; i < MAX_PROV_PORT_NUM; i++)
|
|
|
{
|
|
|
if (diptr[point].Prov[i].Enable)
|
|
|
continue;
|
|
|
|
|
|
diptr[point].Prov[i].PortNo = dipntmsg->Prov[0].PortNo;
|
|
|
diptr[point].Prov[i].PntNo = dipntmsg->Prov[0].PntNo;
|
|
|
diptr[point].Prov[i].Enable = 1;
|
|
|
bRetVal = true;
|
|
|
break;
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
case PI_PNT_TYPE:
|
|
|
if (!SioParam[port].m_psBaoHu->PiPtr)
|
|
|
break;
|
|
|
|
|
|
// wen 2005.09.19
|
|
|
if((point < 0) || (point >= SioParam[port].m_psBaoHu->PiNum))
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
pipntmsg = (PI_DEF*)pntmsg;
|
|
|
piptr = (PI_DEF*)SioParam[port].m_psBaoHu->PiPtr;
|
|
|
|
|
|
switch (attr)
|
|
|
{
|
|
|
case PNT_ENABLE:
|
|
|
piptr[point].Enable = pipntmsg->Enable;
|
|
|
bRetVal = true;
|
|
|
break;
|
|
|
|
|
|
case PNT_STATE:
|
|
|
piptr[point].State = pipntmsg->State;
|
|
|
bRetVal = true;
|
|
|
break;
|
|
|
|
|
|
case PNT_RAWVALUE:
|
|
|
//SioParam[port].Status = TRUE;
|
|
|
|
|
|
if (abs((long)(piptr[point].RawValue - pipntmsg->RawValue)) > 2)
|
|
|
{
|
|
|
piptr[point].RawValue = pipntmsg->RawValue;
|
|
|
piptr[point].State = 1;
|
|
|
|
|
|
for (i = 0; i < MAX_PROV_PORT_NUM; i++)
|
|
|
{
|
|
|
if (piptr[point].Prov[i].Enable == 0)
|
|
|
continue;
|
|
|
|
|
|
j = piptr[point].Prov[i].PortNo;
|
|
|
k = piptr[point].Prov[i].PntNo;
|
|
|
if(SioParam[j].m_psBaoHu)
|
|
|
{
|
|
|
if((PROV_PROTOCOL == SioParam[j].m_psBaoHu->PortType)
|
|
|
&& SioParam[j].m_psBaoHu->PiPtr)
|
|
|
{
|
|
|
piprovptr = (PROV_PI_PNT*)SioParam[j].m_psBaoHu->PiPtr;
|
|
|
piprovptr[k].ChangeFlag = 1;
|
|
|
|
|
|
// wen 2004.11.19 <20><><EFBFBD>ӵ<EFBFBD><D3B5>ȱ仯<C8B1><E4BBAF><EFBFBD>ݵĴ<DDB5><C4B4><EFBFBD>
|
|
|
// SioParam[j].m_psBaoHu->PiChange = TRUE;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>ǰ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
|
|
|
#ifdef FUNCTION_FEND
|
|
|
WriteChangeData(port, point, pipntmsg, PI_PNT_TYPE);
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
// wen 2005.12.15 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>ֵʱ<D6B5><CAB1><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD>˿<EFBFBD>״̬
|
|
|
SioParam[port].LineCommCnt = 0;
|
|
|
SioParam[port].Status = TRUE;
|
|
|
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
bRetVal = true;
|
|
|
break;
|
|
|
|
|
|
case PNT_PROV_MSG:
|
|
|
for (i = 0; i < MAX_PROV_PORT_NUM; i++)
|
|
|
{
|
|
|
if (piptr[point].Prov[i].Enable == 0)
|
|
|
continue;
|
|
|
|
|
|
if (piptr[point].Prov[i].PortNo == pipntmsg->Prov[0].PortNo)
|
|
|
{
|
|
|
piptr[point].Prov[i].PntNo = pipntmsg->Prov[0].PntNo;
|
|
|
piptr[point].Prov[i].Enable = 1;
|
|
|
bRetVal = true;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if(bRetVal)
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
for (i = 0; i < MAX_PROV_PORT_NUM; i++)
|
|
|
{
|
|
|
if (piptr[point].Prov[i].Enable)
|
|
|
continue;
|
|
|
|
|
|
piptr[point].Prov[i].PortNo = pipntmsg->Prov[0].PortNo;
|
|
|
piptr[point].Prov[i].PntNo = pipntmsg->Prov[0].PntNo;
|
|
|
piptr[point].Prov[i].Enable = 1;
|
|
|
bRetVal = true;
|
|
|
break;
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
return bRetVal;
|
|
|
}
|
|
|
|
|
|
int GetPntMsg(int port, int point, void *pntmsg, BYTE type, BYTE attr)
|
|
|
{
|
|
|
AI_DEF *aiptr, *aipntmsg;
|
|
|
DI_DEF *diptr, *dipntmsg;
|
|
|
PI_DEF *piptr, *pipntmsg;
|
|
|
BOOL bRetVal;
|
|
|
|
|
|
bRetVal = false;
|
|
|
if ((port < 0) || (port >= MaxPortNum))
|
|
|
return bRetVal;
|
|
|
|
|
|
if (!IsBaoHuPtr(port))
|
|
|
return bRetVal;
|
|
|
|
|
|
if (RECV_PROTOCOL != SioParam[port].m_psBaoHu->PortType)
|
|
|
return bRetVal;
|
|
|
|
|
|
switch (type)
|
|
|
{
|
|
|
case AI_PNT_TYPE:
|
|
|
if (!SioParam[port].m_psBaoHu->AiPtr)
|
|
|
break;
|
|
|
|
|
|
if ((point < 0) || (point >= SioParam[port].m_psBaoHu->AiNum))
|
|
|
break;
|
|
|
|
|
|
aipntmsg = (AI_DEF*)pntmsg;
|
|
|
aiptr = (AI_DEF*)SioParam[port].m_psBaoHu->AiPtr;
|
|
|
|
|
|
bRetVal = true;
|
|
|
switch (attr)
|
|
|
{
|
|
|
case PNT_ENABLE:
|
|
|
aipntmsg->Enable = aiptr[point].Enable;
|
|
|
break;
|
|
|
|
|
|
case PNT_STATE:
|
|
|
aipntmsg->State = aiptr[point].State;
|
|
|
break;
|
|
|
|
|
|
case PNT_POLAR:
|
|
|
aipntmsg->Polar = aiptr[point].Polar;
|
|
|
break;
|
|
|
|
|
|
case PNT_RAWVALUE:
|
|
|
aipntmsg->RawValue = aiptr[point].RawValue;
|
|
|
break;
|
|
|
|
|
|
case PNT_PROV_MSG:
|
|
|
memmove((char*)&aipntmsg->Prov[0],
|
|
|
(char*)&aiptr[point].Prov[0],
|
|
|
sizeof(PROV_PNT)*MAX_PROV_PORT_NUM);
|
|
|
break;
|
|
|
|
|
|
case PNT_ALL_MSG:
|
|
|
memmove((char*)aipntmsg, (char*)&aiptr[point], sizeof(AI_DEF));
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
bRetVal = false;
|
|
|
break;
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
case DI_PNT_TYPE:
|
|
|
if (!SioParam[port].m_psBaoHu->DiPtr)
|
|
|
break;
|
|
|
|
|
|
if ((point < 0) || (point >= SioParam[port].m_psBaoHu->DiNum))
|
|
|
break;
|
|
|
|
|
|
dipntmsg = (DI_DEF*)pntmsg;
|
|
|
diptr = (DI_DEF*)SioParam[port].m_psBaoHu->DiPtr;
|
|
|
|
|
|
bRetVal = true;
|
|
|
switch (attr)
|
|
|
{
|
|
|
case PNT_ENABLE:
|
|
|
dipntmsg->Enable = diptr[point].Enable;
|
|
|
break;
|
|
|
|
|
|
case PNT_STATE:
|
|
|
dipntmsg->State = diptr[point].State;
|
|
|
break;
|
|
|
|
|
|
case PNT_SOE_TIME:
|
|
|
memmove((char*)&dipntmsg->SoeTime,
|
|
|
(char*)&diptr[point].SoeTime,
|
|
|
sizeof(DAY_TIME));
|
|
|
break;
|
|
|
|
|
|
case PNT_STATUS:
|
|
|
dipntmsg->Status = diptr[point].Status;
|
|
|
break;
|
|
|
|
|
|
case PNT_CTRL_NO:
|
|
|
dipntmsg->ControlNo = diptr[point].ControlNo;
|
|
|
dipntmsg->CtrlEnable = diptr[point].CtrlEnable;
|
|
|
break;
|
|
|
|
|
|
case PNT_PROV_MSG:
|
|
|
memmove((char*)&dipntmsg->Prov[0],
|
|
|
(char*)&diptr[point].Prov[0],
|
|
|
sizeof(PROV_PNT)*MAX_PROV_PORT_NUM);
|
|
|
break;
|
|
|
|
|
|
case PNT_ALL_MSG:
|
|
|
memmove((char*)dipntmsg, (char*)&diptr[point], sizeof(DI_DEF));
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
bRetVal = false;
|
|
|
break;
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
case PI_PNT_TYPE:
|
|
|
if (!SioParam[port].m_psBaoHu->PiPtr)
|
|
|
break;
|
|
|
|
|
|
if ((point < 0) || (point >= SioParam[port].m_psBaoHu->PiNum))
|
|
|
break;
|
|
|
|
|
|
|
|
|
pipntmsg = (PI_DEF*)pntmsg;
|
|
|
piptr = (PI_DEF*)SioParam[port].m_psBaoHu->PiPtr;
|
|
|
|
|
|
bRetVal = true;
|
|
|
switch (attr)
|
|
|
{
|
|
|
case PNT_ENABLE:
|
|
|
pipntmsg->Enable = piptr[point].Enable;
|
|
|
break;
|
|
|
|
|
|
case PNT_STATE:
|
|
|
pipntmsg->State = piptr[point].State;
|
|
|
break;
|
|
|
|
|
|
case PNT_RAWVALUE:
|
|
|
pipntmsg->RawValue = piptr[point].RawValue;
|
|
|
break;
|
|
|
|
|
|
case PNT_PROV_MSG:
|
|
|
memmove((char*)&pipntmsg->Prov[0],
|
|
|
(char*)&piptr[point].Prov[0],
|
|
|
sizeof(PROV_PNT)*MAX_PROV_PORT_NUM);
|
|
|
break;
|
|
|
|
|
|
case PNT_ALL_MSG:
|
|
|
memmove((char*)pipntmsg, (char*)&piptr[point], sizeof(PI_DEF));
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
bRetVal = false;
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
return bRetVal;
|
|
|
}
|
|
|
|
|
|
int SetPorvPntMsg(int port, int point, void *pntmsg, BYTE type, BYTE attr)
|
|
|
{
|
|
|
AI_DEF aipnt;
|
|
|
DI_DEF dipnt;
|
|
|
PI_DEF pipnt;
|
|
|
PROV_AI_PNT *aiprovptr, *aipptr;
|
|
|
PROV_DI_PNT *diprovptr, *dipptr;
|
|
|
PROV_PI_PNT *piprovptr, *pipptr;
|
|
|
BOOL bRetVal;
|
|
|
|
|
|
bRetVal = false;
|
|
|
|
|
|
if((port < 0) || (port >= MaxPortNum))
|
|
|
return bRetVal;
|
|
|
|
|
|
if(!IsBaoHuPtr(port))
|
|
|
return bRetVal;
|
|
|
|
|
|
if(PROTOCOL_SLAVE != SioParam[port].m_psBaoHu->PortType)
|
|
|
return bRetVal;
|
|
|
|
|
|
switch (type)
|
|
|
{
|
|
|
case AI_PNT_TYPE:
|
|
|
if (!SioParam[port].m_psBaoHu->AiPtr)
|
|
|
break;
|
|
|
|
|
|
if ((point < 0) || (point >= SioParam[port].m_psBaoHu->AiNum))
|
|
|
break;
|
|
|
|
|
|
aiprovptr = (PROV_AI_PNT*)SioParam[port].m_psBaoHu->AiPtr;
|
|
|
aipptr = (PROV_AI_PNT*)pntmsg;
|
|
|
|
|
|
aiprovptr[point].PortNo = aipptr->PortNo;
|
|
|
aiprovptr[point].PntNo = aipptr->PntNo;
|
|
|
aiprovptr[point].fFactor = aipptr->fFactor;
|
|
|
aiprovptr[point].Enable = 1;
|
|
|
aiprovptr[point].ChangeFlag = 0;
|
|
|
|
|
|
aipnt.Prov[0].PortNo = port;
|
|
|
aipnt.Prov[0].PntNo = point;
|
|
|
SetPntMsg(aipptr->PortNo, aipptr->PntNo,
|
|
|
(void*)&aipnt, AI_PNT_TYPE, PNT_PROV_MSG);
|
|
|
bRetVal = true;
|
|
|
break;
|
|
|
|
|
|
case DI_PNT_TYPE:
|
|
|
if (!SioParam[port].m_psBaoHu->DiPtr)
|
|
|
break;
|
|
|
|
|
|
if ((point < 0) || (point >= SioParam[port].m_psBaoHu->DiNum))
|
|
|
break;
|
|
|
|
|
|
diprovptr = (PROV_DI_PNT*)SioParam[port].m_psBaoHu->DiPtr;
|
|
|
dipptr = (PROV_DI_PNT*)pntmsg;
|
|
|
|
|
|
switch(attr)
|
|
|
{
|
|
|
case PNT_PROV_MSG:
|
|
|
diprovptr[point].PortNo = dipptr->PortNo;
|
|
|
diprovptr[point].PntNo = dipptr->PntNo;
|
|
|
diprovptr[point].Enable = 1;
|
|
|
diprovptr[point].ChangeFlag = 0;
|
|
|
|
|
|
dipnt.Prov[0].PortNo = port;
|
|
|
dipnt.Prov[0].PntNo = point;
|
|
|
SetPntMsg(dipptr->PortNo, dipptr->PntNo,
|
|
|
(void*)&dipnt, DI_PNT_TYPE, PNT_PROV_MSG);
|
|
|
bRetVal = true;
|
|
|
break;
|
|
|
|
|
|
case PNT_CTRL_NO:
|
|
|
diprovptr[point].ControlNo = dipptr->ControlNo;
|
|
|
diprovptr[point].CtrlEnable = true;
|
|
|
bRetVal = true;
|
|
|
break;
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
case PI_PNT_TYPE:
|
|
|
if (!SioParam[port].m_psBaoHu->PiPtr)
|
|
|
break;
|
|
|
|
|
|
if ((point < 0) || (point >= SioParam[port].m_psBaoHu->PiNum))
|
|
|
break;
|
|
|
|
|
|
piprovptr = (PROV_PI_PNT*)SioParam[port].m_psBaoHu->PiPtr;
|
|
|
pipptr = (PROV_PI_PNT*)pntmsg;
|
|
|
|
|
|
piprovptr[point].PortNo = pipptr->PortNo;
|
|
|
piprovptr[point].PntNo = pipptr->PntNo;
|
|
|
piprovptr[point].fFactor = pipptr->fFactor;
|
|
|
piprovptr[point].Enable = 1;
|
|
|
piprovptr[point].ChangeFlag = 0;
|
|
|
|
|
|
pipnt.Prov[0].PortNo = port;
|
|
|
pipnt.Prov[0].PntNo = point;
|
|
|
SetPntMsg(pipptr->PortNo, pipptr->PntNo,
|
|
|
(void*)&pipnt, PI_PNT_TYPE, PNT_PROV_MSG);
|
|
|
bRetVal = true;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
return bRetVal;
|
|
|
}
|
|
|
|
|
|
int GetPorvPntMsg(int port, int point, void *pntmsg, BYTE type)
|
|
|
{
|
|
|
PROV_AI_PNT *aiprovptr;
|
|
|
PROV_DI_PNT *diprovptr;
|
|
|
PROV_PI_PNT *piprovptr;
|
|
|
BOOL bRetVal;
|
|
|
|
|
|
bRetVal = false;
|
|
|
if ((port < 0) || (port >= MaxPortNum))
|
|
|
return bRetVal;
|
|
|
|
|
|
if (!IsBaoHuPtr(port))
|
|
|
return bRetVal;
|
|
|
|
|
|
if (RECV_PROTOCOL != SioParam[port].m_psBaoHu->PortType)
|
|
|
return bRetVal;
|
|
|
|
|
|
switch (type)
|
|
|
{
|
|
|
case AI_PNT_TYPE:
|
|
|
if (!SioParam[port].m_psBaoHu->AiPtr)
|
|
|
break;
|
|
|
|
|
|
if ((point < 0) || (point >= SioParam[port].m_psBaoHu->AiNum))
|
|
|
break;
|
|
|
|
|
|
aiprovptr = (PROV_AI_PNT*)SioParam[port].m_psBaoHu->AiPtr;
|
|
|
memmove((char*)pntmsg, (char*)&aiprovptr[point], sizeof(PROV_AI_PNT));
|
|
|
bRetVal = true;
|
|
|
break;
|
|
|
|
|
|
case DI_PNT_TYPE:
|
|
|
if (!SioParam[port].m_psBaoHu->DiPtr)
|
|
|
break;
|
|
|
|
|
|
if ((point < 0) || (point >= SioParam[port].m_psBaoHu->DiNum))
|
|
|
break;
|
|
|
|
|
|
diprovptr = (PROV_DI_PNT*)SioParam[port].m_psBaoHu->DiPtr;
|
|
|
memmove((char*)pntmsg, (char*)&diprovptr[point], sizeof(PROV_DI_PNT));
|
|
|
bRetVal = true;
|
|
|
break;
|
|
|
|
|
|
case PI_PNT_TYPE:
|
|
|
if (!SioParam[port].m_psBaoHu->PiPtr)
|
|
|
break;
|
|
|
|
|
|
if ((point < 0) || (point >= SioParam[port].m_psBaoHu->PiNum))
|
|
|
break;
|
|
|
|
|
|
piprovptr = (PROV_PI_PNT*)SioParam[port].m_psBaoHu->PiPtr;
|
|
|
memmove((char*)pntmsg, (char*)&piprovptr[point], sizeof(PROV_PI_PNT));
|
|
|
bRetVal = true;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
return bRetVal;
|
|
|
}
|
|
|
|
|
|
//*******************************************************************
|
|
|
//* Poll Cmd *
|
|
|
//*******************************************************************
|
|
|
|
|
|
int CheckPollCmdBufEmpty(int port)
|
|
|
{
|
|
|
int i, j;
|
|
|
|
|
|
if ((port < 0) || (port >= MaxPortNum))
|
|
|
return 0;
|
|
|
|
|
|
if (!IsBaoHuPtr(port))
|
|
|
return 0;
|
|
|
|
|
|
j = 0;
|
|
|
for (i = 0; i < POLL_CMD_TYPE_NUM; i++)
|
|
|
{
|
|
|
j += SioParam[port].m_psBaoHu->PollCmd[i].MsgCnt ? 1 : 0;
|
|
|
}
|
|
|
|
|
|
return (j ? 0 : 1);
|
|
|
}
|
|
|
|
|
|
int PutPollCmdToBuf(int port, int type, WORD wait, char *buf, int len)
|
|
|
{
|
|
|
int ret;
|
|
|
u_char szbuf[MAX_MSG_BUF_SIZE];
|
|
|
|
|
|
if ((port < 0) || (port >= MaxPortNum))
|
|
|
return 0;
|
|
|
|
|
|
if (len == 0)
|
|
|
return 0;
|
|
|
|
|
|
// wen 2004.10.25 <20><><EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD>δ<EFBFBD><EFBFBD><F2BFAAA3><EFBFBD>0
|
|
|
//if(!SioParam[port].OpenFlag)
|
|
|
if(!ShmGetPortFlag(port, FLAG_OPEN))
|
|
|
return 0;
|
|
|
|
|
|
if (!IsBaoHuPtr(port))
|
|
|
return false;
|
|
|
|
|
|
szbuf[0] = HIBYTE(len+2);
|
|
|
szbuf[1] = LOBYTE(len+2);
|
|
|
|
|
|
// <20><><EFBFBD>ȴ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ִ洢
|
|
|
szbuf[2] = HIBYTE(wait);
|
|
|
szbuf[3] = LOBYTE(wait);
|
|
|
memmove((char*)&szbuf[4], buf, len);
|
|
|
|
|
|
ret = PutDataToBuf(&SioParam[port].m_psBaoHu->PollCmd[type], szbuf, len+4);
|
|
|
if (ret == (len + 4))
|
|
|
return true;
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// wen 2005.09.08 <20><><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EEBBBA><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
|
|
|
void ClearAllCmdFromPollCmdBuf(int port)
|
|
|
{
|
|
|
int i;
|
|
|
|
|
|
if ((port < 0) || (port >= MaxPortNum))
|
|
|
return;
|
|
|
|
|
|
if (!IsBaoHuPtr(port))
|
|
|
return;
|
|
|
|
|
|
for(i = 0; i < POLL_CMD_TYPE_NUM; i++)
|
|
|
{
|
|
|
SioParam[port].m_psBaoHu->PollCmd[i].MsgCnt=0;
|
|
|
}
|
|
|
|
|
|
ClearCmdAllFlag(port);
|
|
|
}
|
|
|
|
|
|
void ClearCmdFormPollCmdBuf(int port)
|
|
|
{
|
|
|
int len, idx;
|
|
|
u_char szbuf[MAX_MSG_BUF_SIZE];
|
|
|
|
|
|
if ((port < 0) || (port >= MaxPortNum))
|
|
|
return;
|
|
|
|
|
|
if (!IsBaoHuPtr(port))
|
|
|
return;
|
|
|
|
|
|
idx = SioParam[port].m_psBaoHu->LastGetCmdBuf;
|
|
|
GetDataFormBuf(&SioParam[port].m_psBaoHu->PollCmd[idx], szbuf, 2, true);
|
|
|
len = BYTE1(szbuf[0]) + BYTE0(szbuf[1]);
|
|
|
GetDataFormBuf(&SioParam[port].m_psBaoHu->PollCmd[idx], szbuf, len, true);
|
|
|
|
|
|
// wen 2005.09.20 <20><EFBFBD><DEB8><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>·<EFBFBD><C2B7><EFBFBD>ʶ
|
|
|
ClearCmdAllFlag(port);
|
|
|
}
|
|
|
|
|
|
void ClearCmdFormPollCmdBufEx( int port, char *file, int line )
|
|
|
{
|
|
|
int len, idx;
|
|
|
char szbuf[MAX_MSG_BUF_SIZE];
|
|
|
|
|
|
ClearCmdFormPollCmdBuf(port);
|
|
|
return;
|
|
|
|
|
|
if ((port < 0) || (port >= MaxPortNum))
|
|
|
return;
|
|
|
|
|
|
if (!IsBaoHuPtr(port))
|
|
|
return;
|
|
|
|
|
|
sprintf(szbuf, "commid=%d %s<%d>, Clear Cmd", port + 1, file, line);
|
|
|
DebugPrint(szbuf);
|
|
|
|
|
|
idx = SioParam[port].m_psBaoHu->LastGetCmdBuf;
|
|
|
GetDataFormBuf(&SioParam[port].m_psBaoHu->PollCmd[idx], (u_char *)szbuf, 2, true);
|
|
|
len = BYTE1(szbuf[0]) + BYTE0(szbuf[1]);
|
|
|
GetDataFormBuf(&SioParam[port].m_psBaoHu->PollCmd[idx], (u_char *)szbuf, len, true);
|
|
|
|
|
|
// wen 2005.09.20 <20><EFBFBD><DEB8><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>·<EFBFBD><C2B7><EFBFBD>ʶ
|
|
|
ClearCmdAllFlag(port);
|
|
|
}
|
|
|
|
|
|
void ClearCmdAllFlag(int port)
|
|
|
{
|
|
|
if (!IsBaoHuPtr(port))
|
|
|
return;
|
|
|
|
|
|
SioParam[port].m_psBaoHu->RetryCnt = 0;
|
|
|
SioParam[port].m_psBaoHu->RetryTimeCnt = 0;
|
|
|
SioParam[port].m_psBaoHu->WaitTimeCnt = 0;
|
|
|
|
|
|
SioParam[port].m_psBaoHu->ForceWaitFlag = 0;
|
|
|
SioParam[port].m_psBaoHu->ForceWaitCnt = 0;
|
|
|
|
|
|
SioParam[port].m_psBaoHu->SendCmdFlag = 0;
|
|
|
SioParam[port].m_psBaoHu->RevCmdFlag = 0;
|
|
|
|
|
|
SioParam[port].m_psBaoHu->ReSendCmdFlag = 0;
|
|
|
SioParam[port].m_psBaoHu->LastGetCmdBuf = 0;
|
|
|
}
|
|
|
|
|
|
int GetCmdFormPollCmdBuf(int port, u_char *buf, int len)
|
|
|
{
|
|
|
int i, tmp;
|
|
|
u_char szbuf[MAX_MSG_BUF_SIZE];
|
|
|
|
|
|
if ((port < 0) || (port >= MaxPortNum))
|
|
|
return 0;
|
|
|
|
|
|
if (!IsBaoHuPtr(port))
|
|
|
return 0;
|
|
|
|
|
|
for (i = POLL_CMD_TYPE_NUM - 1; i >= 0; i--)
|
|
|
{
|
|
|
if (SioParam[port].m_psBaoHu->PollCmd[i].MsgCnt < 4)
|
|
|
{
|
|
|
SioParam[port].m_psBaoHu->PollCmd[i].MsgCnt = 0;
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
GetDataFormBuf(&SioParam[port].m_psBaoHu->PollCmd[i], szbuf, 2, false);
|
|
|
tmp = BYTE1(szbuf[0]) + BYTE0(szbuf[1]);
|
|
|
GetDataFormBuf(&SioParam[port].m_psBaoHu->PollCmd[i], szbuf, tmp + 2, false);
|
|
|
|
|
|
memmove((char*)buf, (char*)&szbuf[2], tmp);
|
|
|
|
|
|
SioParam[port].m_psBaoHu->LastGetCmdBuf = i;
|
|
|
return tmp;
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
int ReGetCmdFormPollCmdBuf(int port, u_char *buf, int len)
|
|
|
{
|
|
|
int idx, ret, tmp;
|
|
|
u_char szbuf[MAX_MSG_BUF_SIZE];
|
|
|
|
|
|
if ((port < 0) || (port >= MaxPortNum))
|
|
|
return 0;
|
|
|
|
|
|
if (!IsBaoHuPtr(port))
|
|
|
return false;
|
|
|
|
|
|
SioParam[port].LostSyncCnt++;
|
|
|
|
|
|
idx = SioParam[port].m_psBaoHu->LastGetCmdBuf;
|
|
|
|
|
|
if (SioParam[port].m_psBaoHu->PollCmd[idx].MsgCnt < 4)
|
|
|
{
|
|
|
SioParam[port].m_psBaoHu->PollCmd[idx].MsgCnt = 0;
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
GetDataFormBuf(&SioParam[port].m_psBaoHu->PollCmd[idx], szbuf, 2, false);
|
|
|
tmp = BYTE1(szbuf[0]) + BYTE0(szbuf[1]);
|
|
|
ret = GetDataFormBuf(&SioParam[port].m_psBaoHu->PollCmd[idx], szbuf, tmp + 2, false);
|
|
|
|
|
|
memmove((char*)buf, (char*)&szbuf[2], tmp);
|
|
|
|
|
|
return tmp;
|
|
|
}
|
|
|
|
|
|
void SendCmdFormPollCmdBuf(int port)
|
|
|
{
|
|
|
int len;
|
|
|
u_char buf[MAX_MSG_BUF_SIZE];
|
|
|
|
|
|
if ((port < 0) || (port >= MaxPortNum))
|
|
|
return;
|
|
|
|
|
|
//if (SioParam[port].OpenFlag == 0)
|
|
|
if(!ShmGetPortFlag(port, FLAG_OPEN))
|
|
|
return;
|
|
|
|
|
|
if (!IsBaoHuPtr(port))
|
|
|
return;
|
|
|
|
|
|
if (SioParam[port].m_psBaoHu->ForceWaitFlag
|
|
|
&& SioParam[port].m_psBaoHu->ForceWaitCnt)
|
|
|
{
|
|
|
SioParam[port].m_psBaoHu->ForceWaitCnt--;
|
|
|
if (SioParam[port].m_psBaoHu->ForceWaitCnt == 0)
|
|
|
{
|
|
|
ClearCmdFormPollCmdBuf(port); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
|
|
|
//ClearCmdAllFlag(port);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (SioParam[port].m_psBaoHu->SendCmdFlag
|
|
|
&& (SioParam[port].m_psBaoHu->RevCmdFlag == 0))
|
|
|
{
|
|
|
SioParam[port].m_psBaoHu->RetryTimeCnt++;
|
|
|
if (SioParam[port].m_psBaoHu->RetryTimeCnt
|
|
|
< SioParam[port].m_psBaoHu->RetryTime)
|
|
|
return;
|
|
|
SioParam[port].m_psBaoHu->RetryTimeCnt = 0;
|
|
|
|
|
|
SioParam[port].m_psBaoHu->RetryCnt++;
|
|
|
if (SioParam[port].m_psBaoHu->RetryCnt
|
|
|
> SioParam[port].m_psBaoHu->Retry)
|
|
|
{
|
|
|
SioParam[port].m_psBaoHu->RevCmdFlag = 1;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
SioParam[port].m_psBaoHu->SendCmdFlag = 0;
|
|
|
SioParam[port].m_psBaoHu->RevCmdFlag = 0;
|
|
|
|
|
|
SioParam[port].m_psBaoHu->ReSendCmdFlag = 1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (SioParam[port].m_psBaoHu->SendCmdFlag
|
|
|
&& SioParam[port].m_psBaoHu->RevCmdFlag)
|
|
|
{
|
|
|
ClearCmdFormPollCmdBuf(port); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
|
|
|
//ClearCmdAllFlag(port);
|
|
|
}
|
|
|
|
|
|
if (SioParam[port].m_psBaoHu->WaitTime)
|
|
|
{
|
|
|
SioParam[port].m_psBaoHu->WaitTimeCnt++;
|
|
|
if (SioParam[port].m_psBaoHu->WaitTimeCnt
|
|
|
< SioParam[port].m_psBaoHu->WaitTime)
|
|
|
return;
|
|
|
}
|
|
|
SioParam[port].m_psBaoHu->WaitTimeCnt = 0;
|
|
|
|
|
|
if (SioParam[port].m_psBaoHu->ReSendCmdFlag)
|
|
|
{
|
|
|
len = ReGetCmdFormPollCmdBuf(port, buf, MAX_MSG_BUF_SIZE);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
len = GetCmdFormPollCmdBuf(port, buf, MAX_MSG_BUF_SIZE);
|
|
|
}
|
|
|
|
|
|
if (len < 3)
|
|
|
return;
|
|
|
|
|
|
if (UdpParam.Socket)
|
|
|
{
|
|
|
FillAndSendCmd(0, port, SDS_SIO_SEND_DATA,
|
|
|
(u_char*)&buf[2], len - 2);
|
|
|
SioParam[port].SendCharNum += (len - 2);
|
|
|
|
|
|
SioParam[port].m_psBaoHu->SendCmdFlag = 1;
|
|
|
SioParam[port].m_psBaoHu->ReSendCmdFlag = 0;
|
|
|
SioParam[port].m_psBaoHu->RevCmdFlag = 0;
|
|
|
}
|
|
|
|
|
|
if ((FAST_CMD_TYPE == SioParam[port].m_psBaoHu->LastGetCmdBuf)
|
|
|
|| (UdpParam.Socket == 0))
|
|
|
{
|
|
|
SioParam[port].m_psBaoHu->ForceWaitCnt
|
|
|
= BYTE1(buf[0]) + BYTE0(buf[1]) + TIMER_CNT - 1;
|
|
|
SioParam[port].m_psBaoHu->ForceWaitCnt /= TIMER_CNT;
|
|
|
if (SioParam[port].m_psBaoHu->ForceWaitCnt)
|
|
|
SioParam[port].m_psBaoHu->ForceWaitFlag = 1;
|
|
|
else
|
|
|
{
|
|
|
ClearCmdFormPollCmdBuf(port); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
|
|
|
//ClearCmdAllFlag(port); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void TimerProc(void)
|
|
|
{
|
|
|
int i;
|
|
|
|
|
|
for (i = 0; i < MaxPortNum; i++)
|
|
|
{
|
|
|
//if (SioParam[i].OpenFlag == 0)
|
|
|
if(!ShmGetPortFlag(i, FLAG_OPEN))
|
|
|
{
|
|
|
ClearCmdFormPollCmdBuf(i);
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
// wen 2004.10.25 <20>Ա<EFBFBD><D4B1><EFBFBD>Լģ<D4BC><C4A3><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7><EFBFBD>ʱ<EFBFBD><CAB1>
|
|
|
if (FunCallPtr[SioParam[i].ProtocolIdx].Timer)
|
|
|
FunCallPtr[SioParam[i].ProtocolIdx].Timer(i);
|
|
|
else
|
|
|
SendCmdFormPollCmdBuf(i);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void YkYtCommandProcess(int port, u_char *buf, int len)
|
|
|
{
|
|
|
//if (SioParam[port].OpenFlag == 0)
|
|
|
if(!ShmGetPortFlag(port, FLAG_OPEN))
|
|
|
return;
|
|
|
|
|
|
if (SioParam[port].ProtocolIdx < 1)
|
|
|
return;
|
|
|
|
|
|
if (FunCallPtr[SioParam[port].ProtocolIdx].YkYtProcess)
|
|
|
{
|
|
|
FunCallPtr[SioParam[port].ProtocolIdx].YkYtProcess(port, buf, len);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void SystemRtuTime(void)
|
|
|
{
|
|
|
int i;
|
|
|
|
|
|
for (i = 0; i < MaxPortNum; i++)
|
|
|
{
|
|
|
//if (SioParam[i].OpenFlag == 0)
|
|
|
if(!ShmGetPortFlag(i, FLAG_OPEN))
|
|
|
continue;
|
|
|
|
|
|
if (!IsBaoHuPtr(i))
|
|
|
continue;
|
|
|
|
|
|
if (!FunCallPtr[SioParam[i].ProtocolIdx].SendSystemTime)
|
|
|
continue;
|
|
|
|
|
|
// <20>¶<EFBFBD>ʱ
|
|
|
if(SioParam[i].m_psBaoHu->CheckTime == 2)
|
|
|
FunCallPtr[SioParam[i].ProtocolIdx].SendSystemTime(i);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
int InitBaohuLibMainFlag = 0;
|
|
|
|
|
|
void PortRecvDataProcess(void)
|
|
|
{
|
|
|
int i;
|
|
|
|
|
|
for (i = 0; i < MaxPortNum; i++)
|
|
|
{
|
|
|
//if(SioParam[i].OpenFlag && (SioParam[i].RecvBuf.MsgCnt > 0))
|
|
|
if (!SioParam[i].m_psBaoHu)
|
|
|
continue;
|
|
|
|
|
|
if (FLAG_OPEN == SioParam[i].OpenFlag && (SioParam[i].RecvBuf.MsgCnt > 0))
|
|
|
{
|
|
|
// <20>ϸ<EFBFBD><CFB8>жϻ<D0B6><CFBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
if (SioParam[i].RecvBuf.MsgCnt > sizeof(SioParam[i].RecvBuf.MsgData))
|
|
|
{
|
|
|
printf("WARN(%04d): RecvBuf is confusional(MsgCnt=%d, MaxLen=%d).\n",
|
|
|
_getpid(), SioParam[i].RecvBuf.MsgCnt,
|
|
|
sizeof(SioParam[i].RecvBuf.MsgData));
|
|
|
SioParam[i].RecvBuf.MsgCnt = 0;
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
if (FunCallPtr[SioParam[i].ProtocolIdx].RecvData)
|
|
|
{
|
|
|
//#ifdef _OS_LINUX_DEBUG_
|
|
|
//printf("wen: SioParam[%d].RecvBuf.MsgCnt=%d\n", i + 1, SioParam[i].RecvBuf.MsgCnt);
|
|
|
//#endif
|
|
|
//printf("idx = %d\n", SioParam[i].ProtocolIdx);
|
|
|
FunCallPtr[SioParam[i].ProtocolIdx].RecvData(i,
|
|
|
SioParam[i].RecvBuf.MsgData,
|
|
|
SioParam[i].RecvBuf.MsgCnt);
|
|
|
// <20>˿ڽ<CBBF><DABD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>ݱ<EFBFBD>־Ӧ<D6BE><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> yizhonghu 20071029
|
|
|
//SioParam[i].PortNoDataCnt = 0;
|
|
|
|
|
|
// wen 2005.03.22 <20><>¼<EFBFBD>˿ڶ<CBBF>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
|
|
//RecordData(i, RECORD_RO_BUF,SioParam[i].RecvBuf.MsgData,SioParam[i].RecvBuf.MsgCnt);
|
|
|
|
|
|
SioParam[i].RecvCharNum += SioParam[i].RecvBuf.MsgCnt;
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
// wen 2005.10.14 <20><><EFBFBD>Ӷ˿<D3B6>״̬<D7B4><CCAC><EFBFBD><EFBFBD>
|
|
|
//SioParam[i].Status = TRUE;
|
|
|
//-----------------------------------------------------
|
|
|
// <20><><EFBFBD>ڹ<EFBFBD>ԼΪbypassʱ<73><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
if (SioParam[i].ProtocolIdx > 1)
|
|
|
{
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
// wen 2006.04.24 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǽ<EFBFBD><C7BD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>˿<EFBFBD>״̬Ϊ<CCAC><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><DEB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>Ƕ˿<C7B6><CBBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>վ<EFBFBD><D5BE><EFBFBD>⡣
|
|
|
//SioParam[i].Status = TRUE;
|
|
|
//=============================================================
|
|
|
//TimeEx(&SioParam[i].dLineCommTime);
|
|
|
SioParam[i].Status = TRUE;
|
|
|
/*if (SioParam[i].m_psBaoHu)
|
|
|
{
|
|
|
// <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>վ
|
|
|
//if(SioParam[i].m_psBaoHu->PortType)
|
|
|
//{
|
|
|
//if(1 == i)
|
|
|
// printf("<22><><EFBFBD>ö˿<C3B6>%d<>˿<EFBFBD>״̬ΪTRUE\n", i+1);
|
|
|
SioParam[i].Status = TRUE;
|
|
|
//}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
SioParam[i].Status = TRUE;
|
|
|
if (i == SioParam[i].MasterPort)
|
|
|
SioParam[SioParam[i].SlavePort].Status = TRUE;
|
|
|
else
|
|
|
SioParam[SioParam[i].MasterPort].Status = TRUE;
|
|
|
}*/
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
}
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
}
|
|
|
}
|
|
|
SioParam[i].RecvBuf.MsgCnt = 0;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void BaohuLibMain(int netportnum)
|
|
|
{
|
|
|
int msec, tmp1, tmp2;
|
|
|
static int systimecnt = 0;
|
|
|
|
|
|
SYSTEMTIME stm;
|
|
|
|
|
|
if (InitBaohuLibMainFlag == 0)
|
|
|
{
|
|
|
systimecnt = 0;
|
|
|
|
|
|
msec = 0;
|
|
|
|
|
|
// <20><><EFBFBD>˿<EFBFBD><CBBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>6<EFBFBD><36><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD>
|
|
|
//ReadPortConfigInfo(netportnum);
|
|
|
ReadPortConfigInfoEx(netportnum);
|
|
|
|
|
|
InitBaohuLibMainFlag = 1;
|
|
|
}
|
|
|
|
|
|
//msec = (msec + TIMER_CNT) % 1000;
|
|
|
|
|
|
GetLocalTime(&stm);
|
|
|
|
|
|
DayTime.Year = stm.wYear;
|
|
|
DayTime.Month = (stm.wMonth & 0xff);
|
|
|
DayTime.Day = (stm.wDay & 0xff);
|
|
|
DayTime.Hour = stm.wHour & 0xff;
|
|
|
DayTime.Min = stm.wMinute & 0xff;
|
|
|
DayTime.Sec = stm.wSecond & 0xff;
|
|
|
DayTime.mSec = stm.wMilliseconds;
|
|
|
Sleep(100);
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD>д
|
|
|
//SetUdpRecv();
|
|
|
|
|
|
// <20><><EFBFBD>ж˿ڶ<CBBF>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
TimerProc();
|
|
|
// wen 2004.10.25 <20><><EFBFBD>´<EFBFBD><C2B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>timerproc<6F>У<EFBFBD><D0A3>Ա<EFBFBD><D4B1><EFBFBD>Լģ<D4BC><C4A3><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7><EFBFBD>ʱ<EFBFBD><CAB1>
|
|
|
//for (i = 0; i < MaxPortNum; i++)
|
|
|
//{
|
|
|
// SendCmdFormPollCmdBuf(i);
|
|
|
//}
|
|
|
// <20><><EFBFBD>ж˿ڽ<CBBF><DABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>
|
|
|
PortRecvDataProcess();
|
|
|
PollAllPort();
|
|
|
|
|
|
//CreatUdpSetSock();
|
|
|
OpenAllPort();
|
|
|
|
|
|
if (stm.wSecond == 0)
|
|
|
{
|
|
|
tmp2 = stm.wMinute * 60;
|
|
|
tmp1 = tmp2 - systimecnt;
|
|
|
if (tmp1 < 0)
|
|
|
tmp1 += 3600;
|
|
|
|
|
|
// ÿ300<30><30>RTU<54><55>ʱһ<CAB1><D2BB>
|
|
|
if ((tmp1 > SYSTEM_TIME) && (tmp2 != systimecnt))
|
|
|
{
|
|
|
systimecnt = tmp2;
|
|
|
SystemRtuTime();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
int GetMaxPort()
|
|
|
{
|
|
|
return MaxPortNum;
|
|
|
}
|
|
|
|
|
|
//********************************************************************
|
|
|
//* <09>洢ת<E6B4A2><D7AA>soe<6F><65><EFBFBD>ݺ<EFBFBD><DDBA><EFBFBD> *
|
|
|
//*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>int provport : ת<><D7AA><EFBFBD>˿<EFBFBD> *
|
|
|
//* SOE_DEF *ptrSoe : <20><><EFBFBD>洢<EFBFBD><E6B4A2>soe<6F><65><EFBFBD><EFBFBD> *
|
|
|
//*<2A><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>int retval : soe<6F><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *
|
|
|
//********************************************************************
|
|
|
int ProvWriteSoeData(int provport, SOE_DEF *ptrSoe)
|
|
|
{
|
|
|
char szDbg[128];
|
|
|
int iRear, iSoeNum;
|
|
|
|
|
|
if(!IsBaoHuPtr(provport))
|
|
|
return 0;
|
|
|
|
|
|
iSoeNum = 0;
|
|
|
if(SioParam[provport].m_psBaoHu->ProvSoeBuf.ptrProvSoe)
|
|
|
{
|
|
|
iRear = SioParam[provport].m_psBaoHu->ProvSoeBuf.iRear;
|
|
|
memcpy((void *)&SioParam[provport].m_psBaoHu->ProvSoeBuf.ptrProvSoe[iRear],
|
|
|
(void *)ptrSoe, sizeof(SOE_DEF));
|
|
|
|
|
|
SioParam[provport].m_psBaoHu->ProvSoeBuf.iRear = (iRear+1) % MAX_PROV_SOE;
|
|
|
if(SioParam[provport].m_psBaoHu->ProvSoeBuf.iSoeNum < MAX_PROV_SOE)
|
|
|
{
|
|
|
SioParam[provport].m_psBaoHu->ProvSoeBuf.iSoeNum++;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
SioParam[provport].m_psBaoHu->ProvSoeBuf.iFront
|
|
|
= (SioParam[provport].m_psBaoHu->ProvSoeBuf.iFront+1) % MAX_PROV_SOE;
|
|
|
sprintf(szDbg, "WARN(%04d): port%02d ProvSoe is overflow(max=%d).",
|
|
|
_getpid(), provport+1, MAX_PROV_SOE);
|
|
|
DebugPrint(szDbg);
|
|
|
}
|
|
|
|
|
|
iSoeNum = SioParam[provport].m_psBaoHu->ProvSoeBuf.iSoeNum;
|
|
|
}
|
|
|
|
|
|
return iSoeNum;
|
|
|
}
|
|
|
|
|
|
//********************************************************************
|
|
|
//* <09><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD><DDB6>庯<EFBFBD><E5BAAF> *
|
|
|
//*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>int provport : ת<><D7AA><EFBFBD>˿<EFBFBD> *
|
|
|
//* SOE_DEF *ptrSoe : <20><>ȡsoe<6F><65><EFBFBD>ݵĻ<DDB5><C4BB><EFBFBD><EFBFBD><EFBFBD> *
|
|
|
//*<2A><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>int retval : ʣ<><CAA3>soe<6F><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *
|
|
|
//********************************************************************
|
|
|
int ProvAndDelGetSoeData(int provport, SOE_DEF *ptrSoe)
|
|
|
{
|
|
|
int iFront, iSoeNum;
|
|
|
SOE_DEF *ptrtmpSoe;
|
|
|
|
|
|
if (!IsBaoHuPtr(provport))
|
|
|
return 0;
|
|
|
|
|
|
iSoeNum = 0;
|
|
|
if(SioParam[provport].m_psBaoHu->ProvSoeBuf.ptrProvSoe
|
|
|
&& (SioParam[provport].m_psBaoHu->ProvSoeBuf.iSoeNum > 0))
|
|
|
{
|
|
|
ptrtmpSoe = SioParam[provport].m_psBaoHu->ProvSoeBuf.ptrProvSoe;
|
|
|
iFront = SioParam[provport].m_psBaoHu->ProvSoeBuf.iFront;
|
|
|
memcpy((void *)ptrSoe, (void *)&ptrtmpSoe[iFront], sizeof(SOE_DEF));
|
|
|
|
|
|
SioParam[provport].m_psBaoHu->ProvSoeBuf.iFront = (iFront+1) % MAX_PROV_SOE;
|
|
|
SioParam[provport].m_psBaoHu->ProvSoeBuf.iSoeNum--;
|
|
|
iSoeNum = SioParam[provport].m_psBaoHu->ProvSoeBuf.iSoeNum;
|
|
|
}
|
|
|
|
|
|
return iSoeNum;
|
|
|
}
|
|
|
|
|
|
//********************************************************************
|
|
|
//* ת<><D7AA><EFBFBD>˿<EFBFBD><CBBF>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>soe<6F><65><EFBFBD>ݺ<EFBFBD><DDBA><EFBFBD> *
|
|
|
//*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>int provport : ת<><D7AA><EFBFBD>˿<EFBFBD> *
|
|
|
//********************************************************************
|
|
|
int ProvHaveSoeData(int provport)
|
|
|
{
|
|
|
if(!IsBaoHuPtr(provport))
|
|
|
return 0;
|
|
|
|
|
|
return SioParam[provport].m_psBaoHu->ProvSoeBuf.iSoeNum;
|
|
|
}
|
|
|
|
|
|
//********************************************************************
|
|
|
//* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݺ<EFBFBD><DDBA><EFBFBD> *
|
|
|
//*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> int commid : <20>˿ں<CBBF> *
|
|
|
//* char *buf : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD><EFBFBD><EFBFBD> *
|
|
|
//* int len : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD> *
|
|
|
//*<2A><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD> *
|
|
|
//********************************************************************
|
|
|
void SendDataToPort(int commid, char *buf, int len)
|
|
|
{
|
|
|
#ifdef FUNCTION_FEND
|
|
|
// ǰ<>û<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>û<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>˿<EFBFBD><CBBF>·<EFBFBD><C2B7><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD>ʽ
|
|
|
if(!IsSendDatatoPort(commid))
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
#ifdef OS_LINUX
|
|
|
AddNode(commid, (char *)buf, len);
|
|
|
#else
|
|
|
FillAndSendCmd(0, commid, SDS_SIO_SEND_DATA, (u_char*)buf, len);
|
|
|
// wen 2004.12.21 <20><><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE>ڷ<EFBFBD><DAB7><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>˼<EFBFBD><CBBC><EFBFBD>
|
|
|
SioParam[commid].SendCharNum += len;
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
//********************************************************************
|
|
|
//* <09><><EFBFBD><EFBFBD>ң<EFBFBD><D2A3>ң<EFBFBD><D2A3><EFBFBD><EFBFBD><EFBFBD>ݺ<EFBFBD><DDBA><EFBFBD> *
|
|
|
//*<2A><> <20><><EFBFBD><EFBFBD>int commid : <20>˿ں<CBBF> *
|
|
|
//* char *buf : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD><EFBFBD><EFBFBD> *
|
|
|
//* int len : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD> *
|
|
|
//*<2A><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD> *
|
|
|
//*˵ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>scadaϵͳ(server)<29><>ң<EFBFBD><D2A3>ң<EFBFBD><D2A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *
|
|
|
//********************************************************************
|
|
|
void SendYkYtCommand(int commid, char *buf, int len)
|
|
|
{
|
|
|
// buf[0] --- <20>˿ں<CBBF>(=commid)
|
|
|
// buf[1]
|
|
|
// buf[2]
|
|
|
// buf[3]
|
|
|
// buf[4] --- <20>ص<EFBFBD><D8B5><EFBFBD>
|
|
|
// buf[5]
|
|
|
// buf[6]
|
|
|
// buf[7]
|
|
|
// buf[8] --- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(ң<><D2A3>:1=ѡ<><D1A1>,2=ִ<><D6B4>,3=ȡ<><C8A1>,7=ֱ<><D6B1>;
|
|
|
// ң<><D2A3>:4=ѡ<><D1A1>,5=ִ<><D6B4>,6=ȡ<><C8A1>,8=<3D><>ͣ)
|
|
|
// buf[9] --- <20><><EFBFBD><EFBFBD>״̬(1=<3D>ֵ<EFBFBD><D6B5>ϣ<EFBFBD>2=<3D>ϵ<EFBFBD><CFB5><EFBFBD>)
|
|
|
// (<28><><EFBFBD><EFBFBD>λΪ1ʱ<31><CAB1>Ϊ<EFBFBD><CEAA>У<EFBFBD><D0A3><EFBFBD><EFBFBD>, 1=<3D>غ<EFBFBD>, 2=<3D>ط<EFBFBD>, 3=ʧ<><CAA7>)
|
|
|
|
|
|
DAY_TIME stime;
|
|
|
|
|
|
// <20><><EFBFBD>ж˿<D0B6>
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
// wen 2005.10.10 <20>Ŀ<DEB8><C4BF><EFBFBD><EFBFBD><EFBFBD>netport<72>·<EFBFBD>
|
|
|
//if(commid < MaxSerialPortNum)
|
|
|
if(commid < MaxPortNum)
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
{
|
|
|
if(!IsBaoHuPtr(commid))
|
|
|
return ;
|
|
|
|
|
|
if(!FunCallPtr)
|
|
|
return;
|
|
|
|
|
|
if(FunCallPtr[SioParam[commid].ProtocolIdx].YkYtProcess)
|
|
|
{
|
|
|
if((buf[9] & 0x80) == 0)
|
|
|
{
|
|
|
// <20><><EFBFBD><EFBFBD>ң<EFBFBD>ز<EFBFBD><D8B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
GetLocalTimeEx(&stime);
|
|
|
memcpy((void *)&SioParam[commid].m_psBaoHu->ProvYkYtMsg.m_sDayTime,
|
|
|
(void *)&stime, sizeof(DAY_TIME));
|
|
|
SioParam[commid].m_psBaoHu->ProvYkYtMsg.m_iYkYtStep = buf[8];
|
|
|
|
|
|
// <20>ýṹ<C3BD><E1B9B9>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>ң<EFBFBD><D2A3>)
|
|
|
SioParam[commid].m_psBaoHu->ProvYkYtMsg.m_iYkYtOperate = buf[9];
|
|
|
SioParam[commid].m_psBaoHu->ProvYkYtMsg.m_iCmdFrom = YKYT_CMD_FROM_SCADA;
|
|
|
}
|
|
|
|
|
|
FunCallPtr[SioParam[commid].ProtocolIdx].YkYtProcess(commid, (u_char *)buf, len);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//********************************************************************
|
|
|
//* <20><><EFBFBD><EFBFBD>ң<EFBFBD><D2A3>ң<EFBFBD><D2A3><EFBFBD><EFBFBD><EFBFBD>ݺ<EFBFBD><DDBA><EFBFBD> *
|
|
|
//*<2A><> <20><><EFBFBD><EFBFBD>int commid : <20>˿ں<CBBF> *
|
|
|
//* PROV_YKYT_PARAM *pParam : ң<><D2A3>ң<EFBFBD><D2A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *
|
|
|
//*<2A><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>BOOL retval : <20>Ƿ<EFBFBD>ת<EFBFBD><D7AA><EFBFBD>˿<EFBFBD><CBBF><EFBFBD><EFBFBD><EFBFBD> *
|
|
|
//*˵ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD>˿ڵ<CBBF>ң<EFBFBD><D2A3>ң<EFBFBD><D2A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *
|
|
|
//********************************************************************
|
|
|
BOOL SendYkYtCommand2(int commid, YKYT_PARAM *pParam)
|
|
|
{
|
|
|
DAY_TIME stime;
|
|
|
char Val[20];
|
|
|
int iRealCommid;
|
|
|
// Val[0] --- <20>˿ں<CBBF>(=commid)
|
|
|
// Val[1]
|
|
|
// Val[2]
|
|
|
// Val[3]
|
|
|
// Val[4] --- <20>ص<EFBFBD><D8B5><EFBFBD>
|
|
|
// Val[5]
|
|
|
// Val[6]
|
|
|
// Val[7]
|
|
|
// Val[8] --- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(ң<><D2A3>:1=ѡ<><D1A1>,2=ִ<><D6B4>,3=ȡ<><C8A1>,7=ֱ<><D6B1>;
|
|
|
// ң<><D2A3>:4=ѡ<><D1A1>,5=ִ<><D6B4>,6=ȡ<><C8A1>,8=<3D><>ͣ)
|
|
|
// Val[9] --- <20><><EFBFBD><EFBFBD>״̬(1=<3D>ֵ<EFBFBD><D6B5>ϣ<EFBFBD>2=<3D>ϵ<EFBFBD><CFB5><EFBFBD>)
|
|
|
// (<28><><EFBFBD><EFBFBD>λΪ1ʱ<31><CAB1>Ϊ<EFBFBD><CEAA>У<EFBFBD><D0A3><EFBFBD><EFBFBD>, 1=<3D>غ<EFBFBD>, 2=<3D>ط<EFBFBD>, 3=ʧ<><CAA7>)
|
|
|
|
|
|
// <20><><EFBFBD>ж˿<D0B6>
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
// wen 2005.10.10 <20>Ŀ<DEB8><C4BF><EFBFBD><EFBFBD><EFBFBD>netport<72>·<EFBFBD>
|
|
|
//if(commid >= MaxSerialPortNum)
|
|
|
//{
|
|
|
// return FALSE;
|
|
|
//}
|
|
|
if(commid >= MaxPortNum)
|
|
|
{
|
|
|
return FALSE;
|
|
|
}
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
|
|
memset(Val, 0, sizeof(Val));
|
|
|
|
|
|
// <20><>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
if(YKYT_SEND_DOWN == pParam->m_iYkYtUpDown)
|
|
|
{
|
|
|
iRealCommid = commid;
|
|
|
|
|
|
Val[0] = (BYTE)iRealCommid;
|
|
|
Val[1] = (BYTE)((iRealCommid & 0xFF00) >> 8);
|
|
|
Val[2] = (BYTE)((iRealCommid & 0xFF0000) >> 16);
|
|
|
Val[3] = (BYTE)((iRealCommid & 0xFF000000) >> 24);
|
|
|
|
|
|
Val[4] = (BYTE)pParam->m_iYkYtPnt;
|
|
|
Val[5] = (BYTE)((pParam->m_iYkYtPnt & 0xFF00) >> 8);
|
|
|
Val[6] = (BYTE)((pParam->m_iYkYtPnt & 0xFF0000) >> 16);
|
|
|
Val[7] = (BYTE)((pParam->m_iYkYtPnt & 0xFF000000) >> 24);
|
|
|
|
|
|
Val[8] = (BYTE)pParam->m_iYkYtStep;
|
|
|
Val[9] = (BYTE)pParam->m_iYkYtOperate;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if(!IsBaoHuPtr(commid))
|
|
|
return FALSE;
|
|
|
|
|
|
if(YKYT_CMD_FROM_SCADA == SioParam[commid].m_psBaoHu->ProvYkYtMsg.m_iCmdFrom)
|
|
|
{
|
|
|
// wen 2005.10.08 <20><>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3>Ӷ<EFBFBD><D3B6><EFBFBD><EFBFBD><EFBFBD>scada<64><61><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
Val[0] = LOBYTE(pParam->m_iYkYtPnt);
|
|
|
Val[1] = HIBYTE(pParam->m_iYkYtPnt);
|
|
|
if(pParam->m_iYkYtOperate == 3)
|
|
|
{
|
|
|
Val[2] = 0;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
Val[2] = 1;
|
|
|
}
|
|
|
SetYkYtAckData(commid, Val);
|
|
|
|
|
|
return TRUE;
|
|
|
}
|
|
|
else if((IsProvYkYtAck(commid, &SioParam[commid].m_psBaoHu->ProvYkYtMsg))
|
|
|
&& (SioParam[commid].m_psBaoHu->ProvYkYtMsg.m_iYkYtPointIdx == pParam->m_iYkYtPnt))
|
|
|
{
|
|
|
iRealCommid = SioParam[commid].m_psBaoHu->ProvYkYtMsg.m_iProvPortIdx;
|
|
|
|
|
|
// ת<><D7AA>վ<EFBFBD><D5BE>
|
|
|
Val[0] = (BYTE)iRealCommid;
|
|
|
Val[1] = (BYTE)((iRealCommid & 0xFF00) >> 8);
|
|
|
Val[2] = (BYTE)((iRealCommid & 0xFF0000) >> 16);
|
|
|
Val[3] = (BYTE)((iRealCommid & 0xFF000000) >> 24);
|
|
|
// ת<><D7AA><EFBFBD>ص<EFBFBD><D8B5><EFBFBD>
|
|
|
Val[4] = (BYTE)SioParam[commid].m_psBaoHu->ProvYkYtMsg.m_iProvYkYtPointIdx;
|
|
|
Val[5] = (BYTE)((SioParam[commid].m_psBaoHu->ProvYkYtMsg.m_iProvYkYtPointIdx & 0xFF00) >> 8);
|
|
|
Val[6] = (BYTE)((SioParam[commid].m_psBaoHu->ProvYkYtMsg.m_iProvYkYtPointIdx & 0xFF0000) >> 16);
|
|
|
Val[7] = (BYTE)((SioParam[commid].m_psBaoHu->ProvYkYtMsg.m_iProvYkYtPointIdx & 0xFF000000) >> 24);
|
|
|
|
|
|
Val[8] = (BYTE)pParam->m_iYkYtStep;
|
|
|
Val[9] = (BYTE)(pParam->m_iYkYtOperate);
|
|
|
Val[9] |= 0x80;
|
|
|
}
|
|
|
else// <20>쳣<EFBFBD><ECB3A3><EFBFBD><EFBFBD>
|
|
|
{
|
|
|
return FALSE;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if(FunCallPtr)
|
|
|
{
|
|
|
if(FunCallPtr[SioParam[iRealCommid].ProtocolIdx].YkYtProcess)
|
|
|
{
|
|
|
if(YKYT_SEND_UP != pParam->m_iYkYtUpDown)
|
|
|
{
|
|
|
// <20><><EFBFBD><EFBFBD>ң<EFBFBD>ز<EFBFBD><D8B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
GetLocalTimeEx(&stime);
|
|
|
memcpy((void *)&SioParam[iRealCommid].m_psBaoHu->ProvYkYtMsg.m_sDayTime,
|
|
|
(void *)&stime, sizeof(DAY_TIME));
|
|
|
SioParam[iRealCommid].m_psBaoHu->ProvYkYtMsg.m_iYkYtStep = pParam->m_iYkYtStep;
|
|
|
|
|
|
SioParam[iRealCommid].m_psBaoHu->ProvYkYtMsg.m_iCmdFrom = YKYT_CMD_FROM_PROVPORT;
|
|
|
}
|
|
|
|
|
|
FunCallPtr[SioParam[iRealCommid].ProtocolIdx].YkYtProcess(iRealCommid, (u_char *)Val, 10);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return TRUE;
|
|
|
}
|
|
|
|
|
|
//********************************************************************
|
|
|
//* <09><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD>ص<EFBFBD><D8B5><EFBFBD>ת<EFBFBD><D7AA><EFBFBD>㺯<EFBFBD><E3BAAF> *
|
|
|
//*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> int commid : ת<><D7AA><EFBFBD>˿ں<CBBF> *
|
|
|
//* int ykytpnt: ת<><D7AA><EFBFBD><EFBFBD>ң<EFBFBD><D2A3>ң<EFBFBD><D2A3><EFBFBD><EFBFBD> *
|
|
|
//* SIO_PARAM_BAOHU_DEF *pBaohuParam :ת<><D7AA><EFBFBD>˿ڱ<CBBF><DAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *
|
|
|
//*<2A><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>int retval : <20><>Ӧ<EFBFBD><D3A6>ʵ<EFBFBD><CAB5>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *
|
|
|
//********************************************************************
|
|
|
int FindProvPntFromYkYtPnt(int commid, int ykytpnt, SIO_PARAM_BAOHU_DEF *pBaohuParam)
|
|
|
{
|
|
|
int i;
|
|
|
PROV_DI_PNT *diprovptr;
|
|
|
|
|
|
if(!pBaohuParam)
|
|
|
{
|
|
|
printf("TIP_(%04d): commid=%d psBaoHu is NULL.\n",
|
|
|
_getpid(), commid + 1);
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
diprovptr = (PROV_DI_PNT*)pBaohuParam->DiPtr;
|
|
|
|
|
|
if(!diprovptr)
|
|
|
{
|
|
|
printf("TIP_(%04d): commid=%d DiPtr is NULL.\n",
|
|
|
_getpid(), commid + 1);
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
for(i=0; i<pBaohuParam->DiNum; i++)
|
|
|
{
|
|
|
if(((int)diprovptr[i].ControlNo) == ykytpnt)
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
if(ShmGetDispYkYtFlag())
|
|
|
{
|
|
|
printf("TIP_(%04d): commid =%d ykytpnt=%d", _getpid(), commid + 1, ykytpnt);
|
|
|
if(i<pBaohuParam->DiNum)
|
|
|
{
|
|
|
printf(" ControlNo=%d.\n", diprovptr[i].ControlNo);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
printf(".\n");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if(i >= pBaohuParam->DiNum)
|
|
|
return -1;
|
|
|
else
|
|
|
return i;
|
|
|
}
|
|
|
|
|
|
BOOL ProvPortYkYtIsTimeOut(int commid, PROV_YKYT_DEF *pProvYkYt)
|
|
|
{
|
|
|
time_t iSaveTime, iCurTime;
|
|
|
struct tm changetm;
|
|
|
DAY_TIME CurTime;
|
|
|
BOOL bReturn;
|
|
|
|
|
|
changetm.tm_hour = pProvYkYt->m_sDayTime.Hour;
|
|
|
changetm.tm_mday = pProvYkYt->m_sDayTime.Day;
|
|
|
changetm.tm_min = pProvYkYt->m_sDayTime.Min;
|
|
|
changetm.tm_mon = pProvYkYt->m_sDayTime.Month-1;
|
|
|
changetm.tm_sec = pProvYkYt->m_sDayTime.Sec;
|
|
|
changetm.tm_year = pProvYkYt->m_sDayTime.Year - 1900;
|
|
|
changetm.tm_isdst = -1;
|
|
|
iSaveTime = mktime(&changetm);
|
|
|
|
|
|
GetLocalTimeEx(&CurTime);
|
|
|
changetm.tm_hour = CurTime.Hour;
|
|
|
changetm.tm_mday = CurTime.Day;
|
|
|
changetm.tm_min = CurTime.Min;
|
|
|
changetm.tm_mon = CurTime.Month-1;
|
|
|
changetm.tm_sec = CurTime.Sec;
|
|
|
changetm.tm_year = CurTime.Year - 1900;
|
|
|
changetm.tm_isdst = -1;
|
|
|
iCurTime = mktime(&changetm);
|
|
|
|
|
|
if((iCurTime-iSaveTime) > pProvYkYt->m_iTimeOut)
|
|
|
{
|
|
|
bReturn = TRUE;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
bReturn = FALSE;
|
|
|
}
|
|
|
|
|
|
if(ShmGetDispYkYtFlag())
|
|
|
{
|
|
|
printf("TIP_(%04d): commid =%d timeout=%d.\n",
|
|
|
_getpid(), commid + 1, pProvYkYt->m_iTimeOut);
|
|
|
|
|
|
printf("TIP_(%04d): curtime %02d:%02d:%02d.\n",
|
|
|
_getpid(), CurTime.Hour, CurTime.Min, CurTime.Sec);
|
|
|
|
|
|
printf("TIP_(%04d): savetime %02d:%02d:%02d.\n",
|
|
|
_getpid(), pProvYkYt->m_sDayTime.Hour,
|
|
|
pProvYkYt->m_sDayTime.Min,
|
|
|
pProvYkYt->m_sDayTime.Sec);
|
|
|
}
|
|
|
|
|
|
return bReturn;
|
|
|
}
|
|
|
|
|
|
BOOL IsProvYkYtAck(int commid, PROV_YKYT_DEF *pProvYkYt)
|
|
|
{
|
|
|
BOOL bReturn;
|
|
|
|
|
|
bReturn = FALSE;
|
|
|
|
|
|
if((STEP_YKYT_SELECT == pProvYkYt->m_iYkYtStep)
|
|
|
&& (pProvYkYt->m_iProvPntIdx >= 0))
|
|
|
{
|
|
|
if(!ProvPortYkYtIsTimeOut(commid, pProvYkYt))
|
|
|
{
|
|
|
bReturn = TRUE;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if(ShmGetDispYkYtFlag())
|
|
|
{
|
|
|
printf("TIP_(%04d): commid=%d ykytpnt is judging timeout.\n",
|
|
|
_getpid(), commid + 1);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if(ShmGetDispYkYtFlag())
|
|
|
{
|
|
|
printf("TIP_(%04d): commid=%d ykyt is not in condition. step=%d, provpntidx=%d.\n",
|
|
|
_getpid(), commid + 1, pProvYkYt->m_iYkYtStep, pProvYkYt->m_iProvPntIdx);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return bReturn;
|
|
|
}
|
|
|
|
|
|
BOOL ShmGetDispYkYtFlag()
|
|
|
{
|
|
|
return FALSE;
|
|
|
}
|
|
|
|
|
|
BOOL ShmGetDispHostLinkFlag()
|
|
|
{
|
|
|
return TRUE;
|
|
|
}
|
|
|
|
|
|
void PortMemoryMalloc(int commid, int type, SIO_PARAM_BAOHU_DEF *pBaohuParam)
|
|
|
{
|
|
|
int i, k, increase;
|
|
|
char entry[128], section[128], szbuf[128];
|
|
|
char *ptr, szDebugInfo[256];
|
|
|
|
|
|
AI_DEF aipntmsg;
|
|
|
DI_DEF dipntmsg;
|
|
|
|
|
|
PROV_AI_PNT aiprovpnt;
|
|
|
PROV_DI_PNT diprovpnt;
|
|
|
PROV_PI_PNT piprovpnt;
|
|
|
|
|
|
if ((commid < 0) || (commid >= MaxPortNum))
|
|
|
return;
|
|
|
|
|
|
if (!IsBaoHuPtr(commid))
|
|
|
return;
|
|
|
|
|
|
char szPortConfig[256];
|
|
|
//GetCurrentDirectory(sizeof(szDir), szDir);
|
|
|
sprintf(szPortConfig, "%s/portconfig.ini", IniFilePath);
|
|
|
|
|
|
switch(type)
|
|
|
{
|
|
|
case PROTOCOL_MASTER:
|
|
|
//SioParam[commid].PortType = PROTOCOL_MASTER;
|
|
|
if (pBaohuParam->AiPtr)
|
|
|
{
|
|
|
sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free(aiptr=0x%08x).\n",
|
|
|
_getpid(), commid + 1, pBaohuParam->AiPtr);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
free(pBaohuParam->AiPtr);
|
|
|
}
|
|
|
|
|
|
if (pBaohuParam->DiPtr)
|
|
|
{
|
|
|
sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free(diptr=0x%08x).\n",
|
|
|
_getpid(), commid + 1, pBaohuParam->DiPtr);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
free(pBaohuParam->DiPtr);
|
|
|
}
|
|
|
|
|
|
if (pBaohuParam->PiPtr)
|
|
|
{
|
|
|
sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free(piptr=0x%08x).\n",
|
|
|
_getpid(), commid + 1, pBaohuParam->PiPtr);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
free(pBaohuParam->PiPtr);
|
|
|
}
|
|
|
|
|
|
if(pBaohuParam->AiNum > 0)
|
|
|
{
|
|
|
pBaohuParam->AiPtr
|
|
|
= (AI_DEF*)malloc(sizeof(AI_DEF)*pBaohuParam->AiNum);
|
|
|
|
|
|
if (pBaohuParam->AiPtr)
|
|
|
{
|
|
|
memset((char*)pBaohuParam->AiPtr, 0,
|
|
|
sizeof(AI_DEF)*pBaohuParam->AiNum);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
sprintf(szDebugInfo, "ERR_(%04d): commid_%02d aiptr=malloc(%d) is failed.\n",
|
|
|
_getpid(), commid + 1, sizeof(AI_DEF)*pBaohuParam->AiNum);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
pBaohuParam->AiNum = 0;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
pBaohuParam->AiNum = 0;
|
|
|
pBaohuParam->AiPtr = NULL;
|
|
|
}
|
|
|
|
|
|
if(pBaohuParam->DiNum > 0)
|
|
|
{
|
|
|
pBaohuParam->DiPtr
|
|
|
= (DI_DEF*)malloc(sizeof(DI_DEF)*pBaohuParam->DiNum);
|
|
|
|
|
|
if (pBaohuParam->DiPtr)
|
|
|
{
|
|
|
memset((char*)pBaohuParam->DiPtr, 0,
|
|
|
sizeof(DI_DEF)*pBaohuParam->DiNum);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
sprintf(szDebugInfo, "ERR_(%04d): commid_%02d diptr=malloc(%d) is failed.\n",
|
|
|
_getpid(), commid + 1, sizeof(DI_DEF)*pBaohuParam->DiNum);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
pBaohuParam->DiNum = 0;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
pBaohuParam->DiNum = 0;
|
|
|
pBaohuParam->DiPtr = NULL;
|
|
|
}
|
|
|
|
|
|
if(pBaohuParam->PiNum > 0)
|
|
|
{
|
|
|
pBaohuParam->PiPtr
|
|
|
= (PI_DEF*)malloc(sizeof(PI_DEF)*pBaohuParam->PiNum);
|
|
|
|
|
|
if (pBaohuParam->PiPtr)
|
|
|
{
|
|
|
memset((char*)pBaohuParam->PiPtr, 0,
|
|
|
sizeof(PI_DEF)*pBaohuParam->PiNum);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
sprintf(szDebugInfo, "ERR_(%04d): commid_%02d piptr=malloc(%d) is failed.\n",
|
|
|
_getpid(), commid, sizeof(PI_DEF)*pBaohuParam->PiNum);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo + 1);
|
|
|
pBaohuParam->PiNum = 0;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
pBaohuParam->PiNum = 0;
|
|
|
pBaohuParam->PiPtr = NULL;
|
|
|
}
|
|
|
|
|
|
sprintf(entry, "Port%d", commid + 1);
|
|
|
for (i = 0; i < pBaohuParam->AiNum; i++)
|
|
|
{
|
|
|
sprintf(section, "Ai%dPolar", i+1);
|
|
|
|
|
|
#ifdef _OS_WINDOWS_DEBUG_
|
|
|
sprintf(szDebugInfo, ">>>>(%04d):[%s]<%s>\n", _getpid(), entry, section);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
#endif
|
|
|
GetPrivateProString(entry, section, "", szbuf, 120, szPortConfig);
|
|
|
if (strlen(szbuf) == 0)
|
|
|
{
|
|
|
// wen 2005.09.28 ȱʡ<C8B1><CAA1><EFBFBD><EFBFBD>Ϊ1
|
|
|
aipntmsg.Polar = 1;
|
|
|
SetPntMsg(commid, i, (void*)&aipntmsg, AI_PNT_TYPE, PNT_POLAR);
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
aipntmsg.Polar = atoi(szbuf) ? 1 : 0;
|
|
|
SetPntMsg(commid, i, (void*)&aipntmsg, AI_PNT_TYPE, PNT_POLAR);
|
|
|
|
|
|
// wen 2005.09.13 <20><><EFBFBD><EFBFBD>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
sprintf(section, "Ai%dInc", i+1);
|
|
|
GetPrivateProString(entry, section, "", szbuf, 120, szPortConfig);
|
|
|
if(strlen(szbuf) == 0)
|
|
|
continue;
|
|
|
increase = atoi(szbuf);
|
|
|
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
// wen 2005.12.01 <20><EFBFBD><DEB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵĶ<D3B5>ȡ
|
|
|
//if(increase > 0)
|
|
|
//{
|
|
|
// for(k=i+1; k<increase; k++)
|
|
|
// {
|
|
|
// if(k >= pBaohuParam->AiNum)
|
|
|
// {
|
|
|
// break;
|
|
|
// }
|
|
|
|
|
|
// SetPntMsg(commid, k, (void*)&aipntmsg, AI_PNT_TYPE, PNT_POLAR);
|
|
|
// }
|
|
|
|
|
|
// i = k;
|
|
|
//}
|
|
|
//================================================================
|
|
|
if(increase > 0)
|
|
|
{
|
|
|
for(k=0; k<increase; k++)
|
|
|
{
|
|
|
if((i+k+1) >= pBaohuParam->AiNum)
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
SetPntMsg(commid, i+k+1, (void*)&aipntmsg, AI_PNT_TYPE, PNT_POLAR);
|
|
|
}
|
|
|
|
|
|
i += k;
|
|
|
}
|
|
|
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
}
|
|
|
|
|
|
GetPrivateProString(entry, "DiAllCtrlNo", "", szbuf, 120, szPortConfig);
|
|
|
if (strlen(szbuf))
|
|
|
{
|
|
|
dipntmsg.ControlNo = atoi(szbuf);
|
|
|
for (i = 0; i < SioParam[commid].m_psBaoHu->DiNum; i++)
|
|
|
{
|
|
|
SetPntMsg(commid, i, (void*)&dipntmsg, DI_PNT_TYPE, PNT_CTRL_NO);
|
|
|
dipntmsg.ControlNo++;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
for (i = 0; i < SioParam[commid].m_psBaoHu->DiNum; i++)
|
|
|
{
|
|
|
sprintf(section, "Di%dCtrlNo", i+1);
|
|
|
#ifdef _OS_WINDOWS_DEBUG_
|
|
|
sprintf(szDebugInfo, ">>>>(%04d):[%s]<%s>\n", _getpid(), entry, section);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
#endif
|
|
|
GetPrivateProString(entry, section, "", szbuf, 120, szPortConfig);
|
|
|
if (strlen(szbuf) == 0)
|
|
|
continue;
|
|
|
|
|
|
dipntmsg.ControlNo = atoi(szbuf);
|
|
|
SetPntMsg(commid, i, (void*)&dipntmsg, DI_PNT_TYPE, PNT_CTRL_NO);
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
case PROTOCOL_SLAVE:
|
|
|
if ((ProvPortCnt+1) > MAX_PROV_PORT_NUM)
|
|
|
{
|
|
|
sprintf(szDebugInfo, "WARN(%04d): commid_%02d is error, the Prov Port is over !!!\n",
|
|
|
_getpid(), commid + 1);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
break;
|
|
|
}
|
|
|
ProvPortCnt++;
|
|
|
//SioParam[commid].PortType = PROTOCOL_SLAVE;
|
|
|
|
|
|
if (pBaohuParam->AiPtr)
|
|
|
{
|
|
|
sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free(aiptr=0x%08x).\n",
|
|
|
_getpid(), commid + 1, pBaohuParam->AiPtr);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
free(pBaohuParam->AiPtr);
|
|
|
}
|
|
|
|
|
|
if (pBaohuParam->DiPtr)
|
|
|
{
|
|
|
sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free(diptr=0x%08x).\n",
|
|
|
_getpid(), commid + 1, pBaohuParam->DiPtr);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
free(pBaohuParam->DiPtr);
|
|
|
}
|
|
|
|
|
|
if (pBaohuParam->PiPtr)
|
|
|
{
|
|
|
sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free(piptr=0x%08x).\n",
|
|
|
_getpid(), commid + 1, pBaohuParam->PiPtr);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
free(pBaohuParam->PiPtr);
|
|
|
}
|
|
|
|
|
|
if(pBaohuParam->ProvSoeBuf.ptrProvSoe)
|
|
|
{
|
|
|
sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free(soeptr=0x%08x).\n",
|
|
|
_getpid(), commid + 1, pBaohuParam->ProvSoeBuf.ptrProvSoe);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
free(pBaohuParam->ProvSoeBuf.ptrProvSoe);
|
|
|
}
|
|
|
|
|
|
if(pBaohuParam->AiNum > 0)
|
|
|
{
|
|
|
pBaohuParam->AiPtr
|
|
|
= (PROV_AI_PNT*)malloc(sizeof(PROV_AI_PNT)*pBaohuParam->AiNum);
|
|
|
|
|
|
if (pBaohuParam->AiPtr)
|
|
|
{
|
|
|
memset((char*)pBaohuParam->AiPtr, 0,
|
|
|
sizeof(PROV_AI_PNT)*pBaohuParam->AiNum);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
sprintf(szDebugInfo, "ERR_(%04d): commid_%02d aiptr=malloc(%d) is failed.\n",
|
|
|
_getpid(), commid + 1, sizeof(PROV_AI_PNT)*pBaohuParam->AiNum);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
pBaohuParam->AiNum = 0;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
pBaohuParam->AiPtr = NULL;
|
|
|
pBaohuParam->AiNum = 0;
|
|
|
}
|
|
|
|
|
|
if(pBaohuParam->DiNum > 0)
|
|
|
{
|
|
|
pBaohuParam->DiPtr
|
|
|
= (PROV_DI_PNT*)malloc(sizeof(PROV_DI_PNT)*pBaohuParam->DiNum);
|
|
|
if (pBaohuParam->DiPtr)
|
|
|
{
|
|
|
memset((char*)pBaohuParam->DiPtr, 0,
|
|
|
sizeof(PROV_DI_PNT)*pBaohuParam->DiNum);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
sprintf(szDebugInfo, "ERR_(%04d): commid_%02d diptr=malloc(%d) is failed.\n",
|
|
|
_getpid(), commid + 1, sizeof(PROV_DI_PNT)*pBaohuParam->DiNum);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
pBaohuParam->DiNum = 0;
|
|
|
}
|
|
|
|
|
|
pBaohuParam->ProvSoeBuf.ptrProvSoe
|
|
|
= (SOE_DEF *)malloc(sizeof(SOE_DEF)*MAX_PROV_SOE);
|
|
|
if(pBaohuParam->ProvSoeBuf.ptrProvSoe)
|
|
|
{
|
|
|
memset((char *)pBaohuParam->ProvSoeBuf.ptrProvSoe, 0,
|
|
|
sizeof(SOE_DEF)*MAX_PROV_SOE);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
sprintf(szDebugInfo, "ERR_(%04d): commid_%02d soeptr=malloc(%d) is failed.\n",
|
|
|
_getpid(), commid + 1, sizeof(SOE_DEF)*MAX_PROV_SOE);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
pBaohuParam->DiNum = 0;
|
|
|
pBaohuParam->DiPtr = NULL;
|
|
|
pBaohuParam->ProvSoeBuf.ptrProvSoe = NULL;
|
|
|
}
|
|
|
|
|
|
if(pBaohuParam->PiNum > 0)
|
|
|
{
|
|
|
pBaohuParam->PiPtr
|
|
|
= (PROV_PI_PNT*)malloc(sizeof(PROV_PI_PNT)*pBaohuParam->PiNum);
|
|
|
if (pBaohuParam->PiPtr)
|
|
|
{
|
|
|
memset((char*)pBaohuParam->PiPtr, 0,
|
|
|
sizeof(PROV_PI_PNT)*pBaohuParam->PiNum);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
sprintf(szDebugInfo, "ERR_(%04d): commid_%02d piptr=malloc(%d) is failed.\n",
|
|
|
_getpid(), commid + 1, sizeof(PROV_PI_PNT)*pBaohuParam->PiNum);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
pBaohuParam->PiNum = 0;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
pBaohuParam->PiPtr = NULL;
|
|
|
pBaohuParam->PiNum = 0;
|
|
|
}
|
|
|
|
|
|
sprintf(entry, "Port%d", commid + 1);
|
|
|
for (i = 0; i < pBaohuParam->AiNum; i++)
|
|
|
{
|
|
|
aiprovpnt.fFactor = 1.0;
|
|
|
sprintf(section, "ProvAi%d", i+1);
|
|
|
#ifdef _OS_WINDOWS_DEBUG_
|
|
|
sprintf(szDebugInfo, ">>>>(%04d): [%s]<%s>\n", _getpid(), entry, section);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
#endif
|
|
|
GetPrivateProString(entry, section, "", szbuf, 120, szPortConfig);
|
|
|
StringToUpper(szbuf);
|
|
|
if (strlen(szbuf) == 0)
|
|
|
continue;
|
|
|
#ifdef _OS_WINDOWS_DEBUG_
|
|
|
sprintf(szDebugInfo, "####(%04d): %s#\n", _getpid(), szbuf);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
#endif
|
|
|
|
|
|
ptr = strstr(szbuf, "A");
|
|
|
if (!ptr)
|
|
|
continue;
|
|
|
aiprovpnt.PortNo = atoi(szbuf) - 1;
|
|
|
aiprovpnt.PntNo = atoi((char*)(ptr+1)) - 1;
|
|
|
#ifdef _OS_WINDOWS_DEBUG_
|
|
|
sprintf(szDebugInfo, "TIP_: commid_%02d provpnt=%d, realport=%d, realpnt=%d\n",
|
|
|
commid + 1, i + 1, aiprovpnt.PortNo, aiprovpnt.PntNo);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
#endif
|
|
|
ptr = strstr(ptr, ",");
|
|
|
if(ptr)
|
|
|
{
|
|
|
aiprovpnt.fFactor = (float)atof(ptr+1);
|
|
|
}
|
|
|
|
|
|
SetPorvPntMsg(commid, i, &aiprovpnt, AI_PNT_TYPE, PNT_PROV_MSG);
|
|
|
|
|
|
sprintf(section, "ProvAi%dInc", i+1);
|
|
|
GetPrivateProString(entry, section, "", szbuf, 120, szPortConfig);
|
|
|
k = atoi(szbuf);
|
|
|
while(k > 0)
|
|
|
{
|
|
|
sprintf(section, "ProvAi%d", i+2);
|
|
|
GetPrivateProString(entry, section, "", szbuf, 120, szPortConfig);
|
|
|
if(strlen(szbuf))
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
i++;
|
|
|
aiprovpnt.PntNo++;
|
|
|
SetPorvPntMsg(commid, i, &aiprovpnt, AI_PNT_TYPE, PNT_PROV_MSG);
|
|
|
#ifdef _OS_WINDOWS_DEBUG_
|
|
|
sprintf(szDebugInfo, "TIP_: commid_%02d provpnt=%d, realport=%d, realpnt=%d\n",
|
|
|
commid + 1, i + 1, aiprovpnt.PortNo, aiprovpnt.PntNo);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
#endif
|
|
|
k--;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
GetPrivateProString(entry, "ProvDiAllCtrlNo", "", szbuf, 120, szPortConfig);
|
|
|
if (strlen(szbuf))
|
|
|
{
|
|
|
diprovpnt.ControlNo = atoi(szbuf);
|
|
|
for (i = 0; i < pBaohuParam->DiNum; i++)
|
|
|
{
|
|
|
SetPorvPntMsg(commid, i, &diprovpnt, DI_PNT_TYPE, PNT_CTRL_NO);
|
|
|
diprovpnt.ControlNo++;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
for (i = 0; i < pBaohuParam->DiNum; i++)
|
|
|
{
|
|
|
sprintf(section, "ProvDi%d", i+1);
|
|
|
#ifdef _OS_WINDOWS_DEBUG_
|
|
|
sprintf(szDebugInfo, ">>>>(%04d): [%s]<%s>\n", _getpid(), entry, section);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
#endif
|
|
|
GetPrivateProString(entry, section, "", szbuf, 120, szPortConfig);
|
|
|
StringToUpper(szbuf);
|
|
|
if (strlen(szbuf) == 0)
|
|
|
continue;
|
|
|
|
|
|
ptr = strstr(szbuf, "D");
|
|
|
if (!ptr)
|
|
|
continue;
|
|
|
diprovpnt.PortNo = atoi(szbuf) - 1;
|
|
|
diprovpnt.PntNo = atoi((char*)(ptr+1)) - 1;
|
|
|
|
|
|
SetPorvPntMsg(commid, i, &diprovpnt, DI_PNT_TYPE, PNT_PROV_MSG);
|
|
|
|
|
|
ptr = strstr(szbuf, ",");
|
|
|
if (ptr)
|
|
|
{
|
|
|
diprovpnt.ControlNo = atoi((char*)(ptr+1));
|
|
|
SetPorvPntMsg(commid, i, &diprovpnt, DI_PNT_TYPE, PNT_CTRL_NO);
|
|
|
}
|
|
|
// wen 2005.03.28 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀص<C4BF><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
else
|
|
|
{
|
|
|
diprovpnt.ControlNo = -1;
|
|
|
}
|
|
|
|
|
|
sprintf(section, "ProvDi%dInc", i+1);
|
|
|
GetPrivateProString(entry, section, "", szbuf, 120, szPortConfig);
|
|
|
k = atoi(szbuf);
|
|
|
while(k > 0)
|
|
|
{
|
|
|
sprintf(section, "ProvDi%d", i+2);
|
|
|
GetPrivateProString(entry, section, "", szbuf, 120, szPortConfig);
|
|
|
if (strlen(szbuf))
|
|
|
break;
|
|
|
|
|
|
i++;
|
|
|
diprovpnt.PntNo++;
|
|
|
SetPorvPntMsg(commid, i, &diprovpnt, DI_PNT_TYPE, PNT_PROV_MSG);
|
|
|
k--;
|
|
|
|
|
|
// wen 2005.03.28 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀص<C4BF><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
if(diprovpnt.ControlNo >= 0)
|
|
|
{
|
|
|
diprovpnt.ControlNo++;
|
|
|
SetPorvPntMsg(commid, i, &diprovpnt, DI_PNT_TYPE, PNT_CTRL_NO);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
for (i = 0; i < pBaohuParam->DiNum; i++)
|
|
|
{
|
|
|
sprintf(section, "ProvDi%dCtrlNo", i+1);
|
|
|
#ifdef _OS_WINDOWS_DEBUG_
|
|
|
sprintf(szDebugInfo, ">>>>(%04d): [%s]<%s>\n", _getpid(), entry, section);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
#endif
|
|
|
|
|
|
GetPrivateProString(entry, section, "", szbuf, 120, szPortConfig);
|
|
|
if (strlen(szbuf) == 0)
|
|
|
continue;
|
|
|
|
|
|
diprovpnt.ControlNo = atoi(szbuf);
|
|
|
SetPorvPntMsg(commid, i, &diprovpnt, DI_PNT_TYPE, PNT_CTRL_NO);
|
|
|
}
|
|
|
|
|
|
for (i = 0; i < pBaohuParam->PiNum; i++)
|
|
|
{
|
|
|
piprovpnt.fFactor = 1.0;
|
|
|
sprintf(section, "ProvPi%d", i+1);
|
|
|
#ifdef _OS_WINDOWS_DEBUG_
|
|
|
sprintf(szDebugInfo, ">>>>(%04d): [%s]<%s>\n", _getpid(), entry, section);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
#endif
|
|
|
GetPrivateProString(entry, section, "", szbuf, 120, szPortConfig);
|
|
|
StringToUpper(szbuf);
|
|
|
if (strlen(szbuf) == 0)
|
|
|
continue;
|
|
|
|
|
|
ptr = strstr(szbuf, "P");
|
|
|
if (!ptr)
|
|
|
continue;
|
|
|
piprovpnt.PortNo = atoi(szbuf) - 1;
|
|
|
piprovpnt.PntNo = atoi((char*)(ptr+1)) - 1;
|
|
|
|
|
|
ptr = strstr(ptr, ",");
|
|
|
if(ptr)
|
|
|
{
|
|
|
piprovpnt.fFactor = (float)atof(ptr+1);
|
|
|
}
|
|
|
|
|
|
SetPorvPntMsg(commid, i, &piprovpnt, PI_PNT_TYPE, PNT_PROV_MSG);
|
|
|
|
|
|
sprintf(section, "ProvPi%dInc", i+1);
|
|
|
GetPrivateProString(entry, section, "", szbuf, 120, szPortConfig);
|
|
|
k = atoi(szbuf);
|
|
|
while(k > 0)
|
|
|
{
|
|
|
sprintf(section, "ProvPi%d", i+2);
|
|
|
GetPrivateProString(entry, section, "", szbuf, 120, szPortConfig);
|
|
|
if (strlen(szbuf))
|
|
|
break;
|
|
|
|
|
|
i++;
|
|
|
piprovpnt.PntNo++;
|
|
|
SetPorvPntMsg(commid, i, &piprovpnt, PI_PNT_TYPE, PNT_PROV_MSG);
|
|
|
k--;
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void PortMemoryMallocEx(int commid, int type, SIO_PARAM_BAOHU_DEF *pBaohuParam)
|
|
|
{
|
|
|
char szDebugInfo[256];
|
|
|
|
|
|
if ((commid < 0) || (commid >= MaxPortNum))
|
|
|
return;
|
|
|
|
|
|
if (!IsBaoHuPtr(commid))
|
|
|
return;
|
|
|
|
|
|
char szPortConfig[256];
|
|
|
//GetCurrentDirectory(sizeof(szDir), szDir);
|
|
|
sprintf(szPortConfig, "%s/portconfig.ini", IniFilePath);
|
|
|
|
|
|
switch(type)
|
|
|
{
|
|
|
case PROTOCOL_MASTER:
|
|
|
//SioParam[commid].PortType = PROTOCOL_MASTER;
|
|
|
if (pBaohuParam->AiPtr)
|
|
|
{
|
|
|
sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free(aiptr=0x%08x).\n",
|
|
|
_getpid(), commid + 1, pBaohuParam->AiPtr);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
free(pBaohuParam->AiPtr);
|
|
|
}
|
|
|
|
|
|
if (pBaohuParam->DiPtr)
|
|
|
{
|
|
|
sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free(diptr=0x%08x).\n",
|
|
|
_getpid(), commid + 1, pBaohuParam->DiPtr);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
free(pBaohuParam->DiPtr);
|
|
|
}
|
|
|
|
|
|
if (pBaohuParam->PiPtr)
|
|
|
{
|
|
|
sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free(piptr=0x%08x).\n",
|
|
|
_getpid(), commid + 1, pBaohuParam->PiPtr);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
free(pBaohuParam->PiPtr);
|
|
|
}
|
|
|
|
|
|
if(pBaohuParam->AiNum > 0)
|
|
|
{
|
|
|
pBaohuParam->AiPtr
|
|
|
= (AI_DEF*)malloc(sizeof(AI_DEF)*pBaohuParam->AiNum);
|
|
|
|
|
|
if (pBaohuParam->AiPtr)
|
|
|
{
|
|
|
memset((char*)pBaohuParam->AiPtr, 0,
|
|
|
sizeof(AI_DEF)*pBaohuParam->AiNum);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
sprintf(szDebugInfo, "ERR_(%04d): commid_%02d aiptr=malloc(%d) is failed.\n",
|
|
|
_getpid(), commid + 1, sizeof(AI_DEF)*pBaohuParam->AiNum);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
pBaohuParam->AiNum = 0;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
pBaohuParam->AiNum = 0;
|
|
|
pBaohuParam->AiPtr = NULL;
|
|
|
}
|
|
|
|
|
|
if(pBaohuParam->DiNum > 0)
|
|
|
{
|
|
|
pBaohuParam->DiPtr
|
|
|
= (DI_DEF*)malloc(sizeof(DI_DEF)*pBaohuParam->DiNum);
|
|
|
|
|
|
if (pBaohuParam->DiPtr)
|
|
|
{
|
|
|
memset((char*)pBaohuParam->DiPtr, 0,
|
|
|
sizeof(DI_DEF)*pBaohuParam->DiNum);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
sprintf(szDebugInfo, "ERR_(%04d): commid_%02d diptr=malloc(%d) is failed.\n",
|
|
|
_getpid(), commid + 1, sizeof(DI_DEF)*pBaohuParam->DiNum);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
pBaohuParam->DiNum = 0;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
pBaohuParam->DiNum = 0;
|
|
|
pBaohuParam->DiPtr = NULL;
|
|
|
}
|
|
|
|
|
|
if(pBaohuParam->PiNum > 0)
|
|
|
{
|
|
|
pBaohuParam->PiPtr
|
|
|
= (PI_DEF*)malloc(sizeof(PI_DEF)*pBaohuParam->PiNum);
|
|
|
|
|
|
if (pBaohuParam->PiPtr)
|
|
|
{
|
|
|
memset((char*)pBaohuParam->PiPtr, 0,
|
|
|
sizeof(PI_DEF)*pBaohuParam->PiNum);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
sprintf(szDebugInfo, "ERR_(%04d): commid_%02d piptr=malloc(%d) is failed.\n",
|
|
|
_getpid(), commid + 1, sizeof(PI_DEF)*pBaohuParam->PiNum);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
pBaohuParam->PiNum = 0;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
pBaohuParam->PiNum = 0;
|
|
|
pBaohuParam->PiPtr = NULL;
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
case PROTOCOL_SLAVE:
|
|
|
if ((ProvPortCnt+1) > MAX_PROV_PORT_NUM)
|
|
|
{
|
|
|
sprintf(szDebugInfo, "WARN(%04d): commid_%02d is error, the Prov Port is over !!!\n",
|
|
|
_getpid(), commid + 1);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
break;
|
|
|
}
|
|
|
ProvPortCnt++;
|
|
|
|
|
|
if (pBaohuParam->AiPtr)
|
|
|
{
|
|
|
sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free(aiptr=0x%08x).\n",
|
|
|
_getpid(), commid + 1, pBaohuParam->AiPtr);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
free(pBaohuParam->AiPtr);
|
|
|
}
|
|
|
|
|
|
if (pBaohuParam->DiPtr)
|
|
|
{
|
|
|
sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free(diptr=0x%08x).\n",
|
|
|
_getpid(), commid + 1, pBaohuParam->DiPtr);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
free(pBaohuParam->DiPtr);
|
|
|
}
|
|
|
|
|
|
if (pBaohuParam->PiPtr)
|
|
|
{
|
|
|
sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free(piptr=0x%08x).\n",
|
|
|
_getpid(), commid + 1, pBaohuParam->PiPtr);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
free(pBaohuParam->PiPtr);
|
|
|
}
|
|
|
|
|
|
if(pBaohuParam->ProvSoeBuf.ptrProvSoe)
|
|
|
{
|
|
|
sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free(soeptr=0x%08x).\n",
|
|
|
_getpid(), commid + 1, pBaohuParam->ProvSoeBuf.ptrProvSoe);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
free(pBaohuParam->ProvSoeBuf.ptrProvSoe);
|
|
|
}
|
|
|
|
|
|
if(pBaohuParam->AiNum > 0)
|
|
|
{
|
|
|
pBaohuParam->AiPtr
|
|
|
= (PROV_AI_PNT*)malloc(sizeof(PROV_AI_PNT)*pBaohuParam->AiNum);
|
|
|
|
|
|
if (pBaohuParam->AiPtr)
|
|
|
{
|
|
|
memset((char*)pBaohuParam->AiPtr, 0,
|
|
|
sizeof(PROV_AI_PNT)*pBaohuParam->AiNum);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
sprintf(szDebugInfo, "ERR_(%04d): commid_%02d aiptr=malloc(%d) is failed.\n",
|
|
|
_getpid(), commid + 1, sizeof(PROV_AI_PNT)*pBaohuParam->AiNum);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
pBaohuParam->AiNum = 0;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
pBaohuParam->AiPtr = NULL;
|
|
|
pBaohuParam->AiNum = 0;
|
|
|
}
|
|
|
|
|
|
if(pBaohuParam->DiNum > 0)
|
|
|
{
|
|
|
pBaohuParam->DiPtr
|
|
|
= (PROV_DI_PNT*)malloc(sizeof(PROV_DI_PNT)*pBaohuParam->DiNum);
|
|
|
if (pBaohuParam->DiPtr)
|
|
|
{
|
|
|
memset((char*)pBaohuParam->DiPtr, 0,
|
|
|
sizeof(PROV_DI_PNT)*pBaohuParam->DiNum);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
sprintf(szDebugInfo, "ERR_(%04d): commid_%02d diptr=malloc(%d) is failed.\n",
|
|
|
_getpid(), commid + 1, sizeof(PROV_DI_PNT)*pBaohuParam->DiNum);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
pBaohuParam->DiNum = 0;
|
|
|
}
|
|
|
|
|
|
pBaohuParam->ProvSoeBuf.ptrProvSoe
|
|
|
= (SOE_DEF *)malloc(sizeof(SOE_DEF)*MAX_PROV_SOE);
|
|
|
if(pBaohuParam->ProvSoeBuf.ptrProvSoe)
|
|
|
{
|
|
|
memset((char *)pBaohuParam->ProvSoeBuf.ptrProvSoe, 0,
|
|
|
sizeof(SOE_DEF)*MAX_PROV_SOE);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
sprintf(szDebugInfo, "ERR_(%04d): commid_%02d soeptr=malloc(%d) is failed.\n",
|
|
|
_getpid(), commid + 1, sizeof(SOE_DEF)*MAX_PROV_SOE);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
pBaohuParam->DiNum = 0;
|
|
|
pBaohuParam->DiPtr = NULL;
|
|
|
pBaohuParam->ProvSoeBuf.ptrProvSoe = NULL;
|
|
|
}
|
|
|
|
|
|
if(pBaohuParam->PiNum > 0)
|
|
|
{
|
|
|
pBaohuParam->PiPtr
|
|
|
= (PROV_PI_PNT*)malloc(sizeof(PROV_PI_PNT)*pBaohuParam->PiNum);
|
|
|
if (pBaohuParam->PiPtr)
|
|
|
{
|
|
|
memset((char*)pBaohuParam->PiPtr, 0,
|
|
|
sizeof(PROV_PI_PNT)*pBaohuParam->PiNum);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
sprintf(szDebugInfo, "ERR_(%04d): commid_%02d piptr=malloc(%d) is failed.\n",
|
|
|
_getpid(), commid + 1, sizeof(PROV_PI_PNT)*pBaohuParam->PiNum);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
pBaohuParam->PiNum = 0;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
pBaohuParam->PiPtr = NULL;
|
|
|
pBaohuParam->PiNum = 0;
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
BOOL PortDataPntInit(int commid, int type, SIO_PARAM_BAOHU_DEF *pBaohuParam)
|
|
|
{
|
|
|
int i, k, increase;
|
|
|
char entry[128], section[128], szbuf[128];
|
|
|
char *ptr;
|
|
|
|
|
|
AI_DEF aipntmsg;
|
|
|
DI_DEF dipntmsg;
|
|
|
|
|
|
PROV_AI_PNT aiprovpnt;
|
|
|
PROV_DI_PNT diprovpnt;
|
|
|
PROV_PI_PNT piprovpnt;
|
|
|
|
|
|
if((commid < 0) || (commid >= MaxPortNum))
|
|
|
{
|
|
|
return FALSE;
|
|
|
}
|
|
|
|
|
|
if(!IsBaoHuPtr(commid))
|
|
|
{
|
|
|
return FALSE;
|
|
|
}
|
|
|
|
|
|
char szPortConfig[256];
|
|
|
//GetCurrentDirectory(sizeof(szDir), szDir);
|
|
|
sprintf(szPortConfig, "%s/portconfig.ini", IniFilePath);
|
|
|
|
|
|
switch(type)
|
|
|
{
|
|
|
case PROTOCOL_MASTER:
|
|
|
sprintf(entry, "Port%d", commid + 1);
|
|
|
for (i = 0; i < pBaohuParam->AiNum; i++)
|
|
|
{
|
|
|
sprintf(section, "Ai%dPolar", i+1);
|
|
|
|
|
|
#ifdef _OS_WINDOWS_DEBUG_
|
|
|
sprintf(szDebugInfo, ">>>>(%04d):[%s]<%s>\n", _getpid(), entry, section);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
#endif
|
|
|
GetPrivateProString(entry, section, "", szbuf, 120, szPortConfig);
|
|
|
if (strlen(szbuf) == 0)
|
|
|
{
|
|
|
// wen 2005.09.28 ȱʡ<C8B1><CAA1><EFBFBD><EFBFBD>Ϊ1
|
|
|
aipntmsg.Polar = 1;
|
|
|
SetPntMsg(commid, i, (void*)&aipntmsg, AI_PNT_TYPE, PNT_POLAR);
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
aipntmsg.Polar = atoi(szbuf) ? 1 : 0;
|
|
|
SetPntMsg(commid, i, (void*)&aipntmsg, AI_PNT_TYPE, PNT_POLAR);
|
|
|
|
|
|
// wen 2005.09.13 <20><><EFBFBD><EFBFBD>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
sprintf(section, "Ai%dInc", i+1);
|
|
|
GetPrivateProString(entry, section, "", szbuf, 120, szPortConfig);
|
|
|
if(strlen(szbuf) == 0)
|
|
|
continue;
|
|
|
increase = atoi(szbuf);
|
|
|
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
// wen 2005.12.01 <20><EFBFBD><DEB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵĶ<D3B5>ȡ
|
|
|
//if(increase > 0)
|
|
|
//{
|
|
|
// for(k=i+1; k<increase; k++)
|
|
|
// {
|
|
|
// if(k >= pBaohuParam->AiNum)
|
|
|
// {
|
|
|
// break;
|
|
|
// }
|
|
|
|
|
|
// SetPntMsg(commid, k, (void*)&aipntmsg, AI_PNT_TYPE, PNT_POLAR);
|
|
|
// }
|
|
|
|
|
|
// i = k;
|
|
|
//}
|
|
|
//================================================================
|
|
|
if(increase > 0)
|
|
|
{
|
|
|
for(k=0; k<increase; k++)
|
|
|
{
|
|
|
if((i+k+1) >= pBaohuParam->AiNum)
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
SetPntMsg(commid, i+k+1, (void*)&aipntmsg, AI_PNT_TYPE, PNT_POLAR);
|
|
|
}
|
|
|
|
|
|
i += k;
|
|
|
}
|
|
|
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
}
|
|
|
|
|
|
GetPrivateProString(entry, "DiAllCtrlNo", "", szbuf, 120, szPortConfig);
|
|
|
if (strlen(szbuf))
|
|
|
{
|
|
|
dipntmsg.ControlNo = atoi(szbuf);
|
|
|
for (i = 0; i < SioParam[commid].m_psBaoHu->DiNum; i++)
|
|
|
{
|
|
|
SetPntMsg(commid, i, (void*)&dipntmsg, DI_PNT_TYPE, PNT_CTRL_NO);
|
|
|
dipntmsg.ControlNo++;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
for (i = 0; i < SioParam[commid].m_psBaoHu->DiNum; i++)
|
|
|
{
|
|
|
sprintf(section, "Di%dCtrlNo", i+1);
|
|
|
#ifdef _OS_WINDOWS_DEBUG_
|
|
|
sprintf(szDebugInfo, ">>>>(%04d):[%s]<%s>\n", _getpid(), entry, section);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
#endif
|
|
|
GetPrivateProString(entry, section, "", szbuf, 120, szPortConfig);
|
|
|
if (strlen(szbuf) == 0)
|
|
|
continue;
|
|
|
|
|
|
dipntmsg.ControlNo = atoi(szbuf);
|
|
|
SetPntMsg(commid, i, (void*)&dipntmsg, DI_PNT_TYPE, PNT_CTRL_NO);
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
case PROTOCOL_SLAVE:
|
|
|
sprintf(entry, "Port%d", commid + 1);
|
|
|
for (i = 0; i < pBaohuParam->AiNum; i++)
|
|
|
{
|
|
|
aiprovpnt.fFactor = 1.0;
|
|
|
sprintf(section, "ProvAi%d", i+1);
|
|
|
#ifdef _OS_WINDOWS_DEBUG_
|
|
|
sprintf(szDebugInfo, ">>>>(%04d): [%s]<%s>\n", _getpid(), entry, section);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
#endif
|
|
|
GetPrivateProString(entry, section, "", szbuf, 120, szPortConfig);
|
|
|
StringToUpper(szbuf);
|
|
|
if (strlen(szbuf) == 0)
|
|
|
continue;
|
|
|
#ifdef _OS_WINDOWS_DEBUG_
|
|
|
sprintf(szDebugInfo, "####(%04d): %s#\n", _getpid(), szbuf);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
#endif
|
|
|
|
|
|
ptr = strstr(szbuf, "A");
|
|
|
if (!ptr)
|
|
|
continue;
|
|
|
aiprovpnt.PortNo = atoi(szbuf) - 1;
|
|
|
aiprovpnt.PntNo = atoi((char*)(ptr+1)) - 1;
|
|
|
#ifdef _OS_WINDOWS_DEBUG_
|
|
|
sprintf(szDebugInfo, "TIP_: commid_%02d provpnt=%d, realport=%d, realpnt=%d\n",
|
|
|
commid + 1, i + 1, aiprovpnt.PortNo, aiprovpnt.PntNo);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
#endif
|
|
|
ptr = strstr(ptr, ",");
|
|
|
if(ptr)
|
|
|
{
|
|
|
aiprovpnt.fFactor = (float)atof(ptr+1);
|
|
|
}
|
|
|
|
|
|
SetPorvPntMsg(commid, i, &aiprovpnt, AI_PNT_TYPE, PNT_PROV_MSG);
|
|
|
|
|
|
sprintf(section, "ProvAi%dInc", i+1);
|
|
|
GetPrivateProString(entry, section, "", szbuf, 120, szPortConfig);
|
|
|
k = atoi(szbuf);
|
|
|
while(k > 0)
|
|
|
{
|
|
|
sprintf(section, "ProvAi%d", i+2);
|
|
|
GetPrivateProString(entry, section, "", szbuf, 120, szPortConfig);
|
|
|
if (strlen(szbuf))
|
|
|
break;
|
|
|
|
|
|
i++;
|
|
|
aiprovpnt.PntNo++;
|
|
|
SetPorvPntMsg(commid, i, &aiprovpnt, AI_PNT_TYPE, PNT_PROV_MSG);
|
|
|
#ifdef _OS_WINDOWS_DEBUG_
|
|
|
sprintf(szDebugInfo, "TIP_: commid_%02d provpnt=%d, realport=%d, realpnt=%d\n",
|
|
|
commid + 1, i + 1, aiprovpnt.PortNo, aiprovpnt.PntNo);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
#endif
|
|
|
k--;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
GetPrivateProString(entry, "ProvDiAllCtrlNo", "", szbuf, 120, szPortConfig);
|
|
|
if (strlen(szbuf))
|
|
|
{
|
|
|
diprovpnt.ControlNo = atoi(szbuf);
|
|
|
for (i = 0; i < pBaohuParam->DiNum; i++)
|
|
|
{
|
|
|
SetPorvPntMsg(commid, i, &diprovpnt, DI_PNT_TYPE, PNT_CTRL_NO);
|
|
|
diprovpnt.ControlNo++;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
for (i = 0; i < pBaohuParam->DiNum; i++)
|
|
|
{
|
|
|
sprintf(section, "ProvDi%d", i+1);
|
|
|
#ifdef _OS_WINDOWS_DEBUG_
|
|
|
sprintf(szDebugInfo, ">>>>(%04d): [%s]<%s>\n", _getpid(), entry, section);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
#endif
|
|
|
GetPrivateProString(entry, section, "", szbuf, 120, szPortConfig);
|
|
|
StringToUpper(szbuf);
|
|
|
if (strlen(szbuf) == 0)
|
|
|
continue;
|
|
|
|
|
|
ptr = strstr(szbuf, "D");
|
|
|
if (!ptr)
|
|
|
continue;
|
|
|
diprovpnt.PortNo = atoi(szbuf) - 1;
|
|
|
diprovpnt.PntNo = atoi((char*)(ptr+1)) - 1;
|
|
|
|
|
|
SetPorvPntMsg(commid, i, &diprovpnt, DI_PNT_TYPE, PNT_PROV_MSG);
|
|
|
|
|
|
ptr = strstr(szbuf, ",");
|
|
|
if (ptr)
|
|
|
{
|
|
|
diprovpnt.ControlNo = atoi((char*)(ptr+1));
|
|
|
SetPorvPntMsg(commid, i, &diprovpnt, DI_PNT_TYPE, PNT_CTRL_NO);
|
|
|
}
|
|
|
// wen 2005.03.28 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀص<C4BF><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
else
|
|
|
{
|
|
|
diprovpnt.ControlNo = -1;
|
|
|
}
|
|
|
|
|
|
sprintf(section, "ProvDi%dInc", i+1);
|
|
|
GetPrivateProString(entry, section, "", szbuf, 120, szPortConfig);
|
|
|
k = atoi(szbuf);
|
|
|
while(k > 0)
|
|
|
{
|
|
|
sprintf(section, "ProvDi%d", i+2);
|
|
|
GetPrivateProString(entry, section, "", szbuf, 120, szPortConfig);
|
|
|
if (strlen(szbuf))
|
|
|
break;
|
|
|
|
|
|
i++;
|
|
|
diprovpnt.PntNo++;
|
|
|
SetPorvPntMsg(commid, i, &diprovpnt, DI_PNT_TYPE, PNT_PROV_MSG);
|
|
|
k--;
|
|
|
|
|
|
// wen 2005.03.28 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀص<C4BF><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
if(diprovpnt.ControlNo >= 0)
|
|
|
{
|
|
|
diprovpnt.ControlNo++;
|
|
|
SetPorvPntMsg(commid, i, &diprovpnt, DI_PNT_TYPE, PNT_CTRL_NO);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
for (i = 0; i < pBaohuParam->DiNum; i++)
|
|
|
{
|
|
|
sprintf(section, "ProvDi%dCtrlNo", i+1);
|
|
|
#ifdef _OS_WINDOWS_DEBUG_
|
|
|
sprintf(szDebugInfo, ">>>>(%04d): [%s]<%s>\n", _getpid(), entry, section);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
#endif
|
|
|
|
|
|
GetPrivateProString(entry, section, "", szbuf, 120, szPortConfig);
|
|
|
if (strlen(szbuf) == 0)
|
|
|
continue;
|
|
|
|
|
|
diprovpnt.ControlNo = atoi(szbuf);
|
|
|
SetPorvPntMsg(commid, i, &diprovpnt, DI_PNT_TYPE, PNT_CTRL_NO);
|
|
|
}
|
|
|
|
|
|
for (i = 0; i < pBaohuParam->PiNum; i++)
|
|
|
{
|
|
|
piprovpnt.fFactor = 1.0;
|
|
|
sprintf(section, "ProvPi%d", i+1);
|
|
|
#ifdef _OS_WINDOWS_DEBUG_
|
|
|
sprintf(szDebugInfo, ">>>>(%04d): [%s]<%s>\n", _getpid(), entry, section);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
#endif
|
|
|
GetPrivateProString(entry, section, "", szbuf, 120, szPortConfig);
|
|
|
StringToUpper(szbuf);
|
|
|
if (strlen(szbuf) == 0)
|
|
|
continue;
|
|
|
|
|
|
ptr = strstr(szbuf, "P");
|
|
|
if (!ptr)
|
|
|
continue;
|
|
|
piprovpnt.PortNo = atoi(szbuf) - 1;
|
|
|
piprovpnt.PntNo = atoi((char*)(ptr+1)) - 1;
|
|
|
|
|
|
ptr = strstr(ptr, ",");
|
|
|
if(ptr)
|
|
|
{
|
|
|
piprovpnt.fFactor = (float)atof(ptr+1);
|
|
|
}
|
|
|
|
|
|
SetPorvPntMsg(commid, i, &piprovpnt, PI_PNT_TYPE, PNT_PROV_MSG);
|
|
|
|
|
|
sprintf(section, "ProvPi%dInc", i+1);
|
|
|
GetPrivateProString(entry, section, "", szbuf, 120, szPortConfig);
|
|
|
k = atoi(szbuf);
|
|
|
while(k > 0)
|
|
|
{
|
|
|
sprintf(section, "ProvPi%d", i+2);
|
|
|
GetPrivateProString(entry, section, "", szbuf, 120, szPortConfig);
|
|
|
if (strlen(szbuf))
|
|
|
break;
|
|
|
|
|
|
i++;
|
|
|
piprovpnt.PntNo++;
|
|
|
SetPorvPntMsg(commid, i, &piprovpnt, PI_PNT_TYPE, PNT_PROV_MSG);
|
|
|
k--;
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
return TRUE;
|
|
|
}
|
|
|
|
|
|
void PortWriteDataFree(int commid)
|
|
|
{
|
|
|
/*
|
|
|
char szDebugInfo[256];
|
|
|
|
|
|
sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free all write data begin...\n",
|
|
|
_getpid(), commid);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
|
|
|
while (SioParam[commid].WriteData)
|
|
|
{
|
|
|
DelNode(commid);
|
|
|
}
|
|
|
|
|
|
sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free all write data end.\n",
|
|
|
_getpid(), commid);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
*/
|
|
|
}
|
|
|
|
|
|
void PortMemoryFree(int commid, SIO_PARAM_DEF *pGenParam)
|
|
|
{
|
|
|
char szDebugInfo[256];
|
|
|
|
|
|
//sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free memory begin.\n", _getpid(), commid);
|
|
|
//OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
if (pGenParam->m_psBaoHu)
|
|
|
{
|
|
|
if (pGenParam->m_psBaoHu->AiPtr)
|
|
|
{
|
|
|
free(pGenParam->m_psBaoHu->AiPtr);
|
|
|
sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free ai memory.\n", _getpid(), commid + 1);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
}
|
|
|
|
|
|
if (pGenParam->m_psBaoHu->DiPtr)
|
|
|
{
|
|
|
free(pGenParam->m_psBaoHu->DiPtr);
|
|
|
sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free di memory.\n", _getpid(), commid + 1);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
}
|
|
|
|
|
|
if (pGenParam->m_psBaoHu->PiPtr)
|
|
|
{
|
|
|
free(pGenParam->m_psBaoHu->PiPtr);
|
|
|
sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free pi memory.\n", _getpid(), commid + 1);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
}
|
|
|
|
|
|
if(pGenParam->m_psBaoHu->ProvSoeBuf.ptrProvSoe)
|
|
|
{
|
|
|
free(pGenParam->m_psBaoHu->ProvSoeBuf.ptrProvSoe);
|
|
|
sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free ProvSoe memory.\n", _getpid(), commid + 1);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
}
|
|
|
|
|
|
free(pGenParam->m_psBaoHu);
|
|
|
sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free psBaohu memory.\n", _getpid(), commid + 1);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
}
|
|
|
|
|
|
if (pGenParam->m_psSerial)
|
|
|
{
|
|
|
free(pGenParam->m_psSerial);
|
|
|
sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free psSerial memory.\n", _getpid(), commid + 1);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
}
|
|
|
|
|
|
if (pGenParam->ExtInfo)
|
|
|
{
|
|
|
// wen 2005.04.13 <20><>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD>ʱ<EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
|
|
|
if (FunCallPtr[SioParam[commid].ProtocolIdx].ProtocolExit)
|
|
|
{
|
|
|
FunCallPtr[SioParam[commid].ProtocolIdx].ProtocolExit(commid);
|
|
|
sprintf(szDebugInfo, "TIP_(%04d): commid_%02d Protocol Exit.\n", _getpid(), commid + 1);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
}
|
|
|
|
|
|
HEAP_FREE(pGenParam->ExtInfo);
|
|
|
//free(pGenParam->ExtInfo);
|
|
|
sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free ExtInfo memory.\n", _getpid(), commid + 1);
|
|
|
OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
}
|
|
|
|
|
|
PortWriteDataFree(commid);
|
|
|
|
|
|
pGenParam->m_psBaoHu = NULL;
|
|
|
pGenParam->m_psSerial = NULL;
|
|
|
pGenParam->ExtInfo = NULL;
|
|
|
|
|
|
//sprintf(szDebugInfo, "TIP_(%04d): commid_%02d free memory end.\n", _getpid(), commid + 1);
|
|
|
//OutputDebugString((LPCWSTR)szDebugInfo);
|
|
|
}
|
|
|
|
|
|
BOOL IsBaoHuPtr(int commid)
|
|
|
{
|
|
|
char szInfo[256];
|
|
|
|
|
|
if ((commid < 0) || (commid >=MaxPortNum))
|
|
|
return FALSE;
|
|
|
|
|
|
if (!SioParam[commid].m_psBaoHu)
|
|
|
{
|
|
|
sprintf(szInfo, "commid_%02d psBaoHu is NULL.\n", commid + 1);
|
|
|
PrintFormatMessage(MSG_CLASS_TIP, szInfo);
|
|
|
return FALSE;
|
|
|
}
|
|
|
|
|
|
return TRUE;
|
|
|
}
|
|
|
|
|
|
BOOL IsExtInfoPtr(int commid)
|
|
|
{
|
|
|
char szInfo[256];
|
|
|
|
|
|
if ((commid < 0) || (commid >=MaxPortNum))
|
|
|
return FALSE;
|
|
|
|
|
|
if (!SioParam[commid].ExtInfo)
|
|
|
{
|
|
|
sprintf(szInfo, "commid_%02d ExtInfo is NULL.\n", commid + 1);
|
|
|
PrintFormatMessage(MSG_CLASS_TIP, szInfo);
|
|
|
return FALSE;
|
|
|
}
|
|
|
|
|
|
return TRUE;
|
|
|
}
|
|
|
|
|
|
BOOL IsSerialPtr(int commid)
|
|
|
{
|
|
|
char szInfo[256];
|
|
|
|
|
|
if ((commid < 0) || (commid >=MaxPortNum))
|
|
|
return FALSE;
|
|
|
|
|
|
if (!SioParam[commid].m_psSerial)
|
|
|
{
|
|
|
sprintf(szInfo, "commid_%02d psSerial is NULL.\n", commid + 1);
|
|
|
PrintFormatMessage(MSG_CLASS_TIP, szInfo);
|
|
|
return FALSE;
|
|
|
}
|
|
|
|
|
|
return TRUE;
|
|
|
}
|
|
|
|
|
|
int ShmGetPortFlag(int commid, int rwflag)
|
|
|
{
|
|
|
if(commid >= DEFAULT_MAX_PORT_NUM)
|
|
|
return 0;
|
|
|
|
|
|
return SioParam[commid].OpenFlag;
|
|
|
}
|
|
|
|
|
|
void SendProtectCmdToDev(int commid, RTUMSG *rtumsg)
|
|
|
{
|
|
|
//if(SioParam[commid].OpenFlag == 0)
|
|
|
if(!ShmGetPortFlag(commid, FLAG_OPEN))
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if(SioParam[commid].ProtocolIdx < 1)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if(FunCallPtr[SioParam[commid].ProtocolIdx].BaoHuCmdProcess)
|
|
|
{
|
|
|
FunCallPtr[SioParam[commid].ProtocolIdx].BaoHuCmdProcess(commid, rtumsg, FALSE);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void PutBaohuDataToPort(RTUMSG *rtumsg)
|
|
|
{
|
|
|
int commid;
|
|
|
|
|
|
commid = rtumsg->PortIdx;
|
|
|
//if(SioParam[commid].OpenFlag == 0)
|
|
|
if(!ShmGetPortFlag(commid, FLAG_OPEN))
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if(SioParam[commid].ProtocolIdx < 1)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if(FunCallPtr[SioParam[commid].ProtocolIdx].BaoHuCmdProcess)
|
|
|
{
|
|
|
FunCallPtr[SioParam[commid].ProtocolIdx].BaoHuCmdProcess(commid, rtumsg, TRUE);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void PutBaohuDataToPortEx(int commid, RTUMSG *rtumsg)
|
|
|
{
|
|
|
if(!ShmGetPortFlag(commid, FLAG_OPEN))
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if(SioParam[commid].ProtocolIdx < 1)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if(FunCallPtr[SioParam[commid].ProtocolIdx].BaoHuCmdProcess)
|
|
|
{
|
|
|
FunCallPtr[SioParam[commid].ProtocolIdx].BaoHuCmdProcess(commid, rtumsg, TRUE);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void SendDataToAllScadaProtectPort(RTUMSG *rtumsg)
|
|
|
{
|
|
|
int i, ProtocolIdx;
|
|
|
|
|
|
ProtocolIdx = GetPortProtocolIdx((char*)"SCADAPROTECT");
|
|
|
for(i=0; i<MaxPortNum; i++)
|
|
|
{
|
|
|
if(SioParam[i].ProtocolIdx == ProtocolIdx)
|
|
|
{
|
|
|
//rtumsg->PortIdx = i;
|
|
|
//PutBaohuDataToPort(rtumsg);
|
|
|
PutBaohuDataToPortEx(i, rtumsg);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
int GetBaohuDB(int commid, int iProvAddr, GROUPDEF **ppBaoHuDB)
|
|
|
{
|
|
|
int iGrpNum, iProtocolIdx;
|
|
|
|
|
|
if((commid < 0) || (commid > MaxPortNum))
|
|
|
{
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
if(SioParam[commid].ProtocolIdx < 1)
|
|
|
{
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
iProtocolIdx = SioParam[commid].ProtocolIdx;
|
|
|
if(FunCallPtr[iProtocolIdx].GetBaohuDataBase)
|
|
|
{
|
|
|
iGrpNum = FunCallPtr[iProtocolIdx].GetBaohuDataBase(commid, iProvAddr, ppBaoHuDB);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
iGrpNum = 0;
|
|
|
}
|
|
|
|
|
|
if(iGrpNum == 0)
|
|
|
{
|
|
|
*ppBaoHuDB = NULL;
|
|
|
}
|
|
|
|
|
|
return iGrpNum;
|
|
|
}
|
|
|
|
|
|
int GetSioParam(SIO_PARAM_DEF **ppParam)
|
|
|
{
|
|
|
*ppParam = SioParam;
|
|
|
|
|
|
return GetMaxPort();
|
|
|
}
|
|
|
|
|
|
int GetDevParam(DEV_DEF **ppParam)
|
|
|
{
|
|
|
*ppParam = &DevParam[iCurDevIdx];
|
|
|
return GetMaxPort();
|
|
|
}
|
|
|
|
|
|
int SetCurPort(int PortNo)
|
|
|
{
|
|
|
CurPort = PortNo;
|
|
|
|
|
|
if(CurPort < 0)
|
|
|
{
|
|
|
RealDataDispFlag = 0;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
RealDataDispFlag = 1;
|
|
|
}
|
|
|
|
|
|
return CurPort;
|
|
|
}
|
|
|
|
|
|
int GetCurPortEx()
|
|
|
{
|
|
|
return CurPort;
|
|
|
}
|
|
|
|
|
|
int SetDispFlag(int iFlag)
|
|
|
{
|
|
|
RealDataDispFlag = iFlag;
|
|
|
|
|
|
return RealDataDispFlag;
|
|
|
}
|
|
|
|
|
|
// <20><>ȡȫ<C8A1>ֱ<EFBFBD><D6B1><EFBFBD>
|
|
|
SIO_PARAM_DEF *GetSioParamPtr()
|
|
|
{
|
|
|
return SioParam;
|
|
|
}
|