Subversion Repositories HomeAutomation

Rev

Rev 1669 | Rev 1887 | 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. function Node_OnChange(node_id, available)
  11. {
  12.     if (node_id == Node_ResetNodeId && available)
  13.     {
  14.         Console_LogToClient(Node_ResetClientId, "\033[32m" + Node_ResetNodeId + " started okay.\033[0m\n");
  15.         Node_ResetNodeId = null;
  16.         Node_ResetClientId = null;
  17.         Console_SetDefaultPrompt();
  18.     }
  19.    
  20.     if (node_id == Node_ProgramNodeId && available)
  21.     {
  22.         Console_LogToClient(Node_ProgramClientId, "\033[32m" + Node_ProgramNodeId + " started okay.\033[0m\n");
  23.         Node_ProgramNodeId = null;
  24.         Node_ProgramClientId = null;
  25.         Console_SetDefaultPrompt();
  26.     }
  27.    
  28.     if (Node_WaitClientId != null && available)
  29.     {    
  30.         var result = NodeExport_GetNodeInformation(node_id);
  31.    
  32.         if (!result)
  33.         {
  34.             Console_LogToClient(Node_WaitClientId, "\033[31mNo node with id " + node_id + " found.\033[0m\n");
  35.             return false;
  36.         }
  37.        
  38.         var date = new Date(result["LastActive"] * 1000);
  39.        
  40.         Console_LogToClient(Node_WaitClientId, "Id: " + result["Id"] + "\n");
  41.         Console_LogToClient(Node_WaitClientId, "Valid: " + result["Valid"] + "\n");
  42.         Console_LogToClient(Node_WaitClientId, "Bios Version: " + result["BiosVersion"] + "\n");
  43.         Console_LogToClient(Node_WaitClientId, "Device Type: " + result["DeviceType"] + "\n");
  44.         Console_LogToClient(Node_WaitClientId, "Has Application: " + result["HasApplication"] + "\n");
  45.         Console_LogToClient(Node_WaitClientId, "Last Active: " + date.toString() + "\n");
  46.        
  47.         Node_WaitClientId = null;
  48.         Console_SetDefaultPrompt();
  49.     }
  50. }
  51.  
  52. function Node_GetAvailableIds()
  53. {
  54.     var result_list = [];
  55.     var available_nodes = NodeExport_GetAvailableNodes();
  56.    
  57.     for (var n in available_nodes)
  58.     {
  59.         var id_parts = available_nodes[n].split(",", 2);
  60.        
  61.         result_list.push(id_parts[0]);
  62.     }
  63.    
  64.     return result_list;
  65. }
  66.  
  67. function Node_ListAvailable()
  68. {
  69.     var available_nodes = NodeExport_GetAvailableNodes();
  70.    
  71.     var lines = [["Id", "Modules"]];
  72.    
  73.     for (var n in available_nodes)
  74.     {
  75.         var parts = available_nodes[n].split(",");
  76.         var id = parts.shift();
  77.         var modules = "<none>";
  78.        
  79.         if (parts.length > 0)
  80.         {
  81.             modules = parts.join(", ");
  82.         }
  83.        
  84.         lines.push([id, modules]);
  85.     }
  86.    
  87.     var table_lines = create_table(lines);
  88.    
  89.     Log("\033[29;1m" + table_lines[0] + "\033[0m\n");
  90.    
  91.     for (var n = 1; n < table_lines.length; n++)
  92.     {
  93.         Log(table_lines[n] + "\n");
  94.     }
  95.    
  96.     return true;
  97. }
  98. Console_RegisterCommand(Node_ListAvailable);
  99.  
  100. function Node_Reset(node_id)
  101. {
  102.     if (arguments.length < 1)
  103.     {
  104.         Log("\033[31mNot enough parameters given.\033[0m\n");
  105.         return false;
  106.     }
  107.    
  108.     Log("Sending reset to " + node_id + "...\n");
  109.    
  110.     if (!NodeExport_ResetNode(node_id))
  111.     {
  112.         Log("\033[31mFailed to send reset.\033[0m\n");
  113.         return false;
  114.     }
  115.    
  116.     Node_ProgramClientId = Console_GetClientId();
  117.     Node_ProgramNodeId = node_id;
  118.     Console_PreventDefaultPrompt();
  119.  
  120.     return true;
  121. }
  122. Console_RegisterCommand(Node_Reset, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Node_GetAvailableIds()); });
  123.  
  124. function Node_Program(node_id, bios, filename)
  125. {
  126.     if (arguments.length < 3)
  127.     {
  128.         Log("\033[31mNot enough parameters given.\033[0m\n");
  129.         return false;
  130.     }
  131.    
  132.     Log("Initiating programming of " + node_id + "...\n");
  133.    
  134.     if (!NodeExport_ProgramNode(node_id, bios > 0, filename))
  135.     {
  136.         Log("\033[31mFailed to start programming.\033[0m\n");
  137.         return false;
  138.     }
  139.    
  140.     Node_ResetClientId = Console_GetClientId();
  141.     Node_ResetNodeId = node_id;
  142.     Console_PreventDefaultPrompt();
  143.    
  144.     return true;
  145. }
  146. Console_RegisterCommand(Node_Program, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Node_GetAvailableIds(), [0, 1]); });
  147.  
  148. function Node_GetInformation(node_id)
  149. {
  150.     if (arguments.length < 1)
  151.     {
  152.         Log("\033[31mNot enough parameters given.\033[0m\n");
  153.         return false;
  154.     }
  155.    
  156.     var result = NodeExport_GetNodeInformation(node_id);
  157.    
  158.     if (!result)
  159.     {
  160.         Log("\033[31mNo node with id " + node_id + " found.\033[0m\n");
  161.         return false;
  162.     }
  163.    
  164.     var date = new Date(result["LastActive"] * 1000);
  165.  
  166.     Log("\033[96mId: \033[0;1m" + result["Id"] + "\033[0m\n");
  167.     Log("\033[96mValid: \033[0;1m" + result["Valid"] + "\033[0m\n");
  168.     Log("\033[96mBios Version: \033[0;1m" + result["BiosVersion"] + "\033[0m\n");
  169.     Log("\033[96mDevice Type: \033[0;1m" + result["DeviceType"] + "\033[0m\n");
  170.     Log("\033[96mHas Application: \033[0;1m" + result["HasApplication"] + "\033[0m\n");
  171.     Log("\033[96mLast Active: \033[0;1m" + date.toString() + "\033[0m\n");
  172.    
  173.     return true;
  174. }
  175. Console_RegisterCommand(Node_GetInformation, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Node_GetAvailableIds()); });
  176.  
  177. function Node_WaitForInformation()
  178. {
  179.     Node_WaitClientId = Console_GetClientId();
  180.     Console_PreventDefaultPrompt();
  181.    
  182.     return true;
  183. }
  184. Console_RegisterCommand(Node_WaitForInformation);
  185.