Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XBee::send always escapes #21

Open
coderocket opened this issue Feb 4, 2016 · 4 comments
Open

XBee::send always escapes #21

coderocket opened this issue Feb 4, 2016 · 4 comments

Comments

@coderocket
Copy link

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.

@nopnop2002
Copy link

nopnop2002 commented Apr 24, 2023

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<unsigned int>(checksum) << std::endl;

	// 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);

@davidsainty
Copy link

The documentation says "To use this library your XBee must be configured in API mode (AP=2)"

@nopnop2002
Copy link

nopnop2002 commented Apr 24, 2023

@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.

xctu-6

@davidsainty
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants