iobroker.bydhvs 1.5.0 → 1.5.2

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/lib/methods.js ADDED
@@ -0,0 +1,56 @@
1
+ 'use strict';
2
+
3
+ function buf2int16SI(byteArray, pos) {
4
+ //signed
5
+ let result = 0;
6
+ result = byteArray[pos] * 256 + byteArray[pos + 1];
7
+ if (result > 32768) {
8
+ result -= 65536;
9
+ }
10
+ return result;
11
+ }
12
+
13
+ function buf2int16US(byteArray, pos) {
14
+ //unsigned
15
+ let result = 0;
16
+ result = byteArray[pos] * 256 + byteArray[pos + 1];
17
+ return result;
18
+ }
19
+
20
+ function buf2int32US(byteArray, pos) {
21
+ //unsigned
22
+ let result = 0;
23
+ result = byteArray[pos + 2] * 16777216 + byteArray[pos + 3] * 65536 + byteArray[pos] * 256 + byteArray[pos + 1];
24
+ return result;
25
+ }
26
+
27
+ function decodePacketNOP(_data) {
28
+ this.log.silly('Packet NOP');
29
+ }
30
+
31
+ function countSetBits(hexString) {
32
+ // Hexadezimale Zeichen in einen Binärstring umwandeln
33
+ let binaryString = '';
34
+ for (let i = 0; i < hexString.length; i++) {
35
+ // Jeder Hex-Char in einen Binär-String umwandeln und auf 4 Stellen auffüllen
36
+ binaryString += parseInt(hexString[i], 16).toString(2).padStart(4, '0');
37
+ }
38
+
39
+ // Anzahl der '1' Bits im Binärstring zählen
40
+ let setBitsCount = 0;
41
+ for (let i = 0; i < binaryString.length; i++) {
42
+ if (binaryString[i] === '1') {
43
+ setBitsCount++;
44
+ }
45
+ }
46
+
47
+ return setBitsCount;
48
+ }
49
+
50
+ module.exports = {
51
+ buf2int16SI,
52
+ buf2int16US,
53
+ buf2int32US,
54
+ decodePacketNOP,
55
+ countSetBits,
56
+ };