default=27, help="Server address") parser.add_argument("-R", "--routing-table", help="Routing table") return parser.parse_args(sys.argv[1:]) if __name__ == "__main__": options = getOptions() libcsp.init(options.address, "host", "model", "1.2.3", 10, 300) if options.can: libcsp.can_socketcan_init(options.can) if options.zmq: libcsp.zmqhub_init(options.address, options.zmq) libcsp.rtable_load("0/0 ZMQHUB") if options.routing_table: libcsp.rtable_load(options.routing_table) libcsp.route_start_task() time.sleep(0.2) # allow router task startup print("Connections:") libcsp.print_connections() print("Routes:") libcsp.print_routes() print("CMP ident:", libcsp.cmp_ident(options.server_address))
print("got packet, len=" + str(length) + ", data=" + ''.join('{:02x}'.format(x) for x in data)) # send reply data[0] = data[0] + 1 reply = libcsp.buffer_get(1) libcsp.packet_set_data(reply, data) libcsp.sendto_reply(packet, reply, libcsp.CSP_O_NONE) else: # pass request on to service handler libcsp.service_handler(conn, packet) if __name__ == "__main__": # init csp libcsp.init(27, "test_service", "bindings", "1.2.3", 10, 300) libcsp.zmqhub_init(27, "localhost") libcsp.rtable_set(0, 0, "ZMQHUB") libcsp.route_start_task() print("Hostname: %s" % libcsp.get_hostname()) print("Model: %s" % libcsp.get_model()) print("Revision: %s" % libcsp.get_revision()) print("Routes:") libcsp.print_routes() # start CSP server threading.Thread(target=csp_server).start()
def __zmq__(self, addr): """ initialize ZMQ interface """ libcsp.zmqhub_init(addr, 'localhost') libcsp.rtable_load('0/0 ZMQHUB')