Files
2026-08-24 10:03:24 +08:00

85 lines
1.4 KiB
C

#ifndef _DATASERVER_MESSAGE_H_
#define _DATASERVER_MESSAGE_H_
#include "stdint.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Message head
*/
typedef struct {
int magic;
#define DS_MAGIC ((int)('d'<<24|'a'<<16|'s'<<8|'r'))
int type;
#define DS_T_DATA 0
#define DS_T_CNTL 1
#define DS_T_RESP 2
#define DS_T_EVNT 3
/**
* Specifies the number of bytes of the body.
*/
int size;
/**
* Contains the different types of message content, as defined below.
*/
uint8_t body[0];
} ds_msg_head_t;
/**
* @brief Message data
*/
typedef struct {
/**
* The data size is specified by field "size" in ds_msg_head_t.
* Details of different device data will be defined in "dataserver_data_xxx.h"
*/
uint8_t data[0];
} ds_msg_data_t;
/**
* @brief Message control
*/
typedef struct {
/**
* A NULL terminated string.
* Detailed commands definition can be found in "dataserver_cmd_resp.h".
*/
uint8_t cmd[0];
} ds_msg_cntl_t;
/**
* @brief Message response (common)
*/
typedef struct {
/**
* A simple reply of state, "ok" or "ko".
*/
uint8_t resp[3];
} ds_msg_resp_comm_t;
/**
* @brief Message event
*/
typedef struct {
/**
* A NULL terminated string.
* Specifies the name of the event.
* Details of events can be found in "dataserver_event.h"
*/
uint8_t event[0];
} ds_msg_evnt_t;
#ifdef __cplusplus
}
#endif
#endif