Removed extern communication files, implemented breakpoints disabling, set/reset breakpoints
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
bin/Backend/Runtime/Testfile.class
Normal file
BIN
bin/Backend/Runtime/Testfile.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,51 +0,0 @@
|
||||
package Backend.BackendCommandProcessing;
|
||||
|
||||
//package SIMULATOR;
|
||||
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class BackendInformationTransferThread extends Thread {
|
||||
|
||||
private static File fileBackendToFrontend = new File("../SIMULATOR_DAT/gui_set.dat");
|
||||
|
||||
private ConcurrentLinkedQueue<String> queue;
|
||||
|
||||
private int iSleepTime = 100;
|
||||
|
||||
public BackendInformationTransferThread(ConcurrentLinkedQueue<String> outputQueue) {
|
||||
queue = outputQueue;
|
||||
}
|
||||
|
||||
private int writeOutputFile() {
|
||||
int iSuccess = 0;
|
||||
if(!queue.isEmpty()) {
|
||||
String sPICInformation = queue.poll();
|
||||
FileWriter fw;
|
||||
try {
|
||||
fw = new FileWriter(fileBackendToFrontend);
|
||||
BufferedWriter bw = new BufferedWriter(fw);
|
||||
bw.write(sPICInformation);
|
||||
bw.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
iSuccess = 1;
|
||||
}
|
||||
return iSuccess;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
Thread.sleep(iSleepTime);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
writeOutputFile();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,14 +10,16 @@ import Backend.Microcontroller.PIC;
|
||||
|
||||
public class ReadEepromFile {
|
||||
|
||||
ArrayList<String> dataLines;
|
||||
ArrayList<String> oPCode;
|
||||
/**
|
||||
* Get OP-Code out of String-data-array.
|
||||
* @param dataArray String-array where OP-Code is.
|
||||
* @return String-array with only OP-Code.
|
||||
*/
|
||||
public ArrayList<String> getOPCode(ArrayList<String> data) {
|
||||
public void setOPCode(ArrayList<String> data) {
|
||||
|
||||
ArrayList<String> oPCode = new ArrayList<String>();
|
||||
oPCode = new ArrayList<String>();
|
||||
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
//If element in dataArray at position i is null or a space, this element is not added into the new oPCode-Array.
|
||||
@@ -25,26 +27,28 @@ public class ReadEepromFile {
|
||||
oPCode.add(data.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<String> getOPCode() {
|
||||
return oPCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whole data of the file.
|
||||
* @param file
|
||||
* @return ArrayList<String>
|
||||
* @throws IOException
|
||||
*/
|
||||
public ArrayList<String> getData(File file) {
|
||||
public void setData(File file) {
|
||||
//Creates String-arraylist with whole data.
|
||||
dataLines = new ArrayList<String>();
|
||||
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
try {
|
||||
FileReader fR = new FileReader(file);
|
||||
BufferedReader br = new BufferedReader(fR);
|
||||
|
||||
String sLine;
|
||||
while ((sLine = br.readLine()) != null) {
|
||||
list.add(sLine);
|
||||
dataLines.add(sLine);
|
||||
}
|
||||
|
||||
br.close();
|
||||
@@ -52,7 +56,13 @@ public class ReadEepromFile {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ArrayList<String> dataLines from current this object.
|
||||
*/
|
||||
public ArrayList<String> getData() {
|
||||
return dataLines;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -188,33 +198,28 @@ public class ReadEepromFile {
|
||||
* @param k index of file in String-Array "files".
|
||||
* @param oPIC of the main-function.
|
||||
*/
|
||||
public void readFileAndWriteToEEPROM(File file, PIC oPIC) {
|
||||
public void readFileAndWriteToEEPROM(PIC oPIC) {
|
||||
if (oPCode.size() > 0) {
|
||||
//Integer-array which will contain oPCode as int-values.
|
||||
//Get an twodimensional array with int-values.
|
||||
int[][] oPCodeAsInt = getOPCodeArrayCommandAsInt(oPCode);
|
||||
|
||||
//Creates String-arraylist with whole data.
|
||||
ArrayList<String> dataLines = getData(file);
|
||||
|
||||
//Creates String-arraylist with oPCode.
|
||||
ArrayList<String> oPCode = getOPCode(dataLines);
|
||||
|
||||
//Integer-array which will contain oPCode as int-values.
|
||||
//Get an twodimensional array with int-values.
|
||||
int[][] oPCodeAsInt = getOPCodeArrayCommandAsInt(oPCode);
|
||||
|
||||
//Set length of eeprom for programend.
|
||||
oPIC.getEeprom().setLengthEEPROM(oPCodeAsInt.length);
|
||||
|
||||
//asCommands are written into EEPROM
|
||||
for (int i = 0; i < oPCodeAsInt.length; i++) {
|
||||
//The adress where the command will be written in the EEPROM
|
||||
int memoryAdress = oPCodeAsInt[i][0];
|
||||
//System.out.println(memoryAdress);
|
||||
|
||||
//Command that will be written into the EEPROM
|
||||
int command = oPCodeAsInt[i][1];
|
||||
//System.out.println(command);
|
||||
//Set length of eeprom for programend.
|
||||
oPIC.getEeprom().setLengthEEPROM(oPCodeAsInt.length);
|
||||
|
||||
//asCommands are written into EEPROM
|
||||
oPIC.getEeprom().setElementXToValueY(memoryAdress, command);
|
||||
}
|
||||
for (int i = 0; i < oPCodeAsInt.length; i++) {
|
||||
//The adress where the command will be written in the EEPROM
|
||||
int memoryAdress = oPCodeAsInt[i][0];
|
||||
//System.out.println(memoryAdress);
|
||||
|
||||
//Command that will be written into the EEPROM
|
||||
int command = oPCodeAsInt[i][1];
|
||||
//System.out.println(command);
|
||||
|
||||
//asCommands are written into EEPROM
|
||||
oPIC.getEeprom().setElementXToValueY(memoryAdress, command);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,393 +0,0 @@
|
||||
package Backend.FrontendCommandProcessing;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import Backend.BackendCommandProcessing.InformationConnecter;
|
||||
import Backend.EepromLoader.ReadEepromFile;
|
||||
import Backend.Runtime.Environment;
|
||||
import Backend.Microcontroller.PIC;
|
||||
|
||||
public class CommandAction {
|
||||
|
||||
int iAction;
|
||||
String sValue;
|
||||
Environment env;
|
||||
|
||||
//List with methods
|
||||
private List<Callable> actions = new ArrayList<>();
|
||||
|
||||
private InformationConnecter informationConnecter = new InformationConnecter();
|
||||
|
||||
public CommandAction(int iAction, String sValue, Environment env) {
|
||||
this.iAction = iAction;
|
||||
this.sValue = sValue;
|
||||
this.env = env;
|
||||
|
||||
actions.add(callLoadFile);//0
|
||||
actions.add(callSaveProgrammState);//1
|
||||
actions.add(callSetBreakpoint);//2
|
||||
actions.add(callTogglePortA);//3
|
||||
actions.add(callTogglePortB);//4
|
||||
actions.add(callChangeQuarz);//5
|
||||
actions.add(callToggleWatchdog);//6
|
||||
actions.add(callReset);//7
|
||||
actions.add(callStep);//8
|
||||
actions.add(callStartProgramm);//9
|
||||
actions.add(callStopProgramm);//10
|
||||
actions.add(callLoadProgrammState);//11
|
||||
actions.add(callRemoveBreakpoint);//12
|
||||
actions.add(callRemoveAllBreakpoints);//13
|
||||
|
||||
actions.add(callErrorReadFailed);//14
|
||||
}
|
||||
|
||||
public int execute() {
|
||||
int iReturn = 0;
|
||||
if (iAction > -1) {
|
||||
try {
|
||||
iReturn = (int)actions.get(iAction).call();
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return iReturn;
|
||||
}
|
||||
|
||||
Callable callLoadFile = new Callable() {
|
||||
@Override
|
||||
public Object call() {
|
||||
return loadFile();
|
||||
}
|
||||
};
|
||||
|
||||
Callable callSaveProgrammState = new Callable() {
|
||||
@Override
|
||||
public Object call() {
|
||||
return saveProgrammState();
|
||||
}
|
||||
};
|
||||
|
||||
Callable callSetBreakpoint = new Callable() {
|
||||
@Override
|
||||
public Object call() {
|
||||
return setBreakpoint();
|
||||
}
|
||||
};
|
||||
|
||||
Callable callTogglePortA = new Callable() {
|
||||
@Override
|
||||
public Object call() {
|
||||
return togglePortA();
|
||||
}
|
||||
};
|
||||
|
||||
Callable callTogglePortB = new Callable() {
|
||||
@Override
|
||||
public Object call() {
|
||||
return togglePortB();
|
||||
}
|
||||
};
|
||||
|
||||
Callable callChangeQuarz = new Callable() {
|
||||
@Override
|
||||
public Object call() {
|
||||
return changeQuarz();
|
||||
}
|
||||
};
|
||||
|
||||
Callable callToggleWatchdog = new Callable() {
|
||||
@Override
|
||||
public Object call() {
|
||||
return toggleWatchdog();
|
||||
}
|
||||
};
|
||||
|
||||
Callable callReset = new Callable() {
|
||||
@Override
|
||||
public Object call() {
|
||||
return reset();
|
||||
}
|
||||
};
|
||||
|
||||
Callable callStep = new Callable() {
|
||||
@Override
|
||||
public Object call() {
|
||||
return step();
|
||||
}
|
||||
};
|
||||
|
||||
Callable callStartProgramm = new Callable() {
|
||||
@Override
|
||||
public Object call() {
|
||||
return startProgramm();
|
||||
}
|
||||
};
|
||||
|
||||
Callable callStopProgramm = new Callable() {
|
||||
@Override
|
||||
public Object call() {
|
||||
return stopProgramm();
|
||||
}
|
||||
};
|
||||
|
||||
Callable callLoadProgrammState = new Callable() {
|
||||
@Override
|
||||
public Object call() {
|
||||
return loadProgrammState();
|
||||
}
|
||||
};
|
||||
|
||||
Callable callRemoveBreakpoint = new Callable() {
|
||||
@Override
|
||||
public Object call() {
|
||||
return removeBreakpoint();
|
||||
}
|
||||
};
|
||||
|
||||
Callable callRemoveAllBreakpoints = new Callable() {
|
||||
@Override
|
||||
public Object call() {
|
||||
return removeAllBreakpoints();
|
||||
}
|
||||
};
|
||||
|
||||
Callable callErrorReadFailed = new Callable() {
|
||||
@Override
|
||||
public Object call() {
|
||||
return readFailed();
|
||||
}
|
||||
};
|
||||
|
||||
//Read file out of filepath and write it to EEPROM of oPIC.
|
||||
private int loadFile() {
|
||||
ReadEepromFile readEepromFile = new ReadEepromFile();
|
||||
env.getPIC().resetPIC();
|
||||
readEepromFile.readFileAndWriteToEEPROM(new File(sValue), env.getPIC());
|
||||
//env.getMainToFrontendQueue().add(informationConnecter.connectInformation(env.getPIC(), env.getActualLine(), env.getLastLine(), -2, -2, env.getRuntime(), env.getWatchdog().getTime()));
|
||||
//TODO sent message to thread, to change value in file
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int saveProgrammState() {
|
||||
//TODO Logic
|
||||
//TODO sent message to thread, to change value in file
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int setBreakpoint() {
|
||||
env.changeListBreakpoints(Integer.parseInt(sValue), true);
|
||||
//env.getMainToFrontendQueue().add(informationConnecter.connectInformation(env.getPIC(), env.getActualLine(), env.getLastLine(), Integer.parseInt(sValue), -2, env.getRuntime(), env.getWatchdog().getTime()));
|
||||
//TODO sent message to thread, to change value in file
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int togglePortA() {
|
||||
int iBit = Integer.parseInt(sValue.substring(0,1));
|
||||
int iValue = Integer.parseInt(sValue.substring(2, 3));
|
||||
env.getPIC().getRam().set_PORTA_Bit_X_To_Y(iBit, iValue);
|
||||
//TODO sent message to thread, to change value in file
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int togglePortB() {
|
||||
int iBit = Integer.parseInt(sValue.substring(0,1));
|
||||
int iValue = Integer.parseInt(sValue.substring(2, 3));
|
||||
env.getPIC().getRam().set_PORTB_Bit_X_To_Y(iBit, iValue);
|
||||
//TODO sent message to thread, to change value in file
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int changeQuarz() {
|
||||
//XTA(L) not implemented
|
||||
//TODO sent message to thread, to change value in file
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int toggleWatchdog() {
|
||||
/**
|
||||
* //WAT(CHDOG)
|
||||
if (sFileFrontendToBackendCommand.substring(9, 11).equals("ON"))
|
||||
{
|
||||
//ON
|
||||
liWorkWithWatchdog(1, 5);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
//OFF
|
||||
liWorkWithWatchdog(1, 4);
|
||||
}
|
||||
*/
|
||||
//TODO sent message to thread, to change value in file
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int reset() {
|
||||
/**
|
||||
* //RES(ET)
|
||||
liDifferenceTimeNano = 0;
|
||||
oPIC.resetPIC();
|
||||
//oPIC.Ram.set_OPTION(255);
|
||||
//resetLines();
|
||||
bCreateGUIFile = true;
|
||||
*/
|
||||
env.getPIC().resetPIC();
|
||||
env.getPIC().getRam().set_OPTION(255);
|
||||
//TODO sent message to thread, to change value in file
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int step() {
|
||||
/**
|
||||
* //STE(P)
|
||||
//System.out.println("STEP " + oPIC.Ram.get_Programcounter());
|
||||
if (oPIC.Ram.get_Programcounter() < (oPIC.Eeprom.getLengthEEPROM() - 1))
|
||||
{
|
||||
final long liTimeStart = System.nanoTime();
|
||||
|
||||
//Makes one step through the eeprom.
|
||||
bitMaskDecisionMaker(oPIC.Eeprom.getElement(oPIC.Ram.get_Programcounter()), oPIC);
|
||||
|
||||
final long timeEnd = System.nanoTime();
|
||||
|
||||
liDifferenceTimeNano += (timeEnd - liTimeStart);
|
||||
|
||||
if (!oPIC.Ram.get_T0CS())
|
||||
{
|
||||
oPIC.Ram.increment_TMR0();
|
||||
}
|
||||
|
||||
bCreateGUIFile = true;
|
||||
*/
|
||||
env.step();//step in env or set/gets
|
||||
//TODO sent message to thread, to change value in file
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int startProgramm() {
|
||||
/**
|
||||
* //STA(RT)
|
||||
|
||||
final long liTimeStart = System.nanoTime();
|
||||
|
||||
liWorkWithWatchdog(1, 1);
|
||||
|
||||
if ((iAccessBreakpoint(3, 0) > (-1)) && (iAccessBreakpoint(3, 0) <= (oPIC.Eeprom.getLengthEEPROM() - 1)))
|
||||
{
|
||||
while ((oPIC.Ram.get_Programcounter() < iAccessBreakpoint(3, 0)) && (cMenueSelection != 'p'))
|
||||
{
|
||||
//System.out.println("STEP " + oPIC.Ram.get_Programcounter());
|
||||
bitMaskDecisionMaker(oPIC.Eeprom.getElement(oPIC.Ram.get_Programcounter()), oPIC);
|
||||
|
||||
if (!oPIC.Ram.get_T0CS())
|
||||
{
|
||||
oPIC.Ram.increment_TMR0();
|
||||
}
|
||||
|
||||
bCreateGUIFile = true;
|
||||
}
|
||||
iAccessBreakpoint(2, 0);
|
||||
bCreateGUIFile = true;
|
||||
System.out.println(iAccessBreakpoint(3, 0));
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
while ((oPIC.Ram.get_Programcounter() < ((oPIC.Eeprom.getLengthEEPROM() - 1))) && (cMenueSelection != 'p'))
|
||||
{
|
||||
//System.out.println("STEP " + oPIC.Ram.get_Programcounter());
|
||||
bitMaskDecisionMaker(oPIC.Eeprom.getElement(oPIC.Ram.get_Programcounter()), oPIC);
|
||||
|
||||
if (!oPIC.Ram.get_T0CS())
|
||||
{
|
||||
oPIC.Ram.increment_TMR0();
|
||||
}
|
||||
|
||||
bCreateGUIFile = true;
|
||||
}
|
||||
}
|
||||
|
||||
liWorkWithWatchdog(1, 2);
|
||||
final long timeEnd = System.nanoTime();
|
||||
|
||||
liDifferenceTimeNano = timeEnd - liTimeStart;
|
||||
|
||||
bCreateGUIFile = true;
|
||||
*/
|
||||
//TODO sent message to thread, to change value in file
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int stopProgramm() {
|
||||
/**
|
||||
* //STO(PP)
|
||||
//watchdogThread.setWatchdogStatus(3);
|
||||
cMenueSelection = 'p';
|
||||
*/
|
||||
//TODO sent message to thread, to change value in file
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int loadProgrammState() {
|
||||
//TODO sent message to thread, to change value in file
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int removeBreakpoint() {
|
||||
env.changeListBreakpoints(Integer.parseInt(sValue), false);
|
||||
//TODO sent message to thread, to change value in file
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int removeAllBreakpoints() {
|
||||
env.changeListBreakpoints(-1, false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int readFailed() {
|
||||
System.out.println("Fehler: Lesen der Datei fehlgeschlagen.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* //PRT( Scale) ? Prescaler is set from additional frontend.
|
||||
try
|
||||
{
|
||||
if (sFileFrontendToBackendCommand.substring(4, 5) != null)
|
||||
{
|
||||
oPIC.Ram.set_OPTION((oPIC.Ram.get_OPTION() & 11111000) | (Integer.parseInt(sFileFrontendToBackendCommand.substring(4, 5))));
|
||||
bCreateGUIFile = true;
|
||||
}
|
||||
}
|
||||
catch (StringIndexOutOfBoundsException e)
|
||||
{}
|
||||
*/
|
||||
|
||||
/**
|
||||
* //PRW( Scale) ? Prescaler is set from additional frontend.
|
||||
try
|
||||
{
|
||||
if (sFileFrontendToBackendCommand.substring(4, 5) != null)
|
||||
{
|
||||
oPIC.Ram.set_OPTION((oPIC.Ram.get_OPTION() & 11111000) | (Integer.parseInt(sFileFrontendToBackendCommand.substring(4, 5))));
|
||||
bCreateGUIFile = true;
|
||||
}
|
||||
if (sFileFrontendToBackendCommand.substring(5, 6) != null)
|
||||
{
|
||||
oPIC.Ram.set_OPTION((oPIC.Ram.get_OPTION() & 11111000) | (Integer.parseInt(sFileFrontendToBackendCommand.substring(4, 6))));
|
||||
bCreateGUIFile = true;
|
||||
}
|
||||
if (sFileFrontendToBackendCommand.substring(6, 7) != null)
|
||||
{
|
||||
oPIC.Ram.set_OPTION((oPIC.Ram.get_OPTION() & 11111000) | (Integer.parseInt(sFileFrontendToBackendCommand.substring(4, 7))));
|
||||
bCreateGUIFile = true;
|
||||
}
|
||||
}
|
||||
catch (StringIndexOutOfBoundsException e)
|
||||
{}
|
||||
*/
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
package Backend.FrontendCommandProcessing;
|
||||
|
||||
import java.util.regex.*;
|
||||
|
||||
import Backend.Runtime.Environment;
|
||||
|
||||
//TODO Changes at patterns have to occur at all methods!
|
||||
|
||||
/**
|
||||
* Class to decode commandstring.
|
||||
*/
|
||||
public class CommandDecoder {
|
||||
|
||||
private String sActualCommand = "";
|
||||
|
||||
public CommandDecoder(String sActualCommand) {
|
||||
this.sActualCommand = sActualCommand;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type of command.
|
||||
* @return int representation of pattern, -1 if no pattern matches
|
||||
*/
|
||||
public int getCommandType() {
|
||||
|
||||
int iPatternMatched = 0;
|
||||
|
||||
//Read file and save line to string
|
||||
//sActualCommand = input.getActualCommand();
|
||||
|
||||
//External oparations
|
||||
Pattern loadFile = Pattern.compile("^F_\\S*$");//0
|
||||
Pattern saveProgrammState = Pattern.compile("^S_\\S*$");//1
|
||||
Pattern setBreakpoint = Pattern.compile("^BS_\\d*$");//2
|
||||
Pattern togglePortA = Pattern.compile("^PA_\\d\\s(1|0)$");//3
|
||||
Pattern togglePortB = Pattern.compile("^PB_\\d$");//4
|
||||
Pattern changeQuarz = Pattern.compile("^Q_[\\d]{1,2}$");//5
|
||||
Pattern toggleWatchdog = Pattern.compile("W_[tf]$");//6
|
||||
Pattern reset = Pattern.compile("^R_$");//7
|
||||
Pattern step = Pattern.compile("^S_$");//8
|
||||
Pattern startProgramm = Pattern.compile("^RP_$");//9
|
||||
Pattern stopProgramm = Pattern.compile("^SP_$");//10
|
||||
Pattern loadProgrammState = Pattern.compile("^L_\\S*$");//11
|
||||
Pattern removeBreakpoint = Pattern.compile("^BR_\\d*$");//12
|
||||
Pattern removeAllBreakpoint = Pattern.compile("^BRA$");//13
|
||||
|
||||
//Internal operations
|
||||
Pattern errorFileRead = Pattern.compile("ERROR FILEREAD");//14
|
||||
|
||||
Pattern[] patterns = {loadFile, saveProgrammState, setBreakpoint, togglePortA, togglePortB, changeQuarz, toggleWatchdog, reset, step,
|
||||
startProgramm, stopProgramm, loadProgrammState, removeBreakpoint, removeAllBreakpoint, errorFileRead};
|
||||
|
||||
int iNumberOfPatterns = patterns.length;
|
||||
|
||||
//Iterate through patterns and check if pattern matches to command.
|
||||
for (int i = 0; i < iNumberOfPatterns; i++) {
|
||||
Matcher matcher = patterns[i].matcher(sActualCommand);
|
||||
boolean bMatchFound = matcher.find();
|
||||
if (bMatchFound) {
|
||||
iPatternMatched = i;
|
||||
i = iNumberOfPatterns; // break loop for performance
|
||||
} else {
|
||||
iPatternMatched = -1;
|
||||
}
|
||||
}
|
||||
|
||||
return iPatternMatched;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get value of command
|
||||
* @return
|
||||
*/
|
||||
public String getCommandValue(int iCommandType) {
|
||||
|
||||
int iStringLen = sActualCommand.length();
|
||||
|
||||
String sValue = "";
|
||||
|
||||
switch (iCommandType) {
|
||||
//0 F_<Path>
|
||||
//1 S_<Path>
|
||||
//5 Q_<IndexNr>
|
||||
//6 W_<Boolean>
|
||||
case 0:
|
||||
case 1:
|
||||
case 5:
|
||||
case 6:
|
||||
case 11: {
|
||||
sValue = sActualCommand.substring(2, iStringLen);
|
||||
}break;
|
||||
|
||||
//2 BS_<RowNr>
|
||||
//3 PA_<PortNr>
|
||||
//4 PB_<PortNr>
|
||||
//12 BR_<RowNr>
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 12: {
|
||||
sValue = sActualCommand.substring(3, iStringLen);
|
||||
}break;
|
||||
|
||||
case 13: {
|
||||
//No Value needed
|
||||
}break;
|
||||
|
||||
default: {
|
||||
sValue = "undefined";
|
||||
}break;
|
||||
}
|
||||
|
||||
return sValue;
|
||||
}
|
||||
|
||||
public int executeAction(Environment env) {
|
||||
int iAction = getCommandType();
|
||||
String sValue = getCommandValue(iAction);
|
||||
CommandAction action = new CommandAction(iAction, sValue, env);
|
||||
return action.execute();
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package Backend.FrontendCommandProcessing;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
/**
|
||||
* Thread-class responsibility is to check every few milliseconds if fileBackendToFrontend exists and if so, then read it and send string through queue to main-thread.
|
||||
*/
|
||||
public class FrontendCommandProcessingThread extends Thread {
|
||||
|
||||
private static File fileBackendToFrontend = new File("../SIMULATOR_DAT/gui_set.dat");
|
||||
|
||||
private ConcurrentLinkedQueue<String> queue;
|
||||
|
||||
private int iSleepTime = 100;
|
||||
|
||||
ReadFile readFile = new ReadFile();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param inputQueue overhanded from main-method
|
||||
*/
|
||||
public FrontendCommandProcessingThread(ConcurrentLinkedQueue<String> inputQueue) {
|
||||
queue = inputQueue;
|
||||
}
|
||||
|
||||
/**
|
||||
* FrontendCommandProcessingThread-class responsibility is to check every few milliseconds if fileBackendToFrontend exists and if so, then read it and send string through queue to main-thread.
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
String sActualCommand = "";
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
//Sleeps iSleepTime milli seconds
|
||||
Thread.sleep(iSleepTime);
|
||||
} catch(InterruptedException e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
if (fileBackendToFrontend.isFile()) {
|
||||
sActualCommand = readFile.getActualCommand();
|
||||
queue.add(sActualCommand);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
package Backend.FrontendCommandProcessing;
|
||||
//package SIMULATOR;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* Class reads line out of file.
|
||||
*/
|
||||
public class ReadFile {
|
||||
|
||||
private File fileFrontendToBackend = new File("C:/Users/Windows 10/Desktop/Studium/SS_21/Rechnerarchitektur_Projekt/gui_change.dat");
|
||||
private String sActualCommand;
|
||||
|
||||
public ReadFile() {}
|
||||
|
||||
/**
|
||||
* Resets file from where data is read to new overhanded path.
|
||||
* @param fileFrontendToBackend
|
||||
*/
|
||||
public ReadFile(String fileFrontendToBackend) {
|
||||
this.fileFrontendToBackend = new File(fileFrontendToBackend);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads FrontendToBackend-file and updates (-)sActualCommand.
|
||||
* @return 1 at success, -1 at error
|
||||
*/
|
||||
private int readInputFile() {
|
||||
|
||||
int iReturn = 0;
|
||||
try {
|
||||
FileReader fileReader = new FileReader(fileFrontendToBackend);
|
||||
BufferedReader bufferedReader = new BufferedReader(fileReader);
|
||||
sActualCommand = bufferedReader.readLine();
|
||||
bufferedReader.close();
|
||||
fileFrontendToBackend.delete();
|
||||
iReturn = 1; // success
|
||||
} catch (IOException e) {
|
||||
iReturn = -1; // error
|
||||
}
|
||||
return iReturn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads file and returns actual command as string
|
||||
* @return command as string at success, ERROR at error
|
||||
*/
|
||||
public String getActualCommand() {
|
||||
String line = null;
|
||||
int iReadInputFile = readInputFile();
|
||||
if (iReadInputFile == 1) {
|
||||
line = sActualCommand;
|
||||
} else if (iReadInputFile == -1) {
|
||||
line = "ERROR FILEREAD";
|
||||
}
|
||||
return line;
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,8 @@
|
||||
|
||||
package Backend.Runtime;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import Backend.FrontendCommandProcessing.CommandDecoder;
|
||||
import Backend.Microcontroller.PIC;
|
||||
import Backend.Microcontroller.WATCHDOG;
|
||||
import Frontend.PIC_SIMULATOR_GUI_JAVA.GUIMainFrame;
|
||||
@@ -33,11 +31,12 @@ public class Environment {
|
||||
|
||||
public Environment() {
|
||||
|
||||
GUIMainFrame oMainFrame = new GUIMainFrame();
|
||||
GUIMainFrame oMainFrame = new GUIMainFrame(this);
|
||||
|
||||
watchdog = new WATCHDOG();
|
||||
|
||||
|
||||
|
||||
oPIC = new PIC();
|
||||
|
||||
sEepromDataFile = "";
|
||||
|
||||
9
src/Backend/Runtime/Testfile.java
Normal file
9
src/Backend/Runtime/Testfile.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package Backend.Runtime;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Testfile {
|
||||
ArrayList<String> lsTestfile;
|
||||
|
||||
|
||||
}
|
||||
@@ -1,43 +1,43 @@
|
||||
package Frontend.PIC_SIMULATOR_GUI_JAVA;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.event.*;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.GridBagConstraints;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.border.Border;
|
||||
|
||||
import Backend.EepromLoader.ReadEepromFile;
|
||||
import Backend.Runtime.Environment;
|
||||
|
||||
public class GUIMainFrame extends JFrame {
|
||||
|
||||
GUITestFileTable oGUITestFileTable;
|
||||
GUIMenuBar oGUIMenuBar;
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public GUIMainFrame() {
|
||||
public GUIMainFrame(Environment env) {
|
||||
|
||||
this.setTitle("PIC-Simulator GUI"); // sets title of frame
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // if x is pressed, exit application (HIDE_ON_CLOSE-hides application, DO_NOTHING_ON_CLOSE-prevents user from closing application)
|
||||
//this.setResizable(false); // prevent frame from beeing resized
|
||||
this.setSize(420, 420); //sets x and y dimension of frame
|
||||
this.setLayout(new FlowLayout());
|
||||
this.setSize(1200, 840); //sets x and y dimension of frame
|
||||
this.setLayout(new GridBagLayout());
|
||||
|
||||
this.setJMenuBar(new GUIMenuBar(this));
|
||||
oGUITestFileTable = new GUITestFileTable();
|
||||
|
||||
this.setJMenuBar(new GUIMenuBar(env, this, oGUITestFileTable));
|
||||
|
||||
this.setVisible(true); //make frame visible
|
||||
this.setBackground(new Color(76, 78, 82));
|
||||
ImageIcon guiLogo = new ImageIcon("./images/gui_logo.png"); // create an ImageIcon
|
||||
this.setIconImage(guiLogo.getImage()); // change icon of frame
|
||||
|
||||
|
||||
Color guiBackgroundColor = new Color(255, 255, 255); // 0xFFFFFF || 0, 0, 0
|
||||
//this.getContentPane().setBackground(guiBackgroundColor); //change color of background
|
||||
//this.getContentPane().setBackground(Color.green); //change color of background
|
||||
|
||||
//JLabel text = new JLabel(); // create label, passing of text at constructor possible
|
||||
//text.setText("Bro do you even code?"); // set text of label
|
||||
@@ -57,7 +57,21 @@ public class GUIMainFrame extends JFrame {
|
||||
//text.setHorizontalAlignment(JLabel.CENTER); // horizontally aligns label "text" (JLabel.LEFT, JLabel.CENTER, JLabel.RIGHT)
|
||||
|
||||
//this.add(text); // add label to frame
|
||||
|
||||
//getContentPane().setLayout(new BorderLayout());
|
||||
//this.add(new GUITestFileTable("./testfiles/TPicSim1.LST"));
|
||||
GridBagConstraints oGridBagConstraints = new GridBagConstraints();
|
||||
oGridBagConstraints.gridx = 10;
|
||||
oGridBagConstraints.gridy = 10;
|
||||
oGridBagConstraints.gridheight = 10;
|
||||
oGridBagConstraints.gridwidth = 500;
|
||||
oGridBagConstraints.anchor = GridBagConstraints.PAGE_START;
|
||||
this.add(oGUITestFileTable, oGridBagConstraints);
|
||||
updateWindow();
|
||||
}
|
||||
|
||||
|
||||
public void updateWindow() {
|
||||
this.revalidate();
|
||||
this.repaint();
|
||||
}
|
||||
}
|
||||
@@ -5,14 +5,26 @@ import java.awt.Dimension;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
|
||||
import Backend.EepromLoader.ReadEepromFile;
|
||||
import Backend.Runtime.Environment;
|
||||
|
||||
public class GUIMenuBar extends JMenuBar implements ActionListener {
|
||||
GUIMainFrame oMainFrame;
|
||||
Environment oEnv;
|
||||
GUIMainFrame oGUIMainFrame;
|
||||
GUITestFileTable oGUITestFileTable;
|
||||
ArrayList<JCheckBox> oCheckBoxes;
|
||||
ReadEepromFile oRef;
|
||||
boolean[] bBreakpointSet;
|
||||
|
||||
//Custom separators because addSeparator(default) looks not nice.
|
||||
JMenuItem oSeparator0;
|
||||
@@ -80,7 +92,7 @@ public class GUIMenuBar extends JMenuBar implements ActionListener {
|
||||
* Constructor initializes menubar.
|
||||
* @param frame
|
||||
*/
|
||||
public GUIMenuBar(GUIMainFrame frame) { //TODO maybe single components, with methods, of frame to set theme
|
||||
public GUIMenuBar(Environment env, GUIMainFrame mainframe, GUITestFileTable guitft) { //TODO maybe single components, with methods, of frame to set theme
|
||||
|
||||
//Custom Separators since default is not able to change background.
|
||||
oSeparator0 = new JMenuItem();
|
||||
@@ -97,7 +109,9 @@ public class GUIMenuBar extends JMenuBar implements ActionListener {
|
||||
oSeparator3.setPreferredSize(new Dimension(0,1));
|
||||
|
||||
//Referrence to change different parts of gui for theme.
|
||||
oMainFrame = frame;
|
||||
oEnv = env;
|
||||
oGUIMainFrame = mainframe;
|
||||
oGUITestFileTable = guitft;
|
||||
|
||||
//File
|
||||
oFileMenu = new JMenu(sGermanLang[0]);
|
||||
@@ -326,8 +340,7 @@ public class GUIMenuBar extends JMenuBar implements ActionListener {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
//File
|
||||
if (e.getSource() == oLoadTestFile) {
|
||||
System.out.println("Bro do you even code? test");
|
||||
//TODO
|
||||
loadTestFile();
|
||||
}
|
||||
if (e.getSource() == oLoadProgStateItem) {
|
||||
System.out.println("Bro do you even code? load");
|
||||
@@ -352,7 +365,7 @@ public class GUIMenuBar extends JMenuBar implements ActionListener {
|
||||
}
|
||||
//Change to light theme
|
||||
if (e.getSource() == oLightTheme) {
|
||||
System.out.println("It burns, it burnnnnnnssssss"); //TODO
|
||||
System.out.println("Death to all vampires!"); //TODO
|
||||
setTheme(aoLightTheme[0], aoLightTheme[1]);
|
||||
}
|
||||
|
||||
@@ -367,7 +380,7 @@ public class GUIMenuBar extends JMenuBar implements ActionListener {
|
||||
System.out.println("oResetProg"); //TODO
|
||||
}
|
||||
if (e.getSource() == oStepProg) {
|
||||
System.out.println("oStepProg"); //TODO
|
||||
oEnv.step();
|
||||
}
|
||||
if (e.getSource() == oIntervalASAP) {
|
||||
System.out.println("oIntervalASAP"); //TODO
|
||||
@@ -399,6 +412,8 @@ public class GUIMenuBar extends JMenuBar implements ActionListener {
|
||||
if (e.getSource() == oAbout) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
controlBreakpoints(e);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -504,4 +519,59 @@ public class GUIMenuBar extends JMenuBar implements ActionListener {
|
||||
oSeparator3.setBackground(oColorSeparators);
|
||||
oSeparator3.setBorder(BorderFactory.createLineBorder(oColorSeparators, 2));
|
||||
}
|
||||
|
||||
private void loadTestFile() {
|
||||
File oFile;
|
||||
//select file to open
|
||||
JFileChooser oFileChooser = new JFileChooser();
|
||||
int iResponse = oFileChooser.showOpenDialog(null);
|
||||
if (iResponse == JFileChooser.APPROVE_OPTION) {
|
||||
oFile = new File(oFileChooser.getSelectedFile().getAbsolutePath());
|
||||
System.out.println(oFile);
|
||||
oRef = new ReadEepromFile();
|
||||
oRef.setData(oFile);
|
||||
oRef.setOPCode(oRef.getData());
|
||||
oGUITestFileTable.setData(oRef.getData());
|
||||
ArrayList<String> data = oRef.getData();
|
||||
int iDataSize = data.size();
|
||||
ArrayList<String> opcode = oRef.getOPCode();
|
||||
int iOPCodeSize = opcode.size();
|
||||
for (int i = 0; i < iDataSize; i++) {
|
||||
for (int j = 0; j < iOPCodeSize; j++) {
|
||||
if (data.get(i).equals(opcode.get(j))) {
|
||||
oCheckBoxes = oGUITestFileTable.getCheckboxes();
|
||||
oCheckBoxes.get(i).setEnabled(true);
|
||||
oCheckBoxes.get(i).addActionListener(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
bBreakpointSet = new boolean[iOPCodeSize];
|
||||
oRef.readFileAndWriteToEEPROM(oEnv.getPIC());
|
||||
oGUIMainFrame.updateWindow();
|
||||
}
|
||||
}
|
||||
|
||||
private void controlBreakpoints(ActionEvent e) {
|
||||
int iOPCode = oRef.getOPCode().size();
|
||||
|
||||
if (iOPCode > 0) {
|
||||
for (int i = 0; i < oCheckBoxes.size(); i++) {
|
||||
if (e.getSource() == oCheckBoxes.get(i)) {
|
||||
for (int j = 0; j < iOPCode; j++) {
|
||||
if (oRef.getOPCode().get(j).equals(oRef.getData().get(i))) {
|
||||
bBreakpointSet[j] = !bBreakpointSet[j];
|
||||
if (bBreakpointSet[j])
|
||||
System.out.println("Breakpoint " + j + " got set.");
|
||||
else
|
||||
System.out.println("Breakpoint " + j + " got reset.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean[] getBreakpoints() {
|
||||
return bBreakpointSet;
|
||||
}
|
||||
}
|
||||
85
src/Frontend/PIC_SIMULATOR_GUI_JAVA/GUITestFileTable.java
Normal file
85
src/Frontend/PIC_SIMULATOR_GUI_JAVA/GUITestFileTable.java
Normal file
@@ -0,0 +1,85 @@
|
||||
package Frontend.PIC_SIMULATOR_GUI_JAVA;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class GUITestFileTable extends JPanel {
|
||||
String sLine;
|
||||
ArrayList<JCheckBox> oCheckboxes = new ArrayList<JCheckBox>();
|
||||
|
||||
public GUITestFileTable() {
|
||||
this.setLayout(new GridBagLayout());
|
||||
GridBagConstraints oGridBagConstraints = new GridBagConstraints();
|
||||
oGridBagConstraints.gridx = 0;
|
||||
oGridBagConstraints.gridy = 0;
|
||||
oGridBagConstraints.gridheight = 20;
|
||||
oGridBagConstraints.gridwidth = 20; //500, 10, 10, 480
|
||||
JTextField oFill = new JTextField("19");
|
||||
oFill.setEditable(false);
|
||||
this.add(oFill, oGridBagConstraints);
|
||||
oGridBagConstraints.gridx = 20;
|
||||
this.add(new JCheckBox(), oGridBagConstraints);
|
||||
oGridBagConstraints.gridx = 40;
|
||||
oGridBagConstraints.gridwidth = 460;
|
||||
oFill = new JTextField("Test");
|
||||
oFill.setEditable(false);
|
||||
this.add(oFill, oGridBagConstraints);
|
||||
}
|
||||
|
||||
public void setData(ArrayList<String> data) {
|
||||
this.removeAll();
|
||||
|
||||
int iNumberOfLines = data.size() + 1;
|
||||
|
||||
this.setLayout(new GridBagLayout());
|
||||
|
||||
JPanel oLineNumbers = new JPanel();
|
||||
oLineNumbers.setLayout(new GridLayout(iNumberOfLines, 1));
|
||||
GridBagConstraints oGridBagConstraints = new GridBagConstraints();
|
||||
oGridBagConstraints.gridx = 0;
|
||||
oGridBagConstraints.gridy = 0;
|
||||
oGridBagConstraints.gridwidth = 500;
|
||||
oGridBagConstraints.gridheight = 600;
|
||||
|
||||
JPanel oBreakpoints = new JPanel();
|
||||
oBreakpoints.setLayout(new GridLayout(iNumberOfLines, 1));
|
||||
|
||||
JPanel oFileLines = new JPanel();
|
||||
oFileLines.setLayout(new GridLayout(iNumberOfLines, 1));
|
||||
|
||||
for (int i = 1; i < iNumberOfLines; i++) {
|
||||
JTextField oTestLine = new JTextField(data.get(i - 1));
|
||||
oTestLine.setEditable(false);
|
||||
oFileLines.add(oTestLine);
|
||||
JCheckBox oCheckbox = new JCheckBox();
|
||||
oCheckbox.setEnabled(false);
|
||||
oCheckboxes.add(oCheckbox);
|
||||
oBreakpoints.add(oCheckbox);
|
||||
JTextField oNumber = new JTextField(i + "");
|
||||
oNumber.setEditable(false);
|
||||
oLineNumbers.add(oNumber);
|
||||
}
|
||||
|
||||
this.add(oLineNumbers, oGridBagConstraints);
|
||||
this.add(oBreakpoints);
|
||||
this.add(oFileLines);
|
||||
}
|
||||
|
||||
public ArrayList<JCheckBox> getCheckboxes() {
|
||||
return oCheckboxes;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user