MCPcopy Create free account
hub / github.com/UtilitechAS/amsreader-firmware / parse

Method parse

lib/AmsDecoder/src/GbtParser.cpp:10–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8#include "lwip/def.h"
9
10int8_t GBTParser::parse(uint8_t *d, DataParserContext &ctx) {
11 GBTHeader* h = (GBTHeader*) (d);
12 uint16_t sequence = ntohs(h->sequence);
13
14 if(h->flag != GBT_TAG) return DATA_PARSE_BOUNDARY_FLAG_MISSING;
15
16 if(sequence == 1) {
17 if(buf == NULL) buf = (uint8_t *)malloc((size_t)1024); // TODO find out from first package ?
18 pos = 0;
19 } else if(lastSequenceNumber != sequence-1) {
20 return DATA_PARSE_FAIL;
21 }
22
23 if(buf == NULL) return DATA_PARSE_FAIL;
24
25 uint8_t* ptr = (uint8_t*) &h[1];
26 memcpy(buf + pos, ptr, h->size);
27 pos += h->size;
28 lastSequenceNumber = sequence;
29
30 if((h->control & 0x80) == 0x00) {
31 return DATA_PARSE_INTERMEDIATE_SEGMENT;
32 } else {
33 memcpy((uint8_t *) d, buf, pos);
34 }
35 ctx.length = pos;
36 return DATA_PARSE_OK;
37
38}

Callers 2

PriceService.cppFile · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected