Commit | Line | Data |
---|---|---|
abbca718 LOK |
1 | /* |
2 | * This file is part of the libCEC(R) library. | |
3 | * | |
b492c10e | 4 | * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved. |
abbca718 LOK |
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 | ||
2abe74eb | 33 | #include "CECProcessor.h" |
abbca718 | 34 | |
7bb4ed43 | 35 | #include "adapter/USBCECAdapterCommunication.h" |
eafa9d46 | 36 | #include "devices/CECBusDevice.h" |
51b2a094 LOK |
37 | #include "devices/CECAudioSystem.h" |
38 | #include "devices/CECPlaybackDevice.h" | |
39 | #include "devices/CECRecordingDevice.h" | |
40 | #include "devices/CECTuner.h" | |
41 | #include "devices/CECTV.h" | |
62f5527d | 42 | #include "implementations/CECCommandHandler.h" |
2abe74eb | 43 | #include "LibCEC.h" |
ba65909d | 44 | #include "platform/util/timeutils.h" |
abbca718 LOK |
45 | |
46 | using namespace CEC; | |
47 | using namespace std; | |
f00ff009 | 48 | using namespace PLATFORM; |
abbca718 | 49 | |
caca2d81 LOK |
50 | CCECProcessor::CCECProcessor(CLibCEC *controller, const libcec_configuration *configuration) : |
51 | m_bInitialised(false), | |
caca2d81 LOK |
52 | m_communication(NULL), |
53 | m_controller(controller), | |
54 | m_bMonitor(false), | |
55 | m_iStandardLineTimeout(3), | |
56 | m_iRetryLineTimeout(3), | |
30b4aac0 | 57 | m_iLastTransmission(0) |
caca2d81 LOK |
58 | { |
59 | m_logicalAddresses.Clear(); | |
60 | CreateBusDevices(); | |
30b4aac0 LOK |
61 | m_configuration.Clear(); |
62 | ||
63 | SetConfiguration(configuration); | |
64 | ||
65 | if (m_configuration.tvVendor != CEC_VENDOR_UNKNOWN) | |
ed63a515 | 66 | m_busDevices[CECDEVICE_TV]->ReplaceHandler(false); |
caca2d81 LOK |
67 | } |
68 | ||
69 | CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, const cec_device_type_list &types, uint16_t iPhysicalAddress, cec_client_version clientVersion) : | |
b64db02e | 70 | m_bInitialised(false), |
99666519 | 71 | m_communication(NULL), |
f8513317 | 72 | m_controller(controller), |
dcd240b2 LOK |
73 | m_bMonitor(false), |
74 | m_iStandardLineTimeout(3), | |
5f316715 | 75 | m_iRetryLineTimeout(3), |
30b4aac0 | 76 | m_iLastTransmission(0) |
f8513317 | 77 | { |
30b4aac0 LOK |
78 | m_configuration.Clear(); |
79 | ||
80 | // client version < 1.5.0 | |
81 | m_configuration.clientVersion = clientVersion; | |
82 | snprintf(m_configuration.strDeviceName, 13, "%s", strDeviceName); | |
83 | m_configuration.deviceTypes = types; | |
84 | m_configuration.iPhysicalAddress = iPhysicalAddress; | |
85 | m_configuration.baseDevice = (cec_logical_address)CEC_DEFAULT_BASE_DEVICE; | |
86 | m_configuration.iHDMIPort = CEC_DEFAULT_HDMI_PORT; | |
87 | ||
88 | if (m_configuration.deviceTypes.IsEmpty()) | |
89 | m_configuration.deviceTypes.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE); | |
ab1469a0 | 90 | m_logicalAddresses.Clear(); |
caca2d81 LOK |
91 | CreateBusDevices(); |
92 | } | |
93 | ||
94 | void CCECProcessor::CreateBusDevices(void) | |
95 | { | |
f8513317 | 96 | for (int iPtr = 0; iPtr < 16; iPtr++) |
51b2a094 LOK |
97 | { |
98 | switch(iPtr) | |
99 | { | |
100 | case CECDEVICE_AUDIOSYSTEM: | |
5d5a2dc2 | 101 | m_busDevices[iPtr] = new CCECAudioSystem(this, (cec_logical_address) iPtr, 0xFFFF); |
51b2a094 LOK |
102 | break; |
103 | case CECDEVICE_PLAYBACKDEVICE1: | |
104 | case CECDEVICE_PLAYBACKDEVICE2: | |
105 | case CECDEVICE_PLAYBACKDEVICE3: | |
5d5a2dc2 | 106 | m_busDevices[iPtr] = new CCECPlaybackDevice(this, (cec_logical_address) iPtr, 0xFFFF); |
51b2a094 LOK |
107 | break; |
108 | case CECDEVICE_RECORDINGDEVICE1: | |
109 | case CECDEVICE_RECORDINGDEVICE2: | |
110 | case CECDEVICE_RECORDINGDEVICE3: | |
5d5a2dc2 | 111 | m_busDevices[iPtr] = new CCECRecordingDevice(this, (cec_logical_address) iPtr, 0xFFFF); |
51b2a094 LOK |
112 | break; |
113 | case CECDEVICE_TUNER1: | |
114 | case CECDEVICE_TUNER2: | |
115 | case CECDEVICE_TUNER3: | |
116 | case CECDEVICE_TUNER4: | |
5d5a2dc2 | 117 | m_busDevices[iPtr] = new CCECTuner(this, (cec_logical_address) iPtr, 0xFFFF); |
51b2a094 LOK |
118 | break; |
119 | case CECDEVICE_TV: | |
120 | m_busDevices[iPtr] = new CCECTV(this, (cec_logical_address) iPtr, 0); | |
121 | break; | |
122 | default: | |
5d5a2dc2 | 123 | m_busDevices[iPtr] = new CCECBusDevice(this, (cec_logical_address) iPtr, 0xFFFF); |
51b2a094 LOK |
124 | break; |
125 | } | |
126 | } | |
f8513317 LOK |
127 | } |
128 | ||
2abe74eb | 129 | CCECProcessor::~CCECProcessor(void) |
abbca718 | 130 | { |
eca71746 | 131 | Close(); |
7c63a480 | 132 | |
d1998c7b LOK |
133 | for (unsigned int iPtr = 0; iPtr < 16; iPtr++) |
134 | delete m_busDevices[iPtr]; | |
abbca718 LOK |
135 | } |
136 | ||
eca71746 LOK |
137 | void CCECProcessor::Close(void) |
138 | { | |
139 | StopThread(); | |
140 | ||
141 | CLockObject lock(m_mutex); | |
142 | if (m_communication) | |
143 | { | |
144 | m_communication->Close(); | |
145 | delete m_communication; | |
146 | m_communication = NULL; | |
147 | } | |
148 | } | |
149 | ||
578c3905 | 150 | bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint32_t iTimeoutMs) |
abbca718 | 151 | { |
a674fd68 | 152 | bool bReturn(false); |
578c3905 | 153 | CLockObject lock(m_mutex); |
99666519 | 154 | if (m_communication) |
578c3905 | 155 | { |
9f9c8c82 LOK |
156 | CLibCEC::AddLog(CEC_LOG_WARNING, "existing connection handler found, deleting it"); |
157 | m_communication->Close(); | |
158 | delete m_communication; | |
578c3905 | 159 | } |
1113cb7d | 160 | |
7bb4ed43 | 161 | m_communication = new CUSBCECAdapterCommunication(this, strPort, iBaudRate); |
99666519 | 162 | |
578c3905 LOK |
163 | /* check for an already opened connection */ |
164 | if (m_communication->IsOpen()) | |
1113cb7d | 165 | { |
5477a250 | 166 | CLibCEC::AddLog(CEC_LOG_ERROR, "connection already opened"); |
578c3905 LOK |
167 | return bReturn; |
168 | } | |
abbca718 | 169 | |
c520af4f LOK |
170 | uint64_t iNow = GetTimeMs(); |
171 | uint64_t iTarget = iTimeoutMs > 0 ? iNow + iTimeoutMs : iNow + CEC_DEFAULT_TRANSMIT_WAIT; | |
172 | ||
578c3905 | 173 | /* open a new connection */ |
efed01e1 LOK |
174 | unsigned iConnectTry(0); |
175 | while (iNow < iTarget && (bReturn = m_communication->Open(this, iTimeoutMs)) == false) | |
3d78df91 LOK |
176 | { |
177 | CLibCEC::AddLog(CEC_LOG_ERROR, "could not open a connection (try %d)", ++iConnectTry); | |
178 | Sleep(500); | |
179 | iNow = GetTimeMs(); | |
180 | } | |
56035c86 | 181 | |
efed01e1 | 182 | if (bReturn) |
30b4aac0 | 183 | CLibCEC::AddLog(CEC_LOG_NOTICE, "connected to the CEC adapter. firmware version = %d, client version = %s", m_communication->GetFirmwareVersion(), ToString(m_configuration.clientVersion)); |
3d78df91 | 184 | |
578c3905 LOK |
185 | return bReturn; |
186 | } | |
187 | ||
0cfdeb5a LOK |
188 | bool CCECProcessor::IsInitialised(void) |
189 | { | |
190 | CLockObject lock(m_mutex); | |
191 | return m_bInitialised; | |
192 | } | |
193 | ||
2db8981f | 194 | void CCECProcessor::SetInitialised(bool bSetTo /* = true */) |
578c3905 | 195 | { |
578c3905 | 196 | CLockObject lock(m_mutex); |
2db8981f LOK |
197 | m_bInitialised = bSetTo; |
198 | } | |
578c3905 | 199 | |
2db8981f LOK |
200 | bool CCECProcessor::Initialise(void) |
201 | { | |
202 | bool bReturn(false); | |
578c3905 | 203 | { |
2db8981f LOK |
204 | CLockObject lock(m_mutex); |
205 | if (!m_logicalAddresses.IsEmpty()) | |
206 | m_logicalAddresses.Clear(); | |
578c3905 | 207 | |
2db8981f LOK |
208 | if (!FindLogicalAddresses()) |
209 | { | |
5477a250 | 210 | CLibCEC::AddLog(CEC_LOG_ERROR, "could not detect our logical addresses"); |
2db8981f LOK |
211 | return bReturn; |
212 | } | |
213 | ||
214 | /* only set our OSD name for the primary device */ | |
30b4aac0 | 215 | m_busDevices[m_logicalAddresses.primary]->m_strDeviceName = m_configuration.strDeviceName; |
2db8981f | 216 | } |
578c3905 LOK |
217 | |
218 | /* get the vendor id from the TV, so we are using the correct handler */ | |
30b4aac0 | 219 | m_busDevices[CECDEVICE_TV]->GetVendorId(); |
578c3905 | 220 | |
30b4aac0 | 221 | if (m_configuration.iPhysicalAddress != 0) |
4f362964 | 222 | { |
30b4aac0 LOK |
223 | CLibCEC::AddLog(CEC_LOG_NOTICE, "setting the physical address to %4x", m_configuration.iPhysicalAddress); |
224 | m_busDevices[m_logicalAddresses.primary]->m_iPhysicalAddress = m_configuration.iPhysicalAddress; | |
4f362964 | 225 | if ((bReturn = m_busDevices[m_logicalAddresses.primary]->TransmitPhysicalAddress()) == false) |
30b4aac0 | 226 | CLibCEC::AddLog(CEC_LOG_ERROR, "unable to set the physical address to %4x", m_configuration.iPhysicalAddress); |
4f362964 | 227 | } |
30b4aac0 LOK |
228 | else if (m_configuration.iPhysicalAddress == 0 && (bReturn = SetHDMIPort(m_configuration.baseDevice, m_configuration.iHDMIPort, true)) == false) |
229 | CLibCEC::AddLog(CEC_LOG_ERROR, "unable to set HDMI port %d on %s (%x)", m_configuration.iHDMIPort, ToString(m_configuration.baseDevice), (uint8_t)m_configuration.baseDevice); | |
2db8981f | 230 | |
ca27e6cf | 231 | PowerOnDevices(); |
d068b3d4 | 232 | |
2db8981f | 233 | SetInitialised(bReturn); |
32403cc3 | 234 | CLibCEC::ConfigurationChanged(m_configuration); |
578c3905 LOK |
235 | |
236 | return bReturn; | |
237 | } | |
238 | ||
239 | bool CCECProcessor::Start(const char *strPort, uint16_t iBaudRate /* = 38400 */, uint32_t iTimeoutMs /* = 10000 */) | |
240 | { | |
241 | bool bReturn(false); | |
242 | ||
243 | { | |
244 | CLockObject lock(m_mutex); | |
245 | if (!OpenConnection(strPort, iBaudRate, iTimeoutMs)) | |
a674fd68 | 246 | return bReturn; |
994dbaaa | 247 | |
a674fd68 | 248 | /* create the processor thread */ |
8e57f83c | 249 | if (!CreateThread()) |
a674fd68 | 250 | { |
5477a250 | 251 | CLibCEC::AddLog(CEC_LOG_ERROR, "could not create a processor thread"); |
a674fd68 | 252 | return bReturn; |
994dbaaa | 253 | } |
a674fd68 LOK |
254 | } |
255 | ||
578c3905 | 256 | if ((bReturn = Initialise()) == false) |
a674fd68 | 257 | { |
5477a250 | 258 | CLibCEC::AddLog(CEC_LOG_ERROR, "could not create a processor thread"); |
578c3905 | 259 | StopThread(true); |
a674fd68 LOK |
260 | } |
261 | else | |
262 | { | |
5477a250 | 263 | CLibCEC::AddLog(CEC_LOG_DEBUG, "processor thread started"); |
a674fd68 LOK |
264 | } |
265 | ||
266 | return bReturn; | |
abbca718 LOK |
267 | } |
268 | ||
b58d9277 | 269 | bool CCECProcessor::TryLogicalAddress(cec_logical_address address) |
f8513317 | 270 | { |
93fff5c1 | 271 | if (m_busDevices[address]->TryLogicalAddress()) |
f8513317 | 272 | { |
ab1469a0 | 273 | m_logicalAddresses.Set(address); |
f8513317 LOK |
274 | return true; |
275 | } | |
276 | ||
f8513317 LOK |
277 | return false; |
278 | } | |
279 | ||
b58d9277 | 280 | bool CCECProcessor::FindLogicalAddressRecordingDevice(void) |
f8513317 | 281 | { |
5477a250 | 282 | CLibCEC::AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'recording device'"); |
b58d9277 LOK |
283 | return TryLogicalAddress(CECDEVICE_RECORDINGDEVICE1) || |
284 | TryLogicalAddress(CECDEVICE_RECORDINGDEVICE2) || | |
285 | TryLogicalAddress(CECDEVICE_RECORDINGDEVICE3); | |
f8513317 LOK |
286 | } |
287 | ||
b58d9277 | 288 | bool CCECProcessor::FindLogicalAddressTuner(void) |
f8513317 | 289 | { |
5477a250 | 290 | CLibCEC::AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'tuner'"); |
b58d9277 LOK |
291 | return TryLogicalAddress(CECDEVICE_TUNER1) || |
292 | TryLogicalAddress(CECDEVICE_TUNER2) || | |
293 | TryLogicalAddress(CECDEVICE_TUNER3) || | |
294 | TryLogicalAddress(CECDEVICE_TUNER4); | |
f8513317 LOK |
295 | } |
296 | ||
b58d9277 | 297 | bool CCECProcessor::FindLogicalAddressPlaybackDevice(void) |
f8513317 | 298 | { |
5477a250 | 299 | CLibCEC::AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'playback device'"); |
b58d9277 LOK |
300 | return TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE1) || |
301 | TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE2) || | |
302 | TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE3); | |
f8513317 LOK |
303 | } |
304 | ||
b58d9277 | 305 | bool CCECProcessor::FindLogicalAddressAudioSystem(void) |
f8513317 | 306 | { |
5477a250 | 307 | CLibCEC::AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'audio'"); |
b58d9277 | 308 | return TryLogicalAddress(CECDEVICE_AUDIOSYSTEM); |
f8513317 LOK |
309 | } |
310 | ||
3e61b350 LOK |
311 | bool CCECProcessor::ChangeDeviceType(cec_device_type from, cec_device_type to) |
312 | { | |
313 | bool bChanged(false); | |
314 | ||
5477a250 | 315 | CLibCEC::AddLog(CEC_LOG_NOTICE, "changing device type '%s' into '%s'", ToString(from), ToString(to)); |
3e61b350 | 316 | |
f00ff009 | 317 | CLockObject lock(m_mutex); |
3e61b350 LOK |
318 | CCECBusDevice *previousDevice = GetDeviceByType(from); |
319 | m_logicalAddresses.primary = CECDEVICE_UNKNOWN; | |
320 | ||
321 | for (unsigned int iPtr = 0; iPtr < 5; iPtr++) | |
322 | { | |
30b4aac0 | 323 | if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_RESERVED) |
3e61b350 LOK |
324 | continue; |
325 | ||
30b4aac0 | 326 | if (m_configuration.deviceTypes.types[iPtr] == from) |
3e61b350 LOK |
327 | { |
328 | bChanged = true; | |
30b4aac0 | 329 | m_configuration.deviceTypes.types[iPtr] = to; |
3e61b350 | 330 | } |
30b4aac0 | 331 | else if (m_configuration.deviceTypes.types[iPtr] == to && bChanged) |
3e61b350 | 332 | { |
30b4aac0 | 333 | m_configuration.deviceTypes.types[iPtr] = CEC_DEVICE_TYPE_RESERVED; |
3e61b350 LOK |
334 | } |
335 | } | |
336 | ||
337 | if (bChanged) | |
338 | { | |
339 | FindLogicalAddresses(); | |
340 | ||
341 | CCECBusDevice *newDevice = GetDeviceByType(to); | |
342 | if (previousDevice && newDevice) | |
343 | { | |
344 | newDevice->SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC); | |
4478bc79 | 345 | previousDevice->SetDeviceStatus(CEC_DEVICE_STATUS_NOT_PRESENT); |
3e61b350 LOK |
346 | |
347 | newDevice->SetCecVersion(previousDevice->GetCecVersion(false)); | |
348 | previousDevice->SetCecVersion(CEC_VERSION_UNKNOWN); | |
349 | ||
350 | newDevice->SetMenuLanguage(previousDevice->GetMenuLanguage(false)); | |
351 | cec_menu_language lang; | |
352 | lang.device = previousDevice->GetLogicalAddress(); | |
353 | for (unsigned int iPtr = 0; iPtr < 4; iPtr++) | |
354 | lang.language[iPtr] = '?'; | |
355 | lang.language[3] = 0; | |
356 | previousDevice->SetMenuLanguage(lang); | |
357 | ||
358 | newDevice->SetMenuState(previousDevice->GetMenuState()); | |
359 | previousDevice->SetMenuState(CEC_MENU_STATE_DEACTIVATED); | |
360 | ||
361 | newDevice->SetOSDName(previousDevice->GetOSDName(false)); | |
362 | previousDevice->SetOSDName(ToString(previousDevice->GetLogicalAddress())); | |
363 | ||
364 | newDevice->SetPhysicalAddress(previousDevice->GetPhysicalAddress(false)); | |
365 | previousDevice->SetPhysicalAddress(0xFFFF); | |
366 | ||
367 | newDevice->SetPowerStatus(previousDevice->GetPowerStatus(false)); | |
368 | previousDevice->SetPowerStatus(CEC_POWER_STATUS_UNKNOWN); | |
369 | ||
370 | newDevice->SetVendorId(previousDevice->GetVendorId(false)); | |
371 | previousDevice->SetVendorId(CEC_VENDOR_UNKNOWN); | |
372 | ||
373 | if ((from == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || from == CEC_DEVICE_TYPE_RECORDING_DEVICE) && | |
374 | (to == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || to == CEC_DEVICE_TYPE_RECORDING_DEVICE)) | |
375 | { | |
376 | ((CCECPlaybackDevice *) newDevice)->SetDeckControlMode(((CCECPlaybackDevice *) previousDevice)->GetDeckControlMode()); | |
377 | ((CCECPlaybackDevice *) previousDevice)->SetDeckControlMode(CEC_DECK_CONTROL_MODE_STOP); | |
378 | ||
379 | ((CCECPlaybackDevice *) newDevice)->SetDeckStatus(((CCECPlaybackDevice *) previousDevice)->GetDeckStatus()); | |
380 | ((CCECPlaybackDevice *) previousDevice)->SetDeckStatus(CEC_DECK_INFO_STOP); | |
381 | } | |
382 | } | |
383 | } | |
384 | ||
385 | return true; | |
386 | } | |
387 | ||
f8513317 LOK |
388 | bool CCECProcessor::FindLogicalAddresses(void) |
389 | { | |
390 | bool bReturn(true); | |
ab1469a0 | 391 | m_logicalAddresses.Clear(); |
f8513317 | 392 | |
30b4aac0 | 393 | if (m_configuration.deviceTypes.IsEmpty()) |
c39611ec LOK |
394 | { |
395 | CLibCEC::AddLog(CEC_LOG_ERROR, "no device types set"); | |
396 | return false; | |
397 | } | |
398 | ||
f8513317 LOK |
399 | for (unsigned int iPtr = 0; iPtr < 5; iPtr++) |
400 | { | |
30b4aac0 | 401 | if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_RESERVED) |
f8513317 LOK |
402 | continue; |
403 | ||
30b4aac0 | 404 | CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - device %d: type %d", __FUNCTION__, iPtr, m_configuration.deviceTypes.types[iPtr]); |
f8513317 | 405 | |
30b4aac0 | 406 | if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_RECORDING_DEVICE) |
b58d9277 | 407 | bReturn &= FindLogicalAddressRecordingDevice(); |
30b4aac0 | 408 | if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_TUNER) |
b58d9277 | 409 | bReturn &= FindLogicalAddressTuner(); |
30b4aac0 | 410 | if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_PLAYBACK_DEVICE) |
b58d9277 | 411 | bReturn &= FindLogicalAddressPlaybackDevice(); |
30b4aac0 | 412 | if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_AUDIO_SYSTEM) |
b58d9277 | 413 | bReturn &= FindLogicalAddressAudioSystem(); |
f8513317 LOK |
414 | } |
415 | ||
a674fd68 LOK |
416 | if (bReturn) |
417 | SetAckMask(m_logicalAddresses.AckMask()); | |
418 | ||
f8513317 LOK |
419 | return bReturn; |
420 | } | |
421 | ||
a3ffc068 LOK |
422 | void CCECProcessor::ReplaceHandlers(void) |
423 | { | |
0cfdeb5a LOK |
424 | if (!IsInitialised()) |
425 | return; | |
a3ffc068 | 426 | for (uint8_t iPtr = 0; iPtr <= CECDEVICE_PLAYBACKDEVICE3; iPtr++) |
591170fd | 427 | m_busDevices[iPtr]->ReplaceHandler(m_bInitialised); |
a3ffc068 LOK |
428 | } |
429 | ||
b1f94db1 LOK |
430 | bool CCECProcessor::OnCommandReceived(const cec_command &command) |
431 | { | |
432 | m_commandBuffer.Push(command); | |
433 | return true; | |
434 | } | |
435 | ||
2abe74eb | 436 | void *CCECProcessor::Process(void) |
f99bc831 | 437 | { |
8e57f83c LOK |
438 | cec_command command; |
439 | CLibCEC::AddLog(CEC_LOG_DEBUG, "processor thread started"); | |
abbca718 | 440 | |
b1f94db1 | 441 | while (!IsStopped() && m_communication->IsOpen()) |
abbca718 | 442 | { |
f0154449 LOK |
443 | if (IsInitialised()) |
444 | { | |
445 | ReplaceHandlers(); | |
446 | if (m_commandBuffer.Pop(command)) | |
447 | ParseCommand(command); | |
b5f34cf9 | 448 | |
f0154449 LOK |
449 | m_controller->CheckKeypressTimeout(); |
450 | } | |
b1f94db1 | 451 | Sleep(5); |
abbca718 LOK |
452 | } |
453 | ||
60fa4578 | 454 | return NULL; |
abbca718 LOK |
455 | } |
456 | ||
18203d17 | 457 | bool CCECProcessor::SetActiveSource(cec_device_type type /* = CEC_DEVICE_TYPE_RESERVED */) |
abbca718 | 458 | { |
8ac9c610 LOK |
459 | bool bReturn(false); |
460 | ||
60fa4578 | 461 | if (!IsRunning()) |
8ac9c610 | 462 | return bReturn; |
f99bc831 | 463 | |
18203d17 | 464 | cec_logical_address addr = m_logicalAddresses.primary; |
04437dcf | 465 | |
18203d17 LOK |
466 | if (type != CEC_DEVICE_TYPE_RESERVED) |
467 | { | |
90ea9066 | 468 | for (uint8_t iPtr = 0; iPtr <= 11; iPtr++) |
18203d17 LOK |
469 | { |
470 | if (m_logicalAddresses[iPtr] && m_busDevices[iPtr]->m_type == type) | |
471 | { | |
472 | addr = (cec_logical_address) iPtr; | |
473 | break; | |
474 | } | |
475 | } | |
476 | } | |
477 | ||
37b0c572 | 478 | m_busDevices[addr]->SetActiveSource(); |
d383d6d0 | 479 | if (m_busDevices[addr]->GetPhysicalAddress(false) != 0xFFFF) |
bbc71623 | 480 | bReturn = m_busDevices[addr]->ActivateSource(); |
8d915412 LOK |
481 | |
482 | return bReturn; | |
18203d17 LOK |
483 | } |
484 | ||
37b0c572 LOK |
485 | bool CCECProcessor::SetActiveSource(uint16_t iStreamPath) |
486 | { | |
487 | bool bReturn(false); | |
488 | ||
489 | CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamPath); | |
490 | if (device) | |
491 | { | |
492 | device->SetActiveSource(); | |
493 | bReturn = true; | |
494 | } | |
495 | ||
496 | return bReturn; | |
497 | } | |
498 | ||
dcd240b2 LOK |
499 | void CCECProcessor::SetStandardLineTimeout(uint8_t iTimeout) |
500 | { | |
f00ff009 | 501 | CLockObject lock(m_mutex); |
dcd240b2 LOK |
502 | m_iStandardLineTimeout = iTimeout; |
503 | } | |
504 | ||
505 | void CCECProcessor::SetRetryLineTimeout(uint8_t iTimeout) | |
506 | { | |
f00ff009 | 507 | CLockObject lock(m_mutex); |
dcd240b2 LOK |
508 | m_iRetryLineTimeout = iTimeout; |
509 | } | |
510 | ||
18203d17 LOK |
511 | bool CCECProcessor::SetActiveView(void) |
512 | { | |
30b4aac0 | 513 | return SetActiveSource(m_configuration.deviceTypes.IsEmpty() ? CEC_DEVICE_TYPE_RESERVED : m_configuration.deviceTypes[0]); |
8ac9c610 LOK |
514 | } |
515 | ||
28fa6c97 | 516 | bool CCECProcessor::SetDeckControlMode(cec_deck_control_mode mode, bool bSendUpdate /* = true */) |
a9232a79 LOK |
517 | { |
518 | bool bReturn(false); | |
519 | ||
520 | CCECBusDevice *device = GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE); | |
521 | if (device) | |
522 | { | |
523 | ((CCECPlaybackDevice *) device)->SetDeckControlMode(mode); | |
28fa6c97 LOK |
524 | if (bSendUpdate) |
525 | ((CCECPlaybackDevice *) device)->TransmitDeckStatus(CECDEVICE_TV); | |
a9232a79 LOK |
526 | bReturn = true; |
527 | } | |
528 | ||
529 | return bReturn; | |
530 | } | |
531 | ||
28fa6c97 | 532 | bool CCECProcessor::SetDeckInfo(cec_deck_info info, bool bSendUpdate /* = true */) |
a9232a79 LOK |
533 | { |
534 | bool bReturn(false); | |
535 | ||
536 | CCECBusDevice *device = GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE); | |
537 | if (device) | |
538 | { | |
539 | ((CCECPlaybackDevice *) device)->SetDeckStatus(info); | |
28fa6c97 LOK |
540 | if (bSendUpdate) |
541 | ((CCECPlaybackDevice *) device)->TransmitDeckStatus(CECDEVICE_TV); | |
a9232a79 LOK |
542 | bReturn = true; |
543 | } | |
544 | ||
545 | return bReturn; | |
546 | } | |
547 | ||
d2f1c157 | 548 | bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort, bool bForce /* = false */) |
16b1e052 LOK |
549 | { |
550 | bool bReturn(false); | |
f00ff009 | 551 | CLockObject lock(m_mutex); |
16b1e052 | 552 | |
30b4aac0 LOK |
553 | m_configuration.baseDevice = iBaseDevice; |
554 | m_configuration.iHDMIPort = iPort; | |
8e57f83c | 555 | if (!IsRunning() && !bForce) |
89b3c9df | 556 | return true; |
16b1e052 | 557 | |
5477a250 | 558 | CLibCEC::AddLog(CEC_LOG_DEBUG, "setting HDMI port to %d on device %s (%d)", iPort, ToString(iBaseDevice), (int)iBaseDevice); |
56035c86 | 559 | |
16b1e052 | 560 | uint16_t iPhysicalAddress(0); |
1e7afacd | 561 | if (iBaseDevice > CECDEVICE_TV) |
5d0c1164 | 562 | { |
f00ff009 | 563 | lock.Unlock(); |
1e7afacd | 564 | iPhysicalAddress = m_busDevices[iBaseDevice]->GetPhysicalAddress(); |
5d0c1164 LOK |
565 | lock.Lock(); |
566 | } | |
1e7afacd | 567 | |
a674fd68 | 568 | if (iPhysicalAddress < 0xffff) |
1e7afacd | 569 | { |
1e7afacd | 570 | if (iPhysicalAddress == 0) |
5d355340 | 571 | iPhysicalAddress += 0x1000 * iPort; |
1e7afacd | 572 | else if (iPhysicalAddress % 0x1000 == 0) |
5d355340 | 573 | iPhysicalAddress += 0x100 * iPort; |
1e7afacd | 574 | else if (iPhysicalAddress % 0x100 == 0) |
5d355340 | 575 | iPhysicalAddress += 0x10 * iPort; |
1e7afacd | 576 | else if (iPhysicalAddress % 0x10 == 0) |
5d355340 | 577 | iPhysicalAddress += iPort; |
1e7afacd | 578 | |
5d355340 | 579 | bReturn = true; |
16b1e052 LOK |
580 | } |
581 | ||
a674fd68 | 582 | if (!bReturn) |
5477a250 | 583 | CLibCEC::AddLog(CEC_LOG_ERROR, "failed to set the physical address"); |
f070564b LOK |
584 | else |
585 | { | |
f00ff009 | 586 | lock.Unlock(); |
f070564b LOK |
587 | SetPhysicalAddress(iPhysicalAddress); |
588 | } | |
a674fd68 | 589 | |
16b1e052 LOK |
590 | return bReturn; |
591 | } | |
592 | ||
45b97de7 | 593 | bool CCECProcessor::PhysicalAddressInUse(uint16_t iPhysicalAddress) |
16b1e052 | 594 | { |
9fd73dd4 | 595 | for (unsigned int iPtr = 0; iPtr < 15; iPtr++) |
16b1e052 LOK |
596 | { |
597 | if (m_busDevices[iPtr]->GetPhysicalAddress(false) == iPhysicalAddress) | |
598 | return true; | |
599 | } | |
600 | return false; | |
601 | } | |
602 | ||
ab27363d | 603 | bool CCECProcessor::TransmitInactiveSource(void) |
abbca718 | 604 | { |
60fa4578 | 605 | if (!IsRunning()) |
f99bc831 LOK |
606 | return false; |
607 | ||
ab1469a0 | 608 | if (!m_logicalAddresses.IsEmpty() && m_busDevices[m_logicalAddresses.primary]) |
ab27363d | 609 | return m_busDevices[m_logicalAddresses.primary]->TransmitInactiveSource(); |
cc60ab1c | 610 | return false; |
abbca718 LOK |
611 | } |
612 | ||
9dee1670 | 613 | void CCECProcessor::LogOutput(const cec_command &data) |
abbca718 | 614 | { |
1d3ca3de | 615 | CStdString strTx; |
57f45e6c LOK |
616 | strTx.Format("<< %02x", ((uint8_t)data.initiator << 4) + (uint8_t)data.destination); |
617 | if (data.opcode_set) | |
618 | strTx.AppendFormat(":%02x", (uint8_t)data.opcode); | |
9dee1670 | 619 | |
06a1f7ce | 620 | for (uint8_t iPtr = 0; iPtr < data.parameters.size; iPtr++) |
1d3ca3de | 621 | strTx.AppendFormat(":%02x", data.parameters[iPtr]); |
5477a250 | 622 | CLibCEC::AddLog(CEC_LOG_TRAFFIC, strTx.c_str()); |
9dee1670 | 623 | } |
2abe74eb | 624 | |
06bfd4d7 | 625 | bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress) |
abbca718 | 626 | { |
f00ff009 | 627 | CLockObject lock(m_mutex); |
f8513317 | 628 | if (m_logicalAddresses.primary != iLogicalAddress) |
06775107 | 629 | { |
5477a250 | 630 | CLibCEC::AddLog(CEC_LOG_NOTICE, "<< setting primary logical address to %1x", iLogicalAddress); |
f8513317 | 631 | m_logicalAddresses.primary = iLogicalAddress; |
ab1469a0 LOK |
632 | m_logicalAddresses.Set(iLogicalAddress); |
633 | return SetAckMask(m_logicalAddresses.AckMask()); | |
06775107 | 634 | } |
2abe74eb | 635 | |
06bfd4d7 | 636 | return true; |
abbca718 | 637 | } |
825ddb96 | 638 | |
28fa6c97 LOK |
639 | bool CCECProcessor::SetMenuState(cec_menu_state state, bool bSendUpdate /* = true */) |
640 | { | |
641 | for (uint8_t iPtr = 0; iPtr < 16; iPtr++) | |
642 | { | |
643 | if (m_logicalAddresses[iPtr]) | |
644 | m_busDevices[iPtr]->SetMenuState(state); | |
645 | } | |
646 | ||
647 | if (bSendUpdate) | |
648 | m_busDevices[m_logicalAddresses.primary]->TransmitMenuState(CECDEVICE_TV); | |
649 | ||
650 | return true; | |
651 | } | |
652 | ||
bebb19dc | 653 | bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress, bool bSendUpdate /* = true */) |
2492216a | 654 | { |
f070564b LOK |
655 | bool bSendActiveView(false); |
656 | bool bReturn(false); | |
4d6f5ac7 | 657 | cec_logical_addresses sendUpdatesTo; |
ded7e7ce | 658 | sendUpdatesTo.Clear(); |
ff684fef | 659 | |
f070564b | 660 | { |
f00ff009 | 661 | CLockObject lock(m_mutex); |
30b4aac0 | 662 | m_configuration.iPhysicalAddress = iPhysicalAddress; |
4f362964 | 663 | |
f070564b LOK |
664 | if (!m_logicalAddresses.IsEmpty()) |
665 | { | |
666 | bool bWasActiveSource(false); | |
667 | for (uint8_t iPtr = 0; iPtr < 15; iPtr++) | |
668 | if (m_logicalAddresses[iPtr]) | |
669 | { | |
670 | bWasActiveSource |= m_busDevices[iPtr]->IsActiveSource(); | |
671 | m_busDevices[iPtr]->SetInactiveSource(); | |
672 | m_busDevices[iPtr]->SetPhysicalAddress(iPhysicalAddress); | |
673 | if (bSendUpdate) | |
4d6f5ac7 | 674 | sendUpdatesTo.Set((cec_logical_address)iPtr); |
f070564b LOK |
675 | } |
676 | ||
677 | bSendActiveView = bWasActiveSource && bSendUpdate; | |
678 | bReturn = true; | |
679 | } | |
cc60ab1c | 680 | } |
f070564b | 681 | |
4d6f5ac7 LOK |
682 | for (uint8_t iPtr = 0; iPtr < 15; iPtr++) |
683 | if (sendUpdatesTo[iPtr]) | |
684 | m_busDevices[iPtr]->TransmitPhysicalAddress(); | |
685 | ||
f070564b LOK |
686 | if (bSendActiveView) |
687 | SetActiveView(); | |
688 | ||
32403cc3 LOK |
689 | if (bReturn) |
690 | CLibCEC::ConfigurationChanged(m_configuration); | |
691 | ||
f070564b | 692 | return bReturn; |
1969b140 LOK |
693 | } |
694 | ||
8b7e5ff6 LOK |
695 | bool CCECProcessor::SwitchMonitoring(bool bEnable) |
696 | { | |
5477a250 | 697 | CLibCEC::AddLog(CEC_LOG_NOTICE, "== %s monitoring mode ==", bEnable ? "enabling" : "disabling"); |
8b7e5ff6 | 698 | |
855a3a98 | 699 | { |
f00ff009 | 700 | CLockObject lock(m_mutex); |
855a3a98 | 701 | m_bMonitor = bEnable; |
855a3a98 LOK |
702 | } |
703 | ||
8b7e5ff6 | 704 | if (bEnable) |
06bfd4d7 | 705 | return SetAckMask(0); |
8b7e5ff6 | 706 | else |
ab1469a0 | 707 | return SetAckMask(m_logicalAddresses.AckMask()); |
8b7e5ff6 LOK |
708 | } |
709 | ||
57f45e6c LOK |
710 | bool CCECProcessor::PollDevice(cec_logical_address iAddress) |
711 | { | |
712 | if (iAddress != CECDEVICE_UNKNOWN && m_busDevices[iAddress]) | |
95a73fa7 LOK |
713 | { |
714 | return m_logicalAddresses.primary == CECDEVICE_UNKNOWN ? | |
715 | m_busDevices[iAddress]->TransmitPoll(iAddress) : | |
716 | m_busDevices[m_logicalAddresses.primary]->TransmitPoll(iAddress); | |
717 | } | |
57f45e6c LOK |
718 | return false; |
719 | } | |
720 | ||
5c73f7f7 | 721 | uint8_t CCECProcessor::VolumeUp(bool bSendRelease /* = true */) |
04e637f9 LOK |
722 | { |
723 | uint8_t status = 0; | |
37b0c572 | 724 | if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM)) |
5c73f7f7 | 725 | status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeUp(bSendRelease); |
04e637f9 LOK |
726 | |
727 | return status; | |
728 | } | |
729 | ||
5c73f7f7 | 730 | uint8_t CCECProcessor::VolumeDown(bool bSendRelease /* = true */) |
04e637f9 LOK |
731 | { |
732 | uint8_t status = 0; | |
37b0c572 | 733 | if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM)) |
5c73f7f7 | 734 | status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeDown(bSendRelease); |
04e637f9 LOK |
735 | |
736 | return status; | |
737 | } | |
738 | ||
5c73f7f7 | 739 | uint8_t CCECProcessor::MuteAudio(bool bSendRelease /* = true */) |
04e637f9 LOK |
740 | { |
741 | uint8_t status = 0; | |
37b0c572 | 742 | if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM)) |
5c73f7f7 | 743 | status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->MuteAudio(bSendRelease); |
04e637f9 LOK |
744 | |
745 | return status; | |
746 | } | |
747 | ||
16b1e052 | 748 | CCECBusDevice *CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress, bool bRefresh /* = false */) const |
8ac9c610 | 749 | { |
16b1e052 | 750 | if (m_busDevices[m_logicalAddresses.primary]->GetPhysicalAddress(false) == iPhysicalAddress) |
b58d9277 | 751 | return m_busDevices[m_logicalAddresses.primary]; |
8ac9c610 | 752 | |
b58d9277 | 753 | CCECBusDevice *device = NULL; |
8ac9c610 LOK |
754 | for (unsigned int iPtr = 0; iPtr < 16; iPtr++) |
755 | { | |
16b1e052 | 756 | if (m_busDevices[iPtr]->GetPhysicalAddress(bRefresh) == iPhysicalAddress) |
8ac9c610 LOK |
757 | { |
758 | device = m_busDevices[iPtr]; | |
759 | break; | |
760 | } | |
761 | } | |
762 | ||
763 | return device; | |
764 | } | |
765 | ||
a9232a79 LOK |
766 | CCECBusDevice *CCECProcessor::GetDeviceByType(cec_device_type type) const |
767 | { | |
768 | CCECBusDevice *device = NULL; | |
769 | ||
7619faad | 770 | for (uint8_t iPtr = 0; iPtr < 16; iPtr++) |
a9232a79 | 771 | { |
b64db02e | 772 | if (m_busDevices[iPtr]->m_type == type && m_logicalAddresses[iPtr]) |
a9232a79 LOK |
773 | { |
774 | device = m_busDevices[iPtr]; | |
775 | break; | |
776 | } | |
777 | } | |
778 | ||
779 | return device; | |
780 | } | |
781 | ||
842262d8 LOK |
782 | CCECBusDevice *CCECProcessor::GetPrimaryDevice(void) const |
783 | { | |
784 | CCECBusDevice *device(NULL); | |
785 | cec_logical_address primary = m_logicalAddresses.primary; | |
786 | if (primary != CECDEVICE_UNKNOWN) | |
787 | device = m_busDevices[primary]; | |
788 | return device; | |
789 | } | |
790 | ||
6a1c0009 LOK |
791 | cec_version CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress) |
792 | { | |
793 | return m_busDevices[iAddress]->GetCecVersion(); | |
794 | } | |
795 | ||
ed21be2a LOK |
796 | cec_osd_name CCECProcessor::GetDeviceOSDName(cec_logical_address iAddress) |
797 | { | |
798 | CStdString strOSDName = m_busDevices[iAddress]->GetOSDName(); | |
799 | cec_osd_name retVal; | |
800 | ||
801 | snprintf(retVal.name, sizeof(retVal.name), "%s", strOSDName.c_str()); | |
802 | retVal.device = iAddress; | |
803 | ||
804 | return retVal; | |
805 | } | |
806 | ||
a3269a0a LOK |
807 | bool CCECProcessor::GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language) |
808 | { | |
cc60ab1c LOK |
809 | if (m_busDevices[iAddress]) |
810 | { | |
811 | *language = m_busDevices[iAddress]->GetMenuLanguage(); | |
5744fbba | 812 | return (strcmp(language->language, "???") != 0); |
cc60ab1c LOK |
813 | } |
814 | return false; | |
a3269a0a LOK |
815 | } |
816 | ||
44c74256 LOK |
817 | uint64_t CCECProcessor::GetDeviceVendorId(cec_logical_address iAddress) |
818 | { | |
cc60ab1c LOK |
819 | if (m_busDevices[iAddress]) |
820 | return m_busDevices[iAddress]->GetVendorId(); | |
821 | return false; | |
44c74256 LOK |
822 | } |
823 | ||
eab72c40 LOK |
824 | uint16_t CCECProcessor::GetDevicePhysicalAddress(cec_logical_address iAddress) |
825 | { | |
826 | if (m_busDevices[iAddress]) | |
827 | return m_busDevices[iAddress]->GetPhysicalAddress(false); | |
828 | return false; | |
829 | } | |
830 | ||
e55f3f70 LOK |
831 | cec_power_status CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddress) |
832 | { | |
cc60ab1c LOK |
833 | if (m_busDevices[iAddress]) |
834 | return m_busDevices[iAddress]->GetPowerStatus(); | |
835 | return CEC_POWER_STATUS_UNKNOWN; | |
e55f3f70 LOK |
836 | } |
837 | ||
b4b1b49b LOK |
838 | cec_logical_address CCECProcessor::GetActiveSource(void) |
839 | { | |
840 | for (uint8_t iPtr = 0; iPtr <= 11; iPtr++) | |
841 | { | |
842 | if (m_busDevices[iPtr]->IsActiveSource()) | |
843 | return (cec_logical_address)iPtr; | |
844 | } | |
845 | ||
846 | return CECDEVICE_UNKNOWN; | |
847 | } | |
848 | ||
849 | bool CCECProcessor::IsActiveSource(cec_logical_address iAddress) | |
850 | { | |
851 | return m_busDevices[iAddress]->IsActiveSource(); | |
852 | } | |
853 | ||
8d84e2c0 | 854 | bool CCECProcessor::Transmit(const cec_command &data) |
825ddb96 | 855 | { |
c4287bcd LOK |
856 | if (m_logicalAddresses[(uint8_t)data.destination]) |
857 | { | |
858 | CLibCEC::AddLog(CEC_LOG_WARNING, "not sending data to myself!"); | |
859 | return false; | |
860 | } | |
861 | ||
7bb4ed43 | 862 | cec_adapter_message_state retVal(ADAPTER_MESSAGE_STATE_UNKNOWN); |
eb35e4ca | 863 | { |
7bb4ed43 LOK |
864 | CLockObject lock(m_mutex); |
865 | LogOutput(data); | |
5f316715 | 866 | m_iLastTransmission = GetTimeMs(); |
7bb4ed43 LOK |
867 | if (!m_communication) |
868 | return false; | |
869 | uint8_t iMaxTries = m_busDevices[data.initiator]->GetHandler()->GetTransmitRetries() + 1; | |
870 | retVal = m_communication->Write(data, iMaxTries, m_iLineTimeout, m_iRetryLineTimeout); | |
2abe74eb LOK |
871 | } |
872 | ||
7bb4ed43 LOK |
873 | /* set to "not present" on failed ack */ |
874 | if (retVal == ADAPTER_MESSAGE_STATE_SENT_NOT_ACKED && | |
875 | data.destination != CECDEVICE_BROADCAST) | |
876 | m_busDevices[data.destination]->SetDeviceStatus(CEC_DEVICE_STATUS_NOT_PRESENT); | |
9902f4e8 | 877 | |
7bb4ed43 | 878 | return retVal == ADAPTER_MESSAGE_STATE_SENT_ACKED; |
825ddb96 | 879 | } |
abbca718 | 880 | |
22b4e74a | 881 | void CCECProcessor::TransmitAbort(cec_logical_address address, cec_opcode opcode, cec_abort_reason reason /* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */) |
abbca718 | 882 | { |
5477a250 | 883 | CLibCEC::AddLog(CEC_LOG_DEBUG, "<< transmitting abort message"); |
9dee1670 | 884 | |
06a1f7ce | 885 | cec_command command; |
f8513317 | 886 | // TODO |
ab1469a0 LOK |
887 | cec_command::Format(command, m_logicalAddresses.primary, address, CEC_OPCODE_FEATURE_ABORT); |
888 | command.parameters.PushBack((uint8_t)opcode); | |
889 | command.parameters.PushBack((uint8_t)reason); | |
9dee1670 LOK |
890 | |
891 | Transmit(command); | |
abbca718 LOK |
892 | } |
893 | ||
b1f94db1 | 894 | void CCECProcessor::ParseCommand(const cec_command &command) |
abbca718 | 895 | { |
e9de9629 | 896 | CStdString dataStr; |
1d3ca3de | 897 | dataStr.Format(">> %1x%1x:%02x", command.initiator, command.destination, command.opcode); |
e9de9629 LOK |
898 | for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++) |
899 | dataStr.AppendFormat(":%02x", (unsigned int)command.parameters[iPtr]); | |
5477a250 | 900 | CLibCEC::AddLog(CEC_LOG_TRAFFIC, dataStr.c_str()); |
dc113aca | 901 | |
7871d66e | 902 | if (!m_bMonitor && command.initiator >= CECDEVICE_TV && command.initiator <= CECDEVICE_BROADCAST) |
e9de9629 | 903 | m_busDevices[(uint8_t)command.initiator]->HandleCommand(command); |
dc113aca LOK |
904 | } |
905 | ||
6d858ba4 LOK |
906 | cec_logical_addresses CCECProcessor::GetActiveDevices(void) |
907 | { | |
908 | cec_logical_addresses addresses; | |
988de7b9 | 909 | addresses.Clear(); |
6d858ba4 LOK |
910 | for (unsigned int iPtr = 0; iPtr < 15; iPtr++) |
911 | { | |
912 | if (m_busDevices[iPtr]->GetStatus() == CEC_DEVICE_STATUS_PRESENT) | |
913 | addresses.Set((cec_logical_address) iPtr); | |
914 | } | |
915 | return addresses; | |
916 | } | |
917 | ||
37b0c572 | 918 | bool CCECProcessor::IsPresentDevice(cec_logical_address address) |
6d858ba4 LOK |
919 | { |
920 | return m_busDevices[address]->GetStatus() == CEC_DEVICE_STATUS_PRESENT; | |
921 | } | |
922 | ||
37b0c572 | 923 | bool CCECProcessor::IsPresentDeviceType(cec_device_type type) |
6d858ba4 | 924 | { |
6d858ba4 | 925 | for (unsigned int iPtr = 0; iPtr < 15; iPtr++) |
2813bd07 LOK |
926 | { |
927 | if (m_busDevices[iPtr]->GetType() == type && m_busDevices[iPtr]->GetStatus() == CEC_DEVICE_STATUS_PRESENT) | |
6d858ba4 | 928 | return true; |
2813bd07 LOK |
929 | } |
930 | ||
6d858ba4 LOK |
931 | return false; |
932 | } | |
933 | ||
0f23c85c LOK |
934 | uint16_t CCECProcessor::GetPhysicalAddress(void) const |
935 | { | |
ab1469a0 | 936 | if (!m_logicalAddresses.IsEmpty() && m_busDevices[m_logicalAddresses.primary]) |
16b1e052 | 937 | return m_busDevices[m_logicalAddresses.primary]->GetPhysicalAddress(false); |
cc60ab1c | 938 | return false; |
0f23c85c LOK |
939 | } |
940 | ||
06bfd4d7 LOK |
941 | bool CCECProcessor::SetAckMask(uint16_t iMask) |
942 | { | |
5dcf9f25 | 943 | return m_communication->SetAckMask(iMask); |
06bfd4d7 | 944 | } |
a33794d8 | 945 | |
4bec9d79 | 946 | bool CCECProcessor::TransmitKeypress(cec_logical_address iDestination, cec_user_control_code key, bool bWait /* = true */) |
a33794d8 | 947 | { |
86869f8f | 948 | return m_busDevices[iDestination]->TransmitKeypress(key, bWait); |
a33794d8 LOK |
949 | } |
950 | ||
4bec9d79 | 951 | bool CCECProcessor::TransmitKeyRelease(cec_logical_address iDestination, bool bWait /* = true */) |
a33794d8 | 952 | { |
86869f8f | 953 | return m_busDevices[iDestination]->TransmitKeyRelease(bWait); |
a33794d8 | 954 | } |
7c63a480 | 955 | |
ca27e6cf LOK |
956 | bool CCECProcessor::StandbyDevices(cec_logical_address address /* = CECDEVICE_BROADCAST */) |
957 | { | |
958 | if (address == CECDEVICE_BROADCAST && m_configuration.clientVersion >= CEC_CLIENT_VERSION_1_5_0) | |
959 | { | |
960 | bool bReturn(true); | |
961 | for (uint8_t iPtr = 0; iPtr <= 0xF; iPtr++) | |
962 | { | |
963 | if (m_configuration.powerOffDevices[iPtr]) | |
964 | bReturn &= m_busDevices[iPtr]->Standby(); | |
965 | } | |
966 | return bReturn; | |
967 | } | |
968 | ||
969 | return m_busDevices[address]->Standby(); | |
970 | } | |
971 | ||
972 | bool CCECProcessor::PowerOnDevices(cec_logical_address address /* = CECDEVICE_BROADCAST */) | |
973 | { | |
974 | if (address == CECDEVICE_BROADCAST && m_configuration.clientVersion >= CEC_CLIENT_VERSION_1_5_0) | |
975 | { | |
976 | bool bReturn(true); | |
977 | for (uint8_t iPtr = 0; iPtr <= 0xF; iPtr++) | |
978 | { | |
979 | if (m_configuration.powerOffDevices[iPtr]) | |
980 | bReturn &= m_busDevices[iPtr]->PowerOn(); | |
981 | } | |
982 | return bReturn; | |
983 | } | |
984 | ||
985 | return m_busDevices[address]->PowerOn(); | |
986 | } | |
987 | ||
3e61b350 LOK |
988 | const char *CCECProcessor::ToString(const cec_device_type type) |
989 | { | |
990 | switch (type) | |
991 | { | |
992 | case CEC_DEVICE_TYPE_AUDIO_SYSTEM: | |
993 | return "audio system"; | |
994 | case CEC_DEVICE_TYPE_PLAYBACK_DEVICE: | |
995 | return "playback device"; | |
996 | case CEC_DEVICE_TYPE_RECORDING_DEVICE: | |
997 | return "recording device"; | |
998 | case CEC_DEVICE_TYPE_RESERVED: | |
999 | return "reserved"; | |
1000 | case CEC_DEVICE_TYPE_TUNER: | |
1001 | return "tuner"; | |
1002 | case CEC_DEVICE_TYPE_TV: | |
1003 | return "TV"; | |
1004 | default: | |
1005 | return "unknown"; | |
1006 | } | |
1007 | } | |
1008 | ||
03ae897d LOK |
1009 | const char *CCECProcessor::ToString(const cec_menu_state state) |
1010 | { | |
1011 | switch (state) | |
1012 | { | |
1013 | case CEC_MENU_STATE_ACTIVATED: | |
1014 | return "activated"; | |
1015 | case CEC_MENU_STATE_DEACTIVATED: | |
1016 | return "deactivated"; | |
1017 | default: | |
1018 | return "unknown"; | |
1019 | } | |
1020 | } | |
1021 | ||
1022 | const char *CCECProcessor::ToString(const cec_version version) | |
1023 | { | |
1024 | switch (version) | |
1025 | { | |
1026 | case CEC_VERSION_1_2: | |
1027 | return "1.2"; | |
1028 | case CEC_VERSION_1_2A: | |
1029 | return "1.2a"; | |
1030 | case CEC_VERSION_1_3: | |
1031 | return "1.3"; | |
1032 | case CEC_VERSION_1_3A: | |
1033 | return "1.3a"; | |
1034 | case CEC_VERSION_1_4: | |
1035 | return "1.4"; | |
1036 | default: | |
1037 | return "unknown"; | |
1038 | } | |
1039 | } | |
1040 | ||
1041 | const char *CCECProcessor::ToString(const cec_power_status status) | |
1042 | { | |
1043 | switch (status) | |
1044 | { | |
1045 | case CEC_POWER_STATUS_ON: | |
1046 | return "on"; | |
1047 | case CEC_POWER_STATUS_STANDBY: | |
1048 | return "standby"; | |
1049 | case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY: | |
1050 | return "in transition from on to standby"; | |
1051 | case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON: | |
1052 | return "in transition from standby to on"; | |
1053 | default: | |
1054 | return "unknown"; | |
1055 | } | |
1056 | } | |
1057 | ||
1058 | const char *CCECProcessor::ToString(const cec_logical_address address) | |
1059 | { | |
1060 | switch(address) | |
1061 | { | |
1062 | case CECDEVICE_AUDIOSYSTEM: | |
1063 | return "Audio"; | |
1064 | case CECDEVICE_BROADCAST: | |
1065 | return "Broadcast"; | |
1066 | case CECDEVICE_FREEUSE: | |
1067 | return "Free use"; | |
1068 | case CECDEVICE_PLAYBACKDEVICE1: | |
1069 | return "Playback 1"; | |
1070 | case CECDEVICE_PLAYBACKDEVICE2: | |
1071 | return "Playback 2"; | |
1072 | case CECDEVICE_PLAYBACKDEVICE3: | |
1073 | return "Playback 3"; | |
1074 | case CECDEVICE_RECORDINGDEVICE1: | |
1075 | return "Recorder 1"; | |
1076 | case CECDEVICE_RECORDINGDEVICE2: | |
1077 | return "Recorder 2"; | |
1078 | case CECDEVICE_RECORDINGDEVICE3: | |
1079 | return "Recorder 3"; | |
1080 | case CECDEVICE_RESERVED1: | |
1081 | return "Reserved 1"; | |
1082 | case CECDEVICE_RESERVED2: | |
1083 | return "Reserved 2"; | |
1084 | case CECDEVICE_TUNER1: | |
1085 | return "Tuner 1"; | |
1086 | case CECDEVICE_TUNER2: | |
1087 | return "Tuner 2"; | |
1088 | case CECDEVICE_TUNER3: | |
1089 | return "Tuner 3"; | |
1090 | case CECDEVICE_TUNER4: | |
1091 | return "Tuner 4"; | |
1092 | case CECDEVICE_TV: | |
1093 | return "TV"; | |
1094 | default: | |
1095 | return "unknown"; | |
1096 | } | |
1097 | } | |
1098 | ||
1099 | const char *CCECProcessor::ToString(const cec_deck_control_mode mode) | |
1100 | { | |
1101 | switch (mode) | |
1102 | { | |
1103 | case CEC_DECK_CONTROL_MODE_SKIP_FORWARD_WIND: | |
1104 | return "skip forward wind"; | |
1105 | case CEC_DECK_CONTROL_MODE_EJECT: | |
1106 | return "eject"; | |
1107 | case CEC_DECK_CONTROL_MODE_SKIP_REVERSE_REWIND: | |
1108 | return "reverse rewind"; | |
1109 | case CEC_DECK_CONTROL_MODE_STOP: | |
1110 | return "stop"; | |
1111 | default: | |
1112 | return "unknown"; | |
1113 | } | |
1114 | } | |
1115 | ||
1116 | const char *CCECProcessor::ToString(const cec_deck_info status) | |
1117 | { | |
1118 | switch (status) | |
1119 | { | |
1120 | case CEC_DECK_INFO_PLAY: | |
1121 | return "play"; | |
1122 | case CEC_DECK_INFO_RECORD: | |
1123 | return "record"; | |
1124 | case CEC_DECK_INFO_PLAY_REVERSE: | |
1125 | return "play reverse"; | |
1126 | case CEC_DECK_INFO_STILL: | |
1127 | return "still"; | |
1128 | case CEC_DECK_INFO_SLOW: | |
1129 | return "slow"; | |
1130 | case CEC_DECK_INFO_SLOW_REVERSE: | |
1131 | return "slow reverse"; | |
1132 | case CEC_DECK_INFO_FAST_FORWARD: | |
1133 | return "fast forward"; | |
1134 | case CEC_DECK_INFO_FAST_REVERSE: | |
1135 | return "fast reverse"; | |
1136 | case CEC_DECK_INFO_NO_MEDIA: | |
1137 | return "no media"; | |
1138 | case CEC_DECK_INFO_STOP: | |
1139 | return "stop"; | |
1140 | case CEC_DECK_INFO_SKIP_FORWARD_WIND: | |
1141 | return "info skip forward wind"; | |
1142 | case CEC_DECK_INFO_SKIP_REVERSE_REWIND: | |
1143 | return "info skip reverse rewind"; | |
1144 | case CEC_DECK_INFO_INDEX_SEARCH_FORWARD: | |
1145 | return "info index search forward"; | |
1146 | case CEC_DECK_INFO_INDEX_SEARCH_REVERSE: | |
1147 | return "info index search reverse"; | |
1148 | case CEC_DECK_INFO_OTHER_STATUS: | |
1149 | return "other"; | |
1150 | default: | |
1151 | return "unknown"; | |
1152 | } | |
1153 | } | |
1154 | ||
1155 | const char *CCECProcessor::ToString(const cec_opcode opcode) | |
1156 | { | |
1157 | switch (opcode) | |
1158 | { | |
1159 | case CEC_OPCODE_ACTIVE_SOURCE: | |
1160 | return "active source"; | |
1161 | case CEC_OPCODE_IMAGE_VIEW_ON: | |
1162 | return "image view on"; | |
1163 | case CEC_OPCODE_TEXT_VIEW_ON: | |
1164 | return "text view on"; | |
1165 | case CEC_OPCODE_INACTIVE_SOURCE: | |
1166 | return "inactive source"; | |
1167 | case CEC_OPCODE_REQUEST_ACTIVE_SOURCE: | |
1168 | return "request active source"; | |
1169 | case CEC_OPCODE_ROUTING_CHANGE: | |
1170 | return "routing change"; | |
1171 | case CEC_OPCODE_ROUTING_INFORMATION: | |
1172 | return "routing information"; | |
1173 | case CEC_OPCODE_SET_STREAM_PATH: | |
1174 | return "set stream path"; | |
1175 | case CEC_OPCODE_STANDBY: | |
1176 | return "standby"; | |
1177 | case CEC_OPCODE_RECORD_OFF: | |
1178 | return "record off"; | |
1179 | case CEC_OPCODE_RECORD_ON: | |
1180 | return "record on"; | |
1181 | case CEC_OPCODE_RECORD_STATUS: | |
1182 | return "record status"; | |
1183 | case CEC_OPCODE_RECORD_TV_SCREEN: | |
1184 | return "record tv screen"; | |
1185 | case CEC_OPCODE_CLEAR_ANALOGUE_TIMER: | |
1186 | return "clear analogue timer"; | |
1187 | case CEC_OPCODE_CLEAR_DIGITAL_TIMER: | |
1188 | return "clear digital timer"; | |
1189 | case CEC_OPCODE_CLEAR_EXTERNAL_TIMER: | |
1190 | return "clear external timer"; | |
1191 | case CEC_OPCODE_SET_ANALOGUE_TIMER: | |
1192 | return "set analogue timer"; | |
1193 | case CEC_OPCODE_SET_DIGITAL_TIMER: | |
1194 | return "set digital timer"; | |
1195 | case CEC_OPCODE_SET_EXTERNAL_TIMER: | |
1196 | return "set external timer"; | |
1197 | case CEC_OPCODE_SET_TIMER_PROGRAM_TITLE: | |
1198 | return "set timer program title"; | |
1199 | case CEC_OPCODE_TIMER_CLEARED_STATUS: | |
1200 | return "timer cleared status"; | |
1201 | case CEC_OPCODE_TIMER_STATUS: | |
1202 | return "timer status"; | |
1203 | case CEC_OPCODE_CEC_VERSION: | |
1204 | return "cec version"; | |
1205 | case CEC_OPCODE_GET_CEC_VERSION: | |
1206 | return "get cec version"; | |
1207 | case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS: | |
1208 | return "give physical address"; | |
1209 | case CEC_OPCODE_GET_MENU_LANGUAGE: | |
1210 | return "get menu language"; | |
1211 | case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS: | |
1212 | return "report physical address"; | |
1213 | case CEC_OPCODE_SET_MENU_LANGUAGE: | |
1214 | return "set menu language"; | |
1215 | case CEC_OPCODE_DECK_CONTROL: | |
1216 | return "deck control"; | |
1217 | case CEC_OPCODE_DECK_STATUS: | |
1218 | return "deck status"; | |
1219 | case CEC_OPCODE_GIVE_DECK_STATUS: | |
1220 | return "give deck status"; | |
1221 | case CEC_OPCODE_PLAY: | |
1222 | return "play"; | |
1223 | case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS: | |
1224 | return "give tuner status"; | |
1225 | case CEC_OPCODE_SELECT_ANALOGUE_SERVICE: | |
1226 | return "select analogue service"; | |
1227 | case CEC_OPCODE_SELECT_DIGITAL_SERVICE: | |
1228 | return "set digital service"; | |
1229 | case CEC_OPCODE_TUNER_DEVICE_STATUS: | |
1230 | return "tuner device status"; | |
1231 | case CEC_OPCODE_TUNER_STEP_DECREMENT: | |
1232 | return "tuner step decrement"; | |
1233 | case CEC_OPCODE_TUNER_STEP_INCREMENT: | |
1234 | return "tuner step increment"; | |
1235 | case CEC_OPCODE_DEVICE_VENDOR_ID: | |
1236 | return "device vendor id"; | |
1237 | case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID: | |
1238 | return "give device vendor id"; | |
1239 | case CEC_OPCODE_VENDOR_COMMAND: | |
1240 | return "vendor command"; | |
1241 | case CEC_OPCODE_VENDOR_COMMAND_WITH_ID: | |
1242 | return "vendor command with id"; | |
1243 | case CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN: | |
1244 | return "vendor remote button down"; | |
1245 | case CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP: | |
1246 | return "vendor remote button up"; | |
1247 | case CEC_OPCODE_SET_OSD_STRING: | |
1248 | return "set osd string"; | |
1249 | case CEC_OPCODE_GIVE_OSD_NAME: | |
1250 | return "give osd name"; | |
1251 | case CEC_OPCODE_SET_OSD_NAME: | |
1252 | return "set osd name"; | |
1253 | case CEC_OPCODE_MENU_REQUEST: | |
1254 | return "menu request"; | |
1255 | case CEC_OPCODE_MENU_STATUS: | |
1256 | return "menu status"; | |
1257 | case CEC_OPCODE_USER_CONTROL_PRESSED: | |
1258 | return "user control pressed"; | |
1259 | case CEC_OPCODE_USER_CONTROL_RELEASE: | |
1260 | return "user control release"; | |
1261 | case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS: | |
1262 | return "give device power status"; | |
1263 | case CEC_OPCODE_REPORT_POWER_STATUS: | |
1264 | return "report power status"; | |
1265 | case CEC_OPCODE_FEATURE_ABORT: | |
1266 | return "feature abort"; | |
1267 | case CEC_OPCODE_ABORT: | |
1268 | return "abort"; | |
1269 | case CEC_OPCODE_GIVE_AUDIO_STATUS: | |
1270 | return "give audio status"; | |
1271 | case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS: | |
1272 | return "give audio mode status"; | |
1273 | case CEC_OPCODE_REPORT_AUDIO_STATUS: | |
1274 | return "report audio status"; | |
1275 | case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE: | |
1276 | return "set system audio mode"; | |
1277 | case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST: | |
1278 | return "system audio mode request"; | |
1279 | case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS: | |
1280 | return "system audio mode status"; | |
1281 | case CEC_OPCODE_SET_AUDIO_RATE: | |
1282 | return "set audio rate"; | |
1283 | default: | |
1284 | return "UNKNOWN"; | |
1285 | } | |
1286 | } | |
1287 | ||
1288 | const char *CCECProcessor::ToString(const cec_system_audio_status mode) | |
1289 | { | |
1290 | switch(mode) | |
1291 | { | |
1292 | case CEC_SYSTEM_AUDIO_STATUS_ON: | |
1293 | return "on"; | |
1294 | case CEC_SYSTEM_AUDIO_STATUS_OFF: | |
1295 | return "off"; | |
1296 | default: | |
1297 | return "unknown"; | |
1298 | } | |
1299 | } | |
1300 | ||
1de6617c | 1301 | const char *CCECProcessor::ToString(const cec_audio_status UNUSED(status)) |
03ae897d LOK |
1302 | { |
1303 | // TODO this is a mask | |
1304 | return "TODO"; | |
1305 | } | |
1306 | ||
1307 | const char *CCECProcessor::ToString(const cec_vendor_id vendor) | |
1308 | { | |
1309 | switch (vendor) | |
1310 | { | |
1311 | case CEC_VENDOR_SAMSUNG: | |
1312 | return "Samsung"; | |
1313 | case CEC_VENDOR_LG: | |
1314 | return "LG"; | |
1315 | case CEC_VENDOR_PANASONIC: | |
1316 | return "Panasonic"; | |
1317 | case CEC_VENDOR_PIONEER: | |
1318 | return "Pioneer"; | |
1319 | case CEC_VENDOR_ONKYO: | |
1320 | return "Onkyo"; | |
1321 | case CEC_VENDOR_YAMAHA: | |
1322 | return "Yamaha"; | |
ec0deac1 LOK |
1323 | case CEC_VENDOR_PHILIPS: |
1324 | return "Philips"; | |
1a87cacc LOK |
1325 | case CEC_VENDOR_SONY: |
1326 | return "Sony"; | |
03ae897d LOK |
1327 | default: |
1328 | return "Unknown"; | |
1329 | } | |
1330 | } | |
1331 | ||
caca2d81 LOK |
1332 | const char *CCECProcessor::ToString(const cec_client_version version) |
1333 | { | |
1334 | switch (version) | |
1335 | { | |
1336 | case CEC_CLIENT_VERSION_PRE_1_5: | |
1337 | return "pre-1.5"; | |
1338 | case CEC_CLIENT_VERSION_1_5_0: | |
1339 | return "1.5.0"; | |
1340 | default: | |
1341 | return "Unknown"; | |
1342 | } | |
1343 | } | |
1344 | ||
7c63a480 LOK |
1345 | void *CCECBusScan::Process(void) |
1346 | { | |
1347 | CCECBusDevice *device(NULL); | |
fe6f8e37 | 1348 | uint8_t iCounter(0); |
5f316715 | 1349 | |
5e5637c6 | 1350 | while (!IsStopped()) |
7c63a480 | 1351 | { |
bdb0f7f4 | 1352 | if (++iCounter < 10) |
fe6f8e37 LOK |
1353 | { |
1354 | Sleep(1000); | |
1355 | continue; | |
1356 | } | |
5f316715 | 1357 | for (unsigned int iPtr = 0; iPtr <= 11 && !IsStopped(); iPtr++) |
7c63a480 | 1358 | { |
5f316715 LOK |
1359 | device = m_processor->m_busDevices[iPtr]; |
1360 | WaitUntilIdle(); | |
1361 | if (device && device->GetStatus(true) == CEC_DEVICE_STATUS_PRESENT) | |
5e5637c6 | 1362 | { |
5f316715 LOK |
1363 | WaitUntilIdle(); |
1364 | if (!IsStopped()) | |
1365 | device->GetVendorId(); | |
1366 | ||
1367 | WaitUntilIdle(); | |
1368 | if (!IsStopped()) | |
1369 | device->GetPowerStatus(true); | |
5e5637c6 | 1370 | } |
7c63a480 LOK |
1371 | } |
1372 | } | |
5f316715 | 1373 | |
7c63a480 LOK |
1374 | return NULL; |
1375 | } | |
1113cb7d | 1376 | |
5f316715 LOK |
1377 | void CCECBusScan::WaitUntilIdle(void) |
1378 | { | |
1379 | if (IsStopped()) | |
1380 | return; | |
1381 | ||
701f753b | 1382 | int32_t iWaitTime = 3000 - (int32_t)(GetTimeMs() - m_processor->GetLastTransmission()); |
5f316715 LOK |
1383 | while (iWaitTime > 0) |
1384 | { | |
1385 | Sleep(iWaitTime); | |
701f753b | 1386 | iWaitTime = 3000 - (int32_t)(GetTimeMs() - m_processor->GetLastTransmission()); |
5f316715 LOK |
1387 | } |
1388 | } | |
1389 | ||
1113cb7d LOK |
1390 | bool CCECProcessor::StartBootloader(void) |
1391 | { | |
1392 | return m_communication->StartBootloader(); | |
1393 | } | |
1394 | ||
1395 | bool CCECProcessor::PingAdapter(void) | |
1396 | { | |
1397 | return m_communication->PingAdapter(); | |
1398 | } | |
6729ac71 LOK |
1399 | |
1400 | void CCECProcessor::HandlePoll(cec_logical_address initiator, cec_logical_address destination) | |
1401 | { | |
0cfdeb5a | 1402 | m_busDevices[initiator]->HandlePoll(destination); |
6729ac71 LOK |
1403 | } |
1404 | ||
7bb4ed43 | 1405 | bool CCECProcessor::HandleReceiveFailed(cec_logical_address initiator) |
6729ac71 | 1406 | { |
0cfdeb5a | 1407 | return !m_busDevices[initiator]->HandleReceiveFailed(); |
6729ac71 | 1408 | } |
f42d3e0f LOK |
1409 | |
1410 | bool CCECProcessor::SetStreamPath(uint16_t iPhysicalAddress) | |
1411 | { | |
1412 | // stream path changes are sent by the TV | |
1413 | return m_busDevices[CECDEVICE_TV]->GetHandler()->TransmitSetStreamPath(iPhysicalAddress); | |
1414 | } | |
d40928b5 | 1415 | |
30b4aac0 LOK |
1416 | bool CCECProcessor::SetConfiguration(const libcec_configuration *configuration) |
1417 | { | |
f0154449 LOK |
1418 | bool bReinit(false); |
1419 | bool bPhysicalAddressChanged(false); | |
1420 | bool bHdmiPortChanged(false); | |
1421 | bool bDeviceTypeChanged(false); | |
30b4aac0 | 1422 | CCECBusDevice *primary = IsRunning() ? GetPrimaryDevice() : NULL; |
f0154449 LOK |
1423 | cec_device_type oldPrimaryType = primary ? primary->GetType() : CEC_DEVICE_TYPE_RECORDING_DEVICE; |
1424 | m_configuration.clientVersion = configuration->clientVersion; | |
30b4aac0 LOK |
1425 | |
1426 | // client version 1.5.0 | |
1427 | ||
1428 | // device types | |
f0154449 | 1429 | bDeviceTypeChanged |= IsRunning () && m_configuration.deviceTypes != configuration->deviceTypes; |
30b4aac0 LOK |
1430 | m_configuration.deviceTypes = configuration->deviceTypes; |
1431 | ||
1432 | // physical address | |
f0154449 | 1433 | bPhysicalAddressChanged |= IsRunning() && m_configuration.iPhysicalAddress != configuration->iPhysicalAddress; |
30b4aac0 LOK |
1434 | m_configuration.iPhysicalAddress = configuration->iPhysicalAddress; |
1435 | ||
1436 | // base device | |
f0154449 | 1437 | bHdmiPortChanged |= IsRunning() && m_configuration.baseDevice != configuration->baseDevice; |
30b4aac0 LOK |
1438 | m_configuration.baseDevice = configuration->baseDevice; |
1439 | ||
1440 | // hdmi port | |
f0154449 | 1441 | bHdmiPortChanged |= IsRunning() && m_configuration.iHDMIPort != configuration->iHDMIPort; |
30b4aac0 LOK |
1442 | m_configuration.iHDMIPort = configuration->iHDMIPort; |
1443 | ||
f0154449 LOK |
1444 | bReinit = bPhysicalAddressChanged || bHdmiPortChanged || bDeviceTypeChanged; |
1445 | ||
30b4aac0 LOK |
1446 | // device name |
1447 | snprintf(m_configuration.strDeviceName, 13, "%s", configuration->strDeviceName); | |
1448 | if (primary && !primary->GetOSDName().Equals(m_configuration.strDeviceName)) | |
1449 | { | |
1450 | primary->SetOSDName(m_configuration.strDeviceName); | |
f0154449 | 1451 | if (!bReinit && IsRunning()) |
30b4aac0 LOK |
1452 | primary->TransmitOSDName(CECDEVICE_TV); |
1453 | } | |
1454 | ||
1455 | // tv vendor id override | |
1456 | if (m_configuration.tvVendor != configuration->tvVendor) | |
1457 | { | |
1458 | m_configuration.tvVendor= configuration->tvVendor; | |
1459 | m_busDevices[CECDEVICE_TV]->SetVendorId((uint64_t)m_configuration.tvVendor); | |
1460 | } | |
1461 | ||
1462 | // wake CEC devices | |
1463 | if (m_configuration.wakeDevices != configuration->wakeDevices) | |
1464 | { | |
1465 | m_configuration.wakeDevices = configuration->wakeDevices; | |
f0154449 | 1466 | if (!bReinit && IsRunning()) |
ca27e6cf | 1467 | PowerOnDevices(); |
30b4aac0 LOK |
1468 | } |
1469 | ||
1470 | // just copy these | |
1471 | m_configuration.bGetSettingsFromROM = configuration->bGetSettingsFromROM; | |
ca27e6cf | 1472 | m_configuration.powerOffDevices = configuration->powerOffDevices; |
30b4aac0 LOK |
1473 | m_configuration.bPowerOffScreensaver = configuration->bPowerOffScreensaver; |
1474 | m_configuration.bPowerOffOnStandby = configuration->bPowerOffOnStandby; | |
1475 | ||
1476 | // ensure that there is at least 1 device type set | |
1477 | if (m_configuration.deviceTypes.IsEmpty()) | |
1478 | m_configuration.deviceTypes.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE); | |
1479 | ||
f0154449 | 1480 | if (bReinit) |
30b4aac0 | 1481 | { |
f0154449 LOK |
1482 | if (bDeviceTypeChanged) |
1483 | return ChangeDeviceType(oldPrimaryType, m_configuration.deviceTypes[0]); | |
1484 | else if (bPhysicalAddressChanged) | |
1485 | return SetPhysicalAddress(m_configuration.iPhysicalAddress); | |
1486 | else | |
1487 | return SetHDMIPort(m_configuration.baseDevice, m_configuration.iHDMIPort); | |
30b4aac0 LOK |
1488 | } |
1489 | ||
1490 | return true; | |
1491 | } | |
1492 | ||
d40928b5 LOK |
1493 | bool CCECProcessor::GetCurrentConfiguration(libcec_configuration *configuration) |
1494 | { | |
30b4aac0 LOK |
1495 | // client version 1.5.0 |
1496 | configuration->clientVersion = m_configuration.clientVersion; | |
1497 | snprintf(configuration->strDeviceName, 13, "%s", m_configuration.strDeviceName); | |
1498 | configuration->deviceTypes = m_configuration.deviceTypes; | |
1499 | configuration->iPhysicalAddress = m_configuration.iPhysicalAddress; | |
1500 | configuration->baseDevice = m_configuration.baseDevice; | |
1501 | configuration->iHDMIPort = m_configuration.iHDMIPort; | |
1502 | configuration->tvVendor = m_configuration.tvVendor; | |
1503 | configuration->wakeDevices = m_configuration.wakeDevices; | |
1504 | configuration->bGetSettingsFromROM = m_configuration.bGetSettingsFromROM; | |
ca27e6cf | 1505 | configuration->powerOffDevices = m_configuration.powerOffDevices; |
30b4aac0 LOK |
1506 | configuration->bPowerOffScreensaver = m_configuration.bPowerOffScreensaver; |
1507 | configuration->bPowerOffOnStandby = m_configuration.bPowerOffOnStandby; | |
1508 | ||
d40928b5 LOK |
1509 | return true; |
1510 | } | |
224ea877 LOK |
1511 | |
1512 | bool CCECProcessor::CanPersistConfiguration(void) | |
1513 | { | |
1514 | return m_communication->GetFirmwareVersion() >= 2; | |
1515 | } | |
1516 | ||
1517 | bool CCECProcessor::PersistConfiguration(libcec_configuration *configuration) | |
1518 | { | |
1519 | return m_communication->PersistConfiguration(configuration); | |
1520 | } |