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