device

package
v0.0.0-...-8229079 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2016 License: MIT Imports: 18 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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) 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() *Manager

New returns a new Manager instance

func (*Manager) AddDevice

func (m *Manager) AddDevice(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) Init

func (m *Manager) Init()

Init 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) List

func (m *Manager) List(w http.ResponseWriter, r *http.Request)

List serves the list of current devices. The list wont cover all devices , only the significant ones( modems for now)

func (*Manager) RemoveDevice

func (m *Manager) RemoveDevice(name string) error

RemoveDevice removes device name from the manager

func (*Manager) RunCommand

func (m *Manager) RunCommand(w http.ResponseWriter, r *http.Request)

RunComand runs commands to the exposed devices over serial ports

func (m *Manager) Symlink() error

func (*Manager) Updates

func (m *Manager) Updates(w http.ResponseWriter, r *http.Request)

Updates is websocket http handler for sending updates about the devices plugged into the system in real time.

type Message

type Message struct {
	Type string                 `json:"type"`
	Data map[string]interface{} `json:"data"`
}

type Modem

type Modem struct {
	IMEI         string `json:"imei"`
	IMSI         string `json:"imsi"`
	Manufacturer string `json:"manufacturer"`
	Path         string `json:"tty"`
	// contains filtered or unexported fields
}
func (m *Modem) Symlink() error

Symlink adds symlink to the modem. The symlink links the tty to the IMEI number of the modem.

Two symlinks are created one for IMEI the other is for IMSI

/dev/ttyUSB -> {IMEI}.imei
/dev/ttyUSB -> {IMSI}.imsi

Jump to

Keyboard shortcuts

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