aboutsummaryrefslogtreecommitdiff
path: root/shared/protocol.h
blob: adec6148c249b02f7515522f6718803354d84421 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#pragma once

#include <memory.h>
#include <stdint.h>
#include <stdlib.h>

#include "bin.h"
#include "consts.h"

#define W2_SERIAL_START_BYTE 0xff

#define W2_CMDDIR_RX 0
#define W2_CMDDIR_TX 1

#define W2_CMD_CODE_MASK (~1)
#define W2_CMD_DIRECTION_MASK (1)

enum w2_e_scmds {
	/** ping command */
	W2_CMD_PING = 0x00,
	/** exception command */
	W2_CMD_EXPT = 0x02,
	/** mode command */
	W2_CMD_MODE = 0x04,
	/** speed command */
	W2_CMD_SPED = 0x06,
	/** direct control command */
	W2_CMD_DIRC = 0x08,
	/** coordinate command */
	W2_CMD_CORD = 0x0a,
	/** backorder modify command */
	W2_CMD_BOMD = 0x0c,
	/** soft reset command */
	W2_CMD_SRES = 0x0e,
	/** map config command */
	W2_CMD_MCFG = 0x10,
	/** sensor data command */
	W2_CMD_SENS = 0x12,
	/** info command */
	W2_CMD_INFO = 0x14,
	/** display control command */
	W2_CMD_DISP = 0x16,
	/** play midi command */
	W2_CMD_PLAY = 0x18,
	/** control leds command */
	W2_CMD_CLED = 0x1a,
};

#pragma pack(push, 1)

typedef struct {
	uint8_t opcode;
	uint8_t id;
} w2_s_cmd_ping_rx;

typedef struct {
	uint8_t opcode;
	uint8_t id;
} w2_s_cmd_ping_tx;

typedef struct {
	uint8_t opcode;
	uint8_t error;
	uint8_t length;
	uint8_t message[];
} w2_s_cmd_expt_tx;

typedef struct {
	uint8_t opcode;
	uint8_t mode;
} w2_s_cmd_mode_rx;

typedef struct {
	uint8_t opcode;
	uint8_t mode;
} w2_s_cmd_mode_tx;

typedef struct {
	uint8_t opcode;
	uint8_t speed;
} w2_s_cmd_sped_rx;

typedef struct {
	uint8_t opcode;
	uint16_t left;
	uint16_t right;
} w2_s_cmd_dirc_rx;

typedef struct {
	uint8_t opcode;
	uint32_t position;
	uint8_t orientation;
} w2_s_cmd_cord_rx;

typedef struct {
	uint8_t opcode;
	uint32_t position;
	uint8_t orientation;
} w2_s_cmd_cord_tx;

typedef struct {
	uint8_t opcode;
	uint32_t id;
	uint32_t position;
} w2_s_cmd_bomd_rx;

typedef struct {
	uint8_t opcode;
	uint32_t id;
	uint8_t status;
} w2_s_cmd_bomd_tx;

typedef struct {
	uint8_t opcode;
	uint8_t type;
} w2_s_cmd_sres_rx;

typedef struct {
	uint16_t position;
	uint8_t kind;
} w2_s_cmd_mcfg_feature;

typedef struct {
	uint8_t opcode;
	uint8_t width;
	uint8_t height;
	uint8_t length;
	w2_s_cmd_mcfg_feature features[];
} w2_s_cmd_mcfg_rx;

typedef struct {
	uint8_t opcode;
} w2_s_cmd_sens_rx;

typedef struct {
	uint8_t opcode;
	// TODO: sensor data
} w2_s_cmd_sens_tx;

typedef struct {
	uint8_t opcode;
} w2_s_cmd_info_rx;

typedef struct {
	uint8_t opcode;
	uint8_t build_str[32];
	uint8_t errcatch_ms;
	uint8_t io_ms;
	uint8_t sercomm_ms;
	uint8_t mode_ms;
	uint32_t uptime_s;
} w2_s_cmd_info_tx;

typedef struct {
} w2_s_cmd_disp_rx;

typedef struct {
} w2_s_cmd_play_rx;

typedef struct {
} w2_s_cmd_cled_rx;

#pragma pack(pop)

/** global handler for complete messages */
void w2_cmd_handler(uint8_t data[W2_SERIAL_READ_BUFFER_SIZE], uint8_t length);
/** calculate message length */
size_t w2_cmd_sizeof(uint8_t data[W2_SERIAL_READ_BUFFER_SIZE], uint8_t length);

/** handler for ping_rx (on complete message) */
void w2_cmd_ping_rx(w2_s_bin *data);
/** handler for ping_tx (on complete message) */
void w2_cmd_ping_tx(w2_s_bin *data);
/** handler for expt_tx (on complete message) */
void w2_cmd_expt_tx(w2_s_bin *data);
/** handler for mode_rx (on complete message) */
void w2_cmd_mode_rx(w2_s_bin *data);
/** handler for mode_tx (on complete message) */
void w2_cmd_mode_tx(w2_s_bin *data);
/** handler for sped_rx (on complete message) */
void w2_cmd_sped_rx(w2_s_bin *data);
/** handler for dirc_rx (on complete message) */
void w2_cmd_dirc_rx(w2_s_bin *data);
/** handler for cord_rx (on complete message) */
void w2_cmd_cord_rx(w2_s_bin *data);
/** handler for cord_tx (on complete message) */
void w2_cmd_cord_tx(w2_s_bin *data);
/** handler for bomd_rx (on complete message) */
void w2_cmd_bomd_rx(w2_s_bin *data);
/** handler for bomd_tx (on complete message) */
void w2_cmd_bomd_tx(w2_s_bin *data);
/** handler for sres_rx (on complete message) */
void w2_cmd_sres_rx(w2_s_bin *data);
/** handler for mcfg_rx (on complete message) */
void w2_cmd_mcfg_rx(w2_s_bin *data);
/** handler for sens_rx (on complete message) */
void w2_cmd_sens_rx(w2_s_bin *data);
/** handler for sens_tx (on complete message) */
void w2_cmd_sens_tx(w2_s_bin *data);
/** handler for info_rx (on complete message) */
void w2_cmd_info_rx(w2_s_bin *data);
/** handler for info_tx (on complete message) */
void w2_cmd_info_tx(w2_s_bin *data);
/** handler for disp_rx (on complete message) */
void w2_cmd_disp_rx(w2_s_bin *data);
/** handler for play_rx (on complete message) */
void w2_cmd_play_rx(w2_s_bin *data);
/** handler for cled_rx (on complete message) */
void w2_cmd_cled_rx(w2_s_bin *data);

/** calculate message length for expt_tx (incomplete message) */
size_t w2_cmd_expt_tx_sizeof(w2_s_bin *data);
/** calculate message length for mcfg_rx (incomplete message) */
size_t w2_cmd_mcfg_rx_sizeof(w2_s_bin *data);