Merge remote-tracking branch 'refs/remotes/origin/advancedSE' into advancedSE-luca

This commit is contained in:
2025-05-25 18:44:22 +02:00
28 changed files with 487 additions and 115 deletions

View File

@ -4,6 +4,7 @@ import fabrik.simulator.pic16f84.interfaces.*;
public class Commands extends PICComponent implements CommandInterface {
private int wRegister;
private long totalExecutionTime;
private double executionTimeMultiplier = 1;
public Commands(){
super();
@ -22,7 +23,7 @@ public class Commands extends PICComponent implements CommandInterface {
}
public double getTotalExecutionTime() {
return (totalExecutionTime * frontendController.getExecutionTimeMultiplier());
return (totalExecutionTime * getExecutionTimeMultiplier());
}
public void resetTotalExecutionTime() {
@ -248,8 +249,6 @@ public class Commands extends PICComponent implements CommandInterface {
else{
System.out.println("Nicht gefunden!");
}
}
public void SLEEP() {
@ -557,9 +556,39 @@ public class Commands extends PICComponent implements CommandInterface {
}
}
public double getExecutionTimeMultiplier(){
return executionTimeMultiplier;
}
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;
}
}
@Override
public void initialize(PICComponents picComponents) {
System.out.println("Commands");
super.initialize(picComponents);
public void initialize(PICComponentLocator locator) {
super.initialize(locator);
}
}

View File

@ -3,7 +3,6 @@ package fabrik.simulator.pic16f84;
import com.gluonhq.charm.glisten.control.ToggleButtonGroup;
import fabrik.simulator.pic16f84.interfaces.*;
import fabrik.simulator.pic16f84.interfaces.WatchdogTimerInterface;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
@ -42,14 +41,7 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
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;
@ -177,29 +169,7 @@ 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;
}
commands.setExecutionTimeMultiplier(selectedOption);
}
@FXML
@ -599,9 +569,9 @@ 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);
this.picComponents = locator;
System.out.println("Frontend");
}
}

View File

@ -4,11 +4,9 @@ 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;
@ -16,30 +14,20 @@ 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;
@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.initAll();
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);
grid.add(code, 0, 1);
@ -53,6 +41,10 @@ public class CreateWindow extends Application {
primaryStage.show();
}
public void startFromMain(String[] args){
launch(args);
}
public static void main(String[] args) {
launch(args);
}
@ -62,7 +54,15 @@ public class CreateWindow extends Application {
table= Table.refresh();
grid.add(table, 1, 1);
}
@Override
public void initialize(PICComponentLocator picComponents) {
CreateWindow.picComponents = picComponents;
}
public CreateWindow (){
}
}

View File

@ -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();
}

View File

@ -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;
@ -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");
@ -171,8 +172,7 @@ 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);
}
}

View File

@ -145,7 +145,7 @@ public class EmptyRegister implements DataRegisterInterface {
}
@Override
public void initialize(PICComponents picComponents) {
public void initialize(PICComponentLocator picComponents) {
}
}

View File

@ -227,8 +227,8 @@ 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");
}
}

View File

@ -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 {
@ -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);
}
}

View 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) {
picComponents.registerComponent(CommandInterface.class, new Commands());
picComponents.registerComponent(ToggleButtonInterface.class, new ToggleButtonGroupExt());
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());
CreateWindow window = new CreateWindow();
picComponents.registerComponent(WindowManagement.class, window);
picComponents.initAll();
window.startFromMain(new String[]{});
}
}

View File

@ -5,31 +5,27 @@ 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;
FrontendControllerInterface frontendController;
WatchdogTimerInterface watchdogTimer;
ProgramStackInterface programStack;
CommandInterface commands;
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);
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);
}
}

View File

@ -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() {

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -4,7 +4,6 @@ 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;
@ -46,7 +45,7 @@ public class Table {
return s;
}
public static VBox init(PICComponents picComponents){
public static VBox init(PICComponentLocator picComponents){
dataRegister = (DataRegisterInterface) picComponents.getComponent(DataRegisterInterface.class);
commands = (CommandInterface) picComponents.getComponent(CommandInterface.class);
ioPorts = (IOPortInterface) picComponents.getComponent(IOPortInterface.class);

View File

@ -1,8 +1,5 @@
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.TimerInterface;
public class Timer extends PICComponent implements TimerInterface {
@ -67,7 +64,7 @@ public class Timer extends PICComponent implements TimerInterface {
}
@Override
public void initialize(PICComponents picComponents) {
super.initialize(picComponents);
public void initialize(PICComponentLocator locator) {
super.initialize(locator);
}
}

View File

@ -1,7 +1,6 @@
package fabrik.simulator.pic16f84;
import com.gluonhq.charm.glisten.control.ToggleButtonGroup;
import fabrik.simulator.pic16f84.interfaces.IOPortInterface;
import fabrik.simulator.pic16f84.interfaces.ToggleButtonInterface;
import javafx.collections.ListChangeListener;
import javafx.event.EventHandler;
@ -59,8 +58,8 @@ 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);
}
}

View File

@ -26,7 +26,7 @@ public class WatchdogTimer extends PICComponent implements WatchdogTimerInterfac
}
else {
rawtimer++;
realtimer = (long) (rawtimer * frontendController.getExecutionTimeMultiplier());
realtimer = (long) (rawtimer * commands.getExecutionTimeMultiplier());
}
}
}
@ -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);
}
}

View File

@ -10,4 +10,10 @@ public interface CommandInterface extends PICComponentInterface {
void decode(int i);
void resetTotalExecutionTime();
void addExecutionTime(int i);
double getExecutionTimeMultiplier();
void setExecutionTimeMultiplier(String option);
}

View File

@ -4,4 +4,8 @@ public interface EEPROMInterface extends PICComponentInterface {
void registerTime(boolean b);
void parse(int i, int content, int i1);
long read(int address);
void write (int address, long data);
}

View File

@ -1,7 +1,6 @@
package fabrik.simulator.pic16f84.interfaces;
public interface FrontendControllerInterface extends PICComponentInterface {
double getExecutionTimeMultiplier();
void sleep();

View File

@ -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);
}

View File

@ -1,5 +1,7 @@
package fabrik.simulator.pic16f84.interfaces;
public interface WindowManagement extends PICComponentInterface {
void refreshTable();
static void refreshTable() {}
static void startFromMain(String[] args) {}
}