Commit | Line | Data |
---|---|---|
abbca718 LOK |
1 | /* |
2 | * This file is part of the libCEC(R) library. | |
3 | * | |
4 | * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved. | |
5 | * libCEC(R) is an original work, containing original code. | |
6 | * | |
7 | * libCEC(R) is a trademark of Pulse-Eight Limited. | |
8 | * | |
9 | * This program is dual-licensed; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
22 | * | |
23 | * | |
24 | * Alternatively, you can license this library under a commercial license, | |
25 | * please contact Pulse-Eight Licensing for more information. | |
26 | * | |
27 | * For more information contact: | |
28 | * Pulse-Eight Licensing <license@pulse-eight.com> | |
29 | * http://www.pulse-eight.com/ | |
30 | * http://www.pulse-eight.net/ | |
31 | */ | |
32 | ||
2abe74eb | 33 | #include "CECProcessor.h" |
abbca718 | 34 | |
2abe74eb | 35 | #include "AdapterCommunication.h" |
eafa9d46 | 36 | #include "devices/CECBusDevice.h" |
2abe74eb | 37 | #include "LibCEC.h" |
abbca718 | 38 | #include "util/StdString.h" |
b9187cc6 | 39 | #include "platform/timeutils.h" |
abbca718 LOK |
40 | |
41 | using namespace CEC; | |
42 | using namespace std; | |
43 | ||
2b4d8297 | 44 | CCECProcessor::CCECProcessor(CLibCEC *controller, CAdapterCommunication *serComm, const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS*/) : |
179efe86 | 45 | m_iLogicalAddress(iLogicalAddress), |
2abe74eb LOK |
46 | m_strDeviceName(strDeviceName), |
47 | m_communication(serComm), | |
8b7e5ff6 | 48 | m_controller(controller), |
179efe86 LOK |
49 | m_bMonitor(false), |
50 | m_bLogicalAddressSet(false) | |
abbca718 | 51 | { |
7ea0d558 | 52 | for (int iPtr = 0; iPtr < 16; iPtr++) |
09c10b66 | 53 | m_busDevices[iPtr] = new CCECBusDevice(this, (cec_logical_address) iPtr, iPtr == iLogicalAddress ? iPhysicalAddress : 0); |
abbca718 LOK |
54 | } |
55 | ||
2abe74eb | 56 | CCECProcessor::~CCECProcessor(void) |
abbca718 | 57 | { |
8b0ee2cc | 58 | m_startCondition.Broadcast(); |
2abe74eb LOK |
59 | StopThread(); |
60 | m_communication = NULL; | |
61 | m_controller = NULL; | |
d1998c7b LOK |
62 | for (unsigned int iPtr = 0; iPtr < 16; iPtr++) |
63 | delete m_busDevices[iPtr]; | |
abbca718 LOK |
64 | } |
65 | ||
2abe74eb | 66 | bool CCECProcessor::Start(void) |
abbca718 | 67 | { |
8b0ee2cc | 68 | CLockObject lock(&m_mutex); |
2abe74eb | 69 | if (!m_communication || !m_communication->IsOpen()) |
13fd6a66 LOK |
70 | { |
71 | m_controller->AddLog(CEC_LOG_ERROR, "connection is closed"); | |
a8f0bd18 | 72 | return false; |
13fd6a66 | 73 | } |
abbca718 | 74 | |
a8f0bd18 | 75 | if (!SetLogicalAddress(m_iLogicalAddress)) |
abbca718 | 76 | { |
2abe74eb | 77 | m_controller->AddLog(CEC_LOG_ERROR, "could not set the logical address"); |
a8f0bd18 | 78 | return false; |
abbca718 LOK |
79 | } |
80 | ||
60fa4578 | 81 | if (CreateThread()) |
8b0ee2cc LOK |
82 | { |
83 | if (!m_startCondition.Wait(&m_mutex)) | |
84 | { | |
85 | m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread"); | |
86 | return false; | |
87 | } | |
a8f0bd18 | 88 | return true; |
8b0ee2cc | 89 | } |
a8f0bd18 | 90 | else |
2abe74eb | 91 | m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread"); |
abbca718 | 92 | |
a8f0bd18 | 93 | return false; |
abbca718 LOK |
94 | } |
95 | ||
2abe74eb | 96 | void *CCECProcessor::Process(void) |
f99bc831 | 97 | { |
8b0ee2cc LOK |
98 | { |
99 | CLockObject lock(&m_mutex); | |
100 | m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started"); | |
101 | m_startCondition.Signal(); | |
102 | } | |
abbca718 | 103 | |
271e7778 LOK |
104 | cec_command command; |
105 | CCECAdapterMessage msg; | |
106 | CCECAdapterMessagePtr msgPtr; | |
9dee1670 | 107 | |
b9eea66d LOK |
108 | m_communication->SetAckMask(0x1 << (uint8_t)m_iLogicalAddress); |
109 | ||
13fd6a66 | 110 | while (!IsStopped()) |
abbca718 | 111 | { |
60fa4578 | 112 | bool bParseFrame(false); |
9dee1670 | 113 | command.clear(); |
76321de4 LOK |
114 | msg.clear(); |
115 | ||
60fa4578 LOK |
116 | { |
117 | CLockObject lock(&m_mutex); | |
271e7778 LOK |
118 | if (m_frameBuffer.Pop(msgPtr)) |
119 | bParseFrame = ParseMessage(msgPtr); | |
120 | else if (m_communication->IsOpen() && m_communication->Read(msg, 50)) | |
121 | { | |
122 | msgPtr = CCECAdapterMessagePtr(new CCECAdapterMessage(msg)); | |
123 | bParseFrame = ParseMessage(msgPtr); | |
124 | } | |
76321de4 | 125 | |
78e8010a | 126 | bParseFrame &= !IsStopped(); |
76321de4 | 127 | if (bParseFrame) |
9dee1670 | 128 | command = m_currentframe; |
60fa4578 LOK |
129 | } |
130 | ||
13fd6a66 | 131 | if (bParseFrame) |
9dee1670 | 132 | ParseCommand(command); |
abbca718 | 133 | |
13fd6a66 LOK |
134 | m_controller->CheckKeypressTimeout(); |
135 | ||
0ab58650 LOK |
136 | for (unsigned int iDevicePtr = 0; iDevicePtr < 16; iDevicePtr++) |
137 | m_busDevices[iDevicePtr]->PollVendorId(); | |
138 | ||
13fd6a66 | 139 | if (!IsStopped()) |
d5bffd3c | 140 | Sleep(5); |
abbca718 LOK |
141 | } |
142 | ||
60fa4578 | 143 | return NULL; |
abbca718 LOK |
144 | } |
145 | ||
2abe74eb | 146 | bool CCECProcessor::SetActiveView(void) |
abbca718 | 147 | { |
60fa4578 | 148 | if (!IsRunning()) |
f99bc831 LOK |
149 | return false; |
150 | ||
cc60ab1c LOK |
151 | if (m_iLogicalAddress != CECDEVICE_UNKNOWN && m_busDevices[m_iLogicalAddress]) |
152 | return m_busDevices[m_iLogicalAddress]->BroadcastActiveView(); | |
153 | return false; | |
abbca718 LOK |
154 | } |
155 | ||
2abe74eb | 156 | bool CCECProcessor::SetInactiveView(void) |
abbca718 | 157 | { |
60fa4578 | 158 | if (!IsRunning()) |
f99bc831 LOK |
159 | return false; |
160 | ||
cc60ab1c LOK |
161 | if (m_iLogicalAddress != CECDEVICE_UNKNOWN && m_busDevices[m_iLogicalAddress]) |
162 | return m_busDevices[m_iLogicalAddress]->BroadcastInactiveView(); | |
163 | return false; | |
abbca718 LOK |
164 | } |
165 | ||
9dee1670 | 166 | void CCECProcessor::LogOutput(const cec_command &data) |
abbca718 | 167 | { |
1d3ca3de LOK |
168 | CStdString strTx; |
169 | strTx.Format("<< %02x:%02x", ((uint8_t)data.initiator << 4) + (uint8_t)data.destination, (uint8_t)data.opcode); | |
9dee1670 | 170 | |
06a1f7ce | 171 | for (uint8_t iPtr = 0; iPtr < data.parameters.size; iPtr++) |
1d3ca3de LOK |
172 | strTx.AppendFormat(":%02x", data.parameters[iPtr]); |
173 | m_controller->AddLog(CEC_LOG_TRAFFIC, strTx.c_str()); | |
9dee1670 | 174 | } |
2abe74eb | 175 | |
179efe86 | 176 | bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress /* = CECDEVICE_UNKNOWN */) |
abbca718 | 177 | { |
179efe86 | 178 | if (iLogicalAddress != CECDEVICE_UNKNOWN) |
06775107 LOK |
179 | { |
180 | CStdString strLog; | |
181 | strLog.Format("<< setting logical address to %1x", iLogicalAddress); | |
182 | m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str()); | |
06775107 | 183 | m_iLogicalAddress = iLogicalAddress; |
179efe86 | 184 | m_bLogicalAddressSet = false; |
06775107 | 185 | } |
2abe74eb | 186 | |
179efe86 LOK |
187 | if (!m_bLogicalAddressSet && m_iLogicalAddress != CECDEVICE_UNKNOWN) |
188 | m_bLogicalAddressSet = m_communication && m_communication->SetAckMask(0x1 << (uint8_t)m_iLogicalAddress); | |
189 | ||
190 | return m_bLogicalAddressSet; | |
abbca718 | 191 | } |
825ddb96 | 192 | |
2492216a LOK |
193 | bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress) |
194 | { | |
cc60ab1c LOK |
195 | if (m_iLogicalAddress != CECDEVICE_UNKNOWN && m_busDevices[m_iLogicalAddress]) |
196 | { | |
197 | m_busDevices[m_iLogicalAddress]->SetPhysicalAddress(iPhysicalAddress); | |
198 | return m_busDevices[m_iLogicalAddress]->BroadcastActiveView(); | |
199 | } | |
200 | return false; | |
1969b140 LOK |
201 | } |
202 | ||
8b7e5ff6 LOK |
203 | bool CCECProcessor::SwitchMonitoring(bool bEnable) |
204 | { | |
205 | CStdString strLog; | |
206 | strLog.Format("== %s monitoring mode ==", bEnable ? "enabling" : "disabling"); | |
207 | m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str()); | |
208 | ||
209 | m_bMonitor = bEnable; | |
210 | if (bEnable) | |
211 | return m_communication && m_communication->SetAckMask(0); | |
212 | else | |
213 | return m_communication && m_communication->SetAckMask(0x1 << (uint8_t)m_iLogicalAddress); | |
214 | } | |
215 | ||
6a1c0009 LOK |
216 | cec_version CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress) |
217 | { | |
218 | return m_busDevices[iAddress]->GetCecVersion(); | |
219 | } | |
220 | ||
a3269a0a LOK |
221 | bool CCECProcessor::GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language) |
222 | { | |
cc60ab1c LOK |
223 | if (m_busDevices[iAddress]) |
224 | { | |
225 | *language = m_busDevices[iAddress]->GetMenuLanguage(); | |
226 | return (strcmp(language->language, "???") == 0); | |
227 | } | |
228 | return false; | |
a3269a0a LOK |
229 | } |
230 | ||
44c74256 LOK |
231 | uint64_t CCECProcessor::GetDeviceVendorId(cec_logical_address iAddress) |
232 | { | |
cc60ab1c LOK |
233 | if (m_busDevices[iAddress]) |
234 | return m_busDevices[iAddress]->GetVendorId(); | |
235 | return false; | |
44c74256 LOK |
236 | } |
237 | ||
e55f3f70 LOK |
238 | cec_power_status CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddress) |
239 | { | |
cc60ab1c LOK |
240 | if (m_busDevices[iAddress]) |
241 | return m_busDevices[iAddress]->GetPowerStatus(); | |
242 | return CEC_POWER_STATUS_UNKNOWN; | |
e55f3f70 LOK |
243 | } |
244 | ||
8d84e2c0 | 245 | bool CCECProcessor::Transmit(const cec_command &data) |
825ddb96 | 246 | { |
179efe86 LOK |
247 | SetLogicalAddress(); |
248 | ||
7ea0d558 | 249 | bool bReturn(false); |
13929cff LOK |
250 | LogOutput(data); |
251 | ||
5a1e87c8 | 252 | CCECAdapterMessagePtr output(new CCECAdapterMessage(data)); |
13929cff | 253 | |
2abe74eb | 254 | CLockObject lock(&m_mutex); |
eb35e4ca LOK |
255 | { |
256 | CLockObject msgLock(&output->mutex); | |
257 | if (!m_communication || !m_communication->Write(output)) | |
258 | return bReturn; | |
259 | else | |
0e31a62c | 260 | { |
e4613795 | 261 | output->condition.Wait(&output->mutex, 1000); |
0e31a62c LOK |
262 | if (output->state != ADAPTER_MESSAGE_STATE_SENT) |
263 | { | |
264 | m_controller->AddLog(CEC_LOG_ERROR, "command was not sent"); | |
265 | return bReturn; | |
266 | } | |
267 | } | |
2abe74eb | 268 | |
cd505625 LOK |
269 | if (data.ack_timeout > 0) |
270 | { | |
271 | bool bError(false); | |
272 | if ((bReturn = WaitForAck(&bError, output->size(), data.ack_timeout)) == false) | |
273 | m_controller->AddLog(CEC_LOG_ERROR, "did not receive ack"); | |
274 | } | |
275 | else | |
276 | { | |
277 | bReturn = true; | |
278 | } | |
2abe74eb LOK |
279 | } |
280 | ||
7ea0d558 | 281 | return bReturn; |
825ddb96 | 282 | } |
abbca718 | 283 | |
2abe74eb | 284 | void CCECProcessor::TransmitAbort(cec_logical_address address, cec_opcode opcode, ECecAbortReason reason /* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */) |
abbca718 | 285 | { |
9dee1670 LOK |
286 | m_controller->AddLog(CEC_LOG_DEBUG, "<< transmitting abort message"); |
287 | ||
06a1f7ce LOK |
288 | cec_command command; |
289 | cec_command::format(command, m_iLogicalAddress, address, CEC_OPCODE_FEATURE_ABORT); | |
9dee1670 LOK |
290 | command.parameters.push_back((uint8_t)opcode); |
291 | command.parameters.push_back((uint8_t)reason); | |
292 | ||
293 | Transmit(command); | |
abbca718 LOK |
294 | } |
295 | ||
7ea0d558 | 296 | bool CCECProcessor::WaitForAck(bool *bError, uint8_t iLength, uint32_t iTimeout /* = 1000 */) |
abbca718 | 297 | { |
7ea0d558 LOK |
298 | bool bTransmitSucceeded = false; |
299 | uint8_t iPacketsLeft(iLength / 4); | |
050df0f9 | 300 | *bError = false; |
abbca718 LOK |
301 | |
302 | int64_t iNow = GetTimeMs(); | |
25701fa6 | 303 | int64_t iTargetTime = iNow + (uint64_t) iTimeout; |
abbca718 | 304 | |
78e8010a | 305 | while (!bTransmitSucceeded && !*bError && (iTimeout == 0 || iNow < iTargetTime)) |
abbca718 | 306 | { |
220537f2 | 307 | CCECAdapterMessage msg; |
25701fa6 | 308 | |
06a1f7ce | 309 | if (!m_communication->Read(msg, iTimeout > 0 ? (int32_t)(iTargetTime - iNow) : 1000)) |
abbca718 | 310 | { |
abbca718 | 311 | iNow = GetTimeMs(); |
5d38b0b6 LOK |
312 | continue; |
313 | } | |
314 | ||
7ea0d558 LOK |
315 | switch(msg.message()) |
316 | { | |
317 | case MSGCODE_TIMEOUT_ERROR: | |
318 | case MSGCODE_HIGH_ERROR: | |
319 | case MSGCODE_LOW_ERROR: | |
320 | { | |
321 | CStdString logStr; | |
322 | if (msg.message() == MSGCODE_TIMEOUT_ERROR) | |
323 | logStr = "MSGCODE_TIMEOUT"; | |
324 | else if (msg.message() == MSGCODE_HIGH_ERROR) | |
325 | logStr = "MSGCODE_HIGH_ERROR"; | |
326 | else | |
327 | logStr = "MSGCODE_LOW_ERROR"; | |
328 | ||
329 | int iLine = (msg.size() >= 3) ? (msg[1] << 8) | (msg[2]) : 0; | |
330 | uint32_t iTime = (msg.size() >= 7) ? (msg[3] << 24) | (msg[4] << 16) | (msg[5] << 8) | (msg[6]) : 0; | |
331 | logStr.AppendFormat(" line:%i", iLine); | |
332 | logStr.AppendFormat(" time:%u", iTime); | |
333 | m_controller->AddLog(CEC_LOG_WARNING, logStr.c_str()); | |
334 | *bError = true; | |
335 | } | |
336 | break; | |
337 | case MSGCODE_COMMAND_ACCEPTED: | |
338 | m_controller->AddLog(CEC_LOG_DEBUG, "MSGCODE_COMMAND_ACCEPTED"); | |
339 | iPacketsLeft--; | |
340 | break; | |
341 | case MSGCODE_TRANSMIT_SUCCEEDED: | |
342 | m_controller->AddLog(CEC_LOG_DEBUG, "MSGCODE_TRANSMIT_SUCCEEDED"); | |
343 | bTransmitSucceeded = (iPacketsLeft == 0); | |
344 | *bError = !bTransmitSucceeded; | |
345 | break; | |
346 | case MSGCODE_RECEIVE_FAILED: | |
347 | m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_RECEIVE_FAILED"); | |
348 | *bError = true; | |
349 | break; | |
350 | case MSGCODE_COMMAND_REJECTED: | |
351 | m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_COMMAND_REJECTED"); | |
352 | *bError = true; | |
353 | break; | |
354 | case MSGCODE_TRANSMIT_FAILED_LINE: | |
355 | m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_LINE"); | |
356 | *bError = true; | |
357 | break; | |
358 | case MSGCODE_TRANSMIT_FAILED_ACK: | |
359 | m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_ACK"); | |
360 | *bError = true; | |
361 | break; | |
362 | case MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA: | |
363 | m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA"); | |
364 | *bError = true; | |
365 | break; | |
366 | case MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE: | |
367 | m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE"); | |
368 | *bError = true; | |
369 | break; | |
370 | default: | |
271e7778 LOK |
371 | CCECAdapterMessagePtr msgPtr = CCECAdapterMessagePtr(new CCECAdapterMessage(msg)); |
372 | m_frameBuffer.Push(msgPtr); | |
7ea0d558 LOK |
373 | break; |
374 | } | |
375 | ||
5d38b0b6 | 376 | iNow = GetTimeMs(); |
abbca718 LOK |
377 | } |
378 | ||
78e8010a | 379 | return bTransmitSucceeded && !*bError; |
abbca718 LOK |
380 | } |
381 | ||
271e7778 | 382 | bool CCECProcessor::ParseMessage(CCECAdapterMessagePtr msg) |
abbca718 | 383 | { |
7ea0d558 | 384 | bool bEom = false; |
60fa4578 | 385 | |
271e7778 | 386 | if (msg->empty()) |
7ea0d558 | 387 | return bEom; |
abbca718 LOK |
388 | |
389 | CStdString logStr; | |
abbca718 | 390 | |
271e7778 | 391 | switch(msg->message()) |
abbca718 LOK |
392 | { |
393 | case MSGCODE_NOTHING: | |
2abe74eb | 394 | m_controller->AddLog(CEC_LOG_DEBUG, "MSGCODE_NOTHING"); |
abbca718 LOK |
395 | break; |
396 | case MSGCODE_TIMEOUT_ERROR: | |
397 | case MSGCODE_HIGH_ERROR: | |
398 | case MSGCODE_LOW_ERROR: | |
399 | { | |
271e7778 | 400 | if (msg->message() == MSGCODE_TIMEOUT_ERROR) |
abbca718 | 401 | logStr = "MSGCODE_TIMEOUT"; |
271e7778 | 402 | else if (msg->message() == MSGCODE_HIGH_ERROR) |
abbca718 LOK |
403 | logStr = "MSGCODE_HIGH_ERROR"; |
404 | else | |
405 | logStr = "MSGCODE_LOW_ERROR"; | |
406 | ||
271e7778 LOK |
407 | int iLine = (msg->size() >= 3) ? (msg->at(1) << 8) | (msg->at(2)) : 0; |
408 | uint32_t iTime = (msg->size() >= 7) ? (msg->at(3) << 24) | (msg->at(4) << 16) | (msg->at(5) << 8) | (msg->at(6)) : 0; | |
abbca718 LOK |
409 | logStr.AppendFormat(" line:%i", iLine); |
410 | logStr.AppendFormat(" time:%u", iTime); | |
2abe74eb | 411 | m_controller->AddLog(CEC_LOG_WARNING, logStr.c_str()); |
abbca718 LOK |
412 | } |
413 | break; | |
414 | case MSGCODE_FRAME_START: | |
415 | { | |
7ea0d558 LOK |
416 | logStr = "MSGCODE_FRAME_START"; |
417 | m_currentframe.clear(); | |
271e7778 | 418 | if (msg->size() >= 2) |
abbca718 | 419 | { |
271e7778 LOK |
420 | logStr.AppendFormat(" initiator:%u destination:%u ack:%s %s", msg->initiator(), msg->destination(), msg->ack() ? "high" : "low", msg->eom() ? "eom" : ""); |
421 | m_currentframe.initiator = msg->initiator(); | |
422 | m_currentframe.destination = msg->destination(); | |
423 | m_currentframe.ack = msg->ack(); | |
424 | m_currentframe.eom = msg->eom(); | |
abbca718 | 425 | } |
7ea0d558 | 426 | m_controller->AddLog(CEC_LOG_DEBUG, logStr.c_str()); |
abbca718 LOK |
427 | } |
428 | break; | |
429 | case MSGCODE_FRAME_DATA: | |
430 | { | |
7ea0d558 | 431 | logStr = "MSGCODE_FRAME_DATA"; |
271e7778 | 432 | if (msg->size() >= 2) |
78e8010a | 433 | { |
271e7778 | 434 | uint8_t iData = msg->at(1); |
7ea0d558 LOK |
435 | logStr.AppendFormat(" %02x", iData); |
436 | m_currentframe.push_back(iData); | |
271e7778 | 437 | m_currentframe.eom = msg->eom(); |
abbca718 | 438 | } |
7ea0d558 | 439 | m_controller->AddLog(CEC_LOG_DEBUG, logStr.c_str()); |
78e8010a | 440 | |
271e7778 | 441 | bEom = msg->eom(); |
abbca718 | 442 | } |
78e8010a LOK |
443 | break; |
444 | case MSGCODE_COMMAND_ACCEPTED: | |
445 | m_controller->AddLog(CEC_LOG_DEBUG, "MSGCODE_COMMAND_ACCEPTED"); | |
446 | break; | |
447 | case MSGCODE_TRANSMIT_SUCCEEDED: | |
448 | m_controller->AddLog(CEC_LOG_DEBUG, "MSGCODE_TRANSMIT_SUCCEEDED"); | |
78e8010a LOK |
449 | break; |
450 | case MSGCODE_RECEIVE_FAILED: | |
451 | m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_RECEIVE_FAILED"); | |
78e8010a LOK |
452 | break; |
453 | case MSGCODE_COMMAND_REJECTED: | |
454 | m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_COMMAND_REJECTED"); | |
78e8010a LOK |
455 | break; |
456 | case MSGCODE_TRANSMIT_FAILED_LINE: | |
457 | m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_LINE"); | |
78e8010a LOK |
458 | break; |
459 | case MSGCODE_TRANSMIT_FAILED_ACK: | |
460 | m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_ACK"); | |
78e8010a LOK |
461 | break; |
462 | case MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA: | |
463 | m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA"); | |
78e8010a LOK |
464 | break; |
465 | case MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE: | |
466 | m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE"); | |
abbca718 LOK |
467 | break; |
468 | default: | |
469 | break; | |
470 | } | |
7ea0d558 LOK |
471 | |
472 | return bEom; | |
abbca718 LOK |
473 | } |
474 | ||
e9de9629 | 475 | void CCECProcessor::ParseCommand(cec_command &command) |
abbca718 | 476 | { |
e9de9629 | 477 | CStdString dataStr; |
1d3ca3de | 478 | dataStr.Format(">> %1x%1x:%02x", command.initiator, command.destination, command.opcode); |
e9de9629 LOK |
479 | for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++) |
480 | dataStr.AppendFormat(":%02x", (unsigned int)command.parameters[iPtr]); | |
1d3ca3de | 481 | m_controller->AddLog(CEC_LOG_TRAFFIC, dataStr.c_str()); |
dc113aca | 482 | |
e9de9629 LOK |
483 | if (!m_bMonitor) |
484 | m_busDevices[(uint8_t)command.initiator]->HandleCommand(command); | |
dc113aca LOK |
485 | } |
486 | ||
0f23c85c LOK |
487 | uint16_t CCECProcessor::GetPhysicalAddress(void) const |
488 | { | |
cc60ab1c LOK |
489 | if (m_iLogicalAddress != CECDEVICE_UNKNOWN && m_busDevices[m_iLogicalAddress]) |
490 | return m_busDevices[m_iLogicalAddress]->GetPhysicalAddress(); | |
491 | return false; | |
0f23c85c LOK |
492 | } |
493 | ||
e9de9629 | 494 | void CCECProcessor::SetCurrentButton(cec_user_control_code iButtonCode) |
dc113aca | 495 | { |
e9de9629 | 496 | m_controller->SetCurrentButton(iButtonCode); |
dc113aca LOK |
497 | } |
498 | ||
e9de9629 | 499 | void CCECProcessor::AddCommand(const cec_command &command) |
dc113aca | 500 | { |
e9de9629 | 501 | m_controller->AddCommand(command); |
dc113aca LOK |
502 | } |
503 | ||
e9de9629 | 504 | void CCECProcessor::AddKey(void) |
dc113aca | 505 | { |
e9de9629 | 506 | m_controller->AddKey(); |
abbca718 | 507 | } |
acec5f48 | 508 | |
e9de9629 | 509 | void CCECProcessor::AddLog(cec_log_level level, const CStdString &strMessage) |
acec5f48 | 510 | { |
e9de9629 | 511 | m_controller->AddLog(level, strMessage); |
acec5f48 | 512 | } |