#!/usr/bin/python from zcm import ZCM import sys sys.path.insert(0, '../build/types/') from example_t import example_t import time success = "Failure" def handler(channel, msg): global success assert msg.timestamp == 10 success = "Success" # make a new zcm object and launch the handle thread zcm = ZCM() if not zcm.good(): print "Unable to initialize zcm" exit() # declare a new msg and populate it msg = example_t() msg.timestamp = 10 # set up a subscription on channel "TEST" subs = zcm.subscribe("TEST", example_t, handler) # publish a message zcm.publish("TEST", msg) # wait a second
sys.path.insert(0, '../build/types/') from example_t import example_t import time success = "Failure" def handler(channel, msg): global success assert msg.timestamp == 10 success = "Success" # make a new zcm object and launch the handle thread zcm = ZCM("ipc") if not zcm.good(): print "Unable to initialize zcm" exit() # declare a new msg and populate it msg = example_t() msg.timestamp = 10 # set up a subscription on channel "TEST" subs = zcm.subscribe("TEST", example_t, handler) # publish a message zcm.publish("TEST", msg) # wait a second
#!/usr/bin/python from zcm import ZCM import sys sys.path.insert(0, '../build/types/') from test_package import packaged_t import time success = "Failure" def handler(channel, msg): global success assert(msg.a.e.timestamp == 10) success = "Success" # make a new zcm object and launch the handle thread zcm = ZCM() if not zcm.good(): print "Unable to initialize zcm" exit() # declare a new msg and populate it msg = packaged_t() msg.a.e.timestamp = 10 # set up a subscription on channel "TEST" subs = zcm.subscribe("TEST", packaged_t, handler) # publish a message zcm.publish("TEST", msg) # wait a second
signal.signal(signal.SIGINT, signal_handler) lock = threading.Lock() done = 0 def handler(channel, msg): global done print "Received message on channel: " + channel assert msg.timestamp == 10 lock.acquire() done = done + 1 lock.release() zcm = ZCM() if not zcm.good(): print "Unable to initialize zcm" exit() zcm.start() msg = example_t() msg.timestamp = 10 subs = zcm.subscribe("TEST", example_t, handler) while True: zcm.publish("TEST", msg) lock.acquire() _done = done lock.release() if _done == 10: break time.sleep(0.25)
sys.path.insert(0, '../build/types/') from example_t import example_t import time success = "Failure" def handler(channel, msg): global success assert msg.timestamp == 10 success = "Success" # make a new zcm object and launch the handle thread zcm = ZCM("") if not zcm.good(): print("Unable to initialize zcm") exit() # declare a new msg and populate it msg = example_t() msg.timestamp = 10 # set up a subscription on channel "TEST" zcm.subscribe("TEST", example_t, handler) # publish a message zcm.publish("TEST", msg) # wait a second
sys.path.insert(0, '../build/types/') from example_t import example_t from encoded_t import encoded_t import time success = "Failure" def handler(channel, msg): global success assert msg.timestamp == 10 success = "Success" # make a new zcm object and launch the handle thread zcm = ZCM("") if not zcm.good(): print "Unable to initialize zcm" exit() # declare a new msg and populate it msg = example_t() msg.timestamp = 10 encoded = encoded_t() encoded.msg = msg.encode() encoded.n = len(encoded.msg) decoded = example_t.decode(encoded.msg) assert (decoded.timestamp == msg.timestamp)
assert msg.timestamp == 10 lock.acquire() done = done + 1 lock.release() def publish(): print "Publish message on channel: " + "TEST" zcm.publish("TEST", msg) print "Publish message on channel: " + "TEST_1" zcm.publish("TEST_1", msg) print "Publish message on channel: " + "TEST_2" zcm.publish("TEST_2", msg) zcm = ZCM("") if not zcm.good(): print "Unable to initialize zcm" exit() zcm.start() msg = example_t() msg.timestamp = 10 subs = zcm.subscribe("TEST.*", example_t, handler) publish() time.sleep(1) while True: publish() lock.acquire() _done = done lock.release() if _done == 9:
# Untested from zcm import ZCM from pto import pto_t from otp import otp_t def handler(channel, msg): print "Received message on channel: " + channel assert msg.timestamp == 10 zcm = ZCM("udpm://10.0.0.4:7777?ttl=64") if not zcm.good(): print "Unable to initialize zcm" exit() # declare a new msg and populate it msg = pto_t() msg.timestamp = 10 # set up a subscription on channel "TEST" subs = zcm.subscribe("TEST", otp_t(), handler) # publish a message zcm.publish("TEST", msg)
import signal def signal_handler(signal, frame): sys.exit(0) signal.signal(signal.SIGINT, signal_handler) lock = threading.Lock() done = 0 def handler(channel, msg): global done print "Received message on channel: " + channel assert msg.timestamp == 10 lock.acquire() done = done + 1 lock.release() zcm = ZCM() if not zcm.good(): print "Unable to initialize zcm" exit() zcm.start() msg = example_t() msg.timestamp = 10 subs = zcm.subscribe("TEST", example_t, handler) while True: zcm.publish("TEST", msg) lock.acquire() _done = done lock.release() if _done == 10: break time.sleep(0.25)