2 * This file is part of the libCEC(R) library.
4 * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
5 * libCEC(R) is an original work, containing original code.
7 * libCEC(R) is a trademark of Pulse-Eight Limited.
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.
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.
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.
24 * Alternatively, you can license this library under a commercial license,
25 * please contact Pulse-Eight Licensing for more information.
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/
33 #include "CECParser.h"
40 #include "util/StdString.h"
41 #include "libPlatform/serialport.h"
42 #include "util/threads.h"
43 #include "util/timeutils.h"
44 #include "CECDetect.h"
49 #define CEC_MAX_RETRY 5
52 * ICECDevice implementation
55 CCECParser::CCECParser(const char *strDeviceName
) :
59 m_iCurrentButton(CEC_USER_CONTROL_CODE_UNKNOWN
),
60 m_physicaladdress(CEC_DEFAULT_PHYSICAL_ADDRESS
),
61 m_iLogicalAddress(CECDEVICE_PLAYBACKDEVICE1
),
62 m_strDeviceName(strDeviceName
),
65 m_serialport
= new CSerialPort
;
68 CCECParser::~CCECParser(void)
71 pthread_join(m_thread
, NULL
);
72 m_serialport
->Close();
76 bool CCECParser::Open(const char *strPort
, int iTimeoutMs
/* = 10000 */)
80 if (!(bReturn
= m_serialport
->Open(strPort
, 38400)))
83 strError
.Format("error opening serial port '%s': %s", strPort
, m_serialport
->GetError().c_str());
84 AddLog(CEC_LOG_ERROR
, strError
);
88 //clear any input bytes
90 m_serialport
->Read(buff
, sizeof(buff
), CEC_SETTLE_DOWN_TIME
);
93 bReturn
= SetAckMask(m_iLogicalAddress
);
98 strError
.Format("error opening serial port '%s': %s", strPort
, m_serialport
->GetError().c_str());
99 AddLog(CEC_LOG_ERROR
, strError
);
106 if (pthread_create(&m_thread
, NULL
, (void *(*) (void *))&CCECParser::ThreadHandler
, (void *)this) == 0)
107 pthread_detach(m_thread
);
115 void *CCECParser::ThreadHandler(CCECParser
*parser
)
122 bool CCECParser::Process(void)
124 int64_t now
= GetTimeMs();
128 CLockObject
lock(&m_mutex
, 1000);
131 if (!ReadFromDevice(100))
139 //AddLog(CEC_LOG_DEBUG, "processing messages");
142 CheckKeypressTimeout(now
);
143 CCondition::Sleep(50);
146 AddLog(CEC_LOG_DEBUG
, "reader thread terminated");
151 bool CCECParser::Ping(void)
153 AddLog(CEC_LOG_DEBUG
, "sending ping");
155 output
.push_back(MSGSTART
);
156 PushEscaped(output
, MSGCODE_PING
);
157 output
.push_back(MSGEND
);
159 if (!TransmitFormatted(output
, false, (int64_t) 5000))
161 AddLog(CEC_LOG_ERROR
, "could not send ping command");
165 AddLog(CEC_LOG_DEBUG
, "ping tranmitted");
167 // TODO check for pong
171 bool CCECParser::StartBootloader(void)
173 AddLog(CEC_LOG_DEBUG
, "starting the bootloader");
175 output
.push_back(MSGSTART
);
176 PushEscaped(output
, MSGCODE_START_BOOTLOADER
);
177 output
.push_back(MSGEND
);
179 if (!TransmitFormatted(output
, false, (int64_t) 5000))
181 AddLog(CEC_LOG_ERROR
, "could not start the bootloader");
185 AddLog(CEC_LOG_DEBUG
, "bootloader start command transmitted");
189 uint8_t CCECParser::GetSourceDestination(cec_logical_address destination
/* = CECDEVICE_BROADCAST */)
191 return ((uint8_t)m_iLogicalAddress
<< 4) + (uint8_t)destination
;
194 bool CCECParser::PowerOffDevices(cec_logical_address address
/* = CECDEVICE_BROADCAST */)
197 strLog
.Format("powering off devices with logical address %d", (int8_t)address
);
198 AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
200 frame
.push_back(GetSourceDestination(address
));
201 frame
.push_back(CEC_OPCODE_STANDBY
);
202 return Transmit(frame
);
205 bool CCECParser::PowerOnDevices(cec_logical_address address
/* = CECDEVICE_BROADCAST */)
208 strLog
.Format("powering on devices with logical address %d", (int8_t)address
);
209 AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
211 frame
.push_back(GetSourceDestination(address
));
212 frame
.push_back(CEC_OPCODE_TEXT_VIEW_ON
);
213 return Transmit(frame
);
216 bool CCECParser::StandbyDevices(cec_logical_address address
/* = CECDEVICE_BROADCAST */)
219 strLog
.Format("putting all devices with logical address %d in standby mode", (int8_t)address
);
220 AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
222 frame
.push_back(GetSourceDestination(address
));
223 frame
.push_back(CEC_OPCODE_STANDBY
);
224 return Transmit(frame
);
227 bool CCECParser::SetActiveView(void)
229 AddLog(CEC_LOG_DEBUG
, "setting active view");
231 frame
.push_back(GetSourceDestination(CECDEVICE_BROADCAST
));
232 frame
.push_back(CEC_OPCODE_ACTIVE_SOURCE
);
233 frame
.push_back((m_physicaladdress
>> 8) & 0xFF);
234 frame
.push_back(m_physicaladdress
& 0xFF);
235 return Transmit(frame
);
238 bool CCECParser::SetInactiveView(void)
240 AddLog(CEC_LOG_DEBUG
, "setting inactive view");
242 frame
.push_back(GetSourceDestination(CECDEVICE_BROADCAST
));
243 frame
.push_back(CEC_OPCODE_INACTIVE_SOURCE
);
244 frame
.push_back((m_physicaladdress
>> 8) & 0xFF);
245 frame
.push_back(m_physicaladdress
& 0xFF);
246 return Transmit(frame
);
249 bool CCECParser::GetNextLogMessage(cec_log_message
*message
)
251 return m_logBuffer
.Pop(*message
);
254 bool CCECParser::GetNextKeypress(cec_keypress
*key
)
256 return m_keyBuffer
.Pop(*key
);
260 void CCECParser::TransmitAbort(cec_logical_address address
, ECecOpcode opcode
, ECecAbortReason reason
/* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */)
262 AddLog(CEC_LOG_DEBUG
, "transmitting abort message");
264 frame
.push_back(GetSourceDestination(address
));
265 frame
.push_back(CEC_OPCODE_FEATURE_ABORT
);
266 frame
.push_back(opcode
);
267 frame
.push_back(reason
);
271 void CCECParser::ReportCECVersion(cec_logical_address address
/* = CECDEVICE_TV */)
274 AddLog(CEC_LOG_NOTICE
, "reporting CEC version as 1.3a");
275 frame
.push_back(GetSourceDestination(address
));
276 frame
.push_back(CEC_OPCODE_CEC_VERSION
);
277 frame
.push_back(CEC_VERSION_1_3A
);
281 void CCECParser::ReportPowerState(cec_logical_address address
/*= CECDEVICE_TV */, bool bOn
/* = true */)
285 AddLog(CEC_LOG_NOTICE
, "reporting \"On\" power status");
287 AddLog(CEC_LOG_NOTICE
, "reporting \"Off\" power status");
289 frame
.push_back(GetSourceDestination(address
));
290 frame
.push_back(CEC_OPCODE_REPORT_POWER_STATUS
);
291 frame
.push_back(bOn
? CEC_POWER_STATUS_ON
: CEC_POWER_STATUS_STANDBY
);
295 void CCECParser::ReportMenuState(cec_logical_address address
/* = CECDEVICE_TV */, bool bActive
/* = true */)
299 AddLog(CEC_LOG_NOTICE
, "reporting menu state as active");
301 AddLog(CEC_LOG_NOTICE
, "reporting menu state as inactive");
303 frame
.push_back(GetSourceDestination(address
));
304 frame
.push_back(CEC_OPCODE_MENU_STATUS
);
305 frame
.push_back(bActive
? CEC_MENU_STATE_ACTIVATED
: CEC_MENU_STATE_DEACTIVATED
);
309 void CCECParser::ReportVendorID(cec_logical_address address
/* = CECDEVICE_TV */)
311 AddLog(CEC_LOG_NOTICE
, "vendor ID requested, feature abort");
312 TransmitAbort(address
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
);
315 void CCECParser::ReportOSDName(cec_logical_address address
/* = CECDEVICE_TV */)
318 const char *osdname
= m_strDeviceName
.c_str();
320 strLog
.Format("reporting OSD name as %s", osdname
);
321 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
322 frame
.push_back(GetSourceDestination(address
));
323 frame
.push_back(CEC_OPCODE_SET_OSD_NAME
);
325 for (unsigned int i
= 0; i
< strlen(osdname
); i
++)
326 frame
.push_back(osdname
[i
]);
331 void CCECParser::ReportPhysicalAddress(void)
335 strLog
.Format("reporting physical address as %04x", m_physicaladdress
);
336 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
337 frame
.push_back(GetSourceDestination(CECDEVICE_BROADCAST
));
338 frame
.push_back(CEC_OPCODE_REPORT_PHYSICAL_ADDRESS
);
339 frame
.push_back((m_physicaladdress
>> 8) & 0xFF);
340 frame
.push_back(m_physicaladdress
& 0xFF);
341 frame
.push_back(CEC_DEVICE_TYPE_PLAYBACK_DEVICE
);
345 void CCECParser::BroadcastActiveSource(void)
348 AddLog(CEC_LOG_NOTICE
, "broadcasting active source");
349 frame
.push_back(GetSourceDestination(CECDEVICE_BROADCAST
));
350 frame
.push_back(CEC_OPCODE_ACTIVE_SOURCE
);
351 frame
.push_back((m_physicaladdress
>> 8) & 0xFF);
352 frame
.push_back(m_physicaladdress
& 0xFF);
356 bool CCECParser::TransmitFormatted(const cec_frame
&data
, bool bWaitForAck
/* = true */, int64_t iTimeout
/* = 2000 */)
358 CLockObject
lock(&m_mutex
, iTimeout
);
359 if (!lock
.IsLocked())
361 AddLog(CEC_LOG_ERROR
, "could not get a write lock");
365 if (m_serialport
->Write(data
) != data
.size())
368 strError
.Format("error writing to serial port: %s", m_serialport
->GetError().c_str());
369 AddLog(CEC_LOG_ERROR
, strError
);
372 AddLog(CEC_LOG_DEBUG
, "command sent");
374 CCondition::Sleep((int) data
.size() * 24 /*data*/ + 5 /*start bit (4.5 ms)*/ + 50 /* to be on the safe side */);
375 if (bWaitForAck
&& !WaitForAck())
377 AddLog(CEC_LOG_DEBUG
, "did not receive ACK");
384 bool CCECParser::Transmit(const cec_frame
&data
, bool bWaitForAck
/* = true */, int64_t iTimeout
/* = 5000 */)
386 CStdString txStr
= "transmit ";
387 for (unsigned int i
= 0; i
< data
.size(); i
++)
388 txStr
.AppendFormat(" %02x", data
[i
]);
389 AddLog(CEC_LOG_DEBUG
, txStr
.c_str());
393 AddLog(CEC_LOG_WARNING
, "transmit buffer is empty");
399 //set ack polarity to high when transmitting to the broadcast address
400 //set ack polarity low when transmitting to any other address
401 output
.push_back(MSGSTART
);
402 PushEscaped(output
, MSGCODE_TRANSMIT_ACK_POLARITY
);
404 if ((data
[0] & 0xF) == 0xF)
405 PushEscaped(output
, CEC_TRUE
);
407 PushEscaped(output
, CEC_FALSE
);
409 output
.push_back(MSGEND
);
411 for (unsigned int i
= 0; i
< data
.size(); i
++)
413 output
.push_back(MSGSTART
);
415 if (i
== data
.size() - 1)
416 PushEscaped(output
, MSGCODE_TRANSMIT_EOM
);
418 PushEscaped(output
, MSGCODE_TRANSMIT
);
420 PushEscaped(output
, data
[i
]);
422 output
.push_back(MSGEND
);
425 return TransmitFormatted(output
, bWaitForAck
, iTimeout
);
428 bool CCECParser::WaitForAck(int64_t iTimeout
/* = 1000 */)
433 int64_t iNow
= GetTimeMs();
434 int64_t iTargetTime
= iNow
+ iTimeout
;
436 while (!bGotAck
&& !bError
&& (iTimeout
<= 0 || iNow
< iTargetTime
))
438 if (!ReadFromDevice((int) iTimeout
))
440 AddLog(CEC_LOG_ERROR
, "failed to read from device");
445 while (!bGotAck
&& !bError
&& GetMessage(msg
, false))
447 uint8_t iCode
= msg
[0] & ~(MSGCODE_FRAME_EOM
| MSGCODE_FRAME_ACK
);
451 case MSGCODE_COMMAND_ACCEPTED
:
452 AddLog(CEC_LOG_DEBUG
, "MSGCODE_COMMAND_ACCEPTED");
454 case MSGCODE_TRANSMIT_SUCCEEDED
:
455 AddLog(CEC_LOG_DEBUG
, "MSGCODE_TRANSMIT_SUCCEEDED");
459 case MSGCODE_RECEIVE_FAILED
:
460 AddLog(CEC_LOG_WARNING
, "MSGCODE_RECEIVE_FAILED");
463 case MSGCODE_COMMAND_REJECTED
:
464 AddLog(CEC_LOG_WARNING
, "MSGCODE_COMMAND_REJECTED");
467 case MSGCODE_TRANSMIT_FAILED_LINE
:
468 AddLog(CEC_LOG_WARNING
, "MSGCODE_TRANSMIT_FAILED_LINE");
471 case MSGCODE_TRANSMIT_FAILED_ACK
:
472 AddLog(CEC_LOG_WARNING
, "MSGCODE_TRANSMIT_FAILED_ACK");
475 case MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA
:
476 AddLog(CEC_LOG_WARNING
, "MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA");
479 case MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE
:
480 AddLog(CEC_LOG_WARNING
, "MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE");
484 m_frameBuffer
.Push(msg
);
485 bGotAck
= (msg
[0] & MSGCODE_FRAME_ACK
) != 0;
492 return bGotAck
&& !bError
;
495 bool CCECParser::ReadFromDevice(int iTimeout
)
498 int iBytesRead
= m_serialport
->Read(buff
, sizeof(buff
), iTimeout
);
502 strError
.Format("error reading from serial port: %s", m_serialport
->GetError().c_str());
503 AddLog(CEC_LOG_ERROR
, strError
);
506 else if (iBytesRead
> 0)
507 AddData(buff
, iBytesRead
);
512 void CCECParser::ProcessMessages(void)
515 while (GetMessage(msg
))
519 bool CCECParser::GetMessage(cec_frame
&msg
, bool bFromBuffer
/* = true */)
521 if (bFromBuffer
&& m_frameBuffer
.Pop(msg
))
524 if (m_iInbufUsed
< 1)
527 //search for first start of message
529 for (int i
= 0; i
< m_iInbufUsed
; i
++)
531 if (m_inbuf
[i
] == MSGSTART
)
541 //move anything from the first start of message to the beginning of the buffer
544 memmove(m_inbuf
, m_inbuf
+ startpos
, m_iInbufUsed
- startpos
);
545 m_iInbufUsed
-= startpos
;
548 if (m_iInbufUsed
< 2)
551 //look for end of message
554 for (int i
= 1; i
< m_iInbufUsed
; i
++)
556 if (m_inbuf
[i
] == MSGEND
)
561 else if (m_inbuf
[i
] == MSGSTART
)
568 if (startpos
> 0) //we found a msgstart before msgend, this is not right, remove
570 AddLog(CEC_LOG_ERROR
, "received MSGSTART before MSGEND");
571 memmove(m_inbuf
, m_inbuf
+ startpos
, m_iInbufUsed
- startpos
);
572 m_iInbufUsed
-= startpos
;
576 if (endpos
> 0) //found a MSGEND
580 for (int i
= 1; i
< endpos
; i
++)
584 msg
.push_back(m_inbuf
[i
] + (uint8_t)ESCOFFSET
);
587 else if (m_inbuf
[i
] == MSGESC
)
593 msg
.push_back(m_inbuf
[i
]);
597 if (endpos
+ 1 < m_iInbufUsed
)
598 memmove(m_inbuf
, m_inbuf
+ endpos
+ 1, m_iInbufUsed
- endpos
- 1);
600 m_iInbufUsed
-= endpos
+ 1;
608 void CCECParser::ParseMessage(cec_frame
&msg
)
614 uint8_t iCode
= msg
[0] & ~(MSGCODE_FRAME_EOM
| MSGCODE_FRAME_ACK
);
615 bool bEom
= (msg
[0] & MSGCODE_FRAME_EOM
) != 0;
616 bool bAck
= (msg
[0] & MSGCODE_FRAME_ACK
) != 0;
620 case MSGCODE_NOTHING
:
621 AddLog(CEC_LOG_DEBUG
, "MSGCODE_NOTHING");
623 case MSGCODE_TIMEOUT_ERROR
:
624 case MSGCODE_HIGH_ERROR
:
625 case MSGCODE_LOW_ERROR
:
627 if (iCode
== MSGCODE_TIMEOUT_ERROR
)
628 logStr
= "MSGCODE_TIMEOUT";
629 else if (iCode
== MSGCODE_HIGH_ERROR
)
630 logStr
= "MSGCODE_HIGH_ERROR";
632 logStr
= "MSGCODE_LOW_ERROR";
634 int iLine
= (msg
.size() >= 3) ? (msg
[1] << 8) | (msg
[2]) : 0;
635 uint32_t iTime
= (msg
.size() >= 7) ? (msg
[3] << 24) | (msg
[4] << 16) | (msg
[5] << 8) | (msg
[6]) : 0;
636 logStr
.AppendFormat(" line:%i", iLine
);
637 logStr
.AppendFormat(" time:%u", iTime
);
638 AddLog(CEC_LOG_WARNING
, logStr
.c_str());
641 case MSGCODE_FRAME_START
:
643 logStr
= "MSGCODE_FRAME_START";
644 m_currentframe
.clear();
647 int iInitiator
= msg
[1] >> 4;
648 int iDestination
= msg
[1] & 0xF;
649 logStr
.AppendFormat(" initiator:%u destination:%u ack:%s %s", iInitiator
, iDestination
, bAck
? "high" : "low", bEom
? "eom" : "");
651 m_currentframe
.push_back(msg
[1]);
653 AddLog(CEC_LOG_DEBUG
, logStr
.c_str());
656 case MSGCODE_FRAME_DATA
:
658 logStr
= "MSGCODE_FRAME_DATA";
661 uint8_t iData
= msg
[1];
662 logStr
.AppendFormat(" %02x", iData
);
663 m_currentframe
.push_back(iData
);
665 AddLog(CEC_LOG_DEBUG
, logStr
.c_str());
675 void CCECParser::ParseCurrentFrame(void)
677 uint8_t initiator
= m_currentframe
[0] >> 4;
678 uint8_t destination
= m_currentframe
[0] & 0xF;
681 dataStr
.Format("received frame: initiator: %u destination: %u", initiator
, destination
);
683 if (m_currentframe
.size() > 1)
686 for (unsigned int i
= 1; i
< m_currentframe
.size(); i
++)
687 dataStr
.AppendFormat(" %02x", m_currentframe
[i
]);
689 AddLog(CEC_LOG_DEBUG
, dataStr
.c_str());
691 if (m_currentframe
.size() <= 1)
695 ECecOpcode opCode
= (ECecOpcode
) m_currentframe
[1];
696 if (destination
== (uint16_t) m_iLogicalAddress
)
700 case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS
:
701 ReportPhysicalAddress();
704 case CEC_OPCODE_GIVE_OSD_NAME
:
705 ReportOSDName((cec_logical_address
)initiator
);
707 case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
:
708 ReportVendorID((cec_logical_address
)initiator
);
710 case CEC_OPCODE_MENU_REQUEST
:
711 ReportMenuState((cec_logical_address
)initiator
);
713 case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
:
714 ReportPowerState((cec_logical_address
)initiator
);
716 case CEC_OPCODE_GET_CEC_VERSION
:
717 ReportCECVersion((cec_logical_address
)initiator
);
719 case CEC_OPCODE_USER_CONTROL_PRESSED
:
720 if (m_currentframe
.size() > 2)
724 if (m_currentframe
[2] <= CEC_USER_CONTROL_CODE_MAX
)
726 m_iCurrentButton
= (cec_user_control_code
) m_currentframe
[2];
727 m_buttontime
= GetTimeMs();
731 case CEC_OPCODE_USER_CONTROL_RELEASE
:
738 else if (destination
== (uint8_t) CECDEVICE_BROADCAST
)
740 if (opCode
== CEC_OPCODE_REQUEST_ACTIVE_SOURCE
)
742 BroadcastActiveSource();
744 else if (opCode
== CEC_OPCODE_SET_STREAM_PATH
)
746 if (m_currentframe
.size() >= 4)
748 int streamaddr
= ((int)m_currentframe
[2] << 8) | ((int)m_currentframe
[3]);
750 strLog
.Format("%i requests stream path from physical address %04x", initiator
, streamaddr
);
751 AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
752 if (streamaddr
== m_physicaladdress
)
753 BroadcastActiveSource();
760 strLog
.Format("ignoring frame: destination: %u != %u", destination
, (uint16_t)m_iLogicalAddress
);
761 AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
765 void CCECParser::AddData(uint8_t *data
, int iLen
)
767 if (iLen
+ m_iInbufUsed
> m_iInbufSize
)
769 m_iInbufSize
= iLen
+ m_iInbufUsed
;
770 m_inbuf
= (uint8_t*)realloc(m_inbuf
, m_iInbufSize
);
773 memcpy(m_inbuf
+ m_iInbufUsed
, data
, iLen
);
774 m_iInbufUsed
+= iLen
;
777 void CCECParser::PushEscaped(cec_frame
&vec
, uint8_t byte
)
779 if (byte
>= MSGESC
&& byte
!= MSGSTART
)
781 vec
.push_back(MSGESC
);
782 vec
.push_back(byte
- ESCOFFSET
);
790 void CCECParser::CheckKeypressTimeout(int64_t now
)
792 if (m_iCurrentButton
!= CEC_USER_CONTROL_CODE_UNKNOWN
&& now
- m_buttontime
> 500)
795 m_iCurrentButton
= CEC_USER_CONTROL_CODE_UNKNOWN
;
799 bool CCECParser::SetAckMask(cec_logical_address ackmask
)
802 strLog
.Format("setting ackmask to %d", (uint16_t) ackmask
);
803 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
806 m_iLogicalAddress
= ackmask
;
807 output
.push_back(MSGSTART
);
809 PushEscaped(output
, MSGCODE_SET_ACK_MASK
);
810 PushEscaped(output
, (uint8_t) ackmask
>> 8);
811 PushEscaped(output
, (uint8_t) ackmask
<< 2);
813 output
.push_back(MSGEND
);
815 if (m_serialport
->Write(output
) == -1)
818 strDebug
.Format("error writing to serial port: %s", m_serialport
->GetError().c_str());
819 AddLog(CEC_LOG_ERROR
, strDebug
);
826 void CCECParser::AddLog(cec_log_level level
, const string
&strMessage
)
828 cec_log_message message
;
829 message
.level
= level
;
830 message
.message
.assign(strMessage
.c_str());
831 m_logBuffer
.Push(message
);
834 void CCECParser::AddKey(void)
836 if (m_iCurrentButton
!= CEC_USER_CONTROL_CODE_UNKNOWN
)
839 key
.duration
= (unsigned int) (GetTimeMs() - m_buttontime
);
840 key
.keycode
= m_iCurrentButton
;
841 m_keyBuffer
.Push(key
);
842 m_iCurrentButton
= CEC_USER_CONTROL_CODE_UNKNOWN
;
847 int CCECParser::GetMinVersion(void)
849 return CEC_MIN_VERSION
;
852 int CCECParser::GetLibVersion(void)
854 return CEC_LIB_VERSION
;
857 int CCECParser::FindDevices(std::vector
<cec_device
> &deviceList
, const char *strDevicePath
/* = NULL */)
861 strDebug
.Format("trying to autodetect the com port for device path '%s'", strDevicePath
);
863 strDebug
.Format("trying to autodetect all CEC adapters");
864 AddLog(CEC_LOG_DEBUG
, strDebug
);
866 return CCECDetect::FindDevices(deviceList
, strDevicePath
);
869 DECLSPEC
void * CECCreate(const char *strDeviceName
)
871 return static_cast< void* > (new CCECParser(strDeviceName
));