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" |
2abe74eb | 37 | #include "LibCEC.h" |
abbca718 | 38 | #include "util/StdString.h" |
b9187cc6 | 39 | #include "platform/timeutils.h" |
abbca718 LOK |
40 | |
41 | using namespace CEC; | |
42 | using namespace std; | |
43 | ||
2b4d8297 | 44 | CCECProcessor::CCECProcessor(CLibCEC *controller, CAdapterCommunication *serComm, const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS*/) : |
f8513317 | 45 | m_bStarted(false), |
2abe74eb LOK |
46 | m_strDeviceName(strDeviceName), |
47 | m_communication(serComm), | |
8b7e5ff6 | 48 | m_controller(controller), |
06bfd4d7 | 49 | m_bMonitor(false) |
abbca718 | 50 | { |
f8513317 LOK |
51 | m_logicalAddresses.clear(); |
52 | m_logicalAddresses.set(iLogicalAddress); | |
53 | m_types.clear(); | |
7ea0d558 | 54 | for (int iPtr = 0; iPtr < 16; iPtr++) |
09c10b66 | 55 | m_busDevices[iPtr] = new CCECBusDevice(this, (cec_logical_address) iPtr, iPtr == iLogicalAddress ? iPhysicalAddress : 0); |
abbca718 LOK |
56 | } |
57 | ||
f8513317 LOK |
58 | CCECProcessor::CCECProcessor(CLibCEC *controller, CAdapterCommunication *serComm, const char *strDeviceName, const cec_device_type_list &types) : |
59 | m_bStarted(false), | |
60 | m_strDeviceName(strDeviceName), | |
61 | m_types(types), | |
62 | m_communication(serComm), | |
63 | m_controller(controller), | |
64 | m_bMonitor(false) | |
65 | { | |
66 | m_logicalAddresses.clear(); | |
67 | for (int iPtr = 0; iPtr < 16; iPtr++) | |
68 | m_busDevices[iPtr] = new CCECBusDevice(this, (cec_logical_address) iPtr, 0); | |
69 | } | |
70 | ||
2abe74eb | 71 | CCECProcessor::~CCECProcessor(void) |
abbca718 | 72 | { |
8b0ee2cc | 73 | m_startCondition.Broadcast(); |
2abe74eb LOK |
74 | StopThread(); |
75 | m_communication = NULL; | |
76 | m_controller = NULL; | |
d1998c7b LOK |
77 | for (unsigned int iPtr = 0; iPtr < 16; iPtr++) |
78 | delete m_busDevices[iPtr]; | |
abbca718 LOK |
79 | } |
80 | ||
2abe74eb | 81 | bool CCECProcessor::Start(void) |
abbca718 | 82 | { |
8b0ee2cc | 83 | CLockObject lock(&m_mutex); |
2abe74eb | 84 | if (!m_communication || !m_communication->IsOpen()) |
13fd6a66 LOK |
85 | { |
86 | m_controller->AddLog(CEC_LOG_ERROR, "connection is closed"); | |
a8f0bd18 | 87 | return false; |
13fd6a66 | 88 | } |
abbca718 | 89 | |
60fa4578 | 90 | if (CreateThread()) |
8b0ee2cc | 91 | { |
f8513317 | 92 | if (!m_startCondition.Wait(&m_mutex) || !m_bStarted) |
8b0ee2cc LOK |
93 | { |
94 | m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread"); | |
95 | return false; | |
96 | } | |
a8f0bd18 | 97 | return true; |
8b0ee2cc | 98 | } |
a8f0bd18 | 99 | else |
2abe74eb | 100 | m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread"); |
abbca718 | 101 | |
a8f0bd18 | 102 | return false; |
abbca718 LOK |
103 | } |
104 | ||
f8513317 LOK |
105 | bool CCECProcessor::TryLogicalAddress(cec_logical_address address, const char *strLabel) |
106 | { | |
107 | CStdString strLog; | |
108 | strLog.Format("trying logical address '%s'", strLabel); | |
109 | AddLog(CEC_LOG_DEBUG, strLog); | |
110 | ||
111 | SetAckMask(0x1 << address); | |
112 | if (!m_busDevices[address]->PollDevice(address)) | |
113 | { | |
114 | ||
115 | strLog.Format("using logical address '%s'", strLabel); | |
116 | AddLog(CEC_LOG_NOTICE, strLog); | |
117 | m_logicalAddresses.set(address); | |
118 | ||
119 | // TODO | |
120 | m_busDevices[address]->SetPhysicalAddress(CEC_DEFAULT_PHYSICAL_ADDRESS); | |
121 | ||
122 | return true; | |
123 | } | |
124 | ||
125 | strLog.Format("logical address '%s' already taken", strLabel); | |
126 | AddLog(CEC_LOG_DEBUG, strLog); | |
127 | return false; | |
128 | } | |
129 | ||
130 | bool CCECProcessor::FindLogicalAddressRecordingDevice(void) | |
131 | { | |
132 | AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'recording device'"); | |
133 | return TryLogicalAddress(CECDEVICE_RECORDINGDEVICE1, "recording 1") || | |
134 | TryLogicalAddress(CECDEVICE_RECORDINGDEVICE2, "recording 2") || | |
135 | TryLogicalAddress(CECDEVICE_RECORDINGDEVICE3, "recording 3"); | |
136 | } | |
137 | ||
138 | bool CCECProcessor::FindLogicalAddressTuner(void) | |
139 | { | |
140 | AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'tuner'"); | |
141 | return TryLogicalAddress(CECDEVICE_TUNER1, "tuner 1") || | |
142 | TryLogicalAddress(CECDEVICE_TUNER2, "tuner 2") || | |
143 | TryLogicalAddress(CECDEVICE_TUNER3, "tuner 3") || | |
144 | TryLogicalAddress(CECDEVICE_TUNER4, "tuner 4"); | |
145 | } | |
146 | ||
147 | bool CCECProcessor::FindLogicalAddressPlaybackDevice(void) | |
148 | { | |
149 | AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'playback device'"); | |
150 | return TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE1, "playback 1") || | |
151 | TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE2, "playback 2") || | |
152 | TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE3, "playback 3"); | |
153 | } | |
154 | ||
155 | bool CCECProcessor::FindLogicalAddressAudioSystem(void) | |
156 | { | |
157 | AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'audio'"); | |
158 | return TryLogicalAddress(CECDEVICE_AUDIOSYSTEM, "audio"); | |
159 | } | |
160 | ||
161 | bool CCECProcessor::FindLogicalAddresses(void) | |
162 | { | |
163 | bool bReturn(true); | |
164 | m_logicalAddresses.clear(); | |
165 | CStdString strLog; | |
166 | ||
167 | for (unsigned int iPtr = 0; iPtr < 5; iPtr++) | |
168 | { | |
169 | if (m_types.types[iPtr] == CEC_DEVICE_TYPE_RESERVED) | |
170 | continue; | |
171 | ||
172 | strLog.Format("%s - device %d: type %d", __FUNCTION__, iPtr, m_types.types[iPtr]); | |
173 | AddLog(CEC_LOG_DEBUG, strLog); | |
174 | ||
175 | if (m_types.types[iPtr] == CEC_DEVICE_TYPE_RECORDING_DEVICE) | |
176 | bReturn &= FindLogicalAddressRecordingDevice(); | |
177 | if (m_types.types[iPtr] == CEC_DEVICE_TYPE_TUNER) | |
178 | bReturn &= FindLogicalAddressTuner(); | |
179 | if (m_types.types[iPtr] == CEC_DEVICE_TYPE_PLAYBACK_DEVICE) | |
180 | bReturn &= FindLogicalAddressPlaybackDevice(); | |
181 | if (m_types.types[iPtr] == CEC_DEVICE_TYPE_AUDIO_SYSTEM) | |
182 | bReturn &= FindLogicalAddressAudioSystem(); | |
183 | } | |
184 | ||
185 | return bReturn; | |
186 | } | |
187 | ||
2abe74eb | 188 | void *CCECProcessor::Process(void) |
f99bc831 | 189 | { |
e0407d3d LOK |
190 | cec_command command; |
191 | CCECAdapterMessage msg; | |
192 | ||
8b0ee2cc | 193 | { |
f8513317 LOK |
194 | if (m_logicalAddresses.empty() && !FindLogicalAddresses()) |
195 | { | |
196 | CLockObject lock(&m_mutex); | |
197 | m_controller->AddLog(CEC_LOG_ERROR, "could not detect our logical addressed"); | |
198 | m_startCondition.Signal(); | |
199 | return NULL; | |
200 | } | |
201 | ||
202 | SetAckMask(m_logicalAddresses.ackmask()); | |
203 | ||
204 | { | |
205 | CLockObject lock(&m_mutex); | |
206 | m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started"); | |
207 | m_bStarted = true; | |
208 | m_startCondition.Signal(); | |
209 | } | |
8b0ee2cc | 210 | } |
abbca718 | 211 | |
13fd6a66 | 212 | while (!IsStopped()) |
abbca718 | 213 | { |
60fa4578 | 214 | bool bParseFrame(false); |
9dee1670 | 215 | command.clear(); |
76321de4 LOK |
216 | msg.clear(); |
217 | ||
60fa4578 LOK |
218 | { |
219 | CLockObject lock(&m_mutex); | |
88c43521 | 220 | if (m_communication->IsOpen() && m_communication->Read(msg, 50)) |
b5f34cf9 LOK |
221 | { |
222 | m_controller->AddLog(msg.is_error() ? CEC_LOG_WARNING : CEC_LOG_DEBUG, msg.ToString()); | |
88c43521 | 223 | bParseFrame = ParseMessage(msg) && !IsStopped(); |
b5f34cf9 | 224 | } |
76321de4 LOK |
225 | |
226 | if (bParseFrame) | |
9dee1670 | 227 | command = m_currentframe; |
60fa4578 LOK |
228 | } |
229 | ||
13fd6a66 | 230 | if (bParseFrame) |
9dee1670 | 231 | ParseCommand(command); |
abbca718 | 232 | |
b5f34cf9 LOK |
233 | Sleep(5); |
234 | ||
13fd6a66 LOK |
235 | m_controller->CheckKeypressTimeout(); |
236 | ||
0ab58650 LOK |
237 | for (unsigned int iDevicePtr = 0; iDevicePtr < 16; iDevicePtr++) |
238 | m_busDevices[iDevicePtr]->PollVendorId(); | |
239 | ||
b5f34cf9 | 240 | Sleep(5); |
abbca718 LOK |
241 | } |
242 | ||
60fa4578 | 243 | return NULL; |
abbca718 LOK |
244 | } |
245 | ||
2abe74eb | 246 | bool CCECProcessor::SetActiveView(void) |
abbca718 | 247 | { |
60fa4578 | 248 | if (!IsRunning()) |
f99bc831 LOK |
249 | return false; |
250 | ||
f8513317 LOK |
251 | if (!m_logicalAddresses.empty() && m_busDevices[m_logicalAddresses.primary]) |
252 | return m_busDevices[m_logicalAddresses.primary]->BroadcastActiveView(); | |
cc60ab1c | 253 | return false; |
abbca718 LOK |
254 | } |
255 | ||
2abe74eb | 256 | bool CCECProcessor::SetInactiveView(void) |
abbca718 | 257 | { |
60fa4578 | 258 | if (!IsRunning()) |
f99bc831 LOK |
259 | return false; |
260 | ||
f8513317 LOK |
261 | if (!m_logicalAddresses.empty() && m_busDevices[m_logicalAddresses.primary]) |
262 | return m_busDevices[m_logicalAddresses.primary]->BroadcastInactiveView(); | |
cc60ab1c | 263 | return false; |
abbca718 LOK |
264 | } |
265 | ||
9dee1670 | 266 | void CCECProcessor::LogOutput(const cec_command &data) |
abbca718 | 267 | { |
1d3ca3de | 268 | CStdString strTx; |
57f45e6c LOK |
269 | strTx.Format("<< %02x", ((uint8_t)data.initiator << 4) + (uint8_t)data.destination); |
270 | if (data.opcode_set) | |
271 | strTx.AppendFormat(":%02x", (uint8_t)data.opcode); | |
9dee1670 | 272 | |
06a1f7ce | 273 | for (uint8_t iPtr = 0; iPtr < data.parameters.size; iPtr++) |
1d3ca3de LOK |
274 | strTx.AppendFormat(":%02x", data.parameters[iPtr]); |
275 | m_controller->AddLog(CEC_LOG_TRAFFIC, strTx.c_str()); | |
9dee1670 | 276 | } |
2abe74eb | 277 | |
06bfd4d7 | 278 | bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress) |
abbca718 | 279 | { |
f8513317 | 280 | if (m_logicalAddresses.primary != iLogicalAddress) |
06775107 LOK |
281 | { |
282 | CStdString strLog; | |
f8513317 | 283 | strLog.Format("<< setting primary logical address to %1x", iLogicalAddress); |
06775107 | 284 | m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str()); |
f8513317 LOK |
285 | m_logicalAddresses.primary = iLogicalAddress; |
286 | m_logicalAddresses.set(iLogicalAddress); | |
287 | return SetAckMask(m_logicalAddresses.ackmask()); | |
06775107 | 288 | } |
2abe74eb | 289 | |
06bfd4d7 | 290 | return true; |
abbca718 | 291 | } |
825ddb96 | 292 | |
2492216a LOK |
293 | bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress) |
294 | { | |
f8513317 | 295 | if (!m_logicalAddresses.empty() && m_busDevices[m_logicalAddresses.primary]) |
cc60ab1c | 296 | { |
f8513317 LOK |
297 | m_busDevices[m_logicalAddresses.primary]->SetPhysicalAddress(iPhysicalAddress); |
298 | return m_busDevices[m_logicalAddresses.primary]->BroadcastActiveView(); | |
cc60ab1c LOK |
299 | } |
300 | return false; | |
1969b140 LOK |
301 | } |
302 | ||
8b7e5ff6 LOK |
303 | bool CCECProcessor::SwitchMonitoring(bool bEnable) |
304 | { | |
305 | CStdString strLog; | |
306 | strLog.Format("== %s monitoring mode ==", bEnable ? "enabling" : "disabling"); | |
307 | m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str()); | |
308 | ||
309 | m_bMonitor = bEnable; | |
310 | if (bEnable) | |
06bfd4d7 | 311 | return SetAckMask(0); |
8b7e5ff6 | 312 | else |
f8513317 | 313 | return SetAckMask(m_logicalAddresses.ackmask()); |
8b7e5ff6 LOK |
314 | } |
315 | ||
57f45e6c LOK |
316 | bool CCECProcessor::PollDevice(cec_logical_address iAddress) |
317 | { | |
318 | if (iAddress != CECDEVICE_UNKNOWN && m_busDevices[iAddress]) | |
319 | return m_busDevices[iAddress]->PollDevice(); | |
320 | return false; | |
321 | } | |
322 | ||
6a1c0009 LOK |
323 | cec_version CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress) |
324 | { | |
325 | return m_busDevices[iAddress]->GetCecVersion(); | |
326 | } | |
327 | ||
a3269a0a LOK |
328 | bool CCECProcessor::GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language) |
329 | { | |
cc60ab1c LOK |
330 | if (m_busDevices[iAddress]) |
331 | { | |
332 | *language = m_busDevices[iAddress]->GetMenuLanguage(); | |
5744fbba | 333 | return (strcmp(language->language, "???") != 0); |
cc60ab1c LOK |
334 | } |
335 | return false; | |
a3269a0a LOK |
336 | } |
337 | ||
44c74256 LOK |
338 | uint64_t CCECProcessor::GetDeviceVendorId(cec_logical_address iAddress) |
339 | { | |
cc60ab1c LOK |
340 | if (m_busDevices[iAddress]) |
341 | return m_busDevices[iAddress]->GetVendorId(); | |
342 | return false; | |
44c74256 LOK |
343 | } |
344 | ||
e55f3f70 LOK |
345 | cec_power_status CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddress) |
346 | { | |
cc60ab1c LOK |
347 | if (m_busDevices[iAddress]) |
348 | return m_busDevices[iAddress]->GetPowerStatus(); | |
349 | return CEC_POWER_STATUS_UNKNOWN; | |
e55f3f70 LOK |
350 | } |
351 | ||
8d84e2c0 | 352 | bool CCECProcessor::Transmit(const cec_command &data) |
825ddb96 | 353 | { |
28352a04 | 354 | bool bReturn(false); |
13929cff LOK |
355 | LogOutput(data); |
356 | ||
28352a04 LOK |
357 | CCECAdapterMessage *output = new CCECAdapterMessage(data); |
358 | bReturn = Transmit(output); | |
359 | delete output; | |
360 | ||
361 | return bReturn; | |
06bfd4d7 | 362 | } |
13929cff | 363 | |
28352a04 | 364 | bool CCECProcessor::Transmit(CCECAdapterMessage *output) |
06bfd4d7 LOK |
365 | { |
366 | bool bReturn(false); | |
2abe74eb | 367 | CLockObject lock(&m_mutex); |
eb35e4ca LOK |
368 | { |
369 | CLockObject msgLock(&output->mutex); | |
370 | if (!m_communication || !m_communication->Write(output)) | |
371 | return bReturn; | |
372 | else | |
0e31a62c | 373 | { |
3a0ca6e1 | 374 | output->condition.Wait(&output->mutex); |
0e31a62c LOK |
375 | if (output->state != ADAPTER_MESSAGE_STATE_SENT) |
376 | { | |
377 | m_controller->AddLog(CEC_LOG_ERROR, "command was not sent"); | |
378 | return bReturn; | |
379 | } | |
380 | } | |
2abe74eb | 381 | |
06bfd4d7 | 382 | if (output->transmit_timeout > 0) |
cd505625 | 383 | { |
06bfd4d7 | 384 | if ((bReturn = WaitForTransmitSucceeded(output->size(), output->transmit_timeout)) == false) |
cd505625 LOK |
385 | m_controller->AddLog(CEC_LOG_ERROR, "did not receive ack"); |
386 | } | |
387 | else | |
cd505625 | 388 | bReturn = true; |
2abe74eb LOK |
389 | } |
390 | ||
7ea0d558 | 391 | return bReturn; |
825ddb96 | 392 | } |
abbca718 | 393 | |
2abe74eb | 394 | void CCECProcessor::TransmitAbort(cec_logical_address address, cec_opcode opcode, ECecAbortReason reason /* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */) |
abbca718 | 395 | { |
9dee1670 LOK |
396 | m_controller->AddLog(CEC_LOG_DEBUG, "<< transmitting abort message"); |
397 | ||
06a1f7ce | 398 | cec_command command; |
f8513317 LOK |
399 | // TODO |
400 | cec_command::format(command, m_logicalAddresses.primary, address, CEC_OPCODE_FEATURE_ABORT); | |
9dee1670 LOK |
401 | command.parameters.push_back((uint8_t)opcode); |
402 | command.parameters.push_back((uint8_t)reason); | |
403 | ||
404 | Transmit(command); | |
abbca718 LOK |
405 | } |
406 | ||
1f0e9e0f | 407 | bool CCECProcessor::WaitForTransmitSucceeded(uint8_t iLength, uint32_t iTimeout /* = 1000 */) |
abbca718 | 408 | { |
1f0e9e0f LOK |
409 | bool bError(false); |
410 | bool bTransmitSucceeded(false); | |
7ea0d558 | 411 | uint8_t iPacketsLeft(iLength / 4); |
abbca718 LOK |
412 | |
413 | int64_t iNow = GetTimeMs(); | |
25701fa6 | 414 | int64_t iTargetTime = iNow + (uint64_t) iTimeout; |
abbca718 | 415 | |
1f0e9e0f | 416 | while (!bTransmitSucceeded && !bError && (iTimeout == 0 || iNow < iTargetTime)) |
abbca718 | 417 | { |
220537f2 | 418 | CCECAdapterMessage msg; |
25701fa6 | 419 | |
06a1f7ce | 420 | if (!m_communication->Read(msg, iTimeout > 0 ? (int32_t)(iTargetTime - iNow) : 1000)) |
abbca718 | 421 | { |
abbca718 | 422 | iNow = GetTimeMs(); |
5d38b0b6 LOK |
423 | continue; |
424 | } | |
425 | ||
edab6137 | 426 | if ((bError = msg.is_error()) == false) |
7ea0d558 | 427 | { |
0544ff56 LOK |
428 | m_controller->AddLog(bError ? CEC_LOG_WARNING : CEC_LOG_DEBUG, msg.ToString()); |
429 | ||
edab6137 LOK |
430 | switch(msg.message()) |
431 | { | |
432 | case MSGCODE_COMMAND_ACCEPTED: | |
433 | if (iPacketsLeft > 0) | |
434 | iPacketsLeft--; | |
435 | break; | |
436 | case MSGCODE_TRANSMIT_SUCCEEDED: | |
437 | bTransmitSucceeded = (iPacketsLeft == 0); | |
438 | bError = !bTransmitSucceeded; | |
439 | break; | |
440 | default: | |
441 | ParseMessage(msg); | |
442 | } | |
7ea0d558 | 443 | |
edab6137 LOK |
444 | iNow = GetTimeMs(); |
445 | } | |
abbca718 LOK |
446 | } |
447 | ||
1f0e9e0f | 448 | return bTransmitSucceeded && !bError; |
abbca718 LOK |
449 | } |
450 | ||
0e7b6c54 | 451 | bool CCECProcessor::ParseMessage(const CCECAdapterMessage &msg) |
abbca718 | 452 | { |
7ea0d558 | 453 | bool bEom = false; |
60fa4578 | 454 | |
0e7b6c54 | 455 | if (msg.empty()) |
7ea0d558 | 456 | return bEom; |
abbca718 | 457 | |
0e7b6c54 | 458 | switch(msg.message()) |
abbca718 | 459 | { |
abbca718 LOK |
460 | case MSGCODE_FRAME_START: |
461 | { | |
7ea0d558 | 462 | m_currentframe.clear(); |
0e7b6c54 | 463 | if (msg.size() >= 2) |
abbca718 | 464 | { |
0e7b6c54 LOK |
465 | m_currentframe.initiator = msg.initiator(); |
466 | m_currentframe.destination = msg.destination(); | |
467 | m_currentframe.ack = msg.ack(); | |
468 | m_currentframe.eom = msg.eom(); | |
abbca718 | 469 | } |
abbca718 LOK |
470 | } |
471 | break; | |
472 | case MSGCODE_FRAME_DATA: | |
473 | { | |
0e7b6c54 | 474 | if (msg.size() >= 2) |
78e8010a | 475 | { |
e41b06f9 | 476 | m_currentframe.push_back(msg[1]); |
0e7b6c54 | 477 | m_currentframe.eom = msg.eom(); |
abbca718 | 478 | } |
0e7b6c54 | 479 | bEom = msg.eom(); |
abbca718 | 480 | } |
78e8010a | 481 | break; |
abbca718 LOK |
482 | default: |
483 | break; | |
484 | } | |
7ea0d558 LOK |
485 | |
486 | return bEom; | |
abbca718 LOK |
487 | } |
488 | ||
e9de9629 | 489 | void CCECProcessor::ParseCommand(cec_command &command) |
abbca718 | 490 | { |
e9de9629 | 491 | CStdString dataStr; |
1d3ca3de | 492 | dataStr.Format(">> %1x%1x:%02x", command.initiator, command.destination, command.opcode); |
e9de9629 LOK |
493 | for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++) |
494 | dataStr.AppendFormat(":%02x", (unsigned int)command.parameters[iPtr]); | |
1d3ca3de | 495 | m_controller->AddLog(CEC_LOG_TRAFFIC, dataStr.c_str()); |
dc113aca | 496 | |
e9de9629 LOK |
497 | if (!m_bMonitor) |
498 | m_busDevices[(uint8_t)command.initiator]->HandleCommand(command); | |
dc113aca LOK |
499 | } |
500 | ||
0f23c85c LOK |
501 | uint16_t CCECProcessor::GetPhysicalAddress(void) const |
502 | { | |
f8513317 LOK |
503 | if (!m_logicalAddresses.empty() && m_busDevices[m_logicalAddresses.primary]) |
504 | return m_busDevices[m_logicalAddresses.primary]->GetPhysicalAddress(); | |
cc60ab1c | 505 | return false; |
0f23c85c LOK |
506 | } |
507 | ||
e9de9629 | 508 | void CCECProcessor::SetCurrentButton(cec_user_control_code iButtonCode) |
dc113aca | 509 | { |
e9de9629 | 510 | m_controller->SetCurrentButton(iButtonCode); |
dc113aca LOK |
511 | } |
512 | ||
e9de9629 | 513 | void CCECProcessor::AddCommand(const cec_command &command) |
dc113aca | 514 | { |
0544ff56 | 515 | m_controller->AddCommand(command); |
dc113aca LOK |
516 | } |
517 | ||
95ba7a09 LOK |
518 | void CCECProcessor::AddKey(cec_keypress &key) |
519 | { | |
520 | m_controller->AddKey(key); | |
521 | } | |
522 | ||
e9de9629 | 523 | void CCECProcessor::AddKey(void) |
dc113aca | 524 | { |
e9de9629 | 525 | m_controller->AddKey(); |
abbca718 | 526 | } |
acec5f48 | 527 | |
e9de9629 | 528 | void CCECProcessor::AddLog(cec_log_level level, const CStdString &strMessage) |
acec5f48 | 529 | { |
e9de9629 | 530 | m_controller->AddLog(level, strMessage); |
acec5f48 | 531 | } |
06bfd4d7 LOK |
532 | |
533 | bool CCECProcessor::SetAckMask(uint16_t iMask) | |
534 | { | |
28352a04 | 535 | bool bReturn(false); |
06bfd4d7 LOK |
536 | CStdString strLog; |
537 | strLog.Format("setting ackmask to %2x", iMask); | |
538 | m_controller->AddLog(CEC_LOG_DEBUG, strLog.c_str()); | |
539 | ||
28352a04 | 540 | CCECAdapterMessage *output = new CCECAdapterMessage; |
06bfd4d7 LOK |
541 | |
542 | output->push_back(MSGSTART); | |
543 | output->push_escaped(MSGCODE_SET_ACK_MASK); | |
544 | output->push_escaped(iMask >> 8); | |
545 | output->push_escaped((uint8_t)iMask); | |
546 | output->push_back(MSGEND); | |
547 | ||
28352a04 | 548 | if ((bReturn = Transmit(output)) == false) |
06bfd4d7 | 549 | m_controller->AddLog(CEC_LOG_ERROR, "could not set the ackmask"); |
06bfd4d7 | 550 | |
28352a04 LOK |
551 | delete output; |
552 | ||
553 | return bReturn; | |
06bfd4d7 | 554 | } |