1,4 → 1,4 |
package first_filter; |
//package first_filter; |
|
import java.io.*; |
import java.net.*; |
9,6 → 9,8 |
import org.jdom.input.SAXBuilder; |
import org.jdom.output.XMLOutputter; |
import java.util.regex.*; |
import java.util.random; |
|
/** |
* <p>Title: First XML filter</p> |
* <p>Description: </p> |
205,7 → 207,7 |
} else if (t.getValue().equals("OneShot")) { |
process_oneshot_task(e, out); |
task_type=21; |
} else if (t.getValue().equals("PeriodicTask")) { |
} else if (t.getValue().equals("CyclicalTask")) { |
String[] dline=pattern.split(e.getChild("dline").getText()); |
task_type=22; |
time.tv_sec = Long.valueOf(dline[0]).longValue(); |
245,11 → 247,15 |
void process_back_task(Element e, OutputStreamWriter out) { |
|
Pattern pattern = Pattern.compile("[us\\s]+"); |
String[] start_time=pattern.split(e.getChild("start_time").getText()); |
String[] wcet=pattern.split(e.getChild("wcet").getText()); |
|
Element act_section=e.getChild("act_section"); |
String[] start_time=pattern.split(act_section.getChild("start_time").getText()); |
Element exec_section=e.getChild("exec_section"); |
|
String[] exec_const=pattern.split(exec_section.getChild("exec_const").getText()); |
try { |
out.write("struct timespec act_task"+task_group+"[]={{"+start_time[0]+","+start_time[1]+"},};\n\n"); |
out.write("struct timespec exec_task"+task_group+"[]={{"+wcet[0]+","+wcet[1]+"},};\n\n"); |
out.write("struct timespec exec_task"+task_group+"[]={{"+exec_const[0]+","+exec_const[1]+"},};\n\n"); |
|
} |
catch (java.io.IOException ex) { |
258,13 → 264,17 |
} |
} |
void process_oneshot_task(Element e, OutputStreamWriter out) { |
int number=Integer.parseInt(e.getChild("number").getText()); |
Pattern pattern = Pattern.compile("[us\\s]+"); |
String[] start_time=pattern.split(e.getChild("start_time").getText()); |
String[] wcet=pattern.split(e.getChild("wcet").getText()); |
|
Element act_section=e.getChild("act_section"); |
String[] start_time=pattern.split(act_section.getChild("start_time").getText()); |
|
Element exec_section=e.getChild("exec_section"); |
String[] exec_const=pattern.split(exec_section.getChild("exec_const").getText()); |
|
try { |
out.write("struct timespec act_task"+task_group+"[]={{"+start_time[0]+","+start_time[1]+"},};\n\n"); |
out.write("struct timespec exec_task"+task_group+"[]={{"+wcet[0]+","+wcet[1]+"},};\n\n"); |
out.write("struct timespec exec_task"+task_group+"[]={{"+exec_const[0]+","+exec_const[1]+"},};\n\n"); |
} |
catch (java.io.IOException ex) { |
System.out.println("File Exception: " + ex.getMessage()); |
271,13 → 281,41 |
} |
} |
|
int process_periodic_task(Element e, OutputStreamWriter out) { |
int number=Integer.parseInt(e.getChild("number").getText()); |
int process_cyclical_task(Element e, OutputStreamWriter out) { |
|
int activated=1; |
Pattern pattern = Pattern.compile("[us\\s]+"); |
String[] start_time=pattern.split(e.getChild("start_time").getText()); |
String[] wcet=pattern.split(e.getChild("wcet").getText()); |
String[] period=pattern.split(e.getChild("mit").getText()); |
Element act_section=e.getChild("act_section"); |
String[] start_time=pattern.split(act_section.getChild("start_time").getText()); |
String[] period=pattern.split(act_section.getChild("period_time").getText()); |
Element deltatime=act_section.getChild("delta_time"); |
String[] delta_time; |
|
long act_delta=0; |
timespec delta_act_ts = new timespec(); |
|
if (deltatime.exists()) { |
delta_time = pattern.split(deltatime.getText()); |
delta_act_ts.tv_sec = Long.valueOf(delta_time[0]).longValue(); |
delta_act_ts.tv_nsec = Long.valueOf(delta_time[1]).longValue() / 1000; |
act_delta = delta_act_ts.TIMESPEC2USEC(); |
} |
|
Element exec_section=e.getChild("exec_section"); |
String[] exec_const=pattern.split(exec_section.getChild("exec_const").getText()); |
Element execdelta=exec_section.getChild("exec_delta"); |
String[] exec_delta; |
|
long exec_delta_long = 0; |
timespec delta_act_ts = new timespec(); |
|
if (execdelta.exists()) { |
exec_delta=pattern.split(execdelta.getText()); |
exec_act_ts.tv_sec = Long.valueOf(exec_delta[0]).longValue(); |
exec_act_ts.tv_nsec = Long.valueOf(exec_delta[1]).longValue() / 1000; |
exec_delta_long = exec_act_ts.TIMESPEC2USEC(); |
} |
|
try { |
out.write("struct timespec act_task"+task_group+"[]={{"+ |
start_time[0]+","+start_time[1]+"},\n"); |
286,25 → 324,40 |
time.tv_sec = Long.valueOf(period[0]).longValue(); |
time.tv_nsec = Long.valueOf(period[1]).longValue() / 1000; |
|
long mit = time.TIMESPEC2USEC(); |
long usecperiod = time.TIMESPEC2USEC(); |
timespec nextact = new timespec(); |
|
time.tv_sec = Long.valueOf(start_time[0]).longValue(); |
time.tv_nsec = Long.valueOf(start_time[1]).longValue() / 1000; |
|
Random rd = new Random(); |
|
while (simulation_time.TIMESPEC_A_GT_B(time)) { |
time.ADDUSEC2TIMESPEC(mit); |
out.write(" {"+period[0]+","+period[1]+"},\n"); |
|
nextact.tv_sec = Long.valueOf(period[0]).longValue(); |
nextact.tv_nsec = Long.valueOf(period[1]).longValue() / 1000; |
|
nextact.ADDUSEC2TIMESPEC((rd.nextInt() & Integer.MAX_INT) % act_delta - act_delta/2); |
|
time.ADDUSEC2TIMESPEC(usecperiod); |
out.write(" {"+nextact.tv_sec+","+nextact.tv_nsec/1000+"},\n"); |
activated++; |
// fprintf(file_act_header, " {%d,%d},\n", |
// (int) c - > act_par_2.tv_sec, (int) c - > act_par_2.tv_nsec); |
} |
out.write("};\n"); |
|
out.write("struct timespec exec_task"+task_group+"[]={{"+ |
wcet[0]+","+wcet[1]+"},\n"); |
out.write("struct timespec exec_task"+task_group+"[]={\n"); |
|
for (int i=1; i<activated; i++) { |
out.write(" {"+wcet[0]+","+wcet[1]+"},\n"); |
timespec nextexec = new timespec(); |
|
for (int i=0; i<activated; i++) { |
|
nextexec.tv_sec = Long.valueOf(exec_const[0]).longValue(); |
nextexec.tv_nsec = Long.valueOf(exec_const[1]).longValue() / 1000; |
|
nextexec.ADDUSEC2TIMESPEC((rd.nextInt() & Integer.MAX_INT) % exec_delta_long - exec_delta_long/2); |
|
out.write(" {"+nextexec.tv_sec+","+nextexec.tv_nsec/1000+"},\n"); |
|
} |
out.write("};\n"); |
} |