Skip to content

Commit 18db167

Browse files
committed
Tested and fixed IO data
1 parent 99567b0 commit 18db167

10 files changed

Lines changed: 366 additions & 149 deletions

File tree

dbc/ecumaster.dbc

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ NS_ :
3232
SG_MUL_VAL_
3333

3434
BS_:
35-
BU_: ECUMaster_L2C ECUMaster_EGT ECU
36-
35+
BU_: ECUMaster_L2C ECUMaster_EGT ECUMaster_Switchboard ECU
3736
BO_ 1636 EcuMaster_AfrData1: 8 ECUMaster_L2C
3837
SG_ SystemVolts : 7|16@0+ (0.01,0) [0|655.35] "V" ECU
3938
SG_ HeaterPower : 23|8@0+ (0.392157,0) [0|100] "%" ECU
@@ -92,6 +91,38 @@ BO_ 1632 EcuMaster_Black_EGT: 8 ECUMaster_EGT
9291
SG_ Egt3 : 39|16@0- (1,0) [-32768|32767] "degC" ECU
9392
SG_ Egt4 : 55|16@0- (1,0) [-32768|32767] "degC" ECU
9493

94+
BO_ 1600 EcuMaster_Switchboard_AV1_4: 8 ECUMaster_Switchboard
95+
SG_ AV1 : 0|16@1+ (0.001,0) [0|65.535] "V" ECU
96+
SG_ AV2 : 16|16@1+ (0.001,0) [0|65.535] "V" ECU
97+
SG_ AV3 : 32|16@1+ (0.001,0) [0|65.535] "V" ECU
98+
SG_ AV4 : 48|16@1+ (0.001,0) [0|65.535] "V" ECU
99+
100+
BO_ 1601 EcuMaster_Switchboard_AV5_8: 8 ECUMaster_Switchboard
101+
SG_ AV5 : 0|16@1+ (0.001,0) [0|65.535] "V" ECU
102+
SG_ AV6 : 16|16@1+ (0.001,0) [0|65.535] "V" ECU
103+
SG_ AV7 : 32|16@1+ (0.001,0) [0|65.535] "V" ECU
104+
SG_ AV8 : 48|16@1+ (0.001,0) [0|65.535] "V" ECU
105+
106+
BO_ 1602 EcuMaster_Switchboard_Other: 8 ECUMaster_Switchboard
107+
SG_ Rotary1 : 0|4@1+ (1,0) [0|15] "" ECU
108+
SG_ Rotary2 : 4|4@1+ (1,0) [0|15] "" ECU
109+
SG_ Rotary3 : 8|4@1+ (1,0) [0|15] "" ECU
110+
SG_ Rotary4 : 12|4@1+ (1,0) [0|15] "" ECU
111+
SG_ Rotary5 : 16|4@1+ (1,0) [0|15] "" ECU
112+
SG_ Rotary6 : 20|4@1+ (1,0) [0|15] "" ECU
113+
SG_ Rotary7 : 24|4@1+ (1,0) [0|15] "" ECU
114+
SG_ Rotary8 : 28|4@1+ (1,0) [0|15] "" ECU
115+
SG_ Switch : 32|8@1+ (1,0) [0|255] "" ECU
116+
SG_ AnalogState : 40|8@1+ (1,0) [0|255] "" ECU
117+
SG_ LowSideState : 48|8@1+ (1,0) [0|255] "" ECU
118+
SG_ Heartbeat : 56|8@1+ (1,0) [0|255] "" ECU
119+
120+
BO_ 1603 EcuMaster_Switchboard_LowSide_Rx: 8 ECU
121+
SG_ LowSide1_State : 0|8@1+ (1,0) [0|255] "" ECUMaster_Switchboard
122+
SG_ LowSide2_State : 8|8@1+ (1,0) [0|255] "" ECUMaster_Switchboard
123+
SG_ LowSide3_State : 16|8@1+ (1,0) [0|255] "" ECUMaster_Switchboard
124+
SG_ LowSide4_State : 24|8@1+ (1,0) [0|255] "" ECUMaster_Switchboard
125+
95126
CM_ BO_ 1636 "EcuMaster AFR Data 1. Base ID 0x664 (1636), 1 Mbps, 10 ms period";
96127
CM_ SG_ 1636 HeaterPower "0-100%, scaling: 100/255";
97128
CM_ SG_ 1636 SensorTemp "Sensor temperature in degC, scaling: 4:1";
@@ -112,6 +143,34 @@ CM_ SG_ 1639 OxygenConcentration "Oxygen concentration in %";
112143
CM_ SG_ 1639 Ri "Sensor internal resistance in Ohms";
113144
CM_ BO_ 1552 "EcuMaster Classic EGT. Base ID 0x610 (1552), supports up to 4 EGT channels";
114145
CM_ BO_ 1632 "EcuMaster Black EGT. Base ID 0x660 (1632), supports up to 4 EGT channels";
146+
CM_ BO_ 1600 "EcuMaster Switchboard Analog Voltages 1-4. Base ID 0x640 (1600), 100 ms period";
147+
CM_ SG_ 1600 AV1 "Analog Voltage input 1";
148+
CM_ SG_ 1600 AV2 "Analog Voltage input 2";
149+
CM_ SG_ 1600 AV3 "Analog Voltage input 3";
150+
CM_ SG_ 1600 AV4 "Analog Voltage input 4";
151+
CM_ BO_ 1601 "EcuMaster Switchboard Analog Voltages 5-8. Base ID + 1 = 0x641 (1601)";
152+
CM_ SG_ 1601 AV5 "Analog Voltage input 5";
153+
CM_ SG_ 1601 AV6 "Analog Voltage input 6";
154+
CM_ SG_ 1601 AV7 "Analog Voltage input 7";
155+
CM_ SG_ 1601 AV8 "Analog Voltage input 8";
156+
CM_ BO_ 1602 "EcuMaster Switchboard Other Data. Base ID + 2 = 0x642 (1602)";
157+
CM_ SG_ 1602 Rotary1 "Rotary switch 1 position (0-15)";
158+
CM_ SG_ 1602 Rotary2 "Rotary switch 2 position (0-15)";
159+
CM_ SG_ 1602 Rotary3 "Rotary switch 3 position (0-15)";
160+
CM_ SG_ 1602 Rotary4 "Rotary switch 4 position (0-15)";
161+
CM_ SG_ 1602 Rotary5 "Rotary switch 5 position (0-15)";
162+
CM_ SG_ 1602 Rotary6 "Rotary switch 6 position (0-15)";
163+
CM_ SG_ 1602 Rotary7 "Rotary switch 7 position (0-15)";
164+
CM_ SG_ 1602 Rotary8 "Rotary switch 8 position (0-15)";
165+
CM_ SG_ 1602 Switch "Switch state bitmask: bits 0-7 represent switches 1-8 (0=open, 1=closed)";
166+
CM_ SG_ 1602 AnalogState "Analog input threshold state bitmask (1=above threshold, 0=below threshold)";
167+
CM_ SG_ 1602 LowSideState "Low-side output state bitmask (1=active, 0=inactive)";
168+
CM_ SG_ 1602 Heartbeat "Heartbeat counter, incremented on each message";
169+
CM_ BO_ 1603 "EcuMaster Switchboard Low-Side Control. Base ID + 3 = 0x643 (1603), ECU to Switchboard";
170+
CM_ SG_ 1603 LowSide1_State "Low-side output 1 control (0=inactive, non-zero=active)";
171+
CM_ SG_ 1603 LowSide2_State "Low-side output 2 control (0=inactive, non-zero=active)";
172+
CM_ SG_ 1603 LowSide3_State "Low-side output 3 control (0=inactive, non-zero=active)";
173+
CM_ SG_ 1603 LowSide4_State "Low-side output 4 control (0=inactive, non-zero=active)";
115174
BA_DEF_ "BusType" STRING ;
116175
BA_DEF_ BO_ "GenMsgBackgroundColor" STRING ;
117176
BA_DEF_ BO_ "GenMsgForegroundColor" STRING ;

dbc/iobox.dbc

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
VERSION ""
2+
3+
4+
NS_ :
5+
NS_DESC_
6+
CM_
7+
BA_DEF_
8+
BA_
9+
VAL_
10+
CAT_DEF_
11+
CAT_
12+
FILTER
13+
BA_DEF_DEF_
14+
EV_DATA_
15+
ENVVAR_DATA_
16+
SGTYPE_
17+
SGTYPE_VAL_
18+
BA_DEF_SGTYPE_
19+
BA_SGTYPE_
20+
SIG_TYPE_REF_
21+
VAL_TABLE_
22+
SIG_GROUP_
23+
SIG_VALTYPE_
24+
SIGTYPE_VALTYPE_
25+
BO_TX_BU_
26+
BA_DEF_REL_
27+
BA_REL_
28+
BA_DEF_DEF_REL_
29+
BU_SG_REL_
30+
BU_EV_REL_
31+
BU_BO_REL_
32+
SG_MUL_VAL_
33+
34+
BS_:
35+
BU_: MS_IOBOX ECU
36+
BO_ 512 MS_IOBOX_PING: 0 ECU
37+
38+
BO_ 513 MS_IOBOX_CONFIG: 8 ECU
39+
SG_ pwm_mask : 0|8@1+ (1,0) [0|255] "" MS_IOBOX
40+
SG_ tachin_mask : 16|8@1+ (1,0) [0|255] "" MS_IOBOX
41+
SG_ adc_broadcast_interval : 32|8@1+ (1,0) [0|255] "ms" MS_IOBOX
42+
SG_ tach_broadcast_interval : 40|8@1+ (1,0) [0|255] "ms" MS_IOBOX
43+
44+
BO_ 514 MS_IOBOX_SET_PWM0: 8 ECU
45+
SG_ ch0_on : 7|16@0+ (1,0) [0|65535] "" MS_IOBOX
46+
SG_ ch0_off : 23|16@0+ (1,0) [0|65535] "" MS_IOBOX
47+
SG_ ch1_on : 39|16@0+ (1,0) [0|65535] "" MS_IOBOX
48+
SG_ ch1_off : 55|16@0+ (1,0) [0|65535] "" MS_IOBOX
49+
50+
BO_ 515 MS_IOBOX_SET_PWM1: 8 ECU
51+
SG_ ch2_on : 7|16@0+ (1,0) [0|65535] "" MS_IOBOX
52+
SG_ ch2_off : 23|16@0+ (1,0) [0|65535] "" MS_IOBOX
53+
SG_ ch3_on : 39|16@0+ (1,0) [0|65535] "" MS_IOBOX
54+
SG_ ch3_off : 55|16@0+ (1,0) [0|65535] "" MS_IOBOX
55+
56+
BO_ 516 MS_IOBOX_SET_PWM2: 8 ECU
57+
SG_ ch4_on : 7|16@0+ (1,0) [0|65535] "" MS_IOBOX
58+
SG_ ch4_off : 23|16@0+ (1,0) [0|65535] "" MS_IOBOX
59+
SG_ ch5_on : 39|16@0+ (1,0) [0|65535] "" MS_IOBOX
60+
SG_ ch5_off : 55|16@0+ (1,0) [0|65535] "" MS_IOBOX
61+
62+
BO_ 517 MS_IOBOX_SET_PWM3: 5 ECU
63+
SG_ ch6_on : 7|16@0+ (1,0) [0|65535] "" MS_IOBOX
64+
SG_ ch6_off : 23|16@0+ (1,0) [0|65535] "" MS_IOBOX
65+
SG_ out_state : 32|8@1+ (1,0) [0|255] "" MS_IOBOX
66+
67+
BO_ 520 MS_IOBOX_WHOAMI: 8 MS_IOBOX
68+
SG_ version : 0|8@1+ (1,0) [0|255] "" ECU
69+
SG_ pwm_period : 32|16@0+ (0.01,0) [0|655.35] "us" ECU
70+
SG_ tachin_period : 48|16@0+ (0.01,0) [0|655.35] "us" ECU
71+
72+
BO_ 521 MS_IOBOX_ADC14: 8 MS_IOBOX
73+
SG_ adc1 : 7|16@0+ (0.00488281,0) [0|5] "V" Vector__XXX
74+
SG_ adc2 : 23|16@0+ (0.00488281,0) [0|5] "V" ECU
75+
SG_ adc3 : 39|16@0+ (0.00488281,0) [0|5] "V" ECU
76+
SG_ adc4 : 55|16@0+ (0.00488281,0) [0|5] "V" ECU
77+
78+
BO_ 522 MS_IOBOX_ADC57: 8 MS_IOBOX
79+
SG_ inputs : 0|8@1+ (1,0) [0|255] "" ECU
80+
SG_ adc5 : 23|16@0+ (0.00488281,0) [0|5] "V" ECU
81+
SG_ adc6 : 39|16@0+ (0.00488281,0) [0|5] "V" ECU
82+
SG_ adc7 : 55|16@0+ (0.00488281,0) [0|5] "V" ECU
83+
84+
CM_ BO_ 512 "Ping request with zero payload";
85+
CM_ BO_ 513 "Configuration message for PWM, tach-in masks and broadcast intervals";
86+
CM_ SG_ 513 pwm_mask "PWM mask: 0=On/Off, 1=PWM";
87+
CM_ SG_ 513 tachin_mask "Tach input mask";
88+
CM_ BO_ 514 "PWM settings for channels 0-1 (mapped to analog outputs)";
89+
CM_ BO_ 515 "PWM settings for channels 2-3";
90+
CM_ BO_ 516 "PWM settings for channels 4-5";
91+
CM_ BO_ 517 "PWM settings for channel 6 and output state";
92+
CM_ BO_ 520 "Device identity and timing information response";
93+
CM_ BO_ 521 "ADC readings for inputs 1-4";
94+
CM_ SG_ 521 adc1 "AUX Left input";
95+
CM_ SG_ 521 adc2 "AUX Right input";
96+
CM_ SG_ 521 adc3 "AUX out left voltage";
97+
CM_ SG_ 521 adc4 "AUX out right voltage";
98+
CM_ BO_ 522 "ADC readings for inputs 5-7";
99+
CM_ SG_ 522 adc5 "WBO supply voltage";
100+
CM_ SG_ 522 adc6 "Left sensor heater supply";
101+
CM_ SG_ 522 adc7 "Right sensor heater supply";
102+
BA_DEF_ BO_ "GenMsgBackgroundColor" STRING ;
103+
BA_DEF_ BO_ "GenMsgForegroundColor" STRING ;
104+
BA_DEF_ BO_ "labelfilters" INT 0 0;
105+
BA_DEF_DEF_ "GenMsgBackgroundColor" "#ffffff";
106+
BA_DEF_DEF_ "GenMsgForegroundColor" "#000000";
107+
BA_DEF_DEF_ "labelfilters" 1;

firmware/boards/port.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ class Configuration {
158158
heaterConfig.PreheatTimeSec = HEATER_PREHEAT_TIME;
159159

160160
ioExpanderConfig.Protocol = CanIoProtocol::None;
161+
ioExpanderConfig.TxEnabled = false;
162+
ioExpanderConfig.RxEnabled = false;
161163
ioExpanderConfig.Offset = 0;
162164
ioExpanderConfig.IOInputsEnabled = 0xFFFF; // All inputs enabled by default
163165
ioExpanderConfig.IOOutputsEnabled = 0xFFFF; // All outputs enabled by default
@@ -205,7 +207,9 @@ class Configuration {
205207

206208
struct {
207209
CanIoProtocol Protocol: 5;
208-
uint8_t Reserved0: 3;
210+
uint8_t Reserved0: 1;
211+
uint8_t TxEnabled: 1;
212+
uint8_t RxEnabled: 1;
209213
uint8_t Offset;
210214
uint16_t IOInputsEnabled; // Bitmask of which inputs should be reported in CAN messages
211215
uint16_t IOOutputsEnabled; // Bitmask of which outputs should be controlled via CAN messages

firmware/can.cpp

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -110,26 +110,27 @@ __attribute__((weak)) void SendCanData(uint16_t elapsedMs)
110110

111111
static uint16_t elapsedSinceIoExpanderTxMs = 0;
112112
const ProtocolHandler* ioExpanderHandler = nullptr;
113-
114-
switch (configuration->ioExpanderConfig.Protocol) {
115-
case CanIoProtocol::EcuMaster:
116-
ioExpanderHandler = &ecuMasterSwitchBoardTxHandler;
117-
break;
118-
case CanIoProtocol::Haltech:
119-
ioExpanderHandler = &haltechIoTxHandler;
120-
break;
121-
case CanIoProtocol::Emtron:
122-
ioExpanderHandler = &emtronIoTxHandler;
123-
break;
124-
case CanIoProtocol::MsIoBox:
125-
ioExpanderHandler = &msIoBoxTxHandler;
126-
break;
127-
default:
128-
break;
129-
}
130-
if (ioExpanderHandler) {
131-
DispatchProtocolHandler(*ioExpanderHandler, elapsedMs, elapsedSinceIoExpanderTxMs, configuration);
132-
}
113+
if (configuration->ioExpanderConfig.TxEnabled) {
114+
switch (configuration->ioExpanderConfig.Protocol) {
115+
case CanIoProtocol::EcuMaster:
116+
ioExpanderHandler = &ecuMasterSwitchBoardTxHandler;
117+
break;
118+
case CanIoProtocol::Haltech:
119+
ioExpanderHandler = &haltechIoTxHandler;
120+
break;
121+
case CanIoProtocol::Emtron:
122+
ioExpanderHandler = &emtronIoTxHandler;
123+
break;
124+
case CanIoProtocol::MsIoBox:
125+
ioExpanderHandler = &msIoBoxTxHandler;
126+
break;
127+
default:
128+
break;
129+
}
130+
if (ioExpanderHandler) {
131+
DispatchProtocolHandler(*ioExpanderHandler, elapsedMs, elapsedSinceIoExpanderTxMs, configuration);
132+
}
133+
}
133134

134135
#endif
135136

@@ -149,16 +150,28 @@ __attribute__((weak)) void ProcessCanMessage(const CANRxFrame* frame)
149150
//ProcessLinkCanMessage(frame, configuration, &canStatusData);
150151

151152
#if IO_EXPANDER_ENABLED > 0
152-
switch (configuration->ioExpanderConfig.Protocol) {
153-
case CanIoProtocol::Haltech:
154-
ProcessHaltechIO12Message(frame, configuration);
155-
return;
156-
case CanIoProtocol::MsIoBox:
157-
ProcessMsIoBoxCanMessage(frame, configuration);
158-
return;
159-
default:
160-
break;
153+
if (configuration->ioExpanderConfig.RxEnabled) {
154+
switch (configuration->ioExpanderConfig.Protocol) {
155+
case CanIoProtocol::Haltech:
156+
ProcessHaltechIO12Message(frame, configuration);
157+
break;
158+
case CanIoProtocol::EcuMaster:
159+
HandleEcuMasterCanMessage(frame, configuration);
160+
break;
161+
case CanIoProtocol::Motec:
162+
// TODO: Implement Motec E888 RX message processing
163+
break;
164+
default:
165+
break;
166+
}
161167
}
168+
169+
// IOBox needs to config packages to know if it should send data
170+
// We handle disabling output control in the handler instead of here
171+
if (configuration->ioExpanderConfig.Protocol == CanIoProtocol::MsIoBox) {
172+
ProcessMsIoBoxCanMessage(frame, configuration);
173+
}
174+
162175
#endif
163176
}
164177

firmware/can/can_ecumaster.cpp

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -218,21 +218,14 @@ void SendEcuMasterSwitchBoardFormat(Configuration* configuration)
218218
CanTxTyped<ecumaster::AVData> frame(id, true);
219219
for (uint8_t i = 0; i < channels; i++)
220220
{
221-
if (configuration->ioExpanderConfig.IOInputsEnabled & (1 << i))
222-
{
223-
float voltage = GetAuxInputVoltage(i);
221+
float voltage = GetAuxInputVoltage(i);
224222

225-
// Some hysteresis
226-
if (voltage > 3.0f) analogStatus |= (1 << i);
227-
if (voltage < 2.0f) analogStatus &= ~(1 << i);
223+
// Some hysteresis
224+
if (voltage > 3.0f) analogStatus |= (1 << i);
225+
if (voltage < 2.0f) analogStatus &= ~(1 << i);
228226

229-
uint16_t raw = (uint16_t)(voltage * 1000);
230-
frame->Value[i] = raw;
231-
}
232-
else
233-
{
234-
frame->Value[i] = 0; // Input disabled, report as 0V
235-
}
227+
uint16_t raw = (uint16_t)(voltage * 1000);
228+
frame->Value[i] = raw;
236229
}
237230

238231
CanTxTyped<ecumaster::OtherData> otherFrame(id + 2, true);
@@ -244,31 +237,25 @@ void SendEcuMasterSwitchBoardFormat(Configuration* configuration)
244237

245238
void HandleEcuMasterCanMessage(const CANRxFrame* msg, Configuration* configuration)
246239
{
247-
auto msg_id = CAN_ID(*msg);
248-
249-
auto device_id = ECUMASTER_SWITCHBOARD_DEVICE_ID(configuration->ioExpanderConfig.Offset);
240+
uint32_t msg_id = CAN_ID(*msg);
241+
uint32_t device_id = ECUMASTER_SWITCHBOARD_DEVICE_ID(configuration->ioExpanderConfig.Offset);
250242

251-
if (msg_id != device_id + ECUMASTER_SWITCHBOARD_RX_OFFSET) {
243+
if (msg_id != (device_id + ECUMASTER_SWITCHBOARD_RX_OFFSET)) {
252244
return; // Not a low-side control message
253245
}
254246

255247
auto lowSideData = reinterpret_cast<const ecumaster::LowSideRxData*>(msg->data8);
256-
for (uint8_t i = 0; i < 4; i++)
248+
for (uint8_t i = 0; i < PWM_OUTPUT_CHANNELS; i++)
257249
{
258-
if (configuration->ioExpanderConfig.IOOutputsEnabled & (1 << i))
250+
if (lowSideData->State[i])
259251
{
260-
if (lowSideData->State[i])
261-
{
262-
lowSideStatus |= (1 << i);
263-
SetAuxPwmDuty(i, 1.0); // Set PWM duty to 100% for active low-side output
264-
}
265-
else
266-
{
267-
lowSideStatus &= ~(1 << i);
268-
SetAuxPwmDuty(i, 0.0); // Set PWM duty to 0% for inactive low-side output
269-
}
270-
271-
252+
lowSideStatus |= (1 << i);
253+
SetAuxPwmDuty(i, 1.0); // Set PWM duty to 100% for active low-side output
254+
}
255+
else
256+
{
257+
lowSideStatus &= ~(1 << i);
258+
SetAuxPwmDuty(i, 0.0); // Set PWM duty to 0% for inactive low-side output
272259
}
273260
}
274261
}

firmware/can/can_emtron.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -264,16 +264,9 @@ void SendEmtronIoFormat(Configuration* configuration)
264264

265265
for (uint8_t i = 0; i < channels; i++)
266266
{
267-
if (configuration->ioExpanderConfig.IOInputsEnabled & (1 << i))
268-
{
269-
float voltage = GetAuxInputVoltage(i);
270-
uint16_t raw = (uint16_t)(voltage * 1000);
271-
frame->Value[i] = raw;
272-
}
273-
else
274-
{
275-
frame->Value[i] = 0; // Input disabled, report as 0V
276-
}
267+
float voltage = GetAuxInputVoltage(i);
268+
uint16_t raw = (uint16_t)(voltage * 1000);
269+
frame->Value[i] = raw;
277270
}
278271
}
279272

0 commit comments

Comments
 (0)