34 lines
654 B
Go
34 lines
654 B
Go
package models
|
|
|
|
import (
|
|
"fiskerinc.com/modules/common"
|
|
)
|
|
|
|
func NewCANSignal(position int, name string, convert func(value float64) interface{}) CANSignal {
|
|
return CANSignal{
|
|
Position: position,
|
|
Name: name,
|
|
RedisKey: name,
|
|
ConvertValue: convert,
|
|
}
|
|
}
|
|
|
|
type CANSignal struct {
|
|
Position int
|
|
Name string
|
|
RedisKey string
|
|
ConvertValue func(value float64) interface{}
|
|
}
|
|
|
|
func (c *CANSignal) ParseState(signal common.CANSignal) interface{} {
|
|
return c.getValue(signal.Value)
|
|
}
|
|
|
|
func (c *CANSignal) getValue(value float64) interface{} {
|
|
if c.ConvertValue == nil {
|
|
return value
|
|
}
|
|
|
|
return c.ConvertValue(value)
|
|
}
|