incyclist-devices 2.1.12 → 2.1.13
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.
- package/LICENSE +0 -0
- package/README.MD +238 -238
- package/lib/antv2/base/adapter.d.ts +0 -0
- package/lib/antv2/base/adapter.js +0 -0
- package/lib/antv2/base/binding.d.ts +0 -0
- package/lib/antv2/base/binding.js +0 -0
- package/lib/antv2/base/interface.d.ts +0 -0
- package/lib/antv2/base/interface.js +0 -0
- package/lib/antv2/cad/adapter.d.ts +0 -0
- package/lib/antv2/cad/adapter.js +0 -0
- package/lib/antv2/cad/index.d.ts +0 -0
- package/lib/antv2/cad/index.js +0 -0
- package/lib/antv2/consts.d.ts +0 -0
- package/lib/antv2/consts.js +0 -0
- package/lib/antv2/factories/adapter-factory.d.ts +0 -0
- package/lib/antv2/factories/adapter-factory.js +0 -0
- package/lib/antv2/factories/sensor-factory.d.ts +0 -0
- package/lib/antv2/factories/sensor-factory.js +0 -0
- package/lib/antv2/fe/adapter.d.ts +0 -0
- package/lib/antv2/fe/adapter.js +0 -0
- package/lib/antv2/fe/index.d.ts +0 -0
- package/lib/antv2/fe/index.js +0 -0
- package/lib/antv2/hr/adapter.d.ts +0 -0
- package/lib/antv2/hr/adapter.js +0 -0
- package/lib/antv2/hr/index.d.ts +0 -0
- package/lib/antv2/hr/index.js +0 -0
- package/lib/antv2/index.d.ts +0 -0
- package/lib/antv2/index.js +0 -0
- package/lib/antv2/pwr/adapter.d.ts +0 -0
- package/lib/antv2/pwr/adapter.js +0 -0
- package/lib/antv2/pwr/index.d.ts +0 -0
- package/lib/antv2/pwr/index.js +0 -0
- package/lib/antv2/types.d.ts +0 -0
- package/lib/antv2/types.js +0 -0
- package/lib/antv2/utils.d.ts +0 -0
- package/lib/antv2/utils.js +0 -0
- package/lib/base/adpater.d.ts +0 -0
- package/lib/base/adpater.js +0 -0
- package/lib/base/consts.d.ts +0 -0
- package/lib/base/consts.js +0 -0
- package/lib/ble/adapter-factory.d.ts +0 -0
- package/lib/ble/adapter-factory.js +0 -0
- package/lib/ble/base/adapter.d.ts +0 -0
- package/lib/ble/base/adapter.js +0 -0
- package/lib/ble/base/comms-utils.d.ts +0 -0
- package/lib/ble/base/comms-utils.js +0 -0
- package/lib/ble/base/comms.d.ts +0 -0
- package/lib/ble/base/comms.js +0 -0
- package/lib/ble/base/types.d.ts +0 -0
- package/lib/ble/base/types.js +0 -0
- package/lib/ble/bindings/index.d.ts +0 -0
- package/lib/ble/bindings/index.js +0 -0
- package/lib/ble/bindings/linux.d.ts +0 -0
- package/lib/ble/bindings/linux.js +0 -0
- package/lib/ble/bindings/mock.d.ts +0 -0
- package/lib/ble/bindings/mock.js +0 -0
- package/lib/ble/bindings/types.d.ts +0 -0
- package/lib/ble/bindings/types.js +0 -0
- package/lib/ble/ble-interface.d.ts +0 -0
- package/lib/ble/ble-interface.js +0 -0
- package/lib/ble/ble-peripheral.d.ts +0 -0
- package/lib/ble/ble-peripheral.js +0 -0
- package/lib/ble/consts.d.ts +0 -0
- package/lib/ble/consts.js +0 -0
- package/lib/ble/cp/adapter.d.ts +0 -0
- package/lib/ble/cp/adapter.js +0 -0
- package/lib/ble/cp/comm.d.ts +0 -0
- package/lib/ble/cp/comm.js +0 -0
- package/lib/ble/cp/index.d.ts +0 -0
- package/lib/ble/cp/index.js +0 -0
- package/lib/ble/cp/types.d.ts +0 -0
- package/lib/ble/cp/types.js +0 -0
- package/lib/ble/elite/adapter.d.ts +0 -0
- package/lib/ble/elite/adapter.js +0 -0
- package/lib/ble/elite/comms.d.ts +0 -0
- package/lib/ble/elite/comms.js +0 -0
- package/lib/ble/elite/index.d.ts +0 -0
- package/lib/ble/elite/index.js +0 -0
- package/lib/ble/fm/adapter.d.ts +0 -0
- package/lib/ble/fm/adapter.js +0 -0
- package/lib/ble/fm/comms.d.ts +0 -0
- package/lib/ble/fm/comms.js +0 -0
- package/lib/ble/fm/consts.d.ts +0 -0
- package/lib/ble/fm/consts.js +0 -0
- package/lib/ble/fm/index.d.ts +0 -0
- package/lib/ble/fm/index.js +0 -0
- package/lib/ble/fm/types.d.ts +0 -0
- package/lib/ble/fm/types.js +0 -0
- package/lib/ble/hr/adapter.d.ts +0 -0
- package/lib/ble/hr/adapter.js +0 -0
- package/lib/ble/hr/comm.d.ts +0 -0
- package/lib/ble/hr/comm.js +0 -0
- package/lib/ble/hr/index.d.ts +0 -0
- package/lib/ble/hr/index.js +0 -0
- package/lib/ble/hr/mock.d.ts +0 -0
- package/lib/ble/hr/mock.js +0 -0
- package/lib/ble/hr/types.d.ts +0 -0
- package/lib/ble/hr/types.js +0 -0
- package/lib/ble/index.d.ts +0 -0
- package/lib/ble/index.js +0 -0
- package/lib/ble/peripheral-cache.d.ts +0 -0
- package/lib/ble/peripheral-cache.js +0 -0
- package/lib/ble/tacx/adapter.d.ts +0 -0
- package/lib/ble/tacx/adapter.js +0 -0
- package/lib/ble/tacx/comms.d.ts +0 -0
- package/lib/ble/tacx/comms.js +0 -0
- package/lib/ble/tacx/index.d.ts +0 -0
- package/lib/ble/tacx/index.js +0 -0
- package/lib/ble/tacx/types.d.ts +0 -0
- package/lib/ble/tacx/types.js +0 -0
- package/lib/ble/types.d.ts +0 -0
- package/lib/ble/types.js +0 -0
- package/lib/ble/utils.d.ts +0 -0
- package/lib/ble/utils.js +0 -0
- package/lib/ble/wahoo/adapter.d.ts +0 -0
- package/lib/ble/wahoo/adapter.js +0 -0
- package/lib/ble/wahoo/comms.d.ts +0 -0
- package/lib/ble/wahoo/comms.js +0 -0
- package/lib/ble/wahoo/index.d.ts +0 -0
- package/lib/ble/wahoo/index.js +0 -0
- package/lib/ble/wahoo/types.d.ts +0 -0
- package/lib/ble/wahoo/types.js +0 -0
- package/lib/factories/adapters.d.ts +0 -0
- package/lib/factories/adapters.js +0 -0
- package/lib/factories/index.d.ts +0 -0
- package/lib/factories/index.js +0 -0
- package/lib/factories/interfaces.d.ts +0 -0
- package/lib/factories/interfaces.js +0 -0
- package/lib/index.d.ts +0 -0
- package/lib/index.js +0 -0
- package/lib/modes/ant-fe-adv-st-mode.d.ts +0 -0
- package/lib/modes/ant-fe-adv-st-mode.js +0 -0
- package/lib/modes/antble-erg.d.ts +0 -0
- package/lib/modes/antble-erg.js +0 -0
- package/lib/modes/antble-smarttrainer.d.ts +0 -0
- package/lib/modes/antble-smarttrainer.js +0 -0
- package/lib/modes/base.d.ts +0 -0
- package/lib/modes/base.js +0 -0
- package/lib/modes/daum-classic-standard.d.ts +0 -0
- package/lib/modes/daum-classic-standard.js +0 -0
- package/lib/modes/daum-erg.d.ts +0 -0
- package/lib/modes/daum-erg.js +0 -0
- package/lib/modes/daum-power.d.ts +0 -0
- package/lib/modes/daum-power.js +0 -0
- package/lib/modes/daum-premium-standard.d.ts +0 -0
- package/lib/modes/daum-premium-standard.js +0 -0
- package/lib/modes/daum-smarttrainer.d.ts +0 -0
- package/lib/modes/daum-smarttrainer.js +0 -0
- package/lib/modes/kettler-erg.d.ts +0 -0
- package/lib/modes/kettler-erg.js +0 -0
- package/lib/modes/power-base.d.ts +0 -0
- package/lib/modes/power-base.js +0 -0
- package/lib/modes/power-meter.d.ts +0 -0
- package/lib/modes/power-meter.js +0 -0
- package/lib/modes/simulator.d.ts +0 -0
- package/lib/modes/simulator.js +0 -0
- package/lib/modes/types.d.ts +0 -0
- package/lib/modes/types.js +0 -0
- package/lib/serial/base/adapter.d.ts +0 -0
- package/lib/serial/base/adapter.js +0 -0
- package/lib/serial/base/comms.d.ts +0 -0
- package/lib/serial/base/comms.js +0 -0
- package/lib/serial/base/serial-interface.d.ts +0 -0
- package/lib/serial/base/serial-interface.js +0 -0
- package/lib/serial/base/serial-scanner.d.ts +0 -0
- package/lib/serial/base/serial-scanner.js +0 -0
- package/lib/serial/base/serialport.d.ts +0 -0
- package/lib/serial/base/serialport.js +0 -0
- package/lib/serial/bindings/tcp.d.ts +0 -0
- package/lib/serial/bindings/tcp.js +0 -0
- package/lib/serial/daum/DaumAdapter.d.ts +0 -0
- package/lib/serial/daum/DaumAdapter.js +0 -0
- package/lib/serial/daum/classic/adapter.d.ts +0 -0
- package/lib/serial/daum/classic/adapter.js +0 -0
- package/lib/serial/daum/classic/comms.d.ts +0 -0
- package/lib/serial/daum/classic/comms.js +0 -0
- package/lib/serial/daum/classic/consts.d.ts +0 -0
- package/lib/serial/daum/classic/consts.js +0 -0
- package/lib/serial/daum/classic/mock.d.ts +0 -0
- package/lib/serial/daum/classic/mock.js +0 -0
- package/lib/serial/daum/classic/types.d.ts +0 -0
- package/lib/serial/daum/classic/types.js +0 -0
- package/lib/serial/daum/classic/utils.d.ts +0 -0
- package/lib/serial/daum/classic/utils.js +0 -0
- package/lib/serial/daum/premium/adapter.d.ts +0 -0
- package/lib/serial/daum/premium/adapter.js +0 -0
- package/lib/serial/daum/premium/comms.d.ts +0 -0
- package/lib/serial/daum/premium/comms.js +0 -0
- package/lib/serial/daum/premium/consts.d.ts +0 -0
- package/lib/serial/daum/premium/consts.js +0 -0
- package/lib/serial/daum/premium/mock.d.ts +0 -0
- package/lib/serial/daum/premium/mock.js +0 -0
- package/lib/serial/daum/premium/types.d.ts +0 -0
- package/lib/serial/daum/premium/types.js +0 -0
- package/lib/serial/daum/premium/utils.d.ts +0 -0
- package/lib/serial/daum/premium/utils.js +0 -0
- package/lib/serial/daum/types.d.ts +0 -0
- package/lib/serial/daum/types.js +0 -0
- package/lib/serial/factories/adapter-factory.d.ts +0 -0
- package/lib/serial/factories/adapter-factory.js +0 -0
- package/lib/serial/index.d.ts +0 -0
- package/lib/serial/index.js +0 -0
- package/lib/serial/kettler/comms.d.ts +0 -0
- package/lib/serial/kettler/comms.js +0 -0
- package/lib/serial/kettler/ergo-racer/adapter.d.ts +1 -1
- package/lib/serial/kettler/ergo-racer/adapter.js +3 -2
- package/lib/serial/kettler/ergo-racer/mock.d.ts +0 -0
- package/lib/serial/kettler/ergo-racer/mock.js +0 -0
- package/lib/serial/kettler/types.d.ts +0 -0
- package/lib/serial/kettler/types.js +0 -0
- package/lib/serial/types.d.ts +0 -0
- package/lib/serial/types.js +0 -0
- package/lib/simulator/Simulator.d.ts +0 -0
- package/lib/simulator/Simulator.js +0 -0
- package/lib/types/adapter.d.ts +0 -0
- package/lib/types/adapter.js +0 -0
- package/lib/types/capabilities.d.ts +0 -0
- package/lib/types/capabilities.js +0 -0
- package/lib/types/data.d.ts +0 -0
- package/lib/types/data.js +0 -0
- package/lib/types/device.d.ts +0 -0
- package/lib/types/device.js +0 -0
- package/lib/types/index.d.ts +0 -0
- package/lib/types/index.js +0 -0
- package/lib/types/interface.d.ts +0 -0
- package/lib/types/interface.js +0 -0
- package/lib/types/user.d.ts +0 -0
- package/lib/types/user.js +0 -0
- package/lib/utils/calculations.d.ts +0 -0
- package/lib/utils/calculations.js +0 -0
- package/lib/utils/utils.d.ts +0 -0
- package/lib/utils/utils.js +0 -0
- package/package.json +51 -51
- package/lib/adapters.d.ts +0 -7
- package/lib/adapters.js +0 -49
- package/lib/antv2/adapter-factory.d.ts +0 -14
- package/lib/antv2/adapter-factory.js +0 -65
- package/lib/antv2/adapter.d.ts +0 -54
- package/lib/antv2/adapter.js +0 -291
- package/lib/antv2/ant-interface.d.ts +0 -35
- package/lib/antv2/ant-interface.js +0 -285
- package/lib/antv2/base/ant-interface.d.ts +0 -35
- package/lib/antv2/base/ant-interface.js +0 -285
- package/lib/antv2/binding.d.ts +0 -13
- package/lib/antv2/binding.js +0 -27
- package/lib/antv2/hr copy/adapter.d.ts +0 -11
- package/lib/antv2/hr copy/adapter.js +0 -30
- package/lib/antv2/hr copy/index.d.ts +0 -2
- package/lib/antv2/hr copy/index.js +0 -7
- package/lib/antv2/sensor-factory.d.ts +0 -5
- package/lib/antv2/sensor-factory.js +0 -20
- package/lib/interfaces.d.ts +0 -7
- package/lib/interfaces.js +0 -27
- package/lib/serial/SinglePathScanner.d.ts +0 -17
- package/lib/serial/SinglePathScanner.js +0 -87
- package/lib/serial/adapter-factory.d.ts +0 -14
- package/lib/serial/adapter-factory.js +0 -30
- package/lib/serial/adapter.d.ts +0 -17
- package/lib/serial/adapter.js +0 -67
- package/lib/serial/comm.d.ts +0 -7
- package/lib/serial/comm.js +0 -2
- package/lib/serial/comms.d.ts +0 -62
- package/lib/serial/comms.js +0 -280
- package/lib/serial/daum/classic/PROTOCOL_NAME.d.ts +0 -2
- package/lib/serial/daum/classic/PROTOCOL_NAME.js +0 -5
- package/lib/serial/daum/consts.d.ts +0 -0
- package/lib/serial/daum/consts.js +0 -0
- package/lib/serial/serial-interface.d.ts +0 -36
- package/lib/serial/serial-interface.js +0 -288
- package/lib/serial/serial-scanner.d.ts +0 -16
- package/lib/serial/serial-scanner.js +0 -87
- package/lib/serial/serialport.d.ts +0 -17
- package/lib/serial/serialport.js +0 -87
- package/lib/types/Command.d.ts +0 -8
- package/lib/types/Command.js +0 -2
- package/lib/types/command.d.ts +0 -0
- package/lib/types/command.js +0 -0
- package/lib/types/route.d.ts +0 -0
- package/lib/types/route.js +0 -0
- package/lib/types/types.d.ts +0 -8
- package/lib/types/types.js +0 -2
|
File without changes
|
|
File without changes
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
import EventEmitter from "events";
|
|
4
|
-
import { BindingInterface } from "@serialport/bindings-interface";
|
|
5
|
-
import { SerialPortStream } from '@serialport/stream';
|
|
6
|
-
import { SerialDeviceSettings, SerialScannerProps, PortMapping, SerialInterfaceProps } from "./types";
|
|
7
|
-
import { IncyclistInterface } from "../types";
|
|
8
|
-
import { EventLogger } from "gd-eventlog";
|
|
9
|
-
export default class SerialInterface extends EventEmitter implements IncyclistInterface {
|
|
10
|
-
ifaceName: string;
|
|
11
|
-
binding: BindingInterface;
|
|
12
|
-
ports: PortMapping[];
|
|
13
|
-
isScanning: boolean;
|
|
14
|
-
isStopScanRequested: boolean;
|
|
15
|
-
scanEvents: EventEmitter;
|
|
16
|
-
logger: EventLogger;
|
|
17
|
-
toScan: NodeJS.Timeout;
|
|
18
|
-
connected: boolean;
|
|
19
|
-
inUse: string[];
|
|
20
|
-
static _instances: SerialInterface[];
|
|
21
|
-
static getInstance(props: SerialInterfaceProps): SerialInterface;
|
|
22
|
-
static _add(instance: SerialInterface): void;
|
|
23
|
-
constructor(props: SerialInterfaceProps);
|
|
24
|
-
logEvent(event: any): void;
|
|
25
|
-
setBinding(binding: BindingInterface): void;
|
|
26
|
-
getName(): string;
|
|
27
|
-
isConnected(): boolean;
|
|
28
|
-
setInUse(path: string): void;
|
|
29
|
-
releaseInUse(path: string): void;
|
|
30
|
-
connect(): Promise<boolean>;
|
|
31
|
-
disconnect(): Promise<boolean>;
|
|
32
|
-
openPort(path: string): Promise<SerialPortStream | null>;
|
|
33
|
-
closePort(path: string): Promise<Boolean>;
|
|
34
|
-
scan(props: SerialScannerProps): Promise<SerialDeviceSettings[]>;
|
|
35
|
-
stopScan(): Promise<boolean>;
|
|
36
|
-
}
|
|
@@ -1,288 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const events_1 = __importDefault(require("events"));
|
|
16
|
-
const serialport_1 = __importDefault(require("./serialport"));
|
|
17
|
-
const gd_eventlog_1 = require("gd-eventlog");
|
|
18
|
-
const utils_1 = require("../utils/utils");
|
|
19
|
-
const adapter_factory_1 = __importDefault(require("./factories/adapter-factory"));
|
|
20
|
-
const serial_scanner_1 = require("./serial-scanner");
|
|
21
|
-
const DEFAULT_SCAN_TIMEOUT = 10000;
|
|
22
|
-
class SerialInterface extends events_1.default {
|
|
23
|
-
static getInstance(props) {
|
|
24
|
-
const { ifaceName, binding, logger } = props;
|
|
25
|
-
let instance = SerialInterface._instances.find(i => i.ifaceName === ifaceName);
|
|
26
|
-
if (!instance) {
|
|
27
|
-
if (binding)
|
|
28
|
-
instance = new SerialInterface(props);
|
|
29
|
-
else {
|
|
30
|
-
instance = new SerialInterface({ ifaceName, binding: serialport_1.default.getInstance().getBinding(ifaceName), logger });
|
|
31
|
-
if (instance)
|
|
32
|
-
SerialInterface._instances.push(instance);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return instance;
|
|
36
|
-
}
|
|
37
|
-
static _add(instance) {
|
|
38
|
-
let existingIdx = SerialInterface._instances.findIndex(i => i.ifaceName === instance.ifaceName);
|
|
39
|
-
if (existingIdx !== -1)
|
|
40
|
-
SerialInterface._instances[existingIdx] = instance;
|
|
41
|
-
else
|
|
42
|
-
SerialInterface._instances.push(instance);
|
|
43
|
-
}
|
|
44
|
-
constructor(props) {
|
|
45
|
-
super();
|
|
46
|
-
const { ifaceName, binding } = props;
|
|
47
|
-
this.ifaceName = ifaceName;
|
|
48
|
-
this.binding = undefined;
|
|
49
|
-
this.ports = [];
|
|
50
|
-
this.inUse = [];
|
|
51
|
-
this.isScanning = false;
|
|
52
|
-
this.isStopScanRequested = false;
|
|
53
|
-
this.scanEvents = new events_1.default();
|
|
54
|
-
this.scanEvents.setMaxListeners(100);
|
|
55
|
-
this.logger = props.logger || new gd_eventlog_1.EventLogger(`Serial:${ifaceName}`);
|
|
56
|
-
this.connected = false;
|
|
57
|
-
this.logEvent({ message: 'new serial interface', ifaceName });
|
|
58
|
-
if (binding) {
|
|
59
|
-
this.setBinding(binding);
|
|
60
|
-
}
|
|
61
|
-
SerialInterface._add(this);
|
|
62
|
-
}
|
|
63
|
-
logEvent(event) {
|
|
64
|
-
if (this.logger) {
|
|
65
|
-
this.logger.logEvent(event);
|
|
66
|
-
}
|
|
67
|
-
const w = global.window;
|
|
68
|
-
if ((w === null || w === void 0 ? void 0 : w.DEVICE_DEBUG) || process.env.BLE_DEBUG) {
|
|
69
|
-
console.log('~~~ Serial', event);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
setBinding(binding) {
|
|
73
|
-
this.binding = binding;
|
|
74
|
-
serialport_1.default.getInstance().setBinding(this.ifaceName, binding);
|
|
75
|
-
}
|
|
76
|
-
getName() {
|
|
77
|
-
return this.ifaceName;
|
|
78
|
-
}
|
|
79
|
-
isConnected() {
|
|
80
|
-
return this.connected;
|
|
81
|
-
}
|
|
82
|
-
setInUse(path) {
|
|
83
|
-
this.logEvent({ message: 'block port for further scans', port: path });
|
|
84
|
-
if (!this.inUse.includes(path))
|
|
85
|
-
this.inUse.push(path);
|
|
86
|
-
}
|
|
87
|
-
releaseInUse(path) {
|
|
88
|
-
if (this.inUse.includes(path)) {
|
|
89
|
-
this.logEvent({ message: 're-enable port for further scans', port: path });
|
|
90
|
-
const idx = this.inUse.findIndex(r => r === path);
|
|
91
|
-
this.inUse.splice(idx, 1);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
connect() {
|
|
95
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
-
this.logEvent({ message: 'connecting', interface: this.ifaceName });
|
|
97
|
-
const binding = serialport_1.default.getInstance().getBinding(this.ifaceName);
|
|
98
|
-
if (!binding || !this.binding) {
|
|
99
|
-
this.connected = false;
|
|
100
|
-
this.logEvent({ message: 'connecting error', interface: this.ifaceName, reason: 'no binfing found' });
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
|
-
try {
|
|
104
|
-
const SerialPort = this.binding;
|
|
105
|
-
yield SerialPort.list();
|
|
106
|
-
this.connected = true;
|
|
107
|
-
return true;
|
|
108
|
-
}
|
|
109
|
-
catch (err) {
|
|
110
|
-
this.logEvent({ message: 'connecting error', interface: this.ifaceName, reason: err.message });
|
|
111
|
-
this.connected = false;
|
|
112
|
-
return false;
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
disconnect() {
|
|
117
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
-
this.connected = false;
|
|
119
|
-
return true;
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
openPort(path) {
|
|
123
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
-
this.logEvent({ message: 'opening port', port: path });
|
|
125
|
-
const existing = this.ports.findIndex(p => p.path === path);
|
|
126
|
-
if (existing !== -1) {
|
|
127
|
-
const port = this.ports[existing].port;
|
|
128
|
-
if (port.isOpen) {
|
|
129
|
-
this.logEvent({ message: 'opening port - port already exists', port: path });
|
|
130
|
-
return port;
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
this.ports.splice(existing, 1);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
const port = serialport_1.default.getInstance().getSerialPort(this.ifaceName, { path });
|
|
137
|
-
if (!port) {
|
|
138
|
-
this.logEvent({ message: 'opening port - port does not exist', port: path });
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
return new Promise((resolve) => {
|
|
142
|
-
port.once('error', (err) => {
|
|
143
|
-
this.logEvent({ message: 'error', path, error: err.message || err, stack: err.stack });
|
|
144
|
-
port.removeAllListeners();
|
|
145
|
-
resolve(null);
|
|
146
|
-
});
|
|
147
|
-
port.once('open', () => {
|
|
148
|
-
this.logEvent({ message: 'port opened', path });
|
|
149
|
-
port.removeAllListeners();
|
|
150
|
-
this.ports.push({ path, port });
|
|
151
|
-
resolve(port);
|
|
152
|
-
});
|
|
153
|
-
port.open();
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
closePort(path) {
|
|
158
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
159
|
-
this.logEvent({ message: 'closing port', port: path });
|
|
160
|
-
const existing = this.ports.findIndex(p => p.path === path);
|
|
161
|
-
if (existing === -1)
|
|
162
|
-
return true;
|
|
163
|
-
const port = this.ports[existing].port;
|
|
164
|
-
if (!port.isOpen)
|
|
165
|
-
return true;
|
|
166
|
-
port.on('error', () => { });
|
|
167
|
-
try {
|
|
168
|
-
port.flush();
|
|
169
|
-
yield port.drain();
|
|
170
|
-
}
|
|
171
|
-
catch (_a) { }
|
|
172
|
-
return new Promise(resolve => {
|
|
173
|
-
port.close(err => {
|
|
174
|
-
if (!err) {
|
|
175
|
-
this.ports.splice(existing, 1);
|
|
176
|
-
port.removeAllListeners();
|
|
177
|
-
resolve(true);
|
|
178
|
-
}
|
|
179
|
-
resolve(false);
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
scan(props) {
|
|
185
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
186
|
-
if (this.isScanning)
|
|
187
|
-
return [];
|
|
188
|
-
if (!this.isConnected())
|
|
189
|
-
yield this.connect();
|
|
190
|
-
const binding = serialport_1.default.getInstance().getBinding(this.ifaceName);
|
|
191
|
-
if (!binding || !this.binding)
|
|
192
|
-
return [];
|
|
193
|
-
const { port, timeout = DEFAULT_SCAN_TIMEOUT } = props;
|
|
194
|
-
let paths;
|
|
195
|
-
const detected = [];
|
|
196
|
-
let timeOutExpired = false;
|
|
197
|
-
let toExpiresAt = Date.now() + timeout;
|
|
198
|
-
if (timeout) {
|
|
199
|
-
this.toScan = setTimeout(() => {
|
|
200
|
-
timeOutExpired = true;
|
|
201
|
-
this.scanEvents.emit('timeout');
|
|
202
|
-
}, timeout);
|
|
203
|
-
}
|
|
204
|
-
this.isScanning = true;
|
|
205
|
-
let attemptNo = 0;
|
|
206
|
-
const isTcpip = this.getName() === 'tcpip';
|
|
207
|
-
do {
|
|
208
|
-
if (attemptNo === 0)
|
|
209
|
-
this.logEvent({ message: 'checking for ports', interface: this.ifaceName, port, excludes: this.inUse });
|
|
210
|
-
else
|
|
211
|
-
this.logEvent({ message: 'checking for ports retry', interface: this.ifaceName, retry: attemptNo });
|
|
212
|
-
attemptNo++;
|
|
213
|
-
try {
|
|
214
|
-
if (isTcpip) {
|
|
215
|
-
const _binding = binding;
|
|
216
|
-
paths = (yield _binding.list(port, this.inUse)) || [];
|
|
217
|
-
}
|
|
218
|
-
else {
|
|
219
|
-
paths = (yield binding.list()) || [];
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
catch (err) {
|
|
223
|
-
this.logEvent({ message: 'error', fn: 'scan#detect ports', error: err.message, interface: this.ifaceName, port, excludes: this.inUse });
|
|
224
|
-
}
|
|
225
|
-
paths = paths.filter(p => !this.inUse.includes(p.path));
|
|
226
|
-
if (!paths || paths.length === 0) {
|
|
227
|
-
this.logEvent({ message: 'scanning: no ports detected', interface: this.ifaceName, paths: paths.map(p => p.path), timeout });
|
|
228
|
-
yield (0, utils_1.sleep)(1000);
|
|
229
|
-
}
|
|
230
|
-
if (Date.now() > toExpiresAt)
|
|
231
|
-
timeOutExpired = true;
|
|
232
|
-
} while (this.isScanning && !timeOutExpired && paths.length === 0);
|
|
233
|
-
if (paths.length === 0) {
|
|
234
|
-
this.logEvent({ message: 'nothing to scan ' });
|
|
235
|
-
if (this.toScan) {
|
|
236
|
-
clearTimeout(this.toScan);
|
|
237
|
-
this.toScan = null;
|
|
238
|
-
}
|
|
239
|
-
return [];
|
|
240
|
-
}
|
|
241
|
-
this.logEvent({ message: 'scanning on ', interface: this.ifaceName, paths: paths.map(p => p.path).join(','), timeout });
|
|
242
|
-
const scanners = paths.map(p => new serial_scanner_1.SinglePathScanner(p.path, this, Object.assign(Object.assign({}, props), { logger: this.logger })));
|
|
243
|
-
try {
|
|
244
|
-
yield Promise.all(scanners.map(s => s.scan()
|
|
245
|
-
.then((device) => __awaiter(this, void 0, void 0, function* () {
|
|
246
|
-
if (device) {
|
|
247
|
-
const adapter = adapter_factory_1.default.getInstance().createInstance(device);
|
|
248
|
-
const path = adapter.getPort();
|
|
249
|
-
this.inUse.push(path);
|
|
250
|
-
yield adapter.pause();
|
|
251
|
-
detected.push(device);
|
|
252
|
-
this.emit('device', device);
|
|
253
|
-
}
|
|
254
|
-
}))
|
|
255
|
-
.catch()));
|
|
256
|
-
}
|
|
257
|
-
catch (err) {
|
|
258
|
-
this.logEvent({ message: 'error', fn: 'scan()', error: err.message || err, stack: err.stack });
|
|
259
|
-
}
|
|
260
|
-
if (this.toScan) {
|
|
261
|
-
clearTimeout(this.toScan);
|
|
262
|
-
this.toScan = null;
|
|
263
|
-
}
|
|
264
|
-
this.isScanning = false;
|
|
265
|
-
this.logEvent({ message: 'scan finished on', interface: this.ifaceName, paths: paths.map(p => p.path), devices: detected.map(d => {
|
|
266
|
-
const res = Object.assign({}, d);
|
|
267
|
-
res.interface = this.ifaceName;
|
|
268
|
-
return res;
|
|
269
|
-
}) });
|
|
270
|
-
return detected;
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
stopScan() {
|
|
274
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
275
|
-
if (!this.isScanning)
|
|
276
|
-
return true;
|
|
277
|
-
if (this.toScan) {
|
|
278
|
-
clearTimeout(this.toScan);
|
|
279
|
-
this.toScan = null;
|
|
280
|
-
}
|
|
281
|
-
this.isScanning = false;
|
|
282
|
-
this.scanEvents.emit('stop');
|
|
283
|
-
return true;
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
SerialInterface._instances = [];
|
|
288
|
-
exports.default = SerialInterface;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { EventLogger } from "gd-eventlog";
|
|
2
|
-
import SerialInterface from "./serial-interface";
|
|
3
|
-
import { SerialDeviceSettings, SerialScannerProps } from "./types";
|
|
4
|
-
export declare class SinglePathScanner {
|
|
5
|
-
path: string;
|
|
6
|
-
serial: SerialInterface;
|
|
7
|
-
result: SerialDeviceSettings;
|
|
8
|
-
isScanning: boolean;
|
|
9
|
-
props: SerialScannerProps;
|
|
10
|
-
logger: EventLogger;
|
|
11
|
-
isFound: boolean;
|
|
12
|
-
constructor(path: string, serial: SerialInterface, props: SerialScannerProps);
|
|
13
|
-
logEvent(event: any): void;
|
|
14
|
-
onStopRequest(resolve: any): Promise<void>;
|
|
15
|
-
scan(): Promise<SerialDeviceSettings | undefined>;
|
|
16
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.SinglePathScanner = void 0;
|
|
16
|
-
const gd_eventlog_1 = require("gd-eventlog");
|
|
17
|
-
const types_1 = require("./types");
|
|
18
|
-
const adapter_factory_1 = __importDefault(require("./factories/adapter-factory"));
|
|
19
|
-
const utils_1 = require("../utils/utils");
|
|
20
|
-
class SinglePathScanner {
|
|
21
|
-
constructor(path, serial, props) {
|
|
22
|
-
this.path = path;
|
|
23
|
-
this.serial = serial;
|
|
24
|
-
this.result = undefined;
|
|
25
|
-
this.isScanning = false;
|
|
26
|
-
this.isFound = false;
|
|
27
|
-
this.props = props;
|
|
28
|
-
this.logger = props.logger || new gd_eventlog_1.EventLogger('SerialScanner');
|
|
29
|
-
}
|
|
30
|
-
logEvent(event) {
|
|
31
|
-
if (this.logger) {
|
|
32
|
-
this.logger.logEvent(event);
|
|
33
|
-
}
|
|
34
|
-
const w = global.window;
|
|
35
|
-
if ((w === null || w === void 0 ? void 0 : w.DEVICE_DEBUG) || process.env.BLE_DEBUG) {
|
|
36
|
-
console.log('~~~ SerialScanner', event);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
onStopRequest(resolve) {
|
|
40
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
this.logEvent({ message: 'stopping scan', path: this.path });
|
|
42
|
-
if (!this.isFound)
|
|
43
|
-
yield this.serial.closePort(this.path);
|
|
44
|
-
this.isScanning = false;
|
|
45
|
-
resolve(this.result);
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
scan() {
|
|
49
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
if (this.isScanning)
|
|
51
|
-
return;
|
|
52
|
-
this.isScanning = true;
|
|
53
|
-
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
54
|
-
this.logEvent({ message: 'starting scan', path: this.path, interface: this.serial.getName() });
|
|
55
|
-
this.serial.scanEvents.on('timeout', () => this.onStopRequest(resolve));
|
|
56
|
-
this.serial.scanEvents.on('stop', () => this.onStopRequest(resolve));
|
|
57
|
-
let found = false;
|
|
58
|
-
while (!found && this.isScanning) {
|
|
59
|
-
try {
|
|
60
|
-
const { protocol } = this.props;
|
|
61
|
-
let host, port;
|
|
62
|
-
if (this.serial.getName() === types_1.SerialInterfaceType.TCPIP) {
|
|
63
|
-
[host, port] = this.path.split(':');
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
port = this.path;
|
|
67
|
-
}
|
|
68
|
-
const adapterSettings = { interface: this.serial.getName(), host, port, protocol };
|
|
69
|
-
const adapter = adapter_factory_1.default.getInstance().createInstance(adapterSettings);
|
|
70
|
-
found = yield adapter.check();
|
|
71
|
-
if (found) {
|
|
72
|
-
this.isFound = true;
|
|
73
|
-
const name = adapter.getName();
|
|
74
|
-
resolve(Object.assign(Object.assign({}, adapterSettings), { name }));
|
|
75
|
-
}
|
|
76
|
-
yield (0, utils_1.sleep)(100);
|
|
77
|
-
}
|
|
78
|
-
catch (err) {
|
|
79
|
-
this.logEvent({ message: 'error', fn: 'scan()', error: err.message || err, stack: err.stack });
|
|
80
|
-
yield (0, utils_1.sleep)(100);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}));
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
exports.SinglePathScanner = SinglePathScanner;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { BindingInterface } from '@serialport/bindings-interface';
|
|
2
|
-
import { InterfaceBinding, InterfaceImplementation } from './types';
|
|
3
|
-
export default class SerialPortProvider {
|
|
4
|
-
static _instance: SerialPortProvider;
|
|
5
|
-
interfaces: InterfaceBinding[];
|
|
6
|
-
implemenations: InterfaceImplementation[];
|
|
7
|
-
static getInstance(): SerialPortProvider;
|
|
8
|
-
constructor();
|
|
9
|
-
setBinding(ifaceName: string, binding: BindingInterface): void;
|
|
10
|
-
getBinding(ifaceName: string): BindingInterface;
|
|
11
|
-
getSerialPort(ifaceName: string, props: any): any;
|
|
12
|
-
list(ifaceName: string): Promise<any>;
|
|
13
|
-
setLegacyClass(ifaceName: string, Serialport: any): void;
|
|
14
|
-
getLegacyInfo(ifaceName: string): InterfaceImplementation;
|
|
15
|
-
getLegacyClass(ifaceName: string): any;
|
|
16
|
-
}
|
|
17
|
-
export declare const useSerialPortProvider: () => SerialPortProvider;
|
package/lib/serial/serialport.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.useSerialPortProvider = void 0;
|
|
13
|
-
const { SerialPortStream } = require('@serialport/stream');
|
|
14
|
-
const DEFAULT_BAUD_RATE = 9600;
|
|
15
|
-
class SerialPortProvider {
|
|
16
|
-
static getInstance() {
|
|
17
|
-
if (!SerialPortProvider._instance)
|
|
18
|
-
SerialPortProvider._instance = new SerialPortProvider();
|
|
19
|
-
return SerialPortProvider._instance;
|
|
20
|
-
}
|
|
21
|
-
constructor() {
|
|
22
|
-
this.interfaces = [];
|
|
23
|
-
this.implemenations = [];
|
|
24
|
-
}
|
|
25
|
-
setBinding(ifaceName, binding) {
|
|
26
|
-
const existing = this.interfaces.find(ib => ib.name === ifaceName);
|
|
27
|
-
if (existing)
|
|
28
|
-
existing.binding = binding;
|
|
29
|
-
else
|
|
30
|
-
this.interfaces.push({ name: ifaceName, binding });
|
|
31
|
-
}
|
|
32
|
-
getBinding(ifaceName) {
|
|
33
|
-
const existing = this.interfaces.find(ib => ib.name === ifaceName);
|
|
34
|
-
if (existing)
|
|
35
|
-
return existing.binding;
|
|
36
|
-
}
|
|
37
|
-
getSerialPort(ifaceName, props) {
|
|
38
|
-
const binding = this.getBinding(ifaceName);
|
|
39
|
-
if (binding) {
|
|
40
|
-
props.binding = binding;
|
|
41
|
-
if (props.autoOpen === undefined)
|
|
42
|
-
props.autoOpen = false;
|
|
43
|
-
if (!props.baudRate)
|
|
44
|
-
props.baudRate = DEFAULT_BAUD_RATE;
|
|
45
|
-
return new SerialPortStream(props);
|
|
46
|
-
}
|
|
47
|
-
const legacy = this.getLegacyInfo(ifaceName);
|
|
48
|
-
if (legacy && legacy.Serialport) {
|
|
49
|
-
const portName = props.path;
|
|
50
|
-
if (props.autoOpen === undefined)
|
|
51
|
-
props.autoOpen = false;
|
|
52
|
-
const settings = Object.assign({}, props);
|
|
53
|
-
delete settings.path;
|
|
54
|
-
return new legacy.Serialport(portName, settings);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
list(ifaceName) {
|
|
58
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
-
const Binding = this.getBinding(ifaceName);
|
|
60
|
-
if (Binding)
|
|
61
|
-
return yield Binding.list();
|
|
62
|
-
const legacy = this.getLegacyInfo(ifaceName);
|
|
63
|
-
if (legacy && legacy.Serialport && legacy.Serialport.list) {
|
|
64
|
-
return yield legacy.Serialport.list();
|
|
65
|
-
}
|
|
66
|
-
return [];
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
setLegacyClass(ifaceName, Serialport) {
|
|
70
|
-
const existing = this.getLegacyInfo(ifaceName);
|
|
71
|
-
if (existing)
|
|
72
|
-
existing.Serialport = Serialport;
|
|
73
|
-
else
|
|
74
|
-
this.implemenations.push({ name: ifaceName, Serialport });
|
|
75
|
-
}
|
|
76
|
-
getLegacyInfo(ifaceName) {
|
|
77
|
-
return this.implemenations.find(ib => ib.name === ifaceName);
|
|
78
|
-
}
|
|
79
|
-
getLegacyClass(ifaceName) {
|
|
80
|
-
const existing = this.implemenations.find(ib => ib.name === ifaceName);
|
|
81
|
-
if (existing)
|
|
82
|
-
return existing.Serialport;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
exports.default = SerialPortProvider;
|
|
86
|
-
const useSerialPortProvider = () => SerialPortProvider.getInstance();
|
|
87
|
-
exports.useSerialPortProvider = useSerialPortProvider;
|
package/lib/types/Command.d.ts
DELETED
package/lib/types/Command.js
DELETED
package/lib/types/command.d.ts
DELETED
|
File without changes
|
package/lib/types/command.js
DELETED
|
File without changes
|
package/lib/types/route.d.ts
DELETED
|
File without changes
|
package/lib/types/route.js
DELETED
|
File without changes
|
package/lib/types/types.d.ts
DELETED
package/lib/types/types.js
DELETED