Skip to content
Snippets Groups Projects
Commit c85eb946 authored by nrs1g15's avatar nrs1g15
Browse files

Tested SD with internal ecu messages and seems good, needs to be tested on car

parent f643be22
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/sufst-controller.iml" filepath="$PROJECT_DIR$/.idea/sufst-controller.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="CPP_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeRunConfigurationManager" shouldGenerate="true" shouldDeleteObsolete="true">
<generated />
</component>
<component name="CMakeSettings">
<configurations>
<configuration PROFILE_NAME="Debug" CONFIG_NAME="Debug" />
</configurations>
</component>
<component name="ChangeListManager">
<list default="true" id="2070e8be-2952-4d02-bba6-112a351189c8" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/can.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/can.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/can.h" beforeDir="false" afterPath="$PROJECT_DIR$/can.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/daq.h" beforeDir="false" afterPath="$PROJECT_DIR$/daq.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ecuCan.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/ecuCan.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/sd.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/sd.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/sufst-controller.ino" beforeDir="false" afterPath="$PROJECT_DIR$/sufst-controller.ino" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sufst-dash/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../sufst-dash/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sufst-dash/sufst-dash.ino" beforeDir="false" afterPath="$PROJECT_DIR$/../sufst-dash/sufst-dash.ino" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="ClangdSettings">
<option name="formatViaClangd" value="false" />
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/ecuCan.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="221">
<caret line="30" column="29" selection-start-line="30" selection-start-column="29" selection-end-line="30" selection-end-column="29" />
<folding>
<element signature="e#39#58#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/dashController.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="80">
<caret line="34" lean-forward="true" selection-start-line="34" selection-end-line="34" />
<folding>
<element signature="e#40#67#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/evoScann-p.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-597">
<caret line="36" column="33" lean-forward="true" selection-start-line="36" selection-start-column="33" selection-end-line="36" selection-end-column="33" />
<folding>
<element signature="e#40#63#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/evoScann-p.h">
<provider selected="true" editor-type-id="text-editor" />
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/can.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="272">
<caret line="16" column="32" lean-forward="true" selection-start-line="16" selection-start-column="32" selection-end-line="16" selection-end-column="32" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/sd.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1049">
<caret line="72" lean-forward="true" selection-start-line="72" selection-end-line="72" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/can.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="323">
<caret line="193" column="1" lean-forward="true" selection-start-line="193" selection-start-column="1" selection-end-line="193" selection-end-column="1" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/wireless.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="884">
<caret line="52" column="1" lean-forward="true" selection-start-line="52" selection-start-column="1" selection-end-line="52" selection-end-column="1" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/wireless.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="238">
<caret line="14" lean-forward="true" selection-start-line="14" selection-end-line="14" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/sufst-controller.ino">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="221">
<caret line="25" column="22" lean-forward="true" selection-start-line="25" selection-start-column="22" selection-end-line="25" selection-end-column="22" />
<folding>
<element signature="e#57#72#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>Serial.print</find>
<find>Se</find>
<find>EcuDataOpenlogger</find>
<find>EcuDataStruct</find>
<find>ecuOpenloggerSave</find>
</findStrings>
<replaceStrings>
<replace>EcuDataStruct</replace>
<replace>EcuDataSaveFormat</replace>
<replace>daqEcuWrite</replace>
</replaceStrings>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/../sufst-dash/sufst-dash.ino" />
<option value="$PROJECT_DIR$/sdTags.h" />
<option value="$PROJECT_DIR$/sdParserTags.h" />
<option value="$PROJECT_DIR$/dataTags.h" />
<option value="$PROJECT_DIR$/dashController.cpp" />
<option value="$PROJECT_DIR$/crc8.c" />
<option value="$PROJECT_DIR$/checksum.h" />
<option value="$PROJECT_DIR$/wireless.h" />
<option value="$PROJECT_DIR$/wireless.cpp" />
<option value="$PROJECT_DIR$/sd.h" />
<option value="$PROJECT_DIR$/daq.cpp" />
<option value="$PROJECT_DIR$/daq.h" />
<option value="$PROJECT_DIR$/can.cpp" />
<option value="$PROJECT_DIR$/sd.cpp" />
<option value="$PROJECT_DIR$/can.h" />
<option value="$PROJECT_DIR$/sufst-controller.ino" />
<option value="$PROJECT_DIR$/ecuCan.cpp" />
</list>
</option>
</component>
<component name="ProjectFrameBounds">
<option name="x" value="588" />
<option name="width" value="1339" />
<option name="height" value="1038" />
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectView">
<navigator proportions="" version="1">
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="Scope" />
<pane id="ProjectPane">
<subPane>
<expand>
<path>
<item name="sufst-controller" type="b2602c69:ProjectViewProjectNode" />
<item name="sufst-controller" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
</pane>
</panes>
</component>
<component name="PropertiesComponent">
<property name="ASKED_SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="node.js.detected.package.eslint" value="true" />
<property name="node.js.detected.package.tslint" value="true" />
<property name="node.js.path.for.package.eslint" value="project" />
<property name="node.js.path.for.package.tslint" value="project" />
<property name="node.js.selected.package.eslint" value="(autodetect)" />
<property name="node.js.selected.package.tslint" value="(autodetect)" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
<property name="settings.editor.selected.configurable" value="preferences.sourceCode.C/C++" />
</component>
<component name="RunDashboard">
<option name="ruleStates">
<list>
<RuleState>
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
</RuleState>
<RuleState>
<option name="name" value="StatusDashboardGroupingRule" />
</RuleState>
</list>
</option>
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="2070e8be-2952-4d02-bba6-112a351189c8" name="Default Changelist" comment="" />
<created>1563993769139</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1563993769139</updated>
<workItem from="1563993770477" duration="2408000" />
<workItem from="1564136548177" duration="6195000" />
<workItem from="1564440384294" duration="8566000" />
</task>
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="17169000" />
</component>
<component name="ToolWindowManager">
<frame x="471" y="0" width="1071" height="830" extended-state="0" />
<editor active="true" />
<layout>
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.29871413" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Favorites" order="2" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" />
<window_info anchor="bottom" id="Run" order="2" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="bottom" id="Database Changes" order="7" />
<window_info anchor="bottom" id="Version Control" order="8" visible="true" weight="0.24212034" />
<window_info anchor="bottom" id="Terminal" order="9" weight="0.3295129" />
<window_info anchor="bottom" id="Event Log" order="10" side_tool="true" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
<window_info anchor="right" id="Database" order="3" />
</layout>
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/../sufst-dash/sufst-dash.ino">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="238">
<caret line="20" column="35" selection-start-line="20" selection-start-column="35" selection-end-line="20" selection-end-column="35" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/openLoggerController.h" />
<entry file="file://$PROJECT_DIR$/dashController.h">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/checksum.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="51">
<caret line="3" column="24" selection-start-line="3" selection-start-column="24" selection-end-line="3" selection-end-column="24" />
<folding>
<element signature="e#1532#1544#0" expanded="true" />
<element signature="e#1926#1927#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/crc8.c">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="733">
<caret line="91" selection-start-line="91" selection-end-line="91" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/ecuCan.h">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/sd.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="357">
<caret line="21" lean-forward="true" selection-start-line="21" selection-end-line="21" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/daq.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="102">
<caret line="21" column="18" lean-forward="true" selection-start-line="21" selection-start-column="18" selection-end-line="21" selection-end-column="18" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/daq.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="360">
<caret line="29" column="1" selection-start-line="29" selection-start-column="1" selection-end-line="29" selection-end-column="1" />
<folding>
<element signature="e#40#56#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/wireless.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="884">
<caret line="52" column="1" lean-forward="true" selection-start-line="52" selection-start-column="1" selection-end-line="52" selection-end-column="1" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/wireless.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="238">
<caret line="14" lean-forward="true" selection-start-line="14" selection-end-line="14" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/can.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="323">
<caret line="193" column="1" lean-forward="true" selection-start-line="193" selection-start-column="1" selection-end-line="193" selection-end-column="1" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/evoScann-p.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-597">
<caret line="36" column="33" lean-forward="true" selection-start-line="36" selection-start-column="33" selection-end-line="36" selection-end-column="33" />
<folding>
<element signature="e#40#63#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/evoScann-p.h">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/sd.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1049">
<caret line="72" lean-forward="true" selection-start-line="72" selection-end-line="72" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/dashController.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="80">
<caret line="34" lean-forward="true" selection-start-line="34" selection-end-line="34" />
<folding>
<element signature="e#40#67#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/can.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="272">
<caret line="16" column="32" lean-forward="true" selection-start-line="16" selection-start-column="32" selection-end-line="16" selection-end-column="32" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/sufst-controller.ino">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="221">
<caret line="25" column="22" lean-forward="true" selection-start-line="25" selection-start-column="22" selection-end-line="25" selection-end-column="22" />
<folding>
<element signature="e#57#72#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/ecuCan.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="221">
<caret line="30" column="29" selection-start-line="30" selection-start-column="29" selection-end-line="30" selection-end-column="29" />
<folding>
<element signature="e#39#58#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</component>
</project>
\ No newline at end of file
......@@ -188,9 +188,9 @@ void canParseRxMsg(CanMsgTemplate *canMsg)
// This removes the need for a long if statement giving significant performance boosts
(*ecuCanFuncPtrs[canMsg->idByte[0]])(canMsg);
}
// else if (canMsg->id == 0x487) {
// evoScannNonMux(canMsg);
// }
else if (canMsg->id == 0x487) {
evoScannNonMux(canMsg);
}
}
void canProcessRx()
......
......@@ -9,7 +9,7 @@
// CAN_INT_PIN MUST BE 2
#define CAN_INT_PIN 2
#define CAN_CS_PIN 10
#define CAN_CS_PIN 9
#define CAN_RX_BUFFER_LEN 32
#define CAN_TX_BUFFER_LEN 32
......
......@@ -25,6 +25,4 @@ void daqEcuWrite(CanMsgTemplate *canMsg, uint8_t index)
daqEcuFormat.endTag = ecuParamterTag;
sdWrite(&daqEcuFormat, sizeof(DaqEcuFormat));
wirelessWrite(&daqEcuFormat, sizeof(DaqEcuFormat));
}
\ No newline at end of file
......@@ -13,7 +13,7 @@ uint16_t gWaterTemp = 0;
void dashBegin()
{
Serial2.begin(57600);
DASH_SERIAL.begin(DASH_SERIAL_BAUD_RATE);
}
void dashEcuSetRpm(uint16_t rpm)
......@@ -45,6 +45,6 @@ void dashControllerProcess()
serialPayload[5] = crc_8(&(serialPayload[1]), 4);
Serial2.write(serialPayload, 6);
DASH_SERIAL.write(serialPayload, 6);
}
}
......@@ -8,6 +8,8 @@
#include "Arduino.h"
#define DASH_REFRESH_MS 20
#define DASH_SERIAL Serial2
#define DASH_SERIAL_BAUD_RATE 57600
void dashBegin();
void dashEcuSetRpm(uint16_t rpm);
......
......@@ -26,9 +26,9 @@ void ecuCanMsg0x2000(CanMsgTemplate *canMsg)
uint16_t waterTempC = canMsg->data16[2];
uint16_t airTempC = canMsg->data16[3];
// daqEcuWrite(canMsg, 0);
// daqEcuWrite(canMsg, 1);
// daqEcuWrite(canMsg, 2);
daqEcuWrite(canMsg, 0);
daqEcuWrite(canMsg, 1);
daqEcuWrite(canMsg, 2);
dashEcuSetRpm(rpm);
dashEcuSetWaterTemp(waterTempC);
......@@ -54,7 +54,8 @@ void ecuCanMsg0x2001(CanMsgTemplate *canMsg)
uint16_t speedKphx10 = canMsg->data16[2];
uint16_t oilPressKpa = canMsg->data16[3];
// daqEcuWrite(canMsg, 1);
daqEcuWrite(canMsg, 1);
daqEcuWrite(canMsg, 2);
}
void ecuCanMsg0x2002(CanMsgTemplate *canMsg)
......@@ -77,7 +78,7 @@ void ecuCanMsg0x2002(CanMsgTemplate *canMsg)
uint16_t batteryVx10 = canMsg->data16[2];
uint16_t fuelComsumLpHrx10 = canMsg->data16[3];
// daqEcuWrite(canMsg, 2);
daqEcuWrite(canMsg, 2);
// Serial.println((float)(batteryVx10 / 10.0));
}
......@@ -102,7 +103,8 @@ void ecuCanMsg0x2003(CanMsgTemplate *canMsg)
uint16_t injectionTimeMsx100 = canMsg->data16[2];
uint16_t fuelComsumLp100kMx10 = canMsg->data16[3];
// daqEcuWrite(canMsg, 1);
daqEcuWrite(canMsg, 1);
daqEcuWrite(canMsg, 2);
}
void ecuCanMsg0x2004(CanMsgTemplate *canMsg)
......@@ -125,7 +127,7 @@ void ecuCanMsg0x2004(CanMsgTemplate *canMsg)
uint16_t ana3mV = canMsg->data16[2];
uint16_t camAdvanceDegx10 = canMsg->data16[3];
// daqEcuWrite(canMsg, 3);
daqEcuWrite(canMsg, 3);
}
void ecuCanMsg0x2005(CanMsgTemplate *canMsg)
......@@ -148,7 +150,10 @@ void ecuCanMsg0x2005(CanMsgTemplate *canMsg)
uint16_t crankErrorsNr = canMsg->data16[2];
uint16_t camErrorsNr = canMsg->data16[3];
// daqEcuWrite(canMsg, 0);
daqEcuWrite(canMsg, 0);
daqEcuWrite(canMsg, 1);
daqEcuWrite(canMsg, 2);
daqEcuWrite(canMsg, 3);
}
void ecuCanMsg0x2006(CanMsgTemplate *canMsg)
......@@ -191,10 +196,10 @@ void ecuCanMsg0x2007(CanMsgTemplate *canMsg)
uint16_t lambdaPidTargPercx10 = canMsg->data16[1];
uint16_t lambdaPidAdjPercx10 = canMsg->data16[2];
uint16_t ecuSwitchesBitField = canMsg->data16[3];
//
// daqEcuWrite(canMsg, 0);
// daqEcuWrite(canMsg, 1);
// daqEcuWrite(canMsg, 2);
daqEcuWrite(canMsg, 0);
daqEcuWrite(canMsg, 1);
daqEcuWrite(canMsg, 2);
}
void ecuCanMsg0x2008(CanMsgTemplate *canMsg)
......
......@@ -8,6 +8,9 @@
#include "Arduino.h"
#include "can.h"
#define DEBUG_ECU_CAN 0
#define DEBUG_ECU_CAN_MINIMAL 0
/*
* These are called from can.cpp when their corresponding can msg id is seen.
* So functions name *must* ecuCanMsg0x200N.
......
......@@ -6,7 +6,8 @@
#include "buffer.h"
#include "SdFat.h"
enum SdState {
enum SdState
{
stopped = 0,
writing,
};
......@@ -23,35 +24,49 @@ CirBuffer sdCirBuffer;
uint8_t sdBegin()
{
if (!cirBufferBegin(&sdCirBuffer, sdBuffer, SD_BUFFER_LEN, sizeof(uint8_t))) {
const uint8_t SD_BASE_NAME_SIZE = sizeof(SD_BASE_FILE_NAME) - 1;
char fileName[13] = SD_BASE_FILE_NAME "00.bin";
if (!sd.begin(SD_CS_PIN, SD_SCK_MHZ(50))) {
sdState = stopped;
Serial.println("SD: BEGIN ERR");
return 0;
}
if (!sd.begin(SD_CS_PIN, SD_SCK_MHZ(10))) {
while (sd.exists(fileName)) {
if (fileName[SD_BASE_NAME_SIZE + 1] != '9') {
fileName[SD_BASE_NAME_SIZE + 1]++;
}
else if (fileName[SD_BASE_NAME_SIZE] != '9') {
fileName[SD_BASE_NAME_SIZE + 1] = '0';
fileName[SD_BASE_NAME_SIZE]++;
}
else {
sdState = stopped;
Serial.println("SD: NAME ERR");
}
}
if (!file.open(fileName, O_WRITE | O_CREAT)) {
sdState = stopped;
Serial.println("SD: FILE ERR");
return 0;
}
if (sd.exists(SD_FILE_NAME)) {
if (!file.open(SD_FILE_NAME, O_WRITE | O_APPEND)) {
sdState = stopped;
if (!cirBufferBegin(&sdCirBuffer, sdBuffer, SD_BUFFER_LEN, sizeof(uint8_t))) {
return 0;
}
}
else {
if (!file.open(SD_FILE_NAME, O_WRITE | O_CREAT)) {
sdState = stopped;
sdState = stopped;
Serial.println("SD: BUFF ERR");
return 0;
}
return 0;
}
sdState = writing;
......@@ -70,32 +85,29 @@ void sdProcess()
{
static uint8_t sdPayload[SD_WRITE_LEN];
static uint8_t sdWritesCntBeforeFlush = 0;
if (sdState == writing) {
if (cirBufferAvailable(&sdCirBuffer) >= SD_WRITE_LEN) {
if (sdState != writing) {
uint32_t currentMs = millis();
static uint32_t lastTryMs = 0;
cirBufferReadBytes(&sdCirBuffer, sdPayload, SD_WRITE_LEN);
if ((currentMs - lastTryMs) >= SD_START_TRY_AGAIN_MS) {
sdBegin();
if (!file.write(sdPayload, SD_WRITE_LEN)) {
lastTryMs = millis();
}
}
else if (cirBufferAvailable(&sdCirBuffer) >= SD_WRITE_LEN) {
sdState = stopped;
}
cirBufferReadBytes(&sdCirBuffer, sdPayload, SD_WRITE_LEN);
sdWritesCntBeforeFlush++;
if (!file.write(sdPayload, SD_WRITE_LEN)) {
if (sdWritesCntBeforeFlush >= SD_WRITES_BEFORE_FLUSH) {
if (!file.sync() || file.getWriteError()) {
Serial.println("SD: WRITE ERR");
sdState = stopped;
}
sdWritesCntBeforeFlush++;
sdState = stopped;
if (sdWritesCntBeforeFlush >= SD_WRITES_BEFORE_FLUSH) {
file.flush();
sdBegin();
}
sdWritesCntBeforeFlush = 0;
sdWritesCntBeforeFlush = 0;
}
}
}
}
\ No newline at end of file
}
......@@ -16,7 +16,7 @@
#define SD_FILE_NAME "DATA.BIN"
#define SD_WRITES_BEFORE_FLUSH 2
#define SD_START_TRY_AGAIN_MS 1000
#define SD_BASE_FILE_NAME "DATA"
uint8_t sdBegin();
......
#define DEBUG_ECU_CAN 0
#define DEBUG_ECU_CAN_MINIMAL 0
#include "sd.h"
#include "ecuCan.h"
#include "can.h"
......@@ -19,11 +16,9 @@ void setup()
dashBegin();
//sdBegin();
sdBegin();
canBegin();
//wirelessBegin();
}
void loop()
......@@ -33,10 +28,9 @@ void loop()
/*
* ALL PROCESSES *MUST* BE NON BLOCKING
*/
canProcessRx();
dashControllerProcess();
//sdProcess();
//wirelessProcess();
sdProcess();
//canProcessTx();
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment