Ejemplo n.º 1
0
 public void pull(FrameBuffer frameBuffer) {
   frameBuffer.put(address64.array());
   frameBuffer.putInt8(options);
   if (packet != null) {
     frameBuffer.put(packet);
   }
 }
Ejemplo n.º 2
0
 public void run() {
   try {
     System.out.println("XModem Send Transcation Start...");
     byte b = receive(false, 60000);
     if (b == CAN) {
       System.out.println("Cancel!!");
       return;
     } else if (b == -1) {
       System.out.println("60sec Timeout!");
       return;
     }
     if (b == C) {
       System.out.println("XModem/CRC Detect");
       crcMode = true;
       crc16 = new CRC16CCITT(false);
     } else if (b == NAK) {
       System.out.println("XModem/Checsum Detect");
       crcMode = false;
     }
     System.out.println("Begin...");
     for (int block = 0; block < getBlockLength(); block++) {
       System.out.println("Fill Block #" + block);
       updateCurrentBlock(block);
       // Fill block
       XBlock xblock = new XBlock();
       xblock.setSequence((byte) (block + 1));
       int blockLen = XBlock.DATA_SIZE;
       if (rawDataBuffer.getRemaining() < XBlock.DATA_SIZE) {
         blockLen = rawDataBuffer.getRemaining();
       }
       byte[] rawBlock = new byte[blockLen];
       rawDataBuffer.get(rawBlock);
       xblock.setData(rawBlock);
       // Fill Buffer
       writeFrameBuffer.rewind();
       writeFrameBuffer.put(SOH);
       xblock.pull(writeFrameBuffer);
       addCRC();
       // Send Buffer
       send();
     }
     System.out.println("End Stream");
     writeFrameBuffer.rewind();
     writeFrameBuffer.put(EOT);
     send();
     System.out.println("Transaction Done.");
   } catch (IOException ex) {
     ex.printStackTrace();
   }
   try {
     Thread.sleep(1000);
     int a = is.available();
     System.out.println("AVL: " + a);
     is.read(readBuffer, 0, a);
     System.out.println(new String(readBuffer, 0, a));
   } catch (Exception ex) {
   }
   setReady(true);
 }