mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
formatting
This commit is contained in:
@@ -1,17 +1,42 @@
|
|||||||
// @ts-nocheck - Optimized MessagePack unpacking library for EMS-ESP32
|
// @ts-nocheck - Optimized MessagePack unpacking library for EMS-ESP32
|
||||||
let decoder, src, srcEnd, position = 0, strings = [], stringPosition = 0, currentUnpackr = {}, currentStructures, srcString, srcStringStart = 0, srcStringEnd = 0, bundledStrings, referenceMap, dataView;
|
let decoder,
|
||||||
const EMPTY_ARRAY = [], currentExtensions = [];
|
src,
|
||||||
|
srcEnd,
|
||||||
|
position = 0,
|
||||||
|
strings = [],
|
||||||
|
stringPosition = 0,
|
||||||
|
currentUnpackr = {},
|
||||||
|
currentStructures,
|
||||||
|
srcString,
|
||||||
|
srcStringStart = 0,
|
||||||
|
srcStringEnd = 0,
|
||||||
|
bundledStrings,
|
||||||
|
referenceMap,
|
||||||
|
dataView;
|
||||||
|
const EMPTY_ARRAY = [],
|
||||||
|
currentExtensions = [];
|
||||||
const defaultOptions = { useRecords: false, mapsAsObjects: true };
|
const defaultOptions = { useRecords: false, mapsAsObjects: true };
|
||||||
try { decoder = new TextDecoder(); } catch (error) { }
|
try {
|
||||||
class C1Type { }
|
decoder = new TextDecoder();
|
||||||
|
} catch (error) {}
|
||||||
|
class C1Type {}
|
||||||
const C1 = new C1Type();
|
const C1 = new C1Type();
|
||||||
C1.name = 'MessagePack 0xC1';
|
C1.name = 'MessagePack 0xC1';
|
||||||
let sequentialMode = false, inlineObjectReadThreshold = 2, readStruct, onLoadedStructures, onSaveState;
|
let sequentialMode = false,
|
||||||
try { new Function(''); } catch (error) { inlineObjectReadThreshold = Infinity; }
|
inlineObjectReadThreshold = 2,
|
||||||
|
readStruct,
|
||||||
|
onLoadedStructures,
|
||||||
|
onSaveState;
|
||||||
|
try {
|
||||||
|
new Function('');
|
||||||
|
} catch (error) {
|
||||||
|
inlineObjectReadThreshold = Infinity;
|
||||||
|
}
|
||||||
export class Unpackr {
|
export class Unpackr {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
if (options) {
|
if (options) {
|
||||||
if (options.useRecords === false && options.mapsAsObjects === undefined) options.mapsAsObjects = true;
|
if (options.useRecords === false && options.mapsAsObjects === undefined)
|
||||||
|
options.mapsAsObjects = true;
|
||||||
if (options.sequential && options.trusted !== false) {
|
if (options.sequential && options.trusted !== false) {
|
||||||
options.trusted = true;
|
options.trusted = true;
|
||||||
if (!options.structures && options.useRecords != false) {
|
if (!options.structures && options.useRecords != false) {
|
||||||
@@ -19,7 +44,8 @@ export class Unpackr {
|
|||||||
if (!options.maxSharedStructures) options.maxSharedStructures = 0;
|
if (!options.maxSharedStructures) options.maxSharedStructures = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (options.structures) options.structures.sharedLength = options.structures.length;
|
if (options.structures)
|
||||||
|
options.structures.sharedLength = options.structures.length;
|
||||||
else if (options.getStructures) {
|
else if (options.getStructures) {
|
||||||
(options.structures = []).uninitialized = true;
|
(options.structures = []).uninitialized = true;
|
||||||
options.structures.sharedLength = 0;
|
options.structures.sharedLength = 0;
|
||||||
@@ -67,9 +93,9 @@ export class Unpackr {
|
|||||||
if (source instanceof Uint8Array) throw error;
|
if (source instanceof Uint8Array) throw error;
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'Source must be a Uint8Array or Buffer but was a ' +
|
'Source must be a Uint8Array or Buffer but was a ' +
|
||||||
(source && typeof source == 'object'
|
(source && typeof source == 'object'
|
||||||
? source.constructor.name
|
? source.constructor.name
|
||||||
: typeof source)
|
: typeof source)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (this instanceof Unpackr) {
|
if (this instanceof Unpackr) {
|
||||||
@@ -506,18 +532,18 @@ function createStructureReader(structure, firstId) {
|
|||||||
const readObject = (structure.read = new Function(
|
const readObject = (structure.read = new Function(
|
||||||
'r',
|
'r',
|
||||||
'return function(){return ' +
|
'return function(){return ' +
|
||||||
(currentUnpackr.freezeData ? 'Object.freeze' : '') +
|
(currentUnpackr.freezeData ? 'Object.freeze' : '') +
|
||||||
'({' +
|
'({' +
|
||||||
structure
|
structure
|
||||||
.map((key) =>
|
.map((key) =>
|
||||||
key === '__proto__'
|
key === '__proto__'
|
||||||
? '__proto_:r()'
|
? '__proto_:r()'
|
||||||
: validName.test(key)
|
: validName.test(key)
|
||||||
? key + ':r()'
|
? key + ':r()'
|
||||||
: '[' + JSON.stringify(key) + ']:r()'
|
: '[' + JSON.stringify(key) + ']:r()'
|
||||||
)
|
)
|
||||||
.join(',') +
|
.join(',') +
|
||||||
'})}'
|
'})}'
|
||||||
)(read));
|
)(read));
|
||||||
if (structure.highByte === 0)
|
if (structure.highByte === 0)
|
||||||
structure.read = createSecondByteReader(firstId, structure.read);
|
structure.read = createSecondByteReader(firstId, structure.read);
|
||||||
@@ -881,7 +907,7 @@ function readOnlyJSString() {
|
|||||||
function readBin(length) {
|
function readBin(length) {
|
||||||
return currentUnpackr.copyBuffers
|
return currentUnpackr.copyBuffers
|
||||||
? // specifically use the copying slice (not the node one)
|
? // specifically use the copying slice (not the node one)
|
||||||
Uint8Array.prototype.slice.call(src, position, (position += length))
|
Uint8Array.prototype.slice.call(src, position, (position += length))
|
||||||
: src.subarray(position, (position += length));
|
: src.subarray(position, (position += length));
|
||||||
}
|
}
|
||||||
function readExt(length) {
|
function readExt(length) {
|
||||||
@@ -989,7 +1015,7 @@ const recordDefinition = (id, highByte) => {
|
|||||||
structure.read = createStructureReader(structure, firstByte);
|
structure.read = createStructureReader(structure, firstByte);
|
||||||
return structure.read();
|
return structure.read();
|
||||||
};
|
};
|
||||||
currentExtensions[0] = () => { }; // notepack defines extension 0 to mean undefined, so use that as the default here
|
currentExtensions[0] = () => {}; // notepack defines extension 0 to mean undefined, so use that as the default here
|
||||||
currentExtensions[0].noBuffer = true;
|
currentExtensions[0].noBuffer = true;
|
||||||
|
|
||||||
const glbl = typeof globalThis === 'object' ? globalThis : window;
|
const glbl = typeof globalThis === 'object' ? globalThis : window;
|
||||||
@@ -1077,25 +1103,25 @@ currentExtensions[0xff] = (data) => {
|
|||||||
else if (data.length == 8)
|
else if (data.length == 8)
|
||||||
return new Date(
|
return new Date(
|
||||||
((data[0] << 22) + (data[1] << 14) + (data[2] << 6) + (data[3] >> 2)) /
|
((data[0] << 22) + (data[1] << 14) + (data[2] << 6) + (data[3] >> 2)) /
|
||||||
1000000 +
|
1000000 +
|
||||||
((data[3] & 0x3) * 0x100000000 +
|
((data[3] & 0x3) * 0x100000000 +
|
||||||
data[4] * 0x1000000 +
|
data[4] * 0x1000000 +
|
||||||
(data[5] << 16) +
|
(data[5] << 16) +
|
||||||
(data[6] << 8) +
|
(data[6] << 8) +
|
||||||
data[7]) *
|
data[7]) *
|
||||||
1000
|
1000
|
||||||
);
|
);
|
||||||
else if (data.length == 12)
|
else if (data.length == 12)
|
||||||
return new Date(
|
return new Date(
|
||||||
((data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3]) / 1000000 +
|
((data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3]) / 1000000 +
|
||||||
((data[4] & 0x80 ? -0x1000000000000 : 0) +
|
((data[4] & 0x80 ? -0x1000000000000 : 0) +
|
||||||
data[6] * 0x10000000000 +
|
data[6] * 0x10000000000 +
|
||||||
data[7] * 0x100000000 +
|
data[7] * 0x100000000 +
|
||||||
data[8] * 0x1000000 +
|
data[8] * 0x1000000 +
|
||||||
(data[9] << 16) +
|
(data[9] << 16) +
|
||||||
(data[10] << 8) +
|
(data[10] << 8) +
|
||||||
data[11]) *
|
data[11]) *
|
||||||
1000
|
1000
|
||||||
);
|
);
|
||||||
else return new Date('invalid');
|
else return new Date('invalid');
|
||||||
}; // notepack defines extension 0 to mean undefined, so use that as the default here
|
}; // notepack defines extension 0 to mean undefined, so use that as the default here
|
||||||
|
|||||||
@@ -276,10 +276,10 @@ function updateMask(entity: any, de: any, dd: any) {
|
|||||||
const old_custom_name = dd.nodes[dd_objIndex].cn;
|
const old_custom_name = dd.nodes[dd_objIndex].cn;
|
||||||
console.log(
|
console.log(
|
||||||
'comparing names, old (' +
|
'comparing names, old (' +
|
||||||
old_custom_name +
|
old_custom_name +
|
||||||
') with new (' +
|
') with new (' +
|
||||||
new_custom_name +
|
new_custom_name +
|
||||||
')'
|
')'
|
||||||
);
|
);
|
||||||
if (old_custom_name !== new_custom_name) {
|
if (old_custom_name !== new_custom_name) {
|
||||||
changed = true;
|
changed = true;
|
||||||
@@ -375,15 +375,15 @@ function check_upgrade(version: string) {
|
|||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
'Upgrade this version (' +
|
'Upgrade this version (' +
|
||||||
THIS_VERSION +
|
THIS_VERSION +
|
||||||
') to dev (' +
|
') to dev (' +
|
||||||
dev_version +
|
dev_version +
|
||||||
') is ' +
|
') is ' +
|
||||||
(DEV_VERSION_IS_UPGRADEABLE ? 'YES' : 'NO') +
|
(DEV_VERSION_IS_UPGRADEABLE ? 'YES' : 'NO') +
|
||||||
' and to stable (' +
|
' and to stable (' +
|
||||||
stable_version +
|
stable_version +
|
||||||
') is ' +
|
') is ' +
|
||||||
(STABLE_VERSION_IS_UPGRADEABLE ? 'YES' : 'NO')
|
(STABLE_VERSION_IS_UPGRADEABLE ? 'YES' : 'NO')
|
||||||
);
|
);
|
||||||
data = {
|
data = {
|
||||||
emsesp_version: THIS_VERSION,
|
emsesp_version: THIS_VERSION,
|
||||||
@@ -4378,78 +4378,124 @@ router
|
|||||||
|
|
||||||
function deviceData(id: number) {
|
function deviceData(id: number) {
|
||||||
if (id == 1) {
|
if (id == 1) {
|
||||||
return new Response(encoder.encode(emsesp_devicedata_1) as BodyInit, { headers });
|
return new Response(encoder.encode(emsesp_devicedata_1) as BodyInit, {
|
||||||
|
headers
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (id == 2) {
|
if (id == 2) {
|
||||||
return new Response(encoder.encode(emsesp_devicedata_2) as BodyInit, { headers });
|
return new Response(encoder.encode(emsesp_devicedata_2) as BodyInit, {
|
||||||
|
headers
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (id == 3) {
|
if (id == 3) {
|
||||||
return new Response(encoder.encode(emsesp_devicedata_3) as BodyInit, { headers });
|
return new Response(encoder.encode(emsesp_devicedata_3) as BodyInit, {
|
||||||
|
headers
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (id == 4) {
|
if (id == 4) {
|
||||||
return new Response(encoder.encode(emsesp_devicedata_4) as BodyInit, { headers });
|
return new Response(encoder.encode(emsesp_devicedata_4) as BodyInit, {
|
||||||
|
headers
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (id == 5) {
|
if (id == 5) {
|
||||||
return new Response(encoder.encode(emsesp_devicedata_5) as BodyInit, { headers });
|
return new Response(encoder.encode(emsesp_devicedata_5) as BodyInit, {
|
||||||
|
headers
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (id == 6) {
|
if (id == 6) {
|
||||||
return new Response(encoder.encode(emsesp_devicedata_6) as BodyInit, { headers });
|
return new Response(encoder.encode(emsesp_devicedata_6) as BodyInit, {
|
||||||
|
headers
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (id == 7) {
|
if (id == 7) {
|
||||||
return new Response(encoder.encode(emsesp_devicedata_7) as BodyInit, { headers });
|
return new Response(encoder.encode(emsesp_devicedata_7) as BodyInit, {
|
||||||
|
headers
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (id == 8) {
|
if (id == 8) {
|
||||||
// test changing the selected flow temp on a Bosch Compress 7000i AW Heat Pump (Boiler/HP)
|
// test changing the selected flow temp on a Bosch Compress 7000i AW Heat Pump (Boiler/HP)
|
||||||
emsesp_devicedata_8.nodes[4].v = Math.floor(Math.random() * 100);
|
emsesp_devicedata_8.nodes[4].v = Math.floor(Math.random() * 100);
|
||||||
return new Response(encoder.encode(emsesp_devicedata_8) as BodyInit, { headers });
|
return new Response(encoder.encode(emsesp_devicedata_8) as BodyInit, {
|
||||||
|
headers
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (id == 9) {
|
if (id == 9) {
|
||||||
return new Response(encoder.encode(emsesp_devicedata_9) as BodyInit, { headers });
|
return new Response(encoder.encode(emsesp_devicedata_9) as BodyInit, {
|
||||||
|
headers
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (id == 10) {
|
if (id == 10) {
|
||||||
return new Response(encoder.encode(emsesp_devicedata_10) as BodyInit, { headers });
|
return new Response(encoder.encode(emsesp_devicedata_10) as BodyInit, {
|
||||||
|
headers
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (id == 11) {
|
if (id == 11) {
|
||||||
return new Response(encoder.encode(emsesp_devicedata_11) as BodyInit, { headers });
|
return new Response(encoder.encode(emsesp_devicedata_11) as BodyInit, {
|
||||||
|
headers
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (id == 99) {
|
if (id == 99) {
|
||||||
return new Response(encoder.encode(emsesp_devicedata_99) as BodyInit, { headers });
|
return new Response(encoder.encode(emsesp_devicedata_99) as BodyInit, {
|
||||||
|
headers
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function deviceEntities(id: number) {
|
function deviceEntities(id: number) {
|
||||||
if (id == 1) {
|
if (id == 1) {
|
||||||
return new Response(encoder.encode(emsesp_deviceentities_1) as BodyInit, { headers });
|
return new Response(encoder.encode(emsesp_deviceentities_1) as BodyInit, {
|
||||||
|
headers
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (id == 2) {
|
if (id == 2) {
|
||||||
return new Response(encoder.encode(emsesp_deviceentities_2) as BodyInit, { headers });
|
return new Response(encoder.encode(emsesp_deviceentities_2) as BodyInit, {
|
||||||
|
headers
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (id == 3) {
|
if (id == 3) {
|
||||||
return new Response(encoder.encode(emsesp_deviceentities_3) as BodyInit, { headers });
|
return new Response(encoder.encode(emsesp_deviceentities_3) as BodyInit, {
|
||||||
|
headers
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (id == 4) {
|
if (id == 4) {
|
||||||
return new Response(encoder.encode(emsesp_deviceentities_4) as BodyInit, { headers });
|
return new Response(encoder.encode(emsesp_deviceentities_4) as BodyInit, {
|
||||||
|
headers
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (id == 5) {
|
if (id == 5) {
|
||||||
return new Response(encoder.encode(emsesp_deviceentities_5) as BodyInit, { headers });
|
return new Response(encoder.encode(emsesp_deviceentities_5) as BodyInit, {
|
||||||
|
headers
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (id == 6) {
|
if (id == 6) {
|
||||||
return new Response(encoder.encode(emsesp_deviceentities_6) as BodyInit, { headers });
|
return new Response(encoder.encode(emsesp_deviceentities_6) as BodyInit, {
|
||||||
|
headers
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (id == 7) {
|
if (id == 7) {
|
||||||
return new Response(encoder.encode(emsesp_deviceentities_7) as BodyInit, { headers });
|
return new Response(encoder.encode(emsesp_deviceentities_7) as BodyInit, {
|
||||||
|
headers
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (id == 8) {
|
if (id == 8) {
|
||||||
return new Response(encoder.encode(emsesp_deviceentities_8) as BodyInit, { headers });
|
return new Response(encoder.encode(emsesp_deviceentities_8) as BodyInit, {
|
||||||
|
headers
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (id == 9) {
|
if (id == 9) {
|
||||||
return new Response(encoder.encode(emsesp_deviceentities_9) as BodyInit, { headers });
|
return new Response(encoder.encode(emsesp_deviceentities_9) as BodyInit, {
|
||||||
|
headers
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (id == 10) {
|
if (id == 10) {
|
||||||
return new Response(encoder.encode(emsesp_deviceentities_10) as BodyInit, { headers });
|
return new Response(encoder.encode(emsesp_deviceentities_10) as BodyInit, {
|
||||||
|
headers
|
||||||
|
});
|
||||||
}
|
}
|
||||||
// not found, return empty
|
// not found, return empty
|
||||||
return new Response(encoder.encode(emsesp_deviceentities_none) as BodyInit, { headers });
|
return new Response(encoder.encode(emsesp_deviceentities_none) as BodyInit, {
|
||||||
|
headers
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepare dashboard data
|
// prepare dashboard data
|
||||||
@@ -4575,7 +4621,9 @@ router
|
|||||||
|
|
||||||
// add analog sensor data. no command c
|
// add analog sensor data. no command c
|
||||||
// remove disabled sensors first (t = 0) and create data in one pass
|
// remove disabled sensors first (t = 0) and create data in one pass
|
||||||
const enabledAnalogSensors = emsesp_sensordata.as.filter((item) => item.t !== 0);
|
const enabledAnalogSensors = emsesp_sensordata.as.filter(
|
||||||
|
(item) => item.t !== 0
|
||||||
|
);
|
||||||
if (enabledAnalogSensors.length > 0) {
|
if (enabledAnalogSensors.length > 0) {
|
||||||
const sensor_data = enabledAnalogSensors.map((item, index) => ({
|
const sensor_data = enabledAnalogSensors.map((item, index) => ({
|
||||||
id: DeviceTypeUniqueID.ANALOGSENSOR_UID * 100 + index,
|
id: DeviceTypeUniqueID.ANALOGSENSOR_UID * 100 + index,
|
||||||
|
|||||||
Reference in New Issue
Block a user