-
Notifications
You must be signed in to change notification settings - Fork 0
/
net.h
133 lines (116 loc) · 2.82 KB
/
net.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
// Generated file, do not edit (its not like it'll explode if you do, but its better not to)
#ifndef NET_H
#define NET_H
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
typedef unsigned char byte;
typedef uint64_t MsgMagic;
#define MSG_MAGIC_SIZE sizeof(MsgMagic)
static const MsgMagic MSG_MAGIC_START = 0xCAFEF00DBEEFDEAD;
static const MsgMagic MSG_MAGIC_END = 0xF00DBEEFCAFEDEAD;
typedef struct Abs {
uint16_t id;
uint32_t min;
uint32_t max;
uint32_t fuzz;
uint32_t flat;
uint32_t res;
} Abs;
typedef struct Key {
uint16_t id;
} Key;
typedef struct Rel {
uint16_t id;
} Rel;
typedef struct TagList {
struct {
uint16_t len;
struct Tag *data;
} tags;
} TagList;
typedef struct Tag {
struct {
uint16_t len;
char *data;
} name;
} Tag;
// Device
typedef enum DeviceTag {
DeviceTagNone = 0,
DeviceTagInfo = 1,
DeviceTagReport = 2,
DeviceTagControllerState = 3,
DeviceTagRequest = 4,
DeviceTagDestroy = 5,
} DeviceTag;
typedef struct DeviceInfo {
DeviceTag tag;
uint8_t slot;
uint8_t index;
struct {
uint8_t len;
struct Abs data[64];
} abs;
struct {
uint8_t len;
struct Rel data[16];
} rel;
struct {
uint16_t len;
struct Key data[768];
} key;
} DeviceInfo;
typedef struct DeviceReport {
DeviceTag tag;
uint8_t slot;
uint8_t index;
struct {
uint8_t len;
uint32_t data[64];
} abs;
struct {
uint8_t len;
uint32_t data[16];
} rel;
struct {
uint16_t len;
uint8_t data[768];
} key;
} DeviceReport;
typedef struct DeviceControllerState {
DeviceTag tag;
uint16_t index;
uint8_t led[3];
uint8_t small_rumble;
uint8_t big_rumble;
uint8_t flash_on;
uint8_t flash_off;
} DeviceControllerState;
typedef struct DeviceRequest {
DeviceTag tag;
struct {
uint16_t len;
struct TagList *data;
} requests;
uint64_t _version;
} DeviceRequest;
typedef struct DeviceDestroy {
DeviceTag tag;
uint16_t index;
} DeviceDestroy;
typedef union DeviceMessage {
DeviceTag tag;
DeviceInfo info;
DeviceReport report;
DeviceControllerState controller_state;
DeviceRequest request;
DeviceDestroy destroy;
} DeviceMessage;
// Serialize the message msg to buffer dst of size len, returns the length of the serialized message, or -1 on error (buffer overflow)
int msg_device_serialize(byte *dst, size_t len, DeviceMessage *msg);
// Deserialize the message in the buffer src of size len into dst, return the length of the serialized message or -1 on error.
int msg_device_deserialize(const byte *src, size_t len, DeviceMessage *dst);
// Free the message (created by msg_device_deserialize)
void msg_device_free(DeviceMessage *msg);
#endif