/
types.ts
52 lines (44 loc) · 1.38 KB
/
types.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
51
52
export interface DriverCommand {
raw: string;
id?: number;
answerTimeoutMS: number;
isAnswerExpected: boolean;
}
export interface DriverAnswer {
raw: string;
id?: number;
}
export interface FindAnswersResult {
answers: DriverAnswer[];
remaining: string;
}
export interface Driver {
buildInitializeCommand: () => DriverCommand;
buildEnableOutputCommand: () => DriverCommand;
buildDisableOutputCommand: () => DriverCommand;
buildSetVoltageCommand: (voltage: number) => DriverCommand;
buildGetVoltageCommand: () => DriverCommand;
buildSetCurrentCommand: (current: number) => DriverCommand;
buildGetCurrentCommand: () => DriverCommand;
buildMeasureVoltageCommand: () => DriverCommand;
buildMeasureCurrentCommand: () => DriverCommand;
buildQueryIdentificationCommand: () => DriverCommand;
findAnswers: (data: string) => FindAnswersResult;
}
type DomainCommandPayload = any;
export interface DomainCommand {
type: string;
payload?: DomainCommandPayload;
}
export interface DomainCommandHandler {
type: string;
handle: (payload: any) => Promise<{}>;
}
export interface DomainCommandHandlerFactoryDependencies {
driver: Driver;
runCommand: (command: DriverCommand) => Promise<DriverAnswer>;
debug: (...args: any) => undefined;
}
export type DomainCommandHandlerFactory = (
dependencies: DomainCommandHandlerFactoryDependencies
) => DomainCommandHandler;