by PaulHoule · 4y ago · 0 comments
I was needing a reliable protocol to move binary data out of an Arduino into my PC and researching XMODEM I found so many things wrong with it, particularly no sane way to specify the file length and a checksum scheme that is totally inadequate. The buffer size also is a bit big for a machine with tiny RAM.
I wound up rolling my own version of
https://en.wikipedia.org/wiki/High-Level_Data_Link_Control
with much smaller packets and a carefully chosen CRC which is adequate for the task. Retrospectively I was shocked that we accepted XMODEM back in the day.
Once you've used the latter letters you never fallback. You'd never leave z to use y or leave y to use x.
At the time you wanted simple and small code.
I have modern (produced in the last couple of years) network switches at work which only support XMODEM (assuming you have to do it over serial, they also support TFTP or transfer from a USB storage device, but in the one occasion we had to use it the OS had trashed itself comprehensively enough that serial was our only option).
I think a more charitable description would be Minimum Viable Product. It was far less complex than KERMIT, and got the job done.
As soon as better options became available, we all jumped.
Still, sometimes you've got a spiffy new Toshiba laptop with 3 1/2" disk drives, MS-DOS, and nothing else. This in a house full of 8" and 5 1/4" floppies. What to do? Use debug and Copy con to pull over just enough of Xmodem from another machine, to then pull over Qmodem, then Laplink, and it's off to the races we go.
I was amazed to watch it happen.
When I found out the Arduino had no wires for FC, I practically had a histamine reaction. That killed the Arduino for me, which was too bad because I had ideas about creating something information radiators for developers and ended up with a box of parts I never touched again. And Raspberry Pi had the same issue, and although having Ethernet made that less of a problem, it didn't fix the problem I was trying to solve (how do I run a device in an organization that doesn't allow BYOD on their networks?)
I have another USB-to-serial controller I got to program my handheld ham radio that does support that, you can wire that to your Arduino and it just works...
But really it is a bad bit of cost cutting because the AVR8 is capable of very fast and reliable communications and you shouldn't need to have to add another dongle to get access to it.
And all the next generation arduino clones with built-in USB stack are just wonderful for serial data! I went over 3Mpbs on atmega32u4 device, and it came with USB flow control, so speed goes up as USB bandwidth is freed up, and connection pauses if data is not consumed, fully automatically.
>I was needing a reliable protocol to move binary data out of an Arduino into my PC
Each solution is designed to deal with the types of noise present in the signals. XMODEM may be bad for you, excellent for the phone lines it was used for. Your method may be terrible for phone line noise. XMODEM was designed to be fast and low cost to implement for the majority case. Your solution looks like it would be neither of those things.
I've made zillions of binary embedded to outside protocols. If you really want robustness, implement a nicer forward error correction protocol.
In any case having a solid understanding of the noise types you see is important to getting best performance. Examples are burst noise (likely bad or loose wiring), average noise (bad shielding), dropped bits (too low power), etc. Each can be combatted by making sure the hardware and connections are decent up to some cost point, then fight the rest with error detection and correction.
As to getting stuff from an arduino to a PC, I've gotten max speed with zero error checking to work on most every occasion, no error correction or detection, testing over many gigabytes to a terabyte, with straight serial protocols. Why is your case so noisy? Is there some physical problem or constraint on the path? I found such transfers to be so robust I no longer even worry about packets or retries for such hardware.
XMODEM was terrible over phone lines.
> I found such transfers to be so robust I no longer even worry about packets or retries for such hardware.
People say that about not having backed up their data in the last 20 years, then a lightning storm came and destroyed their data. A storm could do that with data over a cable as well. This shouldn't even be a conversation in 2022.
The system I am working on is meant to extract graphical data from a persistence of vision display that's hard to test under real conditions because it is supposed to be strapped onto a moving vehicle.
If the probability is 1% that a test isn't giving the right results because a bit got flipped on the serial line that is too much. So I want to know the data is clean and not guess about it.
Unfortunately it was not. Thus, YMODEM and ZMODEM replaced it. ZMODEM is more complex, more reliable. YMODEM is same as XMODEM, but bigger buffer if I recall correctly.
XMODEM is “simple” implementation, but maybe not “fast” or even “low cost” implementation due to time needed to debug its issues :(