243 lines
6.3 KiB
C
243 lines
6.3 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 "../../config/app_config.h"
|
||
#include "../../config/board_config.h"
|
||
#include "sys_log.h"
|
||
|
||
#define PRODUCT0 0x24
|
||
#define PRODUCT1 0x78
|
||
#define VERSIONS 0X01
|
||
|
||
#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,
|
||
|
||
DATA_PORT_TYPE_RF_OFF = 25,
|
||
};
|
||
enum CONNECT_TYPE
|
||
{
|
||
DISCONNECT = 0,
|
||
CONNECT_UART,
|
||
CONNECT_BLE,
|
||
CONNECT_WIFI_TCP,
|
||
CONNECT_WIFI_UDP,
|
||
|
||
CONNECT_RF_OFF = 25,
|
||
};
|
||
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;
|
||
uint8_t app_device_type;
|
||
|
||
sb_data_port_t* embedded_device;
|
||
sb_data_port_t* pc_device;
|
||
sb_data_port_t* app_device;
|
||
|
||
init_device_t init_device;
|
||
|
||
uint8_t connect_embedded;
|
||
uint8_t connect_pc;
|
||
//射频信号是否开启 0开启 1关闭
|
||
uint8_t rf_flag_off;
|
||
uint8_t wifi_flag_off;
|
||
uint8_t ble_flag_off;
|
||
// int (*embedded_read)(device_t *port, void *buffer, uint32_t length);
|
||
// int (*embedded_write)(device_t *port, const void *data, uint32_t size);
|
||
uint8_t last_color;
|
||
|
||
// 每次刚连接ble都会将标志位置一 ,因为连接上app后,app会发送一段字符串,这段字符串我暂时用不到需要抛弃,不然会影响异常飞控固件升级
|
||
uint8_t ble_one_connect_flag;
|
||
}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
|
||
*/
|
||
void device_wifi_start(void);
|
||
|
||
/**
|
||
* @brief
|
||
*/
|
||
void device_wifi_stop(void);
|
||
/**
|
||
* @brief
|
||
*/
|
||
void device_ble_start(void);
|
||
|
||
/**
|
||
* @brief
|
||
*/
|
||
void device_ble_stop(void);
|
||
/**
|
||
* @brief 开启所有射频信号
|
||
*/
|
||
void rf_start(device_t *port);
|
||
|
||
/**
|
||
* @brief 关闭所有射频信号
|
||
*/
|
||
void rf_stop(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 读取数据长度
|
||
* @param timeout 超时时间
|
||
* @retval < 0 操作失败或在指定的时间内未满足指定的操作长度
|
||
* @retval >= 0 实际已缓存的长度
|
||
*/
|
||
int embedded_device_read(device_t *port, void *buffer, uint32_t length, uint32_t timeout);
|
||
/**
|
||
* @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);
|
||
|
||
uint8_t app_device_choice(device_t *port, uint8_t type);
|
||
int app_device_read(device_t *port, void *buffer, uint32_t length, uint32_t timeout);
|
||
int app_device_write(device_t *port, void *buffer, uint32_t length);
|
||
uint32_t app_device_get_rx_length(device_t *port); |