cec: fixed - don't report a changed physical address when it hasn't changed
[deb_libcec.git] / src / lib / devices / CECBusDevice.cpp
CommitLineData
e9de9629
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
33#include "CECBusDevice.h"
eafa9d46
LOK
34#include "../CECProcessor.h"
35#include "../implementations/ANCommandHandler.h"
36#include "../implementations/CECCommandHandler.h"
37#include "../implementations/SLCommandHandler.h"
11621576 38#include "../implementations/VLCommandHandler.h"
eafa9d46 39#include "../platform/timeutils.h"
e9de9629
LOK
40
41using namespace CEC;
42
c4098482
LOK
43#define ToString(p) CCECCommandHandler::ToString(p)
44
e9de9629 45CCECBusDevice::CCECBusDevice(CCECProcessor *processor, cec_logical_address iLogicalAddress, uint16_t iPhysicalAddress) :
c4098482 46 m_type(CEC_DEVICE_TYPE_RESERVED),
e9de9629 47 m_iPhysicalAddress(iPhysicalAddress),
9dc04b07 48 m_iStreamPath(0),
e9de9629 49 m_iLogicalAddress(iLogicalAddress),
e55f3f70 50 m_powerStatus(CEC_POWER_STATUS_UNKNOWN),
e9de9629 51 m_processor(processor),
c4098482 52 m_vendor(CEC_VENDOR_UNKNOWN),
4abd6768 53 m_menuState(CEC_MENU_STATE_ACTIVATED),
8747dd4f 54 m_bActiveSource(false),
d54e8570 55 m_iLastCommandSent(0),
6a1c0009 56 m_iLastActive(0),
f8ae3295
LOK
57 m_cecVersion(CEC_VERSION_UNKNOWN),
58 m_deviceStatus(CEC_DEVICE_STATUS_UNKNOWN)
e9de9629
LOK
59{
60 m_handler = new CCECCommandHandler(this);
51b2a094 61
a3269a0a
LOK
62 for (unsigned int iPtr = 0; iPtr < 4; iPtr++)
63 m_menuLanguage.language[iPtr] = '?';
64 m_menuLanguage.language[3] = 0;
65 m_menuLanguage.device = iLogicalAddress;
1fcf5a3f 66
c4098482 67 m_strDeviceName = ToString(m_iLogicalAddress);
e9de9629
LOK
68}
69
70CCECBusDevice::~CCECBusDevice(void)
71{
6a1c0009 72 m_condition.Broadcast();
e9de9629
LOK
73 delete m_handler;
74}
75
93729720 76void CCECBusDevice::AddLog(cec_log_level level, const CStdString &strMessage)
e9de9629 77{
93729720 78 m_processor->AddLog(level, strMessage);
e9de9629
LOK
79}
80
93729720 81bool CCECBusDevice::HandleCommand(const cec_command &command)
f8513317 82{
81a1e39d 83 CLockObject lock(&m_transmitMutex);
93729720
LOK
84 m_iLastActive = GetTimeMs();
85 m_handler->HandleCommand(command);
a24c27d3
LOK
86 if (m_deviceStatus != CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC)
87 m_deviceStatus = CEC_DEVICE_STATUS_PRESENT;
93729720
LOK
88 m_condition.Signal();
89 return true;
90}
91
92void CCECBusDevice::PollVendorId(void)
93{
81a1e39d 94 CLockObject lock(&m_transmitMutex);
93729720 95 if (m_iLastActive > 0 && m_iLogicalAddress != CECDEVICE_BROADCAST &&
c4098482 96 m_vendor == CEC_VENDOR_UNKNOWN &&
d54e8570 97 GetTimeMs() - m_iLastCommandSent > 5000 &&
315ff809 98 !m_processor->IsMonitoring())
93729720 99 {
5e822b09 100 CStdString strLog;
62f5527d 101 strLog.Format("<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
5e822b09 102 AddLog(CEC_LOG_NOTICE, strLog);
d54e8570 103 m_iLastCommandSent = GetTimeMs();
93729720
LOK
104
105 cec_command command;
ab1469a0 106 cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID);
93729720 107 if (m_processor->Transmit(command))
81a1e39d 108 m_condition.Wait(&m_transmitMutex, 1000);
93729720
LOK
109 }
110}
111
112bool CCECBusDevice::PowerOn(void)
113{
00762a71
LOK
114 CStdString strLog;
115 strLog.Format("<< powering on '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
116 AddLog(CEC_LOG_DEBUG, strLog.c_str());
117
118 cec_command command;
119 cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_IMAGE_VIEW_ON);
120 if (m_processor->Transmit(command))
121 {
122 GetPowerStatus();
123 return true;
f437e4be
LOK
124 }
125
00762a71 126 return false;
93729720
LOK
127}
128
129bool CCECBusDevice::Standby(void)
130{
131 CStdString strLog;
62f5527d 132 strLog.Format("<< putting '%s' (%X) in standby mode", GetLogicalAddressName(), m_iLogicalAddress);
93729720
LOK
133 AddLog(CEC_LOG_DEBUG, strLog.c_str());
134
135 cec_command command;
ab1469a0 136 cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_STANDBY);
93729720
LOK
137
138 return m_processor->Transmit(command);
139}
140
141/** @name Getters */
142//@{
d7be392a 143cec_version CCECBusDevice::GetCecVersion(void)
93729720 144{
f294b22f
LOK
145 CLockObject lock(&m_mutex);
146 if (m_cecVersion == CEC_VERSION_UNKNOWN)
147 {
148 lock.Leave();
149 RequestCecVersion();
150 lock.Lock();
151 }
152
153 return m_cecVersion;
154}
155
156bool CCECBusDevice::RequestCecVersion(void)
157{
158 bool bReturn(false);
81a1e39d 159 if (!MyLogicalAddressContains(m_iLogicalAddress))
93729720 160 {
81a1e39d
LOK
161 CStdString strLog;
162 strLog.Format("<< requesting CEC version of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
163 AddLog(CEC_LOG_NOTICE, strLog);
164 cec_command command;
165 cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GET_CEC_VERSION);
166 CLockObject lock(&m_transmitMutex);
167 if (m_processor->Transmit(command))
f294b22f 168 bReturn = m_condition.Wait(&m_transmitMutex, 1000);
93729720 169 }
f294b22f 170 return bReturn;
93729720
LOK
171}
172
62f5527d
LOK
173const char* CCECBusDevice::GetLogicalAddressName(void) const
174{
c4098482 175 return ToString(m_iLogicalAddress);
62f5527d
LOK
176}
177
d7be392a 178cec_menu_language &CCECBusDevice::GetMenuLanguage(void)
93729720 179{
f294b22f
LOK
180 CLockObject lock(&m_mutex);
181 if (!strcmp(m_menuLanguage.language, "???"))
182 {
183 lock.Leave();
184 RequestMenuLanguage();
185 lock.Lock();
186 }
187 return m_menuLanguage;
188}
189
190bool CCECBusDevice::RequestMenuLanguage(void)
191{
192 bool bReturn(false);
81a1e39d 193 if (!MyLogicalAddressContains(m_iLogicalAddress))
93729720 194 {
81a1e39d
LOK
195 CStdString strLog;
196 strLog.Format("<< requesting menu language of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
197 AddLog(CEC_LOG_NOTICE, strLog);
198 cec_command command;
199 cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GET_MENU_LANGUAGE);
200 CLockObject lock(&m_transmitMutex);
201 if (m_processor->Transmit(command))
f294b22f 202 bReturn = m_condition.Wait(&m_transmitMutex, 1000);
93729720 203 }
f294b22f 204 return bReturn;
93729720
LOK
205}
206
207cec_logical_address CCECBusDevice::GetMyLogicalAddress(void) const
208{
209 return m_processor->GetLogicalAddress();
f8513317
LOK
210}
211
e9de9629
LOK
212uint16_t CCECBusDevice::GetMyPhysicalAddress(void) const
213{
214 return m_processor->GetPhysicalAddress();
215}
216
d7be392a 217cec_power_status CCECBusDevice::GetPowerStatus(void)
e9de9629 218{
f294b22f
LOK
219 CLockObject lock(&m_mutex);
220 if (m_powerStatus == CEC_POWER_STATUS_UNKNOWN)
221 {
222 lock.Leave();
223 RequestPowerStatus();
224 lock.Lock();
225 }
226 return m_powerStatus;
227}
228
229bool CCECBusDevice::RequestPowerStatus(void)
230{
231 bool bReturn(false);
81a1e39d 232 if (!MyLogicalAddressContains(m_iLogicalAddress))
93729720 233 {
81a1e39d
LOK
234 CStdString strLog;
235 strLog.Format("<< requesting power status of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
236 AddLog(CEC_LOG_NOTICE, strLog);
237 cec_command command;
238 cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GIVE_DEVICE_POWER_STATUS);
239 CLockObject lock(&m_transmitMutex);
240 if (m_processor->Transmit(command))
f294b22f 241 bReturn = m_condition.Wait(&m_transmitMutex, 1000);
93729720 242 }
f294b22f
LOK
243 return bReturn;
244}
93729720 245
f294b22f
LOK
246cec_vendor_id CCECBusDevice::GetVendorId(void)
247{
81a1e39d 248 CLockObject lock(&m_mutex);
f294b22f
LOK
249 if (m_vendor == CEC_VENDOR_UNKNOWN)
250 {
251 lock.Leave();
252 RequestVendorId();
253 lock.Lock();
254 }
255 return m_vendor;
e9de9629
LOK
256}
257
f294b22f 258bool CCECBusDevice::RequestVendorId(void)
a3269a0a 259{
f294b22f 260 bool bReturn(false);
81a1e39d 261 if (!MyLogicalAddressContains(m_iLogicalAddress))
a3269a0a 262 {
81a1e39d
LOK
263 CStdString strLog;
264 strLog.Format("<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
265 AddLog(CEC_LOG_NOTICE, strLog);
266 cec_command command;
267 cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID);
81a1e39d 268
f294b22f 269 CLockObject lock(&m_transmitMutex);
81a1e39d 270 if (m_processor->Transmit(command))
f294b22f 271 bReturn = m_condition.Wait(&m_transmitMutex, 1000);
a3269a0a 272 }
f294b22f 273 return bReturn;
93729720
LOK
274}
275
c4098482
LOK
276const char *CCECBusDevice::GetVendorName(void)
277{
f294b22f 278 return ToString(GetVendorId());
c4098482
LOK
279}
280
93729720
LOK
281bool CCECBusDevice::MyLogicalAddressContains(cec_logical_address address) const
282{
283 return m_processor->HasLogicalAddress(address);
a3269a0a
LOK
284}
285
f8ae3295
LOK
286cec_bus_device_status CCECBusDevice::GetStatus(void)
287{
288 CLockObject lock(&m_mutex);
289 if (m_deviceStatus == CEC_DEVICE_STATUS_UNKNOWN)
290 {
291 if (m_processor->PollDevice(m_iLogicalAddress))
292 m_deviceStatus = CEC_DEVICE_STATUS_PRESENT;
293 else
294 m_deviceStatus = CEC_DEVICE_STATUS_NOT_PRESENT;
295 }
296
297 return m_deviceStatus;
298}
299
93729720
LOK
300//@}
301
302/** @name Setters */
303//@{
e55f3f70 304void CCECBusDevice::SetCecVersion(const cec_version newVersion)
6a1c0009 305{
6a1c0009
LOK
306 m_cecVersion = newVersion;
307
c686413b 308 CStdString strLog;
c4098482 309 strLog.Format("%s (%X): CEC version %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(newVersion));
6a1c0009
LOK
310 AddLog(CEC_LOG_DEBUG, strLog);
311}
312
93729720
LOK
313void CCECBusDevice::SetMenuLanguage(const cec_menu_language &language)
314{
81a1e39d 315 CLockObject lock(&m_mutex);
93729720
LOK
316 if (language.device == m_iLogicalAddress)
317 {
318 CStdString strLog;
62f5527d 319 strLog.Format(">> %s (%X): menu language set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, language.language);
93729720
LOK
320 m_processor->AddLog(CEC_LOG_DEBUG, strLog);
321 m_menuLanguage = language;
322 }
323}
324
15d1a84c
LOK
325void CCECBusDevice::SetOSDName(CStdString strName)
326{
327 CLockObject lock(&m_mutex);
328 if (m_strDeviceName != strName)
329 {
330 CStdString strLog;
331 strLog.Format(">> %s (%X): osd name set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, strName);
332 m_processor->AddLog(CEC_LOG_DEBUG, strLog);
333 m_strDeviceName = strName;
334 }
335}
336
28fa6c97
LOK
337void CCECBusDevice::SetMenuState(const cec_menu_state state)
338{
81a1e39d 339 CLockObject lock(&m_mutex);
28fa6c97
LOK
340 if (m_menuState != state)
341 {
342 CStdString strLog;
343 strLog.Format(">> %s (%X): menu state set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_menuState));
344 m_processor->AddLog(CEC_LOG_DEBUG, strLog);
345 m_menuState = state;
346 }
347}
348
7856411b
LOK
349void CCECBusDevice::SetInactiveDevice(void)
350{
351 CLockObject lock(&m_mutex);
352 m_bActiveSource = false;
353}
354
355void CCECBusDevice::SetActiveDevice(void)
356{
357 CLockObject lock(&m_mutex);
358
359 for (int iPtr = 0; iPtr < 16; iPtr++)
360 if (iPtr != m_iLogicalAddress)
361 m_processor->m_busDevices[iPtr]->SetInactiveDevice();
362
363 m_bActiveSource = true;
364 m_powerStatus = CEC_POWER_STATUS_ON;
365}
366
93fff5c1
LOK
367bool CCECBusDevice::TryLogicalAddress(void)
368{
369 CStdString strLog;
370 strLog.Format("trying logical address '%s'", GetLogicalAddressName());
371 AddLog(CEC_LOG_DEBUG, strLog);
372
373 m_processor->SetAckMask(0x1 << m_iLogicalAddress);
374 if (!TransmitPoll(m_iLogicalAddress))
375 {
376 strLog.Format("using logical address '%s'", GetLogicalAddressName());
377 AddLog(CEC_LOG_NOTICE, strLog);
378 SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC);
379
380 return true;
381 }
382
383 strLog.Format("logical address '%s' already taken", GetLogicalAddressName());
384 AddLog(CEC_LOG_DEBUG, strLog);
385 SetDeviceStatus(CEC_DEVICE_STATUS_PRESENT);
386 return false;
387}
388
389void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus)
390{
391 CLockObject lock(&m_mutex);
392 switch (newStatus)
393 {
394 case CEC_DEVICE_STATUS_UNKNOWN:
395 m_iStreamPath = 0;
396 m_powerStatus = CEC_POWER_STATUS_UNKNOWN;
397 m_vendor = CEC_VENDOR_UNKNOWN;
398 m_menuState = CEC_MENU_STATE_ACTIVATED;
399 m_bActiveSource = false;
400 m_iLastCommandSent = 0;
401 m_iLastActive = 0;
402 m_cecVersion = CEC_VERSION_UNKNOWN;
403 m_deviceStatus = newStatus;
404 break;
405 case CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC:
406 m_iStreamPath = 0;
407 m_powerStatus = CEC_POWER_STATUS_ON;
408 m_vendor = CEC_VENDOR_UNKNOWN;
409 m_menuState = CEC_MENU_STATE_ACTIVATED;
410 m_bActiveSource = false;
411 m_iLastCommandSent = 0;
412 m_iLastActive = 0;
413 m_cecVersion = CEC_VERSION_1_3A;
414 m_deviceStatus = newStatus;
415 break;
416 case CEC_DEVICE_STATUS_PRESENT:
417 case CEC_DEVICE_STATUS_NOT_PRESENT:
418 m_deviceStatus = newStatus;
419 break;
420 }
421}
422
9dc04b07 423void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress)
93729720 424{
81a1e39d 425 CLockObject lock(&m_mutex);
b8176e3c 426 if (iNewAddress > 0 && m_iPhysicalAddress != iNewAddress)
93729720
LOK
427 {
428 CStdString strLog;
62f5527d 429 strLog.Format(">> %s (%X): physical address changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress, iNewAddress);
93729720
LOK
430 AddLog(CEC_LOG_DEBUG, strLog.c_str());
431
432 m_iPhysicalAddress = iNewAddress;
433 }
434}
435
9dc04b07
LOK
436void CCECBusDevice::SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress /* = 0 */)
437{
81a1e39d 438 CLockObject lock(&m_mutex);
9dc04b07
LOK
439 if (iNewAddress > 0)
440 {
441 CStdString strLog;
68a12fbf 442 strLog.Format(">> %s (%X): stream path changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress, iOldAddress == 0 ? m_iStreamPath : iOldAddress, iNewAddress);
9dc04b07
LOK
443 AddLog(CEC_LOG_DEBUG, strLog.c_str());
444
445 m_iStreamPath = iNewAddress;
96274140
LOK
446
447 if (iNewAddress > 0)
81a1e39d
LOK
448 {
449 lock.Leave();
96274140 450 SetPowerStatus(CEC_POWER_STATUS_ON);
81a1e39d 451 }
9dc04b07
LOK
452 }
453}
454
e55f3f70
LOK
455void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus)
456{
81a1e39d 457 CLockObject lock(&m_mutex);
b0271d54
LOK
458 if (m_powerStatus != powerStatus)
459 {
460 CStdString strLog;
c4098482 461 strLog.Format(">> %s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_powerStatus), ToString(powerStatus));
b0271d54
LOK
462 m_processor->AddLog(CEC_LOG_DEBUG, strLog);
463 m_powerStatus = powerStatus;
464 }
e55f3f70
LOK
465}
466
c4098482 467void CCECBusDevice::SetVendorId(uint64_t iVendorId)
e9de9629 468{
e9de9629 469 {
81a1e39d
LOK
470 CLockObject lock(&m_mutex);
471 m_vendor = (cec_vendor_id)iVendorId;
472
473 switch (iVendorId)
0ab58650 474 {
81a1e39d
LOK
475 case CEC_VENDOR_SAMSUNG:
476 if (m_handler->GetVendorId() != CEC_VENDOR_SAMSUNG)
477 {
478 delete m_handler;
479 m_handler = new CANCommandHandler(this);
480 }
481 break;
482 case CEC_VENDOR_LG:
483 if (m_handler->GetVendorId() != CEC_VENDOR_LG)
484 {
485 delete m_handler;
486 m_handler = new CSLCommandHandler(this);
487 }
488 break;
489 case CEC_VENDOR_PANASONIC:
490 if (m_handler->GetVendorId() != CEC_VENDOR_PANASONIC)
491 {
492 delete m_handler;
493 m_handler = new CVLCommandHandler(this);
494 }
495 break;
496 default:
497 if (m_handler->GetVendorId() != CEC_VENDOR_UNKNOWN)
498 {
499 delete m_handler;
500 m_handler = new CCECCommandHandler(this);
501 }
502 break;
0ab58650 503 }
e9de9629
LOK
504 }
505
506 CStdString strLog;
81a1e39d 507 strLog.Format("%s (%X): vendor = %s (%06x)", GetLogicalAddressName(), m_iLogicalAddress, GetVendorName(), m_vendor);
e9de9629
LOK
508 m_processor->AddLog(CEC_LOG_DEBUG, strLog.c_str());
509}
93729720 510//@}
e9de9629 511
93729720
LOK
512/** @name Transmit methods */
513//@{
514bool CCECBusDevice::TransmitActiveSource(void)
0f23c85c 515{
81a1e39d 516 CLockObject lock(&m_mutex);
58c1f6f5
LOK
517 if (m_powerStatus != CEC_POWER_STATUS_ON)
518 {
519 CStdString strLog;
520 strLog.Format("<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress);
521 AddLog(CEC_LOG_DEBUG, strLog);
522 }
523 else if (m_bActiveSource)
8747dd4f
LOK
524 {
525 CStdString strLog;
62f5527d 526 strLog.Format("<< %s (%X) -> broadcast (F): active source (%4x)", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress);
8747dd4f 527 AddLog(CEC_LOG_NOTICE, strLog);
0f23c85c 528
8747dd4f 529 cec_command command;
ab1469a0
LOK
530 cec_command::Format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_ACTIVE_SOURCE);
531 command.parameters.PushBack((uint8_t) ((m_iPhysicalAddress >> 8) & 0xFF));
532 command.parameters.PushBack((uint8_t) (m_iPhysicalAddress & 0xFF));
0f23c85c 533
81a1e39d 534 lock.Leave();
8747dd4f
LOK
535 return m_processor->Transmit(command);
536 }
537 else
538 {
539 CStdString strLog;
62f5527d 540 strLog.Format("<< %s (%X) is not the active source", GetLogicalAddressName(), m_iLogicalAddress);
8747dd4f
LOK
541 AddLog(CEC_LOG_DEBUG, strLog);
542 }
543
544 return false;
0f23c85c
LOK
545}
546
29912296 547bool CCECBusDevice::TransmitCECVersion(cec_logical_address dest)
0f23c85c 548{
81a1e39d 549 CLockObject lock(&m_mutex);
d7be392a 550 CStdString strLog;
c4098482 551 strLog.Format("<< %s (%X) -> %s (%X): cec version %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_cecVersion));
d7be392a 552 AddLog(CEC_LOG_NOTICE, strLog);
0f23c85c
LOK
553
554 cec_command command;
ab1469a0
LOK
555 cec_command::Format(command, m_iLogicalAddress, dest, CEC_OPCODE_CEC_VERSION);
556 command.parameters.PushBack((uint8_t)m_cecVersion);
0f23c85c 557
81a1e39d 558 lock.Leave();
0f23c85c
LOK
559 return m_processor->Transmit(command);
560}
561
93729720
LOK
562bool CCECBusDevice::TransmitInactiveView(void)
563{
d7be392a 564 CStdString strLog;
62f5527d 565 strLog.Format("<< %s (%X) -> broadcast (F): inactive view", GetLogicalAddressName(), m_iLogicalAddress);
d7be392a 566 AddLog(CEC_LOG_NOTICE, strLog);
93729720
LOK
567
568 cec_command command;
ab1469a0
LOK
569 cec_command::Format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_INACTIVE_SOURCE);
570 command.parameters.PushBack((m_iPhysicalAddress >> 8) & 0xFF);
571 command.parameters.PushBack(m_iPhysicalAddress & 0xFF);
93729720
LOK
572
573 return m_processor->Transmit(command);
574}
575
29912296 576bool CCECBusDevice::TransmitMenuState(cec_logical_address dest)
0f23c85c 577{
d7be392a 578 CStdString strLog;
28fa6c97 579 strLog.Format("<< %s (%X) -> %s (%X): menu state '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_menuState));
d7be392a 580 AddLog(CEC_LOG_NOTICE, strLog);
0f23c85c
LOK
581
582 cec_command command;
ab1469a0
LOK
583 cec_command::Format(command, m_iLogicalAddress, dest, CEC_OPCODE_MENU_STATUS);
584 command.parameters.PushBack((uint8_t)m_menuState);
0f23c85c
LOK
585
586 return m_processor->Transmit(command);
587}
588
29912296 589bool CCECBusDevice::TransmitOSDName(cec_logical_address dest)
0f23c85c 590{
81a1e39d 591 CLockObject lock(&m_mutex);
0f23c85c 592 CStdString strLog;
c4098482 593 strLog.Format("<< %s (%X) -> %s (%X): OSD name '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, m_strDeviceName.c_str());
0f23c85c
LOK
594 AddLog(CEC_LOG_NOTICE, strLog.c_str());
595
596 cec_command command;
ab1469a0 597 cec_command::Format(command, m_iLogicalAddress, dest, CEC_OPCODE_SET_OSD_NAME);
787a3cb8 598 for (unsigned int iPtr = 0; iPtr < m_strDeviceName.length(); iPtr++)
ab1469a0 599 command.parameters.PushBack(m_strDeviceName.at(iPtr));
0f23c85c 600
81a1e39d 601 lock.Leave();
0f23c85c
LOK
602 return m_processor->Transmit(command);
603}
604
38bdb943
LOK
605bool CCECBusDevice::TransmitOSDString(cec_logical_address dest, cec_display_control duration, const char *strMessage)
606{
81a1e39d 607 CLockObject lock(&m_mutex);
38bdb943 608 CStdString strLog;
c4098482 609 strLog.Format("<< %s (%X) -> %s (%X): display OSD message '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, strMessage);
38bdb943
LOK
610 AddLog(CEC_LOG_NOTICE, strLog.c_str());
611
612 cec_command command;
ab1469a0
LOK
613 cec_command::Format(command, m_iLogicalAddress, dest, CEC_OPCODE_SET_OSD_STRING);
614 command.parameters.PushBack((uint8_t)duration);
38bdb943
LOK
615
616 unsigned int iLen = strlen(strMessage);
617 if (iLen > 13) iLen = 13;
618
619 for (unsigned int iPtr = 0; iPtr < iLen; iPtr++)
ab1469a0 620 command.parameters.PushBack(strMessage[iPtr]);
38bdb943 621
81a1e39d 622 lock.Leave();
38bdb943
LOK
623 return m_processor->Transmit(command);
624}
625
29912296 626bool CCECBusDevice::TransmitPhysicalAddress(void)
0f23c85c 627{
81a1e39d 628 CLockObject lock(&m_mutex);
0f23c85c 629 CStdString strLog;
62f5527d 630 strLog.Format("<< %s (%X) -> broadcast (F): physical adddress %4x", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress);
0f23c85c
LOK
631 AddLog(CEC_LOG_NOTICE, strLog.c_str());
632
633 cec_command command;
ab1469a0
LOK
634 cec_command::Format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_REPORT_PHYSICAL_ADDRESS);
635 command.parameters.PushBack((uint8_t) ((m_iPhysicalAddress >> 8) & 0xFF));
636 command.parameters.PushBack((uint8_t) (m_iPhysicalAddress & 0xFF));
637 command.parameters.PushBack((uint8_t) (m_type));
0f23c85c 638
81a1e39d 639 lock.Leave();
0f23c85c
LOK
640 return m_processor->Transmit(command);
641}
642
93729720 643bool CCECBusDevice::TransmitPoll(cec_logical_address dest)
57f45e6c
LOK
644{
645 bool bReturn(false);
93729720
LOK
646 if (dest == CECDEVICE_UNKNOWN)
647 dest = m_iLogicalAddress;
f8513317 648
57f45e6c 649 CStdString strLog;
c4098482 650 strLog.Format("<< %s (%X) -> %s (%X): POLL", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest);
d7be392a 651 AddLog(CEC_LOG_NOTICE, strLog.c_str());
57f45e6c
LOK
652
653 cec_command command;
ab1469a0 654 cec_command::Format(command, m_iLogicalAddress, dest, CEC_OPCODE_NONE);
57f45e6c 655
1674de37
LOK
656 {
657 CLockObject lock(&m_transmitMutex);
658 bReturn = m_processor->Transmit(command);
659 }
660
57f45e6c 661 AddLog(CEC_LOG_DEBUG, bReturn ? ">> POLL sent" : ">> POLL not sent");
1674de37
LOK
662
663 if (bReturn)
664 {
665 CLockObject lock(&m_mutex);
666 m_iLastActive = GetTimeMs();
667 }
668
57f45e6c
LOK
669 return bReturn;
670}
93729720
LOK
671
672bool CCECBusDevice::TransmitPowerState(cec_logical_address dest)
673{
81a1e39d 674 CLockObject lock(&m_mutex);
93729720 675 CStdString strLog;
c4098482 676 strLog.Format("<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_powerStatus));
d7be392a
LOK
677 AddLog(CEC_LOG_NOTICE, strLog.c_str());
678
93729720 679 cec_command command;
ab1469a0
LOK
680 cec_command::Format(command, m_iLogicalAddress, dest, CEC_OPCODE_REPORT_POWER_STATUS);
681 command.parameters.PushBack((uint8_t) m_powerStatus);
93729720 682
81a1e39d 683 lock.Leave();
93729720
LOK
684 return m_processor->Transmit(command);
685}
686
687bool CCECBusDevice::TransmitVendorID(cec_logical_address dest)
688{
81a1e39d 689 CLockObject lock(&m_mutex);
c4098482
LOK
690 if (m_vendor == CEC_VENDOR_UNKNOWN)
691 {
692 CStdString strLog;
693 strLog.Format("<< %s (%X) -> %s (%X): vendor id feature abort", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest);
694 AddLog(CEC_LOG_NOTICE, strLog);
d7be392a 695
81a1e39d 696 lock.Leave();
c4098482
LOK
697 m_processor->TransmitAbort(dest, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID);
698 return false;
699 }
700 else
701 {
702 CStdString strLog;
703 strLog.Format("<< %s (%X) -> %s (%X): vendor id %s (%x)", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_vendor), (uint64_t)m_vendor);
704 AddLog(CEC_LOG_NOTICE, strLog);
705
706 cec_command command;
5e9b399e 707 cec_command::Format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_DEVICE_VENDOR_ID);
c4098482 708
ab1469a0
LOK
709 command.parameters.PushBack((uint8_t) (((uint64_t)m_vendor >> 16) & 0xFF));
710 command.parameters.PushBack((uint8_t) (((uint64_t)m_vendor >> 8) & 0xFF));
711 command.parameters.PushBack((uint8_t) ((uint64_t)m_vendor & 0xFF));
c4098482 712
81a1e39d 713 lock.Leave();
c4098482
LOK
714 return m_processor->Transmit(command);
715 }
93729720
LOK
716}
717//@}