Compare commits
4 Commits
ca36cffd47
...
db03c9d7bd
| Author | SHA1 | Date | |
|---|---|---|---|
| db03c9d7bd | |||
| 0dd7494f5a | |||
| c38835fd7b | |||
| ac854ed4f1 |
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@ -13,7 +13,7 @@
|
|||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</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" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
25
pom.xml
25
pom.xml
@ -80,6 +80,13 @@
|
|||||||
<version>${junit.version}</version>
|
<version>${junit.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</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>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@ -113,6 +120,24 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</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>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
||||||
@ -4,6 +4,7 @@ import fabrik.simulator.pic16f84.interfaces.*;
|
|||||||
public class Commands extends PICComponent implements CommandInterface {
|
public class Commands extends PICComponent implements CommandInterface {
|
||||||
private int wRegister;
|
private int wRegister;
|
||||||
private long totalExecutionTime;
|
private long totalExecutionTime;
|
||||||
|
private double executionTimeMultiplier = 1;
|
||||||
|
|
||||||
public Commands(){
|
public Commands(){
|
||||||
super();
|
super();
|
||||||
@ -22,7 +23,7 @@ public class Commands extends PICComponent implements CommandInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public double getTotalExecutionTime() {
|
public double getTotalExecutionTime() {
|
||||||
return (totalExecutionTime * frontendController.getExecutionTimeMultiplier());
|
return (totalExecutionTime * getExecutionTimeMultiplier());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetTotalExecutionTime() {
|
public void resetTotalExecutionTime() {
|
||||||
@ -248,8 +249,6 @@ public class Commands extends PICComponent implements CommandInterface {
|
|||||||
else{
|
else{
|
||||||
System.out.println("Nicht gefunden!");
|
System.out.println("Nicht gefunden!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SLEEP() {
|
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
|
@Override
|
||||||
public void initialize(PICComponents picComponents) {
|
public void initialize(PICComponentLocator locator) {
|
||||||
System.out.println("Commands");
|
super.initialize(locator);
|
||||||
super.initialize(picComponents);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,6 @@ package fabrik.simulator.pic16f84;
|
|||||||
import com.gluonhq.charm.glisten.control.ToggleButtonGroup;
|
import com.gluonhq.charm.glisten.control.ToggleButtonGroup;
|
||||||
|
|
||||||
import fabrik.simulator.pic16f84.interfaces.*;
|
import fabrik.simulator.pic16f84.interfaces.*;
|
||||||
import fabrik.simulator.pic16f84.interfaces.WatchdogTimerInterface;
|
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
@ -42,14 +41,7 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
|
|||||||
private int [] prog;
|
private int [] prog;
|
||||||
private int [][] read;
|
private int [][] read;
|
||||||
private int [] ind;
|
private int [] ind;
|
||||||
private PICComponents picComponents;
|
private PICComponentLocator picComponents;
|
||||||
private double executionTimeMultiplier = 1;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public double getExecutionTimeMultiplier(){
|
|
||||||
return executionTimeMultiplier;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isBreakpointReached = false;
|
private boolean isBreakpointReached = false;
|
||||||
|
|
||||||
@ -160,29 +152,7 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
|
|||||||
|
|
||||||
private void updateExecutionTimeMultiplier() {
|
private void updateExecutionTimeMultiplier() {
|
||||||
String selectedOption = executionTimeComboBox.getValue();
|
String selectedOption = executionTimeComboBox.getValue();
|
||||||
switch (selectedOption) {
|
commands.setExecutionTimeMultiplier(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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
@ -582,9 +552,9 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(PICComponents picComponents) {
|
public void initialize(PICComponentLocator locator) {
|
||||||
super.initialize(picComponents);
|
super.initialize(locator);
|
||||||
this.picComponents = picComponents;
|
this.picComponents = locator;
|
||||||
System.out.println("Frontend");
|
System.out.println("Frontend");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,11 +4,9 @@ import fabrik.simulator.pic16f84.interfaces.*;
|
|||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
|
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.scene.Node;
|
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
|
|
||||||
import javafx.scene.control.Tab;
|
|
||||||
import javafx.scene.layout.GridPane;
|
import javafx.scene.layout.GridPane;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
@ -16,30 +14,20 @@ import javafx.stage.Stage;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class CreateWindow extends Application {
|
public class CreateWindow extends Application implements WindowManagement {
|
||||||
private PICComponents picComponents = new PICComponents(); // Subjekt
|
private static PICComponentLocator picComponents; // Subjekt
|
||||||
public static GridPane grid = new GridPane();
|
public static GridPane grid = new GridPane();
|
||||||
private static VBox table;
|
private static VBox table;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) throws IOException {
|
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(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();
|
picComponents.initAll();
|
||||||
|
|
||||||
FXMLLoader codewindow = new FXMLLoader(CreateWindow.class.getResource("frontend.fxml"));
|
FXMLLoader codewindow = new FXMLLoader(CreateWindow.class.getResource("frontend.fxml"));
|
||||||
codewindow.setController(picComponents.getComponent(FrontendControllerInterface.class));
|
codewindow.setController(picComponents.getComponent(FrontendControllerInterface.class));
|
||||||
Parent code = codewindow.load();
|
Parent code = codewindow.load();
|
||||||
|
|
||||||
table = Table.init(picComponents);
|
table = Table.init(picComponents);
|
||||||
grid.add(table, 1, 1);
|
grid.add(table, 1, 1);
|
||||||
grid.add(code, 0, 1);
|
grid.add(code, 0, 1);
|
||||||
@ -53,6 +41,10 @@ public class CreateWindow extends Application {
|
|||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void startFromMain(String[] args){
|
||||||
|
launch(args);
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
launch(args);
|
launch(args);
|
||||||
}
|
}
|
||||||
@ -62,7 +54,15 @@ public class CreateWindow extends Application {
|
|||||||
table= Table.refresh();
|
table= Table.refresh();
|
||||||
grid.add(table, 1, 1);
|
grid.add(table, 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
|
@Override
|
||||||
public void initialize(PICComponents picComponents) {
|
public void initialize(PICComponentLocator locator) {
|
||||||
super.initialize(picComponents);
|
super.initialize(locator);
|
||||||
System.out.println("DataRegister.\n");
|
System.out.println("DataRegister.\n");
|
||||||
initOrReset();
|
initOrReset();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package fabrik.simulator.pic16f84;
|
package fabrik.simulator.pic16f84;
|
||||||
|
|
||||||
|
|
||||||
import eu.hansolo.tilesfx.Command;
|
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import org.json.simple.parser.JSONParser;
|
import org.json.simple.parser.JSONParser;
|
||||||
import org.json.simple.parser.ParseException;
|
import org.json.simple.parser.ParseException;
|
||||||
@ -36,6 +35,7 @@ public class EEPROM extends PICComponent implements EEPROMInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public long read (int address) {
|
public long read (int address) {
|
||||||
|
if (address < 0) return 0;
|
||||||
FileReader reader;
|
FileReader reader;
|
||||||
try {
|
try {
|
||||||
reader = new FileReader("eeprom.json");
|
reader = new FileReader("eeprom.json");
|
||||||
@ -60,6 +60,7 @@ public class EEPROM extends PICComponent implements EEPROMInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void write (int address, long data) {
|
public void write (int address, long data) {
|
||||||
|
if (address < 0) return;
|
||||||
FileReader reader;
|
FileReader reader;
|
||||||
try {
|
try {
|
||||||
reader = new FileReader("eeprom.json");
|
reader = new FileReader("eeprom.json");
|
||||||
@ -171,8 +172,7 @@ public class EEPROM extends PICComponent implements EEPROMInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(PICComponents picComponents) {
|
public void initialize(PICComponentLocator locator) {
|
||||||
System.out.println("EEPROM");
|
super.initialize(locator);
|
||||||
super.initialize(picComponents);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -145,7 +145,7 @@ public class EmptyRegister implements DataRegisterInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(PICComponents picComponents) {
|
public void initialize(PICComponentLocator picComponents) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -227,8 +227,8 @@ public class IOPorts extends PICComponent implements IOPortInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(PICComponents picComponents) {
|
public void initialize(PICComponentLocator locator) {
|
||||||
super.initialize(picComponents);
|
super.initialize(locator);
|
||||||
System.out.println("IOPorts.\n");
|
System.out.println("IOPorts.\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,5 @@
|
|||||||
package fabrik.simulator.pic16f84;
|
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;
|
import fabrik.simulator.pic16f84.interfaces.InterruptInterface;
|
||||||
|
|
||||||
public class Interrupts extends PICComponent implements InterruptInterface {
|
public class Interrupts extends PICComponent implements InterruptInterface {
|
||||||
@ -66,7 +62,7 @@ public class Interrupts extends PICComponent implements InterruptInterface {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(PICComponents picComponents) {
|
public void initialize(PICComponentLocator locator) {
|
||||||
super.initialize(picComponents);
|
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) {
|
||||||
|
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[]{});
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -5,31 +5,27 @@ import fabrik.simulator.pic16f84.interfaces.*;
|
|||||||
public abstract class PICComponent {
|
public abstract class PICComponent {
|
||||||
DataRegisterInterface dataRegister;
|
DataRegisterInterface dataRegister;
|
||||||
EEPROMInterface eeprom;
|
EEPROMInterface eeprom;
|
||||||
PreScaler preScaler;
|
PreScalerInterface preScaler;
|
||||||
IOPortInterface ioPorts;
|
IOPortInterface ioPorts;
|
||||||
TimerInterface timer;
|
TimerInterface timer;
|
||||||
InterruptInterface interrupts;
|
InterruptInterface interrupts;
|
||||||
//TableInterface table;
|
|
||||||
//WindowManagement createWindow;
|
|
||||||
FrontendControllerInterface frontendController;
|
FrontendControllerInterface frontendController;
|
||||||
WatchdogTimerInterface watchdogTimer;
|
WatchdogTimerInterface watchdogTimer;
|
||||||
ProgramStackInterface programStack;
|
ProgramStackInterface programStack;
|
||||||
CommandInterface commands;
|
CommandInterface commands;
|
||||||
ToggleButtonInterface toggleButtonExt;
|
ToggleButtonInterface toggleButtonExt;
|
||||||
|
|
||||||
void initialize(PICComponents picComponents) {
|
void initialize(PICComponentLocator locator) {
|
||||||
toggleButtonExt = (ToggleButtonInterface) picComponents.getComponent(ToggleButtonInterface.class);
|
toggleButtonExt = locator.getComponent(ToggleButtonInterface.class);
|
||||||
dataRegister = (DataRegisterInterface) picComponents.getComponent(DataRegisterInterface.class);
|
dataRegister = locator.getComponent(DataRegisterInterface.class);
|
||||||
eeprom = (EEPROMInterface) picComponents.getComponent(EEPROMInterface.class);
|
eeprom = locator.getComponent(EEPROMInterface.class);
|
||||||
ioPorts = (IOPortInterface) picComponents.getComponent(IOPortInterface.class);
|
ioPorts = locator.getComponent(IOPortInterface.class);
|
||||||
preScaler = (PreScaler) picComponents.getComponent(PreScalerInterface.class);
|
preScaler = locator.getComponent(PreScalerInterface.class);
|
||||||
timer = (TimerInterface) picComponents.getComponent(TimerInterface.class);
|
timer = locator.getComponent(TimerInterface.class);
|
||||||
interrupts = (InterruptInterface) picComponents.getComponent(InterruptInterface.class);
|
interrupts = locator.getComponent(InterruptInterface.class);
|
||||||
//table = (TableInterface) picComponents.getComponent(TableInterface.class);
|
frontendController = locator.getComponent(FrontendControllerInterface.class);
|
||||||
//createWindow = (WindowManagement) picComponents.getComponent(WindowManagement.class);
|
watchdogTimer = locator.getComponent(WatchdogTimerInterface.class);
|
||||||
frontendController = (FrontendControllerInterface) picComponents.getComponent(FrontendControllerInterface.class);
|
programStack = locator.getComponent(ProgramStackInterface.class);
|
||||||
watchdogTimer = (WatchdogTimerInterface) picComponents.getComponent(WatchdogTimerInterface.class);
|
commands = locator.getComponent(CommandInterface.class);
|
||||||
programStack = (ProgramStackInterface) picComponents.getComponent(ProgramStackInterface.class);
|
|
||||||
commands = (CommandInterface) picComponents.getComponent(CommandInterface.class);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,10 +4,11 @@ import fabrik.simulator.pic16f84.interfaces.*;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
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;
|
private final HashMap<Class<? extends PICComponentInterface>, PICComponentInterface> componentCatalogue;
|
||||||
|
|
||||||
public PICComponents() {
|
public PICComponentLocator() {
|
||||||
super();
|
super();
|
||||||
this.componentCatalogue = new HashMap<>();
|
this.componentCatalogue = new HashMap<>();
|
||||||
}
|
}
|
||||||
@ -16,8 +17,9 @@ public class PICComponents {
|
|||||||
this.componentCatalogue.put(componentClass, component);
|
this.componentCatalogue.put(componentClass, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PICComponentInterface getComponent(Class<? extends PICComponentInterface> componentClass) {
|
public <T extends PICComponentInterface> T getComponent(Class<T> componentClass) {
|
||||||
return this.componentCatalogue.get(componentClass);
|
T component = (T) this.componentCatalogue.get(componentClass);
|
||||||
|
return component;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initAll() {
|
public void initAll() {
|
||||||
@ -54,7 +54,7 @@ public class PreScaler extends PICComponent implements PreScalerInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(PICComponents picComponents) {
|
public void initialize(PICComponentLocator locator) {
|
||||||
super.initialize(picComponents);
|
super.initialize(locator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -48,7 +48,7 @@ public class ProgramStack extends PICComponent implements ProgramStackInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(PICComponents picComponents) {
|
public void initialize(PICComponentLocator locator) {
|
||||||
super.initialize(picComponents);
|
super.initialize(locator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,6 @@ import fabrik.simulator.pic16f84.interfaces.*;
|
|||||||
import javafx.beans.property.SimpleStringProperty;
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
|
|
||||||
import javafx.scene.chart.PieChart;
|
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.TableColumn;
|
import javafx.scene.control.TableColumn;
|
||||||
@ -46,7 +45,7 @@ public class Table {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static VBox init(PICComponents picComponents){
|
public static VBox init(PICComponentLocator picComponents){
|
||||||
dataRegister = (DataRegisterInterface) picComponents.getComponent(DataRegisterInterface.class);
|
dataRegister = (DataRegisterInterface) picComponents.getComponent(DataRegisterInterface.class);
|
||||||
commands = (CommandInterface) picComponents.getComponent(CommandInterface.class);
|
commands = (CommandInterface) picComponents.getComponent(CommandInterface.class);
|
||||||
ioPorts = (IOPortInterface) picComponents.getComponent(IOPortInterface.class);
|
ioPorts = (IOPortInterface) picComponents.getComponent(IOPortInterface.class);
|
||||||
|
|||||||
@ -1,8 +1,5 @@
|
|||||||
package fabrik.simulator.pic16f84;
|
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;
|
import fabrik.simulator.pic16f84.interfaces.TimerInterface;
|
||||||
|
|
||||||
public class Timer extends PICComponent implements TimerInterface {
|
public class Timer extends PICComponent implements TimerInterface {
|
||||||
@ -67,7 +64,7 @@ public class Timer extends PICComponent implements TimerInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(PICComponents picComponents) {
|
public void initialize(PICComponentLocator locator) {
|
||||||
super.initialize(picComponents);
|
super.initialize(locator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package fabrik.simulator.pic16f84;
|
package fabrik.simulator.pic16f84;
|
||||||
|
|
||||||
import com.gluonhq.charm.glisten.control.ToggleButtonGroup;
|
import com.gluonhq.charm.glisten.control.ToggleButtonGroup;
|
||||||
import fabrik.simulator.pic16f84.interfaces.IOPortInterface;
|
|
||||||
import fabrik.simulator.pic16f84.interfaces.ToggleButtonInterface;
|
import fabrik.simulator.pic16f84.interfaces.ToggleButtonInterface;
|
||||||
import javafx.collections.ListChangeListener;
|
import javafx.collections.ListChangeListener;
|
||||||
import javafx.event.EventHandler;
|
import javafx.event.EventHandler;
|
||||||
@ -59,8 +58,8 @@ public class ToggleButtonGroupExt extends PICComponent implements ToggleButtonIn
|
|||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(PICComponents picComponents) {
|
public void initialize(PICComponentLocator locator) {
|
||||||
System.out.println("ToggleButtonGroupExt");
|
System.out.println("ToggleButtonGroupExt");
|
||||||
super.initialize(picComponents);
|
super.initialize(locator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,7 +26,7 @@ public class WatchdogTimer extends PICComponent implements WatchdogTimerInterfac
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rawtimer++;
|
rawtimer++;
|
||||||
realtimer = (long) (rawtimer * frontendController.getExecutionTimeMultiplier());
|
realtimer = (long) (rawtimer * commands.getExecutionTimeMultiplier());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -53,7 +53,7 @@ public class WatchdogTimer extends PICComponent implements WatchdogTimerInterfac
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(PICComponents picComponents) {
|
public void initialize(PICComponentLocator locator) {
|
||||||
super.initialize(picComponents);
|
super.initialize(locator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,4 +10,10 @@ public interface CommandInterface extends PICComponentInterface {
|
|||||||
void decode(int i);
|
void decode(int i);
|
||||||
|
|
||||||
void resetTotalExecutionTime();
|
void resetTotalExecutionTime();
|
||||||
|
|
||||||
|
void addExecutionTime(int i);
|
||||||
|
|
||||||
|
double getExecutionTimeMultiplier();
|
||||||
|
|
||||||
|
void setExecutionTimeMultiplier(String option);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,4 +4,8 @@ public interface EEPROMInterface extends PICComponentInterface {
|
|||||||
void registerTime(boolean b);
|
void registerTime(boolean b);
|
||||||
|
|
||||||
void parse(int i, int content, int i1);
|
void parse(int i, int content, int i1);
|
||||||
|
|
||||||
|
long read(int address);
|
||||||
|
|
||||||
|
void write (int address, long data);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package fabrik.simulator.pic16f84.interfaces;
|
package fabrik.simulator.pic16f84.interfaces;
|
||||||
|
|
||||||
public interface FrontendControllerInterface extends PICComponentInterface {
|
public interface FrontendControllerInterface extends PICComponentInterface {
|
||||||
double getExecutionTimeMultiplier();
|
|
||||||
|
|
||||||
void sleep();
|
void sleep();
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
package fabrik.simulator.pic16f84.interfaces;
|
package fabrik.simulator.pic16f84.interfaces;
|
||||||
|
|
||||||
import fabrik.simulator.pic16f84.PICComponents;
|
import fabrik.simulator.pic16f84.PICComponentLocator;
|
||||||
|
|
||||||
public interface PICComponentInterface {
|
public interface PICComponentInterface {
|
||||||
void initialize(PICComponents picComponents);
|
void initialize(PICComponentLocator picComponents);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
package fabrik.simulator.pic16f84.interfaces;
|
package fabrik.simulator.pic16f84.interfaces;
|
||||||
|
|
||||||
public interface WindowManagement extends PICComponentInterface {
|
public interface WindowManagement extends PICComponentInterface {
|
||||||
void refreshTable();
|
static void refreshTable() {}
|
||||||
|
|
||||||
|
static void startFromMain(String[] args) {}
|
||||||
}
|
}
|
||||||
|
|||||||
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);
|
||||||
|
|
||||||
|
CommandInterface 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);
|
||||||
|
|
||||||
|
CommandInterface 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);
|
||||||
|
|
||||||
|
CommandInterface 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);
|
||||||
|
|
||||||
|
CommandInterface mockCommands = mock(CommandInterface.class);
|
||||||
|
picComponents.registerComponent(CommandInterface.class, mockCommands);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
CommandInterface mockCommands = mock(CommandInterface.class);
|
||||||
|
when(
|
||||||
|
mockCommands.getExecutionTimeMultiplier()
|
||||||
|
).thenReturn(
|
||||||
|
1.0
|
||||||
|
);
|
||||||
|
picComponents.registerComponent(CommandInterface.class, mockCommands);
|
||||||
|
|
||||||
|
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