ota_internal.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (C) 2012-2019 UCloud. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License").
  5. * You may not use this file except in compliance with the License.
  6. * A copy of the License is located at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * or in the "license" file accompanying this file. This file is distributed
  11. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  12. * express or implied. See the License for the specific language governing
  13. * permissions and limitations under the License.
  14. */
  15. #ifndef C_SDK_OTA_INTERNAL_H_
  16. #define C_SDK_OTA_INTERNAL_H_
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. #include <stdint.h>
  21. #include "uiot_export_ota.h"
  22. typedef enum {
  23. OTA_REPORT_UNDEFINED_ERROR = -6,
  24. OTA_REPORT_FIRMWARE_BURN_FAILED = -5,
  25. OTA_REPORT_MD5_MISMATCH = -4,
  26. OTA_REPORT_DOWNLOAD_TIMEOUT = -3,
  27. OTA_REPORT_SIGNATURE_EXPIRED = -2,
  28. OTA_REPORT_FIRMWARE_NOT_EXIST = -1,
  29. OTA_REPORT_NONE = 0,
  30. OTA_REPORT_DOWNLOADING = 1,
  31. OTA_REPORT_BURNING = 2,
  32. OTA_REPORT_SUCCESS = 3,
  33. OTA_REQUEST_FIRMWARE = 4,
  34. OTA_REPORT_VERSION = 5,
  35. } IOT_OTA_UpstreamMsgType;
  36. /* OTA状态 */
  37. typedef enum {
  38. OTA_STATE_UNINITED = 0, /* 未初始化 */
  39. OTA_STATE_INITED, /* 初始化完成 */
  40. OTA_STATE_FETCHING, /* 正在下载固件 */
  41. OTA_STATE_FETCHED, /* 固件下载完成 */
  42. OTA_STATE_DISCONNECTED /* 连接已经断开 */
  43. } IOT_OTA_State;
  44. // OTA Signal Channel
  45. typedef void (*OnOTAMessageCallback)(void *pContext, const char *msg, uint32_t msgLen);
  46. void *osc_init(const char *product_sn, const char *device_sn, void *channel, OnOTAMessageCallback callback,
  47. void *context);
  48. int osc_deinit(void *handle);
  49. int osc_report_progress(void *handle, const char *msg);
  50. int osc_upstream_publish(void *handle, const char *msg);
  51. // OTA Fetch Channel
  52. void *ofc_init(const char *url);
  53. int32_t ofc_connect(void *handle);
  54. int32_t ofc_fetch(void *handle, uint32_t size_fetched, char *buf, uint32_t buf_len, size_t range_len, uint32_t timeout_s);
  55. int ofc_deinit(void *handle);
  56. // ota_lib
  57. void *ota_lib_md5_init(void);
  58. void ota_lib_md5_update(void *md5, const char *buf, size_t buf_len);
  59. void ota_lib_md5_finalize(void *md5, char *output_str);
  60. void ota_lib_md5_deinit(void *md5);
  61. int ota_lib_get_msg_type(char *json, char **type);
  62. int ota_lib_get_params(char *json, char **url, char **version, char **md5,
  63. uint32_t *fileSize);
  64. int ota_lib_gen_upstream_msg(char *buf, size_t bufLen, const char *version, int progress,
  65. IOT_OTA_UpstreamMsgType reportType);
  66. #ifdef __cplusplus
  67. }
  68. #endif
  69. #endif //C_SDK_OTA_INTERNAL_H_