Example #1
0
def run():
    channel = grpc.insecure_channel('127.0.0.1:50051')
    network_stub = network_api_pb2_grpc.NetworkServiceStub(channel)
    system_stub = system_api_pb2_grpc.SystemServiceStub(channel)
    check_license(system_stub)
    # request_license(system_stub)
    # download_and_install_license(system_stub, "your_emailed_hash_without_quotes")
    
    upload_folder(system_stub, "configuration_udp")
    # upload_folder(system_stub, "configuration")
    reload_configuration(system_stub)

    # list available signals
    configuration = system_stub.GetConfiguration(common_pb2.Empty())
    for networkInfo in configuration.networkInfo:
        print("signals in namespace ", networkInfo.namespace.name, system_stub.ListSignals(networkInfo.namespace))

    ecu_A_thread  = Thread(target = ecu_A, args = (network_stub, 1,))
    ecu_A_thread.start()

    ecu_B_thread_read  = Thread(target = ecu_B_read, args = (network_stub, 1,))
    ecu_B_thread_read.start()

    ecu_B_thread_subscribe  = Thread(target = ecu_B_subscribe, args = (network_stub,))
    ecu_B_thread_subscribe.start()

    ecu_B_thread_subscribe_2  = Thread(target = ecu_B_subscribe_2, args = (network_stub,))
    ecu_B_thread_subscribe_2.start()

    read_signals = [common_pb2.SignalId(name="counter", namespace=common_pb2.NameSpace(name = "ecu_A")), common_pb2.SignalId(name="TestFr06_Child02", namespace=common_pb2.NameSpace(name = "ecu_A"))]
    ecu_read_demo  = Thread(target = read_on_timer, args = (network_stub, read_signals, 10))
    ecu_read_demo.start()
Example #2
0
def run():
    #     channel = grpc.insecure_channel('192.168.1.82:50051')
    channel = grpc.insecure_channel("192.168.1.184:50051")
    functional_stub = functional_api_pb2_grpc.FunctionalServiceStub(channel)
    network_stub = network_api_pb2_grpc.NetworkServiceStub(channel)
    diag_stub = diagnostics_api_pb2_grpc.DiagnosticsServiceStub(channel)
    system_stub = system_api_pb2_grpc.SystemServiceStub(channel)

    #     print("-------------- Subsribe to fan speed BLOCKING --------------")
    #     subscribe_to_fan_signal(network_stub)

    print("-------------- upload folder and reload--------------")
    #     upload_folder(system_stub, "../../../../configurations/demo-torslanda")
    #     upload_folder(system_stub, "../../../../configurations/mountainview")
    upload_folder(system_stub, "../../../../configurations/vanilla-osx")
    reload_configuration(system_stub)
Example #3
0
def run():
    channel = grpc.insecure_channel("127.0.0.1:50051")
    network_stub = network_api_pb2_grpc.NetworkServiceStub(channel)
    diag_stub = diagnostics_api_pb2_grpc.DiagnosticsServiceStub(channel)
    system_stub = system_api_pb2_grpc.SystemServiceStub(channel)

    upload_folder(system_stub, "configuration")
    reload_configuration(system_stub)

    # print("-------------- Subsribe to fan speed BLOCKING --------------")
    # subscribe_to_fan_signal(network_stub)

    # print("-------------- Read Diagnostics --------------")
    # read_diagnostics_vin(diag_stub)
    #
    # print("-------------- Read Diagnostics --------------")
    read_diagnostics_odb(diag_stub)
def run():
    channel = grpc.insecure_channel('192.168.1.184:50051')
    network_stub = network_api_pb2_grpc.NetworkServiceStub(channel)
    system_stub = system_api_pb2_grpc.SystemServiceStub(channel)
    client_id = common_pb2.ClientId(id="app_identifier")

    # If you need to change the id of the req/resp modify here configuration/can/diagnostics.dbc
    diag_frame_req = common_pb2.SignalId(
        name="DiagReqFrame_2016",
        namespace=common_pb2.NameSpace(name="DiagnosticsCanInterface"))
    diag_frame_resp = signal = common_pb2.SignalId(
        name="DiagResFrame_2024",
        namespace=common_pb2.NameSpace(name="DiagnosticsCanInterface"))

    upload_folder(system_stub, "configuration")
    reload_configuration(system_stub)

    print(
        "-------------- Subscribe to diag_req, on request submit resp_frame --------------"
    )
    subscribe_to_diag(client_id, network_stub, diag_frame_req, diag_frame_resp)
Example #5
0
def run(argv):
    # This script will use below ip-address if no argument is passed to the script
    ip = "127.0.0.1"
    # Keep this port
    port = ":50051"
    try:
        opts, args = getopt.getopt(argv, "h", ["ip="])
    except getopt.GetoptError:
        print("Usage: resp_to_diag_req.py --ip <ip_address>")
        sys.exit(2)
    for opt, arg in opts:
        if opt == "-h":
            print("Usage: resp_to_diag_req.py --ip <ip_address>")
            sys.exit(2)
        elif opt == "--ip":
            ip = arg

    channel = grpc.insecure_channel(ip + port)
    network_stub = network_api_pb2_grpc.NetworkServiceStub(channel)
    system_stub = system_api_pb2_grpc.SystemServiceStub(channel)
    client_id = common_pb2.ClientId(id="app_identifier")

    # If you need to change the id of the req/resp modify here configuration/can/diagnostics.dbc
    diag_frame_req = common_pb2.SignalId(
        name="DiagReqFrame_2016",
        namespace=common_pb2.NameSpace(name="DiagnosticsCanInterface"),
    )
    diag_frame_resp = signal = common_pb2.SignalId(
        name="DiagResFrame_2024",
        namespace=common_pb2.NameSpace(name="DiagnosticsCanInterface"),
    )

    upload_folder(system_stub, "configuration")
    reload_configuration(system_stub)

    print(
        "-------------- Subscribe to diag_req, on request submit resp_frame --------------"
    )
    subscribe_to_diag(client_id, network_stub, diag_frame_req, diag_frame_resp)
def run(ip, port):
    """Main function, checking arguments passed to script, setting up stubs, configuration and starting Threads."""
    # Setting up stubs and configuration
    channel = grpc.insecure_channel(ip + ":" + port)
    network_stub = network_api_pb2_grpc.NetworkServiceStub(channel)
    diag_stub = diagnostics_api_pb2_grpc.DiagnosticsServiceStub(channel)
    system_stub = system_api_pb2_grpc.SystemServiceStub(channel)
    check_license(system_stub)

    upload_folder(system_stub, "configuration")
    reload_configuration(system_stub)

    global signal_creator
    signal_creator = SignalCreator(system_stub)

    # print("-------------- Subsribe to fan speed BLOCKING --------------")
    # subscribe_to_fan_signal(network_stub)

    print("-------------- Read Diagnostics vin --------------")
    read_diagnostics_vin(diag_stub)

    print("-------------- Read Diagnostics BLOCKING--------------")
    read_diagnostics_odb(diag_stub)
def run(argv):
    """Main function, checking arguments passed to script, setting up stubs, configuration and starting Threads.

    Parameters
    ----------
    argv : list
        Arguments passed when starting script

    """
    # Checks argument passed to script, ecu_advanced.py will use below ip-address if no argument is passed to the script
    ip = "127.0.0.1"
    # Keep this port
    port = ":50051"
    try:
        opts, args = getopt.getopt(argv, "h", ["ip="])
    except getopt.GetoptError:
        print("Usage: ecu_advanced.py --ip <ip_address>")
        sys.exit(2)
    for opt, arg in opts:
        if opt == "-h":
            print("Usage: ecu_advanced.py --ip <ip_address>")
            sys.exit(2)
        elif opt == "--ip":
            ip = arg

    # Setting up stubs and configuration
    # allows to custom set message max size. (default 4Mb, 4194304)
    # MAX_MESSAGE_LENGTH = 6000000
    # channel = grpc.insecure_channel('127.0.0.1:50051', options=[
    #     ('grpc.max_send_message_length', MAX_MESSAGE_LENGTH),
    #     ('grpc.max_receive_message_length', MAX_MESSAGE_LENGTH),
    #     ],
    # )
    channel = grpc.insecure_channel(ip + port)
    network_stub = network_api_pb2_grpc.NetworkServiceStub(channel)
    system_stub = system_api_pb2_grpc.SystemServiceStub(channel)
    check_license(system_stub)
    # request_license(system_stub)
    # download_and_install_license(system_stub, "your_emailed_hash")

    upload_folder(system_stub, "configuration_udp")
    # upload_folder(system_stub, "configuration_lin")
    # upload_folder(system_stub, "configuration_can")
    reload_configuration(system_stub)

    # Lists available signals
    configuration = system_stub.GetConfiguration(common_pb2.Empty())
    for networkInfo in configuration.networkInfo:
        print(
            "signals in namespace ",
            networkInfo.namespace.name,
            system_stub.ListSignals(networkInfo.namespace),
        )

    # Starting Threads
    ecu_A_thread = Thread(
        target=ecu_A,
        args=(
            network_stub,
            1,
        ),
    )
    ecu_A_thread.start()

    ecu_B_thread_read = Thread(
        target=ecu_B_read,
        args=(
            network_stub,
            1,
        ),
    )
    ecu_B_thread_read.start()

    ecu_B_thread_subscribe = Thread(target=ecu_B_subscribe, args=(network_stub,))
    ecu_B_thread_subscribe.start()

    ecu_B_thread_subscribe_2 = Thread(target=ecu_B_subscribe_2, args=(network_stub,))
    ecu_B_thread_subscribe_2.start()

    read_signals = [
        common_pb2.SignalId(
            name="counter", namespace=common_pb2.NameSpace(name="ecu_A")
        ),
        common_pb2.SignalId(
            name="TestFr06_Child02", namespace=common_pb2.NameSpace(name="ecu_A")
        ),
    ]
    ecu_read_on_timer = Thread(
        target=read_on_timer, args=(network_stub, read_signals, 10)
    )
    ecu_read_on_timer.start()
Example #8
0
def run(argv):
    """Main function, checking arguments passed to script, setting up stubs, configuration and starting Threads.

    Parameters
    ----------
    argv : list
        Arguments passed when starting script

    """
    # Checks argument passed to script, ecu.py will use below ip-address if no argument is passed to the script
    ip = "127.0.0.1"
    # Keep this port
    port = ":50051"
    try:
        opts, args = getopt.getopt(argv, "h", ["ip="])
    except getopt.GetoptError:
        print("Usage: ecu.py --ip <ip_address>")
        sys.exit(2)
    for opt, arg in opts:
        if opt == "-h":
            print("Usage: ecu.py --ip <ip_address>")
            sys.exit(2)
        elif opt == "--ip":
            ip = arg

    # Setting up stubs and configuration
    channel = grpc.insecure_channel(ip + port)
    network_stub = network_api_pb2_grpc.NetworkServiceStub(channel)
    system_stub = system_api_pb2_grpc.SystemServiceStub(channel)
    check_license(system_stub)

    upload_folder(system_stub, "configuration_udp")
    # upload_folder(system_stub, "configuration_lin")
    # upload_folder(system_stub, "configuration_can")
    reload_configuration(system_stub)

    # Lists available signals
    configuration = system_stub.GetConfiguration(common_pb2.Empty())
    for networkInfo in configuration.networkInfo:
        print(
            "signals in namespace ",
            networkInfo.namespace.name,
            system_stub.ListSignals(networkInfo.namespace),
        )

    # Starting Threads
    ecu_A_thread = Thread(
        target=ecu_A,
        args=(
            network_stub,
            1,
        ),
    )
    ecu_A_thread.start()

    ecu_B_thread_read = Thread(
        target=ecu_B_read,
        args=(
            network_stub,
            1,
        ),
    )
    ecu_B_thread_read.start()

    ecu_B_thread_subscribe = Thread(target=ecu_B_subscribe,
                                    args=(network_stub, ))
    ecu_B_thread_subscribe.start()
Example #9
0
def run(argv):
    """Main function, checking arguments passed to script, setting up stubs, configuration and starting Threads.

    Parameters
    ----------
    argv : list
        Arguments passed when starting script

    """
    global ip
    global port
    global playbacklist
    # Checks argument passed to script, playback.py will use below ip-address if no argument is passed to the script
    ip = "127.0.0.1"
    # Keep this port
    port = ":50051"
    try:
        opts, args = getopt.getopt(argv, "h", ["ip="])
    except getopt.GetoptError:
        print("Usage: playback.py --ip <ip_address>")
        sys.exit(2)
    for opt, arg in opts:
        if opt == "-h":
            print("Usage: playback.py --ip <ip_address>")
            sys.exit(2)
        elif opt == "--ip":
            ip = arg

    # To do a clean exit of the script on CTRL+C
    signal.signal(signal.SIGINT, exit_handler)

    # Setting up stubs and configuration
    channel = grpc.insecure_channel(ip + port)
    network_stub = network_api_pb2_grpc.NetworkServiceStub(channel)
    traffic_stub = traffic_api_pb2_grpc.TrafficServiceStub(channel)
    system_stub = system_api_pb2_grpc.SystemServiceStub(channel)
    # check_license(system_stub)

    upload_folder(system_stub, "configuration_custom_udp")
    reload_configuration(system_stub)
    # Give us some time to see it all went according to plan
    time.sleep(1)

    # Lists available signals
    configuration = system_stub.GetConfiguration(common_pb2.Empty())
    for networkInfo in configuration.networkInfo:
        print(
            "signals in namespace ",
            networkInfo.namespace.name,
            system_stub.ListSignals(networkInfo.namespace),
        )

    # Optonally start threads
    # ecu_B_thread_subscribe = Thread(target=ecu_B_subscribe_, args=(network_stub,))
    # ecu_B_thread_subscribe.start()

    # ecu_B_thread_read = Thread(
    #     target=ecu_B_read,
    #     args=(
    #         network_stub,
    #         1,
    #     ),
    # )
    # ecu_B_thread_read.start()

    upload_file(
        system_stub,
        "recordings/traffic.log",
        "recordings/candump_uploaded.log",
    )

    recordlist = [
        {
            "namespace": "custom_can",
            "path": "recordings/candump_uploaded_recorded.log",
            "mode": traffic_api_pb2.Mode.RECORD,
        },
    ]
    status_record = traffic_stub.PlayTraffic(
        traffic_api_pb2.PlaybackInfos(
            playbackInfo=list(map(create_playback_config, recordlist))))
    print("record traffic result is ", status_record)

    playbacklist = [
        {
            "namespace": "custom_can",
            "path": "recordings/candump_uploaded.log",
            "mode": traffic_api_pb2.Mode.PLAY,
        },
        {
            "namespace": "ecu_A",
            "path": "recordings/candump.log",
            "mode": traffic_api_pb2.Mode.PLAY,
        },
        {
            "namespace": "ecu_C",
            "path": "recordings/candump_.log",
            "mode": traffic_api_pb2.Mode.PLAY,
        },
    ]
    # expect candump_.log does not exist, thus error string will be returned
    status = traffic_stub.PlayTraffic(
        traffic_api_pb2.PlaybackInfos(
            playbackInfo=list(map(create_playback_config, playbacklist))))
    print("play traffic result is ", status)

    time.sleep(5)

    recordlist = [
        {
            "namespace": "custom_can",
            "path": "recordings/candump_uploaded_recorded.log",
            "mode": traffic_api_pb2.Mode.STOP,
        },
    ]
    status_record = traffic_stub.PlayTraffic(
        traffic_api_pb2.PlaybackInfos(
            playbackInfo=list(map(create_playback_config, recordlist))))

    # now stop recording and download the recorded file
    download_file(
        system_stub,
        "recordings/candump_uploaded_recorded.log",
        "candump_uploaded_recorded_downloaded.log",
    )
    print("file is now downloaded")
Example #10
0
def run(ip, port):
    """Main function, checking arguments passed to script, setting up stubs, configuration and starting Threads."""
    # Setting up stubs and configuration
    channel = grpc.insecure_channel(ip + ":" + port)
    network_stub = network_api_pb2_grpc.NetworkServiceStub(channel)
    system_stub = system_api_pb2_grpc.SystemServiceStub(channel)
    check_license(system_stub)

    # upload_folder(system_stub, "configuration_udp")
    # upload_folder(system_stub, "configuration_lin")
    upload_folder(system_stub, "configuration_can")
    # upload_folder(system_stub, "configuration_canfd")
    reload_configuration(system_stub)

    global signal_creator
    signal_creator = SignalCreator(system_stub)

    # Starting Threads

    #####################################################################
    # ECU under test (DUT) is located on namespace ecu_B which and it's
    # specified behaviour is just to to bounce (emit) counter_times_2 as soon as
    # counter arrive
    ecu_under_test_id = common_pb2.ClientId(id="ecu_under_test_id")
    ecu_under_test_namespace = "ecu_B"

    def bounce(network_stub, client_id, trigger, signals):
        global time_stamp_ref
        global time_diff_a_b
        for signal in signals:
            if signal.id == trigger:
                publish_signals(
                    client_id,
                    network_stub,
                    [
                        signal_creator.signal_with_payload(
                            "counter_times_2",
                            ecu_under_test_namespace,
                            ("integer", get_value(signal)),
                        ),
                    ],
                )
                if time_stamp_ref != {} and (get_value(signal)
                                             == get_value(time_stamp_ref)):
                    print(
                        f"time difference (counter @ {time_stamp_ref.id.namespace.name} -> counter @ {signal.id.namespace.name}) is {signal.timestamp - time_stamp_ref.timestamp}"
                    )
                    time_diff_a_b.append(signal.timestamp -
                                         time_stamp_ref.timestamp)

    Thread(
        target=act_on_signal,
        args=(
            ecu_under_test_id,
            network_stub,
            [
                # this is what triggers our bounce
                signal_creator.signal("counter", ecu_under_test_namespace),
            ],
            False,  # True: only report when signal changes
            lambda signals: bounce(
                network_stub,
                ecu_under_test_id,
                signal_creator.signal("counter", ecu_under_test_namespace),
                signals,
            ),
            lambda subscripton: (q.put((ecu_under_test_id, subscripton))),
        ),
    ).start()
    # wait for subscription to settle
    ecu, subscription = q.get()
    #####################################################################

    #####################################################################
    # set up an subscriber which listens to emitted signal and received.
    # NOTE: This subscriber needs to have unique "Client_id", which is different
    # from the publishing client, in order to not be filtered away
    time_measurer_id = common_pb2.ClientId(id="time_measurer_id")
    time_measurer_namespace = "ecu_A"

    def on_subscription(trigger_a, trigger_b, signals):
        global time_stamp_ref
        global time_diff_a_a
        for signal in signals:
            if signal.id == trigger_a:
                time_stamp_ref = signal
            elif signal.id == trigger_b and (time_stamp_ref != {} and
                                             (get_value(signal)
                                              == get_value(time_stamp_ref))):
                print(
                    f"time difference (counter @ {time_measurer_namespace} -> counter_times_2 @ {time_measurer_namespace}) is {signal.timestamp - time_stamp_ref.timestamp}"
                )
                time_diff_a_a.append(signal.timestamp -
                                     time_stamp_ref.timestamp)
            else:
                time_stamp_ref = {}

    Thread(
        target=act_on_signal,
        args=(
            time_measurer_id,
            network_stub,
            [
                # this is what we will emit.
                signal_creator.signal("counter", time_measurer_namespace),
                # this will bounce back form ecu_under_test_id
                signal_creator.signal("counter_times_2",
                                      time_measurer_namespace),
            ],
            False,  # True: only report when signal changes
            lambda signals: on_subscription(
                signal_creator.signal("counter", time_measurer_namespace),
                signal_creator.signal("counter_times_2",
                                      time_measurer_namespace),
                signals,
            ),
            lambda subscripton: (q.put((time_measurer_id, subscripton))),
        ),
    ).start()
    # wait for subscription to settle
    ecu, subscription = q.get()
    #####################################################################

    #####################################################################
    # Emit signals form ecu_a which till trigger ECU under test

    ecu_tester_id = common_pb2.ClientId(id="ecu_tester_id")
    ecu_tester_namespace = "ecu_A"

    Thread(
        target=ecu_tester,
        args=(network_stub, ecu_tester_id, ecu_tester_namespace, 0.05),
    ).start()
Example #11
0
from helper import *

__author__ = "Aleksandar Filipov and Alvaro Alonso"
__copyright__ = "Copyright 2019, Volvo Cars Group"

__version__ = "0.0.1"
__maintainer__ = "Alvaro Alonso"
__email__ = "*****@*****.**"
__status__ = "Development"

if __name__ == "__main__":
    # Create a channel
    channel = grpc.insecure_channel("localhost:50051")
    # Create the stub
    network_stub = network_api_pb2_grpc.NetworkServiceStub(channel)
    system_stub = system_api_pb2_grpc.SystemServiceStub(channel)
    check_license(system_stub)
    upload_folder(system_stub, "configuration")
    reload_configuration(system_stub)
    # create the identifier of *this* client
    client_id = common_pb2.ClientId(id="virtual_example_pub")
    # For 10 messages
    for _ in range(10):
        input_value = input("Enter a number: ")
        try:
            signal_value = int(input_value)
        except ValueError:
            print(f"{input_value} is not a number. Only numbers are allowed")
        else:
            # Create a signal
            namespace = common_pb2.NameSpace(name="VirtualInterface")
Example #12
0
def run(argv):
    """Main function, checking arguments passed to script, setting up stubs, configuration and starting Threads.

    Parameters
    ----------
    argv : list
        Arguments passed when starting script

    """
    # Checks argument passed to script, ecu.py will use below ip-address if no argument is passed to the script
    ip = "127.0.0.1"
    # Keep this port
    port = ":50051"
    try:
        opts, args = getopt.getopt(argv, "h", ["ip="])
    except getopt.GetoptError:
        print("Usage: ecu.py --ip <ip_address>")
        sys.exit(2)
    for opt, arg in opts:
        if opt == "-h":
            print("Usage: ecu.py --ip <ip_address>")
            sys.exit(2)
        elif opt == "--ip":
            ip = arg

    # Setting up stubs and configuration
    channel = grpc.insecure_channel(ip + port)
    network_stub = network_api_pb2_grpc.NetworkServiceStub(channel)
    system_stub = system_api_pb2_grpc.SystemServiceStub(channel)
    # check_license(system_stub)

    upload_folder(system_stub, "configuration_lin")
    reload_configuration(system_stub)

    # grace period to let clients time to pull their configuration
    time.sleep(5)

    clientId = common_pb2.ClientId(id="this_python_app_identifier")

    # slave, prepare to answer to diag request, this gets loaded pening in the transiever (waiting for aribitration)
    namespace_slave = "ecu_B"
    signal = common_pb2.SignalId(
        name="SlaveResp", namespace=common_pb2.NameSpace(name=namespace_slave))
    signal_with_payload = network_api_pb2.Signal(
        id=signal, raw=b"\x81\x09\x0a\x0b\x0c\x0d\x0e\x0f")
    publish_signals(network_stub, clientId, [signal_with_payload], 0)

    print("Slave is ready to reply to diag request %s" % (signal_with_payload))

    # master, subscribe to answer from client (just listen)
    namespace_master = "ecu_A"

    frame = common_pb2.SignalId(
        name="SlaveResp",
        namespace=common_pb2.NameSpace(name=namespace_master))
    # frame = common_pb2.SignalId(name="counter_times_2", namespace=common_pb2.NameSpace(name = namespace_master))
    ecu_m_subscribe = Thread(target=ecu_master_subscribe,
                             args=(network_stub, clientId, [frame], False))
    ecu_m_subscribe.daemon = True  # allow this thread to be automatically stopped on exit.
    ecu_m_subscribe.start()

    # Just listen from slave, for debug purposes
    # frame2 = common_pb2.SignalId(name="MasterReq", namespace=common_pb2.NameSpace(name = namespace_slave))
    # ecu_s_subscribe  = Thread(target = ecu_slave_subscribe, args = (network_stub, clientId, [frame, frame2], False))
    # ecu_s_subscribe.start()

    # # send arbitration from master (not needed arbitration is enabled inte inderfaces.json), expect nothing back! (send arbitration)
    #
    # signal = common_pb2.SignalId(name="SlaveResp", namespace=common_pb2.NameSpace(name = namespace_master))
    # signal_with_payload = network_api_pb2.Signal(id = signal, arbitration = True)
    # publish_signals(network_stub, clientId, [signal_with_payload], 0)

    # print("sent %s from master expect nothing back" % (signal_with_payload))
    # time.sleep(3)

    # send master request, now with propriate NAD, DEVS2 has NAD 0x81 (which is the fist byte below)
    signal = common_pb2.SignalId(
        name="MasterReq",
        namespace=common_pb2.NameSpace(name=namespace_master))
    signal_with_payload = network_api_pb2.Signal(
        id=signal, raw=b"\x81\x02\x03\x04\x05\x06\x07\x08")
    publish_signals(network_stub, clientId, [signal_with_payload], 0)

    print("sent %s from master expect ANSWER" % (signal_with_payload))
    time.sleep(3)

    # # send arbitration from master, expect answer since nad is matching
    # signal = common_pb2.SignalId(name="SlaveResp", namespace=common_pb2.NameSpace(name = namespace_master))
    # signal_with_payload = network_api_pb2.Signal(id = signal, arbitration = True)
    # publish_signals(network_stub, clientId, [signal_with_payload], 0)

    # print("sent %s from master expect ANSWER" % (signal_with_payload))
    # time.sleep(3)

    # send master request, now with another NAD, make sure client doesn't (which is the fist byte below)
    signal = common_pb2.SignalId(
        name="MasterReq",
        namespace=common_pb2.NameSpace(name=namespace_master))
    signal_with_payload = network_api_pb2.Signal(
        id=signal, raw=b"\x82\x02\x03\x04\x05\x06\x07\x08")
    publish_signals(network_stub, clientId, [signal_with_payload], 0)

    # send arbitration from master, expect nothing back (nad is not matching)!
    # signal = common_pb2.SignalId(name="SlaveResp", namespace=common_pb2.NameSpace(name = namespace_master))
    # signal_with_payload = network_api_pb2.Signal(id = signal, arbitration = True)
    # publish_signals(network_stub, clientId, [signal_with_payload], 0)

    print("sent %s from master NOT expecting ANSWER" % (signal_with_payload))
    time.sleep(3)

    print("still quiet.... done")
Example #13
0
def run(ip, port):
    """Main function, checking arguments passed to script, setting up stubs, configuration and starting Threads."""
    # Setting up stubs and configuration
    channel = grpc.insecure_channel(ip + ":" + port)
    network_stub = network_api_pb2_grpc.NetworkServiceStub(channel)
    system_stub = system_api_pb2_grpc.SystemServiceStub(channel)
    check_license(system_stub)

    upload_folder(system_stub, "configuration_udp")
    # upload_folder(system_stub, "configuration_lin")
    # upload_folder(system_stub, "configuration_can")
    # upload_folder(system_stub, "configuration_canfd")
    reload_configuration(system_stub)

    global signal_creator
    signal_creator = SignalCreator(system_stub)

    # Lists available signals
    configuration = system_stub.GetConfiguration(common_pb2.Empty())
    for networkInfo in configuration.networkInfo:
        print(
            "signals in namespace ",
            networkInfo.namespace.name,
            system_stub.ListSignals(networkInfo.namespace),
        )

    # Starting Threads

    # ecu b, we do this with lambda refering to double_and_publish.
    ecu_b_client_id = common_pb2.ClientId(id="id_ecu_B")

    ecu_B_sub_thread = Thread(
        target=act_on_signal,
        args=(
            ecu_b_client_id,
            network_stub,
            [
                signal_creator.signal("counter", "ecu_B"),
                # here you can add any signal from any namespace
                # signal_creator.signal("TestFr04", "ecu_B"),
            ],
            True,  # True: only report when signal changes
            lambda signals: double_and_publish(
                network_stub,
                ecu_b_client_id,
                signal_creator.signal("counter", "ecu_B"),
                signals,
            ),
            lambda subscripton: (q.put(("id_ecu_B", subscripton))),
        ),
    )
    ecu_B_sub_thread.start()
    # wait for subscription to settle
    ecu, subscription = q.get()

    # ecu a, this is where we publish, and
    ecu_A_thread = Thread(
        target=ecu_A,
        args=(
            network_stub,
            1,
        ),
    )
    ecu_A_thread.start()

    # ecu b, bonus, periodically, read using timer.
    signals = [
        signal_creator.signal("counter", "ecu_B"),
        # add any number of signals from any namespace
        # signal_creator.signal("TestFr04", "ecu_B"),
    ]
    ecu_read_on_timer = Thread(target=read_on_timer,
                               args=(network_stub, signals, 1))
    ecu_read_on_timer.start()
Example #14
0
def run(ip, port):
    """Main function, checking arguments passed to script, setting up stubs, configuration and starting Threads."""
    # Setting up stubs and configuration
    channel = grpc.insecure_channel(ip + ":" + port)
    network_stub = network_api_pb2_grpc.NetworkServiceStub(channel)
    system_stub = system_api_pb2_grpc.SystemServiceStub(channel)
    check_license(system_stub)

    upload_folder(system_stub, "configuration_can")
    reload_configuration(system_stub)

    global signal_creator
    signal_creator = SignalCreator(system_stub)

    # ecu a, we do this with lambda refering to modify_signal_publish_frame.
    reflector_client_id = common_pb2.ClientId(id="reflector_client_id")

    def modify_signals_publish_frame(
        network_stub, client_id, destination_namespace_name, signals
    ):
        # work in dictonary domain for easier access.
        signal_dict = {signal.id.name: signal for signal in signals}

        # example, lets update TestFr07_Child02
        (type, value) = get_value_pair(signal_dict["TestFr07_Child02"])
        signal_dict["TestFr07_Child02"] = signal_creator.signal_with_payload(
            "TestFr07_Child02", destination_namespace_name, (type, value + 1)
        )

        # example, lets update TestFr07_Child01_UB just invert this single bit
        (type, value) = get_value_pair(signal_dict["TestFr07_Child01_UB"])
        signal_dict["TestFr07_Child01_UB"] = signal_creator.signal_with_payload(
            "TestFr07_Child01_UB", destination_namespace_name, (type, 1 - value)
        )

        # example, lets compute counter_times_2 using some formula
        (type, value) = get_value_pair(signal_dict["counter_times_2"])
        signal_dict["counter_times_2"] = signal_creator.signal_with_payload(
            "counter_times_2",
            destination_namespace_name,
            (
                type,
                some_function_to_calculate_crc(
                    id,
                    destination_namespace_name,
                    [
                        (
                            "TestFr07_Child02",
                            get_value_pair(signal_dict["TestFr07_Child02"])[0],
                        ),
                        (
                            "TestFr07_Child01_UB",
                            get_value_pair(signal_dict["TestFr07_Child01_UB"])[0],
                        ),
                    ],
                ),
            ),
        )

        publish_list = signal_dict.values()
        # update destination namespace for all entrys in list
        change_namespace(publish_list, destination_namespace_name)
        # print(f"updates lists {publish_list}")
        publish_signals(client_id, network_stub, publish_list)

    Thread(
        target=act_on_signal,
        args=(
            reflector_client_id,
            network_stub,
            # get all childs in frame, alternatively we could do # all_siblings("counter_times_2", "ecu_A")
            signal_creator.signals_in_frame("TestFr07", "ecu_A"),
            False,  # True = only report when signal changes
            lambda signals: modify_signals_publish_frame(
                network_stub,
                reflector_client_id,
                "ecu_B",
                signals,
            ),
        ),
    ).start()