USBLManager.hpp
Go to the documentation of this file.
00001 /*********************************************************************
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2010, LABUST, UNIZG-FER
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of the LABUST nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *
00034  *  Author: Dula Nad
00035  *  Created: 02.04.2013.
00036  *********************************************************************/
00037 #ifndef USBLMANAGER_HPP_
00038 #define USBLMANAGER_HPP_
00039 #include <labust/tritech/DiverMsg.hpp>
00040 
00041 #include <nodelet/nodelet.h>
00042 #include <auv_msgs/NavSts.h>
00043 #include <std_msgs/String.h>
00044 #include <std_msgs/Bool.h>
00045 #include <std_msgs/Int32.h>
00046 #include <std_msgs/Float64MultiArray.h>
00047 #include <ros/ros.h>
00048 
00049 #include <boost/thread.hpp>
00050 #include <boost/function.hpp>
00051 
00052 #include <string>
00053 #include <queue>
00054 #include <map>
00055 #include <ctype.h>
00056 
00057 namespace labust
00058 {
00059         namespace tritech
00060         {
00062                 struct AsciiInternal
00063                 {
00064                         enum {digit_diff=48, alpha_diff=55};
00065                         enum {alpha_limit_int=36, digit_limit_int=10};
00066                         enum {char_size = 6};
00067                         enum {point=36, 
00068                               comma, 
00069                               question_mark, 
00070                               exclamation_mark, 
00071                               space, 
00072                               newline = 62, 
00073                               zero_char};
00077                         static char ascii2Int(char c)
00078                         {
00079                                 if (isalpha(c)) return (toupper(c)-alpha_diff);
00080                                 if (isdigit(c)) return (c-digit_diff);
00081                                 if (c == '.') return (point);
00082                                 if (c == ',') return (comma);
00083                                 if (c == '?') return (question_mark);
00084                                 if (c == '!') return (exclamation_mark);
00085                                 if (c == ' ') return (space);
00086                                 if (c == '\n') return (newline);
00087                                 return zero_char;
00088                         }
00092                         static char int2Ascii(char c)
00093                         {
00094                                 if (c<digit_limit_int) return (c+digit_diff);
00095                                 if (c<alpha_limit_int) return (c+alpha_diff);
00096                                 if (c == point) return '.';
00097                                 if (c == comma) return ',';
00098                                 if (c == question_mark) return '?';
00099                                 if (c == exclamation_mark) return '!';
00100                                 if (c == space) return ' ';
00101                                 if (c == newline) return '\n';
00102                                 return 0;
00103                         }
00104                 };
00105 
00113                 class USBLManager : public nodelet::Nodelet
00114                 {
00118                         enum {idle=0,initDiver,waitForReply,transmission, lastStateNum};
00119                         enum {kmlNotSent=0, kmlSent, kmlWaitValidation, kmlSentAndValid};
00120                         //enum {kmlNotSent=0, kmlSent, kmlWaitValidation, kmlSentAndValid};
00121                 public:
00125                         USBLManager();
00129                         ~USBLManager();
00130 
00134                         void onInit();
00138                         inline void changeState(int next)
00139                         {
00140                                 lastState = state;
00141                                 state = next;
00142                                 NODELET_INFO("Change state: %d -> %d",lastState,next);
00143                         }
00144 
00145                 protected:
00149                         void onNavMsg(const auv_msgs::NavSts::ConstPtr nav);
00153                         void onIncomingMsg(const std_msgs::String::ConstPtr msg);
00157                         void onIncomingText(const std_msgs::String::ConstPtr msg);
00161                         void onUSBLTimeout(const std_msgs::Bool::ConstPtr msg);
00165                         void onIncomingDefaults(const std_msgs::Int32::ConstPtr msg);
00169                         void onIncomingKML(const std_msgs::Float64MultiArray::ConstPtr msg);
00173                         void onIncomingForceState(const std_msgs::Int32::ConstPtr msg);
00174 
00178                         void run();
00179 
00183                         void init_diver();
00187                         void send_msg();
00191                         void incoming_def_txt();
00195                         void incoming_kml();
00196 
00200                         void kml_send();
00201 
00205                         int msgToInt(int len);
00209                         std::string intToMsg(int len);
00213                         void resendLastPackage();
00217                         void publishDiverOrigin();
00218 
00222                         ros::Publisher outgoing, auto_mode, diverText,
00223                         diverDefaults, retKml, diverOrigin, outCurState;
00227                         ros::Subscriber navData, incoming, intext,
00228                         timeoutNotification, inDefaults, inKml, forceState;
00232                         //DiverMsg encoder;
00236                         boost::thread worker;
00240                         int state, lastState;
00244                         bool validNav;
00248                         DiverMsg outgoing_msg, incoming_msg;
00252                         std_msgs::String outgoing_package, incoming_package;
00256                         std::queue<char> textBuffer;
00260                         std::queue<char> defaultMsgs;
00264                         std::queue< std::pair<double, double> > kmlBuffer;
00268                         std::vector< std::pair<int, int> > kmlVec;
00272                         std::vector<int> kmlValidIdx;
00277                         std::pair<int, int> kmlEndValidation;
00281                         int initValidation;
00285                         bool newMessage;
00289                         std::map<int, boost::function<void(void)> > dispatch;
00293                         int timeout, emptyIterations;
00297                         double diverOriginLat, diverOriginLon;
00301                         int lastKmlIdxSent;
00302                 };
00303         }
00304 }
00305 
00306 /* USBLMANAGER_HPP_ */
00307 #endif
00308 
00309 
00310 


usbl_comms
Author(s): Gyula Nagy
autogenerated on Fri Feb 7 2014 11:36:13