tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/gps/ublox.go (about)

     1  package gps
     2  
     3  import (
     4  	"errors"
     5  	"time"
     6  )
     7  
     8  // flight mode disables the GPS COCOM limits
     9  var flight_mode_cmd = [...]byte{
    10  	0xB5, 0x62, 0x06, 0x24, 0x24, 0x00, 0xFF, 0xFF, 0x06, 0x03, 0x00, 0x00, 0x00,
    11  	0x00, 0x10, 0x27, 0x00, 0x00, 0x05, 0x00, 0xFA, 0x00, 0xFA, 0x00, 0x64, 0x00,
    12  	0x2C, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    13  	0x00, 0x00, 0x00, 0x16, 0xDC}
    14  
    15  // Sets CFG-GNSS to disable everything other than GPS GNSS
    16  // solution. Failure to do this means GPS power saving
    17  // doesn't work. Not needed for MAX7, needed for MAX8's
    18  var cfg_gnss_cmd = [...]byte{
    19  	0xB5, 0x62, 0x06, 0x3E, 0x2C, 0x00, 0x00, 0x00,
    20  	0x20, 0x05, 0x00, 0x08, 0x10, 0x00, 0x01, 0x00,
    21  	0x01, 0x01, 0x01, 0x01, 0x03, 0x00, 0x00, 0x00,
    22  	0x01, 0x01, 0x03, 0x08, 0x10, 0x00, 0x00, 0x00,
    23  	0x01, 0x01, 0x05, 0x00, 0x03, 0x00, 0x00, 0x00,
    24  	0x01, 0x01, 0x06, 0x08, 0x0E, 0x00, 0x00, 0x00,
    25  	0x01, 0x01, 0xFC, 0x11}
    26  
    27  func FlightMode(d Device) (err error) {
    28  	err = sendCommand(d, flight_mode_cmd[:])
    29  	return err
    30  }
    31  
    32  func SetCfgGNSS(d Device) (err error) {
    33  	err = sendCommand(d, cfg_gnss_cmd[:])
    34  	return err
    35  }
    36  
    37  func sendCommand(d Device, command []byte) (err error) {
    38  	d.WriteBytes(command)
    39  	start := time.Now()
    40  	for time.Now().Sub(start) < 1000 {
    41  		if d.readNextByte() == '\n' {
    42  			if d.readNextByte() == 0xB5 {
    43  				d.readNextByte()
    44  				if d.readNextByte() == 0x05 {
    45  					if d.readNextByte() == 0x01 {
    46  						return
    47  					}
    48  				}
    49  			}
    50  		}
    51  	}
    52  	return errors.New("no ACK to GPS command")
    53  }