Huge News!Announcing our $40M Series B led by Abstract Ventures.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.7 to 1.4.0

173

lib/gatt.js

@@ -26,5 +26,14 @@ /**

const MFD3D_STRUCT_LENGTH = 6;
const LANGUAGE_STRUCT_LENGTH = 2; // Assumes ISO 639-1 two-character codes only
const GENERIC_LEVEL_STRUCT_LENGTH = 2;
const ILLUMINANCE_STRUCT_LENGTH = 3;
const ILLUMINANCE_UNKNOWN_VALUE = 167772.15;
const CO2_CONCENTRATION_STRUCT_LENGTH = 2;
const CO2_CONCENTRATION_UNKNOWN_VALUE = 0xffff;
const AMMONIA_CONCENTRATION_STRUCT_LENGTH = 2;
const CARBON_MONOXIDE_CONCENTRATION_STRUCT_LENGTH = 2;
const METHANE_CONCENTRATION_STRUCT_LENGTH = 2;
const NO2_CONCENTRATION_STRUCT_LENGTH = 2;
const VOC_CONCENTRATION_STRUCT_LENGTH = 2;
const VOC_CONCENTRATION_UNKNOWN_VALUE = 0xffff;

@@ -58,6 +67,20 @@

return processMagneticFluxDensity3D(buf);
case '2aa2':
return processLanguage(buf);
case '2af9':
return processGenericLevel(buf);
case '2afb':
return processIlluminance(buf);
case '2b8c':
return processCarbonDioxideConcentration(buf);
case '2bcf':
return processAmmoniaConcentration(buf);
case '2bd0':
return processCarbonMonoxideConcentration(buf);
case '2bd1':
return processMethaneConcentration(buf);
case '2bd2':
return processNitrogenDioxideConcentration(buf);
case '2be7':
return processVolatileOrganicCompoundsConcentration(buf);
}

@@ -257,2 +280,36 @@

/**
* Process language data.
* @param {Object} data The raw service data as a Buffer.
* @return {Object} The processed language data as JSON.
*/
function processLanguage(data) {
let isInvalidLength = (data.length !== LANGUAGE_STRUCT_LENGTH);
if(isInvalidLength) {
return null;
}
let language = data.toString('utf-8', 0, 2);
return { language: language };
}
/**
* Process generic level data.
* @param {Object} data The raw service data as a Buffer.
* @return {Object} The processed generic level data as JSON.
*/
function processGenericLevel(data) {
let isInvalidLength = (data.length !== GENERIC_LEVEL_STRUCT_LENGTH);
if(isInvalidLength) {
return null;
}
let levelPercentage = 100 * data.readUIntLE(0, 2) / 65535;
return { levelPercentage: levelPercentage };
}
/**
* Process illuminance data.

@@ -279,2 +336,23 @@ * @param {Object} data The raw service data as a Buffer.

/**
* Process carbon dioxide concentration data.
* @param {Object} data The raw service data as a Buffer.
* @return {Object} The processed cardbon dioxide concentration data as JSON.
*/
function processCarbonDioxideConcentration(data) {
let isInvalidLength = (data.length !== CO2_CONCENTRATION_STRUCT_LENGTH);
if(isInvalidLength) {
return null;
}
let carbonDioxideConcentration = data.readUIntLE(0, 2);
if(carbonDioxideConcentration === CO2_CONCENTRATION_UNKNOWN_VALUE) {
return null;
}
return { carbonDioxideConcentration: carbonDioxideConcentration };
}
/**
* Process ammonia concentration data.

@@ -293,2 +371,6 @@ * @param {Object} data The raw service data as a Buffer.

if(!Number.isFinite(ammoniaConcentration)) {
return null;
}
return { ammoniaConcentration: ammoniaConcentration };

@@ -298,2 +380,93 @@ }

/**
* Process carbon monoxide concentration data.
* @param {Object} data The raw service data as a Buffer.
* @return {Object} The processed carbon monoxide concentration data as JSON.
*/
function processCarbonMonoxideConcentration(data) {
let isInvalidLength =
(data.length !== CARBON_MONOXIDE_CONCENTRATION_STRUCT_LENGTH);
if(isInvalidLength) {
return null;
}
// Convert units: 1 kg/m3 = 1000 ppm
let carbonMonoxideConcentration = utils.parseMedfloat16(data) * 1000;
if(!Number.isFinite(carbonMonoxideConcentration)) {
return null;
}
return { carbonMonoxideConcentration: carbonMonoxideConcentration };
}
/**
* Process methane concentration data.
* @param {Object} data The raw service data as a Buffer.
* @return {Object} The processed methane concentration data as JSON.
*/
function processMethaneConcentration(data) {
let isInvalidLength = (data.length !== METHANE_CONCENTRATION_STRUCT_LENGTH);
if(isInvalidLength) {
return null;
}
// Convert units: 1000 ppb = 1 ppm
let methaneConcentration = utils.parseMedfloat16(data) / 1000;
if(!Number.isFinite(methaneConcentration)) {
return null;
}
return { methaneConcentration: methaneConcentration };
}
/**
* Process nitrogen dioxide concentration data.
* @param {Object} data The raw service data as a Buffer.
* @return {Object} The processed nitrogen dioxide concentration data as JSON.
*/
function processNitrogenDioxideConcentration(data) {
let isInvalidLength = (data.length !== NO2_CONCENTRATION_STRUCT_LENGTH);
if(isInvalidLength) {
return null;
}
// Convert units: 1 kg/m3 = 1000 ppm
let nitrogenDioxideConcentration = utils.parseMedfloat16(data) * 1000;
if(!Number.isFinite(nitrogenDioxideConcentration)) {
return null;
}
return { nitrogenDioxideConcentration: nitrogenDioxideConcentration };
}
/**
* Process volatile organic compounds concentration data.
* @param {Object} data The raw service data as a Buffer.
* @return {Object} The processed VOC concentration data as JSON.
*/
function processVolatileOrganicCompoundsConcentration(data) {
let isInvalidLength = (data.length !== VOC_CONCENTRATION_STRUCT_LENGTH);
if(isInvalidLength) {
return null;
}
let concentration = data.readUIntLE(0, 2);
if(concentration === VOC_CONCENTRATION_UNKNOWN_VALUE) {
return null;
}
// Convert units: 1000 ppb = 1 ppm
concentration = concentration / 1000;
return { volatileOrganicCompoundsConcentration: concentration };
}
module.exports.process = process;

2

package.json

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

],
"version": "1.3.7",
"version": "1.4.0",
"engines": {

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

@@ -6,2 +6,4 @@ advlib-ble-services

![Overview of advlib-ble-services](https://reelyactive.github.io/advlib-ble-services/images/overview.png)
__advlib-ble-services__ is a lightweight [Node.js package](https://www.npmjs.com/package/advlib-ble-services) with no dependencies. See also its sister library [advlib-ble-manufacturers](https://github.com/reelyactive/advlib-ble-manufacturers).

@@ -40,16 +42,23 @@

| Service UUID | Service Name | /lib file |
|:-------------|:-------------------------|:-------------------------|
| 0x2a37 | Heart Rate Measurement | gatt.js |
| 0x2a67 | Location and Speed | gatt.js |
| 0x2a6c | Elevation | gatt.js |
| 0x2a6d | Pressure | gatt.js |
| 0x2a6e | Temperature | gatt.js |
| 0x2aa1 | Magnetic flux density 3D | gatt.js |
| 0x2afb | Illuminance | gatt.js |
| 0x2bcf | Ammonia concentration | gatt.js |
| 0xfd6f | Exposure Notification | exposurenotification.js |
| 0xfdaf | Wiliot | wiliot.js |
| 0xfeaa | Eddystone (Google) | eddystone.js |
| 0xffe1 | Minew | minew.js |
| Service UUID | Service Name | /lib file |
|:-------------|:------------------------------|:-------------------------|
| 0x2a37 | Heart Rate Measurement | gatt.js |
| 0x2a67 | Location and Speed | gatt.js |
| 0x2a6c | Elevation | gatt.js |
| 0x2a6d | Pressure | gatt.js |
| 0x2a6e | Temperature | gatt.js |
| 0x2aa1 | Magnetic flux density 3D | gatt.js |
| 0x2aa2 | Language | gatt.js |
| 0x2af9 | Generic Level | gatt.js |
| 0x2afb | Illuminance | gatt.js |
| 0x2b8c | CO2 Concentration | gatt.js |
| 0x2bcf | Ammonia Concentration | gatt.js |
| 0x2bd0 | Carbon Monoxide Concentration | gatt.js |
| 0x2bd1 | Methane Concentration | gatt.js |
| 0x2bd2 | NO2 Concentration | gatt.js |
| 0x2be7 | VOC Concentration | gatt.js |
| 0xfd6f | Exposure Notification | exposurenotification.js |
| 0xfdaf | Wiliot | wiliot.js |
| 0xfeaa | Eddystone (Google) | eddystone.js |
| 0xffe1 | Minew | minew.js |

@@ -78,2 +87,3 @@ Consult the [Bluetooth Assigned Numbers](https://www.bluetooth.com/specifications/assigned-numbers/) page for the most recent 16-bit UUIDs document.

| Minew | MSL01 | minew.js |
| Arduino | Nicla Vision ([Tutorial](https://reelyactive.github.io/diy/nicla-vision-dev/)) | gatt.js |

@@ -80,0 +90,0 @@

@@ -33,7 +33,23 @@ /**

const INPUT_UUID_MFD3D = '2aa1';
const INPUT_DATA_LANGUAGE = '6672';
const INPUT_UUID_LANGUAGE = '2aa2';
const INPUT_DATA_GENERIC_LEVEL = '971f';
const INPUT_UUID_GENERIC_LEVEL = '2af9';
const INPUT_DATA_ILLUMINANCE_UNKNOWN = 'ffffff';
const INPUT_DATA_ILLUMINANCE = 'a08601';
const INPUT_UUID_ILLUMINANCE = '2afb';
const INPUT_DATA_CO2_CONCENTRATION_UNKNOWN = 'ffff';
const INPUT_DATA_CO2_CONCENTRATION = 'de03';
const INPUT_UUID_CO2_CONCENTRATION = '2b8c';
const INPUT_DATA_AMMONIA_CONCENTRATION = '7bb0';
const INPUT_UUID_AMMONIA_CONCENTRATION = '2bcf';
const INPUT_DATA_CARBON_MONOXIDE_CONCENTRATION = '9ad2';
const INPUT_UUID_CARBON_MONOXIDE_CONCENTRATION = '2bd0';
const INPUT_DATA_METHANE_CONCENTRATION = '7b30';
const INPUT_UUID_METHANE_CONCENTRATION = '2bd1';
const INPUT_DATA_NO2_CONCENTRATION = '9ad2';
const INPUT_UUID_NO2_CONCENTRATION = '2bd2';
const INPUT_DATA_VOC_CONCENTRATION_UNKNOWN = 'ffff';
const INPUT_DATA_VOC_CONCENTRATION = 'de03';
const INPUT_UUID_VOC_CONCENTRATION = '2be7';

@@ -71,3 +87,16 @@

const EXPECTED_DATA_ILLUMINANCE = { illuminance: 1000 };
const EXPECTED_DATA_LANGUAGE = { language: "fr" };
const EXPECTED_DATA_GENERIC_LEVEL = { levelPercentage: 12.339971007858397 };
const EXPECTED_DATA_CO2_CONCENTRATION_UNKNOWN = null;
const EXPECTED_DATA_CO2_CONCENTRATION = { carbonDioxideConcentration: 990 };
const EXPECTED_DATA_AMMONIA_CONCENTRATION = { ammoniaConcentration: 1.23 };
const EXPECTED_DATA_CARBON_MONOXIDE_CONCENTRATION = {
carbonMonoxideConcentration: 666
};
const EXPECTED_DATA_METHANE_CONCENTRATION = { methaneConcentration: 123 };
const EXPECTED_DATA_NO2_CONCENTRATION = { nitrogenDioxideConcentration: 666 };
const EXPECTED_DATA_VOC_CONCENTRATION_UNKNOWN = null;
const EXPECTED_DATA_VOC_CONCENTRATION = {
volatileOrganicCompoundsConcentration: 0.99
};

@@ -176,2 +205,14 @@

// Test the process function with language data
it('should handle language data as input', function() {
assert.deepEqual(service.process(INPUT_DATA_LANGUAGE,
INPUT_UUID_LANGUAGE), EXPECTED_DATA_LANGUAGE);
});
// Test the process function with generic level data
it('should handle generic level data as input', function() {
assert.deepEqual(service.process(INPUT_DATA_GENERIC_LEVEL,
INPUT_UUID_GENERIC_LEVEL), EXPECTED_DATA_GENERIC_LEVEL);
});
// Test the process function with unknown illuminance data

@@ -190,2 +231,16 @@ it('should handle unknown illuminance data as input', function() {

// Test the process function with unknown CO2 concentration data
it('should handle unknown CO2 concentration data as input', function() {
assert.deepEqual(service.process(INPUT_DATA_CO2_CONCENTRATION_UNKNOWN,
INPUT_UUID_CO2_CONCENTRATION),
EXPECTED_DATA_CO2_CONCENTRATION_UNKNOWN);
});
// Test the process function with CO2 concentration data
it('should handle CO2 concentration data as input', function() {
assert.deepEqual(service.process(INPUT_DATA_CO2_CONCENTRATION,
INPUT_UUID_CO2_CONCENTRATION),
EXPECTED_DATA_CO2_CONCENTRATION);
});
// Test the process function with ammonia concentration data

@@ -198,2 +253,37 @@ it('should handle ammonia concentration data as input', function() {

// Test the process function with carbon monoxide concentration data
it('should handle carbon monoxide concentration data as input', function() {
assert.deepEqual(service.process(INPUT_DATA_CARBON_MONOXIDE_CONCENTRATION,
INPUT_UUID_CARBON_MONOXIDE_CONCENTRATION),
EXPECTED_DATA_CARBON_MONOXIDE_CONCENTRATION);
});
// Test the process function with methane concentration data
it('should handle methane concentration data as input', function() {
assert.deepEqual(service.process(INPUT_DATA_METHANE_CONCENTRATION,
INPUT_UUID_METHANE_CONCENTRATION),
EXPECTED_DATA_METHANE_CONCENTRATION);
});
// Test the process function with NO2 concentration data
it('should handle NO2 concentration data as input', function() {
assert.deepEqual(service.process(INPUT_DATA_NO2_CONCENTRATION,
INPUT_UUID_NO2_CONCENTRATION),
EXPECTED_DATA_NO2_CONCENTRATION);
});
// Test the process function with unknown VOC concentration data
it('should handle unknown VOC concentration data as input', function() {
assert.deepEqual(service.process(INPUT_DATA_VOC_CONCENTRATION_UNKNOWN,
INPUT_UUID_VOC_CONCENTRATION),
EXPECTED_DATA_VOC_CONCENTRATION_UNKNOWN);
});
// Test the process function with VOC concentration data
it('should handle VOC concentration data as input', function() {
assert.deepEqual(service.process(INPUT_DATA_VOC_CONCENTRATION,
INPUT_UUID_VOC_CONCENTRATION),
EXPECTED_DATA_VOC_CONCENTRATION);
});
});
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