tkl_ota | OTA Firmware Update
tkl_ota.c Over-the-Air (OTA) firmware update handles the various stages of the firmware update process: obtaining firmware update capability, OTA start notification, OTA data processing, and OTA end notification. This file is automatically generated by the TuyaOS and allows you to add your own implementations in the provided user-defined areas.
API descriptionโ
tkl_ota_get_abilityโ
OPERATE_RET tkl_ota_get_ability(uint32_t *image_size, TUYA_OTA_TYPE_E *type);
Featuresโ
Gets the OTA capability information of the current device, including the maximum firmware image size and the OTA type.
Parametersโ
image_size: Output parameter, used to store the maximum size of the firmware image.type: Output parameter, the OTA type. It can be a full package or a differential package. UseTUYA_OTA_FULLfor a full package andTUYA_OTA_DIFFfor a differential package.typedef enum {
TUYA_OTA_FULL = 1, ///< AB area switch, full package update
TUYA_OTA_DIFF = 2, ///< fixed area, differential package update
} TUYA_OTA_TYPE_E;
Return valueโ
OPRT_OK indicates success, while any other value indicates an error. For more information, see tuya_error_code.h.
tkl_ota_start_notifyโ
OPERATE_RET tkl_ota_start_notify(uint32_t image_size, TUYA_OTA_TYPE_E type, TUYA_OTA_PATH_E path);
Featuresโ
Notifies that an OTA update is starting. This function initializes the necessary variables and states for the OTA process.
Parametersโ
image_size: Input parameter, the size of the firmware image to be updated.type: Input parameter, the OTA type.path: Input parameter, the OTA path. It indicates the channel through which the data is transmitted.typedef enum {
TUYA_OTA_PATH_AIR = 0, ///< OTA from Wired/Wi-Fi/Cellular/NBIoT
TUYA_OTA_PATH_UART = 1, ///< OTA from uart for MF
TUYA_OTA_PATH_BLE = 2, ///< OTA from BLE protocol for subdev
TUYA_OTA_PATH_ZIGBEE = 3, ///< OTA from Zigbee protocol for subdev
TUYA_OTA_PATH_SEC_A = 4, ///< OTA from multi-section A
TUYA_OTA_PATH_SEC_B = 5, ///< OTA from multi-section B
TUYA_OTA_PATH_INVALID = 255 ///< OTA from multi-section invalid
}TUYA_OTA_PATH_E;
Return valueโ
OPRT_OK indicates success, while any other value indicates an error. For more information, see tuya_error_code.h.
tkl_ota_data_processโ
OPERATE_RET tkl_ota_data_process(TUYA_OTA_DATA_T *pack, uint32_t* remain_len);
Featuresโ
Processes the received OTA data packet. This function performs different update operations depending on the state.
Parametersโ
pack: Input parameter, the pointer to the OTA data packet.remain_len: Output parameter. Indicates the remaining unprocessed data length within the OTA data packet.
Return valueโ
If the data packet is processed successfully, the return value is OPRT_OK. Otherwise, an error code is returned. For more information, see tuya_error_code.h.
tkl_ota_end_notifyโ
OPERATE_RET tkl_ota_end_notify(BOOL_T reset);
Featuresโ
Notifies that the OTA update has ended. It performs verification and subsequent processing, and resets the device if necessary.
Parametersโ
reset: Input parameter. Indicates whether a device reset is required after the OTA update ends.
Return valueโ
OPRT_OK is returned if the operation is successful. If verification fails or other causes lead to failure, an error code is returned. For more information, see tuya_error_code.h.
tkl_ota_get_old_firmware_infoโ
OPERATE_RET tkl_ota_get_old_firmware_info(TUYA_OTA_FIRMWARE_INFO_T **info);
Featuresโ
Gets information about the old firmware. This function is typically used for resumable transfer scenarios.
Parametersโ
info: Output parameter, the pointer to the old firmware information structure.
Return valueโ
If the old firmware information is successfully obtained, the return value is OPRT_OK. Otherwise, an error code is returned. For more information, see tuya_error_code.h.