看了一个下午,终于明白了Tinyos下的Message packet ——TOS_Msg其实就是用typede声明的一个结构体,完整的说明在头文件AM.h这个文件里面找到。以下是TOS_Msg的结构:
typedef struct TOS_Msg
{
/* The following fields are transmitted/received on the radio. */
uint16_t addr;
uint8_t type;
uint8_t group;
uint8_t length;
int8_t data[TOSH_DATA_LENGTH]; //TOSH_DATA_LENGTH=29
uint16_t crc;
/* The following fields are not actually transmitted or received
* on the radio! They are used for internal accounting only.
* The reason they are in this structure is that the AM interface
* requires them to be part of the TOS_Msg that is passed to
* send/receive operations.
*/
uint16_t strength;
uint8_t ack;
uint16_t time;
uint8_t sendSecurityMode;
uint8_t receiveSecurityMode;
} TOS_Msg;
The addr field specifies the destination address (a moteID or the broadcast address). The group field specifies a channel for motes on a network. If a mote receives a packet with a different group ID, the packet is dropped. The type field specifies which handler to be called at the AM level when a packet is received. The length field specifies the length of the data portion of the TOS_Msg. Packets have a maximum payload of 29 bytes. The data portion consists of an array of 29 bytes (as specified by TOSH_DATA_LENGTH). The unsigned two byte field crc follows. When sending, the crc is incrementally calculated as each byte of the packet is transmitted.
So, the maximum length of a transmitted TOS_Msg is 36 bytes (addr(2 bytes) + type(1 bytes) + group(1 bytes) + length(13 bytes) + data(29 bytes) + crc(2 bytes) = 36 bytes).
虽然最大长度是36个字节,但是除去各种开销,有效字节只有29个
• sendingNode (2 bytes) – the node that has sent the packet.
• originNode (2 bytes) – the node that generated the packet.
• seqNo (2 bytes) – the sequence number of the packet.
• hopCount (2 bytes) – the number of hops the packet has travelled.
• data[21] (8 bytes) – the payload field of length 21 bytes.
posted on 2005-08-11 18:45
记忆中的深蓝 阅读(2105)
评论(6) 编辑 收藏 引用 所属分类:
TinyOS