From 33516cd75892acd20d99cbb780037ae53e096b9b Mon Sep 17 00:00:00 2001 From: Adrian Del Grosso <10929341+ad3154@users.noreply.github.com> Date: Thu, 31 Oct 2024 00:54:02 -0500 Subject: [PATCH] Various Sonar Cleanup --- .../can_extended_transport_protocol.hpp | 12 ++--- .../isobus/isobus/can_network_manager.hpp | 10 ++-- .../isobus/can_partnered_control_function.hpp | 4 +- .../isobus/isobus/can_transport_protocol.hpp | 12 ++--- .../isobus_language_command_interface.hpp | 2 +- .../isobus_task_controller_server_options.hpp | 2 +- .../isobus/isobus_time_date_interface.hpp | 2 +- .../isobus/isobus_virtual_terminal_client.hpp | 6 +-- .../isobus/isobus_virtual_terminal_server.hpp | 28 +++++------ ...al_terminal_server_managed_working_set.hpp | 2 +- ...obus_virtual_terminal_working_set_base.hpp | 2 +- isobus/src/can_NAME_filter.cpp | 1 + .../src/can_extended_transport_protocol.cpp | 12 ++--- isobus/src/can_message.cpp | 10 ++-- isobus/src/can_network_manager.cpp | 12 ++--- isobus/src/can_partnered_control_function.cpp | 8 ++-- isobus/src/can_transport_protocol.cpp | 12 ++--- .../isobus_device_descriptor_object_pool.cpp | 36 +++++++------- isobus/src/isobus_diagnostic_protocol.cpp | 2 +- isobus/src/isobus_functionalities.cpp | 15 ++++-- .../src/isobus_language_command_interface.cpp | 2 +- .../src/isobus_shortcut_button_interface.cpp | 4 +- isobus/src/isobus_task_controller_client.cpp | 8 ++-- .../isobus_task_controller_client_objects.cpp | 9 ++-- .../isobus_task_controller_server_options.cpp | 10 ++-- isobus/src/isobus_time_date_interface.cpp | 2 +- isobus/src/isobus_virtual_terminal_client.cpp | 48 +++++++++---------- isobus/src/isobus_virtual_terminal_server.cpp | 48 +++++++++---------- ...al_terminal_server_managed_working_set.cpp | 8 +--- ...obus_virtual_terminal_working_set_base.cpp | 16 +++---- test/core_network_management_tests.cpp | 3 ++ 31 files changed, 178 insertions(+), 170 deletions(-) diff --git a/isobus/include/isobus/isobus/can_extended_transport_protocol.hpp b/isobus/include/isobus/isobus/can_extended_transport_protocol.hpp index 24669bcf2..7245bcb5c 100644 --- a/isobus/include/isobus/isobus/can_extended_transport_protocol.hpp +++ b/isobus/include/isobus/isobus/can_extended_transport_protocol.hpp @@ -219,31 +219,31 @@ namespace isobus /// @brief Gracefully closes a session to prepare for a new session /// @param[in] session The session to close /// @param[in] successful Denotes if the session was successful - void close_session(std::shared_ptr &session, bool successful); + void close_session(const std::shared_ptr &session, bool successful); /// @brief Sends the "request to send" message as part of initiating a transmit /// @param[in] session The session for which we're sending the RTS /// @returns true if the RTS was sent, false if sending was not successful - bool send_request_to_send(std::shared_ptr &session) const; + bool send_request_to_send(const std::shared_ptr &session) const; /// @brief Sends the "clear to send" message /// @param[in] session The session for which we're sending the CTS /// @returns true if the CTS was sent, false if sending was not successful - bool send_clear_to_send(std::shared_ptr &session) const; + bool send_clear_to_send(const std::shared_ptr &session) const; /// @brief Sends the "data packet offset" message for the provided session /// @param[in] session The session for which we're sending the DPO /// @returns true if the DPO was sent, false if sending was not successful - bool send_data_packet_offset(std::shared_ptr &session) const; + bool send_data_packet_offset(const std::shared_ptr &session) const; /// @brief Sends the "end of message acknowledgement" message for the provided session /// @param[in] session The session for which we're sending the EOM ACK /// @returns true if the EOM was sent, false if sending was not successful - bool send_end_of_session_acknowledgement(std::shared_ptr &session) const; + bool send_end_of_session_acknowledgement(const std::shared_ptr &session) const; ///@brief Sends data transfer packets for the specified ExtendedTransportProtocolSession. /// @param[in] session The ExtendedTransportProtocolSession for which to send data transfer packets. - void send_data_transfer_packets(std::shared_ptr &session) const; + void send_data_transfer_packets(const std::shared_ptr &session) const; /// @brief Processes a request to send a message over the CAN transport protocol. /// @param[in] source The shared pointer to the source control function. diff --git a/isobus/include/isobus/isobus/can_network_manager.hpp b/isobus/include/isobus/isobus/can_network_manager.hpp index a9d7afc05..d06620585 100644 --- a/isobus/include/isobus/isobus/can_network_manager.hpp +++ b/isobus/include/isobus/isobus/can_network_manager.hpp @@ -65,7 +65,7 @@ namespace isobus /// @param[in] CANPort The CAN channel associated with this control function definition /// @param[in] NAMEFilters A list of filters that describe the identity of the CF based on NAME components /// @returns A shared pointer to a PartneredControlFunction object created with the parameters passed in - std::shared_ptr create_partnered_control_function(std::uint8_t CANPort, const std::vector NAMEFilters); + std::shared_ptr create_partnered_control_function(std::uint8_t CANPort, const std::vector &NAMEFilters); /// @brief Removes an internal control function from the network manager, making it inactive /// @param[in] controlFunction The control function to deactivate @@ -118,7 +118,7 @@ namespace isobus /// @brief Returns an internal control function if the passed-in control function is an internal type /// @param[in] controlFunction The control function to get the internal control function from /// @returns An internal control function casted from the passed in control function - std::shared_ptr get_internal_control_function(std::shared_ptr controlFunction); + std::shared_ptr get_internal_control_function(std::shared_ptr controlFunction) const; /// @brief Returns an estimated busload between 0.0f and 100.0f /// @details This calculates busload over a 1 second window. @@ -282,7 +282,7 @@ namespace isobus /// @brief Processes a message for each internal control function for address claiming /// @param[in] message The message to process - void process_rx_message_for_address_claiming(const CANMessage &message); + void process_rx_message_for_address_claiming(const CANMessage &message) const; /// @brief Processes a CAN message's contribution to the current busload /// @param[in] channelIndex The CAN channel index associated to the message being processed @@ -349,7 +349,7 @@ namespace isobus /// @brief Matches a CAN message to any matching PGN callback, and calls that callback /// @param[in] message A pointer to a CAN message to be processed - void process_can_message_for_global_and_partner_callbacks(const CANMessage &message); + void process_can_message_for_global_and_partner_callbacks(const CANMessage &message) const; /// @brief Processes the internal received message queue void process_rx_messages(); @@ -381,7 +381,7 @@ namespace isobus /// @brief Gets a PGN callback for the global address by index /// @param[in] index The index of the callback to get /// @returns A structure containing the global PGN callback data - ParameterGroupNumberCallbackData get_global_parameter_group_number_callback(std::uint32_t index) const; + ParameterGroupNumberCallbackData get_global_parameter_group_number_callback(std::size_t index) const; static constexpr std::uint32_t BUSLOAD_SAMPLE_WINDOW_MS = 1000; ///< Using a 1s window to average the bus load, otherwise it's very erratic static constexpr std::uint32_t BUSLOAD_UPDATE_FREQUENCY_MS = 100; ///< Bus load bit accumulation happens over a 100ms window diff --git a/isobus/include/isobus/isobus/can_partnered_control_function.hpp b/isobus/include/isobus/isobus/can_partnered_control_function.hpp index cf2ef3acd..6fd41d183 100644 --- a/isobus/include/isobus/isobus/can_partnered_control_function.hpp +++ b/isobus/include/isobus/isobus/can_partnered_control_function.hpp @@ -36,7 +36,7 @@ namespace isobus /// @brief the constructor for a PartneredControlFunction, which is called by the factory function /// @param[in] CANPort The CAN channel associated with this control function definition /// @param[in] NAMEFilters A list of filters that describe the identity of the CF based on NAME components - PartneredControlFunction(std::uint8_t CANPort, const std::vector NAMEFilters); + PartneredControlFunction(std::uint8_t CANPort, const std::vector &NAMEFilters); /// @brief Deleted copy constructor for PartneredControlFunction to avoid slicing PartneredControlFunction(PartneredControlFunction &) = delete; @@ -74,7 +74,7 @@ namespace isobus /// @brief Returns the number of NAME filters with a specific NAME parameter component, like manufacturer code /// @param[in] parameter The NAME parameter to check against /// @returns The number of NAME filters with a specific NAME parameter component - std::size_t get_number_name_filters_with_parameter_type(NAME::NAMEParameters parameter); + std::size_t get_number_name_filters_with_parameter_type(NAME::NAMEParameters parameter) const; /// @brief Returns a NAME filter by index /// @param[in] index The index of the filter to get diff --git a/isobus/include/isobus/isobus/can_transport_protocol.hpp b/isobus/include/isobus/isobus/can_transport_protocol.hpp index ca6152b9b..90f8bc493 100644 --- a/isobus/include/isobus/isobus/can_transport_protocol.hpp +++ b/isobus/include/isobus/isobus/can_transport_protocol.hpp @@ -233,31 +233,31 @@ namespace isobus /// @brief Gracefully closes a session to prepare for a new session /// @param[in] session The session to close /// @param[in] successful Denotes if the session was successful - void close_session(std::shared_ptr &session, bool successful); + void close_session(const std::shared_ptr &session, bool successful); /// @brief Sends the "broadcast announce" message /// @param[in] session The session for which we're sending the BAM /// @returns true if the BAM was sent, false if sending was not successful - bool send_broadcast_announce_message(std::shared_ptr &session) const; + bool send_broadcast_announce_message(const std::shared_ptr &session) const; /// @brief Sends the "request to send" message as part of initiating a transmit /// @param[in] session The session for which we're sending the RTS /// @returns true if the RTS was sent, false if sending was not successful - bool send_request_to_send(std::shared_ptr &session) const; + bool send_request_to_send(const std::shared_ptr &session) const; /// @brief Sends the "clear to send" message /// @param[in] session The session for which we're sending the CTS /// @returns true if the CTS was sent, false if sending was not successful - bool send_clear_to_send(std::shared_ptr &session) const; + bool send_clear_to_send(const std::shared_ptr &session) const; /// @brief Sends the "end of message acknowledgement" message for the provided session /// @param[in] session The session for which we're sending the EOM ACK /// @returns true if the EOM was sent, false if sending was not successful - bool send_end_of_session_acknowledgement(std::shared_ptr &session) const; + bool send_end_of_session_acknowledgement(const std::shared_ptr &session) const; ///@brief Sends data transfer packets for the specified TransportProtocolSession. /// @param[in] session The TransportProtocolSession for which to send data transfer packets. - void send_data_transfer_packets(std::shared_ptr &session); + void send_data_transfer_packets(const std::shared_ptr &session); /// @brief Processes a broadcast announce message. /// @param[in] source The source control function that sent the broadcast announce message. diff --git a/isobus/include/isobus/isobus/isobus_language_command_interface.hpp b/isobus/include/isobus/isobus/isobus_language_command_interface.hpp index 8279f651a..8f3ca2ff2 100644 --- a/isobus/include/isobus/isobus/isobus_language_command_interface.hpp +++ b/isobus/include/isobus/isobus/isobus_language_command_interface.hpp @@ -310,7 +310,7 @@ namespace isobus /// @brief Returns The raw bytes that comprise the current localization data as defined in ISO11783-7 /// @returns The raw bytes that comprise the current localization data - const std::array get_localization_raw_data() const; + std::array get_localization_raw_data() const; /// @brief Parses incoming CAN messages into usable unit and language settings /// @param message The CAN message to parse diff --git a/isobus/include/isobus/isobus/isobus_task_controller_server_options.hpp b/isobus/include/isobus/isobus/isobus_task_controller_server_options.hpp index 5b2568832..bbf5bd3bf 100644 --- a/isobus/include/isobus/isobus/isobus_task_controller_server_options.hpp +++ b/isobus/include/isobus/isobus/isobus_task_controller_server_options.hpp @@ -33,7 +33,7 @@ namespace isobus /// @brief Alters the settings object to indicate you want to support documentation. /// @param[in] supported Whether or not the TC supports documentation. /// @returns An updated settings object. - TaskControllerOptions with_documentation(bool supported = true); + TaskControllerOptions with_documentation(bool supported = true) const; /// @brief Alters the settings object to indicate you want to support tc-geo without position based control. /// @param[in] supported Whether or not the TC supports tc-geo without position based control. diff --git a/isobus/include/isobus/isobus/isobus_time_date_interface.hpp b/isobus/include/isobus/isobus/isobus_time_date_interface.hpp index 7e9e5c5d0..db3e73fb3 100644 --- a/isobus/include/isobus/isobus/isobus_time_date_interface.hpp +++ b/isobus/include/isobus/isobus/isobus_time_date_interface.hpp @@ -66,7 +66,7 @@ namespace isobus /// should be relatively quick as it will be called from the CAN stack's thread, and you don't want to delay the stack's update thread. /// The function should return "true" if the time and date information was successfully populated, and "false" if it was not. /// Note that if it returns false, the request will probably be NACKed, which is not ideal. - TimeDateInterface(std::shared_ptr sourceControlFunction, std::function timeAndDateCallback); + TimeDateInterface(std::shared_ptr sourceControlFunction, const std::function &timeAndDateCallback); /// @brief Destructor for the TimeDateInterface class. ~TimeDateInterface(); diff --git a/isobus/include/isobus/isobus/isobus_virtual_terminal_client.hpp b/isobus/include/isobus/isobus/isobus_virtual_terminal_client.hpp index 36e5b5a2c..cde74b891 100644 --- a/isobus/include/isobus/isobus/isobus_virtual_terminal_client.hpp +++ b/isobus/include/isobus/isobus/isobus_virtual_terminal_client.hpp @@ -1223,7 +1223,7 @@ namespace isobus void set_object_pool(std::uint8_t poolIndex, const std::uint8_t *pool, std::uint32_t size, - std::string version = ""); + const std::string &version = ""); /// @brief Assigns an object pool to the client using a vector. /// @details This is good for small pools or pools where you have all the data in memory. @@ -1232,7 +1232,7 @@ namespace isobus /// @param[in] version An optional version string. The stack will automatically store/load your pool from the VT if this is provided. void set_object_pool(std::uint8_t poolIndex, const std::vector *pool, - std::string version = ""); + const std::string &version = ""); /// @brief Configures an object pool to be automatically scaled to match the target VT server /// @param[in] poolIndex The index of the pool you want to auto-scale @@ -1553,7 +1553,7 @@ namespace isobus /// @param[in] scaleFactor The scale factor to scale the object by /// @param[in] type The type of the object to resize. Must match the object located at `buffer` /// @returns true if the object was resized, otherwise false - bool resize_object(std::uint8_t *buffer, float scaleFactor, VirtualTerminalObjectType type); + bool resize_object(std::uint8_t *buffer, float scaleFactor, VirtualTerminalObjectType type) const; /// @brief Extract from the cache whether a VT does not support a specific function /// @param[in] function The function to check diff --git a/isobus/include/isobus/isobus/isobus_virtual_terminal_server.hpp b/isobus/include/isobus/isobus/isobus_virtual_terminal_server.hpp index d3e0963a7..d33d849e8 100644 --- a/isobus/include/isobus/isobus/isobus_virtual_terminal_server.hpp +++ b/isobus/include/isobus/isobus/isobus_virtual_terminal_server.hpp @@ -479,14 +479,14 @@ namespace isobus /// @param[in] source The source control function to send from /// @param[in] destination The destination control function to send the acknowledgement to /// @returns true if the message was sent, false otherwise - bool send_acknowledgement(AcknowledgementType type, std::uint32_t parameterGroupNumber, std::shared_ptr source, std::shared_ptr destination); + bool send_acknowledgement(AcknowledgementType type, std::uint32_t parameterGroupNumber, std::shared_ptr source, std::shared_ptr destination) const; /// @brief Sends a response to a change active mask command /// @param[in] newMaskObjectID The object ID for the new active mask /// @param[in] errorBitfield An error bitfield /// @param[in] destination The control function to send the message to /// @returns true if the message was sent, otherwise false - bool send_change_active_mask_response(std::uint16_t newMaskObjectID, std::uint8_t errorBitfield, std::shared_ptr destination); + bool send_change_active_mask_response(std::uint16_t newMaskObjectID, std::uint8_t errorBitfield, std::shared_ptr destination) const; /// @brief Sends a response to a change attribute command /// @param[in] objectID The object ID for the target object @@ -494,7 +494,7 @@ namespace isobus /// @param[in] attributeID The attribute ID that was changed /// @param[in] destination The control function to send the message to /// @returns true if the message was sent, otherwise false - bool send_change_attribute_response(std::uint16_t objectID, std::uint8_t errorBitfield, std::uint8_t attributeID, std::shared_ptr destination); + bool send_change_attribute_response(std::uint16_t objectID, std::uint8_t errorBitfield, std::uint8_t attributeID, std::shared_ptr destination) const; /// @brief Sends a response to a change background colour command /// @param[in] objectID The object ID for the object to change @@ -502,7 +502,7 @@ namespace isobus /// @param[in] colour The colour the background was set to /// @param[in] destination The control function to send the message to /// @returns true if the message was sent, otherwise false - bool send_change_background_colour_response(std::uint16_t objectID, std::uint8_t errorBitfield, std::uint8_t colour, std::shared_ptr destination); + bool send_change_background_colour_response(std::uint16_t objectID, std::uint8_t errorBitfield, std::uint8_t colour, std::shared_ptr destination) const; /// @brief Sends a response to a change child location command /// @param[in] parentObjectID The object ID for the parent of the object to move @@ -510,7 +510,7 @@ namespace isobus /// @param[in] errorBitfield An error bitfield /// @param[in] destination The control function to send the message to /// @returns true if the message was sent, otherwise false - bool send_change_child_location_response(std::uint16_t parentObjectID, std::uint16_t objectID, std::uint8_t errorBitfield, std::shared_ptr destination); + bool send_change_child_location_response(std::uint16_t parentObjectID, std::uint16_t objectID, std::uint8_t errorBitfield, std::shared_ptr destination) const; /// @brief Sends a response to a change child position command /// @param[in] parentObjectID The object ID for the parent of the object to move @@ -518,21 +518,21 @@ namespace isobus /// @param[in] errorBitfield An error bitfield /// @param[in] destination The control function to send the message to /// @returns true if the message was sent, otherwise false - bool send_change_child_position_response(std::uint16_t parentObjectID, std::uint16_t objectID, std::uint8_t errorBitfield, std::shared_ptr destination); + bool send_change_child_position_response(std::uint16_t parentObjectID, std::uint16_t objectID, std::uint8_t errorBitfield, std::shared_ptr destination) const; /// @brief Sends a response to a change fill attributes command /// @param[in] objectID The object ID for the object to change /// @param[in] errorBitfield An error bitfield /// @param[in] destination The control function to send the message to /// @returns true if the message was sent, otherwise false - bool send_change_fill_attributes_response(std::uint16_t objectID, std::uint8_t errorBitfield, std::shared_ptr destination); + bool send_change_fill_attributes_response(std::uint16_t objectID, std::uint8_t errorBitfield, std::shared_ptr destination) const; /// @brief Sends a response to a change font attributes command /// @param[in] objectID The object ID for the object to change /// @param[in] errorBitfield An error bitfield /// @param[in] destination The control function to send the message to /// @returns true if the message was sent, otherwise false - bool send_change_font_attributes_response(std::uint16_t objectID, std::uint8_t errorBitfield, std::shared_ptr destination); + bool send_change_font_attributes_response(std::uint16_t objectID, std::uint8_t errorBitfield, std::shared_ptr destination) const; /// @brief Sends a response to a change list item command /// @param[in] objectID The object ID for the object to change @@ -541,7 +541,7 @@ namespace isobus /// @param[in] listIndex The list index to change, numbered 0 to n /// @param[in] destination The control function to send the message to /// @returns true if the message was sent, otherwise false - bool send_change_list_item_response(std::uint16_t objectID, std::uint16_t newObjectID, std::uint8_t errorBitfield, std::uint8_t listIndex, std::shared_ptr destination); + bool send_change_list_item_response(std::uint16_t objectID, std::uint16_t newObjectID, std::uint8_t errorBitfield, std::uint8_t listIndex, std::shared_ptr destination) const; /// @brief Sends a response to a change numeric value command /// @param[in] objectID The object ID for the object whose numeric value was meant to be changed @@ -549,21 +549,21 @@ namespace isobus /// @param[in] value The value that was set by the client /// @param[in] destination The control function to send the message to /// @returns true if the message was sent, otherwise false - bool send_change_numeric_value_response(std::uint16_t objectID, std::uint8_t errorBitfield, std::uint32_t value, std::shared_ptr destination); + bool send_change_numeric_value_response(std::uint16_t objectID, std::uint8_t errorBitfield, std::uint32_t value, std::shared_ptr destination) const; /// @brief Sends a response to a change polygon point command /// @param[in] objectID The object ID of the modified polygon /// @param[in] errorBitfield An error bitfield /// @param[in] destination The control function to send the message to /// @returns true if the message was sent, otherwise false - bool send_change_polygon_point_response(std::uint16_t objectID, std::uint8_t errorBitfield, std::shared_ptr destination); + bool send_change_polygon_point_response(std::uint16_t objectID, std::uint8_t errorBitfield, std::shared_ptr destination) const; /// @brief Sends a response to a change size command /// @param[in] objectID The object ID for the object whose size was meant to be changed /// @param[in] errorBitfield An error bitfield /// @param[in] destination The control function to send the message to /// @returns true if the message was sent, otherwise false - bool send_change_size_response(std::uint16_t objectID, std::uint8_t errorBitfield, std::shared_ptr destination); + bool send_change_size_response(std::uint16_t objectID, std::uint8_t errorBitfield, std::shared_ptr destination) const; /// @brief Sends a response to a change soft key mask command /// @param[in] objectID The object ID of a data mask or alarm mask @@ -571,14 +571,14 @@ namespace isobus /// @param[in] errorBitfield An error bitfield /// @param[in] destination The control function to send the message to /// @returns true if the message was sent, otherwise false - bool send_change_soft_key_mask_response(std::uint16_t objectID, std::uint16_t newObjectID, std::uint8_t errorBitfield, std::shared_ptr destination); + bool send_change_soft_key_mask_response(std::uint16_t objectID, std::uint16_t newObjectID, std::uint8_t errorBitfield, std::shared_ptr destination) const; /// @brief Sends a response to a change string value command /// @param[in] objectID The object ID for the object whose value was meant to be changed /// @param[in] errorBitfield An error bitfield /// @param[in] destination The control function to send the message to /// @returns true if the message was sent, otherwise false - bool send_change_string_value_response(std::uint16_t objectID, std::uint8_t errorBitfield, std::shared_ptr destination); + bool send_change_string_value_response(std::uint16_t objectID, std::uint8_t errorBitfield, std::shared_ptr destination) const; /// @brief Sends a response to a delete version command /// @param[in] errorBitfield An error bitfield to report back to the client diff --git a/isobus/include/isobus/isobus/isobus_virtual_terminal_server_managed_working_set.hpp b/isobus/include/isobus/isobus/isobus_virtual_terminal_server_managed_working_set.hpp index e7f77f776..36ce980c0 100644 --- a/isobus/include/isobus/isobus/isobus_virtual_terminal_server_managed_working_set.hpp +++ b/isobus/include/isobus/isobus/isobus_virtual_terminal_server_managed_working_set.hpp @@ -48,7 +48,7 @@ namespace isobus VirtualTerminalServerManagedWorkingSet(std::shared_ptr associatedControlFunction); /// @brief Destructor - ~VirtualTerminalServerManagedWorkingSet(); + ~VirtualTerminalServerManagedWorkingSet() = default; /// @brief Starts a thread to parse the received object pool files void start_parsing_thread(); diff --git a/isobus/include/isobus/isobus/isobus_virtual_terminal_working_set_base.hpp b/isobus/include/isobus/isobus/isobus_virtual_terminal_working_set_base.hpp index 193c7583a..c9ab24a04 100644 --- a/isobus/include/isobus/isobus/isobus_virtual_terminal_working_set_base.hpp +++ b/isobus/include/isobus/isobus/isobus_virtual_terminal_working_set_base.hpp @@ -47,7 +47,7 @@ namespace isobus /// @brief Appends raw IOP data to the working set's IOP file data /// @param[in] dataToAdd The raw IOP data to add to the working set - void add_iop_raw_data(std::vector &dataToAdd); + void add_iop_raw_data(const std::vector &dataToAdd); /// @brief Returns the number of discrete IOP file chunks that have been added to the object pool /// @returns The number of discrete IOP file chunks that have been added to the object pool diff --git a/isobus/src/can_NAME_filter.cpp b/isobus/src/can_NAME_filter.cpp index ce5c1ee44..c2a9bc5cc 100644 --- a/isobus/src/can_NAME_filter.cpp +++ b/isobus/src/can_NAME_filter.cpp @@ -89,6 +89,7 @@ namespace isobus default: { + // Shouldn't be possible, filter will not match. } break; } diff --git a/isobus/src/can_extended_transport_protocol.cpp b/isobus/src/can_extended_transport_protocol.cpp index 2f6b8177e..baf69122f 100644 --- a/isobus/src/can_extended_transport_protocol.cpp +++ b/isobus/src/can_extended_transport_protocol.cpp @@ -581,7 +581,7 @@ namespace isobus } } - void ExtendedTransportProtocolManager::send_data_transfer_packets(std::shared_ptr &session) const + void ExtendedTransportProtocolManager::send_data_transfer_packets(const std::shared_ptr &session) const { std::array buffer; std::uint8_t framesToSend = session->get_dpo_number_of_packets_remaining(); @@ -771,7 +771,7 @@ namespace isobus CANIdentifier::CANPriority::PriorityLowest7); } - void ExtendedTransportProtocolManager::close_session(std::shared_ptr &session, bool successful) + void ExtendedTransportProtocolManager::close_session(const std::shared_ptr &session, bool successful) { session->complete(successful); auto sessionLocation = std::find(activeSessions.begin(), activeSessions.end(), session); @@ -782,7 +782,7 @@ namespace isobus } } - bool ExtendedTransportProtocolManager::send_request_to_send(std::shared_ptr &session) const + bool ExtendedTransportProtocolManager::send_request_to_send(const std::shared_ptr &session) const { const std::array buffer{ REQUEST_TO_SEND_MULTIPLEXOR, @@ -801,7 +801,7 @@ namespace isobus CANIdentifier::CANPriority::PriorityLowest7); } - bool ExtendedTransportProtocolManager::send_clear_to_send(std::shared_ptr &session) const + bool ExtendedTransportProtocolManager::send_clear_to_send(const std::shared_ptr &session) const { std::uint32_t nextPacketNumber = session->get_last_packet_number() + 1; std::uint8_t packetLimit = session->get_cts_number_of_packet_limit(); @@ -833,7 +833,7 @@ namespace isobus return retVal; } - bool isobus::ExtendedTransportProtocolManager::send_data_packet_offset(std::shared_ptr &session) const + bool isobus::ExtendedTransportProtocolManager::send_data_packet_offset(const std::shared_ptr &session) const { std::uint8_t packetsThisSegment = 0xFF; if (packetsThisSegment > session->get_number_of_remaining_packets()) @@ -877,7 +877,7 @@ namespace isobus return retVal; } - bool ExtendedTransportProtocolManager::send_end_of_session_acknowledgement(std::shared_ptr &session) const + bool ExtendedTransportProtocolManager::send_end_of_session_acknowledgement(const std::shared_ptr &session) const { std::uint32_t messageLength = session->get_message_length(); std::uint32_t parameterGroupNumber = session->get_parameter_group_number(); diff --git a/isobus/src/can_message.cpp b/isobus/src/can_message.cpp index 9e9e0168d..ae1d07a16 100644 --- a/isobus/src/can_message.cpp +++ b/isobus/src/can_message.cpp @@ -161,11 +161,11 @@ namespace isobus if (ByteFormat::LittleEndian == format) { retVal = data.at(index); - retVal |= static_cast(data.at(index + 1)) << 8; + retVal |= static_cast(static_cast(data.at(index + 1)) << 8); } else { - retVal = static_cast(data.at(index)) << 8; + retVal = static_cast(static_cast(data.at(index)) << 8); retVal |= data.at(index + 1); } return retVal; @@ -177,11 +177,11 @@ namespace isobus if (ByteFormat::LittleEndian == format) { retVal = static_cast(data.at(index)); - retVal |= static_cast(data.at(index + 1)) << 8; + retVal |= static_cast(static_cast(data.at(index + 1)) << 8); } else { - retVal = static_cast(data.at(index)) << 8; + retVal = static_cast(static_cast(data.at(index)) << 8); retVal |= static_cast(data.at(index + 1)); } return retVal; @@ -322,7 +322,7 @@ namespace isobus bool isobus::CANMessage::get_bool_at(const std::uint32_t byteIndex, const std::uint8_t bitIndex, const std::uint8_t length) const { assert(length <= 8 - bitIndex && "length must be less than or equal to 8 - bitIndex"); - std::uint8_t mask = ((1 << length) - 1) << bitIndex; + std::uint8_t mask = static_cast(((1 << length) - 1) << bitIndex); return (get_uint8_at(byteIndex) & mask) == mask; } diff --git a/isobus/src/can_network_manager.cpp b/isobus/src/can_network_manager.cpp index a9c156fca..ab2f6c18c 100644 --- a/isobus/src/can_network_manager.cpp +++ b/isobus/src/can_network_manager.cpp @@ -52,7 +52,7 @@ namespace isobus return controlFunction; } - std::shared_ptr CANNetworkManager::create_partnered_control_function(std::uint8_t CANPort, const std::vector NAMEFilters) + std::shared_ptr CANNetworkManager::create_partnered_control_function(std::uint8_t CANPort, const std::vector &NAMEFilters) { auto controlFunction = std::make_shared(CANPort, NAMEFilters); partneredControlFunctions.push_back(controlFunction); @@ -116,7 +116,7 @@ namespace isobus return messageTransmittedEventDispatcher; } - std::shared_ptr CANNetworkManager::get_internal_control_function(std::shared_ptr controlFunction) + std::shared_ptr CANNetworkManager::get_internal_control_function(std::shared_ptr controlFunction) const { std::shared_ptr retVal = nullptr; @@ -207,7 +207,7 @@ namespace isobus retVal = send_can_message_raw(sourceControlFunction->get_can_port(), sourceControlFunction->get_address(), destinationControlFunction->get_address(), parameterGroupNumber, static_cast(priority), dataBuffer, dataLength); } - if ((retVal) && + if (retVal && (nullptr != transmitCompleteCallback)) { // Message was not sent via a protocol, so handle the tx callback now @@ -268,7 +268,7 @@ namespace isobus return send_can_message_raw(portIndex, sourceAddress, destAddress, parameterGroupNumber, priority, data, size); } - ParameterGroupNumberCallbackData CANNetworkManager::get_global_parameter_group_number_callback(std::uint32_t index) const + ParameterGroupNumberCallbackData CANNetworkManager::get_global_parameter_group_number_callback(std::size_t index) const { ParameterGroupNumberCallbackData retVal(0, nullptr, nullptr, nullptr); @@ -637,7 +637,7 @@ namespace isobus } } - void CANNetworkManager::process_rx_message_for_address_claiming(const CANMessage &message) + void CANNetworkManager::process_rx_message_for_address_claiming(const CANMessage &message) const { for (const auto &internalCF : internalControlFunctions) { @@ -962,7 +962,7 @@ namespace isobus } } - void CANNetworkManager::process_can_message_for_global_and_partner_callbacks(const CANMessage &message) + void CANNetworkManager::process_can_message_for_global_and_partner_callbacks(const CANMessage &message) const { std::shared_ptr messageDestination = message.get_destination_control_function(); if ((nullptr == messageDestination) && diff --git a/isobus/src/can_partnered_control_function.cpp b/isobus/src/can_partnered_control_function.cpp index 4888df597..8c6c31439 100644 --- a/isobus/src/can_partnered_control_function.cpp +++ b/isobus/src/can_partnered_control_function.cpp @@ -17,7 +17,7 @@ namespace isobus { - PartneredControlFunction::PartneredControlFunction(std::uint8_t CANPort, const std::vector NAMEFilters) : + PartneredControlFunction::PartneredControlFunction(std::uint8_t CANPort, const std::vector &NAMEFilters) : ControlFunction(NAME(0), NULL_CAN_ADDRESS, CANPort, Type::Partnered), NAMEFilterList(NAMEFilters) { @@ -63,13 +63,13 @@ namespace isobus return retVal; } - std::size_t PartneredControlFunction::get_number_name_filters_with_parameter_type(NAME::NAMEParameters parameter) + std::size_t PartneredControlFunction::get_number_name_filters_with_parameter_type(NAME::NAMEParameters parameter) const { std::size_t retVal = 0; - for (std::size_t i = 0; i < NAMEFilterList.size(); i++) + for (const auto &filter : NAMEFilterList) { - if (parameter == NAMEFilterList[i].get_parameter()) + if (parameter == filter.get_parameter()) { retVal++; } diff --git a/isobus/src/can_transport_protocol.cpp b/isobus/src/can_transport_protocol.cpp index c9d81128a..0071e4008 100644 --- a/isobus/src/can_transport_protocol.cpp +++ b/isobus/src/can_transport_protocol.cpp @@ -657,7 +657,7 @@ namespace isobus } } - void TransportProtocolManager::send_data_transfer_packets(std::shared_ptr &session) + void TransportProtocolManager::send_data_transfer_packets(const std::shared_ptr &session) { std::array buffer; std::uint8_t framesToSend = session->get_cts_number_of_packets_remaining(); @@ -878,7 +878,7 @@ namespace isobus CANIdentifier::CANPriority::PriorityLowest7); } - void TransportProtocolManager::close_session(std::shared_ptr &session, bool successful) + void TransportProtocolManager::close_session(const std::shared_ptr &session, bool successful) { session->complete(successful); @@ -890,7 +890,7 @@ namespace isobus } } - bool TransportProtocolManager::send_broadcast_announce_message(std::shared_ptr &session) const + bool TransportProtocolManager::send_broadcast_announce_message(const std::shared_ptr &session) const { const std::array buffer{ BROADCAST_ANNOUNCE_MESSAGE_MULTIPLEXOR, @@ -909,7 +909,7 @@ namespace isobus CANIdentifier::CANPriority::PriorityLowest7); } - bool TransportProtocolManager::send_request_to_send(std::shared_ptr &session) const + bool TransportProtocolManager::send_request_to_send(const std::shared_ptr &session) const { const std::array buffer{ REQUEST_TO_SEND_MULTIPLEXOR, @@ -928,7 +928,7 @@ namespace isobus CANIdentifier::CANPriority::PriorityLowest7); } - bool TransportProtocolManager::send_clear_to_send(std::shared_ptr &session) const + bool TransportProtocolManager::send_clear_to_send(const std::shared_ptr &session) const { bool retVal = false; @@ -966,7 +966,7 @@ namespace isobus return retVal; } - bool TransportProtocolManager::send_end_of_session_acknowledgement(std::shared_ptr &session) const + bool TransportProtocolManager::send_end_of_session_acknowledgement(const std::shared_ptr &session) const { std::uint32_t messageLength = session->get_message_length(); std::uint32_t parameterGroupNumber = session->get_parameter_group_number(); diff --git a/isobus/src/isobus_device_descriptor_object_pool.cpp b/isobus/src/isobus_device_descriptor_object_pool.cpp index add69b025..6771852af 100644 --- a/isobus/src/isobus_device_descriptor_object_pool.cpp +++ b/isobus/src/isobus_device_descriptor_object_pool.cpp @@ -37,7 +37,7 @@ namespace isobus { bool retVal = true; - for (auto ¤tObject : objectList) + for (const auto ¤tObject : objectList) { if (task_controller_object::ObjectTypes::Device == currentObject->get_object_type()) { @@ -543,9 +543,9 @@ namespace isobus if ((binaryPoolSizeBytes >= expectedSize) && retVal) { std::string deviceElementDesignator; - std::uint16_t parentObject = static_cast(static_cast(binaryPool[9 + numberDesignatorBytes]) | (static_cast(binaryPool[10 + numberDesignatorBytes]) << 8)); - std::uint16_t uniqueID = static_cast(static_cast(binaryPool[3]) | (static_cast(binaryPool[4]) << 8)); - std::uint16_t elementNumber = static_cast(binaryPool[7 + numberDesignatorBytes]) | (static_cast(binaryPool[8 + numberDesignatorBytes]) << 8); + auto parentObject = static_cast(static_cast(binaryPool[9 + numberDesignatorBytes]) | (static_cast(binaryPool[10 + numberDesignatorBytes]) << 8)); + auto uniqueID = static_cast(static_cast(binaryPool[3]) | (static_cast(binaryPool[4]) << 8)); + auto elementNumber = static_cast(binaryPool[7 + numberDesignatorBytes]) | (static_cast(binaryPool[8 + numberDesignatorBytes]) << 8); auto type = static_cast(binaryPool[5]); for (std::uint16_t i = 0; i < numberDesignatorBytes; i++) @@ -602,9 +602,9 @@ namespace isobus if ((binaryPoolSizeBytes >= expectedSize) && retVal) { std::string processDataDesignator; - std::uint16_t DDI = static_cast(static_cast(binaryPool[5]) | (static_cast(binaryPool[6]) << 8)); - std::uint16_t uniqueID = static_cast(static_cast(binaryPool[3]) | (static_cast(binaryPool[4]) << 8)); - std::uint16_t presentationObjectID = static_cast(static_cast(binaryPool[10 + numberDesignatorBytes]) | (static_cast(binaryPool[11 + numberDesignatorBytes]) << 8)); + auto DDI = static_cast(static_cast(binaryPool[5]) | (static_cast(binaryPool[6]) << 8)); + auto uniqueID = static_cast(static_cast(binaryPool[3]) | (static_cast(binaryPool[4]) << 8)); + auto presentationObjectID = static_cast(static_cast(binaryPool[10 + numberDesignatorBytes]) | (static_cast(binaryPool[11 + numberDesignatorBytes]) << 8)); for (std::uint16_t i = 0; i < numberDesignatorBytes; i++) { @@ -652,9 +652,9 @@ namespace isobus (static_cast(binaryPool[8]) << 8) | (static_cast(binaryPool[9]) << 16) | (static_cast(binaryPool[10]) << 24); - std::uint16_t DDI = static_cast(static_cast(binaryPool[5]) | (static_cast(binaryPool[6]) << 8)); - std::uint16_t uniqueID = static_cast(static_cast(binaryPool[3]) | (static_cast(binaryPool[4]) << 8)); - std::uint16_t presentationObjectID = static_cast(static_cast(binaryPool[12 + numberDesignatorBytes]) | (static_cast(binaryPool[13 + numberDesignatorBytes]) << 8)); + auto DDI = static_cast(static_cast(binaryPool[5]) | (static_cast(binaryPool[6]) << 8)); + auto uniqueID = static_cast(static_cast(binaryPool[3]) | (static_cast(binaryPool[4]) << 8)); + auto presentationObjectID = static_cast(static_cast(binaryPool[12 + numberDesignatorBytes]) | (static_cast(binaryPool[13 + numberDesignatorBytes]) << 8)); for (std::uint16_t i = 0; i < numberDesignatorBytes; i++) { @@ -780,7 +780,7 @@ namespace isobus if (resolve_parent_ids_to_objects()) { retVal = true; - for (auto ¤tObject : objectList) + for (const auto ¤tObject : objectList) { auto objectBinary = currentObject->get_binary_object(); @@ -818,14 +818,14 @@ namespace isobus if (resolve_parent_ids_to_objects()) { std::ostringstream xmlOutput; - std::ios initialStreamFormat(NULL); + std::ios initialStreamFormat(nullptr); std::size_t numberOfDevices = 1; std::size_t numberOfElements = 1; initialStreamFormat.copyfmt(xmlOutput); retVal = true; - xmlOutput << "" << std::endl; - xmlOutput << "" << std::endl; + xmlOutput << R"()" << std::endl; + xmlOutput << R"()" << std::endl; // Find the device object, which will be the first object written for (std::size_t i = 0; i < size(); i++) @@ -849,7 +849,7 @@ namespace isobus auto lStructureLabel = rootDevice->get_structure_label(); for (std::uint8_t j = 0; j < 7; j++) { - std::uint8_t structureByte = static_cast(lStructureLabel.at(6 - j)); + auto structureByte = static_cast(lStructureLabel.at(6 - j)); xmlOutput << std::uppercase << std::hex << std::setfill('0') << std::setw(2) << static_cast(structureByte); } @@ -986,7 +986,7 @@ namespace isobus { std::shared_ptr retVal; - for (auto ¤tObject : objectList) + for (const auto ¤tObject : objectList) { if (currentObject->get_object_id() == objectID) { @@ -1062,7 +1062,7 @@ namespace isobus { bool retVal = true; - for (auto ¤tObject : objectList) + for (const auto ¤tObject : objectList) { assert(nullptr != currentObject); switch (currentObject->get_object_type()) @@ -1217,7 +1217,7 @@ namespace isobus if ((0 != uniqueID) && (NULL_OBJECT_ID != uniqueID)) { - for (auto ¤tObject : objectList) + for (const auto ¤tObject : objectList) { if (uniqueID == currentObject->get_object_id()) { diff --git a/isobus/src/isobus_diagnostic_protocol.cpp b/isobus/src/isobus_diagnostic_protocol.cpp index c188a8b98..7d43742cb 100644 --- a/isobus/src/isobus_diagnostic_protocol.cpp +++ b/isobus/src/isobus_diagnostic_protocol.cpp @@ -180,7 +180,7 @@ namespace isobus } else { - if ((0 != activeDTCList.size()) && + if ((!activeDTCList.empty()) && (SystemTiming::time_expired_ms(lastDM1SentTimestamp, DM_MAX_FREQUENCY_MS))) { txFlags.set_flag(static_cast(TransmitFlags::DM1)); diff --git a/isobus/src/isobus_functionalities.cpp b/isobus/src/isobus_functionalities.cpp index 8c62041c9..682379df4 100644 --- a/isobus/src/isobus_functionalities.cpp +++ b/isobus/src/isobus_functionalities.cpp @@ -418,7 +418,16 @@ namespace isobus } else { - retVal = get_functionality_byte_option(Functionalities::TractorImplementManagementServer, get_tim_option_byte_index(option), 1 << get_tim_option_bit_index(option)); + std::uint8_t optionBit = get_tim_option_bit_index(option); + + if (optionBit < 0xFF) + { + retVal = get_functionality_byte_option(Functionalities::TractorImplementManagementServer, get_tim_option_byte_index(option), 1 << get_tim_option_bit_index(option)); + } + else + { + retVal = false; + } } return retVal; } @@ -630,7 +639,7 @@ namespace isobus } else { - serializedValue.at(byteIndex) = (serializedValue.at(byteIndex) & ~(bit)); + serializedValue.at(byteIndex) = (serializedValue.at(byteIndex) & ~bit); } } } @@ -641,7 +650,7 @@ namespace isobus if ((byteIndex < serializedValue.size()) && (bit < std::numeric_limits::max())) { - retVal = (0 != (serializedValue.at(byteIndex) & (bit))); + retVal = (0 != (serializedValue.at(byteIndex) & bit)); } return retVal; } diff --git a/isobus/src/isobus_language_command_interface.cpp b/isobus/src/isobus_language_command_interface.cpp index 2e6b882c0..fa51a1625 100644 --- a/isobus/src/isobus_language_command_interface.cpp +++ b/isobus/src/isobus_language_command_interface.cpp @@ -295,7 +295,7 @@ namespace isobus genericUnitSystem = units; } - const std::array LanguageCommandInterface::get_localization_raw_data() const + std::array LanguageCommandInterface::get_localization_raw_data() const { std::array retVal = { 0 }; diff --git a/isobus/src/isobus_shortcut_button_interface.cpp b/isobus/src/isobus_shortcut_button_interface.cpp index d10608499..7133914d0 100644 --- a/isobus/src/isobus_shortcut_button_interface.cpp +++ b/isobus/src/isobus_shortcut_button_interface.cpp @@ -108,7 +108,7 @@ namespace isobus if (SystemTiming::time_expired_ms(allImplementsStopOperationsSwitchStateTimestamp_ms, TRANSMISSION_RATE_MS)) { // Prune old ISBs - isobusShorcutButtonList.erase(std::remove_if(isobusShorcutButtonList.begin(), isobusShorcutButtonList.end(), [](ISBServerData &isb) { + isobusShorcutButtonList.erase(std::remove_if(isobusShorcutButtonList.begin(), isobusShorcutButtonList.end(), [](const ISBServerData &isb) { return SystemTiming::time_expired_ms(isb.messageReceivedTimestamp_ms, TRANSMISSION_TIMEOUT_MS); }), isobusShorcutButtonList.end()); @@ -155,7 +155,7 @@ namespace isobus if (CAN_DATA_LENGTH == message.get_data_length()) { auto messageNAME = message.get_source_control_function()->get_NAME(); - auto matches_isoname = [messageNAME](ISBServerData &isb) { return isb.ISONAME == messageNAME; }; + auto matches_isoname = [messageNAME](const ISBServerData &isb) { return isb.ISONAME == messageNAME; }; auto ISB = std::find_if(isobusShorcutButtonList.begin(), isobusShorcutButtonList.end(), matches_isoname); auto &messageData = message.get_data(); StopAllImplementOperationsState previousState = get_state(); diff --git a/isobus/src/isobus_task_controller_client.cpp b/isobus/src/isobus_task_controller_client.cpp index 3fea3f6e7..69a5673ea 100644 --- a/isobus/src/isobus_task_controller_client.cpp +++ b/isobus/src/isobus_task_controller_client.cpp @@ -1172,12 +1172,10 @@ namespace isobus if ((newValue != measurementChangeCommand.lastValue) && ((newValue >= (measurementChangeCommand.lastValue + measurementChangeCommand.processDataValue)) || - (newValue <= lowerLimit))) + (newValue <= lowerLimit)) && + (send_value_command(measurementChangeCommand.elementNumber, measurementChangeCommand.ddi, newValue))) { - if (send_value_command(measurementChangeCommand.elementNumber, measurementChangeCommand.ddi, newValue)) - { - measurementChangeCommand.lastValue = newValue; - } + measurementChangeCommand.lastValue = newValue; } } } diff --git a/isobus/src/isobus_task_controller_client_objects.cpp b/isobus/src/isobus_task_controller_client_objects.cpp index 261fbf767..78c42a63f 100644 --- a/isobus/src/isobus_task_controller_client_objects.cpp +++ b/isobus/src/isobus_task_controller_client_objects.cpp @@ -92,14 +92,15 @@ namespace isobus retVal.push_back(static_cast(get_object_id() & 0xFF)); retVal.push_back(static_cast((get_object_id() >> 8) & 0xFF)); retVal.push_back(static_cast(designator.size())); - for (std::size_t i = 0; i < designator.size(); i++) + + for (const auto &character : designator) { - retVal.push_back(designator[i]); + retVal.push_back(character); } retVal.push_back(static_cast(softwareVersion.size())); - for (std::size_t i = 0; i < softwareVersion.size(); i++) + for (const auto &character : softwareVersion) { - retVal.push_back(softwareVersion[i]); + retVal.push_back(character); } retVal.push_back(static_cast(NAME & 0xFF)); retVal.push_back(static_cast((NAME >> 8) & 0xFF)); diff --git a/isobus/src/isobus_task_controller_server_options.cpp b/isobus/src/isobus_task_controller_server_options.cpp index a1c4ca780..9262dbb45 100644 --- a/isobus/src/isobus_task_controller_server_options.cpp +++ b/isobus/src/isobus_task_controller_server_options.cpp @@ -10,7 +10,7 @@ namespace isobus { - TaskControllerOptions TaskControllerOptions::with_documentation(bool supported) + TaskControllerOptions TaskControllerOptions::with_documentation(bool supported) const { TaskControllerOptions copy = *this; copy.optionDocumentation = supported; @@ -62,9 +62,9 @@ namespace isobus std::uint8_t TaskControllerOptions::get_bitfield() const { return static_cast(optionDocumentation) | - static_cast(optionTCGEOWithoutPositionBasedControl << 1) | - static_cast(optionTCGEOWithPositionBasedControl << 2) | - static_cast(optionPeerControlAssignment << 3) | - static_cast(optionImplementSectionControl << 4); + (static_cast(optionTCGEOWithoutPositionBasedControl) << 1) | + (static_cast(optionTCGEOWithPositionBasedControl) << 2) | + (static_cast(optionPeerControlAssignment) << 3) | + (static_cast(optionImplementSectionControl) << 4); } } // namespace isobus diff --git a/isobus/src/isobus_time_date_interface.cpp b/isobus/src/isobus_time_date_interface.cpp index 887701e2a..9fd489a57 100644 --- a/isobus/src/isobus_time_date_interface.cpp +++ b/isobus/src/isobus_time_date_interface.cpp @@ -24,7 +24,7 @@ namespace isobus { - TimeDateInterface::TimeDateInterface(std::shared_ptr sourceControlFunction, std::function timeAndDateCallback) : + TimeDateInterface::TimeDateInterface(std::shared_ptr sourceControlFunction, const std::function &timeAndDateCallback) : myControlFunction(sourceControlFunction), userTimeDateCallback(timeAndDateCallback) { diff --git a/isobus/src/isobus_virtual_terminal_client.cpp b/isobus/src/isobus_virtual_terminal_client.cpp index 43b402f35..23282c0e0 100644 --- a/isobus/src/isobus_virtual_terminal_client.cpp +++ b/isobus/src/isobus_virtual_terminal_client.cpp @@ -1223,7 +1223,7 @@ namespace isobus return activeWorkingSetSoftKeyMaskObjectID; } - void VirtualTerminalClient::set_object_pool(std::uint8_t poolIndex, const std::uint8_t *pool, std::uint32_t size, std::string version) + void VirtualTerminalClient::set_object_pool(std::uint8_t poolIndex, const std::uint8_t *pool, std::uint32_t size, const std::string &version) { if ((nullptr != pool) && (0 != size)) @@ -1252,10 +1252,10 @@ namespace isobus } } - void VirtualTerminalClient::set_object_pool(std::uint8_t poolIndex, const std::vector *pool, std::string version) + void VirtualTerminalClient::set_object_pool(std::uint8_t poolIndex, const std::vector *pool, const std::string &version) { if ((nullptr != pool) && - (0 != pool->size())) + (!pool->empty())) { ObjectPoolDataStruct tempData; @@ -1370,7 +1370,7 @@ namespace isobus set_state(StateMachineState::Disconnected); } - if (0 != objectPools.size()) + if (!objectPools.empty()) { set_state(StateMachineState::SendGetMemory); send_working_set_maintenance(true); @@ -1385,7 +1385,7 @@ namespace isobus { std::uint32_t totalPoolSize = 0; - for (auto &pool : objectPools) + for (const auto &pool : objectPools) { totalPoolSize += pool.objectPoolSize; } @@ -2012,7 +2012,7 @@ namespace isobus { errorCode |= 0x01; } - if ((isAlreadyAssigned) && (false == is_vt_version_supported(VTVersion::Version6))) + if (isAlreadyAssigned && (false == is_vt_version_supported(VTVersion::Version6))) { errorCode |= 0x02; } @@ -2137,9 +2137,9 @@ namespace isobus if (StateMachineState::Disconnected == value) { lastVTStatusTimestamp_ms = 0; - for (std::size_t i = 0; i < objectPools.size(); i++) + for (auto &pool : objectPools) { - objectPools[i].uploaded = false; + pool.uploaded = false; } } } @@ -2149,8 +2149,8 @@ namespace isobus if ((flag <= static_cast(TransmitFlags::NumberFlags)) && (nullptr != parent)) { - TransmitFlags flagToProcess = static_cast(flag); - VirtualTerminalClient *vtClient = static_cast(parent); + auto flagToProcess = static_cast(flag); + auto vtClient = static_cast(parent); bool transmitSuccessful = false; switch (flagToProcess) @@ -2180,9 +2180,9 @@ namespace isobus } break; - case TransmitFlags::NumberFlags: default: { + // Flag not handled } break; } @@ -2196,7 +2196,7 @@ namespace isobus void VirtualTerminalClient::process_rx_message(const CANMessage &message, void *parentPointer) { - VirtualTerminalClient *parentVT = static_cast(parentPointer); + auto parentVT = static_cast(parentPointer); if ((nullptr != parentPointer) && (CAN_DATA_LENGTH <= message.get_data_length()) && ((nullptr == message.get_destination_control_function()) || @@ -2299,7 +2299,7 @@ namespace isobus std::uint16_t xPosition = message.get_uint16_at(1); std::uint16_t yPosition = message.get_uint16_at(3); - std::uint8_t touchState = static_cast(KeyActivationCode::ButtonPressedOrLatched); + auto touchState = static_cast(KeyActivationCode::ButtonPressedOrLatched); std::uint16_t parentMaskObjectID = NULL_OBJECT_ID; std::uint8_t transactionNumber = 0xF; if (parentVT->is_vt_version_supported(VTVersion::Version6)) @@ -4195,7 +4195,7 @@ namespace isobus buffer[6] = (height >> 8); } - bool VirtualTerminalClient::resize_object(std::uint8_t *buffer, float scaleFactor, VirtualTerminalObjectType type) + bool VirtualTerminalClient::resize_object(std::uint8_t *buffer, float scaleFactor, VirtualTerminalObjectType type) const { bool retVal = false; @@ -4330,8 +4330,8 @@ namespace isobus // Reposition the child points for (std::uint_fast8_t i = 0; i < numberOfPoints; i++) { - auto xPosition = static_cast(((static_cast(buffer[14 + (4 * i)]) | (static_cast(buffer[15 + (4 * i)]) << 8))) * scaleFactor); - auto yPosition = static_cast(((static_cast(buffer[16 + (4 * i)]) | (static_cast(buffer[17 + (4 * i)]) << 8))) * scaleFactor); + auto xPosition = static_cast((static_cast(buffer[14 + (4 * i)]) | (static_cast(buffer[15 + (4 * i)]) << 8)) * scaleFactor); + auto yPosition = static_cast((static_cast(buffer[16 + (4 * i)]) | (static_cast(buffer[17 + (4 * i)]) << 8)) * scaleFactor); buffer[14 + (4 * i)] = (xPosition & 0xFF); buffer[15 + (4 * i)] = (xPosition >> 8); buffer[16 + (4 * i)] = (yPosition & 0xFF); @@ -4374,8 +4374,8 @@ namespace isobus // Iterate over the list of children and move them proportionally to the new size for (std::uint_fast8_t i = 0; i < childrenToFollow; i++) { - auto childX = static_cast(((static_cast(buffer[20 + (6 * i)]) | (static_cast(buffer[21 + (6 * i)]) << 8))) * scaleFactor); - auto childY = static_cast(((static_cast(buffer[22 + (6 * i)]) | (static_cast(buffer[23 + (6 * i)]) << 8))) * scaleFactor); + auto childX = static_cast((static_cast(buffer[20 + (6 * i)]) | (static_cast(buffer[21 + (6 * i)]) << 8)) * scaleFactor); + auto childY = static_cast((static_cast(buffer[22 + (6 * i)]) | (static_cast(buffer[23 + (6 * i)]) << 8)) * scaleFactor); buffer[20 + (6 * i)] = (childX & 0xFF); buffer[21 + (6 * i)] = (childX >> 8); buffer[22 + (6 * i)] = (childY & 0xFF); @@ -4391,8 +4391,8 @@ namespace isobus for (std::uint_fast8_t i = 0; i < childrenToFollow; i++) { - auto childX = static_cast(((static_cast(buffer[9 + (6 * i)]) | (static_cast(buffer[10 + (6 * i)]) << 8))) * scaleFactor); - auto childY = static_cast(((static_cast(buffer[11 + (6 * i)]) | (static_cast(buffer[12 + (6 * i)]) << 8))) * scaleFactor); + auto childX = static_cast((static_cast(buffer[9 + (6 * i)]) | (static_cast(buffer[10 + (6 * i)]) << 8)) * scaleFactor); + auto childY = static_cast((static_cast(buffer[11 + (6 * i)]) | (static_cast(buffer[12 + (6 * i)]) << 8)) * scaleFactor); buffer[9 + (6 * i)] = (childX & 0xFF); buffer[10 + (6 * i)] = (childX >> 8); buffer[11 + (6 * i)] = (childY & 0xFF); @@ -4417,8 +4417,8 @@ namespace isobus for (std::uint_fast8_t i = 0; i < childrenToFollow; i++) { - auto childX = static_cast(((static_cast(buffer[8 + (6 * i)]) | (static_cast(buffer[9 + (6 * i)]) << 8))) * scaleFactor); - auto childY = static_cast(((static_cast(buffer[10 + (6 * i)]) | (static_cast(buffer[11 + (6 * i)]) << 8))) * scaleFactor); + auto childX = static_cast((static_cast(buffer[8 + (6 * i)]) | (static_cast(buffer[9 + (6 * i)]) << 8)) * scaleFactor); + auto childY = static_cast((static_cast(buffer[10 + (6 * i)]) | (static_cast(buffer[11 + (6 * i)]) << 8)) * scaleFactor); buffer[8 + (6 * i)] = (childX & 0xFF); buffer[9 + (6 * i)] = (childX >> 8); buffer[10 + (6 * i)] = (childY & 0xFF); @@ -4434,8 +4434,8 @@ namespace isobus for (std::uint_fast8_t i = 0; i < childrenToFollow; i++) { - auto childX = static_cast(((static_cast(buffer[9 + (6 * i)]) | (static_cast(buffer[10 + (6 * i)]) << 8))) * scaleFactor); - auto childY = static_cast(((static_cast(buffer[11 + (6 * i)]) | (static_cast(buffer[12 + (6 * i)]) << 8))) * scaleFactor); + auto childX = static_cast((static_cast(buffer[9 + (6 * i)]) | (static_cast(buffer[10 + (6 * i)]) << 8)) * scaleFactor); + auto childY = static_cast((static_cast(buffer[11 + (6 * i)]) | (static_cast(buffer[12 + (6 * i)]) << 8)) * scaleFactor); buffer[9 + (6 * i)] = (childX & 0xFF); buffer[10 + (6 * i)] = (childX >> 8); buffer[11 + (6 * i)] = (childY & 0xFF); diff --git a/isobus/src/isobus_virtual_terminal_server.cpp b/isobus/src/isobus_virtual_terminal_server.cpp index 131c081eb..90200f0c1 100644 --- a/isobus/src/isobus_virtual_terminal_server.cpp +++ b/isobus/src/isobus_virtual_terminal_server.cpp @@ -107,7 +107,7 @@ namespace isobus // This is the static callback for the instance. // See if we need to set up a new managed working set. - for (auto &cf : managedWorkingSetList) + for (const auto &cf : managedWorkingSetList) { if (cf->get_control_function() == message.get_source_control_function()) { @@ -712,7 +712,7 @@ namespace isobus case Function::HideShowObjectCommand: { - std::uint16_t objectId = static_cast(static_cast(data[1]) | (static_cast(data[2]) << 8)); + auto objectId = static_cast(static_cast(data[1]) | (static_cast(data[2]) << 8)); auto targetObject = cf->get_object_by_id(objectId); if ((nullptr != targetObject) && (VirtualTerminalObjectType::Container == targetObject->get_object_type())) @@ -742,7 +742,7 @@ namespace isobus case Function::EnableDisableObjectCommand: { - std::uint16_t objectId = static_cast(static_cast(data[1]) | (static_cast(data[2]) << 8)); + auto objectId = static_cast(static_cast(data[1]) | (static_cast(data[2]) << 8)); auto lTargetObject = cf->get_object_by_id(objectId); if (nullptr != lTargetObject) @@ -753,7 +753,7 @@ namespace isobus { case VirtualTerminalObjectType::InputBoolean: { - std::static_pointer_cast(lTargetObject)->set_enabled((0 != data[3])); + std::static_pointer_cast(lTargetObject)->set_enabled(0 != data[3]); parentServer->send_enable_disable_object_response(objectId, 0, (0 != data[3]), cf->get_control_function()); parentServer->onRepaintEventDispatcher.call(cf); } @@ -822,8 +822,8 @@ namespace isobus if (nullptr != lTargetObject) { - std::int8_t xRelativeChange = static_cast(static_cast(data[5]) - 127); - std::int8_t yRelativeChange = static_cast(static_cast(data[6]) - 127); + auto xRelativeChange = static_cast(static_cast(data[5]) - 127); + auto yRelativeChange = static_cast(static_cast(data[6]) - 127); bool anyObjectMatched = parentObject->offset_all_children_with_id(objectID, xRelativeChange, yRelativeChange); parentServer->onRepaintEventDispatcher.call(cf); @@ -892,8 +892,8 @@ namespace isobus case Function::ChangeStringValueCommand: { - std::uint16_t objectIdToChange = static_cast(static_cast(data[1]) | (static_cast(data[2]) << 8)); - std::uint16_t numberOfBytesInString = static_cast(static_cast(data[3]) | (static_cast(data[4]) << 8)); + auto objectIdToChange = static_cast(static_cast(data[1]) | (static_cast(data[2]) << 8)); + auto numberOfBytesInString = static_cast(static_cast(data[3]) | (static_cast(data[4]) << 8)); auto stringObject = cf->get_object_by_id(objectIdToChange); if (message.get_data_length() >= static_cast(numberOfBytesInString + 5)) @@ -984,8 +984,8 @@ namespace isobus case Function::ChangeFillAttributesCommand: { - std::uint16_t objectIdToChange = static_cast(static_cast(data[1]) | (static_cast(data[2]) << 8)); - std::uint16_t fillPatternID = static_cast(static_cast(data[5]) | (static_cast(data[6]) << 8)); + auto objectIdToChange = static_cast(static_cast(data[1]) | (static_cast(data[2]) << 8)); + auto fillPatternID = static_cast(static_cast(data[5]) | (static_cast(data[6]) << 8)); auto object = cf->get_object_by_id(objectIdToChange); auto fillPatternObject = cf->get_object_by_id(fillPatternID); @@ -1730,7 +1730,7 @@ namespace isobus } } - bool VirtualTerminalServer::send_acknowledgement(AcknowledgementType type, std::uint32_t parameterGroupNumber, std::shared_ptr source, std::shared_ptr destination) + bool VirtualTerminalServer::send_acknowledgement(AcknowledgementType type, std::uint32_t parameterGroupNumber, std::shared_ptr source, std::shared_ptr destination) const { bool retVal = false; @@ -1757,7 +1757,7 @@ namespace isobus return retVal; } - bool VirtualTerminalServer::send_change_active_mask_response(std::uint16_t newMaskObjectID, std::uint8_t errorBitfield, std::shared_ptr destination) + bool VirtualTerminalServer::send_change_active_mask_response(std::uint16_t newMaskObjectID, std::uint8_t errorBitfield, std::shared_ptr destination) const { bool retVal = false; @@ -1784,7 +1784,7 @@ namespace isobus return retVal; } - bool VirtualTerminalServer::send_change_attribute_response(std::uint16_t objectID, std::uint8_t errorBitfield, std::uint8_t attributeID, std::shared_ptr destination) + bool VirtualTerminalServer::send_change_attribute_response(std::uint16_t objectID, std::uint8_t errorBitfield, std::uint8_t attributeID, std::shared_ptr destination) const { bool retVal = false; @@ -1811,7 +1811,7 @@ namespace isobus return retVal; } - bool VirtualTerminalServer::send_change_background_colour_response(std::uint16_t objectID, std::uint8_t errorBitfield, std::uint8_t colour, std::shared_ptr destination) + bool VirtualTerminalServer::send_change_background_colour_response(std::uint16_t objectID, std::uint8_t errorBitfield, std::uint8_t colour, std::shared_ptr destination) const { bool retVal = false; @@ -1838,7 +1838,7 @@ namespace isobus return retVal; } - bool VirtualTerminalServer::send_change_child_location_response(std::uint16_t parentObjectID, std::uint16_t objectID, std::uint8_t errorBitfield, std::shared_ptr destination) + bool VirtualTerminalServer::send_change_child_location_response(std::uint16_t parentObjectID, std::uint16_t objectID, std::uint8_t errorBitfield, std::shared_ptr destination) const { bool retVal = false; @@ -1865,7 +1865,7 @@ namespace isobus return retVal; } - bool VirtualTerminalServer::send_change_child_position_response(std::uint16_t parentObjectID, std::uint16_t objectID, std::uint8_t errorBitfield, std::shared_ptr destination) + bool VirtualTerminalServer::send_change_child_position_response(std::uint16_t parentObjectID, std::uint16_t objectID, std::uint8_t errorBitfield, std::shared_ptr destination) const { bool retVal = false; @@ -1892,7 +1892,7 @@ namespace isobus return retVal; } - bool VirtualTerminalServer::send_change_fill_attributes_response(std::uint16_t objectID, std::uint8_t errorBitfield, std::shared_ptr destination) + bool VirtualTerminalServer::send_change_fill_attributes_response(std::uint16_t objectID, std::uint8_t errorBitfield, std::shared_ptr destination) const { bool retVal = false; @@ -1918,7 +1918,7 @@ namespace isobus return retVal; } - bool VirtualTerminalServer::send_change_font_attributes_response(std::uint16_t objectID, std::uint8_t errorBitfield, std::shared_ptr destination) + bool VirtualTerminalServer::send_change_font_attributes_response(std::uint16_t objectID, std::uint8_t errorBitfield, std::shared_ptr destination) const { bool retVal = false; @@ -1944,7 +1944,7 @@ namespace isobus return retVal; } - bool VirtualTerminalServer::send_change_list_item_response(std::uint16_t objectID, std::uint16_t newObjectID, std::uint8_t errorBitfield, std::uint8_t listIndex, std::shared_ptr destination) + bool VirtualTerminalServer::send_change_list_item_response(std::uint16_t objectID, std::uint16_t newObjectID, std::uint8_t errorBitfield, std::uint8_t listIndex, std::shared_ptr destination) const { bool retVal = false; @@ -2164,7 +2164,7 @@ namespace isobus } } - bool VirtualTerminalServer::send_change_numeric_value_response(std::uint16_t objectID, std::uint8_t errorBitfield, std::uint32_t value, std::shared_ptr destination) + bool VirtualTerminalServer::send_change_numeric_value_response(std::uint16_t objectID, std::uint8_t errorBitfield, std::uint32_t value, std::shared_ptr destination) const { bool retVal = false; @@ -2191,7 +2191,7 @@ namespace isobus return retVal; } - bool VirtualTerminalServer::send_change_polygon_point_response(std::uint16_t objectID, std::uint8_t errorBitfield, std::shared_ptr destination) + bool VirtualTerminalServer::send_change_polygon_point_response(std::uint16_t objectID, std::uint8_t errorBitfield, std::shared_ptr destination) const { bool retVal = false; @@ -2218,7 +2218,7 @@ namespace isobus return retVal; } - bool VirtualTerminalServer::send_change_size_response(std::uint16_t objectID, std::uint8_t errorBitfield, std::shared_ptr destination) + bool VirtualTerminalServer::send_change_size_response(std::uint16_t objectID, std::uint8_t errorBitfield, std::shared_ptr destination) const { bool retVal = false; @@ -2245,7 +2245,7 @@ namespace isobus return retVal; } - bool VirtualTerminalServer::send_change_soft_key_mask_response(std::uint16_t objectID, std::uint16_t newObjectID, std::uint8_t errorBitfield, std::shared_ptr destination) + bool VirtualTerminalServer::send_change_soft_key_mask_response(std::uint16_t objectID, std::uint16_t newObjectID, std::uint8_t errorBitfield, std::shared_ptr destination) const { bool retVal = false; @@ -2272,7 +2272,7 @@ namespace isobus return retVal; } - bool VirtualTerminalServer::send_change_string_value_response(std::uint16_t objectID, std::uint8_t errorBitfield, std::shared_ptr destination) + bool VirtualTerminalServer::send_change_string_value_response(std::uint16_t objectID, std::uint8_t errorBitfield, std::shared_ptr destination) const { bool retVal = false; diff --git a/isobus/src/isobus_virtual_terminal_server_managed_working_set.cpp b/isobus/src/isobus_virtual_terminal_server_managed_working_set.cpp index 36536731b..8fbcf0e8b 100644 --- a/isobus/src/isobus_virtual_terminal_server_managed_working_set.cpp +++ b/isobus/src/isobus_virtual_terminal_server_managed_working_set.cpp @@ -33,10 +33,6 @@ namespace isobus } } - VirtualTerminalServerManagedWorkingSet::~VirtualTerminalServerManagedWorkingSet() - { - } - void VirtualTerminalServerManagedWorkingSet::start_parsing_thread() { if (nullptr == objectPoolProcessingThread) @@ -57,7 +53,7 @@ namespace isobus bool VirtualTerminalServerManagedWorkingSet::get_any_object_pools() const { - return (0 != iopFilesRawData.size()); + return (!iopFilesRawData.empty()); } VirtualTerminalServerManagedWorkingSet::ObjectPoolProcessingThreadState VirtualTerminalServerManagedWorkingSet::get_object_pool_processing_state() @@ -139,7 +135,7 @@ namespace isobus void VirtualTerminalServerManagedWorkingSet::worker_thread_function() { - if (0 != iopFilesRawData.size()) + if (!iopFilesRawData.empty()) { bool lSuccess = true; diff --git a/isobus/src/isobus_virtual_terminal_working_set_base.cpp b/isobus/src/isobus_virtual_terminal_working_set_base.cpp index cb1e931a7..fa607ae42 100644 --- a/isobus/src/isobus_virtual_terminal_working_set_base.cpp +++ b/isobus/src/isobus_virtual_terminal_working_set_base.cpp @@ -22,7 +22,7 @@ namespace isobus return faultingObjectID; } - void VirtualTerminalWorkingSetBase::add_iop_raw_data(std::vector &dataToAdd) + void VirtualTerminalWorkingSetBase::add_iop_raw_data(const std::vector &dataToAdd) { iopFilesRawData.push_back(dataToAdd); } @@ -72,7 +72,7 @@ namespace isobus if (iopLength > 3) { // We at least have object ID and type - std::uint16_t decodedID = (static_cast(iopData[0]) | (static_cast(iopData[1]) << 8)); + auto decodedID = (static_cast(iopData[0]) | (static_cast(iopData[1]) << 8)); VirtualTerminalObjectType decodedType = static_cast(iopData[2]); switch (decodedType) @@ -107,8 +107,8 @@ namespace isobus for (std::uint_fast8_t i = 0; i < childrenToFollow; i++) { std::uint16_t childID = (static_cast(iopData[0]) | (static_cast(iopData[1]) << 8)); - std::int16_t childX = static_cast(static_cast(iopData[2]) | (static_cast(iopData[3]) << 8)); - std::int16_t childY = static_cast(static_cast(iopData[4]) | (static_cast(iopData[5]) << 8)); + auto childX = static_cast(static_cast(iopData[2]) | (static_cast(iopData[3]) << 8)); + auto childY = static_cast(static_cast(iopData[4]) | (static_cast(iopData[5]) << 8)); tempObject->add_child(childID, childX, childY); iopLength -= 6; iopData += 6; @@ -449,8 +449,8 @@ namespace isobus for (std::uint_fast8_t i = 0; i < childrenToFollow; i++) { std::uint16_t childID = (static_cast(iopData[0]) | (static_cast(iopData[1]) << 8)); - std::int16_t childX = static_cast(static_cast(iopData[2]) | (static_cast(iopData[3]) << 8)); - std::int16_t childY = static_cast(static_cast(iopData[4]) | (static_cast(iopData[5]) << 8)); + auto childX = static_cast(static_cast(iopData[2]) | (static_cast(iopData[3]) << 8)); + auto childY = static_cast(static_cast(iopData[4]) | (static_cast(iopData[5]) << 8)); tempObject->add_child(childID, childX, childY); iopLength -= 6; iopData += 6; @@ -847,8 +847,8 @@ namespace isobus for (std::uint_fast8_t i = 0; i < childrenToFollow; i++) { std::uint16_t childID = (static_cast(iopData[0]) | (static_cast(iopData[1]) << 8)); - std::int16_t childX = static_cast(static_cast(iopData[2]) | (static_cast(iopData[3]) << 8)); - std::int16_t childY = static_cast(static_cast(iopData[4]) | (static_cast(iopData[5]) << 8)); + auto childX = static_cast(static_cast(iopData[2]) | (static_cast(iopData[3]) << 8)); + auto childY = static_cast(static_cast(iopData[4]) | (static_cast(iopData[5]) << 8)); tempObject->add_child(childID, childX, childY); iopLength -= 6; iopData += 6; diff --git a/test/core_network_management_tests.cpp b/test/core_network_management_tests.cpp index 8c1d73cb9..aeec81432 100644 --- a/test/core_network_management_tests.cpp +++ b/test/core_network_management_tests.cpp @@ -229,6 +229,9 @@ TEST(CORE_TESTS, SimilarControlFunctions) const std::vector nameFilters = { filterFuelSystem }; auto TestPartner = isobus::CANNetworkManager::CANNetwork.create_partnered_control_function(0, nameFilters); + // Quick test to make sure partner is working + EXPECT_EQ(1, TestPartner->get_number_name_filters_with_parameter_type(isobus::NAME::NAMEParameters::FunctionCode)); + // Request the address claim PGN CANNetworkManager::CANNetwork.process_receive_can_message_frame(test_helpers::create_message_frame_pgn_request( 0xEE00, // Address Claim PGN