Skip to content

partector_ble_decoder_aux

PartectorBleDecoderAux

Bases: PartectorBleDecoderBlueprint

Decode the std advertisement data from the Partector device.

Source code in src/naneos/partector_ble/decoder/partector_ble_decoder_aux.py
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
class PartectorBleDecoderAux(PartectorBleDecoderBlueprint):
    """
    Decode the std advertisement data from the Partector device.
    """

    OFFSET_CORONA_VOLTAGE = slice(0, 2)
    OFFSET_DIFFUSION_CURRENT = slice(2, 4)
    OFFSET_DEPOSITION_VOLTAGE = slice(4, 6)
    OFFSET_FLOW_FROM_DP = slice(6, 8)
    OFFSET_AMBIENT_PRESSURE = slice(8, 10)
    OFFSET_EM_AMPLITUDE_1 = slice(10, 12)
    OFFSET_EM_AMPLITUDE_2 = slice(12, 14)
    OFFSET_EM_GAIN_1 = slice(14, 16)
    OFFSET_EM_GAIN_2 = slice(16, 18)
    OFFSET_DIFFUSION_CURRENT_OFFSET = slice(18, 20)

    FACTOR_DIFFUSION_CURRENT = 0.01

    # == External used methods =====================================================================
    @classmethod
    def decode(
        cls, data: bytes, data_structure: Optional[NaneosDeviceDataPoint] = None
    ) -> NaneosDeviceDataPoint:
        """
        Decode the auxiliary characteristic data from the Partector device.
        """
        decoded_data = NaneosDeviceDataPoint(
            corona_voltage=cls._get_corona_voltage(data),
            diffusion_current=cls._get_diffusion_current(data),
            deposition_voltage=cls._get_deposition_voltage(data),
            flow_from_dp=cls._get_flow_from_dp(data),
            ambient_pressure=cls._get_ambient_pressure(data),
            electrometer_1_amplitude=cls._get_em_amplitude_1(data),
            electrometer_2_amplitude=cls._get_em_amplitude_2(data),
            electrometer_1_gain=cls._get_em_gain_1(data),
            electrometer_2_gain=cls._get_em_gain_2(data),
            diffusion_current_offset=cls._get_diffusion_current_offset(data),
        )

        if not data_structure:
            return decoded_data

        # Fill the given data_structure with the decoded data
        for field in NaneosDeviceDataPoint.BLE_AUX_FIELD_NAMES:
            setattr(data_structure, field, getattr(decoded_data, field))
        return data_structure

    # == Helpers ===================================================================================
    @classmethod
    def _get_corona_voltage(cls, data: bytes) -> float:
        """
        Get the corona voltage from the advertisement data.
        """
        val = float(int.from_bytes(data[cls.OFFSET_CORONA_VOLTAGE], byteorder="little"))
        return val

    @classmethod
    def _get_diffusion_current(cls, data: bytes) -> float:
        """
        Get the diffusion current from the advertisement data.
        """
        val = float(int.from_bytes(data[cls.OFFSET_DIFFUSION_CURRENT], byteorder="little"))
        return val * cls.FACTOR_DIFFUSION_CURRENT

    @classmethod
    def _get_deposition_voltage(cls, data: bytes) -> float:
        """
        Get the deposition voltage from the advertisement data.
        """
        val = float(int.from_bytes(data[cls.OFFSET_DEPOSITION_VOLTAGE], byteorder="little"))
        return val

    @classmethod
    def _get_flow_from_dp(cls, data: bytes) -> float:
        """
        Get the flow from DP from the advertisement data.
        """
        val = float(int.from_bytes(data[cls.OFFSET_FLOW_FROM_DP], byteorder="little"))
        return val

    @classmethod
    def _get_ambient_pressure(cls, data: bytes) -> float:
        """
        Get the ambient pressure from the advertisement data.
        """
        val = float(int.from_bytes(data[cls.OFFSET_AMBIENT_PRESSURE], byteorder="little"))
        return val

    @classmethod
    def _get_em_amplitude_1(cls, data: bytes) -> float:
        """
        Get the EM amplitude 1 from the advertisement data.
        """
        val = float(int.from_bytes(data[cls.OFFSET_EM_AMPLITUDE_1], byteorder="little"))
        return val

    @classmethod
    def _get_em_amplitude_2(cls, data: bytes) -> float:
        """
        Get the EM amplitude 2 from the advertisement data.
        """
        val = float(int.from_bytes(data[cls.OFFSET_EM_AMPLITUDE_2], byteorder="little"))
        return val

    @classmethod
    def _get_em_gain_1(cls, data: bytes) -> float:
        """
        Get the EM gain 1 from the advertisement data.
        """
        val = float(int.from_bytes(data[cls.OFFSET_EM_GAIN_1], byteorder="little"))
        return val

    @classmethod
    def _get_em_gain_2(cls, data: bytes) -> float:
        """
        Get the EM gain 2 from the advertisement data.
        """
        val = float(int.from_bytes(data[cls.OFFSET_EM_GAIN_2], byteorder="little"))
        return val

    @classmethod
    def _get_diffusion_current_offset(cls, data: bytes) -> float:
        """
        Get the diffusion current offset from the advertisement data.
        """
        val = float(int.from_bytes(data[cls.OFFSET_DIFFUSION_CURRENT_OFFSET], byteorder="little"))
        return val

decode(data, data_structure=None) classmethod

Decode the auxiliary characteristic data from the Partector device.

Source code in src/naneos/partector_ble/decoder/partector_ble_decoder_aux.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
@classmethod
def decode(
    cls, data: bytes, data_structure: Optional[NaneosDeviceDataPoint] = None
) -> NaneosDeviceDataPoint:
    """
    Decode the auxiliary characteristic data from the Partector device.
    """
    decoded_data = NaneosDeviceDataPoint(
        corona_voltage=cls._get_corona_voltage(data),
        diffusion_current=cls._get_diffusion_current(data),
        deposition_voltage=cls._get_deposition_voltage(data),
        flow_from_dp=cls._get_flow_from_dp(data),
        ambient_pressure=cls._get_ambient_pressure(data),
        electrometer_1_amplitude=cls._get_em_amplitude_1(data),
        electrometer_2_amplitude=cls._get_em_amplitude_2(data),
        electrometer_1_gain=cls._get_em_gain_1(data),
        electrometer_2_gain=cls._get_em_gain_2(data),
        diffusion_current_offset=cls._get_diffusion_current_offset(data),
    )

    if not data_structure:
        return decoded_data

    # Fill the given data_structure with the decoded data
    for field in NaneosDeviceDataPoint.BLE_AUX_FIELD_NAMES:
        setattr(data_structure, field, getattr(decoded_data, field))
    return data_structure