diff --git a/.gitignore b/.gitignore index c030963..e1403c0 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ /C5/build /C5/evaluation/build *.iml +*.class diff --git a/C5/app/build.gradle b/C5/app/build.gradle index 22429ac..43b1d86 100644 --- a/C5/app/build.gradle +++ b/C5/app/build.gradle @@ -94,7 +94,7 @@ dependencies { compile 'com.github.barteksc:android-pdf-viewer:2.7.0' compile 'cn.yipianfengye.android:zxing-library:2.2' compile 'com.jaredrummler:android-processes:1.1.1' - implementation project(':xpadapi') + compile project(':xpadapi') } //#解决某些输入文件使用或覆盖了已过时的 API diff --git a/C5/app/src/main/java/com/sunvote/xpadapp/MainActivity.java b/C5/app/src/main/java/com/sunvote/xpadapp/MainActivity.java index 11686b5..070f767 100644 --- a/C5/app/src/main/java/com/sunvote/xpadapp/MainActivity.java +++ b/C5/app/src/main/java/com/sunvote/xpadapp/MainActivity.java @@ -9,13 +9,13 @@ import android.os.Handler; import android.widget.TextView; import com.sunvote.xpadapi.service.XpadApiService; -import com.sunvote.xpadapi.service.logic.XpadApiServiceInfoProxyManager; import com.sunvote.xpadapi.service.bean.BaseInfo; import com.sunvote.xpadapi.service.bean.BaseVoteInfo; import com.sunvote.xpadapi.service.bean.OnLineInfo; import com.sunvote.xpadapi.service.listener.BaseInfoChanageListener; import com.sunvote.xpadapi.service.listener.BaseVoteInfoChanageListener; import com.sunvote.xpadapi.service.listener.OnlineInfoChanageListener; +import com.sunvote.xpadapi.service.logic.XpadApiServiceInfoProxyManager; import com.sunvote.xpadapp.base.BaseActivity; public class MainActivity extends BaseActivity { diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/XpadApiService.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/XpadApiService.java index 479dff3..ae5007d 100644 --- a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/XpadApiService.java +++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/XpadApiService.java @@ -5,38 +5,39 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import android.hardware.usb.UsbManager; import android.os.Handler; import android.os.HandlerThread; import android.os.IBinder; -import com.sunvote.udptransfer.UDPModule; import com.sunvote.udptransfer.stream.SunVoteInputStream; import com.sunvote.udptransfer.work.BaseStationProcessWork; import com.sunvote.udptransfer.work.RepeatMessageManager; import com.sunvote.udptransfer.work.SDKProcessWork; +import com.sunvote.util.LogUtil; import com.sunvote.xpadapi.ISunvoteApi; -import com.sunvote.xpadapi.service.bean.HeartBeat; -import com.sunvote.xpadapi.service.bean.Packet; -import com.sunvote.xpadapi.service.listener.OnDataReceiver; import com.sunvote.xpadapi.service.bean.BaseInfo; import com.sunvote.xpadapi.service.bean.BaseVoteInfo; +import com.sunvote.xpadapi.service.bean.HeartBeat; import com.sunvote.xpadapi.service.bean.KeypadInfo; import com.sunvote.xpadapi.service.bean.ModelInfo; import com.sunvote.xpadapi.service.bean.OnLineInfo; +import com.sunvote.xpadapi.service.bean.Packet; +import com.sunvote.xpadapi.service.listener.OnDataReceiver; +import com.sunvote.xpadapi.service.logic.XpadApiServiceInfoProxyManager; import com.sunvote.xpadapi.usb.UsbTransferManager; import com.sunvote.xpadapi.util.ByteUtils; import com.sunvote.xpadapi.util.Cons; import com.sunvote.xpadapi.util.Crc16; -import com.sunvote.xpadapi.util.LogUtil; import java.io.ByteArrayOutputStream; -import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; +/** + * @Author Elvis + */ public class XpadApiService extends Service { private static final String TAG = XpadApiService.class.getSimpleName(); @@ -52,7 +53,7 @@ public class XpadApiService extends Service { try { temp.onDataReceiver(datas); } catch (Exception ex) { - LogUtil.e(TAG, "onDataReceiver", ex); + LogUtil.e(TAG, "onDataReceiver" + temp.getClass().getSimpleName(), ex); } } } @@ -173,19 +174,6 @@ public class XpadApiService extends Service { }; - private UsbTransferManager.OnUsbConnectListener connectListener = new UsbTransferManager.OnUsbConnectListener() { - @Override - public boolean onConnect(boolean isConnected) { - if (isConnected) { - // - getKeypadParam(); - sleepTimes(100); - getWorkMode(); - } - return true; - } - }; - private Runnable sendTask = new Runnable() { @Override public void run() { @@ -309,10 +297,11 @@ public class XpadApiService extends Service { } private void firmUpdateResponse(byte[] datas) { + } private void voteResultSendResponse(byte[] datas) { - + // 下层模块收到了,说明不了什么,所以不干什么 } private void checkBaseStatusResponse(byte[] datas) { @@ -583,4 +572,159 @@ public class XpadApiService extends Service { sendInnerPacket(packet); } + public void applyFileUpload(int length, String filename, byte anstype,byte index) { + byte[] mBuffer = new byte[0x1F + 4]; + Arrays.fill(mBuffer, (byte) 0x0); + mBuffer[0] = (byte) 0xF5; + mBuffer[1] = (byte) 0xAA; + mBuffer[2] = (byte) 0xAA; + mBuffer[3] = (byte) 0x1F; + mBuffer[4] = 0x73; + mBuffer[5] = (byte) 0XFF;// 流水号 + mBuffer[6] = (byte) 0X01;// 流水号 + mBuffer[7] = (byte) 15;// MSGTYPE + mBuffer[8] = (byte) anstype;// ANSTYPE 添加5 文件上传指令 + mBuffer[9] = index;// 高位 + Packet packet = new Packet(); + packet.setDatas(mBuffer); + packet.setSendNo(Packet.CommunicationTestMatchNum); + sendInnerPacket(packet); + } + + public void packetReceptionConfirmed(byte[] keyid, byte packid, byte packH, byte packtype) { + byte[] mBuffer = new byte[0x1F + 4]; + Arrays.fill(mBuffer, (byte) 0x0); + mBuffer[0] = (byte) 0xF5; + mBuffer[1] = (byte) 0xAA; + mBuffer[2] = (byte) 0xAA; + mBuffer[3] = (byte) 0x1F; + + mBuffer[4] = (byte) 0xA0; + int keyId = XpadApiServiceInfoProxyManager.getInstance().getKeypadInfo().getKeyId(); + mBuffer[5] = (byte)((keyId >> 8) & 0xFF); + mBuffer[6] = (byte)((keyId) & 0xFF); + + mBuffer[7] = 3;//CMD 3 多包接收完毕应答 + mBuffer[8] = packtype;//PACKTYPE 多包类型 + mBuffer[9] = packid;//数据包标识码 + Packet packet = new Packet(); + packet.setDatas(mBuffer); + packet.setSendNo(Packet.CommunicationTestMatchNum); + sendInnerPacket(packet); + } + + public void uploadFileData(byte[] keyid, byte packid, byte packH, byte packL, byte[] datas, byte packtype) { + uploadFileData(keyid, packid, packH, packL, datas, 0, datas.length, packtype); + } + + /** + * @param keyid 键盘编号 + * @param packid 包id + * @param packH 数据段id + * @param packL 数据片id + * @param datas 数据 + * @param offset 偏移位置 + * @param length 长度 + * @Auther Elvis + * 上传数据包(多包应答) + */ + public void uploadFileData(byte[] keyid, byte packid, byte packH, byte packL, byte[] datas, int offset, int length, byte packtype) { + LogUtil.i(TAG, "onMutilPacketData packid=" + packid + ",packH=" + packH + ",packL=" + packL + ",offset=" + offset); + byte[] mBuffer = new byte[0x1F + 4]; + Arrays.fill(mBuffer, (byte) 0x0); + mBuffer[0] = (byte) 0xF5; + mBuffer[1] = (byte) 0xAA; + mBuffer[2] = (byte) 0xAA; + mBuffer[3] = (byte) 0x1F; + + mBuffer[4] = (byte) 0xA0; + int keyId = XpadApiServiceInfoProxyManager.getInstance().getKeypadInfo().getKeyId(); + mBuffer[5] = (byte)((keyId >> 8) & 0xFF); + mBuffer[6] = (byte)((keyId) & 0xFF); + + mBuffer[7] = 2;//CMD 1 回应多包数据 + mBuffer[8] = packtype;//PACKTYPE 多包类型 + mBuffer[9] = packid;//数据包标识码 + mBuffer[10] = packH;//数据段编号 + mBuffer[11] = packL;//数据片编号 + for (int i = 0; i < length && i < 16 && i < datas.length - offset; i++) { + mBuffer[12 + i] = datas[offset + i]; + } + Packet packet = new Packet(); + packet.setDatas(mBuffer); + packet.setSendNo(Packet.CommunicationTestMatchNum); + sendInnerPacket(packet); + } + + /** + * @param packid 包id + * 多包接收确认(多包接收应答) + */ + public void packetConfirmation(byte[] keyid, byte packid, byte packH, byte packL, byte[] names, byte packtype) { + LogUtil.i(TAG, "onMutilPacketRespone packid=" + packid + ",packH=" + packH + ",packL=" + packL + ",names=" + names); + byte[] mBuffer = new byte[0x1F + 4]; + Arrays.fill(mBuffer, (byte) 0x0); + mBuffer[0] = (byte) 0xF5; + mBuffer[1] = (byte) 0xAA; + mBuffer[2] = (byte) 0xAA; + mBuffer[3] = (byte) 0x1F; + + mBuffer[4] = (byte) 0xA0; + int keyId = XpadApiServiceInfoProxyManager.getInstance().getKeypadInfo().getKeyId(); + mBuffer[5] = (byte)((keyId >> 8) & 0xFF); + mBuffer[6] = (byte)((keyId) & 0xFF); + mBuffer[5] = keyid[0]; + mBuffer[6] = keyid[1]; + + mBuffer[7] = 1;//CMD 1 + mBuffer[8] = packtype;//PACKTYPE 多包类型 + mBuffer[9] = packid;//数据包标识码 + mBuffer[10] = packH; + mBuffer[11] = packL; + if (names != null) { + for (int i = 0; i < 14 && i < names.length; i++) { + mBuffer[12 + i] = names[i]; + } + } + + Packet packet = new Packet(); + packet.setDatas(mBuffer); + packet.setSendNo(Packet.CommunicationTestMatchNum); + sendInnerPacket(packet); + } + + private void keepFirmMode() { + byte[] mBuffer = new byte[0x1F + 4]; + Arrays.fill(mBuffer, (byte) 0x0); + mBuffer[0] = (byte) 0xF5; + mBuffer[1] = (byte) 0xAA; + mBuffer[2] = (byte) 0xAA; + mBuffer[3] = (byte) 10; + + mBuffer[4] = 0x78; + mBuffer[5] = 0x02; + + Packet packet = new Packet(); + packet.setDatas(mBuffer); + packet.setSendNo(Packet.CommunicationTestMatchNum); + sendInnerPacket(packet); + } + + private void eraseFlash(int fileLen) { + byte[] mBuffer = new byte[0x1F + 4]; + Arrays.fill(mBuffer, (byte) 0x0); + mBuffer[0] = (byte) 0xF5; + mBuffer[1] = (byte) 0xAA; + mBuffer[2] = (byte) 0xAA; + mBuffer[3] = (byte) 10; + mBuffer[4] = 0x78; + mBuffer[5] = 0x03; + mBuffer[6] = 0; + mBuffer[7] = (byte) (fileLen / 1024); + + Packet packet = new Packet(); + packet.setDatas(mBuffer); + packet.setSendNo(Packet.CommunicationTestMatchNum); + sendInnerPacket(packet); + } } diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/BatchNumberVote.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/BatchNumberVote.java index 4b97372..9251e87 100644 --- a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/BatchNumberVote.java +++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/BatchNumberVote.java @@ -1,6 +1,6 @@ package com.sunvote.xpadapi.service.bean; -import com.sunvote.xpadapi.service.SerialManager; +import com.sunvote.xpadapi.service.logic.SerialManager; import java.util.Arrays; diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/BatchSingleVote.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/BatchSingleVote.java index 8c08a25..4aa028f 100644 --- a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/BatchSingleVote.java +++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/BatchSingleVote.java @@ -1,6 +1,6 @@ package com.sunvote.xpadapi.service.bean; -import com.sunvote.xpadapi.service.SerialManager; +import com.sunvote.xpadapi.service.logic.SerialManager; import java.util.Arrays; diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/LoginInVote.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/LoginInVote.java index 2efde4f..2cb36ad 100644 --- a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/LoginInVote.java +++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/LoginInVote.java @@ -1,6 +1,6 @@ package com.sunvote.xpadapi.service.bean; -import com.sunvote.xpadapi.service.SerialManager; +import com.sunvote.xpadapi.service.logic.SerialManager; import java.util.Arrays; diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/NumberVote.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/NumberVote.java index d70f869..3f0fbfa 100644 --- a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/NumberVote.java +++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/NumberVote.java @@ -1,6 +1,6 @@ package com.sunvote.xpadapi.service.bean; -import com.sunvote.xpadapi.service.SerialManager; +import com.sunvote.xpadapi.service.logic.SerialManager; import java.util.Arrays; diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/SelectOtherVote.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/SelectOtherVote.java index 5cf081f..f8a409c 100644 --- a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/SelectOtherVote.java +++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/SelectOtherVote.java @@ -1,7 +1,7 @@ package com.sunvote.xpadapi.service.bean; -import com.sunvote.xpadapi.service.SerialManager; -import com.sunvote.xpadapi.service.XpadApiServiceInfoProxyManager; +import com.sunvote.xpadapi.service.logic.SerialManager; +import com.sunvote.xpadapi.service.logic.XpadApiServiceInfoProxyManager; import com.sunvote.xpadapi.util.LogUtil; import java.util.Arrays; diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/SelectVote.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/SelectVote.java index 7de230e..bc7e5b4 100644 --- a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/SelectVote.java +++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/SelectVote.java @@ -1,6 +1,6 @@ package com.sunvote.xpadapi.service.bean; -import com.sunvote.xpadapi.service.SerialManager; +import com.sunvote.xpadapi.service.logic.SerialManager; import java.util.Arrays; diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/ServiceTypeVote.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/ServiceTypeVote.java index 21a972d..4dd291d 100644 --- a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/ServiceTypeVote.java +++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/ServiceTypeVote.java @@ -1,6 +1,6 @@ package com.sunvote.xpadapi.service.bean; -import com.sunvote.xpadapi.service.SerialManager; +import com.sunvote.xpadapi.service.logic.SerialManager; import java.util.Arrays; diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/SingleVote.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/SingleVote.java index e004611..77e755f 100644 --- a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/SingleVote.java +++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/SingleVote.java @@ -1,6 +1,6 @@ package com.sunvote.xpadapi.service.bean; -import com.sunvote.xpadapi.service.SerialManager; +import com.sunvote.xpadapi.service.logic.SerialManager; import java.util.Arrays; diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/Vote.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/Vote.java index de9184c..7458402 100644 --- a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/Vote.java +++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/Vote.java @@ -1,6 +1,6 @@ package com.sunvote.xpadapi.service.bean; -import com.sunvote.xpadapi.service.SerialManager; +import com.sunvote.xpadapi.service.logic.SerialManager; import java.util.Arrays; diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/AbsDownloadProcess.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/AbsDownloadProcess.java new file mode 100644 index 0000000..41614fb --- /dev/null +++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/AbsDownloadProcess.java @@ -0,0 +1,115 @@ +package com.sunvote.xpadapi.service.listener; + +import java.io.File; +import java.io.IOException; + +/** + * Created by Elvis on 2018/3/20 11:18 + * Email:Eluis@psunsky.com + * 版权所有:长沙中天电子设计开发有限公司 + * Description: 人大通用版XPadAppRendaMac + */ + +public abstract class AbsDownloadProcess { + + private static String foldPath = "/sdcard/Sunvote/download/"; + + protected static String fileName = "default.obj"; + + private long length ; + private long curComplete = 0 ; + + private static File file ; + + public File getFile() { + if(file == null){ + curComplete = 0 ; + File folder = new File(foldPath); + if(!folder.exists()){ + folder.mkdirs(); + } + if(fileName == null || "".equals(fileName.trim())){ + fileName = "default.obj" ; + } + file = new File(foldPath , fileName); + file.deleteOnExit(); + if(!file.exists()){ + try { + file.createNewFile(); + } catch (IOException e) { + onDownloadError(e); + } + } + } + return file; + } + + protected long getLength() { + return length; + } + + public String getFoldPath() { + return foldPath; + } + + protected void setLength(long length) { + this.length = length; + curComplete = 0 ; + } + + public void setFileName(String fileName) { + if(!(fileName == null || "".equals(fileName.trim()))) { + this.fileName = fileName; + file = null; + } + } + + protected String getFileName() { + return fileName; + } + + public void setFoldPath(String foldPath) { + this.foldPath = foldPath; + } + + protected void onStartDownload(){ + onStartDownload(getFile(),getLength()); + } + + public abstract void onStartDownload(File file,long length); + + protected void onDownloadAddProcess(int curPack) { + curComplete += curPack; + double result = 0; + if(curComplete <= length){ + result = (double)curComplete / length ; + }else{ + result = 1; + } + + try{ + onDownloadProcess(result); + }catch (Exception ex){ + ex.printStackTrace(); + } + try{ + int ri = (int)(result * 100); + onDownloadProcess(ri + "%"); + }catch (Exception ex){ + ex.printStackTrace(); + } + } + + public abstract void onDownloadProcess(double process); + + public abstract void onDownloadProcess(String process); + + protected void onStopDownload(){ + onStopDownload(getFile()); + } + + public abstract void onStopDownload(File file); + + public abstract void onDownloadError(Exception e); + +} diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/IUploadListener.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/IUploadListener.java new file mode 100644 index 0000000..7244f83 --- /dev/null +++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/IUploadListener.java @@ -0,0 +1,18 @@ +package com.sunvote.xpadapi.service.listener; + +/** + * Created by Elvis on 2018/3/22 13:43 + * Email:Eluis@psunsky.com + * 版权所有:长沙中天电子设计开发有限公司 + * Description: 人大通用版XPadAppRendaMac + */ +public interface IUploadListener { + + public void onUploadStart(); + + public void onUploadProcess(double process); + + public void onUploadStop(); + + public void onFail(); +} diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/logic/RFFileDownloadModule.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/logic/RFFileDownloadModule.java new file mode 100644 index 0000000..d4671be --- /dev/null +++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/logic/RFFileDownloadModule.java @@ -0,0 +1,121 @@ +package com.sunvote.xpadapi.service.logic; + +import android.os.Handler; +import android.os.Looper; + +import com.sunvote.util.LogUtil; +import com.sunvote.xpadapi.service.listener.AbsDownloadProcess; + +import java.io.File; + +/** + * Created by Elvis on 2018/3/20 11:16 + * Email:Eluis@psunsky.com + * 版权所有:长沙中天电子设计开发有限公司 + * Description: 文件下载模块 + */ +public class RFFileDownloadModule { + + private RFFileDownloadModule(){ + handler = new Handler(Looper.getMainLooper()); + } + private Handler handler ; + private long overtime = 15 * 1000 ; + private static RFFileDownloadModule instance = new RFFileDownloadModule(); + + public static RFFileDownloadModule getInstance() { + return instance; + } + + private AbsDownloadProcess downloadProcess; + private AbsDownloadProcess tdownloadProcess = new AbsDownloadProcess() { + + private boolean start = false; + private double process = 0 ; + private Runnable runnable = new Runnable() { + @Override + public void run() { + onDownloadError(new Exception("overtime")); + } + }; + + @Override + public void onStartDownload(File file, long length) { + start = true; + process = 0; + LogUtil.i("onStartDownload", file.getName() + "," + length); + if(downloadProcess != null){ + downloadProcess.onStartDownload(file,length); + } + handler.removeCallbacks(runnable); + handler.postDelayed(runnable,overtime); + } + + @Override + public void onDownloadProcess(double process) { + this.process = process; + LogUtil.i("onDownloadProcess", "process," + process); + if(downloadProcess != null && start){ + downloadProcess.onDownloadProcess(process); + } + handler.removeCallbacks(runnable); + handler.postDelayed(runnable,overtime); + } + + @Override + public void onDownloadProcess(String process) { + LogUtil.i("onDownloadProcess", "process," + process); + if(downloadProcess != null && start){ + downloadProcess.onDownloadProcess(process); + } + handler.removeCallbacks(runnable); + handler.postDelayed(runnable,overtime); + } + + @Override + public void onStopDownload(File file) { + LogUtil.i("onStopDownload", "process," + file.getName()); + if(downloadProcess != null && start){ + if(process >= 1.0){ + downloadProcess.onStopDownload(file); + }else{ + downloadProcess.onDownloadError(new Exception("file download error")); + } + } + start = false; + handler.removeCallbacks(runnable); + file.deleteOnExit(); + } + + @Override + public void onDownloadError(Exception e) { + LogUtil.i("onStopDownload", "error", e); + if(downloadProcess != null && start){ + downloadProcess.onDownloadError(e); + } + start = false; + handler.removeCallbacks(runnable); + } + }; + + public void setOvertime(long overtime) { + if(overtime > 0){ + this.overtime = overtime; + } + } + + public synchronized void registerDownloadProcess(AbsDownloadProcess downloadProcess){ + this.downloadProcess = downloadProcess ; + } + + public synchronized void unRegisterDownloadProcess(AbsDownloadProcess downloadProcess){ + this.downloadProcess = null; + } + + protected synchronized AbsDownloadProcess getDownloadProcess() { + + return tdownloadProcess; + } + + +} diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/logic/RFFileUploadModule.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/logic/RFFileUploadModule.java new file mode 100644 index 0000000..9e35e11 --- /dev/null +++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/logic/RFFileUploadModule.java @@ -0,0 +1,358 @@ +package com.sunvote.xpadapi.service.logic; + +import android.os.Handler; +import android.os.HandlerThread; + +import com.sunvote.util.LogUtil; +import com.sunvote.xpadapi.service.listener.IUploadListener; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.UnsupportedEncodingException; + +/** + * Created by Elvis on 2018/3/21 16:13 + * Email:Eluis@psunsky.com + * 版权所有:长沙中天电子设计开发有限公司 + * Description: 文件上传模块 + */ +public class RFFileUploadModule { + + public static final byte PACKTYPE = 5 ; + public static final int SLEEP_TIME = 25 ; + public static byte index = 0 ; + private RFFileUploadModule(){ + handlerThread = new HandlerThread(RFFileUploadModule.class.getSimpleName()); + handlerThread.start(); + handler = new Handler(handlerThread.getLooper()); + } + + private static RFFileUploadModule instance ; + + public static RFFileUploadModule getInstance() { + if(instance == null){ + synchronized (RFFileUploadModule.class){ + if(instance == null){ + instance = new RFFileUploadModule(); + } + } + } + return instance; + } + + private IUploadListener uploadListener = new IUploadListener() { + @Override + public void onUploadStart() { + System.out.println("onUploadStart"); + } + + @Override + public void onUploadProcess(double process) { + System.out.println("onUploadProcess:" + process); + } + + @Override + public void onUploadStop() { + System.out.println("onUploadStop"); + } + + @Override + public void onFail() { + System.out.println("onFail"); + } + }; + + + private String filename; + private byte[] datas = new byte[1024]; + private int length = 1024; + private HandlerThread handlerThread ; + private Handler handler ; + private byte[] keyid = new byte[2]; + private Runnable task; + private int packTotal ; + private boolean isStop = false ; + + /** + * 文件名不能超过16个字符(中文不能超过8个),超过16个字符将会出现截断。 + * 文件长度不能超过65535个字节 + * @param file 文件 + * @return 是否成功发起上传 + */ + public boolean uploadFile(File file){ + LogUtil.i("RFFileUploadModule","uploadFile" + file); + if(file != null){ + length = (int)file.length(); + filename = file.getName(); + datas = new byte[length+4]; + FileInputStream fis = null ; + try { + fis = new FileInputStream(file); + int start = 0 ; + // 把文件数据读入字节数组。 + while(start < length){ + int ret = fis.read(datas,start,length-start); + if(ret < 0){ + break; + } + start += ret ; + } + datas[length] = 0x13 ; + datas[length + 1] = 0x0 ; + datas[length + 2] = 0x10 ; + datas[length + 3] = 0x0 ; + + if(start >= length){ + task = new A0(filename,length); + handler.removeCallbacks(task); + handler.post(task); + return true; + } + + } catch (Exception e) { + e.printStackTrace(); + }finally { + if(fis != null){ + try { + fis.close(); + } catch (IOException e) { + e.printStackTrace(); + } + fis = null; + } + } + } + return false; + } + + public void setKeyid(byte[] keyid) { + setKeyid(keyid,0); + } + public void setKeyid(byte[] keyid,int start) { + this.keyid[0] = keyid[start]; + this.keyid[1] = keyid[start+1]; + } + + public void onUploadFile(byte data, byte[] keyid, byte packid, byte packH, byte[] packLs) { + if (data == 1) { + setKeyid(keyid); + packetConfirmation(packid); + } + if (data == 2) { + uploadData(packid, packH, packLs); + } + if (data == 3) { + packetReceptionConfirmed(packid, packH); + } + } + + public void uploadData(byte packid, byte packH, byte[] packLs){ + System.out.println("uploadData"); + handler.removeCallbacks(task); + if(task instanceof A2){ + ((A2)task).setStop(true); + } + task = new A2(keyid,packid,packH,datas,packLs); + handler.post(task); + if(uploadListener != null){ + double process = 0 ; + if(packTotal > 0){ + int count = 0 ; + int sen = (packLs[1] & 0xFF) * 256 + (packLs[0] & 0XFF); + for(int i = 0 ; i < 16 ; i++){ + if((sen & (1 << i)) == 0){ + count ++ ; + } + } + int been = packH * 16 + count ; + if(been > packTotal){ + been = packTotal ; + } + process = (double)(been) / packTotal ; + } + uploadListener.onUploadProcess(process); + } + } + + public void packetConfirmation(byte packid){ + System.out.println("packetConfirmation"); + handler.removeCallbacks(task); + byte[] names = null; + if(filename != null){ + try { + names = filename.getBytes("GB2312"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + } + task = new A1(keyid,(byte)((length + 4 ) / 65535), (byte)(((length + 4) % 65535) / 256),(byte)((length + 4) % 256),names); + handler.post(task); + } + + public void packetReceptionConfirmed(byte packid,byte packH){ + System.out.println("packetReceptionConfirmed"); + handler.removeCallbacks(task); + task = new A3(keyid,packid,packH); + handler.post(task); + } + + public boolean uploadFile(byte[] datas){ + System.out.println("uploadFile" + datas); + if(datas != null){ + length = datas.length ; + filename = null ; + this.datas = new byte[length + 4]; + System.arraycopy(datas,0,this.datas,0,length); + datas[length] = 0x13 ; + datas[length + 1] = 0x0 ; + datas[length + 2] = 0x10 ; + datas[length + 3] = 0x0 ; + task = new A0(filename,length); + handler.removeCallbacks(task); + handler.post(task); + return true; + } + return false; + } + + + public void setUploadListener(IUploadListener uploadListener) { + this.uploadListener = uploadListener; + } + + class A0 implements Runnable{ + private int length ; + private String filename; + private int times ; + public A0(String filename,int length){ + this.length = length ; + this.filename = filename; + packTotal = length / 16 + 1; + times = 0 ; + index++; + } + + @Override + public void run() { + LogUtil.i("RFFileUploadModule","A0 run"); + XpadApiServiceInfoProxyManager.getInstance().getService().applyFileUpload(this.length,this.filename,PACKTYPE,index); + times ++ ; + if(task != null && times < 5){ + handler.removeCallbacks(task); + handler.postDelayed(task,5000); + } + } + } + + class A1 implements Runnable{ + + private byte[] keyid; + private byte packid ; + private byte packH ; + private byte packL ; + private byte[] names ; + private int times ; + + public A1(byte[] keyid, byte packid,byte packH,byte packL,byte[] names) { + LogUtil.i("RFFileUploadModule","A1"); + this.keyid = keyid; + this.packid = packid; + this.packH = packH ; + this.packL = packL ; + this.names = names ; + times = 0 ; + } + + @Override + public void run() { + LogUtil.i("RFFileUploadModule","A1 run"); + XpadApiServiceInfoProxyManager.getInstance().getService().packetConfirmation(this.keyid,this.packid,this.packH,this.packL,this.names,PACKTYPE); + times ++ ; + if(task != null && times < 5){ + handler.removeCallbacks(task); + handler.postDelayed(task,5000); + } + if(uploadListener != null){ + uploadListener.onUploadStart(); + isStop = false; + } + } + } + + class A2 implements Runnable{ + private byte[] keyid; + private byte packid; + private byte packH; + private byte[] datas ; + private byte[] packLs; + private int times ; + private boolean stop = false; + + public void setStop(boolean stop) { + this.stop = stop; + } + + public A2(byte[] keyid, byte packid, byte packH, byte[] datas, byte[] packLs) { + LogUtil.i("RFFileUploadModule","A2"); + this.keyid = keyid; + this.packid = packid; + this.packH = packH; + this.datas = datas; + this.packLs = packLs; + times = 0 ; + } + + @Override + public void run() { + LogUtil.i("RFFileUploadModule","A2 run"); + int packLsi = (packLs[1] & 0xFF) * 256 + (packLs[0] & 0xFF); + int offset = 0 ; + int length = 16; + System.out.println("packLsi:" + packLsi); + for(byte packL = 0 ;packL < 16 && !stop ;packL ++) { + if((packLsi & (1 << packL)) != 0){ + offset = ((packid * 65535) + (packH) * 256 + 16 * (packL)) & 0xFFFF; + XpadApiServiceInfoProxyManager.getInstance().getService().uploadFileData(this.keyid, this.packid, this.packH, (byte)(packL ), this.datas, offset, length,PACKTYPE); + // need sleep ???? + try{ + Thread.sleep(SLEEP_TIME); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + times ++ ; + if(task != null && times < 5){ + handler.removeCallbacks(task); + handler.postDelayed(task,5000); + } + } + } + + class A3 implements Runnable{ + private byte[] keyid; + private byte packid ; + private byte packH; + private int times ; + + public A3(byte[] keyid, byte packid, byte packH) { + LogUtil.i("RFFileUploadModule","A3"); + this.keyid = keyid; + this.packid = packid; + this.packH = packH; + times = 0 ; + } + + @Override + public void run() { + LogUtil.i("RFFileUploadModule","A3 run"); + XpadApiServiceInfoProxyManager.getInstance().getService().packetReceptionConfirmed(this.keyid,this.packid,this.packH,PACKTYPE); + if(uploadListener != null && !isStop){ + isStop = true; + uploadListener.onUploadStop(); + } + } + } +} diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/logic/RFMessageUploadModule.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/logic/RFMessageUploadModule.java new file mode 100644 index 0000000..ea99227 --- /dev/null +++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/logic/RFMessageUploadModule.java @@ -0,0 +1,301 @@ +package com.sunvote.xpadapi.service.logic; + +import android.os.Handler; +import android.os.HandlerThread; + +import java.io.UnsupportedEncodingException; + +/** + * Created by Elvis on 2018/3/27 9:48 + * Email:Eluis@psunsky.com + * 版权所有:长沙中天电子设计开发有限公司 + * Description: 人大通用版 + * 短消息上传模块 + */ +public class RFMessageUploadModule { + + public static final byte PACKTYPE = 3 ; + private static RFMessageUploadModule instance ; + + private IUploadListener uploadListener ; + + private String filename; + private byte[] datas = "test message".getBytes(); + private int length = 1024; + private HandlerThread handlerThread ; + private Handler handler ; + private byte[] keyid; + private Runnable task; + private int packTotal ; + private boolean stop = false; + + private RFMessageUploadModule(){ + handlerThread = new HandlerThread(RFMessageUploadModule.class.getSimpleName()); + handlerThread.start(); + handler = new Handler(handlerThread.getLooper()); + } + + public static RFMessageUploadModule getInstance() { + if(instance == null){ + instance = new RFMessageUploadModule(); + } + return instance; + } + + public void setMessageContent(byte[] messageContent) { + this.datas = messageContent; + uploadMsgData(datas); + removeTask(); + } + + public void setMessageContent(String message) { + try { + this.datas = message.getBytes("GB2312"); + uploadMsgData(datas); + removeTask(); + handler.removeCallbacks(failCall); + handler.postDelayed(failCall,10000); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private boolean uploadMsgData(byte[] ds){ + System.out.println("uploadMsgData" + ds); + if(ds != null){ + length = ds.length ; + filename = null ; + this.datas = new byte[length ]; + System.arraycopy(ds,0,this.datas,0,length); +// this.datas[length] = 0x13 ; +// this.datas[length + 1] = 0x0 ; +// this.datas[length + 2] = 0x10 ; +// this.datas[length + 3] = 0x0 ; + task = new A0(filename,length); + handler.removeCallbacks(task); + handler.post(task); + return true; + } + return false; + } + + + public void setKeyid(byte[] keyid) { + this.keyid = keyid; + } + + public void uploadData(byte packid, byte packH, byte[] packLs){ + System.out.println("uploadData"); + handler.removeCallbacks(task); + task = new A2(keyid,packid,packH,datas,packLs); + handler.post(task); + if(uploadListener != null){ + double process = 0 ; + if(packTotal > 0){ + int count = 0 ; + int sen = (packLs[1] & 0xFF) * 256 + (packLs[0] & 0XFF); + for(int i = 0 ; i < 16 ; i++){ + if((sen & (1 << i)) != 0){ + count ++ ; + } + } + process = (double)(packH * 16 + count) / packTotal ; + } + uploadListener.onUploadProcess(process); + } + } + + public void packetConfirmation(byte packid){ + System.out.println("packetConfirmation"); + handler.removeCallbacks(task); + byte[] names = null; + if(filename != null){ + try { + names = filename.getBytes("GB2312"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + } + task = new A1(keyid,(byte)((length ) / 65535), (byte)(((length ) % 65535) / 256),(byte)(((length ) % 256 / 16 + (length % 16 == 0 ? 0 : 1))),names); + handler.post(task); + } + + public void packetReceptionConfirmed(byte packid,byte packH){ + System.out.println("packetReceptionConfirmed"); + handler.removeCallbacks(task); + task = new A3(keyid,packid,packH); + handler.post(task); + } + + public boolean uploadMessage(byte[] datas){ + System.out.println("uploadMsgData" + datas); + if(datas != null){ + length = datas.length ; + filename = null ; + this.datas = new byte[length ]; + System.arraycopy(datas,0,this.datas,0,length); +// datas[length] = 0x13 ; +// datas[length + 1] = 0x0 ; +// datas[length + 2] = 0x10 ; +// datas[length + 3] = 0x0 ; + task = new A0(filename,length); + handler.removeCallbacks(task); + handler.post(task); + return true; + } + return false; + } + + + public void setUploadListener(IUploadListener uploadListener) { + this.uploadListener = uploadListener; + } + + class A0 implements Runnable{ + private int length ; + private String filename; + private int times ; + public A0(String filename,int length){ + this.length = length ; + this.filename = filename; + packTotal = length / 16 + 1; + times = 0 ; + } + + @Override + public void run() { + XPadApi.getInstance().applyFileUpload(this.length,this.filename,PACKTYPE,RFFileUploadModule.index); + } + } + + class A1 implements Runnable{ + + private byte[] keyid; + private byte packid ; + private byte packH ; + private byte packL ; + private byte[] names ; + private int times ; + + public A1(byte[] keyid, byte packid,byte packH,byte packL,byte[] names) { + this.keyid = keyid; + this.packid = packid; + this.packH = packH ; + this.packL = packL ; + this.names = names ; + times = 0 ; + } + + @Override + public void run() { + XPadApi.getInstance().packetConfirmation(this.keyid,this.packid,this.packH,this.packL,this.names,PACKTYPE); + times ++ ; + if(task != null && times < 5){ + handler.postDelayed(task,1000); + } + if(uploadListener != null){ + uploadListener.onUploadStart(); + } + + handler.removeCallbacks(failCall); + handler.postDelayed(failCall,10000); + } + } + + class A2 implements Runnable{ + private byte[] keyid; + private byte packid; + private byte packH; + private byte[] datas ; + private byte[] packLs; + private int times ; + + public A2(byte[] keyid, byte packid, byte packH, byte[] datas, byte[] packLs) { + this.keyid = keyid; + this.packid = packid; + this.packH = packH; + this.datas = datas; + this.packLs = packLs; + times = 0 ; + } + + @Override + public void run() { + + int packLsi = packLs[1] * 256 + packLs[0]; + int offset = 0 ; + int length = 16; + System.out.println("packLsi:" + packLsi); + for(byte packL = 0 ;packL < 16 ;packL ++) { + if((packLsi & (1 << packL)) != 0){ + offset = ((packid * 65535) + (packH) * 256 + 16 * (packL)) & 0xFFFF; + XPadApi.getInstance().uploadFileData(this.keyid, this.packid, this.packH, (byte)(packL), this.datas, offset, length,PACKTYPE); + try{ + Thread.sleep(50); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + times ++ ; + if(task != null && times < 5){ + handler.postDelayed(task,1000); + } + handler.removeCallbacks(failCall); + handler.postDelayed(failCall,10000); + } + } + + class A3 implements Runnable{ + private byte[] keyid; + private byte packid ; + private byte packH; + + public A3(byte[] keyid, byte packid, byte packH) { + this.keyid = keyid; + this.packid = packid; + this.packH = packH; + } + + @Override + public void run() { + XPadApi.getInstance().packetReceptionConfirmed(this.keyid,this.packid,this.packH,PACKTYPE); + if(uploadListener != null){ + uploadListener.onUploadStop(); + } + handler.removeCallbacks(failCall); + } + } + + public void onUploadMessage(byte data, byte[] keyid, byte packid, byte packH, byte[] packLs) { + LogUtil.i("RFMessageUploadModule","onUploadMessage:" + data); + if (data == 1) { + setKeyid(keyid); + packetConfirmation(packid); + } + if (data == 2) { + uploadData(packid, packH, packLs); + } + if (data == 3) { + packetReceptionConfirmed(packid, packH); + } + } + + private void removeTask(){ + handler.postDelayed(new Runnable() { + @Override + public void run() { + handler.removeCallbacks(task); + } + },5000); + } + + private Runnable failCall = new Runnable() { + @Override + public void run() { + if(uploadListener != null){ + uploadListener.onFail(); + } + } + }; +} diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/SendPacket.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/logic/SendPacket.java index 20c5c8e..7c7e20d 100644 --- a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/SendPacket.java +++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/logic/SendPacket.java @@ -1,4 +1,4 @@ -package com.sunvote.xpadapi.service; +package com.sunvote.xpadapi.service.logic; public class SendPacket { diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/SenderManager.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/logic/SenderManager.java index cb8b0dd..bd3581b 100644 --- a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/SenderManager.java +++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/logic/SenderManager.java @@ -1,4 +1,4 @@ -package com.sunvote.xpadapi.service; +package com.sunvote.xpadapi.service.logic; import com.sunvote.xpadapi.service.bean.BatchNumberVote; import com.sunvote.xpadapi.service.bean.BatchSingleVote; @@ -160,7 +160,7 @@ public final class SenderManager { public void sendSubmitlAllBatchSingleVote(final OnSender sender) { BatchSingleVote batchSingleVote = new BatchSingleVote(); - batchSingleVote.setAllOk(1); + batchSingleVote.setOk(1); sendBatchSingleVote(batchSingleVote, sender); } @@ -193,7 +193,7 @@ public final class SenderManager { } public void sendBatchNumberVoteOK(final BatchNumberVote batchNumberVote, final OnSender sender) { - batchNumberVote.setAllOk(1); + batchNumberVote.setOk(1); sendBatchNumberVote(batchNumberVote, sender); } diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/SerialManager.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/logic/SerialManager.java index 17cd62d..ac04307 100644 --- a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/SerialManager.java +++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/logic/SerialManager.java @@ -1,4 +1,4 @@ -package com.sunvote.xpadapi.service; +package com.sunvote.xpadapi.service.logic; public final class SerialManager { diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/XpadApiServiceInfoProxyManager.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/logic/XpadApiServiceInfoProxyManager.java index e3962bc..df5e407 100644 --- a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/XpadApiServiceInfoProxyManager.java +++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/logic/XpadApiServiceInfoProxyManager.java @@ -1,5 +1,6 @@ -package com.sunvote.xpadapi.service; +package com.sunvote.xpadapi.service.logic; +import com.sunvote.xpadapi.service.XpadApiService; import com.sunvote.xpadapi.service.bean.BaseInfo; import com.sunvote.xpadapi.service.bean.BaseVoteInfo; import com.sunvote.xpadapi.service.bean.KeypadInfo; @@ -64,6 +65,7 @@ public final class XpadApiServiceInfoProxyManager { private ModelInfoChanageListener modelInfoListener; public void setModelInfo(ModelInfo modelInfo) { + this.modelInfo = modelInfo; if(modelInfoListener != null){ try{ modelInfoListener.onModelInfoChanage(modelInfo); @@ -71,7 +73,6 @@ public final class XpadApiServiceInfoProxyManager { LogUtil.e(TAG,"onModelInfoChanage",ex); } } - this.modelInfo = modelInfo; } public ModelInfo getModelInfo() { @@ -86,6 +87,7 @@ public final class XpadApiServiceInfoProxyManager { private BaseInfoChanageListener baseInfoListener; public void setBaseInfo(BaseInfo baseInfo) { + this.baseInfo = baseInfo; if(baseInfoListener != null){ try { baseInfoListener.onBaseInfoChange(baseInfo); @@ -93,7 +95,7 @@ public final class XpadApiServiceInfoProxyManager { LogUtil.e(TAG,"onBaseInfoChange",ex); } } - this.baseInfo = baseInfo; + } public BaseInfo getBaseInfo() { @@ -108,6 +110,7 @@ public final class XpadApiServiceInfoProxyManager { private BaseVoteInfoChanageListener baseVoteInfoListener; public void setBaseVoteInfo(BaseVoteInfo baseVoteInfo) { + this.baseVoteInfo = baseVoteInfo; if(baseVoteInfoListener != null){ try { baseVoteInfoListener.onBaseVoteInfoListener(baseVoteInfo); @@ -115,7 +118,7 @@ public final class XpadApiServiceInfoProxyManager { LogUtil.e(TAG,"onBaseVoteInfoListener",ex); } } - this.baseVoteInfo = baseVoteInfo; + } public BaseVoteInfo getBaseVoteInfo() { @@ -130,6 +133,7 @@ public final class XpadApiServiceInfoProxyManager { private KeyPadinfoChanageListener keyPadinfoChanageListener; public void setKeypadInfo(KeypadInfo keypadInfo) { + this.keypadInfo = keypadInfo; if(keyPadinfoChanageListener != null){ try{ keyPadinfoChanageListener.onKeyPadinfoChanage(keypadInfo); @@ -137,7 +141,7 @@ public final class XpadApiServiceInfoProxyManager { LogUtil.e(TAG,"onKeyPadinfoChanage",ex); } } - this.keypadInfo = keypadInfo; + } public KeypadInfo getKeypadInfo() { @@ -155,6 +159,7 @@ public final class XpadApiServiceInfoProxyManager { private OnlineInfoChanageListener onlineInfoChanageListener; public void setOnLineInfo(OnLineInfo onLineInfo) { + this.onLineInfo = onLineInfo; if(onlineInfoChanageListener != null){ try{ onlineInfoChanageListener.onOnlineInfoChanage(onLineInfo); @@ -162,7 +167,6 @@ public final class XpadApiServiceInfoProxyManager { LogUtil.e(TAG,"onOnlineInfoChanage",ex); } } - this.onLineInfo = onLineInfo; } public OnLineInfo getOnLineInfo() { diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/util/LogUtil.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/util/LogUtil.java deleted file mode 100644 index 4dc7d4c..0000000 --- a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/util/LogUtil.java +++ /dev/null @@ -1,316 +0,0 @@ -package com.sunvote.xpadapi.util; - -import android.os.Environment; -import android.util.Log; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.text.SimpleDateFormat; -import java.util.Date; - -public class LogUtil { - - private static FileWriter fileWriter; - - public static final int VERBOSE_LEVER = 2; - public static final int DEBUG_LEVER = 3; - public static final int INFO_LEVER = 4; - public static final int WARN_LEVER = 5; - public static final int ERROR_LEVER = 6; - public static final int ASSERT_LEVER = 7; - - public static int lever = VERBOSE_LEVER - 1 ; - - private static boolean logToFile = false; - private static boolean logToLogcat = true ; - - private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH.mm.ss.SSS"); - - LogUtil() { - throw new RuntimeException("Stub!"); - } - - public static int v(String tag, String msg) { - if (VERBOSE_LEVER > lever) { - if(logToLogcat){ - Log.v(tag, msg); - } - inputToFile("(V):" + msg ); - } - return -1; - } - - private static void init(){ - if(fileWriter == null){ - synchronized (LogUtil.class) { - if(fileWriter == null) { - try { - File path = new File(Environment.getExternalStorageDirectory().getPath() + "/sunvote/log"); - if (!path.exists()) { - path.mkdirs(); - } - File file = new File(Environment.getExternalStorageDirectory().getPath() - + "/sunvote/log/" + simpleDateFormat.format(new Date())+".txt"); - if (!file.exists()) { - file.createNewFile(); - } - fileWriter = new FileWriter(file, true); - - } catch (Exception ex) { - ex.printStackTrace(); - fileWriter = null; - } - } - } - } - } - - public static void enableLogToFile(){ - logToFile = true; - } - - public static void disabelLogToFile(){ - logToFile = false; - } - - public static void enableLogToLogcat(){ - logToLogcat = true; - } - - public static void disableLogToLogcat(){ - logToLogcat = false; - } - - public static void enableLog(){ - lever = VERBOSE_LEVER - 1; - } - - public static void disableLog(){ - lever = ASSERT_LEVER ; - } - - public static int v(String tag, String msg, Throwable tr) { - if(VERBOSE_LEVER > lever){ - if(logToLogcat) { - Log.v(tag, msg, tr); - } - inputToFile("(V):" + msg + Log.getStackTraceString(tr)); - } - return -1; - } - - public static int d(String tag, String msg) { - if(DEBUG_LEVER > lever){ - if(logToLogcat) { - Log.d(tag, msg); - } - inputToFile("(D):" + msg ); - } - return -1; - } - - public static int d(String tag, String msg, Throwable tr) { - if(DEBUG_LEVER > lever){ - if(logToLogcat){ - Log.d(tag,msg,tr); - } - inputToFile("(D):" + msg + Log.getStackTraceString(tr)); - } - return -1; - } - - public static int i(String tag, String msg) { - if(INFO_LEVER > lever){ - if(logToLogcat){ - Log.i(tag,msg); - } - inputToFile("(I):" + msg ); - } - return -1; - } - - public static int i(String tag, String msg, Throwable tr) { - if(INFO_LEVER > lever){ - if(logToLogcat){ - Log.i(tag,msg,tr); - } - inputToFile("(I):" + msg + Log.getStackTraceString(tr)); - } - return -1; - } - - public static int i(String tag,byte[] msg){ - String msgStr = ByteUtils.bytesToHexString(msg); - return i(tag,msgStr); - } - - public static int i(String tag,String msgTag, byte[] msg){ - String msgStr = ByteUtils.bytesToHexString(msg); - return i(tag,msgTag + ":\r\n" + msgStr); - } - - public static int v(String tag,String msgTag, byte[] msg){ - String msgStr = ByteUtils.bytesToHexString(msg); - return v(tag,msgTag + ":\r\n" + msgStr); - } - - public static int i(String tag,String msgTag, byte[] msg,int length){ - String msgStr = ByteUtils.bytesToHexString(msg,length); - return i(tag,msgTag + ":\r\n" + msgStr); - } - - public static int v(String tag,String msgTag, byte[] msg,int length){ - String msgStr = ByteUtils.bytesToHexString(msg,length); - return v(tag,msgTag + ":\r\n" + msgStr); - } - - public static int i(String tag,byte[] msg,Throwable tr){ - String msgStr = ByteUtils.bytesToHexString(msg); - return i(tag,msgStr,tr); - } - - public static int i(String tag,String msgTag,byte[] msg,Throwable tr){ - String msgStr = ByteUtils.bytesToHexString(msg); - return i(tag,msgTag + ":\r\n" + msgStr,tr); - } - - public static int w(String tag, String msg) { - if(WARN_LEVER > lever){ - if(logToLogcat){ - Log.w(tag,msg); - } - inputToFile("(V):" + msg); - } - return -1; - } - - public static int w(String tag, String msg, Throwable tr) { - if(WARN_LEVER > lever){ - if(logToLogcat){ - Log.w(tag,msg,tr); - } - inputToFile("(W):" + msg + Log.getStackTraceString(tr)); - } - return -1; - } - - public static boolean isLoggable(String s, int i){ - return Log.isLoggable(s,i); - } - - public static int w(String tag, Throwable tr) { - if(WARN_LEVER > lever){ - if(logToLogcat){ - Log.w(tag,tr); - } - inputToFile("(W):" + Log.getStackTraceString(tr)); - } - return -1; - } - - public static int e(String tag, String msg) { - if(ERROR_LEVER > lever){ - if(logToLogcat){ - Log.e(tag,msg); - } - inputToFile("(E):" + msg); - } - return -1; - } - - public static int e(String tag,Throwable tr){ - String message = "ERROR" ; - if(tr != null && tr.getMessage() != null){ - message = tr.getMessage(); - } - return e(tag,message,tr); - } - - public static int e(String tag, String msg, Throwable tr) { - if(ERROR_LEVER > lever){ - if(logToLogcat){ - Log.e(tag,msg,tr); - } - inputToFile("(E):" + msg + Log.getStackTraceString(tr)); - } - return -1; - } - - public static int wtf(String tag, String msg) { - if(ASSERT_LEVER > lever){ - if(logToLogcat){ - Log.wtf(tag,msg); - } - inputToFile("(WTF):" + msg); - } - return -1; - } - - public static int wtf(String tag, Throwable tr) { - if(ASSERT_LEVER > lever){ - if(logToLogcat){ - Log.wtf(tag,tr); - } - inputToFile("(WTF):" + Log.getStackTraceString(tr)); - } - return -1; - } - - public static int wtf(String tag, String msg, Throwable tr) { - if(ASSERT_LEVER > lever){ - if(logToLogcat){ - Log.wtf(tag,msg,tr); - } - inputToFile("(WTF):" + msg + Log.getStackTraceString(tr)); - } - return -1; - } - - public static String getStackTraceString(Throwable tr) { - return Log.getStackTraceString(tr); - } - - - public static void stack(){ - Throwable throwable = new Throwable(); - // 需要处理TAG 要读出上面class method的信息,后续添上 - i("STACK",getStackTraceString(throwable)); - } - - private synchronized static void inputToFile(String msg){ - if(logToFile) { - String time = simpleDateFormat.format(new Date()); - try { - init(); - String log = time + "(" + Thread.currentThread().getName() + ",id=" + Thread.currentThread().getId() + ")" + msg + "\r\n"; - if(onLogMessage != null){ - onLogMessage.onLog(time + ":" + msg + "\r\n"); - } - fileWriter.write(log); - fileWriter.flush(); - } catch (Exception ex) { - ex.printStackTrace(); - if(fileWriter != null){ - try { - fileWriter.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - fileWriter = null; - } - } - } - - private static OnLogMessage onLogMessage; - - public static void setOnLogMessage(OnLogMessage onLogMessage) { - LogUtil.onLogMessage = onLogMessage; - } - - public static interface OnLogMessage{ - void onLog(String log); - } -} - diff --git a/C5/xpadprotocal/build/libs/xpadprotocal.jar b/C5/xpadprotocal/build/libs/xpadprotocal.jar new file mode 100644 index 0000000..d4ff4a9 --- /dev/null +++ b/C5/xpadprotocal/build/libs/xpadprotocal.jar diff --git a/C5/xpadprotocal/build/tmp/jar/MANIFEST.MF b/C5/xpadprotocal/build/tmp/jar/MANIFEST.MF new file mode 100644 index 0000000..59499bc --- /dev/null +++ b/C5/xpadprotocal/build/tmp/jar/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 +