mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-15 21:53:34 +08:00
Graupner HoTT SUMD/SUMH Receiver Protocol added
This commit is contained in:
@@ -33,8 +33,10 @@
|
||||
|
||||
#
|
||||
# Yuntec ST24 transmitter protocol decoder
|
||||
# Graupnet HoTT transmitter protocol decoder
|
||||
#
|
||||
|
||||
SRCS = st24.c
|
||||
SRCS = st24.c \
|
||||
sumd.c
|
||||
|
||||
MAXOPTIMIZATION = -Os
|
||||
|
||||
@@ -0,0 +1,319 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2015 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* @file sumd.h
|
||||
*
|
||||
* RC protocol definition for Graupner HoTT transmitter
|
||||
*
|
||||
* @author Marco Bauer <marco@wtns.de>
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include "sumd.h"
|
||||
|
||||
|
||||
enum SUMD_DECODE_STATE {
|
||||
SUMD_DECODE_STATE_UNSYNCED = 0,
|
||||
SUMD_DECODE_STATE_GOT_HEADER,
|
||||
SUMD_DECODE_STATE_GOT_STATE,
|
||||
SUMD_DECODE_STATE_GOT_LEN,
|
||||
SUMD_DECODE_STATE_GOT_DATA,
|
||||
SUMD_DECODE_STATE_GOT_CRC,
|
||||
SUMD_DECODE_STATE_GOT_CRC16_BYTE_1,
|
||||
SUMD_DECODE_STATE_GOT_CRC16_BYTE_2
|
||||
};
|
||||
|
||||
/*
|
||||
const char *decode_states[] = {"UNSYNCED",
|
||||
"GOT_HEADER",
|
||||
"GOT_STATE",
|
||||
"GOT_LEN",
|
||||
"GOT_DATA",
|
||||
"GOT_CRC",
|
||||
"GOT_CRC16_BYTE_1",
|
||||
"GOT_CRC16_BYTE_2"
|
||||
};
|
||||
*/
|
||||
|
||||
uint8_t _crc8 = 0x00;
|
||||
uint16_t _crc16 = 0x0000;
|
||||
bool _sumd = true;
|
||||
bool _crcOK = false;
|
||||
bool _debug = false;
|
||||
|
||||
|
||||
/* define range mapping here, -+100% -> 1000..2000 */
|
||||
#define SUMD_RANGE_MIN 0.0f
|
||||
#define SUMD_RANGE_MAX 4096.0f
|
||||
|
||||
#define SUMD_TARGET_MIN 1000.0f
|
||||
#define SUMD_TARGET_MAX 2000.0f
|
||||
|
||||
/* pre-calculate the floating point stuff as far as possible at compile time */
|
||||
#define SUMD_SCALE_FACTOR ((SUMD_TARGET_MAX - SUMD_TARGET_MIN) / (SUMD_RANGE_MAX - SUMD_RANGE_MIN))
|
||||
#define SUMD_SCALE_OFFSET (int)(SUMD_TARGET_MIN - (SUMD_SCALE_FACTOR * SUMD_RANGE_MIN + 0.5f))
|
||||
|
||||
static enum SUMD_DECODE_STATE _decode_state = SUMD_DECODE_STATE_UNSYNCED;
|
||||
static uint8_t _rxlen;
|
||||
|
||||
static ReceiverFcPacketHoTT _rxpacket;
|
||||
|
||||
|
||||
uint16_t sumd_crc16(uint16_t crc, uint8_t value)
|
||||
{
|
||||
int i;
|
||||
crc ^= (uint16_t)value << 8;
|
||||
for (i = 0; i < 8; i++) {
|
||||
crc = (crc & 0x8000) ? (crc << 1) ^ 0x1021 : (crc << 1);
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
uint8_t sumd_crc8(uint8_t crc, uint8_t value)
|
||||
{
|
||||
crc += value;
|
||||
return crc;
|
||||
}
|
||||
|
||||
int sumd_decode(uint8_t byte, uint8_t *rssi, uint8_t *rx_count, uint16_t *channel_count, uint16_t *channels,
|
||||
uint16_t max_chan_count)
|
||||
{
|
||||
|
||||
int ret = 1;
|
||||
switch (_decode_state) {
|
||||
case SUMD_DECODE_STATE_UNSYNCED:
|
||||
if(_debug)
|
||||
printf( " SUMD_DECODE_STATE_UNSYNCED \n") ;
|
||||
|
||||
if (byte == SUMD_HEADER_ID) {
|
||||
_rxpacket.header = byte;
|
||||
_sumd = true;
|
||||
_rxlen = 0;
|
||||
_crc16 = 0x0000;
|
||||
_crc8 = 0x00;
|
||||
_crcOK = false;
|
||||
_crc16 = sumd_crc16(_crc16, byte);
|
||||
_crc8 = sumd_crc8(_crc8, byte);
|
||||
_decode_state = SUMD_DECODE_STATE_GOT_HEADER;
|
||||
if(_debug)
|
||||
printf( " SUMD_DECODE_STATE_GOT_HEADER: %x \n", byte) ;
|
||||
|
||||
} else {
|
||||
ret = 3;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case SUMD_DECODE_STATE_GOT_HEADER:
|
||||
if (byte == SUMD_ID_SUMD || byte == SUMD_ID_SUMH) {
|
||||
_rxpacket.status = byte;
|
||||
if (byte == SUMD_ID_SUMH) {
|
||||
_sumd = false;
|
||||
}
|
||||
if (_sumd) {
|
||||
_crc16 = sumd_crc16(_crc16, byte);
|
||||
} else {
|
||||
_crc8 = sumd_crc8(_crc8, byte);
|
||||
}
|
||||
_decode_state = SUMD_DECODE_STATE_GOT_STATE;
|
||||
if(_debug)
|
||||
printf( " SUMD_DECODE_STATE_GOT_STATE: %x \n", byte) ;
|
||||
|
||||
} else {
|
||||
_decode_state = SUMD_DECODE_STATE_UNSYNCED;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case SUMD_DECODE_STATE_GOT_STATE:
|
||||
if (byte >= 2 && byte <= SUMD_MAX_CHANNELS) {
|
||||
_rxpacket.length = byte;
|
||||
if (_sumd) {
|
||||
_crc16 = sumd_crc16(_crc16, byte);
|
||||
} else {
|
||||
_crc8 = sumd_crc8(_crc8, byte);
|
||||
}
|
||||
_rxlen++;
|
||||
_decode_state = SUMD_DECODE_STATE_GOT_LEN;
|
||||
if(_debug)
|
||||
printf( " SUMD_DECODE_STATE_GOT_LEN: %x (%d) \n", byte, byte) ;
|
||||
|
||||
} else {
|
||||
_decode_state = SUMD_DECODE_STATE_UNSYNCED;
|
||||
}
|
||||
break;
|
||||
|
||||
case SUMD_DECODE_STATE_GOT_LEN:
|
||||
_rxpacket.sumd_data[_rxlen] = byte;
|
||||
if (_sumd) {
|
||||
_crc16 = sumd_crc16(_crc16, byte);
|
||||
} else {
|
||||
_crc8 = sumd_crc8(_crc8, byte);
|
||||
}
|
||||
_rxlen++;
|
||||
|
||||
if (_rxlen <= ((_rxpacket.length*2) )) {
|
||||
if(_debug)
|
||||
printf( " SUMD_DECODE_STATE_GOT_DATA[%d]: %x\n", _rxlen-2, byte) ;
|
||||
|
||||
} else {
|
||||
_decode_state = SUMD_DECODE_STATE_GOT_DATA;
|
||||
if(_debug)
|
||||
printf( " SUMD_DECODE_STATE_GOT_DATA -- finish --\n") ;
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case SUMD_DECODE_STATE_GOT_DATA:
|
||||
_rxpacket.crc16_high = byte;
|
||||
if(_debug)
|
||||
printf( " SUMD_DECODE_STATE_GOT_CRC16[1]: %x [%x]\n", byte, ((_crc16 >> 8) & 0xff)) ;
|
||||
|
||||
if (_sumd) {
|
||||
_decode_state = SUMD_DECODE_STATE_GOT_CRC;
|
||||
} else {
|
||||
_decode_state = SUMD_DECODE_STATE_GOT_CRC16_BYTE_1;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case SUMD_DECODE_STATE_GOT_CRC16_BYTE_1:
|
||||
_rxpacket.crc16_low = byte;
|
||||
if(_debug)
|
||||
printf( " SUMD_DECODE_STATE_GOT_CRC16[2]: %x [%x]\n", byte, (_crc16 & 0xff)) ;
|
||||
|
||||
_decode_state = SUMD_DECODE_STATE_GOT_CRC16_BYTE_2;
|
||||
|
||||
break;
|
||||
|
||||
case SUMD_DECODE_STATE_GOT_CRC16_BYTE_2:
|
||||
_rxpacket.telemetry = byte;
|
||||
if(_debug)
|
||||
printf( " SUMD_DECODE_STATE_GOT_SUMH_TELEMETRY: %x\n", byte) ;
|
||||
|
||||
_decode_state = SUMD_DECODE_STATE_GOT_CRC;
|
||||
|
||||
break;
|
||||
|
||||
case SUMD_DECODE_STATE_GOT_CRC:
|
||||
if (_sumd) {
|
||||
_rxpacket.crc16_low = byte;
|
||||
if(_debug)
|
||||
printf( " SUMD_DECODE_STATE_GOT_CRC[2]: %x [%x]\n\n", byte, (_crc16 & 0xff)) ;
|
||||
|
||||
if (_crc16 == (uint16_t)(_rxpacket.crc16_high<<8)+_rxpacket.crc16_low) {
|
||||
_crcOK = true;
|
||||
}
|
||||
} else {
|
||||
_rxpacket.crc8 = byte;
|
||||
if(_debug)
|
||||
printf( " SUMD_DECODE_STATE_GOT_CRC8_SUMH: %x [%x]\n\n", byte, _crc8) ;
|
||||
|
||||
if (_crc8 == _rxpacket.crc8) {
|
||||
_crcOK = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (_crcOK) {
|
||||
if(_debug)
|
||||
printf( " CRC - OK \n") ;
|
||||
|
||||
if (_sumd) {
|
||||
if(_debug)
|
||||
printf( " Got valid SUMD Packet\n") ;
|
||||
|
||||
} else {
|
||||
if(_debug)
|
||||
printf( " Got valid SUMH Packet\n") ;
|
||||
|
||||
}
|
||||
|
||||
if(_debug)
|
||||
printf( " RXLEN: %d [Chans: %d] \n\n", _rxlen-1, (_rxlen-1)/2) ;
|
||||
|
||||
ret = 0;
|
||||
unsigned i;
|
||||
uint8_t _cnt = *rx_count + 1;
|
||||
*rx_count = _cnt;
|
||||
|
||||
*rssi = 255;
|
||||
|
||||
/* received Channels */
|
||||
if ((uint16_t)_rxpacket.length > max_chan_count) {
|
||||
_rxpacket.length = (uint8_t) max_chan_count;
|
||||
}
|
||||
*channel_count = (uint16_t)_rxpacket.length;
|
||||
|
||||
/* decode the actual packet */
|
||||
/* reorder first 4 channels */
|
||||
|
||||
/* ch1 = roll -> sumd = ch2 */
|
||||
channels[0] = (uint16_t)((_rxpacket.sumd_data[1*2+1]<<8) | _rxpacket.sumd_data[1*2+2])>>3;
|
||||
/* ch2 = pitch -> sumd = ch2 */
|
||||
channels[1] = (uint16_t)((_rxpacket.sumd_data[2*2+1]<<8) | _rxpacket.sumd_data[2*2+2])>>3;
|
||||
/* ch3 = throttle -> sumd = ch2 */
|
||||
channels[2] = (uint16_t)((_rxpacket.sumd_data[0*2+1]<<8) | _rxpacket.sumd_data[0*2+2])>>3;
|
||||
/* ch4 = yaw -> sumd = ch2 */
|
||||
channels[3] = (uint16_t)((_rxpacket.sumd_data[3*2+1]<<8) | _rxpacket.sumd_data[3*2+2])>>3;
|
||||
|
||||
/* we start at channel 5(index 4) */
|
||||
unsigned chan_index = 4;
|
||||
|
||||
for (i = 4; i < _rxpacket.length; i++) {
|
||||
if(_debug)
|
||||
printf( "ch[%d] : %x %x [ %x %d ]\n", i+1, _rxpacket.sumd_data[i*2+1], _rxpacket.sumd_data[i*2+2], ((_rxpacket.sumd_data[i*2+1]<<8) | _rxpacket.sumd_data[i*2+2])>>3, ((_rxpacket.sumd_data[i*2+1]<<8) | _rxpacket.sumd_data[i*2+2])>>3);
|
||||
|
||||
channels[chan_index] = (uint16_t)((_rxpacket.sumd_data[i*2+1]<<8) | _rxpacket.sumd_data[i*2+2])>>3;
|
||||
/* convert values to 1000-2000 ppm encoding in a not too sloppy fashion */
|
||||
//channels[chan_index] = (uint16_t)(channels[chan_index] * SUMD_SCALE_FACTOR + .5f) + SUMD_SCALE_OFFSET;
|
||||
|
||||
chan_index++;
|
||||
}
|
||||
|
||||
} else {
|
||||
/* decoding failed */
|
||||
ret = 4;
|
||||
if(_debug)
|
||||
printf( " CRC - fail \n") ;
|
||||
|
||||
}
|
||||
|
||||
_decode_state = SUMD_DECODE_STATE_UNSYNCED;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2015 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file sumd.h
|
||||
*
|
||||
* RC protocol definition for Graupner HoTT transmitter
|
||||
*
|
||||
* @author Marco Bauer <marco@wtns.de>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#define SUMD_MAX_CHANNELS 32
|
||||
#define SUMD_HEADER_LENGTH 3
|
||||
#define SUMD_HEADER_ID 0xA8
|
||||
#define SUMD_ID_SUMH 0x00
|
||||
#define SUMD_ID_SUMD 0x01
|
||||
#define SUMD_ID_FAILSAFE 0x81
|
||||
|
||||
|
||||
|
||||
|
||||
#pragma pack(push, 1)
|
||||
typedef struct {
|
||||
uint8_t header; ///< 0xA8 for a valid packet
|
||||
uint8_t status; ///< 0x01 valid and live SUMD data frame / 0x00 = SUMH / 0x81 = Failsafe
|
||||
uint8_t length; ///< Channels
|
||||
uint8_t sumd_data[SUMD_MAX_CHANNELS*2]; ///< ChannelData (High Byte/ Low Byte)
|
||||
uint8_t crc16_high; ///< High Byte of 16 Bit CRC
|
||||
uint8_t crc16_low; ///< Low Byte of 16 Bit CRC
|
||||
uint8_t telemetry; ///< Telemetry request
|
||||
uint8_t crc8; ///< SUMH CRC8
|
||||
} ReceiverFcPacketHoTT;
|
||||
#pragma pack(pop)
|
||||
|
||||
|
||||
/**
|
||||
* CRC16 implementation for SUMD protocol
|
||||
*
|
||||
* @param crc Initial CRC Value
|
||||
* @param value to accumulate in the checksum
|
||||
* @return the checksum
|
||||
*/
|
||||
uint16_t sumd_crc16(uint16_t crc, uint8_t value);
|
||||
|
||||
/**
|
||||
* CRC8 implementation for SUMH protocol
|
||||
*
|
||||
* @param crc Initial CRC Value
|
||||
* @param value to accumulate in the checksum
|
||||
* @return the checksum
|
||||
*/
|
||||
uint8_t sumd_crc8(uint8_t crc, uint8_t value);
|
||||
|
||||
/**
|
||||
* Decoder for SUMD/SUMH protocol
|
||||
*
|
||||
* @param byte current char to read
|
||||
* @param rssi pointer to a byte where the RSSI value is written back to
|
||||
* @param rx_count pointer to a byte where the receive count of packets signce last wireless frame is written back to
|
||||
* @param channels pointer to a datastructure of size max_chan_count where channel values (12 bit) are written back to
|
||||
* @param max_chan_count maximum channels to decode - if more channels are decoded, the last n are skipped and success (0) is returned
|
||||
* @return 0 for success (a decoded packet), 1 for no packet yet (accumulating), 2 for unknown packet, 3 for out of sync, 4 for checksum error
|
||||
*/
|
||||
/*
|
||||
__EXPORT int sumd_decode(uint8_t byte, uint8_t *rssi, uint8_t *rx_count, uint16_t *channel_count,
|
||||
uint16_t *channels, uint16_t max_chan_count);
|
||||
*/
|
||||
int sumd_decode(uint8_t byte, uint8_t *rssi, uint8_t *rx_count, uint16_t *channel_count,
|
||||
uint16_t *channels, uint16_t max_chan_count);
|
||||
|
||||
|
||||
__END_DECLS
|
||||
@@ -45,6 +45,7 @@
|
||||
#include <systemlib/perf_counter.h>
|
||||
#include <systemlib/ppm_decode.h>
|
||||
#include <rc/st24.h>
|
||||
#include <rc/sumd.h>
|
||||
|
||||
#include "px4io.h"
|
||||
|
||||
@@ -53,7 +54,7 @@
|
||||
#define RC_CHANNEL_LOW_THRESH -8000 /* 10% threshold */
|
||||
|
||||
static bool ppm_input(uint16_t *values, uint16_t *num_values, uint16_t *frame_len);
|
||||
static bool dsm_port_input(uint16_t *rssi, bool *dsm_updated, bool *st24_updated);
|
||||
static bool dsm_port_input(uint16_t *rssi, bool *dsm_updated, bool *st24_updated, bool *sumd_updated);
|
||||
|
||||
static perf_counter_t c_gather_dsm;
|
||||
static perf_counter_t c_gather_sbus;
|
||||
@@ -63,7 +64,7 @@ static int _dsm_fd;
|
||||
|
||||
static uint16_t rc_value_override = 0;
|
||||
|
||||
bool dsm_port_input(uint16_t *rssi, bool *dsm_updated, bool *st24_updated)
|
||||
bool dsm_port_input(uint16_t *rssi, bool *dsm_updated, bool *st24_updated, bool *sumd_updated)
|
||||
{
|
||||
perf_begin(c_gather_dsm);
|
||||
uint16_t temp_count = r_raw_rc_count;
|
||||
@@ -106,7 +107,31 @@ bool dsm_port_input(uint16_t *rssi, bool *dsm_updated, bool *st24_updated)
|
||||
r_raw_rc_flags &= ~(PX4IO_P_RAW_RC_FLAGS_FAILSAFE);
|
||||
}
|
||||
|
||||
return (*dsm_updated | *st24_updated);
|
||||
|
||||
/* get data from FD and attempt to parse with SUMD libs */
|
||||
uint8_t sumd_rssi, sumd_rx_count;
|
||||
uint16_t sumd_channel_count = 0;
|
||||
|
||||
*sumd_updated = false;
|
||||
|
||||
for (unsigned i = 0; i < n_bytes; i++) {
|
||||
/* set updated flag if one complete packet was parsed */
|
||||
st24_rssi = RC_INPUT_RSSI_MAX;
|
||||
*sumd_updated |= (OK == sumd_decode(bytes[i], &sumd_rssi, &sumd_rx_count,
|
||||
&sumd_channel_count, r_raw_rc_values, PX4IO_RC_INPUT_CHANNELS));
|
||||
}
|
||||
|
||||
if (*sumd_updated) {
|
||||
|
||||
*rssi = sumd_rssi;
|
||||
r_raw_rc_count = sumd_channel_count;
|
||||
|
||||
r_status_flags |= PX4IO_P_STATUS_FLAGS_RC_SUMD;
|
||||
r_raw_rc_flags &= ~(PX4IO_P_RAW_RC_FLAGS_FRAME_DROP);
|
||||
r_raw_rc_flags &= ~(PX4IO_P_RAW_RC_FLAGS_FAILSAFE);
|
||||
}
|
||||
|
||||
return (*dsm_updated | *st24_updated | *sumd_updated);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -169,14 +194,17 @@ controls_tick() {
|
||||
#endif
|
||||
|
||||
perf_begin(c_gather_dsm);
|
||||
bool dsm_updated, st24_updated;
|
||||
(void)dsm_port_input(&rssi, &dsm_updated, &st24_updated);
|
||||
bool dsm_updated, st24_updated, sumd_updated;
|
||||
(void)dsm_port_input(&rssi, &dsm_updated, &st24_updated, &sumd_updated);
|
||||
if (dsm_updated) {
|
||||
r_status_flags |= PX4IO_P_STATUS_FLAGS_RC_DSM;
|
||||
}
|
||||
if (st24_updated) {
|
||||
r_status_flags |= PX4IO_P_STATUS_FLAGS_RC_ST24;
|
||||
}
|
||||
if (sumd_updated) {
|
||||
r_status_flags |= PX4IO_P_STATUS_FLAGS_RC_SUMD;
|
||||
}
|
||||
perf_end(c_gather_dsm);
|
||||
|
||||
perf_begin(c_gather_sbus);
|
||||
@@ -238,7 +266,7 @@ controls_tick() {
|
||||
/*
|
||||
* If we received a new frame from any of the RC sources, process it.
|
||||
*/
|
||||
if (dsm_updated || sbus_updated || ppm_updated || st24_updated) {
|
||||
if (dsm_updated || sbus_updated || ppm_updated || st24_updated || sumd_updated) {
|
||||
|
||||
/* record a bitmask of channels assigned */
|
||||
unsigned assigned_channels = 0;
|
||||
@@ -438,7 +466,7 @@ controls_tick() {
|
||||
r_status_flags |= PX4IO_P_STATUS_FLAGS_OVERRIDE;
|
||||
|
||||
/* mix new RC input control values to servos */
|
||||
if (dsm_updated || sbus_updated || ppm_updated || st24_updated)
|
||||
if (dsm_updated || sbus_updated || ppm_updated || st24_updated || sumd_updated)
|
||||
mixer_tick();
|
||||
|
||||
} else {
|
||||
|
||||
@@ -14,7 +14,8 @@ SRCS = adc.c \
|
||||
../systemlib/mixer/mixer_multirotor.cpp \
|
||||
../systemlib/mixer/mixer_simple.cpp \
|
||||
../systemlib/pwm_limit/pwm_limit.c \
|
||||
../../lib/rc/st24.c
|
||||
../../lib/rc/st24.c \
|
||||
../../lib/rc/sumd.c
|
||||
|
||||
ifeq ($(BOARD),px4io-v1)
|
||||
SRCS += i2c.c
|
||||
|
||||
@@ -115,6 +115,7 @@
|
||||
#define PX4IO_P_STATUS_FLAGS_SAFETY_OFF (1 << 12) /* safety is off */
|
||||
#define PX4IO_P_STATUS_FLAGS_FMU_INITIALIZED (1 << 13) /* FMU was initialized and OK once */
|
||||
#define PX4IO_P_STATUS_FLAGS_RC_ST24 (1 << 14) /* ST24 input is valid */
|
||||
#define PX4IO_P_STATUS_FLAGS_RC_SUMD (1 << 15) /* SUMD input is valid */
|
||||
|
||||
#define PX4IO_P_STATUS_ALARMS 3 /* alarm flags - alarms latch, write 1 to a bit to clear it */
|
||||
#define PX4IO_P_STATUS_ALARMS_VBATT_LOW (1 << 0) /* [1] VBatt is very close to regulator dropout */
|
||||
|
||||
@@ -75,6 +75,10 @@ add_gtest(sbus2_test)
|
||||
add_executable(st24_test st24_test.cpp hrt.cpp ${PX_SRC}/lib/rc/st24.c)
|
||||
add_gtest(st24_test)
|
||||
|
||||
# sumd_test
|
||||
add_executable(sumd_test sumd_test.cpp hrt.cpp ${PX_SRC}/lib/rc/sumd.c)
|
||||
add_gtest(sumd_test)
|
||||
|
||||
# sf0x_test
|
||||
add_executable(sf0x_test sf0x_test.cpp ${PX_SRC}/drivers/sf0x/sf0x_parser.cpp)
|
||||
add_gtest(sf0x_test)
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <systemlib/err.h>
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include <rc/sumd.h>
|
||||
#include "../../src/systemcmds/tests/tests.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
TEST(SUMDTest, SUMD) {
|
||||
const char* filepath = "testdata/sumd_data.txt";
|
||||
|
||||
warnx("loading data from: %s", filepath);
|
||||
|
||||
FILE *fp;
|
||||
|
||||
fp = fopen(filepath, "rt");
|
||||
//ASSERT_TRUE(fp);
|
||||
|
||||
float f;
|
||||
unsigned x;
|
||||
int ret;
|
||||
|
||||
// Trash the first 20 lines
|
||||
for (unsigned i = 0; i < 20; i++) {
|
||||
char buf[200];
|
||||
(void)fgets(buf, sizeof(buf), fp);
|
||||
}
|
||||
|
||||
float last_time = 0;
|
||||
|
||||
while (EOF != (ret = fscanf(fp, "%f,%x,,", &f, &x))) {
|
||||
if (((f - last_time) * 1000 * 1000) > 3000) {
|
||||
// warnx("FRAME RESET\n\n");
|
||||
}
|
||||
|
||||
uint8_t b = static_cast<uint8_t>(x);
|
||||
|
||||
last_time = f;
|
||||
|
||||
// Pipe the data into the parser
|
||||
hrt_abstime now = hrt_absolute_time();
|
||||
|
||||
uint8_t rssi;
|
||||
uint8_t rx_count;
|
||||
uint16_t channel_count;
|
||||
uint16_t channels[32];
|
||||
|
||||
|
||||
if (!sumd_decode(b, &rssi, &rx_count, &channel_count, channels, 32)) {
|
||||
//warnx("decoded: %u channels (converted to PPM range)", (unsigned)channel_count);
|
||||
|
||||
for (unsigned i = 0; i < channel_count; i++) {
|
||||
|
||||
int16_t val = channels[i];
|
||||
//warnx("channel %u: %d 0x%03X", i, static_cast<int>(val), static_cast<int>(val));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ASSERT_EQ(EOF, ret);
|
||||
}
|
||||
Vendored
+14472
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user