mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-16 12:53:23 +00:00
wifi/espat, rtl8720dn, wifinina, net: modify to use Adapter interface
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package net
|
||||
|
||||
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
|
||||
ConnectUDPSocket(addr, sendport, listenport string) error
|
||||
DisconnectSocket() error
|
||||
StartSocketSend(size int) error
|
||||
Write(b []byte) (n int, err error)
|
||||
ReadSocket(b []byte) (n int, err error)
|
||||
IsSocketDataAvailable() bool
|
||||
|
||||
// FIXME: this is really specific to espat, and maybe shouldn't be part
|
||||
// of the driver interface
|
||||
Response(timeout int) ([]byte, error)
|
||||
}
|
||||
|
||||
var ActiveDevice Adapter
|
||||
|
||||
func UseDriver(a Adapter) {
|
||||
// TODO: rethink and refactor this
|
||||
if ActiveDevice != nil {
|
||||
panic("net.ActiveDevice is already set")
|
||||
}
|
||||
ActiveDevice = a
|
||||
}
|
||||
Reference in New Issue
Block a user