From 70cb5a1f9fb27ea527cf559f99883c970b7c42eb Mon Sep 17 00:00:00 2001 From: Gaetan Perrot Date: Thu, 11 Jul 2024 16:31:36 +0900 Subject: [PATCH] examples: python: Add new parameters support to the examples - Add kiss parameter support to the python client example. - Add parameters support to the python server example. Signed-off-by: Gaetan Perrot --- examples/python_bindings_example_client.py | 7 +++- examples/python_bindings_example_server.py | 43 ++++++++++++++++------ 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/examples/python_bindings_example_client.py b/examples/python_bindings_example_client.py index ea9de49e0..3ab35a760 100644 --- a/examples/python_bindings_example_client.py +++ b/examples/python_bindings_example_client.py @@ -22,6 +22,7 @@ def getOptions(): parser = argparse.ArgumentParser(description="Parses command.") parser.add_argument("-a", "--address", type=int, default=10, help="Local CSP address") parser.add_argument("-c", "--can", help="Add CAN interface") + parser.add_argument("-k", "--kiss", help="Add KISS interface") parser.add_argument("-z", "--zmq", help="Add ZMQ interface") parser.add_argument("-s", "--server-address", type=int, default=27, help="Server address") parser.add_argument("-R", "--routing-table", help="Routing table") @@ -53,7 +54,11 @@ def getOptions(): # Format: \[/mask] \ [via][, next entry] # Examples: "0/0 CAN, 8 KISS, 10 I2C 10", same as "0/0 CAN, 8/5 KISS, 10/5 I2C 10" libcsp.rtable_load("0/0 ZMQHUB") - + + if options.kiss: + libcsp.kiss_init(options.kiss, options.address) + libcsp.rtable_load("0/0 KISS") + if options.routing_table: # same format/use as line above libcsp.rtable_load(options.routing_table) diff --git a/examples/python_bindings_example_server.py b/examples/python_bindings_example_server.py index d0c482169..57515fc01 100644 --- a/examples/python_bindings_example_server.py +++ b/examples/python_bindings_example_server.py @@ -14,9 +14,18 @@ import time import sys import threading +import argparse import libcsp_py3 as libcsp +def getOptions(): + parser = argparse.ArgumentParser(description="Parses command.") + parser.add_argument("-a", "--address", type=int, default=10, help="Local CSP address") + parser.add_argument("-c", "--can", help="Add CAN interface") + parser.add_argument("-k", "--kiss", help="Add KISS interface") + parser.add_argument("-z", "--zmq", help="Add ZMQ interface") + parser.add_argument("-R", "--routing-table", help="Routing table") + return parser.parse_args(sys.argv[1:]) def csp_server(): # parameters: {options} - bit flag corresponding to socket options (see "include\csp\csp_types.h" lines 167-180) @@ -92,6 +101,7 @@ def csp_server(): if __name__ == "__main__": + options = getOptions() #initialize libcsp with params: # 27 - CSP address of the system (default=1) # "test_service" - Host name, returned by CSP identity requests @@ -100,18 +110,27 @@ def csp_server(): # See "include\csp\csp.h" - lines 42-80 for more detail # See "src\bindings\python\pycsp.c" - lines 128-156 for more detail libcsp.init("test_service", "bindings", "1.2.3") - - # init zmqhub with parameters: {address (using 255 means all addresses)} {host name/ip} - # subscribe and publish endpoints are created on the default ports using the {host} - # subscribe port = 6000, subscribe port = 7000 - libcsp.zmqhub_init(27, "localhost") - - # params: - # {address} - dest address/node - # {netmask} - number of bits in netmask - # {interface name} - name of interface - # optional{via} - associated with address - libcsp.rtable_set(0, 0, "ZMQHUB") + + if options.can: + # add CAN interface + libcsp.can_socketcan_init(options.can) + + if options.zmq: + # add ZMQ interface - (address, host) + # creates publish and subrcribe endpoints from the host + libcsp.zmqhub_init(options.address, options.zmq) + + # Format: \[/mask] \ [via][, next entry] + # Examples: "0/0 CAN, 8 KISS, 10 I2C 10", same as "0/0 CAN, 8/5 KISS, 10/5 I2C 10" + libcsp.rtable_load("0/0 ZMQHUB") + + if options.kiss: + libcsp.kiss_init(options.kiss, options.address) + libcsp.rtable_load("0/0 KISS") + + if options.routing_table: + # same format/use as line above + libcsp.rtable_load(options.routing_table) # Parameters: {priority} - 0 (critical), 1 (high), 2 (norm), 3 (low) ---- default=2 # Start the router task - creates routing thread