client example comments
@@ -32,32 +32,73 @@ if __name__ == "__main__":
options = getOptions()
+ #initialize libcsp with params:
+ # options.address - CSP address of the system (default=1)
+ # "host" - Host name, returned by CSP identity requests
+ # "model" - Model, returned by CSP identity requests
+ # "1.2.3" - Revision, returned by CSP identity requests
+ # 10 - Number of CSP buffers (default=10)
+ # 300 - Data size of a CSP buffer. Total size will be size of csp_packet_t + Data size (default=256)
+ # 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(options.address, "host", "model", "1.2.3", 10, 300)
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.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
libcsp.route_start_task()
time.sleep(0.2) # allow router task startup
print("Connections:")
+ # Prints connections format:
+ # [state 1 or 0 (open/closed)] [5-bit src address] [5-bit dest address] [6-bit dest port] [6 bit src port] [socket to be woken when packet is ready]
libcsp.print_connections()
print("Routes:")
+ # Prints route table format:
+ # [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
print("CMP ident:", libcsp.cmp_ident(options.server_address))
+ # Parameters: {address of subsystem}, optional:{timeout ms (default=1000)}, optional:{data size in bytes (default=10)}, optional:{connection options as bit flags (see "src\csp_conn.c")}
+ # Ping message
print("Ping: %d mS" % libcsp.ping(options.server_address))
+
+ # *** more services can be found at "src\csp_services.c" *** #
+
+
# transaction
outbuf = bytearray().fromhex('01')
inbuf = bytearray(1)
print ("Exchange data with server using csp_transaction ...")
+
+ # Perform an entire request & reply transaction w/ params:
+ # 0 - priority
+ # options.server_address - dest address
+ # 10 - dest port
+ # 1000 - timeout ms
+ # outbuf - outgoing data (request)
+ # inbuf - buffer provided for recieving data (reply)
libcsp.transaction(0, options.server_address, 10, 1000, outbuf, inbuf)
print (" got reply from server [%s]" % (''.join('{:02x}'.format(x) for x in inbuf)))
