Subversion Repositories HomeAutomation

Rev

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

  1.  
  2. function quit()
  3. {
  4.     if (ClientId)
  5.     {
  6.         _quit(ClientId);
  7.     }
  8. }
  9.  
  10. function print(text)
  11. {
  12.     if (ClientId)
  13.     {
  14.         _print(ClientId, text);
  15.     }
  16.     else
  17.     {
  18.         log(text);
  19.     }
  20. }
  21.  
  22. function printTo(clientId, text)
  23. {
  24.     _print(clientId, text);
  25. }
  26.  
  27. function services()
  28. {
  29.     var list = new Array();
  30.    
  31.     var row = new Array();
  32.    
  33.     row[row.length] = "Type";
  34.     row[row.length] = "Name";
  35.     row[row.length] = "Id";
  36.     row[row.length] = "Online";
  37.    
  38.     list[list.length] = row;
  39.    
  40.     for (var n in ServiceManager.Services)
  41.     {
  42.         var row = new Array();
  43.        
  44.         row[row.length] = ServiceManager.Services[n].getType();
  45.         row[row.length] = ServiceManager.Services[n].getName();
  46.         row[row.length] = ServiceManager.Services[n].getId();
  47.         if (ServiceManager.Services[n].getType() == "Can")
  48.         {
  49.             row[row.length] = ServiceManager.Services[n].isOnline();
  50.         }
  51.         else
  52.         {
  53.             row[row.length] = "";
  54.         }
  55.        
  56.         list[list.length] = row;
  57.     }
  58.  
  59.     var lines = TextTable.create(list);
  60.    
  61.     for (var n in lines)
  62.     {
  63.         print(lines[n] + "\n");
  64.     }
  65. }
  66.  
  67. function getService(id, name)
  68. {
  69.     var fullId = name + id;
  70.  
  71.     if (!ServiceManager.Services[fullId])
  72.     {
  73.         print("No such service found.\n");
  74.     }
  75.    
  76.     return ServiceManager.Services[fullId];
  77. }
  78.  
  79. function ethStart()
  80. {
  81.     var canMessage = new CanNMTMessage("nmt", "Time");
  82.     canMessage.send();
  83. }
  84.  
  85. function resetNode(hardwareId)
  86. {
  87.     ProgrammingClientId = ClientId;
  88.  
  89.     if (hardwareId.length > 2)
  90.     {
  91.         if (hardwareId.substr(0,2)=="0x")
  92.         {
  93.             hardwareId = hex2uint(hardwareId.substring(2,hardwareId.length));
  94.         }
  95.     }
  96.    
  97.     var node = CanNodes[hardwareId];
  98.  
  99.     if (!node)
  100.     {
  101.         printTo(ProgrammingClientId, "STOP: Failed. No node is online that has that hardware id, " + hardwareId + "\n");
  102.         return;
  103.     }
  104.    
  105.     node.reset( function(status)
  106.             {
  107.                 if (status)
  108.                 {
  109.                     printTo(ProgrammingClientId, "STOP: Success: Node reset and bios started okay.\n");
  110.                 }
  111.                 else
  112.                 {
  113.                     printTo(ProgrammingClientId, "STOP: Failed. Node did not respond failed.\n");
  114.                 }
  115.             });
  116. }
  117.  
  118. var ProgrammingClientId = null;
  119.  
  120. function programNodeCallback(status, event, text, raw)
  121. {
  122.     if (raw)
  123.     {
  124.         printTo(ProgrammingClientId, text);
  125.     }
  126.     else
  127.     {
  128.         printTo(ProgrammingClientId, event + ": " + text + "\n");
  129.     }
  130. }
  131.  
  132. function programNode(hardwareId, hexData, bios)
  133. {
  134.     ProgrammingClientId = ClientId;
  135.  
  136.     if (hardwareId.length > 2)
  137.     {
  138.         if (hardwareId.substr(0,2)=="0x")
  139.         {
  140.             hardwareId = hex2uint(hardwareId.substring(2,hardwareId.length));
  141.         }
  142.     }
  143.    
  144.     var node = CanNodes[hardwareId];
  145.  
  146.     if (!node)
  147.     {
  148.         print("STOP: Failed. No node is online that has that hardware id, " + hardwareId + "\n");
  149.         return;
  150.     }
  151.  
  152.     hexData = unescape(hexData);
  153.  
  154.     if (hexData)
  155.     {
  156.         var hexLinesOrg = hexData.split('\n');
  157.         var hexLines = new Array();
  158.    
  159.         for (var n = 0; n < hexLinesOrg.length; n++)
  160.         {
  161.             var line = hexLinesOrg[n].trim(' ');
  162.        
  163.             if (line != "")
  164.             {
  165.                 hexLines[hexLines.length] = line;
  166.             }
  167.         }
  168.  
  169.         var hexObj = new IntelHex(hexLines);
  170.         if (hexObj.isValid()) {
  171.             node.startProgramming(hexObj, programNodeCallback, bios);
  172.         }
  173.         else
  174.         {
  175.             print("STOP: Failed. Invalid hexfile\n");
  176.         }
  177.     }
  178.     else
  179.     {
  180.         //print("File was not found, " + hexFilename + "\n");
  181.     }
  182. }
  183.  
  184. function p(time, button)
  185. {
  186.     var t = ServiceManager.getService("CAN", "irTransmit", 1);
  187.     t.sendClick('KiSS_DP-1500_Remote', button, time);
  188. }
  189.