New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

advlib-ble-services

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

advlib-ble-services - npm Package Compare versions

Comparing version 1.3.4 to 1.3.5

23

lib/gatt.js
/**
* Copyright reelyActive 2015-2021
* Copyright reelyActive 2015-2023
* We believe in an open Internet of Things

@@ -28,2 +28,3 @@ */

const ILLUMINANCE_UNKNOWN_VALUE = 167772.15;
const AMMONIA_CONCENTRATION_STRUCT_LENGTH = 2;

@@ -59,2 +60,4 @@

return processIlluminance(buf);
case '2bcf':
return processAmmoniaConcentration(buf);
}

@@ -274,2 +277,20 @@

/**
* Process ammonia concentration data.
* @param {Object} data The raw service data as a Buffer.
* @return {Object} The processed ammonia concentration data as JSON.
*/
function processAmmoniaConcentration(data) {
let isInvalidLength = (data.length !== AMMONIA_CONCENTRATION_STRUCT_LENGTH);
if(isInvalidLength) {
return null;
}
// Convert units: 1 kg/m3 = 1000 ppm
let ammoniaConcentration = utils.parseMedfloat16(data) * 1000;
return { ammoniaConcentration: ammoniaConcentration };
}
module.exports.process = process;
/**
* Copyright reelyActive 2015-2020
* Copyright reelyActive 2015-2023
* We believe in an open Internet of Things

@@ -92,2 +92,70 @@ */

/**
* Convert the given medfloat16 Buffer to a floating point Number.
* @param {Buffer} data The medfloat16 Buffer data to convert.
* @return {Number} The floating point representation as a Number.
*/
function parseMedfloat16(data) {
let value = data.readUInt16LE();
switch(value) {
case 0x07ff:
return Number.NaN;
case 0x07fe:
return Number.POSITIVE_INFINITY;
case 0x0802:
return Number.NEGATIVE_INFINITY;
case 0x0801:
case 0x0800:
return null;
}
let mantissa = value & 0x0fff;
let exponent = value >> 12;
if(mantissa >= 0x0800) {
mantissa = mantissa - 0x1000;
}
if(exponent >= 0x8) {
exponent = exponent - 0x10;
}
return mantissa * Math.pow(10, exponent);
}
/**
* Convert the given medfloat32 Buffer to a floating point Number.
* @param {Buffer} data The medfloat32 Buffer data to convert.
* @return {Number} The floating point representation as a Number.
*/
function parseMedfloat32(data) {
let value = data.readUInt32LE();
switch(value) {
case 0x007fffff:
return Number.NaN;
case 0x007ffffe:
return Number.POSITIVE_INFINITY;
case 0x00800002:
return Number.NEGATIVE_INFINITY;
case 0x00800001:
case 0x00800000:
return null;
}
let mantissa = value & 0x00ffffff;
let exponent = value >> 24;
if(mantissa >= 0x00800000) {
mantissa = mantissa - 0x1000000;
}
if(exponent >= 0x80) {
exponent = exponent - 0x100;
}
return mantissa * Math.pow(10, exponent);
}
module.exports.SIGNATURE_SEPARATOR = SIGNATURE_SEPARATOR;

@@ -97,2 +165,4 @@ module.exports.convertToBuffer = convertToBuffer;

module.exports.convertToHexString = convertToHexString;
module.exports.parseSigned88 = parseSigned88;
module.exports.parseSigned88 = parseSigned88;
module.exports.parseMedfloat16 = parseMedfloat16;
module.exports.parseMedfloat32 = parseMedfloat32;

2

package.json

@@ -18,3 +18,3 @@ {

],
"version": "1.3.4",
"version": "1.3.5",
"engines": {

@@ -21,0 +21,0 @@ "node": ">=6.0.0"

@@ -48,2 +48,3 @@ advlib-ble-services

| 0x2afb | Illuminance | gatt.js |
| 0x2bcf | Ammonia concentration | gatt.js |
| 0xfd6f | Exposure Notification | exposurenotification.js |

@@ -95,3 +96,3 @@ | 0xfdaf | Wiliot | wiliot.js |

Copyright (c) 2015-2022 [reelyActive](https://www.reelyactive.com)
Copyright (c) 2015-2023 [reelyActive](https://www.reelyactive.com)

@@ -98,0 +99,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

@@ -36,2 +36,4 @@ /**

const INPUT_UUID_ILLUMINANCE = '2afb';
const INPUT_DATA_AMMONIA_CONCENTRATION = '7bb0';
const INPUT_UUID_AMMONIA_CONCENTRATION = '2bcf';

@@ -69,2 +71,3 @@

const EXPECTED_DATA_ILLUMINANCE = { illuminance: 1000 };
const EXPECTED_DATA_AMMONIA_CONCENTRATION = { ammoniaConcentration: 1.23 };

@@ -186,2 +189,9 @@

// Test the process function with ammonia concentration data
it('should handle ammonia concentration data as input', function() {
assert.deepEqual(service.process(INPUT_DATA_AMMONIA_CONCENTRATION,
INPUT_UUID_AMMONIA_CONCENTRATION),
EXPECTED_DATA_AMMONIA_CONCENTRATION);
});
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc