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" |
e9de9629 | 36 | #include "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*/) : |
2492216a | 45 | m_iPhysicalAddress(iPhysicalAddress), |
df7339c6 | 46 | m_iLogicalAddress(iLogicalAddress), |
2abe74eb LOK |
47 | m_strDeviceName(strDeviceName), |
48 | m_communication(serComm), | |
8b7e5ff6 LOK |
49 | m_controller(controller), |
50 | m_bMonitor(false) | |
abbca718 | 51 | { |
e9de9629 LOK |
52 | for (unsigned int iPtr = 0; iPtr < 16; iPtr++) |
53 | m_busDevices[iPtr] = new CCECBusDevice(this, (cec_logical_address) iPtr, 0); | |
abbca718 LOK |
54 | } |
55 | ||
2abe74eb | 56 | CCECProcessor::~CCECProcessor(void) |
abbca718 | 57 | { |
2abe74eb LOK |
58 | StopThread(); |
59 | m_communication = NULL; | |
60 | m_controller = NULL; | |
d1998c7b LOK |
61 | for (unsigned int iPtr = 0; iPtr < 16; iPtr++) |
62 | delete m_busDevices[iPtr]; | |
abbca718 LOK |
63 | } |
64 | ||
2abe74eb | 65 | bool CCECProcessor::Start(void) |
abbca718 | 66 | { |
2abe74eb | 67 | if (!m_communication || !m_communication->IsOpen()) |
13fd6a66 LOK |
68 | { |
69 | m_controller->AddLog(CEC_LOG_ERROR, "connection is closed"); | |
a8f0bd18 | 70 | return false; |
13fd6a66 | 71 | } |
abbca718 | 72 | |
a8f0bd18 | 73 | if (!SetLogicalAddress(m_iLogicalAddress)) |
abbca718 | 74 | { |
2abe74eb | 75 | m_controller->AddLog(CEC_LOG_ERROR, "could not set the logical address"); |
a8f0bd18 | 76 | return false; |
abbca718 LOK |
77 | } |
78 | ||
60fa4578 | 79 | if (CreateThread()) |
a8f0bd18 | 80 | return true; |
a8f0bd18 | 81 | else |
2abe74eb | 82 | m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread"); |
abbca718 | 83 | |
a8f0bd18 | 84 | return false; |
abbca718 LOK |
85 | } |
86 | ||
2abe74eb | 87 | void *CCECProcessor::Process(void) |
f99bc831 | 88 | { |
2abe74eb | 89 | m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started"); |
abbca718 | 90 | |
9dee1670 LOK |
91 | cec_command command; |
92 | cec_adapter_message msg; | |
93 | ||
13fd6a66 | 94 | while (!IsStopped()) |
abbca718 | 95 | { |
60fa4578 | 96 | bool bParseFrame(false); |
78e8010a LOK |
97 | bool bError(false); |
98 | bool bTransmitSucceeded(false); | |
9dee1670 | 99 | command.clear(); |
76321de4 LOK |
100 | msg.clear(); |
101 | ||
60fa4578 LOK |
102 | { |
103 | CLockObject lock(&m_mutex); | |
76321de4 | 104 | if (m_communication->IsOpen() && m_communication->Read(msg, 50)) |
78e8010a | 105 | ParseMessage(msg, &bError, &bTransmitSucceeded, &bParseFrame); |
76321de4 | 106 | |
78e8010a | 107 | bParseFrame &= !IsStopped(); |
76321de4 | 108 | if (bParseFrame) |
9dee1670 | 109 | command = m_currentframe; |
60fa4578 LOK |
110 | } |
111 | ||
13fd6a66 | 112 | if (bParseFrame) |
9dee1670 | 113 | ParseCommand(command); |
abbca718 | 114 | |
13fd6a66 LOK |
115 | m_controller->CheckKeypressTimeout(); |
116 | ||
0ab58650 LOK |
117 | for (unsigned int iDevicePtr = 0; iDevicePtr < 16; iDevicePtr++) |
118 | m_busDevices[iDevicePtr]->PollVendorId(); | |
119 | ||
13fd6a66 | 120 | if (!IsStopped()) |
d5bffd3c | 121 | Sleep(5); |
abbca718 LOK |
122 | } |
123 | ||
60fa4578 | 124 | return NULL; |
abbca718 LOK |
125 | } |
126 | ||
2abe74eb | 127 | bool CCECProcessor::PowerOnDevices(cec_logical_address address /* = CECDEVICE_TV */) |
abbca718 | 128 | { |
60fa4578 | 129 | if (!IsRunning()) |
f99bc831 LOK |
130 | return false; |
131 | ||
abbca718 | 132 | CStdString strLog; |
88f45c9b | 133 | strLog.Format("<< powering on device with logical address %d", (int8_t)address); |
2abe74eb | 134 | m_controller->AddLog(CEC_LOG_DEBUG, strLog.c_str()); |
25701fa6 | 135 | |
06a1f7ce LOK |
136 | cec_command command; |
137 | cec_command::format(command, m_iLogicalAddress, address, CEC_OPCODE_IMAGE_VIEW_ON); | |
138 | ||
139 | return Transmit(command); | |
abbca718 LOK |
140 | } |
141 | ||
2abe74eb | 142 | bool CCECProcessor::StandbyDevices(cec_logical_address address /* = CECDEVICE_BROADCAST */) |
abbca718 | 143 | { |
60fa4578 | 144 | if (!IsRunning()) |
f99bc831 LOK |
145 | return false; |
146 | ||
abbca718 | 147 | CStdString strLog; |
88f45c9b | 148 | strLog.Format("<< putting device with logical address %d in standby mode", (int8_t)address); |
2abe74eb | 149 | m_controller->AddLog(CEC_LOG_DEBUG, strLog.c_str()); |
25701fa6 | 150 | |
06a1f7ce LOK |
151 | cec_command command; |
152 | cec_command::format(command, m_iLogicalAddress, address, CEC_OPCODE_STANDBY); | |
153 | ||
154 | return Transmit(command); | |
abbca718 LOK |
155 | } |
156 | ||
2abe74eb | 157 | bool CCECProcessor::SetActiveView(void) |
abbca718 | 158 | { |
60fa4578 | 159 | if (!IsRunning()) |
f99bc831 LOK |
160 | return false; |
161 | ||
88f45c9b | 162 | m_controller->AddLog(CEC_LOG_DEBUG, "<< setting active view"); |
9dee1670 | 163 | |
06a1f7ce LOK |
164 | cec_command command; |
165 | cec_command::format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_ACTIVE_SOURCE); | |
2492216a LOK |
166 | command.parameters.push_back((m_iPhysicalAddress >> 8) & 0xFF); |
167 | command.parameters.push_back(m_iPhysicalAddress & 0xFF); | |
9dee1670 LOK |
168 | |
169 | return Transmit(command); | |
abbca718 LOK |
170 | } |
171 | ||
2abe74eb | 172 | bool CCECProcessor::SetInactiveView(void) |
abbca718 | 173 | { |
60fa4578 | 174 | if (!IsRunning()) |
f99bc831 LOK |
175 | return false; |
176 | ||
88f45c9b | 177 | m_controller->AddLog(CEC_LOG_DEBUG, "<< setting inactive view"); |
9dee1670 | 178 | |
06a1f7ce LOK |
179 | cec_command command; |
180 | cec_command::format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_INACTIVE_SOURCE); | |
2492216a LOK |
181 | command.parameters.push_back((m_iPhysicalAddress >> 8) & 0xFF); |
182 | command.parameters.push_back(m_iPhysicalAddress & 0xFF); | |
9dee1670 LOK |
183 | |
184 | return Transmit(command); | |
abbca718 LOK |
185 | } |
186 | ||
9dee1670 | 187 | void CCECProcessor::LogOutput(const cec_command &data) |
abbca718 | 188 | { |
2abe74eb | 189 | CStdString txStr = "transmit "; |
9dee1670 | 190 | txStr.AppendFormat(" %02x", ((uint8_t)data.initiator << 4) + (uint8_t)data.destination); |
2b885768 | 191 | txStr.AppendFormat(":%02x", (uint8_t)data.opcode); |
9dee1670 | 192 | |
06a1f7ce | 193 | for (uint8_t iPtr = 0; iPtr < data.parameters.size; iPtr++) |
2b885768 | 194 | txStr.AppendFormat(":%02x", data.parameters[iPtr]); |
2abe74eb | 195 | m_controller->AddLog(CEC_LOG_DEBUG, txStr.c_str()); |
9dee1670 | 196 | } |
2abe74eb | 197 | |
9dee1670 LOK |
198 | bool CCECProcessor::Transmit(const cec_command &data, bool bWaitForAck /* = true */) |
199 | { | |
200 | LogOutput(data); | |
2abe74eb | 201 | |
9dee1670 | 202 | cec_adapter_message output; |
25701fa6 | 203 | output.clear(); |
9dee1670 | 204 | CAdapterCommunication::FormatAdapterMessage(data, output); |
2abe74eb LOK |
205 | |
206 | return TransmitFormatted(output, bWaitForAck); | |
abbca718 LOK |
207 | } |
208 | ||
2abe74eb | 209 | bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress) |
abbca718 | 210 | { |
2abe74eb | 211 | CStdString strLog; |
2492216a | 212 | strLog.Format("<< setting logical address to %1x", iLogicalAddress); |
2abe74eb LOK |
213 | m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str()); |
214 | ||
215 | m_iLogicalAddress = iLogicalAddress; | |
216 | return m_communication && m_communication->SetAckMask(0x1 << (uint8_t)m_iLogicalAddress); | |
abbca718 | 217 | } |
825ddb96 | 218 | |
2492216a LOK |
219 | bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress) |
220 | { | |
221 | CStdString strLog; | |
222 | strLog.Format("<< setting physical address to %2x", iPhysicalAddress); | |
223 | m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str()); | |
224 | ||
225 | m_iPhysicalAddress = iPhysicalAddress; | |
226 | return SetActiveView(); | |
227 | } | |
228 | ||
1969b140 LOK |
229 | bool CCECProcessor::SetOSDString(cec_logical_address iLogicalAddress, cec_display_control duration, const char *strMessage) |
230 | { | |
231 | CStdString strLog; | |
232 | strLog.Format("<< display message '%s'", strMessage); | |
233 | m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str()); | |
234 | ||
235 | cec_command command; | |
236 | cec_command::format(command, m_iLogicalAddress, iLogicalAddress, CEC_OPCODE_SET_OSD_STRING); | |
237 | command.parameters.push_back((uint8_t)duration); | |
238 | ||
239 | for (unsigned int iPtr = 0; iPtr < strlen(strMessage); iPtr++) | |
240 | command.parameters.push_back(strMessage[iPtr]); | |
241 | ||
242 | return Transmit(command); | |
243 | } | |
244 | ||
8b7e5ff6 LOK |
245 | bool CCECProcessor::SwitchMonitoring(bool bEnable) |
246 | { | |
247 | CStdString strLog; | |
248 | strLog.Format("== %s monitoring mode ==", bEnable ? "enabling" : "disabling"); | |
249 | m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str()); | |
250 | ||
251 | m_bMonitor = bEnable; | |
252 | if (bEnable) | |
253 | return m_communication && m_communication->SetAckMask(0); | |
254 | else | |
255 | return m_communication && m_communication->SetAckMask(0x1 << (uint8_t)m_iLogicalAddress); | |
256 | } | |
257 | ||
9dee1670 | 258 | bool CCECProcessor::TransmitFormatted(const cec_adapter_message &data, bool bWaitForAck /* = true */) |
825ddb96 | 259 | { |
2abe74eb LOK |
260 | CLockObject lock(&m_mutex); |
261 | if (!m_communication || !m_communication->Write(data)) | |
262 | return false; | |
263 | ||
050df0f9 | 264 | if (bWaitForAck) |
2abe74eb | 265 | { |
050df0f9 LOK |
266 | uint64_t now = GetTimeMs(); |
267 | uint64_t target = now + 1000; | |
268 | bool bError(false); | |
269 | bool bGotAck(false); | |
270 | ||
271 | while (!bGotAck && now < target) | |
272 | { | |
06a1f7ce | 273 | bGotAck = WaitForAck(&bError, (uint32_t) (target - now)); |
050df0f9 LOK |
274 | now = GetTimeMs(); |
275 | ||
276 | if (bError && now < target) | |
277 | { | |
278 | m_controller->AddLog(CEC_LOG_ERROR, "retransmitting previous frame"); | |
279 | if (!m_communication->Write(data)) | |
280 | return false; | |
281 | } | |
282 | } | |
2abe74eb LOK |
283 | } |
284 | ||
285 | return true; | |
825ddb96 | 286 | } |
abbca718 | 287 | |
2abe74eb | 288 | void CCECProcessor::TransmitAbort(cec_logical_address address, cec_opcode opcode, ECecAbortReason reason /* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */) |
abbca718 | 289 | { |
9dee1670 LOK |
290 | m_controller->AddLog(CEC_LOG_DEBUG, "<< transmitting abort message"); |
291 | ||
06a1f7ce LOK |
292 | cec_command command; |
293 | cec_command::format(command, m_iLogicalAddress, address, CEC_OPCODE_FEATURE_ABORT); | |
9dee1670 LOK |
294 | command.parameters.push_back((uint8_t)opcode); |
295 | command.parameters.push_back((uint8_t)reason); | |
296 | ||
297 | Transmit(command); | |
abbca718 LOK |
298 | } |
299 | ||
2abe74eb | 300 | void CCECProcessor::ReportCECVersion(cec_logical_address address /* = CECDEVICE_TV */) |
abbca718 | 301 | { |
88f45c9b | 302 | m_controller->AddLog(CEC_LOG_NOTICE, "<< reporting CEC version as 1.3a"); |
9dee1670 | 303 | |
06a1f7ce LOK |
304 | cec_command command; |
305 | cec_command::format(command, m_iLogicalAddress, address, CEC_OPCODE_CEC_VERSION); | |
9dee1670 LOK |
306 | command.parameters.push_back(CEC_VERSION_1_3A); |
307 | ||
308 | Transmit(command); | |
abbca718 LOK |
309 | } |
310 | ||
2abe74eb | 311 | void CCECProcessor::ReportPowerState(cec_logical_address address /*= CECDEVICE_TV */, bool bOn /* = true */) |
abbca718 | 312 | { |
abbca718 | 313 | if (bOn) |
88f45c9b | 314 | m_controller->AddLog(CEC_LOG_NOTICE, "<< reporting \"On\" power status"); |
abbca718 | 315 | else |
88f45c9b | 316 | m_controller->AddLog(CEC_LOG_NOTICE, "<< reporting \"Off\" power status"); |
abbca718 | 317 | |
06a1f7ce LOK |
318 | cec_command command; |
319 | cec_command::format(command, m_iLogicalAddress, address, CEC_OPCODE_REPORT_POWER_STATUS); | |
9dee1670 LOK |
320 | command.parameters.push_back(bOn ? (uint8_t) CEC_POWER_STATUS_ON : (uint8_t) CEC_POWER_STATUS_STANDBY); |
321 | ||
322 | Transmit(command); | |
abbca718 LOK |
323 | } |
324 | ||
2abe74eb | 325 | void CCECProcessor::ReportMenuState(cec_logical_address address /* = CECDEVICE_TV */, bool bActive /* = true */) |
abbca718 | 326 | { |
abbca718 | 327 | if (bActive) |
88f45c9b | 328 | m_controller->AddLog(CEC_LOG_NOTICE, "<< reporting menu state as active"); |
abbca718 | 329 | else |
88f45c9b | 330 | m_controller->AddLog(CEC_LOG_NOTICE, "<< reporting menu state as inactive"); |
abbca718 | 331 | |
06a1f7ce LOK |
332 | cec_command command; |
333 | cec_command::format(command, m_iLogicalAddress, address, CEC_OPCODE_MENU_STATUS); | |
9dee1670 LOK |
334 | command.parameters.push_back(bActive ? (uint8_t) CEC_MENU_STATE_ACTIVATED : (uint8_t) CEC_MENU_STATE_DEACTIVATED); |
335 | ||
336 | Transmit(command); | |
abbca718 LOK |
337 | } |
338 | ||
2abe74eb | 339 | void CCECProcessor::ReportVendorID(cec_logical_address address /* = CECDEVICE_TV */) |
abbca718 | 340 | { |
88f45c9b | 341 | m_controller->AddLog(CEC_LOG_NOTICE, "<< vendor ID requested, feature abort"); |
abbca718 LOK |
342 | TransmitAbort(address, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID); |
343 | } | |
344 | ||
2abe74eb | 345 | void CCECProcessor::ReportOSDName(cec_logical_address address /* = CECDEVICE_TV */) |
abbca718 | 346 | { |
abbca718 LOK |
347 | const char *osdname = m_strDeviceName.c_str(); |
348 | CStdString strLog; | |
88f45c9b | 349 | strLog.Format("<< reporting OSD name as %s", osdname); |
2abe74eb | 350 | m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str()); |
abbca718 | 351 | |
06a1f7ce LOK |
352 | cec_command command; |
353 | cec_command::format(command, m_iLogicalAddress, address, CEC_OPCODE_SET_OSD_NAME); | |
9dee1670 LOK |
354 | for (unsigned int iPtr = 0; iPtr < strlen(osdname); iPtr++) |
355 | command.parameters.push_back(osdname[iPtr]); | |
abbca718 | 356 | |
9dee1670 | 357 | Transmit(command); |
abbca718 LOK |
358 | } |
359 | ||
2abe74eb | 360 | void CCECProcessor::ReportPhysicalAddress(void) |
abbca718 | 361 | { |
abbca718 | 362 | CStdString strLog; |
2492216a | 363 | strLog.Format("<< reporting physical address as %04x", m_iPhysicalAddress); |
2abe74eb | 364 | m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str()); |
9dee1670 | 365 | |
06a1f7ce LOK |
366 | cec_command command; |
367 | cec_command::format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_REPORT_PHYSICAL_ADDRESS); | |
2492216a LOK |
368 | command.parameters.push_back((uint8_t) ((m_iPhysicalAddress >> 8) & 0xFF)); |
369 | command.parameters.push_back((uint8_t) (m_iPhysicalAddress & 0xFF)); | |
4a75b661 | 370 | command.parameters.push_back((uint8_t) (CEC_DEVICE_TYPE_PLAYBACK_DEVICE)); |
9dee1670 LOK |
371 | |
372 | Transmit(command); | |
abbca718 LOK |
373 | } |
374 | ||
2abe74eb | 375 | void CCECProcessor::BroadcastActiveSource(void) |
abbca718 | 376 | { |
a6d4fc28 | 377 | m_controller->AddLog(CEC_LOG_NOTICE, "<< broadcasting active source"); |
abbca718 | 378 | |
06a1f7ce LOK |
379 | cec_command command; |
380 | cec_command::format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_ACTIVE_SOURCE); | |
2492216a LOK |
381 | command.parameters.push_back((uint8_t) ((m_iPhysicalAddress >> 8) & 0xFF)); |
382 | command.parameters.push_back((uint8_t) (m_iPhysicalAddress & 0xFF)); | |
9dee1670 LOK |
383 | |
384 | Transmit(command); | |
abbca718 LOK |
385 | } |
386 | ||
050df0f9 | 387 | bool CCECProcessor::WaitForAck(bool *bError, uint32_t iTimeout /* = 1000 */) |
abbca718 | 388 | { |
78e8010a | 389 | bool bTransmitSucceeded = false, bEom = false; |
050df0f9 | 390 | *bError = false; |
abbca718 LOK |
391 | |
392 | int64_t iNow = GetTimeMs(); | |
25701fa6 | 393 | int64_t iTargetTime = iNow + (uint64_t) iTimeout; |
abbca718 | 394 | |
78e8010a | 395 | while (!bTransmitSucceeded && !*bError && (iTimeout == 0 || iNow < iTargetTime)) |
abbca718 | 396 | { |
9dee1670 | 397 | cec_adapter_message msg; |
25701fa6 LOK |
398 | msg.clear(); |
399 | ||
06a1f7ce | 400 | if (!m_communication->Read(msg, iTimeout > 0 ? (int32_t)(iTargetTime - iNow) : 1000)) |
abbca718 | 401 | { |
abbca718 | 402 | iNow = GetTimeMs(); |
5d38b0b6 LOK |
403 | continue; |
404 | } | |
405 | ||
78e8010a | 406 | ParseMessage(msg, bError, &bTransmitSucceeded, &bEom, false); |
5d38b0b6 | 407 | iNow = GetTimeMs(); |
abbca718 LOK |
408 | } |
409 | ||
78e8010a | 410 | return bTransmitSucceeded && !*bError; |
abbca718 LOK |
411 | } |
412 | ||
78e8010a | 413 | void CCECProcessor::ParseMessage(cec_adapter_message &msg, bool *bError, bool *bTransmitSucceeded, bool *bEom, bool bProcessMessages /* = true */) |
abbca718 | 414 | { |
78e8010a LOK |
415 | *bError = false; |
416 | *bTransmitSucceeded = false; | |
417 | *bEom = false; | |
60fa4578 | 418 | |
a6b6469c | 419 | if (msg.empty()) |
78e8010a | 420 | return; |
abbca718 LOK |
421 | |
422 | CStdString logStr; | |
abbca718 | 423 | |
a6b6469c | 424 | switch(msg.message()) |
abbca718 LOK |
425 | { |
426 | case MSGCODE_NOTHING: | |
2abe74eb | 427 | m_controller->AddLog(CEC_LOG_DEBUG, "MSGCODE_NOTHING"); |
abbca718 LOK |
428 | break; |
429 | case MSGCODE_TIMEOUT_ERROR: | |
430 | case MSGCODE_HIGH_ERROR: | |
431 | case MSGCODE_LOW_ERROR: | |
432 | { | |
a6b6469c | 433 | if (msg.message() == MSGCODE_TIMEOUT_ERROR) |
abbca718 | 434 | logStr = "MSGCODE_TIMEOUT"; |
a6b6469c | 435 | else if (msg.message() == MSGCODE_HIGH_ERROR) |
abbca718 LOK |
436 | logStr = "MSGCODE_HIGH_ERROR"; |
437 | else | |
438 | logStr = "MSGCODE_LOW_ERROR"; | |
439 | ||
a6b6469c LOK |
440 | int iLine = (msg.size() >= 3) ? (msg[1] << 8) | (msg[2]) : 0; |
441 | uint32_t iTime = (msg.size() >= 7) ? (msg[3] << 24) | (msg[4] << 16) | (msg[5] << 8) | (msg[6]) : 0; | |
abbca718 LOK |
442 | logStr.AppendFormat(" line:%i", iLine); |
443 | logStr.AppendFormat(" time:%u", iTime); | |
2abe74eb | 444 | m_controller->AddLog(CEC_LOG_WARNING, logStr.c_str()); |
78e8010a | 445 | *bError = true; |
abbca718 LOK |
446 | } |
447 | break; | |
448 | case MSGCODE_FRAME_START: | |
449 | { | |
78e8010a | 450 | if (bProcessMessages) |
abbca718 | 451 | { |
78e8010a LOK |
452 | logStr = "MSGCODE_FRAME_START"; |
453 | m_currentframe.clear(); | |
454 | if (msg.size() >= 2) | |
455 | { | |
456 | logStr.AppendFormat(" initiator:%u destination:%u ack:%s %s", msg.initiator(), msg.destination(), msg.ack() ? "high" : "low", msg.eom() ? "eom" : ""); | |
457 | m_currentframe.initiator = msg.initiator(); | |
458 | m_currentframe.destination = msg.destination(); | |
459 | m_currentframe.ack = msg.ack(); | |
460 | m_currentframe.eom = msg.eom(); | |
461 | } | |
462 | m_controller->AddLog(CEC_LOG_DEBUG, logStr.c_str()); | |
463 | } | |
464 | else | |
465 | { | |
466 | m_frameBuffer.Push(msg); | |
abbca718 | 467 | } |
abbca718 LOK |
468 | } |
469 | break; | |
470 | case MSGCODE_FRAME_DATA: | |
471 | { | |
78e8010a LOK |
472 | if (bProcessMessages) |
473 | { | |
474 | logStr = "MSGCODE_FRAME_DATA"; | |
475 | if (msg.size() >= 2) | |
476 | { | |
477 | uint8_t iData = msg[1]; | |
478 | logStr.AppendFormat(" %02x", iData); | |
479 | m_currentframe.push_back(iData); | |
480 | m_currentframe.eom = msg.eom(); | |
481 | } | |
482 | m_controller->AddLog(CEC_LOG_DEBUG, logStr.c_str()); | |
483 | } | |
484 | else | |
abbca718 | 485 | { |
78e8010a | 486 | m_frameBuffer.Push(msg); |
abbca718 | 487 | } |
78e8010a LOK |
488 | |
489 | *bEom = msg.eom(); | |
abbca718 | 490 | } |
78e8010a LOK |
491 | break; |
492 | case MSGCODE_COMMAND_ACCEPTED: | |
493 | m_controller->AddLog(CEC_LOG_DEBUG, "MSGCODE_COMMAND_ACCEPTED"); | |
494 | break; | |
495 | case MSGCODE_TRANSMIT_SUCCEEDED: | |
496 | m_controller->AddLog(CEC_LOG_DEBUG, "MSGCODE_TRANSMIT_SUCCEEDED"); | |
497 | *bTransmitSucceeded = true; | |
498 | break; | |
499 | case MSGCODE_RECEIVE_FAILED: | |
500 | m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_RECEIVE_FAILED"); | |
501 | *bError = true; | |
502 | break; | |
503 | case MSGCODE_COMMAND_REJECTED: | |
504 | m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_COMMAND_REJECTED"); | |
505 | *bError = true; | |
506 | break; | |
507 | case MSGCODE_TRANSMIT_FAILED_LINE: | |
508 | m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_LINE"); | |
509 | *bError = true; | |
510 | break; | |
511 | case MSGCODE_TRANSMIT_FAILED_ACK: | |
512 | m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_ACK"); | |
513 | *bError = true; | |
514 | break; | |
515 | case MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA: | |
516 | m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA"); | |
517 | *bError = true; | |
518 | break; | |
519 | case MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE: | |
520 | m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE"); | |
521 | *bError = true; | |
abbca718 LOK |
522 | break; |
523 | default: | |
524 | break; | |
525 | } | |
526 | } | |
527 | ||
9dee1670 | 528 | void CCECProcessor::ParseVendorId(cec_logical_address device, const cec_datapacket &data) |
5f150ee2 | 529 | { |
9dee1670 | 530 | if (data.size < 3) |
5f150ee2 LOK |
531 | { |
532 | m_controller->AddLog(CEC_LOG_WARNING, "invalid vendor ID received"); | |
533 | return; | |
534 | } | |
535 | ||
a6b6469c LOK |
536 | uint64_t iVendorId = ((uint64_t)data[0] << 3) + |
537 | ((uint64_t)data[1] << 2) + | |
538 | (uint64_t)data[2]; | |
5f150ee2 | 539 | |
e9de9629 | 540 | m_busDevices[(uint8_t)device]->SetVendorId(iVendorId, data.size >= 4 ? data[3] : 0); |
5f150ee2 LOK |
541 | } |
542 | ||
e9de9629 | 543 | void CCECProcessor::ParseCommand(cec_command &command) |
abbca718 | 544 | { |
e9de9629 LOK |
545 | CStdString dataStr; |
546 | dataStr.Format(">> received frame: %1x%1x:%02x", command.initiator, command.destination, command.opcode); | |
547 | for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++) | |
548 | dataStr.AppendFormat(":%02x", (unsigned int)command.parameters[iPtr]); | |
549 | m_controller->AddLog(CEC_LOG_DEBUG, dataStr.c_str()); | |
dc113aca | 550 | |
e9de9629 LOK |
551 | if (!m_bMonitor) |
552 | m_busDevices[(uint8_t)command.initiator]->HandleCommand(command); | |
dc113aca LOK |
553 | } |
554 | ||
e9de9629 | 555 | void CCECProcessor::SetCurrentButton(cec_user_control_code iButtonCode) |
dc113aca | 556 | { |
e9de9629 | 557 | m_controller->SetCurrentButton(iButtonCode); |
dc113aca LOK |
558 | } |
559 | ||
e9de9629 | 560 | void CCECProcessor::AddCommand(const cec_command &command) |
dc113aca | 561 | { |
e9de9629 | 562 | m_controller->AddCommand(command); |
dc113aca LOK |
563 | } |
564 | ||
e9de9629 | 565 | void CCECProcessor::AddKey(void) |
dc113aca | 566 | { |
e9de9629 | 567 | m_controller->AddKey(); |
abbca718 | 568 | } |
acec5f48 | 569 | |
e9de9629 | 570 | void CCECProcessor::AddLog(cec_log_level level, const CStdString &strMessage) |
acec5f48 | 571 | { |
e9de9629 | 572 | m_controller->AddLog(level, strMessage); |
acec5f48 | 573 | } |