diff --git a/components/ocs_algo/bit_ops.cpp b/components/ocs_algo/bit_ops.cpp index b98e7137..d873ea28 100644 --- a/components/ocs_algo/bit_ops.cpp +++ b/components/ocs_algo/bit_ops.cpp @@ -8,15 +8,15 @@ namespace ocs { namespace algo { -unsigned BitOps::mask(uint8_t pos) { +uint32_t BitOps::mask(uint8_t pos) { return (1UL << pos); } -unsigned BitOps::umask(uint8_t pos) { +uint32_t BitOps::umask(uint8_t pos) { return ~(mask(pos)); } -uint8_t BitOps::nth(unsigned value, uint8_t pos) { +uint8_t BitOps::nth(uint32_t value, uint8_t pos) { return mask(pos) & value ? 1 : 0; } diff --git a/components/ocs_algo/bit_ops.h b/components/ocs_algo/bit_ops.h index 087ab69d..2e266bf3 100644 --- a/components/ocs_algo/bit_ops.h +++ b/components/ocs_algo/bit_ops.h @@ -12,13 +12,13 @@ namespace algo { struct BitOps { //! Create a mask with the n-th bit set. - static unsigned mask(uint8_t pos); + static uint32_t mask(uint8_t pos); //! Create a mask with the n-th bit unset. - static unsigned umask(uint8_t pos); + static uint32_t umask(uint8_t pos); //! Return the n-th bit of the value. - static uint8_t nth(unsigned value, uint8_t pos); + static uint8_t nth(uint32_t value, uint8_t pos); //! Return 16-bit value from two 8-bit values. static uint16_t pack_u8(uint8_t hi, uint8_t lo); diff --git a/components/ocs_algo/container_ops.h b/components/ocs_algo/container_ops.h index 2166ac4a..21f7a086 100644 --- a/components/ocs_algo/container_ops.h +++ b/components/ocs_algo/container_ops.h @@ -38,9 +38,9 @@ struct StringEqual { //! @notes //! Based on combine hash implementation in boost: //! https://www.boost.org/doc/libs/1_35_0/doc/html/boost/hash_combine_id241013.html -template struct ArrayHasher { - unsigned operator()(const std::array& arr) const { - unsigned h = 0; +template struct ArrayHasher { + size_t operator()(const std::array& arr) const { + size_t h = 0; for (const auto& e : arr) { h ^= std::hash {}(e) + 0x9e3779b9 + (h << 6) + (h >> 2); diff --git a/components/ocs_algo/crc_ops.cpp b/components/ocs_algo/crc_ops.cpp index 35412456..fbb089a2 100644 --- a/components/ocs_algo/crc_ops.cpp +++ b/components/ocs_algo/crc_ops.cpp @@ -9,14 +9,14 @@ namespace ocs { namespace algo { uint8_t CrcOps::crc8(const uint8_t* buf, - unsigned size, + size_t size, uint8_t initial, uint8_t polynomial, CrcOps::BitOrder order) { // Initialize shift register. uint8_t crc = initial; - for (unsigned n = 0; n < size; ++n) { + for (size_t n = 0; n < size; ++n) { // XOR data byte with current CRC. crc ^= buf[n]; diff --git a/components/ocs_algo/crc_ops.h b/components/ocs_algo/crc_ops.h index 37bead51..056d1897 100644 --- a/components/ocs_algo/crc_ops.h +++ b/components/ocs_algo/crc_ops.h @@ -5,6 +5,7 @@ #pragma once +#include #include namespace ocs { @@ -26,7 +27,7 @@ struct CrcOps { //! @references //! https://www.boost.org/doc/libs/1_84_0/doc/html/crc/crc_optimal.html static uint8_t crc8(const uint8_t* buf, - unsigned size, + size_t size, uint8_t initial, uint8_t polynomial, BitOrder order); diff --git a/components/ocs_algo/math_ops.cpp b/components/ocs_algo/math_ops.cpp index a77d16e1..07bdd282 100644 --- a/components/ocs_algo/math_ops.cpp +++ b/components/ocs_algo/math_ops.cpp @@ -10,7 +10,7 @@ namespace ocs { namespace algo { -double MathOps::round_floor(double value, unsigned decimal_places) { +double MathOps::round_floor(double value, uint8_t decimal_places) { const auto multiplier = std::pow(10.0, decimal_places); const auto ret = std::floor(value * multiplier) / multiplier; return ret; diff --git a/components/ocs_algo/math_ops.h b/components/ocs_algo/math_ops.h index 63035704..3e298dd6 100644 --- a/components/ocs_algo/math_ops.h +++ b/components/ocs_algo/math_ops.h @@ -10,7 +10,7 @@ namespace algo { struct MathOps { //! Round @p value down to @p decimal_places. - static double round_floor(double value, unsigned decimal_places); + static double round_floor(double value, uint8_t decimal_places); }; } // namespace algo diff --git a/components/ocs_algo/sha_engine_ops.h b/components/ocs_algo/sha_engine_ops.h index 2d507d20..bed8e841 100644 --- a/components/ocs_algo/sha_engine_ops.h +++ b/components/ocs_algo/sha_engine_ops.h @@ -14,7 +14,7 @@ namespace algo { struct ShaEngineOps { //! Return the maximum number of bytes the SHA algorithm can produce on the output. - static constexpr unsigned hash_lenght(security::IShaEngine::Algorithm algorithm) { + static constexpr size_t hash_lenght(security::IShaEngine::Algorithm algorithm) { switch (algorithm) { case security::IShaEngine::Algorithm::SHA1: return 20; diff --git a/components/ocs_algo/storage_ops.cpp b/components/ocs_algo/storage_ops.cpp index 7ddd53d1..b9e58d6d 100644 --- a/components/ocs_algo/storage_ops.cpp +++ b/components/ocs_algo/storage_ops.cpp @@ -19,8 +19,8 @@ const char* log_tag = "storage_ops"; status::StatusCode StorageOps::prob_read(storage::IStorage& storage, const char* key, void* buf, - unsigned size) { - unsigned recv_size = 0; + size_t size) { + size_t recv_size = 0; auto code = storage.probe(key, recv_size); if (code != status::StatusCode::OK) { if (code != status::StatusCode::NoData) { diff --git a/components/ocs_algo/storage_ops.h b/components/ocs_algo/storage_ops.h index 930c3bb8..c9d02077 100644 --- a/components/ocs_algo/storage_ops.h +++ b/components/ocs_algo/storage_ops.h @@ -13,7 +13,7 @@ namespace algo { struct StorageOps { //! Read string with @p key from @p storage to @p buf which can hold @p size bytes. static status::StatusCode - prob_read(storage::IStorage& storage, const char* key, void* buf, unsigned size); + prob_read(storage::IStorage& storage, const char* key, void* buf, size_t size); }; } // namespace algo diff --git a/components/ocs_algo/test/test_storage_ops.cpp b/components/ocs_algo/test/test_storage_ops.cpp index 119bb15e..fb18e1ca 100644 --- a/components/ocs_algo/test/test_storage_ops.cpp +++ b/components/ocs_algo/test/test_storage_ops.cpp @@ -17,7 +17,7 @@ TEST_CASE("Storage Ops: prob read: empty storage", "[ocs_algo], [storage_ops]") test::MemoryStorage storage; - unsigned recv_value = 0; + size_t recv_value = 0; TEST_ASSERT_EQUAL( status::StatusCode::NoData, @@ -29,17 +29,17 @@ TEST_CASE("Storage Ops: prob read: empty storage", "[ocs_algo], [storage_ops]") TEST_CASE("Storage Ops: prob read: invalid key", "[ocs_algo], [storage_ops]") { const char* key = "foo"; const char* invalid_key = "bar"; - const unsigned value = 42; + const size_t value = 42; test::MemoryStorage storage; TEST_ASSERT_EQUAL(status::StatusCode::OK, storage.write(key, &value, sizeof(value))); - unsigned size = 0; + size_t size = 0; TEST_ASSERT_EQUAL(status::StatusCode::OK, storage.probe(key, size)); TEST_ASSERT_EQUAL(size, sizeof(value)); - unsigned recv_value = 0; + size_t recv_value = 0; TEST_ASSERT_EQUAL( status::StatusCode::NoData, @@ -50,13 +50,13 @@ TEST_CASE("Storage Ops: prob read: invalid key", "[ocs_algo], [storage_ops]") { TEST_CASE("Storage Ops: prob read: size mismatch", "[ocs_algo], [storage_ops]") { const char* key = "foo"; - const unsigned value = 42; + const size_t value = 42; test::MemoryStorage storage; TEST_ASSERT_EQUAL(status::StatusCode::OK, storage.write(key, &value, sizeof(value))); - unsigned recv_value = 0; + size_t recv_value = 0; TEST_ASSERT_EQUAL( status::StatusCode::InvalidArg, @@ -67,7 +67,7 @@ TEST_CASE("Storage Ops: prob read: size mismatch", "[ocs_algo], [storage_ops]") TEST_CASE("Storage Ops: prob read: prob failed", "[ocs_algo], [storage_ops]") { const char* key = "foo"; - const unsigned value = 42; + const size_t value = 42; test::MemoryStorage memory_storage; test::StatusStorage storage(memory_storage); @@ -75,7 +75,7 @@ TEST_CASE("Storage Ops: prob read: prob failed", "[ocs_algo], [storage_ops]") { TEST_ASSERT_EQUAL(status::StatusCode::OK, storage.write(key, &value, sizeof(value))); - unsigned recv_value = 0; + size_t recv_value = 0; TEST_ASSERT_EQUAL( storage.probe_status, @@ -86,7 +86,7 @@ TEST_CASE("Storage Ops: prob read: prob failed", "[ocs_algo], [storage_ops]") { TEST_CASE("Storage Ops: prob read: read failed", "[ocs_algo], [storage_ops]") { const char* key = "foo"; - const unsigned value = 42; + const size_t value = 42; test::MemoryStorage memory_storage; test::StatusStorage storage(memory_storage); @@ -94,7 +94,7 @@ TEST_CASE("Storage Ops: prob read: read failed", "[ocs_algo], [storage_ops]") { TEST_ASSERT_EQUAL(status::StatusCode::OK, storage.write(key, &value, sizeof(value))); - unsigned recv_value = 0; + size_t recv_value = 0; TEST_ASSERT_EQUAL( storage.read_status, @@ -105,13 +105,13 @@ TEST_CASE("Storage Ops: prob read: read failed", "[ocs_algo], [storage_ops]") { TEST_CASE("Storage Ops: prob read: properly read", "[ocs_algo], [storage_ops]") { const char* key = "foo"; - const unsigned value = 42; + const size_t value = 42; test::MemoryStorage storage; TEST_ASSERT_EQUAL(status::StatusCode::OK, storage.write(key, &value, sizeof(value))); - unsigned recv_value = 0; + size_t recv_value = 0; TEST_ASSERT_EQUAL( status::StatusCode::OK, diff --git a/components/ocs_algo/uri_ops.cpp b/components/ocs_algo/uri_ops.cpp index 67c409a0..08de2e7a 100644 --- a/components/ocs_algo/uri_ops.cpp +++ b/components/ocs_algo/uri_ops.cpp @@ -36,7 +36,7 @@ UriOps::Path UriOps::parse_path(const char* uri) { return std::string_view(); } - unsigned path_length = 0; + size_t path_length = 0; const char* query_start = strchr(uri, '?'); if (query_start != nullptr) { diff --git a/components/ocs_control/flip_led_task.cpp b/components/ocs_control/flip_led_task.cpp index 48c3e749..52b1aa77 100644 --- a/components/ocs_control/flip_led_task.cpp +++ b/components/ocs_control/flip_led_task.cpp @@ -14,7 +14,7 @@ namespace control { FlipLedTask::FlipLedTask(scheduler::IEventHandler& handler, ILed& led, ILed::Priority priority, - unsigned flip_count) + size_t flip_count) : priority_(priority) , flip_count_(flip_count) , handler_(handler) diff --git a/components/ocs_control/flip_led_task.h b/components/ocs_control/flip_led_task.h index a62caedc..304d0cff 100644 --- a/components/ocs_control/flip_led_task.h +++ b/components/ocs_control/flip_led_task.h @@ -25,7 +25,7 @@ class FlipLedTask : public scheduler::ITask, private core::NonCopyable<> { FlipLedTask(scheduler::IEventHandler& handler, ILed& led, ILed::Priority priority, - unsigned flip_count); + size_t flip_count); //! Flip LED on each task run. //! @@ -40,7 +40,7 @@ class FlipLedTask : public scheduler::ITask, private core::NonCopyable<> { private: const ILed::Priority priority_ { ILed::Priority::None }; - unsigned flip_count_ { 0 }; + size_t flip_count_ { 0 }; scheduler::IEventHandler& handler_; ILed& led_; diff --git a/components/ocs_control/system_fsm.cpp b/components/ocs_control/system_fsm.cpp index 20156572..c9f0522a 100644 --- a/components/ocs_control/system_fsm.cpp +++ b/components/ocs_control/system_fsm.cpp @@ -245,7 +245,7 @@ void SystemFsm::add_fsr_task_() { == status::StatusCode::OK); } -void SystemFsm::add_led_task_(unsigned flip_count) { +void SystemFsm::add_led_task_(size_t flip_count) { configASSERT(!task_); task_.reset(new (std::nothrow) diff --git a/components/ocs_control/system_fsm.h b/components/ocs_control/system_fsm.h index 14ac4b2c..c0caad1a 100644 --- a/components/ocs_control/system_fsm.h +++ b/components/ocs_control/system_fsm.h @@ -91,14 +91,14 @@ class SystemFsm : public IButtonHandler, void handle_state_fsr_done_(); void add_fsr_task_(); - void add_led_task_(unsigned flip_count); + void add_led_task_(size_t flip_count); void remove_task_(); bool button_was_pressed_(); static constexpr system::Time task_interval_ = system::Duration::second / 2; - static constexpr unsigned flip_count_init_ = 6; - static constexpr unsigned flip_count_button_pressed_ = 2; + static constexpr uint8_t flip_count_init_ = 6; + static constexpr uint8_t flip_count_button_pressed_ = 2; static constexpr const char* task_id_ = "sys_fsm_led"; const Params params_; diff --git a/components/ocs_control/test/test_button_event_handler.cpp b/components/ocs_control/test/test_button_event_handler.cpp index 5f6d92df..aa2ecc51 100644 --- a/components/ocs_control/test/test_button_event_handler.cpp +++ b/components/ocs_control/test/test_button_event_handler.cpp @@ -23,7 +23,7 @@ struct TestButton : public IButton, private core::NonCopyable<> { struct TestButtonHandler : public IButtonHandler, private core::NonCopyable<> { system::Time pressed_duration { 0 }; - unsigned pressed_call_count { 0 }; + size_t pressed_call_count { 0 }; status::StatusCode handle_pressed(system::Time duration) { pressed_duration = duration; diff --git a/components/ocs_control/test/test_fsm_block.cpp b/components/ocs_control/test/test_fsm_block.cpp index 6b6f2572..8e21f4fb 100644 --- a/components/ocs_control/test/test_fsm_block.cpp +++ b/components/ocs_control/test/test_fsm_block.cpp @@ -97,7 +97,7 @@ TEST_CASE("FSM block: transit: save state", "[ocs_control], [fsm_block]") { const system::Time resolution = system::Duration::second; const char* id = "block_id"; uint64_t write_count = 17; - const unsigned state_duration = 42; + const size_t state_duration = 42; TestFsmBlockStorage storage; storage.write_count = write_count; @@ -141,7 +141,7 @@ TEST_CASE("FSM block: transit: failed to save state", "[ocs_control], [fsm_block const system::Time resolution = system::Duration::second; const char* id = "block_id"; const uint64_t write_count = 17; - const unsigned state_duration = 42; + const size_t state_duration = 42; TestFsmBlockStorage storage; storage.write_count = write_count; diff --git a/components/ocs_control/test/test_fsm_block_storage.cpp b/components/ocs_control/test/test_fsm_block_storage.cpp index ae513a07..d80e1142 100644 --- a/components/ocs_control/test/test_fsm_block_storage.cpp +++ b/components/ocs_control/test/test_fsm_block_storage.cpp @@ -21,11 +21,11 @@ TestFsmBlockStorage::TestFsmBlockStorage(status::StatusCode read_status, , erase_status(erase_status) { } -status::StatusCode TestFsmBlockStorage::probe(const char* key, unsigned& size) { +status::StatusCode TestFsmBlockStorage::probe(const char* key, size_t& size) { return status::StatusCode::Error; } -status::StatusCode TestFsmBlockStorage::read(const char* key, void* data, unsigned size) { +status::StatusCode TestFsmBlockStorage::read(const char* key, void* data, size_t size) { if (read_status != status::StatusCode::OK) { return read_status; } @@ -53,7 +53,7 @@ status::StatusCode TestFsmBlockStorage::read(const char* key, void* data, unsign } status::StatusCode -TestFsmBlockStorage::write(const char* key, const void* data, unsigned size) { +TestFsmBlockStorage::write(const char* key, const void* data, size_t size) { if (write_status != status::StatusCode::OK) { return write_status; } diff --git a/components/ocs_control/test/test_fsm_store.cpp b/components/ocs_control/test/test_fsm_store.cpp index 226ecd74..1a31b61b 100644 --- a/components/ocs_control/test/test_fsm_store.cpp +++ b/components/ocs_control/test/test_fsm_store.cpp @@ -51,8 +51,8 @@ class TestHandler : public IFsmHandler, private core::NonCopyable<> { return status::StatusCode::OK; } - unsigned handle_state_count { 0 }; - unsigned handle_transit_count { 0 }; + size_t handle_state_count { 0 }; + size_t handle_transit_count { 0 }; status::StatusCode state_result { status::StatusCode::OK }; status::StatusCode transit_result { status::StatusCode::OK }; diff --git a/components/ocs_control/test/test_led_locator.cpp b/components/ocs_control/test/test_led_locator.cpp index 4f774b6e..6793135a 100644 --- a/components/ocs_control/test/test_led_locator.cpp +++ b/components/ocs_control/test/test_led_locator.cpp @@ -28,7 +28,7 @@ class AsyncTestRunner : private core::NonCopyable<> { public: AsyncTestRunner(scheduler::ITaskScheduler& task_scheduler, const char* id, - unsigned stack_size) + size_t stack_size) : id_(id) , stack_size_(stack_size) , task_scheduler_(task_scheduler) { @@ -69,7 +69,7 @@ class AsyncTestRunner : private core::NonCopyable<> { } const std::string id_; - const unsigned stack_size_ { 0 }; + const size_t stack_size_ { 0 }; scheduler::ITaskScheduler& task_scheduler_; @@ -104,7 +104,7 @@ TEST_CASE("LED locator: turn-on/turn-off/flip", "[ocs_control], [led_locator]") TEST_ASSERT_TRUE(locator.get()); auto get_flip_count = [](test::TestGpio& gpio, scheduler::AsyncFuncScheduler& ash) { - unsigned ret = 0; + size_t ret = 0; auto future = ash.add([&gpio, &ret]() { ret = gpio.flip_call_count; @@ -119,7 +119,7 @@ TEST_CASE("LED locator: turn-on/turn-off/flip", "[ocs_control], [led_locator]") return ret; }; - unsigned last_flip_count = 0; + size_t last_flip_count = 0; while (true) { if (get_flip_count(gpio, func_scheduler) > last_flip_count + 5) { @@ -134,7 +134,7 @@ TEST_CASE("LED locator: turn-on/turn-off/flip", "[ocs_control], [led_locator]") last_flip_count = get_flip_count(gpio, func_scheduler); - for (unsigned n = 0; n < 10; ++n) { + for (size_t n = 0; n < 10; ++n) { TEST_ASSERT_EQUAL(last_flip_count, get_flip_count(gpio, func_scheduler)); vTaskDelay(pdMS_TO_TICKS(50)); } @@ -155,7 +155,7 @@ TEST_CASE("LED locator: turn-on/turn-off/flip", "[ocs_control], [led_locator]") last_flip_count = get_flip_count(gpio, func_scheduler); - for (unsigned n = 0; n < 10; ++n) { + for (size_t n = 0; n < 10; ++n) { TEST_ASSERT_EQUAL(last_flip_count, get_flip_count(gpio, func_scheduler)); vTaskDelay(pdMS_TO_TICKS(50)); } @@ -180,7 +180,7 @@ TEST_CASE("LED locator: turn-on/turn-off/flip", "[ocs_control], [led_locator]") last_flip_count = get_flip_count(gpio, func_scheduler); - for (unsigned n = 0; n < 10; ++n) { + for (size_t n = 0; n < 10; ++n) { TEST_ASSERT_EQUAL(last_flip_count, get_flip_count(gpio, func_scheduler)); vTaskDelay(pdMS_TO_TICKS(50)); } @@ -213,7 +213,7 @@ TEST_CASE("LED locator: disable locating when the LED is locked by another compo TEST_ASSERT_TRUE(locator.get()); auto get_flip_count = [](test::TestGpio& gpio, scheduler::AsyncFuncScheduler& ash) { - unsigned ret = 0; + size_t ret = 0; auto future = ash.add([&gpio, &ret]() { ret = gpio.flip_call_count; @@ -228,7 +228,7 @@ TEST_CASE("LED locator: disable locating when the LED is locked by another compo return ret; }; - unsigned last_flip_count = 0; + size_t last_flip_count = 0; while (true) { if (get_flip_count(gpio, func_scheduler) > last_flip_count + 5) { @@ -256,7 +256,7 @@ TEST_CASE("LED locator: disable locating when the LED is locked by another compo last_flip_count = get_flip_count(gpio, func_scheduler); - for (unsigned n = 0; n < 10; ++n) { + for (size_t n = 0; n < 10; ++n) { TEST_ASSERT_EQUAL(last_flip_count, get_flip_count(gpio, func_scheduler)); vTaskDelay(pdMS_TO_TICKS(50)); } diff --git a/components/ocs_control/test/test_system_fsm.cpp b/components/ocs_control/test/test_system_fsm.cpp index dafea08e..a3e40268 100644 --- a/components/ocs_control/test/test_system_fsm.cpp +++ b/components/ocs_control/test/test_system_fsm.cpp @@ -19,7 +19,7 @@ namespace control { namespace { struct TestRebooter : public system::IRebooter, private core::NonCopyable<> { - unsigned call_count { 0 }; + size_t call_count { 0 }; void reboot() override { ++call_count; @@ -35,7 +35,7 @@ struct TestButton : public IButton, private core::NonCopyable<> { }; struct TestFsrHandler : public IFsrHandler, private core::NonCopyable<> { - unsigned call_count { 0 }; + size_t call_count { 0 }; status::StatusCode handle_fsr() override { ++call_count; @@ -45,7 +45,7 @@ struct TestFsrHandler : public IFsrHandler, private core::NonCopyable<> { }; struct TestInitHandler : public scheduler::IEventHandler, private core::NonCopyable<> { - unsigned call_count { 0 }; + size_t call_count { 0 }; status::StatusCode handle_event() override { ++call_count; @@ -91,7 +91,7 @@ TEST_CASE("System FSM: button is pressed before LED reaction on system initializ TEST_ASSERT_EQUAL(status::StatusCode::OK, fsm.run()); // Ensure there is no LED reaction on button event. - for (unsigned n = 0; n < 10; ++n) { + for (size_t n = 0; n < 10; ++n) { TEST_ASSERT_EQUAL(status::StatusCode::OK, task_scheduler.run()); TEST_ASSERT_EQUAL(0, gpio.flip_call_count); } @@ -184,7 +184,7 @@ TEST_CASE("System FSM: button is pressed during LED reaction on system initializ TEST_ASSERT_EQUAL(status::StatusCode::OK, fsm.run()); // Ensure there is no LED reaction on button event. - for (unsigned n = 0; n < 10; ++n) { + for (size_t n = 0; n < 10; ++n) { TEST_ASSERT_EQUAL(status::StatusCode::OK, task_scheduler.run()); TEST_ASSERT_EQUAL(0, gpio.flip_call_count); } @@ -232,7 +232,7 @@ TEST_CASE("System FSM: button isn't released within interval", TEST_ASSERT_EQUAL(status::StatusCode::OK, fsm.run()); // Ensure there is no LED reaction on button event. - for (unsigned n = 0; n < 10; ++n) { + for (size_t n = 0; n < 10; ++n) { TEST_ASSERT_EQUAL(status::StatusCode::OK, task_scheduler.run()); TEST_ASSERT_EQUAL(0, gpio.flip_call_count); } @@ -373,7 +373,7 @@ TEST_CASE("System FSM: FSR canceled: released too quickly", TEST_ASSERT_EQUAL(0, fsr_handler.call_count); // Ensure there is no LED reaction on button event. - for (unsigned n = 0; n < 10; ++n) { + for (size_t n = 0; n < 10; ++n) { TEST_ASSERT_EQUAL(status::StatusCode::OK, task_scheduler.run()); TEST_ASSERT_EQUAL(0, gpio.flip_call_count); } @@ -454,7 +454,7 @@ TEST_CASE("System FSM: FSR canceled: isn't confirmed within timeout", TEST_ASSERT_EQUAL(0, fsr_handler.call_count); // Ensure there is no LED reaction on button event. - for (unsigned n = 0; n < 10; ++n) { + for (size_t n = 0; n < 10; ++n) { TEST_ASSERT_EQUAL(status::StatusCode::OK, task_scheduler.run()); TEST_ASSERT_EQUAL(0, gpio.flip_call_count); } diff --git a/components/ocs_core/file_stream_reader.cpp b/components/ocs_core/file_stream_reader.cpp index 134328f1..66ef8179 100644 --- a/components/ocs_core/file_stream_reader.cpp +++ b/components/ocs_core/file_stream_reader.cpp @@ -71,7 +71,7 @@ status::StatusCode FileStreamReader::cancel() { return ret ? status::StatusCode::Error : status::StatusCode::OK; } -status::StatusCode FileStreamReader::read(void* data, unsigned& size) { +status::StatusCode FileStreamReader::read(void* data, size_t& size) { configASSERT(file_); if (feof(file_)) { diff --git a/components/ocs_core/file_stream_reader.h b/components/ocs_core/file_stream_reader.h index dc5fef93..4397910b 100644 --- a/components/ocs_core/file_stream_reader.h +++ b/components/ocs_core/file_stream_reader.h @@ -39,7 +39,7 @@ class FileStreamReader : public IStreamReader, private core::NonCopyable<> { status::StatusCode cancel() override; //! Read up to @p size bytes from file to @p data. - status::StatusCode read(void* data, unsigned& size) override; + status::StatusCode read(void* data, size_t& size) override; private: const std::string path_; diff --git a/components/ocs_core/istream_reader.h b/components/ocs_core/istream_reader.h index 02f6111d..59332a17 100644 --- a/components/ocs_core/istream_reader.h +++ b/components/ocs_core/istream_reader.h @@ -13,7 +13,7 @@ namespace core { //! Stream reading process. //! //! @example -//! status::StatusCode read_data(IStreamReader& reader, void* data, unsigned size) { +//! status::StatusCode read_data(IStreamReader& reader, void* data, size_t size) { //! if (const auto code = reader.begin(); code != status::StatusCode::OK) { //! return code; //! } @@ -64,7 +64,7 @@ class IStreamReader { //! //! @notes //! Reading is only allowed after the process was started correctly via begin() call. - virtual status::StatusCode read(void* data, unsigned& size) = 0; + virtual status::StatusCode read(void* data, size_t& size) = 0; }; } // namespace core diff --git a/components/ocs_core/istream_writer.h b/components/ocs_core/istream_writer.h index 63b53644..8b52f6e7 100644 --- a/components/ocs_core/istream_writer.h +++ b/components/ocs_core/istream_writer.h @@ -13,7 +13,7 @@ namespace core { //! Stream writing process. //! //! @example -//! status::StatusCode write(IStreamWriter& writer, const void* data, unsigned size) { +//! status::StatusCode write(IStreamWriter& writer, const void* data, size_t size) { //! if (const auto code = writer.begin(); code != status::StatusCode::OK) { //! return code; //! } @@ -57,7 +57,7 @@ class IStreamWriter { //! //! @notes //! Writing is only allowed after the process was started correctly via begin() call. - virtual status::StatusCode write(const void* data, unsigned size) = 0; + virtual status::StatusCode write(const void* data, size_t size) = 0; }; } // namespace core diff --git a/components/ocs_core/stream_transceiver.cpp b/components/ocs_core/stream_transceiver.cpp index 58c692e5..fba8fc2f 100644 --- a/components/ocs_core/stream_transceiver.cpp +++ b/components/ocs_core/stream_transceiver.cpp @@ -50,7 +50,7 @@ status::StatusCode StreamTransceiver::transceive() { while (true) { buffer_.clear(); - unsigned size = buffer_.capacity(); + size_t size = buffer_.capacity(); auto code = reader_.read(buffer_.data(), size); if (code == status::StatusCode::OK) { diff --git a/components/ocs_core/test/test_cond.cpp b/components/ocs_core/test/test_cond.cpp index 8a5ffc00..eb225553 100644 --- a/components/ocs_core/test/test_cond.cpp +++ b/components/ocs_core/test/test_cond.cpp @@ -34,7 +34,7 @@ template T random(T range_from, T range_to) { class TestTask : private NonCopyable<> { public: - TestTask(ILocker& locker, Cond& cond, const char* id, unsigned stack_size) + TestTask(ILocker& locker, Cond& cond, const char* id, size_t stack_size) : id_(id) , stack_size_(stack_size) , locker_(locker) @@ -48,7 +48,7 @@ class TestTask : private NonCopyable<> { return ret == pdTRUE ? status::StatusCode::OK : status::StatusCode::Error; } - unsigned awake_count() const { + size_t awake_count() const { return awake_count_.load(std::memory_order_acquire); } @@ -76,13 +76,13 @@ class TestTask : private NonCopyable<> { } const std::string id_; - const unsigned stack_size_ { 0 }; + const size_t stack_size_ { 0 }; ILocker& locker_; Cond& cond_; TaskHandle_t handle_ { nullptr }; - std::atomic awake_count_ { 0 }; + std::atomic awake_count_ { 0 }; }; } // namespace @@ -91,13 +91,13 @@ TEST_CASE("Condition variable: wait multiple tasks", "[ocs_core], [cond]") { StaticMutex mutex; Cond cond(mutex); - const unsigned task_count = 3; - const unsigned stack_size = 1024 * 2; + const size_t task_count = 3; + const size_t stack_size = 1024 * 2; using TaskPtr = std::shared_ptr; std::vector tasks; - for (unsigned n = 0; n < task_count; ++n) { + for (size_t n = 0; n < task_count; ++n) { const std::string id = "task_" + std::to_string(n); TaskPtr task(new (std::nothrow) TestTask(mutex, cond, id.c_str(), stack_size)); diff --git a/components/ocs_core/test/test_stream_transceiver.cpp b/components/ocs_core/test/test_stream_transceiver.cpp index f2c8ddca..24b23ca8 100644 --- a/components/ocs_core/test/test_stream_transceiver.cpp +++ b/components/ocs_core/test/test_stream_transceiver.cpp @@ -41,7 +41,7 @@ struct TestStreamReader : public IStreamReader { return cancel_status; } - status::StatusCode read(void* data, unsigned& size) override { + status::StatusCode read(void* data, size_t& size) override { ++read_count; if (read_status != status::StatusCode::OK) { @@ -65,10 +65,10 @@ struct TestStreamReader : public IStreamReader { status::StatusCode cancel_status { status::StatusCode::OK }; status::StatusCode read_status { status::StatusCode::OK }; - unsigned begin_count { 0 }; - unsigned end_count { 0 }; - unsigned cancel_count { 0 }; - unsigned read_count { 0 }; + size_t begin_count { 0 }; + size_t end_count { 0 }; + size_t cancel_count { 0 }; + size_t read_count { 0 }; private: Data data_; @@ -90,7 +90,7 @@ struct TestStreamWriter : public IStreamWriter { return cancel_status; } - status::StatusCode write(const void* data, unsigned size) override { + status::StatusCode write(const void* data, size_t size) override { ++write_count; if (write_status != status::StatusCode::OK) { return write_status; @@ -98,7 +98,7 @@ struct TestStreamWriter : public IStreamWriter { const char* ptr = static_cast(data); - for (unsigned n = 0; n < size; ++n) { + for (size_t n = 0; n < size; ++n) { buffer_.push_back(ptr[n]); } @@ -114,10 +114,10 @@ struct TestStreamWriter : public IStreamWriter { status::StatusCode cancel_status { status::StatusCode::OK }; status::StatusCode write_status { status::StatusCode::OK }; - unsigned begin_count { 0 }; - unsigned end_count { 0 }; - unsigned cancel_count { 0 }; - unsigned write_count { 0 }; + size_t begin_count { 0 }; + size_t end_count { 0 }; + size_t cancel_count { 0 }; + size_t write_count { 0 }; private: StreamTransceiver::Buffer buffer_; diff --git a/components/ocs_core/version_to_str.cpp b/components/ocs_core/version_to_str.cpp index 2814ae24..181b9e2b 100644 --- a/components/ocs_core/version_to_str.cpp +++ b/components/ocs_core/version_to_str.cpp @@ -13,9 +13,8 @@ namespace core { version_to_str::version_to_str(Version version) { memset(buf_, 0, sizeof(buf_)); - if (snprintf(buf_, sizeof(buf_), "%u.%u.%u", static_cast(version.major), - static_cast(version.minor), - static_cast(version.patch)) + if (snprintf(buf_, sizeof(buf_), "%u.%u.%u", static_cast(version.major), + static_cast(version.minor), static_cast(version.patch)) < 0) { strcpy(buf_, ""); } diff --git a/components/ocs_core/version_to_str.h b/components/ocs_core/version_to_str.h index 9b3a1e64..5db33458 100644 --- a/components/ocs_core/version_to_str.h +++ b/components/ocs_core/version_to_str.h @@ -22,7 +22,7 @@ class version_to_str : private NonCopyable<> { const char* c_str() const; private: - static constexpr unsigned size_ = strlen("65535.65535.65535"); + static constexpr size_t size_ = strlen("65535.65535.65535"); char buf_[size_ + 1]; }; diff --git a/components/ocs_diagnostic/basic_counter.cpp b/components/ocs_diagnostic/basic_counter.cpp index 8355e7c2..865d8394 100644 --- a/components/ocs_diagnostic/basic_counter.cpp +++ b/components/ocs_diagnostic/basic_counter.cpp @@ -18,7 +18,7 @@ BasicCounter::BasicCounter(const char* id) { configASSERT(strlen(id)); memset(buf_, 0, sizeof(buf_)); - strncpy(buf_, id, std::min(bufsize_, strlen(id))); + strncpy(buf_, id, std::min(static_cast(bufsize_), strlen(id))); } const char* BasicCounter::id() const { diff --git a/components/ocs_diagnostic/basic_counter.h b/components/ocs_diagnostic/basic_counter.h index 2f9406c6..fbf28cb7 100644 --- a/components/ocs_diagnostic/basic_counter.h +++ b/components/ocs_diagnostic/basic_counter.h @@ -26,7 +26,7 @@ class BasicCounter : public ICounter, public core::NonCopyable { const char* id() const; private: - static constexpr unsigned bufsize_ = 15; + static constexpr uint8_t bufsize_ = 15; char buf_[bufsize_ + 1]; }; diff --git a/components/ocs_diagnostic/test/test_basic_counter.cpp b/components/ocs_diagnostic/test/test_basic_counter.cpp index 56419510..fc01ead7 100644 --- a/components/ocs_diagnostic/test/test_basic_counter.cpp +++ b/components/ocs_diagnostic/test/test_basic_counter.cpp @@ -22,12 +22,12 @@ TEST_CASE("Basic counter: ID length overflow", "[ocs_diagnostic], [basic_counter const auto max_len = 15; std::string actual_id; - for (unsigned n = 0; n < max_len * 2; ++n) { + for (size_t n = 0; n < max_len * 2; ++n) { actual_id += std::to_string(1); } std::string expected_id; - for (unsigned n = 0; n < max_len; ++n) { + for (size_t n = 0; n < max_len; ++n) { expected_id += std::to_string(1); } diff --git a/components/ocs_fmt/json/dynamic_formatter.cpp b/components/ocs_fmt/json/dynamic_formatter.cpp index 1a060a5f..166eb18b 100644 --- a/components/ocs_fmt/json/dynamic_formatter.cpp +++ b/components/ocs_fmt/json/dynamic_formatter.cpp @@ -13,7 +13,7 @@ namespace ocs { namespace fmt { namespace json { -DynamicFormatter::DynamicFormatter(unsigned size) +DynamicFormatter::DynamicFormatter(size_t size) : size_(size) { configASSERT(size_); diff --git a/components/ocs_fmt/json/dynamic_formatter.h b/components/ocs_fmt/json/dynamic_formatter.h index a1833734..21af36f4 100644 --- a/components/ocs_fmt/json/dynamic_formatter.h +++ b/components/ocs_fmt/json/dynamic_formatter.h @@ -20,7 +20,7 @@ class DynamicFormatter : public IFormatter, private core::NonCopyable<> { //! //! @params //! - @p size - underlying buffer size, in bytes, allocated on the heap. - explicit DynamicFormatter(unsigned size); + explicit DynamicFormatter(size_t size); //! Format @p json into the underlying buffer. status::StatusCode format(cJSON* json) override; @@ -31,7 +31,7 @@ class DynamicFormatter : public IFormatter, private core::NonCopyable<> { private: void clear_(); - const unsigned size_ { 0 }; + const size_t size_ { 0 }; std::unique_ptr buf_; }; diff --git a/components/ocs_fmt/json/static_formatter.h b/components/ocs_fmt/json/static_formatter.h index c884db8f..3e10d52b 100644 --- a/components/ocs_fmt/json/static_formatter.h +++ b/components/ocs_fmt/json/static_formatter.h @@ -15,7 +15,7 @@ namespace ocs { namespace fmt { namespace json { -template +template class StaticFormatter : public IFormatter, private core::NonCopyable<> { public: //! Initialize. diff --git a/components/ocs_http/chunk_stream_writer.cpp b/components/ocs_http/chunk_stream_writer.cpp index 94475535..b1ff289e 100644 --- a/components/ocs_http/chunk_stream_writer.cpp +++ b/components/ocs_http/chunk_stream_writer.cpp @@ -24,7 +24,7 @@ status::StatusCode ChunkStreamWriter::cancel() { return end(); } -status::StatusCode ChunkStreamWriter::write(const void* data, unsigned size) { +status::StatusCode ChunkStreamWriter::write(const void* data, size_t size) { return writer_.write(data, size); } diff --git a/components/ocs_http/chunk_stream_writer.h b/components/ocs_http/chunk_stream_writer.h index 015febd2..1e70f820 100644 --- a/components/ocs_http/chunk_stream_writer.h +++ b/components/ocs_http/chunk_stream_writer.h @@ -5,6 +5,8 @@ #pragma once +#include + #include "ocs_core/istream_writer.h" #include "ocs_core/noncopyable.h" #include "ocs_http/iresponse_writer.h" @@ -31,7 +33,7 @@ class ChunkStreamWriter : public core::IStreamWriter, private core::NonCopyable< status::StatusCode cancel() override; //! Write @p size bytes of @p data. - status::StatusCode write(const void* data, unsigned size) override; + status::StatusCode write(const void* data, size_t size) override; private: IResponseWriter& writer_; diff --git a/components/ocs_http/iresponse_writer.h b/components/ocs_http/iresponse_writer.h index 34e5ef63..b611cdc0 100644 --- a/components/ocs_http/iresponse_writer.h +++ b/components/ocs_http/iresponse_writer.h @@ -21,7 +21,7 @@ class IResponseWriter { //! //! @remarks //! - Respond with empty data to signal HTTP response completion: write(nullptr, 0). - virtual status::StatusCode write(const void* data, unsigned size) = 0; + virtual status::StatusCode write(const void* data, size_t size) = 0; //! Write HTTP status code. virtual status::StatusCode write_status(StatusCode) = 0; diff --git a/components/ocs_http/target_esp32/client_reader.cpp b/components/ocs_http/target_esp32/client_reader.cpp index 64d017c1..0a5d4dfd 100644 --- a/components/ocs_http/target_esp32/client_reader.cpp +++ b/components/ocs_http/target_esp32/client_reader.cpp @@ -46,10 +46,10 @@ status::StatusCode ClientReader::wait(TickType_t wait) { return status::StatusCode::OK; } -unsigned ClientReader::read(char* buf, unsigned size) { +size_t ClientReader::read(char* buf, size_t size) { core::LockGuard lock(mu_); - const unsigned len = std::min(size, buf_.size()); + const size_t len = std::min(size, buf_.size()); memcpy(buf, buf_.data(), len); return len; @@ -104,7 +104,7 @@ void ClientReader::handle_event_on_data_(esp_http_client_event_t* event) { const char* ptr = static_cast(event->data); - for (unsigned n = 0; n < event->data_len; ++n) { + for (size_t n = 0; n < event->data_len; ++n) { buf_.push_back(ptr[n]); } } diff --git a/components/ocs_http/target_esp32/client_reader.h b/components/ocs_http/target_esp32/client_reader.h index 94a947b6..5758ab7e 100644 --- a/components/ocs_http/target_esp32/client_reader.h +++ b/components/ocs_http/target_esp32/client_reader.h @@ -40,7 +40,7 @@ class ClientReader : private core::NonCopyable<> { //! //! @return //! Number of bytes read. - unsigned read(char* buf, unsigned size); + size_t read(char* buf, size_t size); private: static esp_err_t handle_event_(esp_http_client_event_t* event); diff --git a/components/ocs_http/target_esp32/response_writer.cpp b/components/ocs_http/target_esp32/response_writer.cpp index b9e0ab37..11330f2e 100644 --- a/components/ocs_http/target_esp32/response_writer.cpp +++ b/components/ocs_http/target_esp32/response_writer.cpp @@ -21,7 +21,7 @@ ResponseWriter::ResponseWriter(httpd_req_t& req) , header_(req) { } -status::StatusCode ResponseWriter::write(const void* data, unsigned size) { +status::StatusCode ResponseWriter::write(const void* data, size_t size) { if (header_.chunked()) { const auto err = httpd_resp_send_chunk(&req_, static_cast(data), size); diff --git a/components/ocs_http/target_esp32/response_writer.h b/components/ocs_http/target_esp32/response_writer.h index 096eb91d..b392f97c 100644 --- a/components/ocs_http/target_esp32/response_writer.h +++ b/components/ocs_http/target_esp32/response_writer.h @@ -23,7 +23,7 @@ class ResponseWriter : public IResponseWriter, private core::NonCopyable<> { explicit ResponseWriter(httpd_req_t& req); //! Write @p size bytes of @p data to the underlying request. - status::StatusCode write(const void* data, unsigned size) override; + status::StatusCode write(const void* data, size_t size) override; //! Write HTTP status code. status::StatusCode write_status(StatusCode) override; diff --git a/components/ocs_http/target_esp32/server.h b/components/ocs_http/target_esp32/server.h index fe5e9691..a2c6f973 100644 --- a/components/ocs_http/target_esp32/server.h +++ b/components/ocs_http/target_esp32/server.h @@ -23,10 +23,10 @@ class Server : public IServer, public: struct Params { //! TCP port to accept incoming connections. - unsigned server_port { 80 }; + uint8_t server_port { 80 }; //! Maximum allowed URI handlers. - unsigned max_uri_handlers { 32 }; + uint8_t max_uri_handlers { 32 }; }; //! Initialize. diff --git a/components/ocs_http/test/target_esp32/test_server.cpp b/components/ocs_http/test/target_esp32/test_server.cpp index 3342e3c4..c34e29ef 100644 --- a/components/ocs_http/test/target_esp32/test_server.cpp +++ b/components/ocs_http/test/target_esp32/test_server.cpp @@ -81,7 +81,7 @@ TEST_CASE("Start HTTP server: WiFi invalid credentials", "[ocs_http], [server]") #ifdef CONFIG_OCS_TEST_UNIT_WIFI_STA_ENABLED TEST_CASE("Start HTTP server: WiFi valid credentials", "[ocs_http], [server]") { - const unsigned server_port = 80; + const uint8_t server_port = 80; Router router; Server server(router, @@ -152,7 +152,7 @@ TEST_CASE("Start HTTP server: WiFi valid credentials", "[ocs_http], [server]") { TEST_CASE("Start HTTP server: chunked response", "[ocs_http], [server]") { struct TestStreamReader : public core::IStreamReader { - TestStreamReader(const char* response, unsigned chunk_size) + TestStreamReader(const char* response, size_t chunk_size) : response_(response) , chunk_size_(chunk_size) { } @@ -169,7 +169,7 @@ TEST_CASE("Start HTTP server: chunked response", "[ocs_http], [server]") { return status::StatusCode::OK; } - status::StatusCode read(void* data, unsigned& size) override { + status::StatusCode read(void* data, size_t& size) override { if (pos_ == response_.size()) { return status::StatusCode::NoData; } @@ -185,12 +185,12 @@ TEST_CASE("Start HTTP server: chunked response", "[ocs_http], [server]") { private: const std::string response_; - const unsigned chunk_size_ { 0 }; + const size_t chunk_size_ { 0 }; - unsigned pos_ { 0 }; + size_t pos_ { 0 }; }; - const unsigned server_port = 80; + const uint8_t server_port = 80; Router router; Server server(router, diff --git a/components/ocs_io/i2c/itransceiver.h b/components/ocs_io/i2c/itransceiver.h index 012fdb90..46fcc0d6 100644 --- a/components/ocs_io/i2c/itransceiver.h +++ b/components/ocs_io/i2c/itransceiver.h @@ -24,7 +24,7 @@ class ITransceiver { //! - @p timeout - interval to wait for the operation to complete, //! -1 means wait forever. virtual status::StatusCode - send(const uint8_t* buf, unsigned size, system::Time timeout) = 0; + send(const uint8_t* buf, size_t size, system::Time timeout) = 0; //! Receive data from the I2C device. //! @@ -33,7 +33,7 @@ class ITransceiver { //! - @p timeout - interval to wait for the operation to complete, //! -1 means wait forever. virtual status::StatusCode - receive(uint8_t* buf, unsigned size, system::Time timeout) = 0; + receive(uint8_t* buf, size_t size, system::Time timeout) = 0; }; } // namespace i2c diff --git a/components/ocs_io/i2c/target_esp32/master_transceiver.cpp b/components/ocs_io/i2c/target_esp32/master_transceiver.cpp index 4d63e4a5..050e04e6 100644 --- a/components/ocs_io/i2c/target_esp32/master_transceiver.cpp +++ b/components/ocs_io/i2c/target_esp32/master_transceiver.cpp @@ -34,7 +34,7 @@ MasterTransceiver::MasterTransceiver(MasterTransceiver::DevicePtr device, const } status::StatusCode -MasterTransceiver::send(const uint8_t* buf, unsigned size, system::Time timeout) { +MasterTransceiver::send(const uint8_t* buf, size_t size, system::Time timeout) { if (timeout > 0 && timeout < system::Duration::millisecond) { return status::StatusCode::InvalidArg; } @@ -59,7 +59,7 @@ MasterTransceiver::send(const uint8_t* buf, unsigned size, system::Time timeout) } status::StatusCode -MasterTransceiver::receive(uint8_t* buf, unsigned size, system::Time timeout) { +MasterTransceiver::receive(uint8_t* buf, size_t size, system::Time timeout) { if (timeout > 0 && timeout < system::Duration::millisecond) { return status::StatusCode::InvalidArg; } diff --git a/components/ocs_io/i2c/target_esp32/master_transceiver.h b/components/ocs_io/i2c/target_esp32/master_transceiver.h index d9187000..f3c479d2 100644 --- a/components/ocs_io/i2c/target_esp32/master_transceiver.h +++ b/components/ocs_io/i2c/target_esp32/master_transceiver.h @@ -31,11 +31,11 @@ class MasterTransceiver : public ITransceiver, private core::NonCopyable<> { //! Send data to the I2C device. status::StatusCode - send(const uint8_t* buf, unsigned size, system::Time timeout = -1) override; + send(const uint8_t* buf, size_t size, system::Time timeout = -1) override; //! Receive data from the I2C device. status::StatusCode - receive(uint8_t* buf, unsigned size, system::Time timeout = -1) override; + receive(uint8_t* buf, size_t size, system::Time timeout = -1) override; private: const std::string id_; diff --git a/components/ocs_io/spi/itransceiver.h b/components/ocs_io/spi/itransceiver.h index 3a9bebe4..1fc85c5a 100644 --- a/components/ocs_io/spi/itransceiver.h +++ b/components/ocs_io/spi/itransceiver.h @@ -22,9 +22,9 @@ class ITransceiver { //! - @p send_buf - sending data, should be at least @p send_buf_size bytes long. //! - @p recv_buf - receiving data, should be at least @p recv_buf_size bytes long. virtual status::StatusCode transceive(const uint8_t* send_buf, - unsigned send_buf_size, + size_t send_buf_size, uint8_t* recv_buf, - unsigned recv_buf_size) = 0; + size_t recv_buf_size) = 0; }; } // namespace spi diff --git a/components/ocs_io/spi/target_esp32/master_transceiver.cpp b/components/ocs_io/spi/target_esp32/master_transceiver.cpp index de982162..a9ddb20e 100644 --- a/components/ocs_io/spi/target_esp32/master_transceiver.cpp +++ b/components/ocs_io/spi/target_esp32/master_transceiver.cpp @@ -35,9 +35,9 @@ MasterTransceiver::MasterTransceiver(MasterTransceiver::DevicePtr device, const } status::StatusCode MasterTransceiver::transceive(const uint8_t* send_buf, - unsigned send_buf_size, + size_t send_buf_size, uint8_t* recv_buf, - unsigned recv_buf_size) { + size_t recv_buf_size) { spi_transaction_t transaction; memset(&transaction, 0, sizeof(transaction)); diff --git a/components/ocs_io/spi/target_esp32/master_transceiver.h b/components/ocs_io/spi/target_esp32/master_transceiver.h index 28f77137..5ba85a70 100644 --- a/components/ocs_io/spi/target_esp32/master_transceiver.h +++ b/components/ocs_io/spi/target_esp32/master_transceiver.h @@ -31,9 +31,9 @@ class MasterTransceiver : public ITransceiver, private core::NonCopyable<> { //! Send/receive data over SPI bus. status::StatusCode transceive(const uint8_t* send_buf, - unsigned send_buf_size, + size_t send_buf_size, uint8_t* recv_buf, - unsigned recv_buf_size) override; + size_t recv_buf_size) override; private: const std::string id_; diff --git a/components/ocs_io/test/adc/target_esp32/test_oneshot_store.cpp b/components/ocs_io/test/adc/target_esp32/test_oneshot_store.cpp index 18f6656d..2b32716c 100644 --- a/components/ocs_io/test/adc/target_esp32/test_oneshot_store.cpp +++ b/components/ocs_io/test/adc/target_esp32/test_oneshot_store.cpp @@ -25,9 +25,9 @@ TEST_CASE("Oneshot ADC store: register maximum number of ADC", for (const auto& unit : units) { OneshotStore store(unit, ADC_ATTEN_DB_12, ADC_BITWIDTH_10); - const unsigned count = SOC_ADC_CHANNEL_NUM(unit); + const size_t count = SOC_ADC_CHANNEL_NUM(unit); - for (unsigned n = 0; n < count; ++n) { + for (size_t n = 0; n < count; ++n) { const Channel channel = static_cast(n); TEST_ASSERT_NOT_NULL(store.add(channel)); } @@ -59,9 +59,9 @@ TEST_CASE("Oneshot ADC store: register overflow", "[ocs_io], [adc_oneshot_store] for (const auto& unit : units) { OneshotStore store(unit, ADC_ATTEN_DB_12, ADC_BITWIDTH_10); - const unsigned count = SOC_ADC_CHANNEL_NUM(unit); + const size_t count = SOC_ADC_CHANNEL_NUM(unit); - for (unsigned n = 0; n < count; ++n) { + for (size_t n = 0; n < count; ++n) { const Channel channel = static_cast(n); TEST_ASSERT_NOT_NULL(store.add(channel)); } diff --git a/components/ocs_net/mdns_config.cpp b/components/ocs_net/mdns_config.cpp index 7287d1e3..6f766e7e 100644 --- a/components/ocs_net/mdns_config.cpp +++ b/components/ocs_net/mdns_config.cpp @@ -23,11 +23,11 @@ const char* log_tag = "mdns_config"; MdnsConfig::MdnsConfig(storage::IStorage& storage, const system::DeviceInfo& device_info) : storage_(storage) { memset(hostname_, 0, sizeof(hostname_)); - auto code = - algo::StorageOps::prob_read(storage_, hostname_key_, hostname_, max_hostname_len); + + auto code = algo::StorageOps::prob_read(storage_, hostname_key_, hostname_, + max_hostname_len_); if (code != status::StatusCode::OK) { - memcpy(hostname_, device_info.get_fw_name(), - std::min(max_hostname_len, strlen(device_info.get_fw_name()))); + strncpy(hostname_, device_info.get_fw_name(), sizeof(hostname_)); } } @@ -45,7 +45,7 @@ const char* MdnsConfig::get_hostname() const { } status::StatusCode MdnsConfig::configure(const char* hostname) { - if (strlen(hostname) > max_hostname_len) { + if (strlen(hostname) > max_hostname_len_) { return status::StatusCode::InvalidArg; } diff --git a/components/ocs_net/mdns_config.h b/components/ocs_net/mdns_config.h index 1556b1c2..f1b70db3 100644 --- a/components/ocs_net/mdns_config.h +++ b/components/ocs_net/mdns_config.h @@ -15,9 +15,6 @@ namespace net { class MdnsConfig : public storage::IConfig, private core::NonCopyable<> { public: - // Maximum length of the mDNS hostname. - static constexpr unsigned max_hostname_len = 31; - //! Initialize. //! //! @params @@ -45,7 +42,9 @@ class MdnsConfig : public storage::IConfig, private core::NonCopyable<> { storage::IStorage& storage_; - char hostname_[max_hostname_len + 1]; + static constexpr uint8_t max_hostname_len_ = 31; + + char hostname_[max_hostname_len_ + 1]; }; } // namespace net diff --git a/components/ocs_net/target_esp32/sta_network.h b/components/ocs_net/target_esp32/sta_network.h index 359cb646..037cecf9 100644 --- a/components/ocs_net/target_esp32/sta_network.h +++ b/components/ocs_net/target_esp32/sta_network.h @@ -66,7 +66,7 @@ class StaNetwork : public INetwork, public IStaNetwork, private core::NonCopyabl core::StaticEventGroup event_group_; - unsigned retry_count_ { 0 }; + uint8_t retry_count_ { 0 }; }; } // namespace net diff --git a/components/ocs_onewire/bus.cpp b/components/ocs_onewire/bus.cpp index b659c5bb..3ab9bfbf 100644 --- a/components/ocs_onewire/bus.cpp +++ b/components/ocs_onewire/bus.cpp @@ -95,7 +95,7 @@ status::StatusCode Bus::read_bit(uint8_t& bit) { } status::StatusCode Bus::write_byte(uint8_t byte) { - for (unsigned n = 0; n < bits_in_byte_; ++n) { + for (uint8_t n = 0; n < bits_in_byte_; ++n) { const uint8_t bit = byte % 2; OCS_STATUS_RETURN_ON_ERROR(write_bit(bit)); @@ -106,7 +106,7 @@ status::StatusCode Bus::write_byte(uint8_t byte) { } status::StatusCode Bus::read_byte(uint8_t& byte) { - for (unsigned n = 0; n < bits_in_byte_; ++n) { + for (uint8_t n = 0; n < bits_in_byte_; ++n) { uint8_t bit = 0; OCS_STATUS_RETURN_ON_ERROR(read_bit(bit)); @@ -120,22 +120,22 @@ status::StatusCode Bus::read_byte(uint8_t& byte) { return status::StatusCode::OK; } -status::StatusCode Bus::read_bytes(uint8_t* buf, unsigned size) { +status::StatusCode Bus::read_bytes(uint8_t* buf, size_t size) { OCS_STATUS_RETURN_ON_FALSE(buf, status::StatusCode::InvalidArg); OCS_STATUS_RETURN_ON_FALSE(size, status::StatusCode::InvalidArg); - for (unsigned n = 0; n < size; ++n) { + for (size_t n = 0; n < size; ++n) { OCS_STATUS_RETURN_ON_ERROR(read_byte(buf[n])); } return status::StatusCode::OK; } -status::StatusCode Bus::write_bytes(const uint8_t* buf, unsigned size) { +status::StatusCode Bus::write_bytes(const uint8_t* buf, size_t size) { OCS_STATUS_RETURN_ON_FALSE(buf, status::StatusCode::InvalidArg); OCS_STATUS_RETURN_ON_FALSE(size, status::StatusCode::InvalidArg); - for (unsigned n = 0; n < size; ++n) { + for (size_t n = 0; n < size; ++n) { OCS_STATUS_RETURN_ON_ERROR(write_byte(buf[n])); } diff --git a/components/ocs_onewire/bus.h b/components/ocs_onewire/bus.h index 252530b7..2145a9f5 100644 --- a/components/ocs_onewire/bus.h +++ b/components/ocs_onewire/bus.h @@ -72,13 +72,13 @@ class Bus : private core::NonCopyable<> { //! //! @remarks //! - @p buf should be at least @p size bytes long. - status::StatusCode read_bytes(uint8_t* buf, unsigned size); + status::StatusCode read_bytes(uint8_t* buf, size_t size); //! Write @p size bytes from @p buf to the bus. //! //! @remarks //! - @p buf should be at least @p size bytes long. - status::StatusCode write_bytes(const uint8_t* buf, unsigned size); + status::StatusCode write_bytes(const uint8_t* buf, size_t size); private: status::StatusCode write_bit_one_(); @@ -86,7 +86,7 @@ class Bus : private core::NonCopyable<> { const Params params_; - const unsigned bits_in_byte_ = 8; + const uint8_t bits_in_byte_ = 8; system::Time reset_remain_time_slot_ { 0 }; system::Time write_remain_time_slot_ { 0 }; diff --git a/components/ocs_onewire/crc.cpp b/components/ocs_onewire/crc.cpp index 6a27b3eb..c6cff348 100644 --- a/components/ocs_onewire/crc.cpp +++ b/components/ocs_onewire/crc.cpp @@ -9,7 +9,7 @@ namespace ocs { namespace onewire { -uint8_t calculate_crc(const uint8_t* buf, unsigned size) { +uint8_t calculate_crc(const uint8_t* buf, size_t size) { return algo::CrcOps::crc8(buf, size, 0x00, 0x8C, algo::CrcOps::BitOrder::LSB); } diff --git a/components/ocs_onewire/crc.h b/components/ocs_onewire/crc.h index f10574cc..934d451e 100644 --- a/components/ocs_onewire/crc.h +++ b/components/ocs_onewire/crc.h @@ -5,6 +5,7 @@ #pragma once +#include #include namespace ocs { @@ -18,7 +19,7 @@ namespace onewire { //! @references //! https://stackoverflow.com/questions/29214301/ios-how-to-calculate-crc-8-dallas-maxim-of-nsdata //! https://stackoverflow.com/questions/74775595/maxim-dow-crc-algorithm-cannot-re-create-example-in-application-note -uint8_t calculate_crc(const uint8_t* buf, unsigned size); +uint8_t calculate_crc(const uint8_t* buf, size_t size); } // namespace onewire } // namespace ocs diff --git a/components/ocs_onewire/rom_code_scanner.cpp b/components/ocs_onewire/rom_code_scanner.cpp index 46ffd9eb..7f9087a6 100644 --- a/components/ocs_onewire/rom_code_scanner.cpp +++ b/components/ocs_onewire/rom_code_scanner.cpp @@ -46,7 +46,7 @@ void RomCodeScanner::reset() { conflict_count_ = 0; } -status::StatusCode RomCodeScanner::scan_(uint8_t* buf, unsigned size) { +status::StatusCode RomCodeScanner::scan_(uint8_t* buf, size_t size) { for (int n = 0; n < size * bits_in_byte_; ++n) { uint8_t bit1 = 0; OCS_STATUS_RETURN_ON_ERROR(bus_.read_bit(bit1)); @@ -70,8 +70,8 @@ status::StatusCode RomCodeScanner::scan_(uint8_t* buf, unsigned size) { } } - const unsigned byte_pos = n / bits_in_byte_; - const unsigned bit_pos = n % bits_in_byte_; + const size_t byte_pos = n / bits_in_byte_; + const size_t bit_pos = n % bits_in_byte_; if (bit) { buf[byte_pos] |= algo::BitOps::mask(bit_pos); @@ -123,8 +123,8 @@ uint8_t RomCodeScanner::handle_discrepancy_(const uint8_t* buf, int position) { // Follow to the previous path. configASSERT(prev_discrepancy_ >= 0); - const unsigned byte_pos = prev_discrepancy_ / bits_in_byte_; - const unsigned bit_pos = prev_discrepancy_ % bits_in_byte_; + const size_t byte_pos = prev_discrepancy_ / bits_in_byte_; + const size_t bit_pos = prev_discrepancy_ % bits_in_byte_; prev_discrepancy_ = position; diff --git a/components/ocs_onewire/rom_code_scanner.h b/components/ocs_onewire/rom_code_scanner.h index 90e4b1e2..713e63b8 100644 --- a/components/ocs_onewire/rom_code_scanner.h +++ b/components/ocs_onewire/rom_code_scanner.h @@ -28,17 +28,17 @@ class RomCodeScanner : private core::NonCopyable<> { void reset(); private: - status::StatusCode scan_(uint8_t* buf, unsigned size); + status::StatusCode scan_(uint8_t* buf, size_t size); uint8_t handle_discrepancy_(const uint8_t* buf, int position); - static constexpr unsigned bits_in_byte_ = 8; + static constexpr uint8_t bits_in_byte_ = 8; Bus& bus_; bool finished_ { false }; int prev_discrepancy_ { -1 }; int curr_discrepancy_ { -1 }; - unsigned conflict_count_ { 0 }; + size_t conflict_count_ { 0 }; }; } // namespace onewire diff --git a/components/ocs_onewire/serial_number_to_str.h b/components/ocs_onewire/serial_number_to_str.h index d8065c8d..6a0fd099 100644 --- a/components/ocs_onewire/serial_number_to_str.h +++ b/components/ocs_onewire/serial_number_to_str.h @@ -16,7 +16,7 @@ namespace onewire { //! Format sensor serial number to string. class serial_number_to_str : private core::NonCopyable<> { public: - static constexpr unsigned str_length = strlen("AA:BB:CC:DD:EE:FF"); + static constexpr size_t str_length = strlen("AA:BB:CC:DD:EE:FF"); //! Initialize. serial_number_to_str(const SerialNumber& serial_number); diff --git a/components/ocs_pipeline/httpserver/analog_config_store_handler.cpp b/components/ocs_pipeline/httpserver/analog_config_store_handler.cpp index bcf38346..311a5fc2 100644 --- a/components/ocs_pipeline/httpserver/analog_config_store_handler.cpp +++ b/components/ocs_pipeline/httpserver/analog_config_store_handler.cpp @@ -21,7 +21,7 @@ namespace httpserver { namespace { -status::StatusCode send_json(http::IResponseWriter& w, cJSON* json, unsigned size) { +status::StatusCode send_json(http::IResponseWriter& w, cJSON* json, size_t size) { fmt::json::DynamicFormatter json_formatter(size); const auto code = json_formatter.format(json); diff --git a/components/ocs_pipeline/httpserver/data_handler.cpp b/components/ocs_pipeline/httpserver/data_handler.cpp index 0fd2cb10..f2df7364 100644 --- a/components/ocs_pipeline/httpserver/data_handler.cpp +++ b/components/ocs_pipeline/httpserver/data_handler.cpp @@ -14,7 +14,7 @@ namespace ocs { namespace pipeline { namespace httpserver { -DataHandler::DataHandler(fmt::json::IFormatter& formatter, unsigned buffer_size) { +DataHandler::DataHandler(fmt::json::IFormatter& formatter, size_t buffer_size) { fanout_formatter_.reset(new (std::nothrow) fmt::json::FanoutFormatter()); configASSERT(fanout_formatter_); diff --git a/components/ocs_pipeline/httpserver/data_handler.h b/components/ocs_pipeline/httpserver/data_handler.h index b707f36b..21330997 100644 --- a/components/ocs_pipeline/httpserver/data_handler.h +++ b/components/ocs_pipeline/httpserver/data_handler.h @@ -25,7 +25,7 @@ class DataHandler : public http::IHandler, private core::NonCopyable<> { //! @params //! - @p formatter to format the data. //! - @p buffer_size to hold the formatted JSON data, in bytes. - DataHandler(fmt::json::IFormatter& formatter, unsigned buffer_size); + DataHandler(fmt::json::IFormatter& formatter, size_t buffer_size); // Get data over HTTP. status::StatusCode serve_http(http::IResponseWriter& w, http::IRequest&) override; diff --git a/components/ocs_pipeline/httpserver/ds18b20_handler.cpp b/components/ocs_pipeline/httpserver/ds18b20_handler.cpp index ff65fc7d..8eee859b 100644 --- a/components/ocs_pipeline/httpserver/ds18b20_handler.cpp +++ b/components/ocs_pipeline/httpserver/ds18b20_handler.cpp @@ -285,8 +285,8 @@ status::StatusCode DS18B20Handler::format_sensor_(cJSON* array, status::StatusCode DS18B20Handler::handle_configuration_(http::IResponseWriter& w, http::IRequest& r, - unsigned wait_interval, - unsigned response_size, + size_t wait_interval, + size_t response_size, DS18B20Handler::HandleConfigurationFunc func) { const auto values = algo::UriOps::parse_query(r.get_uri()); @@ -480,7 +480,7 @@ status::StatusCode DS18B20Handler::erase_configuration_(cJSON* json, return status::StatusCode::OK; } -status::StatusCode DS18B20Handler::send_response_(unsigned buffer_size, +status::StatusCode DS18B20Handler::send_response_(size_t buffer_size, cJSON* json, http::IResponseWriter& w) { fmt::json::DynamicFormatter json_formatter(buffer_size); diff --git a/components/ocs_pipeline/httpserver/ds18b20_handler.h b/components/ocs_pipeline/httpserver/ds18b20_handler.h index 7ad0b83b..42cd5c10 100644 --- a/components/ocs_pipeline/httpserver/ds18b20_handler.h +++ b/components/ocs_pipeline/httpserver/ds18b20_handler.h @@ -34,10 +34,10 @@ class DS18B20Handler : private http::IHandler, private core::NonCopyable<> { using HandleConfigurationFunc = std::function; - static constexpr unsigned scan_response_buffer_size_ { 256 }; - static constexpr unsigned read_response_buffer_size_ { 256 }; - static constexpr unsigned write_response_buffer_size_ { 256 }; - static constexpr unsigned erase_response_buffer_size_ { 256 }; + static constexpr size_t scan_response_buffer_size_ { 256 }; + static constexpr size_t read_response_buffer_size_ { 256 }; + static constexpr size_t write_response_buffer_size_ { 256 }; + static constexpr size_t erase_response_buffer_size_ { 256 }; static constexpr TickType_t scan_wait_interval_ { pdMS_TO_TICKS(10 * 1000) }; static constexpr TickType_t read_wait_interval_ { pdMS_TO_TICKS(5 * 1000) }; @@ -65,8 +65,8 @@ class DS18B20Handler : private http::IHandler, private core::NonCopyable<> { status::StatusCode handle_configuration_(http::IResponseWriter& w, http::IRequest& r, - unsigned wait_interval, - unsigned response_size, + size_t wait_interval, + size_t response_size, HandleConfigurationFunc func); status::StatusCode read_configuration_(cJSON* json, sensor::ds18b20::Sensor&); @@ -87,7 +87,7 @@ class DS18B20Handler : private http::IHandler, private core::NonCopyable<> { status::StatusCode erase_configuration_(cJSON* json, sensor::ds18b20::Sensor& sensor); status::StatusCode - send_response_(unsigned buffer_size, cJSON* json, http::IResponseWriter& w); + send_response_(size_t buffer_size, cJSON* json, http::IResponseWriter& w); system::ISuspender& suspender_; sensor::ds18b20::Store& store_; diff --git a/components/ocs_pipeline/httpserver/http_pipeline.h b/components/ocs_pipeline/httpserver/http_pipeline.h index ad7944b7..4f07dadf 100644 --- a/components/ocs_pipeline/httpserver/http_pipeline.h +++ b/components/ocs_pipeline/httpserver/http_pipeline.h @@ -19,7 +19,7 @@ class HttpPipeline : private core::NonCopyable<> { public: struct DataParams { //! Buffer size to hold the formatted JSON data, in bytes. - unsigned buffer_size { 0 }; + size_t buffer_size { 0 }; }; struct Params { diff --git a/components/ocs_pipeline/httpserver/system_state_handler.cpp b/components/ocs_pipeline/httpserver/system_state_handler.cpp index 076acd14..6af0540d 100644 --- a/components/ocs_pipeline/httpserver/system_state_handler.cpp +++ b/components/ocs_pipeline/httpserver/system_state_handler.cpp @@ -14,7 +14,7 @@ namespace ocs { namespace pipeline { namespace httpserver { -SystemStateHandler::SystemStateHandler(unsigned response_size) { +SystemStateHandler::SystemStateHandler(size_t response_size) { state_json_formatter_.reset(new (std::nothrow) jsonfmt::SystemStateFormatter()); configASSERT(state_json_formatter_); diff --git a/components/ocs_pipeline/httpserver/system_state_handler.h b/components/ocs_pipeline/httpserver/system_state_handler.h index 824a2097..b6b80735 100644 --- a/components/ocs_pipeline/httpserver/system_state_handler.h +++ b/components/ocs_pipeline/httpserver/system_state_handler.h @@ -23,7 +23,7 @@ class SystemStateHandler : public http::IHandler, private core::NonCopyable<> { //! //! @params //! - @p response_size - system state response size, in bytes. - SystemStateHandler(unsigned response_size); + explicit SystemStateHandler(size_t response_size); // Get system state over HTTP. status::StatusCode serve_http(http::IResponseWriter& w, http::IRequest&) override; diff --git a/components/ocs_pipeline/httpserver/web_gui_pipeline.h b/components/ocs_pipeline/httpserver/web_gui_pipeline.h index 83c21ad4..92958977 100644 --- a/components/ocs_pipeline/httpserver/web_gui_pipeline.h +++ b/components/ocs_pipeline/httpserver/web_gui_pipeline.h @@ -36,7 +36,7 @@ class WebGuiPipeline : private http::IHandler, private core::NonCopyable<> { status::StatusCode handle_root_(http::IResponseWriter& w); status::StatusCode handle_file_(http::IResponseWriter& w, const char* filename); - static constexpr unsigned buffer_size_ = 1024; + static constexpr size_t buffer_size_ = 1024; const std::string mount_point_; diff --git a/components/ocs_pipeline/jsonfmt/system_state_formatter.cpp b/components/ocs_pipeline/jsonfmt/system_state_formatter.cpp index f3053e16..9036f613 100644 --- a/components/ocs_pipeline/jsonfmt/system_state_formatter.cpp +++ b/components/ocs_pipeline/jsonfmt/system_state_formatter.cpp @@ -53,7 +53,7 @@ status::StatusCode format_task_state(fmt::json::CjsonObjectFormatter& formatter, return status::StatusCode::NoMem; } - const unsigned decimal_places = 2; + const uint8_t decimal_places = 2; const auto value = static_cast(state.ulRunTimeCounter) / total_time; const auto multiplier = std::pow(10.0, decimal_places); const auto relative = std::ceil(value * multiplier) / multiplier; diff --git a/components/ocs_scheduler/async_func_scheduler.cpp b/components/ocs_scheduler/async_func_scheduler.cpp index 9c640bc7..71684cfc 100644 --- a/components/ocs_scheduler/async_func_scheduler.cpp +++ b/components/ocs_scheduler/async_func_scheduler.cpp @@ -19,7 +19,7 @@ const char* log_tag = "async_func_scheduler"; } // namespace -AsyncFuncScheduler::AsyncFuncScheduler(unsigned max_event_count) +AsyncFuncScheduler::AsyncFuncScheduler(size_t max_event_count) : max_event_count_(max_event_count) { configASSERT(max_event_count_); diff --git a/components/ocs_scheduler/async_func_scheduler.h b/components/ocs_scheduler/async_func_scheduler.h index 4381713b..9e404b67 100644 --- a/components/ocs_scheduler/async_func_scheduler.h +++ b/components/ocs_scheduler/async_func_scheduler.h @@ -27,7 +27,7 @@ class AsyncFuncScheduler : public ITask, private core::NonCopyable<> { //! @params //! - @p max_event_count - maximum number of asynchronous events that can be enqueued //! before run() is called. - explicit AsyncFuncScheduler(unsigned max_event_count); + explicit AsyncFuncScheduler(size_t max_event_count); //! Run scheduled events. status::StatusCode run() override; @@ -39,7 +39,7 @@ class AsyncFuncScheduler : public ITask, private core::NonCopyable<> { FuturePtr add(Func func); private: - const unsigned max_event_count_ { 0 }; + const size_t max_event_count_ { 0 }; using Queue = std::vector; using QueuePtr = std::shared_ptr; diff --git a/components/ocs_scheduler/async_task_scheduler.cpp b/components/ocs_scheduler/async_task_scheduler.cpp index 8f1628b8..2747087a 100644 --- a/components/ocs_scheduler/async_task_scheduler.cpp +++ b/components/ocs_scheduler/async_task_scheduler.cpp @@ -22,7 +22,7 @@ AsyncTaskScheduler::AsyncTaskScheduler(IDelayEstimator& estimator, const char* i , estimator_(estimator) { } -unsigned AsyncTaskScheduler::max_count() const { +size_t AsyncTaskScheduler::max_count() const { //! 8 high bits are used by the FreeRTOS itself. return (sizeof(EventBits_t) * 8) - 8; } diff --git a/components/ocs_scheduler/async_task_scheduler.h b/components/ocs_scheduler/async_task_scheduler.h index 247be6bd..8bdd7b11 100644 --- a/components/ocs_scheduler/async_task_scheduler.h +++ b/components/ocs_scheduler/async_task_scheduler.h @@ -28,7 +28,7 @@ class AsyncTaskScheduler : public ITaskScheduler, private core::NonCopyable<> { AsyncTaskScheduler(IDelayEstimator& estimator, const char* id); //! Maximum number of tasks to which a scheduler can deliver asynchronous events. - unsigned max_count() const override; + size_t max_count() const override; //! Add task to be executed once per interval. //! diff --git a/components/ocs_scheduler/itask_scheduler.h b/components/ocs_scheduler/itask_scheduler.h index 464b5153..e1226523 100644 --- a/components/ocs_scheduler/itask_scheduler.h +++ b/components/ocs_scheduler/itask_scheduler.h @@ -18,7 +18,7 @@ class ITaskScheduler { virtual ~ITaskScheduler() = default; //! Return the maximum number of tasks a scheduler can handle. - virtual unsigned max_count() const = 0; + virtual size_t max_count() const = 0; //! Add task to be executed periodically once per interval. //! diff --git a/components/ocs_scheduler/periodic_task_scheduler.cpp b/components/ocs_scheduler/periodic_task_scheduler.cpp index c1497e6c..4f98d268 100644 --- a/components/ocs_scheduler/periodic_task_scheduler.cpp +++ b/components/ocs_scheduler/periodic_task_scheduler.cpp @@ -19,7 +19,7 @@ namespace scheduler { PeriodicTaskScheduler::PeriodicTaskScheduler(system::IClock& clock, IDelayEstimator& estimator, const char* id, - unsigned max_count) + size_t max_count) : max_count_(max_count) , log_tag_(id) , clock_(clock) @@ -27,7 +27,7 @@ PeriodicTaskScheduler::PeriodicTaskScheduler(system::IClock& clock, configASSERT(max_count_); } -unsigned PeriodicTaskScheduler::max_count() const { +size_t PeriodicTaskScheduler::max_count() const { return max_count_; } diff --git a/components/ocs_scheduler/periodic_task_scheduler.h b/components/ocs_scheduler/periodic_task_scheduler.h index c0d571df..99d3ec07 100644 --- a/components/ocs_scheduler/periodic_task_scheduler.h +++ b/components/ocs_scheduler/periodic_task_scheduler.h @@ -32,10 +32,10 @@ class PeriodicTaskScheduler : public ITaskScheduler, private core::NonCopyable<> PeriodicTaskScheduler(system::IClock& clock, IDelayEstimator& estimator, const char* id, - unsigned max_count); + size_t max_count); //! Return the maximum configured number of tasks a scheduler can handle. - unsigned max_count() const override; + size_t max_count() const override; //! Add task to be executed periodically once per interval. //! @@ -96,7 +96,7 @@ class PeriodicTaskScheduler : public ITaskScheduler, private core::NonCopyable<> void run_(); - const unsigned max_count_ { 0 }; + const size_t max_count_ { 0 }; const std::string log_tag_; system::Time total_ts_min_ { INT64_MAX }; diff --git a/components/ocs_scheduler/test/test_async_task_scheduler.cpp b/components/ocs_scheduler/test/test_async_task_scheduler.cpp index 7c0de5a3..81fbcbc4 100644 --- a/components/ocs_scheduler/test/test_async_task_scheduler.cpp +++ b/components/ocs_scheduler/test/test_async_task_scheduler.cpp @@ -73,14 +73,14 @@ TEST_CASE("Async task scheduler: register maximum tasks", using TaskPtr = std::shared_ptr; std::vector tasks; - for (unsigned n = 0; n < scheduler.max_count(); ++n) { + for (size_t n = 0; n < scheduler.max_count(); ++n) { TaskPtr task(new (std::nothrow) test::TestTask(status::StatusCode::OK)); TEST_ASSERT_NOT_NULL(task); tasks.push_back(task); } - for (unsigned n = 0; n < tasks.size(); ++n) { + for (size_t n = 0; n < tasks.size(); ++n) { const std::string task_id = std::string("test_task_") + std::to_string(n); TEST_ASSERT_EQUAL(status::StatusCode::OK, @@ -111,7 +111,7 @@ TEST_CASE("Async task scheduler: register maximum tasks: some failed", using TaskPtr = std::shared_ptr; std::vector tasks; - for (unsigned n = 0; n < scheduler.max_count(); ++n) { + for (size_t n = 0; n < scheduler.max_count(); ++n) { status::StatusCode code = status::StatusCode::OK; if (n % 2 == 0) { code = status::StatusCode::Error; @@ -123,7 +123,7 @@ TEST_CASE("Async task scheduler: register maximum tasks: some failed", tasks.push_back(task); } - for (unsigned n = 0; n < tasks.size(); ++n) { + for (size_t n = 0; n < tasks.size(); ++n) { const std::string task_id = std::string("test_task_") + std::to_string(n); TEST_ASSERT_EQUAL(status::StatusCode::OK, @@ -154,14 +154,14 @@ TEST_CASE("Async task scheduler: register tasks overflow", using TaskPtr = std::shared_ptr; std::vector tasks; - for (unsigned n = 0; n < scheduler.max_count(); ++n) { + for (size_t n = 0; n < scheduler.max_count(); ++n) { TaskPtr task(new (std::nothrow) test::TestTask(status::StatusCode::OK)); TEST_ASSERT_NOT_NULL(task); tasks.push_back(task); } - for (unsigned n = 0; n < tasks.size(); ++n) { + for (size_t n = 0; n < tasks.size(); ++n) { const std::string task_id = std::string("test_task_") + std::to_string(n); TEST_ASSERT_EQUAL(status::StatusCode::OK, diff --git a/components/ocs_scheduler/test/test_periodic_task_scheduler.cpp b/components/ocs_scheduler/test/test_periodic_task_scheduler.cpp index 3e84ef8b..e65d3940 100644 --- a/components/ocs_scheduler/test/test_periodic_task_scheduler.cpp +++ b/components/ocs_scheduler/test/test_periodic_task_scheduler.cpp @@ -279,7 +279,7 @@ TEST_CASE("Periodic task scheduler: add-remove-run", TEST_CASE("Periodic task scheduler: add multiple tasks", "[ocs_scheduler], [periodic_task_scheduler]") { - const unsigned task_count = 10; + const size_t task_count = 10; const TickType_t delay = pdMS_TO_TICKS(10); const system::Time interval = system::Duration::second; @@ -294,14 +294,14 @@ TEST_CASE("Periodic task scheduler: add multiple tasks", using TaskList = std::vector; TaskList tasks; - for (unsigned n = 0; n < task_count; ++n) { + for (size_t n = 0; n < task_count; ++n) { TaskPtr task(new (std::nothrow) test::TestTask(status::StatusCode::OK)); TEST_ASSERT_NOT_NULL(task); tasks.push_back(task); } - for (unsigned n = 0; n < task_count; ++n) { + for (size_t n = 0; n < task_count; ++n) { const std::string id = "test_task_" + std::to_string(n); TEST_ASSERT_EQUAL(status::StatusCode::OK, task_scheduler.add(*tasks[n], id.c_str(), interval)); @@ -396,7 +396,7 @@ TEST_CASE("Periodic task scheduler: max number of tasks overflow: active", TEST_CASE("Periodic task scheduler: add/remove multiple tasks", "[ocs_scheduler], [periodic_task_scheduler]") { - const unsigned task_count = 10; + const size_t task_count = 10; const TickType_t delay = pdMS_TO_TICKS(10); const system::Time interval = system::Duration::second; @@ -411,14 +411,14 @@ TEST_CASE("Periodic task scheduler: add/remove multiple tasks", using TaskList = std::vector; TaskList tasks; - for (unsigned n = 0; n < task_count; ++n) { + for (size_t n = 0; n < task_count; ++n) { TaskPtr task(new (std::nothrow) test::TestTask(status::StatusCode::OK)); TEST_ASSERT_NOT_NULL(task); tasks.push_back(task); } - for (unsigned n = 0; n < task_count; ++n) { + for (size_t n = 0; n < task_count; ++n) { const std::string id = "test_task_" + std::to_string(n); TEST_ASSERT_EQUAL(status::StatusCode::OK, task_scheduler.add(*tasks[n], id.c_str(), interval)); @@ -433,7 +433,7 @@ TEST_CASE("Periodic task scheduler: add/remove multiple tasks", task->reset(status::StatusCode::OK); } - for (unsigned n = task_count / 2; n < task_count; ++n) { + for (size_t n = task_count / 2; n < task_count; ++n) { const std::string id = "test_task_" + std::to_string(n); TEST_ASSERT_EQUAL(status::StatusCode::OK, task_scheduler.remove(id.c_str())); } @@ -443,17 +443,17 @@ TEST_CASE("Periodic task scheduler: add/remove multiple tasks", TEST_ASSERT_EQUAL(0, task->run_call_count()); } - for (unsigned n = task_count / 2; n < task_count; ++n) { + for (size_t n = task_count / 2; n < task_count; ++n) { const std::string id = "test_task_" + std::to_string(n); TEST_ASSERT_EQUAL(status::StatusCode::OK, task_scheduler.add(*tasks[n], id.c_str(), interval)); } TEST_ASSERT_EQUAL(status::StatusCode::OK, task_scheduler.run()); - for (unsigned n = 0; n < task_count / 2; ++n) { + for (size_t n = 0; n < task_count / 2; ++n) { TEST_ASSERT_EQUAL(0, tasks[n]->run_call_count()); } // The first run is always allowed. - for (unsigned n = task_count / 2; n < task_count; ++n) { + for (size_t n = task_count / 2; n < task_count; ++n) { TEST_ASSERT_EQUAL(1, tasks[n]->run_call_count()); } diff --git a/components/ocs_security/isha_engine.h b/components/ocs_security/isha_engine.h index 6f88459a..982ad11b 100644 --- a/components/ocs_security/isha_engine.h +++ b/components/ocs_security/isha_engine.h @@ -5,6 +5,7 @@ #pragma once +#include #include #include "ocs_status/code.h" @@ -33,7 +34,7 @@ class IShaEngine { //! - @p src should be at least @p size bytes long. //! - @p buf should be large enough to store the result of SHA calculation. virtual status::StatusCode - generate(uint8_t* buf, const uint8_t* src, unsigned size) = 0; + generate(uint8_t* buf, const uint8_t* src, size_t size) = 0; }; } // namespace security diff --git a/components/ocs_security/mbedtls_sha_engine.cpp b/components/ocs_security/mbedtls_sha_engine.cpp index 1b356a80..7d57e588 100644 --- a/components/ocs_security/mbedtls_sha_engine.cpp +++ b/components/ocs_security/mbedtls_sha_engine.cpp @@ -20,7 +20,7 @@ MbedTlsShaEngine::MbedTlsShaEngine(IShaEngine::Algorithm algorithm) } status::StatusCode -MbedTlsShaEngine::generate(uint8_t* buf, const uint8_t* src, unsigned size) { +MbedTlsShaEngine::generate(uint8_t* buf, const uint8_t* src, size_t size) { int result = 0; switch (algorithm_) { diff --git a/components/ocs_security/mbedtls_sha_engine.h b/components/ocs_security/mbedtls_sha_engine.h index a19d31af..6ba04e74 100644 --- a/components/ocs_security/mbedtls_sha_engine.h +++ b/components/ocs_security/mbedtls_sha_engine.h @@ -17,7 +17,7 @@ class MbedTlsShaEngine : public BasicShaEngine, private core::NonCopyable<> { explicit MbedTlsShaEngine(IShaEngine::Algorithm algorithm); //! Generate SHA by using the mbedTLS library. - status::StatusCode generate(uint8_t* buf, const uint8_t* src, unsigned size) override; + status::StatusCode generate(uint8_t* buf, const uint8_t* src, size_t size) override; }; } // namespace security diff --git a/components/ocs_security/sha_generator.cpp b/components/ocs_security/sha_generator.cpp index b194a1f0..4677fe90 100644 --- a/components/ocs_security/sha_generator.cpp +++ b/components/ocs_security/sha_generator.cpp @@ -18,8 +18,8 @@ const ShaGenerator::Data& ShaGenerator::get_sha() const { return sha_; } -void ShaGenerator::add(const uint8_t* buf, unsigned size) { - for (unsigned n = 0; n < size; ++n) { +void ShaGenerator::add(const uint8_t* buf, size_t size) { + for (size_t n = 0; n < size; ++n) { src_.push_back(buf[n]); } } diff --git a/components/ocs_security/sha_generator.h b/components/ocs_security/sha_generator.h index 220260a4..0eb09a58 100644 --- a/components/ocs_security/sha_generator.h +++ b/components/ocs_security/sha_generator.h @@ -24,7 +24,7 @@ class ShaGenerator : private core::NonCopyable<> { const Data& get_sha() const; //! Add @p size bytes from @p buf to be used during SHA calculation. - void add(const uint8_t* buf, unsigned size); + void add(const uint8_t* buf, size_t size); //! Generate SHA based on the underlying data. status::StatusCode generate(); diff --git a/components/ocs_security/sha_to_hex_str.cpp b/components/ocs_security/sha_to_hex_str.cpp index 9ee46d18..5f8a4014 100644 --- a/components/ocs_security/sha_to_hex_str.cpp +++ b/components/ocs_security/sha_to_hex_str.cpp @@ -13,12 +13,12 @@ namespace ocs { namespace security { -sha_to_hex_str::sha_to_hex_str(const uint8_t* sha, unsigned size) { +sha_to_hex_str::sha_to_hex_str(const uint8_t* sha, size_t size) { configASSERT(size <= max_hash_length_); memset(buf_, 0, sizeof(buf_)); - for (unsigned n = 0; n < size; ++n) { + for (size_t n = 0; n < size; ++n) { sprintf(buf_ + n * 2, "%02X", sha[n]); } } diff --git a/components/ocs_security/sha_to_hex_str.h b/components/ocs_security/sha_to_hex_str.h index 9d2cfeb6..dfd7eda5 100644 --- a/components/ocs_security/sha_to_hex_str.h +++ b/components/ocs_security/sha_to_hex_str.h @@ -18,13 +18,13 @@ class sha_to_hex_str : private core::NonCopyable<> { //! //! @params //! - @p sha - SHA data, @p size bytes long. - sha_to_hex_str(const uint8_t* sha, unsigned size); + sha_to_hex_str(const uint8_t* sha, size_t size); //! Return SHA formatted as a hex string. const char* c_str() const; private: - static constexpr unsigned max_hash_length_ = + static constexpr size_t max_hash_length_ = algo::ShaEngineOps::hash_lenght(IShaEngine::Algorithm::SHA512); char buf_[max_hash_length_ + 1]; diff --git a/components/ocs_sensor/analog_sample_reader.cpp b/components/ocs_sensor/analog_sample_reader.cpp index 601a38c4..dde321a1 100644 --- a/components/ocs_sensor/analog_sample_reader.cpp +++ b/components/ocs_sensor/analog_sample_reader.cpp @@ -40,7 +40,7 @@ status::StatusCode AnalogSampleReader::read(int& raw) { int total = 0; - for (unsigned n = 0; n < sample_count; ++n) { + for (size_t n = 0; n < sample_count; ++n) { int result = 0; OCS_STATUS_RETURN_ON_ERROR(reader_.read(result)); diff --git a/components/ocs_sensor/bme280/itransceiver.h b/components/ocs_sensor/bme280/itransceiver.h index ef4ea8a7..a0f440c0 100644 --- a/components/ocs_sensor/bme280/itransceiver.h +++ b/components/ocs_sensor/bme280/itransceiver.h @@ -19,11 +19,11 @@ class ITransceiver { //! Send @p size registers from @p buf start with @p addr. virtual status::StatusCode - send(const uint8_t* buf, unsigned size, RegisterAddress addr) = 0; + send(const uint8_t* buf, size_t size, RegisterAddress addr) = 0; //! Receive @p size registers to @p buf start with @p addr. virtual status::StatusCode - receive(uint8_t* buf, unsigned size, RegisterAddress addr) = 0; + receive(uint8_t* buf, size_t size, RegisterAddress addr) = 0; }; } // namespace bme280 diff --git a/components/ocs_sensor/bme280/sensor.cpp b/components/ocs_sensor/bme280/sensor.cpp index 3b6882bd..d8ac6265 100644 --- a/components/ocs_sensor/bme280/sensor.cpp +++ b/components/ocs_sensor/bme280/sensor.cpp @@ -121,12 +121,12 @@ Sensor::Data Sensor::get_data() const { void Sensor::estimate_measurement_time_() { // Appendix B: measurement time and current calculation, page 51. - const unsigned typ_measurement_duration = + const size_t typ_measurement_duration = std::ceil(1 + (2 * oversampling_to_coef(params_.temperature_oversampling)) + ((2 * oversampling_to_coef(params_.pressure_oversampling)) + 0.5) + ((2 * oversampling_to_coef(params_.humidity_oversampling)) + 0.5)); - const unsigned max_measurement_duration = std::ceil( + const size_t max_measurement_duration = std::ceil( 1.25 + (2.3 * oversampling_to_coef(params_.temperature_oversampling)) + ((2.3 * oversampling_to_coef(params_.pressure_oversampling)) + 0.575) + ((2.3 * oversampling_to_coef(params_.humidity_oversampling)) + 0.575)); @@ -242,7 +242,7 @@ status::StatusCode Sensor::read_calibration1_() { status::StatusCode Sensor::read_calibration2_() { // 7 registers. - const unsigned calibration_register_count = 0xE7 - 0xE1 + 1; + const size_t calibration_register_count = 0xE7 - 0xE1 + 1; uint8_t recv_buf[calibration_register_count]; memset(recv_buf, 0, sizeof(recv_buf)); diff --git a/components/ocs_sensor/bme280/spi_transceiver.cpp b/components/ocs_sensor/bme280/spi_transceiver.cpp index 39f0d0ca..6ad741f2 100644 --- a/components/ocs_sensor/bme280/spi_transceiver.cpp +++ b/components/ocs_sensor/bme280/spi_transceiver.cpp @@ -18,16 +18,16 @@ SpiTransceiver::SpiTransceiver(io::spi::ITransceiver& transceiver) } status::StatusCode -SpiTransceiver::send(const uint8_t* buf, unsigned size, RegisterAddress addr) { +SpiTransceiver::send(const uint8_t* buf, size_t size, RegisterAddress addr) { //! Each register is sent as a pair of bytes: | control byte | data byte |. const auto send_buf_size = size * 2; uint8_t send_buf[send_buf_size]; memset(send_buf, 0, sizeof(send_buf)); - unsigned pos = 0; + size_t pos = 0; - for (unsigned n = 0; n < send_buf_size;) { + for (size_t n = 0; n < send_buf_size;) { //! Set the MSB bit to 0 to indicate a write command. const uint8_t control_byte = addr & algo::BitOps::umask(7); const uint8_t data_byte = buf[pos]; @@ -43,7 +43,7 @@ SpiTransceiver::send(const uint8_t* buf, unsigned size, RegisterAddress addr) { } status::StatusCode -SpiTransceiver::receive(uint8_t* buf, unsigned size, RegisterAddress addr) { +SpiTransceiver::receive(uint8_t* buf, size_t size, RegisterAddress addr) { //! Dummy bytes are used to clock out the data we want to receive. uint8_t send_buf[size + 1]; memset(send_buf, 0, sizeof(send_buf)); diff --git a/components/ocs_sensor/bme280/spi_transceiver.h b/components/ocs_sensor/bme280/spi_transceiver.h index 7938b452..e8dd58c0 100644 --- a/components/ocs_sensor/bme280/spi_transceiver.h +++ b/components/ocs_sensor/bme280/spi_transceiver.h @@ -23,11 +23,10 @@ class SpiTransceiver : public ITransceiver, private core::NonCopyable<> { //! Send registers to SPI device. status::StatusCode - send(const uint8_t* buf, unsigned size, RegisterAddress addr) override; + send(const uint8_t* buf, size_t size, RegisterAddress addr) override; //! Receive registers from SPI device. - status::StatusCode - receive(uint8_t* buf, unsigned size, RegisterAddress addr) override; + status::StatusCode receive(uint8_t* buf, size_t size, RegisterAddress addr) override; private: io::spi::ITransceiver& transceiver_; diff --git a/components/ocs_sensor/ds18b20/parse_configuration.cpp b/components/ocs_sensor/ds18b20/parse_configuration.cpp index b2c34725..db537844 100644 --- a/components/ocs_sensor/ds18b20/parse_configuration.cpp +++ b/components/ocs_sensor/ds18b20/parse_configuration.cpp @@ -49,7 +49,7 @@ bool parse_serial_number(onewire::SerialNumber& serial_number, return false; } - for (unsigned n = 0; n < OCS_ARRAY_SIZE(serial_number); ++n) { + for (size_t n = 0; n < OCS_ARRAY_SIZE(serial_number); ++n) { const auto str = values[n]; if (str.size() != strlen("AA")) { return false; diff --git a/components/ocs_sensor/ds18b20/store.cpp b/components/ocs_sensor/ds18b20/store.cpp index 85bb5627..b113ce76 100644 --- a/components/ocs_sensor/ds18b20/store.cpp +++ b/components/ocs_sensor/ds18b20/store.cpp @@ -24,7 +24,7 @@ const char* log_tag = "ds18b20_store"; } // namespace -Store::Store(system::IRtDelayer& delayer, unsigned max_event_count) +Store::Store(system::IRtDelayer& delayer, size_t max_event_count) : max_event_count_(max_event_count) , delayer_(delayer) { configASSERT(max_event_count_); @@ -35,7 +35,7 @@ status::StatusCode Store::run() { const auto code = node->run(); if (code != status::StatusCode::OK) { ocs_logw(log_tag, "failed to handle events on the bus: gpio=%d code=%s", - static_cast(gpio), status::code_to_str(code)); + static_cast(gpio), status::code_to_str(code)); } } @@ -87,7 +87,7 @@ Store::NodePtr Store::add_node_(io::gpio::Gpio gpio, const char* gpio_id) { Store::Node::Node(system::IRtDelayer& delayer, io::gpio::Gpio gpio, const char* gpio_id, - unsigned max_event_count) + size_t max_event_count) : func_scheduler_(max_event_count) { gpio_.reset(new (std::nothrow) io::gpio::DefaultGpio(gpio_id, gpio)); configASSERT(gpio_); diff --git a/components/ocs_sensor/ds18b20/store.h b/components/ocs_sensor/ds18b20/store.h index 077f2e5f..b9dc2abc 100644 --- a/components/ocs_sensor/ds18b20/store.h +++ b/components/ocs_sensor/ds18b20/store.h @@ -34,7 +34,7 @@ class Store : public scheduler::ITask, private core::NonCopyable<> { //! - @p max_event_count - maximum number of asynchronous events that can be //! scheduled per 1-Wire bus. If the value is too small and the run() is called //! rarely, it's possible to miss some events. - Store(system::IRtDelayer& delayer, unsigned max_event_count); + Store(system::IRtDelayer& delayer, size_t max_event_count); //! Handle asynchronous events on the 1-wire buses. status::StatusCode run() override; @@ -60,7 +60,7 @@ class Store : public scheduler::ITask, private core::NonCopyable<> { Node(system::IRtDelayer& delayer, io::gpio::Gpio gpio, const char* gpio_id, - unsigned max_event_count); + size_t max_event_count); //! Handle operations on the 1-Wire bus. status::StatusCode run() override; @@ -86,7 +86,7 @@ class Store : public scheduler::ITask, private core::NonCopyable<> { NodePtr get_node_(io::gpio::Gpio gpio); NodePtr add_node_(io::gpio::Gpio gpio, const char* gpio_id); - const unsigned max_event_count_ { 0 }; + const size_t max_event_count_ { 0 }; system::IRtDelayer& delayer_; diff --git a/components/ocs_sensor/sht4x/sensor.h b/components/ocs_sensor/sht4x/sensor.h index 2decf4a0..a5eb43e9 100644 --- a/components/ocs_sensor/sht4x/sensor.h +++ b/components/ocs_sensor/sht4x/sensor.h @@ -31,7 +31,7 @@ class Sensor : public scheduler::ITask, private core::NonCopyable<> { struct Data { double humidity { 0.0 }; double temperature { 0.0 }; - unsigned heating_count { 0 }; + size_t heating_count { 0 }; }; enum class Command { @@ -136,7 +136,7 @@ class Sensor : public scheduler::ITask, private core::NonCopyable<> { storage::IStorage& storage_; TickType_t heating_delay_ { 0 }; - unsigned heating_count_ { 0 }; + size_t heating_count_ { 0 }; bool initialized_ { false }; SerialNumber serial_number_ { 0 }; diff --git a/components/ocs_sensor/sht4x/serial_number_to_str.h b/components/ocs_sensor/sht4x/serial_number_to_str.h index a05bb793..9e834415 100644 --- a/components/ocs_sensor/sht4x/serial_number_to_str.h +++ b/components/ocs_sensor/sht4x/serial_number_to_str.h @@ -17,7 +17,7 @@ namespace sht4x { //! Format sensor serial number to string. class serial_number_to_str : private core::NonCopyable<> { public: - static constexpr unsigned str_length = strlen("AA:BB:CC:DD"); + static constexpr size_t str_length = strlen("AA:BB:CC:DD"); //! Initialize. serial_number_to_str(const SerialNumber& serial_number); diff --git a/components/ocs_sensor/test/soil/test_analog_sensor.cpp b/components/ocs_sensor/test/soil/test_analog_sensor.cpp index 33951910..e9518d4c 100644 --- a/components/ocs_sensor/test/soil/test_analog_sensor.cpp +++ b/components/ocs_sensor/test/soil/test_analog_sensor.cpp @@ -158,7 +158,7 @@ TEST_CASE("Soil analog sensor: validate each status", const uint16_t def_max = 26; const char* id = "test"; - const unsigned status_interval = + const uint16_t status_interval = (def_max - def_min) / AnalogSensor::get_status_count(); const system::Time resolution = system::Duration::second; @@ -341,7 +341,7 @@ TEST_CASE("Soil analog sensor: read initial status from storage", const char* id = "test"; const system::Time resolution = system::Duration::second; - const unsigned status_interval = + const uint16_t status_interval = (def_max - def_min) / AnalogSensor::get_status_count(); test::MemoryStorage config_storage; @@ -422,7 +422,7 @@ TEST_CASE("Soil analog sensor: ignore changes close to the threshold: valid stat const uint16_t range = def_max - def_min; TEST_ASSERT_TRUE((range % AnalogSensor::get_status_count()) == 0); - const unsigned status_interval = range / AnalogSensor::get_status_count(); + const uint16_t status_interval = range / AnalogSensor::get_status_count(); const uint8_t status_threshold = 49; const double moisture_per_off = static_cast(1) / range; @@ -550,7 +550,7 @@ TEST_CASE("Soil analog sensor: ignore changes close to the threshold: invalid st const uint16_t range = def_max - def_min; TEST_ASSERT_TRUE((range % AnalogSensor::get_status_count()) == 0); - const unsigned status_interval = range / AnalogSensor::get_status_count(); + const uint16_t status_interval = range / AnalogSensor::get_status_count(); const uint8_t status_threshold = 49; const double moisture_per_off = static_cast(1) / range; diff --git a/components/ocs_sensor/test/test_analog_sample_reader.cpp b/components/ocs_sensor/test/test_analog_sample_reader.cpp index 9b95ac10..1fae0e67 100644 --- a/components/ocs_sensor/test/test_analog_sample_reader.cpp +++ b/components/ocs_sensor/test/test_analog_sample_reader.cpp @@ -32,7 +32,7 @@ Samples generate_samples(const AnalogConfig& config) { Samples samples; - for (unsigned n = 0; n < config.get_sample_count(); ++n) { + for (size_t n = 0; n < config.get_sample_count(); ++n) { samples.push_back(random(static_cast(0), max_value)); } diff --git a/components/ocs_storage/target_esp32/nvs_storage.cpp b/components/ocs_storage/target_esp32/nvs_storage.cpp index 2fcdbc23..9c55a6ef 100644 --- a/components/ocs_storage/target_esp32/nvs_storage.cpp +++ b/components/ocs_storage/target_esp32/nvs_storage.cpp @@ -24,7 +24,7 @@ NvsStorage::NvsStorage(const char* ns) { configASSERT(strlen(ns) <= max_namespace_len); memset(ns_, 0, sizeof(ns_)); - strncpy(ns_, ns, std::min(max_namespace_len, strlen(ns))); + strncpy(ns_, ns, std::min(static_cast(max_namespace_len), strlen(ns))); } status::StatusCode NvsStorage::probe(const char* key, size_t& size) { diff --git a/components/ocs_storage/target_esp32/nvs_storage.h b/components/ocs_storage/target_esp32/nvs_storage.h index 397594ad..68807381 100644 --- a/components/ocs_storage/target_esp32/nvs_storage.h +++ b/components/ocs_storage/target_esp32/nvs_storage.h @@ -19,7 +19,7 @@ namespace storage { class NvsStorage : public IStorage, private core::NonCopyable<> { public: //! Maximum number of symbols for the storage namespace, without NULL character. - static constexpr unsigned max_namespace_len = NVS_KEY_NAME_MAX_SIZE - 1; + static constexpr uint8_t max_namespace_len = NVS_KEY_NAME_MAX_SIZE - 1; //! Initialize. //! diff --git a/components/ocs_storage/test/target_esp32/test_nvs_storage.cpp b/components/ocs_storage/test/target_esp32/test_nvs_storage.cpp index 02fa6de1..d17ea8a0 100644 --- a/components/ocs_storage/test/target_esp32/test_nvs_storage.cpp +++ b/components/ocs_storage/test/target_esp32/test_nvs_storage.cpp @@ -18,8 +18,8 @@ TEST_CASE("NVS storage: write-read-erase", "[ocs_storage], [nvs_storage]") { FlashInitializer initializer; const char* id = "foo"; - const unsigned write_value = 42; - unsigned read_value = 0; + const size_t write_value = 42; + size_t read_value = 0; NvsStorage storage("tests"); @@ -44,7 +44,7 @@ TEST_CASE("NVS storage: read: no data", "[ocs_storage], [nvs_storage]") { FlashInitializer initializer; const char* id = "foo"; - unsigned value = 0; + size_t value = 0; NvsStorage storage("tests"); TEST_ASSERT_EQUAL(status::StatusCode::NoData, @@ -97,9 +97,9 @@ TEST_CASE("NVS storage: overwrite key", "[ocs_storage], [nvs_storage]") { FlashInitializer initializer; const char* id = "overwrite"; - const unsigned initial_value = 10; - const unsigned updated_value = 20; - unsigned read_value = 0; + const size_t initial_value = 10; + const size_t updated_value = 20; + size_t read_value = 0; NvsStorage storage("tests"); diff --git a/components/ocs_system/test/target_esp32/test_rt_delayer.cpp b/components/ocs_system/test/target_esp32/test_rt_delayer.cpp index 8dcccd59..68e15dcc 100644 --- a/components/ocs_system/test/target_esp32/test_rt_delayer.cpp +++ b/components/ocs_system/test/target_esp32/test_rt_delayer.cpp @@ -13,7 +13,7 @@ namespace system { TEST_CASE("Rt delayer: delay", "[ocs_system], [rt_delayer]") { RtDelayer delayer; - for (unsigned n = 0; n < 10; ++n) { + for (size_t n = 0; n < 10; ++n) { delayer.delay(system::Duration::microsecond * 100); } } diff --git a/components/ocs_system/test/test_fanout_suspender.cpp b/components/ocs_system/test/test_fanout_suspender.cpp index 9fac7da1..13c7d21c 100644 --- a/components/ocs_system/test/test_fanout_suspender.cpp +++ b/components/ocs_system/test/test_fanout_suspender.cpp @@ -31,8 +31,8 @@ class TestHandler : public ISuspendHandler { return resume_code_; } - unsigned suspend_count { 0 }; - unsigned resume_count { 0 }; + size_t suspend_count { 0 }; + size_t resume_count { 0 }; private: status::StatusCode suspend_code_ { status::StatusCode::OK }; diff --git a/components/ocs_system/time.h b/components/ocs_system/time.h index 37b557b3..1ce9f7b4 100644 --- a/components/ocs_system/time.h +++ b/components/ocs_system/time.h @@ -22,7 +22,7 @@ using Time = int64_t; //! //! To convert an integer number of units to a Duration, multiply: //! -//! const unsigned seconds = 10; +//! const size_t seconds = 10; //! print(seconds * Duration::second) // prints 10 * 1000 * 1000 struct Duration { //! One microsecond represented in microseconds. diff --git a/components/ocs_test/test_gpio.h b/components/ocs_test/test_gpio.h index f93b322b..e7efc33c 100644 --- a/components/ocs_test/test_gpio.h +++ b/components/ocs_test/test_gpio.h @@ -5,6 +5,8 @@ #pragma once +#include + #include "ocs_core/noncopyable.h" #include "ocs_io/gpio/igpio.h" @@ -23,9 +25,9 @@ class TestGpio : public io::gpio::IGpio, private core::NonCopyable<> { status::StatusCode turn_off() override; status::StatusCode set_direction(IGpio::Direction direction) override; - unsigned flip_call_count { 0 }; - unsigned turn_on_call_count { 0 }; - unsigned turn_off_call_count { 0 }; + size_t flip_call_count { 0 }; + size_t turn_on_call_count { 0 }; + size_t turn_off_call_count { 0 }; IGpio::Direction direction { IGpio::Direction::Output }; private: diff --git a/components/ocs_test/test_task.cpp b/components/ocs_test/test_task.cpp index 60516724..ec9cadac 100644 --- a/components/ocs_test/test_task.cpp +++ b/components/ocs_test/test_task.cpp @@ -32,7 +32,7 @@ bool TestTask::was_run_called() const { return run_called_; } -unsigned TestTask::run_call_count() const { +size_t TestTask::run_call_count() const { core::LockGuard lock(mu_); return run_call_count_; diff --git a/components/ocs_test/test_task.h b/components/ocs_test/test_task.h index 2c99c499..ca483c62 100644 --- a/components/ocs_test/test_task.h +++ b/components/ocs_test/test_task.h @@ -20,7 +20,7 @@ class TestTask : public scheduler::ITask, private core::NonCopyable<> { status::StatusCode run() override; bool was_run_called() const; - unsigned run_call_count() const; + size_t run_call_count() const; //! Reset to initial state. void reset(status::StatusCode code); @@ -34,7 +34,7 @@ class TestTask : public scheduler::ITask, private core::NonCopyable<> { status::StatusCode code_ { status::StatusCode::OK }; bool run_called_ { false }; - unsigned run_call_count_ { 0 }; + size_t run_call_count_ { 0 }; }; } // namespace test diff --git a/components/ocs_test/test_timer.h b/components/ocs_test/test_timer.h index e7a81713..2ee41e38 100644 --- a/components/ocs_test/test_timer.h +++ b/components/ocs_test/test_timer.h @@ -5,6 +5,8 @@ #pragma once +#include + #include "ocs_core/noncopyable.h" #include "ocs_system/itimer.h" @@ -18,8 +20,8 @@ class TestTimer : public system::ITimer, private core::NonCopyable<> { status::StatusCode start() override; status::StatusCode stop() override; - unsigned start_call_count { 0 }; - unsigned stop_call_count { 0 }; + size_t start_call_count { 0 }; + size_t stop_call_count { 0 }; private: status::StatusCode code_ { status::StatusCode::OK }; diff --git a/projects/ds18b20-verifier/main/main.cpp b/projects/ds18b20-verifier/main/main.cpp index e2cba73d..be90d5a2 100644 --- a/projects/ds18b20-verifier/main/main.cpp +++ b/projects/ds18b20-verifier/main/main.cpp @@ -31,7 +31,7 @@ const char* log_tag = "ds18b20_verifier"; struct VerifyParams { io::gpio::Gpio gpio { static_cast(-1) }; - unsigned total_attempts { 0 }; + size_t total_attempts { 0 }; TickType_t delay { pdMS_TO_TICKS(0) }; }; @@ -107,9 +107,9 @@ void read_device(onewire::Bus& bus, const onewire::RomCode& rom_code, cJSON* json, VerifyParams verify_params) { - unsigned failed_attempts = 0; + size_t failed_attempts = 0; - for (unsigned n = 0; n < verify_params.total_attempts; ++n) { + for (size_t n = 0; n < verify_params.total_attempts; ++n) { const auto code = read_temperature(bus, rom_code); if (code != status::StatusCode::OK) { ++failed_attempts; diff --git a/projects/sht4x-verifier/main/main.cpp b/projects/sht4x-verifier/main/main.cpp index 9fdc32b0..cbe1e4f3 100644 --- a/projects/sht4x-verifier/main/main.cpp +++ b/projects/sht4x-verifier/main/main.cpp @@ -71,10 +71,10 @@ extern "C" void app_main(void) { ocs_logw(log_tag, "failed to reset sensor: %s", status::code_to_str(code)); } - const unsigned total_attempts = CONFIG_OCS_TOOLS_SHT4x_VERIFIER_TOTAL_ATTEMPTS; - unsigned failed_attempts = 0; + const size_t total_attempts = CONFIG_OCS_TOOLS_SHT4x_VERIFIER_TOTAL_ATTEMPTS; + size_t failed_attempts = 0; - for (unsigned n = 0; n < total_attempts; ++n) { + for (size_t n = 0; n < total_attempts; ++n) { const auto code = sensor->run(); if (code != status::StatusCode::OK) { ++failed_attempts;