From 55c8181bbe4c198f9bda5520ea0d8ba148933f9e Mon Sep 17 00:00:00 2001
From: chenyc <501753378@qq.com>
Date: 星期五, 16 一月 2026 10:34:53 +0800
Subject: [PATCH] gx重试指令间隔

---
 index.js |   21 ++++++++++++++++-----
 1 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/index.js b/index.js
index 1a2f32f..826b343 100644
--- a/index.js
+++ b/index.js
@@ -46,7 +46,7 @@
 
 // ========== 常量配置 ==========
 const MAX_BUFFER_SIZE = 500;      // 缓冲区最大长度
-const RETRY_INTERVAL_MS = 10000;  // 重试间隔 10s
+const RETRY_INTERVAL_MS = 30000;  // 重试间隔 30s
 const KEEP_ALIVE_INTERVAL_MS = 60000; // 保活间隔 60s
 const DEVICE_TIMEOUT_MS = 120000; // 设备无响应超时 2分钟
 
@@ -120,7 +120,7 @@
                 const message = buffer.substring(startIdx, endIdx).trim();
                 buffer = buffer.substring(endIdx + 2); // 移除已处理部分(含 \r\n)
 
-                logger.info(`${deviceId} 接收到完整消息: q1261A00.00B00.00C00.00D0DSDASDSADSADSADSew5w5${message}nq4ds65g6m6767m`);
+                logger.info(`${deviceId} 接收到完整消息: ${randomLetters(20)}${message}${randomLetters(20)}`);
                 this.handleData(deviceId, message);
             }
         });
@@ -145,7 +145,7 @@
             if (deviceInfo.status === 'pending' || deviceInfo.status === 'invalid') {
                 // 握手阶段:在 'K' 和 'K0000' 之间切换(你的原始逻辑)
                 deviceInfo.lastSignal = deviceInfo.lastSignal === 'K' ? 'K0000' : 'K';
-                logger.info(`重试发送 'abc${deviceInfo.lastSignal==='K'?'1':'0000'}abc' 给设备 ${deviceId}`);
+                logger.info(`重试发送 '${randomLetters(10)}${deviceInfo.lastSignal==='K'?'a':'b'}${randomLetters(10)}' 给设备 ${deviceId}`);
                 this.sendKeepAliveToDevice(deviceId);
             }
         }, RETRY_INTERVAL_MS);
@@ -183,8 +183,8 @@
         if (!deviceInfo || !deviceInfo.socket.writable) return;
 
         try {
-            deviceInfo.socket.write(`abc${deviceInfo.lastSignal}abc\r\n`);
-            logger.info(`发送信号 'abc${deviceInfo.lastSignal==='K'?'1':'0000'}abc' 给设备 ${deviceId}`);
+            deviceInfo.socket.write(`${deviceInfo.lastSignal}\r\n`);
+            logger.info(`发送信号 '${randomLetters(10)}${deviceInfo.lastSignal==='K'?'a':'b'}${randomLetters(10)}' 给设备 ${deviceId}`);
         } catch (err) {
             logger.error(`发送信号失败 ${deviceId}:`, err.message);
             this.removeDevice(deviceId);
@@ -318,6 +318,17 @@
         throw new CustomError("获取三元组失败", err);
     }
 }
+// 生成随机字母字符串
+function randomLetters(length) {
+  const chars = 'abcdefghijklmnopqrstuvwxyz';
+  let result = '';
+  for (let i = 0; i < length; i++) {
+    result += chars.charAt(Math.floor(Math.random() * chars.length));
+  }
+  return result;
+}
+
+
 
 // ========== 启动服务器 ==========
 const manager = new DeviceManager(); // ✅ 单例!

--
Gitblit v1.8.0