udev

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2017 License: MIT Imports: 20 Imported by: 3

Documentation

Index

Constants

View Source
const MaxAttempt = 3

MaxAttempt is the maximum numbet of attempts to find imsi and imsi

Variables

This section is empty.

Functions

func ClearSymlinks() error

ClearSymlinks remove all symlinks that wrere created by this aoolication

func FindModem

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

FindModem 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)

NewModem talks to the device to determine if the device is a dongle

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

RemoveDevice removes the dongle which has been tracked by the manager

func (*Manager) Run

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

Run initializes the manager. This involves creating a new goroutine to watch over the changes detected by udev for any device interaction with the system.

The only interesting device actions are add and reomove for adding and removing devices respctively.

func (*Manager) Startup

func (m *Manager) Startup(ctx context.Context)

Startup starts the manager for the first time. This deals with devices that are already in the system by the time the manager was started

func (m *Manager) Symlink(d *db.Dongle) error

Symlink creates symlink for the dongle. The symlinks are for both imei and imsi.

Jump to

Keyboard shortcuts

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