Compare commits

..

2 Commits

Author SHA1 Message Date
dcca71d4d5 解决冲突 2025-07-18 17:41:50 +08:00
32b20c85ad 1.更新开机逻辑 2.修复开机LED设置常亮时开机异常 2025-07-18 16:33:00 +08:00
5 changed files with 226 additions and 235 deletions

View File

@ -818,10 +818,10 @@ static int ws_connect(transport client, const char *host, int port, int timeout_
}
header_len += len;
ws->buffer[header_len] = '\0';
BK_LOGE(TAG, "Read header chunk %d, current header size: %d\r\n", len, header_len);
BK_LOGD(TAG, "Read header chunk %d, current header size: %d\r\n", len, header_len);
} while (NULL == os_strstr(ws->buffer, "\r\n\r\n") && header_len < WS_BUFFER_SIZE);
os_printf("server buffer:\r\n");
bk_hex_dump(ws->buffer, 200);
//os_printf("server buffer:\r\n");
//bk_hex_dump(ws->buffer, 200);
#if 0
if (header_len == WS_BUFFER_SIZE) {
char *is_chunk = get_http_header(ws->buffer, "Transfer-Encoding:");
@ -853,9 +853,9 @@ static int ws_connect(transport client, const char *host, int port, int timeout_
}
mbedtls_base64_encode(expected_server_key, sizeof(expected_server_key), &outlen, expected_server_sha1, sizeof(expected_server_sha1));
expected_server_key[ (outlen < sizeof(expected_server_key)) ? outlen : (sizeof(expected_server_key) - 1) ] = 0;
BK_LOGE(TAG, "server key=%s\r\n\r\n", (char *)server_key);
BK_LOGE(TAG, "send_key=%s\r\n\r\n", (char*)client_key);
BK_LOGE(TAG, "expected_server_key=%s\r\n\r\n", expected_server_key);
BK_LOGD(TAG, "server key=%s\r\n\r\n", (char *)server_key);
BK_LOGD(TAG, "send_key=%s\r\n\r\n", (char*)client_key);
BK_LOGD(TAG, "expected_server_key=%s\r\n\r\n", expected_server_key);
if (os_strcmp((char*)expected_server_key, (char*)server_key) != 0) {
BK_LOGE(TAG, "Invalid websocket key\r\n");
return BK_FAIL;
@ -1082,7 +1082,7 @@ bk_err_t websocket_client_set_uri(transport client, const char *uri)
}
os_strncpy(client->config->scheme, uri + puri.field_data[UF_SCHEMA].off, puri.field_data[UF_SCHEMA].len);
//client->config->scheme[puri.field_data[UF_SCHEMA].len] = '\0';
os_printf("%s scheme:%s len:%d\r\n", __func__, client->config->scheme, puri.field_data[UF_SCHEMA].len);
//os_printf("%s scheme:%s len:%d\r\n", __func__, client->config->scheme, puri.field_data[UF_SCHEMA].len);
}
if (puri.field_data[UF_HOST].len) {
@ -1346,7 +1346,7 @@ void websocket_client_task(beken_thread_arg_t *thread_param)
while (client->run) {
switch ((int)client->state) {
case WEBSOCKET_STATE_INIT:
BK_LOGE(TAG, "websocket connecting to %s://%s:%d\r\n", client->config->scheme, client->config->host, client->config->port);
BK_LOGD(TAG, "websocket connecting to %s://%s:%d\r\n", client->config->scheme, client->config->host, client->config->port);
if (ws_connect(client, client->config->host,
client->config->port,
WEBSOCKET_NETWORK_TIMEOUT_MS) < 0) {
@ -1354,7 +1354,7 @@ void websocket_client_task(beken_thread_arg_t *thread_param)
ws_disconnect(client);
break;
}
BK_LOGE(TAG, "websocket connected to %s://%s:%d\r\n", client->config->scheme, client->config->host, client->config->port);
BK_LOGD(TAG, "websocket connected to %s://%s:%d\r\n", client->config->scheme, client->config->host, client->config->port);
client->state = WEBSOCKET_STATE_CONNECTED;
client->wait_for_pong_resp = false;
bk_websocket_client_dispatch_event(client, WEBSOCKET_EVENT_CONNECTED, NULL, 0, -1);

View File

@ -31,6 +31,8 @@
static const uint32_t s_factory_volume = 7;
static const uint32_t s_bat_offset = 0;
static const uint32_t s_bright_timeout = 10;
static const uint32_t s_bright_brightness = 100;
const struct factory_config_t s_platform_config[] = {
{"sys_initialized", (void *)"1", 1, BK_FALSE, 1}, // first config used to check whether factory config initialized.
@ -40,6 +42,8 @@ const struct factory_config_t s_platform_config[] = {
{"bat_offset", (void *)&s_bat_offset, 4, BK_TRUE, 4},
{"ai_ota_url", (void *)"\0", 1, BK_TRUE, 128},
{"ai_agent_id", (void *)"\0", 1, BK_TRUE, 128},
{"bright_timeout", (void *)&s_bright_timeout, 4, BK_TRUE, 4},
{"bright_brightness", (void *)&s_bright_brightness, 4, BK_TRUE, 4},
};
static const struct factory_config_t *s_user_reg_config = NULL;

View File

@ -103,6 +103,8 @@ const struct factory_config_t s_user_config[] = {
#if (CONFIG_SYS_CPU0)
#include "iot/thing.h"
#endif
void power_on();
void power_off();
static int beken_rtc_cli_init(void)
{
@ -140,31 +142,55 @@ void prepare_config_network_main()
config_network_thread_handle = NULL;
rtos_delete_thread(NULL);
}
void power_off()
beken_timer_t g_adckey_timer;
static void adc_key_ticks(void *param)
{
BK_LOGI(TAG, " power_off\r\n");
BK_LOGW(TAG, " ************TODO:Just force deep sleep for Demo!\r\n");
// extern bk_err_t audio_turn_off(void);
// extern bk_err_t video_turn_off(void);
// audio_turn_off();
// video_turn_off();
//zhanyu
// bk_reboot_ex(RESET_SOURCE_FORCE_DEEPSLEEP);
}
bk_printf("adc_key_ticks9\n");
void power_on()
{
BK_LOGI(TAG, "power_on\r\n");
}
#if (CONFIG_SYS_CPU0)
gsensor_demo_init();
// rtos_delay_milliseconds(100);
// gsensor_demo_open();
rtos_delay_milliseconds(300);
gsensor_demo_set_normal();
#endif
void ai_agent_config()
{
// BK_LOGW(TAG, " ************TODO:AI Agent doesn't complete!\r\n");
rtos_stop_timer(&g_adckey_timer);
rtos_deinit_timer(&g_adckey_timer);
}
KeyConfig_t key_config[] = {
// zhanyu
{
.gpio_id = KEY_GPIO_12,
.active_level = LOW_LEVEL_TRIGGER,
.short_event = POWER_ON,
//.double_event = TURN_ON_LOGHT,
.long_event = TURN_OFF_LOGHT}
// {
// .gpio_id = KEY_GPIO_13, //corresponding to the actual key
// .active_level = LOW_LEVEL_TRIGGER,
// .short_event = VOLUME_UP,
// .double_event = VOLUME_UP, //TRICK: at shutdown mode, it can't recognize double press,short_event is really power on.(but short event is used by VOLUME UP when system is active).
// .long_event = CONFIG_NETWORK
// },
// {
// .gpio_id = KEY_GPIO_12,
// .active_level = LOW_LEVEL_TRIGGER,
// .short_event = POWER_ON,
// .double_event = POWER_ON,
// .long_event = SHUT_DOWN
// },
// {
// .gpio_id = KEY_GPIO_8,
// .active_level = LOW_LEVEL_TRIGGER,
// .short_event = VOLUME_DOWN,
// .double_event = VOLUME_DOWN,
// .long_event = FACTORY_RESET
// }
};
/*Do not execute blocking or time-consuming long code in event handler
functions. The reason is that key_thread processes messages in a
@ -176,30 +202,7 @@ static void handle_system_event(key_event_t event)
extern void bk_bt_app_avrcp_ct_vol_change(uint32_t platform_vol);
switch (event)
{
// case VOLUME_UP:
// {
// uint32_t old_volume = volume;
// volume_increase();
// if (old_volume != volume)
// {
// #if CONFIG_A2DP_SINK_DEMO
// bk_bt_app_avrcp_ct_vol_change(volume);
// #endif
// }
// }
// break;
// case VOLUME_DOWN:
// {
// uint32_t old_volume = volume;
// volume_decrease();
// if (old_volume != volume)
// {
// #if CONFIG_A2DP_SINK_DEMO
// bk_bt_app_avrcp_ct_vol_change(volume);
// #endif
// }
// }
// break;
// case SHUT_DOWN:
// time = rtos_get_time(); // long press more than 6s
// if (time < 9000)
@ -235,13 +238,16 @@ static void handle_system_event(key_event_t event)
// bk_factory_reset();
// bk_reboot();
// break;
case POWER_ON:
bk_printf("POWER_KEY PRESS\n");
break;
case TURN_OFF_LOGHT:
bk_printf("ispoweron11 = %d\n", ispoweron);
bk_printf("current is power on = %d\n", ispoweron);
// clearallled();
if (ispoweron == 1)
{
bk_printf("POWER OFFaaa~~~ \r\n");
bk_printf("POWER OFF!!\r\n");
poweroff_voice();
ws2812_led_clear_all();
ispoweron = 0;
@ -252,9 +258,10 @@ static void handle_system_event(key_event_t event)
}
else if (ispoweron == 0)
{
bk_printf("POWER ONaaaa~~~~~~~\r\n");
bk_printf("POWER ON \r\n");
power_on();
#if (CONFIG_SYS_CPU0)
//打开电源供电
bk_gpio_enable_output(51);
bk_gpio_set_output_high(51);
ispoweron = 1;
@ -272,40 +279,120 @@ static void handle_system_event(key_event_t event)
}
}
KeyConfig_t key_config[] = {
// zhanyu
void power_off()
{
BK_LOGE(TAG, " power_off\r\n");
BK_LOGW(TAG, " ************TODO:Just force deep sleep for Demo!\r\n");
// extern bk_err_t audio_turn_off(void);
// extern bk_err_t video_turn_off(void);
// audio_turn_off();
// video_turn_off();
//zhanyu
// bk_reboot_ex(RESET_SOURCE_FORCE_DEEPSLEEP);
}
void power_on()
{
BK_LOGE(TAG, "power_on!!!!!!\r\n");
#if (CONFIG_SYS_CPU0)
bk_regist_factory_user_config((const struct factory_config_t *)&s_user_config,
sizeof(s_user_config) / sizeof(s_user_config[0]));
bk_factory_init();
#endif
// led init move before
#if (CONFIG_SYS_CPU0)
// No operation countdown 3 minutes to shut down
// start_countdown(countdown_ms);
// led init move before
led_driver_init();
led_app_set(LED_ON_GREEN, LED_LAST_FOREVER);
#endif
// media_service_init();
#if (CONFIG_SYS_CPU0)
//app_event_init();
#if CONFIG_AUD_INTF_SUPPORT_PROMPT_TONE
extern bk_err_t audio_turn_on(void);
int ret = audio_turn_on();
if (ret != BK_OK)
{
.gpio_id = KEY_GPIO_12,
.active_level = LOW_LEVEL_TRIGGER,
//.short_event = TURN_ON_LOGHT,
//.double_event = TURN_ON_LOGHT,
.long_event = TURN_OFF_LOGHT}
// {
// .gpio_id = KEY_GPIO_13, //corresponding to the actual key
// .active_level = LOW_LEVEL_TRIGGER,
// .short_event = VOLUME_UP,
// .double_event = VOLUME_UP, //TRICK: at shutdown mode, it can't recognize double press,short_event is really power on.(but short event is used by VOLUME UP when system is active).
// .long_event = CONFIG_NETWORK
// },
// {
// .gpio_id = KEY_GPIO_12,
// .active_level = LOW_LEVEL_TRIGGER,
// .short_event = POWER_ON,
// .double_event = POWER_ON,
// .long_event = SHUT_DOWN
// },
// {
// .gpio_id = KEY_GPIO_8,
// .active_level = LOW_LEVEL_TRIGGER,
// .short_event = VOLUME_DOWN,
// .double_event = VOLUME_DOWN,
// .long_event = FACTORY_RESET
BK_LOGE(TAG, "%s, %d, audio turn on fail, ret:%d\n", __func__, __LINE__, ret);
}
#endif
#endif
#if (CONFIG_SYS_CPU1)
beken_rtc_cli_init();
#endif
#if (CONFIG_SYS_CPU0)
bk_pm_module_vote_boot_cp1_ctrl(PM_BOOT_CP1_MODULE_NAME_AUDP_AUDIO, PM_POWER_MODULE_STATE_ON);
bk_genie_core_init();
#if CONFIG_NETWORK_AUTO_RECONNECT
bk_genie_smart_config_init();
#endif
#if CONFIG_BAT_MONITOR
extern void battery_monitor_init(void);
battery_monitor_init();
#endif
bk_err_t result;
result = rtos_init_timer(&g_adckey_timer,
6000,
adc_key_ticks,
(void *)0);
if (result != 0)
{
bk_printf("rtos_init_timer fail\r\n");
}
result = rtos_start_timer(&g_adckey_timer);
if (result != 0)
{
bk_printf("rtos_start_timer fail\r\n");
}
#if (CONFIG_SYS_CPU0)
// bk_printf("ispoweron = %d bk_enter_deepsleep();\n",ispoweron);
// if(ispoweron == 0){
// bk_printf("bk_enter_deepsleep()aaa\n");
// bk_enter_deepsleep();
// }
};
static void bk_key_register_wakeup_source()
{
// poka
ws2812_init();
thing_init();
app_start();
init_bat_timer();
// spi_led_init();
bk_printf("VER:%s\r\n", APPLICATION_VERSION);
#endif
#endif
#if CONFIG_USBD_MSC
extern void msc_storage_init(void);
msc_storage_init();
#endif
}
void ai_agent_config()
{
// BK_LOGW(TAG, " ************TODO:AI Agent doesn't complete!\r\n");
}
static void bk_key_register_wakeup_source()
{
for (uint8_t i = 0; i < sizeof(key_config) / sizeof(KeyConfig_t); i++)
{
if ((key_config[i].short_event == POWER_ON) || (key_config[i].double_event == POWER_ON) || (key_config[i].long_event == POWER_ON))
@ -406,29 +493,10 @@ static void handle_system_event(key_event_t event)
{
#if (CONFIG_SYS_CPU0)
bk_pm_module_vote_cpu_freq(PM_DEV_ID_AUDIO, PM_CPU_FRQ_240M);
beken_rtc_cli_init();
//beken_rtc_cli_init();
#endif
}
beken_timer_t g_adckey_timer;
static void adc_key_ticks(void *param)
{
bk_printf("adc_key_ticks9\n");
#if (CONFIG_SYS_CPU0)
gsensor_demo_init();
// rtos_delay_milliseconds(100);
// gsensor_demo_open();
rtos_delay_milliseconds(300);
gsensor_demo_set_normal();
#endif
rtos_stop_timer(&g_adckey_timer);
rtos_deinit_timer(&g_adckey_timer);
}
int main(void)
{
@ -438,9 +506,6 @@ static void handle_system_event(key_event_t event)
bk_gpio_enable_output(GPIO_0);
bk_gpio_set_output_low(GPIO_0);
if (bk_misc_get_reset_reason() != RESET_SOURCE_FORCE_DEEPSLEEP)
{
#if (CONFIG_SYS_CPU0)
@ -448,6 +513,9 @@ static void handle_system_event(key_event_t event)
#endif
bk_init();
media_service_init();
#if (CONFIG_SYS_CPU0)
#ifdef CONFIG_LDO3V3_ENABLE
BK_LOG_ON_ERR(gpio_dev_unmap(LDO3V3_CTRL_GPIO));
@ -455,113 +523,12 @@ static void handle_system_event(key_event_t event)
bk_gpio_enable_output(LDO3V3_CTRL_GPIO);
bk_gpio_set_output_high(LDO3V3_CTRL_GPIO);
#endif
#endif
#if (CONFIG_SYS_CPU0)
/*to judgement key is long press or short press; long press exit deepsleep*/
//zhanyu
// if (bk_misc_get_reset_reason() == RESET_SOURCE_DEEPPS_GPIO && (bk_gpio_get_wakeup_gpio_id() == KEY_GPIO_12))
// {
// // motor vibration
// motor_open(PWM_MOTOR_CH_3);
// bk_wait_power_on();
// motor_close(PWM_MOTOR_CH_3);
// }
bk_regist_factory_user_config((const struct factory_config_t *)&s_user_config,
sizeof(s_user_config) / sizeof(s_user_config[0]));
bk_factory_init();
#endif
// led init move before
#if (CONFIG_SYS_CPU0)
// No operation countdown 3 minutes to shut down
// start_countdown(countdown_ms);
// led init move before
led_driver_init();
led_app_set(LED_ON_GREEN, LED_LAST_FOREVER);
#endif
media_service_init();
#if (CONFIG_SYS_CPU0)
app_event_init();
#if CONFIG_AUD_INTF_SUPPORT_PROMPT_TONE
extern bk_err_t audio_turn_on(void);
int ret = audio_turn_on();
if (ret != BK_OK)
{
BK_LOGE(TAG, "%s, %d, audio turn on fail, ret:%d\n", __func__, __LINE__, ret);
}
#endif
#endif
#if (CONFIG_SYS_CPU1)
beken_rtc_cli_init();
#endif
#if (CONFIG_SYS_CPU0)
bk_pm_module_vote_boot_cp1_ctrl(PM_BOOT_CP1_MODULE_NAME_AUDP_AUDIO, PM_POWER_MODULE_STATE_ON);
bk_genie_core_init();
#if CONFIG_NETWORK_AUTO_RECONNECT
bk_genie_smart_config_init();
#endif
register_event_handler(handle_system_event);
bk_key_driver_init(key_config, sizeof(key_config) / sizeof(KeyConfig_t));
#if CONFIG_BAT_MONITOR
extern void battery_monitor_init(void);
battery_monitor_init();
#endif
bk_err_t result;
result = rtos_init_timer(&g_adckey_timer,
6000,
adc_key_ticks,
(void *)0);
if (result != 0)
{
bk_printf("rtos_init_timer fail\r\n");
}
result = rtos_start_timer(&g_adckey_timer);
if (result != 0)
{
bk_printf("rtos_start_timer fail\r\n");
}
#if (CONFIG_SYS_CPU0)
// bk_printf("ispoweron = %d bk_enter_deepsleep();\n",ispoweron);
// if(ispoweron == 0){
// bk_printf("bk_enter_deepsleep()aaa\n");
// bk_enter_deepsleep();
// }
//poka
ws2812_init();
thing_init();
app_start();
init_bat_timer();
// spi_led_init();
bk_printf("VER:%s\r\n",APPLICATION_VERSION);
#endif
#endif
#if CONFIG_USBD_MSC
extern void msc_storage_init(void);
msc_storage_init();
#endif
}
else
{

View File

@ -65,11 +65,11 @@ bk_err_t bk_genie_send_msg(bk_genie_msg_t *msg)
//helloyifa
//static wifi_scan_result_t *scan_result = NULL;
static wifi_scan_result_t scan_result = {0};
static wifi_scan_ap_info_t aps_tmps[15];
static wifi_scan_ap_info_t aps_tmps[20];
int ssid_count_in_scan_result(char * ssid){
int count = 0;
for(int i = 0 ;i<15 ;i++){
for(int i = 0 ;i<20 ;i++){
if (strcmp(ssid, aps_tmps[i].ssid) == 0) {
//printf("<22><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
@ -107,11 +107,10 @@ void ble_set_wifi_scan_result(wifi_scan_result_t *result){
if (strlen(scan_result->aps[i].ssid) > 0)
{
// os_printf("WIFI_SCAN:%s\r\n",scan_result->aps[i].ssid);
// <20>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ӹ<EFBFBD><D3B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (ssid_count_in_scan_result(scan_result->aps[i].ssid) > 0)
{
// os_printf("%s alread in list\r\n",scan_result->aps[i].ssid);
continue;
os_printf("%s alread in list\r\n",scan_result->aps[i].ssid);
//continue;
}
// <20><><EFBFBD><EFBFBD>б<EFBFBD>

View File

@ -329,6 +329,7 @@ void ws2812_init(){
int close_led_timeout = APPLICATION_DEFULT_LIGHT_TIMEOUT;
ret = bk_get_env_enhance(WS2812_CONFIG_BRIGHT_TIMEOUT, (void *)&close_led_timeout, 4);
bk_printf("bk_get_env_enhance close_led_timeout:%d\n",close_led_timeout);
work_timeout = close_led_timeout*60*1000;
int brightness = APPLICATION_DEFULT_LIGHT_BRIGHTNESS;
@ -337,8 +338,11 @@ void ws2812_init(){
current_brightness = brightness;
#endif
bk_printf("ws2812 init work_timeout:%d ms\n",work_timeout);
if(work_timeout > 0){
//初始化定时器
rtos_init_timer(&timer_close_handle, work_timeout, ws2812_close_timer_handle, 0);
}
}
void ws2812_deinit(){
@ -481,18 +485,31 @@ int ws2812_get_brightness(){
*
*/
void ws2812_start_timer(){
bk_printf("ws2812_reload_timer: %d ms\n",work_timeout);
//超时自动关闭
rtos_start_timer(&timer_close_handle);
}
void ws2812_reload_timer(){
bk_printf("ws2812_reload_timer: %d ms\n",work_timeout);
if(work_timeout > 0){
if(!rtos_is_timer_init(&timer_close_handle)){
rtos_init_timer(&timer_close_handle, work_timeout, ws2812_close_timer_handle, 0);
}
bk_printf("ws2812_reload_time1r: %d ms\n",work_timeout);
if(rtos_is_timer_init(&timer_close_handle) && rtos_is_timer_running(&timer_close_handle)){
//复位定时器
rtos_reload_timer(&timer_close_handle);
}
}
}
void ws2812_close_timer(){
if(rtos_is_timer_init(&timer_close_handle) || rtos_is_timer_running(&timer_close_handle)){
if(rtos_is_timer_init(&timer_close_handle) && rtos_is_timer_running(&timer_close_handle)){
rtos_stop_timer(&timer_close_handle);
}
}
@ -505,6 +522,10 @@ void ws2812_set_timeout(int timeout_m){
bk_printf("ws2812_set_timeout: %d ms\n",work_timeout);
if(work_timeout > 0){
if(!rtos_is_timer_init(&timer_close_handle)){
rtos_init_timer(&timer_close_handle, work_timeout, ws2812_close_timer_handle, 0);
}
rtos_change_period(&timer_close_handle, work_timeout);
ws2812_reload_timer();
}else{