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*/) : |
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 | { |
1d3ca3de LOK |
189 | CStdString strTx; |
190 | strTx.Format("<< %02x:%02x", ((uint8_t)data.initiator << 4) + (uint8_t)data.destination, (uint8_t)data.opcode); | |
9dee1670 | 191 | |
06a1f7ce | 192 | for (uint8_t iPtr = 0; iPtr < data.parameters.size; iPtr++) |
1d3ca3de LOK |
193 | strTx.AppendFormat(":%02x", data.parameters[iPtr]); |
194 | m_controller->AddLog(CEC_LOG_TRAFFIC, strTx.c_str()); | |
9dee1670 | 195 | } |
2abe74eb | 196 | |
9dee1670 LOK |
197 | bool CCECProcessor::Transmit(const cec_command &data, bool bWaitForAck /* = true */) |
198 | { | |
199 | LogOutput(data); | |
2abe74eb | 200 | |
9dee1670 | 201 | cec_adapter_message output; |
25701fa6 | 202 | output.clear(); |
9dee1670 | 203 | CAdapterCommunication::FormatAdapterMessage(data, output); |
2abe74eb LOK |
204 | |
205 | return TransmitFormatted(output, bWaitForAck); | |
abbca718 LOK |
206 | } |
207 | ||
2abe74eb | 208 | bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress) |
abbca718 | 209 | { |
2abe74eb | 210 | CStdString strLog; |
2492216a | 211 | strLog.Format("<< setting logical address to %1x", iLogicalAddress); |
2abe74eb LOK |
212 | m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str()); |
213 | ||
214 | m_iLogicalAddress = iLogicalAddress; | |
215 | return m_communication && m_communication->SetAckMask(0x1 << (uint8_t)m_iLogicalAddress); | |
abbca718 | 216 | } |
825ddb96 | 217 | |
2492216a LOK |
218 | bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress) |
219 | { | |
220 | CStdString strLog; | |
221 | strLog.Format("<< setting physical address to %2x", iPhysicalAddress); | |
222 | m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str()); | |
223 | ||
224 | m_iPhysicalAddress = iPhysicalAddress; | |
225 | return SetActiveView(); | |
226 | } | |
227 | ||
1969b140 LOK |
228 | bool CCECProcessor::SetOSDString(cec_logical_address iLogicalAddress, cec_display_control duration, const char *strMessage) |
229 | { | |
230 | CStdString strLog; | |
231 | strLog.Format("<< display message '%s'", strMessage); | |
232 | m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str()); | |
233 | ||
234 | cec_command command; | |
235 | cec_command::format(command, m_iLogicalAddress, iLogicalAddress, CEC_OPCODE_SET_OSD_STRING); | |
236 | command.parameters.push_back((uint8_t)duration); | |
237 | ||
238 | for (unsigned int iPtr = 0; iPtr < strlen(strMessage); iPtr++) | |
239 | command.parameters.push_back(strMessage[iPtr]); | |
240 | ||
241 | return Transmit(command); | |
242 | } | |
243 | ||
8b7e5ff6 LOK |
244 | bool CCECProcessor::SwitchMonitoring(bool bEnable) |
245 | { | |
246 | CStdString strLog; | |
247 | strLog.Format("== %s monitoring mode ==", bEnable ? "enabling" : "disabling"); | |
248 | m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str()); | |
249 | ||
250 | m_bMonitor = bEnable; | |
251 | if (bEnable) | |
252 | return m_communication && m_communication->SetAckMask(0); | |
253 | else | |
254 | return m_communication && m_communication->SetAckMask(0x1 << (uint8_t)m_iLogicalAddress); | |
255 | } | |
256 | ||
9dee1670 | 257 | bool CCECProcessor::TransmitFormatted(const cec_adapter_message &data, bool bWaitForAck /* = true */) |
825ddb96 | 258 | { |
2abe74eb LOK |
259 | CLockObject lock(&m_mutex); |
260 | if (!m_communication || !m_communication->Write(data)) | |
261 | return false; | |
262 | ||
050df0f9 | 263 | if (bWaitForAck) |
2abe74eb | 264 | { |
050df0f9 LOK |
265 | uint64_t now = GetTimeMs(); |
266 | uint64_t target = now + 1000; | |
267 | bool bError(false); | |
268 | bool bGotAck(false); | |
269 | ||
270 | while (!bGotAck && now < target) | |
271 | { | |
06a1f7ce | 272 | bGotAck = WaitForAck(&bError, (uint32_t) (target - now)); |
050df0f9 LOK |
273 | now = GetTimeMs(); |
274 | ||
275 | if (bError && now < target) | |
276 | { | |
277 | m_controller->AddLog(CEC_LOG_ERROR, "retransmitting previous frame"); | |
278 | if (!m_communication->Write(data)) | |
279 | return false; | |
280 | } | |
281 | } | |
2abe74eb LOK |
282 | } |
283 | ||
284 | return true; | |
825ddb96 | 285 | } |
abbca718 | 286 | |
2abe74eb | 287 | void CCECProcessor::TransmitAbort(cec_logical_address address, cec_opcode opcode, ECecAbortReason reason /* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */) |
abbca718 | 288 | { |
9dee1670 LOK |
289 | m_controller->AddLog(CEC_LOG_DEBUG, "<< transmitting abort message"); |
290 | ||
06a1f7ce LOK |
291 | cec_command command; |
292 | cec_command::format(command, m_iLogicalAddress, address, CEC_OPCODE_FEATURE_ABORT); | |
9dee1670 LOK |
293 | command.parameters.push_back((uint8_t)opcode); |
294 | command.parameters.push_back((uint8_t)reason); | |
295 | ||
296 | Transmit(command); | |
abbca718 LOK |
297 | } |
298 | ||
2abe74eb | 299 | void CCECProcessor::ReportCECVersion(cec_logical_address address /* = CECDEVICE_TV */) |
abbca718 | 300 | { |
88f45c9b | 301 | m_controller->AddLog(CEC_LOG_NOTICE, "<< reporting CEC version as 1.3a"); |
9dee1670 | 302 | |
06a1f7ce LOK |
303 | cec_command command; |
304 | cec_command::format(command, m_iLogicalAddress, address, CEC_OPCODE_CEC_VERSION); | |
9dee1670 LOK |
305 | command.parameters.push_back(CEC_VERSION_1_3A); |
306 | ||
307 | Transmit(command); | |
abbca718 LOK |
308 | } |
309 | ||
2abe74eb | 310 | void CCECProcessor::ReportPowerState(cec_logical_address address /*= CECDEVICE_TV */, bool bOn /* = true */) |
abbca718 | 311 | { |
abbca718 | 312 | if (bOn) |
88f45c9b | 313 | m_controller->AddLog(CEC_LOG_NOTICE, "<< reporting \"On\" power status"); |
abbca718 | 314 | else |
88f45c9b | 315 | m_controller->AddLog(CEC_LOG_NOTICE, "<< reporting \"Off\" power status"); |
abbca718 | 316 | |
06a1f7ce LOK |
317 | cec_command command; |
318 | cec_command::format(command, m_iLogicalAddress, address, CEC_OPCODE_REPORT_POWER_STATUS); | |
9dee1670 LOK |
319 | command.parameters.push_back(bOn ? (uint8_t) CEC_POWER_STATUS_ON : (uint8_t) CEC_POWER_STATUS_STANDBY); |
320 | ||
321 | Transmit(command); | |
abbca718 LOK |
322 | } |
323 | ||
2abe74eb | 324 | void CCECProcessor::ReportMenuState(cec_logical_address address /* = CECDEVICE_TV */, bool bActive /* = true */) |
abbca718 | 325 | { |
abbca718 | 326 | if (bActive) |
88f45c9b | 327 | m_controller->AddLog(CEC_LOG_NOTICE, "<< reporting menu state as active"); |
abbca718 | 328 | else |
88f45c9b | 329 | m_controller->AddLog(CEC_LOG_NOTICE, "<< reporting menu state as inactive"); |
abbca718 | 330 | |
06a1f7ce LOK |
331 | cec_command command; |
332 | cec_command::format(command, m_iLogicalAddress, address, CEC_OPCODE_MENU_STATUS); | |
9dee1670 LOK |
333 | command.parameters.push_back(bActive ? (uint8_t) CEC_MENU_STATE_ACTIVATED : (uint8_t) CEC_MENU_STATE_DEACTIVATED); |
334 | ||
335 | Transmit(command); | |
abbca718 LOK |
336 | } |
337 | ||
2abe74eb | 338 | void CCECProcessor::ReportVendorID(cec_logical_address address /* = CECDEVICE_TV */) |
abbca718 | 339 | { |
88f45c9b | 340 | m_controller->AddLog(CEC_LOG_NOTICE, "<< vendor ID requested, feature abort"); |
abbca718 LOK |
341 | TransmitAbort(address, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID); |
342 | } | |
343 | ||
2abe74eb | 344 | void CCECProcessor::ReportOSDName(cec_logical_address address /* = CECDEVICE_TV */) |
abbca718 | 345 | { |
abbca718 LOK |
346 | const char *osdname = m_strDeviceName.c_str(); |
347 | CStdString strLog; | |
88f45c9b | 348 | strLog.Format("<< reporting OSD name as %s", osdname); |
2abe74eb | 349 | m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str()); |
abbca718 | 350 | |
06a1f7ce LOK |
351 | cec_command command; |
352 | cec_command::format(command, m_iLogicalAddress, address, CEC_OPCODE_SET_OSD_NAME); | |
9dee1670 LOK |
353 | for (unsigned int iPtr = 0; iPtr < strlen(osdname); iPtr++) |
354 | command.parameters.push_back(osdname[iPtr]); | |
abbca718 | 355 | |
9dee1670 | 356 | Transmit(command); |
abbca718 LOK |
357 | } |
358 | ||
2abe74eb | 359 | void CCECProcessor::ReportPhysicalAddress(void) |
abbca718 | 360 | { |
abbca718 | 361 | CStdString strLog; |
2492216a | 362 | strLog.Format("<< reporting physical address as %04x", m_iPhysicalAddress); |
2abe74eb | 363 | m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str()); |
9dee1670 | 364 | |
06a1f7ce LOK |
365 | cec_command command; |
366 | cec_command::format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_REPORT_PHYSICAL_ADDRESS); | |
2492216a LOK |
367 | command.parameters.push_back((uint8_t) ((m_iPhysicalAddress >> 8) & 0xFF)); |
368 | command.parameters.push_back((uint8_t) (m_iPhysicalAddress & 0xFF)); | |
4a75b661 | 369 | command.parameters.push_back((uint8_t) (CEC_DEVICE_TYPE_PLAYBACK_DEVICE)); |
9dee1670 LOK |
370 | |
371 | Transmit(command); | |
abbca718 LOK |
372 | } |
373 | ||
2abe74eb | 374 | void CCECProcessor::BroadcastActiveSource(void) |
abbca718 | 375 | { |
a6d4fc28 | 376 | m_controller->AddLog(CEC_LOG_NOTICE, "<< broadcasting active source"); |
abbca718 | 377 | |
06a1f7ce LOK |
378 | cec_command command; |
379 | cec_command::format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_ACTIVE_SOURCE); | |
2492216a LOK |
380 | command.parameters.push_back((uint8_t) ((m_iPhysicalAddress >> 8) & 0xFF)); |
381 | command.parameters.push_back((uint8_t) (m_iPhysicalAddress & 0xFF)); | |
9dee1670 LOK |
382 | |
383 | Transmit(command); | |
abbca718 LOK |
384 | } |
385 | ||
050df0f9 | 386 | bool CCECProcessor::WaitForAck(bool *bError, uint32_t iTimeout /* = 1000 */) |
abbca718 | 387 | { |
78e8010a | 388 | bool bTransmitSucceeded = false, bEom = false; |
050df0f9 | 389 | *bError = false; |
abbca718 LOK |
390 | |
391 | int64_t iNow = GetTimeMs(); | |
25701fa6 | 392 | int64_t iTargetTime = iNow + (uint64_t) iTimeout; |
abbca718 | 393 | |
78e8010a | 394 | while (!bTransmitSucceeded && !*bError && (iTimeout == 0 || iNow < iTargetTime)) |
abbca718 | 395 | { |
9dee1670 | 396 | cec_adapter_message msg; |
25701fa6 LOK |
397 | msg.clear(); |
398 | ||
06a1f7ce | 399 | if (!m_communication->Read(msg, iTimeout > 0 ? (int32_t)(iTargetTime - iNow) : 1000)) |
abbca718 | 400 | { |
abbca718 | 401 | iNow = GetTimeMs(); |
5d38b0b6 LOK |
402 | continue; |
403 | } | |
404 | ||
78e8010a | 405 | ParseMessage(msg, bError, &bTransmitSucceeded, &bEom, false); |
5d38b0b6 | 406 | iNow = GetTimeMs(); |
abbca718 LOK |
407 | } |
408 | ||
78e8010a | 409 | return bTransmitSucceeded && !*bError; |
abbca718 LOK |
410 | } |
411 | ||
78e8010a | 412 | void CCECProcessor::ParseMessage(cec_adapter_message &msg, bool *bError, bool *bTransmitSucceeded, bool *bEom, bool bProcessMessages /* = true */) |
abbca718 | 413 | { |
78e8010a LOK |
414 | *bError = false; |
415 | *bTransmitSucceeded = false; | |
416 | *bEom = false; | |
60fa4578 | 417 | |
a6b6469c | 418 | if (msg.empty()) |
78e8010a | 419 | return; |
abbca718 LOK |
420 | |
421 | CStdString logStr; | |
abbca718 | 422 | |
a6b6469c | 423 | switch(msg.message()) |
abbca718 LOK |
424 | { |
425 | case MSGCODE_NOTHING: | |
2abe74eb | 426 | m_controller->AddLog(CEC_LOG_DEBUG, "MSGCODE_NOTHING"); |
abbca718 LOK |
427 | break; |
428 | case MSGCODE_TIMEOUT_ERROR: | |
429 | case MSGCODE_HIGH_ERROR: | |
430 | case MSGCODE_LOW_ERROR: | |
431 | { | |
a6b6469c | 432 | if (msg.message() == MSGCODE_TIMEOUT_ERROR) |
abbca718 | 433 | logStr = "MSGCODE_TIMEOUT"; |
a6b6469c | 434 | else if (msg.message() == MSGCODE_HIGH_ERROR) |
abbca718 LOK |
435 | logStr = "MSGCODE_HIGH_ERROR"; |
436 | else | |
437 | logStr = "MSGCODE_LOW_ERROR"; | |
438 | ||
a6b6469c LOK |
439 | int iLine = (msg.size() >= 3) ? (msg[1] << 8) | (msg[2]) : 0; |
440 | uint32_t iTime = (msg.size() >= 7) ? (msg[3] << 24) | (msg[4] << 16) | (msg[5] << 8) | (msg[6]) : 0; | |
abbca718 LOK |
441 | logStr.AppendFormat(" line:%i", iLine); |
442 | logStr.AppendFormat(" time:%u", iTime); | |
2abe74eb | 443 | m_controller->AddLog(CEC_LOG_WARNING, logStr.c_str()); |
78e8010a | 444 | *bError = true; |
abbca718 LOK |
445 | } |
446 | break; | |
447 | case MSGCODE_FRAME_START: | |
448 | { | |
78e8010a | 449 | if (bProcessMessages) |
abbca718 | 450 | { |
78e8010a LOK |
451 | logStr = "MSGCODE_FRAME_START"; |
452 | m_currentframe.clear(); | |
453 | if (msg.size() >= 2) | |
454 | { | |
455 | logStr.AppendFormat(" initiator:%u destination:%u ack:%s %s", msg.initiator(), msg.destination(), msg.ack() ? "high" : "low", msg.eom() ? "eom" : ""); | |
456 | m_currentframe.initiator = msg.initiator(); | |
457 | m_currentframe.destination = msg.destination(); | |
458 | m_currentframe.ack = msg.ack(); | |
459 | m_currentframe.eom = msg.eom(); | |
460 | } | |
461 | m_controller->AddLog(CEC_LOG_DEBUG, logStr.c_str()); | |
462 | } | |
463 | else | |
464 | { | |
465 | m_frameBuffer.Push(msg); | |
abbca718 | 466 | } |
abbca718 LOK |
467 | } |
468 | break; | |
469 | case MSGCODE_FRAME_DATA: | |
470 | { | |
78e8010a LOK |
471 | if (bProcessMessages) |
472 | { | |
473 | logStr = "MSGCODE_FRAME_DATA"; | |
474 | if (msg.size() >= 2) | |
475 | { | |
476 | uint8_t iData = msg[1]; | |
477 | logStr.AppendFormat(" %02x", iData); | |
478 | m_currentframe.push_back(iData); | |
479 | m_currentframe.eom = msg.eom(); | |
480 | } | |
481 | m_controller->AddLog(CEC_LOG_DEBUG, logStr.c_str()); | |
482 | } | |
483 | else | |
abbca718 | 484 | { |
78e8010a | 485 | m_frameBuffer.Push(msg); |
abbca718 | 486 | } |
78e8010a LOK |
487 | |
488 | *bEom = msg.eom(); | |
abbca718 | 489 | } |
78e8010a LOK |
490 | break; |
491 | case MSGCODE_COMMAND_ACCEPTED: | |
492 | m_controller->AddLog(CEC_LOG_DEBUG, "MSGCODE_COMMAND_ACCEPTED"); | |
493 | break; | |
494 | case MSGCODE_TRANSMIT_SUCCEEDED: | |
495 | m_controller->AddLog(CEC_LOG_DEBUG, "MSGCODE_TRANSMIT_SUCCEEDED"); | |
496 | *bTransmitSucceeded = true; | |
497 | break; | |
498 | case MSGCODE_RECEIVE_FAILED: | |
499 | m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_RECEIVE_FAILED"); | |
500 | *bError = true; | |
501 | break; | |
502 | case MSGCODE_COMMAND_REJECTED: | |
503 | m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_COMMAND_REJECTED"); | |
504 | *bError = true; | |
505 | break; | |
506 | case MSGCODE_TRANSMIT_FAILED_LINE: | |
507 | m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_LINE"); | |
508 | *bError = true; | |
509 | break; | |
510 | case MSGCODE_TRANSMIT_FAILED_ACK: | |
511 | m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_ACK"); | |
512 | *bError = true; | |
513 | break; | |
514 | case MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA: | |
515 | m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA"); | |
516 | *bError = true; | |
517 | break; | |
518 | case MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE: | |
519 | m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE"); | |
520 | *bError = true; | |
abbca718 LOK |
521 | break; |
522 | default: | |
523 | break; | |
524 | } | |
525 | } | |
526 | ||
9dee1670 | 527 | void CCECProcessor::ParseVendorId(cec_logical_address device, const cec_datapacket &data) |
5f150ee2 | 528 | { |
9dee1670 | 529 | if (data.size < 3) |
5f150ee2 LOK |
530 | { |
531 | m_controller->AddLog(CEC_LOG_WARNING, "invalid vendor ID received"); | |
532 | return; | |
533 | } | |
534 | ||
2cd8b5d0 LOK |
535 | uint64_t iVendorId = ((uint64_t)data[0] << 3) + |
536 | ((uint64_t)data[1] << 2) + | |
537 | (uint64_t)data[2]; | |
5f150ee2 | 538 | |
e9de9629 | 539 | m_busDevices[(uint8_t)device]->SetVendorId(iVendorId, data.size >= 4 ? data[3] : 0); |
5f150ee2 LOK |
540 | } |
541 | ||
e9de9629 | 542 | void CCECProcessor::ParseCommand(cec_command &command) |
abbca718 | 543 | { |
e9de9629 | 544 | CStdString dataStr; |
1d3ca3de | 545 | dataStr.Format(">> %1x%1x:%02x", command.initiator, command.destination, command.opcode); |
e9de9629 LOK |
546 | for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++) |
547 | dataStr.AppendFormat(":%02x", (unsigned int)command.parameters[iPtr]); | |
1d3ca3de | 548 | m_controller->AddLog(CEC_LOG_TRAFFIC, dataStr.c_str()); |
dc113aca | 549 | |
e9de9629 LOK |
550 | if (!m_bMonitor) |
551 | m_busDevices[(uint8_t)command.initiator]->HandleCommand(command); | |
dc113aca LOK |
552 | } |
553 | ||
e9de9629 | 554 | void CCECProcessor::SetCurrentButton(cec_user_control_code iButtonCode) |
dc113aca | 555 | { |
e9de9629 | 556 | m_controller->SetCurrentButton(iButtonCode); |
dc113aca LOK |
557 | } |
558 | ||
e9de9629 | 559 | void CCECProcessor::AddCommand(const cec_command &command) |
dc113aca | 560 | { |
e9de9629 | 561 | m_controller->AddCommand(command); |
dc113aca LOK |
562 | } |
563 | ||
e9de9629 | 564 | void CCECProcessor::AddKey(void) |
dc113aca | 565 | { |
e9de9629 | 566 | m_controller->AddKey(); |
abbca718 | 567 | } |
acec5f48 | 568 | |
e9de9629 | 569 | void CCECProcessor::AddLog(cec_log_level level, const CStdString &strMessage) |
acec5f48 | 570 | { |
e9de9629 | 571 | m_controller->AddLog(level, strMessage); |
acec5f48 | 572 | } |