It does appear that perhaps the saferead() function should be called to only
read at most 2 bytes, instead of 6:

  char check[2];
  char nonce[6];
  /* Indicate version and check if serial forwarder on the other end
     (life is easy as we're the earliest protocol version) */
  nonce[0] = 'T'; nonce[1] = ' ';
  nonce[2] = (char)  (platform        & 0xff);
  nonce[3] = (char) ((platform >>  8) & 0xff);
  nonce[4] = (char) ((platform >> 16) & 0xff);
  nonce[5] = (char) ((platform >> 24) & 0xff);
  if (safewrite(fd, nonce, 6) != 6 ||
      saferead(fd, check, 6) != 6 ||
      check[0] != 'T' || check[1] < ' ')
    {
      return -1;
    }

  return 0;

Could someone else (the designer of this protocol?) please comment
on this?  

Hui, I would suggest you file a bug at sourceforge on this (I'd do it
but it's your bug):
http://sourceforge.net/tracker/?group_id=28656&atid=393934

-Kim.

On Thu, Nov 18, 2004 at 12:54:44PM -0500, Hui Cao wrote:
> Please check the code on the  tinyos at CVS(at tools/src/sf),  I think 
> there is a bug there. In the function open_sf_sourcre() in the file 
> sfsource.c, the check string should be  6, not  2.  When I use it on at 
> PC, there is no problem. But when I compile it on Stargate, the 
> communication broken by the server.  You can't get the right value at 
> the server side.
> 
> It took me a long time to find this bug. Please confirm this.
>                                                                               
>              
> Hui.
> Kim Nico wrote:
> 
> >This is the "serial forwarder" protocol, which I also discovered the
> >same way you did.  
> >
> >First, the client should write write those two characters to the socket.
> >Then, it should 2 bytes back (they should be the "T " string).
> >Thereafter, it can read 1 byte of length, followed by the packet, in a 
> >loop.
> >
> >Below is a perl program that I believe works the same as Listen.
> >
> >Hope this helps,
> >
> >-Kim.
> >
> >-------
> >
> >#!/usr/bin/perl
> >
> >require "flush.pl";
> >
> >use IO::Socket;
> >
> >$host = shift(@ARGV) || "localhost";
> >$port = shift(@ARGV) || 9001;
> >
> >$remote = IO::Socket::INET->new(Proto    => "tcp",
> >                             PeerAddr => $host,
> >                             PeerPort => $port,
> >                            )
> > or die "cannot connect to port $port at $host";
> >
> ># Initialize protocol to serialforwarder
> >print $remote "T ";
> >$len = read($remote, $foo, 2); # read the "T " back
> ># print "read $len bytes: |$foo|\n";
> >
> >my $length;
> >my $packet;
> >
> >while (read($remote, $length, 1) == 1) {
> >   $len = ord($length);
> >   if (read($remote, $packet, $len) == $len) {
> >     @data = split(/ */,$packet); # splits each character (byte)
> >     for ($i = 0; $i <= $#data; $i++) {
> >         printf("%02x ", ord($data[$i]));
> >     }
> >     print "\n";
> >     flush(stdout);
> >   }
> >}
> >
> >
> >
> >On Wed, Nov 17, 2004 at 04:01:57PM +0100, Libor Roubal wrote:
> > 
> >
> >>Hi All,
> >>I am using SerialForwarder to serve the data from MIB510 and MICA2s
> >>on
> >>a port 9001. I tried to connect to it with my own and other clients
> >>to
> >>read the data, but all I get is this two bytes: 84 and 23 (T and
> >>space
> >>in Ascii). However, the motes are sending correct values. Has anyone
> >>encountered any similar problem?
> >>
> >>Thanks. 
> >>
> >>LabR
> >>
> >>   
> >>
> >
> > 
> >
> >>_______________________________________________
> >>Tinyos-help mailing list
> >>[EMAIL PROTECTED]
> >>http://mail.Millennium.Berkeley.EDU/mailman/listinfo/tinyos-help
> >>   
> >>
> >
> >_______________________________________________
> >Tinyos-users mailing list
> >[EMAIL PROTECTED]
> >http://mail.Millennium.Berkeley.EDU/mailman/listinfo/tinyos-users
> >
> >
> > 
> >
> 
_______________________________________________
Tinyos-users mailing list
[EMAIL PROTECTED]
http://mail.Millennium.Berkeley.EDU/mailman/listinfo/tinyos-users

Reply via email to