bump to libCEC v2.1.0. closes #125
[deb_libcec.git] / src / CecSharpTester / CecSharpClient.cs
index 061a992047877beebe9b9ec6fd1d7bbc22c19579..16f7774b8488c71124a70431379e6b025d7c1b62 100644 (file)
@@ -31,7 +31,6 @@
  */
 
 using System;
-using System.Collections.Generic;
 using System.Text;
 using CecSharp;
 
@@ -44,13 +43,14 @@ namespace CecSharpClient
       Config = new LibCECConfiguration();
       Config.DeviceTypes.Types[0] = CecDeviceType.RecordingDevice;
       Config.DeviceName = "CEC Tester";
-      Config.ClientVersion = CecClientVersion.Version1_5_0;
+      Config.ClientVersion = CecClientVersion.Version2_1_0;
       Config.SetCallbacks(this);
       LogLevel = (int)CecLogLevel.All;
 
       Lib = new LibCecSharp(Config);
+      Lib.InitVideoStandalone();
 
-      Console.WriteLine("CEC Parser created - libcec version " + Lib.GetLibVersionMajor() + "." + Lib.GetLibVersionMinor());
+      Console.WriteLine("CEC Parser created - libCEC version " + Lib.ToString(Config.ServerVersion));
     }
 
     public override int ReceiveCommand(CecCommand command)
@@ -94,45 +94,7 @@ namespace CecSharpClient
       return 1;
     }
 
-    void FlushLog()
-    {
-      CecLogMessage message = Lib.GetNextLogMessage();
-      bool bGotMessage = !message.Empty;
-      while (bGotMessage)
-      {
-        if (((int)message.Level & LogLevel) == (int)message.Level)
-        {
-          string strLevel = "";
-          switch (message.Level)
-          {
-            case CecLogLevel.Error:
-              strLevel = "ERROR:   ";
-              break;
-            case CecLogLevel.Warning:
-              strLevel = "WARNING: ";
-              break;
-            case CecLogLevel.Notice:
-              strLevel = "NOTICE:  ";
-              break;
-            case CecLogLevel.Traffic:
-              strLevel = "TRAFFIC: ";
-              break;
-            case CecLogLevel.Debug:
-              strLevel = "DEBUG:   ";
-              break;
-            default:
-              break;
-          }
-          string strLog = string.Format("{0} {1,16} {2}", strLevel, message.Time, message.Message);
-          Console.WriteLine(strLog);
-        }
-
-        message = Lib.GetNextLogMessage();
-        bGotMessage = !message.Empty;
-      }
-    }
-
-    public bool Connect(int timeout)
+      public bool Connect(int timeout)
     {
       CecAdapter[] adapters = Lib.FindAdapters(string.Empty);
       if (adapters.Length > 0)
@@ -168,39 +130,36 @@ namespace CecSharpClient
     void ShowConsoleHelp()
     {
       Console.WriteLine(
-        "================================================================================" + System.Environment.NewLine +
-        "Available commands:" + System.Environment.NewLine +
-        System.Environment.NewLine +
-        "[tx] {bytes}              transfer bytes over the CEC line." + System.Environment.NewLine +
-        "[txn] {bytes}             transfer bytes but don't wait for transmission ACK." + System.Environment.NewLine +
-        "[on] {address}            power on the device with the given logical address." + System.Environment.NewLine +
-        "[standby] {address}       put the device with the given address in standby mode." + System.Environment.NewLine +
-        "[la] {logical_address}    change the logical address of the CEC adapter." + System.Environment.NewLine +
-        "[pa] {physical_address}   change the physical address of the CEC adapter." + System.Environment.NewLine +
-        "[osd] {addr} {string}     set OSD message on the specified device." + System.Environment.NewLine +
-        "[ver] {addr}              get the CEC version of the specified device." + System.Environment.NewLine +
-        "[ven] {addr}              get the vendor ID of the specified device." + System.Environment.NewLine +
-        "[lang] {addr}             get the menu language of the specified device." + System.Environment.NewLine +
-        "[pow] {addr}              get the power status of the specified device." + System.Environment.NewLine +
-        "[poll] {addr}             poll the specified device." + System.Environment.NewLine +
-        "[scan]                    scan the CEC bus and display device info" + System.Environment.NewLine +
-        "[mon] {1|0}               enable or disable CEC bus monitoring." + System.Environment.NewLine +
-        "[log] {1 - 31}            change the log level. see cectypes.h for values." + System.Environment.NewLine +
-        "[ping]                    send a ping command to the CEC adapter." + System.Environment.NewLine +
-        "[bl]                      to let the adapter enter the bootloader, to upgrade" + System.Environment.NewLine +
-        "                          the flash rom." + System.Environment.NewLine +
-        "[r]                       reconnect to the CEC adapter." + System.Environment.NewLine +
-        "[h] or [help]             show this help." + System.Environment.NewLine +
-        "[q] or [quit]             to quit the CEC test client and switch off all" + System.Environment.NewLine +
-        "                          connected CEC devices." + System.Environment.NewLine +
+        "================================================================================" + Environment.NewLine +
+        "Available commands:" + Environment.NewLine +
+        Environment.NewLine +
+        "[tx] {bytes}              transfer bytes over the CEC line." + Environment.NewLine +
+        "[txn] {bytes}             transfer bytes but don't wait for transmission ACK." + Environment.NewLine +
+        "[on] {address}            power on the device with the given logical address." + Environment.NewLine +
+        "[standby] {address}       put the device with the given address in standby mode." + Environment.NewLine +
+        "[la] {logical_address}    change the logical address of the CEC adapter." + Environment.NewLine +
+        "[pa] {physical_address}   change the physical address of the CEC adapter." + Environment.NewLine +
+        "[osd] {addr} {string}     set OSD message on the specified device." + Environment.NewLine +
+        "[ver] {addr}              get the CEC version of the specified device." + Environment.NewLine +
+        "[ven] {addr}              get the vendor ID of the specified device." + Environment.NewLine +
+        "[lang] {addr}             get the menu language of the specified device." + Environment.NewLine +
+        "[pow] {addr}              get the power status of the specified device." + Environment.NewLine +
+        "[poll] {addr}             poll the specified device." + Environment.NewLine +
+        "[scan]                    scan the CEC bus and display device info" + Environment.NewLine +
+        "[mon] {1|0}               enable or disable CEC bus monitoring." + Environment.NewLine +
+        "[log] {1 - 31}            change the log level. see cectypes.h for values." + Environment.NewLine +
+        "[ping]                    send a ping command to the CEC adapter." + Environment.NewLine +
+        "[bl]                      to let the adapter enter the bootloader, to upgrade" + Environment.NewLine +
+        "                          the flash rom." + Environment.NewLine +
+        "[r]                       reconnect to the CEC adapter." + Environment.NewLine +
+        "[h] or [help]             show this help." + Environment.NewLine +
+        "[q] or [quit]             to quit the CEC test client and switch off all" + Environment.NewLine +
+        "                          connected CEC devices." + Environment.NewLine +
         "================================================================================");
     }
 
     public void MainLoop()
     {
-      Lib.PowerOnDevices(CecLogicalAddress.Tv);
-      Lib.SetActiveSource(CecDeviceType.PlaybackDevice);
-
       bool bContinue = true;
       string command;
       while (bContinue)
@@ -208,7 +167,7 @@ namespace CecSharpClient
         Console.WriteLine("waiting for input");
 
         command = Console.ReadLine();
-        if (command.Length == 0)
+        if (command != null && command.Length == 0)
           continue;
         string[] splitCommand = command.Split(' ');
         if (splitCommand[0] == "tx" || splitCommand[0] == "txn")