0
\$\begingroup\$

I am developing a simple radio transmission network using B-L072Z-LRWAN1 boards. The network structure is formed by:

  1. One board acting as a gateway (where data is received).
  2. Multiple boards acting as nodes (which send data to the gateway).

The packet payload sent by nodes is N bytes long and I want to store this packet's information in case gateway stops working and nodes cannot communicate with it. I want to keep data that could not be sent by the node and send it once the gateway is active again.

Let's say I want to keep the last M messages that node could not send to the gateway. The buffer size should be M*N bytes long, but how do I implement this type of buffer in C?

Thank you in advance!

\$\endgroup\$
0
\$\begingroup\$
    //pseudo algorithm First In First Out
    int FIFO[16]; // size of 2^N
    int WR_Ptr, RD_Ptr; // Write and read pointer
    int Input, Output;

    // On write event
    FIFO[WR_Ptr] = Input;
    WR_Ptr++; //increment WR pointer
    WR_Ptr &= 15 // apply mask 2^N-1, turn over in circular manner
    if WR_Ptr==RD_Ptr //buffer overrun?
    {
       //handle error
    }

    //On read event
    if WR_Ptr<>RD_Ptr //check if FIFO is not empty
    {
      Output = FIFO[RD_Ptr];
      RD_Ptr++; //increment RD pointer
      RD_Ptr &= 15 // apply mask 2^N-1, turn over in circular manner
    }

//clear FIFO
RD_Ptr = 0;
WR_Ptr = 0;
\$\endgroup\$
  • \$\begingroup\$ Could you change the types of FIFO, Input and Output to something other then int? As it is this pseudocode is a bit confusing. \$\endgroup\$ – Jan Dorniak Aug 29 '18 at 18:21
  • \$\begingroup\$ It's a pseudo code only, what thype would be more demonstrative? \$\endgroup\$ – Marko Buršič Aug 29 '18 at 18:23
  • \$\begingroup\$ Something suggesting that it stores those messages - something implying a structure, or honestly - anything other than int to differentiate from WR_Ptr and RD_Ptr \$\endgroup\$ – Jan Dorniak Aug 29 '18 at 20:33
  • \$\begingroup\$ @JanDorniak Don't be afraid to post your answer if you have a better solution. \$\endgroup\$ – Marko Buršič Aug 30 '18 at 10:41
  • \$\begingroup\$ not really. And I'm not afraid - mostly I use SE on mobile which isn't conductive to posting good answers. Although I might suggest an edit to yours since it's more of a clarification of your answer then separate answer (FIFOs are fairly standard anyway) \$\endgroup\$ – Jan Dorniak Aug 30 '18 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.