28 #include <boost/date_time/posix_time/posix_time.hpp> 32 #include <icl_sourcesink/SimpleURI.h> 40 m_can_id_distribution(1, 2047),
41 m_data_distribution(0, 255),
47 icl_sourcesink::SimpleURI parsed_uri(uri);
48 boost::optional<float> rate = parsed_uri.getQuery<
float>(
"rate");
54 boost::optional<std::string> pattern = parsed_uri.getQuery<std::string>(
"pattern");
57 if (*pattern ==
"Fixed")
61 else if (*pattern ==
"ChangingRandom")
65 else if (*pattern ==
"ChangingWithRepeat")
69 else if (*pattern ==
"Linear")
76 "Unknown pattern '" << *pattern <<
"', falling back to Linear." <<
endl);
83 boost::optional<uint16_t> id_value = parsed_uri.getQuery<
uint16_t>(
"id_value");
86 if (*id_value > 0 && *id_value < 2048)
93 "ID value " << *id_value <<
", out of range, starting at " <<
m_next_id <<
"." <<
endl);
114 boost::posix_time::microsec_clock::local_time(),
119 (*m_buffer)->rtr = 0;
120 (*m_buffer)->dlc = 8;
121 for (std::size_t i = 0; i < 8; ++i)
147 unsigned int factor(33), offset(54);
bool advance()
Advance to the next data element.
Pattern m_pattern
The message generation pattern.
boost::random::uniform_int_distribution< unsigned int > m_can_id_distribution
Uniform distribution over possible CAN IDs.
icl_sourcesink::DataSource< tCanMessage > HardwareCanSource
Base type for all sources providing tCanMessage data.
uint16_t m_next_id
The next CAN message ID to be used.
HardwareCanSourceTest(const std::string &uri="", const std::string &name="HardwareCanSourceTest")
Constructor.
float m_rate
Data generation rate in Hz.
#define LOGGING_WARNING_C(streamname, classname, arg)
int usleep(unsigned long useconds)
ThreadStream & endl(ThreadStream &stream)
CanMessageStamped::Ptr m_buffer
Buffers the latest generated message.
boost::random::uniform_int_distribution< uint8_t > m_data_distribution
Uniform distribution over possible payload bytes.
icl_core::Stamped< tCanMessage > CanMessageStamped
unsigned int createCanMessageId()
The IDs are created by a function, IDs can repeat.
The IDs will be created randomly (seed is fixed).
icl_hardware::can::tCanMessage tCanMessage
boost::random::mt19937 m_rng
Random number generator.
A fixed ID is sent at all times.