Skip to content

Commit f185882

Browse files
author
Aaron Roller
committed
looking for file from appropriate source AM-367/user-config
1 parent 1acf98d commit f185882

3 files changed

Lines changed: 22 additions & 35 deletions

File tree

include/dji_sdk_obsoleted/dji_linux_environment.hpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ class DJI_Environment
4343
~DJI_Environment();
4444

4545
static std::string findFile(std::string file);
46+
/**
47+
* @return a string of the path to a file, if found. Empty otherwise.
48+
*/
49+
static std::string findFileInDir(std::string file, std::string dir);
50+
4651
int getApp_id() const;
4752
const std::string& getEnc_key() const;
4853
const std::string& getDevice() const;
@@ -64,16 +69,6 @@ class DJI_Environment
6469
std::string device_acm;
6570
std::string sample_case;
6671

67-
/**
68-
* @return a string of the path to a file in the working dir, if found. Empty otherwise.
69-
*/
70-
static std::string findFileInCwd(std::string file);
71-
72-
/**
73-
* @return a string of the path to a file, if found. Empty otherwise.
74-
*/
75-
static std::string findFileInDir(std::string file, std::string dir);
76-
7772
const static unsigned int default_acm_baudrate = 921600;
7873
};
7974

src/dji_sdk_obsoleted/dji_linux_environment.cpp

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ DJI_Environment::~DJI_Environment()
4545
std::string
4646
DJI_Environment::findFile(std::string file)
4747
{
48-
std::string configFile = findFileInCwd(file);
49-
if(configFile.empty()){
50-
//FIXME: find a better place to declare this
51-
std::string installationDir = "/opt/ros/melodic/share/dji_sdk/launch";
52-
configFile = findFileInDir(file,installationDir);
53-
}
54-
return configFile;
48+
char cwd[1024];
49+
std::string configFile;
50+
51+
if (getcwd(cwd, sizeof(cwd)) == NULL)
52+
throw std::runtime_error("Error getting current directory");
53+
54+
std::string strCWD(cwd);
55+
return findFileInDir(file,strCWD);
5556
}
5657

5758

@@ -71,22 +72,6 @@ DJI_Environment::findFileInDir(std::string file, std::string dir)
7172
return configFile;
7273
}
7374

74-
/**
75-
* @return a string of the path to a file in the working dir, if found. Empty otherwise.
76-
*/
77-
std::string
78-
DJI_Environment::findFileInCwd(std::string file)
79-
{
80-
char cwd[1024];
81-
std::string configFile;
82-
83-
if (getcwd(cwd, sizeof(cwd)) == NULL)
84-
throw std::runtime_error("Error getting current directory");
85-
86-
std::string strCWD(cwd);
87-
return findFileInDir(file,strCWD);
88-
}
89-
9075
int
9176
DJI_Environment::getApp_id() const
9277
{

src/dji_sdk_obsoleted/dji_linux_helpers.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,15 @@ LinuxSetup::setupEnvironment(int argc, char** argv)
170170
}
171171
else
172172
{
173-
config_file_path = DJI_Environment::findFile("UserConfig.txt");
174-
173+
std::string config_filename = "UserConfig.txt";
174+
config_file_path = DJI_Environment::findFile(config_filename);
175+
176+
//look in installation dir if not found in expected places
177+
if(config_file_path.empty()){
178+
//FIXME: find a better place to declare this without ros distro (melodic)
179+
std::string installationDir = "/opt/ros/melodic/share/dji_sdk/launch";
180+
config_file_path = DJI_Environment::findFileInDir(config_filename,installationDir);
181+
}
175182
if (config_file_path.empty())
176183
throw std::runtime_error("User configuration file not found");
177184
}

0 commit comments

Comments
 (0)