diff options
Diffstat (limited to 'Master/Real-Time Systems/mki/src/libcanio.h')
| -rw-r--r-- | Master/Real-Time Systems/mki/src/libcanio.h | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/Master/Real-Time Systems/mki/src/libcanio.h b/Master/Real-Time Systems/mki/src/libcanio.h new file mode 100644 index 0000000..8f57b14 --- /dev/null +++ b/Master/Real-Time Systems/mki/src/libcanio.h @@ -0,0 +1,81 @@ +//============================================================================ +// Name: +// libcanio.h +// +// Summary: +// A pretty simple interface to the SocketCan layer, +// which trys to make the communication with the can interfaces easier. +// +// Created on: +// Sep 24, 2010 +// +// Author: +// Christian Steiger +//============================================================================ + +#ifndef LIBCANIO_H_ +#define LIBCANIO_H_ + +#include <cstdio> +#include <cstdlib> +#include <cstring> +#include <cerrno> + +#include <unistd.h> +#include <net/if.h> +#include <sys/time.h> +#include <sys/ioctl.h> +#include <sys/socket.h> +#include <linux/can.h> +#include <linux/can/raw.h> +#include <linux/can/error.h> + +class CanIO +{ + public: + // constructor and destructor + CanIO(); + virtual ~CanIO(); + + // connect and disconnect + int connect(const char* const interface = "can0"); + int disconnect(void); + + // read and write messages + ssize_t readMsg(can_frame* frame, timeval* timestamp = 0); + ssize_t writeMsg(const can_frame* const frame); + + // socketcan options + int showCanErrors(const can_err_mask_t err_mask = 0); + int hideCanErrors(void); + int enableLoopBack(void); + int disableLoopBack(void); + int enableRecvOwnMsgs(void); + int disableRecvOwnMsgs(void); + + // filter functions + int addFilter(const can_filter* const filter, const unsigned int size); + int enableFilter(void); + int disableFilter(void); + int clearFilter(void); + + // debugging help + void hideErrors(void); + void showErrors(void); + + protected: + // class members + int m_socket; + char m_print_errors; + char m_filter_active; + can_filter* m_filter; + unsigned short int m_filter_size; + + private: + // dont use this function, it will be obsolete when + // the filter functions get a better implementation + char isVisible(const unsigned int id); + +}; + +#endif |
