From 061ba2a859b5667cdc2fa8ef91ce1c6202a0a1e1 Mon Sep 17 00:00:00 2001 From: yotia Date: Thu, 1 Aug 2024 19:34:58 +0300 Subject: [PATCH] Some debug. --- api/modem/gps/check.go | 2 +- api/modem/gps/gps.go | 2 +- api/modem/gps/nmea.go | 8 ++++---- api/modem/modem.go | 19 ++++++++++--------- api/modem/sms/sms.go | 2 +- main.go | 16 +++++++++------- 6 files changed, 26 insertions(+), 23 deletions(-) diff --git a/api/modem/gps/check.go b/api/modem/gps/check.go index 75ba0f3..b1fa3cb 100644 --- a/api/modem/gps/check.go +++ b/api/modem/gps/check.go @@ -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) } diff --git a/api/modem/gps/gps.go b/api/modem/gps/gps.go index 541dcae..cd8eafc 100644 --- a/api/modem/gps/gps.go +++ b/api/modem/gps/gps.go @@ -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 diff --git a/api/modem/gps/nmea.go b/api/modem/gps/nmea.go index bdb1096..94b3ec0 100644 --- a/api/modem/gps/nmea.go +++ b/api/modem/gps/nmea.go @@ -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) } diff --git a/api/modem/modem.go b/api/modem/modem.go index dcb664a..e6d910b 100644 --- a/api/modem/modem.go +++ b/api/modem/modem.go @@ -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 } diff --git a/api/modem/sms/sms.go b/api/modem/sms/sms.go index c27f401..d279d4d 100644 --- a/api/modem/sms/sms.go +++ b/api/modem/sms/sms.go @@ -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) } diff --git a/main.go b/main.go index d05db01..d2d66d1 100644 --- a/main.go +++ b/main.go @@ -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 }