mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-02-05 07:28:29 -04:00
TerrainIO: Support custom_terrain_directory
This commit is contained in:
parent
c06abeb02e
commit
f592981a60
@ -151,19 +151,45 @@ void AP_Terrain::open_file(void)
|
||||
return;
|
||||
}
|
||||
|
||||
// build the pathname to the degree file
|
||||
char path[] = HAL_BOARD_TERRAIN_DIRECTORY "/NxxExxx.DAT";
|
||||
char *p = &path[strlen(HAL_BOARD_TERRAIN_DIRECTORY)+1];
|
||||
snprintf(p, 12, "%c%02u%c%03u.DAT",
|
||||
block.lat_degrees<0?'S':'N',
|
||||
abs(block.lat_degrees),
|
||||
block.lon_degrees<0?'W':'E',
|
||||
abs(block.lon_degrees));
|
||||
char *path;
|
||||
const char* custom_dir = hal.util->get_custom_terrain_directory();
|
||||
if (custom_dir != NULL){
|
||||
// build the pathname from the args provided
|
||||
path = (char*) malloc(strlen(custom_dir)+strlen("/NxxExxx.DAT")+1);
|
||||
if (!path) {
|
||||
printf("Terrain degree file, malloc() failed: insufficient memory!\n");
|
||||
exit(1);
|
||||
}
|
||||
strcpy(path, custom_dir);
|
||||
strcat(path, "/NxxExxx.DAT");
|
||||
char *p = &path[strlen(HAL_BOARD_TERRAIN_DIRECTORY)+1];
|
||||
snprintf(p, 12, "%c%02u%c%03u.DAT",
|
||||
block.lat_degrees<0?'S':'N',
|
||||
abs(block.lat_degrees),
|
||||
block.lon_degrees<0?'W':'E',
|
||||
abs(block.lon_degrees));
|
||||
|
||||
// create directory if need be
|
||||
if (!directory_created) {
|
||||
mkdir(HAL_BOARD_TERRAIN_DIRECTORY, 0755);
|
||||
directory_created = true;
|
||||
// create directory if need be
|
||||
if (!directory_created) {
|
||||
mkdir(custom_dir, 0755);
|
||||
directory_created = true;
|
||||
}
|
||||
} else {
|
||||
// build the pathname to the degree file
|
||||
char path_default[] = HAL_BOARD_TERRAIN_DIRECTORY "/NxxExxx.DAT";
|
||||
char *p = &path_default[strlen(HAL_BOARD_TERRAIN_DIRECTORY)+1];
|
||||
snprintf(p, 12, "%c%02u%c%03u.DAT",
|
||||
block.lat_degrees<0?'S':'N',
|
||||
abs(block.lat_degrees),
|
||||
block.lon_degrees<0?'W':'E',
|
||||
abs(block.lon_degrees));
|
||||
|
||||
path = path_default;
|
||||
// create directory if need be
|
||||
if (!directory_created) {
|
||||
mkdir(HAL_BOARD_TERRAIN_DIRECTORY, 0755);
|
||||
directory_created = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (fd != -1) {
|
||||
|
Loading…
Reference in New Issue
Block a user