34 #include <boost/date_time/posix_time/posix_time.hpp> 35 #include <boost/filesystem/operations.hpp> 36 #include <boost/filesystem/fstream.hpp> 41 #include <icl_core_thread/Thread.h> 46 #include <icl_sourcesink/SimpleURI.h> 145 msg->header().timestamp = boost::posix_time::microsec_clock::local_time();
146 msg->header().dsin =
m_dsin++;
150 msg->header().coordinate_system =
"";
159 -
m_recv_buffer.back()->header().timestamp).total_microseconds()
203 icl_sourcesink::SimpleURI parsed_uri(uri);
206 boost::optional<uint32_t> uri_baudrate = parsed_uri.getQuery<
uint32_t>(
"baudrate");
209 can_baudrate = *uri_baudrate;
213 boost::optional<uint32_t> uri_buffer_size = parsed_uri.getQuery<
uint32_t>(
"buffer_size");
216 can_buffer_size = *uri_buffer_size;
220 boost::optional<uint16_t> uri_can_id = parsed_uri.getQuery<
uint16_t>(
"can_id");
223 if (*uri_can_id > 2047)
225 LOGGING_ERROR(CAN,
"Illegal value for 'can_id' (must be <= 2047). Ignoring." <<
endl);
229 can_id = *uri_can_id;
233 std::string can_mask =
"";
234 boost::optional<std::string> uri_can_mask = parsed_uri.getQuery<std::string>(
"can_mask");
237 can_mask = *uri_can_mask;
241 can_mask = icl_core::config::getDefault<std::string>(
"/icl_hardware_can/can_mask",
"");
247 LOGGING_DEBUG(CAN,
"Opening CAN device... " <<
endl);
251 parsed_uri.path().c_str(),
263 LOGGING_DEBUG(CAN,
"CAN device successfully initialized." <<
endl);
276 LOGGING_DEBUG(CAN,
"Using single CAN ID: " << can_id <<
endl);
279 else if (can_mask !=
"")
285 LOGGING_DEBUG(CAN,
"Using CAN Mask: " << can_mask <<
endl);
void setSingleCanID(uint16_t can_id)
Sets a single CAN ID used to filter out relevant CAN messages.
bool hasData() const
Returns true if the buffer is nonempty.
icl_sourcesink::DataSource< tCanMessage > HardwareCanSource
Base type for all sources providing tCanMessage data.
Contains icl_hardware::tException.
#define LOGGING_DEBUG(streamname, arg)
std::size_t m_max_buffer_size
Buffer size limit.
HardwareCanSourcePeak(const std::string &uri="", const std::string &name="HardwareCanSourcePeak")
Constructor.
CanMessageStamped::Ptr get()
static tCanDevice * Create(const char *device_name, int flags, unsigned char acceptance_code, unsigned char acceptance_mask, unsigned int baud_rate, unsigned send_fifo_size, unsigned receive_fifo_size)
bool advance()
Advance to the next data element.
boost::shared_ptr< Stamped< DataType > > Ptr
CanMessageStamped::Ptr m_buffer
Buffers the latest data element.
#define LOGGING_ERROR(streamname, arg)
static void CheckLXRTInterface()
Thread(const icl_core::String &description, icl_core::ThreadPriority priority=0)
ThreadStream & endl(ThreadStream &stream)
icl_core::thread::Semaphore m_buffer_semaphore
Handles producer/consumer notification.
boost::scoped_ptr< tCanDevice > m_can_device
The CAN device.
boost::scoped_ptr< tCanDevice > & canDevice()
Access the CAN device.
boost::scoped_ptr< WorkerThread > m_worker_thread
virtual void run()
Worker thread main method which receives the CAN messages.
#define LOGGING_WARNING(streamname, arg)
icl_core::thread::Mutex m_buffer_mutex
Synchronizes receive buffer access.
std::deque< CanMessageStamped::Ptr > m_recv_buffer
std::size_t m_sequence_number
void setCanMask(const CanMatrix &can_mask)
Sets the CAN mask used to filter out relevant CAN messages.
WorkerThread(tCanDevice *can_device, std::size_t max_buffer_size=256)
bool m_use_can_mask
If true, m_can_mask is used to filter the CAN stream.
const CanMatrix & getCanMatrix() const
std::map< unsigned int, std::vector< CanMatrixElement > > CanMatrix
const bool isActive() const
int usleep(unsigned long useconds)