Skip to content

Commit

Permalink
Merge pull request #1200 from mavlink/pr-clang10
Browse files Browse the repository at this point in the history
tools: update to clang-format-10
  • Loading branch information
julianoes committed Oct 2, 2020
2 parents 5c80b44 + 518099c commit 6e2607d
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 119 deletions.
17 changes: 9 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ jobs:
- name: test (mavsdk_server)
run: ./build/release/src/backend/test/unit_tests_backend

ubuntu18-proto-check:
name: ubuntu-18.04 (proto check)
runs-on: ubuntu-18.04
ubuntu20-proto-check:
name: ubuntu-20.04 (proto check)
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: install clang-format
run: sudo apt-get install -y clang-format-9
run: sudo apt-get install -y clang-format-10
- name: install dcsdkgen
run: |
cd proto/pb_plugins
Expand All @@ -99,14 +99,15 @@ jobs:
- name: check for diff
run: git diff --exit-code

ubuntu18-check-style:
name: ubuntu-18.04 (check style and docs)
runs-on: ubuntu-18.04
container: mavsdk/mavsdk-ubuntu-18.04
ubuntu20-check-style:
name: ubuntu-20.04 (check style and docs)
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: install dependencies
run: sudo apt-get install -y doxygen clang-format-10
- name: check style
run: ./tools/fix_style.sh .
- name: check docs
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile-Ubuntu-18.04
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RUN apt-get update \
build-essential \
ca-certificates \
ccache \
clang-format-9 \
clang-format-10 \
cmake \
colordiff \
doxygen \
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile-Ubuntu-20.04
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RUN apt-get update \
build-essential \
ca-certificates \
ccache \
clang-format-9 \
clang-format-10 \
cmake \
colordiff \
doxygen \
Expand Down
21 changes: 11 additions & 10 deletions examples/battery/battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,17 @@ void subscribe_armed(std::shared_ptr<Telemetry> telemetry)

void send_battery_status(std::shared_ptr<MavlinkPassthrough> mavlink_passthrough)
{
const uint16_t voltages[10]{3700,
3600,
UINT16_MAX,
UINT16_MAX,
UINT16_MAX,
UINT16_MAX,
UINT16_MAX,
UINT16_MAX,
UINT16_MAX,
UINT16_MAX}; // mV
const uint16_t voltages[10]{
3700,
3600,
UINT16_MAX,
UINT16_MAX,
UINT16_MAX,
UINT16_MAX,
UINT16_MAX,
UINT16_MAX,
UINT16_MAX,
UINT16_MAX}; // mV

mavlink_message_t message;
mavlink_msg_battery_status_pack(
Expand Down
25 changes: 13 additions & 12 deletions src/backend/src/core/core_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,19 @@ class CoreServiceImpl final : public mavsdk::rpc::core::CoreService::Service {
const rpc::core::ListRunningPluginsRequest* /* request */,
mavsdk::rpc::core::ListRunningPluginsResponse* response) override
{
std::string plugin_names[12] = {"action",
"calibration",
"camera",
"core",
"gimbal",
"info",
"mission",
"mocap",
"offboard",
"param",
"shell",
"telemetry"};
std::string plugin_names[12] = {
"action",
"calibration",
"camera",
"core",
"gimbal",
"info",
"mission",
"mocap",
"offboard",
"param",
"shell",
"telemetry"};

for (const auto plugin_name : plugin_names) {
auto plugin_info = response->add_plugin_info();
Expand Down
6 changes: 3 additions & 3 deletions src/core/geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ CoordinateTransformation::local_from_global(GlobalCoordinate global_coordinate)

const double k = (fabs(c) > 0) ? (c / sin(c)) : 1.0;

return LocalCoordinate{k * (ref_cos_lat * sin_lat - ref_sin_lat * cos_lat * cos_d_lon) *
world_radius_m,
k * cos_lat * sin(lon_rad - _ref_lon_rad) * world_radius_m};
return LocalCoordinate{
k * (ref_cos_lat * sin_lat - ref_sin_lat * cos_lat * cos_d_lon) * world_radius_m,
k * cos_lat * sin(lon_rad - _ref_lon_rad) * world_radius_m};
}

CoordinateTransformation::GlobalCoordinate
Expand Down
27 changes: 14 additions & 13 deletions src/core/mavlink_mission_transfer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,19 +580,20 @@ void MAVLinkMissionTransfer::DownloadWorkItem::process_mission_item_int(
mavlink_mission_item_int_t item_int;
mavlink_msg_mission_item_int_decode(&message, &item_int);

_items.push_back(ItemInt{item_int.seq,
item_int.frame,
item_int.command,
item_int.current,
item_int.autocontinue,
item_int.param1,
item_int.param2,
item_int.param3,
item_int.param4,
item_int.x,
item_int.y,
item_int.z,
item_int.mission_type});
_items.push_back(ItemInt{
item_int.seq,
item_int.frame,
item_int.command,
item_int.current,
item_int.autocontinue,
item_int.param1,
item_int.param2,
item_int.param3,
item_int.param4,
item_int.x,
item_int.y,
item_int.z,
item_int.mission_type});

if (_next_sequence + 1 == _expected_count) {
_timeout_handler.remove(_cookie);
Expand Down
28 changes: 14 additions & 14 deletions src/plugins/geofence/geofence_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,20 @@ GeofenceImpl::assemble_items(const std::vector<Geofence::Polygon>& polygons)
const uint8_t autocontinue = 0;
const float param1 = float(polygon.points.size());

items.push_back(
MAVLinkMissionTransfer::ItemInt{sequence,
MAV_FRAME_GLOBAL_INT,
command,
current,
autocontinue,
param1,
0.0f,
0.0f,
0.0f,
int32_t(std::round(point.latitude_deg * 1e7)),
int32_t(std::round(point.longitude_deg * 1e7)),
0.0f,
MAV_MISSION_TYPE_FENCE});
items.push_back(MAVLinkMissionTransfer::ItemInt{
sequence,
MAV_FRAME_GLOBAL_INT,
command,
current,
autocontinue,
param1,
0.0f,
0.0f,
0.0f,
int32_t(std::round(point.latitude_deg * 1e7)),
int32_t(std::round(point.longitude_deg * 1e7)),
0.0f,
MAV_MISSION_TYPE_FENCE});
++sequence;
}
}
Expand Down
108 changes: 56 additions & 52 deletions src/plugins/mission/mission_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,19 +278,20 @@ MissionImpl::convert_to_int_items(const std::vector<MissionItem>& mission_items)

uint8_t autocontinue = 1;

MAVLinkMissionTransfer::ItemInt next_item{static_cast<uint16_t>(int_items.size()),
MAV_FRAME_MISSION,
MAV_CMD_DO_CHANGE_SPEED,
current,
autocontinue,
1.0f, // ground speed
item.speed_m_s,
-1.0f, // no throttle change
0.0f, // absolute
0,
0,
NAN,
MAV_MISSION_TYPE_MISSION};
MAVLinkMissionTransfer::ItemInt next_item{
static_cast<uint16_t>(int_items.size()),
MAV_FRAME_MISSION,
MAV_CMD_DO_CHANGE_SPEED,
current,
autocontinue,
1.0f, // ground speed
item.speed_m_s,
-1.0f, // no throttle change
0.0f, // absolute
0,
0,
NAN,
MAV_MISSION_TYPE_MISSION};

_mission_data.mavlink_mission_item_to_mission_item_indices.push_back(item_i);
int_items.push_back(next_item);
Expand Down Expand Up @@ -332,19 +333,20 @@ MissionImpl::convert_to_int_items(const std::vector<MissionItem>& mission_items)

uint8_t autocontinue = 1;

MAVLinkMissionTransfer::ItemInt next_item{static_cast<uint16_t>(int_items.size()),
MAV_FRAME_MISSION,
MAV_CMD_DO_MOUNT_CONTROL,
current,
autocontinue,
item.gimbal_pitch_deg, // pitch
0.0f, // roll (yes it is a weird order)
item.gimbal_yaw_deg, // yaw
NAN,
0,
0,
MAV_MOUNT_MODE_MAVLINK_TARGETING,
MAV_MISSION_TYPE_MISSION};
MAVLinkMissionTransfer::ItemInt next_item{
static_cast<uint16_t>(int_items.size()),
MAV_FRAME_MISSION,
MAV_CMD_DO_MOUNT_CONTROL,
current,
autocontinue,
item.gimbal_pitch_deg, // pitch
0.0f, // roll (yes it is a weird order)
item.gimbal_yaw_deg, // yaw
NAN,
0,
0,
MAV_MOUNT_MODE_MAVLINK_TARGETING,
MAV_MISSION_TYPE_MISSION};

_mission_data.mavlink_mission_item_to_mission_item_indices.push_back(item_i);
int_items.push_back(next_item);
Expand Down Expand Up @@ -433,19 +435,20 @@ MissionImpl::convert_to_int_items(const std::vector<MissionItem>& mission_items)
break;
}

MAVLinkMissionTransfer::ItemInt next_item{static_cast<uint16_t>(int_items.size()),
MAV_FRAME_MISSION,
command,
current,
autocontinue,
param1,
param2,
param3,
NAN,
0,
0,
NAN,
MAV_MISSION_TYPE_MISSION};
MAVLinkMissionTransfer::ItemInt next_item{
static_cast<uint16_t>(int_items.size()),
MAV_FRAME_MISSION,
command,
current,
autocontinue,
param1,
param2,
param3,
NAN,
0,
0,
NAN,
MAV_MISSION_TYPE_MISSION};

_mission_data.mavlink_mission_item_to_mission_item_indices.push_back(item_i);
int_items.push_back(next_item);
Expand All @@ -459,19 +462,20 @@ MissionImpl::convert_to_int_items(const std::vector<MissionItem>& mission_items)
--item_i;

if (_enable_return_to_launch_after_mission) {
MAVLinkMissionTransfer::ItemInt next_item{static_cast<uint16_t>(int_items.size()),
MAV_FRAME_MISSION,
MAV_CMD_NAV_RETURN_TO_LAUNCH,
0, // current
1, // autocontinue
NAN, // loiter time in seconds
NAN, // empty
NAN, // radius around waypoint in meters ?
NAN, // loiter at center of waypoint
0,
0,
0,
MAV_MISSION_TYPE_MISSION};
MAVLinkMissionTransfer::ItemInt next_item{
static_cast<uint16_t>(int_items.size()),
MAV_FRAME_MISSION,
MAV_CMD_NAV_RETURN_TO_LAUNCH,
0, // current
1, // autocontinue
NAN, // loiter time in seconds
NAN, // empty
NAN, // radius around waypoint in meters ?
NAN, // loiter at center of waypoint
0,
0,
0,
MAV_MISSION_TYPE_MISSION};

_mission_data.mavlink_mission_item_to_mission_item_indices.push_back(item_i);
int_items.push_back(next_item);
Expand Down
10 changes: 6 additions & 4 deletions tools/fix_style.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
# This script runs clang-format over all files ending in .h, .c, .cpp listed
# by git in the given directory.

version_required_major="9"
version_required_major="10"

# Try to find the latest version of clang
if command -v clang-format-9 >/dev/null; then
if command -v clang-format-10 >/dev/null; then
clang_format=clang-format-10
elif command -v clang-format-9 >/dev/null; then
clang_format=clang-format-9
elif command -v clang-format-8 >/dev/null; then
clang_format=clang-format-8
Expand All @@ -27,14 +29,14 @@ if [[ $version =~ $semver_regex ]]; then
version_major=${BASH_REMATCH[1]}
if [ "$version_required_major" -gt "$version_major" ]; then
echo "Clang version $version_major too old (required: $version_required_major)"
echo "You can use clang-format-9 from docker:"
echo "You can use clang-format-10 from docker:"
echo ""
echo " 'tools/run-docker.sh tools/fix_style.sh .'"
exit 1

elif [ "$version_required_major" -lt "$version_major" ]; then
echo "Clang version $version_major too new (required: $version_required_major)"
echo "You can use clang-format-9 from docker:"
echo "You can use clang-format-10 from docker:"
echo ""
echo " 'tools/run-docker.sh tools/fix_style.sh .'"
exit 1
Expand Down
2 changes: 1 addition & 1 deletion tools/run-docker.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env sh

docker run -it --rm -v $(pwd):/home/user/MAVSDK:z -e LOCAL_USER_ID=`id -u` mavsdk/mavsdk-ubuntu-18.04-px4-sitl-v1.10 "$@"
docker run -it --rm -v $(pwd):/home/user/MAVSDK:z -e LOCAL_USER_ID=`id -u` mavsdk/mavsdk-ubuntu-20.04-px4-sitl-v1.11 "$@"

0 comments on commit 6e2607d

Please sign in to comment.