Skip to content

Commit 261cb8b

Browse files
author
Aaron Roller
committed
feat: searching ros install dir for UserConfig.txt AM-367/user-config
1 parent 7391264 commit 261cb8b

3 files changed

Lines changed: 42 additions & 7 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ debian/ros-melodic-am-osdk-ros*
1111
debian/ros-melodic-dji-onboard-sdk-ros.debhelper.log
1212
ros-melodic-dji-onboard-sdk-build-deps_*_all.deb
1313
build
14+
catkin_ws

include/dji_sdk_obsoleted/dji_linux_environment.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ class DJI_Environment
6464
std::string device_acm;
6565
std::string sample_case;
6666

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+
6777
const static unsigned int default_acm_baudrate = 921600;
6878
};
6979

src/dji_sdk_obsoleted/dji_linux_environment.cpp

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,23 @@ DJI_Environment::~DJI_Environment()
4545
std::string
4646
DJI_Environment::findFile(std::string file)
4747
{
48-
char cwd[1024];
49-
std::string configFile;
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";
52+
configFile = findFileInDir(file,installationDir);
53+
}
54+
return configFile;
55+
}
5056

51-
if (getcwd(cwd, sizeof(cwd)) == NULL)
52-
throw std::runtime_error("Error getting current directory");
5357

54-
std::string strCWD(cwd);
55-
// configFile = strCWD + "/osdk-core/" + file;
56-
configFile = strCWD + "/" + file; // just in the current working directory
58+
/**
59+
* @return a string of the path to a file, if found. Empty otherwise.
60+
*/
61+
std::string
62+
DJI_Environment::findFileInDir(std::string file, std::string dir)
63+
{
64+
std::string configFile = dir + "/" + file;
5765

5866
std::ifstream fStream(configFile.c_str());
5967

@@ -63,6 +71,22 @@ DJI_Environment::findFile(std::string file)
6371
return configFile;
6472
}
6573

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+
6690
int
6791
DJI_Environment::getApp_id() const
6892
{

0 commit comments

Comments
 (0)