From bd95e51d7981dbde4647c74b584d0da553051d86 Mon Sep 17 00:00:00 2001
From: nrs1g15 <nrs1g15@soton.ac.uk>
Date: Sun, 21 Jul 2019 13:02:23 +0100
Subject: [PATCH] Added new timestamp field to can messages to allow for
 timestamping data, this allows when saving to sd card or wireless
 transmission we know when that data was captured

---
 .../.idea/workspace.xml                       | 212 +++++++----
 sufst-openlogger_controller/buffer.cpp        |   2 +-
 sufst-openlogger_controller/can.cpp           |  40 +-
 sufst-openlogger_controller/can.h             |   7 +-
 sufst-openlogger_controller/ecuCan.cpp        | 263 +++++++++++++
 sufst-openlogger_controller/ecuCan.h          |  38 ++
 .../sufst-openlogger_controller.ino           | 346 +-----------------
 7 files changed, 478 insertions(+), 430 deletions(-)
 create mode 100644 sufst-openlogger_controller/ecuCan.cpp
 create mode 100644 sufst-openlogger_controller/ecuCan.h

diff --git a/sufst-openlogger_controller/.idea/workspace.xml b/sufst-openlogger_controller/.idea/workspace.xml
index ee11b5a..beeae57 100644
--- a/sufst-openlogger_controller/.idea/workspace.xml
+++ b/sufst-openlogger_controller/.idea/workspace.xml
@@ -10,10 +10,12 @@
   </component>
   <component name="ChangeListManager">
     <list default="true" id="e173ebdc-c119-4235-9653-364cc21b27a5" name="Default Changelist" comment="">
-      <change beforePath="$PROJECT_DIR$/../sufst-openlogger/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../sufst-openlogger/.idea/workspace.xml" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/ecuCan.cpp" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/ecuCan.h" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/buffer.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/buffer.cpp" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/openLoggerController.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/openLoggerController.cpp" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/openLoggerController.h" beforeDir="false" afterPath="$PROJECT_DIR$/openLoggerController.h" 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$/sufst-openlogger_controller.ino" beforeDir="false" afterPath="$PROJECT_DIR$/sufst-openlogger_controller.ino" afterDir="false" />
     </list>
     <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@@ -44,11 +46,55 @@
   </component>
   <component name="FileEditorManager">
     <leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
-      <file pinned="false" current-in-tab="true">
+      <file pinned="false" current-in-tab="false">
         <entry file="file://$PROJECT_DIR$/sufst-openlogger_controller.ino">
           <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="613">
-              <caret line="375" column="27" selection-start-line="375" selection-start-column="27" selection-end-line="375" selection-end-column="27" />
+            <state relative-caret-position="629">
+              <caret line="56" lean-forward="true" selection-start-line="56" selection-end-line="56" />
+              <folding>
+                <element signature="e#57#90#0" expanded="true" />
+              </folding>
+            </state>
+          </provider>
+        </entry>
+      </file>
+      <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="715">
+              <caret line="59" lean-forward="true" selection-start-line="59" selection-end-line="59" />
+              <folding>
+                <element signature="e#39#58#0" expanded="true" />
+                <element signature="e#767#962#0" expanded="true" />
+                <element signature="e#1017#1048#0" expanded="true" />
+                <element signature="e#1415#1610#0" expanded="true" />
+                <element signature="e#1665#1696#0" expanded="true" />
+                <element signature="e#2008#2203#0" expanded="true" />
+                <element signature="e#2258#2289#0" expanded="true" />
+                <element signature="e#3273#3468#0" expanded="true" />
+                <element signature="e#3523#3554#0" expanded="true" />
+                <element signature="e#3914#4109#0" expanded="true" />
+                <element signature="e#4164#4195#0" expanded="true" />
+                <element signature="e#4492#4687#0" expanded="true" />
+                <element signature="e#4742#4773#0" expanded="true" />
+                <element signature="e#5086#5281#0" expanded="true" />
+                <element signature="e#5336#5367#0" expanded="true" />
+                <element signature="e#5683#5878#0" expanded="true" />
+                <element signature="e#5933#5964#0" expanded="true" />
+                <element signature="e#6301#6496#0" expanded="true" />
+                <element signature="e#6551#6582#0" expanded="true" />
+                <element signature="e#6899#7094#0" expanded="true" />
+                <element signature="e#7149#7180#0" expanded="true" />
+              </folding>
+            </state>
+          </provider>
+        </entry>
+      </file>
+      <file pinned="false" current-in-tab="false">
+        <entry file="file://$PROJECT_DIR$/ecuCan.h">
+          <provider selected="true" editor-type-id="text-editor">
+            <state relative-caret-position="357">
+              <caret line="21" selection-start-line="21" selection-end-line="21" />
             </state>
           </provider>
         </entry>
@@ -56,22 +102,10 @@
       <file pinned="false" current-in-tab="false">
         <entry file="file://$PROJECT_DIR$/openLoggerController.cpp">
           <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="610">
-              <caret line="185" lean-forward="true" selection-start-line="185" selection-end-line="185" />
+            <state relative-caret-position="683">
+              <caret line="55" lean-forward="true" selection-start-line="55" selection-end-line="55" />
               <folding>
                 <element signature="e#40#73#0" expanded="true" />
-                <element signature="e#2292#2367#0" expanded="true" />
-                <element signature="e#2559#2637#0" expanded="true" />
-                <element signature="e#2895#2973#0" expanded="true" />
-                <element signature="e#4435#4468#0" expanded="true" />
-                <element signature="e#4894#4935#0" expanded="true" />
-                <element signature="e#5052#5092#0" expanded="true" />
-                <element signature="e#5210#5251#0" expanded="true" />
-                <element signature="e#5773#5813#0" expanded="true" />
-                <element signature="e#5953#6000#0" expanded="true" />
-                <element signature="e#6138#6185#0" expanded="true" />
-                <element signature="e#6384#6509#0" expanded="true" />
-                <element signature="e#7073#7169#0" expanded="true" />
               </folding>
             </state>
           </provider>
@@ -89,8 +123,8 @@
       <file pinned="false" current-in-tab="false">
         <entry file="file://$PROJECT_DIR$/buffer.h">
           <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="459">
-              <caret line="27" column="9" selection-start-line="27" selection-start-column="9" selection-end-line="27" selection-end-column="9" />
+            <state relative-caret-position="85">
+              <caret line="5" column="16" selection-start-line="5" selection-start-column="16" selection-end-line="5" selection-end-column="16" />
             </state>
           </provider>
         </entry>
@@ -98,8 +132,8 @@
       <file pinned="false" current-in-tab="false">
         <entry file="file://$PROJECT_DIR$/buffer.cpp">
           <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="283">
-              <caret line="82" column="85" selection-start-line="82" selection-start-column="85" selection-end-line="82" selection-end-column="85" />
+            <state relative-caret-position="350">
+              <caret line="99" column="1" lean-forward="true" selection-start-line="99" selection-start-column="1" selection-end-line="99" selection-end-column="1" />
             </state>
           </provider>
         </entry>
@@ -107,8 +141,8 @@
       <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="32">
-              <caret line="210" column="30" selection-start-line="210" selection-start-column="30" selection-end-line="210" selection-end-column="30" />
+            <state relative-caret-position="306">
+              <caret line="18" lean-forward="true" selection-start-line="18" selection-end-line="18" />
             </state>
           </provider>
         </entry>
@@ -116,8 +150,8 @@
       <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="187">
-              <caret line="11" column="21" selection-start-line="11" selection-start-column="21" selection-end-line="11" selection-end-column="21" />
+            <state relative-caret-position="221">
+              <caret line="13" column="28" lean-forward="true" selection-start-line="13" selection-start-column="28" selection-end-line="13" selection-end-column="28" />
             </state>
           </provider>
         </entry>
@@ -126,7 +160,6 @@
   </component>
   <component name="FindInProjectRecents">
     <findStrings>
-      <find>openloggerTxPayload</find>
       <find>cirBuffer</find>
       <find>openloggerCommandTxCirBuffer</find>
       <find>begin</find>
@@ -156,6 +189,7 @@
       <find>tail</find>
       <find>Serial</find>
       <find>OPENLOGGER_TX_BUFFER_LEN</find>
+      <find>openloggerProcess</find>
     </findStrings>
     <replaceStrings>
       <replace>Serial1</replace>
@@ -172,21 +206,23 @@
       <list>
         <option value="$PROJECT_DIR$/circularBuffer.cpp" />
         <option value="$PROJECT_DIR$/circularBuffer.h" />
-        <option value="$PROJECT_DIR$/can.h" />
-        <option value="$PROJECT_DIR$/can.cpp" />
         <option value="$PROJECT_DIR$/buffer.h" />
+        <option value="$PROJECT_DIR$/openLoggerController.h" />
+        <option value="$PROJECT_DIR$/ecuCan.h" />
         <option value="$PROJECT_DIR$/buffer.cpp" />
         <option value="$PROJECT_DIR$/openLoggerController.cpp" />
-        <option value="$PROJECT_DIR$/openLoggerController.h" />
+        <option value="$PROJECT_DIR$/can.cpp" />
+        <option value="$PROJECT_DIR$/can.h" />
         <option value="$PROJECT_DIR$/sufst-openlogger_controller.ino" />
+        <option value="$PROJECT_DIR$/ecuCan.cpp" />
       </list>
     </option>
   </component>
   <component name="OCFindUsagesOptions" text="true" ivars="false" properties="true" derivedClasses="false" />
   <component name="ProjectFrameBounds">
-    <option name="x" value="570" />
-    <option name="width" value="3282" />
-    <option name="height" value="2112" />
+    <option name="x" value="976" />
+    <option name="width" value="2873" />
+    <option name="height" value="2111" />
   </component>
   <component name="ProjectLevelVcsManager" settingsEditedManually="true">
     <ConfirmationsSetting value="2" id="Add" />
@@ -196,6 +232,7 @@
       <foldersAlwaysOnTop value="true" />
     </navigator>
     <panes>
+      <pane id="Scope" />
       <pane id="ProjectPane">
         <subPane>
           <expand>
@@ -207,7 +244,6 @@
           <select />
         </subPane>
       </pane>
-      <pane id="Scope" />
     </panes>
   </component>
   <component name="PropertiesComponent">
@@ -255,14 +291,14 @@
     <servers />
   </component>
   <component name="TimeTrackingManager">
-    <option name="totallyTimeSpent" value="79672000" />
+    <option name="totallyTimeSpent" value="86593000" />
   </component>
   <component name="ToolWindowManager">
-    <frame x="380" y="0" width="2188" height="1408" extended-state="0" />
+    <frame x="651" y="0" width="1915" height="1407" extended-state="0" />
     <editor active="true" />
     <layout>
-      <window_info active="true" content_ui="combo" id="Project" order="0" sideWeight="0.4968652" visible="true" weight="0.18280075" />
-      <window_info id="Structure" order="1" sideWeight="0.5031348" side_tool="true" visible="true" weight="0.18280075" />
+      <window_info content_ui="combo" id="Project" order="0" sideWeight="0.4964706" visible="true" weight="0.21185984" />
+      <window_info active="true" id="Structure" order="1" sideWeight="0.5035294" side_tool="true" visible="true" weight="0.21185984" />
       <window_info id="Favorites" order="2" side_tool="true" weight="0.3298872" />
       <window_info anchor="bottom" id="Message" order="0" />
       <window_info anchor="bottom" id="Find" order="1" />
@@ -293,67 +329,95 @@
     </entry>
     <entry file="file://$PROJECT_DIR$/circularBuffer.cpp" />
     <entry file="file://$PROJECT_DIR$/circularBuffer.h" />
-    <entry file="file://$PROJECT_DIR$/can.h">
+    <entry file="file://$PROJECT_DIR$/buffer.h">
       <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="187">
-          <caret line="11" column="21" selection-start-line="11" selection-start-column="21" selection-end-line="11" selection-end-column="21" />
+        <state relative-caret-position="85">
+          <caret line="5" column="16" selection-start-line="5" selection-start-column="16" selection-end-line="5" selection-end-column="16" />
         </state>
       </provider>
     </entry>
-    <entry file="file://$PROJECT_DIR$/buffer.h">
+    <entry file="file://$PROJECT_DIR$/ecuCan.h">
       <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="459">
-          <caret line="27" column="9" selection-start-line="27" selection-start-column="9" selection-end-line="27" selection-end-column="9" />
+        <state relative-caret-position="357">
+          <caret line="21" selection-start-line="21" selection-end-line="21" />
         </state>
       </provider>
     </entry>
-    <entry file="file://$PROJECT_DIR$/can.cpp">
+    <entry file="file://$PROJECT_DIR$/openLoggerController.cpp">
       <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="32">
-          <caret line="210" column="30" selection-start-line="210" selection-start-column="30" selection-end-line="210" selection-end-column="30" />
+        <state relative-caret-position="683">
+          <caret line="55" lean-forward="true" selection-start-line="55" selection-end-line="55" />
+          <folding>
+            <element signature="e#40#73#0" expanded="true" />
+          </folding>
         </state>
       </provider>
     </entry>
-    <entry file="file://$PROJECT_DIR$/buffer.cpp">
+    <entry file="file://$PROJECT_DIR$/openLoggerController.h">
       <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="283">
-          <caret line="82" column="85" selection-start-line="82" selection-start-column="85" selection-end-line="82" selection-end-column="85" />
+        <state relative-caret-position="221">
+          <caret line="13" column="76" selection-start-line="13" selection-start-column="76" selection-end-line="13" selection-end-column="76" />
         </state>
       </provider>
     </entry>
-    <entry file="file://$PROJECT_DIR$/openLoggerController.cpp">
+    <entry file="file://$PROJECT_DIR$/can.cpp">
       <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="610">
-          <caret line="185" lean-forward="true" selection-start-line="185" selection-end-line="185" />
-          <folding>
-            <element signature="e#40#73#0" expanded="true" />
-            <element signature="e#2292#2367#0" expanded="true" />
-            <element signature="e#2559#2637#0" expanded="true" />
-            <element signature="e#2895#2973#0" expanded="true" />
-            <element signature="e#4435#4468#0" expanded="true" />
-            <element signature="e#4894#4935#0" expanded="true" />
-            <element signature="e#5052#5092#0" expanded="true" />
-            <element signature="e#5210#5251#0" expanded="true" />
-            <element signature="e#5773#5813#0" expanded="true" />
-            <element signature="e#5953#6000#0" expanded="true" />
-            <element signature="e#6138#6185#0" expanded="true" />
-            <element signature="e#6384#6509#0" expanded="true" />
-            <element signature="e#7073#7169#0" expanded="true" />
-          </folding>
+        <state relative-caret-position="306">
+          <caret line="18" lean-forward="true" selection-start-line="18" selection-end-line="18" />
         </state>
       </provider>
     </entry>
-    <entry file="file://$PROJECT_DIR$/openLoggerController.h">
+    <entry file="file://$PROJECT_DIR$/buffer.cpp">
+      <provider selected="true" editor-type-id="text-editor">
+        <state relative-caret-position="350">
+          <caret line="99" column="1" lean-forward="true" selection-start-line="99" selection-start-column="1" selection-end-line="99" selection-end-column="1" />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/can.h">
       <provider selected="true" editor-type-id="text-editor">
         <state relative-caret-position="221">
-          <caret line="13" column="76" selection-start-line="13" selection-start-column="76" selection-end-line="13" selection-end-column="76" />
+          <caret line="13" column="28" lean-forward="true" selection-start-line="13" selection-start-column="28" selection-end-line="13" selection-end-column="28" />
         </state>
       </provider>
     </entry>
     <entry file="file://$PROJECT_DIR$/sufst-openlogger_controller.ino">
       <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="613">
-          <caret line="375" column="27" selection-start-line="375" selection-start-column="27" selection-end-line="375" selection-end-column="27" />
+        <state relative-caret-position="629">
+          <caret line="56" lean-forward="true" selection-start-line="56" selection-end-line="56" />
+          <folding>
+            <element signature="e#57#90#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="715">
+          <caret line="59" lean-forward="true" selection-start-line="59" selection-end-line="59" />
+          <folding>
+            <element signature="e#39#58#0" expanded="true" />
+            <element signature="e#767#962#0" expanded="true" />
+            <element signature="e#1017#1048#0" expanded="true" />
+            <element signature="e#1415#1610#0" expanded="true" />
+            <element signature="e#1665#1696#0" expanded="true" />
+            <element signature="e#2008#2203#0" expanded="true" />
+            <element signature="e#2258#2289#0" expanded="true" />
+            <element signature="e#3273#3468#0" expanded="true" />
+            <element signature="e#3523#3554#0" expanded="true" />
+            <element signature="e#3914#4109#0" expanded="true" />
+            <element signature="e#4164#4195#0" expanded="true" />
+            <element signature="e#4492#4687#0" expanded="true" />
+            <element signature="e#4742#4773#0" expanded="true" />
+            <element signature="e#5086#5281#0" expanded="true" />
+            <element signature="e#5336#5367#0" expanded="true" />
+            <element signature="e#5683#5878#0" expanded="true" />
+            <element signature="e#5933#5964#0" expanded="true" />
+            <element signature="e#6301#6496#0" expanded="true" />
+            <element signature="e#6551#6582#0" expanded="true" />
+            <element signature="e#6899#7094#0" expanded="true" />
+            <element signature="e#7149#7180#0" expanded="true" />
+          </folding>
         </state>
       </provider>
     </entry>
diff --git a/sufst-openlogger_controller/buffer.cpp b/sufst-openlogger_controller/buffer.cpp
index b0a407f..6092547 100644
--- a/sufst-openlogger_controller/buffer.cpp
+++ b/sufst-openlogger_controller/buffer.cpp
@@ -121,7 +121,7 @@ void cirBufferRead(cirBuffer_handle cirBuff, void *loc)
 
 void *cirBufferPeek(cirBuffer_handle cirBuff)
 {
-    return (void *)(cirBuff->data[cirBuff->tail]);
+    return (void *) (cirBuff->data[cirBuff->tail]);
 }
 
 void cirBufferReadBytes(cirBuffer_handle cirBuff, void *loc, uint16_t len)
diff --git a/sufst-openlogger_controller/can.cpp b/sufst-openlogger_controller/can.cpp
index f3e1b3a..08097a4 100644
--- a/sufst-openlogger_controller/can.cpp
+++ b/sufst-openlogger_controller/can.cpp
@@ -9,6 +9,8 @@
 #include <mcp_can.h>
 #include <mcp_can_dfs.h>
 
+#include "ecuCan.h"
+
 // Can instance
 MCP_CAN can;
 
@@ -22,31 +24,29 @@ static CanMsgTemplate canTxBuffer[CAN_TX_BUFFER_LEN];
 
 volatile CirBuffer canTxCirBuffer;
 
-extern uint8_t ecuCanMsg0x2000(CanMsgTemplate *canMsg);
-
-extern uint8_t ecuCanMsg0x2001(CanMsgTemplate *canMsg);
+extern void ecuCanMsg0x2000(CanMsgTemplate *canMsg);
 
-extern uint8_t ecuCanMsg0x2002(CanMsgTemplate *canMsg);
+extern void ecuCanMsg0x2001(CanMsgTemplate *canMsg);
 
-extern uint8_t ecuCanMsg0x2003(CanMsgTemplate *canMsg);
+extern void ecuCanMsg0x2002(CanMsgTemplate *canMsg);
 
-extern uint8_t ecuCanMsg0x2004(CanMsgTemplate *canMsg);
+extern void ecuCanMsg0x2003(CanMsgTemplate *canMsg);
 
-extern uint8_t ecuCanMsg0x2005(CanMsgTemplate *canMsg);
+extern void ecuCanMsg0x2004(CanMsgTemplate *canMsg);
 
-extern uint8_t ecuCanMsg0x2006(CanMsgTemplate *canMsg);
+extern void ecuCanMsg0x2005(CanMsgTemplate *canMsg);
 
-extern uint8_t ecuCanMsg0x2007(CanMsgTemplate *canMsg);
+extern void ecuCanMsg0x2006(CanMsgTemplate *canMsg);
 
-extern uint8_t ecuCanMsg0x2008(CanMsgTemplate *canMsg);
+extern void ecuCanMsg0x2007(CanMsgTemplate *canMsg);
 
-extern uint8_t ecuCanMsg0x2009(CanMsgTemplate *canMsg);
+extern void ecuCanMsg0x2008(CanMsgTemplate *canMsg);
 
-uint8_t ecuAddToSdWriteRequest(CanMsgTemplate *canMsg);
+extern void ecuCanMsg0x2009(CanMsgTemplate *canMsg);
 
 // ECU can messages function pointers for calling the corresponding function when that msg is seen.
 // Used in function canParseRxMsg.
-uint8_t
+void
 (*ecuCanFuncPtrs[10])(CanMsgTemplate *) = {ecuCanMsg0x2000, ecuCanMsg0x2001,
                                            ecuCanMsg0x2002,
                                            ecuCanMsg0x2003,
@@ -92,6 +92,8 @@ uint8_t canSaveMsg()
 
     uid.id32 = can.getCanId();
 
+    canReceivedMsg.timestamp = millis();
+
     canReceivedMsg.id = (uid.id[1] << 8) | uid.id[0];
 
     cirBufferWrite(&canRxCirBuffer, &canReceivedMsg);
@@ -166,19 +168,17 @@ ISR(INT4_vect) {
     interrupts();
 }
 
-uint8_t canParseRxMsg(CanMsgTemplate *canMsg)
+void canParseRxMsg(CanMsgTemplate *canMsg)
 {
     if ((canMsg->id >= 0x2000) && (canMsg->id <= 0x200A)) {
         // canMsg->idByte[0] holds the 0x01 in 0x2001 received can msg
         // We use the sub byte of the can ecu msg to determine the corresonding function
         // This removes the need for a long if statement giving significant performance boosts
-        return (*ecuCanFuncPtrs[canMsg->idByte[0]])(canMsg);
+        (*ecuCanFuncPtrs[canMsg->idByte[0]])(canMsg);
     }
-
-    return 0;
 }
 
-uint8_t canProcessRx()
+void canProcessRx()
 {
     uint8_t retVal = 0;
 
@@ -210,7 +210,7 @@ uint8_t canProcessRx()
         Serial.println(canMsg.id, HEX);
 #endif // DEBUG_CAN_RX_MINIMAL
 
-        retVal = canParseRxMsg(&canMsg);
+        canParseRxMsg(&canMsg);
 
         // This may seem dumb but this allows any pending interrupts to be serviced safely
         // just before we start another loop. Otherwise if we stay in this loop too long without
@@ -219,8 +219,6 @@ uint8_t canProcessRx()
         noInterrupts();
     }
     interrupts();
-
-    return retVal;
 }
 
 uint8_t canProcessTx()
diff --git a/sufst-openlogger_controller/can.h b/sufst-openlogger_controller/can.h
index 3065f17..4fc862a 100644
--- a/sufst-openlogger_controller/can.h
+++ b/sufst-openlogger_controller/can.h
@@ -28,6 +28,8 @@
 
 typedef struct CanMsgTemplate
 {
+    uint32_t timestamp;
+
     union
     {
         uint16_t id;
@@ -35,6 +37,7 @@ typedef struct CanMsgTemplate
         // due to the endianness of the system
         uint8_t idByte[2];
     };
+
     uint8_t len;
 
     union
@@ -55,9 +58,9 @@ uint8_t canAddTxRequest(uint16_t id, void *data, uint8_t lenBytes);
 
 void canBeginExtInterrupt();
 
-uint8_t canParseRxMsg(CanMsgTemplate *canMsg);
+void canParseRxMsg(CanMsgTemplate *canMsg);
 
-uint8_t canProcessRx();
+void canProcessRx();
 
 uint8_t canProcessTx();
 
diff --git a/sufst-openlogger_controller/ecuCan.cpp b/sufst-openlogger_controller/ecuCan.cpp
new file mode 100644
index 0000000..513a4e9
--- /dev/null
+++ b/sufst-openlogger_controller/ecuCan.cpp
@@ -0,0 +1,263 @@
+//
+// Created by Sil on 7/21/2019.
+//
+
+#include "ecuCan.h"
+#include "openLoggerController.h"
+
+struct EcuDataOpenlogger
+{
+    uint8_t startTag;
+    uint32_t timestamp;
+    uint16_t data;
+    uint8_t endTag;
+};
+
+void ecuOpenloggerWrite(EcuDataOpenlogger &ecuDataOpenlogger);
+
+void ecuOpenloggerWrite(EcuDataOpenlogger &ecuDataOpenlogger)
+{
+    static uint8_t openloggerPayload[8];
+
+    memcpy(openloggerPayload, &(ecuDataOpenlogger.startTag), 1);
+
+    memcpy(&(openloggerPayload[1]), &(ecuDataOpenlogger.timestamp), 4);
+
+    memcpy(&(openloggerPayload[5]), &(ecuDataOpenlogger.data), 2);
+
+    memcpy(&(openloggerPayload[7]), &(ecuDataOpenlogger.endTag), 1);
+
+    openloggerWrite(openloggerPayload, 8);
+}
+
+void ecuCanMsg0x2000(CanMsgTemplate *canMsg)
+{
+#if DEBUG_ECU_CAN
+    Serial.print("ECU : 0x2000 : ");
+    for (uint8_t i = 0; i < 3; i++) {
+        Serial.print(canMsg->data16[i], HEX);
+        Serial.print(" , ");
+    }
+    Serial.println(canMsg->data16[3], HEX);
+#endif //DEBUG_ECU_CAN
+
+#if DEBUG_ECU_CAN_MINIMAL
+    Serial.println("ECU : 0x2000");
+#endif //DEBUG_ECU_CAN_MINIMAL
+
+    uint16_t rpm = canMsg->data16[0];
+    uint16_t tpsPerc = canMsg->data16[1];
+    uint16_t waterTempC = canMsg->data16[2];
+    uint16_t airTempC = canMsg->data16[3];
+
+    static EcuDataOpenlogger tpsPercOpenlogger;
+    static EcuDataOpenlogger rpmOpenlogger;
+
+    rpmOpenlogger.startTag = 1;
+    rpmOpenlogger.timestamp = canMsg->timestamp;
+    rpmOpenlogger.data = rpm;
+    rpmOpenlogger.endTag = 1;
+
+    ecuOpenloggerWrite(tpsPercOpenlogger);
+
+    tpsPercOpenlogger.startTag = 2;
+    tpsPercOpenlogger.timestamp = canMsg->timestamp;
+    tpsPercOpenlogger.data = tpsPerc;
+    tpsPercOpenlogger.endTag = 2;
+
+    ecuOpenloggerWrite(rpmOpenlogger);
+}
+
+void ecuCanMsg0x2001(CanMsgTemplate *canMsg)
+{
+#if DEBUG_ECU_CAN
+    Serial.print("ECU : 0x2001 : ");
+    for (uint8_t i = 0; i < 3; i++) {
+        Serial.print(canMsg->data16[i], HEX);
+        Serial.print(" , ");
+    }
+    Serial.println(canMsg->data16[3], HEX);
+#endif //DEBUG_ECU_CAN
+
+#if DEBUG_ECU_CAN_MINIMAL
+    Serial.println("ECU : 0x2001");
+#endif //DEBUG_ECU_CAN_MINIMAL
+
+    uint16_t mainifoldPresKpa = canMsg->data16[0];
+    uint16_t lambdax1000 = canMsg->data16[1];
+    uint16_t speedKphx10 = canMsg->data16[2];
+    uint16_t oilPressKpa = canMsg->data16[3];
+
+}
+
+void ecuCanMsg0x2002(CanMsgTemplate *canMsg)
+{
+#if DEBUG_ECU_CAN
+    Serial.print("ECU : 0x2002 : ");
+    for (uint8_t i = 0; i < 3; i++) {
+        Serial.print(canMsg->data16[i], HEX);
+        Serial.print(" , ");
+    }
+    Serial.println(canMsg->data16[3], HEX);
+#endif //DEBUG_ECU_CAN
+
+#if DEBUG_ECU_CAN_MINIMAL
+    Serial.println("ECU : 0x2002");
+#endif //DEBUG_ECU_CAN_MINIMAL
+
+    uint16_t fuelPressKpa = canMsg->data16[0];
+    uint16_t oilTempC = canMsg->data16[1];
+    uint16_t batteryVx10 = canMsg->data16[2];
+    uint16_t fuelComsumLpHrx10 = canMsg->data16[3];
+
+    // Serial.println((float)(batteryVx10 / 10.0));
+
+}
+
+void ecuCanMsg0x2003(CanMsgTemplate *canMsg)
+{
+#if DEBUG_ECU_CAN
+    Serial.print("ECU : 0x2003 : ");
+    for (uint8_t i = 0; i < 3; i++) {
+        Serial.print(canMsg->data16[i], HEX);
+        Serial.print(" , ");
+    }
+    Serial.println(canMsg->data16[3], HEX);
+#endif //DEBUG_ECU_CAN
+
+#if DEBUG_ECU_CAN_MINIMAL
+    Serial.println("ECU : 0x2003");
+#endif //DEBUG_ECU_CAN_MINIMAL
+
+    uint16_t currentGear = canMsg->data16[0];
+    uint16_t advanceDegx10 = canMsg->data16[1];
+    uint16_t injectionTimeMsx100 = canMsg->data16[2];
+    uint16_t fuelComsumLp100kMx10 = canMsg->data16[3];
+
+    Serial.println(currentGear);
+}
+
+void ecuCanMsg0x2004(CanMsgTemplate *canMsg)
+{
+#if DEBUG_ECU_CAN
+    Serial.print("ECU : 0x2004 : ");
+    for (uint8_t i = 0; i < 3; i++) {
+        Serial.print(canMsg->data16[i], HEX);
+        Serial.print(" , ");
+    }
+    Serial.println(canMsg->data16[3], HEX);
+#endif //DEBUG_ECU_CAN
+
+#if DEBUG_ECU_CAN_MINIMAL
+    Serial.println("ECU : 0x2004");
+#endif //DEBUG_ECU_CAN_MINIMAL
+
+    uint16_t ana1mV = canMsg->data16[0];
+    uint16_t ana2mV = canMsg->data16[1];
+    uint16_t ana3mV = canMsg->data16[2];
+    uint16_t camAdvanceDegx10 = canMsg->data16[3];
+}
+
+void ecuCanMsg0x2005(CanMsgTemplate *canMsg)
+{
+#if DEBUG_ECU_CAN
+    Serial.print("ECU : 0x2005 : ");
+    for (uint8_t i = 0; i < 3; i++) {
+        Serial.print(canMsg->data16[i], HEX);
+        Serial.print(" , ");
+    }
+    Serial.println(canMsg->data16[3], HEX);
+#endif //DEBUG_ECU_CAN
+
+#if DEBUG_ECU_CAN_MINIMAL
+    Serial.println("ECU : 0x2005");
+#endif //DEBUG_ECU_CAN_MINIMAL
+
+    uint16_t camTargDegx10 = canMsg->data16[0];
+    uint16_t camPwmPercx10 = canMsg->data16[1];
+    uint16_t crankErrorsNr = canMsg->data16[2];
+    uint16_t camErrorsNr = canMsg->data16[3];
+}
+
+void ecuCanMsg0x2006(CanMsgTemplate *canMsg)
+{
+#if DEBUG_ECU_CAN
+    Serial.print("ECU : 0x2006 : ");
+    for (uint8_t i = 0; i < 3; i++) {
+        Serial.print(canMsg->data16[i], HEX);
+        Serial.print(" , ");
+    }
+    Serial.println(canMsg->data16[3], HEX);
+#endif //DEBUG_ECU_CAN
+
+#if DEBUG_ECU_CAN_MINIMAL
+    Serial.println("ECU : 0x2006");
+#endif //DEBUG_ECU_CAN_MINIMAL
+
+    uint16_t cam2AdvDegx10 = canMsg->data16[0];
+    uint16_t cam2TargDegx10 = canMsg->data16[1];
+    uint16_t cam2PwmPercx10 = canMsg->data16[2];
+    uint16_t external5VmV = canMsg->data16[3];
+
+}
+
+void ecuCanMsg0x2007(CanMsgTemplate *canMsg)
+{
+#if DEBUG_ECU_CAN
+    Serial.print("ECU : 0x2007 : ");
+    for (uint8_t i = 0; i < 3; i++) {
+        Serial.print(canMsg->data16[i], HEX);
+        Serial.print(" , ");
+    }
+    Serial.println(canMsg->data16[3], HEX);
+#endif //DEBUG_ECU_CAN
+
+#if DEBUG_ECU_CAN_MINIMAL
+    Serial.println("ECU : 0x2007");
+#endif //DEBUG_ECU_CAN_MINIMAL
+
+    uint16_t injDutyCyclePerc = canMsg->data16[0];
+    uint16_t lambdaPidTargPercx10 = canMsg->data16[1];
+    uint16_t lambdaPidAdjPercx10 = canMsg->data16[2];
+    uint16_t ecuSwitchesBitField = canMsg->data16[3];
+}
+
+void ecuCanMsg0x2008(CanMsgTemplate *canMsg)
+{
+#if DEBUG_ECU_CAN
+    Serial.print("ECU : 0x2008 : ");
+    for (uint8_t i = 0; i < 3; i++) {
+        Serial.print(canMsg->data16[i], HEX);
+        Serial.print(" , ");
+    }
+    Serial.println(canMsg->data16[3], HEX);
+#endif //DEBUG_ECU_CAN
+
+#if DEBUG_ECU_CAN_MINIMAL
+    Serial.println("ECU : 0x2008");
+#endif //DEBUG_ECU_CAN_MINIMAL
+
+    uint16_t rdSpeedKphx10 = canMsg->data16[0];
+    uint16_t rUdSpeedKphx10 = canMsg->data16[1];
+    uint16_t ldSpeedKphx10 = canMsg->data16[2];
+    uint16_t lUdSpeedKphx10 = canMsg->data16[3];
+
+}
+
+void ecuCanMsg0x2009(CanMsgTemplate *canMsg)
+{
+#if DEBUG_ECU_CAN
+    Serial.print("ECU : 0x2009 : ");
+    for (uint8_t i = 0; i < 3; i++) {
+        Serial.print(canMsg->data16[i], HEX);
+        Serial.print(" , ");
+    }
+    Serial.println(canMsg->data16[3], HEX);
+#endif //DEBUG_ECU_CAN
+
+#if DEBUG_ECU_CAN_MINIMAL
+    Serial.println("ECU : 0x2008");
+#endif //DEBUG_ECU_CAN_MINIMAL
+
+    //uint16_t rightLambdax1000 = canMsg->data16[0];
+}
\ No newline at end of file
diff --git a/sufst-openlogger_controller/ecuCan.h b/sufst-openlogger_controller/ecuCan.h
new file mode 100644
index 0000000..3e0f985
--- /dev/null
+++ b/sufst-openlogger_controller/ecuCan.h
@@ -0,0 +1,38 @@
+//
+// Created by Sil on 7/21/2019.
+//
+
+#ifndef ECUCAN_H
+#define ECUCAN_H
+
+#include "Arduino.h"
+#include "can.h"
+
+/*
+ * These are called from can.cpp when their corresponding can msg id is seen.
+ * So functions name *must* ecuCanMsg0x200N.
+ *
+ */
+
+void ecuCanMsg0x2000(CanMsgTemplate *canMsg);
+
+void ecuCanMsg0x2001(CanMsgTemplate *canMsg);
+
+void ecuCanMsg0x2002(CanMsgTemplate *canMsg);
+
+void ecuCanMsg0x2003(CanMsgTemplate *canMsg);
+
+void ecuCanMsg0x2004(CanMsgTemplate *canMsg);
+
+void ecuCanMsg0x2005(CanMsgTemplate *canMsg);
+
+void ecuCanMsg0x2006(CanMsgTemplate *canMsg);
+
+void ecuCanMsg0x2007(CanMsgTemplate *canMsg);
+
+void ecuCanMsg0x2008(CanMsgTemplate *canMsg);
+
+void ecuCanMsg0x2009(CanMsgTemplate *canMsg);
+
+
+#endif //ECUCAN_H
diff --git a/sufst-openlogger_controller/sufst-openlogger_controller.ino b/sufst-openlogger_controller/sufst-openlogger_controller.ino
index 087e4a4..b4ae202 100644
--- a/sufst-openlogger_controller/sufst-openlogger_controller.ino
+++ b/sufst-openlogger_controller/sufst-openlogger_controller.ino
@@ -2,331 +2,16 @@
 #define DEBUG_ECU_CAN_MINIMAL 0
 
 #include "openLoggerController.h"
+#include "ecuCan.h"
 #include "can.h"
 
 // Watchdog
 #include <avr/wdt.h>
 
-
 #define OPENLOGGER_SERIAL_BUAD_RATE 115200
 
 uint8_t arduinoProcessSerial();
 
-/*
- * These are called from can.cpp when their corresponding can msg id is seen.
- * So functions name *must* ecuCanMsg0x200N.
- *
- */
-
-uint8_t ecuCanMsg0x2000(CanMsgTemplate *canMsg);
-
-uint8_t ecuCanMsg0x2001(CanMsgTemplate *canMsg);
-
-uint8_t ecuCanMsg0x2002(CanMsgTemplate *canMsg);
-
-uint8_t ecuCanMsg0x2003(CanMsgTemplate *canMsg);
-
-uint8_t ecuCanMsg0x2004(CanMsgTemplate *canMsg);
-
-uint8_t ecuCanMsg0x2005(CanMsgTemplate *canMsg);
-
-uint8_t ecuCanMsg0x2006(CanMsgTemplate *canMsg);
-
-uint8_t ecuCanMsg0x2007(CanMsgTemplate *canMsg);
-
-uint8_t ecuCanMsg0x2008(CanMsgTemplate *canMsg);
-
-uint8_t ecuCanMsg0x2009(CanMsgTemplate *canMsg);
-
-uint8_t ecuOpenloggerWrite(CanMsgTemplate *canMsg)
-{
-
-    uint8_t ecuOpenloggerRequest[10];
-
-    memcpy(ecuOpenloggerRequest, &(canMsg->len), 2);
-
-    memcpy(&(ecuOpenloggerRequest[2]), &(canMsg->data), canMsg->len);
-
-    openloggerWrite(&ecuOpenloggerRequest, 10);
-
-    return 1;
-}
-
-uint8_t ecuCanMsg0x2000(CanMsgTemplate *canMsg)
-{
-#if DEBUG_ECU_CAN
-    Serial.print("ECU : 0x2000 : ");
-    for (uint8_t i = 0; i < 3; i++) {
-        Serial.print(canMsg->data16[i], HEX);
-        Serial.print(" , ");
-    }
-    Serial.println(canMsg->data16[3], HEX);
-#endif //DEBUG_ECU_CAN
-
-#if DEBUG_ECU_CAN_MINIMAL
-    Serial.println("ECU : 0x2000");
-#endif //DEBUG_ECU_CAN_MINIMAL
-
-    uint16_t rpm = canMsg->data16[0];
-#if RPM_LEDS_ENABLED
-    g_RPM = rpm;
-#endif
-
-    uint16_t tpsPerc = canMsg->data16[1];
-    uint16_t waterTempC = canMsg->data16[2];
-    uint16_t airTempC = canMsg->data16[3];
-
-    Serial.println(tpsPerc);
-
-#if SD_ENABLED
-    ecuAddToSdWriteRequest(canMsg);
-#endif // SD_ENABLED
-
-    return 1;
-}
-
-uint8_t ecuCanMsg0x2001(CanMsgTemplate *canMsg)
-{
-#if DEBUG_ECU_CAN
-    Serial.print("ECU : 0x2001 : ");
-    for (uint8_t i = 0; i < 3; i++) {
-        Serial.print(canMsg->data16[i], HEX);
-        Serial.print(" , ");
-    }
-    Serial.println(canMsg->data16[3], HEX);
-#endif //DEBUG_ECU_CAN
-
-#if DEBUG_ECU_CAN_MINIMAL
-    Serial.println("ECU : 0x2001");
-#endif //DEBUG_ECU_CAN_MINIMAL
-
-    uint16_t mainifoldPresKpa = canMsg->data16[0];
-    uint16_t lambdax1000 = canMsg->data16[1];
-    uint16_t speedKphx10 = canMsg->data16[2];
-    uint16_t oilPressKpa = canMsg->data16[3];
-
-#if SD_ENABLED
-    ecuAddToSdWriteRequest(canMsg);
-#endif // SD_ENABLED
-
-    return 1;
-}
-
-uint8_t ecuCanMsg0x2002(CanMsgTemplate *canMsg)
-{
-#if DEBUG_ECU_CAN
-    Serial.print("ECU : 0x2002 : ");
-    for (uint8_t i = 0; i < 3; i++) {
-        Serial.print(canMsg->data16[i], HEX);
-        Serial.print(" , ");
-    }
-    Serial.println(canMsg->data16[3], HEX);
-#endif //DEBUG_ECU_CAN
-
-#if DEBUG_ECU_CAN_MINIMAL
-    Serial.println("ECU : 0x2002");
-#endif //DEBUG_ECU_CAN_MINIMAL
-
-    uint16_t fuelPressKpa = canMsg->data16[0];
-    uint16_t oilTempC = canMsg->data16[1];
-    uint16_t batteryVx10 = canMsg->data16[2];
-    uint16_t fuelComsumLpHrx10 = canMsg->data16[3];
-
-
-    // Serial.println((float)(batteryVx10 / 10.0));
-
-#if SD_ENABLED
-    ecuAddToSdWriteRequest(canMsg);
-#endif // SD_ENABLED
-
-    return 1;
-}
-
-uint8_t ecuCanMsg0x2003(CanMsgTemplate *canMsg)
-{
-#if DEBUG_ECU_CAN
-    Serial.print("ECU : 0x2003 : ");
-    for (uint8_t i = 0; i < 3; i++) {
-        Serial.print(canMsg->data16[i], HEX);
-        Serial.print(" , ");
-    }
-    Serial.println(canMsg->data16[3], HEX);
-#endif //DEBUG_ECU_CAN
-
-#if DEBUG_ECU_CAN_MINIMAL
-    Serial.println("ECU : 0x2003");
-#endif //DEBUG_ECU_CAN_MINIMAL
-
-    uint16_t currentGear = canMsg->data16[0];
-    uint16_t advanceDegx10 = canMsg->data16[1];
-    uint16_t injectionTimeMsx100 = canMsg->data16[2];
-    uint16_t fuelComsumLp100kMx10 = canMsg->data16[3];
-
-    Serial.println(currentGear);
-
-#if SD_ENABLED
-    ecuAddToSdWriteRequest(canMsg);
-#endif // SD_ENABLED
-
-    return 1;
-}
-
-uint8_t ecuCanMsg0x2004(CanMsgTemplate *canMsg)
-{
-#if DEBUG_ECU_CAN
-    Serial.print("ECU : 0x2004 : ");
-    for (uint8_t i = 0; i < 3; i++) {
-        Serial.print(canMsg->data16[i], HEX);
-        Serial.print(" , ");
-    }
-    Serial.println(canMsg->data16[3], HEX);
-#endif //DEBUG_ECU_CAN
-
-#if DEBUG_ECU_CAN_MINIMAL
-    Serial.println("ECU : 0x2004");
-#endif //DEBUG_ECU_CAN_MINIMAL
-
-    uint16_t ana1mV = canMsg->data16[0];
-    uint16_t ana2mV = canMsg->data16[1];
-    uint16_t ana3mV = canMsg->data16[2];
-    uint16_t camAdvanceDegx10 = canMsg->data16[3];
-
-#if SD_ENABLED
-    ecuAddToSdWriteRequest(canMsg);
-#endif // SD_ENABLED
-
-    return 1;
-}
-
-uint8_t ecuCanMsg0x2005(CanMsgTemplate *canMsg)
-{
-#if DEBUG_ECU_CAN
-    Serial.print("ECU : 0x2005 : ");
-    for (uint8_t i = 0; i < 3; i++) {
-        Serial.print(canMsg->data16[i], HEX);
-        Serial.print(" , ");
-    }
-    Serial.println(canMsg->data16[3], HEX);
-#endif //DEBUG_ECU_CAN
-
-#if DEBUG_ECU_CAN_MINIMAL
-    Serial.println("ECU : 0x2005");
-#endif //DEBUG_ECU_CAN_MINIMAL
-
-    uint16_t camTargDegx10 = canMsg->data16[0];
-    uint16_t camPwmPercx10 = canMsg->data16[1];
-    uint16_t crankErrorsNr = canMsg->data16[2];
-    uint16_t camErrorsNr = canMsg->data16[3];
-
-#if SD_ENABLED
-    ecuAddToSdWriteRequest(canMsg);
-#endif // SD_ENABLED
-
-    return 1;
-}
-
-uint8_t ecuCanMsg0x2006(CanMsgTemplate *canMsg)
-{
-#if DEBUG_ECU_CAN
-    Serial.print("ECU : 0x2006 : ");
-    for (uint8_t i = 0; i < 3; i++) {
-        Serial.print(canMsg->data16[i], HEX);
-        Serial.print(" , ");
-    }
-    Serial.println(canMsg->data16[3], HEX);
-#endif //DEBUG_ECU_CAN
-
-#if DEBUG_ECU_CAN_MINIMAL
-    Serial.println("ECU : 0x2006");
-#endif //DEBUG_ECU_CAN_MINIMAL
-
-    uint16_t cam2AdvDegx10 = canMsg->data16[0];
-    uint16_t cam2TargDegx10 = canMsg->data16[1];
-    uint16_t cam2PwmPercx10 = canMsg->data16[2];
-    uint16_t external5VmV = canMsg->data16[3];
-
-#if SD_ENABLED
-    ecuAddToSdWriteRequest(canMsg);
-#endif // SD_ENABLED
-
-
-    return 1;
-}
-
-uint8_t ecuCanMsg0x2007(CanMsgTemplate *canMsg)
-{
-#if DEBUG_ECU_CAN
-    Serial.print("ECU : 0x2007 : ");
-    for (uint8_t i = 0; i < 3; i++) {
-        Serial.print(canMsg->data16[i], HEX);
-        Serial.print(" , ");
-    }
-    Serial.println(canMsg->data16[3], HEX);
-#endif //DEBUG_ECU_CAN
-
-#if DEBUG_ECU_CAN_MINIMAL
-    Serial.println("ECU : 0x2007");
-#endif //DEBUG_ECU_CAN_MINIMAL
-
-    uint16_t injDutyCyclePerc = canMsg->data16[0];
-    uint16_t lambdaPidTargPercx10 = canMsg->data16[1];
-    uint16_t lambdaPidAdjPercx10 = canMsg->data16[2];
-    uint16_t ecuSwitchesBitField = canMsg->data16[3];
-
-#if SD_ENABLED
-    ecuAddToSdWriteRequest(canMsg);
-#endif // SD_ENABLED
-
-    return 1;
-}
-
-uint8_t ecuCanMsg0x2008(CanMsgTemplate *canMsg)
-{
-#if DEBUG_ECU_CAN
-    Serial.print("ECU : 0x2008 : ");
-    for (uint8_t i = 0; i < 3; i++) {
-        Serial.print(canMsg->data16[i], HEX);
-        Serial.print(" , ");
-    }
-    Serial.println(canMsg->data16[3], HEX);
-#endif //DEBUG_ECU_CAN
-
-#if DEBUG_ECU_CAN_MINIMAL
-    Serial.println("ECU : 0x2008");
-#endif //DEBUG_ECU_CAN_MINIMAL
-
-    uint16_t rdSpeedKphx10 = canMsg->data16[0];
-    uint16_t rUdSpeedKphx10 = canMsg->data16[1];
-    uint16_t ldSpeedKphx10 = canMsg->data16[2];
-    uint16_t lUdSpeedKphx10 = canMsg->data16[3];
-
-#if SD_ENABLED
-    ecuAddToSdWriteRequest(canMsg);
-#endif // SD_ENABLED
-
-    return 1;
-}
-
-uint8_t ecuCanMsg0x2009(CanMsgTemplate *canMsg)
-{
-#if DEBUG_ECU_CAN
-    Serial.print("ECU : 0x2009 : ");
-    for (uint8_t i = 0; i < 3; i++) {
-        Serial.print(canMsg->data16[i], HEX);
-        Serial.print(" , ");
-    }
-    Serial.println(canMsg->data16[3], HEX);
-#endif //DEBUG_ECU_CAN
-
-#if DEBUG_ECU_CAN_MINIMAL
-    Serial.println("ECU : 0x2008");
-#endif //DEBUG_ECU_CAN_MINIMAL
-
-    //uint16_t rightLambdax1000 = canMsg->data16[0];
-
-    return 1;
-}
-
 void setup()
 {
     // put your setup code here, to run once:
@@ -350,30 +35,27 @@ void loop()
     /*
    * ALL PROCESSES *MUST* BE NON BLOCKING
    */
-
-    static uint8_t payload[120] = {0};
-
     unsigned long currMs = millis();
 
     static unsigned long lastSdWriteMs = millis();
 
-    static uint8_t cnt = 0;
+    static uint16_t cnt = 0;
 
-    payload[0] = cnt;
-    payload[20] = cnt;
-    payload[40] = cnt;
-    payload[60] = cnt;
-    payload[80] = cnt;
-    payload[100] = cnt;
+    static CanMsgTemplate emulateCanMsg;
+
+    emulateCanMsg.id = 0x2002;
+
+    emulateCanMsg.len = 8;
+    emulateCanMsg.data16[2] = 123;
+    emulateCanMsg.data16[3] = 555;
 
     if ((currMs - lastSdWriteMs) >= 20) {
 
-        openloggerWrite(payload, 20);
-        payload[0] = ++cnt;
-        openloggerWrite(payload, 20);
-        payload[0] = ++cnt;
-        openloggerWrite(payload, 20);
-        payload[0] = ++cnt;
+        emulateCanMsg.timestamp = millis();
+        emulateCanMsg.data16[0] = cnt++;
+        emulateCanMsg.data16[1] = cnt++;
+
+        ecuCanMsg0x2000(&emulateCanMsg);
 
         lastSdWriteMs = millis();
     }
-- 
GitLab