lappy

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2018 License: MIT Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Lappy

Lappy is a backend for AMB TranX-2 timing system.

Build Status GoDoc codecov Go Report Card

Features

  • Read passing and noise events from serial device
  • Store passing events in sqlite database with race id
  • Publish noise and passing events as server-sent events
  • Associate metadata with race records
  • Systemd files
  • HTTP API
    • Starting and stopping recoring and publishing passing events
    • Subscribe to SSE
    • CRUD for metadata like drivers names and car numbers
    • Fetch records per race
    • Fetch top records

Configuration

Required environment variables:

  • LOG_LEVEL : debug|info|error
  • DSN : sqlite3 DSN eg. file:test.db
  • LISTEN_ADDR : address to listen eg. 0.0.0.0:8000
  • SERIAL_PORT : path to serial device eg. /dev/usbTTY11

Running with docker using local serial device

Create tunnel with socat

socat -d -d PTY,raw,echo=0 PTY,raw,echo=0
2018/09/12 13:33:11 socat[31301] N PTY is /dev/pts/4
2018/09/12 13:33:11 socat[31301] N PTY is /dev/pts/5
2018/09/12 13:33:11 socat[31301] N starting data transfer loop with FDs [5,5] and [7,7]

Start container and mount /dev/pts to access just created /dev/pts/4

docker run --rm -it \
    -v /dev/pts:/dev/pts \
    -p 8000:8000 \
    -e LOG_LEVEL='debug' \
    -e DSN='file:test.db' \
    -e LISTEN_ADDR=':8000' \
    -e SERIAL_PORT='/dev/pts/4' \
    bitbrewers/lappy:latest

Install simulator and start it to create trafic

go get github.com/bitbrewers/tranx2/cmd/tranx2sim
tranx2sim -i 10000 -t 5 -j 2000 > /dev/pts/5

Running locally with simulator

Instructions for basic linux setup

Requirements
  • socat
  • go
  • tranx2sim
Steps
  1. Install socat and go from repos
  2. Install tranx2sim: go get github.com/bitbrewers/tranx2/cmd/tranx2sim
  3. Use socat for piping serial data: socat PTY,raw,link=ttyS10,echo=0 PTY,raw,link=ttyS11,echo=0
  4. Start simulator tranx2sim -i 10000 -t 5 -j 2000 > ./ttyS10
  5. Start lappy with SERIAL_PORT=./ttyS11

Development

Clone repo and run make dev. For more check the Makefile.

Documentation

Index

Constants

View Source
const (
	RecordsStream = "records"
	NoiseStream   = "noise"
)

Stream names

Variables

View Source
var (
	ErrNoOngoingRace = errors.New("no ongoing race found")
	ErrRaceOngoing   = errors.New("race already ongoing")
)

Functions

This section is empty.

Types

type FatalLogger

type FatalLogger struct{}

func (FatalLogger) Debugf

func (FatalLogger) Debugf(_ string, _ ...interface{})

func (FatalLogger) Errorf

func (FatalLogger) Errorf(_ string, _ ...interface{})

func (FatalLogger) Fatalf

func (FatalLogger) Fatalf(tmpl string, args ...interface{})

func (FatalLogger) Infof

func (FatalLogger) Infof(_ string, _ ...interface{})

type Handler

type Handler struct {
	Log       Logger
	Storage   Storage
	Publisher Publisher
}

func (*Handler) OnError

func (h *Handler) OnError(err error)

func (*Handler) OnNoise

func (h *Handler) OnNoise(noise uint16)

func (*Handler) OnPassing

func (h *Handler) OnPassing(passing tranx2.Passing)

type Logger

type Logger interface {
	Debugf(tmpl string, args ...interface{})
	Infof(tmpl string, args ...interface{})
	Errorf(tmpl string, args ...interface{})
	Fatalf(tmpl string, args ...interface{})
}

type Publisher

type Publisher interface {
	PublishRecord(rec Record)
	PublishNoise(noise uint16)
}

type Race

type Race struct {
	ID      int64
	Started *time.Time
	Ended   *time.Time
}

type Record

type Record struct {
	ID     int64
	RaceID int64
	tranx2.Passing
}

type SqliteStorage

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

func NewSqliteStorage

func NewSqliteStorage(dsn string) (*SqliteStorage, error)

func (*SqliteStorage) Save

func (s *SqliteStorage) Save(passing tranx2.Passing) (rec Record, err error)

func (*SqliteStorage) StartRace

func (s *SqliteStorage) StartRace(started time.Time) (race Race, err error)

func (*SqliteStorage) StopRace

func (s *SqliteStorage) StopRace(ended time.Time) (err error)

type SsePublisher

type SsePublisher struct {
	Server *sse.Server
	Log    Logger
}

func NewSsePublisher

func NewSsePublisher() *SsePublisher

func (*SsePublisher) PublishNoise

func (s *SsePublisher) PublishNoise(noise uint16)

func (*SsePublisher) PublishRecord

func (s *SsePublisher) PublishRecord(rec Record)

type Storage

type Storage interface {
	Save(passing tranx2.Passing) (rec Record, err error)
}

Directories

Path Synopsis
cmd
lappy command

Jump to

Keyboard shortcuts

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