def test_session_container():
    database_name = 'NIXNET_example'
    cluster_name = 'CAN_Cluster'
    signals = ['CANEventSignal1', 'CANEventSignal2']

    with convert.SignalConversionSinglePointSession(
            database_name,
            cluster_name,
            signals) as session:
        with convert.SignalConversionSinglePointSession(
                database_name,
                cluster_name,
                signals) as dup_session:
            assert session == session
            assert not (session == dup_session)
            assert not (session == 1)

            assert not (session != session)
            assert session != dup_session
            assert session != 1

        set([session])  # Testing `__hash__`

        print(repr(session))

    with pytest.warns(errors.XnetResourceWarning):
        session.close()
Пример #2
0
def test_conversion_roundtrip():
    database_name = 'NIXNET_example'
    cluster_name = 'CAN_Cluster'
    signal_names = ['CANEventSignal1', 'CANEventSignal2']

    with convert.SignalConversionSinglePointSession(database_name,
                                                    cluster_name,
                                                    signal_names) as session:

        expected_signals = [2, 3]
        frames = session.convert_signals_to_frames(expected_signals)
        converted_signals = session.convert_frames_to_signals(frames)
        for expected, (_, converted) in zip(expected_signals,
                                            converted_signals):
            assert pytest.approx(expected) == converted
Пример #3
0
def test_conversion_multiframe():
    database_name = 'NIXNET_example'
    cluster_name = 'CAN_Cluster'
    signal_names = [
        'CANCyclicSignal1', 'CANCyclicSignal3', 'CANEventSignal2',
        'CANEventSignal4', 'Speedometer', 'TransmissionOilTemp'
    ]

    with convert.SignalConversionSinglePointSession(database_name,
                                                    cluster_name,
                                                    signal_names) as session:

        expected_signals = [2, 3, 4, 5, 39.06, 16]
        frames = session.convert_signals_to_frames(expected_signals)
        converted_signals = session.convert_frames_to_signals(frames)
        for expected, (_, converted) in zip(expected_signals,
                                            converted_signals):
            assert pytest.approx(expected) == converted
Пример #4
0
def test_session_properties():
    """Verify Session properties.

    Ideally, mutable properties would be set to multiple values and we'd test
    for the intended side-effect.  That'll be a massive undertaking.  For now,
    ensure they are settable and getttable.
    """
    database_name = 'NIXNET_example'
    cluster_name = 'CAN_Cluster'
    signals = ['CANEventSignal1', 'CANEventSignal2']

    with convert.SignalConversionSinglePointSession(database_name,
                                                    cluster_name,
                                                    signals) as session:
        assert session.database_name == database_name
        assert session.cluster_name == cluster_name
        assert session.mode == constants.CreateSessionMode.SIGNAL_CONVERSION_SINGLE_POINT
        assert session.application_protocol == constants.AppProtocol.NONE
        assert session.protocol == constants.Protocol.CAN
Пример #5
0
def main():
    database_name = 'NIXNET_example'
    cluster_name = 'CAN_Cluster'
    signal_names = ['CANEventSignal1', 'CANEventSignal2']

    with convert.SignalConversionSinglePointSession(database_name,
                                                    cluster_name,
                                                    signal_names) as session:

        user_value = six.moves.input(
            'Enter {} signal values [float, float]: '.format(
                len(signal_names)))
        try:
            expected_signals = [
                float(x.strip()) for x in user_value.split(",")
            ]
        except ValueError:
            expected_signals = [24.5343, 77.0129]
            print('Unrecognized input ({}). Setting data buffer to {}'.format(
                user_value, expected_signals))

        if len(expected_signals) != len(signal_names):
            expected_signals = [24.5343, 77.0129]
            print(
                'Invalid number of signal values entered. Setting data buffer to {}'
                .format(expected_signals))

        frames = session.convert_signals_to_frames(expected_signals)
        print('Frames:')
        for frame in frames:
            print('    {}'.format(frame))
            print('        payload={}'.format(
                list(six.iterbytes(frame.payload))))

        converted_signals = session.convert_frames_to_signals(frames)
        print('Signals: {}'.format([v for (_, v) in converted_signals]))
Пример #6
0
def main():

    parser = argparse.ArgumentParser(
        description='Script used to test SOC gauge performance')
    #parser.add_argument('pos_current_lim', help="Choose the charger's positive current limit", type=float)
    ##parser.add_argument('neg_curr_lim', help="Choose the charger's negative current limit", type=float)
    #parser.add_argument('voltage_high', help='Choose what the high level charger voltage is', type=float)
    #parser.add_argument('voltage_low', help='Choose what the low level charger voltage is', type=float)
    parser.add_argument('profile_file',
                        help='Choose Test profile .csv file',
                        type=str)
    parser.add_argument('test_name', help='Choose name of the test', type=str)
    parser.add_argument('charger_visa_name',
                        help='Type in the charger VISA alias',
                        type=str)

    args = parser.parse_args()
    print('Profile chosen : {}'.format(args.profile_file))

    # Open Charger VISA open_resource
    rm = pyvisa.ResourceManager()
    charger_visa = rm.open_resource(args.charger_visa_name)
    # Open log file
    filename = args.test_name + '_' + str(today[1]) + '_' + str(
        today[2]) + '_' + str(today[3]) + str(today[4]) + '.csv'
    print("Opening log file as {}".format(filename))
    log_file = open(filename, 'w')
    header = "time,batt_voltage,batt_current,batt_soc,charger_voltage,charger_current\n"
    log_file.write(header)

    charger.visa = charger_visa
    print(charger.idn())
    charger.init()

    # Set up Profile State Machine
    local_path = os.path.dirname(os.path.abspath(__file__))
    filename = os.path.join(local_path, args.profile_file)

    with open(filename) as profile:
        test_profile = profile_state_machine(profile)
        test_profile.set_event_function(charger.set_charger_setpoints)

        # Setup LIN Sessions
        with nixnet.FrameInSinglePointSession(interface, database, cluster,
                                              frames) as session:
            with convert.SignalConversionSinglePointSession(
                    database, cluster, signals) as converter:

                session.intf.lin_term = constants.LinTerm.ON
                session.intf.lin_master = True

                def read_data_task(time):
                    """Aquires and Converts Telemetry data on the SCPI and LIN buses."""
                    # Read Telemetry
                    charger.read_data()
                    frame = session.frames.read(frame_type=types.LinFrame)

                    # Format Data
                    converted_signals = converter.convert_frames_to_signals(
                        frame)
                    batt.pack_data(time,
                                   *[float(v) for (_, v) in converted_signals])

                # Set the schedule. This will also automatically enable master mode.
                session.start()
                session.change_lin_schedule(schedule_index)
                time.sleep(1)

                # Setup charger
                # charger.set_curr_lim(0, 0)
                # charger.set_voltage(0)
                # charger.set_output('OFF')

                display_task = InfiniteTimer(DISPLAY_RATE, display_data_task)

                #daq_task = InfiniteTimer(SAMPLE_RATE, read_data_task)

                def exit_signal_handler(signal, frame):
                    print('Shutting Down...')
                    charger.set_output('OFF')
                    display_task.cancel()
                    #daq_task.cancel()
                    sys.exit()

                signal.signal(signal.SIGINT, exit_signal_handler)

                display_task.start()
                #daq_task.start()

                loop_count = 0
                start_time = time.time()
                next_step = 0

                while (1):
                    loop_start = time.time()
                    sample_time = loop_start - start_time
                    read_data_task(sample_time)

                    # Logging data
                    data_row = "{},{},{},{},{},{}\n".format(
                        sample_time, batt.voltage, batt.current, batt.soc,
                        charger.voltage, charger.current)
                    log_file.write(data_row)

                    #Feed profile state machine
                    test_profile.run_profile(batt)
                    if (test_profile.done):
                        print('Profile ended.')
                        print('Data acquisition stopped.')
                        log_file.close()
                        print('Shutting Down...')
                        charger.set_output('OFF')
                        display_task.cancel()
                        sys.exit()

                    loop_time = time.time() - loop_start
                    loop_wait = SAMPLE_RATE - loop_time
                    if (loop_wait < 0):
                        loop_wait = 0
                    time.sleep(loop_wait)

    print('Data acquisition stopped.')
Пример #7
0
def main():

    batt = battery('YUASA_30')

    def display_data_task():
        """Display latest data on console."""
        print(
            'Batt. Voltage = {:2.2f}V | Batt. Current = {:2.4f}A | Batt. temp = {:2.2f}C | Batt. SOC = {:2.2f}% | Q.Nom = {:2.2f}Ah | SOC.Recal = {}'
            .format(*(batt.list_data())))

    # Setup LIN Sessions
    with nixnet.FrameInSinglePointSession(interface, database, cluster,
                                          frames) as session:
        with convert.SignalConversionSinglePointSession(
                database, cluster, signals) as converter:

            session.intf.lin_term = constants.LinTerm.ON
            session.intf.lin_master = True

            def read_data_task():
                """Aquires and Converts Telemetry data on the SCPI and LIN buses."""
                # Read Telemetry
                frame = session.frames.read(frame_type=types.LinFrame)

                # Format Data
                converted_signals = converter.convert_frames_to_signals(frame)
                batt.pack_data(*[float(v) for (_, v) in converted_signals])

            # Set the schedule. This will also automatically enable master mode.
            session.start()

            session.change_lin_schedule(lin_schedule)
            time.sleep(1)

            display_task = InfiniteTimer(DISPLAY_RATE, display_data_task)

            def exit_signal_handler(signal, frame):
                print('Shutting Down...')
                display_task.cancel()
                #daq_task.cancel()
                sys.exit()

            signal.signal(signal.SIGINT, exit_signal_handler)

            display_task.start()
            #daq_task.start()

            loop_count = 0
            start_time = time.time()
            next_step = 0

            while (1):
                loop_start = time.time()
                sample_time = loop_start - start_time

                read_data_task()
                # status = session.num_unused
                # print(status)
                loop_time = time.time() - loop_start
                loop_wait = SAMPLE_RATE - loop_time
                if (loop_wait < 0):
                    loop_wait = 0
                time.sleep(loop_wait)

    print('Data acquisition stopped.')