]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/commitdiff
Portval command syntax changed to avoid characters :, ?, ( and )
authorMichal Horn <hornmich@fel.cvut.cz>
Thu, 1 Aug 2013 13:54:50 +0000 (15:54 +0200)
committerMichal Horn <hornmich@fel.cvut.cz>
Thu, 1 Aug 2013 13:54:50 +0000 (15:54 +0200)
commands/cmd_port.c

index 25cb249aed9adc82beb932cc550c7266e2941669..ca09b96c58821ca7233fe5d50b3a5ce438e348a6 100644 (file)
@@ -28,6 +28,7 @@
  */
 
 #include "cmd_port.h"
+#include "stdio.h"
 
 #ifndef DOCGEN
 
@@ -69,40 +70,52 @@ int cmd_do_port_list(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
  */
 int cmd_do_port_val(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
   char *p;
-  int opchar;
   int i;
   port_desc_t* desc;
   uint32_t ret;
   uint32_t values[MAX_PARAM_VALUES_NUM];
+  uint32_t val;
+  char portName[32];
+  char spareParams;
+  uint32_t numParams;
+
+  p = param[1];
+  if (sscanf(p, "%31s ", portName) != 1) {
+         return -CMDERR_BADPAR;
+  }
 
-  if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
-
-  if((desc = hal_port_get_dsc(param[1], param[2]-param[1]))==NULL) return -CMDERR_BADREG;
+  if((desc = hal_port_get_dsc(portName, -1))==NULL) return -CMDERR_BADREG;
 
-  if(opchar==':'){
-       p=param[3];
-       si_skspace(&p);
-       i = read_arg(&p, values, MAX_PARAM_VALUES_NUM, 16);
-       if (i < 0)
-               return i;
+  if(param[2] != NULL){                // More parameters = set values
+       p=param[2];
        if (desc->port_setfnc_ptr == NULL) {
                return -CMDERR_WRPERM;
        }
        else {
                if (desc->interfaceType == PORT_INTERFACE_GPIO) {
-                       if (i != desc->numValues/8+1)   // Information about pin values are encoded as hexadecimal 8b value
-                               return -CMDERR_BADPAR;
+                       // Information about pin values are encoded as hexadecimal 8b value
+                       numParams = desc->numValues/8+1;
                }
                else if (desc->interfaceType == PORT_INTERFACE_SPI) {
-                       if (i != desc->numValues)       // Commands are passed as bytes
-                               return -CMDERR_BADPAR;
+                       // Commands are passed as bytes
+                       numParams = desc->numValues;
                }
                else if (desc->interfaceType == PORT_INTERFACE_ADC) {
                        return -CMDERR_BADPAR;  // ADC is read only and no other port is supported
                }
-               if (desc->port_setfnc_ptr != NULL) {
-                       ret = desc->port_setfnc_ptr(desc->config, desc->numValues, values);
+               /* Read the parameter
+                * At the end test if no more parameters are left.
+                */
+               if (sscanf(p, " %x %1s", &val, &spareParams) != 1) {
+                       return -CMDERR_BADPAR;
                }
+               /* Divide the parameter into bytes, which is the format requested
+                * by the set function.
+                */
+               for (i = 0; i < numParams; i++) {
+                       values[i] = ((val << (4-numParams+i)*8) & 0xFF000000) >> 3*8; // Left byte is the least significant
+               }
+               ret = desc->port_setfnc_ptr(desc->config, desc->numValues, values);
        }
        return cmd_opchar_replong(cmd_io, param, ret, 0, 16);
   }
@@ -116,7 +129,8 @@ int cmd_do_port_val(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
                                rpp_sci_printf("%d\r\n", values[i]);
                        }
          }
-         return cmd_opchar_replong(cmd_io, param, ret, 0, 16);
+               rpp_sci_printf("portval%s=%x", portName, ret);
+               return 0;
   }
 }
 
@@ -124,16 +138,15 @@ int cmd_do_port_val(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
 
 /** Command descriptor for read values from port command */
 cmd_des_t const cmd_des_port_val={
-    0, CDESM_OPCHR|CDESM_RW,
+    0, 0,
     "portval*","Read or write values from or to the port",
     "=== Command syntax ===\n"
     "\n"
-    "   portval<NAME>:(<VAL>)\n"
+    "   portval<NAME> <VAL>\n"
+    "   portval<NAME>\n"
     "where\n"
     "* <NAME> is a string specifying the name of the port\n"
-    "* : means set <VAL> on the port <NAME>\n"
-    "* ? means get a value from the port <NAME>\n"
-    "* <VAL> is a hexadecimal number in range 00 - FF\n"
+    "* <VAL> is a hexadecimal number in range 00 - FFFFFFFF\n"
     "\n"
     "=== Description ===\n"
     "\n"
@@ -161,9 +174,9 @@ cmd_des_t const cmd_des_port_val={
     "\n"
     "=== Example ===\n"
     "\n"
-    "   --> portvalMOUTIN:(3A)\n"
+    "   --> portvalMOUTIN 3A\n"
     "   portvalMOUTIN=0\n"
-    "   --> portvalMOUTIN?\n"
+    "   --> portvalMOUTIN\n"
     "   0\n"
     "   1\n"
     "   0\n"