01234567890123456789012345678901234567890123456789012345678901234567890123456789
414243444546474849505152535455565758596061 6263646566676869707172737475767778798081 631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710 711712713714715716717718719720721722723724725726727728729730731732733734735736737738 |
<----SKIPPED LINES---->
REMOTE_SIMULATED_OUT = MESSAGEBOARD_PATH + REMOTE_SIMULATED_OUT
REMOTE_SIMULATED_IN = MESSAGEBOARD_PATH + REMOTE_SIMULATED_IN
REMOTE_DISPLAY_MODE = MESSAGEBOARD_PATH + REMOTE_DISPLAY_MODE
ARDUINO_ROLLING_LOG = WEBSERVER_PATH + ARDUINO_ROLLING_LOG
CONNECTION_FLAG_BLUETOOTH = 1
CONNECTION_FLAG_USB = 2
CONNECTION_FLAG_SIMULATED = 3
RASPBERRY_PI = psutil.sys.platform.title() == 'Linux'
SN_SERVO = '5583834303435111C1A0'
SERVO_CONNECTION = (CONNECTION_FLAG_BLUETOOTH, (2, '98:D3:11:FC:42:16', 1)) # with MOSFET
#SERVO_CONNECTION = (CONNECTION_FLAG_BLUETOOTH, (3, '98:D3:91:FD:B1:8F', 1)) # no MOSFET
SN_REMOTE = '75835343130351802272'
# directly connected to Serial2
# connected thru MOSFET to Serial1
REMOTE_CONNECTION = (CONNECTION_FLAG_BLUETOOTH, (1, '98:D3:91:FD:B3:C9', 1))
MIN_ALTITUDE = 5 # below this elevation degrees, turn off the tracking
if SIMULATE_ARDUINO:
SERVO_CONNECTION = (CONNECTION_FLAG_SIMULATED, (SERVO_SIMULATED_IN, SERVO_SIMULATED_OUT))
REMOTE_CONNECTION = (
CONNECTION_FLAG_SIMULATED, (REMOTE_SIMULATED_IN, REMOTE_SIMULATED_OUT))
KEY_NOT_PRESENT_STRING = 'N/A'
DISP_LAST_FLIGHT_NUMB_ORIG_DEST = 0
DISP_LAST_FLIGHT_AZIMUTH_ELEVATION = 1
DISP_FLIGHT_COUNT_LAST_SEEN = 2
DISP_RADIO_RANGE = 3
DISPLAY_MODE_NAMES = [
'LAST_FLIGHT_NUMB_ORIG_DEST', 'LAST_FLIGHT_AZIMUTH_ELEVATION',
'FLIGHT_COUNT_LAST_SEEN', 'RADIO_RANGE']
WRITE_DELAY_TIME = 0.2 # write to arduino every n seconds
READ_DELAY_TIME = 0.1 # read from arduino every n seconds
HISTOGRAM_TYPES = (
<----SKIPPED LINES---->
read_format='l', write_format='ff???', name='Servo')
link.Open()
last_flight = {}
last_angles = (0, 0)
flight, json_desc_dict, configuration, additional_attr = InitialMessageValues(
to_arduino_q)
next_read = 0
next_write = 0
now = GetNow(json_desc_dict, additional_attr)
while not shutdown.value:
if not to_arduino_q.empty():
flight, json_desc_dict, configuration, additional_attr = to_arduino_q.get(
block=False)
if 'test_servos' in configuration:
messageboard.RemoveSetting(configuration, 'test_servos')
link.Write((0, 0, *LASER_RGB_OFF))
time.sleep(1)
link.Write((90, 0, *LASER_RGB_OFF))
time.sleep(1)
link.Write((180, 0, *LASER_RGB_OFF))
time.sleep(1)
link.Write((270, 0, *LASER_RGB_OFF))
time.sleep(1)
new_flight = DifferentFlights(flight, last_flight)
if new_flight:
Log('Flight changed from %s to %s' % (
messageboard.DisplayFlightNumber(last_flight),
messageboard.DisplayFlightNumber(flight)
), ser=link)
# Turn off laser so that line isn't traced while it moves to new position
link.Write((*last_angles, *LASER_RGB_OFF))
last_flight = flight
if time.time() >= next_read:
heartbeat = link.Read() # simple ack message sent by servos
next_read = time.time() + READ_DELAY_TIME
if heartbeat and VERBOSE:
Log(heartbeat)
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']:
if VERBOSE:
Log('Flight #: %s current_angles: %s' % (
messageboard.DisplayFlightNumber(flight), str(current_angles)))
laser_rgb = LaserRGBFlight(flight)
link.Write((*current_angles, *laser_rgb))
last_angles = current_angles
else:
link.Write((*last_angles, *LASER_RGB_OFF))
next_write = time.time() + WRITE_DELAY_TIME
link.Close(SHUTDOWN_TEXT)
LASER_RGB_OFF = (0, 0, 0)
def LaserRGBFlight(flight):
"""Based on flight attributes, set the laser."""
# Possible assignment based on:
# - ascending / descending / level
# - to SFO / from SFO / other
# - big plane / med plane / small plane
# - low alt / med alt / high alt
# - low speed / med speed / high speed
# - rare destination / common destination
red = False
green = False
blue = False
aircraft_length = AircraftLength(flight)
if AircraftLength(flight) > 50:
red = True
elif AircraftLength(flight) > 30:
green = True
else:
blue = True
return red, green, blue
def DifferentFlights(f1, f2):
"""True if both squawk and flight number different; false otherwise."""
if f1 is None and f2 is None:
return True
if f1 is None or f2 is None:
return True
if (
f1.get('flight_number') != f2.get('flight_number')
and f1.get('squawk') != f2.get('squawk')):
return True
return False
def FloatToAlphanumericStr(x, decimals, total_length, sign=True):
"""Formats a float as a string without a decimal point.
Since the decimal point is controlled independently on the alphanumeric display,
<----SKIPPED LINES---->
|
01234567890123456789012345678901234567890123456789012345678901234567890123456789
414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699 700701702703704705706707708 709710711712713714715 716717718719720721722723724725726727728729730731732733734735 |
<----SKIPPED LINES---->
REMOTE_SIMULATED_OUT = MESSAGEBOARD_PATH + REMOTE_SIMULATED_OUT
REMOTE_SIMULATED_IN = MESSAGEBOARD_PATH + REMOTE_SIMULATED_IN
REMOTE_DISPLAY_MODE = MESSAGEBOARD_PATH + REMOTE_DISPLAY_MODE
ARDUINO_ROLLING_LOG = WEBSERVER_PATH + ARDUINO_ROLLING_LOG
CONNECTION_FLAG_BLUETOOTH = 1
CONNECTION_FLAG_USB = 2
CONNECTION_FLAG_SIMULATED = 3
RASPBERRY_PI = psutil.sys.platform.title() == 'Linux'
SN_SERVO = '5583834303435111C1A0'
SERVO_CONNECTION = (CONNECTION_FLAG_BLUETOOTH, (2, '98:D3:11:FC:42:16', 1)) # with MOSFET
#SERVO_CONNECTION = (CONNECTION_FLAG_BLUETOOTH, (3, '98:D3:91:FD:B1:8F', 1)) # no MOSFET
SN_REMOTE = '75835343130351802272'
# directly connected to Serial2
# connected thru MOSFET to Serial1
REMOTE_CONNECTION = (CONNECTION_FLAG_BLUETOOTH, (1, '98:D3:91:FD:B3:C9', 1))
LASER_RGB_OFF = (False, False, False)
LASER_RED = (True, False, False)
LASER_GREEN = (False, True, False)
LASER_BLUE = (False, False, False)
if SIMULATE_ARDUINO:
SERVO_CONNECTION = (CONNECTION_FLAG_SIMULATED, (SERVO_SIMULATED_IN, SERVO_SIMULATED_OUT))
REMOTE_CONNECTION = (
CONNECTION_FLAG_SIMULATED, (REMOTE_SIMULATED_IN, REMOTE_SIMULATED_OUT))
KEY_NOT_PRESENT_STRING = 'N/A'
DISP_LAST_FLIGHT_NUMB_ORIG_DEST = 0
DISP_LAST_FLIGHT_AZIMUTH_ELEVATION = 1
DISP_FLIGHT_COUNT_LAST_SEEN = 2
DISP_RADIO_RANGE = 3
DISPLAY_MODE_NAMES = [
'LAST_FLIGHT_NUMB_ORIG_DEST', 'LAST_FLIGHT_AZIMUTH_ELEVATION',
'FLIGHT_COUNT_LAST_SEEN', 'RADIO_RANGE']
WRITE_DELAY_TIME = 0.2 # write to arduino every n seconds
READ_DELAY_TIME = 0.1 # read from arduino every n seconds
HISTOGRAM_TYPES = (
<----SKIPPED LINES---->
read_format='l', write_format='ff???', name='Servo')
link.Open()
last_flight = {}
last_angles = (0, 0)
flight, json_desc_dict, configuration, additional_attr = InitialMessageValues(
to_arduino_q)
next_read = 0
next_write = 0
now = GetNow(json_desc_dict, additional_attr)
while not shutdown.value:
if not to_arduino_q.empty():
flight, json_desc_dict, configuration, additional_attr = to_arduino_q.get(
block=False)
if 'test_servos' in configuration:
messageboard.RemoveSetting(configuration, 'test_servos')
link.Write((0, 0, *LASER_RGB_OFF))
time.sleep(1)
link.Write((90, 0, *LASER_RED))
time.sleep(1)
link.Write((180, 0, *LASER_GREEN))
time.sleep(1)
link.Write((270, 0, *LASER_BLUE))
time.sleep(1)
new_flight = DifferentFlights(flight, last_flight)
if new_flight:
Log('Flight changed from %s to %s' % (
messageboard.DisplayFlightNumber(last_flight),
messageboard.DisplayFlightNumber(flight)
), ser=link)
# Turn off laser so that line isn't traced while it moves to new position
link.Write((*last_angles, *LASER_RGB_OFF))
last_flight = flight
if time.time() >= next_read:
heartbeat = link.Read() # simple ack message sent by servos
next_read = time.time() + READ_DELAY_TIME
if heartbeat and VERBOSE:
Log(heartbeat)
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']:
if VERBOSE:
Log('Flight #: %s current_angles: %s' % (
messageboard.DisplayFlightNumber(flight), str(current_angles)))
laser_rgb = LaserRGBFlight(flight)
link.Write((*current_angles, *laser_rgb))
last_angles = current_angles
else:
link.Write((*last_angles, *LASER_RGB_OFF))
next_write = time.time() + WRITE_DELAY_TIME
link.Close(SHUTDOWN_TEXT)
def LaserRGBFlight(flight):
"""Based on flight attributes, set the laser."""
# Possible assignment based on:
# - ascending / descending / level
# - to SFO / from SFO / other
# - big plane / med plane / small plane
# - low alt / med alt / high alt
# - low speed / med speed / high speed
# - rare destination / common destination
aircraft_length = messageboard.AircraftLength(flight)
if aircraft_length > 50:
return LASER_RED
if aircraft_length > 30:
return LASER_GREEN
return LASER_BLUE
def DifferentFlights(f1, f2):
"""True if both squawk and flight number different; false otherwise."""
if f1 is None and f2 is None:
return True
if f1 is None or f2 is None:
return True
if (
f1.get('flight_number') != f2.get('flight_number')
and f1.get('squawk') != f2.get('squawk')):
return True
return False
def FloatToAlphanumericStr(x, decimals, total_length, sign=True):
"""Formats a float as a string without a decimal point.
Since the decimal point is controlled independently on the alphanumeric display,
<----SKIPPED LINES---->
|