Project

General

Profile

Revision 1379

Added by Chris Mar over 14 years ago

adding wireless abstraction for high level packet sending and receiving

View differences:

trunk/code/projects/libwireless/lib/wl_basic.c
1
/**
2
 * @file wl_basic.c
3
 * @brief High Level Wireless Packet Sending-Receiving Functions
4
 *
5
 * Abstracted wireless functionality for sending and receiving packets
6
 *
7
 * @author Colony Project, CMU Robotics Club
8
 **/
9

  
10
#include <wireless.h>
11
#include "wl_basic.h"
12

  
13
/**
14
 * Wrapper for wl_init().
15
 * Initializes wireless and registers a
16
 * packet handler function for Basic Group.
17
 *
18
 * @param handle_receive function pointer to handler function for Basic Group
19
 * @return 0 on success, -1 on error 
20
 **/
21
int wl_basic_init( void(*handle_receive) (char type, int source,
22
                   unsigned char* packet, int length) ) {
23
    int returnme = wl_init();
24
    wl_basic_register_handler(handle_receive);
25
    return returnme;
26
}
27

  
28
/**
29
 * Internal function to register a packet group handler for Basic Group
30
 *
31
 * @param handle_receive function pointer to handler function for Basic Group
32
 **/
33
void wl_basic_register_handler( void (*handle_receive) (char type, int source,
34
                        unsigned char* packet, int length)) {
35
    wl_basic_group_handler.groupCode = WL_BASIC_GROUP;
36
    wl_basic_group_handler.timeout_handler = 0;
37
    wl_basic_group_handler.handle_response = 0;
38
    wl_basic_group_handler.handle_receive = handle_receive;
39
    wl_basic_group_handler.unregister = 0;
40

  
41
    wl_register_packet_group(&wl_basic_group_handler);
42
}
43

  
44
/**
45
 * Send a packet to a single robot in Basic Group
46
 *
47
 * @param type Packet type
48
 * @param data Packet buffer, data you want to send
49
 * @param len Length of the data buffer in bytes
50
 * @dest Robot ID of the destination robot
51
 **/
52
void wl_basic_send_robot_packet( char type, char* data, int len, int dest ) {
53
    wl_send_robot_to_robot_global_packet(WL_BASIC_GROUP, type, data, len, dest, 0);
54
}
55

  
56
/**
57
 * Send a packet to all robots in Basic Group
58
 *
59
 * @param type Packet type
60
 * @param data Packet buffer, data you want to send
61
 * @param len Length of the data buffer in bytes
62
 **/
63
void wl_basic_send_global_packet( char type, char* data, int len ) {
64
    wl_send_global_packet(WL_BASIC_GROUP, type, data, len, 0);
65
}
66

  
trunk/code/projects/libwireless/lib/wl_basic.h
1
/**
2
 * @file wl_basic.h
3
 * @brief High Level Wireless Packet Sending-Receiving Functions
4
 *
5
 * Abstracted wireless functionality for sending and receiving packets
6
 *
7
 * @author Colony Project, CMU Robotics Club
8
 **/
9

  
10

  
11
#include <wireless.h>
12

  
13
#define WL_BASIC_GROUP 8
14

  
15
/** @brief init wireless for Basic Group **/
16
int wl_basic_init( void (*handle_receive) (char type, int source, unsigned char* packet, int length) );
17
/** @brief internal function to register a packet handler function **/
18
void wl_basic_register_handler( void (*handle_receive) (char type, int source, unsigned char* packet, int length) );
19
/** @brief send a packet to a single robot in Basic Group **/
20
void wl_basic_send_robot_packet( char type, char* data, int len, int dest );
21
/** @brief send a packet to all robots in Basic Group **/
22
void wl_basic_send_global_packet( char type, char* data, int len );
23

  
24
/** @brief PacketGroupHandler struct for Basic Group **/
25
PacketGroupHandler wl_basic_group_handler;
26

  

Also available in: Unified diff