예제 #1
0
 public boolean openDevice(boolean simulate) {
   if (simulate) return true;
   boolean found = false;
   try {
     USBFlash.open();
     phoneident = new String(USBFlash.getLastReply());
     cmd = new Command(_bundle.simulate());
     cmd.send(Command.CMD01, Command.VALNULL, false);
     loaderident = new String(USBFlash.getLastReply());
     found = true;
   } catch (Exception e) {
     found = false;
   }
   return found;
 }
예제 #2
0
 private void uploadImage(InputStream fileinputstream, int buffer) throws X10FlashException {
   try {
     processHeader(fileinputstream);
     int readCount;
     do {
       if (buffer == 0x1000) readCount = fileinputstream.read(readarray4);
       else readCount = fileinputstream.read(readarray65);
       if (readCount > 0)
         if (buffer == 0x1000)
           cmd.send(
               Command.CMD06, BytesUtil.getReply(readarray4, readCount), (readCount == buffer));
         else
           cmd.send(
               Command.CMD06, BytesUtil.getReply(readarray65, readCount), (readCount == buffer));
       if (readCount != buffer) break;
     } while (true);
     fileinputstream.close();
     if (USBFlash.getLastFlags() == 0) getLastError();
   } catch (Exception e) {
     try {
       fileinputstream.close();
     } catch (Exception cl) {
     }
     throw new X10FlashException(e.getMessage());
   }
 }
예제 #3
0
 public void send(int cmd, byte data[], boolean ongoing) throws X10FlashException, IOException {
   writeCommand(cmd, data, ongoing);
   reply = USBFlash.getLastReply();
   if (USBFlash.getLastFlags() == 0) {
     writeCommand(Command.CMD07, Command.VALNULL, false);
     throw new X10FlashException(getLastReplyString());
   }
   while (isMultiPacketMessage()) {
     writeCommand(cmd, data, ongoing);
     reply = Bytes.concat(reply, USBFlash.getLastReply());
     if (USBFlash.getLastFlags() == 0) {
       writeCommand(Command.CMD07, Command.VALNULL, false);
       throw new X10FlashException(getLastReplyString());
     }
   }
   LogProgress.updateProgress();
 }
예제 #4
0
 private void writeCommand(int command, byte data[], boolean ongoing)
     throws X10FlashException, IOException {
   if (!_simulate) {
     if (MyLogger.curlevel.equals("debug")) {
       try {
         Thread.sleep(125);
       } catch (Exception e) {
       }
     }
     S1Packet p = new S1Packet(command, data, ongoing);
     try {
       USBFlash.writeS1(p, true);
     } catch (X10FlashException xe) {
       p.release();
       throw new X10FlashException(xe.getMessage());
     } catch (IOException ioe) {
       p.release();
       throw new IOException(ioe.getMessage());
     }
   }
 }
예제 #5
0
 private void processHeader(InputStream fileinputstream) throws X10FlashException {
   try {
     byte abyte0[] = new byte[6];
     int j = fileinputstream.read(abyte0);
     if (j != 6) {
       fileinputstream.close();
       throw new X10FlashException("Error in processHeader");
     }
     int k;
     byte abyte1[] = new byte[4];
     System.arraycopy(abyte0, 2, abyte1, 0, 4);
     k = BytesUtil.getInt(abyte1);
     abyte1 = new byte[k - 6];
     k = fileinputstream.read(abyte1);
     if (k != abyte1.length) {
       fileinputstream.close();
       throw new X10FlashException("Error in processHeader");
     }
     cmd.send(Command.CMD05, BytesUtil.concatAll(abyte0, abyte1), false);
     if (USBFlash.getLastFlags() == 0) getLastError();
   } catch (IOException ioe) {
     throw new X10FlashException("Error in processHeader : " + ioe.getMessage());
   }
 }
예제 #6
0
 public boolean isMultiPacketMessage() {
   return (USBFlash.getLastFlags() & 4) > 0;
 }
예제 #7
0
 public void closeDevice() {
   USBFlash.close();
 }