-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #626 from JulesDommartin/main
Added support for HealthCurrentStatus and HealthFaultStatus
- Loading branch information
Showing
5 changed files
with
536 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (c) 2024, Nordic Semiconductor | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, | ||
* are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, this | ||
* list of conditions and the following disclaimer in the documentation and/or | ||
* other materials provided with the distribution. | ||
* | ||
* 3. Neither the name of the copyright holder nor the names of its contributors may | ||
* be used to endorse or promote products derived from this software without | ||
* specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | ||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* Created by Jules DOMMARTIN on 04/11/2024. | ||
*/ | ||
|
||
class HealthClientHandler: ModelDelegate { | ||
var messageTypes: [UInt32 : MeshMessage.Type] | ||
|
||
var isSubscriptionSupported: Bool = false | ||
|
||
var publicationMessageComposer: MessageComposer? = nil | ||
|
||
init() { | ||
let types: [StaticMeshMessage.Type] = [ | ||
HealthCurrentStatus.self, | ||
HealthFaultStatus.self | ||
] | ||
|
||
messageTypes = types.toMap() | ||
} | ||
|
||
func model(_ model: NordicMesh.Model, didReceiveAcknowledgedMessage request: any NordicMesh.AcknowledgedMeshMessage, from source: NordicMesh.Address, sentTo destination: NordicMesh.MeshAddress) throws -> any NordicMesh.MeshResponse { | ||
switch request { | ||
// No acknowledged message supported by this Model. | ||
default: | ||
fatalError("Message not supported: \(request)") | ||
} | ||
} | ||
|
||
func model(_ model: NordicMesh.Model, didReceiveUnacknowledgedMessage message: any NordicMesh.UnacknowledgedMeshMessage, from source: NordicMesh.Address, sentTo destination: NordicMesh.MeshAddress) { | ||
switch message { | ||
|
||
default: | ||
// Ignore. | ||
break | ||
} | ||
} | ||
|
||
func model(_ model: NordicMesh.Model, didReceiveResponse response: any NordicMesh.MeshResponse, toAcknowledgedMessage request: any NordicMesh.AcknowledgedMeshMessage, from source: NordicMesh.Address) { | ||
// Ignore. There are no CDB fields matching these parameters. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright (c) 2024, Nordic Semiconductor | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, | ||
* are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, this | ||
* list of conditions and the following disclaimer in the documentation and/or | ||
* other materials provided with the distribution. | ||
* | ||
* 3. Neither the name of the copyright holder nor the names of its contributors may | ||
* be used to endorse or promote products derived from this software without | ||
* specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | ||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* Created by Jules DOMMARTIN on 04/11/2024. | ||
*/ | ||
|
||
import Foundation | ||
|
||
public struct HealthCurrentStatus: StaticMeshResponse { | ||
public static var opCode: UInt32 = 0x0004 | ||
|
||
public var parameters: Data? { | ||
return Data() + testId | ||
} | ||
|
||
/// Test id | ||
public let testId: UInt8 | ||
|
||
/// Company id | ||
public let companyIdentifier: UInt16 | ||
|
||
/// List of faults | ||
/// If no Fault fields are present (nil), it means no registered fault condition exists on an element. | ||
public let faultArray: [HealthFault]? | ||
|
||
public init(testId: UInt8, companyIdentifier: UInt16) { | ||
self.testId = testId | ||
self.companyIdentifier = companyIdentifier | ||
self.faultArray = nil | ||
} | ||
|
||
public init(testId: UInt8, companyIdentifier: UInt16, faultArray: [HealthFault]) { | ||
self.testId = testId | ||
self.companyIdentifier = companyIdentifier | ||
self.faultArray = faultArray | ||
} | ||
|
||
public init?(parameters: Data) { | ||
guard parameters.count >= 3 else { | ||
return nil | ||
} | ||
testId = parameters.read(fromOffset: 0) | ||
companyIdentifier = parameters.read(fromOffset: 1) | ||
if parameters.count > 3 { | ||
faultArray = parameters | ||
.subdata(in: 3 ..< parameters.count - 3) | ||
.bytes | ||
.compactMap { HealthFault.fromId($0) } | ||
} else { | ||
faultArray = nil | ||
} | ||
} | ||
} |
Oops, something went wrong.