Skip to content

Commit

Permalink
Make settings.json work again and add documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
lovettchris committed Feb 15, 2017
1 parent fe1b372 commit 1fee584
Show file tree
Hide file tree
Showing 18 changed files with 619 additions and 506 deletions.
2 changes: 2 additions & 0 deletions AirLib/AirLib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<ClInclude Include="include\control\RpcLibServer.hpp" />
<ClInclude Include="include\control\SafetyEval.hpp" />
<ClInclude Include="include\control\DroneControlServer.hpp" />
<ClInclude Include="include\control\Settings.h" />
<ClInclude Include="include\control\SphereGeoFence.hpp" />
<ClInclude Include="include\control\Waiter.hpp" />
<ClInclude Include="include\physics\Environment.hpp" />
Expand Down Expand Up @@ -104,6 +105,7 @@
<ClCompile Include="src\control\RpcLibClient.cpp" />
<ClCompile Include="src\control\RpcLibServer.cpp" />
<ClCompile Include="src\control\SafetyEval.cpp" />
<ClCompile Include="src\control\Settings.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MavLinkCom\MavLinkCom.vcxproj">
Expand Down
6 changes: 6 additions & 0 deletions AirLib/AirLib.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@
<ClInclude Include="include\common\common_utils\AsyncTasker.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\control\Settings.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\control\DroneControlBase.cpp">
Expand All @@ -266,5 +269,8 @@
<ClCompile Include="src\control\MavLinkHelper.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\control\Settings.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
5 changes: 4 additions & 1 deletion AirLib/include/control/MavLinkHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <mutex>
#include <string>
#include <vector>

#include "Settings.h"

namespace msr { namespace airlib {

Expand All @@ -31,6 +31,9 @@ class MavLinkHelper : public ControllerBase
MavLinkHelper();
~MavLinkHelper();

// Load mavlink specific settings from the given Settings file and update the
// Settings with any new settings that the settings file doesn't know about yet.
void loadSettings(Settings& settings);

struct HILConnectionInfo {

Expand Down
54 changes: 54 additions & 0 deletions AirLib/include/control/Settings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#pragma once
#include <string>
#include "common/common_utils/json.hpp"

namespace msr {
namespace airlib {

class Settings
{
private:
static Settings settings_;
std::wstring file_;
nlohmann::json doc_;
static std::wstring getFullPath(std::wstring fileName);
public:
static wchar_t* getProductName() {
return L"AirSim";
}

static Settings& singleton() {
return settings_;
}

static Settings& loadJSonFile(std::wstring fileName);
void saveJSonFile(std::wstring fileName);
std::wstring getFileName() { return file_; }

std::string getString(std::string name, std::string defaultValue = "");
void setString(std::string name, std::string value);

double getDouble(std::string name, double defaultValue = 0);
void setDouble(std::string name, double value);

bool getBool(std::string name, bool defaultValue = false);
void setBool(std::string name, bool value);

int getInt(std::string name, int defaultValue = 0);
void setInt(std::string name, int value);

Settings getChild(std::string name);
void setChild(std::string name, Settings& value);


static std::wstring getUserDocumentsFolder();
static std::wstring ensureAppDataFolder(std::wstring productName);
static std::wstring getUserHomeFolder();
static void createDirectory(std::wstring parentFolder, std::wstring name);

Settings();
~Settings();
};

}
}
40 changes: 39 additions & 1 deletion AirLib/src/control/MavLinkHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,39 @@ struct MavLinkHelper::impl {
long last_gps_time = 0;
bool was_reseted = false;

void loadSettings(Settings& settings)
{
this->SimSysID = static_cast<uint8_t>(settings.getInt("SimSysID", this->SimSysID));
settings.setInt("SimSysID", this->SimSysID);
this->SimCompID = settings.getInt("SimCompID", this->SimCompID);
settings.setInt("SimCompID", this->SimCompID);

this->ExtRendererSysID = static_cast<uint8_t>(settings.getInt("ExtRendererSysID", this->ExtRendererSysID));
settings.setInt("ExtRendererSysID", this->ExtRendererSysID);
this->ExtRendererCompID = settings.getInt("ExtRendererCompID", this->ExtRendererCompID);
settings.setInt("ExtRendererCompID", this->ExtRendererCompID);

this->AirControlSysID = static_cast<uint8_t>(settings.getInt("AirControlSysID", this->AirControlSysID));
settings.setInt("AirControlSysID", this->AirControlSysID);
this->AirControlCompID = settings.getInt("AirControlCompID", this->AirControlCompID);
settings.setInt("AirControlCompID", this->AirControlCompID);

this->LocalHostIp = settings.getString("LocalHostIp", this->LocalHostIp);
settings.setString("LocalHostIp", this->LocalHostIp);
this->ExternalSimPort = settings.getInt("ExternalSimPort", this->ExternalSimPort);
settings.setInt("ExternalSimPort", this->ExternalSimPort);

this->LogViewerPort = settings.getInt("LogViewerPort", this->LogViewerPort);
settings.setInt("LogViewerPort", this->LogViewerPort);
this->LogViewerHostIp = settings.getString("LogViewerHostIp", this->LogViewerHostIp);
settings.setString("LogViewerHostIp", this->LogViewerHostIp);

this->QgcPort = settings.getInt("QgcPort", this->QgcPort);
settings.setInt("QgcPort", this->QgcPort);
this->QgcHostIp = settings.getString("QgcHostIp", this->QgcHostIp);
settings.setString("QgcHostIp", this->QgcHostIp);
}


void normalizeRotorControls()
{
Expand Down Expand Up @@ -118,7 +151,7 @@ struct MavLinkHelper::impl {
test.base_mode = 0;
test.custom_mode = 0;
test.mavlink_version = 3;
node->sendMessage(test);
node->sendMessage(test);
test.system_status = 0;
return true;
}
Expand Down Expand Up @@ -601,6 +634,11 @@ MavLinkHelper::~MavLinkHelper()
pimpl_->close();
}

void MavLinkHelper::loadSettings(Settings& settings)
{
pimpl_->loadSettings(settings);
}

int MavLinkHelper::getRotorControlsCount()
{
return RotorControlsCount;
Expand Down
Loading

0 comments on commit 1fee584

Please sign in to comment.