From f910e75da010fc94e601594782e70f28a1942f59 Mon Sep 17 00:00:00 2001 From: Asbelos Date: Sun, 27 Oct 2024 12:28:59 +0000 Subject: [PATCH] memory saving --- DCCEXParser.cpp | 8 +++++--- DCCWaveform.cpp | 5 +++++ Release_Notes/Railcom.md | 8 ++++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index dbd69fd..464fb9d 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -480,7 +480,8 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream) break; DCC::writeCVByteMain(p[0], p[1], p[2]); return; - + +#ifdef HAS_ENOUGH_MEMORY case 'r': // READ CV on MAIN Requires Railcom if (params != 2) break; @@ -488,6 +489,7 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream) if (!stashCallback(stream, p, ringStream)) break; DCC::readCVByteMain(p[0], p[1],callback_r); return; +#endif case 'b': // WRITE CV BIT ON MAIN if (params != 4) @@ -1129,7 +1131,7 @@ bool DCCEXParser::parseC(Print *stream, int16_t params, int16_t p[]) { DCC::setGlobalSpeedsteps(128); DIAG(F("128 Speedsteps")); return true; -#if defined(HAS_ENOUGH_MEMORY) && !defined(ARDUINO_ARCH_UNO) && !defined(ARDUINO_ARCH_ESP32) +#if defined(HAS_ENOUGH_MEMORY) case "RAILCOM"_hk: { // if (params<2) return false; @@ -1213,11 +1215,11 @@ bool DCCEXParser::parseD(Print *stream, int16_t params, int16_t p[]) Diag::CMD = onOff; return true; +#ifdef HAS_ENOUGH_MEMORY case "RAILCOM"_hk: // Diag::RAILCOM = onOff; return true; -#ifdef HAS_ENOUGH_MEMORY case "WIFI"_hk: // Diag::WIFI = onOff; return true; diff --git a/DCCWaveform.cpp b/DCCWaveform.cpp index 18d49b9..6744f4d 100644 --- a/DCCWaveform.cpp +++ b/DCCWaveform.cpp @@ -74,12 +74,14 @@ void DCCWaveform::loop() { void DCCWaveform::interruptHandler() { // call the timer edge sensitive actions for progtrack and maintrack // member functions would be cleaner but have more overhead + #if defined(HAS_ENOUGH_MEMORY) if (cutoutNextTime) { cutoutNextTime=false; railcomSampleWindow=false; // about to cutout, stop reading railcom data. railcomCutoutCounter++; DCCTimer::startRailcomTimer(9); } + #endif byte sigMain=signalTransform[mainTrack.state]; byte sigProg=TrackManager::progTrackSyncMain? sigMain : signalTransform[progTrack.state]; @@ -160,6 +162,8 @@ void DCCWaveform::interrupt2() { reminderWindowOpen=transmitRepeats==0 && remainingPreambles<10 && remainingPreambles>1; if (remainingPreambles==1) promotePendingPacket(); + +#if defined(HAS_ENOUGH_MEMORY) else if (isMainTrack && railcomActive) { if (remainingPreambles==(requiredPreambles-1)) { // First look if we need to start a railcom cutout on next interrupt @@ -179,6 +183,7 @@ void DCCWaveform::interrupt2() { DCCTimer::ackRailcomTimer(); } } +#endif // Update free memory diagnostic as we don't have anything else to do this time. // Allow for checkAck and its called functions using 22 bytes more. else DCCTimer::updateMinimumFreeMemoryISR(22); diff --git a/Release_Notes/Railcom.md b/Release_Notes/Railcom.md index 7ffd1fe..dd34036 100644 --- a/Release_Notes/Railcom.md +++ b/Release_Notes/Railcom.md @@ -14,11 +14,15 @@ Some CPUs require very specific choice of brake pins etc to match their internal - Nucleo ... TBA Enabling the Railcom Cutout requires a `` command. This can be added to myAutomation using `PARSE("")` +Code to calculate the cutout position and provide synchronization for the sampling is in `DCCWaveform.cpp` (not ESP32) +and in general a global search for "railcom" will show all code changes that have been made to support this. + +Code to actually implement the timing of the cutout is hihjly cpu dependent and can be found in gthe various implementations of `DCCTimer.h`. At this time only `DCCTimerAVR.cpp`has implemented this. Reading Railcom data: - A new HAL handler has been added to process input from a 2-block railcom reader (Refer Henk) which operates as a 2 channel UART accessible over I2C. The reader(s) sit between the CS and the track and collect railcom data from locos during the cutout. - After the cutout the HAL driver reads the UARTs over I2C and passes the raw data to the CS logic for analysis. + A new HAL handler (`IO_I2CRailcom.h`)has been added to process input from a 2-block railcom reader (Refer Henk) which operates as a 2 channel UART accessible over I2C. The reader(s) sit between the CS and the track and collect railcom data from locos during the cutout. + After the cutout the HAL driver reads the UARTs over I2C and passes the raw data to the CS logic (`Railcom.cpp`)for analysis. Each 2-block reader is described in myAutomation like `HAL(I2CRailcom,10000,2,0x48)` which will assign 2 channels on i2c address 0x48 with vpin numbers 10000 and 10001. If you only use the first channel in the reader, just asign one pin instead of two. (Implementation notes.. potentially other readers are possible with suitable HAL drivers. There are however several touch-points with the code DCC Waveform code which helps the HAL driver to understand when the data is safe to sample, and how to interpret responses when the sender is unknown. )