[telemetry] fbw datalink using generic device

This commit is contained in:
Gautier Hattenberger
2015-03-16 21:59:55 +01:00
parent 33247a0f8a
commit 7c22708ca7
2 changed files with 16 additions and 29 deletions
@@ -1,5 +1,8 @@
FBW_MODEM_PORT_LOWER=$(shell echo $(MODEM_PORT) | tr A-Z a-z)
FBW_AP_PORT_LOWER=$(shell echo $(AUTOPILOT_PORT) | tr A-Z a-z)
fbw.srcs += firmwares/fixedwing/fbw_datalink.c
fbw.CFLAGS += -DFBW_DATALINK
fbw.CFLAGS += -DMODEM_LINK=$(MODEM_PORT) -DUSE_$(MODEM_PORT) -D$(MODEM_PORT)_BAUD=$(MODEM_BAUD)
fbw.CFLAGS += -DAUTOPILOT_LINK=$(AUTOPILOT_PORT) -DUSE_$(AUTOPILOT_PORT) -D$(AUTOPILOT_PORT)_BAUD=$(MODEM_BAUD)
fbw.CFLAGS += -DMODEM_LINK=$(FBW_MODEM_PORT_LOWER) -DUSE_$(MODEM_PORT) -D$(MODEM_PORT)_BAUD=$(MODEM_BAUD)
fbw.CFLAGS += -DAUTOPILOT_LINK=$(FBW_AP_PORT_LOWER) -DUSE_$(AUTOPILOT_PORT) -D$(AUTOPILOT_PORT)_BAUD=$(MODEM_BAUD)
+11 -27
View File
@@ -31,38 +31,19 @@
#include "led.h"
#define __ModemLink(dev, _x) dev##_x
#define _ModemLink(dev, _x) __ModemLink(dev, _x)
#define ModemLink(_x) _ModemLink(MODEM_LINK, _x)
#define ModemBuffer() ModemLink(ChAvailable())
#define __AutopilotLink(dev, _x) dev##_x
#define _AutopilotLink(dev, _x) __AutopilotLink(dev, _x)
#define AutopilotLink(_x) _AutopilotLink(AUTOPILOT_LINK, _x)
#define AutopilotBuffer() AutopilotLink(ChAvailable())
#define ModemLinkDevice (&(MODEM_LINK).device)
#define AutopilotLinkDevice (&(AUTOPILOT_LINK).device)
static inline void autopilot_parse(char c)
{
ModemLink(Transmit(c));
ModemLinkDevice->transmit(ModemLinkDevice->periph, c);
}
static inline void modem_parse(char c)
{
AutopilotLink(Transmit(c));
AutopilotLinkDevice->transmit(AutopilotLinkDevice->periph, c);
}
#define ReadAutopilotBuffer() { \
while (AutopilotLink(ChAvailable())) \
autopilot_parse(AutopilotLink(Getch())); \
}
#define ReadModemBuffer() { \
while (ModemLink(ChAvailable())) \
modem_parse(ModemLink(Getch())); \
}
void fbw_datalink_periodic(void)
{
#ifdef MODEM_LINK_LED
@@ -76,16 +57,19 @@ void fbw_datalink_periodic(void)
void fbw_datalink_event(void)
{
#ifdef MODEM_LINK_LED
if (ModemLink(ChAvailable())) {
if (ModemLinkDevice->char_available(ModemLinkDevice->periph)) {
LED_ON(MODEM_LINK_LED);
}
#endif
#ifdef AUTOPILOT_LINK_LED
if (AutopilotLink(ChAvailable())) {
if (AutopilotLinkDevice->char_available(AutopilotLinkDevice->periph)) {
LED_ON(AUTOPILOT_LINK_LED);
}
#endif
ReadModemBuffer();
ReadAutopilotBuffer();
while (ModemLinkDevice->char_available(ModemLinkDevice->periph))
modem_parse(ModemLinkDevice->getchar(ModemLinkDevice->periph));
while (AutopilotLinkDevice->char_available(AutopilotLinkDevice->periph))
autopilot_parse(AutopilotLinkDevice->getchar(AutopilotLinkDevice->periph));
}