[Tinyos-host-mote-wg] [Tinyos-2.0wg] recommendation for coding
convention on state variables
Philip Levis
pal at cs.stanford.edu
Wed Oct 12 18:45:06 PDT 2005
This is a coding conventions thing, and should probably make its way
into TEP 3 accordingly.
I've recently been using JTAG a lot, and it's amazingly useful for
debugging code on the node (shocking, I know). There's something that
you can do with your code to make this much easier, specifically for
inspecting state variables.
The standard TinyOS component does something like this:
enum {
STATE_ONE,
STATE_TWO,
STATE_THREE,
};
uint8_t myState;
In a debugger, when you inspect myState you'll see 0, 1, or 2. In this
case, you can figure out what state that is pretty easily, but in
something like a radio stack where there are 8 different states,
counting the enums (or looking them up when explicitly assigned) is a
pain. Instead, if you do this:
typedef enum {
STATE_ONE,
STATE_TWO,
STATE_THREE
} my_state_t;
my_state_t myState;
then when you inspect myState the debugger will tell you STATE_ONE or
STATE_TWO or STATE_THREE.
Which is kind of nice.
I'd therefore recommend doing state variables in this way. There's no
cost, etc.
Phil
_______________________________________________
Tinyos-2.0wg mailing list
Tinyos-2.0wg at Mail.Millennium.Berkeley.EDU
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-2.0wg
More information about the Tinyos-host-mote-wg
mailing list