Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Jan 30, 2021
1 parent 27a6a4d commit 495ab6f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/eez/modules/psu/channel_dispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ float getUMaxOvpLevel(const Channel &channel) {

float getUProtectionLevel(const Channel &channel) {
if (channel.channelIndex < 2 && g_couplingType == COUPLING_TYPE_SERIES) {
return Channel::get(0).prot_conf.u_level + Channel::get(1).prot_conf.u_level;
return Channel::get(0).prot_conf.u_level + Channel::get(1).prot_conf.u_level + 0.01;
}
return channel.prot_conf.u_level;
}
Expand Down
27 changes: 13 additions & 14 deletions src/eez/modules/psu/gui/psu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -931,21 +931,19 @@ bool PsuAppContext::dialogOpen(int *err) {
}

DialogActionResult PsuAppContext::dialogAction(uint32_t timeoutMs, const char *&selectedActionName) {
if (timeoutMs == 0) {
timeoutMs = 1000;
}
timeoutMs = millis() + timeoutMs;

while ((int32_t)(millis() - timeoutMs) < 0) {
if (g_externalActionId != ACTION_ID_NONE) {
break;
}

if (!isPageOnStack(getExternalAssetsFirstPageId())) {
break;
}
if (timeoutMs != 0) {
timeoutMs = millis() + timeoutMs;
if (timeoutMs == 0) {
timeoutMs = 1;
}
}

osDelay(5);
while (
(timeoutMs == 0 || (int32_t)(millis() - timeoutMs) < 0) &&
g_externalActionId == ACTION_ID_NONE &&
isPageOnStack(getExternalAssetsFirstPageId())
) {
osDelay(5);
}

if (g_externalActionId != ACTION_ID_NONE) {
Expand All @@ -957,6 +955,7 @@ DialogActionResult PsuAppContext::dialogAction(uint32_t timeoutMs, const char *&
return isPageOnStack(getExternalAssetsFirstPageId()) ? DIALOG_ACTION_RESULT_TIMEOUT : DIALOG_ACTION_RESULT_EXIT;
}


void PsuAppContext::dialogResetDataItemValues() {
for (uint32_t i = 0; i < MAX_NUM_EXTERNAL_DATA_ITEM_VALUES; i++) {
g_externalDataItemValues[i].value = Value();
Expand Down
44 changes: 24 additions & 20 deletions src/eez/mp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,29 +318,33 @@ bool scpi(const char *commandOrQueryText, const char **resultText, size_t *resul
// DebugTrace("> %s\n", commandOrQueryText);

g_scpiDataLen = 0;

g_lastError = 0;

#if 1
g_commandOrQueryText = commandOrQueryText;
sendMessageToLowPriorityThread(MP_EXECUTE_SCPI);

static const uint32_t SCPI_TIMEOUT = 3000;

while (true) {
osEvent event = osMessageGet(g_mpMessageQueueId, SCPI_TIMEOUT);
if (event.status == osEventMessage && event.value.v == QUEUE_MESSAGE_SCPI_RESULT) {
break;
} else {
static char g_scpiError[48];
snprintf(g_scpiError, sizeof(g_scpiError), "SCPI timeout");
mp_raise_ValueError(g_scpiError);
}
bool executeInLowPriorityThread = true;
if (startsWithNoCase(commandOrQueryText, "DISP:INPUT?") || startsWithNoCase(commandOrQueryText, "DISP:DIALOG:ACTION?")) {
executeInLowPriorityThread = false;
}

if (executeInLowPriorityThread) {
g_commandOrQueryText = commandOrQueryText;
sendMessageToLowPriorityThread(MP_EXECUTE_SCPI);

static const uint32_t SCPI_TIMEOUT = 3000;

while (true) {
osEvent event = osMessageGet(g_mpMessageQueueId, SCPI_TIMEOUT);
if (event.status == osEventMessage && event.value.v == QUEUE_MESSAGE_SCPI_RESULT) {
break;
} else {
static char g_scpiError[48];
snprintf(g_scpiError, sizeof(g_scpiError), "SCPI timeout");
mp_raise_ValueError(g_scpiError);
}
}
} else {
input(g_scpiContext, (const char *)commandOrQueryText, strlen(commandOrQueryText));
input(g_scpiContext, "\r\n", 2);
}
#else
input(g_scpiContext, (const char *)commandOrQueryText, strlen(commandOrQueryText));
input(g_scpiContext, "\r\n", 2);
#endif

if (g_lastError != 0) {
static char g_scpiError[48];
Expand Down
10 changes: 10 additions & 0 deletions src/eez/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,16 @@ bool startsWith(const char *str, const char *prefix) {
return strncmp(str, prefix, prefixLen) == 0;
}

bool startsWithNoCase(const char *str, const char *prefix) {
if (!str || !prefix)
return false;
size_t strLen = strlen(str);
size_t prefixLen = strlen(prefix);
if (prefixLen > strLen)
return false;
return strncicmp(str, prefix, prefixLen) == 0;
}

bool endsWith(const char *str, const char *suffix) {
if (!str || !suffix)
return false;
Expand Down
1 change: 1 addition & 0 deletions src/eez/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ int strcicmp(char const *a, char const *b);
int strncicmp(char const *a, char const *b, int n);
bool isStringEmpty(char const *a);
bool startsWith(const char *str, const char *prefix);
bool startsWithNoCase(const char *str, const char *prefix);
bool endsWith(const char *str, const char *suffix);
bool endsWithNoCase(const char *str, const char *suffix);

Expand Down

0 comments on commit 495ab6f

Please sign in to comment.