<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="">Edwards.<div class=""><br class=""></div><div class="">First I’ve heard of this, but it doesn’t surprise me.</div><div class=""><br class=""></div><div class="">Testing this sort of stuff is not particularly easy. What we have done in the past is put in a DIAG mode command to allow this function to be called with a given string parameter, and then to print the result. Then, we can script up something to feed in a bunch of input and see what the output is like. But, that does require physical hardware.</div><div class=""><br class=""></div><div class="">Perhaps also the function could just be run in a standalone C program on the mac? So long as the type sizes are the same, the results should be equivalent (perhaps with some float rounding differences in the original version).</div><div class=""><br class=""></div><div class="">Regards, Mark.</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 2 Feb 2017, at 4:38 AM, Edward Cheeseman <<a href="mailto:cheesemanedward@gmail.com" class="">cheesemanedward@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 23/01/2017, at 8:12 PM, Edward Cheeseman wrote:</div><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><font face="Courier New" class="">I’ve started rewriting gps2latlon() to use a long long (64bit) integer multiply and divide.</font></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><font face="Courier New" class="">I see reference to SIM808 and 908 on an arduino shield, so I might have a look to see what they have done.</font></div></div></blockquote></div><br class=""><div class="">
<span class="Apple-style-span" style="border-collapse: separate; font-variant-ligatures: normal; font-variant-position: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; widows: 2; border-spacing: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; font-variant-ligatures: normal; font-variant-position: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; widows: 2; border-spacing: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="font-family: Helvetica; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;" class="">I totally overestimated the pic18F capability.</div><div style="font-family: Helvetica; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;" class="">So it turns out the C18, and for that matter, the XC8 compilers treat long long the same as long - 32bit.</div><div style="font-family: Helvetica; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;" class="">This of course isn’t news to anyone who has been working with this processor.</div><div style="font-family: Helvetica; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;" class="">So, given the floating point library has been pulled in anyway, I think the current implementation isn’t too bad.</div><div style="font-family: Helvetica; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;" class="">Floating point accuracy:</div><div class="">- The equatorial circumference of the Earth is 40,075,017 meters. </div><div style="font-family: Helvetica; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;" class="">- Divided by 23bit, resolution is 4.8meters</div><div style="font-family: Helvetica; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;" class="">The math is probably unrounded, so probably the best you could hope for is within 10 meters.</div><div style="font-family: Helvetica; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;" class="">I think the following is an improvement in speed (no divides), variables used and accuracy (should be as good as received from the GPS), but these claims are yet to be proved. Readability has taken a hit.</div><div style="font-family: Helvetica; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;" class="">I’ve tried to set up the ide on a mac. I’ve got it to compile with the following code but haven’t tested it yet (can’t figure out how to simulate or view assembler output, don’t have a programmer)</div><div style="font-family: Helvetica; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;" class="">If you think this is worth adding in please point me in a direction that I can test it. At some point I will get a programmer, but I only have the one unit for my car so bench testing is a bit hard.</div><div style="font-family: Helvetica; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;" class="">Edward</div><div style="font-family: Helvetica; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;" class="">--------------utils.c snip--------------------</div><div class=""><div class="">/<font face="Courier" class="">/ Convert GPS coordinate form to internal latlon value</font></div><div class=""><font face="Courier" class="">// SIM908: DDDMM.MMMMMM (separate South/West handling, see net.c)</font></div><div class=""><font face="Courier" class="">// SIM808: +-ddd.dddddd</font></div><div class=""><font face="Courier" class=""><br class=""></font></div><div class=""><font face="Courier" class="">long gps2latlon(char *gpscoord)</font></div><div class=""><font face="Courier" class="">{</font></div><div class=""><font face="Courier" class=""> signed int degrees;</font></div><div class=""><font face="Courier" class=""> unsigned int rem;</font></div><div class=""><font face="Courier" class=""> long frac;</font></div><div class=""><font face="Courier" class=""> char *s;</font></div><div class=""><font face="Courier" class=""><br class=""></font></div><div class=""><font face="Courier" class=""> degrees = atoi(gpscoord); //use built-in to read integer value</font></div><div class=""><font face="Courier" class=""><br class=""></font></div><div class=""><font face="Courier" class="">#ifdef OVMS_SIMCOM_SIM908 // SIM908: DDDMM.MMMM</font></div><div class=""><font face="Courier" class=""> frac = degrees % 100; // extract minutes</font></div><div class=""><font face="Courier" class=""> degrees /= 100; // fix degrees</font></div><div class=""><font face="Courier" class=""> rem = 4;</font></div><div class=""><font face="Courier" class="">#define GPS_DIVIDER ((unsigned long) 3221225) //(3600 * 2048 / 600000) * 2**18</font></div><div class=""><font face="Courier" class="">#else //SIM808: (-)DDD.DDDDDD</font></div><div class=""><font face="Courier" class=""> frac = 0;</font></div><div class=""><font face="Courier" class=""> rem = 6;</font></div><div class=""><font face="Courier" class="">#define GPS_DIVIDER ((unsigned long) 1932735) //(3600 * 2048 / 1000000) * 2**18</font></div><div class=""><font face="Courier" class="">#endif //OVMS_SIMCOM_SIM908</font></div><div class=""><font face="Courier" class=""><br class=""></font></div><div class=""><font face="Courier" class=""> if ( (s = strchr(gpscoord, '.')) )</font></div><div class=""><font face="Courier" class=""> {</font></div><div class=""><font face="Courier" class=""> while (*++s) //read and scale fractional part</font></div><div class=""><font face="Courier" class=""> {</font></div><div class=""><font face="Courier" class=""> if( (unsigned char)(*s - '0') > (unsigned char) 9 )</font></div><div class=""><font face="Courier" class=""> break; //check for non-decimal</font></div><div class=""><font face="Courier" class=""> frac = frac * 10 + (*s - '0');</font></div><div class=""><font face="Courier" class=""> if(--rem==0) //check for too many decimal places</font></div><div class=""><font face="Courier" class=""> break;</font></div><div class=""><font face="Courier" class=""> }</font></div><div class=""><font face="Courier" class=""> while (rem--!=0) //make up missing digits with zeros</font></div><div class=""><font face="Courier" class=""> {</font></div><div class=""><font face="Courier" class=""> frac = frac * 10;</font></div><div class=""><font face="Courier" class=""> }</font></div><div class=""><font face="Courier" class=""> //fractional part is at most 20bits (999999 < 2^20)</font></div><div class=""><font face="Courier" class=""> //multiply 10bits at a time with 22bit constant to keep within 32bits</font></div><div class=""><font face="Courier" class=""> //then bit shift into place and accumulate</font></div><div class=""><font face="Courier" class=""> //(reuse rem here to reduce memory requirement)</font></div><div class=""><font face="Courier" class=""> rem = (unsigned long)(((int)frac & 0x03FF) * GPS_DIVIDER) >> 18 ;</font></div><div class=""><font face="Courier" class=""> frac = (((frac & 0x000FFC00)>>10) * GPS_DIVIDER) >> 8 ;</font></div><div class=""><font face="Courier" class=""> frac += rem;</font></div><div class=""><font face="Courier" class=""> }</font></div><div class=""><font face="Courier" class=""><br class=""></font></div><div class=""><font face="Courier" class=""> if(degrees <0)</font></div><div class=""><font face="Courier" class=""> frac = -frac;</font></div><div class=""><font face="Courier" class=""> return degrees * 2048 * 3600 + frac;</font></div><div class=""><font face="Courier" class="">}</font></div><div style="font-family: Helvetica; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;" class="">--------------utils.c snip end--------------------</div></div></div></span></div></span></div></div>_______________________________________________<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></blockquote></div><br class=""></div></body></html>