]> rtime.felk.cvut.cz Git - rpp-test-sw.git/blobdiff - rpp-test-sw/commands/cmd_hout.c
hout: Do not use variably sized local array
[rpp-test-sw.git] / rpp-test-sw / commands / cmd_hout.c
index fa08f0190167176e23327b25f48e338bf7d99e13..9a37e9d02f4cb71a3cd941e4f90be65774f52f2d 100644 (file)
@@ -1,23 +1,15 @@
 /*
- * Copyright (C) 2012-2013 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 program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * 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.
  *
  * File : cmd_hout.c
  *
@@ -32,8 +24,9 @@
 #ifndef DOCGEN
 
 #include "rpp/rpp.h"
-#include "hal/hal.h"
-#include "drv/drv.h"
+/* FIXME: remove hout.h */
+#include "drv/hout.h"
+#include "drv/port.h"                  /* TODO: Use rpp/port.h */
 #include "cmdproc_utils.h"
 
 
  */
 int cmd_do_read_hout_ifbk_values(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
 {
-       uint32_t i;                     // Cycle control variable
-       port_desc_t *desc;
-       uint32_t values[PORT_HOUTIFBK_CHANNEL_NUM*2];
+       uint32_t i;
+       const struct port_desc *port = &port_desc[PORT_ID_HOUTIFBK];
+       uint16_t values[6];
        int ret;
 
-       desc = hal_port_get_dsc(PORT_NAME_HOUTIFBK, -1);
+       assert(ARRAY_SIZE(values) == port->numchn);
 
-       ret = desc->port_getfnc_ptr(desc->config, PORT_HOUTIFBK_CHANNEL_NUM, values);
+       ret = port->get(port, values, sizeof(values));
        if (ret < 0)
                return ret;
 
-       for (i = 0; i < PORT_HOUTIFBK_CHANNEL_NUM; i++) {
+       for (i = 0; i < port->numchn; i++) {
                rpp_sci_printf("HOUT%d: %d\n", i+1, values[i]);
        }
        return 0;
@@ -76,9 +69,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;
@@ -113,7 +106,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];
@@ -124,7 +117,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]);
@@ -134,7 +127,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;
        }
 }
@@ -151,9 +144,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;
@@ -178,9 +171,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;
@@ -278,7 +271,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",