PX4 Firmware
PX4 Autopilot Software http://px4.io
sumd.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2015 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
34 /**
35  * @file sumd.h
36  *
37  * RC protocol definition for Graupner HoTT transmitter
38  *
39  * @author Marco Bauer <marco@wtns.de>
40  */
41 
42 #pragma once
43 
44 #include <stdint.h>
45 
47 
48 #define SUMD_MAX_CHANNELS 32
49 #define SUMD_HEADER_LENGTH 3
50 #define SUMD_HEADER_ID 0xA8
51 #define SUMD_ID_SUMH 0x00
52 #define SUMD_ID_SUMD 0x01
53 #define SUMD_ID_FAILSAFE 0x81
54 
55 
56 
57 
58 #pragma pack(push, 1)
59 typedef struct {
60  uint8_t header; ///< 0xA8 for a valid packet
61  uint8_t status; ///< 0x01 valid and live SUMD data frame / 0x00 = SUMH / 0x81 = Failsafe
62  uint8_t length; ///< Channels
63  uint8_t sumd_data[SUMD_MAX_CHANNELS * 2]; ///< ChannelData (High Byte/ Low Byte)
64  uint8_t crc16_high; ///< High Byte of 16 Bit CRC
65  uint8_t crc16_low; ///< Low Byte of 16 Bit CRC
66  uint8_t telemetry; ///< Telemetry request
67  uint8_t crc8; ///< SUMH CRC8
69 #pragma pack(pop)
70 
71 
72 /**
73  * CRC16 implementation for SUMD protocol
74  *
75  * @param crc Initial CRC Value
76  * @param value to accumulate in the checksum
77  * @return the checksum
78  */
79 uint16_t sumd_crc16(uint16_t crc, uint8_t value);
80 
81 /**
82  * CRC8 implementation for SUMH protocol
83  *
84  * @param crc Initial CRC Value
85  * @param value to accumulate in the checksum
86  * @return the checksum
87  */
88 uint8_t sumd_crc8(uint8_t crc, uint8_t value);
89 
90 /**
91  * Decoder for SUMD/SUMH protocol
92  *
93  * @param byte current char to read
94  * @param rssi pointer to a byte where the RSSI value is written back to
95  * @param rx_count pointer to a byte where the receive count of packets signce last wireless frame is written back to
96  * @param channels pointer to a datastructure of size max_chan_count where channel values (12 bit) are written back to
97  * @param max_chan_count maximum channels to decode - if more channels are decoded, the last n are skipped and success (0) is returned
98  * @param failsafe pointer to a boolean where the decoded failsafe flag is written back to
99  * @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
100  */
101 /*
102 __EXPORT int sumd_decode(uint8_t byte, uint8_t *rssi, uint8_t *rx_count, uint16_t *channel_count,
103  uint16_t *channels, uint16_t max_chan_count, bool *failsafe);
104 */
105 __EXPORT int sumd_decode(uint8_t byte, uint8_t *rssi, uint8_t *rx_count, uint16_t *channel_count,
106  uint16_t *channels, uint16_t max_chan_count, bool *failsafe);
107 
108 
uint8_t crc16_low
Low Byte of 16 Bit CRC.
Definition: sumd.h:65
#define __END_DECLS
Definition: visibility.h:59
Definition: I2C.hpp:51
uint8_t crc8
SUMH CRC8.
Definition: sumd.h:67
__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, bool *failsafe)
Decoder for SUMD/SUMH protocol.
Definition: sumd.cpp:111
uint16_t sumd_crc16(uint16_t crc, uint8_t value)
CRC16 implementation for SUMD protocol.
Definition: sumd.cpp:93
uint8_t sumd_crc8(uint8_t crc, uint8_t value)
CRC8 implementation for SUMH protocol.
Definition: sumd.cpp:105
uint8_t length
Channels.
Definition: sumd.h:62
#define __BEGIN_DECLS
Definition: visibility.h:58
uint8_t header
0xA8 for a valid packet
Definition: sumd.h:60
uint8_t telemetry
Telemetry request.
Definition: sumd.h:66
#define SUMD_MAX_CHANNELS
Definition: sumd.h:48
uint8_t crc16_high
High Byte of 16 Bit CRC.
Definition: sumd.h:64
uint8_t status
0x01 valid and live SUMD data frame / 0x00 = SUMH / 0x81 = Failsafe
Definition: sumd.h:61