Skip to content

Commit b55d67b

Browse files
authored
Adding some new rx messages (#47)
1 parent 0dd39e8 commit b55d67b

File tree

5 files changed

+64
-2
lines changed

5 files changed

+64
-2
lines changed

xDripG5.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
43538C111D81220F0071CA5E /* NSData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43CABE101C350B2800005705 /* NSData.swift */; };
1212
43846AC61D8F896C00799272 /* CalibrationDataRxMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43846AC51D8F896C00799272 /* CalibrationDataRxMessage.swift */; };
1313
43846AC81D8F89BE00799272 /* CalibrationDataRxMessageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43846AC71D8F89BE00799272 /* CalibrationDataRxMessageTests.swift */; };
14+
43880F981D9E19FC009061A8 /* TransmitterVersionRxMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43880F971D9E19FC009061A8 /* TransmitterVersionRxMessage.swift */; };
15+
43880F9A1D9E1BD7009061A8 /* TransmitterVersionRxMessageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43880F991D9E1BD7009061A8 /* TransmitterVersionRxMessageTests.swift */; };
1416
43CABDF71C3506F100005705 /* xDripG5.h in Headers */ = {isa = PBXBuildFile; fileRef = 43CABDF61C3506F100005705 /* xDripG5.h */; settings = {ATTRIBUTES = (Public, ); }; };
1517
43CABDFE1C3506F100005705 /* xDripG5.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 43CABDF31C3506F100005705 /* xDripG5.framework */; };
1618
43CABE121C350B2800005705 /* BluetoothManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43CABE0E1C350B2800005705 /* BluetoothManager.swift */; };
@@ -78,6 +80,8 @@
7880
430D64C41CB7846A00FCA750 /* NSData+CRC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSData+CRC.swift"; sourceTree = "<group>"; };
7981
43846AC51D8F896C00799272 /* CalibrationDataRxMessage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CalibrationDataRxMessage.swift; sourceTree = "<group>"; };
8082
43846AC71D8F89BE00799272 /* CalibrationDataRxMessageTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CalibrationDataRxMessageTests.swift; sourceTree = "<group>"; };
83+
43880F971D9E19FC009061A8 /* TransmitterVersionRxMessage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransmitterVersionRxMessage.swift; sourceTree = "<group>"; };
84+
43880F991D9E1BD7009061A8 /* TransmitterVersionRxMessageTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransmitterVersionRxMessageTests.swift; sourceTree = "<group>"; };
8185
43CABDF31C3506F100005705 /* xDripG5.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = xDripG5.framework; sourceTree = BUILT_PRODUCTS_DIR; };
8286
43CABDF61C3506F100005705 /* xDripG5.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = xDripG5.h; sourceTree = "<group>"; };
8387
43CABDF81C3506F100005705 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -194,6 +198,7 @@
194198
43F82BD31D037227006F5DD7 /* SessionStartRxMessageTests.swift */,
195199
43F82BD11D037040006F5DD7 /* SessionStopRxMessageTests.swift */,
196200
43F82BCB1D035AA4006F5DD7 /* TransmitterTimeRxMessageTests.swift */,
201+
43880F991D9E1BD7009061A8 /* TransmitterVersionRxMessageTests.swift */,
197202
);
198203
path = xDripG5Tests;
199204
sourceTree = "<group>";
@@ -223,6 +228,7 @@
223228
43CABE211C350B3D00005705 /* TransmitterTimeRxMessage.swift */,
224229
43CABE221C350B3D00005705 /* TransmitterTimeTxMessage.swift */,
225230
43CE7CC91CA73B94003CC1B0 /* TransmitterVersionTxMessage.swift */,
231+
43880F971D9E19FC009061A8 /* TransmitterVersionRxMessage.swift */,
226232
);
227233
path = Messages;
228234
sourceTree = "<group>";
@@ -357,6 +363,7 @@
357363
43EEA7121D14DC0800CBBDA0 /* AESCrypt.m in Sources */,
358364
43CE7CCE1CA73C22003CC1B0 /* SessionStartTxMessage.swift in Sources */,
359365
43CABE2E1C350B3D00005705 /* TransmitterTimeTxMessage.swift in Sources */,
366+
43880F981D9E19FC009061A8 /* TransmitterVersionRxMessage.swift in Sources */,
360367
43538C111D81220F0071CA5E /* NSData.swift in Sources */,
361368
43CABE2C1C350B3D00005705 /* TransmitterMessage.swift in Sources */,
362369
43CABE131C350B2800005705 /* BluetoothServices.swift in Sources */,
@@ -384,6 +391,7 @@
384391
43DC87C01C8B509B005BC30D /* NSData.swift in Sources */,
385392
43F82BD21D037040006F5DD7 /* SessionStopRxMessageTests.swift in Sources */,
386393
43E397911D5692080028E321 /* GlucoseTests.swift in Sources */,
394+
43880F9A1D9E1BD7009061A8 /* TransmitterVersionRxMessageTests.swift in Sources */,
387395
43DC87C21C8B520F005BC30D /* GlucoseRxMessageTests.swift in Sources */,
388396
);
389397
runOnlyForDeploymentPostprocessing = 0;

xDripG5/Messages/BatteryStatusTxMessage.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ import Foundation
1111

1212
struct BatteryStatusTxMessage {
1313
let opcode: UInt8 = 0x22
14+
15+
// Response: 23003c012f01cd021f247bae
1416
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// TransmitterVersionRxMessage.swift
3+
// xDripG5
4+
//
5+
// Created by Nate Racklyeft on 9/29/16.
6+
// Copyright © 2016 Nathan Racklyeft. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
12+
struct TransmitterVersionRxMessage: TransmitterRxMessage {
13+
static let opcode: UInt8 = 0x4b
14+
let status: UInt8
15+
let firmwareVersion: [UInt8]
16+
17+
init?(data: Data) {
18+
guard data.count == 19 && data.crcValid() else {
19+
return nil
20+
}
21+
22+
guard data[0] == type(of: self).opcode else {
23+
return nil
24+
}
25+
26+
status = data[1]
27+
firmwareVersion = data[2..<6]
28+
}
29+
30+
}

xDripG5/NSData.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ public extension Data {
4545

4646
return dataArray
4747
}
48-
48+
*/
4949
subscript(range: Range<Int>) -> [UInt8] {
5050
var dataArray = [UInt8](repeating: 0, count: range.count)
5151
self.copyBytes(to: &dataArray, from: range)
5252

5353
return dataArray
5454
}
55-
55+
/*
5656
subscript(range: Range<Int>) -> [UInt16] {
5757
var dataArray = [UInt16](repeating: 0, count: range.count / 2)
5858
let buffer = UnsafeMutableBufferPointer(start: &dataArray, count: range.count)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// TransmitterVersionRxMessageTests.swift
3+
// xDripG5
4+
//
5+
// Created by Nate Racklyeft on 9/29/16.
6+
// Copyright © 2016 Nathan Racklyeft. All rights reserved.
7+
//
8+
9+
import XCTest
10+
@testable import xDripG5
11+
12+
class TransmitterVersionRxMessageTests: XCTestCase {
13+
14+
func testRxMessage() {
15+
let data = Data(hexadecimalString: "4b0001000011df2900005100037000f00009b6")!
16+
let message = TransmitterVersionRxMessage(data: data)!
17+
18+
XCTAssertEqual(0, message.status)
19+
XCTAssertEqual([1, 0, 0, 17], message.firmwareVersion)
20+
}
21+
22+
}

0 commit comments

Comments
 (0)