Merge branch 'development'
authorLars Op den Kamp <lars@opdenkamp.eu>
Sat, 28 Apr 2012 00:03:41 +0000 (02:03 +0200)
committerLars Op den Kamp <lars@opdenkamp.eu>
Sat, 28 Apr 2012 00:03:41 +0000 (02:03 +0200)
53 files changed:
ChangeLog
Makefile.am
debian/changelog
include/cec.h
include/cectypes.h
project/LibCecSharp.vcproj
project/cec-config.rc
project/libcec.rc
project/testclient.rc
src/CecSharpTester/CecSharpClient.cs
src/CecSharpTester/Properties/AssemblyInfo.cs
src/LibCecSharp/AssemblyInfo.cpp
src/LibCecSharp/CecSharpTypes.h
src/LibCecSharp/LibCecSharp.cpp
src/cec-config-gui/Properties/AssemblyInfo.cs
src/cec-config/cec-config.cpp
src/lib/CECProcessor.cpp
src/lib/CECProcessor.h
src/lib/LibCEC.cpp
src/lib/LibCEC.h
src/lib/adapter/AdapterCommunication.h
src/lib/adapter/USBCECAdapterCommands.cpp
src/lib/adapter/USBCECAdapterCommands.h
src/lib/adapter/USBCECAdapterCommunication.cpp
src/lib/adapter/USBCECAdapterCommunication.h
src/lib/adapter/USBCECAdapterMessage.cpp
src/lib/adapter/USBCECAdapterMessage.h
src/lib/adapter/USBCECAdapterMessageQueue.cpp
src/lib/adapter/USBCECAdapterMessageQueue.h
src/lib/devices/CECAudioSystem.cpp
src/lib/devices/CECAudioSystem.h
src/lib/devices/CECBusDevice.cpp
src/lib/devices/CECBusDevice.h
src/lib/devices/CECPlaybackDevice.cpp
src/lib/devices/CECPlaybackDevice.h
src/lib/devices/CECRecordingDevice.cpp
src/lib/devices/CECRecordingDevice.h
src/lib/devices/CECTV.cpp
src/lib/devices/CECTV.h
src/lib/devices/CECTuner.cpp
src/lib/devices/CECTuner.h
src/lib/implementations/ANCommandHandler.h
src/lib/implementations/CECCommandHandler.cpp
src/lib/implementations/CECCommandHandler.h
src/lib/implementations/RLCommandHandler.h
src/lib/implementations/SLCommandHandler.cpp
src/lib/implementations/SLCommandHandler.h
src/lib/implementations/VLCommandHandler.cpp
src/lib/implementations/VLCommandHandler.h
src/lib/platform/posix/os-threads.h
src/lib/platform/threads/threads.h
src/lib/platform/util/buffer.h
src/testclient/main.cpp

index d3b160e802b425813b64e25a0c2d3b1c6913fde1..aad871a0cbf9acf313f713634f76cef3fce5f4a1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,91 @@
+libcec (1.6-3) unstable; urgency=low
+
+  * changed/added:
+    * cec-client: show the firmware build date if available in cec-client -l
+    * cec-client: don't activate the source when starting
+    * cec-client: group up the output of the 'scan' command, and add the
+      currently active source to the output
+    * log the libCEC version in the 'connected to the CEC adapter' log entry,
+      and add the firmware build date to the line if it's available, so all
+      relevant version info is available in 1 log line.
+    * async writes for CUSBCECAdapterCommunication. less locks and polls, more
+      speed
+    * added 'make docs' target, that updates the doxygen documentation
+
+  * interface changes:
+    * added operator == and != for libcec_configuration
+    * added GetResponseOpcode(cec_opcode opcode) to cec_command
+    * added the firmware build date to libcec_configuration, so it can be
+      displayed by the client too.
+    * added static CLibCEC::Alert() method and CEC_ALERT_CONNECTION_LOST value
+    * added a callback to handle menu state changes. if the callback method
+      returns 1, then the change is processed by the CCECBusDevice too. if 0,
+      then the CCECBusDevice will always have menu state 'activated', so
+      keypresses are routed. bugzid: 724
+    * added a default menu language to libcec_configuration and set this
+      language for devices controlled by libcec. bugzid: 69
+
+  * fixed
+    * CCECProcessor::IsActiveSource() - TV was never checked
+    * don't call the deprecated SetActiveView() method in cec-client
+    * request the active source if unknown in CCECProcessor::GetActiveSource()
+    * don't try to match a device with PA 0xFFFF.
+    * don't change the power status of a device when changing the stream path
+    * don't set the power status to 'powered off' when marking the source
+      managed by libcec as inactive, or the tv will might send a power control
+      keycode when making it active again, potentially shutting down the system
+    * potential segfault in CCECProcessor::GetDeviceByPhysicalAddress()
+    * stream path changes when changed to the TV source (PA 0)
+    * clear the unsupported features list in CCECBusDevice::ResetDeviceStatus()
+    * never mark vendor commands as unsupported (only some may be unsupported),
+      as well as some others that should never be marked unsupported
+    * don't retry in CCECCommandHandler if the command has been marked as
+      unsupported
+    * don't request the PA of devices when handling an incoming CEC command, or
+      it'll block things while waiting for a response. if that response never
+      comes, or comes late, then other incoming commands will be timed out
+      before they are handled
+    * optimisation - strip unneeded virtual keywords from top level
+      implementations
+    * use the vlcommandhandler for the primary device that is handled by libCEC
+      when a panasonic tv is detected, so delayed activate source commands are
+      using the correct handler. bugzid: 723
+    * set the power status of device controlled by libCEC to
+      CEC_POWER_STATUS_ON
+      instead of IN_TRANSITION_STANDBY_TO_ON. reset the device status of a
+      device if it was detected as removed. bugzid: 755
+    * potentially uninitialised values in cec_command
+    * delay the 'active source' command for panasonic, until the vendor command
+      that reports that the TV is powered on has been received. bugzid: 723
+    * only respond to Give Physical Address with Report Physical Address.
+      bugzid: 592
+      This fixes several reports of the TV improperly switching to the libcec
+      device after it has previously switched to another source. Fix confirmed
+      with Panasonic and also reported to be an issue with Samsung and
+      Philips.
+    * check whether callback methods are set to a valid ptr
+    * number of retries for polls
+    * win32: fix build in paths with spaces. bugzid: 730
+    * LibCecSharp: free the alert GC callback when cleaning up
+    * the wrong setting was being read when powering on devices
+    * close the connection when a comm error was detected, and notify the
+      client via an alert
+    * don't segfault when calling ThreadsWait() without a valid thread
+    * lib/platform: fixed memleak
+    * leak in CCECAdapterMessageQueue::Write
+    * don't send commands if we know them to be unsupported. bugzid: 725
+
+ -- Pulse-Eight Packaging <packaging@pulse-eight.com>  Wed, 18 Apr 2012 11:30:00 +0100
+
+libcec (1.6-2) unstable; urgency=low
+
+  * fixed:
+    * fixed typo in CUSBCECAdapterCommands::RequestSettings() that prevented
+      the settings from being read. the settings were still written, but never
+      read when bGetSettingsFromROM = 1.
+
+ -- Pulse-Eight Packaging <packaging@pulse-eight.com>  Wed, 18 Apr 2012 11:30:00 +0100
+
 libcec (1.6-1) unstable; urgency=medium
 
   * changed/added:
index 471d2bd027c580df4edd448ac8952ee6eb52249e..6c69f517255ce970c8a7404adf2708b40b3a3885 100644 (file)
@@ -1 +1,5 @@
-SUBDIRS = src/lib src/testclient src/cec-config
\ No newline at end of file
+SUBDIRS = src/lib src/testclient src/cec-config
+
+docs:
+       echo "Updating documentation (if doxygen is present)"
+       doxygen
index a04a10017101f46687a3d310d26b261e7aa3a7dd..aad871a0cbf9acf313f713634f76cef3fce5f4a1 100644 (file)
@@ -1,3 +1,82 @@
+libcec (1.6-3) unstable; urgency=low
+
+  * changed/added:
+    * cec-client: show the firmware build date if available in cec-client -l
+    * cec-client: don't activate the source when starting
+    * cec-client: group up the output of the 'scan' command, and add the
+      currently active source to the output
+    * log the libCEC version in the 'connected to the CEC adapter' log entry,
+      and add the firmware build date to the line if it's available, so all
+      relevant version info is available in 1 log line.
+    * async writes for CUSBCECAdapterCommunication. less locks and polls, more
+      speed
+    * added 'make docs' target, that updates the doxygen documentation
+
+  * interface changes:
+    * added operator == and != for libcec_configuration
+    * added GetResponseOpcode(cec_opcode opcode) to cec_command
+    * added the firmware build date to libcec_configuration, so it can be
+      displayed by the client too.
+    * added static CLibCEC::Alert() method and CEC_ALERT_CONNECTION_LOST value
+    * added a callback to handle menu state changes. if the callback method
+      returns 1, then the change is processed by the CCECBusDevice too. if 0,
+      then the CCECBusDevice will always have menu state 'activated', so
+      keypresses are routed. bugzid: 724
+    * added a default menu language to libcec_configuration and set this
+      language for devices controlled by libcec. bugzid: 69
+
+  * fixed
+    * CCECProcessor::IsActiveSource() - TV was never checked
+    * don't call the deprecated SetActiveView() method in cec-client
+    * request the active source if unknown in CCECProcessor::GetActiveSource()
+    * don't try to match a device with PA 0xFFFF.
+    * don't change the power status of a device when changing the stream path
+    * don't set the power status to 'powered off' when marking the source
+      managed by libcec as inactive, or the tv will might send a power control
+      keycode when making it active again, potentially shutting down the system
+    * potential segfault in CCECProcessor::GetDeviceByPhysicalAddress()
+    * stream path changes when changed to the TV source (PA 0)
+    * clear the unsupported features list in CCECBusDevice::ResetDeviceStatus()
+    * never mark vendor commands as unsupported (only some may be unsupported),
+      as well as some others that should never be marked unsupported
+    * don't retry in CCECCommandHandler if the command has been marked as
+      unsupported
+    * don't request the PA of devices when handling an incoming CEC command, or
+      it'll block things while waiting for a response. if that response never
+      comes, or comes late, then other incoming commands will be timed out
+      before they are handled
+    * optimisation - strip unneeded virtual keywords from top level
+      implementations
+    * use the vlcommandhandler for the primary device that is handled by libCEC
+      when a panasonic tv is detected, so delayed activate source commands are
+      using the correct handler. bugzid: 723
+    * set the power status of device controlled by libCEC to
+      CEC_POWER_STATUS_ON
+      instead of IN_TRANSITION_STANDBY_TO_ON. reset the device status of a
+      device if it was detected as removed. bugzid: 755
+    * potentially uninitialised values in cec_command
+    * delay the 'active source' command for panasonic, until the vendor command
+      that reports that the TV is powered on has been received. bugzid: 723
+    * only respond to Give Physical Address with Report Physical Address.
+      bugzid: 592
+      This fixes several reports of the TV improperly switching to the libcec
+      device after it has previously switched to another source. Fix confirmed
+      with Panasonic and also reported to be an issue with Samsung and
+      Philips.
+    * check whether callback methods are set to a valid ptr
+    * number of retries for polls
+    * win32: fix build in paths with spaces. bugzid: 730
+    * LibCecSharp: free the alert GC callback when cleaning up
+    * the wrong setting was being read when powering on devices
+    * close the connection when a comm error was detected, and notify the
+      client via an alert
+    * don't segfault when calling ThreadsWait() without a valid thread
+    * lib/platform: fixed memleak
+    * leak in CCECAdapterMessageQueue::Write
+    * don't send commands if we know them to be unsupported. bugzid: 725
+
+ -- Pulse-Eight Packaging <packaging@pulse-eight.com>  Wed, 18 Apr 2012 11:30:00 +0100
+
 libcec (1.6-2) unstable; urgency=low
 
   * fixed:
index f656bb8665a7c70d697bf49afe82c4aedf35dd79..fada217ef52007f514013d9b05c4a6e18f7180a2 100644 (file)
@@ -36,6 +36,8 @@
 
 #include "cectypes.h"
 
+#define LIBCEC_VERSION_CURRENT CEC_SERVER_VERSION_1_6_2
+
 namespace CEC
 {
   class ICECAdapter
index 4edf4ba3dbc36f6766447d41783e57cc10ec39ef..ca065c606051ade2507c39ab669db40004d4a308 100644 (file)
@@ -72,22 +72,44 @@ namespace CEC {
 #define CEC_BUTTON_TIMEOUT           500
 #define CEC_POWER_STATE_REFRESH_TIME 30000
 #define CEC_FW_VERSION_UNKNOWN       0xFFFF
+#define CEC_FW_BUILD_UNKNOWN         0
 #define CEC_CONNECT_TRIES            3
 
-#define CEC_DEFAULT_SETTING_USE_TV_MENU_LANGUAGE  1
-#define CEC_DEFAULT_SETTING_ACTIVATE_SOURCE       1
-#define CEC_DEFAULT_SETTING_POWER_OFF_SHUTDOWN    1
-#define CEC_DEFAULT_SETTING_POWER_OFF_SCREENSAVER 1
-#define CEC_DEFAULT_SETTING_POWER_OFF_ON_STANDBY  1
-#define CEC_DEFAULT_SETTING_SHUTDOWN_ON_STANDBY   0
-#define CEC_DEFAULT_SETTING_SEND_INACTIVE_SOURCE  1
+#define CEC_PHYSICAL_ADDRESS_TV      0
+#define CEC_MIN_PHYSICAL_ADDRESS     0x1000
+#define CEC_MAX_PHYSICAL_ADDRESS     0xFFFE
+#define CEC_INVALID_PHYSICAL_ADDRESS 0xFFFF
+
+#define CEC_MIN_VENDORID             1
+#define CEC_MAX_VENDORID             0xFFFFFE
+#define CEC_INVALID_VENDORID         0xFFFFFF
+
+#define CEC_MIN_HDMI_PORTNUMBER      1
+#define CEC_MAX_HDMI_PORTNUMBER      15
+#define CEC_HDMI_PORTNUMBER_NONE     0
+
+#define CEC_DEFAULT_SETTING_USE_TV_MENU_LANGUAGE      1
+#define CEC_DEFAULT_SETTING_ACTIVATE_SOURCE           1
+#define CEC_DEFAULT_SETTING_POWER_OFF_SHUTDOWN        1
+#define CEC_DEFAULT_SETTING_POWER_OFF_SCREENSAVER     1
+#define CEC_DEFAULT_SETTING_POWER_OFF_ON_STANDBY      1
+#define CEC_DEFAULT_SETTING_SHUTDOWN_ON_STANDBY       0
+#define CEC_DEFAULT_SETTING_SEND_INACTIVE_SOURCE      1
 #define CEC_DEFAULT_SETTING_POWER_OFF_DEVICES_STANDBY 1
+#define CEC_DEFAULT_DEVICE_LANGUAGE                   "eng"
+#define CEC_DEFAULT_SETTING_AUTODETECT_ADDRESS        1
+#define CEC_DEFAULT_SETTING_GET_SETTINGS_FROM_ROM     0
 
 #define CEC_DEFAULT_TRANSMIT_RETRY_WAIT 500
 #define CEC_DEFAULT_TRANSMIT_TIMEOUT    1000
-#define CEC_DEFAULT_TRANSMIT_WAIT       2000
+#define CEC_DEFAULT_TRANSMIT_WAIT       1000
 #define CEC_DEFAULT_TRANSMIT_RETRIES    1
 
+#define CEC_DEFAULT_CONNECT_TIMEOUT     10000
+#define CEC_DEFAULT_CONNECT_RETRY_WAIT  1000
+#define CEC_SERIAL_DEFAULT_BAUDRATE     38400
+#define CEC_CLEAR_INPUT_DEFAULT_WAIT    1000
+
 #define CEC_MIN_LIB_VERSION          1
 #define CEC_LIB_VERSION_MAJOR        1
 #define CEC_LIB_VERSION_MINOR        6
@@ -601,7 +623,7 @@ typedef enum cec_adapter_messagecode
   MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE,
   MSGCODE_FIRMWARE_VERSION,
   MSGCODE_START_BOOTLOADER,
-  MSGCODE_SET_POWERSTATE,
+  MSGCODE_GET_BUILDDATE,
   MSGCODE_SET_CONTROLLED,
   MSGCODE_GET_AUTO_ENABLED,
   MSGCODE_SET_AUTO_ENABLED,
@@ -758,6 +780,11 @@ typedef struct cec_command
   int32_t             transmit_timeout; /**< the timeout to use in ms */
 
 #ifdef __cplusplus
+  cec_command(void)
+  {
+    Clear();
+  }
+
   cec_command &operator =(const struct cec_command &command)
   {
     initiator        = command.initiator;
@@ -827,6 +854,43 @@ typedef struct cec_command
     transmit_timeout = CEC_DEFAULT_TRANSMIT_TIMEOUT;
     parameters.Clear();
   };
+
+  static cec_opcode GetResponseOpcode(cec_opcode opcode)
+  {
+    switch (opcode)
+    {
+    case CEC_OPCODE_REQUEST_ACTIVE_SOURCE:
+      return CEC_OPCODE_ACTIVE_SOURCE;
+    case CEC_OPCODE_GET_CEC_VERSION:
+      return CEC_OPCODE_CEC_VERSION;
+    case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS:
+      return CEC_OPCODE_REPORT_PHYSICAL_ADDRESS;
+    case CEC_OPCODE_GET_MENU_LANGUAGE:
+      return CEC_OPCODE_SET_MENU_LANGUAGE;
+    case CEC_OPCODE_GIVE_DECK_STATUS:
+      return CEC_OPCODE_DECK_STATUS;
+    case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS:
+      return CEC_OPCODE_TUNER_DEVICE_STATUS;
+    case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID:
+      return CEC_OPCODE_DEVICE_VENDOR_ID;
+    case CEC_OPCODE_GIVE_OSD_NAME:
+      return CEC_OPCODE_SET_OSD_NAME;
+    case CEC_OPCODE_MENU_REQUEST:
+      return CEC_OPCODE_MENU_STATUS;
+    case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS:
+      return CEC_OPCODE_REPORT_POWER_STATUS;
+    case CEC_OPCODE_GIVE_AUDIO_STATUS:
+      return CEC_OPCODE_REPORT_AUDIO_STATUS;
+    case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS:
+      return CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS;
+    case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST:
+      return CEC_OPCODE_SET_SYSTEM_AUDIO_MODE;
+    default:
+      break;
+    }
+
+    return CEC_OPCODE_NONE;
+  }
 #endif
 } cec_command;
 
@@ -1016,7 +1080,8 @@ typedef struct cec_logical_addresses
 
 typedef enum libcec_alert
 {
-  CEC_ALERT_SERVICE_DEVICE
+  CEC_ALERT_SERVICE_DEVICE,
+  CEC_ALERT_CONNECTION_LOST
 } libcec_alert;
 
 typedef enum libcec_parameter_type
@@ -1037,6 +1102,7 @@ typedef int (CEC_CDECL* CBCecKeyPressType)(void *param, const cec_keypress &);
 typedef int (CEC_CDECL* CBCecCommandType)(void *param, const cec_command &);
 typedef int (CEC_CDECL* CBCecConfigurationChangedType)(void *param, const libcec_configuration &);
 typedef int (CEC_CDECL* CBCecAlertType)(void *param, const libcec_alert, const libcec_parameter &);
+typedef int (CEC_CDECL* CBCecMenuStateChangedType)(void *param, const cec_menu_state);
 
 typedef struct ICECCallbacks
 {
@@ -1075,6 +1141,32 @@ typedef struct ICECCallbacks
    * @return 1 when ok, 0 otherwise
    */
   CBCecAlertType CBCecAlert;
+
+  /*!
+   * @brief Transfer a menu state change to the client.
+   * Transfer a menu state change to the client. If the command returns 1, then the change will be processed by
+   * the busdevice. If 0, then the state of the busdevice won't be changed, and will always be kept 'activated',
+   * @warning CEC does not allow the player to suppress the menu state change on the TV, so the menu on the TV will always be displayed, whatever the return value of this method is.
+   * so keypresses are always routed.
+   * @param newVal The new value.
+   * @return 1 when libCEC should use this new value, 0 otherwise.
+   */
+  CBCecMenuStateChangedType CBCecMenuStateChanged;
+
+#ifdef __cplusplus
+   ICECCallbacks(void) { Clear(); }
+  ~ICECCallbacks(void) { Clear(); };
+
+  void Clear(void)
+  {
+    CBCecLogMessage           = NULL;
+    CBCecKeyPress             = NULL;
+    CBCecCommand              = NULL;
+    CBCecConfigurationChanged = NULL;
+    CBCecAlert                = NULL;
+    CBCecMenuStateChanged     = NULL;
+  }
+#endif
 } ICECCallbacks;
 
 typedef enum cec_client_version
@@ -1085,7 +1177,8 @@ typedef enum cec_client_version
   CEC_CLIENT_VERSION_1_5_2   = 0x1502,
   CEC_CLIENT_VERSION_1_5_3   = 0x1503,
   CEC_CLIENT_VERSION_1_6_0   = 0x1600,
-  CEC_CLIENT_VERSION_1_6_1   = 0x1601
+  CEC_CLIENT_VERSION_1_6_1   = 0x1601,
+  CEC_CLIENT_VERSION_1_6_2   = 0x1602
 } cec_client_version;
 
 typedef enum cec_server_version
@@ -1096,7 +1189,8 @@ typedef enum cec_server_version
   CEC_SERVER_VERSION_1_5_2   = 0x1502,
   CEC_SERVER_VERSION_1_5_3   = 0x1503,
   CEC_SERVER_VERSION_1_6_0   = 0x1600,
-  CEC_SERVER_VERSION_1_6_1   = 0x1601
+  CEC_SERVER_VERSION_1_6_1   = 0x1601,
+  CEC_SERVER_VERSION_1_6_2   = 0x1602
 } cec_server_version;
 
 typedef struct libcec_configuration
@@ -1129,44 +1223,87 @@ typedef struct libcec_configuration
   uint16_t              iFirmwareVersion;     /*!< the firmware version of the adapter. added in 1.6.0 */
   uint8_t               bPowerOffDevicesOnStandby; /*!< put devices in standby when the PC/player is put in standby. added in 1.6.0 */
   uint8_t               bShutdownOnStandby;   /*!< shutdown this PC when the TV is switched off. only used when bPowerOffOnStandby = 0. added in 1.6.0 */
+  char                  strDeviceLanguage[3]; /*!< the menu language used by the client. 3 character ISO 639-2 country code. see http://http://www.loc.gov/standards/iso639-2/ added in 1.6.2 */
+  uint32_t              iFirmwareBuildDate;   /*!< the build date of the firmware, in seconds since epoch. if not available, this value will be set to 0. added in 1.6.2 */
 
 #ifdef __cplusplus
+   libcec_configuration(void) { Clear(); }
+  ~libcec_configuration(void) { Clear(); }
+
+  bool operator==(const libcec_configuration &other) const
+  {
+    return (     clientVersion        == other.clientVersion &&
+        !strncmp(strDeviceName,          other.strDeviceName, 13) &&
+                 deviceTypes          == other.deviceTypes &&
+                 bAutodetectAddress   == other.bAutodetectAddress &&
+                 iPhysicalAddress     == other.iPhysicalAddress &&
+                 baseDevice           == other.baseDevice &&
+                 iHDMIPort            == other.iHDMIPort &&
+                 tvVendor             == other.tvVendor &&
+                 wakeDevices          == other.wakeDevices &&
+                 powerOffDevices      == other.powerOffDevices &&
+                 serverVersion        == other.serverVersion &&
+                 bGetSettingsFromROM  == other.bGetSettingsFromROM &&
+                 bUseTVMenuLanguage   == other.bUseTVMenuLanguage &&
+                 bActivateSource      == other.bActivateSource &&
+                 bPowerOffScreensaver == other.bPowerOffScreensaver &&
+                 bPowerOffOnStandby   == other.bPowerOffOnStandby &&
+                 bSendInactiveSource  == other.bSendInactiveSource &&
+        /* libcec 1.5.3+ */
+        (other.serverVersion < CEC_SERVER_VERSION_1_5_3 || logicalAddresses == other.logicalAddresses) &&
+        /* libcec 1.6.0+ */
+        (other.serverVersion < CEC_SERVER_VERSION_1_6_0 || iFirmwareVersion          == other.iFirmwareVersion) &&
+        (other.serverVersion < CEC_SERVER_VERSION_1_6_0 || bPowerOffDevicesOnStandby == other.bPowerOffDevicesOnStandby) &&
+        (other.serverVersion < CEC_SERVER_VERSION_1_6_0 || bShutdownOnStandby        == other.bShutdownOnStandby) &&
+        /* libcec 1.6.2+ */
+        (other.serverVersion < CEC_SERVER_VERSION_1_6_2 || !strncmp(strDeviceLanguage, other.strDeviceLanguage, 3)) &&
+        (other.serverVersion < CEC_SERVER_VERSION_1_6_2 || iFirmwareBuildDate       == other.iFirmwareBuildDate));
+  }
+
+  bool operator!=(const libcec_configuration &other) const
+  {
+    return !(*this == other);
+  }
+
   /*!
    * @brief Reset this configution struct to the default values.
    */
   void Clear(void)
   {
+    iPhysicalAddress =                CEC_PHYSICAL_ADDRESS_TV;
+    baseDevice = (cec_logical_address)CEC_DEFAULT_BASE_DEVICE;
+    iHDMIPort =                       CEC_DEFAULT_HDMI_PORT;
+    tvVendor =              (uint64_t)CEC_VENDOR_UNKNOWN;
+    clientVersion =         (uint32_t)CEC_CLIENT_VERSION_PRE_1_5;
+    serverVersion =         (uint32_t)CEC_SERVER_VERSION_PRE_1_5;
+    bAutodetectAddress =              CEC_DEFAULT_SETTING_AUTODETECT_ADDRESS;
+    bGetSettingsFromROM =             CEC_DEFAULT_SETTING_GET_SETTINGS_FROM_ROM;
+    bUseTVMenuLanguage =              CEC_DEFAULT_SETTING_USE_TV_MENU_LANGUAGE;
+    bActivateSource =                 CEC_DEFAULT_SETTING_ACTIVATE_SOURCE;
+    bPowerOffScreensaver =            CEC_DEFAULT_SETTING_POWER_OFF_SCREENSAVER;
+    bPowerOffOnStandby =              CEC_DEFAULT_SETTING_POWER_OFF_ON_STANDBY;
+    bShutdownOnStandby =              CEC_DEFAULT_SETTING_SHUTDOWN_ON_STANDBY;
+    bSendInactiveSource =             CEC_DEFAULT_SETTING_SEND_INACTIVE_SOURCE;
+    iFirmwareVersion =                CEC_FW_VERSION_UNKNOWN;
+    bPowerOffDevicesOnStandby =       CEC_DEFAULT_SETTING_POWER_OFF_DEVICES_STANDBY;
+    memcpy(strDeviceLanguage,         CEC_DEFAULT_DEVICE_LANGUAGE, 3);
+    iFirmwareBuildDate =              CEC_FW_BUILD_UNKNOWN;
+
     memset(strDeviceName, 0, 13);
     deviceTypes.clear();
-    iPhysicalAddress = 0;
-    baseDevice       = (cec_logical_address)CEC_DEFAULT_BASE_DEVICE;
-    iHDMIPort        = CEC_DEFAULT_HDMI_PORT;
-    tvVendor         = (uint64_t)CEC_VENDOR_UNKNOWN;
-    clientVersion    = (uint32_t)CEC_CLIENT_VERSION_PRE_1_5;
-    serverVersion    = (uint32_t)CEC_SERVER_VERSION_PRE_1_5;
+    logicalAddresses.Clear();
     wakeDevices.Clear();
     powerOffDevices.Clear();
 
-    bAutodetectAddress   = 1;
-    bGetSettingsFromROM  = 0;
-    bUseTVMenuLanguage   = CEC_DEFAULT_SETTING_USE_TV_MENU_LANGUAGE;
-    bActivateSource      = CEC_DEFAULT_SETTING_ACTIVATE_SOURCE;
     #if CEC_DEFAULT_SETTING_POWER_OFF_SHUTDOWN == 1
     powerOffDevices.Set(CECDEVICE_BROADCAST);
     #endif
     #if CEC_DEFAULT_SETTING_ACTIVATE_SOURCE == 1
     wakeDevices.Set(CECDEVICE_TV);
     #endif
-    bPowerOffScreensaver = CEC_DEFAULT_SETTING_POWER_OFF_SCREENSAVER;
-    bPowerOffOnStandby   = CEC_DEFAULT_SETTING_POWER_OFF_ON_STANDBY;
-    bShutdownOnStandby   = CEC_DEFAULT_SETTING_SHUTDOWN_ON_STANDBY;
-    bSendInactiveSource  = CEC_DEFAULT_SETTING_SEND_INACTIVE_SOURCE;
-    logicalAddresses.Clear();
-    iFirmwareVersion          = CEC_FW_VERSION_UNKNOWN;
-    bPowerOffDevicesOnStandby = CEC_DEFAULT_SETTING_POWER_OFF_DEVICES_STANDBY;
 
-    callbackParam    = NULL;
-    callbacks        = NULL;
+    callbackParam = NULL;
+    callbacks     = NULL;
   }
 #endif
 } libcec_configuration;
index c8d3d43a2c52b51eb9f2cd919a62adfcb429862a..0f2c49293d1e4fea0b7bf50ecd29a3744832f992 100644 (file)
                        />
                        <Tool
                                Name="VCLinkerTool"
-                               AdditionalDependencies="$(OutDir)libcec.x64.lib"
-                               OutputFile="$(OutDir)\$(ProjectName).x64.dll"
+                               AdditionalDependencies="&quot;$(OutDir)libcec.x64.lib&quot;"
+                               OutputFile="&quot;$(OutDir)\$(ProjectName).x64.dll&quot;"
                                LinkIncremental="2"
                                GenerateDebugInformation="true"
                                AssemblyDebug="1"
                        />
                        <Tool
                                Name="VCLinkerTool"
-                               AdditionalDependencies="$(OutDir)libcec.x64.lib"
+                               AdditionalDependencies="&quot;$(OutDir)libcec.x64.lib&quot;"
                        />
                        <Tool
                                Name="VCALinkTool"
index 0b0f33b5c99e21b386b95a62572ae7c6a3db2bb7..fd83b8b6408a1d4d0e1d7fed4dd20fbf644601be 100644 (file)
Binary files a/project/cec-config.rc and b/project/cec-config.rc differ
index 6c5f6ee36fabe5b78c9d1558fb714a9a1fa422ae..3ff74fe5c2457b84e5e2657ca14b0fc16d29cad0 100644 (file)
Binary files a/project/libcec.rc and b/project/libcec.rc differ
index b8821e380cbed6042133fdaf9436b3a5b25ca458..bba03693151e5d56ee29e48f766d6bb4797229d0 100644 (file)
Binary files a/project/testclient.rc and b/project/testclient.rc differ
index 216382377e59744f2239769c4ea20ffeb9e21fc2..cc3fb03b7efb0137793db6091da953cdaec67c3f 100644 (file)
@@ -43,7 +43,7 @@ namespace CecSharpClient
       Config = new LibCECConfiguration();
       Config.DeviceTypes.Types[0] = CecDeviceType.RecordingDevice;
       Config.DeviceName = "CEC Tester";
-      Config.ClientVersion = CecClientVersion.Version1_6_1;
+      Config.ClientVersion = CecClientVersion.Version1_6_2;
       Config.SetCallbacks(this);
       LogLevel = (int)CecLogLevel.All;
 
index 439ae4c9035c48b6d6111095d96fe872b146d79f..a252ab27585e3e5064d00f5e3aea188e34ecdcd5 100644 (file)
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
 // You can specify all the values or you can default the Build and Revision Numbers 
 // by using the '*' as shown below:
 // [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.6.1.0")]
-[assembly: AssemblyFileVersion("1.6.1.0")]
+[assembly: AssemblyVersion("1.6.2.0")]
+[assembly: AssemblyFileVersion("1.6.2.0")]
index 6af994786c8168a7e872f773a3f25f3445c28542..6296abd61747401f517ee99bd6de7497883b69fd 100644 (file)
@@ -13,7 +13,7 @@ using namespace System::Security::Permissions;
 [assembly:AssemblyTrademarkAttribute("")];
 [assembly:AssemblyCultureAttribute("")];
 
-[assembly:AssemblyVersionAttribute("1.6.1.0")];
+[assembly:AssemblyVersionAttribute("1.6.2.0")];
 
 [assembly:ComVisible(false)];
 [assembly:CLSCompliantAttribute(true)];
index d6189257294772358f14a75b3fbdb11b8adc22c5..14630197f51a561227d005175519552b23ea502f 100644 (file)
@@ -354,7 +354,8 @@ namespace CecSharp
                Version1_5_2  = 0x1502,
                Version1_5_3  = 0x1503,
                Version1_6_0  = 0x1600,
-               Version1_6_1  = 0x1601
+               Version1_6_1  = 0x1601,
+    Version1_6_2  = 0x1602
        };
 
        public enum class CecServerVersion
@@ -365,7 +366,8 @@ namespace CecSharp
                Version1_5_2  = 0x1502,
                Version1_5_3  = 0x1503,
                Version1_6_0  = 0x1600,
-               Version1_6_1  = 0x1601
+               Version1_6_1  = 0x1601,
+    Version1_6_2  = 0x1602
        };
 
        public ref class CecAdapter
@@ -580,10 +582,13 @@ namespace CecSharp
 
                        PowerOffScreensaver = CEC_DEFAULT_SETTING_POWER_OFF_SCREENSAVER == 1;
                        PowerOffOnStandby   = CEC_DEFAULT_SETTING_POWER_OFF_ON_STANDBY == 1;
-      SendInactiveSource  = CEC_DEFAULT_SETTING_SEND_INACTIVE_SOURCE == 1;
-      LogicalAddresses    = gcnew CecLogicalAddresses();
-      FirmwareVersion     = 1;
-      PowerOffDevicesOnStandby = CEC_DEFAULT_SETTING_POWER_OFF_DEVICES_STANDBY == 1;
+
+                       SendInactiveSource  = CEC_DEFAULT_SETTING_SEND_INACTIVE_SOURCE == 1;
+                       LogicalAddresses    = gcnew CecLogicalAddresses();
+                       FirmwareVersion     = 1;
+                       PowerOffDevicesOnStandby = CEC_DEFAULT_SETTING_POWER_OFF_DEVICES_STANDBY == 1;
+                       ShutdownOnStandby   = CEC_DEFAULT_SETTING_SHUTDOWN_ON_STANDBY == 1;
+                       DeviceLanguage      = "";
                }
 
                void SetCallbacks(CecCallbackMethods ^callbacks)
@@ -624,22 +629,26 @@ namespace CecSharp
                        PowerOffScreensaver = config.bPowerOffScreensaver == 1;
                        PowerOffOnStandby = config.bPowerOffOnStandby == 1;
 
-      if (ServerVersion >= CecServerVersion::Version1_5_1)
-        SendInactiveSource = config.bSendInactiveSource == 1;
+                       if (ServerVersion >= CecServerVersion::Version1_5_1)
+                               SendInactiveSource = config.bSendInactiveSource == 1;
 
-      if (ServerVersion >= CecServerVersion::Version1_5_3)
-      {
-        LogicalAddresses->Clear();
-                         for (uint8_t iPtr = 0; iPtr <= 16; iPtr++)
-                                 if (config.logicalAddresses[iPtr])
-                                       LogicalAddresses->Set((CecLogicalAddress)iPtr);
-      }
+                       if (ServerVersion >= CecServerVersion::Version1_5_3)
+                       {
+                               LogicalAddresses->Clear();
+                               for (uint8_t iPtr = 0; iPtr <= 16; iPtr++)
+                                       if (config.logicalAddresses[iPtr])
+                                               LogicalAddresses->Set((CecLogicalAddress)iPtr);
+                       }
 
-      if (ServerVersion >= CecServerVersion::Version1_6_0)
-      {
-        FirmwareVersion          = config.iFirmwareVersion;
-        PowerOffDevicesOnStandby = config.bPowerOffDevicesOnStandby == 1;
-      }
+                       if (ServerVersion >= CecServerVersion::Version1_6_0)
+                       {
+                               FirmwareVersion          = config.iFirmwareVersion;
+                               PowerOffDevicesOnStandby = config.bPowerOffDevicesOnStandby == 1;
+                               ShutdownOnStandby        = config.bShutdownOnStandby == 1;
+                       }
+
+                       if (ServerVersion >= CecServerVersion::Version1_6_2)
+                               DeviceLanguage = gcnew System::String(config.strDeviceLanguage);
                }
 
                property System::String ^     DeviceName;
@@ -660,11 +669,12 @@ namespace CecSharp
                property CecLogicalAddresses ^PowerOffDevices;
                property bool                 PowerOffScreensaver;
                property bool                 PowerOffOnStandby;
-    property bool                 SendInactiveSource;
-    property CecLogicalAddresses ^LogicalAddresses;
-    property uint16_t             FirmwareVersion;
-    property bool                 PowerOffDevicesOnStandby;
-
+               property bool                 SendInactiveSource;
+               property CecLogicalAddresses ^LogicalAddresses;
+               property uint16_t             FirmwareVersion;
+               property bool                 PowerOffDevicesOnStandby;
+               property bool                 ShutdownOnStandby;
+               property System::String ^     DeviceLanguage;
                property CecCallbackMethods ^ Callbacks;
        };
 
@@ -676,12 +686,14 @@ namespace CecSharp
        typedef int (__stdcall *COMMANDCB)(const CEC::cec_command &command);
        typedef int (__stdcall *CONFIGCB) (const CEC::libcec_configuration &config);
        typedef int (__stdcall *ALERTCB)  (const CEC::libcec_alert, const CEC::libcec_parameter &data);
+       typedef int (__stdcall *MENUCB)   (const CEC::cec_menu_state newVal);
 
        static LOGCB              g_logCB;
        static KEYCB              g_keyCB;
        static COMMANDCB          g_commandCB;
        static CONFIGCB           g_configCB;
        static ALERTCB            g_alertCB;
+       static MENUCB             g_menuCB;
        static CEC::ICECCallbacks g_cecCallbacks;
 
        int CecLogMessageCB(void *cbParam, const CEC::cec_log_message &message)
@@ -719,6 +731,13 @@ namespace CecSharp
                return 0;
        }
 
+       int CecMenuCB(void *cbParam, const CEC::cec_menu_state newVal)
+       {
+               if (g_menuCB)
+                       return g_menuCB(newVal);
+               return 0;
+       }
+
        #pragma managed
        // delegates for the unmanaged callback methods
        public delegate int CecLogMessageManagedDelegate(const CEC::cec_log_message &);
@@ -726,6 +745,7 @@ namespace CecSharp
        public delegate int CecCommandManagedDelegate(const CEC::cec_command &);
        public delegate int CecConfigManagedDelegate(const CEC::libcec_configuration &);
        public delegate int CecAlertManagedDelegate(const CEC::libcec_alert, const CEC::libcec_parameter &);
+       public delegate int CecMenuManagedDelegate(const CEC::cec_menu_state newVal);
 
        // callback method interface
        public ref class CecCallbackMethods
@@ -792,6 +812,11 @@ namespace CecSharp
                        return 0;
                }
 
+               virtual int ReceiveMenuStateChange(CecMenuState newVal)
+               {
+                       return 0;
+               }
+
        protected:
                // managed callback methods
                int CecLogMessageManaged(const CEC::cec_log_message &message)
@@ -851,6 +876,16 @@ namespace CecSharp
                        return iReturn;
                }
 
+               int CecMenuManaged(const CEC::cec_menu_state newVal)
+               {
+                       int iReturn(0);
+                       if (m_bHasCallbacks)
+                       {
+                               iReturn = m_callbacks->ReceiveMenuStateChange((CecMenuState)newVal);
+                       }
+                       return iReturn;
+               }
+
                void DestroyDelegates()
                {
       m_bHasCallbacks = false;
@@ -860,6 +895,8 @@ namespace CecSharp
                                m_logMessageGCHandle.Free();
                                m_keypressGCHandle.Free();
                                m_commandGCHandle.Free();
+                               m_alertGCHandle.Free();
+                               m_menuGCHandle.Free();
                        }
                }
 
@@ -901,6 +938,12 @@ namespace CecSharp
         g_alertCB                  = static_cast<ALERTCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_alertDelegate).ToPointer());
         g_cecCallbacks.CBCecAlert  = CecAlertCB;
 
+        // create the delegate method for the menu callback
+        m_menuDelegate             = gcnew CecMenuManagedDelegate(this, &CecCallbackMethods::CecMenuManaged);
+        m_menuGCHandle             = System::Runtime::InteropServices::GCHandle::Alloc(m_menuDelegate);
+        g_menuCB                   = static_cast<MENUCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_menuDelegate).ToPointer());
+        g_cecCallbacks.CBCecMenuStateChanged = CecMenuCB;
+
         delete context;
         m_bDelegatesCreated = true;
       }
@@ -926,6 +969,10 @@ namespace CecSharp
                static System::Runtime::InteropServices::GCHandle m_alertGCHandle;
                CONFIGCB                                          m_alertCallback;
 
+               CecMenuManagedDelegate ^                          m_menuDelegate;
+               static System::Runtime::InteropServices::GCHandle m_menuGCHandle;
+               MENUCB                                            m_menuCallback;
+
                CecCallbackMethods ^ m_callbacks;
          bool                 m_bHasCallbacks;
     bool                 m_bDelegatesCreated;
index 2338671d577dfa53448185aacfd58abafc89a753..680ccfba6f2ffa51b549e145c202c1c78cb3a97f 100644 (file)
@@ -118,11 +118,17 @@ namespace CecSharp
                        config.bPowerOffScreensaver = netConfig->PowerOffScreensaver ? 1 : 0;
                        config.bPowerOffOnStandby   = netConfig->PowerOffOnStandby ? 1 : 0;
 
-      if (netConfig->ServerVersion >= CecServerVersion::Version1_5_1)
-        config.bSendInactiveSource  = netConfig->SendInactiveSource ? 1 : 0;
+                       if (netConfig->ServerVersion >= CecServerVersion::Version1_5_1)
+                               config.bSendInactiveSource  = netConfig->SendInactiveSource ? 1 : 0;
 
-      if (netConfig->ServerVersion >= CecServerVersion::Version1_6_0)
-        config.bPowerOffDevicesOnStandby  = netConfig->PowerOffDevicesOnStandby ? 1 : 0;
+                       if (netConfig->ServerVersion >= CecServerVersion::Version1_6_0)
+                       {
+                               config.bPowerOffDevicesOnStandby  = netConfig->PowerOffDevicesOnStandby ? 1 : 0;
+                               config.bShutdownOnStandby         = netConfig->ShutdownOnStandby ? 1 : 0;
+                       }
+
+                       if (netConfig->ServerVersion >= CecServerVersion::Version1_6_2)
+                               _snprintf_s(config.strDeviceLanguage, 3, context->marshal_as<const char*>(netConfig->DeviceLanguage));
 
                        config.callbacks            = &g_cecCallbacks;
                }
index 26a9fb3b0bffd8bba4c0e3500e473eef5c9d10ef..b669eb14ff97086f3441b27c1129146d7a3aeed8 100644 (file)
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
 // You can specify all the values or you can default the Build and Revision Numbers 
 // by using the '*' as shown below:
 // [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.6.1.0")]
-[assembly: AssemblyFileVersion("1.6.1.0")]
+[assembly: AssemblyVersion("1.6.2.0")]
+[assembly: AssemblyFileVersion("1.6.2.0")]
index 1e6c96fd9272e6763b7fd265294019710f433202..c601afc3f9f573683e2dc2648ebac02dd55b998c 100644 (file)
@@ -144,8 +144,6 @@ void EnableCallbacks(ICECAdapter *adapter)
   g_callbacks.CBCecLogMessage = &CecLogMessage;
   g_callbacks.CBCecKeyPress   = &CecKeyPress;
   g_callbacks.CBCecCommand    = &CecCommand;
-  g_callbacks.CBCecConfigurationChanged = NULL;
-  g_callbacks.CBCecAlert      = NULL;
   adapter->EnableCallbacks(NULL, &g_callbacks);
 }
 
@@ -260,7 +258,7 @@ cec_logical_address FindPhysicalAddressBaseDevice(void)
 uint16_t FindPhysicalAddress(void)
 {
   PrintToStdOut("=== Physical Address Configuration ===\n");
-  uint16_t iAddress(0xFFFF);
+  uint16_t iAddress(CEC_INVALID_PHYSICAL_ADDRESS);
 
   PrintToStdOut("Do you want to let libCEC try to autodetect the address (y/n)?");
   string input;
@@ -282,22 +280,22 @@ uint16_t FindPhysicalAddress(void)
     else
     {
       iAddress = g_parser->GetDevicePhysicalAddress(g_primaryAddress);
-      if (iAddress == 0 || iAddress == 0xFFFF)
+      if (iAddress == 0 || iAddress == CEC_INVALID_PHYSICAL_ADDRESS)
         PrintToStdOut("Failed. Please enter the address manually, or restart this wizard and use different settings.");
     }
   }
 
-  if (iAddress == 0 || iAddress == 0xFFFF)
+  if (iAddress == 0 || iAddress == CEC_INVALID_PHYSICAL_ADDRESS)
   {
-    PrintToStdOut("Please enter the physical address (0000 - FFFF), followed by <enter>.");
+    PrintToStdOut("Please enter the physical address (0001 - FFFE), followed by <enter>.");
     getline(cin, input);
     cin.clear();
 
     int iAddressTmp;
     if (sscanf(input.c_str(), "%x", &iAddressTmp) == 1)
     {
-      if (iAddressTmp < 0 || iAddressTmp > 0xFFFF)
-        iAddressTmp = 0xFFFF;
+      if (iAddressTmp <= CEC_PHYSICAL_ADDRESS_TV || iAddressTmp > CEC_MAX_PHYSICAL_ADDRESS)
+        iAddressTmp = CEC_INVALID_PHYSICAL_ADDRESS;
       iAddress = (uint16_t)iAddressTmp;
     }
   }
index cf42233f5f878adc44176424cab48511ed230833..861a9ac6ca5ef380effa53cef73a8378ae330833 100644 (file)
@@ -47,6 +47,8 @@ using namespace CEC;
 using namespace std;
 using namespace PLATFORM;
 
+#define CEC_PROCESSOR_SIGNAL_WAIT_TIME 1000
+
 CCECProcessor::CCECProcessor(CLibCEC *controller, libcec_configuration *configuration) :
     m_bConnectionOpened(false),
     m_bInitialised(false),
@@ -59,7 +61,7 @@ CCECProcessor::CCECProcessor(CLibCEC *controller, libcec_configuration *configur
 {
   CreateBusDevices();
   m_configuration.Clear();
-  m_configuration.serverVersion = CEC_SERVER_VERSION_1_6_1;
+  m_configuration.serverVersion = LIBCEC_VERSION_CURRENT;
   SetConfiguration(configuration);
 
   if (m_configuration.tvVendor != CEC_VENDOR_UNKNOWN)
@@ -77,7 +79,7 @@ CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, con
     m_iLastTransmission(0)
 {
   m_configuration.Clear();
-  m_configuration.serverVersion    = CEC_SERVER_VERSION_1_6_1;
+  m_configuration.serverVersion    = LIBCEC_VERSION_CURRENT;
 
   // client version < 1.5.0
   m_configuration.clientVersion    = (uint32_t)CEC_CLIENT_VERSION_PRE_1_5;
@@ -94,34 +96,34 @@ CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, con
 
 void CCECProcessor::CreateBusDevices(void)
 {
-  for (int iPtr = 0; iPtr < 16; iPtr++)
+  for (uint8_t iPtr = CECDEVICE_TV; iPtr <= CECDEVICE_BROADCAST; iPtr++)
   {
     switch(iPtr)
     {
     case CECDEVICE_AUDIOSYSTEM:
-      m_busDevices[iPtr] = new CCECAudioSystem(this, (cec_logical_address) iPtr, 0xFFFF);
+      m_busDevices[iPtr] = new CCECAudioSystem(this, (cec_logical_address) iPtr);
       break;
     case CECDEVICE_PLAYBACKDEVICE1:
     case CECDEVICE_PLAYBACKDEVICE2:
     case CECDEVICE_PLAYBACKDEVICE3:
-      m_busDevices[iPtr] = new CCECPlaybackDevice(this, (cec_logical_address) iPtr, 0xFFFF);
+      m_busDevices[iPtr] = new CCECPlaybackDevice(this, (cec_logical_address) iPtr);
       break;
     case CECDEVICE_RECORDINGDEVICE1:
     case CECDEVICE_RECORDINGDEVICE2:
     case CECDEVICE_RECORDINGDEVICE3:
-      m_busDevices[iPtr] = new CCECRecordingDevice(this, (cec_logical_address) iPtr, 0xFFFF);
+      m_busDevices[iPtr] = new CCECRecordingDevice(this, (cec_logical_address) iPtr);
       break;
     case CECDEVICE_TUNER1:
     case CECDEVICE_TUNER2:
     case CECDEVICE_TUNER3:
     case CECDEVICE_TUNER4:
-      m_busDevices[iPtr] = new CCECTuner(this, (cec_logical_address) iPtr, 0xFFFF);
+      m_busDevices[iPtr] = new CCECTuner(this, (cec_logical_address) iPtr);
       break;
     case CECDEVICE_TV:
-      m_busDevices[iPtr] = new CCECTV(this, (cec_logical_address) iPtr, 0);
+      m_busDevices[iPtr] = new CCECTV(this, (cec_logical_address) iPtr);
       break;
     default:
-      m_busDevices[iPtr] = new CCECBusDevice(this, (cec_logical_address) iPtr, 0xFFFF);
+      m_busDevices[iPtr] = new CCECBusDevice(this, (cec_logical_address) iPtr);
       break;
     }
   }
@@ -131,7 +133,7 @@ CCECProcessor::~CCECProcessor(void)
 {
   Close();
 
-  for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
+  for (uint8_t iPtr = CECDEVICE_TV; iPtr <= CECDEVICE_BROADCAST; iPtr++)
   {
     delete m_busDevices[iPtr];
     m_busDevices[iPtr] = NULL;
@@ -182,13 +184,23 @@ bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint
   {
     CLibCEC::AddLog(CEC_LOG_ERROR, "could not open a connection (try %d)", ++iConnectTry);
     m_communication->Close();
-    CEvent::Sleep(1000);
+    CEvent::Sleep(CEC_DEFAULT_CONNECT_RETRY_WAIT);
   }
 
   if (bReturn)
   {
     m_configuration.iFirmwareVersion = m_communication->GetFirmwareVersion();
-    CLibCEC::AddLog(CEC_LOG_NOTICE, "connected to the CEC adapter. firmware version = %d, client version = %s", m_configuration.iFirmwareVersion, ToString((cec_client_version)m_configuration.clientVersion));
+    m_configuration.iFirmwareBuildDate = m_communication->GetFirmwareBuildDate();
+    CStdString strLog;
+    strLog.Format("connected to the CEC adapter. libCEC version = %s, client version = %s, firmware version = %d", ToString((cec_server_version)m_configuration.serverVersion), ToString((cec_client_version)m_configuration.clientVersion), m_configuration.iFirmwareVersion);
+    if (m_configuration.iFirmwareBuildDate != CEC_FW_BUILD_UNKNOWN)
+    {
+      time_t buildTime = (time_t)m_configuration.iFirmwareBuildDate;
+      strLog.AppendFormat(", firmware build date: %s", asctime(gmtime(&buildTime)));
+      strLog = strLog.Left((int)strLog.length() - 1); // strip \n added by asctime
+      strLog.append(" +0000");
+    }
+    CLibCEC::AddLog(CEC_LOG_NOTICE, strLog);
   }
 
   if (m_configuration.bGetSettingsFromROM == 1)
@@ -200,7 +212,7 @@ bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint
     CLockObject lock(m_mutex);
     if (!config.deviceTypes.IsEmpty())
       m_configuration.deviceTypes = config.deviceTypes;
-    if (config.iPhysicalAddress > 0)
+    if (IsValidPhysicalAddress(config.iPhysicalAddress))
       m_configuration.iPhysicalAddress = config.iPhysicalAddress;
     snprintf(m_configuration.strDeviceName, 13, "%s", config.strDeviceName);
   }
@@ -210,7 +222,7 @@ bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint
 
 bool CCECProcessor::IsInitialised(void)
 {
-  CLockObject lock(m_mutex);
+  CLockObject lock(m_threadMutex);
   return m_bInitialised;
 }
 
@@ -240,20 +252,39 @@ bool CCECProcessor::Initialise(void)
     /* make the primary device the active source if the option is set */
     if (m_configuration.bActivateSource == 1)
       m_busDevices[m_configuration.logicalAddresses.primary]->m_bActiveSource = true;
+
+    /* set the default menu language for devices we control */
+    cec_menu_language language;
+    language.device = m_configuration.logicalAddresses.primary;
+    memcpy(language.language, m_configuration.strDeviceLanguage, 3);
+    language.language[3] = 0;
+
+    for (uint8_t iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++)
+    {
+      if (m_configuration.logicalAddresses[iPtr])
+      {
+        language.device = (cec_logical_address) iPtr;
+        m_busDevices[iPtr]->SetMenuLanguage(language);
+      }
+    }
   }
 
   /* get the vendor id from the TV, so we are using the correct handler */
   m_busDevices[CECDEVICE_TV]->GetVendorId();
 
-  if (m_configuration.iPhysicalAddress != 0)
+  if (IsValidPhysicalAddress(m_configuration.iPhysicalAddress))
   {
-    CLibCEC::AddLog(CEC_LOG_NOTICE, "setting the physical address to %4x", m_configuration.iPhysicalAddress);
+    CLibCEC::AddLog(CEC_LOG_NOTICE, "setting the physical address to %04X", m_configuration.iPhysicalAddress);
     m_busDevices[m_configuration.logicalAddresses.primary]->m_iPhysicalAddress = m_configuration.iPhysicalAddress;
     if ((bReturn = m_busDevices[m_configuration.logicalAddresses.primary]->TransmitPhysicalAddress()) == false)
-      CLibCEC::AddLog(CEC_LOG_ERROR, "unable to set the physical address to %4x", m_configuration.iPhysicalAddress);
+      CLibCEC::AddLog(CEC_LOG_ERROR, "unable to set the physical address to %04X", m_configuration.iPhysicalAddress);
+  }
+  else
+  {
+    if (!SetHDMIPort(m_configuration.baseDevice, m_configuration.iHDMIPort, true))
+      CLibCEC::AddLog(CEC_LOG_ERROR, "unable to set HDMI port %d on %s (%x)", m_configuration.iHDMIPort, ToString(m_configuration.baseDevice), (uint8_t)m_configuration.baseDevice);
+    bReturn = true;
   }
-  else if (m_configuration.iPhysicalAddress == 0 && (bReturn = SetHDMIPort(m_configuration.baseDevice, m_configuration.iHDMIPort, true)) == false)
-    CLibCEC::AddLog(CEC_LOG_ERROR, "unable to set HDMI port %d on %s (%x)", m_configuration.iHDMIPort, ToString(m_configuration.baseDevice), (uint8_t)m_configuration.baseDevice);
 
   if (bReturn && m_configuration.bActivateSource == 1)
     m_busDevices[m_configuration.logicalAddresses.primary]->ActivateSource();
@@ -265,7 +296,7 @@ bool CCECProcessor::Initialise(void)
   return bReturn;
 }
 
-bool CCECProcessor::Start(const char *strPort, uint16_t iBaudRate /* = 38400 */, uint32_t iTimeoutMs /* = 10000 */)
+bool CCECProcessor::Start(const char *strPort, uint16_t iBaudRate /* = CEC_SERIAL_DEFAULT_BAUDRATE */, uint32_t iTimeoutMs /* = CEC_DEFAULT_CONNECT_TIMEOUT */)
 {
   bool bReturn(false);
 
@@ -347,7 +378,7 @@ bool CCECProcessor::ChangeDeviceType(cec_device_type from, cec_device_type to)
   CCECBusDevice *previousDevice = GetDeviceByType(from);
   m_configuration.logicalAddresses.primary = CECDEVICE_UNKNOWN;
 
-  for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
+  for (uint8_t iPtr = 0; iPtr < 5; iPtr++)
   {
     if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_RESERVED)
       continue;
@@ -377,12 +408,6 @@ bool CCECProcessor::ChangeDeviceType(cec_device_type from, cec_device_type to)
       previousDevice->SetCecVersion(CEC_VERSION_UNKNOWN);
 
       newDevice->SetMenuLanguage(previousDevice->GetMenuLanguage(false));
-      cec_menu_language lang;
-      lang.device = previousDevice->GetLogicalAddress();
-      for (unsigned int iPtr = 0; iPtr < 4; iPtr++)
-        lang.language[iPtr] = '?';
-      lang.language[3] = 0;
-      previousDevice->SetMenuLanguage(lang);
 
       newDevice->SetMenuState(previousDevice->GetMenuState());
       previousDevice->SetMenuState(CEC_MENU_STATE_DEACTIVATED);
@@ -390,8 +415,8 @@ bool CCECProcessor::ChangeDeviceType(cec_device_type from, cec_device_type to)
       newDevice->SetOSDName(previousDevice->GetOSDName(false));
       previousDevice->SetOSDName(ToString(previousDevice->GetLogicalAddress()));
 
-      newDevice->SetPhysicalAddress(previousDevice->GetPhysicalAddress(false));
-      previousDevice->SetPhysicalAddress(0xFFFF);
+      newDevice->SetPhysicalAddress(previousDevice->GetPhysicalAddress());
+      previousDevice->SetPhysicalAddress(CEC_INVALID_PHYSICAL_ADDRESS);
 
       newDevice->SetPowerStatus(previousDevice->GetPowerStatus(false));
       previousDevice->SetPowerStatus(CEC_POWER_STATUS_UNKNOWN);
@@ -425,7 +450,7 @@ bool CCECProcessor::FindLogicalAddresses(void)
     return false;
   }
 
-  for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
+  for (uint8_t iPtr = 0; iPtr < 5; iPtr++)
   {
     if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_RESERVED)
       continue;
@@ -452,7 +477,7 @@ void CCECProcessor::ReplaceHandlers(void)
 {
   if (!IsInitialised())
     return;
-  for (uint8_t iPtr = 0; iPtr <= CECDEVICE_PLAYBACKDEVICE3; iPtr++)
+  for (uint8_t iPtr = CECDEVICE_TV; iPtr <= CECDEVICE_PLAYBACKDEVICE3; iPtr++)
     m_busDevices[iPtr]->ReplaceHandler(m_bInitialised);
 }
 
@@ -470,7 +495,7 @@ void *CCECProcessor::Process(void)
 
   while (!IsStopped() && m_communication->IsOpen())
   {
-    if (m_inBuffer.Pop(command, 500))
+    if (m_inBuffer.Pop(command, CEC_PROCESSOR_SIGNAL_WAIT_TIME))
       ParseCommand(command);
 
     if (IsInitialised())
@@ -495,7 +520,7 @@ bool CCECProcessor::SetActiveSource(cec_device_type type /* = CEC_DEVICE_TYPE_RE
 
   if (type != CEC_DEVICE_TYPE_RESERVED)
   {
-    for (uint8_t iPtr = 0; iPtr <= 11; iPtr++)
+    for (uint8_t iPtr = CECDEVICE_TV; iPtr <= CECDEVICE_PLAYBACKDEVICE3; iPtr++)
     {
       if (m_configuration.logicalAddresses[iPtr] && m_busDevices[iPtr]->m_type == type)
       {
@@ -506,7 +531,7 @@ bool CCECProcessor::SetActiveSource(cec_device_type type /* = CEC_DEVICE_TYPE_RE
   }
 
   m_busDevices[addr]->SetActiveSource();
-  if (m_busDevices[addr]->GetPhysicalAddress(false) != 0xFFFF)
+  if (IsValidPhysicalAddress(m_busDevices[addr]->GetPhysicalAddress()))
     bReturn = m_busDevices[addr]->ActivateSource();
 
   return bReturn;
@@ -517,12 +542,16 @@ bool CCECProcessor::SetActiveSource(uint16_t iStreamPath)
   bool bReturn(false);
 
   // suppress polls when searching for a device
-  CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamPath, false, true);
+  CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamPath);
   if (device)
   {
     device->SetActiveSource();
     bReturn = true;
   }
+  else
+  {
+    CLibCEC::AddLog(CEC_LOG_DEBUG, "device with PA '%04x' not found", iStreamPath);
+  }
 
   return bReturn;
 }
@@ -582,15 +611,14 @@ bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort,
   bool bReturn(false);
 
   // limit the HDMI port range to 1-15
-  if (iPort < 1)
-      iPort = 1;
-  if (iPort > 15)
-      iPort = 15;
+  if (iPort < CEC_MIN_HDMI_PORTNUMBER ||
+      iPort > CEC_MAX_HDMI_PORTNUMBER)
+    return bReturn;
 
   {
     CLockObject lock(m_mutex);
     m_configuration.baseDevice = iBaseDevice;
-    m_configuration.iHDMIPort = iPort;
+    m_configuration.iHDMIPort  = iPort;
   }
 
   if (!IsRunning() && !bForce)
@@ -600,11 +628,9 @@ bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort,
 
   uint16_t iPhysicalAddress(0);
   if (iBaseDevice > CECDEVICE_TV)
-  {
-    iPhysicalAddress = m_busDevices[iBaseDevice]->GetPhysicalAddress();
-  }
+    iPhysicalAddress = m_busDevices[iBaseDevice]->GetPhysicalAddress(false);
 
-  if (iPhysicalAddress < 0xffff)
+  if (iPhysicalAddress <= CEC_MAX_PHYSICAL_ADDRESS)
   {
     if (iPhysicalAddress == 0)
       iPhysicalAddress += 0x1000 * iPort;
@@ -619,18 +645,21 @@ bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort,
   }
 
   if (!bReturn)
-    CLibCEC::AddLog(CEC_LOG_ERROR, "failed to set the physical address");
-  else
-    SetPhysicalAddress(iPhysicalAddress);
+  {
+    CLibCEC::AddLog(CEC_LOG_WARNING, "failed to set the physical address to %04X, setting it to the default value %04X", iPhysicalAddress, CEC_DEFAULT_PHYSICAL_ADDRESS);
+    iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS;
+  }
+
+  SetPhysicalAddress(iPhysicalAddress);
 
   return bReturn;
 }
 
 bool CCECProcessor::PhysicalAddressInUse(uint16_t iPhysicalAddress)
 {
-  for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
+  for (uint8_t iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++)
   {
-    if (m_busDevices[iPtr]->GetPhysicalAddress(false) == iPhysicalAddress)
+    if (m_busDevices[iPtr]->GetPhysicalAddress() == iPhysicalAddress)
       return true;
   }
   return false;
@@ -674,7 +703,7 @@ bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress)
 
 bool CCECProcessor::SetMenuState(cec_menu_state state, bool bSendUpdate /* = true */)
 {
-  for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
+  for (uint8_t iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++)
   {
     if (m_configuration.logicalAddresses[iPtr])
       m_busDevices[iPtr]->SetMenuState(state);
@@ -696,12 +725,12 @@ bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress, bool bSendUpda
   {
     CLockObject lock(m_mutex);
     m_configuration.iPhysicalAddress = iPhysicalAddress;
-    CLibCEC::AddLog(CEC_LOG_DEBUG, "setting physical address to '%4x'", iPhysicalAddress);
+    CLibCEC::AddLog(CEC_LOG_DEBUG, "setting physical address to '%04X'", iPhysicalAddress);
 
     if (!m_configuration.logicalAddresses.IsEmpty())
     {
       bool bWasActiveSource(false);
-      for (uint8_t iPtr = 0; iPtr < 15; iPtr++)
+      for (uint8_t iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++)
         if (m_configuration.logicalAddresses[iPtr])
         {
           bWasActiveSource |= m_busDevices[iPtr]->IsActiveSource();
@@ -716,7 +745,7 @@ bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress, bool bSendUpda
     }
   }
 
-  for (uint8_t iPtr = 0; iPtr < 15; iPtr++)
+  for (uint8_t iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++)
     if (sendUpdatesTo[iPtr])
       m_busDevices[iPtr]->TransmitPhysicalAddress();
 
@@ -766,7 +795,7 @@ bool CCECProcessor::PollDevice(cec_logical_address iAddress)
 
 uint8_t CCECProcessor::VolumeUp(bool bSendRelease /* = true */)
 {
-  uint8_t status = 0;
+  uint8_t status(CEC_AUDIO_VOLUME_STATUS_UNKNOWN);
   if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM))
     status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeUp(bSendRelease);
 
@@ -775,7 +804,7 @@ uint8_t CCECProcessor::VolumeUp(bool bSendRelease /* = true */)
 
 uint8_t CCECProcessor::VolumeDown(bool bSendRelease /* = true */)
 {
-  uint8_t status = 0;
+  uint8_t status(CEC_AUDIO_VOLUME_STATUS_UNKNOWN);
   if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM))
     status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeDown(bSendRelease);
 
@@ -784,26 +813,22 @@ uint8_t CCECProcessor::VolumeDown(bool bSendRelease /* = true */)
 
 uint8_t CCECProcessor::MuteAudio(bool bSendRelease /* = true */)
 {
-  uint8_t status = 0;
+  uint8_t status(CEC_AUDIO_VOLUME_STATUS_UNKNOWN);
   if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM))
     status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->MuteAudio(bSendRelease);
 
   return status;
 }
 
-CCECBusDevice *CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress, bool bRefresh /* = false */, bool bSuppressPoll /* = false */) const
+CCECBusDevice *CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress, bool bSuppressUpdate /* = true */)
 {
-  if (m_busDevices[m_configuration.logicalAddresses.primary]->GetPhysicalAddress(false) == iPhysicalAddress)
-    return m_busDevices[m_configuration.logicalAddresses.primary];
+  CCECBusDevice *device(NULL);
 
-  CCECBusDevice *device = NULL;
-  for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
+  // check each device until we found a match
+  for (uint8_t iPtr = CECDEVICE_TV; !device && iPtr < CECDEVICE_BROADCAST; iPtr++)
   {
-    if (m_busDevices[iPtr]->GetPhysicalAddress(bRefresh, bSuppressPoll) == iPhysicalAddress)
-    {
+    if (m_busDevices[iPtr]->GetPhysicalAddress(bSuppressUpdate) == iPhysicalAddress)
       device = m_busDevices[iPtr];
-      break;
-    }
   }
 
   return device;
@@ -813,7 +838,7 @@ CCECBusDevice *CCECProcessor::GetDeviceByType(cec_device_type type) const
 {
   CCECBusDevice *device = NULL;
 
-  for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
+  for (uint8_t iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++)
   {
     if (m_busDevices[iPtr]->m_type == type && m_configuration.logicalAddresses[iPtr])
     {
@@ -860,6 +885,13 @@ bool CCECProcessor::GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu
   return false;
 }
 
+CStdString CCECProcessor::GetDeviceName(void) const
+{
+  CStdString strName;
+  strName = m_configuration.strDeviceName;
+  return strName;
+}
+
 uint64_t CCECProcessor::GetDeviceVendorId(cec_logical_address iAddress)
 {
   if (m_busDevices[iAddress])
@@ -881,20 +913,29 @@ cec_power_status CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddres
   return CEC_POWER_STATUS_UNKNOWN;
 }
 
-cec_logical_address CCECProcessor::GetActiveSource(void)
+cec_logical_address CCECProcessor::GetActiveSource(bool bRequestActiveSource /* = true */)
 {
-  for (uint8_t iPtr = 0; iPtr <= 11; iPtr++)
+  for (uint8_t iPtr = CECDEVICE_TV; iPtr <= CECDEVICE_PLAYBACKDEVICE3; iPtr++)
   {
     if (m_busDevices[iPtr]->IsActiveSource())
       return (cec_logical_address)iPtr;
   }
 
+  if (bRequestActiveSource && m_configuration.logicalAddresses.primary != CECDEVICE_UNKNOWN)
+  {
+    CCECBusDevice *primary = m_busDevices[m_configuration.logicalAddresses.primary];
+    if (primary)
+      primary->RequestActiveSource();
+
+    return GetActiveSource(false);
+  }
+
   return CECDEVICE_UNKNOWN;
 }
 
 bool CCECProcessor::IsActiveSource(cec_logical_address iAddress)
 {
-  return iAddress > CECDEVICE_TV && iAddress < CECDEVICE_BROADCAST ?
+  return iAddress >= CECDEVICE_TV && iAddress < CECDEVICE_BROADCAST ?
     m_busDevices[iAddress]->IsActiveSource() :
     false;
 }
@@ -922,8 +963,21 @@ bool CCECProcessor::Transmit(const cec_command &data)
     iMaxTries = m_busDevices[data.initiator]->GetHandler()->GetTransmitRetries() + 1;
   }
 
-  return m_communication->Write(data, iMaxTries, m_iStandardLineTimeout, m_iRetryLineTimeout)
-      == ADAPTER_MESSAGE_STATE_SENT_ACKED;
+  bool bRetry(true);
+  uint8_t iTries(0);
+  uint8_t iLineTimeout = m_iStandardLineTimeout;
+  cec_adapter_message_state adapterState = ADAPTER_MESSAGE_STATE_UNKNOWN;
+
+  while (bRetry && ++iTries < iMaxTries)
+  {
+    if (m_busDevices[data.initiator]->IsUnsupportedFeature(data.opcode))
+      return false;
+
+    adapterState = m_communication->Write(data, bRetry, iLineTimeout);
+    iLineTimeout = m_iRetryLineTimeout;
+  }
+
+  return adapterState == ADAPTER_MESSAGE_STATE_SENT_ACKED;
 }
 
 void CCECProcessor::TransmitAbort(cec_logical_address address, cec_opcode opcode, cec_abort_reason reason /* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */)
@@ -957,7 +1011,7 @@ cec_logical_addresses CCECProcessor::GetActiveDevices(void)
 {
   cec_logical_addresses addresses;
   addresses.Clear();
-  for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
+  for (uint8_t iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++)
   {
     if (m_busDevices[iPtr]->GetStatus() == CEC_DEVICE_STATUS_PRESENT)
       addresses.Set((cec_logical_address) iPtr);
@@ -972,7 +1026,7 @@ bool CCECProcessor::IsPresentDevice(cec_logical_address address)
 
 bool CCECProcessor::IsPresentDeviceType(cec_device_type type)
 {
-  for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
+  for (uint8_t iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++)
   {
     if (m_busDevices[iPtr]->GetType() == type && m_busDevices[iPtr]->GetStatus() == CEC_DEVICE_STATUS_PRESENT)
       return true;
@@ -984,13 +1038,13 @@ bool CCECProcessor::IsPresentDeviceType(cec_device_type type)
 uint16_t CCECProcessor::GetPhysicalAddress(void) const
 {
   if (!m_configuration.logicalAddresses.IsEmpty() && m_busDevices[m_configuration.logicalAddresses.primary])
-    return m_busDevices[m_configuration.logicalAddresses.primary]->GetPhysicalAddress(false);
+    return m_busDevices[m_configuration.logicalAddresses.primary]->GetPhysicalAddress();
   return false;
 }
 
 bool CCECProcessor::SetAckMask(uint16_t iMask)
 {
-  return m_communication->SetAckMask(iMask);
+  return m_communication ? m_communication->SetAckMask(iMask) : false;
 }
 
 bool CCECProcessor::TransmitKeypress(cec_logical_address iDestination, cec_user_control_code key, bool bWait /* = true */)
@@ -1007,12 +1061,12 @@ bool CCECProcessor::EnablePhysicalAddressDetection(void)
 {
   CLibCEC::AddLog(CEC_LOG_WARNING, "deprecated method %s called", __FUNCTION__);
   uint16_t iPhysicalAddress = m_communication->GetPhysicalAddress();
-  if (iPhysicalAddress != 0)
+  if (IsValidPhysicalAddress(iPhysicalAddress))
   {
     m_configuration.bAutodetectAddress = 1;
-    m_configuration.iPhysicalAddress = iPhysicalAddress;
-    m_configuration.baseDevice = CECDEVICE_UNKNOWN;
-    m_configuration.iHDMIPort = 0;
+    m_configuration.iPhysicalAddress   = iPhysicalAddress;
+    m_configuration.baseDevice         = CECDEVICE_UNKNOWN;
+    m_configuration.iHDMIPort          = CEC_HDMI_PORTNUMBER_NONE;
     return SetPhysicalAddress(iPhysicalAddress);
   }
   return false;
@@ -1023,10 +1077,13 @@ bool CCECProcessor::StandbyDevices(cec_logical_address address /* = CECDEVICE_BR
   if (address == CECDEVICE_BROADCAST && m_configuration.clientVersion >= CEC_CLIENT_VERSION_1_5_0)
   {
     bool bReturn(true);
-    for (uint8_t iPtr = 0; iPtr <= 0xF; iPtr++)
+    for (uint8_t iPtr = CECDEVICE_TV; iPtr <= CECDEVICE_BROADCAST; iPtr++)
     {
       if (m_configuration.powerOffDevices[iPtr])
+      {
+        CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - putting '%s' in standby mode", __FUNCTION__, ToString((cec_logical_address)iPtr));
         bReturn &= m_busDevices[iPtr]->Standby();
+      }
     }
     return bReturn;
   }
@@ -1039,10 +1096,13 @@ bool CCECProcessor::PowerOnDevices(cec_logical_address address /* = CECDEVICE_BR
   if (address == CECDEVICE_BROADCAST && m_configuration.clientVersion >= CEC_CLIENT_VERSION_1_5_0)
   {
     bool bReturn(true);
-    for (uint8_t iPtr = 0; iPtr <= 0xF; iPtr++)
+    for (uint8_t iPtr = CECDEVICE_TV; iPtr <= CECDEVICE_BROADCAST; iPtr++)
     {
-      if (m_configuration.powerOffDevices[iPtr])
+      if (m_configuration.wakeDevices[iPtr])
+      {
+        CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - powering on '%s'", __FUNCTION__, ToString((cec_logical_address)iPtr));
         bReturn &= m_busDevices[iPtr]->PowerOn();
+      }
     }
     return bReturn;
   }
@@ -1212,6 +1272,8 @@ const char *CCECProcessor::ToString(const cec_deck_info status)
     return "info index search reverse";
   case CEC_DECK_INFO_OTHER_STATUS:
     return "other";
+  case CEC_DECK_INFO_OTHER_STATUS_LG:
+    return "LG other";
   default:
     return "unknown";
   }
@@ -1416,6 +1478,8 @@ const char *CCECProcessor::ToString(const cec_client_version version)
     return "1.6.0";
   case CEC_CLIENT_VERSION_1_6_1:
     return "1.6.1";
+  case CEC_CLIENT_VERSION_1_6_2:
+    return "1.6.2";
   default:
     return "Unknown";
   }
@@ -1439,69 +1503,26 @@ const char *CCECProcessor::ToString(const cec_server_version version)
     return "1.6.0";
   case CEC_SERVER_VERSION_1_6_1:
     return "1.6.1";
+  case CEC_SERVER_VERSION_1_6_2:
+    return "1.6.2";
   default:
     return "Unknown";
   }
 }
 
-void *CCECBusScan::Process(void)
-{
-  CCECBusDevice *device(NULL);
-  uint8_t iCounter(0);
-
-  while (!IsStopped())
-  {
-    if (++iCounter < 10)
-    {
-      Sleep(1000);
-      continue;
-    }
-    for (unsigned int iPtr = 0; iPtr <= 11 && !IsStopped(); iPtr++)
-    {
-      device = m_processor->m_busDevices[iPtr];
-      WaitUntilIdle();
-      if (device && device->GetStatus(true) == CEC_DEVICE_STATUS_PRESENT)
-      {
-        WaitUntilIdle();
-        if (!IsStopped())
-          device->GetVendorId();
-
-        WaitUntilIdle();
-        if (!IsStopped())
-          device->GetPowerStatus(true);
-      }
-    }
-  }
-
-  return NULL;
-}
-
-void CCECBusScan::WaitUntilIdle(void)
-{
-  if (IsStopped())
-    return;
-
-  int32_t iWaitTime = 3000 - (int32_t)(GetTimeMs() - m_processor->GetLastTransmission());
-  while (iWaitTime > 0)
-  {
-    Sleep(iWaitTime);
-    iWaitTime = 3000 - (int32_t)(GetTimeMs() - m_processor->GetLastTransmission());
-  }
-}
-
 bool CCECProcessor::StartBootloader(const char *strPort /* = NULL */)
 {
+  bool bReturn(false);
   if (!m_communication && strPort)
   {
-    bool bReturn(false);
     IAdapterCommunication *comm = new CUSBCECAdapterCommunication(this, strPort);
-    CTimeout timeout(10000);
+    CTimeout timeout(CEC_DEFAULT_CONNECT_TIMEOUT);
     int iConnectTry(0);
     while (timeout.TimeLeft() > 0 && (bReturn = comm->Open(timeout.TimeLeft() / CEC_CONNECT_TRIES, true)) == false)
     {
       CLibCEC::AddLog(CEC_LOG_ERROR, "could not open a connection (try %d)", ++iConnectTry);
       comm->Close();
-      Sleep(500);
+      Sleep(CEC_DEFAULT_TRANSMIT_RETRY_WAIT);
     }
     if (comm->IsOpen())
     {
@@ -1512,8 +1533,12 @@ bool CCECProcessor::StartBootloader(const char *strPort /* = NULL */)
   }
   else
   {
-    return m_communication->StartBootloader();
+    m_communication->StartBootloader();
+    Close();
+    bReturn = true;
   }
+
+  return bReturn;
 }
 
 bool CCECProcessor::PingAdapter(void)
@@ -1561,34 +1586,34 @@ bool CCECProcessor::SetConfiguration(const libcec_configuration *configuration)
   if (IsRunning() && configuration->bAutodetectAddress == 1)
   {
     uint16_t iPhysicalAddress = m_communication->GetPhysicalAddress();
-    if (iPhysicalAddress != 0)
+    if (IsValidPhysicalAddress(iPhysicalAddress))
     {
       if (IsRunning())
-        CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - autodetected physical address '%4x'", __FUNCTION__, iPhysicalAddress);
+        CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - autodetected physical address '%04X'", __FUNCTION__, iPhysicalAddress);
       else
-        CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - using physical address '%x'", __FUNCTION__, iPhysicalAddress);
+        CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - using physical address '%04X'", __FUNCTION__, iPhysicalAddress);
       bPhysicalAddressChanged = (m_configuration.iPhysicalAddress != iPhysicalAddress);
       m_configuration.iPhysicalAddress = iPhysicalAddress;
-      m_configuration.iHDMIPort = 0;
-      m_configuration.baseDevice = CECDEVICE_UNKNOWN;
-      bPhysicalAutodetected = true;
+      m_configuration.iHDMIPort        = CEC_HDMI_PORTNUMBER_NONE;
+      m_configuration.baseDevice       = CECDEVICE_UNKNOWN;
+      bPhysicalAutodetected            = true;
     }
   }
 
   // physical address
   if (!bPhysicalAutodetected)
   {
-    if (configuration->iPhysicalAddress != 0)
-      bPhysicalAddressChanged = IsRunning() && m_configuration.iPhysicalAddress != configuration->iPhysicalAddress;
+    uint16_t iPhysicalAddress(IsValidPhysicalAddress(configuration->iPhysicalAddress) ? configuration->iPhysicalAddress : CEC_PHYSICAL_ADDRESS_TV);
+    bPhysicalAddressChanged = IsRunning() && m_configuration.iPhysicalAddress != iPhysicalAddress;
     if (bPhysicalAddressChanged)
     {
-      CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - physical address '%x'", __FUNCTION__, configuration->iPhysicalAddress);
-      m_configuration.iPhysicalAddress = configuration->iPhysicalAddress;
+      CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - physical address '%04X'", __FUNCTION__, iPhysicalAddress);
+      m_configuration.iPhysicalAddress = iPhysicalAddress;
     }
   }
 
   bool bHdmiPortChanged(false);
-  if (!bPhysicalAutodetected && !bPhysicalAddressChanged)
+  if (!bPhysicalAutodetected && !IsValidPhysicalAddress(configuration->iPhysicalAddress))
   {
     // base device
     bHdmiPortChanged = IsRunning() && m_configuration.baseDevice != configuration->baseDevice;
@@ -1604,7 +1629,7 @@ bool CCECProcessor::SetConfiguration(const libcec_configuration *configuration)
   {
     CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - resetting HDMI port and base device to defaults", __FUNCTION__);
     m_configuration.baseDevice = CECDEVICE_UNKNOWN;
-    m_configuration.iHDMIPort  = 0;
+    m_configuration.iHDMIPort  = CEC_HDMI_PORTNUMBER_NONE;
   }
 
   bReinit = bPhysicalAddressChanged || bHdmiPortChanged || bDeviceTypeChanged;
@@ -1654,22 +1679,25 @@ bool CCECProcessor::SetConfiguration(const libcec_configuration *configuration)
     m_configuration.bShutdownOnStandby        = configuration->bShutdownOnStandby;
   }
 
+  // client version 1.6.2
+  if (configuration->clientVersion >= CEC_CLIENT_VERSION_1_6_2)
+  {
+    memcpy(m_configuration.strDeviceLanguage, configuration->strDeviceLanguage, 3);
+  }
+
   // ensure that there is at least 1 device type set
   if (m_configuration.deviceTypes.IsEmpty())
     m_configuration.deviceTypes.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE);
 
-  // persist the configuration
-  if (IsRunning())
-    m_communication->PersistConfiguration(&m_configuration);
-
+  bool bReturn(true);
   if (bReinit || m_configuration.logicalAddresses.IsEmpty())
   {
     if (bDeviceTypeChanged)
-      return ChangeDeviceType(oldPrimaryType, m_configuration.deviceTypes[0]);
-    else if (bPhysicalAddressChanged)
-      return SetPhysicalAddress(m_configuration.iPhysicalAddress);
-    else
-      return SetHDMIPort(m_configuration.baseDevice, m_configuration.iHDMIPort);
+      bReturn = ChangeDeviceType(oldPrimaryType, m_configuration.deviceTypes[0]);
+    else if (IsValidPhysicalAddress(m_configuration.iPhysicalAddress))
+      bReturn = SetPhysicalAddress(m_configuration.iPhysicalAddress);
+    else if (m_configuration.baseDevice != CECDEVICE_UNKNOWN && m_configuration.iHDMIPort != CEC_HDMI_PORTNUMBER_NONE)
+      bReturn = SetHDMIPort(m_configuration.baseDevice, m_configuration.iHDMIPort);
   }
   else if (m_configuration.bActivateSource == 1 && IsRunning() && !IsActiveSource(m_configuration.logicalAddresses.primary))
   {
@@ -1677,7 +1705,11 @@ bool CCECProcessor::SetConfiguration(const libcec_configuration *configuration)
     SetActiveSource(m_configuration.deviceTypes.types[0]);
   }
 
-  return true;
+  // persist the configuration
+  if (IsRunning())
+    m_communication->PersistConfiguration(&m_configuration);
+
+  return bReturn;
 }
 
 bool CCECProcessor::GetCurrentConfiguration(libcec_configuration *configuration)
@@ -1717,34 +1749,53 @@ bool CCECProcessor::GetCurrentConfiguration(libcec_configuration *configuration)
     configuration->bShutdownOnStandby        = m_configuration.bShutdownOnStandby;
   }
 
+  // client version 1.6.2
+  if (configuration->clientVersion >= CEC_CLIENT_VERSION_1_6_2)
+  {
+    memcpy(configuration->strDeviceLanguage, m_configuration.strDeviceLanguage, 3);
+    configuration->iFirmwareBuildDate      = m_configuration.iFirmwareBuildDate;
+  }
   return true;
 }
 
 bool CCECProcessor::CanPersistConfiguration(void)
 {
-  return m_communication->GetFirmwareVersion() >= 2;
+  return m_communication ? m_communication->GetFirmwareVersion() >= 2 : false;
 }
 
 bool CCECProcessor::PersistConfiguration(libcec_configuration *configuration)
 {
-  return m_communication->PersistConfiguration(configuration);
+  return m_communication ? m_communication->PersistConfiguration(configuration) : false;
 }
 
 void CCECProcessor::RescanActiveDevices(void)
 {
-  for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
+  for (uint8_t iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++)
     m_busDevices[iPtr]->GetStatus(true);
 }
 
-bool CCECProcessor::GetDeviceInformation(const char *strPort, libcec_configuration *config, uint32_t iTimeoutMs /* = 10000 */)
+bool CCECProcessor::GetDeviceInformation(const char *strPort, libcec_configuration *config, uint32_t iTimeoutMs /* = CEC_DEFAULT_CONNECT_TIMEOUT */)
 {
-  if (!OpenConnection(strPort, 38400, iTimeoutMs, false))
+  if (!OpenConnection(strPort, CEC_SERIAL_DEFAULT_BAUDRATE, iTimeoutMs, false))
     return false;
 
-  config->iFirmwareVersion = m_communication->GetFirmwareVersion();
-  config->iPhysicalAddress = m_communication->GetPhysicalAddress();
+  config->iFirmwareVersion   = m_communication->GetFirmwareVersion();
+  config->iPhysicalAddress   = m_communication->GetPhysicalAddress();
+  config->iFirmwareBuildDate = m_communication->GetFirmwareBuildDate();
 
-  delete m_communication;
-  m_communication = NULL;
   return true;
 }
+
+bool CCECProcessor::TransmitPendingActiveSourceCommands(void)
+{
+  bool bReturn(true);
+  for (uint8_t iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++)
+    bReturn &= m_busDevices[iPtr]->TransmitPendingActiveSourceCommands();
+  return bReturn;
+}
+
+bool CCECProcessor::IsValidPhysicalAddress(uint16_t iPhysicalAddress)
+{
+  return iPhysicalAddress >= CEC_MIN_PHYSICAL_ADDRESS &&
+         iPhysicalAddress <= CEC_MAX_PHYSICAL_ADDRESS;
+}
index 25b0c2aa10f75d627191807155d87bac85fd4847..3986862fe719f3f2730c56bd5cb1840cd700d4af 100644 (file)
@@ -70,7 +70,7 @@ namespace CEC
       return bReturn;
     }
 
-    bool Pop(cec_command &command, uint16_t iTimeout = 10000)
+    bool Pop(cec_command &command, uint16_t iTimeout)
     {
       bool bReturn(false);
       PLATFORM::CLockObject lock(m_mutex);
@@ -102,69 +102,64 @@ namespace CEC
       CCECProcessor(CLibCEC *controller, libcec_configuration *configuration);
       virtual ~CCECProcessor(void);
 
-      virtual bool Start(const char *strPort, uint16_t iBaudRate = 38400, uint32_t iTimeoutMs = 10000);
-      virtual void *Process(void);
-      virtual void Close(void);
-
-      virtual bool                  OnCommandReceived(const cec_command &command);
-
-      virtual bool                  IsMonitoring(void) const { return m_bMonitor; }
-      virtual CCECBusDevice *       GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress, bool bRefresh = false, bool bSuppressPoll = false) const;
-      virtual CCECBusDevice *       GetDeviceByType(cec_device_type type) const;
-      virtual CCECBusDevice *       GetPrimaryDevice(void) const;
-      virtual cec_version           GetDeviceCecVersion(cec_logical_address iAddress);
-      virtual bool                  GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language);
-      virtual CStdString            GetDeviceName(void) const
-      {
-        CStdString strName;
-        strName = m_configuration.strDeviceName;
-        return strName;
-      }
-      virtual cec_osd_name          GetDeviceOSDName(cec_logical_address iAddress);
-      virtual uint64_t              GetDeviceVendorId(cec_logical_address iAddress);
-      virtual cec_power_status      GetDevicePowerStatus(cec_logical_address iAddress);
-      virtual cec_logical_address   GetLogicalAddress(void) const { return m_configuration.logicalAddresses.primary; }
-      virtual cec_logical_addresses GetLogicalAddresses(void) const { return m_configuration.logicalAddresses; }
-      virtual cec_logical_addresses GetActiveDevices(void);
-      virtual uint16_t              GetDevicePhysicalAddress(cec_logical_address iAddress);
-      virtual bool                  HasLogicalAddress(cec_logical_address address) const { return m_configuration.logicalAddresses.IsSet(address); }
-      virtual bool                  IsPresentDevice(cec_logical_address address);
-      virtual bool                  IsPresentDeviceType(cec_device_type type);
-      virtual uint16_t              GetPhysicalAddress(void) const;
-      virtual uint64_t              GetLastTransmission(void) const { return m_iLastTransmission; }
-      virtual cec_logical_address   GetActiveSource(void);
-      virtual bool                  IsActiveSource(cec_logical_address iAddress);
-      virtual bool                  IsInitialised(void);
-      virtual bool                  SetStreamPath(uint16_t iPhysicalAddress);
-      virtual cec_client_version    GetClientVersion(void) const { return (cec_client_version)m_configuration.clientVersion; };
-      virtual bool                  StandbyDevices(cec_logical_address address = CECDEVICE_BROADCAST);
-      virtual bool                  PowerOnDevices(cec_logical_address address = CECDEVICE_BROADCAST);
-
-      virtual bool SetActiveView(void);
-      virtual bool SetActiveSource(cec_device_type type = CEC_DEVICE_TYPE_RESERVED);
-      virtual bool SetDeckControlMode(cec_deck_control_mode mode, bool bSendUpdate = true);
-      virtual bool SetDeckInfo(cec_deck_info info, bool bSendUpdate = true);
-      virtual bool SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort, bool bForce = false);
-      virtual bool TransmitInactiveSource(void);
-      virtual bool SetLogicalAddress(cec_logical_address iLogicalAddress);
-      virtual bool SetMenuState(cec_menu_state state, bool bSendUpdate = true);
-      virtual bool SetPhysicalAddress(uint16_t iPhysicalAddress, bool bSendUpdate = true);
-      virtual bool SetActiveSource(uint16_t iStreamPath);
-      virtual bool SwitchMonitoring(bool bEnable);
-      virtual bool PollDevice(cec_logical_address iAddress);
-      virtual uint8_t VolumeUp(bool bSendRelease = true);
-      virtual uint8_t VolumeDown(bool bSendRelease = true);
-      virtual uint8_t MuteAudio(bool bSendRelease = true);
-      virtual bool TransmitKeypress(cec_logical_address iDestination, cec_user_control_code key, bool bWait = true);
-      virtual bool TransmitKeyRelease(cec_logical_address iDestination, bool bWait = true);
-      virtual bool EnablePhysicalAddressDetection(void);
+      bool Start(const char *strPort, uint16_t iBaudRate = CEC_SERIAL_DEFAULT_BAUDRATE, uint32_t iTimeoutMs = CEC_DEFAULT_CONNECT_TIMEOUT);
+      void *Process(void);
+      void Close(void);
+
+      bool                  OnCommandReceived(const cec_command &command);
+
+      bool                  IsMonitoring(void) const { return m_bMonitor; }
+      CCECBusDevice *       GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress, bool bSuppressUpdate = true);
+      CCECBusDevice *       GetDeviceByType(cec_device_type type) const;
+      CCECBusDevice *       GetPrimaryDevice(void) const;
+      cec_version           GetDeviceCecVersion(cec_logical_address iAddress);
+      bool                  GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language);
+      CStdString            GetDeviceName(void) const;
+      cec_osd_name          GetDeviceOSDName(cec_logical_address iAddress);
+      uint64_t              GetDeviceVendorId(cec_logical_address iAddress);
+      cec_power_status      GetDevicePowerStatus(cec_logical_address iAddress);
+      cec_logical_address   GetLogicalAddress(void) const { return m_configuration.logicalAddresses.primary; }
+      cec_logical_addresses GetLogicalAddresses(void) const { return m_configuration.logicalAddresses; }
+      cec_logical_addresses GetActiveDevices(void);
+      uint16_t              GetDevicePhysicalAddress(cec_logical_address iAddress);
+      bool                  HasLogicalAddress(cec_logical_address address) const { return m_configuration.logicalAddresses.IsSet(address); }
+      bool                  IsPresentDevice(cec_logical_address address);
+      bool                  IsPresentDeviceType(cec_device_type type);
+      uint16_t              GetPhysicalAddress(void) const;
+      uint64_t              GetLastTransmission(void) const { return m_iLastTransmission; }
+      cec_logical_address   GetActiveSource(bool bRequestActiveSource = true);
+      bool                  IsActiveSource(cec_logical_address iAddress);
+      bool                  IsInitialised(void);
+      bool                  SetStreamPath(uint16_t iPhysicalAddress);
+      cec_client_version    GetClientVersion(void) const { return (cec_client_version)m_configuration.clientVersion; };
+      bool                  StandbyDevices(cec_logical_address address = CECDEVICE_BROADCAST);
+      bool                  PowerOnDevices(cec_logical_address address = CECDEVICE_BROADCAST);
+
+      bool SetActiveView(void);
+      bool SetActiveSource(cec_device_type type = CEC_DEVICE_TYPE_RESERVED);
+      bool SetDeckControlMode(cec_deck_control_mode mode, bool bSendUpdate = true);
+      bool SetDeckInfo(cec_deck_info info, bool bSendUpdate = true);
+      bool SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort, bool bForce = false);
+      bool TransmitInactiveSource(void);
+      bool SetLogicalAddress(cec_logical_address iLogicalAddress);
+      bool SetMenuState(cec_menu_state state, bool bSendUpdate = true);
+      bool SetPhysicalAddress(uint16_t iPhysicalAddress, bool bSendUpdate = true);
+      bool SetActiveSource(uint16_t iStreamPath);
+      bool SwitchMonitoring(bool bEnable);
+      bool PollDevice(cec_logical_address iAddress);
+      uint8_t VolumeUp(bool bSendRelease = true);
+      uint8_t VolumeDown(bool bSendRelease = true);
+      uint8_t MuteAudio(bool bSendRelease = true);
+      bool TransmitKeypress(cec_logical_address iDestination, cec_user_control_code key, bool bWait = true);
+      bool TransmitKeyRelease(cec_logical_address iDestination, bool bWait = true);
+      bool EnablePhysicalAddressDetection(void);
       void SetStandardLineTimeout(uint8_t iTimeout);
       void SetRetryLineTimeout(uint8_t iTimeout);
-      virtual bool GetCurrentConfiguration(libcec_configuration *configuration);
-      virtual bool SetConfiguration(const libcec_configuration *configuration);
-      virtual bool CanPersistConfiguration(void);
-      virtual bool PersistConfiguration(libcec_configuration *configuration);
-      virtual void RescanActiveDevices(void);
+      bool GetCurrentConfiguration(libcec_configuration *configuration);
+      bool SetConfiguration(const libcec_configuration *configuration);
+      bool CanPersistConfiguration(void);
+      bool PersistConfiguration(libcec_configuration *configuration);
+      void RescanActiveDevices(void);
 
       bool SetLineTimeout(uint8_t iTimeout);
 
@@ -182,19 +177,23 @@ namespace CEC
       const char *ToString(const cec_client_version version);
       const char *ToString(const cec_server_version version);
 
-      virtual bool Transmit(const cec_command &data);
-      virtual void TransmitAbort(cec_logical_address address, cec_opcode opcode, cec_abort_reason reason = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE);
+      static bool IsValidPhysicalAddress(uint16_t iPhysicalAddress);
 
-      virtual bool ChangeDeviceType(cec_device_type from, cec_device_type to);
-      virtual bool FindLogicalAddresses(void);
-      virtual bool SetAckMask(uint16_t iMask);
+      bool Transmit(const cec_command &data);
+      void TransmitAbort(cec_logical_address address, cec_opcode opcode, cec_abort_reason reason = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE);
 
-      virtual bool StartBootloader(const char *strPort = NULL);
-      virtual bool PingAdapter(void);
-      virtual void HandlePoll(cec_logical_address initiator, cec_logical_address destination);
-      virtual bool HandleReceiveFailed(cec_logical_address initiator);
+      bool ChangeDeviceType(cec_device_type from, cec_device_type to);
+      bool FindLogicalAddresses(void);
+      bool SetAckMask(uint16_t iMask);
 
-      virtual bool GetDeviceInformation(const char *strPort, libcec_configuration *config, uint32_t iTimeoutMs = 10000);
+      bool StartBootloader(const char *strPort = NULL);
+      bool PingAdapter(void);
+      void HandlePoll(cec_logical_address initiator, cec_logical_address destination);
+      bool HandleReceiveFailed(cec_logical_address initiator);
+
+      bool GetDeviceInformation(const char *strPort, libcec_configuration *config, uint32_t iTimeoutMs = CEC_DEFAULT_CONNECT_TIMEOUT);
+
+      bool TransmitPendingActiveSourceCommands(void);
 
       CCECBusDevice *  m_busDevices[16];
 
@@ -229,17 +228,4 @@ namespace CEC
       CCECInputBuffer                     m_inBuffer;
       libcec_configuration                m_configuration;
   };
-
-  class CCECBusScan : public PLATFORM::CThread
-  {
-  public:
-    CCECBusScan(CCECProcessor *processor) { m_processor = processor; }
-    virtual ~CCECBusScan(void) { StopThread(true); }
-    virtual void *Process(void);
-
-  private:
-    void WaitUntilIdle(void);
-
-    CCECProcessor *m_processor;
-  };
 };
index 20c670d3a6c028f020f80d055804076f8f4c1d3e..88e93e0dcd07a2d3ae2c366c46d068219b8faa54 100644 (file)
@@ -60,7 +60,6 @@ CLibCEC::CLibCEC(libcec_configuration *configuration) :
     m_callbacks(configuration->callbacks),
     m_cbParam(configuration->callbackParam)
 {
-  configuration->serverVersion = CEC_SERVER_VERSION_1_6_1;
   m_cec = new CCECProcessor(this, configuration);
 }
 
@@ -69,7 +68,7 @@ CLibCEC::~CLibCEC(void)
   delete m_cec;
 }
 
-bool CLibCEC::Open(const char *strPort, uint32_t iTimeoutMs /* = 10000 */)
+bool CLibCEC::Open(const char *strPort, uint32_t iTimeoutMs /* = CEC_DEFAULT_CONNECT_TIMEOUT */)
 {
   if (m_cec->IsRunning())
   {
@@ -77,7 +76,7 @@ bool CLibCEC::Open(const char *strPort, uint32_t iTimeoutMs /* = 10000 */)
     return false;
   }
 
-  if (!m_cec->Start(strPort, 38400, iTimeoutMs))
+  if (!m_cec->Start(strPort, CEC_SERIAL_DEFAULT_BAUDRATE, iTimeoutMs))
   {
     AddLog(CEC_LOG_ERROR, "could not start CEC communications");
     return false;
@@ -354,14 +353,14 @@ void CLibCEC::AddLog(const cec_log_level level, const char *strFormat, ...)
   CLibCEC *instance = CLibCEC::GetInstance();
   if (!instance)
     return;
-  CLockObject lock(instance->m_mutex);
+  CLockObject lock(instance->m_logMutex);
 
   cec_log_message message;
   message.level = level;
   message.time = GetTimeMs() - instance->m_iStartTime;
   snprintf(message.message, sizeof(message.message), "%s", strLog.c_str());
 
-  if (instance->m_callbacks)
+  if (instance->m_callbacks && instance->m_callbacks->CBCecLogMessage)
     instance->m_callbacks->CBCecLogMessage(instance->m_cbParam, message);
   else
     instance->m_logBuffer.Push(message);
@@ -376,7 +375,7 @@ void CLibCEC::AddKey(const cec_keypress &key)
 
   AddLog(CEC_LOG_DEBUG, "key pressed: %1x", key.keycode);
 
-  if (instance->m_callbacks)
+  if (instance->m_callbacks && instance->m_callbacks->CBCecKeyPress)
     instance->m_callbacks->CBCecKeyPress(instance->m_cbParam, key);
   else
     instance->m_keyBuffer.Push(key);
@@ -392,7 +391,7 @@ void CLibCEC::ConfigurationChanged(const libcec_configuration &config)
 
   if (instance->m_callbacks &&
       config.clientVersion >= CEC_CLIENT_VERSION_1_5_0 &&
-      instance->m_callbacks->CBCecConfigurationChanged != NULL &&
+      instance->m_callbacks->CBCecConfigurationChanged &&
       instance->m_cec->IsInitialised())
     instance->m_callbacks->CBCecConfigurationChanged(instance->m_cbParam, config);
 }
@@ -423,7 +422,7 @@ void CLibCEC::AddKey(void)
     key.keycode = instance->m_iCurrentButton;
     AddLog(CEC_LOG_DEBUG, "key released: %1x", key.keycode);
 
-    if (instance->m_callbacks)
+    if (instance->m_callbacks && instance->m_callbacks->CBCecKeyPress)
       instance->m_callbacks->CBCecKeyPress(instance->m_cbParam, key);
     else
       instance->m_keyBuffer.Push(key);
@@ -441,12 +440,32 @@ void CLibCEC::AddCommand(const cec_command &command)
 
   AddLog(CEC_LOG_NOTICE, ">> %s (%X) -> %s (%X): %s (%2X)", instance->m_cec->ToString(command.initiator), command.initiator, instance->m_cec->ToString(command.destination), command.destination, instance->m_cec->ToString(command.opcode), command.opcode);
 
-  if (instance->m_callbacks)
+  if (instance->m_callbacks && instance->m_callbacks->CBCecCommand)
     instance->m_callbacks->CBCecCommand(instance->m_cbParam, command);
   else if (!instance->m_commandBuffer.Push(command))
     AddLog(CEC_LOG_WARNING, "command buffer is full");
 }
 
+void CLibCEC::Alert(const libcec_alert type, const libcec_parameter &param)
+{
+  CLibCEC *instance = CLibCEC::GetInstance();
+  if (!instance)
+    return;
+  CLockObject lock(instance->m_mutex);
+
+  libcec_configuration config;
+  instance->GetCurrentConfiguration(&config);
+
+  if (instance->m_callbacks &&
+      config.clientVersion >= CEC_CLIENT_VERSION_1_6_0 &&
+      instance->m_cec->IsInitialised() &&
+      instance->m_callbacks->CBCecAlert)
+    instance->m_callbacks->CBCecAlert(instance->m_cbParam, type, param);
+
+  if (type == CEC_ALERT_CONNECTION_LOST)
+    instance->Close();
+}
+
 void CLibCEC::CheckKeypressTimeout(void)
 {
   if (m_iCurrentButton != CEC_USER_CONTROL_CODE_UNKNOWN && GetTimeMs() - m_buttontime > CEC_BUTTON_TIMEOUT)
@@ -456,10 +475,32 @@ void CLibCEC::CheckKeypressTimeout(void)
   }
 }
 
+int CLibCEC::MenuStateChanged(const cec_menu_state newState)
+{
+  int iReturn(0);
+
+  CLibCEC *instance = CLibCEC::GetInstance();
+  if (!instance)
+    return iReturn;
+  CLockObject lock(instance->m_mutex);
+
+  AddLog(CEC_LOG_NOTICE, ">> %s: %s", instance->m_cec->ToString(CEC_OPCODE_MENU_REQUEST), instance->m_cec->ToString(newState));
+
+  libcec_configuration config;
+  instance->GetCurrentConfiguration(&config);
+
+  if (instance->m_callbacks &&
+      config.clientVersion >= CEC_CLIENT_VERSION_1_6_2 &&
+      instance->m_callbacks->CBCecMenuStateChanged)
+    iReturn = instance->m_callbacks->CBCecMenuStateChanged(instance->m_cbParam, newState);
+
+  return iReturn;
+}
+
 bool CLibCEC::SetStreamPath(cec_logical_address iAddress)
 {
   uint16_t iPhysicalAddress = GetDevicePhysicalAddress(iAddress);
-  if (iPhysicalAddress != 0xFFFF)
+  if (iPhysicalAddress != CEC_INVALID_PHYSICAL_ADDRESS)
     return SetStreamPath(iPhysicalAddress);
   return false;
 }
@@ -499,6 +540,7 @@ void * CECInitialise(libcec_configuration *configuration)
 {
   CLibCEC *lib = new CLibCEC(configuration);
   CLibCEC::SetInstance(lib);
+  lib->GetCurrentConfiguration(configuration);
   return static_cast< void* > (lib);
 }
 
@@ -509,7 +551,7 @@ bool CECStartBootloader(void)
   if (CUSBCECAdapterDetection::FindAdapters(deviceList, 1) > 0)
   {
     CUSBCECAdapterCommunication comm(NULL, deviceList[0].comm);
-    CTimeout timeout(10000);
+    CTimeout timeout(CEC_DEFAULT_CONNECT_TIMEOUT);
     while (timeout.TimeLeft() > 0 && (bReturn = comm.Open(timeout.TimeLeft() / CEC_CONNECT_TRIES, true)) == false)
     {
       comm.Close();
@@ -594,7 +636,7 @@ const char *CLibCEC::ToString(const cec_device_type type)
 
 bool CLibCEC::GetCurrentConfiguration(libcec_configuration *configuration)
 {
-  return m_cec->IsInitialised() && m_cec->GetCurrentConfiguration(configuration);
+  return m_cec->GetCurrentConfiguration(configuration);
 }
 
 bool CLibCEC::SetConfiguration(const libcec_configuration *configuration)
@@ -711,7 +753,7 @@ uint16_t CLibCEC::GetMaskForType(cec_device_type type)
   }
 }
 
-bool CLibCEC::GetDeviceInformation(const char *strPort, libcec_configuration *config, uint32_t iTimeoutMs /* = 10000 */)
+bool CLibCEC::GetDeviceInformation(const char *strPort, libcec_configuration *config, uint32_t iTimeoutMs /* = CEC_DEFAULT_CONNECT_TIMEOUT */)
 {
   if (m_cec->IsRunning())
     return false;
index 46973711bed2269cadba69e9c678515cfe973ea3..563cec1ca1c0a0d7db8561280e2247a2a05c055d 100644 (file)
@@ -51,63 +51,63 @@ namespace CEC
       CLibCEC(libcec_configuration *configuration);
       virtual ~CLibCEC(void);
 
-      virtual bool Open(const char *strPort, uint32_t iTimeout = 10000);
-      virtual void Close(void);
-      virtual bool EnableCallbacks(void *cbParam, ICECCallbacks *callbacks);
-      virtual int8_t FindAdapters(cec_adapter *deviceList, uint8_t iBufSize, const char *strDevicePath = NULL);
-      virtual bool PingAdapter(void);
-      virtual bool StartBootloader(void);
+      bool Open(const char *strPort, uint32_t iTimeout = CEC_DEFAULT_CONNECT_TIMEOUT);
+      void Close(void);
+      bool EnableCallbacks(void *cbParam, ICECCallbacks *callbacks);
+      int8_t FindAdapters(cec_adapter *deviceList, uint8_t iBufSize, const char *strDevicePath = NULL);
+      bool PingAdapter(void);
+      bool StartBootloader(void);
 
-      virtual int8_t GetMinLibVersion(void) const   { return CEC_MIN_LIB_VERSION; };
-      virtual int8_t GetLibVersionMajor(void) const { return CEC_LIB_VERSION_MAJOR; };
-      virtual int8_t GetLibVersionMinor(void) const { return CEC_LIB_VERSION_MINOR; };
+      int8_t GetMinLibVersion(void) const   { return CEC_MIN_LIB_VERSION; };
+      int8_t GetLibVersionMajor(void) const { return CEC_LIB_VERSION_MAJOR; };
+      int8_t GetLibVersionMinor(void) const { return CEC_LIB_VERSION_MINOR; };
 
-      virtual bool GetNextLogMessage(cec_log_message *message);
-      virtual bool GetNextKeypress(cec_keypress *key);
-      virtual bool GetNextCommand(cec_command *command);
+      bool GetNextLogMessage(cec_log_message *message);
+      bool GetNextKeypress(cec_keypress *key);
+      bool GetNextCommand(cec_command *command);
 
-      virtual bool Transmit(const cec_command &data);
-      virtual bool SetLogicalAddress(cec_logical_address iLogicalAddress = CECDEVICE_PLAYBACKDEVICE1);
-      virtual bool SetPhysicalAddress(uint16_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS);
+      bool Transmit(const cec_command &data);
+      bool SetLogicalAddress(cec_logical_address iLogicalAddress = CECDEVICE_PLAYBACKDEVICE1);
+      bool SetPhysicalAddress(uint16_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS);
 
-      virtual bool PowerOnDevices(cec_logical_address address = CECDEVICE_TV);
-      virtual bool StandbyDevices(cec_logical_address address = CECDEVICE_BROADCAST);
-      virtual bool SetActiveView(void);
-      virtual bool SetActiveSource(cec_device_type type = CEC_DEVICE_TYPE_RESERVED);
-      virtual bool SetDeckControlMode(cec_deck_control_mode mode, bool bSendUpdate = true);
-      virtual bool SetDeckInfo(cec_deck_info info, bool bSendUpdate = true);
-      virtual bool SetInactiveView(void);
-      virtual bool SetMenuState(cec_menu_state state, bool bSendUpdate = true);
-      virtual bool SetOSDString(cec_logical_address iLogicalAddress, cec_display_control duration, const char *strMessage);
-      virtual bool SwitchMonitoring(bool bEnable);
-      virtual cec_version GetDeviceCecVersion(cec_logical_address iAddress);
-      virtual bool GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language);
-      virtual uint64_t GetDeviceVendorId(cec_logical_address iAddress);
-      virtual uint16_t GetDevicePhysicalAddress(cec_logical_address iAddress);
-      virtual cec_power_status GetDevicePowerStatus(cec_logical_address iAddress);
-      virtual bool PollDevice(cec_logical_address iAddress);
-      virtual cec_logical_addresses GetActiveDevices(void);
-      virtual bool IsActiveDevice(cec_logical_address iAddress);
-      virtual bool IsActiveDeviceType(cec_device_type type);
-      virtual bool SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort = CEC_DEFAULT_HDMI_PORT);
-      virtual uint8_t VolumeUp(bool bSendRelease = true);
-      virtual uint8_t VolumeDown(bool bSendRelease = true);
-      virtual uint8_t MuteAudio(bool bSendRelease = true);
-      virtual bool SendKeypress(cec_logical_address iDestination, cec_user_control_code key, bool bWait = true);
-      virtual bool SendKeyRelease(cec_logical_address iDestination, bool bWait = true);
-      virtual cec_osd_name GetDeviceOSDName(cec_logical_address iAddress);
-      virtual bool EnablePhysicalAddressDetection(void);
-      virtual cec_logical_address GetActiveSource(void);
-      virtual bool IsActiveSource(cec_logical_address iAddress);
-      virtual bool SetStreamPath(cec_logical_address iAddress);
-      virtual bool SetStreamPath(uint16_t iPhysicalAddress);
-      virtual cec_logical_addresses GetLogicalAddresses(void);
-      virtual bool GetCurrentConfiguration(libcec_configuration *configuration);
-      virtual bool SetConfiguration(const libcec_configuration *configuration);
-      virtual bool CanPersistConfiguration(void);
-      virtual bool PersistConfiguration(libcec_configuration *configuration);
-      virtual void RescanActiveDevices(void);
-      virtual bool IsLibCECActiveSource(void);
+      bool PowerOnDevices(cec_logical_address address = CECDEVICE_TV);
+      bool StandbyDevices(cec_logical_address address = CECDEVICE_BROADCAST);
+      bool SetActiveView(void);
+      bool SetActiveSource(cec_device_type type = CEC_DEVICE_TYPE_RESERVED);
+      bool SetDeckControlMode(cec_deck_control_mode mode, bool bSendUpdate = true);
+      bool SetDeckInfo(cec_deck_info info, bool bSendUpdate = true);
+      bool SetInactiveView(void);
+      bool SetMenuState(cec_menu_state state, bool bSendUpdate = true);
+      bool SetOSDString(cec_logical_address iLogicalAddress, cec_display_control duration, const char *strMessage);
+      bool SwitchMonitoring(bool bEnable);
+      cec_version GetDeviceCecVersion(cec_logical_address iAddress);
+      bool GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language);
+      uint64_t GetDeviceVendorId(cec_logical_address iAddress);
+      uint16_t GetDevicePhysicalAddress(cec_logical_address iAddress);
+      cec_power_status GetDevicePowerStatus(cec_logical_address iAddress);
+      bool PollDevice(cec_logical_address iAddress);
+      cec_logical_addresses GetActiveDevices(void);
+      bool IsActiveDevice(cec_logical_address iAddress);
+      bool IsActiveDeviceType(cec_device_type type);
+      bool SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort = CEC_DEFAULT_HDMI_PORT);
+      uint8_t VolumeUp(bool bSendRelease = true);
+      uint8_t VolumeDown(bool bSendRelease = true);
+      uint8_t MuteAudio(bool bSendRelease = true);
+      bool SendKeypress(cec_logical_address iDestination, cec_user_control_code key, bool bWait = true);
+      bool SendKeyRelease(cec_logical_address iDestination, bool bWait = true);
+      cec_osd_name GetDeviceOSDName(cec_logical_address iAddress);
+      bool EnablePhysicalAddressDetection(void);
+      cec_logical_address GetActiveSource(void);
+      bool IsActiveSource(cec_logical_address iAddress);
+      bool SetStreamPath(cec_logical_address iAddress);
+      bool SetStreamPath(uint16_t iPhysicalAddress);
+      cec_logical_addresses GetLogicalAddresses(void);
+      bool GetCurrentConfiguration(libcec_configuration *configuration);
+      bool SetConfiguration(const libcec_configuration *configuration);
+      bool CanPersistConfiguration(void);
+      bool PersistConfiguration(libcec_configuration *configuration);
+      void RescanActiveDevices(void);
+      bool IsLibCECActiveSource(void);
 
       const char *ToString(const cec_menu_state state);
       const char *ToString(const cec_version version);
@@ -127,7 +127,7 @@ namespace CEC
       static uint16_t GetMaskForType(cec_logical_address address);
       static uint16_t GetMaskForType(cec_device_type type);
 
-      virtual bool GetDeviceInformation(const char *strPort, libcec_configuration *config, uint32_t iTimeoutMs = 10000);
+      bool GetDeviceInformation(const char *strPort, libcec_configuration *config, uint32_t iTimeoutMs = CEC_DEFAULT_CONNECT_TIMEOUT);
     //@}
 
       static void AddLog(const cec_log_level level, const char *strFormat, ...);
@@ -136,7 +136,9 @@ namespace CEC
       static void AddCommand(const cec_command &command);
       static void ConfigurationChanged(const libcec_configuration &config);
       static void SetCurrentButton(cec_user_control_code iButtonCode);
-      virtual void CheckKeypressTimeout(void);
+      void CheckKeypressTimeout(void);
+      static int MenuStateChanged(const cec_menu_state newState);
+      static void Alert(const libcec_alert type, const libcec_parameter &param);
 
       static CLibCEC *GetInstance(void);
       static void SetInstance(CLibCEC *instance);
@@ -152,5 +154,6 @@ namespace CEC
       ICECCallbacks *                         m_callbacks;
       void *                                  m_cbParam;
       PLATFORM::CMutex                        m_mutex;
+      PLATFORM::CMutex                        m_logMutex;
   };
 };
index 160a0fd3c30c320f9d262e6b2725c48b61fc0673..48883bb2f3a07646d2b8894f0ad10c5493c67fe7 100644 (file)
@@ -81,7 +81,7 @@ namespace CEC
      * @param bStartListening Start a listener thread when true. False to just open a connection, read the device info, and close the connection.
      * @return True when connected, false otherwise
      */
-    virtual bool Open(uint32_t iTimeoutMs = 10000, bool bSkipChecks = false, bool bStartListening = true) = 0;
+    virtual bool Open(uint32_t iTimeoutMs = CEC_DEFAULT_CONNECT_TIMEOUT, bool bSkipChecks = false, bool bStartListening = true) = 0;
 
     /*!
      * @brief Close an open connection
@@ -101,12 +101,11 @@ namespace CEC
     /*!
      * @brief Write a cec_command to the adapter
      * @param data The command to write
-     * @param iMaxTries The maximum number of tries
-     * @param iLineTimeout The line timeout for the first try
-     * @param iRetryLineTimeout The line timeout for each next try
+     * @param bRetry The command can be retried
+     * @param iLineTimeout The line timeout to be used
      * @return The last state of the transmitted command
      */
-    virtual cec_adapter_message_state Write(const cec_command &data, uint8_t iMaxTries, uint8_t iLineTimeout = 3, uint8_t iRetryLineTimeout = 3) = 0;
+    virtual cec_adapter_message_state Write(const cec_command &data, bool &bRetry, uint8_t iLineTimeout = 3) = 0;
 
     /*!
      * @brief Change the current line timeout on the CEC bus
@@ -139,6 +138,11 @@ namespace CEC
      */
     virtual uint16_t GetFirmwareVersion(void) = 0;
 
+    /*!
+     * @return The build date in seconds since epoch, or 0 when no (valid) reply was received.
+     */
+    virtual uint32_t GetFirmwareBuildDate(void) = 0;
+
     /*!
      * @return True when the control mode has been set, false otherwise.
      */
index 543dbced8f23c93571b8910f94f466276ea4840d..0374dbee60b19f662f693a6bbf430d57a93f1f28 100644 (file)
@@ -43,7 +43,8 @@ CUSBCECAdapterCommands::CUSBCECAdapterCommands(CUSBCECAdapterCommunication *comm
     m_bSettingAutoEnabled(false),
     m_settingCecVersion(CEC_VERSION_UNKNOWN),
     m_iSettingLAMask(0),
-    m_bNeedsWrite(false)
+    m_bNeedsWrite(false),
+    m_iBuildDate(CEC_FW_BUILD_UNKNOWN)
 {
   m_persistedConfiguration.Clear();
 }
@@ -100,6 +101,7 @@ bool CUSBCECAdapterCommands::RequestSettingAutoEnabled(void)
   if (response.size == 1)
   {
     m_bSettingAutoEnabled = response[0] == 1;
+    CLibCEC::AddLog(CEC_LOG_DEBUG, "using persisted autonomous mode setting: '%s'", m_bSettingAutoEnabled ? "enabled" : "disabled");
     return true;
   }
   return false;
@@ -113,11 +115,25 @@ bool CUSBCECAdapterCommands::RequestSettingCECVersion(void)
   if (response.size == 1)
   {
     m_settingCecVersion = (cec_version)response[0];
+    CLibCEC::AddLog(CEC_LOG_DEBUG, "using persisted CEC version setting: '%s'", CLibCEC::GetInstance()->ToString(m_settingCecVersion));
     return true;
   }
   return false;
 }
 
+uint32_t CUSBCECAdapterCommands::RequestBuildDate(void)
+{
+  if (m_iBuildDate == CEC_FW_BUILD_UNKNOWN)
+  {
+    CLibCEC::AddLog(CEC_LOG_DEBUG, "requesting firmware build date");
+
+    cec_datapacket response = RequestSetting(MSGCODE_GET_BUILDDATE);
+    if (response.size == 4)
+      m_iBuildDate = (uint32_t)response[0] << 24 | (uint32_t)response[1] << 16 | (uint32_t)response[2] << 8 | (uint32_t)response[3];
+  }
+  return m_iBuildDate;
+}
+
 bool CUSBCECAdapterCommands::RequestSettingDefaultLogicalAddress(void)
 {
   CLibCEC::AddLog(CEC_LOG_DEBUG, "requesting default logical address setting");
@@ -126,6 +142,7 @@ bool CUSBCECAdapterCommands::RequestSettingDefaultLogicalAddress(void)
   if (response.size == 1)
   {
     m_persistedConfiguration.logicalAddresses.primary = (cec_logical_address)response[0];
+    CLibCEC::AddLog(CEC_LOG_DEBUG, "using persisted logical address setting: '%s'", CLibCEC::GetInstance()->ToString(m_persistedConfiguration.logicalAddresses.primary));
     return true;
   }
   return false;
@@ -140,7 +157,7 @@ bool CUSBCECAdapterCommands::RequestSettingDeviceType(void)
   if (response.size == 1)
   {
     m_persistedConfiguration.deviceTypes.Add((cec_device_type)response[0]);
-    CLibCEC::AddLog(CEC_LOG_DEBUG, "using persisted device type setting %s", CLibCEC::GetInstance()->ToString((cec_device_type)response[0]));
+    CLibCEC::AddLog(CEC_LOG_DEBUG, "using persisted device type setting: '%s'", CLibCEC::GetInstance()->ToString((cec_device_type)response[0]));
     return true;
   }
   CLibCEC::AddLog(CEC_LOG_DEBUG, "no persisted device type setting");
@@ -155,6 +172,7 @@ bool CUSBCECAdapterCommands::RequestSettingLogicalAddressMask(void)
   if (response.size == 2)
   {
     m_iSettingLAMask = ((uint16_t)response[0] << 8) | ((uint16_t)response[1]);
+    CLibCEC::AddLog(CEC_LOG_DEBUG, "using persisted logical address mask setting: '%x'", m_iSettingLAMask);
     return true;
   }
   return false;
@@ -178,7 +196,7 @@ bool CUSBCECAdapterCommands::RequestSettingOSDName(void)
   buf[response.size] = 0;
 
   snprintf(m_persistedConfiguration.strDeviceName, 13, "%s", buf);
-  CLibCEC::AddLog(CEC_LOG_DEBUG, "using persisted device name setting %s", buf);
+  CLibCEC::AddLog(CEC_LOG_DEBUG, "using persisted device name setting: '%s'", buf);
   return true;
 }
 
@@ -190,7 +208,7 @@ bool CUSBCECAdapterCommands::RequestSettingPhysicalAddress(void)
   if (response.size == 2)
   {
     m_persistedConfiguration.iPhysicalAddress = ((uint16_t)response[0] << 8) | ((uint16_t)response[1]);
-    CLibCEC::AddLog(CEC_LOG_DEBUG, "using persisted physical address setting %4x", m_persistedConfiguration.iPhysicalAddress);
+    CLibCEC::AddLog(CEC_LOG_DEBUG, "using persisted physical address setting: '%4x'", m_persistedConfiguration.iPhysicalAddress);
     return true;
   }
   CLibCEC::AddLog(CEC_LOG_DEBUG, "no persisted physical address setting");
@@ -235,7 +253,7 @@ bool CUSBCECAdapterCommands::SetSettingDeviceType(cec_device_type type)
   }
 
   m_bNeedsWrite = true;
-  CLibCEC::AddLog(CEC_LOG_DEBUG, "setting the device type to %X", (uint8_t)type);
+  CLibCEC::AddLog(CEC_LOG_DEBUG, "setting the device type to %X (previous: %X)", (uint8_t)type, (uint8_t)m_persistedConfiguration.deviceTypes.types[0]);
 
   CCECAdapterMessage params;
   params.PushEscaped((uint8_t)type);
@@ -258,7 +276,7 @@ bool CUSBCECAdapterCommands::SetSettingDefaultLogicalAddress(cec_logical_address
   }
 
   m_bNeedsWrite = true;
-  CLibCEC::AddLog(CEC_LOG_DEBUG, "setting the default logical address to %X", (uint8_t)address);
+  CLibCEC::AddLog(CEC_LOG_DEBUG, "setting the default logical address to %X (previous: %X)", (uint8_t)address, (uint8_t)m_persistedConfiguration.logicalAddresses.primary);
 
   CCECAdapterMessage params;
   params.PushEscaped((uint8_t)address);
@@ -284,7 +302,7 @@ bool CUSBCECAdapterCommands::SetSettingLogicalAddressMask(uint16_t iMask)
   }
 
   m_bNeedsWrite = true;
-  CLibCEC::AddLog(CEC_LOG_DEBUG, "setting the logical address mask to %2X", iMask);
+  CLibCEC::AddLog(CEC_LOG_DEBUG, "setting the logical address mask to %2X (previous: %2X)", iMask, m_iSettingLAMask);
 
   CCECAdapterMessage params;
   params.PushEscaped(iMask >> 8);
@@ -311,7 +329,7 @@ bool CUSBCECAdapterCommands::SetSettingPhysicalAddress(uint16_t iPhysicalAddress
   }
 
   m_bNeedsWrite = true;
-  CLibCEC::AddLog(CEC_LOG_DEBUG, "setting the physical address to %04X", iPhysicalAddress);
+  CLibCEC::AddLog(CEC_LOG_DEBUG, "setting the physical address to %04X (previous: %04X)", iPhysicalAddress, m_persistedConfiguration.iPhysicalAddress);
 
   CCECAdapterMessage params;
   params.PushEscaped(iPhysicalAddress >> 8);
@@ -338,7 +356,7 @@ bool CUSBCECAdapterCommands::SetSettingCECVersion(cec_version version)
   }
 
   m_bNeedsWrite = true;
-  CLibCEC::AddLog(CEC_LOG_DEBUG, "setting the CEC version to %s", CLibCEC::GetInstance()->ToString(version));
+  CLibCEC::AddLog(CEC_LOG_DEBUG, "setting the CEC version to %s (previous: %s)", CLibCEC::GetInstance()->ToString(version), CLibCEC::GetInstance()->ToString(m_settingCecVersion));
 
   CCECAdapterMessage params;
   params.PushEscaped((uint8_t)version);
@@ -363,7 +381,7 @@ bool CUSBCECAdapterCommands::SetSettingOSDName(const char *strOSDName)
     return bReturn;
   }
 
-  CLibCEC::AddLog(CEC_LOG_DEBUG, "setting the OSD name to %s", strOSDName);
+  CLibCEC::AddLog(CEC_LOG_DEBUG, "setting the OSD name to %s (previous: %s)", strOSDName, m_persistedConfiguration.strDeviceName);
 
   CCECAdapterMessage params;
   for (size_t iPtr = 0; iPtr < strlen(strOSDName); iPtr++)
index b88651e11619dfe5456074d43010f04853ceaf19..389aa5f680a74a44d19ccf125491f0f45a9b5ffd 100644 (file)
@@ -100,6 +100,12 @@ namespace CEC
      */
     bool SetControlledMode(bool controlled);
 
+    /*!
+     * @brief Request the firmware build date from the device.
+     * @return The build date in seconds since epoch, or 0 when no (valid) reply was received.
+     */
+    uint32_t RequestBuildDate(void);
+
   private:
     /*!
      * @brief Reads all settings from the eeprom.
@@ -218,5 +224,6 @@ namespace CEC
     uint16_t                     m_iSettingLAMask;         /**< the value of the LA mask setting */
     bool                         m_bNeedsWrite;            /**< true when we sent changed settings to the adapter that have not been persisted */
     libcec_configuration         m_persistedConfiguration; /**< the configuration that is persisted in the eeprom */
+    uint32_t                     m_iBuildDate;             /**< the build date of the firmware */
   };
 }
index ef80ed049731abe60fe886f67dcd91018a40ac89..6a4a0b99b99171cce2621406afdd4309163025c1 100644 (file)
@@ -44,7 +44,7 @@ using namespace PLATFORM;
 
 #define CEC_ADAPTER_PING_TIMEOUT 15000
 
-CUSBCECAdapterCommunication::CUSBCECAdapterCommunication(IAdapterCommunicationCallback *callback, const char *strPort, uint16_t iBaudRate /* = 38400 */) :
+CUSBCECAdapterCommunication::CUSBCECAdapterCommunication(IAdapterCommunicationCallback *callback, const char *strPort, uint16_t iBaudRate /* = CEC_SERIAL_DEFAULT_BAUDRATE */) :
     IAdapterCommunication(callback),
     m_port(NULL),
     m_iLineTimeout(0),
@@ -54,7 +54,7 @@ CUSBCECAdapterCommunication::CUSBCECAdapterCommunication(IAdapterCommunicationCa
     m_commands(NULL),
     m_adapterMessageQueue(NULL)
 {
-  for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
+  for (unsigned int iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++)
     m_bWaitingForAck[iPtr] = false;
   m_port = new CSerialPort(strPort, iBaudRate);
 }
@@ -67,7 +67,7 @@ CUSBCECAdapterCommunication::~CUSBCECAdapterCommunication(void)
   delete m_port;
 }
 
-bool CUSBCECAdapterCommunication::Open(uint32_t iTimeoutMs /* = 10000 */, bool bSkipChecks /* = false */, bool bStartListening /* = true */)
+bool CUSBCECAdapterCommunication::Open(uint32_t iTimeoutMs /* = CEC_DEFAULT_CONNECT_TIMEOUT */, bool bSkipChecks /* = false */, bool bStartListening /* = true */)
 {
   bool bConnectionOpened(false);
   {
@@ -92,7 +92,10 @@ bool CUSBCECAdapterCommunication::Open(uint32_t iTimeoutMs /* = 10000 */, bool b
       m_commands = new CUSBCECAdapterCommands(this);
 
     if (!m_adapterMessageQueue)
+    {
       m_adapterMessageQueue = new CCECAdapterMessageQueue(this);
+      m_adapterMessageQueue->CreateThread();
+    }
 
     /* try to open the connection */
     CStdString strError;
@@ -152,47 +155,51 @@ bool CUSBCECAdapterCommunication::Open(uint32_t iTimeoutMs /* = 10000 */, bool b
 
 void CUSBCECAdapterCommunication::Close(void)
 {
+  /* stop the reader thread */
+  StopThread(0);
+
+  CLockObject lock(m_mutex);
+
   /* set the ackmask to 0 before closing the connection */
-  if (IsRunning())
+  if (IsRunning() && m_port->IsOpen() && m_port->GetErrorNumber() == 0)
   {
+    CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - closing the connection", __FUNCTION__);
     SetAckMask(0);
     if (m_commands->GetFirmwareVersion() >= 2)
       SetControlledMode(false);
   }
 
+  m_adapterMessageQueue->Clear();
+
   /* stop and delete the ping thread */
   if (m_pingThread)
     m_pingThread->StopThread(0);
   delete m_pingThread;
   m_pingThread = NULL;
 
-  /* stop the reader thread */
-  StopThread(0);
-
   /* close and delete the com port connection */
   if (m_port)
     m_port->Close();
+
+  libcec_parameter param;
+  CLibCEC::Alert(CEC_ALERT_CONNECTION_LOST, param);
 }
 
-cec_adapter_message_state CUSBCECAdapterCommunication::Write(const cec_command &data, uint8_t iMaxTries, uint8_t iLineTimeout /* = 3 */, uint8_t iRetryLineTimeout /* = 3 */)
+cec_adapter_message_state CUSBCECAdapterCommunication::Write(const cec_command &data, bool &bRetry, uint8_t iLineTimeout)
 {
   cec_adapter_message_state retVal(ADAPTER_MESSAGE_STATE_UNKNOWN);
   if (!IsRunning())
     return retVal;
 
-  CCECAdapterMessage *output = new CCECAdapterMessage(data, iMaxTries, iLineTimeout, iRetryLineTimeout);
+  CCECAdapterMessage *output = new CCECAdapterMessage(data, iLineTimeout);
 
   /* mark as waiting for an ack from the destination */
   MarkAsWaiting(data.destination);
 
   /* send the message */
-  bool bRetry(true);
-  while (bRetry && ++output->tries < output->maxTries)
-  {
-    bRetry = (!m_adapterMessageQueue->Write(output) || output->NeedsRetry()) && output->transmit_timeout > 0;
-    if (bRetry)
-      Sleep(CEC_DEFAULT_TRANSMIT_RETRY_WAIT);
-  }
+  bRetry = (!m_adapterMessageQueue->Write(output) || output->NeedsRetry()) && output->transmit_timeout > 0;
+  if (bRetry)
+    Sleep(CEC_DEFAULT_TRANSMIT_RETRY_WAIT);
   retVal = output->state;
 
   delete output;
@@ -259,7 +266,7 @@ void CUSBCECAdapterCommunication::MarkAsWaiting(const cec_logical_address dest)
   }
 }
 
-void CUSBCECAdapterCommunication::ClearInputBytes(uint32_t iTimeout /* = 1000 */)
+void CUSBCECAdapterCommunication::ClearInputBytes(uint32_t iTimeout /* = CEC_CLEAR_INPUT_DEFAULT_WAIT */)
 {
   CTimeout timeout(iTimeout);
   uint8_t buff[1024];
@@ -298,7 +305,7 @@ bool CUSBCECAdapterCommunication::WriteToDevice(CCECAdapterMessage *message)
   CLockObject adapterLock(m_mutex);
   if (!m_port->IsOpen())
   {
-    CLibCEC::AddLog(CEC_LOG_DEBUG, "error writing command '%s' to the serial port: the connection is closed", CCECAdapterMessage::ToString(message->Message()));
+    CLibCEC::AddLog(CEC_LOG_DEBUG, "error writing command '%s' to serial port '%s': the connection is closed", CCECAdapterMessage::ToString(message->Message()), m_port->GetName().c_str());
     message->state = ADAPTER_MESSAGE_STATE_ERROR;
     return false;
   }
@@ -306,8 +313,9 @@ bool CUSBCECAdapterCommunication::WriteToDevice(CCECAdapterMessage *message)
   /* write the message */
   if (m_port->Write(message->packet.data, message->Size()) != (ssize_t) message->Size())
   {
-    CLibCEC::AddLog(CEC_LOG_DEBUG, "error writing command '%s' to the serial port: %s", CCECAdapterMessage::ToString(message->Message()), m_port->GetError().c_str());
+    CLibCEC::AddLog(CEC_LOG_DEBUG, "error writing command '%s' to serial port '%s': %s", CCECAdapterMessage::ToString(message->Message()), m_port->GetName().c_str(), m_port->GetError().c_str());
     message->state = ADAPTER_MESSAGE_STATE_ERROR;
+    Close();
     return false;
   }
 
@@ -326,17 +334,21 @@ bool CUSBCECAdapterCommunication::ReadFromDevice(uint32_t iTimeout, size_t iSize
   /* read from the serial port */
   {
     CLockObject lock(m_mutex);
-    if (!m_port)
+    if (!m_port || !m_port->IsOpen())
       return false;
+
     iBytesRead = m_port->Read(buff, sizeof(uint8_t) * iSize, iTimeout);
+
+    if (m_port->GetErrorNumber())
+    {
+      CLibCEC::AddLog(CEC_LOG_ERROR, "error reading from serial port: %s", m_port->GetError().c_str());
+      m_port->Close();
+      return false;
+    }
   }
 
   if (iBytesRead < 0 || iBytesRead > 256)
-  {
-    CLibCEC::AddLog(CEC_LOG_ERROR, "error reading from serial port: %s", m_port->GetError().c_str());
-    StopThread(false);
     return false;
-  }
   else if (iBytesRead > 0)
   {
     /* add the data to the current frame */
@@ -362,12 +374,14 @@ CCECAdapterMessage *CUSBCECAdapterCommunication::SendCommand(cec_adapter_message
   /* write the command */
   if (!m_adapterMessageQueue->Write(output))
   {
-    // timed out
+    if (output->state == ADAPTER_MESSAGE_STATE_ERROR)
+      Close();
     return output;
   }
   else
   {
-    if (!bIsRetry && output->Reply() == MSGCODE_COMMAND_REJECTED && msgCode != MSGCODE_SET_CONTROLLED)
+    if (!bIsRetry && output->Reply() == MSGCODE_COMMAND_REJECTED && msgCode != MSGCODE_SET_CONTROLLED &&
+        msgCode != MSGCODE_GET_BUILDDATE /* same messagecode value had a different meaning in older fw builds */)
     {
       /* if the controller reported that the command was rejected, and we didn't send the command
          to set controlled mode, then the controller probably switched to auto mode. set controlled
@@ -382,7 +396,7 @@ CCECAdapterMessage *CUSBCECAdapterCommunication::SendCommand(cec_adapter_message
   return output;
 }
 
-bool CUSBCECAdapterCommunication::CheckAdapter(uint32_t iTimeoutMs /* = 10000 */)
+bool CUSBCECAdapterCommunication::CheckAdapter(uint32_t iTimeoutMs /* = CEC_DEFAULT_CONNECT_TIMEOUT */)
 {
   bool bReturn(false);
   CTimeout timeout(iTimeoutMs > 0 ? iTimeoutMs : CEC_DEFAULT_TRANSMIT_WAIT);
@@ -412,6 +426,9 @@ bool CUSBCECAdapterCommunication::CheckAdapter(uint32_t iTimeoutMs /* = 10000 */
   else
     bReturn = true;
 
+  /* try to read the build date */
+  m_commands->RequestBuildDate();
+
   SetInitialised(bReturn);
   return bReturn;
 }
@@ -441,20 +458,22 @@ bool CUSBCECAdapterCommunication::IsInitialised(void)
 
 bool CUSBCECAdapterCommunication::StartBootloader(void)
 {
-  if (!IsRunning())
-    return false;
-
-  return m_commands->StartBootloader();
+  if (m_port->IsOpen() && m_commands->StartBootloader())
+  {
+    Close();
+    return true;
+  }
+  return false;
 }
 
 bool CUSBCECAdapterCommunication::SetAckMask(uint16_t iMask)
 {
-  return m_commands->SetAckMask(iMask);
+  return m_port->IsOpen() ? m_commands->SetAckMask(iMask) : false;
 }
 
 bool CUSBCECAdapterCommunication::PingAdapter(void)
 {
-  return m_commands->PingAdapter();
+  return m_port->IsOpen() ? m_commands->PingAdapter() : false;
 }
 
 uint16_t CUSBCECAdapterCommunication::GetFirmwareVersion(void)
@@ -462,14 +481,19 @@ uint16_t CUSBCECAdapterCommunication::GetFirmwareVersion(void)
   return m_commands->GetFirmwareVersion();
 }
 
+uint32_t CUSBCECAdapterCommunication::GetFirmwareBuildDate(void)
+{
+  return m_commands->RequestBuildDate();
+}
+
 bool CUSBCECAdapterCommunication::PersistConfiguration(libcec_configuration *configuration)
 {
-  return m_commands->PersistConfiguration(configuration);
+  return m_port->IsOpen() ? m_commands->PersistConfiguration(configuration) : false;
 }
 
 bool CUSBCECAdapterCommunication::GetConfiguration(libcec_configuration *configuration)
 {
-  return m_commands->GetConfiguration(configuration);
+  return m_port->IsOpen() ? m_commands->GetConfiguration(configuration) : false;
 }
 
 CStdString CUSBCECAdapterCommunication::GetPortName(void)
@@ -479,7 +503,7 @@ CStdString CUSBCECAdapterCommunication::GetPortName(void)
 
 bool CUSBCECAdapterCommunication::SetControlledMode(bool controlled)
 {
-  return m_commands->SetControlledMode(controlled);
+  return m_port->IsOpen() ? m_commands->SetControlledMode(controlled) : false;
 }
 
 void *CAdapterPingThread::Process(void)
@@ -498,8 +522,8 @@ void *CAdapterPingThread::Process(void)
       {
         if (!m_com->PingAdapter())
         {
-          /* sleep 1 second and retry */
-          Sleep(1000);
+          /* sleep and retry */
+          Sleep(CEC_DEFAULT_TRANSMIT_RETRY_WAIT);
           ++iFailedCounter;
         }
         else
index 9d125a7b1080fd1de958f5827d8cd8bb4e2ab39b..a1171588bdd0777b9f1523b5acaf2f1c64c79178 100644 (file)
@@ -61,21 +61,22 @@ namespace CEC
      * @param strPort The name of the com port to use.
      * @param iBaudRate The baudrate to use on the com port connection.
      */
-    CUSBCECAdapterCommunication(IAdapterCommunicationCallback *callback, const char *strPort, uint16_t iBaudRate = 38400);
+    CUSBCECAdapterCommunication(IAdapterCommunicationCallback *callback, const char *strPort, uint16_t iBaudRate = CEC_SERIAL_DEFAULT_BAUDRATE);
     virtual ~CUSBCECAdapterCommunication(void);
 
     /** @name IAdapterCommunication implementation */
     ///{
-    bool Open(uint32_t iTimeoutMs = 10000, bool bSkipChecks = false, bool bStartListening = true);
+    bool Open(uint32_t iTimeoutMs = CEC_DEFAULT_CONNECT_TIMEOUT, bool bSkipChecks = false, bool bStartListening = true);
     void Close(void);
     bool IsOpen(void);
     CStdString GetError(void) const;
-    cec_adapter_message_state Write(const cec_command &data, uint8_t iMaxTries, uint8_t iLineTimeout = 3, uint8_t iRetryLineTimeout = 3);
+    cec_adapter_message_state Write(const cec_command &data, bool &bRetry, uint8_t iLineTimeout = 3);
 
     bool StartBootloader(void);
     bool SetAckMask(uint16_t iMask);
     bool PingAdapter(void);
     uint16_t GetFirmwareVersion(void);
+    uint32_t GetFirmwareBuildDate(void);
     bool PersistConfiguration(libcec_configuration *configuration);
     bool GetConfiguration(libcec_configuration *configuration);
     CStdString GetPortName(void);
@@ -90,7 +91,7 @@ namespace CEC
      * @brief Clear all input bytes.
      * @param iTimeout Timeout when anything was received.
      */
-    void ClearInputBytes(uint32_t iTimeout = 1000);
+    void ClearInputBytes(uint32_t iTimeout = CEC_CLEAR_INPUT_DEFAULT_WAIT);
 
     /*!
      * @brief Change the current CEC line timeout.
@@ -124,7 +125,7 @@ namespace CEC
      * @param iTimeoutMs The timeout after which this fails if no proper data was received.
      * @return True when the checks passed, false otherwise.
      */
-    bool CheckAdapter(uint32_t iTimeoutMs = 10000);
+    bool CheckAdapter(uint32_t iTimeoutMs = CEC_DEFAULT_CONNECT_TIMEOUT);
 
     /*!
      * @brief Handle a poll message inside the adapter message (checks if one is present).
index c23c21b24b91c016d5852b2c92a383af77597e67..aef61b2b924f0652129de7b7688f6a62f404d393 100644 (file)
@@ -41,7 +41,7 @@ CCECAdapterMessage::CCECAdapterMessage(void)
   Clear();
 }
 
-CCECAdapterMessage::CCECAdapterMessage(const cec_command &command, uint8_t iMaxTries /* = 1 */, uint8_t iLineTimeout /* = 3 */, uint8_t iRetryLineTimeout /* = 3 */)
+CCECAdapterMessage::CCECAdapterMessage(const cec_command &command, uint8_t iLineTimeout /* = 3 */)
 {
   Clear();
 
@@ -88,15 +88,7 @@ CCECAdapterMessage::CCECAdapterMessage(const cec_command &command, uint8_t iMaxT
   // set timeout
   transmit_timeout = command.transmit_timeout;
 
-  /* set the number of retries */
-  if (command.opcode == CEC_OPCODE_NONE) //TODO
-    maxTries = 1;
-  else if (command.initiator != CECDEVICE_BROADCAST)
-    maxTries = iMaxTries;
-
   lineTimeout = iLineTimeout;
-  retryTimeout = iRetryLineTimeout;
-  tries = 0;
 }
 
 CStdString CCECAdapterMessage::ToString(void) const
@@ -131,6 +123,9 @@ CStdString CCECAdapterMessage::ToString(void) const
         strMsg.AppendFormat(" %02x %s", At(2), IsEOM() ? "eom" : "");
       break;
     default:
+      for (uint8_t iPtr = 2; iPtr < Size(); iPtr++)
+        if (At(iPtr) != MSGEND)
+          strMsg.AppendFormat(" %02x", At(iPtr));
       break;
     }
   }
@@ -192,8 +187,8 @@ const char *CCECAdapterMessage::ToString(cec_adapter_messagecode msgCode)
     return "FRAME_EOM";
   case MSGCODE_FRAME_ACK:
     return "FRAME_ACK";
-  case MSGCODE_SET_POWERSTATE:
-    return "SET_POWERSTATE";
+  case MSGCODE_GET_BUILDDATE:
+    return "GET_BUILDDATE";
   case MSGCODE_SET_CONTROLLED:
     return "SET_CONTROLLED";
   case MSGCODE_GET_AUTO_ENABLED:
@@ -226,6 +221,8 @@ const char *CCECAdapterMessage::ToString(cec_adapter_messagecode msgCode)
     return "SET_OSD_NAME";
   case MSGCODE_WRITE_EEPROM:
     return "WRITE_EEPROM";
+  default:
+    break;
   }
 
   return "unknown";
@@ -257,10 +254,7 @@ void CCECAdapterMessage::Clear(void)
   transmit_timeout    = CEC_DEFAULT_TRANSMIT_TIMEOUT;
   response.Clear();
   packet.Clear();
-  maxTries            = CEC_DEFAULT_TRANSMIT_RETRIES + 1;
-  tries               = 0;
   lineTimeout         = 3;
-  retryTimeout        = 3;
   bNextByteIsEscaped  = false;
 }
 
index 2b122602d79b4b13e7716924f0096b57b3e03953..4d571b10431dc3a4a295a4aa6d4c62fd18cc6760 100644 (file)
@@ -60,11 +60,9 @@ namespace CEC
     /*!
      * @brief Create a message with a command that is to be transmitted over the CEC line.
      * @param command The command to transmit.
-     * @param iMaxTries The maximum number of tries.
-     * @param iLineTimeout The line timeout to use when sending this message the first time.
-     * @param iRetryLineTimeout The line timeout to use when retrying to send this message.
+     * @param iLineTimeout The line timeout to use when sending this message.
      */
-    CCECAdapterMessage(const cec_command &command, uint8_t iMaxTries = 1, uint8_t iLineTimeout = 3, uint8_t iRetryLineTimeout = 3);
+    CCECAdapterMessage(const cec_command &command, uint8_t iLineTimeout = 3);
 
     /*!
      * @return the message as human readable string.
@@ -196,13 +194,11 @@ namespace CEC
     cec_adapter_messagecode Reply(void) const;
 
     uint8_t                               maxTries;             /**< the maximum number of times to try to send this message */
-    uint8_t                               tries;                /**< the amount of times this message has been sent */
     cec_datapacket                        response;             /**< the response to this message */
     cec_datapacket                        packet;               /**< the actual data */
     cec_adapter_message_state             state;                /**< the current state of this message */
     int32_t                               transmit_timeout;     /**< the timeout to use when sending this message */
     uint8_t                               lineTimeout;          /**< the default CEC line timeout to use when sending this message */
-    uint8_t                               retryTimeout;         /**< the CEC line timeout to use when retrying to send this message */
 
   private:
     bool                                  bNextByteIsEscaped;   /**< true when the next byte that is added will be escaped, false otherwise */
index 9c66051f5e368640e27bc128e5185b55839dd77a..a270a78235792a39a81a6fd746088c7155cea175 100644 (file)
@@ -39,6 +39,8 @@ using namespace CEC;
 using namespace PLATFORM;
 using namespace std;
 
+#define MESSAGE_QUEUE_SIGNAL_WAIT_TIME 1000
+
 CCECAdapterMessageQueueEntry::CCECAdapterMessageQueueEntry(CCECAdapterMessage *message) :
     m_message(message),
     m_iPacketsLeft(message->IsTranmission() ? message->Size() / 4 : 1),
@@ -196,7 +198,7 @@ bool CCECAdapterMessageQueueEntry::MessageReceivedResponse(const CCECAdapterMess
 {
   {
     CLockObject lock(m_mutex);
-    CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - received response", ToString());
+    CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - received response - %s", ToString(), message.ToString().c_str());
     m_message->response = message.packet;
     if (m_message->IsTranmission())
       m_message->state = message.Message() == MSGCODE_TRANSMIT_SUCCEEDED ? ADAPTER_MESSAGE_STATE_SENT_ACKED : ADAPTER_MESSAGE_STATE_SENT_NOT_ACKED;
@@ -213,14 +215,42 @@ bool CCECAdapterMessageQueueEntry::MessageReceivedResponse(const CCECAdapterMess
 CCECAdapterMessageQueue::~CCECAdapterMessageQueue(void)
 {
   Clear();
+  StopThread(0);
 }
 
 void CCECAdapterMessageQueue::Clear(void)
 {
+  StopThread(5);
   CLockObject lock(m_mutex);
+  m_writeQueue.Clear();
   m_messages.clear();
 }
 
+void *CCECAdapterMessageQueue::Process(void)
+{
+  CCECAdapterMessageQueueEntry *message(NULL);
+  while (!IsStopped())
+  {
+    /* wait for a new message */
+    if (m_writeQueue.Pop(message, MESSAGE_QUEUE_SIGNAL_WAIT_TIME) && message)
+    {
+      /* write this message */
+      {
+        CLockObject lock(m_mutex);
+        m_com->WriteToDevice(message->m_message);
+      }
+      if (message->m_message->state == ADAPTER_MESSAGE_STATE_ERROR ||
+          message->m_message->Message() == MSGCODE_START_BOOTLOADER)
+      {
+        message->Signal();
+        Clear();
+        break;
+      }
+    }
+  }
+  return NULL;
+}
+
 void CCECAdapterMessageQueue::MessageReceived(const CCECAdapterMessage &msg)
 {
   bool bHandled(false);
@@ -279,30 +309,21 @@ bool CCECAdapterMessageQueue::Write(CCECAdapterMessage *msg)
   /* set the correct line timeout */
   if (msg->IsTranmission())
   {
-    if (msg->tries == 1)
-      m_com->SetLineTimeout(msg->lineTimeout);
-    else
-      m_com->SetLineTimeout(msg->retryTimeout);
+    m_com->SetLineTimeout(msg->lineTimeout);
   }
 
-  CCECAdapterMessageQueueEntry *entry(NULL);
+  CCECAdapterMessageQueueEntry *entry = new CCECAdapterMessageQueueEntry(msg);
   uint64_t iEntryId(0);
   /* add to the wait for ack queue */
   if (msg->Message() != MSGCODE_START_BOOTLOADER)
   {
     CLockObject lock(m_mutex);
-    entry = new CCECAdapterMessageQueueEntry(msg);
     iEntryId = m_iNextMessage++;
     m_messages.insert(make_pair(iEntryId, entry));
   }
 
-  /* TODO write the message async */
-  if (!m_com->WriteToDevice(msg))
-  {
-    /* error! */
-    Clear();
-    return false;
-  }
+  /* add the message to the write queue */
+  m_writeQueue.Push(entry);
 
   bool bReturn(true);
   if (entry)
@@ -314,8 +335,12 @@ bool CCECAdapterMessageQueue::Write(CCECAdapterMessage *msg)
       bReturn = false;
     }
 
-    CLockObject lock(m_mutex);
-    m_messages.erase(iEntryId);
+    if (msg->Message() != MSGCODE_START_BOOTLOADER)
+    {
+      CLockObject lock(m_mutex);
+      m_messages.erase(iEntryId);
+    }
+    delete entry;
   }
 
   return bReturn;
index 9c5be4969b0abb084b65eaa09197d89fea880012..e476e26660382a9359d12fc822054d99114e9c10 100644 (file)
@@ -32,6 +32,7 @@
  */
 
 #include "USBCECAdapterMessage.h"
+#include "../platform/threads/threads.h"
 #include <map>
 
 namespace CEC
@@ -85,7 +86,6 @@ namespace CEC
      */
     const char *ToString(void) const;
 
-  private:
     /*!
      * @brief Called when a 'command accepted' message was received.
      * @param message The message that was received.
@@ -120,7 +120,7 @@ namespace CEC
     PLATFORM::CMutex           m_mutex;        /**< mutex for changes to this class */
   };
 
-  class CCECAdapterMessageQueue
+  class CCECAdapterMessageQueue : public PLATFORM::CThread
   {
     friend class CUSBCECAdapterCommunication;
 
@@ -131,6 +131,7 @@ namespace CEC
      * @param iQueueSize The outgoing message queue size.
      */
     CCECAdapterMessageQueue(CUSBCECAdapterCommunication *com) :
+      PLATFORM::CThread(),
       m_com(com),
       m_iNextMessage(0) {}
     virtual ~CCECAdapterMessageQueue(void);
@@ -160,10 +161,13 @@ namespace CEC
      */
     bool Write(CCECAdapterMessage *msg);
 
+    virtual void *Process(void);
+
   private:
     CUSBCECAdapterCommunication *                          m_com;                    /**< the communication handler */
     PLATFORM::CMutex                                       m_mutex;                  /**< mutex for changes to this class */
     std::map<uint64_t, CCECAdapterMessageQueueEntry *>     m_messages;               /**< the outgoing message queue */
+    PLATFORM::SyncedBuffer<CCECAdapterMessageQueueEntry *> m_writeQueue;             /**< the queue for messages that are to be written */
     uint64_t                                               m_iNextMessage;           /**< the index of the next message */
     CCECAdapterMessage                                     m_incomingAdapterMessage; /**< the current incoming message that's being assembled */
     cec_command                                            m_currentCECFrame;        /**< the current incoming CEC command that's being assembled */
index 6d1d94827a50972c02f1c45c380952d6ab099dea..7e33597a7a974b0dbd0b778465a97540033f4f7d 100644 (file)
@@ -40,7 +40,7 @@ using namespace PLATFORM;
 
 #define ToString(p) m_processor->ToString(p)
 
-CCECAudioSystem::CCECAudioSystem(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress /* = 0 */) :
+CCECAudioSystem::CCECAudioSystem(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress /* = CEC_INVALID_PHYSICAL_ADDRESS */) :
     CCECBusDevice(processor, address, iPhysicalAddress),
     m_systemAudioStatus(CEC_SYSTEM_AUDIO_STATUS_ON),
     m_audioStatus(CEC_AUDIO_MUTE_STATUS_MASK)
index de2a0cc07d14d8e08bab5b21db2633880ecbb8dd..a340ad88ce8541d302ab1ad1fdb9e6c8554493a8 100644 (file)
@@ -38,20 +38,20 @@ namespace CEC
   class CCECAudioSystem : public CCECBusDevice
   {
   public:
-    CCECAudioSystem(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress = 0);
+    CCECAudioSystem(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress = CEC_INVALID_PHYSICAL_ADDRESS);
     virtual ~CCECAudioSystem(void) {};
 
-    virtual bool SetAudioStatus(uint8_t status);
-    virtual bool SetSystemAudioModeStatus(const cec_system_audio_status mode);
-    virtual bool TransmitAudioStatus(cec_logical_address dest);
-    virtual bool TransmitSetSystemAudioMode(cec_logical_address dest);
-    virtual bool TransmitSystemAudioModeStatus(cec_logical_address dest);
+    bool SetAudioStatus(uint8_t status);
+    bool SetSystemAudioModeStatus(const cec_system_audio_status mode);
+    bool TransmitAudioStatus(cec_logical_address dest);
+    bool TransmitSetSystemAudioMode(cec_logical_address dest);
+    bool TransmitSystemAudioModeStatus(cec_logical_address dest);
 
-    virtual uint8_t VolumeUp(bool bSendRelease = true);
-    virtual uint8_t VolumeDown(bool bSendRelease = true);
-    virtual uint8_t MuteAudio(bool bSendRelease = true);
+    uint8_t VolumeUp(bool bSendRelease = true);
+    uint8_t VolumeDown(bool bSendRelease = true);
+    uint8_t MuteAudio(bool bSendRelease = true);
 
-    virtual bool TransmitActiveSource(void) { return false; }
+    bool TransmitActiveSource(void) { return false; }
 
   protected:
     cec_system_audio_status m_systemAudioStatus;
index cba201b678c86424271236753d5fec67a9ae943c..7e63a67ff8808d6da91a3835a4a590cccd68d65b 100644 (file)
@@ -44,24 +44,24 @@ using namespace PLATFORM;
 
 #define ToString(p) m_processor->ToString(p)
 
-CCECBusDevice::CCECBusDevice(CCECProcessor *processor, cec_logical_address iLogicalAddress, uint16_t iPhysicalAddress) :
-  m_type(CEC_DEVICE_TYPE_RESERVED),
-  m_iPhysicalAddress(iPhysicalAddress),
-  m_iStreamPath(0),
-  m_iLogicalAddress(iLogicalAddress),
-  m_powerStatus(CEC_POWER_STATUS_UNKNOWN),
-  m_processor(processor),
-  m_vendor(CEC_VENDOR_UNKNOWN),
-  m_bReplaceHandler(false),
-  m_menuState(CEC_MENU_STATE_ACTIVATED),
-  m_bActiveSource(false),
-  m_iLastActive(0),
-  m_iLastPowerStateUpdate(0),
-  m_cecVersion(CEC_VERSION_UNKNOWN),
-  m_deviceStatus(CEC_DEVICE_STATUS_UNKNOWN),
-  m_iHandlerUseCount(0),
+CCECBusDevice::CCECBusDevice(CCECProcessor *processor, cec_logical_address iLogicalAddress, uint16_t iPhysicalAddress /* = CEC_INVALID_PHYSICAL_ADDRESS */) :
+  m_type                  (CEC_DEVICE_TYPE_RESERVED),
+  m_iPhysicalAddress      (iPhysicalAddress),
+  m_iStreamPath           (CEC_INVALID_PHYSICAL_ADDRESS),
+  m_iLogicalAddress       (iLogicalAddress),
+  m_powerStatus           (CEC_POWER_STATUS_UNKNOWN),
+  m_processor             (processor),
+  m_vendor                (CEC_VENDOR_UNKNOWN),
+  m_bReplaceHandler       (false),
+  m_menuState             (CEC_MENU_STATE_ACTIVATED),
+  m_bActiveSource         (false),
+  m_iLastActive           (0),
+  m_iLastPowerStateUpdate (0),
+  m_cecVersion            (CEC_VERSION_UNKNOWN),
+  m_deviceStatus          (CEC_DEVICE_STATUS_UNKNOWN),
+  m_iHandlerUseCount      (0),
   m_bAwaitingReceiveFailed(false),
-  m_bVendorIdRequested(false)
+  m_bVendorIdRequested    (false)
 {
   m_handler = new CCECCommandHandler(this);
 
@@ -170,6 +170,21 @@ cec_version CCECBusDevice::GetCecVersion(bool bUpdate /* = false */)
   return m_cecVersion;
 }
 
+bool CCECBusDevice::RequestActiveSource(bool bWaitForResponse /* = true */)
+{
+  bool bReturn(false);
+
+  if (MyLogicalAddressContains(m_iLogicalAddress))
+  {
+    MarkBusy();
+    CLibCEC::AddLog(CEC_LOG_NOTICE, "<< requesting active source");
+
+    bReturn = m_handler->TransmitRequestActiveSource(GetMyLogicalAddress(), bWaitForResponse);
+    MarkReady();
+  }
+  return bReturn;
+}
+
 bool CCECBusDevice::RequestCecVersion(bool bWaitForResponse /* = true */)
 {
   bool bReturn(false);
@@ -278,21 +293,23 @@ bool CCECBusDevice::RequestOSDName(bool bWaitForResponse /* = true */)
   return bReturn;
 }
 
-uint16_t CCECBusDevice::GetPhysicalAddress(bool bUpdate /* = false */, bool bSuppressPoll /* = false */)
+uint16_t CCECBusDevice::GetPhysicalAddress(bool bSuppressUpdate /* = true */)
 {
-  bool bIsPresent(GetStatus(false, bSuppressPoll) == CEC_DEVICE_STATUS_PRESENT);
-  bool bRequestUpdate(false);
+  if (!bSuppressUpdate)
   {
-    CLockObject lock(m_mutex);
-    bRequestUpdate = bIsPresent &&
-      (m_iPhysicalAddress == 0xFFFF || bUpdate);
-  }
+    bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT);
+    bool bRequestUpdate(false);
+    {
+      CLockObject lock(m_mutex);
+      bRequestUpdate = bIsPresent && m_iPhysicalAddress == CEC_INVALID_PHYSICAL_ADDRESS;
+    }
 
-  if (bRequestUpdate)
-  {
-    CheckVendorIdRequested();
-    if (!RequestPhysicalAddress())
-      CLibCEC::AddLog(CEC_LOG_ERROR, "failed to request the physical address");
+    if (bRequestUpdate)
+    {
+      CheckVendorIdRequested();
+      if (!RequestPhysicalAddress())
+        CLibCEC::AddLog(CEC_LOG_ERROR, "failed to request the physical address");
+    }
   }
 
   CLockObject lock(m_mutex);
@@ -487,14 +504,16 @@ cec_bus_device_status CCECBusDevice::GetStatus(bool bForcePoll /* = false */, bo
 //@{
 void CCECBusDevice::SetCecVersion(const cec_version newVersion)
 {
+  if (m_cecVersion != newVersion)
+    CLibCEC::AddLog(CEC_LOG_DEBUG, "%s (%X): CEC version %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(newVersion));
   m_cecVersion = newVersion;
-  CLibCEC::AddLog(CEC_LOG_DEBUG, "%s (%X): CEC version %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(newVersion));
 }
 
 void CCECBusDevice::SetMenuLanguage(const cec_menu_language &language)
 {
   CLockObject lock(m_mutex);
-  if (language.device == m_iLogicalAddress)
+  if (language.device == m_iLogicalAddress &&
+      strcmp(language.language, m_menuLanguage.language))
   {
     CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %s (%X): menu language set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, language.language);
     m_menuLanguage = language;
@@ -529,9 +548,6 @@ void CCECBusDevice::SetInactiveSource(void)
       CLibCEC::AddLog(CEC_LOG_DEBUG, "marking %s (%X) as inactive source", GetLogicalAddressName(), m_iLogicalAddress);
     m_bActiveSource = false;
   }
-
-  if (MyLogicalAddressContains(m_iLogicalAddress))
-    SetPowerStatus(CEC_POWER_STATUS_STANDBY);
 }
 
 void CCECBusDevice::SetActiveSource(void)
@@ -539,6 +555,8 @@ void CCECBusDevice::SetActiveSource(void)
   CLockObject lock(m_mutex);
   if (!m_bActiveSource)
     CLibCEC::AddLog(CEC_LOG_DEBUG, "making %s (%x) the active source", GetLogicalAddressName(), m_iLogicalAddress);
+  else
+    CLibCEC::AddLog(CEC_LOG_DEBUG, "%s (%x) was already marked as active source", GetLogicalAddressName(), m_iLogicalAddress);
 
   for (int iPtr = 0; iPtr < 16; iPtr++)
     if (iPtr != m_iLogicalAddress)
@@ -566,6 +584,20 @@ bool CCECBusDevice::TryLogicalAddress(void)
   return false;
 }
 
+void CCECBusDevice::ResetDeviceStatus(void)
+{
+  CLockObject lock(m_mutex);
+  SetPowerStatus   (CEC_POWER_STATUS_UNKNOWN);
+  SetVendorId      (CEC_VENDOR_UNKNOWN);
+  SetMenuState     (CEC_MENU_STATE_ACTIVATED);
+  SetCecVersion    (CEC_VERSION_UNKNOWN);
+  SetStreamPath    (CEC_INVALID_PHYSICAL_ADDRESS);
+  SetOSDName       (ToString(m_iLogicalAddress));
+  SetInactiveSource();
+  m_iLastActive = 0;
+  m_unsupportedFeatures.clear();
+}
+
 void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus)
 {
   {
@@ -575,26 +607,20 @@ void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus)
     case CEC_DEVICE_STATUS_UNKNOWN:
       if (m_deviceStatus != newStatus)
         CLibCEC::AddLog(CEC_LOG_DEBUG, "device status of %s changed into 'unknown'", ToString(m_iLogicalAddress));
-      m_iStreamPath      = 0;
-      m_powerStatus      = CEC_POWER_STATUS_UNKNOWN;
-      m_vendor           = CEC_VENDOR_UNKNOWN;
-      m_menuState        = CEC_MENU_STATE_ACTIVATED;
-      m_bActiveSource    = false;
-      m_iLastActive      = 0;
-      m_cecVersion       = CEC_VERSION_UNKNOWN;
-      m_deviceStatus     = newStatus;
+      ResetDeviceStatus();
+      m_deviceStatus = newStatus;
       break;
     case CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC:
       if (m_deviceStatus != newStatus)
         CLibCEC::AddLog(CEC_LOG_DEBUG, "device status of %s changed into 'handled by libCEC'", ToString(m_iLogicalAddress));
-      m_iStreamPath      = 0;
-      m_powerStatus      = CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON;
-      m_vendor           = CEC_VENDOR_UNKNOWN;
-      m_menuState        = CEC_MENU_STATE_ACTIVATED;
-      m_bActiveSource    = false;
-      m_iLastActive      = 0;
-      m_cecVersion       = CEC_VERSION_1_3A;
-      m_deviceStatus     = newStatus;
+      SetPowerStatus   (CEC_POWER_STATUS_ON);
+      SetVendorId      (CEC_VENDOR_UNKNOWN);
+      SetMenuState     (CEC_MENU_STATE_ACTIVATED);
+      SetCecVersion    (CEC_VERSION_1_3A);
+      SetStreamPath    (CEC_INVALID_PHYSICAL_ADDRESS);
+      SetInactiveSource();
+      m_iLastActive   = 0;
+      m_deviceStatus  = newStatus;
       break;
     case CEC_DEVICE_STATUS_PRESENT:
       if (m_deviceStatus != newStatus)
@@ -603,8 +629,11 @@ void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus)
       break;
     case CEC_DEVICE_STATUS_NOT_PRESENT:
       if (m_deviceStatus != newStatus)
+      {
         CLibCEC::AddLog(CEC_LOG_DEBUG, "device status of %s changed into 'not present'", ToString(m_iLogicalAddress));
-      m_deviceStatus = newStatus;
+        ResetDeviceStatus();
+        m_deviceStatus = newStatus;
+      }
       break;
     }
   }
@@ -623,34 +652,27 @@ void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress)
   }
 }
 
-void CCECBusDevice::SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress /* = 0 */)
+void CCECBusDevice::SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress /* = CEC_INVALID_PHYSICAL_ADDRESS */)
 {
   CLockObject lock(m_mutex);
-  if (iNewAddress > 0)
+  if (iNewAddress != m_iStreamPath)
   {
     CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %s (%X): stream path changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress, iOldAddress == 0 ? m_iStreamPath : iOldAddress, iNewAddress);
     m_iStreamPath = iNewAddress;
+  }
 
-    // suppress polls when searching for a device
-    CCECBusDevice *device = m_processor->GetDeviceByPhysicalAddress(iNewAddress, false, true);
+  CCECBusDevice *device = m_processor->GetDeviceByPhysicalAddress(iNewAddress);
+  if (device)
+  {
+    // if a device is found with the new physical address, mark it as active, which will automatically mark all other devices as inactive
+    device->SetActiveSource();
+  }
+  else
+  {
+    // try to find the device with the old address, and mark it as inactive when found
+    device = m_processor->GetDeviceByPhysicalAddress(iOldAddress);
     if (device)
-    {
-      // if a device is found with the new physical address, mark it as active, which will automatically mark all other devices as inactive
-      device->SetActiveSource();
-    }
-    else
-    {
-      // try to find the device with the old address, and mark it as inactive when found
-      device = m_processor->GetDeviceByPhysicalAddress(iOldAddress, false, true);
-      if (device)
-        device->SetInactiveSource();
-    }
-
-    if (iNewAddress > 0)
-    {
-      lock.Unlock();
-      SetPowerStatus(CEC_POWER_STATUS_ON);
-    }
+      device->SetInactiveSource();
   }
 }
 
@@ -744,7 +766,8 @@ bool CCECBusDevice::SetVendorId(uint64_t iVendorId)
     m_vendor = (cec_vendor_id)iVendorId;
   }
 
-  CLibCEC::AddLog(CEC_LOG_DEBUG, "%s (%X): vendor = %s (%06x)", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_vendor), m_vendor);
+  if (bVendorChanged)
+    CLibCEC::AddLog(CEC_LOG_DEBUG, "%s (%X): vendor = %s (%06x)", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_vendor), m_vendor);
 
   return bVendorChanged;
 }
@@ -876,7 +899,7 @@ bool CCECBusDevice::TransmitPhysicalAddress(void)
   cec_device_type type;
   {
     CLockObject lock(m_mutex);
-    if (m_iPhysicalAddress == 0xffff)
+    if (m_iPhysicalAddress == CEC_INVALID_PHYSICAL_ADDRESS)
       return false;
 
     CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> broadcast (F): physical adddress %4x", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress);
@@ -952,12 +975,6 @@ bool CCECBusDevice::TransmitPowerState(cec_logical_address dest)
   cec_power_status state;
   {
     CLockObject lock(m_mutex);
-    if (!IsActiveSource())
-    {
-      CLibCEC::AddLog(CEC_LOG_NOTICE, "power state requested of %s (%X), but we are not the active source. setting power state to standby", GetLogicalAddressName(), m_iLogicalAddress);
-      SetPowerStatus(CEC_POWER_STATUS_STANDBY);
-    }
-
     CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_powerStatus));
     state = m_powerStatus;
   }
@@ -1012,22 +1029,45 @@ bool CCECBusDevice::TransmitKeyRelease(bool bWait /* = true */)
   return bReturn;
 }
 
-bool CCECBusDevice::IsUnsupportedFeature(cec_opcode opcode) const
+bool CCECBusDevice::IsUnsupportedFeature(cec_opcode opcode)
 {
+  CLockObject lock(m_mutex);
   bool bUnsupported = (m_unsupportedFeatures.find(opcode) != m_unsupportedFeatures.end());
   if (bUnsupported)
-    CLibCEC::AddLog(CEC_LOG_NOTICE, "'%s' is marked as unsupported feature for device '%s'", ToString(opcode), GetLogicalAddressName());
+    CLibCEC::AddLog(CEC_LOG_DEBUG, "'%s' is marked as unsupported feature for device '%s'", ToString(opcode), GetLogicalAddressName());
   return bUnsupported;
 }
 
 void CCECBusDevice::SetUnsupportedFeature(cec_opcode opcode)
 {
-  CLibCEC::AddLog(CEC_LOG_DEBUG, "marking opcode '%s' as unsupported feature for device '%s'", ToString(opcode), GetLogicalAddressName());
-  m_unsupportedFeatures.insert(opcode);
+  // some commands should never be marked as unsupported
+  if (opcode == CEC_OPCODE_VENDOR_COMMAND ||
+      opcode == CEC_OPCODE_VENDOR_COMMAND_WITH_ID ||
+      opcode == CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN ||
+      opcode == CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP ||
+      opcode == CEC_OPCODE_ABORT ||
+      opcode == CEC_OPCODE_FEATURE_ABORT ||
+      opcode == CEC_OPCODE_NONE)
+    return;
+
+  {
+    CLockObject lock(m_mutex);
+    if (m_unsupportedFeatures.find(opcode) == m_unsupportedFeatures.end())
+    {
+      CLibCEC::AddLog(CEC_LOG_DEBUG, "marking opcode '%s' as unsupported feature for device '%s'", ToString(opcode), GetLogicalAddressName());
+      m_unsupportedFeatures.insert(opcode);
+    }
+  }
+
+  // signal threads that are waiting for a reponse
+  MarkBusy();
+  m_handler->SignalOpcode(cec_command::GetResponseOpcode(opcode));
+  MarkReady();
 }
 
 bool CCECBusDevice::ActivateSource(void)
 {
+  CLibCEC::AddLog(CEC_LOG_DEBUG, "activating source '%s'", ToString(m_iLogicalAddress));
   MarkBusy();
   bool bReturn = m_handler->ActivateSource();
   MarkReady();
@@ -1073,4 +1113,12 @@ void CCECBusDevice::CheckVendorIdRequested(void)
   }
 }
 
+bool CCECBusDevice::TransmitPendingActiveSourceCommands(void)
+{
+  MarkBusy();
+  bool bReturn = m_handler->TransmitPendingActiveSourceCommands();
+  MarkReady();
+  return bReturn;
+}
+
 //@}
index 2bd97302f1e047fbc9a2060c0284b768291acb24..95b1bad34155c40b07d10420fc834d4d8cafea3b 100644 (file)
@@ -46,7 +46,7 @@ namespace CEC
     friend class CCECProcessor;
 
   public:
-    CCECBusDevice(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress = 0);
+    CCECBusDevice(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress = CEC_INVALID_PHYSICAL_ADDRESS);
     virtual ~CCECBusDevice(void);
 
     virtual bool HandleCommand(const cec_command &command);
@@ -63,7 +63,7 @@ namespace CEC
     virtual cec_logical_address   GetMyLogicalAddress(void) const;
     virtual uint16_t              GetMyPhysicalAddress(void) const;
     virtual CStdString            GetOSDName(bool bUpdate = false);
-    virtual uint16_t              GetPhysicalAddress(bool bUpdate = false, bool bSuppressPoll = false);
+    virtual uint16_t              GetPhysicalAddress(bool bSuppressUpdate = true);
     virtual cec_power_status      GetPowerStatus(bool bUpdate = false);
     virtual CCECProcessor *       GetProcessor(void) const { return m_processor; }
     virtual cec_device_type       GetType(void) const { return m_type; }
@@ -72,7 +72,7 @@ namespace CEC
     virtual bool                  MyLogicalAddressContains(cec_logical_address address) const;
     virtual cec_bus_device_status GetStatus(bool bForcePoll = false, bool bSuppressPoll = false);
     virtual bool                  IsActiveSource(void) const { return m_bActiveSource; }
-    virtual bool                  IsUnsupportedFeature(cec_opcode opcode) const;
+    virtual bool                  IsUnsupportedFeature(cec_opcode opcode);
     virtual void                  SetUnsupportedFeature(cec_opcode opcode);
     virtual void                  HandlePoll(cec_logical_address destination);
     virtual void                  HandlePollFrom(cec_logical_address initiator);
@@ -85,7 +85,7 @@ namespace CEC
 
     virtual void SetDeviceStatus(const cec_bus_device_status newStatus);
     virtual void SetPhysicalAddress(uint16_t iNewAddress);
-    virtual void SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress = 0);
+    virtual void SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress = CEC_INVALID_PHYSICAL_ADDRESS);
     virtual void SetCecVersion(const cec_version newVersion);
     virtual void SetMenuLanguage(const cec_menu_language &menuLanguage);
     virtual void SetOSDName(CStdString strName);
@@ -109,8 +109,12 @@ namespace CEC
     virtual bool TransmitKeyRelease(bool bWait = true);
 
     bool ReplaceHandler(bool bActivateSource = true);
+    virtual bool TransmitPendingActiveSourceCommands(void);
+
+    virtual bool RequestActiveSource(bool bWaitForResponse = true);
 
   protected:
+    void ResetDeviceStatus(void);
     void CheckVendorIdRequested(void);
     void MarkBusy(void);
     void MarkReady(void);
index 3e255bf553d81db931fd4152c2f820f44cd5b261..522b88f49a572d3042794e1be1e4ac3b452bb2a7 100644 (file)
@@ -40,7 +40,7 @@ using namespace PLATFORM;
 
 #define ToString(p) m_processor->ToString(p)
 
-CCECPlaybackDevice::CCECPlaybackDevice(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress /* = 0 */) :
+CCECPlaybackDevice::CCECPlaybackDevice(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress /* = CEC_INVALID_PHYSICAL_ADDRESS */) :
     CCECBusDevice(processor, address, iPhysicalAddress),
     m_deckStatus(CEC_DECK_INFO_STOP),
     m_deckControlMode(CEC_DECK_CONTROL_MODE_STOP)
index c6f26ec152b524662797654495dbce3eca817d5d..414f8478517562b71366d592fdc5f60222827aaf 100644 (file)
@@ -38,16 +38,16 @@ namespace CEC
   class CCECPlaybackDevice : public CCECBusDevice
   {
   public:
-    CCECPlaybackDevice(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress = 0);
+    CCECPlaybackDevice(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress = CEC_INVALID_PHYSICAL_ADDRESS);
     virtual ~CCECPlaybackDevice(void) {};
 
-    virtual cec_deck_info GetDeckStatus(void);
-    virtual cec_deck_control_mode GetDeckControlMode(void);
+    cec_deck_info GetDeckStatus(void);
+    cec_deck_control_mode GetDeckControlMode(void);
 
-    virtual void SetDeckStatus(cec_deck_info deckStatus);
-    virtual void SetDeckControlMode(cec_deck_control_mode mode);
+    void SetDeckStatus(cec_deck_info deckStatus);
+    void SetDeckControlMode(cec_deck_control_mode mode);
 
-    virtual bool TransmitDeckStatus(cec_logical_address dest);
+    bool TransmitDeckStatus(cec_logical_address dest);
 
   protected:
     cec_deck_info         m_deckStatus;
index 5639bc8dc920d29c057b46b3f541d039b60b908b..c5f4535af4254b7b83028e63b011c5138bb5b154 100644 (file)
@@ -34,7 +34,7 @@
 
 using namespace CEC;
 
-CCECRecordingDevice::CCECRecordingDevice(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress /* = 0 */) :
+CCECRecordingDevice::CCECRecordingDevice(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress /* = CEC_INVALID_PHYSICAL_ADDRESS */) :
     CCECBusDevice(processor, address, iPhysicalAddress),
     m_playbackDevice(processor, address, iPhysicalAddress),
     m_tuner(processor, address, iPhysicalAddress)
index d453e9c22218c4b08539ad0fa5a375f6fada146e..f64b95b357a88683691fc6a9dcaf8004effa4a5d 100644 (file)
@@ -40,17 +40,17 @@ namespace CEC
   class CCECRecordingDevice : public CCECBusDevice
   {
   public:
-    CCECRecordingDevice(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress = 0);
+    CCECRecordingDevice(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress = CEC_INVALID_PHYSICAL_ADDRESS);
     virtual ~CCECRecordingDevice(void) {};
 
     /* playback device methods */
-    virtual cec_deck_info GetDeckStatus(void);
-    virtual cec_deck_control_mode GetDeckControlMode(void);
+    cec_deck_info GetDeckStatus(void);
+    cec_deck_control_mode GetDeckControlMode(void);
 
-    virtual void SetDeckStatus(cec_deck_info deckStatus);
-    virtual void SetDeckControlMode(cec_deck_control_mode mode);
+    void SetDeckStatus(cec_deck_info deckStatus);
+    void SetDeckControlMode(cec_deck_control_mode mode);
 
-    virtual bool TransmitDeckStatus(cec_logical_address dest);
+    bool TransmitDeckStatus(cec_logical_address dest);
 
     /* tuner methods */
     //TODO
index 27df9b600869b9b53294824c626bb61fb3f2fed1..5c2e909f26296ed7f8972c02e43e6640480afc08 100644 (file)
@@ -34,8 +34,8 @@
 
 using namespace CEC;
 
-CCECTV::CCECTV(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress /* = 0 */) :
-    CCECBusDevice(processor, address, iPhysicalAddress)
+CCECTV::CCECTV(CCECProcessor *processor, cec_logical_address address) :
+    CCECBusDevice(processor, address, CEC_PHYSICAL_ADDRESS_TV)
 {
-  m_type          = CEC_DEVICE_TYPE_TV;
+  m_type = CEC_DEVICE_TYPE_TV;
 }
index a90169e43f165baba663133d25f173177ca410f1..e712e96b8818f9eedf1b3d6cf03705dfe7df254a 100644 (file)
@@ -38,7 +38,7 @@ namespace CEC
   class CCECTV : public CCECBusDevice
   {
   public:
-    CCECTV(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress = 0);
+    CCECTV(CCECProcessor *processor, cec_logical_address address);
     virtual ~CCECTV(void) {};
   };
 }
index b5de867d9e8a968fe4aeb644ce572ac5ca2330c5..feb35e4b5bd92834c3099efcbac1b92ee7637409 100644 (file)
@@ -34,7 +34,7 @@
 
 using namespace CEC;
 
-CCECTuner::CCECTuner(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress /* = 0 */) :
+CCECTuner::CCECTuner(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress /* = CEC_INVALID_PHYSICAL_ADDRESS */) :
     CCECBusDevice(processor, address, iPhysicalAddress)
 {
   m_type          = CEC_DEVICE_TYPE_TUNER;
index 2cf2ed2f6cbae0774782707483811ea1ee3b24fa..ad65efdf65ae729a0740ac7b4eeecdc9435d7976 100644 (file)
@@ -38,7 +38,7 @@ namespace CEC
   class CCECTuner : public CCECBusDevice
   {
   public:
-    CCECTuner(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress = 0);
+    CCECTuner(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress = CEC_INVALID_PHYSICAL_ADDRESS);
     virtual ~CCECTuner(void) {};
   };
 }
index d9437d13a1e6529c364bf5f932e05bc32cfc44bd..567684fa7cf78e4bcd99edf95a1be9611f0783cb 100644 (file)
@@ -41,9 +41,10 @@ namespace CEC
     CANCommandHandler(CCECBusDevice *busDevice);
     virtual ~CANCommandHandler(void) {};
 
-    virtual bool HandleCommand(const cec_command &command);
+    bool HandleCommand(const cec_command &command);
+
   protected:
-    virtual bool HandleVendorRemoteButtonDown(const cec_command &command);
-    virtual bool PowerOn(const cec_logical_address iInitiator, const cec_logical_address iDestination);
+    bool HandleVendorRemoteButtonDown(const cec_command &command);
+    bool PowerOn(const cec_logical_address iInitiator, const cec_logical_address iDestination);
   };
 };
index eed60878d8231244346e80756ef45f39081f9d5d..449c589e27154805350ab8dee9cbb06204bd2f40 100644 (file)
@@ -334,12 +334,7 @@ bool CCECCommandHandler::HandleGivePhysicalAddress(const cec_command &command)
   {
     CCECBusDevice *device = GetDevice(command.destination);
     if (device)
-    {
-      device->SetActiveSource();
-      return device->TransmitPhysicalAddress() &&
-          device->TransmitImageViewOn() &&
-          device->TransmitActiveSource();
-    }
+      return device->TransmitPhysicalAddress();
   }
 
   return false;
@@ -379,11 +374,20 @@ bool CCECCommandHandler::HandleMenuRequest(const cec_command &command)
 {
   if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination))
   {
-    if (command.parameters[0] == CEC_MENU_REQUEST_TYPE_QUERY)
+    CCECBusDevice *device = GetDevice(command.destination);
+    if (device)
     {
-      CCECBusDevice *device = GetDevice(command.destination);
-      if (device)
-        return device->TransmitMenuState(command.initiator);
+      if (command.parameters[0] == CEC_MENU_REQUEST_TYPE_ACTIVATE)
+      {
+        if (CLibCEC::MenuStateChanged(CEC_MENU_STATE_ACTIVATED) == 1)
+          device->SetMenuState(CEC_MENU_STATE_ACTIVATED);
+      }
+      else if (command.parameters[0] == CEC_MENU_REQUEST_TYPE_DEACTIVATE)
+      {
+        if (CLibCEC::MenuStateChanged(CEC_MENU_STATE_DEACTIVATED) == 1)
+          device->SetMenuState(CEC_MENU_STATE_DEACTIVATED);
+      }
+      return device->TransmitMenuState(command.initiator);
     }
   }
 
@@ -436,6 +440,7 @@ bool CCECCommandHandler::HandleRequestActiveSource(const cec_command &command)
   if (m_processor->IsRunning())
   {
     CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %i requests active source", (uint8_t) command.initiator);
+    m_processor->m_busDevices[command.initiator]->SetPowerStatus(CEC_POWER_STATUS_ON);
 
     vector<CCECBusDevice *> devices;
     for (size_t iDevicePtr = 0; iDevicePtr < GetMyDevices(devices); iDevicePtr++)
@@ -677,7 +682,7 @@ size_t CCECCommandHandler::GetMyDevices(vector<CCECBusDevice *> &devices) const
   size_t iReturn(0);
 
   cec_logical_addresses addresses = m_processor->GetLogicalAddresses();
-  for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
+  for (uint8_t iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++)
   {
     if (addresses[iPtr])
     {
@@ -758,7 +763,7 @@ bool CCECCommandHandler::TransmitImageViewOn(const cec_logical_address iInitiato
   cec_command command;
   cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_IMAGE_VIEW_ON);
 
-  return Transmit(command, false);
+  return Transmit(command);
 }
 
 bool CCECCommandHandler::TransmitStandby(const cec_logical_address iInitiator, const cec_logical_address iDestination)
@@ -766,7 +771,15 @@ bool CCECCommandHandler::TransmitStandby(const cec_logical_address iInitiator, c
   cec_command command;
   cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_STANDBY);
 
-  return Transmit(command, false);
+  return Transmit(command);
+}
+
+bool CCECCommandHandler::TransmitRequestActiveSource(const cec_logical_address iInitiator, bool bWaitForResponse /* = true */)
+{
+  cec_command command;
+  cec_command::Format(command, iInitiator, CECDEVICE_BROADCAST, CEC_OPCODE_REQUEST_ACTIVE_SOURCE);
+
+  return Transmit(command, !bWaitForResponse);
 }
 
 bool CCECCommandHandler::TransmitRequestCecVersion(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */)
@@ -774,7 +787,7 @@ bool CCECCommandHandler::TransmitRequestCecVersion(const cec_logical_address iIn
   cec_command command;
   cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GET_CEC_VERSION);
 
-  return Transmit(command, bWaitForResponse, CEC_OPCODE_CEC_VERSION);
+  return Transmit(command, !bWaitForResponse);
 }
 
 bool CCECCommandHandler::TransmitRequestMenuLanguage(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */)
@@ -782,7 +795,7 @@ bool CCECCommandHandler::TransmitRequestMenuLanguage(const cec_logical_address i
   cec_command command;
   cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GET_MENU_LANGUAGE);
 
-  return Transmit(command, bWaitForResponse, CEC_OPCODE_SET_MENU_LANGUAGE);
+  return Transmit(command, !bWaitForResponse);
 }
 
 bool CCECCommandHandler::TransmitRequestOSDName(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */)
@@ -790,7 +803,7 @@ bool CCECCommandHandler::TransmitRequestOSDName(const cec_logical_address iIniti
   cec_command command;
   cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GIVE_OSD_NAME);
 
-  return Transmit(command, bWaitForResponse, CEC_OPCODE_SET_OSD_NAME);
+  return Transmit(command, !bWaitForResponse);
 }
 
 bool CCECCommandHandler::TransmitRequestPhysicalAddress(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */)
@@ -798,7 +811,7 @@ bool CCECCommandHandler::TransmitRequestPhysicalAddress(const cec_logical_addres
   cec_command command;
   cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GIVE_PHYSICAL_ADDRESS);
 
-  return Transmit(command, bWaitForResponse, CEC_OPCODE_REPORT_PHYSICAL_ADDRESS);
+  return Transmit(command, !bWaitForResponse);
 }
 
 bool CCECCommandHandler::TransmitRequestPowerStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */)
@@ -806,7 +819,7 @@ bool CCECCommandHandler::TransmitRequestPowerStatus(const cec_logical_address iI
   cec_command command;
   cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GIVE_DEVICE_POWER_STATUS);
 
-  return Transmit(command, bWaitForResponse, CEC_OPCODE_REPORT_POWER_STATUS);
+  return Transmit(command, !bWaitForResponse);
 }
 
 bool CCECCommandHandler::TransmitRequestVendorId(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */)
@@ -814,7 +827,7 @@ bool CCECCommandHandler::TransmitRequestVendorId(const cec_logical_address iInit
   cec_command command;
   cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID);
 
-  return Transmit(command, bWaitForResponse, CEC_OPCODE_DEVICE_VENDOR_ID);
+  return Transmit(command, !bWaitForResponse);
 }
 
 bool CCECCommandHandler::TransmitActiveSource(const cec_logical_address iInitiator, uint16_t iPhysicalAddress)
@@ -824,7 +837,7 @@ bool CCECCommandHandler::TransmitActiveSource(const cec_logical_address iInitiat
   command.parameters.PushBack((uint8_t) ((iPhysicalAddress >> 8) & 0xFF));
   command.parameters.PushBack((uint8_t) (iPhysicalAddress & 0xFF));
 
-  return Transmit(command, false);
+  return Transmit(command);
 }
 
 bool CCECCommandHandler::TransmitCECVersion(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_version cecVersion)
@@ -833,7 +846,7 @@ bool CCECCommandHandler::TransmitCECVersion(const cec_logical_address iInitiator
   cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_CEC_VERSION);
   command.parameters.PushBack((uint8_t)cecVersion);
 
-  return Transmit(command, false);
+  return Transmit(command);
 }
 
 bool CCECCommandHandler::TransmitInactiveSource(const cec_logical_address iInitiator, uint16_t iPhysicalAddress)
@@ -843,7 +856,7 @@ bool CCECCommandHandler::TransmitInactiveSource(const cec_logical_address iIniti
   command.parameters.PushBack((iPhysicalAddress >> 8) & 0xFF);
   command.parameters.PushBack(iPhysicalAddress & 0xFF);
 
-  return Transmit(command, false);
+  return Transmit(command);
 }
 
 bool CCECCommandHandler::TransmitMenuState(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_menu_state menuState)
@@ -852,7 +865,7 @@ bool CCECCommandHandler::TransmitMenuState(const cec_logical_address iInitiator,
   cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_MENU_STATUS);
   command.parameters.PushBack((uint8_t)menuState);
 
-  return Transmit(command, false);
+  return Transmit(command);
 }
 
 bool CCECCommandHandler::TransmitOSDName(const cec_logical_address iInitiator, const cec_logical_address iDestination, CStdString strDeviceName)
@@ -862,7 +875,7 @@ bool CCECCommandHandler::TransmitOSDName(const cec_logical_address iInitiator, c
   for (size_t iPtr = 0; iPtr < strDeviceName.length(); iPtr++)
     command.parameters.PushBack(strDeviceName.at(iPtr));
 
-  return Transmit(command, false);
+  return Transmit(command);
 }
 
 bool CCECCommandHandler::TransmitOSDString(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_display_control duration, const char *strMessage)
@@ -877,7 +890,7 @@ bool CCECCommandHandler::TransmitOSDString(const cec_logical_address iInitiator,
   for (size_t iPtr = 0; iPtr < iLen; iPtr++)
     command.parameters.PushBack(strMessage[iPtr]);
 
-  return Transmit(command, false);
+  return Transmit(command);
 }
 
 bool CCECCommandHandler::TransmitPhysicalAddress(const cec_logical_address iInitiator, uint16_t iPhysicalAddress, cec_device_type type)
@@ -888,7 +901,7 @@ bool CCECCommandHandler::TransmitPhysicalAddress(const cec_logical_address iInit
   command.parameters.PushBack((uint8_t) (iPhysicalAddress & 0xFF));
   command.parameters.PushBack((uint8_t) (type));
 
-  return Transmit(command, false);
+  return Transmit(command);
 }
 
 bool CCECCommandHandler::TransmitSetMenuLanguage(const cec_logical_address iInitiator, const char lang[3])
@@ -899,7 +912,7 @@ bool CCECCommandHandler::TransmitSetMenuLanguage(const cec_logical_address iInit
   command.parameters.PushBack((uint8_t) lang[1]);
   command.parameters.PushBack((uint8_t) lang[2]);
 
-  return Transmit(command, false);
+  return Transmit(command);
 }
 
 bool CCECCommandHandler::TransmitPoll(const cec_logical_address iInitiator, const cec_logical_address iDestination)
@@ -907,7 +920,7 @@ bool CCECCommandHandler::TransmitPoll(const cec_logical_address iInitiator, cons
   cec_command command;
   cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_NONE);
 
-  return Transmit(command, false);
+  return Transmit(command);
 }
 
 bool CCECCommandHandler::TransmitPowerState(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_power_status state)
@@ -916,7 +929,7 @@ bool CCECCommandHandler::TransmitPowerState(const cec_logical_address iInitiator
   cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_REPORT_POWER_STATUS);
   command.parameters.PushBack((uint8_t) state);
 
-  return Transmit(command, false);
+  return Transmit(command);
 }
 
 bool CCECCommandHandler::TransmitVendorID(const cec_logical_address iInitiator, uint64_t iVendorId)
@@ -928,7 +941,7 @@ bool CCECCommandHandler::TransmitVendorID(const cec_logical_address iInitiator,
   command.parameters.PushBack((uint8_t) (((uint64_t)iVendorId >> 8) & 0xFF));
   command.parameters.PushBack((uint8_t) ((uint64_t)iVendorId & 0xFF));
 
-  return Transmit(command, false);
+  return Transmit(command);
 }
 
 bool CCECCommandHandler::TransmitAudioStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination, uint8_t state)
@@ -937,7 +950,7 @@ bool CCECCommandHandler::TransmitAudioStatus(const cec_logical_address iInitiato
   cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_REPORT_AUDIO_STATUS);
   command.parameters.PushBack(state);
 
-  return Transmit(command, false);
+  return Transmit(command);
 }
 
 bool CCECCommandHandler::TransmitSetSystemAudioMode(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_system_audio_status state)
@@ -946,7 +959,7 @@ bool CCECCommandHandler::TransmitSetSystemAudioMode(const cec_logical_address iI
   cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_SET_SYSTEM_AUDIO_MODE);
   command.parameters.PushBack((uint8_t)state);
 
-  return Transmit(command, false);
+  return Transmit(command);
 }
 
 bool CCECCommandHandler::TransmitSetStreamPath(uint16_t iStreamPath)
@@ -956,7 +969,7 @@ bool CCECCommandHandler::TransmitSetStreamPath(uint16_t iStreamPath)
   command.parameters.PushBack((uint8_t) ((iStreamPath >> 8) & 0xFF));
   command.parameters.PushBack((uint8_t) (iStreamPath        & 0xFF));
 
-  return Transmit(command, false);
+  return Transmit(command);
 }
 
 bool CCECCommandHandler::TransmitSystemAudioModeStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_system_audio_status state)
@@ -965,7 +978,7 @@ bool CCECCommandHandler::TransmitSystemAudioModeStatus(const cec_logical_address
   cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS);
   command.parameters.PushBack((uint8_t)state);
 
-  return Transmit(command, false);
+  return Transmit(command);
 }
 
 bool CCECCommandHandler::TransmitDeckStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_deck_info state)
@@ -974,7 +987,7 @@ bool CCECCommandHandler::TransmitDeckStatus(const cec_logical_address iInitiator
   cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_DECK_STATUS);
   command.PushBack((uint8_t)state);
 
-  return Transmit(command, false);
+  return Transmit(command);
 }
 
 bool CCECCommandHandler::TransmitKeypress(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_user_control_code key, bool bWait /* = true */)
@@ -983,7 +996,7 @@ bool CCECCommandHandler::TransmitKeypress(const cec_logical_address iInitiator,
   cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_USER_CONTROL_PRESSED);
   command.parameters.PushBack((uint8_t)key);
 
-  return Transmit(command, bWait);
+  return Transmit(command, !bWait);
 }
 
 bool CCECCommandHandler::TransmitKeyRelease(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWait /* = true */)
@@ -991,12 +1004,14 @@ bool CCECCommandHandler::TransmitKeyRelease(const cec_logical_address iInitiator
   cec_command command;
   cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_USER_CONTROL_RELEASE);
 
-  return Transmit(command, bWait);
+  return Transmit(command, !bWait);
 }
 
-bool CCECCommandHandler::Transmit(cec_command &command, bool bExpectResponse /* = true */, cec_opcode expectedResponse /* = CEC_OPCODE_NONE */)
+bool CCECCommandHandler::Transmit(cec_command &command, bool bSuppressWait /* = false */)
 {
   bool bReturn(false);
+  cec_opcode expectedResponse(cec_command::GetResponseOpcode(command.opcode));
+  bool bExpectResponse(expectedResponse != CEC_OPCODE_NONE && !bSuppressWait);
   command.transmit_timeout = m_iTransmitTimeout;
 
   if (command.initiator == CECDEVICE_UNKNOWN)
@@ -1006,8 +1021,8 @@ bool CCECCommandHandler::Transmit(cec_command &command, bool bExpectResponse /*
   }
 
   {
-    uint8_t iTries(0), iMaxTries(command.opcode == CEC_OPCODE_NONE ? 1 : m_iTransmitRetries + 1);
-    while (!bReturn && ++iTries <= iMaxTries)
+    uint8_t iTries(0), iMaxTries(!command.opcode_set ? 1 : m_iTransmitRetries + 1);
+    while (!bReturn && ++iTries <= iMaxTries && !m_busDevice->IsUnsupportedFeature(command.opcode))
     {
       if ((bReturn = m_processor->Transmit(command)) == true)
       {
@@ -1043,3 +1058,8 @@ bool CCECCommandHandler::ActivateSource(void)
   }
   return true;
 }
+
+void CCECCommandHandler::SignalOpcode(cec_opcode opcode)
+{
+  m_waitForResponse->Received(opcode);
+}
index 93892709ff0fa01534b5d4c7c24b518d6f0387bc..24f62658b9009c419e07d057a923cc4aa5a6faaa 100644 (file)
@@ -77,7 +77,7 @@ namespace CEC
       m_waitingFor.clear();
     }
 
-    bool Wait(cec_opcode opcode, uint32_t iTimeout = 2000)
+    bool Wait(cec_opcode opcode, uint32_t iTimeout = CEC_DEFAULT_TRANSMIT_WAIT)
     {
       CResponse *response = GetEvent(opcode);
       return response ? response->Wait(iTimeout) : false;
@@ -132,6 +132,7 @@ namespace CEC
     virtual bool PowerOn(const cec_logical_address iInitiator, const cec_logical_address iDestination);
     virtual bool TransmitImageViewOn(const cec_logical_address iInitiator, const cec_logical_address iDestination);
     virtual bool TransmitStandby(const cec_logical_address iInitiator, const cec_logical_address iDestination);
+    virtual bool TransmitRequestActiveSource(const cec_logical_address iInitiator, bool bWaitForResponse = true);
     virtual bool TransmitRequestCecVersion(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse = true);
     virtual bool TransmitRequestMenuLanguage(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse = true);
     virtual bool TransmitRequestOSDName(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse = true);
@@ -157,6 +158,9 @@ namespace CEC
     virtual bool TransmitKeyRelease(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWait = true);
     virtual bool TransmitSetStreamPath(uint16_t iStreamPath);
     virtual bool SendDeckStatusUpdateOnActiveSource(void) const { return m_bOPTSendDeckStatusUpdateOnActiveSource; };
+    virtual bool TransmitPendingActiveSourceCommands(void) { return true; }
+
+    virtual void SignalOpcode(cec_opcode opcode);
 
   protected:
     virtual bool HandleActiveSource(const cec_command &command);
@@ -204,7 +208,7 @@ namespace CEC
     virtual bool SetVendorId(const cec_command &command);
     virtual void SetPhysicalAddress(cec_logical_address iAddress, uint16_t iNewAddress);
 
-    virtual bool Transmit(cec_command &command, bool bExpectResponse = true, cec_opcode expectedResponse = CEC_OPCODE_NONE);
+    virtual bool Transmit(cec_command &command, bool bSuppressWait = false);
 
     CCECBusDevice *                       m_busDevice;
     CCECProcessor *                       m_processor;
index 944a6492e4c1bda8e1ea256c7601cc49264ea17b..9766827615de1cd4706e64b11d674633ca1e1545 100644 (file)
@@ -42,6 +42,6 @@ namespace CEC
     CRLCommandHandler(CCECBusDevice *busDevice);
     virtual ~CRLCommandHandler(void) {};
 
-    virtual bool InitHandler(void);
+    bool InitHandler(void);
   };
 };
index 957d296a8a8733dfbf6ec8bf3931ffab67a92ddb..b9103ec5f59da75a037aee61f68a68c9986bde46 100644 (file)
@@ -127,7 +127,7 @@ bool CSLCommandHandler::HandleActiveSource(const cec_command &command)
   {
     uint16_t iAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
     CCECBusDevice *primary = m_processor->GetPrimaryDevice();
-    bool bSendPowerOffState(iAddress != primary->GetPhysicalAddress(false) && primary->IsActiveSource());
+    bool bSendPowerOffState(iAddress != primary->GetPhysicalAddress() && primary->IsActiveSource());
 
     m_processor->SetActiveSource(iAddress);
     if (bSendPowerOffState)
@@ -152,23 +152,11 @@ bool CSLCommandHandler::HandleDeviceVendorId(const cec_command &command)
   {
     cec_command response;
     cec_command::Format(response, m_processor->GetLogicalAddress(), command.initiator, CEC_OPCODE_FEATURE_ABORT);
-    return Transmit(response, false);
+    return Transmit(response);
   }
   return true;
 }
 
-bool CSLCommandHandler::HandleGivePhysicalAddress(const cec_command &command)
-{
-  if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination))
-  {
-    CCECBusDevice *device = GetDevice(command.destination);
-    if (device)
-      return device->TransmitPhysicalAddress(); // only the physical address, don't send image view on
-  }
-
-  return false;
-}
-
 bool CSLCommandHandler::HandleVendorCommand(const cec_command &command)
 {
   if (!m_busDevice->MyLogicalAddressContains(command.destination))
@@ -215,7 +203,7 @@ void CSLCommandHandler::TransmitVendorCommand0205(const cec_logical_address iSou
   response.PushBack(SL_COMMAND_UNKNOWN_02);
   response.PushBack(SL_COMMAND_TYPE_HDDRECORDER);
 
-  Transmit(response, false);
+  Transmit(response);
 }
 
 void CSLCommandHandler::HandleVendorCommandPowerOn(const cec_command &command)
@@ -266,7 +254,7 @@ void CSLCommandHandler::TransmitVendorCommandSetDeviceMode(const cec_logical_add
   cec_command::Format(response, iSource, iDestination, CEC_OPCODE_VENDOR_COMMAND);
   response.PushBack(SL_COMMAND_SET_DEVICE_MODE);
   response.PushBack((uint8_t)type);
-  Transmit(response, false);
+  Transmit(response);
 }
 
 bool CSLCommandHandler::HandleGiveDeckStatus(const cec_command &command)
@@ -418,7 +406,7 @@ bool CSLCommandHandler::PowerOn(const cec_logical_address iInitiator, const cec_
     cec_command::Format(command, CECDEVICE_TV, iDestination, CEC_OPCODE_VENDOR_COMMAND);
     command.PushBack(SL_COMMAND_POWER_ON);
     command.PushBack(0);
-    return Transmit(command, false);
+    return Transmit(command);
   }
 
   return CCECCommandHandler::PowerOn(iInitiator, iDestination);
index a0ea25a329cb3d49bc9716212ce0f8983b26908b..fefb8b387dea30d8bf49b477279b19ee08847e9e 100644 (file)
@@ -42,36 +42,35 @@ namespace CEC
     CSLCommandHandler(CCECBusDevice *busDevice);
     virtual ~CSLCommandHandler(void) {};
 
-    virtual bool InitHandler(void);
-    virtual bool ActivateSource(void);
+    bool InitHandler(void);
+    bool ActivateSource(void);
 
   protected:
-    virtual bool HandleActiveSource(const cec_command &command);
-    virtual bool HandleDeviceVendorId(const cec_command &command);
-    virtual bool HandleGivePhysicalAddress(const cec_command &command);
-    virtual bool HandleVendorCommand(const cec_command &command);
+    bool HandleActiveSource(const cec_command &command);
+    bool HandleDeviceVendorId(const cec_command &command);
+    bool HandleVendorCommand(const cec_command &command);
 
-    virtual void HandleVendorCommand01(const cec_command &command);
-    virtual void TransmitVendorCommand0205(const cec_logical_address iSource, const cec_logical_address iDestination);
+    void HandleVendorCommand01(const cec_command &command);
+    void TransmitVendorCommand0205(const cec_logical_address iSource, const cec_logical_address iDestination);
 
-    virtual void HandleVendorCommandPowerOn(const cec_command &command);
-    virtual void HandleVendorCommandPowerOnStatus(const cec_command &command);
+    void HandleVendorCommandPowerOn(const cec_command &command);
+    void HandleVendorCommandPowerOnStatus(const cec_command &command);
 
-    virtual void HandleVendorCommandSLConnect(const cec_command &command);
-    virtual void TransmitVendorCommandSetDeviceMode(const cec_logical_address iSource, const cec_logical_address iDestination, const cec_device_type type);
+    void HandleVendorCommandSLConnect(const cec_command &command);
+    void TransmitVendorCommandSetDeviceMode(const cec_logical_address iSource, const cec_logical_address iDestination, const cec_device_type type);
 
-    virtual bool HandleGiveDevicePowerStatus(const cec_command &command);
-    virtual bool HandleGiveDeckStatus(const cec_command &command);
-    virtual bool HandleRequestActiveSource(const cec_command &command);
-    virtual bool HandleFeatureAbort(const cec_command &command);
-    virtual bool HandleStandby(const cec_command &command);
-    virtual bool TransmitMenuState(const cec_logical_address UNUSED(iInitiator), const cec_logical_address UNUSED(iDestination), cec_menu_state UNUSED(menuState)) { return true; }
-    virtual bool PowerOn(const cec_logical_address iInitiator, const cec_logical_address iDestination);
+    bool HandleGiveDevicePowerStatus(const cec_command &command);
+    bool HandleGiveDeckStatus(const cec_command &command);
+    bool HandleRequestActiveSource(const cec_command &command);
+    bool HandleFeatureAbort(const cec_command &command);
+    bool HandleStandby(const cec_command &command);
+    bool TransmitMenuState(const cec_logical_address UNUSED(iInitiator), const cec_logical_address UNUSED(iDestination), cec_menu_state UNUSED(menuState)) { return true; }
+    bool PowerOn(const cec_logical_address iInitiator, const cec_logical_address iDestination);
 
-    virtual void ResetSLState(void);
-    virtual bool SLInitialised(void);
-    virtual void SetSLInitialised(void);
-    virtual bool ActiveSourceSent(void);
+    void ResetSLState(void);
+    bool SLInitialised(void);
+    void SetSLInitialised(void);
+    bool ActiveSourceSent(void);
 
     bool               m_bSLEnabled;
     bool               m_bActiveSourceSent;
index ad4cf1717fb68a7f0bd0186e5caa54c99ee1f12d..e8cf7c8c4d01f0aede754d5c2c71f76d94185c50 100644 (file)
 #include "VLCommandHandler.h"
 #include "../devices/CECBusDevice.h"
 #include "../CECProcessor.h"
+#include "../LibCEC.h"
+
+#define VL_POWER_CHANGE 0x20
+#define VL_POWERED_UP   0x00
+#define VL_POWERED_DOWN 0x01
 
 using namespace CEC;
+using namespace PLATFORM;
 
 CVLCommandHandler::CVLCommandHandler(CCECBusDevice *busDevice) :
-    CCECCommandHandler(busDevice)
+    CCECCommandHandler(busDevice),
+    m_bActiveSourcePending(false),
+    m_bPowerUpEventReceived(false)
 {
   m_vendorId = CEC_VENDOR_PANASONIC;
+
+  /* use the VL commandhandler for the primary device that is handled by libCEC */
+  if (busDevice->GetLogicalAddress() == CECDEVICE_TV)
+  {
+    CCECBusDevice *primary = m_processor->GetPrimaryDevice();
+    if (primary && m_busDevice->GetLogicalAddress() != primary->GetLogicalAddress())
+    {
+      primary->SetVendorId(CEC_VENDOR_PANASONIC);
+      primary->ReplaceHandler(false);
+    }
+  }
 }
 
 bool CVLCommandHandler::InitHandler(void)
 {
   CCECBusDevice *primary = m_processor->GetPrimaryDevice();
   if (primary->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE)
-  {
     return m_processor->ChangeDeviceType(CEC_DEVICE_TYPE_RECORDING_DEVICE, CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
-  }
+
   return CCECCommandHandler::InitHandler();
 }
+
+bool CVLCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &command)
+{
+  if (command.initiator == CECDEVICE_TV &&
+      command.destination == CECDEVICE_BROADCAST &&
+      command.parameters.At(3) == VL_POWER_CHANGE)
+  {
+    if (command.parameters.At(4) == VL_POWERED_UP)
+    {
+      CLibCEC::AddLog(CEC_LOG_DEBUG, "TV powered up");
+      {
+        CLockObject lock(m_mutex);
+        m_bPowerUpEventReceived = true;
+      }
+      m_processor->TransmitPendingActiveSourceCommands();
+    }
+    else if (command.parameters.At(4) == VL_POWERED_DOWN)
+      CLibCEC::AddLog(CEC_LOG_DEBUG, "TV powered down");
+    else if (command.parameters.At(4) == VL_POWERED_DOWN)
+      CLibCEC::AddLog(CEC_LOG_DEBUG, "unknown vendor command");
+
+    return true;
+  }
+
+  return CCECCommandHandler::HandleDeviceVendorCommandWithId(command);
+}
+
+bool CVLCommandHandler::TransmitActiveSource(const cec_logical_address iInitiator, uint16_t iPhysicalAddress)
+{
+  bool bPowerUpEventReceived(false);
+
+  CCECBusDevice *tv = m_processor->m_busDevices[CECDEVICE_TV];
+  if (tv && tv->GetVendorId(false) == CEC_VENDOR_PANASONIC)
+  {
+    CVLCommandHandler *handler = static_cast<CVLCommandHandler *>(tv->GetHandler());
+    bPowerUpEventReceived = handler ? handler->PowerUpEventReceived() : false;
+  }
+
+  if (!bPowerUpEventReceived)
+  {
+    CLockObject lock(m_mutex);
+    // wait until we received the event
+    m_bActiveSourcePending = true;
+    return true;
+  }
+  else
+  {
+    // transmit standard active source message
+    return CCECCommandHandler::TransmitActiveSource(iInitiator, iPhysicalAddress);
+  }
+}
+
+bool CVLCommandHandler::TransmitPendingActiveSourceCommands(void)
+{
+  bool bTransmitCommand(false);
+  {
+    CLockObject lock(m_mutex);
+    bTransmitCommand = m_bActiveSourcePending;
+    m_bActiveSourcePending = false;
+  }
+
+  if (bTransmitCommand)
+  {
+    CLibCEC::AddLog(CEC_LOG_DEBUG, "transmitting delayed activate source command");
+    return CCECCommandHandler::TransmitActiveSource(m_busDevice->GetLogicalAddress(), m_busDevice->GetPhysicalAddress());
+  }
+  return true;
+}
+
+bool CVLCommandHandler::PowerUpEventReceived(void)
+{
+  {
+    CLockObject lock(m_mutex);
+    if (m_bPowerUpEventReceived)
+      return true;
+  }
+
+  cec_power_status powerStatus = m_busDevice->GetPowerStatus();
+
+  CLockObject lock(m_mutex);
+  m_bPowerUpEventReceived = (powerStatus == CEC_POWER_STATUS_ON);
+  return m_bPowerUpEventReceived;
+}
index c3b0fe0337b261e5caf978d23076e9b12f929835..d24ea3d93ad9470fa66fb0c7f16e89fab701c94e 100644 (file)
@@ -40,6 +40,18 @@ namespace CEC
   public:
     CVLCommandHandler(CCECBusDevice *busDevice);
     virtual ~CVLCommandHandler(void) {};
-    virtual bool InitHandler(void);
+
+    bool InitHandler(void);
+
+    bool HandleDeviceVendorCommandWithId(const cec_command &command);
+    bool TransmitActiveSource(const cec_logical_address iInitiator, uint16_t iPhysicalAddress);
+    bool TransmitPendingActiveSourceCommands(void);
+
+    bool PowerUpEventReceived(void);
+
+  private:
+    PLATFORM::CMutex m_mutex;
+    bool             m_bActiveSourcePending;
+    bool             m_bPowerUpEventReceived;
   };
 };
index 8b56731adfa2918f2a290e71dd4acc62ce2b7709..89f822b0dec300a89aee85d2f55e62871fac9080 100644 (file)
@@ -66,7 +66,7 @@ namespace PLATFORM
   typedef pthread_t thread_t;
 
   #define ThreadsCreate(thread, func, arg)         (pthread_create(&thread, NULL, (void *(*) (void *))func, (void *)arg) == 0)
-  #define ThreadsWait(thread, retval)              (pthread_join(thread, retval) == 0)
+  #define ThreadsWait(thread, retval)              (thread ? pthread_join(thread, retval) == 0 : true)
 
   typedef pthread_mutex_t mutex_t;
   #define MutexCreate(mutex)                       pthread_mutex_init(&mutex, GetRecursiveMutexAttribute());
index 97774b3b1ee28289952bf8af4321d891398925e8..e29578c728a1b5b0abf5288b5898615433fb6498 100644 (file)
@@ -46,6 +46,11 @@ namespace PLATFORM
     virtual ~CThread(void)
     {
       StopThread(0);
+      void *retVal;
+      ThreadsWait(m_thread, &retVal);
+      #if defined(__WINDOWS__)
+      (void *)retVal; //"unreferenced local variable" warning
+      #endif
     }
 
     static void *ThreadHandler(CThread *thread)
@@ -88,18 +93,18 @@ namespace PLATFORM
 
     virtual bool CreateThread(bool bWait = true)
     {
-        bool bReturn(false);
-        CLockObject lock(m_threadMutex);
-        if (!IsRunning())
+      bool bReturn(false);
+      CLockObject lock(m_threadMutex);
+      if (!IsRunning())
+      {
+        m_bStop = false;
+        if (ThreadsCreate(m_thread, CThread::ThreadHandler, ((void*)static_cast<CThread *>(this))))
         {
-          m_bStop = false;
-          if (ThreadsCreate(m_thread, CThread::ThreadHandler, ((void*)static_cast<CThread *>(this))))
-          {
-            if (bWait)
-              m_threadCondition.Wait(m_threadMutex, m_bRunning);
-            bReturn = true;
-          }
+          if (bWait)
+            m_threadCondition.Wait(m_threadMutex, m_bRunning);
+          bReturn = true;
         }
+      }
       return bReturn;
     }
 
@@ -140,13 +145,13 @@ namespace PLATFORM
 
   protected:
     void SetRunning(bool bSetTo);
+    CMutex           m_threadMutex;
 
   private:
     bool             m_bStop;
     bool             m_bRunning;
     bool             m_bStopped;
     CCondition<bool> m_threadCondition;
-    CMutex           m_threadMutex;
     thread_t         m_thread;
   };
 };
index 8777661df1c4e6942f937905126b868c2d2cce1f..aa658ee61f231b4d111ba9d1a19a82bcfd3c17a8 100644 (file)
@@ -41,7 +41,8 @@ namespace PLATFORM
     {
     public:
       SyncedBuffer(size_t iMaxSize = 100) :
-          m_maxSize(iMaxSize) {}
+          m_maxSize(iMaxSize),
+          m_bHasMessages(false) {}
 
       virtual ~SyncedBuffer(void)
       {
@@ -53,6 +54,7 @@ namespace PLATFORM
         CLockObject lock(m_mutex);
         while (!m_buffer.empty())
           m_buffer.pop();
+        m_condition.Broadcast();
       }
 
       size_t Size(void)
@@ -74,17 +76,29 @@ namespace PLATFORM
           return false;
 
         m_buffer.push(entry);
+        m_bHasMessages = true;
+        m_condition.Signal();
         return true;
       }
 
-      bool Pop(_BType &entry)
+      bool Pop(_BType &entry, uint32_t iTimeoutMs = 0)
       {
         bool bReturn(false);
         CLockObject lock(m_mutex);
+
+        // wait for a signal if the buffer is empty
+        if (m_buffer.empty() && iTimeoutMs > 0)
+        {
+          if (!m_condition.Wait(m_mutex, m_bHasMessages, iTimeoutMs))
+            return bReturn;
+        }
+
+        // pop the first item
         if (!m_buffer.empty())
         {
           entry = m_buffer.front();
           m_buffer.pop();
+          m_bHasMessages = !m_buffer.empty();
           bReturn = true;
         }
         return bReturn;
@@ -106,5 +120,7 @@ namespace PLATFORM
       size_t             m_maxSize;
       std::queue<_BType> m_buffer;
       CMutex             m_mutex;
+      CCondition<bool>   m_condition;
+      bool               m_bHasMessages;
     };
 };
index 0e7387487564a4779cd58cd4444f39f5a0befdeb..39b7ff47df5ca8e761aa3235adc7feffc9db02e9 100644 (file)
@@ -175,14 +175,18 @@ int CecCommand(void *UNUSED(cbParam), const cec_command &UNUSED(command))
   return 0;
 }
 
-void EnableCallbacks(ICECAdapter *adapter)
+int CecAlert(void *UNUSED(cbParam), const libcec_alert type, const libcec_parameter &UNUSED(param))
 {
-  g_callbacks.CBCecLogMessage = &CecLogMessage;
-  g_callbacks.CBCecKeyPress   = &CecKeyPress;
-  g_callbacks.CBCecCommand    = &CecCommand;
-  g_callbacks.CBCecConfigurationChanged = NULL;
-  g_callbacks.CBCecAlert      = NULL;
-  adapter->EnableCallbacks(NULL, &g_callbacks);
+  switch (type)
+  {
+  case CEC_ALERT_CONNECTION_LOST:
+    PrintToStdOut("Connection lost - exiting\n");
+    g_bExit = true;
+    break;
+  default:
+    break;
+  }
+  return 0;
 }
 
 void ListDevices(ICECAdapter *parser)
@@ -200,14 +204,24 @@ void ListDevices(ICECAdapter *parser)
 
     for (int8_t iDevicePtr = 0; iDevicePtr < iDevicesFound; iDevicePtr++)
     {
-      strDeviceInfo.AppendFormat("device:             %d\ncom port:           %s\n", iDevicePtr + 1, devices[iDevicePtr].comm);
+      strDeviceInfo.AppendFormat("device:              %d\ncom port:            %s\n", iDevicePtr + 1, devices[iDevicePtr].comm);
       libcec_configuration config;
       config.Clear();
 
       if (!parser->GetDeviceInformation(devices[iDevicePtr].comm, &config))
         PrintToStdOut("WARNING: unable to open the device on port %s", devices[iDevicePtr].comm);
       else
-        strDeviceInfo.AppendFormat("firmware version:   %d\n", config.iFirmwareVersion);
+      {
+        strDeviceInfo.AppendFormat("firmware version:    %d\n", config.iFirmwareVersion);
+
+        if (config.iFirmwareBuildDate != CEC_FW_BUILD_UNKNOWN)
+        {
+          time_t buildTime = (time_t)config.iFirmwareBuildDate;
+          strDeviceInfo.AppendFormat("firmware build date: %s", asctime(gmtime(&buildTime)));
+          strDeviceInfo = strDeviceInfo.Left((int)strDeviceInfo.length() - 1); // strip \n added by asctime
+          strDeviceInfo.append(" +0000");
+        }
+      }
       strDeviceInfo.append("\n");
     }
     PrintToStdOut(strDeviceInfo.c_str());
@@ -318,7 +332,7 @@ bool ProcessCommandSP(ICECAdapter *parser, const string &command, string &argume
     if (GetWord(arguments, strAddress))
     {
       sscanf(strAddress.c_str(), "%x", &iAddress);
-      if (iAddress >= 0 && iAddress <= 0xFFFF)
+      if (iAddress >= 0 && iAddress <= CEC_INVALID_PHYSICAL_ADDRESS)
         parser->SetStreamPath((uint16_t)iAddress);
       return true;
     }
@@ -509,7 +523,7 @@ bool ProcessCommandAS(ICECAdapter *parser, const string &command, string & UNUSE
 {
   if (command == "as")
   {
-    parser->SetActiveView();
+    parser->SetActiveSource();
     return true;
   }
 
@@ -809,14 +823,15 @@ bool ProcessCommandSCAN(ICECAdapter *parser, const string &command, string & UNU
 {
   if (command == "scan")
   {
-    PrintToStdOut("CEC bus information");
-    PrintToStdOut("===================");
+    CStdString strLog;
+    PrintToStdOut("requesting CEC bus information ...");
+
+    strLog.append("CEC bus information\n===================\n");
     cec_logical_addresses addresses = parser->GetActiveDevices();
     for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
     {
       if (addresses[iPtr])
       {
-        CStdString strLog;
         uint64_t iVendorId        = parser->GetDeviceVendorId((cec_logical_address)iPtr);
         bool     bActive          = parser->IsActiveSource((cec_logical_address)iPtr);
         uint16_t iPhysicalAddress = parser->GetDevicePhysicalAddress((cec_logical_address)iPtr);
@@ -838,10 +853,14 @@ bool ProcessCommandSCAN(ICECAdapter *parser, const string &command, string & UNU
         strLog.AppendFormat("power status:  %s\n", parser->ToString(power));
         if ((uint8_t)lang.device == iPtr)
           strLog.AppendFormat("language:      %s\n", lang.language);
-        strLog.append("\n");
-        PrintToStdOut(strLog);
+        strLog.append("\n\n");
       }
     }
+
+    cec_logical_address activeSource = parser->GetActiveSource();
+    strLog.AppendFormat("currently active source: %s (%d)", parser->ToString(activeSource), (int)activeSource);
+
+    PrintToStdOut(strLog);
     return true;
   }
 
@@ -1067,11 +1086,12 @@ int main (int argc, char *argv[])
 {
   g_config.Clear();
   snprintf(g_config.strDeviceName, 13, "CECTester");
-  g_config.callbackParam       = NULL;
-  g_config.clientVersion       = CEC_CLIENT_VERSION_1_6_1;
+  g_config.clientVersion       = CEC_CLIENT_VERSION_1_6_2;
+  g_config.bActivateSource     = 0;
   g_callbacks.CBCecLogMessage  = &CecLogMessage;
   g_callbacks.CBCecKeyPress    = &CecKeyPress;
   g_callbacks.CBCecCommand     = &CecCommand;
+  g_callbacks.CBCecAlert       = &CecAlert;
   g_config.callbacks           = &g_callbacks;
 
   if (!ProcessCommandLineArguments(argc, argv))