<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Nikolay,<br>
<br>
<blockquote type="cite"
cite="mid:354FB8DC-0A4B-4D47-A8B1-12CAA0E107BB@webb-johnson.net">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<blockquote type="cite" class="">
<div class="">
<div class="" style="font-family: "Helvetica Neue",
Helvetica, Arial, sans-serif; font-size: 13px;">
<div class="">
<div class="">
<div class="">- what is the best way to compare
OvmsMetricStrings? Or should I dublicate the state in
an enum and use that?</div>
<div class="">- what is the best way to compare the
OvmsMetricFloat to a literal float?</div>
</div>
</div>
</div>
</div>
</blockquote>
</blockquote>
<br>
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.<br>
<br>
<tt> std::string charge_state =
StdMetrics.ms_v_charge_state->AsString();</tt><tt><br>
</tt><tt> if (charge_state == "charging")</tt><tt><br>
</tt><tt> …</tt><tt><br>
</tt><br>
If you'd rather use the old numeric state codes, there are utility
functions in the ovms_utils module for encoding / decoding them.<br>
<br>
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.<br>
<br>
<br>
<blockquote type="cite"
cite="mid:354FB8DC-0A4B-4D47-A8B1-12CAA0E107BB@webb-johnson.net"><br
class="">
<blockquote type="cite" class="">
<div class="">
<div class="" style="font-family: "Helvetica Neue",
Helvetica, Arial, sans-serif; font-size: 13px;">
<div class="">
<div class="">
<div class="">- what is the current way of doing <span
class="">net_req_notification</span></div>
</div>
</div>
</div>
</div>
</blockquote>
<div><br class="">
</div>
<div>Not required in v3. If you change a metric that needs
notification, the serverv2 and serverv3 will act appropriately.</div>
</blockquote>
<br>
And if you want to customize standard notifications, you can do so
by overloading the vehicle methods:<br>
<br>
<tt> virtual void NotifyChargeState();</tt><tt><br>
</tt><tt> virtual void NotifyChargeStart();</tt><tt><br>
</tt><tt> virtual void NotifyHeatingStart();</tt><tt><br>
</tt><tt> virtual void NotifyChargeStopped();</tt><tt><br>
</tt><tt> virtual void NotifyChargeDone();</tt><tt><br>
</tt><tt> virtual void NotifyValetEnabled();</tt><tt><br>
</tt><tt> virtual void NotifyValetDisabled();</tt><tt><br>
</tt><tt> virtual void NotifyValetHood();</tt><tt><br>
</tt><tt> virtual void NotifyValetTrunk();</tt><tt><br>
</tt><tt> virtual void NotifyAlarmSounding();</tt><tt><br>
</tt><tt> virtual void NotifyAlarmStopped();</tt><tt><br>
</tt><tt> virtual void Notify12vCritical();</tt><tt><br>
</tt><tt> virtual void Notify12vRecovered();</tt><br>
<br>
If you want to add vehicle specific notifications, take a look at
the Twizy module (rt_notify).<br>
<br>
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.<br>
<br>
For building strings from command methods, there is the StringWriter
class, that's a std::string that can be used as an OvmsWriter.
Example:<br>
<br>
<tt> StringWriter buf(200);</tt><tt><br>
</tt><tt> CommandStat(COMMAND_RESULT_NORMAL, &buf);</tt><tt><br>
</tt><tt> MyNotify.NotifyString("info", "charge.sufficient",
buf.c_str());</tt><br>
<br>
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.<br>
<br>
Regards,<br>
Michael<br>
<br>
PS: we should start collecting these pieces for the developer
manual, the general system API is quite mature now<br>
<br>
<br>
<blockquote type="cite"
cite="mid:354FB8DC-0A4B-4D47-A8B1-12CAA0E107BB@webb-johnson.net">On
19 Jul 2018, at 6:00 AM, Nikolay Shishkov <<a
href="mailto:nshishkov@yahoo.com" class=""
moz-do-not-send="true">nshishkov@yahoo.com</a>> wrote:
<div>
<blockquote type="cite" class=""><br
class="Apple-interchange-newline">
<div class="">
<div class="">
<div style="font-family:Helvetica Neue, Helvetica, Arial,
sans-serif;font-size:13px;" class="">
<div style="font-family:Helvetica Neue, Helvetica,
Arial, sans-serif;font-size:13px;" class="">
<div style="font-family:Helvetica Neue, Helvetica,
Arial, sans-serif;font-size:13px;" class="">
<div class="">Hi, </div>
<div class="">I am working on the Think City EV code
and have some questions.</div>
<div class="">- what is the best way to signal that
the charging connector is plugged?
ms_v_charge_pilot?</div>
<div class="">previously it was cardoorbits1. </div>
<div class=""><br class="">
</div>
<div class="">- what is the best way to compare
OvmsMetricStrings? Or should I dublicate the state
in an enum and use that?</div>
<div class=""><br class="">
</div>
<div class="">- what is the best way to compare the
OvmsMetricFloat to a literal float?</div>
<div class=""><br class="">
</div>
<div class="">- what is the current way of doing <span
class="">net_req_notification</span></div>
<div class=""><br class="">
</div>
<div class="">Thanks in advance,</div>
<div class="">Nikolay</div>
</div>
</div>
<div id="yahoo_quoted_1950539485" class="yahoo_quoted">
<div style="font-family:'Helvetica Neue', Helvetica,
Arial, sans-serif;font-size:13px;color:#26282a;"
class="">
<div class=""> On Tuesday, July 17, 2018, 3:37:49 AM
GMT+2, Mark Webb-Johnson <<a
href="mailto:mark@webb-johnson.net" class=""
moz-do-not-send="true">mark@webb-johnson.net</a>>
wrote: </div>
<br>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</blockquote>
<br>
<pre class="moz-signature" cols="160">--
Michael Balzer * Helkenberger Weg 9 * D-58256 Ennepetal
Fon 02333 / 833 5735 * Handy 0176 / 206 989 26
</pre>
</body>
</html>