Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions OmnipodKit/Bluetooth/Id.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func nextIds(podType: PodType, controllerId: UInt32 = 0, podId: UInt32 = 0) -> (
if podType.isDash {
if controllerId == 0 {
// Create a new semi-randomized base DASH controllerId
myControllerId = createControllerId(podType: podType)
myControllerId = createDashControllerId()
basePodId = myControllerId // so nextPodId will be myControllerId + 1
}
// else a typical situation to keep the controllerId and rotate the podId
Expand Down Expand Up @@ -112,10 +112,9 @@ fileprivate func nextPodId(lastPodId: UInt32) -> UInt32 {
return lastPodId + 1
}

/// Creates a base controllerId to be used directly (DASH) or as a fake
/// controllerId base to be used as the base for the rotating podId's (O5).
/// Creates a base controllerId to be used directly when controlling DASH pods.
/// The top byte will be set for the given pod type, the bottom 2 bits will be
/// clear for use with the cycling 3 podIds, while the other 22 bits are random.
fileprivate func createControllerId(podType: PodType) -> UInt32 {
return (UInt32(podType.topIdByte) << 24) | ((arc4random() & 0x003FFFFF) << 2)
fileprivate func createDashControllerId() -> UInt32 {
return (UInt32(dashType.topIdByte) << 24) | ((arc4random() & 0x003FFFFF) << 2)
}
16 changes: 8 additions & 8 deletions OmnipodKit/OmnipodCommon/PodType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ struct PodType: CustomStringConvertible, Equatable {

case productIdUnknown = 0x0 // can be used before actual pod type is known

// 1 is unsupported, larger form factor first gen Omnipod using 4 batteries
// 1 is unsupported, probably the larger form factor first gen Omnipod using 4 batteries

case productIdEros = 2 // Omnipod Eros (PM=PI=2.x.y), AKA "Omnipod Classic (gen 3)"
case productIdEros = 2 // Omnipod Eros AKA "Omnipod Classic (gen 3)"

// 3 is unsupported & unknown, perhaps a later gen Eros or an early gen DASH NXP BLE
// 3 is unsupported & unknown, maybe an early gen DASH or for other medical use

case productIdDash = 4 // Omnipod DASH, both TWI BOARD (firmware 4.x.y) or NXP BLE (firmware 3.x.y)

case productIdOmnipod5 = 5 // Still needs to be verified!!!
case productIdOmnipod5 = 5 // Omnipod 5, all lot types (PP1, PH1, PR1)

}

Expand Down Expand Up @@ -150,16 +150,16 @@ struct PodType: CustomStringConvertible, Equatable {
// The Eros PDM uses 0x1F for the top byte of the 32 bit Id address.
// The Dash PDM uses the PDM's SN << 2 for the bottom 5 nibbles and some
// unknown values for the top 3 nibbles of its fixed 32-bit controller Id.
// The Omnipod 5 PDM also seems to use the PDM's SN << 2 for the basis
// of the its fixed 32-bit controller Id that pod Id's will be derived from.
// The Omnipod 5 controller uses its SN << 2 for the basis of its fixed 32-bit,
// but this can't be customized since it must match the certificate's value.
var topIdByte: UInt8 {
switch podType {
case .productIdEros:
return 0x1F
case .productIdDash:
return 0x17
case .productIdOmnipod5:
return 0x00 // place holder until we can get created podId working
return 0x00 // not actually used; comes from certifcate controllerId
default:
return 0x0
}
Expand All @@ -179,8 +179,8 @@ struct PodType: CustomStringConvertible, Equatable {
}

/* convenience constants */
let unknownOmnipodType = PodType(podType: .productIdUnknown)
let erosType = PodType(podType: .productIdEros)
let dashType = PodType(podType: .productIdDash)
let omnipod5Type = PodType(podType: .productIdOmnipod5)
let unknownOmnipodType = PodType(podType: .productIdUnknown)