Update magic box firmware

This commit is contained in:
2026-09-02 18:20:54 +08:00
parent b63a928b92
commit 3d1ca8bda9
22 changed files with 402 additions and 279 deletions
+25 -63
View File
@@ -1,6 +1,6 @@
/* ================================================================
* jb_product.c — 用户层实现(请填补空白处)
* 设备: 猫猫捕猎罩 | 生成时间: 2026-08-18 16:24:47
* 设备: 弹力魔盒 | 生成时间: 2026-08-18 16:24:47
*
* ══ 开发流程 ══
* 1. 实现硬件抽象: jbGetTimerCount(定时器由 SOC SDK 提供)
@@ -14,7 +14,7 @@
#include "jb_product.h"
#include "app_function.h"
#include "usr_rtc.h"
#include "app_no_disturb.h"
/* ════════════════════════════════════════════════════════════════
* 全局变量
@@ -30,70 +30,27 @@ static volatile uint32_t timerMs;
#define JB_DND_START_MIN_OFFSET 10
#define JB_DND_END_HOUR_OFFSET 11
#define JB_DND_END_MIN_OFFSET 12
static uint8_t jbLastNoDisturbActive;
/* Return weekday with Monday=0, matching DP7 bytes 2..8. */
static uint8_t jbWeekdayMonday0(const struct sys_time *time)
{
static const uint8_t monthOffset[12] = {
0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4
};
uint16_t year = time->year;
uint8_t sunday0;
if (time->month < 3) {
year--;
}
sunday0 = (uint8_t)((year + year / 4U - year / 100U + year / 400U +
monthOffset[time->month - 1U] + time->day) % 7U);
return (uint8_t)((sunday0 + 6U) % 7U);
}
static void jbNoDisturbNormalize(uint8_t *cfg)
static void jbNoDisturbApply(uint8_t *cfg)
{
uint8_t i;
uint8_t weekdays = 0;
uint16_t start_minute;
uint16_t end_minute;
cfg[JB_DND_ENABLE_OFFSET] = !!cfg[JB_DND_ENABLE_OFFSET];
for (i = 0; i < 7; i++) {
cfg[JB_DND_WEEK_OFFSET + i] = !!cfg[JB_DND_WEEK_OFFSET + i];
}
}
static uint8_t jbNoDisturbScheduleValid(const uint8_t *cfg)
{
uint8_t i;
if (cfg[JB_DND_START_HOUR_OFFSET] >= 24 ||
cfg[JB_DND_END_HOUR_OFFSET] >= 24 ||
cfg[JB_DND_START_MIN_OFFSET] >= 60 ||
cfg[JB_DND_END_MIN_OFFSET] >= 60) {
return 0;
}
for (i = 0; i < 7; i++) {
if (cfg[JB_DND_WEEK_OFFSET + i]) {
return 1;
weekdays |= (uint8_t)(1U << i);
}
}
return 0;
}
static uint8_t jbNoDisturbActive(void)
{
/* Match the verified product behavior: DP7 byte 0 is the global
* no-disturb switch. Schedule bytes are retained and reported, but do
* not gate the local vibration wake path. */
return !!gDevData.no_disturb_enable[JB_DND_ENABLE_OFFSET];
}
static void jbNoDisturbUpdate(void)
{
uint8_t active = jbNoDisturbActive();
if (active == jbLastNoDisturbActive) {
return;
}
jbLastNoDisturbActive = active;
app_function_set_no_disturb(active);
start_minute = (uint16_t)(cfg[JB_DND_START_HOUR_OFFSET] * 60U +
cfg[JB_DND_START_MIN_OFFSET]);
end_minute = (uint16_t)(cfg[JB_DND_END_HOUR_OFFSET] * 60U +
cfg[JB_DND_END_MIN_OFFSET]);
app_no_disturb_configure(cfg[JB_DND_ENABLE_OFFSET], weekdays,
start_minute, end_minute);
}
/* ════════════════════════════════════════════════════════════════
@@ -111,10 +68,10 @@ void userInit(void)
gDevData.battery = 0; /* DP5 电量上报 */
gDevData.shake_wake = 0; /* DP6 震动触发开机 0=关 1=开 */
memset(gDevData.no_disturb_enable, 0, 13); /* DP7 勿扰模式开关 */
app_no_disturb_storage_load(gDevData.no_disturb_enable);
gDevData.charge = 0; /* CHARGE_0 (不支持充电) */
gDevData.reserva_dp3 = 0; /* DP10 预留DP3 */
jbLastNoDisturbActive = 0xff;
jbNoDisturbUpdate();
jbNoDisturbApply(gDevData.no_disturb_enable);
}
/* ════════════════════════════════════════════════════════════════
@@ -123,8 +80,6 @@ void userInit(void)
* ════════════════════════════════════════════════════════════════ */
void userHandle(void)
{
jbNoDisturbUpdate();
/* ── 可上报 DP (RO / RW): 用户数据采集 ── */
// gDevData.power = read_sensor(); /* DP0 开关 */
// gDevData.play_mode = read_sensor(); /* DP1 自动模式 */
@@ -193,12 +148,19 @@ int8_t jbEventProcess(jb_event_info_t *info, jb_data_point_t *ctrl)
break;
/* ── DP7 勿扰模式开关 (raw) ── */
case DP_ID_NO_DISTURB_ENABLE:
case DP_ID_NO_DISTURB_ENABLE: {
uint8_t previous[JB_DND_LEN];
memcpy(previous, gDevData.no_disturb_enable, JB_DND_LEN);
memcpy(gDevData.no_disturb_enable, ctrl->no_disturb_enable,
JB_DND_LEN);
jbNoDisturbNormalize(gDevData.no_disturb_enable);
jbNoDisturbUpdate();
jbNoDisturbApply(gDevData.no_disturb_enable);
if (memcmp(previous, gDevData.no_disturb_enable, JB_DND_LEN) &&
!app_no_disturb_storage_save(gDevData.no_disturb_enable)) {
printf("dnd vm write failed\n");
}
break;
}
/* ── DP10 预留DP3 (uint32) ── */
case DP_ID_RESERVA_DP3:
+1 -1
View File
@@ -1,6 +1,6 @@
/* ================================================================
* jb_product.h — 用户层头文件(自动生成)
* 设备: 猫猫捕猎罩 | 生成时间: 2026-08-18 16:24:47
* 设备: 弹力魔盒 | 生成时间: 2026-08-18 16:24:47
*
* 声明用户需实现的函数。数据结构定义见 jb_protocol.h
* ================================================================
+1 -1
View File
@@ -1,6 +1,6 @@
/* ================================================================
* jb_protocol.c — 见宝 IOT 协议实现(自动生成)
* 设备: 猫猫捕猎罩 | 生成时间: 2026-08-18 16:24:47
* 设备: 弹力魔盒 | 生成时间: 2026-08-18 16:24:47
* ================================================================
*/
+1 -1
View File
@@ -1,6 +1,6 @@
/* ================================================================
* jb_protocol.h — 见宝 IOT 协议层(自动生成)
* 设备: 猫猫捕猎罩 | DP 数: 10 | Bitmap: 2B
* 设备: 弹力魔盒 | DP 数: 10 | Bitmap: 2B
* 协议版本: V1.0 | 生成时间: 2026-08-18 16:24:47
*
* 帧格式: [55 AA] [LEN_H LEN_L] [CMD] [SN] [payload...] [CKSUM]