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