Subversion Repositories HomeAutomation

Rev

Rev 1040 | Rev 1061 | 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 testOutput()
  80. {
  81. _print(ClientId, "====");
  82. _print(ClientId, "\r");
  83. _print(ClientId, "=AR=");
  84.  
  85. }
  86.  
  87. function ethStart()
  88. {
  89.     var canMessage = new CanNMTMessage("nmt", "Time");
  90.     canMessage.send();
  91. }
  92.  
  93. function resetNode(hardwareId)
  94. {
  95.     ProgrammingClientId = ClientId;
  96.  
  97.     if (hardwareId.length > 2)
  98.     {
  99.         if (hardwareId.substr(0,2)=="0x")
  100.         {
  101.             hardwareId = hex2uint(hardwareId.substring(2,hardwareId.length));
  102.         }
  103.     }
  104.    
  105.     var node = CanNodes[hardwareId];
  106.  
  107.     if (!node)
  108.     {
  109.         printTo(ProgrammingClientId, "Failed. No node is online that has that hardware id, " + hardwareId + "\n");
  110.         return;
  111.     }
  112.    
  113.     node.reset( function(status)
  114.             {
  115.                 if (status)
  116.                 {
  117.                     printTo(ProgrammingClientId, "Success: Node reset and bios started okay.\n");
  118.                 }
  119.                 else
  120.                 {
  121.                     printTo(ProgrammingClientId, "Failed. Node did not respond failed.\n");
  122.                 }
  123.             });
  124. }
  125.  
  126. var ProgrammingClientId = null;
  127.  
  128. function programNodeCallback(status, event, text, raw)
  129. {
  130.     if (raw)
  131.     {
  132.         printTo(ProgrammingClientId, text);
  133.     }
  134.     else
  135.     {
  136.         printTo(ProgrammingClientId, event + ": " + text + "\n");
  137.     }
  138. }
  139.  
  140. function programNode(hardwareId, hexData, bios)
  141. {
  142.     ProgrammingClientId = ClientId;
  143.  
  144.     if (hardwareId.length > 2)
  145.     {
  146.         if (hardwareId.substr(0,2)=="0x")
  147.         {
  148.             hardwareId = hex2uint(hardwareId.substring(2,hardwareId.length));
  149.         }
  150.     }
  151.    
  152.     var node = CanNodes[hardwareId];
  153.  
  154.     if (!node)
  155.     {
  156.         print("Failed. No node is online that has that hardware id, " + hardwareId + "\n");
  157.         return;
  158.     }
  159.  
  160.     hexData = unescape(hexData);
  161.  
  162.     //print("helo, hexData: " + hexData);
  163.  
  164.     //var hexData = getFileContents(hexFilename);
  165.     if (hexData)
  166.     {
  167.         var hexLinesOrg = hexData.split('\n');
  168.         var hexLines = new Array();
  169.    
  170.         for (var n = 0; n < hexLinesOrg.length; n++)
  171.         {
  172.             var line = hexLinesOrg[n].trim(' ');
  173.        
  174.             if (line != "")
  175.             {
  176.                 hexLines[hexLines.length] = line;
  177.             }
  178.         }
  179.  
  180.         var hexObj = new IntelHex(hexLines);
  181.         if (hexObj.isValid()) {
  182.             //print("hexfile is valid");
  183.             //for (var i = 0; i < 16; i++) { print(hexObj.getByte(i)+" "); }
  184.             //print("len: "+hexObj.getLength()+" laddr: "+hexObj.getAddrLower()+" uaddr: "+hexObj.getAddrUpper()+"\n");
  185.             node.startProgramming(hexObj, programNodeCallback, bios);
  186.         }
  187.     }
  188.     else
  189.     {
  190.         //print("File was not found, " + hexFilename + "\n");
  191.     }
  192. }
  193.  
  194. function p()
  195. {
  196.     var t = ServiceManager.getService("CAN", "irTransmit", 1);
  197.     t.sendClick('KiSS_DP-1500_Remote','POWER');
  198. }
  199.