cec: read the persisted settings from the ROM, and update it in libcec_configuration...
[deb_libcec.git] / src / lib / CECProcessor.cpp
CommitLineData
abbca718
LOK
1/*
2 * This file is part of the libCEC(R) library.
3 *
b492c10e 4 * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved.
abbca718
LOK
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
7bb4ed43 35#include "adapter/USBCECAdapterCommunication.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"
ba65909d 44#include "platform/util/timeutils.h"
abbca718
LOK
45
46using namespace CEC;
47using namespace std;
f00ff009 48using namespace PLATFORM;
abbca718 49
3efda01a 50CCECProcessor::CCECProcessor(CLibCEC *controller, libcec_configuration *configuration) :
80726797 51 m_bConnectionOpened(false),
caca2d81 52 m_bInitialised(false),
caca2d81
LOK
53 m_communication(NULL),
54 m_controller(controller),
55 m_bMonitor(false),
56 m_iStandardLineTimeout(3),
57 m_iRetryLineTimeout(3),
30b4aac0 58 m_iLastTransmission(0)
caca2d81 59{
caca2d81 60 CreateBusDevices();
30b4aac0 61 m_configuration.Clear();
41e3372a 62 m_configuration.serverVersion = configuration->serverVersion;
30b4aac0
LOK
63 SetConfiguration(configuration);
64
65 if (m_configuration.tvVendor != CEC_VENDOR_UNKNOWN)
ed63a515 66 m_busDevices[CECDEVICE_TV]->ReplaceHandler(false);
caca2d81
LOK
67}
68
7bdfd76c 69CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, const cec_device_type_list &types, uint16_t iPhysicalAddress) :
80726797 70 m_bConnectionOpened(false),
b64db02e 71 m_bInitialised(false),
99666519 72 m_communication(NULL),
f8513317 73 m_controller(controller),
dcd240b2
LOK
74 m_bMonitor(false),
75 m_iStandardLineTimeout(3),
5f316715 76 m_iRetryLineTimeout(3),
30b4aac0 77 m_iLastTransmission(0)
f8513317 78{
30b4aac0 79 m_configuration.Clear();
2e82cff0 80 m_configuration.serverVersion = CEC_SERVER_VERSION_1_5_2;
30b4aac0
LOK
81
82 // client version < 1.5.0
3efda01a 83 m_configuration.clientVersion = (uint32_t)CEC_CLIENT_VERSION_PRE_1_5;
30b4aac0
LOK
84 snprintf(m_configuration.strDeviceName, 13, "%s", strDeviceName);
85 m_configuration.deviceTypes = types;
86 m_configuration.iPhysicalAddress = iPhysicalAddress;
87 m_configuration.baseDevice = (cec_logical_address)CEC_DEFAULT_BASE_DEVICE;
88 m_configuration.iHDMIPort = CEC_DEFAULT_HDMI_PORT;
89
90 if (m_configuration.deviceTypes.IsEmpty())
91 m_configuration.deviceTypes.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE);
caca2d81
LOK
92 CreateBusDevices();
93}
94
95void CCECProcessor::CreateBusDevices(void)
96{
f8513317 97 for (int iPtr = 0; iPtr < 16; iPtr++)
51b2a094
LOK
98 {
99 switch(iPtr)
100 {
101 case CECDEVICE_AUDIOSYSTEM:
5d5a2dc2 102 m_busDevices[iPtr] = new CCECAudioSystem(this, (cec_logical_address) iPtr, 0xFFFF);
51b2a094
LOK
103 break;
104 case CECDEVICE_PLAYBACKDEVICE1:
105 case CECDEVICE_PLAYBACKDEVICE2:
106 case CECDEVICE_PLAYBACKDEVICE3:
5d5a2dc2 107 m_busDevices[iPtr] = new CCECPlaybackDevice(this, (cec_logical_address) iPtr, 0xFFFF);
51b2a094
LOK
108 break;
109 case CECDEVICE_RECORDINGDEVICE1:
110 case CECDEVICE_RECORDINGDEVICE2:
111 case CECDEVICE_RECORDINGDEVICE3:
5d5a2dc2 112 m_busDevices[iPtr] = new CCECRecordingDevice(this, (cec_logical_address) iPtr, 0xFFFF);
51b2a094
LOK
113 break;
114 case CECDEVICE_TUNER1:
115 case CECDEVICE_TUNER2:
116 case CECDEVICE_TUNER3:
117 case CECDEVICE_TUNER4:
5d5a2dc2 118 m_busDevices[iPtr] = new CCECTuner(this, (cec_logical_address) iPtr, 0xFFFF);
51b2a094
LOK
119 break;
120 case CECDEVICE_TV:
121 m_busDevices[iPtr] = new CCECTV(this, (cec_logical_address) iPtr, 0);
122 break;
123 default:
5d5a2dc2 124 m_busDevices[iPtr] = new CCECBusDevice(this, (cec_logical_address) iPtr, 0xFFFF);
51b2a094
LOK
125 break;
126 }
127 }
f8513317
LOK
128}
129
2abe74eb 130CCECProcessor::~CCECProcessor(void)
abbca718 131{
eca71746 132 Close();
7c63a480 133
d1998c7b
LOK
134 for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
135 delete m_busDevices[iPtr];
abbca718
LOK
136}
137
eca71746
LOK
138void CCECProcessor::Close(void)
139{
f9e01dac
LOK
140 StopThread(false);
141 SetInitialised(false);
eca71746
LOK
142 StopThread();
143
80726797
LOK
144 bool bClose(false);
145 {
146 CLockObject lock(m_mutex);
147 bClose = m_bConnectionOpened;
148 m_bConnectionOpened = false;
149 }
150
151 if (bClose && m_communication)
eca71746 152 {
cb4ee028 153 m_communication->PersistConfiguration(&m_configuration);
eca71746
LOK
154 m_communication->Close();
155 delete m_communication;
156 m_communication = NULL;
157 }
158}
159
578c3905 160bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint32_t iTimeoutMs)
abbca718 161{
a674fd68 162 bool bReturn(false);
80726797
LOK
163 Close();
164
578c3905 165 {
80726797
LOK
166 CLockObject lock(m_mutex);
167 if (m_bConnectionOpened)
168 {
169 CLibCEC::AddLog(CEC_LOG_ERROR, "connection already opened");
170 return false;
171 }
172 m_communication = new CUSBCECAdapterCommunication(this, strPort, iBaudRate);
173 m_bConnectionOpened = (m_communication != NULL);
578c3905 174 }
1113cb7d 175
578c3905
LOK
176 /* check for an already opened connection */
177 if (m_communication->IsOpen())
1113cb7d 178 {
5477a250 179 CLibCEC::AddLog(CEC_LOG_ERROR, "connection already opened");
578c3905
LOK
180 return bReturn;
181 }
abbca718 182
3b5e433a 183 CTimeout timeout(iTimeoutMs > 0 ? iTimeoutMs : CEC_DEFAULT_TRANSMIT_WAIT);
c520af4f 184
578c3905 185 /* open a new connection */
efed01e1 186 unsigned iConnectTry(0);
3b5e433a 187 while (timeout.TimeLeft() > 0 && (bReturn = m_communication->Open(this, (timeout.TimeLeft() / CEC_CONNECT_TRIES))) == false)
3d78df91
LOK
188 {
189 CLibCEC::AddLog(CEC_LOG_ERROR, "could not open a connection (try %d)", ++iConnectTry);
d55f263f 190 m_communication->Close();
a88017b8 191 CEvent::Sleep(1000);
3d78df91 192 }
56035c86 193
efed01e1 194 if (bReturn)
3efda01a 195 CLibCEC::AddLog(CEC_LOG_NOTICE, "connected to the CEC adapter. firmware version = %d, client version = %s", m_communication->GetFirmwareVersion(), ToString((cec_client_version)m_configuration.clientVersion));
3d78df91 196
12a36be9
LOK
197 if (m_configuration.bGetSettingsFromROM == 1)
198 m_communication->GetConfiguration(&m_configuration);
199
578c3905
LOK
200 return bReturn;
201}
202
0cfdeb5a
LOK
203bool CCECProcessor::IsInitialised(void)
204{
205 CLockObject lock(m_mutex);
206 return m_bInitialised;
207}
208
2db8981f 209void CCECProcessor::SetInitialised(bool bSetTo /* = true */)
578c3905 210{
578c3905 211 CLockObject lock(m_mutex);
2db8981f
LOK
212 m_bInitialised = bSetTo;
213}
578c3905 214
2db8981f
LOK
215bool CCECProcessor::Initialise(void)
216{
217 bool bReturn(false);
578c3905 218 {
2db8981f 219 CLockObject lock(m_mutex);
dd18e809
LOK
220 if (!m_configuration.logicalAddresses.IsEmpty())
221 m_configuration.logicalAddresses.Clear();
578c3905 222
2db8981f
LOK
223 if (!FindLogicalAddresses())
224 {
5477a250 225 CLibCEC::AddLog(CEC_LOG_ERROR, "could not detect our logical addresses");
2db8981f
LOK
226 return bReturn;
227 }
228
229 /* only set our OSD name for the primary device */
dd18e809 230 m_busDevices[m_configuration.logicalAddresses.primary]->m_strDeviceName = m_configuration.strDeviceName;
80726797
LOK
231
232 /* make the primary device the active source if the option is set */
233 if (m_configuration.bActivateSource == 1)
dd18e809 234 m_busDevices[m_configuration.logicalAddresses.primary]->m_bActiveSource = true;
2db8981f 235 }
578c3905
LOK
236
237 /* get the vendor id from the TV, so we are using the correct handler */
30b4aac0 238 m_busDevices[CECDEVICE_TV]->GetVendorId();
578c3905 239
30b4aac0 240 if (m_configuration.iPhysicalAddress != 0)
4f362964 241 {
30b4aac0 242 CLibCEC::AddLog(CEC_LOG_NOTICE, "setting the physical address to %4x", m_configuration.iPhysicalAddress);
dd18e809
LOK
243 m_busDevices[m_configuration.logicalAddresses.primary]->m_iPhysicalAddress = m_configuration.iPhysicalAddress;
244 if ((bReturn = m_busDevices[m_configuration.logicalAddresses.primary]->TransmitPhysicalAddress()) == false)
30b4aac0 245 CLibCEC::AddLog(CEC_LOG_ERROR, "unable to set the physical address to %4x", m_configuration.iPhysicalAddress);
4f362964 246 }
30b4aac0
LOK
247 else if (m_configuration.iPhysicalAddress == 0 && (bReturn = SetHDMIPort(m_configuration.baseDevice, m_configuration.iHDMIPort, true)) == false)
248 CLibCEC::AddLog(CEC_LOG_ERROR, "unable to set HDMI port %d on %s (%x)", m_configuration.iHDMIPort, ToString(m_configuration.baseDevice), (uint8_t)m_configuration.baseDevice);
2db8981f 249
80726797 250 if (m_configuration.bActivateSource == 1)
dd18e809 251 m_busDevices[m_configuration.logicalAddresses.primary]->ActivateSource();
80726797 252
2db8981f 253 SetInitialised(bReturn);
ba73be2f
LOK
254 if (bReturn)
255 CLibCEC::ConfigurationChanged(m_configuration);
578c3905
LOK
256
257 return bReturn;
258}
259
260bool CCECProcessor::Start(const char *strPort, uint16_t iBaudRate /* = 38400 */, uint32_t iTimeoutMs /* = 10000 */)
261{
262 bool bReturn(false);
263
264 {
265 CLockObject lock(m_mutex);
266 if (!OpenConnection(strPort, iBaudRate, iTimeoutMs))
a674fd68 267 return bReturn;
994dbaaa 268
a674fd68 269 /* create the processor thread */
8e57f83c 270 if (!CreateThread())
a674fd68 271 {
5477a250 272 CLibCEC::AddLog(CEC_LOG_ERROR, "could not create a processor thread");
a674fd68 273 return bReturn;
994dbaaa 274 }
a674fd68
LOK
275 }
276
578c3905 277 if ((bReturn = Initialise()) == false)
a674fd68 278 {
5477a250 279 CLibCEC::AddLog(CEC_LOG_ERROR, "could not create a processor thread");
578c3905 280 StopThread(true);
a674fd68
LOK
281 }
282 else
283 {
5477a250 284 CLibCEC::AddLog(CEC_LOG_DEBUG, "processor thread started");
a674fd68
LOK
285 }
286
287 return bReturn;
abbca718
LOK
288}
289
b58d9277 290bool CCECProcessor::TryLogicalAddress(cec_logical_address address)
f8513317 291{
93fff5c1 292 if (m_busDevices[address]->TryLogicalAddress())
f8513317 293 {
dd18e809 294 m_configuration.logicalAddresses.Set(address);
f8513317
LOK
295 return true;
296 }
297
f8513317
LOK
298 return false;
299}
300
b58d9277 301bool CCECProcessor::FindLogicalAddressRecordingDevice(void)
f8513317 302{
5477a250 303 CLibCEC::AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'recording device'");
b58d9277
LOK
304 return TryLogicalAddress(CECDEVICE_RECORDINGDEVICE1) ||
305 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE2) ||
306 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE3);
f8513317
LOK
307}
308
b58d9277 309bool CCECProcessor::FindLogicalAddressTuner(void)
f8513317 310{
5477a250 311 CLibCEC::AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'tuner'");
b58d9277
LOK
312 return TryLogicalAddress(CECDEVICE_TUNER1) ||
313 TryLogicalAddress(CECDEVICE_TUNER2) ||
314 TryLogicalAddress(CECDEVICE_TUNER3) ||
315 TryLogicalAddress(CECDEVICE_TUNER4);
f8513317
LOK
316}
317
b58d9277 318bool CCECProcessor::FindLogicalAddressPlaybackDevice(void)
f8513317 319{
5477a250 320 CLibCEC::AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'playback device'");
b58d9277
LOK
321 return TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE1) ||
322 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE2) ||
323 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE3);
f8513317
LOK
324}
325
b58d9277 326bool CCECProcessor::FindLogicalAddressAudioSystem(void)
f8513317 327{
5477a250 328 CLibCEC::AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'audio'");
b58d9277 329 return TryLogicalAddress(CECDEVICE_AUDIOSYSTEM);
f8513317
LOK
330}
331
3e61b350
LOK
332bool CCECProcessor::ChangeDeviceType(cec_device_type from, cec_device_type to)
333{
334 bool bChanged(false);
335
5477a250 336 CLibCEC::AddLog(CEC_LOG_NOTICE, "changing device type '%s' into '%s'", ToString(from), ToString(to));
3e61b350 337
f00ff009 338 CLockObject lock(m_mutex);
3e61b350 339 CCECBusDevice *previousDevice = GetDeviceByType(from);
dd18e809 340 m_configuration.logicalAddresses.primary = CECDEVICE_UNKNOWN;
3e61b350
LOK
341
342 for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
343 {
30b4aac0 344 if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_RESERVED)
3e61b350
LOK
345 continue;
346
30b4aac0 347 if (m_configuration.deviceTypes.types[iPtr] == from)
3e61b350
LOK
348 {
349 bChanged = true;
30b4aac0 350 m_configuration.deviceTypes.types[iPtr] = to;
3e61b350 351 }
30b4aac0 352 else if (m_configuration.deviceTypes.types[iPtr] == to && bChanged)
3e61b350 353 {
30b4aac0 354 m_configuration.deviceTypes.types[iPtr] = CEC_DEVICE_TYPE_RESERVED;
3e61b350
LOK
355 }
356 }
357
358 if (bChanged)
359 {
360 FindLogicalAddresses();
361
362 CCECBusDevice *newDevice = GetDeviceByType(to);
363 if (previousDevice && newDevice)
364 {
365 newDevice->SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC);
4478bc79 366 previousDevice->SetDeviceStatus(CEC_DEVICE_STATUS_NOT_PRESENT);
3e61b350
LOK
367
368 newDevice->SetCecVersion(previousDevice->GetCecVersion(false));
369 previousDevice->SetCecVersion(CEC_VERSION_UNKNOWN);
370
371 newDevice->SetMenuLanguage(previousDevice->GetMenuLanguage(false));
372 cec_menu_language lang;
373 lang.device = previousDevice->GetLogicalAddress();
374 for (unsigned int iPtr = 0; iPtr < 4; iPtr++)
375 lang.language[iPtr] = '?';
376 lang.language[3] = 0;
377 previousDevice->SetMenuLanguage(lang);
378
379 newDevice->SetMenuState(previousDevice->GetMenuState());
380 previousDevice->SetMenuState(CEC_MENU_STATE_DEACTIVATED);
381
382 newDevice->SetOSDName(previousDevice->GetOSDName(false));
383 previousDevice->SetOSDName(ToString(previousDevice->GetLogicalAddress()));
384
385 newDevice->SetPhysicalAddress(previousDevice->GetPhysicalAddress(false));
386 previousDevice->SetPhysicalAddress(0xFFFF);
387
388 newDevice->SetPowerStatus(previousDevice->GetPowerStatus(false));
389 previousDevice->SetPowerStatus(CEC_POWER_STATUS_UNKNOWN);
390
391 newDevice->SetVendorId(previousDevice->GetVendorId(false));
392 previousDevice->SetVendorId(CEC_VENDOR_UNKNOWN);
393
394 if ((from == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || from == CEC_DEVICE_TYPE_RECORDING_DEVICE) &&
395 (to == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || to == CEC_DEVICE_TYPE_RECORDING_DEVICE))
396 {
397 ((CCECPlaybackDevice *) newDevice)->SetDeckControlMode(((CCECPlaybackDevice *) previousDevice)->GetDeckControlMode());
398 ((CCECPlaybackDevice *) previousDevice)->SetDeckControlMode(CEC_DECK_CONTROL_MODE_STOP);
399
400 ((CCECPlaybackDevice *) newDevice)->SetDeckStatus(((CCECPlaybackDevice *) previousDevice)->GetDeckStatus());
401 ((CCECPlaybackDevice *) previousDevice)->SetDeckStatus(CEC_DECK_INFO_STOP);
402 }
403 }
404 }
405
406 return true;
407}
408
f8513317
LOK
409bool CCECProcessor::FindLogicalAddresses(void)
410{
411 bool bReturn(true);
dd18e809 412 m_configuration.logicalAddresses.Clear();
f8513317 413
30b4aac0 414 if (m_configuration.deviceTypes.IsEmpty())
c39611ec
LOK
415 {
416 CLibCEC::AddLog(CEC_LOG_ERROR, "no device types set");
417 return false;
418 }
419
f8513317
LOK
420 for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
421 {
30b4aac0 422 if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_RESERVED)
f8513317
LOK
423 continue;
424
30b4aac0 425 CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - device %d: type %d", __FUNCTION__, iPtr, m_configuration.deviceTypes.types[iPtr]);
f8513317 426
30b4aac0 427 if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_RECORDING_DEVICE)
b58d9277 428 bReturn &= FindLogicalAddressRecordingDevice();
30b4aac0 429 if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_TUNER)
b58d9277 430 bReturn &= FindLogicalAddressTuner();
30b4aac0 431 if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_PLAYBACK_DEVICE)
b58d9277 432 bReturn &= FindLogicalAddressPlaybackDevice();
30b4aac0 433 if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
b58d9277 434 bReturn &= FindLogicalAddressAudioSystem();
f8513317
LOK
435 }
436
a674fd68 437 if (bReturn)
dd18e809 438 SetAckMask(m_configuration.logicalAddresses.AckMask());
a674fd68 439
f8513317
LOK
440 return bReturn;
441}
442
a3ffc068
LOK
443void CCECProcessor::ReplaceHandlers(void)
444{
0cfdeb5a
LOK
445 if (!IsInitialised())
446 return;
a3ffc068 447 for (uint8_t iPtr = 0; iPtr <= CECDEVICE_PLAYBACKDEVICE3; iPtr++)
591170fd 448 m_busDevices[iPtr]->ReplaceHandler(m_bInitialised);
a3ffc068
LOK
449}
450
b1f94db1
LOK
451bool CCECProcessor::OnCommandReceived(const cec_command &command)
452{
f6b94ad2 453 ParseCommand(command);
b1f94db1
LOK
454 return true;
455}
456
2abe74eb 457void *CCECProcessor::Process(void)
f99bc831 458{
8e57f83c 459 CLibCEC::AddLog(CEC_LOG_DEBUG, "processor thread started");
abbca718 460
b1f94db1 461 while (!IsStopped() && m_communication->IsOpen())
abbca718 462 {
f0154449
LOK
463 if (IsInitialised())
464 {
465 ReplaceHandlers();
b5f34cf9 466
f0154449
LOK
467 m_controller->CheckKeypressTimeout();
468 }
b1f94db1 469 Sleep(5);
abbca718
LOK
470 }
471
60fa4578 472 return NULL;
abbca718
LOK
473}
474
18203d17 475bool CCECProcessor::SetActiveSource(cec_device_type type /* = CEC_DEVICE_TYPE_RESERVED */)
abbca718 476{
8ac9c610
LOK
477 bool bReturn(false);
478
60fa4578 479 if (!IsRunning())
8ac9c610 480 return bReturn;
f99bc831 481
dd18e809 482 cec_logical_address addr = m_configuration.logicalAddresses.primary;
04437dcf 483
18203d17
LOK
484 if (type != CEC_DEVICE_TYPE_RESERVED)
485 {
90ea9066 486 for (uint8_t iPtr = 0; iPtr <= 11; iPtr++)
18203d17 487 {
dd18e809 488 if (m_configuration.logicalAddresses[iPtr] && m_busDevices[iPtr]->m_type == type)
18203d17
LOK
489 {
490 addr = (cec_logical_address) iPtr;
491 break;
492 }
493 }
494 }
495
37b0c572 496 m_busDevices[addr]->SetActiveSource();
d383d6d0 497 if (m_busDevices[addr]->GetPhysicalAddress(false) != 0xFFFF)
bbc71623 498 bReturn = m_busDevices[addr]->ActivateSource();
8d915412
LOK
499
500 return bReturn;
18203d17
LOK
501}
502
37b0c572
LOK
503bool CCECProcessor::SetActiveSource(uint16_t iStreamPath)
504{
505 bool bReturn(false);
506
507 CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamPath);
508 if (device)
509 {
510 device->SetActiveSource();
511 bReturn = true;
512 }
513
514 return bReturn;
515}
516
dcd240b2
LOK
517void CCECProcessor::SetStandardLineTimeout(uint8_t iTimeout)
518{
f00ff009 519 CLockObject lock(m_mutex);
dcd240b2
LOK
520 m_iStandardLineTimeout = iTimeout;
521}
522
523void CCECProcessor::SetRetryLineTimeout(uint8_t iTimeout)
524{
f00ff009 525 CLockObject lock(m_mutex);
dcd240b2
LOK
526 m_iRetryLineTimeout = iTimeout;
527}
528
18203d17
LOK
529bool CCECProcessor::SetActiveView(void)
530{
8670c970 531 CLibCEC::AddLog(CEC_LOG_WARNING, "deprecated method %s called", __FUNCTION__);
30b4aac0 532 return SetActiveSource(m_configuration.deviceTypes.IsEmpty() ? CEC_DEVICE_TYPE_RESERVED : m_configuration.deviceTypes[0]);
8ac9c610
LOK
533}
534
28fa6c97 535bool CCECProcessor::SetDeckControlMode(cec_deck_control_mode mode, bool bSendUpdate /* = true */)
a9232a79
LOK
536{
537 bool bReturn(false);
538
539 CCECBusDevice *device = GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
540 if (device)
541 {
542 ((CCECPlaybackDevice *) device)->SetDeckControlMode(mode);
28fa6c97
LOK
543 if (bSendUpdate)
544 ((CCECPlaybackDevice *) device)->TransmitDeckStatus(CECDEVICE_TV);
a9232a79
LOK
545 bReturn = true;
546 }
547
548 return bReturn;
549}
550
28fa6c97 551bool CCECProcessor::SetDeckInfo(cec_deck_info info, bool bSendUpdate /* = true */)
a9232a79
LOK
552{
553 bool bReturn(false);
554
555 CCECBusDevice *device = GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
556 if (device)
557 {
558 ((CCECPlaybackDevice *) device)->SetDeckStatus(info);
28fa6c97
LOK
559 if (bSendUpdate)
560 ((CCECPlaybackDevice *) device)->TransmitDeckStatus(CECDEVICE_TV);
a9232a79
LOK
561 bReturn = true;
562 }
563
564 return bReturn;
565}
566
d2f1c157 567bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort, bool bForce /* = false */)
16b1e052
LOK
568{
569 bool bReturn(false);
570
8670c970
LOK
571 {
572 CLockObject lock(m_mutex);
573 m_configuration.baseDevice = iBaseDevice;
574 m_configuration.iHDMIPort = iPort;
8670c970
LOK
575 }
576
8e57f83c 577 if (!IsRunning() && !bForce)
89b3c9df 578 return true;
16b1e052 579
5477a250 580 CLibCEC::AddLog(CEC_LOG_DEBUG, "setting HDMI port to %d on device %s (%d)", iPort, ToString(iBaseDevice), (int)iBaseDevice);
56035c86 581
16b1e052 582 uint16_t iPhysicalAddress(0);
1e7afacd 583 if (iBaseDevice > CECDEVICE_TV)
5d0c1164 584 {
1e7afacd 585 iPhysicalAddress = m_busDevices[iBaseDevice]->GetPhysicalAddress();
5d0c1164 586 }
1e7afacd 587
a674fd68 588 if (iPhysicalAddress < 0xffff)
1e7afacd 589 {
1e7afacd 590 if (iPhysicalAddress == 0)
5d355340 591 iPhysicalAddress += 0x1000 * iPort;
1e7afacd 592 else if (iPhysicalAddress % 0x1000 == 0)
5d355340 593 iPhysicalAddress += 0x100 * iPort;
1e7afacd 594 else if (iPhysicalAddress % 0x100 == 0)
5d355340 595 iPhysicalAddress += 0x10 * iPort;
1e7afacd 596 else if (iPhysicalAddress % 0x10 == 0)
5d355340 597 iPhysicalAddress += iPort;
1e7afacd 598
5d355340 599 bReturn = true;
16b1e052
LOK
600 }
601
a674fd68 602 if (!bReturn)
5477a250 603 CLibCEC::AddLog(CEC_LOG_ERROR, "failed to set the physical address");
f070564b 604 else
f070564b 605 SetPhysicalAddress(iPhysicalAddress);
a674fd68 606
16b1e052
LOK
607 return bReturn;
608}
609
45b97de7 610bool CCECProcessor::PhysicalAddressInUse(uint16_t iPhysicalAddress)
16b1e052 611{
9fd73dd4 612 for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
16b1e052
LOK
613 {
614 if (m_busDevices[iPtr]->GetPhysicalAddress(false) == iPhysicalAddress)
615 return true;
616 }
617 return false;
618}
619
ab27363d 620bool CCECProcessor::TransmitInactiveSource(void)
abbca718 621{
60fa4578 622 if (!IsRunning())
f99bc831
LOK
623 return false;
624
dd18e809
LOK
625 if (!m_configuration.logicalAddresses.IsEmpty() && m_busDevices[m_configuration.logicalAddresses.primary])
626 return m_busDevices[m_configuration.logicalAddresses.primary]->TransmitInactiveSource();
cc60ab1c 627 return false;
abbca718
LOK
628}
629
9dee1670 630void CCECProcessor::LogOutput(const cec_command &data)
abbca718 631{
1d3ca3de 632 CStdString strTx;
57f45e6c
LOK
633 strTx.Format("<< %02x", ((uint8_t)data.initiator << 4) + (uint8_t)data.destination);
634 if (data.opcode_set)
635 strTx.AppendFormat(":%02x", (uint8_t)data.opcode);
9dee1670 636
06a1f7ce 637 for (uint8_t iPtr = 0; iPtr < data.parameters.size; iPtr++)
1d3ca3de 638 strTx.AppendFormat(":%02x", data.parameters[iPtr]);
5477a250 639 CLibCEC::AddLog(CEC_LOG_TRAFFIC, strTx.c_str());
9dee1670 640}
2abe74eb 641
06bfd4d7 642bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress)
abbca718 643{
f00ff009 644 CLockObject lock(m_mutex);
dd18e809 645 if (m_configuration.logicalAddresses.primary != iLogicalAddress)
06775107 646 {
5477a250 647 CLibCEC::AddLog(CEC_LOG_NOTICE, "<< setting primary logical address to %1x", iLogicalAddress);
dd18e809
LOK
648 m_configuration.logicalAddresses.primary = iLogicalAddress;
649 m_configuration.logicalAddresses.Set(iLogicalAddress);
650 return SetAckMask(m_configuration.logicalAddresses.AckMask());
06775107 651 }
2abe74eb 652
06bfd4d7 653 return true;
abbca718 654}
825ddb96 655
28fa6c97
LOK
656bool CCECProcessor::SetMenuState(cec_menu_state state, bool bSendUpdate /* = true */)
657{
658 for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
659 {
dd18e809 660 if (m_configuration.logicalAddresses[iPtr])
28fa6c97
LOK
661 m_busDevices[iPtr]->SetMenuState(state);
662 }
663
664 if (bSendUpdate)
dd18e809 665 m_busDevices[m_configuration.logicalAddresses.primary]->TransmitMenuState(CECDEVICE_TV);
28fa6c97
LOK
666
667 return true;
668}
669
bebb19dc 670bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress, bool bSendUpdate /* = true */)
2492216a 671{
f070564b
LOK
672 bool bSendActiveView(false);
673 bool bReturn(false);
4d6f5ac7 674 cec_logical_addresses sendUpdatesTo;
ded7e7ce 675 sendUpdatesTo.Clear();
ff684fef 676
f070564b 677 {
f00ff009 678 CLockObject lock(m_mutex);
30b4aac0 679 m_configuration.iPhysicalAddress = iPhysicalAddress;
30a09f32 680 CLibCEC::AddLog(CEC_LOG_DEBUG, "setting physical address to '%4x'", iPhysicalAddress);
4f362964 681
dd18e809 682 if (!m_configuration.logicalAddresses.IsEmpty())
f070564b
LOK
683 {
684 bool bWasActiveSource(false);
685 for (uint8_t iPtr = 0; iPtr < 15; iPtr++)
dd18e809 686 if (m_configuration.logicalAddresses[iPtr])
f070564b
LOK
687 {
688 bWasActiveSource |= m_busDevices[iPtr]->IsActiveSource();
689 m_busDevices[iPtr]->SetInactiveSource();
690 m_busDevices[iPtr]->SetPhysicalAddress(iPhysicalAddress);
691 if (bSendUpdate)
4d6f5ac7 692 sendUpdatesTo.Set((cec_logical_address)iPtr);
f070564b
LOK
693 }
694
695 bSendActiveView = bWasActiveSource && bSendUpdate;
696 bReturn = true;
697 }
cc60ab1c 698 }
f070564b 699
4d6f5ac7
LOK
700 for (uint8_t iPtr = 0; iPtr < 15; iPtr++)
701 if (sendUpdatesTo[iPtr])
702 m_busDevices[iPtr]->TransmitPhysicalAddress();
703
f070564b
LOK
704 if (bSendActiveView)
705 SetActiveView();
706
32403cc3
LOK
707 if (bReturn)
708 CLibCEC::ConfigurationChanged(m_configuration);
709
f070564b 710 return bReturn;
1969b140
LOK
711}
712
8b7e5ff6
LOK
713bool CCECProcessor::SwitchMonitoring(bool bEnable)
714{
5477a250 715 CLibCEC::AddLog(CEC_LOG_NOTICE, "== %s monitoring mode ==", bEnable ? "enabling" : "disabling");
8b7e5ff6 716
855a3a98 717 {
f00ff009 718 CLockObject lock(m_mutex);
855a3a98 719 m_bMonitor = bEnable;
855a3a98
LOK
720 }
721
8b7e5ff6 722 if (bEnable)
06bfd4d7 723 return SetAckMask(0);
8b7e5ff6 724 else
dd18e809 725 return SetAckMask(m_configuration.logicalAddresses.AckMask());
8b7e5ff6
LOK
726}
727
57f45e6c
LOK
728bool CCECProcessor::PollDevice(cec_logical_address iAddress)
729{
730 if (iAddress != CECDEVICE_UNKNOWN && m_busDevices[iAddress])
95a73fa7 731 {
dd18e809 732 return m_configuration.logicalAddresses.primary == CECDEVICE_UNKNOWN ?
95a73fa7 733 m_busDevices[iAddress]->TransmitPoll(iAddress) :
dd18e809 734 m_busDevices[m_configuration.logicalAddresses.primary]->TransmitPoll(iAddress);
95a73fa7 735 }
57f45e6c
LOK
736 return false;
737}
738
5c73f7f7 739uint8_t CCECProcessor::VolumeUp(bool bSendRelease /* = true */)
04e637f9
LOK
740{
741 uint8_t status = 0;
37b0c572 742 if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM))
5c73f7f7 743 status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeUp(bSendRelease);
04e637f9
LOK
744
745 return status;
746}
747
5c73f7f7 748uint8_t CCECProcessor::VolumeDown(bool bSendRelease /* = true */)
04e637f9
LOK
749{
750 uint8_t status = 0;
37b0c572 751 if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM))
5c73f7f7 752 status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeDown(bSendRelease);
04e637f9
LOK
753
754 return status;
755}
756
5c73f7f7 757uint8_t CCECProcessor::MuteAudio(bool bSendRelease /* = true */)
04e637f9
LOK
758{
759 uint8_t status = 0;
37b0c572 760 if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM))
5c73f7f7 761 status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->MuteAudio(bSendRelease);
04e637f9
LOK
762
763 return status;
764}
765
16b1e052 766CCECBusDevice *CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress, bool bRefresh /* = false */) const
8ac9c610 767{
dd18e809
LOK
768 if (m_busDevices[m_configuration.logicalAddresses.primary]->GetPhysicalAddress(false) == iPhysicalAddress)
769 return m_busDevices[m_configuration.logicalAddresses.primary];
8ac9c610 770
b58d9277 771 CCECBusDevice *device = NULL;
8ac9c610
LOK
772 for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
773 {
16b1e052 774 if (m_busDevices[iPtr]->GetPhysicalAddress(bRefresh) == iPhysicalAddress)
8ac9c610
LOK
775 {
776 device = m_busDevices[iPtr];
777 break;
778 }
779 }
780
781 return device;
782}
783
a9232a79
LOK
784CCECBusDevice *CCECProcessor::GetDeviceByType(cec_device_type type) const
785{
786 CCECBusDevice *device = NULL;
787
7619faad 788 for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
a9232a79 789 {
dd18e809 790 if (m_busDevices[iPtr]->m_type == type && m_configuration.logicalAddresses[iPtr])
a9232a79
LOK
791 {
792 device = m_busDevices[iPtr];
793 break;
794 }
795 }
796
797 return device;
798}
799
842262d8
LOK
800CCECBusDevice *CCECProcessor::GetPrimaryDevice(void) const
801{
802 CCECBusDevice *device(NULL);
dd18e809 803 cec_logical_address primary = m_configuration.logicalAddresses.primary;
842262d8
LOK
804 if (primary != CECDEVICE_UNKNOWN)
805 device = m_busDevices[primary];
806 return device;
807}
808
6a1c0009
LOK
809cec_version CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress)
810{
811 return m_busDevices[iAddress]->GetCecVersion();
812}
813
ed21be2a
LOK
814cec_osd_name CCECProcessor::GetDeviceOSDName(cec_logical_address iAddress)
815{
816 CStdString strOSDName = m_busDevices[iAddress]->GetOSDName();
817 cec_osd_name retVal;
818
819 snprintf(retVal.name, sizeof(retVal.name), "%s", strOSDName.c_str());
820 retVal.device = iAddress;
821
822 return retVal;
823}
824
a3269a0a
LOK
825bool CCECProcessor::GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language)
826{
cc60ab1c
LOK
827 if (m_busDevices[iAddress])
828 {
829 *language = m_busDevices[iAddress]->GetMenuLanguage();
5744fbba 830 return (strcmp(language->language, "???") != 0);
cc60ab1c
LOK
831 }
832 return false;
a3269a0a
LOK
833}
834
44c74256
LOK
835uint64_t CCECProcessor::GetDeviceVendorId(cec_logical_address iAddress)
836{
cc60ab1c
LOK
837 if (m_busDevices[iAddress])
838 return m_busDevices[iAddress]->GetVendorId();
839 return false;
44c74256
LOK
840}
841
eab72c40
LOK
842uint16_t CCECProcessor::GetDevicePhysicalAddress(cec_logical_address iAddress)
843{
844 if (m_busDevices[iAddress])
845 return m_busDevices[iAddress]->GetPhysicalAddress(false);
846 return false;
847}
848
e55f3f70
LOK
849cec_power_status CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddress)
850{
cc60ab1c
LOK
851 if (m_busDevices[iAddress])
852 return m_busDevices[iAddress]->GetPowerStatus();
853 return CEC_POWER_STATUS_UNKNOWN;
e55f3f70
LOK
854}
855
b4b1b49b
LOK
856cec_logical_address CCECProcessor::GetActiveSource(void)
857{
858 for (uint8_t iPtr = 0; iPtr <= 11; iPtr++)
859 {
860 if (m_busDevices[iPtr]->IsActiveSource())
861 return (cec_logical_address)iPtr;
862 }
863
864 return CECDEVICE_UNKNOWN;
865}
866
867bool CCECProcessor::IsActiveSource(cec_logical_address iAddress)
868{
869 return m_busDevices[iAddress]->IsActiveSource();
870}
871
8d84e2c0 872bool CCECProcessor::Transmit(const cec_command &data)
825ddb96 873{
dd18e809 874 if (m_configuration.logicalAddresses[(uint8_t)data.destination])
c4287bcd
LOK
875 {
876 CLibCEC::AddLog(CEC_LOG_WARNING, "not sending data to myself!");
877 return false;
878 }
879
7cf8ba15 880 uint8_t iMaxTries(0);
eb35e4ca 881 {
7bb4ed43 882 CLockObject lock(m_mutex);
44a1d92a
LOK
883 if (IsStopped())
884 return false;
7bb4ed43 885 LogOutput(data);
5f316715 886 m_iLastTransmission = GetTimeMs();
44195125 887 if (!m_communication || !m_communication->IsOpen())
f9e01dac
LOK
888 {
889 CLibCEC::AddLog(CEC_LOG_ERROR, "cannot transmit command: connection closed");
7bb4ed43 890 return false;
f9e01dac 891 }
7cf8ba15 892 iMaxTries = m_busDevices[data.initiator]->GetHandler()->GetTransmitRetries() + 1;
2abe74eb
LOK
893 }
894
7cf8ba15
LOK
895 return m_communication->Write(data, iMaxTries, m_iLineTimeout, m_iRetryLineTimeout)
896 == ADAPTER_MESSAGE_STATE_SENT_ACKED;
825ddb96 897}
abbca718 898
22b4e74a 899void CCECProcessor::TransmitAbort(cec_logical_address address, cec_opcode opcode, cec_abort_reason reason /* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */)
abbca718 900{
5477a250 901 CLibCEC::AddLog(CEC_LOG_DEBUG, "<< transmitting abort message");
9dee1670 902
06a1f7ce 903 cec_command command;
f8513317 904 // TODO
dd18e809 905 cec_command::Format(command, m_configuration.logicalAddresses.primary, address, CEC_OPCODE_FEATURE_ABORT);
ab1469a0
LOK
906 command.parameters.PushBack((uint8_t)opcode);
907 command.parameters.PushBack((uint8_t)reason);
9dee1670
LOK
908
909 Transmit(command);
abbca718
LOK
910}
911
b1f94db1 912void CCECProcessor::ParseCommand(const cec_command &command)
abbca718 913{
e9de9629 914 CStdString dataStr;
1d3ca3de 915 dataStr.Format(">> %1x%1x:%02x", command.initiator, command.destination, command.opcode);
e9de9629
LOK
916 for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++)
917 dataStr.AppendFormat(":%02x", (unsigned int)command.parameters[iPtr]);
5477a250 918 CLibCEC::AddLog(CEC_LOG_TRAFFIC, dataStr.c_str());
dc113aca 919
7871d66e 920 if (!m_bMonitor && command.initiator >= CECDEVICE_TV && command.initiator <= CECDEVICE_BROADCAST)
e9de9629 921 m_busDevices[(uint8_t)command.initiator]->HandleCommand(command);
dc113aca
LOK
922}
923
6d858ba4
LOK
924cec_logical_addresses CCECProcessor::GetActiveDevices(void)
925{
926 cec_logical_addresses addresses;
988de7b9 927 addresses.Clear();
6d858ba4
LOK
928 for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
929 {
930 if (m_busDevices[iPtr]->GetStatus() == CEC_DEVICE_STATUS_PRESENT)
931 addresses.Set((cec_logical_address) iPtr);
932 }
933 return addresses;
934}
935
37b0c572 936bool CCECProcessor::IsPresentDevice(cec_logical_address address)
6d858ba4
LOK
937{
938 return m_busDevices[address]->GetStatus() == CEC_DEVICE_STATUS_PRESENT;
939}
940
37b0c572 941bool CCECProcessor::IsPresentDeviceType(cec_device_type type)
6d858ba4 942{
6d858ba4 943 for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
2813bd07
LOK
944 {
945 if (m_busDevices[iPtr]->GetType() == type && m_busDevices[iPtr]->GetStatus() == CEC_DEVICE_STATUS_PRESENT)
6d858ba4 946 return true;
2813bd07
LOK
947 }
948
6d858ba4
LOK
949 return false;
950}
951
0f23c85c
LOK
952uint16_t CCECProcessor::GetPhysicalAddress(void) const
953{
dd18e809
LOK
954 if (!m_configuration.logicalAddresses.IsEmpty() && m_busDevices[m_configuration.logicalAddresses.primary])
955 return m_busDevices[m_configuration.logicalAddresses.primary]->GetPhysicalAddress(false);
cc60ab1c 956 return false;
0f23c85c
LOK
957}
958
06bfd4d7
LOK
959bool CCECProcessor::SetAckMask(uint16_t iMask)
960{
5dcf9f25 961 return m_communication->SetAckMask(iMask);
06bfd4d7 962}
a33794d8 963
4bec9d79 964bool CCECProcessor::TransmitKeypress(cec_logical_address iDestination, cec_user_control_code key, bool bWait /* = true */)
a33794d8 965{
86869f8f 966 return m_busDevices[iDestination]->TransmitKeypress(key, bWait);
a33794d8
LOK
967}
968
4bec9d79 969bool CCECProcessor::TransmitKeyRelease(cec_logical_address iDestination, bool bWait /* = true */)
a33794d8 970{
86869f8f 971 return m_busDevices[iDestination]->TransmitKeyRelease(bWait);
a33794d8 972}
7c63a480 973
8670c970
LOK
974bool CCECProcessor::EnablePhysicalAddressDetection(void)
975{
976 CLibCEC::AddLog(CEC_LOG_WARNING, "deprecated method %s called", __FUNCTION__);
977 uint16_t iPhysicalAddress = m_communication->GetPhysicalAddress();
978 if (iPhysicalAddress != 0)
979 {
980 m_configuration.bAutodetectAddress = 1;
981 m_configuration.iPhysicalAddress = iPhysicalAddress;
982 m_configuration.baseDevice = CECDEVICE_UNKNOWN;
983 m_configuration.iHDMIPort = 0;
984 return SetPhysicalAddress(iPhysicalAddress);
985 }
986 return false;
987}
988
ca27e6cf
LOK
989bool CCECProcessor::StandbyDevices(cec_logical_address address /* = CECDEVICE_BROADCAST */)
990{
991 if (address == CECDEVICE_BROADCAST && m_configuration.clientVersion >= CEC_CLIENT_VERSION_1_5_0)
992 {
993 bool bReturn(true);
994 for (uint8_t iPtr = 0; iPtr <= 0xF; iPtr++)
995 {
996 if (m_configuration.powerOffDevices[iPtr])
997 bReturn &= m_busDevices[iPtr]->Standby();
998 }
999 return bReturn;
1000 }
1001
1002 return m_busDevices[address]->Standby();
1003}
1004
1005bool CCECProcessor::PowerOnDevices(cec_logical_address address /* = CECDEVICE_BROADCAST */)
1006{
1007 if (address == CECDEVICE_BROADCAST && m_configuration.clientVersion >= CEC_CLIENT_VERSION_1_5_0)
1008 {
1009 bool bReturn(true);
1010 for (uint8_t iPtr = 0; iPtr <= 0xF; iPtr++)
1011 {
1012 if (m_configuration.powerOffDevices[iPtr])
1013 bReturn &= m_busDevices[iPtr]->PowerOn();
1014 }
1015 return bReturn;
1016 }
1017
1018 return m_busDevices[address]->PowerOn();
1019}
1020
3e61b350
LOK
1021const char *CCECProcessor::ToString(const cec_device_type type)
1022{
1023 switch (type)
1024 {
1025 case CEC_DEVICE_TYPE_AUDIO_SYSTEM:
1026 return "audio system";
1027 case CEC_DEVICE_TYPE_PLAYBACK_DEVICE:
1028 return "playback device";
1029 case CEC_DEVICE_TYPE_RECORDING_DEVICE:
1030 return "recording device";
1031 case CEC_DEVICE_TYPE_RESERVED:
1032 return "reserved";
1033 case CEC_DEVICE_TYPE_TUNER:
1034 return "tuner";
1035 case CEC_DEVICE_TYPE_TV:
1036 return "TV";
1037 default:
1038 return "unknown";
1039 }
1040}
1041
03ae897d
LOK
1042const char *CCECProcessor::ToString(const cec_menu_state state)
1043{
1044 switch (state)
1045 {
1046 case CEC_MENU_STATE_ACTIVATED:
1047 return "activated";
1048 case CEC_MENU_STATE_DEACTIVATED:
1049 return "deactivated";
1050 default:
1051 return "unknown";
1052 }
1053}
1054
1055const char *CCECProcessor::ToString(const cec_version version)
1056{
1057 switch (version)
1058 {
1059 case CEC_VERSION_1_2:
1060 return "1.2";
1061 case CEC_VERSION_1_2A:
1062 return "1.2a";
1063 case CEC_VERSION_1_3:
1064 return "1.3";
1065 case CEC_VERSION_1_3A:
1066 return "1.3a";
1067 case CEC_VERSION_1_4:
1068 return "1.4";
1069 default:
1070 return "unknown";
1071 }
1072}
1073
1074const char *CCECProcessor::ToString(const cec_power_status status)
1075{
1076 switch (status)
1077 {
1078 case CEC_POWER_STATUS_ON:
1079 return "on";
1080 case CEC_POWER_STATUS_STANDBY:
1081 return "standby";
1082 case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY:
1083 return "in transition from on to standby";
1084 case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON:
1085 return "in transition from standby to on";
1086 default:
1087 return "unknown";
1088 }
1089}
1090
1091const char *CCECProcessor::ToString(const cec_logical_address address)
1092{
1093 switch(address)
1094 {
1095 case CECDEVICE_AUDIOSYSTEM:
1096 return "Audio";
1097 case CECDEVICE_BROADCAST:
1098 return "Broadcast";
1099 case CECDEVICE_FREEUSE:
1100 return "Free use";
1101 case CECDEVICE_PLAYBACKDEVICE1:
1102 return "Playback 1";
1103 case CECDEVICE_PLAYBACKDEVICE2:
1104 return "Playback 2";
1105 case CECDEVICE_PLAYBACKDEVICE3:
1106 return "Playback 3";
1107 case CECDEVICE_RECORDINGDEVICE1:
1108 return "Recorder 1";
1109 case CECDEVICE_RECORDINGDEVICE2:
1110 return "Recorder 2";
1111 case CECDEVICE_RECORDINGDEVICE3:
1112 return "Recorder 3";
1113 case CECDEVICE_RESERVED1:
1114 return "Reserved 1";
1115 case CECDEVICE_RESERVED2:
1116 return "Reserved 2";
1117 case CECDEVICE_TUNER1:
1118 return "Tuner 1";
1119 case CECDEVICE_TUNER2:
1120 return "Tuner 2";
1121 case CECDEVICE_TUNER3:
1122 return "Tuner 3";
1123 case CECDEVICE_TUNER4:
1124 return "Tuner 4";
1125 case CECDEVICE_TV:
1126 return "TV";
1127 default:
1128 return "unknown";
1129 }
1130}
1131
1132const char *CCECProcessor::ToString(const cec_deck_control_mode mode)
1133{
1134 switch (mode)
1135 {
1136 case CEC_DECK_CONTROL_MODE_SKIP_FORWARD_WIND:
1137 return "skip forward wind";
1138 case CEC_DECK_CONTROL_MODE_EJECT:
1139 return "eject";
1140 case CEC_DECK_CONTROL_MODE_SKIP_REVERSE_REWIND:
1141 return "reverse rewind";
1142 case CEC_DECK_CONTROL_MODE_STOP:
1143 return "stop";
1144 default:
1145 return "unknown";
1146 }
1147}
1148
1149const char *CCECProcessor::ToString(const cec_deck_info status)
1150{
1151 switch (status)
1152 {
1153 case CEC_DECK_INFO_PLAY:
1154 return "play";
1155 case CEC_DECK_INFO_RECORD:
1156 return "record";
1157 case CEC_DECK_INFO_PLAY_REVERSE:
1158 return "play reverse";
1159 case CEC_DECK_INFO_STILL:
1160 return "still";
1161 case CEC_DECK_INFO_SLOW:
1162 return "slow";
1163 case CEC_DECK_INFO_SLOW_REVERSE:
1164 return "slow reverse";
1165 case CEC_DECK_INFO_FAST_FORWARD:
1166 return "fast forward";
1167 case CEC_DECK_INFO_FAST_REVERSE:
1168 return "fast reverse";
1169 case CEC_DECK_INFO_NO_MEDIA:
1170 return "no media";
1171 case CEC_DECK_INFO_STOP:
1172 return "stop";
1173 case CEC_DECK_INFO_SKIP_FORWARD_WIND:
1174 return "info skip forward wind";
1175 case CEC_DECK_INFO_SKIP_REVERSE_REWIND:
1176 return "info skip reverse rewind";
1177 case CEC_DECK_INFO_INDEX_SEARCH_FORWARD:
1178 return "info index search forward";
1179 case CEC_DECK_INFO_INDEX_SEARCH_REVERSE:
1180 return "info index search reverse";
1181 case CEC_DECK_INFO_OTHER_STATUS:
1182 return "other";
1183 default:
1184 return "unknown";
1185 }
1186}
1187
1188const char *CCECProcessor::ToString(const cec_opcode opcode)
1189{
1190 switch (opcode)
1191 {
1192 case CEC_OPCODE_ACTIVE_SOURCE:
1193 return "active source";
1194 case CEC_OPCODE_IMAGE_VIEW_ON:
1195 return "image view on";
1196 case CEC_OPCODE_TEXT_VIEW_ON:
1197 return "text view on";
1198 case CEC_OPCODE_INACTIVE_SOURCE:
1199 return "inactive source";
1200 case CEC_OPCODE_REQUEST_ACTIVE_SOURCE:
1201 return "request active source";
1202 case CEC_OPCODE_ROUTING_CHANGE:
1203 return "routing change";
1204 case CEC_OPCODE_ROUTING_INFORMATION:
1205 return "routing information";
1206 case CEC_OPCODE_SET_STREAM_PATH:
1207 return "set stream path";
1208 case CEC_OPCODE_STANDBY:
1209 return "standby";
1210 case CEC_OPCODE_RECORD_OFF:
1211 return "record off";
1212 case CEC_OPCODE_RECORD_ON:
1213 return "record on";
1214 case CEC_OPCODE_RECORD_STATUS:
1215 return "record status";
1216 case CEC_OPCODE_RECORD_TV_SCREEN:
1217 return "record tv screen";
1218 case CEC_OPCODE_CLEAR_ANALOGUE_TIMER:
1219 return "clear analogue timer";
1220 case CEC_OPCODE_CLEAR_DIGITAL_TIMER:
1221 return "clear digital timer";
1222 case CEC_OPCODE_CLEAR_EXTERNAL_TIMER:
1223 return "clear external timer";
1224 case CEC_OPCODE_SET_ANALOGUE_TIMER:
1225 return "set analogue timer";
1226 case CEC_OPCODE_SET_DIGITAL_TIMER:
1227 return "set digital timer";
1228 case CEC_OPCODE_SET_EXTERNAL_TIMER:
1229 return "set external timer";
1230 case CEC_OPCODE_SET_TIMER_PROGRAM_TITLE:
1231 return "set timer program title";
1232 case CEC_OPCODE_TIMER_CLEARED_STATUS:
1233 return "timer cleared status";
1234 case CEC_OPCODE_TIMER_STATUS:
1235 return "timer status";
1236 case CEC_OPCODE_CEC_VERSION:
1237 return "cec version";
1238 case CEC_OPCODE_GET_CEC_VERSION:
1239 return "get cec version";
1240 case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS:
1241 return "give physical address";
1242 case CEC_OPCODE_GET_MENU_LANGUAGE:
1243 return "get menu language";
1244 case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS:
1245 return "report physical address";
1246 case CEC_OPCODE_SET_MENU_LANGUAGE:
1247 return "set menu language";
1248 case CEC_OPCODE_DECK_CONTROL:
1249 return "deck control";
1250 case CEC_OPCODE_DECK_STATUS:
1251 return "deck status";
1252 case CEC_OPCODE_GIVE_DECK_STATUS:
1253 return "give deck status";
1254 case CEC_OPCODE_PLAY:
1255 return "play";
1256 case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS:
1257 return "give tuner status";
1258 case CEC_OPCODE_SELECT_ANALOGUE_SERVICE:
1259 return "select analogue service";
1260 case CEC_OPCODE_SELECT_DIGITAL_SERVICE:
1261 return "set digital service";
1262 case CEC_OPCODE_TUNER_DEVICE_STATUS:
1263 return "tuner device status";
1264 case CEC_OPCODE_TUNER_STEP_DECREMENT:
1265 return "tuner step decrement";
1266 case CEC_OPCODE_TUNER_STEP_INCREMENT:
1267 return "tuner step increment";
1268 case CEC_OPCODE_DEVICE_VENDOR_ID:
1269 return "device vendor id";
1270 case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID:
1271 return "give device vendor id";
1272 case CEC_OPCODE_VENDOR_COMMAND:
1273 return "vendor command";
1274 case CEC_OPCODE_VENDOR_COMMAND_WITH_ID:
1275 return "vendor command with id";
1276 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN:
1277 return "vendor remote button down";
1278 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP:
1279 return "vendor remote button up";
1280 case CEC_OPCODE_SET_OSD_STRING:
1281 return "set osd string";
1282 case CEC_OPCODE_GIVE_OSD_NAME:
1283 return "give osd name";
1284 case CEC_OPCODE_SET_OSD_NAME:
1285 return "set osd name";
1286 case CEC_OPCODE_MENU_REQUEST:
1287 return "menu request";
1288 case CEC_OPCODE_MENU_STATUS:
1289 return "menu status";
1290 case CEC_OPCODE_USER_CONTROL_PRESSED:
1291 return "user control pressed";
1292 case CEC_OPCODE_USER_CONTROL_RELEASE:
1293 return "user control release";
1294 case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS:
1295 return "give device power status";
1296 case CEC_OPCODE_REPORT_POWER_STATUS:
1297 return "report power status";
1298 case CEC_OPCODE_FEATURE_ABORT:
1299 return "feature abort";
1300 case CEC_OPCODE_ABORT:
1301 return "abort";
1302 case CEC_OPCODE_GIVE_AUDIO_STATUS:
1303 return "give audio status";
1304 case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS:
1305 return "give audio mode status";
1306 case CEC_OPCODE_REPORT_AUDIO_STATUS:
1307 return "report audio status";
1308 case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE:
1309 return "set system audio mode";
1310 case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST:
1311 return "system audio mode request";
1312 case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS:
1313 return "system audio mode status";
1314 case CEC_OPCODE_SET_AUDIO_RATE:
1315 return "set audio rate";
24dd566c
LOK
1316 case CEC_OPCODE_NONE:
1317 return "poll";
03ae897d
LOK
1318 default:
1319 return "UNKNOWN";
1320 }
1321}
1322
1323const char *CCECProcessor::ToString(const cec_system_audio_status mode)
1324{
1325 switch(mode)
1326 {
1327 case CEC_SYSTEM_AUDIO_STATUS_ON:
1328 return "on";
1329 case CEC_SYSTEM_AUDIO_STATUS_OFF:
1330 return "off";
1331 default:
1332 return "unknown";
1333 }
1334}
1335
1de6617c 1336const char *CCECProcessor::ToString(const cec_audio_status UNUSED(status))
03ae897d
LOK
1337{
1338 // TODO this is a mask
1339 return "TODO";
1340}
1341
1342const char *CCECProcessor::ToString(const cec_vendor_id vendor)
1343{
1344 switch (vendor)
1345 {
1346 case CEC_VENDOR_SAMSUNG:
1347 return "Samsung";
1348 case CEC_VENDOR_LG:
1349 return "LG";
1350 case CEC_VENDOR_PANASONIC:
1351 return "Panasonic";
1352 case CEC_VENDOR_PIONEER:
1353 return "Pioneer";
1354 case CEC_VENDOR_ONKYO:
1355 return "Onkyo";
1356 case CEC_VENDOR_YAMAHA:
1357 return "Yamaha";
ec0deac1
LOK
1358 case CEC_VENDOR_PHILIPS:
1359 return "Philips";
1a87cacc
LOK
1360 case CEC_VENDOR_SONY:
1361 return "Sony";
26555d6b
LOK
1362 case CEC_VENDOR_TOSHIBA:
1363 return "Toshiba";
03ae897d
LOK
1364 default:
1365 return "Unknown";
1366 }
1367}
1368
caca2d81
LOK
1369const char *CCECProcessor::ToString(const cec_client_version version)
1370{
1371 switch (version)
1372 {
1373 case CEC_CLIENT_VERSION_PRE_1_5:
1374 return "pre-1.5";
1375 case CEC_CLIENT_VERSION_1_5_0:
1376 return "1.5.0";
41e3372a
LOK
1377 case CEC_CLIENT_VERSION_1_5_1:
1378 return "1.5.1";
2e82cff0
LOK
1379 case CEC_CLIENT_VERSION_1_5_2:
1380 return "1.5.2";
caca2d81
LOK
1381 default:
1382 return "Unknown";
1383 }
1384}
1385
3efda01a
LOK
1386const char *CCECProcessor::ToString(const cec_server_version version)
1387{
1388 switch (version)
1389 {
1390 case CEC_SERVER_VERSION_PRE_1_5:
1391 return "pre-1.5";
1392 case CEC_SERVER_VERSION_1_5_0:
1393 return "1.5.0";
41e3372a 1394 case CEC_SERVER_VERSION_1_5_1:
2e82cff0
LOK
1395 return "1.5.1";
1396 case CEC_SERVER_VERSION_1_5_2:
1397 return "1.5.2";
3efda01a
LOK
1398 default:
1399 return "Unknown";
1400 }
1401}
1402
7c63a480
LOK
1403void *CCECBusScan::Process(void)
1404{
1405 CCECBusDevice *device(NULL);
fe6f8e37 1406 uint8_t iCounter(0);
5f316715 1407
5e5637c6 1408 while (!IsStopped())
7c63a480 1409 {
bdb0f7f4 1410 if (++iCounter < 10)
fe6f8e37
LOK
1411 {
1412 Sleep(1000);
1413 continue;
1414 }
5f316715 1415 for (unsigned int iPtr = 0; iPtr <= 11 && !IsStopped(); iPtr++)
7c63a480 1416 {
5f316715
LOK
1417 device = m_processor->m_busDevices[iPtr];
1418 WaitUntilIdle();
1419 if (device && device->GetStatus(true) == CEC_DEVICE_STATUS_PRESENT)
5e5637c6 1420 {
5f316715
LOK
1421 WaitUntilIdle();
1422 if (!IsStopped())
1423 device->GetVendorId();
1424
1425 WaitUntilIdle();
1426 if (!IsStopped())
1427 device->GetPowerStatus(true);
5e5637c6 1428 }
7c63a480
LOK
1429 }
1430 }
5f316715 1431
7c63a480
LOK
1432 return NULL;
1433}
1113cb7d 1434
5f316715
LOK
1435void CCECBusScan::WaitUntilIdle(void)
1436{
1437 if (IsStopped())
1438 return;
1439
701f753b 1440 int32_t iWaitTime = 3000 - (int32_t)(GetTimeMs() - m_processor->GetLastTransmission());
5f316715
LOK
1441 while (iWaitTime > 0)
1442 {
1443 Sleep(iWaitTime);
701f753b 1444 iWaitTime = 3000 - (int32_t)(GetTimeMs() - m_processor->GetLastTransmission());
5f316715
LOK
1445 }
1446}
1447
a2198e5e 1448bool CCECProcessor::StartBootloader(const char *strPort /* = NULL */)
1113cb7d 1449{
a2198e5e
LOK
1450 if (!m_communication && strPort)
1451 {
1452 bool bReturn(false);
1453 IAdapterCommunication *comm = new CUSBCECAdapterCommunication(this, strPort);
1454 CTimeout timeout(10000);
1455 int iConnectTry(0);
1456 while (timeout.TimeLeft() > 0 && (bReturn = comm->Open(NULL, (timeout.TimeLeft() / CEC_CONNECT_TRIES)), true) == false)
1457 {
1458 CLibCEC::AddLog(CEC_LOG_ERROR, "could not open a connection (try %d)", ++iConnectTry);
1459 comm->Close();
1460 Sleep(500);
1461 }
1462 if (comm->IsOpen())
1463 {
1464 bReturn = comm->StartBootloader();
1465 delete comm;
1466 }
1467 return bReturn;
1468 }
1469 else
1470 {
1471 return m_communication->StartBootloader();
1472 }
1113cb7d
LOK
1473}
1474
1475bool CCECProcessor::PingAdapter(void)
1476{
1477 return m_communication->PingAdapter();
1478}
6729ac71
LOK
1479
1480void CCECProcessor::HandlePoll(cec_logical_address initiator, cec_logical_address destination)
1481{
0cfdeb5a 1482 m_busDevices[initiator]->HandlePoll(destination);
6729ac71
LOK
1483}
1484
7bb4ed43 1485bool CCECProcessor::HandleReceiveFailed(cec_logical_address initiator)
6729ac71 1486{
0cfdeb5a 1487 return !m_busDevices[initiator]->HandleReceiveFailed();
6729ac71 1488}
f42d3e0f
LOK
1489
1490bool CCECProcessor::SetStreamPath(uint16_t iPhysicalAddress)
1491{
1492 // stream path changes are sent by the TV
1493 return m_busDevices[CECDEVICE_TV]->GetHandler()->TransmitSetStreamPath(iPhysicalAddress);
1494}
d40928b5 1495
30b4aac0
LOK
1496bool CCECProcessor::SetConfiguration(const libcec_configuration *configuration)
1497{
30a09f32 1498 bool bReinit(false);
30b4aac0 1499 CCECBusDevice *primary = IsRunning() ? GetPrimaryDevice() : NULL;
30a09f32 1500 cec_device_type oldPrimaryType = primary ? primary->GetType() : CEC_DEVICE_TYPE_RECORDING_DEVICE;
f0154449 1501 m_configuration.clientVersion = configuration->clientVersion;
30b4aac0
LOK
1502
1503 // client version 1.5.0
1504
1505 // device types
8670c970 1506 bool bDeviceTypeChanged = IsRunning () && m_configuration.deviceTypes != configuration->deviceTypes;
30b4aac0
LOK
1507 m_configuration.deviceTypes = configuration->deviceTypes;
1508
30a09f32
LOK
1509 bool bPhysicalAddressChanged(false);
1510
8670c970 1511 // autodetect address
30a09f32
LOK
1512 bool bPhysicalAutodetected(false);
1513 if (IsRunning() && configuration->bAutodetectAddress == 1)
8670c970 1514 {
30a09f32
LOK
1515 uint16_t iPhysicalAddress = m_communication->GetPhysicalAddress();
1516 if (iPhysicalAddress != 0)
1517 {
1518 if (IsRunning())
1519 CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - autodetected physical address '%4x'", __FUNCTION__, iPhysicalAddress);
1520 bPhysicalAddressChanged = (m_configuration.iPhysicalAddress != iPhysicalAddress);
1521 m_configuration.iPhysicalAddress = iPhysicalAddress;
1522 m_configuration.iHDMIPort = 0;
1523 m_configuration.baseDevice = CECDEVICE_UNKNOWN;
1524 bPhysicalAutodetected = true;
1525 }
8670c970
LOK
1526 }
1527
30b4aac0 1528 // physical address
8670c970
LOK
1529 if (!bPhysicalAutodetected)
1530 {
30a09f32
LOK
1531 if (configuration->iPhysicalAddress != 0)
1532 bPhysicalAddressChanged = IsRunning() && m_configuration.iPhysicalAddress != configuration->iPhysicalAddress;
1533 if (IsRunning())
1534 CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - using physical address '%4x'", __FUNCTION__, configuration->iPhysicalAddress);
8670c970
LOK
1535 m_configuration.iPhysicalAddress = configuration->iPhysicalAddress;
1536 }
30b4aac0 1537
8670c970
LOK
1538 bool bHdmiPortChanged(false);
1539 if (!bPhysicalAutodetected && !bPhysicalAddressChanged)
1540 {
30a09f32 1541 // base device
8670c970 1542 bHdmiPortChanged = IsRunning() && m_configuration.baseDevice != configuration->baseDevice;
30a09f32
LOK
1543 if (IsRunning())
1544 CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - using base device '%x'", __FUNCTION__, (int)configuration->baseDevice);
8670c970 1545 m_configuration.baseDevice = configuration->baseDevice;
30b4aac0 1546
30a09f32 1547 // hdmi port
8670c970 1548 bHdmiPortChanged |= IsRunning() && m_configuration.iHDMIPort != configuration->iHDMIPort;
30a09f32
LOK
1549 if (IsRunning())
1550 CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - using HDMI port '%d'", __FUNCTION__, configuration->iHDMIPort);
8670c970
LOK
1551 m_configuration.iHDMIPort = configuration->iHDMIPort;
1552 }
1553 else
1554 {
30a09f32
LOK
1555 if (IsRunning())
1556 CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - resetting HDMI port and base device to defaults", __FUNCTION__);
1557 m_configuration.baseDevice = CECDEVICE_UNKNOWN;
1558 m_configuration.iHDMIPort = 0;
8670c970 1559 }
30b4aac0 1560
30a09f32 1561 bReinit = bPhysicalAddressChanged || bHdmiPortChanged || bDeviceTypeChanged;
f0154449 1562
30b4aac0
LOK
1563 // device name
1564 snprintf(m_configuration.strDeviceName, 13, "%s", configuration->strDeviceName);
1565 if (primary && !primary->GetOSDName().Equals(m_configuration.strDeviceName))
1566 {
1567 primary->SetOSDName(m_configuration.strDeviceName);
f0154449 1568 if (!bReinit && IsRunning())
30b4aac0
LOK
1569 primary->TransmitOSDName(CECDEVICE_TV);
1570 }
1571
1572 // tv vendor id override
1573 if (m_configuration.tvVendor != configuration->tvVendor)
1574 {
1575 m_configuration.tvVendor= configuration->tvVendor;
1576 m_busDevices[CECDEVICE_TV]->SetVendorId((uint64_t)m_configuration.tvVendor);
1577 }
1578
1579 // wake CEC devices
1580 if (m_configuration.wakeDevices != configuration->wakeDevices)
1581 {
1582 m_configuration.wakeDevices = configuration->wakeDevices;
f0154449 1583 if (!bReinit && IsRunning())
ca27e6cf 1584 PowerOnDevices();
30b4aac0
LOK
1585 }
1586
1587 // just copy these
3efda01a
LOK
1588 m_configuration.clientVersion = configuration->clientVersion;
1589 m_configuration.bActivateSource = configuration->bActivateSource;
30b4aac0 1590 m_configuration.bGetSettingsFromROM = configuration->bGetSettingsFromROM;
ca27e6cf 1591 m_configuration.powerOffDevices = configuration->powerOffDevices;
30b4aac0
LOK
1592 m_configuration.bPowerOffScreensaver = configuration->bPowerOffScreensaver;
1593 m_configuration.bPowerOffOnStandby = configuration->bPowerOffOnStandby;
1594
41e3372a
LOK
1595 // client version 1.5.1
1596 if (configuration->clientVersion >= CEC_CLIENT_VERSION_1_5_1)
1597 m_configuration.bSendInactiveSource = configuration->bSendInactiveSource;
1598
30b4aac0
LOK
1599 // ensure that there is at least 1 device type set
1600 if (m_configuration.deviceTypes.IsEmpty())
1601 m_configuration.deviceTypes.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE);
1602
f0154449 1603 if (bReinit)
30b4aac0 1604 {
44a1d92a
LOK
1605 if (bDeviceTypeChanged)
1606 return ChangeDeviceType(oldPrimaryType, m_configuration.deviceTypes[0]);
1607 else if (bPhysicalAddressChanged)
1608 return SetPhysicalAddress(m_configuration.iPhysicalAddress);
8670c970 1609 else
f0154449 1610 return SetHDMIPort(m_configuration.baseDevice, m_configuration.iHDMIPort);
30b4aac0 1611 }
dd18e809 1612 else if (m_configuration.bActivateSource == 1 && IsRunning() && !IsActiveSource(m_configuration.logicalAddresses.primary))
c3c13157
LOK
1613 {
1614 // activate the source if we're not already the active source
1615 SetActiveSource(m_configuration.deviceTypes.types[0]);
1616 }
30b4aac0
LOK
1617
1618 return true;
1619}
1620
d40928b5
LOK
1621bool CCECProcessor::GetCurrentConfiguration(libcec_configuration *configuration)
1622{
30b4aac0 1623 // client version 1.5.0
30b4aac0
LOK
1624 snprintf(configuration->strDeviceName, 13, "%s", m_configuration.strDeviceName);
1625 configuration->deviceTypes = m_configuration.deviceTypes;
8670c970 1626 configuration->bAutodetectAddress = m_configuration.bAutodetectAddress;
30b4aac0
LOK
1627 configuration->iPhysicalAddress = m_configuration.iPhysicalAddress;
1628 configuration->baseDevice = m_configuration.baseDevice;
1629 configuration->iHDMIPort = m_configuration.iHDMIPort;
3efda01a
LOK
1630 configuration->clientVersion = m_configuration.clientVersion;
1631 configuration->serverVersion = m_configuration.serverVersion;
30b4aac0 1632 configuration->tvVendor = m_configuration.tvVendor;
3efda01a 1633
30b4aac0 1634 configuration->bGetSettingsFromROM = m_configuration.bGetSettingsFromROM;
3efda01a
LOK
1635 configuration->bUseTVMenuLanguage = m_configuration.bUseTVMenuLanguage;
1636 configuration->bActivateSource = m_configuration.bActivateSource;
1637 configuration->wakeDevices = m_configuration.wakeDevices;
ca27e6cf 1638 configuration->powerOffDevices = m_configuration.powerOffDevices;
30b4aac0
LOK
1639 configuration->bPowerOffScreensaver = m_configuration.bPowerOffScreensaver;
1640 configuration->bPowerOffOnStandby = m_configuration.bPowerOffOnStandby;
1641
41e3372a
LOK
1642 // client version 1.5.1
1643 if (configuration->clientVersion >= CEC_CLIENT_VERSION_1_5_1)
1644 configuration->bSendInactiveSource = m_configuration.bSendInactiveSource;
1645
dd18e809
LOK
1646 // client version 1.5.3
1647 if (configuration->clientVersion >= CEC_CLIENT_VERSION_1_5_3)
1648 configuration->logicalAddresses = m_configuration.logicalAddresses;
1649
d40928b5
LOK
1650 return true;
1651}
224ea877
LOK
1652
1653bool CCECProcessor::CanPersistConfiguration(void)
1654{
1655 return m_communication->GetFirmwareVersion() >= 2;
1656}
1657
1658bool CCECProcessor::PersistConfiguration(libcec_configuration *configuration)
1659{
1660 return m_communication->PersistConfiguration(configuration);
1661}
3efda01a
LOK
1662
1663void CCECProcessor::RescanActiveDevices(void)
1664{
1665 for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
1666 m_busDevices[iPtr]->GetStatus(true);
1667}