Created
November 7, 2022 13:01
-
-
Save ajsb85/a689787f71725484dc88727a2c4ca09c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int parseRawFormatFast(char *msg, RawMessage *m, bool showJson) | |
{ | |
unsigned int prio, pgn, dst, src, len, r, i; | |
char *p; | |
p = findOccurrence(msg, ',', 1); | |
if (!p) | |
{ | |
return 1; | |
} | |
p--; // Back to comma | |
memcpy(m->timestamp, msg, p - msg); | |
m->timestamp[p - msg] = 0; | |
/* Moronic Windows does not support %hh<type> so we use intermediate variables */ | |
r = sscanf(p, ",%u,%u,%u,%u,%u ", &prio, &pgn, &src, &dst, &len); | |
if (r < 5) | |
{ | |
logError("Error reading message, scanned %u from %s", r, msg); | |
if (!showJson) | |
fprintf(stdout, "%s", msg); | |
return 2; | |
} | |
p = findOccurrence(p, ',', 6); | |
if (!p) | |
{ | |
logError("Error reading message, scanned %zu bytes from %s", p - msg, msg); | |
if (!showJson) | |
fprintf(stdout, "%s", msg); | |
return 2; | |
} | |
for (i = 0; i < len; i++) | |
{ | |
if (scanHex(&p, &m->data[i])) | |
{ | |
logError("Error reading message, scanned %zu bytes from %s/%s, index %u", p - msg, msg, p, i); | |
if (!showJson) | |
fprintf(stdout, "%s", msg); | |
return 2; | |
} | |
if (i < len) | |
{ | |
if (*p != ',' && !isspace(*p)) | |
{ | |
logError("Error reading message, scanned %zu bytes from %s", p - msg, msg); | |
if (!showJson) | |
fprintf(stdout, "%s", msg); | |
return 2; | |
} | |
p++; | |
} | |
} | |
return setParsedValues(m, prio, pgn, dst, src, len); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment