]> rtime.felk.cvut.cz Git - rpp-test-sw.git/blobdiff - rpp-test-sw/commands/cmd_hout.c
Change license to MIT
[rpp-test-sw.git] / rpp-test-sw / commands / cmd_hout.c
index be5bf4bdb65efd849f7e086691f526dd58237809..280e2cf61f54ef3e6ad149248ade07acadf8713d 100644 (file)
@@ -1,15 +1,31 @@
 /*
- * Copyright (C) 2012-2013, 2015 Czech Technical University in Prague
+ * Copyright (C) 2012-2013, 2015, 2016 Czech Technical University in Prague
  *
  * Created on: 28.2.2013
  *
  * Authors:
  *     - Michal Horn
  *
- * This document contains proprietary information belonging to Czech
- * Technical University in Prague. Passing on and copying of this
- * document, and communication of its contents is not permitted
- * without prior written authorization.
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
  *
  * File : cmd_hout.c
  *
@@ -42,9 +58,10 @@ int cmd_do_read_hout_ifbk_values(cmd_io_t *cmd_io, const struct cmd_des *des, ch
 {
        uint32_t i;
        const struct port_desc *port = &port_desc[PORT_ID_HOUTIFBK];
-       uint16_t values[port->numchn];
+       uint16_t values[6];
        int ret;
 
+       assert(ARRAY_SIZE(values) == port->numchn);
 
        ret = port->get(port, values, sizeof(values));
        if (ret < 0)
@@ -68,9 +85,9 @@ int cmd_do_test_hout_fault(cmd_io_t *cmd_io, const struct cmd_des *des, char *pa
 {
        int pin;
        char *p = param[1];
-       char spareParams;
+       char spareParams[2];
 
-       if (sscanf(p, "%d %1s", &pin, &spareParams) != 1)
+       if (sscanf(p, "%d %1s", &pin, spareParams) != 1)
                return -CMDERR_BADPAR;
        pin--;
        if (pin < 0 || pin > 5) return -CMDERR_BADPAR;
@@ -105,7 +122,7 @@ int cmd_do_hout_pwm(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
 {
        char *p;
        uint32_t values[MAX_PARAM_VALUES_NUM];
-       char spareParams;
+       char spareParams[2];
        int pin;
 
        p = param[1];
@@ -116,7 +133,7 @@ int cmd_do_hout_pwm(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
 
        if (param[2] != NULL) {     // More parameters = set values
                p = param[2];
-               if (sscanf(p, "%d %d %1s", &values[0], &values[1], &spareParams) != 2)
+               if (sscanf(p, "%d %d %1s", &values[0], &values[1], spareParams) != 2)
                        return -CMDERR_BADPAR;
                if (values[1] > 100) return -CMDERR_BADPAR;
                hout_pwm_set_signal(pin, (double)values[0], values[1]);
@@ -126,7 +143,7 @@ int cmd_do_hout_pwm(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
                double period = hout_pwm_get_period(pin);
                uint32_t duty = hout_pwm_get_duty(pin);
 
-               rpp_sci_printf("houtpwm%d_period=%g\r\nhoutpwm%d_duty=%u%%", pin+1, period, pin+1, duty);
+               rpp_sci_printf("houtpwm%d_period=%g\r\nhoutpwm%d_duty=%u%%\n", pin+1, period, pin+1, duty);
                return 0;
        }
 }
@@ -143,9 +160,9 @@ int cmd_do_hout_pwm_start(cmd_io_t *cmd_io, const struct cmd_des *des, char *par
 {
        int pin;
        char *p = param[1];
-       char spareParams;
+       char spareParams[2];
 
-       if (sscanf(p, "%d %1s", &pin, &spareParams) != 1)
+       if (sscanf(p, "%d %1s", &pin, spareParams) != 1)
                return -CMDERR_BADPAR;
        pin--;
        if (pin < 0 || pin > 5) return -CMDERR_BADPAR;
@@ -170,9 +187,9 @@ int cmd_do_hout_pwm_stop(cmd_io_t *cmd_io, const struct cmd_des *des, char *para
 {
        int pin;
        char *p = param[1];
-       char spareParams;
+       char spareParams[2];
 
-       if (sscanf(p, "%d %1s", &pin, &spareParams) != 1)
+       if (sscanf(p, "%d %1s", &pin, spareParams) != 1)
                return -CMDERR_BADPAR;
        pin--;
        if (pin < 0 || pin > 5) return -CMDERR_BADPAR;
@@ -270,7 +287,7 @@ cmd_des_t const cmd_des_hout_pwm = {
        "\n"
        "    --> houtpwm1\n"
        "    houtpwm1_period=1000\n"
-       "    houtpwm1_duty=25\n"
+       "    houtpwm1_duty=25%\n"
        "\n"
        "Prints the actual period of HOUT1 PWM in microseconds and the duty\n"
        "cycle in percents.\n",