cec: added missing libCEC methods to LibCecSharp. added "scan" to the C# version...
authorLars Op den Kamp <lars@opdenkamp.eu>
Thu, 8 Dec 2011 21:29:44 +0000 (22:29 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Thu, 8 Dec 2011 21:29:44 +0000 (22:29 +0100)
src/CecSharpTester/CecSharpClient.cs
src/LibCecSharp/LibCecSharp.cpp

index 0cd6aebd7dab9f14f305be169490aae5374f8b31..3d8ec32c4588ae593750f7a463f21944a072f67e 100644 (file)
@@ -42,7 +42,7 @@ namespace CecSharpClient
     public CecSharpClient()
     {
       CecDeviceTypeList types = new CecDeviceTypeList();
-      types.Types[0] = CecDeviceType.PlaybackDevice;
+      types.Types[0] = CecDeviceType.RecordingDevice;
 
       Lib = new LibCecSharp("CEC Tester", types);
       LogLevel = (int) CecLogLevel.All;
@@ -127,43 +127,21 @@ namespace CecSharpClient
         "================================================================================" + 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 +
-        "[tx 40 00 FF 11 22 33]    sends bytes 0x40 0x00 0xFF 0x11 0x22 0x33" + System.Environment.NewLine +
-        System.Environment.NewLine +
-        "on {address}              power on the device with the given logical address." + System.Environment.NewLine +
-        "[on 5]                    power on a connected audio system" + System.Environment.NewLine +
-        System.Environment.NewLine +
-        "standby {address}         put the device with the given address in standby mode." + System.Environment.NewLine +
-        "[standby 0]               powers off the TV" + System.Environment.NewLine +
-        System.Environment.NewLine +
-        "la {logical_address}      change the logical address of the CEC adapter." + System.Environment.NewLine +
-        "[la 4]                    logical address 4" + System.Environment.NewLine +
-        System.Environment.NewLine +
-        "pa {physical_address}     change the physical address of the CEC adapter." + System.Environment.NewLine +
-        "[pa 1000]                 physical address 1.0.0.0" + System.Environment.NewLine +
-        System.Environment.NewLine +
-        "osd {addr} {string}       set OSD message on the specified device." + System.Environment.NewLine +
-        "[osd 0 Test Message]      displays 'Test Message' on the TV" + System.Environment.NewLine +
-        System.Environment.NewLine +
-        "ver {addr}                get the CEC version of the specified device." + System.Environment.NewLine +
-        "[ver 0]                   get the CEC version of the TV" + System.Environment.NewLine +
-        System.Environment.NewLine +
-        "ven {addr}                get the vendor ID of the specified device." + System.Environment.NewLine +
-        "[ven 0]                   get the vendor ID of the TV" + System.Environment.NewLine +
-        System.Environment.NewLine +
-        "lang {addr}               get the menu language of the specified device." + System.Environment.NewLine +
-        "[lang 0]                  get the menu language of the TV" + System.Environment.NewLine +
-        System.Environment.NewLine +
-        "pow {addr}                get the power status of the specified device." + System.Environment.NewLine +
-        "[pow 0]                   get the power status of the TV" + System.Environment.NewLine +
-        System.Environment.NewLine +
-        "poll {addr}               poll the specified device." + System.Environment.NewLine +
-        "[poll 0]                  sends a poll message to the TV" + 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 +
-        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 +
@@ -186,6 +164,7 @@ namespace CecSharpClient
       string command;
       while (bContinue)
       {
+        FlushLog();
         Console.WriteLine("waiting for input");
 
         command = Console.ReadLine();
@@ -280,8 +259,8 @@ namespace CecSharpClient
         {
           if (splitCommand.Length > 1)
           {
-            ulong vendor = Lib.GetDeviceVendorId((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber));
-            Console.WriteLine("Vendor ID: " + vendor);
+            CecVendorId vendor = Lib.GetDeviceVendorId((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber));
+            Console.WriteLine("Vendor ID: " + Lib.ToString(vendor));
           }
         }
         else if (splitCommand[0] == "ver")
@@ -289,27 +268,7 @@ namespace CecSharpClient
           if (splitCommand.Length > 1)
           {
             CecVersion version = Lib.GetDeviceCecVersion((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber));
-            switch (version)
-            {
-              case CecVersion.V1_2:
-                Console.WriteLine("CEC version 1.2");
-                break;
-              case CecVersion.V1_2A:
-                Console.WriteLine("CEC version 1.2a");
-                break;
-              case CecVersion.V1_3:
-                Console.WriteLine("CEC version 1.3");
-                break;
-              case CecVersion.V1_3A:
-                Console.WriteLine("CEC version 1.3a");
-                break;
-              case CecVersion.V1_4:
-                Console.WriteLine("CEC version 1.4");
-                break;
-              default:
-                Console.WriteLine("unknown CEC version");
-                break;
-            }
+            Console.WriteLine("CEC version: " + Lib.ToString(version));
           }
         }
         else if (splitCommand[0] == "pow")
@@ -317,24 +276,7 @@ namespace CecSharpClient
           if (splitCommand.Length > 1)
           {
             CecPowerStatus power = Lib.GetDevicePowerStatus((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber));
-            switch (power)
-            {
-              case CecPowerStatus.On:
-                Console.WriteLine("powered on");
-                break;
-              case CecPowerStatus.InTransitionOnToStandby:
-                Console.WriteLine("on -> standby");
-                break;
-              case CecPowerStatus.InTransitionStandbyToOn:
-                Console.WriteLine("standby -> on");
-                break;
-              case CecPowerStatus.Standby:
-                Console.WriteLine("standby");
-                break;
-              default:
-                Console.WriteLine("unknown power status");
-                break;
-            }
+            Console.WriteLine("power status: " + Lib.ToString(power));
           }
         }
         else if (splitCommand[0] == "r")
@@ -350,14 +292,46 @@ namespace CecSharpClient
           Console.WriteLine("setting active source");
           Lib.SetActiveSource(CecDeviceType.PlaybackDevice);
         }
+        else if (splitCommand[0] == "scan")
+        {
+          Console.WriteLine("CEC bus information");
+          Console.WriteLine("===================");
+          CecLogicalAddresses addresses = Lib.GetActiveDevices();
+          for (int iPtr = 0; iPtr < addresses.Addresses.Count(); iPtr++)
+          {
+            CecLogicalAddress address = (CecLogicalAddress)iPtr;
+            if (!addresses.IsSet(address))
+              continue;
+
+            CecVendorId iVendorId = Lib.GetDeviceVendorId(address);
+            bool bActive = Lib.IsActiveDevice(address);
+            ushort iPhysicalAddress = Lib.GetDevicePhysicalAddress(address);
+            string strAddr = string.Format("{0,4:X}", iPhysicalAddress);
+            CecVersion iCecVersion = Lib.GetDeviceCecVersion(address);
+            CecPowerStatus power = Lib.GetDevicePowerStatus(address);
+            string osdName = Lib.GetDeviceOSDName(address);
+            string lang = Lib.GetDeviceMenuLanguage(address);
+
+            StringBuilder output = new StringBuilder();
+            output.AppendLine("device #" + iPtr + ": " + Lib.ToString(address));
+            output.AppendLine("address:       " + strAddr);
+            output.AppendLine("active source: " + (bActive ? "yes" : "no"));
+            output.AppendLine("vendor:        " + Lib.ToString(iVendorId));
+            output.AppendLine("osd string:    " + osdName);
+            output.AppendLine("CEC version:   " + Lib.ToString(iCecVersion));
+            output.AppendLine("power status:  " + Lib.ToString(power));
+            if (!string.IsNullOrEmpty(lang))
+              output.AppendLine("language:      " + lang);
+
+            Console.WriteLine(output.ToString());
+          }
+        }
         else if (splitCommand[0] == "h" || splitCommand[0] == "help")
           ShowConsoleHelp();
         else if (splitCommand[0] == "q" || splitCommand[0] == "quit")
           bContinue = false;
         else if (splitCommand[0] == "log" && splitCommand.Length > 1)
-          LogLevel = int.Parse(splitCommand[1]);
-
-        FlushLog();
+          LogLevel = int.Parse(splitCommand[1]);        
       }
     }
 
index 673739a71d9e4ea1affcadabfa5058ad5b69dca9..088c9ef51c70637df6e2e7de592b4b08a070a81e 100644 (file)
@@ -228,6 +228,101 @@ public enum class CecUserControlCode
   Unknown
 };
 
+public enum class CecVendorId
+{
+  Samsung   = 0x00F0,
+  LG        = 0xE091,
+  Panasonic = 0x8045,
+  Pioneer   = 0xE036,
+  Onkyo     = 0x09B0,
+  Yamaha    = 0xA0DE,
+  Philips   = 0x903E,
+  Unknown   = 0
+};
+
+public enum class CecAudioStatus
+{
+  MuteStatusMask      = 0x80,
+  VolumeStatusMask    = 0x7F,
+  VolumeMin           = 0x00,
+  VolumeMax           = 0x64,
+  VolumeStatusUnknown = 0x7F
+};
+
+public enum class CecOpcode
+{
+  ActiveSource                  = 0x82,
+  ImageViewOn                   = 0x04,
+  TextViewOn                    = 0x0D,
+  InactiveSource                = 0x9D,
+  RequestActiveSource           = 0x85,
+  RoutingChange                 = 0x80,
+  RoutingInformation            = 0x81,
+  SetStreamPath                 = 0x86,
+  Standby                       = 0x36,
+  RecordOff                     = 0x0B,
+  RecordOn                      = 0x09,
+  RecordStatus                  = 0x0A,
+  RecordTvScreen                = 0x0F,
+  ClearAnalogueTimer            = 0x33,
+  ClearDigitalTimer             = 0x99,
+  ClearExternalTimer            = 0xA1,
+  SetAnalogueTimer              = 0x34,
+  SetDigitalTimer               = 0x97,
+  SetExternalTimer              = 0xA2,
+  SetTimerProgramTitle          = 0x67,
+  TimerClearedStatus            = 0x43,
+  TimerStatus                   = 0x35,
+  CecVersion                    = 0x9E,
+  GetCecVersion                 = 0x9F,
+  GivePhysicalAddress           = 0x83,
+  GetMenuLanguage               = 0x91,
+  ReportPhysicalAddress         = 0x84,
+  SetMenuLanguage               = 0x32,
+  DeckControl                   = 0x42,
+  DeckStatus                    = 0x1B,
+  GiveDeckStatus                = 0x1A,
+  Play                          = 0x41,
+  GiveTunerDeviceStatus         = 0x08,
+  SelectAnalogueService         = 0x92,
+  SelectDigtalService           = 0x93,
+  TunerDeviceStatus             = 0x07,
+  TunerStepDecrement            = 0x06,
+  TunerStepIncrement            = 0x05,
+  DeviceVendorId                = 0x87,
+  GiveDeviceVendorId            = 0x8C,
+  VendorCommand                 = 0x89,
+  VendorCommandWithId           = 0xA0,
+  VendorRemoteButtonDown        = 0x8A,
+  VendorRemoteButtonUp          = 0x8B,
+  SetOsdString                  = 0x64,
+  GiveOsdName                   = 0x46,
+  SetOsdName                    = 0x47,
+  MenuRequest                   = 0x8D,
+  MenuStatus                    = 0x8E,
+  UserControlPressed            = 0x44,
+  UserControlRelease            = 0x45,
+  GiveDevicePowerStatus         = 0x8F,
+  ReportPowerStatus             = 0x90,
+  FeatureAbort                  = 0x00,
+  Abort                         = 0xFF,
+  GiveAudioStatus               = 0x71,
+  GiveSystemAudioMode           = 0x7D,
+  ReportAudioStatus             = 0x7A,
+  SetSystemAudioMode            = 0x72,
+  SystemAudioModeRequest        = 0x70,
+  SystemAudioModeStatus         = 0x7E,
+  SetAudioRate                  = 0x9A,
+  /* when this opcode is set, no opcode will be sent to the device. this is one of the reserved numbers */
+  None                          = 0xFD
+};
+
+public enum class CecSystemAudioStatus
+{
+  Off = 0,
+  On  = 1
+};
+
 public ref class CecAdapter
 {
 public:
@@ -264,6 +359,11 @@ public:
       Addresses[iPtr] = CecLogicalAddress::Unregistered;
   }
 
+  bool IsSet(CecLogicalAddress iAddress)
+  {
+    return Addresses[(unsigned int)iAddress] != CecLogicalAddress::Unregistered;
+  }
+
   property array<CecLogicalAddress> ^ Addresses;
 };
 
@@ -292,7 +392,7 @@ public:
 public ref class CecCommand
 {
 public:
-  CecCommand(CecLogicalAddress iInitiator, CecLogicalAddress iDestination, bool bAck, bool bEom, int8_t iOpcode, int32_t iTransmitTimeout)
+  CecCommand(CecLogicalAddress iInitiator, CecLogicalAddress iDestination, bool bAck, bool bEom, CecOpcode iOpcode, int32_t iTransmitTimeout)
   {
     Initiator       = iInitiator;
     Destination     = iDestination;
@@ -311,7 +411,7 @@ public:
     Destination     = CecLogicalAddress::Unknown;
     Ack             = false;
     Eom             = false;
-    Opcode          = 0;
+    Opcode          = CecOpcode::None;
     OpcodeSet       = false;
     TransmitTimeout = 0;
     Parameters      = gcnew CecDatapacket;
@@ -328,7 +428,7 @@ public:
     else if (!OpcodeSet)
     {
       OpcodeSet = true;
-      Opcode    = data;
+      Opcode    = (CecOpcode)data;
     }
     else
     {
@@ -341,7 +441,7 @@ public:
   property CecLogicalAddress  Destination;
   property bool               Ack;
   property bool               Eom;
-  property int8_t             Opcode;
+  property CecOpcode          Opcode;
   property CecDatapacket ^    Parameters;
   property bool               OpcodeSet;
   property int32_t            TransmitTimeout;
@@ -508,7 +608,7 @@ public:
     cec_command command;
     if (m_libCec->GetNextCommand(&command))
     {
-      CecCommand ^ retVal = gcnew CecCommand((CecLogicalAddress)command.initiator, (CecLogicalAddress)command.destination, command.ack == 1 ? true : false, command.eom == 1 ? true : false, command.opcode, command.transmit_timeout);
+      CecCommand ^ retVal = gcnew CecCommand((CecLogicalAddress)command.initiator, (CecLogicalAddress)command.destination, command.ack == 1 ? true : false, command.eom == 1 ? true : false, (CecOpcode)command.opcode, command.transmit_timeout);
       for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++)
         retVal->Parameters->PushBack(command.parameters[iPtr]);
       return retVal;
@@ -612,9 +712,9 @@ public:
     return gcnew String("");
   }
 
-  uint64_t GetDeviceVendorId(CecLogicalAddress logicalAddress)
+  CecVendorId GetDeviceVendorId(CecLogicalAddress logicalAddress)
   {
-    return m_libCec->GetDeviceVendorId((cec_logical_address) logicalAddress);
+    return (CecVendorId)m_libCec->GetDeviceVendorId((cec_logical_address) logicalAddress);
   }
 
   CecPowerStatus GetDevicePowerStatus(CecLogicalAddress logicalAddress)
@@ -692,6 +792,71 @@ public:
     return m_libCec->IsActiveSource((cec_logical_address)logicalAddress);
   }
 
+  uint16_t GetDevicePhysicalAddress(CecLogicalAddress iAddress)
+  {
+    return m_libCec->GetDevicePhysicalAddress((cec_logical_address)iAddress);
+  }
+
+  String ^ ToString(CecLogicalAddress iAddress)
+  {
+    const char *retVal = m_libCec->ToString((cec_logical_address)iAddress);
+    return gcnew String(retVal);
+  }
+
+  String ^ ToString(CecVendorId iVendorId)
+  {
+    const char *retVal = m_libCec->ToString((cec_vendor_id)iVendorId);
+    return gcnew String(retVal);
+  }
+  
+  String ^ ToString(CecVersion iVersion)
+  {
+    const char *retVal = m_libCec->ToString((cec_version)iVersion);
+    return gcnew String(retVal);
+  }
+  
+  String ^ ToString(CecPowerStatus iState)
+  {
+    const char *retVal = m_libCec->ToString((cec_power_status)iState);
+    return gcnew String(retVal);
+  }
+
+  String ^ ToString(CecMenuState iState)
+  {
+    const char *retVal = m_libCec->ToString((cec_menu_state)iState);
+    return gcnew String(retVal);
+  }
+
+  String ^ ToString(CecDeckControlMode iMode)
+  {
+    const char *retVal = m_libCec->ToString((cec_deck_control_mode)iMode);
+    return gcnew String(retVal);
+  }
+
+  String ^ ToString(CecDeckInfo status)
+  {
+    const char *retVal = m_libCec->ToString((cec_deck_info)status);
+    return gcnew String(retVal);
+  }
+
+  String ^ ToString(CecOpcode opcode)
+  {
+    const char *retVal = m_libCec->ToString((cec_opcode)opcode);
+    return gcnew String(retVal);
+  }
+
+  String ^ ToString(CecSystemAudioStatus mode)
+  {
+    const char *retVal = m_libCec->ToString((cec_system_audio_status)mode);
+    return gcnew String(retVal);
+  }
+
+  String ^ ToString(CecAudioStatus status)
+  {
+    const char *retVal = m_libCec->ToString((cec_audio_status)status);
+    return gcnew String(retVal);
+  }
+
 private:
    ICECAdapter *m_libCec;
 };