已裁剪掉逗猫棒的业务程序,原有的蓝牙转USB功能不受影响

This commit is contained in:
2026-07-24 12:26:52 +08:00
parent b3f06697a6
commit c843fb24e0
61 changed files with 2195 additions and 7393 deletions
+59 -536
View File
@@ -1,4 +1,4 @@
#include "system/includes.h"
#include "system/includes.h"
#include "app_config.h"
#include "asm/pwm_led.h"
#include "tone_player.h"
@@ -29,7 +29,6 @@
#define FIRM_PACK_LEN 2048//128
extern u8 usr_we_plan_table[170];//[17];
static u8 start_data[10]={0x55,0xAA,0xFE,0x61,0x06,0x00,0x00,0x00,0x00,0x00};
static u8 end_data[2]={0xaa,0x55};
static int encode_len=0x00;
@@ -39,34 +38,19 @@ static u8 ota_source_data[FIRM_PACK_LEN*2]={0};
extern u16 usr_get_conn_service();
extern void usr_clear_up();
extern void ble_multi_trans_disconnect(void);
extern void usr_ble_adv_updata_OTA();
extern void usr_ble_send_data(u8* data,u16 len);///BLE发送接口,MTU 244
extern void usr_ble_send_data(u8* data,u16 len);
extern void usr_write_pair_info();
extern void usr_clear_pair_info();
extern void usr_write_plan(u8 write_num,u8*data);
extern void usr_read_plan();
extern void usr_clear_plan();
extern void usr_write_plan_to_vm();
extern void usr_set_werishi(int cnt,u8 weishi_type);
extern void usr_set_led_sta(u8 flag);
extern void app_audio_volume_set(u8 value);
extern int dual_ota_app_data_deal(u32 msg, u8 *buf, u32 len);
extern void usr_write_time_flag(u8 falg);
extern u8 usr_get_time_flag();
extern int uart_tr_send_data(u8 *data, u32 len);
extern void usr_set_data_time(int64_t timestampMs, int64_t timezoneOffset);
extern void usr_set_device_default();
extern void usr_intterupt_close();
extern int dual_ota_app_data_deal(u32 msg, u8 *buf, u32 len);
extern int uart_tr_send_data(u8 *data, u32 len);
void usr_ota_deal_task();
void usr_le_notify_data();
void usr_data_ana(bleproto_appdata_desc_t *desc);
void usr_do_action_code(int flag);
void usr_run_cmd_code(bleproto_runcmd_req_t* runcmd_par,u8 usr_msg_id);
void usr_app_ota_init();
void usr_data_notify_auto();
void usr_test_protocol(void);
bleproto_authsetup_req_t usr_auth_data;
@@ -75,59 +59,32 @@ usr_module_cfg_cache _usr_module_cfg_cache;
void usr_read_device_sta()
{
int ret = 0xff;
ret=syscfg_read(CFG_USER_DEVICE_STA, (u8 *)&_usr_module_cfg, sizeof(_usr_module_cfg));
if(ret<=0)
{
_usr_module_cfg.local_moto_mode=1;
_usr_module_cfg.usr_dizhuo_mode=0;
_usr_module_cfg.usr_douban_mode=0;
_usr_module_cfg.power_on_flag =1;
_usr_module_cfg.zhengdong_kaiji=0;
_usr_module_cfg.wuraomoshi_onoff=0;
int ret = syscfg_read(CFG_USER_DEVICE_STA, (u8 *)&_usr_module_cfg, sizeof(_usr_module_cfg));
if (ret <= 0) {
memset(&_usr_module_cfg, 0, sizeof(_usr_module_cfg));
_usr_module_cfg.power_on_flag = 1;
syscfg_write(CFG_USER_DEVICE_STA, (u8 *)&_usr_module_cfg, sizeof(_usr_module_cfg));
}
_usr_module_cfg.usr_dizhuo_mode=0;
_usr_module_cfg.usr_douban_mode=0;
// _usr_module_cfg.local_moto_mode=1;
_usr_module_cfg.power_on_flag =1;
//memcpy(&_usr_module_cfg_cache,&_usr_module_cfg,sizeof(_usr_module_cfg));
_usr_module_cfg_cache.local_moto_mode=0xff;
_usr_module_cfg_cache.usr_dizhuo_mode=0xff;
_usr_module_cfg_cache.usr_douban_mode=0xff;
_usr_module_cfg_cache.power_on_flag =0x01;
_usr_module_cfg.power_on_flag = 1;
memset(&_usr_module_cfg_cache, 0xff, sizeof(_usr_module_cfg_cache));
_usr_module_cfg_cache.power_on_flag = 0x01;
}
void usr_reset_device_sta()
{
int ret = 0xff;
_usr_module_cfg.local_moto_mode=1;
_usr_module_cfg.usr_dizhuo_mode=0;
_usr_module_cfg.usr_douban_mode=0;
_usr_module_cfg.power_on_flag =1;
_usr_module_cfg.zhengdong_kaiji=0;
_usr_module_cfg.wuraomoshi_onoff=0;
ret = syscfg_write(CFG_USER_DEVICE_STA, (u8 *)&_usr_module_cfg, sizeof(_usr_module_cfg));
printf("############# ret = %d _usr_module_cfg.zhengdong_kaiji = %d\n",ret,_usr_module_cfg.zhengdong_kaiji);
memset(&_usr_module_cfg, 0, sizeof(_usr_module_cfg));
_usr_module_cfg.power_on_flag = 1;
syscfg_write(CFG_USER_DEVICE_STA, (u8 *)&_usr_module_cfg, sizeof(_usr_module_cfg));
}
void usr_write_device_sta_vm()
{
int ret = 0xff;
ret=syscfg_write(CFG_USER_DEVICE_STA, (u8 *)&_usr_module_cfg, sizeof(_usr_module_cfg));
usr_le_notify_data();
memcpy(&_usr_module_cfg_cache,&_usr_module_cfg,sizeof(_usr_module_cfg));
//printf("usr_write_device_sta_vm\n");
syscfg_write(CFG_USER_DEVICE_STA, (u8 *)&_usr_module_cfg, sizeof(_usr_module_cfg));
memcpy(&_usr_module_cfg_cache, &_usr_module_cfg, sizeof(_usr_module_cfg));
}
void usr_write_device_sta()
{
// io_ext_interrupt_close(0, IO_PORTA_01);
usr_write_device_sta_vm();
}
@@ -140,41 +97,32 @@ void usr_le_data_recieve(u8* data,u16 len)///BLE数据接收
int rc_result=0;
if(_usr_module_cfg.local_moto_mode==3)_usr_module_cfg.local_moto_mode=0;
memcpy(&rxbuf[usr_len],data,len);
usr_len+=len;
rc_result = bleproto_appdata_decode(rxbuf, usr_len, &desc);
// printf("rc_result_le## = %d\n",rc_result);
if(rc_result < 0)
{
// 接收到了非法的数据包,无法解析
usr_len=0;
}
else if(rc_result == 0)
{
// 接收的数据不完整,继续接收数据
/* incomplete frame */
}
else //(rc_result > 0)
else
{
// 数据解析成功
usr_len=0;
usr_data_ana(&desc);
}
//usr_ble_send_data(data,len);
}
#if 1
void usr_send_ble_sta(u8 flag)
{
(void)flag;
}
void usr_set_device_default()
{
}
void usr_data_ana(bleproto_appdata_desc_t *desc)
@@ -192,8 +140,9 @@ void usr_data_ana(bleproto_appdata_desc_t *desc)
encode_desc.header.encrypt = 0;
encode_desc.header.serviceid = E_BLEPROTO_SERVICE_ID_DEVICEINFO;
usr_set_data_time(desc->datast.deviceinfo_req.t,desc->datast.deviceinfo_req.gmtoff);
/* deviceinfo 时间字段忽略:桥接板无 RTC/计划业务 */
(void)desc->datast.deviceinfo_req.t;
(void)desc->datast.deviceinfo_req.gmtoff;
//deviceinfo rsp序列化
bleproto_deviceinfo_rsp_t *rsp = &encode_desc.datast.deviceinfo_rsp;
{
@@ -287,43 +236,29 @@ void usr_data_ana(bleproto_appdata_desc_t *desc)
printf("2encode_len = %d\n",encode_len);
}
break;
case E_BLEPROTO_SERVICE_ID_RUNCMD:
// 设备处理,回复响应
printf("E_BLEPROTO_SERVICE_ID_RUNCMD\n");
usr_run_cmd_code(&desc->datast.runcmd_req,desc->header.msgid);
break;
case E_BLEPROTO_SERVICE_ID_DOACTION:
printf("E_BLEPROTO_SERVICE_ID_DOACTION\n");
encode_desc.header.version = 0;
encode_desc.header.datafmt = BLEPROTO_APPDATA_DATAFMT_JSON;
encode_desc.header.msgtype = BLEPROTO_APPDATA_MSGTYPE_RSP;
encode_desc.header.msgid = desc->header.msgid;//这里的msg_id为上面解析到的包的msg_id;
encode_desc.header.msgid = desc->header.msgid;
encode_desc.header.encrypt = 0;
encode_desc.header.serviceid = E_BLEPROTO_SERVICE_ID_DOACTION;
encode_desc.datast.doaction_rsp.errcode = 0;
bleproto_doaction_rsp_t *action_rsp = &encode_desc.datast.doaction_rsp;
encode_desc.datast.doaction_rsp.errcode = 0;
{
action_rsp->errcode=0;
// 执行命令
printf("action_run %d \n",desc->datast.doaction_req.action);
bleproto_doaction_rsp_t *action_rsp = &encode_desc.datast.doaction_rsp;
action_rsp->errcode = 0;
printf("action_run %d \n", desc->datast.doaction_req.action);
}
encode_len = bleproto_appdata_encode(txbuf, sizeof(txbuf), sizeof(txbuf), &encode_desc);
if(encode_len > 0) {
printf("encode_len = %d\n",encode_len);
usr_ble_send_data(txbuf,encode_len);
if (encode_len > 0) {
usr_ble_send_data(txbuf, encode_len);
usr_do_action_code(desc->datast.doaction_req.action);
}
else
{
printf("2encode_len = %d\n",encode_len);
}
break;
case E_BLEPROTO_SERVICE_ID_OTANOTIFY:
printf("E_BLEPROTO_SERVICE_ID_OTANOTIFY\n");
_usr_module_cfg.local_moto_mode=3;
encode_desc.header.version = 0;
encode_desc.header.datafmt = BLEPROTO_APPDATA_DATAFMT_JSON;
encode_desc.header.msgtype = BLEPROTO_APPDATA_MSGTYPE_RSP;
@@ -558,234 +493,42 @@ void usr_ota_deal_task()
#endif // 0
void usr_run_cmd_code(bleproto_runcmd_req_t* runcmd_par,u8 usr_msg_id)
{
printf("runcmd_par id = %d\n",runcmd_par->ycmd.cmd_id);
bleproto_appdata_desc_t encode_desc = { 0 };
encode_desc.header.version = 0;
encode_desc.header.datafmt = BLEPROTO_APPDATA_DATAFMT_JSON;
encode_desc.header.msgtype = BLEPROTO_APPDATA_MSGTYPE_RSP;
encode_desc.header.msgid = usr_msg_id;
encode_desc.header.encrypt = 0;
encode_desc.header.serviceid = E_BLEPROTO_SERVICE_ID_RUNCMD;
bleproto_runcmd_rsp_t *rsp = &encode_desc.datast.runcmd_rsp;
switch(runcmd_par->ycmd.cmd_id)
{
case 202:
printf("runcmd_par->ycmd.arg_int32 0 = %d\n",runcmd_par->ycmd.arg_int32[0]);
rsp->ycmd.cmd_id = 110;
rsp->ycmd.arg_int32_count = 2;
rsp->ycmd.arg_string_count = 0;
rsp->ycmd.arg_bytes_count = 0;
/*
| 索引 | 类型 | 描述 | 取值 |
| ---- | ----- | ---------- | ---------------- |
| 0 | int32 | 开关机控制 | 0:关机;1:开机 |
*/
if(runcmd_par->ycmd.arg_int32[0]==0)//关机
{
_usr_module_cfg.power_on_flag=0;
usr_var.usr_intterupt_reinit_falg=1;
usr_intterupt_close();
}
else //开机
{
_usr_module_cfg.power_on_flag=1;
}
usr_clear_up();
rsp->ycmd.arg_int32[0] = 202;
rsp->ycmd.arg_int32[1] = 0;
rsp->ycmd.t = usr_var.usr_cureent_utc;
usr_var.usr_allow_to_sleep_cnt=8;
usr_write_device_sta();
break;
case 203:
/*
| 索引 | 类型 | 描述 | 取值 |
| ---- | ----- | ------------------ | ----------------------------------------------------------------- |
| 0 | int32 | 运动模式 | 0:关闭内置模式;1-鸡血,2-佛系 |
| 1 | int32 | 底座转动模式 | 0:关闭;1:平稳;2:狂转 |
| 2 | int32 | 逗猫棒摇动模式 | 0:关闭;1:自动; 2:转圈; 3:抖动; |
| 3 | int32 | 逗猫棒手动参数 | 逗猫棒摇动模式为0时有效, 0:无效;1:手动正转一圈 ;2:手动正转一圈 |
*/
usr_var.usr_allow_to_sleep_cnt=8;
_usr_module_cfg.local_moto_mode=runcmd_par->ycmd.arg_int32[0];
_usr_module_cfg.usr_dizhuo_mode=runcmd_par->ycmd.arg_int32[1];
_usr_module_cfg.usr_douban_mode=runcmd_par->ycmd.arg_int32[2];
_usr_module_cfg.usr_doumaoshoudong=runcmd_par->ycmd.arg_int32[3];
rsp->ycmd.cmd_id = 110;
rsp->ycmd.arg_int32_count = 2;
rsp->ycmd.arg_string_count = 0;
rsp->ycmd.arg_bytes_count = 0;
rsp->ycmd.arg_int32[0] = 203;
rsp->ycmd.arg_int32[1] = 0;
rsp->ycmd.t = usr_var.usr_cureent_utc;
usr_clear_up();
usr_write_device_sta();
break;
case 206:///震动开机参数配置
/*
| 索引 | 类型 | 描述 | 取值 |
| ---- | ------ | ------------------------------------------------------------ | ----------------------------- |
| 0 | int32 | 震动开机开关 | -1:忽略, 0:关闭;1:开启 |
| 1 | int32 | 勿扰模式开关 | -1:忽略, 0:关闭;1:开启 |
| 0 | string | 周计划 + 开始时间点 + 结束时间点<br />周计划:dddddd,
从左到右表示7个,分别表示周一到周日,1表示有效,0表示无效 <br />
时间点:hhmm, hh表示小时,mm表示分钟<br />
例如<br />0
0000001+1828+1930 表示每周日重复+18:28开始+19:30结束<br />
1000001+0928+1930 表示每周一和周日重复+09:28开始+19:30结束<br />
1100000+1328+1930 表示每周一和周二重复+13:28开始+19:30结束<br / | 字符串<br />ddddddd+hhmm+hhmm |
*/
_usr_module_cfg.zhengdong_kaiji=runcmd_par->ycmd.arg_int32[0];
_usr_module_cfg.wuraomoshi_onoff=runcmd_par->ycmd.arg_int32[1];
printf("zhengdong_kaiji = %d wuraomoshi_onoff = %d\n",_usr_module_cfg.zhengdong_kaiji,_usr_module_cfg.wuraomoshi_onoff);
printf("arg_string_count = %d\n",runcmd_par->ycmd.arg_string_count);
//printf("string = %s\n",&rsp->ycmd.arg_string[0][0],17);
if(runcmd_par->ycmd.arg_string_count)
{
usr_clear_plan();
for(u8 i=0;i<runcmd_par->ycmd.arg_string_count;i++)
{
usr_write_plan(i,&runcmd_par->ycmd.arg_string[i][0]);
}
usr_write_plan_to_vm();
usr_read_plan();
}
usr_write_device_sta();
rsp->ycmd.cmd_id = 110;
rsp->ycmd.arg_int32_count = 2;
rsp->ycmd.arg_bytes_count = 0;
rsp->ycmd.arg_int32[0] = 206;
rsp->ycmd.arg_int32[1] = 0;
rsp->ycmd.t = usr_var.usr_cureent_utc;
break;
case 207:///周计划查询
rsp->ycmd.cmd_id = 110;
rsp->ycmd.arg_int32_count = 4;
rsp->ycmd.arg_bytes_count = 0;
rsp->ycmd.arg_string_count = usr_var.usr_plan_cnt;
rsp->ycmd.arg_int32[0] = 207;
rsp->ycmd.arg_int32[1] = 0;
rsp->ycmd.arg_int32[2] = _usr_module_cfg.zhengdong_kaiji;
rsp->ycmd.arg_int32[3] = _usr_module_cfg.wuraomoshi_onoff;
rsp->ycmd.t = usr_var.usr_cureent_utc;
for(u8 i=0;i<usr_var.usr_plan_cnt;i++)
{
memcpy(&rsp->ycmd.arg_string[i][0],&usr_we_plan_table[i*17],17);
}
break;
case 600:
/*
| 索引 | 类型 | 描述 | 取值 |
| ---- | ----- | ---------------- | ------------------------------------------------- |
| 0 | int32 | cmdid | 600 |
| 1 | int32 | 返回值 | 0: 设备接受命令成功; 非零: 参见具体的命令错误代码 |
| 2 | int32 | 当前电量 | [1, 100]:百分比;0:不使用电池供电 |
| 3 | int32 | 当前电量是否正常 | 0:正常;1:电量过低 |
| 4 | int32 | 充电状态 | 0: 不支持充电; 1:充电 2:未充电 |
| 5 | int32 | 开机状态 | 0:关闭;1:开启 |
| 6 | int32 | 运动模式 | 0:关闭;1:鸡血;2:佛系 |
| 7 | int32 | 底座转动模式 | 0:关闭;1:平稳;2:狂转 |
| 8 | int32 | 逗猫棒摇动模式 | 0:手动;1:自动;2:转圈;3:抖动 |
*/
rsp->ycmd.cmd_id = 110;
rsp->ycmd.arg_int32_count = 9;
rsp->ycmd.arg_string_count = 0;
rsp->ycmd.arg_bytes_count = 0;
rsp->ycmd.arg_int32[0] = 600;
rsp->ycmd.arg_int32[1] = 0; //0:命令接收成功
rsp->ycmd.arg_int32[2] = usr_var.usr_bat_level; // 电量上报
if(usr_var.usr_bat_level<30)rsp->ycmd.arg_int32[3] = 1;
else rsp->ycmd.arg_int32[3] = 0; // 当前电量是否正常
rsp->ycmd.arg_int32[4] = usr_var.usr_power_charge_flag; // 充电状态
rsp->ycmd.arg_int32[5] = _usr_module_cfg.power_on_flag; // 开机状态
rsp->ycmd.arg_int32[6] = _usr_module_cfg.local_moto_mode; // 运动模式
rsp->ycmd.arg_int32[7] = _usr_module_cfg.usr_dizhuo_mode; // 底座运动模式
rsp->ycmd.arg_int32[8] = _usr_module_cfg.usr_douban_mode; // 逗猫棒摇动模式
rsp->ycmd.t = usr_var.usr_cureent_utc; // UTC时间戳;
memcpy(&_usr_module_cfg_cache,&_usr_module_cfg,sizeof(_usr_module_cfg));
break;
default:
break;
}
int encode_len = bleproto_appdata_encode(
/* txbuf */ txbuf,
/* size */ sizeof(txbuf),
/* packetlen */ sizeof(txbuf),
/* desc */ &encode_desc);
printf("encode_len = %d\n",encode_len);
if(encode_len > 0)
{
usr_ble_send_data(txbuf,encode_len);
}
else
{
}
}
void usr_ota_process()
{
static u8 cnt=0;
if(cnt==0)
{
static u8 cnt = 0;
if (cnt == 0) {
ble_multi_trans_disconnect();
}
if(usr_get_conn_service()==0)
{
if (usr_get_conn_service() == 0) {
cnt++;
if(cnt==2)
{
if (cnt == 2) {
usr_ble_adv_updata_OTA();
}
if(cnt>=60)
{
cnt=0;
if (cnt >= 60) {
cnt = 0;
cpu_reset();
}
} else {
cnt = 1;
}
else
{
cnt=1;
}
}
void usr_do_action_code(int flag)
{
switch(flag)
{
case 0:///重启
switch (flag) {
case 0: /* reboot */
cpu_reset();
break;
case 1:///指示-identify;收到命令设备led闪烁或者喇叭发音,指示设备存在
// app_task_put_key_msg(KEY_IR_NUM_1, 0);
break;
case 2:///回复出厂设置-reset;蓝牙连接信息也需要清除
case 2: /* factory reset, clear pair */
usr_set_device_default();
usr_clear_pair_info();
break;
case 3:///清空配置-clear,保留蓝牙连接信息
case 3: /* clear cfg, keep pair */
usr_set_device_default();
break;
case 100:
_usr_module_cfg.local_moto_mode=3;
case 100: /* enter OTA */
usr_app_ota_init();
break;
default:
@@ -795,256 +538,36 @@ void usr_do_action_code(int flag)
void usr_app_ota_init()
{
usr_var.usr_goto_updata=1;
if(usr_var.ota_timer==0)
{
usr_var.ota_timer=sys_timer_add(NULL,usr_ota_process,1000);
usr_var.usr_goto_updata = 1;
if (usr_var.ota_timer == 0) {
usr_var.ota_timer = sys_timer_add(NULL, usr_ota_process, 1000);
}
}
void usr_le_notify_data()
{
//设备状态变化可向主控设备上报数据
if(usr_get_conn_service()==0)return;
printf("usr_le_notify_data cmdid1 = 100\n");
// 测试数据
bleproto_appdata_desc_t encode_desc = { 0 };
encode_desc.header.version = 0;
encode_desc.header.datafmt = BLEPROTO_APPDATA_DATAFMT_JSON;
encode_desc.header.msgtype = BLEPROTO_APPDATA_MSGTYPE_REQ;
encode_desc.header.msgid = 1;
encode_desc.header.encrypt = 0;
encode_desc.header.serviceid = E_BLEPROTO_SERVICE_ID_REPORTCMD;
// 每次上报都需要填写以下所有内容
bleproto_reportcmd_req_t *req = &encode_desc.datast.reportcmd_req;
{
/*
| 索引 | 类型 | 描述 | 取值 |
| ---- | ----- | ---------------- | ----------------------------------------------------- |
| 0 | int32 | 当前电量 | [1, 100]:百分比;0:不使用电池供电,无变化填写888888 |
| 1 | int32 | 当前电量是否正常 | 0:正常;1:电量过低,无变化填写888888 |
| 2 | int32 | 充电状态 | 0: 不支持充电; 1:充电 2:未充电,无变化填写888888 |
| 3 | int32 | 开机状态 | 0:关闭;1:开启,无变化填写888888 |
| 4 | int32 | 运动模式 | 0:关闭;1:鸡血;2:佛系,无变化填写888888 |
| 5 | int32 | 底座转动模式 | 0:关闭;1:平稳;2:狂转,无变化填写888888 |
| 6 | int32 | 逗猫棒摇动模式 | 0:关闭;1:自动;2:转圈;3:抖动,无变化填写888888 |
| 7 | int32 | UTC时间戳 | 单位秒 |
*/
req->ycmd.cmd_id = 100;
req->ycmd.arg_int32[0] = usr_var.usr_bat_level;// 电量上报
if(usr_var.usr_bat_level<30)req->ycmd.arg_int32[1] = 1;
else req->ycmd.arg_int32[1] = 0; // 当前电量是否正常
req->ycmd.arg_int32[2] = usr_var.usr_power_charge_flag;// 充电状态
req->ycmd.arg_int32[3] = _usr_module_cfg.power_on_flag;// 开机状态
req->ycmd.arg_int32[4] = _usr_module_cfg.local_moto_mode;
req->ycmd.arg_int32[5] = _usr_module_cfg.usr_dizhuo_mode;// 底座运动模式
req->ycmd.arg_int32[6] = _usr_module_cfg.usr_douban_mode;// 逗猫棒运动模式
req->ycmd.arg_int32[7] = usr_var.usr_cureent_utc;// UTC时间戳
if(_usr_module_cfg_cache.power_on_flag==_usr_module_cfg.power_on_flag)
{
req->ycmd.arg_int32[3] = 888888; // 运动模式
}
if(_usr_module_cfg_cache.local_moto_mode==_usr_module_cfg.local_moto_mode)
{
req->ycmd.arg_int32[4] = 888888; // 运动模式
}
if(_usr_module_cfg_cache.usr_dizhuo_mode==_usr_module_cfg.usr_dizhuo_mode)
{
req->ycmd.arg_int32[5] = 888888; // 底座运动模式
}
if(_usr_module_cfg_cache.usr_douban_mode==_usr_module_cfg.usr_douban_mode)
{
req->ycmd.arg_int32[6] = 888888; // 逗猫棒运动模式
}
req->ycmd.arg_int32_count = 8;
req->ycmd.t = usr_var.usr_cureent_utc;
memcpy(&_usr_module_cfg_cache,&_usr_module_cfg,sizeof(_usr_module_cfg));
}
int encode_len = bleproto_appdata_encode(
/* txbuf */ txbuf,
/* size */ sizeof(txbuf),
/* packetlen */ sizeof(txbuf),
/* desc */ &encode_desc);
printf("encode_len = %d\n",encode_len);
if(encode_len > 0)
{
usr_ble_send_data(txbuf,encode_len);
}
else
{
}
}
void usr_le_120_notify_data()
{
//设备状态变化可向主控设备上报数据
if(usr_get_conn_service()==0)return;
printf("usr_le_notify_data cmdid1 = 120\n");
// 测试数据
bleproto_appdata_desc_t encode_desc = { 0 };
encode_desc.header.version = 0;
encode_desc.header.datafmt = BLEPROTO_APPDATA_DATAFMT_JSON;
encode_desc.header.msgtype = BLEPROTO_APPDATA_MSGTYPE_REQ;
encode_desc.header.msgid = 1;
encode_desc.header.encrypt = 0;
encode_desc.header.serviceid = E_BLEPROTO_SERVICE_ID_REPORTCMD;
// 每次上报都需要填写以下所有内容
bleproto_reportcmd_req_t *req = &encode_desc.datast.reportcmd_req;
{
/*
> 告警上报 (*设备主动上报*)
* 命令ID 120
* 参数说明
| 索引 | 类型 | 描述 | 取值 |
| ---- | ----- | ---------- | ----------------------------------------------------- |
| 0 | int32 | 告警事件id | 5000:硬件故障;5001:低电量报警; 5010:震动开机报警 |
| 1 | int32 | UTC时间戳 | 事件触发UTCS时间戳单位秒 |
*/
req->ycmd.cmd_id = 120;
req->ycmd.arg_int32[0] = 5010;//
req->ycmd.arg_int32[1] = usr_var.usr_cureent_utc;// UTC时间戳
req->ycmd.arg_int32_count = 2;
req->ycmd.t = usr_var.usr_cureent_utc;
}
int encode_len = bleproto_appdata_encode(
/* txbuf */ txbuf,
/* size */ sizeof(txbuf),
/* packetlen */ sizeof(txbuf),
/* desc */ &encode_desc);
printf("encode_len = %d\n",encode_len);
if(encode_len > 0)
{
usr_ble_send_data(txbuf,encode_len);
}
else
{
}
}
void usr_le_low_power_notify()
{
//设备状态变化可向主控设备上报数据
if(usr_get_conn_service()==0)return;
printf("usr_le_notify_data cmdid2 = 120\n");
// 测试数据
bleproto_appdata_desc_t encode_desc = { 0 };
encode_desc.header.version = 0;
encode_desc.header.datafmt = BLEPROTO_APPDATA_DATAFMT_JSON;
encode_desc.header.msgtype = BLEPROTO_APPDATA_MSGTYPE_REQ;
encode_desc.header.msgid = 1;
encode_desc.header.encrypt = 0;
encode_desc.header.serviceid = E_BLEPROTO_SERVICE_ID_REPORTCMD;
// 每次上报都需要填写以下所有内容
bleproto_reportcmd_req_t *req = &encode_desc.datast.reportcmd_req;
{
/*
> 告警上报 (*设备主动上报*)
* 命令ID 120
* 参数说明
| 索引 | 类型 | 描述 | 取值 |
| ---- | ----- | ---------- | ----------------------------------------------------- |
| 0 | int32 | 告警事件id | 5000:硬件故障;5001:低电量报警; 5010:震动开机报警 |
| 1 | int32 | UTC时间戳 | 事件触发UTCS时间戳单位秒 |
*/
req->ycmd.cmd_id = 120;
req->ycmd.arg_int32[0] = 5001;// 电量上报
req->ycmd.arg_int32[1] = usr_var.usr_cureent_utc;// UTC时间戳
req->ycmd.arg_int32_count = 2;
req->ycmd.t = usr_var.usr_cureent_utc;
}
int encode_len = bleproto_appdata_encode(
/* txbuf */ txbuf,
/* size */ sizeof(txbuf),
/* packetlen */ sizeof(txbuf),
/* desc */ &encode_desc);
printf("encode_len = %d\n",encode_len);
if(encode_len > 0)
{
usr_ble_send_data(txbuf,encode_len);
}
else
{
}
}
u8 usr_weishi_type=0;
u8 usr_weishi_index=0;
u8 usr_weishi_fenshu=1;
void usr_weishi_notify()
{
}
void usr_data_notify_auto()
{
// sys_timeout_add(NULL,usr_le_notify_data,500);
// usr_le_notify_data();
}
void usr_test_protocol(void)
{
bleproto_appdata_desc_t encode_desc = { 0 };
encode_desc.header.version = 0;
encode_desc.header.datafmt = BLEPROTO_APPDATA_DATAFMT_JSON;
encode_desc.header.msgtype = BLEPROTO_APPDATA_MSGTYPE_REQ;
encode_desc.header.msgid = 1;
encode_desc.header.encrypt = 0;
encode_desc.header.serviceid = E_BLEPROTO_SERVICE_ID_REPORTCMD_V2;
bleproto_appdata_desc_t encode_desc = {0};
encode_desc.header.version = 0;
encode_desc.header.datafmt = BLEPROTO_APPDATA_DATAFMT_JSON;
encode_desc.header.msgtype = BLEPROTO_APPDATA_MSGTYPE_REQ;
encode_desc.header.msgid = 1;
encode_desc.header.encrypt = 0;
encode_desc.header.serviceid = E_BLEPROTO_SERVICE_ID_REPORTCMD_V2;
ble_proto_packet_t *pkt = &encode_desc.datast.runcmd_v2_req;
uint8_t test_data[9] = {0x55,0xAA,0x00,0x05,0x07,0x00,0x01,0x01,0x0E};
uint8_t test_data[9] = {0x55, 0xAA, 0x00, 0x05, 0x07, 0x00, 0x01, 0x01, 0x0E};
pkt->cmd = 100;
pkt->reserved = 0;
pkt->gateway_int_cnt = 0;
pkt->device_int_len = 0;
pkt->device_str_len = 0;
pkt->device_bytes_len = 9;
pkt->bytes_data = (uint8_t*)test_data;
pkt->bytes_data = (uint8_t *)test_data;
int encode_len = bleproto_appdata_encode(
/* txbuf */ txbuf,
/* size */ sizeof(txbuf),
/* packetlen */ sizeof(txbuf),
/* desc */ &encode_desc);
printf("encode_len = %d\n",encode_len);
if(encode_len > 0)
{
usr_ble_send_data(txbuf,encode_len);
printf("txbuf = ");
printf_buf(txbuf, encode_len);
int elen = bleproto_appdata_encode(txbuf, sizeof(txbuf), sizeof(txbuf), &encode_desc);
printf("encode_len = %d\n", elen);
if (elen > 0) {
usr_ble_send_data(txbuf, elen);
printf_buf(txbuf, elen);
}
}