/* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ /* handle disk IO for terrain code */ #include #include #include #include #include #include "AP_Terrain.h" #if AP_TERRAIN_AVAILABLE #include #include #if HAL_OS_POSIX_IO #include #include #include #endif #include #include extern const AP_HAL::HAL& hal; /* calculate bit number in grid_block bitmap. This corresponds to a bit representing a 4x4 mavlink transmitted block */ uint8_t AP_Terrain::grid_bitnum(uint8_t idx_x, uint8_t idx_y) { ASSERT_RANGE(idx_x,0,27); ASSERT_RANGE(idx_y,0,31); uint8_t subgrid_x = idx_x / TERRAIN_GRID_MAVLINK_SIZE; uint8_t subgrid_y = idx_y / TERRAIN_GRID_MAVLINK_SIZE; ASSERT_RANGE(subgrid_x,0,TERRAIN_GRID_BLOCK_MUL_X-1); ASSERT_RANGE(subgrid_y,0,TERRAIN_GRID_BLOCK_MUL_Y-1); return subgrid_y + TERRAIN_GRID_BLOCK_MUL_Y*subgrid_x; } /* given a grid_info check that a given idx_x/idx_y is available (set in the bitmap) */ bool AP_Terrain::check_bitmap(const struct grid_block &grid, uint8_t idx_x, uint8_t idx_y) { uint8_t bitnum = grid_bitnum(idx_x, idx_y); return (grid.bitmap & (((uint64_t)1U)<