New release

This commit is contained in:
2023-08-06 07:43:21 +03:00
parent f00c743160
commit 6f83643247
7 changed files with 457 additions and 170 deletions
+44
View File
@@ -57,6 +57,7 @@ type converter struct {
type Converter interface {
EventsFromFrame(*can.CanFrame) ([]*Event, bool)
CheckTimeouts() ([]*Event, bool)
}
func NewProtocolConverter() Converter {
@@ -66,6 +67,9 @@ func NewProtocolConverter() Converter {
}
func (c *converter) EventsFromFrame(frame *can.CanFrame) ([]*Event, bool) {
if frame == nil {
return nil, false
}
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}
@@ -117,3 +121,43 @@ func get(from uint8, size uint8, buffer []byte) (uint64, bool) {
func (u unit) GetUnitId() uint {
return uint(u)
}
func (c *converter) CheckTimeouts() ([]*Event, bool) {
var multipler uint = 2
var events []*Event
for k, param := range c.protocolMap {
now := time.Now()
deadline := now.Add(-time.Duration(param.interval*multipler) * time.Millisecond)
var from uint8 = 0
for _, fld := range param.fields {
if fld.last == nil {
continue
} else if deadline.After(*fld.last) {
if events == nil {
events = make([]*Event, 0, len(param.fields))
}
event := &Event{
Field: fld.name,
ActionName: param.name,
Object: param.object,
unit: unit(k.unitId),
Updated: &now,
Value: nil,
}
var mask uint64 = ^(ALL_BITS << fld.length)
mask = mask << from
fld.value = mask
events = append(events, event)
fld.last = nil
}
from += fld.length
}
}
return events, events != nil
}
-1
View File
@@ -44,7 +44,6 @@ type Voltage9BitType float32
type ContactorInternalState struct {
unit
//UnitId uint
ContactorReady *BoardReadyType
ContactorOn *BooleanType
UnexpectedState *ErrorType