Skip to main content

Firmware Upgrade Tutorial

Firmware Upgrade Tutorial

1. Overview

Online OTA firmware upgrades for drones, remote controllers, and other devices require connection to the internet through the Autel official APP. Third-party developers can also download corresponding firmware from the official website for local upgrades.

2. Upgrade Check

  • Online detection is applicable to Autel official APP. After the remote controller is connected to the network, select APP or firmware upgrade in Settings->About->More

  • When developers develop upgrade functionality, they need to download the corresponding offline upgrade package from the official website and perform local upgrades through the SDK-provided interfaces

3. Upgrade Process

3.1 Enter Upgrade Mode

For upgrading drone devices, switching to upgrade mode is required to improve upload speed of upgrade packages

// Only required for aircraft upgrades

// Enter upgrade mode
OTAUpgradeManger.getInstance().switchUpgradeMode(true)
// Exit upgrade mode
OTAUpgradeManger.getInstance().switchUpgradeMode(false)

// Mode switch listener
OTAUpgradeManger.getInstance().addUpgradeVersionListener(l:UpgradeVersionListener)

// Cancel listener
OTAUpgradeManger.getInstance().removeUpgradeVersionListener(l:UpgradeVersionListener)

Mode switch listener:

/**
* Upgrade version information reporting
*/
interface UpgradeVersionListener {

/**
* Whether entering upgrade mode was successful
*/
fun onEnterUpgradeMode(success: Boolean){}

/**
* Whether exiting upgrade mode was successful
*/
fun onExitUpgradeMode(success: Boolean){}
}

3.2 Device Upgrade

3.2.1 Initialize Upgrade Manager

Note: For upgrades, upgrade the drone first, then the base station devices, and finally the remote controller, in order from far to near. Devices need to be restarted after upgrade completion.

Create upgrade manager, example code as follows:

// Upgrade remote controller:
val deviceId = remoteDevice.getDeviceNumber()
UpgradeManager(deviceId).init(UpgradeClientTypeEnum.CLIENT_TYPE_GND)

// Upgrade aircraft:
val deviceId = droneDevice.getDeviceNumber()
UpgradeManager(deviceId).init(UpgradeClientTypeEnum.CLIENT_TYPE_SKY)

// Upgrade WiFi base station:
val deviceId = droneDevice.getDeviceNumber()
UpgradeManager(deviceId).init(UpgradeClientTypeEnum.CLIENT_BASE_STATION)
3.2.2 Start Upgrade Process

After preparing the upgrade package, you can start upgrading the device. Example code as follows:

UpgradeManager.startUpgradeFlow(file: File, md5: String?) // (MD5 not required for encrypted packages, currently MD5 verification is not performed)
3.2.3 Upgrade Process Status Listener

Register upgrade process listener, example code as follows:

UpgradeManager.registerUpgradeListener(listener:UpgradeListener)

4. Interface Description

4.1 Upgrade Process Listener

interface UpgradeListener {

/**
* Upgrade flow state reporting
*/
fun onUpgradeFlowChange(deviceId: Int, flowState: UpgradeFlowEnum){}

/**
* Error state reporting during upgrade process
*/
fun onUpgradeStateChange(deviceId: Int, state: UpgradeErrorStateEnum)

/**
* OTA package upload progress reporting
*/
fun onUploadPackageProgress(deviceId: Int,totalLength:Long,sendLength:Long,progress: Int, speed: Long)

/**
* Upgrade progress reporting after execution
*/
fun onUpgradeProgress(deviceId: Int, progress: Int)

/**
* Upgrade result reporting after execution
*/
fun onUpgradeResult(deviceId: Int, resultBean: UpgradeResultBean)
}

4.2 Upgrade Flow States

/**
* Upgrade flow states
*/
enum class UpgradeFlowEnum {

GENERATE_FILE_MD5, // Generate OTA file MD5

CHECK_UPGRADE_CONDITION, // Check upgrade conditions

CHECK_UPGRADE_STATE, // Check current upgrade state

UPGRADE_ENTER, // Enter upgrade state

UPGRADE_HIGH_SPEED, // Switch to high-speed mode

NOTIFY_SINGLE_UPGRADE, // Network notification for single device to enter upgrade state

UPGRADE_NORMAL_SPEED, // Switch to normal speed mode

UPGRADE_UPLOAD, // Upload file

UPGRADE_MD5_VERIFY, // Upload complete, notify upgrade service to verify file integrity

UPGRADE_EXECUTING, // Upgrade in progress

UNKNOWN; // Unknown state
}

4.3 Upgrade Process Errors

/**
* Upgrade process error state reporting
*/
enum class UpgradeErrorStateEnum {

UPGRADE_UNKNOWN_DEVICE_CLIENT, // Unknown upgrade device type, initialization type error

UPGRADE_DEVICE_DISCONNECT, // Upgrade device disconnected

UPGRADE_DEVICE_NOT_EXIST, // Upgrade device not found by ID

OTA_FILE_ERROR, // OTA file check failed: doesn't exist, length error, unreadable

UPGRADE_CONDITION_ERROR, // Upgrade condition check failed

UPGRADE_MODE_ENTER_ERROR, // Failed to enter upgrade mode

UPGRADE_HIGH_SPEED_ERROR, // Failed to switch to high-speed mode

UPGRADE_NORMAL_SPEED_ERROR, // Failed to switch to normal speed mode

ENTER_SINGLE_UPGRADE_ERROR, // Network failed to enter single device upgrade mode

CHECK_SINGLE_UPGRADE_STATUS_ERROR, // Network failed to check single device upgrade mode

UPGRADE_UPLOAD_ERROR, // File upload failed

UPGRADE_TRANSFER_PROGRESS_ERROR, // Failed to notify upgrade service progress

UPGRADE_MD5_ERROR, // Upgrade file MD5 verification failed

UPGRADE_EXECUTE_ERROR, // Upgrade execution failed

UPGRADE_STATE_ERROR; // Incorrect upgrade state after maximum time reached

UPGRADE_STATE_ERROR_FOR_IDLE; // Final state query returns IDLE
}

4.4 Final Upgrade Result

/**
* Upgrade result message
* Copyright: Autel Robotics
*/
data class UpgradeResultBean(
/**
* Upgrade error, see UpgradeErrorTypeEnum enum, UPGRADE_ERR_NONE indicates successful upgrade
*/
var errCode: UpgradeErrorTypeEnum = UpgradeErrorTypeEnum.UPGRADE_ERR_NONE,
/**
* Error description
*/
var errDesc: String = "",
/**
* Response result 1-success 2-error
*/
var result: ResponseResultEnum = ResponseResultEnum.UNKNOWN,
)
4.4.1 ErrorCode Enum
/**
* Response result enum
* Copyright: Autel Robotics
*/
public enum class UpgradeErrorTypeEnum(var value: Int) {

/**
* Unknown error
*/
CODE_UNKNOWN(-100),

/**
* Upgrade timeout
*/
UPGRADE_TIME_OUT(-101),

/**
* Upgrade file upload failed
*/
UPGRADE_UPLOAD_ERROR(-102),

/**
* Upgrade file download failed
*/
UPGRADE_DOWNLAOD_ERROR(-103),

/**
* Maximum retries reached
*/
UPGRADE_REPEAT_ERROR(-104),

/**
* "Parse failed"
*/
PROTO_RESPONSE_PARSE_ERROR(-1),

/**
* "Return data empty"
*/
PROTO_RESPONSE_EMPTY_DATA(-2),

/**
* "Response timeout"
*/
PROTO_RESPONSE_TIMEOUT(-3),

/**
* "Response code error"
*/
RESPONSE_CODE_ERROR(-4),

/**
* "Device not connected"
*/
DEVICE_DISCONNECTED(-5),

/**
* "Repeated request"
*/
REPEAT_REQUEST(-6),

/**
* Upgrade successful
*/
UPGRADE_ERR_NONE(0),

/**
* in flight
*/
UPGRADE_ERR_FLY(1),

/**
* in upgrading
*/
UPGRADE_ERR_BUSY(2),

/**
* MD5 error
*/
UPGRADE_ERR_MD5(3),

/**
* file not exist
*/
UPGRADE_ERR_EXIST(4),

/**
* low battery
*/
UPGRADE_ERR_LOBAT(5),

/**
* model not match
*/
UPGRADE_ERR_MODEL(6),

/**
* no enough space to upgrade
*/
UPGRADE_ERR_SPACE(7),

/**
* error header of pkg, like crc error
*/
UPGRADE_ERR_HEAD(8),

/**
* error signature, untrusted firmware
*/
UPGRADE_ERR_SIGN(9),

/**
* error firmware size, not match header
*/
UPGRADE_ERR_SIZE(10),

/**
* package error
*/
UPGRADE_ERR_PACKAGE(11),

/**
* error major version, not match firmware
*/
UPGRADE_ERR_VERSION(12),

/**
* lower than the current version, need force flag
*/
UPGRADE_ERR_LVERSION(13),

/**
* refuse upgrade request, errDesc for more details
*/
UPGRADE_ERR_REFUSE(14),

/**
* special error of every pkg, use errDesc for details
*/
UPGRADE_ERR_SPECIAL(15);
}
4.4.2 Response Results
/**
* Response result enum
* Copyright: Autel Robotics
*/
enum class ResponseResultEnum(var value: Int) {

/**
* result response of upgrade finish
*/
FINISH(0),

/**
* result response of upgrade success
*/
SUCCESS(1),

/**
* result response of upgrade failure
*/
ERROR(2),
UNKNOWN(3);
}

5. Sample Access

Refer to OTAFirmwareUpgradeFragment in the Sample