| 157 | } |
| 158 | |
| 159 | bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint32_t iTimeoutMs, bool bStartListening /* = true */) |
| 160 | { |
| 161 | bool bReturn(false); |
| 162 | CTimeout timeout(iTimeoutMs > 0 ? iTimeoutMs : CEC_DEFAULT_TRANSMIT_WAIT); |
| 163 | |
| 164 | // ensure that a previous connection is closed |
| 165 | if (m_communication) |
| 166 | Close(); |
| 167 | |
| 168 | // reset all member to the initial state |
| 169 | ResetMembers(); |
| 170 | |
| 171 | // check whether the Close() method deleted any previous connection |
| 172 | if (m_communication) |
| 173 | { |
| 174 | m_libcec->AddLog(CEC_LOG_ERROR, "previous connection could not be closed"); |
| 175 | return bReturn; |
| 176 | } |
| 177 | |
| 178 | // create a new connection |
| 179 | m_communication = CAdapterFactory(this->m_libcec).GetInstance(strPort, iBaudRate); |
| 180 | |
| 181 | // open a new connection |
| 182 | unsigned iConnectTry(0); |
| 183 | while (timeout.TimeLeft() > 0 && (bReturn = m_communication->Open((timeout.TimeLeft() / CEC_CONNECT_TRIES), false, bStartListening)) == false) |
| 184 | { |
| 185 | m_libcec->AddLog(CEC_LOG_ERROR, "could not open a connection (try %d)", ++iConnectTry); |
| 186 | m_communication->Close(); |
| 187 | CEvent::Sleep(CEC_DEFAULT_CONNECT_RETRY_WAIT); |
| 188 | } |
| 189 | |
| 190 | m_libcec->AddLog(CEC_LOG_NOTICE, "connection opened"); |
| 191 | |
| 192 | // mark as initialised |
| 193 | SetCECInitialised(true); |
| 194 | |
| 195 | return bReturn; |
| 196 | } |
| 197 | |
| 198 | bool CCECProcessor::CECInitialised(void) |
| 199 | { |
nothing calls this directly
no test coverage detected