fix generic parsing
authorMazet Laurent <laurent.mazet@thalesgroup.com>
Mon, 7 Apr 2025 16:14:05 +0000 (18:14 +0200)
committerMazet Laurent <laurent.mazet@thalesgroup.com>
Mon, 7 Apr 2025 16:14:05 +0000 (18:14 +0200)
clear_data.h
morep_valid.c
parse.h
raw_data.c
raw_data.h

index 50ccfda68d13298aeeea265119f4c999ff85aa83..795e9ec762e6458b8dc50146b523a13650bafeb5 100644 (file)
@@ -27,9 +27,9 @@ __BEGIN_DECLS
 */
 typedef struct {
     uint8_t channelid; /**< channel index */
-    uint8_t bypass_len; /**< attached bypass message length */
+    int bypass_len; /**< attached bypass message length */
     uint8_t bypass[255]; /**< attached bypass message */
-    uint8_t data_len; /**< data length (must be aligned to 16 bytes) */
+    int data_len; /**< data length (must be aligned to 16 bytes) */
     uint8_t data[1472]; /**< data message */
 } CLEAR_DATA_t;
 
index 674e3141903185d8e64a27bb7f2d943f1db237e8..8b24ee1c1609d8235e6a13906ff2961e1f0a5af2 100644 (file)
@@ -66,7 +66,6 @@ char *read_stream (FILE *sd, int *plen)
         memset (buffer + size - BUFMAX - 1, 0, BUFMAX + 1);
         blocklen = fread (buffer + size - BUFMAX - 1, 1, BUFMAX, sd);
         length += blocklen;
-        VERBOSE (morep, DEBUG, PRINTF ("buffer: 0x%p 0x%p %d %d %d\n", buffer, buffer + size - BUFMAX - 1, (int)size, length, blocklen));
     } while (blocklen > 0);
 
     /* check size */
@@ -287,13 +286,13 @@ int main (int argc, char **argv)
         VERBOSE (morep, DEBUG, PRINTF ("work with %c[%s]\n", comm->mode ? 'T' : 'R', comm->etype));
 
         /* get values */
-        char *tmp = line;
+        char *tmp = line + offset;
         TEST_CHARS (tmp, " \t", 0);
-        TEST_CHARS (tmp, " \t=", 1); 
         if (strncmp (tmp, "MSG", 3) != 0) {
-            VERBOSE (morep, WARNING, PRINTF ("can't parse line '%s'\n", line));
+            VERBOSE (morep, WARNING, PRINTF ("can't parse line '%s' (%s)\n", line, tmp));
             continue;
         }
+        tmp += 3;
         TEST_CHARS (tmp, " \t=", 0);
         uint8_t msgtype = strtol (tmp, &tmp, 0);
         if ((*tmp != ' ') && (*tmp != '\t')) {
@@ -306,6 +305,7 @@ int main (int argc, char **argv)
             VERBOSE (morep, WARNING, PRINTF ("can't parse line '%s'\n", line));
             continue;
         }
+        VERBOSE (morep, TRACE, PRINTF ("payload length: %d\n", payload.data_len));
 
         /* transmit */
         if (mode == 1) {
diff --git a/parse.h b/parse.h
index 4608c7fb9bf2697de7dfa662888ee5c16f68954f..f19037834e81a287e591dd321de6a87c62514c35 100644 (file)
--- a/parse.h
+++ b/parse.h
@@ -30,9 +30,9 @@ __BEGIN_DECLS
 
    @param str string to be parsed
    @param delim list of characters to test
-   @param test 0 for "contain only", 1 for "exclude"
+   @param stop 0 for "contain only", 1 for "exclude"
 */
-#define TEST_CHARS(str, delim, test)                      \
+#define TEST_CHARS(str, delim, stop)                      \
     while (*str != '\0') {                                \
         int i, stat = 0;                                  \
         for (i = 0; (delim[i] != '\0') && (!stat); i++) { \
@@ -40,7 +40,7 @@ __BEGIN_DECLS
                 stat = 1;                                 \
             }                                             \
         }                                                 \
-        if (stat == test) {                               \
+        if (stat == stop) {                               \
             break;                                        \
         }                                                 \
         str++;                                            \
@@ -56,7 +56,7 @@ __BEGIN_DECLS
 #define BEGIN_PARSE(line)                              \
 {                                                      \
     int rc = 0;                                        \
-    char *pt = (line);                                 \
+    char *pt = line;                                   \
     while (1) {                                        \
         /* find variable */                            \
         TEST_CHARS (pt, " \t", 0);                     \
@@ -65,6 +65,8 @@ __BEGIN_DECLS
         if (*var == '\0') {                            \
             break;                                     \
         }                                              \
+        *pt++ = '\0';                                  \
+        VERBOSE (morep, TRACE, PRINTF ("var: %s\n", var)); \
         TEST_CHARS (pt, " \t=", 0);                    \
         /* find value */                               \
         char *val = pt;                                \
@@ -74,6 +76,7 @@ __BEGIN_DECLS
             }                                          \
             pt++;                                      \
         }                                              \
+        VERBOSE (morep, TRACE, PRINTF ("val: %s\n", val)); \
         if (*val == '\0') {                            \
             rc = 1;                                    \
             break;                                     \
@@ -101,7 +104,7 @@ __BEGIN_DECLS
 
 #define PARSEA(name, buf) \
         else if (strcmp (var, name) == 0) {                      \
-                buf##_len = parse_array (val, buf, sizeof (buf)); \
+            buf##_len = parse_array (val, buf, sizeof (buf)); \
         }
 
 /**
@@ -109,14 +112,14 @@ __BEGIN_DECLS
 
    End of parsing macro
 */
-#define END_PARSE()                                                          \
-        else {                                                               \
-            VERBOSE (morep, WARNING, PRINTF ("can understand '%s'\n", var)); \
-            rc = 1;                                                          \
-            break;                                                           \
-        }                                                                    \
-    }                                                                        \
-    return rc;                                                               \
+#define END_PARSE()                                                            \
+        else {                                                                 \
+            VERBOSE (morep, WARNING, PRINTF ("can't understand '%s'\n", var)); \
+            rc = 1;                                                            \
+            break;                                                             \
+        }                                                                      \
+    }                                                                          \
+    return rc;                                                                 \
 }
 
 /**
index ee27ec3800b43bc13b4e3afdb4d7306d48a63a35..00cc787d607f178eb5447e278af4d167f899d416 100644 (file)
@@ -22,6 +22,7 @@ int parse_raw_data (char *line, RAW_DATA_t *out)
 {
     BEGIN_PARSE (line)
     PARSEA ("DATA", out->data)
+    PARSEA ("PAYLOAD", out->data)
     END_PARSE ()
 }
 
index c261cad6c00e7527d9ce92ce968ead92798d0716..e4dc47690e3489109efb0fae2999e888576fc654 100644 (file)
@@ -26,8 +26,8 @@ __BEGIN_DECLS
    Raw data type
 */
 typedef struct {
-    uint8_t data_len; /**< data length*/
-    uint8_t data[1496 * 16 - 1]; /**< data message */
+    int data_len; /**< data length*/
+    uint8_t data[1496]; /**< data message */
 } RAW_DATA_t;
 
 /**