Firmware
st24.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2014 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 
42 #pragma once
43 
44 #include <stdint.h>
45 
46 __BEGIN_DECLS
47 
48 #define ST24_DATA_LEN_MAX 64
49 #define ST24_STX1 0x55
50 #define ST24_STX2 0x55
51 
52 enum ST24_PACKET_TYPE {
53  ST24_PACKET_TYPE_CHANNELDATA12 = 0,
54  ST24_PACKET_TYPE_CHANNELDATA24,
55  ST24_PACKET_TYPE_TRANSMITTERGPSDATA
56 };
57 
58 enum ST24_DECODE_STATE {
59  ST24_DECODE_STATE_UNSYNCED = 0,
60  ST24_DECODE_STATE_GOT_STX1,
61  ST24_DECODE_STATE_GOT_STX2,
62  ST24_DECODE_STATE_GOT_LEN,
63  ST24_DECODE_STATE_GOT_TYPE,
64  ST24_DECODE_STATE_GOT_DATA
65 };
66 
67 #pragma pack(push, 1)
68 typedef struct {
69  uint8_t header1;
70  uint8_t header2;
71  uint8_t length;
72  uint8_t type;
73  uint8_t st24_data[ST24_DATA_LEN_MAX];
74  uint8_t crc8;
76 
82 typedef struct {
83  uint16_t t;
84  uint8_t rssi;
85  uint8_t lost_count;
86  uint8_t channel[18];
88 
93 typedef struct {
94  uint16_t t;
95  uint8_t rssi;
96  uint8_t lost_count;
97  uint8_t channel[36];
99 
133 typedef struct {
134  uint16_t t;
135  int32_t lat;
136  int32_t lon;
137  int32_t alt;
138  int16_t vx, vy, vz;
139  uint8_t nsat;
140  uint8_t voltage;
141  uint8_t current;
142  int16_t roll, pitch, yaw;
143  uint8_t motorStatus;
144  uint8_t imuStatus;
146 } TelemetryData;
147 
148 #pragma pack(pop)
149 
157 uint8_t st24_common_crc8(uint8_t *ptr, uint8_t len);
158 
169 __EXPORT int st24_decode(uint8_t byte, uint8_t *rssi, uint8_t *lost_count, uint16_t *channel_count,
170  uint16_t *channels, uint16_t max_chan_count);
171 
172 __END_DECLS
int16_t yaw
0.01 degree resolution
Definition: st24.h:142
uint8_t length
length includes type, data, and crc = sizeof(type)+sizeof(data[payload_len])+sizeof(crc8) ...
Definition: st24.h:71
int32_t lat
lattitude (degrees) +/- 90 deg
Definition: st24.h:135
uint8_t lost_count
Number of UART packets sent since reception of last RF frame (100 frame means RC timeout of 1s) ...
Definition: st24.h:96
uint16_t t
packet counter or clock
Definition: st24.h:83
int32_t alt
0.01m resolution, altitude (meters)
Definition: st24.h:137
uint16_t t
packet counter or clock
Definition: st24.h:94
uint8_t nsat
number of satellites
Definition: st24.h:139
Telemetry packet.
Definition: st24.h:133
int16_t vz
velocity 0.01m res, +/-320.00 North-East- Down
Definition: st24.h:138
RC Channel data (12 channels).
Definition: st24.h:82
uint8_t st24_common_crc8(uint8_t *ptr, uint8_t len)
CRC8 implementation for ST24 protocol.
Definition: st24.cpp:71
uint8_t imuStatus
inertial measurement unit status
Definition: st24.h:144
uint8_t rssi
signal strength
Definition: st24.h:84
uint8_t current
0.5A resolution
Definition: st24.h:141
RC Channel data (12 channels).
Definition: st24.h:93
Definition: I2C.hpp:51
uint8_t header2
0x55 for a valid packet
Definition: st24.h:70
uint8_t header1
0x55 for a valid packet
Definition: st24.h:69
uint8_t pressCompassStatus
baro / compass status
Definition: st24.h:145
uint8_t crc8
crc8 checksum, calculated by st24_common_crc8 and including fields length, type and st24_data ...
Definition: st24.h:74
__EXPORT int st24_decode(uint8_t byte, uint8_t *rssi, uint8_t *lost_count, uint16_t *channel_count, uint16_t *channels, uint16_t max_chan_count)
Decoder for ST24 protocol.
Definition: st24.cpp:98
uint16_t t
packet counter or clock
Definition: st24.h:134
uint8_t rssi
signal strength
Definition: st24.h:95
Definition: st24.h:68
uint8_t voltage
25.4V voltage = 5 + 255*0.1 = 30.5V, min=5V
Definition: st24.h:140
uint8_t motorStatus
1 bit per motor for status 1=good, 0= fail
Definition: st24.h:143
int32_t lon
longitude (degrees) +/- 180 deg
Definition: st24.h:136
uint8_t lost_count
Number of UART packets sent since reception of last RF frame (100 frame means RC timeout of 1s) ...
Definition: st24.h:85
uint8_t type
from enum ST24_PACKET_TYPE
Definition: st24.h:72