Skip to content

Commit

Permalink
switch component debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Aug 3, 2021
1 parent 5d018ef commit 3df6e41
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 50 deletions.
2 changes: 1 addition & 1 deletion src/eez/flow/components/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void executeLogComponent(Assets *assets, FlowState *flowState, Component *compon
return;
}

const char *valueStr = value.toString(assets);
const char *valueStr = value.toString(assets).getString();
if (valueStr && *valueStr) {
DebugTrace(valueStr);
if (valueStr[strlen(valueStr) - 1] != '\n') {
Expand Down
4 changes: 2 additions & 2 deletions src/eez/flow/components/scpi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void executeScpiComponent(Assets *assets, FlowState *flowState, Component *compo
size_t resultTextLen;
int err;
if (!scripting::getLatestScpiResult(&resultText, &resultTextLen, &err)) {
char errorMessage[256];
char errorMessage[300];
snprintf(errorMessage, sizeof(errorMessage), "scpi component error: '%s', %s\n", scpiComponentExecutionState->commandOrQueryText, SCPI_ErrorTranslate(err));
throwError(errorMessage);
return;
Expand All @@ -152,7 +152,7 @@ void executeScpiComponent(Assets *assets, FlowState *flowState, Component *compo

scpiComponentExecutionState->commandOrQueryText[0] = 0;

Value srcValue(resultText, resultTextLen);
Value srcValue = Value::makeStringRef(resultText, resultTextLen);

assignValue(assets, flowState, component, dstValue, srcValue);
} else if (scpiComponentExecutionState->op == SCPI_PART_QUERY) {
Expand Down
2 changes: 1 addition & 1 deletion src/eez/flow/components/switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace flow {

void executeSwitchComponent(Assets *assets, FlowState *flowState, Component *component, ComponenentExecutionState *&componentExecutionState) {
struct SwitchTest {
uint16_t outputIndex;
uint8_t outputIndex;
uint8_t conditionInstructions[1];
};

Expand Down
2 changes: 1 addition & 1 deletion src/eez/flow/flow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void dataOperation(unsigned flowHandle, int16_t dataId, DataOperationEnum operat
auto inputWidget = (InputWidget *)widgetCursor.widget;

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

if (operation == DATA_OPERATION_GET_MIN) {
value = Value(get(widgetCursor, inputWidget->min).toFloat(), unit);
Expand Down
21 changes: 11 additions & 10 deletions src/eez/flow/operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ bool do_OPERATION_TYPE_ADD(EvalStack &stack) {
b = *b.pValue_;
}

if (a.isAnyStringType() || b.isAnyStringType()) {
const char *aStr = a.toString(stack.assets).getString();
const char *bStr = b.toString(stack.assets).getString();
if (aStr && bStr) {
stack.push(Value::concatenateString(aStr, bStr));
return true;
}
}

if (a.isDouble() || b.isDouble()) {
stack.push(Value(a.toDouble() + b.toDouble(), VALUE_TYPE_DOUBLE));
return true;
Expand All @@ -56,14 +65,6 @@ bool do_OPERATION_TYPE_ADD(EvalStack &stack) {
return true;
}

if (a.isAnyStringType() && b.isAnyStringType()) {
const char *aStr = a.toString(stack.assets);
const char *bStr = b.toString(stack.assets);
if (aStr && bStr) {
stack.push(Value::concatenateString(aStr, bStr));
}
}

return false;
}

Expand Down Expand Up @@ -238,8 +239,8 @@ bool do_OPERATION_TYPE_STRING_FIND(EvalStack &stack) {
b = *b.pValue_;
}

const char *aStr = a.toString(stack.assets);
const char *bStr = b.toString(stack.assets);
const char *aStr = a.toString(stack.assets).getString();
const char *bStr = b.toString(stack.assets).getString();
if (!aStr || !bStr) {
stack.push(Value(-1, VALUE_TYPE_INT32));
} else {
Expand Down
3 changes: 3 additions & 0 deletions src/eez/flow/private.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ void propagateValue(Assets *assets, FlowState *flowState, ComponentOutput &compo
auto connection = componentOutput.connections.item(assets, connectionIndex);
flowState->values[connection->targetInputIndex] = value;
pingComponent(assets, flowState, connection->targetComponentIndex);
if (connection->seqIn) {
flowState->values[connection->targetInputIndex] = Value();
}
}
}

Expand Down
23 changes: 22 additions & 1 deletion src/eez/gui/assets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,19 @@ bool decompressAssetsData(const uint8_t *assetsData, uint32_t assetsDataSize, As
compressedDataOffset = sizeof(Header);
decompressedSize = header->decompressedSize;

// disable warning: offsetof within non-standard-layout type ... is conditionally-supported [-Winvalid-offsetof]
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Winvalid-offsetof"
#endif

auto decompressedDataOffset = offsetof(Assets, pages);

#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif


if (decompressedDataOffset + decompressedSize > maxDecompressedAssetsSize) {
if (err) {
*err = SCPI_ERROR_OUT_OF_DEVICE_MEMORY;
Expand All @@ -93,7 +104,7 @@ bool decompressAssetsData(const uint8_t *assetsData, uint32_t assetsDataSize, As
decompressedSize
);

if (decompressResult != decompressedSize) {
if (decompressResult != (int)decompressedSize) {
if (err) {
*err = SCPI_ERROR_INVALID_BLOCK_DATA;
}
Expand Down Expand Up @@ -159,8 +170,18 @@ bool loadExternalAssets(const char *filePath, int *err) {
return false;
}

// disable warning: offsetof within non-standard-layout type ... is conditionally-supported [-Winvalid-offsetof]
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Winvalid-offsetof"
#endif

auto decompressedDataOffset = offsetof(Assets, pages);

#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif

size_t externalAssetsSize = decompressedDataOffset + header->decompressedSize;
g_externalAssets = (Assets *)alloc(externalAssetsSize);
if (!g_externalAssets) {
Expand Down
1 change: 1 addition & 0 deletions src/eez/gui/assets.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ struct PropertyValue {
struct Connection {
uint16_t targetComponentIndex;
uint8_t targetInputIndex;
uint8_t seqIn;
};

struct ComponentOutput {
Expand Down
69 changes: 60 additions & 9 deletions src/eez/gui/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <inttypes.h>

#include <eez/util.h>

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

}

const char *Value::toString(Assets *assets) const {
if (type_ == VALUE_TYPE_STRING) {
return str_;
} else if (type_ == VALUE_TYPE_STRING_REF) {
return refString_.str;
} else if (type_ == VALUE_TYPE_ASSETS_STRING) {
return ((AssetsPtr<const char> *)&assetsString_)->ptr(assets);
Value Value::toString(Assets *assets) const {
if (type_ == VALUE_TYPE_STRING || type_ == VALUE_TYPE_STRING_REF) {
return *this;
}
return nullptr;

if (type_ == VALUE_TYPE_ASSETS_STRING) {
return Value(((AssetsPtr<const char> *)&assetsString_)->ptr(assets));
}

char tempStr[64];

#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4474)
#endif

if (type_ == VALUE_TYPE_DOUBLE) {
snprintf(tempStr, sizeof(tempStr), "%g", double_);
} else if (type_ == VALUE_TYPE_FLOAT) {
snprintf(tempStr, sizeof(tempStr), "%g", float_);
} else if (type_ == VALUE_TYPE_INT8) {
snprintf(tempStr, sizeof(tempStr), PRId8, int8_);
} else if (type_ == VALUE_TYPE_UINT8) {
snprintf(tempStr, sizeof(tempStr), PRIu8, uint8_);
} else if (type_ == VALUE_TYPE_INT16) {
snprintf(tempStr, sizeof(tempStr), PRId16, int16_);
} else if (type_ == VALUE_TYPE_UINT16) {
snprintf(tempStr, sizeof(tempStr), PRIu16, uint16_);
} else if (type_ == VALUE_TYPE_INT32) {
snprintf(tempStr, sizeof(tempStr), PRId32, int32_);
} else if (type_ == VALUE_TYPE_UINT32) {
snprintf(tempStr, sizeof(tempStr), PRIu32, uint32_);
} else if (type_ == VALUE_TYPE_INT64) {
snprintf(tempStr, sizeof(tempStr), PRId64, int64_);
} else if (type_ == VALUE_TYPE_UINT64) {
snprintf(tempStr, sizeof(tempStr), PRIu64, uint64_);
}

#ifdef _MSC_VER
#pragma warning(pop)
#endif

return makeStringRef(tempStr, strlen(tempStr));

}

Value Value::makeStringRef(const char *str, size_t len) {
Value value;

auto newStr = (char *)alloc(len + 1);
stringCopyLength(newStr, len + 1, str, len);

value.type_ = VALUE_TYPE_STRING_REF;
value.unit_ = 0;
value.options_ = 0;
value.reserved_ = 0;
value.refString_.refCounter = 1;
value.refString_.str = newStr;

return value;
}

Value Value::concatenateString(const char *str1, const char *str2) {
Expand All @@ -790,7 +842,6 @@ Value Value::concatenateString(const char *str1, const char *str2) {
value.unit_ = 0;
value.options_ = 0;
value.reserved_ = 0;

value.refString_.refCounter = 1;
value.refString_.str = newStr;

Expand Down
45 changes: 28 additions & 17 deletions src/eez/gui/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,6 @@ struct Value {
{
}

Value(const char *str, size_t len)
: type_(VALUE_TYPE_STRING_REF), unit_(UNIT_UNKNOWN), options_(0)
{
auto newStr = (char *)alloc(len + 1);
stringCopyLength(newStr, len + 1, str, len);

refString_.refCounter = 1;
refString_.str = newStr;
}

Value(int version, const char *str)
: type_(VALUE_TYPE_VERSIONED_STRING), unit_(version), options_(0), str_(str)
{
Expand All @@ -140,11 +130,21 @@ struct Value {
{
}

Value(int8_t value, ValueType type)
: type_(type), unit_(UNIT_UNKNOWN), options_(0), uint8_(value)
{
}

Value(uint8_t value, ValueType type)
: type_(type), unit_(UNIT_UNKNOWN), options_(0), uint8_(value)
{
}

Value(int16_t value, ValueType type)
: type_(type), unit_(UNIT_UNKNOWN), options_(0), int16_(value)
{
}

Value(uint16_t value, ValueType type)
: type_(type), unit_(UNIT_UNKNOWN), options_(0), uint16_(value)
{
Expand All @@ -155,6 +155,16 @@ struct Value {
{
}

Value(int64_t value, ValueType type)
: type_(type), unit_(UNIT_UNKNOWN), options_(0), int64_(value)
{
}

Value(uint64_t value, ValueType type)
: type_(type), unit_(UNIT_UNKNOWN), options_(0), uint64_(value)
{
}

Value(float value, Unit unit)
: type_(VALUE_TYPE_FLOAT), unit_(unit), options_(0), float_(value)
{
Expand All @@ -174,10 +184,6 @@ struct Value {
: type_(type), unit_(UNIT_UNKNOWN), options_(0), double_(value) {
}

Value(int64_t value, ValueType type)
: type_(type), unit_(UNIT_UNKNOWN), options_(0), int64_(value) {
}

Value(const char *value, ValueType type, int16_t options)
: type_(type), unit_(UNIT_UNKNOWN), options_(options), str_(value)
{
Expand Down Expand Up @@ -275,11 +281,11 @@ struct Value {
return type_ == VALUE_TYPE_BOOLEAN;
}

bool isString() {
bool isString() const {
return type_ == VALUE_TYPE_STRING;
}

bool isAnyStringType() {
bool isAnyStringType() const {
return type_ == VALUE_TYPE_STRING || type_ == VALUE_TYPE_STRING_REF || type_ == VALUE_TYPE_ASSETS_STRING;
}

Expand Down Expand Up @@ -332,6 +338,9 @@ struct Value {
}

const char *getString() const {
if (type_ == VALUE_TYPE_STRING_REF) {
return refString_.str;
}
return str_;
}

Expand Down Expand Up @@ -587,8 +596,10 @@ struct Value {
return 0;
}

const char *toString(Assets *assets) const;
Value toString(Assets *assets) const;

static Value makeStringRef(const char *str, size_t len);

static Value concatenateString(const char *str1, const char *str2);

//////////
Expand Down
2 changes: 1 addition & 1 deletion src/eez/modules/psu/gui/psu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,7 @@ uint32_t g_focusEditValueChangedTime;

static bool isEncoderEnabledForWidget(const WidgetCursor &widgetCursor) {
auto action = getWidgetAction(widgetCursor);
return g_psuAppContext.isWidgetActionEnabled(widgetCursor) && (action == ACTION_ID_EDIT || action == ACTION_ID_SCROLL) || widgetCursor.widget->type == WIDGET_TYPE_INPUT;
return (g_psuAppContext.isWidgetActionEnabled(widgetCursor) && (action == ACTION_ID_EDIT || action == ACTION_ID_SCROLL)) || widgetCursor.widget->type == WIDGET_TYPE_INPUT;
}

static bool g_focusCursorIsEnabled;
Expand Down
15 changes: 9 additions & 6 deletions src/eez/modules/psu/persist_conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,18 @@ void getSystemDerivedMacAddress(uint8_t *macAddress) {
uint32_t idw0 = HAL_GetUIDw0();
uint32_t idw1 = HAL_GetUIDw1();
uint32_t idw2 = HAL_GetUIDw2();

uint8_t *pIdw0 = (uint8_t *)&idw0;
uint8_t *pIdw1 = (uint8_t *)&idw1;
uint8_t *pIdw2 = (uint8_t *)&idw2;
macAddress[0] = pIdw0[0] ^ pIdw1[0] ^ pIdw2[7] ^ pIdw2[0];
macAddress[1] = pIdw0[1] ^ pIdw1[7] ^ pIdw2[6] ^ pIdw2[1];
macAddress[2] = pIdw0[2] ^ pIdw1[1] ^ pIdw2[5] ^ pIdw0[6];
macAddress[3] = pIdw0[3] ^ pIdw1[6] ^ pIdw2[4] ^ pIdw0[7];
macAddress[4] = pIdw0[4] ^ pIdw1[2] ^ pIdw2[3] ^ pIdw1[3];
macAddress[5] = pIdw0[5] ^ pIdw1[5] ^ pIdw2[2] ^ pIdw1[4];


macAddress[0] = pIdw0[0] ^ pIdw1[0] ^ pIdw2[3] ^ pIdw2[0];
macAddress[1] = pIdw0[1] ^ pIdw1[3] ^ pIdw2[2] ^ pIdw2[1];
macAddress[2] = pIdw0[2] ^ pIdw1[1] ^ pIdw2[1] ^ pIdw0[2];
macAddress[3] = pIdw0[3] ^ pIdw1[2] ^ pIdw2[0] ^ pIdw0[3];
macAddress[4] = pIdw0[0] ^ pIdw1[2] ^ pIdw2[3] ^ pIdw1[3];
macAddress[5] = pIdw0[1] ^ pIdw1[1] ^ pIdw2[2] ^ pIdw1[0];
#endif

#if defined(EEZ_PLATFORM_SIMULATOR)
Expand Down
2 changes: 1 addition & 1 deletion src/eez/unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ static const int g_scpiUnits[] = {

Unit getUnitFromName(const char *unitName) {
if (unitName) {
for (int i = 0; i < sizeof(g_unitNames) / sizeof(const char *); i++) {
for (unsigned i = 0; i < sizeof(g_unitNames) / sizeof(const char *); i++) {
if (strcmp(g_unitNames[i], unitName) == 0) {
return (Unit)i;
}
Expand Down

0 comments on commit 3df6e41

Please sign in to comment.