Esempio n. 1
0
        private static PdmMessage bolus_message(ushort pulse_count,
                                                int pulse_speed = 16, int delivery_delay = 2)
        {
            var commandBody     = new Bytes().Append(0x02);
            var bodyForChecksum = new Bytes().Append(0x01);
            var pulse_span      = (ushort)(pulse_speed * pulse_count);

            bodyForChecksum.Append(pulse_span);
            bodyForChecksum.Append(pulse_count);
            bodyForChecksum.Append(pulse_count);
            var checksum = getChecksum(bodyForChecksum);

            commandBody.Append(checksum);
            commandBody.Append(bodyForChecksum);

            var msg = new PdmMessage(PdmRequest.InsulinSchedule, commandBody);

            commandBody = new Bytes().Append(0x00);
            ushort p10 = (ushort)(pulse_count * 10);

            commandBody.Append(p10);
            uint dd = (uint)delivery_delay * (uint)100000;

            commandBody.Append(dd);
            commandBody.Append(new byte[] { 0, 0, 0, 0, 0, 0 });
            msg.add_part(PdmRequest.BolusSchedule, commandBody);
            return(msg);
        }
Esempio n. 2
0
        public static PdmMessage request_temp_basal(decimal basal_rate_iuhr, decimal duration_hours)
        {
            var half_hour_count = (int)(duration_hours * 2.0m);
            var hh_units        = new decimal[half_hour_count];

            for (int i = 0; i < half_hour_count; i++)
            {
                hh_units[i] = basal_rate_iuhr / 2.0m;
            }

            var pulseList = getPulsesForHalfHours(hh_units);
            var iseList   = getInsulinScheduleTableFromPulses(pulseList);

            var iseBody   = getBodyFromTable(iseList);
            var pulseBody = getBodyFromTable(pulseList);

            var cmd_body = new Bytes();

            cmd_body.Append(0x01);

            var body_checksum = new Bytes();

            body_checksum.Append((byte)half_hour_count);
            ushort b1 = 0x3840;

            body_checksum.Append(b1);
            body_checksum.Append(pulseList[0]);
            var checksum = getChecksum(new Bytes(body_checksum, pulseBody));

            cmd_body.Append(checksum);
            cmd_body.Append(body_checksum);
            cmd_body.Append(iseBody);

            var msg = new PdmMessage(PdmRequest.InsulinSchedule, cmd_body);

            byte reminders = 0;

            //#if confidenceReminder:
            //# reminders |= 0x40

            cmd_body = new Bytes();
            cmd_body.Append(reminders).Append(0x00);
            var pulseEntries = getPulseIntervalEntries(hh_units);

            var firstPte = pulseEntries[0];

            cmd_body.Append(firstPte.Item1);
            cmd_body.Append(firstPte.Item2);

            foreach (var pte in pulseEntries)
            {
                cmd_body.Append(pte.Item1);
                cmd_body.Append(pte.Item2);
            }

            msg.add_part(PdmRequest.TempBasalSchedule, cmd_body);
            return(msg);
        }
Esempio n. 3
0
 public MessageExchange(PdmMessage pdmMessage, IPacketRadio packetRadio, Pod pod)
 {
     this.PdmMessage  = pdmMessage;
     this.PacketRadio = packetRadio;
     this.Pod         = pod;
 }
Esempio n. 4
0
        public static PdmMessage request_set_basal_schedule(decimal[] schedule, ushort hour, ushort minute, ushort second)
        {
            var halved_schedule = new decimal[48];

            for (int i = 0; i < 47; i++)
            {
                halved_schedule[i] = schedule[i] / 2m;
            }

            int    current_hh      = hour * 2;
            ushort seconds_past_hh = 0;

            if (minute < 30)
            {
                seconds_past_hh = (ushort)(minute * 60 + second);
            }
            else
            {
                seconds_past_hh = (ushort)((minute - 30) * 60 + second);
            }

            var seconds_to_hh  = (ushort)(1800 - seconds_past_hh);
            var seconds_to_hh8 = (ushort)(seconds_to_hh * 8);

            var pulse_list = getPulsesForHalfHours(halved_schedule);
            var ise_list   = getInsulinScheduleTableFromPulses(pulse_list);
            var ise_body   = getBodyFromTable(ise_list);
            var pulse_body = getBodyFromTable(pulse_list);

            var command_body  = new Bytes(0);
            var body_checksum = new Bytes((byte)current_hh);

            var current_hh_pulse_count = pulse_list[current_hh];
            var remaining_pulse_count  = (ushort)(current_hh_pulse_count * seconds_to_hh / 1800);

            body_checksum.Append(seconds_to_hh8);
            body_checksum.Append(remaining_pulse_count);

            command_body.Append(getChecksum(new Bytes(body_checksum, pulse_body)));
            command_body.Append(body_checksum);
            command_body.Append(ise_body);

            var msg = new PdmMessage(PdmRequest.InsulinSchedule, command_body);

            command_body = new Bytes(new byte[] { 0, 0 });

            var pulse_entries = getPulseIntervalEntries(halved_schedule);

            for (int i = 0; i < pulse_entries.Length; i++)
            {
                var pti      = pulse_entries[i];
                var pulses10 = pti.Item1;
                var interval = pti.Item2;
                var indices  = pti.Item3;

                var ii = Array.IndexOf <int>(indices, current_hh);
                if (ii >= 0)
                {
                    command_body.Append((byte)i);
                    var pulses_past_intervals          = (ushort)((uint)ii * (uint)1800000000 / (uint)interval);
                    var pulses_past_this_interval      = (ushort)((uint)seconds_past_hh * (uint)1000000 / (uint)interval + 1);
                    var remaining_pulses_this_interval = (ushort)(pulses10 - pulses_past_this_interval - pulses_past_intervals);
                    var microseconds_to_next_interval  = (uint)interval - ((uint)seconds_past_hh * (uint)1000000 % (uint)interval);

                    command_body.Append(remaining_pulses_this_interval);
                    command_body.Append(microseconds_to_next_interval);
                    break;
                }
            }

            for (int i = 0; i < pulse_entries.Length; i++)
            {
                var pti      = pulse_entries[i];
                var pulses10 = pti.Item1;
                var interval = pti.Item2;

                command_body.Append(pulses10);
                command_body.Append(interval);
            }

            msg.add_part(PdmRequest.BasalSchedule, command_body);
            return(msg);
        }