Open coderocket opened 8 years ago
I changed like this:
Xbee.cpp
void XBee::send(XBeeRequest &request, bool escape) {
// the new new deal
sendByte(START_BYTE, false);
// send length
uint8_t msbLen = ((request.getFrameDataLength() + 2) >> 8) & 0xff;
uint8_t lsbLen = (request.getFrameDataLength() + 2) & 0xff;
sendByte(msbLen, escape);
sendByte(lsbLen, escape);
// api id
sendByte(request.getApiId(), escape);
sendByte(request.getFrameId(), escape);
uint8_t checksum = 0;
// compute checksum, start at api id
checksum+= request.getApiId();
checksum+= request.getFrameId();
//std::cout << "frame length is " << static_cast<unsigned int>(request.getFrameDataLength()) << std::endl;
for (int i = 0; i < request.getFrameDataLength(); i++) {
// std::cout << "sending byte [" << static_cast<unsigned int>(i) << "] " << std::endl;
sendByte(request.getFrameData(i), escape);
checksum+= request.getFrameData(i);
}
// perform 2s complement
checksum = 0xff - checksum;
// std::cout << "checksum is " << static_cast
// send checksum
sendByte(checksum, escape);
// send packet (Note: prior to Arduino 1.0 this flushed the incoming buffer, which of course was not so great)
flush();
}
- Xbee.h
/**
* Sends a XBeeRequest (TX packet) out the serial port
*/
void send(XBeeRequest &request, bool escape=false);
The documentation says "To use this library your XBee must be configured in API mode (AP=2)"
@davidsainty
I am using Xbee S2C.
I have an XB24C, firmware version 4061, and when configured with AP=2 I can't transmit at all.
Setting AP=1 allows 0x11, 0x13, 0x7D, 0x7E to be sent without escaping.
Receiver logging:
payload=b'H\x11\x00H\x13\x00H}\x00H~\x00' 12 <class 'bytes'>
unsigned short data=17 index=3 --> 0x11
unsigned short data=19 index=6 --> 0x13
unsigned short data=125 index=9 --> 0x7D
unsigned short data=126 index=12 --> 0x7E
I think the S2B and S2C firmware behave differently.
I have used both S2B and S2C - so I know both do work. I can't spot your problem though, maybe the receiving end isn't handling escaping correctly?
The XBee::send method always escapes the content of the request. As a result when I send messages with an XBee configured for API mode 1,messages that contain bytes with value of 19 never get sent.