132 lines
3.6 KiB
C
132 lines
3.6 KiB
C
#include "system/includes.h"
|
||
#include "app_config.h"
|
||
#include "asm/pwm_led.h"
|
||
#include "tone_player.h"
|
||
#include "ui_manage.h"
|
||
#include "app_main.h"
|
||
#include "app_task.h"
|
||
#include "asm/charge.h"
|
||
#include "app_power_manage.h"
|
||
#include "app_charge.h"
|
||
#include "user_cfg.h"
|
||
#include "audio.h"
|
||
#include "vm.h"
|
||
#include "bleproto.h"
|
||
#include "bleproto_api.h"
|
||
#define LOG_TAG_CONST APP
|
||
#define LOG_TAG "[APP]"
|
||
#define LOG_ERROR_ENABLE
|
||
#define LOG_DEBUG_ENABLE
|
||
#define LOG_INFO_ENABLE
|
||
/* #define LOG_DUMP_ENABLE */
|
||
#define LOG_CLI_ENABLE
|
||
#include "debug.h"
|
||
extern void usr_uart_send_cmd(u8* data,u16 len);
|
||
extern void usr_ble_send_data(u8* data,u16 len);///BLE发送接口,MTU 244
|
||
extern void usr_write_pair_info();
|
||
extern void usr_clear_pair_info();
|
||
extern void usr_mcu_data_recieve(const unsigned char* hex_array, int array_length);
|
||
// 计算校验和并验证
|
||
static int verify_checksum(const unsigned char* packet_data, int length)
|
||
{
|
||
|
||
unsigned int calculated_checksum = 0;
|
||
calculated_checksum=0;
|
||
// 从帧头开始计算到倒数第二个字节的和
|
||
for (int i = 0; i < length; i++) {
|
||
calculated_checksum += packet_data[i];
|
||
}
|
||
// 对256取余
|
||
calculated_checksum %= 256;
|
||
|
||
return calculated_checksum;
|
||
}
|
||
|
||
|
||
|
||
|
||
const u8 check_mcu[7]={0x55,0xAA,0x00,0x08,0x00,0x00,0x07};
|
||
void usr_check_mcu_all_sta()///查询 mcu 工作状态,MCU上报所有DP点数值(用做APP显示)
|
||
{
|
||
usr_uart_send_cmd(check_mcu,7);
|
||
}
|
||
|
||
const u8 set_default[12]={0x55 ,0xAA ,0x00 ,0x06 ,0x00 ,0x05 ,0x18 ,0x01 ,0x00 ,0x01 ,0x01 ,0x24};
|
||
void usr_set_device_default()
|
||
{
|
||
usr_uart_send_cmd(check_mcu,12);
|
||
}
|
||
|
||
static u8 set_led_sta[12]={0x55 ,0xAA ,0x00 ,0x06 ,0x00 ,0x05 ,0x11 ,0x01 ,0x00 ,0x01 ,0xff ,0xff};
|
||
void usr_set_led_sta(u8 flag)
|
||
{
|
||
if(flag)set_led_sta[10]=0x01;
|
||
else set_led_sta[10]=0x00;
|
||
set_led_sta[11]=verify_checksum(set_led_sta,11);
|
||
usr_uart_send_cmd(set_led_sta,12);
|
||
}
|
||
|
||
|
||
/*
|
||
指示WiFI状态:
|
||
0x00:Smartconfig 配网模式 (灯快闪);
|
||
0x01:AP配网模式 (灯慢闪);
|
||
0x02:WiFi配置成功但未连上路由(灯熄灭);
|
||
0x04:已连上路由器且连接到云端 (灯长亮);
|
||
*/
|
||
static u8 send_ble_sta[8]={0x55,0xAA,0x00,0x03,0x00,0x01,0xff,0xff};
|
||
void usr_send_ble_sta(u8 flag)
|
||
{
|
||
send_ble_sta[6]=flag;
|
||
send_ble_sta[7]=verify_checksum(send_ble_sta,7);
|
||
usr_uart_send_cmd(send_ble_sta,8);
|
||
printf("usr_send_ble_sta\n");
|
||
}
|
||
//extern void usr_set_fool_val(u8 wei_cnt);
|
||
extern u8 usr_weishi_type;
|
||
extern u8 usr_weishi_fenshu;
|
||
static u8 weishi_mcu[15]={0x55,0xAA,0x00,0x06 ,0x00 ,0x08 ,0x03 ,0x02 ,0x00 ,0x04 ,0x00 ,0x00 ,0x00 ,0x02 ,0xFF};
|
||
void usr_set_werishi(int cnt,u8 weishi_type)
|
||
{
|
||
if(cnt>0)
|
||
{
|
||
//usr_set_fool_val(cnt);
|
||
usr_weishi_type=weishi_type;
|
||
usr_weishi_fenshu=cnt;
|
||
weishi_mcu[13]=cnt;
|
||
weishi_mcu[14]=verify_checksum(weishi_mcu,14);
|
||
printf("weishi cnt = %d\n",weishi_mcu[13]);
|
||
printf("checksum = %x\n",weishi_mcu[14]);
|
||
usr_uart_send_cmd(weishi_mcu,15);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
extern void usr_clear_pair_info();
|
||
const u8 reset_ble[7] = {0x55,0xAA,0x03,0x04,0x00,0x00,0x06};
|
||
const u8 ble_reset_rsp[7] = {0x55,0xAA,0x00,0x04,0x00,0x00,0x03};
|
||
const u8 ble_le_sta_rsp[7] = {0x55,0xAA,0x03,0x03,0x00,0x00,0x05};
|
||
void usr_uart_data_recieve(u8* data,u16 len)///UART数据接收
|
||
{
|
||
// log_info("uart_recieve: ");
|
||
// printf_buf(data, len);
|
||
if(!memcmp(reset_ble,data,7))
|
||
{
|
||
usr_uart_send_cmd(ble_reset_rsp,7);
|
||
usr_clear_pair_info();
|
||
return;
|
||
}
|
||
if(!memcmp(ble_le_sta_rsp,data,7))
|
||
{
|
||
return;
|
||
}
|
||
usr_mcu_data_recieve(data,len);
|
||
}
|
||
|
||
|
||
|
||
|
||
|