@robotical/webapp-types 3.10.2 → 3.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/dist-types/src/application/ApplicationManager/ApplicationManager.d.ts +12 -1
  2. package/dist-types/src/application/ApplicationManager/ApplicationManager.js +21 -0
  3. package/dist-types/src/application/RAFTs/Marty/Marty.d.ts +14 -0
  4. package/dist-types/src/application/RAFTs/Marty/Marty.js +77 -1
  5. package/dist-types/src/application/RAFTs/Marty/notifications-manager/RICNotificationsManager.d.ts +15 -0
  6. package/dist-types/src/application/RAFTs/Marty/notifications-manager/RICNotificationsManager.js +498 -0
  7. package/dist-types/src/application/RAFTs/Marty/notifications-manager/ReportedWarningsState.d.ts +59 -0
  8. package/dist-types/src/application/RAFTs/Marty/notifications-manager/ReportedWarningsState.js +145 -0
  9. package/dist-types/src/application/RAFTs/RAFT.js +11 -1
  10. package/dist-types/src/components/modals/InBtButAPressed/index.d.ts +2 -0
  11. package/dist-types/src/components/modals/InBtButAPressed/index.js +21 -0
  12. package/dist-types/src/components/modals/InBtButAPressed/styles.d.ts +5 -0
  13. package/dist-types/src/components/modals/InBtButAPressed/styles.js +11 -0
  14. package/dist-types/src/services/logger/Logger.d.ts +5 -5
  15. package/dist-types/src/services/logger/Logger.js +40 -11
  16. package/dist-types/src/store/user-role-context.d.ts +12 -0
  17. package/dist-types/src/store/user-role-context.js +33 -0
  18. package/dist-types/src/types/communication-between-apps/wrapper-communication.d.ts +3 -1
  19. package/dist-types/src/types/communication-between-apps/wrapper-communication.js +2 -0
  20. package/dist-types/src/types/userDeviceInfo.d.ts +6 -0
  21. package/dist-types/src/utils/warranty-service/cookies.d.ts +19 -0
  22. package/dist-types/src/utils/warranty-service/cookies.js +76 -0
  23. package/dist-types/src/utils/warranty-service/warranty-service-utils.d.ts +10 -0
  24. package/dist-types/src/utils/warranty-service/warranty-service-utils.js +232 -0
  25. package/dist-types/src/wrapper-app/WrapperAppManager.d.ts +13 -1
  26. package/dist-types/src/wrapper-app/WrapperAppManager.js +109 -0
  27. package/dist-types/src/wrapper-app/communicators/WebAppCommunicator.js +48 -21
  28. package/dist-types/src/wrapper-app/connectors/MartyConnector/MartyConnector.d.ts +4 -0
  29. package/dist-types/src/wrapper-app/connectors/MartyConnector/MartyConnector.js +13 -0
  30. package/package.json +1 -1
@@ -0,0 +1,498 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import InBtButAPressedModalContent from "../../../../components/modals/InBtButAPressed";
38
+ import modalState from "../../../../state-observables/modal/ModalState";
39
+ import { createElement } from "react";
40
+ import RICServoFaultDetector from "@robotical/ricjs/dist/RICServoFaultDetector";
41
+ import { toast } from "react-toastify";
42
+ import { ReportedWarningsState } from "./ReportedWarningsState";
43
+ import { createTicket, isSerialNumberRegistered } from "../../../../utils/warranty-service/warranty-service-utils";
44
+ import { RICHWElemList_Str } from "@robotical/roboticaljs";
45
+ import Logger from "../../../../services/logger/Logger";
46
+ var SHOW_LOGS = true;
47
+ var TAG = "RICNotificationsManager";
48
+ var USER_WARNING_MESSAGE = {
49
+ registeredUser: "Don't worry, we've logged the issue and our support team will contact you soon. Thanks for your patience!",
50
+ unregisteredUser: "To get things sorted, head over to our 'Help' section and register your Marty for our Warranty Service Program.",
51
+ };
52
+ var CacheManager = /** @class */ (function () {
53
+ function CacheManager() {
54
+ }
55
+ CacheManager.getInstance = function (key, maxTime) {
56
+ if (!CacheManager.instances.has(key)) {
57
+ CacheManager.instances.set(key, new LastReportedCache(maxTime));
58
+ }
59
+ return CacheManager.instances.get(key);
60
+ };
61
+ CacheManager.HW_STATUS_KEY = 'HW_STATUS';
62
+ CacheManager.HW_ELEMS_KEY = 'HW_ELEMS';
63
+ CacheManager.SYSTEM_INFO_KEY = 'SYSTEM_INFO';
64
+ CacheManager.instances = new Map();
65
+ return CacheManager;
66
+ }());
67
+ var LastReportedCache = /** @class */ (function () {
68
+ function LastReportedCache(maxTime) {
69
+ this.maxTime = maxTime;
70
+ this.lastReported = null;
71
+ this.lastReportedTime = 0;
72
+ }
73
+ LastReportedCache.prototype.setLastReported = function (data) {
74
+ if (typeof data === "string") {
75
+ return;
76
+ }
77
+ this.lastReported = data;
78
+ this.lastReportedTime = Date.now();
79
+ };
80
+ LastReportedCache.prototype.getLastReported = function () {
81
+ if (Date.now() - this.lastReportedTime > this.maxTime) {
82
+ return null;
83
+ }
84
+ return this.lastReported;
85
+ };
86
+ return LastReportedCache;
87
+ }());
88
+ var RICNotificationsManager = /** @class */ (function () {
89
+ function RICNotificationsManager(marty) {
90
+ this.marty = marty;
91
+ }
92
+ RICNotificationsManager.prototype.msgBodyDecider = function (report, hwElems) {
93
+ Logger.info(SHOW_LOGS, TAG, "msgBodyDecider", report, hwElems);
94
+ switch (report.msgBody) {
95
+ case "overCurrentDet":
96
+ if (!report.hasOwnProperty("IDNo"))
97
+ break;
98
+ var motor = report.IDNo;
99
+ var motorElem = hwElems.find(function (_a) {
100
+ var IDNo = _a.IDNo;
101
+ return IDNo === report.IDNo;
102
+ });
103
+ if (motorElem !== undefined) {
104
+ motor = motorElem.name;
105
+ }
106
+ // TODO: add warnings manager to display warnings to user
107
+ // adding warning to the manager where the warning message to
108
+ // be displayed is decided
109
+ // const ocwm = OverCurrentWarningManager.getInstanceOrInstantiate();
110
+ // const warning = new OverCurrentWarning(motor);
111
+ // ocwm.addWarning(warning);
112
+ break;
113
+ case "freefallDet":
114
+ // this.emit(INCREMENT_FREE_FALL_WARNINGS);
115
+ break;
116
+ // Button A pressed Case
117
+ case "btnAPressed":
118
+ modalState.setModal(createElement(InBtButAPressedModalContent), "Warning!");
119
+ break;
120
+ }
121
+ };
122
+ // REPORT notifications are messages generated by RIC in response to certain events, including raw i2c events and motor safeties
123
+ RICNotificationsManager.prototype.reportNofication = function (report) {
124
+ return __awaiter(this, void 0, void 0, function () {
125
+ var hwElemsCached_str, hwElems, hwElems_str;
126
+ return __generator(this, function (_a) {
127
+ switch (_a.label) {
128
+ case 0:
129
+ Logger.info(SHOW_LOGS, TAG, "reportNotification Report callback", report);
130
+ hwElemsCached_str = CacheManager.getInstance(CacheManager.HW_ELEMS_KEY, 30000).getLastReported();
131
+ if (!hwElemsCached_str) return [3 /*break*/, 1];
132
+ Logger.info(SHOW_LOGS, TAG, "got hw elems from cache", hwElemsCached_str);
133
+ hwElems = RICHWElemList_Str.expand(hwElemsCached_str);
134
+ return [3 /*break*/, 3];
135
+ case 1:
136
+ Logger.info(SHOW_LOGS, TAG, "getting hw elems from rest");
137
+ return [4 /*yield*/, this.marty.sendRestMessage("hwstatus/strstat")];
138
+ case 2:
139
+ hwElems_str = _a.sent();
140
+ CacheManager.getInstance(CacheManager.HW_ELEMS_KEY, 30000).setLastReported(hwElems_str);
141
+ hwElems = RICHWElemList_Str.expand(hwElems_str);
142
+ _a.label = 3;
143
+ case 3:
144
+ Logger.info(SHOW_LOGS, TAG, "hw elems: ", hwElems);
145
+ if (report.hasOwnProperty("msgType")) {
146
+ if (report.msgType === "raw") {
147
+ this.handleServoFaultRawMsg(report);
148
+ return [2 /*return*/];
149
+ }
150
+ if (report.msgType === "warn" && report.hasOwnProperty("msgBody")) {
151
+ if (report.msgBody === "servoFaultDet") {
152
+ // if there is a servo fault, we want to get the servo fault data using the servo fault detector
153
+ Logger.info(SHOW_LOGS, TAG, "servo fault detected, sending atomic read operation");
154
+ // this.handleServoFaultRawMsg(report); // DEBUGGING ONLY
155
+ this.marty.sendAtomicReadOperation(); // this will trigger reportMsgCallback, and so the above code will be executed
156
+ }
157
+ else if (report.msgBody === "elemCommsFailDet") {
158
+ this.handleElemCommsFailDet(report);
159
+ }
160
+ else if (report.msgBody === "busFailDet") {
161
+ this.handleBusFailDet(report);
162
+ }
163
+ else {
164
+ Logger.info(SHOW_LOGS, TAG, "Unknown msgBody", report.msgBody);
165
+ }
166
+ ///////
167
+ this.msgBodyDecider(report, hwElems.hw);
168
+ }
169
+ else {
170
+ Logger.debug(SHOW_LOGS, TAG, "Either msgType or msgBody not found in report", report.msgType, report.msgBody);
171
+ }
172
+ }
173
+ else {
174
+ Logger.debug(SHOW_LOGS, TAG, "Didn't find msgType in report", report);
175
+ }
176
+ return [2 /*return*/];
177
+ }
178
+ });
179
+ });
180
+ };
181
+ RICNotificationsManager.prototype.getHwStatus = function (stringify, maxRetries, delayMs) {
182
+ if (stringify === void 0) { stringify = true; }
183
+ if (maxRetries === void 0) { maxRetries = 10; }
184
+ if (delayMs === void 0) { delayMs = 1000; }
185
+ return __awaiter(this, void 0, void 0, function () {
186
+ var i, cachedHwStatus, hwStatusResponse, err_1;
187
+ return __generator(this, function (_a) {
188
+ switch (_a.label) {
189
+ case 0:
190
+ i = 0;
191
+ _a.label = 1;
192
+ case 1:
193
+ if (!(i < maxRetries)) return [3 /*break*/, 11];
194
+ cachedHwStatus = CacheManager.getInstance(CacheManager.HW_STATUS_KEY, 30000).getLastReported();
195
+ if (cachedHwStatus) {
196
+ Logger.info(SHOW_LOGS, TAG, "got hw status from cache");
197
+ return [2 /*return*/, stringify ? JSON.stringify(cachedHwStatus.hw) : cachedHwStatus.hw];
198
+ }
199
+ _a.label = 2;
200
+ case 2:
201
+ _a.trys.push([2, 7, , 10]);
202
+ return [4 /*yield*/, this.marty.sendRestMessage('hwstatus')];
203
+ case 3:
204
+ hwStatusResponse = _a.sent();
205
+ if (!((hwStatusResponse === null || hwStatusResponse === void 0 ? void 0 : hwStatusResponse.rslt) === 'ok' && (hwStatusResponse === null || hwStatusResponse === void 0 ? void 0 : hwStatusResponse.hw))) return [3 /*break*/, 4];
206
+ CacheManager.getInstance(CacheManager.HW_STATUS_KEY, 30000).setLastReported(hwStatusResponse);
207
+ Logger.info(SHOW_LOGS, TAG, "got hw status from rest");
208
+ return [2 /*return*/, stringify ? JSON.stringify(hwStatusResponse.hw) : hwStatusResponse.hw];
209
+ case 4:
210
+ Logger.info(SHOW_LOGS, TAG, "Couldn't get hwstatus: retrying...");
211
+ if (!(i < maxRetries - 1)) return [3 /*break*/, 6];
212
+ return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, delayMs); })];
213
+ case 5:
214
+ _a.sent();
215
+ _a.label = 6;
216
+ case 6: return [3 /*break*/, 10];
217
+ case 7:
218
+ err_1 = _a.sent();
219
+ Logger.error(SHOW_LOGS, TAG, "Error getting hwstatus: ".concat(err_1, ", retrying..."));
220
+ if (!(i < maxRetries - 1)) return [3 /*break*/, 9];
221
+ return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, delayMs); })];
222
+ case 8:
223
+ _a.sent();
224
+ _a.label = 9;
225
+ case 9: return [3 /*break*/, 10];
226
+ case 10:
227
+ i++;
228
+ return [3 /*break*/, 1];
229
+ case 11:
230
+ Logger.info(SHOW_LOGS, TAG, "Couldn't get hwstatus: returning empty array");
231
+ return [2 /*return*/, stringify ? "[]" : []];
232
+ }
233
+ });
234
+ });
235
+ };
236
+ RICNotificationsManager.prototype.getHWNameGivenIdNo = function (hwStatusArr, IDNo) {
237
+ var convertedIdNo = Number(IDNo);
238
+ if (isNaN(convertedIdNo)) {
239
+ return null;
240
+ }
241
+ for (var _i = 0, hwStatusArr_1 = hwStatusArr; _i < hwStatusArr_1.length; _i++) {
242
+ var device = hwStatusArr_1[_i];
243
+ var convertedHwIdNo = Number(device.IDNo);
244
+ if (convertedHwIdNo === convertedIdNo) {
245
+ return device.name;
246
+ }
247
+ }
248
+ return convertedIdNo;
249
+ };
250
+ RICNotificationsManager.prototype.getHwRevAndVersion = function () {
251
+ return __awaiter(this, void 0, void 0, function () {
252
+ var cachedSystemInfo, vResponse, err_2;
253
+ return __generator(this, function (_a) {
254
+ switch (_a.label) {
255
+ case 0:
256
+ cachedSystemInfo = CacheManager.getInstance(CacheManager.SYSTEM_INFO_KEY, 1800000).getLastReported();
257
+ if (!cachedSystemInfo) return [3 /*break*/, 1];
258
+ return [2 /*return*/, "Versions info: ".concat(JSON.stringify(cachedSystemInfo))];
259
+ case 1:
260
+ _a.trys.push([1, 3, , 4]);
261
+ return [4 /*yield*/, this.marty.sendRestMessage('v')];
262
+ case 2:
263
+ vResponse = _a.sent();
264
+ if ((vResponse === null || vResponse === void 0 ? void 0 : vResponse.rslt) === 'ok') {
265
+ CacheManager.getInstance(CacheManager.SYSTEM_INFO_KEY, 1800000).setLastReported(vResponse);
266
+ Logger.info(SHOW_LOGS, TAG, "got versions info from rest");
267
+ return [2 /*return*/, "Versions info: ".concat(JSON.stringify(vResponse))];
268
+ }
269
+ else {
270
+ Logger.info(SHOW_LOGS, TAG, "Couldn't get versions info");
271
+ return [2 /*return*/, "Couldn't get versions info"];
272
+ }
273
+ return [3 /*break*/, 4];
274
+ case 3:
275
+ err_2 = _a.sent();
276
+ Logger.error(SHOW_LOGS, TAG, "Error getting hwstatus:", err_2);
277
+ return [2 /*return*/, "Couldn't get versions info"];
278
+ case 4: return [2 /*return*/];
279
+ }
280
+ });
281
+ });
282
+ };
283
+ RICNotificationsManager.prototype.martyNameStr = function () {
284
+ return __awaiter(this, void 0, void 0, function () {
285
+ var nameString, fetchedName;
286
+ return __generator(this, function (_a) {
287
+ switch (_a.label) {
288
+ case 0:
289
+ nameString = 'Robot Name: ';
290
+ if (this.marty.getFriendlyName())
291
+ return [2 /*return*/, nameString + this.marty.getFriendlyName()];
292
+ return [4 /*yield*/, this.marty.getRaftName()];
293
+ case 1:
294
+ fetchedName = _a.sent();
295
+ if (fetchedName) {
296
+ return [2 /*return*/, nameString + fetchedName];
297
+ }
298
+ else {
299
+ return [2 /*return*/, nameString + 'Unknown'];
300
+ }
301
+ return [2 /*return*/];
302
+ }
303
+ });
304
+ });
305
+ };
306
+ RICNotificationsManager.prototype.handleServoFaultRawMsg = function (report) {
307
+ return __awaiter(this, void 0, void 0, function () {
308
+ var detectedServoFaults, humanReadableServoFaults, hwStatusArr, hwStatus, elemName, martyNameStr, appVersion, versionsInfo, _a, _b, _c, _i, servoFaultKey, simpleDescription, enhancedDescription, isSeNoRegistered, userInfo, err_3;
309
+ return __generator(this, function (_d) {
310
+ switch (_d.label) {
311
+ case 0:
312
+ Logger.info(SHOW_LOGS, TAG, "Handling servo fault raw msg", report);
313
+ detectedServoFaults = RICServoFaultDetector.interpretReportMsg(report);
314
+ humanReadableServoFaults = {
315
+ intermittentConnection: "Intermittent Sensor Connection",
316
+ noConnection: "No Sensor Connection",
317
+ faultyConnection: "Faulty Drive Connection",
318
+ servoHornPositionError: "Servo Horn Position Error",
319
+ };
320
+ if (!detectedServoFaults) return [3 /*break*/, 10];
321
+ return [4 /*yield*/, this.getHwStatus(false)];
322
+ case 1:
323
+ hwStatusArr = _d.sent();
324
+ hwStatus = JSON.stringify(hwStatusArr);
325
+ elemName = this.getHWNameGivenIdNo(hwStatusArr, report.IDNo);
326
+ return [4 /*yield*/, this.martyNameStr()];
327
+ case 2:
328
+ martyNameStr = _d.sent();
329
+ appVersion = "webapp";
330
+ return [4 /*yield*/, this.getHwRevAndVersion()];
331
+ case 3:
332
+ versionsInfo = _d.sent();
333
+ _a = detectedServoFaults;
334
+ _b = [];
335
+ for (_c in _a)
336
+ _b.push(_c);
337
+ _i = 0;
338
+ _d.label = 4;
339
+ case 4:
340
+ if (!(_i < _b.length)) return [3 /*break*/, 9];
341
+ _c = _b[_i];
342
+ if (!(_c in _a)) return [3 /*break*/, 8];
343
+ servoFaultKey = _c;
344
+ if (!detectedServoFaults[servoFaultKey]) return [3 /*break*/, 8];
345
+ simpleDescription = "".concat(elemName, " Servo Fault Detected: ").concat(humanReadableServoFaults[servoFaultKey]);
346
+ enhancedDescription = "".concat(simpleDescription, "\n\n").concat(martyNameStr, "\n\n").concat(appVersion, "\n\n").concat(versionsInfo, "\n\nHwStatus: ").concat(hwStatus);
347
+ _d.label = 5;
348
+ case 5:
349
+ _d.trys.push([5, 7, , 8]);
350
+ ReportedWarningsState.getInstanceOrInstantiate().addCachedWarning(simpleDescription);
351
+ return [4 /*yield*/, isSerialNumberRegistered(this.marty.getSerialNumber())];
352
+ case 6:
353
+ isSeNoRegistered = _d.sent();
354
+ if (isSeNoRegistered) {
355
+ if (
356
+ // report the warning if it should not be ignored
357
+ !ReportedWarningsState.shouldIgnoreWarning(simpleDescription) &&
358
+ // and the warning has been seen 3 times in the last 5 minutes
359
+ ReportedWarningsState.getInstanceOrInstantiate().hasNumWarningsInLastMinutes(simpleDescription, 3, 5)) {
360
+ createTicket(this.marty.getSerialNumber(), "Servo Fault: ".concat(elemName || report.IDNo), enhancedDescription, this.marty.getFriendlyName(), this.marty.type);
361
+ }
362
+ }
363
+ if (
364
+ // only show the toast if the warning hasn't already been reported
365
+ !ReportedWarningsState.getInstanceOrInstantiate().warningExists(simpleDescription) &&
366
+ // and the warning should not be ignored
367
+ !ReportedWarningsState.shouldIgnoreWarning(simpleDescription) &&
368
+ // and the warning has been seen 3 times in the last 5 minutes
369
+ ReportedWarningsState.getInstanceOrInstantiate().hasNumWarningsInLastMinutes(simpleDescription, 3, 5)) {
370
+ userInfo = isSeNoRegistered
371
+ ? USER_WARNING_MESSAGE.registeredUser
372
+ : USER_WARNING_MESSAGE.unregisteredUser;
373
+ toast.error("Oops! We've detected that the servo ".concat(elemName || report.IDNo, " might be damaged. ").concat(userInfo), { autoClose: false });
374
+ // add the warning to the reported warnings state
375
+ ReportedWarningsState.getInstanceOrInstantiate().addWarning(simpleDescription);
376
+ }
377
+ return [3 /*break*/, 8];
378
+ case 7:
379
+ err_3 = _d.sent();
380
+ Logger.error(SHOW_LOGS, TAG, err_3);
381
+ return [3 /*break*/, 8];
382
+ case 8:
383
+ _i++;
384
+ return [3 /*break*/, 4];
385
+ case 9:
386
+ Logger.info(SHOW_LOGS, TAG, "detected servo faults", detectedServoFaults);
387
+ _d.label = 10;
388
+ case 10: return [2 /*return*/];
389
+ }
390
+ });
391
+ });
392
+ };
393
+ RICNotificationsManager.prototype.handleElemCommsFailDet = function (report) {
394
+ var _this = this;
395
+ Logger.info(SHOW_LOGS, TAG, "Handling elemCommsFailDet", report);
396
+ // return;
397
+ // this is triggered if we get multiple occurrences of loss of comms with an addon
398
+ // An IDNo will be reported, this can be cross referenced against the
399
+ // hwstatus output to determine which element is giving the error, and hence which leg has a problem
400
+ var warningKey = "elemCommsFailDet ".concat(report.elemName || report.IDNo);
401
+ ReportedWarningsState.getInstanceOrInstantiate().addCachedWarning(warningKey);
402
+ isSerialNumberRegistered(this.marty.getSerialNumber())
403
+ .then(function (isSeNoRegistered) { return __awaiter(_this, void 0, void 0, function () {
404
+ var hwStatusArr, hwStatus, elemName, martyNameStr, appVersion, versionsInfo, enhancedDescription, userInfo;
405
+ return __generator(this, function (_a) {
406
+ switch (_a.label) {
407
+ case 0: return [4 /*yield*/, this.getHwStatus(false)];
408
+ case 1:
409
+ hwStatusArr = _a.sent();
410
+ hwStatus = JSON.stringify(hwStatusArr);
411
+ elemName = this.getHWNameGivenIdNo(hwStatusArr, report.IDNo);
412
+ return [4 /*yield*/, this.martyNameStr()];
413
+ case 2:
414
+ martyNameStr = _a.sent();
415
+ appVersion = "webapp";
416
+ return [4 /*yield*/, this.getHwRevAndVersion()];
417
+ case 3:
418
+ versionsInfo = _a.sent();
419
+ if (isSeNoRegistered) {
420
+ enhancedDescription = "Element IDNo: ".concat(elemName || report.IDNo, "\n\n").concat(martyNameStr, "\n\n").concat(appVersion, "\n\n").concat(versionsInfo, "\n\nHwStatus: ").concat(hwStatus);
421
+ if (
422
+ // only create a ticket if the warning has been seen 3 times in the last 5 minutes
423
+ ReportedWarningsState.getInstanceOrInstantiate().hasNumWarningsInLastMinutes(warningKey, 3, 5) &&
424
+ // and if the warning should not be ignored
425
+ !ReportedWarningsState.shouldIgnoreWarning(warningKey)) {
426
+ createTicket(this.marty.getSerialNumber(), "Element Communication Failure at ".concat(elemName || report.IDNo), enhancedDescription, this.marty.getFriendlyName(), this.marty.type);
427
+ }
428
+ }
429
+ if (
430
+ // only show the toast if the warning hasn't already been reported
431
+ !ReportedWarningsState.getInstanceOrInstantiate().warningExists(warningKey) &&
432
+ // and has been seen 3 times in the last 5 minutes
433
+ ReportedWarningsState.getInstanceOrInstantiate().hasNumWarningsInLastMinutes(warningKey, 3, 5) &&
434
+ // and if the warning should not be ignored
435
+ !ReportedWarningsState.shouldIgnoreWarning(warningKey)) {
436
+ userInfo = isSeNoRegistered ? USER_WARNING_MESSAGE.registeredUser : USER_WARNING_MESSAGE.unregisteredUser;
437
+ toast.error("Oops! We've detected that the cable for the ".concat(elemName || "element " + report.IDNo, " might be damaged. ").concat(userInfo), { autoClose: false });
438
+ ReportedWarningsState.getInstanceOrInstantiate().addWarning(warningKey);
439
+ }
440
+ return [2 /*return*/];
441
+ }
442
+ });
443
+ }); }).catch(function (err) { return Logger.error(SHOW_LOGS, TAG, err); });
444
+ };
445
+ RICNotificationsManager.prototype.handleBusFailDet = function (report) {
446
+ var _this = this;
447
+ Logger.info(SHOW_LOGS, TAG, "Handling busFailDet", report);
448
+ // return;
449
+ // this is a bit of a catch all, which will trigger if we get multiple i2c bus failures.
450
+ // We won't be able to figure out which element is causing the failure from this, but it tells us something is up
451
+ var warningKey = "busFailDet ".concat(report.elemName || report.IDNo);
452
+ ReportedWarningsState.getInstanceOrInstantiate().addCachedWarning(warningKey);
453
+ isSerialNumberRegistered(this.marty.getSerialNumber())
454
+ .then(function (isSeNoRegistered) { return __awaiter(_this, void 0, void 0, function () {
455
+ var hwStatusArr, hwStatus, elemName, martyNameStr, appVersion, versionsInfo, enhancedDescription, userInfo;
456
+ return __generator(this, function (_a) {
457
+ switch (_a.label) {
458
+ case 0: return [4 /*yield*/, this.getHwStatus(false)];
459
+ case 1:
460
+ hwStatusArr = _a.sent();
461
+ hwStatus = JSON.stringify(hwStatusArr);
462
+ elemName = this.getHWNameGivenIdNo(hwStatusArr, report.IDNo);
463
+ return [4 /*yield*/, this.martyNameStr()];
464
+ case 2:
465
+ martyNameStr = _a.sent();
466
+ appVersion = "webapp";
467
+ return [4 /*yield*/, this.getHwRevAndVersion()];
468
+ case 3:
469
+ versionsInfo = _a.sent();
470
+ if (isSeNoRegistered) {
471
+ enhancedDescription = "Bus Fail Detected at ".concat(elemName || report.IDNo, "\n\n").concat(martyNameStr, "\n\n").concat(appVersion, "\n\n").concat(versionsInfo, "\n\nHwStatus: ").concat(hwStatus);
472
+ if (
473
+ // only create a ticket if the warning has been seen 3 times in the last 5 minutes
474
+ ReportedWarningsState.getInstanceOrInstantiate().hasNumWarningsInLastMinutes(warningKey, 3, 5) &&
475
+ // and if the warning should not be ignored
476
+ !ReportedWarningsState.shouldIgnoreWarning(warningKey)) {
477
+ createTicket(this.marty.getSerialNumber(), "Bus Fail ".concat(elemName || report.IDNo), enhancedDescription, this.marty.getFriendlyName(), this.marty.type);
478
+ }
479
+ }
480
+ if (
481
+ // only show the toast if the warning hasn't already been reported
482
+ !ReportedWarningsState.getInstanceOrInstantiate().warningExists(warningKey) &&
483
+ // and has been seen 3 times in the last 5 minutes
484
+ ReportedWarningsState.getInstanceOrInstantiate().hasNumWarningsInLastMinutes(warningKey, 3, 5) &&
485
+ // and if the warning should not be ignored
486
+ !ReportedWarningsState.shouldIgnoreWarning(warningKey)) {
487
+ userInfo = isSeNoRegistered ? USER_WARNING_MESSAGE.registeredUser : USER_WARNING_MESSAGE.unregisteredUser;
488
+ toast.error("Oops! We've detected that the BUS communication system at ".concat(elemName || "element " + report.IDNo, " might be damaged. ").concat(userInfo), { autoClose: false });
489
+ ReportedWarningsState.getInstanceOrInstantiate().addWarning(warningKey);
490
+ }
491
+ return [2 /*return*/];
492
+ }
493
+ });
494
+ }); }).catch(function (err) { return Logger.error(SHOW_LOGS, TAG, err); });
495
+ };
496
+ return RICNotificationsManager;
497
+ }());
498
+ export { RICNotificationsManager };
@@ -0,0 +1,59 @@
1
+ /**
2
+ * The ReportedWarningsState class is used to store the reported warnings from Marty.
3
+ * One of the main purposes of this class is to prevent duplicate warnings from being
4
+ * displayed to the user.
5
+ */
6
+ export declare class ReportedWarningsState {
7
+ private static instance;
8
+ private reportedWarnings;
9
+ private cachedWarnings;
10
+ private constructor();
11
+ static getInstanceOrInstantiate(): ReportedWarningsState;
12
+ static shouldIgnoreWarning(warning: string): boolean;
13
+ /**
14
+ * This method is used to add a warning to the reported warnings state.
15
+ * @param warning The warning to be added to the reported warnings state.
16
+ * @returns true if the warning was added to the reported warnings state, false otherwise.
17
+ */
18
+ addWarning(warning: string): boolean;
19
+ /**
20
+ * This method is used to remove a warning from the reported warnings state.
21
+ * @param warning The warning to be removed from the reported warnings state.
22
+ * @returns true if the warning was removed from the reported warnings state, false otherwise.
23
+ * */
24
+ removeWarning(warning: string): boolean;
25
+ /**
26
+ * This method is used to clear all warnings from the reported warnings state.
27
+ * */
28
+ clearWarnings(): void;
29
+ /**
30
+ * This method is used to get the reported warnings state.
31
+ * @returns The reported warnings state.
32
+ * */
33
+ getReportedWarnings(): Map<string, object>;
34
+ /**
35
+ * This method is used to set the reported warnings state.
36
+ * @param reportedWarnings The reported warnings state to be set.
37
+ * */
38
+ setReportedWarnings(reportedWarnings: Map<string, object>): void;
39
+ /**
40
+ * This method is used to check if a warning exists in the reported warnings state.
41
+ * @param warning The warning to be checked.
42
+ * @returns true if the warning exists in the reported warnings state, false otherwise.
43
+ * */
44
+ warningExists(warning: string): boolean;
45
+ /**
46
+ * This method is used to add a warning to the cached warnings state.
47
+ * @param warning The warning to be added to the cached warnings state.
48
+ * @returns true if the warning was added to the cached warnings state, false otherwise.
49
+ * */
50
+ addCachedWarning(warningsKey: string): boolean;
51
+ /**
52
+ * This method is used to check if there are x number of warnings let last y minutes.
53
+ * @param warningsKey The key to the cached warnings state.
54
+ * @param numWarnings The number of warnings to check for.
55
+ * @param minutes The number of minutes to check for.
56
+ * @returns true if there are x number of warnings let last y minutes, false otherwise.
57
+ * */
58
+ hasNumWarningsInLastMinutes(warningsKey: string, numWarnings: number, minutes: number): boolean;
59
+ }