@zaber/motion 7.5.0 → 7.6.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.
- package/binding.gyp +2 -1
- package/dist/binding/wasm/zaber-motion-core.wasm +0 -0
- package/dist/lib/ascii/connection.d.ts +11 -0
- package/dist/lib/ascii/connection.d.ts.map +1 -1
- package/dist/lib/ascii/connection.js +24 -0
- package/dist/lib/ascii/connection.js.map +1 -1
- package/dist/lib/ascii/servo_tuner.d.ts +35 -6
- package/dist/lib/ascii/servo_tuner.d.ts.map +1 -1
- package/dist/lib/ascii/servo_tuner.js +20 -6
- package/dist/lib/ascii/servo_tuner.js.map +1 -1
- package/dist/lib/ascii/simple_tuning.d.ts +8 -0
- package/dist/lib/ascii/simple_tuning.d.ts.map +1 -1
- package/dist/lib/ascii/simple_tuning.js +4 -0
- package/dist/lib/ascii/simple_tuning.js.map +1 -1
- package/dist/lib/binary/connection.d.ts +11 -0
- package/dist/lib/binary/connection.d.ts.map +1 -1
- package/dist/lib/binary/connection.js +24 -0
- package/dist/lib/binary/connection.js.map +1 -1
- package/dist/lib/gateway/wasm-exec.d.ts.map +1 -1
- package/dist/lib/gateway/wasm-exec.js +70 -64
- package/dist/lib/gateway/wasm-exec.js.map +1 -1
- package/dist/lib/library.js +1 -1
- package/dist/lib/library.js.map +1 -1
- package/dist/lib/requests/set_simple_tuning.d.ts +6 -1
- package/dist/lib/requests/set_simple_tuning.d.ts.map +1 -1
- package/dist/lib/requests/set_simple_tuning.js +11 -2
- package/dist/lib/requests/set_simple_tuning.js.map +1 -1
- package/dist/lib/units.d.ts +3 -1
- package/dist/lib/units.d.ts.map +1 -1
- package/dist/lib/units.js +2 -0
- package/dist/lib/units.js.map +1 -1
- package/package.json +1 -1
|
@@ -105,12 +105,23 @@ export declare class Connection {
|
|
|
105
105
|
* @returns A string that represents the connection.
|
|
106
106
|
*/
|
|
107
107
|
toString(): string;
|
|
108
|
+
/**
|
|
109
|
+
* Releases native resources of the connection.
|
|
110
|
+
* @param interfaceId The ID of the connection.
|
|
111
|
+
*/
|
|
112
|
+
private static _free;
|
|
108
113
|
private _disconnected;
|
|
109
114
|
/**
|
|
110
115
|
* Event invoked when connection is interrupted or closed.
|
|
111
116
|
*/
|
|
112
117
|
get disconnected(): Observable<MotionLibException>;
|
|
113
118
|
private _subscribe;
|
|
119
|
+
/**
|
|
120
|
+
* Releases the native resources of the connection.
|
|
121
|
+
* Should only be called if your environment does not support FinalizationRegistry.
|
|
122
|
+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry
|
|
123
|
+
*/
|
|
124
|
+
free(): void;
|
|
114
125
|
}
|
|
115
126
|
declare namespace Connection {
|
|
116
127
|
interface OpenSerialPortOptions {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../../src/binary/connection.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAiB,MAAM,MAAM,CAAC;AAKjD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../../src/binary/connection.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAiB,MAAM,MAAM,CAAC;AAKjD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,O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D,OAAO,CAAC,OAAO,EAAE,CAAC;IAwBrB;;;OAGG;IACU,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC;IAgB/C;;;;OAIG;IACU,aAAa,CACxB,OAAO,GAAE,UAAU,CAAC,oBAAyB,GAC5C,OAAO,CAAC,MAAM,EAAE,CAAC;IAoBpB;;;;;OAKG;IACI,SAAS,CACd,aAAa,EAAE,MAAM,GACpB,MAAM;IAOT;;;OAGG;IACI,QAAQ,IAAI,MAAM;IAgBzB;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,KAAK;IAcpB,OAAO,CAAC,aAAa,CAA2C;IAEhE;;OAEG;IACH,IAAW,YAAY,IAAI,UAAU,CAAC,kBAAkB,CAAC,CAExD;IAED,OAAO,CAAC,UAAU;IAuBlB;;;;OAIG;IACI,IAAI,IAAI,IAAI;CAGpB;AAED,kBAAU,UAAU,CAAC;IACnB,UAAiB,qBAAqB;QAClC;;WAEG;QACH,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB;;;WAGG;QACH,aAAa,CAAC,EAAE,OAAO,CAAC;KAC3B;IACD,UAAiB,cAAc;QAC3B;;;WAGG;QACH,aAAa,CAAC,EAAE,OAAO,CAAC;KAC3B;IACD,UAAiB,qBAAqB;QAClC;;WAEG;QACH,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB;;WAEG;QACH,WAAW,CAAC,EAAE,OAAO,CAAC;KACzB;IACD,UAAiB,kCAAkC;QAC/C;;WAEG;QACH,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB;;WAEG;QACH,WAAW,CAAC,EAAE,OAAO,CAAC;KACzB;IACD,UAAiB,oBAAoB;QACjC;;WAEG;QACH,eAAe,CAAC,EAAE,OAAO,CAAC;KAC7B;CACF"}
|
|
@@ -33,6 +33,7 @@ const gateway_1 = require("../gateway");
|
|
|
33
33
|
const requests = __importStar(require("../requests"));
|
|
34
34
|
const device_1 = require("./device");
|
|
35
35
|
const message_1 = require("./message");
|
|
36
|
+
const finalizer_1 = require("../finalizer");
|
|
36
37
|
/**
|
|
37
38
|
* Class representing access to particular connection (serial port, TCP connection) using the legacy Binary protocol.
|
|
38
39
|
*/
|
|
@@ -46,6 +47,7 @@ class Connection {
|
|
|
46
47
|
constructor(interfaceId) {
|
|
47
48
|
this._disconnected = new rxjs_1.ReplaySubject();
|
|
48
49
|
this._interfaceId = interfaceId;
|
|
50
|
+
(0, finalizer_1.registerForFinalization)(this, Connection._free.bind(null, interfaceId));
|
|
49
51
|
this._subscribe();
|
|
50
52
|
}
|
|
51
53
|
/**
|
|
@@ -243,6 +245,20 @@ class Connection {
|
|
|
243
245
|
const response = gateway.callSync('interface/to_string', request, requests.StringResponse.fromBinary);
|
|
244
246
|
return response.value;
|
|
245
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* Releases native resources of the connection.
|
|
250
|
+
* @param interfaceId The ID of the connection.
|
|
251
|
+
*/
|
|
252
|
+
static _free(interfaceId) {
|
|
253
|
+
const request = {
|
|
254
|
+
...requests.InterfaceEmptyRequest.DEFAULT,
|
|
255
|
+
interfaceId: interfaceId,
|
|
256
|
+
toBinary() {
|
|
257
|
+
return requests.InterfaceEmptyRequest.toBinary(this);
|
|
258
|
+
},
|
|
259
|
+
};
|
|
260
|
+
gateway.callSync('interface/free', request);
|
|
261
|
+
}
|
|
246
262
|
/**
|
|
247
263
|
* Event invoked when connection is interrupted or closed.
|
|
248
264
|
*/
|
|
@@ -254,6 +270,14 @@ class Connection {
|
|
|
254
270
|
this.replyOnly = gateway_1.events.pipe((0, operators_1.takeUntil)(this._disconnected), (0, gateway_1.filterEvent)('binary/interface/reply_only'), (0, operators_1.filter)(event => event.interfaceId === this.interfaceId), (0, operators_1.map)(event => event.reply));
|
|
255
271
|
gateway_1.events.pipe((0, gateway_1.filterEvent)('interface/disconnected'), (0, operators_1.filter)(event => event.interfaceId === this.interfaceId), (0, operators_1.take)(1), (0, operators_1.map)(({ errorMessage, errorType }) => gateway.convertToException(errorType, errorMessage))).subscribe(this._disconnected);
|
|
256
272
|
}
|
|
273
|
+
/**
|
|
274
|
+
* Releases the native resources of the connection.
|
|
275
|
+
* Should only be called if your environment does not support FinalizationRegistry.
|
|
276
|
+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry
|
|
277
|
+
*/
|
|
278
|
+
free() {
|
|
279
|
+
Connection._free(this.interfaceId);
|
|
280
|
+
}
|
|
257
281
|
}
|
|
258
282
|
exports.Connection = Connection;
|
|
259
283
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../../src/binary/connection.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,sDAAsD;;;;;;;;;;;;;;;;;;;;;;;;;;AAEtD,+BAAiD;AACjD,8CAA8D;AAC9D,oDAAsC;AACtC,wCAAiD;AACjD,sDAAwC;AACxC,qCAAkC;AAIlC,uCAAoC;AAGpC;;GAEG;AACH,MAAa,UAAU;IAgBrB;;OAEG;IACH,IAAW,WAAW;QACpB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAGD,YAAY,WAAmB;QAqRvB,kBAAa,GAAG,IAAI,oBAAa,EAAsB,CAAC;QApR9D,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;IAED;;;;;;;OAOG;IACI,MAAM,CAAC,KAAK,CAAC,cAAc,CAChC,QAAgB,EAChB,UAA4C,EAAE;QAE9C,MAAM,EACJ,QAAQ,GAAG,UAAU,CAAC,iBAAiB,EACvC,aAAa,GAAG,KAAK,GACtB,GAAG,OAAO,CAAC;QACZ,MAAM,OAAO,GAA0D;YACrE,GAAG,QAAQ,CAAC,0BAA0B,CAAC,OAAO;YAC9C,aAAa,EAAE,QAAQ,CAAC,aAAa,CAAC,WAAW;YACjD,QAAQ,EAAE,QAAQ;YAClB,QAAQ,EAAE,QAAQ;YAClB,aAAa,EAAE,aAAa;YA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qBAAS,EAAC,IAAI,CAAC,aAAa,CAAC,EAC7B,IAAA,qBAAW,EAA6C,mCAAmC,CAAC,EAC5F,IAAA,kBAAM,EAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,WAAW,KAAK,IAAI,CAAC,WAAW,CAAC,EACvD,IAAA,eAAG,EAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,eAAe,CAAC,CACpC,CAAC;QAEF,IAAI,CAAC,SAAS,GAAG,gBAAM,CAAC,IAAI,CAC1B,IAAA,qBAAS,EAAC,IAAI,CAAC,aAAa,CAAC,EAC7B,IAAA,qBAAW,EAAuC,6BAA6B,CAAC,EAChF,IAAA,kBAAM,EAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,WAAW,KAAK,IAAI,CAAC,WAAW,CAAC,EACvD,IAAA,eAAG,EAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAC1B,CAAC;QAEF,gBAAM,CAAC,IAAI,CACT,IAAA,qBAAW,EAA6B,wBAAwB,CAAC,EACjE,IAAA,kBAAM,EAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,WAAW,KAAK,IAAI,CAAC,WAAW,CAAC,EACvD,IAAA,gBAAI,EAAC,CAAC,CAAC,EACP,IAAA,eAAG,EAAC,CAAC,EAAE,YAAY,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,kBAAkB,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC,CAC1F,CAAC,SAAS,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAClC,CAAC;;AA3UH,gCA4UC;AAjUC;;GAEG;AACoB,4BAAiB,GAAW,IAAI,AAAf,CAAgB","sourcesContent":["// ==== THIS FILE IS GENERATED FROM A TEMPLATE ==== //\n// ============= DO NOT EDIT DIRECTLY ============= //\n\nimport { Observable, ReplaySubject } from 'rxjs';\nimport { map, filter, takeUntil, take } from 'rxjs/operators';\nimport * as gateway from '../gateway';\nimport { events, filterEvent } from '../gateway';\nimport * as requests from '../requests';\nimport { Device } from './device';\nimport { UnknownResponseEvent } from './unknown_response_event';\nimport { ReplyOnlyEvent } from './reply_only_event';\nimport { CommandCode } from './command_code';\nimport { Message } from './message';\nimport { MotionLibException } from '../exceptions';\n\n/**\n * Class representing access to particular connection (serial port, TCP connection) using the legacy Binary protocol.\n */\nexport class Connection {\n /**\n * Event invoked when a response from a device cannot be matched to any known request.\n */\n public unknownResponse!: Observable<UnknownResponseEvent>;\n\n /**\n * Event invoked when a reply-only command such as a move tracking message is received from a device.\n */\n public replyOnly!: Observable<ReplyOnlyEvent>;\n\n /**\n * Default baud rate for serial connections.\n */\n public static readonly DEFAULT_BAUD_RATE: number = 9600;\n\n /**\n * The interface ID identifies thisConnection instance with the underlying library.\n */\n public get interfaceId(): number {\n return this._interfaceId;\n }\n private _interfaceId: number;\n\n constructor(interfaceId: number) {\n this._interfaceId = interfaceId;\n this._subscribe();\n }\n\n /**\n * Opens a serial port.\n * @param portName Name of the port to open.\n * @param [options.baudRate=Connection.DEFAULT_BAUD_RATE] Optional baud rate (defaults to 9600).\n * @param [options.useMessageIds=false] Enable use of message IDs (defaults to disabled).\n * All your devices must be pre-configured to match.\n * @returns An object representing the port.\n */\n public static async openSerialPort(\n portName: string,\n options: Connection.OpenSerialPortOptions = {}\n ): Promise<Connection> {\n const {\n baudRate = Connection.DEFAULT_BAUD_RATE,\n useMessageIds = false,\n } = options;\n const request: requests.OpenBinaryInterfaceRequest & gateway.Message = {\n ...requests.OpenBinaryInterfaceRequest.DEFAULT,\n interfaceType: requests.InterfaceType.SERIAL_PORT,\n portName: portName,\n baudRate: baudRate,\n useMessageIds: useMessageIds,\n toBinary() {\n return requests.OpenBinaryInterfaceRequest.toBinary(this);\n },\n };\n\n const response = await gateway.callAsync<requests.OpenInterfaceResponse>(\n 'binary/interface/open',\n request,\n requests.OpenInterfaceResponse.fromBinary);\n return new Connection(response.interfaceId);\n }\n\n /**\n * Opens a TCP connection.\n * @param hostName Hostname or IP address.\n * @param port Port number.\n * @param [options.useMessageIds=false] Enable use of message IDs (defaults to disabled).\n * All your devices must be pre-configured to match.\n * @returns An object representing the connection.\n */\n public static async openTcp(\n hostName: string,\n port: number,\n options: Connection.OpenTcpOptions = {}\n ): Promise<Connection> {\n const {\n useMessageIds = false,\n } = options;\n const request: requests.OpenBinaryInterfaceRequest & gateway.Message = {\n ...requests.OpenBinaryInterfaceRequest.DEFAULT,\n interfaceType: requests.InterfaceType.TCP,\n hostName: hostName,\n port: port,\n useMessageIds: useMessageIds,\n toBinary() {\n return requests.OpenBinaryInterfaceRequest.toBinary(this);\n },\n };\n\n const response = await gateway.callAsync<requests.OpenInterfaceResponse>(\n 'binary/interface/open',\n request,\n requests.OpenInterfaceResponse.fromBinary);\n return new Connection(response.interfaceId);\n }\n\n /**\n * Close the connection.\n */\n public async close(): Promise<void> {\n const request: requests.InterfaceEmptyRequest & gateway.Message = {\n ...requests.InterfaceEmptyRequest.DEFAULT,\n interfaceId: this.interfaceId,\n toBinary() {\n return requests.InterfaceEmptyRequest.toBinary(this);\n },\n };\n\n await gateway.callAsync('interface/close', request);\n }\n\n /**\n * Sends a generic Binary command to this connection.\n * For more information please refer to the\n * [Binary Protocol Manual](https://www.zaber.com/protocol-manual?protocol=Binary#topic_quick_command_reference).\n * @param device Device address to send the command to. Use zero for broadcast.\n * @param command Command to send.\n * @param [data=0] Optional data argument to the command. Defaults to zero.\n * @param [options.timeout=0.0] Number of seconds to wait for a response from the device. 0 or negative defaults to 0.5s.\n * @param [options.checkErrors=true] Controls whether to throw an exception when the device rejects the command.\n * @returns A response to the command.\n */\n public async genericCommand(\n device: number,\n command: CommandCode,\n data: number = 0,\n options: Connection.GenericCommandOptions = {}\n ): Promise<Message> {\n const {\n timeout = 0.0,\n checkErrors = true,\n } = options;\n const request: requests.GenericBinaryRequest & gateway.Message = {\n ...requests.GenericBinaryRequest.DEFAULT,\n interfaceId: this.interfaceId,\n device: device,\n command: command,\n data: data,\n timeout: timeout,\n checkErrors: checkErrors,\n toBinary() {\n return requests.GenericBinaryRequest.toBinary(this);\n },\n };\n\n const response = await gateway.callAsync<Message>(\n 'binary/interface/generic_command',\n request,\n Message.fromBinary);\n return response;\n }\n\n /**\n * Sends a generic Binary command to this connection without expecting a response.\n * For more information please refer to the\n * [Binary Protocol Manual](https://www.zaber.com/protocol-manual?protocol=Binary#topic_quick_command_reference).\n * @param device Device address to send the command to. Use zero for broadcast.\n * @param command Command to send.\n * @param [data=0] Optional data argument to the command. Defaults to zero.\n */\n public async genericCommandNoResponse(\n device: number,\n command: CommandCode,\n data: number = 0\n ): Promise<void> {\n const request: requests.GenericBinaryRequest & gateway.Message = {\n ...requests.GenericBinaryRequest.DEFAULT,\n interfaceId: this.interfaceId,\n device: device,\n command: command,\n data: data,\n toBinary() {\n return requests.GenericBinaryRequest.toBinary(this);\n },\n };\n\n await gateway.callAsync('binary/interface/generic_command_no_response', request);\n }\n\n /**\n * Sends a generic Binary command to this connection and expects responses from one or more devices.\n * Responses are returned in order of arrival.\n * For more information please refer to the\n * [Binary Protocol Manual](https://www.zaber.com/protocol-manual?protocol=Binary#topic_quick_command_reference).\n * @param command Command to send.\n * @param [data=0] Optional data argument to the command. Defaults to zero.\n * @param [options.timeout=0.0] Number of seconds to wait for all responses from the device chain. 0 or negative defaults to 0.5s.\n * @param [options.checkErrors=true] Controls whether to throw an exception when any device rejects the command.\n * @returns All responses to the command.\n */\n public async genericCommandMultiResponse(\n command: CommandCode,\n data: number = 0,\n options: Connection.GenericCommandMultiResponseOptions = {}\n ): Promise<Message[]> {\n const {\n timeout = 0.0,\n checkErrors = true,\n } = options;\n const request: requests.GenericBinaryRequest & gateway.Message = {\n ...requests.GenericBinaryRequest.DEFAULT,\n interfaceId: this.interfaceId,\n command: command,\n data: data,\n timeout: timeout,\n checkErrors: checkErrors,\n toBinary() {\n return requests.GenericBinaryRequest.toBinary(this);\n },\n };\n\n const response = await gateway.callAsync<requests.BinaryMessageCollection>(\n 'binary/interface/generic_command_multi_response',\n request,\n requests.BinaryMessageCollection.fromBinary);\n return response.messages;\n }\n\n /**\n * Renumbers devices present on this connection. After renumbering, you must identify devices again.\n * @returns Total number of devices that responded to the renumber.\n */\n public async renumberDevices(): Promise<number> {\n const request: requests.InterfaceEmptyRequest & gateway.Message = {\n ...requests.InterfaceEmptyRequest.DEFAULT,\n interfaceId: this.interfaceId,\n toBinary() {\n return requests.InterfaceEmptyRequest.toBinary(this);\n },\n };\n\n const response = await gateway.callAsync<requests.IntResponse>(\n 'binary/device/renumber',\n request,\n requests.IntResponse.fromBinary);\n return response.value;\n }\n\n /**\n * Attempts to detect any devices present on this connection.\n * @param [options.identifyDevices=true] Determines whether device identification should be performed as well.\n * @returns Array of detected devices.\n */\n public async detectDevices(\n options: Connection.DetectDevicesOptions = {}\n ): Promise<Device[]> {\n const {\n identifyDevices = true,\n } = options;\n const request: requests.BinaryDeviceDetectRequest & gateway.Message = {\n ...requests.BinaryDeviceDetectRequest.DEFAULT,\n interfaceId: this.interfaceId,\n identifyDevices: identifyDevices,\n toBinary() {\n return requests.BinaryDeviceDetectRequest.toBinary(this);\n },\n };\n\n const response = await gateway.callAsync<requests.BinaryDeviceDetectResponse>(\n 'binary/device/detect',\n request,\n requests.BinaryDeviceDetectResponse.fromBinary);\n return response.devices.map(deviceAddress => this.getDevice(deviceAddress));\n }\n\n /**\n * Gets a Device class instance which allows you to control a particular device on this connection.\n * Devices are numbered from 1.\n * @param deviceAddress Address of device intended to control. Address is configured for each device.\n * @returns Device instance.\n */\n public getDevice(\n deviceAddress: number\n ): Device {\n if (deviceAddress <= 0) {\n throw new TypeError('Invalid value; physical devices are numbered from 1.');\n }\n return new Device(this, deviceAddress);\n }\n\n /**\n * Returns a string that represents the connection.\n * @returns A string that represents the connection.\n */\n public toString(): string {\n const request: requests.InterfaceEmptyRequest & gateway.Message = {\n ...requests.InterfaceEmptyRequest.DEFAULT,\n interfaceId: this.interfaceId,\n toBinary() {\n return requests.InterfaceEmptyRequest.toBinary(this);\n },\n };\n\n const response = gateway.callSync<requests.StringResponse>(\n 'interface/to_string',\n request,\n requests.StringResponse.fromBinary);\n return response.value;\n }\n\n private _disconnected = new ReplaySubject<MotionLibException>();\n\n /**\n * Event invoked when connection is interrupted or closed.\n */\n public get disconnected(): Observable<MotionLibException> {\n return this._disconnected;\n }\n\n private _subscribe(): void {\n this.unknownResponse = events.pipe(\n takeUntil(this._disconnected),\n filterEvent<requests.UnknownBinaryResponseEventWrapper>('binary/interface/unknown_response'),\n filter(event => event.interfaceId === this.interfaceId),\n map(event => event.unknownResponse)\n );\n\n this.replyOnly = events.pipe(\n takeUntil(this._disconnected),\n filterEvent<requests.BinaryReplyOnlyEventWrapper>('binary/interface/reply_only'),\n filter(event => event.interfaceId === this.interfaceId),\n map(event => event.reply)\n );\n\n events.pipe(\n filterEvent<requests.DisconnectedEvent>('interface/disconnected'),\n filter(event => event.interfaceId === this.interfaceId),\n take(1),\n map(({ errorMessage, errorType }) => gateway.convertToException(errorType, errorMessage))\n ).subscribe(this._disconnected);\n }\n}\n\nnamespace Connection {\n export interface OpenSerialPortOptions {\n /**\n * Optional baud rate (defaults to 9600).\n */\n baudRate?: number;\n /**\n * Enable use of message IDs (defaults to disabled).\n * All your devices must be pre-configured to match.\n */\n useMessageIds?: boolean;\n }\n export interface OpenTcpOptions {\n /**\n * Enable use of message IDs (defaults to disabled).\n * All your devices must be pre-configured to match.\n */\n useMessageIds?: boolean;\n }\n export interface GenericCommandOptions {\n /**\n * Number of seconds to wait for a response from the device. 0 or negative defaults to 0.5s.\n */\n timeout?: number;\n /**\n * Controls whether to throw an exception when the device rejects the command.\n */\n checkErrors?: boolean;\n }\n export interface GenericCommandMultiResponseOptions {\n /**\n * Number of seconds to wait for all responses from the device chain. 0 or negative defaults to 0.5s.\n */\n timeout?: number;\n /**\n * Controls whether to throw an exception when any device rejects the command.\n */\n checkErrors?: boolean;\n }\n export interface DetectDevicesOptions {\n /**\n * Determines whether device identification should be performed as well.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IACrC,CAAC;;AAvWH,gCAwWC;AA7VC;;GAEG;AACoB,4BAAiB,GAAW,IAAI,AAAf,CAAgB","sourcesContent":["// ==== THIS FILE IS GENERATED FROM A TEMPLATE ==== //\n// ============= DO NOT EDIT DIRECTLY ============= //\n\nimport { Observable, ReplaySubject } from 'rxjs';\nimport { map, filter, takeUntil, take } from 'rxjs/operators';\nimport * as gateway from '../gateway';\nimport { events, filterEvent } from '../gateway';\nimport * as requests from '../requests';\nimport { Device } from './device';\nimport { UnknownResponseEvent } from './unknown_response_event';\nimport { ReplyOnlyEvent } from './reply_only_event';\nimport { CommandCode } from './command_code';\nimport { Message } from './message';\nimport { MotionLibException } from '../exceptions';\nimport { registerForFinalization } from '../finalizer';\n\n/**\n * Class representing access to particular connection (serial port, TCP connection) using the legacy Binary protocol.\n */\nexport class Connection {\n /**\n * Event invoked when a response from a device cannot be matched to any known request.\n */\n public unknownResponse!: Observable<UnknownResponseEvent>;\n\n /**\n * Event invoked when a reply-only command such as a move tracking message is received from a device.\n */\n public replyOnly!: Observable<ReplyOnlyEvent>;\n\n /**\n * Default baud rate for serial connections.\n */\n public static readonly DEFAULT_BAUD_RATE: number = 9600;\n\n /**\n * The interface ID identifies thisConnection instance with the underlying library.\n */\n public get interfaceId(): number {\n return this._interfaceId;\n }\n private _interfaceId: number;\n\n constructor(interfaceId: number) {\n this._interfaceId = interfaceId;\n registerForFinalization(this, Connection._free.bind(null, interfaceId));\n this._subscribe();\n }\n\n /**\n * Opens a serial port.\n * @param portName Name of the port to open.\n * @param [options.baudRate=Connection.DEFAULT_BAUD_RATE] Optional baud rate (defaults to 9600).\n * @param [options.useMessageIds=false] Enable use of message IDs (defaults to disabled).\n * All your devices must be pre-configured to match.\n * @returns An object representing the port.\n */\n public static async openSerialPort(\n portName: string,\n options: Connection.OpenSerialPortOptions = {}\n ): Promise<Connection> {\n const {\n baudRate = Connection.DEFAULT_BAUD_RATE,\n useMessageIds = false,\n } = options;\n const request: requests.OpenBinaryInterfaceRequest & gateway.Message = {\n ...requests.OpenBinaryInterfaceRequest.DEFAULT,\n interfaceType: requests.InterfaceType.SERIAL_PORT,\n portName: portName,\n baudRate: baudRate,\n useMessageIds: useMessageIds,\n toBinary() {\n return requests.OpenBinaryInterfaceRequest.toBinary(this);\n },\n };\n\n const response = await gateway.callAsync<requests.OpenInterfaceResponse>(\n 'binary/interface/open',\n request,\n requests.OpenInterfaceResponse.fromBinary);\n return new Connection(response.interfaceId);\n }\n\n /**\n * Opens a TCP connection.\n * @param hostName Hostname or IP address.\n * @param port Port number.\n * @param [options.useMessageIds=false] Enable use of message IDs (defaults to disabled).\n * All your devices must be pre-configured to match.\n * @returns An object representing the connection.\n */\n public static async openTcp(\n hostName: string,\n port: number,\n options: Connection.OpenTcpOptions = {}\n ): Promise<Connection> {\n const {\n useMessageIds = false,\n } = options;\n const request: requests.OpenBinaryInterfaceRequest & gateway.Message = {\n ...requests.OpenBinaryInterfaceRequest.DEFAULT,\n interfaceType: requests.InterfaceType.TCP,\n hostName: hostName,\n port: port,\n useMessageIds: useMessageIds,\n toBinary() {\n return requests.OpenBinaryInterfaceRequest.toBinary(this);\n },\n };\n\n const response = await gateway.callAsync<requests.OpenInterfaceResponse>(\n 'binary/interface/open',\n request,\n requests.OpenInterfaceResponse.fromBinary);\n return new Connection(response.interfaceId);\n }\n\n /**\n * Close the connection.\n */\n public async close(): Promise<void> {\n const request: requests.InterfaceEmptyRequest & gateway.Message = {\n ...requests.InterfaceEmptyRequest.DEFAULT,\n interfaceId: this.interfaceId,\n toBinary() {\n return requests.InterfaceEmptyRequest.toBinary(this);\n },\n };\n\n await gateway.callAsync('interface/close', request);\n }\n\n /**\n * Sends a generic Binary command to this connection.\n * For more information please refer to the\n * [Binary Protocol Manual](https://www.zaber.com/protocol-manual?protocol=Binary#topic_quick_command_reference).\n * @param device Device address to send the command to. Use zero for broadcast.\n * @param command Command to send.\n * @param [data=0] Optional data argument to the command. Defaults to zero.\n * @param [options.timeout=0.0] Number of seconds to wait for a response from the device. 0 or negative defaults to 0.5s.\n * @param [options.checkErrors=true] Controls whether to throw an exception when the device rejects the command.\n * @returns A response to the command.\n */\n public async genericCommand(\n device: number,\n command: CommandCode,\n data: number = 0,\n options: Connection.GenericCommandOptions = {}\n ): Promise<Message> {\n const {\n timeout = 0.0,\n checkErrors = true,\n } = options;\n const request: requests.GenericBinaryRequest & gateway.Message = {\n ...requests.GenericBinaryRequest.DEFAULT,\n interfaceId: this.interfaceId,\n device: device,\n command: command,\n data: data,\n timeout: timeout,\n checkErrors: checkErrors,\n toBinary() {\n return requests.GenericBinaryRequest.toBinary(this);\n },\n };\n\n const response = await gateway.callAsync<Message>(\n 'binary/interface/generic_command',\n request,\n Message.fromBinary);\n return response;\n }\n\n /**\n * Sends a generic Binary command to this connection without expecting a response.\n * For more information please refer to the\n * [Binary Protocol Manual](https://www.zaber.com/protocol-manual?protocol=Binary#topic_quick_command_reference).\n * @param device Device address to send the command to. Use zero for broadcast.\n * @param command Command to send.\n * @param [data=0] Optional data argument to the command. Defaults to zero.\n */\n public async genericCommandNoResponse(\n device: number,\n command: CommandCode,\n data: number = 0\n ): Promise<void> {\n const request: requests.GenericBinaryRequest & gateway.Message = {\n ...requests.GenericBinaryRequest.DEFAULT,\n interfaceId: this.interfaceId,\n device: device,\n command: command,\n data: data,\n toBinary() {\n return requests.GenericBinaryRequest.toBinary(this);\n },\n };\n\n await gateway.callAsync('binary/interface/generic_command_no_response', request);\n }\n\n /**\n * Sends a generic Binary command to this connection and expects responses from one or more devices.\n * Responses are returned in order of arrival.\n * For more information please refer to the\n * [Binary Protocol Manual](https://www.zaber.com/protocol-manual?protocol=Binary#topic_quick_command_reference).\n * @param command Command to send.\n * @param [data=0] Optional data argument to the command. Defaults to zero.\n * @param [options.timeout=0.0] Number of seconds to wait for all responses from the device chain. 0 or negative defaults to 0.5s.\n * @param [options.checkErrors=true] Controls whether to throw an exception when any device rejects the command.\n * @returns All responses to the command.\n */\n public async genericCommandMultiResponse(\n command: CommandCode,\n data: number = 0,\n options: Connection.GenericCommandMultiResponseOptions = {}\n ): Promise<Message[]> {\n const {\n timeout = 0.0,\n checkErrors = true,\n } = options;\n const request: requests.GenericBinaryRequest & gateway.Message = {\n ...requests.GenericBinaryRequest.DEFAULT,\n interfaceId: this.interfaceId,\n command: command,\n data: data,\n timeout: timeout,\n checkErrors: checkErrors,\n toBinary() {\n return requests.GenericBinaryRequest.toBinary(this);\n },\n };\n\n const response = await gateway.callAsync<requests.BinaryMessageCollection>(\n 'binary/interface/generic_command_multi_response',\n request,\n requests.BinaryMessageCollection.fromBinary);\n return response.messages;\n }\n\n /**\n * Renumbers devices present on this connection. After renumbering, you must identify devices again.\n * @returns Total number of devices that responded to the renumber.\n */\n public async renumberDevices(): Promise<number> {\n const request: requests.InterfaceEmptyRequest & gateway.Message = {\n ...requests.InterfaceEmptyRequest.DEFAULT,\n interfaceId: this.interfaceId,\n toBinary() {\n return requests.InterfaceEmptyRequest.toBinary(this);\n },\n };\n\n const response = await gateway.callAsync<requests.IntResponse>(\n 'binary/device/renumber',\n request,\n requests.IntResponse.fromBinary);\n return response.value;\n }\n\n /**\n * Attempts to detect any devices present on this connection.\n * @param [options.identifyDevices=true] Determines whether device identification should be performed as well.\n * @returns Array of detected devices.\n */\n public async detectDevices(\n options: Connection.DetectDevicesOptions = {}\n ): Promise<Device[]> {\n const {\n identifyDevices = true,\n } = options;\n const request: requests.BinaryDeviceDetectRequest & gateway.Message = {\n ...requests.BinaryDeviceDetectRequest.DEFAULT,\n interfaceId: this.interfaceId,\n identifyDevices: identifyDevices,\n toBinary() {\n return requests.BinaryDeviceDetectRequest.toBinary(this);\n },\n };\n\n const response = await gateway.callAsync<requests.BinaryDeviceDetectResponse>(\n 'binary/device/detect',\n request,\n requests.BinaryDeviceDetectResponse.fromBinary);\n return response.devices.map(deviceAddress => this.getDevice(deviceAddress));\n }\n\n /**\n * Gets a Device class instance which allows you to control a particular device on this connection.\n * Devices are numbered from 1.\n * @param deviceAddress Address of device intended to control. Address is configured for each device.\n * @returns Device instance.\n */\n public getDevice(\n deviceAddress: number\n ): Device {\n if (deviceAddress <= 0) {\n throw new TypeError('Invalid value; physical devices are numbered from 1.');\n }\n return new Device(this, deviceAddress);\n }\n\n /**\n * Returns a string that represents the connection.\n * @returns A string that represents the connection.\n */\n public toString(): string {\n const request: requests.InterfaceEmptyRequest & gateway.Message = {\n ...requests.InterfaceEmptyRequest.DEFAULT,\n interfaceId: this.interfaceId,\n toBinary() {\n return requests.InterfaceEmptyRequest.toBinary(this);\n },\n };\n\n const response = gateway.callSync<requests.StringResponse>(\n 'interface/to_string',\n request,\n requests.StringResponse.fromBinary);\n return response.value;\n }\n\n /**\n * Releases native resources of the connection.\n * @param interfaceId The ID of the connection.\n */\n private static _free(\n interfaceId: number\n ): void {\n const request: requests.InterfaceEmptyRequest & gateway.Message = {\n ...requests.InterfaceEmptyRequest.DEFAULT,\n interfaceId: interfaceId,\n toBinary() {\n return requests.InterfaceEmptyRequest.toBinary(this);\n },\n };\n\n gateway.callSync('interface/free', request);\n }\n\n private _disconnected = new ReplaySubject<MotionLibException>();\n\n /**\n * Event invoked when connection is interrupted or closed.\n */\n public get disconnected(): Observable<MotionLibException> {\n return this._disconnected;\n }\n\n private _subscribe(): void {\n this.unknownResponse = events.pipe(\n takeUntil(this._disconnected),\n filterEvent<requests.UnknownBinaryResponseEventWrapper>('binary/interface/unknown_response'),\n filter(event => event.interfaceId === this.interfaceId),\n map(event => event.unknownResponse)\n );\n\n this.replyOnly = events.pipe(\n takeUntil(this._disconnected),\n filterEvent<requests.BinaryReplyOnlyEventWrapper>('binary/interface/reply_only'),\n filter(event => event.interfaceId === this.interfaceId),\n map(event => event.reply)\n );\n\n events.pipe(\n filterEvent<requests.DisconnectedEvent>('interface/disconnected'),\n filter(event => event.interfaceId === this.interfaceId),\n take(1),\n map(({ errorMessage, errorType }) => gateway.convertToException(errorType, errorMessage))\n ).subscribe(this._disconnected);\n }\n\n /**\n * Releases the native resources of the connection.\n * Should only be called if your environment does not support FinalizationRegistry.\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry\n */\n public free(): void {\n Connection._free(this.interfaceId);\n }\n}\n\nnamespace Connection {\n export interface OpenSerialPortOptions {\n /**\n * Optional baud rate (defaults to 9600).\n */\n baudRate?: number;\n /**\n * Enable use of message IDs (defaults to disabled).\n * All your devices must be pre-configured to match.\n */\n useMessageIds?: boolean;\n }\n export interface OpenTcpOptions {\n /**\n * Enable use of message IDs (defaults to disabled).\n * All your devices must be pre-configured to match.\n */\n useMessageIds?: boolean;\n }\n export interface GenericCommandOptions {\n /**\n * Number of seconds to wait for a response from the device. 0 or negative defaults to 0.5s.\n */\n timeout?: number;\n /**\n * Controls whether to throw an exception when the device rejects the command.\n */\n checkErrors?: boolean;\n }\n export interface GenericCommandMultiResponseOptions {\n /**\n * Number of seconds to wait for all responses from the device chain. 0 or negative defaults to 0.5s.\n */\n timeout?: number;\n /**\n * Controls whether to throw an exception when any device rejects the command.\n */\n checkErrors?: boolean;\n }\n export interface DetectDevicesOptions {\n /**\n * Determines whether device identification should be performed as well.\n */\n identifyDevices?: boolean;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wasm-exec.d.ts","sourceRoot":"","sources":["../../../src/gateway/wasm-exec.js"],"names":[],"mappings":"AAYkB,
|
|
1
|
+
{"version":3,"file":"wasm-exec.d.ts","sourceRoot":"","sources":["../../../src/gateway/wasm-exec.js"],"names":[],"mappings":"AAYkB,iCA0iBjB"}
|
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
/*
|
|
2
2
|
IMPORTANT
|
|
3
|
-
This file was copied from `https://github.com/golang/go/blob/
|
|
3
|
+
This file was copied from `https://github.com/golang/go/blob/go1.23.0/misc/wasm/wasm_exec.js`.
|
|
4
4
|
It has been modified a bit to reduce webpack warnings about how the `require()` function is being used
|
|
5
5
|
*/
|
|
6
6
|
// Copyright 2018 The Go Authors. All rights reserved.
|
|
7
7
|
// Use of this source code is governed by a BSD-style
|
|
8
8
|
// license that can be found in the LICENSE file.
|
|
9
|
-
|
|
9
|
+
'use strict';
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
const wasmExec = (() => {
|
|
12
12
|
const enosys = () => {
|
|
13
|
-
const err = new Error(
|
|
14
|
-
err.code =
|
|
13
|
+
const err = new Error('not implemented');
|
|
14
|
+
err.code = 'ENOSYS';
|
|
15
15
|
return err;
|
|
16
16
|
};
|
|
17
17
|
if (!globalThis.fs) {
|
|
18
|
-
let outputBuf =
|
|
18
|
+
let outputBuf = '';
|
|
19
19
|
globalThis.fs = {
|
|
20
20
|
constants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1 }, // unused
|
|
21
21
|
writeSync(fd, buf) {
|
|
22
22
|
outputBuf += decoder.decode(buf);
|
|
23
|
-
const nl = outputBuf.lastIndexOf(
|
|
23
|
+
const nl = outputBuf.lastIndexOf('\n');
|
|
24
24
|
if (nl != -1) {
|
|
25
|
-
console.log(outputBuf.
|
|
26
|
-
outputBuf = outputBuf.
|
|
25
|
+
console.log(outputBuf.substring(0, nl));
|
|
26
|
+
outputBuf = outputBuf.substring(nl + 1);
|
|
27
27
|
}
|
|
28
28
|
return buf.length;
|
|
29
29
|
},
|
|
@@ -75,29 +75,29 @@ const wasmExec = (() => {
|
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
77
|
if (!globalThis.crypto) {
|
|
78
|
-
throw new Error(
|
|
78
|
+
throw new Error('globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)');
|
|
79
79
|
}
|
|
80
80
|
if (!globalThis.performance) {
|
|
81
|
-
throw new Error(
|
|
81
|
+
throw new Error('globalThis.performance is not available, polyfill required (performance.now only)');
|
|
82
82
|
}
|
|
83
83
|
if (!globalThis.TextEncoder) {
|
|
84
|
-
throw new Error(
|
|
84
|
+
throw new Error('globalThis.TextEncoder is not available, polyfill required');
|
|
85
85
|
}
|
|
86
86
|
if (!globalThis.TextDecoder) {
|
|
87
|
-
throw new Error(
|
|
87
|
+
throw new Error('globalThis.TextDecoder is not available, polyfill required');
|
|
88
88
|
}
|
|
89
|
-
const encoder = new TextEncoder(
|
|
90
|
-
const decoder = new TextDecoder(
|
|
89
|
+
const encoder = new TextEncoder('utf-8');
|
|
90
|
+
const decoder = new TextDecoder('utf-8');
|
|
91
91
|
globalThis.Go = class {
|
|
92
92
|
constructor() {
|
|
93
|
-
this.argv = [
|
|
93
|
+
this.argv = ['js'];
|
|
94
94
|
this.env = {};
|
|
95
|
-
this.exit =
|
|
95
|
+
this.exit = code => {
|
|
96
96
|
if (code !== 0) {
|
|
97
|
-
console.warn(
|
|
97
|
+
console.warn('exit code:', code);
|
|
98
98
|
}
|
|
99
99
|
};
|
|
100
|
-
this._exitPromise = new Promise(
|
|
100
|
+
this._exitPromise = new Promise(resolve => {
|
|
101
101
|
this._resolveExitPromise = resolve;
|
|
102
102
|
});
|
|
103
103
|
this._pendingEvent = null;
|
|
@@ -107,12 +107,15 @@ const wasmExec = (() => {
|
|
|
107
107
|
this.mem.setUint32(addr + 0, v, true);
|
|
108
108
|
this.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true);
|
|
109
109
|
};
|
|
110
|
-
const
|
|
110
|
+
const setInt32 = (addr, v) => {
|
|
111
|
+
this.mem.setUint32(addr + 0, v, true);
|
|
112
|
+
};
|
|
113
|
+
const getInt64 = addr => {
|
|
111
114
|
const low = this.mem.getUint32(addr + 0, true);
|
|
112
115
|
const high = this.mem.getInt32(addr + 4, true);
|
|
113
116
|
return low + high * 4294967296;
|
|
114
117
|
};
|
|
115
|
-
const loadValue =
|
|
118
|
+
const loadValue = addr => {
|
|
116
119
|
const f = this.mem.getFloat64(addr, true);
|
|
117
120
|
if (f === 0) {
|
|
118
121
|
return undefined;
|
|
@@ -125,7 +128,7 @@ const wasmExec = (() => {
|
|
|
125
128
|
};
|
|
126
129
|
const storeValue = (addr, v) => {
|
|
127
130
|
const nanHead = 0x7FF80000;
|
|
128
|
-
if (typeof v ===
|
|
131
|
+
if (typeof v === 'number' && v !== 0) {
|
|
129
132
|
if (isNaN(v)) {
|
|
130
133
|
this.mem.setUint32(addr + 4, nanHead, true);
|
|
131
134
|
this.mem.setUint32(addr, 0, true);
|
|
@@ -151,30 +154,30 @@ const wasmExec = (() => {
|
|
|
151
154
|
this._goRefCounts[id]++;
|
|
152
155
|
let typeFlag = 0;
|
|
153
156
|
switch (typeof v) {
|
|
154
|
-
case
|
|
157
|
+
case 'object':
|
|
155
158
|
if (v !== null) {
|
|
156
159
|
typeFlag = 1;
|
|
157
160
|
}
|
|
158
161
|
break;
|
|
159
|
-
case
|
|
162
|
+
case 'string':
|
|
160
163
|
typeFlag = 2;
|
|
161
164
|
break;
|
|
162
|
-
case
|
|
165
|
+
case 'symbol':
|
|
163
166
|
typeFlag = 3;
|
|
164
167
|
break;
|
|
165
|
-
case
|
|
168
|
+
case 'function':
|
|
166
169
|
typeFlag = 4;
|
|
167
170
|
break;
|
|
168
171
|
}
|
|
169
172
|
this.mem.setUint32(addr + 4, nanHead | typeFlag, true);
|
|
170
173
|
this.mem.setUint32(addr, id, true);
|
|
171
174
|
};
|
|
172
|
-
const loadSlice =
|
|
175
|
+
const loadSlice = addr => {
|
|
173
176
|
const array = getInt64(addr + 0);
|
|
174
177
|
const len = getInt64(addr + 8);
|
|
175
178
|
return new Uint8Array(this._inst.exports.mem.buffer, array, len);
|
|
176
179
|
};
|
|
177
|
-
const loadSliceOfValues =
|
|
180
|
+
const loadSliceOfValues = addr => {
|
|
178
181
|
const array = getInt64(addr + 0);
|
|
179
182
|
const len = getInt64(addr + 8);
|
|
180
183
|
const a = new Array(len);
|
|
@@ -183,20 +186,23 @@ const wasmExec = (() => {
|
|
|
183
186
|
}
|
|
184
187
|
return a;
|
|
185
188
|
};
|
|
186
|
-
const loadString =
|
|
189
|
+
const loadString = addr => {
|
|
187
190
|
const saddr = getInt64(addr + 0);
|
|
188
191
|
const len = getInt64(addr + 8);
|
|
189
192
|
return decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));
|
|
190
193
|
};
|
|
191
194
|
const timeOrigin = Date.now() - performance.now();
|
|
192
195
|
this.importObject = {
|
|
193
|
-
|
|
196
|
+
_gotest: {
|
|
197
|
+
add: (a, b) => a + b,
|
|
198
|
+
},
|
|
199
|
+
gojs: {
|
|
194
200
|
// Go's SP does not change as long as no Go code is running. Some operations (e.g. calls, getters and setters)
|
|
195
201
|
// may synchronously trigger a Go event handler. This makes Go code get executed in the middle of the imported
|
|
196
202
|
// function. A goroutine can switch to a new stack if the current stack is too small (see morestack function).
|
|
197
203
|
// This changes the SP, thus we have to update the SP used by the imported function.
|
|
198
204
|
// func wasmExit(code int32)
|
|
199
|
-
|
|
205
|
+
'runtime.wasmExit': sp => {
|
|
200
206
|
sp >>>= 0;
|
|
201
207
|
const code = this.mem.getInt32(sp + 8, true);
|
|
202
208
|
this.exited = true;
|
|
@@ -208,7 +214,7 @@ const wasmExec = (() => {
|
|
|
208
214
|
this.exit(code);
|
|
209
215
|
},
|
|
210
216
|
// func wasmWrite(fd uintptr, p unsafe.Pointer, n int32)
|
|
211
|
-
|
|
217
|
+
'runtime.wasmWrite': sp => {
|
|
212
218
|
sp >>>= 0;
|
|
213
219
|
const fd = getInt64(sp + 8);
|
|
214
220
|
const p = getInt64(sp + 16);
|
|
@@ -216,24 +222,24 @@ const wasmExec = (() => {
|
|
|
216
222
|
fs.writeSync(fd, new Uint8Array(this._inst.exports.mem.buffer, p, n));
|
|
217
223
|
},
|
|
218
224
|
// func resetMemoryDataView()
|
|
219
|
-
|
|
225
|
+
'runtime.resetMemoryDataView': sp => {
|
|
220
226
|
sp >>>= 0;
|
|
221
227
|
this.mem = new DataView(this._inst.exports.mem.buffer);
|
|
222
228
|
},
|
|
223
229
|
// func nanotime1() int64
|
|
224
|
-
|
|
230
|
+
'runtime.nanotime1': sp => {
|
|
225
231
|
sp >>>= 0;
|
|
226
232
|
setInt64(sp + 8, (timeOrigin + performance.now()) * 1000000);
|
|
227
233
|
},
|
|
228
234
|
// func walltime() (sec int64, nsec int32)
|
|
229
|
-
|
|
235
|
+
'runtime.walltime': sp => {
|
|
230
236
|
sp >>>= 0;
|
|
231
237
|
const msec = (new Date).getTime();
|
|
232
238
|
setInt64(sp + 8, msec / 1000);
|
|
233
239
|
this.mem.setInt32(sp + 16, (msec % 1000) * 1000000, true);
|
|
234
240
|
},
|
|
235
241
|
// func scheduleTimeoutEvent(delay int64) int32
|
|
236
|
-
|
|
242
|
+
'runtime.scheduleTimeoutEvent': sp => {
|
|
237
243
|
sp >>>= 0;
|
|
238
244
|
const id = this._nextCallbackTimeoutID;
|
|
239
245
|
this._nextCallbackTimeoutID++;
|
|
@@ -242,26 +248,26 @@ const wasmExec = (() => {
|
|
|
242
248
|
while (this._scheduledTimeouts.has(id)) {
|
|
243
249
|
// for some reason Go failed to register the timeout event, log and try again
|
|
244
250
|
// (temporary workaround for https://github.com/golang/go/issues/28975)
|
|
245
|
-
console.warn(
|
|
251
|
+
console.warn('scheduleTimeoutEvent: missed timeout event');
|
|
246
252
|
this._resume();
|
|
247
253
|
}
|
|
248
|
-
}, getInt64(sp + 8)
|
|
254
|
+
}, getInt64(sp + 8)));
|
|
249
255
|
this.mem.setInt32(sp + 16, id, true);
|
|
250
256
|
},
|
|
251
257
|
// func clearTimeoutEvent(id int32)
|
|
252
|
-
|
|
258
|
+
'runtime.clearTimeoutEvent': sp => {
|
|
253
259
|
sp >>>= 0;
|
|
254
260
|
const id = this.mem.getInt32(sp + 8, true);
|
|
255
261
|
clearTimeout(this._scheduledTimeouts.get(id));
|
|
256
262
|
this._scheduledTimeouts.delete(id);
|
|
257
263
|
},
|
|
258
264
|
// func getRandomData(r []byte)
|
|
259
|
-
|
|
265
|
+
'runtime.getRandomData': sp => {
|
|
260
266
|
sp >>>= 0;
|
|
261
267
|
crypto.getRandomValues(loadSlice(sp + 8));
|
|
262
268
|
},
|
|
263
269
|
// func finalizeRef(v ref)
|
|
264
|
-
|
|
270
|
+
'syscall/js.finalizeRef': sp => {
|
|
265
271
|
sp >>>= 0;
|
|
266
272
|
const id = this.mem.getUint32(sp + 8, true);
|
|
267
273
|
this._goRefCounts[id]--;
|
|
@@ -273,39 +279,39 @@ const wasmExec = (() => {
|
|
|
273
279
|
}
|
|
274
280
|
},
|
|
275
281
|
// func stringVal(value string) ref
|
|
276
|
-
|
|
282
|
+
'syscall/js.stringVal': sp => {
|
|
277
283
|
sp >>>= 0;
|
|
278
284
|
storeValue(sp + 24, loadString(sp + 8));
|
|
279
285
|
},
|
|
280
286
|
// func valueGet(v ref, p string) ref
|
|
281
|
-
|
|
287
|
+
'syscall/js.valueGet': sp => {
|
|
282
288
|
sp >>>= 0;
|
|
283
289
|
const result = Reflect.get(loadValue(sp + 8), loadString(sp + 16));
|
|
284
290
|
sp = this._inst.exports.getsp() >>> 0; // see comment above
|
|
285
291
|
storeValue(sp + 32, result);
|
|
286
292
|
},
|
|
287
293
|
// func valueSet(v ref, p string, x ref)
|
|
288
|
-
|
|
294
|
+
'syscall/js.valueSet': sp => {
|
|
289
295
|
sp >>>= 0;
|
|
290
296
|
Reflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32));
|
|
291
297
|
},
|
|
292
298
|
// func valueDelete(v ref, p string)
|
|
293
|
-
|
|
299
|
+
'syscall/js.valueDelete': sp => {
|
|
294
300
|
sp >>>= 0;
|
|
295
301
|
Reflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));
|
|
296
302
|
},
|
|
297
303
|
// func valueIndex(v ref, i int) ref
|
|
298
|
-
|
|
304
|
+
'syscall/js.valueIndex': sp => {
|
|
299
305
|
sp >>>= 0;
|
|
300
306
|
storeValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16)));
|
|
301
307
|
},
|
|
302
308
|
// valueSetIndex(v ref, i int, x ref)
|
|
303
|
-
|
|
309
|
+
'syscall/js.valueSetIndex': sp => {
|
|
304
310
|
sp >>>= 0;
|
|
305
311
|
Reflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24));
|
|
306
312
|
},
|
|
307
313
|
// func valueCall(v ref, m string, args []ref) (ref, bool)
|
|
308
|
-
|
|
314
|
+
'syscall/js.valueCall': sp => {
|
|
309
315
|
sp >>>= 0;
|
|
310
316
|
try {
|
|
311
317
|
const v = loadValue(sp + 8);
|
|
@@ -323,7 +329,7 @@ const wasmExec = (() => {
|
|
|
323
329
|
}
|
|
324
330
|
},
|
|
325
331
|
// func valueInvoke(v ref, args []ref) (ref, bool)
|
|
326
|
-
|
|
332
|
+
'syscall/js.valueInvoke': sp => {
|
|
327
333
|
sp >>>= 0;
|
|
328
334
|
try {
|
|
329
335
|
const v = loadValue(sp + 8);
|
|
@@ -340,7 +346,7 @@ const wasmExec = (() => {
|
|
|
340
346
|
}
|
|
341
347
|
},
|
|
342
348
|
// func valueNew(v ref, args []ref) (ref, bool)
|
|
343
|
-
|
|
349
|
+
'syscall/js.valueNew': sp => {
|
|
344
350
|
sp >>>= 0;
|
|
345
351
|
try {
|
|
346
352
|
const v = loadValue(sp + 8);
|
|
@@ -357,30 +363,30 @@ const wasmExec = (() => {
|
|
|
357
363
|
}
|
|
358
364
|
},
|
|
359
365
|
// func valueLength(v ref) int
|
|
360
|
-
|
|
366
|
+
'syscall/js.valueLength': sp => {
|
|
361
367
|
sp >>>= 0;
|
|
362
368
|
setInt64(sp + 16, parseInt(loadValue(sp + 8).length));
|
|
363
369
|
},
|
|
364
370
|
// valuePrepareString(v ref) (ref, int)
|
|
365
|
-
|
|
371
|
+
'syscall/js.valuePrepareString': sp => {
|
|
366
372
|
sp >>>= 0;
|
|
367
373
|
const str = encoder.encode(String(loadValue(sp + 8)));
|
|
368
374
|
storeValue(sp + 16, str);
|
|
369
375
|
setInt64(sp + 24, str.length);
|
|
370
376
|
},
|
|
371
377
|
// valueLoadString(v ref, b []byte)
|
|
372
|
-
|
|
378
|
+
'syscall/js.valueLoadString': sp => {
|
|
373
379
|
sp >>>= 0;
|
|
374
380
|
const str = loadValue(sp + 8);
|
|
375
381
|
loadSlice(sp + 16).set(str);
|
|
376
382
|
},
|
|
377
383
|
// func valueInstanceOf(v ref, t ref) bool
|
|
378
|
-
|
|
384
|
+
'syscall/js.valueInstanceOf': sp => {
|
|
379
385
|
sp >>>= 0;
|
|
380
386
|
this.mem.setUint8(sp + 24, (loadValue(sp + 8) instanceof loadValue(sp + 16)) ? 1 : 0);
|
|
381
387
|
},
|
|
382
388
|
// func copyBytesToGo(dst []byte, src ref) (int, bool)
|
|
383
|
-
|
|
389
|
+
'syscall/js.copyBytesToGo': sp => {
|
|
384
390
|
sp >>>= 0;
|
|
385
391
|
const dst = loadSlice(sp + 8);
|
|
386
392
|
const src = loadValue(sp + 32);
|
|
@@ -394,7 +400,7 @@ const wasmExec = (() => {
|
|
|
394
400
|
this.mem.setUint8(sp + 48, 1);
|
|
395
401
|
},
|
|
396
402
|
// func copyBytesToJS(dst ref, src []byte) (int, bool)
|
|
397
|
-
|
|
403
|
+
'syscall/js.copyBytesToJS': sp => {
|
|
398
404
|
sp >>>= 0;
|
|
399
405
|
const dst = loadValue(sp + 8);
|
|
400
406
|
const src = loadSlice(sp + 16);
|
|
@@ -407,7 +413,7 @@ const wasmExec = (() => {
|
|
|
407
413
|
setInt64(sp + 40, toCopy.length);
|
|
408
414
|
this.mem.setUint8(sp + 48, 1);
|
|
409
415
|
},
|
|
410
|
-
|
|
416
|
+
'debug': value => {
|
|
411
417
|
console.log(value);
|
|
412
418
|
},
|
|
413
419
|
}
|
|
@@ -415,7 +421,7 @@ const wasmExec = (() => {
|
|
|
415
421
|
}
|
|
416
422
|
async run(instance) {
|
|
417
423
|
if (!(instance instanceof WebAssembly.Instance)) {
|
|
418
|
-
throw new Error(
|
|
424
|
+
throw new Error('Go.run: WebAssembly.Instance expected');
|
|
419
425
|
}
|
|
420
426
|
this._inst = instance;
|
|
421
427
|
this.mem = new DataView(this._inst.exports.mem.buffer);
|
|
@@ -441,9 +447,9 @@ const wasmExec = (() => {
|
|
|
441
447
|
this.exited = false; // whether the Go program has exited
|
|
442
448
|
// Pass command line arguments and environment variables to WebAssembly by writing them to the linear memory.
|
|
443
449
|
let offset = 4096;
|
|
444
|
-
const strPtr =
|
|
450
|
+
const strPtr = str => {
|
|
445
451
|
const ptr = offset;
|
|
446
|
-
const bytes = encoder.encode(str
|
|
452
|
+
const bytes = encoder.encode(`${str}\0`);
|
|
447
453
|
new Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);
|
|
448
454
|
offset += bytes.length;
|
|
449
455
|
if (offset % 8 !== 0) {
|
|
@@ -453,17 +459,17 @@ const wasmExec = (() => {
|
|
|
453
459
|
};
|
|
454
460
|
const argc = this.argv.length;
|
|
455
461
|
const argvPtrs = [];
|
|
456
|
-
this.argv.forEach(
|
|
462
|
+
this.argv.forEach(arg => {
|
|
457
463
|
argvPtrs.push(strPtr(arg));
|
|
458
464
|
});
|
|
459
465
|
argvPtrs.push(0);
|
|
460
466
|
const keys = Object.keys(this.env).sort();
|
|
461
|
-
keys.forEach(
|
|
467
|
+
keys.forEach(key => {
|
|
462
468
|
argvPtrs.push(strPtr(`${key}=${this.env[key]}`));
|
|
463
469
|
});
|
|
464
470
|
argvPtrs.push(0);
|
|
465
471
|
const argv = offset;
|
|
466
|
-
argvPtrs.forEach(
|
|
472
|
+
argvPtrs.forEach(ptr => {
|
|
467
473
|
this.mem.setUint32(offset, ptr, true);
|
|
468
474
|
this.mem.setUint32(offset + 4, 0, true);
|
|
469
475
|
offset += 8;
|
|
@@ -472,7 +478,7 @@ const wasmExec = (() => {
|
|
|
472
478
|
// Keep in sync with cmd/link/internal/ld/data.go:wasmMinDataAddr.
|
|
473
479
|
const wasmMinDataAddr = 4096 + 8192;
|
|
474
480
|
if (offset >= wasmMinDataAddr) {
|
|
475
|
-
throw new Error(
|
|
481
|
+
throw new Error('total length of command line and environment variables exceeds limit');
|
|
476
482
|
}
|
|
477
483
|
this._inst.exports.run(argc, argv);
|
|
478
484
|
if (this.exited) {
|
|
@@ -482,7 +488,7 @@ const wasmExec = (() => {
|
|
|
482
488
|
}
|
|
483
489
|
_resume() {
|
|
484
490
|
if (this.exited) {
|
|
485
|
-
throw new Error(
|
|
491
|
+
throw new Error('Go program has already exited');
|
|
486
492
|
}
|
|
487
493
|
this._inst.exports.resume();
|
|
488
494
|
if (this.exited) {
|