[{"id":"a139b862.24cc78","type":"udp in","z":"4669dfe0.ce8de","name":"NCD Push Notifications","iface":"","port":"5000","ipv":"udp4","multicast":"false","group":"","datatype":"buffer","x":140,"y":1620,"wires":[["b1475518.eacd88"]]},{"id":"b1475518.eacd88","type":"function","z":"4669dfe0.ce8de","name":"Parse NCD (Push Notification)","func":"// NOTE: Byte Definitions Below\n\nvar header = msg.payload[0];\n\n// 0xB4 or 180 are NCD devices\nif (header != 0xB4){\n\tmsg.data = msg;\n\tmsg.data.log = \"WARNING; Unknown Protocol\";\n\treturn [null,msg];\n}\n\nvar device = {};\ndevice.transmission_count = msg.payload[1];\ndevice.firmware = getFirmwareVersion(msg.payload);\ndevice.mac_address = getMacAddress(msg.payload);\ndevice.user_def = getUserDef(msg.payload);\ndevice.type = getStatusType(msg.payload);\ngetData(device, msg.payload);\ndevice.checksum = getChecksum(msg.payload);\n\ndevice.ip = msg.ip;\n\nmsg.device = device;\nreturn [msg,null];\n\n// FUNCTIONS ======================== \n\nfunction getFirmwareVersion(payload){\n\treturn payload[2]+\".\"+payload[3];\n}\n\nfunction getMacAddress(payload){\n var mac = [];\n var i;\n for(i=4;i<=9;i++){\n mac.push(toHex(payload[i]));\n }\n return mac.join(\":\");\n}\n\nfunction toHex(d){\n return (\"0\"+(Number(d).toString(16))).slice(-2).toUpperCase();\n}\n\nfunction getUserDef(payload){\n return payload.slice(10,18);\n}\n\nfunction getStatusType(payload){\n return payload[18];\n}\n\nfunction getData(device, payload){\n var data = {};\n switch(device.type){\n case 1: // Push Notification - Contact Closure\n data.prior_status = getPriorStatus(payload);\n data.current_status = getCurrentStatus(payload);\n break;\n default:\n break;\n }\n \n device.data = JSON.stringify(data);\n}\n\nfunction getPriorStatus(payload){\n return payload[19];\n}\n\nfunction getCurrentStatus(payload){\n return payload[20];\n}\n\nfunction getChecksum(payload){\n return payload[21];\n}\n\n\n// Byte 0 is a header byte. This will always be 180 for PN series products.\n\n// Byte 1 is transmission id. This id will increase 1 increment for each broadcast sent by the controller. Note that this will reset after power cycle.\n\n// Bytes 2-3 indicate the controller?s firmware version. 01 00 would indicate v1.0 \n\n// Bytes 4-9 indicate the Ethernet module?s Mac address. Convert these bytes to Hexadecimal bytes for Mac format.\n\n// Bytes 10-17 are user definable. This can be used for any purpose required by the customer. These bytes can be customized underScratch pad memory in Base Station.\n\n// Byte 18 indicates the transmission data type. For current PN products this will be 1 indicating this is the status of the contact closure inputs.\n\n// Byte 19 indicates the status of inputs prior to the input status change which triggered this notification.\n\n// Byte 20 indicates the status of inputs after the input status change which triggered this notification.\n\n// Byte 21 is a checksum for the whole packet. See API Codec guide which explains how this check sum is calculated.","outputs":"2","noerr":0,"x":430,"y":1620,"wires":[["22d780ec.206a3","65ccec84.48f8a4"],["e389c3d.7eba04"]]},{"id":"65ccec84.48f8a4","type":"debug","z":"4669dfe0.ce8de","name":"","active":true,"console":"false","complete":"true","x":650,"y":1580,"wires":[]},{"id":"e389c3d.7eba04","type":"debug","z":"4669dfe0.ce8de","name":"","active":false,"console":"false","complete":"true","x":650,"y":1660,"wires":[]}]