|
| 1 | +"""Test Connectivity.""" |
| 2 | +from typing import List, Union |
| 3 | + |
| 4 | +from hardware_testing.data import ui |
| 5 | +from hardware_testing.data.csv_report import ( |
| 6 | + CSVReport, |
| 7 | + CSVLine, |
| 8 | + CSVLineRepeating, |
| 9 | + CSVResult, |
| 10 | +) |
| 11 | + |
| 12 | +from .driver import FlexStacker, HardwareRevision |
| 13 | + |
| 14 | + |
| 15 | +def build_csv_lines() -> List[Union[CSVLine, CSVLineRepeating]]: |
| 16 | + """Build CSV Lines.""" |
| 17 | + return [ |
| 18 | + CSVLine("usb-get-device-info", [str, str, str, CSVResult]), |
| 19 | + CSVLine("eeprom-set-serial-number", [str, str, CSVResult]), |
| 20 | + CSVLine("led-blinking", [bool, CSVResult]), |
| 21 | + ] |
| 22 | + |
| 23 | + |
| 24 | +def test_gcode(driver: FlexStacker, report: CSVReport) -> None: |
| 25 | + """Send and receive response for GCODE M115.""" |
| 26 | + success = True |
| 27 | + info = driver.get_device_info() |
| 28 | + print("Hardware Revision: ", info.hw, "\n") |
| 29 | + if info is None or info.hw != HardwareRevision.EVT: |
| 30 | + print("Hardware Revision must be EVT") |
| 31 | + success = False |
| 32 | + report( |
| 33 | + "CONNECTIVITY", |
| 34 | + "usb-get-device-info", |
| 35 | + [info.fw, info.hw, info.sn, CSVResult.from_bool(success)], |
| 36 | + ) |
| 37 | + |
| 38 | + |
| 39 | +def test_eeprom(driver: FlexStacker, report: CSVReport) -> None: |
| 40 | + """Set serial number and make sure device info is updated accordingly.""" |
| 41 | + success = True |
| 42 | + if not driver._simulating: |
| 43 | + serial = input("enter Serial Number: ") |
| 44 | + else: |
| 45 | + serial = "STACKER-SIMULATOR-SN" |
| 46 | + driver.set_serial_number(serial) |
| 47 | + info = driver.get_device_info() |
| 48 | + if info.sn != serial: |
| 49 | + print("Serial number is not set properly") |
| 50 | + success = False |
| 51 | + report( |
| 52 | + "CONNECTIVITY", |
| 53 | + "eeprom-set-serial-number", |
| 54 | + [serial, info.sn, CSVResult.from_bool(success)], |
| 55 | + ) |
| 56 | + |
| 57 | + |
| 58 | +def test_leds(driver: FlexStacker, report: CSVReport) -> None: |
| 59 | + """Prompt tester to verify the status led is blinking.""" |
| 60 | + if not driver._simulating: |
| 61 | + is_blinking = ui.get_user_answer("Is the status LED blinking?") |
| 62 | + else: |
| 63 | + is_blinking = True |
| 64 | + report( |
| 65 | + "CONNECTIVITY", "led-blinking", [is_blinking, CSVResult.from_bool(is_blinking)] |
| 66 | + ) |
| 67 | + |
| 68 | + |
| 69 | +def run(driver: FlexStacker, report: CSVReport, section: str) -> None: |
| 70 | + """Run.""" |
| 71 | + ui.print_header("USB Communication") |
| 72 | + test_gcode(driver, report) |
| 73 | + |
| 74 | + ui.print_header("EEPROM Communication") |
| 75 | + test_eeprom(driver, report) |
| 76 | + |
| 77 | + ui.print_header("LED Blinking") |
| 78 | + test_leds(driver, report) |
0 commit comments