2 * This file is part of the libCEC(R) library.
4 * libCEC(R) is Copyright (C) 2011-2012 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/
34 #include "USBCECAdapterCommunication.h"
36 #include "USBCECAdapterCommands.h"
37 #include "USBCECAdapterMessageQueue.h"
38 #include "USBCECAdapterMessage.h"
39 #include "USBCECAdapterDetection.h"
40 #include "lib/platform/sockets/serialport.h"
41 #include "lib/platform/util/timeutils.h"
42 #include "lib/platform/util/util.h"
43 #include "lib/platform/util/edid.h"
44 #include "lib/platform/adl/adl-edid.h"
45 #include "lib/platform/nvidia/nv-edid.h"
46 #include "lib/LibCEC.h"
47 #include "lib/CECProcessor.h"
51 using namespace PLATFORM
;
53 #define CEC_ADAPTER_PING_TIMEOUT 15000
54 #define CEC_ADAPTER_EEPROM_WRITE_INTERVAL 30000
55 #define CEC_ADAPTER_EEPROM_WRITE_RETRY 5000
58 #define CEC_LATEST_ADAPTER_FW_VERSION 2
59 // firmware date Thu Aug 2 08:31:24 UTC 2012
60 #define CEC_LATEST_ADAPTER_FW_DATE 0x501a4b0c
62 #define CEC_FW_DATE_EXTENDED_RESPONSE 0x501a4b0c
63 #define CEC_FW_DATE_DESCRIPTOR2 0x5045dbf5
65 #define LIB_CEC m_callback->GetLib()
67 CUSBCECAdapterCommunication::CUSBCECAdapterCommunication(IAdapterCommunicationCallback
*callback
, const char *strPort
, uint16_t iBaudRate
/* = CEC_SERIAL_DEFAULT_BAUDRATE */) :
68 IAdapterCommunication(callback
),
71 m_lastPollDestination(CECDEVICE_UNKNOWN
),
72 m_bInitialised(false),
74 m_eepromWriteThread(NULL
),
76 m_adapterMessageQueue(NULL
)
78 m_logicalAddresses
.Clear();
79 for (unsigned int iPtr
= CECDEVICE_TV
; iPtr
< CECDEVICE_BROADCAST
; iPtr
++)
80 m_bWaitingForAck
[iPtr
] = false;
81 m_port
= new CSerialPort(strPort
, iBaudRate
);
82 m_commands
= new CUSBCECAdapterCommands(this);
85 CUSBCECAdapterCommunication::~CUSBCECAdapterCommunication(void)
88 DELETE_AND_NULL(m_commands
);
89 DELETE_AND_NULL(m_adapterMessageQueue
);
90 DELETE_AND_NULL(m_port
);
93 void CUSBCECAdapterCommunication::ResetMessageQueue(void)
95 DELETE_AND_NULL(m_adapterMessageQueue
);
96 m_adapterMessageQueue
= new CCECAdapterMessageQueue(this);
97 m_adapterMessageQueue
->CreateThread();
100 bool CUSBCECAdapterCommunication::Open(uint32_t iTimeoutMs
/* = CEC_DEFAULT_CONNECT_TIMEOUT */, bool bSkipChecks
/* = false */, bool bStartListening
/* = true */)
102 bool bConnectionOpened(false);
104 CLockObject
lock(m_mutex
);
106 /* we need the port settings here */
109 LIB_CEC
->AddLog(CEC_LOG_ERROR
, "port is NULL");
110 return bConnectionOpened
;
113 /* return true when the port is already open */
116 LIB_CEC
->AddLog(CEC_LOG_WARNING
, "port is already open");
122 /* try to open the connection */
124 CTimeout
timeout(iTimeoutMs
);
125 while (!bConnectionOpened
&& timeout
.TimeLeft() > 0)
127 if ((bConnectionOpened
= m_port
->Open(timeout
.TimeLeft())) == false)
129 strError
.Format("error opening serial port '%s': %s", m_port
->GetName().c_str(), m_port
->GetError().c_str());
132 /* and retry every 250ms until the timeout passed */
135 /* return false when we couldn't connect */
136 if (!bConnectionOpened
)
138 LIB_CEC
->AddLog(CEC_LOG_ERROR
, strError
);
140 if (m_port
->GetErrorNumber() == EACCES
)
142 libcec_parameter param
;
143 param
.paramType
= CEC_PARAMETER_TYPE_STRING
;
144 param
.paramData
= (void*)"No permission to open the device";
145 LIB_CEC
->Alert(CEC_ALERT_PERMISSION_ERROR
, param
);
147 else if (m_port
->GetErrorNumber() == EBUSY
)
149 libcec_parameter param
;
150 param
.paramType
= CEC_PARAMETER_TYPE_STRING
;
151 param
.paramData
= (void*)"The serial port is busy. Only one program can access the device directly.";
152 LIB_CEC
->Alert(CEC_ALERT_PORT_BUSY
, param
);
157 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "connection opened, clearing any previous input and waiting for active transmissions to end before starting");
161 // always start by setting the ackmask to 0, to clear previous values
162 cec_logical_addresses addresses
; addresses
.Clear();
163 SetLogicalAddresses(addresses
);
167 bConnectionOpened
= false;
168 LIB_CEC
->AddLog(CEC_LOG_ERROR
, "could not create a communication thread");
170 else if (!bSkipChecks
&& !CheckAdapter())
172 bConnectionOpened
= false;
173 LIB_CEC
->AddLog(CEC_LOG_ERROR
, "the adapter failed to pass basic checks");
175 else if (bStartListening
)
177 /* start the eeprom write thread, that handles all eeprom writes async */
178 m_eepromWriteThread
= new CAdapterEepromWriteThread(this);
179 if (!m_eepromWriteThread
->CreateThread())
181 bConnectionOpened
= false;
182 LIB_CEC
->AddLog(CEC_LOG_ERROR
, "could not create the eeprom write thread");
186 /* start a ping thread, that will ping the adapter every 15 seconds
187 if it doesn't receive any ping for 30 seconds, it'll switch to auto mode */
188 m_pingThread
= new CAdapterPingThread(this, CEC_ADAPTER_PING_TIMEOUT
);
189 if (m_pingThread
->CreateThread())
191 bConnectionOpened
= true;
195 bConnectionOpened
= false;
196 LIB_CEC
->AddLog(CEC_LOG_ERROR
, "could not create a ping thread");
201 if (!bConnectionOpened
|| !bStartListening
)
204 return bConnectionOpened
;
207 void CUSBCECAdapterCommunication::Close(void)
209 /* stop the reader thread */
212 CLockObject
lock(m_mutex
);
214 /* set the ackmask to 0 before closing the connection */
215 if (IsOpen() && m_port
->GetErrorNumber() == 0)
217 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s - closing the connection", __FUNCTION__
);
218 cec_logical_addresses addresses
; addresses
.Clear();
219 SetLogicalAddresses(addresses
);
220 if (m_commands
->GetFirmwareVersion() >= 2)
221 SetControlledMode(false);
224 m_adapterMessageQueue
->Clear();
226 /* stop and delete the write thread */
227 if (m_eepromWriteThread
)
228 m_eepromWriteThread
->Stop();
229 DELETE_AND_NULL(m_eepromWriteThread
);
231 /* stop and delete the ping thread */
232 DELETE_AND_NULL(m_pingThread
);
234 /* close and delete the com port connection */
239 cec_adapter_message_state
CUSBCECAdapterCommunication::Write(const cec_command
&data
, bool &bRetry
, uint8_t iLineTimeout
, bool bIsReply
)
241 cec_adapter_message_state
retVal(ADAPTER_MESSAGE_STATE_UNKNOWN
);
245 CCECAdapterMessage
*output
= new CCECAdapterMessage(data
, iLineTimeout
);
246 output
->bFireAndForget
= bIsReply
;
248 /* mark as waiting for an ack from the destination */
249 MarkAsWaiting(data
.destination
);
251 /* send the message */
254 retVal
= m_adapterMessageQueue
->Write(output
) ?
255 ADAPTER_MESSAGE_STATE_WAITING_TO_BE_SENT
: ADAPTER_MESSAGE_STATE_ERROR
;
259 bRetry
= (!m_adapterMessageQueue
->Write(output
) || output
->NeedsRetry()) && output
->transmit_timeout
> 0;
261 Sleep(CEC_DEFAULT_TRANSMIT_RETRY_WAIT
);
262 retVal
= output
->state
;
269 void *CUSBCECAdapterCommunication::Process(void)
271 CCECAdapterMessage msg
;
272 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "communication thread started");
276 /* read from the serial port */
277 if (!ReadFromDevice(50, 5))
279 libcec_parameter param
;
280 param
.paramData
= NULL
; param
.paramType
= CEC_PARAMETER_TYPE_UNKOWN
;
281 LIB_CEC
->Alert(CEC_ALERT_CONNECTION_LOST
, param
);
286 /* TODO sleep 5 ms so other threads can get a lock */
290 m_adapterMessageQueue
->Clear();
291 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "communication thread ended");
295 bool CUSBCECAdapterCommunication::HandlePoll(const CCECAdapterMessage
&msg
)
297 bool bIsError(msg
.IsError());
298 cec_adapter_messagecode
messageCode(msg
.Message());
299 CLockObject
lock(m_mutex
);
301 if (messageCode
== MSGCODE_FRAME_START
&& msg
.IsACK())
303 m_lastPollDestination
= msg
.Destination();
304 if (msg
.Destination() < CECDEVICE_BROADCAST
)
306 if (!m_bWaitingForAck
[msg
.Destination()] && !msg
.IsEOM())
309 m_callback
->HandlePoll(msg
.Initiator(), msg
.Destination());
312 m_bWaitingForAck
[msg
.Destination()] = false;
315 else if (messageCode
== MSGCODE_RECEIVE_FAILED
)
317 /* hack to suppress warnings when an LG is polling */
318 if (m_lastPollDestination
!= CECDEVICE_UNKNOWN
)
319 bIsError
= m_callback
->HandleReceiveFailed(m_lastPollDestination
);
325 void CUSBCECAdapterCommunication::MarkAsWaiting(const cec_logical_address dest
)
327 /* mark as waiting for an ack from the destination */
328 if (dest
< CECDEVICE_BROADCAST
)
330 CLockObject
lock(m_mutex
);
331 m_bWaitingForAck
[dest
] = true;
335 void CUSBCECAdapterCommunication::ClearInputBytes(uint32_t iTimeout
/* = CEC_CLEAR_INPUT_DEFAULT_WAIT */)
337 CTimeout
timeout(iTimeout
);
339 ssize_t
iBytesRead(0);
340 bool bGotMsgEnd(true);
342 while (timeout
.TimeLeft() > 0 && ((iBytesRead
= m_port
->Read(buff
, 1024, 5)) > 0 || !bGotMsgEnd
))
345 /* if something was received, wait for MSGEND */
346 for (ssize_t iPtr
= 0; iPtr
< iBytesRead
; iPtr
++)
347 bGotMsgEnd
= buff
[iPtr
] == MSGEND
;
351 bool CUSBCECAdapterCommunication::SetLineTimeout(uint8_t iTimeout
)
354 bool bChanged(false);
356 /* only send the command if the timeout changed */
358 CLockObject
lock(m_mutex
);
359 bChanged
= (m_iLineTimeout
!= iTimeout
);
360 m_iLineTimeout
= iTimeout
;
364 bReturn
= m_commands
->SetLineTimeout(iTimeout
);
369 bool CUSBCECAdapterCommunication::WriteToDevice(CCECAdapterMessage
*message
)
371 CLockObject
adapterLock(m_mutex
);
374 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "error writing command '%s' to serial port '%s': the connection is closed", CCECAdapterMessage::ToString(message
->Message()), m_port
->GetName().c_str());
375 message
->state
= ADAPTER_MESSAGE_STATE_ERROR
;
379 /* write the message */
380 if (m_port
->Write(message
->packet
.data
, message
->Size()) != (ssize_t
) message
->Size())
382 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "error writing command '%s' to serial port '%s': %s", CCECAdapterMessage::ToString(message
->Message()), m_port
->GetName().c_str(), m_port
->GetError().c_str());
383 message
->state
= ADAPTER_MESSAGE_STATE_ERROR
;
384 // this will trigger an alert in the reader thread
390 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "command '%s' sent", message
->IsTranmission() ? "CEC transmission" : CCECAdapterMessage::ToString(message
->Message()));
392 message
->state
= ADAPTER_MESSAGE_STATE_SENT
;
396 bool CUSBCECAdapterCommunication::ReadFromDevice(uint32_t iTimeout
, size_t iSize
/* = 256 */)
398 ssize_t
iBytesRead(0);
403 /* read from the serial port */
405 CLockObject
lock(m_mutex
);
410 /* retry Read() if it was interrupted */
411 iBytesRead
= m_port
->Read(buff
, sizeof(uint8_t) * iSize
, iTimeout
);
412 } while(m_port
->GetErrorNumber() == EINTR
);
415 if (m_port
->GetErrorNumber())
417 LIB_CEC
->AddLog(CEC_LOG_ERROR
, "error reading from serial port: %s", m_port
->GetError().c_str());
423 if (iBytesRead
< 0 || iBytesRead
> 256)
425 else if (iBytesRead
> 0)
427 /* add the data to the current frame */
428 m_adapterMessageQueue
->AddData(buff
, iBytesRead
);
434 CCECAdapterMessage
*CUSBCECAdapterCommunication::SendCommand(cec_adapter_messagecode msgCode
, CCECAdapterMessage
¶ms
, bool bIsRetry
/* = false */)
436 if (!IsOpen() || !m_adapterMessageQueue
)
439 /* create the adapter message for this command */
440 CCECAdapterMessage
*output
= new CCECAdapterMessage
;
441 output
->PushBack(MSGSTART
);
442 output
->PushEscaped((uint8_t)msgCode
);
443 output
->Append(params
);
444 output
->PushBack(MSGEND
);
446 /* write the command */
447 if (!m_adapterMessageQueue
->Write(output
))
449 // this will trigger an alert in the reader thread
450 if (output
->state
== ADAPTER_MESSAGE_STATE_ERROR
)
456 if (!bIsRetry
&& output
->Reply() == MSGCODE_COMMAND_REJECTED
&& msgCode
!= MSGCODE_SET_CONTROLLED
&&
457 msgCode
!= MSGCODE_GET_BUILDDATE
/* same messagecode value had a different meaning in older fw builds */)
459 /* if the controller reported that the command was rejected, and we didn't send the command
460 to set controlled mode, then the controller probably switched to auto mode. set controlled
462 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "setting controlled mode and retrying");
464 if (SetControlledMode(true))
465 return SendCommand(msgCode
, params
, true);
472 bool CUSBCECAdapterCommunication::CheckAdapter(uint32_t iTimeoutMs
/* = CEC_DEFAULT_CONNECT_TIMEOUT */)
475 CTimeout
timeout(iTimeoutMs
> 0 ? iTimeoutMs
: CEC_DEFAULT_TRANSMIT_WAIT
);
477 /* try to ping the adapter */
479 unsigned iPingTry(0);
480 while (timeout
.TimeLeft() > 0 && (bPinged
= PingAdapter()) == false)
482 LIB_CEC
->AddLog(CEC_LOG_ERROR
, "the adapter did not respond correctly to a ping (try %d)", ++iPingTry
);
486 /* try to read the firmware version */
487 if (bPinged
&& timeout
.TimeLeft() > 0 && m_commands
->RequestFirmwareVersion() >= 2)
489 /* try to set controlled mode for v2+ firmwares */
490 unsigned iControlledTry(0);
491 bool bControlled(false);
492 while (timeout
.TimeLeft() > 0 && (bControlled
= SetControlledMode(true)) == false)
494 LIB_CEC
->AddLog(CEC_LOG_ERROR
, "the adapter did not respond correctly to setting controlled mode (try %d)", ++iControlledTry
);
497 bReturn
= bControlled
;
502 if (m_commands
->GetFirmwareVersion() >= 2)
504 /* try to read the build date */
505 m_commands
->RequestBuildDate();
507 /* try to read the adapter type */
508 m_commands
->RequestAdapterType();
511 SetInitialised(bReturn
);
515 bool CUSBCECAdapterCommunication::IsOpen(void)
517 /* thread is not being stopped, the port is open and the thread is running */
518 return !IsStopped() && m_port
->IsOpen() && IsRunning();
521 std::string
CUSBCECAdapterCommunication::GetError(void) const
523 return m_port
->GetError();
526 void CUSBCECAdapterCommunication::SetInitialised(bool bSetTo
/* = true */)
528 CLockObject
lock(m_mutex
);
529 m_bInitialised
= bSetTo
;
532 bool CUSBCECAdapterCommunication::IsInitialised(void)
534 CLockObject
lock(m_mutex
);
535 return m_bInitialised
;
538 bool CUSBCECAdapterCommunication::StartBootloader(void)
540 if (m_port
->IsOpen() && m_commands
->StartBootloader())
548 bool CUSBCECAdapterCommunication::SetLogicalAddresses(const cec_logical_addresses
&addresses
)
551 CLockObject
lock(m_mutex
);
552 if (m_logicalAddresses
== addresses
)
556 if (IsOpen() && m_commands
->SetAckMask(addresses
.AckMask()))
558 CLockObject
lock(m_mutex
);
559 m_logicalAddresses
= addresses
;
563 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "couldn't change the ackmask: the connection is closed");
567 cec_logical_addresses
CUSBCECAdapterCommunication::GetLogicalAddresses(void)
569 cec_logical_addresses addresses
;
570 CLockObject
lock(m_mutex
);
571 addresses
= m_logicalAddresses
;
575 bool CUSBCECAdapterCommunication::PingAdapter(void)
577 return IsOpen() ? m_commands
->PingAdapter() : false;
580 uint16_t CUSBCECAdapterCommunication::GetFirmwareVersion(void)
582 return m_commands
? m_commands
->GetFirmwareVersion() : CEC_FW_VERSION_UNKNOWN
;
585 uint32_t CUSBCECAdapterCommunication::GetFirmwareBuildDate(void)
587 uint32_t iBuildDate(0);
589 iBuildDate
= m_commands
->GetPersistedBuildDate();
590 if (iBuildDate
== 0 && IsOpen())
591 iBuildDate
= m_commands
->RequestBuildDate();
596 cec_adapter_type
CUSBCECAdapterCommunication::GetAdapterType(void)
598 cec_adapter_type
type(ADAPTERTYPE_UNKNOWN
);
600 type
= (cec_adapter_type
)m_commands
->GetPersistedAdapterType();
601 if (type
== ADAPTERTYPE_UNKNOWN
&& IsOpen())
602 type
= (cec_adapter_type
)m_commands
->RequestAdapterType();
607 bool CUSBCECAdapterCommunication::ProvidesExtendedResponse(void)
609 uint32_t iBuildDate(0);
611 iBuildDate
= m_commands
->GetPersistedBuildDate();
613 return iBuildDate
>= CEC_FW_DATE_EXTENDED_RESPONSE
;
616 uint16_t CUSBCECAdapterCommunication::GetAdapterVendorId(void) const
621 uint16_t CUSBCECAdapterCommunication::GetAdapterProductId(void) const
623 uint32_t iBuildDate(0);
625 iBuildDate
= m_commands
->GetPersistedBuildDate();
627 return iBuildDate
>= CEC_FW_DATE_DESCRIPTOR2
? CEC_PID2
: CEC_PID
;
630 bool CUSBCECAdapterCommunication::IsRunningLatestFirmware(void)
632 return GetFirmwareBuildDate() >= CEC_LATEST_ADAPTER_FW_DATE
&&
633 GetFirmwareVersion() >= CEC_LATEST_ADAPTER_FW_VERSION
;
636 bool CUSBCECAdapterCommunication::PersistConfiguration(const libcec_configuration
&configuration
)
639 m_commands
->PersistConfiguration(configuration
) && m_eepromWriteThread
->Write() :
643 bool CUSBCECAdapterCommunication::GetConfiguration(libcec_configuration
&configuration
)
645 return IsOpen() ? m_commands
->GetConfiguration(configuration
) : false;
648 std::string
CUSBCECAdapterCommunication::GetPortName(void)
650 return m_port
->GetName();
653 bool CUSBCECAdapterCommunication::SetControlledMode(bool controlled
)
655 return IsOpen() ? m_commands
->SetControlledMode(controlled
) : false;
658 uint16_t CUSBCECAdapterCommunication::GetPhysicalAddress(void)
662 // try to get the PA from ADL
663 #if defined(HAS_ADL_EDID_PARSER)
665 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s - trying to get the physical address via ADL", __FUNCTION__
);
667 iPA
= adl
.GetPhysicalAddress();
668 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s - ADL returned physical address %04x", __FUNCTION__
, iPA
);
672 // try to get the PA from the nvidia driver
673 #if defined(HAS_NVIDIA_EDID_PARSER)
676 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s - trying to get the physical address via nvidia driver", __FUNCTION__
);
678 iPA
= nv
.GetPhysicalAddress();
679 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s - nvidia driver returned physical address %04x", __FUNCTION__
, iPA
);
683 // try to get the PA from the OS
686 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s - trying to get the physical address from the OS", __FUNCTION__
);
687 iPA
= CEDIDParser::GetPhysicalAddress();
688 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "%s - OS returned physical address %04x", __FUNCTION__
, iPA
);
694 void *CAdapterPingThread::Process(void)
698 if (m_timeout
.TimeLeft() == 0)
700 /* reinit the timeout */
701 m_timeout
.Init(CEC_ADAPTER_PING_TIMEOUT
);
703 /* send a ping to the adapter */
705 int iFailedCounter(0);
706 while (!bPinged
&& iFailedCounter
< 3)
708 if (!m_com
->PingAdapter())
710 /* sleep and retry */
711 Sleep(CEC_DEFAULT_TRANSMIT_RETRY_WAIT
);
720 if (iFailedCounter
== 3)
722 /* failed to ping the adapter 3 times in a row. something must be wrong with the connection */
723 m_com
->LIB_CEC
->AddLog(CEC_LOG_ERROR
, "failed to ping the adapter 3 times in a row. closing the connection.");
724 m_com
->StopThread(false);
734 void CAdapterEepromWriteThread::Stop(void)
738 CLockObject
lock(m_mutex
);
739 if (m_iScheduleEepromWrite
> 0)
740 m_com
->LIB_CEC
->AddLog(CEC_LOG_WARNING
, "write thread stopped while a write was queued");
741 m_condition
.Signal();
746 void *CAdapterEepromWriteThread::Process(void)
750 CLockObject
lock(m_mutex
);
751 if ((m_iScheduleEepromWrite
> 0 && m_iScheduleEepromWrite
< GetTimeMs()) ||
752 m_condition
.Wait(m_mutex
, m_bWrite
, 100))
755 if (m_com
->m_commands
->WriteEEPROM())
757 m_iLastEepromWrite
= GetTimeMs();
758 m_iScheduleEepromWrite
= 0;
762 m_iScheduleEepromWrite
= GetTimeMs() + CEC_ADAPTER_EEPROM_WRITE_RETRY
;
769 bool CAdapterEepromWriteThread::Write(void)
771 CLockObject
lock(m_mutex
);
772 if (m_iScheduleEepromWrite
== 0)
774 int64_t iNow
= GetTimeMs();
775 if (m_iLastEepromWrite
+ CEC_ADAPTER_EEPROM_WRITE_INTERVAL
> iNow
)
777 m_com
->LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "delaying eeprom write by %ld ms", m_iLastEepromWrite
+ CEC_ADAPTER_EEPROM_WRITE_INTERVAL
- iNow
);
778 m_iScheduleEepromWrite
= m_iLastEepromWrite
+ CEC_ADAPTER_EEPROM_WRITE_INTERVAL
;
783 m_condition
.Signal();