You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
1.6 KiB
C++
75 lines
1.6 KiB
C++
|
4 years ago
|
#include"class_model/requestData.h"
|
||
|
|
#include <cstdlib>
|
||
|
|
#include <iostream>
|
||
|
|
|
||
|
|
global_location leader_position;
|
||
|
|
|
||
|
|
RequestClass::RequestClass() : node_handle_(""){
|
||
|
|
|
||
|
|
mqtt_data = node_handle_.subscribe("/uav_message", 10,
|
||
|
|
&RequestClass::Data_callback, this);
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
RequestClass::~RequestClass() { ros::shutdown(); }
|
||
|
|
|
||
|
|
void RequestClass::Data_callback(const std_msgs::String::ConstPtr &sensor) {
|
||
|
|
|
||
|
|
std::string data = sensor->data;
|
||
|
|
jsonToInt(data);
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
global_location RequestClass::get_leader_GPS(){
|
||
|
|
|
||
|
|
return leader_position;
|
||
|
|
}
|
||
|
|
|
||
|
|
float RequestClass::get_leader_heading(){
|
||
|
|
|
||
|
|
return heading;
|
||
|
|
}
|
||
|
|
|
||
|
|
void RequestClass::jsonToInt(std::string data){
|
||
|
|
|
||
|
|
std::string lat,lon,degree;
|
||
|
|
std::string list[5]={"","","","",""};
|
||
|
|
int j = 0;
|
||
|
|
|
||
|
|
// lat.append(data,9,10);
|
||
|
|
// lon.append(data,29,10);
|
||
|
|
// degree.append(data,53,6);
|
||
|
|
|
||
|
|
// heading = std::stoi(degree);
|
||
|
|
// leader_position.lat=std::stoi(lat);
|
||
|
|
// leader_position.lon=std::stoi(lon);
|
||
|
|
|
||
|
|
for(int i=0;i<data.length();i++){
|
||
|
|
if(data[i] == ':'){
|
||
|
|
i+=3;
|
||
|
|
while(data[i] != ','){
|
||
|
|
list[j]=list[j]+data[i];
|
||
|
|
i++;
|
||
|
|
if(data[i] == ',' || data[i] == '}'){
|
||
|
|
j++;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
if(j>3){
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
leader_position.lat=std::stoi(list[0]);
|
||
|
|
leader_position.lon=std::stoi(list[1]);
|
||
|
|
leader_position.alt=std::stoi(list[2]);
|
||
|
|
heading = std::stoi(list[3]);
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
// std::cout<<sizeof(data)<<std::endl;
|
||
|
|
//std::cout<<data<<std::endl;
|
||
|
|
// ROS_INFO("leader_GPS [%f,%f]", leader_position.lat, leader_position.lon);
|
||
|
|
// ROS_INFO("leader_heading: %f",heading);
|
||
|
|
}
|