Re: [Flightgear-devel] [PATCH] overflow in Instrumentation/gps.cxx

2009-01-03 Thread Roy Vegard Ovesen
On Friday 02 January 2009 18:32:58 Csaba Halász wrote:
 0x007e1c50 in GPS::updateTTWNode (this=0xce164c0,
 c...@0x7fff664fdee0, distance_m=12822604.584446406,
 no...@0x7fff664fddd0) at src/Instrumentation/gps.cxx:483
 483 unsigned int TTW_seconds = (int) (TTW + 0.5);
 (gdb) p TTW
 $10 = 62278235905.950584

 Not sure what it is calculating anyway.  This happened with the
 hurricane just at startup.
 And all the while loops look silly too.

Please apply this patch to extract the hours minutes and seconds without using 
silly while loops.


-- 
Roy Vegard Ovesen
diff --git a/src/Instrumentation/gps.cxx b/src/Instrumentation/gps.cxx
index 913aba7..424ed3e 100644
--- a/src/Instrumentation/gps.cxx
+++ b/src/Instrumentation/gps.cxx
@@ -485,14 +485,9 @@ GPS::updateTTWNode(UpdateContext ctx, double distance_m, SGPropertyNode_ptr nod
   unsigned int TTW_minutes = 0;
   unsigned int TTW_hours   = 0;
   char TTW_str[9];
-  while (TTW_seconds = 3600) {
-TTW_seconds -= 3600;
-TTW_hours++;
-  }
-  while (TTW_seconds = 60) {
-TTW_seconds -= 60;
-TTW_minutes++;
-  }
+  TTW_hours   = TTW_seconds / 3600;
+  TTW_minutes = (TTW_seconds / 60) % 60;
+  TTW_seconds = TTW_seconds % 60;
   snprintf(TTW_str, 9, %02d:%02d:%02d,
 TTW_hours, TTW_minutes, TTW_seconds);
   node-setStringValue(TTW_str);
--
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


Re: [Flightgear-devel] [PATCH] overflow in Instrumentation/gps.cxx

2009-01-03 Thread James Turner

On 3 Jan 2009, at 13:17, Roy Vegard Ovesen wrote:

 Please apply this patch to extract the hours minutes and seconds  
 without using
 silly while loops.

Thanks (and I will apply this!), but to re-iterate, I have a re-write  
of the entire GPS code pending - but I'm holding off committing until  
the 1.9.x issue is decided, since my changes will require updates to  
panel instruments. So I'd urge people to no to worry unduly about this  
particular file (or any of the DCLGPS / KLN89 code)

Regards,
James


--
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


Re: [Flightgear-devel] [PATCH] overflow in Instrumentation/gps.cxx

2009-01-03 Thread Csaba Halász
On Sat, Jan 3, 2009 at 2:30 PM, James Turner zakal...@mac.com wrote:

 On 3 Jan 2009, at 13:17, Roy Vegard Ovesen wrote:

 Please apply this patch to extract the hours minutes and seconds
 without using
 silly while loops.

 Thanks (and I will apply this!)

But you credited it to the wrong person ...

-- 
Csaba/Jester

--
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


Re: [Flightgear-devel] [PATCH] overflow in Instrumentation/gps.cxx

2009-01-03 Thread James Turner

On 3 Jan 2009, at 18:10, Csaba Halász wrote:

 But you credited it to the wrong person ...

Ooops, yes.

Apologies to Roy and Ron for the confusion.

(I could make a poor excuse about names that start 'Ro-' and end with  
'-sen', but I think I'd be laughed at)

James


--
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


Re: [Flightgear-devel] [PATCH] overflow in Instrumentation/gps.cxx

2009-01-03 Thread James Turner

On 3 Jan 2009, at 18:47, Roy Vegard Ovesen wrote:

 marginally less silly ;-)

 IMHO this is the most elegant code I've submitted in a lng time,  
 but if
 it's only marginally less silly, then perhaps I don't mind not  
 getting credit
 for it. :-D

Heh :)

Roy, your code is fine, it's the entire GPS code that's pretty silly,  
and most especially the TTW to string computation. If one patch could  
reduce the total silliness by a large amount, that'd be an impressive  
patch :)

James

--
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


[Flightgear-devel] [PATCH] overflow in Instrumentation/gps.cxx

2009-01-02 Thread Csaba Halász
0x007e1c50 in GPS::updateTTWNode (this=0xce164c0,
c...@0x7fff664fdee0, distance_m=12822604.584446406,
no...@0x7fff664fddd0) at src/Instrumentation/gps.cxx:483
483 unsigned int TTW_seconds = (int) (TTW + 0.5);
(gdb) p TTW
$10 = 62278235905.950584

Not sure what it is calculating anyway.  This happened with the
hurricane just at startup.
And all the while loops look silly too. Not to mention that it
should probably display times up to 99:59:59 so the check at the top
is wrong.

-- 
Csaba/Jester
Index: src/Instrumentation/gps.cxx
===
RCS file: /var/cvs/FlightGear-0.9/source/src/Instrumentation/gps.cxx,v
retrieving revision 1.29
diff -u -r1.29 gps.cxx
--- src/Instrumentation/gps.cxx	9 Dec 2008 08:10:33 -	1.29
+++ src/Instrumentation/gps.cxx	2 Jan 2009 17:29:12 -
@@ -480,8 +480,8 @@
 TTW = (distance_m * SG_METER_TO_NM) / (ctx.speed_kt / 3600);
 }

-unsigned int TTW_seconds = (int) (TTW + 0.5);
-if (TTW_seconds  356400) { // That's 99 hours
+if (TTW  356399.5) { // That's 99 hours minus rounding
+  unsigned int TTW_seconds = (unsigned int) (TTW + 0.5);
   unsigned int TTW_minutes = 0;
   unsigned int TTW_hours   = 0;
   char TTW_str[9];
--
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


Re: [Flightgear-devel] [PATCH] overflow in Instrumentation/gps.cxx

2009-01-02 Thread James Turner

On 2 Jan 2009, at 17:32, Csaba Halász wrote:


 Not sure what it is calculating anyway.  This happened with the
 hurricane just at startup.
 And all the while loops look silly too. Not to mention that it
 should probably display times up to 99:59:59 so the check at the top
 is wrong.

I have a virtual re-write of this file pending, so don't worry about  
this one. And yes, the while loops to calculate hours and minutes for  
the TTW (time-to-waypoint) string are indeed silly.

James


--
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


Re: [Flightgear-devel] [PATCH] overflow in Instrumentation/gps.cxx

2009-01-02 Thread Vivian Meazza
Csaba Halász wrote

 0x007e1c50 in GPS::updateTTWNode (this=0xce164c0,
 c...@0x7fff664fdee0, distance_m=12822604.584446406,
 no...@0x7fff664fddd0) at src/Instrumentation/gps.cxx:483
 483 unsigned int TTW_seconds = (int) (TTW + 0.5);
 (gdb) p TTW
 $10 = 62278235905.950584
 
 Not sure what it is calculating anyway.  This happened with the
 hurricane just at startup.
 And all the while loops look silly too. Not to mention that it
 should probably display times up to 99:59:59 so the check at the top
 is wrong.

Shouldn't be in the Hurricane at all - I'll fix that anyway. And I try to
avoid while loops if at all possible. Seems to help in avoiding staggers,
but ...

Vivian



--
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel