@homebridge/dbus-native 0.6.0 → 0.7.0

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/index.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ import {EventEmitter} from 'events'
2
+ import {Socket} from 'net'
3
+
4
+ interface DbusInterface extends EventEmitter {
5
+ on(event: string, callback: (error: Error, data: any) => void): void
6
+ }
7
+
8
+ interface DbusService {
9
+ getInterface(path: string, interfaceName: string, callback: (error: Error, interface: DbusInterface) => void): void
10
+ }
11
+
12
+ interface DbusBus {
13
+ getService(serviceName: string): DbusService
14
+ }
15
+
16
+ function systemBus(): DbusBus
17
+ function sessionBus(): DbusBus
18
+
19
+ export {systemBus, sessionBus}
20
+ export default {systemBus, sessionBus}
21
+
@@ -1,4 +1,4 @@
1
- const Long = require('@homebridge/long');
1
+ const Long = require('long');
2
2
  const parseSignature = require('./signature');
3
3
 
4
4
  // Buffer + position + global start position ( used in alignment )
package/lib/marshall.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const assert = require('assert');
2
2
 
3
3
  const parseSignature = require('./signature');
4
- const put = require('@homebridge/put');
4
+ const put = require('./put');
5
5
  const Marshallers = require('./marshallers');
6
6
  const align = require('./align').align;
7
7
 
@@ -1,7 +1,7 @@
1
1
  const Buffer = require('safe-buffer').Buffer;
2
2
  const align = require('./align').align;
3
3
  const parseSignature = require('../lib/signature');
4
- const Long = require('@homebridge/long');
4
+ const Long = require('long');
5
5
  /**
6
6
  * MakeSimpleMarshaller
7
7
  * @param signature - the signature of the data you want to check
package/lib/put.js ADDED
@@ -0,0 +1,101 @@
1
+ const assert = require('assert');
2
+
3
+ module.exports = Put;
4
+ function Put() {
5
+ if (!(this instanceof Put)) return new Put();
6
+
7
+ var words = [];
8
+ var len = 0;
9
+
10
+ this.put = function (buf) {
11
+ words.push({ buffer: buf });
12
+ len += buf.length;
13
+ return this;
14
+ };
15
+
16
+ this.word8 = function (x) {
17
+ words.push({ bytes: 1, value: x });
18
+ len += 1;
19
+ return this;
20
+ };
21
+
22
+ this.floatle = function (x) {
23
+ words.push({ bytes: 'float', endian: 'little', value: x });
24
+ len += 4;
25
+ return this;
26
+ };
27
+
28
+ [8, 16, 24, 32, 64].forEach(
29
+ function (bits) {
30
+ this['word' + bits + 'be'] = function (x) {
31
+ words.push({ endian: 'big', bytes: bits / 8, value: x });
32
+ len += bits / 8;
33
+ return this;
34
+ };
35
+
36
+ this['word' + bits + 'le'] = function (x) {
37
+ words.push({ endian: 'little', bytes: bits / 8, value: x });
38
+ len += bits / 8;
39
+ return this;
40
+ };
41
+ }.bind(this)
42
+ );
43
+
44
+ this.pad = function (bytes) {
45
+ assert(
46
+ Number.isInteger(bytes),
47
+ 'pad(bytes) must be supplied with an integer!'
48
+ );
49
+ words.push({ endian: 'big', bytes: bytes, value: 0 });
50
+ len += bytes;
51
+ return this;
52
+ };
53
+
54
+ this.length = function () {
55
+ return len;
56
+ };
57
+
58
+ this.buffer = function () {
59
+ var buf = Buffer.alloc(len);
60
+ var offset = 0;
61
+ words.forEach(function (word) {
62
+ if (word.buffer) {
63
+ word.buffer.copy(buf, offset, 0);
64
+ offset += word.buffer.length;
65
+ } else if (word.bytes === 'float') {
66
+ // s * f * 2^e
67
+ var v = Math.abs(word.value);
68
+ var s = (word.value >= 0) * 1;
69
+ var e = Math.ceil(Math.log(v) / Math.LN2);
70
+ var f = v / (1 << e);
71
+ console.dir([s, e, f]);
72
+
73
+ console.log(word.value);
74
+
75
+ // s:1, e:7, f:23
76
+ // [seeeeeee][efffffff][ffffffff][ffffffff]
77
+ buf[offset++] = (s << 7) & ~~(e / 2);
78
+ buf[offset++] = ((e & 1) << 7) & ~~(f / (1 << 16));
79
+ buf[offset++] = 0;
80
+ buf[offset++] = 0;
81
+ offset += 4;
82
+ } else {
83
+ var big = word.endian === 'big';
84
+ var ix = big ? [(word.bytes - 1) * 8, -8] : [0, 8];
85
+
86
+ for (var i = ix[0]; big ? i >= 0 : i < word.bytes * 8; i += ix[1]) {
87
+ if (i >= 32) {
88
+ buf[offset++] = Math.floor(word.value / Math.pow(2, i)) & 0xff;
89
+ } else {
90
+ buf[offset++] = (word.value >> i) & 0xff;
91
+ }
92
+ }
93
+ }
94
+ });
95
+ return buf;
96
+ };
97
+
98
+ this.write = function (stream) {
99
+ stream.write(this.buffer());
100
+ };
101
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@homebridge/dbus-native",
3
3
  "author": "Andrey Sidorov <sidorares@yandex.com>",
4
- "version": "0.6.0",
4
+ "version": "0.7.0",
5
5
  "keywords": [
6
6
  "dbus",
7
7
  "dcop",
@@ -15,7 +15,8 @@
15
15
  "bin/dbus2js.js",
16
16
  "lib/*",
17
17
  "index.js",
18
- "package.json"
18
+ "package.json",
19
+ "index.d.ts"
19
20
  ],
20
21
  "directories": {
21
22
  "lib": "lib",
@@ -38,11 +39,10 @@
38
39
  "dbus2js": "bin/dbus2js.js"
39
40
  },
40
41
  "dependencies": {
41
- "@homebridge/long": "^5.2.1",
42
- "@homebridge/put": "^0.0.8",
43
42
  "event-stream": "^4.0.1",
44
43
  "hexy": "^0.3.5",
45
- "minimist": "^1.2.6",
44
+ "long": "^5.3.2",
45
+ "minimist": "^1.2.8",
46
46
  "safe-buffer": "^5.1.2",
47
47
  "xml2js": "^0.6.2"
48
48
  },
@@ -52,16 +52,16 @@
52
52
  }
53
53
  },
54
54
  "devDependencies": {
55
- "@types/minimist": "^1.2.2",
56
- "eslint": "^8.57.0",
57
- "eslint-config-prettier": "^9.1.0",
58
- "eslint-plugin-markdown": "^4.0.1",
59
- "eslint-plugin-prettier": "^5.1.3",
60
- "husky": "^9.0.11",
61
- "lint-staged": "^15.2.2",
62
- "mocha": "^10.0.0",
63
- "nyc": "^15.1.0",
64
- "prettier": "^3.2.5"
55
+ "@types/minimist": "^1.2.5",
56
+ "eslint": "^8.57.1",
57
+ "eslint-config-prettier": "^10.1.5",
58
+ "eslint-plugin-markdown": "^5.1.0",
59
+ "eslint-plugin-prettier": "^5.4.1",
60
+ "husky": "^9.1.7",
61
+ "lint-staged": "^16.1.0",
62
+ "mocha": "^11.5.0",
63
+ "nyc": "^17.1.0",
64
+ "prettier": "^3.5.3"
65
65
  },
66
66
  "scripts": {
67
67
  "lint": "npm run lint:docs && npm run lint:code",