gps

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2022 License: MIT Imports: 8 Imported by: 0

README

GPS

A Go package to allow the Adafruit Ultimate GPS module to be read from the serial port.

$GPGGA,161715.000,1858.3654,N,09334.2837,W,1,08,1.11,20.9,M,-8.8,M,,*5E
$GPGSA,A,3,01,08,04,21,07,09,27,17,,,,,1.97,1.11,1.63*0B
$GPRMC,161715.000,A,1858.3654,N,09334.2837,W,0.01,147.61,140421,,,A*75
$GPVTG,147.61,T,,M,0.01,N,0.02,K,A*3B
package main

import (
	"fmt"
	"log"
	"time"

	"github.com/jamsmendez/gps"
)

func main() {
	mGps := gps.GPS{
		Port:     "COM5",
		BaudRate: 9600,
	}

	err := mGps.Connect()
	if err != nil {
		log.Fatal("GPS Connect ERROR: ", err)
	}

	go mGPs.Reading()

	defer mGps.Disconnect()

	for {
		p, err := mGps.FetchPosition()
		if err != nil {
			return
		}

		fmt.Println(p.Latitude, p.Longitude, p.Altitude, p.Speed, p.Course)

		time.Sleep(time.Second * 2)
	}
}

Contact

Github: https://github.com/jamsmendez

Twitter: https://twitter.com/jamsmendez

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GPS

type GPS struct {
	Port     string
	BaudRate int
	Debug    bool
	// contains filtered or unexported fields
}

func (*GPS) Connect

func (gps *GPS) Connect() error

Connect open serial connection with gps

func (*GPS) Disconnect

func (gps *GPS) Disconnect() error

Disconnect ... close serial connection with gps

func (*GPS) FetchPosition

func (gps *GPS) FetchPosition() (Position, error)

FetchPosition return current gps position

func (*GPS) IsConnected

func (gps *GPS) IsConnected() bool

IsConnected return state of the connection with gps

func (*GPS) Reading

func (gps *GPS) Reading()

Reading reads from gps

type Position

type Position struct {
	Latitude   float64  `json:"latitude"`
	Longitude  float64  `json:"longitude"`
	Altitude   float64  `json:"altitude"`
	Course     float64  `json:"course"`
	Speed      float64  `json:"speed"`
	Time       float64  `json:"time"`
	Satellites []string `json:"satellites"`
	Pdop       string   `json:"pdop"`
	Hdop       string   `json:"hdop"`
	Vdop       string   `json:"vdop"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL