⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 onewirecontainer16.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    * @see    #getLastError    * @see    #setErrorReportingMode    */   public ResponseAPDU getErrorReportingMode ()      throws OneWireException, OneWireIOException, IllegalArgumentException   {      capdu = new CommandAPDU(CLA, INS, ( byte ) 0x01, ( byte ) 0x09);      rapdu = sendAPDU(capdu, runTime);      return rapdu;   }   // getErrorReportingMode()   /**    * Sets the Error Reporting mode.    * If the error reporting mode is set (<code>1</code>), this Java iButton    * stores the last exception value code.  This code can be retreived by    * calling <code>getLastError()</code>.    *    *    * @param mode <code>1</code> to turn on  Error Reporting Mode.    *             <code>0</code> to turn off.    * @return <code>ResponseAPDU</code> indicating success or failure    *         <ul>    *         <li>Success SW 0x9000.    *         <li>Failure SW 0x6681. Invalid PIN.    *         <li>For additional error codes, please see:    *             <A HREF="http://www.ibutton.com/jibkit/documents/sw.html">    *                      http://www.ibutton.com/jibkit/documents/sw.html</A>    *         </ul>    *    * @throws IllegalArgumentException Invalid run time value    * @throws OneWireException         Part could not be found [ fatal ]    * @throws OneWireIOException       Data wasn't transferred properly [ recoverable ]    *    * @see    #getLastError    * @see    #getErrorReportingMode    */   public ResponseAPDU setErrorReportingMode (int mode)      throws OneWireException, OneWireIOException, IllegalArgumentException   {      byte[] data;      if (password != null)      {         data     = new byte [2 + password.length()];         data [0] = ( byte ) password.length();         System.arraycopy(password.getBytes(), 0, data, 1, password.length());         data [password.length() + 1] = ( byte ) mode;      }      else      {         data     = new byte [2];         data [0] = ( byte ) 0;         data [1] = ( byte ) mode;      }      capdu = new CommandAPDU(CLA, INS, ( byte ) 0x00, ( byte ) 0x09, data);      rapdu = sendAPDU(capdu, runTime);      return rapdu;   }   // setErrorReportingMode()   /**    * Gets the AID of the applet by its installed number. No PIN required.    *    * @param index installed number of the applet on this Java iButton to get    *              the AID of    *    * @return <code>ResponseAPDU</code> containing the AID of the applet    *         requested    *         <ul>    *         <li>Success SW 0x9000.    *         <li>Failure SW 0x8453.  Applet not found.    *             Valid applet index are in the range of <code>0-15</code>.    *         <li>For additional error codes, please see:    *             <A HREF="http://www.ibutton.com/jibkit/documents/sw.html">    *                      http://www.ibutton.com/jibkit/documents/sw.html</A>    *         </ul>    *    * @throws IllegalArgumentException Invalid run time value    * @throws OneWireException         Part could not be found [ fatal ]    * @throws OneWireIOException       Data wasn't transferred properly [ recoverable ]    */   public ResponseAPDU getAIDByNumber (int index)      throws OneWireException, OneWireIOException, IllegalArgumentException   {      byte[] data = new byte [1];      data [0] = ( byte ) (index & 0xFF);      capdu    = new CommandAPDU(CLA, INS, ( byte ) 0x01, ( byte ) 0x0E,                                 data);      rapdu    = sendAPDU(capdu, runTime);      if (rapdu.getSW() == 0x8453)   // applet not found         return rapdu;      // bug fix for Firmware 0.33      int i = rapdu.getData().length;      data = new byte [(i + 4)];      System.arraycopy(rapdu.getData(), 0, data, 0, i);      // return a "SUCCESS" ResponseAPDU      data [i]     = rapdu.getSW1();      data [i + 1] = rapdu.getSW2();      data [i + 2] = ( byte ) 0x90;      data [i + 3] = ( byte ) 0x00;      return (new ResponseAPDU(data));   }   // getAIDByNumber()   /**    * Deletes the currently selected applet.    * If PIN protection is enabled, a PIN must be supplied.    *    * @return <code>ResponseAPDU</code> indicating success or failure    *         <ul>    *         <li>Success SW 0x9000.    *         <li>Failure SW 0x6681. Invalid PIN.    *         <li>For additional error codes, please see:    *             <A HREF="http://www.ibutton.com/jibkit/documents/sw.html">    *                      http://www.ibutton.com/jibkit/documents/sw.html</A>    *         </ul>    *    * @throws IllegalArgumentException Invalid run time value    * @throws OneWireException         Part could not be found [ fatal ]    * @throws OneWireIOException       Data wasn't transferred properly [ recoverable ]    *    * @see    #deleteAppletByAID    * @see    #deleteAppletByNumber    */   public ResponseAPDU deleteSelectedApplet ()      throws OneWireException, OneWireIOException, IllegalArgumentException   {      byte[] data;      if (password != null)      {         data     = new byte [1 + password.length()];         data [0] = ( byte ) password.length();         System.arraycopy(password.getBytes(), 0, data, 1, password.length());      }      else      {         data     = new byte [2];         data [0] = ( byte ) 0;      }      capdu = new CommandAPDU(CLA, INS, ( byte ) 0x03, ( byte ) 0x00, data);      rapdu = sendAPDU(capdu, runTime);      return rapdu;   }   // deleteSelectedApplet()   /**    * Deletes an applet by its installed number.    *    * @param  index installed number of the applet to delete    *    * @return <code>ResponseAPDU</code> indicating success or failure    *         <ul>    *         <li>Success SW 0x9000.    *         <li>Failure SW 0x6681. Invalid PIN.    *         <li>Failure SW 0x8453. Applet not found.    *         <li>For additional error codes, please see:    *             <A HREF="http://www.ibutton.com/jibkit/documents/sw.html">    *                      http://www.ibutton.com/jibkit/documents/sw.html</A>    *         </ul>    *    * @throws IllegalArgumentException Invalid run time value    * @throws OneWireException         Part could not be found [ fatal ]    * @throws OneWireIOException       Data wasn't transferred properly [ recoverable ]    *    * @see    #deleteAppletByAID    * @see    #deleteSelectedApplet    */   public ResponseAPDU deleteAppletByNumber (int index)      throws OneWireException, OneWireIOException, IllegalArgumentException   {      byte[] data;      if (password != null)      {         data     = new byte [2 + password.length()];         data [0] = ( byte ) password.length();         System.arraycopy(password.getBytes(), 0, data, 1, password.length());         data [password.length() + 1] = ( byte ) index;      }      else      {         data     = new byte [2];         data [0] = ( byte ) 0;         data [1] = ( byte ) index;      }      capdu = new CommandAPDU(CLA, INS, ( byte ) 0x03, ( byte ) 0x01, data);      rapdu = sendAPDU(capdu, runTime);      return rapdu;   }   // deleleAppletByNumber()   /**    * Deletes an applet by its AID.    *    * @param  aid AID of applet to be deleted    *    * @return <code>ResponseAPDU</code> indicating success or failure    *         <ul>    *         <li>Success SW 0x9000.    *         <li>Failure SW 0x6681. Invalid PIN.    *         <li>Failure SW 0x8453. Applet not found.    *         <li>For additional error codes, please see:    *             <A HREF="http://www.ibutton.com/jibkit/documents/sw.html">    *                      http://www.ibutton.com/jibkit/documents/sw.html</A>    *         </ul>    *    * @throws IllegalArgumentException Invalid run time value    * @throws OneWireException         Part could not be found [ fatal ]    * @throws OneWireIOException       Data wasn't transferred properly [ recoverable ]    *    * @see    #deleteSelectedApplet    * @see    #deleteAppletByNumber    */   public ResponseAPDU deleteAppletByAID (String aid)      throws OneWireException, OneWireIOException, IllegalArgumentException   {      byte[] data;      if (password != null)      {         data     = new byte [2 + password.length() + aid.length()];         data [0] = ( byte ) password.length();         System.arraycopy(password.getBytes(), 0, data, 1, password.length());         data [password.length() + 1] = ( byte ) aid.length();         System.arraycopy(aid.getBytes(), 0, data, password.length() + 2,                          aid.length());      }      else      {         data     = new byte [2 + aid.length()];         data [0] = ( byte ) 0;         data [1] = ( byte ) aid.length();         System.arraycopy(aid.getBytes(), 0, data, 2, aid.length());      }      capdu = new CommandAPDU(CLA, INS, ( byte ) 0x03, ( byte ) 0x02, data);      rapdu = sendAPDU(capdu, runTime);      return rapdu;   }   // deleteAppletByAID()   /**    * Loads an applet onto this Java iButton.    * This method takes an input stream    * and an AID.  The AID length must NOT exceed <code>AID_SIZE</code>.    *    * @param  in Stream to read the applet from    * @param  aid AID of the applet to be loaded    *    * @return <code>ResponseAPDU</code> indicating success or failure    *         Possible return values are    *         <ul>    *         <li>Success SW 0x9000.    *         <li>Failure SW 0x6400. Insufficient Memory    *         <li>Failure SW 0x6901. Invalid AID Length    *         <li>Failure SW 0x6902. Invalid API Version    *         <li>Failure SW 0x6903. Invalid Password    *         <li>Failure SW 0x6904. Invalid Signature Length    *         <li>Failure SW 0x6905. Hash Corruption    *         <li>Failure SW 0x6906. Hash Failure    *         <li>Failure SW 0x6982. Invalid Signature    *         <li>Failure SW 0x6A84. Class Length Overrun    *         <li>Failure SW 0x6A86. Invalid Loader Command    *         <li>Failure SW 0x6A87. Invalid Packet    *         <li>For additional error codes, please see:    *             <A HREF="http://www.ibutton.com/jibkit/documents/sw.html">    *                      http://www.ibutton.com/jibkit/documents/sw.html</A>    *         </ul>    *    * @throws IOException              Problem reading applet from the stream    * @throws IllegalArgumentException Invalid run time value    * @throws OneWireException         Part could not be found [ fatal ]    * @throws OneWireIOException       Data wasn't transferred properly [ recoverable ]    *    * @see    #getLoadPINMode    * @see    #setLoadPINMode    */    public ResponseAPDU loadApplet (InputStream appletInputStream, String aid)        throws OneWireException, OneWireIOException, IllegalArgumentException, IOException    {        ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);        byte[] appletBuffer        = new byte[1024];        // Password FIX THIS TO HANDLE LOADING WITH A PASSWORD.        if (password != null)        {            appletBuffer [0] = ( byte ) password.length();            System.arraycopy(password.getBytes(), 0, appletBuffer, 1,                                password.length());        }        // append AID to appletBuffer        for (int offset = 0; offset < AID_SIZE; offset++)        {            if (offset < aid.length())                appletBuffer [offset + AID_NAME_OFFSET] = ( byte ) aid.charAt(( int ) offset);            else   // leave the rest in their default value (0)                break;        }        appletBuffer [AID_LENGTH_OFFSET] = ( byte ) aid.length(); //AID_SIZE;   // AID Length        //  now write the whole enchilada to the ByteArrayOutputStream        baos.write(appletBuffer,0,APPLET_FILE_HEADER_SIZE);        int amount = appletInputStream.read(appletBuffer);        while (amount != -1)        {            baos.write(appletBuffer,0,amount);            amount = appletInputStream.read(appletBuffer);        }        appletInputStream.close();        int          bytesSent   = 0;        boolean      firstPacket = true;        ResponseAPDU rapdu       = null;        byte[]       apduBuffer  = new byte [APDU_PACKET_LENGTH];        appletBuffer = baos.toByteArray();        int appletLength = appletBuffer.length - APPLET_FILE_HEADER_SIZE;        int totalLength = (appletLength + APPLET_FILE_HEADER_SIZE - APDU_PACKET_LENGTH);        if (jibComm.doDebugMessages)        {            System.out.println("TOTAL APPLET LENGTH: "+appletBuffer.length);        }        while (bytesSent < totalLength)        {            if (jibComm.doDebugMessages)            {                System.out.println("byteSent: "+bytesSent);            }            System.arraycopy(appletBuffer,bytesSent,apduBuffer,0,APDU_PACKET_LENGTH);            bytesSent += APDU_PACKET_LENGTH;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -