blob: a1aa31c42856ffd9f83b7b36f60abd991f84659a (
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
|
#include <stdlib.h>
#include <string.h>
#include "../shared/bin.h"
#include "../shared/serial_parse.h"
#include "orangutan_shim.h"
#include "sercomm.h"
w2_s_bin *g_w2_sercomm_buffer[W2_SERCOMM_BUFFER_SIZE] = {0};
uint8_t g_w2_sercomm_index = 0;
uint8_t g_w2_sercomm_offset = 0;
uint8_t g_w2_sercomm_buffer_full = 0;
char g_w2_serial_buffer[W2_SERIAL_READ_BUFFER_SIZE] = {0};
uint8_t g_w2_serial_buffer_index = 0;
uint8_t g_w2_serial_buffer_head = 0;
void w2_sercomm_main() {
#ifdef W2_SIM
simprintfunc("w2_sercomm_main", "");
#endif
// send data
while (g_w2_sercomm_offset != g_w2_sercomm_index) {
w2_s_bin *data = g_w2_sercomm_buffer[g_w2_sercomm_offset];
char *data_cast = malloc(data->bytes);
memcpy(data_cast, data->data, data->bytes);
serial_send(data_cast, data->bytes);
g_w2_sercomm_offset = (g_w2_sercomm_offset + 1) % W2_SERCOMM_BUFFER_SIZE;
}
// read and parse data
while (serial_get_received_bytes() != g_w2_serial_buffer_index) {
w2_serial_parse(g_w2_serial_buffer[g_w2_serial_buffer_index]);
g_w2_serial_buffer_index = (g_w2_serial_buffer_index + 1) % W2_SERIAL_READ_BUFFER_SIZE;
}
}
void w2_sercomm_append_msg(w2_s_bin *data) {
#ifdef W2_SIM
simprintfunc("w2_sercomm_append_msg", "");
#endif
uint8_t next_index = (g_w2_sercomm_index + 1) % W2_SERCOMM_BUFFER_SIZE;
g_w2_sercomm_buffer_full = next_index == g_w2_sercomm_offset;
free(g_w2_sercomm_buffer[g_w2_sercomm_index]);
g_w2_sercomm_buffer[g_w2_sercomm_index] = w2_bin_s_alloc(data->bytes, data->data);
if (g_w2_sercomm_buffer_full) return;
g_w2_sercomm_index = next_index;
}
void w2_scmd_ping_rx(w2_s_bin *data) {
return;
}
void w2_scmd_mode_rx(w2_s_bin *data) {
return;
}
void w2_scmd_sped_rx(w2_s_bin *data) {
return;
}
void w2_scmd_dirc_rx(w2_s_bin *data) {
return;
}
void w2_scmd_cord_rx(w2_s_bin *data) {
return;
}
void w2_scmd_bomd_rx(w2_s_bin *data) {
return;
}
void w2_scmd_sres_rx(w2_s_bin *data) {
return;
}
void w2_scmd_mcfg_rx(w2_s_bin *data) {
return;
}
void w2_scmd_sens_rx(w2_s_bin *data) {
return;
}
void w2_scmd_info_rx(w2_s_bin *data) {
return;
}
void w2_scmd_disp_rx(w2_s_bin *data) {
return;
}
void w2_scmd_play_rx(w2_s_bin *data) {
return;
}
void w2_scmd_cled_rx(w2_s_bin *data) {
return;
}
void w2_scmd_ping_tx(w2_s_bin *data) { }
void w2_scmd_expt_tx(w2_s_bin *data) { }
void w2_scmd_mode_tx(w2_s_bin *data) { }
void w2_scmd_cord_tx(w2_s_bin *data) { }
void w2_scmd_bomd_tx(w2_s_bin *data) { }
void w2_scmd_sens_tx(w2_s_bin *data) { }
void w2_scmd_info_tx(w2_s_bin *data) { }
|