def __str__(self): """Get a string representing the last sample. Return: str: A string representing the last sample. """ with lock(self): sample = self._last_sample if sample is None: return self._name + ': Unknown' if not sample._data: return self._name + ': Unknown' result = '' if len(sample._data) >= 2: result = '%s(%d): Activity is \"%s\", Time is \"%s\"' \ % (self._name, sample._timestamp, str(self.get_activity(sample)), str(self.get_time(sample)) ) if len(sample._data) == 3: result += ', Algorithm is \"%d\"' \ % (self.get_algorithm(sample)) return result
def __str__(self): """Get a string representing the last sample. Return: str: A string representing the last sample. """ with lock(self): sample = self._last_sample if sample is None: return self._name + ': Unknown' if not sample._data: return self._name + ': Unknown' if len(sample._data) == 1: result = '%s(%d): %s %s' \ % (self._name, sample._timestamp, str(sample._data[0]), self._description[0]._unit) return result result = '%s(%d): ( ' % (self._name, sample._timestamp) i = 0 while i < len(sample._data): result += '%s: %s %s%s' \ % (self._description[i]._name, str(sample._data[i]), self._description[i]._unit, ' ' if i < len(sample._data) - 1 else ' )') i += 1 return result
def remove_listener(self, listener): """Remove a listener. Args: listener (:class:`blue_st_sdk.firmware_upgrade.utils.firmware_upgrade.FirmwareUpgradeListener`): Listener to be removed. """ if listener is not None: with lock(self): if listener in self._listeners: self._listeners.remove(listener)
def add_listener(self, listener): """Add a listener. Args: listener (:class:`blue_st_sdk.firmware_upgrade.utils.firmware_upgrade.FirmwareUpgradeListener`): Listener to be added. """ if listener is not None: with lock(self): if not listener in self._listeners: self._listeners.append(listener)
def _set_listener(self, listener): """Set the listener to the debug console. Args: listener (:class:`blue_st_sdk.firmware_upgrade.debug_console.DebugConsoleListener`): Listener to the debug console. """ with lock(self): self._debug_console.remove_listener(self._debug_console_listener) self._debug_console.add_listener(listener) self._debug_console_listener = listener
def remove_logger(self, logger): """Remove a logger. Args: logger (:class:`blue_st_sdk.feature.FeatureLogger`): Logger to be removed. """ if logger is not None: with lock(self): if logger in self._loggers: self._loggers.remove(logger)
def add_logger(self, logger): """Add a logger. Args: logger (:class:`blue_st_sdk.feature.FeatureLogger`): Logger to be added. """ if logger is not None: with lock(self): if not logger in self._loggers: self._loggers.append(logger)
def remove_listener(self, listener): """Remove a listener. Args: listener (:class:`blue_st_sdk.node.NodeListener`): Listener to be removed. """ if listener is not None: with lock(self): if listener in self._listeners: self._listeners.remove(listener)
def add_listener(self, listener): """Add a listener. Args: listener (:class:`blue_st_sdk.node.NodeListener`): Listener to be added. """ if listener is not None: with lock(self): if not listener in self._listeners: self._listeners.append(listener)
def __str__(self): """Get a string representing the last sample. Return: str: A string representing the last sample. """ with lock(self): sample = self._last_sample if sample is None: return self._name + ': Unknown' if not sample._data: return self._name + ': Unknown' if len(sample._data) == 1: result = '%s(%d): %s %s' \ % (self._name, sample._timestamp, str(sample._data[0]), self._description[0]._unit) return result # check on timestamp (ADPCM Audio and ADPCM Sync samples don't have # the timestamp field in order to save bandwidth) if sample._timestamp is not None: result = '%s(%d): ( ' % (self._name, sample._timestamp) i = 0 while i < len(sample._data): result += '%s: %s %s%s' \ % (self._description[i]._name, str(sample._data[i]), self._description[i]._unit, ' ' if i < len(sample._data) - 1 else ' )') i += 1 else: # only for Audio Features result = str(self._name) + " - " for i in range(0,len(sample._data)-1): result += str(sample._data[i]) + ", " result += str(sample._data[len(sample._data)-1]) return result
def update(self, timestamp, data, offset, notify_update=False): """Update feature's internal data through an atomic operation, and notify the registered listeners about the update, if needed. This method has to be called by a node whenever it receives new data from the feature, not by the application. When overriding this method, please remember to update the timestamp and the last-updated value, and to acquire the write-lock. Args: timestamp (int): Package's timestamp. data (list): Feature's data. offset (int): Offset position to start reading data. notify_update (bool, optional): If True all the registered listeners are notified about the new data. Returns: int: The number of bytes read. Raises: :exc:`blue_st_sdk.utils.blue_st_exceptions.InvalidDataException` if the data array has not enough data to read. """ # Update the feature's internal data sample = None with lock(self): try: extracted_data = self.extract_data(timestamp, data, offset) except InvalidDataException as e: raise e sample = self._last_sample = extracted_data.get_sample() read_bytes = extracted_data.get_read_bytes() self._last_update = datetime.now() if notify_update: # Notify all the registered listeners about the new data. self._notify_update(sample) # Log the new data through all the registered loggers. self._log_update(data[offset:offset + read_bytes], sample) return read_bytes
def __str__(self): """Get a string representing the last sample. Return: str: A string representing the last sample. """ with lock(self): sample = self._last_sample if sample is None: return self._name + ': Unknown' if not sample._data: return self._name + ': Unknown' if len(sample._data) == 1: switch = 'ON' if self.get_switch_status(sample) else 'OFF' result = '%s(%d): %s' \ % (self._name, sample._timestamp, switch) return result