Node-REDのfunctionにお使いください。
・RPS,1BSのnormal及びteach-in,4BSのnormal及びteach-in、の5種のtelegramに対応しています。
・下記サンプルコードはRPS,1BS,4BSのIDをconstとして定義しているので適当に修正してお使いください。本稼働にはIDの登録機能が必要でしょう。
===
//EnOcean telegram decoder
//2017.9.26 created
//
const ID_01 = “0500284c”;//STM250J
const ID_02 = “002e588c”;//EWSSJ
const ID_03 = “04011a9e”;//STM431J
//
var ESP3_Packet = msg.payload;
//
var Header = ESP3_Packet.slice(1,5);
var DataLength = 256*ESP3_Packet[1]+ESP3_Packet[2];
//
var RawData = ESP3_Packet.slice(6,6+DataLength);
var ERP2_Header = RawData.slice(0,1).toString(“hex”);
var OriginatorID = “00000000”;
var Data1 = “00”;
var Data4 = “00000000”;
//
var OptionalData = ESP3_Packet.slice(6+DataLength,8+DataLength);
var SubTelNum = OptionalData.slice(0,1);
var dBm = OptionalData.slice(1,2);
//
switch(ERP2_Header){
//normal telegram
case “20”://RPS telegram
case “21”://1BS normal telegram
OriginatorID = RawData.slice(1,5).toString(“hex”)
Data1 = RawData.slice(5,6).toString(“hex”);
break;
case “22”://4BS normal telegram
OriginatorID = RawData.slice(1,5).toString(“hex”)
Data4 = RawData.slice(5,9).toString(“hex”);
break;
//teach-in telegram
case “61”://1BS teach-in telegram
OriginatorID = RawData.slice(3,7).toString(“hex”)
Data1 = RawData.slice(7,8).toString(“hex”);
break;
case “62”://4BS teach-in telegram
OriginatorID = RawData.slice(3,7).toString(“hex”)
Data4 = RawData.slice(7,11).toString(“hex”);
break;
default:
break;
}
msg.payload = {
ESP3_Packet:ESP3_Packet,
Header:Header,
RawData:RawData,
Data1:Data1,
Data4:Data4,
SubTelNum:SubTelNum,
dBm:dBm
};
switch(OriginatorID){
case ID_01:
case ID_02:
case ID_03:
return msg;
default:
break;
}