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 #include <labust/tritech/MTDevice.hpp>
00038 #include <labust/tritech/mtMessages.hpp>
00039 #include <labust/tritech/USBLMessages.hpp>
00040 #include <labust/tritech/DiverMsg_adv.hpp>
00041
00042 #include <std_msgs/String.h>
00043 #include <ros/ros.h>
00044
00045 #include <boost/bind.hpp>
00046 #include <boost/archive/binary_iarchive.hpp>
00047 #include <boost/archive/binary_oarchive.hpp>
00048
00049 void onMsg(labust::tritech::MTDevice* modem, const std_msgs::String::ConstPtr msg)
00050 {
00051 using namespace labust::tritech;
00052
00053 MTMsgPtr tmsg(new MTMsg());
00054 tmsg->txNode = 255;
00055 tmsg->rxNode = labust::tritech::Nodes::SlaveModem;
00056 tmsg->node = labust::tritech::Nodes::SlaveModem;
00057 tmsg->msgType = MTMsg::mtMiniModemCmd;
00058
00059 MMCMsg mmsg;
00060 mmsg.msgType = labust::tritech::mmcSetRepBits;
00061
00062 switch (msg->data.size())
00063 {
00064 case 0: mmsg.data[0] = 0; break;
00065 case 1: mmsg.data[0] = 8; break;
00066 case 2: mmsg.data[0] = 16; break;
00067 case 3: mmsg.data[0] = 24; break;
00068 case 4: mmsg.data[0] = 32; break;
00069 case 5: mmsg.data[0] = 40; break;
00070 case 6: mmsg.data[0] = 48; break;
00071 default:break;
00072 }
00073
00074 for (int i=0;i<6;++i) mmsg.data[i+1] = msg->data[i];
00075
00076 std::ostream out();
00077 boost::archive::binary_oarchive ar(*tmsg->data, boost::archive::no_header);
00078 ar<<mmsg;
00079
00080 modem->send(tmsg);
00081
00082 std::cout<<"send message."<<std::endl;
00083 };
00084
00085 void onData(ros::Publisher* modemOut, labust::tritech::MTMsgPtr tmsg)
00086 {
00087 using namespace labust::tritech;
00088
00089
00090 boost::archive::binary_iarchive dataSer(*tmsg->data, boost::archive::no_header);
00091 MMCMsg data;
00092 dataSer>>data;
00093
00094
00095
00096
00097 ROS_INFO("Received USBL message type %d. Bits=%d",data.msgType);
00098
00099 std::cout<<"Received datammcRangedRepByte package:";
00100 for (int i=0; i<data.data.size(); ++i)
00101 {
00102 std::cout<<int(data.data[i])<<",";
00103 }
00104 std::cout<<std::endl;
00105
00106 std_msgs::String modem;
00107 modem.data.assign(data.data.begin(), data.data.end());
00108 modemOut->publish(modem);
00109 }
00110
00111 int main(int argc, char* argv[])
00112 {
00113 using namespace labust::tritech;
00114
00115 ros::init(argc,argv,"modem_node");
00116
00117 ros::NodeHandle nh,ph("~");
00118
00119 std::string port("/dev/ttyUSB9");
00120 int baud(57600);
00121
00122 ph.param("port",port,port);
00123 ph.param("baud",baud,baud);
00124
00125 MTDevice modem(port,baud);
00126
00127 ros::Subscriber inMsg = nh.subscribe<std_msgs::String>(
00128 "modem_send", 1,boost::bind(&onMsg,&modem,_1));
00129 ros::Publisher pub = nh.advertise<std_msgs::String>("modem_rcvd", 1);
00130
00131 MTDevice::HandlerMap map;
00132 map[MTMsg::mtMiniModemData] = boost::bind(&onData,&pub, _1);
00133 modem.registerHandlers(map);
00134
00135 ros::spin();
00136
00137 return 0;
00138 }
00139
00140
00141