mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-02 22:17:49 +00:00
941c1c9057
Signed-off-by: deadprogram <ron@hybridgroup.com>
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
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
|
|
}
|