<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Tom,<div class=""><br class=""></div><div class="">Thanks for your help with this. It is useful to have a different set of eyes on the problem, and see some alternative approaches.</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""> It doesn't use any of your new metrics except battery voltage</blockquote><br class=""></div><div class="">You seem to have added:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">+    #define MS_V_BAT_CURRENT            “v.b.current"</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">+    OvmsMetricFloat*  ms_v_bat_v;<br class="">+    OvmsMetricFloat*  ms_v_bat_i;</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">+    ms_v_bat_current = new OvmsMetricFloat(MS_V_BAT_CURRENT, SM_STALE_MID);</span></font></div></blockquote><div class=""><br class=""></div><div class="">But that seems strange. Is it ms_v_bat_current or ms_v_bat_i?</div><div class=""><br class=""></div><div class="">What is this MS_V_BAT_CURRENT? Presumably some sort of instantaneous current reading from the battery? If so, probably best to put it just after MS_V_BAT_VOLTAGE, as:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class="">#define MS_V_BAT_CURRENT            “v.b.current"</div><div class="">OvmsMetricInt*    ms_v_bat_current</div><div class="">ms_v_bat_current = new OvmsMetricInt(MS_V_BAT_CURRENT, SM_STALE_MID);</div></blockquote><div class=""><br class=""></div><div class=""><blockquote type="cite" class="">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?</blockquote><br class=""></div><div class="">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.</div><div class=""><br class=""></div><div class="">For example, for OvmsMetricBool, we have:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">    std::string AsString(const char* defvalue = "");</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class=""><br class=""></span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">    int AsBool(const bool defvalue = false);</span></font></div></div></blockquote><div class=""><br class=""></div><div class="">Let’s look at the implementation of AsBool():</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div class=""><font face="Andale Mono" style="font-size: 14px;" class="">int OvmsMetricBool::AsBool(const bool defvalue)</font></div><div class=""><font face="Andale Mono" style="font-size: 14px;" class="">  {</font></div><div class=""><font face="Andale Mono" style="font-size: 14px;" class="">  if (m_defined)</font></div><div class=""><font face="Andale Mono" style="font-size: 14px;" class="">    return m_value;</font></div><div class=""><font face="Andale Mono" style="font-size: 14px;" class="">  else</font></div><div class=""><font face="Andale Mono" style="font-size: 14px;" class="">    return defvalue;</font></div><div class=""><font face="Andale Mono" style="font-size: 14px;" class="">  }</font></div></div></blockquote><div class=""><br class=""></div><div class="">So, you can call metric->AsBool(true) to make ‘true’ the default. Or metric->AsString(“undefined") to make “undefined” the default.</div><div class=""><br class=""></div><div class="">I’ve pushed this, and I think it should satisfy your requirements. Can you modify to adopt this?</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class="">I don't like the fixed size buffer to construct the message, I copied the TPMS message code, and not knowing the "right" way to do it in this embedded C++, I just cargo culted it together. I'd be much happier if we at least used something that was aware of how big the buffer was and failed more gracefully than overflowing.</blockquote><br class=""></div><div class="">You’re right, it is ugly and dangerous.</div><div class=""><br class=""></div><div class="">I re-worked my tpms example, to use std::string:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">  std::string buffer;</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">  buffer.reserve(512);</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">  buffer.append("MP-0 W");</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">  buffer.append(StandardMetrics.ms_v_tpms_fr_p->AsString());</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">  buffer.append(",”);</span></font></div></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">  ...</span></font></div></blockquote><div class=""><br class=""></div><div class="">That pre-allocates 512 bytes (for performance), but can grow if that reserved size is exceeded.</div><div class=""><br class=""></div><div class="">What do you think of that? It looks better, but I still don’t really like all those append(“,”) lines.</div><div class=""><br class=""></div><div class="">Can you try to re-work your code, to use these three new things, and then re-submit a pull request?</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class="">I tried an SD card and it didn't work. How do I hard code or otherwise inject some startup commands without an SD card?</blockquote><br class=""></div><div class="">I’m working with the China guys on SD CARD to try to find out why it is working for them but not us.</div><div class=""><br class=""></div><div class="">In the meantime, Steve made a ‘vfs append’ command:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">vfs append <quoted line> <file></span></font></div></blockquote><div class=""><br class=""></div><div class="">You can use /store to create an event script:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">vfs mkdir /store/scripts</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class=""><br class=""></span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">vfs mkdir /store/scripts/system.start</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">vfs append “wifi mode client <SSID>” /store/scripts/system.start/startmeup</span></font></div><div class=""><span style="font-family: 'Andale Mono'; font-size: 14px;" class="">vfs append “vehicle module NL” /store/scripts/system.start/startmeup</span></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class=""><br class=""></span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">vfs mkdir /store/scripts/</span></font><span style="font-size: 14px; font-family: 'Andale Mono';" class="">network.up</span></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">vfs append “server v2 start” /store/scripts/network.up/startmeup</span></font></div></blockquote><div class=""><br class=""></div><div class="">Untested, so may not be perfect, but I think you get the idea…</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class="">Since I rebased onto the current master, things don't compile:<br class=""><br class="">/vagrant/Open-Vehicle-Monitoring-System-3/vehicle/OVMS.V3/components/spiffs/./spiffs_vfs.c: In function 'vfs_spiffs_fstat’:</blockquote><br class=""></div><div class="">I think this is related to the sdkconfig. Anyway, I removed the components/spiffs (as we don’t use it), and it now compiles.</div><div class=""><br class=""></div><div class="">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.</div><div class=""><br class=""></div><div class="">Regards, Mark.</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 9 Oct 2017, at 6:10 PM, Tom Parker <<a href="mailto:tom@carrott.org" class="">tom@carrott.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">On 09/10/17 03:29, Mark Webb-Johnson wrote:<br class=""><br class=""><blockquote type="cite" class="">Do the best you can, and if you can’t work out how to get something in particular, let me know or leave it as a “TODO” marked in the code.<br class=""></blockquote><br class="">Thanks for adding the metrics. I sent a pull request with an initial implementation of the Stat message. It doesn't use any of your new metrics except battery voltage (I'd already added that one) and I wedged sending it into a nearby loop which is almost certainly the wrong place, but it works and I was able to send telemetry from a real car today using a wifi hotspot for network connectivity.<br class=""><br class="">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?<br class=""><br class="">I don't like the fixed size buffer to construct the message, I copied the TPMS message code, and not knowing the "right" way to do it in this embedded C++, I just cargo culted it together. I'd be much happier if we at least used something that was aware of how big the buffer was and failed more gracefully than overflowing.<br class=""><br class="">I tried an SD card and it didn't work. How do I hard code or otherwise inject some startup commands without an SD card? I tried tracing through the command code but quickly decided it was easier to just start the vehicle module, wifi and v2 server with my laptop in monitor mode.<br class=""><br class="">Since I rebased onto the current master, things don't compile:<br class=""><br class="">/vagrant/Open-Vehicle-Monitoring-System-3/vehicle/OVMS.V3/components/spiffs/./spiffs_vfs.c: In function 'vfs_spiffs_fstat':<br class="">/vagrant/Open-Vehicle-Monitoring-System-3/vehicle/OVMS.V3/components/spiffs/./spiffs_vfs.c:344:22: error: 'CONFIG_SPIFFS_LOG_PAGE_SIZE' undeclared (first use in this function)<br class="">     st->st_blksize = CONFIG_SPIFFS_LOG_PAGE_SIZE;<br class=""><br class="">_______________________________________________<br class="">OvmsDev mailing list<br class=""><a href="mailto:OvmsDev@lists.teslaclub.hk" class="">OvmsDev@lists.teslaclub.hk</a><br class="">http://lists.teslaclub.hk/mailman/listinfo/ovmsdev<br class=""></div></div></blockquote></div><br class=""></div></body></html>