Skip to content

Commit

Permalink
MISRA: clean up logger header (speeduino#1108)
Browse files Browse the repository at this point in the history
* Move log header definitions inside sd_logger.ino
It's the only place they are used.

* Convert to CPP - fixes build error

* Encapsulate fsIntIndex

* MISRA fixes

* Convert logger.ino -> cpp

* Conditonal compile - reclaim memory
  • Loading branch information
adbancroft authored Oct 6, 2023
1 parent 650efeb commit 977ffa3
Show file tree
Hide file tree
Showing 9 changed files with 345 additions and 319 deletions.
255 changes: 255 additions & 0 deletions speeduino/SD_logger.ino → speeduino/SD_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,261 @@
#include "rtc_common.h"
#include "maths.h"

//List of logger field names. This must be in the same order and length as logger_updateLogdataCSV()
constexpr char header_0[] PROGMEM = "secl";
constexpr char header_1[] PROGMEM = "status1";
constexpr char header_2[] PROGMEM = "engine";
constexpr char header_3[] PROGMEM = "Sync Loss #";
constexpr char header_4[] PROGMEM = "MAP";
constexpr char header_5[] PROGMEM = "IAT(C)";
constexpr char header_6[] PROGMEM = "CLT(C)";
constexpr char header_7[] PROGMEM = "Battery Correction";
constexpr char header_8[] PROGMEM = "Battery V";
constexpr char header_9[] PROGMEM = "AFR";
constexpr char header_10[] PROGMEM = "EGO Correction";
constexpr char header_11[] PROGMEM = "IAT Correction";
constexpr char header_12[] PROGMEM = "WUE Correction";
constexpr char header_13[] PROGMEM = "RPM";
constexpr char header_14[] PROGMEM = "Accel. Correction";
constexpr char header_15[] PROGMEM = "Gamma Correction";
constexpr char header_16[] PROGMEM = "VE1";
constexpr char header_17[] PROGMEM = "VE2";
constexpr char header_18[] PROGMEM = "AFR Target";
constexpr char header_19[] PROGMEM = "TPSdot";
constexpr char header_20[] PROGMEM = "Advance Current";
constexpr char header_21[] PROGMEM = "TPS";
constexpr char header_22[] PROGMEM = "Loops/S";
constexpr char header_23[] PROGMEM = "Free RAM";
constexpr char header_24[] PROGMEM = "Boost Target";
constexpr char header_25[] PROGMEM = "Boost Duty";
constexpr char header_26[] PROGMEM = "status2";
constexpr char header_27[] PROGMEM = "rpmDOT";
constexpr char header_28[] PROGMEM = "Eth%";
constexpr char header_29[] PROGMEM = "Flex Fuel Correction";
constexpr char header_30[] PROGMEM = "Flex Adv Correction";
constexpr char header_31[] PROGMEM = "IAC Steps/Duty";
constexpr char header_32[] PROGMEM = "testoutputs";
constexpr char header_33[] PROGMEM = "AFR2";
constexpr char header_34[] PROGMEM = "Baro";
constexpr char header_35[] PROGMEM = "AUX_IN 0";
constexpr char header_36[] PROGMEM = "AUX_IN 1";
constexpr char header_37[] PROGMEM = "AUX_IN 2";
constexpr char header_38[] PROGMEM = "AUX_IN 3";
constexpr char header_39[] PROGMEM = "AUX_IN 4";
constexpr char header_40[] PROGMEM = "AUX_IN 5";
constexpr char header_41[] PROGMEM = "AUX_IN 6";
constexpr char header_42[] PROGMEM = "AUX_IN 7";
constexpr char header_43[] PROGMEM = "AUX_IN 8";
constexpr char header_44[] PROGMEM = "AUX_IN 9";
constexpr char header_45[] PROGMEM = "AUX_IN 10";
constexpr char header_46[] PROGMEM = "AUX_IN 11";
constexpr char header_47[] PROGMEM = "AUX_IN 12";
constexpr char header_48[] PROGMEM = "AUX_IN 13";
constexpr char header_49[] PROGMEM = "AUX_IN 14";
constexpr char header_50[] PROGMEM = "AUX_IN 15";
constexpr char header_51[] PROGMEM = "TPS ADC";
constexpr char header_52[] PROGMEM = "Errors";
constexpr char header_53[] PROGMEM = "PW";
constexpr char header_54[] PROGMEM = "PW2";
constexpr char header_55[] PROGMEM = "PW3";
constexpr char header_56[] PROGMEM = "PW4";
constexpr char header_57[] PROGMEM = "status3";
constexpr char header_58[] PROGMEM = "Engine Protect";
constexpr char header_59[] PROGMEM = "";
constexpr char header_60[] PROGMEM = "Fuel Load";
constexpr char header_61[] PROGMEM = "Ign Load";
constexpr char header_62[] PROGMEM = "Dwell Requested";
constexpr char header_63[] PROGMEM = "Idle Target (RPM)";
constexpr char header_64[] PROGMEM = "MAP DOT";
constexpr char header_65[] PROGMEM = "VVT1 Angle";
constexpr char header_66[] PROGMEM = "VVT1 Target";
constexpr char header_67[] PROGMEM = "VVT1 Duty";
constexpr char header_68[] PROGMEM = "Flex Boost Adj";
constexpr char header_69[] PROGMEM = "Baro Correction";
constexpr char header_70[] PROGMEM = "VE Current";
constexpr char header_71[] PROGMEM = "ASE Correction";
constexpr char header_72[] PROGMEM = "Vehicle Speed";
constexpr char header_73[] PROGMEM = "Gear";
constexpr char header_74[] PROGMEM = "Fuel Pressure";
constexpr char header_75[] PROGMEM = "Oil Pressure";
constexpr char header_76[] PROGMEM = "WMI PW";
constexpr char header_77[] PROGMEM = "status4";
constexpr char header_78[] PROGMEM = "VVT2 Angle";
constexpr char header_79[] PROGMEM = "VVT2 Target";
constexpr char header_80[] PROGMEM = "VVT2 Duty";
constexpr char header_81[] PROGMEM = "outputs";
constexpr char header_82[] PROGMEM = "Fuel Temp";
constexpr char header_83[] PROGMEM = "Fuel Temp Correction";
constexpr char header_84[] PROGMEM = "Advance 1";
constexpr char header_85[] PROGMEM = "Advance 2";
constexpr char header_86[] PROGMEM = "SD Status";
constexpr char header_87[] PROGMEM = "EMAP";
constexpr char header_88[] PROGMEM = "Fan Duty";
constexpr char header_89[] PROGMEM = "AirConStatus";
constexpr char header_90[] PROGMEM = "Dwell Actual";
/*
constexpr char header_91[] PROGMEM = "";
constexpr char header_92[] PROGMEM = "";
constexpr char header_93[] PROGMEM = "";
constexpr char header_94[] PROGMEM = "";
constexpr char header_95[] PROGMEM = "";
constexpr char header_96[] PROGMEM = "";
constexpr char header_97[] PROGMEM = "";
constexpr char header_98[] PROGMEM = "";
constexpr char header_99[] PROGMEM = "";
constexpr char header_100[] PROGMEM = "";
constexpr char header_101[] PROGMEM = "";
constexpr char header_102[] PROGMEM = "";
constexpr char header_103[] PROGMEM = "";
constexpr char header_104[] PROGMEM = "";
constexpr char header_105[] PROGMEM = "";
constexpr char header_106[] PROGMEM = "";
constexpr char header_107[] PROGMEM = "";
constexpr char header_108[] PROGMEM = "";
constexpr char header_109[] PROGMEM = "";
constexpr char header_110[] PROGMEM = "";
constexpr char header_111[] PROGMEM = "";
constexpr char header_112[] PROGMEM = "";
constexpr char header_113[] PROGMEM = "";
constexpr char header_114[] PROGMEM = "";
constexpr char header_115[] PROGMEM = "";
constexpr char header_116[] PROGMEM = "";
constexpr char header_117[] PROGMEM = "";
constexpr char header_118[] PROGMEM = "";
constexpr char header_119[] PROGMEM = "";
constexpr char header_120[] PROGMEM = "";
constexpr char header_121[] PROGMEM = "";
*/

constexpr const char* 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,\
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,\
*/
};
#define SD_LOG_NUM_FIELDS 91 /**< The number of fields that are in the log. This is always smaller than the entry size due to some fields being 2 bytes */

static_assert(sizeof(header_table) == (sizeof(char*) * SD_LOG_NUM_FIELDS), "Number of header table titles must match number of log fields");

SdExFat sd;
ExFile logFile;
RingBuf<ExFile, RING_BUF_CAPACITY> rb;
Expand Down
8 changes: 6 additions & 2 deletions speeduino/SD_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#else
#include "SdFat.h"
#endif
#include "logger.h"
//#include <SdSpiCard.h>
#include "RingBuf.h"


Expand Down Expand Up @@ -43,6 +41,12 @@
#define SD_CS_PIN 10 //This is a made up value for now
#endif

#ifndef UNIT_TEST // Scope guard for unit testing
#define SD_LOG_ENTRY_SIZE 127 /**< The size of the live data packet used by the SD card.*/
#else
#define SD_LOG_ENTRY_SIZE 1 /**< The size of the live data packet used by the SD card.*/
#endif

//Test values only
#define SD_LOG_FILE_SIZE 10000000 //Default 10mb file size
#define MAX_LOG_FILES 10000
Expand Down
4 changes: 2 additions & 2 deletions speeduino/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ void setPinMapping(byte boardID);
void changeHalfToFullSync(void);
void changeFullToHalfSync(void);

#define VSS_USES_RPM2() ((configPage2.vssMode > 1) && (pinVSS == pinTrigger2) && !BIT_CHECK(decoderState, BIT_DECODER_HAS_SECONDARY)) // VSS is on the same pin as RPM2 and RPM2 is not used as part of the decoder
#define FLEX_USES_RPM2() ((configPage2.flexEnabled > 0) && (pinFlex == pinTrigger2) && !BIT_CHECK(decoderState, BIT_DECODER_HAS_SECONDARY)) // Same as above, but for Flex sensor
#define VSS_USES_RPM2() ((configPage2.vssMode > 1U) && (pinVSS == pinTrigger2) && !BIT_CHECK(decoderState, BIT_DECODER_HAS_SECONDARY)) // VSS is on the same pin as RPM2 and RPM2 is not used as part of the decoder
#define FLEX_USES_RPM2() ((configPage2.flexEnabled > 0U) && (pinFlex == pinTrigger2) && !BIT_CHECK(decoderState, BIT_DECODER_HAS_SECONDARY)) // Same as above, but for Flex sensor

#endif
30 changes: 30 additions & 0 deletions speeduino/init.ino
Original file line number Diff line number Diff line change
Expand Up @@ -987,8 +987,10 @@ void initialiseAll(void)
inj3EndFunction = closeInjector3;
inj4StartFunction = openInjector4;
inj4EndFunction = closeInjector4;
#if (INJ_CHANNELS >= 5)
inj5StartFunction = openInjector5;
inj5EndFunction = closeInjector5;
#endif
break;

case INJ_SEMISEQUENTIAL:
Expand Down Expand Up @@ -1052,8 +1054,10 @@ void initialiseAll(void)
inj3EndFunction = closeInjector3;
inj4StartFunction = openInjector4;
inj4EndFunction = closeInjector4;
#if (INJ_CHANNELS >= 5)
inj5StartFunction = openInjector5;
inj5EndFunction = closeInjector5;
#endif
}
break;

Expand All @@ -1067,14 +1071,22 @@ void initialiseAll(void)
inj3EndFunction = closeInjector3;
inj4StartFunction = openInjector4;
inj4EndFunction = closeInjector4;
#if (INJ_CHANNELS >= 5)
inj5StartFunction = openInjector5;
inj5EndFunction = closeInjector5;
#endif
#if (INJ_CHANNELS >= 6)
inj6StartFunction = openInjector6;
inj6EndFunction = closeInjector6;
#endif
#if (INJ_CHANNELS >= 7)
inj7StartFunction = openInjector7;
inj7EndFunction = closeInjector7;
#endif
#if (INJ_CHANNELS >= 8)
inj8StartFunction = openInjector8;
inj8EndFunction = closeInjector8;
#endif
break;

default:
Expand All @@ -1087,8 +1099,10 @@ void initialiseAll(void)
inj3EndFunction = closeInjector3;
inj4StartFunction = openInjector4;
inj4EndFunction = closeInjector4;
#if (INJ_CHANNELS >= 5)
inj5StartFunction = openInjector5;
inj5EndFunction = closeInjector5;
#endif
break;
}

Expand Down Expand Up @@ -1118,14 +1132,22 @@ void initialiseAll(void)
ign3EndFunction = endCoil1Charge;
ign4StartFunction = beginCoil1Charge;
ign4EndFunction = endCoil1Charge;
#if (INJ_CHANNELS >= 5)
ign5StartFunction = beginCoil1Charge;
ign5EndFunction = endCoil1Charge;
#endif
#if (INJ_CHANNELS >= 6)
ign6StartFunction = beginCoil1Charge;
ign6EndFunction = endCoil1Charge;
#endif
#if (INJ_CHANNELS >= 7)
ign7StartFunction = beginCoil1Charge;
ign7EndFunction = endCoil1Charge;
#endif
#if (INJ_CHANNELS >= 5)
ign8StartFunction = beginCoil1Charge;
ign8EndFunction = endCoil1Charge;
#endif
break;

case IGN_MODE_WASTEDCOP:
Expand Down Expand Up @@ -3602,14 +3624,22 @@ void changeHalfToFullSync(void)
inj3EndFunction = closeInjector3;
inj4StartFunction = openInjector4;
inj4EndFunction = closeInjector4;
#if (INJ_CHANNELS >= 5)
inj5StartFunction = openInjector5;
inj5EndFunction = closeInjector5;
#endif
#if (INJ_CHANNELS >= 6)
inj6StartFunction = openInjector6;
inj6EndFunction = closeInjector6;
#endif
#if (INJ_CHANNELS >= 7)
inj7StartFunction = openInjector7;
inj7EndFunction = closeInjector7;
#endif
#if (INJ_CHANNELS >= 8)
inj8StartFunction = openInjector8;
inj8EndFunction = closeInjector8;
#endif

switch (configPage2.nCylinders)
{
Expand Down
Loading

0 comments on commit 977ffa3

Please sign in to comment.