armindoantunes / gh615

Automatically exported from code.google.com/p/gh615
0 stars 0 forks source link

negative elevations is not negative... e.g you get wraped 16bit word like 65535 #28

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Run near the see

I get elevation data like this watch what happends when it crosses 0. 

...
              <pt tm="63" lat="56.227202" lon="12.543167" ele="4" hr="0" />
              <pt tm="64" lat="56.227228" lon="12.543178" ele="3" hr="0" />
              <pt tm="65" lat="56.227255" lon="12.543183" ele="2" hr="0" />
              <pt tm="66" lat="56.227278" lon="12.543188" ele="1" hr="0" />
              <pt tm="67" lat="56.227302" lon="12.543192" ele="0" hr="0" />
              <pt tm="68" lat="56.227323" lon="12.543197" ele="0" hr="0" />
              <pt tm="69" lat="56.227343" lon="12.543203" ele="0" hr="0" />
              <pt tm="70" lat="56.227365" lon="12.54321" ele="0" hr="0" />
              <pt tm="71" lat="56.227388" lon="12.543217" ele="0" hr="0" />
              <pt tm="72" lat="56.22741" lon="12.543218" ele="65535" hr="0" />
              <pt tm="73" lat="56.227428" lon="12.543217" ele="65534" hr="0" />

I get this kind of output both with .fitlog and .gpx formats.

Original issue reported on code.google.com by ZingoAnd...@gmail.com on 14 Sep 2008 at 10:28

GoogleCodeExporter commented 8 years ago
Adding the following to Utilities class

    @classmethod

    def hex2signed16bit(self, s):
        value = long(s, 16)
        if value > 32767:
            value = value - 2L*32767 - 2
        assert -32767-1 <= value <= 32767
        return int(value)

And using it for the altitude reading seem to help in my case
e.g.

   def fromHex(self, hex):

        if len(hex) == 30:

            self.latitude  = Coordinate().fromHex(hex[0:8])

            self.longitude = Coordinate().fromHex(hex[8:16])

            self.altitude  = Utilities.hex2signed16bit(hex[16:20])

            self.speed     = Utilities.hex2dec(hex[20:24])/100

            self.heartrate = Utilities.hex2dec(hex[24:26])

            self.interval  =
datetime.timedelta(seconds=Utilities.hex2dec(hex[26:30])/10.0)       

            return self

        else:

            raise GH600ParseException(self.__class__.__name__, len(hex), 30)

I found a code sniped with the help of goggle here:
http://mail.python.org/pipermail/python-list/2003-July/215016.html
That I stole...

Original comment by ZingoAnd...@gmail.com on 15 Sep 2008 at 7:04

GoogleCodeExporter commented 8 years ago

Original comment by spei...@gmail.com on 15 Sep 2008 at 10:00

GoogleCodeExporter commented 8 years ago
fixed in revision 206

Thanks for reporting

Original comment by spei...@gmail.com on 6 Aug 2009 at 8:47

GoogleCodeExporter commented 8 years ago
There seem to still be something fish here, just got this:

              <pt tm="27195" lat="55.387123" lon="14.2023" ele="0" hr="0" />
              <pt tm="27201" lat="55.387042" lon="14.202207" ele="0" hr="0" />
              <pt tm="27206" lat="55.386985" lon="14.202088" ele="32766" hr="0" />
              <pt tm="27212" lat="55.386875" lon="14.201918" ele="32765" hr="0" />
              <pt tm="27217" lat="55.386825" lon="14.201823" ele="32765" hr="0" />
              <pt tm="27223" lat="55.386767" lon="14.201747" ele="32766" hr="0" />
              <pt tm="27228" lat="55.386738" lon="14.201708" ele="32766" hr="0" />
              <pt tm="27234" lat="55.386665" lon="14.201647" ele="32766" hr="0" />
              <pt tm="27239" lat="55.386612" lon="14.20162" ele="0" hr="0" />
              <pt tm="27245" lat="55.386558" lon="14.20153" ele="0" hr="0" />

Original comment by ZingoAnd...@gmail.com on 17 Aug 2009 at 8:41

GoogleCodeExporter commented 8 years ago
This solves the problem:

    @classmethod

    def hex2signedDec(self, hex):

        value = self.hex2dec(hex)

        if value > 32767:

            value = value - 2L*32767 - 2

        return int(value)

Original comment by ZingoAnd...@gmail.com on 24 Aug 2009 at 7:57