Skip to content

Commit d87ae1d

Browse files
committed
Working on base architecture
1 parent 1ab7ff9 commit d87ae1d

File tree

6 files changed

+194
-0
lines changed

6 files changed

+194
-0
lines changed

drivers/8810ft.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package drivers
2+
3+
// DO NOT USE DIRECTLY
4+
type ZTE8810FT struct {
5+
TargetIP string
6+
basePath string
7+
}
8+
9+
func init() {
10+
registerModel("8810FT", newZTE8810FT)
11+
}
12+
13+
func newZTE8810FT(ip string) BaseModem {
14+
return &ZTE8810FT{TargetIP: ip, basePath: "/goform/goform_set_cmd_process"}
15+
}
16+
17+
func (m *ZTE8810FT) SetTargetIP(ip string) error {
18+
m.TargetIP = ip
19+
return nil
20+
}
21+
22+
func (m *ZTE8810FT) GetTargetIP() string {
23+
return m.TargetIP
24+
}
25+
26+
func (m *ZTE8810FT) GetModel() string {
27+
return "ZTE 8810FT"
28+
}

drivers/common.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package drivers
2+
3+
import "fmt"
4+
5+
type BaseModem interface {
6+
SetTargetIP(ip string) error
7+
GetTargetIP() string
8+
GetModel() string
9+
}
10+
11+
type ModemCell interface {
12+
BaseModem
13+
14+
GetCellConnStatus() error
15+
ConnectCell() error
16+
DisconnectCell() error
17+
}
18+
19+
type SMS struct {
20+
Sender string
21+
Message string
22+
}
23+
24+
type ModemSMS interface {
25+
BaseModem
26+
27+
SendSMS(phone string, message string) error
28+
GetAllSMS() ([]SMS, error)
29+
}
30+
31+
var models map[string]func(ip string) BaseModem
32+
33+
func isRegistered(name string) bool {
34+
// Check if model has already been registered
35+
_, ok := models[name]
36+
return ok
37+
}
38+
39+
func registerModel(name string, generator func(ip string) BaseModem) {
40+
// Check if model has already been registered
41+
if isRegistered(name) {
42+
panic(fmt.Sprintf("Attempted to register %s twice", name))
43+
}
44+
45+
// Register the model
46+
models[name] = generator
47+
}
48+
49+
func GetModemDriver(model string, ip string) (BaseModem, error) {
50+
if !isRegistered(model) {
51+
return nil, ErrUnknownModel
52+
}
53+
54+
return models[model](ip), nil
55+
}
56+
57+
func GetAvailableDrivers() *[]string {
58+
return nil
59+
}

drivers/errors.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package drivers
2+
3+
import (
4+
"errors"
5+
)
6+
7+
// Basic Errors
8+
var ErrUnknownModel = errors.New("attempting to get unknown model")

go.mod

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module brokenCursor/zte-modem-cli
2+
3+
go 1.20
4+
5+
require github.com/go-playground/validator/v10 v10.22.0
6+
7+
require (
8+
github.com/alexflint/go-arg v1.5.1 // indirect
9+
github.com/alexflint/go-scalar v1.2.0 // indirect
10+
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
11+
github.com/go-playground/locales v0.14.1 // indirect
12+
github.com/go-playground/universal-translator v0.18.1 // indirect
13+
github.com/leodido/go-urn v1.4.0 // indirect
14+
golang.org/x/crypto v0.19.0 // indirect
15+
golang.org/x/net v0.21.0 // indirect
16+
golang.org/x/sys v0.17.0 // indirect
17+
golang.org/x/text v0.14.0 // indirect
18+
)

go.sum

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
github.com/alexflint/go-arg v1.5.1 h1:nBuWUCpuRy0snAG+uIJ6N0UvYxpxA0/ghA/AaHxlT8Y=
2+
github.com/alexflint/go-arg v1.5.1/go.mod h1:A7vTJzvjoaSTypg4biM5uYNTkJ27SkNTArtYXnlqVO8=
3+
github.com/alexflint/go-scalar v1.2.0 h1:WR7JPKkeNpnYIOfHRa7ivM21aWAdHD0gEWHCx+WQBRw=
4+
github.com/alexflint/go-scalar v1.2.0/go.mod h1:LoFvNMqS1CPrMVltza4LvnGKhaSpc3oyLEBUZVhhS2o=
5+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6+
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
7+
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
8+
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
9+
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
10+
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
11+
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
12+
github.com/go-playground/validator/v10 v10.22.0 h1:k6HsTZ0sTnROkhS//R0O+55JgM8C4Bx7ia+JlgcnOao=
13+
github.com/go-playground/validator/v10 v10.22.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
14+
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
15+
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
16+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
17+
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
18+
golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
19+
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
20+
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
21+
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
22+
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
23+
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
24+
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
25+
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=

main.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/brokenCursor/zte-modem-cli/drivers"
7+
8+
"github.com/alexflint/go-arg"
9+
"github.com/go-playground/validator/v10"
10+
)
11+
12+
// CLI Definitions //
13+
14+
type SMSArgs struct {
15+
Action string `arg:""`
16+
PhoneNumber string `arg:"-n" help:"Recievers"`
17+
Message string `arg:"-m"`
18+
}
19+
20+
type ConnectionArgs struct {
21+
Action string `arg:"positional,required" help:"up/down/status" validate:"oneof=up down status"`
22+
}
23+
24+
type BaseArgs struct {
25+
Connection *ConnectionArgs `validate:"-" arg:"subcommand:conn" help:"Manage cell connection"`
26+
SMS *SMSArgs `validate:"-" arg:"subcommand:sms" help:"Manage SMS"`
27+
Ip string `validate:"ipv4" arg:"--ip" help:"Override IP in config file"`
28+
}
29+
30+
var validate *validator.Validate
31+
var args BaseArgs
32+
33+
func init() {
34+
// Create a single instance of validator
35+
validate = validator.New(validator.WithRequiredStructEnabled())
36+
}
37+
38+
func main() {
39+
parser := arg.MustParse(&args)
40+
41+
switch {
42+
case args.Connection != nil:
43+
err := validate.Struct(args.Connection)
44+
45+
if err != nil {
46+
parser.FailSubcommand("Unknown action", "conn")
47+
}
48+
fmt.Printf("changing connection status to %s\n", args.Connection.Action)
49+
case parser.Subcommand() == nil:
50+
parser.Fail("Missing or unknown command")
51+
}
52+
53+
GetModemDriver()
54+
55+
fmt.Printf("Modem cmd: %s\n", args.Ip)
56+
}

0 commit comments

Comments
 (0)