Project

General

Profile

Revision 1589

Wrote basic receive function in wireless_receive.c. Added an error code for
having too short of a packet destination for basic receive function (maybe can
also be used by other packet handlers) in wl_defs.h. Added packet buffers for
basic packets and other types of packets in xbee.c.

View differences:

branches/wireless/code/projects/libwireless/wireless_receive.c
33 33
 * @author Colony Project, CMU Robotics Club
34 34
 **/
35 35

  
36
#include <string.h>
36 37
#include "wl_defs.h"
37 38
#include "wireless.h"
39
#include "xbee.h"
38 40

  
39

  
40 41
// the receive functions
41 42

  
42 43
/**
......
44 45
 * @{
45 46
 **/
46 47

  
48
extern uint8_t xbee_basic_buf[PACKET_BUFFER_SIZE];  // buffer for basic-group packets
49
extern uint8_t xbee_other_buf[PACKET_BUFFER_SIZE];  // buffer for non-basic-group packets
50
extern uint8_t basic_buf_first;	// beginning of first packet in basic buffer
51
extern uint8_t basic_buf_last;	// end of last packet in basic buffer
52
extern uint8_t other_buf_first; // beginning of first packet in other buffer
53
extern uint8_t other_buf_last;  // end of last packet in other buffer
54

  
47 55
/**
48 56
 * the main receive function (similar to wl_do)
49 57
 * 
......
59 67
  int8_t return_code = wl_dispatch(); // run dispatch of other packet groups
60 68
  if (return_code != 0)
61 69
    return return_code; // error, so end early
62
  return wl_get_basic(data,length); // get a basic packet
70
  return wl_get_basic(data, length); // get a basic packet
63 71
}
64 72

  
65 73
/**
......
72 80
 * @return the length of the used portion of data array or error (<0)
73 81
 **/
74 82
int8_t wl_get_basic(char *data, uint8_t length) {
83
    uint8_t buf_pos = basic_buf_first;	// start at beginning of first (oldest) basic packet
84
    uint8_t data_length = xbee_basic_buf[buf_pos];  // get packet length
85
    uint8_t packet_num;	// number of packet (may eventually be used to weed out duplicates)
75 86

  
76
  return 0;
87
    if (data_length > length)	// not enough room for packet in destination
88
	return WL_ERROR_TOO_SMALL;
89
    
90
    buf_pos++;
91
    packet_num = xbee_basic_buf[buf_pos];   // get packet number
92
    buf_pos++;
93
    buf_pos++;	// ignore the group code. it will always be the same.
94

  
95
    memcpy(data, xbee_basic_buf + buf_pos, data_length);    // get the data
96
    basic_buf_first += data_length; // "free up" this packet's buffer space
97

  
98
    return 0;
77 99
}
78 100

  
79 101
/*
branches/wireless/code/projects/libwireless/xbee.c
112 112

  
113 113
//used to store packets as they are read
114 114
static char xbee_buf[PACKET_BUFFER_SIZE];
115
static uint8_t xbee_basic_buf[PACKET_BUFFER_SIZE];
116
static uint8_t xbee_other_buf[PACKET_BUFFER_SIZE];
115 117
static int currentBufPos = 0;
118
static uint8_t basic_buf_first = 0;	// beginning of first packet in basic buffer
119
static uint8_t basic_buf_last = 0;	// end of last packet in basic buffer
120
static uint8_t other_buf_first = 0; // beginning of first packet in other buffer
121
static uint8_t other_buf_last = 0;  // end of last packet in other buffer
116 122

  
117 123
//XBee status
118 124
static unsigned int xbee_panID = XBEE_PAN_DEFAULT;
branches/wireless/code/projects/libwireless/wl_defs.h
101 101
/** @brief Error code for a bad mode **/
102 102
#define WL_ERROR_MODE INT8_C(-14)
103 103

  
104
/** @brief Error code for received paacket destination too small for received packet **/
105
#define WL_ERROR_TOO_SMALL INT8_C(-15)
104 106

  
107

  
105 108
/**@} */ // end error group
106 109

  
107 110
/**@} */ // end wireless group

Also available in: Unified diff