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