Beispiel #1
0
 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()))
Beispiel #2
0
 def stop(self):
     """
     Signals the process to stop parsing data.
     :return:
     """
     Log.d(TAG, "Process finishing...")
     self._exit.set()
Beispiel #3
0
 def run(self):
     """
     Process will monitor the internal buffer to parse raw data and distribute to graph and storage, if needed.
     The process will loop again after timeout if more data is available.
     :return:
     """
     Log.d(TAG, "Process starting...")
     while not self._exit.is_set():
         self._consume_queue()
         sleep(self._consumer_timeout)
     # last check on the queue to completely remove data.
     self._consume_queue()
     Log.d(TAG, "Process finished")
Beispiel #4
0
 def get_ports():
     """
     Gets a list of the available serial ports.
     :return: List of available serial ports.
     :rtype: str list.
     """
     if Architecture.get_os() is OSType.macosx:
         import glob
         return glob.glob("/dev/tty.*")
     else:
         found_ports = []
         for port in list(list_ports.comports()):
             Log.d(TAG, "found device {}".format(port))
             found_ports.append(port.device)
         return found_ports
Beispiel #5
0
    def __init__(self,
                 data_queue,
                 store_reference=None,
                 split=Constants.csv_delimiter,
                 consumer_timeout=Constants.parser_timeout_ms):
        """

        :param data_queue: Reference to Queue where processed data will be put.
        :type data_queue: multiprocessing Queue.
        :param store_reference: Reference to CSVProcess instance, if needed.
        :type store_reference: CSVProcess (multiprocessing.Process)
        :param split: Delimiter in incoming data.
        :type split: str.
        :param consumer_timeout: Time to wait after emptying the internal buffer before next parsing.
        :type consumer_timeout: float.
        """
        multiprocessing.Process.__init__(self)
        self._exit = multiprocessing.Event()
        self._in_queue = multiprocessing.Queue()
        self._out_queue = data_queue
        self._consumer_timeout = consumer_timeout
        self._split = split
        self._store_reference = store_reference
        Log.d(TAG, "Process ready")