arduino-2020-06-21-1117.py
01234567890123456789012345678901234567890123456789012345678901234567890123456789









306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346








373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413











                            <----SKIPPED LINES---->




      format_string = self.read_format
    try:
      data = Read(self.link, format_string, bytes_read=bytes_read)

    # on OSError, record a disconnection and attempt to reconnect & re-read
    except OSError as e:
      failure_message = 'Failed to read from %s: %s' % (self.name, e)
      if self.error_pin:
        self.to_parent_q.put(('pin', (self.error_pin, True, failure_message)))
      self.Reopen(log_message=failure_message)
      return self.Read(format_string=format_string)

    self.last_read = time.time()
    if data:
      self.last_receipt = time.time()
      if LOG_SERIALS:
        now = time.time()
        elapsed = now - self.start_time
        str_data = str(
            ['%7.2f' % d if isinstance(d, float) else str(d) for d in data])
        now_time = messageboard.EpochDisplayTime(now, '%d %H%M%S.%f')
        message = '%s %10.3f RECD@%s: %s\n' % (
            now_time, elapsed, self.name, str_data)
        with open(SERIALS_LOG, 'a') as f:
          f.write(message)
        messageboard.Tail(
            SERIALS_LOG,
            ROLLING_SERIALS_LOG,
            max_line_length=130,
            lines_to_keep=messageboard.ROLLING_LOG_SIZE)

    # If we haven't received data (despite reading) in more than the timeout,
    # close and reopen.
    if (
        self.read_timeout and
        self.last_read - self.last_receipt > self.read_timeout):
      failure_message = (
          'Heartbeat not received in %.2f seconds (expected: %.2f) on %s' % (
              self.last_read - self.last_receipt, self.read_timeout, self.name))
      if self.error_pin:
        self.to_parent_q.put(('pin', (self.error_pin, True, failure_message)))




                            <----SKIPPED LINES---->




    now = time.time()
    elapsed = now - self.start_time
    str_values = str(
        ['%7.2f' % v if isinstance(v, float) else str(v) for v in values])
    if self.connection_type == CONNECTION_FLAG_SIMULATED:
      with open(self.connection_tuple[1], 'a') as f:
        f.write('%10.3f: %s\n' % (elapsed, str_values))
      return

    if not format_string:
      format_string = self.write_format
    try:
      Write(self.link, values, format_string)
    except OSError as e:
      failure_message = 'Failed to write: %s' % e
      if self.error_pin:
        self.to_parent_q.put(('pin', (self.error_pin, True, failure_message)))
      self.Reopen(log_message=failure_message)
      self.Write(values)
    if LOG_SERIALS:
      now_time = messageboard.EpochDisplayTime(now, '%d %H%M%S.%f')
      message = '%s %10.3f SENT@%s: %s\n' % (
          now_time, elapsed, self.name, str_values)
      with open(SERIALS_LOG, 'a') as f:
        f.write(message)
      messageboard.Tail(
          SERIALS_LOG,
          ROLLING_SERIALS_LOG,
          max_line_length=130,
          lines_to_keep=messageboard.ROLLING_LOG_SIZE)

  def HasReset(self):
    """Indicates exactly once whether serial has reset since last called."""
    if self.connection_type == CONNECTION_FLAG_SIMULATED:
      raise NotImplementedError('Not implemented for simulations')

    flag = self.reset_flag
    self.reset_flag = False
    return flag






                            <----SKIPPED LINES---->





01234567890123456789012345678901234567890123456789012345678901234567890123456789









306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346








373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413











                            <----SKIPPED LINES---->




      format_string = self.read_format
    try:
      data = Read(self.link, format_string, bytes_read=bytes_read)

    # on OSError, record a disconnection and attempt to reconnect & re-read
    except OSError as e:
      failure_message = 'Failed to read from %s: %s' % (self.name, e)
      if self.error_pin:
        self.to_parent_q.put(('pin', (self.error_pin, True, failure_message)))
      self.Reopen(log_message=failure_message)
      return self.Read(format_string=format_string)

    self.last_read = time.time()
    if data:
      self.last_receipt = time.time()
      if LOG_SERIALS:
        now = time.time()
        elapsed = now - self.start_time
        str_data = str(
            ['%7.2f' % d if isinstance(d, float) else str(d) for d in data])
        now_time = messageboard.EpochDisplayTime(now, '%H:%M:%S.%f')
        message = '%s %10.3f RECD@%s: %s\n' % (
            now_time, elapsed, self.name, str_data)
        with open(SERIALS_LOG, 'a') as f:
          f.write(message)
        messageboard.Tail(
            SERIALS_LOG,
            ROLLING_SERIALS_LOG,
            max_line_length=130,
            lines_to_keep=messageboard.ROLLING_LOG_SIZE)

    # If we haven't received data (despite reading) in more than the timeout,
    # close and reopen.
    if (
        self.read_timeout and
        self.last_read - self.last_receipt > self.read_timeout):
      failure_message = (
          'Heartbeat not received in %.2f seconds (expected: %.2f) on %s' % (
              self.last_read - self.last_receipt, self.read_timeout, self.name))
      if self.error_pin:
        self.to_parent_q.put(('pin', (self.error_pin, True, failure_message)))




                            <----SKIPPED LINES---->




    now = time.time()
    elapsed = now - self.start_time
    str_values = str(
        ['%7.2f' % v if isinstance(v, float) else str(v) for v in values])
    if self.connection_type == CONNECTION_FLAG_SIMULATED:
      with open(self.connection_tuple[1], 'a') as f:
        f.write('%10.3f: %s\n' % (elapsed, str_values))
      return

    if not format_string:
      format_string = self.write_format
    try:
      Write(self.link, values, format_string)
    except OSError as e:
      failure_message = 'Failed to write: %s' % e
      if self.error_pin:
        self.to_parent_q.put(('pin', (self.error_pin, True, failure_message)))
      self.Reopen(log_message=failure_message)
      self.Write(values)
    if LOG_SERIALS:
      now_time = messageboard.EpochDisplayTime(now, '%H:%M:%S.%f')
      message = '%s %10.3f SENT@%s: %s\n' % (
          now_time, elapsed, self.name, str_values)
      with open(SERIALS_LOG, 'a') as f:
        f.write(message)
      messageboard.Tail(
          SERIALS_LOG,
          ROLLING_SERIALS_LOG,
          max_line_length=130,
          lines_to_keep=messageboard.ROLLING_LOG_SIZE)

  def HasReset(self):
    """Indicates exactly once whether serial has reset since last called."""
    if self.connection_type == CONNECTION_FLAG_SIMULATED:
      raise NotImplementedError('Not implemented for simulations')

    flag = self.reset_flag
    self.reset_flag = False
    return flag






                            <----SKIPPED LINES---->