mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.3.1 XMLWriter
This commit is contained in:
parent
25b312f379
commit
ad3cf03991
@ -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"
|
||||
|
@ -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
|
||||
|
@ -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)** \<!-- text --\>
|
||||
- **void header()** injects standard XML header string, must be first line.
|
||||
- **void reset()** resets internal state, to be called before new XML is written.
|
||||
- **void comment(char\* text, bool multiLine = false)** \<!-- text --\>
|
||||
if multiline == true it does not indent to allow bigger text blocks
|
||||
multiline is default false.
|
||||
- **flush()** call flush() at the end of writing to empty the internal buffer. **!!**
|
||||
- **void flush()** call flush() at the end of writing to empty the internal buffer. **!!**
|
||||
|
||||
|
||||
### Functions to create simple tags with named fields
|
||||
|
||||
- **tagOpen(tag, newLine)** \<tag\>
|
||||
- **tagOpen(tag, name, newLine)** \<tag name="name"\>
|
||||
- **tagClose()** \</tag\>
|
||||
- **void tagOpen(char\* tag, bool newLine)** \<tag\>
|
||||
- **void tagOpen(char\* tag, char\* name, bool newLine)** \<tag name="name"\>
|
||||
- **void tagClose()** \</tag\>
|
||||
|
||||
|
||||
### Functions to make up tags with multiple fields
|
||||
|
||||
- **tagStart(tag)** \<tag
|
||||
- **tagField(field, string);** field="string"
|
||||
- **tagField(field, T value, base = DEC);** standard math types, field="value"
|
||||
- **tagEnd(newline = true, addSlash = true);** /\>
|
||||
- **void tagStart(char\* tag)** \<tag
|
||||
- **void tagField(char\* field, char\* string)** field="string"
|
||||
- **void tagField(char\* field, T value, uint8_t base = DEC)** standard math types, field="value"
|
||||
- **void tagEnd(bool newline = true, bool addSlash = true);** /\>
|
||||
|
||||
### Functions to make a node
|
||||
|
||||
- **writeNode(tag, value);** \<tag\>value\</tag\>
|
||||
- **writeNode(tag, T value, base = DEC);** standard math types
|
||||
- **void writeNode(char\* tag, bool value);** \<tag\>value\</tag\>
|
||||
- **void writeNode(char\* tag, T value, uint8_t base = DEC);** standard math types.
|
||||
|
||||
### Helper
|
||||
|
||||
- **escape(str)** expands the xml chars: \"\'\<\>\&
|
||||
- **void escape(char\* str)** expands the XML chars: \"\'\<\>\&
|
||||
Note one need to set the **XMLWRITER_ESCAPE_SUPPORT** flag.
|
||||
|
||||
|
||||
### Metrics and debug
|
||||
|
||||
To optimize buffersize in combination with timing.
|
||||
To optimize buffer size in combination with timing.
|
||||
|
||||
- **bufferIndex()** returns the size of the internal buffer
|
||||
- **bytesWritten()** idem, since reset().
|
||||
- **version()** injects the XMLWRITER_VERSION as comment in outputstream.
|
||||
- **debug()** injects comment with internal info.
|
||||
- **uint8_t bufferIndex()** returns the size of the internal buffer.
|
||||
- **uint32_t bytesWritten()** idem, since reset().
|
||||
- **void version()** injects the **XMLWRITER_VERSION** as comment in output stream.
|
||||
- **void debug()** injects comment with internal info.
|
||||
|
||||
|
||||
## Print interface
|
||||
@ -123,12 +128,12 @@ can inject strings.
|
||||
|
||||
## Configuration flags
|
||||
|
||||
| Flag | Value | Meaning |
|
||||
|:----|:----|:----|
|
||||
|XMLWRITER_NONE | 0x00 | minimize output, smaller & faster |
|
||||
|XMLWRITER_COMMENT | 0x01 | allow comments |
|
||||
|XMLWRITER_INDENT | 0x02 | allow indentation |
|
||||
|XMLWRITER_NEWLINE | 0x04 | allow newlines |
|
||||
| Flag | Value | Description |
|
||||
|:-----------------|:------|:-------------|
|
||||
|XMLWRITER_NONE | 0x00 | minimize output, smaller & faster |
|
||||
|XMLWRITER_COMMENT | 0x01 | allow comments |
|
||||
|XMLWRITER_INDENT | 0x02 | allow indentation |
|
||||
|XMLWRITER_NEWLINE | 0x04 | allow newlines |
|
||||
|
||||
- **setConfig(XMLWRITER_NONE);** to minimize the output in bytes.
|
||||
- **setConfig(XMLWRITER_NEWLINE);** to break an XML stream in lines.
|
||||
@ -140,3 +145,8 @@ can inject strings.
|
||||
|
||||
See examples
|
||||
|
||||
|
||||
## Future
|
||||
|
||||
- update documentation
|
||||
-
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: XMLWriter.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.3.0
|
||||
// VERSION: 0.3.1
|
||||
// DATE: 2013-11-06
|
||||
// PURPOSE: Arduino library for creating XML
|
||||
//
|
||||
@ -21,17 +21,21 @@
|
||||
// 0.2.2 2020-04-29 dynamic buffer size in constructor
|
||||
// 0.2.3 2020-06-19 fix library.json
|
||||
// 0.2.4 2020-07-07 fix #6 Print interface made public
|
||||
// 0.3.0 2021-01-09 arduino-ci + unit tests
|
||||
// 0.3.0 2021-01-09 Arduino-ci + unit tests
|
||||
// add getIndentSize(); version(); debug();
|
||||
// 0.3.1 2021-11-11 refactor naming to improve readability
|
||||
// update build-CI,
|
||||
// update readme.md, Badges.
|
||||
//
|
||||
|
||||
|
||||
#include "XMLWriter.h"
|
||||
|
||||
|
||||
XMLWriter::XMLWriter(Print* stream, uint8_t bufsize)
|
||||
XMLWriter::XMLWriter(Print* stream, uint8_t bufferSize)
|
||||
{
|
||||
_bufsize = constrain(bufsize, 2, 250);
|
||||
_buffer = (char *) malloc(_bufsize);
|
||||
_bufferSize = constrain(bufferSize, 2, 250);
|
||||
_buffer = (char *) malloc(_bufferSize);
|
||||
_stream = stream;
|
||||
reset();
|
||||
}
|
||||
@ -45,12 +49,12 @@ XMLWriter::~XMLWriter()
|
||||
|
||||
void XMLWriter::reset()
|
||||
{
|
||||
_indent = 0;
|
||||
_indentStep = 2;
|
||||
_tidx = 0;
|
||||
_bidx = 0;
|
||||
_config = XMLWRITER_COMMENT | XMLWRITER_INDENT | XMLWRITER_NEWLINE;
|
||||
_bytesOut = 0;
|
||||
_indent = 0;
|
||||
_indentStep = 2;
|
||||
_tagIndex = 0;
|
||||
_bufferIndex = 0;
|
||||
_config = XMLWRITER_COMMENT | XMLWRITER_INDENT | XMLWRITER_NEWLINE;
|
||||
_bytesOut = 0;
|
||||
}
|
||||
|
||||
|
||||
@ -84,7 +88,7 @@ void XMLWriter::debug()
|
||||
print(F(" INDENT: "));
|
||||
println(_indent);
|
||||
print(F(" BUFSIZE: "));
|
||||
println(_bufsize);
|
||||
println(_bufferSize);
|
||||
print(F(" -->\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("</");
|
||||
print(_tagStack[--_tidx]);
|
||||
print(_tagStack[--_tagIndex]);
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -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 --
|
||||
|
||||
|
@ -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
|
||||
<!--
|
||||
KMLWriterTest.ino
|
||||
|
@ -7,12 +7,14 @@
|
||||
// URL: https://github.com/RobTillaart/XMLWriter
|
||||
//
|
||||
|
||||
|
||||
#include <XMLWriter.h>
|
||||
|
||||
XMLWriter XML;
|
||||
|
||||
char buffer[24];
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
@ -33,12 +35,14 @@ void setup()
|
||||
DataTypes();
|
||||
|
||||
XML.tagClose();
|
||||
XML.flush();
|
||||
|
||||
uint32_t stop = micros();
|
||||
Serial.println();
|
||||
Serial.println(stop - start);
|
||||
}
|
||||
|
||||
|
||||
void Weather2()
|
||||
{
|
||||
XML.comment("The weather in South Africa");
|
||||
@ -55,6 +59,7 @@ void Weather2()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Weather()
|
||||
{
|
||||
XML.comment("The weather in Nebraska");
|
||||
@ -68,6 +73,7 @@ void Weather()
|
||||
XML.tagClose();
|
||||
}
|
||||
|
||||
|
||||
// casting to keep some compilers happy
|
||||
void AnalogPorts(const char* name)
|
||||
{
|
||||
@ -81,6 +87,7 @@ void AnalogPorts(const char* name)
|
||||
XML.tagClose();
|
||||
}
|
||||
|
||||
|
||||
// casting to keep some compilers happy
|
||||
void DigitalPorts()
|
||||
{
|
||||
@ -91,6 +98,7 @@ void DigitalPorts()
|
||||
XML.tagClose();
|
||||
}
|
||||
|
||||
|
||||
void DataTypes()
|
||||
{
|
||||
XML.comment("Testing dataTypes I");
|
||||
@ -118,8 +126,10 @@ void DataTypes()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
@ -0,0 +1,16 @@
|
||||
compile:
|
||||
# Choosing to run compilation tests on 2 different Arduino platforms
|
||||
platforms:
|
||||
- uno
|
||||
- due
|
||||
- zero
|
||||
- leonardo
|
||||
- m4
|
||||
# - esp32 // has different Ethernet libraries
|
||||
# - esp8266
|
||||
# - mega2560
|
||||
libraries:
|
||||
- "Ethernet"
|
||||
- "SD"
|
||||
- "printHelpers"
|
||||
- "Complex"
|
@ -4,7 +4,7 @@
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: demo XML writer for EthernetClient
|
||||
// DATE: 2020-04-24
|
||||
// URL:
|
||||
// URL: https://github.com/RobTillaart/XMLWriter
|
||||
//
|
||||
|
||||
#include <XMLWriter.h>
|
||||
@ -22,6 +22,7 @@ EthernetServer server(80); // change to your config
|
||||
char httpRequest[40];
|
||||
uint8_t reqCnt;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// HTTP HELPER CODE
|
||||
@ -32,7 +33,7 @@ void HTTP_header(EthernetClient* cl, const char *contentType, bool keepAlive = f
|
||||
cl->print("Content-Type: ");
|
||||
cl->println( contentType );
|
||||
cl->println("Connection: ");
|
||||
cl->println(keepAlive ? "keep-alive":"close");
|
||||
cl->println(keepAlive ? "keep-alive" : "close");
|
||||
cl->println("Refresh: ");
|
||||
cl->println(refresh);
|
||||
cl->println();
|
||||
@ -101,16 +102,16 @@ void loop()
|
||||
// so you can send a reply
|
||||
if (c == '\n' && currentLineIsBlank)
|
||||
{
|
||||
if (strstr(httpRequest, "1.xml"))
|
||||
{
|
||||
if (strstr(httpRequest, "1.xml"))
|
||||
{
|
||||
// send a standard http response header
|
||||
HTTP_header(&client, "text/xml", true, 5);
|
||||
XMLWriter XML(&client);
|
||||
|
||||
|
||||
// XML body
|
||||
XML.header();
|
||||
XML.comment("XMLWriterTest.ino\nThis is a demo of a simple XML lib for Arduino", true);
|
||||
|
||||
|
||||
// use of {} to get indentation that follows the XML (sort of)
|
||||
// it adds no code size, but improves readability a lot
|
||||
XML.tagOpen("Arduino", "42");
|
||||
@ -119,23 +120,23 @@ void loop()
|
||||
{
|
||||
AnalogPorts(XML, "before");
|
||||
DigitalPorts(XML);
|
||||
AnalogPorts(XML,"after");
|
||||
AnalogPorts(XML, "after");
|
||||
}
|
||||
XML.tagClose();
|
||||
}
|
||||
XML.tagClose();
|
||||
break;
|
||||
}
|
||||
if (strstr(httpRequest, "2.xml"))
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (strstr(httpRequest, "2.xml"))
|
||||
{
|
||||
// send a standard http response header
|
||||
HTTP_header(&client, "text/xml", true, 5);
|
||||
XMLWriter XML(&client);
|
||||
|
||||
|
||||
// XML body
|
||||
XML.header();
|
||||
XML.comment("XMLWriterTest.ino\nThis is a demo of a simple XML lib for Arduino", true);
|
||||
|
||||
|
||||
// use of {} to get indentation that follows the XML (sort of)
|
||||
// it adds no code size, but improves readability a lot
|
||||
XML.tagOpen("Arduino", "102");
|
||||
@ -145,10 +146,10 @@ void loop()
|
||||
DataTypes(XML);
|
||||
}
|
||||
XML.tagClose();
|
||||
break;
|
||||
}
|
||||
|
||||
// default page is simple HTML
|
||||
break;
|
||||
}
|
||||
|
||||
// default page is simple HTML
|
||||
// send a standard http response header
|
||||
HTTP_header(&client, "text/html", true, 5);
|
||||
|
||||
@ -203,6 +204,7 @@ void Weather2(XMLWriter xw)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Weather(XMLWriter xw)
|
||||
{
|
||||
xw.comment("The weather in Nebraska");
|
||||
@ -230,6 +232,7 @@ void AnalogPorts(XMLWriter xw, const char* name)
|
||||
xw.tagClose();
|
||||
}
|
||||
|
||||
|
||||
void DigitalPorts(XMLWriter xw)
|
||||
{
|
||||
char buffer[24];
|
||||
@ -241,6 +244,7 @@ void DigitalPorts(XMLWriter xw)
|
||||
xw.tagClose();
|
||||
}
|
||||
|
||||
|
||||
void DataTypes(XMLWriter xw)
|
||||
{
|
||||
xw.comment("Testing dataTypes I");
|
||||
@ -252,7 +256,7 @@ void DataTypes(XMLWriter xw)
|
||||
xw.writeNode("HEX", 42, HEX);
|
||||
xw.writeNode("OCT", 42, OCT);
|
||||
xw.tagClose();
|
||||
|
||||
|
||||
xw.comment("Testing dataTypes II");
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
@ -268,4 +272,6 @@ void DataTypes(XMLWriter xw)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -7,11 +7,13 @@
|
||||
// URL: https://github.com/RobTillaart/XMLWriter
|
||||
//
|
||||
|
||||
|
||||
#include <XMLWriter.h>
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
|
||||
|
||||
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
||||
IPAddress ip( 192, 168, 1, 177);
|
||||
|
||||
@ -22,6 +24,7 @@ EthernetServer server(80); // change to your config
|
||||
char httpRequest[40];
|
||||
uint8_t reqCnt;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// HTTP HELPER CODE
|
||||
@ -221,6 +224,7 @@ void Weather2(XMLWriter* xw)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Weather(XMLWriter* xw)
|
||||
{
|
||||
xw->comment("The weather in Nebraska");
|
||||
@ -234,6 +238,7 @@ void Weather(XMLWriter* xw)
|
||||
xw->tagClose();
|
||||
}
|
||||
|
||||
|
||||
// casting to keep some compilers happy
|
||||
void AnalogPorts(XMLWriter* xw, const char* name)
|
||||
{
|
||||
@ -248,6 +253,7 @@ void AnalogPorts(XMLWriter* xw, const char* name)
|
||||
xw->tagClose();
|
||||
}
|
||||
|
||||
|
||||
// casting to keep some compilers happy
|
||||
void DigitalPorts(XMLWriter* xw)
|
||||
{
|
||||
@ -260,6 +266,7 @@ void DigitalPorts(XMLWriter* xw)
|
||||
xw->tagClose();
|
||||
}
|
||||
|
||||
|
||||
void DataTypes(XMLWriter* xw)
|
||||
{
|
||||
xw->comment("Testing dataTypes I");
|
||||
@ -287,4 +294,6 @@ void DataTypes(XMLWriter* xw)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: XMLWriterPrint_1.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// VERSION: 0.1.1
|
||||
// PURPOSE: demo Print interface
|
||||
// DATE: 2020-07-07
|
||||
// URL: https://github.com/RobTillaart/XMLWriter
|
||||
@ -13,6 +13,7 @@ XMLWriter XML(&Serial);
|
||||
|
||||
char buffer[24];
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
@ -48,11 +49,13 @@ void setup()
|
||||
}
|
||||
XML.tagClose();
|
||||
XML.flush();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,12 +1,13 @@
|
||||
//
|
||||
// FILE: XMLWriterPrint_2.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: demo Print interface - use it to print "unsupported" and Printable datatypes
|
||||
// VERSION: 0.1.1
|
||||
// PURPOSE: demo Print interface - use it to print "unsupported" and Printable data types
|
||||
// DATE: 2020-07-07
|
||||
// URL: https://github.com/RobTillaart/XMLWriter
|
||||
//
|
||||
|
||||
|
||||
#include <XMLWriter.h>
|
||||
#include <printHelpers.h> // https://github.com/RobTillaart/printHelpers
|
||||
|
||||
@ -17,6 +18,7 @@ double large = 5.46372819E30;
|
||||
|
||||
char buffer[24];
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
@ -38,8 +40,11 @@ void setup()
|
||||
XML.flush();
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
//
|
||||
// FILE: XMLWriterPrint_3.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: demo Print interface - Printable datatypes
|
||||
// VERSION: 0.1.1
|
||||
// PURPOSE: demo Print interface - Printable data types
|
||||
// DATE: 2020-07-07
|
||||
// URL: https://github.com/RobTillaart/XMLWriter
|
||||
//
|
||||
@ -10,6 +10,7 @@
|
||||
// example works for UNO but does not compile for ESP,
|
||||
// to investigate [complex vs Complex]
|
||||
|
||||
|
||||
#include <XMLWriter.h>
|
||||
#include <Complex.h> // https://github.com/RobTillaart/Complex
|
||||
|
||||
@ -19,6 +20,7 @@ Complex c(3, 5);
|
||||
|
||||
char buffer[24];
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
@ -38,8 +40,10 @@ void setup()
|
||||
XML.flush();
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
@ -7,12 +7,14 @@
|
||||
// URL: https://github.com/RobTillaart/XMLWriter
|
||||
//
|
||||
|
||||
|
||||
#include <XMLWriter.h>
|
||||
|
||||
XMLWriter XML(&Serial);
|
||||
|
||||
#define NUMBERZ F("1.2.3.4.5")
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
@ -32,8 +34,10 @@ void setup()
|
||||
XML.flush();
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
@ -10,6 +10,7 @@
|
||||
// and it will append to the data.xml file every time started.
|
||||
//
|
||||
|
||||
|
||||
#include <SPI.h>
|
||||
#include <SD.h>
|
||||
// SPI PINS
|
||||
@ -23,6 +24,7 @@
|
||||
|
||||
char buffer[24];
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
@ -80,6 +82,7 @@ void AnalogPorts(XMLWriter* xw, const char* name)
|
||||
xw->tagClose();
|
||||
}
|
||||
|
||||
|
||||
void DigitalPorts(XMLWriter* xw)
|
||||
{
|
||||
xw->comment("The digital ports are not multiplexed");
|
||||
@ -89,8 +92,11 @@ void DigitalPorts(XMLWriter* xw)
|
||||
xw->tagClose();
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -13,6 +13,7 @@ XMLWriter XML(&Serial);
|
||||
|
||||
char buffer[24];
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
@ -36,11 +37,13 @@ void setup()
|
||||
DataTypes();
|
||||
|
||||
XML.tagClose();
|
||||
XML.flush();
|
||||
uint32_t stop = micros();
|
||||
Serial.println(stop - start);
|
||||
Serial.println("done...");
|
||||
}
|
||||
|
||||
|
||||
void Weather2()
|
||||
{
|
||||
XML.comment("The weather in South Africa");
|
||||
@ -57,6 +60,7 @@ void Weather2()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Weather()
|
||||
{
|
||||
XML.comment("The weather in Nebraska");
|
||||
@ -70,6 +74,7 @@ void Weather()
|
||||
XML.tagClose();
|
||||
}
|
||||
|
||||
|
||||
// casting to keep some compilers happy
|
||||
void AnalogPorts(const char* name)
|
||||
{
|
||||
@ -82,6 +87,7 @@ void AnalogPorts(const char* name)
|
||||
XML.tagClose();
|
||||
}
|
||||
|
||||
|
||||
void DigitalPorts()
|
||||
{
|
||||
XML.comment("The digital ports are not multiplexed");
|
||||
@ -91,6 +97,7 @@ void DigitalPorts()
|
||||
XML.tagClose();
|
||||
}
|
||||
|
||||
|
||||
void DataTypes()
|
||||
{
|
||||
XML.comment("Testing dataTypes I");
|
||||
@ -118,8 +125,11 @@ void DataTypes()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: XMLWriterDemo01.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.2
|
||||
// VERSION: 0.1.3
|
||||
// PURPOSE: XML writer demo
|
||||
// DATE: 2016-03-16
|
||||
// URL: https://github.com/RobTillaart/XMLWriter
|
||||
@ -11,6 +11,7 @@
|
||||
|
||||
XMLWriter XML(&Serial);
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
@ -26,6 +27,7 @@ void setup()
|
||||
Serial.println(stop - start);
|
||||
}
|
||||
|
||||
|
||||
void shoot(double p, double y, double r)
|
||||
{
|
||||
uint8_t ID = 0;
|
||||
@ -94,10 +96,13 @@ void shoot(double p, double y, double r)
|
||||
XML.tagClose();
|
||||
|
||||
XML.tagClose(); // shoot
|
||||
XML.flush();
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
@ -1,6 +1,6 @@
|
||||
# Syntax Coloring Map For XMLWriter
|
||||
# Syntax Colouring Map For XMLWriter
|
||||
|
||||
# Datatypes (KEYWORD1)
|
||||
# Data types (KEYWORD1)
|
||||
XMLWriter KEYWORD1
|
||||
|
||||
|
||||
@ -9,23 +9,29 @@ reset KEYWORD2
|
||||
setConfig KEYWORD2
|
||||
header KEYWORD2
|
||||
version KEYWORD2
|
||||
|
||||
debug KEYWORD2
|
||||
comment KEYWORD2
|
||||
newLine KEYWORD2
|
||||
|
||||
tagOpen KEYWORD2
|
||||
tagClose KEYWORD2
|
||||
tagStart KEYWORD2
|
||||
tagField KEYWORD2
|
||||
tagEnd KEYWORD2
|
||||
|
||||
writeNode KEYWORD2
|
||||
setIndentSize KEYWORD2
|
||||
getIndentSize
|
||||
getIndentSize KEYWORD2
|
||||
|
||||
incrIndent KEYWORD2
|
||||
decrIndent KEYWORD2
|
||||
|
||||
indent KEYWORD2
|
||||
raw KEYWORD2
|
||||
escape KEYWORD2
|
||||
flush KEYWORD2
|
||||
|
||||
bufferIndex KEYWORD2
|
||||
bytesWritten KEYWORD2
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/XMLWriter"
|
||||
},
|
||||
"version": "0.3.0",
|
||||
"version": "0.3.1",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*"
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=XMLWriter
|
||||
version=0.3.0
|
||||
version=0.3.1
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for creating XML
|
||||
|
Loading…
Reference in New Issue
Block a user