Commit 1c278e70 authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Add SETPOINT_TRACK to command_send.

Fix some small command handling stuff.
parent c75128e5
......@@ -201,6 +201,9 @@ int command_packet_entry_set(struct command_pkt *pkt,
vsize = 2;
break;
}
if (entry->type == COMMAND_PTYPE_SETPOINT_TRACK) {
vsize = 0;
}
size = sizeof(struct command_id);
size += vsize;
......@@ -228,6 +231,8 @@ int command_packet_entry_set(struct command_pkt *pkt,
}
switch (vsize) {
case 0:
break;
case 1:
*p = entry->value.u8;
break;
......@@ -352,14 +357,9 @@ int command_handle(struct command *command, fd_set *set)
case COMMAND_PTYPE_SPEED:
case COMMAND_PTYPE_SETPOINT: {
struct command_ptype_value *v;
struct command_id *id;
size_t pos_id = pos + sizeof(struct command_id);
entry.type = pkt->data[0];
if (pos_id < pkt->len) {
id = (void *)pkt->data + pos;
entry.id = be32toh(id->id);
v = (void *)pkt->data + pos_id;
switch (command->type) {
case COMMAND_VALUE_TYPE_FLOAT:
......@@ -381,6 +381,18 @@ int command_handle(struct command *command, fd_set *set)
break;
}
}
}
/* fall through */
case COMMAND_PTYPE_SETPOINT_TRACK: {
struct command_id *id;
if (sizeof(*id) <= pkt->len) {
id = (void *)pkt->data + 1;
entry.id = be32toh(id->id);
}
entry.type = pkt->data[0];
if (command->handler_entry)
command->handler_entry(command, &entry);
break;
......
......@@ -59,10 +59,12 @@ int main(int argc, char **argv)
char *type;
char *value;
enum command_ptype ptype = COMMAND_PTYPE_NULL;
bool has_value = true;
if (argc < 5) {
printf("Usage: %s <host> <port> <name> <type> <value>\n", argv[0]);
printf("Example: %s localhost %d spgname SETPOINT 42", port);
printf("Example: %s localhost %d spgname SETPOINT 42\n",
argv[0], port);
return 1;
}
......@@ -70,16 +72,22 @@ int main(int argc, char **argv)
port = atoi(argv[2]);
arg_name = argv[3];
type = argv[4];
value = argv[5];
if (!strcmp(type, "SETPOINT")) {
ptype = COMMAND_PTYPE_SETPOINT;
} else if (!strcmp(type, "SPEED")) {
ptype = COMMAND_PTYPE_SPEED;
} else if (!strcmp(type, "SETPOINT_TRACK")) {
ptype = COMMAND_PTYPE_SETPOINT_TRACK;
has_value = false;
} else {
printf("Unsupported type\n");
return 1;
}
if (has_value) {
value = argv[5];
}
command = command_open(host, port);
command->handler_list_entry = handler_list_entry;
......@@ -115,31 +123,34 @@ int main(int argc, char **argv)
struct command_entry entry;
entry.type = ptype;
switch (vtype) {
case COMMAND_VALUE_TYPE_FLOAT:
entry.value.f = atof(value);
break;
case COMMAND_VALUE_TYPE_BOOL:
entry.value.b = atoi(value);
break;
case COMMAND_VALUE_TYPE_UINT8:
entry.value.u8 = atoi(value);
break;
case COMMAND_VALUE_TYPE_UINT16:
entry.value.u16 = atoi(value);
break;
case COMMAND_VALUE_TYPE_UINT32:
entry.value.u32 = atoi(value);
break;
case COMMAND_VALUE_TYPE_SINT8:
entry.value.s8 = atoi(value);
break;
case COMMAND_VALUE_TYPE_SINT16:
entry.value.s16 = atoi(value);
break;
case COMMAND_VALUE_TYPE_SINT32:
entry.value.s32 = atoi(value);
break;
if (has_value) {
switch (vtype) {
case COMMAND_VALUE_TYPE_FLOAT:
entry.value.f = atof(value);
break;
case COMMAND_VALUE_TYPE_BOOL:
entry.value.b = atoi(value);
break;
case COMMAND_VALUE_TYPE_UINT8:
entry.value.u8 = atoi(value);
break;
case COMMAND_VALUE_TYPE_UINT16:
entry.value.u16 = atoi(value);
break;
case COMMAND_VALUE_TYPE_UINT32:
entry.value.u32 = atoi(value);
break;
case COMMAND_VALUE_TYPE_SINT8:
entry.value.s8 = atoi(value);
break;
case COMMAND_VALUE_TYPE_SINT16:
entry.value.s16 = atoi(value);
break;
case COMMAND_VALUE_TYPE_SINT32:
entry.value.s32 = atoi(value);
break;
}
}
command_send(command, &entry);
......
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