mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-12 02:43:42 +00:00
wifi/espat, rtl8720dn, wifinina, net: modify to use Adapter interface
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
@@ -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
@@ -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
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user