Add test event system
This commit is contained in:
parent
596b79ad0d
commit
e615d6e441
|
@ -33,6 +33,93 @@ async function fetchEvents() {
|
|||
setTimeout(fetchEvents, 1000);
|
||||
}
|
||||
|
||||
dataTypes = {
|
||||
DoorMode: {
|
||||
1: 'NormallyOpen',
|
||||
2: 'NormallyClosed',
|
||||
3: 'Controlled'
|
||||
},
|
||||
|
||||
Direction: {
|
||||
1: 'In',
|
||||
2: 'Out'
|
||||
},
|
||||
EventType: {
|
||||
0: 'None',
|
||||
1: 'Swipe',
|
||||
2: 'Door',
|
||||
3: 'Alarm',
|
||||
255: 'Overwritten'
|
||||
},
|
||||
|
||||
EventReason: {
|
||||
0: 'None',
|
||||
1: 'Swipe',
|
||||
2: 'SwipeOpen',
|
||||
3: 'SwipeClose',
|
||||
5: 'Denied',
|
||||
6: 'NoAccessRights',
|
||||
7: 'IncorrectPassword',
|
||||
8: 'AntiPassback',
|
||||
9: 'MoreCards',
|
||||
10: 'FirstCardOpen',
|
||||
11: 'DoorIsNormallyClosed',
|
||||
12: 'Interlock',
|
||||
13: 'NotInAllowedTimePeriod',
|
||||
15: 'InvalidTimezone',
|
||||
18: 'AccessDenied',
|
||||
20: 'PushbuttonOk',
|
||||
23: 'DoorOpened',
|
||||
24: 'DoorClosed',
|
||||
25: 'DoorOpenedSupervisorPassword',
|
||||
28: 'ControllerPowerOn',
|
||||
29: 'ControllerReset',
|
||||
31: 'PushbuttonInvalidDoorLocked',
|
||||
32: 'PushbuttonInvalidOffline',
|
||||
33: 'PushbuttonInvalidInterlock',
|
||||
34: 'PushbuttonInvalidThreat',
|
||||
37: 'DoorOpenTooLong',
|
||||
38: 'ForcedOpen',
|
||||
39: 'Fire',
|
||||
40: 'ForcedClosed',
|
||||
41: 'TheftPrevention',
|
||||
42: 'Zone24x7',
|
||||
43: 'Emergency',
|
||||
44: 'RemoteOpenDoor',
|
||||
45: 'RemoteOpenDoorUSBReader'
|
||||
}
|
||||
}
|
||||
|
||||
const validEvents = {
|
||||
1: [1,2,3,6,7],
|
||||
2: [25],
|
||||
3: [23,24,28,37,38,39,40,41,42,43,44,45]
|
||||
}
|
||||
|
||||
if (process.env.EVENT_TESTING == true) {
|
||||
setInterval(() => {
|
||||
const eventTypes = Object.keys(validEvents);
|
||||
const eventType = parseInt(eventTypes[Math.floor(Math.random() * eventTypes.length)]);
|
||||
const reasons = validEvents[eventType];
|
||||
const eventReason = reasons[Math.floor(Math.random() * reasons.length)];
|
||||
const cardNumber = Math.floor(Math.random() * 1000000) + 1;
|
||||
const granted = [5, 6, 7, 18].includes(eventReason) ? false : true;
|
||||
const testEvent = {
|
||||
Controller: 123456789,
|
||||
EventIndex: ++lastEventIndex,
|
||||
Timestamp: new Date().toISOString().replace('T', ' ').substring(0, 19),
|
||||
Type: eventType,
|
||||
Reason: eventReason,
|
||||
Granted: granted,
|
||||
CardNumber: cardNumber,
|
||||
Door: 1,
|
||||
Direction: eventType == 1 ? (Math.random() < 0.5 ? 1 : 2) : 0,
|
||||
}
|
||||
log.info(`Generated test event: ${JSON.stringify(testEvent)}`);
|
||||
emitter.emit('event', testEvent);
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
(async () => {
|
||||
await getLastEventIndex();
|
||||
await fetchEvents();
|
||||
|
|
Loading…
Reference in a new issue