Skip to content

Commit

Permalink
added message sendType, start/delayTime
Browse files Browse the repository at this point in the history
  • Loading branch information
FerroO2000 committed Apr 18, 2024
1 parent b8122f3 commit b550413
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 6 deletions.
80 changes: 78 additions & 2 deletions examples/convert/main.go → examples/sc24/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@ import (
var (
flagType = acmelib.NewFlagSignalType("flag")
float16Type, _ = acmelib.NewFloatSignalType("float16", 16)
unit8Type, _ = acmelib.NewIntegerSignalType("uint8", 8, false)
)

var (
voltageUnit = acmelib.NewSignalUnit("voltage", acmelib.SignalUnitKindElectrical, "V")
celsiusDegUnit = acmelib.NewSignalUnit("celsius_deg", acmelib.SignalUnitKindTemperature, "degC")
voltageUnit = acmelib.NewSignalUnit("voltage", acmelib.SignalUnitKindElectrical, "V")
milliAmpereUnit = acmelib.NewSignalUnit("milli_ampere", acmelib.SignalUnitKindElectrical, "mA")
celsiusDegUnit = acmelib.NewSignalUnit("celsius_deg", acmelib.SignalUnitKindTemperature, "degC")
kiloWattUnit = acmelib.NewSignalUnit("kilo_watt", acmelib.SignalUnitKindPower, "kW")
)

var (
genSigStartVal, _ = acmelib.NewFloatAttribute("GenSigStartValue", 0, 0, 100000000000)
)

func main() {
Expand Down Expand Up @@ -57,6 +64,17 @@ func main() {
nvbRXDiagnosisMsg := nvbRXDiagnosis()
err = hvbNode.AddMessage(nvbRXDiagnosisMsg)
panicErr(err)

hvbRXCurLimMsg := hvbRXCurLim()
err = hvbNode.AddMessage(hvbRXCurLimMsg)
panicErr(err)
hvbRXCurLimMsg.AddReceiver(chargerNode)
hvbRXCurLimMsg.AddReceiver(vcuNode)

hvbRXStatusMsg := hvbRXStatus()
panicErr(hvbNode.AddMessage(hvbRXStatusMsg))
hvbRXStatusMsg.AddReceiver(chargerNode)
hvbRXStatusMsg.AddReceiver(vcuNode)
}

func panicErr(err error) {
Expand Down Expand Up @@ -114,6 +132,8 @@ func info02DbgT() *acmelib.Message {
sig.SetUnit(celsiusDegUnit)
sig.SetDesc(fmt.Sprintf("Thermistor %d temperature.", i))

sig.AddAttributeValue(genSigStartVal, 23315)

err = muxSig.AppendMuxSignal(selectValue, sig)
panicErr(err)
}
Expand Down Expand Up @@ -188,3 +208,59 @@ func nvbRXDiagnosis() *acmelib.Message {

return msg
}

func hvbRXCurLim() *acmelib.Message {
msg := acmelib.NewMessage("HVB_RX_CurrentLimits", 8)
msg.SetID(514)

chargeCurLim, err := acmelib.NewStandardSignal("HVB_ChargeCurLimits", float16Type)
panicErr(err)
chargeCurLim.SetUnit(milliAmpereUnit)
chargeCurLim.SetPhysicalValues(0, 1310.7, 0, 0.02)
chargeCurLim.SetDesc("Maximum potential charging power limit. even in case of a protection this values is shown what might possible if no protection is on")
err = msg.InsertSignal(chargeCurLim, 7)
panicErr(err)

dischargeCurLim, err := acmelib.NewStandardSignal("HVB_DischargeCurLimits", float16Type)
panicErr(err)
dischargeCurLim.SetUnit(milliAmpereUnit)
dischargeCurLim.SetPhysicalValues(0, 1310.7, 0, 0.02)
dischargeCurLim.SetDesc("Maximum discharging power limit. even in case of a protection this values is shown what might possible if no protection is on")
err = msg.InsertSignal(dischargeCurLim, 23)
panicErr(err)

pwrHvb, err := acmelib.NewStandardSignal("HVB_pwrHvb", float16Type)
panicErr(err)
pwrHvb.SetUnit(kiloWattUnit)
pwrHvb.SetPhysicalValues(-1310.72, 1310.68, 0, 0.04)
pwrHvb.SetDesc("instantaneous net power (+ for input, - for output)")
err = msg.InsertSignal(pwrHvb, 39)
panicErr(err)

return msg
}

func hvbRXStatus() *acmelib.Message {
msg := acmelib.NewMessage("HVB_RX_CurrentLimits", 8)
msg.SetID(515)

stSysEnum := acmelib.NewSignalEnum("HVB_stSys_enum")
stSysEnum.SetMinSize(8)
panicErr(stSysEnum.AddValue(acmelib.NewSignalEnumValue("OFF", 0)))
panicErr(stSysEnum.AddValue(acmelib.NewSignalEnumValue("STARTUP", 1)))
panicErr(stSysEnum.AddValue(acmelib.NewSignalEnumValue("ON", 2)))
panicErr(stSysEnum.AddValue(acmelib.NewSignalEnumValue("SHUTDOWN", 3)))
panicErr(stSysEnum.AddValue(acmelib.NewSignalEnumValue("ERROR", 5)))

stSysSig, err := acmelib.NewEnumSignal("HVB_stSys", stSysEnum)
panicErr(err)
stSysSig.SetDesc("present system main state (State Machine)")
panicErr(msg.InsertSignal(stSysSig, 7))

stInv, err := acmelib.NewStandardSignal("HVB_stInv", unit8Type)
panicErr(err)
stInv.SetDesc("present state for Inverter")
panicErr(msg.InsertSignal(stInv, 15))

return msg
}
60 changes: 56 additions & 4 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ const (
MessagePriorityLow
)

// MessageSendType rappresents the transition type of a [Message].
type MessageSendType string

const (
// MessageSendTypeUnset defines an unset transmission type.
MessageSendTypeUnset MessageSendType = "unset"
// MessageSendTypeCyclic defines a cyclic transmission type.
MessageSendTypeCyclic MessageSendType = "cyclic"
// MessageSendTypeCyclicIfActive defines a cyclic if active transmission type.
MessageSendTypeCyclicIfActive MessageSendType = "cyclicIfActive"
// MessageSendTypeCyclicIfTriggered defines a cyclic if triggered transmission type.
MessageSendTypeCyclicIfTriggered MessageSendType = "cyclicAndTriggered"
// MessageSendTypeCyclicIfActiveAndTriggered defines a cyclic if active and triggered transmission type.
MessageSendTypeCyclicIfActiveAndTriggered MessageSendType = "cyclicIfActiveAndTriggered"
)

// Message is the representation of data sent by a node thought the bus.
// It holds a list of signals that are contained in the message payload.
type Message struct {
Expand All @@ -65,7 +81,10 @@ type Message struct {
idGenFn MessageIDGeneratorFn
priority MessagePriority

cycleTime uint
cycleTime int
sendType MessageSendType
delayTime int
startDelayTime int

receivers *set[EntityID, *Node]
}
Expand All @@ -90,7 +109,10 @@ func NewMessage(name string, sizeByte int) *Message {
idGenFn: defMsgIDGenFn,
priority: MessagePriorityVeryHigh,

cycleTime: 0,
cycleTime: 0,
sendType: MessageSendTypeUnset,
delayTime: 0,
startDelayTime: 0,

receivers: newSet[EntityID, *Node]("receiver"),
}
Expand Down Expand Up @@ -417,15 +439,45 @@ func (m *Message) Priority() MessagePriority {
}

// SetCycleTime sets the message cycle time.
func (m *Message) SetCycleTime(cycleTime uint) {
func (m *Message) SetCycleTime(cycleTime int) {
m.cycleTime = cycleTime
}

// CycleTime returns the message cycle time.
func (m *Message) CycleTime() uint {
func (m *Message) CycleTime() int {
return m.cycleTime
}

// SetSendType sets the send type of the [Message].
func (m *Message) SetSendType(sendType MessageSendType) {
m.sendType = sendType
}

// SendType returns the message send type.
func (m *Message) SendType() MessageSendType {
return m.sendType
}

// SetDelayTime sets the delay time of the [Message].
func (m *Message) SetDelayTime(delayTime int) {
m.delayTime = delayTime
}

// DelayTime returns the message delay time.
func (m *Message) DelayTime() int {
return m.delayTime
}

// SetStartDelayTime sets the start delay time of the [Message].
func (m *Message) SetStartDelayTime(startDelayTime int) {
m.startDelayTime = startDelayTime
}

// StartDelayTime returns the message start delay time.
func (m *Message) StartDelayTime() int {
return m.startDelayTime
}

// AddReceiver adds a receiver [Node] to the [Message].
func (m *Message) AddReceiver(receiver *Node) {
m.receivers.add(receiver.entityID, receiver)
Expand Down
2 changes: 2 additions & 0 deletions signal_unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const (
SignalUnitKindTemperature SignalUnitKind = "signal_unit-temperature"
// SignalUnitKindElectrical defines an electrical unit.
SignalUnitKindElectrical SignalUnitKind = "signal_unit-electrical"
// SignalUnitKindPower defines a power unit.
SignalUnitKindPower SignalUnitKind = "signal_unit-power"
)

// SignalUnit is an entity that defines the physical unit of a [Signal].
Expand Down

0 comments on commit b550413

Please sign in to comment.