@Override protected void internal_receive(String line) throws MyException { int rs = 0; if (line.length() >= 2 && line.substring(0, 2).equals("ok")) { receiveCount++; if (receiveCount > cmdHistroy.size()) { throw new MyException("More OK than send commands!"); } Communication.class.notify(); } // "start" line after reset if (line.length() >= 5 && line.substring(0, 5).equals("start")) { if (!initThread.isAlive()) { throw new MyException("Controler reset detected!"); } } // resend? if (line.length() >= 2 && line.substring(0, 2).equals("rs")) { rs = Integer.parseInt(line.substring(3)); } if (line.length() >= 7 && line.substring(0, 7).equals("Resend:")) { receiveCount--; // Marlin ok will be comming anyway :-( try { rs = Integer.parseInt(line.substring(7).trim()); } catch (Exception ex) { throw new MyException("Resend string error! (" + ex.getMessage() + ")"); } if (rs < cmdHistroy.size() - 1) { throw new MyException("Resending old command!"); } } if (rs > 0) { if (rs != 1) { resend(rs); } else { throw new MyException("Resend 1! Controller reset?!"); } } }
@Override protected void internal_send(String command) throws MyException { cmdHistroy.add(command); resend(cmdHistroy.size()); }