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