-
Notifications
You must be signed in to change notification settings - Fork 0
/
hyper_device_31_v3.gen.h
264 lines (214 loc) · 7.3 KB
/
hyper_device_31_v3.gen.h
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
// --- HYPER GENERATED CODE %VERSION% 1662984786 ---
//
// WARNING
//
// This file was automatically generated by the Hyper Platform.
// Manual changes MUST NOT be made, consult documentation at hyper.ag for more
// information.
#ifndef __HYPER_DEVICE_CLASS_31__
#define __HYPER_DEVICE_CLASS_31__
#ifdef __cplusplus
extern "C"
{
#endif
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include "cmp.h"
#include "hyper_device_core_v3.h"
// --- DEVICE TYPE ---
typedef struct {
uint8_t version;
uint32_t device_class_id;
uint8_t device_id[6];
uint8_t fcap_lemna_density_0_1_set : 1;
float fcap_lemna_density_0_1;
uint8_t fcap_lemna_sensor_distance_0_1_set : 1;
float fcap_lemna_sensor_distance_0_1;
} hyper_device_31_t;
void hyper_device_31_reset(hyper_device_31_t * device) {
device->fcap_lemna_density_0_1_set = 0;
device->fcap_lemna_density_0_1 = 0.0;
device->fcap_lemna_sensor_distance_0_1_set = 0;
device->fcap_lemna_sensor_distance_0_1 = 0.0;
}
void hyper_device_31_init(hyper_device_31_t * device, uint8_t device_id[6]) {
device->version = 3;
device->device_class_id = 31;
memcpy(device->device_id, device_id, 6);
hyper_device_31_reset(device);
}
// --- PRINT DEVICE ---
void hyper_device_31_print(hyper_device_31_t * device) {
HYPER_PRINTF(
"(hyper_device_31_t\n"
" (version %d)\n"
" (device_class_id %lu)\n"
" (device_id (%02x %02x %02x %02x %02x %02x))\n",
device->version, (long unsigned)device->device_class_id, device->device_id[0],
device->device_id[1], device->device_id[2], device->device_id[3],
device->device_id[4], device->device_id[5]);
if (device->fcap_lemna_density_0_1_set) {
HYPER_PRINTF(" (fcap_lemna_density_0_1 (f32 %f))\n", device->fcap_lemna_density_0_1);
} else {
HYPER_PRINTF(" (fcap_lemna_density_0_1 (f32 none))\n");
}
if (device->fcap_lemna_sensor_distance_0_1_set) {
HYPER_PRINTF(" (fcap_lemna_sensor_distance_0_1 (f32 %f))\n", device->fcap_lemna_sensor_distance_0_1);
} else {
HYPER_PRINTF(" (fcap_lemna_sensor_distance_0_1 (f32 none))\n");
}
HYPER_PRINTF(")\n");
}
// --- BIND ATTRIBUTES ---
// --- SET ATTRIBUTES ---
void hyper_device_31_set_fcap_lemna_density_0_1(hyper_device_31_t * device, float value) {
device->fcap_lemna_density_0_1_set = 1;
device->fcap_lemna_density_0_1 = value;
}
void hyper_device_31_set_fcap_lemna_sensor_distance_0_1(hyper_device_31_t * device, float value) {
device->fcap_lemna_sensor_distance_0_1_set = 1;
device->fcap_lemna_sensor_distance_0_1 = value;
}
// --- ENCODE DEVICE ---
hyper_result_t hyper_device_31_encode(hyper_device_31_t * device, uint8_t * out, uint8_t * out_len) {
cmp_ctx_t cmp_ctx = {0};
hyper_msgpack_buffer_t msgpack_buf = {out, 0};
cmp_init(&cmp_ctx, (void *)&msgpack_buf, NULL, NULL, hyper_device_msgpack_writer);
// Encode message as array of elements.
if (!cmp_write_array(&cmp_ctx, 3)) {
HYPER_PRINTF("%s\n", cmp_strerror(&cmp_ctx));
return HYPER_ERR_ENCODE;
}
// Device info.
if (!cmp_write_uinteger(&cmp_ctx, device->device_class_id)) {
HYPER_PRINTF("%s\n", cmp_strerror(&cmp_ctx));
return HYPER_ERR_ENCODE;
}
if (!cmp_write_bin(&cmp_ctx, device->device_id, 6)) {
HYPER_PRINTF("%s\n", cmp_strerror(&cmp_ctx));
return HYPER_ERR_ENCODE;
}
uint8_t defined_attributes_count = 0;
if (device->fcap_lemna_density_0_1_set) ++defined_attributes_count;
if (device->fcap_lemna_sensor_distance_0_1_set) ++defined_attributes_count;
// Attributes
if (!cmp_write_map(&cmp_ctx, defined_attributes_count)) {
HYPER_PRINTF("%s\n", cmp_strerror(&cmp_ctx));
return HYPER_ERR_ENCODE;
}
// 0: fcap_lemna_density_0_1
if (device->fcap_lemna_density_0_1_set) {
if (!cmp_write_u8(&cmp_ctx, 0)) {
HYPER_PRINTF("%s\n", cmp_strerror(&cmp_ctx));
return HYPER_ERR_ENCODE;
}
if (!cmp_write_float(&cmp_ctx, device->fcap_lemna_density_0_1)) {
HYPER_PRINTF("%s\n", cmp_strerror(&cmp_ctx));
return HYPER_ERR_ENCODE;
}
}
// 1: fcap_lemna_sensor_distance_0_1
if (device->fcap_lemna_sensor_distance_0_1_set) {
if (!cmp_write_u8(&cmp_ctx, 1)) {
HYPER_PRINTF("%s\n", cmp_strerror(&cmp_ctx));
return HYPER_ERR_ENCODE;
}
if (!cmp_write_float(&cmp_ctx, device->fcap_lemna_sensor_distance_0_1)) {
HYPER_PRINTF("%s\n", cmp_strerror(&cmp_ctx));
return HYPER_ERR_ENCODE;
}
}
*out_len = msgpack_buf.offset;
return HYPER_OK;
}
// --- DECODE DEVICE ---
hyper_result_t hyper_device_31_decode(hyper_device_31_t * device, uint8_t * in, uint8_t in_size) {
cmp_ctx_t cmp_ctx = {0};
hyper_msgpack_buffer_t msgpack_buf = {in, 0};
cmp_init(&cmp_ctx, (void *)&msgpack_buf, hyper_device_msgpack_reader, NULL, NULL);
uint32_t msg_array_size = 0;
// Main msg array
if (!cmp_read_array(&cmp_ctx, &msg_array_size) && msg_array_size != 3) {
HYPER_PRINTF("%s\n", cmp_strerror(&cmp_ctx));
return HYPER_ERR_DECODE;
}
cmp_object_t obj;
// Device class id
if (!cmp_read_object(&cmp_ctx, &obj)) {
HYPER_PRINTF("%s\n", "could not read object");
return HYPER_ERR_DECODE;
}
if (!cmp_object_as_uint(&obj, &device->device_class_id)) {
HYPER_PRINTF("%s\n", "could not read device_class_id\n");
return HYPER_ERR_DECODE;
}
// Device id
uint32_t device_id_size = 0;
if (!cmp_read_bin_size(&cmp_ctx, &device_id_size)) {
HYPER_PRINTF("%s\n", cmp_strerror(&cmp_ctx));
return HYPER_ERR_DECODE;
}
if (device_id_size != 6) {
HYPER_PRINTF("%s\n", "hyper_device_decode: wrong device_id_size\n");
return HYPER_ERR_DECODE;
}
memcpy(device->device_id, in + msgpack_buf.offset, 6);
msgpack_buf.offset += 6;
// Attributes
uint32_t attributes_map_len = 0;
if (!cmp_read_map(&cmp_ctx, &attributes_map_len)) {
HYPER_PRINTF("%s\n", cmp_strerror(&cmp_ctx));
return HYPER_ERR_DECODE;
}
uint8_t key = 0xFF;
for (uint16_t i = 0; i < attributes_map_len; ++i) {
// Key
if (!cmp_read_object(&cmp_ctx, &obj)) {
HYPER_PRINTF("%s\n", "could not read map key");
return HYPER_ERR_DECODE;
}
if (cmp_object_as_uchar(&obj, &key)) {
// Value
if (!cmp_read_object(&cmp_ctx, &obj)) {
HYPER_PRINTF("%s\n", "could not read attribute value");
return HYPER_ERR_DECODE;
}
switch (key) {
case 0: // fcap_lemna_density_0_1
if (cmp_object_as_float(&obj, &device->fcap_lemna_density_0_1)) {
device->fcap_lemna_density_0_1_set = 1;
} else {
HYPER_PRINTF("%s\n", "could not read value\n");
return HYPER_ERR_DECODE;
}
break;
case 1: // fcap_lemna_sensor_distance_0_1
if (cmp_object_as_float(&obj, &device->fcap_lemna_sensor_distance_0_1)) {
device->fcap_lemna_sensor_distance_0_1_set = 1;
} else {
HYPER_PRINTF("%s\n", "could not read value\n");
return HYPER_ERR_DECODE;
}
break;
default:
HYPER_PRINTF("%s\n", "attribute index out of bounds\n");
return HYPER_ERR_DECODE;
}
} else {
HYPER_PRINTF("%s\n", "could not read value\n");
return HYPER_ERR_DECODE;
}
}
return HYPER_OK;
}
// --- DISPATCH DEVICE ---
uint8_t hyper_device_31_dispatch(hyper_device_31_t * device) {
uint8_t count = 0;
return count;
}
#ifdef __cplusplus
}
#endif
#endif // __HYPER_DEVICE_CLASS_31__