diff --git a/README.md b/README.md index c2e62df..59534ee 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,35 @@ -# LDLiDAR SDK +# LDLiDAR SDK - Fixed + +## Fixes by MrKussen including: + +- Deleted non-working code +- Added missing functions +- Fixing includes +- Added one missing header guard instead of pragma once, to make the code uniform. +- Added platform-dependant defines to decrease confusion and making sure that only code for the right platform will be compiled and run. +- The linux code was mostly fine, most changes were either in the windows code or the logging module + +## How to use (mostly for beginners): + +You can use this SDK by just adding the cpp files and the headers to your projects. + +When you compile, there might be errors if you have UNICODE or _UNICODE defined, so avoid defining those if you can, or you will have to change between wide and thin characters in the source code. + +Make sure that you compile the .cpp files here as well as your program files. + +(For example, compilation with g++ can be done by placing your program files in /src/ and running g++ ./src/*.cpp -I./include/) + +--- + +## Supported products + This SDK is only applicable to the LiDAR products sold by Shenzhen LDROBOT Co., LTD. | product models | range types | -| ---- | ---- | -| LDROBOT LiDAR LD06 | 2D DTOF | -| LDROBOT LiDAR LD19 | 2D DTOF | -| LDROBOT LiDAR LD14 | 2D Triangle| -| LDROBOT LiDAR LD14P | 2D Triangle| +| ---- | ---- | +| LDROBOT LiDAR LD06 | 2D DTOF | +| LDROBOT LiDAR LD19 | 2D DTOF | +| LDROBOT LiDAR LD14 | 2D Triangle | +| LDROBOT LiDAR LD14P | 2D Triangle | --- ## Get SDK diff --git a/include/ldlidar_driver/ldlidar_driver.h b/include/ldlidar_driver/ldlidar_driver.h index afed1c9..b6d5182 100644 --- a/include/ldlidar_driver/ldlidar_driver.h +++ b/include/ldlidar_driver/ldlidar_driver.h @@ -28,6 +28,8 @@ namespace ldlidar { +uint64_t GetSystemTimeStamp(void); + class LDLidarDriver { public: LDLidarDriver(); diff --git a/include/ldlidar_driver/ldlidar_driver_linux.h b/include/ldlidar_driver/ldlidar_driver_linux.h index 4eaa4c8..57d1cfb 100644 --- a/include/ldlidar_driver/ldlidar_driver_linux.h +++ b/include/ldlidar_driver/ldlidar_driver_linux.h @@ -21,6 +21,8 @@ #ifndef __LDLIDAR_DRIVER_SDK_LINUX_INTERFACE_H__ #define __LDLIDAR_DRIVER_SDK_LINUX_INTERFACE_H__ +#ifdef __linux__ + #include "ldlidar_driver/ldlidar_driver.h" #include "ldlidar_driver/ldlidar_dataprocess.h" #include "ldlidar_driver/serial_interface_linux.h" @@ -158,6 +160,7 @@ class LDLidarDriverLinuxInterface : public LDLidarDriver { } // namespace ldlidar +#endif //__linux__ #endif // __LDLIDAR_DRIVER_NODE_H__ /********************* (C) COPYRIGHT SHENZHEN LDROBOT CO., LTD *******END OF * FILE ********/ \ No newline at end of file diff --git a/include/ldlidar_driver/ldlidar_driver_win.h b/include/ldlidar_driver/ldlidar_driver_win.h index 0212a1d..16ef574 100644 --- a/include/ldlidar_driver/ldlidar_driver_win.h +++ b/include/ldlidar_driver/ldlidar_driver_win.h @@ -21,6 +21,8 @@ #ifndef __LDLIDAR_DRIVER_SDK_WIN_INTERFACE_H__ #define __LDLIDAR_DRIVER_SDK_WIN_INTERFACE_H__ +#ifdef WIN32 + #include "ldlidar_driver/ldlidar_driver.h" #include "ldlidar_driver/ldlidar_dataprocess.h" #include "ldlidar_driver/log_module.h" @@ -72,7 +74,7 @@ class LDLidarDriverWinInterface : public LDLidarDriver { bool WaitLidarComm(int64_t timeout = 1000) override; /** - * @brief get lidar laser scan point cloud data + * @brief get lidar laser scan point cloud data | NOTE THAT THIS DOES NOT RETURN X AND Y, ONLY ANGLE AND DISTANCE * @param [output] * *@param dst: type is ldlidar::Point2D, value is laser scan point cloud data * @param [in] @@ -147,6 +149,7 @@ class LDLidarDriverWinInterface : public LDLidarDriver { } // namespace ldlidar +#endif //WIN32 #endif // __LDLIDAR_DRIVER_NODE_H__ /********************* (C) COPYRIGHT SHENZHEN LDROBOT CO., LTD *******END OF * FILE ********/ \ No newline at end of file diff --git a/include/ldlidar_driver/log_module.h b/include/ldlidar_driver/log_module.h index 5fc2ce5..ce712ed 100644 --- a/include/ldlidar_driver/log_module.h +++ b/include/ldlidar_driver/log_module.h @@ -159,7 +159,7 @@ class LogModule { ILogRealization* p_realization_; public: - static LogModule* GetInstance( __in const char* filename, __in const char* funcname,__in int lineno, LogLevel level, ILogRealization* plog = NULL); + // static LogModule* GetInstance( __in const char* filename, __in const char* funcname,__in int lineno, LogLevel level, ILogRealization* plog = NULL); static LogModule* GetInstance(LogLevel level, ILogRealization* plog = NULL); static LogModule* GetInstancePrintOriginData(LogLevel level, ILogRealization* plog = NULL); @@ -200,7 +200,7 @@ class LogModule { }; #ifdef ENABLE_LOG_DIS_OUTPUT -#define LOG(level,format,...) LogModule::GetInstance(__FILE__, __FUNCTION__, __LINE__,level)->LogPrintInf(format,__VA_ARGS__); +#define LOG(level,format,...) LogModule::GetInstance(level)->LogPrintInf(format,__VA_ARGS__); #define LOG_DEBUG(format,...) LOG(LogModule::DEBUG_LEVEL,format,__VA_ARGS__) #define LOG_INFO(format,...) LOG(LogModule::INFO_LEVEL,format,__VA_ARGS__) #define LOG_WARN(format,...) LOG(LogModule::WARNING_LEVEL,format,__VA_ARGS__) diff --git a/include/ldlidar_driver/network_socket_interface_linux.h b/include/ldlidar_driver/network_socket_interface_linux.h index 6c569f6..7015fc8 100644 --- a/include/ldlidar_driver/network_socket_interface_linux.h +++ b/include/ldlidar_driver/network_socket_interface_linux.h @@ -20,6 +20,8 @@ #ifndef __SOCKET_INTERFACE_LINUX_H__ #define __SOCKET_INTERFACE_LINUX_H__ +#ifdef __linux__ + #include #include #include @@ -120,6 +122,8 @@ class TCPSocketInterfaceLinux { }; } // namespace ldlidar + +#endif // __linux__ #endif // __SOCKET_INTERFACE_LINUX_H__ /********************* (C) COPYRIGHT SHENZHEN LDROBOT CO., LTD *******END OF * FILE ********/ \ No newline at end of file diff --git a/include/ldlidar_driver/serial_interface_linux.h b/include/ldlidar_driver/serial_interface_linux.h index d3e4e94..0a4c606 100644 --- a/include/ldlidar_driver/serial_interface_linux.h +++ b/include/ldlidar_driver/serial_interface_linux.h @@ -20,6 +20,8 @@ #ifndef __LINUX_SERIAL_PORT_H__ #define __LINUX_SERIAL_PORT_H__ +#ifdef __linux__ + #include #include #include @@ -75,7 +77,8 @@ class SerialInterfaceLinux { } // namespace ldlidar -#endif //__LINUX_SERIAL_PORT_H__ +#endif //__linux__ +#endif //__LINUX_SERIAL_PORT_H__ /********************* (C) COPYRIGHT SHENZHEN LDROBOT CO., LTD *******END OF * FILE ********/ \ No newline at end of file diff --git a/include/ldlidar_driver/serial_interface_win.h b/include/ldlidar_driver/serial_interface_win.h index f250548..2f4668c 100644 --- a/include/ldlidar_driver/serial_interface_win.h +++ b/include/ldlidar_driver/serial_interface_win.h @@ -16,14 +16,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#ifndef __WINDOWS_SERIAL_PORT_H__ +#define __WINDOWS_SERIAL_PORT_H__ + +#ifdef WIN32 -#pragma once #include #include #include #include #include +#include struct PortInfo { std::string name; @@ -77,6 +81,10 @@ struct PortParams { }; class SerialInterfaceWin { + private: + std::function commErrorHandle; + std::function readCallback; + public: SerialInterfaceWin(); ~SerialInterfaceWin(); @@ -115,10 +123,9 @@ class SerialInterfaceWin { OVERLAPPED mOverlappedRecv; std::atomic mRxThreadRunFlag; - std::function commErrorHandle; - std::function readCallback; - PortParams portParams; }; +#endif //WIN32 +#endif //__WINDOWS_SERIAL_PORT_H__ /********************* (C) COPYRIGHT LD Robot *******END OF FILE ********/ \ No newline at end of file diff --git a/src/ldlidar_driver.cpp b/src/ldlidar_driver.cpp index f3709c1..6847c4c 100644 --- a/src/ldlidar_driver.cpp +++ b/src/ldlidar_driver.cpp @@ -22,6 +22,13 @@ namespace ldlidar { +uint64_t GetSystemTimeStamp(void) { + std::chrono::time_point tp = + std::chrono::time_point_cast(std::chrono::system_clock::now()); + auto tmp = std::chrono::duration_cast(tp.time_since_epoch()); + return ((uint64_t)tmp.count()); +} + bool LDLidarDriver::is_ok_ = false; LDLidarDriver::LDLidarDriver() : diff --git a/src/ldlidar_driver_linux.cpp b/src/ldlidar_driver_linux.cpp index 00daaf2..0eba874 100644 --- a/src/ldlidar_driver_linux.cpp +++ b/src/ldlidar_driver_linux.cpp @@ -18,6 +18,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +#ifdef __linux__ + #include "ldlidar_driver/ldlidar_driver_linux.h" namespace ldlidar { @@ -28,6 +31,7 @@ LDLidarDriverLinuxInterface::LDLidarDriverLinuxInterface() : comm_pkg_(new LdLi comm_udp_network_(new UDPSocketInterfaceLinux()){ last_pubdata_times_ = std::chrono::steady_clock::now(); + RegisterGetTimestampFunctional(std::bind(GetSystemTimeStamp)); } LDLidarDriverLinuxInterface::~LDLidarDriverLinuxInterface() { @@ -337,5 +341,7 @@ bool LDLidarDriverLinuxInterface::Stop(void) { } } // namespace ldlidar + +#endif //__linux__ /********************* (C) COPYRIGHT SHENZHEN LDROBOT CO., LTD *******END OF * FILE ********/ \ No newline at end of file diff --git a/src/ldlidar_driver_win.cpp b/src/ldlidar_driver_win.cpp index 6eabc02..cadbdce 100644 --- a/src/ldlidar_driver_win.cpp +++ b/src/ldlidar_driver_win.cpp @@ -18,6 +18,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +#ifdef WIN32 + #include "ldlidar_driver/ldlidar_driver_win.h" namespace ldlidar { @@ -27,6 +30,7 @@ LDLidarDriverWinInterface::LDLidarDriverWinInterface() : comm_port_handle_(new SerialInterfaceWin()) { last_pubdata_times_ = std::chrono::steady_clock::now(); + RegisterGetTimestampFunctional(std::bind(GetSystemTimeStamp)); } LDLidarDriverWinInterface::~LDLidarDriverWinInterface() { @@ -226,5 +230,7 @@ bool LDLidarDriverWinInterface::Stop(void) { } } // namespace ldlidar + +#endif //WIN32 /********************* (C) COPYRIGHT SHENZHEN LDROBOT CO., LTD *******END OF * FILE ********/ \ No newline at end of file diff --git a/src/log_module.cpp b/src/log_module.cpp index 5fff546..2bc9ac8 100644 --- a/src/log_module.cpp +++ b/src/log_module.cpp @@ -32,23 +32,6 @@ LogModule* LogModule::s_plog_module_ = NULL; - -LogModule* LogModule::GetInstance(__in const char* filename, __in const char* funcname, __in int lineno,LogLevel level,ILogRealization* plog) { - if (s_plog_module_ == NULL) { - s_plog_module_ = new LogModule(); - } - s_plog_module_->logInfo_.str_filename = filename; - s_plog_module_->logInfo_.str_funcname = funcname; - s_plog_module_->logInfo_.n_linenumber = lineno; - s_plog_module_->logInfo_.loglevel = level; - - if (plog != NULL) { - s_plog_module_->p_realization_->free(); - s_plog_module_->p_realization_ = plog; - } - return s_plog_module_; -} - LogModule* LogModule::GetInstance(LogLevel level, ILogRealization* plog) { if (s_plog_module_ == NULL) { s_plog_module_ = new LogModule(); diff --git a/src/network_socket_interface_linux.cpp b/src/network_socket_interface_linux.cpp index 5eb138d..e2aeaca 100644 --- a/src/network_socket_interface_linux.cpp +++ b/src/network_socket_interface_linux.cpp @@ -17,9 +17,12 @@ * limitations under the License. */ +#ifdef __linux__ + #include "ldlidar_driver/network_socket_interface_linux.h" #include "ldlidar_driver/log_module.h" + #define MAX_RECV_BUF_LEN 4096 namespace ldlidar { @@ -454,5 +457,6 @@ void TCPSocketInterfaceLinux::RecvThreadProc(void *param) { } } // namespace ldlidar +#endif //__linux__ /********************* (C) COPYRIGHT SHENZHEN LDROBOT CO., LTD *******END OF * FILE ********/ \ No newline at end of file diff --git a/src/serial_interface_linux.cpp b/src/serial_interface_linux.cpp index dbbadcf..be9514e 100644 --- a/src/serial_interface_linux.cpp +++ b/src/serial_interface_linux.cpp @@ -20,6 +20,7 @@ #include "ldlidar_driver/serial_interface_linux.h" #include "ldlidar_driver/log_module.h" +#ifdef __linux__ #define MAX_ACK_BUF_LEN 4096 @@ -179,6 +180,6 @@ void SerialInterfaceLinux::RxThreadProc(void *param) { } } // namespace ldlidar - +#endif //__linux__ /********************* (C) COPYRIGHT SHENZHEN LDROBOT CO., LTD *******END OF * FILE ********/ \ No newline at end of file diff --git a/src/serial_interface_win.cpp b/src/serial_interface_win.cpp index c5a52c8..21ec469 100644 --- a/src/serial_interface_win.cpp +++ b/src/serial_interface_win.cpp @@ -17,6 +17,8 @@ * limitations under the License. */ +#ifdef WIN32 + #include "ldlidar_driver/serial_interface_win.h" #include "ldlidar_driver/log_module.h" @@ -323,4 +325,6 @@ void SerialInterfaceWin::rxThreadProc(SerialInterfaceWin *pClass) { delete[] rxBuf; } + +#endif //WIN32 /********************* (C) COPYRIGHT LD Robot *******END OF FILE ********/