diff --git a/package-lock.json b/package-lock.json index 57fdb22..dd7e002 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3763,6 +3763,11 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + }, "node_modules/lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", @@ -6176,6 +6181,9 @@ "name": "aas-lib", "version": "0.1.0", "license": "ISC", + "dependencies": { + "lodash": "^4.17.21" + }, "devDependencies": {} }, "packages/webui": { diff --git a/packages/lib/index.js b/packages/lib/index.js index 40e8f54..a730eac 100644 --- a/packages/lib/index.js +++ b/packages/lib/index.js @@ -1,10 +1,11 @@ /* eslint-disable no-bitwise */ +const _ = require('lodash'); + class Console { constructor() { this.sportInitialized = false; this.state = { time: {}, - auxTime: {}, home: {}, guest: {}, }; @@ -70,7 +71,8 @@ class Console { break; case 0x59: this.sport = 'whirley'; - throw new Error('Whirley is not implemented'); + this.parseWhirley(); + break; case 0x67: this.sport = 'segment'; throw new Error('Segment is not implemented'); @@ -94,7 +96,13 @@ class Console { } this.state.auxTime = this.latestPacket.buffer.subarray(8, 9).toString('hex'); + if (this.state.auxTime === 'aa') { + this.state.auxTime = ''; + } this.state.aux2Time = this.latestPacket.buffer.subarray(9, 10).toString('hex'); + if (this.state.aux2Time === 'aa') { + this.state.aux2Time = ''; + } const hornBinaryFlags = this.latestPacket.buffer.at(4).toString(2).padStart(8, '0'); this.state.horn = hornBinaryFlags[0] === '1'; @@ -440,6 +448,26 @@ class Console { } } + parseWhirley() { + if (!this.sportInitialized) { + this.sportInitialized = true; + } + const propertiesToDelete = [ + 'home.timeouts', + 'guest.timeouts', + 'home.bonus', + 'guest.bonus', + 'home.doubleBonus', + 'guest.doubleBonus', + 'auxTime', + 'aux2Time', + ]; + + this.state.key = this.state.aux2Time; + + this.state = _.omit(this.state, propertiesToDelete); + } + /** * * @param {number} packedNumber diff --git a/packages/lib/package.json b/packages/lib/package.json index a450c7a..8966afb 100644 --- a/packages/lib/package.json +++ b/packages/lib/package.json @@ -3,10 +3,12 @@ "version": "0.1.0", "description": "", "main": "index.js", - "devDependencies": {}, "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", - "license": "ISC" + "license": "ISC", + "dependencies": { + "lodash": "^4.17.21" + } }