OTA分析

#define EMBER_AF_PLUGIN_OTA_CLIENT_POLICY_FIRMWARE_VERSION 11node

還要修改一個地方就是PY文件,也要把相對應的固件版本更新下。服務器

 emberAfPluginOtaClientStackStatusCallback  //若是不想開機啓動升級,要把這裏屏蔽掉網絡

 

void emberAfPluginOtaClientStackStatusCallback(EmberStatus status)
{
return ;
#if defined(EMBER_AF_PLUGIN_OTA_CLIENT_AUTO_START)
uint16_t randomDelaySeconds;
if (status != EMBER_NETWORK_UP
|| currentBootloadState != BOOTLOAD_STATE_NONE) {
return;
}
randomDelaySeconds=0;
// EMAPPFWKV2-1516: make sure we don't have a delay time of 0 seconds.
if (randomDelaySeconds == 0) {
randomDelaySeconds = 1;
}
recordUpgradeStatus(BOOTLOAD_STATE_DELAY);
//otaPrintln("Delaying %d seconds before starting OTA client", randomDelaySeconds);
// the setTimer(uint32_t) function wants milliseconds
setTimer(randomDelaySeconds * MILLISECOND_TICKS_PER_SECOND);
#endif
}dom

plugin ota-server notify (args)
<uint16_t> The node ID (can be a broadcast address) to which this OTA Notify mess ...
<uint8_t> Target endpoint for the OTA Notify message (only really meaningful for ...
<uint8_t> Used to specify which parameters you want included in the OTA Notify c ...
<uint8_t> Corresponds to QueryJitter parameter in the OTA Upgrade cluster specif ...
<uint16_t> Manufacturer ID for the image being advertised (should match the mfr I ...
<uint16_t> Image type ID for the image being advertised (should match the image t ...
<uint32_t> Firmware version of the image being advertised (should match the versi ...函數

 

 plugin ota-server notify 0x9858  1 0 12 0x1002 0 30   ui

//修改最後一個數字就好,是版本號this

plugin ota-server upgrade (args)
<uint16_t> Short destination to send message
<uint8_t> Endpoint destination to send message
<uint16_t> Manufacturer ID for the image (0xFFFF for wildcard)
<uint16_t> Image type for the image (0xFFFF for wildcard)
<uint32_t> File version for the image (0xFFFFFFFF for wildcard)spa

- Instruct a device to upgrade now.server

plugin ota-server upgrade 0x9858 1  0x1002 0 26ci

 

void emberAfOtaClientVersionInfoCallback(EmberAfOtaImageId* currentImageInfo,
uint16_t* hardwareVersion){

currentImageInfo->manufacturerId = EMBER_AF_MANUFACTURER_CODE;
currentImageInfo->imageTypeId = EMBER_AF_PLUGIN_OTA_CLIENT_POLICY_IMAGE_TYPE_ID;
currentImageInfo->firmwareVersion = EMBER_AF_PLUGIN_OTA_CLIENT_POLICY_FIRMWARE_VERSION;

}

 

//=======網關進來的消息處理===========

static EmberAfStatus commandParse(bool defaultResponse,
EmberAfClusterCommand* message)

startDownload 、、啓動下載

recordUpgradeStatus(BOOTLOAD_STATE_DOWNLOAD);

startDownload  、、這裏面是正式開始下載

continueImageDownload開始下載

//==========

 

1:上電覆位

    emberAfPluginEepromInitCallback(); 

檢測外部SPI 存儲器在不在,

2:簇初始化函數

emberAfOtaBootloadClusterClientInitCallback()

emAfOtaStorageEepromInit();若是FLASH不在,這裏會讓代碼崩潰

若是有一個高版本的文件在FLASH中,storageHasFullImage會爲1.

3:當網絡起來的時候,會觸發OTA客戶端的一些處理流程:這裏是入口很是關鍵

#define EMBER_AF_GENERATED_PLUGIN_STACK_STATUS_FUNCTION_DECLARATIONS \
void emberAfPluginOtaClientStackStatusCallback(EmberStatus status); \

{   

  這個裏面要修改一下,否則啓動會很慢

      randomDelaySeconds=0;改爲0秒就能夠了,實際會1秒以後觸發

      currentBootloadState = BOOTLOAD_STATE_DELAY;

     waitingForResponse=0;沒有等待相應

     setTimer(延時啓動),觸發函數

     nextEventTimer = 0;  、、超時處理下載文件時候

4:setTimer延時觸發的就是下面這個函數;

   emberAfOtaBootloadClusterClientTickCallback

   otaClientTick();

 

5:OTA運行的正式啓動的第一步

     currentBootloadState = BOOTLOAD_STATE_DELAY;

   startServerDiscovery()啓動服務發現,就是去找OTA服務器、2秒時間超時處理

   waitingForResponse = true;、、等待接收

    setTimer(10分鐘);

    emAfOtaClientServiceDiscoveryCallback 當收到網關回的信息,會進入這

    waitingForResponse = false;、、正常會清掉

     若是沒有找到服務器,會過10分鐘,繼續尋找

    若是找到了:

    serverEndpoint = epList->list[0];
    serverNodeId = result->matchAddress;

     getPartnerLinkKey();;獲取LINKKEY

 

  }

 

若是SPI裏有一個更新的

EMBER_AF_PLUGIN_OTA_CLIENT_VERIFY_DELAY_MS  就檢測完整性10MS 這個能夠一改

先不考慮FLSAH裏有一個更高版本的文件。

 

6:找服務器的IEEE地址

recordUpgradeStatus(BOOTLOAD_STATE_GET_SERVER_EUI);

determineNextState  決定下一個作什麼

 recordUpgradeStatus(BOOTLOAD_STATE_QUERY_NEXT_IMAGE);

查詢下一個映象文件,超時5分鐘

接收函數處理

 

 

1:進來的消息處理

bool emAfProcessClusterSpecificCommand(EmberAfClusterCommand *cmd)

{ emberAfOtaClientIncomingMessageRawCallback(cmd))

 }

 

2:

bool emberAfOtaClientIncomingMessageRawCallback(EmberAfClusterCommand* message)
{
commandParse(false, // default response?
}

3:

waitingForResponse = false;

imageBlockResponseParse(message->buffer,index + defaultResponse,message->bufLen);

 continueImageDownload();

sendMessage(commandId,0, // upgrade end status (ignored) timer)

waitingForResponse = true;

emberAfSendCommandUnicast(EMBER_OUTGOING_DIRECT, serverNodeId);

 setTimer(timer);  、、超時處理

相關文章
相關標籤/搜索