def main(): try: dispatcher = Dispatcher() host = Host(dispatcher, "/dev/ttyUSB0") dispatcher.add_host(host) Tasklet.new(dispatcher.loop)() print "Calibration: %s" % host.calibrate_baudrate() print "Available: %s" % host.available() dev = RadioDevice(dispatcher, 2) print "Protocol version: %s" % dev.protocol_version # Running HTTP server application = django.core.handlers.wsgi.WSGIHandler() def app_wrapper(*args, **kwargs): try: return application(*args, **kwargs) except Exception as e: print e server = WSGIServer(application) server.serve(('localhost', 8080)) while True: print "ADC data: %s, supply voltage: %.2f" % (dev.adc_data(), dev.supply_voltage()) Tasklet.sleep(1) os._exit(0) except Exception as e: logging.exception(e) os._exit(1)
class EmulatedTest(unittest.TestCase): def setUp(self): self.dispatcher = Dispatcher() self.host = EmulatedHost(self.dispatcher) self.dispatcher.add_host(self.host) self.dispatcher_task = Tasklet.new(self.dispatcher.loop) self.dispatcher_task() def tearDown(self): self.dispatcher_task.kill()
def setUp(self): self.dispatcher = Dispatcher() self.host = EmulatedHost(self.dispatcher) self.dispatcher.add_host(self.host) self.dispatcher_task = Tasklet.new(self.dispatcher.loop) self.dispatcher_task()