update_task.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #pragma once
  2. #ifdef __cplusplus
  3. extern "C" {
  4. #endif
  5. #include <update_util/update_manifest.h>
  6. #include <stdint.h>
  7. #include <stdbool.h>
  8. #include <m-string.h>
  9. #define UPDATE_DELAY_OPERATION_OK 600
  10. #define UPDATE_DELAY_OPERATION_ERROR INT_MAX
  11. typedef enum {
  12. UpdateTaskStageProgress,
  13. UpdateTaskStageReadManifest,
  14. UpdateTaskStageValidateDFUImage,
  15. UpdateTaskStageFlashWrite,
  16. UpdateTaskStageFlashValidate,
  17. UpdateTaskStageRadioWrite,
  18. UpdateTaskStageRadioCommit,
  19. UpdateTaskStageLfsBackup,
  20. UpdateTaskStageLfsRestore,
  21. UpdateTaskStageComplete,
  22. UpdateTaskStageError,
  23. } UpdateTaskStage;
  24. typedef struct {
  25. UpdateTaskStage stage;
  26. uint8_t progress;
  27. uint8_t current_stage_idx;
  28. uint8_t total_stages;
  29. string_t status;
  30. } UpdateTaskState;
  31. typedef struct UpdateTask UpdateTask;
  32. typedef void (*updateProgressCb)(
  33. const char* status,
  34. const uint8_t stage_pct,
  35. const uint8_t idx_stage,
  36. const uint8_t total_stages,
  37. bool failed,
  38. void* state);
  39. UpdateTask* update_task_alloc();
  40. void update_task_free(UpdateTask* update_task);
  41. bool update_task_init(UpdateTask* update_task);
  42. void update_task_set_progress_cb(UpdateTask* update_task, updateProgressCb cb, void* state);
  43. bool update_task_start(UpdateTask* update_task);
  44. bool update_task_is_running(UpdateTask* update_task);
  45. UpdateTaskState const* update_task_get_state(UpdateTask* update_task);
  46. UpdateManifest const* update_task_get_manifest(UpdateTask* update_task);
  47. #ifdef __cplusplus
  48. }
  49. #endif