添加app对接接口已经修改灯显示

This commit is contained in:
OPTOC
2025-09-15 16:48:12 +08:00
parent 11bdfc80d2
commit 15f2af329a
5 changed files with 159 additions and 18 deletions

View File

@@ -46,6 +46,12 @@ uint8_t device_init(device_t *port)
{
SYS_LOG_ERR("pc device choice error");
}
res = app_device_choice(port, DATA_PORT_TYPE_BLE_CMD);
if(res == DEVICE_EMBEDDED_ERROR)
{
SYS_LOG_ERR("app device choice error");
}
SYS_LOG_INF("device init success");
return DEVICE_OK;
}
@@ -265,7 +271,7 @@ void wifi_mode_switch(init_device_t *port)
uint8_t embedded_device_choice(device_t *port, uint8_t type)
{
//端口与PC一致
if(port->pc_device_type == type)
if((port->pc_device_type == type || port->app_device_type == type) && type != DATA_PORT_TYPE_NONE)
{
SYS_LOG_WRN("pc Port consistency");
return DEVICE_WRN_EMBEDDED_TYPE;
@@ -274,6 +280,9 @@ uint8_t embedded_device_choice(device_t *port, uint8_t type)
port->embedded_device_type = type;
switch (port->embedded_device_type)
{
case DATA_PORT_TYPE_NONE:
port->embedded_device = NULL;
break;
case DATA_PORT_TYPE_UART:
port->embedded_device = port->init_device.uart_port;
break;
@@ -293,7 +302,7 @@ uint8_t embedded_device_choice(device_t *port, uint8_t type)
break;
}
if(port->embedded_device == NULL)
if(port->embedded_device == NULL && type != DATA_PORT_TYPE_NONE)
{
SYS_LOG_WRN("embedded device choice error");
return DEVICE_EMBEDDED_ERROR;
@@ -304,15 +313,24 @@ uint8_t embedded_device_choice(device_t *port, uint8_t type)
int embedded_device_read(device_t *port, void *buffer, uint32_t length, uint32_t timeout)
{
if(port->embedded_device == NULL)
return -1;
return sb_data_port_read(port->embedded_device, buffer, length, timeout);
}
int embedded_device_write(device_t *port, void *buffer, uint32_t length)
{
if(port->embedded_device == NULL)
return -1;
return sb_data_port_write(port->embedded_device, buffer, length, 0);
}
uint32_t embedded_device_get_rx_length(device_t *port)
{
if(port->embedded_device == NULL)
return 0;
return sb_data_port_get_rx_length(port->embedded_device);
}
@@ -334,7 +352,7 @@ static uint8_t pc_device_choice_inside(device_t *port, uint8_t type, uint8_t con
uint8_t pc_device_choice(device_t *port, uint8_t type)
{
//端口与embedded一致
if(port->embedded_device_type == type)
if((port->embedded_device_type == type || port->app_device_type == type) && type != DATA_PORT_TYPE_NONE)
{
SYS_LOG_WRN("embedded Port consistency");
return DEVICE_WRN_PC_TYPE;
@@ -343,6 +361,9 @@ uint8_t pc_device_choice(device_t *port, uint8_t type)
port->pc_device_type = type;
switch (port->pc_device_type)
{
case DATA_PORT_TYPE_NONE:
port->pc_device = NULL;
break;
case DATA_PORT_TYPE_UART:
port->pc_device = port->init_device.uart_port;
break;
@@ -362,7 +383,7 @@ uint8_t pc_device_choice(device_t *port, uint8_t type)
break;
}
if(port->pc_device == NULL)
if(port->pc_device == NULL && type != DATA_PORT_TYPE_NONE)
{
SYS_LOG_WRN("pc device choice error");
return DEVICE_PC_ERROR;
@@ -372,11 +393,17 @@ uint8_t pc_device_choice(device_t *port, uint8_t type)
}
int pc_device_read(device_t *port, void *buffer, uint32_t length)
{
if (port->pc_device == NULL)
return -1;
return sb_data_port_read(port->pc_device, buffer, length, 0);
}
int pc_device_write(device_t *port, void *buffer, uint32_t length)
{
if(port->pc_device == NULL)
return -1;
if(port->connect_pc)
return sb_data_port_write(port->pc_device, buffer, length, 0);
@@ -384,5 +411,73 @@ int pc_device_write(device_t *port, void *buffer, uint32_t length)
}
uint32_t pc_device_get_rx_length(device_t *port)
{
if(port->pc_device == NULL)
return 0;
return sb_data_port_get_rx_length(port->pc_device);
}
uint8_t app_device_choice(device_t *port, uint8_t type)
{
//端口与PC一致
if((port->pc_device_type == type || port->embedded_device_type == type) && type != DATA_PORT_TYPE_NONE)
{
SYS_LOG_WRN("pc Port consistency");
return DEVICE_WRN_EMBEDDED_TYPE;
}
port->app_device_type = type;
switch (port->app_device_type)
{
case DATA_PORT_TYPE_NONE:
port->app_device = NULL;
break;
case DATA_PORT_TYPE_UART:
port->app_device = port->init_device.uart_port;
break;
case DATA_PORT_TYPE_WIFI_TCP:
port->app_device = port->init_device.wifi_tcp;
break;
case DATA_PORT_TYPE_WIFI_UDP:
port->app_device = port->init_device.wifi_udp;
break;
case DATA_PORT_TYPE_BLE_CMD:
port->app_device = port->init_device.ble_spp_server_cmd;
break;
case DATA_PORT_TYPE_BLE_VAL:
port->app_device = port->init_device.ble_spp_server_val;
break;
default:
break;
}
if(port->app_device == NULL && type != DATA_PORT_TYPE_NONE)
{
SYS_LOG_WRN("embedded device choice error");
return DEVICE_EMBEDDED_ERROR;
}
return DEVICE_OK;
}
int app_device_read(device_t *port, void *buffer, uint32_t length, uint32_t timeout)
{
if(port->app_device == NULL)
return -1;
return sb_data_port_read(port->app_device, buffer, length, timeout);
}
int app_device_write(device_t *port, void *buffer, uint32_t length)
{
if(port->app_device == NULL)
return -1;
return sb_data_port_write(port->app_device, buffer, length, 0);
}
uint32_t app_device_get_rx_length(device_t *port)
{
if(port->app_device == NULL)
return 0;
return sb_data_port_get_rx_length(port->app_device);
}