Skip to Navigation
Home
  • Company
    • Quick Facts
    • Board of Directors
    • Management Team
    • Press Releases
    • News Coverage
    • Newsletter
    • Careers
    • Articles
    • Ember Chronology
    • Contact Us
  • Products
    • ZigBee Chips
    • ZigBee Software
    • ZigBee Development Tools
    • Documentation
  • Buy
    • Digi-Key (Online)
    • Distributors
  • Applications
    • AMI & AMR
    • Integrated Home Automation
    • Building Automation
    • Others
  • ZigBee
    • About ZigBee
    • Ember & ZigBee
    • ZigBee FAQ
    • Download Specifications
    • ZigBee Events
  • Partners
  • Support
    • Training
  • Events
Home › FAQs

What do I need to do in order to use fragmented messaging (fragmentation) in my application?

Categories:
  • Software : Networking
  • EmberZNet PRO

NOTE: This writeup shows example code specific to the EmberZNet API (non-EZSP environment). If you are using EZSP, please refer to app/util/zigbee-framework/fragment-host.h for guidance on differences in the fragmentation API.

To add fragmentation, in your main file where the messaging is done, add the following inclusion:

  1. #include "app/util/zigbee-framework/fragment.h"

We also recommend adding a state variable to make sure you don’t send more than one fragmented message at once since the library only maintains state for one collection of fragments:

  1. boolean fragmentedMessageInProcess = FALSE;

In the place where you send the large message, do something like this:

  1. EmberMessageBuffer masterBuffer;
  2.  
  3. masterBuffer = emberFillLinkedBuffers(messageContents, messageLength);
  4.  
  5. if (masterBuffer == EMBER_NULL_MESSAGE_BUFFER) {
  6. return EMBER_NO_BUFFERS;
  7. }
  8.  
  9. status = emberSendFragmentedMessage(EMBER_OUTGOING_DIRECT,
  10. destination,
  11. &apsFrame,
  12. masterBuffer,
  13. maxFragmentSize);
  14.  
  15. // we are now sending a fragmented message
  16. if (status == EMBER_SUCCESS) {
  17. fragmentedMessageInProcess = TRUE;
  18. }
  19.  
  20. emberReleaseMessageBuffer(masterBuffer);
  21. return status;

In your main loop, add a call to service the fragmentation state machine:

  1. emberFragmentTick();

In your incomingMessageHandler routine, add a check before running further processing on the message:

  1. boolean isFragment;
  2.  
  3. isFragment = emberIsIncomingFragment(apsFrame, message);
  4. if( isFragment ) return; // don't process these here

…Note that the Boolean return value of emberIsIncomingFragment() is not so much whether the processed buffer is a fragment but whether the fragmentation library code completely processed it (TRUE if yes; in which case the IncomingMessageHandler should not continue to process it after this subroutine completes). In particular, the last fragment is processed by this function but leads to a FALSE return value, since the fragment buffer is replaced by a concatenation of all received fragments as one large buffer chain, which the application is then expected to handle when IsIncomingFragment returns. So when you arrive back in top-level IncomingMessageHandler context, your buffer now represents the entire collection of received fragments as one very long message, which is why you should wait to compute the payload length until after the fragmentation check (IsIncomingFragment), as per this code:

  1. // has to be after frag so that len of whole message is collected len = emberMessageBufferLength(message);

Then, on the outgoing side, add similar handling in your MessageSentHandler to delay processing until all fragments are handled:

  1. boolean isFragment;
  2.  
  3. isFragment = emberIsOutgoingFragment(apsFrame, message, status);
  4. if( isFragment ) return; // don't process these here

Finally, set up code to handle the completion of the fragmented delivery:

  1. void emberFragmentedMessageSentHandler(EmberStatus status)
  2. {
  3. // the fragmented message is no longer in process
  4. fragmentedMessageInProcess = FALSE;
  5.  
  6. // Add any other code here you want to execute when all fragments are done
  7. }

See Also: 
Using Packet Buffers
  • Login to post comments
  • Printer-friendly version

Search

FAQs

  • All (160)
  • Software : Embedded (62)
  • Software : Networking (70)
  • Hardware : Design (22)
  • Hardware : Manufacturing (10)
  • Tools : Dev Boards (2)
  • Tools : ISD/ISA (17)
  • Tools : xIDE (6)
  • Tools : Other (7)
  • ZigBee (1)
  • Change Notification (0)
Primary links
  • Developer Blog
  • Documentation
    • Release Notes
  • Contributed Software
  • FAQs
  • Change Notifications
  • Training
Portal
  • My Account
  • Search
User login
  • Request new password

Company | Products | Buy | Applications | ZigBee | Partners | Support | Events | Contact Us

©2007-2008 Ember Corporation | All rights reserved | Privacy