CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_BLHeli/blheli_4way_protocol.h
Views: 1798
1
/*
2
blheli 4way protocol. Based on serial_4way.c from betaflight
3
*/
4
/*
5
* Cleanflight is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
9
*
10
* Cleanflight is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
17
* Author: 4712
18
*/
19
20
// Interface related only
21
// establish and test connection to the Interface
22
23
// Send Structure
24
// ESC + CMD PARAM_LEN [PARAM (if len > 0)] CRC16_Hi CRC16_Lo
25
// Return
26
// ESC CMD PARAM_LEN [PARAM (if len > 0)] + ACK (uint8_t OK or ERR) + CRC16_Hi CRC16_Lo
27
28
#define cmd_Remote_Escape 0x2E // '.'
29
#define cmd_Local_Escape 0x2F // '/'
30
31
// Test Interface still present
32
#define cmd_InterfaceTestAlive 0x30 // '0' alive
33
// RETURN: ACK
34
35
// get Protocol Version Number 01..255
36
#define cmd_ProtocolGetVersion 0x31 // '1' version
37
// RETURN: uint8_t VersionNumber + ACK
38
39
// get Version String
40
#define cmd_InterfaceGetName 0x32 // '2' name
41
// RETURN: String + ACK
42
43
//get Version Number 01..255
44
#define cmd_InterfaceGetVersion 0x33 // '3' version
45
// RETURN: uint8_t AVersionNumber + ACK
46
47
48
// Exit / Restart Interface - can be used to switch to Box Mode
49
#define cmd_InterfaceExit 0x34 // '4' exit
50
// RETURN: ACK
51
52
// Reset the Device connected to the Interface
53
#define cmd_DeviceReset 0x35 // '5' reset
54
// RETURN: ACK
55
56
// Get the Device ID connected
57
// #define cmd_DeviceGetID 0x36 //'6' device id removed since 06/106
58
// RETURN: uint8_t DeviceID + ACK
59
60
// Initialize Flash Access for Device connected
61
#define cmd_DeviceInitFlash 0x37 // '7' init flash access
62
// RETURN: ACK
63
64
// Erase the whole Device Memory of connected Device
65
#define cmd_DeviceEraseAll 0x38 // '8' erase all
66
// RETURN: ACK
67
68
// Erase one Page of Device Memory of connected Device
69
#define cmd_DevicePageErase 0x39 // '9' page erase
70
// PARAM: uint8_t APageNumber
71
// RETURN: ACK
72
73
// Read to Buffer from Device Memory of connected Device // Buffer Len is Max 256 Bytes
74
// BuffLen = 0 means 256 Bytes
75
#define cmd_DeviceRead 0x3A // ':' read Device
76
// PARAM: uint8_t ADRESS_Hi + ADRESS_Lo + BuffLen[0..255]
77
// RETURN: PARAM: uint8_t ADRESS_Hi + ADRESS_Lo + BUffLen + Buffer[0..255] ACK
78
79
// Write to Buffer for Device Memory of connected Device // Buffer Len is Max 256 Bytes
80
// BuffLen = 0 means 256 Bytes
81
#define cmd_DeviceWrite 0x3B // ';' write
82
// PARAM: uint8_t ADRESS_Hi + ADRESS_Lo + BUffLen + Buffer[0..255]
83
// RETURN: ACK
84
85
// Set C2CK low infinite ) permanent Reset state
86
#define cmd_DeviceC2CK_LOW 0x3C // '<'
87
// RETURN: ACK
88
89
// Read to Buffer from Device Memory of connected Device //Buffer Len is Max 256 Bytes
90
// BuffLen = 0 means 256 Bytes
91
#define cmd_DeviceReadEEprom 0x3D // '=' read Device
92
// PARAM: uint8_t ADRESS_Hi + ADRESS_Lo + BuffLen[0..255]
93
// RETURN: PARAM: uint8_t ADRESS_Hi + ADRESS_Lo + BUffLen + Buffer[0..255] ACK
94
95
// Write to Buffer for Device Memory of connected Device // Buffer Len is Max 256 Bytes
96
// BuffLen = 0 means 256 Bytes
97
#define cmd_DeviceWriteEEprom 0x3E // '>' write
98
// PARAM: uint8_t ADRESS_Hi + ADRESS_Lo + BUffLen + Buffer[0..255]
99
// RETURN: ACK
100
101
// Set Interface Mode
102
#define cmd_InterfaceSetMode 0x3F // '?'
103
// #define imC2 0
104
// #define imSIL_BLB 1
105
// #define imATM_BLB 2
106
// #define imSK 3
107
// PARAM: uint8_t Mode
108
// RETURN: ACK or ACK_I_INVALID_CHANNEL
109
110
//Write to Buffer for Verify Device Memory of connected Device //Buffer Len is Max 256 Bytes
111
//BuffLen = 0 means 256 Bytes
112
#define cmd_DeviceVerify 0x40 //'@' write
113
//PARAM: uint8_t ADRESS_Hi + ADRESS_Lo + BUffLen + Buffer[0..255]
114
//RETURN: ACK
115
116
/*
117
local defines
118
*/
119
#define SERIAL_4WAY_VER_MAIN 20
120
#define SERIAL_4WAY_VER_SUB_1 (uint8_t) 0
121
#define SERIAL_4WAY_VER_SUB_2 (uint8_t) 05
122
123
#define SERIAL_4WAY_PROTOCOL_VER 107
124
// *** end
125
126
#if (SERIAL_4WAY_VER_MAIN > 24)
127
#error "beware of SERIAL_4WAY_VER_SUB_1 is uint8_t"
128
#endif
129
130
#define SERIAL_4WAY_VERSION (uint16_t) ((SERIAL_4WAY_VER_MAIN * 1000) + (SERIAL_4WAY_VER_SUB_1 * 100) + SERIAL_4WAY_VER_SUB_2)
131
132
#define SERIAL_4WAY_VERSION_HI (uint8_t) (SERIAL_4WAY_VERSION / 100)
133
#define SERIAL_4WAY_VERSION_LO (uint8_t) (SERIAL_4WAY_VERSION % 100)
134
135
#define brSUCCESS 0x30
136
#define brERRORVERIFY 0xC0
137
#define brERRORCOMMAND 0xC1
138
#define brERRORCRC 0xC2
139
#define brNONE 0xFF
140
141
#define CMD_RUN 0x00
142
#define CMD_PROG_FLASH 0x01
143
#define CMD_ERASE_FLASH 0x02
144
#define CMD_READ_FLASH_SIL 0x03
145
#define CMD_VERIFY_FLASH 0x03
146
#define CMD_VERIFY_FLASH_ARM 0x04
147
#define CMD_READ_EEPROM 0x04
148
#define CMD_PROG_EEPROM 0x05
149
#define CMD_READ_SRAM 0x06
150
#define CMD_READ_FLASH_ATM 0x07
151
#define CMD_KEEP_ALIVE 0xFD
152
#define CMD_SET_ADDRESS 0xFF
153
#define CMD_SET_BUFFER 0xFE
154
155
#define RestartBootloader 0
156
#define ExitBootloader 1
157
158
#define ACK_OK 0x00
159
#define ACK_I_INVALID_CMD 0x02
160
#define ACK_I_INVALID_CRC 0x03
161
#define ACK_I_VERIFY_ERROR 0x04
162
#define ACK_I_INVALID_CHANNEL 0x08
163
#define ACK_I_INVALID_PARAM 0x09
164
#define ACK_D_GENERAL_ERROR 0x0F
165
166
// interface modes
167
#define imC2 0
168
#define imSIL_BLB 1
169
#define imATM_BLB 2
170
#define imSK 3
171
#define imARM_BLB 4
172
173