PX4 Firmware
PX4 Autopilot Software http://px4.io
sumd.cpp File Reference
#include <stdbool.h>
#include <stdio.h>
#include "sumd.h"
#include "common_rc.h"
Include dependency graph for sumd.cpp:

Go to the source code of this file.

Macros

#define SUMD_RANGE_MIN   0.0f
 
#define SUMD_RANGE_MAX   4096.0f
 
#define SUMD_TARGET_MIN   1000.0f
 
#define SUMD_TARGET_MAX   2000.0f
 
#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))
 

Enumerations

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
}
 

Functions

uint16_t sumd_crc16 (uint16_t crc, uint8_t value)
 CRC16 implementation for SUMD protocol. More...
 
uint8_t sumd_crc8 (uint8_t crc, uint8_t value)
 CRC8 implementation for SUMH protocol. More...
 
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, bool *failsafe)
 Decoder for SUMD/SUMH protocol. More...
 

Variables

uint8_t _crc8 = 0x00
 
uint16_t _crc16 = 0x0000
 
bool _sumd = true
 
bool _crcOK = false
 
bool _debug = false
 
static enum SUMD_DECODE_STATE _decode_state = SUMD_DECODE_STATE_UNSYNCED
 
static uint8_t _rxlen
 
static ReceiverFcPacketHoTT_rxpacket = rc_decode_buf._hottrxpacket
 

Macro Definition Documentation

◆ SUMD_RANGE_MAX

#define SUMD_RANGE_MAX   4096.0f

Definition at line 79 of file sumd.cpp.

◆ SUMD_RANGE_MIN

#define SUMD_RANGE_MIN   0.0f

Definition at line 78 of file sumd.cpp.

◆ SUMD_SCALE_FACTOR

#define SUMD_SCALE_FACTOR   ((SUMD_TARGET_MAX - SUMD_TARGET_MIN) / (SUMD_RANGE_MAX - SUMD_RANGE_MIN))

Definition at line 85 of file sumd.cpp.

◆ SUMD_SCALE_OFFSET

#define SUMD_SCALE_OFFSET   (int)(SUMD_TARGET_MIN - (SUMD_SCALE_FACTOR * SUMD_RANGE_MIN + 0.5f))

Definition at line 86 of file sumd.cpp.

◆ SUMD_TARGET_MAX

#define SUMD_TARGET_MAX   2000.0f

Definition at line 82 of file sumd.cpp.

◆ SUMD_TARGET_MIN

#define SUMD_TARGET_MIN   1000.0f

Definition at line 81 of file sumd.cpp.

Enumeration Type Documentation

◆ SUMD_DECODE_STATE

Enumerator
SUMD_DECODE_STATE_UNSYNCED 
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 

Definition at line 47 of file sumd.cpp.

Function Documentation

◆ sumd_crc16()

uint16_t sumd_crc16 ( uint16_t  crc,
uint8_t  value 
)

CRC16 implementation for SUMD protocol.

Parameters
crcInitial CRC Value
valueto accumulate in the checksum
Returns
the checksum

Definition at line 93 of file sumd.cpp.

Referenced by sumd_decode().

Here is the caller graph for this function:

◆ sumd_crc8()

uint8_t sumd_crc8 ( uint8_t  crc,
uint8_t  value 
)

CRC8 implementation for SUMH protocol.

Parameters
crcInitial CRC Value
valueto accumulate in the checksum
Returns
the checksum

Definition at line 105 of file sumd.cpp.

Referenced by sumd_decode().

Here is the caller graph for this function:

◆ sumd_decode()

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,
bool *  failsafe 
)

Decoder for SUMD/SUMH protocol.

Parameters
bytecurrent char to read
rssipointer to a byte where the RSSI value is written back to
rx_countpointer to a byte where the receive count of packets signce last wireless frame is written back to
channelspointer to a datastructure of size max_chan_count where channel values (12 bit) are written back to
max_chan_countmaximum channels to decode - if more channels are decoded, the last n are skipped and success (0) is returned
failsafepointer to a boolean where the decoded failsafe flag is written back to
Returns
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

Definition at line 111 of file sumd.cpp.

References _crc16, _crc8, _crcOK, _debug, _decode_state, _rxlen, _sumd, ReceiverFcPacketHoTT::crc16_high, ReceiverFcPacketHoTT::crc16_low, ReceiverFcPacketHoTT::crc8, ReceiverFcPacketHoTT::header, ReceiverFcPacketHoTT::length, ReceiverFcPacketHoTT::status, sumd_crc16(), sumd_crc8(), ReceiverFcPacketHoTT::sumd_data, SUMD_DECODE_STATE_GOT_CRC, SUMD_DECODE_STATE_GOT_CRC16_BYTE_1, SUMD_DECODE_STATE_GOT_CRC16_BYTE_2, SUMD_DECODE_STATE_GOT_DATA, SUMD_DECODE_STATE_GOT_HEADER, SUMD_DECODE_STATE_GOT_LEN, SUMD_DECODE_STATE_GOT_STATE, SUMD_DECODE_STATE_UNSYNCED, SUMD_HEADER_ID, SUMD_ID_FAILSAFE, SUMD_ID_SUMD, SUMD_ID_SUMH, SUMD_MAX_CHANNELS, and ReceiverFcPacketHoTT::telemetry.

Referenced by RCInput::cycle(), dsm_port_input(), and RCTest::sumdTest().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ _crc16

uint16_t _crc16 = 0x0000

Definition at line 71 of file sumd.cpp.

Referenced by sumd_decode().

◆ _crc8

uint8_t _crc8 = 0x00

Definition at line 70 of file sumd.cpp.

Referenced by sumd_decode().

◆ _crcOK

bool _crcOK = false

Definition at line 73 of file sumd.cpp.

Referenced by sumd_decode().

◆ _debug

bool _debug = false

Definition at line 74 of file sumd.cpp.

Referenced by sumd_decode().

◆ _decode_state

enum SUMD_DECODE_STATE _decode_state = SUMD_DECODE_STATE_UNSYNCED
static

Definition at line 88 of file sumd.cpp.

Referenced by sumd_decode().

◆ _rxlen

uint8_t _rxlen
static

Definition at line 89 of file sumd.cpp.

Referenced by sumd_decode().

◆ _rxpacket

ReceiverFcPacketHoTT& _rxpacket = rc_decode_buf._hottrxpacket
static

Definition at line 91 of file sumd.cpp.

◆ _sumd

bool _sumd = true

Definition at line 72 of file sumd.cpp.

Referenced by sumd_decode().