func main() { var dev *gps.Device var err error if dev, err = gps.Open("/dev/ttyAMA0"); err != nil { log.Panicln("Failed to open GPS device", err) } dev.Watch() f, err := os.OpenFile(*outFile, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600) if err != nil { log.Panicln("Failed to open output file", err) } defer f.Close() conn, _ := net.Dial("udp", fmt.Sprintf("255.255.255.255:%d", *udpPort)) defer conn.Close() var lastUpdate int64 = 0 for fix := range dev.Fixes { now := time.Now().Unix() if now-lastUpdate > *updateFreq { lastUpdate = now stanza := fmt.Sprintf("%d;%.8f;%.8f;%.2f;%.2f\n", now-EPOCH, fix.Lat, fix.Lon, fix.Alt, fix.TrackAngle) f.WriteString(stanza) conn.Write([]byte(stanza)) } } }
func main() { var dev *gps.Device var err error if dev, err = gps.Open("/dev/ttyAMA0"); err != nil { panic(err) } dev.Watch() for fix := range dev.Fixes { fmt.Println(fmt.Sprintf("Location: (%.8f,%.8f) Altitude:%.2fm Angle:%.2f", fix.Lat, fix.Lon, fix.Alt, fix.TrackAngle)) } }