PX4/Firmware — pull request #1044 by DrTon (2014-06-06 13:44:34+00:00)
Title: mavlink: count items in dataman storage on startup

@LorenzMeier, @julianoes, @thomasgubler, @jean-m-cyr
WIP, not for merging

On mavlink initialization need to read waypoints count in dataman storage to init `_wpm` and `mission` structs. But there are two storages: DM_KEY_WAYPOINTS_OFFBOARD_0 and DM_KEY_WAYPOINTS_OFFBOARD_1, and which should be used NOT saved in dataman.

Now I count always DM_KEY_WAYPOINTS_OFFBOARD_0, but it's not correct. How to do this better?
Possible solutions that I see:
- Clear unused storage once full new mission received: if reboot happens on mission transfer it will be impossible to detect which mission is old, and which is not completed new
- Use storage 0 as main and 1 as temp, at the end of receiving mission copy 1 to 0 and clear 1: some overhead + if reboot happens while copying from 1 to 0 mission will be corrupted

I.e. both ways are non-ideal. But I think we can and must do atomic mission updates properly. Lat's think together how to do this. It looks like need to extend dataman functionality to store not only data itself, but also some metadata, e.g. items count or `in progress` flags.

It looks like nobody actually thought about testing persistent missions yet :(