arduino-2020-06-03-1146.py
01234567890123456789012345678901234567890123456789012345678901234567890123456789









98598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043








11781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218











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




  """Converts a number of seconds to a three-character time representation (i.e.: 23M).

  Converts seconds to a three character representation containing at most two digits,
  potentially with a decimal point, and one character indicating time unit (S, M, H, or D).

  Args:
    s: Number of seconds.

  Returns:
    2-tuple of string as described and string map indicating decimal position
  """
  m = s / messageboard.SECONDS_IN_MINUTE
  h = s / messageboard.SECONDS_IN_HOUR
  d = s / messageboard.SECONDS_IN_DAY

  no_decimals = '000'
  decimal_after_first_character = '100'

  partial_decimal_mask = no_decimals

  if s < 10:
    numeric_string = '%sS' % FloatToAlphanumericStr(s, 1, 3, sign=False)
    partial_decimal_mask = decimal_after_first_character
  elif s < messageboard.SECONDS_IN_MINUTE:
    numeric_string = '%2dS' % round(s)

  elif m < 10:
    numeric_string = '%sM' % FloatToAlphanumericStr(m, 1, 3, sign=False)
    partial_decimal_mask = decimal_after_first_character
  elif m < messageboard.MINUTES_IN_HOUR:
    numeric_string = '%2dM' % round(m)

  elif h < 10:
    numeric_string = '%sH' % FloatToAlphanumericStr(h, 1, 3, sign=False)
    partial_decimal_mask = decimal_after_first_character
  elif h < messageboard.HOURS_IN_DAY:
    numeric_string = '%2dH' % round(h)

  elif d < 10:
    numeric_string = '%sD' % FloatToAlphanumericStr(d, 1, 3, sign=False)
    partial_decimal_mask = decimal_after_first_character
  else:
    numeric_string = '%2dD' % round(d)

  return numeric_string, partial_decimal_mask


def SimulateCommand(potential_commands, counter, fraction_command=0.01, randomized=False):
  """Simulates the remote generating a command for remote-free testing.

  A command from the list of potential_commands is generated periodically, roughly
  fraction_command percent of the time.
  - not randomized: a command is returned every time (counter / fraction_command) rolls
    over to a new integer. The command returned is the next one in the list of potential
    commands. For instance, if fraction_command = 0.01, when counter=100, the first
    command in potential_commands is returned; when counter=200, the second command is
    returned, and so on.  At the end of the list, we rotate back to the first command.
  - randomized: fraction_command percent of the time, a randomly selected command is sent.





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




      ('setting_delay',               'H'),  # 2 bytes
      ('line1',                       '9s'), # 9 bytes; 8 character plus terminator
      ('line2',                       '9s'), # 9 bytes; 8 character plus terminator
      ('line1_dec_mask',              'H'),  # 2 bytes
      ('line2_dec_mask',              'H'),  # 2 bytes
  )
  #pylint: enable = bad-whitespace
  read_keys, unused_read_format_tuple, read_format_string = SplitFormat(read_config)
  write_keys, write_format_tuple, write_format_string = SplitFormat(write_config)

  values_d = {}
  low_batt = False
  to_parent_q.put(('pin', (messageboard.GPIO_ERROR_BATTERY_CHARGE, low_batt)))

  link = Serial(
      *REMOTE_CONNECTION, read_timeout=7,
      error_pin=messageboard.GPIO_ERROR_ARDUINO_REMOTE_CONNECTION, to_parent_q=to_parent_q,
      read_format=read_format_string, write_format=write_format_string, name='Remote')
  link.Open()

  display_mode = 2  #TODO: remove after switch integration

  flight, json_desc_dict, configuration, additional_attr = InitialMessageValues(
      to_arduino_q)
  next_read = 0
  next_write = 0

  while not shutdown.value:
    if not to_arduino_q.empty():
      to_arduino_message = to_arduino_q.get(block=False)
      flight, json_desc_dict, configuration, additional_attr = to_arduino_message

      if 'test_remote' in configuration:
        messageboard.RemoveSetting(configuration, 'test_remote')

        def TestDisplayMode(m):
          SendRemoteMessage(
              flight, json_desc_dict, configuration, additional_attr,
              m, write_keys, write_format_tuple, link)
          time.sleep(1)





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





01234567890123456789012345678901234567890123456789012345678901234567890123456789









98598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043








11781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218











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




  """Converts a number of seconds to a three-character time representation (i.e.: 23M).

  Converts seconds to a three character representation containing at most two digits,
  potentially with a decimal point, and one character indicating time unit (S, M, H, or D).

  Args:
    s: Number of seconds.

  Returns:
    2-tuple of string as described and string map indicating decimal position
  """
  m = s / messageboard.SECONDS_IN_MINUTE
  h = s / messageboard.SECONDS_IN_HOUR
  d = s / messageboard.SECONDS_IN_DAY

  no_decimals = '000'
  decimal_after_first_character = '100'

  partial_decimal_mask = no_decimals

  if round(s, 1) < 10:
    numeric_string = '%sS' % FloatToAlphanumericStr(s, 1, 3, sign=False)
    partial_decimal_mask = decimal_after_first_character
  elif s < messageboard.SECONDS_IN_MINUTE:
    numeric_string = '%2dS' % round(s)

  elif round(m, 1) < 10:
    numeric_string = '%sM' % FloatToAlphanumericStr(m, 1, 3, sign=False)
    partial_decimal_mask = decimal_after_first_character
  elif m < messageboard.MINUTES_IN_HOUR:
    numeric_string = '%2dM' % round(m)

  elif round(h, 1) < 10:
    numeric_string = '%sH' % FloatToAlphanumericStr(h, 1, 3, sign=False)
    partial_decimal_mask = decimal_after_first_character
  elif h < messageboard.HOURS_IN_DAY:
    numeric_string = '%2dH' % round(h)

  elif round(d, 1) < 10:
    numeric_string = '%sD' % FloatToAlphanumericStr(d, 1, 3, sign=False)
    partial_decimal_mask = decimal_after_first_character
  else:
    numeric_string = '%2dD' % round(d)

  return numeric_string, partial_decimal_mask


def SimulateCommand(potential_commands, counter, fraction_command=0.01, randomized=False):
  """Simulates the remote generating a command for remote-free testing.

  A command from the list of potential_commands is generated periodically, roughly
  fraction_command percent of the time.
  - not randomized: a command is returned every time (counter / fraction_command) rolls
    over to a new integer. The command returned is the next one in the list of potential
    commands. For instance, if fraction_command = 0.01, when counter=100, the first
    command in potential_commands is returned; when counter=200, the second command is
    returned, and so on.  At the end of the list, we rotate back to the first command.
  - randomized: fraction_command percent of the time, a randomly selected command is sent.





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




      ('setting_delay',               'H'),  # 2 bytes
      ('line1',                       '9s'), # 9 bytes; 8 character plus terminator
      ('line2',                       '9s'), # 9 bytes; 8 character plus terminator
      ('line1_dec_mask',              'H'),  # 2 bytes
      ('line2_dec_mask',              'H'),  # 2 bytes
  )
  #pylint: enable = bad-whitespace
  read_keys, unused_read_format_tuple, read_format_string = SplitFormat(read_config)
  write_keys, write_format_tuple, write_format_string = SplitFormat(write_config)

  values_d = {}
  low_batt = False
  to_parent_q.put(('pin', (messageboard.GPIO_ERROR_BATTERY_CHARGE, low_batt)))

  link = Serial(
      *REMOTE_CONNECTION, read_timeout=7,
      error_pin=messageboard.GPIO_ERROR_ARDUINO_REMOTE_CONNECTION, to_parent_q=to_parent_q,
      read_format=read_format_string, write_format=write_format_string, name='Remote')
  link.Open()

  display_mode = DISP_LAST_FLIGHT_NUMB_ORIG_DEST  # initial state

  flight, json_desc_dict, configuration, additional_attr = InitialMessageValues(
      to_arduino_q)
  next_read = 0
  next_write = 0

  while not shutdown.value:
    if not to_arduino_q.empty():
      to_arduino_message = to_arduino_q.get(block=False)
      flight, json_desc_dict, configuration, additional_attr = to_arduino_message

      if 'test_remote' in configuration:
        messageboard.RemoveSetting(configuration, 'test_remote')

        def TestDisplayMode(m):
          SendRemoteMessage(
              flight, json_desc_dict, configuration, additional_attr,
              m, write_keys, write_format_tuple, link)
          time.sleep(1)





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