Skip to content

Instantly share code, notes, and snippets.

@ecc1
Created June 30, 2019 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ecc1/ec3182064bcea6be57ed29be156e9ecc to your computer and use it in GitHub Desktop.
Save ecc1/ec3182064bcea6be57ed29be156e9ecc to your computer and use it in GitHub Desktop.
// Return 1 for insulin-related events, 0 for events to skip, -1 on error.
static int decode_history_record(uint8_t *data, int len, int family, history_record_t *r) {
memset(r, 0, sizeof(*r));
r->type = data[0];
r->length = 7;
switch (r->type) {
case Bolus:
if (family <= 22) {
r->length = 9;
r->time = decode_time(&data[4]);
r->insulin = int_to_insulin(data[2], family);
r->duration = half_hours(data[3]);
} else {
r->length = 13;
r->time = decode_time(&data[8]);
r->insulin = int_to_insulin(two_byte_be_int(&data[3]), family);
r->duration = half_hours(data[7]);
}
return 1;
case Prime:
r->length = 10;
return 0;
case Alarm:
r->length = 9;
return 0;
case DailyTotal:
r->length = family <= 22 ? 7 : 10;
return 0;
case BasalProfileBefore:
r->length = 152;
return 0;
case BasalProfileAfter:
r->length = 152;
return 0;
case BGCapture:
return 0;
case SensorAlarm:
r->length = 8;
return 0;
case ClearAlarm:
return 0;
case ChangeBasalPattern:
return 0;
case TempBasalDuration:
r->time = decode_time(&data[2]);
r->duration = half_hours(data[1]);
return 1;
case ChangeTime:
return 0;
case NewTime:
return 0;
case LowBattery:
return 0;
case BatteryChange:
return 0;
case SetAutoOff:
return 0;
case PrepareInsulinChange:
return 0;
case SuspendPump:
r->time = decode_time(&data[2]);
return 1;
case ResumePump:
r->time = decode_time(&data[2]);
return 1;
case SelfTest:
return 0;
case Rewind:
return 0;
case ClearSettings:
return 0;
case EnableChildBlock:
return 0;
case MaxBolus:
return 0;
case EnableRemote:
r->length = 21;
return 0;
case MaxBasal:
return 0;
case EnableBolusWizard:
return 0;
case Unknown2E:
r->length = 107;
return 0;
case BolusWizard512:
r->length = 19;
return 0;
case UnabsorbedInsulin512:
r->length = data[1];
return 0;
case ChangeBGReminder:
return 0;
case SetAlarmClockTime:
return 0;
case TempBasalRate:
r->length = 8;
r->time = decode_time(&data[2]);
switch (data[7] >> 3) { // temp basal type
case ABSOLUTE:
r->insulin = int_to_insulin(((data[7] & 0x7) << 8) | data[1], 23);
return 1;
default:
ESP_LOGE(TAG, "ignoring %3d percent temp basal in pump history at %s", data[1], time_string(r->time));
return 0;
}
case LowReservoir:
return 0;
case AlarmClock:
return 0;
case ChangeMeterID:
r->length = 21;
return 0;
case BGReceived512:
r->length = 10;
return 0;
case ConfirmInsulinChange:
return 0;
case SensorStatus:
return 0;
case EnableMeter:
r->length = 21;
return 0;
case BGReceived:
r->length = 10;
return 0;
case MealMarker:
r->length = 9;
return 0;
case ExerciseMarker:
r->length = 8;
return 0;
case InsulinMarker:
r->length = 8;
return 0;
case OtherMarker:
return 0;
case EnableSensorAutoCal:
return 0;
case ChangeBolusWizardSetup:
r->length = 39;
return 0;
case SensorSetup:
r->length = family >= 51 ? 41 : 37;
return 0;
case Sensor51:
return 0;
case Sensor52:
return 0;
case ChangeSensorAlarm:
r->length = 8;
return 0;
case Sensor54:
r->length = 64;
return 0;
case Sensor55:
r->length = 55;
return 0;
case ChangeSensorAlert:
r->length = 12;
return 0;
case ChangeBolusStep:
return 0;
case BolusWizardSetup:
r->length = family <= 22 ? 124 : 144;
return 0;
case BolusWizard:
r->length = family <= 22 ? 20 : 22;
return 0;
case UnabsorbedInsulin:
r->length = data[1];
return 0;
case SaveSettings:
return 0;
case EnableVariableBolus:
return 0;
case ChangeEasyBolus:
return 0;
case EnableBGReminder:
return 0;
case EnableAlarmClock:
return 0;
case ChangeTempBasalType:
return 0;
case ChangeAlarmType:
return 0;
case ChangeTimeFormat:
return 0;
case ChangeReservoirWarning:
return 0;
case EnableBolusReminder:
return 0;
case SetBolusReminderTime:
r->length = 9;
return 0;
case DeleteBolusReminderTime:
r->length = 9;
return 0;
case BolusReminder:
r->length = 9;
return 0;
case DeleteAlarmClockTime:
return 0;
case DailyTotal515:
r->length = 38;
return 0;
case DailyTotal522:
r->length = 44;
return 0;
case DailyTotal523:
r->length = 52;
return 0;
case ChangeCarbUnits:
return 0;
case BasalProfileStart:
r->length = 10;
r->time = decode_time(&data[2]);
// data[7] = starting half-hour
r->insulin = int_to_insulin(two_byte_le_int(&data[8]), 23);
return 1;
case ConnectOtherDevices:
return 0;
case ChangeOtherDevice:
r->length = 37;
return 0;
case ChangeMarriage:
r->length = 12;
return 0;
case DeleteOtherDevice:
r->length = 12;
return 0;
case EnableCaptureEvent:
return 0;
default:
return -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment