DECLARE_VERBOSE_LEVEL (morep, INFO);
-#define MODERAW
-
#define BUFMAX 4096
void sig_handler (int sig)
/* get values */
char *tmp = line + offset;
uint8_t msgtype;
-#ifdef MODERAW
- PAYLOAD_t payload= {0};
- if (parse_payload (tmp, &payload) != 0) {
- VERBOSE (morep, WARNING, PRINTF ("can't parse line '%s'\n", line));
- continue;
- }
- msgtype = payload.msgtype;
-#else /* ! MODERAW */
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'\n", line));
continue;
}
-#endif /* MODERAW */
VERBOSE (morep, TRACE, PRINTF ("payload length: %d\n", payload.data_len));
/* transmit */
/* check msg type */
if (rxmsgtype != msgtype) {
- VERBOSE (morep, WARNING, PRINTF ("R%04x SEQ=%d MSG=%d: expected msgtype %04x\n", rxmsgtype, seqnum, rxmsgtype, msgtype));
+ VERBOSE (morep, WARNING, PRINTF ("R%sx SEQ=%d MSG=%d: expected msgtype %d\n", comm->etype, seqnum, rxmsgtype, msgtype));
}
/* check payload */
- else {
- int ok = (rxlen == payload.data_len);
- i = -1;
- for (i = 0; ok && (i < rxlen); i++) {
- ok = (rxpayload[i] == payload.data[i]);
- }
- if (!ok) {
- VERBOSE (morep, WARNING, PRINTF ("R%04x SEQ=%d MSG=%d: payloads differed at %d/%d\n", rxmsgtype, seqnum, rxmsgtype, i, rxlen));
- }
+ else if ((rxlen != payload.data_len) ||
+ ((memcmp (rxpayload, payload.data, rxlen) != 0))) {
+ VERBOSE (morep, WARNING, PRINTF ("R%s SEQ=%d MSG=%d: payloads differed %d/%d\n", comm->etype, seqnum, rxmsgtype, payload.data_len, rxlen));
}
if (log) {
-#ifdef MODERAW
- char buffer[64 + sizeof (payload.data)] = {0};
- PAYLOAD_t _rxpayload;
- _rxpayload.msgtype = rxmsgtype;
- _rxpayload.data_len = rxlen;
- memcpy (_rxpayload.data, rxpayload, rxlen);
- format_payload (&_rxpayload, buffer, sizeof (buffer));
- fprintf (log, "R%s %s\n", comm->etype, buffer);
-#else /* ! MODERAW */
print_message (log, comm->etype, 0, rxmsgtype, seqnum, rxpayload, rxlen);
-#endif /* MODERAW */
}
}
}
+++ /dev/null
-/*
- File name : payload.c
- Projet : MERLIN
- Date of creation : 2025/04/07
- Version : 1.0
- Copyright : Thales SIX
- Author : Laurent Mazet <laurent.mazet@thalesgroup.com>
-
- Description : This file contains definition of a raw payloaddata type
-
- History :
- - initial version
-*/
-
-#include <stdint.h>
-
-#include "parse.h"
-
-#include "payload.h"
-
-int parse_payload (char *line, PAYLOAD_t *out)
-{
- BEGIN_PARSE (line)
- PARSE_INT ("MSG", out->msgtype)
- PARSE_ARRAY ("PAYLOAD", out->data)
- END_PARSE ()
-}
-
-int format_payload (PAYLOAD_t *in, char *buffer, int maxlen)
-{
- BEGIN_FORMAT (buffer, maxlen)
- FORMAT_INT ("MSG", in->msgtype)
- FORMAT_ARRAY ("PAYLOAD", in->data)
- END_FORMAT ()
-}
-
-int serial_payload (PAYLOAD_t *in, uint8_t *buffer, int maxlen)
-{
- BEGIN_SERIAL (buffer, maxlen)
- SERIAL_INT (in->msgtype)
- SERIAL_ARRAY (in->data)
- END_SERIAL ()
-}
-
-/* vim: set ts=4 sw=4 si et: */
+++ /dev/null
-/*
- File name : payload.h
- Projet : MERLIN
- Date of creation : 2025/04/07
- Version : 1.0
- Copyright : Thales SIX
- Author : Laurent Mazet <laurent.mazet@thalesgroup.com>
-
- Description : This file contains definition of a raw paylad
-
- History :
- - initial version
-*/
-
-#ifndef __PAYLOAD_H__
-#define __PAYLOAD_H__
-
-#include <stdint.h>
-#include <sys/cdefs.h>
-
-__BEGIN_DECLS
-
-/**
- @ingroup MESSAGES
-
- Raw data type
-*/
-typedef struct {
- uint8_t msgtype; /**< message type */
- int data_len; /**< data length*/
- uint8_t data[1496]; /**< data message */
-} PAYLOAD_t;
-
-/**
- @ingroup MESSAGES
-
- Parse a string containing a raw payload
-
- @param line string to analyse
- @param out output structure
-*/
-int parse_payload (char *line, PAYLOAD_t *out);
-
-/**
- @ingroup MESSAGES
-
- Format payload into a string
-
- @param in input structure
- @param buffer output string
- @param maxlen buffer limit
-*/
-int format_payload (PAYLOAD_t *in, char *buffer, int maxlen);
-
-/**
- @ingroup MESSAGES
-
- Serialize payload into a network stream
-
- @param in input structure
- @param buffer network stream
- @param maxlen buffer limit
-*/
-int serial_payload (PAYLOAD_t *in, uint8_t *buffer, int maxlen);
-
-__END_DECLS
-
-#endif /* __PAYLOAD_H__ */
-
-/* vim: set ts=4 sw=4 si et: */
# Test script
-T0808 MSG=42 PAYLOAD="Hello_world"
-R0808 MSG=42 PAYLOAD="Hello_world"
+T0808 MSG=42 DATA="Hello_world"
+R0808 MSG=42 DATA="Hello_world"
SLEEP 1000
-T0808 MSG=24 PAYLOAD=42796520776f726c64
-R0808 MSG=24 PAYLOAD=42796520776f726c64
+T0808 MSG=24 DATA=42796520776f726c64
+R0808 MSG=24 DATA=42796520776f726c64
-T0808 MSG=10 PAYLOAD=@makefile
-R0808 MSG=10 PAYLOAD=@makefile
+T0808 MSG=10 DATA=@makefile
+R0808 MSG=10 DATA=@makefile
# Test script
-R0808 MSG=42 PAYLOAD="Hello_world"
-T0809 MSG=43 PAYLOAD="Bye"
+R0808 MSG=42 DATA="Hello_world"
+T0809 MSG=43 DATA="Bye"
SLEEP 1000
-R0808 MSG=24 PAYLOAD=42796520776f726c64
-T0809 MSG=25 PAYLOAD=48656c6c6f
+R0808 MSG=24 DATA=42796520776f726c64
+T0809 MSG=25 DATA=48656c6c6f
-R0808 MSG=10 PAYLOAD=@makefile
-T0809 MSG=11 PAYLOAD="OK"
+R0808 MSG=10 DATA=@makefile
+T0809 MSG=11 DATA="OK"
# Test script
-T0808 MSG=42 PAYLOAD="Hello_world"
-R0809 MSG=43 PAYLOAD="Bye"
+T0808 MSG=42 DATA="Hello_world"
+R0809 MSG=43 DATA="Bye"
SLEEP 1000
-T0808 MSG=24 PAYLOAD=42796520776f726c64
-R0809 MSG=25 PAYLOAD=48656c6c6f
+T0808 MSG=24 DATA=42796520776f726c64
+R0809 MSG=25 DATA=48656c6c6f
-T0808 MSG=10 PAYLOAD=@makefile
-R0809 MSG=11 PAYLOAD="OK"
+T0808 MSG=10 DATA=@makefile
+R0809 MSG=11 DATA="OK"