📄 udconfig.c
字号:
int pttDDEType; /* DDE point data type */
WORD dataLen; /* length of data element */
} PATTERNENTRY;
PATTERNENTRY name_table[] =
{
/* Mne PatternType dataType, pttDDEType Len */
{"V9", P_ADD, PLC_V, PTT_INTEGER, 2},
{"V9?", P_ADDS, PLC_V, PTT_INTEGER, 2},
{"V9:9", P_BIT, PLC_V, PTT_DISCRETE, 2},
{"V9-9", P_STR, PLC_V, PTT_STRING, 2},
{"V9-9?", P_STRS, PLC_V, PTT_STRING, 2},
{"C9", P_ADD, PLC_C, PTT_INTEGER, 2},
};
static int num_namepatterns = (sizeof(name_table) / sizeof(PATTERNENTRY));
/***********************************************************************/
/** ValidatePoint() checks to see that a point name
conforms to the standard programming conventions for this PLC.
Fields for the corresponding symbol table entry are initialized here.
returns TRUE if point name is valid **/
BOOL
WINAPI
ValidatePoint(LPSTR lpszPointName,
LPPPS ppp)
{
if (UT_CheckItemName(lpszPointName, ppp))
return TRUE;
return FALSE;
} /* ValidatePoint */
/***********************************************************************/
/** initialize mnemonic pattern **/
BOOL
WINAPI
InitializeMNEPATTERN (LPMNEPATTERN mne_patt,
LPSTR patt_buf, int patt_buf_size,
LONG FAR *address_array, int addr_max,
LPSTR pattern_table,
unsigned long entry_size, int num_entries)
{
BOOL status;
/* initialize return value */
status = FALSE;
if (mne_patt)
{
/* mnemonic pattern flags, pointers */
_fmemset (mne_patt, 0, sizeof (MNEPATTERN));
status = TRUE;
/* set up mnemonic pattern pointers, buffers */
mne_patt->pattern_buf = patt_buf;
mne_patt->pattern_size = patt_buf_size;
mne_patt->addresses = address_array;
mne_patt->address_max = addr_max;
mne_patt->pattern_table = pattern_table;
mne_patt->element_size = entry_size;
mne_patt->element_count = num_entries;
/* set default scanning mode flags */
mne_patt->enable_case = FALSE;
}
/* indicate success or failure */
return status;
} /* InitializeMNEPATTERN */
/***********************************************************************/
/** scan point name, produce pattern string, list of values;
return TRUE if pattern string is in correct format;
return index+1 of table element that matches pattern;
if there is no match, return 0 **/
BOOL
WINAPI
ScanPointName (LPSTR lpszPointName, LPMNEPATTERN mne_patt)
{
char ch, ch_p, ch_t;
LONG FAR *addr;
int I, pattern_len, addr_count, len, max_len, max_count;
LPSTR scan_ptr, next_ptr;
LPSTR patt_str, table_str, p_ptr, t_ptr;
int found_index, search_index, table_count;
BOOL bPointOk, done, match;
BOOL bGotSignificantDigit, bLeadingZero;
char digit_str [81];
/* initialize return values */
found_index = 0;
bPointOk = FALSE;
if (mne_patt)
{
/* get pointer and length for search pattern */
patt_str = mne_patt->pattern_buf;
if (patt_str != NULL)
/* use actual length indicated */
max_len = mne_patt->pattern_size;
else
/* force max length to zero -- no characters stored */
max_len = 0;
/* get pointer and max count for address array */
addr = mne_patt->addresses;
if (addr != NULL)
/* use actual count indicated */
max_count = mne_patt->address_max;
else
/* force max count to zero -- no addresses stored */
max_count = 0;
/* get pointer, length, and max count for table */
table_str = mne_patt->pattern_table;
if (table_str != NULL)
/* use actual count indicated */
table_count = mne_patt->element_count;
else
/* force table count to zero -- no elements to search */
table_count = 0;
if ((table_count > 0) && (mne_patt->element_size == 0))
/* only one element is addressable, so only search one */
table_count = 1;
/* initialize return values */
pattern_len = 0;
addr_count = 0;
/* process various parts of point name */
next_ptr = lpszPointName;
if (next_ptr != NULL)
ch = *next_ptr;
else
ch = 0;
done = FALSE;
bPointOk = (ch != 0);
while (bPointOk && (!done))
{
/* handle character, build pattern */
if (ch == 0)
{
/* no more parts, exit loop */
done = TRUE;
}
else
{
/* check for decimal digit */
if (('0' <= ch) && (ch <= '9'))
{
/* digit found, save starting point */
scan_ptr = next_ptr;
/* initialize flags */
bGotSignificantDigit = (ch != '0');
bLeadingZero = FALSE;
/* scan until the end of the digits */
ch = *(++next_ptr);
while (('0' <= ch) && (ch <= '9'))
{
/* identify numbers with leading zeros */
if (!bGotSignificantDigit)
bLeadingZero = TRUE;
/* check digit */
if (ch != '0')
bGotSignificantDigit = TRUE;
/* get next character, advance pointer */
ch = *(++next_ptr);
}
/* check for leading zeros */
if (bLeadingZero)
{
/* point name not unique (e.g. V1 vs. V01), reject it */
bPointOk = FALSE;
done = TRUE;
}
/* get length */
len = (int) (next_ptr - scan_ptr);
/* process number as address, log it */
if ((pattern_len < max_len) &&
(addr_count < max_count))
{
/* indicate digits in pattern */
patt_str [pattern_len++] = '9';
/* convert digits to unsigned long number */
f_lstrncpy ((LPSTR) digit_str, scan_ptr, len);
digit_str[len] = 0;
addr [addr_count++] = atol (digit_str);
}
else
{
/* too many parts to point name, quit */
bPointOk = FALSE;
done = TRUE;
}
}
else
{
/* add non-digit characters to search pattern */
if (pattern_len < max_len)
{
patt_str [pattern_len++] = ch;
ch = *(++next_ptr);
}
else
{
/* too many parts to point name, quit */
bPointOk = FALSE;
done = TRUE;
}
}
}
}
/* terminate pattern string */
while (pattern_len < max_len)
patt_str [pattern_len++] = 0;
/* indicate number of addresses found */
mne_patt->address_count = addr_count;
/* search for match with table entry */
if (bPointOk)
{
/* force pattern to all upper case, if case is not significant */
if (!mne_patt->enable_case)
_fstrupr (patt_str);
/* initialize search index */
search_index = 0;
while ((search_index < table_count) && (found_index == 0))
{
/* compare table entry to pattern */
match = TRUE;
done = FALSE;
p_ptr = patt_str;
t_ptr = table_str;
I = 0;
while ((I < max_len) && (!done))
{
/* get characters from pattern buffer and table */
ch_p = *(p_ptr++);
ch_t = *(t_ptr++);
/* advance character count */
I++;
/* check table character for wild card */
if (ch_t != '?')
{
/* not wild card, check for match */
if (ch_t == 0)
/* end of table entry reached, stop after check */
done = TRUE;
if (ch_t != ch_p)
{
/* flag mismatch, stop loop */
match = FALSE;
done = TRUE;
}
}
else
{
/* wild card, check for end of pattern string */
if (ch_p == 0)
{
/* flag mismatch, stop loop */
match = FALSE;
done = TRUE;
}
}
}
/* check if match was found */
if (match)
/* indicate match found */
found_index = search_index + 1;
else
{
/* not found, go to next table element */
table_str += mne_patt->element_size;
search_index++;
}
}
}
/* indicate which element matches table, if any */
mne_patt->match_index = found_index;
}
return (bPointOk);
} /* ScanPointName */
/***********************************************************************
***********************************************************************
* Routines for reading the CFG file *
***********************************************************************
***********************************************************************/
/***********************************************************************\
The string szCfgPath contains the file name to be used for the
configuration file.
The configuration file keeps information about the comm ports and
the topics defined for this protocol driver.
In addition to the configuration file name, we define the name for
the backup configuration file. Before we update the configuration
file, we rename the previous configuration file with the backup name
provided here.
When updating the configuration file, care is taken not to destroy the
old configuration file before we know that the updated file has been
safely written. To accomplish this, the updated file is written first
with a temp file name. If this is successful, the old configuration
file is renamed to the backup name and the new configuration file is
renamed to the real file name.
\***********************************************************************/
/***********************************************************************/
/** read in the configuration file;
returns TRUE if successful **/
BOOL
WINAPI
ConfigureInit()
{
int i;
BOOL ok;
BUFFERED_FILE SourceFile;
char SourceBuf [512];
char ConfigFile[PATH_STRING_SIZE];
LPSTR path_source;
long lVersion;
/*
* basic file structure:
* - version info
* - i/o channels (com ports 1-4, boards, etc.)
* - topics
* - additional i/o channels, if any (e.g. com ports 5-MAX_COMPORT)
*/
if (bUsesComPorts) {
/* setup default com port structure */
SetupDefaultPortCfgParams( (LPWW_CP_PARAMS) &DefaultCpParams );
/* initialize the in-memory com port structure array with defaults */
for( i=0; i < NUM_COMPORTS; i++ ) {
comPort[i] = DefaultCpParams;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -