wifi/espat, rtl8720dn, wifinina, net: modify to use Adapter interface

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram
2022-01-23 17:10:37 +01:00
committed by Ron Evans
parent d8c813d515
commit 941c1c9057
16 changed files with 110 additions and 114 deletions
+21 -4
View File
@@ -1,6 +1,23 @@
package net
type DeviceDriver interface {
import (
"errors"
"time"
)
var (
ErrWiFiMissingSSID = errors.New("missing SSID")
ErrWiFiConnectTimeout = errors.New("WiFi connect timeout")
)
// Adapter interface is used to communicate with the network adapter.
type Adapter interface {
// functions used to connect/disconnect to/from an access point
ConnectToAccessPoint(ssid, pass string, timeout time.Duration) error
Disconnect() error
GetClientIP() (string, error)
// these functions are used once the adapter is connected to the network
GetDNS(domain string) (string, error)
ConnectTCPSocket(addr, port string) error
ConnectSSLSocket(addr, port string) error
@@ -16,12 +33,12 @@ type DeviceDriver interface {
Response(timeout int) ([]byte, error)
}
var ActiveDevice DeviceDriver
var ActiveDevice Adapter
func UseDriver(driver DeviceDriver) {
func UseDriver(a Adapter) {
// TODO: rethink and refactor this
if ActiveDevice != nil {
panic("net.ActiveDevice is already set")
}
ActiveDevice = driver
ActiveDevice = a
}
+1 -1
View File
@@ -23,7 +23,7 @@ func NewClient(o *ClientOptions) Client {
}
type mqttclient struct {
adaptor net.DeviceDriver
adaptor net.Adapter
conn net.Conn
connected bool
opts *ClientOptions
+1 -1
View File
@@ -175,7 +175,7 @@ type ClientOptionsReader struct {
// ClientOptions contains configurable options for an MQTT Client.
type ClientOptions struct {
Adaptor net.DeviceDriver
Adaptor net.Adapter
//Servers []*url.URL
Servers string
+1 -1
View File
@@ -94,7 +94,7 @@ func Dial(network, address string) (Conn, error) {
// SerialConn is a loosely net.Conn compatible implementation
type SerialConn struct {
Adaptor DeviceDriver
Adaptor Adapter
}
// UDPSerialConn is a loosely net.Conn compatible intended to support