[Ovmsdev] V3 progress

HONDA S-2000 s2000 at audiobanshee.com
Mon Oct 9 04:53:37 HKT 2017

On Oct 8, 2017, at 2:40 AM, Tom Parker <tom at carrott.org> wrote:
> On 04/10/17 02:30, Mark Webb-Johnson wrote:
>> I just added the very basic ones, as a starting point and proof of concept. Hadn’t decided if I needed anything special for the bitmapped ones at the time (either a new MetricBitmap type, or extend MetricInt). Looking at how things have evolved, and bearing in mind the GAPP bluetooth stuff, and OVMS v3 MQTT, it seems that each bit should be a metric of their own. Not too hard for ovms_server_v2 to convert that back to an integer bitmap, for backwards compatibility. To do that, car_doors1 becomes:
> I fully support the concept of storing the data in the most appropriate format and serializing it into the v2 message in the v2 server code. I like the idea of storing the bit field stuff as separate boolean objects.

What are the specific advantages of having boolean "objects" as opposed to standard C bit fields? The compiler can certainly emit more efficient code for bit fields.

I almost always find an advantage to using objects in any design. However, there are also many examples where using standard C types can make the code way more efficient and execute much faster. Sometimes it's difficult to predict which way to go in a design until after you've tried out one of the options in running code.

> I don't know if you can do anything clever with C++ to use less memory while preserving a nice API within the vehicle code, but we probably have enough memory to not need to worry too much?

It may not be true of all C++ compilers, but in my embedded experience I have found that grouping all of the boolean member variables together in the class definition allows them to be automatically grouped into a bit field. As soon as you have another type interleaved between boolean member variables, the compiler no longer efficiently groups them into the same word. I have been able to save a lot of memory in embedded firmware by merely editing the class headers to change the order of member variables and move the booleans together.

I tend to avoid using C++ in my own designs, but it is sometimes possible to make good use of the language. I have noticed a trend in the industry of using C++ where it is inappropriate (e.g. only one instance of any object, and no inheritance). In other words, I think it's best not to try too hard to make everything "C++" unless you can see a distinct advantage that is only possible with that language. Good design structure is way more important than the language.

In our example, I think that the communications protocol needs to be efficient, even more so than the embedded code. With OVMS v2, we ran out of Flash and other memory, and while it seems that v3 has space to burn I wouldn't recommend being too wasteful.

Brian Willoughby

More information about the OvmsDev mailing list