Hello everyone,

I am trying to understand the C program of SFListen tool of tinyos - 1.x,
which reads the packets from SerialForwarder and dumps them on the cygwin
window.

Here is the concerned code:

----------------------------------------------------
*int init_sf_source(int fd)
/* Effects: Checks that fd is following the serial forwarder protocol
     Sends 'platform' for protocol version '!', and sets 'platform' to
     the received platform value.
   Modifies: platform
   Returns: 0 if it is, -1 otherwise
 */
{
  char check[2], us[2];
  int version;
  unsigned char nonce[4];
  /* Indicate version and check if serial forwarder on the other end */
  us[0] = 'T'; us[1] = '!';
  if (safewrite(fd, us, 2) != 2 ||
      saferead(fd, check, 2) != 2 ||
      check[0] != 'T' || check[1] < ' ')
    return -1;

  version = check[1];
  if (us[1] < version)
    version = us[1];

  switch (version)
    {
    case ' ': break;
    case '!':
      nonce[0] = platform;
      nonce[1] = platform >>  8;
      nonce[2] = platform >> 16;
      nonce[3] = platform >> 24;
      if (safewrite(fd, nonce, 4) != 4)
    return -1;
      if (saferead(fd, nonce, 4) != 4)
    return -1;
      //Unlike the more general SFProtocol.java this piece of code always
knows what platform it is connected to; just   drop the preferred platform
from the client
//platform = nonce[0] | nonce[1] << 8 | nonce[2] << 16 | nonce[3] << 24;
      break;
    }

  return 0;
}*
-----------------------------------------

I have understood whole code except this part:

*   case '!':
      nonce[0] = platform;
      nonce[1] = platform >>  8;
      nonce[2] = platform >> 16;
      nonce[3] = platform >> 24;
      if (safewrite(fd, nonce, 4) != 4)
    return -1;
      if (saferead(fd, nonce, 4) != 4)
    return -1;

*I am not able to understand which platform variable we are referring here.
I opened platform.h file and found that:

#define AVRMOTE 1
#define TELOS   2
#define MICAZ   3
#define EYES 4
#define TINYNODE 5

Are we referring to these values only? I am not very sure about this.

Could anyone please give me more insight into this. Please try to help me in
understanding this part of the code. Its little bit urgent. I am trying to
right my own application similar to SFListen.

Thank you so much.

Vishal*
*
-- 
Vishal Pal
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to