188 lines
5.0 KiB
C
188 lines
5.0 KiB
C
#pragma once
|
|
|
|
#include "../data_port/uart/uart_port.h"
|
|
#include "../data_port/sb_data_port.h"
|
|
#include "../data_port/ble_spp/ble_spp_server.h"
|
|
#include "../data_port/ble_spp/ble_spp_client.h"
|
|
#include "../data_port/socket_inet/socket_inet_server_shell.h"
|
|
#include "../data_port/socket_inet/wifi.h"
|
|
#include "../data_port/socket_inet/socket_inet.h"
|
|
#include "sys_log.h"
|
|
|
|
#define UART_ENABLE 1
|
|
#define BLE_ENABLE 1
|
|
#define WIFI_ENABLE 1
|
|
|
|
enum DEVICE_ERROR
|
|
{
|
|
DEVICE_OK = 0,
|
|
DEVICE_UART_ERROR,
|
|
DEVICE_BLE_ERROR,
|
|
DEVICE_WIFI_ERROR,
|
|
DEVICE_EMBEDDED_ERROR,
|
|
DEVICE_PC_ERROR,
|
|
|
|
DEVICE_WRN_EMBEDDED_TYPE = 110,
|
|
DEVICE_WRN_PC_TYPE
|
|
|
|
};
|
|
enum DATA_PORT_TYPE
|
|
{
|
|
DATA_PORT_TYPE_NONE = 0,
|
|
DATA_PORT_TYPE_UART,
|
|
DATA_PORT_TYPE_WIFI_TCP,
|
|
DATA_PORT_TYPE_WIFI_UDP,
|
|
DATA_PORT_TYPE_BLE_CMD,
|
|
DATA_PORT_TYPE_BLE_VAL
|
|
};
|
|
enum CONNECT_TYPE
|
|
{
|
|
DISCONNECT = 0,
|
|
CONNECT_UART,
|
|
CONNECT_BLE,
|
|
CONNECT_WIFI_TCP,
|
|
CONNECT_WIFI_UDP,
|
|
};
|
|
enum WIFI_MODE
|
|
{
|
|
AP_TCP,
|
|
STA_TCP,
|
|
AP_UDP,
|
|
STA_UDP
|
|
};
|
|
typedef struct
|
|
{
|
|
sb_data_port_t* uart_port;
|
|
sb_data_port_t* ble_spp_server_cmd;
|
|
sb_data_port_t* ble_spp_server_val;
|
|
sb_data_port_t* ble_spp_client_cmd;
|
|
sb_data_port_t* ble_spp_client_val;
|
|
sb_data_port_t* wifi_tcp;
|
|
sb_data_port_t* wifi_udp;
|
|
uint8_t wifi_mode;
|
|
|
|
socket_listen_tcp_t tcp_listen;
|
|
}init_device_t;
|
|
|
|
typedef struct
|
|
{
|
|
uint8_t embedded_device_type;
|
|
uint8_t pc_device_type;
|
|
sb_data_port_t* embedded_device;
|
|
sb_data_port_t* pc_device;
|
|
init_device_t init_device;
|
|
|
|
uint8_t connect_embedded;
|
|
uint8_t connect_pc;
|
|
// int (*embedded_read)(device_t *port, void *buffer, uint32_t length);
|
|
// int (*embedded_write)(device_t *port, const void *data, uint32_t size);
|
|
|
|
|
|
}device_t;
|
|
|
|
/**
|
|
* @brief 初始化设备
|
|
*
|
|
* @param port 由对应的驱动提供的绑定接口获得的句柄
|
|
* @retval 0 成功
|
|
*/
|
|
uint8_t device_init(device_t *port);
|
|
/**
|
|
* @brief UART 初始化
|
|
*
|
|
* @param port 由对应的驱动提供的绑定接口获得的句柄
|
|
* @retval 0 成功
|
|
*/
|
|
uint8_t uart_init(init_device_t *port);
|
|
/**
|
|
* @brief 蓝牙 初始化
|
|
*
|
|
* @param port 由对应的驱动提供的绑定接口获得的句柄
|
|
* @retval 0 成功
|
|
*/
|
|
uint8_t ble_init(init_device_t *port);
|
|
/**
|
|
* @brief WIFI 初始化
|
|
*
|
|
* @param port 由对应的驱动提供的绑定接口获得的句柄
|
|
* @retval 0 成功
|
|
*/
|
|
uint8_t wifi_init(init_device_t *port);
|
|
/**
|
|
* @brief WIFI 模式切换
|
|
*/
|
|
void wifi_mode_switch(init_device_t *port);
|
|
/**
|
|
* @brief 嵌入式设备数据接口
|
|
*
|
|
* @param port 由对应的驱动提供的绑定接口获得的句柄
|
|
* @param type 对应的数据接口类型
|
|
* @retval 0 成功
|
|
*/
|
|
uint8_t embedded_device_choice(device_t *port, uint8_t type);
|
|
/**
|
|
* @brief PC OR 手机数据接口
|
|
*
|
|
* @param port 由对应的驱动提供的绑定接口获得的句柄
|
|
* @param type 对应的数据接口类型
|
|
* @retval 0 成功
|
|
*/
|
|
uint8_t pc_device_choice(device_t *port, uint8_t type);
|
|
/**
|
|
* @brief 嵌入式设备数据接口读操作
|
|
*
|
|
* @param port 由对应的驱动提供的绑定接口获得的句柄
|
|
* @param buffer 读取数据缓存
|
|
* @param length 读取数据长度
|
|
* @retval < 0 操作失败或在指定的时间内未满足指定的操作长度
|
|
* @retval >= 0 实际已缓存的长度
|
|
*/
|
|
int embedded_device_read(device_t *port, void *buffer, uint32_t length);
|
|
/**
|
|
* @brief 嵌入式设备数据接口写操作
|
|
*
|
|
* @param port 由对应的驱动提供的绑定接口获得的句柄
|
|
* @param data 写入数据
|
|
* @param size 写入数据长度
|
|
* @retval < 0 操作失败或在指定的时间内未满足指定的操作长度
|
|
* @retval >= 0 实际已缓存的长度
|
|
*/
|
|
int embedded_device_write(device_t *port, void *buffer, uint32_t length);
|
|
/**
|
|
* @brief 嵌入式设备数据接口写操作
|
|
*
|
|
* @param port 由对应的驱动提供的绑定接口获得的句柄
|
|
* @param data 写入数据
|
|
* @param size 写入数据长度
|
|
* @retval 缓存中可读取的字节数
|
|
*/
|
|
uint32_t embedded_device_get_rx_length(device_t *port);
|
|
/**
|
|
* @brief PC OR 手机数据接口读操作
|
|
*
|
|
* @param port 由对应的驱动提供的绑定接口获得的句柄
|
|
* @param buffer 读取数据缓存
|
|
* @param length 读取数据长度
|
|
* @retval < 0 操作失败或在指定的时间内未满足指定的操作长度
|
|
* @retval >= 0 实际已缓存的长度
|
|
*/
|
|
int pc_device_read(device_t *port, void *buffer, uint32_t length);
|
|
/**
|
|
* @brief PC OR 手机数据接口写操作
|
|
*
|
|
* @param port 由对应的驱动提供的绑定接口获得的句柄
|
|
* @param data 写入数据
|
|
* @param size 写入数据长度
|
|
* @retval < 0 操作失败或在指定的时间内未满足指定的操作长度
|
|
* @retval >= 0 实际已缓存的长度
|
|
*/
|
|
int pc_device_write(device_t *port, void *buffer, uint32_t length);
|
|
/**
|
|
* @brief PC OR 手机数据接口写操作
|
|
*
|
|
* @param port 由对应的驱动提供的绑定接口获得的句柄
|
|
* @param data 写入数据
|
|
* @param size 写入数据长度
|
|
* @retval 缓存中可读取的字节数
|
|
*/
|
|
uint32_t pc_device_get_rx_length(device_t *port); |