Example #1
0
/* Reads the body of an RT packet from the network */
static int rt_read_data_packet(libtrace_t *libtrace,
		libtrace_packet_t *packet, int blocking) {
	uint32_t prep_flags = 0;

	prep_flags |= TRACE_PREP_DO_NOT_OWN_BUFFER;

	/* The stored RT header will tell us how much data we need to read */
	if (rt_read(libtrace, &packet->buffer, (size_t)RT_INFO->rt_hdr.length, 
				blocking) != RT_INFO->rt_hdr.length) {
		return -1;
	}

	/* Send an ACK if required */
        if (RT_INFO->reliable > 0 && packet->type >= TRACE_RT_DATA_SIMPLE) {
		if (rt_send_ack(libtrace, RT_INFO->rt_hdr.sequence) == -1)
                               	return -1;
	}
	
	/* Convert to the original capture format */
	if (rt_set_format(libtrace, packet) < 0) {
		return -1;
        }
               	
	/* Update payload pointers and packet type to match the original
	 * format */
	if (trace_prepare_packet(packet->trace, packet, packet->buffer,
				packet->type, prep_flags)) {
		return -1;
	}

	return 0;
}
Example #2
0
uint8 _create_timestamp(RT_DATA **timestamp)
{
    RT_DATA *new_timestamp;
    uint8 result;
    
    new_timestamp = malloc(sizeof(*new_timestamp));
    
    if (new_timestamp != NULL)
    {
        result = rt_read(new_timestamp);
        
        if (result == RT_SUCCESS)
        {
            *timestamp = new_timestamp;
        }
    }
    else
    {
        result = ER_NO_MEMORY;
    }
    
    return result;
}
Example #3
0
/* Reads an RT packet from the network. Will block if the "blocking" flag is
 * set to 1, otherwise will return if insufficient data is available */
static int rt_read_packet_versatile(libtrace_t *libtrace,
		libtrace_packet_t *packet,int blocking) {
	rt_header_t *pkt_hdr = NULL;
	void *void_hdr;
	libtrace_rt_types_t switch_type;
	
	if (packet->buf_control == TRACE_CTRL_PACKET) {
		packet->buf_control = TRACE_CTRL_EXTERNAL;
		free(packet->buffer);
		packet->buffer = NULL;
	}

	/* RT_LAST indicates that we need to read the RT header for the next
	 * packet. This is a touch hax, I admit */
	if (RT_INFO->rt_hdr.type == TRACE_RT_LAST) {
		void_hdr = (void *)pkt_hdr;
		/* FIXME: Better error handling required */
		if (rt_read(libtrace, &void_hdr, 
				sizeof(rt_header_t),blocking) !=
				sizeof(rt_header_t)) {
			return -1;
		}
		pkt_hdr = (rt_header_t *)void_hdr;
		
		/* Need to store these in case the next rt_read overwrites 
		 * the buffer they came from! */
		RT_INFO->rt_hdr.type = pkt_hdr->type;
		RT_INFO->rt_hdr.length = pkt_hdr->length;
		RT_INFO->rt_hdr.sequence = pkt_hdr->sequence;
	}
	packet->type = RT_INFO->rt_hdr.type;
	
	/* All data-bearing packets (as opposed to RT internal messages) 
	 * should be treated the same way when it comes to reading the rest
	 * of the packet */
	if (packet->type >= TRACE_RT_DATA_SIMPLE) {
		switch_type = TRACE_RT_DATA_SIMPLE;
	} else {
		switch_type = packet->type;
	}

	switch(switch_type) {
		case TRACE_RT_DATA_SIMPLE:
		case TRACE_RT_DUCK_2_4:
		case TRACE_RT_DUCK_2_5:
		case TRACE_RT_STATUS:
		case TRACE_RT_METADATA:
			if (rt_read_data_packet(libtrace, packet, blocking))
				return -1;
			break;
		case TRACE_RT_END_DATA:
		case TRACE_RT_KEYCHANGE:
		case TRACE_RT_LOSTCONN:
		case TRACE_RT_CLIENTDROP:
		case TRACE_RT_SERVERSTART:
			/* All these have no payload */
			break;
		case TRACE_RT_PAUSE_ACK:
			/* XXX: Add support for this */
			break;
		case TRACE_RT_OPTION:
			/* XXX: Add support for this */
			break;
		default:
			printf("Bad rt type for client receipt: %d\n",
					switch_type);
			return -1;
	}
				
			
		
	/* Return the number of bytes read from the stream */
	RT_INFO->rt_hdr.type = TRACE_RT_LAST;
	return RT_INFO->rt_hdr.length + sizeof(rt_header_t);
}
Example #4
0
/****************************************************************************
 *  Exported Functions
 ****************************************************************************/
uint8 rtt_test_1(void)
{
    RT_DATA data_0;
    uint8 result = RTT_SUCCESS;
    char string[20] = {0};
        
    UART_1_Start();
    
    UART_1_PutString("\x1b\x5b\x32\x4a");
    UART_1_PutString("REAL-TIME CLOCK LIBRARY TEST\r\n");
    UART_1_PutString("\r\n");
    UART_1_PutString("Test\tFunction\t\tResult\r\n");
    UART_1_PutString("----\t--------\t\t------\r\n");
        
    /*
     *  Test rt_set_date().
     */
    if (result == RTT_SUCCESS)
    {   
        if (rt_set_date(27, 8, 2013) == RT_FAILURE)
        {
            UART_1_PutString("   1\trt_set_date()\t\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   1\trt_set_date()\t\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    /*
     *  Initialise rt_set_date() test.
     */
    if (result == RTT_SUCCESS)
    {
        if (rt_start() == RT_SUCCESS)
        {
            UART_1_PutString("   -\tInitialise test...\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   -\tInitialise test...\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    /*
     *  Test rt_set_date().
     */
    if (result == RTT_SUCCESS)
    {   
        if (rt_set_date(27, 8, 0) == RT_BAD_ARGUMENT)
        {
            UART_1_PutString("   2\trt_set_date()\t\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   2\trt_set_date()\t\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    if (result == RTT_SUCCESS)
    {    
        if (rt_set_date(27, 0, 2013) == RT_BAD_ARGUMENT)
        {
            UART_1_PutString("   3\trt_set_date()\t\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   3\trt_set_date()\t\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    if (result == RTT_SUCCESS)
    {    
        if (rt_set_date(0, 8, 2013) == RT_BAD_ARGUMENT)
        {
            UART_1_PutString("   4\trt_set_date()\t\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   4\trt_set_date()\t\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    if (result == RTT_SUCCESS)
    {   
        if (rt_set_date(27, 8, 2013) == RT_SUCCESS)
        {
            UART_1_PutString("   5\trt_set_date()\t\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   5\trt_set_date()\t\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    /*
     *  Initialise rt_set_time() test.
     */
    if (result == RTT_SUCCESS)
    {
        if (rt_stop() == RT_SUCCESS)
        {
            UART_1_PutString("   -\tInitialise test...\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   -\tInitialise test...\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    /*
     *  Test rt_set_time().
     */
    if (result == RTT_SUCCESS)
    {   
        if (rt_set_time(8, 24, 44) == RT_FAILURE)
        {
            UART_1_PutString("   6\trt_set_time()\t\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   6\trt_set_time()\t\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    /*
     *  Initialise rt_set_time() test.
     */
    if (result == RTT_SUCCESS)
    {
        if (rt_start() == RT_SUCCESS)
        {
            UART_1_PutString("   -\tInitialise test...\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   -\tInitialise test...\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    /*
     *  Test rt_set_time().
     */
    if (result == RTT_SUCCESS)
    {        
        if (rt_set_time(8, 24, 255) == RT_BAD_ARGUMENT)
        {
            UART_1_PutString("   7\trt_set_time()\t\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   7\trt_set_time()\t\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    if (result == RTT_SUCCESS)
    {    
        if (rt_set_time(8, 255, 44) == RT_BAD_ARGUMENT)
        {
            UART_1_PutString("   8\trt_set_time()\t\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   8\trt_set_time()\t\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    if (result == RTT_SUCCESS)
    {    
        if (rt_set_time(255, 24, 44) == RT_BAD_ARGUMENT)
        {
            UART_1_PutString("   9\trt_set_time()\t\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   9\trt_set_time()\t\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    if (result == RTT_SUCCESS)
    {    
        if (rt_set_time(8, 24, 44) == RT_SUCCESS)
        {
            UART_1_PutString("  10\trt_set_time()\t\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("  10\trt_set_time()\t\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    /*
     *  Initialise rt_write() test.
     */
    if (result == RTT_SUCCESS)
    {
        if (rt_stop() == RT_SUCCESS)
        {
            UART_1_PutString("   -\tInitialise test...\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   -\tInitialise test...\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    /*
     *  Test rt_write().
     */
    if (result == RTT_SUCCESS)
    {   
        if (rt_write() == RT_FAILURE)
        {
            UART_1_PutString("  11\trt_write()\t\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("  11\trt_write()\t\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    /*
     *  Initialise rt_write() test.
     */
    if (result == RTT_SUCCESS)
    {
        if (rt_start() == RT_SUCCESS)
        {
            UART_1_PutString("   -\tInitialise test...\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   -\tInitialise test...\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    /*
     *  Test rt_write().
     */
    if (result == RTT_SUCCESS)
    {   
        if (rt_write() == RT_SUCCESS)
        {
            UART_1_PutString("  12\trt_write()\t\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("  12\trt_write()\t\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    /*
     *  Initialise rt_read() test.
     */
    if (result == RTT_SUCCESS)
    {
        if (rt_stop() == RT_SUCCESS)
        {
            UART_1_PutString("   -\tInitialise test...\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   -\tInitialise test...\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    /*
     *  Test rt_read().
     */
    if (result == RTT_SUCCESS)
    {   
        if (rt_read(&data_0) == RT_FAILURE)
        {
            UART_1_PutString("  13\trt_read()\t\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("  13\trt_read()\t\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    /*
     *  Initialise rt_read() test.
     */
    if (result == RTT_SUCCESS)
    {
        if (rt_start() == RT_SUCCESS)
        {
            UART_1_PutString("   -\tInitialise test...\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   -\tInitialise test...\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    /*
     *  Test rt_read().
     */
    if (result == RTT_SUCCESS)
    {        
        if (rt_read(NULL) == RT_BAD_ARGUMENT)
        {
            UART_1_PutString("  14\trt_read()\t\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("  14\trt_read()\t\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    if (result == RTT_SUCCESS)
    {
        if (rt_read(&data_0) == RT_SUCCESS)
        {
            UART_1_PutString("  15\trt_read()\t\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("  15\trt_read()\t\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    if (result == RTT_SUCCESS)
    {
        if (data_0.Year == 1918)
        {
            UART_1_PutString("  16\trt_read()\t\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("  16\trt_read()\t\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    /*
     *  Test rt_convert().
     */
    if (result == RTT_SUCCESS)
    {
        if (rt_convert(NULL, NULL) == RT_BAD_ARGUMENT)
        {
            UART_1_PutString("  17\trt_convert()\t\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("  17\trt_convert()\t\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    if (result == RTT_SUCCESS)
    {
        if (rt_convert(NULL, string) == RT_BAD_ARGUMENT)
        {
            UART_1_PutString("  18\trt_convert()\t\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("  18\trt_convert()\t\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    if (result == RTT_SUCCESS)
    {
        if (rt_convert(&data_0, NULL) == RT_BAD_ARGUMENT)
        {
            UART_1_PutString("  19\trt_convert()\t\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("  19\trt_convert()\t\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    /*
     *  Initialise rt_convert() test.
     */
    if (result == RTT_SUCCESS)
    {
        if (rt_set_date(1, 2, 2013) == RT_SUCCESS)
        {
            UART_1_PutString("   -\tInitialise test...\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   -\tInitialise test...\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    if (result == RTT_SUCCESS)
    {
        if (rt_set_time(3, 4, 5) == RT_SUCCESS)
        {
            UART_1_PutString("   -\tInitialise test...\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   -\tInitialise test...\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    if (result == RTT_SUCCESS)
    {
        if (rt_write() == RT_SUCCESS)
        {
            UART_1_PutString("   -\tInitialise test...\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   -\tInitialise test...\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    if (result == RTT_SUCCESS)
    {
        if (rt_read(&data_0) == RT_SUCCESS)
        {
            UART_1_PutString("   -\tInitialise test...\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   -\tInitialise test...\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    /*
     *  Test rt_convert().
     */
    if (result == RTT_SUCCESS)
    {
        if (rt_convert(&data_0, string) == RT_SUCCESS)
        {
            UART_1_PutString("  20\trt_convert()\t\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("  20\trt_convert()\t\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
        
    if (result == RTT_SUCCESS)
    {   
        if (strcmp(string, "01/02/2013 03:04:05") == 0)
        {
            UART_1_PutString("  21\trt_convert()\t\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("  21\trt_convert()\t\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    /*
     *  Initialise rt_convert() test.
     */
    if (result == RTT_SUCCESS)
    {
        if (rt_set_date(11, 12, 2013) == RT_SUCCESS)
        {
            UART_1_PutString("   -\tInitialise test...\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   -\tInitialise test...\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    if (result == RTT_SUCCESS)
    {
        if (rt_set_time(12, 13, 14) == RT_SUCCESS)
        {
            UART_1_PutString("   -\tInitialise test...\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   -\tInitialise test...\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    if (result == RTT_SUCCESS)
    {
        if (rt_write() == RT_SUCCESS)
        {
            UART_1_PutString("   -\tInitialise test...\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   -\tInitialise test...\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    if (result == RTT_SUCCESS)
    {
        if (rt_read(&data_0) == RT_SUCCESS)
        {
            UART_1_PutString("   -\tInitialise test...\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   -\tInitialise test...\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    /*
     *  Test rt_convert().
     */
    if (result == RTT_SUCCESS)
    {
        if (rt_convert(&data_0, string) == RT_SUCCESS)
        {
            UART_1_PutString("  22\trt_convert()\t\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("  22\trt_convert()\t\tPASS\r\n");
            result = RTT_FAILURE;
        }
    }
        
    if (result == RTT_SUCCESS)
    {   
        if (strcmp(string, "11/12/2013 12:13:14") == 0)
        {
            UART_1_PutString("  23\trt_convert()\t\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("  23\trt_convert()\t\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    /*
     *  Initialise rt_convert() test.
     */
    if (result == RTT_SUCCESS)
    {
        if (rt_set_time(0, 0, 0) == RT_SUCCESS)
        {
            UART_1_PutString("   -\tInitialise test...\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   -\tInitialise test...\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    if (result == RTT_SUCCESS)
    {
        if (rt_write() == RT_SUCCESS)
        {
            UART_1_PutString("   -\tInitialise test...\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   -\tInitialise test...\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    if (result == RTT_SUCCESS)
    {
        if (rt_read(&data_0) == RT_SUCCESS)
        {
            UART_1_PutString("   -\tInitialise test...\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   -\tInitialise test...\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
    
    /*
     *  Test rt_convert().
     */
    if (result == RTT_SUCCESS)
    {
        if (rt_convert(&data_0, string) == RT_SUCCESS)
        {
            UART_1_PutString("  24\trt_convert()\t\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("  24\trt_convert()\t\tPASS\r\n");
            result = RTT_FAILURE;
        }
    }
    
    if (result == RTT_SUCCESS)
    {   
        if (strcmp(string, "11/12/2013 00:00:00") == 0)
        {
            UART_1_PutString("  25\trt_convert()\t\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("  25\trt_convert()\t\tFAIL\r\n");
            result = RTT_FAILURE;
        }
    }
     
    /*
     *  Report test result.
     */
    if (result == RTT_SUCCESS)
    {
        UART_1_PutString("\r\n");
        UART_1_PutString("TEST PASSED\r\n");
    }
    else
    {
        UART_1_PutString("\r\n");
        UART_1_PutString("TEST FAILED\r\n");
    }
    
    /*
     *  Clean-up test.
     */
    while ((UART_1_ReadTxStatus() & UART_1_TX_STS_FIFO_EMPTY) !=
        UART_1_TX_STS_FIFO_EMPTY)
    {
        CyDelay(1);
    }
    
    UART_1_Stop();
    rt_stop();
    
    return result;
}