Compare commits
23 Commits
a3e823c57a
...
data_handl
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ed435b4cc8 | ||
|
|
d43b1aca73 | ||
|
|
f798c1e230 | ||
|
|
4308315fa2 | ||
|
|
b53898c6b5 | ||
|
|
5932e44c3e | ||
|
|
2800c2660b | ||
|
|
d192e3e40f | ||
|
|
9b9964439c | ||
|
|
b479ee103a | ||
|
|
4d633454e9 | ||
|
|
cdff6c812a | ||
|
|
d54455dee9 | ||
|
|
9754257a40 | ||
|
|
ee28ccf5a7 | ||
|
|
21b4e242a0 | ||
|
|
793817d00e | ||
|
|
88dadb4f0e | ||
|
|
a61905726e | ||
|
|
a8a5bb61af | ||
|
|
1e15f28f72 | ||
|
|
c026c49fac | ||
|
|
ce9fac6b32 |
@@ -32,6 +32,7 @@ list(APPEND srcs "drivers/sertrf/sertrf.c")
|
||||
list(APPEND srcs "drivers/sertrf/device.c")
|
||||
list(APPEND srcs "drivers/sertrf/key.c")
|
||||
list(APPEND srcs "drivers/sertrf/ota_u.c")
|
||||
list(APPEND srcs "drivers/sertrf/tool.c")
|
||||
list(APPEND srcs "drivers/sertrf/ring_buffer.c")
|
||||
list(APPEND srcs "drivers/sertrf/protocol/MSP.c")
|
||||
list(APPEND srcs "drivers/sertrf/protocol/p_protocol.c")
|
||||
|
||||
@@ -769,7 +769,7 @@ static void _ble_spp_server_init(void)
|
||||
{
|
||||
|
||||
s_init_param.manufacturer_data(s_manufacturer_data);
|
||||
printf("set manufacturer data %d %d\n",s_manufacturer_data[0],s_manufacturer_data[1]);
|
||||
// SYS_LOG_DBG("set manufacturer data %d %d\n",s_manufacturer_data[0],s_manufacturer_data[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -60,6 +60,7 @@ typedef struct
|
||||
|
||||
typedef enum
|
||||
{
|
||||
RC_OFF_NONE,
|
||||
WIFI_NETIF_MODE_AP,
|
||||
WIFI_NETIF_MODE_STA,
|
||||
} wifi_netif_mode_t;
|
||||
|
||||
@@ -6,15 +6,20 @@ rmt_transmit_config_t tx_config = {
|
||||
.loop_count = 0, // no transfer loop
|
||||
};
|
||||
|
||||
// 颜色结构体
|
||||
static rgb_color_t expression[EXAMPLE_LED_NUMBERS];
|
||||
static rgb_color_t expression_lat[EXAMPLE_LED_NUMBERS] = {0};
|
||||
// 延时计数
|
||||
static uint16_t rgb_toggle_cnt[EXAMPLE_LED_NUMBERS] = {10,10};
|
||||
static uint16_t rgb_toggle_cnt_lat[EXAMPLE_LED_NUMBERS] = {0};
|
||||
static uint16_t rgb_toggle_cnt_lat[EXAMPLE_LED_NUMBERS] = {2000,2000};
|
||||
|
||||
static uint8_t led_strip_pixels[EXAMPLE_LED_NUMBERS * 3];
|
||||
uint16_t toggle_cycle = 1000;
|
||||
// 翻转标志位
|
||||
bool toggle_flag[EXAMPLE_LED_NUMBERS] = {true,true};
|
||||
bool toggle_flag_lat[EXAMPLE_LED_NUMBERS] = {true,true};
|
||||
|
||||
rgb_color_t rgb_color_none = {0,0,0,0,0,1,0,RGB_COLOR_NONE};
|
||||
rgb_color_t rgb_color_rad = {0,255,0,0,0,1,0,RGB_COLOR_RAD};
|
||||
rgb_color_t rgb_color_orange = {0,255,80,0,0,1,0,RGB_COLOR_ORANGE};
|
||||
rgb_color_t rgb_color_green = {0,0,255,0,0,1,0,RGB_COLOR_GREEN};
|
||||
@@ -95,39 +100,47 @@ void rgb_update_cyle(uint8_t index, uint16_t cyle)
|
||||
}
|
||||
void rgb_color_change(uint8_t index, uint8_t color)
|
||||
{
|
||||
switch(color)
|
||||
{
|
||||
case RGB_COLOR_RAD:
|
||||
memcpy(&expression[index], &rgb_color_rad, sizeof(rgb_color_rad));
|
||||
break;
|
||||
case RGB_COLOR_ORANGE:
|
||||
memcpy(&expression[index], &rgb_color_orange, sizeof(rgb_color_orange));
|
||||
break;
|
||||
case RGB_COLOR_GREEN:
|
||||
memcpy(&expression[index], &rgb_color_green, sizeof(rgb_color_green));
|
||||
break;
|
||||
case RGB_COLOR_WHITE:
|
||||
memcpy(&expression[index], &rgb_color_white, sizeof(rgb_color_white));
|
||||
break;
|
||||
case RGB_COLOR_PURPLE:
|
||||
memcpy(&expression[index], &rgb_color_purple, sizeof(rgb_color_purple));
|
||||
break;
|
||||
case RGB_COLOR_CYAN:
|
||||
memcpy(&expression[index], &rgb_color_cyan, sizeof(rgb_color_cyan));
|
||||
break;
|
||||
case RGB_COLOR_BLUE:
|
||||
memcpy(&expression[index], &rgb_color_blue, sizeof(rgb_color_blue));
|
||||
break;
|
||||
case RGB_COLOR_GREEN_WHITE:
|
||||
memcpy(&expression[index], &rgb_color_green_white, sizeof(rgb_color_green_white));
|
||||
break;
|
||||
case RGB_COLOR_GREEN_PURPLE:
|
||||
memcpy(&expression[index], &rgb_color_green_purple, sizeof(rgb_color_green_purple));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
expression[index].index = index;
|
||||
static uint8_t rgb_color_lat[EXAMPLE_LED_NUMBERS] = {0};
|
||||
if(rgb_color_lat[index] != color)
|
||||
{
|
||||
switch(color)
|
||||
{
|
||||
case RGB_COLOR_NONE:
|
||||
memcpy(&expression[index], &rgb_color_none, sizeof(rgb_color_none));
|
||||
break;
|
||||
case RGB_COLOR_RAD:
|
||||
memcpy(&expression[index], &rgb_color_rad, sizeof(rgb_color_rad));
|
||||
break;
|
||||
case RGB_COLOR_ORANGE:
|
||||
memcpy(&expression[index], &rgb_color_orange, sizeof(rgb_color_orange));
|
||||
break;
|
||||
case RGB_COLOR_GREEN:
|
||||
memcpy(&expression[index], &rgb_color_green, sizeof(rgb_color_green));
|
||||
break;
|
||||
case RGB_COLOR_WHITE:
|
||||
memcpy(&expression[index], &rgb_color_white, sizeof(rgb_color_white));
|
||||
break;
|
||||
case RGB_COLOR_PURPLE:
|
||||
memcpy(&expression[index], &rgb_color_purple, sizeof(rgb_color_purple));
|
||||
break;
|
||||
case RGB_COLOR_CYAN:
|
||||
memcpy(&expression[index], &rgb_color_cyan, sizeof(rgb_color_cyan));
|
||||
break;
|
||||
case RGB_COLOR_BLUE:
|
||||
memcpy(&expression[index], &rgb_color_blue, sizeof(rgb_color_blue));
|
||||
break;
|
||||
case RGB_COLOR_GREEN_WHITE:
|
||||
memcpy(&expression[index], &rgb_color_green_white, sizeof(rgb_color_green_white));
|
||||
break;
|
||||
case RGB_COLOR_GREEN_PURPLE:
|
||||
memcpy(&expression[index], &rgb_color_green_purple, sizeof(rgb_color_green_purple));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
expression[index].index = index;
|
||||
rgb_color_lat[index] = color;
|
||||
}
|
||||
}
|
||||
void rgb_toggle(uint8_t index, rgb_color_t* rgb_color)
|
||||
{
|
||||
@@ -220,19 +233,26 @@ void rgb_Indicator_light_on(uint8_t index, uint8_t color, uint16_t cyle)
|
||||
memcpy(&expression_lat[index], &expression[index], sizeof(rgb_color_t));
|
||||
rgb_color_change(index, color);
|
||||
}
|
||||
if(rgb_toggle_cnt_lat[index] == 0 && rgb_toggle_cnt[index] != cyle)
|
||||
// 设置较大的时间计数,防止数值被轻易到达
|
||||
if(rgb_toggle_cnt_lat[index] == 2000 )
|
||||
{
|
||||
rgb_toggle_cnt_lat[index] = rgb_toggle_cnt[index];
|
||||
printf("rgb_toggle_cnt[index]:%d\n",rgb_toggle_cnt[index]);
|
||||
rgb_update_cyle(index, cyle);
|
||||
}
|
||||
|
||||
if(toggle_flag[index] == false)
|
||||
{
|
||||
toggle_flag_lat[index] = !toggle_flag_lat[index];
|
||||
toggle_flag[index] = !toggle_flag[index];
|
||||
}
|
||||
}
|
||||
void rgb_Indicator_light_off(uint8_t index)
|
||||
{
|
||||
|
||||
rgb_color_change(index, expression_lat[index].color_type);
|
||||
rgb_update_cyle(index,(rgb_toggle_cnt_lat[index] + 1) * WORD_TIME_MS );
|
||||
|
||||
toggle_flag[index] = toggle_flag_lat[index];
|
||||
|
||||
memset(&expression_lat[index], 0, sizeof(rgb_color_t));
|
||||
rgb_toggle_cnt_lat[index] = 0;
|
||||
rgb_toggle_cnt_lat[index] = 2000;
|
||||
}
|
||||
|
||||
@@ -83,6 +83,20 @@ void pin_cfg_output(const cfg_board_pin_io_t *pin)
|
||||
gpio_config(&io_conf);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void gpio_to_high_z(const cfg_board_pin_io_t *pin)
|
||||
{
|
||||
gpio_config_t io = {
|
||||
.pin_bit_mask = 1ULL << pin->pin,
|
||||
.mode = GPIO_MODE_DISABLE, // 或 GPIO_MODE_INPUT(都不会驱动外部)
|
||||
.pull_up_en = GPIO_PULLUP_DISABLE,
|
||||
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||
.intr_type = GPIO_INTR_DISABLE,
|
||||
};
|
||||
gpio_config(&io);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief IO 基本操作:设置使输出是否为有效的电平
|
||||
*
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
void pin_cfg_input(const cfg_board_pin_io_t *pin);
|
||||
bool pin_get_valid(const cfg_board_pin_io_t *pin);
|
||||
|
||||
|
||||
void gpio_to_high_z(const cfg_board_pin_io_t *pin);
|
||||
void pin_cfg_output(const cfg_board_pin_io_t *pin);
|
||||
void pin_set_valid(const cfg_board_pin_io_t *pin, bool en);
|
||||
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
*/
|
||||
static uint8_t pc_device_choice_inside(device_t *port, uint8_t type, uint8_t connect);
|
||||
|
||||
// 内部全局变量
|
||||
static uint8_t* rf_flag_off_overall = NULL;
|
||||
static device_t *device_inside;
|
||||
|
||||
uint8_t device_init(device_t *port)
|
||||
{
|
||||
uint8_t res = DEVICE_OK;
|
||||
@@ -53,12 +57,17 @@ uint8_t device_init(device_t *port)
|
||||
SYS_LOG_ERR("app device choice error");
|
||||
}
|
||||
SYS_LOG_INF("device init success");
|
||||
// 赋值全局变量 RF开关
|
||||
rf_flag_off_overall = &port->rf_flag_off;
|
||||
// 赋值设备
|
||||
device_inside = port;
|
||||
|
||||
return DEVICE_OK;
|
||||
}
|
||||
uint8_t uart_init(init_device_t *port)
|
||||
{
|
||||
// port->uart_port = sb_uart_port_bind(g_cfg_board->uart_fc.id, g_cfg_board->uart_fc.br, g_cfg_board->uart_fc.pin_txd.pin, g_cfg_board->uart_fc.pin_rxd.pin, g_cfg_board->uart_fc.irq_prior, 1024, 0, NULL);
|
||||
port->uart_port = sb_uart_port_bind(1, 115200, 21, 20, 21, 1024, 0, NULL);
|
||||
port->uart_port = sb_uart_port_bind(1, 115200, 21, 20, 21, 2048, 0, NULL);
|
||||
|
||||
if(port->uart_port == NULL)
|
||||
{
|
||||
@@ -75,21 +84,27 @@ uint8_t uart_init(init_device_t *port)
|
||||
// 蓝牙连接回调函数
|
||||
static void ble_server_connect_handler(ble_server_status_t status)
|
||||
{
|
||||
// 处理连接状态,例如:
|
||||
if (status == BLE_SERVER_STATUS_CONNECTED) {
|
||||
uint8_t res = pc_device_choice_inside(NULL, DATA_PORT_TYPE_BLE_VAL, CONNECT_BLE);
|
||||
if(res == DEVICE_PC_ERROR){
|
||||
if(rf_flag_off_overall != NULL && *rf_flag_off_overall == 0){
|
||||
// 处理连接状态,例如:
|
||||
if (status == BLE_SERVER_STATUS_CONNECTED) {
|
||||
uint8_t res = pc_device_choice_inside(NULL, DATA_PORT_TYPE_BLE_VAL, CONNECT_BLE);
|
||||
if(res == DEVICE_PC_ERROR){
|
||||
}
|
||||
device_wifi_stop();
|
||||
device_inside->ble_one_connect_flag = 1;
|
||||
SYS_LOG_INF("ble Connected");
|
||||
} else if(status == BLE_SERVER_STATUS_DISCONNECTED){
|
||||
uint8_t res = pc_device_choice_inside(NULL, DATA_PORT_TYPE_BLE_VAL, DISCONNECT);
|
||||
if(res == DEVICE_PC_ERROR){
|
||||
}
|
||||
device_wifi_start();
|
||||
SYS_LOG_INF("ble dis Connected");
|
||||
// disconnected / other
|
||||
} else {
|
||||
SYS_LOG_INF("ble stop");
|
||||
}
|
||||
SYS_LOG_INF("ble Connected");
|
||||
} else if(status == BLE_SERVER_STATUS_DISCONNECTED){
|
||||
uint8_t res = pc_device_choice_inside(NULL, DATA_PORT_TYPE_BLE_VAL, DISCONNECT);
|
||||
if(res == DEVICE_PC_ERROR){
|
||||
}
|
||||
SYS_LOG_INF("ble dis Connected");
|
||||
// disconnected / other
|
||||
} else {
|
||||
SYS_LOG_INF("ble stop");
|
||||
}
|
||||
|
||||
}
|
||||
static void _sb_manufacturer_encode(uint8_t manufacturer_data[20])
|
||||
{
|
||||
@@ -143,54 +158,62 @@ static void wifi_event_handler(bool is_connect, sb_data_port_t *port)
|
||||
{
|
||||
SYS_LOG_ERR("wifi pc device choice error");
|
||||
}
|
||||
SYS_LOG_INF("wifi connect");
|
||||
SYS_LOG_INF("wifi tcp connect");
|
||||
}else{
|
||||
uint8_t res = pc_device_choice_inside(NULL, DATA_PORT_TYPE_WIFI_UDP, DISCONNECT);
|
||||
uint8_t res = pc_device_choice_inside(NULL, DATA_PORT_TYPE_WIFI_UDP, CONNECT_WIFI_UDP);
|
||||
if(res == DEVICE_PC_ERROR)
|
||||
{
|
||||
SYS_LOG_ERR("wifi pc device choice error");
|
||||
}
|
||||
SYS_LOG_INF("wifi disconnect");
|
||||
SYS_LOG_INF("wifi tcp disconnect");
|
||||
}
|
||||
}
|
||||
static void wifi_ap_connect_handler(wifi_ap_connect_status_t status, uint8_t connect_cnt)
|
||||
{
|
||||
SYS_LOG_WRN("wifi ap connect status %d %d", (int)status, (int)connect_cnt);
|
||||
//实现自动切换发送对象
|
||||
if((connect_cnt == 1 && status == WIFI_AP_CONNECT_GOT_STA)){
|
||||
uint8_t res = pc_device_choice_inside(NULL, DATA_PORT_TYPE_WIFI_UDP, CONNECT_WIFI_UDP);
|
||||
if(res == DEVICE_PC_ERROR)
|
||||
{
|
||||
SYS_LOG_ERR("wifi pc device choice error");
|
||||
if(rf_flag_off_overall != NULL && *rf_flag_off_overall == 0)
|
||||
{
|
||||
SYS_LOG_WRN("wifi ap connect status %d %d", (int)status, (int)connect_cnt);
|
||||
//实现自动切换发送对象
|
||||
if((connect_cnt == 1 && status == WIFI_AP_CONNECT_GOT_STA)){
|
||||
uint8_t res = pc_device_choice_inside(NULL, DATA_PORT_TYPE_WIFI_UDP, CONNECT_WIFI_UDP);
|
||||
if(res == DEVICE_PC_ERROR)
|
||||
{
|
||||
SYS_LOG_ERR("wifi pc device choice error");
|
||||
}
|
||||
device_ble_stop();
|
||||
SYS_LOG_INF("wifi connect");
|
||||
}else{
|
||||
uint8_t res = pc_device_choice_inside(NULL, DATA_PORT_TYPE_WIFI_UDP, DISCONNECT);
|
||||
if(res == DEVICE_PC_ERROR)
|
||||
{
|
||||
SYS_LOG_ERR("wifi pc device choice error");
|
||||
}
|
||||
device_ble_start();
|
||||
SYS_LOG_INF("wifi disconnect");
|
||||
}
|
||||
SYS_LOG_INF("wifi connect");
|
||||
}else{
|
||||
uint8_t res = pc_device_choice_inside(NULL, DATA_PORT_TYPE_WIFI_UDP, DISCONNECT);
|
||||
if(res == DEVICE_PC_ERROR)
|
||||
{
|
||||
SYS_LOG_ERR("wifi pc device choice error");
|
||||
}
|
||||
SYS_LOG_INF("wifi disconnect");
|
||||
}
|
||||
}
|
||||
static void wifi_sta_connect_handler(wifi_sta_connect_status_t status, uint8_t ip_v4[4])
|
||||
{
|
||||
SYS_LOG_WRN("wifi ap connect status %d", (int)status);
|
||||
//实现自动切换发送对象
|
||||
if(status == WIFI_STA_CONNECT_GOT_IP){
|
||||
uint8_t res = pc_device_choice_inside(NULL, DATA_PORT_TYPE_WIFI_UDP, CONNECT_WIFI_UDP);
|
||||
if(res == DEVICE_PC_ERROR)
|
||||
{
|
||||
SYS_LOG_ERR("wifi pc device choice error");
|
||||
if(rf_flag_off_overall != NULL && *rf_flag_off_overall == 0)
|
||||
{
|
||||
SYS_LOG_WRN("wifi ap connect status %d", (int)status);
|
||||
//实现自动切换发送对象
|
||||
if(status == WIFI_STA_CONNECT_GOT_IP){
|
||||
uint8_t res = pc_device_choice_inside(NULL, DATA_PORT_TYPE_WIFI_UDP, CONNECT_WIFI_UDP);
|
||||
if(res == DEVICE_PC_ERROR)
|
||||
{
|
||||
SYS_LOG_ERR("wifi pc device choice error");
|
||||
}
|
||||
SYS_LOG_INF("wifi connect");
|
||||
}else{
|
||||
uint8_t res = pc_device_choice_inside(NULL, DATA_PORT_TYPE_WIFI_UDP, DISCONNECT);
|
||||
if(res == DEVICE_PC_ERROR)
|
||||
{
|
||||
SYS_LOG_ERR("wifi pc device choice error");
|
||||
}
|
||||
SYS_LOG_INF("wifi disconnect");
|
||||
}
|
||||
SYS_LOG_INF("wifi connect");
|
||||
}else{
|
||||
uint8_t res = pc_device_choice_inside(NULL, DATA_PORT_TYPE_WIFI_UDP, DISCONNECT);
|
||||
if(res == DEVICE_PC_ERROR)
|
||||
{
|
||||
SYS_LOG_ERR("wifi pc device choice error");
|
||||
}
|
||||
SYS_LOG_INF("wifi disconnect");
|
||||
}
|
||||
}
|
||||
uint8_t wifi_init(init_device_t *port)
|
||||
@@ -259,30 +282,86 @@ uint8_t wifi_init(init_device_t *port)
|
||||
void wifi_mode_switch(init_device_t *port)
|
||||
{
|
||||
static init_device_t* port_lat = NULL;
|
||||
static bool wifi_mode_flag = false;
|
||||
static uint8_t wifi_mode_flag = 0;
|
||||
|
||||
if(port_lat == NULL && port != NULL)
|
||||
{
|
||||
port_lat = port;
|
||||
port_lat->wifi_mode = WIFI_NETIF_MODE_AP;
|
||||
return;
|
||||
}
|
||||
|
||||
if (wifi_mode_flag)
|
||||
switch(wifi_mode_flag)
|
||||
{
|
||||
wifi_mode_flag = false;
|
||||
wifi_set_mode(WIFI_NETIF_MODE_AP);
|
||||
port_lat->wifi_mode = WIFI_NETIF_MODE_AP;
|
||||
SYS_LOG_INF("wifi mode switch to ap");
|
||||
}
|
||||
else
|
||||
{
|
||||
wifi_mode_flag = true;
|
||||
wifi_set_mode(WIFI_NETIF_MODE_STA);
|
||||
port_lat->wifi_mode = WIFI_NETIF_MODE_STA;
|
||||
SYS_LOG_INF("wifi mode switch to sta");
|
||||
case 0:
|
||||
wifi_mode_flag = 1;
|
||||
wifi_set_mode(WIFI_NETIF_MODE_STA);
|
||||
port_lat->wifi_mode = WIFI_NETIF_MODE_STA;
|
||||
SYS_LOG_INF("wifi mode switch to sta");
|
||||
break;
|
||||
case 1:
|
||||
wifi_mode_flag = 2;
|
||||
SYS_LOG_INF("wifi mode switch to off");
|
||||
port_lat->wifi_mode = RC_OFF_NONE;
|
||||
rf_stop(device_inside);
|
||||
break;
|
||||
case 2:
|
||||
rf_start(device_inside);
|
||||
wifi_mode_flag = 0;
|
||||
wifi_set_mode(WIFI_NETIF_MODE_AP);
|
||||
port_lat->wifi_mode = WIFI_NETIF_MODE_AP;
|
||||
SYS_LOG_INF("wifi mode switch to ap");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
wifi_start();
|
||||
}
|
||||
void device_wifi_start(void)
|
||||
{
|
||||
device_inside->wifi_flag_off = 0;
|
||||
sb_data_port_start(device_inside->init_device.wifi_tcp);
|
||||
sb_data_port_start(device_inside->init_device.wifi_udp);
|
||||
}
|
||||
void device_wifi_stop(void)
|
||||
{
|
||||
device_inside->wifi_flag_off = 1;
|
||||
sb_data_port_stop(device_inside->init_device.wifi_tcp);
|
||||
sb_data_port_stop(device_inside->init_device.wifi_udp);
|
||||
}
|
||||
void device_ble_start(void)
|
||||
{
|
||||
device_inside->ble_flag_off = 0;
|
||||
sb_data_port_start(device_inside->init_device.ble_spp_server_cmd);
|
||||
sb_data_port_start(device_inside->init_device.ble_spp_server_val);
|
||||
}
|
||||
void device_ble_stop(void)
|
||||
{
|
||||
device_inside->ble_flag_off = 1;
|
||||
sb_data_port_stop(device_inside->init_device.ble_spp_server_cmd);
|
||||
sb_data_port_stop(device_inside->init_device.ble_spp_server_val);
|
||||
}
|
||||
|
||||
void rf_start(device_t *port)
|
||||
{
|
||||
port->rf_flag_off = 0;
|
||||
sb_data_port_start(port->init_device.wifi_tcp);
|
||||
sb_data_port_start(port->init_device.wifi_udp);
|
||||
sb_data_port_start(port->init_device.ble_spp_server_cmd);
|
||||
sb_data_port_start(port->init_device.ble_spp_server_val);
|
||||
uint8_t res = pc_device_choice_inside(NULL, DATA_PORT_TYPE_BLE_VAL, DISCONNECT);
|
||||
}
|
||||
|
||||
void rf_stop(device_t *port)
|
||||
{
|
||||
port->rf_flag_off = 1;
|
||||
uint8_t res = pc_device_choice_inside(NULL, DATA_PORT_TYPE_RF_OFF, CONNECT_RF_OFF);
|
||||
sb_data_port_stop(port->init_device.wifi_tcp);
|
||||
sb_data_port_stop(port->init_device.wifi_udp);
|
||||
sb_data_port_stop(port->init_device.ble_spp_server_cmd);
|
||||
sb_data_port_stop(port->init_device.ble_spp_server_val);
|
||||
}
|
||||
|
||||
uint8_t embedded_device_choice(device_t *port, uint8_t type)
|
||||
{
|
||||
//端口与PC一致
|
||||
@@ -352,13 +431,12 @@ uint32_t embedded_device_get_rx_length(device_t *port)
|
||||
static uint8_t pc_device_choice_inside(device_t *port, uint8_t type, uint8_t connect)
|
||||
{
|
||||
static device_t* port_device_inside = NULL;
|
||||
SYS_LOG_WRN("pc_device_choice_inside type %d connect %d", type, connect);
|
||||
if(port != NULL && port_device_inside == NULL){
|
||||
SYS_LOG_INF("pc_device_choice_inside");
|
||||
pc_device_choice(port, type);
|
||||
port_device_inside = port;
|
||||
port_device_inside->connect_pc = connect;
|
||||
}else if(port == NULL && port_device_inside != NULL && (port_device_inside->pc_device_type == type || connect != DISCONNECT)){
|
||||
}else if(port == NULL && port_device_inside != NULL && (port_device_inside->pc_device_type == type || connect != DISCONNECT || port_device_inside->pc_device_type == DATA_PORT_TYPE_RF_OFF)){
|
||||
pc_device_choice(port_device_inside, type);
|
||||
port_device_inside->connect_pc = connect;
|
||||
}
|
||||
@@ -410,6 +488,9 @@ int pc_device_read(device_t *port, void *buffer, uint32_t length)
|
||||
{
|
||||
if (port->pc_device == NULL)
|
||||
return -1;
|
||||
//判断是否开启射频
|
||||
if(port->rf_flag_off && port->pc_device_type > 1)
|
||||
return -2;
|
||||
|
||||
return sb_data_port_read(port->pc_device, buffer, length, 0);
|
||||
}
|
||||
@@ -418,6 +499,9 @@ int pc_device_write(device_t *port, void *buffer, uint32_t length)
|
||||
{
|
||||
if(port->pc_device == NULL)
|
||||
return -1;
|
||||
//判断是否开启射频
|
||||
if(port->rf_flag_off && port->pc_device_type > 1)
|
||||
return -2;
|
||||
|
||||
if(port->connect_pc)
|
||||
return sb_data_port_write(port->pc_device, buffer, length, 0);
|
||||
@@ -428,7 +512,9 @@ uint32_t pc_device_get_rx_length(device_t *port)
|
||||
{
|
||||
if(port->pc_device == NULL)
|
||||
return 0;
|
||||
|
||||
//判断是否开启射频
|
||||
if(port->rf_flag_off && port->pc_device_type > 1)
|
||||
return 0;
|
||||
return sb_data_port_get_rx_length(port->pc_device);
|
||||
}
|
||||
|
||||
@@ -479,6 +565,10 @@ int app_device_read(device_t *port, void *buffer, uint32_t length, uint32_t time
|
||||
if(port->app_device == NULL)
|
||||
return -1;
|
||||
|
||||
//判断是否开启射频
|
||||
if((port->rf_flag_off || port->ble_flag_off) && port->app_device_type > 1)
|
||||
return -2;
|
||||
|
||||
return sb_data_port_read(port->app_device, buffer, length, timeout);
|
||||
}
|
||||
|
||||
@@ -487,6 +577,10 @@ int app_device_write(device_t *port, void *buffer, uint32_t length)
|
||||
if(port->app_device == NULL)
|
||||
return -1;
|
||||
|
||||
//判断是否开启射频
|
||||
if((port->rf_flag_off || port->ble_flag_off) && port->app_device_type > 1)
|
||||
return -2;
|
||||
|
||||
return sb_data_port_write(port->app_device, buffer, length, 0);
|
||||
}
|
||||
uint32_t app_device_get_rx_length(device_t *port)
|
||||
@@ -494,5 +588,9 @@ uint32_t app_device_get_rx_length(device_t *port)
|
||||
if(port->app_device == NULL)
|
||||
return 0;
|
||||
|
||||
//判断是否开启射频
|
||||
if((port->rf_flag_off || port->ble_flag_off) && port->app_device_type > 1)
|
||||
return -2;
|
||||
|
||||
return sb_data_port_get_rx_length(port->app_device);
|
||||
}
|
||||
@@ -39,7 +39,9 @@ enum DATA_PORT_TYPE
|
||||
DATA_PORT_TYPE_WIFI_TCP,
|
||||
DATA_PORT_TYPE_WIFI_UDP,
|
||||
DATA_PORT_TYPE_BLE_CMD,
|
||||
DATA_PORT_TYPE_BLE_VAL
|
||||
DATA_PORT_TYPE_BLE_VAL,
|
||||
|
||||
DATA_PORT_TYPE_RF_OFF = 25,
|
||||
};
|
||||
enum CONNECT_TYPE
|
||||
{
|
||||
@@ -48,6 +50,8 @@ enum CONNECT_TYPE
|
||||
CONNECT_BLE,
|
||||
CONNECT_WIFI_TCP,
|
||||
CONNECT_WIFI_UDP,
|
||||
|
||||
CONNECT_RF_OFF = 25,
|
||||
};
|
||||
enum WIFI_MODE
|
||||
{
|
||||
@@ -84,10 +88,16 @@ typedef struct
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -122,6 +132,35 @@ 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 嵌入式设备数据接口
|
||||
*
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#include "key.h"
|
||||
|
||||
#include "sertrf.h"
|
||||
button_t btn;
|
||||
|
||||
cfg_board_pin_io_t key_switch = {
|
||||
.pin = 9,
|
||||
.en_lev = 0,};
|
||||
.pin = 18,
|
||||
.en_lev = 1,};
|
||||
cfg_board_pin_io_t boot_switch = {
|
||||
.pin = ~0,
|
||||
.pin = 18,
|
||||
.en_lev = 0,};
|
||||
// 新增事件类型
|
||||
// EVT_DOUBLE_CLICK: 双击
|
||||
@@ -14,7 +14,7 @@ cfg_board_pin_io_t boot_switch = {
|
||||
|
||||
bool key_single_click = 0,key_press_down = 0,key_press_up = 0;
|
||||
|
||||
|
||||
static os_work_t work_handler_button;
|
||||
// 用户在此处理按键事件
|
||||
static void my_button_handler(button_event_t evt) {
|
||||
switch (evt) {
|
||||
@@ -34,11 +34,15 @@ static void my_button_handler(button_event_t evt) {
|
||||
break;
|
||||
case EVT_DOUBLE_CLICK: //双击
|
||||
// SYS_LOG_INF("[Event] DOUBLE_CLICK");
|
||||
// sertrf_rf_switch(1);
|
||||
// aes_test();
|
||||
// key_test();
|
||||
break;
|
||||
case EVT_LONG_PRESS: //长按
|
||||
SYS_LOG_INF("[Event] LONG_PRESS");
|
||||
Examples_run();
|
||||
rgb_Indicator_light_off(0);
|
||||
rgb_Indicator_light_off(0); //如果处理有变色,需要该函数先调用
|
||||
// sertrf_rf_switch(0);
|
||||
break;
|
||||
case EVT_SINGLE_LONG_PRESS: //单击后长按
|
||||
rgb_Indicator_light_off(0);
|
||||
@@ -169,16 +173,57 @@ void _work_button(void *arg) {
|
||||
void button_work_init() {
|
||||
|
||||
pin_cfg_input(&key_switch);
|
||||
pin_cfg_output(&boot_switch);
|
||||
// pin_cfg_output(&boot_switch);
|
||||
// gpio_to_high_z(&boot_switch);
|
||||
|
||||
button_init(&btn, read_button_pin, my_button_handler);
|
||||
|
||||
static os_work_t work_handler_button;
|
||||
os_work_create(&work_handler_button, "work-button", _work_button, NULL, OS_PRIORITY_NORMAL);
|
||||
os_work_submit(default_os_work_q_hdl, &work_handler_button, 10);
|
||||
}
|
||||
|
||||
void boot_set(uint8_t value)
|
||||
{
|
||||
// 设置按键为高阻态,防止冲突
|
||||
gpio_to_high_z(&key_switch);
|
||||
os_work_suspend(&work_handler_button);
|
||||
|
||||
pin_cfg_output(&boot_switch);
|
||||
pin_set_valid(&boot_switch, value);
|
||||
}
|
||||
|
||||
void boot_set_high_z(void)
|
||||
{
|
||||
gpio_to_high_z(&boot_switch);
|
||||
//重新初始化按键
|
||||
pin_cfg_input(&key_switch);
|
||||
os_work_resume(&work_handler_button,10);
|
||||
// os_work_later(10);
|
||||
}
|
||||
|
||||
void key_test(void)
|
||||
{
|
||||
boot_set(0);
|
||||
|
||||
os_thread_sleep(5000);
|
||||
|
||||
boot_set_high_z();
|
||||
}
|
||||
|
||||
void boot_set_2(uint8_t value)
|
||||
{
|
||||
pin_cfg_output(&boot_switch);
|
||||
pin_set_valid(&boot_switch, value);
|
||||
os_work_suspend(&work_handler_button);
|
||||
}
|
||||
|
||||
void boot_set_high_z_2(void)
|
||||
{
|
||||
pin_cfg_input(&key_switch);
|
||||
os_work_resume(&work_handler_button,10);
|
||||
}
|
||||
|
||||
bool key_get_status(void)
|
||||
{
|
||||
return pin_get_valid(&key_switch);
|
||||
}
|
||||
@@ -47,5 +47,23 @@ typedef struct {
|
||||
|
||||
extern bool key_single_click,key_press_down,key_press_up;
|
||||
void _work_button(void *arg);
|
||||
/**
|
||||
* @brief 初始化按键
|
||||
*/
|
||||
void button_work_init();
|
||||
/**
|
||||
* @brief 设置boot按键输出
|
||||
*/
|
||||
void boot_set(uint8_t value);
|
||||
/**
|
||||
* @brief 设置boot按键为高阻态
|
||||
*/
|
||||
void boot_set_high_z(void);
|
||||
|
||||
void key_test(void);
|
||||
|
||||
void boot_set_2(uint8_t value);
|
||||
|
||||
void boot_set_high_z_2(void);
|
||||
|
||||
bool key_get_status(void);
|
||||
|
||||
@@ -15,7 +15,7 @@ typedef struct
|
||||
esp_ota_handle_t ota_handle;
|
||||
int total_size;
|
||||
uint16_t ota_data_cnt;
|
||||
uint8_t ota_buff[20480 + 512];
|
||||
// uint8_t ota_buff[20480 + 512];
|
||||
}ota_u_t;
|
||||
|
||||
typedef struct
|
||||
|
||||
@@ -448,7 +448,15 @@ void fc_put_ack(void)
|
||||
// printf("ACK\n");
|
||||
}
|
||||
|
||||
|
||||
// MSP重启命令
|
||||
void msp_send_reboot(msp_port_t *msp)
|
||||
{
|
||||
msp_send2(msp, MSP_REBOOT, NULL, 0);
|
||||
}
|
||||
void msp_request_type(msp_port_t *msp)
|
||||
{
|
||||
msp_send2(msp, MSP_FC_VARIANT, NULL, 0);
|
||||
}
|
||||
// MSP数据读取,并根据读取的数据进行处理
|
||||
void msp_recv_loop(msp_port_t *msp)
|
||||
{
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#define MSP_SONAR_ALTITUDE 58
|
||||
#define MSP_ARMING_CONFIG 61
|
||||
#define MSP_RX_MAP 64 // get channel map (also returns number of channels total)
|
||||
#define MSP_REBOOT 68 // 重启命令
|
||||
#define MSP_LOOP_TIME 73 // FC cycle time i.e looptime parameter
|
||||
#define MSP_STATUS 101
|
||||
#define MSP_RAW_IMU 102
|
||||
@@ -366,7 +367,10 @@ void msp_handle_get_gcs(msp_gcs_t pkt);
|
||||
// 回复请求包处理
|
||||
void fc_put_ack(void);
|
||||
|
||||
|
||||
// 发送MSP重启命令
|
||||
void msp_send_reboot(msp_port_t *msp);
|
||||
// 请求飞控类型
|
||||
void msp_request_type(msp_port_t *msp);
|
||||
// 接口层
|
||||
int MSP_wirite(const void *data, uint32_t size, uint32_t wait_ms);
|
||||
int MSP_read(void *data, uint32_t size, uint32_t wait_ms);
|
||||
|
||||
@@ -31,7 +31,7 @@ int Protocol_write(const void *data, uint32_t size, uint32_t wait_ms)
|
||||
return -1;
|
||||
}
|
||||
|
||||
void Protocol_init(port_type_m port_type, void* port)
|
||||
void Protocol_init(port_type_e port_type, void* port)
|
||||
{
|
||||
protocol.port.data_port = port;
|
||||
protocol.port_type = port_type;
|
||||
@@ -137,23 +137,25 @@ void Protocol_buf_decode(void* data, uint32_t size)
|
||||
break;
|
||||
}
|
||||
}
|
||||
void protocol_set_message_status(message_status_m status)
|
||||
void protocol_set_message_status(message_status_e status)
|
||||
{
|
||||
protocol.message_status = status;
|
||||
}
|
||||
protocol_status_t get_protocol_status(void)
|
||||
protocol_status_e get_protocol_status(void)
|
||||
{
|
||||
protocol.protocol_status = PROTOCOL_STATUS_OK;
|
||||
|
||||
if(protocol.pro_type == PROTOCOL_IDLE)
|
||||
// 先OTA升级、未知协议、未收到飞控数据
|
||||
if(protocol.message_status == MESSAGE_OTA || protocol.message_status == MESSAGE_FC_ISP)
|
||||
{
|
||||
protocol.protocol_status = PROTOCOL_STATUS_IN_OTA;
|
||||
}
|
||||
else if(protocol.pro_type == PROTOCOL_IDLE)
|
||||
{
|
||||
protocol.protocol_status = PROTOCOL_STATUS_TYPE_IDLE;
|
||||
} else if(protocol.analysis_sussess_count == 0)
|
||||
{
|
||||
protocol.protocol_status = PROTOCOL_STATUS_NO_DATA;
|
||||
} else if(protocol.message_status == MESSAGE_OTA)
|
||||
{
|
||||
protocol.protocol_status = PROTOCOL_STATUS_IN_OTA;
|
||||
}
|
||||
|
||||
protocol.analysis_sussess_count = 0;
|
||||
@@ -170,7 +172,7 @@ int fc_reboot(void)
|
||||
break;
|
||||
case PROTOCOL_MSP:
|
||||
{
|
||||
|
||||
msp_send_reboot(&protocol.msp);
|
||||
}
|
||||
break;
|
||||
case PROTOCOL_MAVLINK:
|
||||
|
||||
@@ -22,12 +22,13 @@ typedef enum
|
||||
{
|
||||
PORT_LINUX_UART = 0,
|
||||
PORT_LINUX_SBDATA,
|
||||
}port_type_m;
|
||||
}port_type_e;
|
||||
typedef enum
|
||||
{
|
||||
MESSAGE_IDLE = 0,
|
||||
MESSAGE_OTA,
|
||||
}message_status_m;
|
||||
MESSAGE_FC_ISP,
|
||||
}message_status_e;
|
||||
typedef enum
|
||||
{
|
||||
PROTOCOL_STATUS_OK = 0,
|
||||
@@ -35,20 +36,20 @@ typedef enum
|
||||
PROTOCOL_STATUS_TYPE_IDLE, //协议类型未知
|
||||
PROTOCOL_STATUS_ANALYSIS_ERROR, //长时间解析失败
|
||||
PROTOCOL_STATUS_IN_OTA, //OTA中
|
||||
}protocol_status_t;
|
||||
}protocol_status_e;
|
||||
typedef struct
|
||||
{
|
||||
protocol_port_t port;
|
||||
protocol_type_m pro_type;
|
||||
port_type_m port_type;
|
||||
port_type_e port_type;
|
||||
|
||||
mavlink_device_t mavlink_device;
|
||||
msp_port_t msp;
|
||||
|
||||
protocol_status_t protocol_status;
|
||||
protocol_status_e protocol_status;
|
||||
uint16_t analysis_sussess_count; //数据解析成功次数
|
||||
|
||||
message_status_m message_status;
|
||||
message_status_e message_status;
|
||||
|
||||
mavlink_message_t message;
|
||||
}protocol_t;
|
||||
@@ -59,7 +60,7 @@ typedef struct
|
||||
* @param port_type 使用的设备类型(如串口或其他)
|
||||
* @param port 由对应的驱动提供的绑定接口获得的句柄
|
||||
*/
|
||||
void Protocol_init(port_type_m port_type, void* port);
|
||||
void Protocol_init(port_type_e port_type, void* port);
|
||||
/**
|
||||
* @brief 搜索协议
|
||||
*
|
||||
@@ -90,13 +91,13 @@ void Protocol_buf_decode(void* data, uint32_t size);
|
||||
*
|
||||
* @param status 消息状态
|
||||
*/
|
||||
void protocol_set_message_status(message_status_m status);
|
||||
void protocol_set_message_status(message_status_e status);
|
||||
/**
|
||||
* @brief 获取协议状态
|
||||
*
|
||||
* @retval 协议状态
|
||||
*/
|
||||
protocol_status_t get_protocol_status(void);
|
||||
protocol_status_e get_protocol_status(void);
|
||||
|
||||
/**
|
||||
* @brief 飞控重启命令
|
||||
|
||||
@@ -34,6 +34,8 @@ typedef enum
|
||||
|
||||
RESEND_CMD_DATA_ACK = 0x06,
|
||||
|
||||
RESEND_CMD_ERROR_CODE = 0x07,
|
||||
|
||||
RESEND_CMD_OTA_GET_PARAM = 0x010,
|
||||
RESEND_CMD_OTA_START = 0x011,
|
||||
RESEND_CMD_OTA_DATA = 0x012,
|
||||
|
||||
@@ -71,7 +71,7 @@ int send_cmd_wait(stmisp_device_t *stmisp_device, uint8_t cmd, uint32_t timeout)
|
||||
switch(ack)
|
||||
{
|
||||
case 1:
|
||||
printf("stmisp: ACK to cmd 0x%02x\n", cmd);
|
||||
// printf("stmisp: ACK to cmd 0x%02x\n", cmd);
|
||||
return 1;
|
||||
case 2:
|
||||
printf("stmisp: NACK to cmd 0x%02x\n", cmd);
|
||||
@@ -235,7 +235,7 @@ int cmd_write_memory(stmisp_device_t *stmisp_device, uint32_t addr, const uint8_
|
||||
stmisp_device->send((void *)&data[idx], chunk, 0);
|
||||
stmisp_device->send(&cs, 1, 0);
|
||||
|
||||
if(wait_ack(stmisp_device, 5000) != 1) return 0;
|
||||
if(wait_ack(stmisp_device, 1000) != 1) return 0;
|
||||
//是否需要校验写入的数据块
|
||||
if (verify)
|
||||
{
|
||||
|
||||
@@ -38,6 +38,10 @@ typedef struct
|
||||
uint32_t adder_offset; //地址偏移
|
||||
}stmisp_device_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t stmisp_file_size;
|
||||
}stmisp_parm_t;
|
||||
/**
|
||||
* @brief 计算校验和
|
||||
*/
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "sertrf.h"
|
||||
|
||||
//设置日志打印类型
|
||||
#define CONFIG_SYS_LOG_LEVEL SYS_LOG_LEVEL_INF
|
||||
#define CONFIG_SYS_LOG_LEVEL SYS_LOG_LEVEL_DBG
|
||||
#define SYS_LOG_DOMAIN "Seryrf"
|
||||
|
||||
sertrf_t sertrf;
|
||||
@@ -33,6 +33,18 @@ void sertrf_init(void)
|
||||
|
||||
//获取飞控代码地址
|
||||
sertrf.fc_address = parse_hex_or_dec(FC_ADDRESS);
|
||||
|
||||
//获取加密后的efuse MAC 地址
|
||||
if(!esp_efuse_mac_get_default_id(sertrf.efuse_mac))
|
||||
{
|
||||
sertrf_aes_ctr_encrypt(sertrf.efuse_mac, 6, sertrf.efuse_mac_encrypt);
|
||||
}
|
||||
//初始化环形buff
|
||||
rb_init(&sertrf.data_handle_buffer, DATA_HANDLE_BUFFER_SIZE, sizeof(uint8_t));
|
||||
|
||||
// 判断飞控是否进入 飞控固件强刷模式
|
||||
sertrf.force_update = key_get_status();
|
||||
|
||||
//线程启动
|
||||
sertrf_start();
|
||||
|
||||
@@ -64,6 +76,24 @@ void sertrf_start(void)
|
||||
NULL,
|
||||
2048,
|
||||
10);
|
||||
os_thread_create(&sertrf.data_handle_thread,
|
||||
"data_handle_thread",
|
||||
data_handle_thread,
|
||||
NULL,
|
||||
4096,
|
||||
10);
|
||||
}
|
||||
void sertrf_rf_switch(uint8_t on)
|
||||
{
|
||||
switch(on)
|
||||
{
|
||||
case 1:
|
||||
rf_start(&sertrf.device);
|
||||
break;
|
||||
case 0:
|
||||
rf_stop(&sertrf.device);
|
||||
break;
|
||||
}
|
||||
}
|
||||
//因为 串口
|
||||
void embedded_thread(void* arg)
|
||||
@@ -75,7 +105,7 @@ void embedded_thread(void* arg)
|
||||
{
|
||||
uint8_t data[embedded_size ];
|
||||
// data[embedded_size] = '\0';
|
||||
if(!sertrf.stmisp_device.flag)
|
||||
if(!sertrf.stmisp_device.flag && !sertrf.force_update)
|
||||
embedded_device_read(&sertrf.device, data, embedded_size,0);
|
||||
|
||||
Protocol_buf_decode(data, embedded_size);
|
||||
@@ -91,6 +121,7 @@ void embedded_thread(void* arg)
|
||||
}
|
||||
void pc_thread(void* arg)
|
||||
{
|
||||
static bool app_pc_discard = true;
|
||||
while(true)
|
||||
{
|
||||
uint32_t pc_size = pc_device_get_rx_length(&sertrf.device);
|
||||
@@ -100,7 +131,13 @@ void pc_thread(void* arg)
|
||||
uint8_t data[pc_size];
|
||||
pc_device_read(&sertrf.device, data, pc_size);
|
||||
// SYS_LOG_INF("data : %s", data);
|
||||
if(!sertrf.stmisp_device.flag)
|
||||
// 由于APP连接上后,会发送一串我用不到的数据,需要丢弃掉,不然会影响我异常飞控固件升级
|
||||
if(sertrf.device.ble_one_connect_flag == 1)
|
||||
{
|
||||
sertrf.device.ble_one_connect_flag = 0;
|
||||
continue;
|
||||
}
|
||||
if(!sertrf.stmisp_device.flag && !sertrf.force_update)
|
||||
embedded_device_write(&sertrf.device, data, pc_size);
|
||||
}
|
||||
// printf_chill_time(10,1000);
|
||||
@@ -124,37 +161,27 @@ void app_thread(void* arg)
|
||||
strcpy(sertrf_stauct.wifi_ap_password, g_cfg_app->app_config_wifi_para.wifi_ap_password);
|
||||
strcpy(sertrf_stauct.wifi_sta_ssid, g_cfg_app->app_config_wifi_para.wifi_sta_ssid);
|
||||
strcpy(sertrf_stauct.wifi_sta_password, g_cfg_app->app_config_wifi_para.wifi_sta_password);
|
||||
|
||||
memcpy(sertrf_stauct.efuse_mac_encrypt, sertrf.efuse_mac_encrypt, 6);
|
||||
resend_send_data(&sertrf.resend_device, RESEND_CMD_GET_PARAM, &sertrf_stauct, sizeof(sertrf_stauct_t), 1000);
|
||||
|
||||
sertrf.resend_device.handle_flag = 0;//标志位清零
|
||||
break;
|
||||
case RESEND_CMD_OTA_GET_PARAM:
|
||||
printf("RESEND_CMD_OTA_GET_PARAM\r\n");
|
||||
SYS_LOG_DBG("RESEND_CMD_OTA_GET_PARAM\r\n");
|
||||
ota_parm_t ota_parm;
|
||||
resend_send_data(&sertrf.resend_device, RESEND_CMD_OTA_GET_PARAM, &ota_parm, sizeof(ota_parm_t), 1000);
|
||||
sertrf.resend_device.handle_flag = 0;//标志位清零
|
||||
break;
|
||||
case RESEND_CMD_FC_ISP_GET_PARAM:
|
||||
SYS_LOG_DBG("RESEND_CMD_FC_ISP_GET_PARAM\r\n");
|
||||
stmisp_parm_t stmisp_parm;
|
||||
resend_send_data(&sertrf.resend_device, RESEND_CMD_FC_ISP_GET_PARAM, &stmisp_parm, sizeof(stmisp_parm), 1000);
|
||||
sertrf.resend_device.handle_flag = 0;//标志位清零
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
resend_recv_data(&sertrf.resend_device, 0);
|
||||
// static uint8_t count = 0;
|
||||
// count++;
|
||||
// if(count > 100)
|
||||
// {
|
||||
// // resend_send_cmd(&sertrf.resend_device, RESEND_CMD_ACK, 0);
|
||||
// resend_send_data(&sertrf.resend_device, RESEND_CMD_GET_PARAM, NULL, 0, 0);
|
||||
// // count = 0;
|
||||
// }
|
||||
// uint32_t app_size = app_device_get_rx_length(&sertrf.device);
|
||||
|
||||
// if(app_size > 0)
|
||||
// {
|
||||
// uint8_t data[app_size];
|
||||
// app_device_read(&sertrf.device, data, app_size,0);
|
||||
// printf("data:%d:%s\n", app_size,data);
|
||||
// }
|
||||
os_thread_sleep(1);
|
||||
}
|
||||
|
||||
@@ -171,10 +198,12 @@ void task_thread(void* arg)
|
||||
static size_t end_time = 0;
|
||||
if(start_time - end_time > 2000)
|
||||
{
|
||||
switch(get_protocol_status())
|
||||
sertrf.fc_protocol_status = get_protocol_status();
|
||||
switch(sertrf.fc_protocol_status)
|
||||
{
|
||||
case PROTOCOL_STATUS_OK:
|
||||
rgb_color_change(1, sertrf.device.last_color);
|
||||
// rgb_color_change(1, sertrf.device.last_color);
|
||||
rgb_color_change(1, RGB_COLOR_ORANGE);
|
||||
break;
|
||||
case PROTOCOL_STATUS_NO_DATA:
|
||||
rgb_color_change(1, RGB_COLOR_RAD);
|
||||
@@ -197,6 +226,110 @@ void task_thread(void* arg)
|
||||
os_thread_sleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
void data_handle_thread(void* arg)
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
switch(sertrf.mode_status.task_state)
|
||||
{
|
||||
case DATA_HANDLE_OTA_DATA:
|
||||
{
|
||||
size_t data_size = rb_size(&sertrf.data_handle_buffer);
|
||||
if(data_size > 1024)
|
||||
{
|
||||
uint8_t data[data_size];
|
||||
rb_get_bulk(&sertrf.data_handle_buffer, data, data_size);
|
||||
|
||||
if(otau_write(&sertrf.otau, data, data_size))
|
||||
{
|
||||
SYS_LOG_DBG("stmisp write error");
|
||||
}
|
||||
else
|
||||
{
|
||||
SYS_LOG_DBG("stmisp write ok");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case DATA_HANDLE_OTA_DATA_END:
|
||||
{
|
||||
size_t data_size = rb_size(&sertrf.data_handle_buffer);
|
||||
if(data_size > 0)
|
||||
{
|
||||
uint8_t data[data_size];
|
||||
rb_get_bulk(&sertrf.data_handle_buffer, data, data_size);
|
||||
if(otau_write(&sertrf.otau, data, data_size))
|
||||
{
|
||||
SYS_LOG_DBG("stmisp write error");
|
||||
}
|
||||
else
|
||||
{
|
||||
SYS_LOG_DBG("stmisp write ok");
|
||||
sertrf.mode_status.task_state = DATA_HANDLE_IDLE;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case DATA_HANDLE_ISP_DATA:
|
||||
{
|
||||
size_t data_size = rb_size(&sertrf.data_handle_buffer);
|
||||
if(data_size > 0)
|
||||
{
|
||||
uint8_t data[data_size];
|
||||
rb_get_bulk(&sertrf.data_handle_buffer, data, data_size);
|
||||
|
||||
uint32_t addr = sertrf.fc_address + sertrf.stmisp_device.adder_offset;
|
||||
|
||||
if(cmd_write_memory(&sertrf.stmisp_device, addr, data, data_size, false))
|
||||
{
|
||||
resend_send_cmd(&sertrf.resend_device, RESEND_CMD_ACK, 0);
|
||||
sertrf.stmisp_device.adder_offset += data_size;
|
||||
SYS_LOG_INF("stmisp write ok %d %d\n",data_size, sertrf.stmisp_device.adder_offset);
|
||||
}
|
||||
else
|
||||
{
|
||||
sertrf.stmisp_device.adder_offset = 0;
|
||||
sertrf.mode_status.task_state = DATA_HANDLE_IDLE;
|
||||
SYS_LOG_DBG("stmisp write error");
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case DATA_HANDLE_ISP_DATA_END:
|
||||
{
|
||||
size_t data_size = rb_size(&sertrf.data_handle_buffer);
|
||||
if(data_size > 0)
|
||||
{
|
||||
uint8_t data[data_size];
|
||||
rb_get_bulk(&sertrf.data_handle_buffer, data, data_size);
|
||||
|
||||
uint32_t addr = sertrf.fc_address + sertrf.stmisp_device.adder_offset;
|
||||
|
||||
if(cmd_write_memory(&sertrf.stmisp_device, addr, data, data_size, true))
|
||||
{
|
||||
sertrf.stmisp_device.adder_offset = 0;
|
||||
sertrf.mode_status.task_state = DATA_HANDLE_IDLE;
|
||||
}
|
||||
else
|
||||
{
|
||||
SYS_LOG_DBG("stmisp write end error");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sertrf.stmisp_device.adder_offset = 0;
|
||||
sertrf.mode_status.task_state = DATA_HANDLE_IDLE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
os_thread_sleep(1);
|
||||
}
|
||||
}
|
||||
void pc_link_rgb_color(device_t* device)
|
||||
{
|
||||
static uint8_t last_connect = 255, last_wifi_mode = 0;
|
||||
@@ -208,31 +341,41 @@ void pc_link_rgb_color(device_t* device)
|
||||
case DISCONNECT:
|
||||
{
|
||||
if(device->init_device.wifi_mode == WIFI_NETIF_MODE_AP)
|
||||
new_color = RGB_COLOR_GREEN_WHITE;
|
||||
else
|
||||
new_color = RGB_COLOR_GREEN_PURPLE;
|
||||
new_color = NO_CONNECT_COLOR_BLE_AP;
|
||||
else if(device->init_device.wifi_mode == WIFI_NETIF_MODE_STA)
|
||||
new_color = NO_CONNECT_COLOR_BLE_STA;
|
||||
else if(device->init_device.wifi_mode == RC_OFF_NONE)
|
||||
new_color = RF_OFF_COLOR;
|
||||
break;
|
||||
}
|
||||
case CONNECT_WIFI_TCP:
|
||||
{
|
||||
if(device->init_device.wifi_mode == WIFI_NETIF_MODE_AP)
|
||||
new_color = RGB_COLOR_WHITE;
|
||||
else
|
||||
new_color = RGB_COLOR_PURPLE;
|
||||
|
||||
new_color = WIFI_AP_COLOR;
|
||||
else if(device->init_device.wifi_mode == WIFI_NETIF_MODE_STA)
|
||||
new_color = WIFI_STA_COLOR;
|
||||
else if(device->init_device.wifi_mode == RC_OFF_NONE)
|
||||
new_color = RF_OFF_COLOR;
|
||||
break;
|
||||
}
|
||||
case CONNECT_WIFI_UDP:
|
||||
{
|
||||
if(device->init_device.wifi_mode == WIFI_NETIF_MODE_AP)
|
||||
new_color = RGB_COLOR_WHITE;
|
||||
new_color = WIFI_AP_COLOR;
|
||||
else
|
||||
new_color = RGB_COLOR_PURPLE;
|
||||
new_color = WIFI_STA_COLOR;
|
||||
|
||||
break;
|
||||
}
|
||||
case CONNECT_BLE:
|
||||
new_color = RGB_COLOR_GREEN;
|
||||
{
|
||||
new_color = BLE_COLOR;
|
||||
}
|
||||
break;
|
||||
case CONNECT_RF_OFF:
|
||||
{
|
||||
new_color = RF_OFF_COLOR;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -243,45 +386,17 @@ void pc_link_rgb_color(device_t* device)
|
||||
|
||||
last_connect = device->connect_pc;
|
||||
last_wifi_mode = device->init_device.wifi_mode;
|
||||
}
|
||||
if(device->connect_pc == DISCONNECT)
|
||||
{
|
||||
rgb_update_cyle(0,50);
|
||||
}
|
||||
else if(device->connect_pc){
|
||||
rgb_update_cyle(0,888);
|
||||
}else{
|
||||
rgb_update_cyle(0,500);
|
||||
}
|
||||
}
|
||||
|
||||
void printf_chill_time(uint8_t chill_time, uint16_t type)
|
||||
{
|
||||
static size_t last_time[24] = {0};
|
||||
static uint16_t cnt[24] = {0};
|
||||
static uint32_t type_cnt_time[24] = {0};
|
||||
size_t now_time = os_get_sys_time();
|
||||
cnt[chill_time]++;
|
||||
type_cnt_time[chill_time] += now_time - last_time[chill_time];
|
||||
if(cnt[chill_time] % type == 0 && type_cnt_time[chill_time] / type >= now_time - last_time[chill_time] - 1)
|
||||
{
|
||||
SYS_LOG_INF("TIME_CHILL%d : %d : %d",chill_time, now_time - last_time[chill_time], type_cnt_time[chill_time]);
|
||||
cnt[chill_time] = 0;
|
||||
type_cnt_time[chill_time] = 0;
|
||||
if(device->connect_pc == DISCONNECT)
|
||||
{
|
||||
rgb_update_cyle(0,50);
|
||||
}
|
||||
else if(device->connect_pc){
|
||||
rgb_update_cyle(0,888);
|
||||
}else{
|
||||
rgb_update_cyle(0,500);
|
||||
}
|
||||
}
|
||||
else if(cnt[chill_time] % type == 0)
|
||||
{
|
||||
SYS_LOG_WRN("TIME_CHILL%d : %d : %d",chill_time, now_time - last_time[chill_time], type_cnt_time[chill_time]);
|
||||
cnt[chill_time] = 0;
|
||||
type_cnt_time[chill_time] = 0;
|
||||
}
|
||||
last_time[chill_time] = now_time;
|
||||
}
|
||||
|
||||
uint32_t parse_hex_or_dec(const char *s) {
|
||||
if (!s) return 0;
|
||||
if (s[0] == '0' && (s[1]=='x' || s[1]=='X')) return (uint32_t)strtoul(s+2, NULL, 16);
|
||||
return (uint32_t)strtoul(s, NULL, 0);
|
||||
}
|
||||
|
||||
int resend_send(void* data, uint16_t len, int timeout)
|
||||
@@ -309,9 +424,10 @@ void resend_user_parse(void *resend_device)
|
||||
switch(resend_parse->rx_frame.cmd)
|
||||
{
|
||||
case RESEND_CMD_SET_PARAM:
|
||||
if(sizeof(sertrf_stauct_t) != resend_parse->rx_frame.len)
|
||||
// 减6的目的是因为华哥没对MAC进行处理,所以也不返回
|
||||
if(sizeof(sertrf_stauct_t) - 6 != resend_parse->rx_frame.len)
|
||||
{
|
||||
printf("RESEND_CMD_SET_PARAM len error\r\n");
|
||||
SYS_LOG_DBG("RESEND_CMD_SET_PARAM len error\r\n");
|
||||
}
|
||||
sertrf_stauct_t* sertrf_stauct = (sertrf_stauct_t*)resend_parse->rx_frame.payload;
|
||||
|
||||
@@ -328,10 +444,10 @@ void resend_user_parse(void *resend_device)
|
||||
{
|
||||
if(sizeof(ota_parm_t) != resend_parse->rx_frame.len)
|
||||
{
|
||||
printf("RESEND_CMD_OTA_GET_PARAM len error\r\n");
|
||||
SYS_LOG_DBG("RESEND_CMD_OTA_GET_PARAM len error\r\n");
|
||||
}
|
||||
ota_parm_t* ota_parm = (ota_parm_t*)resend_parse->rx_frame.payload;
|
||||
printf("RESEND_CMD_OTA_GET_PARAM %d\n", ota_parm->ota_file_size);
|
||||
SYS_LOG_DBG("RESEND_CMD_OTA_GET_PARAM %d\n", ota_parm->ota_file_size);
|
||||
resend_send_cmd(resend_device, RESEND_CMD_ACK, 0);
|
||||
}
|
||||
break;
|
||||
@@ -340,82 +456,194 @@ void resend_user_parse(void *resend_device)
|
||||
//设置协议状态,为了后续灯颜色变化
|
||||
protocol_set_message_status(MESSAGE_OTA);
|
||||
// if(!sertrf.resend_device.status.resend_flag)
|
||||
//初始化ota会占用大量系统资源,需要先把飞控获取数据关闭,不然会导致栈溢出
|
||||
sb_data_port_stop(sertrf.device.embedded_device);
|
||||
otau_init(&sertrf.otau);
|
||||
|
||||
|
||||
sertrf.mode_status.task_state = DATA_HANDLE_OTA_DATA;
|
||||
resend_send_cmd(resend_device, RESEND_CMD_ACK, 0);
|
||||
}
|
||||
break;
|
||||
case RESEND_CMD_OTA_DATA:
|
||||
{
|
||||
memcpy(sertrf.otau.ota_buff + sertrf.otau.ota_data_cnt, sertrf.resend_device.rx_frame.payload, sertrf.resend_device.rx_frame.len);
|
||||
|
||||
sertrf.otau.ota_data_cnt += sertrf.resend_device.rx_frame.len;
|
||||
// if(!sertrf.resend_device.status.resend_flag)
|
||||
if(sertrf.otau.ota_data_cnt >= 20480 )
|
||||
protocol_set_message_status(MESSAGE_OTA);
|
||||
// 使用环形buff
|
||||
if(rb_size(&sertrf.data_handle_buffer) + sertrf.resend_device.rx_frame.len <= DATA_HANDLE_BUFFER_SIZE)
|
||||
{
|
||||
SYS_LOG_DBG("KUYI_CMD_OTA_DATA %d\n", sertrf.resend_device.rx_frame.seq);
|
||||
otau_write(&sertrf.otau, sertrf.otau.ota_buff, sertrf.otau.ota_data_cnt);
|
||||
sertrf.otau.ota_data_cnt = 0;
|
||||
rb_put_bulk(&sertrf.data_handle_buffer, sertrf.resend_device.rx_frame.payload, sertrf.resend_device.rx_frame.len);
|
||||
}
|
||||
else
|
||||
{
|
||||
SYS_LOG_DBG("RESEND_CMD_OTA_DATA buffer full");
|
||||
}
|
||||
resend_send_cmd(resend_device, RESEND_CMD_ACK, 0);
|
||||
}
|
||||
break;
|
||||
case RESEND_CMD_OTA_END:
|
||||
{
|
||||
if(sertrf.otau.ota_data_cnt > 0)
|
||||
{
|
||||
otau_write(&sertrf.otau, sertrf.otau.ota_buff, sertrf.otau.ota_data_cnt);
|
||||
sertrf.otau.ota_data_cnt = 0;
|
||||
}
|
||||
// if(!sertrf.resend_device.status.resend_flag)
|
||||
sertrf.mode_status.task_state = DATA_HANDLE_OTA_DATA_END;
|
||||
while (sertrf.mode_status.task_state != DATA_HANDLE_IDLE){
|
||||
os_thread_sleep(10);}
|
||||
otau_end(&sertrf.otau);
|
||||
protocol_set_message_status(MESSAGE_IDLE);
|
||||
resend_send_cmd(resend_device, RESEND_CMD_ACK, 0);
|
||||
os_thread_sleep(2);
|
||||
esp_restart();
|
||||
}
|
||||
break;
|
||||
|
||||
case RESEND_CMD_FC_ISP_GET_PARAM:
|
||||
if(sizeof(stmisp_parm_t) != resend_parse->rx_frame.len)
|
||||
{
|
||||
SYS_LOG_DBG("RESEND_CMD_FC_ISP_GET_PARAM len error\r\n");
|
||||
}
|
||||
stmisp_parm_t* stmisp_parm = (stmisp_parm_t*)resend_parse->rx_frame.payload;
|
||||
SYS_LOG_DBG("RESEND_CMD_FC_ISP_GET_PARAM %d\n", stmisp_parm->stmisp_file_size);
|
||||
resend_send_cmd(resend_device, RESEND_CMD_ACK, 0);
|
||||
break;
|
||||
case RESEND_CMD_FC_ISP_START:
|
||||
/*关闭其他线程中相同串口的使用,并复位飞控,使其进入isp烧录模式,串口切换为偶校验模式
|
||||
使用sync与isp确定通讯波特率,并建立联系 解除其写保护 并重新sync建立连接后擦除全部区域内存*/
|
||||
//关闭其他线程中相同串口的使用
|
||||
sertrf.stmisp_device.flag = 1;
|
||||
// 修改灯珠颜色
|
||||
protocol_set_message_status(MESSAGE_FC_ISP);
|
||||
// 重启飞控,并使其进入isp烧录模式 需要在能够识别飞控的情况下才需要重启
|
||||
// if(sertrf.fc_protocol_status != PROTOCOL_STATUS_TYPE_IDLE && sertrf.fc_protocol_status != PROTOCOL_STATUS_NO_DATA)
|
||||
fc_reboot();
|
||||
boot_set_2(0);
|
||||
os_thread_sleep(1000);
|
||||
//串口切换为偶校验模式,并清除缓存
|
||||
uart_set_parity_switch(sertrf.device.embedded_device, 0x02);
|
||||
os_thread_sleep(100);
|
||||
// 与isp确定通讯波特率,并建立联系
|
||||
if(!send_sync(&sertrf.stmisp_device, 5))
|
||||
{
|
||||
SYS_LOG_DBG("stmisp: sync error\n");
|
||||
// app_send_error_code(SERTRF_ERROR_FC_ISP_SYNC);
|
||||
break;
|
||||
}
|
||||
else
|
||||
SYS_LOG_DBG("stmisp: sync ok\n");
|
||||
|
||||
os_thread_sleep(100);
|
||||
|
||||
// 解除写保护
|
||||
if(!cmd_write_unprotect(&sertrf.stmisp_device))
|
||||
SYS_LOG_DBG("stmisp: write unprotect error\n");
|
||||
else
|
||||
SYS_LOG_DBG("stmisp: write unprotect ok\n");
|
||||
|
||||
os_thread_sleep(100);
|
||||
|
||||
|
||||
if(!send_sync(&sertrf.stmisp_device, 5))
|
||||
SYS_LOG_DBG("stmisp: sync error\n");
|
||||
else
|
||||
SYS_LOG_DBG("stmisp: sync ok\n");
|
||||
os_thread_sleep(100);
|
||||
|
||||
boot_set_high_z_2();
|
||||
// 全盘擦除
|
||||
if(!cmd_extended_erase_mass(&sertrf.stmisp_device))
|
||||
SYS_LOG_DBG("stmisp: erase mass error\n");
|
||||
else
|
||||
SYS_LOG_DBG("stmisp: erase mass ok\n");
|
||||
|
||||
os_thread_sleep(10);
|
||||
|
||||
SYS_LOG_DBG("stmisp: isp start\n");
|
||||
|
||||
sertrf.mode_status.task_state = DATA_HANDLE_ISP_DATA;
|
||||
resend_send_cmd(resend_device, RESEND_CMD_ACK, 0);
|
||||
break;
|
||||
case RESEND_CMD_FC_ISP_DATA:
|
||||
protocol_set_message_status(MESSAGE_FC_ISP);
|
||||
// 使用环形buff
|
||||
if(rb_size(&sertrf.data_handle_buffer) + sertrf.resend_device.rx_frame.len <= DATA_HANDLE_BUFFER_SIZE)
|
||||
{
|
||||
rb_put_bulk(&sertrf.data_handle_buffer, sertrf.resend_device.rx_frame.payload, sertrf.resend_device.rx_frame.len);
|
||||
}
|
||||
else
|
||||
{
|
||||
SYS_LOG_DBG("RESEND_CMD_FC_ISP_DATA buffer full");
|
||||
}
|
||||
// resend_send_cmd(resend_device, RESEND_CMD_ACK, 0);
|
||||
break;
|
||||
case RESEND_CMD_FC_ISP_END:
|
||||
// 告诉数据处理线程,ISP烧录数据传输完成
|
||||
sertrf.mode_status.task_state = DATA_HANDLE_ISP_DATA_END;
|
||||
// 等待数据处理线程写入完成
|
||||
SYS_LOG_INF("RESEND_CMD_FC_ISP_END1");
|
||||
while(sertrf.mode_status.task_state != DATA_HANDLE_IDLE){
|
||||
os_thread_sleep(10);}
|
||||
// ISP下跳转到应用层运行地址
|
||||
if(cmd_go(&sertrf.stmisp_device, sertrf.fc_address))
|
||||
{
|
||||
SYS_LOG_DBG("stmisp: go ok\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
SYS_LOG_DBG("stmisp: go error\n");
|
||||
}
|
||||
//开启其他线程中相同串口的使用
|
||||
sertrf.stmisp_device.flag = 0;
|
||||
// 将串口切换为无校验模式
|
||||
uart_set_parity_switch(sertrf.device.embedded_device, 0x00);
|
||||
SYS_LOG_INF("RESEND_CMD_FC_ISP_END2");
|
||||
protocol_set_message_status(MESSAGE_IDLE);
|
||||
resend_send_cmd(resend_device, RESEND_CMD_ACK, 0);
|
||||
esp_restart();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Examples_run(void)
|
||||
{
|
||||
//关闭其他线程中相同串口的使用
|
||||
// // //关闭其他线程中相同串口的使用
|
||||
sertrf.stmisp_device.flag = 1;
|
||||
// 重启飞控,并使其进入isp烧录模式
|
||||
// // // 重启飞控,并使其进入isp烧录模式
|
||||
fc_reboot();
|
||||
boot_set(1);
|
||||
os_thread_sleep(1000);
|
||||
boot_set(0);
|
||||
os_thread_sleep(500);
|
||||
uart_set_parity_switch(sertrf.device.embedded_device, 0x02);
|
||||
os_thread_sleep(100);
|
||||
os_thread_sleep(500);
|
||||
// 与isp确定通讯波特率,并建立联系
|
||||
if(!send_sync(&sertrf.stmisp_device, 5))
|
||||
printf("stmisp: sync error\n");
|
||||
SYS_LOG_DBG("stmisp: sync error\n");
|
||||
else
|
||||
printf("stmisp: sync ok\n");
|
||||
SYS_LOG_DBG("stmisp: sync ok\n");
|
||||
|
||||
os_thread_sleep(100);
|
||||
|
||||
// 解除写保护
|
||||
if(!cmd_write_unprotect(&sertrf.stmisp_device))
|
||||
printf("stmisp: write unprotect error\n");
|
||||
SYS_LOG_DBG("stmisp: write unprotect error\n");
|
||||
else
|
||||
printf("stmisp: write unprotect ok\n");
|
||||
SYS_LOG_DBG("stmisp: write unprotect ok\n");
|
||||
|
||||
os_thread_sleep(100);
|
||||
if(!send_sync(&sertrf.stmisp_device, 5))
|
||||
printf("stmisp: sync error\n");
|
||||
SYS_LOG_DBG("stmisp: sync error\n");
|
||||
else
|
||||
printf("stmisp: sync ok\n");
|
||||
SYS_LOG_DBG("stmisp: sync ok\n");
|
||||
os_thread_sleep(100);
|
||||
|
||||
boot_set_high_z();
|
||||
// 全盘擦除
|
||||
if(!cmd_extended_erase_mass(&sertrf.stmisp_device))
|
||||
printf("stmisp: erase mass error\n");
|
||||
SYS_LOG_DBG("stmisp: erase mass error\n");
|
||||
else
|
||||
printf("stmisp: erase mass ok\n");
|
||||
SYS_LOG_DBG("stmisp: erase mass ok\n");
|
||||
|
||||
os_thread_sleep(10);
|
||||
|
||||
printf("stmisp: isp start\n");
|
||||
SYS_LOG_DBG("stmisp: isp start\n");
|
||||
|
||||
}
|
||||
int stmisp_send(void* data, uint16_t len, int timeout)
|
||||
@@ -439,3 +667,10 @@ int stmisp_get_length(void)
|
||||
{
|
||||
return embedded_device_get_rx_length(&sertrf.device);
|
||||
}
|
||||
|
||||
int app_send_error_code(uint8_t error_code)
|
||||
{
|
||||
sertrf.mode_status.sertrf_error_code = error_code;
|
||||
|
||||
return resend_send_data(&sertrf.resend_device, RESEND_CMD_ERROR_CODE, &sertrf.mode_status.sertrf_error_code, sizeof(sertrf_mode_status_t), 1000);
|
||||
}
|
||||
@@ -7,17 +7,56 @@
|
||||
#include "protocol/resend_protl.h"
|
||||
#include "protocol/stmisp.h"
|
||||
#include "ota_u.h"
|
||||
#include "tool.h"
|
||||
#include "ring_buffer.h"
|
||||
#include "../../config/app_config.h"
|
||||
|
||||
#define FC_ADDRESS "0x08000000"
|
||||
#define DATA_HANDLE_BUFFER_SIZE 4096
|
||||
|
||||
#define RF_OFF_COLOR RGB_COLOR_NONE //关闭射频灯的颜色指示
|
||||
#define WIFI_AP_COLOR RGB_COLOR_WHITE //连接WIFI AP模式指示
|
||||
#define WIFI_STA_COLOR RGB_COLOR_PURPLE //连接WIFI STA模式指示
|
||||
#define BLE_COLOR RGB_COLOR_GREEN //连接BLE模式指示
|
||||
#define NO_CONNECT_COLOR_BLE_AP RGB_COLOR_GREEN_WHITE //未连接模式指示BLE+AP
|
||||
#define NO_CONNECT_COLOR_BLE_STA RGB_COLOR_GREEN_PURPLE //未连接模式指示BLE+STA
|
||||
typedef enum
|
||||
{
|
||||
DATA_HANDLE_IDLE = 0,
|
||||
DATA_HANDLE_OTA_DATA,
|
||||
DATA_HANDLE_OTA_DATA_END,
|
||||
DATA_HANDLE_ISP_DATA,
|
||||
DATA_HANDLE_ISP_DATA_END
|
||||
}data_handle_e;
|
||||
typedef enum
|
||||
{
|
||||
SERTRF_ERROR_NONE = 0,
|
||||
SERTRF_ERROR_OTA_INIT = 10, // ota初始化失败
|
||||
SERTRF_ERROR_OTA_DATA, // ota数据传输异常
|
||||
SERTRF_ERROR_OTA_END, // ota 结束异常
|
||||
|
||||
SERTRF_ERROR_FC_ISP_UART_TYPE = 30, // 飞控ISP 无法识别其协议
|
||||
SERTRF_ERROR_FC_ISP_UART_DATA, // 飞控ISP 无法收到其数据
|
||||
SERTRF_ERROR_FC_ISP_SYNC, // 飞控ISP 无法与ISP建立连接,需判断BOOT键是否有效
|
||||
}sertrf_error_code_e;
|
||||
typedef struct __attribute__((packed))
|
||||
{
|
||||
data_handle_e task_state;
|
||||
|
||||
uint16_t sertrf_error_code;
|
||||
}sertrf_mode_status_t;
|
||||
typedef struct
|
||||
{
|
||||
device_t device;
|
||||
os_thread_t embedded_thread;
|
||||
os_thread_t pc_thread;
|
||||
os_thread_t task_thread;
|
||||
os_thread_t app_thread;
|
||||
// 任务
|
||||
os_thread_t embedded_thread; //处理飞控接收
|
||||
os_thread_t pc_thread; //处理app接收
|
||||
os_thread_t task_thread; //处理其他任务
|
||||
os_thread_t app_thread; //处理app任务
|
||||
os_thread_t data_handle_thread; //数据处理任务
|
||||
|
||||
sertrf_mode_status_t mode_status;
|
||||
// ota
|
||||
ota_u_t otau;
|
||||
|
||||
//自定义协议
|
||||
@@ -27,16 +66,29 @@ typedef struct
|
||||
//STMISP协议
|
||||
stmisp_device_t stmisp_device;
|
||||
|
||||
// 环形buff
|
||||
RingBuffer data_handle_buffer;
|
||||
uint32_t fc_address;
|
||||
|
||||
// efuse MAC 地址
|
||||
uint8_t efuse_mac[6];
|
||||
uint8_t efuse_mac_encrypt[6];
|
||||
|
||||
// 记录错误信息
|
||||
protocol_status_e fc_protocol_status; //飞控连接端的协议状态
|
||||
|
||||
// 判断是否使用强刷固件
|
||||
uint8_t force_update;
|
||||
}sertrf_t;
|
||||
|
||||
typedef struct
|
||||
typedef struct __attribute__((packed))
|
||||
{
|
||||
char ble_name[32];
|
||||
char wifi_ap_ssid[32];
|
||||
char wifi_ap_password[32];
|
||||
char wifi_sta_ssid[32];
|
||||
char wifi_sta_password[32];
|
||||
uint8_t efuse_mac_encrypt[6];
|
||||
}sertrf_stauct_t;
|
||||
/**
|
||||
* @brief 模块初始化
|
||||
@@ -53,6 +105,11 @@ void sertrf_start(void);
|
||||
*/
|
||||
void sertrf_stop(void);
|
||||
|
||||
/**
|
||||
* @brief 射频模块开关
|
||||
*/
|
||||
void sertrf_rf_switch(uint8_t on);
|
||||
|
||||
/**
|
||||
* @brief 模块数据查看
|
||||
*/
|
||||
@@ -75,18 +132,18 @@ void app_thread(void* arg);
|
||||
* @brief task thread
|
||||
*/
|
||||
void task_thread(void* arg);
|
||||
/**
|
||||
* @brief data handle thread
|
||||
*/
|
||||
void data_handle_thread(void* arg);
|
||||
|
||||
/**
|
||||
* @brief 根据连接状态显示不同的颜色
|
||||
*
|
||||
* @param connect 连接状态
|
||||
*/
|
||||
void pc_link_rgb_color(device_t* device);
|
||||
/**
|
||||
* @brief 打印时间间隔
|
||||
*/
|
||||
void printf_chill_time(uint8_t chill_time, uint16_t type);
|
||||
/**
|
||||
* @brief 字符串转十进制
|
||||
*/
|
||||
uint32_t parse_hex_or_dec(const char *s);
|
||||
|
||||
int app_send_error_code(uint8_t error_code);
|
||||
|
||||
|
||||
|
||||
140
app/drivers/sertrf/tool.c
Normal file
140
app/drivers/sertrf/tool.c
Normal file
@@ -0,0 +1,140 @@
|
||||
#include "tool.h"
|
||||
|
||||
uint8_t efuse_mac[6];
|
||||
int time_out(uint32_t* time_start, uint32_t timeout_ms)
|
||||
{
|
||||
uint32_t time_new = os_get_sys_time();
|
||||
if(time_new - *time_start > timeout_ms)
|
||||
{
|
||||
*time_start = time_new;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void printf_chill_time(uint8_t chill_time, uint16_t type)
|
||||
{
|
||||
static size_t last_time[24] = {0};
|
||||
static uint16_t cnt[24] = {0};
|
||||
static uint32_t type_cnt_time[24] = {0};
|
||||
size_t now_time = os_get_sys_time();
|
||||
cnt[chill_time]++;
|
||||
type_cnt_time[chill_time] += now_time - last_time[chill_time];
|
||||
if(cnt[chill_time] % type == 0 && type_cnt_time[chill_time] / type >= now_time - last_time[chill_time] - 1)
|
||||
{
|
||||
SYS_LOG_INF("TIME_CHILL%d : %d : %d\n",chill_time, now_time - last_time[chill_time], type_cnt_time[chill_time]);
|
||||
cnt[chill_time] = 0;
|
||||
type_cnt_time[chill_time] = 0;
|
||||
}
|
||||
else if(cnt[chill_time] % type == 0)
|
||||
{
|
||||
SYS_LOG_WRN("TIME_CHILL%d : %d : %d",chill_time, now_time - last_time[chill_time], type_cnt_time[chill_time]);
|
||||
cnt[chill_time] = 0;
|
||||
type_cnt_time[chill_time] = 0;
|
||||
}
|
||||
last_time[chill_time] = now_time;
|
||||
}
|
||||
|
||||
uint32_t parse_hex_or_dec(const char *s) {
|
||||
if (!s) return 0;
|
||||
if (s[0] == '0' && (s[1]=='x' || s[1]=='X')) return (uint32_t)strtoul(s+2, NULL, 16);
|
||||
return (uint32_t)strtoul(s, NULL, 0);
|
||||
}
|
||||
|
||||
void aes_test(void)
|
||||
{
|
||||
// if(!esp_efuse_mac_get_default_id(efuse_mac))
|
||||
// SYS_LOG_DBG("mac: %02X:%02X:%02X:%02X:%02X:%02X\n", efuse_mac[0], efuse_mac[1], efuse_mac[2], efuse_mac[3], efuse_mac[4], efuse_mac[5]);
|
||||
|
||||
// const unsigned char key[16] = "1234567890abcdef"; // 128-bit key
|
||||
// unsigned char nonce_counter[16] = {0}; // 初始计数器块 (可用随机数 + 计数)
|
||||
// unsigned char stream_block[16] = {0}; // 内部缓冲
|
||||
// size_t nc_off = 0;
|
||||
|
||||
// const unsigned char input[] = "Hello AES-CTR on ESP32!";
|
||||
// unsigned char output[64] = {0};
|
||||
|
||||
// mbedtls_aes_context aes;
|
||||
// mbedtls_aes_init(&aes);
|
||||
// mbedtls_aes_setkey_enc(&aes, key, 128);
|
||||
|
||||
// // 加密
|
||||
// mbedtls_aes_crypt_ctr(&aes, sizeof(efuse_mac), &nc_off,
|
||||
// nonce_counter, stream_block, efuse_mac, output);
|
||||
|
||||
// SYS_LOG_DBG("Ciphertext (hex): ");
|
||||
// for (int i = 0; i < sizeof(efuse_mac); i++)
|
||||
// SYS_LOG_DBG("%02X", output[i]);
|
||||
// SYS_LOG_DBG("\n");
|
||||
|
||||
// // 解密(同一函数)
|
||||
// unsigned char decrypted[64] = {0};
|
||||
// nc_off = 0;
|
||||
// memset(nonce_counter, 0, 16);
|
||||
// memset(stream_block, 0, 16);
|
||||
|
||||
// mbedtls_aes_crypt_ctr(&aes, sizeof(efuse_mac), &nc_off,
|
||||
// nonce_counter, stream_block, output, decrypted);
|
||||
|
||||
// SYS_LOG_DBG("Decrypted: %s\n", decrypted);
|
||||
|
||||
// mbedtls_aes_free(&aes);
|
||||
|
||||
|
||||
if(!esp_efuse_mac_get_default_id(efuse_mac))
|
||||
SYS_LOG_DBG("mac: %02X:%02X:%02X:%02X:%02X:%02X\n", efuse_mac[0], efuse_mac[1], efuse_mac[2], efuse_mac[3], efuse_mac[4], efuse_mac[5]);
|
||||
|
||||
uint8_t efuse_mac_encrypt[6] = {0};
|
||||
sertrf_aes_ctr_encrypt(efuse_mac, 6, efuse_mac_encrypt);
|
||||
SYS_LOG_DBG("mac: %02X:%02X:%02X:%02X:%02X:%02X\n", efuse_mac_encrypt[0], efuse_mac_encrypt[1], efuse_mac_encrypt[2], efuse_mac_encrypt[3], efuse_mac_encrypt[4], efuse_mac_encrypt[5]);
|
||||
|
||||
uint8_t efuse_mac_decrypt[6] = {0};
|
||||
sertrf_aes_ctr_decrypt(efuse_mac_encrypt, 6, efuse_mac_decrypt);
|
||||
SYS_LOG_DBG("mac: %02X:%02X:%02X:%02X:%02X:%02X\n", efuse_mac_decrypt[0], efuse_mac_decrypt[1], efuse_mac_decrypt[2], efuse_mac_decrypt[3], efuse_mac_decrypt[4], efuse_mac_decrypt[5]);
|
||||
}
|
||||
|
||||
void sertrf_aes_ctr_encrypt(uint8_t *data, uint32_t len,uint8_t* output)
|
||||
{
|
||||
size_t nc_off = 0;
|
||||
unsigned char nonce_counter[16] = {0}; // 初始计数器块 (可用随机数 + 计数)
|
||||
unsigned char stream_block[16] = {0}; // 内部缓冲
|
||||
|
||||
const unsigned char key[16] = PRIVATE_KEY; // 128-bit key
|
||||
|
||||
mbedtls_aes_context aes;
|
||||
mbedtls_aes_init(&aes);
|
||||
mbedtls_aes_setkey_enc(&aes, key, 128);
|
||||
|
||||
// 加密
|
||||
mbedtls_aes_crypt_ctr(&aes, len, &nc_off,
|
||||
nonce_counter, stream_block, data, output);
|
||||
mbedtls_aes_free(&aes);
|
||||
}
|
||||
void sertrf_aes_ctr_decrypt(uint8_t *data, uint32_t len,uint8_t* output)
|
||||
{
|
||||
size_t nc_off = 0;
|
||||
unsigned char nonce_counter[16] = {0}; // 初始计数器块 (可用随机数 + 计数)
|
||||
unsigned char stream_block[16] = {0}; // 内部缓冲
|
||||
|
||||
const unsigned char key[16] = PRIVATE_KEY; // 128-bit key
|
||||
|
||||
mbedtls_aes_context aes;
|
||||
mbedtls_aes_init(&aes);
|
||||
mbedtls_aes_setkey_enc(&aes, key, 128);
|
||||
|
||||
mbedtls_aes_crypt_ctr(&aes, len, &nc_off,
|
||||
nonce_counter, stream_block, data, output);
|
||||
mbedtls_aes_free(&aes);
|
||||
}
|
||||
esp_err_t esp_efuse_mac_get_default_id(uint8_t *mac)
|
||||
{
|
||||
esp_err_t err = esp_efuse_mac_get_default(mac);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
#if CONFIG_SOC_IEEE802154_SUPPORTED
|
||||
return insert_mac_ext_into_mac(mac);
|
||||
#else
|
||||
return ESP_OK;
|
||||
#endif
|
||||
}
|
||||
55
app/drivers/sertrf/tool.h
Normal file
55
app/drivers/sertrf/tool.h
Normal file
@@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include "os/os.h"
|
||||
#include "sys_log.h"
|
||||
#include "mbedtls/aes.h"
|
||||
#include <esp_err.h>
|
||||
#include "esp_system.h"
|
||||
#include "esp_mac.h"
|
||||
#include "../data_port/ble_spp/ble_spp_server.h"
|
||||
|
||||
#define PRIVATE_KEY "1234567890abcdef"
|
||||
|
||||
/**
|
||||
* @brief 超时判断
|
||||
*
|
||||
*/
|
||||
int time_out(uint32_t* time_start, uint32_t timeout_ms);
|
||||
/**
|
||||
* @brief 打印时间间隔
|
||||
*/
|
||||
void printf_chill_time(uint8_t chill_time, uint16_t type);
|
||||
/**
|
||||
* @brief 字符串转十进制
|
||||
*/
|
||||
uint32_t parse_hex_or_dec(const char *s);
|
||||
|
||||
/**
|
||||
* @brief AEStest
|
||||
*/
|
||||
void aes_test(void);
|
||||
|
||||
/**
|
||||
* @brief AES加密
|
||||
*/
|
||||
void sertrf_aes_ctr_encrypt(uint8_t *data, uint32_t len,uint8_t* output);
|
||||
/**
|
||||
* @brief AES解密
|
||||
*/
|
||||
void sertrf_aes_ctr_decrypt(uint8_t *data, uint32_t len,uint8_t* output);
|
||||
|
||||
/**
|
||||
* @breif 获取ESP MAC地址
|
||||
*/
|
||||
esp_err_t esp_efuse_mac_get_default_id(uint8_t *mac);
|
||||
|
||||
/**
|
||||
* @brief 获取BLE MAC地址
|
||||
*/
|
||||
esp_err_t esp_efuse_ble_mac_get_default(uint8_t *mac);
|
||||
@@ -25,3 +25,13 @@ CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=1536
|
||||
CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID=y
|
||||
CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS=y
|
||||
CONFIG_LOG_DEFAULT_LEVEL_NONE=y
|
||||
|
||||
#定义APP配置
|
||||
CONFIG_BOARD_NAME_SERTRF_ESP32C3=y
|
||||
CONFIG_PRODUCT_ID_SERTRF=y
|
||||
|
||||
|
||||
#关闭bootloard生成输出日志
|
||||
#CONFIG_BOOT_ROM_LOG_ON_GPIO_LOW=y
|
||||
#设置应用层输出日志等级
|
||||
#CONFIG_LOG_DEFAULT_LEVEL_INFO=y
|
||||
Reference in New Issue
Block a user