cec: fix some logging. only transmit packets once
[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"
62f5527d 42#include "implementations/CECCommandHandler.h"
2abe74eb 43#include "LibCEC.h"
abbca718 44#include "util/StdString.h"
b9187cc6 45#include "platform/timeutils.h"
abbca718
LOK
46
47using namespace CEC;
48using namespace std;
49
1113cb7d 50CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS*/) :
f8513317 51 m_bStarted(false),
16b1e052 52 m_iHDMIPort(CEC_DEFAULT_HDMI_PORT),
d2f1c157 53 m_iBaseDevice((cec_logical_address)CEC_DEFAULT_BASE_DEVICE),
855a3a98 54 m_lastInitiator(CECDEVICE_UNKNOWN),
2abe74eb 55 m_strDeviceName(strDeviceName),
8b7e5ff6 56 m_controller(controller),
7c63a480
LOK
57 m_bMonitor(false),
58 m_busScan(NULL)
abbca718 59{
1113cb7d 60 m_communication = new CAdapterCommunication(this);
ab1469a0
LOK
61 m_logicalAddresses.Clear();
62 m_logicalAddresses.Set(iLogicalAddress);
20b8870a 63 m_types.clear();
7871d66e 64 for (int iPtr = 0; iPtr <= 16; iPtr++)
09c10b66 65 m_busDevices[iPtr] = new CCECBusDevice(this, (cec_logical_address) iPtr, iPtr == iLogicalAddress ? iPhysicalAddress : 0);
abbca718
LOK
66}
67
1113cb7d 68CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, const cec_device_type_list &types) :
f8513317 69 m_bStarted(false),
16b1e052 70 m_iHDMIPort(CEC_DEFAULT_HDMI_PORT),
d2f1c157 71 m_iBaseDevice((cec_logical_address)CEC_DEFAULT_BASE_DEVICE),
f8513317
LOK
72 m_strDeviceName(strDeviceName),
73 m_types(types),
f8513317
LOK
74 m_controller(controller),
75 m_bMonitor(false)
76{
1113cb7d 77 m_communication = new CAdapterCommunication(this);
ab1469a0 78 m_logicalAddresses.Clear();
f8513317 79 for (int iPtr = 0; iPtr < 16; iPtr++)
51b2a094
LOK
80 {
81 switch(iPtr)
82 {
83 case CECDEVICE_AUDIOSYSTEM:
5d5a2dc2 84 m_busDevices[iPtr] = new CCECAudioSystem(this, (cec_logical_address) iPtr, 0xFFFF);
51b2a094
LOK
85 break;
86 case CECDEVICE_PLAYBACKDEVICE1:
87 case CECDEVICE_PLAYBACKDEVICE2:
88 case CECDEVICE_PLAYBACKDEVICE3:
5d5a2dc2 89 m_busDevices[iPtr] = new CCECPlaybackDevice(this, (cec_logical_address) iPtr, 0xFFFF);
51b2a094
LOK
90 break;
91 case CECDEVICE_RECORDINGDEVICE1:
92 case CECDEVICE_RECORDINGDEVICE2:
93 case CECDEVICE_RECORDINGDEVICE3:
5d5a2dc2 94 m_busDevices[iPtr] = new CCECRecordingDevice(this, (cec_logical_address) iPtr, 0xFFFF);
51b2a094
LOK
95 break;
96 case CECDEVICE_TUNER1:
97 case CECDEVICE_TUNER2:
98 case CECDEVICE_TUNER3:
99 case CECDEVICE_TUNER4:
5d5a2dc2 100 m_busDevices[iPtr] = new CCECTuner(this, (cec_logical_address) iPtr, 0xFFFF);
51b2a094
LOK
101 break;
102 case CECDEVICE_TV:
103 m_busDevices[iPtr] = new CCECTV(this, (cec_logical_address) iPtr, 0);
104 break;
105 default:
5d5a2dc2 106 m_busDevices[iPtr] = new CCECBusDevice(this, (cec_logical_address) iPtr, 0xFFFF);
51b2a094
LOK
107 break;
108 }
109 }
f8513317
LOK
110}
111
2abe74eb 112CCECProcessor::~CCECProcessor(void)
abbca718 113{
7c63a480
LOK
114 if (m_busScan)
115 {
116 m_busScan->StopThread();
117 delete m_busScan;
118 }
119
8b0ee2cc 120 m_startCondition.Broadcast();
2abe74eb 121 StopThread();
7c63a480 122
1113cb7d 123 delete m_communication;
2abe74eb
LOK
124 m_communication = NULL;
125 m_controller = NULL;
d1998c7b
LOK
126 for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
127 delete m_busDevices[iPtr];
abbca718
LOK
128}
129
1113cb7d 130bool CCECProcessor::Start(const char *strPort, uint16_t iBaudRate /* = 38400 */, uint32_t iTimeoutMs /* = 10000 */)
abbca718 131{
8b0ee2cc 132 CLockObject lock(&m_mutex);
1113cb7d 133 if (!m_communication || m_communication->IsOpen())
13fd6a66 134 {
1113cb7d
LOK
135 m_controller->AddLog(CEC_LOG_ERROR, "connection already opened");
136 return false;
137 }
138
139 if (!m_communication->Open(strPort, iBaudRate, iTimeoutMs))
140 {
141 m_controller->AddLog(CEC_LOG_ERROR, "could not open a connection");
a8f0bd18 142 return false;
13fd6a66 143 }
abbca718 144
60fa4578 145 if (CreateThread())
8b0ee2cc 146 {
f8513317 147 if (!m_startCondition.Wait(&m_mutex) || !m_bStarted)
8b0ee2cc
LOK
148 {
149 m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread");
150 return false;
151 }
9fd73dd4
LOK
152
153 lock.Leave();
154 if (SetAckMask(m_logicalAddresses.AckMask()) &&
d2f1c157 155 SetHDMIPort(m_iBaseDevice, m_iHDMIPort, true))
9fd73dd4 156 {
7c63a480
LOK
157 m_busScan = new CCECBusScan(this);
158 m_busScan->CreateThread(true);
9fd73dd4
LOK
159 return true;
160 }
8b0ee2cc 161 }
a8f0bd18 162 else
2abe74eb 163 m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread");
abbca718 164
a8f0bd18 165 return false;
abbca718
LOK
166}
167
b58d9277 168bool CCECProcessor::TryLogicalAddress(cec_logical_address address)
f8513317 169{
93fff5c1 170 if (m_busDevices[address]->TryLogicalAddress())
f8513317 171 {
8747dd4f 172 /* only set our OSD name and active source for the primary device */
ab1469a0 173 if (m_logicalAddresses.IsEmpty())
8747dd4f 174 {
787a3cb8 175 m_busDevices[address]->m_strDeviceName = m_strDeviceName;
8747dd4f
LOK
176 m_busDevices[address]->m_bActiveSource = true;
177 }
ab1469a0 178 m_logicalAddresses.Set(address);
f8513317
LOK
179 return true;
180 }
181
f8513317
LOK
182 return false;
183}
184
b58d9277 185bool CCECProcessor::FindLogicalAddressRecordingDevice(void)
f8513317
LOK
186{
187 AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'recording device'");
b58d9277
LOK
188 return TryLogicalAddress(CECDEVICE_RECORDINGDEVICE1) ||
189 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE2) ||
190 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE3);
f8513317
LOK
191}
192
b58d9277 193bool CCECProcessor::FindLogicalAddressTuner(void)
f8513317
LOK
194{
195 AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'tuner'");
b58d9277
LOK
196 return TryLogicalAddress(CECDEVICE_TUNER1) ||
197 TryLogicalAddress(CECDEVICE_TUNER2) ||
198 TryLogicalAddress(CECDEVICE_TUNER3) ||
199 TryLogicalAddress(CECDEVICE_TUNER4);
f8513317
LOK
200}
201
b58d9277 202bool CCECProcessor::FindLogicalAddressPlaybackDevice(void)
f8513317
LOK
203{
204 AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'playback device'");
b58d9277
LOK
205 return TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE1) ||
206 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE2) ||
207 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE3);
f8513317
LOK
208}
209
b58d9277 210bool CCECProcessor::FindLogicalAddressAudioSystem(void)
f8513317
LOK
211{
212 AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'audio'");
b58d9277 213 return TryLogicalAddress(CECDEVICE_AUDIOSYSTEM);
f8513317
LOK
214}
215
216bool CCECProcessor::FindLogicalAddresses(void)
217{
218 bool bReturn(true);
ab1469a0 219 m_logicalAddresses.Clear();
f8513317
LOK
220 CStdString strLog;
221
222 for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
223 {
224 if (m_types.types[iPtr] == CEC_DEVICE_TYPE_RESERVED)
225 continue;
226
227 strLog.Format("%s - device %d: type %d", __FUNCTION__, iPtr, m_types.types[iPtr]);
228 AddLog(CEC_LOG_DEBUG, strLog);
229
230 if (m_types.types[iPtr] == CEC_DEVICE_TYPE_RECORDING_DEVICE)
b58d9277 231 bReturn &= FindLogicalAddressRecordingDevice();
f8513317 232 if (m_types.types[iPtr] == CEC_DEVICE_TYPE_TUNER)
b58d9277 233 bReturn &= FindLogicalAddressTuner();
f8513317 234 if (m_types.types[iPtr] == CEC_DEVICE_TYPE_PLAYBACK_DEVICE)
b58d9277 235 bReturn &= FindLogicalAddressPlaybackDevice();
f8513317 236 if (m_types.types[iPtr] == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
b58d9277 237 bReturn &= FindLogicalAddressAudioSystem();
f8513317
LOK
238 }
239
240 return bReturn;
241}
242
855a3a98
LOK
243bool CCECProcessor::SetLineTimeout(uint8_t iTimeout)
244{
245 bool bReturn(false);
246 CCECAdapterMessage *output = new CCECAdapterMessage;
247
248 output->push_back(MSGSTART);
249 output->push_escaped(MSGCODE_TRANSMIT_IDLETIME);
250 output->push_escaped(iTimeout);
251 output->push_back(MSGEND);
252
253 if ((bReturn = Transmit(output)) == false)
254 m_controller->AddLog(CEC_LOG_ERROR, "could not set the idletime");
255 delete output;
256 return bReturn;
257}
258
2abe74eb 259void *CCECProcessor::Process(void)
f99bc831 260{
8747dd4f 261 bool bParseFrame(false);
e0407d3d
LOK
262 cec_command command;
263 CCECAdapterMessage msg;
264
9fd73dd4 265 if (m_logicalAddresses.IsEmpty() && !FindLogicalAddresses())
8b0ee2cc 266 {
9fd73dd4
LOK
267 CLockObject lock(&m_mutex);
268 m_controller->AddLog(CEC_LOG_ERROR, "could not detect our logical addresses");
269 m_startCondition.Signal();
270 return NULL;
271 }
272 else
273 {
274 CLockObject lock(&m_mutex);
275 m_bStarted = true;
276 m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started");
277 m_startCondition.Signal();
8b0ee2cc 278 }
abbca718 279
13fd6a66 280 while (!IsStopped())
abbca718 281 {
ab1469a0 282 command.Clear();
76321de4
LOK
283 msg.clear();
284
60fa4578
LOK
285 {
286 CLockObject lock(&m_mutex);
8747dd4f
LOK
287 if (m_commandBuffer.Pop(command))
288 {
289 bParseFrame = true;
290 }
291 else if (m_communication->IsOpen() && m_communication->Read(msg, 50))
b5f34cf9 292 {
f2198ab5 293 if ((bParseFrame = (ParseMessage(msg) && !IsStopped())) == true)
8747dd4f 294 command = m_currentframe;
b5f34cf9 295 }
60fa4578
LOK
296 }
297
13fd6a66 298 if (bParseFrame)
9dee1670 299 ParseCommand(command);
8747dd4f 300 bParseFrame = false;
abbca718 301
b5f34cf9
LOK
302 Sleep(5);
303
13fd6a66 304 m_controller->CheckKeypressTimeout();
abbca718
LOK
305 }
306
1113cb7d
LOK
307 if (m_communication)
308 m_communication->Close();
309
60fa4578 310 return NULL;
abbca718
LOK
311}
312
18203d17 313bool CCECProcessor::SetActiveSource(cec_device_type type /* = CEC_DEVICE_TYPE_RESERVED */)
abbca718 314{
8ac9c610
LOK
315 bool bReturn(false);
316
60fa4578 317 if (!IsRunning())
8ac9c610 318 return bReturn;
f99bc831 319
18203d17 320 cec_logical_address addr = m_logicalAddresses.primary;
04437dcf 321
18203d17
LOK
322 if (type != CEC_DEVICE_TYPE_RESERVED)
323 {
f2198ab5 324 for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
18203d17
LOK
325 {
326 if (m_logicalAddresses[iPtr] && m_busDevices[iPtr]->m_type == type)
327 {
328 addr = (cec_logical_address) iPtr;
329 break;
330 }
331 }
332 }
333
16b1e052 334 return SetStreamPath(m_busDevices[addr]->GetPhysicalAddress(false)) &&
4a870dc8 335 m_busDevices[addr]->TransmitActiveSource();
18203d17
LOK
336}
337
1a6669b8
LOK
338bool CCECProcessor::SetActiveSource(cec_logical_address iAddress)
339{
16b1e052 340 return SetStreamPath(m_busDevices[iAddress]->GetPhysicalAddress(false));
1a6669b8
LOK
341}
342
18203d17
LOK
343bool CCECProcessor::SetActiveView(void)
344{
4a870dc8 345 return SetActiveSource(m_types.IsEmpty() ? CEC_DEVICE_TYPE_RESERVED : m_types[0]);
8ac9c610
LOK
346}
347
28fa6c97 348bool CCECProcessor::SetDeckControlMode(cec_deck_control_mode mode, bool bSendUpdate /* = true */)
a9232a79
LOK
349{
350 bool bReturn(false);
351
352 CCECBusDevice *device = GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
353 if (device)
354 {
355 ((CCECPlaybackDevice *) device)->SetDeckControlMode(mode);
28fa6c97
LOK
356 if (bSendUpdate)
357 ((CCECPlaybackDevice *) device)->TransmitDeckStatus(CECDEVICE_TV);
a9232a79
LOK
358 bReturn = true;
359 }
360
361 return bReturn;
362}
363
28fa6c97 364bool CCECProcessor::SetDeckInfo(cec_deck_info info, bool bSendUpdate /* = true */)
a9232a79
LOK
365{
366 bool bReturn(false);
367
368 CCECBusDevice *device = GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
369 if (device)
370 {
371 ((CCECPlaybackDevice *) device)->SetDeckStatus(info);
28fa6c97
LOK
372 if (bSendUpdate)
373 ((CCECPlaybackDevice *) device)->TransmitDeckStatus(CECDEVICE_TV);
a9232a79
LOK
374 bReturn = true;
375 }
376
377 return bReturn;
378}
379
d2f1c157 380bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort, bool bForce /* = false */)
16b1e052
LOK
381{
382 bool bReturn(false);
383
384 CStdString strLog;
d2f1c157 385 strLog.Format("setting HDMI port to %d on device %s (%d)", iPort, ToString(iBaseDevice), (int)iBaseDevice);
16b1e052
LOK
386 AddLog(CEC_LOG_DEBUG, strLog);
387
d2f1c157 388 m_iBaseDevice = iBaseDevice;
16b1e052 389 m_iHDMIPort = iPort;
9fd73dd4 390 if (!m_bStarted && !bForce)
16b1e052
LOK
391 return true;
392
393 uint16_t iPhysicalAddress(0);
d2f1c157
LOK
394 iPhysicalAddress = m_busDevices[iBaseDevice]->GetPhysicalAddress();
395 uint16_t iPos = 0;
396 if (iPhysicalAddress == 0)
397 iPos = 0x1000;
398 else if (iPhysicalAddress % 0x1000 == 0)
399 iPos = 0x100;
400 else if (iPhysicalAddress % 0x100 == 0)
401 iPos = 0x10;
402 else if (iPhysicalAddress % 0x10 == 0)
403 iPos = 0x1;
404
405 while(!bReturn && iPos > 0)
16b1e052 406 {
d2f1c157 407 iPhysicalAddress += (uint16_t)(iPort * iPos);
16b1e052
LOK
408 strLog.Format("checking physical address %4x", iPhysicalAddress);
409 AddLog(CEC_LOG_DEBUG, strLog);
410 if (CheckPhysicalAddress(iPhysicalAddress))
411 {
412 strLog.Format("physical address %4x is in use", iPhysicalAddress);
413 AddLog(CEC_LOG_DEBUG, strLog);
d2f1c157 414 iPos = (iPos == 1) ? 0 : iPos / 0x10;
16b1e052
LOK
415 }
416 else
417 {
418 SetPhysicalAddress(iPhysicalAddress);
419 bReturn = true;
420 }
421 }
422
423 return bReturn;
424}
425
426bool CCECProcessor::CheckPhysicalAddress(uint16_t iPhysicalAddress)
427{
9fd73dd4 428 for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
16b1e052
LOK
429 {
430 if (m_busDevices[iPtr]->GetPhysicalAddress(false) == iPhysicalAddress)
431 return true;
432 }
433 return false;
434}
435
8ac9c610
LOK
436bool CCECProcessor::SetStreamPath(uint16_t iStreamPath)
437{
04437dcf
LOK
438 bool bReturn(false);
439
8ac9c610
LOK
440 CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamPath);
441 if (device)
442 {
7856411b 443 device->SetActiveDevice();
91bea174 444 bReturn = true;
8ac9c610
LOK
445 }
446
04437dcf 447 return bReturn;
abbca718
LOK
448}
449
ab27363d 450bool CCECProcessor::TransmitInactiveSource(void)
abbca718 451{
60fa4578 452 if (!IsRunning())
f99bc831
LOK
453 return false;
454
ab1469a0 455 if (!m_logicalAddresses.IsEmpty() && m_busDevices[m_logicalAddresses.primary])
ab27363d 456 return m_busDevices[m_logicalAddresses.primary]->TransmitInactiveSource();
cc60ab1c 457 return false;
abbca718
LOK
458}
459
9dee1670 460void CCECProcessor::LogOutput(const cec_command &data)
abbca718 461{
1d3ca3de 462 CStdString strTx;
57f45e6c
LOK
463 strTx.Format("<< %02x", ((uint8_t)data.initiator << 4) + (uint8_t)data.destination);
464 if (data.opcode_set)
465 strTx.AppendFormat(":%02x", (uint8_t)data.opcode);
9dee1670 466
06a1f7ce 467 for (uint8_t iPtr = 0; iPtr < data.parameters.size; iPtr++)
1d3ca3de
LOK
468 strTx.AppendFormat(":%02x", data.parameters[iPtr]);
469 m_controller->AddLog(CEC_LOG_TRAFFIC, strTx.c_str());
9dee1670 470}
2abe74eb 471
06bfd4d7 472bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress)
abbca718 473{
f8513317 474 if (m_logicalAddresses.primary != iLogicalAddress)
06775107
LOK
475 {
476 CStdString strLog;
f8513317 477 strLog.Format("<< setting primary logical address to %1x", iLogicalAddress);
06775107 478 m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str());
f8513317 479 m_logicalAddresses.primary = iLogicalAddress;
ab1469a0
LOK
480 m_logicalAddresses.Set(iLogicalAddress);
481 return SetAckMask(m_logicalAddresses.AckMask());
06775107 482 }
2abe74eb 483
06bfd4d7 484 return true;
abbca718 485}
825ddb96 486
28fa6c97
LOK
487bool CCECProcessor::SetMenuState(cec_menu_state state, bool bSendUpdate /* = true */)
488{
489 for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
490 {
491 if (m_logicalAddresses[iPtr])
492 m_busDevices[iPtr]->SetMenuState(state);
493 }
494
495 if (bSendUpdate)
496 m_busDevices[m_logicalAddresses.primary]->TransmitMenuState(CECDEVICE_TV);
497
498 return true;
499}
500
2492216a
LOK
501bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress)
502{
16b1e052 503 if (!m_logicalAddresses.IsEmpty())
cc60ab1c 504 {
16b1e052
LOK
505 for (uint8_t iPtr = 0; iPtr < 15; iPtr++)
506 if (m_logicalAddresses[iPtr])
507 m_busDevices[iPtr]->SetPhysicalAddress(iPhysicalAddress);
8ac9c610 508 return SetActiveView();
cc60ab1c
LOK
509 }
510 return false;
1969b140
LOK
511}
512
8b7e5ff6
LOK
513bool CCECProcessor::SwitchMonitoring(bool bEnable)
514{
515 CStdString strLog;
516 strLog.Format("== %s monitoring mode ==", bEnable ? "enabling" : "disabling");
517 m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str());
518
855a3a98
LOK
519 {
520 CLockObject lock(&m_mutex);
521 m_bMonitor = bEnable;
522
523 if (bEnable)
524 {
525 if (!m_busScan)
526 {
527 m_busScan = new CCECBusScan(this);
528 m_busScan->CreateThread(true);
529 }
530 }
531 else
532 {
533 if (m_busScan)
534 {
535 m_busScan->StopThread();
536 delete m_busScan;
537 m_busScan = NULL;
538 }
539 }
540 }
541
8b7e5ff6 542 if (bEnable)
06bfd4d7 543 return SetAckMask(0);
8b7e5ff6 544 else
ab1469a0 545 return SetAckMask(m_logicalAddresses.AckMask());
8b7e5ff6
LOK
546}
547
57f45e6c
LOK
548bool CCECProcessor::PollDevice(cec_logical_address iAddress)
549{
550 if (iAddress != CECDEVICE_UNKNOWN && m_busDevices[iAddress])
95a73fa7
LOK
551 {
552 return m_logicalAddresses.primary == CECDEVICE_UNKNOWN ?
553 m_busDevices[iAddress]->TransmitPoll(iAddress) :
554 m_busDevices[m_logicalAddresses.primary]->TransmitPoll(iAddress);
555 }
57f45e6c
LOK
556 return false;
557}
558
9f332fe2 559uint8_t CCECProcessor::VolumeUp(bool bWait /* = true */)
04e637f9
LOK
560{
561 uint8_t status = 0;
562 if (IsActiveDevice(CECDEVICE_AUDIOSYSTEM))
9f332fe2 563 status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeUp(bWait);
04e637f9
LOK
564
565 return status;
566}
567
9f332fe2 568uint8_t CCECProcessor::VolumeDown(bool bWait /* = true */)
04e637f9
LOK
569{
570 uint8_t status = 0;
571 if (IsActiveDevice(CECDEVICE_AUDIOSYSTEM))
9f332fe2 572 status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeDown(bWait);
04e637f9
LOK
573
574 return status;
575}
576
9f332fe2 577uint8_t CCECProcessor::MuteAudio(bool bWait /* = true */)
04e637f9
LOK
578{
579 uint8_t status = 0;
580 if (IsActiveDevice(CECDEVICE_AUDIOSYSTEM))
9f332fe2 581 status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->MuteAudio(bWait);
04e637f9
LOK
582
583 return status;
584}
585
16b1e052 586CCECBusDevice *CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress, bool bRefresh /* = false */) const
8ac9c610 587{
16b1e052 588 if (m_busDevices[m_logicalAddresses.primary]->GetPhysicalAddress(false) == iPhysicalAddress)
b58d9277 589 return m_busDevices[m_logicalAddresses.primary];
8ac9c610 590
b58d9277 591 CCECBusDevice *device = NULL;
8ac9c610
LOK
592 for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
593 {
16b1e052 594 if (m_busDevices[iPtr]->GetPhysicalAddress(bRefresh) == iPhysicalAddress)
8ac9c610
LOK
595 {
596 device = m_busDevices[iPtr];
597 break;
598 }
599 }
600
601 return device;
602}
603
a9232a79
LOK
604CCECBusDevice *CCECProcessor::GetDeviceByType(cec_device_type type) const
605{
606 CCECBusDevice *device = NULL;
607
608 for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
609 {
610 if (m_busDevices[iPtr]->m_type == type)
611 {
612 device = m_busDevices[iPtr];
613 break;
614 }
615 }
616
617 return device;
618}
619
6a1c0009
LOK
620cec_version CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress)
621{
622 return m_busDevices[iAddress]->GetCecVersion();
623}
624
ed21be2a
LOK
625cec_osd_name CCECProcessor::GetDeviceOSDName(cec_logical_address iAddress)
626{
627 CStdString strOSDName = m_busDevices[iAddress]->GetOSDName();
628 cec_osd_name retVal;
629
630 snprintf(retVal.name, sizeof(retVal.name), "%s", strOSDName.c_str());
631 retVal.device = iAddress;
632
633 return retVal;
634}
635
a3269a0a
LOK
636bool CCECProcessor::GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language)
637{
cc60ab1c
LOK
638 if (m_busDevices[iAddress])
639 {
640 *language = m_busDevices[iAddress]->GetMenuLanguage();
5744fbba 641 return (strcmp(language->language, "???") != 0);
cc60ab1c
LOK
642 }
643 return false;
a3269a0a
LOK
644}
645
44c74256
LOK
646uint64_t CCECProcessor::GetDeviceVendorId(cec_logical_address iAddress)
647{
cc60ab1c
LOK
648 if (m_busDevices[iAddress])
649 return m_busDevices[iAddress]->GetVendorId();
650 return false;
44c74256
LOK
651}
652
e55f3f70
LOK
653cec_power_status CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddress)
654{
cc60ab1c
LOK
655 if (m_busDevices[iAddress])
656 return m_busDevices[iAddress]->GetPowerStatus();
657 return CEC_POWER_STATUS_UNKNOWN;
e55f3f70
LOK
658}
659
8d84e2c0 660bool CCECProcessor::Transmit(const cec_command &data)
825ddb96 661{
28352a04 662 bool bReturn(false);
13929cff
LOK
663 LogOutput(data);
664
28352a04
LOK
665 CCECAdapterMessage *output = new CCECAdapterMessage(data);
666 bReturn = Transmit(output);
667 delete output;
668
669 return bReturn;
06bfd4d7 670}
13929cff 671
28352a04 672bool CCECProcessor::Transmit(CCECAdapterMessage *output)
06bfd4d7
LOK
673{
674 bool bReturn(false);
2abe74eb 675 CLockObject lock(&m_mutex);
eb35e4ca 676 {
fd5e333a 677 do
0e31a62c 678 {
82d1a9a1
LOK
679 CLockObject msgLock(&output->mutex);
680 if (!m_communication || !m_communication->Write(output))
0e31a62c 681 return bReturn;
82d1a9a1
LOK
682 else
683 {
684 output->condition.Wait(&output->mutex);
685 if (output->state != ADAPTER_MESSAGE_STATE_SENT)
686 {
687 m_controller->AddLog(CEC_LOG_ERROR, "command was not sent");
688 return bReturn;
689 }
0e31a62c 690 }
2abe74eb 691
82d1a9a1
LOK
692 if (output->transmit_timeout > 0)
693 {
694 if ((bReturn = WaitForTransmitSucceeded(output)) == false)
695 m_controller->AddLog(CEC_LOG_DEBUG, "did not receive ack");
696 }
697 else
698 bReturn = true;
fd5e333a 699 }while (output->transmit_timeout > 0 && output->needs_retry() && ++output->tries <= output->maxTries);
2abe74eb
LOK
700 }
701
7ea0d558 702 return bReturn;
825ddb96 703}
abbca718 704
22b4e74a 705void CCECProcessor::TransmitAbort(cec_logical_address address, cec_opcode opcode, cec_abort_reason reason /* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */)
abbca718 706{
9dee1670
LOK
707 m_controller->AddLog(CEC_LOG_DEBUG, "<< transmitting abort message");
708
06a1f7ce 709 cec_command command;
f8513317 710 // TODO
ab1469a0
LOK
711 cec_command::Format(command, m_logicalAddresses.primary, address, CEC_OPCODE_FEATURE_ABORT);
712 command.parameters.PushBack((uint8_t)opcode);
713 command.parameters.PushBack((uint8_t)reason);
9dee1670
LOK
714
715 Transmit(command);
abbca718
LOK
716}
717
82d1a9a1 718bool CCECProcessor::WaitForTransmitSucceeded(CCECAdapterMessage *message)
abbca718 719{
1f0e9e0f
LOK
720 bool bError(false);
721 bool bTransmitSucceeded(false);
82d1a9a1 722 uint8_t iPacketsLeft(message->size() / 4);
abbca718
LOK
723
724 int64_t iNow = GetTimeMs();
82d1a9a1 725 int64_t iTargetTime = iNow + message->transmit_timeout;
abbca718 726
82d1a9a1 727 while (!bTransmitSucceeded && !bError && (message->transmit_timeout == 0 || iNow < iTargetTime))
abbca718 728 {
220537f2 729 CCECAdapterMessage msg;
25701fa6 730
82d1a9a1 731 if (!m_communication->Read(msg, message->transmit_timeout > 0 ? (int32_t)(iTargetTime - iNow) : 1000))
abbca718 732 {
abbca718 733 iNow = GetTimeMs();
5d38b0b6
LOK
734 continue;
735 }
736
855a3a98
LOK
737 if (msg.message() == MSGCODE_FRAME_START && msg.ack())
738 {
739 m_busDevices[msg.initiator()]->GetHandler()->HandlePoll(msg.initiator(), msg.destination());
740 m_lastInitiator = msg.initiator();
741 iNow = GetTimeMs();
742 continue;
743 }
744
745 bError = msg.is_error();
746 if (msg.message() == MSGCODE_RECEIVE_FAILED &&
747 m_lastInitiator != CECDEVICE_UNKNOWN &&
748 !m_busDevices[m_lastInitiator]->GetHandler()->HandleReceiveFailed())
749 {
750 iNow = GetTimeMs();
751 continue;
752 }
753
82d1a9a1 754 if (bError)
fd5e333a 755 {
82d1a9a1 756 message->reply = msg.message();
fd5e333a
LOK
757 m_controller->AddLog(CEC_LOG_DEBUG, msg.ToString());
758 }
82d1a9a1 759 else
7ea0d558 760 {
edab6137
LOK
761 switch(msg.message())
762 {
763 case MSGCODE_COMMAND_ACCEPTED:
fd5e333a 764 m_controller->AddLog(CEC_LOG_DEBUG, msg.ToString());
edab6137
LOK
765 if (iPacketsLeft > 0)
766 iPacketsLeft--;
767 break;
768 case MSGCODE_TRANSMIT_SUCCEEDED:
fd5e333a 769 m_controller->AddLog(CEC_LOG_DEBUG, msg.ToString());
edab6137
LOK
770 bTransmitSucceeded = (iPacketsLeft == 0);
771 bError = !bTransmitSucceeded;
82d1a9a1 772 message->reply = MSGCODE_TRANSMIT_SUCCEEDED;
edab6137
LOK
773 break;
774 default:
8747dd4f
LOK
775 if (ParseMessage(msg))
776 m_commandBuffer.Push(m_currentframe);
edab6137 777 }
7ea0d558 778
edab6137
LOK
779 iNow = GetTimeMs();
780 }
abbca718
LOK
781 }
782
1f0e9e0f 783 return bTransmitSucceeded && !bError;
abbca718
LOK
784}
785
0e7b6c54 786bool CCECProcessor::ParseMessage(const CCECAdapterMessage &msg)
abbca718 787{
855a3a98
LOK
788 bool bEom(false);
789 bool bIsError(msg.is_error());
60fa4578 790
0e7b6c54 791 if (msg.empty())
7ea0d558 792 return bEom;
abbca718 793
0e7b6c54 794 switch(msg.message())
abbca718 795 {
abbca718
LOK
796 case MSGCODE_FRAME_START:
797 {
ab1469a0 798 m_currentframe.Clear();
0e7b6c54 799 if (msg.size() >= 2)
abbca718 800 {
0e7b6c54
LOK
801 m_currentframe.initiator = msg.initiator();
802 m_currentframe.destination = msg.destination();
803 m_currentframe.ack = msg.ack();
804 m_currentframe.eom = msg.eom();
abbca718 805 }
855a3a98
LOK
806 if (m_currentframe.ack == true)
807 {
808 m_lastInitiator = m_currentframe.initiator;
809 m_busDevices[m_lastInitiator]->GetHandler()->HandlePoll(m_currentframe.initiator, m_currentframe.destination);
810 }
811 }
812 break;
813 case MSGCODE_RECEIVE_FAILED:
814 {
815 if (m_lastInitiator != CECDEVICE_UNKNOWN)
816 bIsError = m_busDevices[m_lastInitiator]->GetHandler()->HandleReceiveFailed();
abbca718
LOK
817 }
818 break;
819 case MSGCODE_FRAME_DATA:
820 {
0e7b6c54 821 if (msg.size() >= 2)
78e8010a 822 {
ab1469a0 823 m_currentframe.PushBack(msg[1]);
0e7b6c54 824 m_currentframe.eom = msg.eom();
abbca718 825 }
0e7b6c54 826 bEom = msg.eom();
abbca718 827 }
78e8010a 828 break;
abbca718
LOK
829 default:
830 break;
831 }
7ea0d558 832
855a3a98 833 m_controller->AddLog(bIsError ? CEC_LOG_WARNING : CEC_LOG_DEBUG, msg.ToString());
7ea0d558 834 return bEom;
abbca718
LOK
835}
836
e9de9629 837void CCECProcessor::ParseCommand(cec_command &command)
abbca718 838{
e9de9629 839 CStdString dataStr;
1d3ca3de 840 dataStr.Format(">> %1x%1x:%02x", command.initiator, command.destination, command.opcode);
e9de9629
LOK
841 for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++)
842 dataStr.AppendFormat(":%02x", (unsigned int)command.parameters[iPtr]);
1d3ca3de 843 m_controller->AddLog(CEC_LOG_TRAFFIC, dataStr.c_str());
dc113aca 844
7871d66e 845 if (!m_bMonitor && command.initiator >= CECDEVICE_TV && command.initiator <= CECDEVICE_BROADCAST)
e9de9629 846 m_busDevices[(uint8_t)command.initiator]->HandleCommand(command);
dc113aca
LOK
847}
848
6d858ba4
LOK
849cec_logical_addresses CCECProcessor::GetActiveDevices(void)
850{
851 cec_logical_addresses addresses;
988de7b9 852 addresses.Clear();
6d858ba4
LOK
853 for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
854 {
855 if (m_busDevices[iPtr]->GetStatus() == CEC_DEVICE_STATUS_PRESENT)
856 addresses.Set((cec_logical_address) iPtr);
857 }
858 return addresses;
859}
860
861bool CCECProcessor::IsActiveDevice(cec_logical_address address)
862{
863 return m_busDevices[address]->GetStatus() == CEC_DEVICE_STATUS_PRESENT;
864}
865
866bool CCECProcessor::IsActiveDeviceType(cec_device_type type)
867{
6d858ba4 868 for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
2813bd07
LOK
869 {
870 if (m_busDevices[iPtr]->GetType() == type && m_busDevices[iPtr]->GetStatus() == CEC_DEVICE_STATUS_PRESENT)
6d858ba4 871 return true;
2813bd07
LOK
872 }
873
6d858ba4
LOK
874 return false;
875}
876
0f23c85c
LOK
877uint16_t CCECProcessor::GetPhysicalAddress(void) const
878{
ab1469a0 879 if (!m_logicalAddresses.IsEmpty() && m_busDevices[m_logicalAddresses.primary])
16b1e052 880 return m_busDevices[m_logicalAddresses.primary]->GetPhysicalAddress(false);
cc60ab1c 881 return false;
0f23c85c
LOK
882}
883
e9de9629 884void CCECProcessor::SetCurrentButton(cec_user_control_code iButtonCode)
dc113aca 885{
e9de9629 886 m_controller->SetCurrentButton(iButtonCode);
dc113aca
LOK
887}
888
e9de9629 889void CCECProcessor::AddCommand(const cec_command &command)
dc113aca 890{
0544ff56 891 m_controller->AddCommand(command);
dc113aca
LOK
892}
893
95ba7a09
LOK
894void CCECProcessor::AddKey(cec_keypress &key)
895{
896 m_controller->AddKey(key);
897}
898
e9de9629 899void CCECProcessor::AddKey(void)
dc113aca 900{
e9de9629 901 m_controller->AddKey();
abbca718 902}
acec5f48 903
e9de9629 904void CCECProcessor::AddLog(cec_log_level level, const CStdString &strMessage)
acec5f48 905{
e9de9629 906 m_controller->AddLog(level, strMessage);
acec5f48 907}
06bfd4d7
LOK
908
909bool CCECProcessor::SetAckMask(uint16_t iMask)
910{
28352a04 911 bool bReturn(false);
06bfd4d7
LOK
912 CStdString strLog;
913 strLog.Format("setting ackmask to %2x", iMask);
914 m_controller->AddLog(CEC_LOG_DEBUG, strLog.c_str());
915
28352a04 916 CCECAdapterMessage *output = new CCECAdapterMessage;
06bfd4d7
LOK
917
918 output->push_back(MSGSTART);
919 output->push_escaped(MSGCODE_SET_ACK_MASK);
920 output->push_escaped(iMask >> 8);
921 output->push_escaped((uint8_t)iMask);
922 output->push_back(MSGEND);
923
28352a04 924 if ((bReturn = Transmit(output)) == false)
06bfd4d7 925 m_controller->AddLog(CEC_LOG_ERROR, "could not set the ackmask");
06bfd4d7 926
28352a04
LOK
927 delete output;
928
929 return bReturn;
06bfd4d7 930}
a33794d8
LOK
931
932bool CCECProcessor::SendKeypress(cec_logical_address iDestination, cec_user_control_code key, bool bWait /* = false */)
933{
934 return m_busDevices[iDestination]->SendKeypress(key, bWait);
935}
936
937bool CCECProcessor::SendKeyRelease(cec_logical_address iDestination, bool bWait /* = false */)
938{
939 return m_busDevices[iDestination]->SendKeyRelease(bWait);
940}
7c63a480 941
03ae897d
LOK
942const char *CCECProcessor::ToString(const cec_menu_state state)
943{
944 switch (state)
945 {
946 case CEC_MENU_STATE_ACTIVATED:
947 return "activated";
948 case CEC_MENU_STATE_DEACTIVATED:
949 return "deactivated";
950 default:
951 return "unknown";
952 }
953}
954
955const char *CCECProcessor::ToString(const cec_version version)
956{
957 switch (version)
958 {
959 case CEC_VERSION_1_2:
960 return "1.2";
961 case CEC_VERSION_1_2A:
962 return "1.2a";
963 case CEC_VERSION_1_3:
964 return "1.3";
965 case CEC_VERSION_1_3A:
966 return "1.3a";
967 case CEC_VERSION_1_4:
968 return "1.4";
969 default:
970 return "unknown";
971 }
972}
973
974const char *CCECProcessor::ToString(const cec_power_status status)
975{
976 switch (status)
977 {
978 case CEC_POWER_STATUS_ON:
979 return "on";
980 case CEC_POWER_STATUS_STANDBY:
981 return "standby";
982 case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY:
983 return "in transition from on to standby";
984 case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON:
985 return "in transition from standby to on";
986 default:
987 return "unknown";
988 }
989}
990
991const char *CCECProcessor::ToString(const cec_logical_address address)
992{
993 switch(address)
994 {
995 case CECDEVICE_AUDIOSYSTEM:
996 return "Audio";
997 case CECDEVICE_BROADCAST:
998 return "Broadcast";
999 case CECDEVICE_FREEUSE:
1000 return "Free use";
1001 case CECDEVICE_PLAYBACKDEVICE1:
1002 return "Playback 1";
1003 case CECDEVICE_PLAYBACKDEVICE2:
1004 return "Playback 2";
1005 case CECDEVICE_PLAYBACKDEVICE3:
1006 return "Playback 3";
1007 case CECDEVICE_RECORDINGDEVICE1:
1008 return "Recorder 1";
1009 case CECDEVICE_RECORDINGDEVICE2:
1010 return "Recorder 2";
1011 case CECDEVICE_RECORDINGDEVICE3:
1012 return "Recorder 3";
1013 case CECDEVICE_RESERVED1:
1014 return "Reserved 1";
1015 case CECDEVICE_RESERVED2:
1016 return "Reserved 2";
1017 case CECDEVICE_TUNER1:
1018 return "Tuner 1";
1019 case CECDEVICE_TUNER2:
1020 return "Tuner 2";
1021 case CECDEVICE_TUNER3:
1022 return "Tuner 3";
1023 case CECDEVICE_TUNER4:
1024 return "Tuner 4";
1025 case CECDEVICE_TV:
1026 return "TV";
1027 default:
1028 return "unknown";
1029 }
1030}
1031
1032const char *CCECProcessor::ToString(const cec_deck_control_mode mode)
1033{
1034 switch (mode)
1035 {
1036 case CEC_DECK_CONTROL_MODE_SKIP_FORWARD_WIND:
1037 return "skip forward wind";
1038 case CEC_DECK_CONTROL_MODE_EJECT:
1039 return "eject";
1040 case CEC_DECK_CONTROL_MODE_SKIP_REVERSE_REWIND:
1041 return "reverse rewind";
1042 case CEC_DECK_CONTROL_MODE_STOP:
1043 return "stop";
1044 default:
1045 return "unknown";
1046 }
1047}
1048
1049const char *CCECProcessor::ToString(const cec_deck_info status)
1050{
1051 switch (status)
1052 {
1053 case CEC_DECK_INFO_PLAY:
1054 return "play";
1055 case CEC_DECK_INFO_RECORD:
1056 return "record";
1057 case CEC_DECK_INFO_PLAY_REVERSE:
1058 return "play reverse";
1059 case CEC_DECK_INFO_STILL:
1060 return "still";
1061 case CEC_DECK_INFO_SLOW:
1062 return "slow";
1063 case CEC_DECK_INFO_SLOW_REVERSE:
1064 return "slow reverse";
1065 case CEC_DECK_INFO_FAST_FORWARD:
1066 return "fast forward";
1067 case CEC_DECK_INFO_FAST_REVERSE:
1068 return "fast reverse";
1069 case CEC_DECK_INFO_NO_MEDIA:
1070 return "no media";
1071 case CEC_DECK_INFO_STOP:
1072 return "stop";
1073 case CEC_DECK_INFO_SKIP_FORWARD_WIND:
1074 return "info skip forward wind";
1075 case CEC_DECK_INFO_SKIP_REVERSE_REWIND:
1076 return "info skip reverse rewind";
1077 case CEC_DECK_INFO_INDEX_SEARCH_FORWARD:
1078 return "info index search forward";
1079 case CEC_DECK_INFO_INDEX_SEARCH_REVERSE:
1080 return "info index search reverse";
1081 case CEC_DECK_INFO_OTHER_STATUS:
1082 return "other";
1083 default:
1084 return "unknown";
1085 }
1086}
1087
1088const char *CCECProcessor::ToString(const cec_opcode opcode)
1089{
1090 switch (opcode)
1091 {
1092 case CEC_OPCODE_ACTIVE_SOURCE:
1093 return "active source";
1094 case CEC_OPCODE_IMAGE_VIEW_ON:
1095 return "image view on";
1096 case CEC_OPCODE_TEXT_VIEW_ON:
1097 return "text view on";
1098 case CEC_OPCODE_INACTIVE_SOURCE:
1099 return "inactive source";
1100 case CEC_OPCODE_REQUEST_ACTIVE_SOURCE:
1101 return "request active source";
1102 case CEC_OPCODE_ROUTING_CHANGE:
1103 return "routing change";
1104 case CEC_OPCODE_ROUTING_INFORMATION:
1105 return "routing information";
1106 case CEC_OPCODE_SET_STREAM_PATH:
1107 return "set stream path";
1108 case CEC_OPCODE_STANDBY:
1109 return "standby";
1110 case CEC_OPCODE_RECORD_OFF:
1111 return "record off";
1112 case CEC_OPCODE_RECORD_ON:
1113 return "record on";
1114 case CEC_OPCODE_RECORD_STATUS:
1115 return "record status";
1116 case CEC_OPCODE_RECORD_TV_SCREEN:
1117 return "record tv screen";
1118 case CEC_OPCODE_CLEAR_ANALOGUE_TIMER:
1119 return "clear analogue timer";
1120 case CEC_OPCODE_CLEAR_DIGITAL_TIMER:
1121 return "clear digital timer";
1122 case CEC_OPCODE_CLEAR_EXTERNAL_TIMER:
1123 return "clear external timer";
1124 case CEC_OPCODE_SET_ANALOGUE_TIMER:
1125 return "set analogue timer";
1126 case CEC_OPCODE_SET_DIGITAL_TIMER:
1127 return "set digital timer";
1128 case CEC_OPCODE_SET_EXTERNAL_TIMER:
1129 return "set external timer";
1130 case CEC_OPCODE_SET_TIMER_PROGRAM_TITLE:
1131 return "set timer program title";
1132 case CEC_OPCODE_TIMER_CLEARED_STATUS:
1133 return "timer cleared status";
1134 case CEC_OPCODE_TIMER_STATUS:
1135 return "timer status";
1136 case CEC_OPCODE_CEC_VERSION:
1137 return "cec version";
1138 case CEC_OPCODE_GET_CEC_VERSION:
1139 return "get cec version";
1140 case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS:
1141 return "give physical address";
1142 case CEC_OPCODE_GET_MENU_LANGUAGE:
1143 return "get menu language";
1144 case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS:
1145 return "report physical address";
1146 case CEC_OPCODE_SET_MENU_LANGUAGE:
1147 return "set menu language";
1148 case CEC_OPCODE_DECK_CONTROL:
1149 return "deck control";
1150 case CEC_OPCODE_DECK_STATUS:
1151 return "deck status";
1152 case CEC_OPCODE_GIVE_DECK_STATUS:
1153 return "give deck status";
1154 case CEC_OPCODE_PLAY:
1155 return "play";
1156 case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS:
1157 return "give tuner status";
1158 case CEC_OPCODE_SELECT_ANALOGUE_SERVICE:
1159 return "select analogue service";
1160 case CEC_OPCODE_SELECT_DIGITAL_SERVICE:
1161 return "set digital service";
1162 case CEC_OPCODE_TUNER_DEVICE_STATUS:
1163 return "tuner device status";
1164 case CEC_OPCODE_TUNER_STEP_DECREMENT:
1165 return "tuner step decrement";
1166 case CEC_OPCODE_TUNER_STEP_INCREMENT:
1167 return "tuner step increment";
1168 case CEC_OPCODE_DEVICE_VENDOR_ID:
1169 return "device vendor id";
1170 case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID:
1171 return "give device vendor id";
1172 case CEC_OPCODE_VENDOR_COMMAND:
1173 return "vendor command";
1174 case CEC_OPCODE_VENDOR_COMMAND_WITH_ID:
1175 return "vendor command with id";
1176 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN:
1177 return "vendor remote button down";
1178 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP:
1179 return "vendor remote button up";
1180 case CEC_OPCODE_SET_OSD_STRING:
1181 return "set osd string";
1182 case CEC_OPCODE_GIVE_OSD_NAME:
1183 return "give osd name";
1184 case CEC_OPCODE_SET_OSD_NAME:
1185 return "set osd name";
1186 case CEC_OPCODE_MENU_REQUEST:
1187 return "menu request";
1188 case CEC_OPCODE_MENU_STATUS:
1189 return "menu status";
1190 case CEC_OPCODE_USER_CONTROL_PRESSED:
1191 return "user control pressed";
1192 case CEC_OPCODE_USER_CONTROL_RELEASE:
1193 return "user control release";
1194 case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS:
1195 return "give device power status";
1196 case CEC_OPCODE_REPORT_POWER_STATUS:
1197 return "report power status";
1198 case CEC_OPCODE_FEATURE_ABORT:
1199 return "feature abort";
1200 case CEC_OPCODE_ABORT:
1201 return "abort";
1202 case CEC_OPCODE_GIVE_AUDIO_STATUS:
1203 return "give audio status";
1204 case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS:
1205 return "give audio mode status";
1206 case CEC_OPCODE_REPORT_AUDIO_STATUS:
1207 return "report audio status";
1208 case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE:
1209 return "set system audio mode";
1210 case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST:
1211 return "system audio mode request";
1212 case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS:
1213 return "system audio mode status";
1214 case CEC_OPCODE_SET_AUDIO_RATE:
1215 return "set audio rate";
1216 default:
1217 return "UNKNOWN";
1218 }
1219}
1220
1221const char *CCECProcessor::ToString(const cec_system_audio_status mode)
1222{
1223 switch(mode)
1224 {
1225 case CEC_SYSTEM_AUDIO_STATUS_ON:
1226 return "on";
1227 case CEC_SYSTEM_AUDIO_STATUS_OFF:
1228 return "off";
1229 default:
1230 return "unknown";
1231 }
1232}
1233
1234const char *CCECProcessor::ToString(const cec_audio_status status)
1235{
1236 // TODO this is a mask
1237 return "TODO";
1238}
1239
1240const char *CCECProcessor::ToString(const cec_vendor_id vendor)
1241{
1242 switch (vendor)
1243 {
1244 case CEC_VENDOR_SAMSUNG:
1245 return "Samsung";
1246 case CEC_VENDOR_LG:
1247 return "LG";
1248 case CEC_VENDOR_PANASONIC:
1249 return "Panasonic";
1250 case CEC_VENDOR_PIONEER:
1251 return "Pioneer";
1252 case CEC_VENDOR_ONKYO:
1253 return "Onkyo";
1254 case CEC_VENDOR_YAMAHA:
1255 return "Yamaha";
ec0deac1
LOK
1256 case CEC_VENDOR_PHILIPS:
1257 return "Philips";
03ae897d
LOK
1258 default:
1259 return "Unknown";
1260 }
1261}
1262
7c63a480
LOK
1263void *CCECBusScan::Process(void)
1264{
1265 CCECBusDevice *device(NULL);
5e5637c6 1266 while (!IsStopped())
7c63a480 1267 {
5e5637c6 1268 for (unsigned int iPtr = 0; iPtr < 15 && !IsStopped(); iPtr++)
7c63a480 1269 {
5e5637c6
LOK
1270 device = m_processor->m_busDevices[iPtr];
1271 if (device && device->GetStatus() == CEC_DEVICE_STATUS_PRESENT)
1272 {
1273 if (!IsStopped())
0b775bf2 1274 device->GetPhysicalAddress(false);
5e5637c6 1275 Sleep(5);
7c63a480 1276
5e5637c6
LOK
1277 if (!IsStopped())
1278 device->GetCecVersion();
1279 Sleep(5);
7c63a480 1280
5e5637c6
LOK
1281 if (!IsStopped())
1282 device->GetVendorId();
1283 Sleep(5);
1284 }
7c63a480 1285 }
34d46707 1286 Sleep(5000);
7c63a480
LOK
1287 }
1288 return NULL;
1289}
1113cb7d
LOK
1290
1291bool CCECProcessor::StartBootloader(void)
1292{
1293 return m_communication->StartBootloader();
1294}
1295
1296bool CCECProcessor::PingAdapter(void)
1297{
1298 return m_communication->PingAdapter();
1299}