From 15e869426d825bb7eecd7bcc7226794347ce611d Mon Sep 17 00:00:00 2001
From: Michael Reuscher <michael.reuscher@desy.de>
Date: Mon, 10 Jul 2023 17:51:32 +0200
Subject: [PATCH] Simrunner 1.0 und README Controller

---
 controller/README.md   | 23 +++++++++++++++++++++++
 controller/setup.py    |  2 +-
 simrunner/simrunner.py | 22 ++++++++++++++++++++++
 3 files changed, 46 insertions(+), 1 deletion(-)
 create mode 100644 controller/README.md
 create mode 100644 simrunner/simrunner.py

diff --git a/controller/README.md b/controller/README.md
new file mode 100644
index 0000000..3f71031
--- /dev/null
+++ b/controller/README.md
@@ -0,0 +1,23 @@
+Install the controller and its dependencies 
+by following these instructions:
+
+Please make sure that you are using Python 3.9 or higher.
+
+Please make sure that you have installed setuptools for python3
+if not:
+   sudo apt install python3-setuptools
+   or
+   pip install setuptools
+
+1. Navigate to /detectorwritesim/controller
+2. Create a new Python3.9 or higher virtual environment:
+   python3 -m venv cenv
+3. Activate the environment:
+   source cenv/bin/activate
+4. Build the controller:
+   python3 setup.py install
+
+Now you have completed the setup process, 
+you can start the controller by entering the following command:
+
+controller_run
\ No newline at end of file
diff --git a/controller/setup.py b/controller/setup.py
index aa79bcb..82953ab 100644
--- a/controller/setup.py
+++ b/controller/setup.py
@@ -15,7 +15,7 @@ setup(
     ],
     entry_points={
         'console_scripts': [
-            'mein_programm=controller.main:main'
+            'controller_run=controller.main:main'
         ]
     }
 )
diff --git a/simrunner/simrunner.py b/simrunner/simrunner.py
new file mode 100644
index 0000000..8ee801c
--- /dev/null
+++ b/simrunner/simrunner.py
@@ -0,0 +1,22 @@
+import os
+import subprocess
+
+
+def start_cpp_program(program_path, arguments):
+    command = [program_path] + arguments
+    process = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+    return process
+
+
+def send_input(program_path, arguments):
+    command = [program_path] + arguments
+    process = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+    output = process.stdout.readline().decode()
+    return output
+
+
+# Beispielverwendung
+cpp_program_path = os.path.join(os.path.dirname(__file__), "../build/src/detsim")
+arguments = ["-o", "output", "--posixDataDir", "protokoll", "-n", "100", "-s", "2M", "-i", "0.1s", "-N", "4"]
+
+send_input(cpp_program_path, arguments)
-- 
GitLab