repositories
/
deb_libcec.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
5559c36
)
cec: fix reconnect
author
Lars Op den Kamp
<lars@opdenkamp.eu>
Wed, 5 Oct 2011 21:14:12 +0000
(23:14 +0200)
committer
Lars Op den Kamp
<lars@opdenkamp.eu>
Wed, 5 Oct 2011 21:14:12 +0000
(23:14 +0200)
src/lib/AdapterCommunication.cpp
patch
|
blob
|
blame
|
history
src/lib/CECProcessor.cpp
patch
|
blob
|
blame
|
history
src/lib/LibCEC.cpp
patch
|
blob
|
blame
|
history
src/testclient/main.cpp
patch
|
blob
|
blame
|
history
diff --git
a/src/lib/AdapterCommunication.cpp
b/src/lib/AdapterCommunication.cpp
index 4b0bcdd1b238ac26aa7882a8b4ebae1c62de90da..ae1a4e451c288fd4820cc3527efaf4084d67f20b 100644
(file)
--- a/
src/lib/AdapterCommunication.cpp
+++ b/
src/lib/AdapterCommunication.cpp
@@
-40,6
+40,7
@@
using namespace std;
using namespace CEC;
CAdapterCommunication::CAdapterCommunication(CLibCEC *controller) :
using namespace CEC;
CAdapterCommunication::CAdapterCommunication(CLibCEC *controller) :
+ m_port(NULL),
m_controller(controller),
m_inbuf(NULL),
m_iInbufSize(0),
m_controller(controller),
m_inbuf(NULL),
m_iInbufSize(0),
@@
-52,16
+53,19
@@
CAdapterCommunication::CAdapterCommunication(CLibCEC *controller) :
CAdapterCommunication::~CAdapterCommunication(void)
{
CAdapterCommunication::~CAdapterCommunication(void)
{
- StopThread();
- m_port->Close();
- delete m_port;
- m_port = NULL;
+ Close();
+
+ if (m_port)
+ {
+ delete m_port;
+ m_port = NULL;
+ }
}
bool CAdapterCommunication::Open(const char *strPort, uint16_t iBaudRate /* = 38400 */, uint64_t iTimeoutMs /* = 10000 */)
{
CLockObject lock(&m_commMutex);
}
bool CAdapterCommunication::Open(const char *strPort, uint16_t iBaudRate /* = 38400 */, uint64_t iTimeoutMs /* = 10000 */)
{
CLockObject lock(&m_commMutex);
- if (m_bStarted)
+ if (m_bStarted
|| !m_port
)
return false;
if (!m_port->Open(strPort, iBaudRate))
return false;
if (!m_port->Open(strPort, iBaudRate))
@@
-78,14
+82,12
@@
bool CAdapterCommunication::Open(const char *strPort, uint16_t iBaudRate /* = 38
uint8_t buff[1024];
m_port->Read(buff, sizeof(buff), 50);
uint8_t buff[1024];
m_port->Read(buff, sizeof(buff), 50);
- CCondition::Sleep(CEC_SETTLE_DOWN_TIME);
-
- m_bStop = false;
- m_bStarted = true;
+ Sleep(CEC_SETTLE_DOWN_TIME);
if (CreateThread())
{
m_controller->AddLog(CEC_LOG_DEBUG, "reader thread created");
if (CreateThread())
{
m_controller->AddLog(CEC_LOG_DEBUG, "reader thread created");
+ m_bStarted = true;
return true;
}
else
return true;
}
else
@@
-98,14
+100,20
@@
bool CAdapterCommunication::Open(const char *strPort, uint16_t iBaudRate /* = 38
void CAdapterCommunication::Close(void)
{
void CAdapterCommunication::Close(void)
{
+ CLockObject lock(&m_commMutex);
+ if (m_port)
+ m_port->Close();
+
StopThread();
StopThread();
- m_port->Close();
}
void *CAdapterCommunication::Process(void)
{
}
void *CAdapterCommunication::Process(void)
{
+ m_controller->AddLog(CEC_LOG_DEBUG, "communication thread started");
+
while (!m_bStop)
{
while (!m_bStop)
{
+ CLockObject lock(&m_commMutex);
if (!ReadFromDevice(250))
{
m_bStarted = false;
if (!ReadFromDevice(250))
{
m_bStarted = false;
@@
-113,10
+121,12
@@
void *CAdapterCommunication::Process(void)
}
if (!m_bStop)
}
if (!m_bStop)
- CCondition::Sleep(50);
+ {
+ lock.Leave();
+ Sleep(50);
+ }
}
}
- CLockObject lock(&m_commMutex);
m_bStarted = false;
return NULL;
}
m_bStarted = false;
return NULL;
}
@@
-124,12
+134,10
@@
void *CAdapterCommunication::Process(void)
bool CAdapterCommunication::ReadFromDevice(uint64_t iTimeout)
{
uint8_t buff[1024];
bool CAdapterCommunication::ReadFromDevice(uint64_t iTimeout)
{
uint8_t buff[1024];
- CLockObject lock(&m_commMutex);
if (!m_port)
return false;
int32_t iBytesRead = m_port->Read(buff, sizeof(buff), iTimeout);
if (!m_port)
return false;
int32_t iBytesRead = m_port->Read(buff, sizeof(buff), iTimeout);
- lock.Leave();
if (iBytesRead < 0 || iBytesRead > 256)
{
CStdString strError;
if (iBytesRead < 0 || iBytesRead > 256)
{
CStdString strError;
@@
-172,7
+180,7
@@
bool CAdapterCommunication::Write(const cec_frame &data)
m_controller->AddLog(CEC_LOG_DEBUG, "command sent");
m_controller->AddLog(CEC_LOG_DEBUG, "command sent");
-
CCondition::
Sleep((int) data.size() * 24 /*data*/ + 5 /*start bit (4.5 ms)*/ + 50 /* to be on the safe side */);
+ Sleep((int) data.size() * 24 /*data*/ + 5 /*start bit (4.5 ms)*/ + 50 /* to be on the safe side */);
return true;
}
return true;
}
diff --git
a/src/lib/CECProcessor.cpp
b/src/lib/CECProcessor.cpp
index 2133080c8d461b678a139b1e149194604c41c767..6750c87dba52a1a2c9dd8111755a51cb11c9bec4 100644
(file)
--- a/
src/lib/CECProcessor.cpp
+++ b/
src/lib/CECProcessor.cpp
@@
-95,7
+95,7
@@
void *CCECProcessor::Process(void)
if (!m_bStop)
{
m_controller->CheckKeypressTimeout();
if (!m_bStop)
{
m_controller->CheckKeypressTimeout();
-
CCondition::
Sleep(50);
+ Sleep(50);
}
}
}
}
diff --git
a/src/lib/LibCEC.cpp
b/src/lib/LibCEC.cpp
index 47554d662a921faa39637f220855f9abae552586..abc800c19cc528af2ff0029f43b6787a9f9a5625 100644
(file)
--- a/
src/lib/LibCEC.cpp
+++ b/
src/lib/LibCEC.cpp
@@
-51,6
+51,7
@@
CLibCEC::CLibCEC(const char *strDeviceName, cec_logical_address iLogicalAddress
CLibCEC::~CLibCEC(void)
{
CLibCEC::~CLibCEC(void)
{
+ Close();
delete m_cec;
m_cec = NULL;
delete m_cec;
m_cec = NULL;
@@
-61,7
+62,10
@@
CLibCEC::~CLibCEC(void)
bool CLibCEC::Open(const char *strPort, uint64_t iTimeoutMs /* = 10000 */)
{
if (!m_comm)
bool CLibCEC::Open(const char *strPort, uint64_t iTimeoutMs /* = 10000 */)
{
if (!m_comm)
+ {
+ AddLog(CEC_LOG_ERROR, "no comm port");
return false;
return false;
+ }
if (m_comm->IsOpen())
{
if (m_comm->IsOpen())
{
@@
-87,17
+91,9
@@
bool CLibCEC::Open(const char *strPort, uint64_t iTimeoutMs /* = 10000 */)
void CLibCEC::Close(void)
{
if (m_cec)
void CLibCEC::Close(void)
{
if (m_cec)
- {
m_cec->StopThread();
m_cec->StopThread();
- delete m_cec;
- m_cec = NULL;
- }
if (m_comm)
if (m_comm)
- {
m_comm->Close();
m_comm->Close();
- delete m_comm;
- m_comm = NULL;
- }
}
int CLibCEC::FindAdapters(std::vector<cec_adapter> &deviceList, const char *strDevicePath /* = NULL */)
}
int CLibCEC::FindAdapters(std::vector<cec_adapter> &deviceList, const char *strDevicePath /* = NULL */)
diff --git
a/src/testclient/main.cpp
b/src/testclient/main.cpp
index 983ba13736fff90d6b3b16c9fce8985206ead71c..813e22b4cd193501dd0f7447d26041e1f690c7e7 100644
(file)
--- a/
src/testclient/main.cpp
+++ b/
src/testclient/main.cpp
@@
-240,7
+240,6
@@
int main (int argc, char *argv[])
}
cout << "cec device opened" << endl;
}
cout << "cec device opened" << endl;
- usleep(CEC_SETTLE_DOWN_TIME);
parser->PowerOnDevices(CECDEVICE_TV);
flush_log(parser);
parser->PowerOnDevices(CECDEVICE_TV);
flush_log(parser);
@@
-289,6
+288,12
@@
int main (int argc, char *argv[])
{
parser->StartBootloader();
}
{
parser->StartBootloader();
}
+ else if (command == "r")
+ {
+ parser->Close();
+ parser->Open(strPort.c_str());
+ parser->SetActiveView();
+ }
else if (command == "h" || command == "help")
{
show_console_help();
else if (command == "h" || command == "help")
{
show_console_help();