📄 udcfgbin.c
字号:
/* return contents of structure */
*lpBoardCfg = vcur;
break;
} /* switch */
/* indicate success or failure */
return (ok);
} /* ReadBoardCfgStruct */
/***********************************************************************/
/* read the config TOPIC structure as a binary image;
return TRUE if successful */
static
BOOL
WINAPI
ReadTopicCfgStruct( BUFFERED_FILE *SourceFile,
LPTOPIC_CFG lpTopicCfg,
long lVersion )
{
TOPIC_CFG vcur;
BOOL ok;
/* initialize return value */
ok = TRUE;
/* handle according to version of configuration file */
switch( lVersion ) {
case 1 :
default: /* versions 1 and 2 - latest - identical, so direct read */
if (ok)
ok = ReadNextBuffer( SourceFile, (char *) &vcur.tc_chainLink, sizeof(vcur.tc_chainLink));
if (ok)
ok = ReadNextBuffer( SourceFile, (char *) &vcur.tc_channelID, sizeof(vcur.tc_channelID));
if (ok)
ok = ReadNextBuffer( SourceFile, (char *) &vcur.tc_name[0], sizeof(vcur.tc_name));
if (ok)
ok = ReadNextBuffer( SourceFile, (char *) &vcur.tc_topicAddress, sizeof(vcur.tc_topicAddress));
if (ok)
ok = ReadNextBuffer( SourceFile, (char *) &vcur.tc_coilReadSize, sizeof(vcur.tc_coilReadSize));
if (ok)
ok = ReadNextBuffer( SourceFile, (char *) &vcur.tc_regReadSize, sizeof(vcur.tc_regReadSize));
if (ok)
ok = ReadNextBuffer( SourceFile, (char *) &vcur.tc_updateInterval, sizeof(vcur.tc_updateInterval));
/* return contents of structure */
*lpTopicCfg = vcur;
break;
} /* switch */
/* indicate success or failure */
return (ok);
} /* ReadTopicCfgStruct */
/***********************************************************************
***********************************************************************
* Routines for writing CFG files as binary structures *
***********************************************************************
***********************************************************************/
/********************************************************************/
/** write configuration as binary structures to configuration file.
returns TRUE if successful **/
BOOL
WINAPI
WriteConfigsStruct (BUFFERED_FILE *DestFile)
{
BOOL ok;
int i;
LPBOARD_CFG lpBoardCfg;
LPTOPIC_CFG lpTopicCfg;
CHAINSCANNER board_scanner;
CHAINSCANNER topic_scanner;
/* write file version header, indicate binary mode */
ok = WriteVersion(DestFile, CFGVER, '\0');
if (bUsesComPorts) {
/* write first 4 comport data structures */
for( i=1; ok && (i <= 4); i++ ) {
ok = WritePortCfgStruct( DestFile, &comPort[i-1] );
}
}
if (bUsesBoards) {
/* write board data structures */
if( ok ) {
lpBoardCfg = (LPBOARD_CFG) FindFirstItem (&BoardCfgList,
SCAN_FROM_HEAD, /* search forward */
NULL, /* any item in list */
NULL, /* no comparison value */
&board_scanner); /* used for FindNextItem */
while( ok && (lpBoardCfg != (LPBOARD_CFG)NULL) ) {
/* indicate more boards available */
ok = WriteNextAnyMore( DestFile, TRUE );
if ( ok ) {
/* write board structure to file */
ok = WriteBoardCfgStruct( DestFile, lpBoardCfg );
}
/* get pointer to next board */
lpBoardCfg = (LPBOARD_CFG) FindNextItem (&board_scanner);
}
if (ok) {
/* indicate no more boards available */
ok = WriteNextAnyMore(DestFile, FALSE);
}
}
}
/* write topic data structures */
if( ok ) {
lpTopicCfg = (LPTOPIC_CFG) FindFirstItem (&TopicCfgList,
SCAN_FROM_HEAD, /* search forward */
NULL, /* any item in list */
NULL, /* no comparison value */
&topic_scanner); /* used for FindNextItem */
while (ok && (lpTopicCfg != (LPTOPIC_CFG) NULL)) {
/* indicate more topics available */
ok = WriteNextAnyMore( DestFile, TRUE );
if( ok ) {
/* write topic structure to file */
ok = WriteTopicCfgStruct( DestFile, lpTopicCfg );
}
/* get pointer to next topic */
lpTopicCfg = (LPTOPIC_CFG) FindNextItem (&topic_scanner);
}
if( ok ) {
/* indicate no more topics available */
ok = WriteNextAnyMore (DestFile, FALSE);
}
}
if (bUsesComPorts) {
/* now write out ports 5 thru MAX_COMPORT at end */
for( i=5; ok && (i<=MAX_COMPORT); i++ ) {
/* indicate another port available */
ok = WriteNextAnyMore( DestFile, TRUE );
if( ok ) {
/* write COM port structure to file */
ok = WritePortCfgStruct( DestFile, &comPort[i-1] );
}
}
/* write out end of com ports flag */
if( ok ) {
ok = WriteNextAnyMore( DestFile, FALSE );
}
}
/* indicate success or failure */
return (ok);
} /* WriteConfigsStruct */
/***********************************************************************/
/* write the config COM port structure as a binary image;
return TRUE if successful */
static
BOOL
WINAPI
WritePortCfgStruct( BUFFERED_FILE *DestFile,
LPWW_CP_PARAMS lpCpParams )
{
WW_CP_PARAMS vcur;
BOOL ok;
/* initialize return value */
ok = TRUE;
/* copy to local structure */
vcur = *lpCpParams;
/* attempt to write structure to file */
if (ok)
ok = WriteNextBuffer( DestFile, (char *) &vcur, sizeof(vcur));
/** Note: The WW_CP_PARAMS structure happens to be identically
aligned on both Win16 and Win32 platforms, so direct reads
and writes of the entire structure are OK. **/
/* indicate success or failure */
return (ok);
} /* WritePortCfgStruct */
/***********************************************************************/
/* write the config BOARD_CFG structure as a binary image;
return TRUE if successful */
static
BOOL
WINAPI
WriteBoardCfgStruct( BUFFERED_FILE *DestFile,
LPBOARD_CFG lpBoardCfg )
{
BOARD_CFG vcur;
BOOL ok;
/* initialize return value */
ok = TRUE;
/* copy to local structure */
vcur = *lpBoardCfg;
/* clear local chainLink -- forward/backward pointers
will be reassigned the next time the program runs, anyway */
memset (&vcur.cp_chainLink, 0, sizeof(vcur.cp_chainLink));
/* attempt to write structure to file */
if (ok)
ok = WriteNextBuffer( DestFile, (char *) &vcur.cp_chainLink, sizeof(vcur.cp_chainLink));
if (ok)
ok = WriteNextBuffer( DestFile, (char *) &vcur.cp_channelID, sizeof(vcur.cp_channelID));
if (ok)
ok = WriteNextBuffer( DestFile, (char *) &vcur.cp_name[0], sizeof(vcur.cp_name));
if (ok)
ok = WriteNextBuffer( DestFile, (char *) &vcur.cp_memSegment, sizeof(vcur.cp_memSegment));
if (ok)
ok = WriteNextBuffer( DestFile, (char *) &vcur.cp_ioAddr, sizeof(vcur.cp_ioAddr));
if (ok)
ok = WriteNextBuffer( DestFile, (char *) &vcur.cp_replyTimeout, sizeof(vcur.cp_replyTimeout));
/* indicate success or failure */
return (ok);
} /* WriteBoardCfgStruct */
/***********************************************************************/
/* write the config TOPIC structure as a binary image;
return TRUE if successful */
static
BOOL
WINAPI
WriteTopicCfgStruct( BUFFERED_FILE *DestFile,
LPTOPIC_CFG lpTopicCfg )
{
TOPIC_CFG vcur;
BOOL ok;
/* initialize return value */
ok = TRUE;
/* copy to local structure */
vcur = *lpTopicCfg;
/* clear local chainLink -- forward/backward pointers
will be reassigned the next time the program runs, anyway */
memset (&vcur.tc_chainLink, 0, sizeof(vcur.tc_chainLink));
/* attempt to write structure to file */
if (ok)
ok = WriteNextBuffer( DestFile, (char *) &vcur.tc_chainLink, sizeof(vcur.tc_chainLink));
if (ok)
ok = WriteNextBuffer( DestFile, (char *) &vcur.tc_channelID, sizeof(vcur.tc_channelID));
if (ok)
ok = WriteNextBuffer( DestFile, (char *) &vcur.tc_name[0], sizeof(vcur.tc_name));
if (ok)
ok = WriteNextBuffer( DestFile, (char *) &vcur.tc_topicAddress, sizeof(vcur.tc_topicAddress));
if (ok)
ok = WriteNextBuffer( DestFile, (char *) &vcur.tc_coilReadSize, sizeof(vcur.tc_coilReadSize));
if (ok)
ok = WriteNextBuffer( DestFile, (char *) &vcur.tc_regReadSize, sizeof(vcur.tc_regReadSize));
if (ok)
ok = WriteNextBuffer( DestFile, (char *) &vcur.tc_updateInterval, sizeof(vcur.tc_updateInterval));
/* indicate success or failure */
return (ok);
} /* WriteTopicCfgStruct */
/***********************************************************************
***********************************************************************
* CONVERSION ROUTINES *
***********************************************************************
***********************************************************************/
/***********************************************************************/
/* convert the old-style baud rate id to the current version */
static
UINT
WINAPI
ConvertOldBaud ( int iOldBaud )
{
switch(iOldBaud) {
/* these id's are from the old RC.H file */
case 140:
return (WWTranslateWinBaudToCDlg(CBR_19200));
case 141:
return (WWTranslateWinBaudToCDlg(CBR_9600));
case 142:
return (WWTranslateWinBaudToCDlg(CBR_4800));
case 143:
return (WWTranslateWinBaudToCDlg(CBR_2400));
case 144:
return (WWTranslateWinBaudToCDlg(CBR_1200));
case 145:
return (WWTranslateWinBaudToCDlg(CBR_300));
default:
/* default baud rate if unexpected baud rate */
return (WWTranslateWinBaudToCDlg(CBR_19200));
}
} /* ConvertOldBaud */
/***********************************************************************/
/* convert the old-style parity id to the current version */
static
UINT
WINAPI
ConvertOldParity( int iOldParity )
{
switch(iOldParity) {
case 121:
return (WWTranslateWinParityToCDlg(EVENPARITY));
case 122:
return (WWTranslateWinParityToCDlg(ODDPARITY));
case 123:
return (WWTranslateWinParityToCDlg(NOPARITY));
case 124:
return (WWTranslateWinParityToCDlg(MARKPARITY));
case 125:
return (WWTranslateWinParityToCDlg(SPACEPARITY));
default: /* invalid - use default */
return (WWTranslateWinParityToCDlg(ODDPARITY));
}
} /* ConvertOldParity */
/***********************************************************************/
/* convert the old-style stop bits id to the current version */
static
UINT
WINAPI
ConvertOldStopbits( int iOldStopbits )
{
switch(iOldStopbits) {
case 151:
return(WWTranslateWinStopToCDlg(ONESTOPBIT));
case 152:
return(WWTranslateWinStopToCDlg(TWOSTOPBITS));
default: /* invalid */
return(WWTranslateWinStopToCDlg(ONESTOPBIT));
}
} /* ConvertOldStopbits */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -