On Sun, Dec 1, 2013 at 1:34 PM, nivedita datta <[email protected]>wrote:

> Hi,
>
> I an trying to implement sensor communication & have created a packet
> structure as follows:
>
> *typedef nx_struct ctr{*
> *nx_uint16_t counter;*
> *char data[20];*
> *nx_uint16_t counter2;*
> *nx_uint16_t counter3;*
> *} ctr;*
>
> *typedef nx_struct BlinkToRadioMsg {*
> *  nx_uint16_t nodeid;*
> *  ctr counter_;*
> *} BlinkToRadioMsg;*
>
> Say, I want to send some string from one node to other, how do I do that?
>

First, a particular given packet structure on the wire is denoted by a
given particular am_type.  The simplest TinyOS network stack is
ActiveMessaging typically shorted to just AM.  AM packets have a field
called the am_type (8 bits) which determines what the rest of the packet
looks like.

So in BlinkToRadioMsg, the nx_struct has a particular format and when its
gets transmitted it uses the am_type AM_BLINKTORADIO (which has the value
6).

Now that said, there hasn't really been any real coordination about who is
using what numbers for AM_TYPES, but if you change a packet format you
really should understand what you are doing.


An AM packet on a serial line looks like:  (numbers in parens are the
number of bytes)

dest(2)   src(2)  len(1)  group(1)  am_type(1) <payload> <fcs>

while on a radio link (802.15.4 psuedo):

len(1)  fcf(2)  dsn(1)  dpan(2)  daddr(2)  saddr(2)  net(1)  am_type(1)
<payload> <fcs>


In other words, if you change the packet format you should pick a different
am_type value to use.




You really should work though the TinyOS tutorials and learn a bunch more
before asking really basic questions on the email list.

more below


Please.



> Is there any way to initialize the char array other than initializing in a
> loop?
>

this is a basic C question.  Please take a basic C tutorial.

there are chars (bytes), uint8_t (bytes), and strings.   Strings are a
special case of chars.  Then there are pointers.

if you have something like...

uint8_t * ptr;

ptr = "now is the time for all good programmers to learn C\n";

ptr points to the char array that implements the string.


Seriously go do a C tutorial.


>
> Also, does NesC packet structure support any float & string data type??
> I tried using the string datatype supported by C but it throws error
> saying:
>

C does NOT support a string data type per se.

there is no declaration like

string   abc;

in C.

You are thinking C++.

nesC is a superset of C    not C++.



>
> *syntax error before `string'*
>

see above.



>
>
> Please let me know how can I send float or string data type across the
> nodes.
>

Basic nesC as of 1.3.4 does not support float.   However, float was added
to the msp430 code sometime around Sept 2008.

>From tos/chips/msp430/msp430hardware.h:

/* Floating-point network-type support.
>    These functions must convert to/from a 32-bit big-endian integer that
> follows
>    the layout of Java's java.lang.float.floatToRawIntBits method.
>    Conveniently, for the MSP430 family, this is a straight byte copy...
> */
> typedef float nx_float __attribute__((nx_base_be(afloat)));
> inline float __nesc_ntoh_afloat(const void *COUNT(sizeof(float)) source)
> @safe() {
>   float f;
>   memcpy(&f, source, sizeof(float));
>   return f;
> }
> inline float __nesc_hton_afloat(void *COUNT(sizeof(float)) target, float
> value) @safe() {
>   memcpy(target, &value, sizeof(float));
>   return value;
> }




> Thanks in advance for your time & effort.
>
> Regards,
> Nivedita Datta
>
> _______________________________________________
> Tinyos-help mailing list
> [email protected]
> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
>



-- 
Eric B. Decker
Senior (over 50 :-) Researcher
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to