Skip to content

Commit

Permalink
Add OTA Software Update in Darwin Tool Framework
Browse files Browse the repository at this point in the history
  • Loading branch information
krypton36 committed Jul 9, 2022
1 parent 776c06d commit 4e77dd8
Show file tree
Hide file tree
Showing 7 changed files with 432 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/darwin-framework-tool/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ executable("darwin-framework-tool") {
"commands/pairing/PairingCommandBridge.mm",
"commands/pairing/PairingDelegateBridge.mm",
"commands/payload/SetupPayloadParseCommand.mm",
"commands/provider/OTAProviderDelegate.mm",
"commands/provider/OTASoftwareUpdateInteractive.mm",
"commands/provider/Commands.h",
"commands/storage/Commands.h",
"commands/storage/StorageManagementCommand.mm",
"main.mm",
Expand Down
14 changes: 14 additions & 0 deletions examples/darwin-framework-tool/commands/provider/Commands.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "OTASoftwareUpdateInteractive.h"

void registerClusterOtaSoftwareUpdateProviderInteractive(Commands & commands)
{

const char * clusterName = "OtaSoftwareUpdateApp";

commands_list clusterCommands = {
make_unique<OTASoftwareUpdateSetFilePath>(), //

};

commands.Register(clusterName, clusterCommands);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
*
* Copyright (c) 2022 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#import <Matter/Matter.h>

@interface OTAProviderDelegate : NSObject <MTROTAProviderDelegate>
- (void)handleQueryImage:(MTROtaSoftwareUpdateProviderClusterQueryImageParams * _Nonnull)params
completionHandler:(void (^ _Nonnull)(MTROtaSoftwareUpdateProviderClusterQueryImageResponseParams * _Nullable data,
NSError * _Nullable error))completionHandler;

- (void)handleApplyUpdateRequest:(MTROtaSoftwareUpdateProviderClusterApplyUpdateRequestParams * _Nonnull)params
completionHandler:(void (^ _Nonnull)(MTROtaSoftwareUpdateProviderClusterApplyUpdateResponseParams * _Nullable data,
NSError * _Nullable error))completionHandler;


- (void)handleNotifyUpdateApplied:(MTROtaSoftwareUpdateProviderClusterNotifyUpdateAppliedParams * _Nonnull)params
completionHandler:(StatusCompletion _Nonnull)completionHandler;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
*
* Copyright (c) 2022 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "OTAProviderDelegate.h"
#import <Matter/Matter.h>


@interface OTAProviderDelegate ()
@end

@implementation OTAProviderDelegate
- (void)handleQueryImage:(MTROtaSoftwareUpdateProviderClusterQueryImageParams * _Nonnull)params
completionHandler:(void (^ _Nonnull)(MTROtaSoftwareUpdateProviderClusterQueryImageResponseParams * _Nullable data,
NSError * _Nullable error))completionHandler
{
NSLog(@"handleQueryImage: %@", params);

}

- (void)handleApplyUpdateRequest:(MTROtaSoftwareUpdateProviderClusterApplyUpdateRequestParams * _Nonnull)params
completionHandler:(void (^ _Nonnull)(MTROtaSoftwareUpdateProviderClusterApplyUpdateResponseParams * _Nullable data,
NSError * _Nullable error))completionHandler
{
NSLog(@"handleApplyUpdateRequest: %@", params);
}

- (void)handleNotifyUpdateApplied:(MTROtaSoftwareUpdateProviderClusterNotifyUpdateAppliedParams * _Nonnull)params
completionHandler:(StatusCompletion _Nonnull)completionHandler
{
NSLog(@"handleNotifyUpdateApplied: %@", params);
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
*
* Copyright (c) 2022 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "../common/CHIPCommandBridge.h"

static constexpr uint16_t SW_VER_STR_MAX_LEN = 64;
static constexpr uint16_t OTA_URL_MAX_LEN = 512;

typedef struct DeviceSoftwareVersionModel
{
chip::VendorId vendorId;
uint16_t productId;
uint32_t softwareVersion;
char softwareVersionString[SW_VER_STR_MAX_LEN];
uint16_t cDVersionNumber;
bool softwareVersionValid;
uint32_t minApplicableSoftwareVersion;
uint32_t maxApplicableSoftwareVersion;
char otaURL[OTA_URL_MAX_LEN];
} DeviceSoftwareVersionModel;

class OTASoftwareUpdateBase : public CHIPCommandBridge {
public:
OTASoftwareUpdateBase(const char * _Nonnull commandName)
: CHIPCommandBridge(commandName) {}
void SetCandidatesFromFilePath(char * _Nonnull filePath);
bool SelectOTACandidate(const uint16_t requestorVendorID,
const uint16_t requestorProductID,
const uint32_t requestorSoftwareVersion,
DeviceSoftwareVersionModel & finalCandidate);

/////////// CHIPCommandBridge Interface /////////
chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(120); }
private:
std::vector<DeviceSoftwareVersionModel> mCandidates;

};

class OTASoftwareUpdateSetFilePath : public OTASoftwareUpdateBase {
public:
OTASoftwareUpdateSetFilePath()
: OTASoftwareUpdateBase("candidate-file-path")
{
AddArgument("path", &mOTACandidatesFilePath);
}

/////////// CHIPCommandBridge Interface /////////
CHIP_ERROR RunCommand() override;
private:
char * _Nonnull mOTACandidatesFilePath;
};
Loading

0 comments on commit 4e77dd8

Please sign in to comment.