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
2930namespace eez {
3031namespace psu {
@@ -40,9 +41,9 @@ static EventQueueHeader g_eventQueue;
4041
4142static 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];
4446static uint8_t g_eventsToPushHead = 0 ;
45- static const int MAX_EVENTS_TO_PUSH = sizeof (g_eventsToPush) / sizeof (int16_t );
4647
4748static 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+
223235void 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
232247void markAsRead () {
0 commit comments