Skip to content

Commit

Permalink
Switch to a set for temporarily storing the slots, so we can add the …
Browse files Browse the repository at this point in the history
…number of slots from various sources
  • Loading branch information
peternewman committed Dec 26, 2018
1 parent e3e1527 commit aa33fca
Showing 1 changed file with 17 additions and 25 deletions.
42 changes: 17 additions & 25 deletions tools/rdm/ModelCollector.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def _ResetData(self):
self.outstanding_pid = None
self.work_state = None
self.manufacturer_pids = []
self.slots = []
self.slots = set()
self.personalities = []
self.sensors = []
# keyed by manufacturer id
Expand Down Expand Up @@ -212,6 +212,8 @@ def _HandleDeviceInfo(self, data):
}

self.personalities = list(xrange(1, data['personality_count'] + 1))
self.slots.update(xrange(0, data['dmx_footprint']))
logging.debug("Populated %d slots from device info" % (slot_count))
self.sensors = list(xrange(0, data['sensor_count']))
self._NextState()
else:
Expand Down Expand Up @@ -324,7 +326,7 @@ def _HandleSlotInfo(self, data):
if this_slot_data is not None:
this_slot_data['label_id'] = slot['slot_label_id']
this_slot_data['type'] = slot['slot_type']
self.slots.append(slot['slot_offset'])
self.slots.add(slot['slot_offset'])
self._NextState()

def _HandleSlotDescription(self, data):
Expand Down Expand Up @@ -420,16 +422,10 @@ def _NextState(self):
pid)
self._NextState()
elif self.work_state == self.SLOT_INFO:
# fetch slot description
self.work_state = self.SLOT_DESCRIPTION
pid = self.pid_store.GetName('SLOT_DESCRIPTION')
if self._CheckPidSupported(pid):
if not self.slots:
slot_count = self._GetCurrentPersonality().get('slot_count', 0)
if slot_count:
self.slots = list(xrange(0, slot_count))
logging.debug("%s supported but no slots from SLOT_INFO, "
"populated %d slots from personality info" %
(pid, slot_count))
self._FetchNextSlotDescription()
else:
logging.debug("Skipping pid %s as it's not supported on this device" %
Expand Down Expand Up @@ -550,23 +546,19 @@ def _FetchNextSlotDescription(self):
"""Fetch the description for the next slot, or proceed to the next state if
there are none left.
"""
pid = self.pid_store.GetName('SLOT_DESCRIPTION')
if self._CheckPidSupported(pid):
if self.slots:
slot = self.slots.pop(0)
self.rdm_api.Get(self.universe,
self.uid,
PidStore.ROOT_DEVICE,
pid,
self._RDMRequestComplete,
[slot])
logging.debug('Sent SLOT_DESCRIPTION request for slot %d' % slot)
self.outstanding_pid = pid
else:
self._NextState()
if self.slots:
slot = self.slots.pop()
pid = self.pid_store.GetName('SLOT_DESCRIPTION')
self.rdm_api.Get(self.universe,
self.uid,
PidStore.ROOT_DEVICE,
pid,
self._RDMRequestComplete,
[slot])
logging.debug('Sent SLOT_DESCRIPTION request for slot %d' % slot)
self.outstanding_pid = pid
else:
logging.debug("Skipping pid %s as it's not supported on this device" %
pid)
logging.debug('No more slots to fetch SLOT_DESCRIPTION for')
self._NextState()

def _FetchQueuedMessages(self):
Expand Down

0 comments on commit aa33fca

Please sign in to comment.