tirecheck-device-sdk 0.2.49 → 0.2.50
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/dist/index.cjs +18 -36
- package/dist/index.mjs +18 -36
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -145,7 +145,7 @@ const bridgeTools = {
|
|
|
145
145
|
convertBytesToStructure(objStructure, payload, fwVersion) {
|
|
146
146
|
let numArray = ___default.clone(payload);
|
|
147
147
|
const keys = Object.keys(objStructure).filter(
|
|
148
|
-
(key) => !objStructure[key].version ||
|
|
148
|
+
(key) => !objStructure[key].version || fwVersion && fwVersion >= objStructure[key].version
|
|
149
149
|
);
|
|
150
150
|
let sumWithInitial = 0;
|
|
151
151
|
for (const key of keys) {
|
|
@@ -169,7 +169,7 @@ const bridgeTools = {
|
|
|
169
169
|
},
|
|
170
170
|
convertStructureToBytes(objStructure, structurizedObj, fwVersion) {
|
|
171
171
|
const keys = Object.keys(objStructure).filter(
|
|
172
|
-
(key) => !objStructure[key].version ||
|
|
172
|
+
(key) => !objStructure[key].version || fwVersion && fwVersion >= objStructure[key].version
|
|
173
173
|
);
|
|
174
174
|
const result = [];
|
|
175
175
|
for (const key of keys) {
|
|
@@ -339,6 +339,13 @@ const bridgeTools = {
|
|
|
339
339
|
getSpareTyres(tcVehicle) {
|
|
340
340
|
const spareTyres = tcVehicle.tcTyres?.filter((tyre) => String(tyre.mountedOn?.positionId).endsWith("0"));
|
|
341
341
|
return spareTyres;
|
|
342
|
+
},
|
|
343
|
+
getBridgeIndexFromPositionId(positionId, centerIndex = 8) {
|
|
344
|
+
const halfPoint = positionId % 10 * 6;
|
|
345
|
+
const tyrePosition = positionId % 100;
|
|
346
|
+
const result = (tyrePosition - halfPoint) / 10 - (tyrePosition <= halfPoint ? 1 : 0);
|
|
347
|
+
const bitIndex = centerIndex + result;
|
|
348
|
+
return bitIndex;
|
|
342
349
|
}
|
|
343
350
|
};
|
|
344
351
|
function getDefaultTyreLabels() {
|
|
@@ -1688,21 +1695,6 @@ const subCommandIds = {
|
|
|
1688
1695
|
/** 0x20 - 0x2F */
|
|
1689
1696
|
idsPerWheel: (axleIndex) => 32 + axleIndex,
|
|
1690
1697
|
/** only for commandIds.sensorMeasurement */
|
|
1691
|
-
sensorMeasurementPerWheel: (axlePosition, tyrePosition, isTwinTyre, isSpareAxle) => {
|
|
1692
|
-
let bridgeTyrePosition = 0;
|
|
1693
|
-
if (isTwinTyre && !isSpareAxle) {
|
|
1694
|
-
if (tyrePosition === 1) bridgeTyrePosition = 6;
|
|
1695
|
-
else if (tyrePosition === 2) bridgeTyrePosition = 7;
|
|
1696
|
-
else if (tyrePosition === 3) bridgeTyrePosition = 9;
|
|
1697
|
-
else if (tyrePosition === 4) bridgeTyrePosition = 10;
|
|
1698
|
-
} else if (!isTwinTyre && !isSpareAxle) {
|
|
1699
|
-
if (tyrePosition === 1) bridgeTyrePosition = 7;
|
|
1700
|
-
else if (tyrePosition === 2) bridgeTyrePosition = 9;
|
|
1701
|
-
} else if (isSpareAxle) {
|
|
1702
|
-
if (tyrePosition === 1) bridgeTyrePosition = 8;
|
|
1703
|
-
}
|
|
1704
|
-
return axlePosition * 16 + bridgeTyrePosition;
|
|
1705
|
-
},
|
|
1706
1698
|
pressurePerAxle: 48,
|
|
1707
1699
|
customerPressureThresholds: 64,
|
|
1708
1700
|
customerTemperatureThresholds: 65,
|
|
@@ -1981,16 +1973,13 @@ const bridgeCommands = {
|
|
|
1981
1973
|
const deviceData = bridgeTools.getBridgeFromStore(deviceId);
|
|
1982
1974
|
const isSpare = String(positionId).endsWith("0");
|
|
1983
1975
|
const positionInfo = bridgeTools.getPositionInfo(positionId);
|
|
1984
|
-
const { axlePosition
|
|
1985
|
-
if (axlePosition == null
|
|
1976
|
+
const { axlePosition } = positionInfo;
|
|
1977
|
+
if (axlePosition == null) {
|
|
1986
1978
|
throw new Error(`Invalid positionId ${positionId}`);
|
|
1987
1979
|
}
|
|
1988
|
-
const
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
subCommandIds.sensorMeasurementPerWheel(axlePosition, tyrePosition, isTwinTyre, isSpare),
|
|
1992
|
-
[]
|
|
1993
|
-
);
|
|
1980
|
+
const bridgeIndex = isSpare ? 8 : bridgeTools.getBridgeIndexFromPositionId(positionId);
|
|
1981
|
+
const subCommandId = axlePosition * 16 + bridgeIndex;
|
|
1982
|
+
const result = await this.writeCommand(deviceData, commandIds$1.sensorMeasurement, subCommandId, []);
|
|
1994
1983
|
return result;
|
|
1995
1984
|
},
|
|
1996
1985
|
async readCommand(device, subCommandId) {
|
|
@@ -2310,7 +2299,7 @@ async function setAxleInfo(deviceId, tcVehicle) {
|
|
|
2310
2299
|
const spareTyre = spareTyres[axleIndex];
|
|
2311
2300
|
if (!axleTyres.length && !spareTyre && axleIndex >= tcVehicle.axles.length) continue;
|
|
2312
2301
|
for (const tyre of axleTyres) {
|
|
2313
|
-
const bridgeIndex = getBridgeIndexFromPositionId(tyre.positionId, 7);
|
|
2302
|
+
const bridgeIndex = bridgeTools.getBridgeIndexFromPositionId(tyre.positionId, 7);
|
|
2314
2303
|
tyres[bridgeIndex] = tyre.tcTpmsSensor.id;
|
|
2315
2304
|
}
|
|
2316
2305
|
if (spareTyre && spareTyre.tcTpmsSensor) tyres[7] = spareTyre.tcTpmsSensor.id;
|
|
@@ -2430,7 +2419,7 @@ async function getAutolearnStatuses(deviceId, tcVehicle) {
|
|
|
2430
2419
|
if (!tcTyre.mountedOn?.positionId || tcTyre.mountedOn?.positionId % 10 === 0) continue;
|
|
2431
2420
|
const axleIndex = Math.floor(tcTyre.mountedOn?.positionId / 100) - 1;
|
|
2432
2421
|
const axleStatuses = statusEntries[axleIndex];
|
|
2433
|
-
const tyreIndex = getBridgeIndexFromPositionId(tcTyre.mountedOn.positionId, 7);
|
|
2422
|
+
const tyreIndex = bridgeTools.getBridgeIndexFromPositionId(tcTyre.mountedOn.positionId, 7);
|
|
2434
2423
|
const tyreStatus = axleStatuses.split("").reverse().join("")[tyreIndex];
|
|
2435
2424
|
let autolearnedSensorId;
|
|
2436
2425
|
if (["1", "4", "9"].includes(tyreStatus)) {
|
|
@@ -2474,7 +2463,7 @@ async function resetAutolearnStatuses(deviceId, positionIds) {
|
|
|
2474
2463
|
for (const [axleIndex, axlePositionIds] of Object.entries(sortedByAxle)) {
|
|
2475
2464
|
const statusesAxleIndex = Number(axleIndex) - 1;
|
|
2476
2465
|
for (const positionId of axlePositionIds) {
|
|
2477
|
-
const bitIndex = getBridgeIndexFromPositionId(positionId, 7);
|
|
2466
|
+
const bitIndex = bridgeTools.getBridgeIndexFromPositionId(positionId, 7);
|
|
2478
2467
|
let status = statuses[statusesKeys[statusesAxleIndex]].split("").reverse().join("");
|
|
2479
2468
|
status = `${status.substring(0, bitIndex)}0${status.substring(bitIndex + 1)}`;
|
|
2480
2469
|
statuses[statusesKeys[statusesAxleIndex]] = status.split("").reverse().join("");
|
|
@@ -2482,13 +2471,6 @@ async function resetAutolearnStatuses(deviceId, positionIds) {
|
|
|
2482
2471
|
}
|
|
2483
2472
|
await bridgeCommands.setAutolearnIdStatus(deviceId, statuses);
|
|
2484
2473
|
}
|
|
2485
|
-
function getBridgeIndexFromPositionId(positionId, centerIndex = 8) {
|
|
2486
|
-
const halfPoint = positionId % 10 * 6;
|
|
2487
|
-
const tyrePosition = positionId % 100;
|
|
2488
|
-
const result = (tyrePosition - halfPoint) / 10 - (tyrePosition <= halfPoint ? 1 : 0);
|
|
2489
|
-
const bitIndex = centerIndex + result;
|
|
2490
|
-
return bitIndex;
|
|
2491
|
-
}
|
|
2492
2474
|
function getPressureAndTemperatureReadingObjects(rawPressure, rawTemperature) {
|
|
2493
2475
|
if (rawTemperature === 255 || rawPressure === 0) {
|
|
2494
2476
|
return {
|
|
@@ -2664,7 +2646,7 @@ async function assignTyres(deviceId, tcVehicle) {
|
|
|
2664
2646
|
}
|
|
2665
2647
|
for (let tyreIndex = 1; tyreIndex <= axle.tyresCount; tyreIndex++) {
|
|
2666
2648
|
const tyrePositionId = getPositionId(index + 1, tyreIndex, axle.tyresCount);
|
|
2667
|
-
const sensorIndex = getBridgeIndexFromPositionId(tyrePositionId, 7);
|
|
2649
|
+
const sensorIndex = bridgeTools.getBridgeIndexFromPositionId(tyrePositionId, 7);
|
|
2668
2650
|
const tyre = createNewTyre(tyrePositionId);
|
|
2669
2651
|
if (Number.parseInt(joinedAxleData[sensorIndex], 16)) {
|
|
2670
2652
|
tyre.tcTpmsSensor = {
|
package/dist/index.mjs
CHANGED
|
@@ -138,7 +138,7 @@ const bridgeTools = {
|
|
|
138
138
|
convertBytesToStructure(objStructure, payload, fwVersion) {
|
|
139
139
|
let numArray = _.clone(payload);
|
|
140
140
|
const keys = Object.keys(objStructure).filter(
|
|
141
|
-
(key) => !objStructure[key].version ||
|
|
141
|
+
(key) => !objStructure[key].version || fwVersion && fwVersion >= objStructure[key].version
|
|
142
142
|
);
|
|
143
143
|
let sumWithInitial = 0;
|
|
144
144
|
for (const key of keys) {
|
|
@@ -162,7 +162,7 @@ const bridgeTools = {
|
|
|
162
162
|
},
|
|
163
163
|
convertStructureToBytes(objStructure, structurizedObj, fwVersion) {
|
|
164
164
|
const keys = Object.keys(objStructure).filter(
|
|
165
|
-
(key) => !objStructure[key].version ||
|
|
165
|
+
(key) => !objStructure[key].version || fwVersion && fwVersion >= objStructure[key].version
|
|
166
166
|
);
|
|
167
167
|
const result = [];
|
|
168
168
|
for (const key of keys) {
|
|
@@ -332,6 +332,13 @@ const bridgeTools = {
|
|
|
332
332
|
getSpareTyres(tcVehicle) {
|
|
333
333
|
const spareTyres = tcVehicle.tcTyres?.filter((tyre) => String(tyre.mountedOn?.positionId).endsWith("0"));
|
|
334
334
|
return spareTyres;
|
|
335
|
+
},
|
|
336
|
+
getBridgeIndexFromPositionId(positionId, centerIndex = 8) {
|
|
337
|
+
const halfPoint = positionId % 10 * 6;
|
|
338
|
+
const tyrePosition = positionId % 100;
|
|
339
|
+
const result = (tyrePosition - halfPoint) / 10 - (tyrePosition <= halfPoint ? 1 : 0);
|
|
340
|
+
const bitIndex = centerIndex + result;
|
|
341
|
+
return bitIndex;
|
|
335
342
|
}
|
|
336
343
|
};
|
|
337
344
|
function getDefaultTyreLabels() {
|
|
@@ -1681,21 +1688,6 @@ const subCommandIds = {
|
|
|
1681
1688
|
/** 0x20 - 0x2F */
|
|
1682
1689
|
idsPerWheel: (axleIndex) => 32 + axleIndex,
|
|
1683
1690
|
/** only for commandIds.sensorMeasurement */
|
|
1684
|
-
sensorMeasurementPerWheel: (axlePosition, tyrePosition, isTwinTyre, isSpareAxle) => {
|
|
1685
|
-
let bridgeTyrePosition = 0;
|
|
1686
|
-
if (isTwinTyre && !isSpareAxle) {
|
|
1687
|
-
if (tyrePosition === 1) bridgeTyrePosition = 6;
|
|
1688
|
-
else if (tyrePosition === 2) bridgeTyrePosition = 7;
|
|
1689
|
-
else if (tyrePosition === 3) bridgeTyrePosition = 9;
|
|
1690
|
-
else if (tyrePosition === 4) bridgeTyrePosition = 10;
|
|
1691
|
-
} else if (!isTwinTyre && !isSpareAxle) {
|
|
1692
|
-
if (tyrePosition === 1) bridgeTyrePosition = 7;
|
|
1693
|
-
else if (tyrePosition === 2) bridgeTyrePosition = 9;
|
|
1694
|
-
} else if (isSpareAxle) {
|
|
1695
|
-
if (tyrePosition === 1) bridgeTyrePosition = 8;
|
|
1696
|
-
}
|
|
1697
|
-
return axlePosition * 16 + bridgeTyrePosition;
|
|
1698
|
-
},
|
|
1699
1691
|
pressurePerAxle: 48,
|
|
1700
1692
|
customerPressureThresholds: 64,
|
|
1701
1693
|
customerTemperatureThresholds: 65,
|
|
@@ -1974,16 +1966,13 @@ const bridgeCommands = {
|
|
|
1974
1966
|
const deviceData = bridgeTools.getBridgeFromStore(deviceId);
|
|
1975
1967
|
const isSpare = String(positionId).endsWith("0");
|
|
1976
1968
|
const positionInfo = bridgeTools.getPositionInfo(positionId);
|
|
1977
|
-
const { axlePosition
|
|
1978
|
-
if (axlePosition == null
|
|
1969
|
+
const { axlePosition } = positionInfo;
|
|
1970
|
+
if (axlePosition == null) {
|
|
1979
1971
|
throw new Error(`Invalid positionId ${positionId}`);
|
|
1980
1972
|
}
|
|
1981
|
-
const
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
subCommandIds.sensorMeasurementPerWheel(axlePosition, tyrePosition, isTwinTyre, isSpare),
|
|
1985
|
-
[]
|
|
1986
|
-
);
|
|
1973
|
+
const bridgeIndex = isSpare ? 8 : bridgeTools.getBridgeIndexFromPositionId(positionId);
|
|
1974
|
+
const subCommandId = axlePosition * 16 + bridgeIndex;
|
|
1975
|
+
const result = await this.writeCommand(deviceData, commandIds$1.sensorMeasurement, subCommandId, []);
|
|
1987
1976
|
return result;
|
|
1988
1977
|
},
|
|
1989
1978
|
async readCommand(device, subCommandId) {
|
|
@@ -2303,7 +2292,7 @@ async function setAxleInfo(deviceId, tcVehicle) {
|
|
|
2303
2292
|
const spareTyre = spareTyres[axleIndex];
|
|
2304
2293
|
if (!axleTyres.length && !spareTyre && axleIndex >= tcVehicle.axles.length) continue;
|
|
2305
2294
|
for (const tyre of axleTyres) {
|
|
2306
|
-
const bridgeIndex = getBridgeIndexFromPositionId(tyre.positionId, 7);
|
|
2295
|
+
const bridgeIndex = bridgeTools.getBridgeIndexFromPositionId(tyre.positionId, 7);
|
|
2307
2296
|
tyres[bridgeIndex] = tyre.tcTpmsSensor.id;
|
|
2308
2297
|
}
|
|
2309
2298
|
if (spareTyre && spareTyre.tcTpmsSensor) tyres[7] = spareTyre.tcTpmsSensor.id;
|
|
@@ -2423,7 +2412,7 @@ async function getAutolearnStatuses(deviceId, tcVehicle) {
|
|
|
2423
2412
|
if (!tcTyre.mountedOn?.positionId || tcTyre.mountedOn?.positionId % 10 === 0) continue;
|
|
2424
2413
|
const axleIndex = Math.floor(tcTyre.mountedOn?.positionId / 100) - 1;
|
|
2425
2414
|
const axleStatuses = statusEntries[axleIndex];
|
|
2426
|
-
const tyreIndex = getBridgeIndexFromPositionId(tcTyre.mountedOn.positionId, 7);
|
|
2415
|
+
const tyreIndex = bridgeTools.getBridgeIndexFromPositionId(tcTyre.mountedOn.positionId, 7);
|
|
2427
2416
|
const tyreStatus = axleStatuses.split("").reverse().join("")[tyreIndex];
|
|
2428
2417
|
let autolearnedSensorId;
|
|
2429
2418
|
if (["1", "4", "9"].includes(tyreStatus)) {
|
|
@@ -2467,7 +2456,7 @@ async function resetAutolearnStatuses(deviceId, positionIds) {
|
|
|
2467
2456
|
for (const [axleIndex, axlePositionIds] of Object.entries(sortedByAxle)) {
|
|
2468
2457
|
const statusesAxleIndex = Number(axleIndex) - 1;
|
|
2469
2458
|
for (const positionId of axlePositionIds) {
|
|
2470
|
-
const bitIndex = getBridgeIndexFromPositionId(positionId, 7);
|
|
2459
|
+
const bitIndex = bridgeTools.getBridgeIndexFromPositionId(positionId, 7);
|
|
2471
2460
|
let status = statuses[statusesKeys[statusesAxleIndex]].split("").reverse().join("");
|
|
2472
2461
|
status = `${status.substring(0, bitIndex)}0${status.substring(bitIndex + 1)}`;
|
|
2473
2462
|
statuses[statusesKeys[statusesAxleIndex]] = status.split("").reverse().join("");
|
|
@@ -2475,13 +2464,6 @@ async function resetAutolearnStatuses(deviceId, positionIds) {
|
|
|
2475
2464
|
}
|
|
2476
2465
|
await bridgeCommands.setAutolearnIdStatus(deviceId, statuses);
|
|
2477
2466
|
}
|
|
2478
|
-
function getBridgeIndexFromPositionId(positionId, centerIndex = 8) {
|
|
2479
|
-
const halfPoint = positionId % 10 * 6;
|
|
2480
|
-
const tyrePosition = positionId % 100;
|
|
2481
|
-
const result = (tyrePosition - halfPoint) / 10 - (tyrePosition <= halfPoint ? 1 : 0);
|
|
2482
|
-
const bitIndex = centerIndex + result;
|
|
2483
|
-
return bitIndex;
|
|
2484
|
-
}
|
|
2485
2467
|
function getPressureAndTemperatureReadingObjects(rawPressure, rawTemperature) {
|
|
2486
2468
|
if (rawTemperature === 255 || rawPressure === 0) {
|
|
2487
2469
|
return {
|
|
@@ -2657,7 +2639,7 @@ async function assignTyres(deviceId, tcVehicle) {
|
|
|
2657
2639
|
}
|
|
2658
2640
|
for (let tyreIndex = 1; tyreIndex <= axle.tyresCount; tyreIndex++) {
|
|
2659
2641
|
const tyrePositionId = getPositionId(index + 1, tyreIndex, axle.tyresCount);
|
|
2660
|
-
const sensorIndex = getBridgeIndexFromPositionId(tyrePositionId, 7);
|
|
2642
|
+
const sensorIndex = bridgeTools.getBridgeIndexFromPositionId(tyrePositionId, 7);
|
|
2661
2643
|
const tyre = createNewTyre(tyrePositionId);
|
|
2662
2644
|
if (Number.parseInt(joinedAxleData[sensorIndex], 16)) {
|
|
2663
2645
|
tyre.tcTpmsSensor = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tirecheck-device-sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.50",
|
|
4
4
|
"description": "SDK for working with various devices produced by Tirecheck via Bluetooth (CAN Bridge, Routers, Sensors, FlexiGauge, PressureStick, etc)",
|
|
5
5
|
"author": "Leonid Buneev <leonid.buneev@tirecheck.com>",
|
|
6
6
|
"license": "ISC",
|