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