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