Skip to content

Commit

Permalink
Merge pull request #272 from ps2/dev
Browse files Browse the repository at this point in the history
Version 0.12.6
  • Loading branch information
ps2 authored Oct 23, 2016
2 parents 20d1181 + 2b7224d commit b43eee9
Show file tree
Hide file tree
Showing 62 changed files with 2,007 additions and 87 deletions.
2 changes: 1 addition & 1 deletion Crypto/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.12.5</string>
<string>0.12.6</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down
1 change: 0 additions & 1 deletion MinimedKit/Extensions/NSData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ extension Data {
*/
}


extension Data {
init?(hexadecimalString: String) {
guard let chars = hexadecimalString.cString(using: String.Encoding.utf8) else {
Expand Down
13 changes: 13 additions & 0 deletions MinimedKit/Extensions/NSDateComponents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,17 @@ extension DateComponents {

calendar = Calendar(identifier: Calendar.Identifier.gregorian)
}

init(glucoseEventBytes: Data) {
self.init()

year = Int(glucoseEventBytes[3] & 0b01111111) + 2000
month = Int((glucoseEventBytes[0] & 0b11000000) >> 4 +
(glucoseEventBytes[1] & 0b11000000) >> 6)
day = Int(glucoseEventBytes[2] & 0b00011111)
hour = Int(glucoseEventBytes[0] & 0b00011111)
minute = Int(glucoseEventBytes[1] & 0b00111111)

calendar = Calendar(identifier: Calendar.Identifier.gregorian)
}
}
56 changes: 56 additions & 0 deletions MinimedKit/GlucoseEventType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// GlucoseEventType.swift
// RileyLink
//
// Created by Timothy Mecklem on 10/16/16.
// Copyright © 2016 Pete Schwamb. All rights reserved.
//

import Foundation

public enum GlucoseEventType: UInt8 {
case dataEnd = 0x01
case sensorWeakSignal = 0x02
case sensorCal = 0x03
case fokko7 = 0x07
case sensorTimestamp = 0x08
case batteryChange = 0x0a
case sensorStatus = 0x0b
case dateTimeChange = 0x0c
case sensorSync = 0x0d
case calBGForGH = 0x0e
case sensorCalFactor = 0x0f
case tenSomething = 0x10
case nineteenSomething = 0x13

public var eventType: GlucoseEvent.Type {
switch self {
case .dataEnd:
return DataEndGlucoseEvent.self
case .sensorWeakSignal:
return SensorWeakSignalGlucoseEvent.self
case .sensorCal:
return SensorCalGlucoseEvent.self
case .fokko7:
return Fokko7GlucoseEvent.self
case .sensorTimestamp:
return SensorTimestampGlucoseEvent.self
case .batteryChange:
return BatteryChangeGlucoseEvent.self
case .sensorStatus:
return SensorStatusGlucoseEvent.self
case .dateTimeChange:
return DateTimeChangeGlucoseEvent.self
case .sensorSync:
return SensorSyncGlucoseEvent.self
case .calBGForGH:
return CalBGForGHGlucoseEvent.self
case .sensorCalFactor:
return SensorCalFactorGlucoseEvent.self
case .tenSomething:
return TenSomethingGlucoseEvent.self
case .nineteenSomething:
return NineteenSomethingGlucoseEvent.self
}
}
}
32 changes: 32 additions & 0 deletions MinimedKit/GlucoseEvents/BatteryChangeGlucoseEvent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// BatteryChangeGlucoseEvent.swift
// RileyLink
//
// Created by Timothy Mecklem on 10/16/16.
// Copyright © 2016 Pete Schwamb. All rights reserved.
//

import Foundation

public struct BatteryChangeGlucoseEvent : GlucoseEvent {
public let length: Int
public let rawData: Data
public let timestamp: DateComponents

public init?(availableData: Data) {
length = 5

guard length <= availableData.count else {
return nil
}

rawData = availableData.subdata(in: 0..<length)
timestamp = DateComponents(glucoseEventBytes: availableData.subdata(in: 1..<5))
}

public var dictionaryRepresentation: [String: Any] {
return [
"name": "BatteryChange",
]
}
}
39 changes: 39 additions & 0 deletions MinimedKit/GlucoseEvents/CalBGForGHGlucoseEvent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// CalBGForGHGlucoseEvent.swift
// RileyLink
//
// Created by Timothy Mecklem on 10/16/16.
// Copyright © 2016 Pete Schwamb. All rights reserved.
//

import Foundation

public struct CalBGForGHGlucoseEvent : GlucoseEvent {
public let length: Int
public let rawData: Data
public let timestamp: DateComponents
public let amount: Int

public init?(availableData: Data) {
length = 6

guard length <= availableData.count else {
return nil
}

func d(_ idx:Int) -> Int {
return Int(availableData[idx] as UInt8)
}

rawData = availableData.subdata(in: 0..<length)
timestamp = DateComponents(glucoseEventBytes: availableData.subdata(in: 1..<5))
amount = Int( (UInt16(d(3) & 0b00100000) << 3) | UInt16(d(5)) )
}

public var dictionaryRepresentation: [String: Any] {
return [
"name": "CalBGForGH",
"amount": amount
]
}
}
33 changes: 33 additions & 0 deletions MinimedKit/GlucoseEvents/DataEndGlucoseEvent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// DataEndGlucoseEvent.swift
// RileyLink
//
// Created by Timothy Mecklem on 10/16/16.
// Copyright © 2016 Pete Schwamb. All rights reserved.
//

import Foundation

public struct DataEndGlucoseEvent : RelativeTimestampedGlucoseEvent {
public let length: Int
public let rawData: Data
public var timestamp: DateComponents

public init?(availableData: Data) {
length = 1

guard length <= availableData.count else {
return nil
}

rawData = availableData.subdata(in: 0..<length)
timestamp = DateComponents()
}

public var dictionaryRepresentation: [String: Any] {
return [
"name": "DataEnd",
]
}
}

32 changes: 32 additions & 0 deletions MinimedKit/GlucoseEvents/DateTimeChangeGlucoseEvent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// DateTimeChangeGlucoseEvent.swift
// RileyLink
//
// Created by Timothy Mecklem on 10/16/16.
// Copyright © 2016 Pete Schwamb. All rights reserved.
//

import Foundation

public struct DateTimeChangeGlucoseEvent : GlucoseEvent {
public let length: Int
public let rawData: Data
public let timestamp: DateComponents

public init?(availableData: Data) {
length = 5

guard length <= availableData.count else {
return nil
}

rawData = availableData.subdata(in: 0..<length)
timestamp = DateComponents(glucoseEventBytes: availableData.subdata(in: 1..<5))
}

public var dictionaryRepresentation: [String: Any] {
return [
"name": "DateTimeChange",
]
}
}
32 changes: 32 additions & 0 deletions MinimedKit/GlucoseEvents/Fokko7GlucoseEvent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// Fokko7GlucoseEvent.swift
// RileyLink
//
// Created by Timothy Mecklem on 10/16/16.
// Copyright © 2016 Pete Schwamb. All rights reserved.
//

import Foundation

public struct Fokko7GlucoseEvent : GlucoseEvent {
public let length: Int
public let rawData: Data
public var timestamp: DateComponents

public init?(availableData: Data) {
length = 2

guard length <= availableData.count else {
return nil
}

rawData = availableData.subdata(in: 0..<length)
timestamp = DateComponents()
}

public var dictionaryRepresentation: [String: Any] {
return [
"name": "Fokko-7",
]
}
}
27 changes: 27 additions & 0 deletions MinimedKit/GlucoseEvents/GlucoseEvent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// GlucoseEvent.swift
// RileyLink
//
// Created by Timothy Mecklem on 10/16/16.
// Copyright © 2016 Pete Schwamb. All rights reserved.
//

import Foundation

public protocol GlucoseEvent : DictionaryRepresentable {

init?(availableData: Data)

var rawData: Data {
get
}

var length: Int {
get
}

var timestamp: DateComponents {
get
}

}
35 changes: 35 additions & 0 deletions MinimedKit/GlucoseEvents/GlucoseSensorDataGlucoseEvent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// GlucoseSensorDataGlucoseEvent.swift
// RileyLink
//
// Created by Timothy Mecklem on 10/16/16.
// Copyright © 2016 Pete Schwamb. All rights reserved.
//

import Foundation

public struct GlucoseSensorDataGlucoseEvent : RelativeTimestampedGlucoseEvent {
public let length: Int
public let rawData: Data
public let sgv: Int
public var timestamp: DateComponents

public init?(availableData: Data) {
length = 1

guard length <= availableData.count else {
return nil
}

rawData = availableData.subdata(in: 0..<length)
sgv = Int(UInt16(availableData[0]) * UInt16(2))
timestamp = DateComponents()
}

public var dictionaryRepresentation: [String: Any] {
return [
"name": "GlucoseSensorData",
"sgv": sgv
]
}
}
33 changes: 33 additions & 0 deletions MinimedKit/GlucoseEvents/NineteenSomethingGlucoseEvent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// NineteenSomethingGlucoseEvent.swift
// RileyLink
//
// Created by Timothy Mecklem on 10/16/16.
// Copyright © 2016 Pete Schwamb. All rights reserved.
//

import Foundation

public struct NineteenSomethingGlucoseEvent : RelativeTimestampedGlucoseEvent {
public let length: Int
public let rawData: Data
public var timestamp: DateComponents

public init?(availableData: Data) {
length = 1

guard length <= availableData.count else {
return nil
}

rawData = availableData.subdata(in: 0..<length)
timestamp = DateComponents()
}

public var dictionaryRepresentation: [String: Any] {
return [
"name": "19-Something",
]
}
}

15 changes: 15 additions & 0 deletions MinimedKit/GlucoseEvents/ReferenceTimestampedGlucoseEvent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// ReferenceTimestampedGlucoseEvent.swift
// RileyLink
//
// Created by Timothy Mecklem on 10/17/16.
// Copyright © 2016 Pete Schwamb. All rights reserved.
//

import Foundation

/// An event that supplies timestamp information that can be used to calculate a RelativeTimestampedGlucoseEvent
public protocol ReferenceTimestampedGlucoseEvent : GlucoseEvent {

}

18 changes: 18 additions & 0 deletions MinimedKit/GlucoseEvents/RelativeTimestampedGlucoseEvent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// RelativeTimestampedGlucoseEvent.swift
// RileyLink
//
// Created by Timothy Mecklem on 10/16/16.
// Copyright © 2016 Pete Schwamb. All rights reserved.
//

import Foundation

/// An event that requires timestamp information from a ReferenceTimestampGlucoseEvent
public protocol RelativeTimestampedGlucoseEvent : GlucoseEvent {

var timestamp: DateComponents {
get set
}

}
Loading

0 comments on commit b43eee9

Please sign in to comment.