Project

General

Profile

Revision 1642

wireless: test_xbee is good. Need to start testing wireless_send and wireless_receive.

View differences:

xbee.c
620 620
  // TODO: we should set the MY address to the robot address from eeprom  
621 621
  uint16_t i=0;
622 622
  setStatus(XBEE_COMMAND_MASK,XBEE_COMMAND_WAIT);  
623
  uint8_t newmy = 4;
624
  if (xbee_send_modify_at_command((uint8_t*)"MY",&newmy,1) != WL_SUCCESS) {
623
  uint16_t newmy = 0x9876;
624
  if (xbee_send_modify_at_command((uint8_t*)"MY",&newmy,2) != WL_SUCCESS) {
625 625
    WL_DEBUG_PRINT("setting MY address failed\r\n");
626 626
  }
627 627
  // wait for up to 30 ms
......
1031 1031
 * @param len the size in bytes of the packet data
1032 1032
 *
1033 1033
 **/
1034
int8_t xbee_send_header(uint8_t type, uint16_t len)
1034
int8_t xbee_send_header(uint16_t len)
1035 1035
{  
1036 1036
  //packet prefix
1037 1037
  if (xbee_putc(XBEE_FRAME_START) != WL_SUCCESS)
......
1287 1287
 *
1288 1288
 * @param id the new personal area network (PAN) id
1289 1289
 **/
1290
int8_t xbee_set_pan_id(uint16_t id)
1290
int8_t xbee_set_pan(uint16_t id)
1291 1291
{
1292 1292
  if (getStatus(XBEE_COMMAND_MASK) == XBEE_COMMAND_WAIT
1293 1293
    || getStatus(XBEE_COMMAND_MASK) == XBEE_COMMAND_RESPONSE)
......
1301 1301
  while(getStatus(XBEE_COMMAND_MASK) != XBEE_COMMAND_RESPONSE && i++ < 10000) {
1302 1302
    delay_us(1); // wait 3us
1303 1303
  }
1304
  if (i < 1000 && xbee_command[0] == 'O' && xbee_command[1] == 'K')
1304
  if (i < 1000 && xbee_command[0] == 'I' && xbee_command[1] == 'D')
1305 1305
    i = WL_SUCCESS;
1306 1306
  else
1307 1307
    i = WL_ERROR_XBEE_COMMAND; // set error code
......
1315 1315
 * @return the personal area network id, or
1316 1316
 * XBEE_PAN_DEFAULT if it has not yet been set.
1317 1317
 **/
1318
uint16_t xbee_get_pan_id()
1318
uint16_t xbee_get_pan()
1319 1319
{
1320 1320
  if (getStatus(XBEE_COMMAND_MASK) == XBEE_COMMAND_WAIT
1321 1321
    || getStatus(XBEE_COMMAND_MASK) == XBEE_COMMAND_RESPONSE)
......
1330 1330
    delay_us(1); // wait 3us
1331 1331
  }
1332 1332
  if (i < 1000 && xbee_command[0] == 'I' && xbee_command[1] == 'D')
1333
    i = (xbee_command[2]<<8)|xbee_command[3]; // get PAN
1333
    i = xbee_command[2]|(xbee_command[3]<<8); // do ntoh16 coversion
1334 1334
  else
1335 1335
    i = WL_ERROR_XBEE_COMMAND_16BIT; // set error code
1336 1336
  setStatus(XBEE_COMMAND_MASK,XBEE_COMMAND_NONE); // reset status
......
1350 1350
  if (channel < 0x0B || channel > 0x1A)
1351 1351
  {
1352 1352
    WL_DEBUG_PRINT("Channel out of range.\r\n");
1353
    return -1;
1353
    return WL_ERROR_ARGUMENT;
1354 1354
  }
1355 1355

  
1356 1356
  if (getStatus(XBEE_COMMAND_MASK) == XBEE_COMMAND_WAIT
......
1365 1365
  while(getStatus(XBEE_COMMAND_MASK) != XBEE_COMMAND_RESPONSE && i++ < 10000) {
1366 1366
    delay_us(1); // wait 3us
1367 1367
  }
1368
  if (i < 1000 && xbee_command[0] == 'O' && xbee_command[1] == 'K')
1368
  if (i < 1000 && xbee_command[0] == 'C' && xbee_command[1] == 'H')
1369 1369
    i = WL_SUCCESS;
1370 1370
  else
1371 1371
    i = WL_ERROR_XBEE_COMMAND; // set error code
......
1389 1389
  int16_t i=0;
1390 1390
  // change status to command wait
1391 1391
  setStatus(XBEE_COMMAND_MASK,XBEE_COMMAND_WAIT);
1392
  xbee_send_read_at_command((uint8_t*)"ID"); // send command to get the channel
1392
  xbee_send_read_at_command((uint8_t*)"CH"); // send command to get the channel
1393 1393
  // wait for up to 30 ms
1394 1394
  while(getStatus(XBEE_COMMAND_MASK) != XBEE_COMMAND_RESPONSE && i++ < 10000) {
1395 1395
    delay_us(1); // wait 3us
1396 1396
  }
1397 1397
  if (i < 1000 && xbee_command[0] == 'C' && xbee_command[1] == 'H')
1398
    i = xbee_command[2]; // get channel
1398
    i = (int8_t)xbee_command[2]; // get channel
1399 1399
  else
1400 1400
    i = WL_ERROR_XBEE_COMMAND; // set error code
1401 1401
  setStatus(XBEE_COMMAND_MASK,XBEE_COMMAND_NONE); // reset status
......
1438 1438
  }
1439 1439
  
1440 1440
  if (i < 1000 && xbee_command[0] == 'M' && xbee_command[1] == 'Y') {
1441
    i = (xbee_command[2]<<8) | (xbee_command[3]);
1441
    i = xbee_command[2]|(xbee_command[3]<<8); // do ntoh16 coversion
1442 1442
  } else
1443 1443
    i = WL_ERROR_XBEE_COMMAND_16BIT; // set error code
1444 1444
  setStatus(XBEE_COMMAND_MASK,XBEE_COMMAND_NONE); // reset status

Also available in: Unified diff