timesync.h
Go to the documentation of this file.
1 //
2 // The MIT License (MIT)
3 //
4 // Copyright (c) 2019 Livox. All rights reserved.
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 // SOFTWARE.
23 //
24 
25 #ifndef TIMESYNC_TIMESYNC_H_
26 #define TIMESYNC_TIMESYNC_H_
27 
28 #include <thread>
29 #include "comm_device.h"
30 #include "comm_protocol.h"
31 #include "user_uart.h"
32 
33 namespace livox_ros {
34 
35 typedef void (*FnReceiveSyncTimeCb)(const char *rmc, uint32_t rmc_length,
36  void *client_data);
37 
39 
40 typedef struct {
44 
45 class TimeSync {
46  public:
47  static TimeSync *GetInstance() {
48  static TimeSync time_sync;
49 
50  return &time_sync;
51  }
52 
53  int32_t InitTimeSync(const TimeSyncConfig &config);
55  void StartTimesync() {
56  start_poll_state_ = true;
57  start_poll_data_ = true;
58  }
59 
61  if ((cb != nullptr) || (data != nullptr)) {
62  fn_cb_ = cb;
63  client_data_ = data;
64  return 0;
65  } else {
66  return -1;
67  }
68  }
69 
70  private:
71  TimeSync();
72  ~TimeSync();
73  TimeSync(const TimeSync &) = delete;
74  TimeSync &operator=(const TimeSync &) = delete;
75 
76  void PollStateLoop();
77  void PollDataLoop();
78  void StopTimesync();
79 
80  std::shared_ptr<std::thread> t_poll_state_;
81  volatile bool exit_poll_state_;
82  volatile bool start_poll_state_;
83 
84  std::shared_ptr<std::thread> t_poll_data_;
85  volatile bool exit_poll_data_;
86  volatile bool start_poll_data_;
87 
91  volatile uint32_t rx_bytes_;
92 
94  void *client_data_;
95 
96  volatile uint8_t fsm_state_;
97  std::chrono::steady_clock::time_point transfer_time_;
98  void FsmTransferState(uint8_t new_state);
99  void FsmOpenDev();
100  void FsmPrepareDev();
101  void FsmCheckDevState();
102 };
103 
104 } // namespace livox_ros
105 #endif
FsmPollState
Definition: timesync.h:38
int32_t InitTimeSync(const TimeSyncConfig &config)
Definition: timesync.cpp:52
void FsmTransferState(uint8_t new_state)
Definition: timesync.cpp:155
volatile bool exit_poll_data_
Definition: timesync.h:85
void(* FnReceiveSyncTimeCb)(const char *rmc, uint32_t rmc_length, void *client_data)
Definition: timesync.h:35
void StartTimesync()
Definition: timesync.h:55
std::shared_ptr< std::thread > t_poll_state_
Definition: timesync.h:80
static TimeSync * GetInstance()
Definition: timesync.h:47
volatile uint8_t fsm_state_
Definition: timesync.h:96
std::chrono::steady_clock::time_point transfer_time_
Definition: timesync.h:97
unsigned char uint8_t
Definition: stdint.h:125
CommProtocol * comm_
Definition: timesync.h:90
int32_t DeInitTimeSync()
Definition: timesync.cpp:81
ProtocolConfig protocol_config
Definition: timesync.h:42
volatile uint32_t rx_bytes_
Definition: timesync.h:91
unsigned int uint32_t
Definition: stdint.h:127
std::shared_ptr< std::thread > t_poll_data_
Definition: timesync.h:84
volatile bool start_poll_state_
Definition: timesync.h:82
TimeSync & operator=(const TimeSync &)=delete
CommDevConfig dev_config
Definition: timesync.h:41
volatile bool exit_poll_state_
Definition: timesync.h:81
void * client_data_
Definition: timesync.h:94
int32_t SetReceiveSyncTimeCb(FnReceiveSyncTimeCb cb, void *data)
Definition: timesync.h:60
signed int int32_t
Definition: stdint.h:124
TimeSyncConfig config_
Definition: timesync.h:88
UserUart * uart_
Definition: timesync.h:89
volatile bool start_poll_data_
Definition: timesync.h:86
FnReceiveSyncTimeCb fn_cb_
Definition: timesync.h:93


livox_ros_driver
Author(s): Livox Dev Team
autogenerated on Mon Mar 15 2021 02:40:46