def _parse_csv(self, time, line): """ Parses incoming data and distributes to external processes. :param time: Timestamp. :type time: float. :param line: Raw data coming from acquisition process. :type line: basestring. :return: """ if len(line) > 0: try: if type(line) == bytes: values = line.decode("UTF-8").split(self._split) elif type(line) == str: values = line.split(self._split) else: raise TypeError values = [float(v) for v in values] Log.d(TAG, values) self._out_queue.put((time, values)) if self._store_reference is not None: self._store_reference.add(time, values) except ValueError: Log.w(TAG, "Can't convert to float. Raw: {}".format(line.strip())) except AttributeError: Log.w( TAG, "Attribute error on type ({}). Raw: {}".format( type(line), line.strip()))
def set_user_log_level(self): """ Sets the user specified log level. :return: """ if self._parser is not None: self._parse_log_level() else: Log.w(TAG, "Parser was not created !") return None
def get_source_speeds(source): """ Gets the available speeds for specified source. :param source: Source to get available speeds. :type source: SourceType. :return: List of available speeds. :rtype: str list. """ if source == SourceType.serial: return SerialProcess.get_speeds() else: Log.w(TAG, "Unknown source selected") return None
def run(self): """ Reads the serial port expecting CSV until a stop call is made. The expected format is comma (",") separated values, and a new line (CRLF or LF) as a new row. While running, it will parse CSV data convert each value to float and added to a queue. If incoming data from serial port can't be converted to float, that data will be discarded. :return: """ Log.i(TAG, "Process starting...") if self._is_port_available(self._serial.port): if not self._serial.isOpen(): self._serial.open() Log.i(TAG, "Port opened") timestamp = time() while not self._exit.is_set(): self._parser.add( [time() - timestamp, self._serial.readline()]) Log.i(TAG, "Process finished") self._serial.close() else: Log.w(TAG, "Port is not opened") else: Log.w(TAG, "Port is not available")