cec: set power status to on when the stream path changed to something else than 0
[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
43CCECBusDevice::CCECBusDevice(CCECProcessor *processor, cec_logical_address iLogicalAddress, uint16_t iPhysicalAddress) :
44 m_iPhysicalAddress(iPhysicalAddress),
9dc04b07 45 m_iStreamPath(0),
e9de9629 46 m_iLogicalAddress(iLogicalAddress),
e55f3f70 47 m_powerStatus(CEC_POWER_STATUS_UNKNOWN),
e9de9629 48 m_processor(processor),
1844f5f7 49 m_bMenuActive(true),
8747dd4f 50 m_bActiveSource(false),
0ab58650 51 m_iVendorClass(CEC_VENDOR_UNKNOWN),
d54e8570 52 m_iLastCommandSent(0),
6a1c0009 53 m_iLastActive(0),
5e822b09 54 m_cecVersion(CEC_VERSION_UNKNOWN)
e9de9629
LOK
55{
56 m_handler = new CCECCommandHandler(this);
51b2a094 57
a3269a0a
LOK
58 for (unsigned int iPtr = 0; iPtr < 4; iPtr++)
59 m_menuLanguage.language[iPtr] = '?';
60 m_menuLanguage.language[3] = 0;
61 m_menuLanguage.device = iLogicalAddress;
1fcf5a3f 62
51b2a094
LOK
63 m_vendor.vendor = CEC_VENDOR_UNKNOWN;
64 m_type = CEC_DEVICE_TYPE_RESERVED;
62f5527d 65 m_strDeviceName = CCECCommandHandler::ToString(m_iLogicalAddress);
e9de9629
LOK
66}
67
68CCECBusDevice::~CCECBusDevice(void)
69{
6a1c0009 70 m_condition.Broadcast();
e9de9629
LOK
71 delete m_handler;
72}
73
93729720 74void CCECBusDevice::AddLog(cec_log_level level, const CStdString &strMessage)
e9de9629 75{
93729720 76 m_processor->AddLog(level, strMessage);
e9de9629
LOK
77}
78
93729720 79bool CCECBusDevice::HandleCommand(const cec_command &command)
f8513317 80{
93729720
LOK
81 CLockObject lock(&m_mutex);
82 m_iLastActive = GetTimeMs();
83 m_handler->HandleCommand(command);
84 m_condition.Signal();
85 return true;
86}
87
88void CCECBusDevice::PollVendorId(void)
89{
90 CLockObject lock(&m_mutex);
91 if (m_iLastActive > 0 && m_iLogicalAddress != CECDEVICE_BROADCAST &&
92 m_vendor.vendor == CEC_VENDOR_UNKNOWN &&
d54e8570 93 GetTimeMs() - m_iLastCommandSent > 5000 &&
315ff809 94 !m_processor->IsMonitoring())
93729720 95 {
5e822b09 96 CStdString strLog;
62f5527d 97 strLog.Format("<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
5e822b09 98 AddLog(CEC_LOG_NOTICE, strLog);
d54e8570 99 m_iLastCommandSent = GetTimeMs();
93729720
LOK
100
101 cec_command command;
102 cec_command::format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID);
103 if (m_processor->Transmit(command))
104 m_condition.Wait(&m_mutex, 1000);
105 }
106}
107
108bool CCECBusDevice::PowerOn(void)
109{
110 CStdString strLog;
62f5527d 111 strLog.Format("<< powering on '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
93729720
LOK
112 AddLog(CEC_LOG_DEBUG, strLog.c_str());
113
114 cec_command command;
115 cec_command::format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_IMAGE_VIEW_ON);
116
117 return m_processor->Transmit(command);
118}
119
120bool CCECBusDevice::Standby(void)
121{
122 CStdString strLog;
62f5527d 123 strLog.Format("<< putting '%s' (%X) in standby mode", GetLogicalAddressName(), m_iLogicalAddress);
93729720
LOK
124 AddLog(CEC_LOG_DEBUG, strLog.c_str());
125
126 cec_command command;
127 cec_command::format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_STANDBY);
128
129 return m_processor->Transmit(command);
130}
131
132/** @name Getters */
133//@{
d7be392a 134cec_version CCECBusDevice::GetCecVersion(void)
93729720 135{
d7be392a 136 if (m_cecVersion == CEC_VERSION_UNKNOWN)
93729720 137 {
d7be392a
LOK
138 if (!MyLogicalAddressContains(m_iLogicalAddress))
139 {
5e822b09 140 CStdString strLog;
62f5527d 141 strLog.Format("<< requesting CEC version of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
5e822b09 142 AddLog(CEC_LOG_NOTICE, strLog);
d7be392a
LOK
143 cec_command command;
144 cec_command::format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GET_CEC_VERSION);
145 CLockObject lock(&m_mutex);
146 if (m_processor->Transmit(command))
147 m_condition.Wait(&m_mutex, 1000);
148 }
93729720
LOK
149 }
150
151 return m_cecVersion;
152}
153
62f5527d
LOK
154const char* CCECBusDevice::GetLogicalAddressName(void) const
155{
156 return CCECCommandHandler::ToString(m_iLogicalAddress);
157}
158
d7be392a 159cec_menu_language &CCECBusDevice::GetMenuLanguage(void)
93729720 160{
d7be392a 161 if (!strcmp(m_menuLanguage.language, "???"))
93729720 162 {
d7be392a
LOK
163 if (!MyLogicalAddressContains(m_iLogicalAddress))
164 {
5e822b09 165 CStdString strLog;
62f5527d 166 strLog.Format("<< requesting menu language of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
5e822b09 167 AddLog(CEC_LOG_NOTICE, strLog);
d7be392a
LOK
168 cec_command command;
169 cec_command::format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GET_MENU_LANGUAGE);
170 CLockObject lock(&m_mutex);
171 if (m_processor->Transmit(command))
172 m_condition.Wait(&m_mutex, 1000);
173 }
93729720
LOK
174 }
175
176 return m_menuLanguage;
177}
178
179cec_logical_address CCECBusDevice::GetMyLogicalAddress(void) const
180{
181 return m_processor->GetLogicalAddress();
f8513317
LOK
182}
183
e9de9629
LOK
184uint16_t CCECBusDevice::GetMyPhysicalAddress(void) const
185{
186 return m_processor->GetPhysicalAddress();
187}
188
d7be392a 189cec_power_status CCECBusDevice::GetPowerStatus(void)
e9de9629 190{
d7be392a 191 if (m_powerStatus == CEC_POWER_STATUS_UNKNOWN)
93729720 192 {
d7be392a
LOK
193 if (!MyLogicalAddressContains(m_iLogicalAddress))
194 {
5e822b09 195 CStdString strLog;
62f5527d 196 strLog.Format("<< requesting power status of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
5e822b09 197 AddLog(CEC_LOG_NOTICE, strLog);
d7be392a
LOK
198 cec_command command;
199 cec_command::format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GIVE_DEVICE_POWER_STATUS);
200 CLockObject lock(&m_mutex);
201 if (m_processor->Transmit(command))
202 m_condition.Wait(&m_mutex, 1000);
203 }
93729720
LOK
204 }
205
206 return m_powerStatus;
e9de9629
LOK
207}
208
93729720 209const cec_vendor &CCECBusDevice::GetVendor(void)
a3269a0a 210{
93729720 211 if (m_vendor.vendor == CEC_VENDOR_UNKNOWN)
a3269a0a 212 {
d7be392a
LOK
213 if (!MyLogicalAddressContains(m_iLogicalAddress))
214 {
5e822b09 215 CStdString strLog;
62f5527d 216 strLog.Format("<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
5e822b09 217 AddLog(CEC_LOG_NOTICE, strLog);
d7be392a
LOK
218 cec_command command;
219 cec_command::format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID);
220 CLockObject lock(&m_mutex);
93729720 221
d7be392a
LOK
222 if (m_processor->Transmit(command))
223 m_condition.Wait(&m_mutex, 1000);
224 }
a3269a0a 225 }
93729720
LOK
226
227 return m_vendor;
228}
229
230bool CCECBusDevice::MyLogicalAddressContains(cec_logical_address address) const
231{
232 return m_processor->HasLogicalAddress(address);
a3269a0a
LOK
233}
234
93729720
LOK
235//@}
236
237/** @name Setters */
238//@{
e55f3f70 239void CCECBusDevice::SetCecVersion(const cec_version newVersion)
6a1c0009
LOK
240{
241 CStdString strLog;
242 m_cecVersion = newVersion;
243
244 switch (newVersion)
245 {
246 case CEC_VERSION_1_2:
62f5527d 247 strLog.Format("%s (%X): CEC version 1.2", GetLogicalAddressName(), m_iLogicalAddress);
6a1c0009
LOK
248 break;
249 case CEC_VERSION_1_2A:
62f5527d 250 strLog.Format("%s (%X): CEC version 1.2a", GetLogicalAddressName(), m_iLogicalAddress);
6a1c0009
LOK
251 break;
252 case CEC_VERSION_1_3:
62f5527d 253 strLog.Format("%s (%X): CEC version 1.3", GetLogicalAddressName(), m_iLogicalAddress);
6a1c0009
LOK
254 break;
255 case CEC_VERSION_1_3A:
62f5527d 256 strLog.Format("%s (%X): CEC version 1.3a", GetLogicalAddressName(), m_iLogicalAddress);
6a1c0009
LOK
257 break;
258 default:
62f5527d 259 strLog.Format("%s (%X): unknown CEC version", GetLogicalAddressName(), m_iLogicalAddress);
6a1c0009
LOK
260 m_cecVersion = CEC_VERSION_UNKNOWN;
261 break;
262 }
263 AddLog(CEC_LOG_DEBUG, strLog);
264}
265
93729720
LOK
266void CCECBusDevice::SetMenuLanguage(const cec_menu_language &language)
267{
268 if (language.device == m_iLogicalAddress)
269 {
270 CStdString strLog;
62f5527d 271 strLog.Format(">> %s (%X): menu language set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, language.language);
93729720
LOK
272 m_processor->AddLog(CEC_LOG_DEBUG, strLog);
273 m_menuLanguage = language;
274 }
275}
276
9dc04b07 277void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress)
93729720
LOK
278{
279 if (iNewAddress > 0)
280 {
281 CStdString strLog;
62f5527d 282 strLog.Format(">> %s (%X): physical address changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress, iNewAddress);
93729720
LOK
283 AddLog(CEC_LOG_DEBUG, strLog.c_str());
284
285 m_iPhysicalAddress = iNewAddress;
286 }
287}
288
9dc04b07
LOK
289void CCECBusDevice::SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress /* = 0 */)
290{
291 if (iNewAddress > 0)
292 {
293 CStdString strLog;
62f5527d 294 strLog.Format(">> %s (%X): stream path changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress, iOldAddress, iNewAddress);
9dc04b07
LOK
295 AddLog(CEC_LOG_DEBUG, strLog.c_str());
296
297 m_iStreamPath = iNewAddress;
96274140
LOK
298
299 if (iNewAddress > 0)
300 SetPowerStatus(CEC_POWER_STATUS_ON);
9dc04b07
LOK
301 }
302}
303
e55f3f70
LOK
304void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus)
305{
b0271d54
LOK
306 if (m_powerStatus != powerStatus)
307 {
308 CStdString strLog;
62f5527d 309 strLog.Format(">> %s (%X): power status changed from %2x to %2x", GetLogicalAddressName(), m_iLogicalAddress, m_powerStatus, powerStatus);
b0271d54
LOK
310 m_processor->AddLog(CEC_LOG_DEBUG, strLog);
311 m_powerStatus = powerStatus;
312 }
e55f3f70
LOK
313}
314
2cd8b5d0 315void CCECBusDevice::SetVendorId(uint64_t iVendorId, uint8_t iVendorClass /* = 0 */)
e9de9629 316{
0500da96 317 m_vendor.vendor = (cec_vendor_id)iVendorId;
e9de9629
LOK
318 m_iVendorClass = iVendorClass;
319
320 switch (iVendorId)
321 {
322 case CEC_VENDOR_SAMSUNG:
0ab58650
LOK
323 if (m_handler->GetVendorId() != CEC_VENDOR_SAMSUNG)
324 {
325 delete m_handler;
326 m_handler = new CANCommandHandler(this);
327 }
e9de9629
LOK
328 break;
329 case CEC_VENDOR_LG:
0ab58650
LOK
330 if (m_handler->GetVendorId() != CEC_VENDOR_LG)
331 {
332 delete m_handler;
333 m_handler = new CSLCommandHandler(this);
334 }
e9de9629 335 break;
11621576
LOK
336 case CEC_VENDOR_PANASONIC:
337 if (m_handler->GetVendorId() != CEC_VENDOR_PANASONIC)
338 {
339 delete m_handler;
340 m_handler = new CVLCommandHandler(this);
341 }
342 break;
e9de9629 343 default:
0ab58650
LOK
344 if (m_handler->GetVendorId() != CEC_VENDOR_UNKNOWN)
345 {
346 delete m_handler;
347 m_handler = new CCECCommandHandler(this);
348 }
e9de9629
LOK
349 break;
350 }
351
352 CStdString strLog;
62f5527d 353 strLog.Format("%s (%X): vendor = %s (%06x) class = %2x", GetLogicalAddressName(), m_iLogicalAddress, GetVendorName(), GetVendorId(), GetVendorClass());
e9de9629
LOK
354 m_processor->AddLog(CEC_LOG_DEBUG, strLog.c_str());
355}
93729720 356//@}
e9de9629 357
93729720
LOK
358/** @name Transmit methods */
359//@{
360bool CCECBusDevice::TransmitActiveSource(void)
0f23c85c 361{
8747dd4f
LOK
362 if (m_bActiveSource)
363 {
364 CStdString strLog;
62f5527d 365 strLog.Format("<< %s (%X) -> broadcast (F): active source (%4x)", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress);
8747dd4f 366 AddLog(CEC_LOG_NOTICE, strLog);
0f23c85c 367
8747dd4f
LOK
368 cec_command command;
369 cec_command::format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_ACTIVE_SOURCE);
370 command.parameters.push_back((uint8_t) ((m_iPhysicalAddress >> 8) & 0xFF));
371 command.parameters.push_back((uint8_t) (m_iPhysicalAddress & 0xFF));
0f23c85c 372
8747dd4f
LOK
373 return m_processor->Transmit(command);
374 }
375 else
376 {
377 CStdString strLog;
62f5527d 378 strLog.Format("<< %s (%X) is not the active source", GetLogicalAddressName(), m_iLogicalAddress);
8747dd4f
LOK
379 AddLog(CEC_LOG_DEBUG, strLog);
380 }
381
382 return false;
0f23c85c
LOK
383}
384
93729720 385bool CCECBusDevice::TransmitActiveView(void)
0f23c85c 386{
d7be392a 387 CStdString strLog;
62f5527d 388 strLog.Format("<< %s (%X) -> broadcast (F): active view (%4x)", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress);
d7be392a 389 AddLog(CEC_LOG_NOTICE, strLog);
0f23c85c
LOK
390
391 cec_command command;
93729720
LOK
392 cec_command::format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_ACTIVE_SOURCE);
393 command.parameters.push_back((m_iPhysicalAddress >> 8) & 0xFF);
394 command.parameters.push_back(m_iPhysicalAddress & 0xFF);
0f23c85c
LOK
395
396 return m_processor->Transmit(command);
397}
398
29912296 399bool CCECBusDevice::TransmitCECVersion(cec_logical_address dest)
0f23c85c 400{
d7be392a 401 CStdString strLog;
62f5527d 402 strLog.Format("<< %s (%X) -> %s (%X): cec version ", GetLogicalAddressName(), m_iLogicalAddress, CCECCommandHandler::ToString(dest), dest);
d7be392a
LOK
403 switch (m_cecVersion)
404 {
405 case CEC_VERSION_1_2:
406 strLog.append("1.2");
407 break;
408 case CEC_VERSION_1_2A:
409 strLog.append("1.2a");
410 break;
411 case CEC_VERSION_1_3:
412 strLog.append("1.3");
413 break;
414 case CEC_VERSION_1_3A:
415 strLog.append("1.3a");
416 break;
417 default:
418 strLog.append("unknown");
419 break;
420 }
421 AddLog(CEC_LOG_NOTICE, strLog);
0f23c85c
LOK
422
423 cec_command command;
f8513317 424 cec_command::format(command, m_iLogicalAddress, dest, CEC_OPCODE_CEC_VERSION);
700c1ea7 425 command.parameters.push_back(m_cecVersion);
0f23c85c
LOK
426
427 return m_processor->Transmit(command);
428}
429
29912296 430bool CCECBusDevice::TransmitDeckStatus(cec_logical_address dest)
0f23c85c
LOK
431{
432 // need to support opcodes play and deck control before doing anything with this
d7be392a 433 CStdString strLog;
62f5527d 434 strLog.Format("<< %s (%X) -> %s (%X): deck status feature abort", GetLogicalAddressName(), m_iLogicalAddress, CCECCommandHandler::ToString(dest), dest);
d7be392a
LOK
435 AddLog(CEC_LOG_NOTICE, strLog);
436
a1f8fb1b 437 m_processor->TransmitAbort(dest, CEC_OPCODE_GIVE_DECK_STATUS);
0f23c85c
LOK
438 return false;
439}
440
93729720
LOK
441bool CCECBusDevice::TransmitInactiveView(void)
442{
d7be392a 443 CStdString strLog;
62f5527d 444 strLog.Format("<< %s (%X) -> broadcast (F): inactive view", GetLogicalAddressName(), m_iLogicalAddress);
d7be392a 445 AddLog(CEC_LOG_NOTICE, strLog);
93729720
LOK
446
447 cec_command command;
448 cec_command::format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_INACTIVE_SOURCE);
449 command.parameters.push_back((m_iPhysicalAddress >> 8) & 0xFF);
450 command.parameters.push_back(m_iPhysicalAddress & 0xFF);
451
452 return m_processor->Transmit(command);
453}
454
29912296 455bool CCECBusDevice::TransmitMenuState(cec_logical_address dest)
0f23c85c 456{
d7be392a 457 CStdString strLog;
62f5527d 458 strLog.Format("<< %s (%X) -> %s (%X): ", GetLogicalAddressName(), m_iLogicalAddress, CCECCommandHandler::ToString(dest), dest);
1844f5f7 459 if (m_bMenuActive)
d7be392a 460 strLog.append("menu active");
0f23c85c 461 else
d7be392a
LOK
462 strLog.append("menu inactive");
463 AddLog(CEC_LOG_NOTICE, strLog);
0f23c85c
LOK
464
465 cec_command command;
f8513317 466 cec_command::format(command, m_iLogicalAddress, dest, CEC_OPCODE_MENU_STATUS);
1844f5f7 467 command.parameters.push_back(m_bMenuActive ? (uint8_t) CEC_MENU_STATE_ACTIVATED : (uint8_t) CEC_MENU_STATE_DEACTIVATED);
0f23c85c
LOK
468
469 return m_processor->Transmit(command);
470}
471
29912296 472bool CCECBusDevice::TransmitOSDName(cec_logical_address dest)
0f23c85c 473{
0f23c85c 474 CStdString strLog;
62f5527d 475 strLog.Format("<< %s (%X) -> %s (%X): OSD name '%s'", GetLogicalAddressName(), m_iLogicalAddress, CCECCommandHandler::ToString(dest), dest, m_strDeviceName.c_str());
0f23c85c
LOK
476 AddLog(CEC_LOG_NOTICE, strLog.c_str());
477
478 cec_command command;
f8513317 479 cec_command::format(command, m_iLogicalAddress, dest, CEC_OPCODE_SET_OSD_NAME);
787a3cb8
LOK
480 for (unsigned int iPtr = 0; iPtr < m_strDeviceName.length(); iPtr++)
481 command.parameters.push_back(m_strDeviceName.at(iPtr));
0f23c85c
LOK
482
483 return m_processor->Transmit(command);
484}
485
38bdb943
LOK
486bool CCECBusDevice::TransmitOSDString(cec_logical_address dest, cec_display_control duration, const char *strMessage)
487{
488 CStdString strLog;
62f5527d 489 strLog.Format("<< %s (%X) -> %s (%X): display OSD message '%s'", GetLogicalAddressName(), m_iLogicalAddress, CCECCommandHandler::ToString(dest), dest, strMessage);
38bdb943
LOK
490 AddLog(CEC_LOG_NOTICE, strLog.c_str());
491
492 cec_command command;
493 cec_command::format(command, m_iLogicalAddress, dest, CEC_OPCODE_SET_OSD_STRING);
494 command.parameters.push_back((uint8_t)duration);
495
496 unsigned int iLen = strlen(strMessage);
497 if (iLen > 13) iLen = 13;
498
499 for (unsigned int iPtr = 0; iPtr < iLen; iPtr++)
500 command.parameters.push_back(strMessage[iPtr]);
501
502 return m_processor->Transmit(command);
503}
504
29912296 505bool CCECBusDevice::TransmitPhysicalAddress(void)
0f23c85c
LOK
506{
507 CStdString strLog;
62f5527d 508 strLog.Format("<< %s (%X) -> broadcast (F): physical adddress %4x", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress);
0f23c85c
LOK
509 AddLog(CEC_LOG_NOTICE, strLog.c_str());
510
511 cec_command command;
f8513317 512 cec_command::format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_REPORT_PHYSICAL_ADDRESS);
0f23c85c
LOK
513 command.parameters.push_back((uint8_t) ((m_iPhysicalAddress >> 8) & 0xFF));
514 command.parameters.push_back((uint8_t) (m_iPhysicalAddress & 0xFF));
6fc97923 515 command.parameters.push_back((uint8_t) (m_type));
0f23c85c
LOK
516
517 return m_processor->Transmit(command);
518}
519
93729720 520bool CCECBusDevice::TransmitPoll(cec_logical_address dest)
57f45e6c
LOK
521{
522 bool bReturn(false);
523
93729720
LOK
524 if (dest == CECDEVICE_UNKNOWN)
525 dest = m_iLogicalAddress;
f8513317 526
57f45e6c 527 CStdString strLog;
62f5527d 528 strLog.Format("<< %s (%X) -> %s (%X): POLL", GetLogicalAddressName(), m_iLogicalAddress, CCECCommandHandler::ToString(dest), dest);
d7be392a 529 AddLog(CEC_LOG_NOTICE, strLog.c_str());
57f45e6c
LOK
530
531 cec_command command;
93729720 532 cec_command::format(command, m_iLogicalAddress, dest, CEC_OPCODE_NONE);
57f45e6c
LOK
533 CLockObject lock(&m_mutex);
534
535 bReturn = m_processor->Transmit(command);
536 AddLog(CEC_LOG_DEBUG, bReturn ? ">> POLL sent" : ">> POLL not sent");
537 return bReturn;
538}
93729720
LOK
539
540bool CCECBusDevice::TransmitPowerState(cec_logical_address dest)
541{
542 CStdString strLog;
62f5527d 543 strLog.Format("<< %s (%X) -> %s (%X): ", GetLogicalAddressName(), m_iLogicalAddress, CCECCommandHandler::ToString(dest), dest);
d7be392a
LOK
544
545 switch (m_powerStatus)
546 {
547 case CEC_POWER_STATUS_ON:
548 strLog.append("powered on");
549 break;
550 case CEC_POWER_STATUS_STANDBY:
551 strLog.append("in standby mode");
552 break;
553 case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY:
554 strLog.append("in transition from on to standby");
555 break;
556 case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON:
557 strLog.append("in transition from standby to on");
558 break;
559 default:
560 strLog.append("power state unknown");
561 break;
562 }
563 AddLog(CEC_LOG_NOTICE, strLog.c_str());
564
93729720
LOK
565 strLog.Format("<< reporting power status '%d'", m_powerStatus);
566 AddLog(CEC_LOG_NOTICE, strLog);
567
568 cec_command command;
569 cec_command::format(command, m_iLogicalAddress, dest, CEC_OPCODE_REPORT_POWER_STATUS);
570 command.parameters.push_back((uint8_t) m_powerStatus);
571
572 return m_processor->Transmit(command);
573}
574
575bool CCECBusDevice::TransmitVendorID(cec_logical_address dest)
576{
d7be392a 577 CStdString strLog;
62f5527d 578 strLog.Format("<< %s (%X) -> %s (%X): vendor id feature abort", GetLogicalAddressName(), m_iLogicalAddress, CCECCommandHandler::ToString(dest), dest);
d7be392a
LOK
579 AddLog(CEC_LOG_NOTICE, strLog);
580
93729720
LOK
581 m_processor->TransmitAbort(dest, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID);
582 return false;
583}
584//@}