]> rtime.felk.cvut.cz Git - rpp-test-sw.git/commitdiff
cantest syntax changed to be simpler and code cleaner.
authorMichal Horn <hornmich@fel.cvut.cz>
Thu, 1 Aug 2013 13:49:15 +0000 (15:49 +0200)
committerMichal Horn <hornmich@fel.cvut.cz>
Thu, 1 Aug 2013 13:49:15 +0000 (15:49 +0200)
New syntax cantest1 2

commands/cmd_can.c

index c292984c294ed9a1f3386510056a42a0c8ca229c..106debbdd10587d4ee392c8721a0cc8a6272917f 100644 (file)
@@ -98,7 +98,6 @@ int cmd_do_test_can_loopback(cmd_io_t *cmd_io, const struct cmd_des *des, char *
        uint32_t can_src, can_dst;
        canBASE_t *canBases[3] = {canREG1, canREG2, canREG3};
        uint32_t canMailBoxes[3] = {canMESSAGE_BOX1, canMESSAGE_BOX2, canMESSAGE_BOX3};
-       char* token = NULL;
        uint32_t txTimeOutCnt = 0;
        uint32_t rxTimeOutCnt = 0;
        uint32_t messagesTransmitted = 0;
@@ -106,6 +105,8 @@ int cmd_do_test_can_loopback(cmd_io_t *cmd_io, const struct cmd_des *des, char *
        uint32_t i;
        uint8_t tx_data[8] = {'T', 'E', 'S', 'T', ' ', 'C', 'A', 'N'};
        uint8_t rx_data[8] = {0, 0, 0, 0, 0, 0, 0, 0 };
+       char *p=param[1];
+       char spareParams;
 
 
        dmmREG->PC4 = (1<<(13)); // set CAN_NSTB
@@ -119,29 +120,11 @@ int cmd_do_test_can_loopback(cmd_io_t *cmd_io, const struct cmd_des *des, char *
        dmmREG->PC4 = (1<<(15)); // set CAN_EN
        vTaskDelay(50/portTICK_RATE_MS);
 
-       // Get can ID 1
-       if ((token = strtok(param[1], " ")) == NULL) {
 
-               rpp_sci_printf("ERROR: Parameter 1 expected.\n");
-               return 1;
-       }
-       if (EOF == sscanf(token, "%d", &can_src)){
-               rpp_sci_printf("ERROR: unsigned number expected as param 1!\n");
-               return 1;
-       }
-       // Get can ID 2
-       if ((token = strtok(NULL, " ")) == NULL) {
-               rpp_sci_printf("ERROR: Parameter 2 expected.\n");
-               return 1;
-       }
-       if (EOF == sscanf(token, "%d", &can_dst)){
-               rpp_sci_printf("ERROR: unsigned number expected as param 2!\n");
-               return 1;
-       }
-       if ((token = strtok(NULL, " ")) != NULL) {
-               rpp_sci_printf("ERROR: More than 2 parameters detected!\n");
-               return 1;
+       if (sscanf(p, "%d %d %1s", &can_src, &can_dst, &spareParams) != 2) {
+               return -CMDERR_BADPAR;
        }
+
        if (can_src == can_dst) {
                rpp_sci_printf("ERROR: Destination equals source!\n");
                return 1;
@@ -249,7 +232,7 @@ cmd_des_t const cmd_des_test_can_loopback={
     "\n"
     "=== Example ===\n"
     "\n"
-    "   --> cantest 1 2\n"
+    "   --> cantest1 2\n"
     "   Testing CAN loopback\n"
     "   Messages transmitted: 100/100\n"
     "   Messages received: 100/100\n"