Skip to content

Commit a6746e3

Browse files
committed
Added getEventCodeString method
1 parent b51959b commit a6746e3

1 file changed

Lines changed: 52 additions & 7 deletions

File tree

client.js

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,9 @@ class Client {
242242
const requestId = this._getRequestId();
243243
// Convert the simple query into a proper EventQuery message.
244244
const eventQuery = this._buildEventQuery(query);
245-
246245

247-
246+
247+
248248
if (!this.isOpen) {
249249
this.queuedRequests[requestId] = { type: "events", query: eventQuery };
250250
} else {
@@ -305,7 +305,7 @@ class Client {
305305
for (const key in query.dataConditions) {
306306
const val = query.dataConditions[key];
307307
const conditions = [];
308-
308+
309309
if (Array.isArray(val)) {
310310
for (const item of val) {
311311
conditions.push({
@@ -319,7 +319,7 @@ class Client {
319319
type: MatchType.Exact
320320
});
321321
}
322-
322+
323323
// Store without any table qualification
324324
dataConds[key] = { conditions };
325325
}
@@ -328,10 +328,10 @@ class Client {
328328

329329
return EventQuery.create(baseQuery);
330330
}
331-
332331

333-
334-
332+
333+
334+
335335

336336
/**
337337
* Converts a numeric CDP event code into a descriptive string.
@@ -363,6 +363,51 @@ class Client {
363363
return flags.join(" + ");
364364
}
365365

366+
/**
367+
* Returns a human‐readable string for a given event code.
368+
*
369+
* @param {number} code - The numeric event code.
370+
* @returns {string} - The corresponding event code string.
371+
*/
372+
getEventCodeString(code) {
373+
// Return empty string if eventCode is zero
374+
if (code === 0) return "";
375+
376+
// Define the flag values (adjust these constants if needed)
377+
const EventCodeFlags = {
378+
AlarmSet: 0x1,
379+
AlarmClr: 0x2,
380+
AlarmAck: 0x4,
381+
AlarmReprise: 0x40
382+
};
383+
384+
// Check for specific combinations first
385+
if (code === EventCodeFlags.AlarmSet) return "AlarmSet";
386+
if (code === EventCodeFlags.AlarmClr) return "AlarmClear";
387+
if (code === EventCodeFlags.AlarmAck) return "Ack";
388+
if (code === EventCodeFlags.AlarmReprise) return "Reprise";
389+
if (code === (EventCodeFlags.AlarmReprise | EventCodeFlags.AlarmSet))
390+
return "RepriseAlarmSet";
391+
if (code === (EventCodeFlags.AlarmReprise | EventCodeFlags.AlarmClr))
392+
return "RepriseAlarmClear";
393+
if (code === (EventCodeFlags.AlarmReprise | EventCodeFlags.AlarmAck))
394+
return "RepriseAck";
395+
396+
// Otherwise, combine the flag strings based on which bits are set.
397+
let s = "";
398+
if (code & EventCodeFlags.AlarmReprise)
399+
s += (s ? "+" : "") + "Reprise";
400+
if (code & EventCodeFlags.AlarmSet)
401+
s += (s ? "+" : "") + "AlarmSet";
402+
if (code & EventCodeFlags.AlarmClr)
403+
s += (s ? "+" : "") + "AlarmClear";
404+
if (code & EventCodeFlags.AlarmAck)
405+
s += (s ? "+" : "") + "Ack";
406+
407+
return s;
408+
}
409+
410+
366411
_handleMessage(ws, message) {
367412
const data = Container.decode(new Uint8Array(message));
368413
this._parseMessage(data);

0 commit comments

Comments
 (0)