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

Merge branch 'beaglebone' into jeroen

parents 18a7162f 49fd7bff
...@@ -33,15 +33,9 @@ help: ...@@ -33,15 +33,9 @@ help:
echo "golden repository (on eris.camras.nl)." echo "golden repository (on eris.camras.nl)."
libnova/libnova.h: lib/libnova.la
libnova.la: lib/libnova.la
lib/libnova.la:
cd libnova-0.13.0 && ./configure -enable-static -disable-shared --prefix=${CURDIR} $(CONF_HOST) && $(MAKE) && $(MAKE) install
clean: subdirs_CLEAN clean: subdirs_CLEAN
rm -rf lib/* rm -rf lib/*
rm -rf include/libnova rm -rf include/libnova
cd libnova-0.13.0 ; $(MAKE) clean || true
# Rules for building a release # Rules for building a release
...@@ -80,13 +74,7 @@ rel_ctrl: rel_trace rel_log rel_command ...@@ -80,13 +74,7 @@ rel_ctrl: rel_trace rel_log rel_command
echo " Done" echo " Done"
rel_libnova: rel_clone_dir rel_cons: rel_trace rel_log rel_command
@echo "****** Building libnova"; \
(cd $(REL_BUILD_DIR)/libnova-0.13.0 ; ./configure -enable-static -disable-shared --prefix=$(REL_BUILD_DIR) $(CONF_HOST); $(MAKE); $(MAKE) install) >/dev/null; \
echo " Done"
rel_cons: rel_trace rel_libnova rel_log rel_command
@echo "****** Building console"; \ @echo "****** Building console"; \
$(MAKE) -C $(REL_BUILD_DIR)/console >/dev/null; \ $(MAKE) -C $(REL_BUILD_DIR)/console >/dev/null; \
echo " Done" echo " Done"
...@@ -123,7 +111,7 @@ TARGETS:= ...@@ -123,7 +111,7 @@ TARGETS:=
include $(DIR)/$1/build.mk include $(DIR)/$1/build.mk
targets_$$(DIR): $$(TARGETS) targets_$$(DIR): $$(TARGETS)
$$(TARGETS): $(DIR)/$1/build.mk $$(TARGETS): $(DIR)/$1/build.mk Makefile build.mk buildflags.mk
TARGETS:= $$($(DIR)_TMPTARGETS) $$(TARGETS) TARGETS:= $$($(DIR)_TMPTARGETS) $$(TARGETS)
......
...@@ -3,8 +3,12 @@ BUILDSYS=@BUILDSYS@ ...@@ -3,8 +3,12 @@ BUILDSYS=@BUILDSYS@
BUILD_CONSOLE=@BUILD_CONSOLE@ BUILD_CONSOLE=@BUILD_CONSOLE@
BUILD_CONSOLE_HTTPD=@BUILD_CONSOLE_HTTPD@ BUILD_CONSOLE_HTTPD=@BUILD_CONSOLE_HTTPD@
BUILD_CONSOLE_J2000=@BUILD_CONSOLE_J2000@
BUILD_CONSOLE_SATTRACKER=@BUILD_CONSOLE_SATTRACKER@
BUILD_CONSOLE_J2000_INDI=@BUILD_CONSOLE_J2000_INDI@ BUILD_CONSOLE_J2000_INDI=@BUILD_CONSOLE_J2000_INDI@
BUILD_ETHERCAT=@BUILD_ETHERCAT@ BUILD_ETHERCAT=@BUILD_ETHERCAT@
BUILD_VESP=@BUILD_VESP@ BUILD_VESP=@BUILD_VESP@
BUILD_AM335X=@BUILD_AM335X@ BUILD_AM335X=@BUILD_AM335X@
BUILD_TEST=@BUILD_TEST@
command_joystick
command_list command_list
command_send command_send
...@@ -3,6 +3,10 @@ COMMAND_TARGETS += $(LIBDIR)/libcommand.la ...@@ -3,6 +3,10 @@ COMMAND_TARGETS += $(LIBDIR)/libcommand.la
COMMAND_TARGETS += $(DIR)/command_list $(DIR)/command_send COMMAND_TARGETS += $(DIR)/command_list $(DIR)/command_send
ifneq ($(OS), FreeBSD)
COMMAND_TARGETS += $(DIR)/command_joystick
endif
ARCHSRCS := $(DIR)/command.c $(DIR)/command_tcp.c ARCHSRCS := $(DIR)/command.c $(DIR)/command_tcp.c
ARCHOBJS := $(ARCHSRCS:.c=.lo) ARCHOBJS := $(ARCHSRCS:.c=.lo)
...@@ -28,9 +32,17 @@ $(DIR)/command_send: libcommand.la ...@@ -28,9 +32,17 @@ $(DIR)/command_send: libcommand.la
$(DIR)/command_send_LDFLAGS += -lcommand $(DIR)/command_send_LDFLAGS += -lcommand
$(DIR)/command_send: $(COMMAND_SEND_OBJS) $(DIR)/command_send: $(COMMAND_SEND_OBJS)
SRCS += $(ARCHSRCS) $(COMMAND_LIST_SRCS) $(COMMAND_SEND_SRCS) COMMAND_JOYSTICK_SRCS := $(DIR)/command_joystick.c
COMMAND_JOYSTICK_OBJS := $(COMMAND_JOYSTICK_SRCS:.c=.o)
$(DIR)/command_joystick: libcommand.la
$(DIR)/command_joystick_LDFLAGS += -lcommand
$(DIR)/command_joystick: $(COMMAND_JOYSTICK_OBJS)
SRCS += $(ARCHSRCS) $(COMMAND_LIST_SRCS) $(COMMAND_SEND_SRCS) $(COMMAND_JOYSTICK_SRCS)
TARGETS += $(COMMAND_TARGETS) TARGETS += $(COMMAND_TARGETS)
CLEAN += $(COMMAND_TARGETS) $(ARCHOBJS) \ CLEAN += $(COMMAND_TARGETS) $(ARCHOBJS) \
$(COMMAND_LIST_OBJS) \ $(COMMAND_LIST_OBJS) \
$(COMMAND_SEND_OBJS) \ $(COMMAND_SEND_OBJS) \
$(COMMAND_JOYSTICK_OBJS) \
$(LIBDIR)/libcommand.a $(LIBDIR)/libcommand.a
...@@ -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;
...@@ -521,6 +533,8 @@ char *enum_command_ptype2str(enum command_ptype ptype) ...@@ -521,6 +533,8 @@ char *enum_command_ptype2str(enum command_ptype ptype)
return "SPEED"; return "SPEED";
case COMMAND_PTYPE_SETPOINT_TIME: case COMMAND_PTYPE_SETPOINT_TIME:
return "SETPOINT_TIME"; return "SETPOINT_TIME";
case COMMAND_PTYPE_SETPOINT_TRACK:
return "SETPOINT_TRACK";
case COMMAND_PTYPE_MAX: case COMMAND_PTYPE_MAX:
return "MAX"; return "MAX";
default: default:
......
...@@ -35,6 +35,7 @@ enum command_ptype { ...@@ -35,6 +35,7 @@ enum command_ptype {
COMMAND_PTYPE_SETPOINT = 4, /* Simple direct setpoint */ COMMAND_PTYPE_SETPOINT = 4, /* Simple direct setpoint */
COMMAND_PTYPE_SPEED = 5, /* Simple direct 1st derivative setpoint */ COMMAND_PTYPE_SPEED = 5, /* Simple direct 1st derivative setpoint */
COMMAND_PTYPE_SETPOINT_TIME = 6, /* Setpoint to be reached @ time */ COMMAND_PTYPE_SETPOINT_TIME = 6, /* Setpoint to be reached @ time */
COMMAND_PTYPE_SETPOINT_TRACK = 7, /* Use setpoint from track input */
COMMAND_PTYPE_MAX, /* Always the last entry! */ COMMAND_PTYPE_MAX, /* Always the last entry! */
}; };
......
/*
Copyright Jeroen Vreeken (jeroen@vreeken.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 <fcntl.h>
#include <linux/joystick.h>
#include <command/command.h>
#include <dt_port_numbers.h>
#include <stdbool.h>
static bool found_name = false;
static bool found_float = false;
static bool found_setpoint = false;
static char *arg_name;
static void handler_list_entry(struct command *command,
char *name, enum command_value_type type, char *unit,
int typec, enum command_ptype typev[])
{
int i;
if (strcmp(name, arg_name))
return;
found_name = true;
found_float = (type == COMMAND_VALUE_TYPE_FLOAT);
for (i = 0; i < typec; i++) {
if (typev[i] == COMMAND_PTYPE_SETPOINT)
found_setpoint = true;
}
}
int main(int argc, char **argv)
{
struct command *command;
char *id = "command_joystick";
char *host;
short port = 21000;
char *js_dev;
int fd_joy = -1;
if (argc < 5) {
printf("Usage: %s <host> <port> <name> <joystick dev>\n", argv[0]);
printf("Example: %s localhost %d spgname /dev/input/js0", argv[0], port);
return 1;
}
host = argv[1];
port = atoi(argv[2]);
arg_name = argv[3];
js_dev = argv[4];
fd_joy = open(js_dev, O_RDONLY);
if (fd_joy < 0) {
perror("Could not open joystick device");
return 1;
}
ioctl(fd_joy, FIONBIO, &(int){ 1 });
command = command_open(host, port);
command->handler_list_entry = handler_list_entry;
while (command_state_get(command) != COMMAND_STATE_READY &&
command_state_get(command) != COMMAND_STATE_DISCONNECTED) {
fd_set fdrx;
int high = 0;
FD_ZERO(&fdrx);
command_fd_set(command, &fdrx, &high);
select(high + 1, &fdrx, NULL, NULL, NULL);
command_handle(command, &fdrx);
}
if (command_state_get(command) == COMMAND_STATE_DISCONNECTED) {
printf("Not connected.\n");
return 1;
}
if (!found_name) {
printf("Could not find spg '%s'\n", arg_name);
return 1;
}
if (!found_float) {
printf("Only float type is supported\n");
return 1;
}
if (!found_setpoint) {
printf("Setpoint command is not supported\n");
return 1;
}
command->type = COMMAND_VALUE_TYPE_FLOAT;
command_id_set(command, id);
command_name_set(command, arg_name);
do {
fd_set fdrx;
int high;
FD_ZERO(&fdrx);
FD_SET(fd_joy, &fdrx);
high = fd_joy;
command_fd_set(command, &fdrx, &high);
select(high + 1, &fdrx, NULL, NULL, NULL);
command_handle(command, &fdrx);
if (FD_ISSET(fd_joy, &fdrx)) {
struct js_event event;
ssize_t ret = read(fd_joy, &event, sizeof(event));
if (ret == sizeof(event)) {
if (event.type & JS_EVENT_AXIS && event.number == 0) {
struct command_entry entry;
entry.type = COMMAND_PTYPE_SETPOINT;
entry.value.f = (float)event.value / 32768.0;
command_send(command, &entry);
}
}
}
} while (1);
return 0;
}
...@@ -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,17 +72,23 @@ int main(int argc, char **argv) ...@@ -70,17 +72,23 @@ 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,6 +123,8 @@ int main(int argc, char **argv) ...@@ -115,6 +123,8 @@ int main(int argc, char **argv)
struct command_entry entry; struct command_entry entry;
entry.type = ptype; entry.type = ptype;
if (has_value) {
switch (vtype) { switch (vtype) {
case COMMAND_VALUE_TYPE_FLOAT: case COMMAND_VALUE_TYPE_FLOAT:
entry.value.f = atof(value); entry.value.f = atof(value);
...@@ -141,6 +151,7 @@ int main(int argc, char **argv) ...@@ -141,6 +151,7 @@ int main(int argc, char **argv)
entry.value.s32 = atoi(value); entry.value.s32 = atoi(value);
break; break;
} }
}
command_send(command, &entry); command_send(command, &entry);
printf("Command sent\n"); printf("Command sent\n");
......
/* /*
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2008, 2013, 2014 Copyright Jeroen Vreeken (jeroen@vreeken.net), 2008, 2013, 2014, 2015
Copyright Stichting C.A. Muller Radioastronomiestation, 2008, 2013 Copyright Stichting C.A. Muller Radioastronomiestation, 2008, 2013
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
...@@ -226,13 +226,13 @@ static void *log_server(void *arg) ...@@ -226,13 +226,13 @@ static void *log_server(void *arg)
(struct sockaddr *)&sockaddr, sizeof(sockaddr)) < 0) { (struct sockaddr *)&sockaddr, sizeof(sockaddr)) < 0) {
perror("bind() failed"); perror("bind() failed");
close(fd_accept); close(fd_accept);
return NULL; fd_accept = -1;
} }
if (listen(fd_accept, 4) < 0) { if (fd_accept >= 0 && listen(fd_accept, 4) < 0) {
perror("listen() failed"); perror("listen() failed");
close(fd_accept); close(fd_accept);
return NULL; fd_accept = -1;
} }
while (1) { while (1) {
...@@ -247,7 +247,7 @@ static void *log_server(void *arg) ...@@ -247,7 +247,7 @@ static void *log_server(void *arg)
sem_wait(&queue_wait); sem_wait(&queue_wait);
} }
do { if (fd_accept >= 0) do {
FD_ZERO(&fdset_r); FD_ZERO(&fdset_r);
FD_SET(fd_accept, &fdset_r); FD_SET(fd_accept, &fdset_r);
tv.tv_sec = 0; tv.tv_sec = 0;
...@@ -358,9 +358,6 @@ int log_server_start(int port, enum log_type console_level, ...@@ -358,9 +358,6 @@ int log_server_start(int port, enum log_type console_level,
printf("Starting log server on port %d\n", port); printf("Starting log server on port %d\n", port);
pthread_attr_init(&attr); pthread_attr_init(&attr);
#ifndef __FreeBSD__
pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN * 2);
#endif
pthread_create(&thread_id, &attr, log_server, NULL); pthread_create(&thread_id, &attr, log_server, NULL);
......
...@@ -89,7 +89,7 @@ int trace_interval_set(struct trace *trace, struct timespec *interval, enum trac ...@@ -89,7 +89,7 @@ int trace_interval_set(struct trace *trace, struct timespec *interval, enum trac
return 0; return 0;
} }
int trace_name_set(struct trace *trace, char *name) int trace_name_set(struct trace *trace, int channel, char *name)
{ {
struct trace_pkt *pkt; struct trace_pkt *pkt;
...@@ -98,7 +98,7 @@ int trace_name_set(struct trace *trace, char *name) ...@@ -98,7 +98,7 @@ int trace_name_set(struct trace *trace, char *name)
trace->name = strdup(name); trace->name = strdup(name);
pkt = trace_packet_new(); pkt = trace_packet_new();
trace_packet_name_set(pkt, name); trace_packet_name_set(pkt, channel, name);
trace_packet_write(trace, pkt); trace_packet_write(trace, pkt);
trace_packet_put(pkt); trace_packet_put(pkt);
...@@ -208,7 +208,8 @@ int trace_packet_list_add(struct trace_pkt *pkt, ...@@ -208,7 +208,8 @@ int trace_packet_list_add(struct trace_pkt *pkt,
return 0; return 0;
} }
int trace_packet_value_add(struct trace_pkt *pkt, struct trace_value *value, enum trace_value_type type) int trace_packet_value_add(struct trace_pkt *pkt, int channel,
struct trace_value *value, enum trace_value_type type)
{ {
size_t entry_size; size_t entry_size;
struct { struct {
...@@ -223,28 +224,30 @@ int trace_packet_value_add(struct trace_pkt *pkt, struct trace_value *value, enu ...@@ -223,28 +224,30 @@ int trace_packet_value_add(struct trace_pkt *pkt, struct trace_value *value, enu
case TRACE_VALUE_TYPE_BOOL: case TRACE_VALUE_TYPE_BOOL:
case TRACE_VALUE_TYPE_UINT8: case TRACE_VALUE_TYPE_UINT8:
case TRACE_VALUE_TYPE_SINT8: case TRACE_VALUE_TYPE_SINT8:
entry_size = 1; entry_size = 1+1;
break; break;
case TRACE_VALUE_TYPE_SINT16: case TRACE_VALUE_TYPE_SINT16:
case TRACE_VALUE_TYPE_UINT16: case TRACE_VALUE_TYPE_UINT16:
entry_size = 2; entry_size = 2+1;
break; break;
case TRACE_VALUE_TYPE_UINT32: case TRACE_VALUE_TYPE_UINT32:
case TRACE_VALUE_TYPE_SINT32: case TRACE_VALUE_TYPE_SINT32:
case TRACE_VALUE_TYPE_FLOAT: case TRACE_VALUE_TYPE_FLOAT:
default: default:
entry_size = 4; entry_size = 4+1;
break; break;
} }
if (!pkt->len) { if (!pkt->len) {
trace_packet_resize(pkt, 1); size_t len = sizeof(struct trace_header);
pkt->len = 1; trace_packet_resize(pkt, len);
pkt->len = len;
pkt->data[0] = TRACE_PTYPE_DATA; pkt->data[0] = TRACE_PTYPE_DATA;
} }
trace_packet_resize(pkt, pkt->len + entry_size); trace_packet_resize(pkt, pkt->len + entry_size);
entry = pkt->data + pkt->len; pkt->data[pkt->len] = channel;
entry = pkt->data + pkt->len + 1;
switch (type) { switch (type) {
case TRACE_VALUE_TYPE_BOOL: case TRACE_VALUE_TYPE_BOOL:
...@@ -315,14 +318,18 @@ int trace_packet_timestamp_set(struct trace_pkt *pkt, ...@@ -315,14 +318,18 @@ int trace_packet_timestamp_set(struct trace_pkt *pkt,
return 0; return 0;
} }
int trace_packet_name_set(struct trace_pkt *pkt, char *name) int trace_packet_name_set(struct trace_pkt *pkt, int channel, char *name)
{ {
if (pkt->len < sizeof(struct trace_header) + strlen(name) + 1) { size_t len = sizeof(struct trace_header) +
pkt->len = strlen(name) + 1 + sizeof(struct trace_header);