Author Topic: Echo ping reply doesn't inform my task about the ping result  (Read 4163 times)

Offline Stan

  • Newbie
  • *
  • Posts: 18
    • View Profile
Echo ping reply doesn't inform my task about the ping result
« on: April 06, 2009, 02:11:59 PM »
Hello everyone,

I'm trying to implement the ping request in my board. I'm using AT91SAM7X256.

I have a task in which I do:
...
if (z % 200 == 0) // This is executed every 10 seconds
   fnSendPing(PING_ADDRESS, MAX_TTL, OWN_TASK, PING_SOCKET); 
     
switch(ptrTaskTable->ucEvent){
    case PING_RESULT: ser_write_string(RS232_UART, "\n\r Ping OK"); break;
    case ARP_RESOLUTION_SUCCESS: ser_write_string(RS232_UART, "\n\r ARP Success"); break;
}

...

OWN_TASK is defined to be the same as the first letter of my task's name, in my case it's '_' .
I saw that it goes in case ECHO_PING_REPLY in fnHandleICP() and it writes '_' in int_message[MSG_DESTINATION_TASK]. I'm not sure but I think something is wrong with the scheduler. I check my task's  ucEvent field with the Watch but it's always 0.

In config.h I have all the definitions:
#define USE_ICMP                                                // enable ICMP

        #ifdef USE_ICMP                                              // specify ICMP support details
            #define ICMP_PING                                       // allow PING reply
            #define ICMP_SEND_PING                               // support PING transmission
            #define ICMP_DEST_UNREACHABLE                   // allow destination unreachable if no UDP port exists
        #endif


Any help will be appreciated :) Thanks!

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3191
    • View Profile
    • uTasker
Re: Echo ping reply doesn't inform my task about the ping result
« Reply #1 on: April 06, 2009, 05:30:09 PM »
Hi Stan

Can you check the return value from the following line in the ECHO_PING_REPLY case in fnHandleICP()?


        fnWrite( INTERNAL_ROUTE, int_message, HEADER_LENGTH + 2);        // we send details to the owner of the ping request

If the destination task can be found it will return (HEADER_LENGTH + 2), which is 7.
If it can't find a destination task to deliver to it will return 0.

This will give you an indication of whether it is a problem with the task name or not.

I just did a test. It is possible to command a ping in the demo project from the command line menu (UART, TELNET or USB). This worked normally, using the maintenance task as owner task.

I then modified the maintenance task to have a name like the one that you use. It also worked correctly so I didn't see any relationship to the name of the task. These are the two changes I made, please check that it corresponds to your code.

Original:

#define TASK_DEBUG              'm'

  { "maintenace",fnDebug,        SMALL_QUEUE, (DELAY_LIMIT)(NO_DELAY_RESERVE_MONO), 0, UTASKER_STOP}, // Task used for debug messages (started by application)



Changed:

#define TASK_DEBUG              '_'

  { "_maintenace",fnDebug,       SMALL_QUEUE, (DELAY_LIMIT)(NO_DELAY_RESERVE_MONO), 0, UTASKER_STOP}, // Task used for debug messages (started by application)



Also check the method used to read the input in the task. Perhaps it is being woken by the message but the message not being handled correctly?
This is how the maintenance task does it:

    while ( fnRead( PortIDInternal, ucInputMessage, HEADER_LENGTH )) {   // check input queue
        switch ( ucInputMessage[ MSG_SOURCE_TASK ] ) {                   // switch depending on message source
...
        case TASK_ICMP:
            fnRead( PortIDInternal, ucInputMessage, ucInputMessage[MSG_CONTENT_LENGTH]); // read the contents
            if (ucInputMessage[ 0 ] == PING_RESULT) {
                fnPingSuccess((USOCKET)ucInputMessage[ 1 ]);
            }
            break;
...
        }
    }


I notice that you are accessing ptrTaskTable->ucEvent. This is used only as a timer event (which is not generally accessed by user code) so this may explain the problem. It will also always have the value 0 when access by the task since it is reset before the task is scheduled.

Regards

Mark



Offline Stan

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Echo ping reply doesn't inform my task about the ping result
« Reply #2 on: April 08, 2009, 02:24:59 PM »
Hi Mark,

Yes, the problem was that didn't read the message correctly. Thanks for your quick answer, now it works fine! :]

Best Regards
Stan