XBee - reworked status codes
This commit is contained in:
parent
75bb635370
commit
357408c3a6
4 changed files with 49 additions and 49 deletions
|
@ -19,12 +19,12 @@ void setup() {
|
|||
|
||||
// initialize XBee module with baudrate 9600
|
||||
Serial.print(F("[XBee] Initializing ... "));
|
||||
byte state = bee.begin(9600);
|
||||
int state = bee.begin(9600);
|
||||
if(state == ERR_NONE) {
|
||||
Serial.println(F("success!"));
|
||||
} else {
|
||||
Serial.print(F("failed, code 0x"));
|
||||
Serial.println(state, HEX);
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
while(true);
|
||||
}
|
||||
|
||||
|
@ -36,8 +36,8 @@ void setup() {
|
|||
if(state == ERR_NONE) {
|
||||
Serial.println(F("success!"));
|
||||
} else {
|
||||
Serial.print(F("failed, code 0x"));
|
||||
Serial.println(state, HEX);
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
while(true);
|
||||
}
|
||||
}
|
||||
|
@ -47,11 +47,11 @@ void loop() {
|
|||
uint8_t dest[] = {0x00, 0x13, 0xA2, 0x00,
|
||||
0x40, 0xA5, 0x8A, 0x6B};
|
||||
Serial.print(F("[XBee] Transmitting message ... "));
|
||||
byte state = bee.transmit(dest, "Hello World!");
|
||||
int state = bee.transmit(dest, "Hello World!");
|
||||
if(state == ERR_NONE) {
|
||||
Serial.println(F("success!"));
|
||||
} else {
|
||||
Serial.print(F("failed, code 0x"));
|
||||
Serial.println(state, HEX);
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
/*
|
||||
* KiteLib XBee Transparent Operation Example
|
||||
*
|
||||
* This example transmits packets using XBee Transparent mode.
|
||||
* In Transparent mode, two XBee modules act like a Serial line.
|
||||
* Both modules must have the same PAN ID, and the destination
|
||||
* addresses have to be set properly.
|
||||
*
|
||||
* IMPORTANT: Before uploading this example, make sure that the XBee modules
|
||||
* are running AT COORDINATOR and AT ROUTER firmware!
|
||||
*/
|
||||
KiteLib XBee Transparent Operation Example
|
||||
|
||||
This example transmits packets using XBee Transparent mode.
|
||||
In Transparent mode, two XBee modules act like a Serial line.
|
||||
Both modules must have the same PAN ID, and the destination
|
||||
addresses have to be set properly.
|
||||
|
||||
IMPORTANT: Before uploading this example, make sure that the XBee modules
|
||||
are running AT COORDINATOR and AT ROUTER firmware!
|
||||
*/
|
||||
|
||||
// include the library
|
||||
#include <KiteLib.h>
|
||||
|
@ -21,47 +21,47 @@ void setup() {
|
|||
|
||||
// initialize XBee module with baudrate 9600
|
||||
Serial.print(F("[XBee] Initializing ... "));
|
||||
byte state = bee.begin(9600);
|
||||
if(state == ERR_NONE) {
|
||||
int state = bee.begin(9600);
|
||||
if (state == ERR_NONE) {
|
||||
Serial.println(F("success!"));
|
||||
} else {
|
||||
Serial.print(F("failed, code 0x"));
|
||||
Serial.println(state, HEX);
|
||||
while(true);
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
while (true);
|
||||
}
|
||||
|
||||
// set PAN ID to 0123456789ABCDEF
|
||||
Serial.print(F("[XBee] Setting PAN ID ... "));
|
||||
state = bee.setPanId("0123456789ABCDEF");
|
||||
if(state == ERR_NONE) {
|
||||
if (state == ERR_NONE) {
|
||||
Serial.println(F("success!"));
|
||||
} else {
|
||||
Serial.print(F("failed, code 0x"));
|
||||
Serial.println(state, HEX);
|
||||
while(true);
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
while (true);
|
||||
}
|
||||
|
||||
// set destination address to the address of the second module
|
||||
Serial.print(F("[XBee] Setting destination address ... "));
|
||||
state = bee.setDestinationAddress("0013A200", "40A58A5D");
|
||||
if(state == ERR_NONE) {
|
||||
if (state == ERR_NONE) {
|
||||
Serial.println(F("success!"));
|
||||
} else {
|
||||
Serial.print(F("failed, code 0x"));
|
||||
Serial.println(state, HEX);
|
||||
while(true);
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
while (true);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// XBeeSerial supports all methods of the Serial class
|
||||
// read data incoming from Serial port and write them to XBee
|
||||
while(Serial.available() > 0) {
|
||||
while (Serial.available() > 0) {
|
||||
bee.write(Serial.read());
|
||||
}
|
||||
|
||||
// read data incoming from XBee and write them to Serial port
|
||||
while(bee.available() > 0) {
|
||||
while (bee.available() > 0) {
|
||||
Serial.write(bee.read());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ XBee::XBee(Module* mod) {
|
|||
_frameID = 0x01;
|
||||
}
|
||||
|
||||
uint8_t XBee::begin(long speed) {
|
||||
int16_t XBee::begin(long speed) {
|
||||
// set module properties
|
||||
_mod->baudrate = speed;
|
||||
_mod->init(USE_UART, INT_NONE);
|
||||
|
@ -25,12 +25,12 @@ uint8_t XBee::begin(long speed) {
|
|||
return(readApiFrame(frameID, 4));
|
||||
}
|
||||
|
||||
uint8_t XBee::transmit(uint8_t* dest, const char* payload, uint8_t radius) {
|
||||
int16_t XBee::transmit(uint8_t* dest, const char* payload, uint8_t radius) {
|
||||
uint8_t destNetwork[] = {0xFF, 0xFE};
|
||||
return(transmit(dest, destNetwork, payload));
|
||||
}
|
||||
|
||||
uint8_t XBee::transmit(uint8_t* dest, uint8_t* destNetwork, const char* payload, uint8_t radius) {
|
||||
int16_t XBee::transmit(uint8_t* dest, uint8_t* destNetwork, const char* payload, uint8_t radius) {
|
||||
// build the frame
|
||||
size_t payloadLen = strlen(payload);
|
||||
size_t dataLen = 8 + 2 + 1 + 1 + payloadLen;
|
||||
|
@ -63,7 +63,7 @@ String XBee::getPacketData() {
|
|||
|
||||
}
|
||||
|
||||
uint8_t XBee::setPanId(uint8_t* panId) {
|
||||
int16_t XBee::setPanId(uint8_t* panId) {
|
||||
// build AT command
|
||||
uint8_t cmd[10];
|
||||
memcpy(cmd, "ID", 2);
|
||||
|
@ -82,7 +82,7 @@ XBeeSerial::XBeeSerial(Module* mod) : ISerial(mod) {
|
|||
|
||||
}
|
||||
|
||||
uint8_t XBeeSerial::begin(long speed) {
|
||||
int16_t XBeeSerial::begin(long speed) {
|
||||
// set module properties
|
||||
_mod->AtLineFeed = "\r";
|
||||
_mod->baudrate = speed;
|
||||
|
@ -112,7 +112,7 @@ uint8_t XBeeSerial::begin(long speed) {
|
|||
return(ERR_NONE);
|
||||
}
|
||||
|
||||
uint8_t XBeeSerial::setDestinationAddress(const char* destinationAddressHigh, const char* destinationAddressLow) {
|
||||
int16_t XBeeSerial::setDestinationAddress(const char* destinationAddressHigh, const char* destinationAddressLow) {
|
||||
// enter command mode
|
||||
DEBUG_PRINTLN_STR("Entering command mode ...");
|
||||
if(!enterCmdMode()) {
|
||||
|
@ -150,7 +150,7 @@ uint8_t XBeeSerial::setDestinationAddress(const char* destinationAddressHigh, co
|
|||
return(ERR_NONE);
|
||||
}
|
||||
|
||||
uint8_t XBeeSerial::setPanId(const char* panId) {
|
||||
int16_t XBeeSerial::setPanId(const char* panId) {
|
||||
// enter command mode
|
||||
DEBUG_PRINTLN_STR("Entering command mode ...");
|
||||
if(!enterCmdMode()) {
|
||||
|
@ -245,7 +245,7 @@ void XBee::sendApiFrame(uint8_t type, uint8_t id, uint8_t* data, uint16_t length
|
|||
delete[] frame;
|
||||
}
|
||||
|
||||
uint8_t XBee::readApiFrame(uint8_t frameID, uint8_t codePos) {
|
||||
int16_t XBee::readApiFrame(uint8_t frameID, uint8_t codePos) {
|
||||
// get number of bytes in response
|
||||
uint16_t numBytes = getNumBytes(10000, 5);
|
||||
if(numBytes == 0) {
|
||||
|
|
|
@ -37,11 +37,11 @@ class XBeeSerial: public ISerial {
|
|||
XBeeSerial(Module* mod);
|
||||
|
||||
// basic methods
|
||||
uint8_t begin(long speed);
|
||||
int16_t begin(long speed);
|
||||
|
||||
// configuration methods
|
||||
uint8_t setDestinationAddress(const char* destinationAddressHigh, const char* destinationAddressLow);
|
||||
uint8_t setPanId(const char* panID);
|
||||
int16_t setDestinationAddress(const char* destinationAddressHigh, const char* destinationAddressLow);
|
||||
int16_t setPanId(const char* panID);
|
||||
|
||||
private:
|
||||
bool enterCmdMode();
|
||||
|
@ -54,15 +54,15 @@ class XBee {
|
|||
XBee(Module* mod);
|
||||
|
||||
// basic methods
|
||||
uint8_t begin(long speed);
|
||||
uint8_t transmit(uint8_t* dest, const char* payload, uint8_t radius = 1);
|
||||
uint8_t transmit(uint8_t* dest, uint8_t* destNetwork, const char* payload, uint8_t radius = 1);
|
||||
int16_t begin(long speed);
|
||||
int16_t transmit(uint8_t* dest, const char* payload, uint8_t radius = 1);
|
||||
int16_t transmit(uint8_t* dest, uint8_t* destNetwork, const char* payload, uint8_t radius = 1);
|
||||
size_t available();
|
||||
String getPacketSource();
|
||||
String getPacketData();
|
||||
|
||||
// configuration methods
|
||||
uint8_t setPanId(uint8_t* panID);
|
||||
int16_t setPanId(uint8_t* panID);
|
||||
|
||||
private:
|
||||
Module* _mod;
|
||||
|
@ -70,7 +70,7 @@ class XBee {
|
|||
|
||||
void sendApiFrame(uint8_t type, uint8_t id, const char* data);
|
||||
void sendApiFrame(uint8_t type, uint8_t id, uint8_t* data, uint16_t length);
|
||||
uint8_t readApiFrame(uint8_t frameID, uint8_t codePos);
|
||||
int16_t readApiFrame(uint8_t frameID, uint8_t codePos);
|
||||
|
||||
uint16_t getNumBytes(uint32_t timeout = 10000, size_t minBytes = 10);
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue