Skip to content

Commit

Permalink
Merge branch 'feature/log_backward_compatability' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
miwright2 committed Sep 16, 2022
2 parents 40c5fc9 + 8a11033 commit 016cc56
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
15 changes: 13 additions & 2 deletions Sources/CombustionBLE/UART/LogResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class LogResponse: Response {
let sequenceNumber: UInt32
let temperatures: ProbeTemperatures

init(data: Data, success: Bool) {
init(data: Data, success: Bool, payloadLength: Int) {
let sequenceByteIndex = Response.HEADER_LENGTH
let sequenceRaw = data.subdata(in: sequenceByteIndex..<(sequenceByteIndex + 4))
sequenceNumber = sequenceRaw.withUnsafeBytes {
Expand All @@ -47,6 +47,17 @@ class LogResponse: Response {
// print("******** Received response!")
// print("Sequence = \(sequenceNumber) : Temperature = \(temperatures)")

super.init(success: success, payLoadLength: LogResponse.PAYLOAD_LENGTH)
super.init(success: success, payLoadLength: payloadLength)
}
}

extension LogResponse {

static func fromRaw(data: Data, success: Bool, payloadLength: Int) -> LogResponse? {
if(payloadLength < PAYLOAD_LENGTH) {
return nil
}

return LogResponse(data: data, success: success, payloadLength: payloadLength)
}
}
4 changes: 2 additions & 2 deletions Sources/CombustionBLE/UART/Response.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ extension Response {

switch messageType {
case .Log:
return LogResponse(data: data, success: success)
return LogResponse.fromRaw(data: data, success: success, payloadLength: Int(payloadLength))
case .SetID:
return SetIDResponse(success: success, payLoadLength: Int(payloadLength))
case .SetColor:
return SetColorResponse(success: success, payLoadLength: Int(payloadLength))
case .SessionInfo:
return SessionInfoResponse(data: data, success: success)
return SessionInfoResponse.fromRaw(data: data, success: success, payloadLength: Int(payloadLength))
}
}
}
15 changes: 13 additions & 2 deletions Sources/CombustionBLE/UART/SessionInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SessionInfoResponse: Response {

let info: SessionInformation

init(data: Data, success: Bool) {
init(data: Data, success: Bool, payloadLength: Int) {
let sequenceByteIndex = Response.HEADER_LENGTH
let sessionIDRaw = data.subdata(in: sequenceByteIndex..<(sequenceByteIndex + 4))
let sessionID = sessionIDRaw.withUnsafeBytes {
Expand All @@ -56,6 +56,17 @@ class SessionInfoResponse: Response {

info = SessionInformation(sessionID: sessionID, samplePeriod: samplePeriod)

super.init(success: success, payLoadLength: SessionInfoResponse.PAYLOAD_LENGTH)
super.init(success: success, payLoadLength: payloadLength)
}
}

extension SessionInfoResponse {

static func fromRaw(data: Data, success: Bool, payloadLength: Int) -> SessionInfoResponse? {
if(payloadLength < PAYLOAD_LENGTH) {
return nil
}

return SessionInfoResponse(data: data, success: success, payloadLength: payloadLength)
}
}

0 comments on commit 016cc56

Please sign in to comment.