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