def send(self, signal, value): global command command = self.split_signal(signal) if verbose: logging.info("From rmc_ipc.py, send(), the signal is " + str(signal)) logging.info("From rmc_ipc.py, send(), the value is " + str(value)) logging.info("From rmc_ipc.py, send(), the command is " + str(command)) logging.info("From rmc_ipc.py, send(), the object type of value is " + str(type(value))) m = self._re.match(signal) if m is None: if verbose: logging.info("From rmc_ipc.py, send(), no match") return # for can signals, this was a tuple # sig_cat, sig_name = m.groups() # for the dstc tuner, this is the control signal # read from the rules file for this test # need to ensure this matches a signal from the csv file sig_cat = m.groups() if verbose: logging.info("sig_cat is " + str(sig_cat[0])) if sig_cat[0] == command: # 1000000 seems enough for the test system to receive the # callback from the tuner after setting the frequency # increase this value if tests frequently timeout self.client_func(self.format_string_as_double(value)) if verbose: logging.info("From rmc_ipc just called self.client_func(value) " + str(value)) dstc.process_events(100000)
def main(): #./ in the path name forces the current directory to be searched # instead of LD_LIBRARY_PATH (/lib, /usr/libm, etc) vsd.load_vss_shared_object("./example.so") sig = vsd.signal("Modem.DataLink.Status") if not sig: print("Could not resolve signal Modem.DataLink.Status") sys.exit(255) vsd.set(sig, "connecting") sig = vsd.signal("Modem.SignalStrength") if not sig: print("Could not resolve signal Modem.SignalStrength") sys.exit(255) vsd.set(sig, 12) pub = vsd.signal("Modem") dstc.activate() stop_ts = current_milli_time() + 400 while (current_milli_time() < stop_ts): dstc.process_events(stop_ts - current_milli_time()) vsd.publish(pub) dstc.process_pending_events()
def main(): vsd.load_vss_shared_object("./example.so") dstc.activate() vsd.set_callback(process_signal) sig = vsd.signal("Modem"); if not sig: print("Could not resolve signal Modem") sys.exit(255) vsd.subscribe(sig) global exit_flag while not exit_flag: dstc.process_events(-1)
def __init__(self, myFifo, csv_file): global fifo_fd if verbose: logging.info("rmc_ipc __init__()...") logging.info("rmc_ipc __init__(), myFifo is " + str(myFifo)) logging.info("rmc_ipc __init__(), csv_file is " + str(csv_file)) self._re = re.compile('^Vehicle\.([a-zA-Z]+)') # open fifo for read/write non-blocking self._myFifo = myFifo self._signals = parse_csv(csv_file) if not self._signals: print("From rmc_ipc, ERROR: no signals could not be parsed from " + csv_file) sys.exit(1) fifo_fd = os.open(self._myFifo, os.O_RDWR | os.O_NONBLOCK) if verbose: logging.info("rmc_ipc init(), the fifo_fd is " + str(fifo_fd)) self.client_func = dstc.register_client_function("set_fm_frequency", "d") self._ctx = vsd.create_context() vsd.set_callback(self._ctx, process_signal) if vsd.load_from_file(self._ctx, "./vss_rel_2.0.0-alpha+005.csv") != 0: print("Could not load vss_rel_2.0.0-alpha+005.csv") sys.exit(255) sig = vsd.signal(self._ctx, "Vehicle.setfrequency"); vsd.subscribe(self._ctx, sig) if verbose: logging.info("rmc_ipc is waiting for remote dstc function") dstc.activate() # 100000 seems enough # increase this value if tests timeout # also see dstc.process_events() in send() while not dstc.remote_function_available(self.client_func): dstc.process_events(100000) if verbose: logging.info("From class RMCIPC, init complete")
def double_value_callback(doubled_value): global do_exit print("Callback-delivered value: {}".format(doubled_value)) do_exit = True if __name__ == "__main__": # Setup a client call to the server that will double the value for us. # double_value_server() takes an integer ("i") with the value to double # and a callback ("&") that double_value_server() is to invoke # on this process in order to deliver the result. client_func = dstc.register_client_function("double_value_server", "i&") dstc.activate() print("Waiting for remote function") while not dstc.remote_function_available(client_func): dstc.process_events(100000) # # Call the server's double_value_server() function, providing 21 # as the value to double. # # The second argument, (double_value_callback, "i"), matches the # ampersand in the "i&" and specifies the local function # (double_value_callback()) that the remote double_value_server() # function is to invoke in order to deliver the result. # client_func(21, (double_value_callback, "i")) while not do_exit: dstc.process_events(-1)
#!/usr/bin/env python3 # Test python client to exercise import dstc from dstc import current_milli_time do_exit = False def complex_arg(func_name, name, dynamic, age_array): global do_exit print("Function name: {}".format(func_name)) print("Name: {}".format(name)) print("Dynamic: {} / {}".format(dynamic, len(dynamic))) print("Age array: {}".format(age_array)) do_exit = True if __name__ == "__main__": dstc.register_server_function("complex_arg", complex_arg, "32s#3i") dstc.activate() stop_ts = current_milli_time() + 400 while (current_milli_time() < stop_ts): dstc.process_events(stop_ts - current_milli_time()) while not do_exit: dstc.process_events(-1)
#!/usr/bin/env python3 # Test python client to exercise DSTC. import dstc if __name__ == "__main__": client_func = dstc.register_client_function("complex_arg", "32s#3i") dstc.activate() print("Waiting for remote function") while not dstc.remote_function_available(client_func): dstc.process_events(100000) client_func("32 byte string", b"Dynamic string", [11,22,33]) dstc.process_events(500)
def process_events(timeout_msec): return dstc.process_events(timeout_msec)