11#include < cstring>
2+ #include < chrono>
23#include < memory>
3- #include " utils/simple_time.h"
44#include " protocol/haier_protocol.h"
55
66namespace haier_protocol
77{
88
99constexpr uint8_t MAX_PACKET_RETRIES = 9 ;
10- constexpr simple_time:: ms_t DEFAULT_ANSWER_TIMEOUT = 200 ;
11- constexpr simple_time:: ms_t DEFAULT_COOLDOWN_INTERVAL = 400 ;
10+ constexpr std::chrono::milliseconds DEFAULT_ANSWER_TIMEOUT = std::chrono::milliseconds( 200 ) ;
11+ constexpr std::chrono::milliseconds DEFAULT_COOLDOWN_INTERVAL = std::chrono::milliseconds( 400 ) ;
1212
1313#if HAIER_LOG_LEVEL > 3
14- static simple_time:: ms_t last_message_sent_;
14+ static std::chrono::steady_clock::time_point last_message_sent_;
1515#endif
1616
1717ProtocolHandler::ProtocolHandler (ProtocolStream &stream) noexcept : ProtocolHandler(stream, MAX_FRAME_SIZE + 10 )
@@ -34,14 +34,14 @@ ProtocolHandler::ProtocolHandler(ProtocolStream& stream, size_t buffer_size) noe
3434 answer_timeout_interval_(DEFAULT_ANSWER_TIMEOUT),
3535 cooldown_interval_(DEFAULT_COOLDOWN_INTERVAL)
3636{
37- this ->cooldown_time_point_ = simple_time::zero_ms ();
37+ this ->cooldown_time_point_ = std::chrono::steady_clock::time_point ();
3838}
3939
4040void ProtocolHandler::loop ()
4141{
4242 this ->transport_ .read_data ();
4343 this ->transport_ .process_data ();
44- simple_time:: ms_t now = simple_time::now_ms ();
44+ std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now ();
4545 switch (this ->state_ )
4646 {
4747 case ProtocolState::IDLE:
@@ -135,7 +135,7 @@ void ProtocolHandler::loop()
135135 if (this ->transport_ .available () > 0 )
136136 {
137137#if HAIER_LOG_LEVEL > 3
138- HAIER_LOGD (" Answer delay %dms" , ( int ) (now - last_message_sent_));
138+ HAIER_LOGD (" Answer delay %dms" , std::chrono::duration_cast<std::chrono::milliseconds> (now - last_message_sent_));
139139#endif
140140 TimestampedFrame frame;
141141 this ->transport_ .pop (frame);
@@ -175,7 +175,7 @@ bool ProtocolHandler::write_message_(const HaierMessage &message, bool use_crc)
175175 {
176176 HAIER_LOGE (" Error sending message: %02X" , frame_type);
177177 }
178- simple_time:: ms_t now = simple_time::now_ms ();
178+ std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now ();
179179#if HAIER_LOG_LEVEL > 3
180180 last_message_sent_ = now;
181181#endif
@@ -185,32 +185,32 @@ bool ProtocolHandler::write_message_(const HaierMessage &message, bool use_crc)
185185
186186void ProtocolHandler::set_answer_timeout (long long answer_timeout_miliseconds)
187187{
188- this ->set_answer_timeout (simple_time::ms_t (answer_timeout_miliseconds));
188+ this ->set_answer_timeout (std::chrono::milliseconds (answer_timeout_miliseconds));
189189}
190190
191- void ProtocolHandler::set_answer_timeout (simple_time:: ms_t answer_timeout)
191+ void ProtocolHandler::set_answer_timeout (std::chrono::milliseconds answer_timeout)
192192{
193193 this ->answer_timeout_interval_ = answer_timeout;
194194}
195195
196196void ProtocolHandler::set_cooldown_interval (long long answer_timeout_miliseconds)
197197{
198- this ->set_cooldown_interval (simple_time::ms_t (answer_timeout_miliseconds));
198+ this ->set_cooldown_interval (std::chrono::milliseconds (answer_timeout_miliseconds));
199199}
200200
201- void ProtocolHandler::set_cooldown_interval (simple_time:: ms_t answer_timeout)
201+ void ProtocolHandler::set_cooldown_interval (std::chrono::milliseconds answer_timeout)
202202{
203203 this ->cooldown_interval_ = answer_timeout;
204204}
205205
206- void ProtocolHandler::send_message (const HaierMessage& message, bool use_crc, uint8_t num_repeats, simple_time:: ms_t interval)
206+ void ProtocolHandler::send_message (const HaierMessage& message, bool use_crc, uint8_t num_repeats, std::chrono::milliseconds interval)
207207{
208208 this ->outgoing_messages_ .push ({ message, use_crc, false , std::min (num_repeats, MAX_PACKET_RETRIES) + 1 , interval });
209209}
210210
211211void ProtocolHandler::send_message_without_answer (const HaierMessage& message, bool use_crc)
212212{
213- this ->outgoing_messages_ .push ({ message, use_crc, true , 1 , simple_time::zero_ms () });
213+ this ->outgoing_messages_ .push ({ message, use_crc, true , 1 , std::chrono::milliseconds::zero () });
214214}
215215
216216void ProtocolHandler::send_answer (const HaierMessage &answer)
0 commit comments