Author Topic: Safely extracting data from radio.DATA  (Read 137 times)

mah115

  • Newbie
  • *
  • Posts: 31
Safely extracting data from radio.DATA
« on: March 24, 2019, 04:44:30 AM »
Hi,
   I was wondering what's the best way to extract data from radio.DATA.  Do I have to read it out as fast as I can in case a new packet comes in and overwrites it while I'm processing it?  Or is there some clever double buffering in the background that "freezes" the data when radio.receiveDone() is called?

In the send/receive struct example, it seems like the code copies the data from radio.DATA into a struct.  Instead of copying, could I just make a struct pointer and point to radio.DATA?

Mike

TomWS

  • Hero Member
  • *****
  • Posts: 1888
Re: Safely extracting data from radio.DATA
« Reply #1 on: March 24, 2019, 09:15:05 AM »
Hi,
   I was wondering what's the best way to extract data from radio.DATA.  Do I have to read it out as fast as I can in case a new packet comes in and overwrites it while I'm processing it?  Or is there some clever double buffering in the background that "freezes" the data when radio.receiveDone() is called?
Probably nothing 'clever', but the data is intact until you either Send or call radio.receiveDone();
Quote
In the send/receive struct example, it seems like the code copies the data from radio.DATA into a struct.  Instead of copying, could I just make a struct pointer and point to radio.DATA?
You could do this and access the data reliably, however, as stated above, don't call the radio send or receive functions, including sendACK, until you've either copied or you're done with the data.

ISTM, that it's easier and always reliable if you simply copy to your own buffer, however.  I don't think the RFM69 library comes with any guarantees about data volatility after return from receiveDone() and what works today may not work forever...