bowen liu
/
mbed-os-example-blinky
ex
Fork of mbed-os-example-mbed5-blinky by
DuerOS-Light-SDK-v1.1.0/duer-os-light/src/iot-baidu-ota/baidu_iot_ota_manager.h@50:9ecaa144d1f3, 2017-07-18 (annotated)
- Committer:
- tmboy
- Date:
- Tue Jul 18 09:08:52 2017 +0000
- Revision:
- 50:9ecaa144d1f3
- Parent:
- 47:9e361da97763
add .json
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
TMBOY | 47:9e361da97763 | 1 | /** |
TMBOY | 47:9e361da97763 | 2 | * File: baidu_iot_ota_manager.h |
TMBOY | 47:9e361da97763 | 3 | * Auth: Duan Lian(duanlian01@baidu.com) |
TMBOY | 47:9e361da97763 | 4 | * Date: 2016.12.21 |
TMBOY | 47:9e361da97763 | 5 | * Desc: The OTA Manager |
TMBOY | 47:9e361da97763 | 6 | */ |
TMBOY | 47:9e361da97763 | 7 | #pragma once |
TMBOY | 47:9e361da97763 | 8 | #include "rtos.h" |
TMBOY | 47:9e361da97763 | 9 | #include "shared_buffer.h" |
TMBOY | 47:9e361da97763 | 10 | #include "baidu_iot_ota_reporter.h" |
TMBOY | 47:9e361da97763 | 11 | //#include "baidu_iot_ota_package_scanner.h" //k64f |
TMBOY | 47:9e361da97763 | 12 | #ifdef TARGET_UNO_91H |
TMBOY | 47:9e361da97763 | 13 | #include "package_scanner.h" //rda |
TMBOY | 47:9e361da97763 | 14 | #endif |
TMBOY | 47:9e361da97763 | 15 | #define OPTIONAL_UPDATE 0 |
TMBOY | 47:9e361da97763 | 16 | #define MANDATED_UPDATE 1 |
TMBOY | 47:9e361da97763 | 17 | |
TMBOY | 47:9e361da97763 | 18 | |
TMBOY | 47:9e361da97763 | 19 | struct OTAServerUpdateCommand |
TMBOY | 47:9e361da97763 | 20 | { |
TMBOY | 47:9e361da97763 | 21 | char transaction[65]; |
TMBOY | 47:9e361da97763 | 22 | char version[16]; |
TMBOY | 47:9e361da97763 | 23 | char old_version[16]; |
TMBOY | 47:9e361da97763 | 24 | char url[129]; |
TMBOY | 47:9e361da97763 | 25 | char signature[129]; |
TMBOY | 47:9e361da97763 | 26 | unsigned int size; |
TMBOY | 47:9e361da97763 | 27 | }; |
TMBOY | 47:9e361da97763 | 28 | |
TMBOY | 47:9e361da97763 | 29 | class OTAManager |
TMBOY | 47:9e361da97763 | 30 | { |
TMBOY | 47:9e361da97763 | 31 | public: |
TMBOY | 47:9e361da97763 | 32 | static OTAManager* instance(); |
TMBOY | 47:9e361da97763 | 33 | ~OTAManager(); |
TMBOY | 47:9e361da97763 | 34 | int checkUpdates(const char *command = 0); |
TMBOY | 47:9e361da97763 | 35 | int syncPackageInfo(); |
TMBOY | 47:9e361da97763 | 36 | |
TMBOY | 47:9e361da97763 | 37 | int getOSInfo(os_info_t& info); |
TMBOY | 47:9e361da97763 | 38 | private: |
TMBOY | 47:9e361da97763 | 39 | enum {SHARED_BUFFER_SIZE = 2048}; |
TMBOY | 47:9e361da97763 | 40 | SharedBuffer m_SharedBuffer; |
TMBOY | 47:9e361da97763 | 41 | static OTAManager _manager; |
TMBOY | 47:9e361da97763 | 42 | bool m_bIdle; |
TMBOY | 47:9e361da97763 | 43 | char *m_pUpdateCommand; |
TMBOY | 47:9e361da97763 | 44 | OTAReporter *m_pReporter; |
TMBOY | 47:9e361da97763 | 45 | rtos::Thread *m_pThread; |
TMBOY | 47:9e361da97763 | 46 | rtos::Thread *m_pRestart_thread; |
TMBOY | 47:9e361da97763 | 47 | rtos::Mutex m_Lock; |
TMBOY | 47:9e361da97763 | 48 | rtos::Semaphore *m_pInstallComplete; |
TMBOY | 47:9e361da97763 | 49 | #ifdef TARGET_UNO_91H |
TMBOY | 47:9e361da97763 | 50 | PackageScanner m_Scanner; |
TMBOY | 47:9e361da97763 | 51 | #endif |
TMBOY | 47:9e361da97763 | 52 | |
TMBOY | 47:9e361da97763 | 53 | OTAManager(); |
TMBOY | 47:9e361da97763 | 54 | //check if updates are available and perform downloading |
TMBOY | 47:9e361da97763 | 55 | void run_downloader(); |
TMBOY | 47:9e361da97763 | 56 | int contact_ota_server(); |
TMBOY | 47:9e361da97763 | 57 | int parse_update_command(const char* str_command, OTAServerUpdateCommand &command); |
TMBOY | 47:9e361da97763 | 58 | //decrypt package and write data to storage |
TMBOY | 47:9e361da97763 | 59 | void run_installer(); |
TMBOY | 47:9e361da97763 | 60 | int applyUpdates(const OTAServerUpdateCommand& command); |
TMBOY | 47:9e361da97763 | 61 | static int data_available(unsigned char* data, unsigned int len, void* ctx); |
TMBOY | 47:9e361da97763 | 62 | static void ota_resart(); |
TMBOY | 47:9e361da97763 | 63 | }; |