Compare commits
14 Commits
fec427794d
...
advancedSE
| Author | SHA1 | Date | |
|---|---|---|---|
| d56c7a1439 | |||
| 3ae042e0bb | |||
| cf6bcd8498 | |||
| 85bc6e9eba | |||
| 06e9348016 | |||
| 03941fc302 | |||
| 087b132362 | |||
| 757e51f1db | |||
| db03c9d7bd | |||
| 0dd7494f5a | |||
| c38835fd7b | |||
| ac854ed4f1 | |||
| bafb8314f6 | |||
| 466ae211d9 |
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@ -13,7 +13,7 @@
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" default="true" project-jdk-name="19" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="19" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
516
luca.qmd
Normal file
516
luca.qmd
Normal file
@ -0,0 +1,516 @@
|
||||
---
|
||||
title: "Programmentwurf AdvancedSoftwareEngineering"
|
||||
author:
|
||||
- Luca Müller
|
||||
- Paul Martin
|
||||
date: 05/31/2025
|
||||
date-format: "DD.MM.YYYY"
|
||||
lang: de
|
||||
format:
|
||||
pdf:
|
||||
toc: true
|
||||
number-sections: true
|
||||
colorlinks: true
|
||||
---
|
||||
|
||||
# Code Smell 1: Long Method
|
||||
|
||||
## Beschreibung des Problems
|
||||
|
||||
Das **Long Method** Anti-Pattern tritt auf, wenn eine einzelne Methode zu viele Zeilen Code enthält und multiple Verantwortlichkeiten übernimmt. Eine solche Methode verstößt gegen das **Single Responsibility Principle (SRP)** und führt zu verschiedenen Problemen:
|
||||
|
||||
- **Schwere Verständlichkeit**: Entwickler müssen viel Zeit aufwenden, um die gesamte Methode zu durchdringen
|
||||
- **Reduzierte Testbarkeit**: Verschiedene Logikbereiche können nicht isoliert getestet werden
|
||||
- **Mangelnde Wiederverwendbarkeit**: Teilfunktionalitäten sind nicht separat nutzbar
|
||||
- **Erhöhte Fehleranfälligkeit**: Bugs sind schwerer zu lokalisieren und zu beheben
|
||||
|
||||
## Praktisches Beispiel
|
||||
|
||||
Die folgende Methode `stopRunFromBackend()` zeigt ein typisches Long Method Problem:
|
||||
|
||||
### Vorher (Problematischer Code)
|
||||
|
||||
```java
|
||||
public static void stopRunFromBackend(String message){
|
||||
// Zustandsänderungen
|
||||
isAutoRunActive = false;
|
||||
if (isSleeping)
|
||||
wakeUpFromSleep();
|
||||
else
|
||||
DataRegister.resetPC();
|
||||
|
||||
// UI-Erstellung und -Konfiguration
|
||||
Stage stoppedStage = new Stage();
|
||||
stoppedStage.setTitle("Programm unterbrochen!");
|
||||
VBox vbox = new VBox();
|
||||
vbox.setAlignment(javafx.geometry.Pos.CENTER);
|
||||
Label grundlabel = new Label("Grund: " + message);
|
||||
grundlabel.setStyle("-fx-font-size: 16px; -fx-font-weight: bold;");
|
||||
Label ueberlabel = new Label("Programm unterbrochen!");
|
||||
vbox.getChildren().add(ueberlabel);
|
||||
vbox.getChildren().add(grundlabel);
|
||||
VBox.setMargin(grundlabel, new javafx.geometry.Insets(10, 10, 10, 10));
|
||||
Scene scene = new Scene(vbox, 300, 90);
|
||||
stoppedStage.setAlwaysOnTop(true);
|
||||
stoppedStage.setScene(scene);
|
||||
stoppedStage.show();
|
||||
}
|
||||
```
|
||||
|
||||
### Identifizierte Probleme
|
||||
|
||||
- **Vermischte Verantwortlichkeiten**: Die Methode kombiniert Geschäftslogik (Zustandsänderungen) mit UI-Code
|
||||
- **Schwere Testbarkeit**: UI-Code kann nicht isoliert von der Geschäftslogik getestet werden
|
||||
- **Code-Duplikation**: Wird die Dialog-Funktionalität anderswo benötigt, muss der gesamte UI-Code kopiert werden
|
||||
|
||||
## Lösung: Extract Method Refactoring
|
||||
|
||||
Die **Extract Method** Technik löst das Problem durch Aufspaltung der langen Methode in kleinere, fokussierte Methoden:
|
||||
|
||||
### Nachher (Refactorierter Code)
|
||||
|
||||
```java
|
||||
public static void stopRunFromBackend(String message){
|
||||
handleExecutionStop();
|
||||
showInterruptionDialog(message);
|
||||
}
|
||||
|
||||
private static void handleExecutionStop(){
|
||||
isAutoRunActive = false;
|
||||
if (isSleeping)
|
||||
wakeUpFromSleep();
|
||||
else
|
||||
DataRegister.resetPC();
|
||||
}
|
||||
|
||||
private static void showInterruptionDialog(String message){
|
||||
Stage stoppedStage = new Stage();
|
||||
stoppedStage.setTitle("Programm unterbrochen!");
|
||||
|
||||
VBox vbox = new VBox();
|
||||
vbox.setAlignment(javafx.geometry.Pos.CENTER);
|
||||
|
||||
Label ueberlabel = new Label("Programm unterbrochen!");
|
||||
Label grundlabel = new Label("Grund: " + message);
|
||||
grundlabel.setStyle("-fx-font-size: 16px; -fx-font-weight: bold;");
|
||||
|
||||
vbox.getChildren().addAll(ueberlabel, grundlabel);
|
||||
VBox.setMargin(grundlabel, new javafx.geometry.Insets(10, 10, 10, 10));
|
||||
|
||||
Scene scene = new Scene(vbox, 300, 90);
|
||||
stoppedStage.setAlwaysOnTop(true);
|
||||
stoppedStage.setScene(scene);
|
||||
stoppedStage.show();
|
||||
}
|
||||
```
|
||||
|
||||
## Vorteile der Lösung
|
||||
|
||||
- **Klare Trennung der Verantwortlichkeiten**: Geschäftslogik und UI-Code sind getrennt
|
||||
- **Verbesserte Lesbarkeit**: Jede Methode hat einen klaren, fokussierten Zweck
|
||||
- **Erhöhte Wiederverwendbarkeit**: `showInterruptionDialog()` kann in anderen Kontexten genutzt werden
|
||||
- **Bessere Testbarkeit**: Geschäftslogik und UI können separat getestet werden
|
||||
|
||||
---
|
||||
|
||||
# Code Smell 2: Large Class
|
||||
|
||||
## Beschreibung des Problems
|
||||
|
||||
Eine **Large Class** entsteht, wenn eine Klasse zu viele Verantwortlichkeiten übernimmt und dadurch überladen wird. Typische Kennzeichen sind:
|
||||
|
||||
- **Hohe Anzahl an Instanzvariablen**: Die Klasse verwaltet zu viele verschiedene Datentypen
|
||||
- **Viele Methoden**: Unterschiedliche Funktionsbereiche werden in einer Klasse gemischt
|
||||
- **Multiple Domänenaspekte**: Logik, Darstellung, Benutzerinteraktion und Statusverwaltung in einer Klasse
|
||||
|
||||
## Praktisches Beispiel
|
||||
|
||||
Die Klasse `Controller_Frontend` zeigt typische Large Class Probleme:
|
||||
|
||||
### Identifizierte Probleme
|
||||
|
||||
```java
|
||||
public class Controller_Frontend {
|
||||
// GUI-Elemente
|
||||
@FXML private Button startButton;
|
||||
@FXML private Button pauseButton;
|
||||
@FXML private Label statusLabel;
|
||||
|
||||
// Zustandsverwaltung (gehört nicht hierher!)
|
||||
private static boolean isAutoRunActive = false;
|
||||
private static boolean isSleeping = false;
|
||||
private static double executionTimeMultiplier = 1.0;
|
||||
|
||||
// GUI-Steuerung
|
||||
public void handleStart() { /* ... */ }
|
||||
public void handlePause() { /* ... */ }
|
||||
|
||||
// Zustandslogik (gehört nicht hierher!)
|
||||
public void sleep() { isSleeping = true; }
|
||||
public void wakeUpFromSleep() { isSleeping = false; }
|
||||
|
||||
// ... viele weitere Methoden
|
||||
}
|
||||
```
|
||||
|
||||
### Auswirkungen
|
||||
|
||||
- **Schwere Wartbarkeit**: Änderungen in einem Bereich können unbeabsichtigte Nebeneffekte verursachen
|
||||
- **Reduzierte Testbarkeit**: Verschiedene Aspekte können nicht isoliert getestet werden
|
||||
- **Unübersichtlichkeit**: Die Klasse wird schnell unhandlich und schwer verständlich
|
||||
- **Violierung des Single Responsibility Principle**: Eine Klasse sollte nur einen Grund zur Änderung haben
|
||||
|
||||
## Lösung: Extract Class Refactoring
|
||||
|
||||
Die Lösung besteht in der Auslagerung der Zustandsverwaltung in eine separate, spezialisierte Klasse:
|
||||
|
||||
### Neue ExecutionState Klasse
|
||||
|
||||
```java
|
||||
/**
|
||||
* Zentrale Verwaltung aller Ausführungszustände.
|
||||
* Diese Klasse kapselt alle zustandsbezogenen Operationen
|
||||
* und bietet eine saubere API für den Zugriff darauf.
|
||||
*/
|
||||
public class ExecutionState {
|
||||
private static boolean isAutoRunActive = false;
|
||||
private static boolean isSleeping = false;
|
||||
private static double executionTimeMultiplier = 1.0;
|
||||
|
||||
// AutoRun-Zustand
|
||||
public static boolean isAutoRunActive() {
|
||||
return isAutoRunActive;
|
||||
}
|
||||
|
||||
public static void setAutoRunActive(boolean active) {
|
||||
isAutoRunActive = active;
|
||||
}
|
||||
|
||||
// Sleep-Zustand
|
||||
public static boolean isSleeping() {
|
||||
return isSleeping;
|
||||
}
|
||||
|
||||
public static void sleep() {
|
||||
isSleeping = true;
|
||||
}
|
||||
|
||||
public static void wakeUp() {
|
||||
isSleeping = false;
|
||||
}
|
||||
|
||||
// Ausführungsgeschwindigkeit
|
||||
public static double getExecutionTimeMultiplier() {
|
||||
return executionTimeMultiplier;
|
||||
}
|
||||
|
||||
public static void setExecutionTimeMultiplier(double multiplier) {
|
||||
if (multiplier > 0) {
|
||||
executionTimeMultiplier = multiplier;
|
||||
}
|
||||
}
|
||||
|
||||
// Hilfsmethoden
|
||||
public static void reset() {
|
||||
isAutoRunActive = false;
|
||||
isSleeping = false;
|
||||
executionTimeMultiplier = 1.0;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Refactorierte Controller Klasse
|
||||
|
||||
```java
|
||||
public class Controller_Frontend {
|
||||
// Nur noch GUI-Elemente
|
||||
@FXML private Button startButton;
|
||||
@FXML private Button pauseButton;
|
||||
@FXML private Label statusLabel;
|
||||
|
||||
// Verwendung der ExecutionState Klasse
|
||||
public void stopRunFromBackend(String message) {
|
||||
ExecutionState.setAutoRunActive(false);
|
||||
|
||||
if (ExecutionState.isSleeping()) {
|
||||
ExecutionState.wakeUp();
|
||||
} else {
|
||||
DataRegister.resetPC();
|
||||
}
|
||||
|
||||
showInterruptionDialog(message);
|
||||
}
|
||||
|
||||
// Weitere GUI-Methoden...
|
||||
}
|
||||
```
|
||||
|
||||
## Vorteile der Lösung
|
||||
|
||||
- **Klare Verantwortlichkeiten**: Controller fokussiert sich auf GUI, ExecutionState auf Zustandsverwaltung
|
||||
- **Verbesserte Testbarkeit**: Zustandslogik kann isoliert getestet werden
|
||||
- **Erhöhte Wiederverwendbarkeit**: ExecutionState kann in anderen Klassen genutzt werden
|
||||
- **Bessere Wartbarkeit**: Änderungen an der Zustandslogik betreffen nur eine Klasse
|
||||
|
||||
---
|
||||
|
||||
# Code Smell 3: Shotgun Surgery
|
||||
|
||||
## Beschreibung des Problems
|
||||
|
||||
**Shotgun Surgery** tritt auf, wenn eine kleine fachliche Änderung Modifikationen an vielen verschiedenen Stellen im Code erfordert. Dieses Anti-Pattern entsteht durch:
|
||||
|
||||
- **Zu starke Verteilung**: Zusammengehörige Funktionalität ist über viele Klassen und Methoden verstreut
|
||||
- **Mangelnde Kapselung**: Ähnliche Operationen sind nicht zentral gebündelt
|
||||
- **Duplizierte Logik**: Gleiche oder ähnliche Code-Fragmente existieren an mehreren Stellen
|
||||
|
||||
## Praktisches Beispiel
|
||||
|
||||
Die Schlafmodus-Funktionalität war ursprünglich über mehrere Bereiche verteilt:
|
||||
|
||||
### Vor dem Refactoring (Problematische Verteilung)
|
||||
|
||||
```java
|
||||
// In Controller_Frontend
|
||||
private boolean isSleeping = false;
|
||||
|
||||
public void enterSleepMode() {
|
||||
isSleeping = true;
|
||||
// Logging hier
|
||||
System.out.println("Entering sleep mode");
|
||||
}
|
||||
|
||||
// In ExecutionEngine
|
||||
private boolean sleepState = false;
|
||||
|
||||
public void pauseExecution() {
|
||||
sleepState = true;
|
||||
// Ähnliches Logging dort
|
||||
System.out.println("Execution paused - sleep mode");
|
||||
}
|
||||
|
||||
// In StatusManager
|
||||
public void checkSleepStatus() {
|
||||
if (someCondition) {
|
||||
// Wieder ähnlicher Code
|
||||
setSleeping(true);
|
||||
System.out.println("Sleep mode activated");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Identifizierte Probleme
|
||||
|
||||
- **Mehrfache Implementierung**: Sleep-Logik existiert in verschiedenen Varianten
|
||||
- **Inkonsistente Zustände**: Verschiedene Klassen können unterschiedliche Sleep-Zustände haben
|
||||
- **Hoher Änderungsaufwand**: Neue Sleep-Features müssen an mehreren Stellen implementiert werden
|
||||
- **Fehleranfälligkeit**: Beim Hinzufügen neuer Funktionen können leicht Stellen vergessen werden
|
||||
|
||||
## Lösung: Zentralisierung durch Extract Class
|
||||
|
||||
Die Lösung besteht in der Konsolidierung aller sleep-bezogenen Operationen in der `ExecutionState` Klasse:
|
||||
|
||||
### Zentralisierte Lösung
|
||||
|
||||
```java
|
||||
public class ExecutionState {
|
||||
private static boolean isSleeping = false;
|
||||
private static final Logger logger = LoggerFactory.getLogger(ExecutionState.class);
|
||||
|
||||
/**
|
||||
* Aktiviert den Schlafmodus mit einheitlichem Logging und Zustandsmanagement
|
||||
*/
|
||||
public static void sleep() {
|
||||
if (!isSleeping) {
|
||||
isSleeping = true;
|
||||
logger.info("Sleep mode activated");
|
||||
notifyStateChange("SLEEP_ACTIVATED");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deaktiviert den Schlafmodus
|
||||
*/
|
||||
public static void wakeUp() {
|
||||
if (isSleeping) {
|
||||
isSleeping = false;
|
||||
logger.info("Waking up from sleep mode");
|
||||
notifyStateChange("SLEEP_DEACTIVATED");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Überprüft den aktuellen Schlafzustand
|
||||
*/
|
||||
public static boolean isSleeping() {
|
||||
return isSleeping;
|
||||
}
|
||||
|
||||
/**
|
||||
* Erweiterte Sleep-Funktionalität mit Timeout
|
||||
*/
|
||||
public static void sleepWithTimeout(long milliseconds) {
|
||||
sleep();
|
||||
Timer timer = new Timer();
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
wakeUp();
|
||||
}
|
||||
}, milliseconds);
|
||||
}
|
||||
|
||||
private static void notifyStateChange(String event) {
|
||||
// Zentrale Benachrichtigung für alle interessierten Komponenten
|
||||
EventBus.getInstance().publish(new StateChangeEvent(event));
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Vereinfachte Nutzung in anderen Klassen
|
||||
|
||||
```java
|
||||
// In Controller_Frontend
|
||||
public void handleSleepButton() {
|
||||
ExecutionState.sleep();
|
||||
updateUI();
|
||||
}
|
||||
|
||||
// In ExecutionEngine
|
||||
public void pauseIfNeeded() {
|
||||
if (shouldPause()) {
|
||||
ExecutionState.sleep();
|
||||
}
|
||||
}
|
||||
|
||||
// In StatusManager
|
||||
public void checkAndActivateSleep() {
|
||||
if (criticalCondition()) {
|
||||
ExecutionState.sleepWithTimeout(5000); // 5 Sekunden Sleep
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Vorteile der Lösung
|
||||
|
||||
- **Einheitliche Implementierung**: Alle sleep-bezogenen Operationen verwenden dieselbe Logik
|
||||
- **Zentrale Wartung**: Änderungen müssen nur an einer Stelle vorgenommen werden
|
||||
- **Konsistente Zustände**: Nur eine Quelle der Wahrheit für den Sleep-Zustand
|
||||
- **Erweiterte Funktionalität**: Neue Features (wie Timeout) können zentral hinzugefügt werden
|
||||
- **Bessere Nachverfolgbarkeit**: Einheitliches Logging und Event-System
|
||||
|
||||
---
|
||||
|
||||
---
|
||||
title: "Anwendung von Programmierprinzipien im Projekt"
|
||||
format: html
|
||||
---
|
||||
|
||||
## Einleitung
|
||||
Im Rahmen der Refaktorisierung und Weiterentwicklung des Projekts wurde besonderer Fokus auf die Einhaltung zentraler Programmierprinzipien gelegt. Die folgenden Prinzipien wurden gezielt analysiert und angewendet:
|
||||
|
||||
## 1. SOLID-Prinzipien
|
||||
|
||||
### Single Responsibility Principle (SRP)
|
||||
Die Methode `stopRunFromBackend()` wurde in zwei unabhängige Methoden aufgeteilt:
|
||||
|
||||
```java
|
||||
public void stopRunFromBackend(String message) {
|
||||
ExecutionState.setAutoRunActive(false);
|
||||
handleSleepOrReset();
|
||||
showStopDialog(message);
|
||||
}
|
||||
|
||||
private void handleSleepOrReset() {
|
||||
if (ExecutionState.isSleeping()) {
|
||||
ExecutionState.wakeUp();
|
||||
} else {
|
||||
dataRegister.resetPC();
|
||||
}
|
||||
}
|
||||
|
||||
private static void showStopDialog(String message) {
|
||||
// GUI-Erzeugung...
|
||||
}
|
||||
```
|
||||
|
||||
### Open/Closed Principle (OCP)
|
||||
Die Klasse `ExecutionState` kapselt erweiterbare Zustandslogik, ohne dass bestehende Methoden geändert werden müssen:
|
||||
|
||||
```java
|
||||
public class ExecutionState {
|
||||
private static boolean isAutoRunActive;
|
||||
private static boolean isSleeping;
|
||||
|
||||
public static boolean isSleeping() { return isSleeping; }
|
||||
public static void wakeUp() { isSleeping = false; }
|
||||
public static void setAutoRunActive(boolean value) {
|
||||
isAutoRunActive = value;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Liskov Substitution Principle (LSP)
|
||||
`Controller_Frontend` implementiert ein Interface, wodurch die Substituierbarkeit gemäß LSP gewährleistet ist:
|
||||
|
||||
```java
|
||||
public class Controller_Frontend extends PICComponent implements FrontendControllerInterface { }
|
||||
|
||||
public void resetPC() {
|
||||
programCounter = 0;
|
||||
}
|
||||
```
|
||||
|
||||
### Interface Segregation Principle (ISP)
|
||||
Spezialisierte Interfaces sorgen dafür, dass Klassen nur relevante Funktionen implementieren:
|
||||
|
||||
```java
|
||||
public interface TimerInterface {
|
||||
void start();
|
||||
void stop();
|
||||
int getCurrentTime();
|
||||
}
|
||||
```
|
||||
|
||||
### Dependency Inversion Principle (DIP)
|
||||
Zentrale Komponenten wie `PICComponentLocator` und Interfaces lösen die Abhängigkeit von konkreten Klassen:
|
||||
|
||||
```java
|
||||
private PICComponentLocator picComponents;
|
||||
```
|
||||
|
||||
## 2. GRASP-Prinzipien
|
||||
|
||||
### Low Coupling
|
||||
Die Kopplung im Projekt ist durch Verwendung zentraler Zugriffsklassen wie `PICComponentLocator` gering gehalten.
|
||||
|
||||
```java
|
||||
private PICComponentLocator picComponents;
|
||||
```
|
||||
|
||||
### High Cohesion
|
||||
Funktionen übernehmen jeweils thematisch zusammenhängende Aufgaben:
|
||||
|
||||
```java
|
||||
public static void showStopDialog(String message) {
|
||||
Stage stoppedStage = new Stage();
|
||||
VBox vbox = new VBox();
|
||||
Label grundlabel = new Label("Grund: " + message);
|
||||
// GUI-Details ausgelassen
|
||||
stoppedStage.show();
|
||||
}
|
||||
```
|
||||
|
||||
## 3. DRY – Don’t Repeat Yourself
|
||||
Wiederverwendbare Logik zur Statuskontrolle wurde in `ExecutionState` gekapselt. GUI-Erzeugung findet zentral in `showStopDialog()` statt:
|
||||
|
||||
```java
|
||||
public class ExecutionState {
|
||||
private static boolean isSleeping;
|
||||
public static boolean isSleeping() { return isSleeping; }
|
||||
public static void wakeUp() { isSleeping = false; }
|
||||
}
|
||||
|
||||
private static void showStopDialog(String message) {
|
||||
// einmal zentral definierte GUI-Logik
|
||||
}
|
||||
25
pom.xml
25
pom.xml
@ -80,6 +80,13 @@
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>5.17.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@ -113,6 +120,24 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>properties</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<argLine>@{argLine} -javaagent:${org.mockito:mockito-core:jar}</argLine>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@ -1,9 +1,11 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import fabrik.simulator.pic16f84.interfaces.*;
|
||||
|
||||
public class Commands extends PICComponent implements CommandInterface {
|
||||
public class Commands extends ExecutionTimeSubject implements CommandInterface {
|
||||
private int wRegister;
|
||||
private long totalExecutionTime;
|
||||
private double executionTimeMultiplier = 1;
|
||||
|
||||
public Commands(){
|
||||
super();
|
||||
@ -17,16 +19,17 @@ public class Commands extends PICComponent implements CommandInterface {
|
||||
|
||||
public void addExecutionTime(int i) {
|
||||
totalExecutionTime += i;
|
||||
timer.cycles(i);
|
||||
eeprom.registerTime(false);
|
||||
super.notifyObservers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTotalExecutionTime() {
|
||||
return (totalExecutionTime * frontendController.getExecutionTimeMultiplier());
|
||||
return (totalExecutionTime * getExecutionTimeMultiplier());
|
||||
}
|
||||
|
||||
public void resetTotalExecutionTime() {
|
||||
totalExecutionTime = 0;
|
||||
super.notifyObservers();
|
||||
}
|
||||
|
||||
|
||||
@ -248,12 +251,10 @@ public class Commands extends PICComponent implements CommandInterface {
|
||||
else{
|
||||
System.out.println("Nicht gefunden!");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void SLEEP() {
|
||||
frontendController.sleep();
|
||||
ExecutionState.sleep();
|
||||
}
|
||||
|
||||
public void RETFIE() {
|
||||
@ -558,8 +559,35 @@ public class Commands extends PICComponent implements CommandInterface {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponents picComponents) {
|
||||
System.out.println("Commands");
|
||||
super.initialize(picComponents);
|
||||
public double getExecutionTimeMultiplier(){
|
||||
return executionTimeMultiplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExecutionTimeMultiplier(String option){
|
||||
switch (option) {
|
||||
case "8 MHZ":
|
||||
executionTimeMultiplier = 0.5;
|
||||
break;
|
||||
|
||||
case "4 MHZ":
|
||||
executionTimeMultiplier = 1;
|
||||
break;
|
||||
case "1 MHZ":
|
||||
executionTimeMultiplier = 4;
|
||||
break;
|
||||
case "500 HZ":
|
||||
executionTimeMultiplier = 8;
|
||||
break;
|
||||
|
||||
case "100 HZ":
|
||||
executionTimeMultiplier = 40;
|
||||
break;
|
||||
|
||||
case "32 HZ":
|
||||
executionTimeMultiplier = 125;
|
||||
break;
|
||||
}
|
||||
super.notifyObservers();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import com.gluonhq.charm.glisten.control.ToggleButtonGroup;
|
||||
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.FrontendSpecificToggleButtonGroup;
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.ToggleButtonGroup;
|
||||
|
||||
import fabrik.simulator.pic16f84.interfaces.*;
|
||||
import fabrik.simulator.pic16f84.interfaces.WatchdogTimerInterface;
|
||||
import javafx.application.Platform;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
@ -37,19 +38,12 @@ import java.util.Set;
|
||||
|
||||
import static java.lang.Math.max;
|
||||
|
||||
public class Controller_Frontend extends PICComponent implements FrontendControllerInterface {
|
||||
public class Controller_Frontend extends PICComponent implements FrontendControllerInterface, ExecutionTimeObserver {
|
||||
|
||||
private int [] prog;
|
||||
private int [][] read;
|
||||
private int [] ind;
|
||||
private PICComponents picComponents;
|
||||
private double executionTimeMultiplier = 1;
|
||||
|
||||
|
||||
|
||||
public double getExecutionTimeMultiplier(){
|
||||
return executionTimeMultiplier;
|
||||
}
|
||||
private PICComponentLocator picComponents;
|
||||
|
||||
private boolean isBreakpointReached = false;
|
||||
|
||||
@ -80,8 +74,6 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
|
||||
@FXML
|
||||
private CheckBox wdtCheck;
|
||||
|
||||
private static volatile boolean isAutoRunActive = false;
|
||||
private static volatile boolean isSleeping = false;
|
||||
|
||||
|
||||
public Controller_Frontend() {
|
||||
@ -90,55 +82,67 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
|
||||
}
|
||||
|
||||
|
||||
public boolean isSleeping (){
|
||||
return isSleeping;
|
||||
|
||||
|
||||
|
||||
//Refactoring
|
||||
|
||||
public void stopRunFromBackend(String message) {
|
||||
ExecutionState.setAutoRunActive(false);
|
||||
|
||||
handleSleepOrReset();
|
||||
showStopDialog(message);
|
||||
|
||||
}
|
||||
private void handleSleepOrReset() {
|
||||
if (ExecutionState.isSleeping()) {
|
||||
ExecutionState.wakeUp();
|
||||
} else {
|
||||
dataRegister.resetPC();
|
||||
}
|
||||
}
|
||||
|
||||
public void stopRunFromBackend(String message){
|
||||
isAutoRunActive = false;
|
||||
if (isSleeping)
|
||||
wakeUpFromSleep();
|
||||
else
|
||||
dataRegister.resetPC();
|
||||
private static void showStopDialog(String message) {
|
||||
Stage stoppedStage = new Stage();
|
||||
stoppedStage.setTitle("Programm unterbrochen!");
|
||||
|
||||
VBox vbox = new VBox();
|
||||
vbox.setAlignment(javafx.geometry.Pos.CENTER);
|
||||
|
||||
Label grundlabel = new Label("Grund: " + message);
|
||||
grundlabel.setStyle("-fx-font-size: 16px; -fx-font-weight: bold;");
|
||||
|
||||
Label ueberlabel = new Label("Programm unterbrochen!");
|
||||
vbox.getChildren().add(ueberlabel);
|
||||
vbox.getChildren().add(grundlabel);
|
||||
vbox.getChildren().addAll(ueberlabel, grundlabel);
|
||||
VBox.setMargin(grundlabel, new javafx.geometry.Insets(10, 10, 10, 10));
|
||||
|
||||
Scene scene = new Scene(vbox, 300, 90);
|
||||
stoppedStage.setAlwaysOnTop(true);
|
||||
stoppedStage.setScene(scene);
|
||||
stoppedStage.show();
|
||||
}
|
||||
|
||||
public void sleep() {
|
||||
isSleeping = true;
|
||||
}
|
||||
|
||||
public void wakeUpFromSleep() {
|
||||
isSleeping = false;
|
||||
}
|
||||
|
||||
//Refactoring Ende
|
||||
|
||||
|
||||
|
||||
@FXML
|
||||
private void stopAutoRun(ActionEvent event) {
|
||||
isAutoRunActive = false;
|
||||
ExecutionState.setAutoRunActive(false);
|
||||
}
|
||||
|
||||
|
||||
@FXML
|
||||
public void autoRunGUI(ActionEvent event) {
|
||||
if (!isAutoRunActive) {
|
||||
isAutoRunActive = true;
|
||||
if (!ExecutionState.isAutoRunActive()) {
|
||||
ExecutionState.setAutoRunActive(true) ;
|
||||
}
|
||||
|
||||
Thread autoRunThread = new Thread(() -> {
|
||||
try {
|
||||
while (dataRegister.getPC() < prog.length && isAutoRunActive){
|
||||
while (dataRegister.getPC() < prog.length && ExecutionState.isAutoRunActive()){
|
||||
|
||||
Platform.runLater(() -> {
|
||||
try {
|
||||
@ -158,31 +162,10 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void updateExecutionTimeMultiplier() {
|
||||
String selectedOption = executionTimeComboBox.getValue();
|
||||
switch (selectedOption) {
|
||||
case "8 MHZ":
|
||||
executionTimeMultiplier = 0.5;
|
||||
break;
|
||||
|
||||
case "4 MHZ":
|
||||
executionTimeMultiplier = 1;
|
||||
break;
|
||||
case "1 MHZ":
|
||||
executionTimeMultiplier = 4;
|
||||
break;
|
||||
case "500 HZ":
|
||||
executionTimeMultiplier = 8;
|
||||
break;
|
||||
|
||||
case "100 HZ":
|
||||
executionTimeMultiplier = 40;
|
||||
break;
|
||||
|
||||
case "32 HZ":
|
||||
executionTimeMultiplier = 125;
|
||||
break;
|
||||
}
|
||||
executionTime.setExecutionTimeMultiplier(selectedOption);
|
||||
}
|
||||
|
||||
@FXML
|
||||
@ -194,7 +177,7 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
|
||||
|
||||
int currentIndex;
|
||||
// Aktuelle Zeile abrufen
|
||||
if (!isSleeping)
|
||||
if (!ExecutionState.isSleeping())
|
||||
currentIndex = ind[dataRegister.getPC()];
|
||||
else
|
||||
currentIndex = ind[dataRegister.getPC()]-1;
|
||||
@ -223,14 +206,14 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
|
||||
lstContentListView.getSelectionModel().select(currentIndex);
|
||||
|
||||
String selectedRowStyle;
|
||||
if (!isSleeping)
|
||||
if (!ExecutionState.isSleeping())
|
||||
selectedRowStyle = "-fx-background-color: red; -fx-text-fill: white;";
|
||||
else
|
||||
selectedRowStyle = "-fx-background-color: teal; -fx-text-fill: white;";
|
||||
|
||||
markSelectedRow(currentIndex, selectedRowStyle);
|
||||
|
||||
if (!isSleeping) {
|
||||
if (!ExecutionState.isSleeping()) {
|
||||
commands.decode(prog[dataRegister.getPC()]);
|
||||
dataRegister.increasePC();
|
||||
}
|
||||
@ -238,15 +221,14 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
|
||||
commands.decode(0);
|
||||
}
|
||||
watchdogTimer.testAndTrigger();
|
||||
Table.refresh();
|
||||
table.refresh();
|
||||
CreateWindow.refreshTable();
|
||||
ioPorts.refreshUI(getTRISbuttons(), getPORTbuttons());
|
||||
updateStack();
|
||||
updateWatchdog();
|
||||
double totalExecutionTime = commands.getTotalExecutionTime();
|
||||
totalExecutionTimeLabel.setText("Total Execution Time: " + totalExecutionTime + "µs");
|
||||
}
|
||||
|
||||
|
||||
private void markSelectedRow(int currentIndex, String selectedRowStyle) {
|
||||
lstContentListView.setCellFactory(column -> new ListCell<String>() {
|
||||
@Override
|
||||
@ -298,13 +280,13 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
|
||||
} catch (NullPointerException ignored) {}
|
||||
}
|
||||
programStack.reset();
|
||||
wakeUpFromSleep();
|
||||
ExecutionState.wakeUp();
|
||||
breakpoints.clear();
|
||||
ioPorts.refreshUI(getTRISbuttons(), getPORTbuttons());
|
||||
commands.resetTotalExecutionTime();
|
||||
executionTime.resetTotalExecutionTime();
|
||||
watchdogTimer.reset();
|
||||
wdtCheck.setSelected(false);
|
||||
Table.refresh();
|
||||
table.refresh();
|
||||
read = ParseFile.parseDatei(fileAddress);
|
||||
prog = read [0];
|
||||
ind = read[1];
|
||||
@ -496,27 +478,27 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
|
||||
|
||||
|
||||
|
||||
private static void setTRISbuttons(ToggleButtonGroup[] allButtons) {
|
||||
private void setTRISbuttons(ToggleButtonGroup[] allButtons) {
|
||||
allTRISbuttons = allButtons;
|
||||
}
|
||||
|
||||
public static ToggleButtonGroup [] getTRISbuttons() {
|
||||
public FrontendSpecificToggleButtonGroup [] getTRISbuttons() {
|
||||
return allTRISbuttons;
|
||||
}
|
||||
|
||||
private static void setPORTbuttons(ToggleButtonGroup[] allButtons) {
|
||||
private void setPORTbuttons(ToggleButtonGroup[] allButtons) {
|
||||
allPORTbuttons = allButtons;
|
||||
}
|
||||
|
||||
public static ToggleButtonGroup [] getPORTbuttons() {
|
||||
public ToggleButtonGroup [] getPORTbuttons() {
|
||||
return allPORTbuttons;
|
||||
}
|
||||
|
||||
public static Circle[] getLEDsA() {
|
||||
public Circle[] getLEDsA() {
|
||||
return allLEDsA;
|
||||
}
|
||||
|
||||
public static Circle[] getLEDsB() {
|
||||
public Circle[] getLEDsB() {
|
||||
return allLEDsB;
|
||||
}
|
||||
|
||||
@ -582,13 +564,16 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponents picComponents) {
|
||||
super.initialize(picComponents);
|
||||
this.picComponents = picComponents;
|
||||
public void initialize(PICComponentLocator locator) {
|
||||
super.initialize(locator);
|
||||
executionTime.registerObserver(this);
|
||||
this.picComponents = locator;
|
||||
System.out.println("Frontend");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executionTimeChanged() {
|
||||
totalExecutionTimeLabel.setText("Total Execution Time: " + executionTime.getTotalExecutionTime() + "µs");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,47 +1,41 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.VBox;
|
||||
import fabrik.simulator.pic16f84.interfaces.*;
|
||||
import javafx.application.Application;
|
||||
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
|
||||
import javafx.scene.control.Tab;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
public class CreateWindow extends Application {
|
||||
private PICComponents picComponents = new PICComponents(); // Subjekt
|
||||
public class CreateWindow extends Application implements WindowManagement {
|
||||
private static PICComponentLocator picComponents; // Subjekt
|
||||
public static GridPane grid = new GridPane();
|
||||
private static VBox table;
|
||||
private TableInterface table;
|
||||
private static VBox tableBox;
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws IOException {
|
||||
|
||||
picComponents.registerComponent(CommandInterface.class, new Commands());
|
||||
picComponents.registerComponent(ToggleButtonInterface.class, new ToggleButtonGroupExt());
|
||||
picComponents.registerComponent(FrontendControllerInterface.class, new Controller_Frontend());
|
||||
picComponents.registerComponent(DataRegisterInterface.class, new DataRegister());
|
||||
picComponents.registerComponent(EEPROMInterface.class, new EEPROM());
|
||||
picComponents.registerComponent(InterruptInterface.class, new Interrupts());
|
||||
picComponents.registerComponent(IOPortInterface.class, new IOPorts());
|
||||
picComponents.registerComponent(PreScalerInterface.class, new PreScaler());
|
||||
picComponents.registerComponent(ProgramStackInterface.class, new ProgramStack());
|
||||
picComponents.registerComponent(TimerInterface.class, new Timer());
|
||||
picComponents.registerComponent(WatchdogTimerInterface.class, new WatchdogTimer());
|
||||
picComponents.registerComponent(TableInterface.class, new Table());
|
||||
picComponents.registerComponent(FrontendControllerInterface.class, new Controller_Frontend());
|
||||
picComponents.initAll();
|
||||
|
||||
table = picComponents.getComponent(TableInterface.class);
|
||||
|
||||
FXMLLoader codewindow = new FXMLLoader(CreateWindow.class.getResource("frontend.fxml"));
|
||||
codewindow.setController(picComponents.getComponent(FrontendControllerInterface.class));
|
||||
Parent code = codewindow.load();
|
||||
table = Table.init(picComponents);
|
||||
grid.add(table, 1, 1);
|
||||
|
||||
tableBox = (VBox) table.getTable();
|
||||
grid.add(tableBox, 1, 1);
|
||||
grid.add(code, 0, 1);
|
||||
|
||||
grid.relocate(0, 0);
|
||||
@ -53,16 +47,29 @@ public class CreateWindow extends Application {
|
||||
primaryStage.show();
|
||||
}
|
||||
|
||||
public void startFromMain(String[] args){
|
||||
launch(args);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
|
||||
public static void refreshTable() {
|
||||
grid.getChildren().remove(table);
|
||||
table= Table.refresh();
|
||||
grid.add(table, 1, 1);
|
||||
TableInterface table = picComponents.getComponent(TableInterface.class);
|
||||
grid.getChildren().remove(table.getTable());
|
||||
table.refresh();
|
||||
tableBox = (VBox) table.getTable();
|
||||
grid.add(tableBox, 1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponentLocator picComponents) {
|
||||
CreateWindow.picComponents = picComponents;
|
||||
}
|
||||
|
||||
public CreateWindow (){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -39,8 +39,8 @@ public class DataRegister extends PICComponent implements DataRegisterInterface
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponents picComponents) {
|
||||
super.initialize(picComponents);
|
||||
public void initialize(PICComponentLocator locator) {
|
||||
super.initialize(locator);
|
||||
System.out.println("DataRegister.\n");
|
||||
initOrReset();
|
||||
}
|
||||
@ -60,7 +60,7 @@ public class DataRegister extends PICComponent implements DataRegisterInterface
|
||||
carryFlag = 0;
|
||||
zeroFlag = 0;
|
||||
digitCarryFlag = 0;
|
||||
ioPorts.resetTRIS();
|
||||
if (null != ioPorts) ioPorts.resetTRIS();
|
||||
System.out.println(Arrays.toString(dataRegister));
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
|
||||
import eu.hansolo.tilesfx.Command;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
@ -14,7 +13,7 @@ import java.nio.file.Paths;
|
||||
|
||||
import fabrik.simulator.pic16f84.interfaces.*;
|
||||
|
||||
public class EEPROM extends PICComponent implements EEPROMInterface {
|
||||
public class EEPROM extends PICComponent implements EEPROMInterface, ExecutionTimeObserver {
|
||||
private final int EEDATA = 0x08;
|
||||
private final int EEADR = 0x09;
|
||||
private final int EECON1 = 0x88;
|
||||
@ -36,6 +35,7 @@ public class EEPROM extends PICComponent implements EEPROMInterface {
|
||||
}
|
||||
|
||||
public long read (int address) {
|
||||
if (address < 0) return 0;
|
||||
FileReader reader;
|
||||
try {
|
||||
reader = new FileReader("eeprom.json");
|
||||
@ -60,6 +60,7 @@ public class EEPROM extends PICComponent implements EEPROMInterface {
|
||||
}
|
||||
|
||||
public void write (int address, long data) {
|
||||
if (address < 0) return;
|
||||
FileReader reader;
|
||||
try {
|
||||
reader = new FileReader("eeprom.json");
|
||||
@ -82,13 +83,13 @@ public class EEPROM extends PICComponent implements EEPROMInterface {
|
||||
dataRegister.setDirectBit(EECON1, WRERR, 1);
|
||||
return;
|
||||
}
|
||||
registerTime(true);
|
||||
registerTime(executionTime.getTotalExecutionTime(), true);
|
||||
}
|
||||
|
||||
public void registerTime(boolean reset) {
|
||||
public void registerTime(double executionTime, boolean reset) {
|
||||
if (reset)
|
||||
startTime = commands.getTotalExecutionTime();
|
||||
else if ((commands.getTotalExecutionTime() >= (startTime + 1000)) && writeControl) {
|
||||
startTime = executionTime;
|
||||
else if ((executionTime >= (startTime + 1000)) && writeControl) {
|
||||
eecon2stages = new boolean[]{false, false};
|
||||
dataRegister.setDirectBit(EECON1, EEIF, 1);
|
||||
dataRegister.setDirectBit(EECON1, WR, 0);
|
||||
@ -171,8 +172,13 @@ public class EEPROM extends PICComponent implements EEPROMInterface {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponents picComponents) {
|
||||
System.out.println("EEPROM");
|
||||
super.initialize(picComponents);
|
||||
public void initialize(PICComponentLocator locator) {
|
||||
super.initialize(locator);
|
||||
executionTime.registerObserver(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executionTimeChanged() {
|
||||
registerTime(executionTime.getTotalExecutionTime(), false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,7 +145,7 @@ public class EmptyRegister implements DataRegisterInterface {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponents picComponents) {
|
||||
public void initialize(PICComponentLocator picComponents) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
19
src/main/java/fabrik/simulator/pic16f84/ExecutionState.java
Normal file
19
src/main/java/fabrik/simulator/pic16f84/ExecutionState.java
Normal file
@ -0,0 +1,19 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
public class ExecutionState {
|
||||
|
||||
private static boolean isAutoRunActive = false;
|
||||
private static boolean isSleeping = false;
|
||||
private static double executionTimeMultiplier = 1;
|
||||
|
||||
public static boolean isAutoRunActive() { return isAutoRunActive; }
|
||||
public static void setAutoRunActive(boolean active) { isAutoRunActive = active; }
|
||||
|
||||
public static boolean isSleeping() { return isSleeping; }
|
||||
public static void sleep() { isSleeping = true; }
|
||||
public static void wakeUp() { isSleeping = false; }
|
||||
|
||||
public static double getExecutionTimeMultiplier() { return executionTimeMultiplier; }
|
||||
public static void setExecutionTimeMultiplier(double multiplier) { executionTimeMultiplier = multiplier; }
|
||||
}
|
||||
|
||||
@ -0,0 +1,54 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import fabrik.simulator.pic16f84.interfaces.ExecutionTimeObserver;
|
||||
import fabrik.simulator.pic16f84.interfaces.PICComponentInterface;
|
||||
|
||||
public abstract class ExecutionTimeSubject extends PICComponent implements PICComponentInterface{
|
||||
private Set<ExecutionTimeObserver> observers;
|
||||
|
||||
public ExecutionTimeSubject(){
|
||||
super();
|
||||
this.observers = new HashSet<>();
|
||||
}
|
||||
|
||||
|
||||
public void registerObserver(ExecutionTimeObserver observer){
|
||||
observers.add(observer);
|
||||
}
|
||||
|
||||
public void unregisterObserver(ExecutionTimeObserver observer){
|
||||
observers.remove(observer);
|
||||
}
|
||||
|
||||
protected void notifyObservers(){
|
||||
observers.forEach(o -> o.executionTimeChanged());
|
||||
}
|
||||
|
||||
public double getTotalExecutionTime(){
|
||||
throw new UnsupportedOperationException("No class implements ExecutionTimeSubject correctly!");
|
||||
}
|
||||
|
||||
public void addExecutionTime(int i){
|
||||
throw new UnsupportedOperationException("No class implements ExecutionTimeSubject correctly!");
|
||||
}
|
||||
|
||||
public double getExecutionTimeMultiplier(){
|
||||
throw new UnsupportedOperationException("No class implements ExecutionTimeSubject correctly!");
|
||||
}
|
||||
|
||||
public void setExecutionTimeMultiplier(String option){
|
||||
throw new UnsupportedOperationException("No class implements ExecutionTimeSubject correctly!");
|
||||
}
|
||||
|
||||
public void resetTotalExecutionTime(){
|
||||
throw new UnsupportedOperationException("No class implements ExecutionTimeSubject correctly!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponentLocator locator) {
|
||||
super.initialize(locator);
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import com.gluonhq.charm.glisten.control.ToggleButtonGroup;
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.FrontendSpecificToggleButtonGroup;
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.ToggleButtonGroup;
|
||||
import fabrik.simulator.pic16f84.interfaces.*;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.control.ToggleButton;
|
||||
@ -77,7 +78,7 @@ public class IOPorts extends PICComponent implements IOPortInterface {
|
||||
dataRegister.setDirectRegister(TRISB, trisLatch[B]);
|
||||
if (((trisLatch[A] >> 4) & 1 )== 1)
|
||||
timer.incrementFromPin(dataRegister.getDirectRegister(PORTA));
|
||||
ToggleButtonGroup[] buttons = Controller_Frontend.getPORTbuttons();
|
||||
ToggleButtonGroup[] buttons = (ToggleButtonGroup[]) frontendController.getPORTbuttons();
|
||||
for (int i = 0; i < buttons.length; i++){
|
||||
int port = (i < 8) ? PORTA : PORTB;
|
||||
int bit = i % 8;
|
||||
@ -139,7 +140,7 @@ public class IOPorts extends PICComponent implements IOPortInterface {
|
||||
int tris = params[0];
|
||||
int bit = params[1];
|
||||
int value = params[2];
|
||||
ToggleButtonGroup [] buttonsPORT = Controller_Frontend.getPORTbuttons();
|
||||
ToggleButtonGroup [] buttonsPORT = (ToggleButtonGroup[]) frontendController.getPORTbuttons();
|
||||
if (value == 1){
|
||||
setBit(tris, bit);
|
||||
buttonsPORT[(tris-TRISA)*8 + bit].setDisable(false);
|
||||
@ -192,7 +193,7 @@ public class IOPorts extends PICComponent implements IOPortInterface {
|
||||
}
|
||||
|
||||
public void refreshTable(ToggleButtonGroup parent) {
|
||||
Table.refresh();
|
||||
table.refresh();
|
||||
CreateWindow.refreshTable();
|
||||
}
|
||||
|
||||
@ -227,8 +228,24 @@ public class IOPorts extends PICComponent implements IOPortInterface {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponents picComponents) {
|
||||
super.initialize(picComponents);
|
||||
public void initialize(PICComponentLocator locator) {
|
||||
super.initialize(locator);
|
||||
System.out.println("IOPorts.\n");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPORTfromUI(FrontendSpecificToggleButtonGroup parent) throws IOException {
|
||||
setPORTfromUI((ToggleButtonGroup) parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTRISfromUI(FrontendSpecificToggleButtonGroup parent) throws IOException {
|
||||
setTRISfromUI((ToggleButtonGroup) parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshUI(FrontendSpecificToggleButtonGroup[] trisButtons,
|
||||
FrontendSpecificToggleButtonGroup[] portButtons) {
|
||||
refreshUI((ToggleButtonGroup[]) trisButtons, (ToggleButtonGroup[]) portButtons);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,5 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import eu.hansolo.tilesfx.Command;
|
||||
import fabrik.simulator.pic16f84.interfaces.CommandInterface;
|
||||
import fabrik.simulator.pic16f84.interfaces.DataRegisterInterface;
|
||||
import fabrik.simulator.pic16f84.interfaces.FrontendControllerInterface;
|
||||
import fabrik.simulator.pic16f84.interfaces.InterruptInterface;
|
||||
|
||||
public class Interrupts extends PICComponent implements InterruptInterface {
|
||||
@ -34,7 +30,7 @@ public class Interrupts extends PICComponent implements InterruptInterface {
|
||||
enableFlag = dataRegister.getDirectBit(INTCON, enableFlag);
|
||||
int globalFlag = dataRegister.getDirectBit(INTCON, GIE);
|
||||
if (enableFlag == 1) {
|
||||
frontendController.wakeUpFromSleep();
|
||||
ExecutionState.wakeUp();
|
||||
if (globalFlag == 1) {
|
||||
dataRegister.clearBit(INTCON, GIE);
|
||||
commands.CALL(ISR);
|
||||
@ -66,7 +62,7 @@ public class Interrupts extends PICComponent implements InterruptInterface {
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponents picComponents) {
|
||||
super.initialize(picComponents);
|
||||
public void initialize(PICComponentLocator locator) {
|
||||
super.initialize(locator);
|
||||
}
|
||||
}
|
||||
|
||||
25
src/main/java/fabrik/simulator/pic16f84/Main.java
Normal file
25
src/main/java/fabrik/simulator/pic16f84/Main.java
Normal file
@ -0,0 +1,25 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import fabrik.simulator.pic16f84.interfaces.*;
|
||||
|
||||
public class Main {
|
||||
private static final PICComponentLocator picComponents = new PICComponentLocator(); // Subjekt
|
||||
|
||||
public static void main(String[] args) {
|
||||
Commands commands = new Commands();
|
||||
picComponents.registerComponent(CommandInterface.class, commands);
|
||||
picComponents.registerComponent(ExecutionTimeSubject.class, commands);
|
||||
picComponents.registerComponent(DataRegisterInterface.class, new DataRegister());
|
||||
picComponents.registerComponent(EEPROMInterface.class, new EEPROM());
|
||||
picComponents.registerComponent(InterruptInterface.class, new Interrupts());
|
||||
picComponents.registerComponent(PreScalerInterface.class, new PreScaler());
|
||||
picComponents.registerComponent(ProgramStackInterface.class, new ProgramStack());
|
||||
picComponents.registerComponent(TimerInterface.class, new Timer());
|
||||
picComponents.registerComponent(WatchdogTimerInterface.class, new WatchdogTimer());
|
||||
CreateWindow window = new CreateWindow();
|
||||
picComponents.registerComponent(WindowManagement.class, window);
|
||||
picComponents.initAll();
|
||||
|
||||
window.startFromMain(new String[]{});
|
||||
}
|
||||
}
|
||||
@ -5,31 +5,31 @@ import fabrik.simulator.pic16f84.interfaces.*;
|
||||
public abstract class PICComponent {
|
||||
DataRegisterInterface dataRegister;
|
||||
EEPROMInterface eeprom;
|
||||
PreScaler preScaler;
|
||||
PreScalerInterface preScaler;
|
||||
IOPortInterface ioPorts;
|
||||
TimerInterface timer;
|
||||
InterruptInterface interrupts;
|
||||
//TableInterface table;
|
||||
//WindowManagement createWindow;
|
||||
TableInterface table;
|
||||
FrontendControllerInterface frontendController;
|
||||
WatchdogTimerInterface watchdogTimer;
|
||||
ProgramStackInterface programStack;
|
||||
CommandInterface commands;
|
||||
ExecutionTimeSubject executionTime;
|
||||
ToggleButtonInterface toggleButtonExt;
|
||||
|
||||
void initialize(PICComponents picComponents) {
|
||||
toggleButtonExt = (ToggleButtonInterface) picComponents.getComponent(ToggleButtonInterface.class);
|
||||
dataRegister = (DataRegisterInterface) picComponents.getComponent(DataRegisterInterface.class);
|
||||
eeprom = (EEPROMInterface) picComponents.getComponent(EEPROMInterface.class);
|
||||
ioPorts = (IOPortInterface) picComponents.getComponent(IOPortInterface.class);
|
||||
preScaler = (PreScaler) picComponents.getComponent(PreScalerInterface.class);
|
||||
timer = (TimerInterface) picComponents.getComponent(TimerInterface.class);
|
||||
interrupts = (InterruptInterface) picComponents.getComponent(InterruptInterface.class);
|
||||
//table = (TableInterface) picComponents.getComponent(TableInterface.class);
|
||||
//createWindow = (WindowManagement) picComponents.getComponent(WindowManagement.class);
|
||||
frontendController = (FrontendControllerInterface) picComponents.getComponent(FrontendControllerInterface.class);
|
||||
watchdogTimer = (WatchdogTimerInterface) picComponents.getComponent(WatchdogTimerInterface.class);
|
||||
programStack = (ProgramStackInterface) picComponents.getComponent(ProgramStackInterface.class);
|
||||
commands = (CommandInterface) picComponents.getComponent(CommandInterface.class);
|
||||
public void initialize(PICComponentLocator locator) {
|
||||
toggleButtonExt = locator.getComponent(ToggleButtonInterface.class);
|
||||
dataRegister = locator.getComponent(DataRegisterInterface.class);
|
||||
eeprom = locator.getComponent(EEPROMInterface.class);
|
||||
ioPorts = locator.getComponent(IOPortInterface.class);
|
||||
preScaler = locator.getComponent(PreScalerInterface.class);
|
||||
timer = locator.getComponent(TimerInterface.class);
|
||||
interrupts = locator.getComponent(InterruptInterface.class);
|
||||
frontendController = locator.getComponent(FrontendControllerInterface.class);
|
||||
watchdogTimer = locator.getComponent(WatchdogTimerInterface.class);
|
||||
programStack = locator.getComponent(ProgramStackInterface.class);
|
||||
commands = locator.getComponent(CommandInterface.class);
|
||||
table = locator.getComponent(TableInterface.class);
|
||||
executionTime = locator.getComponent(ExecutionTimeSubject.class);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,10 +4,11 @@ import fabrik.simulator.pic16f84.interfaces.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class PICComponents {
|
||||
public class PICComponentLocator {
|
||||
// https://en.wikipedia.org/wiki/Service_locator_pattern
|
||||
private final HashMap<Class<? extends PICComponentInterface>, PICComponentInterface> componentCatalogue;
|
||||
|
||||
public PICComponents() {
|
||||
public PICComponentLocator() {
|
||||
super();
|
||||
this.componentCatalogue = new HashMap<>();
|
||||
}
|
||||
@ -16,8 +17,9 @@ public class PICComponents {
|
||||
this.componentCatalogue.put(componentClass, component);
|
||||
}
|
||||
|
||||
public PICComponentInterface getComponent(Class<? extends PICComponentInterface> componentClass) {
|
||||
return this.componentCatalogue.get(componentClass);
|
||||
public <T extends PICComponentInterface> T getComponent(Class<T> componentClass) {
|
||||
T component = (T) this.componentCatalogue.get(componentClass);
|
||||
return component;
|
||||
}
|
||||
|
||||
public void initAll() {
|
||||
@ -54,7 +54,7 @@ public class PreScaler extends PICComponent implements PreScalerInterface {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponents picComponents) {
|
||||
super.initialize(picComponents);
|
||||
public void initialize(PICComponentLocator locator) {
|
||||
super.initialize(locator);
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ public class ProgramStack extends PICComponent implements ProgramStackInterface
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponents picComponents) {
|
||||
super.initialize(picComponents);
|
||||
public void initialize(PICComponentLocator locator) {
|
||||
super.initialize(locator);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,34 +1,25 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.VBox;
|
||||
import fabrik.simulator.pic16f84.interfaces.*;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.geometry.Insets;
|
||||
|
||||
import javafx.scene.chart.PieChart;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableView;
|
||||
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.VBox;
|
||||
|
||||
|
||||
import static javafx.application.Application.launch;
|
||||
|
||||
public class Table {
|
||||
|
||||
|
||||
//Hier wird die Tabelle aktualisiert
|
||||
//Tabelle aktualisieren
|
||||
private static DataRegisterInterface dataRegister;
|
||||
private static CommandInterface commands;
|
||||
|
||||
public class Table extends PICComponent implements TableInterface {
|
||||
private VBox tableBox;
|
||||
private static final int NUM_COLUMNS = 8; // Anzahl der Spalten
|
||||
private static final double TABLE_WIDTH = 425; // Breite der TableView
|
||||
private static final double TABLE_HEIGHT = 600; // Höhe der TableView
|
||||
private static IOPortInterface ioPorts;
|
||||
private static PreScalerInterface preScaler;
|
||||
|
||||
private static String formatHex(String s) {
|
||||
return (s.length() == 1) ? "0" + s : s;
|
||||
@ -46,27 +37,16 @@ public class Table {
|
||||
return s;
|
||||
}
|
||||
|
||||
public static VBox init(PICComponents picComponents){
|
||||
dataRegister = (DataRegisterInterface) picComponents.getComponent(DataRegisterInterface.class);
|
||||
commands = (CommandInterface) picComponents.getComponent(CommandInterface.class);
|
||||
ioPorts = (IOPortInterface) picComponents.getComponent(IOPortInterface.class);
|
||||
preScaler = (PreScalerInterface) picComponents.getComponent(PreScalerInterface.class);
|
||||
return refresh();
|
||||
public VBox getTable(){
|
||||
refresh();
|
||||
return tableBox;
|
||||
}
|
||||
|
||||
public static VBox refresh() {
|
||||
|
||||
// Erstelle eine Instanz der dataRegister-Klasse
|
||||
|
||||
|
||||
public void refresh() {
|
||||
// Erstelle eine TableView für die Datenanzeige
|
||||
TableView<DataEntry[]> tableView = new TableView<>();
|
||||
tableView.setPrefWidth(TABLE_WIDTH);
|
||||
tableView.setPrefHeight(TABLE_HEIGHT);
|
||||
|
||||
|
||||
|
||||
|
||||
// Erstelle Spalten für die TableView
|
||||
for (int i = 0; i < NUM_COLUMNS; i++) {
|
||||
TableColumn<DataEntry[], String> column = new TableColumn<>("0" + (i));
|
||||
@ -80,7 +60,6 @@ public class Table {
|
||||
});
|
||||
tableView.getColumns().add(column);
|
||||
}
|
||||
|
||||
// Fülle die TableView mit Daten aus dem Array
|
||||
int numRows = (int) Math.ceil((double) dataRegister.getDataRegister().length / NUM_COLUMNS);
|
||||
for (int row = 0; row < numRows; row++) {
|
||||
@ -136,14 +115,12 @@ public class Table {
|
||||
VBox table = new VBox();
|
||||
table.getChildren().addAll(tableView, labelsAndButton);
|
||||
VBox.setMargin(tableView, new Insets(0, 0, 0, 0));
|
||||
|
||||
return table;
|
||||
|
||||
tableBox = table;
|
||||
}
|
||||
|
||||
private static void triggerReset() {
|
||||
private void triggerReset() {
|
||||
dataRegister.initDataRegister();
|
||||
ioPorts.refreshUI(Controller_Frontend.getTRISbuttons(), Controller_Frontend.getPORTbuttons());
|
||||
ioPorts.refreshUI(frontendController.getTRISbuttons(), frontendController.getPORTbuttons());
|
||||
CreateWindow.refreshTable();
|
||||
}
|
||||
|
||||
@ -170,5 +147,7 @@ public class Table {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void initialize(PICComponentLocator picComponents) {
|
||||
super.initialize(picComponents);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import fabrik.simulator.pic16f84.interfaces.DataRegisterInterface;
|
||||
import fabrik.simulator.pic16f84.interfaces.FrontendControllerInterface;
|
||||
import fabrik.simulator.pic16f84.interfaces.InterruptInterface;
|
||||
import fabrik.simulator.pic16f84.interfaces.ExecutionTimeObserver;
|
||||
import fabrik.simulator.pic16f84.interfaces.TimerInterface;
|
||||
|
||||
public class Timer extends PICComponent implements TimerInterface {
|
||||
public class Timer extends PICComponent implements TimerInterface, ExecutionTimeObserver {
|
||||
private final int TIMERREG = 0x1;
|
||||
private final int T0SE = 0x4;
|
||||
private final int T0CS = 0x5;
|
||||
@ -30,7 +28,7 @@ public class Timer extends PICComponent implements TimerInterface {
|
||||
|
||||
|
||||
public void incrementFromPin (int register){
|
||||
if ((dataRegister.getDirectBit(OPTION, T0CS) == 1) && !frontendController.isSleeping()){
|
||||
if ((dataRegister.getDirectBit(OPTION, T0CS) == 1) && !ExecutionState.isSleeping()){
|
||||
int newpin = (register >> 4) & 1;
|
||||
if (newpin != oldpin) {
|
||||
if (dataRegister.getDirectBit(OPTION, T0SE) == 0) {
|
||||
@ -67,7 +65,13 @@ public class Timer extends PICComponent implements TimerInterface {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponents picComponents) {
|
||||
super.initialize(picComponents);
|
||||
public void initialize(PICComponentLocator locator) {
|
||||
super.initialize(locator);
|
||||
executionTime.registerObserver(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executionTimeChanged() {
|
||||
cycles((int) executionTime.getTotalExecutionTime());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import com.gluonhq.charm.glisten.control.ToggleButtonGroup;
|
||||
import fabrik.simulator.pic16f84.interfaces.IOPortInterface;
|
||||
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.FrontendSpecificObject;
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.ToggleButtonGroup;
|
||||
import fabrik.simulator.pic16f84.interfaces.ToggleButtonInterface;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.event.EventHandler;
|
||||
@ -11,7 +12,7 @@ import javafx.scene.input.MouseEvent;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ToggleButtonGroupExt extends PICComponent implements ToggleButtonInterface {
|
||||
public class ToggleButtonGroupExt extends PICComponent implements ToggleButtonInterface, FrontendSpecificObject {
|
||||
|
||||
|
||||
private static ToggleButtonGroupExt me;
|
||||
@ -58,9 +59,9 @@ public class ToggleButtonGroupExt extends PICComponent implements ToggleButtonIn
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponents picComponents) {
|
||||
|
||||
public void initialize(PICComponentLocator locator) {
|
||||
System.out.println("ToggleButtonGroupExt");
|
||||
super.initialize(picComponents);
|
||||
super.initialize(locator);
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,18 +21,18 @@ public class WatchdogTimer extends PICComponent implements WatchdogTimerInterfac
|
||||
if (enabled) {
|
||||
if (realtimer >= (watchdogTime + lastReset - 1)) {
|
||||
dataRegister.clearBit(3, 4);
|
||||
lastReset = commands.getTotalExecutionTime();
|
||||
lastReset = executionTime.getTotalExecutionTime();
|
||||
frontendController.stopRunFromBackend("Watchdog Timer");
|
||||
}
|
||||
else {
|
||||
rawtimer++;
|
||||
realtimer = (long) (rawtimer * frontendController.getExecutionTimeMultiplier());
|
||||
realtimer = (long) (rawtimer * executionTime.getExecutionTimeMultiplier());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void reset (){
|
||||
lastReset = commands.getTotalExecutionTime();
|
||||
lastReset = executionTime.getTotalExecutionTime();
|
||||
rawtimer = 0;
|
||||
realtimer = 0;
|
||||
preScaler.reset();
|
||||
@ -53,7 +53,7 @@ public class WatchdogTimer extends PICComponent implements WatchdogTimerInterfac
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponents picComponents) {
|
||||
super.initialize(picComponents);
|
||||
public void initialize(PICComponentLocator locator) {
|
||||
super.initialize(locator);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
package fabrik.simulator.pic16f84.frontendspecifics;
|
||||
|
||||
public interface FrontendSpecificObject {
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
package fabrik.simulator.pic16f84.frontendspecifics;
|
||||
|
||||
public interface FrontendSpecificToggleButtonGroup extends FrontendSpecificObject{
|
||||
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
package fabrik.simulator.pic16f84.frontendspecifics;
|
||||
|
||||
public interface FrontendSpecificVBox extends FrontendSpecificObject {
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package fabrik.simulator.pic16f84.frontendspecifics;
|
||||
|
||||
import javafx.scene.control.ToggleButton;
|
||||
|
||||
public class ToggleButtonGroup extends com.gluonhq.charm.glisten.control.ToggleButtonGroup implements FrontendSpecificToggleButtonGroup {
|
||||
public ToggleButtonGroup(){
|
||||
super();
|
||||
}
|
||||
|
||||
public ToggleButtonGroup(ToggleButton... toggles) {
|
||||
super(toggles);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
package fabrik.simulator.pic16f84.frontendspecifics;
|
||||
|
||||
public class VBox extends javafx.scene.layout.VBox implements FrontendSpecificVBox {
|
||||
public VBox(){
|
||||
super();
|
||||
}
|
||||
}
|
||||
@ -3,11 +3,10 @@ package fabrik.simulator.pic16f84.interfaces;
|
||||
public interface CommandInterface extends PICComponentInterface {
|
||||
void CALL(int isr);
|
||||
|
||||
double getTotalExecutionTime();
|
||||
|
||||
int get_wRegister();
|
||||
|
||||
void decode(int i);
|
||||
|
||||
void resetTotalExecutionTime();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,7 +1,11 @@
|
||||
package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
public interface EEPROMInterface extends PICComponentInterface {
|
||||
void registerTime(boolean b);
|
||||
void registerTime(double executionTime, boolean b);
|
||||
|
||||
void parse(int i, int content, int i1);
|
||||
|
||||
long read(int address);
|
||||
|
||||
void write (int address, long data);
|
||||
}
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
public interface ExecutionTimeObserver {
|
||||
void executionTimeChanged();
|
||||
}
|
||||
@ -1,13 +1,13 @@
|
||||
package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
public interface FrontendControllerInterface extends PICComponentInterface {
|
||||
double getExecutionTimeMultiplier();
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.FrontendSpecificObject;
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.FrontendSpecificToggleButtonGroup;
|
||||
|
||||
void sleep();
|
||||
public interface FrontendControllerInterface extends PICComponentInterface, FrontendSpecificObject {
|
||||
|
||||
void wakeUpFromSleep();
|
||||
FrontendSpecificToggleButtonGroup[] getPORTbuttons();
|
||||
|
||||
boolean isSleeping();
|
||||
FrontendSpecificToggleButtonGroup[] getTRISbuttons();
|
||||
|
||||
void stopRunFromBackend(String watchdogTimer);
|
||||
}
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
import com.gluonhq.charm.glisten.control.ToggleButtonGroup;
|
||||
import javafx.scene.shape.Circle;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface IOPortInterface extends PICComponentInterface {
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.FrontendSpecificObject;
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.FrontendSpecificToggleButtonGroup;
|
||||
|
||||
public interface IOPortInterface extends PICComponentInterface, FrontendSpecificObject {
|
||||
void resetTRIS();
|
||||
|
||||
void setRegister(int i, int content);
|
||||
@ -14,11 +16,11 @@ public interface IOPortInterface extends PICComponentInterface {
|
||||
|
||||
void setBit(int i, int bit);
|
||||
|
||||
void setPORTfromUI(ToggleButtonGroup parent) throws IOException;
|
||||
void setPORTfromUI(FrontendSpecificToggleButtonGroup parent) throws IOException;
|
||||
|
||||
void setTRISfromUI(ToggleButtonGroup parent) throws IOException;
|
||||
void setTRISfromUI(FrontendSpecificToggleButtonGroup parent) throws IOException;
|
||||
|
||||
void refreshUI(ToggleButtonGroup[] triSbuttons, ToggleButtonGroup[] porTbuttons);
|
||||
void refreshUI(FrontendSpecificToggleButtonGroup[] trisButtons, FrontendSpecificToggleButtonGroup[] portButtons);
|
||||
|
||||
void reset();
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
import fabrik.simulator.pic16f84.PICComponents;
|
||||
import fabrik.simulator.pic16f84.PICComponentLocator;
|
||||
|
||||
public interface PICComponentInterface {
|
||||
void initialize(PICComponents picComponents);
|
||||
void initialize(PICComponentLocator picComponents);
|
||||
}
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.FrontendSpecificVBox;
|
||||
import javafx.scene.layout.VBox;
|
||||
|
||||
public interface TableInterface extends PICComponentInterface {
|
||||
VBox refresh();
|
||||
void refresh();
|
||||
|
||||
FrontendSpecificVBox getTable();
|
||||
}
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
import com.gluonhq.charm.glisten.control.ToggleButtonGroup;
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.FrontendSpecificObject;
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.ToggleButtonGroup;
|
||||
|
||||
public interface ToggleButtonInterface extends PICComponentInterface {
|
||||
public interface ToggleButtonInterface extends PICComponentInterface, FrontendSpecificObject {
|
||||
void addAlwaysOneSelectedSupport(ToggleButtonGroup allTRISButton);
|
||||
}
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
public interface WindowManagement extends PICComponentInterface {
|
||||
void refreshTable();
|
||||
static void refreshTable() {}
|
||||
|
||||
static void startFromMain(String[] args) {}
|
||||
}
|
||||
@ -11,7 +11,9 @@ module fabrik.simulator.pic16f84 {
|
||||
requires json.simple;
|
||||
|
||||
opens fabrik.simulator.pic16f84 to javafx.fxml;
|
||||
opens fabrik.simulator.pic16f84.frontendspecifics to javafx.fxml;
|
||||
exports fabrik.simulator.pic16f84;
|
||||
exports fabrik.simulator.pic16f84.interfaces;
|
||||
exports fabrik.simulator.pic16f84.frontendspecifics;
|
||||
opens fabrik.simulator.pic16f84.interfaces to javafx.fxml;
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import fabrik.simulator.pic16f84.frontendspecifics.*?>
|
||||
<?import com.gluonhq.charm.glisten.control.*?>
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.collections.*?>
|
||||
|
||||
88
src/test/java/fabrik/simulator/pic16f84/CommandsTests.java
Normal file
88
src/test/java/fabrik/simulator/pic16f84/CommandsTests.java
Normal file
@ -0,0 +1,88 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import fabrik.simulator.pic16f84.interfaces.*;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
class CommandsTests {
|
||||
PICComponentLocator picComponents;
|
||||
|
||||
public CommandsTests() {}
|
||||
|
||||
@BeforeEach
|
||||
void resetComponents() {
|
||||
picComponents = new PICComponentLocator();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Execution Time wird korrekt addiert")
|
||||
void executionTimeIsAddedCorrectly() {
|
||||
TimerInterface timerMock = mock(TimerInterface.class);
|
||||
picComponents.registerComponent(TimerInterface.class, timerMock);
|
||||
|
||||
EEPROMInterface eepromMock = mock(EEPROMInterface.class);
|
||||
picComponents.registerComponent(EEPROMInterface.class, eepromMock);
|
||||
|
||||
Commands commands = new Commands();
|
||||
picComponents.registerComponent(CommandInterface.class, commands);
|
||||
picComponents.initAll();
|
||||
|
||||
|
||||
commands.addExecutionTime(5);
|
||||
|
||||
|
||||
assertEquals(5, commands.getTotalExecutionTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Execution Time wird korrekt zurückgesetzt")
|
||||
void executionTimeResetWorks() {
|
||||
TimerInterface timerMock = mock(TimerInterface.class);
|
||||
picComponents.registerComponent(TimerInterface.class, timerMock);
|
||||
|
||||
EEPROMInterface eepromMock = mock(EEPROMInterface.class);
|
||||
picComponents.registerComponent(EEPROMInterface.class, eepromMock);
|
||||
|
||||
Commands commands = new Commands();
|
||||
picComponents.registerComponent(CommandInterface.class, commands);
|
||||
picComponents.initAll();
|
||||
|
||||
|
||||
commands.addExecutionTime(5);
|
||||
commands.resetTotalExecutionTime();
|
||||
|
||||
|
||||
assertEquals(0, commands.getTotalExecutionTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Execution Time Faktor wird berücksichtigt")
|
||||
void executionTimeMultiplierIsUsed() {
|
||||
TimerInterface timerMock = mock(TimerInterface.class);
|
||||
picComponents.registerComponent(TimerInterface.class, timerMock);
|
||||
|
||||
EEPROMInterface eepromMock = mock(EEPROMInterface.class);
|
||||
picComponents.registerComponent(EEPROMInterface.class, eepromMock);
|
||||
|
||||
Commands commands = new Commands();
|
||||
picComponents.registerComponent(CommandInterface.class, commands);
|
||||
picComponents.initAll();
|
||||
|
||||
commands.addExecutionTime(5);
|
||||
commands.setExecutionTimeMultiplier("100 HZ");
|
||||
|
||||
assertEquals(5 * 40, commands.getTotalExecutionTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Decode mit ungültigem Opcode wirft keine Exception")
|
||||
void decodeInvalidOpcodeDoesNotCrash() {
|
||||
CommandInterface commands = new Commands();
|
||||
|
||||
assertDoesNotThrow(() -> commands.decode(1));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import fabrik.simulator.pic16f84.interfaces.*;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
class DataRegisterTests {
|
||||
PICComponentLocator picComponents;
|
||||
|
||||
public DataRegisterTests() {}
|
||||
|
||||
@BeforeEach
|
||||
void resetComponents() {
|
||||
picComponents = new PICComponentLocator();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@DisplayName("DataRegister wird durch Components initialisiert und enthält dann die korrekten Startwerte")
|
||||
void registerGetsInitializedThroughComponents() {
|
||||
IOPortInterface mockIOPorts = mock(IOPortInterface.class);
|
||||
picComponents.registerComponent(IOPortInterface.class, mockIOPorts);
|
||||
|
||||
DataRegisterInterface dataRegister = new DataRegister();
|
||||
picComponents.registerComponent(DataRegisterInterface.class, dataRegister);
|
||||
|
||||
|
||||
picComponents.initAll();
|
||||
int [] expected = {0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 255, 0, 24, 0, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
int [] actual = dataRegister.getDataRegister();
|
||||
|
||||
assertEquals(expected.length, actual.length);
|
||||
for (int i = 0; i<expected.length; i++){
|
||||
assertEquals(expected[i], actual[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
135
src/test/java/fabrik/simulator/pic16f84/EEPROMTests.java
Normal file
135
src/test/java/fabrik/simulator/pic16f84/EEPROMTests.java
Normal file
@ -0,0 +1,135 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import fabrik.simulator.pic16f84.interfaces.CommandInterface;
|
||||
import fabrik.simulator.pic16f84.interfaces.DataRegisterInterface;
|
||||
import fabrik.simulator.pic16f84.interfaces.EEPROMInterface;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
|
||||
class EEPROMTests {
|
||||
PICComponentLocator picComponents;
|
||||
String savedEEPROM;
|
||||
|
||||
public EEPROMTests() {}
|
||||
|
||||
@BeforeEach
|
||||
void resetComponentsAndReadEEPROM() throws IOException {
|
||||
picComponents = new PICComponentLocator();
|
||||
savedEEPROM = Files.readString(Path.of("eeprom.json"));
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void rewriteEEPROM() throws IOException {
|
||||
FileWriter writer = new FileWriter("eeprom.json");
|
||||
writer.write(savedEEPROM);
|
||||
writer.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("EEPROM read gibt gültigen Wert zurück")
|
||||
void eepromReadReturnsValidLong() throws IOException {
|
||||
FileWriter writer = new FileWriter("eeprom.json");
|
||||
writer.write("{\"0\": 255}");
|
||||
writer.close();
|
||||
|
||||
DataRegisterInterface mockDataRegister = Mockito.mock(DataRegisterInterface.class);
|
||||
picComponents.registerComponent(DataRegisterInterface.class, mockDataRegister);
|
||||
|
||||
EEPROMInterface eeprom = new EEPROM();
|
||||
picComponents.registerComponent(EEPROMInterface.class, eeprom);
|
||||
picComponents.initAll();
|
||||
|
||||
|
||||
long value = eeprom.read(0);
|
||||
|
||||
|
||||
assertEquals(255, value);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@DisplayName("EEPROM write schreibt an die korrekte Adresse in eeprom.json")
|
||||
void eepromWritesCorrectly() throws IOException {
|
||||
FileWriter writer = new FileWriter("eeprom.json");
|
||||
writer.write("{}");
|
||||
writer.close();
|
||||
|
||||
DataRegisterInterface mockDataRegister = Mockito.mock(DataRegisterInterface.class);
|
||||
picComponents.registerComponent(DataRegisterInterface.class, mockDataRegister);
|
||||
|
||||
ExecutionTimeSubject mockExecutionTime = mock(ExecutionTimeSubject.class);
|
||||
picComponents.registerComponent(ExecutionTimeSubject.class, mockExecutionTime);
|
||||
|
||||
EEPROMInterface eeprom = new EEPROM();
|
||||
picComponents.registerComponent(EEPROMInterface.class, eeprom);
|
||||
picComponents.initAll();
|
||||
|
||||
|
||||
eeprom.write(3, 123);
|
||||
|
||||
|
||||
assertEquals("{\"3\":123}", Files.readString(Path.of("eeprom.json")));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@DisplayName("EEPROM write schreibt nicht an negative Adressen")
|
||||
void eepromDoesntWriteNegative() throws IOException {
|
||||
FileWriter writer = new FileWriter("eeprom.json");
|
||||
writer.write("{}");
|
||||
writer.close();
|
||||
|
||||
DataRegisterInterface mockDataRegister = Mockito.mock(DataRegisterInterface.class);
|
||||
picComponents.registerComponent(DataRegisterInterface.class, mockDataRegister);
|
||||
|
||||
CommandInterface mockCommands = mock(CommandInterface.class);
|
||||
picComponents.registerComponent(CommandInterface.class, mockCommands);
|
||||
|
||||
EEPROMInterface eeprom = new EEPROM();
|
||||
picComponents.registerComponent(EEPROMInterface.class, eeprom);
|
||||
picComponents.initAll();
|
||||
|
||||
|
||||
eeprom.write(-1, 1);
|
||||
|
||||
|
||||
assertEquals("{}", Files.readString(Path.of("eeprom.json")));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@DisplayName("EEPROM read mit negativem Wert liefert 0")
|
||||
void eepromReadWithNegativeAddress() throws IOException {
|
||||
FileWriter writer = new FileWriter("eeprom.json");
|
||||
writer.write("{\"-1\":5}");
|
||||
writer.close();
|
||||
|
||||
DataRegisterInterface mockDataRegister = Mockito.mock(DataRegisterInterface.class);
|
||||
picComponents.registerComponent(DataRegisterInterface.class, mockDataRegister);
|
||||
|
||||
CommandInterface mockCommands = mock(CommandInterface.class);
|
||||
picComponents.registerComponent(CommandInterface.class, mockCommands);
|
||||
|
||||
EEPROMInterface eeprom = new EEPROM();
|
||||
picComponents.registerComponent(EEPROMInterface.class, eeprom);
|
||||
picComponents.initAll();
|
||||
|
||||
|
||||
long result = eeprom.read(-1);
|
||||
|
||||
|
||||
assertEquals(0, result);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import fabrik.simulator.pic16f84.interfaces.*;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class WatchDogTimerTests {
|
||||
private PICComponentLocator picComponents;
|
||||
|
||||
@BeforeEach
|
||||
void resetComponents() {
|
||||
picComponents = new PICComponentLocator();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("WatchDogTimer testet ob er triggern soll, triggert korrekt nicht")
|
||||
void watchDogIncrementWithoutTriggering() {
|
||||
PreScalerInterface mockPreScaler = mock(PreScalerInterface.class);
|
||||
when(
|
||||
mockPreScaler.isPrescalerOnTimer()
|
||||
).thenReturn(
|
||||
true
|
||||
);
|
||||
picComponents.registerComponent(PreScalerInterface.class, mockPreScaler);
|
||||
|
||||
|
||||
ExecutionTimeSubject mockExecutionTime = mock(ExecutionTimeSubject.class);
|
||||
when(
|
||||
mockExecutionTime.getExecutionTimeMultiplier()
|
||||
).thenReturn(
|
||||
1.0
|
||||
);
|
||||
picComponents.registerComponent(ExecutionTimeSubject.class, mockExecutionTime);
|
||||
|
||||
WatchdogTimerInterface watchDogTimer = new WatchdogTimer();
|
||||
picComponents.registerComponent(WatchdogTimerInterface.class, watchDogTimer);
|
||||
picComponents.initAll();
|
||||
|
||||
watchDogTimer.enable();
|
||||
watchDogTimer.testAndTrigger();
|
||||
|
||||
|
||||
assertEquals(1, watchDogTimer.get());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user