Skip to content

Commit

Permalink
flow error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Oct 11, 2021
1 parent 183e542 commit cbf3db8
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 53 deletions.
Binary file modified scripts/DC Power App/DC Power.app
Binary file not shown.
26 changes: 24 additions & 2 deletions scripts/DC Power App/DC Power.eez-project
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
"type": "ScpiActionComponent",
"left": -245,
"top": -145,
"width": 436,
"width": 437,
"height": 87,
"wireID": "9a5fc5c4-c7a6-4257-c380-281d79c76fa4",
"customInputs": [],
Expand Down Expand Up @@ -207,7 +207,7 @@
"type": "LoopActionComponent",
"left": -533,
"top": 17,
"width": 196,
"width": 197,
"height": 70,
"wireID": "71acb5a9-df39-48cb-b0f6-6ce84d5cdaa9",
"customInputs": [],
Expand Down Expand Up @@ -1581,6 +1581,22 @@
"catchError": false,
"instrument": "null",
"scpi": "DISP:ERROR {'\"' + error + '\"'}"
},
{
"type": "LogActionComponent",
"left": 199,
"top": 464,
"width": 75,
"height": 61,
"wireID": "eb32ad68-f8a3-4232-ad92-fd25dea0d12f",
"customInputs": [
{
"name": "idx",
"type": "string"
}
],
"customOutputs": [],
"value": "\"Value:\" + ch[idx].u.set"
}
],
"connectionLines": [
Expand Down Expand Up @@ -1727,6 +1743,12 @@
"output": "@error",
"target": "7bb34731-ede7-4bce-f390-9d7f5a7c00a9",
"input": "error"
},
{
"source": "7e882d1c-c85b-4b72-835b-c51d82dcaa8a",
"output": "action",
"target": "eb32ad68-f8a3-4232-ad92-fd25dea0d12f",
"input": "idx"
}
],
"localVariables": [
Expand Down
6 changes: 2 additions & 4 deletions src/eez/flow/components/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <eez/flow/components.h>
#include <eez/flow/flow_defs_v3.h>
#include <eez/flow/expression.h>
#include <eez/flow/debugger.h>

using namespace eez::gui;

Expand All @@ -41,10 +42,7 @@ void executeLogComponent(FlowState *flowState, unsigned componentIndex) {

const char *valueStr = value.toString(0x0f9812ee).getString();
if (valueStr && *valueStr) {
DebugTrace(valueStr);
if (valueStr[strlen(valueStr) - 1] != '\n') {
DebugTrace("\n");
}
logInfo(flowState, componentIndex, valueStr);
}

propagateValue(flowState, componentIndex);
Expand Down
78 changes: 70 additions & 8 deletions src/eez/flow/debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ enum MessagesToDebugger {
MESSAGE_TO_DEBUGGER_FLOW_STATE_CREATED, // FLOW_STATE_INDEX, FLOW_INDEX, PARENT_FLOW_STATE_INDEX (-1 - NO PARENT), PARENT_COMPONENT_INDEX (-1 - NO PARENT COMPONENT)
MESSAGE_TO_DEBUGGER_FLOW_STATE_DESTROYED, // FLOW_STATE_INDEX

MESSAGE_TO_DEBUGGER_FLOW_STATE_ERROR, // FLOW_STATE_INDEX, COMPONENT_INDEX, ERROR_MESSAGE

MESSAGE_TO_DEBUGGER_LOG // LOG_ITEM_TYPE, FLOW_STATE_INDEX, COMPONENT_INDEX, MESSAGE

};
Expand Down Expand Up @@ -479,31 +481,92 @@ void onFlowStateDestroyed(FlowState *flowState) {
}
}

void onFlowError(FlowState *flowState, int componentIndex, const char *errorMessage) {
if (g_debuggerIsConnected) {
char buffer[100];
snprintf(buffer, sizeof(buffer), "%d\t%d\t%d\t",
MESSAGE_TO_DEBUGGER_FLOW_STATE_ERROR,
(int)flowState->flowStateIndex,
componentIndex
);
eez::mcu::ethernet::writeDebuggerBuffer(buffer, strlen(buffer));
writeString(errorMessage);
}
}

void writeLogMessage(const char *str) {
for (const char *p = str; *p; p++) {
if (*p == '\t') {
WRITE_TO_OUTPUT_BUFFER('\\');
WRITE_TO_OUTPUT_BUFFER('t');
} if (*p == '\n') {
WRITE_TO_OUTPUT_BUFFER('\\');
WRITE_TO_OUTPUT_BUFFER('n');
} else {
WRITE_TO_OUTPUT_BUFFER(*p);
}
}

WRITE_TO_OUTPUT_BUFFER('\n');
FLUSH_OUTPUT_BUFFER();
}

void writeLogMessage(const char *str, size_t len) {
for (size_t i = 0; i < len; i++) {
if (str[i] == '\t') {
WRITE_TO_OUTPUT_BUFFER('\\');
WRITE_TO_OUTPUT_BUFFER('t');
} if (str[i] == '\n') {
WRITE_TO_OUTPUT_BUFFER('\\');
WRITE_TO_OUTPUT_BUFFER('n');
} else {
WRITE_TO_OUTPUT_BUFFER(str[i]);
}
}

WRITE_TO_OUTPUT_BUFFER('\n');
FLUSH_OUTPUT_BUFFER();
}

void logInfo(FlowState *flowState, unsigned componentIndex, const char *message) {
if (g_debuggerIsConnected) {
char buffer[256];
snprintf(buffer, sizeof(buffer), "%d\t%d\t%d\t%d\t",
MESSAGE_TO_DEBUGGER_LOG,
LOG_ITEM_TYPE_INFO,
(int)flowState->flowStateIndex,
componentIndex
);
eez::mcu::ethernet::writeDebuggerBuffer(buffer, strlen(buffer));
writeLogMessage(message);
}
}

void logScpiCommand(FlowState *flowState, unsigned componentIndex, const char *cmd) {
if (g_debuggerIsConnected) {
char buffer[256];
snprintf(buffer, sizeof(buffer), "%d\t%d\t%d\t%d\tSCPI COMMAND: %s\n",
snprintf(buffer, sizeof(buffer), "%d\t%d\t%d\t%d\tSCPI COMMAND: ",
MESSAGE_TO_DEBUGGER_LOG,
LOG_ITEM_TYPE_SCPI,
(int)flowState->flowStateIndex,
componentIndex,
cmd
componentIndex
);
eez::mcu::ethernet::writeDebuggerBuffer(buffer, strlen(buffer));
writeLogMessage(cmd);
}
}

void logScpiQuery(FlowState *flowState, unsigned componentIndex, const char *query) {
if (g_debuggerIsConnected) {
char buffer[256];
snprintf(buffer, sizeof(buffer), "%d\t%d\t%d\t%d\tSCPI QUERY: %s\n",
snprintf(buffer, sizeof(buffer), "%d\t%d\t%d\t%d\tSCPI QUERY: ",
MESSAGE_TO_DEBUGGER_LOG,
LOG_ITEM_TYPE_SCPI,
(int)flowState->flowStateIndex,
componentIndex,
query
componentIndex
);
eez::mcu::ethernet::writeDebuggerBuffer(buffer, strlen(buffer));
writeLogMessage(query);
}
}

Expand All @@ -516,9 +579,8 @@ void logScpiQueryResult(FlowState *flowState, unsigned componentIndex, const cha
(int)flowState->flowStateIndex,
componentIndex
);
stringAppendStringLength(buffer, sizeof(buffer) - 1, resultText, resultTextLen);
stringAppendString(buffer, sizeof(buffer), "\n");
eez::mcu::ethernet::writeDebuggerBuffer(buffer, strlen(buffer));
writeLogMessage(resultText, resultTextLen);
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/eez/flow/debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ void onValueChanged(const Value *pValue);
void onFlowStateCreated(FlowState *flowState);
void onFlowStateDestroyed(FlowState *flowState);

void onFlowError(FlowState *flowState, int componentIndex, const char *errorMessage);

void logInfo(FlowState *flowState, unsigned componentIndex, const char *message);

void logScpiCommand(FlowState *flowState, unsigned componentIndex, const char *cmd);
void logScpiQuery(FlowState *flowState, unsigned componentIndex, const char *query);
void logScpiQueryResult(FlowState *flowState, unsigned componentIndex, const char *resultText, size_t resultTextLen);
Expand Down
39 changes: 0 additions & 39 deletions src/eez/flow/flow_defs_v3.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,13 @@ enum ComponentTypes {
COMPONENT_TYPE_END_ACTION = 1002,
COMPONENT_TYPE_INPUT_ACTION = 1003,
COMPONENT_TYPE_OUTPUT_ACTION = 1004,
COMPONENT_TYPE_GET_VARIABLE_ACTION = 1005,
COMPONENT_TYPE_EVAL_ACTION = 1006,
COMPONENT_TYPE_SET_VARIABLE_ACTION = 1007,
COMPONENT_TYPE_SWITCH_ACTION = 1009,
COMPONENT_TYPE_COMPARE_ACTION = 1009,
COMPONENT_TYPE_IS_TRUE_ACTION = 1010,
COMPONENT_TYPE_CONSTANT_ACTION = 1011,
COMPONENT_TYPE_DATE_NOW_ACTION = 1012,
COMPONENT_TYPE_READ_SETTING_ACTION = 1013,
COMPONENT_TYPE_WRITE_SETTINGS_ACTION = 1014,
COMPONENT_TYPE_LOG_ACTION = 1015,
COMPONENT_TYPE_CALL_ACTION_ACTION = 1016,
COMPONENT_TYPE_COMMENT_ACTION = 1017,
COMPONENT_TYPE_DELAY_ACTION = 1018,
COMPONENT_TYPE_ERROR_ACTION = 1019,
COMPONENT_TYPE_CATCH_ERROR_ACTION = 1020,
COMPONENT_TYPE_COUNTER_ACTION = 1021,
COMPONENT_TYPE_LOOP_ACTION = 1021,
COMPONENT_TYPE_SHOW_PAGE_ACTION = 1022,
COMPONENT_TYPE_SCPI_ACTION = 1023
};

Expand Down Expand Up @@ -185,33 +173,10 @@ enum Component_INPUT_EMBEDDED_WIDGET_Properties {
INPUT_EMBEDDED_WIDGET_PROPERTY_UNIT = 4
};

enum Component_GET_VARIABLE_ACTION_COMPONENT_Properties {
GET_VARIABLE_ACTION_COMPONENT_PROPERTY_VARIABLE = 0
};

enum Component_SET_VARIABLE_ACTION_COMPONENT_Properties {
SET_VARIABLE_ACTION_COMPONENT_PROPERTY_VALUE = 0
};

enum Component_COMPARE_ACTION_COMPONENT_Properties {
COMPARE_ACTION_COMPONENT_PROPERTY_A = 0,
COMPARE_ACTION_COMPONENT_PROPERTY_B = 1,
COMPARE_ACTION_COMPONENT_PROPERTY_C = 2
};

enum Component_IS_TRUE_ACTION_COMPONENT_Properties {
IS_TRUE_ACTION_COMPONENT_PROPERTY_VALUE = 0
};

enum Component_READ_SETTING_ACTION_COMPONENT_Properties {
READ_SETTING_ACTION_COMPONENT_PROPERTY_KEY = 0
};

enum Component_WRITE_SETTINGS_ACTION_COMPONENT_Properties {
WRITE_SETTINGS_ACTION_COMPONENT_PROPERTY_KEY = 0,
WRITE_SETTINGS_ACTION_COMPONENT_PROPERTY_VALUE = 1
};

enum Component_LOG_ACTION_COMPONENT_Properties {
LOG_ACTION_COMPONENT_PROPERTY_VALUE = 0
};
Expand All @@ -220,10 +185,6 @@ enum Component_DELAY_ACTION_COMPONENT_Properties {
DELAY_ACTION_COMPONENT_PROPERTY_MILLISECONDS = 0
};

enum Component_ERROR_ACTION_COMPONENT_Properties {
ERROR_ACTION_COMPONENT_PROPERTY_MESSAGE = 0
};

enum Component_LOOP_ACTION_COMPONENT_Properties {
LOOP_ACTION_COMPONENT_PROPERTY_FROM = 0,
LOOP_ACTION_COMPONENT_PROPERTY_TO = 1,
Expand Down
1 change: 1 addition & 0 deletions src/eez/flow/operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ EvalOperation g_evalOperations[] = {
do_OPERATION_TYPE_MATH_SIN,
do_OPERATION_TYPE_MATH_COS,
do_OPERATION_TYPE_MATH_LOG,
do_OPERATION_TYPE_MATH_ABS,
do_OPERATION_TYPE_STRING_FIND,
do_OPERATION_TYPE_ARRAY_SLICE
};
Expand Down
1 change: 1 addition & 0 deletions src/eez/flow/private.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ void throwError(FlowState *flowState, int componentIndex, const char *errorMessa
);
} else {
flowState->error = true;
onFlowError(flowState, componentIndex, errorMessage);
scripting::stopScript();
}
}
Expand Down

0 comments on commit cbf3db8

Please sign in to comment.