Subversion Repositories HomeAutomation

Rev

Rev 1649 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1.  
  2. Serial_ModuleNames    = [ "Serial" ];
  3. Serial_Aliases        = function() { return Module_GetAliasNames(Serial_ModuleNames); };
  4. Serial_AvailableIds   = function() { return Module_GetAvailableIds(Serial_ModuleNames); };
  5.  
  6. function Serial_Configure(alias_name)
  7. {
  8.     if (arguments.length < 1)
  9.     {
  10.         Log("\033[31mNot enough parameters given.\033[0m\n");
  11.         return false;
  12.     }
  13.    
  14.     var aliases_data = Module_ResolveAlias(alias_name, Serial_ModuleNames);
  15.     var found = false;
  16.    
  17.     for (var name in aliases_data)
  18.     {
  19.         var variables = {
  20.         "BaudRate"       : 9600,
  21.         "PhysicalFormat" : "RS232",
  22.         "DataBits"       : 8,
  23.         "StopBits"       : 1,
  24.         "Parity"         : "ParityNone" };
  25.            
  26.         if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "SerialConfig", variables))
  27.         {
  28.             Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n");
  29.         }
  30.         else
  31.         {
  32.             Log("\033[31mFailed to send command to " + name + ".\033[0m\n");
  33.         }
  34.        
  35.         found = true;
  36.     }
  37.    
  38.     if (!found)
  39.     {
  40.         Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n");
  41.         return false;
  42.     }
  43.    
  44.     return true;
  45. }
  46. Console_RegisterCommand(Serial_Configure, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Serial_Aliases()); });
  47.  
  48. function Serial_Send(alias_name)
  49. {
  50.     if (arguments.length < 1)
  51.     {
  52.         Log("\033[31mNot enough parameters given.\033[0m\n");
  53.         return false;
  54.     }
  55.    
  56.     var data = "";
  57.    
  58.     for (var n = 1; n < arguments.length; n++)
  59.     {
  60.       data += arguments[n] + " ";
  61.     }
  62.    
  63.     data = data.trim(" ") + "\r";
  64.    
  65.     var aliases_data = Module_ResolveAlias(alias_name, Serial_ModuleNames);
  66.     var found = false;
  67.    
  68.     for (var name in aliases_data)
  69.     {
  70.         var variables = {
  71.         "Text"  : data };
  72.        
  73.         if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "SerialData", variables))
  74.         {
  75.             Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n");
  76.         }
  77.         else
  78.         {
  79.             Log("\033[31mFailed to send command to " + name + ".\033[0m\n");
  80.         }
  81.        
  82.         found = true;
  83.     }
  84.    
  85.     if (!found)
  86.     {
  87.         Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n");
  88.         return false;
  89.     }
  90.    
  91.     return true;
  92. }
  93. Console_RegisterCommand(Serial_Send, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Serial_Aliases()); });
  94.  
  95.