[Tinyos-devel] Bug/inconsistency in mig python

David Gay dgay42 at gmail.com
Fri Sep 19 15:28:18 PDT 2008


2008/9/6 Rodrigo Fonseca <rfonseca at cs.berkeley.edu>:
> Hi,
>
> I noticed a couple of things regarding mig generating python classes.
>
> 1. First, a bug in the __str__ method of the generated mig class: the mask
> for printing array fields is not set properly.
>
> My struct:
>
> typedef nx_struct nx_entry_t {
>     nx_uint8_t type;
>     nx_uint8_t res_id;
>     nx_uint32_t time;
>     nx_uint32_t ic;
>     nx_uint16_t arg;
> } nx_entry_t;
>
> typedef nx_struct quanto_vlog_msg_t {
>     nx_uint8_t n;
>     nx_entry_t entries[N];
> } quanto_vlog_msg_t;
>
> The mig command:
> mig -o QuantoLogMsgV.py -python-classname=QuantoLogMsgV python \
>
> $(QUANTO_ROOT)/tos/lib/quanto/QuantoLog/QuantoLogStagedMyUART.h \
>               quanto_vlog_msg_t
>
> The generated __str__ method (exception code omitted):
>     def __str__(self):
>             s = "Message <QuantoLogMsgV> \n"
>             s += "  [n=0x%x]\n" % (self.get_n())
>             s += "  [entries.type=";
>             for i in range(0, 10):
>                 s += "0x%x " % (self.getElement_entries_type(i) & 0xff)
>             s += "]\n";
>             s += "  [entries.res_id=";
>             for i in range(0, 10):
>                 s += "0x%x " % (self.getElement_entries_res_id(i) & 0xff)
>             s += "]\n";
>             s += "  [entries.time=";
>             for i in range(0, 10):
>                 s += "0x%x " % (self.getElement_entries_time(i) & 0xff)
>             s += "]\n";
>             s += "  [entries.ic=";
>             for i in range(0, 10):
>                 s += "0x%x " % (self.getElement_entries_ic(i) & 0xff)
>             s += "]\n";
>             s += "  [entries.arg=";
>             for i in range(0, 10):
>                 s += "0x%x " % (self.getElement_entries_arg(i) & 0xff)
>             s += "]\n";
>
> The masks for time, ic, and arg are wrong, should be respectively
> 0xffffffff, 0xffffffff, 0xffff.

Now fixed in CVS, thanks.

> 2. This is an inconsistency between what MIG and nesc are doing with
> nx_types.
>
> I defined nx_entry_t as above, and the generated code in app.c is
>
> typedef nx_struct nx_entry_t {
>   nx_uint8_t type;
>   nx_uint8_t res_id;
>   nx_uint32_t time;
>   nx_uint32_t ic;
>   nx_uint16_t arg;
> } __attribute__((packed))
>
> Then I changed nx_entry_t to include arg inside a union, and nesc added a
> filler.
>
> typedef nx_struct nx_entry_t {
>     nx_uint8_t type;
>     nx_uint8_t res_id;
>     nx_uint32_t time;
>     nx_uint32_t ic;
>     nx_union {
>       nx_uint16_t arg;
>     }
> } nx_entry_t;

>
> In app.c, a filler is added by nesc. I don't know if this has to be done,
> but, in any case, this is what's in app.c. Of course, sizeof works
> correctly, and gives 14 as an answer.

The filler is a bug. It doesn't show up if you actually give the union
a name, though. Hopefully should be fixed in CVS soon.

David Gay


More information about the Tinyos-devel mailing list