helloyifa 31f179cb76 init
2025-05-15 14:19:56 +08:00

142 lines
3.4 KiB
C
Executable File

#include <components/log.h>
#include <components/system.h>
#include <os/os.h>
#include <components/shell_task.h>
#include <common/bk_include.h>
#include "gpio_map.h"
#include "gpio_driver.h"
#include <driver/gpio.h>
#include <common/bk_kernel_err.h>
//#include "bk_wifi_netif.h"
#include "bk_wifi.h"
#include <os/str.h>
#include "bk_uart.h"
#include <os/mem.h>
#include <os/os.h>
#include <common/bk_kernel_err.h>
#include <string.h>
//#include "wlan_ui_pub.h"
//#include <lwip/inet.h>
#include <driver/uart.h>
//dtim
#include "modules/pm.h"
#include "bk_ps.h"
#include "ble_client.h"
#include "system_client.h"
#include "audio_player.h"
#include "camera_client.h"
#define TAG "Sys"
static int mode = PM_MODE_DEFAULT;
static beken_queue_t system_msg_q = NULL;
static beken_timer_t timer_reboot_handle;
//static beken_thread_t system_thread_hdl = NULL;
void system_handle_thread( beken_thread_arg_t arg )
{
SystemMessage uMsg;
while(1)
{
bk_err_t ret = rtos_pop_from_queue(&system_msg_q, &uMsg, BEKEN_WAIT_FOREVER);
if(kNoErr != ret)
{
}
if(uMsg.type != mode){
switch(uMsg.type)
{
case MSG_ENTER_POWER_SAVE:
bk_wifi_send_listen_interval_req(10);
mode = PM_MODE_LOW_VOLTAGE;
//os_printf("listen_interval_req 10 \r\n");
break;
case MSG_EXIT_POWER_SAVE:
bk_wifi_send_listen_interval_req(1);
mode = PM_MODE_DEFAULT;
//os_printf("listen_interval_req 1 \r\n");
break;
case MSG_AGORA:{
//test_audio();
break;
}
case MSG_CLOSE_BLE:{
//关闭蓝牙
ble_client_boarding_deinit();
break;
}
case MSG_SEND_PHOTO:{
//camera_client_post_photo();
break;
}
default:
os_printf("unknown msg\r\n");
break;
}
}
}
}
void system_client_do(SystemMessageType msg){
SystemMessage uMsg;
uMsg.len = 0;
uMsg.msg = NULL;
uMsg.type = msg;
bk_err_t ret = rtos_push_to_queue(&system_msg_q, &uMsg, BEKEN_NEVER_TIMEOUT);
if(kNoErr != ret)
{
os_printf("rtos_push_to_queue failed\r\n");
}
}
void ota_timer_handle( void *arg )
{
BK_LOGE(TAG,"ota timerout --> REBOOT! \n");
bk_reboot();
}
void system_start_ota_timer(){
//启动OTA 超时自动重启
rtos_init_timer(&timer_reboot_handle, 60*1000*3, ota_timer_handle, 0);
rtos_start_timer(&timer_reboot_handle);
}
void system_client_start(void)
{
bk_err_t ret = BK_OK;
ret = rtos_init_queue(&system_msg_q,
"UartQueue",
sizeof(SystemMessage),
12);
ret = rtos_create_thread( NULL, BEKEN_APPLICATION_PRIORITY,
"UART1_TxRx_Handle",
system_handle_thread,
0x2048,
0 );
if (ret != kNoErr) {
warning_prf("system_client_start fail \r\n");
}
}