Ejemplo n.º 1
0
 def test_set_filter_constants(self):
     uc = UserConfiguration(user_config_sample())
     new_bytes = bytearray(range(16))
     new_value = base64.b64encode(new_bytes)
     uc.filter_constants = new_value
     self.assertEqual(new_value, uc.filter_constants)
     self.assertEqual(new_bytes, uc.filter_constants_bytes)
Ejemplo n.º 2
0
    def test_set_mode_wave(self):
        """
        Test setting each bit in the mode individually
        0    WAVE_DATA_RATE = 'wave_data_rate'
        1    WAVE_CELL_POS = 'wave_cell_position'
        2    DYNAMIC_POS_TYPE = 'dynamic_position_type'
        """
        uc = UserConfiguration(user_config_sample())

        uc.mode_wave = 0
        self.assertEqual(uc.wave_data_rate, 0)
        self.assertEqual(uc.wave_cell_position, 0)
        self.assertEqual(uc.dynamic_position_type, 0)

        uc.mode_wave = 0b1
        self.assertEqual(uc.wave_data_rate, 1)
        self.assertEqual(uc.wave_cell_position, 0)
        self.assertEqual(uc.dynamic_position_type, 0)

        uc.mode_wave = 0b10
        self.assertEqual(uc.wave_data_rate, 0)
        self.assertEqual(uc.wave_cell_position, 1)
        self.assertEqual(uc.dynamic_position_type, 0)

        uc.mode_wave = 0b100
        self.assertEqual(uc.wave_data_rate, 0)
        self.assertEqual(uc.wave_cell_position, 0)
        self.assertEqual(uc.dynamic_position_type, 1)
Ejemplo n.º 3
0
 def test_set_velocity_adjustment_factor_invalid(self):
     uc = UserConfiguration(user_config_sample())
     new_velocity_adjustment_factor_bytes = bytearray(range(179))
     new_velocity_adjustment_factor = base64.b64encode(
         new_velocity_adjustment_factor_bytes)
     with self.assertRaises(TypeError):
         uc.velocity_adjustment_factor = new_velocity_adjustment_factor
Ejemplo n.º 4
0
    def test_mode_bit_set(self):
        uc = UserConfiguration(user_config_sample())
        uc.mode = 0

        uc.use_specified_sound_speed = 1
        self.assertEqual(uc.mode, 0b1)

        uc.diagnostics_mode_enable = 1
        self.assertEqual(uc.mode, 0b11)

        uc.analog_output_enable = 1
        self.assertEqual(uc.mode, 0b111)

        uc.output_format_nortek = 1
        self.assertEqual(uc.mode, 0b1111)

        uc.scaling = 1
        self.assertEqual(uc.mode, 0b11111)

        uc.serial_output_enable = 1
        self.assertEqual(uc.mode, 0b111111)

        uc.stage_enable = 1
        self.assertEqual(uc.mode, 0b10111111)

        uc.analog_power_output = 1
        self.assertEqual(uc.mode, 0b110111111)
Ejemplo n.º 5
0
    def test_set_diag_interval(self):
        uc = UserConfiguration(user_config_sample())

        # low only
        uc.diagnostics_interval = 1
        self.assertEqual(uc.diag_interval_low, 1)
        self.assertEqual(uc.diag_interval_high, 0)
        self.assertEqual(uc.diagnostics_interval, 1)

        # high only
        uc.diagnostics_interval = 65536
        self.assertEqual(uc.diag_interval_low, 0)
        self.assertEqual(uc.diag_interval_high, 1)
        self.assertEqual(uc.diagnostics_interval, 65536)

        # both
        uc.diagnostics_interval = 65537
        self.assertEqual(uc.diag_interval_low, 1)
        self.assertEqual(uc.diag_interval_high, 1)
        self.assertEqual(uc.diagnostics_interval, 65537)

        # max
        uc.diagnostics_interval = 2**32 - 1
        self.assertEqual(uc.diag_interval_low, 65535)
        self.assertEqual(uc.diag_interval_high, 65535)
        self.assertEqual(uc.diagnostics_interval, 2**32 - 1)

        # too big
        with self.assertRaises(ValueError):
            uc.diagnostics_interval = 2**32

        uc.diagnostics_interval = 10800
        print uc.diag_interval_low
        print uc.diag_interval_high
Ejemplo n.º 6
0
    def test_values(self):
        uc = UserConfiguration(user_config_sample())

        for row in user_config_particle:
            key = row[DataParticleKey.VALUE_ID]
            value = row[DataParticleKey.VALUE]

            self.assertEqual(getattr(uc, key, None), value, msg=key)
Ejemplo n.º 7
0
    def test_mode_test_bit_set(self):
        uc = UserConfiguration(user_config_sample())
        uc.mode_test = 0

        uc.use_dsp_filter = 1
        self.assertEqual(uc.mode_test, 0b1)

        uc.filter_data_output = 1
        self.assertEqual(uc.mode_test, 0b11)
Ejemplo n.º 8
0
    def test_pcr_bit_set(self):
        uc = UserConfiguration(user_config_sample())
        uc.pcr = 0

        uc.power_level_pcr1 = 1
        self.assertEqual(uc.pcr, 0b100000)

        uc.power_level_pcr2 = 1
        self.assertEqual(uc.pcr, 0b1100000)
Ejemplo n.º 9
0
    def test_set_deploy_start_time(self):
        uc = UserConfiguration(user_config_sample())
        new_time = [0, 0, 0, 0, 0, 0]
        uc.deployment_start_time = new_time
        self.assertEqual(new_time, uc.deployment_start_time)

        new_time = [1, 2, 3, 4, 5, 6]
        uc.deployment_start_time = new_time
        self.assertEqual(new_time, uc.deployment_start_time)
Ejemplo n.º 10
0
    def test_set_short_out_of_range(self):
        uc = UserConfiguration()
        with self.assertRaises(ValueError):
            uc._set_short_at(sizeof(UserConfiguration), 1)

        with self.assertRaises(ValueError):
            uc._set_short_at(sizeof(UserConfiguration) - 1, 1)

        with self.assertRaises(ValueError):
            uc._set_short_at(-1, 1)
Ejemplo n.º 11
0
 def test_set_velocity_adjustment_factor(self):
     uc = UserConfiguration(user_config_sample())
     new_velocity_adjustment_factor_bytes = bytearray(range(180))
     new_velocity_adjustment_factor = base64.b64encode(
         new_velocity_adjustment_factor_bytes)
     uc.velocity_adjustment_factor = new_velocity_adjustment_factor
     self.assertEqual(new_velocity_adjustment_factor,
                      uc.velocity_adjustment_factor)
     self.assertEqual(new_velocity_adjustment_factor_bytes,
                      uc.velocity_adjustment_factor_bytes)
Ejemplo n.º 12
0
    def test_mode_wave_bit_set(self):
        uc = UserConfiguration(user_config_sample())
        uc.mode_wave = 0

        uc.wave_data_rate = 1
        self.assertEqual(uc.mode_wave, 0b1)

        uc.wave_cell_position = 1
        self.assertEqual(uc.mode_wave, 0b11)

        uc.dynamic_position_type = 1
        self.assertEqual(uc.mode_wave, 0b111)
Ejemplo n.º 13
0
    def test_set_pcr(self):
        """
        Test setting each bit in the TCR individually
        5    POWER_PCR1 = 'power_level_pcr1'
        6    POWER_PCR2 = 'power_level_pcr2'
        """
        uc = UserConfiguration(user_config_sample())

        uc.pcr = 0
        self.assertEqual(uc.power_level_pcr1, 0)
        self.assertEqual(uc.power_level_pcr2, 0)

        uc.pcr = 0b100000
        self.assertEqual(uc.power_level_pcr1, 1)
        self.assertEqual(uc.power_level_pcr2, 0)

        uc.pcr = 0b1000000
        self.assertEqual(uc.power_level_pcr1, 0)
        self.assertEqual(uc.power_level_pcr2, 1)
Ejemplo n.º 14
0
    def test_set_mode_test(self):
        """
        Test setting each bit in the mode individually
        0    USE_DSP_FILTER = 'use_dsp_filter'
        1    FILTER_DATA_OUTPUT = 'filter_data_output'
        """
        uc = UserConfiguration(user_config_sample())

        uc.mode_test = 0
        self.assertEqual(uc.use_dsp_filter, 0)
        self.assertEqual(uc.filter_data_output, 0)

        uc.mode_test = 0b1
        self.assertEqual(uc.use_dsp_filter, 1)
        self.assertEqual(uc.filter_data_output, 0)

        uc.mode_test = 0b10
        self.assertEqual(uc.use_dsp_filter, 0)
        self.assertEqual(uc.filter_data_output, 1)
Ejemplo n.º 15
0
    def test_tcr_bit_set(self):
        uc = UserConfiguration(user_config_sample())
        uc.tcr = 0

        uc.profile_type = 1
        self.assertEqual(uc.tcr, 0b10)

        uc.mode_type = 1
        self.assertEqual(uc.tcr, 0b110)

        uc.power_level_tcm1 = 1
        self.assertEqual(uc.tcr, 0b100110)

        uc.power_level_tcm2 = 1
        self.assertEqual(uc.tcr, 0b1100110)

        uc.sync_out_position = 1
        self.assertEqual(uc.tcr, 0b11100110)

        uc.sample_on_sync = 1
        self.assertEqual(uc.tcr, 0b111100110)

        uc.start_on_sync = 1
        self.assertEqual(uc.tcr, 0b1111100110)
Ejemplo n.º 16
0
 def test_get_mode_wave(self):
     uc = UserConfiguration(user_config_sample())
     expected = 4615
     self.assertEqual(uc.mode_wave, expected)
Ejemplo n.º 17
0
 def test_set_invalid_deploy_start_time(self):
     uc = UserConfiguration(user_config_sample())
     new_time = [0, 0, 0, 0, 0, 0, 0]
     with self.assertRaises(TypeError):
         uc.deployment_start_time = new_time
Ejemplo n.º 18
0
 def test_get_pcr(self):
     uc = UserConfiguration(user_config_sample())
     expected = 0
     self.assertEqual(uc.pcr, expected)
Ejemplo n.º 19
0
 def test_str(self):
     uc = UserConfiguration()
     d = uc._dict()
     self.assertEqual(str(uc), pformat(d))
Ejemplo n.º 20
0
 def test_dict(self):
     uc = UserConfiguration()
     d = uc._dict()
     self.assertEqual(d['sync'], 165)
     self.assertListEqual(sorted([f[0] for f in uc._fields_]), sorted(d))
Ejemplo n.º 21
0
 def test_set_non_integer_array(self):
     uc = UserConfiguration()
     with self.assertRaises(TypeError):
         uc.deployment_start_time = [
             'green', 'yellow', 'red', 'blue', 'orange', 'banana'
         ]
Ejemplo n.º 22
0
 def test_create(self):
     uc = UserConfiguration(user_config_sample())
     self.assertIsNotNone(uc)
Ejemplo n.º 23
0
 def test_set_filter_constants_invalid(self):
     uc = UserConfiguration(user_config_sample())
     new_bytes = bytearray(range(17))
     new_value = base64.b64encode(new_bytes)
     with self.assertRaises(TypeError):
         uc.filter_constants = new_value
Ejemplo n.º 24
0
 def test_set_non_integer(self):
     uc = UserConfiguration()
     with self.assertRaises(TypeError):
         uc.sample_rate = 'blue'
Ejemplo n.º 25
0
 def assert_round_trip(self, config_string):
     uc = UserConfiguration(config_string)
     self.assertTrue(uc.valid)
     self.assertEqual(config_string, repr(uc))
Ejemplo n.º 26
0
    def test_set_tcr(self):
        """
        Test setting each bit in the TCR individually
        1    PROFILE_TYPE = 'profile_type'
        2    MODE_TYPE = 'mode_type'
        5    POWER_TCM1 = 'power_level_tcm1'
        6    POWER_TCM2 = 'power_level_tcm2'
        7    SYNC_OUT_POSITION = 'sync_out_position'
        8    SAMPLE_ON_SYNC = 'sample_on_sync'
        9    START_ON_SYNC = 'start_on_sync'
        """
        uc = UserConfiguration(user_config_sample())

        uc.tcr = 0
        self.assertEqual(uc.profile_type, 0)
        self.assertEqual(uc.mode_type, 0)
        self.assertEqual(uc.power_level_tcm1, 0)
        self.assertEqual(uc.power_level_tcm2, 0)
        self.assertEqual(uc.sync_out_position, 0)
        self.assertEqual(uc.sample_on_sync, 0)
        self.assertEqual(uc.start_on_sync, 0)

        uc.tcr = 0b10
        self.assertEqual(uc.profile_type, 1)
        self.assertEqual(uc.mode_type, 0)
        self.assertEqual(uc.power_level_tcm1, 0)
        self.assertEqual(uc.power_level_tcm2, 0)
        self.assertEqual(uc.sync_out_position, 0)
        self.assertEqual(uc.sample_on_sync, 0)
        self.assertEqual(uc.start_on_sync, 0)

        uc.tcr = 0b100
        self.assertEqual(uc.profile_type, 0)
        self.assertEqual(uc.mode_type, 1)
        self.assertEqual(uc.power_level_tcm1, 0)
        self.assertEqual(uc.power_level_tcm2, 0)
        self.assertEqual(uc.sync_out_position, 0)
        self.assertEqual(uc.sample_on_sync, 0)
        self.assertEqual(uc.start_on_sync, 0)

        uc.tcr = 0b100000
        self.assertEqual(uc.profile_type, 0)
        self.assertEqual(uc.mode_type, 0)
        self.assertEqual(uc.power_level_tcm1, 1)
        self.assertEqual(uc.power_level_tcm2, 0)
        self.assertEqual(uc.sync_out_position, 0)
        self.assertEqual(uc.sample_on_sync, 0)
        self.assertEqual(uc.start_on_sync, 0)

        uc.tcr = 0b1000000
        self.assertEqual(uc.profile_type, 0)
        self.assertEqual(uc.mode_type, 0)
        self.assertEqual(uc.power_level_tcm1, 0)
        self.assertEqual(uc.power_level_tcm2, 1)
        self.assertEqual(uc.sync_out_position, 0)
        self.assertEqual(uc.sample_on_sync, 0)
        self.assertEqual(uc.start_on_sync, 0)

        uc.tcr = 0b10000000
        self.assertEqual(uc.profile_type, 0)
        self.assertEqual(uc.mode_type, 0)
        self.assertEqual(uc.power_level_tcm1, 0)
        self.assertEqual(uc.power_level_tcm2, 0)
        self.assertEqual(uc.sync_out_position, 1)
        self.assertEqual(uc.sample_on_sync, 0)
        self.assertEqual(uc.start_on_sync, 0)

        uc.tcr = 0b100000000
        self.assertEqual(uc.profile_type, 0)
        self.assertEqual(uc.mode_type, 0)
        self.assertEqual(uc.power_level_tcm1, 0)
        self.assertEqual(uc.power_level_tcm2, 0)
        self.assertEqual(uc.sync_out_position, 0)
        self.assertEqual(uc.sample_on_sync, 1)
        self.assertEqual(uc.start_on_sync, 0)

        uc.tcr = 0b1000000000
        self.assertEqual(uc.profile_type, 0)
        self.assertEqual(uc.mode_type, 0)
        self.assertEqual(uc.power_level_tcm1, 0)
        self.assertEqual(uc.power_level_tcm2, 0)
        self.assertEqual(uc.sync_out_position, 0)
        self.assertEqual(uc.sample_on_sync, 0)
        self.assertEqual(uc.start_on_sync, 1)
Ejemplo n.º 27
0
    def test_set_mode(self):
        """
        Test setting each bit in the mode individually
        0    USE_SPEC_SOUND_SPEED = 'use_specified_sound_speed'
        1    DIAG_MODE_ON = 'diagnostics_mode_enable'
        2    ANALOG_OUTPUT_ON = 'analog_output_enable'
        3    OUTPUT_FORMAT = 'output_format_nortek'
        4    SCALING = 'scaling'
        5    SERIAL_OUT_ON = 'serial_output_enable'
        7    STAGE_ON = 'stage_enable'
        8    ANALOG_POWER_OUTPUT = 'analog_power_output'
        """
        uc = UserConfiguration(user_config_sample())

        uc.mode = 0
        self.assertEqual(uc.use_specified_sound_speed, 0)
        self.assertEqual(uc.diagnostics_mode_enable, 0)
        self.assertEqual(uc.analog_output_enable, 0)
        self.assertEqual(uc.output_format_nortek, 0)
        self.assertEqual(uc.scaling, 0)
        self.assertEqual(uc.serial_output_enable, 0)
        self.assertEqual(uc.stage_enable, 0)
        self.assertEqual(uc.analog_power_output, 0)

        uc.mode = 0b1
        self.assertEqual(uc.use_specified_sound_speed, 1)
        self.assertEqual(uc.diagnostics_mode_enable, 0)
        self.assertEqual(uc.analog_output_enable, 0)
        self.assertEqual(uc.output_format_nortek, 0)
        self.assertEqual(uc.scaling, 0)
        self.assertEqual(uc.serial_output_enable, 0)
        self.assertEqual(uc.stage_enable, 0)
        self.assertEqual(uc.analog_power_output, 0)

        uc.mode = 0b10
        self.assertEqual(uc.use_specified_sound_speed, 0)
        self.assertEqual(uc.diagnostics_mode_enable, 1)
        self.assertEqual(uc.analog_output_enable, 0)
        self.assertEqual(uc.output_format_nortek, 0)
        self.assertEqual(uc.scaling, 0)
        self.assertEqual(uc.serial_output_enable, 0)
        self.assertEqual(uc.stage_enable, 0)
        self.assertEqual(uc.analog_power_output, 0)

        uc.mode = 0b100
        self.assertEqual(uc.use_specified_sound_speed, 0)
        self.assertEqual(uc.diagnostics_mode_enable, 0)
        self.assertEqual(uc.analog_output_enable, 1)
        self.assertEqual(uc.output_format_nortek, 0)
        self.assertEqual(uc.scaling, 0)
        self.assertEqual(uc.serial_output_enable, 0)
        self.assertEqual(uc.stage_enable, 0)
        self.assertEqual(uc.analog_power_output, 0)

        uc.mode = 0b1000
        self.assertEqual(uc.use_specified_sound_speed, 0)
        self.assertEqual(uc.diagnostics_mode_enable, 0)
        self.assertEqual(uc.analog_output_enable, 0)
        self.assertEqual(uc.output_format_nortek, 1)
        self.assertEqual(uc.scaling, 0)
        self.assertEqual(uc.serial_output_enable, 0)
        self.assertEqual(uc.stage_enable, 0)
        self.assertEqual(uc.analog_power_output, 0)

        uc.mode = 0b10000
        self.assertEqual(uc.use_specified_sound_speed, 0)
        self.assertEqual(uc.diagnostics_mode_enable, 0)
        self.assertEqual(uc.analog_output_enable, 0)
        self.assertEqual(uc.output_format_nortek, 0)
        self.assertEqual(uc.scaling, 1)
        self.assertEqual(uc.serial_output_enable, 0)
        self.assertEqual(uc.stage_enable, 0)
        self.assertEqual(uc.analog_power_output, 0)

        uc.mode = 0b100000
        self.assertEqual(uc.use_specified_sound_speed, 0)
        self.assertEqual(uc.diagnostics_mode_enable, 0)
        self.assertEqual(uc.analog_output_enable, 0)
        self.assertEqual(uc.output_format_nortek, 0)
        self.assertEqual(uc.scaling, 0)
        self.assertEqual(uc.serial_output_enable, 1)
        self.assertEqual(uc.stage_enable, 0)
        self.assertEqual(uc.analog_power_output, 0)

        uc.mode = 0b10000000
        self.assertEqual(uc.use_specified_sound_speed, 0)
        self.assertEqual(uc.diagnostics_mode_enable, 0)
        self.assertEqual(uc.analog_output_enable, 0)
        self.assertEqual(uc.output_format_nortek, 0)
        self.assertEqual(uc.scaling, 0)
        self.assertEqual(uc.serial_output_enable, 0)
        self.assertEqual(uc.stage_enable, 1)
        self.assertEqual(uc.analog_power_output, 0)

        uc.mode = 0b100000000
        self.assertEqual(uc.use_specified_sound_speed, 0)
        self.assertEqual(uc.diagnostics_mode_enable, 0)
        self.assertEqual(uc.analog_output_enable, 0)
        self.assertEqual(uc.output_format_nortek, 0)
        self.assertEqual(uc.scaling, 0)
        self.assertEqual(uc.serial_output_enable, 0)
        self.assertEqual(uc.stage_enable, 0)
        self.assertEqual(uc.analog_power_output, 1)
Ejemplo n.º 28
0
    def _build_parsed_values(self):
        """
        Take the user config data and parse it into
        values with appropriate tags.
        @throws SampleException If there is a problem with sample creation
        """
        try:
            config = UserConfiguration(self.raw_data)
        except Exception as e:
            log.error('Error creating particle user config, raw data: %r',
                      self.raw_data)
            raise SampleException(e)

        fields = [
            UserConfigKey.TX_LENGTH,
            UserConfigKey.BLANK_DIST,
            UserConfigKey.RX_LENGTH,
            UserConfigKey.TIME_BETWEEN_PINGS,
            UserConfigKey.TIME_BETWEEN_BURSTS,
            UserConfigKey.NUM_PINGS,
            UserConfigKey.AVG_INTERVAL,
            UserConfigKey.NUM_BEAMS,
            UserConfigKey.PROFILE_TYPE,
            UserConfigKey.MODE_TYPE,
            UserConfigKey.POWER_TCM1,
            UserConfigKey.POWER_TCM2,
            UserConfigKey.SYNC_OUT_POSITION,
            UserConfigKey.SAMPLE_ON_SYNC,
            UserConfigKey.START_ON_SYNC,
            UserConfigKey.POWER_PCR1,
            UserConfigKey.POWER_PCR2,
            UserConfigKey.COMPASS_UPDATE_RATE,
            UserConfigKey.COORDINATE_SYSTEM,
            UserConfigKey.NUM_CELLS,
            UserConfigKey.CELL_SIZE,
            UserConfigKey.MEASUREMENT_INTERVAL,
            UserConfigKey.DEPLOYMENT_NAME,
            UserConfigKey.WRAP_MODE,
            UserConfigCompositeKey.DEPLOY_START_TIME,
            UserConfigCompositeKey.DIAG_INTERVAL,
            UserConfigKey.USE_SPEC_SOUND_SPEED,
            UserConfigKey.DIAG_MODE_ON,
            UserConfigKey.ANALOG_OUTPUT_ON,
            UserConfigKey.OUTPUT_FORMAT,
            UserConfigKey.SCALING,
            UserConfigKey.SERIAL_OUT_ON,
            UserConfigKey.STAGE_ON,
            UserConfigKey.ANALOG_POWER_OUTPUT,
            UserConfigKey.SOUND_SPEED_ADJUST,
            UserConfigKey.NUM_DIAG_SAMPLES,
            UserConfigKey.NUM_BEAMS_PER_CELL,
            UserConfigKey.NUM_PINGS_DIAG,
            UserConfigKey.USE_DSP_FILTER,
            UserConfigKey.FILTER_DATA_OUTPUT,
            UserConfigKey.ANALOG_INPUT_ADDR,
            UserConfigKey.SW_VER,
            UserConfigCompositeKey.VELOCITY_ADJ_FACTOR,
            UserConfigKey.FILE_COMMENTS,
            UserConfigKey.WAVE_DATA_RATE,
            UserConfigKey.WAVE_CELL_POS,
            UserConfigKey.DYNAMIC_POS_TYPE,
            UserConfigKey.PERCENT_WAVE_CELL_POS,
            UserConfigKey.WAVE_TX_PULSE,
            UserConfigKey.FIX_WAVE_BLANK_DIST,
            UserConfigKey.WAVE_CELL_SIZE,
            UserConfigKey.NUM_DIAG_PER_WAVE,
            UserConfigKey.NUM_SAMPLE_PER_BURST,
            UserConfigKey.ANALOG_SCALE_FACTOR,
            UserConfigKey.CORRELATION_THRS,
            UserConfigKey.TX_PULSE_LEN_2ND,
            UserConfigCompositeKey.FILTER_CONSTANTS,
        ]

        result = [{
            VID: field,
            VAL: getattr(config, field)
        } for field in fields]

        log.debug('NortekUserConfigDataParticle: particle=%r', result)
        return result
Ejemplo n.º 29
0
 def test_empty(self):
     empty = UserConfiguration()
     self.assertEqual(repr(empty),
                      '\xa5\x00\x00\x01' + '\x00' * 506 + '\x31\xb7')