+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:
-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
+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:
#include "cectypes.h"
+#define LIBCEC_VERSION_CURRENT CEC_SERVER_VERSION_1_6_2
+
namespace CEC
{
class ICECAdapter
#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
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,
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;
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;
typedef enum libcec_alert
{
- CEC_ALERT_SERVICE_DEVICE
+ CEC_ALERT_SERVICE_DEVICE,
+ CEC_ALERT_CONNECTION_LOST
} libcec_alert;
typedef enum libcec_parameter_type
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
{
* @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
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
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
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;
/>
<Tool
Name="VCLinkerTool"
- AdditionalDependencies="$(OutDir)libcec.x64.lib"
- OutputFile="$(OutDir)\$(ProjectName).x64.dll"
+ AdditionalDependencies=""$(OutDir)libcec.x64.lib""
+ OutputFile=""$(OutDir)\$(ProjectName).x64.dll""
LinkIncremental="2"
GenerateDebugInformation="true"
AssemblyDebug="1"
/>
<Tool
Name="VCLinkerTool"
- AdditionalDependencies="$(OutDir)libcec.x64.lib"
+ AdditionalDependencies=""$(OutDir)libcec.x64.lib""
/>
<Tool
Name="VCALinkTool"
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;
// 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")]
[assembly:AssemblyTrademarkAttribute("")];
[assembly:AssemblyCultureAttribute("")];
-[assembly:AssemblyVersionAttribute("1.6.1.0")];
+[assembly:AssemblyVersionAttribute("1.6.2.0")];
[assembly:ComVisible(false)];
[assembly:CLSCompliantAttribute(true)];
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
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
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)
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;
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;
};
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)
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 &);
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
return 0;
}
+ virtual int ReceiveMenuStateChange(CecMenuState newVal)
+ {
+ return 0;
+ }
+
protected:
// managed callback methods
int CecLogMessageManaged(const CEC::cec_log_message &message)
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;
m_logMessageGCHandle.Free();
m_keypressGCHandle.Free();
m_commandGCHandle.Free();
+ m_alertGCHandle.Free();
+ m_menuGCHandle.Free();
}
}
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;
}
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;
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;
}
// 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")]
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);
}
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;
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;
}
}
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),
{
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)
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;
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;
}
}
{
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;
{
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)
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);
}
bool CCECProcessor::IsInitialised(void)
{
- CLockObject lock(m_mutex);
+ CLockObject lock(m_threadMutex);
return m_bInitialised;
}
/* 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();
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);
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;
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);
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);
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;
{
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);
}
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())
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)
{
}
m_busDevices[addr]->SetActiveSource();
- if (m_busDevices[addr]->GetPhysicalAddress(false) != 0xFFFF)
+ if (IsValidPhysicalAddress(m_busDevices[addr]->GetPhysicalAddress()))
bReturn = m_busDevices[addr]->ActivateSource();
return bReturn;
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;
}
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)
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;
}
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;
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);
{
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();
}
}
- 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();
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);
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);
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;
{
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])
{
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])
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;
}
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 */)
{
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);
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;
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 */)
{
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;
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;
}
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;
}
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";
}
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";
}
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())
{
}
else
{
- return m_communication->StartBootloader();
+ m_communication->StartBootloader();
+ Close();
+ bReturn = true;
}
+
+ return bReturn;
}
bool CCECProcessor::PingAdapter(void)
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;
{
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;
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))
{
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)
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;
+}
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);
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);
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];
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;
- };
};
m_callbacks(configuration->callbacks),
m_cbParam(configuration->callbackParam)
{
- configuration->serverVersion = CEC_SERVER_VERSION_1_6_1;
m_cec = new CCECProcessor(this, configuration);
}
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())
{
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;
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);
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);
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);
}
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);
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 ¶m)
+{
+ 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)
}
}
+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;
}
{
CLibCEC *lib = new CLibCEC(configuration);
CLibCEC::SetInstance(lib);
+ lib->GetCurrentConfiguration(configuration);
return static_cast< void* > (lib);
}
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();
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)
}
}
-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;
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);
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, ...);
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 ¶m);
static CLibCEC *GetInstance(void);
static void SetInstance(CLibCEC *instance);
ICECCallbacks * m_callbacks;
void * m_cbParam;
PLATFORM::CMutex m_mutex;
+ PLATFORM::CMutex m_logMutex;
};
};
* @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
/*!
* @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
*/
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.
*/
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();
}
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;
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");
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;
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");
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;
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;
}
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");
}
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);
}
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);
}
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);
}
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);
}
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);
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++)
*/
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.
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 */
};
}
#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),
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);
}
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);
{
m_commands = new CUSBCECAdapterCommands(this);
if (!m_adapterMessageQueue)
+ {
m_adapterMessageQueue = new CCECAdapterMessageQueue(this);
+ m_adapterMessageQueue->CreateThread();
+ }
/* try to open the connection */
CStdString strError;
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;
}
}
-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];
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;
}
/* 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;
}
/* 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 */
/* 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
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);
else
bReturn = true;
+ /* try to read the build date */
+ m_commands->RequestBuildDate();
+
SetInitialised(bReturn);
return bReturn;
}
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)
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)
bool CUSBCECAdapterCommunication::SetControlledMode(bool controlled)
{
- return m_commands->SetControlledMode(controlled);
+ return m_port->IsOpen() ? m_commands->SetControlledMode(controlled) : false;
}
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
* @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);
* @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.
* @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).
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();
// 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
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;
}
}
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:
return "SET_OSD_NAME";
case MSGCODE_WRITE_EEPROM:
return "WRITE_EEPROM";
+ default:
+ break;
}
return "unknown";
transmit_timeout = CEC_DEFAULT_TRANSMIT_TIMEOUT;
response.Clear();
packet.Clear();
- maxTries = CEC_DEFAULT_TRANSMIT_RETRIES + 1;
- tries = 0;
lineTimeout = 3;
- retryTimeout = 3;
bNextByteIsEscaped = false;
}
/*!
* @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.
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 */
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),
{
{
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;
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);
/* 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)
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;
*/
#include "USBCECAdapterMessage.h"
+#include "../platform/threads/threads.h"
#include <map>
namespace CEC
*/
const char *ToString(void) const;
- private:
/*!
* @brief Called when a 'command accepted' message was received.
* @param message The message that was received.
PLATFORM::CMutex m_mutex; /**< mutex for changes to this class */
};
- class CCECAdapterMessageQueue
+ class CCECAdapterMessageQueue : public PLATFORM::CThread
{
friend class CUSBCECAdapterCommunication;
* @param iQueueSize The outgoing message queue size.
*/
CCECAdapterMessageQueue(CUSBCECAdapterCommunication *com) :
+ PLATFORM::CThread(),
m_com(com),
m_iNextMessage(0) {}
virtual ~CCECAdapterMessageQueue(void);
*/
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 */
#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)
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;
#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);
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);
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);
//@{
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;
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)
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)
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)
{
{
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)
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;
}
}
}
}
-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();
}
}
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;
}
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);
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;
}
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();
}
}
+bool CCECBusDevice::TransmitPendingActiveSourceCommands(void)
+{
+ MarkBusy();
+ bool bReturn = m_handler->TransmitPendingActiveSourceCommands();
+ MarkReady();
+ return bReturn;
+}
+
//@}
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);
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; }
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);
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);
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);
#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)
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;
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)
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
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;
}
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) {};
};
}
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;
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) {};
};
}
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);
};
};
{
CCECBusDevice *device = GetDevice(command.destination);
if (device)
- {
- device->SetActiveSource();
- return device->TransmitPhysicalAddress() &&
- device->TransmitImageViewOn() &&
- device->TransmitActiveSource();
- }
+ return device->TransmitPhysicalAddress();
}
return false;
{
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);
}
}
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++)
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])
{
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)
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 */)
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 */)
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 */)
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 */)
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 */)
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 */)
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)
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)
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)
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)
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)
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)
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)
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])
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)
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)
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)
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)
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)
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)
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)
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)
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 */)
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 */)
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)
}
{
- 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)
{
}
return true;
}
+
+void CCECCommandHandler::SignalOpcode(cec_opcode opcode)
+{
+ m_waitForResponse->Received(opcode);
+}
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;
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);
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);
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;
CRLCommandHandler(CCECBusDevice *busDevice);
virtual ~CRLCommandHandler(void) {};
- virtual bool InitHandler(void);
+ bool InitHandler(void);
};
};
{
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)
{
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))
response.PushBack(SL_COMMAND_UNKNOWN_02);
response.PushBack(SL_COMMAND_TYPE_HDDRECORDER);
- Transmit(response, false);
+ Transmit(response);
}
void CSLCommandHandler::HandleVendorCommandPowerOn(const cec_command &command)
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)
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);
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;
#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;
+}
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;
};
};
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());
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)
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;
}
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;
};
};
{
public:
SyncedBuffer(size_t iMaxSize = 100) :
- m_maxSize(iMaxSize) {}
+ m_maxSize(iMaxSize),
+ m_bHasMessages(false) {}
virtual ~SyncedBuffer(void)
{
CLockObject lock(m_mutex);
while (!m_buffer.empty())
m_buffer.pop();
+ m_condition.Broadcast();
}
size_t Size(void)
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;
size_t m_maxSize;
std::queue<_BType> m_buffer;
CMutex m_mutex;
+ CCondition<bool> m_condition;
+ bool m_bHasMessages;
};
};
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)
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());
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;
}
{
if (command == "as")
{
- parser->SetActiveView();
+ parser->SetActiveSource();
return true;
}
{
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);
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;
}
{
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))