def test_drill(drill_id=39):
    # sets mode, params; starts drill; stops drill
    test_rc = True
    active = is_active()
    if (type(active) is not bool):
        return False
    if active:
        print("Base is already active")
        return False

    mode = {'mode': DRILL_MODE_E, 'id': drill_id}
    rc, code = send_msg(PUT_METHOD, MODE_RSRC, mode)
    if not rc:
        logging.error(
            "test_drill: initial PUT mode failed, code: {}".format(code))
        return False

    # start and check for active
    rc, code = send_msg(PUT_METHOD, STRT_RSRC)
    if not rc:
        logging.error("test_drill: PUT START failed, code: {}".format(code))
        return False
    active = is_active()
    if (type(active) is not bool):
        return False
    if not active:
        logging.error("Base didn't go active after start command")
        test_rc = False

    # stop and check for inactive
    rc, code = send_msg(PUT_METHOD, STOP_RSRC)
    if not rc:
        logging.error("test drill: PUT STOP failed, code: {}".format(code))
        return False
    active = is_active()
    if (type(active) is not bool):
        return False
    if active:
        logging.error("Base didn't go inactive after stop command")
        test_rc = False

    return test_rc
def test_register(register_under_test, patterns):
    test_pattern = {}
    read_back_compare = True
    msg_ok, register_original = send_msg(GET_METHOD, register_under_test)
    if not msg_ok:
        logging.error("GET {} failed.".format(register_under_test))
        return False
    #  if len(register_original) == 0:
    #      register_original = default_values
    logging.debug(f"register before test: {register_original}")

    for pattern in patterns:
        logging.debug(f"Setting {register_under_test} to: {pattern}")
        if send_msg(PUT_METHOD, register_under_test, pattern) == False:
            logging.error(f"PUT {register_under_test} failed")
            read_back_compare = False
            break
        msg_ok, reg_read_back = send_msg(GET_METHOD, register_under_test)
        if not msg_ok:
            logging.error(f"GET {register_under_test} failed.")
            read_back_compare = False
            break
        for key in pattern:
            if reg_read_back[key] != pattern[key]:
                logging.error(
                    f"{register_under_test}: read: {pattern} not equal to values written: {reg_read_back}"
                )
                read_back_compare = False
                break
        if not read_back_compare:
            break

    #restore
    if (send_msg(PUT_METHOD, register_under_test, register_original) == False):
        logging.error(f"restore {register_under_test} failed")
    logging.info(
        f"Register test done: {register_under_test} restored to: {register_original}"
    )
    return (read_back_compare)
Esempio n. 3
0
get list of faults from boomer_base
"""
import datetime
import logging
log_format = ('[%(asctime)s] %(levelname)-6s %(message)s')
logging.basicConfig(format=log_format, level=logging.INFO)
# logging.basicConfig(format=log_format, level=logging.DEBUG)

if __name__ == '__main__':
    from ctrl_messaging_routines import send_msg
    from control_ipc_defines import GET_METHOD, UI_TRANSPRT
    from control_ipc_defines import FLTS_RSRC, FLT_CODE_PARAM, FLT_LOCATION_PARAM, FLT_TIMESTAMP_PARAM
    from control_ipc_defines import fault_e, net_device_e
    import sys

    msg_ok, status = send_msg()
    if not msg_ok:
        print("Error getting status")
    else:
        if (status is not None) and ('hFault' in status) and (status['hFault']
                                                              == 0):
            print("No active faults")
        else:
            print(f"{status['hFault'] } active faults")

            msg_ok, faults = send_msg(GET_METHOD, FLTS_RSRC)
            if not msg_ok:
                print("Error getting status")
            else:
                # print(f"faults: {faults}")
                if len(faults) > 0:
def test_game(tie_breaker=False):
    # sets mode, params; starts game; stops game
    test_rc = True
    active = is_active()
    if (type(active) is not bool):
        return False
    if active:
        print("Base is already active")
        return False

    int_tiebreaker = int(tie_breaker == True)

    mode = {'mode': GAME_MODE_E, 'tie_breaker': int_tiebreaker}
    rc, code = send_msg(PUT_METHOD, MODE_RSRC, mode)
    if not rc:
        logging.error(
            "test_game: initial PUT mode failed, code: {}".format(code))
        return False

    # start and check for active
    rc, code = send_msg(PUT_METHOD, STRT_RSRC)
    if not rc:
        logging.error("test_game: PUT START failed, code: {}".format(code))
        return False
    active = is_active()
    if (type(active) is not bool):
        return False
    if not active:
        logging.error("Base didn't go active after start command")
        test_rc = False

    # stop and check for inactive
    rc, code = send_msg(PUT_METHOD, STOP_RSRC)
    if not rc:
        logging.error("test_game: PUT STOP failed, code: {}".format(code))
        return False
    active = is_active()
    if (type(active) is not bool):
        return False
    if active:
        logging.error("Base didn't go inactive after stop command")
        test_rc = False

    # check mode for doubles, tieb_break
    rc, register = send_msg(GET_METHOD, MODE_RSRC)
    if not rc:
        logging.error("test_game: final GET mode failed")
        return False
    if (register is not None):
        if register['mode'] != str(GAME_MODE_E):
            logging.error(
                "test_game: mode check failed, expected: {}, got {}:".format(
                    GAME_MODE_E, register['mode']))
            test_rc = False
        if (('tie_breaker' in register)
                and (register['tie_breaker'] != str(int_tiebreaker))):
            logging.error(
                "test_game: tiebreaker check failed, expected: {}, got {}:".
                format(int_tiebreaker, register['tie_breaker']))
            test_rc = False

    return test_rc
Esempio n. 5
0
                                                   LEVEL_MOD_MAX))
        sys.exit(1)

    active = is_active()
    if (type(active) is not bool):
        logging.error("GET Status failed")
        sys.exit(1)
    if active:
        logging.error("Base already active")
        sys.exit(1)


    mode = {MODE_PARAM: args.mode_setting, \
       ID_PARAM: args.drill_id_setting, \
       TIEBREAKER_PARAM: args.tiebreaker_setting}
    rc, code = send_msg(PUT_METHOD, MODE_RSRC, mode)
    if not rc:
        logging.error("PUT Mode failed, code: {}".format(code))
        sys.exit(1)

    params = {LEVEL_PARAM: args.level_setting, \
          SPEED_PARAM: args.speed_setting, \
          HEIGHT_PARAM: args.height_setting, \
          DELAY_PARAM: args.delay_setting}
    rc, code = send_msg(PUT_METHOD, OPTS_RSRC, params)
    if not rc:
        logging.error("PUT PARAMS failed, code: {}".format(code))
        sys.exit(1)

    # start and check for active
    rc, code = send_msg(PUT_METHOD, STRT_RSRC)
Esempio n. 6
0
def main(main_screen):
    not_up = "Not_running"
    screen = curses.initscr()
    # lines, columns, start line, start column
    my_window = curses.newwin(3, 48, 0, 0)
    refresh_count = 1
    while True:
        # init variables to something, for when they are accessed below
        mode = ''
        drill_worko_id = ''
        state = 'Error'
        fault_count = 0
        #get/parse status
        msg_ok, status_msg = send_msg()
        if not msg_ok:
            state = not_up
        else:
            if (status_msg is not None):
                if (STATUS_PARAM in status_msg):
                    state = base_state_e(status_msg[STATUS_PARAM]).name
                if (HARD_FAULT_PARAM in status_msg):
                    fault_count = int(status_msg[HARD_FAULT_PARAM])

            msg_ok, mode_reg = send_msg(GET_METHOD, MODE_RSRC)
            if not msg_ok:
                logging.error(f"GET Mode register failed.")
            else:
                if (mode_reg is not None) and (MODE_PARAM in mode_reg):
                    mode = base_mode_e(mode_reg[MODE_PARAM]).name
                    if (base_mode_e(
                            mode_reg[MODE_PARAM]) == base_mode_e.DRILL):
                        drill_worko_id = mode_reg[ID_PARAM]

        my_window.clear()  #clears warning from ctrl_messaging_routines
        my_window.addstr(0, 0, state)
        my_window.addstr(0, 14, f"{mode} {str(drill_worko_id)}")
        if (fault_count > 0):
            my_window.addstr(0, 30, f"Faults: {fault_count}")
        if state == not_up:
            my_window.addstr(1, 0, "Waiting for the base to be active...")
            my_window.addstr(2, 0, "  Type q to quit:")
        else:
            my_window.addstr(1, 0, "Command (d,g,w,t,e,q,?): ")
        my_window.refresh()
        my_window.timeout(2000)  #millisec
        c = my_window.getch()
        refresh_count += 1
        if c == ord('q'):
            break
        if c == ord('?'):
            my_window.addstr(1, 0,
                             "d=drill, g=game, w=workout, t=toggle_pause")
            my_window.addstr(2, 8, "e=end game/drill/wo, q=quit")
            my_window.refresh()
            curses.napms(3000)
        if c == ord('g'):
            start_boomer()
        if c == ord('d'):
            # window.clrtoeol()
            my_window.clear()
            my_window.addstr(1, 0, "Enter drill number: ")
            curses.echo()
            my_window.refresh()
            my_window.timeout(-1)
            entry = my_window.getstr().decode(encoding="utf-8")
            curses.noecho()
            start_boomer(mode=base_mode_e.DRILL.value, id=entry)
        if c == ord('w'):
            my_window.clear()
            my_window.addstr(1, 0, "Enter workout number: ")
            curses.echo()
            my_window.refresh()
            my_window.timeout(-1)
            entry = my_window.getstr().decode(encoding="utf-8")
            curses.noecho()
            start_boomer(mode=base_mode_e.WORKOUT.value, id=entry)
        if c == ord('t'):
            rc, code = send_msg(PUT_METHOD, PAUS_RSRC)
        if c == ord('e'):
            rc, code = send_msg(PUT_METHOD, STOP_RSRC)

    curses.endwin()
Esempio n. 7
0
def start_boomer(mode=base_mode_e.GAME.value, id=0):
    rc, code = send_msg(PUT_METHOD, STOP_RSRC)
    mode_reg = {MODE_PARAM: mode, ID_PARAM: id}
    rc, code = send_msg(PUT_METHOD, MODE_RSRC, mode_reg)
    rc, code = send_msg(PUT_METHOD, STRT_RSRC)