Skip to content

Commit

Permalink
Upgrades + new logger (#16)
Browse files Browse the repository at this point in the history
* Use the race detector on unit tests

* Advanced file log reading

* RW

* fixes

* win builds
  • Loading branch information
half2me authored Aug 8, 2017
1 parent 20a6ef0 commit a837b36
Show file tree
Hide file tree
Showing 13 changed files with 166 additions and 352 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ env:
- CGO_ENABLED=1

script:
- go test ./...
- go test -race ./...

after_script:
- GOARCH=amd64 go build -o "bin/antdump-${TRAVIS_OS_NAME}-x64" -i cmd/antdump/antdump.go
- GOARCH=amd64 go build -o "bin/antserver-${TRAVIS_OS_NAME}-x64" -i cmd/antserver/antserver.go
- go build -o "bin/antdump-${TRAVIS_OS_NAME}" -i cmd/antdump/antdump.go

deploy:
skip_cleanup: true
Expand Down
6 changes: 3 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ clone_folder: C:\msys64\go\src\github.com\half2me\antgo

install:
- C:\msys64\usr\bin\bash.exe -lc "cd /go/src/github.com/half2me/antgo && ./av.sh"
- 7z a antgo-win64.zip C:\msys64\go\src\github.com\half2me\antgo\antserver-win64.exe C:\msys64\go\src\github.com\half2me\antgo\antdump-win64.exe C:\msys64\mingw64\bin\libusb-1.0.dll
- 7z a antgo-win.zip C:\msys64\go\src\github.com\half2me\antgo\antdump-win.exe C:\msys64\mingw64\bin\libusb-1.0.dll

build: off

artifacts:
- path: antgo-win64.zip
- path: antgo-win.zip
name: binary

deploy:
release: antdump-win64
release: antdump-win
description: 'Antgo'
provider: GitHub
auth_token:
Expand Down
3 changes: 1 addition & 2 deletions av.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ pacman --noconfirm -S \
go version
go get github.com/half2me/antgo/... && \
go test ./... && \
go build -o antdump-win64.exe -i cmd/antdump/antdump.go && \
go build -o antserver-win64.exe -i cmd/antserver/antserver.go && \
go build -o antdump-win.exe -i cmd/antdump/antdump.go && \
echo "Build complete!" #
59 changes: 26 additions & 33 deletions cmd/antdump/antdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,10 @@ import (
"net/url"
"fmt"
"time"
"github.com/half2me/antgo/driver/usb"
"github.com/half2me/antgo/driver/file"
)

// Write ANT packets to a file
func writeToFile(in <-chan message.AntPacket, done chan<- struct{}) {
defer func() {done<-struct {}{}}()
f, err := os.Create(*outfile)
if err != nil {
panic(err.Error())
}

defer f.Close()

for m := range in {
f.Write(m)
}
}

func sendToWs(in <-chan message.AntPacket, done chan<- struct{}) {
defer func() {done<-struct {}{}}()
u, errp := url.Parse(*wsAddr)
Expand Down Expand Up @@ -108,13 +95,13 @@ func loop(in <-chan message.AntPacket, done chan<- struct{}) {

outs := make([]chan message.AntPacket, 0, 2)

var f *file.AntCaptureFile

//File
if len(*outfile) > 0 {
c := make(chan message.AntPacket)
cdone := make(chan struct{})
go writeToFile(c, cdone)
defer func() {<-cdone}()
outs = append(outs, c)
f = file.GetAntCaptureFile(*outfile)
if e := f.Open(); e != nil {panic(e.Error())}
defer f.Close()
}

// Ws
Expand All @@ -139,6 +126,10 @@ func loop(in <-chan message.AntPacket, done chan<- struct{}) {
default:
}
}

if f != nil {
f.Write(m)
}
}
}
}
Expand All @@ -151,36 +142,38 @@ var wsAddr = flag.String("ws", "", "Upload ANT+ data to a websocket server at ad
var silent = flag.Bool("silent", false, "Don't show ANT+ data on terminal")
var persistent = flag.Bool("persistent", false, "Don't panic on errors, keep trying")

var stopFile = make(chan struct{})

func main() {
flag.Parse()

if *persistent {
log.Println("Persistent mode actvated!")
}

var device *driver.AntDevice
antIn := make(chan message.AntPacket)
antOut := make(chan message.AntPacket)
done := make(chan struct{})
defer func() {<-done}()

switch *drv {
case "usb":
device = driver.NewDevice(driver.GetUsbDevice(0x0fcf, *pid), antIn, antOut)
device := driver.NewDevice(usb.GetUsbDevice(0x0fcf, *pid), antIn, antOut)
if err := device.Start(); err != nil {panic(err.Error())}
defer device.Stop()
device.StartRxScanMode()
case "file":
device = driver.NewDevice(driver.GetAntCaptureFile(*inFile), antIn, antOut)
f := file.GetAntCaptureFile(*inFile)
if e := f.Open(); e != nil {
panic(e.Error())
}
go f.ReadLoop(antIn, stopFile)
defer func(){stopFile <- struct{}{}}()
default:
panic("Unknown driver specified!")
}

if err := device.Start(); err != nil {
panic(err.Error())
}

done := make(chan struct{})
go loop(device.Read, done)
defer func() {<-done}()
defer device.Stop()

device.StartRxScanMode()
go loop(antIn, done)

interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt)
Expand Down
233 changes: 0 additions & 233 deletions cmd/antserver/antserver.go

This file was deleted.

Loading

0 comments on commit a837b36

Please sign in to comment.