Commit 9e36c27071f2104f922130d0313073a5e056c12a

Authored by 孙向锦
1 parent 6d9503bc

添加服务的关闭与开启

Showing 23 changed files with 1123 additions and 359 deletions
C5/app/src/main/java/com/sunvote/xpadapp/MainActivity.java
... ... @@ -1236,6 +1236,23 @@ public class MainActivity extends BaseActivity implements ComListener {
1236 1236 mBaseInfo = info;
1237 1237 LogUtil.i(TAG, "baseEvent:" + info);
1238 1238 meetingId = info.confId;
  1239 + //attrib bit 6 1 表示服务可以申请,0,表示服务关闭
  1240 + if((mBaseInfo.attrib & 0x20) != 0){
  1241 + runOnUiThread(new Runnable() {
  1242 + @Override
  1243 + public void run() {
  1244 + service.setVisibility(View.VISIBLE);
  1245 +
  1246 + }
  1247 + });
  1248 + }else{
  1249 + runOnUiThread(new Runnable() {
  1250 + @Override
  1251 + public void run() {
  1252 + service.setVisibility(View.GONE);
  1253 + }
  1254 + });
  1255 + }
1239 1256 if (info.confId != 0) {
1240 1257 if (dbm != null && dbm.confId != info.confId) {
1241 1258 dbm.closeDB();
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/XpadApiService.java
... ... @@ -5,38 +5,39 @@ import android.content.BroadcastReceiver;
5 5 import android.content.Context;
6 6 import android.content.Intent;
7 7 import android.content.IntentFilter;
8   -import android.hardware.usb.UsbManager;
9 8 import android.os.Handler;
10 9 import android.os.HandlerThread;
11 10 import android.os.IBinder;
12 11  
13   -import com.sunvote.udptransfer.UDPModule;
14 12 import com.sunvote.udptransfer.stream.SunVoteInputStream;
15 13 import com.sunvote.udptransfer.work.BaseStationProcessWork;
16 14 import com.sunvote.udptransfer.work.RepeatMessageManager;
17 15 import com.sunvote.udptransfer.work.SDKProcessWork;
  16 +import com.sunvote.util.LogUtil;
18 17 import com.sunvote.xpadapi.ISunvoteApi;
19   -import com.sunvote.xpadapi.service.bean.HeartBeat;
20   -import com.sunvote.xpadapi.service.bean.Packet;
21   -import com.sunvote.xpadapi.service.listener.OnDataReceiver;
22 18 import com.sunvote.xpadapi.service.bean.BaseInfo;
23 19 import com.sunvote.xpadapi.service.bean.BaseVoteInfo;
  20 +import com.sunvote.xpadapi.service.bean.HeartBeat;
24 21 import com.sunvote.xpadapi.service.bean.KeypadInfo;
25 22 import com.sunvote.xpadapi.service.bean.ModelInfo;
26 23 import com.sunvote.xpadapi.service.bean.OnLineInfo;
  24 +import com.sunvote.xpadapi.service.bean.Packet;
  25 +import com.sunvote.xpadapi.service.listener.OnDataReceiver;
  26 +import com.sunvote.xpadapi.service.logic.XpadApiServiceInfoProxyManager;
27 27 import com.sunvote.xpadapi.usb.UsbTransferManager;
28 28 import com.sunvote.xpadapi.util.ByteUtils;
29 29 import com.sunvote.xpadapi.util.Cons;
30 30 import com.sunvote.xpadapi.util.Crc16;
31   -import com.sunvote.xpadapi.util.LogUtil;
32 31  
33 32 import java.io.ByteArrayOutputStream;
34   -import java.io.IOException;
35 33 import java.util.ArrayList;
36 34 import java.util.Arrays;
37 35 import java.util.Collections;
38 36 import java.util.List;
39 37  
  38 +/**
  39 + * @Author Elvis
  40 + */
40 41 public class XpadApiService extends Service {
41 42  
42 43 private static final String TAG = XpadApiService.class.getSimpleName();
... ... @@ -52,7 +53,7 @@ public class XpadApiService extends Service {
52 53 try {
53 54 temp.onDataReceiver(datas);
54 55 } catch (Exception ex) {
55   - LogUtil.e(TAG, "onDataReceiver", ex);
  56 + LogUtil.e(TAG, "onDataReceiver" + temp.getClass().getSimpleName(), ex);
56 57 }
57 58 }
58 59 }
... ... @@ -173,19 +174,6 @@ public class XpadApiService extends Service {
173 174  
174 175 };
175 176  
176   - private UsbTransferManager.OnUsbConnectListener connectListener = new UsbTransferManager.OnUsbConnectListener() {
177   - @Override
178   - public boolean onConnect(boolean isConnected) {
179   - if (isConnected) {
180   - //
181   - getKeypadParam();
182   - sleepTimes(100);
183   - getWorkMode();
184   - }
185   - return true;
186   - }
187   - };
188   -
189 177 private Runnable sendTask = new Runnable() {
190 178 @Override
191 179 public void run() {
... ... @@ -309,10 +297,11 @@ public class XpadApiService extends Service {
309 297 }
310 298  
311 299 private void firmUpdateResponse(byte[] datas) {
  300 +
312 301 }
313 302  
314 303 private void voteResultSendResponse(byte[] datas) {
315   -
  304 + // 下层模块收到了,说明不了什么,所以不干什么
316 305 }
317 306  
318 307 private void checkBaseStatusResponse(byte[] datas) {
... ... @@ -583,4 +572,159 @@ public class XpadApiService extends Service {
583 572 sendInnerPacket(packet);
584 573 }
585 574  
  575 + public void applyFileUpload(int length, String filename, byte anstype,byte index) {
  576 + byte[] mBuffer = new byte[0x1F + 4];
  577 + Arrays.fill(mBuffer, (byte) 0x0);
  578 + mBuffer[0] = (byte) 0xF5;
  579 + mBuffer[1] = (byte) 0xAA;
  580 + mBuffer[2] = (byte) 0xAA;
  581 + mBuffer[3] = (byte) 0x1F;
  582 + mBuffer[4] = 0x73;
  583 + mBuffer[5] = (byte) 0XFF;// 流水号
  584 + mBuffer[6] = (byte) 0X01;// 流水号
  585 + mBuffer[7] = (byte) 15;// MSGTYPE
  586 + mBuffer[8] = (byte) anstype;// ANSTYPE 添加5 文件上传指令
  587 + mBuffer[9] = index;// 高位
  588 + Packet packet = new Packet();
  589 + packet.setDatas(mBuffer);
  590 + packet.setSendNo(Packet.CommunicationTestMatchNum);
  591 + sendInnerPacket(packet);
  592 + }
  593 +
  594 + public void packetReceptionConfirmed(byte[] keyid, byte packid, byte packH, byte packtype) {
  595 + byte[] mBuffer = new byte[0x1F + 4];
  596 + Arrays.fill(mBuffer, (byte) 0x0);
  597 + mBuffer[0] = (byte) 0xF5;
  598 + mBuffer[1] = (byte) 0xAA;
  599 + mBuffer[2] = (byte) 0xAA;
  600 + mBuffer[3] = (byte) 0x1F;
  601 +
  602 + mBuffer[4] = (byte) 0xA0;
  603 + int keyId = XpadApiServiceInfoProxyManager.getInstance().getKeypadInfo().getKeyId();
  604 + mBuffer[5] = (byte)((keyId >> 8) & 0xFF);
  605 + mBuffer[6] = (byte)((keyId) & 0xFF);
  606 +
  607 + mBuffer[7] = 3;//CMD 3 多包接收完毕应答
  608 + mBuffer[8] = packtype;//PACKTYPE 多包类型
  609 + mBuffer[9] = packid;//数据包标识码
  610 + Packet packet = new Packet();
  611 + packet.setDatas(mBuffer);
  612 + packet.setSendNo(Packet.CommunicationTestMatchNum);
  613 + sendInnerPacket(packet);
  614 + }
  615 +
  616 + public void uploadFileData(byte[] keyid, byte packid, byte packH, byte packL, byte[] datas, byte packtype) {
  617 + uploadFileData(keyid, packid, packH, packL, datas, 0, datas.length, packtype);
  618 + }
  619 +
  620 + /**
  621 + * @param keyid 键盘编号
  622 + * @param packid 包id
  623 + * @param packH 数据段id
  624 + * @param packL 数据片id
  625 + * @param datas 数据
  626 + * @param offset 偏移位置
  627 + * @param length 长度
  628 + * @Auther Elvis
  629 + * 上传数据包(多包应答)
  630 + */
  631 + public void uploadFileData(byte[] keyid, byte packid, byte packH, byte packL, byte[] datas, int offset, int length, byte packtype) {
  632 + LogUtil.i(TAG, "onMutilPacketData packid=" + packid + ",packH=" + packH + ",packL=" + packL + ",offset=" + offset);
  633 + byte[] mBuffer = new byte[0x1F + 4];
  634 + Arrays.fill(mBuffer, (byte) 0x0);
  635 + mBuffer[0] = (byte) 0xF5;
  636 + mBuffer[1] = (byte) 0xAA;
  637 + mBuffer[2] = (byte) 0xAA;
  638 + mBuffer[3] = (byte) 0x1F;
  639 +
  640 + mBuffer[4] = (byte) 0xA0;
  641 + int keyId = XpadApiServiceInfoProxyManager.getInstance().getKeypadInfo().getKeyId();
  642 + mBuffer[5] = (byte)((keyId >> 8) & 0xFF);
  643 + mBuffer[6] = (byte)((keyId) & 0xFF);
  644 +
  645 + mBuffer[7] = 2;//CMD 1 回应多包数据
  646 + mBuffer[8] = packtype;//PACKTYPE 多包类型
  647 + mBuffer[9] = packid;//数据包标识码
  648 + mBuffer[10] = packH;//数据段编号
  649 + mBuffer[11] = packL;//数据片编号
  650 + for (int i = 0; i < length && i < 16 && i < datas.length - offset; i++) {
  651 + mBuffer[12 + i] = datas[offset + i];
  652 + }
  653 + Packet packet = new Packet();
  654 + packet.setDatas(mBuffer);
  655 + packet.setSendNo(Packet.CommunicationTestMatchNum);
  656 + sendInnerPacket(packet);
  657 + }
  658 +
  659 + /**
  660 + * @param packid 包id
  661 + * 多包接收确认(多包接收应答)
  662 + */
  663 + public void packetConfirmation(byte[] keyid, byte packid, byte packH, byte packL, byte[] names, byte packtype) {
  664 + LogUtil.i(TAG, "onMutilPacketRespone packid=" + packid + ",packH=" + packH + ",packL=" + packL + ",names=" + names);
  665 + byte[] mBuffer = new byte[0x1F + 4];
  666 + Arrays.fill(mBuffer, (byte) 0x0);
  667 + mBuffer[0] = (byte) 0xF5;
  668 + mBuffer[1] = (byte) 0xAA;
  669 + mBuffer[2] = (byte) 0xAA;
  670 + mBuffer[3] = (byte) 0x1F;
  671 +
  672 + mBuffer[4] = (byte) 0xA0;
  673 + int keyId = XpadApiServiceInfoProxyManager.getInstance().getKeypadInfo().getKeyId();
  674 + mBuffer[5] = (byte)((keyId >> 8) & 0xFF);
  675 + mBuffer[6] = (byte)((keyId) & 0xFF);
  676 + mBuffer[5] = keyid[0];
  677 + mBuffer[6] = keyid[1];
  678 +
  679 + mBuffer[7] = 1;//CMD 1
  680 + mBuffer[8] = packtype;//PACKTYPE 多包类型
  681 + mBuffer[9] = packid;//数据包标识码
  682 + mBuffer[10] = packH;
  683 + mBuffer[11] = packL;
  684 + if (names != null) {
  685 + for (int i = 0; i < 14 && i < names.length; i++) {
  686 + mBuffer[12 + i] = names[i];
  687 + }
  688 + }
  689 +
  690 + Packet packet = new Packet();
  691 + packet.setDatas(mBuffer);
  692 + packet.setSendNo(Packet.CommunicationTestMatchNum);
  693 + sendInnerPacket(packet);
  694 + }
  695 +
  696 + private void keepFirmMode() {
  697 + byte[] mBuffer = new byte[0x1F + 4];
  698 + Arrays.fill(mBuffer, (byte) 0x0);
  699 + mBuffer[0] = (byte) 0xF5;
  700 + mBuffer[1] = (byte) 0xAA;
  701 + mBuffer[2] = (byte) 0xAA;
  702 + mBuffer[3] = (byte) 10;
  703 +
  704 + mBuffer[4] = 0x78;
  705 + mBuffer[5] = 0x02;
  706 +
  707 + Packet packet = new Packet();
  708 + packet.setDatas(mBuffer);
  709 + packet.setSendNo(Packet.CommunicationTestMatchNum);
  710 + sendInnerPacket(packet);
  711 + }
  712 +
  713 + private void eraseFlash(int fileLen) {
  714 + byte[] mBuffer = new byte[0x1F + 4];
  715 + Arrays.fill(mBuffer, (byte) 0x0);
  716 + mBuffer[0] = (byte) 0xF5;
  717 + mBuffer[1] = (byte) 0xAA;
  718 + mBuffer[2] = (byte) 0xAA;
  719 + mBuffer[3] = (byte) 10;
  720 + mBuffer[4] = 0x78;
  721 + mBuffer[5] = 0x03;
  722 + mBuffer[6] = 0;
  723 + mBuffer[7] = (byte) (fileLen / 1024);
  724 +
  725 + Packet packet = new Packet();
  726 + packet.setDatas(mBuffer);
  727 + packet.setSendNo(Packet.CommunicationTestMatchNum);
  728 + sendInnerPacket(packet);
  729 + }
586 730 }
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/BatchNumberVote.java
1 1 package com.sunvote.xpadapi.service.bean;
2 2  
3   -import com.sunvote.xpadapi.service.SerialManager;
  3 +import com.sunvote.xpadapi.service.logic.SerialManager;
4 4  
5 5 import java.util.Arrays;
6 6  
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/BatchSingleVote.java
1 1 package com.sunvote.xpadapi.service.bean;
2 2  
3   -import com.sunvote.xpadapi.service.SerialManager;
  3 +import com.sunvote.xpadapi.service.logic.SerialManager;
4 4  
5 5 import java.util.Arrays;
6 6  
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/LoginInVote.java
1 1 package com.sunvote.xpadapi.service.bean;
2 2  
3   -import com.sunvote.xpadapi.service.SerialManager;
  3 +import com.sunvote.xpadapi.service.logic.SerialManager;
4 4  
5 5 import java.util.Arrays;
6 6  
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/NumberVote.java
1 1 package com.sunvote.xpadapi.service.bean;
2 2  
3   -import com.sunvote.xpadapi.service.SerialManager;
  3 +import com.sunvote.xpadapi.service.logic.SerialManager;
4 4  
5 5 import java.util.Arrays;
6 6  
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/SelectOtherVote.java
1 1 package com.sunvote.xpadapi.service.bean;
2 2  
3   -import com.sunvote.xpadapi.service.SerialManager;
4   -import com.sunvote.xpadapi.service.XpadApiServiceInfoProxyManager;
  3 +import com.sunvote.xpadapi.service.logic.SerialManager;
  4 +import com.sunvote.xpadapi.service.logic.XpadApiServiceInfoProxyManager;
5 5 import com.sunvote.xpadapi.util.LogUtil;
6 6  
7 7 import java.util.Arrays;
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/SelectVote.java
1 1 package com.sunvote.xpadapi.service.bean;
2 2  
3   -import com.sunvote.xpadapi.service.SerialManager;
  3 +import com.sunvote.xpadapi.service.logic.SerialManager;
4 4  
5 5 import java.util.Arrays;
6 6  
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/ServiceTypeVote.java
1 1 package com.sunvote.xpadapi.service.bean;
2 2  
3   -import com.sunvote.xpadapi.service.SerialManager;
  3 +import com.sunvote.xpadapi.service.logic.SerialManager;
4 4  
5 5 import java.util.Arrays;
6 6  
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/SingleVote.java
1 1 package com.sunvote.xpadapi.service.bean;
2 2  
3   -import com.sunvote.xpadapi.service.SerialManager;
  3 +import com.sunvote.xpadapi.service.logic.SerialManager;
4 4  
5 5 import java.util.Arrays;
6 6  
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/Vote.java
1 1 package com.sunvote.xpadapi.service.bean;
2 2  
3   -import com.sunvote.xpadapi.service.SerialManager;
  3 +import com.sunvote.xpadapi.service.logic.SerialManager;
4 4  
5 5 import java.util.Arrays;
6 6  
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/AbsDownloadProcess.java 0 → 100644
  1 +package com.sunvote.xpadapi.service.listener;
  2 +
  3 +import java.io.File;
  4 +import java.io.IOException;
  5 +
  6 +/**
  7 + * Created by Elvis on 2018/3/20 11:18
  8 + * Email:Eluis@psunsky.com
  9 + * 版权所有:长沙中天电子设计开发有限公司
  10 + * Description: 人大通用版XPadAppRendaMac
  11 + */
  12 +
  13 +public abstract class AbsDownloadProcess {
  14 +
  15 + private static String foldPath = "/sdcard/Sunvote/download/";
  16 +
  17 + protected static String fileName = "default.obj";
  18 +
  19 + private long length ;
  20 + private long curComplete = 0 ;
  21 +
  22 + private static File file ;
  23 +
  24 + public File getFile() {
  25 + if(file == null){
  26 + curComplete = 0 ;
  27 + File folder = new File(foldPath);
  28 + if(!folder.exists()){
  29 + folder.mkdirs();
  30 + }
  31 + if(fileName == null || "".equals(fileName.trim())){
  32 + fileName = "default.obj" ;
  33 + }
  34 + file = new File(foldPath , fileName);
  35 + file.deleteOnExit();
  36 + if(!file.exists()){
  37 + try {
  38 + file.createNewFile();
  39 + } catch (IOException e) {
  40 + onDownloadError(e);
  41 + }
  42 + }
  43 + }
  44 + return file;
  45 + }
  46 +
  47 + protected long getLength() {
  48 + return length;
  49 + }
  50 +
  51 + public String getFoldPath() {
  52 + return foldPath;
  53 + }
  54 +
  55 + protected void setLength(long length) {
  56 + this.length = length;
  57 + curComplete = 0 ;
  58 + }
  59 +
  60 + public void setFileName(String fileName) {
  61 + if(!(fileName == null || "".equals(fileName.trim()))) {
  62 + this.fileName = fileName;
  63 + file = null;
  64 + }
  65 + }
  66 +
  67 + protected String getFileName() {
  68 + return fileName;
  69 + }
  70 +
  71 + public void setFoldPath(String foldPath) {
  72 + this.foldPath = foldPath;
  73 + }
  74 +
  75 + protected void onStartDownload(){
  76 + onStartDownload(getFile(),getLength());
  77 + }
  78 +
  79 + public abstract void onStartDownload(File file,long length);
  80 +
  81 + protected void onDownloadAddProcess(int curPack) {
  82 + curComplete += curPack;
  83 + double result = 0;
  84 + if(curComplete <= length){
  85 + result = (double)curComplete / length ;
  86 + }else{
  87 + result = 1;
  88 + }
  89 +
  90 + try{
  91 + onDownloadProcess(result);
  92 + }catch (Exception ex){
  93 + ex.printStackTrace();
  94 + }
  95 + try{
  96 + int ri = (int)(result * 100);
  97 + onDownloadProcess(ri + "%");
  98 + }catch (Exception ex){
  99 + ex.printStackTrace();
  100 + }
  101 + }
  102 +
  103 + public abstract void onDownloadProcess(double process);
  104 +
  105 + public abstract void onDownloadProcess(String process);
  106 +
  107 + protected void onStopDownload(){
  108 + onStopDownload(getFile());
  109 + }
  110 +
  111 + public abstract void onStopDownload(File file);
  112 +
  113 + public abstract void onDownloadError(Exception e);
  114 +
  115 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/IUploadListener.java 0 → 100644
  1 +package com.sunvote.xpadapi.service.listener;
  2 +
  3 +/**
  4 + * Created by Elvis on 2018/3/22 13:43
  5 + * Email:Eluis@psunsky.com
  6 + * 版权所有:长沙中天电子设计开发有限公司
  7 + * Description: 人大通用版XPadAppRendaMac
  8 + */
  9 +public interface IUploadListener {
  10 +
  11 + public void onUploadStart();
  12 +
  13 + public void onUploadProcess(double process);
  14 +
  15 + public void onUploadStop();
  16 +
  17 + public void onFail();
  18 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/logic/RFFileDownloadModule.java 0 → 100644
  1 +package com.sunvote.xpadapi.service.logic;
  2 +
  3 +import android.os.Handler;
  4 +import android.os.Looper;
  5 +
  6 +import com.sunvote.util.LogUtil;
  7 +import com.sunvote.xpadapi.service.listener.AbsDownloadProcess;
  8 +
  9 +import java.io.File;
  10 +
  11 +/**
  12 + * Created by Elvis on 2018/3/20 11:16
  13 + * Email:Eluis@psunsky.com
  14 + * 版权所有:长沙中天电子设计开发有限公司
  15 + * Description: 文件下载模块
  16 + */
  17 +public class RFFileDownloadModule {
  18 +
  19 + private RFFileDownloadModule(){
  20 + handler = new Handler(Looper.getMainLooper());
  21 + }
  22 + private Handler handler ;
  23 + private long overtime = 15 * 1000 ;
  24 + private static RFFileDownloadModule instance = new RFFileDownloadModule();
  25 +
  26 + public static RFFileDownloadModule getInstance() {
  27 + return instance;
  28 + }
  29 +
  30 + private AbsDownloadProcess downloadProcess;
  31 + private AbsDownloadProcess tdownloadProcess = new AbsDownloadProcess() {
  32 +
  33 + private boolean start = false;
  34 + private double process = 0 ;
  35 + private Runnable runnable = new Runnable() {
  36 + @Override
  37 + public void run() {
  38 + onDownloadError(new Exception("overtime"));
  39 + }
  40 + };
  41 +
  42 + @Override
  43 + public void onStartDownload(File file, long length) {
  44 + start = true;
  45 + process = 0;
  46 + LogUtil.i("onStartDownload", file.getName() + "," + length);
  47 + if(downloadProcess != null){
  48 + downloadProcess.onStartDownload(file,length);
  49 + }
  50 + handler.removeCallbacks(runnable);
  51 + handler.postDelayed(runnable,overtime);
  52 + }
  53 +
  54 + @Override
  55 + public void onDownloadProcess(double process) {
  56 + this.process = process;
  57 + LogUtil.i("onDownloadProcess", "process," + process);
  58 + if(downloadProcess != null && start){
  59 + downloadProcess.onDownloadProcess(process);
  60 + }
  61 + handler.removeCallbacks(runnable);
  62 + handler.postDelayed(runnable,overtime);
  63 + }
  64 +
  65 + @Override
  66 + public void onDownloadProcess(String process) {
  67 + LogUtil.i("onDownloadProcess", "process," + process);
  68 + if(downloadProcess != null && start){
  69 + downloadProcess.onDownloadProcess(process);
  70 + }
  71 + handler.removeCallbacks(runnable);
  72 + handler.postDelayed(runnable,overtime);
  73 + }
  74 +
  75 + @Override
  76 + public void onStopDownload(File file) {
  77 + LogUtil.i("onStopDownload", "process," + file.getName());
  78 + if(downloadProcess != null && start){
  79 + if(process >= 1.0){
  80 + downloadProcess.onStopDownload(file);
  81 + }else{
  82 + downloadProcess.onDownloadError(new Exception("file download error"));
  83 + }
  84 + }
  85 + start = false;
  86 + handler.removeCallbacks(runnable);
  87 + file.deleteOnExit();
  88 + }
  89 +
  90 + @Override
  91 + public void onDownloadError(Exception e) {
  92 + LogUtil.i("onStopDownload", "error", e);
  93 + if(downloadProcess != null && start){
  94 + downloadProcess.onDownloadError(e);
  95 + }
  96 + start = false;
  97 + handler.removeCallbacks(runnable);
  98 + }
  99 + };
  100 +
  101 + public void setOvertime(long overtime) {
  102 + if(overtime > 0){
  103 + this.overtime = overtime;
  104 + }
  105 + }
  106 +
  107 + public synchronized void registerDownloadProcess(AbsDownloadProcess downloadProcess){
  108 + this.downloadProcess = downloadProcess ;
  109 + }
  110 +
  111 + public synchronized void unRegisterDownloadProcess(AbsDownloadProcess downloadProcess){
  112 + this.downloadProcess = null;
  113 + }
  114 +
  115 + protected synchronized AbsDownloadProcess getDownloadProcess() {
  116 +
  117 + return tdownloadProcess;
  118 + }
  119 +
  120 +
  121 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/logic/RFFileUploadModule.java 0 → 100644
  1 +package com.sunvote.xpadapi.service.logic;
  2 +
  3 +import android.os.Handler;
  4 +import android.os.HandlerThread;
  5 +
  6 +import com.sunvote.util.LogUtil;
  7 +import com.sunvote.xpadapi.service.listener.IUploadListener;
  8 +
  9 +import java.io.File;
  10 +import java.io.FileInputStream;
  11 +import java.io.IOException;
  12 +import java.io.UnsupportedEncodingException;
  13 +
  14 +/**
  15 + * Created by Elvis on 2018/3/21 16:13
  16 + * Email:Eluis@psunsky.com
  17 + * 版权所有:长沙中天电子设计开发有限公司
  18 + * Description: 文件上传模块
  19 + */
  20 +public class RFFileUploadModule {
  21 +
  22 + public static final byte PACKTYPE = 5 ;
  23 + public static final int SLEEP_TIME = 25 ;
  24 + public static byte index = 0 ;
  25 + private RFFileUploadModule(){
  26 + handlerThread = new HandlerThread(RFFileUploadModule.class.getSimpleName());
  27 + handlerThread.start();
  28 + handler = new Handler(handlerThread.getLooper());
  29 + }
  30 +
  31 + private static RFFileUploadModule instance ;
  32 +
  33 + public static RFFileUploadModule getInstance() {
  34 + if(instance == null){
  35 + synchronized (RFFileUploadModule.class){
  36 + if(instance == null){
  37 + instance = new RFFileUploadModule();
  38 + }
  39 + }
  40 + }
  41 + return instance;
  42 + }
  43 +
  44 + private IUploadListener uploadListener = new IUploadListener() {
  45 + @Override
  46 + public void onUploadStart() {
  47 + System.out.println("onUploadStart");
  48 + }
  49 +
  50 + @Override
  51 + public void onUploadProcess(double process) {
  52 + System.out.println("onUploadProcess:" + process);
  53 + }
  54 +
  55 + @Override
  56 + public void onUploadStop() {
  57 + System.out.println("onUploadStop");
  58 + }
  59 +
  60 + @Override
  61 + public void onFail() {
  62 + System.out.println("onFail");
  63 + }
  64 + };
  65 +
  66 +
  67 + private String filename;
  68 + private byte[] datas = new byte[1024];
  69 + private int length = 1024;
  70 + private HandlerThread handlerThread ;
  71 + private Handler handler ;
  72 + private byte[] keyid = new byte[2];
  73 + private Runnable task;
  74 + private int packTotal ;
  75 + private boolean isStop = false ;
  76 +
  77 + /**
  78 + * 文件名不能超过16个字符(中文不能超过8个),超过16个字符将会出现截断。
  79 + * 文件长度不能超过65535个字节
  80 + * @param file 文件
  81 + * @return 是否成功发起上传
  82 + */
  83 + public boolean uploadFile(File file){
  84 + LogUtil.i("RFFileUploadModule","uploadFile" + file);
  85 + if(file != null){
  86 + length = (int)file.length();
  87 + filename = file.getName();
  88 + datas = new byte[length+4];
  89 + FileInputStream fis = null ;
  90 + try {
  91 + fis = new FileInputStream(file);
  92 + int start = 0 ;
  93 + // 把文件数据读入字节数组。
  94 + while(start < length){
  95 + int ret = fis.read(datas,start,length-start);
  96 + if(ret < 0){
  97 + break;
  98 + }
  99 + start += ret ;
  100 + }
  101 + datas[length] = 0x13 ;
  102 + datas[length + 1] = 0x0 ;
  103 + datas[length + 2] = 0x10 ;
  104 + datas[length + 3] = 0x0 ;
  105 +
  106 + if(start >= length){
  107 + task = new A0(filename,length);
  108 + handler.removeCallbacks(task);
  109 + handler.post(task);
  110 + return true;
  111 + }
  112 +
  113 + } catch (Exception e) {
  114 + e.printStackTrace();
  115 + }finally {
  116 + if(fis != null){
  117 + try {
  118 + fis.close();
  119 + } catch (IOException e) {
  120 + e.printStackTrace();
  121 + }
  122 + fis = null;
  123 + }
  124 + }
  125 + }
  126 + return false;
  127 + }
  128 +
  129 + public void setKeyid(byte[] keyid) {
  130 + setKeyid(keyid,0);
  131 + }
  132 + public void setKeyid(byte[] keyid,int start) {
  133 + this.keyid[0] = keyid[start];
  134 + this.keyid[1] = keyid[start+1];
  135 + }
  136 +
  137 + public void onUploadFile(byte data, byte[] keyid, byte packid, byte packH, byte[] packLs) {
  138 + if (data == 1) {
  139 + setKeyid(keyid);
  140 + packetConfirmation(packid);
  141 + }
  142 + if (data == 2) {
  143 + uploadData(packid, packH, packLs);
  144 + }
  145 + if (data == 3) {
  146 + packetReceptionConfirmed(packid, packH);
  147 + }
  148 + }
  149 +
  150 + public void uploadData(byte packid, byte packH, byte[] packLs){
  151 + System.out.println("uploadData");
  152 + handler.removeCallbacks(task);
  153 + if(task instanceof A2){
  154 + ((A2)task).setStop(true);
  155 + }
  156 + task = new A2(keyid,packid,packH,datas,packLs);
  157 + handler.post(task);
  158 + if(uploadListener != null){
  159 + double process = 0 ;
  160 + if(packTotal > 0){
  161 + int count = 0 ;
  162 + int sen = (packLs[1] & 0xFF) * 256 + (packLs[0] & 0XFF);
  163 + for(int i = 0 ; i < 16 ; i++){
  164 + if((sen & (1 << i)) == 0){
  165 + count ++ ;
  166 + }
  167 + }
  168 + int been = packH * 16 + count ;
  169 + if(been > packTotal){
  170 + been = packTotal ;
  171 + }
  172 + process = (double)(been) / packTotal ;
  173 + }
  174 + uploadListener.onUploadProcess(process);
  175 + }
  176 + }
  177 +
  178 + public void packetConfirmation(byte packid){
  179 + System.out.println("packetConfirmation");
  180 + handler.removeCallbacks(task);
  181 + byte[] names = null;
  182 + if(filename != null){
  183 + try {
  184 + names = filename.getBytes("GB2312");
  185 + } catch (UnsupportedEncodingException e) {
  186 + e.printStackTrace();
  187 + }
  188 + }
  189 + task = new A1(keyid,(byte)((length + 4 ) / 65535), (byte)(((length + 4) % 65535) / 256),(byte)((length + 4) % 256),names);
  190 + handler.post(task);
  191 + }
  192 +
  193 + public void packetReceptionConfirmed(byte packid,byte packH){
  194 + System.out.println("packetReceptionConfirmed");
  195 + handler.removeCallbacks(task);
  196 + task = new A3(keyid,packid,packH);
  197 + handler.post(task);
  198 + }
  199 +
  200 + public boolean uploadFile(byte[] datas){
  201 + System.out.println("uploadFile" + datas);
  202 + if(datas != null){
  203 + length = datas.length ;
  204 + filename = null ;
  205 + this.datas = new byte[length + 4];
  206 + System.arraycopy(datas,0,this.datas,0,length);
  207 + datas[length] = 0x13 ;
  208 + datas[length + 1] = 0x0 ;
  209 + datas[length + 2] = 0x10 ;
  210 + datas[length + 3] = 0x0 ;
  211 + task = new A0(filename,length);
  212 + handler.removeCallbacks(task);
  213 + handler.post(task);
  214 + return true;
  215 + }
  216 + return false;
  217 + }
  218 +
  219 +
  220 + public void setUploadListener(IUploadListener uploadListener) {
  221 + this.uploadListener = uploadListener;
  222 + }
  223 +
  224 + class A0 implements Runnable{
  225 + private int length ;
  226 + private String filename;
  227 + private int times ;
  228 + public A0(String filename,int length){
  229 + this.length = length ;
  230 + this.filename = filename;
  231 + packTotal = length / 16 + 1;
  232 + times = 0 ;
  233 + index++;
  234 + }
  235 +
  236 + @Override
  237 + public void run() {
  238 + LogUtil.i("RFFileUploadModule","A0 run");
  239 + XpadApiServiceInfoProxyManager.getInstance().getService().applyFileUpload(this.length,this.filename,PACKTYPE,index);
  240 + times ++ ;
  241 + if(task != null && times < 5){
  242 + handler.removeCallbacks(task);
  243 + handler.postDelayed(task,5000);
  244 + }
  245 + }
  246 + }
  247 +
  248 + class A1 implements Runnable{
  249 +
  250 + private byte[] keyid;
  251 + private byte packid ;
  252 + private byte packH ;
  253 + private byte packL ;
  254 + private byte[] names ;
  255 + private int times ;
  256 +
  257 + public A1(byte[] keyid, byte packid,byte packH,byte packL,byte[] names) {
  258 + LogUtil.i("RFFileUploadModule","A1");
  259 + this.keyid = keyid;
  260 + this.packid = packid;
  261 + this.packH = packH ;
  262 + this.packL = packL ;
  263 + this.names = names ;
  264 + times = 0 ;
  265 + }
  266 +
  267 + @Override
  268 + public void run() {
  269 + LogUtil.i("RFFileUploadModule","A1 run");
  270 + XpadApiServiceInfoProxyManager.getInstance().getService().packetConfirmation(this.keyid,this.packid,this.packH,this.packL,this.names,PACKTYPE);
  271 + times ++ ;
  272 + if(task != null && times < 5){
  273 + handler.removeCallbacks(task);
  274 + handler.postDelayed(task,5000);
  275 + }
  276 + if(uploadListener != null){
  277 + uploadListener.onUploadStart();
  278 + isStop = false;
  279 + }
  280 + }
  281 + }
  282 +
  283 + class A2 implements Runnable{
  284 + private byte[] keyid;
  285 + private byte packid;
  286 + private byte packH;
  287 + private byte[] datas ;
  288 + private byte[] packLs;
  289 + private int times ;
  290 + private boolean stop = false;
  291 +
  292 + public void setStop(boolean stop) {
  293 + this.stop = stop;
  294 + }
  295 +
  296 + public A2(byte[] keyid, byte packid, byte packH, byte[] datas, byte[] packLs) {
  297 + LogUtil.i("RFFileUploadModule","A2");
  298 + this.keyid = keyid;
  299 + this.packid = packid;
  300 + this.packH = packH;
  301 + this.datas = datas;
  302 + this.packLs = packLs;
  303 + times = 0 ;
  304 + }
  305 +
  306 + @Override
  307 + public void run() {
  308 + LogUtil.i("RFFileUploadModule","A2 run");
  309 + int packLsi = (packLs[1] & 0xFF) * 256 + (packLs[0] & 0xFF);
  310 + int offset = 0 ;
  311 + int length = 16;
  312 + System.out.println("packLsi:" + packLsi);
  313 + for(byte packL = 0 ;packL < 16 && !stop ;packL ++) {
  314 + if((packLsi & (1 << packL)) != 0){
  315 + offset = ((packid * 65535) + (packH) * 256 + 16 * (packL)) & 0xFFFF;
  316 + XpadApiServiceInfoProxyManager.getInstance().getService().uploadFileData(this.keyid, this.packid, this.packH, (byte)(packL ), this.datas, offset, length,PACKTYPE);
  317 + // need sleep ????
  318 + try{
  319 + Thread.sleep(SLEEP_TIME);
  320 + } catch (Exception e) {
  321 + e.printStackTrace();
  322 + }
  323 + }
  324 + }
  325 +
  326 + times ++ ;
  327 + if(task != null && times < 5){
  328 + handler.removeCallbacks(task);
  329 + handler.postDelayed(task,5000);
  330 + }
  331 + }
  332 + }
  333 +
  334 + class A3 implements Runnable{
  335 + private byte[] keyid;
  336 + private byte packid ;
  337 + private byte packH;
  338 + private int times ;
  339 +
  340 + public A3(byte[] keyid, byte packid, byte packH) {
  341 + LogUtil.i("RFFileUploadModule","A3");
  342 + this.keyid = keyid;
  343 + this.packid = packid;
  344 + this.packH = packH;
  345 + times = 0 ;
  346 + }
  347 +
  348 + @Override
  349 + public void run() {
  350 + LogUtil.i("RFFileUploadModule","A3 run");
  351 + XpadApiServiceInfoProxyManager.getInstance().getService().packetReceptionConfirmed(this.keyid,this.packid,this.packH,PACKTYPE);
  352 + if(uploadListener != null && !isStop){
  353 + isStop = true;
  354 + uploadListener.onUploadStop();
  355 + }
  356 + }
  357 + }
  358 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/logic/RFMessageUploadModule.java 0 → 100644
  1 +package com.sunvote.xpadapi.service.logic;
  2 +
  3 +import android.os.Handler;
  4 +import android.os.HandlerThread;
  5 +
  6 +import java.io.UnsupportedEncodingException;
  7 +
  8 +/**
  9 + * Created by Elvis on 2018/3/27 9:48
  10 + * Email:Eluis@psunsky.com
  11 + * 版权所有:长沙中天电子设计开发有限公司
  12 + * Description: 人大通用版
  13 + * 短消息上传模块
  14 + */
  15 +public class RFMessageUploadModule {
  16 +
  17 + public static final byte PACKTYPE = 3 ;
  18 + private static RFMessageUploadModule instance ;
  19 +
  20 + private IUploadListener uploadListener ;
  21 +
  22 + private String filename;
  23 + private byte[] datas = "test message".getBytes();
  24 + private int length = 1024;
  25 + private HandlerThread handlerThread ;
  26 + private Handler handler ;
  27 + private byte[] keyid;
  28 + private Runnable task;
  29 + private int packTotal ;
  30 + private boolean stop = false;
  31 +
  32 + private RFMessageUploadModule(){
  33 + handlerThread = new HandlerThread(RFMessageUploadModule.class.getSimpleName());
  34 + handlerThread.start();
  35 + handler = new Handler(handlerThread.getLooper());
  36 + }
  37 +
  38 + public static RFMessageUploadModule getInstance() {
  39 + if(instance == null){
  40 + instance = new RFMessageUploadModule();
  41 + }
  42 + return instance;
  43 + }
  44 +
  45 + public void setMessageContent(byte[] messageContent) {
  46 + this.datas = messageContent;
  47 + uploadMsgData(datas);
  48 + removeTask();
  49 + }
  50 +
  51 + public void setMessageContent(String message) {
  52 + try {
  53 + this.datas = message.getBytes("GB2312");
  54 + uploadMsgData(datas);
  55 + removeTask();
  56 + handler.removeCallbacks(failCall);
  57 + handler.postDelayed(failCall,10000);
  58 + } catch (Exception e) {
  59 + e.printStackTrace();
  60 + }
  61 + }
  62 +
  63 + private boolean uploadMsgData(byte[] ds){
  64 + System.out.println("uploadMsgData" + ds);
  65 + if(ds != null){
  66 + length = ds.length ;
  67 + filename = null ;
  68 + this.datas = new byte[length ];
  69 + System.arraycopy(ds,0,this.datas,0,length);
  70 +// this.datas[length] = 0x13 ;
  71 +// this.datas[length + 1] = 0x0 ;
  72 +// this.datas[length + 2] = 0x10 ;
  73 +// this.datas[length + 3] = 0x0 ;
  74 + task = new A0(filename,length);
  75 + handler.removeCallbacks(task);
  76 + handler.post(task);
  77 + return true;
  78 + }
  79 + return false;
  80 + }
  81 +
  82 +
  83 + public void setKeyid(byte[] keyid) {
  84 + this.keyid = keyid;
  85 + }
  86 +
  87 + public void uploadData(byte packid, byte packH, byte[] packLs){
  88 + System.out.println("uploadData");
  89 + handler.removeCallbacks(task);
  90 + task = new A2(keyid,packid,packH,datas,packLs);
  91 + handler.post(task);
  92 + if(uploadListener != null){
  93 + double process = 0 ;
  94 + if(packTotal > 0){
  95 + int count = 0 ;
  96 + int sen = (packLs[1] & 0xFF) * 256 + (packLs[0] & 0XFF);
  97 + for(int i = 0 ; i < 16 ; i++){
  98 + if((sen & (1 << i)) != 0){
  99 + count ++ ;
  100 + }
  101 + }
  102 + process = (double)(packH * 16 + count) / packTotal ;
  103 + }
  104 + uploadListener.onUploadProcess(process);
  105 + }
  106 + }
  107 +
  108 + public void packetConfirmation(byte packid){
  109 + System.out.println("packetConfirmation");
  110 + handler.removeCallbacks(task);
  111 + byte[] names = null;
  112 + if(filename != null){
  113 + try {
  114 + names = filename.getBytes("GB2312");
  115 + } catch (UnsupportedEncodingException e) {
  116 + e.printStackTrace();
  117 + }
  118 + }
  119 + task = new A1(keyid,(byte)((length ) / 65535), (byte)(((length ) % 65535) / 256),(byte)(((length ) % 256 / 16 + (length % 16 == 0 ? 0 : 1))),names);
  120 + handler.post(task);
  121 + }
  122 +
  123 + public void packetReceptionConfirmed(byte packid,byte packH){
  124 + System.out.println("packetReceptionConfirmed");
  125 + handler.removeCallbacks(task);
  126 + task = new A3(keyid,packid,packH);
  127 + handler.post(task);
  128 + }
  129 +
  130 + public boolean uploadMessage(byte[] datas){
  131 + System.out.println("uploadMsgData" + datas);
  132 + if(datas != null){
  133 + length = datas.length ;
  134 + filename = null ;
  135 + this.datas = new byte[length ];
  136 + System.arraycopy(datas,0,this.datas,0,length);
  137 +// datas[length] = 0x13 ;
  138 +// datas[length + 1] = 0x0 ;
  139 +// datas[length + 2] = 0x10 ;
  140 +// datas[length + 3] = 0x0 ;
  141 + task = new A0(filename,length);
  142 + handler.removeCallbacks(task);
  143 + handler.post(task);
  144 + return true;
  145 + }
  146 + return false;
  147 + }
  148 +
  149 +
  150 + public void setUploadListener(IUploadListener uploadListener) {
  151 + this.uploadListener = uploadListener;
  152 + }
  153 +
  154 + class A0 implements Runnable{
  155 + private int length ;
  156 + private String filename;
  157 + private int times ;
  158 + public A0(String filename,int length){
  159 + this.length = length ;
  160 + this.filename = filename;
  161 + packTotal = length / 16 + 1;
  162 + times = 0 ;
  163 + }
  164 +
  165 + @Override
  166 + public void run() {
  167 + XPadApi.getInstance().applyFileUpload(this.length,this.filename,PACKTYPE,RFFileUploadModule.index);
  168 + }
  169 + }
  170 +
  171 + class A1 implements Runnable{
  172 +
  173 + private byte[] keyid;
  174 + private byte packid ;
  175 + private byte packH ;
  176 + private byte packL ;
  177 + private byte[] names ;
  178 + private int times ;
  179 +
  180 + public A1(byte[] keyid, byte packid,byte packH,byte packL,byte[] names) {
  181 + this.keyid = keyid;
  182 + this.packid = packid;
  183 + this.packH = packH ;
  184 + this.packL = packL ;
  185 + this.names = names ;
  186 + times = 0 ;
  187 + }
  188 +
  189 + @Override
  190 + public void run() {
  191 + XPadApi.getInstance().packetConfirmation(this.keyid,this.packid,this.packH,this.packL,this.names,PACKTYPE);
  192 + times ++ ;
  193 + if(task != null && times < 5){
  194 + handler.postDelayed(task,1000);
  195 + }
  196 + if(uploadListener != null){
  197 + uploadListener.onUploadStart();
  198 + }
  199 +
  200 + handler.removeCallbacks(failCall);
  201 + handler.postDelayed(failCall,10000);
  202 + }
  203 + }
  204 +
  205 + class A2 implements Runnable{
  206 + private byte[] keyid;
  207 + private byte packid;
  208 + private byte packH;
  209 + private byte[] datas ;
  210 + private byte[] packLs;
  211 + private int times ;
  212 +
  213 + public A2(byte[] keyid, byte packid, byte packH, byte[] datas, byte[] packLs) {
  214 + this.keyid = keyid;
  215 + this.packid = packid;
  216 + this.packH = packH;
  217 + this.datas = datas;
  218 + this.packLs = packLs;
  219 + times = 0 ;
  220 + }
  221 +
  222 + @Override
  223 + public void run() {
  224 +
  225 + int packLsi = packLs[1] * 256 + packLs[0];
  226 + int offset = 0 ;
  227 + int length = 16;
  228 + System.out.println("packLsi:" + packLsi);
  229 + for(byte packL = 0 ;packL < 16 ;packL ++) {
  230 + if((packLsi & (1 << packL)) != 0){
  231 + offset = ((packid * 65535) + (packH) * 256 + 16 * (packL)) & 0xFFFF;
  232 + XPadApi.getInstance().uploadFileData(this.keyid, this.packid, this.packH, (byte)(packL), this.datas, offset, length,PACKTYPE);
  233 + try{
  234 + Thread.sleep(50);
  235 + } catch (Exception e) {
  236 + e.printStackTrace();
  237 + }
  238 + }
  239 + }
  240 + times ++ ;
  241 + if(task != null && times < 5){
  242 + handler.postDelayed(task,1000);
  243 + }
  244 + handler.removeCallbacks(failCall);
  245 + handler.postDelayed(failCall,10000);
  246 + }
  247 + }
  248 +
  249 + class A3 implements Runnable{
  250 + private byte[] keyid;
  251 + private byte packid ;
  252 + private byte packH;
  253 +
  254 + public A3(byte[] keyid, byte packid, byte packH) {
  255 + this.keyid = keyid;
  256 + this.packid = packid;
  257 + this.packH = packH;
  258 + }
  259 +
  260 + @Override
  261 + public void run() {
  262 + XPadApi.getInstance().packetReceptionConfirmed(this.keyid,this.packid,this.packH,PACKTYPE);
  263 + if(uploadListener != null){
  264 + uploadListener.onUploadStop();
  265 + }
  266 + handler.removeCallbacks(failCall);
  267 + }
  268 + }
  269 +
  270 + public void onUploadMessage(byte data, byte[] keyid, byte packid, byte packH, byte[] packLs) {
  271 + LogUtil.i("RFMessageUploadModule","onUploadMessage:" + data);
  272 + if (data == 1) {
  273 + setKeyid(keyid);
  274 + packetConfirmation(packid);
  275 + }
  276 + if (data == 2) {
  277 + uploadData(packid, packH, packLs);
  278 + }
  279 + if (data == 3) {
  280 + packetReceptionConfirmed(packid, packH);
  281 + }
  282 + }
  283 +
  284 + private void removeTask(){
  285 + handler.postDelayed(new Runnable() {
  286 + @Override
  287 + public void run() {
  288 + handler.removeCallbacks(task);
  289 + }
  290 + },5000);
  291 + }
  292 +
  293 + private Runnable failCall = new Runnable() {
  294 + @Override
  295 + public void run() {
  296 + if(uploadListener != null){
  297 + uploadListener.onFail();
  298 + }
  299 + }
  300 + };
  301 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/SendPacket.java renamed to C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/logic/SendPacket.java
1   -package com.sunvote.xpadapi.service;
  1 +package com.sunvote.xpadapi.service.logic;
2 2  
3 3 public class SendPacket {
4 4  
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/SenderManager.java renamed to C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/logic/SenderManager.java
1   -package com.sunvote.xpadapi.service;
  1 +package com.sunvote.xpadapi.service.logic;
2 2  
3 3 import com.sunvote.xpadapi.service.bean.BatchNumberVote;
4 4 import com.sunvote.xpadapi.service.bean.BatchSingleVote;
... ... @@ -160,7 +160,7 @@ public final class SenderManager {
160 160  
161 161 public void sendSubmitlAllBatchSingleVote(final OnSender<BatchSingleVote> sender) {
162 162 BatchSingleVote batchSingleVote = new BatchSingleVote();
163   - batchSingleVote.setAllOk(1);
  163 + batchSingleVote.setOk(1);
164 164 sendBatchSingleVote(batchSingleVote, sender);
165 165 }
166 166  
... ... @@ -193,7 +193,7 @@ public final class SenderManager {
193 193 }
194 194  
195 195 public void sendBatchNumberVoteOK(final BatchNumberVote batchNumberVote, final OnSender<BatchNumberVote> sender) {
196   - batchNumberVote.setAllOk(1);
  196 + batchNumberVote.setOk(1);
197 197 sendBatchNumberVote(batchNumberVote, sender);
198 198 }
199 199  
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/SerialManager.java renamed to C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/logic/SerialManager.java
1   -package com.sunvote.xpadapi.service;
  1 +package com.sunvote.xpadapi.service.logic;
2 2  
3 3 public final class SerialManager {
4 4  
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/XpadApiServiceInfoProxyManager.java renamed to C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/logic/XpadApiServiceInfoProxyManager.java
1   -package com.sunvote.xpadapi.service;
  1 +package com.sunvote.xpadapi.service.logic;
2 2  
  3 +import com.sunvote.xpadapi.service.XpadApiService;
3 4 import com.sunvote.xpadapi.service.bean.BaseInfo;
4 5 import com.sunvote.xpadapi.service.bean.BaseVoteInfo;
5 6 import com.sunvote.xpadapi.service.bean.KeypadInfo;
... ... @@ -64,6 +65,7 @@ public final class XpadApiServiceInfoProxyManager {
64 65 private ModelInfoChanageListener modelInfoListener;
65 66  
66 67 public void setModelInfo(ModelInfo modelInfo) {
  68 + this.modelInfo = modelInfo;
67 69 if(modelInfoListener != null){
68 70 try{
69 71 modelInfoListener.onModelInfoChanage(modelInfo);
... ... @@ -71,7 +73,6 @@ public final class XpadApiServiceInfoProxyManager {
71 73 LogUtil.e(TAG,"onModelInfoChanage",ex);
72 74 }
73 75 }
74   - this.modelInfo = modelInfo;
75 76 }
76 77  
77 78 public ModelInfo getModelInfo() {
... ... @@ -86,6 +87,7 @@ public final class XpadApiServiceInfoProxyManager {
86 87 private BaseInfoChanageListener baseInfoListener;
87 88  
88 89 public void setBaseInfo(BaseInfo baseInfo) {
  90 + this.baseInfo = baseInfo;
89 91 if(baseInfoListener != null){
90 92 try {
91 93 baseInfoListener.onBaseInfoChange(baseInfo);
... ... @@ -93,7 +95,7 @@ public final class XpadApiServiceInfoProxyManager {
93 95 LogUtil.e(TAG,"onBaseInfoChange",ex);
94 96 }
95 97 }
96   - this.baseInfo = baseInfo;
  98 +
97 99 }
98 100  
99 101 public BaseInfo getBaseInfo() {
... ... @@ -108,6 +110,7 @@ public final class XpadApiServiceInfoProxyManager {
108 110 private BaseVoteInfoChanageListener baseVoteInfoListener;
109 111  
110 112 public void setBaseVoteInfo(BaseVoteInfo baseVoteInfo) {
  113 + this.baseVoteInfo = baseVoteInfo;
111 114 if(baseVoteInfoListener != null){
112 115 try {
113 116 baseVoteInfoListener.onBaseVoteInfoListener(baseVoteInfo);
... ... @@ -115,7 +118,7 @@ public final class XpadApiServiceInfoProxyManager {
115 118 LogUtil.e(TAG,"onBaseVoteInfoListener",ex);
116 119 }
117 120 }
118   - this.baseVoteInfo = baseVoteInfo;
  121 +
119 122 }
120 123  
121 124 public BaseVoteInfo getBaseVoteInfo() {
... ... @@ -130,6 +133,7 @@ public final class XpadApiServiceInfoProxyManager {
130 133 private KeyPadinfoChanageListener keyPadinfoChanageListener;
131 134  
132 135 public void setKeypadInfo(KeypadInfo keypadInfo) {
  136 + this.keypadInfo = keypadInfo;
133 137 if(keyPadinfoChanageListener != null){
134 138 try{
135 139 keyPadinfoChanageListener.onKeyPadinfoChanage(keypadInfo);
... ... @@ -137,7 +141,7 @@ public final class XpadApiServiceInfoProxyManager {
137 141 LogUtil.e(TAG,"onKeyPadinfoChanage",ex);
138 142 }
139 143 }
140   - this.keypadInfo = keypadInfo;
  144 +
141 145 }
142 146  
143 147 public KeypadInfo getKeypadInfo() {
... ... @@ -155,6 +159,7 @@ public final class XpadApiServiceInfoProxyManager {
155 159 private OnlineInfoChanageListener onlineInfoChanageListener;
156 160  
157 161 public void setOnLineInfo(OnLineInfo onLineInfo) {
  162 + this.onLineInfo = onLineInfo;
158 163 if(onlineInfoChanageListener != null){
159 164 try{
160 165 onlineInfoChanageListener.onOnlineInfoChanage(onLineInfo);
... ... @@ -162,7 +167,6 @@ public final class XpadApiServiceInfoProxyManager {
162 167 LogUtil.e(TAG,"onOnlineInfoChanage",ex);
163 168 }
164 169 }
165   - this.onLineInfo = onLineInfo;
166 170 }
167 171  
168 172 public OnLineInfo getOnLineInfo() {
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/util/LogUtil.java deleted
1   -package com.sunvote.xpadapi.util;
2   -
3   -import android.os.Environment;
4   -import android.util.Log;
5   -
6   -import java.io.File;
7   -import java.io.FileWriter;
8   -import java.io.IOException;
9   -import java.text.SimpleDateFormat;
10   -import java.util.Date;
11   -
12   -public class LogUtil {
13   -
14   - private static FileWriter fileWriter;
15   -
16   - public static final int VERBOSE_LEVER = 2;
17   - public static final int DEBUG_LEVER = 3;
18   - public static final int INFO_LEVER = 4;
19   - public static final int WARN_LEVER = 5;
20   - public static final int ERROR_LEVER = 6;
21   - public static final int ASSERT_LEVER = 7;
22   -
23   - public static int lever = VERBOSE_LEVER - 1 ;
24   -
25   - private static boolean logToFile = false;
26   - private static boolean logToLogcat = true ;
27   -
28   - private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH.mm.ss.SSS");
29   -
30   - LogUtil() {
31   - throw new RuntimeException("Stub!");
32   - }
33   -
34   - public static int v(String tag, String msg) {
35   - if (VERBOSE_LEVER > lever) {
36   - if(logToLogcat){
37   - Log.v(tag, msg);
38   - }
39   - inputToFile("(V):" + msg );
40   - }
41   - return -1;
42   - }
43   -
44   - private static void init(){
45   - if(fileWriter == null){
46   - synchronized (LogUtil.class) {
47   - if(fileWriter == null) {
48   - try {
49   - File path = new File(Environment.getExternalStorageDirectory().getPath() + "/sunvote/log");
50   - if (!path.exists()) {
51   - path.mkdirs();
52   - }
53   - File file = new File(Environment.getExternalStorageDirectory().getPath()
54   - + "/sunvote/log/" + simpleDateFormat.format(new Date())+".txt");
55   - if (!file.exists()) {
56   - file.createNewFile();
57   - }
58   - fileWriter = new FileWriter(file, true);
59   -
60   - } catch (Exception ex) {
61   - ex.printStackTrace();
62   - fileWriter = null;
63   - }
64   - }
65   - }
66   - }
67   - }
68   -
69   - public static void enableLogToFile(){
70   - logToFile = true;
71   - }
72   -
73   - public static void disabelLogToFile(){
74   - logToFile = false;
75   - }
76   -
77   - public static void enableLogToLogcat(){
78   - logToLogcat = true;
79   - }
80   -
81   - public static void disableLogToLogcat(){
82   - logToLogcat = false;
83   - }
84   -
85   - public static void enableLog(){
86   - lever = VERBOSE_LEVER - 1;
87   - }
88   -
89   - public static void disableLog(){
90   - lever = ASSERT_LEVER ;
91   - }
92   -
93   - public static int v(String tag, String msg, Throwable tr) {
94   - if(VERBOSE_LEVER > lever){
95   - if(logToLogcat) {
96   - Log.v(tag, msg, tr);
97   - }
98   - inputToFile("(V):" + msg + Log.getStackTraceString(tr));
99   - }
100   - return -1;
101   - }
102   -
103   - public static int d(String tag, String msg) {
104   - if(DEBUG_LEVER > lever){
105   - if(logToLogcat) {
106   - Log.d(tag, msg);
107   - }
108   - inputToFile("(D):" + msg );
109   - }
110   - return -1;
111   - }
112   -
113   - public static int d(String tag, String msg, Throwable tr) {
114   - if(DEBUG_LEVER > lever){
115   - if(logToLogcat){
116   - Log.d(tag,msg,tr);
117   - }
118   - inputToFile("(D):" + msg + Log.getStackTraceString(tr));
119   - }
120   - return -1;
121   - }
122   -
123   - public static int i(String tag, String msg) {
124   - if(INFO_LEVER > lever){
125   - if(logToLogcat){
126   - Log.i(tag,msg);
127   - }
128   - inputToFile("(I):" + msg );
129   - }
130   - return -1;
131   - }
132   -
133   - public static int i(String tag, String msg, Throwable tr) {
134   - if(INFO_LEVER > lever){
135   - if(logToLogcat){
136   - Log.i(tag,msg,tr);
137   - }
138   - inputToFile("(I):" + msg + Log.getStackTraceString(tr));
139   - }
140   - return -1;
141   - }
142   -
143   - public static int i(String tag,byte[] msg){
144   - String msgStr = ByteUtils.bytesToHexString(msg);
145   - return i(tag,msgStr);
146   - }
147   -
148   - public static int i(String tag,String msgTag, byte[] msg){
149   - String msgStr = ByteUtils.bytesToHexString(msg);
150   - return i(tag,msgTag + ":\r\n" + msgStr);
151   - }
152   -
153   - public static int v(String tag,String msgTag, byte[] msg){
154   - String msgStr = ByteUtils.bytesToHexString(msg);
155   - return v(tag,msgTag + ":\r\n" + msgStr);
156   - }
157   -
158   - public static int i(String tag,String msgTag, byte[] msg,int length){
159   - String msgStr = ByteUtils.bytesToHexString(msg,length);
160   - return i(tag,msgTag + ":\r\n" + msgStr);
161   - }
162   -
163   - public static int v(String tag,String msgTag, byte[] msg,int length){
164   - String msgStr = ByteUtils.bytesToHexString(msg,length);
165   - return v(tag,msgTag + ":\r\n" + msgStr);
166   - }
167   -
168   - public static int i(String tag,byte[] msg,Throwable tr){
169   - String msgStr = ByteUtils.bytesToHexString(msg);
170   - return i(tag,msgStr,tr);
171   - }
172   -
173   - public static int i(String tag,String msgTag,byte[] msg,Throwable tr){
174   - String msgStr = ByteUtils.bytesToHexString(msg);
175   - return i(tag,msgTag + ":\r\n" + msgStr,tr);
176   - }
177   -
178   - public static int w(String tag, String msg) {
179   - if(WARN_LEVER > lever){
180   - if(logToLogcat){
181   - Log.w(tag,msg);
182   - }
183   - inputToFile("(V):" + msg);
184   - }
185   - return -1;
186   - }
187   -
188   - public static int w(String tag, String msg, Throwable tr) {
189   - if(WARN_LEVER > lever){
190   - if(logToLogcat){
191   - Log.w(tag,msg,tr);
192   - }
193   - inputToFile("(W):" + msg + Log.getStackTraceString(tr));
194   - }
195   - return -1;
196   - }
197   -
198   - public static boolean isLoggable(String s, int i){
199   - return Log.isLoggable(s,i);
200   - }
201   -
202   - public static int w(String tag, Throwable tr) {
203   - if(WARN_LEVER > lever){
204   - if(logToLogcat){
205   - Log.w(tag,tr);
206   - }
207   - inputToFile("(W):" + Log.getStackTraceString(tr));
208   - }
209   - return -1;
210   - }
211   -
212   - public static int e(String tag, String msg) {
213   - if(ERROR_LEVER > lever){
214   - if(logToLogcat){
215   - Log.e(tag,msg);
216   - }
217   - inputToFile("(E):" + msg);
218   - }
219   - return -1;
220   - }
221   -
222   - public static int e(String tag,Throwable tr){
223   - String message = "ERROR" ;
224   - if(tr != null && tr.getMessage() != null){
225   - message = tr.getMessage();
226   - }
227   - return e(tag,message,tr);
228   - }
229   -
230   - public static int e(String tag, String msg, Throwable tr) {
231   - if(ERROR_LEVER > lever){
232   - if(logToLogcat){
233   - Log.e(tag,msg,tr);
234   - }
235   - inputToFile("(E):" + msg + Log.getStackTraceString(tr));
236   - }
237   - return -1;
238   - }
239   -
240   - public static int wtf(String tag, String msg) {
241   - if(ASSERT_LEVER > lever){
242   - if(logToLogcat){
243   - Log.wtf(tag,msg);
244   - }
245   - inputToFile("(WTF):" + msg);
246   - }
247   - return -1;
248   - }
249   -
250   - public static int wtf(String tag, Throwable tr) {
251   - if(ASSERT_LEVER > lever){
252   - if(logToLogcat){
253   - Log.wtf(tag,tr);
254   - }
255   - inputToFile("(WTF):" + Log.getStackTraceString(tr));
256   - }
257   - return -1;
258   - }
259   -
260   - public static int wtf(String tag, String msg, Throwable tr) {
261   - if(ASSERT_LEVER > lever){
262   - if(logToLogcat){
263   - Log.wtf(tag,msg,tr);
264   - }
265   - inputToFile("(WTF):" + msg + Log.getStackTraceString(tr));
266   - }
267   - return -1;
268   - }
269   -
270   - public static String getStackTraceString(Throwable tr) {
271   - return Log.getStackTraceString(tr);
272   - }
273   -
274   -
275   - public static void stack(){
276   - Throwable throwable = new Throwable();
277   - // 需要处理TAG 要读出上面class method的信息,后续添上
278   - i("STACK",getStackTraceString(throwable));
279   - }
280   -
281   - private synchronized static void inputToFile(String msg){
282   - if(logToFile) {
283   - String time = simpleDateFormat.format(new Date());
284   - try {
285   - init();
286   - String log = time + "(" + Thread.currentThread().getName() + ",id=" + Thread.currentThread().getId() + ")" + msg + "\r\n";
287   - if(onLogMessage != null){
288   - onLogMessage.onLog(time + ":" + msg + "\r\n");
289   - }
290   - fileWriter.write(log);
291   - fileWriter.flush();
292   - } catch (Exception ex) {
293   - ex.printStackTrace();
294   - if(fileWriter != null){
295   - try {
296   - fileWriter.close();
297   - } catch (IOException e) {
298   - e.printStackTrace();
299   - }
300   - }
301   - fileWriter = null;
302   - }
303   - }
304   - }
305   -
306   - private static OnLogMessage onLogMessage;
307   -
308   - public static void setOnLogMessage(OnLogMessage onLogMessage) {
309   - LogUtil.onLogMessage = onLogMessage;
310   - }
311   -
312   - public static interface OnLogMessage{
313   - void onLog(String log);
314   - }
315   -}
316   -
C5/xpadprotocal/build/libs/xpadprotocal.jar 0 → 100644
No preview for this file type
C5/xpadprotocal/build/tmp/jar/MANIFEST.MF 0 → 100644
  1 +Manifest-Version: 1.0
  2 +
... ...