typedef enum
{
RK_UPGRADE_START,
RK_UPGRADE_FINISHED,
RK_UPGRADE_ERR,
}RK_Upgrade_Status_t;
typedef void(*RK_upgrade_callback)(void *user_data, RK_Upgrade_Status_t status); //函数指针
void RK_ota_start(RK_upgrade_callback cb)
{
cb(NULL, RK_UPGRADE_START);
}
void handle_upgrade_callback_reboot(void *user_data, RK_Upgrade_Status_t status)
{
if(status == RK_UPGRADE_FINISHED){
update_ok = true;
reboot(RB_AUTOBOOT);
printf("\nupdate success\n");
}
}
int main(int argc, char **argv)
{
RK_ota_start(handle_upgrade_callback_reboot);
return 0;
}
博客展示了在Linux环境下,使用函数指针和钩子函数实现升级状态回调的代码示例。定义了升级状态枚举,通过函数指针类型定义回调函数,在主函数中调用启动函数并传入处理回调函数,实现升级完成后重启操作。
298

被折叠的 条评论
为什么被折叠?



