Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for SX1262 modules #123

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
2,445 changes: 2,445 additions & 0 deletions lib/Queue/Doxyfile

Large diffs are not rendered by default.

2,445 changes: 2,445 additions & 0 deletions lib/Queue/Doxyfile.auto

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions lib/Queue/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2017-2020, SMFSW
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
75 changes: 75 additions & 0 deletions lib/Queue/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Queue [![Build Status](https://travis-ci.com/SMFSW/Queue.svg?branch=master)](https://travis-ci.com/SMFSW/Queue)

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 `(uint16_t size_rec, uint16_t nb_recs=20, QueueType type=FIFO, overwrite=false)` (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_
- 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

- [SimpleQueue.ino](examples/SimpleQueue/SimpleQueue.ino): Simple queue example (both LIFO FIFO implementations can be tested)
- [PointersQueue.ino](examples/PointersQueue/PointersQueue.ino): Queue of string pointers for string processing
- [QueueDuplicates.ino](examples/QueueDuplicates/QueueDuplicates.ino): Simple test to test queue duplicates before pushing to queue
- [QueueIdxPeeking.ino](examples/QueueIdxPeeking/QueueIdxPeeking.ino): Simple test to test queue index picking
- [RolloverTest.ino](examples/RolloverTest/RolloverTest.ino): Simple test to test queue rollover (for lib testing purposes mainly)
- [LibTst.ino](examples/LibTst/LibTst.ino): flexible test (for lib testing purposes mainly)

## Documentation

Doxygen doc can be generated using "Doxyfile".

See [generated documentation](https://smfsw.github.io/Queue/)

## Release Notes

See [release notes](ReleaseNotes.md)

## See also

[cQueue](https://github.com/SMFSW/cQueue) - C implementation of this library
61 changes: 61 additions & 0 deletions lib/Queue/ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
Queue handling library (designed on Arduino)
2017-2020 SMFSW

Feel free to share your thoughts @ xgarmanboziax@gmail.com about:
- issues encountered
- optimizations
- improvements & new functionalities

------------

** Actual:

v1.9: 4 Nov 2020:
- Queue class renamed to cppQueue

v1.8: 4 Nov 2019:
- const qualifiers added where missing
- Added peekIdx and peekPrevious methods
- Added related examples

v1.7: 2 Jun 2019:
- Fixed README.md thanks to @reydelleon
- INC_IDX & DEC_IDX macros changed to inlines
- Added nonnull function attribute where needed
- Updated Doxyfile

v1.6 26 May 2018:
- Constructor does not check anymore if class instance is already allocated (as it supposedly isn't)
- Added getRemainingCount inline returning how much records are left in the queue
- Added sizeOf inline to check full queue size in byte (may also be used to check if queue has been allocated properly)
- Adding support for unit tests and doxygen documentation generation with Travis CI (using travis-ci-arduino from adafruit before custom bash files needed)
- Travis bash scripts found in SMFSW travis-ci-arduino forked repository
- Removed Doxygen anchor with version in source headers
- Updated README.md
- Added more example sketches & updated LibTst example using latest inlines additions

v1.5 14 March 2018:
- Added isInitialized inline to be able to check after init if queue has been properly allocated
- Added flush inline (to have the same functions as in cQueue library)
- LIFO peek temporary variable is uint16_t (same type as in variable)
- Comments fixes

v1.4 21 November 2017:
- Added const qualifier for function parameters

v1.3 12 July 2017:
- #2 fix for esp8266: renamed cpp/h files : header name already used in compiler sys includes
- examples updated with new header file name (cppQueue.h)
- comply with Arduino v1.5+ IDE source located in src subfolder

v1.2 07 July 2017:
- #1 added pull inline for compatibility with older versions (v1.0)
- #2 surrounded c libs with extern C

v1.1 06 July 2017:
- pop keyword used (instead of pull)
- peek & drop functions added
- examples updated to reflect latest changes

v1.0 22 March 2017:
- First release
86 changes: 86 additions & 0 deletions lib/Queue/examples/LibTst/LibTst.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
Lib Test

LIFO / FIFO implementations can be tested by changing IMPLEMENTATION

This example code is in the public domain.

created 22 March 2017
modified 04 November 2020
by SMFSW
*/

#include <cppQueue.h>

#define IMPLEMENTATION FIFO
#define OVERWRITE true

#define NB_PUSH 14
#define NB_PULL 11


typedef struct strRec {
uint16_t entry1;
uint16_t entry2;
} Rec;

Rec tab[6] = {
{ 0x1234, 0x3456 },
{ 0x5678, 0x7890 },
{ 0x90AB, 0xABCD },
{ 0xCDEF, 0xEFDC },
{ 0xDCBA, 0xBA09 },
{ 0x0987, 0x8765 }
};

cppQueue q(sizeof(Rec), 10, IMPLEMENTATION, OVERWRITE); // Instantiate queue

// the setup function runs once when you press reset or power the board
void setup() {
Serial.begin(115200);

Serial.print("Queue is ");
Serial.print(q.sizeOf());
Serial.println(" bytes long.");
}

// the loop function runs over and over again forever
void loop() {
unsigned int i;

for (i = 0 ; i < NB_PUSH ; i++)
{
Rec rec = tab[i % (sizeof(tab)/sizeof(Rec))];
q.push(&rec);
Serial.print(rec.entry1, HEX);
Serial.print(" ");
Serial.print(rec.entry2, HEX);
Serial.print(" Count ");
Serial.print(q.getCount());
Serial.print(" Remaining ");
Serial.print(q.getRemainingCount());
Serial.print(" Full? ");
Serial.println(q.isFull());
}

Serial.print("Full?: ");
Serial.print(q.isFull());
Serial.print(" Nb left: ");
Serial.println(q.getCount());
for (i = 0 ; i < NB_PULL+1 ; i++)
{
Rec rec = {0xffff,0xffff};
if (i != NB_PULL / 2) { Serial.print(q.pop(&rec)); }
else { Serial.print("Test Peek: "); Serial.print(q.peek(&rec)); }
Serial.print(" ");
Serial.print(rec.entry1, HEX);
Serial.print(" ");
Serial.println(rec.entry2, HEX);
}
Serial.print("Empty?: ");
Serial.print(q.isEmpty());
Serial.print(" Nb left: ");
Serial.println(q.getCount());

while(1);
}
53 changes: 53 additions & 0 deletions lib/Queue/examples/PointersQueue/PointersQueue.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Pointers Queue
Pointers queue demonstration

This example code is in the public domain.

created 25 May 2018
modified 04 November 2020
by SMFSW
*/

#include <cppQueue.h>


const char * str[3] = {
">>> This example demonstrates how to strip quotes",
">>> from strings using a queue of pointers",
">>> to access methods from the string class."
};

cppQueue q(sizeof(String *), 3, FIFO); // Instantiate queue


// the setup function runs once when you press reset or power the board
void setup() {
Serial.begin(115200);
}

// the loop function runs over and over again forever
void loop() {
String strings[3];
String * pStr;

Serial.println("Original text:");
for (unsigned int i = 0 ; i < 3 ; i++)
{
strings[i] = str[i];
pStr = &strings[i];
q.push(&pStr);
Serial.println(strings[i]);
}

Serial.println("");
Serial.println("Processed text:");
for (unsigned int i = 0 ; i < 3 ; i++)
{
q.pop(&pStr);
pStr->remove(0, 4);
Serial.println(*pStr);
}

while(1);
}
Loading