SAMsg in = new SAMsg();
SAMsg result = new SAMsg();
int enq = is.read();
System.out.print("<-- " + toHexString(enq));
if (enq != SAMsg.ENQ)
throw new TaskException(State.DONE_ERR, "Incorrect the first signal from host");
q.sendTo(s.getOutputStream());
System.out.print("\n-->");
q.printTo(System.out);
System.out.println();
String v;
for (String n : prmi.getFieldNames()) {
v = prmi.getField(n);
System.out.println(n + " = " + v);
}
int ch;
PrmInterface inpi = in.getPrmInterface();
CloseableOutputStream osc = in.getOutputStream();
System.out.print("\n<--");
boolean end = false;
while (!end && (ch = is.read()) != -1) {
System.out.print(" ");
System.out.print(toHexString(ch));
osc.write(ch);
if (osc.isClosed()) {
switch(Integer.parseInt(inpi.getField("type"))) {
case SAMsg.STX:
System.out.println();
PrmInterface rpi = result.getPrmInterface();
for (String n : inpi.getFieldNames()) {
v = inpi.getField(n);
rpi.setField(n, v);
System.out.println(n + " = " + v);
}
end = true;
break;
case SAMsg.ACK:
System.out.print("\n<--");
break;
case SAMsg.ENQ:
System.out.print("\n<--");
break;
default:
System.out.print("\n<--");
throw new TaskException(State.DONE_ERR, "Incorrect response from host");
}
in.reset();
osc = in.getOutputStream();
}
}
os.write(SAMsg.ACK);
System.out.print("\n--> " + toHexString(SAMsg.ACK));
os.write(SAMsg.EOT);
System.out.println("\n--> " + toHexString(SAMsg.EOT));
PrmInterface rpi = result.getPrmInterface();
StringList flds = rpi.getFieldNames();
for (String fld : flds) {
cntx.setPrmByFullName(msg_grp_out + "/" + fld, rpi.getField(fld), false);
}
} catch (UnknownHostException e) {
throw new TaskException(State.DONE_ERR, e);
} catch (IOException e) {
throw new TaskException(State.DONE_ERR, e);
} finally {
ru.vassaev.core.util.Sockets.close(s);
}
return State.DONE_OK;
}