Fix offline timeouts
This commit is contained in:
+23
-3
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user