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

MUCH better working and faster data logging with pure function pointers and state machines

parent ec6317f9
No related branches found
No related tags found
No related merge requests found
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>
\ No newline at end of file
...@@ -10,16 +10,13 @@ ...@@ -10,16 +10,13 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="81322c4e-6adb-4223-9d00-22249012da89" name="Default Changelist" comment=""> <list default="true" id="81322c4e-6adb-4223-9d00-22249012da89" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/circularBuffer.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/circularBuffer.cpp" afterDir="false" /> <change afterPath="$PROJECT_DIR$/.idea/codeStyles/codeStyleConfig.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/circularBuffer.h" beforeDir="false" afterPath="$PROJECT_DIR$/circularBuffer.h" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/circularBuffer.cpp" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/circularBuffer.h" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/openLogger.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/openLogger.cpp" afterDir="false" /> <change beforePath="$PROJECT_DIR$/openLogger.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/openLogger.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/openLogger.h" beforeDir="false" afterPath="$PROJECT_DIR$/openLogger.h" afterDir="false" /> <change beforePath="$PROJECT_DIR$/openLogger.h" beforeDir="false" afterPath="$PROJECT_DIR$/openLogger.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sufst-openlogger_controller/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../sufst-openlogger_controller/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../sufst-openlogger_controller/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../sufst-openlogger_controller/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sufst-openlogger_controller/can.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/../sufst-openlogger_controller/can.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sufst-openlogger_controller/circularBuffer.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/../sufst-openlogger_controller/circularBuffer.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sufst-openlogger_controller/circularBuffer.h" beforeDir="false" afterPath="$PROJECT_DIR$/../sufst-openlogger_controller/circularBuffer.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sufst-openlogger_controller/openLoggerController.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/../sufst-openlogger_controller/openLoggerController.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sufst-openlogger_controller/openLoggerController.h" beforeDir="false" afterPath="$PROJECT_DIR$/../sufst-openlogger_controller/openLoggerController.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sufst-openlogger_controller/sufst-openlogger_controller.ino" beforeDir="false" afterPath="$PROJECT_DIR$/../sufst-openlogger_controller/sufst-openlogger_controller.ino" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../sufst-openlogger_controller/sufst-openlogger_controller.ino" beforeDir="false" afterPath="$PROJECT_DIR$/../sufst-openlogger_controller/sufst-openlogger_controller.ino" afterDir="false" />
</list> </list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
...@@ -40,46 +37,33 @@ ...@@ -40,46 +37,33 @@
<entry file="file://$PROJECT_DIR$/sufst-openlogger.ino"> <entry file="file://$PROJECT_DIR$/sufst-openlogger.ino">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="187"> <state relative-caret-position="187">
<caret line="11" lean-forward="true" selection-start-line="11" selection-end-line="11" /> <caret line="11" selection-start-line="11" selection-end-line="11" />
</state> </state>
</provider> </provider>
</entry> </entry>
</file> </file>
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/openLogger.cpp"> <entry file="file://$PROJECT_DIR$/openLogger.cpp">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-34"> <state relative-caret-position="340">
<caret line="109" lean-forward="true" selection-start-line="109" selection-end-line="109" /> <caret line="260" column="1" lean-forward="true" selection-start-line="260" selection-start-column="1" selection-end-line="260" selection-end-column="1" />
<folding> <folding>
<element signature="e#8677#8871#0" expanded="true" /> <element signature="e#4547#4623#0" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>
</entry> </entry>
</file> </file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/openLogger.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="238">
<caret line="14" column="50" lean-forward="true" selection-start-line="14" selection-start-column="50" selection-end-line="14" selection-end-column="50" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/circularBuffer.cpp"> <entry file="file://$PROJECT_DIR$/openLogger.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-680">
<caret line="50" column="17" lean-forward="true" selection-start-line="50" selection-start-column="17" selection-end-line="50" selection-end-column="17" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/circularBuffer.h">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="459"> <state relative-caret-position="-357">
<caret line="27" column="63" selection-start-line="27" selection-start-column="63" selection-end-line="27" selection-end-column="63" /> <caret line="24" selection-start-line="24" selection-end-line="24" />
<folding>
<element signature="e#758#862#0" expanded="true" />
<element signature="e#1008#1095#0" expanded="true" />
<element signature="e#1506#1864#0" expanded="true" />
</folding>
</state> </state>
</provider> </provider>
</entry> </entry>
...@@ -109,6 +93,10 @@ ...@@ -109,6 +93,10 @@
<find>openloggerWriteBufferBlocks</find> <find>openloggerWriteBufferBlocks</find>
<find>cir</find> <find>cir</find>
<find>fast</find> <find>fast</find>
<find>start</find>
<find>begin</find>
<find>close</find>
<find>openloggerBeginSd</find>
</findStrings> </findStrings>
<replaceStrings> <replaceStrings>
<replace>DEBUG_OPENLOGGER</replace> <replace>DEBUG_OPENLOGGER</replace>
...@@ -123,26 +111,15 @@ ...@@ -123,26 +111,15 @@
<list> <list>
<option value="$PROJECT_DIR$/circularBuffer.h" /> <option value="$PROJECT_DIR$/circularBuffer.h" />
<option value="$PROJECT_DIR$/circularBuffer.cpp" /> <option value="$PROJECT_DIR$/circularBuffer.cpp" />
<option value="$PROJECT_DIR$/openLogger.cpp" />
<option value="$PROJECT_DIR$/openLogger.h" /> <option value="$PROJECT_DIR$/openLogger.h" />
<option value="$PROJECT_DIR$/openLogger.cpp" />
</list> </list>
</option> </option>
</component> </component>
<component name="OCFindUsagesOptions" text="true" ivars="false" properties="true" derivedClasses="false" /> <component name="OCFindUsagesOptions" text="true" ivars="false" properties="true" derivedClasses="false" />
<component name="ProjectConfigurationFiles">
<option name="files">
<list>
<option value="$PROJECT_DIR$/.idea/sufst-openlogger.iml" />
<option value="$PROJECT_DIR$/.idea/misc.xml" />
<option value="$PROJECT_DIR$/.idea/vcs.xml" />
<option value="$PROJECT_DIR$/.idea/modules.xml" />
<option value="$PROJECT_DIR$/../sufst-openlogger_controller/.idea/sufst-openlogger_controller.iml" />
</list>
</option>
</component>
<component name="ProjectFrameBounds"> <component name="ProjectFrameBounds">
<option name="x" value="476" /> <option name="x" value="501" />
<option name="width" value="1453" /> <option name="width" value="1428" />
<option name="height" value="1038" /> <option name="height" value="1038" />
</component> </component>
<component name="ProjectLevelVcsManager" settingsEditedManually="true" /> <component name="ProjectLevelVcsManager" settingsEditedManually="true" />
...@@ -150,31 +127,22 @@ ...@@ -150,31 +127,22 @@
<navigator proportions="" version="1"> <navigator proportions="" version="1">
<foldersAlwaysOnTop value="true" /> <foldersAlwaysOnTop value="true" />
</navigator> </navigator>
<panes> <panes />
<pane id="ProjectPane">
<subPane>
<expand>
<path>
<item name="sufst-openlogger" type="b2602c69:ProjectViewProjectNode" />
<item name="sufst-openlogger" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
</pane>
<pane id="Scope" />
</panes>
</component> </component>
<component name="PropertiesComponent"> <component name="PropertiesComponent">
<property name="ASKED_SHARE_PROJECT_CONFIGURATION_FILES" value="true" /> <property name="ASKED_SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" /> <property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" /> <property name="WebServerToolWindowFactoryState" value="false" />
<property name="node.js.detected.package.eslint" value="true" /> <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.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.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_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" /> <property name="nodejs_npm_path_reset_for_default_project" value="true" />
<property name="nodejs_package_manager_path" value="npm" /> <property name="nodejs_package_manager_path" value="npm" />
<property name="settings.editor.selected.configurable" value="preferences.sourceCode.C/C++" />
</component> </component>
<component name="RunDashboard"> <component name="RunDashboard">
<option name="ruleStates"> <option name="ruleStates">
...@@ -200,18 +168,19 @@ ...@@ -200,18 +168,19 @@
<updated>1563140776084</updated> <updated>1563140776084</updated>
<workItem from="1563140777259" duration="246000" /> <workItem from="1563140777259" duration="246000" />
<workItem from="1563216461708" duration="10620000" /> <workItem from="1563216461708" duration="10620000" />
<workItem from="1563385421018" duration="9848000" />
</task> </task>
<servers /> <servers />
</component> </component>
<component name="TimeTrackingManager"> <component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="33190000" /> <option name="totallyTimeSpent" value="43419000" />
</component> </component>
<component name="ToolWindowManager"> <component name="ToolWindowManager">
<frame x="381" y="0" width="1162" height="830" extended-state="0" /> <frame x="401" y="0" width="1142" height="830" extended-state="0" />
<editor active="true" /> <editor active="true" />
<layout> <layout>
<window_info content_ui="combo" id="Project" order="0" sideWeight="0.49856734" weight="0.522686" /> <window_info content_ui="combo" id="Project" order="0" sideWeight="0.49856734" weight="0.522686" />
<window_info active="true" id="Structure" order="1" sideWeight="0.50143266" side_tool="true" visible="true" weight="0.24954627" /> <window_info active="true" id="Structure" order="1" sideWeight="0.50143266" side_tool="true" visible="true" weight="0.25878003" />
<window_info id="Favorites" order="2" side_tool="true" weight="0.32916266" /> <window_info id="Favorites" order="2" side_tool="true" weight="0.32916266" />
<window_info anchor="bottom" id="Message" order="0" /> <window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" /> <window_info anchor="bottom" id="Find" order="1" />
...@@ -234,41 +203,46 @@ ...@@ -234,41 +203,46 @@
<option name="version" value="1" /> <option name="version" value="1" />
</component> </component>
<component name="editorHistoryManager"> <component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/openLogger.cpp"> <entry file="file://$PROJECT_DIR$/circularBuffer.cpp">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-34"> <state relative-caret-position="850">
<caret line="109" lean-forward="true" selection-start-line="109" selection-end-line="109" /> <caret line="50" column="17" lean-forward="true" selection-start-line="50" selection-start-column="17" selection-end-line="50" selection-end-column="17" />
<folding>
<element signature="e#8677#8871#0" expanded="true" />
</folding>
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/sufst-openlogger.ino"> <entry file="file://$PROJECT_DIR$/circularBuffer.h">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="187"> <state relative-caret-position="459">
<caret line="11" lean-forward="true" selection-start-line="11" selection-end-line="11" /> <caret line="27" column="63" selection-start-line="27" selection-start-column="63" selection-end-line="27" selection-end-column="63" />
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/circularBuffer.cpp"> <entry file="file://$PROJECT_DIR$/sufst-openlogger.ino">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-680"> <state relative-caret-position="187">
<caret line="50" column="17" lean-forward="true" selection-start-line="50" selection-start-column="17" selection-end-line="50" selection-end-column="17" /> <caret line="11" selection-start-line="11" selection-end-line="11" />
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/circularBuffer.h"> <entry file="file://$PROJECT_DIR$/openLogger.h">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="459"> <state relative-caret-position="-357">
<caret line="27" column="63" selection-start-line="27" selection-start-column="63" selection-end-line="27" selection-end-column="63" /> <caret line="24" selection-start-line="24" selection-end-line="24" />
<folding>
<element signature="e#758#862#0" expanded="true" />
<element signature="e#1008#1095#0" expanded="true" />
<element signature="e#1506#1864#0" expanded="true" />
</folding>
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/openLogger.h"> <entry file="file://$PROJECT_DIR$/openLogger.cpp">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="238"> <state relative-caret-position="340">
<caret line="14" column="50" lean-forward="true" selection-start-line="14" selection-start-column="50" selection-end-line="14" selection-end-column="50" /> <caret line="260" column="1" lean-forward="true" selection-start-line="260" selection-start-column="1" selection-end-line="260" selection-end-column="1" />
<folding>
<element signature="e#4547#4623#0" expanded="true" />
</folding>
</state> </state>
</provider> </provider>
</entry> </entry>
......
//
// Created by Sil on 14/07/2019.
//
#include "circularBuffer.h"
uint8_t cirBufferBegin(cirBuffer_handle cirBuff, void *dataSource, uint16_t dataCapacity) {
if (cirBuff == NULL) {
return 0;
}
if (dataSource == NULL) {
return 0;
}
cirBuff->head = 0;
cirBuff->tail = 0;
cirBuff->capacity = dataCapacity;
cirBuff->full = 0;
cirBuff->data = (uint8_t *) dataSource;
return 1;
}
uint16_t cirBufferGetUsedBytes(cirBuffer_handle cirBuff) {
if (!cirBuff->full) {
if (cirBuff->head >= cirBuff->tail) {
return (cirBuff->head - cirBuff->tail);
} else {
return (cirBuff->capacity + cirBuff->head - cirBuff->tail);
}
} else {
return cirBuff->capacity;
}
}
uint8_t cirBufferPeak(cirBuffer_handle cirBuff) {
return cirBuff->data[cirBuff->tail];
}
uint8_t cirBufferWrite(cirBuffer_handle cirBuff, uint8_t byte) {
cirBuff->data[cirBuff->head] = byte;
cirBuff->head = (cirBuff->head + 1) % cirBuff->capacity;
if (cirBuff->head == cirBuff->tail) {
cirBuff->full = 1;
return 0;
}
return 1;
}
uint8_t cirBufferWrite16(cirBuffer_handle cirBuff, uint16_t data) {
return cirBufferWriteBytes(cirBuff, &data, 2);
}
uint8_t cirBufferWrite32(cirBuffer_handle cirBuff, uint32_t data) {
return cirBufferWriteBytes(cirBuff, &data, 2);
}
uint8_t cirBufferWriteBytes(cirBuffer_handle cirBuff, void *data, uint16_t dataSize) {
#if DEBUG_CIR_BUFFERS
Serial.print("CBUF: WRITING DATA LENGTH ");
Serial.println(dataSize);
Serial.print("CBUF: CAPACITY ");
Serial.println(cirBuff->capacity);
Serial.print("CBUF: USED BYTES ");
Serial.println(cirBufferGetUsedBytes(cirBuff));
Serial.print("CBUF: HEAD ");
Serial.println(cirBuff->head);
Serial.print("CBUF: TAIL ");
Serial.println(cirBuff->tail);
Serial.flush();
#endif // DEBUG_CIR_BUFFERS
const uint16_t cirBufferBytesToAddUntilEnd = cirBuff->capacity - cirBuff->head;
const uint16_t cirBufferBytesToAddFromStart = dataSize - cirBufferBytesToAddUntilEnd;
const uint16_t cirBufferUsedBytes = cirBufferGetUsedBytes(cirBuff);
if ((cirBuff->capacity - cirBufferUsedBytes) < dataSize) {
cirBuff->full = true;
cirBuff->tail = ((cirBuff->tail + (dataSize - (cirBuff->capacity - cirBufferUsedBytes)))) % cirBuff->capacity;
}
if (cirBufferBytesToAddUntilEnd >= dataSize) {
memcpy(&(cirBuff->data[cirBuff->head]), data, dataSize);
} else {
memcpy(&(cirBuff->data[cirBuff->head]), data, cirBufferBytesToAddUntilEnd);
memcpy(cirBuff->data, ((uint8_t *)data)[cirBufferBytesToAddUntilEnd], cirBufferBytesToAddFromStart);
}
#if DEBUG_CIR_BUFFERS
Serial.print("CBUF: USED BYTES ");
Serial.println(cirBufferGetUsedBytes(cirBuff));
#endif // DEBUG_CIR_BUFFERS
cirBuff->head = (cirBuff->head + dataSize) % cirBuff->capacity;
#if DEBUG_CIR_BUFFERS
Serial.print("CBUF: HEAD ");
Serial.println(cirBuff->head);
Serial.print("CBUF: TAIL ");
Serial.println(cirBuff->tail);
Serial.flush();
#endif // DEBUG_CIR_BUFFERS
return 1;
}
uint8_t cirBufferRead(cirBuffer_handle cirBuff) {
uint8_t tailByte = cirBuff->data[cirBuff->tail];
cirBuff->tail = (cirBuff->tail + 1) % cirBuff->capacity;
cirBuff->full = 0;
return tailByte;
}
uint16_t cirBufferRead16(cirBuffer_handle cirBuff) {
uint16_t retData = 0;
return (cirBufferReadBytes(cirBuff, &retData, 2)) ? retData : 0;
}
uint32_t cirBufferRead32(cirBuffer_handle cirBuff) {
uint32_t retData = 0;
return (cirBufferReadBytes(cirBuff, &retData, 4)) ? retData : 0;
}
uint8_t cirBufferReadBytes(cirBuffer_handle cirBuff, void *data, uint8_t dataSize) {
#if DEBUG_CIR_BUFFERS
Serial.print("CBUF: READING DATA LENGTH ");
Serial.println(dataSize);
Serial.print("CBUF: CAPACITY ");
Serial.println(cirBuff->capacity);
Serial.print("CBUF: USED BYTES ");
Serial.println(cirBufferGetUsedBytes(cirBuff));
Serial.print("CBUF: HEAD ");
Serial.println(cirBuff->head);
Serial.print("CBUF: TAIL ");
Serial.println(cirBuff->tail);
Serial.flush();
#endif // DEBUG_CIR_BUFFERS
if ((dataSize + cirBuff->head) <= cirBuff->capacity) {
memcpy(data, &(cirBuff->data[cirBuff->tail]), dataSize);
} else {
const uint16_t cirBufferBytesToReadUntilEnd = cirBuff->capacity - cirBuff->head;
const uint16_t cirBufferBytesToReadFromStart = dataSize - cirBufferBytesToReadUntilEnd;
memcpy(data, &(cirBuff->data[cirBuff->tail]), cirBufferBytesToReadUntilEnd);
memcpy(&(((uint8_t *)data)[cirBufferBytesToReadUntilEnd]), cirBuff->data, cirBufferBytesToReadFromStart);
}
#if DEBUG_CIR_BUFFERS
Serial.print("CBUF: USED BYTES ");
Serial.println(cirBufferGetUsedBytes(cirBuff));
#endif // DEBUG_CIR_BUFFERS
cirBuff->tail = (cirBuff->tail + dataSize) % cirBuff->capacity;
#if DEBUG_CIR_BUFFERS
Serial.print("CBUF: HEAD ");
Serial.println(cirBuff->head);
Serial.print("CBUF: TAIL ");
Serial.println(cirBuff->tail);
Serial.flush();
#endif // DEBUG_CIR_BUFFERS
cirBuff->full = 0;
return 1;
}
uint8_t cirBufferReset(cirBuffer_handle cirBuff) {
cirBuff->head = 0;
cirBuff->tail = 0;
cirBuff->full = 0;
return 1;
}
//
// Created by Sil on 14/07/2019.
//
#ifndef SUFST_OPENLOGGER_INO_CIRCULARBUFFER_H
#define SUFST_OPENLOGGER_INO_CIRCULARBUFFER_H
#include "Arduino.h"
#define DEBUG_CIR_BUFFERS 0
typedef struct CirBuffer {
uint16_t head;
uint16_t tail;
uint8_t full;
uint8_t *data;
uint16_t capacity;
};
typedef CirBuffer *cirBuffer_handle;
uint8_t cirBufferBegin(cirBuffer_handle cirBuff, void *dataSource, uint16_t dataCapacity);
uint16_t cirBufferGetUsedBytes(cirBuffer_handle cirBuff);
uint8_t cirBufferPeak(cirBuffer_handle cirBuff);
uint8_t cirBufferWrite(cirBuffer_handle cirBuff, uint8_t byte);
uint8_t cirBufferWrite16(cirBuffer_handle cirBuff, uint16_t data);
uint8_t cirBufferWrite32(cirBuffer_handle cirBuff, uint32_t data);
uint8_t cirBufferWriteBytes(cirBuffer_handle cirBuff, void *data, uint16_t dataSize);
uint8_t cirBufferRead(cirBuffer_handle cirBuff);
uint16_t cirBufferRead16(cirBuffer_handle cirBuff);
uint32_t cirBufferRead32(cirBuffer_handle cirBuff);
uint8_t cirBufferReadBytes(cirBuffer_handle cirBuff, void *data, uint8_t dataSize);
uint8_t cirBufferReset(cirBuffer_handle cirBuff);
#endif //SUFST_OPENLOGGER_INO_CIRCULARBUFFER_H
...@@ -6,466 +6,322 @@ ...@@ -6,466 +6,322 @@
#include <SdFat.h> #include <SdFat.h>
enum SdState {
sdIdle,
sdStarting,
sdRunning,
sdStopping,
sdError
};
enum OpenloggerUartRxState {
openloggerRxCheckingForStartByte,
openloggerRxCheckingForMessageType,
openloggerRxCheckingForDataLength,
openloggerRxCheckingForCommand,
openloggerRxReceivingDataActive
};
typedef struct {
uint16_t blockHead;
// Writing 256 bytes per write gives fastest performance due to
// least overheads.
uint8_t block[OPENLOGGER_BYTES_PER_BLOCK_WRITE];
} sdBlockTemplate;
static sdBlockTemplate sdWriteBuffer[OPENLOGGER_WRITE_BUFFER_LEN];
static uint8_t sdWriteBufferHead = 0;
static uint8_t sdWriteBufferTail = 0;
SdFat sd; SdFat sd;
SdFile file; SdFile file;
SdState sdState = sdIdle; uint8_t openloggerBeginSd ();
OpenloggerUartRxState openloggerUartRxState = openloggerRxCheckingForStartByte;
#define OPENLOGGER_UART_INFO_TX_BUFFER_LEN 8 void uartCheckingForStartByte ();
uint8_t openloggerUartInfoTxBuffer[OPENLOGGER_UART_INFO_TX_BUFFER_LEN]; void uartCheckingForType ();
CirBuffer openloggerUartInfoTxCirBuffer;
uint8_t openloggerProcess() { void uartCheckingForLength ();
openloggerProcessUartRx(); void uartReceivingData ();
openloggerProcessUartTx();
switch (sdState) { void uartCheckingForCommand ();
case sdIdle:
break;
case sdStarting: void openloggerIdle ();
if (!openloggerBeginSd()) { void openloggerStarting ();
openloggerSendInfoToMaster(OPENLOGGER_INFO_WRITES_START_ERROR);
sdState = sdIdle; void openloggerRunning ();
} else { void openloggerStopping ();
digitalWrite(5, HIGH); typedef enum {
IDLE = 0,
STARTING,
RUNNING,
STOPPING
} OpenloggerState;
openloggerSendInfoToMaster(OPENLOGGER_INFO_WRITES_STARTED); typedef enum {
CHECKING_FOR_START = 0,
CHECKING_FOR_TYPE,
CHECKING_FOR_LENGTH,
RECEIVING_DATA,
CHECKING_FOR_COMMAND
} UartRxState;
sdState = sdRunning; OpenloggerState openloggerState = IDLE;
} UartRxState uartRxState = CHECKING_FOR_START;
break; void (*openloggerState_ptrs[4]) (void) = {openloggerIdle, openloggerStarting, openloggerRunning, openloggerStopping};
case sdRunning:
if (sdWriteBufferTail != sdWriteBufferHead) {
if (openloggerUartRxState == openloggerRxCheckingForStartByte) {
if (!openloggerWriteBufferBlocks()) {
openloggerSendInfoToMaster(OPENLOGGER_INFO_WRITE_ERROR);
}
}
}
break;
case sdStopping:
if (!file.close()) {
openloggerSendInfoToMaster(OPENLOGGER_INFO_WRITES_STOP_ERROR);
} else {
openloggerSendInfoToMaster(OPENLOGGER_INFO_WRITES_STOPPED);
digitalWrite(5, LOW); void
(*uartRxState_ptrs[5]) (void) = {uartCheckingForStartByte, uartCheckingForType, uartCheckingForLength,
uartReceivingData,
uartCheckingForCommand};
sdState = sdIdle; uint8_t openloggerSdBuffer[OPENLOGGER_WRITE_BUFFER_LEN];
} uint16_t openloggerSdBufferHead = 0;
break; uint8_t uartExpectedDataLength = 0;
default: uint8_t openloggerLastSeenCommand = 0;
sdState = sdIdle;
break; bool ledStatus = false;
}
return 1; void serialEvent ()
{
uartRxState_ptrs[uartRxState] ();
} }
uint8_t openloggerBegin() { void uartCheckingForStartByte ()
{
Serial.begin(OPENLOGGER_SERIAL_BUAD_RATE, OPENLOGGER_SERIAL_PARITY_CONFIG);
#if DEBUG_OPENLOGGER #if DEBUG_OPENLOGGER
Serial.println("OPLOG: BEGIN"); Serial.print ("OPLOG: CHECKING START ");
Serial.println (Serial.peek ());
#endif // DEBUG_OPENLOGGER #endif // DEBUG_OPENLOGGER
pinMode(5, OUTPUT); if (Serial.read () == OPENLOGGER_UART_START_BYTE) {
uartRxState = CHECKING_FOR_TYPE;
digitalWrite(5, LOW);
if (!cirBufferBegin(&openloggerUartInfoTxCirBuffer, openloggerUartInfoTxBuffer,
OPENLOGGER_UART_INFO_TX_BUFFER_LEN)) {
return 0;
} }
return 1;
} }
uint8_t openloggerBeginSd() { void uartCheckingForType ()
{
#if DEBUG_OPENLOGGER #if DEBUG_OPENLOGGER
Serial.println("SD: STARTING SD SERIAL"); Serial.print ("OPLOG: CHECKING FOR TYPE ");
Serial.println (Serial.peek ());
#endif // DEBUG_OPENLOGGER #endif // DEBUG_OPENLOGGER
noInterrupts(); uartRxState = (Serial.read () == OPENLOGGER_TYPE_DATA) ? CHECKING_FOR_LENGTH : CHECKING_FOR_COMMAND;
if (!sd.begin(OPENLOGGER_CS_PIN, SD_SCK_MHZ(10))) {
#if DEBUG_OPENLOGGER
Serial.print("SD: ERROR ");
Serial.println(sd.card()->errorCode(), HEX);
#endif // DEBUG_OPENLOGGER
interrupts();
return 0;
} }
void uartCheckingForLength ()
{
if (openloggerState != RUNNING) {
#if DEBUG_OPENLOGGER #if DEBUG_OPENLOGGER
Serial.println("SD: STARTED SD SERIAL"); Serial.println("OPLOG: NOT RUNNING");
#endif // DEBUG_OPENLOGGER #endif // DEBUG_OPENLOGGER
if (sd.exists("DATA.BIN")) { uartRxState = CHECKING_FOR_START;
#if DEBUG_OPENLOGGER return;
Serial.println("SD: FILE EXISTS - REMOVING"); }
#endif //DEBUG_OPENLOGGER
if (!sd.remove("DATA.BIN")) {
#if DEBUG_OPENLOGGER #if DEBUG_OPENLOGGER
Serial.print("SD: ERROR "); Serial.print ("OPLOG: CHECKING LENGTH ");
Serial.println(sd.card()->errorCode(), HEX); Serial.println (Serial.peek ());
#endif // DEBUG_OPENLOGGER #endif // DEBUG_OPENLOGGER
interrupts(); uartExpectedDataLength = Serial.read ();
return 0;
}
#if DEBUG_OPENLOGGER uartRxState = RECEIVING_DATA;
Serial.println("SD: REMOVED FILE");
#endif //DEBUG_OPENLOGGER
} }
void uartReceivingData ()
{
#if DEBUG_OPENLOGGER #if DEBUG_OPENLOGGER
Serial.println("SD: OPENING FILE"); Serial.print ("OPLOG: RECEIVED DATA ");
Serial.println (Serial.peek ());
#endif // DEBUG_OPENLOGGER #endif // DEBUG_OPENLOGGER
if (!file.open("DATA.BIN", O_WRITE | O_CREAT)) { openloggerSdBuffer[openloggerSdBufferHead] = Serial.read ();
#if DEBUG_OPENLOGGER openloggerSdBufferHead++;
Serial.print("SD: ERROR "); uartExpectedDataLength--;
Serial.println(sd.card()->errorCode(), HEX);
#endif // DEBUG_OPENLOGGER
interrupts(); if (openloggerSdBufferHead >= OPENLOGGER_WRITE_BUFFER_LEN) {
return 0; openloggerSdBufferHead = 0;
} }
interrupts(); if (!uartExpectedDataLength) {
uartRxState = CHECKING_FOR_START;
return 1; }
} }
uint8_t openloggerAddToWriteBlocks(void *pPayload, uint8_t payloadLen) { void uartCheckingForCommand ()
{
#if DEBUG_OPENLOGGER #if DEBUG_OPENLOGGER
Serial.print("SD: REQ "); Serial.print ("OPLOG: CHECKING COMMAND ");
Serial.println(payloadLen); Serial.println (Serial.peek ());
Serial.print("SD: BLOCK NR ");
Serial.println(sdWriteBufferHead);
Serial.flush();
#endif // DEBUG_OPENLOGGER #endif // DEBUG_OPENLOGGER
sdBlockTemplate *sdCurrBlock = &(sdWriteBuffer[sdWriteBufferHead]); openloggerLastSeenCommand = Serial.read ();
uint16_t sdBytesLeftInCurrBlock = OPENLOGGER_BYTES_PER_BLOCK_WRITE - sdCurrBlock->blockHead;
#if DEBUG_OPENLOGGER
Serial.print("SD: CURRENT BLOCK HEAD ");
Serial.println(sdCurrBlock->blockHead);
Serial.print("SD: BYTES LEFT IN BLOCK "); uartRxState = CHECKING_FOR_START;
Serial.println(sdBytesLeftInCurrBlock); }
Serial.flush();
#endif //DEBUG_OPENLOGGER
if ((payloadLen + sdCurrBlock->blockHead) <= OPENLOGGER_BYTES_PER_BLOCK_WRITE) { void openloggerIdle ()
memcpy(&(sdCurrBlock->block[sdCurrBlock->blockHead]), pPayload, payloadLen); {
sdCurrBlock->blockHead = sdCurrBlock->blockHead + payloadLen; }
void openloggerStarting ()
{
#if DEBUG_OPENLOGGER #if DEBUG_OPENLOGGER
Serial.print("SD: WROTE TO CURR BLOCK "); Serial.println ("OPLOG: STARTING WRITES");
Serial.println(payloadLen);
Serial.flush();
#endif //DEBUG_OPENLOGGER
} else {
#if DEBUG_OPENLOGGER
Serial.print("SD: WR THIS AND NEXT BLOCK ");
Serial.println(payloadLen);
Serial.flush();
#endif // DEBUG_OPENLOGGER #endif // DEBUG_OPENLOGGER
uint16_t sdBytesToAddThisBlock = sdBytesLeftInCurrBlock; if (openloggerBeginSd()) {
uint16_t sdBytesToAddNextBlock = payloadLen - sdBytesToAddThisBlock;
#if DEBUG_OPENLOGGER
Serial.print("SD: WR THIS ");
Serial.println(sdBytesLeftInCurrBlock);
Serial.print("SD: WR NEXT ");
Serial.println(sdBytesToAddNextBlock);
Serial.flush(); if (!ledStatus) {
#endif //DEBUG_OPENLOGGER digitalWrite (5, HIGH);
memcpy(&(sdCurrBlock->block[sdCurrBlock->blockHead]), pPayload, sdBytesToAddThisBlock); ledStatus = true;
}
sdWriteBufferHead = (sdWriteBufferHead + 1) % OPENLOGGER_WRITE_BUFFER_LEN; openloggerState = RUNNING;
} else {
openloggerState = IDLE;
}
}
sdCurrBlock = &(sdWriteBuffer[sdWriteBufferHead]); void openloggerRunning ()
{
memcpy(&(sdCurrBlock->block), (uint8_t * )((pPayload + sdBytesToAddThisBlock) - 1), sdBytesToAddNextBlock); static uint8_t sdBlocksWritten = 0;
sdCurrBlock->blockHead = sdBytesToAddNextBlock; if (openloggerSdBufferHead >= OPENLOGGER_BYTES_PER_BLOCK_WRITE) {
noInterrupts ();
#if DEBUG_OPENLOGGER #if DEBUG_OPENLOGGER
Serial.print("SD: WROTE TO CURR BLOCK "); Serial.println ("OPLOG: WRITING BLOCK");
Serial.println(sdBytesToAddThisBlock);
Serial.print("SD: WROTE TO NEXT BLOCK ");
Serial.println(sdBytesToAddNextBlock);
Serial.flush();
#endif // DEBUG_OPENLOGGER #endif // DEBUG_OPENLOGGER
if (!file.write (&(openloggerSdBuffer[openloggerSdBufferHead
- OPENLOGGER_BYTES_PER_BLOCK_WRITE]), OPENLOGGER_BYTES_PER_BLOCK_WRITE)) {
openloggerState = STOPPING;
} }
return 1; sdBlocksWritten++;
} if (sdBlocksWritten >= OPENLOGGER_BLOCKS_BEFORE_FLUSH) {
file.flush ();
uint8_t openloggerWriteBufferBlocks() {
sdBlockTemplate *sdCurrBlock = &(sdWriteBuffer[sdWriteBufferTail]);
static uint8_t sdBlocksBeforeSync = 0;
static uint32_t sdTotalBlocksWrittenToCard = 0;
noInterrupts(); sdBlocksWritten = 0;
if (!(file.write(sdCurrBlock->block, OPENLOGGER_BYTES_PER_BLOCK_WRITE))) {
interrupts();
return 0;
} }
interrupts();
if (sdBlocksBeforeSync >= 2) { openloggerSdBufferHead -= OPENLOGGER_BYTES_PER_BLOCK_WRITE;
noInterrupts();
file.flush();
interrupts (); interrupts ();
}
sdBlocksBeforeSync = 0;
} }
#if OPENLOGGER_SERIAL_PRINT_BLOCK_WRITES void openloggerStopping ()
Serial.print("SD: BL WR "); {
Serial.println(sdTotalBlocksWrittenToCard); #if DEBUG_OPENLOGGER
#endif // OPENLOGGER_SERIAL_PRINT_BLOCK_WRITES Serial.println ("OPLOG: STOPPING ");
#endif // DEBUG_OPENLOGGER
sdBlocksBeforeSync++;
sdCurrBlock->blockHead = 0;
sdTotalBlocksWrittenToCard++;
sdWriteBufferTail = (sdWriteBufferTail + 1) % OPENLOGGER_WRITE_BUFFER_LEN; if (file.close ()) {
if (ledStatus) {
digitalWrite (5, LOW);
return 1; ledStatus = false;
}
openloggerState = IDLE;
} }
uint8_t openloggerProcessUartRx() { openloggerState = RUNNING;
}
static unsigned long openloggerLastSeenValidUartMs = 0; void openloggerProcess ()
{
openloggerState_ptrs[openloggerState] ();
unsigned long sdCurrMs = millis(); if (openloggerLastSeenCommand != 0x00) {
openloggerState = (openloggerLastSeenCommand == OPENLOGGER_COMMAND_START_WRITES) ? STARTING : STOPPING;
static uint8_t uartRxWantedBytesAmount = 1; openloggerLastSeenCommand = 0;
}
}
static uint8_t openloggerToAdd[64]; uint8_t openloggerBegin ()
{
#if !DEBUG_OPENLOGGER #if !DEBUG_OPENLOGGER
if ((sdCurrMs - openloggerLastSeenValidUartMs) >= OPENLOGGER_UART_MESSAGE_TIMEOUT_MS) { Serial.begin (OPENLOGGER_SERIAL_BUAD_RATE, OPENLOGGER_SERIAL_PARITY_CONFIG);
openloggerUartRxState = openloggerRxCheckingForStartByte; #else
Serial.begin (OPENLOGGER_SERIAL_BUAD_RATE);
}
#endif // !DEBUG_OPENLOGGER #endif // !DEBUG_OPENLOGGER
if (Serial.available() >= uartRxWantedBytesAmount) {
uint8_t uartRxByte;
#if DEBUG_OPENLOGGER #if DEBUG_OPENLOGGER
Serial.print("SD: RX STATE "); Serial.println ("OPLOG: BEGIN");
Serial.println(openloggerUartRxState);
Serial.print("SD: Received Byte ");
Serial.println(cirBufferPeak(&openloggerRxUartCirBuffer), HEX);
#endif // DEBUG_OPENLOGGER #endif // DEBUG_OPENLOGGER
switch (openloggerUartRxState) { pinMode (5, OUTPUT);
case openloggerRxCheckingForStartByte:
if (Serial.read() == OPENLOGGER_UART_START_BYTE) {
openloggerUartRxState = openloggerRxCheckingForMessageType;
openloggerLastSeenValidUartMs = millis();
}
break;
case openloggerRxCheckingForMessageType:
switch (Serial.read()) {
case OPENLOGGER_TYPE_COMMAND:
openloggerUartRxState = openloggerRxCheckingForCommand;
break;
case OPENLOGGER_TYPE_SAVE_THIS_DATA: digitalWrite (5, LOW);
if (sdState != sdRunning) {
openloggerSendInfoToMaster(OPENLOGGER_INFO_WRITES_NOT_STARTED);
openloggerUartRxState = openloggerRxCheckingForStartByte; return 1;
} else {
openloggerUartRxState = openloggerRxCheckingForDataLength;
} }
break; void openloggerInformMaster(uint8_t info) {
Serial.write(OPENLOGGER_UART_START_BYTE);
default: Serial.write(OPENLOGGER_TYPE_INFO);
openloggerUartRxState = openloggerRxCheckingForStartByte; Serail.write(info);
Serial.write(OPENLOGGER_UART_STOP_BYTE);
break;
} }
break; uint8_t openloggerBeginSd ()
{
case openloggerRxCheckingForDataLength:
uartRxWantedBytesAmount = Serial.read();
openloggerUartRxState = openloggerRxReceivingDataActive;
break;
case openloggerRxReceivingDataActive: #if DEBUG_OPENLOGGER
Serial.println ("SD: STARTING SD SERIAL");
if (Serial.available() >= uartRxWantedBytesAmount) { #endif //DEBUG_OPENLOGGER
Serial.readBytes(openloggerToAdd, uartRxWantedBytesAmount); noInterrupts ();
openloggerAddToWriteBlocks(openloggerToAdd, uartRxWantedBytesAmount); if (!sd.begin (OPENLOGGER_CS_PIN, SD_SCK_MHZ (10))) {
uartRxWantedBytesAmount = 1; #if DEBUG_OPENLOGGER
Serial.print ("SD: ERROR ");
Serial.println (sd.card ()->errorCode (), HEX);
#endif // DEBUG_OPENLOGGER
openloggerUartRxState = openloggerRxCheckingForStartByte; interrupts ();
return 0;
} }
break; #if DEBUG_OPENLOGGER
Serial.println ("SD: STARTED SD SERIAL");
case openloggerRxCheckingForCommand: #endif //DEBUG_OPENLOGGER
switch (Serial.read()) { if (sd.exists ("DATA.BIN")) {
case OPENLOGGER_COMMAND_START_WRITES:
if (sdState == sdIdle) { #if DEBUG_OPENLOGGER
sdState = sdStarting; Serial.println ("SD: FILE EXISTS - REMOVING");
} else { #endif //DEBUG_OPENLOGGER
openloggerSendInfoToMaster(OPENLOGGER_INFO_ALREADY_RUNNING);
}
break; if (!sd.remove ("DATA.BIN")) {
case (OPENLOGGER_COMMAND_END_WRITES): #if DEBUG_OPENLOGGER
Serial.print ("SD: ERROR ");
Serial.println (sd.card ()->errorCode (), HEX);
#endif // DEBUG_OPENLOGGER
if (sdState == sdRunning) { interrupts ();
sdState = sdStopping; return 0;
} else {
openloggerSendInfoToMaster(OPENLOGGER_INFO_ALREADY_IDLE);
} }
break; #if DEBUG_OPENLOGGER
Serial.println ("SD: REMOVED FILE");
default: #endif //DEBUG_OPENLOGGER
break;
} }
openloggerUartRxState = openloggerRxCheckingForStartByte; #if DEBUG_OPENLOGGER
Serial.println ("SD: OPENING FILE");
break; #endif //DEBUG_OPENLOGGER
default: if (!file.open ("DATA.BIN", O_WRITE | O_CREAT)) {
openloggerUartRxState = openloggerRxCheckingForStartByte; #if DEBUG_OPENLOGGER
Serial.print ("SD: ERROR ");
Serial.println (sd.card ()->errorCode (), HEX);
#endif // DEBUG_OPENLOGGER
interrupts ();
return 0; return 0;
} }
}
return 1;
}
uint8_t openloggerSendInfoToMaster(uint8_t infoByte) {
if (!cirBufferWrite(&openloggerUartInfoTxCirBuffer, infoByte)) { interrupts ();
return 0;
}
return 1; return 1;
} }
uint8_t openloggerProcessUartTx() {
uint8_t openloggerStartByte = OPENLOGGER_UART_START_BYTE;
uint8_t openloggerMasterInfoByte = OPENLOGGER_TYPE_INFO;
uint8_t openloggerEndByte = OPENLOGGER_UART_STOP_BYTE;
if (cirBufferGetUsedBytes(&openloggerUartInfoTxCirBuffer) > 0) {
if (Serial.availableForWrite() > 4) {
Serial.write(openloggerStartByte);
Serial.write(openloggerMasterInfoByte);
Serial.write(cirBufferRead(&openloggerUartInfoTxCirBuffer));
Serial.write(openloggerEndByte);
} else {
return 0;
}
}
return 1;
}
...@@ -6,38 +6,78 @@ ...@@ -6,38 +6,78 @@
#define SUFST_OPENLOGGER_INO_SDCARD_H #define SUFST_OPENLOGGER_INO_SDCARD_H
#include "Arduino.h" #include "Arduino.h"
#include "circularBuffer.h"
#define DEBUG_OPENLOGGER 0 #define DEBUG_OPENLOGGER 1
#define OPENLOGGER_SERIAL_PRINT_BLOCK_WRITES 0
#define OPENLOGGER_SERIAL_BUAD_RATE 115200 #define OPENLOGGER_SERIAL_BUAD_RATE 115200
#define OPENLOGGER_SERIAL_PARITY_CONFIG SERIAL_8E1 #define OPENLOGGER_SERIAL_PARITY_CONFIG SERIAL_8E1
#define OPENLOGGER_BYTES_PER_BLOCK_WRITE 256 #define OPENLOGGER_BYTES_PER_BLOCK_WRITE 256
#define OPENLOGGER_WRITE_BUFFER_LEN OPENLOGGER_BYTES_PER_BLOCK_WRITE * 2
#define OPENLOGGER_WRITE_BUFFER_LEN 2 #define OPENLOGGER_BLOCKS_BEFORE_FLUSH 2
#define OPENLOGGER_CS_PIN 10 #define OPENLOGGER_CS_PIN 10
#if DEBUG_OPENLOGGER
#define OPENLOGGER_UART_START_BYTE 's'
#define OPENLOGGER_UART_STOP_BYTE 'f'
#define OPENLOGGER_UART_START_BYTE 0xFF #define OPENLOGGER_UART_START_BYTE 0xFF
#define OPENLOGGER_UART_STOP_BYTE 0x01 #define OPENLOGGER_UART_STOP_BYTE 0xAF
#endif // DEBUG_OPENLOGGER
#if DEBUG_OPENLOGGER
#define OPENLOGGER_TYPE_DATA 'd'
#define OPENLOGGER_TYPE_COMMAND 'c'
#define OPENLOGGER_TYPE_INFO 'i'
#else
#define OPENLOGGER_TYPE_DATA 0x00
#define OPENLOGGER_TYPE_COMMAND 0x01
#define OPENLOGGER_TYPE_INFO 0x02
#endif // DEBUG_OPENLOGGER
#if DEBUG_OPENLOGGER
#define OPENLOGGER_COMMAND_START_WRITES 'v'
#define OPENLOGGER_COMMAND_END_WRITES 'b'
#define OPENLOGGER_TYPE_SAVE_THIS_DATA 0x65 #else
#define OPENLOGGER_TYPE_COMMAND 0x88
#define OPENLOGGER_TYPE_INFO 0x99
#define OPENLOGGER_COMMAND_START_WRITES 0x11 #define OPENLOGGER_COMMAND_START_WRITES 0x01
#define OPENLOGGER_COMMAND_END_WRITES 0x22 #define OPENLOGGER_COMMAND_END_WRITES 0x02
#define OPENLOGGER_INFO_ALREADY_RUNNING 0x11 #endif // DEBUG_OPENLOGGER
#define OPENLOGGER_INFO_ALREADY_IDLE 0x22
#define OPENLOGGER_INFO_WRITES_STARTED 0x33 #if DEBUG_OPENLOGGER
#define OPENLOGGER_INFO_WRITES_START_ERROR 0x44
#define OPENLOGGER_INFO_WRITES_STOPPED 0x55 #define OPENLOGGER_INFO_ALREADY_RUNNING '0'
#define OPENLOGGER_INFO_WRITES_STOP_ERROR 0x66 #define OPENLOGGER_INFO_ALREADY_IDLE '1'
#define OPENLOGGER_INFO_WRITE_ERROR 0x77 #define OPENLOGGER_INFO_WRITES_STARTED '2'
#define OPENLOGGER_INFO_WRITES_NOT_STARTED 0x88 #define OPENLOGGER_INFO_WRITES_START_ERROR '3'
#define OPENLOGGER_INFO_WRITES_STOPPED '4'
#define OPENLOGGER_INFO_WRITES_STOP_ERROR '5'
#define OPENLOGGER_INFO_WRITE_ERROR '6'
#define OPENLOGGER_INFO_WRITES_NOT_STARTED '7'
#else
#define OPENLOGGER_INFO_ALREADY_RUNNING 0x00
#define OPENLOGGER_INFO_ALREADY_IDLE 0x01
#define OPENLOGGER_INFO_WRITES_STARTED 0x02
#define OPENLOGGER_INFO_WRITES_START_ERROR 0x03
#define OPENLOGGER_INFO_WRITES_STOPPED 0x04
#define OPENLOGGER_INFO_WRITES_STOP_ERROR 0x05
#define OPENLOGGER_INFO_WRITE_ERROR 0x06
#define OPENLOGGER_INFO_WRITES_NOT_STARTED 0x07
#endif // DEBUG_OPENLOGGER
#define OPENLOGGER_UART_MESSAGE_TIMEOUT_MS 500 #define OPENLOGGER_UART_MESSAGE_TIMEOUT_MS 500
...@@ -60,22 +100,8 @@ ...@@ -60,22 +100,8 @@
* *
*/ */
uint8_t openloggerProcess(); void openloggerProcess ();
uint8_t openloggerBegin (); uint8_t openloggerBegin ();
uint8_t openloggerBeginSd();
uint8_t openloggerAddToWriteBlocks(void *pPayload, uint8_t payloadLen);
uint8_t openloggerAddToWriteBlocksFromCirBuff(CirBuffer* cirBuff, uint8_t payloadLen);
uint8_t openloggerWriteBufferBlocks();
uint8_t openloggerProcessUartRx();
uint8_t openloggerSendInfoToMaster(uint8_t infoByte);
uint8_t openloggerProcessUartTx();
#endif //SUFST_OPENLOGGER_INO_SDCARD_H #endif //SUFST_OPENLOGGER_INO_SDCARD_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment