Skip to content

Commit

Permalink
examples: python: Add new parameters support to the client and server…
Browse files Browse the repository at this point in the history
… examples

- Add kiss parameter support to the python client example.
- Add parameter support to the python server example.
  • Loading branch information
moonlight83340 committed Jul 11, 2024
1 parent aef9c41 commit e84b625
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
9 changes: 7 additions & 2 deletions examples/python_bindings_example_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -53,7 +54,11 @@ def getOptions():
# Format: \<address\>[/mask] \<interface\> [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)
Expand All @@ -77,6 +82,7 @@ def getOptions():
# [address] [netmask] [interface name] optional([via])
libcsp.print_routes()


# Parameters: {node} - address of subsystem, optional:{timeout ms (default=1000)}
# CSP Management Protocol (CMP)
# CMP identification request
Expand All @@ -89,7 +95,6 @@ def getOptions():

# *** more services can be found at "src\csp_services.c" *** #


# transaction
outbuf = bytearray().fromhex('01')
inbuf = bytearray(1)
Expand Down
43 changes: 31 additions & 12 deletions examples/python_bindings_example_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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: \<address\>[/mask] \<interface\> [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
Expand Down

0 comments on commit e84b625

Please sign in to comment.