📄 swinterpreter.java
字号:
/*--------------------------------------------------------------------------- * Copyright (C) 1999,2000 Dallas Semiconductor Corporation, All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * Except as contained in this notice, the name of Dallas Semiconductor * shall not be used except as stated in the Dallas Semiconductor * Branding Policy. *--------------------------------------------------------------------------- */package com.dalsemi.onewire.jib;/** * <p>This class is intended to help developers translate from status words * returned by a Java Powered iButton into a meaningful message. Normal * program execution with the Java Powered iButton is performed using * APDU classes and OneWireContainer16, and looks something like this: * <pre><code> * //CommandAPDU capdu already defined * ResponseAPDU response; * response = owc16.sendAPDU(capdu); * int statusword = response.getSW(); * //use the SWInterpreter class to print a message * System.out.println(SWInterpreter.interpret(statusword)); * </code></pre> * * This class allows you to use the <code>statusword</code> to print a message. If the status word returned * was 0x6400, indicating not enough memory, the above code would print the message: * <pre><code> * "SW 0x6400 Insufficient Memory" * </code></pre> * * @see com.dalsemi.onewire.container.OneWireContainer16 * * @version 0.00, 16 Mar 2001 * @author K */public class SWInterpreter{ /** * Returns an appropriate message for the status word argument. * this adapter object will find. This method knows messages * for the following status words: * <ul> * <li>SW 0x6100 Response Bytes Remaining * <li>SW 0x6301 Success Packet * <li>SW 0x6400 Insufficient Memory * <li>SW 0x6681 Bad Master PIN * <li>SW 0x6700 Wrong Length * <li>SW 0x6901 Invalid AID Length * <li>SW 0x6902 Invalid API Version * <li>SW 0x6903 Invalid Password * <li>SW 0x6904 Invalid Signature Length * <li>SW 0x6905 Hash Corruption * <li>SW 0x6906 Hash Failure * <li>SW 0x6982 Invalid Signature * <li>SW 0x6984 Data Invalid * <li>SW 0x6985 Conditions Of Use Not Satisfied * <li>SW 0x6A80 Wrong Data * <li>SW 0x6A81 Function Not Supported * <li>SW 0x6A82 Unable to Select Applet * <li>SW 0x6A84 Class Length Overrun * <li>SW 0x6A86 Invalid Loader Command * <li>SW 0x6A87 Incomplete Packet * <li>SW 0x6B00 Incorrect Parameters (P1,P2) * <li>SW 0x6C00 Correct Expected Length * <li>SW 0x6D00 INS Value Not Supported * <li>SW 0x6F00 Uncaught Exception * <li>SW 0x8450 Unable to Find Applet * <li>SW 0x8453 Unable to Select Applet * <li>SW 0x9000 Success * </ul> * If any other status word is passed to this method, the <code>String</code> * "Unrecognized SW" is returned. * * @param status word returned from the Java Powered iButton * * @return message suitable for display */ public static String interpret(int sw) { //mask 'sw' just incase someone sent us a short that didn't upcast well String swpart = "SW 0x"+Integer.toHexString(sw & 0x0ffff)+" "; String message = null; switch (sw & 0x0ffff) { case 0x6100: message = "Response Bytes Remaining"; break; case 0x6301: message = "Success Packet"; break; case 0x6400: message = "Insufficient Memory"; break; case 0x6681: message = "Bad Master PIN"; break; case 0x6700: message = "Wrong Length"; break; case 0x6901: message = "Invalid AID Length"; break; case 0x6902: message = "Invalid API Version"; break; case 0x6903: message = "Invalid Password"; break; case 0x6904: message = "Invalid Signature Length"; break; case 0x6905: message = "Hash Corruption"; break; case 0x6906: message = "Hash Failure"; break; case 0x6982: message = "Invalid Signature"; break; case 0x6984: message = "Data Invalid"; break; case 0x6985: message = "Conditions Of Use Not Satisfied"; break; case 0x6A80: message = "Wrong Data"; break; case 0x6A81: message = "Function Not Supported"; break; case 0x6A82: message = "Unable to Select Applet"; break; case 0x6A84: message = "Class Length Overrun"; break; case 0x6A86: message = "Invalid Loader Command"; break; case 0x6A87: message = "Incomplete Packet"; break; case 0x6B00: message = "Incorrect Parameters (P1,P2)"; break; case 0x6C00: message = "Correct Expected Length"; break; case 0x6D00: message = "INS Value Not Supported"; break; case 0x6F00: message = "Uncaught Exception"; break; case 0x8450: message = "Unable to Find Applet"; break; case 0x8453: message = "Unable to Select Applet"; break; case 0x9000: message = "Success"; break; default: message = "Unrecognized SW"; break; } //end switch return swpart + message; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -