repositories
/
deb_libcec.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
34d4670
)
cec: create the CAdapterCommunication instance in CCECProcessor
author
Lars Op den Kamp
<lars@opdenkamp.eu>
Sat, 3 Dec 2011 21:32:08 +0000
(22:32 +0100)
committer
Lars Op den Kamp
<lars@opdenkamp.eu>
Sun, 4 Dec 2011 02:28:18 +0000
(
03:28
+0100)
src/lib/AdapterCommunication.cpp
patch
|
blob
|
blame
|
history
src/lib/AdapterCommunication.h
patch
|
blob
|
blame
|
history
src/lib/CECProcessor.cpp
patch
|
blob
|
blame
|
history
src/lib/CECProcessor.h
patch
|
blob
|
blame
|
history
src/lib/LibCEC.cpp
patch
|
blob
|
blame
|
history
src/lib/LibCEC.h
patch
|
blob
|
blame
|
history
diff --git
a/src/lib/AdapterCommunication.cpp
b/src/lib/AdapterCommunication.cpp
index 32ceeafc02e5835be628af9a2d8e140056c838b0..e6afcf463bae80fd0cacbf2f964090fa418caaed 100644
(file)
--- a/
src/lib/AdapterCommunication.cpp
+++ b/
src/lib/AdapterCommunication.cpp
@@
-32,7
+32,7
@@
#include "AdapterCommunication.h"
#include "AdapterCommunication.h"
-#include "
LibCEC
.h"
+#include "
CECProcessor
.h"
#include "platform/serialport.h"
#include "util/StdString.h"
#include "platform/timeutils.h"
#include "platform/serialport.h"
#include "util/StdString.h"
#include "platform/timeutils.h"
@@
-237,9
+237,9
@@
void CCECAdapterMessage::push_escaped(uint8_t byte)
push_back(byte);
}
push_back(byte);
}
-CAdapterCommunication::CAdapterCommunication(C
LibCEC *controlle
r) :
+CAdapterCommunication::CAdapterCommunication(C
CECProcessor *processo
r) :
m_port(NULL),
m_port(NULL),
- m_
controller(controlle
r)
+ m_
processor(processo
r)
{
m_port = new CSerialPort;
}
{
m_port = new CSerialPort;
}
@@
-260,24
+260,24
@@
bool CAdapterCommunication::Open(const char *strPort, uint16_t iBaudRate /* = 38
CLockObject lock(&m_mutex);
if (!m_port)
{
CLockObject lock(&m_mutex);
if (!m_port)
{
- m_
controlle
r->AddLog(CEC_LOG_ERROR, "port is NULL");
+ m_
processo
r->AddLog(CEC_LOG_ERROR, "port is NULL");
return false;
}
if (IsOpen())
{
return false;
}
if (IsOpen())
{
- m_
controlle
r->AddLog(CEC_LOG_ERROR, "port is already open");
+ m_
processo
r->AddLog(CEC_LOG_ERROR, "port is already open");
}
if (!m_port->Open(strPort, iBaudRate))
{
CStdString strError;
strError.Format("error opening serial port '%s': %s", strPort, m_port->GetError().c_str());
}
if (!m_port->Open(strPort, iBaudRate))
{
CStdString strError;
strError.Format("error opening serial port '%s': %s", strPort, m_port->GetError().c_str());
- m_
controlle
r->AddLog(CEC_LOG_ERROR, strError);
+ m_
processo
r->AddLog(CEC_LOG_ERROR, strError);
return false;
}
return false;
}
- m_
controlle
r->AddLog(CEC_LOG_DEBUG, "connection opened");
+ m_
processo
r->AddLog(CEC_LOG_DEBUG, "connection opened");
//clear any input bytes
uint8_t buff[1024];
//clear any input bytes
uint8_t buff[1024];
@@
-286,12
+286,12
@@
bool CAdapterCommunication::Open(const char *strPort, uint16_t iBaudRate /* = 38
if (CreateThread())
{
m_startCondition.Wait(&m_mutex);
if (CreateThread())
{
m_startCondition.Wait(&m_mutex);
- m_
controlle
r->AddLog(CEC_LOG_DEBUG, "communication thread started");
+ m_
processo
r->AddLog(CEC_LOG_DEBUG, "communication thread started");
return true;
}
else
{
return true;
}
else
{
- m_
controlle
r->AddLog(CEC_LOG_DEBUG, "could not create a communication thread");
+ m_
processo
r->AddLog(CEC_LOG_DEBUG, "could not create a communication thread");
}
return false;
}
return false;
@@
-334,7
+334,7
@@
bool CAdapterCommunication::ReadFromDevice(uint32_t iTimeout)
{
CStdString strError;
strError.Format("error reading from serial port: %s", m_port->GetError().c_str());
{
CStdString strError;
strError.Format("error reading from serial port: %s", m_port->GetError().c_str());
- m_
controlle
r->AddLog(CEC_LOG_ERROR, strError);
+ m_
processo
r->AddLog(CEC_LOG_ERROR, strError);
return false;
}
else if (iBytesRead > 0)
return false;
}
else if (iBytesRead > 0)
@@
-366,12
+366,12
@@
void CAdapterCommunication::SendMessageToAdapter(CCECAdapterMessage *msg)
{
CStdString strError;
strError.Format("error writing to serial port: %s", m_port->GetError().c_str());
{
CStdString strError;
strError.Format("error writing to serial port: %s", m_port->GetError().c_str());
- m_
controlle
r->AddLog(CEC_LOG_ERROR, strError);
+ m_
processo
r->AddLog(CEC_LOG_ERROR, strError);
msg->state = ADAPTER_MESSAGE_STATE_ERROR;
}
else
{
msg->state = ADAPTER_MESSAGE_STATE_ERROR;
}
else
{
- m_
controlle
r->AddLog(CEC_LOG_DEBUG, "command sent");
+ m_
processo
r->AddLog(CEC_LOG_DEBUG, "command sent");
CCondition::Sleep((uint32_t) msg->size() * 24 /*data*/ + 5 /*start bit (4.5 ms)*/);
msg->state = ADAPTER_MESSAGE_STATE_SENT;
}
CCondition::Sleep((uint32_t) msg->size() * 24 /*data*/ + 5 /*start bit (4.5 ms)*/);
msg->state = ADAPTER_MESSAGE_STATE_SENT;
}
@@
-414,7
+414,7
@@
bool CAdapterCommunication::Read(CCECAdapterMessage &msg, uint32_t iTimeout)
else if (buf == MSGSTART) //we found a msgstart before msgend, this is not right, remove
{
if (msg.size() > 0)
else if (buf == MSGSTART) //we found a msgstart before msgend, this is not right, remove
{
if (msg.size() > 0)
- m_
controlle
r->AddLog(CEC_LOG_WARNING, "received MSGSTART before MSGEND, removing previous buffer contents");
+ m_
processo
r->AddLog(CEC_LOG_WARNING, "received MSGSTART before MSGEND, removing previous buffer contents");
msg.clear();
bGotStart = true;
}
msg.clear();
bGotStart = true;
}
@@
-451,7
+451,7
@@
bool CAdapterCommunication::StartBootloader(void)
if (!IsRunning())
return bReturn;
if (!IsRunning())
return bReturn;
- m_
controlle
r->AddLog(CEC_LOG_DEBUG, "starting the bootloader");
+ m_
processo
r->AddLog(CEC_LOG_DEBUG, "starting the bootloader");
CCECAdapterMessage *output = new CCECAdapterMessage;
output->push_back(MSGSTART);
CCECAdapterMessage *output = new CCECAdapterMessage;
output->push_back(MSGSTART);
@@
-471,7
+471,7
@@
bool CAdapterCommunication::PingAdapter(void)
if (!IsRunning())
return bReturn;
if (!IsRunning())
return bReturn;
- m_
controlle
r->AddLog(CEC_LOG_DEBUG, "sending ping");
+ m_
processo
r->AddLog(CEC_LOG_DEBUG, "sending ping");
CCECAdapterMessage *output = new CCECAdapterMessage;
output->push_back(MSGSTART);
CCECAdapterMessage *output = new CCECAdapterMessage;
output->push_back(MSGSTART);
diff --git
a/src/lib/AdapterCommunication.h
b/src/lib/AdapterCommunication.h
index aaa07475f4899b35516e5caebc35d13f0c06f45f..2ebffed25dbe38775a4a90f2aabdab40e05a2d09 100644
(file)
--- a/
src/lib/AdapterCommunication.h
+++ b/
src/lib/AdapterCommunication.h
@@
-81,12
+81,12
@@
namespace CEC
};
class CSerialPort;
};
class CSerialPort;
- class C
LibCEC
;
+ class C
CECProcessor
;
class CAdapterCommunication : private CThread
{
public:
class CAdapterCommunication : private CThread
{
public:
- CAdapterCommunication(C
LibCEC *controlle
r);
+ CAdapterCommunication(C
CECProcessor *processo
r);
virtual ~CAdapterCommunication();
bool Open(const char *strPort, uint16_t iBaudRate = 38400, uint32_t iTimeoutMs = 10000);
virtual ~CAdapterCommunication();
bool Open(const char *strPort, uint16_t iBaudRate = 38400, uint32_t iTimeoutMs = 10000);
@@
-108,7
+108,7
@@
namespace CEC
bool ReadFromDevice(uint32_t iTimeout);
CSerialPort * m_port;
bool ReadFromDevice(uint32_t iTimeout);
CSerialPort * m_port;
- C
LibCEC * m_controlle
r;
+ C
CECProcessor * m_processo
r;
CecBuffer<uint8_t> m_inBuffer;
CecBuffer<CCECAdapterMessage *> m_outBuffer;
CMutex m_mutex;
CecBuffer<uint8_t> m_inBuffer;
CecBuffer<CCECAdapterMessage *> m_outBuffer;
CMutex m_mutex;
diff --git
a/src/lib/CECProcessor.cpp
b/src/lib/CECProcessor.cpp
index 406ef324f2d5967b06d9adfa19984f2c7dfadfda..3eb4734757da194b2539779b0c16d6b27bcc4fbb 100644
(file)
--- a/
src/lib/CECProcessor.cpp
+++ b/
src/lib/CECProcessor.cpp
@@
-47,17
+47,17
@@
using namespace CEC;
using namespace std;
using namespace CEC;
using namespace std;
-CCECProcessor::CCECProcessor(CLibCEC *controller,
CAdapterCommunication *serComm,
const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS*/) :
+CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS*/) :
m_bStarted(false),
m_iHDMIPort(CEC_DEFAULT_HDMI_PORT),
m_iBaseDevice((cec_logical_address)CEC_DEFAULT_BASE_DEVICE),
m_lastInitiator(CECDEVICE_UNKNOWN),
m_strDeviceName(strDeviceName),
m_bStarted(false),
m_iHDMIPort(CEC_DEFAULT_HDMI_PORT),
m_iBaseDevice((cec_logical_address)CEC_DEFAULT_BASE_DEVICE),
m_lastInitiator(CECDEVICE_UNKNOWN),
m_strDeviceName(strDeviceName),
- m_communication(serComm),
m_controller(controller),
m_bMonitor(false),
m_busScan(NULL)
{
m_controller(controller),
m_bMonitor(false),
m_busScan(NULL)
{
+ m_communication = new CAdapterCommunication(this);
m_logicalAddresses.Clear();
m_logicalAddresses.Set(iLogicalAddress);
m_types.clear();
m_logicalAddresses.Clear();
m_logicalAddresses.Set(iLogicalAddress);
m_types.clear();
@@
-65,16
+65,16
@@
CCECProcessor::CCECProcessor(CLibCEC *controller, CAdapterCommunication *serComm
m_busDevices[iPtr] = new CCECBusDevice(this, (cec_logical_address) iPtr, iPtr == iLogicalAddress ? iPhysicalAddress : 0);
}
m_busDevices[iPtr] = new CCECBusDevice(this, (cec_logical_address) iPtr, iPtr == iLogicalAddress ? iPhysicalAddress : 0);
}
-CCECProcessor::CCECProcessor(CLibCEC *controller,
CAdapterCommunication *serComm,
const char *strDeviceName, const cec_device_type_list &types) :
+CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, const cec_device_type_list &types) :
m_bStarted(false),
m_iHDMIPort(CEC_DEFAULT_HDMI_PORT),
m_iBaseDevice((cec_logical_address)CEC_DEFAULT_BASE_DEVICE),
m_strDeviceName(strDeviceName),
m_types(types),
m_bStarted(false),
m_iHDMIPort(CEC_DEFAULT_HDMI_PORT),
m_iBaseDevice((cec_logical_address)CEC_DEFAULT_BASE_DEVICE),
m_strDeviceName(strDeviceName),
m_types(types),
- m_communication(serComm),
m_controller(controller),
m_bMonitor(false)
{
m_controller(controller),
m_bMonitor(false)
{
+ m_communication = new CAdapterCommunication(this);
m_logicalAddresses.Clear();
for (int iPtr = 0; iPtr < 16; iPtr++)
{
m_logicalAddresses.Clear();
for (int iPtr = 0; iPtr < 16; iPtr++)
{
@@
-120,18
+120,25
@@
CCECProcessor::~CCECProcessor(void)
m_startCondition.Broadcast();
StopThread();
m_startCondition.Broadcast();
StopThread();
+ delete m_communication;
m_communication = NULL;
m_controller = NULL;
for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
delete m_busDevices[iPtr];
}
m_communication = NULL;
m_controller = NULL;
for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
delete m_busDevices[iPtr];
}
-bool CCECProcessor::Start(
void
)
+bool CCECProcessor::Start(
const char *strPort, uint16_t iBaudRate /* = 38400 */, uint32_t iTimeoutMs /* = 10000 */
)
{
CLockObject lock(&m_mutex);
{
CLockObject lock(&m_mutex);
- if (!m_communication ||
!
m_communication->IsOpen())
+ if (!m_communication || m_communication->IsOpen())
{
{
- m_controller->AddLog(CEC_LOG_ERROR, "connection is closed");
+ m_controller->AddLog(CEC_LOG_ERROR, "connection already opened");
+ return false;
+ }
+
+ if (!m_communication->Open(strPort, iBaudRate, iTimeoutMs))
+ {
+ m_controller->AddLog(CEC_LOG_ERROR, "could not open a connection");
return false;
}
return false;
}
@@
-297,6
+304,9
@@
void *CCECProcessor::Process(void)
m_controller->CheckKeypressTimeout();
}
m_controller->CheckKeypressTimeout();
}
+ if (m_communication)
+ m_communication->Close();
+
return NULL;
}
return NULL;
}
@@
-1268,3
+1278,13
@@
void *CCECBusScan::Process(void)
}
return NULL;
}
}
return NULL;
}
+
+bool CCECProcessor::StartBootloader(void)
+{
+ return m_communication->StartBootloader();
+}
+
+bool CCECProcessor::PingAdapter(void)
+{
+ return m_communication->PingAdapter();
+}
diff --git
a/src/lib/CECProcessor.h
b/src/lib/CECProcessor.h
index 7ec9d8105857d5913a51fe2ca0fdbb8dc5db17fc..c8c8262080c7addb337a7791c18c72939ac0dcdf 100644
(file)
--- a/
src/lib/CECProcessor.h
+++ b/
src/lib/CECProcessor.h
@@
-49,11
+49,11
@@
namespace CEC
class CCECProcessor : public CThread
{
public:
class CCECProcessor : public CThread
{
public:
- CCECProcessor(CLibCEC *controller,
CAdapterCommunication *serComm,
const char *strDeviceName, cec_logical_address iLogicalAddress = CECDEVICE_PLAYBACKDEVICE1, uint16_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS);
- CCECProcessor(CLibCEC *controller,
CAdapterCommunication *serComm,
const char *strDeviceName, const cec_device_type_list &types);
+ CCECProcessor(CLibCEC *controller, const char *strDeviceName, cec_logical_address iLogicalAddress = CECDEVICE_PLAYBACKDEVICE1, uint16_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS);
+ CCECProcessor(CLibCEC *controller, const char *strDeviceName, const cec_device_type_list &types);
virtual ~CCECProcessor(void);
virtual ~CCECProcessor(void);
- virtual bool Start(
void
);
+ virtual bool Start(
const char *strPort, uint16_t iBaudRate = 38400, uint32_t iTimeoutMs = 10000
);
virtual void *Process(void);
virtual bool IsMonitoring(void) const { return m_bMonitor; }
virtual void *Process(void);
virtual bool IsMonitoring(void) const { return m_bMonitor; }
@@
-119,6
+119,9
@@
namespace CEC
virtual bool FindLogicalAddresses(void);
virtual bool SetAckMask(uint16_t iMask);
virtual bool FindLogicalAddresses(void);
virtual bool SetAckMask(uint16_t iMask);
+ virtual bool StartBootloader(void);
+ virtual bool PingAdapter(void);
+
CCECBusDevice *m_busDevices[16];
private:
CCECBusDevice *m_busDevices[16];
private:
diff --git
a/src/lib/LibCEC.cpp
b/src/lib/LibCEC.cpp
index 445798bbefd2197d62300233a8855d8103462eb7..4a63051b885ad092949e2169af6bc94df3ec53cd 100644
(file)
--- a/
src/lib/LibCEC.cpp
+++ b/
src/lib/LibCEC.cpp
@@
-47,8
+47,7
@@
CLibCEC::CLibCEC(const char *strDeviceName, cec_device_type_list types) :
m_iCurrentButton(CEC_USER_CONTROL_CODE_UNKNOWN),
m_buttontime(0)
{
m_iCurrentButton(CEC_USER_CONTROL_CODE_UNKNOWN),
m_buttontime(0)
{
- m_comm = new CAdapterCommunication(this);
- m_cec = new CCECProcessor(this, m_comm, strDeviceName, types);
+ m_cec = new CCECProcessor(this, strDeviceName, types);
}
CLibCEC::CLibCEC(const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */) :
}
CLibCEC::CLibCEC(const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */) :
@@
-56,48
+55,24
@@
CLibCEC::CLibCEC(const char *strDeviceName, cec_logical_address iLogicalAddress
m_iCurrentButton(CEC_USER_CONTROL_CODE_UNKNOWN),
m_buttontime(0)
{
m_iCurrentButton(CEC_USER_CONTROL_CODE_UNKNOWN),
m_buttontime(0)
{
- m_comm = new CAdapterCommunication(this);
- m_cec = new CCECProcessor(this, m_comm, strDeviceName, iLogicalAddress, iPhysicalAddress);
+ m_cec = new CCECProcessor(this, strDeviceName, iLogicalAddress, iPhysicalAddress);
}
CLibCEC::~CLibCEC(void)
{
Close();
delete m_cec;
}
CLibCEC::~CLibCEC(void)
{
Close();
delete m_cec;
- delete m_comm;
}
bool CLibCEC::Open(const char *strPort, uint32_t iTimeoutMs /* = 10000 */)
{
}
bool CLibCEC::Open(const char *strPort, uint32_t iTimeoutMs /* = 10000 */)
{
- if (!m_comm)
- {
- AddLog(CEC_LOG_ERROR, "no comm port");
- return false;
- }
-
- if (m_comm->IsOpen())
+ if (m_cec->IsRunning())
{
AddLog(CEC_LOG_ERROR, "connection already open");
return false;
}
{
AddLog(CEC_LOG_ERROR, "connection already open");
return false;
}
- int64_t iNow = GetTimeMs();
- int64_t iTarget = iNow + iTimeoutMs;
-
- bool bOpened(false);
- while (!bOpened && iNow < iTarget)
- {
- bOpened = m_comm->Open(strPort, 38400, iTimeoutMs);
- iNow = GetTimeMs();
- }
-
- if (!bOpened)
- {
- AddLog(CEC_LOG_ERROR, "could not open a connection");
- return false;
- }
-
- if (!m_cec->Start())
+ if (!m_cec->Start(strPort, 38400, iTimeoutMs))
{
AddLog(CEC_LOG_ERROR, "could not start CEC communications");
return false;
{
AddLog(CEC_LOG_ERROR, "could not start CEC communications");
return false;
@@
-110,8
+85,6
@@
void CLibCEC::Close(void)
{
if (m_cec)
m_cec->StopThread();
{
if (m_cec)
m_cec->StopThread();
- if (m_comm)
- m_comm->Close();
}
int8_t CLibCEC::FindAdapters(cec_adapter *deviceList, uint8_t iBufSize, const char *strDevicePath /* = NULL */)
}
int8_t CLibCEC::FindAdapters(cec_adapter *deviceList, uint8_t iBufSize, const char *strDevicePath /* = NULL */)
@@
-128,12
+101,12
@@
int8_t CLibCEC::FindAdapters(cec_adapter *deviceList, uint8_t iBufSize, const ch
bool CLibCEC::PingAdapter(void)
{
bool CLibCEC::PingAdapter(void)
{
- return m_c
omm ? m_comm
->PingAdapter() : false;
+ return m_c
ec ? m_cec
->PingAdapter() : false;
}
bool CLibCEC::StartBootloader(void)
{
}
bool CLibCEC::StartBootloader(void)
{
- return m_c
omm ? m_comm
->StartBootloader() : false;
+ return m_c
ec ? m_cec
->StartBootloader() : false;
}
bool CLibCEC::GetNextLogMessage(cec_log_message *message)
}
bool CLibCEC::GetNextLogMessage(cec_log_message *message)
diff --git
a/src/lib/LibCEC.h
b/src/lib/LibCEC.h
index e1b991bcb69c2265aa54641d8b6c273b828b55e0..a0a4ddc373cdd97fdeb2c50996acdf9a4e28d9ef 100644
(file)
--- a/
src/lib/LibCEC.h
+++ b/
src/lib/LibCEC.h
@@
-120,7
+120,6
@@
namespace CEC
cec_user_control_code m_iCurrentButton;
int64_t m_buttontime;
CCECProcessor *m_cec;
cec_user_control_code m_iCurrentButton;
int64_t m_buttontime;
CCECProcessor *m_cec;
- CAdapterCommunication *m_comm;
CecBuffer<cec_log_message> m_logBuffer;
CecBuffer<cec_keypress> m_keyBuffer;
CecBuffer<cec_command> m_commandBuffer;
CecBuffer<cec_log_message> m_logBuffer;
CecBuffer<cec_keypress> m_keyBuffer;
CecBuffer<cec_command> m_commandBuffer;