Files
ESPC3-wireless/app/drivers/sertrf/device.h

198 lines
5.4 KiB
C
Raw Normal View History

2025-08-20 11:28:11 +08:00
#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"
2025-08-20 11:28:11 +08:00
#include "sys_log.h"
#define UART_ENABLE 1
#define BLE_ENABLE 1
#define WIFI_ENABLE 1
2025-08-20 11:28:11 +08:00
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,
2025-08-20 11:28:11 +08:00
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
};
2025-08-20 11:28:11 +08:00
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;
2025-08-20 11:28:11 +08:00
}init_device_t;
typedef struct
{
uint8_t embedded_device_type;
uint8_t pc_device_type;
uint8_t app_device_type;
2025-08-20 11:28:11 +08:00
sb_data_port_t* embedded_device;
sb_data_port_t* pc_device;
sb_data_port_t* app_device;
2025-08-20 11:28:11 +08:00
init_device_t init_device;
uint8_t connect_embedded;
uint8_t connect_pc;
2025-08-20 11:28:11 +08:00
// 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;
2025-08-20 11:28:11 +08:00
}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);
2025-08-20 11:28:11 +08:00
/**
* @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
2025-09-09 18:16:48 +08:00
* @param timeout
2025-08-20 11:28:11 +08:00
* @retval < 0
* @retval >= 0
*/
2025-09-09 18:16:48 +08:00
int embedded_device_read(device_t *port, void *buffer, uint32_t length, uint32_t timeout);
2025-08-20 11:28:11 +08:00
/**
* @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);