node-red-contrib-knx-ultimate 1.4.11 → 1.4.13

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/CHANGELOG.md CHANGED
@@ -6,6 +6,14 @@
6
6
 
7
7
  # CHANGELOG
8
8
 
9
+ <p>
10
+ <b>Version 1.4.13</b> - January 2022<br/>
11
+ - FIX: Fixed Datapoint 9. There was too many decimals.<br/>
12
+ </p>
13
+ <p>
14
+ <b>Version 1.4.12</b> - January 2022<br/>
15
+ - FIX: fixed scene controller issue.<br/>
16
+ </p>
9
17
  <p>
10
18
  <b>Version 1.4.11</b> - January 2022<br/>
11
19
  - FIX: fixed RBE output filter, for those Datapoints (like PPM) that doesn't follow the KNX specifications. (https://github.com/Supergiovane/node-red-contrib-knx-ultimate/issues/223) and when you use the "round, multiply, etc..." payload handling option in the node configuration.<br/>
@@ -11,110 +11,63 @@ const knxLog = require('./../KnxLog')
11
11
 
12
12
  const util = require('util')
13
13
  // kudos to http://croquetweak.blogspot.gr/2014/08/deconstructing-floats-frexp-and-ldexp.html
14
- // function ldexp(mantissa, exponent) {
15
- // return exponent > 1023 // avoid multiplying by infinity
16
- // ? mantissa * Math.pow(2, 1023) * Math.pow(2, exponent - 1023)
17
- // : exponent < -1074 // avoid multiplying by zero
18
- // ? mantissa * Math.pow(2, -1074) * Math.pow(2, exponent + 1074)
19
- // : mantissa * Math.pow(2, exponent)
20
- // }
21
-
22
- // function frexp(value) {
23
- // if (value === 0) return [value, 0]
24
- // const data = new DataView(new ArrayBuffer(8))
25
- // data.setFloat64(0, value)
26
- // let bits = (data.getUint32(0) >>> 20) & 0x7FF
27
- // if (bits === 0) {
28
- // data.setFloat64(0, value * Math.pow(2, 64))
29
- // bits = ((data.getUint32(0) >>> 20) & 0x7FF) - 64
30
- // }
31
- // const exponent = bits - 1022
32
- // const mantissa = ldexp(value, -exponent)
33
- // return [mantissa, exponent]
34
- // }
35
-
36
- function ldexp(mantissa, exponent) {
37
- return exponent > 1023
38
- ? mantissa * Math.pow(2, 1023) * Math.pow(2, exponent - 1023)
39
- : exponent < -1074
40
- ? mantissa * Math.pow(2, -1074) * Math.pow(2, exponent + 1074)
41
- : mantissa * Math.pow(2, exponent);
14
+ function ldexp (mantissa, exponent) {
15
+ return exponent > 1023 // avoid multiplying by infinity
16
+ ? mantissa * Math.pow(2, 1023) * Math.pow(2, exponent - 1023)
17
+ : exponent < -1074 // avoid multiplying by zero
18
+ ? mantissa * Math.pow(2, -1074) * Math.pow(2, exponent + 1074)
19
+ : mantissa * Math.pow(2, exponent)
42
20
  }
43
- function frexp(value) {
44
- if (value === 0) {
45
- return [value, 0];
46
- }
47
- const data = new DataView(new ArrayBuffer(8));
48
- data.setFloat64(0, value);
49
- let bits = (data.getUint32(0) >>> 20) & 0x7FF;
21
+
22
+ function frexp (value) {
23
+ if (value === 0) return [value, 0]
24
+ const data = new DataView(new ArrayBuffer(8))
25
+ data.setFloat64(0, value)
26
+ let bits = (data.getUint32(0) >>> 20) & 0x7FF
50
27
  if (bits === 0) {
51
- data.setFloat64(0, value * Math.pow(2, 64));
52
- bits = ((data.getUint32(0) >>> 20) & 0x7FF) - 64;
28
+ data.setFloat64(0, value * Math.pow(2, 64))
29
+ bits = ((data.getUint32(0) >>> 20) & 0x7FF) - 64
53
30
  }
54
- const exponent = bits - 1022, mantissa = ldexp(value, -exponent);
55
- return [mantissa, exponent];
31
+ const exponent = bits - 1022
32
+ const mantissa = ldexp(value, -exponent)
33
+ return [mantissa, exponent]
56
34
  }
57
35
 
58
36
  exports.formatAPDU = function (value) {
59
37
  const apdu_data = Buffer.alloc(2)
60
- const buf = Buffer.alloc(2);
61
- let [mant, exp] = frexp(value);
62
- const sign = mant < 0 ? 1 : 0;
63
- let max_mantissa = 0;
64
- let e;
65
- for (e = exp; e >= -15; e--) {
66
- max_mantissa = ldexp(100 * mant, e);
67
- if (max_mantissa > -2048 && max_mantissa < 2047) {
68
- break;
38
+ if (!isFinite(value)) {
39
+ knxLog.get().warn('DPT9: cannot write non-numeric or undefined value')
40
+ } else {
41
+ const arr = frexp(value)
42
+ const mantissa = arr[0]; const exponent = arr[1]
43
+ // find the minimum exponent that will upsize the normalized mantissa (0,5 to 1 range)
44
+ // in order to fit in 11 bits ([-2048, 2047])
45
+ max_mantissa = 0
46
+ for (e = exponent; e >= -15; e--) {
47
+ max_mantissa = ldexp(100 * mantissa, e)
48
+ if (max_mantissa > -2048 && max_mantissa < 2047) break
69
49
  }
50
+ const sign = (mantissa < 0) ? 1 : 0
51
+ const mant = (mantissa < 0) ? ~(max_mantissa ^ 2047) : max_mantissa
52
+ const exp = exponent - e
53
+ // yucks
54
+ apdu_data[0] = (sign << 7) + (exp << 3) + (mant >> 8)
55
+ apdu_data[1] = mant % 256
70
56
  }
71
- mant = (mant < 0) ? ~(max_mantissa ^ 2047) : max_mantissa;
72
- exp = exp - e;
73
- buf.writeUInt8((sign << 7) + (exp << 3) + (mant >> 8), 0);
74
- buf.writeUInt8(mant % 256, 1);
75
- return buf;
76
- // if (!isFinite(value)) {
77
- // knxLog.get().warn('DPT9: cannot write non-numeric or undefined value')
78
- // } else {
79
- // const arr = frexp(value)
80
- // const mantissa = arr[0]; const exponent = arr[1]
81
- // // find the minimum exponent that will upsize the normalized mantissa (0,5 to 1 range)
82
- // // in order to fit in 11 bits ([-2048, 2047])
83
- // max_mantissa = 0
84
- // for (e = exponent; e >= -15; e--) {
85
- // max_mantissa = ldexp(100 * mantissa, e)
86
- // if (max_mantissa > -2048 && max_mantissa < 2047) break
87
- // }
88
- // const sign = (mantissa < 0) ? 1 : 0
89
- // const mant = (mantissa < 0) ? ~(max_mantissa ^ 2047) : max_mantissa
90
- // const exp = exponent - e
91
- // // yucks
92
- // apdu_data[0] = (sign << 7) + (exp << 3) + (mant >> 8)
93
- // apdu_data[1] = mant % 256
94
- // }
95
- // return apdu_data
57
+ return apdu_data
96
58
  }
97
59
 
98
- exports.fromBuffer = function (buffer) {
99
- if (buffer.length !== 2) {
100
- knxLog.get().warn('DPT9: cannot write non-numeric or undefined value')
60
+ exports.fromBuffer = function (buf) {
61
+ if (buf.length != 2) {
62
+ knxLog.get().warn('DPT9.fromBuffer: buf should be 2 bytes long (got %d bytes)', buf.length)
63
+ return null
64
+ } else {
65
+ const sign = buf[0] >> 7
66
+ const exponent = (buf[0] & 0b01111000) >> 3
67
+ let mantissa = 256 * (buf[0] & 0b00000111) + buf[1]
68
+ mantissa = (sign == 1) ? ~(mantissa ^ 2047) : mantissa
69
+ return parseFloat(ldexp((0.01 * mantissa), exponent).toPrecision(15))
101
70
  }
102
- const val = buffer.readUInt8(0);
103
- const sign = val >> 7;
104
- const exp = (val & 0b01111000) >> 3;
105
- const mant = ((val & 0x07) << 8) + buffer.readUInt8(1);
106
- const signedMant = sign === 1 ? ~(mant ^ 2047) : mant;
107
- return ldexp((0.01 * signedMant), exp);
108
- // if (buf.length != 2) {
109
- // knxLog.get().warn('DPT9.fromBuffer: buf should be 2 bytes long (got %d bytes)', buf.length)
110
- // return null
111
- // } else {
112
- // const sign = buf[0] >> 7
113
- // const exponent = (buf[0] & 0b01111000) >> 3
114
- // let mantissa = 256 * (buf[0] & 0b00000111) + buf[1]
115
- // mantissa = (sign == 1) ? ~(mantissa ^ 2047) : mantissa
116
- // return parseFloat(ldexp((0.01 * mantissa), exponent).toPrecision(15))
117
- // }
118
71
  }
119
72
 
120
73
  // DPT9 basetype info
@@ -305,4 +258,4 @@ exports.subtypes = {
305
258
  unit: 'ug/m3',
306
259
  range: [0, 670760]
307
260
  }
308
- }
261
+ }
@@ -31,7 +31,7 @@ exports.Manipulate = function roundPayload(_oNode, jsValue) {
31
31
  }
32
32
  return jsValue
33
33
  } else {
34
- return null
34
+ return jsValue
35
35
  }
36
36
  } catch (error) {
37
37
  return jsValue
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-knx-ultimate",
3
- "version": "1.4.11",
3
+ "version": "1.4.13",
4
4
  "description": "Control your KNX intallation via Node-Red! Single Node KNX IN/OUT with optional ETS group address importer. Easy to use and highly configurable.",
5
5
  "dependencies": {
6
6
  "mkdirp": "1.0.4",