除了显示驱动,其余全部测试通过
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
#ifndef MQTT_PROTOCOL_H
|
||||
#define MQTT_PROTOCOL_H
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
/*
|
||||
* 小智MQTT消息类型
|
||||
*/
|
||||
enum mqtt_protocol_message_type
|
||||
{
|
||||
|
||||
MQTT_PROTOCOL_MSG_UNKNOWN = 0,
|
||||
|
||||
MQTT_PROTOCOL_MSG_HELLO,
|
||||
|
||||
MQTT_PROTOCOL_MSG_TTS,
|
||||
|
||||
MQTT_PROTOCOL_MSG_STT,
|
||||
|
||||
MQTT_PROTOCOL_MSG_LLM,
|
||||
|
||||
MQTT_PROTOCOL_MSG_LISTEN,
|
||||
|
||||
MQTT_PROTOCOL_MSG_GOODBYE
|
||||
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* 小智MQTT消息状态
|
||||
*/
|
||||
enum mqtt_protocol_message_state
|
||||
{
|
||||
|
||||
MQTT_PROTOCOL_STATE_NONE = 0,
|
||||
|
||||
MQTT_PROTOCOL_STATE_START,
|
||||
|
||||
MQTT_PROTOCOL_STATE_SENTENCE_START,
|
||||
|
||||
MQTT_PROTOCOL_STATE_STOP,
|
||||
|
||||
MQTT_PROTOCOL_STATE_DETECT
|
||||
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* 小智MQTT消息
|
||||
*/
|
||||
struct mqtt_protocol_message
|
||||
{
|
||||
|
||||
enum mqtt_protocol_message_type type;
|
||||
|
||||
enum mqtt_protocol_message_state state;
|
||||
|
||||
int has_code;
|
||||
|
||||
int code;
|
||||
|
||||
int has_version;
|
||||
|
||||
int version;
|
||||
|
||||
char transport[16];
|
||||
|
||||
char session_id[64];
|
||||
|
||||
char text[160];
|
||||
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* 消息回调
|
||||
*
|
||||
* 返回0表示协议层已处理, 返回-1表示无法识别
|
||||
*/
|
||||
int mqtt_protocol_handle_message
|
||||
(
|
||||
const char *topic,
|
||||
const uint8_t *payload,
|
||||
uint32_t len
|
||||
);
|
||||
|
||||
|
||||
/*
|
||||
* 发送hello, 申请会话
|
||||
*/
|
||||
int mqtt_protocol_send_hello(void);
|
||||
|
||||
|
||||
/*
|
||||
* 发送监听开始
|
||||
*/
|
||||
int mqtt_protocol_send_listen_start(void);
|
||||
|
||||
|
||||
/*
|
||||
* 发送监听停止
|
||||
*/
|
||||
int mqtt_protocol_send_listen_stop(void);
|
||||
|
||||
|
||||
/*
|
||||
* 发送中止
|
||||
*/
|
||||
int mqtt_protocol_send_abort(void);
|
||||
|
||||
|
||||
/*
|
||||
* 发送bye
|
||||
*/
|
||||
int mqtt_protocol_send_goodbye(void);
|
||||
|
||||
|
||||
/*
|
||||
* 获取当前会话ID
|
||||
*/
|
||||
const char *mqtt_protocol_session_id(void);
|
||||
|
||||
|
||||
/*
|
||||
* 设置协议消息回调
|
||||
*/
|
||||
typedef void (*mqtt_protocol_callback_t)
|
||||
(
|
||||
const struct mqtt_protocol_message *message
|
||||
);
|
||||
|
||||
void mqtt_protocol_set_callback(mqtt_protocol_callback_t callback);
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user