Subversion Repositories HomeAutomation

Rev

Rev 1009 | Rev 1022 | 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. var ProgrammingClientId = null;
  80.  
  81. function programNodeCallback(status, event, text)
  82. {
  83.     printTo(ProgrammingClientId, event + ": " + text + "\n");
  84. }
  85.  
  86. function programNode(hardwareId, hexData, bios)
  87. {
  88.     ProgrammingClientId = ClientId;
  89.  
  90.     if (hardwareId.length > 2)
  91.     {
  92.         if (hardwareId.substr(0,2)=="0x")
  93.         {
  94.             hardwareId = hex2uint(hardwareId.substring(2,hardwareId.length));
  95.             //hardwareId += hex2uint(hardwareId.substring(0,hardwareId.length-1));
  96.         }
  97.     }
  98.    
  99.     var node = CanNodes[hardwareId];
  100.  
  101.     if (!node)
  102.     {
  103.         print("Failed. No node is online that has that hardware id, " + hardwareId + "\n");
  104.         return;
  105.     }
  106.  
  107.     hexData = unescape(hexData);
  108.  
  109.     //print("helo, hexData: " + hexData);
  110.  
  111.     //var hexData = getFileContents(hexFilename);
  112.     if (hexData)
  113.     {
  114.         var hexLinesOrg = hexData.split('\n');
  115.         var hexLines = new Array();
  116.    
  117.         for (var n = 0; n < hexLinesOrg.length; n++)
  118.         {
  119.             var line = hexLinesOrg[n].trim(' ');
  120.        
  121.             if (line != "")
  122.             {
  123.                 hexLines[hexLines.length] = line;
  124.             }
  125.         }
  126.  
  127.         var hexObj = new IntelHex(hexLines);
  128.         if (hexObj.isValid()) {
  129.             //print("hexfile is valid");
  130.             //for (var i = 0; i < 16; i++) { print(hexObj.getByte(i)+" "); }
  131.             node.startProgramming(hexObj, programNodeCallback, bios);
  132.         }
  133.     }
  134.     else
  135.     {
  136.         //print("File was not found, " + hexFilename + "\n");
  137.     }
  138. }
  139.