cec: give every device type it's own class
[deb_libcec.git] / src / lib / CECProcessor.cpp
CommitLineData
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"
51b2a094
LOK
37#include "devices/CECAudioSystem.h"
38#include "devices/CECPlaybackDevice.h"
39#include "devices/CECRecordingDevice.h"
40#include "devices/CECTuner.h"
41#include "devices/CECTV.h"
2abe74eb 42#include "LibCEC.h"
abbca718 43#include "util/StdString.h"
b9187cc6 44#include "platform/timeutils.h"
abbca718
LOK
45
46using namespace CEC;
47using namespace std;
48
2b4d8297 49CCECProcessor::CCECProcessor(CLibCEC *controller, CAdapterCommunication *serComm, const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS*/) :
f8513317 50 m_bStarted(false),
2abe74eb
LOK
51 m_strDeviceName(strDeviceName),
52 m_communication(serComm),
8b7e5ff6 53 m_controller(controller),
06bfd4d7 54 m_bMonitor(false)
abbca718 55{
f8513317
LOK
56 m_logicalAddresses.clear();
57 m_logicalAddresses.set(iLogicalAddress);
58 m_types.clear();
7ea0d558 59 for (int iPtr = 0; iPtr < 16; iPtr++)
09c10b66 60 m_busDevices[iPtr] = new CCECBusDevice(this, (cec_logical_address) iPtr, iPtr == iLogicalAddress ? iPhysicalAddress : 0);
abbca718
LOK
61}
62
f8513317
LOK
63CCECProcessor::CCECProcessor(CLibCEC *controller, CAdapterCommunication *serComm, const char *strDeviceName, const cec_device_type_list &types) :
64 m_bStarted(false),
65 m_strDeviceName(strDeviceName),
66 m_types(types),
67 m_communication(serComm),
68 m_controller(controller),
69 m_bMonitor(false)
70{
71 m_logicalAddresses.clear();
72 for (int iPtr = 0; iPtr < 16; iPtr++)
51b2a094
LOK
73 {
74 switch(iPtr)
75 {
76 case CECDEVICE_AUDIOSYSTEM:
77 m_busDevices[iPtr] = new CCECAudioSystem(this, (cec_logical_address) iPtr, 0);
78 break;
79 case CECDEVICE_PLAYBACKDEVICE1:
80 case CECDEVICE_PLAYBACKDEVICE2:
81 case CECDEVICE_PLAYBACKDEVICE3:
82 m_busDevices[iPtr] = new CCECPlaybackDevice(this, (cec_logical_address) iPtr, 0);
83 break;
84 case CECDEVICE_RECORDINGDEVICE1:
85 case CECDEVICE_RECORDINGDEVICE2:
86 case CECDEVICE_RECORDINGDEVICE3:
87 m_busDevices[iPtr] = new CCECRecordingDevice(this, (cec_logical_address) iPtr, 0);
88 break;
89 case CECDEVICE_TUNER1:
90 case CECDEVICE_TUNER2:
91 case CECDEVICE_TUNER3:
92 case CECDEVICE_TUNER4:
93 m_busDevices[iPtr] = new CCECTuner(this, (cec_logical_address) iPtr, 0);
94 break;
95 case CECDEVICE_TV:
96 m_busDevices[iPtr] = new CCECTV(this, (cec_logical_address) iPtr, 0);
97 break;
98 default:
99 m_busDevices[iPtr] = new CCECBusDevice(this, (cec_logical_address) iPtr, 0);
100 break;
101 }
102 }
f8513317
LOK
103}
104
2abe74eb 105CCECProcessor::~CCECProcessor(void)
abbca718 106{
8b0ee2cc 107 m_startCondition.Broadcast();
2abe74eb
LOK
108 StopThread();
109 m_communication = NULL;
110 m_controller = NULL;
d1998c7b
LOK
111 for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
112 delete m_busDevices[iPtr];
abbca718
LOK
113}
114
2abe74eb 115bool CCECProcessor::Start(void)
abbca718 116{
8b0ee2cc 117 CLockObject lock(&m_mutex);
2abe74eb 118 if (!m_communication || !m_communication->IsOpen())
13fd6a66
LOK
119 {
120 m_controller->AddLog(CEC_LOG_ERROR, "connection is closed");
a8f0bd18 121 return false;
13fd6a66 122 }
abbca718 123
60fa4578 124 if (CreateThread())
8b0ee2cc 125 {
f8513317 126 if (!m_startCondition.Wait(&m_mutex) || !m_bStarted)
8b0ee2cc
LOK
127 {
128 m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread");
129 return false;
130 }
a8f0bd18 131 return true;
8b0ee2cc 132 }
a8f0bd18 133 else
2abe74eb 134 m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread");
abbca718 135
a8f0bd18 136 return false;
abbca718
LOK
137}
138
51b2a094 139bool CCECProcessor::TryLogicalAddress(cec_logical_address address, const char *strLabel, unsigned int iIndex)
f8513317
LOK
140{
141 CStdString strLog;
142 strLog.Format("trying logical address '%s'", strLabel);
143 AddLog(CEC_LOG_DEBUG, strLog);
144
145 SetAckMask(0x1 << address);
146 if (!m_busDevices[address]->PollDevice(address))
147 {
f8513317
LOK
148 strLog.Format("using logical address '%s'", strLabel);
149 AddLog(CEC_LOG_NOTICE, strLog);
787a3cb8
LOK
150
151 /* only set our OSD name for the primary device */
152 if (m_logicalAddresses.empty())
153 m_busDevices[address]->m_strDeviceName = m_strDeviceName;
f8513317
LOK
154 m_logicalAddresses.set(address);
155
156 // TODO
51b2a094 157 m_busDevices[address]->SetPhysicalAddress(CEC_DEFAULT_PHYSICAL_ADDRESS + iIndex);
f8513317
LOK
158
159 return true;
160 }
161
162 strLog.Format("logical address '%s' already taken", strLabel);
163 AddLog(CEC_LOG_DEBUG, strLog);
164 return false;
165}
166
51b2a094 167bool CCECProcessor::FindLogicalAddressRecordingDevice(unsigned int iIndex)
f8513317
LOK
168{
169 AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'recording device'");
51b2a094
LOK
170 return TryLogicalAddress(CECDEVICE_RECORDINGDEVICE1, "recording 1", iIndex) ||
171 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE2, "recording 2", iIndex) ||
172 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE3, "recording 3", iIndex);
f8513317
LOK
173}
174
51b2a094 175bool CCECProcessor::FindLogicalAddressTuner(unsigned int iIndex)
f8513317
LOK
176{
177 AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'tuner'");
51b2a094
LOK
178 return TryLogicalAddress(CECDEVICE_TUNER1, "tuner 1", iIndex) ||
179 TryLogicalAddress(CECDEVICE_TUNER2, "tuner 2", iIndex) ||
180 TryLogicalAddress(CECDEVICE_TUNER3, "tuner 3", iIndex) ||
181 TryLogicalAddress(CECDEVICE_TUNER4, "tuner 4", iIndex);
f8513317
LOK
182}
183
51b2a094 184bool CCECProcessor::FindLogicalAddressPlaybackDevice(unsigned int iIndex)
f8513317
LOK
185{
186 AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'playback device'");
51b2a094
LOK
187 return TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE1, "playback 1", iIndex) ||
188 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE2, "playback 2", iIndex) ||
189 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE3, "playback 3", iIndex);
f8513317
LOK
190}
191
51b2a094 192bool CCECProcessor::FindLogicalAddressAudioSystem(unsigned int iIndex)
f8513317
LOK
193{
194 AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'audio'");
51b2a094 195 return TryLogicalAddress(CECDEVICE_AUDIOSYSTEM, "audio", iIndex);
f8513317
LOK
196}
197
198bool CCECProcessor::FindLogicalAddresses(void)
199{
200 bool bReturn(true);
201 m_logicalAddresses.clear();
202 CStdString strLog;
203
204 for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
205 {
206 if (m_types.types[iPtr] == CEC_DEVICE_TYPE_RESERVED)
207 continue;
208
209 strLog.Format("%s - device %d: type %d", __FUNCTION__, iPtr, m_types.types[iPtr]);
210 AddLog(CEC_LOG_DEBUG, strLog);
211
212 if (m_types.types[iPtr] == CEC_DEVICE_TYPE_RECORDING_DEVICE)
51b2a094 213 bReturn &= FindLogicalAddressRecordingDevice(iPtr);
f8513317 214 if (m_types.types[iPtr] == CEC_DEVICE_TYPE_TUNER)
51b2a094 215 bReturn &= FindLogicalAddressTuner(iPtr);
f8513317 216 if (m_types.types[iPtr] == CEC_DEVICE_TYPE_PLAYBACK_DEVICE)
51b2a094 217 bReturn &= FindLogicalAddressPlaybackDevice(iPtr);
f8513317 218 if (m_types.types[iPtr] == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
51b2a094 219 bReturn &= FindLogicalAddressAudioSystem(iPtr);
f8513317
LOK
220 }
221
222 return bReturn;
223}
224
2abe74eb 225void *CCECProcessor::Process(void)
f99bc831 226{
e0407d3d
LOK
227 cec_command command;
228 CCECAdapterMessage msg;
229
8b0ee2cc 230 {
f8513317
LOK
231 if (m_logicalAddresses.empty() && !FindLogicalAddresses())
232 {
233 CLockObject lock(&m_mutex);
234 m_controller->AddLog(CEC_LOG_ERROR, "could not detect our logical addressed");
235 m_startCondition.Signal();
236 return NULL;
237 }
238
239 SetAckMask(m_logicalAddresses.ackmask());
240
241 {
242 CLockObject lock(&m_mutex);
243 m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started");
244 m_bStarted = true;
245 m_startCondition.Signal();
246 }
8b0ee2cc 247 }
abbca718 248
13fd6a66 249 while (!IsStopped())
abbca718 250 {
60fa4578 251 bool bParseFrame(false);
9dee1670 252 command.clear();
76321de4
LOK
253 msg.clear();
254
60fa4578
LOK
255 {
256 CLockObject lock(&m_mutex);
88c43521 257 if (m_communication->IsOpen() && m_communication->Read(msg, 50))
b5f34cf9
LOK
258 {
259 m_controller->AddLog(msg.is_error() ? CEC_LOG_WARNING : CEC_LOG_DEBUG, msg.ToString());
88c43521 260 bParseFrame = ParseMessage(msg) && !IsStopped();
b5f34cf9 261 }
76321de4
LOK
262
263 if (bParseFrame)
9dee1670 264 command = m_currentframe;
60fa4578
LOK
265 }
266
13fd6a66 267 if (bParseFrame)
9dee1670 268 ParseCommand(command);
abbca718 269
b5f34cf9
LOK
270 Sleep(5);
271
13fd6a66
LOK
272 m_controller->CheckKeypressTimeout();
273
0ab58650
LOK
274 for (unsigned int iDevicePtr = 0; iDevicePtr < 16; iDevicePtr++)
275 m_busDevices[iDevicePtr]->PollVendorId();
276
b5f34cf9 277 Sleep(5);
abbca718
LOK
278 }
279
60fa4578 280 return NULL;
abbca718
LOK
281}
282
2abe74eb 283bool CCECProcessor::SetActiveView(void)
abbca718 284{
60fa4578 285 if (!IsRunning())
f99bc831
LOK
286 return false;
287
f8513317
LOK
288 if (!m_logicalAddresses.empty() && m_busDevices[m_logicalAddresses.primary])
289 return m_busDevices[m_logicalAddresses.primary]->BroadcastActiveView();
cc60ab1c 290 return false;
abbca718
LOK
291}
292
2abe74eb 293bool CCECProcessor::SetInactiveView(void)
abbca718 294{
60fa4578 295 if (!IsRunning())
f99bc831
LOK
296 return false;
297
f8513317
LOK
298 if (!m_logicalAddresses.empty() && m_busDevices[m_logicalAddresses.primary])
299 return m_busDevices[m_logicalAddresses.primary]->BroadcastInactiveView();
cc60ab1c 300 return false;
abbca718
LOK
301}
302
9dee1670 303void CCECProcessor::LogOutput(const cec_command &data)
abbca718 304{
1d3ca3de 305 CStdString strTx;
57f45e6c
LOK
306 strTx.Format("<< %02x", ((uint8_t)data.initiator << 4) + (uint8_t)data.destination);
307 if (data.opcode_set)
308 strTx.AppendFormat(":%02x", (uint8_t)data.opcode);
9dee1670 309
06a1f7ce 310 for (uint8_t iPtr = 0; iPtr < data.parameters.size; iPtr++)
1d3ca3de
LOK
311 strTx.AppendFormat(":%02x", data.parameters[iPtr]);
312 m_controller->AddLog(CEC_LOG_TRAFFIC, strTx.c_str());
9dee1670 313}
2abe74eb 314
06bfd4d7 315bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress)
abbca718 316{
f8513317 317 if (m_logicalAddresses.primary != iLogicalAddress)
06775107
LOK
318 {
319 CStdString strLog;
f8513317 320 strLog.Format("<< setting primary logical address to %1x", iLogicalAddress);
06775107 321 m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str());
f8513317
LOK
322 m_logicalAddresses.primary = iLogicalAddress;
323 m_logicalAddresses.set(iLogicalAddress);
324 return SetAckMask(m_logicalAddresses.ackmask());
06775107 325 }
2abe74eb 326
06bfd4d7 327 return true;
abbca718 328}
825ddb96 329
2492216a
LOK
330bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress)
331{
f8513317 332 if (!m_logicalAddresses.empty() && m_busDevices[m_logicalAddresses.primary])
cc60ab1c 333 {
f8513317
LOK
334 m_busDevices[m_logicalAddresses.primary]->SetPhysicalAddress(iPhysicalAddress);
335 return m_busDevices[m_logicalAddresses.primary]->BroadcastActiveView();
cc60ab1c
LOK
336 }
337 return false;
1969b140
LOK
338}
339
8b7e5ff6
LOK
340bool CCECProcessor::SwitchMonitoring(bool bEnable)
341{
342 CStdString strLog;
343 strLog.Format("== %s monitoring mode ==", bEnable ? "enabling" : "disabling");
344 m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str());
345
346 m_bMonitor = bEnable;
347 if (bEnable)
06bfd4d7 348 return SetAckMask(0);
8b7e5ff6 349 else
f8513317 350 return SetAckMask(m_logicalAddresses.ackmask());
8b7e5ff6
LOK
351}
352
57f45e6c
LOK
353bool CCECProcessor::PollDevice(cec_logical_address iAddress)
354{
355 if (iAddress != CECDEVICE_UNKNOWN && m_busDevices[iAddress])
356 return m_busDevices[iAddress]->PollDevice();
357 return false;
358}
359
6a1c0009
LOK
360cec_version CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress)
361{
362 return m_busDevices[iAddress]->GetCecVersion();
363}
364
a3269a0a
LOK
365bool CCECProcessor::GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language)
366{
cc60ab1c
LOK
367 if (m_busDevices[iAddress])
368 {
369 *language = m_busDevices[iAddress]->GetMenuLanguage();
5744fbba 370 return (strcmp(language->language, "???") != 0);
cc60ab1c
LOK
371 }
372 return false;
a3269a0a
LOK
373}
374
44c74256
LOK
375uint64_t CCECProcessor::GetDeviceVendorId(cec_logical_address iAddress)
376{
cc60ab1c
LOK
377 if (m_busDevices[iAddress])
378 return m_busDevices[iAddress]->GetVendorId();
379 return false;
44c74256
LOK
380}
381
e55f3f70
LOK
382cec_power_status CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddress)
383{
cc60ab1c
LOK
384 if (m_busDevices[iAddress])
385 return m_busDevices[iAddress]->GetPowerStatus();
386 return CEC_POWER_STATUS_UNKNOWN;
e55f3f70
LOK
387}
388
8d84e2c0 389bool CCECProcessor::Transmit(const cec_command &data)
825ddb96 390{
28352a04 391 bool bReturn(false);
13929cff
LOK
392 LogOutput(data);
393
28352a04
LOK
394 CCECAdapterMessage *output = new CCECAdapterMessage(data);
395 bReturn = Transmit(output);
396 delete output;
397
398 return bReturn;
06bfd4d7 399}
13929cff 400
28352a04 401bool CCECProcessor::Transmit(CCECAdapterMessage *output)
06bfd4d7
LOK
402{
403 bool bReturn(false);
2abe74eb 404 CLockObject lock(&m_mutex);
eb35e4ca
LOK
405 {
406 CLockObject msgLock(&output->mutex);
407 if (!m_communication || !m_communication->Write(output))
408 return bReturn;
409 else
0e31a62c 410 {
3a0ca6e1 411 output->condition.Wait(&output->mutex);
0e31a62c
LOK
412 if (output->state != ADAPTER_MESSAGE_STATE_SENT)
413 {
414 m_controller->AddLog(CEC_LOG_ERROR, "command was not sent");
415 return bReturn;
416 }
417 }
2abe74eb 418
06bfd4d7 419 if (output->transmit_timeout > 0)
cd505625 420 {
06bfd4d7 421 if ((bReturn = WaitForTransmitSucceeded(output->size(), output->transmit_timeout)) == false)
cd505625
LOK
422 m_controller->AddLog(CEC_LOG_ERROR, "did not receive ack");
423 }
424 else
cd505625 425 bReturn = true;
2abe74eb
LOK
426 }
427
7ea0d558 428 return bReturn;
825ddb96 429}
abbca718 430
2abe74eb 431void CCECProcessor::TransmitAbort(cec_logical_address address, cec_opcode opcode, ECecAbortReason reason /* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */)
abbca718 432{
9dee1670
LOK
433 m_controller->AddLog(CEC_LOG_DEBUG, "<< transmitting abort message");
434
06a1f7ce 435 cec_command command;
f8513317
LOK
436 // TODO
437 cec_command::format(command, m_logicalAddresses.primary, address, CEC_OPCODE_FEATURE_ABORT);
9dee1670
LOK
438 command.parameters.push_back((uint8_t)opcode);
439 command.parameters.push_back((uint8_t)reason);
440
441 Transmit(command);
abbca718
LOK
442}
443
1f0e9e0f 444bool CCECProcessor::WaitForTransmitSucceeded(uint8_t iLength, uint32_t iTimeout /* = 1000 */)
abbca718 445{
1f0e9e0f
LOK
446 bool bError(false);
447 bool bTransmitSucceeded(false);
7ea0d558 448 uint8_t iPacketsLeft(iLength / 4);
abbca718
LOK
449
450 int64_t iNow = GetTimeMs();
25701fa6 451 int64_t iTargetTime = iNow + (uint64_t) iTimeout;
abbca718 452
1f0e9e0f 453 while (!bTransmitSucceeded && !bError && (iTimeout == 0 || iNow < iTargetTime))
abbca718 454 {
220537f2 455 CCECAdapterMessage msg;
25701fa6 456
06a1f7ce 457 if (!m_communication->Read(msg, iTimeout > 0 ? (int32_t)(iTargetTime - iNow) : 1000))
abbca718 458 {
abbca718 459 iNow = GetTimeMs();
5d38b0b6
LOK
460 continue;
461 }
462
edab6137 463 if ((bError = msg.is_error()) == false)
7ea0d558 464 {
0544ff56
LOK
465 m_controller->AddLog(bError ? CEC_LOG_WARNING : CEC_LOG_DEBUG, msg.ToString());
466
edab6137
LOK
467 switch(msg.message())
468 {
469 case MSGCODE_COMMAND_ACCEPTED:
470 if (iPacketsLeft > 0)
471 iPacketsLeft--;
472 break;
473 case MSGCODE_TRANSMIT_SUCCEEDED:
474 bTransmitSucceeded = (iPacketsLeft == 0);
475 bError = !bTransmitSucceeded;
476 break;
477 default:
478 ParseMessage(msg);
479 }
7ea0d558 480
edab6137
LOK
481 iNow = GetTimeMs();
482 }
abbca718
LOK
483 }
484
1f0e9e0f 485 return bTransmitSucceeded && !bError;
abbca718
LOK
486}
487
0e7b6c54 488bool CCECProcessor::ParseMessage(const CCECAdapterMessage &msg)
abbca718 489{
7ea0d558 490 bool bEom = false;
60fa4578 491
0e7b6c54 492 if (msg.empty())
7ea0d558 493 return bEom;
abbca718 494
0e7b6c54 495 switch(msg.message())
abbca718 496 {
abbca718
LOK
497 case MSGCODE_FRAME_START:
498 {
7ea0d558 499 m_currentframe.clear();
0e7b6c54 500 if (msg.size() >= 2)
abbca718 501 {
0e7b6c54
LOK
502 m_currentframe.initiator = msg.initiator();
503 m_currentframe.destination = msg.destination();
504 m_currentframe.ack = msg.ack();
505 m_currentframe.eom = msg.eom();
abbca718 506 }
abbca718
LOK
507 }
508 break;
509 case MSGCODE_FRAME_DATA:
510 {
0e7b6c54 511 if (msg.size() >= 2)
78e8010a 512 {
e41b06f9 513 m_currentframe.push_back(msg[1]);
0e7b6c54 514 m_currentframe.eom = msg.eom();
abbca718 515 }
0e7b6c54 516 bEom = msg.eom();
abbca718 517 }
78e8010a 518 break;
abbca718
LOK
519 default:
520 break;
521 }
7ea0d558
LOK
522
523 return bEom;
abbca718
LOK
524}
525
e9de9629 526void CCECProcessor::ParseCommand(cec_command &command)
abbca718 527{
e9de9629 528 CStdString dataStr;
1d3ca3de 529 dataStr.Format(">> %1x%1x:%02x", command.initiator, command.destination, command.opcode);
e9de9629
LOK
530 for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++)
531 dataStr.AppendFormat(":%02x", (unsigned int)command.parameters[iPtr]);
1d3ca3de 532 m_controller->AddLog(CEC_LOG_TRAFFIC, dataStr.c_str());
dc113aca 533
e9de9629
LOK
534 if (!m_bMonitor)
535 m_busDevices[(uint8_t)command.initiator]->HandleCommand(command);
dc113aca
LOK
536}
537
0f23c85c
LOK
538uint16_t CCECProcessor::GetPhysicalAddress(void) const
539{
f8513317
LOK
540 if (!m_logicalAddresses.empty() && m_busDevices[m_logicalAddresses.primary])
541 return m_busDevices[m_logicalAddresses.primary]->GetPhysicalAddress();
cc60ab1c 542 return false;
0f23c85c
LOK
543}
544
e9de9629 545void CCECProcessor::SetCurrentButton(cec_user_control_code iButtonCode)
dc113aca 546{
e9de9629 547 m_controller->SetCurrentButton(iButtonCode);
dc113aca
LOK
548}
549
e9de9629 550void CCECProcessor::AddCommand(const cec_command &command)
dc113aca 551{
0544ff56 552 m_controller->AddCommand(command);
dc113aca
LOK
553}
554
95ba7a09
LOK
555void CCECProcessor::AddKey(cec_keypress &key)
556{
557 m_controller->AddKey(key);
558}
559
e9de9629 560void CCECProcessor::AddKey(void)
dc113aca 561{
e9de9629 562 m_controller->AddKey();
abbca718 563}
acec5f48 564
e9de9629 565void CCECProcessor::AddLog(cec_log_level level, const CStdString &strMessage)
acec5f48 566{
e9de9629 567 m_controller->AddLog(level, strMessage);
acec5f48 568}
06bfd4d7
LOK
569
570bool CCECProcessor::SetAckMask(uint16_t iMask)
571{
28352a04 572 bool bReturn(false);
06bfd4d7
LOK
573 CStdString strLog;
574 strLog.Format("setting ackmask to %2x", iMask);
575 m_controller->AddLog(CEC_LOG_DEBUG, strLog.c_str());
576
28352a04 577 CCECAdapterMessage *output = new CCECAdapterMessage;
06bfd4d7
LOK
578
579 output->push_back(MSGSTART);
580 output->push_escaped(MSGCODE_SET_ACK_MASK);
581 output->push_escaped(iMask >> 8);
582 output->push_escaped((uint8_t)iMask);
583 output->push_back(MSGEND);
584
28352a04 585 if ((bReturn = Transmit(output)) == false)
06bfd4d7 586 m_controller->AddLog(CEC_LOG_ERROR, "could not set the ackmask");
06bfd4d7 587
28352a04
LOK
588 delete output;
589
590 return bReturn;
06bfd4d7 591}