Skip to content

Commit 3df6e41

Browse files
committed
switch component debugging
1 parent 5d018ef commit 3df6e41

File tree

13 files changed

+141
-50
lines changed

13 files changed

+141
-50
lines changed

src/eez/flow/components/log.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void executeLogComponent(Assets *assets, FlowState *flowState, Component *compon
4141
return;
4242
}
4343

44-
const char *valueStr = value.toString(assets);
44+
const char *valueStr = value.toString(assets).getString();
4545
if (valueStr && *valueStr) {
4646
DebugTrace(valueStr);
4747
if (valueStr[strlen(valueStr) - 1] != '\n') {

src/eez/flow/components/scpi.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ void executeScpiComponent(Assets *assets, FlowState *flowState, Component *compo
136136
size_t resultTextLen;
137137
int err;
138138
if (!scripting::getLatestScpiResult(&resultText, &resultTextLen, &err)) {
139-
char errorMessage[256];
139+
char errorMessage[300];
140140
snprintf(errorMessage, sizeof(errorMessage), "scpi component error: '%s', %s\n", scpiComponentExecutionState->commandOrQueryText, SCPI_ErrorTranslate(err));
141141
throwError(errorMessage);
142142
return;
@@ -152,7 +152,7 @@ void executeScpiComponent(Assets *assets, FlowState *flowState, Component *compo
152152

153153
scpiComponentExecutionState->commandOrQueryText[0] = 0;
154154

155-
Value srcValue(resultText, resultTextLen);
155+
Value srcValue = Value::makeStringRef(resultText, resultTextLen);
156156

157157
assignValue(assets, flowState, component, dstValue, srcValue);
158158
} else if (scpiComponentExecutionState->op == SCPI_PART_QUERY) {

src/eez/flow/components/switch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace flow {
3434

3535
void executeSwitchComponent(Assets *assets, FlowState *flowState, Component *component, ComponenentExecutionState *&componentExecutionState) {
3636
struct SwitchTest {
37-
uint16_t outputIndex;
37+
uint8_t outputIndex;
3838
uint8_t conditionInstructions[1];
3939
};
4040

src/eez/flow/flow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ void dataOperation(unsigned flowHandle, int16_t dataId, DataOperationEnum operat
131131
auto inputWidget = (InputWidget *)widgetCursor.widget;
132132

133133
auto unitValue = get(widgetCursor, inputWidget->unit);
134-
Unit unit = getUnitFromName(unitValue.toString(assets));
134+
Unit unit = getUnitFromName(unitValue.toString(assets).getString());
135135

136136
if (operation == DATA_OPERATION_GET_MIN) {
137137
value = Value(get(widgetCursor, inputWidget->min).toFloat(), unit);

src/eez/flow/operations.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ bool do_OPERATION_TYPE_ADD(EvalStack &stack) {
3636
b = *b.pValue_;
3737
}
3838

39+
if (a.isAnyStringType() || b.isAnyStringType()) {
40+
const char *aStr = a.toString(stack.assets).getString();
41+
const char *bStr = b.toString(stack.assets).getString();
42+
if (aStr && bStr) {
43+
stack.push(Value::concatenateString(aStr, bStr));
44+
return true;
45+
}
46+
}
47+
3948
if (a.isDouble() || b.isDouble()) {
4049
stack.push(Value(a.toDouble() + b.toDouble(), VALUE_TYPE_DOUBLE));
4150
return true;
@@ -56,14 +65,6 @@ bool do_OPERATION_TYPE_ADD(EvalStack &stack) {
5665
return true;
5766
}
5867

59-
if (a.isAnyStringType() && b.isAnyStringType()) {
60-
const char *aStr = a.toString(stack.assets);
61-
const char *bStr = b.toString(stack.assets);
62-
if (aStr && bStr) {
63-
stack.push(Value::concatenateString(aStr, bStr));
64-
}
65-
}
66-
6768
return false;
6869
}
6970

@@ -238,8 +239,8 @@ bool do_OPERATION_TYPE_STRING_FIND(EvalStack &stack) {
238239
b = *b.pValue_;
239240
}
240241

241-
const char *aStr = a.toString(stack.assets);
242-
const char *bStr = b.toString(stack.assets);
242+
const char *aStr = a.toString(stack.assets).getString();
243+
const char *bStr = b.toString(stack.assets).getString();
243244
if (!aStr || !bStr) {
244245
stack.push(Value(-1, VALUE_TYPE_INT32));
245246
} else {

src/eez/flow/private.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ void propagateValue(Assets *assets, FlowState *flowState, ComponentOutput &compo
111111
auto connection = componentOutput.connections.item(assets, connectionIndex);
112112
flowState->values[connection->targetInputIndex] = value;
113113
pingComponent(assets, flowState, connection->targetComponentIndex);
114+
if (connection->seqIn) {
115+
flowState->values[connection->targetInputIndex] = Value();
116+
}
114117
}
115118
}
116119

src/eez/gui/assets.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,19 @@ bool decompressAssetsData(const uint8_t *assetsData, uint32_t assetsDataSize, As
7575
compressedDataOffset = sizeof(Header);
7676
decompressedSize = header->decompressedSize;
7777

78+
// disable warning: offsetof within non-standard-layout type ... is conditionally-supported [-Winvalid-offsetof]
79+
#ifdef __GNUC__
80+
#pragma GCC diagnostic push
81+
#pragma GCC diagnostic ignored "-Winvalid-offsetof"
82+
#endif
83+
7884
auto decompressedDataOffset = offsetof(Assets, pages);
7985

86+
#ifdef __GNUC__
87+
#pragma GCC diagnostic pop
88+
#endif
89+
90+
8091
if (decompressedDataOffset + decompressedSize > maxDecompressedAssetsSize) {
8192
if (err) {
8293
*err = SCPI_ERROR_OUT_OF_DEVICE_MEMORY;
@@ -93,7 +104,7 @@ bool decompressAssetsData(const uint8_t *assetsData, uint32_t assetsDataSize, As
93104
decompressedSize
94105
);
95106

96-
if (decompressResult != decompressedSize) {
107+
if (decompressResult != (int)decompressedSize) {
97108
if (err) {
98109
*err = SCPI_ERROR_INVALID_BLOCK_DATA;
99110
}
@@ -159,8 +170,18 @@ bool loadExternalAssets(const char *filePath, int *err) {
159170
return false;
160171
}
161172

173+
// disable warning: offsetof within non-standard-layout type ... is conditionally-supported [-Winvalid-offsetof]
174+
#ifdef __GNUC__
175+
#pragma GCC diagnostic push
176+
#pragma GCC diagnostic ignored "-Winvalid-offsetof"
177+
#endif
178+
162179
auto decompressedDataOffset = offsetof(Assets, pages);
163180

181+
#ifdef __GNUC__
182+
#pragma GCC diagnostic pop
183+
#endif
184+
164185
size_t externalAssetsSize = decompressedDataOffset + header->decompressedSize;
165186
g_externalAssets = (Assets *)alloc(externalAssetsSize);
166187
if (!g_externalAssets) {

src/eez/gui/assets.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ struct PropertyValue {
215215
struct Connection {
216216
uint16_t targetComponentIndex;
217217
uint8_t targetInputIndex;
218+
uint8_t seqIn;
218219
};
219220

220221
struct ComponentOutput {

src/eez/gui/data.cpp

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <math.h>
2222
#include <stdio.h>
2323
#include <string.h>
24+
#include <inttypes.h>
2425

2526
#include <eez/util.h>
2627

@@ -767,15 +768,66 @@ bool Value::isMega() const {
767768

768769
}
769770

770-
const char *Value::toString(Assets *assets) const {
771-
if (type_ == VALUE_TYPE_STRING) {
772-
return str_;
773-
} else if (type_ == VALUE_TYPE_STRING_REF) {
774-
return refString_.str;
775-
} else if (type_ == VALUE_TYPE_ASSETS_STRING) {
776-
return ((AssetsPtr<const char> *)&assetsString_)->ptr(assets);
771+
Value Value::toString(Assets *assets) const {
772+
if (type_ == VALUE_TYPE_STRING || type_ == VALUE_TYPE_STRING_REF) {
773+
return *this;
777774
}
778-
return nullptr;
775+
776+
if (type_ == VALUE_TYPE_ASSETS_STRING) {
777+
return Value(((AssetsPtr<const char> *)&assetsString_)->ptr(assets));
778+
}
779+
780+
char tempStr[64];
781+
782+
#ifdef _MSC_VER
783+
#pragma warning(push)
784+
#pragma warning(disable : 4474)
785+
#endif
786+
787+
if (type_ == VALUE_TYPE_DOUBLE) {
788+
snprintf(tempStr, sizeof(tempStr), "%g", double_);
789+
} else if (type_ == VALUE_TYPE_FLOAT) {
790+
snprintf(tempStr, sizeof(tempStr), "%g", float_);
791+
} else if (type_ == VALUE_TYPE_INT8) {
792+
snprintf(tempStr, sizeof(tempStr), PRId8, int8_);
793+
} else if (type_ == VALUE_TYPE_UINT8) {
794+
snprintf(tempStr, sizeof(tempStr), PRIu8, uint8_);
795+
} else if (type_ == VALUE_TYPE_INT16) {
796+
snprintf(tempStr, sizeof(tempStr), PRId16, int16_);
797+
} else if (type_ == VALUE_TYPE_UINT16) {
798+
snprintf(tempStr, sizeof(tempStr), PRIu16, uint16_);
799+
} else if (type_ == VALUE_TYPE_INT32) {
800+
snprintf(tempStr, sizeof(tempStr), PRId32, int32_);
801+
} else if (type_ == VALUE_TYPE_UINT32) {
802+
snprintf(tempStr, sizeof(tempStr), PRIu32, uint32_);
803+
} else if (type_ == VALUE_TYPE_INT64) {
804+
snprintf(tempStr, sizeof(tempStr), PRId64, int64_);
805+
} else if (type_ == VALUE_TYPE_UINT64) {
806+
snprintf(tempStr, sizeof(tempStr), PRIu64, uint64_);
807+
}
808+
809+
#ifdef _MSC_VER
810+
#pragma warning(pop)
811+
#endif
812+
813+
return makeStringRef(tempStr, strlen(tempStr));
814+
815+
}
816+
817+
Value Value::makeStringRef(const char *str, size_t len) {
818+
Value value;
819+
820+
auto newStr = (char *)alloc(len + 1);
821+
stringCopyLength(newStr, len + 1, str, len);
822+
823+
value.type_ = VALUE_TYPE_STRING_REF;
824+
value.unit_ = 0;
825+
value.options_ = 0;
826+
value.reserved_ = 0;
827+
value.refString_.refCounter = 1;
828+
value.refString_.str = newStr;
829+
830+
return value;
779831
}
780832

781833
Value Value::concatenateString(const char *str1, const char *str2) {
@@ -790,7 +842,6 @@ Value Value::concatenateString(const char *str1, const char *str2) {
790842
value.unit_ = 0;
791843
value.options_ = 0;
792844
value.reserved_ = 0;
793-
794845
value.refString_.refCounter = 1;
795846
value.refString_.str = newStr;
796847

src/eez/gui/data.h

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,6 @@ struct Value {
106106
{
107107
}
108108

109-
Value(const char *str, size_t len)
110-
: type_(VALUE_TYPE_STRING_REF), unit_(UNIT_UNKNOWN), options_(0)
111-
{
112-
auto newStr = (char *)alloc(len + 1);
113-
stringCopyLength(newStr, len + 1, str, len);
114-
115-
refString_.refCounter = 1;
116-
refString_.str = newStr;
117-
}
118-
119109
Value(int version, const char *str)
120110
: type_(VALUE_TYPE_VERSIONED_STRING), unit_(version), options_(0), str_(str)
121111
{
@@ -140,11 +130,21 @@ struct Value {
140130
{
141131
}
142132

133+
Value(int8_t value, ValueType type)
134+
: type_(type), unit_(UNIT_UNKNOWN), options_(0), uint8_(value)
135+
{
136+
}
137+
143138
Value(uint8_t value, ValueType type)
144139
: type_(type), unit_(UNIT_UNKNOWN), options_(0), uint8_(value)
145140
{
146141
}
147142

143+
Value(int16_t value, ValueType type)
144+
: type_(type), unit_(UNIT_UNKNOWN), options_(0), int16_(value)
145+
{
146+
}
147+
148148
Value(uint16_t value, ValueType type)
149149
: type_(type), unit_(UNIT_UNKNOWN), options_(0), uint16_(value)
150150
{
@@ -155,6 +155,16 @@ struct Value {
155155
{
156156
}
157157

158+
Value(int64_t value, ValueType type)
159+
: type_(type), unit_(UNIT_UNKNOWN), options_(0), int64_(value)
160+
{
161+
}
162+
163+
Value(uint64_t value, ValueType type)
164+
: type_(type), unit_(UNIT_UNKNOWN), options_(0), uint64_(value)
165+
{
166+
}
167+
158168
Value(float value, Unit unit)
159169
: type_(VALUE_TYPE_FLOAT), unit_(unit), options_(0), float_(value)
160170
{
@@ -174,10 +184,6 @@ struct Value {
174184
: type_(type), unit_(UNIT_UNKNOWN), options_(0), double_(value) {
175185
}
176186

177-
Value(int64_t value, ValueType type)
178-
: type_(type), unit_(UNIT_UNKNOWN), options_(0), int64_(value) {
179-
}
180-
181187
Value(const char *value, ValueType type, int16_t options)
182188
: type_(type), unit_(UNIT_UNKNOWN), options_(options), str_(value)
183189
{
@@ -275,11 +281,11 @@ struct Value {
275281
return type_ == VALUE_TYPE_BOOLEAN;
276282
}
277283

278-
bool isString() {
284+
bool isString() const {
279285
return type_ == VALUE_TYPE_STRING;
280286
}
281287

282-
bool isAnyStringType() {
288+
bool isAnyStringType() const {
283289
return type_ == VALUE_TYPE_STRING || type_ == VALUE_TYPE_STRING_REF || type_ == VALUE_TYPE_ASSETS_STRING;
284290
}
285291

@@ -332,6 +338,9 @@ struct Value {
332338
}
333339

334340
const char *getString() const {
341+
if (type_ == VALUE_TYPE_STRING_REF) {
342+
return refString_.str;
343+
}
335344
return str_;
336345
}
337346

@@ -587,8 +596,10 @@ struct Value {
587596
return 0;
588597
}
589598

590-
const char *toString(Assets *assets) const;
599+
Value toString(Assets *assets) const;
591600

601+
static Value makeStringRef(const char *str, size_t len);
602+
592603
static Value concatenateString(const char *str1, const char *str2);
593604

594605
//////////

0 commit comments

Comments
 (0)