Correct timestamp when reading from stdin or file

This commit is contained in:
2023-08-04 01:05:56 +03:00
parent e42d3b5722
commit 6521b707dd
4 changed files with 97 additions and 22 deletions
+5 -6
View File
@@ -1,7 +1,7 @@
package yabl
import (
"cli-mon/can"
can "cli-mon/can"
"encoding/binary"
time "time"
)
@@ -40,7 +40,7 @@ type Event struct {
ActionName AName
Field FName
Object Action
Updated time.Time
Updated *time.Time
Value any
}
@@ -55,7 +55,7 @@ type field struct {
length uint8
setter func(uint64 uint64) any
value uint64
last time.Time
last *time.Time
name FName
}
@@ -106,14 +106,13 @@ func StartProtocolParsing(frames <-chan *can.CanFrame) <-chan *Event {
var unitId = uint((frame.CanId & UNIT_ID_MASK) >> UNIT_ID_OFFSET)
var canId = frame.CanId & ACTION_ID_MASK
var k = key{canId: canId, unitId: unitId}
var now = time.Now()
param := protocolMap[k]
var start uint8 = 0
for _, f := range param.fields {
if val, found := get(start, f.length, frame.Payload); found {
f.last = now
f.last = frame.Date
if f.value != val {
f.value = val
obj := f.setter(val)
@@ -122,7 +121,7 @@ func StartProtocolParsing(frames <-chan *can.CanFrame) <-chan *Event {
ActionName: param.name,
Object: param.object,
UnitId: unitId,
Updated: now,
Updated: frame.Date,
Value: obj,
}
}