arduino-2020-05-30-1527.py
01234567890123456789012345678901234567890123456789012345678901234567890123456789









226227228229230231232233234235236237238239240241242243244245246247248249250251252253 254255256257258259260261262263264265266267268269270271272273








665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710








12221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247



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




    if self.error_pin:
      self.to_parent_q.put(('pin', (self.error_pin, False)))
    self.last_read = time.time()
    self.last_receipt = time.time()
    self.reset_flag = True

  def Reopen(self, log_message=None):
    """Closes and reopens a link, optionally logging a message."""
    if self.connection_type == CONNECTION_FLAG_SIMULATED:
      raise NotImplementedError('Not implemented for simulations')

    self.link = ReopenConnection(
        self.open_function, self.link, self.connection_tuple,
        baud=self.baud, timeout=self.open_timeout, log_message=log_message)
    if self.error_pin:
      self.to_parent_q.put(('pin', (self.error_pin, False)))
    self.reset_flag = True
    self.last_read = time.time()
    self.last_receipt = time.time()

  def Close(self):
    """Closes an open serial connection."""
    if self.connection_type == CONNECTION_FLAG_SIMULATED:
      return

    self.link.close()
    if self.error_pin:
      self.to_parent_q.put(('pin', (self.error_pin, True)))


  def Available(self):
    """Calls self.link.available()."""
    if self.connection_type == CONNECTION_FLAG_SIMULATED:
      raise NotImplementedError('Not implemented for simulations')
    self.link.available()

  def Read(self, format_string=None):
    """Reads from an open serial.

    Reads from an open serial values as identified in the format_string provided here,
    or if not provided in this call, as saved on the Serial instance.  If an OSError
    exception is detected, or if this read, in failing to return non-empty results, means
    that the heartbeat timeout time has elapsed, this method will attempt to reopen
    the connection.

    Args:
      format_string: String of the form expected by struct.pack

    Returns:




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




      link.Read()  # simple ack message sent by servos
      next_read = time.time() + READ_DELAY_TIME

    now = GetNow(json_desc_dict, additional_attr)

    current_angles = AzimuthAltitude(flight, now)
    if current_angles and time.time() > next_write:
      if current_angles[1] >= configuration['minimum_altitude_servo_tracking']:
        flight_present = True
        laser_rgb = LaserRGBFlight(flight)
        link.Write((*current_angles, *laser_rgb))
        last_angles = current_angles

      # flight no longer tracked; send one more command to turn off lasers
      elif flight_present:
        link.Write((*last_angles, *LASER_RGB_OFF))
        flight_present = False

      next_write = time.time() + WRITE_DELAY_TIME

  link.Close()
  failure_message = 'Shutdown signal received by process %d' % os.getpid()
  Log(failure_message, link)
  to_parent_q.put((
      'pin',
      (messageboard.GPIO_ERROR_ARDUINO_SERVO_CONNECTION, True, failure_message)))


LASER_RGB_OFF = (0, 0, 0)
def LaserRGBFlight(flight):
  """Based on flight attributes, set the laser."""
  if not flight:
    return LASER_RGB_OFF
  return 1, 0, 0


def DifferentFlights(f1, f2):
  """True if flights same except for persistent path; False if they differ.

  We cannot simply check if two flights are identical by checking equality of the dicts,
  because a few attributes are updated after the flight is first found:
  - the persistent_path is kept current
  - cached_* attributes may be updated
  - the insights are generated after flight first enqueued
  On the other hand, we cannot check if they are identical by looking just at the
  flight number, because flight numbers may be unknown. Thus, this checks all




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




          time.sleep(1)

        TestDisplayMode(DISP_LAST_FLIGHT_NUMB_ORIG_DEST)
        TestDisplayMode(DISP_LAST_FLIGHT_AZIMUTH_ELEVATION)
        TestDisplayMode(DISP_FLIGHT_COUNT_LAST_SEEN)
        TestDisplayMode(DISP_RADIO_RANGE)

    if time.time() >= next_write:
      next_write = SendRemoteMessage(
          flight, json_desc_dict, configuration, additional_attr,
          display_mode, write_keys, write_format_tuple, link)

    if time.time() >= next_read:
      values_t = link.Read()  # simple ack message sent by servos
      values_d = dict(zip(read_keys, values_t))
      if values_d.get('confirmed'):
        display_mode, low_batt = ExecuteArduinoCommand(
            values_d, configuration, display_mode, low_batt, to_parent_q, link)
      next_read = time.time() + READ_DELAY_TIME

  link.Close()
  failure_message = 'Shutdown signal received by process %d' % os.getpid()
  Log(failure_message, link)
  to_parent_q.put((
      'pin',
      (messageboard.GPIO_ERROR_ARDUINO_REMOTE_CONNECTION, True, failure_message)))

01234567890123456789012345678901234567890123456789012345678901234567890123456789









226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274








666667668669670671672673674675676677678679680681682683684685686     687688689690691692693694695696697698699700701702703704705706








121812191220122112221223122412251226122712281229123012311232123312341235123612371238     



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




    if self.error_pin:
      self.to_parent_q.put(('pin', (self.error_pin, False)))
    self.last_read = time.time()
    self.last_receipt = time.time()
    self.reset_flag = True

  def Reopen(self, log_message=None):
    """Closes and reopens a link, optionally logging a message."""
    if self.connection_type == CONNECTION_FLAG_SIMULATED:
      raise NotImplementedError('Not implemented for simulations')

    self.link = ReopenConnection(
        self.open_function, self.link, self.connection_tuple,
        baud=self.baud, timeout=self.open_timeout, log_message=log_message)
    if self.error_pin:
      self.to_parent_q.put(('pin', (self.error_pin, False)))
    self.reset_flag = True
    self.last_read = time.time()
    self.last_receipt = time.time()

  def Close(self, close_message):
    """Closes an open serial connection."""
    if self.connection_type == CONNECTION_FLAG_SIMULATED:
      return

    self.link.close()
    if self.error_pin:
      self.to_parent_q.put(('pin', (self.error_pin, True, close_message)))
    Log(close_message, self)

  def Available(self):
    """Calls self.link.available()."""
    if self.connection_type == CONNECTION_FLAG_SIMULATED:
      raise NotImplementedError('Not implemented for simulations')
    self.link.available()

  def Read(self, format_string=None):
    """Reads from an open serial.

    Reads from an open serial values as identified in the format_string provided here,
    or if not provided in this call, as saved on the Serial instance.  If an OSError
    exception is detected, or if this read, in failing to return non-empty results, means
    that the heartbeat timeout time has elapsed, this method will attempt to reopen
    the connection.

    Args:
      format_string: String of the form expected by struct.pack

    Returns:




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




      link.Read()  # simple ack message sent by servos
      next_read = time.time() + READ_DELAY_TIME

    now = GetNow(json_desc_dict, additional_attr)

    current_angles = AzimuthAltitude(flight, now)
    if current_angles and time.time() > next_write:
      if current_angles[1] >= configuration['minimum_altitude_servo_tracking']:
        flight_present = True
        laser_rgb = LaserRGBFlight(flight)
        link.Write((*current_angles, *laser_rgb))
        last_angles = current_angles

      # flight no longer tracked; send one more command to turn off lasers
      elif flight_present:
        link.Write((*last_angles, *LASER_RGB_OFF))
        flight_present = False

      next_write = time.time() + WRITE_DELAY_TIME

  link.Close('Shutdown requested')







LASER_RGB_OFF = (0, 0, 0)
def LaserRGBFlight(flight):
  """Based on flight attributes, set the laser."""
  if not flight:
    return LASER_RGB_OFF
  return 1, 0, 0


def DifferentFlights(f1, f2):
  """True if flights same except for persistent path; False if they differ.

  We cannot simply check if two flights are identical by checking equality of the dicts,
  because a few attributes are updated after the flight is first found:
  - the persistent_path is kept current
  - cached_* attributes may be updated
  - the insights are generated after flight first enqueued
  On the other hand, we cannot check if they are identical by looking just at the
  flight number, because flight numbers may be unknown. Thus, this checks all




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




          time.sleep(1)

        TestDisplayMode(DISP_LAST_FLIGHT_NUMB_ORIG_DEST)
        TestDisplayMode(DISP_LAST_FLIGHT_AZIMUTH_ELEVATION)
        TestDisplayMode(DISP_FLIGHT_COUNT_LAST_SEEN)
        TestDisplayMode(DISP_RADIO_RANGE)

    if time.time() >= next_write:
      next_write = SendRemoteMessage(
          flight, json_desc_dict, configuration, additional_attr,
          display_mode, write_keys, write_format_tuple, link)

    if time.time() >= next_read:
      values_t = link.Read()  # simple ack message sent by servos
      values_d = dict(zip(read_keys, values_t))
      if values_d.get('confirmed'):
        display_mode, low_batt = ExecuteArduinoCommand(
            values_d, configuration, display_mode, low_batt, to_parent_q, link)
      next_read = time.time() + READ_DELAY_TIME

  link.Close('Shutdown requested')