44
55#include " status.h"
66#include " can_helper.h"
7- #include " can_aemnet.h"
7+ #include " can/can_rusefi.h"
8+ #include " can/can_aemnet.h"
89#include " heater_control.h"
910#include " lambda_conversion.h"
1011#include " sampling.h"
@@ -22,7 +23,7 @@ static Configuration* configuration;
2223static THD_WORKING_AREA (waCanTxThread, 512 );
2324void CanTxThread (void *)
2425{
25- int cycle;
26+ int cycle = 0 ;
2627 chRegSetThreadName (" CAN Tx" );
2728
2829 // Current system time.
@@ -183,52 +184,11 @@ void InitCan()
183184 chThdCreateStatic (waCanRxThread, sizeof (waCanRxThread), NORMALPRIO - 4 , CanRxThread, nullptr );
184185}
185186
186- void SendRusefiFormat (uint8_t ch)
187- {
188- auto baseAddress = WB_DATA_BASE_ADDR + 2 * configuration->afr [ch].RusEfiIdx ;
189-
190- const auto & sampler = GetSampler (ch);
191- const auto & heater = GetHeaterController (ch);
192-
193- auto nernstDc = sampler.GetNernstDc ();
194- auto pumpDuty = GetPumpOutputDuty (ch);
195- auto lambda = GetLambda (ch);
196-
197- // Lambda is valid if:
198- // 1. Nernst voltage is near target
199- // 2. Lambda is >0.6 (sensor isn't specified below that)
200- bool lambdaValid =
201- nernstDc > (NERNST_TARGET - 0 .1f ) && nernstDc < (NERNST_TARGET + 0 .1f ) &&
202- lambda > 0 .6f ;
203-
204- if (configuration->afr [ch].RusEfiTx ) {
205- CanTxTyped<wbo::StandardData> frame (baseAddress + 0 );
206-
207- // The same header is imported by the ECU and checked against this data in the frame
208- frame.get ().Version = RUSEFI_WIDEBAND_VERSION ;
209-
210- uint16_t lambdaInt = lambdaValid ? (lambda * 10000 ) : 0 ;
211- frame.get ().Lambda = lambdaInt;
212- frame.get ().TemperatureC = sampler.GetSensorTemperature ();
213- bool heaterClosedLoop = heater.IsRunningClosedLoop ();
214- frame.get ().Valid = (heaterClosedLoop && lambdaValid) ? 0x01 : 0x00 ;
215- }
216-
217- if (configuration->afr [ch].RusEfiTxDiag ) {
218- CanTxTyped<wbo::DiagData> frame (baseAddress + 1 );;
219-
220- frame.get ().Esr = sampler.GetSensorInternalResistance ();
221- frame.get ().NernstDc = nernstDc * 1000 ;
222- frame.get ().PumpDuty = pumpDuty * 255 ;
223- frame.get ().status = GetCurrentStatus (ch);
224- frame.get ().HeaterDuty = GetHeaterDuty (ch) * 255 ;
225- }
226- }
227187
228188// Weak link so boards can override it
229189__attribute__ ((weak)) void SendCanForChannel(uint8_t ch)
230190{
231- SendRusefiFormat (ch);
191+ SendRusefiFormat (configuration, ch);
232192 SendAemNetUEGOFormat (configuration, ch);
233193}
234194
0 commit comments