Author Topic: also the uart use!  (Read 9412 times)

Offline tr111

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
also the uart use!
« on: September 08, 2007, 12:38:15 PM »
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
« Last Edit: September 08, 2007, 12:50:59 PM by tr111 »

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: also the uart use!
« Reply #1 on: September 08, 2007, 09:12:16 PM »
Hi

The first thing to remember is that the uTasker demo project is a software base for other specific developments. It contains quite a lot of useful examples which can often be used unchanged or with only minor modifications for other work. It doesn't however need to be used as it is: another project can also be simply made by copying the sub-directory \Applications\uTaskerV1.3 and renaming it to the new project name. In this case all files in this sub-directory can be modifed as required.

In your case you could keep the serial reception in application.c or you could also add you own task especially to control this job; you can simply remove all serial port stuff from the application.c file and put it in the new one. The advantage is that the specific task will make the project more modular - application.c in the demo project includes quite a lot of different demos (and new demos tend to be added to it on a regular basis).

The uTasker demo shows various UART reception methods which are controlled by a local define. The 'step 3' path is in fact the normal path when the receiver is in character mode. It is reading the received character(s) and echoing them back. It is checking whether there is a TELNET connection open because the demo project includes a command menu which is shared by both the serial interface and TELNET. When a Telnet connection is active the serial menu will not operate and user will receive the message Command line blocked. Alternatively, if a serial menu is in operation the TELNET connection will be refused. This means that what you see is actually the serial interface and not Telnet so you can in fact change this as you wish - Telnet will always be able to operate with the demo menu if you don't use the menu via the UART.

Regards

Mark

Offline tr111

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
Re: also the uart use!
« Reply #2 on: September 09, 2007, 01:05:43 AM »
Mark :
       You are right!Thank you!