-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopensportident.ts
50 lines (44 loc) · 1.37 KB
/
opensportident.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import * as moment from 'moment';
import { listSiPorts } from './si/siport';
export const NO_TIME = -1;
export interface SiPunch {
controlCode: number;
timestampMs: number;
}
export class SiReadout {
siCardSeries: string;
siCardNumber: string;
checkTimestampMs: number;
startTimestampMs: number;
finishTimestampMs: number;
punches: SiPunch[];
toDebugString(): string {
const start = this.formatTime(this.startTimestampMs);
const finish = this.formatTime(this.finishTimestampMs);
const check = this.formatTime(this.checkTimestampMs);
const count = this.punches.length;
// const indenting = ' '.repeat(this.siCardSeries.length + 1);
let ret = `${this.siCardSeries}: ${this.siCardNumber} check(${check}) start(${start}) finish(${finish})`;
for (let i = 0; i < count; i++) {
ret += `\n - ${i<9?' ':''}${i + 1}:${this.punches[i].controlCode} ${this.formatTime(this.punches[i].timestampMs)}`;
}
return ret;
}
private formatTime(timestamp: number): string {
if (timestamp === NO_TIME) {
return "no time";
} else {
return moment.utc(timestamp).format('ddd HH:mm:ss');
}
}
}
export interface SiPortId {
comName: string;
serialNumber: string;
}
export type SiEvent = 'open' | 'close' | 'readout' | 'error' | 'warning';
export { SiPortReader, listSiPorts } from './si/siport';
export interface SiPortDetectedMode {
siCard6Punches: number;
baudRate: number;
}