Some debug.

This commit is contained in:
yotia 2024-08-01 19:34:58 +03:00
parent 6498d20378
commit 061ba2a859
6 changed files with 26 additions and 23 deletions

View File

@ -10,7 +10,7 @@ func (g *gps) CheckStatus() error {
// Provides more information about signal and possible problems using NMEA reports
// Collect reports
reports, err := g.collectNmeaReports(gpgsv | gpgsa) // Now minimum
reports, err := g.collectNmeaReports(nmeaFlagsAll) // Now minimum
if err != nil {
return fmt.Errorf("collect nmea reports: %w", err)
}

View File

@ -31,7 +31,7 @@ func New(logger *log.Logger, port at.Port) Gps {
}
func (g *gps) Init() error {
if g.port.IsConnected() {
if !g.port.IsConnected() {
return fmt.Errorf("at port is not connected")
}
return nil

View File

@ -33,17 +33,17 @@ const (
)
// Go... otherwise will throw warning
var _ = gga | rmc | gpgsv | gpgsa | vtg | xfi | glgsa | gns | gagsv | bdpqgsa | bdpqgsv
var nmeaFlagsAll = gga | rmc | gpgsv | gpgsa | vtg | xfi | glgsa | gns | gagsv | bdpqgsa | bdpqgsv
func (g *gps) rawCollect(flags nmeaFlags) (string, error) {
// Need to omplement low level write/read here because collect must be atomic operation
// If other command is executed(write/read) it will read a part of nmea report and cause an error
g.switchGpsMode(true)
g.port.Mutex().Lock()
s := g.port.SerialPort()
defer func() {
s.ResetInputBuffer()
s.ResetOutputBuffer()
g.port.Mutex().Unlock()
g.switchGpsMode(false)
}()
// Send AT+CGPSINFOCFG=255, flags
@ -57,7 +57,7 @@ func (g *gps) rawCollect(flags nmeaFlags) (string, error) {
time.Sleep(collectTimeout)
// Send AT+CGPSINFOCFG=0, flags
if _, err := s.Write([]byte("AT+CGPSINFOCFG=255," + string(flags) + "\r\n")); err != nil {
if _, err := s.Write([]byte("AT+CGPSINFOCFG=0," + string(flags) + "\r\n")); err != nil {
return "", fmt.Errorf("serial port write 2: %w", err)
}

View File

@ -101,12 +101,6 @@ func (m *modem) Init() error {
return fmt.Errorf("connect: %w", err)
}
// Tests
m.logger.Println("=============================== Test")
if err := m.testGPS(); err != nil {
return fmt.Errorf("testGPS: %w", err)
}
// // Establish internet connection
// m.logger.Println("=============================== Internet")
// m.ic = internet.New(log.New(m.logger.Writer(), "internet", log.LstdFlags), m.port)
@ -115,15 +109,22 @@ func (m *modem) Init() error {
// }
// Init submodules
m.logger.Println("=============================== Init submodules")
m.sms = sms.New(log.New(m.logger.Writer(), "modem-sms", log.LstdFlags), m.port)
if err := m.sms.Init(); err != nil {
return fmt.Errorf("sms dialer init %w", err)
}
m.gps = gps.New(log.New(m.logger.Writer(), "modem-gps", log.LstdFlags), m.port)
if err := m.gps.Init(); err != nil {
return fmt.Errorf("gps init %w", err)
}
m.logger.Println(m.gps, m)
// Tests
m.logger.Println("=============================== Test")
if err := m.testGPS(); err != nil {
return fmt.Errorf("testGPS: %w", err)
}
return nil
}
@ -137,9 +138,9 @@ func (m *modem) Update() error {
m.logger.Println("No connection to module")
return nil
}
m.logger.Println("Update")
m.logger.Println("Update", m.gps)
if err := m.gps.Update(); err != nil {
return fmt.Errorf("gps update: %w", err)
m.logger.Println("gps update:", err.Error())
}
return nil
}

View File

@ -61,7 +61,7 @@ func (d *dialer) Send(number, msg string) error {
// Reads all new messages
func (d *dialer) ReadNew() ([]string, error) {
resp, err := d.port.Send("AT+CMGL")
resp, err := d.port.Send("AT+CMGL=\"ALL\"")
if err != nil {
return nil, fmt.Errorf("AT+CMGL request: %w", err)
}

16
main.go
View File

@ -28,16 +28,18 @@ func mainE() error {
log.Println("||||||||||||||||| GET INFO |||||||||||||||||")
log.Println(m.GetData())
log.Println("||||||||||||||||| SEND SMS |||||||||||||||||")
log.Println(m.At().Send("AT+CNUM"))
// log.Println("||||||||||||||||| SEND SMS |||||||||||||||||")
// log.Println(m.At().Send("AT+CNUM"))
// if err := m.Sms().Send("+79218937173", "CGSG forever"); err != nil {
// return err
// }
if ms, err := m.Sms().ReadNew(); err != nil {
return err
} else {
log.Println("NEW:", ms)
}
// if ms, err := m.Sms().ReadNew(); err != nil {
// return err
// } else {
// log.Println("NEW:", ms)
// }
log.Println("||||||||||||||||| Checking gps status |||||||||||||||||")
log.Println(m.Gps().CheckStatus())
return nil
}