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

Added uart time out resetting to checking for start byte and sending info back to master

parent b26fa61c
No related branches found
No related tags found
No related merge requests found
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<Objective-C>
<option name="INDENT_NAMESPACE_MEMBERS" value="0" />
<option name="INDENT_C_STRUCT_MEMBERS" value="2" />
<option name="INDENT_CLASS_MEMBERS" value="2" />
<option name="INDENT_VISIBILITY_KEYWORDS" value="1" />
<option name="INDENT_INSIDE_CODE_BLOCK" value="2" />
<option name="KEEP_STRUCTURES_IN_ONE_LINE" value="true" />
<option name="KEEP_CASE_EXPRESSIONS_IN_ONE_LINE" value="true" />
<option name="FUNCTION_NON_TOP_AFTER_RETURN_TYPE_WRAP" value="0" />
<option name="FUNCTION_TOP_AFTER_RETURN_TYPE_WRAP" value="0" />
<option name="FUNCTION_PARAMETERS_WRAP" value="5" />
<option name="FUNCTION_CALL_ARGUMENTS_WRAP" value="5" />
<option name="TEMPLATE_CALL_ARGUMENTS_WRAP" value="5" />
<option name="TEMPLATE_CALL_ARGUMENTS_ALIGN_MULTILINE" value="true" />
<option name="CLASS_CONSTRUCTOR_INIT_LIST_WRAP" value="5" />
<option name="ALIGN_INIT_LIST_IN_COLUMNS" value="false" />
<option name="HEADER_GUARD_STYLE_PATTERN" value="${PROJECT_NAME}_${PROJECT_REL_PATH}_${FILE_NAME}_${EXT}_" />
<option name="NAMESPACES_NAMING_CONVENTION">
<value prefix="" style="SNAKE_CASE" suffix="" />
</option>
<option name="CLASSES_AND_STRUCTS_NAMING_CONVENTION">
<value prefix="" style="PASCAL_CASE" suffix="" />
</option>
<option name="ENUMS_NAMING_CONVENTION">
<value prefix="" style="PASCAL_CASE" suffix="" />
</option>
<option name="ENUMERATORS_NAMING_CONVENTION">
<value prefix="" style="SCREAMING_SNAKE_CASE" suffix="" />
</option>
<option name="TYPEDEFS_NAMING_CONVENTION">
<value prefix="" style="PASCAL_CASE" suffix="" />
</option>
<option name="UNIONS_NAMING_CONVENTION">
<value prefix="" style="PASCAL_CASE" suffix="" />
</option>
<option name="METHODS_NAMING_CONVENTION">
<value prefix="" style="PASCAL_CASE" suffix="" />
</option>
<option name="FIELDS_NAMING_CONVENTION">
<value prefix="" style="SNAKE_CASE" suffix="_" />
</option>
<option name="GLOBAL_FUNCTIONS_NAMING_CONVENTION">
<value prefix="" style="PASCAL_CASE" suffix="" />
</option>
<option name="GLOBAL_VARIABLES_NAMING_CONVENTION">
<value prefix="" style="SNAKE_CASE" suffix="" />
</option>
<option name="PARAMETERS_NAMING_CONVENTION">
<value prefix="" style="SNAKE_CASE" suffix="" />
</option>
<option name="LOCAL_VARIABLES_NAMING_CONVENTION">
<value prefix="" style="SNAKE_CASE" suffix="" />
</option>
</Objective-C>
<codeStyleSettings language="ObjectiveC">
<option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" />
<option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="1" />
<option name="BLANK_LINES_BEFORE_IMPORTS" value="0" />
<option name="BLANK_LINES_AFTER_IMPORTS" value="0" />
<option name="BLANK_LINES_AROUND_CLASS" value="0" />
<option name="BLANK_LINES_AROUND_METHOD" value="0" />
<option name="BLANK_LINES_AROUND_METHOD_IN_INTERFACE" value="0" />
<option name="ALIGN_MULTILINE_BINARY_OPERATION" value="false" />
<option name="BINARY_OPERATION_SIGN_ON_NEXT_LINE" value="true" />
<option name="FOR_STATEMENT_WRAP" value="1" />
<option name="ASSIGNMENT_WRAP" value="1" />
<indentOptions>
<option name="INDENT_SIZE" value="2" />
<option name="CONTINUATION_INDENT_SIZE" value="4" />
</indentOptions>
</codeStyleSettings>
</code_scheme>
</component>
\ No newline at end of file
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>
\ No newline at end of file
......@@ -10,14 +10,11 @@
</component>
<component name="ChangeListManager">
<list default="true" id="81322c4e-6adb-4223-9d00-22249012da89" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/.idea/codeStyles/codeStyleConfig.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/codeStyles/Project.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/codeStyles/codeStyleConfig.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/codeStyles/codeStyleConfig.xml" 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.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/sufst-openlogger_controller.ino" beforeDir="false" afterPath="$PROJECT_DIR$/../sufst-openlogger_controller/sufst-openlogger_controller.ino" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
......@@ -42,27 +39,28 @@
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/openLogger.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="340">
<caret line="260" column="1" lean-forward="true" selection-start-line="260" selection-start-column="1" selection-end-line="260" selection-end-column="1" />
<state relative-caret-position="680">
<caret line="286" column="7" selection-start-line="286" selection-start-column="7" selection-end-line="286" selection-end-column="7" />
<folding>
<element signature="e#4547#4623#0" expanded="true" />
<element signature="e#5062#5137#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<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="-357">
<caret line="24" selection-start-line="24" selection-end-line="24" />
<state relative-caret-position="136">
<caret line="8" lean-forward="true" selection-start-line="8" selection-end-line="8" />
<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" />
<element signature="e#1134#1210#0" expanded="true" />
<element signature="e#1349#1450#0" expanded="true" />
<element signature="e#1615#1700#0" expanded="true" />
<element signature="e#1848#2198#0" expanded="true" />
</folding>
</state>
</provider>
......@@ -97,6 +95,7 @@
<find>begin</find>
<find>close</find>
<find>openloggerBeginSd</find>
<find>SERIAL</find>
</findStrings>
<replaceStrings>
<replace>DEBUG_OPENLOGGER</replace>
......@@ -111,16 +110,16 @@
<list>
<option value="$PROJECT_DIR$/circularBuffer.h" />
<option value="$PROJECT_DIR$/circularBuffer.cpp" />
<option value="$PROJECT_DIR$/openLogger.h" />
<option value="$PROJECT_DIR$/openLogger.cpp" />
<option value="$PROJECT_DIR$/openLogger.h" />
</list>
</option>
</component>
<component name="OCFindUsagesOptions" text="true" ivars="false" properties="true" derivedClasses="false" />
<component name="ProjectFrameBounds">
<option name="x" value="501" />
<option name="width" value="1428" />
<option name="height" value="1038" />
<option name="x" value="1186" />
<option name="width" value="2663" />
<option name="height" value="2111" />
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectView">
......@@ -142,7 +141,7 @@
<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_package_manager_path" value="npm" />
<property name="settings.editor.selected.configurable" value="preferences.sourceCode.C/C++" />
<property name="settings.editor.selected.configurable" value="preferences.lookFeel" />
</component>
<component name="RunDashboard">
<option name="ruleStates">
......@@ -169,18 +168,19 @@
<workItem from="1563140777259" duration="246000" />
<workItem from="1563216461708" duration="10620000" />
<workItem from="1563385421018" duration="9848000" />
<workItem from="1563401015844" duration="2605000" />
</task>
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="43419000" />
<option name="totallyTimeSpent" value="46024000" />
</component>
<component name="ToolWindowManager">
<frame x="401" y="0" width="1142" height="830" extended-state="0" />
<frame x="791" y="0" width="1775" height="1407" extended-state="0" />
<editor active="true" />
<layout>
<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.25878003" />
<window_info active="true" id="Structure" order="1" sideWeight="0.50143266" side_tool="true" visible="true" weight="0.13760933" />
<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="Find" order="1" />
......@@ -203,20 +203,8 @@
<option name="version" value="1" />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/circularBuffer.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="850">
<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>
<entry file="file://$PROJECT_DIR$/circularBuffer.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="459">
<caret line="27" column="63" selection-start-line="27" selection-start-column="63" selection-end-line="27" selection-end-column="63" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/circularBuffer.cpp" />
<entry file="file://$PROJECT_DIR$/circularBuffer.h" />
<entry file="file://$PROJECT_DIR$/sufst-openlogger.ino">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="187">
......@@ -224,27 +212,43 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/openLogger.h">
<entry file="file://$PROJECT_DIR$/openLogger.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-357">
<caret line="24" selection-start-line="24" selection-end-line="24" />
<state relative-caret-position="680">
<caret line="286" column="7" selection-start-line="286" selection-start-column="7" selection-end-line="286" selection-end-column="7" />
<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" />
<element signature="e#5062#5137#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/openLogger.cpp">
<entry file="file://$PROJECT_DIR$/openLogger.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="340">
<caret line="260" column="1" lean-forward="true" selection-start-line="260" selection-start-column="1" selection-end-line="260" selection-end-column="1" />
<state relative-caret-position="136">
<caret line="8" lean-forward="true" selection-start-line="8" selection-end-line="8" />
<folding>
<element signature="e#4547#4623#0" expanded="true" />
<element signature="e#1134#1210#0" expanded="true" />
<element signature="e#1349#1450#0" expanded="true" />
<element signature="e#1615#1700#0" expanded="true" />
<element signature="e#1848#2198#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</component>
<component name="masterDetails">
<states>
<state key="ScopeChooserConfigurable.UI">
<settings>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
</states>
</component>
</project>
\ No newline at end of file
......@@ -4,6 +4,9 @@
#include "openLogger.h"
#include <avr/wdt.h>
#include <avr/interrupt.h>
#include <SdFat.h>
SdFat sd;
......@@ -29,6 +32,10 @@ void openloggerRunning ();
void openloggerStopping();
void openloggerInformMaster(uint8_t info);
void watchdogBegin500ms();
typedef enum {
IDLE = 0,
STARTING,
......@@ -63,13 +70,18 @@ uint8_t openloggerLastSeenCommand = 0;
bool ledStatus = false;
void serialEvent ()
{
void serialEvent() {
wdt_reset();
uartRxState_ptrs[uartRxState]();
}
void uartCheckingForStartByte ()
{
ISR(WDT_vect) {
uartRxState = CHECKING_FOR_START;
}
void uartCheckingForStartByte() {
#if DEBUG_OPENLOGGER
Serial.print("OPLOG: CHECKING START ");
......@@ -81,8 +93,7 @@ void uartCheckingForStartByte ()
}
}
void uartCheckingForType ()
{
void uartCheckingForType() {
#if DEBUG_OPENLOGGER
Serial.print("OPLOG: CHECKING FOR TYPE ");
Serial.println(Serial.peek());
......@@ -92,13 +103,14 @@ void uartCheckingForType ()
}
void uartCheckingForLength ()
{
void uartCheckingForLength() {
if (openloggerState != RUNNING) {
#if DEBUG_OPENLOGGER
Serial.println("OPLOG: NOT RUNNING");
#endif // DEBUG_OPENLOGGER
openloggerInformMaster(OPENLOGGER_INFO_WRITES_NOT_STARTED);
uartRxState = CHECKING_FOR_START;
return;
......@@ -114,8 +126,7 @@ void uartCheckingForLength ()
uartRxState = RECEIVING_DATA;
}
void uartReceivingData ()
{
void uartReceivingData() {
#if DEBUG_OPENLOGGER
Serial.print("OPLOG: RECEIVED DATA ");
......@@ -135,8 +146,7 @@ void uartReceivingData ()
}
}
void uartCheckingForCommand ()
{
void uartCheckingForCommand() {
#if DEBUG_OPENLOGGER
Serial.print("OPLOG: CHECKING COMMAND ");
Serial.println(Serial.peek());
......@@ -147,13 +157,11 @@ void uartCheckingForCommand ()
uartRxState = CHECKING_FOR_START;
}
void openloggerIdle ()
{
void openloggerIdle() {
}
void openloggerStarting ()
{
void openloggerStarting() {
#if DEBUG_OPENLOGGER
Serial.println("OPLOG: STARTING WRITES");
#endif // DEBUG_OPENLOGGER
......@@ -166,14 +174,17 @@ void openloggerStarting ()
ledStatus = true;
}
openloggerInformMaster(OPENLOGGER_INFO_WRITES_STARTED);
openloggerState = RUNNING;
} else {
openloggerInformMaster(OPENLOGGER_INFO_WRITES_START_ERROR);
openloggerState = IDLE;
}
}
void openloggerRunning ()
{
void openloggerRunning() {
static uint8_t sdBlocksWritten = 0;
......@@ -186,6 +197,8 @@ void openloggerRunning ()
if (!file.write(&(openloggerSdBuffer[openloggerSdBufferHead
- OPENLOGGER_BYTES_PER_BLOCK_WRITE]), OPENLOGGER_BYTES_PER_BLOCK_WRITE)) {
openloggerInformMaster(OPENLOGGER_INFO_WRITE_ERROR);
openloggerState = STOPPING;
}
......@@ -203,8 +216,7 @@ void openloggerRunning ()
}
}
void openloggerStopping ()
{
void openloggerStopping() {
#if DEBUG_OPENLOGGER
Serial.println("OPLOG: STOPPING ");
#endif // DEBUG_OPENLOGGER
......@@ -216,14 +228,19 @@ void openloggerStopping ()
ledStatus = false;
}
openloggerInformMaster(OPENLOGGER_INFO_WRITES_STOPPED);
openloggerState = IDLE;
}
} else {
openloggerInformMaster(OPENLOGGER_INFO_WRITES_STOP_ERROR);
openloggerState = RUNNING;
}
void openloggerProcess ()
{
}
void openloggerProcess() {
openloggerState_ptrs[openloggerState]();
if (openloggerLastSeenCommand != 0x00) {
......@@ -233,8 +250,7 @@ void openloggerProcess ()
}
}
uint8_t openloggerBegin ()
{
uint8_t openloggerBegin() {
#if !DEBUG_OPENLOGGER
Serial.begin(OPENLOGGER_SERIAL_BUAD_RATE, OPENLOGGER_SERIAL_PARITY_CONFIG);
......@@ -246,6 +262,8 @@ uint8_t openloggerBegin ()
Serial.println("OPLOG: BEGIN");
#endif // DEBUG_OPENLOGGER
watchdogBegin500ms();
pinMode(5, OUTPUT);
digitalWrite(5, LOW);
......@@ -256,12 +274,22 @@ uint8_t openloggerBegin ()
void openloggerInformMaster(uint8_t info) {
Serial.write(OPENLOGGER_UART_START_BYTE);
Serial.write(OPENLOGGER_TYPE_INFO);
Serail.write(info);
Serial.write(info);
Serial.write(OPENLOGGER_UART_STOP_BYTE);
}
uint8_t openloggerBeginSd ()
{
void watchdogBegin500ms() {
cli();
WDTCSR = (1<<WDCE)|(1<<WDE);
WDTCSR = 0;
WDTCSR = (1<<WDIE) | (1<<WDP2) | (1<<WDP0);
sei();
}
uint8_t openloggerBeginSd() {
#if DEBUG_OPENLOGGER
Serial.println("SD: STARTING SD SERIAL");
......
......@@ -7,7 +7,7 @@
#include "Arduino.h"
#define DEBUG_OPENLOGGER 1
#define DEBUG_OPENLOGGER 0
#define OPENLOGGER_SERIAL_BUAD_RATE 115200
#define OPENLOGGER_SERIAL_PARITY_CONFIG SERIAL_8E1
......@@ -18,11 +18,33 @@
#define OPENLOGGER_CS_PIN 10
/*
*
* There are three types of transactions: save this data, do this command or heres some info.
*
* STRUCTURE OF A VALID SD CARD UART SAVE THIS DATA TRANSACTION
*
* START BYTE | DATA TYPE | LENGTH BYTE | DATA BYTES | STOP BYTE
*
* STRUCTURE OF A VALID COMMAND TRANSACTION
*
* START BYTE | COMMAND TYPE | COMMAND BYTE | STOP BYTE
*
* STUCTURE OF VALID INFO TRANSACTION
*
* START BYTE | INFO TYPE | INFO BYTE | STOP BYTE
*
* If no rx has been received for more than 500ms the rx state is reset to checking for start byte
* This ensures the open logger does not get stuck in the middle of a transaction if the master stops sending data
*
*/
#if DEBUG_OPENLOGGER
#define OPENLOGGER_UART_START_BYTE 's'
#define OPENLOGGER_UART_STOP_BYTE 'f'
#else
#define OPENLOGGER_UART_START_BYTE 0xFF
#define OPENLOGGER_UART_STOP_BYTE 0xAF
......@@ -79,27 +101,6 @@
#endif // DEBUG_OPENLOGGER
#define OPENLOGGER_UART_MESSAGE_TIMEOUT_MS 500
/*
*
* There are three types of transactions: save this data, do this command or heres some info.
*
* STRUCTURE OF A VALID SD CARD UART SAVE THIS DATA TRANSACTION
*
* START BYTE | DATA TYPE | LENGTH BYTE | DATA BYTES | STOP BYTE
*
* STRUCTURE OF A VALID COMMAND TRANSACTION
*
* START BYTE | COMMAND TYPE | COMMAND BYTE | STOP BYTE
*
* STUCTURE OF VALID INFO TRANSACTION
*
* START BYTE | INFO TYPE | INFO BYTE | STOP BYTE
*
*
*/
void openloggerProcess();
uint8_t openloggerBegin();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment