ArduPilot / MissionPlanner

Mission Planner Ground Control Station for ArduPilot (c# .net)
http://ardupilot.org/planner/
GNU General Public License v3.0
1.68k stars 2.33k forks source link

MAVFTP: Check CRC after file upload #3308

Open IamPete1 opened 3 months ago

IamPete1 commented 3 months ago

The FTP protocol has a option to get the CRC32 checksum of a file, this could be fetched after a file upload to confirm it was uploaded correctly.

This can be currently be done manually:

Grab the CRC from the file: image

image

Then a online tool can be used to get the expected checksum from the local copy: https://www.lddgo.net/en/encrypt/crc

It needs a little custom setup to get the correct result:

image

If they don't match the file should be deleted and/or the upload give a failed warning.

meee1 commented 3 months ago

I used to do this. The issue is large files where taking to long to CRC, causing other issues

There would need to be a limit on the max size that's crc'd

IamPete1 commented 3 months ago

I guess we could add to the FTP protocol a "check CRC is x" so you would send the expected CRC and then leave the flight controller to deal with what to do if its wrong.

This all came about because of a report of scripts getting corrupted on upload . Its certainly not a common issue. https://discord.com/channels/674039678562861068/719466647710072832/1215451314700550144

I wonder if there was a bug that has now been fixed or something like that.

hunter-hall commented 3 months ago

Here is a tlog that should contain the crc error I was getting: https://drive.google.com/file/d/16BGuqd8N30H53Prg8PadIq1kyhnfnpw7/view?usp=sharing

Edit: Here are two more tlogs that are smaller in size with the same errors as the first tlog I posted above: https://drive.google.com/drive/folders/1pITjT7hwX8_a7NZpv9sovi_QU7MQGNxW?usp=sharing

hunter-hall commented 3 months ago

Update: Upon rolling back to plane v4.4.4 (with my modified lua bindings description file), it works perfectly fine and this error does not exist.

tridge commented 3 months ago

@hunter-hall i've tested uploading the plane_aerobatics.lua both with MAVProxy and MissionPlanner 1.3.81 on a Pixhawk6X on USB with no errors after 5 uploads

hunter-hall commented 3 months ago

@tridge Yeah, I'm not surprised you haven't seen this error... it seems weirdly non-deterministic. I'm sure it actually is indeed deterministic, but it only happens sometimes to me (even though I am uploading the same scripts every time). I'm thinking it might have something to do with the total number of kb of all the scripts combined... it seems to happen more often when I upload one or two large scripts vs one or two small ones (large being 4+ kb). However, it still happens sometimes when I upload 3-6 scripts that are all 1-2 kb in size. Again, I've only experienced this error in the plane 4.5.0-beta2 and the 4.6.0 dev build. The beta build was installed directly via Mission Planner and I tried a few different dev builds: one of the dev builds was my own (where I only changed one line in the lua binding descriptions file) and the others have been from builds I've done on this site: https://custom.ardupilot.org/

Also, once I do get the CRC error, my scripts will throw "syntax errors" and "unexpected symbol" errors in different lines every time I restart the board or restart scripting (even though the scripts themselves haven't changed). Eventually, I'll be able to get a good bootup/scripting restart and they work without issue, but it can take a dozen or more restarts before that happens.

This is all documented on this message (and below this message in the channel): https://discord.com/channels/674039678562861068/719466647710072832/1215451314700550144

As well as on this message (and below this message on this other channel): https://discord.com/channels/674039678562861068/797952826847920128/1217205074351095899

Edit: Also, this happens to me regardless of if I'm uploading scripts via USB, via telem radio, or via the SD card itself. This happened on two separate Pixhawk6Xs with two different SD cards and different telem radios and different USB cables.

Edit 2: Okay, I just put a new build on the board that has your crc32.py commit that you added a few hours ago on it. I haven't seen the same CRC error I was getting before (seen here: https://discord.com/channels/674039678562861068/719466647710072832/1216778004290732072) get thrown, however I am still getting all of the Lua behaviors as I was getting before as if the CRC error was thrown (i.e. seemingly random "syntax" errors and "unexpected symbol" errors that change every time I restart the board, even though the scripts themselves have not changed).