Commit Graph

84 Commits

Author SHA1 Message Date
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 e2d4c9e901 Use a more explicit loop termination condition.
git-svn-id: https://arducopter.googlecode.com/svn/trunk@1657 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-02-14 17:49:02 +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@gmail.com 0b60757b43 Add a template AP_VarS that handles arbitrary structure/class types.
Note that the object must still be <= 32 bytes in size to be saved/loaded.


git-svn-id: https://arducopter.googlecode.com/svn/trunk@1644 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-02-14 01:47:24 +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 b614aca274 Add a template AP_VarA that defines a variable that is an array of some basic type. This is like AP_VarT for arrays, with minor changes in behaviour consistent with the difference between regular variables and arrays.
Note that AP_VarA arrays are still limited by the constraints on the total size of a variable (AP_Var::k_size_max).

Add a basic unit test for arrays; more are needed.

git-svn-id: https://arducopter.googlecode.com/svn/trunk@1579 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-30 20:58:34 +00:00
DrZiplok@gmail.com ca0005db2a Comments, minor consting, use a better target for sizeof in AP_VarT
git-svn-id: https://arducopter.googlecode.com/svn/trunk@1578 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-30 20:14:42 +00:00
DrZiplok@gmail.com b60480fac0 Minor whitespace fixes.
git-svn-id: https://arducopter.googlecode.com/svn/trunk@1577 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-30 20:13:07 +00:00
DrZiplok c18fd76449 Try to pre-empt subsequent inclusions of wiring.h by grabbing it here and giving ourselves a chance to undo some of the less well-advised macros it defines.
git-svn-id: https://arducopter.googlecode.com/svn/trunk@1554 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-24 02:44:31 +00:00
DrZiplok@gmail.com 34f43934da Move the unit test framework out of the unit tests. Add unit tests for the k_typeid_* constants.
git-svn-id: https://arducopter.googlecode.com/svn/trunk@1543 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-23 23:59:26 +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 2caea855cd Don't include AP_Vector (in preparation for retirement) and AP_Loop (because it's not being used by APM*). Interested clients can still include AP_Loop if they need it.
git-svn-id: https://arducopter.googlecode.com/svn/trunk@1540 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-23 23:48:07 +00:00
DrZiplok@gmail.com 2f263229f9 Rename AP_Meta_class::AP_Type_id to AP_Meta_class::Type_id in keeping with the coding standard.
Add a non-static version of AP_Meta_class::meta_cast that can be used against any subclass object directly.

git-svn-id: https://arducopter.googlecode.com/svn/trunk@1539 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-23 23:46:58 +00:00
DrZiplok 8c9ece1f37 Fix a serious typo, add more documentation.
git-svn-id: https://arducopter.googlecode.com/svn/trunk@1538 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-23 20:33:20 +00:00
DrZiplok 7a3d33844a Move the Test unit test framework out into its own header, so that it can be used by other libraries.
Add some documentation explaining how it is used.

git-svn-id: https://arducopter.googlecode.com/svn/trunk@1537 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-23 20:26:11 +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 de71731994 Add a templated version of AP_Meta_class::meta_type_id so that you can get a type ID for any named type without having to have an instance of the type lying around. Update the comments about caching type IDs to reflect its availability.
Fix the comments around AP_Meta_class::meta_cast; they were leftovers from an earlier implementation and entirely not helpful.


git-svn-id: https://arducopter.googlecode.com/svn/trunk@1530 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-23 06:44:07 +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
james.goppert 05622fe225 Updated AP_RcChannel for AP_Var.
git-svn-id: https://arducopter.googlecode.com/svn/trunk@1509 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-18 04:56:45 +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 aaf125e441 Based on explaining AP_VarNoAddress to Doug, improve the description of the value.
git-svn-id: https://arducopter.googlecode.com/svn/trunk@1491 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-12 02:43:25 +00:00
DrZiplok@gmail.com dd6ede36ee Add more unit tests for AP_Var.
git-svn-id: https://arducopter.googlecode.com/svn/trunk@1466 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-10 01:44:23 +00:00
DrZiplok@gmail.com 6366cdc094 Add more documentation for AP_MetaClass.
git-svn-id: https://arducopter.googlecode.com/svn/trunk@1465 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-10 01:43:41 +00:00
DrZiplok@gmail.com 44cac7a853 Add a new macro PROGMEM_STRING that can be used to define a constant string in program memory.
This is a partial workaround for not being able to use PSTR at global scope, e.g. in an argument to a constructor; it makes the intent of the otherwise somewhat bulky declaration of the string more obvious.

git-svn-id: https://arducopter.googlecode.com/svn/trunk@1464 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-10 01:42:59 +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 0e868ca343 More unit tests.
git-svn-id: https://arducopter.googlecode.com/svn/trunk@1447 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-05 07:40:35 +00:00
DrZiplok 765cef724d Fix the assignment operator overload for AP_VarT so that direct assignments to the type work correctly.
Add a variant of AP_Float that stores the value as Q5.10 (16-bit fixed-point) to save EEPROM space.


git-svn-id: https://arducopter.googlecode.com/svn/trunk@1446 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-05 07:40:06 +00:00
DrZiplok@gmail.com d8046957c6 Unit tests for scope-based address offsetting.
git-svn-id: https://arducopter.googlecode.com/svn/trunk@1418 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-04 08:50:24 +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@gmail.com d2bd744244 Metaclass improvements:
- Add a default ctor/dtor pair.  The dtor ensures that all dtors are virtual, and guarantees that there is something in the dtor vtable slot for classes that don't implement their own.
 - serialize must not alter the class, mark it const
 - Improve documentation
 - Fix handle validation to prevent trying to read 2 bytes beyond the end of memory


git-svn-id: https://arducopter.googlecode.com/svn/trunk@1416 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-04 08:46:01 +00:00
DrZiplok 57f3f4e65b Beef up the unit tests for AP_Var. Most of the basic functionality is now covered.
git-svn-id: https://arducopter.googlecode.com/svn/trunk@1403 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-03 02:29:17 +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 ea9c7859f8 Don't allow the default serialize/unserialize to be inlined.
Fix some includes and remove an old implementation of meta_cast.

git-svn-id: https://arducopter.googlecode.com/svn/trunk@1401 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-03 02:26:18 +00:00
DrZiplok a02136236f Add the ability to find the sketchbook when called from a Makefile in a library example.
git-svn-id: https://arducopter.googlecode.com/svn/trunk@1400 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-01-02 22:16:21 +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
james.goppert 8bc3fc599d Fixed casting issues with EEPROM Registry
git-svn-id: https://arducopter.googlecode.com/svn/trunk@1371 f9c3cf11-9bcb-44bc-f272-b75c42450872
2010-12-30 06:46:40 +00:00
james.goppert 86feb8bf7b Fixed issues with RcChannel EEPROM var ownership.
git-svn-id: https://arducopter.googlecode.com/svn/trunk@1369 f9c3cf11-9bcb-44bc-f272-b75c42450872
2010-12-30 05:25:28 +00:00
DrZiplok 23e78d0f4b Fix/improve depdendency handling. Deps are autogenerated on the first compile pass and consumed on subsequent builds. This helps work around the difficulty of building the 'clean' target with Eclipse.
Don't depend on the build directory anywhere; we automake it as required.



git-svn-id: https://arducopter.googlecode.com/svn/trunk@1368 f9c3cf11-9bcb-44bc-f272-b75c42450872
2010-12-30 03:45:50 +00:00
DrZiplok 7bc153f038 More awk-related changes. mawk hangs on the parser scripts, so try gawk; it's what we'll need for cygwin anyway.
git-svn-id: https://arducopter.googlecode.com/svn/trunk@1367 f9c3cf11-9bcb-44bc-f272-b75c42450872
2010-12-30 03:20:33 +00:00
DrZiplok f0f13752d0 We need TOOLPATH even when ARDUINO is defined. Refactor.
git-svn-id: https://arducopter.googlecode.com/svn/trunk@1366 f9c3cf11-9bcb-44bc-f272-b75c42450872
2010-12-30 02:25:55 +00:00