From 387bc81f26c25fb74a92d21560299c4ca59ff87c Mon Sep 17 00:00:00 2001
From: Daniel Agar <daniel@agar.ca>
Date: Mon, 11 Jun 2018 12:45:06 -0400
Subject: [PATCH] move systemlib/circuit_breaker.cpp to standalone lib

---
 src/drivers/kinetis/tone_alarm/CMakeLists.txt |  1 +
 src/drivers/kinetis/tone_alarm/tone_alarm.cpp |  2 +-
 src/drivers/px4fmu/CMakeLists.txt             |  1 +
 src/drivers/px4fmu/fmu.cpp                    |  2 +-
 src/drivers/px4io/CMakeLists.txt              |  1 +
 src/drivers/px4io/px4io.cpp                   |  2 +-
 src/drivers/samv7/tone_alarm/CMakeLists.txt   |  1 +
 src/drivers/samv7/tone_alarm/tone_alarm.cpp   |  2 +-
 src/drivers/stm32/tone_alarm/CMakeLists.txt   |  1 +
 src/drivers/stm32/tone_alarm/tone_alarm.cpp   |  2 +-
 .../uuv_example_app/uuv_example_app.cpp       |  2 +-
 src/lib/CMakeLists.txt                        |  1 +
 src/lib/circuit_breaker/CMakeLists.txt        | 34 +++++++++++++++++++
 .../circuit_breaker}/circuit_breaker.cpp      |  3 +-
 .../circuit_breaker}/circuit_breaker.h        |  2 +-
 .../circuit_breaker}/circuit_breaker_params.c |  0
 src/modules/commander/CMakeLists.txt          |  1 +
 src/modules/commander/commander.cpp           |  2 +-
 src/modules/mc_att_control/CMakeLists.txt     |  1 +
 .../mc_att_control/mc_att_control_main.cpp    |  2 +-
 src/modules/systemlib/CMakeLists.txt          |  1 -
 21 files changed, 53 insertions(+), 11 deletions(-)
 create mode 100644 src/lib/circuit_breaker/CMakeLists.txt
 rename src/{modules/systemlib => lib/circuit_breaker}/circuit_breaker.cpp (98%)
 rename src/{modules/systemlib => lib/circuit_breaker}/circuit_breaker.h (99%)
 rename src/{modules/systemlib => lib/circuit_breaker}/circuit_breaker_params.c (100%)

diff --git a/src/drivers/kinetis/tone_alarm/CMakeLists.txt b/src/drivers/kinetis/tone_alarm/CMakeLists.txt
index ae51757d6a..768934bf1b 100644
--- a/src/drivers/kinetis/tone_alarm/CMakeLists.txt
+++ b/src/drivers/kinetis/tone_alarm/CMakeLists.txt
@@ -37,5 +37,6 @@ px4_add_module(
 	SRCS
 		tone_alarm.cpp
 	DEPENDS
+		circuit_breaker
 		tunes
 	)
\ No newline at end of file
diff --git a/src/drivers/kinetis/tone_alarm/tone_alarm.cpp b/src/drivers/kinetis/tone_alarm/tone_alarm.cpp
index 4cbf7b04b0..7f25e34a26 100644
--- a/src/drivers/kinetis/tone_alarm/tone_alarm.cpp
+++ b/src/drivers/kinetis/tone_alarm/tone_alarm.cpp
@@ -113,7 +113,7 @@
 #include "kinetis_tpm.h"
 
 #include <systemlib/err.h>
-#include <systemlib/circuit_breaker.h>
+#include <circuit_breaker/circuit_breaker.h>
 
 #define CAT3_(A, B, C)    A##B##C
 #define CAT3(A, B, C)     CAT3_(A, B, C)
diff --git a/src/drivers/px4fmu/CMakeLists.txt b/src/drivers/px4fmu/CMakeLists.txt
index 6a10c9131a..60867d2697 100644
--- a/src/drivers/px4fmu/CMakeLists.txt
+++ b/src/drivers/px4fmu/CMakeLists.txt
@@ -38,5 +38,6 @@ px4_add_module(
 	SRCS
 		fmu.cpp
 	DEPENDS
+		circuit_breaker
 		rc
 	)
diff --git a/src/drivers/px4fmu/fmu.cpp b/src/drivers/px4fmu/fmu.cpp
index f7d2548317..7a9e22cc7e 100644
--- a/src/drivers/px4fmu/fmu.cpp
+++ b/src/drivers/px4fmu/fmu.cpp
@@ -56,7 +56,7 @@
 #include <px4_getopt.h>
 #include <px4_log.h>
 #include <px4_module.h>
-#include <systemlib/circuit_breaker.h>
+#include <circuit_breaker/circuit_breaker.h>
 #include <lib/mixer/mixer.h>
 #include <parameters/param.h>
 #include <perf/perf_counter.h>
diff --git a/src/drivers/px4io/CMakeLists.txt b/src/drivers/px4io/CMakeLists.txt
index f48bd9ec6e..0d779b3334 100644
--- a/src/drivers/px4io/CMakeLists.txt
+++ b/src/drivers/px4io/CMakeLists.txt
@@ -42,6 +42,7 @@ px4_add_module(
 		px4io_serial_f4.cpp
 		px4io_serial_f7.cpp
 	DEPENDS
+		circuit_breaker
 	)
 
 # include the px4io binary in ROMFS
diff --git a/src/drivers/px4io/px4io.cpp b/src/drivers/px4io/px4io.cpp
index dc4a949864..c75a7d995e 100644
--- a/src/drivers/px4io/px4io.cpp
+++ b/src/drivers/px4io/px4io.cpp
@@ -71,7 +71,7 @@
 #include <perf/perf_counter.h>
 #include <systemlib/err.h>
 #include <parameters/param.h>
-#include <systemlib/circuit_breaker.h>
+#include <circuit_breaker/circuit_breaker.h>
 #include <systemlib/mavlink_log.h>
 
 #include <uORB/topics/actuator_controls.h>
diff --git a/src/drivers/samv7/tone_alarm/CMakeLists.txt b/src/drivers/samv7/tone_alarm/CMakeLists.txt
index 815f4d5c69..c54cbdd3ec 100644
--- a/src/drivers/samv7/tone_alarm/CMakeLists.txt
+++ b/src/drivers/samv7/tone_alarm/CMakeLists.txt
@@ -37,5 +37,6 @@ px4_add_module(
 	SRCS
 		tone_alarm.cpp
 	DEPENDS
+		circuit_breaker
 		tunes
 	)
\ No newline at end of file
diff --git a/src/drivers/samv7/tone_alarm/tone_alarm.cpp b/src/drivers/samv7/tone_alarm/tone_alarm.cpp
index afb470a5cd..672321331a 100644
--- a/src/drivers/samv7/tone_alarm/tone_alarm.cpp
+++ b/src/drivers/samv7/tone_alarm/tone_alarm.cpp
@@ -116,7 +116,7 @@
 #include <sam_tc.h>
 
 #include <systemlib/err.h>
-#include <systemlib/circuit_breaker.h>
+#include <circuit_breaker/circuit_breaker.h>
 
 /* Check that tone alarm and HRT timers are different */
 #if defined(TONE_ALARM_CHANNEL)  && defined(HRT_TIMER_CHANNEL)
diff --git a/src/drivers/stm32/tone_alarm/CMakeLists.txt b/src/drivers/stm32/tone_alarm/CMakeLists.txt
index 815f4d5c69..c54cbdd3ec 100644
--- a/src/drivers/stm32/tone_alarm/CMakeLists.txt
+++ b/src/drivers/stm32/tone_alarm/CMakeLists.txt
@@ -37,5 +37,6 @@ px4_add_module(
 	SRCS
 		tone_alarm.cpp
 	DEPENDS
+		circuit_breaker
 		tunes
 	)
\ No newline at end of file
diff --git a/src/drivers/stm32/tone_alarm/tone_alarm.cpp b/src/drivers/stm32/tone_alarm/tone_alarm.cpp
index 4d8f950221..ad1746d20b 100644
--- a/src/drivers/stm32/tone_alarm/tone_alarm.cpp
+++ b/src/drivers/stm32/tone_alarm/tone_alarm.cpp
@@ -109,7 +109,7 @@
 #include <drivers/drv_hrt.h>
 
 #include <systemlib/err.h>
-#include <systemlib/circuit_breaker.h>
+#include <circuit_breaker/circuit_breaker.h>
 
 #include <px4_workqueue.h>
 
diff --git a/src/examples/uuv_example_app/uuv_example_app.cpp b/src/examples/uuv_example_app/uuv_example_app.cpp
index 36f241c4ae..86739b1c0f 100644
--- a/src/examples/uuv_example_app/uuv_example_app.cpp
+++ b/src/examples/uuv_example_app/uuv_example_app.cpp
@@ -54,7 +54,7 @@
 #include <parameters/param.h>
 #include <systemlib/err.h>
 #include <perf/perf_counter.h>
-#include <systemlib/circuit_breaker.h>
+
 // internal libraries
 #include <lib/mathlib/mathlib.h>
 #include <matrix/math.hpp>
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index 93152ae534..8aa234c76d 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -35,6 +35,7 @@ px4_add_git_submodule(TARGET git_ecl PATH "ecl")
 px4_add_git_submodule(TARGET git_matrix PATH "matrix")
 
 add_subdirectory(battery)
+add_subdirectory(circuit_breaker)
 add_subdirectory(controllib)
 add_subdirectory(conversion)
 add_subdirectory(drivers)
diff --git a/src/lib/circuit_breaker/CMakeLists.txt b/src/lib/circuit_breaker/CMakeLists.txt
new file mode 100644
index 0000000000..54ee7cdbd0
--- /dev/null
+++ b/src/lib/circuit_breaker/CMakeLists.txt
@@ -0,0 +1,34 @@
+############################################################################
+#
+#   Copyright (c) 2018 PX4 Development Team. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in
+#    the documentation and/or other materials provided with the
+#    distribution.
+# 3. Neither the name PX4 nor the names of its contributors may be
+#    used to endorse or promote products derived from this software
+#    without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+############################################################################
+
+px4_add_library(circuit_breaker circuit_breaker.cpp)
diff --git a/src/modules/systemlib/circuit_breaker.cpp b/src/lib/circuit_breaker/circuit_breaker.cpp
similarity index 98%
rename from src/modules/systemlib/circuit_breaker.cpp
rename to src/lib/circuit_breaker/circuit_breaker.cpp
index 9a6fdd5834..099238d2fd 100644
--- a/src/modules/systemlib/circuit_breaker.cpp
+++ b/src/lib/circuit_breaker/circuit_breaker.cpp
@@ -42,9 +42,10 @@
  * parameter needs to set to the key (magic).
  */
 
+#include "circuit_breaker.h"
+
 #include <stdint.h>
 #include <px4_defines.h>
-#include <systemlib/circuit_breaker.h>
 
 bool circuit_breaker_enabled(const char *breaker, int32_t magic)
 {
diff --git a/src/modules/systemlib/circuit_breaker.h b/src/lib/circuit_breaker/circuit_breaker.h
similarity index 99%
rename from src/modules/systemlib/circuit_breaker.h
rename to src/lib/circuit_breaker/circuit_breaker.h
index dc403ceb72..d3ac50ea66 100644
--- a/src/modules/systemlib/circuit_breaker.h
+++ b/src/lib/circuit_breaker/circuit_breaker.h
@@ -59,7 +59,7 @@
 #define CBRK_USB_CHK_KEY	197848
 #define CBRK_VELPOSERR_KEY	201607
 
-#include <stdbool.h>
+#include <stdint.h>
 
 __BEGIN_DECLS
 
diff --git a/src/modules/systemlib/circuit_breaker_params.c b/src/lib/circuit_breaker/circuit_breaker_params.c
similarity index 100%
rename from src/modules/systemlib/circuit_breaker_params.c
rename to src/lib/circuit_breaker/circuit_breaker_params.c
diff --git a/src/modules/commander/CMakeLists.txt b/src/modules/commander/CMakeLists.txt
index 8c70eca7c0..b6796a2cc8 100644
--- a/src/modules/commander/CMakeLists.txt
+++ b/src/modules/commander/CMakeLists.txt
@@ -54,6 +54,7 @@ px4_add_module(
 		rc_check.cpp
 		state_machine_helper.cpp
 	DEPENDS
+		circuit_breaker
 		df_driver_framework
 		git_ecl
 		ecl_geo
diff --git a/src/modules/commander/commander.cpp b/src/modules/commander/commander.cpp
index fe4f47dd36..34dd9e65d5 100644
--- a/src/modules/commander/commander.cpp
+++ b/src/modules/commander/commander.cpp
@@ -73,7 +73,7 @@
 #include <px4_shutdown.h>
 #include <px4_tasks.h>
 #include <px4_time.h>
-#include <systemlib/circuit_breaker.h>
+#include <circuit_breaker/circuit_breaker.h>
 #include <systemlib/err.h>
 #include <systemlib/hysteresis/hysteresis.h>
 #include <systemlib/mavlink_log.h>
diff --git a/src/modules/mc_att_control/CMakeLists.txt b/src/modules/mc_att_control/CMakeLists.txt
index 32012dd686..588e43f786 100644
--- a/src/modules/mc_att_control/CMakeLists.txt
+++ b/src/modules/mc_att_control/CMakeLists.txt
@@ -40,6 +40,7 @@ px4_add_module(
 	SRCS
 		mc_att_control_main.cpp
 	DEPENDS
+		circuit_breaker
 		conversion
 		mathlib
 	)
diff --git a/src/modules/mc_att_control/mc_att_control_main.cpp b/src/modules/mc_att_control/mc_att_control_main.cpp
index d539b985dd..0960b49cfb 100644
--- a/src/modules/mc_att_control/mc_att_control_main.cpp
+++ b/src/modules/mc_att_control/mc_att_control_main.cpp
@@ -48,7 +48,7 @@
 #include <conversion/rotation.h>
 #include <drivers/drv_hrt.h>
 #include <lib/ecl/geo/geo.h>
-#include <systemlib/circuit_breaker.h>
+#include <circuit_breaker/circuit_breaker.h>
 #include <mathlib/math/Limits.hpp>
 #include <mathlib/math/Functions.hpp>
 
diff --git a/src/modules/systemlib/CMakeLists.txt b/src/modules/systemlib/CMakeLists.txt
index 56bce98846..16ec98603c 100644
--- a/src/modules/systemlib/CMakeLists.txt
+++ b/src/modules/systemlib/CMakeLists.txt
@@ -33,7 +33,6 @@
 
 set(SRCS
 	airspeed.cpp
-	circuit_breaker.cpp
 	conversions.c
 	cpuload.c
 	crc.c
-- 
GitLab