// vi:ft=c #ifndef NET_H #define NET_H #include #include #include typedef enum { DeviceInfo = 1, DeviceReport = 2, DeviceDestroy = 3, ControllerState = 4, } MessageCode; typedef struct { MessageCode code; uint16_t abs_count; uint16_t rel_count; uint16_t key_count; uint16_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]; uint16_t rel_id[REL_CNT]; uint16_t key_id[KEY_CNT]; } MessageDeviceInfo; #define MSS_DEVICE_INFO(abs, rel, key) (6 + abs * 22 + rel * 2 + key * 2) // MSS -> Message Serialized Size: // Size of the data of the message when serialized (no alignment / padding) typedef struct { MessageCode code; uint16_t abs_count; uint16_t rel_count; uint16_t key_count; uint32_t abs[ABS_CNT]; uint32_t rel[REL_CNT]; uint8_t key[KEY_CNT]; } MessageDeviceReport; #define MSS_DEVICE_REPORT(abs, rel, key) (6 + abs * 4 + rel * 4 + key * 1) typedef struct { MessageCode code; 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 { MessageCode code; MessageDeviceInfo device_info; MessageDeviceReport device_report; MessageControllerState controller_state; } Message; // 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); #endif