Fragmentation

Zigbee is designed for transporting small amounts of data. As such, the packet size is small, with a maximum payload of 81B. For sending larger messages the module can automatically fragment the payload into smaller packets and then re-assemble these into the complete payload on the other end. This process is called fragmentation, and it's one of the cooler features of the module, especially if you've ever had to write a custom fragmenter before. We have created an example that shows how to use Fragmentation, see Fragmentation Example.

There's a lot of processing that goes on to get the data into and out of the module on each end, but the nice thing is that this processing has been abstracted away by the library. The method afSendDataExtended is used to send these long messages. Refer to the source code documentation for that method for more information. In afSendDataExtended method, if the payload is large then it is uploaded to the module in 250B increments using a helper method in af.c named afDataStore and once all data has been sent to the module then the message is sent using AF_DATA_REQUEST_EXT. Up to 600B can be sent at one time.

On the receive side there is a similar process, using the method retrieveExtendedMessage. When a AF_DATA_REQUEST_EXT message is received, calling retrieveExtendedMessage will retrieve all the parts of the payload and reassemble it into one continuous chunk of data.

Note: the MDB1 and MDB2 use a 600B message but since the MSP430G2553 processor on the Launchpad only has 512B of RAM, the size of the payload with a LaunchPad is reduced to 130B.

=Sending A Message= We will walk through the steps required to send a 600B message. This is all encapsulated in the afSendDataExtended method and demonstrated in the Fragmentation Example, but here's how it works behind the scenes.

1. Send an AF_DATA_REQUEST_EXT message with: Other fields are same as what is used in the AF_DATA_REQUEST function. 2. Send AF_DATA_STORE message: Index = 0, Length = 250, ...and 250B of data 3. Send AF_DATA_STORE message: Index = 250, Length = 250, ...and 250B of data 4. Send AF_DATA_STORE message: Index = 500, Length = 100, ...and 100B of data 5. Send AF_DATA_STORE message: Index = 0, Length = 0, … and no data
 * DstAddrMode = 2 (to indicate short addressing mode)
 * DstAddr = 0x0000 (since sending to coord)
 * DstPanId = 0x0000 (since intra-PAN)
 * Options = 0x00 (since normal MAC level Ack'ing is ok)
 * Len = 600 ...and no data
 * Since Length is 0, the entire data request is now sent over the air.

=Receiving a Message= For example, to receive a 600B message.

1. You will receive an AF_INCOMING_MSG_EXT: Length = 600, ...and no data. Note the timestamp in this message, we'll need it to identify this message. 2. Send AF_DATA_RETRIEVE with: Index = 0, Length = 250, and same Timestamp as what was received in AF_INCOMING_MSG_EXT. 3. Receive AF_DATA_RECEIVE SRSP with the first 250B of data 4. Send AF_DATA_RETRIEVE with: Index = 250, Length = 250, and same Timestamp as what was received in AF_INCOMING_MSG_EXT. 5. Receive AF_DATA_RECEIVE SRSP with the second 250B of data 6. Send AF_DATA_RECEIVE with: Index = 500, Length = 100, and same Timestamp as what was received in AF_INCOMING_MSG_EXT. 7. Receive AF_DATA_RECEIVE SRSP with the last 100B of data. 8. Send AF_DATA_RECEIVE with: Index = 0, Length = 0, and same Timestamp as what was received in AF_INCOMING_MSG_EXT.
 * Since Length is 0 this will trigger freeing the message.