Documentation ¶
Index ¶
- func FindModem(ctx context.Context, d *udev.Device) (*db.Dongle, error)
- func NewModem(ctx context.Context, c *Conn) (*db.Dongle, error)
- type Conn
- type Manager
- func (m *Manager) AddDevice(ctx context.Context, d *udev.Device) error
- func (m *Manager) Close()
- func (m *Manager) RemoveDevice(ctx context.Context, dpath string) error
- func (m *Manager) Run(ctx context.Context) error
- func (m *Manager) Startup(ctx context.Context)
- func (m *Manager) Symlink(d *db.Dongle)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindModem ¶
FindDongle thic=s checks if the udev Device is a donge. We are only interested in dongle that we can communicate with via serial port.
For a plugged in 3g dongle, three devices are seen by udev. They are registered in three different tty. For isntance tty0,tty1,tty2. It is not obvious to know which is the command tty.
Only two tty's are candidates for the command dongle. The criteria of picking the right candidate is based on whether we can get IMEI and IMSI number from the tty.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn is a device serial connection
func (*Conn) Exec ¶
Exec sends the command over serial port and rrturns the response. If the port is closed it is opened before sending the command.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages devices that are plugged into the system. It supports auto detection of devices.
Serial ports are opened each for a device, and a clean API for communicating is provided via Read, Write and Flush methods.
The devices are monitored via udev, and any changes that requires reloading of the ports are handled by reloading the ports to the devices.
This is safe to use concurrently in multiple goroutines
func (*Manager) AddDevice ¶
AddDevice adds device name to the manager
WARNING: The way modems are picked is a hack. It asserts that the modem with the lowest tty number is the control modem( Which I'm not so sure is always correct).
TODO: comeup with a proper way to identify modems
func (*Manager) Close ¶
func (m *Manager) Close()
Close shuts down the device manager. This makes sure the udev monitor is closed and all goroutines are properly exited.