除了显示驱动,其余全部测试通过
This commit is contained in:
@@ -0,0 +1,159 @@
|
||||
#include "system/includes.h"
|
||||
#include "app_log.h"
|
||||
|
||||
#include "radar_data_service.h"
|
||||
#include "r60abd1.h"
|
||||
#include "radar_manager.h"
|
||||
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/*
|
||||
* 已经成功同步到radar_manager的
|
||||
* R60 data_update_count。
|
||||
*
|
||||
* 不使用frame_count:
|
||||
* 未知但checksum正确的合法帧只增加frame_count,
|
||||
* 不应该触发manager业务状态更新。
|
||||
*/
|
||||
static u32 radar_data_service_last_update_count;
|
||||
|
||||
|
||||
/*
|
||||
* 把R60协议层的公开快照
|
||||
* 映射成manager通用输入结构。
|
||||
*
|
||||
* 这里不做:
|
||||
* - 合法性判断
|
||||
* - meaningful change判断
|
||||
* - freshness判断
|
||||
*
|
||||
* 这些都属于radar_manager职责。
|
||||
*/
|
||||
static void radar_data_service_build_manager_input(
|
||||
const struct radar_r60abd1_data *r60,
|
||||
struct radar_manager_input *input
|
||||
)
|
||||
{
|
||||
memset(input, 0, sizeof(*input));
|
||||
|
||||
|
||||
input->presence =
|
||||
r60->presence;
|
||||
|
||||
input->motion =
|
||||
r60->motion;
|
||||
|
||||
input->body_movement =
|
||||
r60->body_movement;
|
||||
|
||||
|
||||
input->distance_cm =
|
||||
r60->distance_cm;
|
||||
|
||||
|
||||
input->heart_rate_x10 =
|
||||
r60->heart_rate_x10;
|
||||
|
||||
input->breath_rate_x10 =
|
||||
r60->breath_rate_x10;
|
||||
|
||||
|
||||
input->sleep_state =
|
||||
r60->sleep_state;
|
||||
|
||||
|
||||
input->pos_x_mm =
|
||||
r60->pos_x_mm;
|
||||
|
||||
input->pos_y_mm =
|
||||
r60->pos_y_mm;
|
||||
|
||||
input->pos_z_mm =
|
||||
r60->pos_z_mm;
|
||||
|
||||
|
||||
/*
|
||||
* 当前稳定R60接口没有abnormal_state来源。
|
||||
* 不猜协议,保持0。
|
||||
*/
|
||||
input->abnormal_state = 0;
|
||||
|
||||
|
||||
/*
|
||||
* 使用协议层“真正业务数据更新”的时间。
|
||||
*
|
||||
* manager自身不依赖AC79 timer API。
|
||||
*/
|
||||
input->update_ms =
|
||||
r60->update_ms;
|
||||
}
|
||||
|
||||
|
||||
int radar_data_service_init(void)
|
||||
{
|
||||
radar_data_service_last_update_count = 0;
|
||||
|
||||
APP_LOG("[RADAR_DATA] init success\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int radar_data_service_process(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
struct radar_r60abd1_data r60;
|
||||
struct radar_manager_input input;
|
||||
|
||||
|
||||
ret = radar_r60abd1_get_data(&r60);
|
||||
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 没有新的“已识别业务更新”:
|
||||
* 不重复刷新manager。
|
||||
*
|
||||
* 这里直接比较计数即可。
|
||||
* 即使u32未来发生回绕,也仍能识别下一次变化。
|
||||
*/
|
||||
if (r60.data_update_count ==
|
||||
radar_data_service_last_update_count) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
radar_data_service_build_manager_input(
|
||||
&r60,
|
||||
&input
|
||||
);
|
||||
|
||||
|
||||
ret = radar_manager_update(&input);
|
||||
|
||||
if (ret != 0) {
|
||||
/*
|
||||
* manager更新失败时不要推进last_update_count,
|
||||
* 下次process还能重试同一份最新数据。
|
||||
*/
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 只有manager真正接收成功后,
|
||||
* 才认为这次R60更新已被消费。
|
||||
*/
|
||||
radar_data_service_last_update_count =
|
||||
r60.data_update_count;
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
Reference in New Issue
Block a user