[Ovmsdev] Porting code from v2 to v3

Mark Webb-Johnson mark at webb-johnson.net
Thu Jul 19 18:46:04 HKT 2018


Best is to create a pull request, and let us know. We can check and merge with master.

Regards, Mark

> On 19 Jul 2018, at 6:41 PM, Nikolay Shishkov <nshishkov at yahoo.com> wrote:
> 
> Thank you guys!
> I think I am ready with something I want to create pull request on. Do I do this through my own repository, or can I just send someone a diff?
> Nikolay
> 
> On Thursday, July 19, 2018, 12:37:58 PM GMT+2, Michael Balzer <dexter at expeedo.de> wrote:
> 
> 
> Nikolay,
> 
> 
>> - what is the best way to compare OvmsMetricStrings? Or should I dublicate the state in an enum and use that?
>> - what is the best way to compare the OvmsMetricFloat to a literal float?
> 
> If you want to compare a state code encoded as a string, you can simply compare the std::string returned by AsString() with hard coded strings, e.g.
> 
>     std::string charge_state = StdMetrics.ms_v_charge_state->AsString();
>     if (charge_state == "charging")
>> 
> If you'd rather use the old numeric state codes, there are utility functions in the ovms_utils module for encoding / decoding them.
> 
> As Mark wrote, you get the float value by the AsFloat() method and can compare that directly to a float literal. We haven't added comparison operators to the metrics classes yet, just assignment (and that needs casts in many cases). If you'd like to add more operators/types, go ahead.
> 
> 
>> 
>>> - what is the current way of doing net_req_notification
>> 
>> Not required in v3. If you change a metric that needs notification, the serverv2 and serverv3 will act appropriately.
> 
> And if you want to customize standard notifications, you can do so by overloading the vehicle methods:
> 
>     virtual void NotifyChargeState();
>     virtual void NotifyChargeStart();
>     virtual void NotifyHeatingStart();
>     virtual void NotifyChargeStopped();
>     virtual void NotifyChargeDone();
>     virtual void NotifyValetEnabled();
>     virtual void NotifyValetDisabled();
>     virtual void NotifyValetHood();
>     virtual void NotifyValetTrunk();
>     virtual void NotifyAlarmSounding();
>     virtual void NotifyAlarmStopped();
>     virtual void Notify12vCritical();
>     virtual void Notify12vRecovered();
> 
> If you want to add vehicle specific notifications, take a look at the Twizy module (rt_notify).
> 
> You can simply send a notification from any command output by issuing MyNotify.NotifyCommand() (att: stack intensive) or send any string by MyNotify.NotifyString(). There are also varargs versions with "f" suffix acting like printf.
> 
> For building strings from command methods, there is the StringWriter class, that's a std::string that can be used as an OvmsWriter. Example:
> 
>     StringWriter buf(200);
>     CommandStat(COMMAND_RESULT_NORMAL, &buf);
>     MyNotify.NotifyString("info", "charge.sufficient", buf.c_str());
> 
> Best practice is to send notifications from within an event handler (e.g. Ticker1), so they run asynchronously in the event task context instead of blocking something.
> 
> Regards,
> Michael
> 
> PS: we should start collecting these pieces for the developer manual, the general system API is quite mature now
> 
> 
> 
>>> On 19 Jul 2018, at 6:00 AM, Nikolay Shishkov <nshishkov at yahoo.com> wrote:
>>> 
>>> Hi, 
>>> I am working on the Think City EV code and have some questions.
>>> - what is the best way to signal that the charging connector is plugged? ms_v_charge_pilot?
>>> previously it was cardoorbits1. 
>>> 
>>> - what is the best way to compare OvmsMetricStrings? Or should I dublicate the state in an enum and use that?
>>> 
>>> - what is the best way to compare the OvmsMetricFloat to a literal float?
>>> 
>>> - what is the current way of doing net_req_notification
>>> 
>>> Thanks in advance,
>>> Nikolay
>>> On Tuesday, July 17, 2018, 3:37:49 AM GMT+2, Mark Webb-Johnson <mark at webb-johnson.net> wrote:
>>> 
> 
> -- 
> Michael Balzer * Helkenberger Weg 9 * D-58256 Ennepetal
> Fon 02333 / 833 5735 * Handy 0176 / 206 989 26
> _______________________________________________
> OvmsDev mailing list
> OvmsDev at lists.openvehicles.com
> http://lists.openvehicles.com/mailman/listinfo/ovmsdev
> _______________________________________________
> OvmsDev mailing list
> OvmsDev at lists.openvehicles.com
> http://lists.openvehicles.com/mailman/listinfo/ovmsdev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openvehicles.com/pipermail/ovmsdev/attachments/20180719/1aeff048/attachment.htm>


More information about the OvmsDev mailing list