network

package
v0.15.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package network contains drivers to manage various network interfaces including modems.

Index

Constants

View Source
const APNHologram = "hologram"

APNHologram is the APN to use on the Hologram network

View Source
const APNKajeet = "kajeet.gw12.vzwentp"

APNKajeet is the APN to use on the Kajeet network

View Source
const APNVerizon = "vzwinternet"

APNVerizon is the APN to use on VZ network

Variables

View Source
var DebugAtCommands = false

DebugAtCommands can be set to true to debug at commands

View Source
var ErrorModemNotDetected = errors.New("No modem detected")

ErrorModemNotDetected is returned if we try an operation and the modem is not detected

Functions

func Cmd

func Cmd(port io.ReadWriter, cmd string) (string, error)

Cmd send a command to modem and read response retry 3 times. Port should be a RespReadWriter.

func CmdATI

func CmdATI(port io.ReadWriter) (string, error)

CmdATI gets version # from modem

func CmdAt

func CmdAt(port io.ReadWriter) error

CmdAt just executes a generic at command

func CmdAttach

func CmdAttach(port io.ReadWriter) error

CmdAttach attaches modem to network

func CmdBg96ForceLTE

func CmdBg96ForceLTE(port io.ReadWriter) error

CmdBg96ForceLTE forces BG96 modems to use LTE only, (no 2G)

func CmdCesq

func CmdCesq(port io.ReadWriter) (rsrq, rsrp int, err error)

CmdCesq is used to send the AT+CESQ command

func CmdCops

func CmdCops(port io.ReadWriter) (carrier string, err error)

CmdCops is used determine what carrier we are connected to

func CmdFunFull

func CmdFunFull(port io.ReadWriter) error

CmdFunFull sets the modem functionality to full

func CmdFunMin

func CmdFunMin(port io.ReadWriter) error

CmdFunMin sets the modem functionality to min

func CmdGGA

func CmdGGA(port io.ReadWriter) (string, error)

CmdGGA gets GPS information from modem

func CmdGetApn added in v0.14.5

func CmdGetApn(port io.ReadWriter) (string, error)

CmdGetApn gets the APN

func CmdGetFwSwitch added in v0.14.5

func CmdGetFwSwitch(port io.ReadWriter) (int, error)

CmdGetFwSwitch returns the firmware used in Telit modems 0 - AT&T 1 - Verizon

func CmdGetFwVersionBG96

func CmdGetFwVersionBG96(port io.ReadWriter) (string, error)

CmdGetFwVersionBG96 gets FW version from BG96 modem

func CmdGetGpio added in v0.14.5

func CmdGetGpio(port io.ReadWriter, gpio int) (GpioDir, GpioLevel, error)

CmdGetGpio is used to get GPIO state on Telit modems

func CmdGetImei

func CmdGetImei(port io.ReadWriter) (string, error)

CmdGetImei gets IMEI # from modem

func CmdGetPhoneNum

func CmdGetPhoneNum(port io.ReadWriter) (string, error)

CmdGetPhoneNum gets phone number from modem

func CmdGetSignal

func CmdGetSignal(port io.ReadWriter) (int, int, error)

CmdGetSignal gets signal strength

func CmdGetSim

func CmdGetSim(port io.ReadWriter) (string, error)

CmdGetSim gets SIM # from modem

func CmdGetSimBg96

func CmdGetSimBg96(port io.ReadWriter) (string, error)

CmdGetSimBg96 returns SIM for bg96 modems

func CmdGetUsbCfg added in v0.14.5

func CmdGetUsbCfg(port io.ReadWriter) (int, error)

CmdGetUsbCfg gets the USB config. For Telit modems, 0 is ppp, 3 is USB network

func CmdOK

func CmdOK(port io.ReadWriter, cmd string) error

CmdOK runs the command and checks for OK response

func CmdQcsq

func CmdQcsq(port io.ReadWriter) (service bool, rssi, rsrp, rsrq int, err error)

CmdQcsq is used to send the AT+QCSQ command

func CmdQspn

func CmdQspn(port io.ReadWriter) (network string, err error)

CmdQspn is used to send the AT+QSPN command

func CmdReboot

func CmdReboot(port io.ReadWriter) error

CmdReboot reboots modem

func CmdSetApn

func CmdSetApn(port io.ReadWriter, apn string) error

CmdSetApn is used to set the APN using the GCDCONT command

func CmdSetGpio added in v0.14.5

func CmdSetGpio(port io.ReadWriter, gpio int, level GpioLevel) error

CmdSetGpio is used to set GPIO state in Telit modems

func CmdSetUsbConfig added in v0.14.5

func CmdSetUsbConfig(port io.ReadWriter, cfg int) error

CmdSetUsbConfig is configures the USB mode of Telit modems 0 = ppp 3 = usb network

func CmdSica

func CmdSica(port io.ReadWriter) error

CmdSica is used to send SICA command

func GetIP

func GetIP(ifaceName string) (string, error)

GetIP returns the IP address for the itnerface

func RsrpValueToDb

func RsrpValueToDb(value int) float64

RsrpValueToDb converts AT value to dB

func RsrqValueToDb

func RsrqValueToDb(value int) float64

RsrqValueToDb converts AT value to dB

Types

type BG96ScanMode

type BG96ScanMode int

BG96ScanMode is a type that defines the varios BG96 scan modes

const (
	BG96ScanModeUnknown BG96ScanMode = -1
	BG96ScanModeAuto    BG96ScanMode = 0
	BG96ScanModeGSM     BG96ScanMode = 1
	BG96ScanModeLTE     BG96ScanMode = 3
)

valid scan modes

func CmdBg96GetScanMode

func CmdBg96GetScanMode(port io.ReadWriter) (BG96ScanMode, error)

CmdBg96GetScanMode returns the current modem scan mode

type DummyInterface

type DummyInterface struct {
}

DummyInterface is an interface that always reports detected/connected

func NewDummyInterface

func NewDummyInterface() *DummyInterface

NewDummyInterface constructor

func (*DummyInterface) Configure

func (d *DummyInterface) Configure() (InterfaceConfig, error)

Configure stub

func (*DummyInterface) Connect

func (d *DummyInterface) Connect() error

Connect stub

func (*DummyInterface) Desc

func (d *DummyInterface) Desc() string

Desc returns description

func (*DummyInterface) Enable

func (d *DummyInterface) Enable(_ bool) error

Enable or disable interface

func (*DummyInterface) GetStatus

func (d *DummyInterface) GetStatus() (InterfaceStatus, error)

GetStatus return interface status

func (*DummyInterface) Reset

func (d *DummyInterface) Reset() error

Reset stub

type Ethernet

type Ethernet struct {
	// contains filtered or unexported fields
}

Ethernet implements the Interface interface

func NewEthernet

func NewEthernet(iface string) *Ethernet

NewEthernet contructor

func (*Ethernet) Configure

func (e *Ethernet) Configure() (InterfaceConfig, error)

Configure the interface

func (*Ethernet) Connect

func (e *Ethernet) Connect() error

Connect network interface

func (*Ethernet) Desc

func (e *Ethernet) Desc() string

Desc returns a description of the interface

func (*Ethernet) Enable

func (e *Ethernet) Enable(en bool) error

Enable or disable interface

func (*Ethernet) GetStatus

func (e *Ethernet) GetStatus() (InterfaceStatus, error)

GetStatus returns ethernet interface status

func (*Ethernet) Reset

func (e *Ethernet) Reset() error

Reset interface. Currently no-op for ethernet

type GpioDir added in v0.14.5

type GpioDir int

GpioDir specifies Gpio Direction

const (
	GpioDirUnknown GpioDir = -1
	GpioIn         GpioDir = 0
	GpioOut        GpioDir = 1
)

Gpio dir values

type GpioLevel added in v0.14.5

type GpioLevel int

GpioLevel describes GPIO level

const (
	GpioLevelUnknown GpioLevel = -1
	GpioLow          GpioLevel = 0
	GpioHigh         GpioLevel = 1
)

Gpio Level values

type Interface

type Interface interface {
	Desc() string
	Configure() (InterfaceConfig, error)
	Connect() error
	GetStatus() (InterfaceStatus, error)
	Reset() error
	Enable(bool) error
}

Interface is an interface that network drivers implement

type InterfaceConfig

type InterfaceConfig struct {
	Imei    string
	Sim     string
	Apn     string
	Version string
}

InterfaceConfig contains static information about an interface

type InterfaceStatus

type InterfaceStatus struct {
	Detected  bool
	Connected bool
	Operator  string
	Signal    int
	Rsrp      int
	Rsrq      int
	IP        string
}

InterfaceStatus defines the status of an interface

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager is used to configure the network and manage the lifecycle.

func NewManager

func NewManager(errResetCnt int) *Manager

NewManager constructor

func (*Manager) AddInterface

func (m *Manager) AddInterface(iface Interface)

AddInterface adds a network interface to the manager. Interfaces added first have higher priority

func (*Manager) Desc

func (m *Manager) Desc() string

Desc returns current interface description

func (*Manager) Error

func (m *Manager) Error()

Error is called any time there is a network error after errResetCnt errors are reached, we reset all the interfaces and start over

func (*Manager) Reset

func (m *Manager) Reset()

Reset resets all network interfaces

func (*Manager) Run

Run must be called periodically to process the network life cycle -- perhaps every 10s

func (*Manager) Success

func (m *Manager) Success()

Success is called any time there is a network success so that we know to reset the internal error count

type Modem

type Modem struct {
	// contains filtered or unexported fields
}

Modem is an interface that always reports detected/connected

func NewModem

func NewModem(config ModemConfig) *Modem

NewModem constructor

func (*Modem) Configure

func (m *Modem) Configure() (InterfaceConfig, error)

Configure modem interface

func (*Modem) Connect

func (m *Modem) Connect() error

Connect stub

func (*Modem) Desc

func (m *Modem) Desc() string

Desc returns description

func (*Modem) Enable

func (m *Modem) Enable(en bool) error

Enable or disable interface

func (*Modem) GetLocation

func (m *Modem) GetLocation() (data.GpsPos, error)

GetLocation returns current GPS location

func (*Modem) GetStatus

func (m *Modem) GetStatus() (InterfaceStatus, error)

GetStatus return interface status

func (*Modem) Reset

func (m *Modem) Reset() error

Reset stub

type ModemConfig

type ModemConfig struct {
	ChatScript    string
	AtCmdPortName string
	Reset         func() error
	Debug         bool
	APN           string
}

ModemConfig describes the configuration for a modem

type State

type State int

State is used to describe the network state

const (
	StateNotDetected State = iota
	StateConfigure
	StateConnecting
	StateConnected
	StateError
)

define valid states

func (State) String

func (s State) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL