diff --git a/scripts/DC Power App/DC Power.app b/scripts/DC Power App/DC Power.app index b50ce5443..954471458 100644 Binary files a/scripts/DC Power App/DC Power.app and b/scripts/DC Power App/DC Power.app differ diff --git a/scripts/DC Power App/DC Power.eez-project b/scripts/DC Power App/DC Power.eez-project index 0320bc246..72c6d3751 100644 --- a/scripts/DC Power App/DC Power.eez-project +++ b/scripts/DC Power App/DC Power.eez-project @@ -144,7 +144,7 @@ "type": "ScpiActionComponent", "left": -245, "top": -145, - "width": 436, + "width": 437, "height": 87, "wireID": "9a5fc5c4-c7a6-4257-c380-281d79c76fa4", "customInputs": [], @@ -207,7 +207,7 @@ "type": "LoopActionComponent", "left": -533, "top": 17, - "width": 196, + "width": 197, "height": 70, "wireID": "71acb5a9-df39-48cb-b0f6-6ce84d5cdaa9", "customInputs": [], @@ -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": [ @@ -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": [ diff --git a/src/eez/flow/components/log.cpp b/src/eez/flow/components/log.cpp index 66f915912..185504ae8 100644 --- a/src/eez/flow/components/log.cpp +++ b/src/eez/flow/components/log.cpp @@ -21,6 +21,7 @@ #include #include #include +#include using namespace eez::gui; @@ -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); diff --git a/src/eez/flow/debugger.cpp b/src/eez/flow/debugger.cpp index d6d3faa12..1728bf344 100644 --- a/src/eez/flow/debugger.cpp +++ b/src/eez/flow/debugger.cpp @@ -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 }; @@ -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); } } @@ -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); } } diff --git a/src/eez/flow/debugger.h b/src/eez/flow/debugger.h index 5bfbe4ed7..cd0d852a3 100644 --- a/src/eez/flow/debugger.h +++ b/src/eez/flow/debugger.h @@ -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); diff --git a/src/eez/flow/flow_defs_v3.h b/src/eez/flow/flow_defs_v3.h index 5a8801b9f..0be301683 100644 --- a/src/eez/flow/flow_defs_v3.h +++ b/src/eez/flow/flow_defs_v3.h @@ -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 }; @@ -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 }; @@ -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, diff --git a/src/eez/flow/operations.cpp b/src/eez/flow/operations.cpp index 9fba78d42..b4726005a 100644 --- a/src/eez/flow/operations.cpp +++ b/src/eez/flow/operations.cpp @@ -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 }; diff --git a/src/eez/flow/private.cpp b/src/eez/flow/private.cpp index e0f555527..80a7fbaab 100644 --- a/src/eez/flow/private.cpp +++ b/src/eez/flow/private.cpp @@ -306,6 +306,7 @@ void throwError(FlowState *flowState, int componentIndex, const char *errorMessa ); } else { flowState->error = true; + onFlowError(flowState, componentIndex, errorMessage); scripting::stopScript(); } }