Giter Club home page Giter Club logo

queue's Introduction

Queue Build Status

Queue handling library (designed on Arduino)

This library was designed for Arduino, yet may be compiled without change with gcc for other purposes/targets

Queue class has since start been called Queue. Unfortunately, on some platforms or when using FreeRTOS, Queue is already declared. For compatibility purposes, Queue class has been renamed to cppQueue. Sorry for the inconvenience...

Usage

  • Declare a cppQueue instance (size_t size_rec, uint16_t nb_recs=20, QueueType type=FIFO, bool overwrite=false, void * pQDat=NULL, size_t lenQDat=0) (called q below):
    • size_rec - size of a record in the queue
    • nb_recs - number of records in the queue
    • type - queue implementation type: FIFO, LIFO
    • overwrite - overwrite previous records when queue is full if set to true
    • pQDat - pointer to static data queue
    • lenQDat - length of static data queue (in bytes)
  • Push stuff to the queue using q.push(void * rec)
    • returns true if successfully pushed into queue
    • returns false is queue is full
  • Pop stuff from the queue using q.pop(void * rec) or q.pull(void * rec)
    • returns true if successfully popped from queue
    • returns false if queue is empty
  • Peek stuff from the queue using q.peek(void * rec)
    • returns true if successfully peeked from queue
    • returns false if queue is empty
  • Drop stuff from the queue using q.drop(void)
    • returns true if successfully dropped from queue
    • returns false if queue is empty
  • Peek stuff at index from the queue using q.peekIdx(void * rec, uint16_t idx)
    • returns true if successfully peeked from queue
    • returns false if index is out of range
    • warning: no associated drop function, not to use with q.drop
  • Peek latest stored from the queue using q.peekPrevious(void * rec)
    • returns true if successfully peeked from queue
    • returns false if queue is empty
    • warning: no associated drop function, not to use with q.drop
    • note: only useful with FIFO implementation, use q.peek instead with a LIFO
  • Other methods:
    • q.isInitialized(): true if initialized properly, false otherwise
    • q.isEmpty(): true if empty, false otherwise
    • q.isFull(): true if full, false otherwise
    • q.sizeOf(): queue size in bytes (returns 0 in case queue allocation failed)
    • q.getCount() or q.nbRecs(): number of records stored in the queue
    • q.getRemainingCount(): number of records left in the queue
    • q.clean() or q.flush(): remove all items in the queue

Notes

  • Interrupt safe automation is not implemented in the library. You have to manually disable/enable interrupts where required. No implementation will be made as it would be an issue when using peek/drop methods with LIFO implementation: if an item is put to the queue through interrupt between peek and drop calls, the drop call would drop the wrong (newer) item. In this particular case, dropping decision must be made before re-enabling interrupts.

Examples included

Documentation

Doxygen doc can be generated using "Doxyfile".

See generated documentation

Release Notes

See release notes

See also

cQueue - C implementation of this library

queue's People

Contributors

jarboer avatar per1234 avatar reydelleon avatar smfsw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

queue's Issues

get the minimal value in a queue

Hello,

I would like to get the minimal value of a queue, because I am trying to modify this code https://github.com/Seeed-Studio/Seeed_Arduino_Linechart/blob/master/examples/basic/basic.ino
I thought about writing a for loop with an if loop inside to compare each element but I don't manage to get the value inside the queue. I have tried like the vectors data[i] where data is a std::queue type and i the index.

Does anyone could give me some help?

Best regards,

Alice

Esp32 compatibility

Hi,

Is this library works with esp32 ?

Our process is

  1. Using Wire.onReceive to get data from other controller.
  2. Push data to queue
  3. On the void loop we retrieve the data from queue do a bit manipulation and send to server

Is this process possible ?

Request: add keyword and function POP

Hey,

really like your library. Most implementations do not use the word pull , but use the keyword pop.

Could you maybe implement that? I was trying to add an extra function in the header just to call the pull function, but my C++ is not up to par.

Thanks

Add unit tests and continuous integration

Hello,

I'm considering this library as a dependency for an application.
Althought I'd prefer to rely on a library which have unit tests.

You can find some links dealing with continuous integration and Arduino
https://github.com/adafruit/travis-ci-arduino
https://www.pololu.com/blog/654/continuous-testing-for-arduino-libraries-using-platformio-and-travis-ci
(they are using http://platformio.org/ )

Kind regards

PS : see also https://docs.travis-ci.com/user/integration/platformio/

https://github.com/platformio/platformio-remote-unit-testing-example

See also https://github.com/mmurdoch/arduinounit/

and discussion at mmurdoch/arduinounit#63

parallel access of getRemainingCount() / getCount() / nbRecs()

When trying to access the current remaining count or get count for a queue, the getCount() always gives value as 0 and getRemainingCount() always stays at 50. The queue publish and pop are working because they execute corrdinates on an arm running the motors, but the number of coordinates in the queue currently is not accessible.
Since i'm not able to publish the number of coordinates currently in the queue, it is making it difficult to know when to send next list of points.

Add method to peek last item in queue

Hi,

I am using your (slightly modified) library on a project where I am using a FIFO queue. However before adding a new item I need to check if the last item in the queue has the same properties which I am trying to add. If yes I just don't add a new item. I was wondering if a peek_last() method is worth to be added to the main library (considering that with a LIFO queue it might not make much sense to have it)

Best regards

Limit on data types a Queue may hold?

Hi,

Are there limits on the data types that one may use in the Queues created by this library?

Seeing as initialisation of the Queue involves setting the size of members of the Queue I can see it wouldn't be a good idea to use this library with items whose size isn't known at compile (aka an Arduino String).

But how about queueing objects which are members of a class? Fiddling around with your library I can get expected behaviour when queueing ints, etc. But get 'invalid conversion' errors when using the same code with class objects.

Is this behaviour you would expect? I'd appreciate any feedback you may have!

Missing definition for size_t

The Arduino IDE probably provides a size_t but plain C++ does not. I think cppQueue.h should include stddef.h to be more self-contained.

I've noticed this problem when including cppQueue.h from a C++ source file instead of an .ino sketch. Compiling with the Arduino IDE gives the following error:

[library path omitted]src/cppQueue.h:37:2: error: 'size_t' does not name a type
  size_t   queue_sz; //!< Size of the full queue
  ^~~~~~

ESP8266 - error: 'Queue' does not name a type

Building with PlatformIO through Deviot for ESP8266.

This is the build error:

/Users/booli/queue_test.ino:52:1: error: 'Queue' does not name a type
Queue sendLogDataQueue(sizeof(Logdata), 24, LIFO, true);
^

Relevant code:

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <SoftwareSerial.h>
#include <TickerScheduler.h>
#include <time.h>
#include <FS.h>
#include <Queue.h>
#include "SimpleTime.h"
#include "config.h"
#include "credentials.h"

// Solar data variables
float solar_yield = 0;
float consumption_yield = 0;
uint32_t aggregate_tick = 0;

typedef struct { 
    uint32_t    solar;
    uint32_t    consumption;
    char        date_hour[10];
} Logdata;

Queue sendLogDataQueue(sizeof(Logdata), 24, LIFO, true);

void setup() { 
   // stuff
}

void loop () { 
  // stuff 
}

It does work when I put the library directly into my project folder an use "Queue.h"

issue added from #1 Request

Feature request: interrupt safe

Are there any plans to make this library interrupt safe? That is, safe to use the queue when accessing or modifying a queue in an interrupt service and the setup() and loop() functions.

Here's a more simple example script, in case it's useful to anyone

I had some trouble using the SimpleQueue.ino example script, here's SimplerQueue.ino on the off chance it's useful to anyone:

#include <cppQueue.h>

typedef struct strRec {
  char  url[300];
  char  misc1[255];
} Rec;

cppQueue  queue1(sizeof(Rec), 10, LIFO, true); 

void setup() {
  Serial.begin(115200); 
  
  // Put a sample record into the queue
  Rec test = {"http://google.com", "some stuff"};
  queue1.push(&test);

}

void loop() {  

  // iterate through the queue
  while (!queue1.isEmpty())
  {
    Rec rec;
    queue1.pop(&rec);
    Serial.println("There's something in the queue!");
    Serial.println();
    Serial.print(rec.url);
    Serial.print(" ");
    Serial.print(rec.misc1);

    Serial.println();
    String url = rec.url;
    Serial.println("URL = " + url);
    
    Serial.println();
  }   
  delay(1000);
}

can't transmit string to queue

Hello First of all thank you very much for your development
I am new about Arduino
I want to "991" string transmit to Queue list , but always only get โ€˜1โ€™.
This string ''991' has been pushed to Queue through q.push(). in addition, the string data is also read through the q.pop() ,but the read value is '1'.
maybe I'm using pointer incorrectly!
can you give me some help, thanks a lot.

#include <Arduino_BuiltIn.h>

#include<cppQueue.h>
#include<String.h>

#define QueueLength 10

cppQueue q(sizeof(String* ),QueueLength,FIFO,true);

//Crate 5*5 array
int Location[5][5]
{
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,0,0,0}
};

int Step = 0;
int occupied =1;
int Null =0;
String coordinate(2) ;
int x =9;
int y =9;
int StartButton=2;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Location[x][y]=1; //write 1 to strat position
Step=Step+1;
// char Str1 =char(x);
//char Str2 =char(y);
//char Str3 =char(Step);
String Str1;
String * Str2;
Str1.concat (x) ;
Str1.concat (y) ;
Str1.concat (Step) ;

Str2 = &Str1;
q.push(&Str2);

}

void loop() {
//get location from queue list

if (!q.isEmpty())
{
//String snd;
//String Str;
String * Str1;
for(int i=0; i<3; i++)
{

 Serial.println( q.pop(&Str1)); 
     
 }     

delay(500);
}

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.