Added sms test.
This commit is contained in:
parent
e0110c558e
commit
1b741c7dab
@ -12,6 +12,7 @@ import (
|
||||
"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/internet"
|
||||
"github.com/CGSG-2021-AE4/modem-test/api/modem/sms"
|
||||
)
|
||||
|
||||
type ModemData struct {
|
||||
@ -40,6 +41,9 @@ type modem struct {
|
||||
|
||||
// Internet connection
|
||||
ic internet.Conn
|
||||
|
||||
// Sms and calls
|
||||
sms sms.Dialer
|
||||
}
|
||||
|
||||
type Modem interface {
|
||||
@ -47,6 +51,10 @@ type Modem interface {
|
||||
Validate() bool
|
||||
Update() error
|
||||
GetInfo() ModemData
|
||||
|
||||
// Temp access to sms interface
|
||||
Sms() sms.Dialer
|
||||
|
||||
io.Closer
|
||||
}
|
||||
|
||||
@ -95,11 +103,17 @@ func (m *modem) Init() error {
|
||||
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)
|
||||
if err := m.ic.Init(); err != nil {
|
||||
return fmt.Errorf("internet connection init: %w", err)
|
||||
// // Establish internet connection
|
||||
// m.logger.Println("=============================== Internet")
|
||||
// m.ic = internet.New(log.New(m.logger.Writer(), "internet", log.LstdFlags), m.port)
|
||||
// if err := m.ic.Init(); err != nil {
|
||||
// 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
|
||||
}
|
||||
@ -155,7 +169,15 @@ func (m *modem) GetInfo() ModemData {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *modem) Sms() sms.Dialer {
|
||||
return m.sms
|
||||
}
|
||||
|
||||
func (m *modem) Close() error {
|
||||
if err := m.sms.Close(); err != nil {
|
||||
return fmt.Errorf("sms: %w", err)
|
||||
}
|
||||
|
||||
// Not right way I think
|
||||
if err := m.port.Close(); err != nil {
|
||||
return fmt.Errorf("serial port: %w", err)
|
||||
|
@ -21,6 +21,13 @@ type Dialer interface {
|
||||
io.Closer
|
||||
}
|
||||
|
||||
func New(logger *log.Logger, port at.Port) Dialer {
|
||||
return &dialer{
|
||||
logger: logger,
|
||||
port: port,
|
||||
}
|
||||
}
|
||||
|
||||
func (d *dialer) Init() error {
|
||||
// Ensure serial port
|
||||
if !d.port.IsConnected() {
|
||||
@ -59,3 +66,7 @@ func (d *dialer) ReadNew() ([]string, error) {
|
||||
msgs := strings.Split(strings.Replace(string(resp), "\r", "", -1), "\n")
|
||||
return msgs, nil // TODO
|
||||
}
|
||||
|
||||
func (d *dialer) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user