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