├── app ├── .gitignore ├── libs │ └── serialport-release.aar ├── src │ ├── main │ │ ├── res │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── layout │ │ │ │ └── activity_main.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ └── drawable │ │ │ │ └── ic_launcher_background.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── apacherio │ │ │ └── jondy │ │ │ └── annotationdemo │ │ │ ├── BanknotesProtocol.java │ │ │ ├── BaseProtocol.java │ │ │ ├── MainActivity.java │ │ │ └── BanknotesApi.java │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── apacherio │ │ │ └── jondy │ │ │ └── annotationdemo │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── apacherio │ │ └── jondy │ │ └── annotationdemo │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── bind-api ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ └── values │ │ │ │ └── strings.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── ljw │ │ │ └── bind_api │ │ │ ├── LJWProtocol.java │ │ │ ├── ProtocolBean.java │ │ │ └── RioBinder.java │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── apacherio │ │ │ └── jondy │ │ │ └── bind_api │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── apacherio │ │ └── jondy │ │ └── bind_api │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── okserialport ├── consumer-rules.pro ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ └── values │ │ │ │ └── strings.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── ljw │ │ │ └── okserialport │ │ │ └── serialport │ │ │ ├── utils │ │ │ ├── ApiExceptionCode.java │ │ │ ├── OkSerialPortLog.java │ │ │ ├── FlowManager.java │ │ │ ├── IQueue.java │ │ │ ├── BaseSerialPortException.java │ │ │ ├── ReadType.java │ │ │ ├── ServiceType.java │ │ │ ├── ApiException.java │ │ │ ├── ReadMessage.java │ │ │ ├── Priority.java │ │ │ ├── AbstractBlockingQueue.java │ │ │ ├── BaseQueue.java │ │ │ ├── CheckUtil.java │ │ │ ├── AbstractTaskQueue.java │ │ │ ├── CmdPack.java │ │ │ ├── OrderAssembleUtil.java │ │ │ ├── CRC16Utils.java │ │ │ ├── CmdTask.java │ │ │ ├── ResultDataParseUtils.java │ │ │ └── ByteUtil.java │ │ │ ├── callback │ │ │ ├── SendResultCallback.java │ │ │ ├── DataPackCallback.java │ │ │ ├── SerialReadCallback.java │ │ │ ├── AsyncDataCallback.java │ │ │ ├── BaseDataCallback.java │ │ │ ├── CommonCallback.java │ │ │ └── SerialportConnectCallback.java │ │ │ ├── bean │ │ │ ├── ProtocolBean.java │ │ │ ├── DataPack.java │ │ │ ├── CmdBean.java │ │ │ ├── BanknotesHeartBeatEntity.java │ │ │ └── SerialPortParams.java │ │ │ ├── core │ │ │ ├── OkSerialPort_ProtocolManager.java │ │ │ ├── OkSerialport.java │ │ │ └── SerialPortSingletonMgr.java │ │ │ └── proxy │ │ │ ├── SyncServicesProxy.java │ │ │ ├── SerialReadThread.java │ │ │ └── AsyncServicesProxy.java │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── ljw │ │ │ └── okserialport │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── ljw │ │ └── okserialport │ │ └── ExampleInstrumentedTest.java ├── libs │ └── serialport-release.aar ├── proguard-rules.pro └── build.gradle ├── bind-annotation ├── .gitignore ├── build.gradle └── src │ └── main │ └── java │ └── com │ └── ljw │ └── protocol │ └── Protocol.java ├── bind-compiler ├── .gitignore ├── build.gradle └── src │ └── main │ └── java │ └── com │ └── ljw │ └── protocolcompiler │ └── ProtocolProcessor.java ├── serialport-release.aar ├── settings.gradle ├── .idea ├── caches │ ├── gradle_models.ser │ └── build_file_checksums.ser ├── vcs.xml ├── misc.xml ├── runConfigurations.xml ├── modules.xml ├── gradle.xml ├── inspectionProfiles │ └── Project_Default.xml └── codeStyles │ └── Project.xml ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── gradlew.bat ├── gradlew └── README.md /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /bind-api/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /okserialport/consumer-rules.pro: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /bind-annotation/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /bind-compiler/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /okserialport/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /serialport-release.aar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jarvie-cn/OkSerialPort/HEAD/serialport-release.aar -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':bind-annotation', ':bind-compiler', ':bind-api', ':okserialport' 2 | -------------------------------------------------------------------------------- /.idea/caches/gradle_models.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jarvie-cn/OkSerialPort/HEAD/.idea/caches/gradle_models.ser -------------------------------------------------------------------------------- /app/libs/serialport-release.aar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jarvie-cn/OkSerialPort/HEAD/app/libs/serialport-release.aar -------------------------------------------------------------------------------- /bind-api/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | bind-api 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jarvie-cn/OkSerialPort/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /.idea/caches/build_file_checksums.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jarvie-cn/OkSerialPort/HEAD/.idea/caches/build_file_checksums.ser -------------------------------------------------------------------------------- /okserialport/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | OkSerialPort 3 | 4 | -------------------------------------------------------------------------------- /okserialport/libs/serialport-release.aar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jarvie-cn/OkSerialPort/HEAD/okserialport/libs/serialport-release.aar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jarvie-cn/OkSerialPort/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jarvie-cn/OkSerialPort/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jarvie-cn/OkSerialPort/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jarvie-cn/OkSerialPort/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jarvie-cn/OkSerialPort/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jarvie-cn/OkSerialPort/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jarvie-cn/OkSerialPort/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /okserialport/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jarvie-cn/OkSerialPort/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jarvie-cn/OkSerialPort/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /bind-api/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jarvie-cn/OkSerialPort/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | AnnotationDemo 3 | 点击测试注解 4 | 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /bind-api/src/main/java/com/ljw/bind_api/LJWProtocol.java: -------------------------------------------------------------------------------- 1 | package com.ljw.bind_api; 2 | 3 | /** 4 | * Created by Administrator on 2018/2/11 0011. 5 | */ 6 | 7 | public interface LJWProtocol { 8 | public void bind(T t); 9 | } 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Feb 11 21:01:33 CST 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip 7 | -------------------------------------------------------------------------------- /okserialport/src/main/java/com/ljw/okserialport/serialport/utils/ApiExceptionCode.java: -------------------------------------------------------------------------------- 1 | package com.ljw.okserialport.serialport.utils; 2 | 3 | public interface ApiExceptionCode { 4 | String SERIAL_PORT_ERROR = "serial_port_error"; 5 | String SERIAL_PORT_READ_OUT_TIME_ERROR = "read_out_time_error"; 6 | 7 | } 8 | -------------------------------------------------------------------------------- /bind-annotation/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java-library' 2 | apply plugin: 'com.github.dcendents.android-maven' // 增加 3 | group='com.github.Jarvie-cn' 4 | dependencies { 5 | implementation fileTree(dir: 'libs', include: ['*.jar']) 6 | } 7 | 8 | sourceCompatibility = "1.7" 9 | targetCompatibility = "1.7" 10 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /okserialport/src/main/java/com/ljw/okserialport/serialport/callback/SendResultCallback.java: -------------------------------------------------------------------------------- 1 | package com.ljw.okserialport.serialport.callback; 2 | 3 | 4 | import com.ljw.okserialport.serialport.bean.DataPack; 5 | 6 | /** 7 | * @author : LJW 8 | * @date : 2019/11/23 9 | * @desc : 10 | */ 11 | public interface SendResultCallback extends CommonCallback{ 12 | } 13 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /okserialport/src/main/java/com/ljw/okserialport/serialport/callback/DataPackCallback.java: -------------------------------------------------------------------------------- 1 | package com.ljw.okserialport.serialport.callback; 2 | 3 | 4 | import com.ljw.okserialport.serialport.bean.DataPack; 5 | 6 | /** 7 | * @author : LJW 8 | * @date : 2019/11/22 9 | * @desc : 10 | */ 11 | public interface DataPackCallback { 12 | void setDataPack(DataPack dataPack); 13 | } 14 | -------------------------------------------------------------------------------- /okserialport/src/main/java/com/ljw/okserialport/serialport/callback/SerialReadCallback.java: -------------------------------------------------------------------------------- 1 | package com.ljw.okserialport.serialport.callback; 2 | 3 | 4 | import com.ljw.okserialport.serialport.utils.ReadMessage; 5 | 6 | /** 7 | * @author : LJW 8 | * @date : 2019/11/22 9 | * @desc : 10 | */ 11 | public interface SerialReadCallback { 12 | void onReadMessage(ReadMessage readMessage); 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /okserialport/src/main/java/com/ljw/okserialport/serialport/callback/AsyncDataCallback.java: -------------------------------------------------------------------------------- 1 | package com.ljw.okserialport.serialport.callback; 2 | 3 | 4 | import com.ljw.okserialport.serialport.bean.DataPack; 5 | 6 | /** 7 | * @author : LJW 8 | * @date : 2019/11/22 9 | * @desc : 10 | */ 11 | public interface AsyncDataCallback extends BaseDataCallback { 12 | 13 | 14 | /** 15 | * 主动收到回调(比如心跳包回调) 16 | */ 17 | void onActivelyReceivedCommand(DataPack dataPack); 18 | } 19 | -------------------------------------------------------------------------------- /okserialport/src/main/java/com/ljw/okserialport/serialport/callback/BaseDataCallback.java: -------------------------------------------------------------------------------- 1 | package com.ljw.okserialport.serialport.callback; 2 | 3 | /** 4 | * @author : LJW 5 | * @date : 2019/11/22 6 | * @desc : 7 | */ 8 | public interface BaseDataCallback { 9 | /** 10 | * 校验数据包 11 | * 12 | * @param received 接收数据 13 | * @param size 数据大小 14 | * @return 返回整理好的数据包 15 | */ 16 | boolean checkData(byte[] received, int size, DataPackCallback dataPackCallback); 17 | } 18 | -------------------------------------------------------------------------------- /bind-compiler/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java-library' 2 | apply plugin: 'com.github.dcendents.android-maven' // 增加 3 | group='com.github.Jarvie-cn' 4 | dependencies { 5 | implementation fileTree(include: ['*.jar'], dir: 'libs') 6 | implementation project(':bind-annotation') 7 | implementation 'com.google.auto.service:auto-service:1.0-rc2' 8 | 9 | } 10 | tasks.withType(JavaCompile) { 11 | options.encoding = "UTF-8" 12 | } 13 | 14 | sourceCompatibility = "1.7" 15 | targetCompatibility = "1.7" 16 | -------------------------------------------------------------------------------- /okserialport/src/test/java/com/ljw/okserialport/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.ljw.okserialport; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /okserialport/src/main/java/com/ljw/okserialport/serialport/callback/CommonCallback.java: -------------------------------------------------------------------------------- 1 | package com.ljw.okserialport.serialport.callback; 2 | 3 | 4 | import com.ljw.okserialport.serialport.utils.BaseSerialPortException; 5 | import com.ljw.okserialport.serialport.utils.CmdPack; 6 | 7 | /** 8 | * 接口回调 9 | * 10 | * @param 11 | */ 12 | public interface CommonCallback { 13 | void onStart(CmdPack cmdPack); 14 | 15 | void onSuccess(T t); 16 | 17 | void onFailed(BaseSerialPortException spException); 18 | } 19 | -------------------------------------------------------------------------------- /bind-api/src/test/java/com/apacherio/jondy/bind_api/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.apacherio.jondy.bind_api; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /app/src/test/java/com/apacherio/jondy/annotationdemo/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.apacherio.jondy.annotationdemo; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /okserialport/src/main/java/com/ljw/okserialport/serialport/utils/OkSerialPortLog.java: -------------------------------------------------------------------------------- 1 | package com.ljw.okserialport.serialport.utils; 2 | 3 | import android.util.Log; 4 | 5 | /** 6 | * @author : LJW 7 | * @date : 2019/12/29 8 | * @desc : 9 | */ 10 | public class OkSerialPortLog { 11 | 12 | public static boolean isDebug = false; 13 | 14 | public void setDebug(boolean debug) { 15 | isDebug = debug; 16 | } 17 | 18 | 19 | public static void e(String text){ 20 | if (isDebug) { 21 | Log.e("OkSerialport",text); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /okserialport/src/main/java/com/ljw/okserialport/serialport/callback/SerialportConnectCallback.java: -------------------------------------------------------------------------------- 1 | package com.ljw.okserialport.serialport.callback; 2 | 3 | 4 | import com.ljw.okserialport.serialport.bean.DataPack; 5 | import com.ljw.okserialport.serialport.utils.ApiException; 6 | 7 | /** 8 | * @author : LJW 9 | * @date : 2019/11/22 10 | * @desc :连接成功回调 11 | */ 12 | public interface SerialportConnectCallback { 13 | void onError(ApiException apiException); 14 | 15 | void onOpenSerialPortSuccess(); 16 | 17 | /**心跳上传回调*/ 18 | void onHeatDataCallback(DataPack dataPack); 19 | } 20 | -------------------------------------------------------------------------------- /okserialport/src/main/java/com/ljw/okserialport/serialport/utils/FlowManager.java: -------------------------------------------------------------------------------- 1 | package com.ljw.okserialport.serialport.utils; 2 | 3 | public class FlowManager { 4 | private int flowWater = 0; 5 | 6 | private static FlowManager flowManager = new FlowManager(); 7 | 8 | public static FlowManager get() { 9 | return flowManager; 10 | } 11 | 12 | public synchronized int getFlowWater() { 13 | if (flowWater >= 0xff) { 14 | flowWater = 0; 15 | } else { 16 | flowWater++; 17 | } 18 | return flowWater; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /bind-api/src/main/java/com/ljw/bind_api/ProtocolBean.java: -------------------------------------------------------------------------------- 1 | package com.ljw.bind_api; 2 | 3 | /** 4 | * @author : LJW 5 | * @date : 2019/12/27 6 | * @desc : 7 | */ 8 | public class ProtocolBean { 9 | /** 10 | * 位置 11 | * */ 12 | public int index; 13 | /** 14 | * 字节长度 15 | * */ 16 | public int length; 17 | 18 | /** 19 | * 字节长度 20 | * */ 21 | public byte value; 22 | 23 | public ProtocolBean(int index, int length, byte value) { 24 | this.index = index; 25 | this.length = length; 26 | this.value = value; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /okserialport/src/main/java/com/ljw/okserialport/serialport/utils/IQueue.java: -------------------------------------------------------------------------------- 1 | package com.ljw.okserialport.serialport.utils; 2 | 3 | /** 4 | * @author : LJW 5 | * @date : 2019/11/22 6 | * @desc : 7 | */ 8 | public interface IQueue extends Comparable { 9 | /** 10 | * 开始工作 11 | */ 12 | void runTask(); 13 | 14 | /** 15 | * 设置等级 16 | */ 17 | void setPriority(@Priority int priority); 18 | 19 | int getPriority(); 20 | 21 | /** 22 | * 一个序列标记 23 | */ 24 | void setSequence(int sequence); 25 | 26 | /** 27 | * 获取序列标记 28 | */ 29 | int getSequence(); 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /okserialport/src/main/java/com/ljw/okserialport/serialport/bean/ProtocolBean.java: -------------------------------------------------------------------------------- 1 | package com.ljw.okserialport.serialport.bean; 2 | 3 | /** 4 | * @author : LJW 5 | * @date : 2019/12/27 6 | * @desc : 7 | */ 8 | public class ProtocolBean { 9 | /** 10 | * 位置 11 | * */ 12 | public int index; 13 | /** 14 | * 字节长度 15 | * */ 16 | public int length; 17 | 18 | /** 19 | * 字节长度 20 | * */ 21 | public byte value; 22 | 23 | public ProtocolBean(int index, int length, byte value) { 24 | this.index = index; 25 | this.length = length; 26 | this.value = value; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /okserialport/src/main/java/com/ljw/okserialport/serialport/utils/BaseSerialPortException.java: -------------------------------------------------------------------------------- 1 | package com.ljw.okserialport.serialport.utils; 2 | 3 | public class BaseSerialPortException extends ApiException { 4 | /** 5 | * 目标地址 6 | */ 7 | private int address; 8 | 9 | public BaseSerialPortException(String code, String message, int address) { 10 | super(code, message); 11 | this.address = address; 12 | } 13 | 14 | public BaseSerialPortException(String code, Throwable message, int address) { 15 | super(code, message); 16 | this.address = address; 17 | } 18 | 19 | public int getAddress() { 20 | return address; 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /okserialport/src/main/java/com/ljw/okserialport/serialport/utils/ReadType.java: -------------------------------------------------------------------------------- 1 | package com.ljw.okserialport.serialport.utils; 2 | 3 | 4 | import android.support.annotation.IntDef; 5 | 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | 9 | import static com.ljw.okserialport.serialport.utils.ReadType.CheckSendData; 10 | import static com.ljw.okserialport.serialport.utils.ReadType.ReadDataSuccess; 11 | 12 | 13 | @IntDef({CheckSendData, ReadDataSuccess}) 14 | @Retention(RetentionPolicy.SOURCE) 15 | public @interface ReadType { 16 | /** 17 | * 检测发送数据包的回调 18 | */ 19 | int CheckSendData = 0; 20 | /** 21 | * 读取数据成功 22 | */ 23 | int ReadDataSuccess = 1; 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /bind-api/src/main/java/com/ljw/bind_api/RioBinder.java: -------------------------------------------------------------------------------- 1 | package com.ljw.bind_api; 2 | 3 | import android.app.Activity; 4 | 5 | /** 6 | * Created by Administrator on 2018/2/11 0011. 7 | */ 8 | 9 | public class RioBinder { 10 | private static final String SUFFIX ="$ViewBinder"; 11 | public static void bind(Activity target){ 12 | Class clazz = target.getClass(); 13 | String className =clazz.getName()+SUFFIX; 14 | try { 15 | Class binderClass = Class.forName("com.ljw.okserialport.LJWProtocolImp"); 16 | // ViewBinder rioBind = (ViewBinder) binderClass.newInstance(); 17 | // rioBind.bind(target); 18 | } catch (ClassNotFoundException e) { 19 | e.printStackTrace(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1024m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /okserialport/src/main/java/com/ljw/okserialport/serialport/utils/ServiceType.java: -------------------------------------------------------------------------------- 1 | package com.ljw.okserialport.serialport.utils; 2 | 3 | 4 | import android.support.annotation.IntDef; 5 | 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | 9 | import static com.ljw.okserialport.serialport.utils.ServiceType.AsyncServices; 10 | import static com.ljw.okserialport.serialport.utils.ServiceType.SyncServices; 11 | 12 | 13 | /** 14 | * @author : LJW 15 | * @date : 2019/11/22 16 | * @desc : 17 | */ 18 | @IntDef({SyncServices, AsyncServices}) 19 | @Retention(RetentionPolicy.SOURCE) 20 | public @interface ServiceType { 21 | /** 22 | * 同步服务,适用于485 23 | */ 24 | int SyncServices = 0; 25 | /** 26 | * 异步服务适用于485和232 27 | */ 28 | int AsyncServices = 1; 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /bind-api/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /okserialport/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /okserialport/src/main/java/com/ljw/okserialport/serialport/utils/ApiException.java: -------------------------------------------------------------------------------- 1 | package com.ljw.okserialport.serialport.utils; 2 | 3 | public class ApiException extends RuntimeException { 4 | /** 5 | * 用String,若是int转下就是 6 | */ 7 | private final String code; 8 | 9 | public ApiException(String code, String message) { 10 | super(message); 11 | this.code = code; 12 | } 13 | 14 | public ApiException(String code, Throwable message) { 15 | super(message); 16 | this.code = code; 17 | } 18 | 19 | /** 20 | * 异常码 21 | */ 22 | public String getCode() { 23 | return code; 24 | } 25 | 26 | @Override 27 | public String toString() { 28 | return "ApiException{" + 29 | "code='" + code + '\'' + ",message='" + getMessage() + '\'' + 30 | '}'; 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /okserialport/src/androidTest/java/com/ljw/okserialport/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.ljw.okserialport; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); 23 | 24 | assertEquals("com.ljw.okserialport.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /bind-api/src/androidTest/java/com/apacherio/jondy/bind_api/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.apacherio.jondy.bind_api; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.apacherio.jondy.bind_api.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/apacherio/jondy/annotationdemo/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.apacherio.jondy.annotationdemo; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.apacherio.jondy.annotationdemo", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 23 | -------------------------------------------------------------------------------- /bind-api/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 26 5 | 6 | 7 | 8 | defaultConfig { 9 | minSdkVersion 15 10 | targetSdkVersion 26 11 | versionCode 1 12 | versionName "1.0" 13 | 14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 15 | 16 | } 17 | 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | 25 | } 26 | 27 | dependencies { 28 | implementation fileTree(include: ['*.jar'], dir: 'libs') 29 | implementation 'com.android.support:appcompat-v7:26.1.0' 30 | testImplementation 'junit:junit:4.12' 31 | androidTestImplementation 'com.android.support.test:runner:1.0.1' 32 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 33 | implementation project(':bind-annotation') 34 | } 35 | -------------------------------------------------------------------------------- /app/src/main/java/com/apacherio/jondy/annotationdemo/BanknotesProtocol.java: -------------------------------------------------------------------------------- 1 | package com.apacherio.jondy.annotationdemo; 2 | 3 | 4 | /** 5 | * @author : LJW 6 | * @date : 2019/11/22 7 | * @desc :纸币器 232协议 8 | */ 9 | public class BanknotesProtocol extends BaseProtocol { 10 | 11 | /** 12 | * 心跳命令-纸币器状态主动上报 13 | */ 14 | public static byte HEART_BEAT_CMD = (byte) 0x33; 15 | /** 16 | * 2.获取纸币器设备参数 17 | */ 18 | public static byte GET_BANKNOTES_PARAM = (byte) 0x31; 19 | /** 20 | * 3.控制纸币器工作模式 21 | */ 22 | public static byte CONTROL_WAY_SHIPMENT_CMD = (byte) 0x34; 23 | /** 24 | * .硬币器状态主动上报 25 | */ 26 | public static byte COIN_HEART_BEAT_CMD = (byte) 0x0B; 27 | /** 28 | * 2.获取硬币器设备参数09H 29 | */ 30 | public static byte GET_COIN_PARAM = (byte) 0x09; 31 | /** 32 | * 3.控制硬币器工作模式0CH 33 | */ 34 | public static byte CONTROL_COIN_WORK_MODE = (byte) 0x0C; 35 | /** 36 | * 4.找零器动作0FH 37 | */ 38 | public static byte CHANGE_ACTION = (byte) 0x0F; 39 | 40 | } 41 | -------------------------------------------------------------------------------- /okserialport/src/main/java/com/ljw/okserialport/serialport/utils/ReadMessage.java: -------------------------------------------------------------------------------- 1 | package com.ljw.okserialport.serialport.utils; 2 | 3 | 4 | import com.ljw.okserialport.serialport.bean.DataPack; 5 | 6 | /** 7 | * 收到的日志 8 | */ 9 | 10 | public class ReadMessage { 11 | 12 | private String message; 13 | private int readType = -1; 14 | private DataPack dataPack; 15 | 16 | public ReadMessage(@ReadType int readType, String message, DataPack dataPack) { 17 | this.readType = readType; 18 | this.message = message; 19 | this.dataPack = dataPack; 20 | } 21 | 22 | public String getMessage() { 23 | return message; 24 | } 25 | 26 | 27 | public int getReadType() { 28 | return readType; 29 | } 30 | 31 | public void setReadType(@ReadType int readType) { 32 | this.readType = readType; 33 | } 34 | 35 | public DataPack getDataPack() { 36 | return dataPack; 37 | } 38 | 39 | public void setDataPack(DataPack dataPack) { 40 | this.dataPack = dataPack; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /okserialport/src/main/java/com/ljw/okserialport/serialport/utils/Priority.java: -------------------------------------------------------------------------------- 1 | package com.ljw.okserialport.serialport.utils; 2 | 3 | 4 | import android.support.annotation.IntDef; 5 | 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | 9 | import static com.ljw.okserialport.serialport.utils.Priority.DEFAULT; 10 | import static com.ljw.okserialport.serialport.utils.Priority.HIGH; 11 | import static com.ljw.okserialport.serialport.utils.Priority.IMMEDTATELY; 12 | import static com.ljw.okserialport.serialport.utils.Priority.LOW; 13 | 14 | 15 | /** 16 | * @author : fangbingran 17 | * @aescription : 等级 18 | * @date : 2019/06/05 19:34 19 | */ 20 | @IntDef({LOW, DEFAULT, HIGH, IMMEDTATELY}) 21 | @Retention(RetentionPolicy.SOURCE) 22 | public @interface Priority { 23 | /** 24 | * 最低等级 25 | */ 26 | int LOW = 0; 27 | /** 28 | * 默认等级 29 | */ 30 | int DEFAULT = 1; 31 | /** 32 | * 高等级 33 | */ 34 | int HIGH = 2; 35 | /** 36 | * 立即执行 37 | */ 38 | int IMMEDTATELY = 3; 39 | } 40 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | 15 |