예제 #1
0
 public void pull(FrameBuffer frameBuffer) {
   frameBuffer.put(address64.array());
   frameBuffer.putInt8(options);
   if (packet != null) {
     frameBuffer.put(packet);
   }
 }
예제 #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);
 }
예제 #3
0
 private void addCRC() {
   if (crcMode) {
     crc16.reset(0);
     for (int i = 0; i < XBlock.DATA_SIZE; i++) {
       crc16.update(writeBuffer[3 + i]);
     }
     writeFrameBuffer.putInt16(crc16.getCRC());
   } else {
     int cs = 0;
     for (int i = 0; i < XBlock.DATA_SIZE; i++) {
       cs += writeBuffer[3 + i];
     }
     writeFrameBuffer.putInt8(cs);
   }
 }
예제 #4
0
 private void send() throws IOException {
   for (int i = 0; i < MAX_RETRY; i++) {
     System.out.println("Send #" + i);
     Commons.printDev(
         writeFrameBuffer.getRawArray(),
         writeFrameBuffer.getOffset(),
         writeFrameBuffer.getPosition(),
         false);
     os.write(
         writeFrameBuffer.getRawArray(),
         writeFrameBuffer.getOffset(),
         writeFrameBuffer.getPosition());
     os.flush();
     byte b = receive(true, 10000);
     if (b == CAN) {
       throw new IOException("Cancel");
     } else if (b == ACK) {
       return;
     }
   }
   throw new IOException("Timeout");
 }
예제 #5
0
 public XSendThread() {
   writeFrameBuffer.setByteOrder(FrameBuffer.BO_BIG_ENDIAN);
 }