udev

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2017 License: MIT Imports: 19 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindModem

func FindModem(ctx context.Context, d *udev.Device) (*db.Dongle, error)

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.

func NewModem

func NewModem(ctx context.Context, cfg serial.Config) (*db.Dongle, error)

Types

type Conn

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

Conn is a device serial connection

func (*Conn) Close

func (c *Conn) Close() error

Close closes the port helt by *Conn.

func (*Conn) Exec

func (c *Conn) Exec(cmd string) ([]byte, error)

Exec sends the command over serial port and rrturns the response. If the port is closed it is opened before sending the command.

func (*Conn) Flush added in v0.1.3

func (c *Conn) Flush() error

func (*Conn) Open

func (c *Conn) Open() error

Open opens a serial port to the undelying device

func (*Conn) Read

func (c *Conn) Read(b []byte) (int, error)

Read reads from serial port

func (*Conn) Run

func (c *Conn) Run(cmd string) ([]byte, error)

Run helper for Exec that adds \r to the command

func (*Conn) Write

func (c *Conn) Write(b []byte) (int, error)

Write wites b to the serieal port

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 New

func New(db *sql.DB, s *events.Stream) *Manager

New returns a new Manager instance

func (*Manager) AddDevice

func (m *Manager) AddDevice(ctx context.Context, d *udev.Device) error

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.

func (*Manager) RemoveDevice

func (m *Manager) RemoveDevice(ctx context.Context, dpath string) error

func (*Manager) Run

func (m *Manager) Run(ctx context.Context) error

func (*Manager) Startup

func (m *Manager) Startup(ctx context.Context)
func (m *Manager) Symlink(d *db.Dongle)

Jump to

Keyboard shortcuts

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