Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ra02 g r603 #815

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
64 changes: 61 additions & 3 deletions vendor/netvox/payload/r315.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,67 @@ function decodeUplink(input) {
data.Humi = input.bytes[10]*0.5;
}
}
else if (input.bytes[2] == 0x02)
data.Illuminance = (input.bytes[4]<<8 | input.bytes[5]);

else if (input.bytes[2] == 0x02){
data.Illuminance = (input.bytes[4]<<8 | input.bytes[5])+"Lux";
data.LowTemperatureAlarm = input.bytes[6] & 1;
data.HighTemperatureAlarm = input.bytes[6]>>1 & 1;
data.LowHumidityAlarm = input.bytes[6]>>2 & 1;
data.HighHumidityAlarm = input.bytes[6]>>3 & 1;
data.LowIlluminanceAlarm = input.bytes[6]>>4 & 1;
data.HighIlluminanceAlarm = input.bytes[6]>>5 & 1;
}
else if(input.bytes[2] == 0x011){
let FunctionEnable = (input.bytes[5]<<8 |input.bytes[6]);
data.THSensor = FunctionEnable & 1;
data.LightSensor = FunctionEnable>>1 & 1;
data.PIRSensor = FunctionEnable>>2 & 1;
data.EmergenceButton = FunctionEnable>>3 & 1;
data.TiltSensor = FunctionEnable>>4 & 1;
data.InternalContactSwitch = FunctionEnable>>5 & 1;
data.ExternalContactSwitch1 = FunctionEnable>>6 & 1;
data.ExternalContactSwitch2 = FunctionEnable>>7 & 1;
data.InternalShockSensor = FunctionEnable>>8 & 1;
data.ExternalShockSensor = FunctionEnable>>9 & 1;
data.ExternalDryContactPointIN = FunctionEnable>>10 & 1;
data.DryContactPointOut = FunctionEnable>>11 & 1;
data.ExternalWaterLeakSenor1 = FunctionEnable>>12 & 1;
data.ExternalWaterLeakSenor2 = FunctionEnable>>13 & 1;
data.ExternalSeatSensor = FunctionEnable>>14 & 1;
data.ExternalGlassSensor1 = FunctionEnable>>15 & 1;
data.ExternalGlassSensor2 = input.bytes[4]& 1;

let BinarySensorReport = (input.bytes[7]<<8 | input.bytes[8]);
data.PIRSensorState = BinarySensorReport & 1;
data.EmergenceButtonaLAlarmState = BinarySensorReport>>1 & 1;
data.TiltSensorState = BinarySensorReport>>2 & 1;
data.InternalContactSwitchSensorState = BinarySensorReport>>3 & 1;
data.ExternalContactSwitch1SensorState = BinarySensorReport>>4 & 1;
data.ExternalContactSwitch2SensorState = BinarySensorReport>>5 & 1;
data.InternalShockSensorState = BinarySensorReport>>6 & 1;
data.ExternalShockSensorState = BinarySensorReport>>7 & 1;
data.ExternalDryContactPointINState = BinarySensorReport>>8 & 1;
data.ExternalWaterLeak1SenorState = BinarySensorReport>>9 & 1;
data.ExternalWaterLeak2SenorState = BinarySensorReport>>10 & 1;
data.ExternalSeatSenorState = BinarySensorReport>>11 & 1;
data.ExternalGlassSenor1State = BinarySensorReport>>12 & 1;
data.ExternalGlassSenor2State = BinarySensorReport>>13 & 1;
}
else if(input.bytes[2] == 0x12){
if (input.bytes[4] & 0x80){
var tmpval = (input.bytes[4]<<8 | input.bytes[5]);
data.Temp = (0x10000 - tmpval)/100 * -1;
}else{
data.Temp = (input.bytes[4]<<8 | input.bytes[5])/100;
}
data.Humidity = (input.bytes[6]<<8 | input.bytes[7])*0.01 +"%";
data.Illuminance = (input.bytes[8]<<8 | input.bytes[9])+"Lux";
data.LowTemperatureAlarm = input.bytes[10] & 1;
data.HighTemperatureAlarm = input.bytes[10]>>1 & 1;
data.LowHumidityAlarm = input.bytes[10]>>2 & 1;
data.HighHumidityAlarm = input.bytes[10]>>3 & 1;
data.LowIlluminanceAlarm = input.bytes[10]>>4 & 1;
data.HighIlluminanceAlarm = input.bytes[10]>>5 & 1;
}
break;

case 7:
Expand Down
316 changes: 316 additions & 0 deletions vendor/netvox/payload/r603.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,316 @@
function getCfgCmd(cfgcmd){
var cfgcmdlist = {
1: "ConfigReportReq",
129: "ConfigReportRsp",
2: "ReadConfigReportReq",
130: "ReadConfigReportRsp",
3: "StartSirenReq",

4: "SetPeriodSirenReq",
132: "SetPeriodSirenRsp",
5: "GetPeriodSirenReq",
133: "GetPeriodSirenRsp",
6: "StopPeriodSirenReq",
134: "StopPeriodSirenRsp",
7: "SetLEDColorReq",
135: "SetLEDColorRsp",
8: "GetLEDColorReq",
136: "GetLEDColorRsp",
9: "SetContactSwitchTriggerAlarmReq",
137: "SetContactSwitchTriggerAlarmRsp",
10: "GetContactSwitchTriggerAlarmReq",
138: "GetContactSwitchTriggerAlarmRsp",
};
return cfgcmdlist[cfgcmd];
}

function getCmdToID(cmdtype){
if (cmdtype == "ConfigReportReq")
return 1;
else if (cmdtype == "ConfigReportRsp")
return 129;
else if (cmdtype == "ReadConfigReportReq")
return 2;
else if (cmdtype == "ReadConfigReportRsp")
return 130;
else if (cmdtype == "StartSirenReq")
return 3;

else if (cmdtype == "SetPeriodSirenReq")
return 4;
else if (cmdtype == "SetPeriodSirenRsp")
return 132;
else if (cmdtype == "GetPeriodSirenReq")
return 5;
else if (cmdtype == "GetPeriodSirenRsp")
return 133;
else if (cmdtype == "StopPeriodSirenReq")
return 6;
else if (cmdtype == "StopPeriodSirenRsp")
return 134;
else if (cmdtype == "SetLEDColorReq")
return 7;
else if (cmdtype == "SetLEDColorRsp")
return 135;
else if (cmdtype == "GetLEDColorReq")
return 8;
else if (cmdtype == "GetLEDColorRsp")
return 136;
else if (cmdtype == "SetContactSwitchTriggerAlarmReq")
return 9;
else if (cmdtype == "SetContactSwitchTriggerAlarmRsp")
return 137;
else if (cmdtype == "GetContactSwitchTriggerAlarmReq")
return 10;
else if (cmdtype == "GetContactSwitchTriggerAlarmRsp")
return 138;
}

function getDeviceName(dev){
var deviceName = {
222: "R603"
};
return deviceName[dev];
}

function getDeviceID(devName){
var deviceName = {
"R603": 222
};
return deviceName[devName];
}
function getSirenNoType(id){
var type = {
"0X00":"EmergencyMode",
"0X01":"Doorbel",
"0X02":"Burglar",
"0X03":"FireMode",
"0X04":"Help",
"0X05":"No Smoking",
"0X06":"Poor Air Quality",
"0X07":"The temperature is too high",
"0X08":"Thief",
"0X09":"Welcome"
};
return type[id];
}
function getSirenNoTypeByName(name){
var typeList = {
"EmergencyMode":"0X00",
"Doorbel":"0X01",
"Burglar":"0X02",
"FireMode":"0X03",
"Help":"0X04",
"No Smoking":"0X05",
"Poor Air Quality":"0X06",
"The temperature is too high":"0X07",
"Thief":"0X08",
"Welcome":"0X09"
};
return typeList[id];
}
function getStrobeModeType(id){
var type = {
"0X00":"NoLedIndication",
"0X01":"LedBlinkMode1 in Parallel to Warning",
"0X02":"LedBlinkMode2 in Parallel to Warning"
};
return type[id];
}
function getStrobeModeTypeByName(name){
var typeList = {
"NoLedIndication":"0X00",
"LedBlinkMode1 in Parallel to Warning":"0X01",
"LedBlinkMode2 in Parallel to Warning":"0X02"
};
return typeList[id];
}
function padLeft(str, len) {
str = '' + str;
if (str.length >= len) {
return str;
} else {
return padLeft("0" + str, len);
}
}

function decodeUplink(input) {
var data = {};
switch (input.fPort) {
case 6:
if (input.bytes[2] === 0x00)
{
data.Device = getDeviceName(input.bytes[1]);
data.HWver = input.bytes[3];
data.SWver = input.bytes[4];
data.Datecode = padLeft(input.bytes[5].toString(16), 2) + padLeft(input.bytes[6].toString(16), 2) + padLeft(input.bytes[7].toString(16), 2) + padLeft(input.bytes[8].toString(16), 2);

return {
data: data,
};
}

data.Device = getDeviceName(input.bytes[1]);
if (input.bytes[3] & 0x80)
{
var tmp_v = input.bytes[3] & 0x7F;
data.Volt = (tmp_v / 10).toString() + '(low battery)';
}
else
data.Volt = input.bytes[3]/10;

data.WarningStatus = (input.bytes[4] == 0x00) ? 'NoWarnring' : 'Warning';
data.ContactSwitchStatus = (input.bytes[5] == 0x00) ? 'Off' : 'On';
break;

case 7:
data.Cmd = getCfgCmd(input.bytes[0]);
data.Device = getDeviceName(input.bytes[1]);

if ((input.bytes[0] === getCmdToID("ConfigReportRsp"))
|| (input.bytes[0] === getCmdToID("SetPeriodSirenRsp"))
|| (input.bytes[0] === getCmdToID("StopPeriodSirenRsp"))
|| (input.bytes[0] === getCmdToID("SetLEDColorRsp"))
|| (input.bytes[0] === getCmdToID("SetContactSwitchTriggerAlarmRsp")))
{
data.Status = (input.bytes[2] === 0x00) ? 'Success' : 'Failure';
}
else if (input.bytes[0] === getCmdToID("ReadConfigReportRsp"))
{
data.MinTime = (input.bytes[2]<<8 | input.bytes[3]);
data.MaxTime = (input.bytes[4]<<8 | input.bytes[5]);
}
else if (input.bytes[0] === getCmdToID("GetPeriodSirenRsp"))
{
data.SirenNo = getSirenNoType(input.bytes[2]);
data.SirenLevel = input.bytes[3];
data.StrobeMode = getStrobeModeType(input.bytes[4]);
data.Duration = (input.bytes[5]<<8 | input.bytes[6]);
data.PeriodTime = (input.bytes[7]<<8 | input.bytes[8]);
}
else if (input.bytes[0] === getCmdToID("GetLEDColorRsp"))
{
data.Red = input.bytes[2];
data.Green = input.bytes[3];
data.Blue = input.bytes[4];
}
else if (input.bytes[0] === getCmdToID("GetContactSwitchTriggerAlarmRsp"))
{
data.SirenNo = getSirenNoType(input.bytes[2]);
data.SirenLevel = input.bytes[3];
data.StrobeMode = getStrobeModeType(input.bytes[4]);
data.Duration = (input.bytes[5]<<8 | input.bytes[6]);
}

break;

default:
return {
errors: ['unknown FPort'],
};

}

return {
data: data,
};
}

function encodeDownlink(input) {
var ret = [];
var devid;
var getCmdID;

getCmdID = getCmdToID(input.data.Cmd);
devid = getDeviceID(input.data.Device);

if (input.data.Cmd == "ConfigReportReq")
{
var mint = input.data.MinTime;
var maxt = input.data.MaxTime;
ret = ret.concat(getCmdID, devid, (mint >> 8), (mint & 0xFF), (maxt >> 8), (maxt & 0xFF), 0x00, 0x00, 0x00, 0x00, 0x00);
}
else if ((input.data.Cmd == "ReadConfigReportReq")
|| (input.data.Cmd == "GetPeriodSirenReq")
|| (input.data.Cmd == "StopPeriodSirenReq")
|| (input.data.Cmd == "GetLEDColorReq"))
{
ret = ret.concat(getCmdID, devid, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
}
else if ((input.data.Cmd == "StartSirenReq")
|| (input.data.Cmd == "SetContactSwitchTriggerAlarmReq") )
{
var sirenNo = getSirenNoTypeByName(input.data.SirenNo);
var siren = input.data.SirenLevel;
var strobeMode = getStrobeModeTypeByName(input.data.StrobeMode);
var duration = input.data.Duration;
ret = ret.concat(getCmdID, devid, sirenNo, siren, strobeMode, (duration >> 8), (duration & 0xFF), 0x00, 0x00, 0x00, 0x00);
}
else if ((input.data.Cmd == "SetPeriodSirenReq") )
{
var sirenNo = getSirenNoTypeByName(input.data.SirenNo);
var siren = input.data.SirenLevel;
var strobeMode = getStrobeModeTypeByName(input.data.StrobeMode);
var duration = input.data.Duration;
var periodTime = input.data.PeriodTime;
ret = ret.concat(getCmdID, devid, sirenNo, siren, strobeMode,(duration >> 8), (duration & 0xFF), (periodTime >> 8), (periodTime & 0xFF), 0x00, 0x00);
}
else if ((input.data.Cmd == "SetLEDColorReq") )
{
var red = input.data.Red;
var green = input.data.Green;
var blue = input.data.Blue;
ret = ret.concat(getCmdID, devid, red, green, blue, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
}

return {
fPort: 7,
bytes: ret
};
}

function decodeDownlink(input) {
var data = {};
switch (input.fPort) {
case 7:
data.Cmd = getCfgCmd(input.bytes[0]);
data.Device = getDeviceName(input.bytes[1]);
if (input.bytes[0] === getCmdToID("ConfigReportReq"))
{
data.MinTime = (input.bytes[2]<<8 | input.bytes[3]);
data.MaxTime = (input.bytes[4]<<8 | input.bytes[5]);
}
else if ((input.bytes[0] === getCmdToID("StartSirenReq"))
||(input.bytes[0] === getCmdToID("SetContactSwitchTriggerAlarmReq")))
{
data.SirenNo= getSirenNoType(input.bytes[2]);
data.SirenLevel=input.bytes[3];
data.StrobeMode=getStrobeModeType(input.bytes[4])
data.Duration=(input.bytes[5]<<8 | input.bytes[6]);
}
else if (input.bytes[0] === getCmdToID("SetPeriodSirenReq"))
{
data.SirenNo= getSirenNoType(input.bytes[2]);
data.SirenLevel=input.bytes[3];
data.StrobeMode=getStrobeModeType(input.bytes[4])
data.Duration=(input.bytes[5]<<8 | input.bytes[6]);
data.PeriodTime=(input.bytes[7]<<8 | input.bytes[8]);
}
else if (input.bytes[0] === getCmdToID("SetLEDColorReq"))
{
data.Red= getSirenNoType(input.bytes[2]);
data.Green=input.bytes[3];
data.Blue=getStrobeModeType(input.bytes[4])
}
break;

default:
return {
errors: ['invalid FPort'],
};
}

return {
data: data,
};
}
Loading
Loading