11/* ------------------------------------------------------------------------------
2- Parse_Unicore .cpp
2+ Parse_Unicore_Binary .cpp
33
44Unicore message parsing support routines
55
@@ -22,7 +22,7 @@ License: MIT. Please see LICENSE.md for more details
2222// ----------------------------------------
2323
2424// Compute the CRC for the Unicore data
25- uint32_t sempUnicoreComputeCrc (SEMP_PARSE_STATE *parse, uint8_t data)
25+ uint32_t sempUnicoreBinaryComputeCrc (SEMP_PARSE_STATE *parse, uint8_t data)
2626{
2727 uint32_t crc;
2828
@@ -32,7 +32,7 @@ uint32_t sempUnicoreComputeCrc(SEMP_PARSE_STATE *parse, uint8_t data)
3232}
3333
3434// Print the Unicore message header
35- void sempUnicorePrintHeader (SEMP_PARSE_STATE *parse)
35+ void sempUnicoreBinaryPrintHeader (SEMP_PARSE_STATE *parse)
3636{
3737 SEMP_UNICORE_HEADER * header;
3838
@@ -77,12 +77,12 @@ void sempUnicorePrintHeader(SEMP_PARSE_STATE *parse)
7777//
7878
7979// Read the CRC
80- bool sempUnicoreReadCrc (SEMP_PARSE_STATE *parse, uint8_t data)
80+ bool sempUnicoreBinaryReadCrc (SEMP_PARSE_STATE *parse, uint8_t data)
8181{
8282 SEMP_SCRATCH_PAD *scratchPad = (SEMP_SCRATCH_PAD *)parse->scratchPad ;
8383
8484 // Determine if the entire message was read
85- if (--scratchPad->unicore .bytesRemaining )
85+ if (--scratchPad->unicoreBinary .bytesRemaining )
8686 // Need more bytes
8787 return true ;
8888
@@ -100,27 +100,27 @@ bool sempUnicoreReadCrc(SEMP_PARSE_STATE *parse, uint8_t data)
100100 parse->buffer [parse->length - 3 ],
101101 parse->buffer [parse->length - 2 ],
102102 parse->buffer [parse->length - 1 ],
103- scratchPad->unicore .crc & 0xff ,
104- (scratchPad->unicore .crc >> 8 ) & 0xff ,
105- (scratchPad->unicore .crc >> 16 ) & 0xff ,
106- (scratchPad->unicore .crc >> 24 ) & 0xff );
103+ scratchPad->unicoreBinary .crc & 0xff ,
104+ (scratchPad->unicoreBinary .crc >> 8 ) & 0xff ,
105+ (scratchPad->unicoreBinary .crc >> 16 ) & 0xff ,
106+ (scratchPad->unicoreBinary .crc >> 24 ) & 0xff );
107107 }
108108 parse->state = sempFirstByte;
109109 return false ;
110110}
111111
112112// Read the message data
113- bool sempUnicoreReadData (SEMP_PARSE_STATE *parse, uint8_t data)
113+ bool sempUnicoreBinaryReadData (SEMP_PARSE_STATE *parse, uint8_t data)
114114{
115115 SEMP_SCRATCH_PAD *scratchPad = (SEMP_SCRATCH_PAD *)parse->scratchPad ;
116116
117117 // Determine if the entire message was read
118- if (!--scratchPad->unicore .bytesRemaining )
118+ if (!--scratchPad->unicoreBinary .bytesRemaining )
119119 {
120120 // The message data is complete, read the CRC
121- scratchPad->unicore .bytesRemaining = 4 ;
122- scratchPad->unicore .crc = parse->crc ;
123- parse->state = sempUnicoreReadCrc ;
121+ scratchPad->unicoreBinary .bytesRemaining = 4 ;
122+ scratchPad->unicoreBinary .crc = parse->crc ;
123+ parse->state = sempUnicoreBinaryReadCrc ;
124124 }
125125 return true ;
126126}
@@ -143,75 +143,75 @@ bool sempUnicoreReadData(SEMP_PARSE_STATE *parse, uint8_t data)
143143// 2 Output delay time, ms
144144//
145145// Read the header
146- bool sempUnicoreReadHeader (SEMP_PARSE_STATE *parse, uint8_t data)
146+ bool sempUnicoreBinaryReadHeader (SEMP_PARSE_STATE *parse, uint8_t data)
147147{
148148 SEMP_SCRATCH_PAD *scratchPad = (SEMP_SCRATCH_PAD *)parse->scratchPad ;
149149
150150 if (parse->length >= sizeof (SEMP_UNICORE_HEADER))
151151 {
152152 // The header is complete, read the message data next
153153 SEMP_UNICORE_HEADER *header = (SEMP_UNICORE_HEADER *)parse->buffer ;
154- scratchPad->unicore .bytesRemaining = header->messageLength ;
155- parse->state = sempUnicoreReadData ;
154+ scratchPad->unicoreBinary .bytesRemaining = header->messageLength ;
155+ parse->state = sempUnicoreBinaryReadData ;
156156 }
157157 return true ;
158158}
159159
160160// Read the third sync byte
161- bool sempUnicoreBinarySync3 (SEMP_PARSE_STATE *parse, uint8_t data)
161+ bool sempUnicoreBinaryBinarySync3 (SEMP_PARSE_STATE *parse, uint8_t data)
162162{
163163 // Verify sync byte 3
164164 if (data != 0xB5 )
165165 // Invalid sync byte, start searching for a preamble byte
166166 return sempFirstByte (parse, data);
167167
168168 // Read the header next
169- parse->state = sempUnicoreReadHeader ;
169+ parse->state = sempUnicoreBinaryReadHeader ;
170170 return true ;
171171}
172172
173173// Read the second sync byte
174- bool sempUnicoreBinarySync2 (SEMP_PARSE_STATE *parse, uint8_t data)
174+ bool sempUnicoreBinaryBinarySync2 (SEMP_PARSE_STATE *parse, uint8_t data)
175175{
176176 // Verify sync byte 2
177177 if (data != 0x44 )
178178 // Invalid sync byte, start searching for a preamble byte
179179 return sempFirstByte (parse, data);
180180
181181 // Look for the last sync byte
182- parse->state = sempUnicoreBinarySync3 ;
182+ parse->state = sempUnicoreBinaryBinarySync3 ;
183183 return true ;
184184}
185185
186186// Check for the preamble
187- bool sempUnicorePreamble (SEMP_PARSE_STATE *parse, uint8_t data)
187+ bool sempUnicoreBinaryPreamble (SEMP_PARSE_STATE *parse, uint8_t data)
188188{
189189 // Determine if this is the beginning of a Unicore message
190190 if (data != 0xAA )
191191 return false ;
192192
193193 // Look for the second sync byte
194194 parse->crc = 0 ;
195- parse->computeCrc = sempUnicoreComputeCrc ;
195+ parse->computeCrc = sempUnicoreBinaryComputeCrc ;
196196 parse->crc = parse->computeCrc (parse, data);
197- parse->state = sempUnicoreBinarySync2 ;
197+ parse->state = sempUnicoreBinaryBinarySync2 ;
198198 return true ;
199199}
200200
201201// Translates state value into an string, returns nullptr if not found
202- const char * sempUnicoreGetStateName (const SEMP_PARSE_STATE *parse)
202+ const char * sempUnicoreBinaryGetStateName (const SEMP_PARSE_STATE *parse)
203203{
204- if (parse->state == sempUnicorePreamble )
205- return " sempUnicorePreamble " ;
206- if (parse->state == sempUnicoreBinarySync2 )
207- return " sempUnicoreBinarySync2 " ;
208- if (parse->state == sempUnicoreBinarySync3 )
209- return " sempUnicoreBinarySync3 " ;
210- if (parse->state == sempUnicoreReadHeader )
211- return " sempUnicoreReadHeader " ;
212- if (parse->state == sempUnicoreReadData )
213- return " sempUnicoreReadData " ;
214- if (parse->state == sempUnicoreReadCrc )
215- return " sempUnicoreReadCrc " ;
204+ if (parse->state == sempUnicoreBinaryPreamble )
205+ return " sempUnicoreBinaryPreamble " ;
206+ if (parse->state == sempUnicoreBinaryBinarySync2 )
207+ return " sempUnicoreBinaryBinarySync2 " ;
208+ if (parse->state == sempUnicoreBinaryBinarySync3 )
209+ return " sempUnicoreBinaryBinarySync3 " ;
210+ if (parse->state == sempUnicoreBinaryReadHeader )
211+ return " sempUnicoreBinaryReadHeader " ;
212+ if (parse->state == sempUnicoreBinaryReadData )
213+ return " sempUnicoreBinaryReadData " ;
214+ if (parse->state == sempUnicoreBinaryReadCrc )
215+ return " sempUnicoreBinaryReadCrc " ;
216216 return nullptr ;
217217}
0 commit comments