01234567890123456789012345678901234567890123456789012345678901234567890123456789
54515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476 54775478 5479548054815482548354845485548654875488548954905491549254935494549554965497549854995500 56625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702 |
<----SKIPPED LINES---->
Args:
q: multiprocessing queue provided to both the Arduino processes
flights: list of flights
configuration: dictionary of settings
message_queue: current message queue
next_message_time: epoch of the next message to display to screen
Returns:
A 2-tuple of the (possibly-updated) message_queue and next_message_time.
"""
while not q.empty():
command, args = q.get()
if command == 'pin':
UpdateStatusLight(*args)
elif command == 'replay':
# 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
# that we're no longer interested in
messageboard_flight_index = IdentifyFlightDisplayed(
flights, configuration, display_all_hours=True)
if messageboard_flight_index is not None:
message_queue = DeleteMessageTypes(message_queue, (FLAG_MSG_INSIGHT, ))
flight_message = CreateMessageAboutFlight(flights[messageboard_flight_index])
message_queue.insert(0, (FLAG_MSG_FLIGHT, flight_message))
next_message_time = time.time()
elif command == 'histogram':
if not flights:
Log('Histogram requested by remote %s but no flights in memory' % str(args))
else:
histogram_type, histogram_history = args
message_queue.extend(MessageboardHistograms(
flights,
histogram_type,
histogram_history,
'_1',
False))
elif command == 'update_configuration':
updated_settings = args[0]
Log('Updated settings received from arduino: %s' % updated_settings)
WriteFile(CONFIG_FILE, updated_settings)
else:
<----SKIPPED LINES---->
Returns:
Next_message_time, potentially updated if a message has been displayed, or unchanged
if no message was displayed.
"""
if message_queue and (time.time() >= next_message_time or SIMULATION):
if SIMULATION: # drain the queue because the messages come so fast
messages_to_display = list(message_queue)
# passed by reference, so clear it out since we drained it to the display
del message_queue[:]
else: # display only one message, being mindful of the display timing
messages_to_display = [message_queue.pop(0)]
for message in messages_to_display:
message_text = message[1]
if isinstance(message_text, str):
message_text = textwrap.wrap(message_text, width=SPLITFLAP_CHARS_PER_LINE)
display_message = Screenify(message_text, False)
Log(display_message, file=ALL_MESSAGE_FILE)
# This allows us to identify whats currently on the screen
PickleObjectToFile(message, PICKLE_SCREENS, True)
MaintainRollingWebLog(display_message, 25)
if not SIMULATION:
splitflap_message = Screenify(message_text, True)
PublishMessage(splitflap_message)
next_message_time = time.time() + configuration['setting_delay']
return next_message_time
def DeleteMessageTypes(q, types_to_delete):
"""Delete messages from the queue if type is in the iterable types."""
if VERBOSE:
messages_to_delete = [m for m in q if m[0] in types_to_delete]
if messages_to_delete:
Log('Deleting messages from queue due to new-found plane: %s' % messages_to_delete)
updated_q = [m for m in q if m[0] not in types_to_delete]
return updated_q
<----SKIPPED LINES---->
|
01234567890123456789012345678901234567890123456789012345678901234567890123456789
545154525453545454555456545754585459546054615462546354645465546654675468546954705471 5472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499 56615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701 |
<----SKIPPED LINES---->
Args:
q: multiprocessing queue provided to both the Arduino processes
flights: list of flights
configuration: dictionary of settings
message_queue: current message queue
next_message_time: epoch of the next message to display to screen
Returns:
A 2-tuple of the (possibly-updated) message_queue and next_message_time.
"""
while not q.empty():
command, args = q.get()
if command == 'pin':
UpdateStatusLight(*args)
elif command == 'replay':
# 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 insight messages in queue
replayed_flight_index = IdentifyFlightDisplayed(
flights, configuration, display_all_hours=True)
Log('Replay requested; re-displaying flight index %s' % str(replayed_flight_index)) #TODO - change to flight number once working
if replayed_flight_index is not None:
message_queue = DeleteMessageTypes(message_queue, (FLAG_MSG_INSIGHT, ))
replayed_flight = flights[replayed_flight_index]
flight_message = CreateMessageAboutFlight(replayed_flight)
message_queue.insert(0, (FLAG_MSG_FLIGHT, flight_message, replayed_flight))
next_message_time = time.time()
elif command == 'histogram':
if not flights:
Log('Histogram requested by remote %s but no flights in memory' % str(args))
else:
histogram_type, histogram_history = args
message_queue.extend(MessageboardHistograms(
flights,
histogram_type,
histogram_history,
'_1',
False))
elif command == 'update_configuration':
updated_settings = args[0]
Log('Updated settings received from arduino: %s' % updated_settings)
WriteFile(CONFIG_FILE, updated_settings)
else:
<----SKIPPED LINES---->
Returns:
Next_message_time, potentially updated if a message has been displayed, or unchanged
if no message was displayed.
"""
if message_queue and (time.time() >= next_message_time or SIMULATION):
if SIMULATION: # drain the queue because the messages come so fast
messages_to_display = list(message_queue)
# passed by reference, so clear it out since we drained it to the display
del message_queue[:]
else: # display only one message, being mindful of the display timing
messages_to_display = [message_queue.pop(0)]
for message in messages_to_display:
message_text = message[1]
if isinstance(message_text, str):
message_text = textwrap.wrap(message_text, width=SPLITFLAP_CHARS_PER_LINE)
display_message = Screenify(message_text, False)
Log(display_message, file=ALL_MESSAGE_FILE)
# Saving this to disk allows us to identify persistently whats currently on the screen
PickleObjectToFile(message, PICKLE_SCREENS, True)
MaintainRollingWebLog(display_message, 25)
if not SIMULATION:
splitflap_message = Screenify(message_text, True)
PublishMessage(splitflap_message)
next_message_time = time.time() + configuration['setting_delay']
return next_message_time
def DeleteMessageTypes(q, types_to_delete):
"""Delete messages from the queue if type is in the iterable types."""
if VERBOSE:
messages_to_delete = [m for m in q if m[0] in types_to_delete]
if messages_to_delete:
Log('Deleting messages from queue due to new-found plane: %s' % messages_to_delete)
updated_q = [m for m in q if m[0] not in types_to_delete]
return updated_q
<----SKIPPED LINES---->
|