SDK Initialization
Overview
Before using other modules' functionality in the SDK, you need to invoke SDK initialization to establish a trusted communication link and initialize the running environment for the foundational components.
Correct SDK Initialization
To correctly init SDK, the following items should be realized.
- Init Device Information
- Init Developer Verification Information
- Init Log Endpoint
- Realize Key Obtain Interface
Invoke the following interface to realize the SDK initialization. Returning kOk
represents a successful initialization. If initialization fails, the error information can be check through the log print.
ErrorCode ESDKInit::Init(const Options& options)
Note: When the device is first used, it should be bound through DJI Pilot. Otherwise, this interface will be blocked until a successful binding.
/* @brief ESDKInit initialize SDK environment, preparing for SDK function
* components, caller should ensure that it is initialized correctly, otherwise
* the function may be abnormal
*/
class ESDKInit final {
public:
~ESDKInit();
ESDKInit(const ESDKInit&) = delete;
ESDKInit& operator=(const ESDKInit&) = delete;
/* @brief get the singleton of ESDKInit.
* @return instance.
*/
static ESDKInit* Instance();
/* @brief Initialize SDK environment
* @param options: options for initializing the environment
* @return Execution result.
*/
ErrorCode Init(const Options& options);
/* @brief Returns the firmware version
* @return Firmware version
*/
FirmwareVersion GetFirmwareVersion() const;
/* @brief Returns the product name
* @return Product name
*/
ProductName GetProductName() const;
/* @brief Returns the vendor name
* @return Vendor name
*/
VendorName GetVendorName() const;
/* @brief Returns the serial number
* @return Serial number
*/
SerialNumber GetSerialNumber() const;
/* @brief Returns the App license info
* @return App info
*/
AppInfo GetAppInfo() const;
/* @brief DeInitialize SDK environment
* @return Execution result.
*/
ErrorCode DeInit();
private:
ESDKInit();
class Impl;
std::unique_ptr<Impl> impl_;
};
Init Device Information
After the device information initialization, device information such as product name, supplier name, product serial number and firmware version can be check through DJI Pilot.
/**
* brief version number definition
*/
struct Version {
uint8_t major_version;
uint8_t minor_version;
uint8_t modify_version;
uint8_t debug_version;
};
/**
* brief Device information definition
*/
using FirmwareVersion = Version;
using ProductName = std::string;
using VendorName = std::string;
using SerialNumber = std::string;
/**
* brief Used to init EdgeSDK configuration
*/
struct Options {
/*! product name */
ProductName product_name;
/*! vendor name */
VendorName vendor_name;
/*! product serial number, Each device is uniqueness. */
SerialNumber serial_number;
/*! firmware version */
FirmwareVersion firmware_version;
...
}
Init Developer Verification Information
Click "App > CREATE APP" 在developer website to apply ESDK application. Without the App information of ESDK application will result in improper initialization and will affect the functionality usage.
/**
* brief AppInfo
* It is App authentication information generated from the DJI Developer website developer account. Only by correctly entering the information obtained through registration can EdgeSDK be initialized successfully.
*/
struct AppInfo {
/*! APP name generated from the developer website application */
std::string app_name;
/*! APP ID generated from the developer website application */
std::string app_id;
/*! APP KEY generated from the developer website application */
std::string app_key;
/*! APP LICENSE generated from the developer website application */
std::string app_license;
/*! User account of developer website */
std::string developer_account;
};
struct Options {
...
/*! App verification information generated from the developer website applicatio */
AppInfo app_info;
...
}
Init Log Endpoint
Log endpoint initialization can init multiple endpoint and corresponding endpoint print level. The log information during SDK running wil be printed initialized lig endpoint.
/**
* @brief Log configuration
*/
struct LoggerConsole {
/*! log output function definition */
using OutputFunc = std::function<ErrorCode(const uint8_t *, uint32_t)>;
/*! Filter log level, only output logs equal to or less than that level */
LogLevel level;
/*! Output log processing function */
OutputFunc output_func;
/*! Whether color display is supported */
bool is_support_color;
};
using LoggerConsoleList = std::list<LoggerConsole>;
struct Options {
...
/*! List of terminals for logging, supports adding multiple terminals. */
LoggerConsoleList logger_console_lists;
...
}
Realize Key Obtain Interface
The key interface obtains device-specific RSA2048 key information. Developers have to implement secure key generation and persistent storage for the device keys. EdgeSDK utilizes this interface to access key information for security functionality.
Note:if the keys are lost, re-binding is required through Pilot.
An example of implementing the key obtain interface can be found in examples/init/key_store_default.h
, where the generated keys are stored in the /tmp/
directory and will be lost upon device reboot.
Function Invocation Sample:
EdgeSDK obtains the RSA2048 DER-format private key and public key
class KeyStore {
public:
KeyStore() = default;
virtual ~KeyStore() {}
KeyStore(const KeyStore&) = delete;
KeyStore& operator=(const KeyStore&) = delete;
/* @brief Returns RSA2048 DER private key.
* @return Execution result.
*/
virtual ErrorCode RSA2048_GetDERPrivateKey(
std::string& private_key) const = 0;
/* @brief Returns RSA2048 DER public key.
* @return Execution result.
*/
virtual ErrorCode RSA2048_GetDERPublicKey(
std::string& public_key) const = 0;
};