Skip to content

Conversation

@Lytrix
Copy link

@Lytrix Lytrix commented Aug 13, 2018

This looks like a lot better PR. ;-)
I've updated cancelDelivery.
Added tests with cancel temp basal and bolus.
Fixed the missing values cancelDelivery variables in the podSessions.

The suspend command still needs to be added into this with this test: 1f 05 b15898b0 03 which I also have ready, but I wanted to make it testable with a 0x19 command as well.

@Lytrix
Copy link
Author

Lytrix commented Aug 29, 2018

I've updated this PR to the latest Omnikit branch to review the sound options for cancelDeliveryType.

It works properly using the Tests commands on a live Pod. I still have some error in Travis to look at, but almost there.

The way I setup the sounds does differ currently with the way it is called on the 0x19 command using beepType = 0x0302.

It is probably better to make one beep method which can be reused in all commands, also to be able to make a setup page to let users choose sound setups for different things. What do you think?

Copy link
Owner

@ps2 ps2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Need to get tests passing too.

public enum CancelType {
case normal
case suspend
public struct BeepType: OptionSet {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BeepType should be an enum, not an OptionSet

@Lytrix
Copy link
Author

Lytrix commented Sep 4, 2018

Let me know if this is ok. Then I will look at combining the same enum beep setup on the 0x19 command.

@Lytrix Lytrix changed the title Added sound options to cancel command Added sound options to cancel and configure alerts command Sep 4, 2018
}

self.beepType = (UInt16(encodedData[4]) << 8) + UInt16(encodedData[5])
self.beepType = BeepType(rawValue: encodedData[4])!
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should throw an exception if the rawValue isn't valid

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have an example how I can assert this? Would be good to write a test to see if it fails on values higher than 8.

Copy link
Owner

@ps2 ps2 Sep 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

guard let beepType = BeepType(rawValue: encodedData[4]) else {
   throw MessageError.unknownValue(value: encodedData[4], typeDescription: "BeepType")
}
self.beepType = beepType

}
data.appendBigEndian(beepType)
data.appendBigEndian(UInt16(beepType.rawValue) << 8 + UInt16(beepRepeat))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these are two bytes, you could just append each one in turn, rather than encoding them into a UInt16, and then splitting them back up into something to be appended to the data object.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, this is a bit overkill.

@Lytrix Lytrix changed the title Added sound options to cancel and configure alerts command Added beepType options to cancel and configure alerts command Sep 4, 2018
data.appendBigEndian(minutes)
}
data.appendBigEndian(UInt16(beepType.rawValue) << 8 + UInt16(beepRepeat))
data.append(UInt8(beepType.rawValue))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beepType.rawValue already is a UInt8

}
data.appendBigEndian(UInt16(beepType.rawValue) << 8 + UInt16(beepRepeat))
data.append(UInt8(beepType.rawValue))
data.append(UInt8(beepRepeat))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you change beepRepeat to a UInt8, then you don't need to worry about casting, and possible errors caused by that (if you cast a number > 255 into a UInt8 you'll get an exception)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was unsure where it is essential to explicitly declare the cast type.

}
let beepTypeBits = encodedData[4]
guard let beepType = BeepType(rawValue: beepTypeBits) else {
throw MessageError.unknownValue(value: beepTypeBits, typeDescription: "beepType")
Copy link
Owner

@ps2 ps2 Sep 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small suggestion: typeDescription is intended to have name of the enum type that we're missing a value for, so "beepType" should be capitalized.

@ps2
Copy link
Owner

ps2 commented Sep 5, 2018

Thanks @Lytrix !

@ps2 ps2 merged commit cbbe193 into ps2:omnikit Sep 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants