[{"id":"b3e07776.934738","type":"ui_template","z":"6014e012.9666a","group":"ef703e94.45e24","name":"tree scheme","order":0,"width":"0","height":"0","format":"\n\n\n","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":950,"y":2932,"wires":[[]]},{"id":"e2e6b879.e431d8","type":"function","z":"6014e012.9666a","name":"prepare tree data","func":"// data to read from cordinator eeprom\nvar numBonded = 4;\nvar numDiscovered = 3;\n//\t\t\t\t 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\nvar nodesBonded = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0 ];\nvar nodesDiscovered = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0 ];\nvar vrnArray = \t\t [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 2, 0, 0 ];\nvar nodesZone = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 1, 0, 0 ];\nvar nodesParent = \t [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ];\n\nvar treeData = [\n\t{\n\t\t\"name\": \"Cordinator\",\n\t\t\"parent\": \"null\",\n\t\t\"status\": \"orange\",\n\t\t\"children\": [],\n\t\t\"zone\": 0\n\t}\n];\n\nvar index = 0;\nwhile( numBonded )\n{\n index++;\n\tif( nodesBonded[index] == 1)\n\t{\n\t\tvar parent = \"\";\n\t\tvar status = \"\";\n\t\t\n\t\t// orphan\n\t\tif( nodesDiscovered[index] === 0 )\n\t\t{\n\t\t\tparent = \"null\";\n\t\t\tstatus = \"red\";\n\t\t}\n\t\t// first children\n\t\telse if( nodesParent[index] === 0 )\n\t\t{\n\t\t\tparent = \"Cordinator\";\n\t\t\tstatus = \"green\";\n\t\t}\n\t\t// other children\n\t\telse\n\t\t{\n\t\t\tparent = \"ID \" + vrnArray.indexOf(nodesParent[index]).toString() + \", VRN \" + nodesParent[index].toString();\n\t\t\tstatus = \"green\";\n\t\t}\n\t\t\n\t\ttreeData.push( \n\t\t{\n\t\t\t\"name\": \"ID \" + index.toString() + \", VRN \" + vrnArray[index].toString(),\n\t\t\t\"parent\": parent,\n\t\t\t\"status\": status,\n\t\t\t\"children\": [],\n\t\t\t\"zone\": nodesZone[index],\n\t\t} );\n\t\tnumBonded--;\n\t}\n}\n\n// sort array by zone\ntreeData.sort(function(a,b) {return (a.zone > b.zone) ? 1 : ((b.zone > a.zone) ? -1 : 0);} );\n\n// arrange tree\nvar maxDepth = treeData[treeData.length-1].zone;\nwhile( treeData[treeData.length-1].zone !== 0 )\n{\n var nodeChild = treeData.pop();\n \n // find and add as children to parent\n var i = FindParent(treeData,nodeChild);\n\n if( i != -1)\n treeData[i].children.push(nodeChild);\n}\n\nglobal.set(\"treeData\", treeData);\nmsg.payload={\"treeData\": treeData,\n \"maxDepth\": maxDepth};\n\nreturn msg;\n\nfunction FindParent(treeData, nodeChild) {\n for( var i = treeData.length-1 ; i >= 0 ; i--)\n {\n var n = nodeChild.parent.localeCompare(treeData[i].name);\n if((treeData[i].zone === (nodeChild.zone)-1) && (n===0))\n return i;\n }\n return -1;\n}","outputs":1,"noerr":0,"x":741,"y":2851,"wires":[["3077e546.81d73a","b3e07776.934738"]]},{"id":"3077e546.81d73a","type":"debug","z":"6014e012.9666a","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":943,"y":2820,"wires":[]},{"id":"6a8815a2.c290dc","type":"inject","z":"6014e012.9666a","name":"","topic":"request tree","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":492,"y":2851,"wires":[["e2e6b879.e431d8"]]},{"id":"f022d5be.82bef8","type":"function","z":"6014e012.9666a","name":"prepare tree data","func":"// data to read from cordinator eeprom\nvar numBonded = 9;\nvar numDiscovered = 8;\n//\t\t\t\t 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\nvar nodesBonded = [ 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0 ];\nvar nodesDiscovered = [ 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0 ];\nvar vrnArray = \t\t [ 0, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 1, 3, 2, 0, 0 ];\nvar nodesZone = [ 0, 1, 2, 3, 3, 4, 0, 0, 0, 0, 0, 1, 2, 1, 0, 0 ];\nvar nodesParent = \t [ 0, 0, 4, 5, 5, 7, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ];\n\nvar treeData = [\n\t{\n\t\t\"name\": \"Cordinator\",\n\t\t\"parent\": \"null\",\n\t\t\"status\": \"orange\",\n\t\t\"children\": [],\n\t\t\"zone\": 0\n\t}\n];\n\nvar index = 0;\nwhile( numBonded )\n{\n index++;\n\tif( nodesBonded[index] == 1)\n\t{\n\t\tvar parent = \"\";\n\t\tvar status = \"\";\n\t\t\n\t\t// orphan\n\t\tif( nodesDiscovered[index] === 0 )\n\t\t{\n\t\t\tparent = \"null\";\n\t\t\tstatus = \"red\";\n\t\t}\n\t\t// first children\n\t\telse if( nodesParent[index] === 0 )\n\t\t{\n\t\t\tparent = \"Cordinator\";\n\t\t\tstatus = \"green\";\n\t\t}\n\t\t// other children\n\t\telse\n\t\t{\n\t\t\tparent = \"ID \" + vrnArray.indexOf(nodesParent[index]).toString() + \", VRN \" + nodesParent[index].toString();\n\t\t\tstatus = \"green\";\n\t\t}\n\t\t\n\t\ttreeData.push( \n\t\t{\n\t\t\t\"name\": \"ID \" + index.toString() + \", VRN \" + vrnArray[index].toString(),\n\t\t\t\"parent\": parent,\n\t\t\t\"status\": status,\n\t\t\t\"children\": [],\n\t\t\t\"zone\": nodesZone[index],\n\t\t} );\n\t\tnumBonded--;\n\t}\n}\n\n// sort array by zone\ntreeData.sort(function(a,b) {return (a.zone > b.zone) ? 1 : ((b.zone > a.zone) ? -1 : 0);} );\n\n// arrange tree\nvar maxDepth = treeData[treeData.length-1].zone;\nwhile( treeData[treeData.length-1].zone !== 0 )\n{\n var nodeChild = treeData.pop();\n \n // find and add as children to parent\n var i = FindParent(treeData,nodeChild);\n\n if( i != -1)\n treeData[i].children.push(nodeChild);\n}\n\nglobal.set(\"treeData\", treeData);\nmsg.payload={\"treeData\": treeData,\n \"maxDepth\": maxDepth};\n\nreturn msg;\n\nfunction FindParent(treeData, nodeChild) {\n for( var i = treeData.length-1 ; i >= 0 ; i--)\n {\n var n = nodeChild.parent.localeCompare(treeData[i].name);\n if((treeData[i].zone === (nodeChild.zone)-1) && (n===0))\n return i;\n }\n return -1;\n}","outputs":1,"noerr":0,"x":741,"y":2909,"wires":[["3077e546.81d73a","b3e07776.934738"]]},{"id":"be939e26.b8f6c","type":"inject","z":"6014e012.9666a","name":"","topic":"request tree","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":492,"y":2909,"wires":[["f022d5be.82bef8"]]},{"id":"ef703e94.45e24","type":"ui_group","z":"","name":"map","tab":"e5ac23fa.f61fb","order":2,"disp":true,"width":"6","collapse":false},{"id":"e5ac23fa.f61fb","type":"ui_tab","z":"","name":"Layout","icon":"dashboard","order":2}]