コード例 #1
0
ファイル: taskFlightPlan2.c プロジェクト: keimi/SUCHAI
void taskFlightPlan2(void *param)
{
#if (SCH_FLIGHTPLAN2_VERBOSE)
        printf(">>[FlightPlan2] Started\r\n");
#endif

#if SCH_FLIGHTPLAN2_REALTIME
    unsigned int min_check_period_ms = 10000;      /* check every x ms  */
    portTickType xDelay_ticks = (min_check_period_ms) / portTICK_RATE_MS;
    portTickType check_deployment_time = (10000) / portTICK_RATE_MS;      /* check every 10sec  */
#else
    unsigned int min_check_period_ms = 1000;      /* check every 2sec  */
    portTickType xDelay_ticks = (min_check_period_ms) / portTICK_RATE_MS;
    portTickType check_deployment_time = (10000) / portTICK_RATE_MS;      /* check every 10sec  */
#endif

    DispCmd NewCmd;
    NewCmd.idOrig = CMD_IDORIG_TFLIGHTPLAN2; /* Housekeeping */
    NewCmd.cmdId = CMD_CMDNULL;
    NewCmd.param = 0;

    /*Avoid the acummulation of commands while the SUCHAI is still deploying.. */
    portTickType xLastWakeTime = xTaskGetTickCount();
    #if (SCH_USE_HOUSEKEEPING == 1)
        while( TRUE ){
            if( sta_get_stateVar(sta_dep_ant_deployed)==1 ){
                break;
            }
            vTaskDelayUntil(&xLastWakeTime, check_deployment_time);
        }
    #endif

    while(1)
    {
        /* min_check_period_ms actions */
        vTaskDelayUntil(&xLastWakeTime, xDelay_ticks);
        
        /* Check if the next tick to wake has already
         * expired (*pxPreviousWakeTime = xTimeToWake;)
         * This avoids multiple reentries on vTaskDelayUntil */
        BOOL xShouldDelay = shouldDelayTask(&xLastWakeTime, xDelay_ticks);
        if( xShouldDelay == FALSE )
        {
             xLastWakeTime = xTaskGetTickCount();
            #if (SCH_FLIGHTPLAN2_VERBOSE>=1)
                printf("[FlightPlan2] xLastWakeTime + xDelay_ticks < xTickCount, "
                        "update xLastWakeTime to xTickCount ..\r\n");
            #endif
        }

        //Add commands below ..

        #if (SCH_FLIGHTPLAN2_VERBOSE>=1)
            printf("[FlightPlan2] min_check_period_ms (%d) actions ..\r\n", min_check_period_ms);
        #endif

        if(sta_get_stateVar(sta_ppc_opMode)==STA_PPC_OPMODE_NORMAL){
            NewCmd.cmdId = pay_id_fp2_default_fsm;
            NewCmd.param = 0;
            xQueueSend(dispatcherQueue, (const void *) &NewCmd, portMAX_DELAY);
        }

    }
}
コード例 #2
0
ファイル: taskFlightPlan3.c プロジェクト: spel-uchile/SUCHAI
void taskFlightPlan3(void *param)
{
#if (SCH_TFLIGHTPLAN3_VERBOSE)
        printf(">>[FlightPlan3] Started\r\n");
#endif

#if (SCH_TFLIGHTPLAN3_REALTIME == 1)
    unsigned int tick_period_ms = 10000;      /* check every x ms  */
    portTickType xDelay_ticks = (tick_period_ms) / portTICK_RATE_MS;
    #if (SCH_THOUSEKEEPING_USE == 1)
        //portTickType check_deployment_time = (10000) / portTICK_RATE_MS;      /* check every 10sec  */
    #endif
#else
    unsigned int tick_period_ms = 1000;      /* check every 2sec  */
    portTickType xDelay_ticks = (tick_period_ms) / portTICK_RATE_MS;
    portTickType check_deployment_time = (10000) / portTICK_RATE_MS;      /* check every 10sec  */
#endif

    DispCmd NewCmd;
    NewCmd.idOrig = SCH_TFLIGHTPLAN3_IDORIG;
    NewCmd.cmdId = CMD_CMDNULL;
    NewCmd.param = 0;

    /*Avoid the acummulation of commands while the SUCHAI is still deploying.. */
    portTickType xLastWakeTime = xTaskGetTickCount();
//    #if (SCH_THOUSEKEEPING_USE == 1)
//        while( TRUE ){
//            if( sta_get_BusStateVar(sta_dep_ant_deployed)==1 ){
//                break;
//            }
//            vTaskDelayUntil(&xLastWakeTime, check_deployment_time);
//        }
//    #endif

    int ticks_elapsed = 1;
    int res_ticks = (60*(SCH_TFLIGHTPLAN_RESOLUTION))/(2*(tick_period_ms/1000));
    while(1)
    {
        /* min_check_period_ms actions */
        vTaskDelayUntil(&xLastWakeTime, xDelay_ticks);
        
        /* Check if the next tick to wake has already
         * expired (*pxPreviousWakeTime = xTimeToWake;)
         * This avoids multiple reentries on vTaskDelayUntil */
        BOOL xShouldDelay = shouldDelayTask(&xLastWakeTime, xDelay_ticks);
        if( xShouldDelay == FALSE )
        {
             xLastWakeTime = xTaskGetTickCount();
            #if (SCH_TFLIGHTPLAN3_VERBOSE>=1)
                printf("[FlightPlan3] xLastWakeTime + xDelay_ticks < xTickCount, "
                        "update xLastWakeTime to xTickCount ..\r\n");
            #endif
        }

        //Add commands below ..

        #if (SCH_TFLIGHTPLAN3_VERBOSE>=1)
            printf("[FlightPlan3] min_check_period_ms (%d) actions, ticks_elapsed/res_ticks = %u/%u ..\r\n", tick_period_ms, ticks_elapsed, res_ticks);
        #endif

        //execute regular/cyclic payloads ..
        //if(sta_get_BusStateVar(sta_ppc_opMode)==STA_PPC_OPMODE_NORMAL){
            NewCmd.cmdId = pay_id_fp2_default_fsm;
            NewCmd.param = tick_period_ms;
            xQueueSend(dispatcherQueue, (const void *) &NewCmd, portMAX_DELAY);
        //}

        if(ticks_elapsed >= res_ticks){
            ticks_elapsed = 1;

            //execute programmed/itinerary actions ..
            NewCmd.cmdId = drp_id_fpl_check_and_exec;
            NewCmd.param = 0;
            xQueueSend(dispatcherQueue, (const void *) &NewCmd, portMAX_DELAY);
        }
        else{
            ticks_elapsed++;
        }
    }
}
コード例 #3
0
ファイル: taskHousekeeping.c プロジェクト: spel-uchile/SUCHAI
void taskHousekeeping(void *param)
{
    #if SCH_THOUSEKEEPING_VERBOSE
        printf(">>[Housekeeping] Started\r\n");
    #endif

    portTickType delay_ms    = 10000;    //Task period in [ms]
    portTickType xDelay_ticks = delay_ms / portTICK_RATE_MS; //Task period in ticks

#if (SCH_THOUSEKEEPING_REALTIME == 1)
    unsigned int elapsed_sec = 0;       // Seconds counter
    unsigned int elapsed_hrs = 0;       // Hours counter
    unsigned int check_20sec = 20;     //20[s] condition
    unsigned int check_1min = 1*60;      //1[m] condition
    unsigned int check_5min = 5*60;    //5[m] condition
    unsigned int check_1hour = 60*60;  //1[h] condition
    unsigned int check_1day = 24;      //24[hrs] condition
#else
    unsigned int elapsed_sec = 0;                    // Seconds counter
    unsigned int elapsed_hrs = 0;                    // Hours counter
    unsigned int check_20sec = 2;                    //2[s] condition
    unsigned int check_1min = 3*check_20sec;         //3[s] condition
    unsigned int check_5min = 3*3*check_20sec;       //5[s] condition
    unsigned int check_1hour = 3*3*3*check_20sec;   //10[s] condition
    unsigned int check_1day = 3;                     //1[m] condition
#endif

    DispCmd NewCmd;
    NewCmd.idOrig = SCH_THOUSEKEEPING_IDORIG; /* Housekeeping */
    NewCmd.cmdId = CMD_CMDNULL;
    NewCmd.param = 0;

    //deploy if necessary
    //if( sta_get_BusStateVar(sta_dep_ant_deployed) == 0 ){

        #if (SCH_THOUSEKEEPING_SILENT_REALTIME==1)
            NewCmd.cmdId = thk_id_suchai_deployment;
            NewCmd.param = 31;  //in minutes
            xQueueSend(dispatcherQueue, &NewCmd, portMAX_DELAY);
        #else
            NewCmd.cmdId = thk_id_suchai_deployment;
            NewCmd.param = 3;  //in minutes
            xQueueSend(dispatcherQueue, &NewCmd, portMAX_DELAY);
        #endif
    //}

    /*Avoid the acummulation of commands while the SUCHAI is still deploying.. */
    portTickType xLastWakeTime = xTaskGetTickCount();
    while(TRUE)
    {
        vTaskDelayUntil(&xLastWakeTime, xDelay_ticks); //Suspend task
        elapsed_sec += delay_ms/1000; //Update seconds counts
        /* Check if the next tick to wake has already
         * expired (*pxPreviousWakeTime = xTimeToWake;)
         * This avoids multiple reentries on vTaskDelayUntil */
        BOOL xShouldDelay = shouldDelayTask(&xLastWakeTime, xDelay_ticks);
        if( xShouldDelay == FALSE )
        {
             xLastWakeTime = xTaskGetTickCount();
            #if (SCH_TFLIGHTPLAN2_VERBOSE>=1)
                printf("[Housekeeping] xLastWakeTime + xDelay_ticks < xTickCount, "
                        "update xLastWakeTime to xTickCount ..\r\n");
            #endif
        }

        //Add commands below ..

        /* 20 seconds actions */
        if((elapsed_sec % check_20sec) == 0)
        {
            #if (SCH_THOUSEKEEPING_VERBOSE>=2)
                printf("[Houskeeping]:  20[s] actions ..\r\n");
            #endif
            //Add commands below ..
        }

        /* 1 minute actions */
        if((elapsed_sec % check_1min) == 0)
        {
            #if (SCH_THOUSEKEEPING_VERBOSE>=2)
                printf("[Houskeeping] 1[min] actions ..\r\n");
            #endif
            //Add commands below ..
                
        }

        /* 5 minutes actions */
        if((elapsed_sec % check_5min) == 0)
        {
            #if (SCH_THOUSEKEEPING_VERBOSE>=1)
                printf("[Houskeeping] 5[min] actions ..\r\n");
            #endif
            //Add commands below ..
                

//            //print StateVars, debug purposes
//            NewCmd.cmdId = srp_id_print_STA_stateVar;
//            NewCmd.param = 1;
//            xQueueSend(dispatcherQueue, &NewCmd, portMAX_DELAY);
        }

        /* 1 hour actions  */
        if((elapsed_sec % check_1hour) == 0)
        {
            elapsed_hrs++;
            elapsed_sec = 0; //Prevent overflow

            #if (SCH_THOUSEKEEPING_VERBOSE>=1)
                printf("[Houskeeping] 1[hr] actions ..\r\n");
            #endif
            //Add commands below ..

            //test trx ping
            NewCmd.cmdId = trx_id_isAlive;
            NewCmd.param = 0;
            xQueueSend(dispatcherQueue, &NewCmd, portMAX_DELAY);
            
            //test eps ping
            NewCmd.cmdId = eps_id_isAlive;
            NewCmd.param = 0;
            xQueueSend(dispatcherQueue, &NewCmd, portMAX_DELAY);

            // hoursWithoutReset++
            NewCmd.cmdId = srp_id_increment_STA_stateVar_hoursWithoutReset;
            NewCmd.param = 0;
            xQueueSend(dispatcherQueue, &NewCmd, portMAX_DELAY);

            // hoursAlive ++
            NewCmd.cmdId = srp_id_increment_STA_stateVar_hoursAlive;
            NewCmd.param = 0;
            xQueueSend(dispatcherQueue, &NewCmd, portMAX_DELAY);

        }

        /* codigo para _1day_check */
        if( (elapsed_hrs % check_1day == 0) && (elapsed_hrs != 0) )
        {
            #if (SCH_THOUSEKEEPING_VERBOSE>=1)
                printf("[Houskeeping]:        1[day] actions ..\r\n");
            #endif
            elapsed_hrs = 0;  //Prevent overflow
            //Add commands below ..
        }
    }
}