2022-12-08 17:36:12 +08:00
|
|
|
#ifndef MONITOR_H
|
|
|
|
#define MONITOR_H
|
|
|
|
|
2022-12-12 22:29:51 +08:00
|
|
|
#include "stdint.h"
|
2023-06-23 17:05:55 +08:00
|
|
|
#include "string.h"
|
2022-12-08 17:36:12 +08:00
|
|
|
|
|
|
|
#define DAEMON_MX_CNT 64
|
|
|
|
|
|
|
|
/* 模块离线处理函数指针 */
|
|
|
|
typedef void (*offline_callback)(void *);
|
2023-07-07 19:27:24 +08:00
|
|
|
|
2022-12-08 17:36:12 +08:00
|
|
|
/* daemon结构体定义 */
|
|
|
|
typedef struct daemon_ins
|
|
|
|
{
|
2023-01-01 12:45:07 +08:00
|
|
|
uint16_t reload_count; // 重载值
|
2022-12-08 17:36:12 +08:00
|
|
|
offline_callback callback; // 异常处理函数,当模块发生异常时会被调用
|
2023-07-07 19:27:24 +08:00
|
|
|
|
2023-01-01 12:45:07 +08:00
|
|
|
uint16_t temp_count; // 当前值,减为零说明模块离线或异常
|
|
|
|
void *owner_id; // daemon实例的地址,初始化的时候填入
|
2022-12-08 17:36:12 +08:00
|
|
|
} DaemonInstance;
|
|
|
|
|
|
|
|
/* daemon初始化配置 */
|
|
|
|
typedef struct
|
|
|
|
{
|
2023-01-01 17:32:22 +08:00
|
|
|
uint16_t reload_count; // 实际上这是app唯一需要设置的值?
|
2023-06-23 15:56:20 +08:00
|
|
|
uint16_t init_count; // 上线等待时间,有些模块需要收到主控的指令才会反馈报文,或pc等需要开机时间
|
2023-01-01 17:32:22 +08:00
|
|
|
offline_callback callback; // 异常处理函数,当模块发生异常时会被调用
|
2023-07-07 19:27:24 +08:00
|
|
|
|
2023-01-01 17:32:22 +08:00
|
|
|
void *owner_id; // id取拥有daemon的实例的地址,如DJIMotorInstance*,cast成void*类型
|
2022-12-08 17:36:12 +08:00
|
|
|
} Daemon_Init_Config_s;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 注册一个daemon实例
|
2023-01-01 12:45:07 +08:00
|
|
|
*
|
2022-12-08 17:36:12 +08:00
|
|
|
* @param config 初始化配置
|
|
|
|
* @return DaemonInstance* 返回实例指针
|
|
|
|
*/
|
|
|
|
DaemonInstance *DaemonRegister(Daemon_Init_Config_s *config);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 当模块收到新的数据或进行其他动作时,调用该函数重载temp_count,相当于"喂狗"
|
2023-01-01 12:45:07 +08:00
|
|
|
*
|
2022-12-08 17:36:12 +08:00
|
|
|
* @param instance daemon实例指针
|
|
|
|
*/
|
|
|
|
void DaemonReload(DaemonInstance *instance);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 确认模块是否离线
|
2023-01-01 12:45:07 +08:00
|
|
|
*
|
2022-12-08 17:36:12 +08:00
|
|
|
* @param instance daemon实例指针
|
|
|
|
* @return uint8_t 若在线且工作正常,返回1;否则返回零. 后续根据异常类型和离线状态等进行优化.
|
|
|
|
*/
|
|
|
|
uint8_t DaemonIsOnline(DaemonInstance *instance);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 放入rtos中,会给每个daemon实例的temp_count按频率进行递减操作.
|
|
|
|
* 模块成功接受数据或成功操作则会重载temp_count的值为reload_count.
|
2023-01-01 12:45:07 +08:00
|
|
|
*
|
2022-12-08 17:36:12 +08:00
|
|
|
*/
|
|
|
|
void DaemonTask();
|
|
|
|
|
|
|
|
#endif // !MONITOR_H
|