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);  、、超时处理

相关文章
相关标签/搜索