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