Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
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
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
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
00307 #endif
00308
00309
00310