Skip to content

Commit

Permalink
1.0.13 stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
roffe committed Mar 31, 2024
1 parent 9846400 commit b941c28
Show file tree
Hide file tree
Showing 17 changed files with 125 additions and 155 deletions.
2 changes: 1 addition & 1 deletion FyneApp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Website = "https://roffe.nu/"
Name = "txlogger"
ID = "com.roffe.txlogger"
Version = "1.0.13"
Build = 214
Build = 223
7 changes: 4 additions & 3 deletions WHATSNEW.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# 1.0.13

The default presets has been updated. Be sure to load it once from the settings menu to make sure ActualIn.n_Engine, Out.X_AccPedal & In.v_Vehicle are logged properly on Trionic 7
The default presets has been updated. Be sure to load it once from the settings menu to make sure ActualIn.n_Engine, Out.X_AccPedal & In.v_Vehicle is logged properly on Trionic 7

In earlier versions there existed different presets depending on your CAN adapter. This has been fixed and the presets are now the same for all adapters. The default presets has been updated to reflect this change

- This new window you are reading this in
- Added WHATSNEW.md that will be displayed once the first time a new version is started.
- A ton of code optimizations to make the Dashboard & logplayer use less cpu
- Added ignition duty cycle (Idc) to Dashboard, loggable via Myrtilos.InjectorDutyCycle once EU0D v25 is released, display value is 0 - 100%
- Fixed a bugg in the symbol list where "ghost" duplicates of symbols would be added when the same symbol was added to the list multiple times
- Changed symbol name in symbol list to be a label instead of a textbox, also added a copy symbol name button on each row
- Added additional symbols to Trionic 7 main menu
- It's now possible to create your own presets selectable from the preset dropdown
- It's now possible to create your own presets selectable from the preset dropdown
- Added a Log plotter in the log player so you can see line graphs of the recorded values
7 changes: 6 additions & 1 deletion pkg/datalogger/t7logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,14 @@ func (c *T7Client) onError(err error) {

func (c *T7Client) Start() error {
defer c.lw.Close()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cl, err := gocan.NewWithOpts(ctx, c.Device)

cl, err := gocan.NewWithOpts(
ctx,
c.Device,
)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/layout/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (l *Vertical) Layout(objects []fyne.CanvasObject, size fyne.Size) {
for i, o := range objects {
height := size.Height / float32(len(objects))
o.Resize(fyne.NewSize(o.MinSize().Width, o.MinSize().Height))
o.Move(fyne.NewPos(0, (float32(i)*height)+(height/2)-o.MinSize().Height/2))
o.Move(fyne.NewPos(0, (float32(i)*height)+(height*.5)-o.MinSize().Height*.5))
}
}

Expand Down
50 changes: 22 additions & 28 deletions pkg/logfile/csv_logfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,21 @@ import (
)

type CSVLogfile struct {
headerNames map[string]*string
records []Record
length int
pos int
records []Record
length int
pos int
}

func NewFromCSVLogfile(filename string) (Logfile, error) {
rec, err := parseCSVLogfile(filename)
if err != nil {
return nil, err
c := &CSVLogfile{
pos: -1,
}
csvlog := &CSVLogfile{
records: rec,
length: len(rec),
pos: -1,

if err := c.parseCSVLogfile(filename); err != nil {
return nil, err
}

return csvlog, nil
return c, nil
}

func (l *CSVLogfile) Next() Record {
Expand Down Expand Up @@ -64,12 +61,6 @@ func (l *CSVLogfile) Pos() int {
return l.pos
}

func (l *CSVLogfile) SeekTime(time.Time) Record {
return Record{
EOF: true,
}
}

func (l *CSVLogfile) Len() int {
return l.length
}
Expand All @@ -88,44 +79,47 @@ func (l *CSVLogfile) End() time.Time {
return time.Time{}
}

func parseCSVLogfile(filename string) ([]Record, error) {
func (l *CSVLogfile) parseCSVLogfile(filename string) error {
f, err := os.Open(filename)
if f != nil {
defer f.Close()
}
if err != nil {
return nil, err
return err
}
r := csv.NewReader(f)
records, err := r.ReadAll()
if err != nil {
return nil, err
return err
}

var recs []Record

for i := 1; i < len(records); i++ {
ts, err := time.Parse(datalogger.ISONICO, records[i][0])
if err != nil {
return nil, err
return err
}
rec := NewRecord(ts)

for j := 1; j < len(records[i]); j++ {
val, err := strconv.ParseFloat(records[i][j], 64)
if err != nil {
return nil, err
return err
}
rec.SetValue(records[0][j], val)
}

if i < len(records)-1 {
ts2, err := time.Parse(datalogger.ISONICO, records[i+1][0])
if err != nil {
return nil, err
return err
}
rec.DelayTillNext = ts2.Sub(ts).Milliseconds()
}

recs = append(recs, rec)
l.records = append(l.records, rec)
}

return recs, nil
l.length = len(l.records)

return nil
}
5 changes: 1 addition & 4 deletions pkg/logfile/logfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@ type Record struct {
DelayTillNext int64
Values map[string]float64
EOF bool
//mu sync.Mutex
}

func (r *Record) SetValue(key string, value float64) {
//r.mu.Lock()
//defer r.mu.Unlock()
func (r Record) SetValue(key string, value float64) {
r.Values[key] = value
}

Expand Down
84 changes: 34 additions & 50 deletions pkg/logfile/tx_logfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import (
"errors"
"log"
"os"
"runtime"
"strconv"
"strings"
"sync"
"time"
)

Expand All @@ -20,15 +18,14 @@ type TxLogfile struct {

func NewFromTxLogfile(filename string) (Logfile, error) {
// start := time.Now()
rec, err := parseTxLogfile(filename)
if err != nil {
return nil, err
}

// log.Printf("Parsed %d records in %s", len(rec), time.Since(start))
txlog := &TxLogfile{
records: rec,
length: len(rec),
pos: -1,
pos: -1,
}

if err := txlog.parseTxLogfile(filename); err != nil {
return nil, err
}

return txlog, nil
Expand Down Expand Up @@ -68,10 +65,6 @@ func (l *TxLogfile) Pos() int {
return l.pos
}

func (l *TxLogfile) SeekTime(time.Time) *Record {
return nil
}

func (l *TxLogfile) Len() int {
return l.length
}
Expand Down Expand Up @@ -107,43 +100,48 @@ func detectTimeFormat(text string) (string, error) {
return "", errors.New("could not detect time format")
}

func parseTxLogfile(filename string) ([]Record, error) {
lines, err := readTxLogfile(filename)
func (l *TxLogfile) parseTxLogfile(filename string) error {
lines := make([]string, 0)
readFile, err := os.Open(filename)
if readFile != nil {
defer readFile.Close()
}
if err != nil {
return nil, err
return err
}
buffer := make([]byte, 4*1024)
fileScanner := bufio.NewScanner(readFile)
fileScanner.Buffer(buffer, bufio.MaxScanTokenSize)
for fileScanner.Scan() {
lines = append(lines, string(fileScanner.Bytes()))
}

noLines := len(lines)

if noLines <= 0 {
return nil, errors.New("no lines in file")
return errors.New("no lines in file")
}

timeFormat, err := detectTimeFormat(lines[0])
if err != nil {
return nil, err
return err
}

records := make([]Record, noLines)
semChan := make(chan struct{}, runtime.NumCPU())
var wg sync.WaitGroup
l.records = make([]Record, noLines)
for pos := 0; pos < noLines; pos++ {
semChan <- struct{}{}
wg.Add(1)
go func(position int) {
defer wg.Done()
if record, err := parseLine(lines[position], timeFormat); err == nil {
if position+1 < noLines {
record.DelayTillNext = getDelayTillNext(lines[position+1], timeFormat, record.Time)
}
records[position] = record
} else {
log.Println(err)
if record, err := parseLine(lines[pos], timeFormat); err == nil {
if pos+1 < noLines {
record.DelayTillNext = getDelayTillNext(lines[pos+1], timeFormat, record.Time)
}
<-semChan
}(pos)
l.records[pos] = record
} else {
log.Println(err)
}
}
wg.Wait()
return records, nil

l.length = len(l.records)

return nil
}

func parseLine(line, timeFormat string) (Record, error) {
Expand Down Expand Up @@ -196,17 +194,3 @@ func splitTxLogLine(line, timeFormat string) (time.Time, []string, error) {
}
return parsedTime, touples[1:], nil
}

func readTxLogfile(filename string) ([]string, error) {
readFile, err := os.Open(filename)
if err != nil {
return nil, err
}
defer readFile.Close()
fileScanner := bufio.NewScanner(readFile)
var output []string
for fileScanner.Scan() {
output = append(output, fileScanner.Text())
}
return output, nil
}
22 changes: 16 additions & 6 deletions pkg/plotter/plotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import (
"fyne.io/fyne/v2/widget"
)

type PlotterControl interface {
Seek(int)
}

type Plotter struct {
widget.BaseWidget

Expand Down Expand Up @@ -134,19 +138,23 @@ func NewPlotter(values map[string][]float64, opts ...PlotterOpt) *Plotter {
}

func (p *Plotter) Seek(pos int) {
halfDataPointsToShow := p.dataPointsToShow / 2
halfDataPointsToShow := int(float64(p.dataPointsToShow) * .5)
offsetPosition := float64(pos - halfDataPointsToShow)
if offsetPosition > 0 && pos < p.dataLength-halfDataPointsToShow {
p.startPos = int(offsetPosition)
p.RefreshImage()
if pos < p.dataLength-halfDataPointsToShow {
if offsetPosition < 0 {
offsetPosition = 0
}
p.startPos = min(int(offsetPosition), p.dataLength)
}
p.cursorPos = pos + 1
p.RefreshImage()
p.cursorPos = pos
p.updateLegend()
p.updateCursor()
}

func (p *Plotter) updateCursor() {
x := float32(p.cursorPos-p.startPos) * p.widthFactor

x := float32(p.cursorPos-max(p.startPos, 0)) * p.widthFactor
xOffset := p.zoom.Size().Width + x
p.cursor.Position1 = fyne.NewPos(xOffset, 0)
p.cursor.Position2 = fyne.NewPos(xOffset+1, p.canvasImage.Size().Height)
Expand Down Expand Up @@ -198,6 +206,8 @@ func (p *Plotter) RefreshImage() {
continue
}
p.ts[n].PlotImage(img, p.values, p.startPos, p.dataPointsToShow)
//p.ts[n].PlotImage(p.canvasImage.Image.(*image.RGBA), p.values, p.startPos, p.dataPointsToShow)

}

p.canvasImage.Image = img
Expand Down
1 change: 1 addition & 0 deletions pkg/plotter/plotter_mouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func (p *Plotter) onZoom(value float64) {
p.startPos = 0
}
p.widthFactor = p.canvasImage.Size().Width / float32(p.dataPointsToShow)
p.updateCursor()
p.RefreshImage()
}

Expand Down
1 change: 1 addition & 0 deletions pkg/plotter/plotter_render.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func (r *plotterRenderer) Layout(size fyne.Size) {
pl := r.p.canvasImage.Size()
r.p.plotResolution = fyne.NewSize(pl.Width*r.p.plotResolutionFactor, pl.Height*r.p.plotResolutionFactor)
r.p.widthFactor = pl.Width / float32(r.p.dataPointsToShow)
//r.p.canvasImage.Image = image.NewRGBA(image.Rect(0, 0, int(r.p.plotResolution.Width), int(r.p.plotResolution.Height)))
r.p.RefreshImage()
r.p.updateCursor()
}
Expand Down
Loading

0 comments on commit b941c28

Please sign in to comment.