Skip to content

Commit

Permalink
[telemetry] add support for ivy_transport
Browse files Browse the repository at this point in the history
  • Loading branch information
gautierhattenberger committed Nov 5, 2014
1 parent e5cdfa1 commit 96445e9
Show file tree
Hide file tree
Showing 16 changed files with 342 additions and 103 deletions.
8 changes: 4 additions & 4 deletions conf/firmwares/subsystems/fixedwing/autopilot.makefile
Expand Up @@ -183,8 +183,8 @@ sim.srcs += $(fbw_srcs) $(ap_srcs)
sim.CFLAGS += -DSITL
sim.srcs += $(SRC_ARCH)/sim_ap.c

sim.CFLAGS += -DDOWNLINK -DPERIODIC_TELEMETRY -DDOWNLINK_TRANSPORT=IvyTransport
sim.srcs += subsystems/datalink/downlink.c $(SRC_FIRMWARE)/datalink.c $(SRC_ARCH)/ivy_transport.c
sim.CFLAGS += -DDOWNLINK -DPERIODIC_TELEMETRY -DDOWNLINK_TRANSPORT=ivy_tp -DDOWNLINK_DEVICE=ivy_tp
sim.srcs += subsystems/datalink/downlink.c $(SRC_FIRMWARE)/datalink.c subsystems/datalink/ivy_transport.c

sim.srcs += $(SRC_ARCH)/sim_gps.c $(SRC_ARCH)/sim_adc_generic.c

Expand Down Expand Up @@ -223,8 +223,8 @@ jsbsim.srcs += $(SIMDIR)/sim_ac_jsbsim.c $(SIMDIR)/sim_ac_fw.c $(SIMDIR)/sim_a
jsbsim.CFLAGS += -I/usr/include $(shell pkg-config glib-2.0 --cflags)
jsbsim.LDFLAGS += $(shell pkg-config glib-2.0 --libs) -lglibivy -lm $(shell pcre-config --libs)

jsbsim.CFLAGS += -DDOWNLINK -DPERIODIC_TELEMETRY -DDOWNLINK_TRANSPORT=IvyTransport
jsbsim.srcs += subsystems/datalink/downlink.c $(SRC_FIRMWARE)/datalink.c $(SRC_ARCH)/ivy_transport.c
jsbsim.CFLAGS += -DDOWNLINK -DPERIODIC_TELEMETRY -DDOWNLINK_TRANSPORT=ivy_tp -DDOWNLINK_DEVICE=ivy_tp
jsbsim.srcs += subsystems/datalink/downlink.c $(SRC_FIRMWARE)/datalink.c subsystems/datalink/ivy_transport.c

jsbsim.srcs += $(SRC_ARCH)/jsbsim_hw.c $(SRC_ARCH)/jsbsim_ir.c $(SRC_ARCH)/jsbsim_gps.c $(SRC_ARCH)/jsbsim_ahrs.c $(SRC_ARCH)/jsbsim_transport.c

Expand Down
4 changes: 2 additions & 2 deletions conf/firmwares/subsystems/fixedwing/fdm_crrcsim.makefile
Expand Up @@ -47,6 +47,6 @@ nps.srcs += $(NPSDIR)/nps_main.c \
$(NPSDIR)/nps_flightgear.c \


nps.CFLAGS += -DDOWNLINK -DPERIODIC_TELEMETRY -DDOWNLINK_TRANSPORT=IvyTransport
nps.srcs += subsystems/datalink/downlink.c $(SRC_FIRMWARE)/datalink.c $(SRC_ARCH)/ivy_transport.c
nps.CFLAGS += -DDOWNLINK -DPERIODIC_TELEMETRY -DDOWNLINK_TRANSPORT=ivy_tp -DDOWNLINK_DEVICE=ivy_tp
nps.srcs += subsystems/datalink/downlink.c $(SRC_FIRMWARE)/datalink.c subsystems/datalink/ivy_transport.c

4 changes: 2 additions & 2 deletions conf/firmwares/subsystems/fixedwing/fdm_jsbsim.makefile
Expand Up @@ -65,6 +65,6 @@ nps.srcs += $(NPSDIR)/nps_main.c \

nps.srcs += math/pprz_geodetic_wmm2010.c

nps.CFLAGS += -DDOWNLINK -DPERIODIC_TELEMETRY -DDOWNLINK_TRANSPORT=IvyTransport
nps.srcs += subsystems/datalink/downlink.c $(SRC_FIRMWARE)/datalink.c $(SRC_ARCH)/ivy_transport.c
nps.CFLAGS += -DDOWNLINK -DPERIODIC_TELEMETRY -DDOWNLINK_TRANSPORT=ivy_tp -DDOWNLINK_DEVICE=ivy_tp
nps.srcs += subsystems/datalink/downlink.c $(SRC_FIRMWARE)/datalink.c subsystems/datalink/ivy_transport.c

4 changes: 2 additions & 2 deletions conf/firmwares/subsystems/rotorcraft/fdm_jsbsim.makefile
Expand Up @@ -62,8 +62,8 @@ nps.srcs += $(NPSDIR)/nps_main.c \
# for geo mag calculation
nps.srcs += math/pprz_geodetic_wmm2010.c

nps.CFLAGS += -DDOWNLINK -DPERIODIC_TELEMETRY -DDOWNLINK_TRANSPORT=IvyTransport -DDefaultPeriodic='&telemetry_Main'
nps.srcs += $(SRC_ARCH)/ivy_transport.c
nps.CFLAGS += -DDOWNLINK -DPERIODIC_TELEMETRY -DDOWNLINK_TRANSPORT=ivy_tp -DDOWNLINK_DEVICE=ivy_tp -DDefaultPeriodic='&telemetry_Main'
nps.srcs += subsystems/datalink/ivy_transport.c
nps.srcs += subsystems/datalink/downlink.c subsystems/datalink/telemetry.c
nps.srcs += $(SRC_FIRMWARE)/rotorcraft_telemetry.c
nps.srcs += $(SRC_FIRMWARE)/datalink.c
Expand Down
3 changes: 0 additions & 3 deletions sw/airborne/arch/sim/ivy_transport.c

This file was deleted.

73 changes: 0 additions & 73 deletions sw/airborne/arch/sim/ivy_transport.h

This file was deleted.

2 changes: 1 addition & 1 deletion sw/airborne/arch/sim/sim_ap.c
Expand Up @@ -110,7 +110,7 @@ value update_bat(value bat) {
}

value update_dl_status(value dl_enabled) {
ivy_dl_enabled = Int_val(dl_enabled);
ivy_tp.ivy_dl_enabled = Int_val(dl_enabled);
return Val_unit;
}

Expand Down
4 changes: 4 additions & 0 deletions sw/airborne/firmwares/fixedwing/main_ap.c
Expand Up @@ -78,6 +78,7 @@ PRINT_CONFIG_MSG_VALUE("USE_BARO_BOARD is TRUE, reading onboard baro: ", BARO_BO
#include "subsystems/datalink/pprz_transport.h"
#include "subsystems/datalink/xbee.h"
#include "subsystems/datalink/w5100.h"
#include "subsystems/datalink/ivy_transport.h"

// modules & settings
#include "generated/modules.h"
Expand Down Expand Up @@ -254,6 +255,9 @@ void init_ap( void ) {
w5100_init();
#endif
#endif /* DATALINK */
#if SITL
ivy_transport_init();
#endif

#if defined AEROCOMM_DATA_PIN
IO0DIR |= _BV(AEROCOMM_DATA_PIN);
Expand Down
4 changes: 4 additions & 0 deletions sw/airborne/firmwares/rotorcraft/main.c
Expand Up @@ -44,6 +44,7 @@
#include "subsystems/settings.h"
#include "subsystems/datalink/pprz_transport.h"
#include "subsystems/datalink/xbee.h"
#include "subsystems/datalink/ivy_transport.h"

#include "subsystems/commands.h"
#include "subsystems/actuators.h"
Expand Down Expand Up @@ -178,6 +179,9 @@ STATIC_INLINE void main_init( void ) {
#if DATALINK == XBEE
xbee_init();
#endif
#if SITL
ivy_transport_init();
#endif

// register the timers for the periodic functions
main_periodic_tid = sys_time_register_timer((1./PERIODIC_FREQUENCY), NULL);
Expand Down
178 changes: 178 additions & 0 deletions sw/airborne/subsystems/datalink/ivy_transport.c
@@ -0,0 +1,178 @@
/*
* Copyright (C) 2003 Pascal Brisset, Antoine Drouin
* Copyright (C) 2014 Gautier Hattenberger <gautier.hattenberger@enac.fr>
*
* This file is part of paparazzi.
*
* paparazzi 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 2, or (at your option)
* any later version.
*
* paparazzi 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 paparazzi; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/

/**
* @file subsystems/datalink/ivy_transport.c
*
* Building Paparazzi frames over IVY.
*
*/

#include "std.h"
#include "subsystems/datalink/ivy_transport.h"
#include "subsystems/datalink/downlink.h"
#include "subsystems/datalink/transport.h"

#include <stdio.h>
#include <Ivy/ivy.h>

struct ivy_transport ivy_tp;

static void put_bytes(struct ivy_transport *trans, struct device *dev __attribute__((unused)), enum TransportDataType type __attribute__((unused)), enum TransportDataFormat format __attribute__((unused)), uint8_t len, const void *bytes)
{
const uint8_t *b = (const uint8_t *) bytes;

// Start delimiter for arrays
if (format == DL_FORMAT_ARRAY) {
trans->ivy_p += sprintf(trans->ivy_p, "|");
}

int i = 0;
while (i < len) {
// print data with correct type
switch (type) {
case DL_TYPE_CHAR:
trans->ivy_p += sprintf(trans->ivy_p, "%c", (char)(*((char*)(b+i))));
i++;
break;
case DL_TYPE_UINT8:
trans->ivy_p += sprintf(trans->ivy_p, "%u", b[i]);
i++;
break;
case DL_TYPE_UINT16:
trans->ivy_p += sprintf(trans->ivy_p, "%u", (uint16_t)(*((uint16_t*)(b+i))));
i += 2;
break;
case DL_TYPE_UINT32:
case DL_TYPE_TIMESTAMP:
trans->ivy_p += sprintf(trans->ivy_p, "%u", (uint32_t)(*((uint32_t*)(b+i))));
i += 4;
break;
case DL_TYPE_UINT64:
trans->ivy_p += sprintf(trans->ivy_p, "%llu", (uint64_t)(*((uint64_t*)(b+i))));
i += 8;
break;
case DL_TYPE_INT8:
trans->ivy_p += sprintf(trans->ivy_p, "%d", (int8_t)(*((int8_t*)(b+i))));
i++;
break;
case DL_TYPE_INT16:
trans->ivy_p += sprintf(trans->ivy_p, "%d", (int16_t)(*((int16_t*)(b+i))));
i += 2;
break;
case DL_TYPE_INT32:
trans->ivy_p += sprintf(trans->ivy_p, "%d", (int32_t)(*((int32_t*)(b+i))));
i += 4;
break;
case DL_TYPE_INT64:
trans->ivy_p += sprintf(trans->ivy_p, "%lld", (int64_t)(*((int64_t*)(b+i))));
i += 8;
break;
case DL_TYPE_FLOAT:
trans->ivy_p += sprintf(trans->ivy_p, "%f", (float)(*((float*)(b+i))));
i += 4;
break;
case DL_TYPE_DOUBLE:
trans->ivy_p += sprintf(trans->ivy_p, "%f", (double)(*((double*)(b+i))));
i += 8;
break;
case DL_TYPE_ARRAY_LENGTH:
default:
// Don't print array length but increment index
i++;
break;
}
// Coma delimiter for array, space otherwise
if (format == DL_FORMAT_ARRAY) {
trans->ivy_p += sprintf(trans->ivy_p, ",");
} else {
trans->ivy_p += sprintf(trans->ivy_p, " ");
}
}

// End delimiter for arrays
if (format == DL_FORMAT_ARRAY) {
trans->ivy_p += sprintf(trans->ivy_p, "| ");
}
}

static void put_named_byte(struct ivy_transport *trans, struct device *dev __attribute__((unused)), enum TransportDataType type __attribute__((unused)), enum TransportDataFormat format __attribute__((unused)), uint8_t byte __attribute__((unused)), const char * name __attribute__((unused)))
{
trans->ivy_p += sprintf(trans->ivy_p, "%s ", name);
}

static uint8_t size_of(struct ivy_transport *trans __attribute__((unused)), uint8_t len)
{
return len;
}

static void start_message(struct ivy_transport *trans, struct device *dev __attribute__((unused)), uint8_t payload_len __attribute__((unused)))
{
trans->ivy_p = trans->ivy_buf;
}

static void end_message(struct ivy_transport *trans, struct device *dev __attribute__((unused)))
{
*(--trans->ivy_p) = '\0';
if (trans->ivy_dl_enabled) {
IvySendMsg("%s", trans->ivy_buf);
}
}

static void overrun(struct ivy_transport *trans __attribute__((unused)), struct device *dev __attribute__((unused)))
{
downlink_nb_ovrn++;
}

static void count_bytes(struct ivy_transport *trans __attribute__((unused)), struct device *dev __attribute__((unused)), uint8_t bytes)
{
downlink_nb_bytes += bytes;
}

static int check_available_space(struct ivy_transport *trans __attribute__((unused)), struct device *dev __attribute__((unused)), uint8_t bytes __attribute__((unused)))
{
return TRUE;
}

static int check_free_space(struct ivy_transport* p __attribute__((unused)), uint8_t len __attribute__((unused))) { return TRUE; }
static void transmit(struct ivy_transport* p __attribute__((unused)), uint8_t byte __attribute__((unused))) {}
static void send_message(struct ivy_transport* p __attribute__((unused))) {}

void ivy_transport_init(void)
{
ivy_tp.ivy_p = ivy_tp.ivy_buf;
ivy_tp.ivy_dl_enabled = TRUE;

ivy_tp.trans_tx.size_of = (size_of_t) size_of;
ivy_tp.trans_tx.check_available_space = (check_available_space_t) check_available_space;
ivy_tp.trans_tx.put_bytes = (put_bytes_t) put_bytes;
ivy_tp.trans_tx.put_named_byte = (put_named_byte_t) put_named_byte;
ivy_tp.trans_tx.start_message = (start_message_t) start_message;
ivy_tp.trans_tx.end_message = (end_message_t) end_message;
ivy_tp.trans_tx.overrun = (overrun_t) overrun;
ivy_tp.trans_tx.count_bytes = (count_bytes_t) count_bytes;
ivy_tp.trans_tx.impl = (void *)(&ivy_tp);
ivy_tp.device.check_free_space = (check_free_space_t) check_free_space;
ivy_tp.device.transmit = (transmit_t) transmit;
ivy_tp.device.send_message = (send_message_t) send_message;
ivy_tp.device.periph = (void *)(&ivy_tp);
}

0 comments on commit 96445e9

Please sign in to comment.