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