Esempio n. 1
0
 def setUp(self):
     self._messages = test_util.SynthesizeMessages(['ServoStatus'], 0)
     # Convert data from ctypes object to Python dicts.
     data = self._messages.Data(convert_to_basic_types=False)
     # Create a new StructTree referencing the data so that we can change
     self._servo_statuses = data['ServoStatus']
     self._tetherdown_servo_statuses = (
         data['filtered'].merge_tether_down.tether_down.servo_statuses)
Esempio n. 2
0
 def _RunLayouts(self):
     num_messages = 10
     messages = test_util.SynthesizeMessages()
     for layout_name in self._layout_names:
         layout = loader.LayoutLoader().GetLayoutByModuleName(layout_name)
         layout.Initialize()
         for _ in range(num_messages):
             json.dumps(layout.Filter(messages).Json())
             assert not layout.ErrorReport()
Esempio n. 3
0
    def setUp(self):
        self._messages = test_util.SynthesizeMessages(
            ['NovAtelObservations', 'SeptentrioObservations'], 0)
        # Convert data from ctypes object to Python dicts.
        data = self._messages.Data(convert_to_basic_types=False)
        self._novatel_obs = data['NovAtelObservations']['FcB']
        self._septentrio_obs = data['SeptentrioObservations']['FcA']
        # Values to qualify a good condition.
        for i in range(32):
            self._novatel_obs.range.cn0[i] = 51
            self._novatel_obs.range.status_bits[i] = 0
            self._septentrio_obs.meas_epoch.cn0[i] = 121
            self._septentrio_obs.meas_epoch.type[i] = 0

        self._novatel_obs.range.num_obs = 5
        self._septentrio_obs.meas_epoch.num_obs = 5
        self._novatel_cn0_indicator = gps.NovAtelObsCn0Indicator('FcB')
        self._septentrio_cn0_indicator = gps.SeptentrioObsCn0Indicator('FcA')
Esempio n. 4
0
    def testTetherReleaseReadinessIndicator(self):
        """Test entering the 'continue' and 'any_warning_or_error' branch."""
        loadcells = ['LoadcellPortA', 'LoadcellPortB']
        indicator = control.TetherReleaseReadinessIndicator(loadcells)
        # Create a message snapshot that fail silently to gracefully handle
        # missing messages.
        messages = test_util.SynthesizeMessages(
            ['ControlTelemetry', 'ControlSlowTelemetry', 'Loadcell'],
            0,
            fail_silently=True)

        # Set up the port message so that it contains an empty StructTree in one
        # port and an error in the other port.
        read_message = messages.Data(convert_to_basic_types=False)
        error_code = pack_avionics_messages.kLoadcellErrorBatteryDisconnected
        del read_message['Loadcell']['LoadcellPortA']
        read_message['Loadcell']['LoadcellPortB'].status.warning = 0
        read_message['Loadcell']['LoadcellPortB'].status.error = error_code
        read_message['ControlSlowTelemetry']['ControllerA'].flight_plan = (
            system_params.kFlightPlanTurnKey)

        # Call Filter, check that stoplight value is error,
        # and check the string values detect a Low Battery Error in PortB.
        result = indicator.Filter(messages)
        result_string, result_stoplight = result
        result_lines = result_string.split('\n')

        self.assertEqual(stoplights.STOPLIGHT_ERROR, result_stoplight)
        self.assertEqual('PortB:', result_lines[0])
        self.assertEqual('[ERROR]', result_lines[1])
        self.assertEqual('BatteryDisconnected', result_lines[2])

        # Change flight plan to a low altitude plan.
        read_message['ControlSlowTelemetry']['ControllerA'].flight_plan = (
            system_params.kFlightPlanLaunchPerch)
        result_string, result_stoplight = indicator.Filter(messages)
        self.assertEqual(result_string, 'No Key')
        self.assertEqual(result_stoplight, stoplights.STOPLIGHT_NORMAL)

        # Disable BatterDisconnected error (key is plugged in).
        read_message['Loadcell']['LoadcellPortB'].status.error = 0
        result_string, result_stoplight = indicator.Filter(messages)
        self.assertEqual(result_string, 'Keyed: PortB')
        self.assertEqual(result_stoplight, stoplights.STOPLIGHT_ERROR)
Esempio n. 5
0
 def _SynthesizeMessages(self,
                         full_source,
                         init_state,
                         tether_valid,
                         flight_mode,
                         no_update_count=0):
     messages = test_util.SynthesizeMessages(['ControlTelemetry'])
     data = messages.Data(convert_to_basic_types=False)
     filtered_data = aio_helper.GetFilteredData()
     data['filtered'] = filtered_data
     data['ControlTelemetry']['ControllerA'].init_state = init_state
     data['ControlTelemetry']['ControllerA'].flight_mode = flight_mode
     merge_tether_down = filtered_data.merge_tether_down
     merge_tether_down.tether_down.control_telemetry.flight_mode = flight_mode
     merge_tether_down.tether_down.control_telemetry.no_update_count = (
         no_update_count)
     merge_tether_down.valid = tether_valid
     merge_tether_down.timestamp_sec = 1234567
     return data
Esempio n. 6
0
    def setUp(self):
        self.array = np.array([(0.0, 20), (1.0, 40), (2.0, 80), (3.0, 160)],
                              dtype=[('x', '<f8'), ('y', '<i8')])

        self._data = {
            'numbers': [
                {
                    1: ['apple', 'antenna', 'alps']
                },
                {
                    2: ['banana', 'bus', 'bound']
                },
                {
                    3: ['car', 'cat', 'circuit']
                },
                {
                    4: ['dance', 'deer', 'direction']
                },
            ],
            'strings': {
                'a': ['apple', 'antenna', 'alps'],
                'b': ['banana', 'bus', 'bound'],
                'c': ['car', 'cat', 'circuit'],
                'd': ['dance', 'deer', 'direction'],
            },
            'deep': {
                'x': {
                    'y': {
                        'z': 0
                    }
                }
            },
            'numpy':
            self.array
        }
        self._struct_tree = struct_tree.StructTree(self._data)
        self._ndarray = np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8]])
        self._numpy_tree = struct_tree.StructTree({'array': self._ndarray})
        self._ctype_tree = test_util.SynthesizeMessages('MotorStatus', 0)
        self.assertIn('strings.a', self._struct_tree)
        self.assertNotIn('strings.z', self._struct_tree)
        self.assertNotIn('shallow.a', self._struct_tree)
Esempio n. 7
0
 def testCtypes(self):
     messages = test_util.SynthesizeMessages(['ControlTelemetry'], 0)
     # Run and make sure there are no faults.
     autogen.GenerateScenario(messages.Data(convert_to_basic_types=True),
                              'Test')
Esempio n. 8
0
 def _SynthesizeControlTelemetry(self, sequence=0):
     return test_util.SynthesizeMessages(
         ['ControlTelemetry', 'ControlSlowTelemetry'], sequence)
Esempio n. 9
0
 def _SynthesizePlcTelemetry(self, sequence=0):
     messages = test_util.SynthesizeMessages(['GroundStationPlcStatus'],
                                             sequence)
     plc = messages.Subtree('GroundStationPlcStatus.PlcTophat').Data()
     return plc, messages