Skip to content

Commit 7e5fea9

Browse files
committed
Added checks to make sure that rpi_apps.yaml file exists as well as the imx296_noir.yaml file. .
1 parent cbca1ae commit 7e5fea9

File tree

2 files changed

+51
-20
lines changed

2 files changed

+51
-20
lines changed

Software/LMSourceCode/ImageProcessing/core/rpicam_app.cpp

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include <cmath>
1515
#include <fcntl.h>
16+
#include <fstream>
1617
#include <stdlib.h>
1718

1819
#include <sys/ioctl.h>
@@ -25,6 +26,7 @@
2526
#include <libcamera/orientation.h>
2627

2728
#include "logging_tools.h"
29+
#include "gs_config.h"
2830

2931

3032
unsigned int RPiCamApp::verbosity = 1;
@@ -53,34 +55,52 @@ static libcamera::PixelFormat mode_to_pixel_format(Mode const &mode)
5355
return libcamera::formats::SBGGR12_CSI2P;
5456
}
5557

56-
static void set_pipeline_configuration(Platform platform)
58+
static bool set_pipeline_configuration(Platform platform)
5759
{
5860
GS_LOG_TRACE_MSG(trace, "set_pipeline_configuration called for platform: " + std::to_string((int)platform));
5961

62+
bool found_valid_file = false;
63+
std::string configure_file_name;
64+
6065
// Respect any pre-existing value in the environment variable.
61-
char const *existing_config = getenv("LIBCAMERA_RPI_CONFIG_FILE");
62-
if (existing_config && existing_config[0])
63-
return;
66+
std::string existing_config = golf_sim::GolfSimConfiguration::safe_getenv("LIBCAMERA_RPI_CONFIG_FILE");
67+
if (!existing_config.empty()) {
68+
found_valid_file = true;
69+
configure_file_name = existing_config;
70+
}
6471

65-
// Otherwise point it at whichever of these we find first (if any) for the given platform.
66-
static const std::vector<std::pair<Platform, std::string>> config_files = {
67-
{ Platform::VC4, "/usr/local/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml" },
68-
{ Platform::VC4, "/usr/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml" },
69-
{ Platform::PISP, "/usr/local/share/libcamera/pipeline/rpi/pisp/rpi_apps.yaml" },
70-
{ Platform::PISP, "/usr/share/libcamera/pipeline/rpi/pisp/rpi_apps.yaml" },
71-
};
72+
if (!found_valid_file) {
73+
// Otherwise point it at whichever of these we find first (if any) for the given platform.
74+
static const std::vector<std::pair<Platform, std::string>> config_files = {
75+
{ Platform::VC4, "/usr/local/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml" },
76+
{ Platform::VC4, "/usr/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml" },
77+
{ Platform::PISP, "/usr/local/share/libcamera/pipeline/rpi/pisp/rpi_apps.yaml" },
78+
{ Platform::PISP, "/usr/share/libcamera/pipeline/rpi/pisp/rpi_apps.yaml" },
79+
};
7280

73-
for (auto &config_file : config_files)
74-
{
75-
struct stat info;
76-
if (config_file.first == platform && stat(config_file.second.c_str(), &info) == 0)
81+
for (auto& config_file : config_files)
7782
{
78-
GS_LOG_TRACE_MSG(trace, "set_pipeline_configuration setting yaml pipeline file to : " + config_file.second);
83+
struct stat info;
84+
if (config_file.first == platform && stat(config_file.second.c_str(), &info) == 0)
85+
{
86+
GS_LOG_TRACE_MSG(trace, "set_pipeline_configuration setting yaml pipeline file to : " + config_file.second);
7987

80-
setenv("LIBCAMERA_RPI_CONFIG_FILE", config_file.second.c_str(), 1);
81-
break;
88+
configure_file_name = config_file.second;
89+
setenv("LIBCAMERA_RPI_CONFIG_FILE", config_file.second.c_str(), 1);
90+
break;
91+
}
8292
}
8393
}
94+
95+
// Make sure the environment actually has the file available
96+
std::ifstream file(configure_file_name);
97+
if (!file.good()) {
98+
GS_LOG_MSG(error, "set_pipeline_configuration failed to open file: " + configure_file_name);
99+
GS_LOG_MSG(error, "If necessary, find the example.yaml file, copy it to the expected file name, and ensure the timeout value is set correctly.");
100+
return false;
101+
}
102+
103+
return true;
84104
}
85105

86106
RPiCamApp::RPiCamApp(std::unique_ptr<Options> opts)
@@ -105,7 +125,10 @@ RPiCamApp::RPiCamApp(std::unique_ptr<Options> opts)
105125
exit(-1);
106126
}
107127

108-
set_pipeline_configuration(platform);
128+
if (!set_pipeline_configuration(platform)) {
129+
fprintf(stderr, "ERROR: failed to set the libcamera pipeline configuration. Exiting Program.\n");
130+
exit(-1);
131+
}
109132
}
110133

111134
RPiCamApp::~RPiCamApp()

Software/LMSourceCode/ImageProcessing/libcamera_interface.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#include <chrono>
1818

19-
19+
#include <fstream>
2020
#include <opencv2/calib3d/calib3d.hpp>
2121

2222
// TBD - May need to be before ball_watcher, as there is a mman.h conflict
@@ -1079,6 +1079,14 @@ bool SetLibcameraTuningFileEnvVariable(const GolfSimCamera& camera) {
10791079
}
10801080
}
10811081

1082+
// Make sure the environment actually has the file available
1083+
std::ifstream file(tuning_file);
1084+
if (!file.good()) {
1085+
GS_LOG_MSG(error, "SetLibcameraTuningFileEnvVariable failed to open file: " + tuning_file);
1086+
GS_LOG_MSG(error, "If necessary, find the example file (e.g., imx296_noir.json.PI_5_FOR_PISP_DIRECTORY), and copy it to the expected file name.");
1087+
return false;
1088+
}
1089+
10821090
setenv("LIBCAMERA_RPI_TUNING_FILE", tuning_file.c_str(), 1);
10831091
GS_LOG_TRACE_MSG(trace, "LIBCAMERA_RPI_TUNING_FILE set to: " + tuning_file);
10841092

0 commit comments

Comments
 (0)