Revision 1425
updated wireless basic library code and docs
wl_basic.c | ||
---|---|---|
12 | 12 |
|
13 | 13 |
/** |
14 | 14 |
* Wrapper for wl_init(). |
15 |
* Initializes wireless and registers a |
|
16 |
* packet handler function for Basic Group. |
|
15 |
* Initializes wireless and registers a packet handler function for Basic Group. |
|
17 | 16 |
* |
18 | 17 |
* @param handle_receive function pointer to handler function for Basic Group |
19 | 18 |
* @return 0 on success, -1 on error |
... | ... | |
27 | 26 |
} |
28 | 27 |
|
29 | 28 |
/** |
29 |
* Wrapper for wl_init(). |
|
30 |
* Initializes wireless and registers the default packet handler for Basig Group. |
|
30 | 31 |
* |
31 |
* |
|
32 | 32 |
**/ |
33 | 33 |
int wl_basic_init_default( ) { |
34 | 34 |
return wl_basic_init(&wl_basic_packet_receive_handler); |
35 | 35 |
} |
36 | 36 |
|
37 | 37 |
/** |
38 |
* Internal function to register a packet group handler for Basic Group |
|
38 |
* Internal function to register a packet group handler for Basic Group.
|
|
39 | 39 |
* |
40 | 40 |
* @param handle_receive function pointer to handler function for Basic Group |
41 | 41 |
**/ |
... | ... | |
51 | 51 |
} |
52 | 52 |
|
53 | 53 |
/** |
54 |
* Send a packet to a single robot in Basic Group |
|
54 |
* Send a packet to a single robot in Basic Group.
|
|
55 | 55 |
* |
56 | 56 |
* @param type Packet type |
57 | 57 |
* @param data Packet buffer, data you want to send |
58 | 58 |
* @param len Length of the data buffer in bytes |
59 |
* @dest Robot ID of the destination robot |
|
59 |
* @param dest Robot ID of the destination robot
|
|
60 | 60 |
**/ |
61 | 61 |
void wl_basic_send_robot_packet( char type, char* data, int len, int dest ) { |
62 | 62 |
wl_send_robot_to_robot_global_packet(WL_BASIC_GROUP, type, data, len, dest, 0); |
63 | 63 |
} |
64 | 64 |
|
65 | 65 |
/** |
66 |
* Send a packet to all robots in Basic Group |
|
66 |
* Send a packet to all robots in Basic Group.
|
|
67 | 67 |
* |
68 | 68 |
* @param type Packet type |
69 | 69 |
* @param data Packet buffer, data you want to send |
... | ... | |
74 | 74 |
} |
75 | 75 |
|
76 | 76 |
/** |
77 |
* Default packet handler used if none is specified on init |
|
77 |
* Default packet handler used if none is specified on init. |
|
78 |
* This should not be called directly by any user program. |
|
78 | 79 |
* |
79 | 80 |
* @param type Packet type |
80 |
* @param data Packet buffer, data you received |
|
81 |
* @param source the robot ID of the sending robot |
|
82 |
* @param packet Packet buffer, data you received |
|
81 | 83 |
* @param length Length of the data buffer in bytes |
82 | 84 |
**/ |
83 | 85 |
void wl_basic_packet_receive_handler( char type, int source, unsigned char* packet, int length ) { |
84 | 86 |
current_packet.new_flag = 1; |
85 | 87 |
current_packet.type = type; |
86 | 88 |
current_packet.source = source; |
87 |
current_packet.pointer = packet;
|
|
89 |
current_packet.data = packet;
|
|
88 | 90 |
current_packet.length = length; |
89 | 91 |
} |
90 | 92 |
|
91 | 93 |
/** |
92 |
* Wrapper for wl_do() |
|
94 |
* Wrapper for wl_do() for use with the Basic Wireless group. |
|
95 |
* Can only be called if wl_basic_init_default and your packets |
|
96 |
* are handled with the default packet handler. |
|
97 |
* To access packet information, use PacketInfo current_packet. |
|
93 | 98 |
* |
94 |
* @return pointer to the data of the packet just received |
|
99 |
* @return pointer to the data of the packet just received, 0 if no new packet
|
|
95 | 100 |
**/ |
96 |
unsigned char* wl_basic_do( void ) { |
|
101 |
unsigned char* wl_basic_do_default( void ) {
|
|
97 | 102 |
wl_do(); |
98 | 103 |
if (current_packet.new_flag == 1) { |
99 | 104 |
current_packet.new_flag = 0; |
100 |
return current_packet.pointer;
|
|
105 |
return current_packet.data;
|
|
101 | 106 |
} |
102 | 107 |
return 0; |
103 | 108 |
} |
Also available in: Unified diff