1818import SwiftOCA
1919
2020public extension OcaRoot {
21+ private nonisolated static func _logUnexpectedParameterCount(
22+ _ command: Ocp1Command ,
23+ expected responseParameterCount: UInt8 ? = nil
24+ ) {
25+ Task {
26+ await OcaDevice . shared. logger. info (
27+ " OcaRoot.decodeCommand( \( command) ): unexpected parameter count \( command. parameters. parameterCount) , expected \( responseParameterCount != nil ? " \( responseParameterCount!) " : " none " ) "
28+ )
29+ }
30+ }
31+
2132 nonisolated static func decodeCommand< U: Decodable > (
2233 _ command: Ocp1Command
2334 ) throws -> U {
2435 let responseParameterCount = _ocp1ParameterCount ( type: U . self)
2536 let response = try Ocp1Decoder ( ) . decode ( U . self, from: command. parameters. parameterData)
2637 if command. parameters. parameterCount != responseParameterCount {
27- Task {
28- await OcaDevice . shared. logger. info (
29- " OcaRoot.decodeCommand( \( command) ): unexpected parameter count \( command. parameters. parameterCount) , expected \( responseParameterCount) "
30- )
31- }
38+ _logUnexpectedParameterCount ( command, expected: responseParameterCount)
3239 throw Ocp1Error . status ( . parameterOutOfRange)
3340 }
3441 return response
@@ -46,11 +53,7 @@ public extension OcaRoot {
4653 guard command. parameters. parameterCount == 0 ,
4754 command. parameters. parameterData. isEmpty
4855 else {
49- Task {
50- await OcaDevice . shared. logger. info (
51- " OcaRoot.decodeCommand( \( command) ): unexpected parameter count \( command. parameters. parameterCount) , expected none "
52- )
53- }
56+ Self . _logUnexpectedParameterCount ( command)
5457 throw Ocp1Error . status ( . parameterOutOfRange)
5558 }
5659 }
0 commit comments