diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2017-03-14 00:13:57 +0100 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2017-03-16 17:15:55 +0100 |
commit | d1282ada6335171914a23c328c8a17c809557e62 (patch) | |
tree | 7671bd00a72c1df319a033e136629dac912c7495 /src | |
parent | 990b25bf850f797f499a326713cad1f7076ab8d1 (diff) |
Improve Doxygen comments and formating.
Change-Id: Ia39e78aca00a49c7cee5e42d26ba1ef2b49d3709
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'src')
-rw-r--r-- | src/can/can-bus-dev.cpp | 11 | ||||
-rw-r--r-- | src/can/can-bus.cpp | 39 | ||||
-rw-r--r-- | src/can/can-bus.hpp | 3 | ||||
-rw-r--r-- | src/can/can-command.hpp | 11 | ||||
-rw-r--r-- | src/can/can-decoder.cpp | 120 | ||||
-rw-r--r-- | src/can/can-decoder.hpp | 153 | ||||
-rw-r--r-- | src/can/can-message-set.hpp | 20 | ||||
-rw-r--r-- | src/can/can-message.cpp | 5 | ||||
-rw-r--r-- | src/configuration.cpp | 10 | ||||
-rw-r--r-- | src/low-can-binding.cpp | 6 | ||||
-rw-r--r-- | src/utils/openxc-utils.cpp | 82 | ||||
-rw-r--r-- | src/utils/openxc-utils.hpp | 89 |
12 files changed, 281 insertions, 268 deletions
diff --git a/src/can/can-bus-dev.cpp b/src/can/can-bus-dev.cpp index a574b42..dd2f51f 100644 --- a/src/can/can-bus-dev.cpp +++ b/src/can/can-bus-dev.cpp @@ -204,9 +204,14 @@ int can_bus_dev_t::send(can_message_t& can_msg) return 0; } -/// @brief Send a can message from a can_message_t object. -/// @param[in] can bus used to send the message -/// @param[in] can_msg the can message object to send +/// @brief Static method used to send diagnostic CAN message +/// that follow isotp SendShimsMessage signature. This method is launched +/// from diagnostic manager's' same name method. It will use the diagnostic +/// manager configured CAN bus device to send the CAN message. +/// +/// @param[in] arbitration_id - CAN arbitration id. +/// @param[in] data - CAN message payload to send +/// @param[in] size - size of the data to send bool can_bus_dev_t::shims_send(const uint32_t arbitration_id, const uint8_t* data, const uint8_t size) { ssize_t nbytes; diff --git a/src/can/can-bus.cpp b/src/can/can-bus.cpp index 6483fd9..09fce46 100644 --- a/src/can/can-bus.cpp +++ b/src/can/can-bus.cpp @@ -50,7 +50,18 @@ can_bus_t::can_bus_t(int conf_file) { } - +/** + * @brief Will make the decoding operation on a classic CAN message. It will not + * handle CAN commands nor diagnostic messages that have their own method to get + * this happens. + * + * It will add to the vehicle_message queue the decoded message and tell the event push + * thread to process it. + * + * @param[in] can_message - a single CAN message from the CAN socket read, to be decode. + * + * @return How many signals has been decoded. + */ int can_bus_t::process_can_signals(can_message_t& can_message) { int processed_signals = 0; @@ -92,13 +103,23 @@ int can_bus_t::process_can_signals(can_message_t& can_message) return processed_signals; } +/** + * @brief Will make the decoding operation on a diagnostic CAN message.It will add to + * the vehicle_message queue the decoded message and tell the event push thread to process it. + * + * @param[in] entry - an active_diagnostic_request_t object that made the request + * about that diagnostic CAN message. + * @param[in] can_message - a single CAN message from the CAN socket read, to be decode. + * + * @return How many signals has been decoded. + */ int can_bus_t::process_diagnostic_signals(active_diagnostic_request_t* entry, const can_message_t& can_message) { int processed_signals = 0; openxc_VehicleMessage vehicle_message; diagnostic_manager_t& manager = configuration_t::instance().get_diagnostic_manager(); - + std::lock_guard<std::mutex> subscribed_signals_lock(get_subscribed_signals_mutex()); std::map<std::string, struct afb_event>& s = get_subscribed_signals(); @@ -141,7 +162,7 @@ int can_bus_t::process_diagnostic_signals(active_diagnostic_request_t* entry, co * corresponding decoding function if there is one assigned for that signal. If not, it will be the default * noopDecoder function that will operate on it. * -* Depending on the nature of message, if id match a diagnostic request corresponding id for a response +* Depending on the nature of message, if id match a diagnostic request corresponding id for a response * then decoding a diagnostic message else use classic CAN signals decoding functions. * * TODO: make diagnostic messages parsing optionnal. @@ -195,9 +216,9 @@ void can_bus_t::can_event_push() } /** - * @brief Will initialize threads that will decode - * and push subscribed events. - */ +* @brief Will initialize threads that will decode +* and push subscribed events. +*/ void can_bus_t::start_threads() { is_decoding_ = true; @@ -224,7 +245,11 @@ void can_bus_t::stop_threads() /** * @brief Will initialize can_bus_dev_t objects after reading -* the configuration file passed in the constructor. +* the configuration file passed in the constructor. All CAN buses +* Initialized here will be added to a vector holding them for +* inventory and later access. +* +* That will initialize CAN socket reading too using a new thread. */ int can_bus_t::init_can_dev() { diff --git a/src/can/can-bus.hpp b/src/can/can-bus.hpp index b4f1a3e..97b683d 100644 --- a/src/can/can-bus.hpp +++ b/src/can/can-bus.hpp @@ -66,7 +66,7 @@ private: std::condition_variable new_decoded_can_message_; /// < condition_variable use to wait until there is a new vehicle message to read from the queue vehicle_message_q_ std::mutex decoded_can_message_mutex_; /// < mutex protecting the vehicle_message_q_ queue. - std::queue <openxc_VehicleMessage> vehicle_message_q_; /// < queue that'll store openxc_VehicleMessage to pushed + std::queue <openxc_VehicleMessage> vehicle_message_q_; /// < queue that'll store openxc_VehicleMessage to pushed std::vector<std::shared_ptr<can_bus_dev_t>> can_devices_; /// < Can device map containing all can_bus_dev_t objects initialized during init_can_dev function @@ -93,4 +93,3 @@ public: const std::vector<std::shared_ptr<can_bus_dev_t>>& get_can_devices() const; }; - diff --git a/src/can/can-command.hpp b/src/can/can-command.hpp index 062cbd7..8324d32 100644 --- a/src/can/can-command.hpp +++ b/src/can/can-command.hpp @@ -53,14 +53,3 @@ typedef struct { CommandHandler handler; /*!< handler - An function to process the received command's data and perform some * action.*/ } CanCommand; - -/* Public: Return an array of all OpenXC CAN commands enabled in the active - * configuration that can write back to CAN with a custom handler. - * - * Commands not defined here are handled using a 1-1 mapping from the signals - * list. - */ -CanCommand* getCommands(); - -/* Public: Return the length of the array returned by getCommandCount(). */ -int getCommandCount();
\ No newline at end of file diff --git a/src/can/can-decoder.cpp b/src/can/can-decoder.cpp index a5e4d8e..ec31e36 100644 --- a/src/can/can-decoder.cpp +++ b/src/can/can-decoder.cpp @@ -19,6 +19,15 @@ #include "canutil/read.h" #include "../utils/openxc-utils.hpp" +/* Public: Parse the signal's bitfield from the given data and return the raw +* value. +* +* @param[in] signal - The signal to parse from the data. +* @param[in] message - can_message_t to parse +* +* @return Returns the raw value of the signal parsed as a bitfield from the given byte +* array. +*/ float decoder_t::parseSignalBitfield(can_signal_t& signal, const can_message_t& message) { return bitfield_parse_float(message.get_data(), CAN_MESSAGE_SIZE, @@ -26,6 +35,21 @@ float decoder_t::parseSignalBitfield(can_signal_t& signal, const can_message_t& signal.get_offset()); } +/* Public: Wrap a raw CAN signal value in a DynamicField without modification. +* +* This is an implementation of the SignalDecoder type signature, and can be +* used directly in the can_signal_t.decoder field. +* +* @param[in] signal - The details of the signal that contains the state mapping. +* @param[in] signals - The list of all signals +* @param[in] value - The numerical value that will be wrapped in a DynamicField. +* @param[out]send - An output argument that will be set to false if the value should +* not be sent for any reason. +* +* @return Returns a DynamicField with the original, unmodified raw CAN signal value as +* its numeric value. The 'send' argument will not be modified as this decoder +* always succeeds. +*/ openxc_DynamicField decoder_t::noopDecoder(can_signal_t& signal, const std::vector<can_signal_t>& signals, float value, bool* send) { @@ -33,7 +57,21 @@ openxc_DynamicField decoder_t::noopDecoder(can_signal_t& signal, return decoded_value; } - +/* Public: Coerces a numerical value to a boolean. +* +* This is an implementation of the SignalDecoder type signature, and can be +* used directly in the can_signal_t.decoder field. +* +* @param[in] signal - The details of the signal that contains the state mapping. +* @param[in] signals - The list of all signals +* @param[in] value - The numerical value that will be converted to a boolean. +* @param[out] send - An output argument that will be set to false if the value should +* not be sent for any reason. +* +* @return Returns a DynamicField with a boolean value of false if the raw signal value +* is 0.0, otherwise true. The 'send' argument will not be modified as this +* decoder always succeeds. +*/ openxc_DynamicField decoder_t::booleanDecoder(can_signal_t& signal, const std::vector<can_signal_t>& signals, float value, bool* send) { @@ -41,18 +79,48 @@ openxc_DynamicField decoder_t::booleanDecoder(can_signal_t& signal, return decoded_value; } - +/* Public: Update the metadata for a signal and the newly received value. +* +* This is an implementation of the SignalDecoder type signature, and can be +* used directly in the can_signal_t.decoder field. +* +* This function always flips 'send' to false. +* +* @param[in] signal - The details of the signal that contains the state mapping. +* @param[in] signals - The list of all signals. +* @param[in] value - The numerical value that will be converted to a boolean. +* @param[out] send - This output argument will always be set to false, so the caller will +* know not to publish this value to the pipeline. +* +* @return Return value is undefined. +*/ openxc_DynamicField decoder_t::ignoreDecoder(can_signal_t& signal, const std::vector<can_signal_t>& signals, float value, bool* send) { if(send) *send = false; - - openxc_DynamicField decoded_value = {0, openxc_DynamicField_Type_BOOL, 0, "", 0, 0, 0, 0}; - + + openxc_DynamicField decoded_value; + return decoded_value; } +/* Public: Find and return the corresponding string state for a CAN signal's +* raw integer value. +* +* This is an implementation of the SignalDecoder type signature, and can be +* used directly in the can_signal_t.decoder field. +* +* @param[in] signal - The details of the signal that contains the state mapping. +* @param[in] signals - The list of all signals. +* @param[in] value - The numerical value that should map to a state. +* @param[out] send - An output argument that will be set to false if the value should +* not be sent for any reason. +* +* @return Returns a DynamicField with a string value if a matching state is found in +* the signal. If an equivalent isn't found, send is sent to false and the +* return value is undefined. +*/ openxc_DynamicField decoder_t::stateDecoder(can_signal_t& signal, const std::vector<can_signal_t>& signals, float value, bool* send) { @@ -66,6 +134,20 @@ openxc_DynamicField decoder_t::stateDecoder(can_signal_t& signal, return decoded_value; } + +/* Public: Parse a signal from a CAN message, apply any required transforations +* to get a human readable value and public the result to the pipeline. +* +* If the can_signal_t has a non-NULL 'decoder' field, the raw CAN signal value +* will be passed to the decoder before publishing. +* +* @param[in] signal - The details of the signal to decode and forward. +* @param[in] message - The received CAN message that should contain this signal. +* @param[in] signals - an array of all active signals. +* +* The decoder returns an openxc_DynamicField, which may contain a number, +* string or boolean. +*/ openxc_DynamicField decoder_t::translateSignal(can_signal_t& signal, can_message_t& message, const std::vector<can_signal_t>& signals) { @@ -89,6 +171,21 @@ openxc_DynamicField decoder_t::translateSignal(can_signal_t& signal, can_message return decoded_value; } +/* Public: Parse a signal from a CAN message and apply any required +* transforations to get a human readable value. +* +* If the can_signal_t has a non-NULL 'decoder' field, the raw CAN signal value +* will be passed to the decoder before returning. +* +* @param[in] signal - The details of the signal to decode and forward. +* @param[in] value - The numerical value that will be converted to a boolean. +* @param[in] signals - an array of all active signals. +* @param[out] send - An output parameter that will be flipped to false if the value could +* not be decoded. +* +* @return The decoder returns an openxc_DynamicField, which may contain a number, +* string or boolean. If 'send' is false, the return value is undefined. +*/ openxc_DynamicField decoder_t::decodeSignal( can_signal_t& signal, float value, const std::vector<can_signal_t>& signals, bool* send) { @@ -99,6 +196,19 @@ openxc_DynamicField decoder_t::decodeSignal( can_signal_t& signal, return decoded_value; } +/* Public: Decode a transformed, human readable value from an raw CAN signal +* already parsed from a CAN message. +* +* This is the same as decodeSignal but you must parse the bitfield value of the signal from the CAN +* message yourself. This is useful if you need that raw value for something +* else. +* +* @param[in] signal - The details of the signal to decode and forward. +* @param[in] value - The numerical value that will be converted to a boolean. +* @param[in] signals - an array of all active signals. +* @param[out] send - An output parameter that will be flipped to false if the value could +* not be decoded. +*/ openxc_DynamicField decoder_t::decodeSignal( can_signal_t& signal, const can_message_t& message, const std::vector<can_signal_t>& signals, bool* send) { diff --git a/src/can/can-decoder.hpp b/src/can/can-decoder.hpp index 63d91d4..326a2b7 100644 --- a/src/can/can-decoder.hpp +++ b/src/can/can-decoder.hpp @@ -21,139 +21,24 @@ class decoder_t { - public: - /* Public: Parse the signal's bitfield from the given data and return the raw - * value. - * - * signal - The signal to parse from the data. - * data - The data to parse the signal from. - * length - The length of the data array. - * - * Returns the raw value of the signal parsed as a bitfield from the given byte - * array. - */ - static float parseSignalBitfield(can_signal_t& signal, const can_message_t& message); - - /* Public: Find and return the corresponding string state for a CAN signal's - * raw integer value. - * - * This is an implementation of the SignalDecoder type signature, and can be - * used directly in the can_signal_t.decoder field. - * - * signal - The details of the signal that contains the state mapping. - * signals - The list of all signals. - * signalCount - the length of the signals array. - * value - The numerical value that should map to a state. - * send - An output argument that will be set to false if the value should - * not be sent for any reason. - * - * Returns a DynamicField with a string value if a matching state is found in - * the signal. If an equivalent isn't found, send is sent to false and the - * return value is undefined. - */ - static openxc_DynamicField stateDecoder(can_signal_t& signal, const std::vector<can_signal_t>& signals, - float value, bool* send); - - /* Public: Coerces a numerical value to a boolean. - * - * This is an implementation of the SignalDecoder type signature, and can be - * used directly in the can_signal_t.decoder field. - * - * signal - The details of the signal that contains the state mapping. - * signals - The list of all signals - * signalCount - The length of the signals array - * value - The numerical value that will be converted to a boolean. - * send - An output argument that will be set to false if the value should - * not be sent for any reason. - * - * Returns a DynamicField with a boolean value of false if the raw signal value - * is 0.0, otherwise true. The 'send' argument will not be modified as this - * decoder always succeeds. - */ - static openxc_DynamicField booleanDecoder(can_signal_t& signal, const std::vector<can_signal_t>& signals, - float value, bool* send); - - /* Public: Update the metadata for a signal and the newly received value. - * - * This is an implementation of the SignalDecoder type signature, and can be - * used directly in the can_signal_t.decoder field. - * - * This function always flips 'send' to false. - * - * signal - The details of the signal that contains the state mapping. - * signals - The list of all signals. - * signalCount - The length of the signals array. - * value - The numerical value that will be converted to a boolean. - * send - This output argument will always be set to false, so the caller will - * know not to publish this value to the pipeline. - * - * The return value is undefined. - */ - static openxc_DynamicField ignoreDecoder(can_signal_t& signal, const std::vector<can_signal_t>& signals, - float value, bool* send); - - /* Public: Wrap a raw CAN signal value in a DynamicField without modification. - * - * This is an implementation of the SignalDecoder type signature, and can be - * used directly in the can_signal_t.decoder field. - * - * signal - The details of the signal that contains the state mapping. - * signals - The list of all signals - * signalCount - The length of the signals array - * value - The numerical value that will be wrapped in a DynamicField. - * send - An output argument that will be set to false if the value should - * not be sent for any reason. - * - * Returns a DynamicField with the original, unmodified raw CAN signal value as - * its numeric value. The 'send' argument will not be modified as this decoder - * always succeeds. - */ - static openxc_DynamicField noopDecoder(can_signal_t& signal, const std::vector<can_signal_t>& signals, - float value, bool* send); - - - /* Public: Parse a signal from a CAN message, apply any required transforations - * to get a human readable value and public the result to the pipeline. - * - * If the can_signal_t has a non-NULL 'decoder' field, the raw CAN signal value - * will be passed to the decoder before publishing. - * - * signal - The details of the signal to decode and forward. - * message - The received CAN message that should contain this signal. - * signals - an array of all active signals. - * - * The decoder returns an openxc_DynamicField, which may contain a number, - * string or boolean. - */ - static openxc_DynamicField translateSignal(can_signal_t& signal, can_message_t& message, - const std::vector<can_signal_t>& signals); - - /* Public: Parse a signal from a CAN message and apply any required - * transforations to get a human readable value. - * - * If the can_signal_t has a non-NULL 'decoder' field, the raw CAN signal value - * will be passed to the decoder before returning. - * - * signal - The details of the signal to decode and forward. - * message - The CAN message that contains the signal. - * signals - an array of all active signals. - * send - An output parameter that will be flipped to false if the value could - * not be decoded. - * - * The decoder returns an openxc_DynamicField, which may contain a number, - * string or boolean. If 'send' is false, the return value is undefined. - */ - static openxc_DynamicField decodeSignal(can_signal_t& signal, const can_message_t& message, - const std::vector<can_signal_t>& signals, bool* send); - - /* Public: Decode a transformed, human readable value from an raw CAN signal - * already parsed from a CAN message. - * - * This is the same as decodeSignal(const can_signal_t&, CanMessage*, const can_signal_t&, int, - * bool*) but you must parse the bitfield value of the signal from the CAN - * message yourself. This is useful if you need that raw value for something - * else. - */ - static openxc_DynamicField decodeSignal(can_signal_t& signal, float value, +public: + static float parseSignalBitfield(can_signal_t& signal, const can_message_t& message); + + static openxc_DynamicField stateDecoder(can_signal_t& signal, const std::vector<can_signal_t>& signals, + float value, bool* send); + static openxc_DynamicField booleanDecoder(can_signal_t& signal, const std::vector<can_signal_t>& signals, + float value, bool* send); + static openxc_DynamicField ignoreDecoder(can_signal_t& signal, const std::vector<can_signal_t>& signals, + float value, bool* send); + static openxc_DynamicField noopDecoder(can_signal_t& signal, const std::vector<can_signal_t>& signals, + float value, bool* send); + + static openxc_DynamicField translateSignal(can_signal_t& signal, can_message_t& message, + const std::vector<can_signal_t>& signals); + + static openxc_DynamicField decodeSignal(can_signal_t& signal, const can_message_t& message, const std::vector<can_signal_t>& signals, bool* send); + + static openxc_DynamicField decodeSignal(can_signal_t& signal, float value, + const std::vector<can_signal_t>& signals, bool* send); };
\ No newline at end of file diff --git a/src/can/can-message-set.hpp b/src/can/can-message-set.hpp index 8952320..94e2d8d 100644 --- a/src/can/can-message-set.hpp +++ b/src/can/can-message-set.hpp @@ -33,15 +33,15 @@ private: uint16_t can_signal_count_; /// < The number of CAN signals (across all messages) defined for this message set. uint16_t can_command_count_; /// < The number of CanCommmands defined for this message set. uint16_t obd2_signal_count_; /// < The number of obd2 signals defined for this message set. - + public: - can_message_set_t( - uint8_t index, - const std::string& name, - uint8_t can_bus_count, - short unsigned int can_message_count, - short unsigned int can_signal_count, - short unsigned int can_command_count, - short unsigned int obd2_signal_count); - + can_message_set_t( + uint8_t index, + const std::string& name, + uint8_t can_bus_count, + short unsigned int can_message_count, + short unsigned int can_signal_count, + short unsigned int can_command_count, + short unsigned int obd2_signal_count); + }; diff --git a/src/can/can-message.cpp b/src/can/can-message.cpp index 36cce92..cc4adb4 100644 --- a/src/can/can-message.cpp +++ b/src/can/can-message.cpp @@ -136,7 +136,10 @@ void can_message_t::set_format(const can_message_format_t new_format) * * This is the preferred way to initialize class members. * -* @param[in] args - struct read from can bus device. +* @param[in] frame - canfd_frame to convert coming from a read of CAN socket +* @param[in] nbyte - bytes read from socket read operation. +* +* @return A can_message_t object fully initialized with canfd_frame values. */ can_message_t can_message_t::convert_from_canfd_frame(const struct canfd_frame& frame, size_t nbytes) { diff --git a/src/configuration.cpp b/src/configuration.cpp index de5cc3b..d8c44a7 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -100,11 +100,11 @@ void configuration_t::set_active_message_set(uint8_t id) /** * @fn std::vector<std::string> find_can_signals(const openxc_DynamicField &key) * @brief return signals name found searching through CAN_signals and OBD2 pid - * - * @param[in] key - can contain numeric or string value in order to search against + * + * @param[in] key - can contain numeric or string value in order to search against * can signals or obd2 signals name. * - * @return Vector of signals name found. + * @return Vector of signals name found. */ void configuration_t::find_obd2_signals(const openxc_DynamicField &key, std::vector<obd2_signal_t*>& found_signals) { @@ -126,8 +126,8 @@ void configuration_t::find_obd2_signals(const openxc_DynamicField &key, std::vec /** * @fn void find_can_signals(const openxc_DynamicField& key, std::vector<can_signal_t*>& found_signals) * @brief return signals name found searching through CAN_signals and OBD2 pid - * - * @param[in] key - can contain numeric or string value in order to search against + * + * @param[in] key - can contain numeric or string value in order to search against * can signals or obd2 signals name. * @param[out] found_signals - provided vector to fill with ponter to signals matched. * diff --git a/src/low-can-binding.cpp b/src/low-can-binding.cpp index 7a19c62..f7833d8 100644 --- a/src/low-can-binding.cpp +++ b/src/low-can-binding.cpp @@ -126,7 +126,7 @@ static int subscribe_unsubscribe_signals(struct afb_req request, bool subscribe, int rets = 0; sd_event_source *source; - //TODO: Implement way to dynamically call the right function no matter + //TODO: Implement way to dynamically call the right function no matter // how much signals types we have. for(const std::string& sig : signals) @@ -236,9 +236,9 @@ extern "C" /** * @brief Initialize the binding. - * + * * @param[in] service Structure which represent the Application Framework Binder. - * + * * @return Exit code, zero if success. */ int afbBindingV1ServiceInit(struct afb_service service) diff --git a/src/utils/openxc-utils.cpp b/src/utils/openxc-utils.cpp index 34fe7f0..8449acc 100644 --- a/src/utils/openxc-utils.cpp +++ b/src/utils/openxc-utils.cpp @@ -20,6 +20,18 @@ #include "../configuration.hpp" + +/** + * @brief Build a specific VehicleMessage containing a DiagnosticResponse. + * + * @param[in] request - Original request use to retrieve decoder and callback + * @param[in] response - Response to the request that will be decoded if decoder set + * and put into the DiagnosticResponse of the VehicleMessage. + * @param[in] parsed_value - raw parsed value of the payload from CAN message + * + * @return a vehicle message including simple message that will be convert into + * a JSON object before being pushed to the subscribers + */ openxc_VehicleMessage build_VehicleMessage(active_diagnostic_request_t* request, const DiagnosticResponse& response, float parsed_value) { openxc_VehicleMessage message; @@ -74,6 +86,14 @@ openxc_VehicleMessage build_VehicleMessage(active_diagnostic_request_t* request, return message; } +/** + * @brief Build a specific VehicleMessage containing a SimpleMessage. + * + * @param[in] message - simple message to include into openxc_VehicleMessage + * + * @return a vehicle message including simple message that will be convert into + * a JSON object before being pushed to the subscribers + */ openxc_VehicleMessage build_VehicleMessage(const openxc_SimpleMessage& message) { openxc_VehicleMessage v; @@ -88,6 +108,17 @@ openxc_VehicleMessage build_VehicleMessage(const openxc_SimpleMessage& message) return v; } +/** + * @brief Build an openxc_SimpleMessage associating a name to an openxc_DynamicField + * + * @param[in] name - const string reference name to assign to the created SimpleMessage + * this will set has_name member to true and assign name to the name member. Maximum size for name is + * set to 100 char. + * @param[in] value - const reference with DynamicField to assign to SimpleMessage + * value. + * + * @return an openxc_SimpleMessage struct initialized with name and value provided. + */ openxc_SimpleMessage build_SimpleMessage(const std::string& name, const openxc_DynamicField& value) { openxc_SimpleMessage s; @@ -100,6 +131,14 @@ openxc_SimpleMessage build_SimpleMessage(const std::string& name, const openxc_D return s; } +/** + * @brief Build an openxc_DynamicField with a string value + * + * @param[in] value - const string reference value to assign to builded + * openxc_DynamicField. + * + * @return openxc_DynamicField initialized with a string value. + */ openxc_DynamicField build_DynamicField(const std::string& value) { openxc_DynamicField d; @@ -114,6 +153,15 @@ openxc_DynamicField build_DynamicField(const std::string& value) return d; } +/** + * @fn openxc_DynamicField build_DynamicField(double value); + * + * @brief Build an openxc_DynamicField with a double value + * + * @param[in] value - double value to assign to builded openxc_DynamicField. + * + * @return openxc_DynamicField initialized with a double value. + */ openxc_DynamicField build_DynamicField(double value) { openxc_DynamicField d; @@ -128,6 +176,13 @@ openxc_DynamicField build_DynamicField(double value) return d; } +/** + * @brief Build an openxc_DynamicField with a boolean value + * + * @param[in] value - boolean value to assign to builded openxc_DynamicField. + * + * @return openxc_DynamicField initialized with a boolean value. + */ openxc_DynamicField build_DynamicField(bool value) { openxc_DynamicField d; @@ -142,6 +197,16 @@ openxc_DynamicField build_DynamicField(bool value) return d; } +/** + * @brief Extract the simple message value from an openxc_VehicleMessage + * and return it. If there isn't SimpleMessage in the VehicleMessage then + * returned value will be a SimpleMessage with all field set at false. + * DynamicField from SimpleMessage will be boolean DynamicField set to false too. + * + * @param[in] v_msg - const reference to openxc_VehicleMessage + * + * @return A simpleMessage from the provided VehicleMessage. + */ openxc_SimpleMessage get_simple_message(const openxc_VehicleMessage& v_msg) { if (v_msg.has_simple_message) @@ -151,6 +216,13 @@ openxc_SimpleMessage get_simple_message(const openxc_VehicleMessage& v_msg) return s_msg; } +/** + * @brief Make a JSON object from a DynamicField + * + * @param[in] field - openxc_DynamicField struct to convert into + * a json object. + * @param[out] value - pointer to the object to set up. + */ void jsonify_DynamicField(const openxc_DynamicField& field, json_object* value) { if(field.has_numeric_value) @@ -161,6 +233,16 @@ void jsonify_DynamicField(const openxc_DynamicField& field, json_object* value) json_object_object_add(value, "value", json_object_new_string(field.string_value)); } +/** + * @brief Make a JSON object from a SimpleMessage + * + * @param[in] s_msg - const reference to an openxc_SimpleMessage + * struct to convert into a json object. + * @param[out] json - pointer with the DynamicField converted into json object + * + * @return True if SimpleMessage has been transformed into json object + * and false if not. In such case, a json object is returned { "error": "error msg"} + */ bool jsonify_simple(const openxc_SimpleMessage& s_msg, json_object* json) { if(s_msg.has_name) diff --git a/src/utils/openxc-utils.hpp b/src/utils/openxc-utils.hpp index f837ab1..c51fd3a 100644 --- a/src/utils/openxc-utils.hpp +++ b/src/utils/openxc-utils.hpp @@ -25,101 +25,16 @@ #include "openxc.pb.h" #include "../obd2/active-diagnostic-request.hpp" -/** - * @brief Build a specific VehicleMessage containing a SimpleMessage. - * - * @param[in] message - simple message to include into openxc_VehicleMessage - * - * @return a vehicle message including simple message that will be convert into - * a JSON object before being pushed to the subscribers - */ openxc_VehicleMessage build_VehicleMessage(active_diagnostic_request_t* request, const DiagnosticResponse& response, float parsed_value); openxc_VehicleMessage build_VehicleMessage(const openxc_SimpleMessage& message); -/** - * @fn openxc_SimpleMessage build_SimpleMessage(const std::string& name, const openxc_DynamicField& value); - * - * @brief Build an openxc_SimpleMessage associating a name to an openxc_DynamicField - * - * @param[in] name - const string reference name to assign to the created SimpleMessage - * this will set has_name member to true and assign name to the name member. Maximum size for name is - * set to 100 char. - * @param[in] value - const reference with DynamicField to assign to SimpleMessage - * value. - * - * @return an openxc_SimpleMessage struct initialized with name and value provided. - */ openxc_SimpleMessage build_SimpleMessage(const std::string& name, const openxc_DynamicField& value); - -/** - * @fn openxc_DynamicField build_DynamicField(const std::string& value); - * - * @brief Build an openxc_DynamicField with a string value - * - * @param[in] value - const string reference value to assign to builded - * openxc_DynamicField. - * - * @return openxc_DynamicField initialized with a string value. - */ openxc_DynamicField build_DynamicField(const std::string& value); - -/** - * @fn openxc_DynamicField build_DynamicField(double value); - * - * @brief Build an openxc_DynamicField with a double value - * - * @param[in] value - double value to assign to builded openxc_DynamicField. - * - * @return openxc_DynamicField initialized with a double value. - */ openxc_DynamicField build_DynamicField(double value); - -/** - * @fn openxc_DynamicField build_DynamicField(bool value); - * - * @brief Build an openxc_DynamicField with a boolean value - * - * @param[in] value - boolean value to assign to builded openxc_DynamicField. - * - * @return openxc_DynamicField initialized with a boolean value. - */ openxc_DynamicField build_DynamicField(bool value); -/** - * @fn void jsonify_DynamicField(const openxc_DynamicField& field, json_object* value); - * - * @brief Make a JSON object from a DynamicField - * - * @param[in] field - openxc_DynamicField struct to convert into - * a json object. - * @param[out] value - pointer to the object to set up. - */ -void jsonify_DynamicField(const openxc_DynamicField& field, json_object* value); - -/** - * @fn openxc_SimpleMessage get_simple_message(const openxc_VehicleMessage& v_msg); - * - * @brief Extract the simple message value from an openxc_VehicleMessage - * and return it. If there isn't SimpleMessage in the VehicleMessage then - * returned value will be a SimpleMessage with all field set at false. - * DynamicField from SimpleMessage will be boolean DynamicField set to false too. - * - * @param[in] v_msg - const reference to openxc_VehicleMessage - * - * @return A simpleMessage from the provided VehicleMessage. - */ openxc_SimpleMessage get_simple_message(const openxc_VehicleMessage& v_msg); -/** - * @fn json_object* jsonify_simple(const openxc_SimpleMessage& s_msg); - * - * @brief Make a JSON object from a SimpleMessage - * - * @param[in] s_msg - const reference to an openxc_SimpleMessage - * struct to convert into a json object. - * @param[out] json - pointer with the DynamicField converted into json object - * - * @return True if SimpleMessage has been transformed into json object - * and false if not. In such case, a json object is returned { "error": "error msg"} - */ +void jsonify_DynamicField(const openxc_DynamicField& field, json_object* value); + bool jsonify_simple(const openxc_SimpleMessage& s_msg, json_object* json);
\ No newline at end of file |