void taskExecuter(void *param) { printf(">>[Executer] Started\n"); ExeCmd RunCmd; int cmdStat, queueStat, cmdParam; while(1) { /* Read the CMD that Dispatcher sent - BLOCKING */ queueStat = xQueueReceive(executerCmdQueue, &RunCmd, portMAX_DELAY); if(queueStat == pdPASS) { printf("[Executer] Running a command...\n"); /* Commands may take a long time, so reset the WDT */ ClrWdt(); /* Execute the command */ cmdParam = RunCmd.param; cmdStat = RunCmd.fnct((void *)&cmdParam); /* Commands may take a long time, so reset the WDT */ ClrWdt(); printf("[Executer] Command result: %d\n", cmdStat); /* Send the result to Dispatcher - BLOCKING */ xQueueSend(executerStatQueue, &cmdStat, portMAX_DELAY); } } }
void taskExecuter(void *param) { #if (SCH_TEXECUTER_VERBOSE>=1) printf("[Executer] Started\r\n"); #endif ExeCmd RunCmd; int cmdStat, queueStat, cmdParam; while(1) { /* Read the CMD that Dispatcher sent - BLOCKING */ queueStat = xQueueReceive(executerCmdQueue, &RunCmd, portMAX_DELAY); #if (SCH_TEXECUTER_VERBOSE > 1) printf("[Executer] Executing a new command...\r\n"); #endif if(queueStat == pdPASS) { /* El comando tiene 2min aprox para ejecutarse */ ClrWdt(); /* Execute the command */ cmdParam = RunCmd.param; cmdStat = RunCmd.fnct((void *)&cmdParam); /* Si el comando se ejecuto bien reseteo el WDT */ ClrWdt(); #if (SCH_TEXECUTER_VERBOSE > 1) printf("[Executer] Return status: %d\n", (unsigned int)cmdStat ); #endif /* Send the result to Dispatcher - BLOCKING */ xQueueSend(executerStatQueue, &cmdStat, portMAX_DELAY); } } }
int drp_fpl_check_and_exec(void *param){ //FP, programmed actions unsigned int index, current_hour, current_mins; static unsigned int last_index; //to enter the first try, then check every time DispCmd NewCmd; NewCmd.idOrig = 0; NewCmd.cmdId = CMD_CMDNULL; NewCmd.param = 0; ExeCmd exeCmd; /* The cmd to executer */ int cmdParam; int cmdResult; /* Map hh:mm to MM minutues of the day to obtain the * index of the next command to read from fligh plan */ current_hour = sta_get_stateVar(sta_rtc_hours); current_mins = sta_get_stateVar(sta_rtc_minutes); index = current_hour*60 + current_mins; index = index / SCH_FLIGHTPLAN_RESOLUTION; #if SCH_TASKFLIGHTPLAN_VERBOSE /* Debug info */ printf(" [drp_fpl_check_and_exec] index = %d = (%d*60+%d)/SCH_FP_RESOLUTION \n last_index=%d | SCH_FP_N_CMD=%d\r\n", index, current_hour, current_mins, last_index, SCH_FLIGHTPLAN_N_CMD); #endif /* If check time is less than flight plan resolution (as it should be) * we need to prevent an index repetition */ if(last_index != index) { /* Update last_index */ last_index = index; /* Get the next command from flight plan */ NewCmd = dat_get_FlightPlan(index); //get cmdId and param //NewCmd.idOrig = CMD_IDORIG_TFLIGHTPLAN3; /* Check if valid cmd */ if(NewCmd.cmdId == CMD_CMDNULL){ #if SCH_TASKFLIGHTPLAN_VERBOSE printf(" [drp_fpl_check_and_exec] Se extrae CMD_CMDNULL, se omite\r\n"); #endif return 0; } #if SCH_TASKFLIGHTPLAN_VERBOSE /* Print the command code */ printf(" [drp_fpl_check_and_exec] Se extrae cmdId = 0x%X, param = %d, ejecutando .. \r\n", (unsigned int)NewCmd.cmdId, (unsigned int)NewCmd.param); #endif /* Queue NewCmd - Blocking */ //xQueueSend(dispatcherQueue, &NewCmd, portMAX_DELAY); /* Check if command is executable */ //not performed /* Fill the executer command */ exeCmd.fnct = repo_getFunction(NewCmd.cmdId); exeCmd.param = NewCmd.param; /* Execute the command */ cmdParam = exeCmd.param; cmdResult = exeCmd.fnct((void *)&cmdParam); } else{ #if(SCH_TASKFLIGHTPLAN_VERBOSE >= 1) /* Print the command code */ printf(" [drp_fpl_check_and_exec] (last_index==index) => NO se genera comando\r\n"); #endif return 1; } return cmdResult; }