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