QueueArray library max queue size

Status
Not open for further replies.

Lorenzo

Well-known member
Hello forum,

I have a very quick question that I was not able to solve online.
Which is the maximum default size of a queue in the Queue Array library? And how can I set a different size of the queue?

Thank you very much,
Lorenzo
 
QueueArray uses malloc, and hasnt been updated in 3 years
it is just a ring buffer supporting multiple types as well
 
I have a little trouble using Circular Buffer.

I have initialize the buffer as follows:

Code:
#include "circular_buffer.h"
Circular_Buffer<byte, 8, 512> myBuffer;

bacause I need 8 slots of 512 bytes.
And I am writing the 512 bytes as follows:

Code:
myBuffer.write(SDPacket,BYTE_SD_PACKET);

and it works. (I can read the myBuffer.size(); increasing).

How can I extract (read) the 512 packet from the buffer?

I have tryed different ways with packet=myBuffer.read(); or packet=myBuffer.pop_front();
but without success.

Any suggestions?
Thank you.
 
ok first you know the size of the array 512bytes
so
even if you forget the size, the library is smart enough to tell you what the size you wrote, not the raw space
ex, if you wrote 256 bytes instead of 512, it will tell you 256.
Here we go:

to get the length of the buffer in queue, do this:
Code:
uint16_t length = myBuffer.length_front();
then you create a buffer for yourself
Code:
uint8_t mySDBuf[length];
Now to get the data out AND dequeue at same time, just:
Code:
myBuffer.pop_front(mySDBuf,length);

IF you prefer to access the data directly without dequeueing, you may also do so:
Code:
myBuffer.peek_front()[i] ; // where I is the indice of the array you want to read

example:
Code:
for ( uint16_t i = 0; i < myBuffer.length_front(); i++ ) {
  Serial.print(myBuffer.peek_front()[i]);
  Serial.print(" "); // a space between bytes
}
Serial.println();

that will read the whole buffer but not dequeue
to finally dequeue it you can do:
Code:
myBuffer.pop_front();

by the way, the array system your using requires a buffered input
you need to feed the SD's buffer and length to it:
Code:
myBuffer.write(SDPacketBuffer,length);

You cant feed it single bytes. If you choose the ring buffer, you can, but doesnt make sense to run 8 ring buffers when your data is already there to be dumped immediately in a array in less that 5uS time
you can also do:
Code:
myBuffer.push_front(SDPacketBuffer,length);
myBuffer.push_back(SDPacketBuffer,length);

you can queue and dequeue from either back or front of the queue, but never do single bytes, yes, a queue will be created, but not with all your entries in it, the array system needs an entire buffer to write to it
 
Thank you very much for the help!

Actually, when I write in the buffer I can see the size of the buffer increasing from 0 to 8 but myBuffer.length_front() is always 0.

This is my code:

Code:
#include "circular_buffer.h"
Circular_Buffer<byte, 8, 512> myBuffer;

#define BYTE_PACKET 512
uint8_t dataPacket[BYTE_PACKET];

void setup() 
{
  dataPacket[0] = 0x01;
  dataPacket[1] = 0x02;
  dataPacket[2] = 0x03;
  // DATA
  for (uint i = 3; i < sizeof(dataPacket); i++) dataPacket[i - 3] = 0x00;
  // STOP
  dataPacket[31] = 0x04;
  dataPacket[32] = 0x05;
  dataPacket[33] = 0x06;
}



void loop() 
{
  myBuffer.write(dataPacket, BYTE_PACKET);
  Serial.println(myBuffer.length_front());
  Serial.println(myBuffer.size());
  delay(1000);
}
 
Status
Not open for further replies.
Back
Top