vr1.1

Dependencies:   FreescaleIAP mbed-rtos mbed

Fork of CDMS_RTOS_v1_1 by Team Fox

PL.cpp

Committer:
pradeepvk2208
Date:
2015-07-04
Revision:
9:7ff6d75cc09e
Parent:
8:607ae92fa6af
Child:
12:cb3ee1ac3638

File content as of revision 9:7ff6d75cc09e:

#include "mbed.h"
#include "PL.h"
#include "all_funcs.h"
#include "Flags.h"

Serial sr(USBTX,USBRX);

void FCTN_PL_RCV_SC_DATA()
{
    sr.printf("in FCTN_PL_RCV_SC_DATA\r\n");
    uint8_t scienceRawPacket[payloadBins];
    for(int i=0; i<payloadBins; i++) 
    {
        while(!pl_spi.receive()); // blocking statement --> waiting for data from Payload
        uint8_t v = pl_spi.read();   // Read byte from master
        scienceRawPacket[i] = v;
    }
    // serial feedback
    sr.printf("Packet recieved\r\r\n");
    for(int i=0; i<payloadBins; i++) 
    {
        sr.printf("%0x\t",scienceRawPacket[i]);
        scienceRawPacket[i] = 0;
    }
    sr.printf("\r\r\n");
}

void FCTN_PL_MAIN()
{
    pl_main_flags|=PL_MAIN_STATUS;
    pl_main_flags&=~(PL_LOW_POWER);
    pl_prev_state=pl_state;
    if(pl_schedule==1) 
    {
        pl_state=pl_schedule_TC;
    } 
    else 
    {
        if(pl_state==PL_SCIENCE) 
        {
            pl_state= PL_HIBERNATE;
        } 
        else 
        {
            pl_state=pl_prev_state;
        }
    }

    switch(pl_state) 
    {
        case PL_OFF: 
        {
            if(pl_prev_state!=PL_OFF) 
            {
                sr.printf("Command SPEED DL to go to Standby State (I2C) \r\n");
            }
            sr.printf("Power off SPEED\r\n");
            pl_status=PL_OFF;
            sr.printf("Disable SRP_INTERVAL_COUNTER\r\n");
            pl_main_flags&=~(PL_MAIN_STATUS);
        }
        case PL_STANDBY: 
        {
            if(power_level<0) 
            {
                pl_main_flags|=PL_LOW_POWER;
                if(pl_prev_state!=PL_OFF) 
                {
                    sr.printf("Command SPEED DL to go to Standby State (I2C) \r\n");
                }
                sr.printf("Power off SPEED\r\n");
                pl_status=PL_OFF;
                sr.printf("Disable SRP_INTERVAL_COUNTER\r\n");
                pl_main_flags&=~(PL_MAIN_STATUS);
            } 
            else 
            {
                if(pl_prev_state!=PL_OFF) 
                {
                    sr.printf("Command SPEED DL to go to Standby State (I2C) \r\n");
                    sr.printf("Power OFF SPEED PMTs\r\n");
                    if(I2C_acknowledgement==1) 
                    {
                        pl_status=PL_STANDBY;
                    } 
                    else 
                    {
                        pl_status=PL_ERR_I2C;
                    }
                    sr.printf("Disable SRP_INTERVAL_COUNTER\r\n");
                    pl_main_flags&=~(PL_MAIN_STATUS);
                } 
                else 
                {
                    sr.printf("Power on SPPED DL\r\n");
                    sr.printf("Command SPEED DL to go to Standby State (I2C) \r\n");
                    if(I2C_acknowledgement==1) 
                    {
                        pl_status=PL_STANDBY;
                    } 
                    else 
                    {
                        pl_status=PL_ERR_I2C;
                    }
                    sr.printf("Disable SRP_INTERVAL_COUNTER\r\n");
                    pl_main_flags&=~(PL_MAIN_STATUS);
                }
            }
        }
        case PL_HIBERNATE: 
        {
            if(power_level<1) 
            {
                pl_main_flags|=PL_LOW_POWER;
                if(power_level<0) 
                {
                    pl_main_flags|=PL_LOW_POWER;
                    if(pl_prev_state!=PL_OFF) 
                    {
                        sr.printf("Command SPEED DL to go to Standby State (I2C) \r\n");
                    }
                    sr.printf("Power off SPEED\r\n");
                    pl_status=PL_OFF;
                    sr.printf("Disable SRP_INTERVAL_COUNTER\r\n");
                    pl_main_flags&=~(PL_MAIN_STATUS);
                } 
                else 
                {
                    if(pl_prev_state!=PL_OFF) 
                    {
                        sr.printf("Command SPEED DL to go to Standby State (I2C) \r\n");
                        sr.printf("Power OFF SPEED PMTs\r\n");
                        if(I2C_acknowledgement==1) 
                        {
                            pl_status=PL_STANDBY;
                        } 
                        else 
                        {
                            pl_status=PL_ERR_I2C;
                        }
                        sr.printf("Disable SRP_INTERVAL_COUNTER\r\n");
                        pl_main_flags&=~(PL_MAIN_STATUS);
                    } 
                    else 
                    {
                        sr.printf("Power on SPPED DL\r\n");
                        sr.printf("Command SPEED DL to go to Standby State (I2C) \r\n");
                        if(I2C_acknowledgement==1) {
                            pl_status=PL_STANDBY;
                        } 
                        else 
                        {
                            pl_status=PL_ERR_I2C;
                        }
                        sr.printf("Disable SRP_INTERVAL_COUNTER\r\n");
                        pl_main_flags&=~(PL_MAIN_STATUS);
                    }
                }
            }
            if(power_level>1) 
            {
                if(pl_prev_state==PL_OFF) 
                {
                    sr.printf("Power on SPEED DL\r\n");
                }
                sr.printf("Power on Speed PMT with reduced Voltage\r\n");
                sr.printf("Command SPEED DL to go to Standby State (I2C) \r\n");
                if(I2C_acknowledgement==1) 
                {
                    pl_status=PL_HIBERNATE;
                } 
                else 
                {
                    pl_status=PL_ERR_I2C;
                }
                sr.printf("Disable SRP_INTERVAL_COUNTER\r\n");
                pl_main_flags&=~(PL_MAIN_STATUS);
            }
        }

        case PL_SCIENCE: 
        {

            if(power_level<2) 
            {
                if(power_level<1) 
                {
                    pl_main_flags|=PL_LOW_POWER;
                    if(power_level<0) 
                    {
                        pl_main_flags|=PL_LOW_POWER;
                        if(pl_prev_state!=PL_OFF) 
                        {
                            sr.printf("Command SPEED DL to go to Standby State (I2C) \r\n");
                        }
                        sr.printf("Power off SPEED\r\n");
                        pl_status=PL_OFF;
                        sr.printf("Disable SRP_INTERVAL_COUNTER\r\n");
                        pl_main_flags&=~(PL_MAIN_STATUS);
                    } 
                    else 
                    {
                        if(pl_prev_state!=PL_OFF) 
                        {
                            sr.printf("Command SPEED DL to go to Standby State (I2C) \r\n");
                            sr.printf("Power OFF SPEED PMTs\r\n");
                            if(I2C_acknowledgement==1) 
                            {
                                pl_status=PL_STANDBY;
                            } 
                            else 
                            {
                                pl_status=PL_ERR_I2C;
                            }
                            sr.printf("Disable SRP_INTERVAL_COUNTER\r\n");
                            pl_main_flags&=~(PL_MAIN_STATUS);
                        } 
                        else 
                        {
                            sr.printf("Power on SPPED DL\r\n");
                            sr.printf("Command SPEED DL to go to Standby State (I2C) \r\n");
                            if(I2C_acknowledgement==1) 
                            {
                                pl_status=PL_STANDBY;
                            } 
                            else 
                            {
                                pl_status=PL_ERR_I2C;
                            }
                            sr.printf("Disable SRP_INTERVAL_COUNTER\r\n");
                            pl_main_flags&=~(PL_MAIN_STATUS);
                        }
                    }
                }
                if(power_level>1) 
                {
                    if(pl_prev_state==PL_OFF) 
                    {
                        sr.printf("Power on SPEED DL\r\n");
                    }
                    sr.printf("Power on Speed PMT with reduced Voltage\r\n");
                    sr.printf("Command SPEED DL to go to Standby State (I2C) \r\n");
                    if(I2C_acknowledgement==1) 
                    {
                        pl_status=PL_HIBERNATE;
                    } 
                    else 
                    {
                        pl_status=PL_ERR_I2C;
                    }
                    sr.printf("Disable SRP_INTERVAL_COUNTER\r\n");
                    pl_main_flags&=~(PL_MAIN_STATUS);
                }
            }
            if(power_level>2) 
            {
                if(pl_prev_state==PL_SCIENCE) 
                {
                    pl_status=PL_SCIENCE;
                    pl_main_flags&=~(PL_MAIN_STATUS);
                } 
                else if(pl_prev_state==PL_HIBERNATE) 
                {
                    sr.printf("Power on SPEED PMT with high voltage \r\n");
                    sr.printf("Command SPEED DL to go to Standby State (I2C) \r\n");
                    if(I2C_acknowledgement==1) 
                    {
                        sr.printf("Enable SRP_INTERVAL_COUNTER\r\n");
                        pl_status=PL_SCIENCE;
                        pl_main_flags&=~(PL_MAIN_STATUS);
                    } 
                    else 
                    {
                        pl_status=PL_ERR_I2C;
                        sr.printf("Disable SRP_INTERVAL_COUNTER\r\n");
                        pl_main_flags&=~(PL_MAIN_STATUS);
                    }
                } 
                else

                {
                    if(pl_prev_state==PL_OFF) 
                    {
                        sr.printf("Power on SPEED DL\r\n");
                    }
                    sr.printf("Power on Speed PMT with reduced Voltage\r\n");
                    sr.printf("Command SPEED DL to go to Standby State (I2C) \r\n");
                    if(I2C_acknowledgement==1) 
                    {
                        pl_status=PL_HIBERNATE;
                    } 
                    else 
                    {
                        pl_status=PL_ERR_I2C;
                    }
                    sr.printf("Disable SRP_INTERVAL_COUNTER\r\n");
                    pl_main_flags&=~(PL_MAIN_STATUS);
                }
            }


        }

    }
}