30 #include "pprzlink/intermcu_msg.h"
41 #include "libopencm3/cm3/scb.h"
44 static uint8_t px4RebootSequence[] = {0x41, 0xd7, 0x32, 0x0a, 0x46, 0x39};
45 static uint8_t px4RebootSequenceCount = 0;
49 #if RADIO_CONTROL_NB_CHANNEL > 8
50 #undef RADIO_CONTROL_NB_CHANNEL
51 #define RADIO_CONTROL_NB_CHANNEL 8
52 INFO(
"InterMCU UART will only send 8 radio channels!")
68 static void checkPx4RebootCommand(
unsigned char b);
74 #define IMCU_GPS_ID GPS_MULTI_ID
117 #ifdef RADIO_KILL_SWITCH
122 #ifdef RADIO_KILL_SWITCH
123 #warning "RC AUX1 and KILL_SWITCH are on the same channel. AUX1 is discarded."
135 pprz_msg_send_IMCU_RADIO_COMMANDS(&(intermcu.
transport.trans_tx), intermcu.
device,
147 #pragma GCC diagnostic ignored "-Wcast-align"
152 #if PPRZLINK_DEFAULT_VER == 2
154 if (pprzlink_get_msg_class_id(
imcu_msg_buf) == DL_intermcu_CLASS_ID) {
157 case DL_IMCU_COMMANDS: {
167 for (i = 0; i < size; i++) {
168 intermcu_commands[i] = new_commands[i];
173 commands_frame_handler();
176 #if defined(TELEMETRY_INTERMCU_DEV)
177 case DL_IMCU_TELEMETRY: {
184 #if defined(SPEKTRUM_HAS_SOFT_BIND_PIN) //TODO: make subscribable module parser
185 case DL_IMCU_SPEKTRUM_SOFT_BIND:
193 #if PPRZLINK_DEFAULT_VER == 2
197 #pragma GCC diagnostic pop
204 if (intermcu.
device->char_available(intermcu.
device->periph)) {
205 while (intermcu.
device->char_available(intermcu.
device->periph) && !intermcu.
transport.trans_rx.msg_received) {
211 checkPx4RebootCommand(c);
216 if (intermcu.
transport.trans_rx.msg_received) {
217 for (i = 0; i < intermcu.
transport.trans_rx.payload_len; i++) {
222 intermcu.
transport.trans_rx.msg_received =
false;
234 uint32_t stamp __attribute__((unused)),
256 static void checkPx4RebootCommand(
uint8_t b)
262 }
else if (intermcu.stable_px4_baud ==
PX4_BAUD) {
281 if (b == px4RebootSequence[px4RebootSequenceCount]) {
282 px4RebootSequenceCount++;
284 px4RebootSequenceCount = 0;
287 if (px4RebootSequenceCount >= 6) {
288 px4RebootSequenceCount = 0;
292 intermcu.
device->put_byte(intermcu.
device->periph, 0, 0x00);
293 intermcu.
device->put_byte(intermcu.
device->periph, 0, 0xe5);
294 intermcu.
device->put_byte(intermcu.
device->periph, 0, 0x32);
295 intermcu.
device->put_byte(intermcu.
device->periph, 0, 0x0a);
struct intermcu_t intermcu
Event structure to store callbacks in a linked list.
void intermcu_send_status(uint8_t mode)
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
void uart_periph_set_baudrate(struct uart_periph *p, uint32_t baud)
Set baudrate.
#define INTERMCU_LOST_CNT
uint8_t imcu_msg_buf[128]
The InterMCU message buffer.
void InterMcuEvent(void(*frame_handler)(void))
uint32_t pacc
position accuracy in cm
static void intermcu_parse_msg(void(*commands_frame_handler)(void))
struct link_device * device
Device used for communication.
#define INTERMCU_RADIO_AUX3
pprz_t intermcu_commands[COMMANDS_NB]
uint8_t cmd_status
Command status information that is transfered (intermcu_cmd_status)
void telemetry_intermcu_on_msg(uint8_t *msg, uint8_t size)
Telemetry through InterMCU.
void sys_time_cancel_timer(tid_t id)
Cancel a system timer by id.
Main include for ABI (AirBorneInterface).
enum intermcu_status status
Status of the INTERMCU.
float vsupply
supply voltage in V
InterMCU communication is OK.
#define INTERMCU_RADIO_PITCH
#define INTERMCU_RADIO_MODE
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
bool msg_available
If we have an InterMCU message.
int32_t alt
in millimeters above WGS84 reference ellipsoid
uint32_t sacc
speed accuracy in cm/s
Rotorcraft Inter-MCU on FlyByWire.
#define RADIO_CONTROL_NB_CHANNEL
bool enabled
If the InterMCU communication is enabled.
#define INTERMCU_RADIO_ROLL
No interMCU communication anymore.
#define INTERMCU_RADIO_AUX1
int32_t hmsl
height above mean sea level (MSL) in mm
Interface for electrical status: supply voltage, current, battery status, etc.
Architecture independent timing functions.
data structure for GPS information
The status of autopilot_motors_on.
#define INTERMCU_RADIO_YAW
Device independent GPS code (interface)
#define INTERMCU_GET_CMD_STATUS(_bit)
struct EcefCoor_i ecef_pos
position in ECEF in cm
int8_t tid_t
sys_time timer id type
struct RadioControl radio_control
struct pprz_transport transport
Transport over communication line (PPRZ)
void intermcu_on_rc_frame(uint8_t fbw_mode)
#define INTERMCU_RADIO_KILL_SWITCH
#define INTERMCU_RADIO_THROTTLE
static void gps_cb(uint8_t sender_id, uint32_t stamp, struct GpsState *gps_s)
#define INTERMCU_CLR_CMD_STATUS(_bit)
#define INTERMCU_RADIO_AUX2
void received_spektrum_soft_bind(void)
int32_t course
GPS course over ground in rad*1e7, [0, 2*Pi]*1e7 (CW/north)
uint8_t time_since_last_frame
Time since last frame.
static uint8_t mode
mode holds the current sonar mode mode = 0 used at high altitude, uses 16 wave patterns mode = 1 used...
static bool sys_time_check_and_ack_timer(tid_t id)
Check if timer has elapsed.
uint8_t num_sv
number of sat in fix
arch independent LED (Light Emitting Diodes) API
uint16_t gspeed
norm of 2d ground speed in cm/s
struct EcefCoor_i ecef_vel
speed ECEF in cm/s
struct Electrical electrical
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
#define RADIO_KILL_SWITCH
float current
current in A
uint8_t msg[10]
Buffer used for general comunication over SPI (out buffer)
void intermcu_periodic(void)
tid_t sys_time_register_timer(float duration, sys_time_cb cb)
Register a new system timer.