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