/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package mxgstest.egse; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.List; import mxgsegse.MXGSEGSE; /** * * @author stet */ public class Dausim { public static BufferedReader bwin; public static BufferedWriter bw; public static Process telnetDausim; public void telnet_dausim() throws IOException, InterruptedException { ProcessBuilder pb = new ProcessBuilder("/usr/bin/expect"); telnetDausim = pb.start(); bwin = new BufferedReader(new InputStreamReader(telnetDausim.getInputStream())); bw = new BufferedWriter(new OutputStreamWriter(telnetDausim.getOutputStream())); bw.write("spawn telnet 192.168.1.11"); bw.newLine(); bw.write("expect \"login:\""); bw.newLine(); bw.write("send \"root\\r\""); bw.newLine(); bw.write("expect \"Password:\""); bw.newLine(); bw.write("send \"root\\r\""); bw.newLine(); bw.write("expect \"#\""); bw.newLine(); bw.write("send \"echo Telnet to Dausim opened\\r\""); bw.newLine(); bw.write("expect \"#\""); bw.newLine(); bw.flush(); Thread.sleep(2000); String readFir = ""; try { while (!readFir.equals("Telnet to Dausim opened")) { readFir=bwin.readLine(); if(!readFir.substring(0, Math.min(8,readFir.length())).equals("~ # echo")) { System.out.println(readFir); } } } catch (IOException e) { System.err.println("Error: " + e); } } public void dausimCmd(List cmdList) throws IOException, InterruptedException { for (String item : cmdList) { bw.write("send \""+item+" \\r\""); bw.newLine(); bw.write("expect \"#\""); bw.newLine(); } bw.write("send \"echo fchEnd\\r\""); bw.newLine(); bw.write("expect \"#\""); bw.newLine(); bw.flush(); String readFir = ""; try { while (!readFir.equals("fchEnd")) { readFir=bwin.readLine(); if(!readFir.substring(0, Math.min(8,readFir.length())).equals("~ # echo")) { System.out.println(readFir); } } } catch (IOException e) { System.err.println("Error: " + e); } } public String dausimPeek(String address) throws IOException, InterruptedException { bw.write("send \"peek "+address+" \\r\""); bw.newLine(); bw.write("expect \"#\""); bw.newLine(); bw.write("send \"echo fchEnd\\r\""); bw.newLine(); bw.write("expect \"#\""); bw.newLine(); bw.flush(); String readFir = ""; String out=""; try { while (!readFir.equals("fchEnd")) { readFir=bwin.readLine(); if(readFir.substring(0,2).equals("0x")) { out=readFir; } if(!readFir.substring(0, Math.min(8,readFir.length())).equals("~ # echo")) { System.out.println(readFir); } } } catch (IOException e) { System.err.println("Error: " + e); } return out; } public void dausimfullCmd(String testDir) throws IOException, InterruptedException { bw.write("send \"killall dausimfull\\r\""); bw.newLine(); bw.write("expect -re stopped|killed"); bw.newLine(); bw.flush(); bw.write("send \"\\r\""); bw.newLine(); bw.write("expect \"#\""); bw.newLine(); bw.write("set timeout 120"); bw.newLine(); bw.write("send \"dausimfull -l /dev/shm/Dausim/logs/ -r /dev/remserial1 -s /mnt/nfs/Settings/"+testDir+"/ &\\r\""); bw.newLine(); bw.write("expect \"HW started!\""); bw.newLine(); // bw.write("set timeout 10"); bw.newLine(); bw.flush(); bw.write("send \"\\r\""); bw.newLine(); bw.write("expect \"#\""); bw.newLine(); bw.flush(); bw.write("send \"echo fchEnd\\r\""); bw.newLine(); bw.write("expect \"#\""); bw.newLine(); bw.flush(); String readFir = ""; try { while (!readFir.equals("fchEnd")) { // while (!readFir.equals("HW started!")) { readFir=bwin.readLine(); if(!readFir.substring(0, Math.min(8,readFir.length())).equals("~ # echo")) { System.out.println(readFir); } } } catch (IOException e) { System.err.println("Error: " + e); } } public void enableDaus(MXGSEGSE egse,String Daus) throws Exception { egse.dausim.tcp.stop(); Thread.sleep(100); egse.dausim.dau.stop(); Thread.sleep(100); egse.dausim.reset(); Thread.sleep(500); String binDaus = Integer.toString(Integer.valueOf(Daus,16),2); binDaus=("00000000" + binDaus).substring(binDaus.length()); for(int i=0; i