diff --git a/cli-mon.go b/cli-mon.go index 1801a31..a442827 100644 --- a/cli-mon.go +++ b/cli-mon.go @@ -54,9 +54,11 @@ func main() { updates := make(chan *yabl.Event, 1000) + isOffline := len(*filename) > 0 || *stdin + var f func() f = func() { - if events, ok := converter.CheckTimeouts(); ok { + if events, ok := converter.CheckTimeouts(isOffline); ok { for _, event := range events { updates <- event } diff --git a/yabl/protocol.go b/yabl/protocol.go index 47bfbfd..9a0cbdc 100644 --- a/yabl/protocol.go +++ b/yabl/protocol.go @@ -57,7 +57,7 @@ type converter struct { type Converter interface { EventsFromFrame(*can.CanFrame) ([]*Event, bool) - CheckTimeouts() ([]*Event, bool) + CheckTimeouts(isOffline bool) ([]*Event, bool) } func NewProtocolConverter() Converter { @@ -122,12 +122,19 @@ func (u unit) GetUnitId() uint { return uint(u) } -func (c *converter) CheckTimeouts() ([]*Event, bool) { +func (c *converter) CheckTimeouts(isOffline bool) ([]*Event, bool) { var multipler uint = 2 var events []*Event for k, param := range c.protocolMap { - now := time.Now() + + var now time.Time + if isOffline { + now = getMaxTime(&c.protocolMap) + } else { + now = time.Now() + } + deadline := now.Add(-time.Duration(param.interval*multipler) * time.Millisecond) var from uint8 = 0 @@ -161,3 +168,16 @@ func (c *converter) CheckTimeouts() ([]*Event, bool) { } return events, events != nil } + +func getMaxTime(protocolMap *map[key]action) time.Time { + now := time.Unix(0, 0) + + for _, param := range *protocolMap { + for _, fld := range param.fields { + if fld.last != nil && fld.last.After(now) { + now = *fld.last + } + } + } + return now +}