示例#1
0
/******************************************************************************
**  Function:  UTF_add_volume()
**
**  Purpose:
**    Configures the Volume Table for filesystem calls.  Each call to this function
**    will add another entry to the Volume Table.
**
**    There are two ways to configure the filesystem,
**        1. by making a single call to UTF_add_volume to set everything
**        2. by making a call to UTF_add_volume to set only the device name and physical device and then call OS_mkfs and OS_mount
**           The only time you would want to use option 2 is where the task you are testing calls OS_mkfs and OS_mount.  Most of
**           the time the system will do this for you on startup.
**
**    Option 1
**    - adds the device "/nonvol0"
**    - maps the filesystem to a directory "tmp" in the current working directory
**    - is filesystem based
**    - is not volatile
**    - is not free
**    - is mounted
**    - the volume name is "CF"
**    - the virtual filesystem is "/cf", i.e. references to the virtual directory "/cf" get translated
**      to the physical directory "tmp/nonvol0/".  Note that this directory should already exist.
**    - block size is 0
**
**      UTF_add_volume("/nonvol0", "tmp", FS_BASED, FALSE, FALSE, TRUE, "CF", "/cf", 0);
**
**    Option 2
**    - adds the device "/nonvol0"
**    - maps the filesystem to a directory "tmp" in the current working directory
**    - is filesystem based
**    - is not volatile
**    - is free - needed for OS_mkfs
**    - is not mounted - needed for OS_mount
**    - the volume name is " " - set by OS_mkfs
**    - the virtual filesystem is " ", - set by OS_mount
**    - block size is 0
**
**      UTF_add_volume("/nonvol0", "tmp", FS_BASED, FALSE, TRUE, FALSE, " ", " ", 0);
**      status = OS_mkfs(0, "/nonvol0", "CF", 0, 0);
**      status = OS_mount("/nonvol0", "/cf");
*/
void UTF_add_volume(char *DeviceName, char *PhysDevName, uint32 VolumeType, uint8 VolatileFlag,
                    uint8 FreeFlag, uint8 IsMounted, char *VolumeName, char *MountPoint, uint32 BlockSize)
{
    int i;

    if (strlen(DeviceName) > 32)
        UTF_error("Add Volume DeviceName Too Long MAX:32 ACT:%d", strlen(DeviceName));
    else if (strlen(PhysDevName) > 32)
        UTF_error("Add Volume PhysDevName Too Long MAX:32 ACT:%d", strlen(PhysDevName));
    else if (strlen(VolumeName) > 32)
        UTF_error("Add Volume VolumeName Too Long MAX:32 ACT:%d", strlen(VolumeName));
    else if (strlen(MountPoint) > 64)
        UTF_error("Add Volume MountPoint Too Long MAX:32 ACT:%d", strlen(MountPoint));

    /* find an open entry in the Volume Table */
    for (i=0; i < NUM_TABLE_ENTRIES; i++)
    {
        if (OS_VolumeTable[i].FreeFlag == TRUE) {
            strcpy(OS_VolumeTable[i].DeviceName, DeviceName);
            strcpy(OS_VolumeTable[i].PhysDevName, PhysDevName);
            OS_VolumeTable[i].VolumeType = VolumeType;
            OS_VolumeTable[i].VolatileFlag = VolatileFlag;
            OS_VolumeTable[i].IsMounted = IsMounted;
            strcpy(OS_VolumeTable[i].VolumeName, VolumeName);
            strcpy(OS_VolumeTable[i].MountPoint, MountPoint);
            OS_VolumeTable[i].BlockSize = BlockSize;
            OS_VolumeTable[i].FreeFlag = FreeFlag;
            return;
        }
    }

    UTF_error("Volume Table Full");
}
示例#2
0
/******************************************************************************
**  Function: UTF_queue_add()
**
**  Purpose:
**    This function adds an entry to the queue.
*/
void UTF_queue_add (CFE_SB_PipeId_t PipeId, const void *data, size_t length)
{
   utf_queue_type *queue = UTF_lookup_queue (PipeId);
   int             next_head;

   if (queue == NULL)
      UTF_error ("Queue Not Found For source_id %lu\n", PipeId);

   next_head = (queue->head + 1) % UTF_QUEUE_SIZE;

   if (length > UTF_BUFFER_SIZE)
   {
      UTF_error ("Buffer Request For %d Bytes Exceeds UTF_BUFFER_SIZE.\n", length);
   }

   if (next_head == queue->tail)
   {
      UTF_error ("Queue Full, source_id %lu\n", PipeId);
   }

   queue->buffers[queue->head].data = UTF_get_buffer();
   if (queue->buffers[queue->head].data == NULL) {
      UTF_error ("Queue Buffer Allocation Error, Not Enough Buffers (UTF_NUMBER_OF_BUFFERS)\n");
   }

   memcpy(queue->buffers[queue->head].data, data, length);

   queue->buffers[queue->head].length = length;

   queue->head = next_head;

}
示例#3
0
/******************************************************************************
**  Function: UTF_get_input_fc()
**
**  Purpose:
**    This routine returns a input file context structure for the specified source_id.
**    if the source_id is specified in the file_descriptor_table then the corresponding
**    file context will be returned, otherwise if the source_id is not found in the
**    file_descriptor_table then the default "sbsim.in" file context will be used.  Files
**    are opened the first time this routine is called for each source_id.
*/
utf_file_context_type *UTF_get_input_fc(unsigned long source_id)
{

    unsigned short int  i;

    /* search the file descriptor table for a matching source_id.  if found
       then either open the file if not already open or return the already open
       file context.  If no match is found in the descriptor table then use
       the default file context for the file "sbsim.in" */
    for (i=0; i < file_descriptor_count; i++)
    {
        if (source_id == file_descriptor_table[i].source_id)
        {
            if (file_descriptor_table[i].file_context.fd == NULL)
            {
                file_descriptor_table[i].file_context.fd = fopen(file_descriptor_table[i].file_context.filename, "r");
                if (file_descriptor_table[i].file_context.fd == NULL) {

                    UTF_error("Error Opening Input File %s", file_descriptor_table[i].file_context.filename);
                }
            }
            return(&file_descriptor_table[i].file_context);
        }
    }

    /* no matching source_id in the descriptor table so use the default */

#ifdef UTF_USE_STDIN

    if (default_fc_in.fd == NULL) {

        default_fc_in.filename = "stdin";
        default_fc_in.fd = stdin;
        default_fc_in.line_number = 1;
    }
    return &default_fc_in;

#else

    if (default_fc_in.fd == NULL) {

        default_fc_in.filename = "sbsim.in";
        default_fc_in.fd = fopen("sbsim.in", "r");
        if (default_fc_in.fd == NULL) {
            UTF_error("Error Opening Input File sbsim.in");
        }
        default_fc_in.line_number = 1;
    }
    return &default_fc_in;

#endif

}
示例#4
0
/******************************************************************************
**  Function: UTF_get_output_fc()
**
**  Purpose:
**    Return a output file context. The output file is opened the first time this
**    routine is called.
*/
utf_file_context_type *UTF_get_output_fc (void)
{

#ifdef UTF_USE_STDOUT

    if (default_fc_out.fd == NULL) {

        default_fc_out.filename = "stdout";
        default_fc_out.fd = stdout;
        default_fc_out.line_number = 0;
    }
    return &default_fc_out;

#else

    if (default_fc_out.fd == NULL) {

        default_fc_out.filename = output_filename;
        default_fc_out.fd = fopen(output_filename, "w");
        if (default_fc_out.fd == NULL) {
            UTF_error("Error Opening Output File %s", output_filename);
        }
        default_fc_out.line_number = 0;
    }
    return &default_fc_out;

#endif

}
/******************************************************************************
**  Function: UTF_PSP_set_function_hook()
**
**  Purpose:
**    Install a user defined hook function for a CFE_PSP function call.
*/
void UTF_PSP_set_function_hook(int Index, void *FunPtr)
{
    if (Index == CFE_PSP_EEPROMWRITE8_HOOK) { UTF_PSP_HookTable.CFE_PSP_EepromWrite8 = FunPtr; }
    else if (Index == CFE_PSP_EEPROMWRITE16_HOOK) { UTF_PSP_HookTable.CFE_PSP_EepromWrite16 = FunPtr; }
    else if (Index == CFE_PSP_EEPROMWRITE32_HOOK) { UTF_PSP_HookTable.CFE_PSP_EepromWrite32 = FunPtr; }
    else { UTF_error("Invalid PSP Hook Index In Set Hook Call %d", Index); }
}
示例#6
0
/******************************************************************************
**  Function: UTF_SB_set_function_hook()
**
**  Purpose:
**    Install a user defined hook function for a SB function call.
*/
void UTF_SB_set_function_hook(int Index, void *FunPtr)
{
    if      (Index == CFE_SB_SUBSCRIBE_HOOK)   { UTF_SB_HookTable.CFE_SB_Subscribe = FunPtr; }
    else if (Index == CFE_SB_SUBSCRIBEEX_HOOK) { UTF_SB_HookTable.CFE_SB_SubscribeEx = FunPtr; }
    else if (Index == CFE_SB_CREATEPIPE_HOOK)  { UTF_SB_HookTable.CFE_SB_CreatePipe = FunPtr; }
    else if (Index == CFE_SB_DELETEPIPE_HOOK)  { UTF_SB_HookTable.CFE_SB_DeletePipe = FunPtr; }
    else                                       { UTF_error("Invalid SB Hook Index In Set Hook Call %d", Index); }
}
/******************************************************************************
**  Function: UTF_ES_set_function_hook()
**
**  Purpose:
**    Install a user defined hook function for an ES function call.
*/
void UTF_ES_set_function_hook(int Index, void *FunPtr)
{
    if      (Index == CFE_ES_POOLCREATE_HOOK)       { UTF_ES_HookTable.CFE_ES_PoolCreate = FunPtr; }
    else if (Index == CFE_ES_POOLCREATENOSEM_HOOK)  { UTF_ES_HookTable.CFE_ES_PoolCreateNoSem = FunPtr; }
    else if (Index == CFE_ES_GETPOOLBUF_HOOK)       { UTF_ES_HookTable.CFE_ES_GetPoolBuf = FunPtr; }
    else if (Index == CFE_ES_PUTPOOLBUF_HOOK)       { UTF_ES_HookTable.CFE_ES_PutPoolBuf = FunPtr; }
    else                                            { UTF_error("Invalid ES Hook Index In Set Hook Call %d", Index); }
}
示例#8
0
/******************************************************************************
**  Function: UTF_queue_empty()
**
**  Purpose:
**    This function checks to see if the specified queue is empty.  Returns
**    TRUE if empty.
*/
char UTF_queue_empty (CFE_SB_PipeId_t PipeId)
{
   const utf_queue_type *queue     = UTF_lookup_queue (PipeId);

   if (queue == NULL)
      UTF_error ("Queue Not Found For source_id %lu\n", PipeId);

   return queue->head == queue->tail;
}
示例#9
0
/******************************************************************************
**  Function: UTF_add_input_queue()
**
**  Purpose:
**    This function maps a source_id to a queue by adding a new entry to the
**    file_descriptor_table.
*/
void UTF_add_input_queue(unsigned long PipeId)
{
    if (file_descriptor_count >= UTF_FD_TABLE_SIZE) { /* 0 based array */
        UTF_error("Maximum Number of Input Sources Exceeded, Max: %d", UTF_FD_TABLE_SIZE);
    }
    else if (queue_table_count > UTF_QUEUE_COUNT) { /* 1 based array */
        UTF_error("Maximum Number of Input Queues Exceeded, Max: %d", UTF_QUEUE_COUNT);
    }
    else {
        file_descriptor_table[file_descriptor_count].source_id = PipeId;
        file_descriptor_table[file_descriptor_count].queue_id = queue_table_count + 1;  /* index into queue_table, must be > 0 */
        file_descriptor_table[file_descriptor_count].file_context.filename = NULL;      /* not used for queues */
        file_descriptor_table[file_descriptor_count].file_context.fd = NULL;            /* not used for queues */
        file_descriptor_table[file_descriptor_count].file_context.line_number = 0;      /* not used for queues */
        file_descriptor_count++;
        queue_table_count++;
    }
}
示例#10
0
/******************************************************************************
**  Function: UTF_set_write_sim_hook()
**
**  Purpose:
**    This function sets a custom sim mem write hook.
*/
void UTF_set_write_sim_hook(utf_write_sim_hook_type hook)
{
    if (hook != NULL) {

        write_sim_hook = hook;
    }
    else {
        UTF_error("Sim Mem Write Sim Hook Function Pointer is NULL");
    }
}
示例#11
0
/******************************************************************************
**  Function: UTF_set_read_sim_hook()
**
**  Purpose:
**    This function sets a custom sim mem read hook.
*/
void UTF_set_read_sim_hook(utf_read_sim_hook_type hook)
{
    if (hook != NULL) {

        read_sim_hook = hook;
    }
    else {
        UTF_error("Sim Mem Read Sim Hook Function Pointer is NULL");
    }
}
示例#12
0
/******************************************************************************
**  Function: UTF_add_special_command()
**
**  Purpose:
**    This function adds a special command to the special command lookup table.
*/
void UTF_add_special_command(char *name, utf_special_command_type function)
{

    if (function != NULL) {

        if (special_command_count < UTF_SPECIAL_COMMAND_TABLE_SIZE) {

            special_command_table[special_command_count].name = name;
            special_command_table[special_command_count].function = function;
            special_command_count++;
        }
        else {
            UTF_error("Maximum Number of Special Commands Exceeded, Max: %d", UTF_SPECIAL_COMMAND_TABLE_SIZE);
        }
    }
    else {
        UTF_error("Special Command Function Pointer is NULL, %s", name);
    }
}
示例#13
0
/******************************************************************************
**  Function: UTF_queue_get()
**
**  Purpose:
**    This function removes an entry from the queue.  If the queue is empty this
**    routine will assert an error so it is a good idea to check the queue using the
**    UTF_queue_empty routine first to be sure there is something available.
*/
void UTF_queue_get (CFE_SB_PipeId_t PipeId, void *buffer)
{
   utf_queue_type *queue = UTF_lookup_queue (PipeId);
   int             next_tail;

   if (queue == NULL)
      UTF_error ("Queue Not Found For source_id %lu\n", PipeId);

   next_tail = (queue->tail + 1) % UTF_QUEUE_SIZE;

   memcpy(buffer, queue->buffers[queue->tail].data, queue->buffers[queue->tail].length);
   UTF_release_buffer(queue->buffers[queue->tail].data);

   if (queue->head == queue->tail)
   {
      UTF_error ("Queue Empty, source_id %lu\n", PipeId);
   }

   queue->tail = next_tail;

}
示例#14
0
/******************************************************************************
**  Function: UTF_process_special_command()
**
**  Purpose:
**    This function executes a special command.
*/
void UTF_process_special_command(utf_file_context_type *fc, char *command_line)
{

    utf_special_command_type    func;
    int                         argc;
    char                        *argv[UTF_SPECIAL_COMMAND_MAX_ARGS];

    split_line(command_line, &argc, argv);
    if (argc > 0) {

        func = UTF_special_command_lookup(argv[0]);  /* argv[0] is the name of the special command */
        if (func) {
            (*func)(argc, argv);
        }
        else {
            UTF_error("File: %s, Line: %d, Special Command Not Found, %s", fc->filename, fc->line_number, argv[0]);
        }
    }
    else {
        UTF_error("File: %s, Line: %d, Special Command Name Is Missing", fc->filename, fc->line_number);
    }
}
示例#15
0
/******************************************************************************
**  Function: UTF_add_input_file()
**
**  Purpose:
**    This function maps a source_id to a text file by adding a new entry to the
**    file_descriptor_table.
*/
void UTF_add_input_file(unsigned long source_id, char *filename)
{
    if (file_descriptor_count < UTF_FD_TABLE_SIZE) {
        file_descriptor_table[file_descriptor_count].source_id = source_id;
        file_descriptor_table[file_descriptor_count].queue_id = 0;          /* not used for files */
        file_descriptor_table[file_descriptor_count].file_context.filename = filename;
        file_descriptor_table[file_descriptor_count].file_context.fd = NULL;
        file_descriptor_table[file_descriptor_count].file_context.line_number = 1;
        file_descriptor_count++;
    }
    else {
        UTF_error("Maximum Number of Input Sources Exceeded, Max: %d", UTF_FD_TABLE_SIZE);
    }
}
示例#16
0
/******************************************************************************
**  Function: UTF_add_sim_address()
**
**  Purpose:
**    This function adds a memory segment to the sim mem lookup table.
*/
void UTF_add_sim_address(unsigned long start, unsigned long size, char *name)
{
    if (sim_address_count < UTF_SIM_MEM_LOOKUP_TABLE_SIZE) {

        if (size > 0) {

            sim_memory_lookup_table[sim_address_count].start = start;
            sim_memory_lookup_table[sim_address_count].size = size;
            sim_memory_lookup_table[sim_address_count].name = name;
            sim_memory_lookup_table[sim_address_count].memory = malloc(size);
            if (sim_memory_lookup_table[sim_address_count].memory == NULL) {
                UTF_error("Sim Mem Error Allocating Sim Memory Space, Address 0X%x, Bytes %d", start, size);
            }
            memset (sim_memory_lookup_table[sim_address_count].memory, 0, size);
            sim_address_count++;
        }
        else {
            UTF_error("Sim Mem Memory Segment Size is 0, Address: 0X%x", start);
        }
    }
    else {
        UTF_error("Sim Mem Maximum Number of Memory Addresses Exceeded, Max: %d", UTF_SIM_MEM_LOOKUP_TABLE_SIZE);
    }
}
示例#17
0
void UTF_SCRIPT_LoadTableFromGround(int argc, char *argv[]) {
    char Table_Name[30], File_Name[50];
    /*	UTF_put_text("Entered UTF_SCRIPT_LoadTableFromGround\n"); */
    if (argc != 3) {
        UTF_error("Error: Read %d args w/script cmd LOAD_TABLE_FROM_GROUND. Expected 2.\n", argc - 1);
        UTF_exit();
    }

    strcpy(Table_Name, argv[1]);
    strcpy(File_Name, argv[2]);
    UTF_put_text("Table_Name is %s\n", Table_Name);
    UTF_put_text("File_Name is %s\n", File_Name);
    UTF_TBL_LoadTableFromGround(Table_Name, File_Name);
    return;
}
示例#18
0
void not_working(void)
{
	/* I never got this to work with the 'open' function call, */
	/* & so used fopen instead.  See Create_input_File0       */
	int to;
	int8 values[4] = {5,10,15,20};
	to = open("/ram/tt_table_initial_values.dat",  O_WRONLY | O_CREAT, 0644);
	if (to < 0)
	{
		UTF_error("Error opening file /tt_table_initial_values.dat to write\n");
		UTF_exit();
	}

	write(to, values, 4);	
	
	close(to);
}
示例#19
0
void UTF_SCRIPT_SB_Use_Default_Api_Return_Code(int argc,char *argv[])
{
    int32 Index;

    /* Check for correct number of arguments */
    if (argc != 2)
    {
        UTF_error("UTF Error: Read %d args w/script cmd UTF_SCRIPT_SB_Set_Api_Return_Code. Expected 1.\n", argc -1 );
        UTF_exit();
    }

    /* Extract argument values */
    Index = UTF_arg2dbl(argv[1]);

    /* Call function to set API return code */
    UTF_CFE_SB_Set_Api_Return_Code(Index, UTF_CFE_USE_DEFAULT_RETURN_CODE);
    return;
}
示例#20
0
void UTF_SCRIPT_EVS_Set_Api_Return_Code(int argc,char *argv[])
{
    int32 Index;
    int32 Code;
	/* Check for correct number of arguments */
	if (argc != 3)
	{
	   UTF_error("UTF Error: Read %d args w/script cmd UTF_SCRIPT_EVS_Set_Api_Return_Code. Expected 2.\n",
	   argc -1 );
	   UTF_exit();
	}
    /* Extract argument values */
    Index = UTF_arg2dbl(argv[1]);
    Code  = UTF_arg2uint(argv[2]);
    /* Call function to set API return code */
	UTF_CFE_EVS_Set_Api_Return_Code(Index, Code);
	return;
}
示例#21
0
/******************************************************************************
**  Function: UTF_put_data()
**
**  Purpose:
**    This routine writes a data buffer to the output file.  It will write length
**    bytes of data as hex digits.  The data_type determines how the data should
**    be interpreted.  This is done to make the printed output easier to read
*/
void UTF_put_data(void *buffer, unsigned short int length, unsigned short int data_type)
{
    FILE               *fd;
    unsigned short int  i;
    unsigned long int  *dword_ptr = (unsigned long int *)buffer;
    unsigned short int *word_ptr  = (unsigned short int *)buffer;
    unsigned char      *byte_ptr  = (unsigned char *)buffer;

    fd = UTF_get_output_fd();

    switch(data_type)
    {
        case UTF_AS_BYTE:

            for (i=0; i < length; i++)
            {
                fprintf(fd, "%02x ", *byte_ptr++);
            }
            fprintf(fd, "\n");
            break;

        case UTF_AS_WORD:

            for (i=0; i < length; i+=2)
            {
                fprintf(fd, "%04x ", *word_ptr++);
            }
            fprintf(fd, "\n");
            break;

        case UTF_AS_DWORD:

            for (i=0; i < length; i+=4)
            {
                fprintf(fd, "%08lx ", *dword_ptr++);
            }
            fprintf(fd, "\n");
            break;

        default:
            UTF_error("Invalid data_type For Write, %d", data_type);
            break;
    }
}
示例#22
0
/******************************************************************************
**  Function: UTF_set_output_filename()
**
**  Purpose:
**    This function sets the name of the output file.
*/
void UTF_set_output_filename(char *filename)
{
	/* Check if a current file is open */
    if (default_fc_out.fd != NULL) {
    	fclose(default_fc_out.fd);
    	default_fc_out.fd = NULL;
    }

	/* Check if the filename is not null */
	if (filename != "") {
	  output_filename = filename;
      default_fc_out.filename = output_filename;
      default_fc_out.fd = fopen(output_filename, "w");
      if (default_fc_out.fd == NULL) {
        UTF_error("Error Opening Output File %s", output_filename);
      }
      default_fc_out.line_number = 0;
	}
}
示例#23
0
void UTF_SCRIPT_LoadTableFromGround(int argc,char *argv[])
{
    int debug = 1;
    int32 status;
    char Table_Name[30], File_Name[50];
    if (argc != 3)
    {
       UTF_error("Error: Read %d args w/script cmd LOAD_TABLE_FROM_GROUND. Expected 2.\n",
	   argc -1 );
       UTF_exit();
    }

   strcpy(Table_Name,argv[1]);
   strcpy(File_Name,argv[2]);
   if (debug) 
      UTF_put_text("UTF_SCRIPT_LoadTableFromGround called for Table_Name = '%s', File_Name = '%s'\n",
                   Table_Name, File_Name); 
   status = UTF_TBL_LoadTableFromGround(Table_Name, File_Name);
   if (debug) UTF_put_text("UTF_TBL_LoadTableFromGround returned %d", status);
   return;
}
示例#24
0
/******************************************************************************
** Name:    CFE_SB_RcvMsg
**
** Purpose: Simulates the API used to receive a message from the software bus.
**
** Assumptions, External Events, and Notes:
**          None
**
** Routines Called:
**          UTF_get_buffer
**          UTF_get_data
**          UTF_put_packet
**
** Date Written:
**          07/25/2005
**
** Input Arguments:
**          PipeId
**          BufPtr
**          timeOut - CFE_SB_PEND, CFE_SB_POLL or millisecond timeout
**
** Output Arguments:
**          None
**
** Return Values:
**          Status
**
******************************************************************************/
int32  CFE_SB_RcvMsg(CFE_SB_MsgPtr_t  *BufPtr,
                     CFE_SB_PipeId_t  PipeId,
                     int32            TimeOut)
{
    boolean     status;
    static void *temp = NULL;

    /* Grab a buffer from the buffer_table the first time CFE_SB_RcvMsg */
	/* is called.  This buffer is reused for the remaining calls.       */
    if (temp == NULL)
	{
        temp = (void *)UTF_get_buffer();
		if (temp == NULL)
			UTF_error("UTF_get_buffer returned null\n");
    }

    /* Assign the caller's pointer to point to our allocated buffer */
    *BufPtr = temp;

    status = UTF_get_data(PipeId, *BufPtr, UTF_BUFFER_SIZE, UTF_AS_WORD);
    if (status == TRUE) /* Message was received */
    {
        /* UTF_put_packet, in utf_sb.c, displays packet */
        UTF_put_packet (UTF_SOURCE_RECEIVE, (CCSDS_PriHdr_t *)*BufPtr);

	    /* Handle Preset & Special Return Codes */
        if ((cfe_sb_api_return_value[CFE_SB_RCVMSG_PROC] != UTF_CFE_USE_DEFAULT_RETURN_CODE) &&
        	(cfe_sb_api_return_value[CFE_SB_RCVMSG_PROC] != UTF_CFE_SB_RCVMSG_EXIT_RETURN_CODE))
   	    {
            return cfe_sb_api_return_value[CFE_SB_RCVMSG_PROC];
        }

        return(CFE_SUCCESS);
    }
    else /* no data available */
    {
    	/* Arrive here when empty pipe is indicated in test script*/

	    /* Handle Preset & Special Return Codes */
        if ((cfe_sb_api_return_value[CFE_SB_RCVMSG_PROC] != UTF_CFE_USE_DEFAULT_RETURN_CODE) &&
        	(cfe_sb_api_return_value[CFE_SB_RCVMSG_PROC] != UTF_CFE_SB_RCVMSG_EXIT_RETURN_CODE))
   	    {
            return cfe_sb_api_return_value[CFE_SB_RCVMSG_PROC];
        }

		/*  Handle default behavior for empty pipe indication */
        switch (TimeOut)
        {
        case CFE_SB_PEND_FOREVER:
		    /* Handle Special Return Code */
		    /* This code must be explicitly set by the caller.
		     * This will exit the test process */
    	    if (cfe_sb_api_return_value[CFE_SB_RCVMSG_PROC] == UTF_CFE_SB_RCVMSG_EXIT_RETURN_CODE)
    	    {
    	    	UTF_exit();
    	    }
	        return CFE_SB_NO_MESSAGE;
            break;

        case CFE_SB_POLL:
            return CFE_SB_NO_MESSAGE;
            break;

        default:
            return CFE_SB_TIME_OUT;
            break;
        }
    }
} /* end CFE_SB_RcvMsg */
示例#25
0
/******************************************************************************
**  Function: read_hex_data()
**
**  Purpose:
**    This routine reads hex digits from the file specified by fc and places the
**    data in the buffer specified by the void buffer pointer.  The software will
**    read data until it hits the end of the line or it has read max_bytes of data.
**    Note that his code assumes that there will be only one data item (packet) per line.
*/
static void read_hex_data(utf_file_context_type *fc, void *buffer, unsigned short int max_bytes, unsigned short int data_type)
{

    unsigned short int  i;
    unsigned short int  bytes_read = 0;
    unsigned long int   *dword_ptr = (unsigned long int *)buffer;
    unsigned short int  *word_ptr  = (unsigned short int *)buffer;
    unsigned char       *byte_ptr  = (unsigned char *)buffer;

    switch(data_type) {

        /* assumes that 1 NUMBER token has already been read prior to calling this routine */

        case UTF_AS_BYTE:

            while ((token != END_OF_LINE) && (bytes_read < max_bytes)) {

                *byte_ptr = 0;

                for (i=0; i < 2; i++) {
                    if (token == END_OF_LINE) UTF_error("File: %s, Line: %d, Not Enough Characters For AS_BYTE Read", fc->filename, fc->line_number-1);
                    if (token != NUMBER)      UTF_error("File: %s, Line: %d, Invalid Hex Number Read", fc->filename, fc->line_number);
                    *byte_ptr = (*byte_ptr << 4) + c_to_hex(number_token);
                    token = get_token(fc);
                }

                bytes_read += 1;
                byte_ptr++;
            }

            if ((token != END_OF_LINE) && (bytes_read >= max_bytes))
                UTF_error("File: %s, Line: %d, Input Data Exceeds Max Size of %d", fc->filename, fc->line_number, max_bytes);

            break;

        case UTF_AS_WORD:

            if ((max_bytes % 2) != 0) UTF_error("File: %s, Line: %d, Invalid Max_Bytes Parameter For AS_WORD Read, %d", fc->filename, fc->line_number, max_bytes);

            while ((token != END_OF_LINE) && (bytes_read < max_bytes)) {

                *word_ptr = 0;

                for (i=0; i < 4; i++) {
                    if (token == END_OF_LINE) UTF_error("File: %s, Line: %d, Not Enough Characters For AS_WORD Read", fc->filename, fc->line_number-1);
                    if (token != NUMBER)      UTF_error("File: %s, Line: %d, Invalid Hex Number Read", fc->filename, fc->line_number);
                    *word_ptr = (*word_ptr << 4) + c_to_hex(number_token);
                    token = get_token(fc);
                }

                bytes_read += 2;
                word_ptr++;
            }

            if ((token != END_OF_LINE) && (bytes_read >= max_bytes))
                UTF_error("File: %s, Line: %d, Input Data Exceeds Max Size of %d", fc->filename, fc->line_number, max_bytes);

            break;

        case UTF_AS_DWORD:

            if ((max_bytes % 4) != 0) UTF_error("File: %s, Line: %d, Invalid Max_Bytes Parameter For AS_DWORD Read, %d", fc->filename, fc->line_number, max_bytes);

            while ((token != END_OF_LINE) && (bytes_read < max_bytes)) {

                *dword_ptr = 0;

                for (i=0; i < 8; i++) {
                    if (token == END_OF_LINE) UTF_error("File: %s, Line: %d, Not Enough Characters For AS_DWORD Read", fc->filename, fc->line_number-1);
                    if (token != NUMBER)      UTF_error("File: %s, Line: %d, Invalid Hex Number Read", fc->filename, fc->line_number);
                    *dword_ptr = (*dword_ptr << 4) + c_to_hex(number_token);
                    token = get_token(fc);
                }

                bytes_read += 4;
                dword_ptr++;
            }

            if ((token != END_OF_LINE) && (bytes_read >= max_bytes))
                UTF_error("File: %s, Line: %d, Input Data Exceeds Max Size of %d", fc->filename, fc->line_number, max_bytes);

            break;

        default:
            UTF_error("File: %s, Line: %d, Invalid DATA_TYPE For Read, %d", fc->filename, fc->line_number, data_type);
            break;
    }
}
示例#26
0
/******************************************************************************
**  Function: get_token()
**
**  Purpose:
**    This routine parses a input text file looking for tokens.  To sipmlify things
**    all tokens are single characters. The following tokens are recognized:
**    \n = END_OF_LINE
**    !  = NO_DATA
**    *  = LABEL
**    @  = SPECIAL_COMMAND
**    ;  = comment which extends to the end of the line
**    hex digit = interpreted as a data set which extends to the end of the line
**    all spaces and unrecognized characters are skipped
*/
static unsigned short int get_token(utf_file_context_type *fc)
{

    char                ch;
    unsigned short int  i;

    while (TRUE) {

        /* skip blank spaces */
        do {
            if ((ch = fgetc(fc->fd)) == EOF) { cleanup(); }
        } while (isspace(ch) && ch != '\n');

        switch (ch) {

            case '\n':                  /* end of line */
                fc->line_number++;
                return(END_OF_LINE);
                break;

            case '!':                   /* no more packets on this pipe */
                return(NO_DATA);
                break;

            case '*':                   /* label */
                for (i=0; i < UTF_STRING_TOKEN_SIZE; i++) {
                    if ((ch = fgetc(fc->fd)) == EOF)  { cleanup(); }
                    else if (ch == '\n' || ch == ';') { ungetc(ch, fc->fd); string_token[i] = '\0'; return(LABEL); }
                    else                              { string_token[i] = ch; }
                }
                UTF_error("File: %s, Line: %d, Label Exceeds %d Characters, %s", fc->filename, fc->line_number, UTF_STRING_TOKEN_SIZE, string_token);
                break;

            case '@':                   /* special command */
                for (i=0; i < UTF_STRING_TOKEN_SIZE; i++) {
                    if ((ch = fgetc(fc->fd)) == EOF)  { cleanup(); }
                    else if (ch == '\n' || ch == ';') { ungetc(ch, fc->fd); string_token[i] = '\0'; return(SPECIAL_COMMAND); }
                    else                              { string_token[i] = ch; }
                }
                UTF_error("File: %s, Line: %d, Special Command Exceeds %d Characters, %s", fc->filename, fc->line_number, UTF_STRING_TOKEN_SIZE, string_token);
                break;

            case ';':                   /* comment extends to the end of the line */
                do {
                    if ((ch = fgetc(fc->fd)) == EOF) cleanup();
                } while (ch != '\n');
                ungetc(ch, fc->fd);
                break;

            case '0':                   /* hex digit */
            case '1':
            case '2':
            case '3':
            case '4':
            case '5':
            case '6':
            case '7':
            case '8':
            case '9':
            case 'A':
            case 'B':
            case 'C':
            case 'D':
            case 'E':
            case 'F':
            case 'a':
            case 'b':
            case 'c':
            case 'd':
            case 'e':
            case 'f':
                number_token = ch;
                return(NUMBER);
                break;

            default:                    /* skip unrecognized chars */
                break;
        }
    }
}