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