@openrfid/hopeland-discovery 0.1.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/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 RFID Software India Private Limited - https://rfidsoftwares.com
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ For RFID developer resources, documentation, hardware integrations, and enterprise software solutions, visit https://rfidsoftwares.com
@@ -0,0 +1,42 @@
1
+ import { IPlugin, PluginMetadata, PluginContext } from '@openrfid/plugin-api';
2
+
3
+ /**
4
+ * OpenRFID Simulator - The Open Source RFID Reader Simulator for Developers.
5
+ * Copyright (c) 2026 RFID Software India Private Limited - https://rfidsoftwares.com
6
+ *
7
+ * Licensed under the MIT License.
8
+ *
9
+ * Hopeland/Identium UDP Multicast Discovery Announcer
10
+ * =====================================================
11
+ * This plugin makes the OpenRFID Simulator behave like a real Hopeland/Identium
12
+ * RFID reader on the local network. It implements the exact discovery protocol
13
+ * used by the Hopeland MyReaderAPI SDK:
14
+ *
15
+ * - UDP Multicast group: 230.1.1.116 (hardcoded in the SDK)
16
+ * - UDP Port: 9091 (hardcoded in the SDK)
17
+ * - Message format (ASCII):
18
+ * ^RFID_READER_INFORMATION:<type>,IP:<ip>,MAC:<mac>,PORT:<port>,
19
+ * HOST_SERVER_IP:0.0.0.0,HOST_SERVER_PORT:0,MODE:SERVER,NET_STATE:CONNECTED$
20
+ *
21
+ * The SDK's DeviceSearch class joins this multicast group, listens for these
22
+ * packets, and parses them into Device_Mode objects shown in the search dialog.
23
+ * Any middleware using MyReaderAPI (unmodified) will discover the simulator
24
+ * automatically.
25
+ *
26
+ * Also opens a TCP server on port 9090 so that CreateTcpConn() succeeds
27
+ * (Hopeland binary protocol — full implementation pending Wireshark capture).
28
+ */
29
+
30
+ declare class HopelandDiscoveryPlugin implements IPlugin {
31
+ private udpSocket;
32
+ private tcpServer;
33
+ private announceTimer;
34
+ private context;
35
+ getMetadata(): PluginMetadata;
36
+ initialize(context: PluginContext): Promise<void>;
37
+ start(): Promise<void>;
38
+ stop(): Promise<void>;
39
+ dispose(): Promise<void>;
40
+ }
41
+
42
+ export { HopelandDiscoveryPlugin };
@@ -0,0 +1,42 @@
1
+ import { IPlugin, PluginMetadata, PluginContext } from '@openrfid/plugin-api';
2
+
3
+ /**
4
+ * OpenRFID Simulator - The Open Source RFID Reader Simulator for Developers.
5
+ * Copyright (c) 2026 RFID Software India Private Limited - https://rfidsoftwares.com
6
+ *
7
+ * Licensed under the MIT License.
8
+ *
9
+ * Hopeland/Identium UDP Multicast Discovery Announcer
10
+ * =====================================================
11
+ * This plugin makes the OpenRFID Simulator behave like a real Hopeland/Identium
12
+ * RFID reader on the local network. It implements the exact discovery protocol
13
+ * used by the Hopeland MyReaderAPI SDK:
14
+ *
15
+ * - UDP Multicast group: 230.1.1.116 (hardcoded in the SDK)
16
+ * - UDP Port: 9091 (hardcoded in the SDK)
17
+ * - Message format (ASCII):
18
+ * ^RFID_READER_INFORMATION:<type>,IP:<ip>,MAC:<mac>,PORT:<port>,
19
+ * HOST_SERVER_IP:0.0.0.0,HOST_SERVER_PORT:0,MODE:SERVER,NET_STATE:CONNECTED$
20
+ *
21
+ * The SDK's DeviceSearch class joins this multicast group, listens for these
22
+ * packets, and parses them into Device_Mode objects shown in the search dialog.
23
+ * Any middleware using MyReaderAPI (unmodified) will discover the simulator
24
+ * automatically.
25
+ *
26
+ * Also opens a TCP server on port 9090 so that CreateTcpConn() succeeds
27
+ * (Hopeland binary protocol — full implementation pending Wireshark capture).
28
+ */
29
+
30
+ declare class HopelandDiscoveryPlugin implements IPlugin {
31
+ private udpSocket;
32
+ private tcpServer;
33
+ private announceTimer;
34
+ private context;
35
+ getMetadata(): PluginMetadata;
36
+ initialize(context: PluginContext): Promise<void>;
37
+ start(): Promise<void>;
38
+ stop(): Promise<void>;
39
+ dispose(): Promise<void>;
40
+ }
41
+
42
+ export { HopelandDiscoveryPlugin };
package/dist/index.js ADDED
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ HopelandDiscoveryPlugin: () => HopelandDiscoveryPlugin
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+
37
+ // src/hopeland-discovery-plugin.ts
38
+ var dgram = __toESM(require("dgram"));
39
+ var net = __toESM(require("net"));
40
+ var os = __toESM(require("os"));
41
+ var MULTICAST_GROUP = "230.1.1.116";
42
+ var MULTICAST_PORT = 9091;
43
+ var TCP_PORT = 9090;
44
+ var ANNOUNCE_INTERVAL_MS = 2e3;
45
+ function getLocalIpv4() {
46
+ const interfaces = os.networkInterfaces();
47
+ const allIfaces = Array.from(Object.values(interfaces));
48
+ for (const iface of allIfaces) {
49
+ if (!iface) continue;
50
+ for (const entry of iface) {
51
+ if (entry.family === "IPv4" && !entry.internal) {
52
+ return entry.address;
53
+ }
54
+ }
55
+ }
56
+ return "127.0.0.1";
57
+ }
58
+ function buildFakeMac() {
59
+ const hostname2 = os.hostname();
60
+ let hash = 0;
61
+ for (let i = 0; i < hostname2.length; i++) {
62
+ hash = (hash << 5) - hash + hostname2.charCodeAt(i);
63
+ hash |= 0;
64
+ }
65
+ const hex = (Math.abs(hash) + 1048576).toString(16).padStart(8, "0");
66
+ return `52-46-${hex.slice(0, 2)}-${hex.slice(2, 4)}-${hex.slice(4, 6)}-${hex.slice(6, 8)}`.toUpperCase();
67
+ }
68
+ function buildAnnouncementPacket(localIp, mac) {
69
+ const msg = `^RFID_READER_INFORMATION:OpenRFID-Sim,IP:${localIp},MAC:${mac},PORT:${TCP_PORT},HOST_SERVER_IP:0.0.0.0,HOST_SERVER_PORT:0,MODE:SERVER,NET_STATE:CONNECTED$`;
70
+ return Buffer.from(msg, "ascii");
71
+ }
72
+ var HopelandDiscoveryPlugin = class {
73
+ udpSocket = null;
74
+ tcpServer = null;
75
+ announceTimer = null;
76
+ context = null;
77
+ getMetadata() {
78
+ return {
79
+ name: "hopeland-discovery",
80
+ version: "0.1.0",
81
+ description: `Hopeland/Identium UDP multicast device discovery announcer. Makes the simulator visible as a real RFID reader on the local network (multicast ${MULTICAST_GROUP}:${MULTICAST_PORT}, TCP ${TCP_PORT}).`
82
+ };
83
+ }
84
+ async initialize(context) {
85
+ this.context = context;
86
+ }
87
+ async start() {
88
+ const localIp = getLocalIpv4();
89
+ const fakeMac = buildFakeMac();
90
+ const packet = buildAnnouncementPacket(localIp, fakeMac);
91
+ this.context?.logger.info(
92
+ `[HopelandDiscovery] Local IP: ${localIp} Fake MAC: ${fakeMac}`
93
+ );
94
+ this.udpSocket = dgram.createSocket({ type: "udp4", reuseAddr: true });
95
+ this.udpSocket.on("error", (err) => {
96
+ this.context?.logger.error("[HopelandDiscovery] UDP socket error", err);
97
+ });
98
+ await new Promise((resolve, reject) => {
99
+ this.udpSocket.bind(0, () => {
100
+ try {
101
+ this.udpSocket.setMulticastTTL(16);
102
+ this.udpSocket.setMulticastLoopback(true);
103
+ resolve();
104
+ } catch (e) {
105
+ reject(e);
106
+ }
107
+ });
108
+ });
109
+ const sendAnnouncement = () => {
110
+ this.udpSocket?.send(
111
+ packet,
112
+ 0,
113
+ packet.length,
114
+ MULTICAST_PORT,
115
+ MULTICAST_GROUP,
116
+ (err) => {
117
+ if (err) this.context?.logger.error("[HopelandDiscovery] UDP send error", err);
118
+ }
119
+ );
120
+ };
121
+ sendAnnouncement();
122
+ this.announceTimer = setInterval(sendAnnouncement, ANNOUNCE_INTERVAL_MS);
123
+ this.context?.logger.info(
124
+ `[HopelandDiscovery] Announcing on UDP multicast ${MULTICAST_GROUP}:${MULTICAST_PORT} every ${ANNOUNCE_INTERVAL_MS}ms`
125
+ );
126
+ this.tcpServer = net.createServer((socket) => {
127
+ const remote = `${socket.remoteAddress}:${socket.remotePort}`;
128
+ this.context?.logger.info(`[HopelandDiscovery] TCP connection from ${remote}`);
129
+ socket.on("error", (err) => {
130
+ this.context?.logger.error(`[HopelandDiscovery] TCP socket error from ${remote}`, err);
131
+ });
132
+ socket.on("close", () => {
133
+ this.context?.logger.info(`[HopelandDiscovery] TCP connection closed: ${remote}`);
134
+ });
135
+ socket.on("data", (_data) => {
136
+ });
137
+ });
138
+ this.tcpServer.on("error", (err) => {
139
+ if (err.code === "EADDRINUSE") {
140
+ this.context?.logger.error(
141
+ `[HopelandDiscovery] TCP port ${TCP_PORT} already in use. Is another reader application running?`
142
+ );
143
+ } else {
144
+ this.context?.logger.error("[HopelandDiscovery] TCP server error", err);
145
+ }
146
+ });
147
+ await new Promise((resolve) => {
148
+ this.tcpServer.listen(TCP_PORT, "0.0.0.0", () => {
149
+ this.context?.logger.info(
150
+ `[HopelandDiscovery] TCP server listening on 0.0.0.0:${TCP_PORT} \u2014 middleware can now connect`
151
+ );
152
+ resolve();
153
+ });
154
+ });
155
+ }
156
+ async stop() {
157
+ if (this.announceTimer) {
158
+ clearInterval(this.announceTimer);
159
+ this.announceTimer = null;
160
+ }
161
+ if (this.udpSocket) {
162
+ this.udpSocket.close();
163
+ this.udpSocket = null;
164
+ }
165
+ await new Promise((resolve) => {
166
+ if (this.tcpServer) {
167
+ this.tcpServer.close(() => resolve());
168
+ this.tcpServer = null;
169
+ } else {
170
+ resolve();
171
+ }
172
+ });
173
+ this.context?.logger.info("[HopelandDiscovery] Stopped.");
174
+ }
175
+ async dispose() {
176
+ await this.stop();
177
+ }
178
+ };
179
+ // Annotate the CommonJS export names for ESM import in node:
180
+ 0 && (module.exports = {
181
+ HopelandDiscoveryPlugin
182
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,145 @@
1
+ // src/hopeland-discovery-plugin.ts
2
+ import * as dgram from "dgram";
3
+ import * as net from "net";
4
+ import * as os from "os";
5
+ var MULTICAST_GROUP = "230.1.1.116";
6
+ var MULTICAST_PORT = 9091;
7
+ var TCP_PORT = 9090;
8
+ var ANNOUNCE_INTERVAL_MS = 2e3;
9
+ function getLocalIpv4() {
10
+ const interfaces = os.networkInterfaces();
11
+ const allIfaces = Array.from(Object.values(interfaces));
12
+ for (const iface of allIfaces) {
13
+ if (!iface) continue;
14
+ for (const entry of iface) {
15
+ if (entry.family === "IPv4" && !entry.internal) {
16
+ return entry.address;
17
+ }
18
+ }
19
+ }
20
+ return "127.0.0.1";
21
+ }
22
+ function buildFakeMac() {
23
+ const hostname2 = os.hostname();
24
+ let hash = 0;
25
+ for (let i = 0; i < hostname2.length; i++) {
26
+ hash = (hash << 5) - hash + hostname2.charCodeAt(i);
27
+ hash |= 0;
28
+ }
29
+ const hex = (Math.abs(hash) + 1048576).toString(16).padStart(8, "0");
30
+ return `52-46-${hex.slice(0, 2)}-${hex.slice(2, 4)}-${hex.slice(4, 6)}-${hex.slice(6, 8)}`.toUpperCase();
31
+ }
32
+ function buildAnnouncementPacket(localIp, mac) {
33
+ const msg = `^RFID_READER_INFORMATION:OpenRFID-Sim,IP:${localIp},MAC:${mac},PORT:${TCP_PORT},HOST_SERVER_IP:0.0.0.0,HOST_SERVER_PORT:0,MODE:SERVER,NET_STATE:CONNECTED$`;
34
+ return Buffer.from(msg, "ascii");
35
+ }
36
+ var HopelandDiscoveryPlugin = class {
37
+ udpSocket = null;
38
+ tcpServer = null;
39
+ announceTimer = null;
40
+ context = null;
41
+ getMetadata() {
42
+ return {
43
+ name: "hopeland-discovery",
44
+ version: "0.1.0",
45
+ description: `Hopeland/Identium UDP multicast device discovery announcer. Makes the simulator visible as a real RFID reader on the local network (multicast ${MULTICAST_GROUP}:${MULTICAST_PORT}, TCP ${TCP_PORT}).`
46
+ };
47
+ }
48
+ async initialize(context) {
49
+ this.context = context;
50
+ }
51
+ async start() {
52
+ const localIp = getLocalIpv4();
53
+ const fakeMac = buildFakeMac();
54
+ const packet = buildAnnouncementPacket(localIp, fakeMac);
55
+ this.context?.logger.info(
56
+ `[HopelandDiscovery] Local IP: ${localIp} Fake MAC: ${fakeMac}`
57
+ );
58
+ this.udpSocket = dgram.createSocket({ type: "udp4", reuseAddr: true });
59
+ this.udpSocket.on("error", (err) => {
60
+ this.context?.logger.error("[HopelandDiscovery] UDP socket error", err);
61
+ });
62
+ await new Promise((resolve, reject) => {
63
+ this.udpSocket.bind(0, () => {
64
+ try {
65
+ this.udpSocket.setMulticastTTL(16);
66
+ this.udpSocket.setMulticastLoopback(true);
67
+ resolve();
68
+ } catch (e) {
69
+ reject(e);
70
+ }
71
+ });
72
+ });
73
+ const sendAnnouncement = () => {
74
+ this.udpSocket?.send(
75
+ packet,
76
+ 0,
77
+ packet.length,
78
+ MULTICAST_PORT,
79
+ MULTICAST_GROUP,
80
+ (err) => {
81
+ if (err) this.context?.logger.error("[HopelandDiscovery] UDP send error", err);
82
+ }
83
+ );
84
+ };
85
+ sendAnnouncement();
86
+ this.announceTimer = setInterval(sendAnnouncement, ANNOUNCE_INTERVAL_MS);
87
+ this.context?.logger.info(
88
+ `[HopelandDiscovery] Announcing on UDP multicast ${MULTICAST_GROUP}:${MULTICAST_PORT} every ${ANNOUNCE_INTERVAL_MS}ms`
89
+ );
90
+ this.tcpServer = net.createServer((socket) => {
91
+ const remote = `${socket.remoteAddress}:${socket.remotePort}`;
92
+ this.context?.logger.info(`[HopelandDiscovery] TCP connection from ${remote}`);
93
+ socket.on("error", (err) => {
94
+ this.context?.logger.error(`[HopelandDiscovery] TCP socket error from ${remote}`, err);
95
+ });
96
+ socket.on("close", () => {
97
+ this.context?.logger.info(`[HopelandDiscovery] TCP connection closed: ${remote}`);
98
+ });
99
+ socket.on("data", (_data) => {
100
+ });
101
+ });
102
+ this.tcpServer.on("error", (err) => {
103
+ if (err.code === "EADDRINUSE") {
104
+ this.context?.logger.error(
105
+ `[HopelandDiscovery] TCP port ${TCP_PORT} already in use. Is another reader application running?`
106
+ );
107
+ } else {
108
+ this.context?.logger.error("[HopelandDiscovery] TCP server error", err);
109
+ }
110
+ });
111
+ await new Promise((resolve) => {
112
+ this.tcpServer.listen(TCP_PORT, "0.0.0.0", () => {
113
+ this.context?.logger.info(
114
+ `[HopelandDiscovery] TCP server listening on 0.0.0.0:${TCP_PORT} \u2014 middleware can now connect`
115
+ );
116
+ resolve();
117
+ });
118
+ });
119
+ }
120
+ async stop() {
121
+ if (this.announceTimer) {
122
+ clearInterval(this.announceTimer);
123
+ this.announceTimer = null;
124
+ }
125
+ if (this.udpSocket) {
126
+ this.udpSocket.close();
127
+ this.udpSocket = null;
128
+ }
129
+ await new Promise((resolve) => {
130
+ if (this.tcpServer) {
131
+ this.tcpServer.close(() => resolve());
132
+ this.tcpServer = null;
133
+ } else {
134
+ resolve();
135
+ }
136
+ });
137
+ this.context?.logger.info("[HopelandDiscovery] Stopped.");
138
+ }
139
+ async dispose() {
140
+ await this.stop();
141
+ }
142
+ };
143
+ export {
144
+ HopelandDiscoveryPlugin
145
+ };
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@openrfid/hopeland-discovery",
3
+ "version": "0.1.0",
4
+ "description": "Hopeland/Identium UDP multicast device discovery announcer for OpenRFID Simulator. Makes the simulator appear as a real Hopeland RFID reader on the local network.",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "dependencies": {
19
+ "ws": "^8.16.0",
20
+ "@openrfid/plugin-api": "0.1.0",
21
+ "@openrfid/core": "0.1.0"
22
+ },
23
+ "devDependencies": {
24
+ "@types/node": "^20.11.0",
25
+ "tsup": "^8.0.2",
26
+ "typescript": "^5.4.5",
27
+ "vitest": "^1.5.0"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "license": "MIT",
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "https://github.com/rfidsoftwares/openrfid-simulator.git"
36
+ },
37
+ "bugs": {
38
+ "url": "https://github.com/rfidsoftwares/openrfid-simulator/issues"
39
+ },
40
+ "homepage": "https://rfidsoftwares.com",
41
+ "scripts": {
42
+ "build": "tsup src/index.ts --format cjs,esm --dts",
43
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
44
+ "test": "vitest run",
45
+ "typecheck": "tsc --noEmit"
46
+ }
47
+ }