2022-08-29 18:06:25 -05:00
|
|
|
// vi: set ft=c
|
2022-08-27 19:29:43 -05:00
|
|
|
#ifndef NET_H
|
|
|
|
#define NET_H
|
2022-08-30 08:37:34 -05:00
|
|
|
#include <linux/input.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
2022-08-29 17:27:03 -05:00
|
|
|
|
|
|
|
typedef enum {
|
2022-08-30 08:37:34 -05:00
|
|
|
DeviceInfo = 1,
|
|
|
|
DeviceReport = 2,
|
|
|
|
DeviceDestroy = 3,
|
2022-08-29 17:27:03 -05:00
|
|
|
ControllerState = 4,
|
|
|
|
} MessageCode;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
MessageCode code;
|
|
|
|
|
2022-08-30 08:37:34 -05:00
|
|
|
uint8_t abs_count;
|
|
|
|
uint8_t rel_count;
|
|
|
|
uint8_t key_count;
|
|
|
|
|
|
|
|
uint8_t abs_id[ABS_CNT];
|
|
|
|
uint32_t abs_min[ABS_CNT];
|
|
|
|
uint32_t abs_max[ABS_CNT];
|
|
|
|
uint32_t abs_fuzz[ABS_CNT];
|
|
|
|
uint32_t abs_flat[ABS_CNT];
|
|
|
|
uint32_t abs_res[ABS_CNT];
|
|
|
|
|
|
|
|
uint8_t rel_id[REL_CNT];
|
|
|
|
|
|
|
|
uint8_t key_id[KEY_CNT];
|
2022-08-29 17:27:03 -05:00
|
|
|
} MessageDeviceInfo;
|
2022-08-30 08:37:34 -05:00
|
|
|
#define MSS_DEVICE_INFO(abs, rel, key) (3 + abs * 21 + rel * 1 + key * 1)
|
|
|
|
// MSS -> Message Serialized Size:
|
|
|
|
// Size of the data of the message when serialized (no alignment / padding)
|
2022-08-29 17:27:03 -05:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
MessageCode code;
|
|
|
|
} MessageDeviceReport;
|
|
|
|
#define MSS_DEVICE_REPORT 0
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
MessageCode code;
|
|
|
|
} MessageDeviceDestroy;
|
|
|
|
#define MSS_DEVICE_DESTROY 0
|
|
|
|
|
2022-08-30 08:37:34 -05:00
|
|
|
typedef struct {
|
2022-08-29 17:27:03 -05:00
|
|
|
MessageCode code;
|
2022-08-30 08:37:34 -05:00
|
|
|
|
2022-08-29 17:27:03 -05:00
|
|
|
uint8_t led[3];
|
|
|
|
uint8_t small_rumble;
|
|
|
|
uint8_t big_rumble;
|
|
|
|
uint8_t flash_on;
|
|
|
|
uint8_t flash_off;
|
|
|
|
} MessageControllerState;
|
|
|
|
#define MSS_CONTROLLER_STATE 7
|
|
|
|
|
|
|
|
typedef union {
|
2022-08-30 08:37:34 -05:00
|
|
|
MessageCode code;
|
|
|
|
MessageDeviceInfo device_info;
|
|
|
|
MessageDeviceReport device_report;
|
|
|
|
MessageDeviceDestroy device_destroy;
|
2022-08-29 17:27:03 -05:00
|
|
|
MessageControllerState controller_state;
|
|
|
|
} Message;
|
|
|
|
|
2022-08-30 08:37:34 -05:00
|
|
|
// Read a message from a buffer with a length, message goes into dst, returns -1 if a messsage couldn't be
|
|
|
|
// read
|
|
|
|
int msg_deserialize(const uint8_t *buf, size_t len, Message *dst);
|
|
|
|
// Write a message to a buffer with a length, return -1 if the message couldn't be written (buffer not big
|
|
|
|
// enough). Returns the length of the serialized message if succeeded.
|
|
|
|
int msg_serialize(uint8_t *buf, size_t len, Message *msg);
|
2022-08-27 19:29:43 -05:00
|
|
|
|
|
|
|
#endif
|