Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //! @brief Get logfile name published by GUI and open file to write.
- bool serviceCallback(atrias_controllers::data_subscriber_srv::Request& req, atrias_controllers::data_subscriber_srv::Response& res) {
- if (req.isLogging) {
- ROS_INFO("logging");
- char buffer[256]; // Create buffer to store filename.
- if (req.logfilename == "") { // If filename is unspecified, set one based on date and time.
- time_t curSeconds;
- curSeconds = time(NULL);
- struct tm *tInfo;
- tInfo = localtime(&curSeconds);
- sprintf(buffer, "%s/atrias_%0.2d%0.2d%0.2d_%0.2d%0.2d%0.2d.log", "/home/drl/atrias/drl-sim/atrias/log_files", tInfo->tm_year%100, tInfo->tm_mon+1, tInfo->tm_mday, tInfo->tm_hour, tInfo->tm_min, tInfo->tm_sec);
- }
- else { // If filename is specified, use that as logfilename.
- sprintf(buffer, "%s", req.logfilename.c_str());
- }
- log_file_fp = fopen(buffer, "w"); // Open logfile.
- fprintf(log_file_fp, "-"); // Make sure the file exists.
- ROS_INFO("data_subscriber opened logfile at %s", buffer);
- res.logfilename = buffer; // Respond with new logfilename.
- isLogging = true; // data_subscriber should start logging.
- }
- else if (!req.isLogging) {
- ROS_INFO("not logging");
- if (log_file_fp != NULL) { // Check if logfile is open because serviceCallback could be run if logfilename is set but isLogging is off.
- fclose(log_file_fp);
- ROS_INFO("data_subscriber closed logfile.");
- }
- res.logfilename = ""; // Respond with blank logfilename.
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement