Project

General

Profile

Revision 779

Updated logging program.

View differences:

wl_token_logger.c
11 11

  
12 12
/*Function Prototypes*/
13 13
/*Wireless Library Prototypes*/
14
void wl_logger_receive_handler(char type, int source, unsigned char* packet,
14
void wl_token_ring_receive_handler(char type, int source, unsigned char* packet,
15 15
							int length);
16 16
void timeout_handler(void);
17
PacketGroupHandler wl_logger_handler =
17
PacketGroupHandler wl_token_ring_handler =
18 18
		{WL_TOKEN_RING_GROUP, timeout_handler,
19
		NULL, wl_logger_receive_handler,
19
		NULL, wl_token_ring_receive_handler,
20 20
		NULL};
21 21

  
22 22
/* Global Variables */
......
48 48
	startTime = time(NULL);
49 49
	endTime = startTime + seconds;
50 50

  
51
	wl_register_packet_group(&wl_logger_handler);
51
	wl_register_packet_group(&wl_token_ring_handler);
52 52
}
53 53

  
54 54
/**
......
56 56
 **/
57 57
void wl_token_logger_unregister()
58 58
{
59
	wl_unregister_packet_group(&wl_logger_handler);
59
	wl_unregister_packet_group(&wl_token_ring_handler);
60 60
}
61 61

  
62 62
/**
......
66 66
 * @param packet the data in the packet
67 67
 * @param length the length of the packet in bytes
68 68
 **/
69
void wl_logger_receive_handler(char type, int source, unsigned char* packet,
69
void wl_token_ring_receive_handler(char type, int source, unsigned char* packet,
70 70
							int length)
71 71
{
72 72
	struct timeb t;
......
77 77
	if (seconds >= endTime)
78 78
		exit(0);
79 79
	int temp = (int)(seconds - startTime);
80
	printf("%d:%.2d.%.3d: ", temp / 60, temp % 60, millis);
80
	printf("%d:%.2d.%.3d:\n", temp / 60, temp % 60, millis);
81 81

  
82 82
	switch (type)
83 83
	{
84 84
		case WL_TOKEN_PASS:
85
			if (length < 1)
86
			{
87
				WL_DEBUG_PRINT("Malformed Token Pass packet received.\r\n");
88
				return;
89
			}
90
			printf("Robot %d passed the token to robot %d. Sensor matrix:\n", source, packet[0]);
85
			printf("We were passed the token from robot %d.\n", source);
86
			break;
87
		case WL_TOKEN_SENSOR_MATRIX:
88
			printf("Robot %d sent sensor matrix:\n", source);
91 89
			int i;
92
			for (i = 1; i < length; i+=2)
90
			for (i = 0; i < length; i+=2)
93 91
				printf("(%d %d)", packet[i], packet[i+1]);
94 92
			printf("\n");
95 93
			break;

Also available in: Unified diff