'This function acts on messages from the firmware'

def _listen(self):

    self.clear = True
    if (not self.printing):
        self._listen_until_online()
    while self._listen_can_continue():
        line = self._readline()
        if (line is None):
            break
        if line.startswith('DEBUG_'):
            continue
        if (line.startswith(tuple(self.greetings)) or line.startswith('ok')):
            self.clear = True
        if (line.startswith('ok') and ('T:' in line)):
            for handler in self.event_handler:
                try:
                    handler.on_temp(line)
                except:
                    logging.error(traceback.format_exc())
        if (line.startswith('ok') and ('T:' in line) and self.tempcb):
            try:
                self.tempcb(line)
            except:
                self.logError(traceback.format_exc())
        elif line.startswith('Error'):
            self.logError(line)
        if (line.lower().startswith('resend') or line.startswith('rs')):
            for haystack in ['N:', 'N', ':']:
                line = line.replace(haystack, '    ')
            linewords = line.split()
            while (len(linewords) != 0):
                try:
                    toresend = int(linewords.pop(0))
                    self.resendfrom = toresend
                    break
                except:
                    pass
            self.clear = True
    self.clear = True
