Subversion Repositories HomeAutomation

Rev

Rev 1968 | Rev 2162 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1.  
  2. Node_ResetNodeId = null;
  3. Node_ResetClientId = null;
  4.  
  5. Node_ProgramNodeId = null;
  6. Node_ProgramClientId = null;
  7.  
  8. Node_WaitClientId = null;
  9.  
  10. Node_HexData = "";
  11. Node_HexNumLines = 0;
  12.  
  13. function Node_OnChange(node_id, available)
  14. {
  15.     if (node_id == Node_ResetNodeId && available)
  16.     {
  17.         Console_LogToClient(Node_ResetClientId, "\033[32m" + Node_ResetNodeId + " started okay.\033[0m\n");
  18.  
  19.     Console_NewConnection(Node_ResetClientId); // This is a ugly hack for a bad design for multiusers
  20.     Node_ResetNodeId = null;
  21.     Node_ResetClientId = null;
  22.     }
  23.  
  24.     if (node_id == Node_ProgramNodeId && available)
  25.     {
  26.         Console_LogToClient(Node_ProgramClientId, "\033[32m" + Node_ProgramNodeId + " started okay.\033[0m\n");
  27.  
  28.         Console_NewConnection(Node_ProgramClientId); // This is a ugly hack for a bad design for multiusers
  29.         Node_ProgramNodeId = null;
  30.         Node_ProgramClientId = null;
  31.     }
  32.  
  33.     if (Node_WaitClientId != null && available)
  34.     {
  35.         var result = NodeExport_GetNodeInformation(node_id);
  36.  
  37.         if (!result)
  38.         {
  39.             Console_LogToClient(Node_WaitClientId, "\033[31mNo node with id " + node_id + " found.\033[0m\n");
  40.             return false;
  41.         }
  42.  
  43.         var date = new Date(result["LastActive"] * 1000);
  44.  
  45.         Console_LogToClient(Node_WaitClientId, "Id: " + result["Id"] + "\n");
  46.         Console_LogToClient(Node_WaitClientId, "Valid: " + result["Valid"] + "\n");
  47.         Console_LogToClient(Node_WaitClientId, "Bios Version: " + result["BiosVersion"] + "\n");
  48.         Console_LogToClient(Node_WaitClientId, "Device Type: " + result["DeviceType"] + "\n");
  49.         Console_LogToClient(Node_WaitClientId, "Has Application: " + result["HasApplication"] + "\n");
  50.         Console_LogToClient(Node_WaitClientId, "Last Active: " + date.toString() + "\n");
  51.  
  52.         Console_NewConnection(Node_WaitClientId); // This is a ugly hack for a bad design for multiusers
  53.         Node_WaitClientId = null;
  54.     }
  55. }
  56.  
  57. function Node_GetAvailableIds()
  58. {
  59.     var result_list = [];
  60.     var available_nodes = NodeExport_GetAvailableNodes();
  61.  
  62.     for (var n in available_nodes)
  63.     {
  64.         var id_parts = available_nodes[n].split(",", 2);
  65.  
  66.         result_list.push(id_parts[0]);
  67.     }
  68.  
  69.     return result_list;
  70. }
  71.  
  72. function Node_ListAvailable()
  73. {
  74.     var available_nodes = NodeExport_GetAvailableNodes();
  75.  
  76.     var lines = [["Id", "Modules"]];
  77.  
  78.     for (var n in available_nodes)
  79.     {
  80.         var parts = available_nodes[n].split(",");
  81.         var id = parts.shift();
  82.         var modules = "<none>";
  83.  
  84.         if (parts.length > 0)
  85.         {
  86.             modules = parts.join(", ");
  87.         }
  88.  
  89.         lines.push([id, modules]);
  90.     }
  91.  
  92.     var table_lines = create_table(lines);
  93.  
  94.     Log("\033[29;1m" + table_lines[0] + "\033[0m\n");
  95.  
  96.     for (var n = 1; n < table_lines.length; n++)
  97.     {
  98.         Log(table_lines[n] + "\n");
  99.     }
  100.  
  101.     return true;
  102. }
  103. Console_RegisterCommand(Node_ListAvailable);
  104.  
  105. function Node_Reset(node_id)
  106. {
  107.     if (arguments.length < 1)
  108.     {
  109.         Log("\033[31mNot enough parameters given.\033[0m\n");
  110.         return false;
  111.     }
  112.  
  113.     Log("Sending reset to " + node_id + "...\n");
  114.  
  115.     if (!NodeExport_ResetNode(node_id))
  116.     {
  117.         Log("\033[31mFailed to send reset.\033[0m\n");
  118.         return false;
  119.     }
  120.  
  121.     Node_ProgramClientId = Console_GetClientId();
  122.     Node_ProgramNodeId = node_id;
  123.     Console_PreventDefaultPrompt();
  124.  
  125.     return true;
  126. }
  127. Console_RegisterCommand(Node_Reset, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Node_GetAvailableIds()); });
  128.  
  129. function Node_Program(node_id, bios, filename)
  130. {
  131.     if (arguments.length < 3)
  132.     {
  133.         Log("\033[31mNot enough parameters given.\033[0m\n");
  134.         return false;
  135.     }
  136.  
  137.     Log("Initiating programming of " + node_id + "...\n");
  138.  
  139.     if (!NodeExport_ProgramNode(node_id, bios > 0, filename))
  140.     {
  141.         Log("\033[31mFailed to start programming.\033[0m\n");
  142.         return false;
  143.     }
  144.  
  145.     Node_ResetClientId = Console_GetClientId();
  146.     Node_ResetNodeId = node_id;
  147.     Console_PreventDefaultPrompt();
  148.  
  149.     return true;
  150. }
  151. Console_RegisterCommand(Node_Program, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Node_GetAvailableIds(), [0, 1]); });
  152.  
  153. function Node_ProgramHex(node_id, bios, hexnumlines)
  154. {
  155.     if (arguments.length < 2)
  156.     {
  157.         Log("\033[31mNot enough parameters given.\033[0m\n");
  158.         return false;
  159.     }
  160.     if (Node_HexNumLines != hexnumlines)
  161.     {
  162.         Log("\033[31mNumber of hex lines does not match received (" + Node_HexNumLines + " received, should be " + hexnumlines + ").\033[0m\n");
  163.         return false;
  164.     }
  165.  
  166.     Log("Initiating programming of " + node_id + "...\n");
  167.  
  168.     if (!NodeExport_ProgramNodeHex(node_id, bios > 0, Node_HexData))
  169.     {
  170.         Log("\033[31mFailed to start programming.\033[0m\n");
  171.         return false;
  172.     }
  173.  
  174.     Node_ResetClientId = Console_GetClientId();
  175.     Node_ResetNodeId = node_id;
  176.     Console_PreventDefaultPrompt();
  177.  
  178.     Node_HexData = "";
  179.     Node_HexNumLines = 0;
  180.  
  181.  
  182.     return true;
  183. }
  184. Console_RegisterCommand(Node_ProgramHex, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Node_GetAvailableIds(), [0, 1]); });
  185.  
  186. function Node_ClearHex()
  187. {
  188. //    Log("Clearing hexdata...\n");
  189.  
  190.     Node_HexData = "";
  191.     Node_HexNumLines = 0;
  192.  
  193.     return true;
  194. }
  195. Console_RegisterCommand(Node_ClearHex);
  196.  
  197. function Node_AppendHex(hexrow)
  198. {
  199.     if (arguments.length < 1)
  200.     {
  201.         Log("\033[31mNot enough parameters given.\033[0m\n");
  202.         return false;
  203.     }
  204.  
  205. //    Log("Appending hexrow...\n");
  206.  
  207.     Node_HexData = Node_HexData + hexrow + "\n";
  208.     Node_HexNumLines += 1;
  209.  
  210.     return true;
  211. }
  212. Console_RegisterCommand(Node_AppendHex);
  213.  
  214. function Node_GetInformation(node_id)
  215. {
  216.     if (arguments.length < 1)
  217.     {
  218.         Log("\033[31mNot enough parameters given.\033[0m\n");
  219.         return false;
  220.     }
  221.  
  222.     var result = NodeExport_GetNodeInformation(node_id);
  223.  
  224.     if (!result)
  225.     {
  226.         Log("\033[31mNo node with id " + node_id + " found.\033[0m\n");
  227.         return false;
  228.     }
  229.  
  230.     var date = new Date(result["LastActive"] * 1000);
  231.  
  232.     Log("\033[96mId: \033[0;1m" + result["Id"] + "\033[0m\n");
  233.     Log("\033[96mValid: \033[0;1m" + result["Valid"] + "\033[0m\n");
  234.     Log("\033[96mBios Version: \033[0;1m" + result["BiosVersion"] + "\033[0m\n");
  235.     Log("\033[96mDevice Type: \033[0;1m" + result["DeviceType"] + "\033[0m\n");
  236.     Log("\033[96mHas Application: \033[0;1m" + result["HasApplication"] + "\033[0m\n");
  237.     Log("\033[96mLast Active: \033[0;1m" + date.toString() + "\033[0m\n");
  238.  
  239.     return true;
  240. }
  241. Console_RegisterCommand(Node_GetInformation, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Node_GetAvailableIds()); });
  242.  
  243. function Node_WaitForInformation()
  244. {
  245.     Node_WaitClientId = Console_GetClientId();
  246.     Console_PreventDefaultPrompt();
  247.  
  248.     return true;
  249. }
  250. Console_RegisterCommand(Node_WaitForInformation);
  251.