Fixed hardware reset

pull/13/head
jgromes 2019-02-05 17:32:33 +01:00
rodzic 77caff43bf
commit 38d9677268
1 zmienionych plików z 15 dodań i 3 usunięć

Wyświetl plik

@ -23,9 +23,9 @@ int16_t XBee::begin(long speed) {
bool flagFound = false; bool flagFound = false;
uint8_t i = 0; uint8_t i = 0;
while((i < 10) && !flagFound) { while((i < 10) && !flagFound) {
// send test frame (get baudrate setting) // hardware reset should return 2 modem status frames - 1st status 0x00, second status 0x06
sendApiFrame(XBEE_API_FRAME_AT_COMMAND_QUEUE, 0x00, "BD"); int16_t state = readApiFrame(0x00, 1, 2000);
int16_t state = readApiFrame(0x00, 4, 2000); readApiFrame(0x00, 1, 2000);
if(state == ERR_NONE) { if(state == ERR_NONE) {
flagFound = true; flagFound = true;
@ -377,6 +377,8 @@ int16_t XBee::readApiFrame(uint8_t frameID, uint8_t codePos, uint16_t timeout) {
return(ERR_FRAME_MALFORMED); return(ERR_FRAME_MALFORMED);
} }
} }
DEBUG_PRINT_STR("frame data field length: ");
DEBUG_PRINTLN(numBytes);
// read the response // read the response
uint8_t* resp = new uint8_t[numBytes]; uint8_t* resp = new uint8_t[numBytes];
@ -387,8 +389,11 @@ int16_t XBee::readApiFrame(uint8_t frameID, uint8_t codePos, uint16_t timeout) {
// verify checksum // verify checksum
uint8_t checksum = 0; uint8_t checksum = 0;
for(uint16_t i = 0; i < numBytes; i++) { for(uint16_t i = 0; i < numBytes; i++) {
DEBUG_PRINT_HEX(resp[i]);
DEBUG_PRINT_STR("\t");
checksum += resp[i]; checksum += resp[i];
} }
DEBUG_PRINTLN();
if(checksum != 0xFF) { if(checksum != 0xFF) {
DEBUG_PRINTLN_HEX(checksum); DEBUG_PRINTLN_HEX(checksum);
return(ERR_FRAME_INCORRECT_CHECKSUM); return(ERR_FRAME_INCORRECT_CHECKSUM);
@ -396,7 +401,10 @@ int16_t XBee::readApiFrame(uint8_t frameID, uint8_t codePos, uint16_t timeout) {
// check frame ID // check frame ID
if(resp[1] != frameID) { if(resp[1] != frameID) {
DEBUG_PRINT_STR("received frame ID: ");
DEBUG_PRINTLN(resp[1]); DEBUG_PRINTLN(resp[1]);
DEBUG_PRINT_STR("expected frame ID: ");
DEBUG_PRINTLN(frameID);
return(ERR_FRAME_UNEXPECTED_ID); return(ERR_FRAME_UNEXPECTED_ID);
} }
@ -418,13 +426,17 @@ uint16_t XBee::getNumBytes(uint32_t timeout, size_t minBytes) {
// read response // read response
uint8_t resp[3]; uint8_t resp[3];
uint8_t i = 0; uint8_t i = 0;
DEBUG_PRINT_STR("reading frame length: ");
while(_mod->ModuleSerial->available() > 0) { while(_mod->ModuleSerial->available() > 0) {
uint8_t b = _mod->ModuleSerial->read(); uint8_t b = _mod->ModuleSerial->read();
DEBUG_PRINT_HEX(b);
DEBUG_PRINT_STR("\t");
resp[i++] = b; resp[i++] = b;
if(i == 3) { if(i == 3) {
break; break;
} }
} }
DEBUG_PRINTLN();
return((resp[1] << 8) | resp[2]); return((resp[1] << 8) | resp[2]);
} }