From 2539732e45c43c66ca15fb4934b5e1cbc16df154 Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Sat, 7 Jun 2025 17:24:20 +0200 Subject: [PATCH] correct morep_valid (raw data format) --- morep_valid.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/morep_valid.c b/morep_valid.c index 6d3d246..167061a 100644 --- a/morep_valid.c +++ b/morep_valid.c @@ -36,6 +36,7 @@ char *progname = NULL; int stop = 0; #define BUFMAX 4096 +#define MAXPAYLOAD 1500 void sig_handler (int sig) { @@ -81,16 +82,9 @@ char *read_stream (FILE *sd, int *plen) return buffer; } -void print_message (FILE *fd, char *etype, int mode, uint8_t msg, int seqnum, uint8_t *payload, int len) +void print_message (FILE *fd, char *etype, int mode, uint8_t msg, int seqnum, char *buffer) { - fprintf (fd, "%c%s SEG=%d MSG=%d LEN=%d", mode ? 'T' : 'R', etype, seqnum, msg, len); - if (len > 0) { - int i; - fprintf (fd, " PAYLOAD="); - for (i = 0; i < len; i++) { - fprintf (fd, "%02x%c", payload[i], (i == len - 1) ? '\n' : ':'); - } - } + fprintf (fd, "%c%s SEG=%d MSG=%d %s\n", mode ? 'T' : 'R', etype, seqnum, msg, buffer); } typedef struct { @@ -288,19 +282,20 @@ int main (int argc, char **argv) uint8_t msgtype; TEST_CHARS (tmp, " \t", 0); if (strncmp (tmp, "MSG", 3) != 0) { - VERBOSE (morep, WARNING, PRINTF ("can't parse line '%s' (%s)\n", line, tmp)); + VERBOSE (morep, WARNING, PRINTF ("can't parse line '%s' (%c)\n", line, *tmp)); continue; } tmp += 3; TEST_CHARS (tmp, " \t=", 0); msgtype = strtol (tmp, &tmp, 0); - if ((*tmp != ' ') && (*tmp != '\t')) { - VERBOSE (morep, WARNING, PRINTF ("can't parse line '%s'\n", line)); + if ((*tmp != ' ') && (*tmp != '\t') && (*tmp != '\0')) { + VERBOSE (morep, WARNING, PRINTF ("can't parse line '%s (%c)'\n", line, *tmp)); continue; } RAW_DATA_t payload = {0}; - if (parse_raw_data (tmp, &payload) < 0) { + int fieldmask = 0; + if ((fieldmask = parse_raw_data (tmp, &payload)) < 0) { VERBOSE (morep, WARNING, PRINTF ("can't parse line '%s'\n", line)); continue; } @@ -310,28 +305,32 @@ int main (int argc, char **argv) if (mode == 1) { int seqnum = MOREP_Send (comm->morep, msgtype, payload.data, payload.data_len); if (log) { - print_message (log, comm->etype, 1, msgtype, seqnum, payload.data, payload.data_len); + char buffer[MAXPAYLOAD * 3 + 32] = {0}; + format_raw_data (&payload, buffer, sizeof (buffer)); + print_message (log, comm->etype, 1, msgtype, seqnum, buffer); } } else { /* receive */ uint8_t rxmsgtype = 0; - uint8_t rxpayload[MOREP_PAYLOAD] = {0}; + uint8_t rxdata[MOREP_PAYLOAD] = {0}; + RAW_DATA_t rxpayload = {0}; int rxlen = -1; - int seqnum = MOREP_Receive (comm->morep, &rxmsgtype, rxpayload, &rxlen); + int seqnum = MOREP_Receive (comm->morep, &rxmsgtype, rxdata, &rxlen); /* check msg type */ if (rxmsgtype != msgtype) { VERBOSE (morep, WARNING, PRINTF ("R%s SEQ=%d MSG=%d: expected msgtype %d\n", comm->etype, seqnum, rxmsgtype, msgtype)); } /* check payload */ - else if ((rxlen != payload.data_len) || - ((memcmp (rxpayload, payload.data, rxlen) != 0))) { + else if ((deserial_raw_data (rxdata, rxlen, &rxpayload)) || (check_raw_data (&payload, &rxpayload, fieldmask))) { VERBOSE (morep, WARNING, PRINTF ("R%s SEQ=%d MSG=%d: payloads differed %d/%d\n", comm->etype, seqnum, rxmsgtype, payload.data_len, rxlen)); } else { VERBOSE (morep, INFO, PRINTF ("R%s SEQ=%d MSG=%d: payloads matched [%d]\n", comm->etype, seqnum, rxmsgtype, rxlen)); + if (log) { + char buffer[MAXPAYLOAD * 3 + 32] = {0}; + format_raw_data (&rxpayload, buffer, sizeof (buffer)); + print_message (log, comm->etype, 1, msgtype, seqnum, buffer); + } } - if (log) { - print_message (log, comm->etype, 0, rxmsgtype, seqnum, rxpayload, rxlen); - } } } -- 2.30.2