Skip to content

Commit

Permalink
[update]版本号v3.0.2,修复32位系统下日志打印时间戳uint64_t数据格式不对问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ldrobotsensor committed Oct 25, 2022
1 parent bf34b12 commit 224fefa
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
4 changes: 2 additions & 2 deletions ldlidar_driver/include/logger/log_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ class LogModule {

std::string GetCurrentTime();

inline int64_t GetCurrentLocalTimeStamp() {
inline uint64_t GetCurrentLocalTimeStamp() {
//// 获取系统时间戳
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> tp =
std::chrono::time_point_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now());
auto tmp = std::chrono::duration_cast<std::chrono::nanoseconds>(tp.time_since_epoch());
return tmp.count();
return (uint64_t)tmp.count();
}

std::string GetFormatValue(std::string str_value);
Expand Down
2 changes: 1 addition & 1 deletion ldlidar_driver/src/core/ldlidar_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace ldlidar {

bool LDLidarDriver::is_ok_ = false;

LDLidarDriver::LDLidarDriver() : sdk_pack_version_("3.0.1"),
LDLidarDriver::LDLidarDriver() : sdk_pack_version_("3.0.2"),
is_start_flag_(false),
comm_pkg_(new LiPkg()),
comm_serial_(new SerialInterfaceLinux()){
Expand Down
24 changes: 20 additions & 4 deletions ldlidar_driver/src/logger/log_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,16 @@ void LogModule::LogPrintInf(const char* format,...) {
case DEBUG_LEVEL: {
//时间戳 uint is seconds
char s_stamp[100] = {0};
int64_t timestamp = GetCurrentLocalTimeStamp();
snprintf(s_stamp, 100, "[%ld.%ld]", (timestamp/1000000000), (timestamp%1000000000));
uint64_t timestamp = GetCurrentLocalTimeStamp();
#ifdef __LP64__
snprintf(s_stamp, 100, "[%lu.%lu]", (timestamp/1000000000), (timestamp%1000000000));
#else
#ifdef _WIN64
snprintf(s_stamp, 100, "[%lu.%lu]", (timestamp/1000000000), (timestamp%1000000000));
#else
snprintf(s_stamp, 100, "[%llu.%llu]", (timestamp/1000000000), (timestamp%1000000000));
#endif
#endif
str_temp.append(s_stamp);
}
break;
Expand Down Expand Up @@ -132,8 +140,16 @@ void LogModule::LogPrintNoLocationInf(const char* format,...) {

//时间戳 uint is seconds
char s_stamp[100] = {0};
int64_t timestamp = GetCurrentLocalTimeStamp();
snprintf(s_stamp, 100, "[%ld.%ld]", (timestamp/1000000000), (timestamp%1000000000));
uint64_t timestamp = GetCurrentLocalTimeStamp();
#ifdef __LP64__
snprintf(s_stamp, 100, "[%lu.%lu]", (timestamp/1000000000), (timestamp%1000000000));
#else
#ifdef _WIN64
snprintf(s_stamp, 100, "[%lu.%lu]", (timestamp/1000000000), (timestamp%1000000000));
#else
snprintf(s_stamp, 100, "[%llu.%llu]", (timestamp/1000000000), (timestamp%1000000000));
#endif
#endif
str_temp.append(s_stamp);

va_list ptr;
Expand Down
12 changes: 10 additions & 2 deletions src/linux_demo/demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,21 @@ int main(int argc, char **argv) {
case ldlidar::LidarStatus::NORMAL: {
double lidar_spin_freq = 0;
node->GetLidarSpinFreq(lidar_spin_freq);

#ifdef __LP64__
LDS_LOG_INFO("speed(Hz):%f, size:%d,stamp_front:%lu, stamp_back:%lu",
lidar_spin_freq, laser_scan_points.size(), laser_scan_points.front().stamp, laser_scan_points.back().stamp);

#else
LDS_LOG_INFO("speed(Hz):%f, size:%d,stamp_front:%llu, stamp_back:%llu",
lidar_spin_freq, laser_scan_points.size(), laser_scan_points.front().stamp, laser_scan_points.back().stamp);
#endif
for (auto point : laser_scan_points) {
#ifdef __LP64__
LDS_LOG_INFO("stamp(ns):%lu,angle:%f,distance(mm):%d,intensity:%d",
point.stamp, point.angle, point.distance, point.intensity);
#else
LDS_LOG_INFO("stamp(ns):%llu,angle:%f,distance(mm):%d,intensity:%d",
point.stamp, point.angle, point.distance, point.intensity);
#endif
}
break;
}
Expand Down

0 comments on commit 224fefa

Please sign in to comment.