Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions components/ocs_algo/bit_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions components/ocs_algo/bit_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions components/ocs_algo/container_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename T, unsigned N> struct ArrayHasher {
unsigned operator()(const std::array<T, N>& arr) const {
unsigned h = 0;
template <typename T, size_t N> struct ArrayHasher {
size_t operator()(const std::array<T, N>& arr) const {
size_t h = 0;

for (const auto& e : arr) {
h ^= std::hash<T> {}(e) + 0x9e3779b9 + (h << 6) + (h >> 2);
Expand Down
4 changes: 2 additions & 2 deletions components/ocs_algo/crc_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
3 changes: 2 additions & 1 deletion components/ocs_algo/crc_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#pragma once

#include <cstddef>
#include <cstdint>

namespace ocs {
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion components/ocs_algo/math_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion components/ocs_algo/math_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion components/ocs_algo/sha_engine_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions components/ocs_algo/storage_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion components/ocs_algo/storage_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions components/ocs_algo/test/test_storage_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -67,15 +67,15 @@ 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);
storage.probe_status = status::StatusCode::Error;

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,
Expand All @@ -86,15 +86,15 @@ 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);
storage.read_status = status::StatusCode::Timeout;

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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion components/ocs_algo/uri_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion components/ocs_control/flip_led_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions components/ocs_control/flip_led_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//!
Expand All @@ -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_;
Expand Down
2 changes: 1 addition & 1 deletion components/ocs_control/system_fsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions components/ocs_control/system_fsm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
2 changes: 1 addition & 1 deletion components/ocs_control/test/test_button_event_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions components/ocs_control/test/test_fsm_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions components/ocs_control/test/test_fsm_block_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions components/ocs_control/test/test_fsm_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
Loading