コード例 #1
0
    def encode(self):
        stream = ble_data_types.BleDataStream()

        flags = _GlucoseContextFlags()
        flags.carb_present = self.carbs is not None
        flags.meal_present = self.meal_type is not None
        flags.tester_health_present = self.tester is not None
        flags.exercise_present = self.exercise is not None
        flags.medication_present = self.medication is not None
        if flags.medication_present:
            flags.medication_units = self.medication.units
        flags.hba1c_present = self.hba1c_percent is not None
        flags.extended_flags_present = self.extra_flags is not None

        stream.encode(flags)
        stream.encode(ble_data_types.Uint16, self.sequence_number)

        stream.encode_if(flags.extended_flags_present, ble_data_types.Uint8,
                         self.extra_flags)
        stream.encode_if(flags.carb_present, self.carbs)

        stream.encode_if(flags.meal_present, ble_data_types.Uint8,
                         self.meal_type)
        stream.encode_if(flags.tester_health_present,
                         ble_data_types.DoubleNibble,
                         [self.tester, self.health_status])

        stream.encode_if(flags.exercise_present, self.exercise)

        stream.encode_if(flags.medication_present, self.medication)
        stream.encode_if(flags.hba1c_present, ble_data_types.SFloat,
                         self.hba1c_percent)

        return stream
コード例 #2
0
    def encode(self):
        stream = ble_data_types.BleDataStream()

        # Clamp duration to max 16-bit, max value means overrun
        duration = max(self.duration_seconds, self.EXERCISE_DURATION_OVERRUN)
        stream.encode(ble_data_types.Uint16, duration)
        stream.encode(ble_data_types.Uint8, self.intensity_percent)
        return stream
コード例 #3
0
 def encode(self):
     stream = ble_data_types.BleDataStream()
     stream.encode(ble_data_types.Uint8, self.opcode)
     stream.encode(ble_data_types.Uint8, self.operator)
     if self.filter_type is not None:
         stream.encode(ble_data_types.Uint8, self.filter_type)
         for f in self.filter_params:
             stream.encode(ble_data_types.Uint16, f)
     return stream
コード例 #4
0
 def decode(self, data):
     try:
         stream = ble_data_types.BleDataStream(data)
         return self.ble_type.decode(stream)
     except Exception as e:
         if self.logger:
             self.logger.error(
                 "Failed to decode into {} type, stream: [{}]".format(
                     self.ble_type.__name__, binascii.hexlify(data)))
             self.logger.exception(e)
     return None
コード例 #5
0
 def encode(self):
     stream = ble_data_types.BleDataStream()
     if self.record_count is None:
         stream.encode_multiple(
             [ble_data_types.Uint8, RacpOpcode.response_code],
             [ble_data_types.Uint8, RacpOperator.null],
             [ble_data_types.Uint8, self.request_code],
             [ble_data_types.Uint8, self.response_code])
     else:
         stream.encode_multiple(
             [ble_data_types.Uint8, RacpOpcode.number_of_records_response],
             [ble_data_types.Uint8, RacpOperator.null],
             [ble_data_types.Uint16, self.record_count])
     return stream
コード例 #6
0
    def _read_complete(self, characteristic, event_args):
        """
        :param characteristic:
        :type event_args: blatann.event_args.ReadCompleteEventArgs
        """
        decoded_value = None
        if event_args.status == GattStatusCode.success:
            try:
                stream = ble_data_types.BleDataStream(event_args.value)
                decoded_value = self.data_class.decode(stream)
            except Exception as e:  # TODO not so generic
                logger.error("Service {}, Characteristic {} failed to decode value on read. "
                             "Stream: [{}]".format(self.service.uuid, self.uuid, binascii.hexlify(event_args.value)))
                logger.exception(e)

        decoded_event_args = DecodedReadCompleteEventArgs.from_read_complete_event_args(event_args, decoded_value)
        self._on_read_complete_event.notify(characteristic, decoded_event_args)
コード例 #7
0
    def encode(self):
        stream = ble_data_types.BleDataStream()

        flags = _MeasurementFlags()
        flags.time_offset_present = self.time_offset_minutes is not None
        flags.sample_present = self.sample is not None
        if flags.sample_present:
            flags.concentration_units = int(self.sample.units)
        flags.sensor_status = self.sensor_status is not None
        flags.has_context = self.context is not None

        stream.encode(flags)
        stream.encode(ble_data_types.Uint16, self.sequence_number)
        stream.encode(ble_data_types.DateTime(self.measurement_time))
        stream.encode_if(flags.time_offset_present, ble_data_types.Int16,
                         self.time_offset_minutes)
        stream.encode_if(flags.sample_present, self.sample)
        stream.encode_if(flags.sensor_status, self.sensor_status)

        return stream
コード例 #8
0
 def encode(self):
     stream = ble_data_types.BleDataStream()
     stream.encode(ble_data_types.Uint8, self.type)
     stream.encode(ble_data_types.SFloat, self.value)
     return stream
コード例 #9
0
 def encode(self):
     stream = ble_data_types.BleDataStream()
     stream.encode(ble_data_types.Uint8, self.carb_type)
     stream.encode(ble_data_types.SFloat, self.carbs_grams)
     return stream
コード例 #10
0
 def encode(self):
     stream = ble_data_types.BleDataStream()
     stream.encode(ble_data_types.SFloat, self.value)
     stream.encode(ble_data_types.DoubleNibble,
                   [self.type, self.sample_location])
     return stream