Skip to content

Commit

Permalink
fix latitude and longitude
Browse files Browse the repository at this point in the history
  • Loading branch information
Junker committed Sep 2, 2021
1 parent 99848dc commit c1584c5
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions h02own.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ func SendOwntracksMessage(json_data []byte, device_cfg *deviceConfig) {
mqtt_client.Publish(topic, 0, true, string(json_data))
}

func FixCoord(coord string) float64 {
degrees, _ := strconv.ParseInt(coord[:len(coord)-7], 0, 16)
minutes, _ := strconv.ParseFloat(coord[len(coord)-7:], 16)

return float64(degrees) + (minutes / 60)
}

func ParseH02Message(message string) (*H02Data, error) {
var matches, err = H02LocationMessageRegex.Groups(message)
if err != nil {
Expand All @@ -189,14 +196,12 @@ func ParseH02Message(message string) (*H02Data, error) {

data.GPSDataValid = matches["gps_valid"] == "A"

data.Latitude, _ = strconv.ParseFloat(matches["latitude"], 32)
data.Latitude /= 100
data.Latitude = FixCoord(matches["latitude"])
if matches["latitude_symbol"] == "S" {
data.Latitude *= -1
}

data.Longitude, _ = strconv.ParseFloat(matches["longitude"], 32)
data.Longitude /= 100
data.Longitude = FixCoord(matches["longitude"])
if matches["longitude_symbol"] == "W" {
data.Longitude *= -1
}
Expand Down

0 comments on commit c1584c5

Please sign in to comment.