Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions vendors/browan/codecs/browan-industrial-tracker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//Browan version:1.0.1
function decodeUplink(input) {
let decoded = {};
switch (input.fPort) {
case 136:
decoded.MovingMode = ((input.bytes[0] - ((input.bytes[0] >> 4) * 16)) % 8) % 2;
decoded.NoGNSSFix = (input.bytes[0] - ((input.bytes[0] >> 4) * 16)) >> 3;
decoded.GNSSerror = (input.bytes[0] >> 4);
decoded.battery_volt = (25 + (input.bytes[1] - ((input.bytes[1] >> 4) * 16))) / 10;
decoded.temperature = input.bytes[2] - 32;
let int_lat = (input.bytes[3] + input.bytes[4] * 256 + input.bytes[5] * 65536 + (input.bytes[6] - ((input.bytes[6] >> 4))) * 16777216);
let int_lon = (input.bytes[7] + input.bytes[8] * 256 + input.bytes[9] * 65536 + (input.bytes[10] - (((input.bytes[10] >> 5) << 1) * 16)) * 16777216);
let bit_lon = ((input.bytes[10] >> 4) % 2);
decoded.accuracy = Math.pow(2, ((input.bytes[10] >> 5) + 2));
decoded.latitude = twocomplement_Lat(int_lat, 27) / 1000000;
decoded.longitude = twocomplement_Long(bit_lon, int_lon, 28) / 1000000;
decoded.altitude = 2;
// Decoded data
return {data: decoded};
}
}

function twocomplement_Lat(inputNum, comtimes) {
let count02 = (Math.pow(2, comtimes + 1)) - 1;
let final_Lat;
if ((inputNum >> comtimes) == 0) {
final_Lat = inputNum;
return final_Lat;
} else {
final_Lat = -(inputNum ^ count02) - 1;
return final_Lat;
}
}

function twocomplement_Long(firstbit, inputNum, comtimes) {
let count02 = (Math.pow(2, comtimes + 1)) - 1;
let final_Long;
if (firstbit == 0) {
final_Long = inputNum;
return final_Long;
} else {
final_Long = -(inputNum ^ count02) - 1;
return final_Long;
}
}

/**
* Encode downlink function.
*
* @param {object} input
* @param {object} input.data Object representing the payload that must be encoded.
* @param {Record<string, string>} input.variables Object containing the configured device variables.
*
* @returns {{bytes: number[]}} Byte array containing the downlink payload.
*/
function encodeDownlink(input) {
return {
// bytes: [225, 230, 255, 0]
};
}
117 changes: 117 additions & 0 deletions vendors/browan/codecs/merryiot-cd10.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
////////////* MerryIot CO2 sensor*////////////

//hex to binary function
function hex2bin(hex){
return (parseInt(hex, 16).toString(2)).padStart(8, '0');
}

//MerryIot CO2 sensor
function decodeUplink(input) {
let fPort = input.fPort;
let payloadlens = input.bytes.length;
if(fPort==127 && payloadlens==7){
let intput_list = input.bytes;
let battery_int = intput_list[1];
let battery_volt = (21 + battery_int) / 10;

let temperature_hex = intput_list[3].toString(16).padStart(2, '0') + intput_list[2].toString(16).padStart(2, '0');
let temperature_val = parseInt(temperature_hex, 16);
let temperature = temperature_val > 1250 ? (temperature_val - 65536) / 10 : temperature_val / 10;

let humidity = intput_list[4];

let co2_hex = intput_list[0].toString(16).padStart(2, '0');
let co2_binary = hex2bin(co2_hex);
let trigger_st = co2_binary.substring(7, 8);
let button_st = co2_binary.substring(6, 7);
let co2threshold_st = co2_binary.substring(3, 4);
let co2calibration_st = co2_binary.substring(2, 3);

let trigger = parseInt(trigger_st);
let button = parseInt(button_st);
let co2threshold = parseInt(co2threshold_st);
let co2calibration = parseInt(co2calibration_st);

let co2ppm_hex = intput_list[6].toString(16).padStart(2, '0') + intput_list[5].toString(16).padStart(2, '0');
let co2_ppm = parseInt(co2ppm_hex, 16);
co2_ppm = co2_ppm < 0 ? 0 : co2_ppm > 40000 ? 40000 : co2_ppm;

return {
data: {
battery_volt,
temperature,
humidity,
trigger,
button,
co2threshold,
co2calibration,
co2_ppm
},
};
}
else if (fPort==127 && payloadlens==6){
let intput_list = input.bytes;
let battery_int = intput_list[1];
let battery_volt = (21 + battery_int) / 10;

let temperature_int = intput_list[2];
let temperature = temperature_int > 125 ? temperature_int - 256 : temperature_int;

let humidity = intput_list[3];

let co2_hex = intput_list[0].toString(16).padStart(2, '0');
let co2_binary = hex2bin(co2_hex);
let trigger_st = co2_binary.substring(7, 8);
let button_st = co2_binary.substring(6, 7);
let co2threshold_st = co2_binary.substring(3, 4);
let co2calibration_st = co2_binary.substring(2, 3);

let trigger = parseInt(trigger_st);
let button = parseInt(button_st);
let co2threshold = parseInt(co2threshold_st);
let co2calibration = parseInt(co2calibration_st);

let co2ppm_hex = intput_list[5].toString(16).padStart(2, '0') + intput_list[4].toString(16).padStart(2, '0');
let co2_ppm = parseInt(co2ppm_hex, 16);
co2_ppm = co2_ppm < 0 ? 0 : co2_ppm > 40000 ? 40000 : co2_ppm;

return {
data: {
battery_volt,
temperature,
humidity,
trigger,
button,
co2threshold,
co2calibration,
co2_ppm
},
};
}
else{
return {
data: {
fPort: input.fPort,
payloadlength: input.bytes.length,
message: 'Invalid fPort or payload length'
},
};
}
}

////////////* MerryIot CO2 sensor End !!*////////////

/**
* Encode downlink function.
*
* @param {object} input
* @param {object} input.data Object representing the payload that must be encoded.
* @param {Record<string, string>} input.variables Object containing the configured device variables.
*
* @returns {{bytes: number[]}} Byte array containing the downlink payload.
*/
function encodeDownlink(input) {
return {
// bytes: [225, 230, 255, 0]
};
}
128 changes: 128 additions & 0 deletions vendors/browan/codecs/merryiot-dw10.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
////////////* MerryIot Open/Close sensor*////////////

//hex to binary function
function hex2bin(hex){
return (parseInt(hex, 16).toString(2)).padStart(8, '0');
}

//MerryIot Open/Close sensor
function decodeUplink(input) {
let fPort = input.fPort;
let payloadlens = input.bytes.length;
if(fPort==120 && payloadlens==10){
let intput_list = input.bytes;
let battery_int = intput_list[1];
let battery_volt = (21 + battery_int) / 10;

let temperature_hex = intput_list[3].toString(16).padStart(2, '0') + intput_list[2].toString(16).padStart(2, '0');
let temperature_val = parseInt(temperature_hex, 16);
let temperature = temperature_val > 1250 ? (temperature_val - 65536) / 10 : temperature_val / 10;

let humi = intput_list[4];

let door_hex = intput_list[0].toString(16).padStart(2, '0');
let door_binary = hex2bin(door_hex);
let open_st = door_binary.substring(7, 8);
let button_st = door_binary.substring(6, 7);
let tamper_st = door_binary.substring(5, 6);
let tilt_st = door_binary.substring(4, 5);

let open = parseInt(open_st);
let button = parseInt(button_st);
let tamper = parseInt(tamper_st);
let tilt = parseInt(tilt_st);

let time_hex = intput_list[6].toString(16).padStart(2, '0') + intput_list[5].toString(16).padStart(2, '0');
let time = parseInt(time_hex, 16);

let count_hex = intput_list[9].toString(16).padStart(2, '0') + intput_list[8].toString(16) + intput_list[7].toString(16).padStart(2, '0');
let count = parseInt(count_hex, 16);

return {
data: {
battery_volt,
temperature,
humi,
open,
button,
tamper,
tilt,
time,
count
},
};
}
else if (fPort==120 && payloadlens==9){
let intput_list = input.bytes;
let battery_int = intput_list[1];
let battery_volt = (21 + battery_int) / 10;

let temperature_int = intput_list[2];
let temperature;
if(temperature_int > 125){
temperature = temperature_int - 256;
} else {
temperature = temperature_int;
}

let humi = intput_list[3];

let door_hex = intput_list[0].toString(16).padStart(2, '0');
let door_binary = hex2bin(door_hex);
let open_st = door_binary.substring(7, 8);
let button_st = door_binary.substring(6, 7);
let tamper_st = door_binary.substring(5, 6);
let tilt_st = door_binary.substring(4, 5);

let open = parseInt(open_st);
let button = parseInt(button_st);
let tamper = parseInt(tamper_st);
let tilt = parseInt(tilt_st);

let time_hex = intput_list[5].toString(16).padStart(2, '0') + intput_list[4].toString(16).padStart(2, '0');
let time = parseInt(time_hex, 16);

let count_hex = intput_list[8].toString(16).padStart(2, '0') + intput_list[7].toString(16).padStart(2, '0') + intput_list[6].toString(16).padStart(2, '0');
let count = parseInt(count_hex, 16);

return {
data: {
battery_volt,
temperature,
humi,
open,
button,
tamper,
tilt,
time,
count
},
};
}
else{
return {
data: {
fPort: input.fPort,
payloadlength: input.bytes.length,
message: 'Invalid fPort or payload length'
},
};
}
}

////////////* MerryIot Open/Close sensor End !!*////////////

/**
* Encode downlink function.
*
* @param {object} input
* @param {object} input.data Object representing the payload that must be encoded.
* @param {Record<string, string>} input.variables Object containing the configured device variables.
*
* @returns {{bytes: number[]}} Byte array containing the downlink payload.
*/
function encodeDownlink(input) {
return {
// bytes: [225, 230, 255, 0]
};
}
44 changes: 44 additions & 0 deletions vendors/browan/codecs/tabs-tbhh100.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
function decodeUplink(input) {
const bytes = input.bytes;
const fPort = input.fPort;
const len = bytes.length;

if (fPort === 222 && len === 17) {
const hex = bytes.map(b => b.toString(16).padStart(2, '0')).join('');
const bootloader = hex.slice(2, 10).match(/../g).reverse().join('');
const HW_ID = hex.slice(10, 18).match(/../g).reverse().join('');
const FW_CRC = hex.slice(18, 26).match(/../g).reverse().join('');
return { data: { fPort, bootloader, HW_ID, FW_CRC } };
}
else if (fPort === 204 && len === 12) {
const hex = bytes.map(b => b.toString(16).padStart(2, '0')).join('');
const thh_keepalive = parseInt(hex.slice(2, 6).match(/../g).reverse().join(''), 16);
const thh_Monitor = parseInt(hex.slice(8, 12).match(/../g).reverse().join(''), 16);
const thh_temptrig = bytes[7];
const thh_rhtrig = bytes[9];
return { data: { fPort, len, thh_keepalive, thh_Monitor, thh_temptrig, thh_rhtrig } };
}
else if (fPort === 103 && len === 8) {
const battery_volt = (25 + (bytes[1] & 0x0F)) / 10;
const temperature = (bytes[2] & 0x7F) - 32;
const humidity = bytes[3] & 0x3F;
const thh_type = (bytes[0] >> 4) & 0x01;
return { data: { fPort, battery_volt, temperature, humidity, thh_type, CO2: 0, VOC: 0 } };
}
return { data: { fPort, payloadlength: len, message: 'Invalid fPort or payload length' } };
}

/**
* Encode downlink function.
*
* @param {object} input
* @param {object} input.data Object representing the payload that must be encoded.
* @param {Record<string, string>} input.variables Object containing the configured device variables.
*
* @returns {{bytes: number[]}} Byte array containing the downlink payload.
*/
function encodeDownlink(input) {
return {
// bytes: [225, 230, 255, 0]
};
}
Loading
Loading