payload converter fixes
This commit is contained in:
1 parent
15e8e0722d
commit
e2c975178a
4 files changed
+30
-30
No files matched your search
+11
-11
@@ -43,7 +43,7 @@ function Decoder(bytes, port) {
|
||||
|
||||
if (port === 7) {
|
||||
// BME680 sensor data
|
||||
return decode(bytes, [temperature, uint16, humidity, uint16], ['temperature', 'pressure', 'humidity', 'air']);
|
||||
return decode(bytes, [float, ufloat, ufloat, ufloat], ['temperature', 'pressure', 'humidity', 'air']);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -116,9 +116,9 @@ var hdop = function (bytes) {
|
||||
};
|
||||
hdop.BYTES = 2;
|
||||
|
||||
var temperature = function (bytes) {
|
||||
if (bytes.length !== temperature.BYTES) {
|
||||
throw new Error('Temperature must have exactly 2 bytes');
|
||||
var float = function (bytes) {
|
||||
if (bytes.length !== float.BYTES) {
|
||||
throw new Error('Float must have exactly 2 bytes');
|
||||
}
|
||||
var isNegative = bytes[0] & 0x80;
|
||||
var b = ('00000000' + Number(bytes[0]).toString(2)).slice(-8)
|
||||
@@ -139,17 +139,17 @@ var temperature = function (bytes) {
|
||||
}
|
||||
return +(t / 100).toFixed(1);
|
||||
};
|
||||
temperature.BYTES = 2;
|
||||
float.BYTES = 2;
|
||||
|
||||
var humidity = function (bytes) {
|
||||
if (bytes.length !== humidity.BYTES) {
|
||||
throw new Error('Humidity must have exactly 2 bytes');
|
||||
var ufloat = function (bytes) {
|
||||
if (bytes.length !== ufloat.BYTES) {
|
||||
throw new Error('Ufloat must have exactly 2 bytes');
|
||||
}
|
||||
|
||||
var h = bytesToInt(bytes);
|
||||
return +(h / 100).toFixed(1);
|
||||
};
|
||||
humidity.BYTES = 2;
|
||||
ufloat.BYTES = 2;
|
||||
|
||||
var bitmap = function (byte) {
|
||||
if (byte.length !== bitmap.BYTES) {
|
||||
@@ -193,8 +193,8 @@ if (typeof module === 'object' && typeof module.exports !== 'undefined') {
|
||||
uint16: uint16,
|
||||
uint32: uint32,
|
||||
uptime: uptime,
|
||||
temperature: temperature,
|
||||
humidity: humidity,
|
||||
float: float,
|
||||
ufloat: ufloat,
|
||||
latLng: latLng,
|
||||
hdop: hdop,
|
||||
bitmap: bitmap,
|
||||
|
||||
+13
-12
@@ -104,15 +104,16 @@ void PayloadConvert::addBME(bmeStatus_t value) {
|
||||
#ifdef HAS_BME
|
||||
int16_t temperature = (int16_t)(value.temperature); // float -> int
|
||||
uint16_t humidity = (uint16_t)(value.humidity); // float -> int
|
||||
uint16_t pressure = (uint16_t)(value.pressure); // float -> int
|
||||
uint16_t iaq = (uint16_t)(value.iaq); // float -> int
|
||||
buffer[cursor++] = highByte(temperature);
|
||||
buffer[cursor++] = lowByte(temperature);
|
||||
buffer[cursor++] = highByte(value.pressure);
|
||||
buffer[cursor++] = lowByte(value.pressure);
|
||||
buffer[cursor++] = highByte(pressure);
|
||||
buffer[cursor++] = lowByte(pressure);
|
||||
buffer[cursor++] = highByte(humidity);
|
||||
buffer[cursor++] = lowByte(humidity);
|
||||
buffer[cursor++] = highByte(value.iaq);
|
||||
buffer[cursor++] = lowByte(value.iaq);
|
||||
buffer[cursor++] = highByte(iaq);
|
||||
buffer[cursor++] = lowByte(iaq);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -192,10 +193,10 @@ void PayloadConvert::addSensor(uint8_t buf[]) {
|
||||
|
||||
void PayloadConvert::addBME(bmeStatus_t value) {
|
||||
#ifdef HAS_BME
|
||||
writeTemperature(value.temperature);
|
||||
writeUint16(value.pressure);
|
||||
writeHumidity(value.humidity);
|
||||
writeUint16(value.iaq);
|
||||
writeFloat(value.temperature);
|
||||
writeUFloat(value.pressure);
|
||||
writeUFloat(value.humidity);
|
||||
writeUFloat(value.iaq);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -232,7 +233,7 @@ void PayloadConvert::writeUint16(uint16_t i) { intToBytes(cursor, i, 2); }
|
||||
|
||||
void PayloadConvert::writeUint8(uint8_t i) { intToBytes(cursor, i, 1); }
|
||||
|
||||
void PayloadConvert::writeHumidity(float humidity) {
|
||||
void PayloadConvert::writeUFloat(float humidity) {
|
||||
int16_t h = (int16_t)(humidity * 100);
|
||||
intToBytes(cursor, h, 2);
|
||||
}
|
||||
@@ -241,7 +242,7 @@ void PayloadConvert::writeHumidity(float humidity) {
|
||||
* Uses a 16bit two's complement with two decimals, so the range is
|
||||
* -327.68 to +327.67 degrees
|
||||
*/
|
||||
void PayloadConvert::writeTemperature(float temperature) {
|
||||
void PayloadConvert::writeFloat(float temperature) {
|
||||
int16_t t = (int16_t)(temperature * 100);
|
||||
if (temperature < 0) {
|
||||
t = ~-t;
|
||||
@@ -375,7 +376,7 @@ void PayloadConvert::addBME(bmeStatus_t value) {
|
||||
// 0.5% per bit => 0 .. 128 %C
|
||||
uint8_t humidity = (uint8_t)(value.humidity * 2.0);
|
||||
// 0.01 IAQ per bit => 0 .. 655,36 IAQ
|
||||
uint16_t iaq = (uint16_t) value.iaq * 100;
|
||||
uint16_t iaq = (uint16_t)value.iaq * 100;
|
||||
|
||||
#if (PAYLOAD_ENCODER == 3)
|
||||
buffer[cursor++] = LPP_TEMPERATURE_CHANNEL;
|
||||
@@ -395,7 +396,7 @@ void PayloadConvert::addBME(bmeStatus_t value) {
|
||||
buffer[cursor++] = LPP_HUMIDITY; // 1 byte 0.5 % Unsigned
|
||||
buffer[cursor++] = humidity;
|
||||
#if (PAYLOAD_ENCODER == 3)
|
||||
buffer[cursor++] = LPP_GAS_CHANNEL;
|
||||
buffer[cursor++] = LPP_AIR_CHANNEL;
|
||||
#endif
|
||||
buffer[cursor++] = LPP_ANALOG_INPUT; // 2 bytes 0.01 Signed
|
||||
buffer[cursor++] = highByte(iaq);
|
||||
|
||||
Reference in new issue
Block a user