Skip to content

Commit

Permalink
Merge pull request #16 from combustion-inc/develop
Browse files Browse the repository at this point in the history
Release v0.8.1
  • Loading branch information
jjohnstz authored May 27, 2022
2 parents 680b20f + 516edf5 commit 5015d40
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,54 +33,6 @@ public enum CombustionProductType: UInt8 {
case NODE = 0x02
}

/// Probe colors
public enum ProbeColor: UInt8, CaseIterable {
case COLOR1 = 0x00
case COLOR2 = 0x01
case COLOR3 = 0x02
case COLOR4 = 0x03
case COLOR5 = 0x04
case COLOR6 = 0x05
case COLOR7 = 0x06
case COLOR8 = 0x07

private enum Constants {
static let PRODE_COLOR_MASK: UInt8 = 0x7
static let PRODE_COLOR_SHIFT: UInt8 = 2
}

static func fromRawData(data: Data) -> ProbeColor {
let modeIdColorBytes = [UInt8](data)

let rawProbeColor = (modeIdColorBytes[0] & (Constants.PRODE_COLOR_MASK << Constants.PRODE_COLOR_SHIFT)) >> Constants.PRODE_COLOR_SHIFT
return ProbeColor(rawValue: rawProbeColor) ?? .COLOR1
}
}

/// Probe IDs
public enum ProbeID: UInt8, CaseIterable {
case ID1 = 0x00
case ID2 = 0x01
case ID3 = 0x02
case ID4 = 0x03
case ID5 = 0x04
case ID6 = 0x05
case ID7 = 0x06
case ID8 = 0x07

private enum Constants {
static let PRODE_ID_MASK: UInt8 = 0x7
static let PRODE_ID_SHIFT: UInt8 = 5
}

static func fromRawData(data: Data) -> ProbeID {
let modeIdColorBytes = [UInt8](data)

let rawProbeID = (modeIdColorBytes[0] & (Constants.PRODE_ID_MASK << Constants.PRODE_ID_SHIFT)) >> Constants.PRODE_ID_SHIFT
return ProbeID(rawValue: rawProbeID) ?? .ID1
}
}


/// Struct containing advertising data received from device.
public struct AdvertisingData {
Expand All @@ -94,6 +46,8 @@ public struct AdvertisingData {
public let id: ProbeID
/// Probe Color
public let color: ProbeColor
/// Probe mode
public let mode: ProbeMode

private enum Constants {
// Locations of data in advertising packets
Expand Down Expand Up @@ -140,10 +94,12 @@ extension AdvertisingData {
let modeIdColorData = data.subdata(in: Constants.MODE_COLOR_ID_RANGE)
id = ProbeID.fromRawData(data: modeIdColorData)
color = ProbeColor.fromRawData(data: modeIdColorData)
mode = ProbeMode.fromRawData(data: modeIdColorData)
}
else {
id = .ID1
color = .COLOR1
mode = .Normal
}
}
}
Expand All @@ -157,6 +113,7 @@ extension AdvertisingData {
serialNumber = fakeSerial
id = .ID1
color = .COLOR1
mode = .Normal
}

// Fake data initializer for Simulated Probe
Expand All @@ -166,5 +123,6 @@ extension AdvertisingData {
serialNumber = fakeSerial
id = .ID1
color = .COLOR1
mode = .Normal
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public struct DeviceStatus {
public let id: ProbeID
/// Probe Color
public let color: ProbeColor
/// Probe mode
public let mode: ProbeMode

private enum Constants {
// Locations of data in status packet
Expand Down Expand Up @@ -71,10 +73,12 @@ extension DeviceStatus {
let modeIdColorData = data.subdata(in: Constants.MODE_COLOR_ID_RANGE)
id = ProbeID.fromRawData(data: modeIdColorData)
color = ProbeColor.fromRawData(data: modeIdColorData)
mode = ProbeMode.fromRawData(data: modeIdColorData)
}
else {
id = .ID1
color = .COLOR1
mode = .Normal
}
}
}
50 changes: 50 additions & 0 deletions Sources/CombustionBLE/BleData/ProbeColor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// ProbeColor.swift

/*--
MIT License

Copyright (c) 2021 Combustion Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
--*/

import Foundation

public enum ProbeColor: UInt8, CaseIterable {
case COLOR1 = 0x00
case COLOR2 = 0x01
case COLOR3 = 0x02
case COLOR4 = 0x03
case COLOR5 = 0x04
case COLOR6 = 0x05
case COLOR7 = 0x06
case COLOR8 = 0x07

private enum Constants {
static let PRODE_COLOR_MASK: UInt8 = 0x7
static let PRODE_COLOR_SHIFT: UInt8 = 2
}

static func fromRawData(data: Data) -> ProbeColor {
let modeIdColorBytes = [UInt8](data)

let rawProbeColor = (modeIdColorBytes[0] & (Constants.PRODE_COLOR_MASK << Constants.PRODE_COLOR_SHIFT)) >> Constants.PRODE_COLOR_SHIFT
return ProbeColor(rawValue: rawProbeColor) ?? .COLOR1
}
}
50 changes: 50 additions & 0 deletions Sources/CombustionBLE/BleData/ProbeID.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// ProbeID.swift

/*--
MIT License

Copyright (c) 2021 Combustion Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
--*/

import Foundation

public enum ProbeID: UInt8, CaseIterable {
case ID1 = 0x00
case ID2 = 0x01
case ID3 = 0x02
case ID4 = 0x03
case ID5 = 0x04
case ID6 = 0x05
case ID7 = 0x06
case ID8 = 0x07

private enum Constants {
static let PRODE_ID_MASK: UInt8 = 0x7
static let PRODE_ID_SHIFT: UInt8 = 5
}

static func fromRawData(data: Data) -> ProbeID {
let modeIdColorBytes = [UInt8](data)

let rawProbeID = (modeIdColorBytes[0] & (Constants.PRODE_ID_MASK << Constants.PRODE_ID_SHIFT)) >> Constants.PRODE_ID_SHIFT
return ProbeID(rawValue: rawProbeID) ?? .ID1
}
}
45 changes: 45 additions & 0 deletions Sources/CombustionBLE/BleData/ProbeMode.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// ProbeMode.swift

/*--
MIT License

Copyright (c) 2021 Combustion Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
--*/

import Foundation

public enum ProbeMode: UInt8, CaseIterable {
case Normal = 0x00
case InstantRead = 0x01
case Reserved = 0x02
case Error = 0x03

private enum Constants {
static let PRODE_MODE_MASK: UInt8 = 0x3
}

static func fromRawData(data: Data) -> ProbeMode {
let modeIdColorBytes = [UInt8](data)

let rawProbeID = modeIdColorBytes[0] & (Constants.PRODE_MODE_MASK)
return ProbeMode(rawValue: rawProbeID) ?? .Normal
}
}
11 changes: 7 additions & 4 deletions Sources/CombustionBLE/Probe.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,18 @@ extension Probe {
/// Updates the Device based on newly-received DeviceStatus message. Requests missing records.
func updateProbeStatus(deviceStatus: DeviceStatus) {

currentTemperatures = deviceStatus.temperatures
minSequenceNumber = deviceStatus.minSequenceNumber
maxSequenceNumber = deviceStatus.maxSequenceNumber
id = deviceStatus.id
color = deviceStatus.color

// Log the temperature data point
temperatureLog.appendDataPoint(dataPoint:
LoggedProbeDataPoint.fromDeviceStatus(deviceStatus:
deviceStatus))
// Log the temperature data point for "Normal" status updates
if(deviceStatus.mode == .Normal) {
temperatureLog.appendDataPoint(dataPoint:
LoggedProbeDataPoint.fromDeviceStatus(deviceStatus:
deviceStatus))
}

// Check for missing records
if let missingSequence = temperatureLog.firstMissingIndex(sequenceRangeStart: deviceStatus.minSequenceNumber,
Expand Down
3 changes: 2 additions & 1 deletion Sources/CombustionBLE/SimulatedProbe.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ class SimulatedProbe: Probe {
maxSequenceNumber: lastSequence,
temperatures: ProbeTemperatures.withRandomData(),
id: .ID1,
color: .COLOR1)
color: .COLOR1,
mode: .Normal)

updateProbeStatus(deviceStatus: deviceStatus)
}
Expand Down

0 comments on commit 5015d40

Please sign in to comment.