From 4cf8640a8f2e90536ce79e858816c5da7caf9e18 Mon Sep 17 00:00:00 2001 From: Rodrigo CORTES PORTO <Rodrigo.Cortes-porto@lip6.fr> Date: Wed, 22 Aug 2018 15:47:59 +0200 Subject: [PATCH] Fixed bug related to sc_time showing SC_S instead of SC_SEC and a bug when using microseconds and invalid characters were generated in the syscams code. (syscams) Fixed bug related to delays in input converter ports and current TDF time going negative. (syscams) Fixed bug with Fraction conversion, using BigFraction instead of Fraction. (syscams) --- .../syscamstranslator/SysCAMSTBlockTDF.java | 20 +++++++--- src/main/java/ui/SysCAMSPanelTranslator.java | 15 +++++++ ...DialogSysCAMSExecutableCodeGeneration.java | 40 ++++++++++++------- 3 files changed, 55 insertions(+), 20 deletions(-) diff --git a/src/main/java/syscamstranslator/SysCAMSTBlockTDF.java b/src/main/java/syscamstranslator/SysCAMSTBlockTDF.java index 12f8bc9edf..6b59d50f50 100644 --- a/src/main/java/syscamstranslator/SysCAMSTBlockTDF.java +++ b/src/main/java/syscamstranslator/SysCAMSTBlockTDF.java @@ -68,6 +68,7 @@ public class SysCAMSTBlockTDF extends SysCAMSTComponent { private LinkedList<SysCAMSTPortConverter> portConverter; private SysCAMSTPortConverter localPortConverter; private int n; + private boolean isTimestepPropagated; public SysCAMSTBlockTDF(String _name, double _period, String _time, String _processCode, DefaultListModel<String> _listStruct, String _nameTemplate, String _typeTemplate, DefaultListModel<String> _listTypedef, SysCAMSTCluster _cluster) { name = _name; @@ -82,6 +83,7 @@ public class SysCAMSTBlockTDF extends SysCAMSTComponent { portTDF = new LinkedList<SysCAMSTPortTDF>(); portConverter = new LinkedList<SysCAMSTPortConverter>(); n = 0; + isTimestepPropagated = false; } public String getName() { @@ -139,6 +141,14 @@ public class SysCAMSTBlockTDF extends SysCAMSTComponent { public void addPortConverter(SysCAMSTPortConverter converter){ portConverter.add(converter); } + + public boolean getIsTimestepPropagated() { + return isTimestepPropagated; + } + + public void setIsTimestepPropagated() { + isTimestepPropagated = true; + } public void syncTDFBlockDEBlock(double[] time_prev) throws SysCAMSValidateException { double tp; @@ -196,12 +206,12 @@ public class SysCAMSTBlockTDF extends SysCAMSTComponent { } System.out.println("time_prev_max_out: " + time_prev_max[1]); - if(time_now_min_de < time_prev_max[1]) { + if(time_now_min_tdf < time_prev_max[1]) { localPortConverter.setDelay((int)Math.ceil((time_prev_max[1]-time_now_min_de)/tp) + d); localPortConverter.setRecompute(true); throw new SysCAMSValidateException("Timestamp of previous write port executed module is: " + time_prev_max[1] - + " and current timestamp is: " + time_now_min_de + ".\n" - + "Suggested delay in port \"" + localPortConverter.getName() + "\": " + (Math.ceil((time_prev_max[1]-time_now_min_de)/tp) + d)); + + " and current timestamp is: " + time_now_min_tdf + ".\n" + + "Suggested delay in port \"" + localPortConverter.getName() + "\": " + (Math.ceil((time_prev_max[1]-time_now_min_tdf)/tp) + d)); } time_prev_max[0] = Double.valueOf(Math.max(time_prev_max[0],time_now_max_de)); System.out.println("New time_prev_max_in: " + time_prev_max[0]); @@ -232,8 +242,8 @@ public class SysCAMSTBlockTDF extends SysCAMSTComponent { for (k = 1; k <= r; k++) { time_tmp_tdf = (n*tm)+((k-1)*tp); time_tmp_de = (n*tm)+((k-1)*tp)+(d*tp);; - System.out.println("tmstmp_in_tdf: " + time_tmp_tdf); - System.out.println("tmstmp_in_de: " + time_tmp_de); + System.out.println("tmstmp_out_tdf: " + time_tmp_tdf); + System.out.println("tmstmp_out_de: " + time_tmp_de); time_now_min_tdf = Math.min(time_tmp_tdf, time_now_min_tdf); time_now_max_tdf = Math.max(time_tmp_tdf, time_now_max_tdf); time_now_min_de = Math.min(time_tmp_de, time_now_min_de); diff --git a/src/main/java/ui/SysCAMSPanelTranslator.java b/src/main/java/ui/SysCAMSPanelTranslator.java index 67e98f79bf..c590afb21c 100644 --- a/src/main/java/ui/SysCAMSPanelTranslator.java +++ b/src/main/java/ui/SysCAMSPanelTranslator.java @@ -167,6 +167,11 @@ public class SysCAMSPanelTranslator { String blockTDFName = blockTDF.getValue(); double periodBlock = blockTDF.getPeriod(); String timeBlock = blockTDF.getTime(); + if (timeBlock.equals("s")) { + timeBlock = timeBlock + "ec"; + } else if (timeBlock.equals("\u03BCs")) { + timeBlock = "us"; + } String processCode = blockTDF.getProcessCode(); DefaultListModel<String> listStruct = blockTDF.getListStruct(); String nameTemplate = blockTDF.getNameTemplate(); @@ -182,6 +187,11 @@ public class SysCAMSPanelTranslator { String portName = portTDF.getPortName(); double periodPort = portTDF.getPeriod(); String time = portTDF.getTime(); + if (time.equals("s")) { + time = time + "ec"; + } else if (time.equals("\u03BCs")) { + time = "us"; + } int rate = portTDF.getRate(); int delay = portTDF.getDelay(); String type = portTDF.getTDFType(); @@ -200,6 +210,11 @@ public class SysCAMSPanelTranslator { String portName = portConverter.getPortName(); double periodPort = portConverter.getPeriod(); String time = portConverter.getTime(); + if (time.equals("s")) { + time = time + "ec"; + } else if (time.equals("\u03BCs")) { + time = "us"; + } int rate = portConverter.getRate(); int delay = portConverter.getDelay(); String type = portConverter.getConvType(); diff --git a/src/main/java/ui/window/JDialogSysCAMSExecutableCodeGeneration.java b/src/main/java/ui/window/JDialogSysCAMSExecutableCodeGeneration.java index f59997cf41..f025550281 100644 --- a/src/main/java/ui/window/JDialogSysCAMSExecutableCodeGeneration.java +++ b/src/main/java/ui/window/JDialogSysCAMSExecutableCodeGeneration.java @@ -591,7 +591,6 @@ public class JDialogSysCAMSExecutableCodeGeneration extends javax.swing.JFrame i RealVector execRate = solveTopologyMatrix(topologyMatrix, tdfBlocks); //TODO: to recompute missing delays in loops: modify buffer with the suggested delay, and loop. do { - System.out.println("Computing schedule... " ); recompute = computeSchedule(execRate, topologyMatrix, buffer, tdfBlocks, connectors); if(recompute) suggest_delays = true; @@ -893,9 +892,7 @@ public class JDialogSysCAMSExecutableCodeGeneration extends javax.swing.JFrame i } } jta.append("Error: At least one Module or Port Timestep should be entered in at least one TDF block of this cluster.\n"); - //System.out.println("Error: at least one timestep should be entered."); throw new InterruptedException(); - //return; } public boolean propagateTm(SysCAMSTBlockTDF tdfBlock, LinkedList<SysCAMSTConnector> connectors) { @@ -910,11 +907,15 @@ public class JDialogSysCAMSExecutableCodeGeneration extends javax.swing.JFrame i * propagateTp(nextTdfBlock); * else //(Tp of connected block > 0) * validate timestep consitency between 2 ports. + * if connected block is unvisted + * propagateTp(nextTdfBlock); * return * */ double tm = tdfBlock.getPeriod(); double tp; int rate; + //Mark this tdf block as visited. + tdfBlock.setIsTimestepPropagated(); SysCAMSTPortTDF p1_tdfPort, p2_tdfPort; for(SysCAMSTPortTDF tdfPort : tdfBlock.getPortTDF()) { tp = tdfPort.getPeriod(); @@ -923,7 +924,6 @@ public class JDialogSysCAMSExecutableCodeGeneration extends javax.swing.JFrame i //validate timestep consistency (rate*tp == tm) if(rate*tp != tm){ jta.append("Error: In block \""+tdfBlock.getName()+ "\" Timestep Tm is inconsistent with timestep Tp of port \"" + tdfPort.getName()+"\".\n"); - //System.out.println("Error in propagateTM: Tm inconsistent with Tp of port: " + tdfPort.getName()); return false; } } else { @@ -946,9 +946,14 @@ public class JDialogSysCAMSExecutableCodeGeneration extends javax.swing.JFrame i if(p2_tdfPort.getPeriod() != tp) { jta.append("Error: In block \""+tdfBlock.getName()+"\" Timestep Tp of port \"" +tdfPort.getName() + "\" is inconsistent with timestep Tp of port \"" + p2_tdfPort.getName()+"\" from block \""+p2_tdfPort.getBlockTDF().getName()+"\".\n"); - //System.out.println("Error in propagateTM: Tp inconsistent with Tp of ports " + tdfPort.getName() + " and " + p2_tdfPort.getName()); return false; } + //if connected block was not visited yet, then propagate timestep + if(!p2_tdfPort.getBlockTDF().getIsTimestepPropagated()) { + if(!propagateTpTdf(p2_tdfPort.getBlockTDF(), p2_tdfPort, connectors)) { + return false; + } + } } } else if(p2_tdfPort.getName().equals(tdfPort.getName()) && p2_tdfPort.getBlockTDF().getName().equals(tdfBlock.getName())) { if(p1_tdfPort.getPeriod() <= 0) { @@ -961,9 +966,14 @@ public class JDialogSysCAMSExecutableCodeGeneration extends javax.swing.JFrame i if(p1_tdfPort.getPeriod() != tp) { jta.append("Error: In block \""+tdfBlock.getName()+"\" Timestep Tp of port \"" +tdfPort.getName() + "\" is inconsistent with timestep Tp of port \"" + p1_tdfPort.getName()+"\" from block \""+p1_tdfPort.getBlockTDF().getName()+"\".\n"); - //System.out.println("Error in propagateTM: Tp inconsistent with Tp of ports " + tdfPort.getName() + " and " + p1_tdfPort.getName()); return false; } + //if connected block was not visited yet, then propagate timestep + if(!p1_tdfPort.getBlockTDF().getIsTimestepPropagated()) { + if(!propagateTpTdf(p1_tdfPort.getBlockTDF(), p1_tdfPort, connectors)) { + return false; + } + } } } } @@ -977,7 +987,6 @@ public class JDialogSysCAMSExecutableCodeGeneration extends javax.swing.JFrame i //validate timestep consistency (rate*tp == tm) if(rate*tp != tm){ jta.append("Error: In block \""+tdfBlock.getName()+ "\" Timestep Tm is inconsistent with timestep Tp of port \"" + converterPort.getName()+"\".\n"); - //System.out.println("Error in propagateTM: Tm inconsistent with Tp of port: " + converterPort.getName()); return false; } } else { @@ -1003,7 +1012,6 @@ public class JDialogSysCAMSExecutableCodeGeneration extends javax.swing.JFrame i if(tm > 0) { if(rate*tp != tm) { jta.append("Error: In block \""+tdfBlock.getName()+ "\" Timestep Tm is inconsistent with timestep Tp of port \"" + tdfPort.getName()+"\".\n"); - //System.out.println("Error in propagateTpTdf: Tm inconsistent with Tp of port " + tdfPort.getName()); return false; } } else { @@ -1021,7 +1029,6 @@ public class JDialogSysCAMSExecutableCodeGeneration extends javax.swing.JFrame i if(tm > 0) { if(rate*tp != tm) { jta.append("Error: In block \""+tdfBlock.getName()+ "\" Timestep Tm is inconsistent with timestep Tp of port \"" + converterPort.getName()+"\".\n"); - //System.out.println("Error in propagateTpConverter: Tm inconsistent with Tp of port " + converterPort.getName()); return false; } } else { @@ -1085,15 +1092,16 @@ public class JDialogSysCAMSExecutableCodeGeneration extends javax.swing.JFrame i double[] resultArray = new double[kernelMatrix.getRowDimension()]; double result_tmp = 0.0; int v_lcm = 1; - Fraction[] resultFractionArray = new Fraction[kernelMatrix.getRowDimension()]; + BigFraction[] resultFractionArray = new BigFraction[kernelMatrix.getRowDimension()]; for (int i = 0; i < kernelMatrix.getRowDimension(); i++) { System.out.printf("The kernelMatrix is %f .\n", kernelMatrix.getEntry(i, 0) ); resultArray[i] = kernelMatrix.getEntry(i, 0) / kernelMatrix.getEntry(kernelMatrix.getRowDimension()-1, 0); result_tmp = kernelMatrix.getEntry(i, 0) / kernelMatrix.getEntry(kernelMatrix.getRowDimension()-1, 0); - resultFractionArray[i] = new Fraction(result_tmp); - System.out.println("The resultArray is: "+ resultArray[i] ); - System.out.println("The resultFractionArray is: "+ resultFractionArray[i].toString() ); - v_lcm = ArithmeticUtils.lcm(resultFractionArray[i].getDenominator() , v_lcm); + resultFractionArray[i] = new BigFraction(result_tmp, 2147483647); + System.out.println("The resultArray is: "+ resultArray[i] + ", result_tmp: " + result_tmp); + System.out.println("The resultFractionArray is: "+ resultFractionArray[i].toString() + " with num: " + resultFractionArray[i].getNumeratorAsInt() + " and denom: "+ resultFractionArray[i].getDenominatorAsInt() + + " and given as a double: " + resultFractionArray[i].doubleValue()); + v_lcm = ArithmeticUtils.lcm(resultFractionArray[i].getDenominatorAsInt() , v_lcm); System.out.println("The lcm is: "+ v_lcm ); } int[] tmpResult = new int[kernelMatrix.getRowDimension()]; @@ -1115,11 +1123,13 @@ public class JDialogSysCAMSExecutableCodeGeneration extends javax.swing.JFrame i boolean deadlock = false; boolean recompute = false; SysCAMSTBlockTDF tdfBlock; + LinkedList<SysCAMSTPortConverter> portConvertersTmp; + double[] time_prev = {0.0, 0.0}; //array to store "in" ([0]) and "out" ([1]) previous times //Reset the number of times all blocks have been executed for(int i = 0; i < tdfBlocks.size(); i++) { tdfBlocks.get(i).setN(0); } - double[] time_prev = {0.0, 0.0}; //array to store in[0] and out[1] previous times + try { while (!(q1.equals(q)) && !deadlock){ deadlock = true; -- GitLab