mirror of
https://gitee.com/dlmu-cone/bf_original_balance_chassis
synced 2026-07-24 03:27:45 +08:00
将警报声添加到DaemonTask
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include "bsp_dwt.h" // 后续通过定时器来计时?
|
||||
#include "stdlib.h"
|
||||
#include "memory.h"
|
||||
#include "buzzer.h"
|
||||
|
||||
// 用于保存所有的daemon instance
|
||||
static DaemonInstance *daemon_instances[DAEMON_MX_CNT] = {NULL};
|
||||
@@ -15,7 +16,9 @@ DaemonInstance *DaemonRegister(Daemon_Init_Config_s *config)
|
||||
instance->owner_id = config->owner_id;
|
||||
instance->reload_count = config->reload_count == 0 ? 100 : config->reload_count;
|
||||
instance->callback = config->callback;
|
||||
|
||||
instance->alarm_state = config->alarm_state;
|
||||
instance->alarm_level = config->alarm_level;
|
||||
instance->temp_count = config->reload_count;
|
||||
daemon_instances[idx++] = instance;
|
||||
return instance;
|
||||
}
|
||||
@@ -36,6 +39,7 @@ void DaemonTask()
|
||||
DaemonInstance *dins; // 提高可读性同时降低访存开销
|
||||
for (size_t i = 0; i < idx; ++i)
|
||||
{
|
||||
|
||||
dins = daemon_instances[i];
|
||||
if (dins->temp_count > 0) // 如果计数器还有值,说明上一次喂狗后还没有超时,则计数器减一
|
||||
dins->temp_count--;
|
||||
@@ -43,6 +47,11 @@ void DaemonTask()
|
||||
{
|
||||
dins->callback(dins->owner_id); // module内可以将owner_id强制类型转换成自身类型从而调用特定module的offline callback
|
||||
// @todo 为蜂鸣器/led等增加离线报警的功能,非常关键!
|
||||
if(dins->alarm_state == ALARM_ON)
|
||||
{
|
||||
BuzzerPlay(dins->alarm_level);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,18 +2,34 @@
|
||||
#define MONITOR_H
|
||||
|
||||
#include "stdint.h"
|
||||
#include "string.h"
|
||||
|
||||
#define DAEMON_MX_CNT 64
|
||||
|
||||
/* 模块离线处理函数指针 */
|
||||
typedef void (*offline_callback)(void *);
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ALARM_OFF = 0,
|
||||
ALARM_ON = 1,
|
||||
}alarm_state_e;
|
||||
typedef enum
|
||||
{
|
||||
ALARM_LEVEL_LOW = 0,
|
||||
ALARM_LEVEL_BELOW_MEDIUM = 1,
|
||||
ALARM_LEVEL_MEDIUM = 2,
|
||||
ALARM_LEVEL_ABOVE_MEDIUM = 3,
|
||||
ALARM_LEVEL_HIGH = 4,
|
||||
ALARM_OFFLINE = 5,
|
||||
}alarm_level_e;
|
||||
/* daemon结构体定义 */
|
||||
typedef struct daemon_ins
|
||||
{
|
||||
uint16_t reload_count; // 重载值
|
||||
offline_callback callback; // 异常处理函数,当模块发生异常时会被调用
|
||||
|
||||
alarm_state_e alarm_state; // 蜂鸣器状态
|
||||
alarm_level_e alarm_level; //警报级别
|
||||
|
||||
uint16_t temp_count; // 当前值,减为零说明模块离线或异常
|
||||
void *owner_id; // daemon实例的地址,初始化的时候填入
|
||||
} DaemonInstance;
|
||||
@@ -23,6 +39,9 @@ typedef struct
|
||||
{
|
||||
uint16_t reload_count; // 实际上这是app唯一需要设置的值?
|
||||
offline_callback callback; // 异常处理函数,当模块发生异常时会被调用
|
||||
alarm_state_e alarm_state; // 蜂鸣器状态
|
||||
alarm_level_e alarm_level; //警报级别
|
||||
|
||||
void *owner_id; // id取拥有daemon的实例的地址,如DJIMotorInstance*,cast成void*类型
|
||||
} Daemon_Init_Config_s;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user