[Ovmsdev] V3 progress

Tom Parker tom at carrott.org
Tue Oct 10 18:39:20 HKT 2017


On 10/10/17 02:17, Mark Webb-Johnson wrote:
> But that seems strange. Is it ms_v_bat_current or ms_v_bat_i?

Oops, I originally added voltage and current as ms_v_bat_v and 
ms_v_bat_i, and you spelled out voltage, so I removed my voltage metric 
and attempted to update my current metric and missed half the changes.

>> I had trouble with method overloading and hiding in the Metrics 
>> classes and ended up giving the AsStringDefault method a unique name. 
>> The api I made also seems very clunky, do I really have to make a 
>> std::string from a constant and then pass it in? Or is it more 
>> idomatic to pass in the constant and turn it into a std::string when 
>> and if it is returned?
>
> I think the standard C++ mechanisms for providing pre-initialised 
> default values as parameters should work, so have modified the 
> AsString, AsInt, etc functions to use that. It doesn’t change a normal 
> call (so current behaviour is unchanged), but does give you a way of 
> providing a default value for undefined metrics.

Yes, this is very much what I wanted, it didn't occur to me that C++ 
supported default values for arguments. I've updated my code to use the 
default argument method.

> I re-worked my tpms example, to use std::string:

...

> What do you think of that? It looks better, but I still don’t really 
> like all those append(“,”) lines.

Much better. I too didn't like how the commas were added. I had a read 
of https://stackoverflow.com/questions/1430757/c-vector-to-string and 
wasn't sure which answer was most appropriate. Given we're going to have 
quite a few different v2 messages, I think it is worth serializing each 
field in the message into members of an array and then programmatically 
serializing that to a comma separated string, such as the following 
pastiche of Java and our code:

std:string message[] = {
   StandardMetrics.ms_v_bat_soc->AsString("0"),
   StandardMetrics.ms_v_bat_range_ideal->AsString("0"),
   StandardMetrics.ms_v_bat_range_est->AsString("0"),
   ...
};

buffer = "MP-0 S" + String.join(",", message);

> Can you try to re-work your code, to use these three new things, and 
> then re-submit a pull request?

I've reworked it, will test and update the pull request tomorrow.

> I think this is related to the sdkconfig. Anyway, I removed the 
> components/spiffs (as we don’t use it), and it now compiles.
>
> I also created a sdkconfig.default that developers can copy to 
> sdkconfig, to provide a good set of defaults. You should also be able 
> to diff it, to see anything changed.

Thanks it is compiling again.

I'll test the vfs append tomorrow too




More information about the OvmsDev mailing list