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