root / trunk / code / projects / libwireless / lib / wl_error_group.c @ 17
History | View | Annotate | Download (1.96 KB)
1 |
#include "wl_error_group.h" |
---|---|
2 |
|
3 |
#include <wireless.h> |
4 |
#include <wl_defs.h> |
5 |
#include <stdio.h> |
6 |
#include <string.h> |
7 |
|
8 |
|
9 |
void wl_error_response_receive(int frame, int received); |
10 |
void wl_error_handle_receive(char type, int source, unsigned char* packet, |
11 |
int length);
|
12 |
|
13 |
PacketGroupHandler wl_error_handler = |
14 |
{WL_ERROR_GROUP, NULL,
|
15 |
wl_error_response_receive, wl_error_handle_receive, NULL};
|
16 |
|
17 |
void wl_error_response_receive(int frame, int received) |
18 |
{ |
19 |
WL_DEBUG_PRINT("Response received.\r\n");
|
20 |
if (!received)
|
21 |
{ |
22 |
WL_DEBUG_PRINT("FAILED.\r\n");
|
23 |
} |
24 |
} |
25 |
/**
|
26 |
* Register this packet group with the wireless library.
|
27 |
* This function must be called before any other wl_error
|
28 |
* function.
|
29 |
**/
|
30 |
void wl_error_register(void) |
31 |
{ |
32 |
wl_register_packet_group(&wl_error_handler); |
33 |
} |
34 |
|
35 |
/**
|
36 |
* Unregister this packet group with the wireless library.
|
37 |
* This function must be called after wl_error_register.
|
38 |
*
|
39 |
* @see wl_error_register
|
40 |
**/
|
41 |
void wl_error_unregister(void) |
42 |
{ |
43 |
wl_unregister_packet_group(&wl_error_handler); |
44 |
} |
45 |
|
46 |
/**
|
47 |
* Handles receiving an error packet.
|
48 |
*
|
49 |
* @param type the packet type
|
50 |
* @param source the 16-bit address of the packet's sender
|
51 |
* @param packet the packet data
|
52 |
* @param length the length in bytes of the packet
|
53 |
**/
|
54 |
void wl_error_handle_receive(char type, int source, unsigned char* packet, |
55 |
int length)
|
56 |
{ |
57 |
switch (type)
|
58 |
{ |
59 |
case WL_ERROR_STRING_TYPE:
|
60 |
if (packet[length - 1] != 0) |
61 |
{ |
62 |
WL_DEBUG_PRINT( |
63 |
"Error packet string should be null terminated.\r\n");
|
64 |
break;
|
65 |
} |
66 |
WL_DEBUG_PRINT("Error packet received from robot ");
|
67 |
WL_DEBUG_PRINT_INT(source); |
68 |
WL_DEBUG_PRINT(":\r\n");
|
69 |
WL_DEBUG_PRINT((char*)packet);
|
70 |
WL_DEBUG_PRINT("\r\n");
|
71 |
break;
|
72 |
default:
|
73 |
WL_DEBUG_PRINT("Error packet of unknown type received.\r\n");
|
74 |
break;
|
75 |
} |
76 |
} |
77 |
|
78 |
/**
|
79 |
* Send an error message as a string.
|
80 |
*
|
81 |
* @param str the error message to send
|
82 |
**/
|
83 |
void wl_error_send_string(char* str) |
84 |
{ |
85 |
wl_send_global_packet(WL_ERROR_GROUP, WL_ERROR_STRING_TYPE, |
86 |
str, strlen(str) + 1, 1); |
87 |
} |
88 |
|