hitl_tester.modules.cyber_6t.led
Controls the USB stack lights
(c) 2020-2024 TurnAround Factor, Inc.
#
CUI DISTRIBUTION CONTROL
Controlled by: DLA J68 R&D SBIP
CUI Category: Small Business Research and Technology
Distribution/Dissemination Controls: PROTECTED BY SBIR DATA RIGHTS
POC: GOV SBIP Program Manager Denise Price, 571-767-0111
Distribution authorized to U.S. Government Agencies only, to protect information not owned by the
U.S. Government and protected by a contractor’s ‘limited rights’ statement, or received with the understanding that
it is not routinely transmitted outside the U.S. Government (determination made September 14, 2024). Other requests
for this document shall be referred to ACOR DLA Logistics Operations (J-68), 8725 John J. Kingman Rd., Suite 4317,
Fort Belvoir, VA 22060-6221
#
SBIR DATA RIGHTS
Contract No.:SP4701-23-C-0083
Contractor Name: TurnAround Factor, Inc.
Contractor Address: 10365 Wood Park Ct. Suite 313 / Ashland, VA 23005
Expiration of SBIR Data Rights Period: September 24, 2029
The Government's rights to use, modify, reproduce, release, perform, display, or disclose technical data or computer
software marked with this legend are restricted during the period shown as provided in paragraph (b)(4) of the Rights
in Noncommercial Technical Data and Computer Software--Small Business Innovative Research (SBIR) Program clause
contained in the above identified contract. No restrictions apply after the expiration date shown above. Any
reproduction of technical data, computer software, or portions thereof marked with this legend must also reproduce
the markings.
1""" 2Controls the USB stack lights 3 4# (c) 2020-2024 TurnAround Factor, Inc. 5# 6# CUI DISTRIBUTION CONTROL 7# Controlled by: DLA J68 R&D SBIP 8# CUI Category: Small Business Research and Technology 9# Distribution/Dissemination Controls: PROTECTED BY SBIR DATA RIGHTS 10# POC: GOV SBIP Program Manager Denise Price, 571-767-0111 11# Distribution authorized to U.S. Government Agencies only, to protect information not owned by the 12# U.S. Government and protected by a contractor’s ‘limited rights’ statement, or received with the understanding that 13# it is not routinely transmitted outside the U.S. Government (determination made September 14, 2024). Other requests 14# for this document shall be referred to ACOR DLA Logistics Operations (J-68), 8725 John J. Kingman Rd., Suite 4317, 15# Fort Belvoir, VA 22060-6221 16# 17# SBIR DATA RIGHTS 18# Contract No.:SP4701-23-C-0083 19# Contractor Name: TurnAround Factor, Inc. 20# Contractor Address: 10365 Wood Park Ct. Suite 313 / Ashland, VA 23005 21# Expiration of SBIR Data Rights Period: September 24, 2029 22# The Government's rights to use, modify, reproduce, release, perform, display, or disclose technical data or computer 23# software marked with this legend are restricted during the period shown as provided in paragraph (b)(4) of the Rights 24# in Noncommercial Technical Data and Computer Software--Small Business Innovative Research (SBIR) Program clause 25# contained in the above identified contract. No restrictions apply after the expiration date shown above. Any 26# reproduction of technical data, computer software, or portions thereof marked with this legend must also reproduce 27# the markings. 28""" 29 30import sys 31 32import serial 33from serial.serialutil import SerialException 34 35RED = "red" 36YELLOW = "yellow" 37GREEN = "green" 38ON = "on" 39OFF = "off" 40LED = { 41 GREEN: {ON: b"\xA0\x02\x01\xA3", OFF: b"\xA0\x02\x00\xA2"}, 42 YELLOW: {ON: b"\xA0\x03\x01\xA4", OFF: b"\xA0\x03\x00\xA3"}, 43 RED: {ON: b"\xA0\x01\x01\xA2", OFF: b"\xA0\x01\x00\xA1"}, 44 OFF: {ON: bytes()}, 45} 46 47 48class LEDController: 49 """LED controller""" 50 51 @staticmethod 52 def set_color(clr: bytes, c: str, r: bool = False): 53 """Sets the color""" 54 if not clr: 55 raise ValueError("Color not found") 56 57 try: 58 # 9600,8,N,1 59 with serial.Serial("/dev/taf-led", timeout=1) as ser: 60 ser.write(clr) 61 s = "reset" if r else "set" 62 if len(ser.read(4)) == 0: 63 raise TimeoutError(f"Unable to {s} color {c}") 64 if not r: 65 print(f"Successfully {s} color {c}") 66 except (ValueError, TimeoutError) as ex: 67 print(ex) 68 except (FileNotFoundError, SerialException): 69 pass 70 71 @staticmethod 72 def reset(): 73 """Resets LEDs to off state""" 74 LEDController.set_color(LED[GREEN][OFF], "green", True) 75 LEDController.set_color(LED[YELLOW][OFF], "yellow", True) 76 LEDController.set_color(LED[RED][OFF], "red", True) 77 78 79def main(): 80 """Set the LED color.""" 81 LEDController.reset() 82 83 color = sys.argv[1] 84 if color != OFF: 85 LEDController.set_color(LED[color][ON], color) 86 87 88if __name__ == "__main__": 89 main()
RED =
'red'
YELLOW =
'yellow'
GREEN =
'green'
ON =
'on'
OFF =
'off'
LED =
{'green': {'on': b'\xa0\x02\x01\xa3', 'off': b'\xa0\x02\x00\xa2'}, 'yellow': {'on': b'\xa0\x03\x01\xa4', 'off': b'\xa0\x03\x00\xa3'}, 'red': {'on': b'\xa0\x01\x01\xa2', 'off': b'\xa0\x01\x00\xa1'}, 'off': {'on': b''}}
class
LEDController:
49class LEDController: 50 """LED controller""" 51 52 @staticmethod 53 def set_color(clr: bytes, c: str, r: bool = False): 54 """Sets the color""" 55 if not clr: 56 raise ValueError("Color not found") 57 58 try: 59 # 9600,8,N,1 60 with serial.Serial("/dev/taf-led", timeout=1) as ser: 61 ser.write(clr) 62 s = "reset" if r else "set" 63 if len(ser.read(4)) == 0: 64 raise TimeoutError(f"Unable to {s} color {c}") 65 if not r: 66 print(f"Successfully {s} color {c}") 67 except (ValueError, TimeoutError) as ex: 68 print(ex) 69 except (FileNotFoundError, SerialException): 70 pass 71 72 @staticmethod 73 def reset(): 74 """Resets LEDs to off state""" 75 LEDController.set_color(LED[GREEN][OFF], "green", True) 76 LEDController.set_color(LED[YELLOW][OFF], "yellow", True) 77 LEDController.set_color(LED[RED][OFF], "red", True)
LED controller
@staticmethod
def
set_color(clr: bytes, c: str, r: bool = False):
52 @staticmethod 53 def set_color(clr: bytes, c: str, r: bool = False): 54 """Sets the color""" 55 if not clr: 56 raise ValueError("Color not found") 57 58 try: 59 # 9600,8,N,1 60 with serial.Serial("/dev/taf-led", timeout=1) as ser: 61 ser.write(clr) 62 s = "reset" if r else "set" 63 if len(ser.read(4)) == 0: 64 raise TimeoutError(f"Unable to {s} color {c}") 65 if not r: 66 print(f"Successfully {s} color {c}") 67 except (ValueError, TimeoutError) as ex: 68 print(ex) 69 except (FileNotFoundError, SerialException): 70 pass
Sets the color
def
main():
80def main(): 81 """Set the LED color.""" 82 LEDController.reset() 83 84 color = sys.argv[1] 85 if color != OFF: 86 LEDController.set_color(LED[color][ON], color)
Set the LED color.