Skip to content

Instantly share code, notes, and snippets.

@MilhouseVH
Created October 18, 2016 16:23
Show Gist options
  • Save MilhouseVH/530f703f13b762f73422e0209345c4b2 to your computer and use it in GitHub Desktop.
Save MilhouseVH/530f703f13b762f73422e0209345c4b2 to your computer and use it in GitHub Desktop.
diff --git a/src/libcec/adapter/RPi/RPiCECAdapterCommunication.cpp b/src/libcec/adapter/RPi/RPiCECAdapterCommunication.cpp
index 96065f8..b774832 100644
--- a/src/libcec/adapter/RPi/RPiCECAdapterCommunication.cpp
+++ b/src/libcec/adapter/RPi/RPiCECAdapterCommunication.cpp
@@ -71,7 +71,6 @@ CRPiCECAdapterCommunication::CRPiCECAdapterCommunication(IAdapterCommunicationCa
m_bLogicalAddressChanged(false),
m_previousLogicalAddress(CECDEVICE_FREEUSE),
m_bLogicalAddressRegistered(false),
- m_bDisableCallbacks(false),
m_bInitialised(false)
{
m_queue = new CRPiCECAdapterMessageQueue(this);
@@ -142,12 +141,6 @@ void CRPiCECAdapterCommunication::OnTVServiceCallback(uint32_t reason, uint32_t
void CRPiCECAdapterCommunication::OnDataReceived(uint32_t header, uint32_t p0, uint32_t p1, uint32_t p2, uint32_t p3)
{
- {
- CLockObject lock(m_mutex);
- if (m_bDisableCallbacks)
- return;
- }
-
VC_CEC_NOTIFY_T reason = (VC_CEC_NOTIFY_T)CEC_CB_REASON(header);
#ifdef CEC_DEBUGGING
@@ -371,50 +364,12 @@ std::string CRPiCECAdapterCommunication::GetError(void) const
return strError;
}
-void CRPiCECAdapterCommunication::SetDisableCallback(const bool disable)
-{
- CLockObject lock(m_mutex);
- m_bDisableCallbacks = disable;
-}
-
cec_adapter_message_state CRPiCECAdapterCommunication::Write(const cec_command &data, bool &bRetry, uint8_t iLineTimeout, bool bIsReply)
{
VC_CEC_ERROR_T vcAnswer;
uint32_t iTimeout = (data.transmit_timeout ? data.transmit_timeout : iLineTimeout*1000);
- cec_adapter_message_state rc;
-
- // to send a real POLL (dest & source LA the same - eg 11), VC
- // needs us to be in passivemode(we are) and with no actual LA
- // registered
- // libCEC sends 'true' POLLs only when at LA choosing process.
- // any other POLLing of devices happens with regular 'empty'
- // msg (just header, no OPCODE) with actual LA as source to X.
- // for us this means, that libCEC already registered tmp LA
- // (0xf, 0xe respectively) before it calls us for LA POLLing.
- //
- // that means - unregistering any A from adapter, _while_
- // ignoring callbacks (and especially not reporting the
- // subsequent actions generated from VC layer - like
- // LA change to 0xf ...)
- //
- // calling vc_cec_release_logical_address() over and over is
- // fine.
- // once libCEC gets NACK on tested A, it calls RegisterLogicalAddress()
- // on it's own - so we don't need to take care of re-registering
- if (!data.opcode_set && data.initiator == data.destination)
- {
- SetDisableCallback(true);
-
- vc_cec_release_logical_address();
- // accept nothing else than NACK or ACK, repeat until this happens
- while (ADAPTER_MESSAGE_STATE_WAITING_TO_BE_SENT ==
- (rc = m_queue->Write(data, bRetry, iTimeout, bIsReply, vcAnswer)));
-
- SetDisableCallback(false);
- return rc;
- }
- rc = m_queue->Write(data, bRetry, iTimeout, bIsReply, vcAnswer);
+ cec_adapter_message_state rc = m_queue->Write(data, bRetry, iTimeout, bIsReply, vcAnswer);
#ifdef CEC_DEBUGGING
LIB_CEC->AddLog(CEC_LOG_DEBUG, "sending data: result %s", ToString(vcAnswer));
#endif
diff --git a/src/libcec/adapter/RPi/RPiCECAdapterCommunication.h b/src/libcec/adapter/RPi/RPiCECAdapterCommunication.h
index 0cc1288..47e12e9 100644
--- a/src/libcec/adapter/RPi/RPiCECAdapterCommunication.h
+++ b/src/libcec/adapter/RPi/RPiCECAdapterCommunication.h
@@ -100,7 +100,6 @@ namespace CEC
bool UnregisterLogicalAddress(void);
bool RegisterLogicalAddress(const cec_logical_address address, uint32_t iTimeoutMs = CEC_DEFAULT_CONNECT_TIMEOUT);
int InitHostCEC(void);
- void SetDisableCallback(const bool disable);
bool m_bInitialised; /**< true when the connection is initialised, false otherwise */
std::string m_strError; /**< current error message */
@@ -114,8 +113,6 @@ namespace CEC
VCHI_CONNECTION_T * m_vchi_connection;
cec_logical_address m_previousLogicalAddress;
bool m_bLogicalAddressRegistered;
-
- bool m_bDisableCallbacks;
};
};
diff --git a/src/libcec/adapter/RPi/RPiCECAdapterMessageQueue.cpp b/src/libcec/adapter/RPi/RPiCECAdapterMessageQueue.cpp
index 08e7d51..5f29e4c 100644
--- a/src/libcec/adapter/RPi/RPiCECAdapterMessageQueue.cpp
+++ b/src/libcec/adapter/RPi/RPiCECAdapterMessageQueue.cpp
@@ -53,13 +53,10 @@ using namespace P8PLATFORM;
#define LIB_CEC m_com->m_callback->GetLib()
-// initialise new msg with unsuccesfull status, also
-// set default return state to "UNKNOWN" - instead
-// of NACK (which has special meaning for dev POLLing)
CRPiCECAdapterMessageQueueEntry::CRPiCECAdapterMessageQueueEntry(CRPiCECAdapterMessageQueue *queue, const cec_command &command) :
m_queue(queue),
m_command(command),
- m_retval(VC_CEC_ERROR_BUSY),
+ m_retval(VC_CEC_ERROR_NO_ACK),
m_bSucceeded(false)
{
@@ -77,7 +74,7 @@ bool CRPiCECAdapterMessageQueueEntry::MessageReceived(cec_opcode opcode, cec_log
m_command.initiator == initiator &&
m_command.destination == destination)
||
- (!m_command.opcode_set &&
+ (!m_command.opcode_set &&
m_command.destination == destination))
{
CLockObject lock(m_mutex);
@@ -133,27 +130,6 @@ uint32_t CRPiCECAdapterMessageQueueEntry::Result() const
cec_adapter_message_state CRPiCECAdapterMessageQueue::Write(const cec_command &command, bool &bRetry, uint32_t iLineTimeout, bool bIsReply, VC_CEC_ERROR_T &vcReply)
{
- // handle POLL (msg like '11') in a special way - the way it was
- // originally designed by BCM, expected to happen and documented
- // in API docs (/opt/vc/includes)
- // due to often (more than 20% test cases - CEC bus with 8 devices)
- // irregularities on returned status, repeat until we get SAME
- // result twice in a row
- if (!command.opcode_set && command.destination == command.initiator)
- {
- int iReturnPrev = -1;
- int iReturn = 0;
-
- while((iReturn = vc_cec_poll_address((CEC_AllDevices_T)command.destination)) != iReturnPrev)
- iReturnPrev = iReturn;
- if (iReturn == 0)
- return ADAPTER_MESSAGE_STATE_SENT_ACKED;
- else if (iReturn > 0)
- return ADAPTER_MESSAGE_STATE_SENT_NOT_ACKED;
- else
- return ADAPTER_MESSAGE_STATE_WAITING_TO_BE_SENT;
- }
-
CRPiCECAdapterMessageQueueEntry *entry = new CRPiCECAdapterMessageQueueEntry(this, command);
uint64_t iEntryId(0);
/* add to the wait for ack queue */
@@ -216,9 +192,8 @@ cec_adapter_message_state CRPiCECAdapterMessageQueue::Write(const cec_command &c
bRetry = false;
if (iReturn != VCHIQ_SUCCESS)
{
- LIB_CEC->AddLog(CEC_LOG_DEBUG, "sending command '%s' failed (%d)", CCECTypeUtils::ToString(command.opcode), iReturn);
- delete entry;
- m_messages.erase(iEntryId);
+ LIB_CEC->AddLog(CEC_LOG_DEBUG, "sending command '%s' failed (%d)", command.opcode_set ? CCECTypeUtils::ToString(command.opcode) : "POLL", iReturn);
+ delete (entry);
return ADAPTER_MESSAGE_STATE_ERROR;
}
@@ -238,9 +213,12 @@ cec_adapter_message_state CRPiCECAdapterMessageQueue::Write(const cec_command &c
}
else
{
- bRetry = true;
- LIB_CEC->AddLog(CEC_LOG_DEBUG, "command '%s' timeout", CCECTypeUtils::ToString(command.opcode));
- CEvent::Sleep(CEC_DEFAULT_TRANSMIT_RETRY_WAIT);
+ if (command.opcode_set)
+ {
+ bRetry = true;
+ LIB_CEC->AddLog(CEC_LOG_DEBUG, "command '%s' timeout", command.opcode_set ? CCECTypeUtils::ToString(command.opcode) : "POLL");
+ CEvent::Sleep(CEC_DEFAULT_TRANSMIT_RETRY_WAIT);
+ }
bReturn = ADAPTER_MESSAGE_STATE_WAITING_TO_BE_SENT;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment