diff --git a/bin/Backend/BackendCommandProcessing/BackendInformationTransferThread.class b/bin/Backend/BackendCommandProcessing/BackendInformationTransferThread.class deleted file mode 100644 index cca4b4f..0000000 Binary files a/bin/Backend/BackendCommandProcessing/BackendInformationTransferThread.class and /dev/null differ diff --git a/bin/Backend/EepromLoader/ReadEepromFile.class b/bin/Backend/EepromLoader/ReadEepromFile.class index 1b708dd..d6f5906 100644 Binary files a/bin/Backend/EepromLoader/ReadEepromFile.class and b/bin/Backend/EepromLoader/ReadEepromFile.class differ diff --git a/bin/Backend/FrontendCommandProcessing/CommandAction$1.class b/bin/Backend/FrontendCommandProcessing/CommandAction$1.class deleted file mode 100644 index 2b9c01d..0000000 Binary files a/bin/Backend/FrontendCommandProcessing/CommandAction$1.class and /dev/null differ diff --git a/bin/Backend/FrontendCommandProcessing/CommandAction$10.class b/bin/Backend/FrontendCommandProcessing/CommandAction$10.class deleted file mode 100644 index d83a3f8..0000000 Binary files a/bin/Backend/FrontendCommandProcessing/CommandAction$10.class and /dev/null differ diff --git a/bin/Backend/FrontendCommandProcessing/CommandAction$11.class b/bin/Backend/FrontendCommandProcessing/CommandAction$11.class deleted file mode 100644 index 18c9660..0000000 Binary files a/bin/Backend/FrontendCommandProcessing/CommandAction$11.class and /dev/null differ diff --git a/bin/Backend/FrontendCommandProcessing/CommandAction$12.class b/bin/Backend/FrontendCommandProcessing/CommandAction$12.class deleted file mode 100644 index 6e0c5c5..0000000 Binary files a/bin/Backend/FrontendCommandProcessing/CommandAction$12.class and /dev/null differ diff --git a/bin/Backend/FrontendCommandProcessing/CommandAction$13.class b/bin/Backend/FrontendCommandProcessing/CommandAction$13.class deleted file mode 100644 index 932bdfa..0000000 Binary files a/bin/Backend/FrontendCommandProcessing/CommandAction$13.class and /dev/null differ diff --git a/bin/Backend/FrontendCommandProcessing/CommandAction$14.class b/bin/Backend/FrontendCommandProcessing/CommandAction$14.class deleted file mode 100644 index 1321088..0000000 Binary files a/bin/Backend/FrontendCommandProcessing/CommandAction$14.class and /dev/null differ diff --git a/bin/Backend/FrontendCommandProcessing/CommandAction$15.class b/bin/Backend/FrontendCommandProcessing/CommandAction$15.class deleted file mode 100644 index aacff16..0000000 Binary files a/bin/Backend/FrontendCommandProcessing/CommandAction$15.class and /dev/null differ diff --git a/bin/Backend/FrontendCommandProcessing/CommandAction$2.class b/bin/Backend/FrontendCommandProcessing/CommandAction$2.class deleted file mode 100644 index 2cc2b9f..0000000 Binary files a/bin/Backend/FrontendCommandProcessing/CommandAction$2.class and /dev/null differ diff --git a/bin/Backend/FrontendCommandProcessing/CommandAction$3.class b/bin/Backend/FrontendCommandProcessing/CommandAction$3.class deleted file mode 100644 index af718fa..0000000 Binary files a/bin/Backend/FrontendCommandProcessing/CommandAction$3.class and /dev/null differ diff --git a/bin/Backend/FrontendCommandProcessing/CommandAction$4.class b/bin/Backend/FrontendCommandProcessing/CommandAction$4.class deleted file mode 100644 index a164759..0000000 Binary files a/bin/Backend/FrontendCommandProcessing/CommandAction$4.class and /dev/null differ diff --git a/bin/Backend/FrontendCommandProcessing/CommandAction$5.class b/bin/Backend/FrontendCommandProcessing/CommandAction$5.class deleted file mode 100644 index 2b7ae1d..0000000 Binary files a/bin/Backend/FrontendCommandProcessing/CommandAction$5.class and /dev/null differ diff --git a/bin/Backend/FrontendCommandProcessing/CommandAction$6.class b/bin/Backend/FrontendCommandProcessing/CommandAction$6.class deleted file mode 100644 index e59faf6..0000000 Binary files a/bin/Backend/FrontendCommandProcessing/CommandAction$6.class and /dev/null differ diff --git a/bin/Backend/FrontendCommandProcessing/CommandAction$7.class b/bin/Backend/FrontendCommandProcessing/CommandAction$7.class deleted file mode 100644 index 0b1c699..0000000 Binary files a/bin/Backend/FrontendCommandProcessing/CommandAction$7.class and /dev/null differ diff --git a/bin/Backend/FrontendCommandProcessing/CommandAction$8.class b/bin/Backend/FrontendCommandProcessing/CommandAction$8.class deleted file mode 100644 index 8eb7f9d..0000000 Binary files a/bin/Backend/FrontendCommandProcessing/CommandAction$8.class and /dev/null differ diff --git a/bin/Backend/FrontendCommandProcessing/CommandAction$9.class b/bin/Backend/FrontendCommandProcessing/CommandAction$9.class deleted file mode 100644 index 1245beb..0000000 Binary files a/bin/Backend/FrontendCommandProcessing/CommandAction$9.class and /dev/null differ diff --git a/bin/Backend/FrontendCommandProcessing/CommandAction.class b/bin/Backend/FrontendCommandProcessing/CommandAction.class deleted file mode 100644 index 7963297..0000000 Binary files a/bin/Backend/FrontendCommandProcessing/CommandAction.class and /dev/null differ diff --git a/bin/Backend/FrontendCommandProcessing/CommandDecoder.class b/bin/Backend/FrontendCommandProcessing/CommandDecoder.class deleted file mode 100644 index fec746e..0000000 Binary files a/bin/Backend/FrontendCommandProcessing/CommandDecoder.class and /dev/null differ diff --git a/bin/Backend/FrontendCommandProcessing/FrontendCommandProcessingThread.class b/bin/Backend/FrontendCommandProcessing/FrontendCommandProcessingThread.class deleted file mode 100644 index 270965a..0000000 Binary files a/bin/Backend/FrontendCommandProcessing/FrontendCommandProcessingThread.class and /dev/null differ diff --git a/bin/Backend/FrontendCommandProcessing/ReadFile.class b/bin/Backend/FrontendCommandProcessing/ReadFile.class deleted file mode 100644 index 29afeba..0000000 Binary files a/bin/Backend/FrontendCommandProcessing/ReadFile.class and /dev/null differ diff --git a/bin/Backend/Runtime/Environment.class b/bin/Backend/Runtime/Environment.class index a78e009..a6fd8ff 100644 Binary files a/bin/Backend/Runtime/Environment.class and b/bin/Backend/Runtime/Environment.class differ diff --git a/bin/Backend/Runtime/Testfile.class b/bin/Backend/Runtime/Testfile.class new file mode 100644 index 0000000..e2f3065 Binary files /dev/null and b/bin/Backend/Runtime/Testfile.class differ diff --git a/bin/Frontend/PIC_SIMULATOR_GUI_JAVA/GUIMainFrame.class b/bin/Frontend/PIC_SIMULATOR_GUI_JAVA/GUIMainFrame.class index a42e755..f0dd174 100644 Binary files a/bin/Frontend/PIC_SIMULATOR_GUI_JAVA/GUIMainFrame.class and b/bin/Frontend/PIC_SIMULATOR_GUI_JAVA/GUIMainFrame.class differ diff --git a/bin/Frontend/PIC_SIMULATOR_GUI_JAVA/GUIMenuBar.class b/bin/Frontend/PIC_SIMULATOR_GUI_JAVA/GUIMenuBar.class index 36adfed..3c0b56c 100644 Binary files a/bin/Frontend/PIC_SIMULATOR_GUI_JAVA/GUIMenuBar.class and b/bin/Frontend/PIC_SIMULATOR_GUI_JAVA/GUIMenuBar.class differ diff --git a/bin/Frontend/PIC_SIMULATOR_GUI_JAVA/GUITestFileTable.class b/bin/Frontend/PIC_SIMULATOR_GUI_JAVA/GUITestFileTable.class index e135bab..e7c5bc6 100644 Binary files a/bin/Frontend/PIC_SIMULATOR_GUI_JAVA/GUITestFileTable.class and b/bin/Frontend/PIC_SIMULATOR_GUI_JAVA/GUITestFileTable.class differ diff --git a/src/Backend/BackendCommandProcessing/BackendInformationTransferThread.java b/src/Backend/BackendCommandProcessing/BackendInformationTransferThread.java deleted file mode 100755 index 872f0a8..0000000 --- a/src/Backend/BackendCommandProcessing/BackendInformationTransferThread.java +++ /dev/null @@ -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 queue; - - private int iSleepTime = 100; - - public BackendInformationTransferThread(ConcurrentLinkedQueue 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(); - } - } -} diff --git a/src/Backend/EepromLoader/ReadEepromFile.java b/src/Backend/EepromLoader/ReadEepromFile.java index 2cf9159..f94f52c 100755 --- a/src/Backend/EepromLoader/ReadEepromFile.java +++ b/src/Backend/EepromLoader/ReadEepromFile.java @@ -10,14 +10,16 @@ import Backend.Microcontroller.PIC; public class ReadEepromFile { + ArrayList dataLines; + ArrayList 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 getOPCode(ArrayList data) { + public void setOPCode(ArrayList data) { - ArrayList oPCode = new ArrayList(); + oPCode = new ArrayList(); 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 getOPCode() { return oPCode; } /** * Gets whole data of the file. * @param file - * @return ArrayList * @throws IOException */ - public ArrayList getData(File file) { + public void setData(File file) { + //Creates String-arraylist with whole data. + dataLines = new ArrayList(); - ArrayList list = new ArrayList(); 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 dataLines from current this object. + */ + public ArrayList 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 dataLines = getData(file); - - //Creates String-arraylist with oPCode. - ArrayList 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); + } + } } } diff --git a/src/Backend/FrontendCommandProcessing/CommandAction.java b/src/Backend/FrontendCommandProcessing/CommandAction.java deleted file mode 100755 index 6180ef4..0000000 --- a/src/Backend/FrontendCommandProcessing/CommandAction.java +++ /dev/null @@ -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 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) - {} - */ -} \ No newline at end of file diff --git a/src/Backend/FrontendCommandProcessing/CommandDecoder.java b/src/Backend/FrontendCommandProcessing/CommandDecoder.java deleted file mode 100755 index 0ea11f3..0000000 --- a/src/Backend/FrontendCommandProcessing/CommandDecoder.java +++ /dev/null @@ -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_ - //1 S_ - //5 Q_ - //6 W_ - case 0: - case 1: - case 5: - case 6: - case 11: { - sValue = sActualCommand.substring(2, iStringLen); - }break; - - //2 BS_ - //3 PA_ - //4 PB_ - //12 BR_ - 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(); - } -} \ No newline at end of file diff --git a/src/Backend/FrontendCommandProcessing/FrontendCommandProcessingThread.java b/src/Backend/FrontendCommandProcessing/FrontendCommandProcessingThread.java deleted file mode 100755 index f559b2a..0000000 --- a/src/Backend/FrontendCommandProcessing/FrontendCommandProcessingThread.java +++ /dev/null @@ -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 queue; - - private int iSleepTime = 100; - - ReadFile readFile = new ReadFile(); - - /** - * - * @param inputQueue overhanded from main-method - */ - public FrontendCommandProcessingThread(ConcurrentLinkedQueue 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); - } - } - } -} diff --git a/src/Backend/FrontendCommandProcessing/ReadFile.java b/src/Backend/FrontendCommandProcessing/ReadFile.java deleted file mode 100755 index 8749043..0000000 --- a/src/Backend/FrontendCommandProcessing/ReadFile.java +++ /dev/null @@ -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; - } -} diff --git a/src/Backend/Runtime/Environment.java b/src/Backend/Runtime/Environment.java index 7dd959f..db2b9fa 100755 --- a/src/Backend/Runtime/Environment.java +++ b/src/Backend/Runtime/Environment.java @@ -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 = ""; diff --git a/src/Backend/Runtime/Testfile.java b/src/Backend/Runtime/Testfile.java new file mode 100644 index 0000000..d4cae74 --- /dev/null +++ b/src/Backend/Runtime/Testfile.java @@ -0,0 +1,9 @@ +package Backend.Runtime; + +import java.util.ArrayList; + +public class Testfile { + ArrayList lsTestfile; + + +} \ No newline at end of file diff --git a/src/Frontend/PIC_SIMULATOR_GUI_JAVA/GUIMainFrame.java b/src/Frontend/PIC_SIMULATOR_GUI_JAVA/GUIMainFrame.java index 2c01813..9a7230f 100755 --- a/src/Frontend/PIC_SIMULATOR_GUI_JAVA/GUIMainFrame.java +++ b/src/Frontend/PIC_SIMULATOR_GUI_JAVA/GUIMainFrame.java @@ -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(); + } } \ No newline at end of file diff --git a/src/Frontend/PIC_SIMULATOR_GUI_JAVA/GUIMenuBar.java b/src/Frontend/PIC_SIMULATOR_GUI_JAVA/GUIMenuBar.java index 84d3afb..2de643e 100644 --- a/src/Frontend/PIC_SIMULATOR_GUI_JAVA/GUIMenuBar.java +++ b/src/Frontend/PIC_SIMULATOR_GUI_JAVA/GUIMenuBar.java @@ -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 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 data = oRef.getData(); + int iDataSize = data.size(); + ArrayList 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; + } } \ No newline at end of file diff --git a/src/Frontend/PIC_SIMULATOR_GUI_JAVA/GUITestFileTable.java b/src/Frontend/PIC_SIMULATOR_GUI_JAVA/GUITestFileTable.java new file mode 100644 index 0000000..f447009 --- /dev/null +++ b/src/Frontend/PIC_SIMULATOR_GUI_JAVA/GUITestFileTable.java @@ -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 oCheckboxes = new ArrayList(); + + 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 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 getCheckboxes() { + return oCheckboxes; + } +}