working on localloop
authorMazet Laurent <laurent.mazet@thalesgroup.com>
Thu, 27 Mar 2025 21:49:06 +0000 (22:49 +0100)
committerMazet Laurent <laurent.mazet@thalesgroup.com>
Thu, 27 Mar 2025 21:49:06 +0000 (22:49 +0100)
morep_valid.c
script-lo.eth [new file with mode: 0644]
script.eth

index 409e9cb26411e30ee2396810b9412ad0d6797ca3..54fe897e9fbf888513596991ca150250d35ae469 100644 (file)
@@ -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 (file)
index 0000000..87df396
--- /dev/null
@@ -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
index e13499f06c0f6d4ce6cfb5c19eacf544806e4ddc..a358ada6b348ec218b20e87773c254ba474a6d73 100644 (file)
@@ -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"