ev3duder  0.3.0
EV3 Downloader/Uploader
packets.h
Go to the documentation of this file.
1 
9 #ifndef EV3DUDER_PACKETS_H
10 #define EV3DUDER_PACKETS_H
11 
12 #include "defs.h"
13 // inheritance :^)
15 #define HID_LAYER \
16  u8 hidLayer;
17 
23 #define EV3_PACKET_FIELDS \
24  u16 packetLen;\
25  u16 msgCount;
26 
32 #define EV3_COMMAND_FIELDS \
33  HID_LAYER \
34  EV3_PACKET_FIELDS \
35  u8 replyType;\
36  u8 cmd;
37 
42 #define EV3_REPLY_FIELDS \
43  EV3_PACKET_FIELDS \
44  u8 type; \
45  u8 cmd; \
46  u8 ret;
47 
54 #define PREFIX_SIZE 3
55 
61 #pragma pack(push, 1) //README: __attribute__((packed)) doesn't work for whatever reason
62 
64 typedef struct
65 {
67 
68  u8 bytes[];
69 } SYSTEM_CMD;
70 
72 typedef struct
73 {
75  u8 bytes[];
76 } SYSTEM_REPLY;
77 
79 typedef struct
80 {
87  char fileName[];
90 
92 typedef struct
93 {
98 
99 
101 typedef struct
102 {
106  /* Your data */
107  char fileChunk[];
109 
111 
114 
116 typedef struct
117 {
119 
123  char fileName[];
124 } BEGIN_UPLOAD;
125 
127 typedef struct
128 {
130 
136  u8 bytes[];
138 
140 typedef struct
141 {
143 
149 
151 typedef struct
152 {
154 
158  u8 bytes[];
160 
162 extern const BEGIN_UPLOAD BEGIN_UPLOAD_INIT;
163 
164 
166 typedef struct
167 {
172  u8 path[];
173 } LIST_FILES;
174 extern const LIST_FILES LIST_FILES_INIT;
175 
177 extern const BEGIN_GETFILE BEGIN_GETFILE_INIT;
178 
195 typedef struct
196 {
198 
199  u32 listSize; // when listSize < maxBytes; reached EO List?
200  u8 handle; // for CONTINUE_LIST_FILES
201  /* files according to above description.
202  * \n separated and UTF-8 encoded
203  */
204  char list[];
206 
208 typedef struct
209 {
211 
216 
218 typedef struct
219 {
221 
222  u8 handle; // for CONTINUE_LIST_FILES
223  char list[];
224  // \n seperated; UTF-8 encoded.
226 
228 typedef struct
229 {
231 
233  u8 path[];
234 } CREATE_DIR;
235 
236 extern const CREATE_DIR CREATE_DIR_INIT;
237 
239 
241 typedef struct
242 {
245  u8 path[];
246 } DELETE_FILE;
247 extern const DELETE_FILE DELETE_FILE_INIT;
248 
250 
253 /*typedef struct
254 {
255  EV3_COMMAND_FIELDS
256 
257  u8 mac_len;
258  u8 mac[mac_len]; // asciiz hex; no colons
259  u8 pin_len;
260  u8 pen[pin_len]; // asciiz
261 } BLUETOOTHPIN;*/ /* implement with mempcpy like in exec.c */
262 
263 extern const BLUETOOTHPIN BLUETOOTHPIN_INIT;
264 
266 typedef struct{
268 
269  BLUETOOTHPIN echo; // GNU C extension
271 
274 extern const ENTERFWUPDATE ENTERFWUPDATE_INIT;
275 
276 //
278 #define EV3_VM_COMMAND_FIELDS \
279  HID_LAYER \
280  EV3_PACKET_FIELDS \
281  u8 replyType; \
282  u16 alloc;
283 
285 typedef struct
286 {
288 
289  u8 bytes[];
290 } VM_CMD;
291 
293 extern const EXECUTE_FILE EXECUTE_FILE_INIT;
294 
295 /*
296 typedef struct
297 {
298  EV3_VM_COMMAND_FIELDS
299 
300  u8 opCode;
301  u8 cmd;
302  u8 userSlot;
303 
304 
305 
306 } EXEC_FILE;
307 
308 C00882010084 2E2E2F70726A732F42726B50726F675F534156452F44656D6F2E72706600
309 cccccccccccc cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
310 
311 */
312 
314 typedef struct
315 {
318  u8 bytes[];
319 } VM_REPLY;
320 
322 
323 
324 #pragma pack(pop)
325 
328 #define packet_alloc(type, extra) ({ \
329  void *ptr = NULL; \
330  if ((sizeof(type) + extra < (u16)-1) \
331  && (ptr = malloc(sizeof(type) + extra))) { \
332  memcpy(ptr, &type##_INIT, sizeof(type)); \
333  ((SYSTEM_CMD *)ptr)->packetLen = (u16)(sizeof(type) + extra - PREFIX_SIZE); \
334  } \
335  ptr;})
336 
337 #endif
338 
SYSTEM_REPLY CREATE_DIR_REPLY
Definition: packets.h:238
SYSTEM_CMD ENTERFWUPDATE
Force brick into Firmware update mode, untested and unused.
Definition: packets.h:273
EV3_COMMAND_FIELDS u16 maxBytes
Definition: packets.h:170
EV3_PACKET_FIELDS u8 replyType
Definition: packets.h:317
delete file
Definition: packets.h:241
const EXECUTE_FILE EXECUTE_FILE_INIT
Definition: packets.c:46
EV3_REPLY_FIELDS u8 fileHandle
Definition: packets.h:156
const ENTERFWUPDATE ENTERFWUPDATE_INIT
Definition: packets.c:43
VM_CMD EXECUTE_FILE
Definition: packets.h:292
EV3_COMMAND_FIELDS u16 maxBytes
Definition: packets.h:121
send file chunk wise
Definition: packets.h:101
EV3_REPLY_FIELDS u8 fileHandle
Definition: packets.h:96
Directory contents on EV3.
Definition: packets.h:195
EV3_COMMAND_FIELDS u8 fileHandle
Definition: packets.h:105
untested and unused
Definition: packets.h:266
LIST_FILES BEGIN_GETFILE
Definition: packets.h:176
const CONTINUE_DOWNLOAD CONTINUE_DOWNLOAD_INIT
Definition: packets.c:13
create directory
Definition: packets.h:228
uint32_t u32
Definition: defs.h:11
const CONTINUE_UPLOAD CONTINUE_UPLOAD_INIT
Definition: packets.c:22
#define EV3_VM_COMMAND_FIELDS
VM stuff.
Definition: packets.h:278
continue download from ev3
Definition: packets.h:140
const VM_REPLY EXECUTE_FILE_REPLY_SUCCESS
Definition: packets.c:49
EV3_REPLY_FIELDS u32 fileSize
Definition: packets.h:132
const CONTINUE_DOWNLOAD_REPLY CONTINUE_DOWNLOAD_REPLY_SUCCESS
Definition: packets.c:16
continue download from ev3 reply
Definition: packets.h:151
uint16_t u16
Definition: defs.h:10
EV3_COMMAND_FIELDS u8 fileHandle
Definition: packets.h:145
SYSTEM_CMD BLUETOOTHPIN
set bluetooth pin, untested
Definition: packets.h:252
const BEGIN_DOWNLOAD BEGIN_DOWNLOAD_INIT
Definition: packets.c:10
const BLUETOOTHPIN BLUETOOTHPIN_INIT
Definition: packets.c:40
BEGIN_DOWNLOAD_REPLY CONTINUE_DOWNLOAD_REPLY
Definition: packets.h:112
const BEGIN_UPLOAD BEGIN_UPLOAD_INIT
Definition: packets.c:19
download from EV3 reply
Definition: packets.h:127
EV3_REPLY_FIELDS BLUETOOTHPIN echo
Definition: packets.h:269
#define EV3_COMMAND_FIELDS
Definition: packets.h:32
const LIST_FILES LIST_FILES_INIT
Definition: packets.c:25
SYSTEM_REPLY DELETE_FILE_REPLY
Definition: packets.h:249
base reply packet
Definition: packets.h:314
upload to EV3
Definition: packets.h:79
EV3_COMMAND_FIELDS u8 handle
Definition: packets.h:212
List files on EV3.
Definition: packets.h:166
base packet for SYSTEM REPLIES
Definition: packets.h:72
uint8_t u8
Definition: defs.h:9
const CONTINUE_LIST_FILES CONTINUE_LIST_FILES_INIT
Definition: packets.c:28
EV3_COMMAND_FIELDS u32 fileSize
Definition: packets.h:83
#define EV3_REPLY_FIELDS
Definition: packets.h:42
Th ev3's reply.
Definition: packets.h:92
download from EV3
Definition: packets.h:116
const CREATE_DIR CREATE_DIR_INIT
Definition: packets.c:34
base packet for SYSTEM COMMANDS
Definition: packets.h:64
const DELETE_FILE DELETE_FILE_INIT
Definition: packets.c:37
EV3_REPLY_FIELDS u8 handle
Definition: packets.h:222
const BEGIN_GETFILE BEGIN_GETFILE_INIT
Definition: packets.c:31
base packet
Definition: packets.h:285
EV3_REPLY_FIELDS u32 listSize
Definition: packets.h:199
#define EV3_PACKET_FIELDS
Definition: packets.h:23