Revision 1396
updated wl_basic with default packet handling
trunk/code/projects/libwireless/lib/wl_basic.c | ||
---|---|---|
22 | 22 |
unsigned char* packet, int length) ) { |
23 | 23 |
int returnme = wl_init(); |
24 | 24 |
wl_basic_register_handler(handle_receive); |
25 |
current_packet.new_flag = 0; |
|
25 | 26 |
return returnme; |
26 | 27 |
} |
27 | 28 |
|
28 | 29 |
/** |
30 |
* |
|
31 |
* |
|
32 |
**/ |
|
33 |
int wl_basic_init_default( ) { |
|
34 |
return wl_basic_init(&wl_basic_packet_receive_handler); |
|
35 |
} |
|
36 |
|
|
37 |
/** |
|
29 | 38 |
* Internal function to register a packet group handler for Basic Group |
30 | 39 |
* |
31 | 40 |
* @param handle_receive function pointer to handler function for Basic Group |
... | ... | |
64 | 73 |
wl_send_global_packet(WL_BASIC_GROUP, type, data, len, 0); |
65 | 74 |
} |
66 | 75 |
|
76 |
/** |
|
77 |
* Default packet handler used if none is specified on init |
|
78 |
* |
|
79 |
* @param type Packet type |
|
80 |
* @param data Packet buffer, data you received |
|
81 |
* @param length Length of the data buffer in bytes |
|
82 |
**/ |
|
83 |
void wl_basic_packet_receive_handler( char type, int source, unsigned char* packet, int length ) { |
|
84 |
current_packet.new_flag = 1; |
|
85 |
current_packet.type = type; |
|
86 |
current_packet.source = source; |
|
87 |
current_packet.pointer = packet; |
|
88 |
current_packet.length = length; |
|
89 |
} |
|
90 |
|
|
91 |
/** |
|
92 |
* Wrapper for wl_do() |
|
93 |
* |
|
94 |
* @return pointer to the data of the packet just received |
|
95 |
**/ |
|
96 |
unsigned char* wl_basic_do( void ) { |
|
97 |
wl_do(); |
|
98 |
if (current_packet.new_flag == 1) { |
|
99 |
current_packet.new_flag = 0; |
|
100 |
return current_packet.pointer; |
|
101 |
} |
|
102 |
return 0; |
|
103 |
} |
|
104 |
|
trunk/code/projects/libwireless/lib/wl_basic.h | ||
---|---|---|
27 | 27 |
|
28 | 28 |
/** @brief init wireless for Basic Group **/ |
29 | 29 |
int wl_basic_init( void (*handle_receive) (char type, int source, unsigned char* packet, int length) ); |
30 |
/** @brief init wireless for Basic Group with default packet handling **/ |
|
31 |
int wl_basic_init_default( void ); |
|
30 | 32 |
/** @brief internal function to register a packet handler function **/ |
31 | 33 |
void wl_basic_register_handler( void (*handle_receive) (char type, int source, unsigned char* packet, int length) ); |
32 | 34 |
/** @brief send a packet to a single robot in Basic Group **/ |
33 | 35 |
void wl_basic_send_robot_packet( char type, char* data, int len, int dest ); |
34 | 36 |
/** @brief send a packet to all robots in Basic Group **/ |
35 | 37 |
void wl_basic_send_global_packet( char type, char* data, int len ); |
38 |
/** @brief default packet handler if none is specified on init **/ |
|
39 |
void wl_basic_packet_receive_handler( char type, int source, unsigned char* packet, int length ); |
|
40 |
/** @brief wrapper for wl_do() to return packet data buffer **/ |
|
41 |
unsigned char* wl_basic_do( void ); |
|
36 | 42 |
|
37 | 43 |
/** @brief PacketGroupHandler struct for Basic Group **/ |
38 | 44 |
PacketGroupHandler wl_basic_group_handler; |
39 | 45 |
|
46 |
struct PacketInfo { |
|
47 |
char new_flag; |
|
48 |
char type; |
|
49 |
int source; |
|
50 |
unsigned char* pointer; |
|
51 |
int length; |
|
52 |
}; |
|
53 |
|
|
54 |
/** |
|
55 |
* @brief current packet information, correct after wl_basic_do() |
|
56 |
**/ |
|
57 |
struct PacketInfo current_packet; |
|
58 |
|
|
40 | 59 |
/** @} **/ // end defgroup |
41 | 60 |
|
42 | 61 |
#endif |
Also available in: Unified diff