添加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"); 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"); SYS_LOG_INF("device init success");
return DEVICE_OK; 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) uint8_t embedded_device_choice(device_t *port, uint8_t type)
{ {
//端口与PC一致 //端口与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"); SYS_LOG_WRN("pc Port consistency");
return DEVICE_WRN_EMBEDDED_TYPE; 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; port->embedded_device_type = type;
switch (port->embedded_device_type) switch (port->embedded_device_type)
{ {
case DATA_PORT_TYPE_NONE:
port->embedded_device = NULL;
break;
case DATA_PORT_TYPE_UART: case DATA_PORT_TYPE_UART:
port->embedded_device = port->init_device.uart_port; port->embedded_device = port->init_device.uart_port;
break; break;
@@ -293,7 +302,7 @@ uint8_t embedded_device_choice(device_t *port, uint8_t type)
break; break;
} }
if(port->embedded_device == NULL) if(port->embedded_device == NULL && type != DATA_PORT_TYPE_NONE)
{ {
SYS_LOG_WRN("embedded device choice error"); SYS_LOG_WRN("embedded device choice error");
return DEVICE_EMBEDDED_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) 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); return sb_data_port_read(port->embedded_device, buffer, length, timeout);
} }
int embedded_device_write(device_t *port, void *buffer, uint32_t length) 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); return sb_data_port_write(port->embedded_device, buffer, length, 0);
} }
uint32_t embedded_device_get_rx_length(device_t *port) 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); 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) uint8_t pc_device_choice(device_t *port, uint8_t type)
{ {
//端口与embedded一致 //端口与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"); SYS_LOG_WRN("embedded Port consistency");
return DEVICE_WRN_PC_TYPE; 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; port->pc_device_type = type;
switch (port->pc_device_type) switch (port->pc_device_type)
{ {
case DATA_PORT_TYPE_NONE:
port->pc_device = NULL;
break;
case DATA_PORT_TYPE_UART: case DATA_PORT_TYPE_UART:
port->pc_device = port->init_device.uart_port; port->pc_device = port->init_device.uart_port;
break; break;
@@ -362,7 +383,7 @@ uint8_t pc_device_choice(device_t *port, uint8_t type)
break; break;
} }
if(port->pc_device == NULL) if(port->pc_device == NULL && type != DATA_PORT_TYPE_NONE)
{ {
SYS_LOG_WRN("pc device choice error"); SYS_LOG_WRN("pc device choice error");
return DEVICE_PC_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) 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); return sb_data_port_read(port->pc_device, buffer, length, 0);
} }
int pc_device_write(device_t *port, void *buffer, uint32_t length) int pc_device_write(device_t *port, void *buffer, uint32_t length)
{ {
if(port->pc_device == NULL)
return -1;
if(port->connect_pc) if(port->connect_pc)
return sb_data_port_write(port->pc_device, buffer, length, 0); 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) 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); 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);
}

View File

@@ -68,8 +68,12 @@ typedef struct
{ {
uint8_t embedded_device_type; uint8_t embedded_device_type;
uint8_t pc_device_type; uint8_t pc_device_type;
uint8_t app_device_type;
sb_data_port_t* embedded_device; sb_data_port_t* embedded_device;
sb_data_port_t* pc_device; sb_data_port_t* pc_device;
sb_data_port_t* app_device;
init_device_t init_device; init_device_t init_device;
uint8_t connect_embedded; uint8_t connect_embedded;
@@ -187,3 +191,8 @@ int pc_device_write(device_t *port, void *buffer, uint32_t length);
* @retval 缓存中可读取的字节数 * @retval 缓存中可读取的字节数
*/ */
uint32_t pc_device_get_rx_length(device_t *port); 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);

View File

@@ -16,6 +16,10 @@ typedef struct
int total_size; int total_size;
}ota_u_t; }ota_u_t;
/**
* @brief 获取当前ota信息
*/
void get_partition_status(ota_u_t* otau);
/** /**
* @brief OTA初始化 * @brief OTA初始化
* *

View File

@@ -20,6 +20,8 @@ void sertrf_init(void)
// 协议初始化 // 协议初始化
sertrf.resend_read_mutex = xSemaphoreCreateMutex(); sertrf.resend_read_mutex = xSemaphoreCreateMutex();
resend_init(&sertrf.resend_device, resend_send, resend_recv, resend_get_length,resend_user_parse); resend_init(&sertrf.resend_device, resend_send, resend_recv, resend_get_length,resend_user_parse);
//OAT信息获取
get_partition_status(&sertrf.otau);
//线程启动 //线程启动
sertrf_start(); sertrf_start();
} }
@@ -37,6 +39,12 @@ void sertrf_start(void)
NULL, NULL,
4096, 4096,
20); 20);
os_thread_create(&sertrf.app_thread,
"app_thread",
app_thread,
NULL,
4096,
15);
os_thread_create(&sertrf.task_thread, os_thread_create(&sertrf.task_thread,
"task_thread", "task_thread",
task_thread, task_thread,
@@ -60,7 +68,7 @@ void embedded_thread(void* arg)
// SYS_LOG_INF("data : %s", data); // SYS_LOG_INF("data : %s", data);
pc_device_write(&sertrf.device, data, embedded_size); pc_device_write(&sertrf.device, data, embedded_size);
} }
printf_chill_time(10,1000); // printf_chill_time(10,1000);
//需要添加一些延时,否则会卡死,导致看门狗复位 //需要添加一些延时,否则会卡死,导致看门狗复位
// vTaskDelay(( TickType_t ) 1000 / configTICK_RATE_HZ); // vTaskDelay(( TickType_t ) 1000 / configTICK_RATE_HZ);
@@ -87,7 +95,26 @@ void pc_thread(void* arg)
os_thread_sleep(1); os_thread_sleep(1);
} }
} }
void app_thread(void* arg)
{
while (true)
{
switch(0)
{
case 0:
break;
case 1:
break;
default:
break;
}
resend_recv_data(&sertrf.resend_device,0);
os_thread_sleep(1);
}
}
void task_thread(void* arg) void task_thread(void* arg)
{ {
while(true) while(true)
@@ -103,16 +130,16 @@ void task_thread(void* arg)
switch(get_protocol_status()) switch(get_protocol_status())
{ {
case PROTOCOL_STATUS_OK: case PROTOCOL_STATUS_OK:
rgb_color_change(0, sertrf.device.last_color); rgb_color_change(1, sertrf.device.last_color);
break; break;
case PROTOCOL_STATUS_NO_DATA: case PROTOCOL_STATUS_NO_DATA:
rgb_color_change(0, RGB_COLOR_RAD); rgb_color_change(1, RGB_COLOR_RAD);
break; break;
case PROTOCOL_STATUS_TYPE_IDLE: case PROTOCOL_STATUS_TYPE_IDLE:
rgb_color_change(0, RGB_COLOR_RAD); rgb_color_change(1, RGB_COLOR_RAD);
break; break;
case PROTOCOL_STATUS_ANALYSIS_ERROR: case PROTOCOL_STATUS_ANALYSIS_ERROR:
rgb_color_change(0, RGB_COLOR_RAD); rgb_color_change(1, RGB_COLOR_RAD);
break; break;
default: default:
break; break;
@@ -173,12 +200,12 @@ void pc_link_rgb_color(device_t* device)
} }
if(device->connect_pc == DISCONNECT) if(device->connect_pc == DISCONNECT)
{ {
rgb_update_cyle(50); rgb_update_cyle(0,50);
} }
else if(device->connect_pc){ else if(device->connect_pc){
rgb_update_cyle(888); rgb_update_cyle(0,888);
}else{ }else{
rgb_update_cyle(500); rgb_update_cyle(0,500);
} }
} }
@@ -207,7 +234,7 @@ void printf_chill_time(uint8_t chill_time, uint16_t type)
int resend_send(void* data, uint16_t len, int timeout) int resend_send(void* data, uint16_t len, int timeout)
{ {
return embedded_device_write(&sertrf.device, data, len); return app_device_write(&sertrf.device, data, len);
} }
int resend_recv(void* data, uint16_t len, int timeout) int resend_recv(void* data, uint16_t len, int timeout)
{ {
@@ -215,14 +242,14 @@ int resend_recv(void* data, uint16_t len, int timeout)
if (xSemaphoreTake(sertrf.resend_read_mutex, portMAX_DELAY) == pdTRUE) if (xSemaphoreTake(sertrf.resend_read_mutex, portMAX_DELAY) == pdTRUE)
{ {
ret = embedded_device_read(&sertrf.device, data, len,timeout); ret = app_device_read(&sertrf.device, data, len,timeout);
xSemaphoreGive(sertrf.resend_read_mutex); xSemaphoreGive(sertrf.resend_read_mutex);
} }
return ret; return ret;
} }
int resend_get_length(void) int resend_get_length(void)
{ {
return embedded_device_get_rx_length(&sertrf.device); return app_device_get_rx_length(&sertrf.device);
} }
void resend_user_parse(void *resend_device) void resend_user_parse(void *resend_device)
{ {

View File

@@ -12,10 +12,12 @@ typedef struct
os_thread_t embedded_thread; os_thread_t embedded_thread;
os_thread_t pc_thread; os_thread_t pc_thread;
os_thread_t task_thread; os_thread_t task_thread;
os_thread_t app_thread;
ota_u_t otau; ota_u_t otau;
resend_device_t resend_device; resend_device_t resend_device;
SemaphoreHandle_t resend_read_mutex; SemaphoreHandle_t resend_read_mutex;
}sertrf_t; }sertrf_t;
/** /**
@@ -47,6 +49,10 @@ void embedded_thread(void* arg);
* @brief pc thread * @brief pc thread
*/ */
void pc_thread(void* arg); void pc_thread(void* arg);
/**
* @brief app thread
*/
void app_thread(void* arg);
/** /**
* @brief task thread * @brief task thread
*/ */