forked from dastcvi/StrateoleXML
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXMLWriter_v5.h
165 lines (133 loc) · 4.17 KB
/
XMLWriter_v5.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
* XMLWriter_v5.h
* XML writer specifically designed for communicating with
* Zephyr Iridium Modem
* Author: Marika Schubert
* January 2017
*
* Adapted: Alex St. Clair (v4, v5)
* August 2019
*
* This library will allow devices on the Strateole project
* to write specific message types in XML to the Zephyr Gondola.
* This file will write the Tag->Tag contents of a message to a
* character output buffer, run the CRC check on this buffer, then
* send the buffer with the proper CRC.
*
* * Version 3 adds DIB/MCB Communications
* * Version 4 updates the interface for StratoCore
* * Version 5 removes DIB/MCB Communications, cleans the interface, and
* adds bigger, safer, more efficient bufferering
*
* This code has the following dependencies:
*
* "Arduino.h"
* "Time.h"
* <BitPacking.h>
*/
#ifndef XMLWRITER_H
#define XMLWRITER_H
#include "InstInfo.h"
#include "Arduino.h"
#include "TimeLib.h"
#define TMBUF_MAXSIZE 8192
enum StateFlag_t {
UNKN,
FINE,
WARN,
CRIT,
NOMESS
};
class XMLWriter {
public:
#ifdef XMLDEBUG
XMLWriter(Print* stream, Instrument_t inst, Stream * log);
#else
XMLWriter(Print* stream, Instrument_t inst);
#endif
// Call to set names of state flags
void setStateFlags(uint8_t num, String flag);
// Call to set values of state flags
void setStateFlagValue(uint8_t num, StateFlag_t stat);
// Call to set value of details
void setStateDetails(uint8_t num, String details);
// Send specific messages
void IMR();
void S();
void RA();
void IMAck(bool ackval);
void TCAck(bool ackval);
// Telemetry packet
void TM();
void TM_String(StateFlag_t state_flag, const char * message);
// Interacting with telemetry buffer
bool addTm(uint8_t inChar);
bool addTm(uint16_t inWord);
bool addTm(uint32_t inDouble);
bool addTm(String inStr);
bool addTm(const uint8_t * buffer, uint16_t size);
bool addTm(const uint16_t * buffer, uint16_t size);
void clearTm();
uint16_t getTmLen();
uint16_t getTmBuffer(uint8_t ** buffer);
private:
void reset();
// Reset crc calculation
void crcReset();
// Returns current crc
uint16_t crcValue();
// Write the new byte over serial, and update the CRC
void writeAndUpdateCRC(uint8_t data);
void writeAndUpdateCRC(uint8_t* data, uint8_t length);
void writeAndUpdateCRC(const char* data);
// Writes crc node and resets crc value
void writeCRC();
// Sends Msg node
uint16_t msgNode();
// Sends Inst Node
void instNode();
// <tag>
void tagOpen(const char* tag);
// </tag>
void tagClose(const char* tag);
// \t<field>value</field>
void writeNode(const char* tag, const char* value); //string
void writeNode(const char* tag, String value);
void writeNode(const char* tag, char* value, uint8_t length); //char array
void writeNode(const char* tag, uint8_t value);
void writeNode(String tag, String value);
void writeNode(String tag, const char* value);
// Creates and wraps binary section
// Called from TM
void sendBin();
// sends an empty binary section
void sendEmptyBin();
// builds TM message body
void sendTMBody();
// internal interaction with the tm buffer
bool addTMByte(uint8_t in_byte);
// output streams
Print* _stream;
Print* _log;
// working crc to transmit for both XML and binary sections
uint16_t tx_crc;
// Instrument id
Instrument_t instrument;
// Telemetry state fields
String StateFlag1 = "StateFlag1";
String StateFlag2 = "StateFlag2";
String StateFlag3 = "StateFlag3";
StateFlag_t flag1 = FINE;
StateFlag_t flag2 = NOMESS; //Only the first one is mandatory
StateFlag_t flag3 = NOMESS;
String details1 = "";
String details2 = "";
String details3 = "";
// Telemetry buffer
uint8_t tm_buffer[TMBUF_MAXSIZE];
uint16_t num_tm_elements = 0;
bool tm_buff_sent = false;
uint16_t messCount = 1;
};
#endif
// END OF FILE