Commit Graph

34 Commits

Author SHA1 Message Date
James Goppert 77da85648d Clean up formatting for AP_Common 2011-10-28 14:43:43 -04:00
Andrew Tridgell bcc2aed8fb initialise spare bits in AP_Var headers
if we ever need these bits, it would be nice to know that they are
zero in existing eeproms
2011-10-09 22:09:00 +11:00
James Goppert 71fbdf721a Added APO branch. 2011-09-28 20:51:12 -04:00
tridge60@gmail.com dab8c0cca8 AP_Var: added EEPROM wear levelling
This adds a variable length dummy variable at the front of the EEPROM
when we erase it, which has the effect of moving the location of any
hot variables within the EEPROM. This should improve EEPROM
life. Thanks to Mike for the implementation.

Pair-Programmed-With: Mike Smith

git-svn-id: https://arducopter.googlecode.com/svn/trunk@3234 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-09-04 06:39:57 +00:00
tridge60@gmail.com 06c4f60490 AP_Var: avoid wearing out EEPROM by re-writing the same value
when saving a variable, this avoids EEPROM wear by checking if the
existing value is already the same as the value being written, and
avoiding the write.

Thanks to Mike Smith for the implementation

git-svn-id: https://arducopter.googlecode.com/svn/trunk@3233 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-09-04 06:39:49 +00:00
tridge60@gmail.com e099079cc0 AP_Var: fixed a logic bug in APVar::key()
We were using && instead of & for a bit check. Thanks to Mike for
spotting this!

Pair-Programmed-With: Mike Smith

git-svn-id: https://arducopter.googlecode.com/svn/trunk@3232 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-09-04 06:39:40 +00:00
tridge60@gmail.com b8b8b7e8ca AP_Var: fill all of EEPROM with 0xFF on erase_all()
This wipes all parameter values, and also clears out any waypoints as
the waypoint format could have changed between firmware revisions.

This also ensures that the AP_Var code can't re-use any key values
from the old EEPROM state, which makes us less dependent on the old
EEPROM being in a good state

Pair-Programmed-With: Mike Smith

git-svn-id: https://arducopter.googlecode.com/svn/trunk@3231 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-09-04 06:39:28 +00:00
james.goppert 7809b0ca2a Massive warning fixes.
git-svn-id: https://arducopter.googlecode.com/svn/trunk@2089 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-05-04 19:12:27 +00:00
DrZiplok 76a5a48206 Add an interface for locating a variable by key.
git-svn-id: https://arducopter.googlecode.com/svn/trunk@1811 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-03-25 02:46:45 +00:00
tridge60@gmail.com 860998d337 implemented typesafe PSTR()
This makes PSTR() type safe by using a 1 byte wrapper
structure. Attempts to use the wrong varient of a print function will
generate a compilation error.

git-svn-id: https://arducopter.googlecode.com/svn/trunk@1797 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-03-21 07:25:48 +00:00
DrZiplok@gmail.com 5fe288dd43 Fix the return value from ::save() on AP_Var_groups so that the caller can verify that a save was successful.
git-svn-id: https://arducopter.googlecode.com/svn/trunk@1706 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-02-21 05:11:02 +00:00
DrZiplok@gmail.com e85b2d3c17 Increase the maximum save size to 64B, so that a Vector3f can be saved.
git-svn-id: https://arducopter.googlecode.com/svn/trunk@1704 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-02-21 04:42:28 +00:00
DrZiplok@gmail.com 72e112e8c0 Fix AP_Var::load - it has to ask the serialiser, not the unserialiser, for the variable's size.
Fix AP_Float16 - scaling was being done in the wrong direction, and the unserialiser wasn't reporting errors.

Add test cases for the above.


git-svn-id: https://arducopter.googlecode.com/svn/trunk@1696 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-02-20 00:38:09 +00:00
DrZiplok@gmail.com bffe20ed5e Add a little code to track the amount of memory used by AP_Var subclasses.
git-svn-id: https://arducopter.googlecode.com/svn/trunk@1661 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-02-16 07:01:17 +00:00
DrZiplok@gmail.com fabcfd942b Don't return a name for a variable if it has no name, even if it's in a group that does have a name.
When displaying variables, don't display variables with no name, or that are groups.


git-svn-id: https://arducopter.googlecode.com/svn/trunk@1656 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-02-14 17:44:33 +00:00
DrZiplok 991acad1f0 Add a constant that can be used to identify groups.
git-svn-id: https://arducopter.googlecode.com/svn/trunk@1653 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-02-14 07:11:42 +00:00
DrZiplok 61d65f652c Fix for log() being a bad idea.
git-svn-id: https://arducopter.googlecode.com/svn/trunk@1617 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-02-09 23:15:11 +00:00
DrZiplok 4632dd2f29 Implement a cast_to_float method for convenience; at a cost of a couple of bytes in the vtable this will save many callers having to play type introspection games.
It might be possible to implement a set of virtual cast operator overrides, but only float lets us return NAN to indicate that a cast can't be made, so for now we'll stick with just this one.

git-svn-id: https://arducopter.googlecode.com/svn/trunk@1614 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-02-08 10:17:45 +00:00
DrZiplok@gmail.com b58693f203 Add a function to AP_Var for finding a variable by name. It is not efficient, but convenient for e.g. interactive use.
Add pseudo-constant copies of the AP_Meta_calss::Type_id for the standard AP_VarT subclasses.  This makes checking the type of a possible AP_Var much cheaper than calling ::meta_cast, as there is no object con/destruction involved.

Add some helper functions for manipulating AP_Vars from Menu interfaces.

git-svn-id: https://arducopter.googlecode.com/svn/trunk@1541 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-23 23:58:07 +00:00
DrZiplok@gmail.com 8cc7e658b0 Simplify AP_Var_group::_serialize_unserialize slightly by removing some variables.
git-svn-id: https://arducopter.googlecode.com/svn/trunk@1535 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-23 10:04:24 +00:00
DrZiplok@gmail.com 4b21f3485a Improve performance when saving a number of variables that don't have space allocated in the EEPROM. This avoids scanning the entire EEPROM every time a variable that has not yet had space allocated is written.
git-svn-id: https://arducopter.googlecode.com/svn/trunk@1534 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-23 09:56:58 +00:00
DrZiplok@gmail.com 655f7a21ff Fix ::save_all/::load_all so that they check the correct criteria for opt-out. Now load/save_all work.
Fix prototype for AP_Var_group::serialize so that it's called correctly when saving a group.  Now group load/save works.

Add load/save_all and group load/save unit tests.

git-svn-id: https://arducopter.googlecode.com/svn/trunk@1533 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-23 09:27:58 +00:00
DrZiplok@gmail.com e7da843d90 Fixes for EEPROM space allocation and mapping.
- We can't count on the first EEPROM scan knowing about everything; new variables may be constructed later so be willing to go back and re-scan the EEPROM if we encounter a new variable that hasn't been loaded yet.
- Sort out where _key actually points (the variable's data) in the EEPROM and get everyone to use the same interpretation.
- Fix return values from ::save and ::load.
- Make it possible to re-save after ::erase_all by de-locating all variables before the EEPROM is blown away.
- Fix args to eeprom_read_block/eeprom_write_block so that we don't spam random memory.

Add unit tests for basic save/load operations.


git-svn-id: https://arducopter.googlecode.com/svn/trunk@1532 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-23 08:11:53 +00:00
DrZiplok@gmail.com 39fea200ca I never liked the plan that variable groups could only be statically scoped; it was much too fragile. These changes address that issue by splitting the global variable list into two lists, one for standalone variables (including groups), and one for variables that are members of a group.
Now a variable belonging to a group can safely be constructed before the group it belongs to, and the group can be destroyed before its member variables.  This greatly simplifies the AP_Var constructor(s).

Remove the lookup-by-index and lookup-by-key interfaces to AP_Var and replace them with first/next interfaces for all variables, and for variables belonging to a specific group.  Document their usage.  Add an accessor for the key associated with a variable so that search-by-key can be performed by a consumer.  Throw away the lookup cache implementation, as it's not required anymore.

Re-layout the EEPROM variable header and tweak the EEPROM space allocator so that it's more resistant to interruptions during variable save.

Fix the global constants so that they work.

Add an interface for erasing all variables in EEPROM (only writes one byte).

Fix unit tests so that they work with the changed interfaces.  Also tweak the unit test framework so that it doesn't inline all its code.  This is a WIP - many more tests need to be written still.


git-svn-id: https://arducopter.googlecode.com/svn/trunk@1531 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-23 06:52:59 +00:00
DrZiplok@gmail.com 39b718fce0 Implement the missing AP_Var_group::*serialize functions.
Rather than implementing empty default constructors, make sure that AP_Var and friends have useful default constructors instead.  This works around AP_Meta_class::meta_cast requiring a default constructor without having empty ctors scattered around.

Add accessors to AP_Var so that the global variable list can be traversed and the group/variable relationship comprehended by outsiders.

git-svn-id: https://arducopter.googlecode.com/svn/trunk@1523 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-22 18:42:44 +00:00
DrZiplok@gmail.com 30d9a92c4e Implement a pure data serialisation load/save model for AP_Var.
The format is a simple TLV format; a tag identifying the variable, a length for the variable, and then the actual data.  This format could ultimately be extended to include waypoint/commands as well.

This allows us to load and save groups of variables to EEPROM without having to have a static EEPROM map.

Still needs unit tests and (probably) bugfixing.

git-svn-id: https://arducopter.googlecode.com/svn/trunk@1522 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-22 08:37:52 +00:00
DrZiplok@gmail.com 96d2dc33fe Formatting and naming changes for conformance with the ArduPilot Coding Conventions.
git-svn-id: https://arducopter.googlecode.com/svn/trunk@1502 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-16 09:14:21 +00:00
DrZiplok e299d5f58a Add a flags byte to variables, and implement a "no auto load" bit that opts variables out of load_all / save_all.
git-svn-id: https://arducopter.googlecode.com/svn/trunk@1449 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-05 17:56:46 +00:00
DrZiplok c0de571afd Save AP_Var's initial value as a default value, and add a function for restoring the default value.
Fix the AP_Var::lookup cache, which was very busted.

git-svn-id: https://arducopter.googlecode.com/svn/trunk@1448 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-05 09:25:07 +00:00
DrZiplok@gmail.com 63643f73fc Move the AP_Var ctor out of the class definition; it's big enough that we don't want to inline it.
AP_Vars with either a name or an address are 'interesting' (the latter so we can save_all).

Add the concept of address offsets to scopes.  Now we have a container that we can put AP_Vars into that can be moved around in the EEPROM.  This will make it easier for things like the PID library which need to support multiple instances getting their parameters from different parts of the ROM.

Improve documentation.

Suck it up and admit that we aren't going to do "identity"-based addressing for the EEPROM and just call the property "address".



git-svn-id: https://arducopter.googlecode.com/svn/trunk@1417 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-04 08:49:55 +00:00
DrZiplok 277105c437 Rename the base class for variables AP_Var; less confusing, less to type. Rename the template type instead.
We don't need any of the arithmetic overloads, so strip them.

Fix includes.

git-svn-id: https://arducopter.googlecode.com/svn/trunk@1402 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-03 02:28:35 +00:00
DrZiplok a3a9fe59e3 Following discussions with James, a complete rewrite of AP_Var.
The overriding principle here is to keep the use of AP_Vars as simple as possible, whilst letting the implementation do useful things behind the scenes.  To that end, we define AP_Float, AP_Int8, AP_Int16 and AP_Int32.  These are strongly typed, so that there is no ambiguity about what a variable "really" is.

The classes behave like the variables they are storing; you can use an AP_Float in most places you would use a regular float; you can add to it, multiply by it, etc.  If it has been given an address in EEPROM you can load and save it.

Variables can be given names, and if they are named then they can be looked up.  This allows e.g. a GCS or a test tool to find and traffic in variables that it may not explicitly know about.

AP_Var does not attempt to solve the problem of EEPROM address space management.

git-svn-id: https://arducopter.googlecode.com/svn/trunk@1399 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-02 22:14:36 +00:00
DrZiplok 68be029a17 Don't define constant AP_Var's extern
git-svn-id: https://arducopter.googlecode.com/svn/trunk@1381 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-01 00:31:39 +00:00
james.goppert 634f2734b5 Added AP_Controller library.
git-svn-id: https://arducopter.googlecode.com/svn/trunk@1379 f9c3cf11-9bcb-44bc-f272-b75c42450872
2010-12-31 06:20:28 +00:00