Skip to content

Commit b467658

Browse files
committed
mqtt
1 parent e6751ad commit b467658

File tree

19 files changed

+344
-155
lines changed

19 files changed

+344
-155
lines changed

modular-psu-firmware.eez-project

Lines changed: 70 additions & 56 deletions
Large diffs are not rendered by default.

src/eez/modules/mcu/simulator/display.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,6 @@ void turnOff() {
224224
setColor(0, 0, 0);
225225
fillRect(g_psuAppContext.x, g_psuAppContext.y, g_psuAppContext.x + g_psuAppContext.width - 1, g_psuAppContext.y + g_psuAppContext.height - 1);
226226
updateScreen(g_buffer);
227-
228-
g_buffer = nullptr;
229-
230-
for (int bufferIndex = 0; bufferIndex < NUM_BUFFERS; bufferIndex++) {
231-
delete (uint32_t *)g_buffers[bufferIndex].bufferPointer;
232-
}
233227
}
234228
}
235229

src/eez/modules/psu/channel_dispatcher.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include <eez/modules/psu/psu.h>
2323
#include <eez/modules/psu/init.h>
24+
#include <eez/modules/psu/calibration.h>
2425
#include <eez/modules/psu/channel_dispatcher.h>
2526
#include <eez/modules/psu/event_queue.h>
2627
#include <eez/modules/psu/list_program.h>
@@ -1100,6 +1101,51 @@ void outputEnable(Channel &channel, bool enable) {
11001101
}
11011102
}
11021103

1104+
bool outputEnable(Channel &channel, bool enable, int *err) {
1105+
if (enable != channel.isOutputEnabled()) {
1106+
bool triggerModeEnabled =
1107+
channel_dispatcher::getVoltageTriggerMode(channel) != TRIGGER_MODE_FIXED ||
1108+
channel_dispatcher::getCurrentTriggerMode(channel) != TRIGGER_MODE_FIXED;
1109+
1110+
if (channel.isOutputEnabled()) {
1111+
if (calibration::isEnabled()) {
1112+
if (err) {
1113+
*err = SCPI_ERROR_CAL_OUTPUT_DISABLED;
1114+
}
1115+
return false;
1116+
}
1117+
1118+
if (triggerModeEnabled) {
1119+
trigger::abort();
1120+
} else {
1121+
channel_dispatcher::outputEnable(channel, false);
1122+
}
1123+
} else {
1124+
if (channel_dispatcher::isTripped(channel)) {
1125+
if (err) {
1126+
*err = SCPI_ERROR_CANNOT_EXECUTE_BEFORE_CLEARING_PROTECTION;
1127+
}
1128+
return false;
1129+
}
1130+
1131+
if (triggerModeEnabled && !trigger::isIdle()) {
1132+
if (trigger::isInitiated()) {
1133+
trigger::abort();
1134+
} else {
1135+
if (err) {
1136+
*err = SCPI_ERROR_CANNOT_CHANGE_TRANSIENT_TRIGGER;
1137+
}
1138+
return false;
1139+
}
1140+
}
1141+
1142+
channel_dispatcher::outputEnable(channel, true);
1143+
}
1144+
}
1145+
1146+
return true;
1147+
}
1148+
11031149
void disableOutputForAllChannels() {
11041150
beginOutputEnableSequence();
11051151

src/eez/modules/psu/channel_dispatcher.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ void outputEnableSyncPrepare(Channel &channel);
109109
void outputEnableSyncReady(Channel &channel);
110110

111111
void outputEnable(Channel &channel, bool enable);
112+
bool outputEnable(Channel &channel, bool enable, int *err);
112113
void disableOutputForAllChannels();
113114

114115
void remoteSensingEnable(Channel &channel, bool enable);

src/eez/modules/psu/event_queue.cpp

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <eez/modules/psu/datetime.h>
2626
#include <eez/modules/psu/event_queue.h>
2727
#include <eez/sound.h>
28+
#include <eez/scpi/scpi.h>
2829

2930
namespace eez {
3031
namespace psu {
@@ -40,9 +41,9 @@ static EventQueueHeader g_eventQueue;
4041

4142
static Event g_events[MAX_EVENTS];
4243

43-
static int16_t g_eventsToPush[6];
44+
static const int MAX_EVENTS_TO_PUSH = 10;
45+
static int16_t g_eventsToPush[MAX_EVENTS_TO_PUSH];
4446
static uint8_t g_eventsToPushHead = 0;
45-
static const int MAX_EVENTS_TO_PUSH = sizeof(g_eventsToPush) / sizeof(int16_t);
4647

4748
static uint8_t g_pageIndex = 0;
4849

@@ -137,28 +138,32 @@ Event *getLastErrorEvent() {
137138
return g_eventQueue.lastErrorEventIndex != NULL_INDEX ? readEvent(g_eventQueue.lastErrorEventIndex) : nullptr;
138139
}
139140

140-
int getEventType(Event *e) {
141-
if (!e) {
142-
return EVENT_TYPE_NONE;
143-
}
144-
if (e->eventId >= EVENT_INFO_START_ID) {
141+
int getEventType(int16_t eventId) {
142+
if (eventId >= EVENT_INFO_START_ID) {
145143
return EVENT_TYPE_INFO;
146-
} else if (e->eventId >= EVENT_WARNING_START_ID) {
144+
} else if (eventId >= EVENT_WARNING_START_ID) {
147145
return EVENT_TYPE_WARNING;
148-
} else if (e->eventId != EVENT_TYPE_NONE) {
146+
} else if (eventId != EVENT_TYPE_NONE) {
149147
return EVENT_TYPE_ERROR;
150148
} else {
151149
return EVENT_TYPE_NONE;
152150
}
153151
}
154152

155-
const char *getEventMessage(Event *e) {
153+
int getEventType(Event *e) {
154+
if (!e) {
155+
return EVENT_TYPE_NONE;
156+
}
157+
return getEventType(e->eventId);
158+
}
159+
160+
const char *getEventMessage(int16_t eventId) {
156161
static char message[35];
157162

158163
const char *p_message = 0;
159164

160-
if (e->eventId >= EVENT_INFO_START_ID) {
161-
switch (e->eventId) {
165+
if (eventId >= EVENT_INFO_START_ID) {
166+
switch (eventId) {
162167
#define EVENT_SCPI_ERROR(ID, TEXT)
163168
#define EVENT_ERROR(NAME, ID, TEXT)
164169
#define EVENT_WARNING(NAME, ID, TEXT)
@@ -172,8 +177,8 @@ const char *getEventMessage(Event *e) {
172177
#undef EVENT_WARNING
173178
#undef EVENT_ERROR
174179
}
175-
} else if (e->eventId >= EVENT_WARNING_START_ID) {
176-
switch (e->eventId) {
180+
} else if (eventId >= EVENT_WARNING_START_ID) {
181+
switch (eventId) {
177182
#define EVENT_SCPI_ERROR(ID, TEXT)
178183
#define EVENT_ERROR(NAME, ID, TEXT)
179184
#define EVENT_WARNING(NAME, ID, TEXT) \
@@ -190,7 +195,7 @@ const char *getEventMessage(Event *e) {
190195
p_message = 0;
191196
}
192197
} else {
193-
switch (e->eventId) {
198+
switch (eventId) {
194199
#define EVENT_SCPI_ERROR(ID, TEXT) \
195200
case ID: \
196201
p_message = TEXT; \
@@ -207,7 +212,7 @@ const char *getEventMessage(Event *e) {
207212
#undef EVENT_WARNING
208213
#undef EVENT_ERROR
209214
default:
210-
return SCPI_ErrorTranslate(e->eventId);
215+
return SCPI_ErrorTranslate(eventId);
211216
}
212217
}
213218

@@ -220,13 +225,23 @@ const char *getEventMessage(Event *e) {
220225
return 0;
221226
}
222227

228+
const char *getEventMessage(Event *e) {
229+
if (!e) {
230+
return nullptr;
231+
}
232+
return getEventMessage(e->eventId);
233+
}
234+
223235
void pushEvent(int16_t eventId) {
224236
if (g_eventsToPushHead < MAX_EVENTS_TO_PUSH) {
225237
g_eventsToPush[g_eventsToPushHead] = eventId;
226238
++g_eventsToPushHead;
227239
} else {
228240
DebugTrace("MAX_EVENTS_TO_PUSH exceeded");
229241
}
242+
243+
using namespace scpi;
244+
osMessagePut(g_scpiMessageQueueId, SCPI_QUEUE_MESSAGE(SCPI_QUEUE_MESSAGE_TARGET_NONE, SCPI_QUEUE_MESSAGE_PUSH_EVENT, (uint32_t)(uint16_t)eventId), 0);
230245
}
231246

232247
void markAsRead() {

src/eez/modules/psu/event_queue.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,10 @@ void tick();
289289

290290
Event *getLastErrorEvent();
291291

292+
int getEventType(int16_t eventId);
292293
int getEventType(Event *e);
294+
295+
const char *getEventMessage(int16_t eventId);
293296
const char *getEventMessage(Event *e);
294297

295298
void pushEvent(int16_t eventId);

src/eez/modules/psu/gui/keypad.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ namespace gui {
2828
////////////////////////////////////////////////////////////////////////////////
2929

3030
enum KeypadMode {
31-
KEYPAD_MODE_UPPERCASE,
32-
KEYPAD_MODE_LOWERCASE,
33-
KEYPAD_MODE_SYMBOL
31+
KEYPAD_MODE_LOWERCASE,
32+
KEYPAD_MODE_UPPERCASE,
33+
KEYPAD_MODE_SYMBOL
3434
};
3535

3636
class Keypad : public eez::gui::Page {

src/eez/modules/psu/gui/psu.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,9 @@ void PsuAppContext::onPageChanged(int previousPageId, int activePageId) {
496496
} else if (previousPageId == PAGE_ID_IMAGE_VIEW) {
497497
animateFadeOutFadeIn();
498498
} else if (previousPageId == PAGE_ID_SYS_SETTINGS_MQTT) {
499-
animateSlideRight();
499+
if (activePageId == PAGE_ID_SYS_SETTINGS_ETHERNET) {
500+
animateSlideRight();
501+
}
500502
}
501503
}
502504

src/eez/modules/psu/scpi/debug.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <eez/modules/psu/temperature.h>
3232
#include <eez/modules/psu/ontime.h>
3333
#include <eez/modules/psu/scpi/psu.h>
34+
#include <eez/modules/psu/event_queue.h>
3435

3536
#include <eez/modules/bp3c/relays.h>
3637

@@ -441,6 +442,17 @@ scpi_result_t scpi_cmd_debugBoot(scpi_t *context) {
441442
#endif // DEBUG
442443
}
443444

445+
scpi_result_t scpi_cmd_debugEvent(scpi_t *context) {
446+
int32_t eventId;
447+
if (!SCPI_ParamInt(context, &eventId, TRUE)) {
448+
return SCPI_RES_ERR;
449+
}
450+
451+
event_queue::pushEvent(eventId);
452+
453+
return SCPI_RES_OK;
454+
}
455+
444456
} // namespace scpi
445457
} // namespace psu
446458
} // namespace eez

src/eez/modules/psu/scpi/dlog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ scpi_result_t scpi_cmd_initiateDlogTrace(scpi_t *context) {
825825
#endif
826826
}
827827

828-
scpi_result_t scpi_cmd_dlogTraceData(scpi_t *context) {
828+
scpi_result_t scpi_cmd_senseDlogTraceData(scpi_t *context) {
829829
#if OPTION_SD_CARD
830830
if (!dlog_record::isTraceExecuting()) {
831831
SCPI_ErrorPush(context, SCPI_ERROR_EXECUTION_ERROR);

0 commit comments

Comments
 (0)