Project

General

Profile

Revision 1825

Wireless: updated library to make it more readable and to reduce possible errors with acking (untested changes, but shouldn't be broken or something is very wrong).

View differences:

xbee.c
31 31
 *
32 32
 * @author Colony Project, CMU Robotics Club
33 33
 **/
34
// TODO Why are we including lights? Because lights are awesome. No, really, figure this out.
34 35
#include <lights.h>
35 36

  
36 37
#include <string.h>
......
123 124
#define XBEE_COMMAND_MASK 0xC0
124 125
#define XBEE_NOT_INITD 0xF0
125 126
#define LAST_PACKET_MASK 0x0F
126
uint8_t xbee_status = XBEE_NOT_INITD;
127
uint8_t xbee_status = XBEE_NOT_INITD; //This is the super-byte
127 128

  
128 129
// xbee command response (for PAN, channel, address, etc)
129 130
static uint8_t xbee_command[8];
......
198 199
    
199 200
  // get length and type
200 201
  while(i<3) {
201
    if (FLAG) {
202
    if (FLAG) { //if there is a byte to read //checks for escape characters in API mode 2. This repeats below (should be a function)
202 203
      if (i==0) {
203
        if (getStatus(XBEE_API_MASK) == XBEE_API_ESCAPE
204
            && apitype == ESCAPE_MARKER)
204
        if (getStatus(XBEE_API_MASK) == XBEE_API_ESCAPE             && apitype == ESCAPE_MARKER) //apitype is used here as dummy var
205 205
          apitype = PORT ^ ESCAPE_XOR;
206 206
        else {
207 207
          apitype = PORT;
......
250 250
    uint8_t ptr=basic_buf_last;
251 251
    uint8_t status=0;
252 252
    while(i<len) {
253
      if (FLAG) {
253
      if (FLAG) {  //more escape characters
254 254
        if (i==1) {
255 255
          if (getStatus(XBEE_API_MASK) == XBEE_API_ESCAPE
256 256
              && apitype == ESCAPE_MARKER)
......
332 332
    for(uint8_t j=0;j<(len-5);j++)
333 333
      WL_DEBUG_PRINT_HEX(xbee_basic_buf_get(&ptr2));
334 334
    WL_DEBUG_PRINT_P("|\r\n");
335
	//end of DEBUG_PRINT
335 336
    xbee_handle_at_command_response(atcommand,status,len-5);
336 337
    break; }
337 338
  case XBEE_FRAME_STATUS: {
......
379 380
                && apitype == ESCAPE_MARKER)
380 381
              continue; // get escaped character
381 382
          }
382
          ackhandle(frame_id,apitype); // handle the status
383
          ackhandle(frame_id,apitype); // handle the status (stored in apitype)
383 384
          break;
384 385
        }
385 386
        i++;
......
481 482
            WL_DEBUG_PRINT_P("|ptr2=");
482 483
            WL_DEBUG_PRINT_INT(ptr);
483 484
          
484
          if (group == 0) {
485
          if (group == 0) { //writes the packet to the buffer
485 486
            WL_DEBUG_PRINT_P("|last1=");
486 487
            WL_DEBUG_PRINT_INT(basic_buf_last);
487 488
            WL_DEBUG_PRINT_P("|ptr1=");
......
720 721

  
721 722
/** status functions **/
722 723
inline uint8_t getStatus(uint8_t mask) { return xbee_status&mask; }
723
void setStatus(uint8_t mask,uint8_t value) { xbee_status = ((xbee_status&(~mask))|value); }
724
void setStatus(uint8_t mask,uint8_t value) {
725
  xbee_status = ((xbee_status&(~mask))|value); //xbee is the super-byte
726
}
724 727

  
725 728

  
726 729
/**
......
751 754
  // Set startup baud rate of 9600
752 755
  // Set frame format: 8data, 1stop bit, asynchronous normal mode
753 756
  // Enable receiver and transmitter and the receiving interrupt
757
  // DO NOT TOUCH
754 758
#ifdef FIREFLY
755 759
  UBRR0H = 0x00;
756 760
  UBRR0L = 103;
......
1099 1103
}
1100 1104

  
1101 1105
/**
1102
 * Enter API mode.
1106
 * Enter API mode 1.
1103 1107
 **/
1104 1108
static int8_t xbee_enter_api_mode(void) {
1105 1109
  if (xbee_send_string((uint8_t*)"ATAP 1\r") != 0) {
......
1236 1240
  if (getStatus(XBEE_API_MASK) == XBEE_API_OFF) {
1237 1241
    // wait until the response is received (only wait 1 second)
1238 1242
    while(getStatus(XBEE_COMMAND_MASK) != XBEE_COMMAND_RESPONSE && i++ < 1000) {
1239
      delay_us(1);
1243
      delay_us(1); //3 us
1240 1244
    }
1241 1245
    // check response
1242 1246
    if (i >= 1000) {
......
1411 1415
}
1412 1416

  
1413 1417
/**
1414
 * Send the specified packet.
1418
 * Send the specified packet. (wl_send depreciates this)
1415 1419
 *
1416 1420
 * @param packet the packet data to send
1417 1421
 * @param len the number of bytes in the packet
......
1647 1651
/**
1648 1652
 * Set the channel the XBee is using.
1649 1653
 *
1650
 * @param channel the channel the XBee will not use,
1654
 * @param channel the channel the XBee will use,
1651 1655
 * between 0x0B and 0x1A
1652 1656
 *
1657
 * @reutrn success or error code
1658
 *
1653 1659
 * @see xbee_get_channel
1654 1660
 **/
1655 1661
int8_t xbee_set_channel(uint8_t channel)

Also available in: Unified diff