コード例 #1
0
ファイル: state.py プロジェクト: spel-uchile/SUCHAIportings
    def on_reset():
        gnrl_services.console_print("      [on_reset]")
        gnrl_services.console_print("        Updating state vars ..")

        #--------------------
        # ppc_resetCounter
        # read
        val = data.PersistenMem.read_state_var(StateVar.ppc_resetCounter.name)
        # write new val
        val = int(val)
        val += 1
        data.PersistenMem.write_state_var(StateVar.ppc_resetCounter.name, val)
        #check
        val = data.PersistenMem.read_state_var(StateVar.ppc_resetCounter.name)
        if val == 1:
            gnrl_services.console_print(
                "          First time on, ppc_resetCounter = %s" % val)
        else:
            gnrl_services.console_print("          ppc_resetCounter = %s" %
                                        val)
        #--------------------
        # state_var_x
        #--------------------
        # state_var_y
        #--------------------

        verbose = False
        if verbose:
            for j in range(0, len(StateVar)):
                arg = "          %s(%s) => %s" % (StateVar.__name__, j,
                                                  StateVar(j))
                gnrl_services.console_print(arg)
                logger.debug(arg)
コード例 #2
0
def init_suchai_repos():
    arg = "  [init_suchai_repo]"
    logger.debug(arg)
    gnrl_services.console_print(arg)
    # /* Repositories */
    init_state_repo()       # modify specific reset-dependant STA_StateVar vars
    init_command_repo()     # loads cmdXXX repos to be used
    init_data_repo()        # prepares permanent memory to be used by bus and paylaods
コード例 #3
0
def init_data_repo():
    # prepares permanent memory to be used by bus and paylaods

    arg = "    [init_data_repo]"
    logger.debug(arg)
    gnrl_services.console_print(arg)

    data.init()
コード例 #4
0
def init_state_repo():
    # modify specific reset-dependant STA_StateVar vars

    arg = "    [init_state_repo]"
    logger.debug(arg)
    gnrl_services.console_print(arg)

    state.StateVar.on_reset()
コード例 #5
0
 def take_photo(param):
     name = str(datetime.datetime.now())
     gnrl_services.console_print("cmdName %s" % name)
     camera.RaspiCamIf.init()
     camera.RaspiCamIf.take_picture(SUCHAI_config.SCH_DATA_FOLDER + name)
     camera.RaspiCamIf.stop()
     gnrl_services.console_print("done")
     return True
コード例 #6
0
def listener_console(fileno):
    sys.stdin = os.fdopen(fileno)  # open stdin in this process
    verbose = False
    if verbose:
        gnrl_services.console_print("main stdin %s" % sys.stdin)
        gnrl_services.console_print("main stdout %s" % sys.stdout)

    arg = "cmdName %s, pid %s, is_alive %s, exitcode %s" %\
          (listenerHandler.name, listenerHandler.pid, listenerHandler.is_alive(), listenerHandler.exitcode)
    logger.debug(arg)

    while True:
        # time.sleep(0.1)  # give time for short commands ( < 0.1 seg) to execute, before the promt

        # /* Parsing command - return CmdDisp structure*/
        new_disp_cmd = con_cmd_handler()

        # /* cmdId = 0xFFFF means no new command */
        if new_disp_cmd.cmdId != command.CmdRepo.cmdnull.cmdId:
            # /* Print the command code */
            gnrl_services.console_print(
                "  con_cmd_handler spawns command 0x%0.4X %s" %
                (new_disp_cmd.cmdId, new_disp_cmd.cmdParam))

            # /* Queue NewCmd - Blocking */
            #send cmd to Dispatcher (blocking call)
            disp_cmd = dispatcherhandler.DispCmd(
                cmdid=new_disp_cmd.cmdId,
                cmdparam=new_disp_cmd.cmdParam,
                taskorigid=new_disp_cmd.taskorigId)
            disp_cmd.send_to_dispatcher()  # blocking by default
        else:
            gnrl_services.console_print(
                "  con_cmd_handler error. No command was spawn")
コード例 #7
0
def launch_listeners():
    arg = "[launch_listeners]"
    logger.debug(arg)
    gnrl_services.console_print(arg)

    handler = dispatcher.listenerHandler
    arg = "%s, %s, %s, %s" % (handler.name, handler.pid, handler.is_alive(), handler.exitcode)
    logger.debug(arg)
    handler = comunications.listenerHandler
    arg = "%s, %s, %s, %s" % (handler.name, handler.pid, handler.is_alive(), handler.exitcode)
    logger.debug(arg)
    handler = console.listenerHandler
    arg = "%s, %s, %s, %s" % (handler.name, handler.pid, handler.is_alive(), handler.exitcode)
    logger.debug(arg)
    handler = flightplan.listenerHandler
    arg = "%s, %s, %s, %s" % (handler.name, handler.pid, handler.is_alive(), handler.exitcode)
    logger.debug(arg)
    handler = housekeeping.listenerHandler
    arg = "%s, %s, %s, %s" % (handler.name, handler.pid, handler.is_alive(), handler.exitcode)
    logger.debug(arg)

    # time.sleep(2)
    logger.info("Starting nominal operations ..")

    dispatcher.listenerHandler.start()
    comunications.listenerHandler.start()
    console.listenerHandler.start()
    flightplan.listenerHandler.start()
    housekeeping.listenerHandler.start()

    # time.sleep(2)   # give time for every process to start
    # logger.debug("-------------------------")

    dispatcher.listenerHandler.join()
    comunications.listenerHandler.join()
    console.listenerHandler.join()
    flightplan.listenerHandler.join()
    housekeeping.listenerHandler.join()
コード例 #8
0
def init_command_repo():
    # loads cmdXXX repos to be used

    arg = "    [init_command_repo]"
    logger.debug(arg)
    gnrl_services.console_print(arg)

    # add cmds to cmdRepo
    cmdgroup_j = cmdcon.CmdgroupCON()
    command.CmdRepo.add_cmdgroup(cmdgroup_j)
    arg = "      Attaching %s to CmdRepo .." % cmdgroup_j.cmdgroupName
    logger.debug(arg)
    gnrl_services.console_print(arg)

    cmdgroup_j = cmdrtc.CmdgroupRTC()
    command.CmdRepo.add_cmdgroup(cmdgroup_j)
    arg = "      Attaching %s to CmdRepo .." % cmdgroup_j.cmdgroupName
    logger.debug(arg)
    gnrl_services.console_print(arg)

    if SUCHAI_config.SCH_CAM_ONBOARD == 1:
        cmdgroup_j = cmdcam.CmdgroupCAM()
        command.CmdRepo.add_cmdgroup(cmdgroup_j)
        arg = "      Attaching %s to CmdRepo .." % cmdgroup_j.cmdgroupName
        logger.debug(arg)
        gnrl_services.console_print(arg)
    else:
        pass

    # debug info
    arg = "      Commands successfully loaded to CmdRepo: "
    logger.debug(arg)
    gnrl_services.console_print(arg)
    for j in range(0, command.CmdRepo.get_num_cmdgroups()):
        cmdgroup_j = command.CmdRepo.get_cmdgroup(j)
        for i in range(0, cmdgroup_j.get_num_cmds()):
            cmd_i = cmdgroup_j.get_cmd(i)
            arg = "        %s.get_cmd(%s) => cmdId: 0x%0.4X, cmdName: %s, " %\
                  (cmdgroup_j.cmdgroupName, i, cmd_i.cmdId, cmd_i.cmdName)
            gnrl_services.console_print(arg)
            logger.debug(arg)
コード例 #9
0
def init_hw_configs():
    arg = "  [init_hw_configs] Internal configs .."
    gnrl_services.console_print(arg)
    logger.debug(arg)
コード例 #10
0
def listener_dispatcher():
    arg = "cmdName %s, pid %s, is_alive %s, exitcode %s" %\
          (listenerHandler.name, listenerHandler.pid, listenerHandler.is_alive(), listenerHandler.exitcode)
    logger.debug(arg)

    while True:
        msg = dispatcherhandler.DispCmd.receive_from_listeners(
        )  # blocking call
        disp_cmd = dispatcherhandler.DispCmd(cmdid=msg.cmdId,
                                             cmdparam=msg.cmdParam,
                                             taskorigid=msg.taskorigId)

        # recover command from CmdRepo
        dispatched_cmd = command.CmdRepo.get_cmd_by_id(disp_cmd.cmdId)
        dispatched_cmd_cmdid = dispatched_cmd.cmdId
        dispatched_cmd_cmdname = dispatched_cmd.cmdName
        dispatched_cmd_cmdsysreq = dispatched_cmd.cmdSysReq
        # recover metadata from requesting Listener (DispCmd)
        dispatched_cmd_cmdparam = disp_cmd.cmdParam
        dispatched_cmd_taskorig = disp_cmd.taskorigId

        #report received Cmd
        arg = "[listener_dispatcher]"
        logger.info(arg)
        gnrl_services.console_print(arg)
        arg = "  Cmdid: 0x%0.4X, CmdName: %s, Listener: 0x%0.4X" %\
              (dispatched_cmd_cmdid, dispatched_cmd_cmdname, dispatched_cmd_taskorig)
        gnrl_services.console_print(arg)
        logger.info(arg)

        #check cmdSysReq
        system_soc = state.StateVar.get_value(state.StateVar.eps_soc)
        executable = check_if_executable(system_soc, dispatched_cmd_cmdsysreq)
        arg = "  Cmd cmdSysReq: %s, System soc: %s, executable: %s" %\
              (dispatched_cmd_cmdsysreq, system_soc, executable)
        logger.info(arg)
        gnrl_services.console_print(arg)

        #execute
        if executable:
            arg = "  >>"
            logger.info(arg)
            gnrl_services.console_print(arg)

            i_time = datetime.datetime.now()
            exitcode = dispatched_cmd.exect(dispatched_cmd_cmdparam)
            f_time = datetime.datetime.now()

            arg = "  <<"
            logger.info(arg)
            gnrl_services.console_print(arg)

            #report time, return status, etc
            d_time = f_time - i_time
            arg = "  d_time: %s, exitcode: %s" % (d_time, exitcode)
            logger.info(arg)
            gnrl_services.console_print(arg)
        else:
            #report time, soc, etc
            arg = "  command NOT executed (not executable)"
            logger.info(arg)
            gnrl_services.console_print(arg)
            arg = "  Cmd cmdSysReq: %s, System soc: %s" % (
                dispatched_cmd_cmdsysreq, system_soc)
            logger.info(arg)
            gnrl_services.console_print(arg)

        arg = "----------------------"
        logger.info(arg)
        gnrl_services.console_print(arg)
        # gnrl_services.console_print("priorityEmulatorSem will be released (cmd sent by %s is done)"
        #                             % disp_cmd.taskorigId)

        # Necesario para emular prioridades de procesos de Listener (Listeners) y Dispatcher
        dispatcherhandler.DispCmd.priorityEmulatorSem.release()
コード例 #11
0
def con_cmd_handler():
    """ Search every cmdName inside cmdgroup_j for a match/hit
    if successful returns a DispCmd containing the corresponding command  """

    # line = gnrl_services.console_input("r>>")
    line = gnrl_services.console_input("")
    # gnrluse.console_print(line)
    line = line.split()

    #if no match or another error
    hit_flag = False
    hit_cmd_cmdid = ""
    hit_cmd_cmdparam = ""
    disp_cmd = dispatcherhandler.DispCmd(
        cmdid=SUCHAI_config.GnrlCmds.CMD_NULL,
        cmdparam=0,
        taskorigid=SUCHAI_config.ConfigTaskorig.TCONSOLE)

    if len(line) != 2:
        gnrl_services.console_print("Bad syntax: cmdId cmdParam")
        return disp_cmd

    # Without the 0x prefix, you need to specify the base explicitly, otherwise there's no way to tell:
    # int("A12FFE12", 16)
    # With the 0x prefix, Python can distinguish hex and decimal automatically:
    # int("0xA12FFE12")
    try:
        user_cmd_id = int(line[0], 16)  # 0x prefix needed
        user_cmd_param = int(line[1])  # No prefix if Decimal is used
    except ValueError:
        gnrl_services.console_print("ValueError: cmdId cmdParam")
        return disp_cmd

    verbose = False
    gnrl_services.console_print("[listener_console]")
    gnrl_services.console_print("  Searching a match for user input " +
                                str(line) + " ..")
    # gnrl_services.console_print("user_cmd_id = %s" % user_cmd_id)
    # gnrl_services.console_print("user_cmd_param = %s" % user_cmd_param)
    # gnrl_services.console_print("-------------------")
    for j in range(0, command.CmdRepo.get_num_cmdgroups()):
        cmdgroup_j = command.CmdRepo.get_cmdgroup(j)
        if verbose:
            gnrl_services.console_print("    cmdgroup_j.cmdgroupName => %s" %
                                        cmdgroup_j.cmdgroupName)
        for i in range(0, cmdgroup_j.get_num_cmds()):
            cmd_i = cmdgroup_j.get_cmd(i)
            cmd_i_cmdid = cmd_i.cmdId
            cmd_i_cmdname = cmd_i.cmdName
            if verbose:
                arg = "      cmdId: 0x%0.4X, cmdName: %s, " % (cmd_i_cmdid,
                                                               cmd_i_cmdname)
                gnrl_services.console_print(arg)
            if user_cmd_id == cmd_i_cmdid:
                hit_cmd_cmdid = user_cmd_id
                hit_cmd_cmdparam = user_cmd_param
                hit_flag = True
                break
        # reevaluate condition to break again (nested loops)
        if hit_flag:
            break

    #check for a hit
    if hit_flag:
        gnrl_services.console_print(
            "  cmdId \"0x%0.4X\" and cmdParam \"%s\" identified as valid command"
            % (hit_cmd_cmdid, hit_cmd_cmdparam))
        disp_cmd = dispatcherhandler.DispCmd(
            cmdid=hit_cmd_cmdid,
            cmdparam=hit_cmd_cmdparam,
            taskorigid=SUCHAI_config.ConfigTaskorig.TCONSOLE)
        return disp_cmd
    else:
        gnrl_services.console_print("  \"%s\" was NOT identified as command" %
                                    user_cmd_id)
        return disp_cmd
コード例 #12
0
ファイル: cmdcon.py プロジェクト: spel-uchile/SUCHAIportings
 def con_help(param):
     gnrl_services.console_print("This is the useless %s command" %
                                 CmdFunctCON.con_help.__name__)
     gnrl_services.console_print("Used with cmdParam %s" % param)
     return True
コード例 #13
0
 def cmdnull(param):
     arg = "cmdnull used with cmdParam: %s" % param
     logger.error(arg)
     gnrl_services.console_print(arg)
     return True
コード例 #14
0
 def get_time_now(param):
     gnrl_services.console_print(datetime.datetime.now())
     return True