Skip to content

Commit

Permalink
Merge pull request #84 from saleemhamo/development
Browse files Browse the repository at this point in the history
Final HW testing / demo
  • Loading branch information
AlexandruRO45 authored Apr 17, 2024
2 parents abf5a48 + c3e2cb6 commit 1a1c779
Show file tree
Hide file tree
Showing 23 changed files with 835 additions and 254 deletions.
32 changes: 14 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ if (NOT Boost_FOUND)
URL https://boostorg.jfrog.io/artifactory/main/release/1.76.0/source/boost_1_76_0.tar.bz2
)
FetchContent_MakeAvailable(boost)
# Adjust the include path as needed based on how Boost is structured when fetched

endif ()

####### Testing Configuration #######
Expand Down Expand Up @@ -105,13 +105,11 @@ function(add_hardware_test TEST_NAME TEST_FILE)
add_test(NAME ${TEST_NAME}UnitTest COMMAND ${TEST_NAME})
endfunction(add_hardware_test)


# Assuming the Timer class is part of the 'utils' group of files
set(TIMER_SOURCES include/utils/Timer.h) # Adjust path as necessary

# Define a function for non-hardware tests if not already existing
function(add_unit_test TEST_NAME TEST_FILE)
add_executable(${TEST_NAME} ${TEST_FILE} ${TIMER_SOURCES})
cmake_parse_arguments(ADD_UNIT_TEST "" "ADDITIONAL_SOURCES" "" ${ARGN})

add_executable(${TEST_NAME} ${TEST_FILE} ${ADD_UNIT_TEST_ADDITIONAL_SOURCES}) # Include additional sources if provided
target_link_libraries(${TEST_NAME} ${Boost_LIBRARIES} cpr::cpr) # Add other dependencies as needed
target_include_directories(${TEST_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/include)
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
Expand All @@ -127,20 +125,18 @@ else ()
message(STATUS "Configuring tests for non-Raspberry Pi environment.")
include_directories(${CMAKE_SOURCE_DIR}/include)

# Add hardware tests for actuators and sensors
add_hardware_test(BuzzerTest "tests/hardware_tests/actuators/Buzzer_test.cpp")
add_hardware_test(LEDTest "tests/hardware_tests/actuators/LED_test.cpp")
add_hardware_test(UltrasonicSensorTest "tests/hardware_tests/sensors/Ultrasonic_test.cpp")

# Ideas of tests to be implemented (priority order):
# add_hardware_test(CameraSensorTest "tests/hardware_tests/sensors/Camera_test.cpp")
# add_hardware_test(PushButtonTest "tests/hardware_tests/sensors/PushButton_test.cpp")
add_unit_test(TimerTest "tests/TimerTest.cpp")
# add_unit_test(CheckingSystemTest "tests/hardware_tests/main/CheckingSystem_test.cpp")
# add_unit_test(WarningSystemTest "tests/hardware_tests/main/WarningSystem_test.cpp")
# add_unit_test(TrafficLightTest "tests/hardware_tests/models/TrafficLight_test.cpp")
# add_unit_test(CarsTrafficLightSystemTest "tests/hardware_tests/main/CarsTrafficLightSystem_test.cpp")
# add_unit_test(PedestriansTrafficLightSystemTest "tests/hardware_tests/main/PedestriansTrafficLightSystem_test.cpp")
# add_unit_test(FirestoreLoggerTest "tests/hardware_tests/utils/FirestoreLogger_test.cpp")
# add_unit_test(MainSystemTest "tests/hardware_tests/main/MainSystem_test.cpp")
add_hardware_test(PushButtonTest "tests/hardware_tests/sensors/PushButton_test.cpp")

# Add logic tests for the main system and its components
add_hardware_test(CheckingSystemTest "tests/logic_tests/main/CheckingSystem_test.cpp")
add_hardware_test(WarningSystemTest "tests/logic_tests/main/WarningSystem_test.cpp")
add_hardware_test(TrafficLightTest "tests/logic_tests/models/TrafficLight_test.cpp")

# Add unit tests for the utility classes
add_unit_test(TimerTest "tests/logic_tests/utils/Timer_test.cpp" ADDITIONAL_SOURCES "include/utils/Timer.h")

endif ()
8 changes: 4 additions & 4 deletions Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -2502,7 +2502,7 @@ HIDE_UNDOC_RELATIONS = YES
# set to NO
# The default value is: NO.

HAVE_DOT = NO
HAVE_DOT = YES

# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is allowed
# to run in parallel. When set to 0 doxygen will base this on the number of
Expand Down Expand Up @@ -2566,7 +2566,7 @@ DOT_FONTPATH =
# The default value is: YES.

CLASS_GRAPH = YES

CLASS_DIAGRAMS = YES
# If the COLLABORATION_GRAPH tag is set to YES then doxygen will generate a
# graph for each documented class showing the direct and indirect implementation
# dependencies (inheritance, containment, and class references variables) of the
Expand Down Expand Up @@ -2596,7 +2596,7 @@ GROUP_GRAPHS = YES
# The default value is: NO.
# This tag requires that the tag HAVE_DOT is set to YES.

UML_LOOK = NO
UML_LOOK = YES

# If the UML_LOOK tag is enabled, the fields and methods are shown inside the
# class node. If there are many fields or methods and many nodes the graph may
Expand Down Expand Up @@ -2745,7 +2745,7 @@ INTERACTIVE_SVG = NO
# found. If left blank, it is assumed the dot tool can be found in the path.
# This tag requires that the tag HAVE_DOT is set to YES.

DOT_PATH =
DOT_PATH = /opt/homebrew/bin/dot

# The DOTFILE_DIRS tag can be used to specify one or more directories that
# contain dot files that are included in the documentation (see the \dotfile
Expand Down
16 changes: 11 additions & 5 deletions include/main/CheckingSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

class CheckingSystem {
public:
CheckingSystem(); ///< Constructor to initialize the system with default states and sensor configurations.
CheckingSystem(); ///< Constructor to initialize the system with default states and sensor configurations.
~CheckingSystem(); ///< Destructor to clean up resources, ensuring all threads are joined if necessary.

void initialize(); ///< Initialize sensors and system components.
Expand All @@ -42,23 +42,28 @@ class CheckingSystem {

void onPedestriansButtonPress(); ///< Handler for pedestrian button presses.

void registerCarsMotionCallback(const std::function<void()>& callback);
void registerPedestriansMotionCallback(const std::function<void()>& callback);
void registerPedestriansButtonCallback(const std::function<void()>& callback);
void registerCarsMotionCallback(const std::function<void()> &callback);

void registerPedestriansMotionCallback(const std::function<void()> &callback);

void registerPedestriansButtonCallback(const std::function<void()> &callback);

void enablePedestriansMotionDetection();

void disablePedestriansMotionDetection();

void enableCarsMotionDetection();

void disableCarsMotionDetection();

void enablePedestriansButton();

void disablePedestriansButton();

void enableSensing(); ///< Enable all sensors and detection mechanisms.
void disableSensing(); ///< Disable all sensors and detection mechanisms.


bool isRoadMotionDetected();

private:
std::atomic<bool> isActive; ///< Indicates if the system is currently active.
Expand All @@ -82,6 +87,7 @@ class CheckingSystem {
void monitorPedestrian(); ///< Function to monitor pedestrian movements continuously.
void monitorRoad(); ///< Function to monitor vehicle movements continuously.

void monitorPedestriansButton();
};

#endif // CHECKINGSYSTEM_H
12 changes: 9 additions & 3 deletions include/main/WarningSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
* activation, and deactivation methods. Utilizes predefined pin numbers
* from the Constants class for LED and buzzer components.
*/
class WarningSystem : public SystemInterface
{
class WarningSystem : public SystemInterface {
public:
/**
* @brief Constructs a new Warning System instance.
Expand All @@ -35,6 +34,13 @@ class WarningSystem : public SystemInterface
*/
void initialize() override;

/**
* @brief Getter of the isInitialized_ variable
*
* Return the value of isInitialized_.
*/
bool isInitialized() const { return isInitialized_; }

/**
* @brief Activates the warning system.
*
Expand All @@ -59,7 +65,7 @@ class WarningSystem : public SystemInterface
LED warningLED2; ///< Second LED component.
LED warningLED3; ///< Third LED component.
Buzzer warningBuzzer; ///< Buzzer component.
bool isInitialized; ///< Flag indicating whether the system has been initialized.
bool isInitialized_; ///< Flag indicating whether the system has been initialized.
};

#endif // WARNING_SYSTEM_H
1 change: 1 addition & 0 deletions include/pigpio_stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extern const int PI_LOW;
#define PI_PUD_DOWN 0
#define PI_PUD_OFF 0
#define FALLING_EDGE 0
#define RISING_EDGE 1

// Function declarations to mimic those in the pigpio library.
int gpioInitialise();
Expand Down
36 changes: 29 additions & 7 deletions include/sensors/PushButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,47 @@ class PushButton {
* @param pin The GPIO pin number associated with the button.
*/
PushButton(int pin);
/**
* @brief Destructor that cleans up ISR handling if necessary.
*/

/**
* @brief Destructor that cleans up ISR handling if necessary.
*/
~PushButton();

/**
* @brief Initializes the button's GPIO pin and sets up the interrupt service routine.
*
* This method sets the GPIO pin as an input and attaches an interrupt handler
* that is triggered on the falling edge (button press).
*/
void initialize();


/**
* @brief Detaches the interrupt service routine from the GPIO pin.
*/
void detachInterruptHandler();

/**
* @brief Attaches the interrupt service routine to the GPIO pin.
*/
void attachInterruptHandler();

/**
* @brief Initializes the GPIO pin as an input.
*/
void gpioInit();

/**
* @brief Registers a callback function to be called when the button is pressed.
* @param callback The function to call when the button is pressed.
*/
void registerButtonPressCallback(ButtonCallback callback);

/**
* @brief Registers a callback function to be called when the button is released.
* @param callback The function to call when the button is released.
*/
void registerButtonReleaseCallback(ButtonCallback callback);

// Disabling copy constructor and assignment operator
PushButton(const PushButton &) = delete;

Expand All @@ -60,6 +81,7 @@ class PushButton {
private:
int gpioPin; ///< GPIO pin number.
ButtonCallback buttonPressCallback; ///< User-defined callback function to handle button press events.
ButtonCallback buttonReleaseCallback; ///< User-defined callback function to handle button release events.

/**
* @brief Static method used as the interrupt service routine for button presses.
Expand All @@ -72,4 +94,4 @@ class PushButton {
};


#endif //CROSSGUARD_PUSHBUTTON_H
#endif //CROSSGUARD_PUSHBUTTON_H
4 changes: 4 additions & 0 deletions include/utils/FirestoreLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class FirestoreLogger {
*/
static void Log(const std::string &level, const std::string &message);

static std::string GetApiKey();

static std::string GetBaseUrl();

private:
/**
* @brief Generates a timestamp string in ISO 8601 format.
Expand Down
11 changes: 6 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ void initApplication() {
try {
FirestoreLogger::Initialize("INITIALIZE");
FirestoreLogger::Log("INFO", "Application Started!");
} catch (const std::exception &e) {
}
catch (const std::exception &e) {
std::cerr << "Failed to connect to firebase: " << e.what() << std::endl;
}

try {
Logger::init("app.log");
Logger::logInfo("Application starting");
} catch (const std::exception &e) {
}
catch (const std::exception &e) {
std::cerr << "Failed to initialize logger: " << e.what() << std::endl;
}
}
Expand All @@ -63,9 +65,8 @@ void closeApplication(MainSystem &mainSystem) {
try {
Logger::logInfo("Application stopping");
Logger::close();
} catch (const std::exception &e) {
}
catch (const std::exception &e) {
std::cerr << "Failed to close logger: " << e.what() << std::endl;
}


}
Loading

0 comments on commit 1a1c779

Please sign in to comment.