Mark:
2. Fixed message lengths.
If the received messages have random content but fixed length, they can be collected until a complete message is available. In character mode, the following could be used (called each time the task is worken by a character reception).
while (fnMsgs(SerialPortID) >= MESSAGE_LENGTH) {
unsigned char ucBuff[MESSAGE_LENGTH];
fnRead(SerialPortID, ucBuff, MESSAGE_LENGTH); // read a complete message which is waiting
fnWrite(SerialPortID, ucBuff, MESSAGE_LENGTH); // send complete message back
}
I like to use the 2 Fixed message lengths.
but where to add the
while (fnMsgs(SerialPortID) >= MESSAGE_LENGTH) {
unsigned char ucBuff[MESSAGE_LENGTH];
fnRead(SerialPortID, ucBuff, MESSAGE_LENGTH); // read a complete message which is waiting
fnWrite(SerialPortID, ucBuff, MESSAGE_LENGTH); // send complete message back
}
is in the application.c
#ifdef SERIAL_INTERFACE
#ifdef TEST_MSG_MODE
#ifdef TEST_MSG_CNT_MODE/*step 1*/
while (fnMsgs(SerialPortID)) {
unsigned char ucLength;
fnRead( SerialPortID, &ucLength, 1); // get message length
Length = fnRead( SerialPortID, ucInputMessage, ucLength);
fnEchoInput(ucInputMessage, ucLength);
}
#else/*step 2*/
while (fnMsgs(SerialPortID)) {
Length = fnRead( SerialPortID, ucInputMessage, MEDIUM_MESSAGE);
fnEchoInput(ucInputMessage, Length);
}
#endif
#else/*step 3*/
if ((iAppState & (STATE_ACTIVE | STATE_DELAYING | STATE_ESCAPING | STATE_RESTARTING | STATE_VALIDATING)) && (Length = fnMsgs(SerialPortID))) {
while ((Length = fnRead( SerialPortID, ucInputMessage, MEDIUM_MESSAGE)) != 0) {
fnEchoInput(ucInputMessage, Length);
if (usData_state == ES_NO_CONNECTION) {
if (fnCommandInput(ucInputMessage, Length, SOURCE_SERIAL)) {
if (fnInitiateLogin(ES_SERIAL_LOGIN) == TELNET_ON_LINE) {
static const CHAR ucCOMMAND_MODE_BLOCKED[] = "Command line blocked\r\n";
fnWrite(SerialPortID, (unsigned char *)ucCOMMAND_MODE_BLOCKED, sizeof(ucCOMMAND_MODE_BLOCKED));
}
}
}
else {
fnCommandInput(ucInputMessage, Length, SOURCE_SERIAL);
}
}
}
#endif
#endif
I find it always go the /*step 3*/, But I don't sure the /*step 3*/ function,it look like the TELNET function!
I don't like to change the TELNET function! How can I do???
can add the"2. Fixed message lengths" in fnEchoInput(ucInputMessage, Length);
??
Regards
tr111