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