Exemplo n.º 1
0
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *  * *  * * * * **/
void $APPLICATION_NAME$_AppMain( void )
{
    int32  status;
    uint32 RunStatus = CFE_ES_APP_RUN;

    CFE_ES_PerfLogEntry($APPLICATION_NAME$_APP_PERF_ID);

    $APPLICATION_NAME$_AppInit();

    /*
    ** $APPLICATION_NAME$ Runloop
    */
    while (CFE_ES_RunLoop(&RunStatus) == TRUE)
    {
        CFE_ES_PerfLogExit($APPLICATION_NAME$_APP_PERF_ID);

        /* Pend on receipt of command packet -- timeout set to 500 millisecs */
        status = CFE_SB_RcvMsg(&$APPLICATION_NAME$_MsgPtr, $APPLICATION_NAME$_CommandPipe, 500);
        
        CFE_ES_PerfLogEntry($APPLICATION_NAME$_APP_PERF_ID);

        if (status == CFE_SUCCESS)
        {
            $APPLICATION_NAME$_ProcessCommandPacket();
        }

    }

    CFE_ES_ExitApp(RunStatus);

} /* End of $APPLICATION_NAME$_AppMain() */
Exemplo n.º 2
0
void THRSIM_TaskMain(void) {
    uint32 RunStatus = CFE_ES_APP_RUN;
    int32  Status = CFE_SUCCESS;

    CFE_ES_PerfLogEntry(THRSIM_MAIN_TASK_PERF_ID);

    Status = THRSIM_Init();
    if (Status != CFE_SUCCESS) {
        RunStatus = CFE_ES_APP_ERROR;
    }

    while (CFE_ES_RunLoop(&RunStatus) == TRUE) {
        CFE_ES_PerfLogExit(THRSIM_MAIN_TASK_PERF_ID);

        Status = CFE_SB_RcvMsg(&THRSIM_AppData.MsgPtr, THRSIM_AppData.CmdPipe, CFE_SB_PEND_FOREVER);

        CFE_ES_PerfLogEntry(THRSIM_MAIN_TASK_PERF_ID);

        if (Status == CFE_SUCCESS) {
            THRSIM_AppPipe();
        } else {
            CFE_EVS_SendEvent(THRSIM_PIPE_ERR_EID, CFE_EVS_ERROR, "SB pipe read error, THRSIM will exit.");
            RunStatus = CFE_ES_APP_ERROR;
        }
    }
}
Exemplo n.º 3
0
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void TO_Lab_AppMain(void)
{
   uint32                  RunStatus = CFE_ES_APP_RUN;
   
   CFE_ES_PerfLogEntry(TO_MAIN_TASK_PERF_ID);

   TO_init();

   /*
   ** TO RunLoop
   */
   while(CFE_ES_RunLoop(&RunStatus) == TRUE)
   {
        CFE_ES_PerfLogExit(TO_MAIN_TASK_PERF_ID);

        OS_TaskDelay(TO_TASK_MSEC);    /*2 Hz*/

        CFE_ES_PerfLogEntry(TO_MAIN_TASK_PERF_ID);

        TO_forward_telemetry();

        TO_process_commands();
    }

   CFE_ES_ExitApp(RunStatus);

} /* End of TO_Lab_AppMain() */
void CFE_TIME_TaskMain(void)
{
    int32  Status;
  
    CFE_ES_PerfLogEntry(CFE_TIME_MAIN_PERF_ID);
  
    Status = CFE_TIME_TaskInit();
    
    if(Status != CFE_SUCCESS)
    {
      CFE_ES_WriteToSysLog("TIME:Application Init Failed,RC=0x%08X\n", Status);      
      CFE_ES_PerfLogExit(CFE_TIME_MAIN_PERF_ID);
      /* Note: CFE_ES_ExitApp will not return */      
      CFE_ES_ExitApp(CFE_ES_CORE_APP_INIT_ERROR);
    }/* end if */
  
    /*
     * Wait for other apps to start.
     * It is important that the core apps are present before this starts receiving
     * messages from the command pipe, as some of those handlers might depend on
     * the other core apps.
     */
    CFE_ES_WaitForStartupSync(CFE_CORE_MAX_STARTUP_MSEC);

    /* Main loop */
    while (Status == CFE_SUCCESS)
    {
    
      /* Increment the Main task Execution Counter */
      CFE_ES_IncrementTaskCounter();

      CFE_ES_PerfLogExit(CFE_TIME_MAIN_PERF_ID);
  
      /* Pend on receipt of packet */
      Status = CFE_SB_RcvMsg(&CFE_TIME_TaskData.MsgPtr,
                              CFE_TIME_TaskData.CmdPipe,
                              CFE_SB_PEND_FOREVER);
  
      CFE_ES_PerfLogEntry(CFE_TIME_MAIN_PERF_ID);
  
      if (Status == CFE_SUCCESS)
      {
          /* Process cmd pipe msg */
          CFE_TIME_TaskPipe(CFE_TIME_TaskData.MsgPtr);
      }else{
          CFE_ES_WriteToSysLog("TIME:Error reading cmd pipe,RC=0x%08X\n",Status);
      }/* end if */
      
    }/* end while */
    
    /* while loop exits only if CFE_SB_RcvMsg returns error */
    CFE_ES_ExitApp(CFE_ES_CORE_APP_RUNTIME_ERROR);

} /* end CFE_TIME_TaskMain */
Exemplo n.º 5
0
void CFE_TBL_TaskMain(void)
{
    int32  Status;

    CFE_ES_PerfLogEntry(CFE_TBL_MAIN_PERF_ID);

    Status = CFE_TBL_TaskInit();
    
    if(Status != CFE_SUCCESS)
    {
      CFE_ES_WriteToSysLog("TBL:Application Init Failed,RC=0x%08X\n", Status);      
      CFE_ES_PerfLogExit(CFE_TBL_MAIN_PERF_ID);      
      /* Note: CFE_ES_ExitApp will not return */
      CFE_ES_ExitApp(CFE_ES_CORE_APP_INIT_ERROR);
    }/* end if */

    /* Main loop */
    while (Status == CFE_SUCCESS)
    {
        /* Increment the Main task Execution Counter */
        CFE_ES_IncrementTaskCounter();

        CFE_ES_PerfLogExit(CFE_TBL_MAIN_PERF_ID);

        /* Pend on receipt of packet */
        Status = CFE_SB_RcvMsg( &CFE_TBL_TaskData.MsgPtr,
                                CFE_TBL_TaskData.CmdPipe,
                                CFE_SB_PEND_FOREVER);

        CFE_ES_PerfLogEntry(CFE_TBL_MAIN_PERF_ID);

        if (Status == CFE_SUCCESS)
        {
            /* Process cmd pipe msg */
            CFE_TBL_TaskPipe(CFE_TBL_TaskData.MsgPtr);
        }else{
            CFE_ES_WriteToSysLog("TBL:Error reading cmd pipe,RC=0x%08X\n",Status);
        }/* end if */

    }/* end while */

    /* while loop exits only if CFE_SB_RcvMsg returns error */
    CFE_ES_ExitApp(CFE_ES_CORE_APP_RUNTIME_ERROR);

} /* end CFE_TBL_TaskMain() */
Exemplo n.º 6
0
void CI_TaskMain( void )
{
    int32   status;
    uint32  RunStatus = CFE_ES_APP_RUN;

    CFE_ES_PerfLogEntry(CI_MAIN_TASK_PERF_ID);

    CI_TaskInit();

#ifdef _CI_DELAY_TEST
    OS_printf("CI going to delay for 40 seconds before calling runloop\n");
    OS_TaskDelay(40000);
#endif

    /*
    ** CI Runloop
    */
    while (CFE_ES_RunLoop(&RunStatus) == TRUE)
    {
        CFE_ES_PerfLogExit(CI_MAIN_TASK_PERF_ID);

        /* Pend on receipt of command packet -- timeout set to 500 millisecs */
        status = CFE_SB_RcvMsg(&CIMsgPtr, CI_CommandPipe, 500);
        CFE_ES_PerfLogEntry(CI_MAIN_TASK_PERF_ID);

        if (status == CFE_SUCCESS)
        {
            CI_ProcessCommandPacket();
        }

        /* Regardless of packet vs timeout, always process uplink queue      */
        if (CI_SocketConnected)
        {
            CI_ReadUpLink();
        }
    }
    CFE_ES_ExitApp(RunStatus);

} /* End of CI_TaskMain() */
Exemplo n.º 7
0
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void TO_forward_telemetry(void)
{
    static struct sockaddr_in s_addr;
    int                       status;
    int32                     CFE_SB_status;
    uint16                    size;
    CFE_SB_Msg_t              *PktPtr;

    bzero((char *) &s_addr, sizeof(s_addr));
    s_addr.sin_family      = AF_INET;
    s_addr.sin_addr.s_addr = inet_addr(tlm_dest_IP);
    s_addr.sin_port        = htons(cfgTLM_PORT);
    status = 0;

    do
    {
       CFE_SB_status = CFE_SB_RcvMsg(&PktPtr, TO_Tlm_pipe, CFE_SB_POLL);

       if ( (CFE_SB_status == CFE_SUCCESS) && (suppress_sendto == FALSE) )
       {
          size = CFE_SB_GetTotalMsgLength(PktPtr);
          
          if(downlink_on == TRUE)
          {
             CFE_ES_PerfLogEntry(TO_SOCKET_SEND_PERF_ID);

             status = sendto(TLMsockid, (char *)PktPtr, size, 0,
                                        (struct sockaddr *) &s_addr,
                                         sizeof(s_addr) );
                                         
             CFE_ES_PerfLogExit(TO_SOCKET_SEND_PERF_ID);                             
          }
          if (status < 0)
          {
             CFE_EVS_SendEvent(TO_TLMOUTSTOP_ERR_EID,CFE_EVS_ERROR,
                               "L%d TO sendto errno %d. Tlm output supressed\n", __LINE__, errno);
             suppress_sendto = TRUE;
          }
       }
    /* If CFE_SB_status != CFE_SUCCESS, then no packet was received from CFE_SB_RcvMsg() */
    }while(CFE_SB_status == CFE_SUCCESS);
} /* End of TO_forward_telemetry() */
Exemplo n.º 8
0
void TO_SendToChannel(uint32 ChannelID, CFE_SB_MsgPtr_t Msg, uint32 Size)
{
	static struct sockaddr_in s_addr;
    int						  status = 0;

    bzero((char *) &s_addr, sizeof(s_addr));
    s_addr.sin_family      = AF_INET;

    if(ChannelID < TO_MAX_TLM_CHANNELS)
    {
    	char *Buffer = (char*)Msg;
    	TO_TlmChannels_t *channel = &TO_AppData.Config->Channel[ChannelID];

    	if(channel->Mode == TO_CHANNEL_ENABLED)
    	{
			CFE_ES_PerfLogEntry(TO_SOCKET_SEND_PERF_ID);
			/* Send message via UDP socket */
			s_addr.sin_addr.s_addr = inet_addr(channel->IP);
			s_addr.sin_port        = htons(channel->DstPort);
			status = sendto(channel->Socket, (char *)Buffer, Size, 0,
									(struct sockaddr *) &s_addr,
									 sizeof(s_addr));
			if (status < 0)
			{
				if(errno == 90)
				{
					CFE_EVS_SendEvent(TO_TLMOUTSTOP_ERR_EID,CFE_EVS_ERROR,
								   "L%d TO sendto errno %d.  Message too long.  Size=%u\n", __LINE__, errno, Size);
				}
				else
				{
					CFE_EVS_SendEvent(TO_TLMOUTSTOP_ERR_EID,CFE_EVS_ERROR,
							   "L%d TO sendto errno %d.\n", __LINE__, errno);
					channel->Mode = TO_CHANNEL_DISABLED;
				}
			}
			CFE_ES_PerfLogExit(TO_SOCKET_SEND_PERF_ID);
    	}
    }
}
Exemplo n.º 9
0
void SIMCI_IngestPacket(void) {
    int32 bytes_received;
    uint8 buffer[SIMCI_MAX_INGEST];

    bytes_received = recvfrom(SIMCI_AppData.IngestSocketID, buffer, SIMCI_MAX_INGEST, MSG_DONTWAIT, 0, 0);

    if (bytes_received == ERROR) {
        SIMCI_AppData.HkPacket.ingest_errors++;
        CFE_EVS_SendEvent(SIMCI_INGEST_ERR_EID, CFE_EVS_ERROR, "SIMCI: Error receiving from ingest socket, errno=0x%08X", errno);
    } else if (bytes_received <= SIMCI_MAX_INGEST) {
        CFE_ES_PerfLogEntry(SIMCI_INGEST_RCV_PERF_ID);
        SIMCI_AppData.HkPacket.ingest_packets++;

        /* Send the prepared command out to SB */
        CFE_SB_SendMsg((CFE_SB_MsgPtr_t)buffer);

        CFE_ES_PerfLogExit(SIMCI_INGEST_RCV_PERF_ID);
    } else {
        SIMCI_AppData.HkPacket.ingest_errors++;
        CFE_EVS_SendEvent(SIMCI_INGEST_ERR_EID, CFE_EVS_ERROR, "SIMCI: Dropped problematically lengthy ingest frame of %u bytes", bytes_received);
    }
}
Exemplo n.º 10
0
void HS_IdleTask(void)
{
    OS_time_t PSPTime = {0,0};

    HS_CustomData.IdleTaskRunStatus = CFE_ES_RegisterChildTask();

    while (HS_CustomData.IdleTaskRunStatus == CFE_SUCCESS)
    {

        /* Check to see if we are to mark the time. */
        if(((HS_CustomData.ThisIdleTaskExec & HS_CustomData.UtilMask) == HS_CustomData.UtilMask) &&
           (HS_CustomData.ThisIdleTaskExec > HS_CustomData.UtilMask))
        {
            /* Entry and Exit markers are for easy time marking only; not performance */
            CFE_ES_PerfLogEntry(HS_IDLETASK_PERF_ID);

            /* Increment the child task Execution Counter */
            CFE_ES_IncrementTaskCounter();

            /* update stamp and array */
            CFE_PSP_GetTime(&PSPTime);
            HS_CustomData.UtilArray[HS_CustomData.UtilArrayIndex & HS_CustomData.UtilArrayMask] = (uint32) PSPTime.microsecs;
            HS_CustomData.UtilArrayIndex++;

            CFE_ES_PerfLogExit(HS_IDLETASK_PERF_ID);
        }

        /* Call the Utilization Tracking function */
        HS_UtilizationIncrement();

    }

    /*
    ** If the run status is externally set to something else
    */
    return;

} /* End of HS_IdleTask() */
Exemplo n.º 11
0
void TO_AppMain(void)
{
	int32     iStatus;

	CFE_ES_PerfLogEntry(TO_MAIN_TASK_PERF_ID);

	/* Initialize the TO app*/
	iStatus = TO_AppInit();

	if (iStatus != CFE_SUCCESS)
	{
		TO_AppData.RunStatus= CFE_ES_APP_ERROR;
	}

	/* Application Main Loop */
	while(CFE_ES_RunLoop(&TO_AppData.RunStatus) == TRUE)
	{
		/* Call RecvMsg to pend on sch wakeup msg */
   		TO_RecvMsg(TO_WAKEUP_TIMEOUT);
	}

	/*  Exit the Application */
	CFE_ES_ExitApp(TO_AppData.RunStatus);
}
Exemplo n.º 12
0
int32 TO_RecvMsg( int32 timeout )
{
	int32 iStatus ;

    /*  Performance Log Exit Stamp */
    CFE_ES_PerfLogExit(TO_MAIN_TASK_PERF_ID);

    /* Wait for SCH software bus Wakeup or HK message */
    iStatus = CFE_SB_RcvMsg(&TO_AppData.MsgPtr,
    		                 TO_AppData.SchPipe,
    		                 timeout);
    /* Message received now process message */
    if (iStatus == CFE_SUCCESS)
    {
        TO_ProcessSchMsg();
    }
    else if ( iStatus == CFE_SB_TIME_OUT )
	{
    	/* SCH was probably unloaded or the entry was disabled, causing the
    	 * wakeup to timeout.  Rather than completely blackout all telemetry
    	 * we'll go ahead and send telemetry after the timeout anyway.
    	 */
        TO_OutputStatus();
        TO_ForwardTelemetry(TO_AppData.Config->Timeout);
    }
    else if ( iStatus == CFE_SB_NO_MESSAGE )
    {
        /* nothing to be done if no message is present */
    }

    /* Performance Log Exit Stamp */
    CFE_ES_PerfLogEntry(TO_MAIN_TASK_PERF_ID);

    return iStatus ;

}
Exemplo n.º 13
0
void SC_AppMain(void)
{   
    uint32 RunStatus = CFE_ES_APP_RUN;
    int32 Result;

    /* Register application with cFE */
    Result = CFE_ES_RegisterApp();

    /* Performance Log (start time counter) */
    CFE_ES_PerfLogEntry(SC_APPMAIN_PERF_ID);

    /* Startup initialization */
    if (Result == CFE_SUCCESS)
    {
        Result = SC_AppInit();                  
    }

    /* Check for start-up error */
    if (Result != CFE_SUCCESS)
    {
        /* Set request to terminate main loop */
        RunStatus = CFE_ES_APP_ERROR;
    }

    /* Main process loop */
    while (CFE_ES_RunLoop(&RunStatus))
    {
        /* Performance Log (stop time counter) */
        CFE_ES_PerfLogExit(SC_APPMAIN_PERF_ID);

        /* Pend on Software Bus for message */
        Result = CFE_SB_RcvMsg(&SC_OperData.MsgPtr, SC_OperData.CmdPipe, CFE_SB_PEND_FOREVER);

        /* Performance Log (start time counter) */
        CFE_ES_PerfLogEntry(SC_APPMAIN_PERF_ID);

        /* Check for Software Bus error */
        if (Result == CFE_SUCCESS)
        {
            /* Invoke command handlers */
            SC_ProcessRequest(SC_OperData.MsgPtr);   
        }
        else
        {
            /* Exit main process loop */
            RunStatus = CFE_ES_APP_ERROR;
        }
    }
    
    /* Check for "fatal" process error */
    if (Result !=  CFE_SUCCESS)
    {
        /* Send event describing reason for termination */
        CFE_EVS_SendEvent(SC_APP_EXIT_ERR_EID, CFE_EVS_ERROR,
           "App terminating, Result = 0x%08X", Result);

        /* In case cFE Event Services is not working */
        CFE_ES_WriteToSysLog("SC App terminating, Result = 0x%08X\n", Result);
    }

    /* Performance Log (stop time counter) */
    CFE_ES_PerfLogExit(SC_APPMAIN_PERF_ID);
    
    /* Let cFE kill the app */
    CFE_ES_ExitApp(RunStatus);
    
} /* end SC_AppMain() */
Exemplo n.º 14
0
void SIMCI_TaskMain( void ) {
    int32  Status = CFE_SUCCESS;
    uint32 RunStatus = CFE_ES_APP_RUN;
    struct timeval tv_timeout;
    fd_set readfds;
    int32  max_fd;

    CFE_ES_PerfLogEntry(SIMCI_MAIN_TASK_PERF_ID);

    Status = SIMCI_TaskInit();
    if (Status != CFE_SUCCESS) {
        RunStatus = CFE_ES_APP_ERROR;
    }

    /* Set up information for select */
    max_fd = max(SIMCI_AppData.UplinkSocketID, SIMCI_AppData.IngestSocketID);
    max_fd++;

    tv_timeout.tv_sec = 0;
    tv_timeout.tv_usec = SIMCI_PERIOD_USEC;

    /* Runloop */
    while (CFE_ES_RunLoop(&RunStatus) == TRUE)
    {
        FD_ZERO(&readfds);

        FD_SET(SIMCI_AppData.UplinkSocketID, &readfds);
        FD_SET(SIMCI_AppData.IngestSocketID, &readfds);

        CFE_ES_PerfLogExit(SIMCI_MAIN_TASK_PERF_ID);

        /* Select on the two sockets + SB pipe */
        Status = select(max_fd, &readfds, NULL, NULL, &tv_timeout);

        CFE_ES_PerfLogEntry(SIMCI_MAIN_TASK_PERF_ID);

        if (Status == 0) {
            /* Timed out, process some commands if available */
            uint32 i;

            for (i = 0; i < SIMCI_PIPE_DEPTH; i++) {
                Status = CFE_SB_RcvMsg(&SIMCI_AppData.MsgPtr, SIMCI_AppData.CommandPipe, CFE_SB_POLL);
                if (Status == CFE_SUCCESS) {
                    /* We have a message to process */
                    SIMCI_AppPipe();
                } else if (Status == CFE_SB_NO_MESSAGE) {
                    /* Nothing to do, go back to sleep */
                    break;
                } else {
                    SIMCI_AppData.HkPacket.error_count++;
                    CFE_EVS_SendEvent(SIMCI_PIPE_ERR_EID, CFE_EVS_ERROR, "SIMCI: Error reading command pipe, RC=%08X", Status);
                }
            }
        } else {
            if (FD_ISSET(SIMCI_AppData.UplinkSocketID, &readfds)) {
                SIMCI_ForwardUplinkPacket();
            }
            if (FD_ISSET(SIMCI_AppData.IngestSocketID, &readfds)) {
                SIMCI_IngestPacket();
            }
        }
    }
    CFE_ES_ExitApp(RunStatus);

}
Exemplo n.º 15
0
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void HS_AppMain(void)
{
    int32   Status      = CFE_SUCCESS;
    uint32  RunStatus   = CFE_ES_APP_RUN;

    /*
    ** Performance Log, Start
    */
    CFE_ES_PerfLogEntry(HS_APPMAIN_PERF_ID);

    /*
    ** Register this application with Executive Services
    */
    Status = CFE_ES_RegisterApp();

    /*
    ** Perform application specific initialization
    */
    if (Status == CFE_SUCCESS)
    {
        Status = HS_AppInit();
    }

    /*
    ** If no errors were detected during initialization, then wait for everyone to start
    */
    if (Status == CFE_SUCCESS)
    {
       CFE_ES_WaitForStartupSync(HS_STARTUP_SYNC_TIMEOUT);

       /*
       ** Enable and set the watchdog timer
       */
       CFE_PSP_WatchdogSet(HS_WATCHDOG_TIMEOUT_VALUE);
       CFE_PSP_WatchdogService();
       CFE_PSP_WatchdogEnable();
       CFE_PSP_WatchdogService();

       /*
       ** Subscribe to Event Messages
       */
       if (HS_AppData.CurrentEventMonState == HS_STATE_ENABLED)
       {
          Status = CFE_SB_SubscribeEx(CFE_EVS_EVENT_MSG_MID,
                                      HS_AppData.EventPipe,
                                      CFE_SB_Default_Qos,
                                      HS_EVENT_PIPE_DEPTH);
          if (Status != CFE_SUCCESS)
          {
             CFE_EVS_SendEvent(HS_SUB_EVS_ERR_EID, CFE_EVS_ERROR,
                 "Error Subscribing to Events,RC=0x%08X",Status);
          }
       }
    }

    if (Status != CFE_SUCCESS)
    {
       /*
       ** Set run status to terminate main loop
       */
       RunStatus = CFE_ES_APP_ERROR;
    }

    /*
    ** Application main loop
    */
    while(CFE_ES_RunLoop(&RunStatus) == TRUE)
    {
        /*
        ** Performance Log, Stop
        */
        CFE_ES_PerfLogExit(HS_APPMAIN_PERF_ID);

        /*
        ** Task Delay for a configured timeout
        */
#if HS_POST_PROCESSING_DELAY != 0
        OS_TaskDelay(HS_POST_PROCESSING_DELAY);
#endif

        /*
        ** Task Delay for a configured timeout
        */
        Status = CFE_SB_RcvMsg(&HS_AppData.MsgPtr, HS_AppData.WakeupPipe, HS_WAKEUP_TIMEOUT);

        /*
        ** Performance Log, Start
        */
        CFE_ES_PerfLogEntry(HS_APPMAIN_PERF_ID);

        /*
        ** Process the software bus message
        */
        if ((Status == CFE_SUCCESS) ||
            (Status == CFE_SB_NO_MESSAGE) ||
            (Status == CFE_SB_TIME_OUT))
        {
            Status = HS_ProcessMain();
        }

        /*
        ** Note: If there were some reason to exit the task
        **       normally (without error) then we would set
        **       RunStatus = CFE_ES_APP_EXIT
        */
        if (Status != CFE_SUCCESS)
        {
            /*
            ** Set request to terminate main loop
            */
            RunStatus = CFE_ES_APP_ERROR;
        }

    } /* end CFS_ES_RunLoop while */

    /*
    ** Check for "fatal" process error...
    */
    if (Status != CFE_SUCCESS)
    {
        /*
        ** Send an event describing the reason for the termination
        */
        CFE_EVS_SendEvent(HS_APP_EXIT_EID, CFE_EVS_CRITICAL,
                          "Application Terminating, err = 0x%08X", Status);

        /*
        ** In case cFE Event Services is not working
        */
        CFE_ES_WriteToSysLog("HS App: Application Terminating, ERR = 0x%08X\n", Status);
    }

    HS_CustomCleanup();

    /*
    ** Performance Log, Stop
    */
    CFE_ES_PerfLogExit(HS_APPMAIN_PERF_ID);

    /*
    ** Exit the application
    */
    CFE_ES_ExitApp(RunStatus);

} /* end HS_AppMain */
Exemplo n.º 16
0
void CI_ReadUpLink(void)
{
    socklen_t addr_len;
    int i;
    int status;

    addr_len = sizeof(CI_SocketAddress);

    bzero((char *) &CI_SocketAddress, sizeof(CI_SocketAddress));

    for (i = 0; i <= 10; i++)
    {
        status = recvfrom(CI_SocketID, (char *)&CI_IngestBuffer[0], sizeof(CI_IngestBuffer), MSG_DONTWAIT,
                         (struct sockaddr *) &CI_SocketAddress, &addr_len);

        if ( (status < 0) && (errno == EWOULDBLOCK) )
            break; /* no (more) messages */
        else
        {
            if (status <= CI_MAX_INGEST)
            {
                CCSDS_PriHdr_t *PrimaryHeader = NULL;

                CFE_ES_PerfLogEntry(CI_SOCKET_RCV_PERF_ID);
                CI_HkTelemetryPkt.IngestPackets++;

#ifdef SOFTWARE_LITTLE_BIT_ORDER
                PrimaryHeader = (CCSDS_PriHdr_t*)CI_IngestPointer;
                PrimaryHeader->StreamId = ntohs(PrimaryHeader->StreamId);
                PrimaryHeader->Sequence = ntohs(PrimaryHeader->Sequence);
                PrimaryHeader->Length = ntohs(PrimaryHeader->Length);

                if (CCSDS_SID_TYPE(PrimaryHeader->StreamId) == CCSDS_CMD) {
                    CCSDS_CmdPkt_t *CmdPkt = (CCSDS_CmdPkt_t*)PrimaryHeader;

                    CmdPkt->SecHdr.Command = ntohs(CmdPkt->SecHdr.Command);
                } else {
                    CCSDS_TlmPkt_t *TlmPkt = (CCSDS_TlmPkt_t*)PrimaryHeader;
                    uint32 *SecondsPtr = ((uint32 *)&TlmPkt->SecHdr.Time[0]);
                    uint16 *SubsecondsPtr = ((uint16 *)&TlmPkt->SecHdr.Time[4]);

                    *SecondsPtr = ntohs(*SecondsPtr);
                    *SubsecondsPtr = ntohs(*SubsecondsPtr);
                }
#endif

#ifdef DO_DEBUG
                {
                    /*LOGAN - print out hex command message exactly as it was sent */
                    int i;
                    unsigned char *mpp = (unsigned char*) &CI_IngestPointer[0];
                    for( i=0; i< CFE_SB_GetTotalMsgLength(CI_IngestPointer);  i++ ) { printf("%02x ",  mpp[i] ); }
                    printf("\n");
                }
#endif

                CFE_SB_SendMsg(CI_IngestPointer);
                CFE_ES_PerfLogExit(CI_SOCKET_RCV_PERF_ID);
            }
            else
            {
                CI_HkTelemetryPkt.IngestErrors++;
                CFE_EVS_SendEvent(CI_INGEST_ERR_EID,CFE_EVS_ERROR, "CI: L%d, cmd %0x %0x dropped, too long\n", __LINE__, *(long *)CI_IngestBuffer, *(long *)(CI_IngestBuffer+4) );
            }
        }
    }

    return;

} /* End of CI_ReadUpLink() */