Subversion Repositories HomeAutomation

Rev

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