Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT: Basic ble & connect flow #8

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from

Conversation

bastiaanv
Copy link
Collaborator

Started basic BLE, with read & write, and connection flow.

TODO's:

  • Add debug view or something to test this
  • Ensure Device name filter is correct at MedtrumKit -> PumpManager -> BluetoothManager line 73
  • Ensure/fix manufacture data from advertising data at MedtrumKit -> PumpManager -> BluetoothManager line 79

closes #2

@bastiaanv bastiaanv requested a review from jbr7rr February 27, 2025 20:41
@bastiaanv bastiaanv self-assigned this Feb 27, 2025
@bastiaanv bastiaanv linked an issue Feb 27, 2025 that may be closed by this pull request
func centralManager(_: CBCentralManager, didFailToConnect peripheral: CBPeripheral, error: Error?) {
log.info("Device connect error, name: \(peripheral.name ?? "<NO_NAME>"), error: \(error!.localizedDescription)")
}
}
Copy link
Owner

@jbr7rr jbr7rr Feb 28, 2025

Choose a reason for hiding this comment

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

You might want to use
func centralManager(_ central: CBCentralManager, willRestoreState dict: [String : Any]) {}

To handle coming back from background, not sure how you handle this in the other loopkit pump drivers though

return
}

// TODO: Need to validate if the device name is always MT
Copy link
Owner

@jbr7rr jbr7rr Feb 28, 2025

Choose a reason for hiding this comment

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

Yes, also ensure it's a perfect match, pump boots up in bootloader mode and advertises as "MTBT" you don't want to connect to that

Copy link
Owner

@jbr7rr jbr7rr Feb 28, 2025

Choose a reason for hiding this comment

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

Another solution is to filter bootloader out by device type:
https://github.com/jbr7rr/insuBox/blob/8f217de4df784e86a49ee380fc07968353325e9b/lib/pump/medtrum_bt/comm/PumpScanner.cpp#L68

In that case you don't have to rely on having to correct device name

// Created by Bastiaan Verhaar on 27/02/2025.
//

class ReadPacket {
Copy link
Owner

@jbr7rr jbr7rr Feb 28, 2025

Choose a reason for hiding this comment

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

Something to consider, In AAPS we had this indeed, In insubox I merged the serialization of the incoming messages in the basePacket as well.

See:
https://github.com/jbr7rr/insuBox/blob/8f217de4df784e86a49ee380fc07968353325e9b/lib/pump/medtrum_bt/comm/packets/MedtrumBasePacket.cpp#L29

It can make the handling of incoming messages, more straightforward, see:
https://github.com/jbr7rr/insuBox/blob/8f217de4df784e86a49ee380fc07968353325e9b/lib/pump/medtrum_bt/MedtrumBTDevice.cpp#L92

// Created by Bastiaan Verhaar on 26/02/2025.
//

class WritePacket {
Copy link
Owner

Choose a reason for hiding this comment

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

Add unit tests for this thing, It can have nasty surprises ;)


let commandType: UInt8 = CommandType.SET_TIME_ZONE

func getRequestBytes() -> Data {
Copy link
Owner

Choose a reason for hiding this comment

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

Ensure you do the workaround here for this issue:
nightscout/AndroidAPS#2831

@jbr7rr
Copy link
Owner

jbr7rr commented Feb 28, 2025

Nice! Good progress!

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.

Setup connection with MedtrumPatch
2 participants