feat:replace boost library with C++11 std library
This commit is contained in:
@@ -25,8 +25,8 @@
|
||||
#ifndef LIVOX_COMMAND_CALLBACK_H
|
||||
#define LIVOX_COMMAND_CALLBACK_H
|
||||
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/smart_ptr.hpp>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include "livox_sdk.h"
|
||||
|
||||
namespace livox {
|
||||
@@ -76,9 +76,9 @@ class MemberFunctionCallback<T, uint8_t> : public CommandCallback {
|
||||
};
|
||||
|
||||
template <class T, class ResponseType>
|
||||
boost::shared_ptr<CommandCallback> MakeCommandCallback(T *cls,
|
||||
std::shared_ptr<CommandCallback> MakeCommandCallback(T *cls,
|
||||
typename MemberFunctionCallback<T, ResponseType>::MemFn func) {
|
||||
boost::shared_ptr<CommandCallback> cb(new MemberFunctionCallback<T, ResponseType>(cls, func));
|
||||
std::shared_ptr<CommandCallback> cb(new MemberFunctionCallback<T, ResponseType>(cls, func));
|
||||
return cb;
|
||||
}
|
||||
|
||||
@@ -123,8 +123,8 @@ class FunctionStatusCallback<uint8_t> : public CommandCallback {
|
||||
};
|
||||
|
||||
template <class T>
|
||||
boost::shared_ptr<CommandCallback> MakeCommandCallback(typename FunctionStatusCallback<T>::Fn func, void *client_data) {
|
||||
boost::shared_ptr<CommandCallback> cb(new FunctionStatusCallback<T>(func, client_data));
|
||||
std::shared_ptr<CommandCallback> MakeCommandCallback(typename FunctionStatusCallback<T>::Fn func, void *client_data) {
|
||||
std::shared_ptr<CommandCallback> cb(new FunctionStatusCallback<T>(func, client_data));
|
||||
return cb;
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ class MessageCallback : public CommandCallback {
|
||||
template <class ResponseType>
|
||||
class BoostFunctionMessageCallback : public CommandCallback {
|
||||
public:
|
||||
typedef boost::function<void(livox_status, uint8_t, ResponseType *)> Fn;
|
||||
typedef std::function<void(livox_status, uint8_t, ResponseType *)> Fn;
|
||||
|
||||
public:
|
||||
BoostFunctionMessageCallback(const Fn &func) : func_(func) {}
|
||||
@@ -163,14 +163,14 @@ class BoostFunctionMessageCallback : public CommandCallback {
|
||||
};
|
||||
|
||||
template <class T>
|
||||
boost::shared_ptr<CommandCallback> MakeMessageCallback(typename MessageCallback<T>::Fn func) {
|
||||
boost::shared_ptr<CommandCallback> cb(new MessageCallback<T>(func));
|
||||
std::shared_ptr<CommandCallback> MakeMessageCallback(typename MessageCallback<T>::Fn func) {
|
||||
std::shared_ptr<CommandCallback> cb(new MessageCallback<T>(func));
|
||||
return cb;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
boost::shared_ptr<CommandCallback> MakeMessageCallback(typename BoostFunctionMessageCallback<T>::Fn func) {
|
||||
boost::shared_ptr<CommandCallback> cb(new BoostFunctionMessageCallback<T>(func));
|
||||
std::shared_ptr<CommandCallback> MakeMessageCallback(typename BoostFunctionMessageCallback<T>::Fn func) {
|
||||
std::shared_ptr<CommandCallback> cb(new BoostFunctionMessageCallback<T>(func));
|
||||
return cb;
|
||||
}
|
||||
|
||||
@@ -192,17 +192,17 @@ class MemberMessageCallback : public CommandCallback {
|
||||
};
|
||||
|
||||
template <class T, class ResponseType>
|
||||
boost::shared_ptr<CommandCallback> MakeMemberMessageCallback(
|
||||
std::shared_ptr<CommandCallback> MakeMemberMessageCallback(
|
||||
T *_this,
|
||||
typename MemberMessageCallback<T, ResponseType>::MemFn func) {
|
||||
boost::shared_ptr<CommandCallback> cb(new MemberMessageCallback<T, ResponseType>(_this, func));
|
||||
std::shared_ptr<CommandCallback> cb(new MemberMessageCallback<T, ResponseType>(_this, func));
|
||||
return cb;
|
||||
}
|
||||
|
||||
template <class ResponseType>
|
||||
class BoostFunctionCallback : public CommandCallback {
|
||||
public:
|
||||
typedef boost::function<void(uint8_t, uint8_t, ResponseType *)> Fn;
|
||||
typedef std::function<void(uint8_t, uint8_t, ResponseType *)> Fn;
|
||||
BoostFunctionCallback(const Fn &func) : func_(func) {}
|
||||
void operator()(livox_status status,uint8_t handle, void *data) {
|
||||
if (func_) {
|
||||
@@ -221,7 +221,7 @@ class BoostFunctionCallback : public CommandCallback {
|
||||
template <>
|
||||
class BoostFunctionCallback<uint8_t> : public CommandCallback {
|
||||
public:
|
||||
typedef boost::function<void(uint8_t, uint8_t, uint8_t)> Fn;
|
||||
typedef std::function<void(uint8_t, uint8_t, uint8_t)> Fn;
|
||||
BoostFunctionCallback(const Fn &func) : func_(func) {}
|
||||
void operator()(livox_status status,uint8_t handle, void *data) {
|
||||
if (func_) {
|
||||
@@ -238,8 +238,8 @@ class BoostFunctionCallback<uint8_t> : public CommandCallback {
|
||||
};
|
||||
|
||||
template <class ResponseType>
|
||||
boost::shared_ptr<CommandCallback> MakeCommandCallback(const typename BoostFunctionCallback<ResponseType>::Fn &func) {
|
||||
boost::shared_ptr<CommandCallback> cb(new BoostFunctionCallback<ResponseType>(func));
|
||||
std::shared_ptr<CommandCallback> MakeCommandCallback(const typename BoostFunctionCallback<ResponseType>::Fn &func) {
|
||||
std::shared_ptr<CommandCallback> cb(new BoostFunctionCallback<ResponseType>(func));
|
||||
return cb;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,14 +23,13 @@
|
||||
//
|
||||
|
||||
#include "io_loop.h"
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/thread/lock_guard.hpp>
|
||||
#include <boost/thread/locks.hpp>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <iostream>
|
||||
#include "logging.h"
|
||||
|
||||
using boost::lock_guard;
|
||||
using boost::mutex;
|
||||
using std::lock_guard;
|
||||
using std::mutex;
|
||||
using std::vector;
|
||||
|
||||
namespace livox {
|
||||
@@ -40,13 +39,8 @@ bool IOLoop::Init() {
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
apr_status_t rv =
|
||||
apr_pollset_create(&pollset_, kMaxPollCount, mem_pool_, APR_POLLSET_WAKEABLE);
|
||||
#else
|
||||
apr_status_t rv =
|
||||
apr_pollset_create(&pollset_, kMaxPollCount, mem_pool_, APR_POLLSET_THREADSAFE | APR_POLLSET_WAKEABLE);
|
||||
#endif
|
||||
|
||||
if (rv != APR_SUCCESS) {
|
||||
LOG_ERROR(PrintAPRStatus(rv));
|
||||
@@ -74,11 +68,11 @@ void IOLoop::Uninit() {
|
||||
}
|
||||
|
||||
void IOLoop::AddDelegate(apr_socket_t *sock, IOLoop::IOLoopDelegate *delegate, void *data) {
|
||||
PostTask(boost::bind(&IOLoop::AddDelegateAsync, this, sock, delegate, data));
|
||||
PostTask(std::bind(&IOLoop::AddDelegateAsync, this, sock, delegate, data));
|
||||
}
|
||||
|
||||
void IOLoop::RemoveDelegate(apr_socket_t *sock, IOLoopDelegate *) {
|
||||
PostTask(boost::bind(&IOLoop::RemoveDelegateAsync, this, sock));
|
||||
PostTask(std::bind(&IOLoop::RemoveDelegateAsync, this, sock));
|
||||
}
|
||||
|
||||
void IOLoop::RemoveDelegateSync(apr_socket_t *sock) {
|
||||
@@ -97,7 +91,7 @@ void IOLoop::Loop() {
|
||||
if (data) {
|
||||
IOLoopDelegate *delegate = data->first;
|
||||
if (delegate) {
|
||||
delegate->OnData(ret_pfd->desc.s, data->second);
|
||||
delegate->OnData(ret_pfd[i].desc.s, data->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,9 +25,9 @@
|
||||
#ifndef LIVOX_IO_LOOP_H_
|
||||
#define LIVOX_IO_LOOP_H_
|
||||
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/unordered_map.hpp>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "apr_general.h"
|
||||
@@ -50,7 +50,7 @@ class IOLoop : public noncopyable {
|
||||
virtual void OnWake() {}
|
||||
};
|
||||
|
||||
typedef boost::function<void(void)> IOLoopTask;
|
||||
typedef std::function<void(void)> IOLoopTask;
|
||||
|
||||
public:
|
||||
explicit IOLoop(apr_pool_t *mem_pool, bool enable_timer = true, bool enable_wake = true)
|
||||
@@ -74,12 +74,12 @@ class IOLoop : public noncopyable {
|
||||
private:
|
||||
static const apr_uint32_t kMaxPollCount = 48;
|
||||
typedef std::pair<IOLoopDelegate *, void *> ClientData;
|
||||
typedef boost::unordered_map<apr_socket_t *, ClientData *> DelegatesType;
|
||||
typedef std::unordered_map<apr_socket_t *, ClientData *> DelegatesType;
|
||||
DelegatesType delegates_;
|
||||
apr_pollset_t *pollset_;
|
||||
apr_pool_t *mem_pool_;
|
||||
apr_time_t last_timeout_;
|
||||
boost::mutex mutex_;
|
||||
std::mutex mutex_;
|
||||
bool enable_timer_;
|
||||
bool enable_wake_;
|
||||
std::vector<IOLoopTask> pending_tasks_;
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
#ifndef LIVOX_IO_THREAD_H_
|
||||
#define LIVOX_IO_THREAD_H_
|
||||
#include <boost/smart_ptr.hpp>
|
||||
#include <memory>
|
||||
#include "io_loop.h"
|
||||
#include "thread_base.h"
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace livox {
|
||||
|
||||
class IOThread : public ThreadBase {
|
||||
public:
|
||||
IOThread() : loop_(NULL) {}
|
||||
IOThread() : loop_(nullptr) {}
|
||||
bool Init(bool enable_timer = true, bool enable_wake = true);
|
||||
void Join();
|
||||
void Uninit();
|
||||
@@ -41,7 +41,7 @@ class IOThread : public ThreadBase {
|
||||
void ThreadFunc();
|
||||
|
||||
private:
|
||||
boost::scoped_ptr<IOLoop> loop_;
|
||||
std::unique_ptr<IOLoop> loop_;
|
||||
};
|
||||
} // namespace livox
|
||||
#endif // LIVOX_IO_THREAD_H_
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
std::shared_ptr<spdlog::logger> logger = NULL;
|
||||
bool is_save_log_file = false;
|
||||
bool is_console_log_enable = true;
|
||||
|
||||
void InitLogger() {
|
||||
|
||||
@@ -35,9 +36,11 @@ void InitLogger() {
|
||||
}
|
||||
|
||||
std::vector<spdlog::sink_ptr> sinkList;
|
||||
auto consoleSink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
|
||||
consoleSink->set_level(spdlog::level::debug);
|
||||
sinkList.push_back(consoleSink);
|
||||
if (is_console_log_enable) {
|
||||
auto consoleSink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
|
||||
consoleSink->set_level(spdlog::level::debug);
|
||||
sinkList.push_back(consoleSink);
|
||||
}
|
||||
|
||||
if (is_save_log_file) {
|
||||
auto rotateSink = std::make_shared<spdlog::sinks::rotating_file_sink_mt>("livox_log.txt", 1024 * 1024 * 5, 2);
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
|
||||
extern std::shared_ptr<spdlog::logger> logger;
|
||||
extern bool is_save_log_file;
|
||||
extern bool is_console_log_enable;
|
||||
|
||||
void InitLogger();
|
||||
void UninitLogger();
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
#include "network_util.h"
|
||||
#ifdef WIN32
|
||||
#include <boost/scoped_array.hpp>
|
||||
#include <memory>
|
||||
#include <Winsock2.h>
|
||||
#include <iphlpapi.h>
|
||||
#include <string>
|
||||
@@ -101,7 +101,7 @@ bool GetAdapterState(const IP_ADAPTER_INFO *pAdapter)
|
||||
bool FindLocalIp(const struct sockaddr_in &client_addr, uint32_t &local_ip) {
|
||||
bool found = false;
|
||||
ULONG ulOutbufLen = sizeof(IP_ADAPTER_INFO);
|
||||
boost::scoped_array<uint8_t> pAdapterInfo(new uint8_t[ulOutbufLen]);
|
||||
std::unique_ptr<uint8_t[]> pAdapterInfo(new uint8_t[ulOutbufLen]);
|
||||
DWORD dlRetVal = GetAdaptersInfo(reinterpret_cast<IP_ADAPTER_INFO *>(pAdapterInfo.get()), &ulOutbufLen);
|
||||
if (dlRetVal == ERROR_BUFFER_OVERFLOW) {
|
||||
pAdapterInfo.reset(new uint8_t[ulOutbufLen]);
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include <apr_general.h>
|
||||
#include <apr_thread_proc.h>
|
||||
#include <apr_portable.h>
|
||||
#include <boost/atomic/atomic.hpp>
|
||||
#include <atomic>
|
||||
#include "noncopyable.h"
|
||||
|
||||
namespace livox {
|
||||
@@ -46,7 +46,7 @@ class ThreadBase : public noncopyable {
|
||||
|
||||
protected:
|
||||
apr_thread_t *thread_;
|
||||
boost::atomic_bool quit_;
|
||||
std::atomic_bool quit_;
|
||||
apr_pool_t *pool_;
|
||||
};
|
||||
|
||||
|
||||
@@ -23,15 +23,15 @@
|
||||
//
|
||||
|
||||
#include "command_channel.h"
|
||||
#include <boost/bind.hpp>
|
||||
#include <functional>
|
||||
#include <atomic>
|
||||
#include "base/logging.h"
|
||||
#include "base/network_util.h"
|
||||
#include "command_impl.h"
|
||||
#include "device_manager.h"
|
||||
#include "livox_def.h"
|
||||
|
||||
using boost::atomic_uint16_t;
|
||||
using boost::bind;
|
||||
using std::bind;
|
||||
using std::list;
|
||||
using std::make_pair;
|
||||
using std::map;
|
||||
@@ -182,7 +182,7 @@ void CommandChannel::HeartBeat(apr_time_t t) {
|
||||
NULL,
|
||||
0,
|
||||
0,
|
||||
boost::shared_ptr<CommandCallback>());
|
||||
std::shared_ptr<CommandCallback>());
|
||||
SendInternal(command);
|
||||
}
|
||||
}
|
||||
@@ -207,7 +207,7 @@ void CommandChannel::SendInternal(const Command &command) {
|
||||
}
|
||||
|
||||
uint16_t CommandChannel::GenerateSeq() {
|
||||
static atomic_uint16_t seq(1);
|
||||
static std::atomic<std::uint16_t> seq(1);
|
||||
uint16_t value = seq.load();
|
||||
uint16_t desired = 0;
|
||||
do {
|
||||
|
||||
@@ -24,7 +24,8 @@
|
||||
|
||||
#ifndef LIVOX_COMMAND_CHANNEL_H_
|
||||
#define LIVOX_COMMAND_CHANNEL_H_
|
||||
#include <boost/smart_ptr.hpp>
|
||||
#include <memory>
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include "apr_network_io.h"
|
||||
@@ -36,7 +37,7 @@ namespace livox {
|
||||
typedef struct TagCommand {
|
||||
uint8_t handle;
|
||||
CommPacket packet;
|
||||
boost::shared_ptr<CommandCallback> cb;
|
||||
std::shared_ptr<CommandCallback> cb;
|
||||
uint32_t time_out;
|
||||
TagCommand() : packet(), time_out(0) {}
|
||||
TagCommand(uint8_t _handle,
|
||||
@@ -47,7 +48,7 @@ typedef struct TagCommand {
|
||||
uint8_t *data,
|
||||
uint16_t length,
|
||||
uint32_t _time_out,
|
||||
const boost::shared_ptr<CommandCallback> &_cb)
|
||||
const std::shared_ptr<CommandCallback> &_cb)
|
||||
: handle(_handle), packet(), cb(_cb) {
|
||||
packet.packet_type = _cmd_type;
|
||||
packet.cmd_set = _cmd_set;
|
||||
@@ -115,7 +116,7 @@ class CommandChannel : public IOLoop::IOLoopDelegate {
|
||||
IOLoop *loop_;
|
||||
CommandChannelDelegate *callback_;
|
||||
std::map<uint16_t, std::pair<Command, apr_time_t> > commands_;
|
||||
boost::scoped_ptr<CommPort> comm_port_;
|
||||
std::unique_ptr<CommPort> comm_port_;
|
||||
apr_time_t heartbeat_time_;
|
||||
std::string remote_ip_;
|
||||
apr_time_t last_heartbeat_;
|
||||
|
||||
@@ -23,17 +23,16 @@
|
||||
//
|
||||
|
||||
#include "command_handler.h"
|
||||
#include <boost/thread/lock_guard.hpp>
|
||||
#include <boost/thread/locks.hpp>
|
||||
#include <mutex>
|
||||
#include "base/logging.h"
|
||||
#include "command_impl.h"
|
||||
#include "device_manager.h"
|
||||
#include "hub_command_handler.h"
|
||||
#include "lidar_command_handler.h"
|
||||
|
||||
using boost::lock_guard;
|
||||
using boost::mutex;
|
||||
using boost::shared_ptr;
|
||||
using std::lock_guard;
|
||||
using std::mutex;
|
||||
using std::shared_ptr;
|
||||
using std::list;
|
||||
using std::make_pair;
|
||||
using std::multimap;
|
||||
|
||||
@@ -25,8 +25,9 @@
|
||||
#ifndef LIVOX_COMMAND_HANDLER_H_
|
||||
#define LIVOX_COMMAND_HANDLER_H_
|
||||
|
||||
#include <boost/smart_ptr.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <memory>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include "base/command_callback.h"
|
||||
#include "base/util.h"
|
||||
#include "command_channel.h"
|
||||
@@ -51,12 +52,12 @@ class CommandHandler : public noncopyable {
|
||||
uint8_t command_id,
|
||||
uint8_t *data,
|
||||
uint16_t length,
|
||||
const boost::shared_ptr<CommandCallback> &cb);
|
||||
const std::shared_ptr<CommandCallback> &cb);
|
||||
|
||||
livox_status RegisterPush(uint8_t handle,
|
||||
uint8_t command_set,
|
||||
uint8_t command_id,
|
||||
const boost::shared_ptr<CommandCallback> &cb);
|
||||
const std::shared_ptr<CommandCallback> &cb);
|
||||
|
||||
void OnCommand(uint8_t handle, const Command &command);
|
||||
|
||||
@@ -71,8 +72,8 @@ class CommandHandler : public noncopyable {
|
||||
private:
|
||||
std::multimap<uint16_t, Command> message_registers_;
|
||||
apr_pool_t *mem_pool_;
|
||||
boost::scoped_ptr<CommandHandlerImpl> impl_;
|
||||
boost::mutex mutex_;
|
||||
std::unique_ptr<CommandHandlerImpl> impl_;
|
||||
std::mutex mutex_;
|
||||
IOLoop *loop_;
|
||||
};
|
||||
|
||||
|
||||
@@ -211,6 +211,7 @@ bool ParseRmcTime(const char* rmc, uint16_t rmc_len, LidarSetUtcSyncTimeRequest*
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
utc_time_req->hour = hour;
|
||||
utc_time_req->mircrosecond = (minute * 60 * 1000 + second * 1000 + millisecond) * 1000;
|
||||
return true;
|
||||
}
|
||||
@@ -339,9 +340,16 @@ livox_status GetDeviceIpInformation(uint8_t handle, GetDeviceIpInformationCallba
|
||||
}
|
||||
|
||||
livox_status RebootDevice(uint8_t handle, uint16_t timeout, CommonCommandCallback cb, void * client_data) {
|
||||
if(device_manager().IsLidarMid40(handle)) {
|
||||
return kStatusNotSupported;
|
||||
if (device_manager().IsLidarMid40(handle)) {
|
||||
uint32_t firm_ver = 0;
|
||||
// Mid40 firmware version 03.07.0000
|
||||
uint32_t min_firm_ver = (uint32_t)3 << 24 | 7 << 16 | 0 << 8 | 0;
|
||||
device_manager().GetLidarFirmwareVersion(handle, firm_ver);
|
||||
if (firm_ver < min_firm_ver) {
|
||||
return kStatusNotSupported;
|
||||
}
|
||||
}
|
||||
|
||||
livox_status result = command_handler().SendCommand(handle,
|
||||
kCommandSetGeneral,
|
||||
kCommandIDGeneralRebootDevice,
|
||||
@@ -735,10 +743,19 @@ livox_status LidarSetRmcSyncTime(uint8_t handle,
|
||||
uint16_t rmc_length,
|
||||
CommonCommandCallback cb,
|
||||
void *client_data) {
|
||||
if (device_manager().device_mode() != kDeviceModeLidar
|
||||
|| device_manager().IsLidarMid40(handle)) {
|
||||
if (device_manager().device_mode() != kDeviceModeLidar) {
|
||||
return kStatusNotSupported;
|
||||
}
|
||||
|
||||
if (device_manager().IsLidarMid40(handle)) {
|
||||
uint32_t firm_ver = 0;
|
||||
// Mid40 firmware version 03.07.0000
|
||||
uint32_t min_firm_ver = (uint32_t)3 << 24 | 7 << 16 | 0 << 8 | 0;
|
||||
device_manager().GetLidarFirmwareVersion(handle, firm_ver);
|
||||
if (firm_ver < min_firm_ver) {
|
||||
return kStatusNotSupported;
|
||||
}
|
||||
}
|
||||
|
||||
LidarSetUtcSyncTimeRequest utc_time_req;
|
||||
if (!ParseRmcTime(rmc, rmc_length, &utc_time_req)) {
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#ifndef LIVOX_HUB_COMMAND_HANDLER_H_
|
||||
#define LIVOX_HUB_COMMAND_HANDLER_H_
|
||||
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
#include <memory>
|
||||
#include "command_handler.h"
|
||||
|
||||
namespace livox {
|
||||
@@ -43,7 +43,7 @@ class HubCommandHandlerImpl : public CommandHandlerImpl {
|
||||
IOLoop *loop_;
|
||||
bool is_valid_;
|
||||
DeviceInfo hub_info_;
|
||||
boost::scoped_ptr<CommandChannel> channel_;
|
||||
std::unique_ptr<CommandChannel> channel_;
|
||||
};
|
||||
} // namespace livox
|
||||
#endif // LIVOX_HUB_COMMAND_HANDLER_H_
|
||||
|
||||
@@ -33,8 +33,8 @@ void LidarCommandHandlerImpl::Uninit() {
|
||||
}
|
||||
|
||||
bool LidarCommandHandlerImpl::AddDevice(const DeviceInfo &info) {
|
||||
boost::shared_ptr<CommandChannel> channel =
|
||||
boost::make_shared<CommandChannel>(info.cmd_port, info.handle, info.ip, this, mem_pool_);
|
||||
std::shared_ptr<CommandChannel> channel =
|
||||
std::make_shared<CommandChannel>(info.cmd_port, info.handle, info.ip, this, mem_pool_);
|
||||
channel->Bind(loop_);
|
||||
|
||||
DeviceItem item = {channel, info};
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
#ifndef LIVOX_LIDAR_COMMAND_HANDLER_H_
|
||||
#define LIVOX_LIDAR_COMMAND_HANDLER_H_
|
||||
#include <boost/smart_ptr.hpp>
|
||||
#include <memory>
|
||||
#include "command_handler.h"
|
||||
|
||||
namespace livox {
|
||||
@@ -42,7 +42,7 @@ class LidarCommandHandlerImpl : public CommandHandlerImpl {
|
||||
|
||||
private:
|
||||
typedef struct {
|
||||
boost::shared_ptr<CommandChannel> channel;
|
||||
std::shared_ptr<CommandChannel> channel;
|
||||
DeviceInfo info;
|
||||
} DeviceItem;
|
||||
apr_pool_t *mem_pool_;
|
||||
|
||||
@@ -25,10 +25,10 @@
|
||||
#ifndef LIVOX_DATA_HANDLER_H_
|
||||
#define LIVOX_DATA_HANDLER_H_
|
||||
|
||||
#include <boost/array.hpp>
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/smart_ptr.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <array>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include "apr_pools.h"
|
||||
#include "base/io_thread.h"
|
||||
#include "device_manager.h"
|
||||
@@ -38,7 +38,7 @@ class DataHandlerImpl;
|
||||
|
||||
class DataHandler : public noncopyable {
|
||||
public:
|
||||
typedef boost::function<void(uint8_t handle, LivoxEthPacket *data, uint32_t data_num, void *client_data)> DataCallback;
|
||||
typedef std::function<void(uint8_t handle, LivoxEthPacket *data, uint32_t data_num, void *client_data)> DataCallback;
|
||||
|
||||
public:
|
||||
DataHandler() : mem_pool_(NULL) {}
|
||||
@@ -54,9 +54,9 @@ class DataHandler : public noncopyable {
|
||||
|
||||
private:
|
||||
apr_pool_t *mem_pool_;
|
||||
boost::array<DataCallback, kMaxConnectedDeviceNum> callbacks_;
|
||||
boost::array<void *, kMaxConnectedDeviceNum> client_data_;
|
||||
boost::scoped_ptr<DataHandlerImpl> impl_;
|
||||
std::array<DataCallback, kMaxConnectedDeviceNum> callbacks_;
|
||||
std::array<void *, kMaxConnectedDeviceNum> client_data_;
|
||||
std::unique_ptr<DataHandlerImpl> impl_;
|
||||
};
|
||||
|
||||
class DataHandlerImpl : public IOLoop::IOLoopDelegate {
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#ifndef LIVOX_HUB_DATA_HANDLER_H_
|
||||
#define LIVOX_HUB_DATA_HANDLER_H_
|
||||
|
||||
#include <boost/smart_ptr.hpp>
|
||||
#include <memory>
|
||||
#include "base/io_thread.h"
|
||||
#include "data_handler.h"
|
||||
|
||||
@@ -45,7 +45,7 @@ class HubDataHandlerImpl : public DataHandlerImpl {
|
||||
|
||||
private:
|
||||
apr_pool_t *mem_pool_;
|
||||
boost::scoped_ptr<IOThread> thread_;
|
||||
std::unique_ptr<IOThread> thread_;
|
||||
apr_socket_t *sock_;
|
||||
DeviceInfo hub_info_;
|
||||
bool is_valid_;
|
||||
|
||||
@@ -23,13 +23,12 @@
|
||||
//
|
||||
|
||||
#include "lidar_data_handler.h"
|
||||
#include <boost/thread/lock_guard.hpp>
|
||||
#include <boost/thread/locks.hpp>
|
||||
#include <mutex>
|
||||
#include "base/network_util.h"
|
||||
|
||||
using boost::lock_guard;
|
||||
using boost::mutex;
|
||||
using boost::shared_ptr;
|
||||
using std::lock_guard;
|
||||
using std::mutex;
|
||||
using std::shared_ptr;
|
||||
using std::list;
|
||||
|
||||
namespace livox {
|
||||
@@ -64,7 +63,7 @@ bool LidarDataHandlerImpl::AddDevice(const DeviceInfo &info) {
|
||||
return false;
|
||||
}
|
||||
|
||||
shared_ptr<IOThread> thread = boost::make_shared<IOThread>();
|
||||
shared_ptr<IOThread> thread = std::make_shared<IOThread>();
|
||||
thread->Init(false, false);
|
||||
thread->loop()->AddDelegate(sock, this, reinterpret_cast<void *>(info.handle));
|
||||
{
|
||||
@@ -106,7 +105,7 @@ void LidarDataHandlerImpl::OnData(apr_socket_t *sock, void *client_data) {
|
||||
if (handle > data_buffers_.size()) {
|
||||
return;
|
||||
}
|
||||
boost::scoped_array<char> &buf = data_buffers_[handle];
|
||||
std::unique_ptr<char[]> &buf = data_buffers_[handle];
|
||||
if (buf.get() == NULL) {
|
||||
buf.reset(new char[kMaxBufferSize]);
|
||||
}
|
||||
|
||||
@@ -25,9 +25,8 @@
|
||||
#ifndef LIVOX_LIDAR_DATA_HANDLER_H_
|
||||
#define LIVOX_LIDAR_DATA_HANDLER_H_
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/smart_ptr/scoped_array.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include "data_handler.h"
|
||||
#include "device_manager.h"
|
||||
|
||||
@@ -46,14 +45,14 @@ class LidarDataHandlerImpl : public DataHandlerImpl {
|
||||
private:
|
||||
typedef struct {
|
||||
apr_socket_t *sock;
|
||||
boost::shared_ptr<IOThread> thread;
|
||||
std::shared_ptr<IOThread> thread;
|
||||
uint16_t handle;
|
||||
} DeviceItem;
|
||||
std::list<DeviceItem> devices_;
|
||||
|
||||
boost::array<boost::scoped_array<char>, kMaxConnectedDeviceNum> data_buffers_;
|
||||
std::array<std::unique_ptr<char[]>, kMaxConnectedDeviceNum> data_buffers_;
|
||||
apr_pool_t *mem_pool_;
|
||||
boost::mutex mutex_;
|
||||
std::mutex mutex_;
|
||||
};
|
||||
|
||||
} // namespace livox
|
||||
|
||||
@@ -24,8 +24,7 @@
|
||||
|
||||
#include "device_discovery.h"
|
||||
#include <algorithm>
|
||||
#include <boost/thread/lock_guard.hpp>
|
||||
#include <boost/thread/locks.hpp>
|
||||
#include <mutex>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "apr_network_io.h"
|
||||
@@ -41,7 +40,7 @@
|
||||
#include "device_manager.h"
|
||||
#include "livox_def.h"
|
||||
|
||||
using boost::tuple;
|
||||
using std::tuple;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
@@ -97,10 +96,10 @@ void DeviceDiscovery::OnData(apr_socket_t *sock, void *) {
|
||||
if (connecting_devices_.find(sock) == connecting_devices_.end()) {
|
||||
continue;
|
||||
}
|
||||
DeviceInfo info = boost::get<2>(connecting_devices_[sock]);
|
||||
DeviceInfo info = std::get<2>(connecting_devices_[sock]);
|
||||
loop_->RemoveDelegate(sock, this);
|
||||
apr_socket_close(sock);
|
||||
apr_pool_destroy(boost::get<0>(connecting_devices_[sock]));
|
||||
apr_pool_destroy(std::get<0>(connecting_devices_[sock]));
|
||||
connecting_devices_.erase(sock);
|
||||
|
||||
if (packet.data == NULL) {
|
||||
@@ -124,10 +123,10 @@ void DeviceDiscovery::OnTimer(apr_time_t now) {
|
||||
ConnectingDeviceMap::iterator ite = connecting_devices_.begin();
|
||||
while (ite != connecting_devices_.end()) {
|
||||
tuple<apr_pool_t *, apr_time_t, DeviceInfo> &device_tuple = ite->second;
|
||||
if (now - boost::get<1>(device_tuple) > apr_time_from_msec(500)) {
|
||||
if (now - std::get<1>(device_tuple) > apr_time_from_msec(500)) {
|
||||
loop_->RemoveDelegate(ite->first, this);
|
||||
apr_socket_close(ite->first);
|
||||
apr_pool_destroy(boost::get<0>(device_tuple));
|
||||
apr_pool_destroy(std::get<0>(device_tuple));
|
||||
connecting_devices_.erase(ite++);
|
||||
} else {
|
||||
++ite;
|
||||
@@ -211,8 +210,8 @@ void DeviceDiscovery::OnBroadcast(const CommPacket &packet, apr_sockaddr_t *addr
|
||||
|
||||
loop_->AddDelegate(cmd_sock, this);
|
||||
OnTimer(apr_time_now());
|
||||
boost::get<0>(connecting_devices_[cmd_sock]) = pool;
|
||||
boost::get<2>(connecting_devices_[cmd_sock]) = lidar_info;
|
||||
std::get<0>(connecting_devices_[cmd_sock]) = pool;
|
||||
std::get<2>(connecting_devices_[cmd_sock]) = lidar_info;
|
||||
|
||||
bool result = false;
|
||||
do {
|
||||
@@ -247,7 +246,7 @@ void DeviceDiscovery::OnBroadcast(const CommPacket &packet, apr_sockaddr_t *addr
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
boost::get<1>(connecting_devices_[cmd_sock]) = apr_time_now();
|
||||
std::get<1>(connecting_devices_[cmd_sock]) = apr_time_now();
|
||||
result = true;
|
||||
} while (0);
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#ifndef LIVOX_DEVICE_DISCOVERY_
|
||||
#define LIVOX_DEVICE_DISCOVERY_
|
||||
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include "apr_general.h"
|
||||
#include "apr_network_io.h"
|
||||
@@ -43,7 +43,7 @@ namespace livox {
|
||||
*/
|
||||
class DeviceDiscovery : public noncopyable, IOLoop::IOLoopDelegate {
|
||||
public:
|
||||
DeviceDiscovery() : sock_(NULL), mem_pool_(NULL), loop_(NULL), comm_port_(NULL) {}
|
||||
DeviceDiscovery() : sock_(NULL), mem_pool_(NULL), loop_(NULL), comm_port_(nullptr) {}
|
||||
bool Init();
|
||||
void Uninit();
|
||||
|
||||
@@ -79,9 +79,9 @@ class DeviceDiscovery : public noncopyable, IOLoop::IOLoopDelegate {
|
||||
apr_socket_t *sock_;
|
||||
apr_pool_t *mem_pool_;
|
||||
IOLoop *loop_;
|
||||
boost::scoped_ptr<CommPort> comm_port_;
|
||||
boost::mutex mutex_;
|
||||
typedef std::map<apr_socket_t *, boost::tuple<apr_pool_t *, apr_time_t, DeviceInfo> > ConnectingDeviceMap;
|
||||
std::unique_ptr<CommPort> comm_port_;
|
||||
std::mutex mutex_;
|
||||
typedef std::map<apr_socket_t *, std::tuple<apr_pool_t *, apr_time_t, DeviceInfo> > ConnectingDeviceMap;
|
||||
ConnectingDeviceMap connecting_devices_;
|
||||
};
|
||||
|
||||
|
||||
@@ -23,17 +23,16 @@
|
||||
//
|
||||
|
||||
#include "device_manager.h"
|
||||
#include <boost/atomic.hpp>
|
||||
#include <boost/thread/lock_guard.hpp>
|
||||
#include <boost/thread/locks.hpp>
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
#include "base/logging.h"
|
||||
#include "command_handler/command_handler.h"
|
||||
#include "command_handler/command_impl.h"
|
||||
#include "data_handler/data_handler.h"
|
||||
|
||||
using boost::lock_guard;
|
||||
using boost::mutex;
|
||||
using std::lock_guard;
|
||||
using std::mutex;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
@@ -113,25 +112,31 @@ void DeviceManager::BroadcastDevices(const BroadcastDeviceInfo *info) {
|
||||
}
|
||||
|
||||
void DeviceManager::UpdateDevices(const DeviceInfo &device, DeviceEvent type) {
|
||||
if (device_mode_ == kDeviceModeLidar && connected_cb_) {
|
||||
connected_cb_(&device, type);
|
||||
if (device_mode_ == kDeviceModeLidar && type == kEventConnect) {
|
||||
command_handler().SendCommand(device.handle,
|
||||
kCommandSetGeneral,
|
||||
kCommandIDGeneralDeviceInfo,
|
||||
NULL,
|
||||
0,
|
||||
MakeCommandCallback<DeviceManager, DeviceInformationResponse>(
|
||||
this, &DeviceManager::QueryDeviceInformationCallback));
|
||||
return;
|
||||
}
|
||||
|
||||
if (device_mode_ == kDeviceModeHub) {
|
||||
if (type == kEventHubConnectionChange) {
|
||||
LOG_DEBUG("Send Query lidars command");
|
||||
command_handler().SendCommand(kHubDefaultHandle,
|
||||
kCommandSetHub,
|
||||
kCommandIDHubQueryLidarInformation,
|
||||
NULL,
|
||||
0,
|
||||
MakeCommandCallback<DeviceManager, HubQueryLidarInformationResponse>(
|
||||
this, &DeviceManager::HubLidarInfomationCallback));
|
||||
} else {
|
||||
if (connected_cb_) {
|
||||
connected_cb_(&device, type);
|
||||
}
|
||||
}
|
||||
if (device_mode_ == kDeviceModeHub && type == kEventHubConnectionChange) {
|
||||
LOG_DEBUG("Send Query lidars command");
|
||||
command_handler().SendCommand(kHubDefaultHandle,
|
||||
kCommandSetHub,
|
||||
kCommandIDHubQueryLidarInformation,
|
||||
NULL,
|
||||
0,
|
||||
MakeCommandCallback<DeviceManager, HubQueryLidarInformationResponse>(
|
||||
this, &DeviceManager::HubLidarInfomationCallback));
|
||||
return;
|
||||
}
|
||||
|
||||
if (connected_cb_) {
|
||||
connected_cb_(&device, type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,6 +157,11 @@ void DeviceManager::HubLidarInfomationCallback(livox_status status, uint8_t, Hub
|
||||
strncpy(
|
||||
info.info.broadcast_code, response->device_info_list[i].broadcast_code, sizeof(info.info.broadcast_code));
|
||||
info.info.handle = index;
|
||||
info.info.type = response->device_info_list[i].dev_type;
|
||||
info.info.slot = response->device_info_list[i].slot;
|
||||
info.info.id = response->device_info_list[i].id;
|
||||
memcpy(
|
||||
info.info.firmware_version, response->device_info_list[i].version, sizeof(info.info.firmware_version));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -163,6 +173,24 @@ void DeviceManager::HubLidarInfomationCallback(livox_status status, uint8_t, Hub
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceManager::QueryDeviceInformationCallback(livox_status status, uint8_t handle, DeviceInformationResponse *response) {
|
||||
if (status == kStatusSuccess) {
|
||||
{
|
||||
lock_guard<mutex> lock(mutex_);
|
||||
if (handle < devices_.size()) {
|
||||
DetailDeviceInfo &info = devices_[handle];
|
||||
memcpy(
|
||||
info.info.firmware_version, response->firmware_version, sizeof(response->firmware_version));
|
||||
}
|
||||
}
|
||||
if (connected_cb_) {
|
||||
connected_cb_(&devices_[handle].info, kEventConnect);
|
||||
}
|
||||
} else {
|
||||
LOG_ERROR("Failed to query lidar information.");
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceManager::GetConnectedDevices(vector<DeviceInfo> &devices) {
|
||||
lock_guard<mutex> lock(mutex_);
|
||||
for (DeviceContainer::iterator ite = devices_.begin(); ite != devices_.end(); ++ite) {
|
||||
@@ -273,6 +301,15 @@ bool DeviceManager::IsLidarMid40(uint8_t handle) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DeviceManager::GetLidarFirmwareVersion(uint8_t handle, uint32_t &firmware_version) {
|
||||
if (handle > devices_.size()) {
|
||||
return false;
|
||||
}
|
||||
uint8_t *firm_ver = devices_[handle].info.firmware_version;
|
||||
firmware_version = firm_ver[0] << 24 | firm_ver[1] << 16 | firm_ver[2] << 8 | firm_ver[3];
|
||||
return true;
|
||||
}
|
||||
|
||||
DeviceManager &device_manager() {
|
||||
static DeviceManager lidar_manager;
|
||||
return lidar_manager;
|
||||
|
||||
@@ -25,9 +25,9 @@
|
||||
#ifndef LIVOX_DEVICE_MANAGER_H_
|
||||
#define LIVOX_DEVICE_MANAGER_H_
|
||||
|
||||
#include <boost/array.hpp>
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <array>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include "device_discovery.h"
|
||||
#include "livox_sdk.h"
|
||||
@@ -88,13 +88,14 @@ class DeviceManager : public noncopyable {
|
||||
*/
|
||||
bool IsDeviceConnected(uint8_t handle);
|
||||
|
||||
void SetDeviceConnectedCallback(const boost::function<void(const DeviceInfo *, DeviceEvent)> &cb) {
|
||||
void SetDeviceConnectedCallback(const std::function<void(const DeviceInfo *, DeviceEvent)> &cb) {
|
||||
connected_cb_ = cb;
|
||||
}
|
||||
void SetDeviceBroadcastCallback(const boost::function<void(const BroadcastDeviceInfo *info)> &cb) {
|
||||
void SetDeviceBroadcastCallback(const std::function<void(const BroadcastDeviceInfo *info)> &cb) {
|
||||
broadcast_cb_ = cb;
|
||||
}
|
||||
void HubLidarInfomationCallback(livox_status status, uint8_t handle, HubQueryLidarInformationResponse *response);
|
||||
void QueryDeviceInformationCallback(livox_status status, uint8_t handle, DeviceInformationResponse *response);
|
||||
DeviceMode device_mode() { return device_mode_; }
|
||||
void BroadcastDevices(const BroadcastDeviceInfo *info);
|
||||
void UpdateDevices(const DeviceInfo &device, DeviceEvent type);
|
||||
@@ -102,6 +103,7 @@ class DeviceManager : public noncopyable {
|
||||
void GetConnectedDevices(std::vector<DeviceInfo> &devices);
|
||||
bool AddListeningDevice(const std::string &broadcast_code, DeviceMode mode, uint8_t &handle);
|
||||
bool IsLidarMid40(uint8_t handle);
|
||||
bool GetLidarFirmwareVersion(uint8_t handle, uint32_t &firmware_version);
|
||||
|
||||
private:
|
||||
typedef struct _DetailDeviceInfo {
|
||||
@@ -116,7 +118,8 @@ class DeviceManager : public noncopyable {
|
||||
uint32_t type,
|
||||
uint16_t data_port,
|
||||
uint16_t cmd_port,
|
||||
const char *ip) {
|
||||
const char *ip,
|
||||
const uint8_t *firmware_version) {
|
||||
connected = _connected;
|
||||
strncpy(info.broadcast_code, broadcast_code, sizeof(info.broadcast_code));
|
||||
info.handle = handle;
|
||||
@@ -126,6 +129,7 @@ class DeviceManager : public noncopyable {
|
||||
info.data_port = data_port;
|
||||
info.cmd_port = cmd_port;
|
||||
strncpy(info.ip, ip, sizeof(info.ip));
|
||||
memcpy(info.firmware_version, firmware_version, sizeof(info.firmware_version));
|
||||
}
|
||||
void clear() {
|
||||
connected = false;
|
||||
@@ -137,15 +141,16 @@ class DeviceManager : public noncopyable {
|
||||
info.data_port = 0;
|
||||
info.cmd_port = 0;
|
||||
memset(info.ip, 0, sizeof(info.ip));
|
||||
memset(info.firmware_version, 0, sizeof(info.firmware_version));
|
||||
};
|
||||
} DetailDeviceInfo;
|
||||
typedef boost::array<DetailDeviceInfo, kMaxConnectedDeviceNum> DeviceContainer;
|
||||
typedef std::array<DetailDeviceInfo, kMaxConnectedDeviceNum> DeviceContainer;
|
||||
DeviceContainer devices_;
|
||||
apr_pool_t *mem_pool_;
|
||||
DeviceMode device_mode_;
|
||||
boost::function<void(const DeviceInfo *, DeviceEvent)> connected_cb_;
|
||||
boost::function<void(const BroadcastDeviceInfo *info)> broadcast_cb_;
|
||||
boost::mutex mutex_;
|
||||
std::function<void(const DeviceInfo *, DeviceEvent)> connected_cb_;
|
||||
std::function<void(const BroadcastDeviceInfo *info)> broadcast_cb_;
|
||||
std::mutex mutex_;
|
||||
};
|
||||
|
||||
DeviceManager &device_manager();
|
||||
|
||||
@@ -121,4 +121,8 @@ bool Start() {
|
||||
|
||||
void SaveLoggerFile() {
|
||||
is_save_log_file = true;
|
||||
}
|
||||
|
||||
void DisableConsoleLogger() {
|
||||
is_console_log_enable = false;
|
||||
}
|
||||
Reference in New Issue
Block a user