Reading data using the IEEE 11073 PHD (Personal Health Device) standards

I have been having a fun couple of days trawling through the IEEE 11073 specs (no, really!) to implement a new USB driver for a Roche blood glucose meter. This is the first meter I've worked with that fully adheres to the standards on all the protocol layers, from using the USB Personal Healthcare Device Class specification on the transport layer, to using the ISO/IEEE 11073-20601 and 11073-10417 standards that describe the data model.

So far I'm quite impressed with the IEEE 11073 standard. Instead of forcing a manufacturer to use a specific format to describe blood glucose readings, it allows for the device to specify an extended configuration. Such a configuration, sent by the device, describes the format in which to expect the readings, for example a timestamps of eight bytes followed by an observation value of two bytes and measurement status of two bytes.

I've just parsed the Roche meter's extended configuration by hand and it goes into a lot of detail, even describing if a measurement is measured (e.g. blood glucose) or manual (e.g. meal context).

On the transport layer, there was a small hiccup as I realised two different Roche glucose meters use different USB endpoints. I then discovered that you can actually find out what the endpoint numbers are for the device you're connected to by looking at the configuration descriptor. The trick is that you needs to look in alternates:

device = await navigator.usb.requestDevice({
  filters: [{
    vendorId: VENDOR_ID
  }]
});

const ep =  device.configuration.interfaces[0].alternates[0].endpoints[0].endpointNumber;

Now, off to parse the MDS (Medical Device System) attributes, which includes things like the model number, serial number and device time.