Subversion Repositories HomeAutomation

Rev

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