forked from tinygo-org/drivers
/
adapter.go
44 lines (37 loc) · 1.17 KB
/
adapter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
}