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