📄 udcfgtxt.c
字号:
ReadBoardCfgASCII ( BUFFERED_FILE *SourceFile,
LPBOARD_CFG lpBoardCfg, char *scan_ptr,
char *scan_buf, int scan_buf_size )
{
BOOL ok;
BOOL done;
char ch;
int i;
char param_name [31];
int param_id;
unsigned long new_long;
unsigned long len;
BOOL truncated;
char string_status;
BOARD_CFG BoardCfg;
/* initialize return value */
ok = TRUE;
/* initialize flag */
done = FALSE;
/* initialize board structure to default settings */
SetupDefaultBoardCfgParams ( &BoardCfg );
/* get current character */
ch = *scan_ptr;
/* process each parameter in command */
while (ok && !done) {
/* skip blanks, search for start of parameter name */
ch = *scan_ptr;
while ((ch) && (ch == ' '))
ch = *(++scan_ptr);
if (ch) {
/* non-blank found, get parameter name */
GetParamName (&scan_ptr, param_name, sizeof(param_name));
/* identify parameter */
if (stricmp (param_name, ";") == 0) {
/* end of command reached */
done = TRUE;
} else {
param_id = 0;
i = 0;
while ((param_id == 0) && (i < NUM_BOARD_PARAMS)) {
if (stricmp (param_name, board_param_table[i].param_name) == 0)
param_id = board_param_table[i].param_index;
i++;
}
switch (param_id) {
case BOARD_NAME_PARAM : /* NAME=<string in quotes> */
/* attempt to get string in quotes */
ok = GetDelimitedString (&scan_ptr, &BoardCfg.cp_name[0],
sizeof(BoardCfg.cp_name), &len,
&truncated, &string_status);
if (truncated || (string_status != 'y'))
/* string too long or error encountered */
ok = FALSE;
break;
case BOARD_PORTID_PARAM : /* PORTID=<number> */
/* accept value only if valid integer and in range */
ok = GetParamNumber (&scan_ptr, &new_long);
if ((ok) &&
(bUsesComPorts && bUsesBoards) &&
(new_long <= MAX_COMPORT))
{
/* uses both types of interface,
but PortID is in range reserved for ComPorts */
ok = FALSE;
}
if (ok && (1 <= new_long))
BoardCfg.cp_channelID = new_long;
else
ok = FALSE;
break;
case BOARD_MEM_SEGMENT_PARAM : /* MEM_SEGMENT=<number> */
/* accept value only if valid integer and in range */
ok = GetParamNumber (&scan_ptr, &new_long);
if (ok && (0 <= new_long) && (new_long <= 0xFFFF))
BoardCfg.cp_memSegment = (WORD) new_long;
break;
case BOARD_IO_ADDR_PARAM : /* IO_ADDR=<number> */
/* accept value only if valid integer and in range */
ok = GetParamNumber (&scan_ptr, &new_long);
if (ok &&
(0x200 <= new_long) && (new_long <= 0x2f8) &&
((new_long % 8) == 0))
BoardCfg.cp_ioAddr = (WORD) new_long;
else
ok = FALSE;
break;
case BOARD_REPLYTIMEOUT_PARAM : /* REPLYTIMEOUT=<number> */
/* accept value only if valid integer and in range */
ok = GetParamNumber (&scan_ptr, &new_long);
if (ok && (0 <= new_long) && (new_long <= 0xFFFF))
BoardCfg.cp_replyTimeout = (WORD) new_long;
else
ok = FALSE;
break;
default : /* unrecognized parameter */
ok = FALSE;
break;
} /* switch */
}
}
/* check for end of line */
if (ok && (!done) && (*scan_ptr == 0)) {
/* get another line of text from file */
if ((SourceFile->more_data) && (SourceFile->error == 0)) {
ok = ReadNextLine(SourceFile, scan_buf, scan_buf_size);
scan_ptr = scan_buf;
}
}
}
/* return configured structure */
if (ok)
*lpBoardCfg = BoardCfg;
/* indicate success or failure */
return (ok);
} /* ReadBoardCfgASCII */
/**************************************************************************/
static
BOOL
WINAPI
ReadPortCfgASCII ( BUFFERED_FILE *SourceFile,
LPCOMPORT_CFG_WITHID lpComPortCfgWithID, char *scan_ptr,
char *scan_buf, int scan_buf_size )
{
BOOL ok;
BOOL done;
char ch;
int i;
char param_name [31];
char param_str [31];
int param_id;
unsigned long new_long;
unsigned long index;
COMPORT_CFG_WITHID ComPortCfg;
/* initialize return value */
ok = TRUE;
/* initialize flag */
done = FALSE;
/* initialize comport structure to default settings */
SetupDefaultComportCfgParams ( &ComPortCfg, 1);
/* get current character */
ch = *scan_ptr;
/* process each parameter in command */
while (ok && !done) {
/* skip blanks, search for start of parameter name */
ch = *scan_ptr;
while ((ch) && (ch == ' '))
ch = *(++scan_ptr);
if (ch) {
/* non-blank found, get parameter name */
GetParamName (&scan_ptr, param_name, sizeof(param_name));
/* identify parameter */
if (stricmp (param_name, ";") == 0) {
/* end of command reached */
done = TRUE;
} else {
param_id = 0;
i = 0;
while ((param_id == 0) && (i < NUM_COMPORT_PARAMS)) {
if (stricmp (param_name, comport_param_table[i].param_name) == 0)
param_id = comport_param_table[i].param_index;
i++;
}
switch (param_id) {
case COMPORT_PORTID_PARAM : /* PORTID=<number> */
/* accept value only if valid integer and in range */
ok = GetParamNumber (&scan_ptr, &new_long);
if (ok && (1 <= new_long) && (new_long <= NUM_COMPORTS))
ComPortCfg.channelID = (short) new_long;
else
ok = FALSE;
break;
case COMPORT_BAUD_PARAM : /* BAUD=<number> */
/* accept value only if valid integer and valid BAUD rate */
ok = GetParamNumber (&scan_ptr, &new_long);
if (ok) {
index = IndexFromBaud (new_long);
if (index != 0)
ComPortCfg.comport.uBaud = index;
else
ok = FALSE;
}
break;
case COMPORT_DATABITS_PARAM : /* DATA_BITS=<number> */
/* accept value only if valid integer and valid setting */
ok = GetParamNumber (&scan_ptr, &new_long);
if (ok && (0 <= new_long) && (new_long <= 32767)) {
index = IndexFromDataBits ((int) new_long);
if (index != 0)
ComPortCfg.comport.uDataBits = index;
else
ok = FALSE;
} else {
ok = FALSE;
}
break;
case COMPORT_STOPBITS_PARAM : /* STOP_BITS=<number> */
/* accept value only if valid integer and valid setting */
ok = GetParamNumber (&scan_ptr, &new_long);
if (ok && (0 <= new_long) && (new_long <= 32767)) {
index = IndexFromStopBits ((int) new_long);
if (index != 0)
ComPortCfg.comport.uStopBits = index;
else
ok = FALSE;
} else {
ok = FALSE;
}
break;
case COMPORT_PARITY_PARAM : /* PARITY_BITS=<name> */
ok = GetParamStr (&scan_ptr, ¶m_str[0], sizeof(param_str));
if (ok) {
index = IndexFromParity (param_str);
if (index != 0)
ComPortCfg.comport.uParity = index;
else
ok = FALSE;
}
break;
case COMPORT_REPLYTIMEOUT_PARAM : /* REPLYTIMEOUT=<number> */
/* accept value only if valid integer */
ok = GetParamNumber (&scan_ptr, &new_long);
if (ok)
ComPortCfg.comport.uReplyTimeout = new_long;
break;
default : /* unrecognized parameter */
ok = FALSE;
break;
} /* switch */
}
}
/* check for end of line */
if (ok && (!done) && (*scan_ptr == 0)) {
/* get another line of text from file */
if ((SourceFile->more_data) && (SourceFile->error == 0)) {
ok = ReadNextLine(SourceFile, scan_buf, scan_buf_size);
scan_ptr = scan_buf;
}
}
}
/* return configured structure */
if (ok)
*lpComPortCfgWithID = ComPortCfg;
/* indicate success or failure */
return (ok);
} /* ReadPortCfgASCII */
/**************************************************************************/
/** Store new configurable comport structure,
Return TRUE if value is acceptable **/
static
BOOL
WINAPI
StoreNewComPortCfg (COMPORT_CFG_WITHID *pComportCfgWithID)
{
int index;
BOOL ok;
/* initialize return value */
ok = FALSE;
/* select destination structure from array */
index = pComportCfgWithID->channelID;
if ((1 <= index) && (index <= NUM_COMPORTS)) {
/* valid port selected, update port data */
comPort[index-1] = pComportCfgWithID->comport;
/* indicate success */
ok = TRUE;
}
/* indicate success or failure */
return (ok);
} /* StoreNewComPortCfg */
/**************************************************************************/
/** Store new configurable board structure,
Return TRUE if value is acceptable **/
static
BOOL
WINAPI
StoreNewBoardCfg (BOARD_CFG *pBoard)
{
BOOL status;
LPBOARD_CFG lpBoardCfg;
CHAINSCANNER item_scanner;
/* initialize return value */
status = FALSE;
/* check whether there is already a board with identical name */
lpBoardCfg = (LPBOARD_CFG) FindFirstItem (&BoardCfgList, SCAN_FROM_HEAD,
BoardCfgNameMatch,
(LPSTR) pBoard->cp_name,
&item_scanner);
if (lpBoardCfg == NULL) {
/* check whether there is already a board with identical channel ID */
lpBoardCfg = (LPBOARD_CFG) FindFirstItem (&BoardCfgList, SCAN_FROM_HEAD,
BoardCfgIDMatch,
(DWORD FAR *) &pBoard->cp_channelID,
&item_scanner);
}
if (lpBoardCfg == NULL) {
/* board name and ID are unique */
/* ensure board has a channel ID number */
if (pBoard->cp_channelID == 0L)
/* no ID number yet, assign one */
BoardCfgAssignID ((LPBOARD_CFG) pBoard);
/* allocate new structure from heap */
lpBoardCfg = BoardCfgAlloc();
if (lpBoardCfg != NULL) {
/* copy contents to new structure */
*lpBoardCfg = *pBoard;
/* add board to list */
BoardCfgAddToList (lpBoardCfg);
/* indicate success */
status = TRUE;
}
}
/* indicate success or failure */
return (status);
} /* StoreNewBoardCfg */
/**************************************************************************/
/** Store new configurable TOPIC_CFG structure,
Return TRUE if value is acceptable **/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -