SHARE
TWEET

Untitled

a guest Jul 12th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Return 1 for insulin-related events, 0 for events to skip, -1 on error.
  2. static int decode_history_record(uint8_t *data, int len, int family, history_record_t *r) {
  3.     memset(r, 0, sizeof(*r));
  4.     r->type = data[0];
  5.     r->length = 7;
  6.     switch (r->type) {
  7.     case Bolus:
  8.         if (family <= 22) {
  9.             r->length = 9;
  10.             r->time = decode_time(&data[4]);
  11.             r->insulin = int_to_insulin(data[2], family);
  12.             r->duration = half_hours(data[3]);
  13.         } else {
  14.             r->length = 13;
  15.             r->time = decode_time(&data[8]);
  16.             r->insulin = int_to_insulin(two_byte_be_int(&data[3]), family);
  17.             r->duration = half_hours(data[7]);
  18.         }
  19.         return 1;
  20.     case Prime:
  21.         r->length = 10;
  22.         return 0;
  23.     case Alarm:
  24.         r->length = 9;
  25.         return 0;
  26.     case DailyTotal:
  27.         r->length = family <= 22 ? 7 : 10;
  28.         return 0;
  29.     case BasalProfileBefore:
  30.         r->length = 152;
  31.         return 0;
  32.     case BasalProfileAfter:
  33.         r->length = 152;
  34.         return 0;
  35.     case BGCapture:
  36.         return 0;
  37.     case SensorAlarm:
  38.         r->length = 8;
  39.         return 0;
  40.     case ClearAlarm:
  41.         return 0;
  42.     case ChangeBasalPattern:
  43.         return 0;
  44.     case TempBasalDuration:
  45.         r->time = decode_time(&data[2]);
  46.         r->duration = half_hours(data[1]);
  47.         return 1;
  48.     case ChangeTime:
  49.         return 0;
  50.     case NewTime:
  51.         return 0;
  52.     case LowBattery:
  53.         return 0;
  54.     case BatteryChange:
  55.         return 0;
  56.     case SetAutoOff:
  57.         return 0;
  58.     case PrepareInsulinChange:
  59.         return 0;
  60.     case SuspendPump:
  61.         r->time = decode_time(&data[2]);
  62.         return 1;
  63.     case ResumePump:
  64.         r->time = decode_time(&data[2]);
  65.         return 1;
  66.     case SelfTest:
  67.         return 0;
  68.     case Rewind:
  69.         return 0;
  70.     case ClearSettings:
  71.         return 0;
  72.     case EnableChildBlock:
  73.         return 0;
  74.     case MaxBolus:
  75.         return 0;
  76.     case EnableRemote:
  77.         r->length = 21;
  78.         return 0;
  79.     case MaxBasal:
  80.         return 0;
  81.     case EnableBolusWizard:
  82.         return 0;
  83.     case Unknown2E:
  84.         r->length = 107;
  85.         return 0;
  86.     case BolusWizard512:
  87.         r->length = 19;
  88.         return 0;
  89.     case UnabsorbedInsulin512:
  90.         r->length = data[1];
  91.         return 0;
  92.     case ChangeBGReminder:
  93.         return 0;
  94.     case SetAlarmClockTime:
  95.         return 0;
  96.     case TempBasalRate:
  97.         r->length = 8;
  98.         r->time = decode_time(&data[2]);
  99.         switch (data[7] >> 3) { // temp basal type
  100.         case ABSOLUTE:
  101.             r->insulin = int_to_insulin(((data[7] & 0x7) << 8) | data[1], 23);
  102.             return 1;
  103.         default:
  104.             ESP_LOGE(TAG, "ignoring %3d percent temp basal in pump history at %s", data[1], time_string(r->time));
  105.             return 0;
  106.         }
  107.     case LowReservoir:
  108.         return 0;
  109.     case AlarmClock:
  110.         return 0;
  111.     case ChangeMeterID:
  112.         r->length = 21;
  113.         return 0;
  114.     case BGReceived512:
  115.         r->length = 10;
  116.         return 0;
  117.     case ConfirmInsulinChange:
  118.         return 0;
  119.     case SensorStatus:
  120.         return 0;
  121.     case EnableMeter:
  122.         r->length = 21;
  123.         return 0;
  124.     case BGReceived:
  125.         r->length = 10;
  126.         return 0;
  127.     case MealMarker:
  128.         r->length = 9;
  129.         return 0;
  130.     case ExerciseMarker:
  131.         r->length = 8;
  132.         return 0;
  133.     case InsulinMarker:
  134.         r->length = 8;
  135.         return 0;
  136.     case OtherMarker:
  137.         return 0;
  138.     case EnableSensorAutoCal:
  139.         return 0;
  140.     case ChangeBolusWizardSetup:
  141.         r->length = 39;
  142.         return 0;
  143.     case SensorSetup:
  144.         r->length = family >= 51 ? 41 : 37;
  145.         return 0;
  146.     case Sensor51:
  147.         return 0;
  148.     case Sensor52:
  149.         return 0;
  150.     case ChangeSensorAlarm:
  151.         r->length = 8;
  152.         return 0;
  153.     case Sensor54:
  154.         r->length = 64;
  155.         return 0;
  156.     case Sensor55:
  157.         r->length = 55;
  158.         return 0;
  159.     case ChangeSensorAlert:
  160.         r->length = 12;
  161.         return 0;
  162.     case ChangeBolusStep:
  163.         return 0;
  164.     case BolusWizardSetup:
  165.         r->length = family <= 22 ? 124 : 144;
  166.         return 0;
  167.     case BolusWizard:
  168.         r->length = family <= 22 ? 20 : 22;
  169.         return 0;
  170.     case UnabsorbedInsulin:
  171.         r->length = data[1];
  172.         return 0;
  173.     case SaveSettings:
  174.         return 0;
  175.     case EnableVariableBolus:
  176.         return 0;
  177.     case ChangeEasyBolus:
  178.         return 0;
  179.     case EnableBGReminder:
  180.         return 0;
  181.     case EnableAlarmClock:
  182.         return 0;
  183.     case ChangeTempBasalType:
  184.         return 0;
  185.     case ChangeAlarmType:
  186.         return 0;
  187.     case ChangeTimeFormat:
  188.         return 0;
  189.     case ChangeReservoirWarning:
  190.         return 0;
  191.     case EnableBolusReminder:
  192.         return 0;
  193.     case SetBolusReminderTime:
  194.         r->length = 9;
  195.         return 0;
  196.     case DeleteBolusReminderTime:
  197.         r->length = 9;
  198.         return 0;
  199.     case BolusReminder:
  200.         r->length = 9;
  201.         return 0;
  202.     case DeleteAlarmClockTime:
  203.         return 0;
  204.     case DailyTotal515:
  205.         r->length = 38;
  206.         return 0;
  207.     case DailyTotal522:
  208.         r->length = 44;
  209.         return 0;
  210.     case DailyTotal523:
  211.         r->length = 52;
  212.         return 0;
  213.     case ChangeCarbUnits:
  214.         return 0;
  215.     case BasalProfileStart:
  216.         r->length = 10;
  217.         r->time = decode_time(&data[2]);
  218.         // data[7] = starting half-hour
  219.         r->insulin = int_to_insulin(two_byte_le_int(&data[8]), 23);
  220.         return 1;
  221.     case ConnectOtherDevices:
  222.         return 0;
  223.     case ChangeOtherDevice:
  224.         r->length = 37;
  225.         return 0;
  226.     case ChangeMarriage:
  227.         r->length = 12;
  228.         return 0;
  229.     case DeleteOtherDevice:
  230.         r->length = 12;
  231.         return 0;
  232.     case EnableCaptureEvent:
  233.         return 0;
  234.     default:
  235.         return -1;
  236.     }
  237. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top