28 #include <boost/date_time.hpp> 30 #include <icl_sourcesink/SimpleURI.h> 41 m_msg_container_size(500),
42 m_commit_timediff(boost::posix_time::seconds(1)),
60 icl_sourcesink::SimpleURI parsed_uri(uri());
63 boost::optional<std::size_t> msg_container_size = parsed_uri.getQuery<std::size_t>(
"container_size");
64 if (msg_container_size)
66 if (msg_container_size > 0)
77 std::string can_filename = parsed_uri.path();
78 if (can_filename.size() < 4 || can_filename.substr(can_filename.size()-4) !=
".can")
80 can_filename +=
".can";
98 if (!msg || ((*msg)->id == 0 && (*msg)->dlc == 0 && (*msg)->rtr == 0))
119 for (std::vector<CanMessageStamped::ConstPtr>::const_iterator iter =
m_msg_container.begin();
123 boost::posix_time::time_duration time_since_epoch
124 = (*iter)->header().timestamp - boost::posix_time::from_time_t(0);
125 uint64_t seconds = time_since_epoch.ticks() / boost::posix_time::time_duration::ticks_per_second();
126 long microseconds = time_since_epoch.fractional_seconds() / (boost::posix_time::time_duration::ticks_per_second() / 1000000);
127 m_data_file << std::dec << seconds <<
"." << std::setw(6) << microseconds
128 <<
" " << (**iter)->id <<
" " << unsigned((**iter)->dlc)
130 <<
" " << std::setw(2) << unsigned((**iter)->data[0])
131 <<
" " << std::setw(2) << unsigned((**iter)->data[1])
132 <<
" " << std::setw(2) << unsigned((**iter)->data[2])
133 <<
" " << std::setw(2) << unsigned((**iter)->data[3])
134 <<
" " << std::setw(2) << unsigned((**iter)->data[4])
135 <<
" " << std::setw(2) << unsigned((**iter)->data[5])
136 <<
" " << std::setw(2) << unsigned((**iter)->data[6])
137 <<
" " << std::setw(2) << unsigned((**iter)->data[7])
icl_sourcesink::DataSink< tCanMessage > HardwareCanSink
Base type for all sinks providing tCanMessage data.
Contains icl_hardware::tException.
std::vector< CanMessageStamped::ConstPtr > m_msg_container
std::size_t m_msg_container_size
HardwareCanSinkCanfile(const std::string &uri="HardwareCanSinkCanfile", const std::string &name="UnnamedHardwareCanSinkCanfile")
Constructor.
boost::posix_time::ptime m_last_msg_time
Timestamp of the last processed message.
std::ofstream m_data_file
CAN data file stream.
boost::shared_ptr< Stamped< DataType > > Ptr
#define LOGGING_ERROR(streamname, arg)
unsigned __int64 uint64_t
static const short cMAJOR_FILEVERSION
Major version number of the file format.
ThreadStream & endl(ThreadStream &stream)
#define LOGGING_WARNING(streamname, arg)
static const short cMINOR_FILEVERSION
Minor version number of the file format.
boost::posix_time::time_duration m_commit_timediff
boost::posix_time::ptime m_last_commit_time
Time at which the last message was committed to disk.
bool prepareFile()
Opens the output file and writes the file header.
virtual void set(const CanMessageStamped::Ptr &msg)
virtual ~HardwareCanSinkCanfile()
Destructor.