Firmware
syslink.h
1 /****************************************************************************
2  *
3  * Copyright (c) 2016 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 #pragma once
35 
36 #include <stdint.h>
37 
38 
39 extern const char *syslink_magic;
40 
41 #define SYSLINK_GROUP 0xF0
42 
43 #define SYSLINK_RADIO 0x00
44 #define SYSLINK_RADIO_RAW 0x00
45 #define SYSLINK_RADIO_CHANNEL 0x01
46 #define SYSLINK_RADIO_DATARATE 0x02
47 #define SYSLINK_RADIO_CONTWAVE 0x03
48 #define SYSLINK_RADIO_RSSI 0x04
49 #define SYSLINK_RADIO_ADDRESS 0x05
50 
51 #define SYSLINK_PM 0x10
52 #define SYSLINK_PM_SOURCE 0x10
53 #define SYSLINK_PM_ONOFF_SWITCHOFF 0x11
54 #define SYSLINK_PM_BATTERY_VOLTAGE 0x12
55 #define SYSLINK_PM_BATTERY_STATE 0x13
56 #define SYSLINK_PM_BATTERY_AUTOUPDATE 0x14
57 
58 #define SYSLINK_OW 0x20
59 #define SYSLINK_OW_SCAN 0x20
60 #define SYSLINK_OW_GETINFO 0x21
61 #define SYSLINK_OW_READ 0x22
62 #define SYSLINK_OW_WRITE 0x23
63 
64 // Limited by the CRTP packet which is limited by the ESB protocol used by the NRF
65 #define SYSLINK_MAX_DATA_LEN 32
66 
67 #define SYSLINK_RADIO_RATE_250K 0
68 #define SYSLINK_RADIO_RATE_1M 1
69 #define SYSLINK_RADIO_RATE_2M 2
70 
71 
72 typedef struct {
73  uint8_t type;
74  uint8_t length;
75  uint8_t data[SYSLINK_MAX_DATA_LEN];
76  uint8_t cksum[2];
77 } __attribute__((packed)) syslink_message_t;
78 
79 
80 #define OW_SIZE 112
81 #define OW_READ_BLOCK 29
82 #define OW_WRITE_BLOCK 26 // TODO: Use even, but can be up to 27
83 
84 typedef struct {
85  uint8_t nmems;
86 } __attribute__((packed)) syslink_ow_scan_t;
87 
88 typedef struct {
89  uint8_t family; // Should by 0x0D for most chips
90  uint8_t sn[6];
91  uint8_t crc;
92 } __attribute__((packed)) syslink_ow_id_t;
93 
94 typedef struct {
95  uint8_t idx;
96  uint8_t id[8];
97 } __attribute__((packed)) syslink_ow_getinfo_t;
98 
99 typedef struct {
100  uint8_t idx;
101  uint16_t addr;
102  uint8_t data[OW_READ_BLOCK];
103 } __attribute__((packed)) syslink_ow_read_t;
104 
105 typedef struct {
106  uint8_t idx;
107  uint16_t addr;
108  uint16_t length;
109  uint8_t data[OW_WRITE_BLOCK];
110 } __attribute__((packed)) syslink_ow_write_t;
111 
112 
113 typedef enum {
114  SYSLINK_STATE_START = 0,
115  SYSLINK_STATE_TYPE,
116  SYSLINK_STATE_LENGTH,
117  SYSLINK_STATE_DATA,
118  SYSLINK_STATE_CKSUM
119 } SYSLINK_STATE;
120 
121 typedef struct {
122  SYSLINK_STATE state;
123  int index;
124 
126 
127 
128 #ifdef __cplusplus
129 extern "C" {
130 #endif
131 
132 extern void syslink_parse_init(syslink_parse_state *state);
133 
134 // Returns true if a full message was parsed
135 extern int syslink_parse_char(syslink_parse_state *state, char c, syslink_message_t *msg);
136 
137 extern void syslink_compute_cksum(syslink_message_t *msg);
138 
139 #ifdef __cplusplus
140 }
141 #endif
Definition: crtp.h:57