From a38ac0e624e0f9e124d10e7555a4c4cf98cf4206 Mon Sep 17 00:00:00 2001 From: Mazet Laurent Date: Thu, 27 Mar 2025 22:49:06 +0100 Subject: [PATCH] working on localloop --- morep_valid.c | 25 ++++++++++++++++--------- script-lo.eth | 12 ++++++++++++ script.eth | 14 ++++++++------ 3 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 script-lo.eth diff --git a/morep_valid.c b/morep_valid.c index 409e9cb..54fe897 100644 --- a/morep_valid.c +++ b/morep_valid.c @@ -81,12 +81,17 @@ char *readstream (FILE *sd, int *length) int parse_line (char *line, uint8_t *msgtype, uint8_t **payload) { + int rc = -1; + *msgtype = -1; + + while ((*line == ' ') || (*line == '\t')) { + line++; + } + char *delim = " =\t"; char *str = strdup (line); char *save_ptr; char *pt = str; - int rc = -1; - *msgtype = -1; while (1) { char *var = strtok_r (pt, delim, &save_ptr); pt = NULL; @@ -95,7 +100,7 @@ int parse_line (char *line, uint8_t *msgtype, uint8_t **payload) if (!var) break; if (0) { - } else if (strcmp ("MSGTYPE", var) == 0) { + } else if (strcmp ("MSG", var) == 0) { *msgtype = strtol (val, NULL, 0); if (rc < 0 ) { rc = 0; @@ -127,11 +132,11 @@ int parse_line (char *line, uint8_t *msgtype, uint8_t **payload) *buf++ = strtol (digit, NULL, 16); } } else { - VERBOSE (morep, WARNING, PRINTF ("can't parse payload in '%s'\n", line)); + VERBOSE (morep, WARNING, PRINTF ("can't parse payload '%s'\n", val)); break; } } else { - VERBOSE (morep, WARNING, PRINTF ("can't parse line '%s'\n", line)); + VERBOSE (morep, WARNING, PRINTF ("unknown word '%s'\n", var)); break; } } @@ -201,7 +206,7 @@ int main (int argc, char **argv) break; case 'h': default: - printf ("usage: %s [-h] [-r url] [-t url] [-v level]\n", progname); + printf ("usage: %s [-h] [-r url] [-t url] [-v level] [file]\n", progname); return (c != 'h'); } @@ -278,8 +283,9 @@ int main (int argc, char **argv) mode = 0; } else if (*pt == 'T') { mode = 1; - } else if (strcmp (pt, "SLEEP") == 0) { + } else if (strncmp (pt, "SLEEP", 5) == 0) { int duration = atoi (pt + 5); + VERBOSE (morep, INFO, PRINTF ("sleep %dms\n", duration)); usleep (duration * 1000); continue; } @@ -293,8 +299,10 @@ int main (int argc, char **argv) comm_t *comm = NULL; for (i = 0; i < nbcomms; i++) { comm_t *c = comm_list + i; + VERBOSE (morep, DEBUG, PRINTF ("test %c[%s]\n", c->mode ? 'T' : 'R', c->etype)); if ((strncmp (pt, c->etype, strlen (c->etype)) == 0) && (c->mode == mode)) { comm = c; + pt += strlen (c->etype); break; } } @@ -318,7 +326,7 @@ int main (int argc, char **argv) VERBOSE (morep, INFO, PRINTF ("S%s seqnum %d\n", comm->etype, seqnum)); } else { /* receive */ uint8_t rxmsgtype = 0; - uint8_t *rxpayload = NULL; + uint8_t rxpayload[1496 * 16 - 1] = {0}; int rxlen = 0; int seqnum = MOREP_Receive (comm->morep, &rxmsgtype, rxpayload, &rxlen); if (rxmsgtype != msgtype) { @@ -335,7 +343,6 @@ int main (int argc, char **argv) VERBOSE (morep, INFO, PRINTF ("R%04x seqnum %d\n", rxmsgtype, seqnum)); } } - free (rxpayload); } free (payload); } diff --git a/script-lo.eth b/script-lo.eth new file mode 100644 index 0000000..87df396 --- /dev/null +++ b/script-lo.eth @@ -0,0 +1,12 @@ +# Test script + +T0808 MSG=42 PAYLOAD="Hello_world" +R0808 MSG=42 PAYLOAD="Hello_world" + +SLEEP 1000 + +T0808 MSG=24 PAYLOAD=42796520776f726c64 +R0808 MSG=24 PAYLOAD=42796520776f726c64 + +T0808 MSG=10 PAYLOAD=@makefile +R0808 MSG=10 PAYLOAD=@makefile diff --git a/script.eth b/script.eth index e13499f..a358ada 100644 --- a/script.eth +++ b/script.eth @@ -1,10 +1,12 @@ # Test script -TX[0808] MSG=42 PAYLOAD="Hello world" -RX[0808] MSG=43 PAYLOAD="Bye" +T0808 MSG=42 PAYLOAD="Hello_world" +R0808 MSG=43 PAYLOAD="Bye" -TX[0808] MSG=24 PAYLOAD=42796520776f726c64 -RX[0808] MSG=25 PAYLOAD=48656c6c6f +SLEEP 1000 -TX[0808] MSG=10 PAYLOAD=@makefile -RX[0808] MSG=11 PAYLOAD="OK" +T0808 MSG=24 PAYLOAD=42796520776f726c64 +R0808 MSG=25 PAYLOAD=48656c6c6f + +T0808 MSG=10 PAYLOAD=@makefile +R0808 MSG=11 PAYLOAD="OK" -- 2.30.2