diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2017-03-17 12:48:46 +0100 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2017-03-17 12:48:46 +0100 |
commit | 7591838644a3fcb5145b9ccc7200166debe7ba87 (patch) | |
tree | 90336690ab6e294e9d1937beb98a1d50a0b327c4 /src/can | |
parent | f05cdb00aff6ba1d41a6d705d34bce42122f971f (diff) |
Comments fixes, typo and formating.
No more warning when generate the docs and all comments follow the same
formating.
Change-Id: I80d4c5c2d64401c2e53a550c60155680c4f968ce
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'src/can')
-rw-r--r-- | src/can/can-bus-dev.cpp | 45 | ||||
-rw-r--r-- | src/can/can-bus-dev.hpp | 12 | ||||
-rw-r--r-- | src/can/can-bus.cpp | 204 | ||||
-rw-r--r-- | src/can/can-bus.hpp | 24 | ||||
-rw-r--r-- | src/can/can-command.hpp | 50 | ||||
-rw-r--r-- | src/can/can-decoder.cpp | 252 | ||||
-rw-r--r-- | src/can/can-decoder.hpp | 2 | ||||
-rw-r--r-- | src/can/can-message.cpp | 134 | ||||
-rw-r--r-- | src/can/can-signals.hpp | 86 |
9 files changed, 397 insertions, 412 deletions
diff --git a/src/can/can-bus-dev.cpp b/src/can/can-bus-dev.cpp index 85bed4a..fb76498 100644 --- a/src/can/can-bus-dev.cpp +++ b/src/can/can-bus-dev.cpp @@ -31,7 +31,9 @@ #include "../low-can-binding.hpp" /// @brief Class constructor -/// @param dev_name String representing the device name into the linux /dev tree +/// +/// @param[in] dev_name - String representing the device name into the linux /dev tree +/// @param[in] address - integer identifier of the bus, set using init_can_dev from can_bus_t. can_bus_dev_t::can_bus_dev_t(const std::string& dev_name, int32_t address) : device_name_{dev_name}, address_{address} {} @@ -47,6 +49,10 @@ uint32_t can_bus_dev_t::get_address() const } /// @brief Open the can socket and returning it +/// +/// We try to open CAN socket and apply the following options +/// timestamp received messages and pass the socket to FD mode. +/// /// @return -1 if something wrong. int can_bus_dev_t::open() { @@ -55,41 +61,41 @@ int can_bus_dev_t::open() struct ifreq ifr; struct timeval timeout; - DEBUG(binder_interface, "CAN Handler socket : %d", can_socket_.socket()); + DEBUG(binder_interface, "open: CAN Handler socket : %d", can_socket_.socket()); if (can_socket_) return 0; can_socket_.open(PF_CAN, SOCK_RAW, CAN_RAW); if (can_socket_) { - DEBUG(binder_interface, "CAN Handler socket correctly initialized : %d", can_socket_.socket()); + DEBUG(binder_interface, "open: CAN Handler socket correctly initialized : %d", can_socket_.socket()); // Set timeout for read can_socket_.setopt(SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout)); // Set timestamp for receveid frame if (can_socket_.setopt(SOL_SOCKET, SO_TIMESTAMP, ×tamp_on, sizeof(timestamp_on)) < 0) - WARNING(binder_interface, "setsockopt SO_TIMESTAMP error: %s", ::strerror(errno)); - DEBUG(binder_interface, "Switch CAN Handler socket to use fd mode"); + WARNING(binder_interface, "open: setsockopt SO_TIMESTAMP error: %s", ::strerror(errno)); + DEBUG(binder_interface, "open: Switch CAN Handler socket to use fd mode"); // try to switch the socket into CAN_FD mode if (can_socket_.setopt(SOL_CAN_RAW, CAN_RAW_FD_FRAMES, &canfd_on, sizeof(canfd_on)) < 0) { - NOTICE(binder_interface, "Can not switch into CAN Extended frame format."); + NOTICE(binder_interface, "open: Can not switch into CAN Extended frame format."); is_fdmode_on_ = false; } else { - DEBUG(binder_interface, "Correctly set up CAN socket to use FD frames."); + DEBUG(binder_interface, "open: Correctly set up CAN socket to use FD frames."); is_fdmode_on_ = true; } // Attempts to open a socket to CAN bus ::strcpy(ifr.ifr_name, device_name_.c_str()); - DEBUG(binder_interface, "ifr_name is : %s", ifr.ifr_name); + DEBUG(binder_interface, "open: ifr_name is : %s", ifr.ifr_name); if(::ioctl(can_socket_.socket(), SIOCGIFINDEX, &ifr) < 0) { - ERROR(binder_interface, "ioctl failed. Error was : %s", strerror(errno)); + ERROR(binder_interface, "open: ioctl failed. Error was : %s", strerror(errno)); } else { @@ -109,12 +115,17 @@ int can_bus_dev_t::open() } /// @brief Close the bus. +/// +/// @return interger return value of socket.close() function int can_bus_dev_t::close() { return can_socket_.close(); } -/// @brief Read the can socket and retrieve canfd_frame +/// @brief Read the can socket and retrieve canfd_frame. +/// +/// Read operation are blocking and we try to read CANFD frame +/// rather than classic CAN frame. CANFD frame are retro compatible. can_message_t can_bus_dev_t::read() { ssize_t nbytes; @@ -161,7 +172,7 @@ void can_bus_dev_t::stop_reading() } /// @brief Thread function used to read the can socket. -/// @param[in] can_bus object to be used to read the can socket +/// @param[in] can_bus - object to be used to read the can socket void can_bus_dev_t::can_reader(can_bus_t& can_bus) { while(is_running_) @@ -176,7 +187,9 @@ void can_bus_dev_t::can_reader(can_bus_t& can_bus) } /// @brief Send a can message from a can_message_t object. -/// @param[in] can_msg the can message object to send +/// @param[in] can_msg - the can message object to send +/// +/// @return 0 if message snet, -1 if something wrong. int can_bus_dev_t::send(can_message_t& can_msg) { ssize_t nbytes; @@ -211,6 +224,8 @@ int can_bus_dev_t::send(can_message_t& can_msg) /// @param[in] arbitration_id - CAN arbitration id. /// @param[in] data - CAN message payload to send /// @param[in] size - size of the data to send +/// +/// @return True if message sent, false if not. bool can_bus_dev_t::shims_send(const uint32_t arbitration_id, const uint8_t* data, const uint8_t size) { ssize_t nbytes; @@ -227,14 +242,14 @@ bool can_bus_dev_t::shims_send(const uint32_t arbitration_id, const uint8_t* dat if (nbytes == -1) { ERROR(binder_interface, "send_can_message: Sending CAN frame failed."); - return -1; + return false; } - return (int)nbytes; + return true; } else { ERROR(binder_interface, "send_can_message: socket not initialized. Attempt to reopen can device socket."); open(); } - return 0; + return false; } diff --git a/src/can/can-bus-dev.hpp b/src/can/can-bus-dev.hpp index 63e6163..a612e7d 100644 --- a/src/can/can-bus-dev.hpp +++ b/src/can/can-bus-dev.hpp @@ -29,20 +29,20 @@ class can_bus_t; class can_message_t; /// @brief Object representing a can device. Handle opening, closing and reading on the -/// socket. This is the low level object to be use by can_bus_t. +/// socket. This is the low level object to be initialized and use by can_bus_t. class can_bus_dev_t { private: - std::string device_name_; + std::string device_name_; ///< a string identifier identitfying the linux CAN device. utils::socket_t can_socket_; - int32_t address_; /// < an identifier used through binding that refer to that device + int32_t address_; ///< an identifier used through binding that refer to that device - bool is_fdmode_on_; /// < boolean telling if whether or not the can socket use fdmode. + bool is_fdmode_on_; ///< boolean telling if whether or not the can socket use fdmode. struct sockaddr_can txAddress_; /// < internal member using to bind to the socket - std::thread th_reading_; /// < Thread handling read the socket can device filling can_message_q_ queue of can_bus_t - bool is_running_ = false; /// < boolean telling whether or not reading is running or not + std::thread th_reading_; ///< Thread handling read the socket can device filling can_message_q_ queue of can_bus_t + bool is_running_ = false; ///< boolean telling whether or not reading is running or not void can_reader(can_bus_t& can_bus); public: diff --git a/src/can/can-bus.cpp b/src/can/can-bus.cpp index 0c2337c..a81c142 100644 --- a/src/can/can-bus.cpp +++ b/src/can/can-bus.cpp @@ -40,12 +40,9 @@ extern "C" #include <afb/afb-binding.h> } -/** -* @brief Class constructor -* -* @param struct afb_binding_interface *interface between daemon and binding -* @param int file handle to the json configuration file. -*/ +/// @brief Class constructor +/// +/// @param[in] conf_file - handle to the json configuration file. can_bus_t::can_bus_t(int conf_file) : conf_file_{conf_file} { @@ -53,18 +50,16 @@ can_bus_t::can_bus_t(int conf_file) std::map<std::string, std::shared_ptr<can_bus_dev_t>> can_bus_t::can_devices_; -/** - * @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. - */ +/// @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; @@ -72,21 +67,21 @@ int can_bus_t::process_can_signals(can_message_t& can_message) openxc_DynamicField search_key, decoded_message; openxc_VehicleMessage vehicle_message; - /* First we have to found which can_signal_t it is */ + // First we have to found which can_signal_t it is search_key = build_DynamicField((double)can_message.get_id()); configuration_t::instance().find_can_signals(search_key, signals); - /* Decoding the message ! Don't kill the messenger ! */ + // Decoding the message ! Don't kill the messenger ! for(auto& sig : signals) { std::lock_guard<std::mutex> subscribed_signals_lock(get_subscribed_signals_mutex()); std::map<std::string, struct afb_event>& s = get_subscribed_signals(); - /* DEBUG message to make easier debugger STL containers... - DEBUG(binder_interface, "Operator[] key char: %s, event valid? %d", sig.generic_name, afb_event_is_valid(s[sig.generic_name])); - DEBUG(binder_interface, "Operator[] key string: %s, event valid? %d", sig.generic_name, afb_event_is_valid(s[std::string(sig.generic_name)])); - DEBUG(binder_interface, "Nb elt matched char: %d", (int)s.count(sig.generic_name)); - DEBUG(binder_interface, "Nb elt matched string: %d", (int)s.count(std::string(sig.generic_name)));*/ + // DEBUG message to make easier debugger STL containers... + //DEBUG(binder_interface, "Operator[] key char: %s, event valid? %d", sig.generic_name, afb_event_is_valid(s[sig.generic_name])); + //DEBUG(binder_interface, "Operator[] key string: %s, event valid? %d", sig.generic_name, afb_event_is_valid(s[std::string(sig.generic_name)])); + //DEBUG(binder_interface, "Nb elt matched char: %d", (int)s.count(sig.generic_name)); + //DEBUG(binder_interface, "Nb elt matched string: %d", (int)s.count(std::string(sig.generic_name)); if( s.find(sig->get_name()) != s.end() && afb_event_is_valid(s[sig->get_name()])) { decoded_message = decoder_t::translateSignal(*sig, can_message, configuration_t::instance().get_can_signals()); @@ -105,15 +100,14 @@ 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] manager - the diagnostic manager object that handle diagnostic communication - * @param[in] can_message - a single CAN message from the CAN socket read, to be decode. - * - * @return How many signals has been decoded. - */ +/// @brief Will make the decoding operation on a diagnostic CAN message.Then it find the subscribed signal +/// corresponding and will add the vehicle_message to the queue of event to pushed before notifying +/// the event push thread to process it. +/// +/// @param[in] manager - the diagnostic manager object that handle diagnostic communication +/// @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(diagnostic_manager_t& manager, const can_message_t& can_message) { int processed_signals = 0; @@ -134,20 +128,18 @@ int can_bus_t::process_diagnostic_signals(diagnostic_manager_t& manager, const c return processed_signals; } -/** -* @brief thread to decoding raw CAN messages. -* -* @desc It will take from the can_message_q_ queue the next can message to process then it will search -* about signal subscribed if there is a valid afb_event for it. We only decode signal for which a -* subscription has been made. Can message will be decoded using translateSignal that will pass it to the -* 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 -* then decoding a diagnostic message else use classic CAN signals decoding functions. -* -* TODO: make diagnostic messages parsing optionnal. -*/ +/// @brief thread to decoding raw CAN messages. +/// +/// Depending on the nature of message, if arbitration ID matches ID for a diagnostic response +/// then decoding a diagnostic message else use classic CAN signals decoding functions. +/// +/// It will take from the can_message_q_ queue the next can message to process then it search +/// about signal subscribed if there is a valid afb_event for it. We only decode signal for which a +/// subscription has been made. Can message will be decoded using translateSignal that will pass it to the +/// 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. +/// +/// TODO: make diagnostic messages parsing optionnal. void can_bus_t::can_decode_message() { can_message_t can_message; @@ -165,10 +157,8 @@ void can_bus_t::can_decode_message() } } -/** -* @brief thread to push events to suscribers. It will read subscribed_signals map to look -* which are events that has to be pushed. -*/ +/// @brief thread to push events to suscribers. It will read subscribed_signals map to look +/// which are events that has to be pushed. void can_bus_t::can_event_push() { openxc_VehicleMessage v_message; @@ -195,10 +185,8 @@ 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; @@ -212,25 +200,23 @@ void can_bus_t::start_threads() is_pushing_ = false; } -/** -* @brief Will stop all threads holded by can_bus_t object -* which are decoding and pushing then will wait that's -* they'll finish their job. -*/ +/// @brief Will stop all threads holded by can_bus_t object +/// which are decoding and pushing then will wait that's +/// they'll finish their job. void can_bus_t::stop_threads() { is_decoding_ = false; is_pushing_ = false; } -/** -* @brief Will initialize can_bus_dev_t objects after reading -* 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. -*/ +/// @brief Will initialize can_bus_dev_t objects after reading +/// 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. +/// +/// @return 0 if ok, other if not. int can_bus_t::init_can_dev() { std::vector<std::string> devices_name; @@ -264,12 +250,10 @@ int can_bus_t::init_can_dev() return 1; } -/** -* @brief read the conf_file_ and will parse json objects -* in it searching for canbus objects devices name. -* -* @return Vector of can bus device name string. -*/ +/// @brief read the conf_file_ and will parse json objects +/// in it searching for canbus objects devices name. +/// +/// @return Vector of can bus device name string. std::vector<std::string> can_bus_t::read_conf() { std::vector<std::string> ret; @@ -314,31 +298,25 @@ std::vector<std::string> can_bus_t::read_conf() return ret; } -/** -* @brief return new_can_message_cv_ member -* -* @return return new_can_message_cv_ member -*/ +/// @brief return new_can_message_cv_ member +/// +/// @return return new_can_message_cv_ member std::condition_variable& can_bus_t::get_new_can_message_cv() { return new_can_message_cv_; } -/** -* @brief return can_message_mutex_ member -* -* @return return can_message_mutex_ member -*/ +/// @brief return can_message_mutex_ member +/// +/// @return return can_message_mutex_ member std::mutex& can_bus_t::get_can_message_mutex() { return can_message_mutex_; } -/** -* @brief Return first can_message_t on the queue -* -* @return a can_message_t -*/ +/// @brief Return first can_message_t on the queue +/// +/// @return a can_message_t can_message_t can_bus_t::next_can_message() { can_message_t can_msg; @@ -355,21 +333,17 @@ can_message_t can_bus_t::next_can_message() return can_msg; } -/** -* @brief Push a can_message_t into the queue -* -* @param the const reference can_message_t object to push into the queue -*/ +/// @brief Push a can_message_t into the queue +/// +/// @param[in] can_msg - the const reference can_message_t object to push into the queue void can_bus_t::push_new_can_message(const can_message_t& can_msg) { can_message_q_.push(can_msg); } -/** -* @brief Return first openxc_VehicleMessage on the queue -* -* @return a openxc_VehicleMessage containing a decoded can message -*/ +/// @brief Return first openxc_VehicleMessage on the queue +/// +/// @return a openxc_VehicleMessage containing a decoded can message openxc_VehicleMessage can_bus_t::next_vehicle_message() { openxc_VehicleMessage v_msg; @@ -385,34 +359,28 @@ openxc_VehicleMessage can_bus_t::next_vehicle_message() return v_msg; } -/** -* @brief Push a openxc_VehicleMessage into the queue -* -* @param the const reference openxc_VehicleMessage object to push into the queue -*/ +/// @brief Push a openxc_VehicleMessage into the queue +/// +/// @param[in] v_msg - const reference openxc_VehicleMessage object to push into the queue void can_bus_t::push_new_vehicle_message(const openxc_VehicleMessage& v_msg) { vehicle_message_q_.push(v_msg); } -/** -* @brief Return a map with the can_bus_dev_t initialized -* -* @return map can_bus_dev_m_ map -*/ +/// @brief Return a map with the can_bus_dev_t initialized +/// +/// @return map can_bus_dev_m_ map const std::map<std::string, std::shared_ptr<can_bus_dev_t>>& can_bus_t::get_can_devices() const { return can_bus_t::can_devices_; } -/** -* @brief Return the shared pointer on the can_bus_dev_t initialized -* with device_name "bus" -* -* @param[in] bus - CAN bus device name to retrieve. -* -* @return A shared pointer on an object can_bus_dev_t -*/ +/// @brief Return the shared pointer on the can_bus_dev_t initialized +/// with device_name "bus" +/// +/// @param[in] bus - CAN bus device name to retrieve. +/// +/// @return A shared pointer on an object can_bus_dev_t std::shared_ptr<can_bus_dev_t> can_bus_t::get_can_device(std::string bus) { return can_bus_t::can_devices_[bus]; diff --git a/src/can/can-bus.hpp b/src/can/can-bus.hpp index 9370d3b..eb47476 100644 --- a/src/can/can-bus.hpp +++ b/src/can/can-bus.hpp @@ -48,25 +48,25 @@ class can_bus_t { private: - int conf_file_; /// < configuration file handle used to initialize can_bus_dev_t objects. + int conf_file_; ///< configuration file handle used to initialize can_bus_dev_t objects. void can_decode_message(); - std::thread th_decoding_; /// < thread that'll handle decoding a can frame - bool is_decoding_ = false; /// < boolean member controling thread while loop + std::thread th_decoding_; ///< thread that'll handle decoding a can frame + bool is_decoding_ = false; ///< boolean member controling thread while loop void can_event_push(); - std::thread th_pushing_; /// < thread that'll handle pushing decoded can frame to subscribers - bool is_pushing_ = false; /// < boolean member controling thread while loop + std::thread th_pushing_; ///< thread that'll handle pushing decoded can frame to subscribers + bool is_pushing_ = false; ///< boolean member controling thread while loop - std::condition_variable new_can_message_cv_; /// < condition_variable use to wait until there is a new CAN message to read - std::mutex can_message_mutex_; /// < mutex protecting the can_message_q_ queue. - std::queue <can_message_t> can_message_q_; /// < queue that'll store can_message_t to decoded + std::condition_variable new_can_message_cv_; ///< condition_variable use to wait until there is a new CAN message to read + std::mutex can_message_mutex_; ///< mutex protecting the can_message_q_ queue. + std::queue <can_message_t> can_message_q_; ///< queue that'll store can_message_t to decoded - 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::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 - static std::map<std::string, 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 + static std::map<std::string, 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 public: can_bus_t(int conf_file); diff --git a/src/can/can-command.hpp b/src/can/can-command.hpp index 8324d32..4cf20cb 100644 --- a/src/can/can-command.hpp +++ b/src/can/can-command.hpp @@ -20,34 +20,34 @@ #include "openxc.pb.h" #include "can-signals.hpp" -/** - * @brief The type signature for a function to handle a custom OpenXC command. - * - * @param[in] name - the name of the received command. - * @param[in] value - the value of the received command, in a DynamicField. The actual type - * may be a number, string or bool. - * @param[in] event - an optional event from the received command, in a DynamicField. The - * actual type may be a number, string or bool. - * @param[in] signals - The list of all signals. - * @param[in] signalCount - The length of the signals array. - */ +/// +/// @brief The type signature for a function to handle a custom OpenXC command. +/// +/// @param[in] name - the name of the received command. +/// @param[in] value - the value of the received command, in a DynamicField. The actual type +/// may be a number, string or bool. +/// @param[in] event - an optional event from the received command, in a DynamicField. The +/// actual type may be a number, string or bool. +/// @param[in] signals - The list of all signals. +/// @param[in] signalCount - The length of the signals array. +/// typedef void (*CommandHandler)(const char* name, openxc_DynamicField* value, openxc_DynamicField* event, can_signal_t* signals, int signalCount); -/* @struct CanCommand - * @brief The structure to represent a supported custom OpenXC command. - * - * @desc For completely customized CAN commands without a 1-1 mapping between an - * OpenXC message from the host and a CAN signal, you can define the name of the - * command and a custom function to handle it in the VI. An example is - * the "turn_signal_status" command in OpenXC, which has a value of "left" or - * "right". The vehicle may have separate CAN signals for the left and right - * turn signals, so you will need to implement a custom command handler to send - * the correct signals. - * - * Command handlers are also useful if you want to trigger multiple CAN messages - * or signals from a signal OpenXC message. - */ +/// @struct CanCommand +/// @brief The structure to represent a supported custom OpenXC command. +/// +/// For completely customized CAN commands without a 1-1 mapping between an +/// OpenXC message from the host and a CAN signal, you can define the name of the +/// command and a custom function to handle it in the VI. An example is +/// the "turn_signal_status" command in OpenXC, which has a value of "left" or +/// "right". The vehicle may have separate CAN signals for the left and right +/// turn signals, so you will need to implement a custom command handler to send +/// the correct signals. +/// +/// Command handlers are also useful if you want to trigger multiple CAN messages +/// or signals from a signal OpenXC message. +/// typedef struct { const char* generic_name; /*!< generic_name - The name of the command.*/ CommandHandler handler; /*!< handler - An function to process the received command's data and perform some diff --git a/src/can/can-decoder.cpp b/src/can/can-decoder.cpp index 866434e..467261a 100644 --- a/src/can/can-decoder.cpp +++ b/src/can/can-decoder.cpp @@ -20,15 +20,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. -*/ +/// @brief 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, @@ -36,21 +36,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. -*/ +/// @brief 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) { @@ -58,21 +58,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. -*/ +/// @brief 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) { @@ -80,21 +80,21 @@ 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. -*/ +/// @brief 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) { @@ -106,22 +106,22 @@ openxc_DynamicField decoder_t::ignoreDecoder(can_signal_t& signal, 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. -*/ +/// @brief 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) { @@ -136,19 +136,19 @@ openxc_DynamicField decoder_t::stateDecoder(can_signal_t& signal, } -/* 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. -*/ +/// @brief 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) { @@ -172,21 +172,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. -*/ +/// @brief 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) { @@ -197,19 +197,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. -*/ +/// @brief 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] message - Raw CAN message to decode +/// @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) { @@ -218,20 +218,22 @@ openxc_DynamicField decoder_t::decodeSignal( can_signal_t& signal, } -/** -* @brief Decode the payload of an OBD-II PID. -* -* This function matches the type signature for a DiagnosticResponseDecoder, so -* it can be used as the decoder for a DiagnosticRequest. It returns the decoded -* value of the PID, using the standard formulas (see -* http://en.wikipedia.org/wiki/OBD-II_PIDs#Mode_01). -* -* @param[in] response - the received DiagnosticResponse (the data is in response.payload, -* a byte array). This is most often used when the byte order is -* signiticant, i.e. with many OBD-II PID formulas. -* @param[in] parsed_payload - the entire payload of the response parsed as an int. -*/ -float decoder_t::decode_obd2_response(const DiagnosticResponse* response, float parsedPayload) +/// +/// @brief Decode the payload of an OBD-II PID. +/// +/// This function matches the type signature for a DiagnosticResponseDecoder, so +/// it can be used as the decoder for a DiagnosticRequest. It returns the decoded +/// value of the PID, using the standard formulas (see +/// http://en.wikipedia.org/wiki/OBD-II_PIDs#Mode_01). +/// +/// @param[in] response - the received DiagnosticResponse (the data is in response.payload, +/// a byte array). This is most often used when the byte order is +/// signiticant, i.e. with many OBD-II PID formulas. +/// @param[in] parsed_payload - the entire payload of the response parsed as an int. +/// +/// @return Float decoded value. +/// +float decoder_t::decode_obd2_response(const DiagnosticResponse* response, float parsed_payload) { return diagnostic_decode_obd2_pid(response); }
\ No newline at end of file diff --git a/src/can/can-decoder.hpp b/src/can/can-decoder.hpp index 0507a6b..ebe1de2 100644 --- a/src/can/can-decoder.hpp +++ b/src/can/can-decoder.hpp @@ -44,6 +44,6 @@ public: static openxc_DynamicField decodeSignal(can_signal_t& signal, float value, const std::vector<can_signal_t>& signals, bool* send); - static float decode_obd2_response(const DiagnosticResponse* response, float parsedPayload); + static float decode_obd2_response(const DiagnosticResponse* response, float parsed_payload); };
\ No newline at end of file diff --git a/src/can/can-message.cpp b/src/can/can-message.cpp index 5d8c9cb..af0d3f3 100644 --- a/src/can/can-message.cpp +++ b/src/can/can-message.cpp @@ -21,11 +21,11 @@ #include "../low-can-binding.hpp" -/** -* @brief Class constructor -* -* Constructor about can_message_t class. -*/ +/// +/// @brief Class constructor +/// +/// Constructor about can_message_t class. +/// can_message_t::can_message_t() : maxdlen_{0}, id_{0}, length_{0}, format_{can_message_format_t::ERROR}, rtr_flag_{false}, flags_{0} {} @@ -46,31 +46,31 @@ can_message_t::can_message_t(uint8_t maxdlen, data_{data} {} -/** -* @brief Retrieve id_ member value. -* -* @return id_ class member -*/ +/// +/// @brief Retrieve id_ member value. +/// +/// @return id_ class member +/// uint32_t can_message_t::get_id() const { return id_; } -/** -* @brief Retrieve RTR flag member. -* -* @return rtr_flags_ class member -*/ +/// +/// @brief Retrieve RTR flag member. +/// +/// @return rtr_flags_ class member +/// bool can_message_t::get_rtr_flag_() const { return rtr_flag_; } -/** -* @brief Retrieve format_ member value. -* -* @return format_ class member -*/ +/// +/// @brief Retrieve format_ member value. +/// +/// @return format_ class member +/// can_message_format_t can_message_t::get_format() const { if (format_ != can_message_format_t::STANDARD || format_ != can_message_format_t::EXTENDED) @@ -78,43 +78,43 @@ can_message_format_t can_message_t::get_format() const return format_; } -/** -* @brief Retrieve flags_ member value. -* -* @return flags_ class member -*/ +/// +/// @brief Retrieve flags_ member value. +/// +/// @return flags_ class member +/// uint8_t can_message_t::get_flags() const { return flags_; } -/** -* @brief Retrieve data_ member value. -* -* @return pointer to the first element -* of class member data_ -*/ +/// +/// @brief Retrieve data_ member value. +/// +/// @return pointer to the first element +/// of class member data_ +/// const uint8_t* can_message_t::get_data() const { return data_.data(); } -/** -* @brief Retrieve length_ member value. -* -* @return length_ class member -*/ +/// +/// @brief Retrieve length_ member value. +/// +/// @return length_ class member +/// uint8_t can_message_t::get_length() const { return length_; } -/** -* @brief Control whether the object is correctly initialized -* to be sent over the CAN bus -* -* @return true if object correctly initialized and false if not. -*/ +/// +/// @brief Control whether the object is correctly initialized +/// to be sent over the CAN bus +/// +/// @return true if object correctly initialized and false if not. +/// bool can_message_t::is_correct_to_send() { if (id_ != 0 && length_ != 0 && format_ != can_message_format_t::ERROR) @@ -127,14 +127,14 @@ bool can_message_t::is_correct_to_send() return false; } -/** -* @brief Set format_ member value. -* -* Preferred way to initialize these members by using -* convert_from_canfd_frame method. -* -* @param[in] new_format - class member -*/ +/// +/// @brief Set format_ member value. +/// +/// Preferred way to initialize these members by using +/// convert_from_canfd_frame method. +/// +/// @param[in] new_format - class member +/// void can_message_t::set_format(const can_message_format_t new_format) { if(new_format == can_message_format_t::STANDARD || new_format == can_message_format_t::EXTENDED || new_format == can_message_format_t::ERROR) @@ -143,16 +143,16 @@ void can_message_t::set_format(const can_message_format_t new_format) ERROR(binder_interface, "ERROR: Can set format, wrong format chosen"); } -/** -* @brief Take a canfd_frame struct to initialize class members -* -* This is the preferred way to initialize class members. -* -* @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. -*/ +/// +/// @brief Take a canfd_frame struct to initialize class members +/// +/// This is the preferred way to initialize class members. +/// +/// @param[in] frame - canfd_frame to convert coming from a read of CAN socket +/// @param[in] nbytes - 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) { uint8_t maxdlen, length, flags = (uint8_t)NULL; @@ -240,13 +240,13 @@ can_message_t can_message_t::convert_from_canfd_frame(const struct canfd_frame& return can_message_t(maxdlen, id, length, format, rtr_flag, flags, data); } -/** -* @brief Take all initialized class's members and build an -* canfd_frame struct that can be use to send a CAN message over -* the bus. -* -* @return canfd_frame struct built from class members. -*/ +/// +/// @brief Take all initialized class's members and build an +/// canfd_frame struct that can be use to send a CAN message over +/// the bus. +/// +/// @return canfd_frame struct built from class members. +/// canfd_frame can_message_t::convert_to_canfd_frame() { canfd_frame frame; diff --git a/src/can/can-signals.hpp b/src/can/can-signals.hpp index aacb888..34ebeeb 100644 --- a/src/can/can-signals.hpp +++ b/src/can/can-signals.hpp @@ -1,19 +1,19 @@ -/* - * Copyright (C) 2015, 2016 "IoT.bzh" - * Author "Romain Forlot" <romain.forlot@iot.bzh> - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/// +/// Copyright (C) 2015, 2016 "IoT.bzh" +/// Author "Romain Forlot" <romain.forlot@iot.bzh> +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// #pragma once @@ -40,36 +40,36 @@ extern "C" class can_signal_t; -/** - * @brief The type signature for a CAN signal decoder. - * - * @desc A SignalDecoder transforms a raw floating point CAN signal into a number, - * string or boolean. - * - * @param[in] signal - The CAN signal that we are decoding. - * @param[in] signals - The list of all signals. - * @param[in] signalCount - The length of the signals array. - * @param[in] value - The CAN signal parsed from the message as a raw floating point - * value. - * @param[out] send - An output parameter. If the decoding failed or the CAN signal should - * not send for some other reason, this should be flipped to false. - * - * @return a decoded value in an openxc_DynamicField struct. - */ +/// +/// @brief The type signature for a CAN signal decoder. +/// +/// A SignalDecoder transforms a raw floating point CAN signal into a number, +/// string or boolean. +/// +/// @param[in] signal - The CAN signal that we are decoding. +/// @param[in] signals - The list of all signals. +/// @param[in] signalCount - The length of the signals array. +/// @param[in] value - The CAN signal parsed from the message as a raw floating point +/// value. +/// @param[out] send - An output parameter. If the decoding failed or the CAN signal should +/// not send for some other reason, this should be flipped to false. +/// +/// @return a decoded value in an openxc_DynamicField struct. +/// typedef openxc_DynamicField (*SignalDecoder)(can_signal_t& signal, const std::vector<can_signal_t>& signals, float value, bool* send); -/** - * @brief: The type signature for a CAN signal encoder. - * - * @desc A SignalEncoder transforms a number, string or boolean into a raw floating - * point value that fits in the CAN signal. - * - * @params[in] signal - The CAN signal to encode. - * @params[in] value - The dynamic field to encode. - * @params send - An output parameter. If the encoding failed or the CAN signal should - * not be encoded for some other reason, this will be flipped to false. - */ +/// +/// @brief: The type signature for a CAN signal encoder. +/// +/// A SignalEncoder transforms a number, string or boolean into a raw floating +/// point value that fits in the CAN signal. +/// +/// @param[in] signal - The CAN signal to encode. +/// @param[in] value - The dynamic field to encode. +/// @param[out] send - An output parameter. If the encoding failed or the CAN signal should +/// not be encoded for some other reason, this will be flipped to false. +/// typedef uint64_t (*SignalEncoder)(can_signal_t* signal, openxc_DynamicField* value, bool* send); |