10 years ago.

XbeeApi and mbed-rtos

When i import mbed-rtos library to my project the mbed blocks on the fuction xbeeDevice.setUpApi(). Is this a known issue? Do i have to configure something different on the .hpp configuration file so i can use mbed-rtos? If i delete the mbed-rtos library my code works just fine and it doesnt stop at xbeeDevice.setUpApi().

Question relating to:

API for communicating with XBee devices. wireless, xbee

Thanks you example worked perfectly! Does this alter anything regarding the way i receive packets? For some reason this part of the code stopped working:

XBeeApiRxFrame* frameP; pc.printf("Received frames: %d\r\n",rxBuffer.getFrameCount() ); /* Work through all of the frames in the buffer */ while( NULL != ( frameP = ( XBeeApiRxFrame* )rxBuffer.getTailPtr())) { /* Dump out some information from the frame */ dumpFrame( frameP ); interpret_frame( frameP ); /* Remove the frame from the buffer */ rxBuffer.pop(); }

posted by Grupo 1 Ser 08 Jul 2014

1 Answer

10 years ago.

Hi,

Thanks for letting me know - I've not tried using XBeeApi with mbed-rtos in a while now, and I know that there are sections of code that are not thread-safe. Let me take a look later today and I'll try and get back to you with an answer.

Thanks,

John

Accepted Answer

Thank you very much for your promptly aswner. I'm not even using mbed rtos on that code! It is just the fact of importing the mbed-rtos library! I wont have any issue with concurrency problems.

posted by Grupo 1 Ser 04 Jul 2014

OK, I can reproduce this. Digging into it, it seems that the Serial class used in the API isn't RTOS friendly when used within interrupts (as the API does). Switching to RawSerial should fix the problem, so I'll try and get that done soon.

Thanks,

John

posted by John Bailey 05 Jul 2014

OK, so other than switching to RawSerial it seems that there was an issue with the received data handler overflowing the stack, so I've re-structured it slightly to use a thread outside the interrupt context to deal with the received data.

I've created an example at

Import programXBeeApiBroadcastExampleRTOS

Example of using the XBeeApi library to broadcast a message, based on XBeeApiBroadcastExample. This example shows how to use the library when using mbed-rtos. Before compiling you must open "XbeeApi\Config\XBeeApiCfg.hpp" and change the '#if 0' to '#if 1' on the line above the comment reading "Use RTOS features to make XBeeApi threadsafe"

which shows how to use the API if you're using mbed-rtos.

Simply:

  • You need to change the configuration file as described in the comment at the top of the example
  • You need to call xbeeDevice.setupDispatchTask() before calling setUpApi()

Hope that works for you - let me know how you get on.

Thanks,

John

posted by John Bailey 06 Jul 2014

Thanks you example worked perfectly! Does this alter anything regarding the way i receive packets? For some reason this part of the code stopped working:

XBeeApiRxFrame* frameP; pc.printf("Received frames: %d\r\n",rxBuffer.getFrameCount() ); /* Work through all of the frames in the buffer */ while( NULL != ( frameP = ( XBeeApiRxFrame* )rxBuffer.getTailPtr())) { /* Dump out some information from the frame */ dumpFrame( frameP ); interpret_frame( frameP ); /* Remove the frame from the buffer */ rxBuffer.pop(); }

I mean if i try to use one of your example for receiving like the one using the CircularBuffer or the callback one, neither works!

posted by Grupo 1 Ser 08 Jul 2014

Alright so i used i called a function on your code called xbeeDevice.dumpRxBuffer(&pc,true); and the buffer is effectively receiving my packets. but for some reason when i call pc.printf("Received frames: %d\r\n",rxBuffer.getFrameCount() ); it returns 0

posted by Grupo 1 Ser 08 Jul 2014