Subversion Repositories HomeAutomation

Rev

Rev 1066 | 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.         //log("A can node with hardware id " + uint2hex(canMessage.getData("HardwareId"), 32) + " was not found, starting.\n");
  103.  
  104.         /* As a node with this hardware id has not been seen it could just be that it was started before atom and has no application installed */
  105.         node = new CanNode(hardwareId, null);
  106.         CanNodes[hardwareId] = node;
  107.         //return;
  108.     }
  109.    
  110.     node.reset( function(status)
  111.             {
  112.                 if (status)
  113.                 {
  114.                     printTo(ProgrammingClientId, "STOP: Success: Node reset and bios started okay.\n");
  115.                 }
  116.                 else
  117.                 {
  118.                     printTo(ProgrammingClientId, "STOP: Failed. Node did not respond failed.\n");
  119.                 }
  120.             });
  121. }
  122.  
  123. var ProgrammingClientId = null;
  124.  
  125. function programNodeCallback(status, event, text, raw)
  126. {
  127.     if (raw)
  128.     {
  129.         printTo(ProgrammingClientId, text);
  130.     }
  131.     else
  132.     {
  133.         printTo(ProgrammingClientId, event + ": " + text + "\n");
  134.     }
  135. }
  136.  
  137. function programNode(hardwareId, hexData, bios)
  138. {
  139.     ProgrammingClientId = ClientId;
  140.  
  141.     if (hardwareId.length > 2)
  142.     {
  143.         if (hardwareId.substr(0,2)=="0x")
  144.         {
  145.             hardwareId = hex2uint(hardwareId.substring(2,hardwareId.length));
  146.         }
  147.     }
  148.    
  149.     var node = CanNodes[hardwareId];
  150.  
  151.     if (!node)
  152.     {
  153.         //print("STOP: Failed. No node is online that has that hardware id, " + hardwareId + "\n");
  154.         //return;
  155.         /* As a node with this hardware id has not been seen it could just be that it was started before atom and has no application installed */
  156.         node = new CanNode(hardwareId, null);
  157.         CanNodes[hardwareId] = node;
  158.     }
  159.  
  160.     hexData = unescape(hexData);
  161.  
  162.     if (hexData)
  163.     {
  164.         var hexLinesOrg = hexData.split('\n');
  165.         var hexLines = new Array();
  166.    
  167.         for (var n = 0; n < hexLinesOrg.length; n++)
  168.         {
  169.             var line = hexLinesOrg[n].trim(' ');
  170.        
  171.             if (line != "")
  172.             {
  173.                 hexLines[hexLines.length] = line;
  174.             }
  175.         }
  176.  
  177.         var hexObj = new IntelHex(hexLines);
  178.         if (hexObj.isValid()) {
  179.             node.startProgramming(hexObj, programNodeCallback, bios);
  180.         }
  181.         else
  182.         {
  183.             print("STOP: Failed. Invalid hexfile\n");
  184.         }
  185.     }
  186.     else
  187.     {
  188.         //print("File was not found, " + hexFilename + "\n");
  189.     }
  190. }
  191.  
  192. function p(time, button)
  193. {
  194.     var t = ServiceManager.getService("CAN", "irTransmit", 1);
  195.     t.sendClick('KiSS_DP-1500_Remote', button, time);
  196. }
  197.