Skip to content

Commit

Permalink
Merge 11c079d into 58508b2
Browse files Browse the repository at this point in the history
  • Loading branch information
selissia authored Oct 27, 2021
2 parents 58508b2 + 11c079d commit 2381315
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 26 deletions.
10 changes: 6 additions & 4 deletions examples/ota-requestor-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier,
return (retval);
}

void SendQueryImageCommand()
void SendQueryImageCommand(chip::NodeId peerNodeId = providerNodeId, chip::FabricIndex peerFabricIndex = providerFabricIndex)
{
// Explicitly calling UpdateAddress() should not be needed once OperationalDeviceProxy can resolve IP address from node ID and
// fabric index
Expand All @@ -261,9 +261,8 @@ void SendQueryImageCommand()
.fabricsTable = &(server->GetFabricTable()),
};

CHIP_ERROR err = CHIP_NO_ERROR;
FabricIndex peerFabricIndex = providerFabricIndex;
gOperationalDeviceProxy.Init(providerNodeId, peerFabricIndex, initParams);
CHIP_ERROR err = CHIP_NO_ERROR;
gOperationalDeviceProxy.Init(peerNodeId, peerFabricIndex, initParams);
err = gOperationalDeviceProxy.Connect(&mOnConnectedCallback, &mOnConnectionFailureCallback);
if (err != CHIP_NO_ERROR)
{
Expand Down Expand Up @@ -316,6 +315,9 @@ int main(int argc, char * argv[])
// Initialize device attestation config
SetDeviceAttestationCredentialsProvider(chip::Credentials::Examples::GetExampleDACProvider());

// This will allow ExampleOTARequestor to call SendQueryImageCommand
ExampleOTARequestor::GetInstance().SetConnectToProviderCallback(SendQueryImageCommand);

// If a delay is provided, QueryImage after the timer expires
if (delayQueryTimeInSec > 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ void ExampleOTARequestor::Init(chip::Controller::ControllerDeviceInitParams conn

void ExampleOTARequestor::ConnectToProvider()
{
FabricInfo * providerFabric = GetProviderFabricInfo();
VerifyOrReturn(providerFabric != nullptr,
ChipLogError(SoftwareUpdate, "No Fabric found for index %" PRIu8, mProviderFabricIndex));

ChipLogProgress(SoftwareUpdate,
"Once #7976 is fixed, this would attempt to connect to 0x" ChipLogFormatX64 " on FabricIndex 0x%" PRIu8
" (" ChipLogFormatX64 ")",
ChipLogValueX64(mProviderNodeId), mProviderFabricIndex, ChipLogValueX64(providerFabric->GetFabricId()));

// TODO: uncomment and fill in after #7976 is fixed
// mProviderDevice.Init(mConnectParams, mProviderNodeId, address, mProviderFabricIndex);
// mProviderDevice.EstablishConnectivity();

if (mConnectToProviderCallback != nullptr)
{
ChipLogProgress(SoftwareUpdate, "Attempting to connect to 0x" ChipLogFormatX64 " on FabricIndex 0x%" PRIu8,
ChipLogValueX64(mProviderNodeId), mProviderFabricIndex);

mConnectToProviderCallback(mProviderNodeId, mProviderFabricIndex);
}
else
{
ChipLogError(SoftwareUpdate, "ConnectToProviderCallback is not set");
}
}

EmberAfStatus ExampleOTARequestor::HandleAnnounceOTAProvider(
Expand All @@ -91,16 +91,8 @@ EmberAfStatus ExampleOTARequestor::HandleAnnounceOTAProvider(
mProviderNodeId = providerLocation;
mProviderFabricIndex = commandObj->GetExchangeContext()->GetSessionHandle().GetFabricIndex();

FabricInfo * providerFabric = GetProviderFabricInfo();
if (providerFabric == nullptr)
{
ChipLogError(SoftwareUpdate, "No Fabric found for index %" PRIu8, mProviderFabricIndex);
return EMBER_ZCL_STATUS_SUCCESS;
}

ChipLogProgress(SoftwareUpdate,
"Notified of Provider at NodeID: 0x" ChipLogFormatX64 "on FabricIndex 0x%" PRIu8 " (" ChipLogFormatX64 ")",
ChipLogValueX64(mProviderNodeId), mProviderFabricIndex, ChipLogValueX64(providerFabric->GetFabricId()));
ChipLogProgress(SoftwareUpdate, "Notified of Provider at NodeID: 0x" ChipLogFormatX64 " on FabricIndex 0x%" PRIu8,
ChipLogValueX64(mProviderNodeId), mProviderFabricIndex);

// If reason is URGENT_UPDATE_AVAILABLE, we start OTA immediately. Otherwise, respect the timer value set in mOtaStartDelayMs.
// This is done to exemplify what a real-world OTA Requestor might do while also being configurable enough to use as a test app.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class ExampleOTARequestor
chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath,
const chip::app::Clusters::OtaSoftwareUpdateRequestor::Commands::AnnounceOtaProvider::DecodableType & commandData);

// Setter for mConnectToProviderCallback
void SetConnectToProviderCallback(void (*f)(chip::NodeId, chip::FabricIndex)) { mConnectToProviderCallback = f; }

private:
ExampleOTARequestor();

Expand All @@ -53,4 +56,9 @@ class ExampleOTARequestor
chip::NodeId mProviderNodeId;
chip::FabricIndex mProviderFabricIndex;
uint32_t mOtaStartDelayMs;

// TODO: This will be redone once the full Requestor app design is in place
// Pointer to the function that establishes a session with the Provider and initiates
// the BDX download
void (*mConnectToProviderCallback)(chip::NodeId, chip::FabricIndex);
};

0 comments on commit 2381315

Please sign in to comment.