Project

General

Profile

Revision 1628

got the status flag masking to work. API mode still doesn't work

View differences:

branches/wireless/code/projects/unit_tests/xbee.c
159 159
  
160 160
  WL_DEBUG_PRINT("in interrupt|status=");
161 161
  WL_DEBUG_PRINT_HEX(xbee_status);
162
  WL_DEBUG_PRINT("|frame_start=");
163
  WL_DEBUG_PRINT_HEX(apitype);
162 164
  
163 165
  // check that we're in API mode
164 166
  if (getStatus(XBEE_API_MASK) == XBEE_API_OFF || apitype != XBEE_FRAME_START) {
......
194 196
  step=10;
195 197
    
196 198
  // get length and type
199
  //apitype = 0;
197 200
  while(i<3) {
198 201
    if (FLAG) {
199 202
      if (i==0)
200 203
        len |= PORT<<8;
201 204
      else if (i==1)
202 205
        len |= PORT;
203
      else if (i==2)
206
      else if (i==2) {
204 207
        apitype = PORT;
208
        WL_DEBUG_PRINT("|GOT APITYPE");
209
      }
205 210
      i++;
206 211
    }
207 212
  }
......
335 340
      }
336 341
    }
337 342
    break; }
343
    default:
344
      WL_DEBUG_PRINT("|BAD APITYPE");
338 345
  } // end of switch statement
339 346
  while (1) {
340 347
    if (FLAG) {
......
400 407

  
401 408
/** status functions **/
402 409
inline uint8_t getStatus(uint8_t mask) { return xbee_status&mask; }
403
inline void setStatus(uint8_t mask,uint8_t value) { xbee_status = (xbee_status&(!mask))|value; }
410
void setStatus(uint8_t mask,uint8_t value) { xbee_status = ((xbee_status&(~mask))|value); }
404 411

  
405 412

  
406 413
// test interrupt
......
424 431
    return WL_ERROR_INIT_ALREADY_INITD;
425 432
  }
426 433
  
434
  // set status
435
  setStatus(XBEE_NOT_INITD,XBEE_COMMAND_NONE);
436
  
427 437
  // clear last packet buffer
428 438
  for(int i=0;i<NUM_LAST_PACKETS;i++)
429 439
    lastPacket[i].source = lastPacket[i].framenum = 0;
......
457 467
  WL_DEBUG_PRINT("|\r\n");
458 468
  sei();
459 469
 
460
  /*xbee_putc('+');
461
  xbee_putc('+');
462
  xbee_putc('+');
463
  delay_ms(1000);*/
464
  
465
  
470
  // enter command mode
466 471
  WL_DEBUG_PRINT("entering command mode\r\n");
467 472
  xbee_send_string((uint8_t*)"+++");
468 473
  xbee_wait_for_ok();
......
536 541
  return WL_ERROR_BUAD;
537 542
#endif
538 543
#endif
544
  // wait one second for the baud change to stabalize
539 545
  delay_ms(1000);
540 546

  
541 547
  // enter command mode
......
544 550
  xbee_wait_for_ok();
545 551
  WL_DEBUG_PRINT("entered command mode 2\r\n");
546 552
  
547
  if (xbee_enter_api_mode() != 0) {
553
  /*if (xbee_enter_api_mode() != 0) {
548 554
    WL_DEBUG_PRINT("can't enter api mode\r\n");
549 555
    return -1;
550
  }
556
  }*/
557
  xbee_send_string((uint8_t*)"ATAP 1\r");
558
  xbee_wait_for_ok();
551 559
  
552
  
553

  
554 560
  WL_DEBUG_PRINT("Entered api mode.\r\n");
555 561

  
556 562
  if (xbee_exit_command_mode() != 0) {
......
561 567
  
562 568
  WL_DEBUG_PRINT("Left command mode.\r\n");
563 569
  
570
    // wait one second for the baud change to stabalize
571
  delay_ms(1000);
572

  
573
  // enter command mode
574
  WL_DEBUG_PRINT("entering command mode 2\r\n");
575
  xbee_send_string((uint8_t*)"+++");
576
  xbee_wait_for_ok();
577
  WL_DEBUG_PRINT("entered command mode 2\r\n");
578
    
579
  WL_DEBUG_PRINT("before status=");
580
  WL_DEBUG_PRINT_HEX(getStatus(0xFF));
581
  WL_DEBUG_PRINT("\r\n");
582
  
583
  setStatus(XBEE_API_MASK,XBEE_API_ON); // set status
584
  
585
  WL_DEBUG_PRINT("after status=");
586
  WL_DEBUG_PRINT_HEX(getStatus(0xFF));
587
  WL_DEBUG_PRINT("\r\n");
588
  
564 589
  // TODO: we should set the MY address to the robot address from eeprom
565 590
  
566 591
  if (xbee_get_address() == WL_ERROR_XBEE_COMMAND_16BIT) {
......
568 593
  }
569 594
  WL_DEBUG_PRINT("MY address successful\r\n");
570 595
  
571
  // set status
572
  setStatus(XBEE_NOT_INITD,XBEE_COMMAND_NONE);
573 596
  
574 597
  return WL_SUCCESS;
575 598
}
......
738 761
  }
739 762
  WL_DEBUG_PRINT("got OK after entering API mode\r\n");
740 763
  
741
  setStatus(XBEE_API_MASK,XBEE_API_ON); // set status
742

  
743 764
  return WL_SUCCESS;
744 765
}
745 766

  
......
1316 1337
    return WL_ERROR_XBEE_COMMAND_16BIT; // can't do command right now
1317 1338
  
1318 1339
  uint16_t i=0;
1319
  // change status to command wait
1340
  // change status to command wait  
1341
  WL_DEBUG_PRINT("\r\nbefore status=");
1342
  WL_DEBUG_PRINT_HEX(getStatus(0xFF));
1343
  WL_DEBUG_PRINT("\r\n");
1320 1344
  setStatus(XBEE_COMMAND_MASK,XBEE_COMMAND_WAIT);
1345
  WL_DEBUG_PRINT("after status=");
1346
  WL_DEBUG_PRINT_HEX(getStatus(0xFF));
1347
  WL_DEBUG_PRINT("\r\n");
1321 1348
  xbee_send_read_at_command((uint8_t*)"MY"); // send command to get the address
1322 1349
  // wait for up to 30 ms
1323 1350
  while(getStatus(XBEE_COMMAND_MASK) != XBEE_COMMAND_RESPONSE && i++ < 10000) {

Also available in: Unified diff