Advertisement
Guest User

VIERA control class

a guest
Apr 22nd, 2012
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.49 KB | None | 0 0
  1. class vieraControl
  2. {
  3.     public $host;
  4.    
  5.     function __construct($hostname = false)
  6.     {
  7.         if ($hostname)
  8.             $this->host = $hostname;
  9.     }
  10.    
  11.     function createRequest($url, $urn, $action, $option = array())
  12.     {
  13.  
  14. $input = '<?xml version="1.0" encoding="utf-8"?>
  15. <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  16.  <s:Body>
  17.   <u:'.$action.' xmlns:u="urn:'.$urn.'">
  18.   '.$option['args'].'
  19.   </u:'.$action.'>
  20.  </s:Body>
  21. </s:Envelope>';
  22.         $curl = curl_init();
  23.         curl_setopt($curl, CURLOPT_URL, 'http://'.$this->host.':55000/'.$url);
  24.         curl_setopt($curl, CURLOPT_POST, 1);
  25.         curl_setopt($curl, CURLOPT_HTTPHEADER, array('SOAPACTION: "urn:'.$urn.'#'.$action.'"'));  
  26.         curl_setopt($curl, CURLOPT_POSTFIELDS, $input);
  27.         //curl_setopt($curl, CURLOPT_HEADER, true);
  28.         curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  29.         $data = curl_exec($curl);
  30.        
  31.         if ($option['returnXml'])
  32.             return $data;
  33.         else
  34.             return $this->getResponse($data);
  35.     }
  36.    
  37.     function getResponse($data)
  38.     {
  39.         $xml = simplexml_load_string($data);
  40.         if ($xml === false)
  41.             return false;
  42.         $ns = $xml->getNamespaces(true);
  43.         $soap = $xml->children($ns['s']);
  44.         $res = $soap->children($ns['u'])->children();
  45.         return $res[0];
  46.     }
  47.    
  48.     function getVolume()
  49.     {
  50.         return $this->createRequest(
  51.             'dmr/control_0',
  52.             'schemas-upnp-org:service:RenderingControl:1',
  53.             'GetVolume',
  54.             array('args' => '<InstanceID>0</InstanceID><Channel>Master</Channel>')
  55.         );
  56.     }
  57.    
  58.     function sendKey($keyCode)
  59.     {
  60.         return $this->createRequest(
  61.             'nrc/control_0',
  62.             'panasonic-com:service:p00NetworkControl:1',
  63.             'X_SendKey',
  64.             array(
  65.                 'args' => '<X_KeyEvent>' . $keyCode . '</X_KeyEvent>',
  66.                 'returnXml' => true
  67.             )
  68.         );
  69.     }
  70.    
  71.     function getMute()
  72.     {
  73.         return $this->createRequest(
  74.             'dmr/control_0',
  75.             'schemas-upnp-org:service:RenderingControl:1',
  76.             'GetMute',
  77.             array('args' => '<InstanceID>0</InstanceID><Channel>Master</Channel>')
  78.         );
  79.     }
  80.    
  81.     function setMute($enable = false)
  82.     {
  83.         $data = ($enable) ? '1' : '0';
  84.         return $this->createRequest(
  85.             'dmr/control_0',
  86.             'schemas-upnp-org:service:RenderingControl:1',
  87.             'SetMute',
  88.             array('args' => '<InstanceID>0</InstanceID><Channel>Master</Channel><DesiredMute>'.$data.'</DesiredMute>')
  89.         );
  90.     }
  91.  
  92.     function setVolume($volume = '0')
  93.     {
  94.         $volume = intval($volume);
  95.         if ($volume > 100 || $volume < 0)
  96.             throw new Exception('Bad request to volume control. Must be between 0 and 100');
  97.            
  98.         return $this->createRequest(
  99.             'dmr/control_0',
  100.             'schemas-upnp-org:service:RenderingControl:1',
  101.             'SetVolume',
  102.             array('args' => '<InstanceID>0</InstanceID><Channel>Master</Channel><DesiredVolume>'.$volume.'</DesiredVolume>', 'returnXml' => true)
  103.         );
  104.     }
  105.    
  106.     function sendString($string)
  107.     {
  108.         return $this->createRequest(
  109.             'nrc/control_0',
  110.             'panasonic-com:service:p00NetworkControl:1',
  111.             'X_SendString',
  112.             array(
  113.                 'args' => '<X_String>' . $string . '</X_String>',
  114.                 'returnXml' => true
  115.             )
  116.         );     
  117.     }
  118. }
  119.  
  120. $keys = array(
  121.     "NRC_CH_DOWN-ONOFF", // channel down
  122.     "NRC_CH_UP-ONOFF", // channel up
  123.     "NRC_VOLUP-ONOFF", // volume up
  124.     "NRC_VOLDOWN-ONOFF", // volume down
  125.     "NRC_MUTE-ONOFF", // mute
  126.     "NRC_TV-ONOFF", // TV
  127.     "NRC_CHG_INPUT-ONOFF", // AV,
  128.     "NRC_RED-ONOFF", // red
  129.     "NRC_GREEN-ONOFF", // green
  130.     "NRC_YELLOW-ONOFF", // yellow
  131.     "NRC_BLUE-ONOFF", // blue
  132.     "NRC_VTOOLS-ONOFF", // VIERA tools
  133.     "NRC_CANCEL-ONOFF", // Cancel / Exit
  134.     "NRC_SUBMENU-ONOFF", // Option
  135.     "NRC_RETURN-ONOFF", // Return
  136.     "NRC_ENTER-ONOFF", // Control Center click / enter
  137.     "NRC_RIGHT-ONOFF", // Control RIGHT
  138.     "NRC_LEFT-ONOFF", // Control LEFT
  139.     "NRC_UP-ONOFF", // Control UP
  140.     "NRC_DOWN-ONOFF", // Control DOWN
  141.     "NRC_3D-ONOFF", // 3D button
  142.     "NRC_SD_CARD-ONOFF", // SD-card
  143.     "NRC_DISP_MODE-ONOFF", // Display mode / Aspect ratio
  144.     "NRC_MENU-ONOFF", // Menu
  145.     "NRC_INTERNET-ONOFF", // VIERA connect
  146.     "NRC_VIERA_LINK-ONOFF", // VIERA link
  147.     "NRC_EPG-ONOFF", // Guide / EPG
  148.     "NRC_TEXT-ONOFF", // Text / TTV
  149.     "NRC_STTL-ONOFF", // STTL / Subtitles
  150.     "NRC_INFO-ONOFF", // info
  151.     "NRC_INDEX-ONOFF", // TTV index
  152.     "NRC_HOLD-ONOFF", // TTV hold / image freeze
  153.     "NRC_R_TUNE-ONOFF", // Last view
  154.     "NRC_POWER-ONOFF", // Power off
  155.    
  156.     "NRC_REW-ONOFF", // rewind
  157.     "NRC_PLAY-ONOFF", // play
  158.     "NRC_FF-ONOFF", // fast forward
  159.     "NRC_SKIP_PREV-ONOFF", // skip previous
  160.     "NRC_PAUSE-ONOFF", // pause
  161.     "NRC_SKIP_NEXT-ONOFF", // skip next
  162.     "NRC_STOP-ONOFF", // stop
  163.     "NRC_REC-ONOFF", // record
  164.    
  165.     // numeric buttons
  166.     "NRC_D1-ONOFF", "NRC_D2-ONOFF", "NRC_D3-ONOFF", "NRC_D4-ONOFF", "NRC_D5-ONOFF",
  167.     "NRC_D6-ONOFF", "NRC_D7-ONOFF", "NRC_D8-ONOFF", "NRC_D9-ONOFF", "NRC_D0-ONOFF",
  168.    
  169.     // The below commands were not avaliable in the iPhone app when using my
  170.     // VIERA G30 - they were pulled out from a disassembly instead
  171.     // only these top three did anything on my TV
  172.    
  173.     "NRC_P_NR-ONOFF", // P-NR (Noise reduction)
  174.     "NRC_OFFTIMER-ONOFF", // off timer
  175.     "NRC_R_TUNE-ONOFF", // Seems to do the same as INFO
  176.    
  177.     "NRC_CHG_NETWORK-ONOFF",
  178.     "NRC_CC-ONOFF",
  179.     "NRC_SAP-ONOFF",
  180.     "NRC_RECLIST-ONOFF",
  181.     "NRC_DRIVE-ONOFF",
  182.     "NRC_DATA-ONOFF",
  183.     "NRC_BD-ONOFF",
  184.     "NRC_FAVORITE-ONOFF",
  185.     "NRC_DIGA_CTL-ONOFF",
  186.     "NRC_VOD-ONOFF",
  187.     "NRC_ECO-ONOFF",
  188.     "NRC_GAME-ONOFF",
  189.     "NRC_EZ_SYNC-ONOFF",
  190.     "NRC_PICTAI-ONOFF",
  191.     "NRC_MPX-ONOFF",
  192.     "NRC_SPLIT-ONOFF",
  193.     "NRC_SWAP-ONOFF",
  194.     "NRC_R_SCREEN-ONOFF",
  195.     "NRC_30S_SKIP-ONOFF",
  196.     "NRC_PROG-ONOFF",
  197.     "NRC_TV_MUTE_ON-ONOFF",
  198.     "NRC_TV_MUTE_OFF-ONOFF",
  199.     "NRC_DMS_CH_UP-ONOFF",
  200.     "NRC_DMS_CH_DOWN-ONOFF"
  201.  
  202. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement