advlib-ble-services
Advanced tools
Comparing version 1.3.2 to 1.3.3
@@ -16,2 +16,3 @@ /** | ||
const PIR_FRAME_LENGTH = 11; | ||
const ILLUMINANCE_FRAME_LENGTH = 11; | ||
const VIBRATION_FRAME_LENGTH = 14; | ||
@@ -32,2 +33,3 @@ const MIN_INFO_FRAME_LENGTH = 9; | ||
const VIBRATION_OFFSET = 7; | ||
const ILLUMINANCE_OFFSET = 3; | ||
const PIR_MASK = 0x0001; | ||
@@ -70,2 +72,4 @@ const VISIBLE_LIGHT_MASK = 0x01; | ||
return processVibration(buf); | ||
case 0x19: | ||
return processIlluminance(buf); | ||
} | ||
@@ -202,2 +206,21 @@ | ||
/** | ||
* Process illuminance service data. | ||
* @param {Object} data The raw service data as a Buffer. | ||
* @return {Object} The processed illuminance data as JSON. | ||
*/ | ||
function processIlluminance(data) { | ||
let isInvalidLength = (data.length !== ILLUMINANCE_FRAME_LENGTH); | ||
if(isInvalidLength) { | ||
return null; | ||
} | ||
let batteryPercentage = data.readUInt8(BATTERY_PERCENTAGE_OFFSET); | ||
let illuminance = data.readUInt16BE(ILLUMINANCE_OFFSET); | ||
return { batteryPercentage: batteryPercentage, illuminance: illuminance, | ||
uri: MINEW_URI }; | ||
} | ||
module.exports.process = process; |
@@ -18,3 +18,3 @@ { | ||
], | ||
"version": "1.3.2", | ||
"version": "1.3.3", | ||
"engines": { | ||
@@ -21,0 +21,0 @@ "node": ">=6.0.0" |
@@ -19,2 +19,3 @@ /** | ||
const INPUT_DATA_VIBRATION = 'a118321234567801aabbccddeeff'; | ||
const INPUT_DATA_ILLUMINANCE = 'a119640ab4aabbccddeeff'; | ||
@@ -55,2 +56,7 @@ | ||
}; | ||
const EXPECTED_DATA_ILLUMINANCE = { | ||
batteryPercentage: 100, | ||
illuminance: 2740, | ||
uri: "https://sniffypedia.org/Organization/Shenzhen_Minew_Technologies_Co_Ltd/" | ||
}; | ||
@@ -107,2 +113,8 @@ | ||
// Test the process function with valid illuminance data | ||
it('should handle valid illuminance data as input', function() { | ||
assert.deepEqual(service.process(INPUT_DATA_ILLUMINANCE), | ||
EXPECTED_DATA_ILLUMINANCE); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57560
1165