Changeset 83 in flair-src


Ignore:
Timestamp:
Sep 21, 2016, 5:49:17 PM (8 years ago)
Author:
Thomas Fuhrmann
Message:

Cahnge the parsing of parameters

Location:
branches/mavlink/tools/Controller/Mavlink/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/mavlink/tools/Controller/Mavlink/src/GuiGcs.cpp

    r82 r83  
    2727#include <ListWidget.h>
    2828
    29 //todo remove for tests
    3029#include <iostream>
     30#include <array>
    3131
    3232using namespace std;
    3333using namespace flair::core;
    3434using namespace flair::gui;
     35
     36const std::string delimiter = "|";
    3537
    3638GuiGcs::GuiGcs(const FrameworkManager *parent, string name,
     
    7476void GuiGcs::MissionStop() {
    7577  cout << "MavPlanner GuiGcs MissionStop" << endl;
    76   outputSocket->SendMessage("MavPlanner GuiGcs MissionStop");
    7778}
    7879
    7980void GuiGcs::MissionResume() {
    8081  cout << "MavPlanner GuiGcs MissionResume" << endl;
    81   outputSocket->SendMessage("MavPlanner GuiGcs MissionResume");
    8282}
    8383
     
    103103  // sending mission items
    104104  cout << "[INFO] Mission items.\n";
    105   std::string delimiter = "|";
    106105  for (auto &missionCommand : missionCommandList) {
    107106    cout << "[INFO] Mission item : " << missionCommand << "\n";
     
    109108    std::string command = missionCommand.substr(0, missionCommand.find(delimiter));
    110109    missionCommand.erase(0, missionCommand.find(delimiter) + delimiter.length());
    111     // Parse param1
    112     float param1 = std::stof(missionCommand.substr(0, missionCommand.find(delimiter)));
    113     missionCommand.erase(0, missionCommand.find(delimiter) + delimiter.length());
    114     // Parse param2
    115     float param2 = std::stof(missionCommand.substr(0, missionCommand.find(delimiter)));
    116     missionCommand.erase(0, missionCommand.find(delimiter) + delimiter.length());
    117     // Parse param3
    118     float param3 = std::stof(missionCommand.substr(0, missionCommand.find(delimiter)));
    119     missionCommand.erase(0, missionCommand.find(delimiter) + delimiter.length());
    120     // Parse latitude
    121     float latitude = std::stof(missionCommand.substr(0, missionCommand.find(delimiter)));
    122     missionCommand.erase(0, missionCommand.find(delimiter) + delimiter.length());
    123     // Parse longitude
    124     float longitude = std::stof(missionCommand.substr(0, missionCommand.find(delimiter)));
    125     missionCommand.erase(0, missionCommand.find(delimiter) + delimiter.length());
    126     // Parse altitude
    127     float altitude = std::stof(missionCommand.substr(0, missionCommand.find(delimiter)));
    128     missionCommand.erase(0, missionCommand.find(delimiter) + delimiter.length());
    129     // cout << "[INFO] Mission item commands : " << command << ", " << param1 << ", " << param2 << ", " << param3 << std::endl;
    130     mavCom->sendMissionItem(mavCom->target.getSysID(), mavCom->target.getCompID(), 0, MAV_FRAME_GLOBAL_RELATIVE_ALT, MavCommandGet(command), 0, 1, param1, param2, param3, 0, latitude, longitude, altitude);
     110    std::array<float, 6> missionParameters;
     111    ParametersParse(missionCommand, missionParameters);
     112
     113    mavCom->sendMissionItem(mavCom->target.getSysID(), mavCom->target.getCompID(), 0, MAV_FRAME_GLOBAL_RELATIVE_ALT, MavCommandGet(command), 0, 1,
     114            missionParameters[0], missionParameters[1], missionParameters[2], 0, missionParameters[3], missionParameters[4], missionParameters[5]);
    131115    mavCom->waitMissionAck(ACK_TIMEOUT);
    132116  }
     
    142126}
    143127
     128void GuiGcs::ParametersParse(const std::string& parametersString, std::array<float, 6>& parametersFloat) {
     129  std::string parametersBuffer = parametersString;
     130  for (int count = 0; count < parametersFloat.size(); count++) {
     131    parametersFloat[count] = std::stof(parametersBuffer.substr(0, parametersBuffer.find(delimiter)));
     132    parametersBuffer.erase(0, parametersBuffer.find(delimiter) + delimiter.length());
     133  }
     134}
     135
    144136uint16_t GuiGcs::MavCommandGet(const std::string& command) const {
    145137  uint16_t returnValue = -1;
  • branches/mavlink/tools/Controller/Mavlink/src/GuiGcs.h

    r82 r83  
    2121
    2222#include <string>
     23#include <array>
    2324
    2425#include "GuiInterface.h"
     
    5354
    5455private:
    55   flair::core::Socket *outputSocket;
    5656  std::string outputAddress;
    5757  int outputPort;
     
    6060
    6161  void Initialize();
     62  void ParametersParse(const std::string& parametersString, std::array<float, 6>& parametersFloat);
    6263};
    6364
Note: See TracChangeset for help on using the changeset viewer.