From 810e9e174f88ea4742c198337623fabfbd63cc05 Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Wed, 21 Apr 2021 09:29:36 -0700 Subject: [PATCH] distance_sensor: Use inttypes --- .../lightware_laser_i2c.cpp | 6 +++--- .../lightware_laser_serial.cpp | 5 +++-- .../distance_sensor/ll40ls/LidarLiteI2C.cpp | 20 +++++++++---------- .../ll40ls_pwm/LidarLitePWM.cpp | 4 ++-- .../distance_sensor/ll40ls_pwm/LidarLitePWM.h | 2 +- src/drivers/distance_sensor/srf05/SRF05.cpp | 2 +- .../distance_sensor/teraranger/TERARANGER.cpp | 9 ++++----- .../distance_sensor/teraranger/TERARANGER.hpp | 2 +- src/drivers/distance_sensor/tfmini/TFMINI.cpp | 4 ++-- src/drivers/distance_sensor/tfmini/TFMINI.hpp | 2 +- 10 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/drivers/distance_sensor/lightware_laser_i2c/lightware_laser_i2c.cpp b/src/drivers/distance_sensor/lightware_laser_i2c/lightware_laser_i2c.cpp index 0ed849188e..2a8f470509 100644 --- a/src/drivers/distance_sensor/lightware_laser_i2c/lightware_laser_i2c.cpp +++ b/src/drivers/distance_sensor/lightware_laser_i2c/lightware_laser_i2c.cpp @@ -200,7 +200,7 @@ int LightwareLaser::init() break; default: - PX4_ERR("invalid HW model %d.", hw_model); + PX4_ERR("invalid HW model %" PRId32 ".", hw_model); return ret; } @@ -265,7 +265,7 @@ int LightwareLaser::enableI2CBinaryProtocol() return ret; } - PX4_DEBUG("protocol values: 0x%x 0x%x", value[0], value[1]); + PX4_DEBUG("protocol values: 0x%" PRIx8 " 0x%" PRIx8, value[0], value[1]); return (value[0] == 0xcc && value[1] == 0x00) ? 0 : -1; } @@ -348,7 +348,7 @@ int LightwareLaser::collect() perf_end(_sample_perf); // compare different outputs (median filter adds about 25ms delay) - PX4_DEBUG("fm: %4i, fs: %2i%%, lm: %4i, lr: %4i, fs: %2i%%, n: %i", + PX4_DEBUG("fm: %4" PRIi16 ", fs: %2" PRIi16 "%%, lm: %4" PRIi16 ", lr: %4" PRIi16 ", fs: %2" PRIi16 "%%, n: %" PRIi16, data.first_return_median, data.first_return_strength, data.last_return_median, data.last_return_raw, data.last_return_strength, data.background_noise); diff --git a/src/drivers/distance_sensor/lightware_laser_serial/lightware_laser_serial.cpp b/src/drivers/distance_sensor/lightware_laser_serial/lightware_laser_serial.cpp index 34716cbc2e..c6e7571492 100644 --- a/src/drivers/distance_sensor/lightware_laser_serial/lightware_laser_serial.cpp +++ b/src/drivers/distance_sensor/lightware_laser_serial/lightware_laser_serial.cpp @@ -1,6 +1,6 @@ /**************************************************************************** * - * Copyright (c) 2014-2019 PX4 Development Team. All rights reserved. + * Copyright (c) 2014-2019, 2021 PX4 Development Team. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -33,6 +33,7 @@ #include "lightware_laser_serial.hpp" +#include #include #include @@ -127,7 +128,7 @@ LightwareLaserSerial::init() break; default: - PX4_ERR("invalid HW model %d.", hw_model); + PX4_ERR("invalid HW model %" PRIi32 ".", hw_model); return -1; } diff --git a/src/drivers/distance_sensor/ll40ls/LidarLiteI2C.cpp b/src/drivers/distance_sensor/ll40ls/LidarLiteI2C.cpp index 562afbe36d..e009db68d2 100644 --- a/src/drivers/distance_sensor/ll40ls/LidarLiteI2C.cpp +++ b/src/drivers/distance_sensor/ll40ls/LidarLiteI2C.cpp @@ -1,6 +1,6 @@ /**************************************************************************** * - * Copyright (c) 2014-2019 PX4 Development Team. All rights reserved. + * Copyright (c) 2014-2019, 2021 PX4 Development Team. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -83,7 +83,7 @@ LidarLiteI2C::print_status() perf_print_counter(_comms_errors); perf_print_counter(_sensor_resets); perf_print_counter(_sensor_zero_resets); - printf("poll interval: %u \n", get_measure_interval()); + printf("poll interval: %" PRIu32 "\n", get_measure_interval()); } int @@ -152,12 +152,12 @@ LidarLiteI2C::probe() if (_unit_id > 0) { // v2 - PX4_INFO("probe success - hw: %u, sw:%u, id: %u", _hw_version, _sw_version, _unit_id); + PX4_INFO("probe success - hw: %" PRIu8 ", sw:%" PRIu8 ", id: %" PRIu16, _hw_version, _sw_version, _unit_id); _px4_rangefinder.set_max_distance(LL40LS_MAX_DISTANCE_V2); } else { // v1 and v3 - PX4_INFO("probe success - hw: %u, sw:%u", _hw_version, _sw_version); + PX4_INFO("probe success - hw: %" PRIu8 ", sw:%" PRIu8, _hw_version, _sw_version); } } else { @@ -165,7 +165,7 @@ LidarLiteI2C::probe() if (_unit_id > 0) { // v3hp _is_v3hp = true; - PX4_INFO("probe success - id: %u", _unit_id); + PX4_INFO("probe success - id: %" PRIu16, _unit_id); } } @@ -173,10 +173,8 @@ LidarLiteI2C::probe() return OK; } - PX4_DEBUG("probe failed unit_id=0x%02x hw_version=0x%02x sw_version=0x%02x", - (unsigned)_unit_id, - (unsigned)_hw_version, - (unsigned)_sw_version); + PX4_DEBUG("probe failed unit_id=0x%02" PRIx16 " hw_version=0x%02" PRIu8 " sw_version=0x%02" PRIu8, + _unit_id, _hw_version, _sw_version); } @@ -273,10 +271,10 @@ LidarLiteI2C::print_registers() int ret = lidar_transfer(®, 1, &val, 1); if (ret != OK) { - printf("%02x:XX ", (unsigned)reg); + printf("%02" PRIx8 ":XX ", reg); } else { - printf("%02x:%02x ", (unsigned)reg, (unsigned)val); + printf("%02" PRIx8 ":%02" PRIu8, reg, val); } if (reg % 16 == 15) { diff --git a/src/drivers/distance_sensor/ll40ls_pwm/LidarLitePWM.cpp b/src/drivers/distance_sensor/ll40ls_pwm/LidarLitePWM.cpp index 0d3a4a0754..4006e66401 100644 --- a/src/drivers/distance_sensor/ll40ls_pwm/LidarLitePWM.cpp +++ b/src/drivers/distance_sensor/ll40ls_pwm/LidarLitePWM.cpp @@ -1,6 +1,6 @@ /**************************************************************************** * - * Copyright (c) 2014-2019 PX4 Development Team. All rights reserved. + * Copyright (c) 2014-2019, 2021 PX4 Development Team. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -145,7 +145,7 @@ LidarLitePWM::print_info() perf_print_counter(_comms_errors); perf_print_counter(_sensor_resets); perf_print_counter(_sensor_zero_resets); - printf("poll interval: %u \n", get_measure_interval()); + printf("poll interval: %" PRIu32 " \n", get_measure_interval()); } #endif diff --git a/src/drivers/distance_sensor/ll40ls_pwm/LidarLitePWM.h b/src/drivers/distance_sensor/ll40ls_pwm/LidarLitePWM.h index 1da621f8e9..55786ab4cf 100644 --- a/src/drivers/distance_sensor/ll40ls_pwm/LidarLitePWM.h +++ b/src/drivers/distance_sensor/ll40ls_pwm/LidarLitePWM.h @@ -1,6 +1,6 @@ /**************************************************************************** * - * Copyright (c) 2014-2019 PX4 Development Team. All rights reserved. + * Copyright (c) 2014-2019, 2021 PX4 Development Team. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/src/drivers/distance_sensor/srf05/SRF05.cpp b/src/drivers/distance_sensor/srf05/SRF05.cpp index 76ba2eb502..f8b7cc2a47 100644 --- a/src/drivers/distance_sensor/srf05/SRF05.cpp +++ b/src/drivers/distance_sensor/srf05/SRF05.cpp @@ -245,7 +245,7 @@ SRF05::print_status() perf_print_counter(_sample_perf); perf_print_counter(_comms_errors); perf_print_counter(_sensor_resets); - printf("poll interval: %u \n", get_measure_interval()); + printf("poll interval: %" PRIu32 " \n", get_measure_interval()); return 0; } diff --git a/src/drivers/distance_sensor/teraranger/TERARANGER.cpp b/src/drivers/distance_sensor/teraranger/TERARANGER.cpp index 507a8460f4..4a7456d858 100644 --- a/src/drivers/distance_sensor/teraranger/TERARANGER.cpp +++ b/src/drivers/distance_sensor/teraranger/TERARANGER.cpp @@ -1,6 +1,6 @@ /**************************************************************************** * - * Copyright (c) 2013-2020 PX4 Development Team. All rights reserved. + * Copyright (c) 2013-2021 PX4 Development Team. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -208,7 +208,7 @@ int TERARANGER::init() break; default: - PX4_ERR("invalid HW model %d.", hw_model); + PX4_ERR("invalid HW model %" PRId32 ".", hw_model); return PX4_ERROR; } @@ -244,9 +244,8 @@ int TERARANGER::probe() } } - PX4_DEBUG("WHO_AM_I byte mismatch 0x%02x should be 0x%02x\n", - (unsigned)who_am_i, - TERARANGER_WHO_AM_I_REG_VAL); + PX4_DEBUG("WHO_AM_I byte mismatch 0x%02" PRIx8 " should be 0x%02" PRIx8 "\n", + who_am_i, TERARANGER_WHO_AM_I_REG_VAL); // Not found on any address. return -EIO; diff --git a/src/drivers/distance_sensor/teraranger/TERARANGER.hpp b/src/drivers/distance_sensor/teraranger/TERARANGER.hpp index 6351f30cd4..e1f9facd19 100644 --- a/src/drivers/distance_sensor/teraranger/TERARANGER.hpp +++ b/src/drivers/distance_sensor/teraranger/TERARANGER.hpp @@ -1,6 +1,6 @@ /**************************************************************************** * - * Copyright (c) 2013-2020 PX4 Development Team. All rights reserved. + * Copyright (c) 2013-2021 PX4 Development Team. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/src/drivers/distance_sensor/tfmini/TFMINI.cpp b/src/drivers/distance_sensor/tfmini/TFMINI.cpp index d20a20b4c2..150d1c486d 100644 --- a/src/drivers/distance_sensor/tfmini/TFMINI.cpp +++ b/src/drivers/distance_sensor/tfmini/TFMINI.cpp @@ -1,6 +1,6 @@ /**************************************************************************** * - * Copyright (c) 2017-2019 PX4 Development Team. All rights reserved. + * Copyright (c) 2017-2019, 2021 PX4 Development Team. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -88,7 +88,7 @@ TFMINI::init() break; default: - PX4_ERR("invalid HW model %d.", hw_model); + PX4_ERR("invalid HW model %" PRId32 ".", hw_model); return -1; } diff --git a/src/drivers/distance_sensor/tfmini/TFMINI.hpp b/src/drivers/distance_sensor/tfmini/TFMINI.hpp index ba1e0055c2..027d73fa52 100644 --- a/src/drivers/distance_sensor/tfmini/TFMINI.hpp +++ b/src/drivers/distance_sensor/tfmini/TFMINI.hpp @@ -1,6 +1,6 @@ /**************************************************************************** * - * Copyright (c) 2017-2019 PX4 Development Team. All rights reserved. + * Copyright (c) 2017-2019, 2021 PX4 Development Team. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions