01234567890123456789012345678901234567890123456789012345678901234567890123456789
917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949 950951952953954955956957958959960961962963964965966967968969 114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210 | <----SKIPPED LINES----> - (Re)display a recent flight - Display a histogram - Send information for a different display mode - Indicate that the battery is low Args: command: dictionary representing all data fields from remote. configuration: dictionary representing the current state of the messageboard configuration. display_mode: current display mode; only passed so that we may identify changes. low_battery: current battery status; only passed so that we may identify changes. to_parent_q: multiprocessing queue, where instructions to send back to messageboard, if any, can be placed. link: the open serial link. Returns: A 2-tuple of potentially-updated display_mode, and low_battery. """ # command might update a setting; see if there's a change, and if so, write to disk setting_change = False # remote sees T/F whereas messageboard.py & the web interface expect 'on'/absent key if command['setting_screen_enabled_bool']: command['setting_screen_enabled'] = 'on' log_lines = [] setting_keys = ['setting_screen_enabled', 'setting_max_distance', 'setting_max_altitude', 'setting_on_time', 'setting_off_time', 'setting_delay'] for key in setting_keys: if command.get(key) != configuration.get(key): log_lines.append(' |-->Setting %s updated from %s to %s' % ( key, str(configuration.get(key)), str(command[key]))) setting_change = True configuration[key] = command[key] if setting_change: settings_string = messageboard.BuildSettings(configuration) to_parent_q.put(('update_configuration', (settings_string, ))) # a command might request info about flight to be (re)displayed, irrespective of # whether the screen is on; if so, let's put that message at the front of the message # queue, and delete any subsequent messages in queue because presumably the button # was pushed either a) when the screen was off (so no messages in queue), or b) # because the screen was on, but the last flight details got lost after other screens! if command['last_plane']: to_parent_q.put(('replay', ())) log_lines.append(' |-->Requested last flight (re)display') # 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)) <----SKIPPED LINES----> def RemoteMain(to_arduino_q, to_parent_q, shutdown): """Main process for controlling the arduino-based remote control. Takes various data from the messageboard and formats it for display on the alphanumeric display on the remote control; provides latest configuration; and executes any commands such as histogram requests or setting updates. """ sys.stderr = open(messageboard.STDERR_FILE, 'a') Log('Process started with process id %d' % os.getpid()) # Ensures that the child can exit if the parent exits unexpectedly # docs.python.org/2/library/multiprocessing.html#multiprocessing.Queue.cancel_join_thread to_arduino_q.cancel_join_thread() to_parent_q.cancel_join_thread() #pylint: disable = bad-whitespace read_config = ( # when confirmed is true, this is a command; when false, this is a heartbeat ('confirmed', '?'), ('setting_screen_enabled', '?'), ('setting_max_distance', 'H'), ('setting_max_altitude', 'L'), ('setting_on_time', 'H'), ('setting_off_time', 'H'), ('setting_delay', 'H'), ('last_plane', '?'), ('display_mode', 'H'), ('histogram_enabled', '?'), ('current_hist_type', 'H'), ('current_hist_history', 'H'), ('low_battery', '?')) write_config = ( ('setting_screen_enabled', '?'), # 1 bytes ('setting_max_distance', 'H'), # 2 bytes ('setting_max_altitude', 'L'), # 4 bytes ('setting_on_time', 'H'), # 2 bytes ('setting_off_time', 'H'), # 2 bytes ('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 ('display_mode', '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() # 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: <----SKIPPED LINES----> |
01234567890123456789012345678901234567890123456789012345678901234567890123456789
917918919920921922923924925926927928929930931932933934935936 937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977 115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218 | <----SKIPPED LINES----> - (Re)display a recent flight - Display a histogram - Send information for a different display mode - Indicate that the battery is low Args: command: dictionary representing all data fields from remote. configuration: dictionary representing the current state of the messageboard configuration. display_mode: current display mode; only passed so that we may identify changes. low_battery: current battery status; only passed so that we may identify changes. to_parent_q: multiprocessing queue, where instructions to send back to messageboard, if any, can be placed. link: the open serial link. Returns: A 2-tuple of potentially-updated display_mode, and low_battery. """ # command might update a setting; see if there's a change, and if so, write to disk setting_change = False log_lines = [] setting_keys = ['setting_max_distance', 'setting_max_altitude', 'setting_on_time', 'setting_off_time', 'setting_delay'] for key in setting_keys: if command.get(key) != configuration.get(key): log_lines.append(' |-->Setting %s updated from %s to %s' % ( key, str(configuration.get(key)), str(command[key]))) setting_change = True configuration[key] = command[key] remote_key = 'setting_screen_enabled_bool' system_key = 'setting_screen_enabled' # remote sees T/F whereas messageboard.py & the web interface expect 'on'/absent key if command[remote_key] and system_key not in configuration: setting_change = True configuration[system_key] = 'on' log_lines.append(' |-->Setting %s updated from None to on' % system_key) elif not command[remote_key] and system_key in configuration: setting_change = True configuration.pop(system_key) log_lines.append(' |-->Setting %s updated from on to None' % system_key) if setting_change: settings_string = messageboard.BuildSettings(configuration) to_parent_q.put(('update_configuration', (settings_string, ))) # a command might request info about flight to be (re)displayed, irrespective of # whether the screen is on; if so, let's put that message at the front of the message # queue, and delete any subsequent messages in queue because presumably the button # was pushed either a) when the screen was off (so no messages in queue), or b) # because the screen was on, but the last flight details got lost after other screens! if command['last_plane']: to_parent_q.put(('replay', ())) log_lines.append(' |-->Requested last flight (re)display') # 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)) <----SKIPPED LINES----> def RemoteMain(to_arduino_q, to_parent_q, shutdown): """Main process for controlling the arduino-based remote control. Takes various data from the messageboard and formats it for display on the alphanumeric display on the remote control; provides latest configuration; and executes any commands such as histogram requests or setting updates. """ sys.stderr = open(messageboard.STDERR_FILE, 'a') Log('Process started with process id %d' % os.getpid()) # Ensures that the child can exit if the parent exits unexpectedly # docs.python.org/2/library/multiprocessing.html#multiprocessing.Queue.cancel_join_thread to_arduino_q.cancel_join_thread() to_parent_q.cancel_join_thread() #pylint: disable = bad-whitespace read_config = ( # when confirmed is true, this is a command; when false, this is a heartbeat ('confirmed', '?'), ('setting_screen_enabled_bool', '?'), ('setting_max_distance', 'H'), ('setting_max_altitude', 'L'), ('setting_on_time', 'H'), ('setting_off_time', 'H'), ('setting_delay', 'H'), ('last_plane', '?'), ('display_mode', 'H'), ('histogram_enabled', '?'), ('current_hist_type', 'H'), ('current_hist_history', 'H'), ('low_battery', '?')) write_config = ( ('setting_screen_enabled', '?'), # 1 bytes ('setting_max_distance', 'H'), # 2 bytes ('setting_max_altitude', 'L'), # 4 bytes ('setting_on_time', 'H'), # 2 bytes ('setting_off_time', 'H'), # 2 bytes ('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 ('display_mode', '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() # 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: <----SKIPPED LINES----> |