Commit 792ac420 authored by martin hou's avatar martin hou

feat: 增加使用conn初始化Jensen实例和增加reconnect方法的实现

parent 3e69499f
...@@ -4,7 +4,7 @@ module.exports = { ...@@ -4,7 +4,7 @@ module.exports = {
printWidth: 140, // 换行长度 printWidth: 140, // 换行长度
semi: true, // 使用分号 semi: true, // 使用分号
singleQuote: true, // 使用单引号 singleQuote: true, // 使用单引号
tabWidth: 2, // tab长度 tabWidth: 4, // tab长度
trailingComma: 'none', // 确保数组末尾没有尾随逗号 trailingComma: 'none', // 确保数组末尾没有尾随逗号
bracketSpacing: true, // 数组括号内的空格(根据需要调整) bracketSpacing: true, // 数组括号内的空格(根据需要调整)
proseWrap: 'never', // 确保不会因文档换行规则影响数组 proseWrap: 'never', // 确保不会因文档换行规则影响数组
......
...@@ -71,9 +71,9 @@ const COMMAND_NAMES = { ...@@ -71,9 +71,9 @@ const COMMAND_NAMES = {
let Logger = null; let Logger = null;
function Jensen(log) { async function Jensen(log, conn) {
Logger = log || internalLogger; Logger = log || internalLogger;
let device = null; let device = conn;
let actions = {}; let actions = {};
let buffer = []; let buffer = [];
let blocks = []; let blocks = [];
...@@ -129,13 +129,9 @@ function Jensen(log) { ...@@ -129,13 +129,9 @@ function Jensen(log) {
await device.selectConfiguration(1); await device.selectConfiguration(1);
await device.claimInterface(0); await device.claimInterface(0);
await device.selectAlternateInterface(0, 0); await device.selectAlternateInterface(0, 0);
self.model = self.model = device.productId == 0xb00c ? 'hidock-h1'
device.productId == 0xb00c : device.productId == 0xb00d ? 'hidock-h1e'
? 'hidock-h1' : device.productId == 0xb00e ? 'hidock-p1'
: device.productId == 0xb00d
? 'hidock-h1e'
: device.productId == 0xb00e
? 'hidock-p1'
: device.productId == 0xb00f ? 'hidock-p1:mini' : 'unknown'; : device.productId == 0xb00f ? 'hidock-p1:mini' : 'unknown';
Logger.info('jensen', 'connect', 'device pid: ' + device.productId); Logger.info('jensen', 'connect', 'device pid: ' + device.productId);
} catch (e) { } catch (e) {
...@@ -153,6 +149,25 @@ function Jensen(log) { ...@@ -153,6 +149,25 @@ function Jensen(log) {
} }
}; };
if (conn)
{
if (!conn.opened) conn.open();
await setup();
}
this.reconnect = async function () {
try
{
if (device && device.opened) device.close();
device.open();
await setup();
}
catch(ex)
{
Logger.error('jensen', 'reconnect', ex);
}
}
this.connect = async function () { this.connect = async function () {
Logger.debug('jensen', 'connect', 'connect'); Logger.debug('jensen', 'connect', 'connect');
let r = await self.tryconnect(); let r = await self.tryconnect();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment