Skip to content

Commit

Permalink
Add Aeroprobe On-The-Fly! air data computer interface
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmm committed Mar 11, 2013
1 parent 5a301aa commit b6e2d66
Show file tree
Hide file tree
Showing 5 changed files with 271 additions and 1 deletion.
9 changes: 8 additions & 1 deletion conf/messages.xml
Expand Up @@ -1495,7 +1495,14 @@
</message>


<!--179 is free -->
<message name="FLOW_AP_OTF" id="179">
<field name="counter" type="uint32"/>
<field name="velocity" type="int16" unit="cm/s" alt_unit="m/s"/>
<field name="a_attack" type="int16" unit="centideg" alt_unit="deg"/>
<field name="a_sidesl" type="int16" unit="centideg" alt_unit="deg"/>
<field name="altitude" type="int32" unit="cm" alt_unit="m"/>
<field name="checksum" type="uint8"/>
</message>

<message name="FMS_TIME" id="180">
<field name="tv_sec" type="uint32"/>
Expand Down
20 changes: 20 additions & 0 deletions conf/modules/airspeed_otf.xml
@@ -0,0 +1,20 @@
<!DOCTYPE module SYSTEM "module.dtd">

<module name="airspeed_otf" dir="sensors">
<doc>
<description></description>

This comment has been minimized.

Copy link
@flixr

flixr Mar 12, 2013

Member

Could you please add the description here?
The first line will be the tiltle of the generated module page, the rest the detailed description: http://paparazzi.github.com/docs/latest/module__airspeed_otf.html
And also document the configure options...
For consistency it might also be nicer to configure the UARTx and not just the number x, like we have for modem, gps, etc.
module example: http://paparazzi.github.com/docs/latest/module__mavlink_decoder.html

</doc>
<header>
<file name="met_module.h"/>
<file name="airspeed_otf.h"/>
</header>
<init fun="airspeed_otf_init()"/>
<periodic fun="airspeed_otf_periodic()" freq="1"/>
<event fun="airspeed_otf_event()"/>
<makefile target="ap">
<file name="airspeed_otf.c"/>
<define name="USE_UART$(OTF_UART_NR)"/>
<define name="MET_LINK" value="Uart$(OTF_UART_NR)"/>
<define name="UART$(OTF_UART_NR)_BAUD" value="B115200"/>
</makefile>
</module>
162 changes: 162 additions & 0 deletions sw/airborne/modules/sensors/airspeed_otf.c
@@ -0,0 +1,162 @@
/*
* Copyright (C) 2013 Martin Mueller <martinmm@pfump.org>
*
* 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, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/

/** \file met_ap_otf.c
* \brief UART interface for Aeroprobe On-The-Fly! air data computer
*
*/

#include <stdbool.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "mcu_periph/uart.h"
#include "messages.h"
#include "subsystems/datalink/downlink.h"

#include "met_module.h"
#include "airspeed_otf.h"

#ifndef DOWNLINK_DEVICE
#define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
#endif

#define OTF_UNINIT 0x00
#define OTF_WAIT_START OTF_UNINIT
#define OTF_WAIT_COUNTER 0x01
#define OTF_WAIT_ANGLES 0x02
#define OTF_WAIT_ALTITUDE 0x03
#define OTF_WAIT_CHECKSUM 0x04

#define OTF_START 0x0A
#define OTF_LIMITER ','
#define OTF_END 0x0D

/* workaround for newlib */
void* _sbrk(int);
void* _sbrk(int a) {return 0;}

/* airspeed_otf_parse */
void airspeed_otf_parse(char c)
{
static unsigned char otf_status = OTF_UNINIT, otf_idx = 0, otf_crs_idx;
static char otf_inp[64];
static unsigned int counter;
static short course[3];
static unsigned int altitude;
static unsigned char checksum;

switch (otf_status) {

case OTF_WAIT_START:
if (c == OTF_START) {
otf_status++;
otf_idx = 0;
} else {
otf_status = OTF_UNINIT;
}
break;

case OTF_WAIT_COUNTER:
if (isdigit((int)c)) {
if (otf_idx == 0) {
//FIXME otf_timestamp = getclock();
}
otf_inp[otf_idx++] = c;
} else {
if ((otf_idx == 5) && (c == OTF_LIMITER)) {
otf_inp[otf_idx] = 0;
counter = atoi(otf_inp);
otf_idx = 0;
otf_crs_idx = 0;
otf_status++;
} else {
otf_status = OTF_UNINIT;
}
}
break;

case OTF_WAIT_ANGLES:
if (isdigit((int)c) || (c == '-') || (c == '.')) {
otf_inp[otf_idx++] = c;
} else {
if ((otf_idx > 1) && (otf_idx < 9) && (c == OTF_LIMITER)) {
otf_inp[otf_idx] = 0;
course[otf_crs_idx] = (int16_t) (100. * atof(otf_inp));
otf_idx = 0;
if (otf_crs_idx++ == 2) {
otf_status++;
}
} else {
otf_status = OTF_UNINIT;
}
}
break;

case OTF_WAIT_ALTITUDE:
if (isdigit((int)c) || (c == '-') || (c == '.')) {
otf_inp[otf_idx++] = c;
} else {
if ((otf_idx > 1) && (otf_idx < 9) && (c == OTF_LIMITER)) {
otf_inp[otf_idx] = 0;
altitude = (int32_t) (100. * atof(otf_inp));
otf_idx = 0;
otf_status++;
} else {
otf_status = OTF_UNINIT;
}
}
break;

case OTF_WAIT_CHECKSUM:
if (isxdigit((int)c)) {
otf_inp[otf_idx++] = c;
} else {
if ((otf_idx == 2) && (c == OTF_END)) {
otf_inp[otf_idx] = 0;
checksum = strtol(otf_inp, NULL, 16);
otf_idx = 0;
DOWNLINK_SEND_FLOW_AP_OTF(DefaultChannel, DefaultDevice, &counter, &course[0], &course[1], &course[2], &altitude, &checksum);
}
otf_status = OTF_UNINIT;
}
break;

default:
otf_status = OTF_UNINIT;
break;
}
}

void airspeed_otf_init(void) {
}

void airspeed_otf_event(void) {
while (MetLink(ChAvailable())) {
uint8_t ch = MetLink(Getch());
airspeed_otf_parse(ch);
}
}

void airspeed_otf_periodic(void) {
}
11 changes: 11 additions & 0 deletions sw/airborne/modules/sensors/airspeed_otf.h
@@ -0,0 +1,11 @@
#ifndef AIRSPEED_OTF_H
#define AIRSPEED_OTF_H

#include "std.h"

void airspeed_otf_parse(char c);
void airspeed_otf_init(void);
void airspeed_otf_event(void);
void airspeed_otf_periodic(void);

#endif
70 changes: 70 additions & 0 deletions sw/airborne/modules/sensors/met_module.h
@@ -0,0 +1,70 @@
/*
* $Id$
*
* Copyright (C) 2003 Pascal Brisset, Antoine Drouin
*
* 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, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/

/** \file met_module.h
* \brief Device independent serial meteo code
*
*/


#ifndef MET_H
#define MET_H

#include "std.h"
#include "led.h"

extern volatile uint8_t ins_msg_received;
extern volatile uint8_t new_ins_attitude;

This comment has been minimized.

Copy link
@flixr

flixr Mar 12, 2013

Member

What is all this ins stuff doing in here?


#ifndef SITL
#include "mcu_periph/uart.h"

#define __MetLink(dev, _x) dev##_x
#define _MetLink(dev, _x) __MetLink(dev, _x)
#define MetLink(_x) _MetLink(MET_LINK, _x)

#define MetBuffer() MetLink(ChAvailable())
#define ReadMetBuffer() { while (MetLink(ChAvailable())&&!met_msg_received) parse_met_buffer(MetLink(Getch())); }
#define MetSend1(c) MetLink(Transmit(c))
#define MetUartSend1(c) MetSend1(c)
#define MetSend(_dat,_len) { for (uint8_t i = 0; i< (_len); i++) MetSend1(_dat[i]); };
#define MetUartSetBaudrate(_b) MetLink(SetBaudrate(_b))
#define MetUartRunning MetLink(TxRunning)

#endif /** !SITL */

#define InsEventCheckAndHandle(handler) { \
if (InsBuffer()) { \
ReadInsBuffer(); \
} \
if (ins_msg_received) { \
LED_TOGGLE(2); \
parse_ins_msg(); \
handler; \
ins_msg_received = FALSE; \
} \
}


#endif /* MET_H */

0 comments on commit b6e2d66

Please sign in to comment.