Commit d054f3f1 authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Add uint32 command

Small pwm fix
(added t_off)
vesp fixes, communication seems to be buggy
parent 1c278e70
/*
Copyright Jeroen Vreeken (jeroen@vreken.net), 2015
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 3 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/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <log/log.h>
#include <controller/controller_block.h>
#include <controller/controller_command.h>
struct controller_block_private {
uint32_t value;
uint32_t id;
struct controller_command *command;
};
static void command_calculate(struct controller_block *cmd)
{
struct controller_block_private *priv = cmd->private;
struct controller_command_entry c_entry;
if (!controller_command_queue_read(priv->command, &c_entry)) {
priv->value = c_entry.value.u32;
priv->id = c_entry.id;
} else {
priv->id = COMMAND_ID_NONE;
}
}
static struct controller_block_outterm_list outterms[] = {
{ "value", CONTROLLER_BLOCK_TERM_UINT32, offsetof(struct controller_block_private, value) },
{ "id", CONTROLLER_BLOCK_TERM_UINT32, offsetof(struct controller_block_private, id) },
{ NULL },
};
static struct controller_block * block_command_uint32_create(char *name, int argc, va_list val)
{
struct controller_block *cmd;
char *cmd_name = name;
char *cmd_unit = "uint32";
if (argc >= 1)
cmd_name = va_arg(val, char *);
if (argc >= 2)
cmd_unit = va_arg(val, char *);
if (!(cmd = controller_block_alloc("command_uint32", name, sizeof(struct controller_block_private))))
return NULL;
cmd->private->value = false;
cmd->private->id = COMMAND_ID_NONE;
if (controller_block_outterm_list_init(cmd, outterms))
goto err_block;
cmd->calculate = command_calculate;
if (controller_block_add(cmd))
goto err_block;
cmd->private->command = controller_command_create(cmd, cmd_name, cmd_unit);
cmd->private->command->value_type = COMMAND_VALUE_TYPE_UINT32;
cmd->private->command->command_types[0] = COMMAND_PTYPE_SETPOINT;
return cmd;
err_block:
controller_block_free(cmd);
return NULL;
}
BLOCK_CREATE(command_uint32) = {
.create = block_command_uint32_create,
.args = { "", "char*", "char*,char*", NULL },
};
trigger {
{ "immediate" }
}
blocks (10.0, 0.0) {
{ "command_uint32", "command_uint32" }
{ "command_uint32", "command_uint32_named", "aname" }
{ "command_uint32", "command_uint32_named_unit", "anothername", "aunit" }
{ "test_output_uint32", "value" }
{ "test_output_uint32", "id" }
{ "test_command", "command" }
}
links {
{ "command_uint32", "value", "value", "value", true }
{ "command_uint32", "id", "id", "value", true }
}
set SETPOINT 4
set SPEED 5
set SETPOINT_TIME 6
set COMMAND_ID_NONE (int)0xffffffff
params {
{ "command", "command", "command_uint32", $[SETPOINT_TIME], 123, 1, 0, 500000000 }
{ "command", "command", "command_uint32", $[SETPOINT], 234, 2 }
{ "command", "command", "command_uint32", $[SETPOINT], 567, -1 }
{ "command", "command", "command_uint32", $[SETPOINT], 666, 0 }
{ "command", "command", "command_uint32", $[SETPOINT], 777, -10 }
{ "command", "command", "aname", $[SETPOINT], 1888, 1234 }
{ "command", "command", "anothername", $[SETPOINT], 2888, 2468 }
{ "value", "value", 10,
(int) { 0, 1, 2, -1, 0, -10, -10, -10, -10, -10 }
}
{ "id", "value", 10,
(int) { $[COMMAND_ID_NONE], 123, 234, 567, 666, 777, $[COMMAND_ID_NONE], $[COMMAND_ID_NONE], $[COMMAND_ID_NONE], $[COMMAND_ID_NONE] }
}
}
......@@ -9,6 +9,7 @@ BLOCKS := \
bridge_pwm \
command_bool \
command_float \
command_uint32 \
controller_profile \
counter \
debug \
......@@ -101,6 +102,7 @@ CTRL_TESTS += \
$(DIR)/block_bridge_pwm.test.output \
$(DIR)/block_command_bool.test.output \
$(DIR)/block_command_float.test.output \
$(DIR)/block_command_uint32.test.output \
$(DIR)/block_gain.test.output \
$(DIR)/block_gain_ratio_abs.test.output \
$(DIR)/block_i2t.test.output \
......
......@@ -117,6 +117,9 @@ static int param_set(struct controller_block *block, char *param, int argc,
case COMMAND_VALUE_TYPE_BOOL:
entry->value.b = va_arg(val, int);
break;
case COMMAND_VALUE_TYPE_UINT32:
entry->value.u32 = va_arg(val, int);
break;
default:
log_send(LOG_T_ERROR, "%s not yet supported",
enum_command_value_type2str(command->value_type));
......
......@@ -82,6 +82,8 @@ struct tx_packet {
#define VESP_CONTROLLER_EEPROM_T_OFF_L 2
#define VESP_CONTROLLER_EEPROM_T_OFF_H 3
#define VESP_CONTROLLER_CTRL_OOB 128
static void calculate_controller_rx(struct controller_block *controller)
{
struct controller_block_private *priv = controller->private;
......@@ -94,14 +96,14 @@ static void calculate_controller_rx(struct controller_block *controller)
adc = be16toh(packet_rx->adc);
/* 0 -> -1.0
16383 -> 0.0
16384 -> 0.0
32767 -> 1.0
32767 -> 0.0
32768 -> 0.0
65535 -> 1.0
*/
if (adc & 0x8000)
priv->adc = ((float)(adc) - 16384.0) / 16387.0;
priv->adc = ((float)(adc) - 32768.0) / 32767.0;
else
priv->adc = ((float)(adc) - 16383.0) / 16387.0;
priv->adc = ((float)(adc) - 32767.0) / 32767.0;
priv->sw0 = switches & 0x01;
priv->sw1 = switches & 0x02;
priv->sw2 = switches & 0x04;
......@@ -116,7 +118,7 @@ static void calculate_controller_tx(struct controller_block *controller)
struct controller_block_private *priv = controller->private;
struct tx_packet *packet_tx = priv->data_tx;
packet_tx->leds =
packet_tx->leds = VESP_CONTROLLER_CTRL_OOB |
(*priv->led0 << 0) |
(*priv->led1 << 1) |
(*priv->led2 << 2) |
......
......@@ -72,11 +72,11 @@ static int vesp_tty_fd_recv(struct controller_block *vesp)
if (fd < 0)
return -1;
// log_send(LOG_T_DEBUG, "%s: try to receive %zd from fd %d",
// vesp->name, priv->rx_size, fd);
log_send(LOG_T_DEBUG, "%s: try to receive %zd from fd %d",
vesp->name, priv->rx_size, fd);
ret = read(fd, rx_buffer, priv->rx_size);
if (ret > 0) {
// log_send(LOG_T_DEBUG, "received %zd bytes", ret);
log_send(LOG_T_DEBUG, "received %zd bytes", ret);
vesp_input_process(priv->bus, rx_buffer, ret);
} else {
if (ret < 0 && errno != EAGAIN && errno != EWOULDBLOCK) {
......
......@@ -227,7 +227,7 @@ int vesp_input_process(struct controller_bus *bus, void *data, size_t size)
for (p = 0; p < size; p++) {
uint8_t b = data8[p];
// log_send(LOG_T_DEBUG, "%s: recv %zd: 0x%02x", bus->name, p, b);
log_send(LOG_T_DEBUG, "%s: recv %zd: 0x%02x", bus->name, p, b);
if (b == VESP_PKT_END || priv->rx_cur >= priv->rx_size) {
// log_send(LOG_T_DEBUG, "Got end, %zd bytes, crc: 0x%02x",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment