Friday, November 21, 2008

Working with floating point in TinyOS

There are two ways to represent float in nesc.
One way, is to do it through by convention using the exponent and mantissa,
where you need to use 2^exponent. The function that does that is called powf().
The problem with using that function is that it is reaaaaallly slow.
----8<---- span="">
r = logf((float)v / 10000.0); // takes up about 10 ms (!!)
----8<---- span="">

and a
----8<---- span="">
r = powf(10,(float)v / 10000.0); // takes up about 32 ms (!!!!!!)
----8<---- span="">

In case you need to have fast response, this function might not be your choice.
One way to optimize the speed of those operations are:
"I'd like to mention that pow(a,b) is MUCH harder to implement than
exp(b). Use the latter whenever possible. In particular, if a is
fixed, use exp(b * log(a)) rather than pow(a,b). (In fact, that's a
common low-precision implementation technique even when a is not fixed.)

Also note that keeping logarithms in fixed-point format is often
convenient, and shaves a bit of overhead from the code when you
don't have hardware floating-point. "

One quite dirty trick to show real numbers in nesc is to define fix point.
for example in 16 bits, you say 12 bits are the bits before the decimal point, and 4 bits are bits after the point. a(12bits) + ( b(4bits)/16 ).
This dirty trick is good in case one wants working with float go faster, without need for much precision.

Wednesday, November 5, 2008

File Sharing between to PCs under Windows

Several times I badly needed the connection between to PCs and I never actually managed to make it working :(

One thing I always forget to set is that both PCs have the same Workgroup, besides the part where you set your folder to be shared among PCs in the network.

Thursday, June 5, 2008

Finally, clear explanation of TinyOS 2.x serial packet structure

TinyOS 2.x

A message sent through serial ports from motes to PC will typically look like this:

00 FF FF 00 00 08 00 09 19 77 02 07 00 13 00 00

  • The first byte 00 is the leading zero.
  • After that, the whole packet is of the type "serial_packet_t", defined in tinyos-2.x/tos/lib/serial/Serial.h.
    • Inside the serial_packet_t structure, the first 7 bytes are of the type "serial_header_t", which is also defined in tinyos-2.x/tos/lib/serial/Serial.h.

      In the case above, it would be FF FF 00 00 08 00 09.

      Within the "serial_header_t", the following structure takes place:
      • nx_am_addr_t dest // Destination (2 bytes)
      • nx_am_addr_t src // Source (2 bytes)
      • nx_uint8_t length // Payload Length (1 byte)
      • nx_am_group_t group // Group ID (1 byte)
      • nx_am_id_t type // Active Message Handler Type (1 byte), some enum value that you can define yourself.
    • After the 7 byte header, here comes the payload, which can be up to TOS_DATA_LENGTH (28 bytes) long. The content could be anything.

      In the above example, the payload is: 19 77 02 07 00 13 00 00, which is of the length (8 bytes) denoted in the "Payload Length" field.

To note, besides the payload part, we need to fill out the destination address and payload length field by calling SerialActiveMessageC.AMSend(am_addr_t dest, message_t* msg, uint8_t len). It would be a good programming manner to fill the len with sizeof(). And we also need to specify the Active Message Handler Type by wiring the AMSend to SerialActiveMessage.AMSend[am_id_t id];

ref: The doc here doesn't seem to be up-to-date since it left out the source address from the header.
GREAT THANKS TO and his blog!!!!
(I copied whole blog from him in order to have in mine blog everything I might use in future)

Friday, April 25, 2008


Some really nice people has made cool Linux Live CD which has TinyOS installed.
Really cool for people who need the TinyOS fast!
This is the version with TinyOS 2.x

Thursday, January 17, 2008

Changing communication channel and RF Power

To change default communication channel and RF Power you can either:
1) edit opt/tinyos-1.x/tos/lib/CC2420Radio/CC2420Const.h
CC2420_DEF_CHANNEL 11 (this is default value)
CC2420_DEF_RFPOWER 0x1f (31, maximum, if you for example want to test multihop routing easiest way is to make RFPOWER smaller)

2) add line in Makefile
CC2420_DEF_RFPOWER= 0x1f

3) change it in program by colling function from CC2420Control interface, called:
SetRFPower(uint8_t power);

Wednesday, January 16, 2008

TinyOS little help

Last 2 months I was actively working in TinyOS, and since there's no better place than internet to put solutions to problems which most likely you will forget in near future, I will write here some little things about TinyOS.

In general, that was the main idea of this blog.
Quite recently I started with Linux, which have as usual, a lot of difficulties with drivers; you find a number of solutions which maybe one or maybe none is working.

Yes this is also public cause I support idea of helping people with similar problems over internet.
That is just my gratitude for all those nice people who helped me simply by posting their solutions on forums and other public places.