[Tinyos-help] Re: connecting to the SerialForwarder

Javier Barbarán Sánchez barbaran at lcc.uma.es
Tue Jun 5 23:49:47 PDT 2007


Hi Islam,

Try to do it as I do... In my case it is working, but anyway, you have not 
implemented properly de protocol
(the code is in pseudo-C#)

//First we have to send the protocol initialization, sending the protocol 
version
us[0]='T'; us= '!';
socket.Send(us,0,us.Length, ....);
//After that we have to receive also de protocol information
byte[] check = new byte[2];
socket.Receive(check,0, check.Lengh, ...)
//Now, receive the platform information (4 bytes)
byte[] nonceRem = new byte[4];
socket.Receive(nonceRem,0, nonceRem.Length,...)
//And send the information of the platform we are using,
//in my case the platform is micaz and the corresponding value is 3
char[] nonce = new char[4];

int platform = 3; //micaz

nonce[0] = (char)platform;
nonce[1] = (char) (platform >> 8);
nonce[2] = (char) (platform >> 16);
nonce[3] = (char) (platform >> 24);

socket.send(nonce, 0, nonce.Length,...)

//And thats all falks ;)
// Following you will receive one byte that show you the length of the next 
message
//And following you have to read from socket tha amount of bytes

byte[] myLength = new byte[1];
socket.receive(myLength,0, 1,..)
byte[] data = new byte[myLength];
socket.receive(data,0, data.Length,...)


Anyway, if it doesn't work, check that you have compiled the last version 
for C-based SerialForwarder (you can download it from tinyos cvs).

Greetings


----- Original Message ----- 
From: "Islam Hegazy" <islheg at gmail.com>
To: "Javier Barbarán" <barbaran at lcc.uma.es>
Cc: <tinyos-help at Millennium.Berkeley.EDU>
Sent: Tuesday, June 05, 2007 7:49 AM
Subject: Re: connecting to the SerialForwarder


> Thanks very much for the paper. It was really helpful.
> Now I can receive from the SF. However, what I receive is unexpected. 
> First,
> what is the platform that I have to send to the SF? At the moment I resend
> the platform that I receive from the SF. Second, the data length byte is
> always '\t' which leads to wrong readings. Following is my code:
> char s[2];
>
> char dataLen[1];
>
> char packet[256];
>
> char platform[4];
>
> int rcd;
>
> short data;
>
> short len;
>
>
> if ((rcd = recv(sd, s, 2, 0)) != 0)
>
> {
>
>        send(sd, s, 2, 0);
>
>        rcd = recv(sd, platform, 4, 0);    //reads 4 bytes
>
>        send(sd, platform, 4, 0);    //send the platform that I received
>
>
>        rcd = recv(sd, dataLen, 1, 0);    //dataLen is always '\t'
>
>        sscanf(dataLen, "%d", &len); //wrong len
>
>        printf("%d\n", len);
>
>
>        rcd = recv(sd, packet, len, 0);    //read wrong data
>
>        sscanf(packet, "%d", &data); //read the first byte
>
>        printf("%d\n", data);
>
>
> }
>
>
> I also found this article about the SF protocol:
> http://www.stanza.co.uk/emergentcity/?cat=11
>
> Regards
> Islam Hegazy
> 



More information about the Tinyos-help mailing list