update_task.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. UpdateTaskStageResourcesUpdate,
  22. UpdateTaskStageCompleted,
  23. UpdateTaskStageError,
  24. } UpdateTaskStage;
  25. typedef struct {
  26. UpdateTaskStage stage;
  27. uint8_t progress;
  28. uint8_t current_stage_idx;
  29. uint8_t total_stages;
  30. string_t status;
  31. } UpdateTaskState;
  32. typedef struct UpdateTask UpdateTask;
  33. typedef void (*updateProgressCb)(
  34. const char* status,
  35. const uint8_t stage_pct,
  36. const uint8_t idx_stage,
  37. const uint8_t total_stages,
  38. bool failed,
  39. void* state);
  40. UpdateTask* update_task_alloc();
  41. void update_task_free(UpdateTask* update_task);
  42. bool update_task_init(UpdateTask* update_task);
  43. void update_task_set_progress_cb(UpdateTask* update_task, updateProgressCb cb, void* state);
  44. bool update_task_start(UpdateTask* update_task);
  45. bool update_task_is_running(UpdateTask* update_task);
  46. UpdateTaskState const* update_task_get_state(UpdateTask* update_task);
  47. UpdateManifest const* update_task_get_manifest(UpdateTask* update_task);
  48. #ifdef __cplusplus
  49. }
  50. #endif