From 3d630e1b742d99b557e3408ef473729cd70c69eb Mon Sep 17 00:00:00 2001 From: Mazet Laurent Date: Wed, 7 May 2025 15:12:53 +0200 Subject: [PATCH] correct simulator --- morep_simulator.c | 14 +++++++------- simulator/script-simulator.sh | 3 +++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/morep_simulator.c b/morep_simulator.c index d6c4343..fa9eabd 100644 --- a/morep_simulator.c +++ b/morep_simulator.c @@ -264,7 +264,7 @@ int main (int argc, char **argv) for (int i = 0; (service_list + i)->service_id != noserv_e; i++) { service_t *s = service_list + i; if (s && servname && (strcmp (s->name, servname) == 0)) { - memcpy (mode ? &(s->rx) : &(s->tx), comm_list + nbcomms, sizeof (comm_t)); + memcpy ((mode == 0) ? &(s->rx) : &(s->tx), comm_list + nbcomms, sizeof (comm_t)); break; } } @@ -367,7 +367,7 @@ int main (int argc, char **argv) service_t *s = service_list + i; VERBOSE (simul, TRACE, PRINTF ("test %c[%s]\n", *line, s->name)); if (strncmp (line + offset, s->name, strlen (s->name)) == 0) { - comm = mode ? &(s->rx) : &(s->tx); + comm = (mode == 0) ? &(s->rx) : &(s->tx); serv = s; offset += strlen (s->name); } @@ -375,12 +375,12 @@ int main (int argc, char **argv) /* find MOREP by ethertype */ for (int j = 0; (j < nbcomms) && (comm == NULL); j++) { comm_t *c = comm_list + j; - VERBOSE (simul, TRACE, PRINTF ("test %c[%s]\n", c->mode ? 'T' : 'R', c->etype)); + VERBOSE (simul, TRACE, PRINTF ("test %c[%s]\n", (c->mode == 0) ? 'R' : 'T', c->etype)); if ((strncmp (line + offset, c->etype, strlen (c->etype)) == 0) && (c->mode == mode)) { comm = c; for (int i = 0; ((service_list + i)->service_id != noserv_e) && (serv == NULL); i++) { service_t *s = service_list + i; - c = mode ? &(s->rx) : &(s->tx); + c = (mode == 0) ? &(s->rx) : &(s->tx); if (strncmp (c->etype, comm->etype, strlen (comm->etype)) == 0) { serv = s; } @@ -393,7 +393,7 @@ int main (int argc, char **argv) VERBOSE (simul, TRACE, PRINTF ("no morep found '%s'\n", line)); continue; } - VERBOSE (simul, DEBUG, PRINTF ("select %c[%s]\n", comm->mode ? 'T' : 'R', serv->name)); + VERBOSE (simul, DEBUG, PRINTF ("select %c[%s]\n", (comm->mode == 0) ? 'R' : 'T', serv->name)); /* skip space */ tmp = line + offset; @@ -444,7 +444,7 @@ int main (int argc, char **argv) VERBOSE (simul, WARNING, PRINTF ("message %s is not allowed for service %s (line '%s')\n", msg->name, serv->name, line)); continue; } - VERBOSE (simul, DEBUG, PRINTF ("%s message %s\n", comm->mode ? "sending" : "waiting", msg->name)); + VERBOSE (simul, DEBUG, PRINTF ("%s message %s\n", (comm->mode == 0) ? "waiting" : "sending", msg->name)); CHANNEL_t pdu_channel = {0}; CLEAR_DATA_t pdu_clear_data = {0}; @@ -613,7 +613,7 @@ int main (int argc, char **argv) /* log message */ if (log) { - fprintf (log, "%c:%s[%s] [SEG=%d MSG=%d LEN=%d PDU=%d] %s", mode ? 'T' : 'R', + fprintf (log, "%c:%s[%s] [SEG=%d MSG=%d LEN=%d PDU=%d] %s", (mode == 0) ? 'R' : 'T', serv->name, comm->etype, seqnum, msg->msgtype, len, pdu, msg->name); char buffer[MOREP_PAYLOAD * 3 + 256] = {0}; switch (pdu) { diff --git a/simulator/script-simulator.sh b/simulator/script-simulator.sh index 28c5895..b8ede40 100755 --- a/simulator/script-simulator.sh +++ b/simulator/script-simulator.sh @@ -9,6 +9,7 @@ ETH_RADIOBLACK=enp0s4://52:54:00:12:34:57 case "$1" in red) + #gdb $SIMULATOR --args \ $SIMULATOR -l script-red.log \ -s BYPASS -t $ETH_SECRED/080D -r $ETH_RADIORED/080D \ -s CONTROL -t $ETH_SECRED/080E -r $ETH_RADIORED/080E \ @@ -17,6 +18,7 @@ red) script-red.eth -v 3 -V 3 ;; secu) + #gdb $SIMULATOR --args \ $SIMULATOR -l script-secu.log \ -s BYPASS_BLACK -t $ETH_RADIOBLACK/081D -r $ETH_SECBLACK/081D \ -s BYPASS_RED -t $ETH_RADIORED/080D -r $ETH_SECRED/080D \ @@ -27,6 +29,7 @@ secu) script-secu.eth -v 3 -V 3 ;; black) + #gdb $SIMULATOR --args \ $SIMULATOR -l script-black.log \ -s BYPASS -t $ETH_SECBLACK/081D -r $ETH_RADIOBLACK/081D \ -s CROSS_CRYPTO -t $ETH_SECBLACK/0819 -r $ETH_RADIOBLACK/0819 \ -- 2.30.2