Example #1
0
    def __tcp_read(self, isGpsd=False):
        buf = ''
        data = True

        while data and not self._cancel:
            reads, writes, errors = select.select([self._comm], [self._comm],
                                                  [self._comm], 0.1)
            for read in reads:
                data = read.recv(64)
                buf += data
                while buf.find('\n') != -1:
                    line, buf = buf.split('\n', 1)
                    if not isGpsd:
                        pos = line.find('$')
                        if pos != -1 and pos + 1 < len(line):
                            yield line[pos + 1:].rstrip('\r\n')
                    else:
                        yield line
                    if self._raw:
                        line = limit_to_ascii(line)
                        post_event(self._notify,
                                   EventThread(Event.LOC_RAW, 0, line))

            for write in writes:
                if self._send is not None:
                    write.sendall(self._send)
                    self._send = None

            for _error in errors:
                post_event(self._notify,
                           EventThread(Event.LOC_ERR, 0, 'Connection dropped'))
        return
Example #2
0
 def __serial_read(self):
     isSentence = False
     sentence = ''
     while not self._cancel:
         data = self._comm.read(1)
         if data:
             self._timeout.reset()
             if data == '$':
                 isSentence = True
                 continue
             if data == '\r' or data == '\n':
                 isSentence = False
                 if sentence:
                     yield sentence
                     if self._raw:
                         line = limit_to_ascii(sentence)
                         post_event(self._notify,
                                    EventThread(Event.LOC_RAW, 0, line))
                     sentence = ''
             if isSentence:
                 sentence += data
         else:
             time.sleep(0.1)