Advertisement
Guest User

VIERA control class

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