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

Problems handling XMODEM protocol packets #13

Open
SteMMo33 opened this issue May 31, 2024 · 0 comments
Open

Problems handling XMODEM protocol packets #13

SteMMo33 opened this issue May 31, 2024 · 0 comments

Comments

@SteMMo33
Copy link

hello,
thanks a lot for your serial-port examples: I'm interested in particular into 2_with_timeout sample.

Implementing XMODEM protocol I'm able to read the 'standard' 133-bytes packet, but the last packet has only 1 byte (EOT = 0x04).
To avoid the timeout exception on the last packet I initially read only 1 byte and, if different from EOT, I read the remaining 133-1 bytes.

		_serialPort.setTimeout( boost::posix_time::millisec(timeout));

		char data[XMODEM_PACKET_LENGTH];

		try {
			// Per non far andare in timeout ..
			_serialPort.read( data, 1);
			// .. eventualmente il resto del pacchetto (-1)
			if (data[0] != XMODEM_CHARS_EOT)
			{
				// Resto del pacchetto
				_serialPort.read( (char*)(data+1), XMODEM_PACKET_LENGTH-1);

				std::cout << ">> '";
				for(auto i:data)
					std::cout << i;
				std::cout << "'" << std::endl;

				_XModemReceiveResponse = std::vector<byte>( data, data + XMODEM_PACKET_LENGTH);
			}
			else {
				std::cout << "[WaitForXModemResponse] EOT !!" << std::endl;
				_XModemReceiveResponse = std::vector<byte>( data, data + 1);
			}
		}
		catch (timeout_exception){
                   ...

In this way I have randomly packet error caused by a data misalignment in the data buffer.
This is my log:

image

Packet 22 (and previous ones) is ok, for packet 23 the data buffer is filled 1 position ahead (?) ...
I checked the USB packet and it doesn't contain the char in first position ('M' in this case):

image

If I run the program without this hack, but only with:
_serialPort.read( data, XMODEM_PACKET_LENGTH);
I have not problem at all, only the last 1-bytes packet causes the timeout_exception (waiting 133 bytes ..).

Any idea?
thanks a lot !!

@SteMMo33 SteMMo33 changed the title Problems handling XMODEM protocol Problems handling XMODEM protocol packets May 31, 2024
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

1 participant