40 #include <sys/types.h> 51 pnh_(
ros::NodeHandle(
"~")),
53 is_ros_subscriber_(is_ros_subscriber) {
80 ROS_INFO(
"Subscribing to raw data stream.");
85 ROS_INFO(
"Publishing raw data stream.");
90 struct stat stat_info;
91 if (stat(
file_dir_.c_str(), &stat_info ) != 0) {
93 "Directory \"%s\" does not exist.",
file_dir_.c_str());
95 }
else if ((stat_info.st_mode & S_IFDIR) != S_IFDIR) {
97 "\"%s\" exists, but is not a directory.",
file_dir_.c_str());
104 time_t t = time(NULL);
105 struct tm time_struct = *localtime(&t);
108 filename.width(4); filename.fill(
'0');
109 filename << time_struct.tm_year + 1900;
110 filename.width(0); filename <<
'_';
111 filename.width(2); filename.fill(
'0');
112 filename << time_struct.tm_mon + 1;
113 filename.width(0); filename <<
'_';
114 filename.width(2); filename.fill(
'0');
115 filename << time_struct.tm_mday;
116 filename.width(0); filename <<
'_';
117 filename.width(2); filename.fill(
'0');
118 filename << time_struct.tm_hour;
119 filename.width(2); filename.fill(
'0');
120 filename << time_struct.tm_min ;
121 filename.width(0); filename <<
".log";
126 ROS_INFO(
"Logging raw data to file \"%s\"",
128 }
catch(
const std::exception& e) {
130 "Can't create file \"%s\".",
file_name_.c_str());
137 const std::size_t size) {
139 std::string str((
const char*) data, size);
149 const std_msgs::UInt8MultiArray::ConstPtr& msg) {
151 std::string str(msg->data.size(),
' ');
152 std::copy(msg->data.begin(), msg->data.end(), str.begin());
157 const std::string str) {
159 std_msgs::UInt8MultiArray
msg;
161 msg.layout.data_offset = 0;
162 msg.layout.dim.push_back(std_msgs::MultiArrayDimension());
163 msg.layout.dim[0].size = str.length();
164 msg.layout.dim[0].stride = 1;
165 msg.layout.dim[0].label =
"raw_data_stream";
167 msg.data.resize(str.length());
168 std::copy(str.begin(), str.end(), msg.data.begin());
176 pnh_.
advertise<std_msgs::UInt8MultiArray>(
"raw_data_stream", 100);
187 }
catch(
const std::exception& e) {
void publish(const boost::shared_ptr< M > &message) const
void ubloxCallback(const unsigned char *data, const std::size_t size)
Callback function which handles raw data.
void saveToFile(const std::string str)
Stores data to given file.
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
std::string file_dir_
Directoy name for storing raw data.
bool flag_publish_
Flag for publishing raw data.
std_msgs::UInt8MultiArray str2uint8(const std::string str)
Converts a string into an uint8 multibyte array.
ros::NodeHandle nh_
ROS node handle (only for subscriber)
void initialize(void)
Initializes raw data streams If storing to file is enabled, the filename is created and the correspon...
std::ofstream file_handle_
Handle for file access.
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ros::NodeHandle pnh_
ROS private node handle (for params and publisher)
RawDataStreamPa(bool is_ros_subscriber=false)
Constructor. Initialises variables and the nodehandle.
void publishMsg(const std::string str)
Publishes data stream as ros message.
std::string file_name_
Filename for storing raw data.
void msgCallback(const std_msgs::UInt8MultiArray::ConstPtr &msg)
Callback function which handles raw data.
bool isEnabled(void)
Returns the if raw data streaming is enabled.
void getRosParams(void)
Get the raw data stream parameters.