示例#1
0
 private static void parse_resync_response(Bytes response, Pod pod)
 {
     if (response[1] == 0x14)
     {
         pod.nonce_syncword = response.Word(2);
     }
     else
     {
         throw new ProtocolException($"Unknown resync request {response} from pod");
     }
 }
示例#2
0
        private static void parse_information_response(Bytes response, Pod pod)
        {
            int i  = 1;
            var rt = response.Byte(i++);

            switch (rt)
            {
            case 0x01:
                pod.state_alert_w278 = response.Word(i);
                i += 2;
                pod.state_alerts = new ushort[]
                {
                    response.Word(i),
                    response.Word(i + 2),
                    response.Word(i + 4),
                    response.Word(i + 6),
                    response.Word(i + 8),
                    response.Word(i + 10),
                    response.Word(i + 12),
                    response.Word(i + 14),
                };
                break;

            case 0x02:
                pod.state_last_updated = DateTime.UtcNow;
                pod.state_faulted      = true;
                pod.state_progress     = (PodProgress)response.Byte(i++);
                parse_delivery_state(pod, response.Byte(i++));
                pod.insulin_canceled       = response.Byte(i++) * 0.05m;
                pod.radio_message_sequence = response.Byte(i++);
                pod.insulin_delivered      = response.Byte(i++) * 0.05m;
                pod.fault_event            = response.Byte(i++);
                pod.fault_event_rel_time   = response.Word(i);
                pod.insulin_reservoir      = response.Word(i + 2) * 0.05m;
                pod.state_active_minutes   = response.Word(i + 4);
                i += 6;
                pod.state_alert        = response.Byte(i++);
                pod.fault_table_access = response.Byte(i++);
                byte f17 = response.Byte(i++);
                pod.fault_insulin_state_table_corruption = f17 >> 7;
                pod.fault_internal_variables             = (f17 & 0x60) >> 6;
                pod.fault_immediate_bolus_in_progress    = (f17 & 0x10) > 0;
                pod.fault_progress_before = (PodProgress)(f17 & 0x0F);
                byte r18 = response.Byte(i++);
                pod.radio_low_gain                    = (r18 & 0xC0) >> 6;
                pod.radio_rssi                        = r18 & 0x3F;
                pod.fault_progress_before2            = (PodProgress)(response.Byte(i++) & 0x0F);
                pod.fault_information_type2_last_word = response.Byte(i++);
                break;

            default:
                throw new ProtocolException($"Failed to parse the information response of type {rt}");
            }
        }