-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: đź’ˇ Removed the demo code from main and into its own
- Loading branch information
1 parent
330ba4a
commit b297503
Showing
4 changed files
with
92 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include <iostream> | ||
#include <memory> | ||
#include <thread> | ||
#include <chrono> | ||
|
||
#include "RailwaySignal.hpp" | ||
#include "RailwayTypes.hpp" | ||
#include "SignalCommand.hpp" | ||
|
||
/** | ||
* @brief Programme principal de démonstration | ||
* @safety_level SIL4 | ||
* @requirement REQ_DEMO_001 | ||
*/ | ||
class SignalDemo { | ||
public: | ||
SignalDemo(); | ||
~SignalDemo() = default; | ||
|
||
void run(); | ||
|
||
private: | ||
static std::string aspectToString(Railway::Aspect aspect) { | ||
switch (aspect) { | ||
using enum Railway::Aspect; | ||
|
||
case RED: | ||
return "RED"; | ||
case YELLOW: | ||
return "YELLOW"; | ||
case GREEN: | ||
return "GREEN"; | ||
default: | ||
return "UNKNOWN"; | ||
} | ||
} | ||
|
||
Railway::RailwaySignal signal_{"SIGNAL_DEMO_001"}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "SignalDemo.hpp" | ||
|
||
using namespace std::chrono_literals; | ||
|
||
SignalDemo::SignalDemo() { | ||
// Configuration du handler pour les changements d'aspect | ||
signal_.aspectChanged.connect([](Railway::Aspect aspect) { | ||
std::cout << "Signal aspect changed to: " << aspectToString(aspect) << std::endl; | ||
}); | ||
} | ||
|
||
void SignalDemo::run() { | ||
std::cout << "Starting Railway Signal Demo\nInitial aspect: " << aspectToString(signal_.getAspect()) << "\n"; | ||
|
||
// Démonstration des commandes et de leur réversibilité | ||
try { | ||
std::cout << "\nDémonstration des commandes et de leur réversibilité:\n"; | ||
|
||
// Transition vers jaune | ||
std::cout << "\nChanging to YELLOW...\n"; | ||
auto yellowCmd = std::make_unique<Railway::ChangeAspectCommand>(signal_, Railway::Aspect::YELLOW); | ||
signal_.executeCommand(std::move(yellowCmd)); | ||
std::this_thread::sleep_for(2s); | ||
|
||
// Transition vers vert | ||
std::cout << "\nChanging to GREEN...\n"; | ||
auto greenCmd = std::make_unique<Railway::ChangeAspectCommand>(signal_, Railway::Aspect::GREEN); | ||
signal_.executeCommand(std::move(greenCmd)); | ||
std::this_thread::sleep_for(2s); | ||
|
||
// DĂ©monstration de l'annulation | ||
std::cout << "\nUndoing last command (should return to YELLOW)...\n"; | ||
signal_.undoLastCommand(); | ||
std::this_thread::sleep_for(2s); | ||
|
||
// Démonstration de la réexécution | ||
std::cout << "\nRedoing command (should return to GREEN)...\n"; | ||
signal_.redoCommand(); | ||
std::this_thread::sleep_for(2s); | ||
|
||
// Retour à rouge pour la sécurité | ||
std::cout << "\nReturning to RED (safety state)...\n"; | ||
auto redCmd = std::make_unique<Railway::ChangeAspectCommand>(signal_, Railway::Aspect::RED); | ||
signal_.executeCommand(std::move(redCmd)); | ||
|
||
} catch (const std::exception& e) { | ||
std::cerr << "Error during demo: " << e.what() << std::endl; | ||
// En cas d'erreur, on s'assure de revenir à l'état sûr (rouge) | ||
signal_.setAspect(Railway::Aspect::RED); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters