[Ovmsdev] Porting code from v2 to v3

Michael Balzer dexter at expeedo.de
Thu Jul 19 18:37:23 HKT 2018


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 <mailto: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 <mailto:mark at webb-johnson.net>> wrote:
>>

-- 
Michael Balzer * Helkenberger Weg 9 * D-58256 Ennepetal
Fon 02333 / 833 5735 * Handy 0176 / 206 989 26

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openvehicles.com/pipermail/ovmsdev/attachments/20180719/43d02f6c/attachment.htm>


More information about the OvmsDev mailing list