01234567890123456789012345678901234567890123456789012345678901234567890123456789
971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014 12061207120812091210121112121213121412151216121712181219122012211222122312241225 12261227122812291230 12311232123312341235123612371238123912401241124212431244124512461247124812491250 |
<----SKIPPED LINES---->
# a command might request a histogram; simply generate and save a histogram file to disk
if command['histogram_enabled']:
h_type = GetName(HISTOGRAM_TYPES, command['current_hist_type'])
h_history = GetName(HISTOGRAM_HISTORY, command['current_hist_history'])
to_parent_q.put(('histogram', (h_type, h_history)))
log_lines.append(' |-->Requested %s histogram with %s data' % (h_type, h_history))
# a command might update us on the display mode; based on the display mode, we might
# pass different attributes back to the remote
if display_mode != command['display_mode']:
log_lines.append(' |-->Display mode set to %d (%s)' % (
command['display_mode'], DISPLAY_MODE_NAMES[display_mode]))
messageboard.WriteFile(REMOTE_DISPLAY_MODE, str(command['display_mode']))
# a command might tell us the battery is low
to_parent_q.put(
('pin', (messageboard.GPIO_ERROR_BATTERY_CHARGE, command['low_battery'])))
if low_battery != command['low_battery']:
log_lines.append(' |-->Low battery set to %d' % command['low_battery'])
if VERBOSE:
if log_lines:
log_lines.insert(0, '') # for improved formatting
Log('\n'.join(log_lines), link)
return command['display_mode'], command['low_battery']
def SecondsToShortString(s):
"""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
<----SKIPPED LINES---->
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()
# Read in the saved display mode, if it exists
display_mode = messageboard.ReadFile(REMOTE_DISPLAY_MODE, log_exception=False)
if not display_mode:
display_mode = DISP_LAST_FLIGHT_NUMB_ORIG_DEST
else:
display_mode = int(display_mode)
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
Log(additional_attr['ts']) # TODO: debug
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)
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)
<----SKIPPED LINES---->
|
01234567890123456789012345678901234567890123456789012345678901234567890123456789
971972973974975976977978979980981982983984985986987988989990 99199299399499599699799899910001001100210031004100510061007100810091010101110121013 120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261 |
<----SKIPPED LINES---->
# a command might request a histogram; simply generate and save a histogram file to disk
if command['histogram_enabled']:
h_type = GetName(HISTOGRAM_TYPES, command['current_hist_type'])
h_history = GetName(HISTOGRAM_HISTORY, command['current_hist_history'])
to_parent_q.put(('histogram', (h_type, h_history)))
log_lines.append(' |-->Requested %s histogram with %s data' % (h_type, h_history))
# a command might update us on the display mode; based on the display mode, we might
# pass different attributes back to the remote
if display_mode != command['display_mode']:
log_lines.append(' |-->Display mode set to %d (%s)' % (
command['display_mode'], DISPLAY_MODE_NAMES[display_mode]))
messageboard.WriteFile(REMOTE_DISPLAY_MODE, str(command['display_mode']))
# a command might tell us the battery is low
to_parent_q.put(
('pin', (messageboard.GPIO_ERROR_BATTERY_CHARGE, command['low_battery'])))
if low_battery != command['low_battery']:
log_lines.append(' |-->Low battery set to %d' % command['low_battery'])
if log_lines:
log_lines.insert(0, '') # for improved formatting
Log('\n'.join(log_lines), link)
return command['display_mode'], command['low_battery']
def SecondsToShortString(s):
"""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
<----SKIPPED LINES---->
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()
# Read in the saved display mode, if it exists
display_mode = messageboard.ReadFile(REMOTE_DISPLAY_MODE, log_exception=False)
if not display_mode:
display_mode = DISP_LAST_FLIGHT_NUMB_ORIG_DEST
else:
display_mode = int(display_mode)
flight, json_desc_dict, configuration, additional_attr = InitialMessageValues(
to_arduino_q)
next_read = 0
next_write = 0
last_configuration = configuration
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 'setting_screen_enabled' not in last_configuration and 'setting_screen_enabled' in configuration:
Log('setting_screen_enabled changed from NOT PRESENT to ON')
if 'setting_screen_enabled' in last_configuration and 'setting_screen_enabled' not in configuration:
Log('setting_screen_enabled changed from ON to NOT PRESENT')
last_configuration = configuration
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)
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)
<----SKIPPED LINES---->
|