Merge pull request #7 from og01/master
[deb_libcec.git] / src / testclient / main.cpp
index 671e46e94e0749e9a7228de55d3ae73a8483b7e4..1b13848021c7bc2bf694efa0f6af90dedf9f91f3 100644 (file)
@@ -40,6 +40,7 @@
 #include <sstream>
 #include "../lib/platform/threads.h"
 #include "../lib/util/StdString.h"
+#include "../lib/implementations/CECCommandHandler.h"
 
 using namespace CEC;
 using namespace std;
@@ -226,13 +227,14 @@ void ShowHelpConsole(void)
   "[on] {address}            power on the device with the given logical address." << endl <<
   "[standby] {address}       put the device with the given address in standby mode." << endl <<
   "[la] {logical address}    change the logical address of the CEC adapter." << endl <<
-  "[p] {port number}         change the HDMI port number of the CEC adapter." << endl <<
+  "[p] {device} {port}       change the HDMI port number of the CEC adapter." << endl <<
   "[pa] {physical address}   change the physical address of the CEC adapter." << endl <<
   "[osd] {addr} {string}     set OSD message on the specified device." << endl <<
   "[ver] {addr}              get the CEC version of the specified device." << endl <<
   "[ven] {addr}              get the vendor ID of the specified device." << endl <<
   "[lang] {addr}             get the menu language of the specified device." << endl <<
   "[pow] {addr}              get the power status of the specified device." << endl <<
+  "[name] {addr}             get the OSD name of the specified device." << endl <<
   "[poll] {addr}             poll the specified device." << endl <<
   "[lad]                     lists active devices on the bus" << endl <<
   "[ad] {addr}               checks whether the specified device is active." << endl <<
@@ -240,6 +242,7 @@ void ShowHelpConsole(void)
   "[volup]                   send a volume up command to the amp if present" << endl <<
   "[voldown]                 send a volume down command to the amp if present" << endl <<
   "[mute]                    send a mute/unmute command to the amp if present" << endl <<
+  "[scan]                    scan the CEC bus and display device info" << endl <<
   "[mon] {1|0}               enable or disable CEC bus monitoring." << endl <<
   "[log] {1 - 31}            change the log level. see cectypes.h for values." << endl <<
   "[ping]                    send a ping command to the CEC adapter." << endl <<
@@ -370,7 +373,7 @@ int main (int argc, char *argv[])
       {
         if (argc >= iArgPtr + 2)
         {
-          iHDMIPortatoi(argv[iArgPtr + 1]);
+          iHDMIPort = (int8_t)atoi(argv[iArgPtr + 1]);
           cout << "using HDMI port '" << iHDMIPort << "'" << endl;
           ++iArgPtr;
         }
@@ -442,7 +445,7 @@ int main (int argc, char *argv[])
 
   if (iHDMIPort > 0)
   {
-    parser->SetHDMIPort((uint8_t)iHDMIPort);
+    parser->SetHDMIPort((cec_logical_address)CEC_DEFAULT_BASE_DEVICE, (uint8_t)iHDMIPort);
     FlushLog(parser);
   }
 
@@ -557,10 +560,10 @@ int main (int argc, char *argv[])
         }
         else if (command == "p")
         {
-          string strvalue;
-          if (GetWord(input, strvalue))
+          string strPort, strDevice;
+          if (GetWord(input, strDevice) && GetWord(input, strPort))
           {
-            parser->SetHDMIPort(atoi(strvalue.c_str()));
+            parser->SetHDMIPort((cec_logical_address)atoi(strDevice.c_str()), (uint8_t)atoi(strPort.c_str()));
           }
         }
         else if (command == "pa")
@@ -599,15 +602,21 @@ int main (int argc, char *argv[])
         }
         else if (command == "volup")
         {
-          parser->VolumeUp();
+          CStdString strLog;
+          strLog.Format("volume up: %2X", parser->VolumeUp());
+          cout << strLog.c_str() << endl;
         }
         else if (command == "voldown")
         {
-          parser->VolumeDown();
+          CStdString strLog;
+          strLog.Format("volume up: %2X", parser->VolumeDown());
+          cout << strLog.c_str() << endl;
         }
         else if (command == "mute")
         {
-          parser->MuteAudio();
+          CStdString strLog;
+          strLog.Format("mute: %2X", parser->MuteAudio());
+          cout << strLog.c_str() << endl;
         }
         else if (command == "mon")
         {
@@ -714,13 +723,52 @@ int main (int argc, char *argv[])
             }
           }
         }
+        else if (command == "name")
+        {
+          CStdString strDev;
+          if (GetWord(input, strDev))
+          {
+            int iDev = atoi(strDev);
+            if (iDev >= 0 && iDev < 15)
+            {
+              cec_osd_name name = parser->GetOSDName((cec_logical_address)iDev);
+              cout << "OSD name of device " << iDev << " is '" << name.name << "'" << endl;
+            }
+          }
+        }
         else if (command == "lad")
         {
           cout << "listing active devices:" << endl;
           cec_logical_addresses addresses = parser->GetActiveDevices();
-          for (unsigned iPtr = 0; iPtr < 16; iPtr++)
+          for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
             if (addresses[iPtr])
-              cout << "logical address " << iPtr << endl;
+              cout << "logical address " << (int)iPtr << endl;
+        }
+        else if (command == "scan")
+        {
+          cout << "CEC bus information" << endl;
+          cout << "===================" << endl;
+          cec_logical_addresses addresses = parser->GetActiveDevices();
+          for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
+            if (addresses[iPtr])
+            {
+              uint64_t iVendorId      = parser->GetDeviceVendorId((cec_logical_address)iPtr);
+              cec_version iCecVersion = parser->GetDeviceCecVersion((cec_logical_address)iPtr);
+              cec_power_status power  = parser->GetDevicePowerStatus((cec_logical_address)iPtr);
+              cec_osd_name osdName    = parser->GetOSDName((cec_logical_address)iPtr);
+              cec_menu_language lang;
+              lang.device = CECDEVICE_UNKNOWN;
+              parser->GetDeviceMenuLanguage((cec_logical_address)iPtr, &lang);
+
+              cout << "device #" << (int)iPtr << ": " << parser->ToString((cec_logical_address)iPtr) << endl;
+              cout << "vendor:       " << parser->ToString((cec_vendor_id)iVendorId) << endl;
+              cout << "osd string:   " << osdName.name << endl;
+              cout << "CEC version:  " << parser->ToString(iCecVersion) << endl;
+              cout << "power status: " << parser->ToString(power) << endl;
+              if ((uint8_t)lang.device == iPtr)
+                cout << "language:     " << lang.language << endl;
+              cout << endl;
+            }
         }
         else if (command == "ad")
         {