diff --git a/libraries/XMLWriter/.arduino-ci.yml b/libraries/XMLWriter/.arduino-ci.yml index a377a782..37b64d55 100644 --- a/libraries/XMLWriter/.arduino-ci.yml +++ b/libraries/XMLWriter/.arduino-ci.yml @@ -2,9 +2,13 @@ compile: # Choosing to run compilation tests on 2 different Arduino platforms platforms: - uno - - leonardo - due - zero + - leonardo + - m4 + - esp32 + # - esp8266 + # - mega2560 libraries: - "Ethernet" - "SD" diff --git a/libraries/XMLWriter/.github/workflows/arduino_test_runner.yml b/libraries/XMLWriter/.github/workflows/arduino_test_runner.yml index 476456bb..096b975b 100644 --- a/libraries/XMLWriter/.github/workflows/arduino_test_runner.yml +++ b/libraries/XMLWriter/.github/workflows/arduino_test_runner.yml @@ -4,10 +4,14 @@ name: Arduino CI on: [push, pull_request] jobs: - arduino_ci: + runTest: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: Arduino-CI/action@master - # Arduino-CI/action@v0.1.1 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.6 + - run: | + gem install arduino_ci + arduino_ci.rb diff --git a/libraries/XMLWriter/README.md b/libraries/XMLWriter/README.md index c4693321..1df75a64 100644 --- a/libraries/XMLWriter/README.md +++ b/libraries/XMLWriter/README.md @@ -8,6 +8,7 @@ Arduino Library to create simple XML (messages, files, print, ...) + ## Description The XMLWriter class supports generating XML files and send these over a stream @@ -26,10 +27,10 @@ Indicative sizes based upon the examples. Run your tests to find your application optimum. | STREAM | SIZE | -|:------------|:----------| -| Ethernet | 20-30 | -| Serial | 5 | -| SD File | 10-16 | +|:---------|:-----------| +| Ethernet | 20-30 | +| Serial | 5 | +| SD File | 10-16 | **IMPORTANT:** When using buffering you should always call **XML.flush()** at the end of the XML generation. This will flush the last bytes in the internal buffer into the output stream. @@ -37,71 +38,75 @@ at the end of the XML generation. This will flush the last bytes in the internal ## Interface + ### Constructor -- **XMLWriter(stream, bufsize);** Constructor defines the stream and the buffersize +- **XMLWriter(Print\* stream = &Serial, uint8_t bufferSize = 10)** Constructor defines the stream and the buffer size to optimize performance vs memory usage. +Note the default bufferSize of 10 can be optimized. +See table in description above. ### Functions for manual layout control -- **setIndentSize(size = 2)** preferred a multiple of 2; no limit -- **getIndentSize()** returns set indent -- **incrIndent()** increments indent by 2 spaces -- **decrIndent()** decrements indent by 2 spaces -- **indent()** manually indent output -- **raw(str)** inject any string +- **void setIndentSize(uint8_t size = 2)** preferred a multiple of 2; no limit. +- **uint8_t getIndentSize()** returns set indent. +- **void incrIndent()** increments indent by 2 spaces. +- **void decrIndent()** decrements indent by 2 spaces. +- **void indent()** manually indent output. +- **void raw(char\* str)** inject any string. ### General settings -- **setConfig(cfg)** used to show/strip comment, indent, newLine. -use **setConfig(0);** to minimize the output -- **newLine(n)** add a number of newlines to the output, default = 1 +- **void setConfig(uint8_t config)** used to show/strip comment, indent, newLine. +use **setConfig(0);** to minimize the output. +- **void newLine(uint8_t n)** add a number of newlines to the output, default = 1. ### Functions -- **header()** injects standard XML header string, must be first line -- **reset()** resets internal state, to be called before new XML is written -- **comment(text, multiline)** \\n")); } @@ -118,9 +122,10 @@ void XMLWriter::tagOpen(const char* tag, const bool newline) tagOpen(tag, "", newline); } + void XMLWriter::tagOpen(const char* tag, const char* name, const bool newline) { - if (_tidx > XMLWRITER_MAXLEVEL) + if (_tagIndex > XMLWRITER_MAXLEVEL) { comment("MAXLEVEL exceeded."); comment(tag); @@ -135,22 +140,24 @@ void XMLWriter::tagOpen(const char* tag, const char* name, const bool newline) flush(); return; } - strcpy(_tagStack[_tidx++], tag); + strcpy(_tagStack[_tagIndex++], tag); tagStart(tag); if (name[0] != 0) tagField("name", name); tagEnd(newline, NOSLASH); _indent += _indentStep; } + void XMLWriter::tagClose(const bool ind) { _indent -= _indentStep; if (ind) indent(); print("\n"); } + void XMLWriter::tagStart(const char *tag) { indent(); @@ -158,6 +165,7 @@ void XMLWriter::tagStart(const char *tag) print(tag); } + void XMLWriter::tagField(const char *field, const char* str) { print(' '); @@ -171,6 +179,7 @@ void XMLWriter::tagField(const char *field, const char* str) print('"'); } + void XMLWriter::tagEnd(const bool newline, const bool addSlash) { if (addSlash) print("/>"); @@ -178,6 +187,7 @@ void XMLWriter::tagEnd(const bool newline, const bool addSlash) if (newline) print('\n'); } + void XMLWriter::writeNode(const char* tag, const char* str) { tagOpen(tag, "", NONEWLINE); @@ -199,11 +209,13 @@ void XMLWriter::tagField(const char *field, const uint8_t value, const uint8_t b tagField(field, (uint32_t) value, base); } + void XMLWriter::tagField(const char *field, const uint16_t value, const uint8_t base) { tagField(field, (uint32_t) value, base); } + void XMLWriter::tagField(const char *field, const uint32_t value, const uint8_t base) { print(' '); @@ -213,21 +225,25 @@ void XMLWriter::tagField(const char *field, const uint32_t value, const uint8_t print('"'); } + void XMLWriter::tagField(const char *field, const int8_t value, const uint8_t base) { tagField(field, (int32_t) value, base); } + void XMLWriter::tagField(const char *field, const int16_t value, const uint8_t base) { tagField(field, (int32_t) value, base); } + void XMLWriter::tagField(const char *field, const int value, const int base) { tagField(field, (int32_t) value, (uint8_t) base); } + void XMLWriter::tagField(const char *field, const int32_t value, const uint8_t base) { print(' '); @@ -237,6 +253,7 @@ void XMLWriter::tagField(const char *field, const int32_t value, const uint8_t b print('"'); } + void XMLWriter::tagField(const char *field, const bool value) { print(' '); @@ -245,6 +262,7 @@ void XMLWriter::tagField(const char *field, const bool value) print(value ? F("=\"true\"") : F("=\"false\"")); } + void XMLWriter::tagField(const char *field, const double value, const uint8_t decimals) { print(' '); @@ -254,6 +272,7 @@ void XMLWriter::tagField(const char *field, const double value, const uint8_t de print('"'); } + /////////////////////////////////////////////////////////////// // // WRITENODE @@ -263,11 +282,13 @@ void XMLWriter::writeNode(const char* tag, const uint8_t value, const uint8_t ba writeNode(tag, (uint32_t) value, base); } + void XMLWriter::writeNode(const char* tag, const uint16_t value, const uint8_t base) { writeNode(tag, (uint32_t) value, base); } + void XMLWriter::writeNode(const char* tag, const uint32_t value, const uint8_t base) { tagOpen(tag, "", NONEWLINE); @@ -275,21 +296,25 @@ void XMLWriter::writeNode(const char* tag, const uint32_t value, const uint8_t b tagClose(NOINDENT); } + void XMLWriter::writeNode(const char* tag, const int8_t value, const uint8_t base) { writeNode(tag, (int32_t) value, base); } + void XMLWriter::writeNode(const char* tag, const int16_t value, const uint8_t base) { writeNode(tag, (int32_t) value, base); } + void XMLWriter::writeNode(const char* tag, const int value, const int base) { writeNode(tag, (int32_t) value, (uint8_t) base); } + void XMLWriter::writeNode(const char* tag, const int32_t value, const uint8_t base) { tagOpen(tag, "", NONEWLINE); @@ -297,6 +322,7 @@ void XMLWriter::writeNode(const char* tag, const int32_t value, const uint8_t ba tagClose(NOINDENT); } + void XMLWriter::writeNode(const char* tag, const bool value) { tagOpen(tag, "", NONEWLINE); @@ -305,6 +331,7 @@ void XMLWriter::writeNode(const char* tag, const bool value) tagClose(NOINDENT); } + void XMLWriter::writeNode(const char* tag, const double value, const uint8_t decimals) { tagOpen(tag, "", NONEWLINE); @@ -312,6 +339,7 @@ void XMLWriter::writeNode(const char* tag, const double value, const uint8_t dec tagClose(NOINDENT); } + void XMLWriter::indent() { if (_config & XMLWRITER_INDENT) @@ -322,21 +350,24 @@ void XMLWriter::indent() } } + size_t XMLWriter::write(uint8_t c) { - _buffer[_bidx++] = c; - if (_bidx == (_bufsize - 1)) flush(); + _buffer[_bufferIndex++] = c; + if (_bufferIndex == (_bufferSize - 1)) flush(); return 1; }; + void XMLWriter::flush() { - _bytesOut += _bidx; - if (_bidx > 0) + _bytesOut += _bufferIndex; + if (_bufferIndex > 0) { - _buffer[_bidx] = 0; - _stream->print(_buffer); - _bidx = 0; + _buffer[_bufferIndex] = 0; + _stream->write(_buffer, _bufferIndex); // saves ~40 bytes on UNO. + // _stream->print(_buffer); + _bufferIndex = 0; } }; diff --git a/libraries/XMLWriter/XMLWriter.h b/libraries/XMLWriter/XMLWriter.h index 14a3f645..d84bdbad 100644 --- a/libraries/XMLWriter/XMLWriter.h +++ b/libraries/XMLWriter/XMLWriter.h @@ -2,7 +2,7 @@ // // FILE: XMLWriter.h // AUTHOR: Rob Tillaart -// VERSION: 0.3.0 +// VERSION: 0.3.1 // DATE: 2013-11-06 // PURPOSE: Arduino library for creating XML // @@ -11,7 +11,7 @@ #include "Arduino.h" -#define XMLWRITER_VERSION (F("0.3.0")) +#define XMLWRITER_VERSION (F("0.3.1")) // for comment() @@ -54,14 +54,14 @@ class XMLWriter : public Print { public: // default = Serial - XMLWriter(Print* stream = &Serial, uint8_t bufsize = 10); + XMLWriter(Print* stream = &Serial, uint8_t bufferSize = 10); ~XMLWriter(); void reset(); // to show/strip comment, indent, newLine // to minimize the output setConfig(0); - void setConfig(uint8_t cfg) { _config = cfg; }; + void setConfig(uint8_t config) { _config = config; }; // standard XML header void header(); @@ -151,12 +151,12 @@ public: // metrics - uint8_t bufferIndex() { return _bidx; }; + uint8_t bufferIndex() { return _bufferIndex; }; uint32_t bytesWritten() { return _bytesOut; }; private: - // outputstream, Print Class + // output stream, Print Class Print* _stream; size_t write(uint8_t c); @@ -169,14 +169,16 @@ private: // stack - used to remember the current tagname to create // automatic the right close tag. - uint8_t _tidx; + uint8_t _tagIndex; char _tagStack[XMLWRITER_MAXLEVEL][XMLWRITER_MAXTAGSIZE + 1]; // output admin char * _buffer; - uint8_t _bufsize; - uint8_t _bidx; + uint8_t _bufferSize; + uint8_t _bufferIndex; uint32_t _bytesOut; }; + // -- END OF FILE -- + diff --git a/libraries/XMLWriter/examples/KMLWriterTest/KMLWriterTest.ino b/libraries/XMLWriter/examples/KMLWriterTest/KMLWriterTest.ino index 90e2867a..5e8e5a8e 100644 --- a/libraries/XMLWriter/examples/KMLWriterTest/KMLWriterTest.ino +++ b/libraries/XMLWriter/examples/KMLWriterTest/KMLWriterTest.ino @@ -13,6 +13,7 @@ XMLWriter KML(&Serial); char buffer[24]; + void setup() { Serial.begin(115200); @@ -24,10 +25,12 @@ void setup() Serial.println(stop - start); } + void loop() { } + void KMLTest() { KML.setIndentSize(2); @@ -62,8 +65,10 @@ void KMLTest() KML.tagStart("/kml"); KML.tagEnd(NEWLINE, NOSLASH); + KML.flush(); } + /* output