speeduino/speeduino/logger.h

297 lines
14 KiB
C
Raw Normal View History

/** \file logger.h
* @brief File for generating log files and meta data
* @author Josh Stewart
*
* This file contains functions for creating a log file for use with by TunerStudio directly or to be written to an SD card
*
*/
#ifndef LOGGER_H
#define LOGGER_H
#include <assert.h>
2020-11-19 02:38:00 -08:00
#ifndef UNIT_TEST // Scope guard for unit testing
#define LOG_ENTRY_SIZE 125 /**< The size of the live data packet. This MUST match ochBlockSize setting in the ini file */
#define SD_LOG_ENTRY_SIZE 125 /**< The size of the live data packet used by the SD card.*/
2020-11-19 02:38:00 -08:00
#else
#define LOG_ENTRY_SIZE 1 /**< The size of the live data packet. This MUST match ochBlockSize setting in the ini file */
2021-12-09 19:26:13 -08:00
#define SD_LOG_ENTRY_SIZE 1 /**< The size of the live data packet used by the SD card.*/
2020-11-19 02:38:00 -08:00
#endif
Air Conditioning Control - Feature Implementation (#665) * 19.09.2021 * Final testing of AC Control, some idle features fixed AC control feature added, better than the existing idle-up feature (which can still be used for other things, e.g. electrical load detection). Air conditioning is locked out with coolant temp, RPM high/low, and high TPS. So the A/C automatically cuts out when driving hard. Idle step now works correctly with closed loop PWM, open loop PWM, and closed+open loop PWM. Untested with stepper motor, but no reason it shouldn't work. * Fixed mistakenly incremented page sizes * Initial changes as per HWright9 -Renamed engineRunSeconds to acAfterEngineStartDelay -Formatted large if statements better -Fixed acStartDelay overflow bug -Improved readability of logic * Final fixes as per HWright9's feedback -Add high/low RPM lockout delay, similar to the high TPM lockout delay -General tidy-up * Added stand-alone fan, moved config data in EEPROM -Added additional configurable stand-alone A/C fan output, for when there is dedicated cooling fan for the A/C compressor. This is independent of the engine cooling fan logic. -Moved config storage in EEPROM to configPage9, as noisymime's SD card logging has used the (previously unused) bytes I had used in configPage13. -Minor bug fix - rename Aux in 1-16 to Aux in 0-15 * Revert to current master branch - as of master commit 97f8ef795a514c9a5693e85be6cdb8bdee8ef2c5 * A/C Control Re-Integrated from AC-Control-Clean-3 (@Corey-Harding). Tested & ready to merge. Additionally, added @HazuTo25's lines into the update() routine to configure default A/C settings. * Changed updates.ino to just set A/C to disabled * Fix change reverted by mistake - master merge commit 73badbce8ca171faa8c58575947917829adfc1ba * Fix remaining mistakes from previous master merge * Remove test statements left in by mistake * define unusedBits * Remove test statements left in by mistake * Increase timing granularity to 0.1s * idleUpRPMAdder * Remove another line put in by mistake by auto merge * idleUpRPMFixes * Update speeduino.ino * Tweak A/C idle up descriptions * Tweak A/C TS descriptors again * Fixed alignment bug that turned page 15 config values into gobbledegook. This had the symptom of the A/C request never triggering, because when a pin was assigned in TS (e.g. I did 27), a completely different pin would be read from config15 (in my case 22 - connecting the button to pin 22 would work in this case, even though TS was set to 27). * Fix bit count - should be 6 to match ini file * Increase minimum RPM lockout granularity * Change granularity of A/C minimum RPM lockout to 10 RPM; Inline some functions for readability * Add static inline function prototypes to auxiliaries.h as per the style guide. * Fixed page 15 merge errors * Style changes to suit new pinIsUsed() checks in setPinMappings() * Add PWM Fan Control Minimum Clamp Value when A/C Compressor Engaged * Fix comment * Fix bug with stand-alone fan initialisation Pin was unable to be used in prog. I/O even if fan was disabled, because it was always initialised as an output even if it was disabled. Fixed in this commit. * Correction to Fahrenheit temperature scaling * Move A/C updates to correct next release Co-authored-by: shiznit304 <62686180+shiznit304@users.noreply.github.com> Co-authored-by: Josh Stewart <josh@noisymime.org>
2022-09-06 17:23:01 -07:00
#define SD_LOG_NUM_FIELDS 90 /**< The number of fields that are in the log. This is always smaller than the entry size due to some fields being 2 bytes */
2021-12-09 19:44:27 -08:00
2022-11-05 15:43:29 -07:00
byte getTSLogEntry(uint16_t byteNum);
int16_t getReadableLogEntry(uint16_t logIndex);
#if FPU_MAX_SIZE >= 32
2022-11-05 15:43:29 -07:00
float getReadableFloatLogEntry(uint16_t logIndex);
#endif
2022-11-05 15:43:29 -07:00
bool is2ByteEntry(uint8_t key);
2021-10-12 17:53:46 -07:00
Refactor comms: save 130+ bytes RAM (#906) * Remove serialCRC - only used within parseSerial() Also hoist the CRC read into a function. * Minimize global variable visibility * Encapsulate write of multi-byte primitives * Factor out sendBufferAndCrc() * Push safety test into TS_CommandButtonsHandler() * Extract writePage() * Simpler parsing * Remove some functions from public interface * Store constant arrays in progmem * Centralize high speed logger start/stop code * Factor out loadO2Calibration() * Factor out temperature calibration table update functions * Remove dead code * Fix sendToothLog() * Fix sendCompositeLog() * Replace tooth log send booleans with an enum Saves a byte * Remove sendBufferAndCrcProgMem() Use serialPayload to send * Whitespace clean up * Optimize comms.cpp for size * Replace global unsigned long with bool Saves 2 bytes * Replace 2 global bools with an enum Saves a byte, reads better. * Remove global FastCRC instance * Make sendSerialReturnCode blocking. It was using non-blocking functions but was never re-entered. Rename to make blocking & non-blocking calls more obvious. * Use one uint16_t to track RX/TX byte count * Simplify new comms log tx API * Extract loadPageToBuffer function * All endianess changes use the same code * Doxygen comments and code organization * Remove serialWriteUpdateCrc() & updateTmpCalibration() * Combine SerialStatus & logSendStatus enums. Makes sense since we can only be doing one thing at a time. * Remove global inProgressCompositeTime Only used when sending composite log * Replace 3 global bools with expanded SerialStatus enum * Remove unused global tsCanId * Limit scope of some comms globals. * Remove isMap global - replace witth function * Reduce the serial API to only 2 calls transmit & receive * Tidy up #define visibility * Fix Black* build errors * Workaround Teensy code race condition availableForWrite() is not reliable. * Prevent race condition Was pematurely setting the serialStatusFlag to SERIAL_INACTIVE before final CRC ws read from serial. * Use post write buffer availability checks Remove buffer size check prior to writing. * Write multi-byte values as single bytes. (attempt to fix Teensy 3.5 issue) * Only use Serial.available() as a boolean test (Teensy fix) * writeNonBlocking checks Serial.write() return value * Non-blocking CRC write In sendBufferAndCrcNonBlocking(). * Fix compile warning * Set serial status flag prior to transmitting! * Reliable blocking byte writes. * Fix timeout code: not firing under some conditions * MISRA fixes
2023-02-20 17:55:54 -08:00
void startToothLogger(void);
void stopToothLogger(void);
void startCompositeLogger(void);
void stopCompositeLogger(void);
// This array indicates which index values from the log are 2 byte values
// This array MUST remain in ascending order
// !!!! WARNING: If any value above 255 is required in this array, changes MUST be made to is2ByteEntry() function !!!!
const byte PROGMEM fsIntIndex[] = {4, 14, 17, 22, 26, 28, 33, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 76, 78, 80, 82, 86, 88, 90, 93, 95, 99, 104, 111, 121 };
2021-10-12 17:53:46 -07:00
//List of logger field names. This must be in the same order and length as logger_updateLogdataCSV()
const char header_0[] PROGMEM = "secl";
const char header_1[] PROGMEM = "status1";
const char header_2[] PROGMEM = "engine";
const char header_3[] PROGMEM = "Sync Loss #";
const char header_4[] PROGMEM = "MAP";
const char header_5[] PROGMEM = "IAT(C)";
const char header_6[] PROGMEM = "CLT(C)";
const char header_7[] PROGMEM = "Battery Correction";
const char header_8[] PROGMEM = "Battery V";
const char header_9[] PROGMEM = "AFR";
const char header_10[] PROGMEM = "EGO Correction";
const char header_11[] PROGMEM = "IAT Correction";
const char header_12[] PROGMEM = "WUE Correction";
const char header_13[] PROGMEM = "RPM";
const char header_14[] PROGMEM = "Accel. Correction";
const char header_15[] PROGMEM = "Gamma Correction";
const char header_16[] PROGMEM = "VE1";
const char header_17[] PROGMEM = "VE2";
const char header_18[] PROGMEM = "AFR Target";
const char header_19[] PROGMEM = "TPSdot";
const char header_20[] PROGMEM = "Advance Current";
const char header_21[] PROGMEM = "TPS";
const char header_22[] PROGMEM = "Loops/S";
const char header_23[] PROGMEM = "Free RAM";
const char header_24[] PROGMEM = "Boost Target";
const char header_25[] PROGMEM = "Boost Duty";
const char header_26[] PROGMEM = "status2";
const char header_27[] PROGMEM = "rpmDOT";
const char header_28[] PROGMEM = "Eth%";
const char header_29[] PROGMEM = "Flex Fuel Correction";
const char header_30[] PROGMEM = "Flex Adv Correction";
const char header_31[] PROGMEM = "IAC Steps/Duty";
const char header_32[] PROGMEM = "testoutputs";
const char header_33[] PROGMEM = "AFR2";
const char header_34[] PROGMEM = "Baro";
const char header_35[] PROGMEM = "AUX_IN 0";
const char header_36[] PROGMEM = "AUX_IN 1";
const char header_37[] PROGMEM = "AUX_IN 2";
const char header_38[] PROGMEM = "AUX_IN 3";
const char header_39[] PROGMEM = "AUX_IN 4";
const char header_40[] PROGMEM = "AUX_IN 5";
const char header_41[] PROGMEM = "AUX_IN 6";
const char header_42[] PROGMEM = "AUX_IN 7";
const char header_43[] PROGMEM = "AUX_IN 8";
const char header_44[] PROGMEM = "AUX_IN 9";
const char header_45[] PROGMEM = "AUX_IN 10";
const char header_46[] PROGMEM = "AUX_IN 11";
const char header_47[] PROGMEM = "AUX_IN 12";
const char header_48[] PROGMEM = "AUX_IN 13";
const char header_49[] PROGMEM = "AUX_IN 14";
const char header_50[] PROGMEM = "AUX_IN 15";
const char header_51[] PROGMEM = "TPS ADC";
const char header_52[] PROGMEM = "Errors";
const char header_53[] PROGMEM = "PW";
const char header_54[] PROGMEM = "PW2";
const char header_55[] PROGMEM = "PW3";
const char header_56[] PROGMEM = "PW4";
const char header_57[] PROGMEM = "status3";
const char header_58[] PROGMEM = "Engine Protect";
const char header_59[] PROGMEM = "";
const char header_60[] PROGMEM = "Fuel Load";
const char header_61[] PROGMEM = "Ign Load";
const char header_62[] PROGMEM = "Dwell";
const char header_63[] PROGMEM = "Idle Target (RPM)";
const char header_64[] PROGMEM = "MAP DOT";
const char header_65[] PROGMEM = "VVT1 Angle";
const char header_66[] PROGMEM = "VVT1 Target";
const char header_67[] PROGMEM = "VVT1 Duty";
const char header_68[] PROGMEM = "Flex Boost Adj";
const char header_69[] PROGMEM = "Baro Correction";
const char header_70[] PROGMEM = "VE Current";
const char header_71[] PROGMEM = "ASE Correction";
const char header_72[] PROGMEM = "Vehicle Speed";
const char header_73[] PROGMEM = "Gear";
const char header_74[] PROGMEM = "Fuel Pressure";
const char header_75[] PROGMEM = "Oil Pressure";
const char header_76[] PROGMEM = "WMI PW";
const char header_77[] PROGMEM = "status4";
const char header_78[] PROGMEM = "VVT2 Angle";
const char header_79[] PROGMEM = "VVT2 Target";
const char header_80[] PROGMEM = "VVT2 Duty";
const char header_81[] PROGMEM = "outputs";
const char header_82[] PROGMEM = "Fuel Temp";
const char header_83[] PROGMEM = "Fuel Temp Correction";
const char header_84[] PROGMEM = "Advance 1";
const char header_85[] PROGMEM = "Advance 2";
const char header_86[] PROGMEM = "SD Status";
const char header_87[] PROGMEM = "EMAP";
const char header_88[] PROGMEM = "Fan Duty";
Air Conditioning Control - Feature Implementation (#665) * 19.09.2021 * Final testing of AC Control, some idle features fixed AC control feature added, better than the existing idle-up feature (which can still be used for other things, e.g. electrical load detection). Air conditioning is locked out with coolant temp, RPM high/low, and high TPS. So the A/C automatically cuts out when driving hard. Idle step now works correctly with closed loop PWM, open loop PWM, and closed+open loop PWM. Untested with stepper motor, but no reason it shouldn't work. * Fixed mistakenly incremented page sizes * Initial changes as per HWright9 -Renamed engineRunSeconds to acAfterEngineStartDelay -Formatted large if statements better -Fixed acStartDelay overflow bug -Improved readability of logic * Final fixes as per HWright9's feedback -Add high/low RPM lockout delay, similar to the high TPM lockout delay -General tidy-up * Added stand-alone fan, moved config data in EEPROM -Added additional configurable stand-alone A/C fan output, for when there is dedicated cooling fan for the A/C compressor. This is independent of the engine cooling fan logic. -Moved config storage in EEPROM to configPage9, as noisymime's SD card logging has used the (previously unused) bytes I had used in configPage13. -Minor bug fix - rename Aux in 1-16 to Aux in 0-15 * Revert to current master branch - as of master commit 97f8ef795a514c9a5693e85be6cdb8bdee8ef2c5 * A/C Control Re-Integrated from AC-Control-Clean-3 (@Corey-Harding). Tested & ready to merge. Additionally, added @HazuTo25's lines into the update() routine to configure default A/C settings. * Changed updates.ino to just set A/C to disabled * Fix change reverted by mistake - master merge commit 73badbce8ca171faa8c58575947917829adfc1ba * Fix remaining mistakes from previous master merge * Remove test statements left in by mistake * define unusedBits * Remove test statements left in by mistake * Increase timing granularity to 0.1s * idleUpRPMAdder * Remove another line put in by mistake by auto merge * idleUpRPMFixes * Update speeduino.ino * Tweak A/C idle up descriptions * Tweak A/C TS descriptors again * Fixed alignment bug that turned page 15 config values into gobbledegook. This had the symptom of the A/C request never triggering, because when a pin was assigned in TS (e.g. I did 27), a completely different pin would be read from config15 (in my case 22 - connecting the button to pin 22 would work in this case, even though TS was set to 27). * Fix bit count - should be 6 to match ini file * Increase minimum RPM lockout granularity * Change granularity of A/C minimum RPM lockout to 10 RPM; Inline some functions for readability * Add static inline function prototypes to auxiliaries.h as per the style guide. * Fixed page 15 merge errors * Style changes to suit new pinIsUsed() checks in setPinMappings() * Add PWM Fan Control Minimum Clamp Value when A/C Compressor Engaged * Fix comment * Fix bug with stand-alone fan initialisation Pin was unable to be used in prog. I/O even if fan was disabled, because it was always initialised as an output even if it was disabled. Fixed in this commit. * Correction to Fahrenheit temperature scaling * Move A/C updates to correct next release Co-authored-by: shiznit304 <62686180+shiznit304@users.noreply.github.com> Co-authored-by: Josh Stewart <josh@noisymime.org>
2022-09-06 17:23:01 -07:00
const char header_89[] PROGMEM = "AirConStatus";
2021-10-12 17:53:46 -07:00
/*
const char header_90[] PROGMEM = "";
const char header_91[] PROGMEM = "";
const char header_92[] PROGMEM = "";
const char header_93[] PROGMEM = "";
const char header_94[] PROGMEM = "";
const char header_95[] PROGMEM = "";
const char header_96[] PROGMEM = "";
const char header_97[] PROGMEM = "";
const char header_98[] PROGMEM = "";
const char header_99[] PROGMEM = "";
const char header_100[] PROGMEM = "";
const char header_101[] PROGMEM = "";
const char header_102[] PROGMEM = "";
const char header_103[] PROGMEM = "";
const char header_104[] PROGMEM = "";
const char header_105[] PROGMEM = "";
const char header_106[] PROGMEM = "";
const char header_107[] PROGMEM = "";
const char header_108[] PROGMEM = "";
const char header_109[] PROGMEM = "";
const char header_110[] PROGMEM = "";
const char header_111[] PROGMEM = "";
const char header_112[] PROGMEM = "";
const char header_113[] PROGMEM = "";
const char header_114[] PROGMEM = "";
const char header_115[] PROGMEM = "";
const char header_116[] PROGMEM = "";
const char header_117[] PROGMEM = "";
const char header_118[] PROGMEM = "";
const char header_119[] PROGMEM = "";
const char header_120[] PROGMEM = "";
const char header_121[] PROGMEM = "";
*/
const char* const header_table[] PROGMEM = { header_0,\
header_1,\
header_2,\
header_3,\
header_4,\
header_5,\
header_6,\
header_7,\
header_8,\
header_9,\
header_10,\
header_11,\
header_12,\
header_13,\
header_14,\
header_15,\
header_16,\
header_17,\
header_18,\
header_19,\
header_20,\
header_21,\
header_22,\
header_23,\
header_24,\
header_25,\
header_26,\
header_27,\
header_28,\
header_29,\
header_30,\
header_31,\
header_32,\
header_33,\
header_34,\
header_35,\
header_36,\
header_37,\
header_38,\
header_39,\
header_40,\
header_41,\
header_42,\
header_43,\
header_44,\
header_45,\
header_46,\
header_47,\
header_48,\
header_49,\
header_50,\
header_51,\
header_52,\
header_53,\
header_54,\
header_55,\
header_56,\
header_57,\
header_58,\
header_59,\
header_60,\
header_61,\
header_62,\
header_63,\
header_64,\
header_65,\
header_66,\
header_67,\
header_68,\
header_69,\
header_70,\
header_71,\
header_72,\
header_73,\
header_74,\
header_75,\
header_76,\
header_77,\
header_78,\
header_79,\
header_80,\
header_81,\
header_82,\
header_83,\
header_84,\
header_85,\
header_86,\
header_87,\
header_88,\
header_89,\
Air Conditioning Control - Feature Implementation (#665) * 19.09.2021 * Final testing of AC Control, some idle features fixed AC control feature added, better than the existing idle-up feature (which can still be used for other things, e.g. electrical load detection). Air conditioning is locked out with coolant temp, RPM high/low, and high TPS. So the A/C automatically cuts out when driving hard. Idle step now works correctly with closed loop PWM, open loop PWM, and closed+open loop PWM. Untested with stepper motor, but no reason it shouldn't work. * Fixed mistakenly incremented page sizes * Initial changes as per HWright9 -Renamed engineRunSeconds to acAfterEngineStartDelay -Formatted large if statements better -Fixed acStartDelay overflow bug -Improved readability of logic * Final fixes as per HWright9's feedback -Add high/low RPM lockout delay, similar to the high TPM lockout delay -General tidy-up * Added stand-alone fan, moved config data in EEPROM -Added additional configurable stand-alone A/C fan output, for when there is dedicated cooling fan for the A/C compressor. This is independent of the engine cooling fan logic. -Moved config storage in EEPROM to configPage9, as noisymime's SD card logging has used the (previously unused) bytes I had used in configPage13. -Minor bug fix - rename Aux in 1-16 to Aux in 0-15 * Revert to current master branch - as of master commit 97f8ef795a514c9a5693e85be6cdb8bdee8ef2c5 * A/C Control Re-Integrated from AC-Control-Clean-3 (@Corey-Harding). Tested & ready to merge. Additionally, added @HazuTo25's lines into the update() routine to configure default A/C settings. * Changed updates.ino to just set A/C to disabled * Fix change reverted by mistake - master merge commit 73badbce8ca171faa8c58575947917829adfc1ba * Fix remaining mistakes from previous master merge * Remove test statements left in by mistake * define unusedBits * Remove test statements left in by mistake * Increase timing granularity to 0.1s * idleUpRPMAdder * Remove another line put in by mistake by auto merge * idleUpRPMFixes * Update speeduino.ino * Tweak A/C idle up descriptions * Tweak A/C TS descriptors again * Fixed alignment bug that turned page 15 config values into gobbledegook. This had the symptom of the A/C request never triggering, because when a pin was assigned in TS (e.g. I did 27), a completely different pin would be read from config15 (in my case 22 - connecting the button to pin 22 would work in this case, even though TS was set to 27). * Fix bit count - should be 6 to match ini file * Increase minimum RPM lockout granularity * Change granularity of A/C minimum RPM lockout to 10 RPM; Inline some functions for readability * Add static inline function prototypes to auxiliaries.h as per the style guide. * Fixed page 15 merge errors * Style changes to suit new pinIsUsed() checks in setPinMappings() * Add PWM Fan Control Minimum Clamp Value when A/C Compressor Engaged * Fix comment * Fix bug with stand-alone fan initialisation Pin was unable to be used in prog. I/O even if fan was disabled, because it was always initialised as an output even if it was disabled. Fixed in this commit. * Correction to Fahrenheit temperature scaling * Move A/C updates to correct next release Co-authored-by: shiznit304 <62686180+shiznit304@users.noreply.github.com> Co-authored-by: Josh Stewart <josh@noisymime.org>
2022-09-06 17:23:01 -07:00
/*
2021-10-12 17:53:46 -07:00
header_90,\
header_91,\
header_92,\
header_93,\
header_94,\
header_95,\
header_96,\
header_97,\
header_98,\
header_99,\
header_100,\
header_101,\
header_102,\
header_103,\
header_104,\
header_105,\
header_106,\
header_107,\
header_108,\
header_109,\
header_110,\
header_111,\
header_112,\
header_113,\
header_114,\
header_115,\
header_116,\
header_117,\
header_118,\
header_119,\
header_120,\
header_121,\
*/
};
static_assert(sizeof(header_table) == (sizeof(char*) * SD_LOG_NUM_FIELDS), "Number of header table titles must match number of log fields");
#endif