Added sms test.

This commit is contained in:
Andrey Egorov 2024-07-29 16:51:54 +03:00
parent e0110c558e
commit 1b741c7dab
3 changed files with 43 additions and 5 deletions

View File

@ -12,6 +12,7 @@ import (
"github.com/CGSG-2021-AE4/modem-test/api/modem/at" "github.com/CGSG-2021-AE4/modem-test/api/modem/at"
"github.com/CGSG-2021-AE4/modem-test/api/modem/gpio" "github.com/CGSG-2021-AE4/modem-test/api/modem/gpio"
"github.com/CGSG-2021-AE4/modem-test/api/modem/internet" "github.com/CGSG-2021-AE4/modem-test/api/modem/internet"
"github.com/CGSG-2021-AE4/modem-test/api/modem/sms"
) )
type ModemData struct { type ModemData struct {
@ -40,6 +41,9 @@ type modem struct {
// Internet connection // Internet connection
ic internet.Conn ic internet.Conn
// Sms and calls
sms sms.Dialer
} }
type Modem interface { type Modem interface {
@ -47,6 +51,10 @@ type Modem interface {
Validate() bool Validate() bool
Update() error Update() error
GetInfo() ModemData GetInfo() ModemData
// Temp access to sms interface
Sms() sms.Dialer
io.Closer io.Closer
} }
@ -95,11 +103,17 @@ func (m *modem) Init() error {
return fmt.Errorf("testGPS: %w", err) return fmt.Errorf("testGPS: %w", err)
} }
// Establish internet connection // // Establish internet connection
m.logger.Println("=============================== Internet") // m.logger.Println("=============================== Internet")
m.ic = internet.New(log.New(m.logger.Writer(), "internet", log.LstdFlags), m.port) // m.ic = internet.New(log.New(m.logger.Writer(), "internet", log.LstdFlags), m.port)
if err := m.ic.Init(); err != nil { // if err := m.ic.Init(); err != nil {
return fmt.Errorf("internet connection init: %w", err) // return fmt.Errorf("internet connection init: %w", err)
// }
// Init sms dialer
m.sms = sms.New(log.New(m.logger.Writer(), "sms", log.LstdFlags), m.port)
if err := m.sms.Init(); err != nil {
return fmt.Errorf("sms dialer init %w", err)
} }
return nil return nil
} }
@ -155,7 +169,15 @@ func (m *modem) GetInfo() ModemData {
} }
} }
func (m *modem) Sms() sms.Dialer {
return m.sms
}
func (m *modem) Close() error { func (m *modem) Close() error {
if err := m.sms.Close(); err != nil {
return fmt.Errorf("sms: %w", err)
}
// Not right way I think // Not right way I think
if err := m.port.Close(); err != nil { if err := m.port.Close(); err != nil {
return fmt.Errorf("serial port: %w", err) return fmt.Errorf("serial port: %w", err)

View File

@ -21,6 +21,13 @@ type Dialer interface {
io.Closer io.Closer
} }
func New(logger *log.Logger, port at.Port) Dialer {
return &dialer{
logger: logger,
port: port,
}
}
func (d *dialer) Init() error { func (d *dialer) Init() error {
// Ensure serial port // Ensure serial port
if !d.port.IsConnected() { if !d.port.IsConnected() {
@ -59,3 +66,7 @@ func (d *dialer) ReadNew() ([]string, error) {
msgs := strings.Split(strings.Replace(string(resp), "\r", "", -1), "\n") msgs := strings.Split(strings.Replace(string(resp), "\r", "", -1), "\n")
return msgs, nil // TODO return msgs, nil // TODO
} }
func (d *dialer) Close() error {
return nil
}

View File

@ -27,5 +27,10 @@ func mainE() error {
} }
log.Println("||||||||||||||||| GET INFO |||||||||||||||||") log.Println("||||||||||||||||| GET INFO |||||||||||||||||")
log.Println(m.GetInfo()) log.Println(m.GetInfo())
log.Println("||||||||||||||||| SEND SMS |||||||||||||||||")
if err := m.Sms().Send("+", "CGSG forever"); err != nil {
return err
}
return nil return nil
} }