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