diff --git a/app/src/main/java/com/example/xiaojin20135/topsdevlibs/LoRaFragment.java b/app/src/main/java/com/example/xiaojin20135/topsdevlibs/LoRaFragment.java index 97ecea1..889065e 100644 --- a/app/src/main/java/com/example/xiaojin20135/topsdevlibs/LoRaFragment.java +++ b/app/src/main/java/com/example/xiaojin20135/topsdevlibs/LoRaFragment.java @@ -74,6 +74,7 @@ private void sendData() { byte[] frame = new byte[]{0x00, 0x01, 0x02, 0x03, 0x04}; DataSendBuffer.DATA_SEND_BUFFER.setDatasSendArr(frame); HelpUtils.currentChannel = channelLoRa; + send(); } diff --git a/comlib/src/main/java/com/example/xiaojin20135/comlib/fragment/BaseReadFragment.java b/comlib/src/main/java/com/example/xiaojin20135/comlib/fragment/BaseReadFragment.java index 9ba4e82..adc98cd 100644 --- a/comlib/src/main/java/com/example/xiaojin20135/comlib/fragment/BaseReadFragment.java +++ b/comlib/src/main/java/com/example/xiaojin20135/comlib/fragment/BaseReadFragment.java @@ -266,7 +266,6 @@ private void showError(String errorInfo){ } private void parseBytes(byte[] bytes){ - byte[] receiveBytes = dataRecieveBuffer.addItem (bytes); Log.d(TAG,"in parseBytes receiveBytes = " + MethodsHelp.METHODS_HELP.byteToHexString(receiveBytes,receiveBytes.length)); Map map = new HashMap(); diff --git a/comlib/src/main/java/com/example/xiaojin20135/comlib/help/HelpUtils.java b/comlib/src/main/java/com/example/xiaojin20135/comlib/help/HelpUtils.java index 248589f..15409f8 100644 --- a/comlib/src/main/java/com/example/xiaojin20135/comlib/help/HelpUtils.java +++ b/comlib/src/main/java/com/example/xiaojin20135/comlib/help/HelpUtils.java @@ -11,12 +11,12 @@ public enum HelpUtils { //最大发送次数 public static final int maxWriteCount = 5; //最大读取次数 - public static final int maxReadCount = 40; + public static int maxReadCount = 20; //收到报文后,连续收不到多少次后停止 public static final int maxSerialCount = 2; //串口最小通信间隔 单位毫秒 - public static final int minSerialInterval = 100; + public static int minSerialInterval = 100; //每次发送接收时的最大字节个数 public static final int normalByteSize = 1024; //当前通道 @@ -43,7 +43,8 @@ public enum HelpUtils { public static final int channelNFC = 5; //载波通道 public static final int channelZb = 6; - + //LoRa音频通道 + public static final int channelLoRaAudio = 7; //标识当前传输的报文类型 public static int protocolType = 0; @@ -60,4 +61,29 @@ public enum HelpUtils { public static final int TYPE_NFC = 4; //是否允许一直接收数据 public static boolean canReceiving = false; + + + public static int getMaxReadCount() { + return maxReadCount; + } + + public static void setMaxReadCount(int maxReadCount) { + HelpUtils.maxReadCount = maxReadCount; + } + + public static int getMinSerialInterval() { + return minSerialInterval; + } + + public static void setMinSerialInterval(int minSerialInterval) { + HelpUtils.minSerialInterval = minSerialInterval; + } + + public static int getMaxWriteCount() { + return maxWriteCount; + } + + public static int getMaxSerialCount() { + return maxSerialCount; + } } diff --git a/comlib/src/main/java/com/example/xiaojin20135/comlib/help/ReadDatas.java b/comlib/src/main/java/com/example/xiaojin20135/comlib/help/ReadDatas.java index 58b9277..f817590 100644 --- a/comlib/src/main/java/com/example/xiaojin20135/comlib/help/ReadDatas.java +++ b/comlib/src/main/java/com/example/xiaojin20135/comlib/help/ReadDatas.java @@ -18,6 +18,7 @@ import static com.example.xiaojin20135.comlib.help.HelpUtils.channel485; import static com.example.xiaojin20135.comlib.help.HelpUtils.channelFirared; import static com.example.xiaojin20135.comlib.help.HelpUtils.channelLoRa; +import static com.example.xiaojin20135.comlib.help.HelpUtils.channelLoRaAudio; import static com.example.xiaojin20135.comlib.help.HelpUtils.channelManage; import static com.example.xiaojin20135.comlib.help.HelpUtils.channelNFC; import static com.example.xiaojin20135.comlib.help.HelpUtils.channelNetPort; @@ -114,9 +115,12 @@ public void subscribe (ObservableEmitter emitter) throws Exception { }else if(HelpUtils.currentChannel == channelLoRa){ datasLen = JniMethods.LoraWrite(toSendArr,toSendArr.length); Log.d (TAG,"LoRa通道 发送 dataLen = " + datasLen); + }else if(HelpUtils.currentChannel == channelLoRaAudio){ + datasLen = JniMethods.AudioWrite(toSendArr,toSendArr.length); + Log.d (TAG,"LoRa音频通道 发送 dataLen = " + datasLen); } } - Thread.sleep (1); + Thread.sleep (0); }catch (InterruptedException e){ if(!emitter.isDisposed ()){ emitter.onError (e); @@ -180,6 +184,10 @@ public void subscribe (ObservableEmitter emitter) throws Exception { datas = new byte[255]; length = JniMethods.LoraRead(datas,255); Log.d (TAG,"LoRa通道 接收 length = " + length); + }else if(HelpUtils.currentChannel == channelLoRaAudio){ + datas = new byte[255]; + length = JniMethods.AudioRead(datas,255); + Log.d (TAG,"LoRa音频通道 接收 length = " + length); } if(length > 0){ Log.d(TAG,"当前已收到的报文长度 currentLen = " + currentLen); @@ -257,6 +265,10 @@ public void subscribe (ObservableEmitter emitter) throws Exception { datas = new byte[255]; length = JniMethods.LoraRead(datas,255); Log.d (TAG,"LoRa通道 接收 length = " + length); + }else if(HelpUtils.currentChannel == channelLoRa){ + datas = new byte[255]; + length = JniMethods.LoraRead(datas,255); + Log.d (TAG,"LoRa通道 接收 length = " + length); } if(length > 0){ Log.d(TAG,"本次收到 = " + MethodsHelp.METHODS_HELP.byteToHexString(datas,length)); diff --git a/comlib/src/main/java/com/example/xiaojin20135/comlib/jni/JniMethods.java b/comlib/src/main/java/com/example/xiaojin20135/comlib/jni/JniMethods.java index 0c57f97..25cfc8d 100644 --- a/comlib/src/main/java/com/example/xiaojin20135/comlib/jni/JniMethods.java +++ b/comlib/src/main/java/com/example/xiaojin20135/comlib/jni/JniMethods.java @@ -104,6 +104,10 @@ public static void initPort(File device) throws SecurityException, IOException { public static native int LoraWrite(byte[] bytesArr,int len); + public static native int AudioRead(byte[] bytesArr,int len); + public static native int AudioWrite(byte[] bytesArr,int len); + + //设置中心频率 public static native int LoRaSetFrequency(int freq); //设置扩频因子