Skip to content

Commit 69ecbcd

Browse files
committed
Added individual channel enable for EGT channels, and added 0305 AEMNet protocol back in
1 parent cea7a59 commit 69ecbcd

18 files changed

Lines changed: 194 additions & 127 deletions

firmware/boards/port.h

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,26 @@ enum class AuxOutputMode : uint8_t {
5959
Egt1 = 5,
6060
};
6161

62-
enum class CanProtocol : uint8_t {
62+
enum class CanAfrProtocol : uint8_t {
6363
None = 0,
6464
AemNet = 1,
6565
LinkEcu = 2,
6666
Haltech = 3,
67+
EcuMaster = 4,
68+
Motec = 6,
69+
Emtron = 7,
70+
};
71+
72+
enum class CanEgtProtocol : uint8_t {
73+
None = 0,
74+
AemNet0305 = 1,
75+
LinkEcu = 2,
76+
Haltech = 3,
6777
EcuMasterClassic = 4,
6878
EcuMasterBlack = 5,
6979
Motec = 6,
7080
Emtron = 7,
81+
AemNet2224 = 8,
7182
};
7283

7384
class Configuration {
@@ -110,7 +121,7 @@ class Configuration {
110121
afr[i].RusEfiIdx = i;
111122

112123
// No extra protocol by default
113-
afr[i].ExtraCanProtocol = CanProtocol::None;
124+
afr[i].ExtraCanProtocol = CanAfrProtocol::None;
114125
afr[i].ExtraCanIdOffset = i;
115126
}
116127

@@ -121,7 +132,8 @@ class Configuration {
121132
egt[i].RusEfiIdx = i;
122133

123134
// AemNet protocol by default
124-
egt[i].ExtraCanProtocol = CanProtocol::AemNet;
135+
egt[i].ExtraCanProtocol = CanEgtProtocol::AemNet0305;
136+
egt[i].ExtraCanChannelEnabled = true;
125137
egt[i].ExtraCanIdOffset = i;
126138
}
127139

@@ -149,8 +161,7 @@ class Configuration {
149161
struct {
150162
bool RusEfiTx:1;
151163
bool RusEfiTxDiag:1;
152-
CanProtocol ExtraCanProtocol:4;
153-
164+
CanAfrProtocol ExtraCanProtocol:4;
154165

155166
uint8_t RusEfiIdx;
156167
uint8_t ExtraCanIdOffset;
@@ -161,8 +172,9 @@ class Configuration {
161172
struct {
162173
bool RusEfiTx:1;
163174
bool RusEfiTxDiag:1;
164-
CanProtocol ExtraCanProtocol:4;
165-
175+
CanEgtProtocol ExtraCanProtocol:4;
176+
uint8_t Reserved0:3; // Keep some room for future protocol expansion without breaking the config format
177+
bool ExtraCanChannelEnabled:1; // Is the channel actually enabled in the selected protocol
166178

167179
uint8_t RusEfiIdx;
168180
uint8_t ExtraCanIdOffset;

firmware/can.cpp

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ void CanTxThread(void*)
3939

4040
// EGT - 20 Hz
4141
if ((cycle % 5) == 0) {
42-
for (int ch = 0; ch < EGT_CHANNELS; ch++) {
43-
SendCanEgtForChannel(ch);
44-
}
42+
SendCanEgt();
4543
}
4644

4745
cycle++;
@@ -102,56 +100,59 @@ __attribute__((weak)) void SendCanForChannel(uint8_t ch)
102100

103101
switch (configuration->afr[ch].ExtraCanProtocol)
104102
{
105-
case CanProtocol::AemNet:
103+
case CanAfrProtocol::AemNet:
106104
SendAemNetUEGOFormat(configuration, ch);
107105
break;
108-
case CanProtocol::EcuMasterClassic:
109-
case CanProtocol::EcuMasterBlack:
106+
case CanAfrProtocol::EcuMaster:
110107
SendEcuMasterAfrFormat(configuration, ch);
111108
break;
112-
case CanProtocol::Haltech:
109+
case CanAfrProtocol::Haltech:
113110
SendHaltechAfrFormat(configuration, ch);
114111
break;
115-
case CanProtocol::LinkEcu:
112+
case CanAfrProtocol::LinkEcu:
116113
SendLinkAfrFormat(configuration, ch);
117114
break;
118-
case CanProtocol::Emtron:
115+
case CanAfrProtocol::Emtron:
119116
SendEmtronAfrFormat(configuration, ch);
120117
break;
121-
case CanProtocol::Motec:
118+
case CanAfrProtocol::Motec:
122119
SendMotecAfrFormat(configuration, ch);
123120
break;
124121
default:
125122
break;
126123
}
127124
}
128125

129-
__attribute__((weak)) void SendCanEgtForChannel(uint8_t ch)
126+
__attribute__((weak)) void SendCanEgt()
130127
{
131128
#if (EGT_CHANNELS > 0)
132129

133-
SendRusefiEgtFormat(configuration, ch);
130+
SendRusefiEgtFormat(configuration);
134131

135-
switch (configuration->egt[ch].ExtraCanProtocol)
132+
// Look at channel 0 EGT protocol
133+
switch (configuration->egt[0].ExtraCanProtocol)
136134
{
137-
case CanProtocol::AemNet:
138-
SendAemNetEGTFormat(configuration, ch);
135+
case CanEgtProtocol::AemNet0305:
136+
SendAemNetEGT0305Format(configuration);
139137
break;
140-
case CanProtocol::EcuMasterClassic:
141-
case CanProtocol::EcuMasterBlack:
142-
SendEcuMasterEgtFormat(configuration, ch);
138+
case CanEgtProtocol::AemNet2224:
139+
SendAemNetEGT2224Format(configuration);
143140
break;
144-
case CanProtocol::Haltech:
145-
SendHaltechEgtFormat(configuration, ch);
141+
case CanEgtProtocol::EcuMasterClassic:
142+
case CanEgtProtocol::EcuMasterBlack:
143+
SendEcuMasterEgtFormat(configuration);
146144
break;
147-
case CanProtocol::LinkEcu:
148-
SendLinkEgtFormat(configuration, ch);
145+
case CanEgtProtocol::Haltech:
146+
SendHaltechEgtFormat(configuration);
149147
break;
150-
case CanProtocol::Emtron:
151-
SendEmtronEgtFormat(configuration, ch);
148+
case CanEgtProtocol::LinkEcu:
149+
SendLinkEgtFormat(configuration);
152150
break;
153-
case CanProtocol::Motec:
154-
SendMotec888Format(configuration, ch);
151+
case CanEgtProtocol::Emtron:
152+
SendEmtronEgtFormat(configuration);
153+
break;
154+
case CanEgtProtocol::Motec:
155+
SendMotec888Format(configuration);
155156
break;
156157
default:
157158
break;

firmware/can.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ float GetRemoteBatteryVoltage();
2121
// implement this for your board if you want some non-standard behavior
2222
// default implementation simply calls SendRusefiFormat
2323
void SendCanForChannel(uint8_t ch);
24-
void SendCanEgtForChannel(uint8_t ch);
24+
void SendCanEgt();
2525

2626
// Helpers to support both bxCAN and CANFD peripherals
2727
#ifdef STM32G4XX

firmware/can/can_aemnet.cpp

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,62 +70,84 @@ namespace aemnet
7070

7171
#define AEMNET_EGT_TX_PERIOD 50
7272

73-
// That's for AEM EGT Gauge 1800F (30-0305)
74-
// It does not support multiple EGT channels, as 0x000A0306 is a ID of AEM Boost Gauge 50psia (30-0306)
75-
//#define AEMNET_EGT_BASE_ID 0x000A0305
73+
// AEM EGT Gauge 1800F (30-0305)
74+
#define AEMNET_EGT_0305_BASE_ID 0x000A0305
7675

77-
// This one is for 8-Channel K-Type CAN Module (30-2224), which supports up to 8 EGT channels
76+
struct Egt0305Data
77+
{
78+
// 1 degC/bit, 0 to 65535 degC
79+
beuint16_t TemperatureC;
80+
uint8_t Reserved[6];
81+
} __attribute__((packed));
82+
83+
static_assert(sizeof(Egt0305Data) == 8);
84+
85+
// 8-Channel K-Type CAN Module (30-2224), which supports up to 8 EGT channels
7886
// https://documents.aemelectronics.com/techlibrary_30-2224-_8-channel-k-type-can-module-instructions.pdf
7987
// 0xBA00 and 0xBB00 if using 29 bit IDs
8088
// 0x5A0 and 0x5B0 if using 11 bit IDs
81-
#define AEMNET_EGT1_BASE_ID 0x0000BA00
82-
#define AEMNET_EGT2_BASE_ID 0x0000BB00
89+
#define AEMNET_EGT_2224_1_BASE_ID 0x0000BA00
90+
#define AEMNET_EGT_2224_2_BASE_ID 0x0000BB00
8391

8492
// 29 bit ID, 500kbs, rate 20 hz, endian big, DLC 8
8593
// UNIT1 ID: 0x0000BA00 .. 0x0000BA01
8694
// UNIT2 ID: 0x0000BB00 .. 0x0000BB01
87-
struct EgtData
95+
struct Egt2224Data
8896
{
8997
beint16_t Egt[4]; // 0.1 C/bit, -3276.8 to 3276.7 C
9098
} __attribute__((packed));
9199

92-
static_assert(sizeof(EgtData) == 8);
100+
static_assert(sizeof(Egt2224Data) == 8);
93101

94102
// UNIT1 ID: 0x0000BA02
95103
// UNIT2 ID: 0x0000BB02
96-
struct EgtStatus
104+
struct Egt2224Status
97105
{
98106
beuint16_t ColdJunctionTemp; // 0.1 C/bit, -3276.8 to 3276.7 C
99107
uint8_t BatteryVoltage; // 0 - 25.5 V
100108
uint8_t Reserved[5];
101109
} __attribute__((packed));
102110

103-
static_assert(sizeof(EgtStatus) == 8);
111+
static_assert(sizeof(Egt2224Status) == 8);
104112

105113
} //namespace aemnet
106114

107-
void SendAemNetEGTFormat(Configuration* cfg, uint8_t ch)
115+
116+
void SendAemNetEGT0305Format(Configuration* cfg)
108117
{
109-
if (ch != 0)
110-
return; // Use a first channel for config, as AEMNet sends up to 4 EGT channels in one message
118+
for (uint8_t ch = 0; ch < EGT_CHANNELS; ch++)
119+
{
120+
if (!cfg->egt[ch].ExtraCanChannelEnabled)
121+
return;
111122

123+
auto id = AEMNET_EGT_0305_BASE_ID + cfg->egt[ch].ExtraCanIdOffset;
124+
CanTxTyped<aemnet::Egt0305Data> frame(id, true);
125+
frame.get().TemperatureC = getEgtDrivers()[ch].temperature;
126+
}
127+
}
128+
129+
void SendAemNetEGT2224Format(Configuration* cfg)
130+
{
112131
uint32_t id;
113-
switch (cfg->egt[ch].ExtraCanIdOffset)
132+
switch (cfg->egt[0].ExtraCanIdOffset)
114133
{
115134
case 0:
116-
id = AEMNET_EGT1_BASE_ID;
135+
id = AEMNET_EGT_2224_1_BASE_ID;
117136
break;
118137
case 1:
119-
id = AEMNET_EGT2_BASE_ID;
138+
id = AEMNET_EGT_2224_2_BASE_ID;
120139
break;
121140

122141
default:
123142
return; // Invalid channel for AEMNet EGT
124143
}
125144

126-
CanTxTyped<aemnet::EgtData> frame(id, true);
145+
CanTxTyped<aemnet::Egt2224Data> frame(id, true);
127146
for (uint8_t i = 0; i < EGT_CHANNELS; i++)
128147
{
148+
if (!cfg->egt[i].ExtraCanChannelEnabled)
149+
continue;
150+
129151
frame.get().Egt[i] = getEgtDrivers()[i].temperature * 10;
130152
}
131153
}

firmware/can/can_aemnet.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@
66
#include "port.h"
77

88
void SendAemNetUEGOFormat(Configuration* cfg, uint8_t ch);
9-
void SendAemNetEGTFormat(Configuration* cfg, uint8_t ch);
9+
10+
void SendAemNetEGT0305Format(Configuration* cfg);
11+
void SendAemNetEGT2224Format(Configuration* cfg);

firmware/can/can_ecumaster.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,21 +127,21 @@ static_assert(sizeof(EgtData) == 8);
127127
} //namespace ecumaster
128128

129129

130-
void SendEcuMasterEgtFormat(Configuration* configuration, uint8_t ch)
130+
void SendEcuMasterEgtFormat(Configuration* configuration)
131131
{
132-
if (ch != 0)
133-
return; // EcuMaster protocol sends 1-4 channels in one message
134-
135132
auto base = ECUMASTER_CLASSIC_EGT_BASE_ID;
136-
if (configuration->egt[ch].ExtraCanProtocol == CanProtocol::EcuMasterBlack)
133+
if (configuration->egt[0].ExtraCanProtocol == CanEgtProtocol::EcuMasterBlack)
137134
base = ECUMASTER_BLACK_EGT_BASE_ID;
138135

139-
auto id = base + configuration->egt[ch].ExtraCanIdOffset;
136+
auto id = base + configuration->egt[0].ExtraCanIdOffset;
140137

141138
CanTxTyped<ecumaster::EgtData> frame(id, true);
142139

143140
for (uint8_t i = 0; i < EGT_CHANNELS; i++)
144141
{
142+
if (!configuration->egt[i].ExtraCanChannelEnabled)
143+
continue;
144+
145145
frame.get().Egt[i] = getEgtDrivers()[i].temperature;
146146
}
147147
}

firmware/can/can_ecumaster.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77

88
void SendEcuMasterAfrFormat(Configuration* configuration, uint8_t ch);
99

10-
void SendEcuMasterEgtFormat(Configuration* configuration, uint8_t ch);
10+
void SendEcuMasterEgtFormat(Configuration* configuration);

firmware/can/can_emtron.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,36 +175,47 @@ uint16_t get_temperature(float raw_temp)
175175

176176
} //namespace emtron
177177

178-
void SendEmtronEgtFormat(Configuration* configuration, uint8_t ch)
178+
void SendEmtronEgtFormat(Configuration* configuration)
179179
{
180-
if (ch != 0)
181-
return;
182-
183-
auto id = EMTRON_ETC4_BASE_ID + configuration->egt[ch].ExtraCanIdOffset;
180+
auto id = EMTRON_ETC4_BASE_ID + configuration->egt[0].ExtraCanIdOffset;
184181
CanTxTyped<emtron::ETC4Data> frame(id, true);
185182

186183
const auto egtDrivers = getEgtDrivers();
187-
uint16_t temp = emtron::get_temperature(egtDrivers[0].temperature);
184+
185+
uint16_t temp;
188186

189-
frame->EgtData[0] = (temp >> 4) & 0xFF; // High 8 bits
190-
frame->EgtData[1] = (temp & 0xF) << 4; // Low 4 bits in high nibble
187+
if (configuration->egt[0].ExtraCanChannelEnabled)
188+
{
189+
uint16_t temp = emtron::get_temperature(egtDrivers[0].temperature);
190+
frame->EgtData[0] = (temp >> 4) & 0xFF; // High 8 bits
191+
frame->EgtData[1] = (temp & 0xF) << 4; // Low 4 bits in high nibble
192+
}
191193

192194
#if (EGT_CHANNELS > 1)
195+
if (configuration->egt[1].ExtraCanChannelEnabled)
196+
{
193197
temp = emtron::get_temperature(egtDrivers[1].temperature);
194198
frame->EgtData[1] |= (temp >> 8) & 0xF; // High 4 bits in low nibble
195199
frame->EgtData[2] = temp & 0xFF; // Low 8 bits
200+
}
196201
#endif
197202

198203
#if (EGT_CHANNELS > 2)
204+
if (configuration->egt[2].ExtraCanChannelEnabled)
205+
{
199206
temp = emtron::get_temperature(egtDrivers[2].temperature);
200207
frame->EgtData[3] |= (temp >> 8) & 0xF; // High 4 bits in low nibble
201208
frame->EgtData[4] = temp & 0xFF; // Low 8 bits
209+
}
202210
#endif
203211

204212
#if (EGT_CHANNELS > 3)
213+
if (configuration->egt[3].ExtraCanChannelEnabled)
214+
{
205215
temp = emtron::get_temperature(egtDrivers[3].temperature);
206216
frame->EgtData[4] |= (temp >> 8) & 0xF; // High 4 bits in low nibble
207217
frame->EgtData[5] = temp & 0xFF; // Low 8 bits
218+
}
208219
#endif
209220

210221
frame->ColdJunctionTemp = egtDrivers[0].coldJunctionTemperature;

firmware/can/can_emtron.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
#include "port.h"
77

88
void SendEmtronAfrFormat(Configuration* configuration, uint8_t ch);
9-
void SendEmtronEgtFormat(Configuration* configuration, uint8_t ch);
9+
void SendEmtronEgtFormat(Configuration* configuration);

0 commit comments

Comments
 (0)