The way to receive data from SerialForwarder (c-based version
partiularly, but also any version) is to implement the whole protocol
(check the code, it's more than you are doing). Once you have negotiated
properly the SerialForwarder protocol, the SerialForwarder protocol will
send you first one byte that is the length in bytes of the next message
and following the message.
You can also take a look to this paper where we have defined a (very
basic) sequence diagram of the SerialForwarder protocol.
http://www.waset.org/proceedings/v21/v21-29.pdf
Hope this help...
Islam Hegazy escribió:
What I understand from the code is how to interpret the data not how
to receive it. My problem is that my client receives 'T!' only. I have
the following changes but nothing new happens. It stops at the second
recv waiting for data to arrive:
if ((rcd = recv(sd, s, 2, 0)) != 0)
{
if (s[0] == 'T' && s[1] == '!')
{
char byte[4];
recv(sd, byte, 4, 0);
char data[20];
int offset = 0;
while (offset < 20)
{
int count = recv(sd, data, 20 - offset, 0);
if (count == -1)
shutdown(sd, SHUT_RD);
offset += count;
}
}
}
Regards
Islam
----- Original Message ----- From: "Javier Barbarán"
<[EMAIL PROTECTED]>
To: "Islam Hegazy" <[EMAIL PROTECTED]>;
<[email protected]>
Sent: Monday, June 04, 2007 1:16 PM
Subject: Re: connecting to the SerialForwarder
Hello,
I mean that you have to take a look to the class that I mentioned in
my last mail. There you will see that in order to connect to
SerialForwarder application (I remember that you were using c-based
version) you have to follow a specific protocol (implemented in
SFProtocol java class) where you receive 'T!' that is the begining of
the protocol. So if you look to the server side in SerialForwarder
you will be able to see how to implement the protocol.
The following code is part of sfsource.c file, part of c-based
serialforwarder that you are already using.
int init_sf_source(int fd)
95 /* Effects: Checks that fd is following the serial forwarder
protocol
96 Sends 'platform' for protocol version '!', and sets
'platform' to
97 the received platform value.
98 Modifies: platform
99 Returns: 0 if it is, -1 otherwise
100 */
101 {
102 char check[2], us[2];
103 int version;
104 unsigned char nonce[4];
105 /* Indicate version and check if serial forwarder on the other
end */
106 us[0] = 'T'; us[1] = '!';
107 if (safewrite(fd, us, 2) != 2 ||
108 saferead(fd, check, 2) != 2 ||
109 check[0] != 'T' || check[1] < ' ')
110 return -1;
111 112 version = check[1];
113 if (us[1] < version)
114 version = us[1];
115 116 switch (version)
117 {
118 case ' ': break;
119 case '!':
120 nonce[0] = platform;
121 nonce[1] = platform >> 8;
122 nonce[2] = platform >> 16;
123 nonce[3] = platform >> 24;
124 if (safewrite(fd, nonce, 4) != 4)
125 return -1;
126 if (saferead(fd, nonce, 4) != 4)
127 return -1;
128 //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
129 //platform = nonce[0] | nonce[1] << 8 | nonce[2] << 16 |
nonce[3] << 24;
130 break;
131 }
132 133 return 0;
134 }
Islam Hegazy escribió:
Hi
What do you mean by following the SerialForwarder protocol? I
create a socket and connect it to the SF but I only receive T!- . I
did another client on Windows using C# and I did the same steps but
it receives normally through the socket...
Regards
Islam Hegazy
----- Original Message -----
*From:* Javier Barbarán Sánchez <mailto:[EMAIL PROTECTED]>
*To:* [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> ;
[email protected]
<mailto:[email protected]>
*Sent:* Monday, June 04, 2007 2:03 AM
*Subject:* connecting to the SerialForwarder
Hello
You must follow the SerialForwarder protocol, you can take a look
on it in
<tinyos_directory>\tools\java\net\tinyos\packet\SFProtocol.java
Good luck
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help