mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.4 DEVNULL
This commit is contained in:
parent
580182c3ad
commit
53cf5a74de
51
libraries/DEVNULL/DEVNULL.cpp
Normal file
51
libraries/DEVNULL/DEVNULL.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
//
|
||||
// FILE: DEVNULL.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.4
|
||||
// PURPOSE: Arduino library for a /dev/null stream - useful for testing
|
||||
// URL: https://github.com/RobTillaart/DEVNULL
|
||||
//
|
||||
// HISTORY:
|
||||
// 0.1.0 2020-06-23 initial version.
|
||||
// 0.1.1 2020-12-18 add Arduino-CI.
|
||||
// 0.1.2 2021-11-24 update build-CI, badges, etc.
|
||||
// added write(data, length) + _timeOut.
|
||||
// 0.1.3 2021-12-15 update library.json, license, minor edits
|
||||
// 0.1.4 2022-09-21 split up .h in .cpp and .h
|
||||
// add last() to check last byte written to.
|
||||
|
||||
|
||||
#include "DEVNULL.h"
|
||||
|
||||
DEVNULL::DEVNULL()
|
||||
{
|
||||
setTimeout(0); // no timeout.
|
||||
_bottomLessPit = -1; // nothing in the pit
|
||||
}
|
||||
|
||||
int DEVNULL::available() { return 0; };
|
||||
int DEVNULL::peek() { return EOF; };
|
||||
int DEVNULL::read() { return EOF; };
|
||||
// placeholder to keep CI happy
|
||||
void DEVNULL::flush() { return; };
|
||||
|
||||
size_t DEVNULL::write(const uint8_t data)
|
||||
{
|
||||
_bottomLessPit = data;
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t DEVNULL::write( const uint8_t *buffer, size_t size)
|
||||
{
|
||||
if (size > 0) _bottomLessPit = buffer[size - 1];
|
||||
return size;
|
||||
}
|
||||
|
||||
int DEVNULL::lastByte()
|
||||
{
|
||||
return _bottomLessPit;
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
@ -2,47 +2,30 @@
|
||||
//
|
||||
// FILE: DEVNULL.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.3
|
||||
// VERSION: 0.1.4
|
||||
// PURPOSE: Arduino library for a /dev/null stream - useful for testing
|
||||
// URL: https://github.com/RobTillaart/DEVNULL
|
||||
//
|
||||
// HISTORY:
|
||||
// 0.1.0 2020-06-23 initial version.
|
||||
// 0.1.1 2020-12-18 add Arduino-CI.
|
||||
// 0.1.2 2021-11-24 update build-CI, badges, etc.
|
||||
// added write(data, length) + _timeOut.
|
||||
// 0.1.3 2021-12-15 update library.json, license, minor edits
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#define DEVNULL_LIB_VERSION (F("0.1.3"))
|
||||
#define DEVNULL_LIB_VERSION (F("0.1.4"))
|
||||
|
||||
|
||||
class DEVNULL : public Stream
|
||||
{
|
||||
public:
|
||||
DEVNULL()
|
||||
{
|
||||
setTimeout(0); // no timeout.
|
||||
};
|
||||
DEVNULL();
|
||||
|
||||
int available() { return 0; };
|
||||
int peek() { return EOF; };
|
||||
int read() { return EOF; };
|
||||
void flush() { return; }; // placeholder to keep CI happy
|
||||
int available();
|
||||
int peek();
|
||||
int read();
|
||||
void flush(); // placeholder to keep CI happy
|
||||
|
||||
size_t write(const uint8_t data)
|
||||
{
|
||||
_bottomLessPit = data;
|
||||
return 1;
|
||||
};
|
||||
size_t write( const uint8_t *buffer, size_t size)
|
||||
{
|
||||
if (size > 0) _bottomLessPit = buffer[size - 1];
|
||||
return size;
|
||||
};
|
||||
size_t write(const uint8_t data);
|
||||
size_t write( const uint8_t *buffer, size_t size);
|
||||
|
||||
int lastByte();
|
||||
|
||||
private:
|
||||
uint8_t _bottomLessPit;
|
||||
|
@ -30,12 +30,18 @@ with only a return 0; (or at least **print(Type)** as the **println(T)** would o
|
||||
call once extra for the "\n".
|
||||
|
||||
|
||||
#### Version 0.1.2
|
||||
## Versions
|
||||
|
||||
- sets the timeout for reading to 0. No need to wait longer with DEVNULl.
|
||||
#### 0.1.2
|
||||
|
||||
- sets the timeout for reading to 0. No need to wait longer with DEVNULL.
|
||||
this improves the **find(...)** calls substantially.
|
||||
- added **size_t write( const uint8_t \*buffer, size_t size)** for faster string processing.
|
||||
|
||||
#### 0.1.4
|
||||
|
||||
- add **lastByte()** to check last byte written.
|
||||
- split of .cpp
|
||||
|
||||
## Interface
|
||||
|
||||
@ -45,10 +51,10 @@ call once extra for the "\n".
|
||||
- **int read()** always return EOF.
|
||||
- **void flush()** does nothing but keeps some compilers happy.
|
||||
- **size_t write(const uint8_t data)** implements print interface. returns 1.
|
||||
|
||||
0.1.2 added to improve performance a few percent (UNO).
|
||||
|
||||
- **size_t write( const uint8_t \*buffer, size_t size)** implements print interface. returns size.
|
||||
- **size_t write( const uint8_t \*buffer, size_t size)** implements print interface.
|
||||
Returns size.
|
||||
- **int lastByte()** returns last byte written (debug and test purpose).
|
||||
Returns -1 if no byte has been written yet.
|
||||
|
||||
|
||||
## Operation
|
||||
@ -60,11 +66,22 @@ See examples.
|
||||
|
||||
## Future
|
||||
|
||||
- add optional delay to mimic pause / tune behaviour for simulating other devices
|
||||
microseconds - milliseconds?
|
||||
delay per byte or per call to write? (esp long arrays might need other performance
|
||||
feels out of scope for /dev/null
|
||||
#### Could
|
||||
|
||||
- add byte counter (uint32_t)
|
||||
- add lastWrittenByte() - look at the last byte written to the bottomless pit.
|
||||
- investigate if DEVNULL can be used to harvest entropy?
|
||||
- sum xor of all data + timestamp?
|
||||
- enable / disable flag (complex)
|
||||
- => /dev/entropy class?
|
||||
- **flush()** could reset bottomLessPit to -1?
|
||||
|
||||
|
||||
#### Wont
|
||||
|
||||
- add delay to mimic pause / tune behaviour for simulating devices
|
||||
- microseconds
|
||||
- delay per byte, esp long arrays might need other performance
|
||||
- out of scope for /dev/null => separate class?
|
||||
- implement Print class to increase performance?
|
||||
- derived class?
|
||||
|
||||
|
@ -1,10 +1,7 @@
|
||||
//
|
||||
// FILE: DEVNULL_performance.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// AUTHOR: Rob Tillaart0
|
||||
// PURPOSE: demo
|
||||
// DATE: 2021-11-24
|
||||
// (c) : MIT
|
||||
//
|
||||
|
||||
|
||||
@ -80,10 +77,21 @@ void setup()
|
||||
|
||||
|
||||
start = micros();
|
||||
bool b = dn.find("hello");
|
||||
bool b = dn.find((char*)"hello");
|
||||
stop = micros();
|
||||
Serial.print("find: \t");
|
||||
Serial.println(stop - start);
|
||||
Serial.print("find: \t");
|
||||
Serial.println(b);
|
||||
delay(10);
|
||||
|
||||
start = micros();
|
||||
int v = dn.lastByte();
|
||||
stop = micros();
|
||||
Serial.print("last: \t");
|
||||
Serial.println(stop - start);
|
||||
Serial.print("last: \t");
|
||||
Serial.println(v);
|
||||
delay(10);
|
||||
|
||||
|
||||
@ -97,4 +105,3 @@ void loop()
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -0,0 +1,20 @@
|
||||
// test run on IDE 1.8.13 UNO
|
||||
|
||||
DEVNULL_performance.ino
|
||||
DEVNULL_LIB_VERSION: 0.1.4
|
||||
text1: 20
|
||||
text2: 4
|
||||
long: 356
|
||||
float: 596
|
||||
float: 1092
|
||||
float: 1604
|
||||
float: 2120
|
||||
find: 8
|
||||
find: 0
|
||||
last: 4
|
||||
last: 56
|
||||
|
||||
|
||||
Done...
|
||||
|
||||
|
@ -1,13 +1,12 @@
|
||||
# Syntax Colouring Map For DEVNULL
|
||||
|
||||
|
||||
# Data types (KEYWORD1)
|
||||
DEVNULL KEYWORD1
|
||||
|
||||
|
||||
# Methods and Functions (KEYWORD2)
|
||||
# all known from Stream.
|
||||
|
||||
lastByte KEYWORD2
|
||||
|
||||
# Instances (KEYWORD2)
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/DEVNULL.git"
|
||||
},
|
||||
"version": "0.1.3",
|
||||
"version": "0.1.4",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=DEVNULL
|
||||
version=0.1.3
|
||||
version=0.1.4
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for a /dev/null stream
|
||||
|
@ -44,9 +44,14 @@ unittest(test_all)
|
||||
assertEqual(0, dn.available());
|
||||
assertEqual(EOF, dn.peek());
|
||||
assertEqual(EOF, dn.read());
|
||||
|
||||
assertEqual(1, dn.write('a'));
|
||||
assertEqual('a', dn.lastByte());
|
||||
|
||||
assertEqual(11, dn.print("hello world"));
|
||||
assertEqual('d', dn.lastByte());
|
||||
assertEqual(13, dn.println("hello world"));
|
||||
assertEqual(10, dn.lastByte()); // 10 == newline
|
||||
}
|
||||
|
||||
unittest_main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user