Releasing receive buffer memory on Lora Radio event.
Tagged: MDot Radio Event.
- This topic has 5 replies, 4 voices, and was last updated 7 years, 4 months ago by Jason Reiss.
-
AuthorPosts
-
February 16, 2017 at 9:49 pm #17281Tom HillParticipant
I have subscribed to RadioEvents when Initializing the LORA communication on my mDot using the mdot api method as shown below.
//subscribe to the LORA Events. m_dot->setEvents(this);
When I had discussed about subscribing this event a while back in this forum I was told to ensure to release the recv buffer on completion of the recv event. However since I have migrated to mbed 5, if try to release the recv buffer (uint8_t*), the mdot hangs when the call returns back to my main thread. If I stop releasing the recv buffer, everything works well. So I am hoping this is not an issue, because I don’t want to create a memory leak in my application, which would eventually kill my mdot application? In the sample code on the mbed web site I noticed that this recv buffer is not released. So before I go with this approach I am hoping to get confirmation from the Multitech developers, its okay not release the recv buffer?
This is my current code….
void TestLora::MacEvent(LoRaMacEventFlags* flags, LoRaMacEventInfo* info) { std::string msg = "OK"; switch (info->Status) { case LORAMAC_EVENT_INFO_STATUS_OK: m_TransmissionDoneOrTimedOut = true; break; case LORAMAC_EVENT_INFO_STATUS_ERROR: msg = "ERROR"; break; case LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT: m_TransmissionDoneOrTimedOut = true; msg = "TX_TIMEOUT"; break; case LORAMAC_EVENT_INFO_STATUS_RX_TIMEOUT: m_bReceiveDoneOrTimedOut = true; msg = "RX_TIMEOUT"; break; case LORAMAC_EVENT_INFO_STATUS_RX_ERROR: m_bReceiveDoneOrTimedOut = true; msg = "RX_ERROR"; break; case LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL: msg = "JOIN_FAIL"; break; case LORAMAC_EVENT_INFO_STATUS_DOWNLINK_FAIL: m_bReceiveDoneOrTimedOut = true; msg = "DOWNLINK_FAIL"; break; case LORAMAC_EVENT_INFO_STATUS_ADDRESS_FAIL: msg = "ADDRESS_FAIL"; break; case LORAMAC_EVENT_INFO_STATUS_MIC_FAIL: msg = "MIC_FAIL"; break; default: break; } if (mts::MTSLog::getLogLevel() == mts::MTSLog::TRACE_LEVEL) { logTrace("Event: %s", msg.c_str()); logTrace("Flags Tx: %d Rx: %d RxData: %d RxSlot: %d LinkCheck: %d JoinAccept: %d", flags->Bits.Tx, flags->Bits.Rx, flags->Bits.RxData, flags->Bits.RxSlot, flags->Bits.LinkCheck, flags->Bits.JoinAccept); logTrace("Info: Status: %d ACK: %d Retries: %d TxDR: %d RxPort: %d RxSize: %d RSSI: %d SNR: %d Energy: %d Margin: %d Gateways: %d", info->Status, info->TxAckReceived, info->TxNbRetries, info->TxDatarate, info->RxPort, info->RxBufferSize, info->RxRssi, info->RxSnr, info->Energy, info->DemodMargin, info->NbGateways); } if (flags->Bits.Rx) { //set this flag to true. m_bReceiveDoneOrTimedOut = true; logDebug("Rx %d bytes", info->RxBufferSize); if (info->RxBufferSize > 0 && info->RxBuffer != NULL) { //queue the downlink packet for processing. TestMDot* pTestMDot = TestMDot::getInstance(); if(pTestMDot != NULL) { pTestMDot->QueueDownlinkPacket(info->RxBuffer,info->RxBufferSize); } //logDebug("Releasing Memory...."); //delete[] info->RxBuffer; //info->RxBuffer = NULL; } } }
Thanks,
YogeshFebruary 17, 2017 at 8:18 am #17288Mike FioreBlockedYogesh,
The implementation has changed so that consumers of the API no longer need to free the memory. You’ll notice that the mDotEvent object has its own buffer and that the RX data from the event gets copied into that. So there isn’t any dynamic allocation WRT the RX data that you need to worry about.
Cheers,
MikeFebruary 18, 2017 at 12:23 am #17346Tom HillParticipantThanks Mike for confirming. That helps a lot, I guess I didn’t notice the buffer on the mDotEvent object.
Thanks,
YogeshJuly 6, 2017 at 2:28 am #19863Momo SMITHParticipantHello guys,
I have a problem with the class RadioEvent.if (flags->Bits.Rx) {
logDebug(“Rx %d bytes”, info->RxBufferSize);
if (info->RxBufferSize > 0) {
// print RX data as string and hexadecimal
std::string rx((const char*)info->RxBuffer, info->RxBufferSize);
printf(“Rx data: %s [%s]\r\n”, rx.c_str(), mts::Text::bin2hexString(info->RxBuffer, info->RxBufferSize).c_str());
}
}When my gateway send a message without caractere null, the code work but when there is a caractere null, the first %s doesn’t post a complet message and then the second %s post a complet message in hex.
I want receive a string message. How i can resolve this problem to receive a complet message in string ?Thanks you
July 6, 2017 at 5:17 am #19865Jason ReissKeymasterUse memcpy
July 6, 2017 at 8:39 am #19869Jason ReissKeymasterOr if you want to output all characters to serial then use putc for each or use Serial object write function.
String functions such as printf will stop at first NULL.
-
AuthorPosts
- You must be logged in to reply to this topic.