Beispiel #1
0
def test_database_database_container():
    with database.Database('NIXNET_example') as db_1:
        with database.Database('NIXNET_exampleLDF') as db_2:
            db_3 = database.Database('NIXNET_example')

            # test dunders
            assert db_1 == db_3
            assert db_1 != db_2
            assert len({db_1, db_2, db_3}) == 2  # testing `__hash__`
            print(repr(db_1))

            db_3.close()
            del db_3
def test_signal_dbc_signal_value_table():
    database_filepath = os.path.join(os.path.dirname(__file__), 'databases\\attributes.dbc')
    with database.Database(database_filepath) as db:
        cluster = db.clusters['Cluster']
        frame1 = cluster.frames['Msg1']
        sig1 = frame1.mux_static_signals['Sig1']
        sig2 = frame1.mux_static_signals['Sig2']

        # test dunders
        assert len(sig1.dbc_signal_value_table) == 3
        assert len(sig2.dbc_signal_value_table) == 0
        assert len({sig1.dbc_signal_value_table, sig1.dbc_signal_value_table}) == 1  # testing `__hash__`
        assert len({sig1.dbc_signal_value_table, sig2.dbc_signal_value_table}) == 2  # testing `__hash__`
        assert sig1.dbc_signal_value_table == sig1.dbc_signal_value_table
        assert sig1.dbc_signal_value_table != sig2.dbc_signal_value_table
        for key in sig1.dbc_signal_value_table:
            print(sig1.dbc_signal_value_table[key])

        # test container
        assert sorted(sig1.dbc_signal_value_table.keys()) == ['High', 'Low', 'Zero']
        assert sorted(sig1.dbc_signal_value_table.values()) == ['-10', '0', '4']
        assert sorted(sig1.dbc_signal_value_table.items()) == [('High', '4'), ('Low', '-10'), ('Zero', '0')]

        # test values
        assert sig1.dbc_signal_value_table['Low'] == '-10'
        assert sig1.dbc_signal_value_table['High'] == '4'
        assert sig1.dbc_signal_value_table['Zero'] == '0'
Beispiel #3
0
def test_database_collection_container():
    test_cluster_name = '__cluster__name__for__testing__'
    with database.Database('NIXNET_example') as db:
        collection_1 = db.clusters  # type: _collection.DbCollection
        collection_2 = db.clusters  # type: _collection.DbCollection
        collection_3 = db.clusters[
            'CAN_Cluster'].ecus  # type: _collection.DbCollection

        # test dunders
        assert collection_1 == collection_2
        assert collection_1 != collection_3
        assert len({collection_1, collection_2, collection_3
                    }) == 2  # testing `__hash__`
        print(repr(collection_1))
        for key in collection_1:
            print(collection_1[key])
        with pytest.raises(errors.XnetError):
            print(collection_1[test_cluster_name])
        with pytest.raises(TypeError):
            print(collection_1[5])

        # test '__del__' after using the add function
        cluster = db.clusters.add(test_cluster_name)
        assert (cluster == db.clusters[test_cluster_name])
        del db.clusters[test_cluster_name]
        with pytest.raises(errors.XnetError):
            print(db.clusters[test_cluster_name])

        # test container
        assert len(list(collection_1.keys())) > 0
        assert len(list(collection_1.values())) > 0
        assert len(list(collection_1.items())) > 0
Beispiel #4
0
def test_signal_dbc_attributes():
    database_filepath = os.path.join(os.path.dirname(__file__), 'databases\\attributes.dbc')
    with database.Database(database_filepath) as db:
        cluster = db.clusters['Cluster']
        frame1 = cluster.frames['Msg1']
        sig1 = frame1.mux_static_signals['Sig1']
        sig2 = frame1.mux_static_signals['Sig2']

        # test dunders
        assert len(sig1.dbc_attributes) == 1
        assert len({sig1.dbc_attributes, sig1.dbc_attributes}) == 1  # testing `__hash__`
        assert len({sig1.dbc_attributes, sig2.dbc_attributes}) == 2  # testing `__hash__`
        assert sig1.dbc_attributes == sig1.dbc_attributes
        assert sig1.dbc_attributes != sig2.dbc_attributes
        for key in sig1.dbc_attributes:
            print(sig1.dbc_attributes[key])

        # test container
        assert sorted(sig2.dbc_attributes.keys()) == ['SigAttr1']
        assert sorted(sig2.dbc_attributes.values()) == [('11', False)]
        assert sorted(sig2.dbc_attributes.items()) == [('SigAttr1', ('11', False))]

        # test values
        assert sig1.dbc_attributes['SigAttr1'] == ('1', True)
        assert sig2.dbc_attributes['SigAttr1'] == ('11', False)
Beispiel #5
0
def test_database_signal_properties():
    with database.Database('NIXNET_example') as db:
        signal = db.find(database.Signal, 'CANCyclicSignal1')  # type: database.Signal

        # test references
        print(signal.frame)
        print(signal.pdu)
        with pytest.raises(errors.XnetError):
            print(signal.mux_subfrm)

        # test setters
        signal.byte_ordr = constants.SigByteOrdr.BIG_ENDIAN
        signal.data_type = constants.SigDataType.IEEE_FLOAT
        signal.comment = 'This is a comment.'
        signal.default = signal.default
        signal.max = signal.max
        signal.min = signal.min
        signal.name = 'NewSignalName'
        signal.num_bits = signal.num_bits
        signal.scale_fac = signal.scale_fac
        signal.scale_off = signal.scale_off
        signal.start_bit = signal.start_bit
        signal.unit = 'Volts'
        signal.mux_is_data_mux = signal.mux_is_data_mux

        # test getters
        print(signal.byte_ordr)
        print(signal.comment)
        print(signal.data_type)
        print(signal.name)
        print(signal.name_unique_to_cluster)
        print(signal.unit)
        print(signal.mux_is_dynamic)
        print(signal.mux_value)
Beispiel #6
0
def test_database_frame_properties_common():
    with database.Database('NIXNET_example') as db:
        frame = db.find(database.Frame,
                        'CANCyclicFrame1')  # type: database.Frame

        # test references
        print(frame.cluster)
        assert len(list(frame.sigs)) > 0
        assert len(list(frame.pdu_properties)) > 0
        assert len(frame.mux_static_signals) > 0
        assert len(frame.mux_subframes) == 0
        with pytest.raises(errors.XnetError):
            print(frame.mux_data_mux_sig)

        # test setters
        frame.application_protocol = constants.AppProtocol.NONE
        frame.comment = 'This is a comment.'
        frame.default_payload = list(frame.default_payload)
        frame.id = frame.id
        frame.name = 'NewFrameName'
        frame.payload_len = frame.payload_len
        frame.variable_payload = frame.variable_payload

        # test getters
        print(frame.application_protocol)
        print(frame.comment)
        print(frame.name)
        print(frame.mux_is_muxed)
Beispiel #7
0
def test_database_frame_properties_can():
    with database.Database('NIXNET_example') as db:
        frame = db.find(database.Frame,
                        'CANCyclicFrame1')  # type: database.Frame
        frame.can_ext_id = frame.can_ext_id
        frame.can_tx_time = frame.can_tx_time
        frame.can_timing_type = constants.FrmCanTiming.CYCLIC_DATA
        print(frame.can_timing_type)
Beispiel #8
0
def test_database_database_save():
    # Avoid using an installed example database for saving to ensure those aren't modified.
    # Instead, save the pre-existing 'attributes.dbc' database to a temp XML (FIBEX).
    input_filepath = os.path.join(os.path.dirname(__file__),
                                  'databases\\attributes.dbc')
    output_filepath = tempfile.NamedTemporaryFile(suffix='.xml',
                                                  delete=False).name
    with database.Database(input_filepath) as db:
        db.save(output_filepath)
def test_database_subframe_functions():
    with database.Database('NIXNET_example') as db:
        frame = db.find(database.Frame,
                        'CANCyclicFrame1')  # type: database.Frame
        subframe = frame.mux_subframes.add(
            'subframe1')  # type: database.SubFrame
        subframe.check_config_status()
        with pytest.raises(errors.XnetError):
            subframe.find(database.Signal, 'signal_name')
Beispiel #10
0
def test_database_frame_container():
    with database.Database('NIXNET_example') as db:
        cluster = db.clusters['CAN_Cluster']  # type: database.Cluster
        frame_1 = cluster.frames['CANCyclicFrame1']  # type: database.Frame
        frame_2 = cluster.frames['CANCyclicFrame1']  # type: database.Frame
        frame_3 = cluster.frames['CANCyclicFrame2']  # type: database.Frame

        # test dunders
        assert frame_1 == frame_2
        assert frame_1 != frame_3
        assert len({frame_1, frame_2, frame_3}) == 2  # testing `__hash__`
        print(repr(frame_1))
def test_database_lin_sched_container():
    with database.Database('NIXNET_exampleLDF') as db:
        cluster = db.clusters['Cluster']  # type: database.Cluster
        sched_1 = cluster.lin_schedules['FastSchedule']  # type: database.LinSched
        sched_2 = cluster.lin_schedules['FastSchedule']  # type: database.LinSched
        sched_3 = cluster.lin_schedules['SlowSchedule']  # type: database.LinSched

        # test dunders
        assert sched_1 == sched_2
        assert sched_1 != sched_3
        assert len({sched_1, sched_2, sched_3}) == 2  # testing `__hash__`
        print(repr(sched_1))
Beispiel #12
0
def test_database_ecu_container():
    with database.Database('NIXNET_example') as db:
        cluster = db.clusters['CAN_Demo_Box_Cluster']  # type: database.Cluster
        ecu_1 = cluster.ecus['CAN_Demo_Box']  # type: database.Ecu
        ecu_2 = cluster.ecus['CAN_Demo_Box']  # type: database.Ecu
        ecu_3 = cluster.ecus['PC_Master']  # type: database.Ecu

        # test dunders
        assert ecu_1 == ecu_2
        assert ecu_1 != ecu_3
        assert len({ecu_1, ecu_2, ecu_3}) == 2  # testing `__hash__`
        print(repr(ecu_1))
Beispiel #13
0
def test_database_pdu_container():
    with database.Database('NIXNET_example') as db:
        cluster = db.clusters['CAN_Cluster']  # type: database.Cluster
        pdu_1 = cluster.pdus['CANCyclicFrame1_pdu']  # type: database.Pdu
        pdu_2 = cluster.pdus['CANCyclicFrame1_pdu']  # type: database.Pdu
        pdu_3 = cluster.pdus['CANCyclicFrame2_pdu']  # type: database.Pdu

        # test dunders
        assert pdu_1 == pdu_2
        assert pdu_1 != pdu_3
        assert len({pdu_1, pdu_2, pdu_3}) == 2  # testing `__hash__`
        print(repr(pdu_1))
Beispiel #14
0
def test_database_signal_container():
    with database.Database('NIXNET_example') as db:
        cluster = db.clusters['CAN_Cluster']  # type: database.Cluster
        frame = cluster.frames['CANCyclicFrame1']  # type: database.Frame
        sig_1 = frame.mux_static_signals['CANCyclicSignal1']  # type: database.Signal
        sig_2 = frame.mux_static_signals['CANCyclicSignal1']  # type: database.Signal
        sig_3 = frame.mux_static_signals['CANCyclicSignal2']  # type: database.Signal

        # test dunders
        assert sig_1 == sig_2
        assert sig_1 != sig_3
        assert len({sig_1, sig_2, sig_3}) == 2  # testing `__hash__`
        print(repr(sig_1))
def test_database_lin_sched_entry_container():
    with database.Database('NIXNET_exampleLDF') as db:
        cluster = db.clusters['Cluster']  # type: database.Cluster
        sched = cluster.lin_schedules['FastSchedule']  # type: database.LinSched
        entry_1 = sched.entries['se1']  # type: database.LinSchedEntry
        entry_2 = sched.entries['se1']  # type: database.LinSchedEntry
        entry_3 = sched.entries['se2']  # type: database.LinSchedEntry

        # test dunders
        assert entry_1 == entry_2
        assert entry_1 != entry_3
        assert len({entry_1, entry_2, entry_3}) == 2  # testing `__hash__`
        print(repr(entry_1))
Beispiel #16
0
def test_database_ecu_properties():
    with database.Database('NIXNET_exampleLDF') as db:
        ecu = db.find(database.Ecu, 'Master1')  # type: database.Ecu

        # test references
        assert len(list(ecu.rx_frms)) > 0
        assert len(list(ecu.tx_frms)) > 0

        # test setters
        ecu.comment = 'This is a comment.'
        ecu.name = 'NewEcuName'

        # test getters
        print(ecu.clst)
        print(ecu.comment)
        print(ecu.name)
def test_database_subframe_container():
    with database.Database('NIXNET_example') as db:
        cluster = db.clusters['CAN_Cluster']  # type: database.Cluster
        frame = cluster.frames['CANCyclicFrame1']  # type: database.Frame
        subframe_1 = frame.mux_subframes.add(
            'subframe1')  # type: database.SubFrame
        subframe_2 = frame.find(database.SubFrame,
                                'subframe1')  # type: database.SubFrame
        subframe_3 = frame.mux_subframes.add(
            'subframe3')  # type: database.SubFrame

        # test dunders
        assert subframe_1 == subframe_2
        assert subframe_1 != subframe_3
        assert len({subframe_1, subframe_2, subframe_3
                    }) == 2  # testing `__hash__`
        print(repr(subframe_1))
def test_database_lin_sched_properties():
    with database.Database('NIXNET_exampleLDF') as db:
        sched = db.find(database.LinSched, 'FastSchedule')  # type: database.LinSched

        # test references
        print(sched.clst)
        assert len(sched.entries) > 0

        # test setters
        sched.comment = 'This is a comment.'
        sched.name = 'NewScheduleName'
        sched.priority = sched.priority
        sched.run_mode = constants.LinSchedRunMode.NULL

        # test getters
        print(sched.comment)
        print(sched.name)
        print(sched.run_mode)
def test_database_subframe_properties():
    with database.Database('NIXNET_example') as db:
        frame = db.find(database.Frame,
                        'CANCyclicFrame1')  # type: database.Frame
        subframe = frame.mux_subframes.add(
            'subframe1')  # type: database.SubFrame

        # test references
        print(subframe.frm)
        print(subframe.pdu)
        assert len(subframe.dyn_signals) == 0

        # test setters
        subframe.mux_value = 1
        subframe.name = 'NewSubframeName'

        # test getters
        print(subframe.mux_value)
        print(subframe.name)
        print(subframe.name_unique_to_cluster)
def test_database_lin_sched_entry_properties():
    with database.Database('NIXNET_exampleLDF') as db:
        entry = db.find(database.LinSchedEntry, 'se1')  # type: database.LinSchedEntry

        # test references
        assert len(list(entry.frames)) > 0
        print(entry.sched)
        with pytest.raises(errors.XnetError):
            print(entry.collision_res_sched)

        # test setters
        entry.delay = entry.delay
        entry.event_id = 1
        entry.name = 'NewEntryName'
        entry.type = entry.type

        # test getters
        print(entry.event_id)
        print(entry.name)
        print(entry.name_unique_to_cluster)
Beispiel #21
0
def test_database_ecu_properties_lin():
    with database.Database('NIXNET_exampleLDF') as db:
        ecu = db.find(database.Ecu, 'Master1')  # type: database.Ecu

        # test setters
        ecu.lin_master = ecu.lin_master
        ecu.lin_protocol_ver = constants.LinProtocolVer.VER_2_1
        ecu.lin_initial_nad = 0
        ecu.lin_config_nad = 0
        ecu.lin_supplier_id = 0
        ecu.lin_function_id = 0
        ecu.lin_p2_min = 0
        ecu.lin_st_min = 0

        # test getters
        print(ecu.lin_protocol_ver)
        print(ecu.lin_initial_nad)
        print(ecu.lin_config_nad)
        print(ecu.lin_supplier_id)
        print(ecu.lin_function_id)
        print(ecu.lin_p2_min)
        print(ecu.lin_st_min)
Beispiel #22
0
def test_database_pdu_properties():
    with database.Database('NIXNET_example') as db:
        pdu = db.find(database.Pdu,
                      'CANCyclicFrame1_pdu')  # type: database.Pdu

        # test references
        print(pdu.cluster)
        assert len(list(pdu.frms)) > 0
        assert len(pdu.signals) > 0
        assert len(list(pdu.mux_static_sigs)) > 0
        assert len(list(pdu.mux_subframes)) == 0
        with pytest.raises(errors.XnetError):
            print(pdu.mux_data_mux_sig)

        # test setters
        pdu.comment = 'This is a comment.'
        pdu.name = 'NewPduName'
        pdu.payload_len = pdu.payload_len

        # test getters
        print(pdu.comment)
        print(pdu.name)
        print(pdu.mux_is_muxed)
Beispiel #23
0
def test_cluster_dbc_attributes():
    database_filepath = os.path.join(os.path.dirname(__file__), 'databases\\attributes.dbc')
    with database.Database(database_filepath) as db:
        cluster = db.clusters['Cluster']
        frame1 = cluster.frames['Msg1']

        # test dunders
        assert len(cluster.dbc_attributes) == 2
        assert len({cluster.dbc_attributes, cluster.dbc_attributes}) == 1  # testing `__hash__`
        assert len({cluster.dbc_attributes, frame1.dbc_attributes}) == 2  # testing `__hash__`
        assert cluster.dbc_attributes == cluster.dbc_attributes
        assert cluster.dbc_attributes != frame1.dbc_attributes
        for key in cluster.dbc_attributes:
            print(cluster.dbc_attributes[key])

        # test container
        assert sorted(cluster.dbc_attributes.keys()) == ['BusType', 'NetworkAttr1']
        assert sorted(cluster.dbc_attributes.values()) == [('CAN', True), ('abc', True)]
        assert sorted(cluster.dbc_attributes.items()) == [('BusType', ('CAN', True)), ('NetworkAttr1', ('abc', True))]

        # test values
        assert cluster.dbc_attributes['BusType'] == ('CAN', True)
        assert cluster.dbc_attributes['NetworkAttr1'] == ('abc', True)
Beispiel #24
0
def test_ecu_dbc_attributes():
    database_filepath = os.path.join(os.path.dirname(__file__), 'databases\\attributes.dbc')
    with database.Database(database_filepath) as db:
        cluster = db.clusters['Cluster']
        ecu1 = cluster.ecus['ECU1']
        ecu2 = cluster.ecus['ECU2']

        # test dunders
        assert len(ecu1.dbc_attributes) == 1
        assert len({ecu1.dbc_attributes, ecu1.dbc_attributes}) == 1  # testing `__hash__`
        assert len({ecu1.dbc_attributes, ecu2.dbc_attributes}) == 2  # testing `__hash__`
        assert ecu1.dbc_attributes == ecu1.dbc_attributes
        assert ecu1.dbc_attributes != ecu2.dbc_attributes
        for key in ecu1.dbc_attributes:
            print(ecu1.dbc_attributes[key])

        # test container
        assert sorted(ecu1.dbc_attributes.keys()) == ['EcuAttr1']
        assert sorted(ecu1.dbc_attributes.items()) == [('EcuAttr1', ('xEcu1', True))]
        assert sorted(ecu1.dbc_attributes.values()) == [('xEcu1', True)]

        # test values
        assert ecu1.dbc_attributes['EcuAttr1'] == ('xEcu1', True)
        assert ecu2.dbc_attributes['EcuAttr1'] == ('xEcu2-Set', False)
Beispiel #25
0
def test_frame_dbc_attributes():
    database_filepath = os.path.join(os.path.dirname(__file__), 'databases\\attributes.dbc')
    with database.Database(database_filepath) as db:
        cluster = db.clusters['Cluster']
        frame1 = cluster.frames['Msg1']
        frame2 = cluster.frames['Msg2']

        # test dunders
        assert len(frame1.dbc_attributes) == 4
        assert len({frame1.dbc_attributes, frame1.dbc_attributes}) == 1  # testing `__hash__`
        assert len({frame1.dbc_attributes, frame2.dbc_attributes}) == 2  # testing `__hash__`
        assert frame1.dbc_attributes == frame1.dbc_attributes
        assert frame1.dbc_attributes != frame2.dbc_attributes
        for key in frame1.dbc_attributes:
            print(frame1.dbc_attributes[key])

        # test container
        assert sorted(frame1.dbc_attributes.keys()) == ['MsgAttr1', 'MsgAttr2', 'MsgAttr3', 'MsgAttr4']
        assert sorted(frame1.dbc_attributes.values()) == [('-11.1', True),
                                                          ('2', True),
                                                          ('2', True),
                                                          ('DefaultMsgAttr3String', True)]
        assert sorted(frame1.dbc_attributes.items()) == [('MsgAttr1', ('2', True)),
                                                         ('MsgAttr2', ('-11.1', True)),
                                                         ('MsgAttr3', ('DefaultMsgAttr3String', True)),
                                                         ('MsgAttr4', ('2', True))]

        # test values
        assert frame1.dbc_attributes['MsgAttr1'] == ('2', True)
        assert frame1.dbc_attributes['MsgAttr2'] == ('-11.1', True)
        assert frame1.dbc_attributes['MsgAttr3'] == ('DefaultMsgAttr3String', True)
        assert frame1.dbc_attributes['MsgAttr4'] == ('2', True)
        assert frame2.dbc_attributes['MsgAttr1'] == ('22', False)
        assert frame2.dbc_attributes['MsgAttr2'] == ('-23.33', False)
        assert frame2.dbc_attributes['MsgAttr3'] == ('MsgAttr3String', False)
        assert frame2.dbc_attributes['MsgAttr4'] == ('1', False)
Beispiel #26
0
def main():
    database_name = ':memory:'
    cluster_name = 'LIN_Cluster'
    ecu_1_name = 'LIN_ECU_1'
    ecu_2_name = 'LIN_ECU_2'
    schedule_name = 'LIN_Schedule_1'
    schedule_entry_name = 'LIN_Schedule_Entry'
    frame_name = 'LIN_Frame'
    signal_1_name = 'LIN_Signal_1'
    signal_2_name = 'LIN_Signal_2'
    signal_list = [signal_1_name, signal_2_name]
    output_interface = 'LIN1'
    input_interface = 'LIN2'

    # Open the default in-memory database.
    with database.Database(database_name) as db:

        # Add a LIN cluster, a frame, and two signals to the database.
        cluster = db.clusters.add(cluster_name)
        cluster.protocol = constants.Protocol.LIN
        cluster.baud_rate = 19200
        frame = cluster.frames.add(frame_name)
        frame.id = 1
        frame.payload_len = 2
        signal_1 = frame.mux_static_signals.add(signal_1_name)
        signal_1.byte_ordr = constants.SigByteOrdr.BIG_ENDIAN
        signal_1.data_type = constants.SigDataType.UNSIGNED
        signal_1.start_bit = 0
        signal_1.num_bits = 8
        signal_2 = frame.mux_static_signals.add(signal_2_name)
        signal_2.byte_ordr = constants.SigByteOrdr.BIG_ENDIAN
        signal_2.data_type = constants.SigDataType.UNSIGNED
        signal_2.start_bit = 8
        signal_2.num_bits = 8

        # Add a LIN ECU and LIN Schedule to the cluster.
        ecu_1 = cluster.ecus.add(ecu_1_name)
        ecu_1.lin_protocol_ver = constants.LinProtocolVer.VER_2_2
        ecu_1.lin_master = True
        ecu_2 = cluster.ecus.add(ecu_2_name)
        ecu_2.lin_protocol_ver = constants.LinProtocolVer.VER_2_2
        ecu_2.lin_master = False
        cluster.lin_tick = 0.01
        schedule = cluster.lin_schedules.add(schedule_name)
        schedule.priority = 0
        schedule.run_mode = constants.LinSchedRunMode.CONTINUOUS
        schedule_entry = schedule.entries.add(schedule_entry_name)
        schedule_entry.delay = 1000.0
        schedule_entry.type = constants.LinSchedEntryType.UNCONDITIONAL
        schedule_entry.frames = [frame]

        # Using the database we just created, write and then read a pair of signals.
        with nixnet.SignalOutSinglePointSession(output_interface,
                                                database_name, cluster_name,
                                                signal_list) as output_session:
            with nixnet.SignalInSinglePointSession(
                    input_interface, database_name, cluster_name,
                    signal_list) as input_session:
                terminated_cable = six.moves.input(
                    'Are you using a terminated cable (Y or N)? ')
                if terminated_cable.lower() == "y":
                    input_session.intf.lin_term = constants.LinTerm.ON
                    output_session.intf.lin_term = constants.LinTerm.OFF
                elif terminated_cable.lower() == "n":
                    input_session.intf.lin_term = constants.LinTerm.ON
                    output_session.intf.lin_term = constants.LinTerm.ON
                else:
                    print("Unrecognised input ({}), assuming 'n'".format(
                        terminated_cable))
                    input_session.intf.lin_term = constants.LinTerm.ON
                    output_session.intf.lin_term = constants.LinTerm.ON

                # Start the input session manually to make sure that the first
                # signal values sent before the initial read will be received.
                input_session.start()

                # Set the schedule. This will also automatically enable master mode.
                output_session.change_lin_schedule(0)

                # Generate a pair of random values and send out the signals.
                output_values = [randint(0, 255), randint(0, 255)]
                output_session.signals.write(output_values)
                print('Sent signal values: {}'.format(output_values))

                # Wait 1 s and then read the received values.
                # They should be the same as the ones sent.
                time.sleep(1)

                input_signals = input_session.signals.read()
                input_values = [
                    int(value) for timestamp, value in input_signals
                ]
                print('Received signal values: {}'.format(input_values))
Beispiel #27
0
def test_database_frame_properties_lin():
    with database.Database('NIXNET_exampleLDF') as db:
        frame = db.find(database.Frame, 'MasterFrame1')  # type: database.Frame
        print(frame.lin_checksum)
Beispiel #28
0
def test_database_frame_functions():
    with database.Database('NIXNET_example') as db:
        frame = db.find(database.Frame,
                        'CANCyclicFrame1')  # type: database.Frame
        frame.check_config_status()
        frame.find(database.Signal, 'CANCyclicSignal1')
Beispiel #29
0
def test_database_database_properties():
    with database.Database('NIXNET_example') as db:
        assert len(db.clusters) > 0
        assert db.name == 'NIXNET_example'
        db.show_invalid_from_open = db.show_invalid_from_open
Beispiel #30
0
def test_database_database_find():
    with database.Database('NIXNET_example') as db:
        cluster = db.clusters['CAN_Cluster']  # type: database.Cluster
        frame_1 = cluster.frames['CANEventFrame1']
        frame_2 = db.find(database.Frame, 'CANEventFrame1')
        assert frame_1 == frame_2