[Tinyos-help] Manipulating string

Nicolas Esteves nicolas.esteves at inrialpes.fr
Thu Aug 30 06:28:42 PDT 2007


Hi,
I don't know why you want to use string but I don think that it is a 
good idea.
If you want to use it for sending commands, I recommend you to use 
numeric  constants, this is faster, easier and it saves resources. You 
declare them with enum and dont have to worry about their representation 
(byte).
If you want to use commands like "read" for example you use 4 chars ( 4 
bytes ) where you can use only one by defining a constant using enum{ 
READ };
using that representation and designing correctly your packets you don't 
have to parse a string.
Like

typedef nx_struct packet_t {
  nx_uint16_t commandCode;
  nx_uint16_t commandParam1;
  ...
} packet_t;

and instead of doing something like strcmp you can use a switch
switch( packet.commandCode )
{
    case READ:
          ...
    case SEND:
       ...
}

If you still want to use string, I think you can code string 
manipulations methods by yourself if you don't find a nesc library to do 
that (I don't know if it exists), but again I think it's too resources 
consuming for a very limited efficiency.

Regards


More information about the Tinyos-help mailing list