def test_chain_setup(self): self.expected_cmds = [[0x09, 0x02, 0x01, 0x01, 0xff, 0x00, 0x02, 0x10], [ 0x09, 0x02, 0x09, 0x03, 0x00, 0x00, 0x09, 0x03, 0x04, 0x02, 0x00, 0x00, 0x00, 0x00 ], [ 0x09, 0x02, 0x09, 0x03, 0x01, 0x60, 0x06, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 ], [ 0x09, 0x02, 0x09, 0x03, 0x01, 0x60, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ], [0x0a, 0x02, 0x09, 0x03, 0x02, 0x02, 0x03, 0x0f], [ 0x0a, 0x03, 0x02, 0x02, 0x10, 0x10, 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, 0xe8, 0x03, 0x00, 0x00, 0xff ], [0x0a, 0x02, 0x09, 0x03, 0x02, 0x02, 0x01, 0x01], [0x0a, 0x03, 0x01], [0x0a, 0x02, 0x09, 0x03, 0x03, 0x02, 0x02, 0x01], [0x0a, 0x03, 0x01]] self.cmds_recorded_handler = Fn_VoidPtr_Int(self.cmds_recorded) self.counter_handler = Fn_VoidPtr(self.counter_processor_created) self.math_handler = Fn_VoidPtr(self.math_processor_created) switch_signal = self.libmetawear.mbl_mw_switch_get_state_data_signal( self.board) self.libmetawear.mbl_mw_dataprocessor_counter_create( switch_signal, self.counter_handler)
def test_number_to_firmware(self): expected = [ 0x09, 0x02, 0x09, 0x03, 0x00, 0x20, 0x06, 0x00, 0x04, 0x00, 0xa0, 0x0f, 0x00, 0x00 ] comp_created_ptr = Fn_VoidPtr( lambda comp: self.assertEqual(self.command, expected)) rss_created_ptr = Fn_VoidPtr( lambda rms: self. libmetawear.mbl_mw_dataprocessor_comparator_create( rms, Comparator.OPERATION_GT, 250.0, comp_created_ptr)) signal = self.libmetawear.mbl_mw_mag_bmm150_get_b_field_data_signal( self.board) self.libmetawear.mbl_mw_dataprocessor_rss_create( signal, rss_created_ptr)
def gt_counter_comparator_processor_created(self, signal): self.gt_comparator_counter_comparator = signal self.lte_comparator_handler = Fn_VoidPtr( self.lte_comparator_processor_created) self.libmetawear.mbl_mw_dataprocessor_comparator_create( self.abs_ref_offset, Comparator.OPERATION_LTE, 0.0, self.lte_comparator_handler)
def comparator_odd_created(self, signal): self.comp_odd_signal = signal self.comparator_even_handler = Fn_VoidPtr(self.comparator_even_created) self.libmetawear.mbl_mw_dataprocessor_comparator_create( self.modulus_signal, Comparator.OPERATION_EQ, 0.0, self.comparator_even_handler)
def lte_counter_processor_created(self, signal): self.lte_comparator_counter = signal self.lte_counter_comparator_handler = Fn_VoidPtr( self.lte_counter_comparator_processor_created) self.libmetawear.mbl_mw_dataprocessor_comparator_create( signal, Comparator.OPERATION_EQ, 16.0, self.lte_counter_comparator_handler)
def setUp(self): super().setUp() self.pulse_handler = Fn_VoidPtr(self.pulse_processor_created) gpio_adc_signal = self.libmetawear.mbl_mw_gpio_get_analog_input_data_signal( self.board, 0, Gpio.ANALOG_READ_MODE_ADC) self.libmetawear.mbl_mw_dataprocessor_pulse_create( gpio_adc_signal, Pulse.OUTPUT_PEAK, 500.0, 10, self.pulse_handler)
def threshold_processor_created(self, signal): self.threshold_signal = signal self.comparator_below_handler = Fn_VoidPtr( self.comparator_below_created) self.libmetawear.mbl_mw_dataprocessor_comparator_create( signal, Comparator.OPERATION_EQ, -1.0, self.comparator_below_handler)
def setUp(self): self.boardType = TestMetaWearBase.METAWEAR_RPRO_BOARD super().setUp() self.processor_handler = Fn_VoidPtr(self.processor_created) self.baro_pa_signal = self.libmetawear.mbl_mw_baro_bosch_get_pressure_data_signal( self.board)
def test_modify_config_signal(self): references = (c_float * 1)(128) adc_signal = self.libmetawear.mbl_mw_gpio_get_analog_input_data_signal( self.board, 0x0, Gpio.ANALOG_READ_MODE_ABS_REF) comp_created_ptr = Fn_VoidPtr(self.comp_created_2) self.libmetawear.mbl_mw_dataprocessor_multi_comparator_create( adc_signal, Comparator.OPERATION_GTE, Comparator.MODE_ABSOLUTE, references, len(references), comp_created_ptr)
def test_modify_config(self): references = (c_float * 4)(1024, 512, 256, 128) adc_signal = self.libmetawear.mbl_mw_gpio_get_analog_input_data_signal( self.board, 0x15, Gpio.ANALOG_READ_MODE_ADC) comp_created_ptr = Fn_VoidPtr(self.comp_created_cmd_check) self.libmetawear.mbl_mw_dataprocessor_multi_comparator_create( adc_signal, Comparator.OPERATION_GTE, Comparator.MODE_REFERENCE, references, len(references), comp_created_ptr)
def test_acc_y_threshold(self): expected_cmds = [[ 0x09, 0x02, 0x03, 0x04, 0xff, 0x22, 0x0d, 0x0d, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00 ], [0x09, 0x02, 0x09, 0x03, 0x00, 0x00, 0x06, 0x01, 0x01], [0x09, 0x07, 0x01, 0x01], [0x09, 0x03, 0x01]] ths_created = Fn_VoidPtr( lambda t: self.libmetawear.mbl_mw_dataprocessor_comparator_create( t, Comparator.OPERATION_EQ, 1.0, comp_created)) comp_created = Fn_VoidPtr( lambda c: self.libmetawear.mbl_mw_datasignal_subscribe( c, self.sensor_data_handler)) acc_y_signal = self.libmetawear.mbl_mw_datasignal_get_component( self.acc_signal, Accelerometer.ACCEL_Y_AXIS_INDEX) self.libmetawear.mbl_mw_dataprocessor_threshold_create( acc_y_signal, Threshold.MODE_BINARY, 1.0, 0.0, ths_created) self.assertEqual(self.command_history, expected_cmds)
def test_collector_setup(self): self.expected_cmds = [[ 0x09, 0x02, 0x05, 0xc7, 0x00, 0x20, 0x0a, 0x01, 0x10 ], [0x09, 0x02, 0x09, 0x03, 0x00, 0x20, 0x01, 0x02, 0x00, 0x00]] self.sample_handler = Fn_VoidPtr(self.sample_processor_created) gpio_adc_signal = self.libmetawear.mbl_mw_gpio_get_analog_input_data_signal( self.board, 0, Gpio.ANALOG_READ_MODE_ADC) self.libmetawear.mbl_mw_dataprocessor_sample_create( gpio_adc_signal, 16, self.sample_handler)
def setUp(self): self.boardType = TestMetaWearBase.METAWEAR_RPRO_BOARD super().setUp() self.rms_handler = Fn_VoidPtr(self.rms_processor_created) accel_signal = self.libmetawear.mbl_mw_acc_get_acceleration_data_signal( self.board) self.libmetawear.mbl_mw_dataprocessor_rms_create( accel_signal, self.rms_handler)
def test_timeout_no_state(self): dataprocessor_created_fn = Fn_VoidPtr(self.dataprocessor_created) self.e = threading.Event() signal = self.libmetawear.mbl_mw_acc_get_acceleration_data_signal( self.board) self.libmetawear.mbl_mw_dataprocessor_rss_create( signal, dataprocessor_created_fn) self.e.wait() self.assertIsNone(self.created_proc)
def setUp(self): super().setUp() self.passthrough_handler = Fn_VoidPtr( self.passthrough_processor_created) self.gpio_abs_ref_signal = self.libmetawear.mbl_mw_gpio_get_analog_input_data_signal( self.board, 0, Gpio.ANALOG_READ_MODE_ABS_REF) self.libmetawear.mbl_mw_dataprocessor_passthrough_create( self.gpio_abs_ref_signal, Passthrough.MODE_COUNT, 0, self.passthrough_handler)
def test_timeout_with_state(self): dataprocessor_created_fn = Fn_VoidPtr(self.dataprocessor_created) self.e = threading.Event() signal = self.libmetawear.mbl_mw_switch_get_state_data_signal( self.board) self.libmetawear.mbl_mw_dataprocessor_accumulator_create( signal, dataprocessor_created_fn) self.e.wait() self.assertIsNone(self.created_proc)
def setUp(self): self.boardType = TestMetaWearBase.METAWEAR_RPRO_BOARD super().setUp() self.f_mult_handler = Fn_VoidPtr(self.f_mult_processor_created) self.temp_signal = self.libmetawear.mbl_mw_multi_chnl_temp_get_temperature_data_signal( self.board, MultiChannelTemperature.METAWEAR_RPRO_CHANNEL_ON_DIE) self.libmetawear.mbl_mw_dataprocessor_math_create( self.temp_signal, Math.OPERATION_MULTIPLY, 18.0, self.f_mult_handler)
def test_constant_op(self): expected = [ 0x09, 0x02, 0x04, 0xc1, 0x00, 0x20, 0x09, 0x17, 0x0b, 0xc8, 0x00, 0x00, 0x00, 0x00 ] temp_signal = self.libmetawear.mbl_mw_multi_chnl_temp_get_temperature_data_signal( self.board, MultiChannelTemperature.METAWEAR_R_CHANNEL_ON_DIE) self.libmetawear.mbl_mw_dataprocessor_math_create( temp_signal, Math.OPERATION_CONSTANT, 25.0, Fn_VoidPtr(lambda math: self.assertEqual(self.command, expected)))
def test_valid_set_count(self): expected = [ 0x09, 0x02, 0x16, 0xc1, 0xff, 0x60, 0x0d, 0x0b, 0x00, 0xe4, 0x00, 0x00, 0x00, 0x00 ] signal = self.libmetawear.mbl_mw_humidity_bme280_get_percentage_data_signal( self.board) self.libmetawear.mbl_mw_dataprocessor_threshold_create( signal, Threshold.MODE_BINARY, 57.0, 0.0, Fn_VoidPtr(lambda p: self.assertEqual(self.command, expected)))
def test_acc_z_pulse_setup(self): expected_cmds = [[ 0x09, 0x02, 0x03, 0x04, 0xff, 0x24, 0x0b, 0x01, 0x00, 0x01, 0x00, 0x08, 0x00, 0x00, 0x10, 0x00 ], [0x09, 0x07, 0x00, 0x01], [0x09, 0x03, 0x01]] acc_z_signal = self.libmetawear.mbl_mw_datasignal_get_component( self.acc_signal, Accelerometer.ACCEL_Z_AXIS_INDEX) self.libmetawear.mbl_mw_dataprocessor_pulse_create( acc_z_signal, Pulse.OUTPUT_AREA, 1.0, 16, Fn_VoidPtr(lambda p: self.libmetawear.mbl_mw_datasignal_subscribe( p, self.sensor_data_handler))) self.assertEqual(self.command_history, expected_cmds)
def test_zone(self): expected = [ 0x09, 0x02, 0x14, 0x03, 0xff, 0x60, 0x06, 0x96, 0x00, 0xc4, 0x02, 0x00, 0xfa, 0x33, 0x5b, 0x00, 0x2a, 0x6d, 0x75, 0x01 ] references = (c_float * 3)(181248, 5977082, 24472874) signal = self.libmetawear.mbl_mw_als_ltr329_get_illuminance_data_signal( self.board) comp_created_ptr = Fn_VoidPtr( lambda comp: self.assertEqual(self.command, expected)) self.libmetawear.mbl_mw_dataprocessor_multi_comparator_create( signal, Comparator.OPERATION_LT, Comparator.MODE_ZONE, references, len(references), comp_created_ptr)
def test_reference(self): expected = [ 0x09, 0x02, 0x05, 0xc7, 0x15, 0x20, 0x06, 0x6a, 0x00, 0x04, 0x00, 0x02, 0x00, 0x01, 0x80, 0x00 ] references = (c_float * 4)(1024, 512, 256, 128) adc_signal = self.libmetawear.mbl_mw_gpio_get_analog_input_data_signal( self.board, 0x15, Gpio.ANALOG_READ_MODE_ADC) comp_created_ptr = Fn_VoidPtr( lambda comp: self.assertEqual(self.command, expected)) self.libmetawear.mbl_mw_dataprocessor_multi_comparator_create( adc_signal, Comparator.OPERATION_GTE, Comparator.MODE_REFERENCE, references, len(references), comp_created_ptr)
def test_absolute(self): expected = [ 0x09, 0x02, 0x04, 0xc1, 0x01, 0x20, 0x06, 0x03, 0xc0, 0x00, 0xc8, 0x00, 0xd0, 0x00 ] references = (c_float * 3)(24.0, 25.0, 26.0) signal = self.libmetawear.mbl_mw_multi_chnl_temp_get_temperature_data_signal( self.board, MultiChannelTemperature.METAWEAR_RPRO_CHANNEL_ON_BOARD_THERMISTOR) comp_created_ptr = Fn_VoidPtr( lambda comp: self.assertEqual(self.command, expected)) self.libmetawear.mbl_mw_dataprocessor_multi_comparator_create( signal, Comparator.OPERATION_EQ, Comparator.MODE_ABSOLUTE, references, len(references), comp_created_ptr)
def test_set_major_signal(self): expected= [ [0x09, 0x02, 0x01, 0x01, 0xff, 0x00, 0x02, 0x13], [0x0a, 0x02, 0x09, 0x03, 0x00, 0x07, 0x03, 0x02, 0x09, 0x00], [0x0a, 0x03, 0x00, 0x00] ] switch= self.libmetawear.mbl_mw_switch_get_state_data_signal(self.board) self.callback= Fn_VoidPtr(self.counter_created) self.libmetawear.mbl_mw_dataprocessor_counter_create_size(switch, 4, self.callback) self.libmetawear.mbl_mw_event_record_commands(self.counter) self.libmetawear.mbl_mw_ibeacon_set_major_signal(self.board, self.counter) self.libmetawear.mbl_mw_event_end_record(self.counter, self.commands_recorded_fn) self.assertEqual(self.command_history, expected)
def test_freefall_setup(self): self.expected_cmds = [ [0x09, 0x02, 0x03, 0x04, 0xff, 0xa0, 0x07, 0xa5, 0x01], [0x09, 0x02, 0x09, 0x03, 0x00, 0x20, 0x03, 0x05, 0x04], [ 0x09, 0x02, 0x09, 0x03, 0x01, 0x20, 0x0d, 0x09, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00 ], [ 0x09, 0x02, 0x09, 0x03, 0x02, 0x00, 0x06, 0x01, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff ], [ 0x09, 0x02, 0x09, 0x03, 0x02, 0x00, 0x06, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 ] ] self.rss_handler = Fn_VoidPtr(self.rss_processor_created) accel_signal = self.libmetawear.mbl_mw_acc_get_acceleration_data_signal( self.board) self.libmetawear.mbl_mw_dataprocessor_rss_create( accel_signal, self.rss_handler)
def gt_comparator_processor_created(self, signal): self.gt_comparator = signal self.gt_counter_handler = Fn_VoidPtr(self.gt_counter_processor_created) self.libmetawear.mbl_mw_dataprocessor_counter_create( signal, self.gt_counter_handler)
def math_processor_created(self, signal): self.abs_ref_offset = signal self.gt_comparator_handler = Fn_VoidPtr( self.gt_comparator_processor_created) self.libmetawear.mbl_mw_dataprocessor_comparator_create( signal, Comparator.OPERATION_GT, 0.0, self.gt_comparator_handler)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.boardType = TestMetaWearBase.METAWEAR_ENV_BOARD self.processor_created_fn = Fn_VoidPtr(self.processor_created) self.logger_created_fn = Fn_VoidPtr(self.logger_created)
def test_constant_op_data(self): const_created_ptr = Fn_VoidPtr(self.const_created) temp_signal = self.libmetawear.mbl_mw_multi_chnl_temp_get_temperature_data_signal( self.board, MultiChannelTemperature.METAWEAR_R_CHANNEL_ON_DIE) self.libmetawear.mbl_mw_dataprocessor_math_create( temp_signal, Math.OPERATION_CONSTANT, 25.0, const_created_ptr)
def passthrough_processor_created(self, signal): self.offset_passthrough = signal self.math_handler = Fn_VoidPtr(self.math_processor_created) self.libmetawear.mbl_mw_dataprocessor_math_create( self.gpio_abs_ref_signal, Math.OPERATION_SUBTRACT, 0.0, self.math_handler)