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