logging with date time format.
This commit is contained in:
parent
29d7dc1632
commit
39b5a95eb4
@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/google/gousb"
|
"github.com/google/gousb"
|
||||||
@ -35,7 +34,7 @@ func ListenForTrainer(vendorId gousb.ID, productId gousb.ID, deviceNumber uint32
|
|||||||
}
|
}
|
||||||
defer drv.Close()
|
defer drv.Close()
|
||||||
|
|
||||||
fmt.Println("device opened")
|
logMsg("device opened")
|
||||||
|
|
||||||
if err := resetAndWait(drv); err != nil {
|
if err := resetAndWait(drv); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -43,15 +42,15 @@ func ListenForTrainer(vendorId gousb.ID, productId gousb.ID, deviceNumber uint32
|
|||||||
if err := device.StartRxScanModeWait(drv); err != nil {
|
if err := device.StartRxScanModeWait(drv); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
fmt.Println("scan mode started")
|
logMsg("scan mode started")
|
||||||
|
|
||||||
msgs := make(chan ant.BroadcastMessage, 100)
|
msgs := make(chan ant.BroadcastMessage, 100)
|
||||||
go device.DumpBroadcastMessages(context.Background(), drv, msgs)
|
go device.DumpBroadcastMessages(context.Background(), drv, msgs)
|
||||||
|
|
||||||
fmt.Println("listening...")
|
logMsg("listening...")
|
||||||
for msg := range msgs {
|
for msg := range msgs {
|
||||||
if msg.DeviceNumber() != deviceNumber {
|
if msg.DeviceNumber() != deviceNumber {
|
||||||
fmt.Printf("Received msg from ignored ant+ device %v\n", msg.DeviceNumber())
|
logPrintf("Received msg from ignored ant+ device %v\n", msg.DeviceNumber())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
//fmt.Printf("raw msg: device type=0x%02x device number=%d content=%x\n",
|
//fmt.Printf("raw msg: device type=0x%02x device number=%d content=%x\n",
|
||||||
@ -65,7 +64,7 @@ func ListenForTrainer(vendorId gousb.ID, productId gousb.ID, deviceNumber uint32
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
cur := ant.PowerMessage(msg)
|
cur := ant.PowerMessage(msg)
|
||||||
fmt.Printf("%v: power: %dW cadence: %d rpm\n",
|
logPrintf("ant: %v: power: %dW cadence: %d rpm\n",
|
||||||
msg.DeviceNumber(), cur.InstantaneousPower(), cur.InstantaneousCadence())
|
msg.DeviceNumber(), cur.InstantaneousPower(), cur.InstantaneousCadence())
|
||||||
events <- Event{
|
events <- Event{
|
||||||
Power: cur.InstantaneousPower(),
|
Power: cur.InstantaneousPower(),
|
||||||
|
|||||||
@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
|
||||||
"math"
|
"math"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -43,7 +42,7 @@ func ExposeBluetooth(events <-chan Event) {
|
|||||||
ServiceUUIDs: []bluetooth.UUID{bluetooth.New16BitUUID(0x1818)},
|
ServiceUUIDs: []bluetooth.UUID{bluetooth.New16BitUUID(0x1818)},
|
||||||
}))
|
}))
|
||||||
must(adapter.DefaultAdvertisement().Start())
|
must(adapter.DefaultAdvertisement().Start())
|
||||||
fmt.Println("BLE advertising...")
|
logMsg("BLE advertising...")
|
||||||
|
|
||||||
var totalRevs float64
|
var totalRevs float64
|
||||||
var lastCompletedRev float64 // time in 1/1024s of last completed revolution
|
var lastCompletedRev float64 // time in 1/1024s of last completed revolution
|
||||||
@ -74,7 +73,7 @@ func ExposeBluetooth(events <-chan Event) {
|
|||||||
binary.LittleEndian.PutUint16(payload[6:], uint16(lastCompletedRev))
|
binary.LittleEndian.PutUint16(payload[6:], uint16(lastCompletedRev))
|
||||||
|
|
||||||
powerChar.Write(payload)
|
powerChar.Write(payload)
|
||||||
fmt.Printf("watts: %d rpm: %.0f completedRevs: %.0f lastRevTime: %.0f\n",
|
logPrintf("bt: watts: %d rpm: %.0f completedRevs: %.0f lastRevTime: %.0f processingTime: %v\n",
|
||||||
watts, rpm, completedRevs, lastCompletedRev)
|
watts, rpm, completedRevs, lastCompletedRev, time.Now().Sub(now))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user