From cce657e1fe2a5eb15dd78511cc14a622bdc12259 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Tue, 25 Mar 2014 01:36:25 +0400 Subject: [PATCH] Manual style fixes, logic was not affected --- .../uavcan/node/global_data_type_registry.hpp | 7 +++--- libuavcan/src/data_type.cpp | 15 +++++++++--- libuavcan/src/driver/can.cpp | 3 ++- libuavcan/src/marshal/bit_array_copy.cpp | 20 ++++++++-------- .../src/node/global_data_type_registry.cpp | 23 +++++++------------ .../src/protocol/global_time_sync_master.cpp | 4 ++-- libuavcan/src/transport/frame.cpp | 3 ++- libuavcan/src/transport/transfer_buffer.cpp | 6 +++-- libuavcan/src/transport/transfer_receiver.cpp | 3 ++- 9 files changed, 45 insertions(+), 39 deletions(-) diff --git a/libuavcan/include/uavcan/node/global_data_type_registry.hpp b/libuavcan/include/uavcan/node/global_data_type_registry.hpp index 60bd5263af..1e210fa1d3 100644 --- a/libuavcan/include/uavcan/node/global_data_type_registry.hpp +++ b/libuavcan/include/uavcan/node/global_data_type_registry.hpp @@ -56,14 +56,13 @@ public: private: typedef LinkedListRoot List; - List msgs_; - List srvs_; + mutable List msgs_; + mutable List srvs_; bool frozen_; GlobalDataTypeRegistry() : frozen_(false) { } - const List* selectList(DataTypeKind kind) const; - List* selectList(DataTypeKind kind); + List* selectList(DataTypeKind kind) const; RegistResult remove(Entry* dtd); RegistResult registImpl(Entry* dtd); diff --git a/libuavcan/src/data_type.cpp b/libuavcan/src/data_type.cpp index 761e3274dc..da52f71e5f 100644 --- a/libuavcan/src/data_type.cpp +++ b/libuavcan/src/data_type.cpp @@ -55,9 +55,18 @@ std::string DataTypeDescriptor::toString() const char kindch = '?'; switch (kind_) { - case DataTypeKindMessage: kindch = 'm'; break; - case DataTypeKindService: kindch = 's'; break; - default: assert(0); + case DataTypeKindMessage: + { + kindch = 'm'; + break; + } + case DataTypeKindService: + { + kindch = 's'; + break; + } + default: + assert(0); } std::ostringstream os; diff --git a/libuavcan/src/driver/can.cpp b/libuavcan/src/driver/can.cpp index 0113a6dfd5..efc3b8ad4a 100644 --- a/libuavcan/src/driver/can.cpp +++ b/libuavcan/src/driver/can.cpp @@ -26,7 +26,8 @@ std::string CanFrame::toString(StringRepresentation mode) const static const int ASCII_COLUMN_OFFSET = 36; char buf[50]; - char* wpos = buf, *epos = buf + sizeof(buf); + char* wpos = buf; + char* const epos = buf + sizeof(buf); std::fill(buf, buf + sizeof(buf), 0); if (id & FlagEFF) diff --git a/libuavcan/src/marshal/bit_array_copy.cpp b/libuavcan/src/marshal/bit_array_copy.cpp index a974602574..e1cc6fd641 100644 --- a/libuavcan/src/marshal/bit_array_copy.cpp +++ b/libuavcan/src/marshal/bit_array_copy.cpp @@ -7,16 +7,16 @@ #include #include -#define PREPARE_FIRST_COPY() \ - do { \ - if (src_len >= (CHAR_BIT - dst_offset_modulo)) { \ - *dst &= reverse_mask[dst_offset_modulo]; \ - src_len -= CHAR_BIT - dst_offset_modulo; \ - } else { \ - *dst &= reverse_mask[dst_offset_modulo] \ - | reverse_mask_xor[dst_offset_modulo + src_len + 1];\ - c &= reverse_mask[dst_offset_modulo + src_len ];\ - src_len = 0; \ +#define PREPARE_FIRST_COPY() \ + do { \ + if (src_len >= (CHAR_BIT - dst_offset_modulo)) { \ + *dst &= reverse_mask[dst_offset_modulo]; \ + src_len -= CHAR_BIT - dst_offset_modulo; \ + } else { \ + *dst &= reverse_mask[dst_offset_modulo] | \ + reverse_mask_xor[dst_offset_modulo + src_len + 1]; \ + c &= reverse_mask[dst_offset_modulo + src_len]; \ + src_len = 0; \ } } while (0) namespace uavcan diff --git a/libuavcan/src/node/global_data_type_registry.cpp b/libuavcan/src/node/global_data_type_registry.cpp index d9d2b3ecf1..2f1f7dd0c9 100644 --- a/libuavcan/src/node/global_data_type_registry.cpp +++ b/libuavcan/src/node/global_data_type_registry.cpp @@ -10,25 +10,18 @@ namespace uavcan { -const GlobalDataTypeRegistry::List* GlobalDataTypeRegistry::selectList(DataTypeKind kind) const +GlobalDataTypeRegistry::List* GlobalDataTypeRegistry::selectList(DataTypeKind kind) const { - switch (kind) + if (kind == DataTypeKindMessage) { - case DataTypeKindMessage: return &msgs_; - case DataTypeKindService: return &srvs_; - default: - assert(0); - return NULL; + return &msgs_; } -} - -GlobalDataTypeRegistry::List* GlobalDataTypeRegistry::selectList(DataTypeKind kind) -{ - switch (kind) + else if (kind == DataTypeKindService) + { + return &srvs_; + } + else { - case DataTypeKindMessage: return &msgs_; - case DataTypeKindService: return &srvs_; - default: assert(0); return NULL; } diff --git a/libuavcan/src/protocol/global_time_sync_master.cpp b/libuavcan/src/protocol/global_time_sync_master.cpp index 5727dbbba9..10991dc4cd 100644 --- a/libuavcan/src/protocol/global_time_sync_master.cpp +++ b/libuavcan/src/protocol/global_time_sync_master.cpp @@ -104,8 +104,8 @@ int GlobalTimeSyncMaster::init() } // Data type ID - const DataTypeDescriptor* const desc = GlobalDataTypeRegistry::instance().find(DataTypeKindMessage, - protocol::GlobalTimeSync::getDataTypeFullName()); + const DataTypeDescriptor* const desc = + GlobalDataTypeRegistry::instance().find(DataTypeKindMessage, protocol::GlobalTimeSync::getDataTypeFullName()); if (desc == NULL) { return -1; diff --git a/libuavcan/src/transport/frame.cpp b/libuavcan/src/transport/frame.cpp index 3c3483ee67..16f152257a 100644 --- a/libuavcan/src/transport/frame.cpp +++ b/libuavcan/src/transport/frame.cpp @@ -116,7 +116,8 @@ bool Frame::compile(CanFrame& out_can_frame) const return false; } - out_can_frame.id = CanFrame::FlagEFF | + out_can_frame.id = + CanFrame::FlagEFF | bitpack<0, 3>(transfer_id_.get()) | bitpack<3, 1>(last_frame_) | bitpack<4, 6>(frame_index_) | diff --git a/libuavcan/src/transport/transfer_buffer.cpp b/libuavcan/src/transport/transfer_buffer.cpp index acfed726a1..ba477f26ba 100644 --- a/libuavcan/src/transport/transfer_buffer.cpp +++ b/libuavcan/src/transport/transfer_buffer.cpp @@ -147,9 +147,11 @@ int DynamicTransferBufferManagerEntry::write(unsigned int offset, const uint8_t* len = max_size_ - offset; assert((offset + len) <= max_size_); - unsigned int total_offset = 0, left_to_write = len; + unsigned int total_offset = 0; + unsigned int left_to_write = len; const uint8_t* inptr = data; - Block* p = blocks_.get(), *last_written_block = NULL; + Block* p = blocks_.get(); + Block* last_written_block = NULL; // First we need to write the part that is already allocated while (p) diff --git a/libuavcan/src/transport/transfer_receiver.cpp b/libuavcan/src/transport/transfer_receiver.cpp index 37c9d80dfd..cab435a4c9 100644 --- a/libuavcan/src/transport/transfer_receiver.cpp +++ b/libuavcan/src/transport/transfer_receiver.cpp @@ -182,7 +182,8 @@ TransferReceiver::ResultCode TransferReceiver::addFrame(const RxFrame& frame, Tr const bool iface_timed_out = (frame.getMonotonicTimestamp() - this_transfer_ts_).toUSec() > (uint64_t(transfer_interval_usec_) * 2); - const bool need_restart = // FSM, the hard way + // FSM, the hard way + const bool need_restart = (not_initialized) || (receiver_timed_out) || (same_iface && first_fame && (tid_rel == TidFuture)) ||