public override void OnCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { var record = new BloodPressureData(); var offset = 0; Integer flags = characteristic.GetIntValue(GattFormat.Uint8, offset++); // See BPMManagerCallbacks.UNIT_* for unit options bool timestampPresent = ((int)flags & 0x02) > 0; bool pulseRatePresent = ((int)flags & 0x04) > 0; // following bytes - systolic, diastolic and mean arterial pressure record.Systolic = characteristic.GetFloatValue(GattFormat.Sfloat, offset).FloatValue(); record.Diastolic = characteristic.GetFloatValue(GattFormat.Sfloat, offset + 2) .FloatValue(); offset += 6; if (timestampPresent) { record.RecordDateTime = new DateTime( characteristic.GetIntValue(GattFormat.Uint16, offset).IntValue(), characteristic.GetIntValue(GattFormat.Uint8, offset + 2).IntValue(), characteristic.GetIntValue(GattFormat.Uint8, offset + 3).IntValue(), characteristic.GetIntValue(GattFormat.Uint8, offset + 4).IntValue(), characteristic.GetIntValue(GattFormat.Uint8, offset + 5).IntValue(), characteristic.GetIntValue(GattFormat.Uint8, offset + 6).IntValue()); offset += 7; } if (pulseRatePresent) { record.PulseRate = characteristic.GetFloatValue(GattFormat.Sfloat, offset).FloatValue(); } Records.Add(record); }
public override void OnCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { if (!BLEHelpers.UuidGlucMeasurementChar.Equals(characteristic.Uuid)) { return; } var offset = 0; int flags = characteristic.GetIntValue(GattFormat.Uint8, offset).IntValue(); offset += 1; bool timeOffsetPresent = (flags & 0x01) > 0; bool typeAndLocationPresent = (flags & 0x02) > 0; bool sensorStatusAnnunciationPresent = (flags & 0x08) > 0; // create and fill the new record _record = new GlucoseDeviceData { SequenceNumber = characteristic.GetIntValue(GattFormat.Uint16, offset).IntValue() }; offset += 2; int year = characteristic.GetIntValue(GattFormat.Uint16, offset).IntValue(); int month = characteristic.GetIntValue(GattFormat.Uint8, offset + 2).IntValue(); int day = characteristic.GetIntValue(GattFormat.Uint8, offset + 3).IntValue(); int hours = characteristic.GetIntValue(GattFormat.Uint8, offset + 4).IntValue(); int minutes = characteristic.GetIntValue(GattFormat.Uint8, offset + 5).IntValue(); int seconds = characteristic.GetIntValue(GattFormat.Uint8, offset + 6).IntValue(); offset += 7; var calendar = Calendar.Instance; calendar.Set(year, month, day, hours, minutes, seconds); if (timeOffsetPresent) { characteristic.GetIntValue(GattFormat.Uint16, offset).IntValue(); offset += 2; } if (typeAndLocationPresent) { _record.GlucoseConcentration = characteristic.GetFloatValue(GattFormat.Sfloat, offset).FloatValue(); offset += 3; } if (sensorStatusAnnunciationPresent) { characteristic.GetIntValue(GattFormat.Uint16, offset).IntValue(); } gatt.Disconnect(); }
public sealed override void BuildCharacteristic(BluetoothGattCharacteristic characteristic) { if (!characteristic.Uuid.Equals(Uuid)) { throw new GattCharactersticMismatch(this, characteristic.Uuid); } var bytes = characteristic.GetValue(); if (bytes == null) { return; } //1 bit per flag, as a boolean TimeOffsetPresent = bytes[0].BitAt(0); GlucoseConcentrationPresent = bytes[0].BitAt(1); _glucoseConcentrationUnits = bytes[0].BitAt(2); SensorStatusAnnunciationPresent = bytes[0].BitAt(3); ContextInformationFollows = bytes[0].BitAt(4); SequenceNumber = characteristic.GetIntValue(GattFormat.Uint16, 1).IntValue(); _baseTime.ConvertFromCharacteristicByBytes(bytes.SubarrayAt(3, 9)); //7 bytes for the date. BaseTime = _baseTime.Date; TimeOffset = characteristic.GetIntValue(GattFormat.Sint16, 10).IntValue(); var glcConcentration = characteristic.GetFloatValue(GattFormat.Sfloat, 12).FloatValue(); if (_glucoseConcentrationUnits) { GlucoseConcentration = Math.Round(glcConcentration * 100000 / MmollToMgdl, 1); } else { GlucoseConcentration = Math.Round(glcConcentration * 1000 * MmollToMgdl, 1); } Type = (GlucoseTypes)bytes.SubarrayAt(14, 14).ToInt16().NibbleAt(false); SampleLocation = (GlucoseSampleLocation)bytes.SubarrayAt(14, 14).ToInt16().NibbleAt(true); //need a nibble at method //SensorStatusAnnunciation = bytes.SubarrayAt(17, 19); }
public override void BuildCharacteristic(BluetoothGattCharacteristic characteristic) { if (!characteristic.Uuid.Equals(Uuid)) { throw new GattCharactersticMismatch(this, characteristic.Uuid); } var bytes = characteristic.GetValue(); if (bytes == null) { return; } var offset = 0; //1 bit per flag, as a boolean CarbohydratePresent = bytes[0].BitAt(0); MealPresent = bytes[0].BitAt(1); TesterHealthPresent = bytes[0].BitAt(2); ExercisePresent = bytes[0].BitAt(3); MedicationPresent = bytes[0].BitAt(4); _medicationUnitsValue = bytes[0].BitAt(5); HbA1cPresent = bytes[0].BitAt(6); ExtendedFlags = bytes[0].BitAt(7); offset++; SequenceNumber = characteristic.GetIntValue(GattFormat.Uint16, offset).IntValue(); if (CarbohydratePresent) { offset++; CarbohydrateId = (CarbohydrateTypes)characteristic.GetIntValue(GattFormat.Uint8, offset).IntValue(); offset++; CarbohydrateUnits = characteristic.GetFloatValue(GattFormat.Sfloat, offset).FloatValue(); offset++; } if (MealPresent) { offset++; Meal = (MealTypes)characteristic.GetIntValue(GattFormat.Uint8, offset).IntValue(); } if (TesterHealthPresent) { offset++; Tester = (TesterTypes)bytes.SubarrayAt(offset, offset).ToInt16().NibbleAt(true); Health = (HealthTypes)bytes.SubarrayAt(offset, offset).ToInt16().NibbleAt(false); } if (ExercisePresent) { offset++; ExerciseDuration = bytes.SubarrayAt(offset, offset + 1).ToUInt16(); offset++; ExerciseIntensity = (ushort)characteristic.GetIntValue(GattFormat.Uint8, offset).ShortValue(); } if (MedicationPresent) { offset++; MedicationId = (MedicationTypes)characteristic.GetIntValue(GattFormat.Uint8, offset).IntValue(); offset++; MedicationUnits = characteristic.GetFloatValue(GattFormat.Sfloat, offset).FloatValue(); offset++; } if (HbA1cPresent) { offset++; HbA1c = characteristic.GetFloatValue(GattFormat.Sfloat, offset).FloatValue(); } }