Example #1
0
 def getData(self):
     data = self.data
     if len(data) < 4:
         return bytearray(data)
     begin = lib.BangInt(data[0:2])
     end = lib.BangInt(data[2:4])
     return dict(begin=begin, end=end)
Example #2
0
  def __init__ (self, raw):
    data, crc = raw[0:1022], raw[1022:]
    computed = lib.CRC16CCITT.compute(bytearray(data))
    if lib.BangInt(crc) != computed:
      assert lib.BangInt(crc) == computed, "CRC does not match page data"

    self.raw = raw
    self.clean(data)
Example #3
0
 def getData(self):
     data = self.data
     log.info("READ totals today:\n%s" % lib.hexdump(data))
     totals = {
         'today': lib.BangInt(data[0:2]) / 10.0,
         'yesterday': lib.BangInt(data[2:4]) / 10.0
     }
     return totals
Example #4
0
 def getData(self):
   data = self.data
   temp = { 0: 'absolute', 1: 'percent' }[self.data[0]]
   status = dict(temp=temp)
   if temp is 'absolute':
     rate = lib.BangInt(data[2:4])/40.0
     duration = lib.BangInt(data[4:6])
     status.update(rate=rate, duration=duration)
   if temp is 'percent':
     rate = int(data[1])
     duration = lib.BangInt(data[4:6])
     status.update(rate=rate, duration=duration)
   log.info("READ temporary basal:\n%s" % lib.hexdump(data))
   return status
Example #5
0
 def getData(self):
   data = self.data
   bd = bytearray(data)
   volt = lib.BangInt((bd[1], bd[2]))
   indicator = bd[0]
   battery = {'status': {0: 'normal', 1: 'low'}[indicator], 'voltage': volt/100.0 }
   return battery
Example #6
0
  def getData(self):
    values = super(ReadSettings523, self).getData()
    data = self.data

    values['maxBasal'] = lib.BangInt(data[7:9]) / 40.0
    values['maxBolus'] = data[6]/ 10.0

    return values
Example #7
0
    def parse(self, raw):
        """
    Detect BadCRC here.  Also, look for eod set.
    """
        """
    log.info('readData validating remote raw[ack]: %02x' % raw[0])
    log.info('readData; foreign raw should be at least 14 bytes? %s %s' % (len(raw), len(raw) > 14))
    log.info('readData; raw[retries] %s' % int(raw[3]))
    dl_status = int(raw[0])
    if dl_status != 0x02: # this differs from the others?
      raise BadDeviceCommError("bad dl raw! %r" % raw)
      assert (int(raw[0]) == 2), repr(raw)
    # raw[1] != 0 # interface number !=0
    # raw[2] == 5 # timeout occurred
    # raw[2] == 2 # NAK
    # raw[2] # should be within 0..4
    log.info("readData ACK")
    lb, hb    = raw[5] & 0x7F, raw[6]
    self.eod  = (raw[5] & 0x80) > 0
    """
        lb, hb = raw[5] & 0x7F, raw[6]
        self.eod = (raw[5] & 0x80) > 0
        resLength = lib.BangInt((lb, hb))
        # we don't really care about the length
        #assert resLength < 64, ("cmd low byte count:\n%s" % lib.hexdump(raw))

        data = raw[13:13 + resLength]
        self.packet = data
        log.info('%s:eod:found eod (%s)' % (self, self.eod))
        log.info('found packet len(%s), link expects(%s)' %
                 (len(self.packet), resLength))
        assert len(data) == resLength
        head = raw[13:]
        crc = raw[-1]
        # crc check
        if crc == 0 and len(data) > 1:
            log.warn('bad zero CRC?')
        expected_crc = CRC8(data)
        if crc != expected_crc:
            msg = ':'.join([
                'ReadRadio:BAD ACK:found raw[crc]: %#04x' % (crc),
                'expected_crc(data): %#04x' % (expected_crc),
                'raw:\n%s\n' % (lib.hexdump(raw)),
                'head:\n%s\n' % (lib.hexdump(head)),
                'data:\n%s\n' % (lib.hexdump(data))
            ])
            log.info(msg)
            log.info(
                "XXX:IGNORE:BadCRC:returning empty message, sleep .100, avoid errors."
            )
            time.sleep(.100)
            return bytearray()
            raise BadCRC(msg)
        assert crc == expected_crc
        return data
Example #8
0
    def record_error(self, result):
        self.error = True
        self.ack = result[0]  # 0 indicates success
        # believe success = result[1] # 'U' or 'f'
        self.status = result[2]
        lb, hb = result[3], result[4]
        self.size = lib.BangInt((lb, hb))

        if self.ack == 0 and (self.status & 0x1) > 0:
            self.error = False
        self.set_reason(self.ack)
Example #9
0
 def decode(self):
     self.parse_time()
     temp = {0: 'absolute', 1: 'percent'}[(self.body[0] >> 3)]
     status = dict(temp=temp)
     if temp is 'absolute':
         rate = lib.BangInt([self.body[0] & 0x7, self.head[1]]) / 40.0
         status.update(rate=rate)
     if temp is 'percent':
         rate = int(self.head[1])
         status.update(rate=rate)
     return status
Example #10
0
 def getData(self):
   data = self.data
   d = {
     'hour'  : int(data[0]),
     'minute': int(data[1]),
     'second': int(data[2]),
     # XXX
     'year'  : lib.BangInt([data[3], data[4]]),
     'month' : int(data[5]),
     'day'   : int(data[6]),
   }
   return "{year:#04}-{month:#02}-{day:#02}T{hour:#02}:{minute:#02}:{second:#02}".format(**d)
Example #11
0
 def decode_ratios(klass, data, units=0):
     schedule = []
     for x in range(len(data) / 3):
         start = x * 3
         end = start + 3
         (i, q, r) = data[start:end]
         ratio = r / 10.0
         if q:
             ratio = lib.BangInt([q, r]) / 1000.0
         schedule.append(
             dict(x=x, i=i, offset=i * 30, q=q, ratio=ratio, r=r))
     return schedule
Example #12
0
def decode_carb_ratios (data):
  ratios = [ ]
  for x in range(8):
    start = x * 3
    end = start + 3
    (offset, q, r) = data[start:end]
    ratio = r/10.0
    if q:
      ratio = lib.BangInt([q, r]) / 1000.0
    ratios.append(dict(i=x, offset=offset*30, q=q, _offset=offset,
                       ratio=ratio, r=r))
  return ratios
Example #13
0
  def decode(self):
    super(AlarmSensor, self).decode()

    alarm_type = self.head[1]

    decoded_dict = {
      'alarm_type': alarm_type,
      'alarm_description': self.alarm_types.get(alarm_type, 'Unknown sensor alarm ({})'.format(alarm_type))
    }

    if alarm_type in (101, 102,):
      year_bits = extra_year_bits(self.date[4])
      decoded_dict['amount'] = int(lib.BangInt([year_bits[0], self.head[2]]))

    return decoded_dict
Example #14
0
  def getData(self):
    data = self.data
    log.info("READ pump settings:\n%s" % lib.hexdump(data))

    if len(data) < 2:
      log.info("pump settings: unsupported version, sorry")
      return data

    auto_off_duration_hrs = data[0]
    alarm = self.alarm(data[1])
    audio_bolus_enable = data[2] == 1
    audio_bolus_size = 0
    if audio_bolus_enable:
      audio_bolus_size = data[3] / 10.0
    variable_bolus_enable = data[4] == 1
    #MM23 is different
    maxBolus = data[5]/ 10.0
    # MM512 and up
    maxBasal = lib.BangInt(data[6:8]) / 40.0
    timeformat = data[8]
    insulinConcentration = {0: 100, 1: 50}[data[9]]
    patterns_enabled = data[10] == 1
    selected_pattern = data[11]
    rf_enable = data[12] == 1
    block_enable = data[13] == 1
    temp_basal = self.temp_basal_type(data[14:16])
    paradigm_enabled = data[16]
    """
    # MM12
    insulin_action_type = data[17] == 0 and 'Fast' or 'Regular'
    """
    #MM15
    # insulin_action_type = data[17]
    insulin_action_curve = data[17]
    low_reservoir_warn_type = data[18]
    low_reservoir_warn_point = data[19]
    keypad_lock_status = data[20]

    values = locals( )
    # safety
    values.pop('self')
    values.pop('data')

    return values
Example #15
0
 def getData(self):
     units = self.data[0]
     labels = {1: 'grams', 2: 'exchanges'}
     fixed = self.data[1]
     data = self.data[2:2 + (fixed * 3)]
     return dict(schedule=self.decode_ratios(data, units=units),
                 units=labels.get(units),
                 first=self.data[0])
     # xxx: remove
     schedule = []
     for x in range(len(data) / 3):
         start = x * 3
         end = start + 3
         (i, q, r) = data[start:end]
         ratio = r / 10.0
         if q:
             ratio = lib.BangInt([q, r]) / 1000.0
         schedule.append(
             dict(x=x, i=i, offset=i * 30, q=q, ratio=ratio, r=r))
     return dict(schedule=schedule,
                 units=labels.get(units),
                 first=self.data[0])
Example #16
0
 def getData(self):
     data = self.data
     rate = lib.BangInt(data[2:4]) / 40.0
     duration = lib.BangInt(data[4:6])
     log.info("READ temporary basal:\n%s" % lib.hexdump(data))
     return {'rate': rate, 'duration': duration}
Example #17
0
 def getData(self):
     data = self.data
     log.info("READ remaining insulin:\n%s" % lib.hexdump(data))
     return lib.BangInt(data[0:2]) / 10.0
Example #18
0
 def getData(self):
   data = self.data
   log.info("READ remaining insulin:\n%s" % lib.hexdump(data))
   return lib.BangInt(data[self.startByte:self.endByte])/self.basalStrokes
Example #19
0
    def decode(self):
        super(JournalEntryMealMarker, self).decode()

        return dict(carb_input=int(lib.BangInt([self.head[1], self.body[0]])))