From 7fb77b0892e40639af704b2cbced3ed77da75aa7 Mon Sep 17 00:00:00 2001 From: FerroO2000 <30318301+FerroO2000@users.noreply.github.com> Date: Mon, 13 May 2024 08:29:33 +0200 Subject: [PATCH] sync pc --- canid_builder.go | 6 ++++- canid_builder_test.go | 2 +- examples/markdown/MCB.dbc | 52 ++++++++++++++++++++++++--------------- examples/markdown/SC24.md | 38 ++++++++++++++-------------- signal_unit.go | 25 +++++++++++++++---- template.go | 26 ++++++++++++++++++++ 6 files changed, 102 insertions(+), 47 deletions(-) create mode 100644 template.go diff --git a/canid_builder.go b/canid_builder.go index 4cbb9bd..e261d6d 100644 --- a/canid_builder.go +++ b/canid_builder.go @@ -29,11 +29,15 @@ func (bo *CANIDBuilderOp) Len() int { } type CANIDBuilder struct { + *entity + operations []*CANIDBuilderOp } -func NewCANIDBuilder() *CANIDBuilder { +func NewCANIDBuilder(name string) *CANIDBuilder { return &CANIDBuilder{ + entity: newEntity(name), + operations: []*CANIDBuilderOp{}, } } diff --git a/canid_builder_test.go b/canid_builder_test.go index 969ce26..7fd2127 100644 --- a/canid_builder_test.go +++ b/canid_builder_test.go @@ -9,7 +9,7 @@ import ( func Test_CANIDBuilder(t *testing.T) { assert := assert.New(t) - b := NewCANIDBuilder() + b := NewCANIDBuilder("canid_builder") b.UseMessagePriority(30).UseMessageID(4, 10).UseNodeID(0, 4) msgPriority := MessagePriorityLow diff --git a/examples/markdown/MCB.dbc b/examples/markdown/MCB.dbc index 347d6c2..8fc0dac 100644 --- a/examples/markdown/MCB.dbc +++ b/examples/markdown/MCB.dbc @@ -141,12 +141,20 @@ BO_ 49 SB_FRONT_sdcStatus: 1 SB_FRONT SG_ SDC_POST_COCKPIT_isClosed : 3|1@1+ (1,0) [0|1] "" DSPACE BO_ 1024 SB_FRONT_ntcResistance: 8 SB_FRONT - SG_ RAD_NTC_IN_resistance : 0|10@1+ (31.25,1000) [0|31968.75] "Ohm" DSPACE - SG_ RAD_NTC_OUT_resistance : 10|10@1+ (31.25,1000) [0|31968.75] "Ohm" DSPACE - SG_ JACKET_NTC_FRONT_resistance : 20|10@1+ (31.25,1000) [0|31968.75] "Ohm" DSPACE - SG_ JACKET_NTC_REAR_resistance : 30|10@1+ (31.25,1000) [0|31968.75] "Ohm" DSPACE - SG_ COLDPLATE_NTC_resistance : 40|10@1+ (31.25,1000) [0|31968.75] "Ohm" DSPACE - SG_ NTC_SPARE_resistance : 50|10@1+ (31.25,1000) [0|31968.75] "Ohm" DSPACE + SG_ JACKET_FL_NTC_resistance : 0|10@1+ (31.25,1000) [0|31968.75] "Ohm" DSPACE + SG_ JACKET_FR_NTC_resistance : 10|10@1+ (31.25,1000) [0|31968.75] "Ohm" DSPACE + SG_ COLDPLATE_L_NTC_resistance : 20|10@1+ (31.25,1000) [0|31968.75] "Ohm" DSPACE + SG_ COLDPLATE_R_NTC_resistance : 30|10@1+ (31.25,1000) [0|31968.75] "Ohm" DSPACE + SG_ SPARE_NTC_0_resistance : 40|10@1+ (31.25,1000) [0|31968.75] "Ohm" DSPACE + SG_ SPARE_NTC_1_resistance : 50|10@1+ (31.25,1000) [0|31968.75] "Ohm" DSPACE + +BO_ 1025 SB_REAR_ntcResistance: 8 SB_REAR + SG_ JACKET_RL_NTC_resistance : 0|10@1+ (31.25,1000) [0|31968.75] "Ohm" DSPACE + SG_ JACKET_RR_NTC_resistance : 10|10@1+ (31.25,1000) [0|31968.75] "Ohm" DSPACE + SG_ RAD_RL_IN_NTC_resistance : 20|10@1+ (31.25,1000) [0|31968.75] "Ohm" DSPACE + SG_ RAD_RL_OUT_NTC_resistance : 30|10@1+ (31.25,1000) [0|31968.75] "Ohm" DSPACE + SG_ RAD_RR_IN_NTC_resistance : 40|10@1+ (31.25,1000) [0|31968.75] "Ohm" DSPACE + SG_ RAD_RR_OUT_NTC_resistance : 50|10@1+ (31.25,1000) [0|31968.75] "Ohm" DSPACE BO_ 48 SB_REAR_sdcStatus: 1 SB_REAR SG_ SDC_POST_BSPD_isClosed : 0|1@1+ (1,0) [0|1] "" DSPACE @@ -169,6 +177,9 @@ BO_ 50 SB_REAR_dischargeStatus: 1 SB_REAR + + + BO_ 5 Sens_Front_1: 8 SB_FRONT SG_ Throttle_0_Voltage_mV : 0|16@1+ (1,0) [0|65535] "" DSPACE SG_ Throttle_1_Voltage_mV : 16|16@1+ (1,0) [0|65535] "" DSPACE @@ -246,13 +257,7 @@ BO_ 512 dSpace_PeripheralsCTRL: 3 DSPACE -BO_ 1025 Sens_Rear_NTC: 8 SB_REAR - SG_ NTC_1_Resistance : 0|10@1+ (31.25,1000) [0|31968.75] "Ohm" DSPACE - SG_ NTC_2_Resistance : 10|10@1+ (31.25,1000) [0|31968.75] "Ohm" DSPACE - SG_ NTC_3_Resistance : 20|10@1+ (31.25,1000) [0|31968.75] "Ohm" DSPACE - SG_ NTC_4_Resistance : 30|10@1+ (31.25,1000) [0|31968.75] "Ohm" DSPACE - SG_ NTC_5_Resistance : 40|10@1+ (31.25,1000) [0|31968.75] "Ohm" DSPACE - SG_ NTC_6_Resistance : 50|10@1+ (31.25,1000) [0|31968.75] "Ohm" DSPACE + BO_ 1026 Sens_Rear_2: 4 SB_REAR SG_ CoolingPressure_DX_Voltage_mV : 0|16@1+ (1,0) [0|65535] "" DSPACE @@ -353,12 +358,19 @@ CM_ SG_ 49 SDC_POST_INERTIA_isClosed "States whether the SDC post inertia switch CM_ SG_ 49 SDC_POST_BOTS_isClosed "States whether the SDC post BOTS is closed."; CM_ SG_ 49 SDC_POST_COCKPIT_isClosed "States whether the SDC post cockpit push button is closed."; -CM_ SG_ 1024 RAD_NTC_IN_resistance "The resistance of the radiator IN NTC expressed in Ohm."; -CM_ SG_ 1024 RAD_NTC_OUT_resistance "The resistance of the radiator OUT NTC expressed in Ohm."; -CM_ SG_ 1024 JACKET_NTC_FRONT_resistance "The resistance of the jacket front NTC expressed in Ohm."; -CM_ SG_ 1024 JACKET_NTC_REAR_resistance "The resistance of the jacket rear NTC expressed in Ohm."; -CM_ SG_ 1024 COLDPLATE_NTC_resistance "The resistance of the coldplate NTC expressed in Ohm."; -CM_ SG_ 1024 NTC_SPARE_resistance "The resistance of the spare NTC expressed in Ohm."; +CM_ SG_ 1024 JACKET_FL_NTC_resistance "The resistance of the front left jacket NTC expressed in Ohm."; +CM_ SG_ 1024 JACKET_FR_NTC_resistance "The resistance of the front right jacket NTC expressed in Ohm."; +CM_ SG_ 1024 COLDPLATE_L_NTC_resistance "The resistance of the left coldplate NTC expressed in Ohm."; +CM_ SG_ 1024 COLDPLATE_R_NTC_resistance "The resistance of the right coldplate NTC expressed in Ohm."; +CM_ SG_ 1024 SPARE_NTC_0_resistance "The resistance of the spare NTC #0 expressed in Ohm."; +CM_ SG_ 1024 SPARE_NTC_1_resistance "The resistance of the spare NTC #1 expressed in Ohm."; + +CM_ SG_ 1024 JACKET_RL_NTC_resistance "The resistance of the rear left jacket NTC expressed in Ohm."; +CM_ SG_ 1024 JACKET_RR_NTC_resistance "The resistance of the rear right jacket NTC expressed in Ohm."; +CM_ SG_ 1024 RAD_RL_IN_NTC_resistance "The resistance of the rear left IN radiator NTC expressed in Ohm."; +CM_ SG_ 1024 RAD_RL_OUT_NTC_resistance "The resistance of the rear left OUT radiator NTC expressed in Ohm."; +CM_ SG_ 1024 RAD_RR_IN_NTC_resistance "The resistance of the rear right IN radiator NTC expressed in Ohm."; +CM_ SG_ 1024 RAD_RR_OUT_NTC_resistance "The resistance of the rear right OUT radiator NTC expressed in Ohm."; CM_ SG_ 48 SDC_POST_BSPD_isClosed "States whether the SDC post BSPD is closed."; CM_ SG_ 48 SDC_PRE_PUSH_BTNS_isClosed "States whether the SDC per push buttons (hoop right/left) is closed."; @@ -375,7 +387,6 @@ CM_ SG_ 50 DISCHARGE_isOpen "States whether the discharge is open."; CM_ BO_ 1026 "(period: 10 ms)"; -CM_ BO_ 1025 "(period: 10 ms)"; CM_ BO_ 5 "(period: 10 ms)"; CM_ BO_ 16 "(period: 10 ms)"; CM_ BO_ 18 "(period: 100 ms)"; @@ -409,4 +420,5 @@ BA_ "GenMsgCycleTime" BO_ 261 2000; BA_ "GenMsgCycleTime" BO_ 38 500; BA_ "GenMsgCycleTime" BO_ 49 10; BA_ "GenMsgCycleTime" BO_ 1024 10; +BA_ "GenMsgCycleTime" BO_ 1025 10; BA_ "GenMsgCycleTime" BO_ 48 10; \ No newline at end of file diff --git a/examples/markdown/SC24.md b/examples/markdown/SC24.md index 2b4bc85..30e41d6 100644 --- a/examples/markdown/SC24.md +++ b/examples/markdown/SC24.md @@ -355,14 +355,14 @@ Cycle Time: **10** ms Receivers: [DSPACE](#DSPACE) -| Name | Start Bit | Size | Min | Max | Offset | Scale | Unit | Description | -|-----------------------------|-----------|------|-----|----------|--------|-------|------|----------------------------------------------------------| -| RAD_NTC_IN_resistance | 0 | 10 | 0 | 31968.75 | 1000 | 31.25 | Ohm | The resistance of the radiator IN NTC expressed in Ohm. | -| RAD_NTC_OUT_resistance | 10 | 10 | 0 | 31968.75 | 1000 | 31.25 | Ohm | The resistance of the radiator OUT NTC expressed in Ohm. | -| JACKET_NTC_FRONT_resistance | 20 | 10 | 0 | 31968.75 | 1000 | 31.25 | Ohm | The resistance of the jacket front NTC expressed in Ohm. | -| JACKET_NTC_REAR_resistance | 30 | 10 | 0 | 31968.75 | 1000 | 31.25 | Ohm | The resistance of the jacket rear NTC expressed in Ohm. | -| COLDPLATE_NTC_resistance | 40 | 10 | 0 | 31968.75 | 1000 | 31.25 | Ohm | The resistance of the coldplate NTC expressed in Ohm. | -| NTC_SPARE_resistance | 50 | 10 | 0 | 31968.75 | 1000 | 31.25 | Ohm | The resistance of the spare NTC expressed in Ohm. | +| Name | Start Bit | Size | Min | Max | Offset | Scale | Unit | Description | +|----------------------------|-----------|------|-----|----------|--------|-------|------|----------------------------------------------------------------| +| JACKET_FL_NTC_resistance | 0 | 10 | 0 | 31968.75 | 1000 | 31.25 | Ohm | The resistance of the front left jacket NTC expressed in Ohm. | +| JACKET_FR_NTC_resistance | 10 | 10 | 0 | 31968.75 | 1000 | 31.25 | Ohm | The resistance of the front right jacket NTC expressed in Ohm. | +| COLDPLATE_L_NTC_resistance | 20 | 10 | 0 | 31968.75 | 1000 | 31.25 | Ohm | The resistance of the left coldplate NTC expressed in Ohm. | +| COLDPLATE_R_NTC_resistance | 30 | 10 | 0 | 31968.75 | 1000 | 31.25 | Ohm | The resistance of the right coldplate NTC expressed in Ohm. | +| SPARE_NTC_0_resistance | 40 | 10 | 0 | 31968.75 | 1000 | 31.25 | Ohm | The resistance of the spare NTC #0 expressed in Ohm. | +| SPARE_NTC_1_resistance | 50 | 10 | 0 | 31968.75 | 1000 | 31.25 | Ohm | The resistance of the spare NTC #1 expressed in Ohm. | --- ### SB_REAR @@ -450,25 +450,23 @@ Receivers: [DSPACE](#DSPACE) | Straingauge_PushRL_Voltage_mV | 32 | 16 | 0 | 65535 | 0 | 1 | - | - | | Straingauge_TieRL_Voltage_mV | 48 | 16 | 0 | 65535 | 0 | 1 | - | - | -#### Sens_Rear_NTC -(period: 10 ms) - +#### SB_REAR_ntcResistance CAN-ID: **1025** Size: **8** bytes -Cycle Time: - +Cycle Time: **10** ms Receivers: [DSPACE](#DSPACE) -| Name | Start Bit | Size | Min | Max | Offset | Scale | Unit | Description | -|------------------|-----------|------|-----|----------|--------|-------|------|-------------| -| NTC_1_Resistance | 0 | 10 | 0 | 31968.75 | 1000 | 31.25 | Ohm | - | -| NTC_2_Resistance | 10 | 10 | 0 | 31968.75 | 1000 | 31.25 | Ohm | - | -| NTC_3_Resistance | 20 | 10 | 0 | 31968.75 | 1000 | 31.25 | Ohm | - | -| NTC_4_Resistance | 30 | 10 | 0 | 31968.75 | 1000 | 31.25 | Ohm | - | -| NTC_5_Resistance | 40 | 10 | 0 | 31968.75 | 1000 | 31.25 | Ohm | - | -| NTC_6_Resistance | 50 | 10 | 0 | 31968.75 | 1000 | 31.25 | Ohm | - | +| Name | Start Bit | Size | Min | Max | Offset | Scale | Unit | Description | +|---------------------------|-----------|------|-----|----------|--------|-------|------|-------------| +| JACKET_RL_NTC_resistance | 0 | 10 | 0 | 31968.75 | 1000 | 31.25 | Ohm | - | +| JACKET_RR_NTC_resistance | 10 | 10 | 0 | 31968.75 | 1000 | 31.25 | Ohm | - | +| RAD_RL_IN_NTC_resistance | 20 | 10 | 0 | 31968.75 | 1000 | 31.25 | Ohm | - | +| RAD_RL_OUT_NTC_resistance | 30 | 10 | 0 | 31968.75 | 1000 | 31.25 | Ohm | - | +| RAD_RR_IN_NTC_resistance | 40 | 10 | 0 | 31968.75 | 1000 | 31.25 | Ohm | - | +| RAD_RR_OUT_NTC_resistance | 50 | 10 | 0 | 31968.75 | 1000 | 31.25 | Ohm | - | #### Sens_Rear_2 (period: 10 ms) diff --git a/signal_unit.go b/signal_unit.go index 40c26ad..debb894 100644 --- a/signal_unit.go +++ b/signal_unit.go @@ -6,19 +6,34 @@ import ( ) // SignalUnitKind defines the kind of a [SignalUnit]. -type SignalUnitKind string +type SignalUnitKind int const ( // SignalUnitKindCustom defines a custom unit. - SignalUnitKindCustom SignalUnitKind = "signal_unit-custom" + SignalUnitKindCustom SignalUnitKind = iota // SignalUnitKindTemperature defines a temperature unit. - SignalUnitKindTemperature SignalUnitKind = "signal_unit-temperature" + SignalUnitKindTemperature // SignalUnitKindElectrical defines an electrical unit. - SignalUnitKindElectrical SignalUnitKind = "signal_unit-electrical" + SignalUnitKindElectrical // SignalUnitKindPower defines a power unit. - SignalUnitKindPower SignalUnitKind = "signal_unit-power" + SignalUnitKindPower ) +func (suk SignalUnitKind) String() string { + switch suk { + case SignalUnitKindCustom: + return "custom" + case SignalUnitKindTemperature: + return "temperature" + case SignalUnitKindElectrical: + return "electrical" + case SignalUnitKindPower: + return "power" + default: + return "unknown" + } +} + // SignalUnit is an entity that defines the physical unit of a [Signal]. type SignalUnit struct { *entity diff --git a/template.go b/template.go new file mode 100644 index 0000000..1307450 --- /dev/null +++ b/template.go @@ -0,0 +1,26 @@ +package acmelib + +type templateRef interface { + EntityID() EntityID +} + +type template[Ent any, Ref templateRef] struct { + entity Ent + refs *set[EntityID, Ref] +} + +func newTemplate[Ent any, Ref templateRef](e Ent) *template[Ent, Ref] { + return &template[Ent, Ref]{ + entity: e, + + refs: newSet[EntityID, Ref](), + } +} + +func (t *template[Ent, Ref]) addRef(ref Ref) { + t.refs.add(ref.EntityID(), ref) +} + +func (t *template[Ent, Ref]) removeRef(refID EntityID) { + t.refs.remove(refID) +}