def __init__(self): self.pid_store = PidStore.GetStore() # we can provide custom printers for PIDs below self._handlers = { 'SUPPORTED_PARAMETERS': self.SupportedParameters, 'PROXIED_DEVICES': self.ProxiedDevices, }
def main(): pid_store = PidStore.GetStore() pids = [] manufacturers = [] for pid in pid_store.Pids(): pid_dict = BuildPid(pid) pids.append(pid_dict) for id, name in pid_store._manufacturer_id_to_name.iteritems(): manufacturer = { 'id': id, 'name': name, 'pids': [] } for pid in pid_store._manufacturer_pids[id].values(): pid_dict = BuildPid(pid) manufacturer['pids'].append(pid_dict) manufacturers.append(manufacturer) # pprint.pprint(manufacturers) pprint.pprint(pids)
def __init__(self, universe, uid, sub_device, pid_file): """Create a new InteractiveModeController. Args: universe: uid: sub_device: pid_file: """ cmd.Cmd.__init__(self) self._universe = universe self._uid = uid self._sub_device = sub_device self.pid_store = PidStore.GetStore(pid_file) self.wrapper = ClientWrapper() self.client = self.wrapper.Client() self.rdm_api = RDMAPI(self.client, self.pid_store) self._uids = [] self._response_printer = ResponsePrinter() # tuple of (sub_device, command_class, pid) self._outstanding_request = None self.prompt = '> '
def main(): options = parse_options() settings.update(options.__dict__) pid_store = PidStore.GetStore(options.pid_store, ('pids.proto')) logging.basicConfig(level=logging.INFO, format='%(message)s') SetupLogDirectory(options) #Check olad status logging.info('Checking olad status') try: ola_client = OlaClient() except OLADNotRunningException: logging.error('Error creating connection with olad. Is it running?') sys.exit(127) ola_thread = OLAThread(ola_client) ola_thread.start() test_thread = RDMTestThread(pid_store, settings['log_directory']) test_thread.start() app = BuildApplication(ola_thread, test_thread) httpd = make_server('', settings['PORT'], app.HandleRequest) logging.info('Running RDM Tests Server on %s:%s' % ('127.0.0.1', httpd.server_port)) try: httpd.serve_forever() except KeyboardInterrupt: pass ola_thread.Stop() test_thread.Stop() ola_thread.join() test_thread.join()
def testDirectoryAndSingleton(self): store = PidStore.GetStore(os.path.join(path, "pids")) self.assertIs(store, PidStore.GetStore(os.path.join(path, "pids"))) self.assertEqual(len(store.Pids()), 6) self.assertEqual(len(store.ManufacturerPids(OPEN_LIGHTING_ESTA_CODE)), 1) # in pids1 self.assertIsNotNone(store.GetPid(16)) self.assertIsNotNone(store.GetPid(17)) self.assertIsNotNone(store.GetName("DEVICE_INFO")) self.assertIsNotNone(store.GetName("PROXIED_DEVICES", OPEN_LIGHTING_ESTA_CODE)) self.assertEqual(store.NameToValue("DEVICE_INFO"), 96) # in pids2 self.assertIsNotNone(store.GetPid(80)) self.assertIsNotNone(store.GetName("COMMS_STATUS")) self.assertEqual(store.GetName("PROXIED_DEVICES"), store.GetPid(16, OPEN_LIGHTING_ESTA_CODE)) self.assertIsNotNone(store.GetPid(32768, 161)) # check override file self.assertIsNone(store.GetName("SERIAL_NUMBER", OPEN_LIGHTING_ESTA_CODE)) self.assertIsNone(store.GetName("DEVICE_MODE", OPEN_LIGHTING_ESTA_CODE)) pid = store.GetName("FOO_BAR", OPEN_LIGHTING_ESTA_CODE) self.assertEqual(pid.value, 32768) self.assertEqual(pid, store.GetPid(32768, OPEN_LIGHTING_ESTA_CODE)) self.assertEqual(pid.name, "FOO_BAR") self.assertIsNotNone(pid.GetRequest(PidStore.RDM_GET)) self.assertIsNotNone(pid.GetResponse(PidStore.RDM_GET)) self.assertIsNone(pid.GetRequest(PidStore.RDM_SET)) self.assertIsNone(pid.GetResponse(PidStore.RDM_SET)) self.assertEqual(store.NameToValue("FOO_BAR", OPEN_LIGHTING_ESTA_CODE), 32768) self.assertIsNone(store.NameToValue("FOO_BAR", OPEN_LIGHTING_ESTA_CODE + 1)) self.assertEqual(pid.GetResponse(PidStore.RDM_GET).GetDescription(), ("<baz>", " baz: <[0, 4294967295]>"))
def __init__(self, universe, uid, rdm_api, wrapper, limit=25): self._universe = universe self._uid = uid self._api = rdm_api self._wrapper = wrapper # implement some basic endless loop checking self._limit = limit self._counter = 0 self._outstanding_ack_timers = 0 store = PidStore.GetStore() self._queued_message_pid = store.GetName('QUEUED_MESSAGE') self._status_messages_pid = store.GetName('STATUS_MESSAGES')
def main(): try: opts, args = getopt.getopt(sys.argv[1:], 'dhp:u:', [ 'debug', 'help', 'skip-queued-messages', 'pid-location=', 'universe=' ]) except getopt.GetoptError as e: print(str(e)) Usage() sys.exit(2) universe = None pid_location = None level = logging.INFO skip_queued_messages = False for o, a in opts: if o in ('-d', '--debug'): level = logging.DEBUG elif o in ('-h', '--help'): Usage() sys.exit() elif o in ('--skip-queued-messages'): skip_queued_messages = True elif o in ( '-p', '--pid-location', ): pid_location = a elif o in ('-u', '--universe'): universe = int(a) if universe is None: Usage() sys.exit() logging.basicConfig(level=level, format='%(message)s') client_wrapper = ClientWrapper() pid_store = PidStore.GetStore(pid_location) controller = ModelCollector(client_wrapper, pid_store) data = controller.Run(universe, skip_queued_messages) pprint.pprint(data)
def main(): options = ParseOptions() test_classes = TestRunner.GetTestClasses(TestDefinitions) if options.list_tests: for test_name in sorted(c.__name__ for c in test_classes): print test_name sys.exit(0) SetupLogging(options) logging.info('OLA Responder Tests Version %s' % Version.version) pid_store = PidStore.GetStore(options.pid_location, ('pids.proto', 'draft_pids.proto', 'manufacturer_names.proto')) wrapper = ClientWrapper() global uid_ok uid_ok = False def UIDList(state, uids): wrapper.Stop() global uid_ok if not state.Succeeded(): logging.error('Fetch failed: %s' % state.message) return for uid in uids: if uid == options.uid: logging.debug('Found UID %s' % options.uid) uid_ok = True if not uid_ok: logging.error('UID %s not found in universe %d' % (options.uid, options.universe)) return if len(uids) > 1: logging.info( 'The following devices were detected and will be reconfigured') for uid in uids: logging.info(' %s' % uid) if not options.skip_check: logging.info('Continue ? [Y/n]') response = raw_input().strip().lower() uid_ok = response == 'y' or response == '' logging.debug('Fetching UID list from server') wrapper.Client().FetchUIDList(options.universe, UIDList) wrapper.Run() wrapper.Reset() if not uid_ok: sys.exit() test_filter = None if options.tests is not None: logging.info('Restricting tests to %s' % options.tests) test_filter = set(options.tests.split(',')) logging.info( 'Starting tests, universe %d, UID %s, broadcast write delay %dms, ' 'inter-test delay %dms' % (options.universe, options.uid, options.broadcast_write_delay, options.inter_test_delay)) runner = TestRunner.TestRunner(options.universe, options.uid, options.broadcast_write_delay, options.inter_test_delay, pid_store, wrapper, options.timestamp) for test_class in test_classes: runner.RegisterTest(test_class) DMXSender(wrapper, options.universe, options.dmx_frame_rate, options.slot_count) tests, device = runner.RunTests(test_filter, options.no_factory_defaults) DisplaySummary(options, runner, tests, device, pid_store)
def testLoad(self): store = PidStore.GetStore(os.environ['PIDDATA']) self.assertIsNotNone(store) pids = store.Pids() self.assertNotEqual(0, len(pids))
skip_queued_messages = False for o, a in opts: if o in ('-d', '--debug'): level = logging.DEBUG elif o in ('-h', '--help'): Usage() sys.exit() elif o in ('--skip_queued_messages'): skip_queued_messages = True elif o in ('--pid_file',): pid_file = a elif o in ('-u', '--universe'): universe = int(a) if universe is None: Usage() sys.exit() logging.basicConfig( level=level, format='%(message)s') client_wrapper = ClientWrapper() pid_store = PidStore.GetStore(pid_file) controller = ModelCollector(client_wrapper, pid_store) data = controller.Run(universe, skip_queued_messages) pprint.pprint(data) if __name__ == '__main__': main()
def main(): try: opts, args = getopt.getopt(sys.argv[1:], 'dhi:o:p:u:', [ 'debug', 'help', 'input=', 'skip-queued-messages', 'output=', 'pid-location=', 'universe=' ]) except getopt.GetoptError as err: print(str(err)) Usage() sys.exit(2) universe = None output_file = None input_file = None pid_location = None level = logging.INFO skip_queued_messages = False for o, a in opts: if o in ('-d', '--debug'): level = logging.DEBUG elif o in ('-h', '--help'): Usage() sys.exit() elif o in ('-i', '--input'): input_file = a elif o in ('--skip-queued-messages'): skip_queued_messages = True elif o in ('-o', '--output'): output_file = a elif o in ( '-p', '--pid-location', ): pid_location = a elif o in ('-u', '--universe'): universe = int(a) if universe is None: Usage() sys.exit() if input_file and output_file: print('Only one of --input and --output can be provided.') sys.exit() logging.basicConfig(level=level, format='%(message)s') client_wrapper = ClientWrapper() pid_store = PidStore.GetStore(pid_location) if input_file: configuration = ReadFile(input_file) if configuration: writer = ConfigWriter(client_wrapper, pid_store) writer.Run(universe, configuration) else: controller = ConfigReader(client_wrapper, pid_store) data = controller.Run(universe, skip_queued_messages) if output_file: WriteToFile(output_file, data) else: pprint.pprint(data)
def main(): readline.set_completer_delims(' \t') try: opts, args = getopt.getopt(sys.argv[1:], 'd:hilp:u:', ['sub-device=', 'help', 'interactive', 'list-pids', 'pid-location=', 'uid=', 'universe=']) except getopt.GetoptError as err: print(str(err)) Usage() sys.exit(2) universe = None uid = None sub_device = 0 list_pids = False pid_location = None interactive_mode = False for o, a in opts: if o in ('-d', '--sub-device'): sub_device = int(a) elif o in ('-h', '--help'): Usage() sys.exit() elif o in ('-i', '--interactive'): interactive_mode = True elif o in ('-l', '--list-pids'): list_pids = True elif o in ('--uid',): uid = UID.FromString(a) elif o in ('-p', '--pid-location',): pid_location = a elif o in ('-u', '--universe'): universe = int(a) if universe is None and not list_pids: Usage() sys.exit() if not uid and not list_pids and not interactive_mode: Usage() sys.exit() # try to load the PID store so we fail early if we're missing PIDs try: PidStore.GetStore(pid_location) except PidStore.MissingPLASAPIDs as e: print(e) sys.exit() controller = InteractiveModeController(universe, uid, sub_device, pid_location) if interactive_mode: sys.stdout.write('Available Uids:\n') controller.onecmd('uids') controller.cmdloop() sys.exit() if list_pids: controller.onecmd('list') sys.exit() if len(args) == 0: Usage() sys.exit() request_type = 'get' if os.path.basename(sys.argv[0]) == 'ola_rdm_set.py': request_type = 'set' controller.onecmd('%s %s' % (request_type, ' '.join(args)))
def testGetParamsWithResponse(self): """uses client to send an RDM get with mocked olad. Regression test that confirms sent message is correct and sends fixed response message.""" sockets = socket.socketpair() wrapper = ClientWrapper(sockets[0]) pid_store = PidStore.GetStore(pid_store_path) client = wrapper.Client() rdm_api = RDMAPI(client, pid_store) class results: got_request = False got_response = False def DataCallback(self): # request and response for # ola_rdm_get.py -u 1 --uid 7a70:ffffff00 DMX_PERSONALITY_DESCRIPTION 2 # against olad dummy plugin # enable logging in rpc/StreamRpcChannel.py data = sockets[1].recv(4096) expected = binascii.unhexlify( "2b000010080110001a0a52444d436f6d6d616e6422190801120908f0f4011500" "ffffff180020e1012a010230003800") self.assertEqual(data, expected, msg="Regression check failed. If protocol change " "was intended set expected to: " + str(binascii.hexlify(data))) results.got_request = True response = binascii.unhexlify( "3d0000100802100022370800100018002210020005506572736f6e616c697479" "203228e101300038004a0908f0f4011500ffffff520908f0f40115ac107de058" "29") sent_bytes = sockets[1].send(response) self.assertEqual(sent_bytes, len(response)) def ResponseCallback(self, response, data, unpack_exception): results.got_response = True self.assertEqual(response.response_type, client.RDM_ACK) self.assertEqual(response.pid, 0xe1) self.assertEqual(data['personality'], 2) self.assertEqual(data['slots_required'], 5) self.assertEqual(data['name'], "Personality 2") wrapper.AddEvent(0, wrapper.Stop) wrapper._ss.AddReadDescriptor(sockets[1], lambda: DataCallback(self)) uid = UID.FromString("7a70:ffffff00") pid = pid_store.GetName("DMX_PERSONALITY_DESCRIPTION") rdm_api.Get(1, uid, 0, pid, lambda x, y, z: ResponseCallback(self, x, y, z), args=["2"]) wrapper.Run() sockets[0].close() sockets[1].close() self.assertTrue(results.got_request) self.assertTrue(results.got_response)
names = True elif o in ('--include-draft'): include_draft = True elif o in ( '-p', '--pid-location', ): pid_location = a logging.basicConfig(level=level, format='%(message)s') pid_files = ['pids.proto'] if include_draft: pid_files.append('draft_pids.proto') pid_store = PidStore.GetStore(pid_location, pid_files) for pid in pid_store.Pids(): pid_test_base_name = pid.name.lower().title().replace('_', '') get_size = 0 if ((pid.RequestSupported(PidStore.RDM_GET)) and (pid.GetRequest(PidStore.RDM_GET).HasAtoms())): get_size = pid.GetRequest(PidStore.RDM_GET).GetAtoms()[0].size # print('# Get requires %d bytes' % (get_size)) AllSubDevicesGet(names, pid, pid_test_base_name, get_size) Get(names, pid, pid_test_base_name) if ((pid.RequestSupported(PidStore.RDM_GET)) and (pid.GetRequest(PidStore.RDM_GET).HasAtoms())):
def testGetWithResponse(self): """uses client to send an RDM get with mocked olad. Regression test that confirms sent message is correct and sends fixed response message.""" sockets = socket.socketpair() wrapper = ClientWrapper(sockets[0]) pid_store = PidStore.GetStore(pid_store_path) client = wrapper.Client() rdm_api = RDMAPI(client, pid_store) class results: got_request = False got_response = False def DataCallback(self): # request and response for # ola_rdm_get.py -u 1 --uid 7a70:ffffff00 device_info # against olad dummy plugin # enable logging in rpc/StreamRpcChannel.py data = sockets[1].recv(4096) expected = binascii.unhexlify( "29000010080110001a0a52444d436f6d6d616e6422170801120908f0f4011500" "ffffff180020602a0030003800") self.assertEqual(data, expected, msg="Regression check failed. If protocol change " "was intended set expected to: " + str(binascii.hexlify(data))) results.got_request = True response = binascii.unhexlify( "3f0000100802100022390800100018002213010000017fff0000000300050204" "00010000032860300038004a0908f0f4011500ffffff520908f0f40115ac1100" "02580a") sent_bytes = sockets[1].send(response) self.assertEqual(sent_bytes, len(response)) def ResponseCallback(self, response, data, unpack_exception): results.got_response = True self.assertEqual(response.response_type, client.RDM_ACK) self.assertEqual(response.pid, 0x60) self.assertEqual(data["dmx_footprint"], 5) self.assertEqual(data["software_version"], 3) self.assertEqual(data["personality_count"], 4) self.assertEqual(data["device_model"], 1) self.assertEqual(data["current_personality"], 2) self.assertEqual(data["protocol_major"], 1) self.assertEqual(data["protocol_minor"], 0) self.assertEqual(data["product_category"], 32767) self.assertEqual(data["dmx_start_address"], 1) self.assertEqual(data["sub_device_count"], 0) self.assertEqual(data["sensor_count"], 3) wrapper.AddEvent(0, wrapper.Stop) wrapper._ss.AddReadDescriptor(sockets[1], lambda: DataCallback(self)) uid = UID.FromString("7a70:ffffff00") pid = pid_store.GetName("DEVICE_INFO") rdm_api.Get(1, uid, 0, pid, lambda x, y, z: ResponseCallback(self, x, y, z)) wrapper.Run() sockets[0].close() sockets[1].close() self.assertTrue(results.got_request) self.assertTrue(results.got_response)
def testSetParamsWithNack(self): """uses client to send an RDM set with mocked olad. Regression test that confirms sent message is correct and sends fixed response message.""" sockets = socket.socketpair() wrapper = ClientWrapper(sockets[0]) pid_store = PidStore.GetStore(pid_store_path) client = wrapper.Client() rdm_api = RDMAPI(client, pid_store) class results: got_request = False got_response = False def DataCallback(self): # request and response for # ola_rdm_set.py -u 1 --uid 7a70:ffffff00 DMX_PERSONALITY 10 # against olad dummy plugin # enable logging in rpc/StreamRpcChannel.py data = sockets[1].recv(4096) expected = binascii.unhexlify( "2b000010080110001a0a52444d436f6d6d616e6422190801120908f0f401150" "0ffffff180020e0012a010a30013800") self.assertEqual(data, expected, msg="Regression check failed. If protocol change " "was intended set expected to: " + str(binascii.hexlify(data))) results.got_request = True response = binascii.unhexlify( "2f0000100802100022290800100218002202000628e001300138004a0908f0f" "4011500ffffff520908f0f40115ac107de05831") sent_bytes = sockets[1].send(response) self.assertEqual(sent_bytes, len(response)) def ResponseCallback(self, response, data, unpack_exception): results.got_response = True self.assertEqual(response.response_type, client.RDM_NACK_REASON) self.assertEqual(response.pid, 0xe0) self.assertEqual(response.nack_reason, RDMNack.NR_DATA_OUT_OF_RANGE) wrapper.AddEvent(0, wrapper.Stop) wrapper._ss.AddReadDescriptor(sockets[1], lambda: DataCallback(self)) uid = UID.FromString("7a70:ffffff00") pid = pid_store.GetName("DMX_PERSONALITY") rdm_api.Set(1, uid, 0, pid, lambda x, y, z: ResponseCallback(self, x, y, z), args=["10"]) wrapper.Run() sockets[0].close() sockets[1].close() self.assertTrue(results.got_request) self.assertTrue(results.got_response)
def main(): try: opts, args = getopt.getopt( sys.argv[1:], 'dhnp:', ['debug', 'help', 'names', 'pid-location=', 'include-draft']) except getopt.GetoptError as err: print(str(err)) Usage() sys.exit(2) pid_location = None level = logging.INFO names = False include_draft = False for o, a in opts: if o in ('-d', '--debug'): level = logging.DEBUG elif o in ('-h', '--help'): Usage() sys.exit() elif o in ('-n', '--names'): names = True elif o in ('--include-draft'): include_draft = True elif o in ( '-p', '--pid-location', ): pid_location = a logging.basicConfig(level=level, format='%(message)s') pid_files = ['pids.proto'] if include_draft: pid_files.append('draft_pids.proto') pid_store = PidStore.GetStore(pid_location, pid_files) for pid in pid_store.Pids(): pid_test_base_name = pid.name.lower().title().replace('_', '') get_size = 0 if ((pid.RequestSupported(PidStore.RDM_GET)) and (pid.GetRequest(PidStore.RDM_GET).HasAtoms())): get_size = pid.GetRequest(PidStore.RDM_GET).GetAtoms()[0].size # print('# Get requires %d bytes' % (get_size)) AllSubDevicesGet(names, pid, pid_test_base_name, get_size) Get(names, pid, pid_test_base_name) if ((pid.RequestSupported(PidStore.RDM_GET)) and (pid.GetRequest(PidStore.RDM_GET).HasAtoms())): first_atom = pid.GetRequest(PidStore.RDM_GET).GetAtoms()[0] if (first_atom.HasRanges() and (not first_atom.ValidateRawValueInRange(0) and first_atom.ValidateRawValueInRange(1))): GetZero(names, pid, pid_test_base_name, first_atom) GetWithNoData(names, pid, pid_test_base_name) GetWithExtraData(names, pid, pid_test_base_name, get_size) else: GetWithData(names, pid, pid_test_base_name) Set(names, pid, pid_test_base_name) set_size = 0 if ((pid.RequestSupported(PidStore.RDM_SET)) and (pid.GetRequest(PidStore.RDM_SET).HasAtoms())): for atom in pid.GetRequest(PidStore.RDM_SET).GetAtoms(): set_size += atom.size # print('# Set requires %d bytes' % (set_size)) first_atom = pid.GetRequest(PidStore.RDM_SET).GetAtoms()[0] if (first_atom.HasRanges() and (not first_atom.ValidateRawValueInRange(0) and first_atom.ValidateRawValueInRange(1))): SetZero(names, pid, pid_test_base_name, first_atom) SetWithNoData(names, pid, pid_test_base_name) SetWithExtraData(names, pid, pid_test_base_name, set_size) else: SetWithData(names, pid, pid_test_base_name) sys.exit(0)
if o in ('-d', '--debug'): level = logging.DEBUG elif o in ('-h', '--help'): Usage() sys.exit() elif o in ('--skip-queued-messages'): skip_queued_messages = True elif o in ( '-p', '--pid-location', ): pid_location = a elif o in ('-u', '--universe'): universe = int(a) if universe is None: Usage() sys.exit() logging.basicConfig(level=level, format='%(message)s') client_wrapper = ClientWrapper() pid_store = PidStore.GetStore(pid_location) controller = ModelCollector(client_wrapper, pid_store) data = controller.Run(universe, skip_queued_messages) pprint.pprint(data) if __name__ == '__main__': main()