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:
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
rm -rf lib/*
rm -rf include/libnova
cd libnova-0.13.0 ; $(MAKE) clean || true
# Rules for building a release
......@@ -80,13 +74,7 @@ rel_ctrl: rel_trace rel_log rel_command
echo " Done"
rel_libnova: rel_clone_dir
@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
rel_cons: rel_trace rel_log rel_command
@echo "****** Building console"; \
$(MAKE) -C $(REL_BUILD_DIR)/console >/dev/null; \
echo " Done"
......@@ -123,7 +111,7 @@ TARGETS:=
include $(DIR)/$1/build.mk
targets_$$(DIR): $$(TARGETS)
$$(TARGETS): $(DIR)/$1/build.mk
$$(TARGETS): $(DIR)/$1/build.mk Makefile build.mk buildflags.mk
TARGETS:= $$($(DIR)_TMPTARGETS) $$(TARGETS)
......
......@@ -3,8 +3,12 @@ BUILDSYS=@BUILDSYS@
BUILD_CONSOLE=@BUILD_CONSOLE@
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_ETHERCAT=@BUILD_ETHERCAT@
BUILD_VESP=@BUILD_VESP@
BUILD_AM335X=@BUILD_AM335X@
BUILD_TEST=@BUILD_TEST@
command_joystick
command_list
command_send
......@@ -3,6 +3,10 @@ COMMAND_TARGETS += $(LIBDIR)/libcommand.la
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
ARCHOBJS := $(ARCHSRCS:.c=.lo)
......@@ -28,9 +32,17 @@ $(DIR)/command_send: libcommand.la
$(DIR)/command_send_LDFLAGS += -lcommand
$(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)
CLEAN += $(COMMAND_TARGETS) $(ARCHOBJS) \
$(COMMAND_LIST_OBJS) \
$(COMMAND_SEND_OBJS) \
$(COMMAND_JOYSTICK_OBJS) \
$(LIBDIR)/libcommand.a
......@@ -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;
......@@ -521,6 +533,8 @@ char *enum_command_ptype2str(enum command_ptype ptype)
return "SPEED";
case COMMAND_PTYPE_SETPOINT_TIME:
return "SETPOINT_TIME";
case COMMAND_PTYPE_SETPOINT_TRACK:
return "SETPOINT_TRACK";
case COMMAND_PTYPE_MAX:
return "MAX";
default:
......
......@@ -35,6 +35,7 @@ enum command_ptype {
COMMAND_PTYPE_SETPOINT = 4, /* Simple direct setpoint */
COMMAND_PTYPE_SPEED = 5, /* Simple direct 1st derivative setpoint */
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! */
};
......
/*
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)
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);
......
/*
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
This program is free software: you can redistribute it and/or modify
......@@ -226,13 +226,13 @@ static void *log_server(void *arg)
(struct sockaddr *)&sockaddr, sizeof(sockaddr)) < 0) {
perror("bind() failed");
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");
close(fd_accept);
return NULL;
fd_accept = -1;
}
while (1) {
......@@ -247,7 +247,7 @@ static void *log_server(void *arg)
sem_wait(&queue_wait);
}
do {
if (fd_accept >= 0) do {
FD_ZERO(&fdset_r);
FD_SET(fd_accept, &fdset_r);
tv.tv_sec = 0;
......@@ -358,9 +358,6 @@ int log_server_start(int port, enum log_type console_level,
printf("Starting log server on port %d\n", port);
pthread_attr_init(&attr);
#ifndef __FreeBSD__
pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN * 2);
#endif
pthread_create(&thread_id, &attr, log_server, NULL);
......
......@@ -89,7 +89,7 @@ int trace_interval_set(struct trace *trace, struct timespec *interval, enum trac
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;
......@@ -98,7 +98,7 @@ int trace_name_set(struct trace *trace, char *name)
trace->name = strdup(name);
pkt = trace_packet_new();
trace_packet_name_set(pkt, name);
trace_packet_name_set(pkt, channel, name);
trace_packet_write(trace, pkt);
trace_packet_put(pkt);
......@@ -208,7 +208,8 @@ int trace_packet_list_add(struct trace_pkt *pkt,
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;
struct {
......@@ -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_UINT8:
case TRACE_VALUE_TYPE_SINT8:
entry_size = 1;
entry_size = 1+1;
break;
case TRACE_VALUE_TYPE_SINT16:
case TRACE_VALUE_TYPE_UINT16:
entry_size = 2;
entry_size = 2+1;
break;
case TRACE_VALUE_TYPE_UINT32:
case TRACE_VALUE_TYPE_SINT32:
case TRACE_VALUE_TYPE_FLOAT:
default:
entry_size = 4;
entry_size = 4+1;
break;
}
if (!pkt->len) {
trace_packet_resize(pkt, 1);
pkt->len = 1;
size_t len = sizeof(struct trace_header);
trace_packet_resize(pkt, len);
pkt->len = len;
pkt->data[0] = TRACE_PTYPE_DATA;
}
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) {
case TRACE_VALUE_TYPE_BOOL:
......@@ -315,14 +318,18 @@ int trace_packet_timestamp_set(struct trace_pkt *pkt,
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) {
pkt->len = strlen(name) + 1 + sizeof(struct trace_header);
size_t len = sizeof(struct trace_header) +
sizeof(struct trace_ptype_name_header) +
strlen(name) + 1;
if (pkt->len < len) {
pkt->len = len;
trace_packet_resize(pkt, pkt->len);
pkt->data[0] = TRACE_PTYPE_NAME;
pkt->data[1] = 0;
}
strcpy((char *)pkt->data + 1, name);
strcpy((char *)pkt->data + 2, name);
return 0;
}
......@@ -343,6 +350,22 @@ int trace_packet_type_set(struct trace_pkt *pkt, enum trace_value_type type)
return 0;
}
int trace_packet_capabilities_set(struct trace_pkt *pkt, unsigned long cap)
{
size_t len = sizeof(struct trace_header) +
sizeof(struct trace_ptype_capabilities);
if (pkt->len < len) {
struct trace_ptype_capabilities *pcap;
pkt->len = len;
trace_packet_resize(pkt, pkt->len);
pkt->data[0] = TRACE_PTYPE_CAPABILITIES;
pcap = (void*)pkt->data + 1;
pcap->capabilities = htobe32(cap);
}
return 0;
}
bool trace_check(struct trace *trace)
{
if (trace->fd < 0) {
......@@ -360,8 +383,9 @@ bool trace_check(struct trace *trace)
struct trace_pkt *pkt;
if (trace->name) {
int channel = 0;
pkt = trace_packet_new();
trace_packet_name_set(pkt, trace->name);
trace_packet_name_set(pkt, channel, trace->name);
trace_packet_write(trace, pkt);
trace_packet_put(pkt);
}
......@@ -475,40 +499,58 @@ int trace_handle_recv(struct trace *trace)
}
case TRACE_PTYPE_NAME: {
char *name;
int channel;
name = (void*)pkt->data + 1;
name = (void*)pkt->data +
sizeof(struct trace_ptype_name_header) +
sizeof(struct trace_header);
trace->name_set = true;
trace->name = strdup(name);
channel = pkt->data[sizeof(struct trace_header)];
if (trace->handler_name) {
trace->handler_name(trace, name);
trace->handler_name(trace, channel, name);
}
break;
}
case TRACE_PTYPE_CAPABILITIES: {
size_t pos = sizeof(struct trace_header);
struct trace_ptype_capabilities *ncaps = (void *)pkt->data + pos;
unsigned long caps = be32toh(ncaps->capabilities);
if (trace->handler_capabilities) {
trace->handler_capabilities(trace, caps);
}
break;
}
case TRACE_PTYPE_DATA: {
size_t pos = 1;
/* ignore channel number for now (no multiplexing yet) */
size_t pos = sizeof(struct trace_header);
struct trace_ptype_value *v;
uint8_t channel;
while (pos < pkt->len) {
v = (void *)pkt->data + pos;
channel = v->channel;
switch (trace->type) {
case TRACE_VALUE_TYPE_FLOAT:
case TRACE_VALUE_TYPE_UINT32:
case TRACE_VALUE_TYPE_SINT32:
trace->value.value.u32 = be32toh(v->u.u32);
pos+=4;
pos+=4+1;
break;
case TRACE_VALUE_TYPE_UINT16:
case TRACE_VALUE_TYPE_SINT16:
trace->value.value.u16 = be32toh(v->u.u16);
pos+=2;
pos+=2+1;
break;
case TRACE_VALUE_TYPE_BOOL:
case TRACE_VALUE_TYPE_UINT8:
case TRACE_VALUE_TYPE_SINT8: