GY-63_MS5611/libraries/XMLWriter/examples/XMLWriterdemo01/XMLWriterdemo01.ino

109 lines
2.3 KiB
Arduino
Raw Normal View History

//
// FILE: XMLWriterDemo01.ino
// AUTHOR: Rob Tillaart
2021-11-11 14:36:58 -05:00
// VERSION: 0.1.3
// PURPOSE: XML writer demo
// DATE: 2016-03-16
2020-05-25 03:58:04 -04:00
// URL: https://github.com/RobTillaart/XMLWriter
//
#include <XMLWriter.h>
XMLWriter XML(&Serial);
2021-11-11 14:36:58 -05:00
void setup()
{
Serial.begin(115200);
2021-01-29 06:31:58 -05:00
double p = random(100) * 1.0;
double y = random(100) * 1.0;
double r = random(100) * 1.0;
2020-05-25 03:58:04 -04:00
uint32_t start = micros();
shoot(p, y, r);
2020-05-25 03:58:04 -04:00
uint32_t stop = micros();
Serial.println();
Serial.println(stop - start);
}
2021-11-11 14:36:58 -05:00
2021-01-29 06:31:58 -05:00
void shoot(double p, double y, double r)
{
2021-01-29 06:31:58 -05:00
uint8_t ID = 0;
XML.header();
XML.comment("Demo opening tag with multiple fields");
XML.tagOpen("shoot");
XML.comment("use nodes for every field");
XML.tagOpen("position");
2021-01-29 06:31:58 -05:00
XML.writeNode("id", ID++);
XML.writeNode("pitch", p);
XML.writeNode("yaw", y);
XML.writeNode("roll", r);
XML.writeNode("Date", "20160316");
XML.writeNode("Time", "101534");
XML.tagClose(); // position
XML.comment("use tagfields in tag");
XML.tagStart("position");
2021-01-29 06:31:58 -05:00
XML.tagField("id", ID++);
XML.tagField("pitch", p);
XML.tagField("yaw", y);
XML.tagField("roll", r);
XML.tagField("Date", "20160316");
XML.tagField("Time", "101534");
XML.tagEnd();
XML.comment("use manual indent and raw output");
XML.tagStart("position");
2021-01-29 06:31:58 -05:00
XML.tagField("id", ID++);
XML.tagField("pitch", p);
XML.tagField("yaw", y);
XML.tagField("roll", r);
XML.tagEnd(NEWLINE, NOSLASH);
XML.incrIndent();
XML.indent();
XML.raw("20160316\n");
XML.indent();
XML.raw("101534\n");
XML.decrIndent();
XML.tagStart("/position");
XML.tagEnd(NEWLINE, NOSLASH);
XML.comment("use manual indent + nodes");
XML.tagStart("position");
2021-01-29 06:31:58 -05:00
XML.tagField("id", ID++);
XML.tagField("pitch", p);
XML.tagField("yaw", y);
XML.tagField("roll", r);
XML.tagEnd(NEWLINE, NOSLASH);
XML.incrIndent();
XML.writeNode("Date", "20160316");
XML.writeNode("Time", "101534");
XML.decrIndent();
XML.tagStart("/position");
XML.tagEnd(NEWLINE, NOSLASH);
2020-05-25 03:58:04 -04:00
XML.comment("test escape() codes");
XML.tagOpen("supported");
XML.writeNode("ampersand", "&");
XML.writeNode("lessthan", "<");
XML.writeNode("greaterthan", ">");
XML.writeNode("quote", "\"");
XML.writeNode("apostrophe", "\'");
XML.tagClose();
XML.tagClose(); // shoot
2021-11-11 14:36:58 -05:00
XML.flush();
}
2021-11-11 14:36:58 -05:00
void loop()
{
}
2020-05-25 03:58:04 -04:00
2021-11-11 14:36:58 -05:00
2020-05-25 03:58:04 -04:00
// -- END OF FILE --