sim-modem/main.go

62 lines
1.5 KiB
Go
Raw Normal View History

2024-07-18 16:34:26 +00:00
package main
import (
"log"
2024-07-23 16:02:28 +00:00
"os"
2024-07-22 15:53:34 +00:00
2024-08-08 10:26:33 +00:00
"gitea.unprism.ru/KRBL/sim-modem/api/modem"
2024-07-18 16:34:26 +00:00
)
func main() {
log.Println("CGSG forever!!!")
if err := mainE(); err != nil {
log.Println("MAIN finished with error:", err.Error())
}
log.Println("END")
}
func mainE() error {
2024-08-06 17:37:20 +00:00
logger := log.New(os.Stdout, "main : ", log.LstdFlags)
m := modem.New(log.New(logger.Writer(), "modem : ", log.LstdFlags))
2024-08-02 16:43:15 +00:00
logger.Println("||||||||||||||||| INIT |||||||||||||||")
2024-07-23 14:59:26 +00:00
if err := m.Init(); err != nil {
2024-08-07 14:34:56 +00:00
logger.Println("Init ended with error:", err.Error())
logger.Println("Try to turn on")
if err := m.PowerOn(); err != nil {
return err
}
logger.Println("Reinit")
if err := m.Init(); err != nil {
return err
}
2024-07-23 14:59:26 +00:00
}
2024-08-06 17:37:20 +00:00
if !m.IsConnected() {
logger.Println("AAAAAAAAAAAAAAA Modem is not connected")
2024-07-26 19:58:34 +00:00
return nil
}
2024-08-02 16:43:15 +00:00
logger.Println("||||||||||||||||| GET INFO |||||||||||||||||")
2024-08-07 14:34:56 +00:00
logger.Println(m.Update())
2024-08-06 17:37:20 +00:00
logger.Printf("DATA: %+v\n", m.GetData())
2024-07-29 13:51:54 +00:00
2024-08-07 14:34:56 +00:00
logger.Println("||||||||||||||||| SEND SMS |||||||||||||||||")
logger.Println(m.At().Send("AT+CNUM"))
2024-07-29 17:03:22 +00:00
// if err := m.Sms().Send("+79218937173", "CGSG forever"); err != nil {
// return err
// }
2024-08-07 14:34:56 +00:00
if ms, err := m.Sms().ReadNew(); err != nil {
return err
} else {
logger.Println("NEW:", ms)
}
2024-08-02 16:43:15 +00:00
logger.Println("||||||||||||||||| Checking gps status |||||||||||||||||")
2024-08-06 17:37:20 +00:00
st, err := m.Gps().GetStatus()
2024-08-02 16:43:15 +00:00
if err != nil {
return err
}
2024-08-06 17:37:20 +00:00
logger.Printf("GPS Status:%+v\n", st)
2024-07-29 17:03:22 +00:00
2024-08-07 14:34:56 +00:00
// logger.Println("Turn off", m.PowerOff())
2024-07-23 14:59:26 +00:00
return nil
2024-07-18 16:34:26 +00:00
}