diff --git a/C5/app/src/main/res/layout/fragment_result_multi_vote.xml b/C5/app/src/main/res/layout/fragment_result_multi_vote.xml
index 0c07cd8..911d582 100644
--- a/C5/app/src/main/res/layout/fragment_result_multi_vote.xml
+++ b/C5/app/src/main/res/layout/fragment_result_multi_vote.xml
@@ -44,13 +44,15 @@
+ android:layout_centerVertical="true"
+ android:textColor="@color/yellow"
+ android:textSize="@dimen/big_text_p4"
+ android:textStyle="bold"
+ android:text="序号"/>
Testing documentation
+ */
+@RunWith(AndroidJUnit4.class)
+public class ExampleInstrumentedTest {
+ @Test
+ public void useAppContext() {
+ // Context of the app under test.
+ Context appContext = InstrumentationRegistry.getTargetContext();
+
+ assertEquals("com.sunvote.xpadapi.test", appContext.getPackageName());
+ }
+}
diff --git a/C5/xpadapi/src/main/AndroidManifest.xml b/C5/xpadapi/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..1c11958
--- /dev/null
+++ b/C5/xpadapi/src/main/AndroidManifest.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/C5/xpadapi/src/main/aidl/com/sunvote/xpadapi/ISunvoteApi.aidl b/C5/xpadapi/src/main/aidl/com/sunvote/xpadapi/ISunvoteApi.aidl
new file mode 100644
index 0000000..55ac746
--- /dev/null
+++ b/C5/xpadapi/src/main/aidl/com/sunvote/xpadapi/ISunvoteApi.aidl
@@ -0,0 +1,35 @@
+// ISunvoteApi.aidl
+package com.sunvote.xpadapi;
+
+// Declare any non-default types here with import statements
+
+interface ISunvoteApi {
+
+
+ /**
+ * 数据包接收
+ */
+
+
+ /**
+ * 基础信标
+ */
+
+ /**
+ * 投票信标
+ */
+
+
+ /**
+ * 基础信标
+ */
+
+ /**
+ * 30透传包
+ */
+
+ /**
+ * 40透传包
+ */
+}
+
diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/SendPacket.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/SendPacket.java
new file mode 100644
index 0000000..20c5c8e
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/SendPacket.java
@@ -0,0 +1,25 @@
+package com.sunvote.xpadapi.service;
+
+public class SendPacket {
+
+ private byte[] datas;
+
+ /**
+ * 0 未发送
+ * 1 已发送
+ * 2 发送成功
+ */
+ private int sendOK ;
+
+ /**
+ * 发送次数
+ */
+ private int sendTimes;
+
+ /**
+ * 是否有序 有序需要第一个才发送
+ * 无序,则可全部发送
+ */
+ private boolean canAll;
+
+}
diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/SenderManager.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/SenderManager.java
new file mode 100644
index 0000000..cb8b0dd
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/SenderManager.java
@@ -0,0 +1,283 @@
+package com.sunvote.xpadapi.service;
+
+import com.sunvote.xpadapi.service.bean.BatchNumberVote;
+import com.sunvote.xpadapi.service.bean.BatchSingleVote;
+import com.sunvote.xpadapi.service.bean.LoginInVote;
+import com.sunvote.xpadapi.service.bean.NumberVote;
+import com.sunvote.xpadapi.service.bean.Packet;
+import com.sunvote.xpadapi.service.bean.SelectOtherVote;
+import com.sunvote.xpadapi.service.bean.SelectVote;
+import com.sunvote.xpadapi.service.bean.ServiceTypeVote;
+import com.sunvote.xpadapi.service.bean.SingleVote;
+import com.sunvote.xpadapi.service.listener.OnSendPacket;
+import com.sunvote.xpadapi.service.listener.OnSender;
+
+public final class SenderManager {
+
+ private static SenderManager instance = null;
+
+ private SenderManager() {
+ }
+
+ public static SenderManager getInstance() {
+ if (instance == null) {
+ synchronized (SenderManager.class) {
+ if (instance == null) {
+ instance = new SenderManager();
+ }
+ }
+ }
+ return instance;
+ }
+
+ /**
+ * 发送
+ *
+ * @param singleVote
+ */
+ public void sendSingleVote(final SingleVote singleVote) {
+ sendSingleVote(singleVote, null);
+ }
+
+ public void sendVoteAllOK(final OnSender sender) {
+ SingleVote singleVote = new SingleVote(1);
+ sendSingleVote(singleVote, sender);
+ }
+
+ public void sendSingleVote(final SingleVote singleVote, final OnSender onSender) {
+ if (singleVote != null) {
+ byte[] datas = singleVote.toBytes();
+ XpadApiServiceInfoProxyManager.getInstance().sendPacket(datas, new OnSendPacket() {
+ @Override
+ public void onSuccess(Packet packet) {
+ if (onSender != null) {
+ onSender.onSuccess(singleVote);
+ }
+ }
+
+ @Override
+ public void onFail(Packet packet) {
+ if (onSender != null) {
+ onSender.onFail(singleVote);
+ }
+ }
+ });
+ } else {
+ if (onSender != null) {
+ onSender.onFail(singleVote);
+ }
+ }
+ }
+
+ public void sendSelectVote(final SelectVote selectVote) {
+ sendSelectVote(selectVote, null);
+ }
+
+ public void sendSelectVote(final SelectVote selectVote, final OnSender onSender) {
+ if (selectVote != null) {
+ XpadApiServiceInfoProxyManager.getInstance().sendPacket(selectVote.toBytes(), new OnSendPacket() {
+ @Override
+ public void onSuccess(Packet packet) {
+ if (onSender != null) {
+ onSender.onSuccess(selectVote);
+ }
+ }
+
+ @Override
+ public void onFail(Packet packet) {
+ if (onSender != null) {
+ onSender.onFail(selectVote);
+ }
+ }
+ });
+ } else {
+ if (onSender != null) {
+ onSender.onFail(selectVote);
+ }
+ }
+ }
+
+ public void sendNumberVote(final NumberVote numberVote) {
+ sendNumberVote(numberVote, null);
+ }
+
+ public void sendNumberVote(final NumberVote numberVote, final OnSender sender) {
+ if (numberVote != null) {
+ XpadApiServiceInfoProxyManager.getInstance().sendPacket(numberVote.toBytes(), new OnSendPacket() {
+ @Override
+ public void onSuccess(Packet packet) {
+ if (sender != null) {
+ sender.onSuccess(numberVote);
+ }
+ }
+
+ @Override
+ public void onFail(Packet packet) {
+ if (sender != null) {
+ sender.onFail(numberVote);
+ }
+ }
+ });
+ } else {
+ if (sender != null) {
+ sender.onFail(numberVote);
+ }
+ }
+ }
+
+ public void sendLoginInVote(final LoginInVote loginInVote) {
+ sendLoginInVote(loginInVote, null);
+ }
+
+ public void sendLoginInVote(final LoginInVote loginInVote, final OnSender sender) {
+ if (loginInVote != null) {
+ XpadApiServiceInfoProxyManager.getInstance().sendPacket(loginInVote.toBytes(), new OnSendPacket() {
+ @Override
+ public void onSuccess(Packet packet) {
+ if (sender != null) {
+ sender.onSuccess(loginInVote);
+ }
+ }
+
+ @Override
+ public void onFail(Packet packet) {
+ if (sender != null) {
+ sender.onFail(loginInVote);
+ }
+ }
+ });
+ } else {
+ if (sender != null) {
+ sender.onFail(loginInVote);
+ }
+ }
+ }
+
+ public void sendCancelAllBatchSingleVote(final OnSender sender) {
+ BatchSingleVote batchSingleVote = new BatchSingleVote();
+ sendBatchSingleVote(batchSingleVote, sender);
+ }
+
+ public void sendSubmitlAllBatchSingleVote(final OnSender sender) {
+ BatchSingleVote batchSingleVote = new BatchSingleVote();
+ batchSingleVote.setAllOk(1);
+ sendBatchSingleVote(batchSingleVote, sender);
+ }
+
+ public void sendBatchSingleVote(final BatchSingleVote batchSingleVote) {
+ sendBatchSingleVote(batchSingleVote, null);
+ }
+
+ public void sendBatchSingleVote(final BatchSingleVote batchSingleVote, final OnSender sender) {
+ if (batchSingleVote != null) {
+ XpadApiServiceInfoProxyManager.getInstance().sendPacket(batchSingleVote.toBytes(), new OnSendPacket() {
+ @Override
+ public void onSuccess(Packet packet) {
+ if (sender != null) {
+ sender.onSuccess(batchSingleVote);
+ }
+ }
+
+ @Override
+ public void onFail(Packet packet) {
+ if (sender != null) {
+ sender.onFail(batchSingleVote);
+ }
+ }
+ });
+ } else {
+ if (sender != null) {
+ sender.onFail(batchSingleVote);
+ }
+ }
+ }
+
+ public void sendBatchNumberVoteOK(final BatchNumberVote batchNumberVote, final OnSender sender) {
+ batchNumberVote.setAllOk(1);
+ sendBatchNumberVote(batchNumberVote, sender);
+ }
+
+ public void sendBatchNumberVote(final BatchNumberVote batchNumberVote) {
+ sendBatchNumberVote(batchNumberVote, null);
+ }
+
+ public void sendBatchNumberVote(final BatchNumberVote batchNumberVote, final OnSender sender) {
+ if (batchNumberVote != null) {
+ XpadApiServiceInfoProxyManager.getInstance().sendPacket(batchNumberVote.toBytes(), new OnSendPacket() {
+ @Override
+ public void onSuccess(Packet packet) {
+ if (sender != null) {
+ sender.onSuccess(batchNumberVote);
+ }
+ }
+
+ @Override
+ public void onFail(Packet packet) {
+ if (sender != null) {
+ sender.onFail(batchNumberVote);
+ }
+ }
+ });
+ } else {
+ if (sender != null) {
+ sender.onFail(batchNumberVote);
+ }
+ }
+ }
+
+ public void sendSelectOtherVote(SelectOtherVote selectOtherVote) {
+ sendSelectOtherVote(selectOtherVote, null);
+ }
+
+ public void sendSelectOtherVote(final SelectOtherVote selectOtherVote, final OnSender sender) {
+ if (selectOtherVote != null) {
+ XpadApiServiceInfoProxyManager.getInstance().sendPacket(selectOtherVote.toBytes(), new OnSendPacket() {
+ @Override
+ public void onSuccess(Packet packet) {
+ if (sender != null) {
+ sender.onSuccess(selectOtherVote);
+ }
+ }
+
+ @Override
+ public void onFail(Packet packet) {
+ if (sender != null) {
+ sender.onFail(selectOtherVote);
+ }
+ }
+ });
+ } else {
+ if (sender != null) {
+ sender.onFail(selectOtherVote);
+ }
+ }
+ }
+
+ public void sendServiceTypeVote(final ServiceTypeVote serviceTypeVote) {
+ sendServiceTypeVote(serviceTypeVote, null);
+ }
+
+ public void sendServiceTypeVote(final ServiceTypeVote serviceTypeVote, final OnSender sender) {
+ if (serviceTypeVote != null) {
+ XpadApiServiceInfoProxyManager.getInstance().sendPacket(serviceTypeVote.toBytes(), new OnSendPacket() {
+ @Override
+ public void onSuccess(Packet packet) {
+ if (sender != null) {
+ sender.onSuccess(serviceTypeVote);
+ }
+ }
+
+ @Override
+ public void onFail(Packet packet) {
+ if (sender != null) {
+ sender.onFail(serviceTypeVote);
+ }
+ }
+ });
+ } else {
+ if (sender != null) {
+ sender.onFail(serviceTypeVote);
+ }
+ }
+ }
+}
diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/SerialManager.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/SerialManager.java
new file mode 100644
index 0000000..17cd62d
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/SerialManager.java
@@ -0,0 +1,29 @@
+package com.sunvote.xpadapi.service;
+
+public final class SerialManager {
+
+ private static SerialManager instance = null ;
+
+ private SerialManager(){
+ }
+
+ public static SerialManager getInstance(){
+ if(instance == null){
+ synchronized(SerialManager.class){
+ if(instance == null){
+ instance = new SerialManager();
+ }
+ }
+ }
+ return instance;
+ }
+
+ private byte seq = 0 ;
+
+ public byte getSeq() {
+ if (seq == 0xfe) {
+ seq = 0 ;
+ }
+ return ++seq;
+ }
+}
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
new file mode 100644
index 0000000..479dff3
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/XpadApiService.java
@@ -0,0 +1,586 @@
+package com.sunvote.xpadapi.service;
+
+import android.app.Service;
+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.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.KeypadInfo;
+import com.sunvote.xpadapi.service.bean.ModelInfo;
+import com.sunvote.xpadapi.service.bean.OnLineInfo;
+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;
+
+public class XpadApiService extends Service {
+
+ private static final String TAG = XpadApiService.class.getSimpleName();
+ private List onDataReceiverList = new ArrayList<>();
+ private int batteryLevel = 0;
+ private List innerList = Collections.synchronizedList(new ArrayList());
+ private OnDataReceiver onDataReceiver = new OnDataReceiver() {
+ @Override
+ public void onDataReceiver(byte[] datas) {
+ LogUtil.i(TAG, "onDataReceiver", datas);
+ for (OnDataReceiver temp : onDataReceiverList) {
+ if (temp != null) {
+ try {
+ temp.onDataReceiver(datas);
+ } catch (Exception ex) {
+ LogUtil.e(TAG, "onDataReceiver", ex);
+ }
+ }
+ }
+ }
+
+ @Override
+ public void onDataSender(byte[] datas) {
+ LogUtil.i(TAG, "onDataSender", datas);
+ for (OnDataReceiver temp : onDataReceiverList) {
+ if (temp != null) {
+ try {
+ temp.onDataSender(datas);
+ } catch (Exception ex) {
+ LogUtil.e(TAG, "onDataSender", ex);
+ }
+ }
+ }
+ }
+ };
+
+ public XpadApiService() {
+ }
+
+ public int registerOnDataReceiver(OnDataReceiver onDataReceiver) {
+ for (OnDataReceiver temp : onDataReceiverList) {
+ if (temp == onDataReceiver) {
+ return 0;
+ }
+ }
+ onDataReceiverList.add(onDataReceiver);
+ return 1;
+ }
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+
+ sendThread = new HandlerThread("send");
+ receiverThread = new HandlerThread("receiver");
+ sendThread.start();
+ receiverThread.start();
+
+ taskHandler = new Handler(sendThread.getLooper());
+ IntentFilter batteryLevelFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
+ registerReceiver(batteryLevelRcvr, batteryLevelFilter);
+ XpadApiServiceInfoProxyManager.getInstance().setService(this);
+
+ receiverDatas();
+ }
+
+ private void receiverDatas() {
+ SunVoteInputStream sunVoteInputStream = new SunVoteInputStream();
+ sunVoteInputStream.setOnBytesReceiver(new SunVoteInputStream.OnBytesReceiver() {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ @Override
+ public void onBytesReceiver(byte[] bytes, int len) {
+ // 1. 先检测读取数据到缓冲区
+ byteArrayOutputStream.write(bytes, 0, bytes.length);
+ if (byteArrayOutputStream.size() >= 3) {
+ byte[] temp = byteArrayOutputStream.toByteArray();
+ int find = ByteUtils.findBytes(temp, new byte[]{(byte) 0xF5, (byte) 0xAA, (byte) 0xAA}, 0);
+ if (find >= 0) {
+ // 3. 标志存在,则继续读取长度
+ if (byteArrayOutputStream.size() >= find + 4) {
+ int length = ByteUtils.byte1ToInt(byteArrayOutputStream.toByteArray()[find + 3]);
+ if (byteArrayOutputStream.size() >= find + 4 + length) {
+ ByteArrayOutputStream tmp = new ByteArrayOutputStream();
+ // 4. 根据长度读取包的内容
+ for (int i = find; i < find + 4 + length; i++) {
+ // 5. 截取包的内容,向外抛出,处理,接着读取下一个包
+ tmp.write(temp[i]);
+ }
+ //CRC 校验
+ byte[] datas = tmp.toByteArray();
+ LogUtil.i(TAG, "RECEIVER DATA:", datas);
+
+ try {
+ //处理
+ doWith(datas);
+ } catch (Exception ex) {
+ LogUtil.i(TAG, "处理命令出错:", ex);
+ }
+ // 7. 剩余数据重新打包处理
+ byteArrayOutputStream.reset();
+ for (int i = find + 4 + length; i < temp.length; i++) {
+ byteArrayOutputStream.write(temp[i]);
+ }
+ }
+ }
+ }
+ }
+ }
+ });
+ SDKProcessWork.getInstance().setInputStream(sunVoteInputStream);
+ BaseStationProcessWork.getInstance().start();
+ RepeatMessageManager.getInstance().start();
+ SDKProcessWork.getInstance().start();
+ }
+
+ @Override
+ public void onDestroy() {
+ unregisterReceiver(batteryLevelRcvr);
+ super.onDestroy();
+ }
+
+ private HandlerThread sendThread = null;
+ private HandlerThread receiverThread = null;
+ private Handler taskHandler = null;
+ private boolean receivering = true;
+
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ return stub;
+ }
+
+ private final ISunvoteApi.Stub stub = new ISunvoteApi.Stub() {
+
+ };
+
+ 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() {
+ // 从队列中取出待发送数据
+ List sendList = XpadApiServiceInfoProxyManager.getInstance().getSendList();
+ boolean isSend = false;
+ for (Packet p : sendList) {
+ if (p.needSend() && !isSend) {// 按照顺序发送
+ p.addSendCount();
+ sendPacket(p);
+ isSend = true;
+ }
+ if (p.needSend() && isSend && p.isSync()) {// 并行发送
+ sleepTimes(50);// 模块不能发送太快
+ p.addSendCount();
+ sendPacket(p);
+ }
+ if (!p.needSend() && (p.getOnSendPacket() != null)) {
+ p.getOnSendPacket().onFail(p);
+ }
+ }
+ if (!isSend) {
+ LogUtil.i(TAG, "没有要提交的数据,检查是否有查询包发送");
+ if (innerList.size() > 0) {
+ synchronized (innerList) {
+ for (Packet packet : innerList) {
+ sendPacket(packet);
+ sleepTimes(50);
+ }
+ }
+ }
+ }
+
+ if (!isSend) {// 没有数据发送? 那就发送心跳吧
+ LogUtil.i(TAG, "没有任何数据要发送,则发送心跳包");
+ sendData(new HeartBeat((byte) batteryLevel, (byte) 0).toBytes());
+ }
+ // 轮询下一次发送数据
+ taskHandler.removeCallbacks(this);
+ taskHandler.postDelayed(this, 1000);
+ }
+ };
+
+ private void doWith(byte[] datas) {
+ onDataReceiver.onDataReceiver(datas);
+ switch (datas[4] & 0xFF) {
+ case Cons.CMD_CHECK_BASE_STATUS_RESPONSE:
+ checkBaseStatusResponse(datas);
+ break;
+ case Cons.CMD_VOTE_RESULT_SEND_RESPONSE:
+ voteResultSendResponse(datas);
+ break;
+ case Cons.CMD_FIRM_UPDATE_RESPONSE:
+ firmUpdateResponse(datas);
+ break;
+
+ case Cons.CMD_BASE_STATUS_CHANGE:
+ baseStatusChange(datas);
+ break;
+ case Cons.CMD_VOTE_STATUS_CHANGE:
+ voteStatusChange(datas);
+ break;
+ case Cons.CMD_VOTE_SEND_SUCCESS_RESPONSE:
+ voteSendSuccessResponse(datas);
+ break;
+
+ case Cons.CMD_UPLOAD_DATA_RESPONSE:
+ uploadDataResponse(datas);
+ break;
+ case Cons.CMD_TRANSPARENT_TRANSMISSION:
+ transparentTransmission(datas);
+ break;
+ case Cons.CMD_MULTI_PCKAGE_DOWNLOAD:
+ break;
+ case Cons.CMD_COM_COMMUNICATION_TEST_RESPONSE:
+ break;
+
+ }
+ }
+
+ private void transparentTransmission(byte[] datas) {
+ }
+
+ private void uploadDataResponse(byte[] datas) {
+ }
+
+ private void voteSendSuccessResponse(byte[] datas) {
+ responseChange(datas, 4, (byte) 0xF3);
+ int serialNo = datas[5] & 0xff;
+ Packet packet = XpadApiServiceInfoProxyManager.getInstance().findPacket(serialNo);
+ if (packet != null && packet.getOnSendPacket() != null) {
+ packet.getOnSendPacket().onSuccess(packet);
+ }
+ }
+
+ private void sendInnerPacket(Packet packet) {
+ synchronized (innerList) {
+ for (Packet temp : innerList) {
+ if (temp.getSendNo() == packet.getSendNo()) {
+ return;
+ }
+ }
+ innerList.add(packet);
+ }
+ immediately();
+ }
+
+ public void immediately(){
+ taskHandler.removeCallbacks(sendTask);
+ taskHandler.post(sendTask);
+ }
+
+ private void voteStatusChange(byte[] datas) {
+ responseChange(datas, 4, (byte) 0xF2);
+ saveVoteInfo(datas);
+ }
+
+ private void baseStatusChange(byte[] datas) {
+ responseChange(datas, 4, (byte) 0xF1);
+ saveBaseInfo(datas);
+ }
+
+ private void firmUpdateResponse(byte[] datas) {
+ }
+
+ private void voteResultSendResponse(byte[] datas) {
+
+ }
+
+ private void checkBaseStatusResponse(byte[] datas) {
+ switch (datas[5] & 0xFF) {
+ case 1://当前工作模式和版本
+ case 2://当前工作模式和版本
+ saveModelInfo(datas);
+ break;
+ case 3:
+ saveBaseInfo(datas);
+ break;
+ case 4:
+ saveVoteInfo(datas);
+ break;
+ case 5:
+ case 6:
+ saveKeypadInfo(datas);
+ break;
+ case 7:
+ saveOnLineInfo(datas);
+ break;
+ case 8:
+ case 9:
+ saveKeypadInfo(datas);
+ break;
+ }
+ }
+
+ private void saveOnLineInfo(byte[] datas) {
+ OnLineInfo info = new OnLineInfo();
+ info.setOnLine(datas[6] & 0xff);
+ info.setIdMode(datas[7] & 0xff);
+ info.setChan(datas[8] & 0xff);
+ info.setRssi(datas[9] & 0xff);
+ info.setTx(datas[10] & 0xff);
+ info.setRx(datas[11] & 0xff);
+ info.setBaseId(datas[12] & 0xff);
+ info.setKeyId(((datas[13] & 0xff) << 8) | (datas[14] & 0xff));
+ byte[] sn = Arrays.copyOfRange(datas, 15, 21);
+ info.setKeySn(ByteUtils.getKeySn(sn));
+ XpadApiServiceInfoProxyManager.getInstance().setOnLineInfo(info);
+ }
+
+ private void saveKeypadInfo(byte[] datas) {
+ KeypadInfo info = new KeypadInfo();
+ info.setOk(datas[6] & 0xff);
+ info.setChan(datas[7] & 0xff);
+ info.setKeyId(((datas[8] & 0xff) << 8) | (datas[9] & 0xff));
+ byte[] sn = Arrays.copyOfRange(datas, 10, 16);
+ info.setKeySn(ByteUtils.getKeySn(sn));
+ byte[] mc = Arrays.copyOfRange(datas, 16, 19);
+ info.setMatchCode(new String(mc));
+ XpadApiServiceInfoProxyManager.getInstance().setKeypadInfo(info);
+ }
+
+ private void saveVoteInfo(byte[] datas) {
+ BaseVoteInfo info = new BaseVoteInfo();
+ info.setBaseId(datas[1] & 0xff);
+ info.setNowT(datas[2] & 0xff << 8 | datas[3] & 0xff);
+ info.setDataPos(datas[4] & 0xff);
+ info.setMode(datas[5] & 0xff);
+ info.setModes(datas);
+ XpadApiServiceInfoProxyManager.getInstance().setBaseVoteInfo(info);
+ }
+
+ /**
+ * 保存基础信标信息
+ *
+ * @param data
+ */
+ private void saveBaseInfo(byte[] data) {
+ BaseInfo info = new BaseInfo();
+ info.setBaseId(data[5] & 0xff);// baseID
+ info.setIdMode(data[6] & 0xff);
+ info.setConfId(((data[7] & 0xff) << 8) | (data[8] & 0xff));
+ info.setBillId(data[9] & 0xff);
+ info.setAuthCode((data[10] & 0xff) << 8 | (data[11] & 0xff));
+ info.setLogin(data[12] & 0xff);
+ info.setReport(data[13] & 0xff);
+ info.setOffTime(data[14] & 0xff);
+ info.setAttrib(data[15] & 0xff);
+ info.setPageNo((data[16] & 0xff) << 8 | (data[17] & 0xff));
+ byte[] bname = Arrays.copyOfRange(data, 16, 16 + 12);
+ info.setBaseName(new String(bname));
+ XpadApiServiceInfoProxyManager.getInstance().setBaseInfo(info);
+ }
+
+ private void saveModelInfo(byte[] datas) {
+ ModelInfo info = new ModelInfo();
+ info.setMode(datas[6] & 0xff);
+ info.sethModel(datas[7] & 0xff);
+ info.setsVer((datas[8] & 0xff) + "." + (datas[9] & 0xff) + "." + (datas[10] & 0xff));
+ XpadApiServiceInfoProxyManager.getInstance().setModelInfo(info);
+ }
+
+
+ private void responseChange(byte[] data, int pos, byte res) {
+ byte[] retData = Arrays.copyOf(data, data.length);
+ retData[pos] = res;
+ sendData(data);
+ }
+
+ private void roundCRC(byte[] data) {
+ int crcValue = Crc16.getUnsignedShort(Crc16.crc16(data, data.length - 4 - 2));
+ data[data.length - 2] = (byte) (crcValue >> 8);
+ data[data.length - 1] = (byte) (crcValue);
+ }
+
+ public void sendPacket(Packet packet) {
+ sendData(packet.getDatas());
+ }
+
+ public void sendData(byte[] datas) {
+ roundCRC(datas);
+ onDataReceiver.onDataSender(datas);
+ try {
+ SDKProcessWork.getInstance().execute(datas,datas.length);
+ } catch (Exception e) {
+ LogUtil.e(TAG, e);
+ }
+ }
+
+ private void sleepTimes(long times) {
+ try {
+ Thread.sleep(times);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ BroadcastReceiver batteryLevelRcvr = new BroadcastReceiver() {
+
+ public void onReceive(Context context, Intent intent) {
+ if (Intent.ACTION_BATTERY_CHANGED.equals(intent.getAction())) {
+ int rawlevel = intent.getIntExtra("level", -1);
+ int scale = intent.getIntExtra("scale", -1);
+ int status = intent.getIntExtra("status", -1);
+ int health = intent.getIntExtra("health", -1);
+ int voltage = intent.getIntExtra("voltage", 0);
+ int level = -1; // percentage, or -1 for unknown
+ if (rawlevel >= 0 && scale > 0) {
+ level = (rawlevel * 100) / scale;
+ }
+
+ float val = (float) voltage / 1000;
+ batteryLevel = (int) (val / 0.04);
+
+ }
+ }
+ };
+
+ public void getKeypadParam() {
+ 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] = 0x70;
+ mBuffer[5] = 0x05;
+ Packet packet = new Packet();
+ packet.setDatas(mBuffer);
+ packet.setSendNo(Packet.GetKeypadParam);
+ sendInnerPacket(packet);
+ }
+
+ public void getWorkMode() {
+ 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] = 0x70;
+ mBuffer[5] = 0x01;
+ Packet packet = new Packet();
+ packet.setDatas(mBuffer);
+ packet.setSendNo(Packet.GetWorkModeNum);
+ sendInnerPacket(packet);
+ }
+
+ public void setWorkMode(int iMode) {
+ 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] = 0x70;
+ mBuffer[5] = 0x02;
+ mBuffer[6] = (byte) iMode;
+ Packet packet = new Packet();
+ packet.setDatas(mBuffer);
+ packet.setSendNo(Packet.SetWorkModeNum);
+ sendInnerPacket(packet);
+ }
+
+ public void getBaseStatus() {
+ 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] = 0x70;
+ mBuffer[5] = 0x03;
+ Packet packet = new Packet();
+ packet.setDatas(mBuffer);
+ packet.setSendNo(Packet.BaseStatusNum);
+ sendInnerPacket(packet);
+ }
+
+ public void getVoteStatus() {
+ 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] = 0x70;
+ mBuffer[5] = 0x04;
+ Packet packet = new Packet();
+ packet.setDatas(mBuffer);
+ packet.setSendNo(Packet.VoteStatusNum);
+ sendInnerPacket(packet);
+ }
+
+ public void execKeypadMatch(int iMode, int channal) {
+ 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] = 0x70;
+ mBuffer[5] = 0x08;
+ mBuffer[6] = (byte) iMode;
+ mBuffer[7] = (byte) channal;
+ Packet packet = new Packet();
+ packet.setDatas(mBuffer);
+ packet.setSendNo(Packet.ExecKeypadMatchNum);
+ sendInnerPacket(packet);
+ }
+
+ public void comCommunicationTest(int sendn, int okn) {
+ 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] = 0x30;
+ mBuffer[5] = 0x0;
+ mBuffer[6] = 0x0;
+ mBuffer[7] = 7;
+ mBuffer[8] = (byte) sendn;
+ mBuffer[9] = (byte) okn;
+ mBuffer[10] = (byte) 0xAA;
+
+ for (int i = 1; i < 17; i++) {
+ mBuffer[10 + i] = (byte) i;
+ }
+
+ 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/XpadApiServiceInfoProxyManager.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/XpadApiServiceInfoProxyManager.java
new file mode 100644
index 0000000..e3962bc
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/XpadApiServiceInfoProxyManager.java
@@ -0,0 +1,236 @@
+package com.sunvote.xpadapi.service;
+
+import com.sunvote.xpadapi.service.bean.BaseInfo;
+import com.sunvote.xpadapi.service.bean.BaseVoteInfo;
+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.BaseInfoChanageListener;
+import com.sunvote.xpadapi.service.listener.BaseVoteInfoChanageListener;
+import com.sunvote.xpadapi.service.listener.KeyPadinfoChanageListener;
+import com.sunvote.xpadapi.service.listener.ModelInfoChanageListener;
+import com.sunvote.xpadapi.service.listener.OnSendPacket;
+import com.sunvote.xpadapi.service.listener.OnlineInfoChanageListener;
+import com.sunvote.xpadapi.util.LogUtil;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * 服务信息
+ */
+public final class XpadApiServiceInfoProxyManager {
+
+ public static final String TAG = XpadApiServiceInfoProxyManager.class.getSimpleName();
+ private static XpadApiServiceInfoProxyManager instance = null ;
+ private List sendList = Collections.synchronizedList(new ArrayList());
+ private Object lock = new Object();
+ private String charset = "GB2312" ;
+ private XpadApiService service;
+
+ public void setCharset(String charset) {
+ this.charset = charset;
+ }
+
+ public void setService(XpadApiService service) {
+ this.service = service;
+ }
+
+ public XpadApiService getService() {
+ return service;
+ }
+
+ public String getCharset() {
+ return charset;
+ }
+
+ private XpadApiServiceInfoProxyManager(){
+ }
+
+ public static XpadApiServiceInfoProxyManager getInstance(){
+ if(instance == null){
+ synchronized(XpadApiServiceInfoProxyManager.class){
+ if(instance == null){
+ instance = new XpadApiServiceInfoProxyManager();
+ }
+ }
+ }
+ return instance;
+ }
+
+ private ModelInfo modelInfo;
+ private ModelInfoChanageListener modelInfoListener;
+
+ public void setModelInfo(ModelInfo modelInfo) {
+ if(modelInfoListener != null){
+ try{
+ modelInfoListener.onModelInfoChanage(modelInfo);
+ }catch (Exception ex){
+ LogUtil.e(TAG,"onModelInfoChanage",ex);
+ }
+ }
+ this.modelInfo = modelInfo;
+ }
+
+ public ModelInfo getModelInfo() {
+ return modelInfo;
+ }
+
+ public void setModelInfoListener(ModelInfoChanageListener modelInfoListener) {
+ this.modelInfoListener = modelInfoListener;
+ }
+
+ private BaseInfo baseInfo;
+ private BaseInfoChanageListener baseInfoListener;
+
+ public void setBaseInfo(BaseInfo baseInfo) {
+ if(baseInfoListener != null){
+ try {
+ baseInfoListener.onBaseInfoChange(baseInfo);
+ }catch (Exception ex){
+ LogUtil.e(TAG,"onBaseInfoChange",ex);
+ }
+ }
+ this.baseInfo = baseInfo;
+ }
+
+ public BaseInfo getBaseInfo() {
+ return baseInfo;
+ }
+
+ public void setBaseInfoListener(BaseInfoChanageListener baseInfoListener) {
+ this.baseInfoListener = baseInfoListener;
+ }
+
+ private BaseVoteInfo baseVoteInfo;
+ private BaseVoteInfoChanageListener baseVoteInfoListener;
+
+ public void setBaseVoteInfo(BaseVoteInfo baseVoteInfo) {
+ if(baseVoteInfoListener != null){
+ try {
+ baseVoteInfoListener.onBaseVoteInfoListener(baseVoteInfo);
+ }catch (Exception ex){
+ LogUtil.e(TAG,"onBaseVoteInfoListener",ex);
+ }
+ }
+ this.baseVoteInfo = baseVoteInfo;
+ }
+
+ public BaseVoteInfo getBaseVoteInfo() {
+ return baseVoteInfo;
+ }
+
+ public void setBaseVoteInfoListener(BaseVoteInfoChanageListener baseVoteInfoListener) {
+ this.baseVoteInfoListener = baseVoteInfoListener;
+ }
+
+ private KeypadInfo keypadInfo;
+ private KeyPadinfoChanageListener keyPadinfoChanageListener;
+
+ public void setKeypadInfo(KeypadInfo keypadInfo) {
+ if(keyPadinfoChanageListener != null){
+ try{
+ keyPadinfoChanageListener.onKeyPadinfoChanage(keypadInfo);
+ }catch (Exception ex){
+ LogUtil.e(TAG,"onKeyPadinfoChanage",ex);
+ }
+ }
+ this.keypadInfo = keypadInfo;
+ }
+
+ public KeypadInfo getKeypadInfo() {
+ if(keypadInfo == null){
+ keypadInfo = new KeypadInfo();
+ }
+ return keypadInfo;
+ }
+
+ public void setKeyPadinfoChanageListener(KeyPadinfoChanageListener keyPadinfoChanageListener) {
+ this.keyPadinfoChanageListener = keyPadinfoChanageListener;
+ }
+
+ private OnLineInfo onLineInfo;
+ private OnlineInfoChanageListener onlineInfoChanageListener;
+
+ public void setOnLineInfo(OnLineInfo onLineInfo) {
+ if(onlineInfoChanageListener != null){
+ try{
+ onlineInfoChanageListener.onOnlineInfoChanage(onLineInfo);
+ }catch (Exception ex){
+ LogUtil.e(TAG,"onOnlineInfoChanage",ex);
+ }
+ }
+ this.onLineInfo = onLineInfo;
+ }
+
+ public OnLineInfo getOnLineInfo() {
+ return onLineInfo;
+ }
+
+ public void setOnlineInfoChanageListener(OnlineInfoChanageListener onlineInfoChanageListener) {
+ this.onlineInfoChanageListener = onlineInfoChanageListener;
+ }
+
+ public void sendPacket(byte[] datas,final OnSendPacket sendPacket){
+ Packet packet = new Packet();
+ packet.setDatas(datas);
+ packet.setSendNo(datas[5] & 0xFF);
+ packet.setOnSendPacket(new OnSendPacket() {
+ @Override
+ public void onSuccess(Packet packet) {
+ synchronized (lock){
+ sendList.remove(packet);
+ }
+ try{
+ sendPacket.onSuccess(packet);
+ }catch (Exception ex){
+ LogUtil.e(TAG,"sendPacket.onSuccess",ex);
+ }
+ }
+
+ @Override
+ public void onFail(Packet packet) {
+ synchronized (lock){
+ sendList.remove(packet);
+ }
+ try{
+ sendPacket.onFail(packet);
+ }catch (Exception ex){
+ LogUtil.e(TAG,"sendPacket.onFail",ex);
+ }
+ }
+ });
+ synchronized (lock){
+ if(!exsit(packet)){
+ sendList.add(packet);
+ }
+ }
+ if(service != null){
+ service.immediately();
+ }
+ }
+
+ public List getSendList() {
+ return sendList;
+ }
+
+ private boolean exsit(Packet packet){
+ for(Packet packet1: sendList){
+ if(packet.getSendNo() == packet1.getSendNo()){
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public Packet findPacket(int sendNo){
+ for(Packet packet: sendList){
+ if(packet.getSendNo() == sendNo){
+ return packet;
+ }
+ }
+ return null;
+ }
+}
diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/BaseInfo.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/BaseInfo.java
new file mode 100644
index 0000000..31183ef
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/BaseInfo.java
@@ -0,0 +1,103 @@
+package com.sunvote.xpadapi.service.bean;
+
+public class BaseInfo {
+ private int baseId;//基站编号
+ private int idMode;//基站识别模式,1编号、2序列号
+ private int confId;//会议资料UID编号,1-65535,高位字节在前
+ private int billId;//议题编号
+ private int pageNo; //议案页码
+ private int authCode;//授权号,2字节,高位在前,0-0xFFFF
+ private int login;//登录申请模式(后台签到模式),是否需要IC卡、登录码(
+ private int report;//表决器报告状态模式和指定语言
+ private int offTime;//自动关机时间
+ private int attrib;//表决器特性:背光模式+蜂鸣器模式等等
+ private String baseName; //基站名称,最多12字节
+
+ public int getBaseId() {
+ return baseId;
+ }
+
+ public void setBaseId(int baseId) {
+ this.baseId = baseId;
+ }
+
+ public int getIdMode() {
+ return idMode;
+ }
+
+ public void setIdMode(int idMode) {
+ this.idMode = idMode;
+ }
+
+ public int getConfId() {
+ return confId;
+ }
+
+ public void setConfId(int confId) {
+ this.confId = confId;
+ }
+
+ public int getBillId() {
+ return billId;
+ }
+
+ public void setBillId(int billId) {
+ this.billId = billId;
+ }
+
+ public int getPageNo() {
+ return pageNo;
+ }
+
+ public void setPageNo(int pageNo) {
+ this.pageNo = pageNo;
+ }
+
+ public int getAuthCode() {
+ return authCode;
+ }
+
+ public void setAuthCode(int authCode) {
+ this.authCode = authCode;
+ }
+
+ public int getLogin() {
+ return login;
+ }
+
+ public void setLogin(int login) {
+ this.login = login;
+ }
+
+ public int getReport() {
+ return report;
+ }
+
+ public void setReport(int report) {
+ this.report = report;
+ }
+
+ public int getOffTime() {
+ return offTime;
+ }
+
+ public void setOffTime(int offTime) {
+ this.offTime = offTime;
+ }
+
+ public int getAttrib() {
+ return attrib;
+ }
+
+ public void setAttrib(int attrib) {
+ this.attrib = attrib;
+ }
+
+ public String getBaseName() {
+ return baseName;
+ }
+
+ public void setBaseName(String baseName) {
+ this.baseName = baseName;
+ }
+}
diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/BaseVoteInfo.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/BaseVoteInfo.java
new file mode 100644
index 0000000..091bc28
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/BaseVoteInfo.java
@@ -0,0 +1,72 @@
+package com.sunvote.xpadapi.service.bean;
+
+import com.sunvote.xpadapi.service.listener.IModesVoteInfo;
+
+/**
+ * 字节 标识符 描述
+ 1 CMD 0x72 投票信标变化
+ 2 BADDH 基站编号,保证有效数据从第3字节开始,和查询指令相同
+ 3,4 NOWT 时标值,2字节,高位在前
+ 从投票启动开始的时间,用于表决器同步计时,20ms为单位,最大约21分钟,最大0xFFFF不自动变为0
+ 5 DATAPOS 表决序号(结果记录序号)
+ 1-0xFF,值发生变化的时候,代表是新的一轮表决开始
+
+ 6 MODE 投票模式
+ Bit7=1表示继续表决,表决器重新提交数据,用于系统恢复,表决器可继续输入或使用原先结果;=0 正常表决
+ 低7位是表决模式:
+ 1-9是政务应用 10-19商务应用和教育 20-29多项和批次 30-39二维表评测 40-50管理类
+
+ 7-25 MODES 投票参数,具体和MODE有关,不同模式下参数意义不同
+
+ */
+public class BaseVoteInfo {
+
+ private int baseId;//[1]基站编号
+ private int nowT;//[2,3]
+ private int dataPos;//[4]
+ private int mode;// [5] 表决模式
+
+ private IModesVoteInfo modes;
+
+ public int getBaseId() {
+ return baseId;
+ }
+
+ public void setBaseId(int baseId) {
+ this.baseId = baseId;
+ }
+
+ public int getNowT() {
+ return nowT;
+ }
+
+ public void setNowT(int nowT) {
+ this.nowT = nowT;
+ }
+
+ public int getDataPos() {
+ return dataPos;
+ }
+
+ public void setDataPos(int dataPos) {
+ this.dataPos = dataPos;
+ }
+
+ public int getMode() {
+ return mode;
+ }
+
+ public void setMode(int mode) {
+ this.mode = mode;
+ }
+
+ public IModesVoteInfo getModes() {
+ return modes;
+ }
+
+ public void setModes(byte[] datas) {
+ this.modes = modes;
+ }
+
+
+}
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
new file mode 100644
index 0000000..4b97372
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/BatchNumberVote.java
@@ -0,0 +1,65 @@
+package com.sunvote.xpadapi.service.bean;
+
+import com.sunvote.xpadapi.service.SerialManager;
+
+import java.util.Arrays;
+
+/**
+ * 批次评分值结果
+ */
+public class BatchNumberVote extends Vote {
+
+ public static final int AnsType_BatchNumber = 23;
+
+ private int personId;
+ private int projectId;
+ private String strNum;
+
+ public BatchNumberVote(int personId, int projectId, String strNum) {
+ super(AnsType_BatchNumber);
+ this.personId = personId;
+ this.projectId = projectId;
+ this.strNum = strNum;
+ }
+
+ public BatchNumberVote() {
+ super(AnsType_BatchNumber);
+ }
+
+ public void setPersonId(int personId) {
+ this.personId = personId;
+ }
+
+ public void setProjectId(int projectId) {
+ this.projectId = projectId;
+ }
+
+ public void setStrNum(String strNum) {
+ this.strNum = strNum;
+ }
+
+ @Override
+ public byte[] toBytes() {
+ 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] = SerialManager.getInstance().getSeq();
+ mBuffer[6] = msgType;
+ mBuffer[7] = (byte) ansType;
+ mBuffer[8] = (byte)ok;// ALLOK
+ if (projectId != 0) {
+ mBuffer[9] = (byte) personId;
+ mBuffer[10] = (byte) projectId;
+ } else {
+ mBuffer[9] = (byte) (personId >> 8);
+ mBuffer[10] = (byte) (personId & 0xff);
+ }
+ byte[] val = util_encodeBCD(strNum.getBytes());
+ System.arraycopy(val, 0, mBuffer, 11, 4);
+ return mBuffer;
+ }
+}
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
new file mode 100644
index 0000000..8c08a25
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/BatchSingleVote.java
@@ -0,0 +1,54 @@
+package com.sunvote.xpadapi.service.bean;
+
+import com.sunvote.xpadapi.service.SerialManager;
+
+import java.util.Arrays;
+
+public class BatchSingleVote extends Vote{
+
+ public static final int AnsType_BatchSingle = 21 ;
+
+ private int num;
+ private int val ;
+
+ public BatchSingleVote(int num, int val) {
+ super(AnsType_BatchSingle);
+ this.num = num;
+ this.val = val;
+ }
+
+ /**
+ * 不设计任何值,则为取消全部投票
+ */
+ public BatchSingleVote() {
+ super(AnsType_BatchSingle);
+ }
+
+ public void setNum(int num) {
+ this.num = num;
+ }
+
+ public void setVal(int val) {
+ this.val = val;
+ }
+
+ @Override
+ public byte[] toBytes() {
+ 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) SerialManager.getInstance().getSeq();
+ mBuffer[6] = msgType;
+ mBuffer[7] = (byte) ansType;
+ mBuffer[8] = (byte)ok;// ALLOK
+ int pos = 9;
+ mBuffer[pos++] = (byte) (num >> 8);
+ mBuffer[pos++] = (byte) (num & 0xff);
+ mBuffer[pos++] = (byte) val;
+ return mBuffer;
+ }
+}
diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/HeartBeat.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/HeartBeat.java
new file mode 100644
index 0000000..676f175
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/HeartBeat.java
@@ -0,0 +1,39 @@
+package com.sunvote.xpadapi.service.bean;
+
+import java.util.Arrays;
+
+public class HeartBeat {
+
+ private byte volt;
+ private byte keyinStatus;
+
+ public HeartBeat(byte volt, byte keyinStatus) {
+ this.volt = volt;
+ this.keyinStatus = keyinStatus;
+ }
+
+ public HeartBeat() {
+ }
+
+ public void setKeyinStatus(byte keyinStatus) {
+ this.keyinStatus = keyinStatus;
+ }
+
+ public void setVolt(byte volt) {
+ this.volt = volt;
+ }
+
+ public byte[] toBytes(){
+ 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] = 0x70;
+ mBuffer[5] = 0x07;
+ mBuffer[6] = (byte) volt;
+ mBuffer[7] = (byte) keyinStatus;
+ return mBuffer;
+ }
+}
diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/KeypadInfo.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/KeypadInfo.java
new file mode 100644
index 0000000..23d698a
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/KeypadInfo.java
@@ -0,0 +1,59 @@
+package com.sunvote.xpadapi.service.bean;
+
+public class KeypadInfo {
+
+ private int cmd1;//8:match 9:config
+ private int ok;
+ private int chan;
+ private int keyId;//键盘编号,高位在前
+ private String keySn;//6字节键盘序列号
+ private String matchCode;//4字节配对码
+
+ public int getCmd1() {
+ return cmd1;
+ }
+
+ public void setCmd1(int cmd1) {
+ this.cmd1 = cmd1;
+ }
+
+ public int getOk() {
+ return ok;
+ }
+
+ public void setOk(int ok) {
+ this.ok = ok;
+ }
+
+ public int getChan() {
+ return chan;
+ }
+
+ public void setChan(int chan) {
+ this.chan = chan;
+ }
+
+ public int getKeyId() {
+ return keyId;
+ }
+
+ public void setKeyId(int keyId) {
+ this.keyId = keyId;
+ }
+
+ public String getKeySn() {
+ return keySn;
+ }
+
+ public void setKeySn(String keySn) {
+ this.keySn = keySn;
+ }
+
+ public String getMatchCode() {
+ return matchCode;
+ }
+
+ public void setMatchCode(String matchCode) {
+ this.matchCode = matchCode;
+ }
+}
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
new file mode 100644
index 0000000..2efde4f
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/LoginInVote.java
@@ -0,0 +1,40 @@
+package com.sunvote.xpadapi.service.bean;
+
+import com.sunvote.xpadapi.service.SerialManager;
+
+import java.util.Arrays;
+
+public class LoginInVote extends Vote{
+
+ public static final int AnsType_LoginIn = 16 ;
+
+ private String info ;
+
+ public LoginInVote(String info) {
+ super(AnsType_LoginIn);
+ this.info = info;
+ }
+
+ public void setInfo(String info) {
+ this.info = info;
+ }
+
+ public byte[] toBytes(){
+ 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] = SerialManager.getInstance().getSeq();
+
+ mBuffer[6] = (byte)msgType;
+ mBuffer[7] = (byte) ansType;
+ mBuffer[8] = 3;//3 签到信息按BCD码格式
+ byte[] val = util_encodeBCD(info.getBytes());
+ System.arraycopy(val, 0, mBuffer, 9, 9);
+ return mBuffer;
+ }
+}
diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/ModelInfo.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/ModelInfo.java
new file mode 100644
index 0000000..ee5a087
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/ModelInfo.java
@@ -0,0 +1,31 @@
+package com.sunvote.xpadapi.service.bean;
+
+public class ModelInfo {
+ private int mode;//模块当前主从模式 1 基站模式(主) 2 键盘模式(从)
+ private int hModel;//硬件型号,数字
+ private String sVer;//固件版本,3位数字,例如 0.1.0
+
+ public int getMode() {
+ return mode;
+ }
+
+ public void setMode(int mode) {
+ this.mode = mode;
+ }
+
+ public int gethModel() {
+ return hModel;
+ }
+
+ public void sethModel(int hModel) {
+ this.hModel = hModel;
+ }
+
+ public String getsVer() {
+ return sVer;
+ }
+
+ public void setsVer(String sVer) {
+ this.sVer = sVer;
+ }
+}
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
new file mode 100644
index 0000000..d70f869
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/NumberVote.java
@@ -0,0 +1,43 @@
+package com.sunvote.xpadapi.service.bean;
+
+import com.sunvote.xpadapi.service.SerialManager;
+
+import java.util.Arrays;
+
+public class NumberVote extends Vote{
+
+ public static final int AnsType_Number = 3;
+ private String info;
+
+ public void setInfo(String info) {
+ this.info = info;
+ }
+
+ public NumberVote(String info) {
+ super(AnsType_Number);
+ this.info = info;
+ }
+
+ public NumberVote() {
+ super(AnsType_Number);
+ }
+
+ public byte[] toBytes(){
+ 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] = SerialManager.getInstance().getSeq();
+ mBuffer[6] = (byte)msgType;
+ mBuffer[7] = (byte) ansType;
+ byte[] val = util_encodeBCD(info.getBytes());
+ System.arraycopy(val, 0, mBuffer, 8, 8);
+
+ return mBuffer;
+ }
+
+
+}
diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/OnLineInfo.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/OnLineInfo.java
new file mode 100644
index 0000000..4e8e9ad
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/OnLineInfo.java
@@ -0,0 +1,94 @@
+package com.sunvote.xpadapi.service.bean;
+
+public class OnLineInfo {
+ private int onLine; //键盘是否在线 1 在线 2 离线
+ private int idMode;//基站的识别模式
+ private int chan; //当前频点号
+ private int rssi; //接收到基站的信号强度RSSI值,负数,越小表示信号越大
+ private int tx; //1表示刚才1秒内有提交数据过 0 表示没有
+ private int rx; //1 表示刚才1秒内收到过基站的投票指令(特指投票中) 0 表示没有
+ private int baseId;
+ private int keyId;
+ private String keySn;
+ private int comError=0;
+
+ public int getOnLine() {
+ return onLine;
+ }
+
+ public void setOnLine(int onLine) {
+ this.onLine = onLine;
+ }
+
+ public int getIdMode() {
+ return idMode;
+ }
+
+ public void setIdMode(int idMode) {
+ this.idMode = idMode;
+ }
+
+ public int getChan() {
+ return chan;
+ }
+
+ public void setChan(int chan) {
+ this.chan = chan;
+ }
+
+ public int getRssi() {
+ return rssi;
+ }
+
+ public void setRssi(int rssi) {
+ this.rssi = rssi;
+ }
+
+ public int getTx() {
+ return tx;
+ }
+
+ public void setTx(int tx) {
+ this.tx = tx;
+ }
+
+ public int getRx() {
+ return rx;
+ }
+
+ public void setRx(int rx) {
+ this.rx = rx;
+ }
+
+ public int getBaseId() {
+ return baseId;
+ }
+
+ public void setBaseId(int baseId) {
+ this.baseId = baseId;
+ }
+
+ public int getKeyId() {
+ return keyId;
+ }
+
+ public void setKeyId(int keyId) {
+ this.keyId = keyId;
+ }
+
+ public String getKeySn() {
+ return keySn;
+ }
+
+ public void setKeySn(String keySn) {
+ this.keySn = keySn;
+ }
+
+ public int getComError() {
+ return comError;
+ }
+
+ public void setComError(int comError) {
+ this.comError = comError;
+ }
+}
diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/Packet.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/Packet.java
new file mode 100644
index 0000000..b2c84c7
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/Packet.java
@@ -0,0 +1,67 @@
+package com.sunvote.xpadapi.service.bean;
+
+import com.sunvote.xpadapi.service.listener.OnSendPacket;
+
+public class Packet {
+
+ public static final int OVER_TIME_COUNTS = 6;
+
+ public static final int BaseStatusNum = 1 ;
+ public static final int VoteStatusNum = 2 ;
+ public static final int ExecKeypadMatchNum = 6 ;
+ public static final int GetWorkModeNum = 11 ;
+ public static final int SetWorkModeNum = 12 ;
+ public static final int GetKeypadParam = 13 ;
+
+ public static final int CommunicationTestMatchNum = 30 ;
+
+ private int sendNo ;
+ private byte[] datas;
+ private int sendCount = 0 ;
+ private boolean isSync = false;
+
+ private OnSendPacket onSendPacket;
+
+ public int getSendNo() {
+ return sendNo;
+ }
+
+ public void setSendNo(int sendNo) {
+ this.sendNo = sendNo;
+ }
+
+ public byte[] getDatas() {
+ return datas;
+ }
+
+ public void setDatas(byte[] datas) {
+ this.datas = datas;
+ }
+
+ public OnSendPacket getOnSendPacket() {
+ return onSendPacket;
+ }
+
+ public void setOnSendPacket(OnSendPacket onSendPacket) {
+ this.onSendPacket = onSendPacket;
+ }
+
+ public void addSendCount(){
+ sendCount ++ ;
+ }
+
+ public boolean needSend(){
+ if(sendCount < OVER_TIME_COUNTS){
+ return true;
+ }
+ return false;
+ }
+
+ public boolean isSync() {
+ return isSync;
+ }
+
+ public void setSync(boolean sync) {
+ isSync = sync;
+ }
+}
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
new file mode 100644
index 0000000..5cf081f
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/SelectOtherVote.java
@@ -0,0 +1,59 @@
+package com.sunvote.xpadapi.service.bean;
+
+import com.sunvote.xpadapi.service.SerialManager;
+import com.sunvote.xpadapi.service.XpadApiServiceInfoProxyManager;
+import com.sunvote.xpadapi.util.LogUtil;
+
+import java.util.Arrays;
+
+public class SelectOtherVote extends Vote {
+
+ public static final int AnsType_SelectOther = 26;
+
+ private int num;
+ private String info;
+
+ public SelectOtherVote(int num, String info) {
+ super(AnsType_SelectOther);
+ this.num = num;
+ this.info = info;
+ }
+
+ public SelectOtherVote() {
+ super(AnsType_SelectOther);
+ }
+
+ public void setNum(int num) {
+ this.num = num;
+ }
+
+ public void setInfo(String info) {
+ this.info = info;
+ }
+
+ @Override
+ public byte[] toBytes() {
+ 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] = SerialManager.getInstance().getSeq();// 流水号
+ mBuffer[6] = (byte)msgType;
+ mBuffer[7] = (byte) ansType;
+ mBuffer[8] = (byte) ok;// ALLOK
+ int pos = 9;
+ mBuffer[pos++] = (byte) (num >> 8);
+ mBuffer[pos++] = (byte) num;
+ mBuffer[pos++] = 0;// slot
+ try {
+ byte[] name = info.getBytes(XpadApiServiceInfoProxyManager.getInstance().getCharset());
+ System.arraycopy(name, 0, mBuffer, pos, name.length > 16 ? 16 : name.length);
+ } catch (Exception e) {
+ LogUtil.e(XpadApiServiceInfoProxyManager.TAG, "SelectOtherVote", e);
+ }
+ return mBuffer;
+ }
+}
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
new file mode 100644
index 0000000..7de230e
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/SelectVote.java
@@ -0,0 +1,48 @@
+package com.sunvote.xpadapi.service.bean;
+
+import com.sunvote.xpadapi.service.SerialManager;
+
+import java.util.Arrays;
+
+public class SelectVote extends Vote{
+
+ public final static int SELECT_VOTE_TYPE = 2;
+
+ private int content;
+ private int time;
+
+ public SelectVote(int content, int time) {
+ super(SELECT_VOTE_TYPE);
+ this.content = content;
+ this.time = time;
+ }
+
+ public SelectVote() {
+ super(SELECT_VOTE_TYPE);
+ }
+ public void setContent(int content) {
+ this.content = content;
+ }
+
+ public void setTime(int time) {
+ this.time = time;
+ }
+
+ public byte[] toBytes(){
+ 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] = SerialManager.getInstance().getSeq();
+ mBuffer[6] = msgType;
+ mBuffer[7] = (byte) ansType;
+ mBuffer[8] = (byte) ((time >> 8) & 0xff);// 原来的计算居然是这样 没懂
+ mBuffer[9] = (byte) (time & 0xff);
+ mBuffer[10] = (byte) ((time >> 8) & 0xff);
+ mBuffer[11] = (byte) (time & 0xff);
+ return mBuffer;
+ }
+}
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
new file mode 100644
index 0000000..21a972d
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/ServiceTypeVote.java
@@ -0,0 +1,46 @@
+package com.sunvote.xpadapi.service.bean;
+
+import com.sunvote.xpadapi.service.SerialManager;
+
+import java.util.Arrays;
+
+/**
+ * 服务申请
+ */
+public class ServiceTypeVote extends Vote {
+
+ public static final int AnsType_Service = 33;
+
+ private int serviceType = 0;
+
+ public ServiceTypeVote(int serviceType) {
+ super(AnsType_Service);
+ this.serviceType = serviceType;
+ }
+
+ public ServiceTypeVote() {
+ super(AnsType_Service);
+ }
+
+ public void setServiceType(int serviceType) {
+ this.serviceType = serviceType;
+ }
+
+ @Override
+ public byte[] toBytes() {
+ 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] = SerialManager.getInstance().getSeq();// 流水号
+ mBuffer[6] = msgType;
+ mBuffer[7] = (byte) ansType;
+ mBuffer[8] = 4;
+ mBuffer[9] = (byte) serviceType;
+ mBuffer[10] = mBuffer[5];
+ return mBuffer;
+ }
+}
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
new file mode 100644
index 0000000..e004611
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/SingleVote.java
@@ -0,0 +1,38 @@
+package com.sunvote.xpadapi.service.bean;
+
+import com.sunvote.xpadapi.service.SerialManager;
+
+import java.util.Arrays;
+
+public class SingleVote extends Vote {
+
+ private int info;
+
+ public SingleVote(int info) {
+ super(1);
+ this.info = info;
+ }
+
+ public SingleVote() {
+ super(1);
+ }
+
+ public void setInfo(int info) {
+ this.info = info;
+ }
+
+ public byte[] toBytes() {
+ 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] = SerialManager.getInstance().getSeq();
+ mBuffer[6] = msgType;
+ mBuffer[7] = (byte) ansType;
+ mBuffer[8] = (byte) info;
+ return mBuffer;
+ }
+}
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
new file mode 100644
index 0000000..de9184c
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/Vote.java
@@ -0,0 +1,105 @@
+package com.sunvote.xpadapi.service.bean;
+
+import com.sunvote.xpadapi.service.SerialManager;
+
+import java.util.Arrays;
+
+public class Vote {
+
+ protected int ansType = 16;
+ protected static byte msgType = 1;// MSGTYPE 1:ID mode, 2:SN
+ private String info;
+ protected int ok;
+
+ public Vote(int ansType) {
+ this.ansType = ansType;
+ }
+
+ public static void setMsgTypeIdModel() {
+ msgType = 1;
+ }
+
+ public static void setMsgTypeSnModel() {
+ msgType = 2;
+ }
+
+ public void setInfo(String info) {
+ this.info = info;
+ }
+
+ public void setOk(int ok) {
+ this.ok = ok;
+ }
+
+ /**
+ * 把字符串形式转换为字节形式
+ */
+ protected byte[] util_encodeBCD(byte[] cs) {
+ byte[] rs = new byte[17];
+ Arrays.fill(rs, (byte) 0xff);//
+
+ int len = cs.length < 16 ? cs.length : 16;
+ int io = 0;
+
+ for (int i = 0; i < len; i += 2) {
+ int n = encodeBCD(cs[i]);
+ n <<= 4;
+ if (i + 1 == cs.length) {
+ rs[io++] = (byte) (n | 0xf);
+ break;
+ }
+
+ n |= encodeBCD(cs[i + 1]);
+ if (n < 0) {
+ break;
+ }
+ rs[io++] = (byte) n;
+ }
+ rs[++io] = 0;
+ return rs;
+ }
+
+ protected int encodeBCD(byte c) {
+ if (c >= 'a' && c <= 'f') {
+ return 10 + (c - 'a');
+ } else if (c >= '0' && c <= '9') {
+ return c - '0';
+ } else if (c >= 'A' && c <= 'F') {
+ return 10 + (c - 'A');
+ } else if (c == '.') {
+ return 0xE;
+ }
+ return -1;
+ }
+
+ public byte[] toBytes() {
+ 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] = SerialManager.getInstance().getSeq();
+ mBuffer[6] = msgType;
+ mBuffer[7] = (byte) ansType;
+ mBuffer[8] = (byte)ok;
+ int pos = 9;
+ if(info != null) {
+ String[] item = info.split(":");
+ if (item.length > 1) {
+ int num = Integer.parseInt(item[0]);
+ String val = item[1];
+ mBuffer[pos++] = (byte) (num >> 8);
+ mBuffer[pos++] = (byte) num;
+ mBuffer[pos++] = 0;// slot
+ try {
+ byte[] name = val.getBytes("GB2312");
+ System.arraycopy(name, 0, mBuffer, pos, name.length > 16 ? 16 : name.length);
+ } catch (Exception e) {
+ }
+ }
+ }
+ return mBuffer;
+ }
+}
diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/BaseInfoChanageListener.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/BaseInfoChanageListener.java
new file mode 100644
index 0000000..883d69a
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/BaseInfoChanageListener.java
@@ -0,0 +1,8 @@
+package com.sunvote.xpadapi.service.listener;
+
+import com.sunvote.xpadapi.service.bean.BaseInfo;
+
+public interface BaseInfoChanageListener {
+
+ void onBaseInfoChange(BaseInfo newBaseInfo);
+}
diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/BaseVoteInfoChanageListener.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/BaseVoteInfoChanageListener.java
new file mode 100644
index 0000000..9ab110a
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/BaseVoteInfoChanageListener.java
@@ -0,0 +1,8 @@
+package com.sunvote.xpadapi.service.listener;
+
+import com.sunvote.xpadapi.service.bean.BaseVoteInfo;
+
+public interface BaseVoteInfoChanageListener {
+
+ void onBaseVoteInfoListener(BaseVoteInfo newBaseVoteInfo);
+}
diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/IModesVoteInfo.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/IModesVoteInfo.java
new file mode 100644
index 0000000..78337a2
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/IModesVoteInfo.java
@@ -0,0 +1,6 @@
+package com.sunvote.xpadapi.service.listener;
+
+public interface IModesVoteInfo {
+
+
+}
diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/KeyPadinfoChanageListener.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/KeyPadinfoChanageListener.java
new file mode 100644
index 0000000..e3426f4
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/KeyPadinfoChanageListener.java
@@ -0,0 +1,8 @@
+package com.sunvote.xpadapi.service.listener;
+
+import com.sunvote.xpadapi.service.bean.KeypadInfo;
+
+public interface KeyPadinfoChanageListener {
+
+ void onKeyPadinfoChanage(KeypadInfo newKeypadInfo);
+}
diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/ModelInfoChanageListener.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/ModelInfoChanageListener.java
new file mode 100644
index 0000000..9c2c029
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/ModelInfoChanageListener.java
@@ -0,0 +1,8 @@
+package com.sunvote.xpadapi.service.listener;
+
+import com.sunvote.xpadapi.service.bean.ModelInfo;
+
+public interface ModelInfoChanageListener {
+
+ void onModelInfoChanage(ModelInfo newModelInfo);
+}
diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/OnDataReceiver.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/OnDataReceiver.java
new file mode 100644
index 0000000..9596a6f
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/OnDataReceiver.java
@@ -0,0 +1,17 @@
+package com.sunvote.xpadapi.service.listener;
+
+public interface OnDataReceiver {
+
+ /**
+ * 收到信息
+ * @param datas
+ */
+ void onDataReceiver(byte[] datas);
+
+ /**
+ * 发出的信息
+ * @param datas
+ */
+ void onDataSender(byte[] datas);
+
+}
diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/OnSendPacket.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/OnSendPacket.java
new file mode 100644
index 0000000..398b307
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/OnSendPacket.java
@@ -0,0 +1,10 @@
+package com.sunvote.xpadapi.service.listener;
+
+import com.sunvote.xpadapi.service.bean.Packet;
+
+public interface OnSendPacket {
+
+ void onSuccess(Packet packet);
+
+ void onFail(Packet packet);
+}
diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/OnSender.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/OnSender.java
new file mode 100644
index 0000000..4eaa0b9
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/OnSender.java
@@ -0,0 +1,8 @@
+package com.sunvote.xpadapi.service.listener;
+
+public interface OnSender {
+
+ void onSuccess(T t);
+
+ void onFail(T t);
+}
diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/OnlineInfoChanageListener.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/OnlineInfoChanageListener.java
new file mode 100644
index 0000000..7ac293a
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/OnlineInfoChanageListener.java
@@ -0,0 +1,8 @@
+package com.sunvote.xpadapi.service.listener;
+
+import com.sunvote.xpadapi.service.bean.OnLineInfo;
+
+public interface OnlineInfoChanageListener {
+
+ void onOnlineInfoChanage(OnLineInfo newOnlineInfo);
+}
diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/usb/UsbTransferManager.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/usb/UsbTransferManager.java
new file mode 100644
index 0000000..faffea1
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/usb/UsbTransferManager.java
@@ -0,0 +1,453 @@
+package com.sunvote.xpadapi.usb;
+
+import android.app.PendingIntent;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.hardware.usb.UsbDevice;
+import android.hardware.usb.UsbDeviceConnection;
+import android.hardware.usb.UsbEndpoint;
+import android.hardware.usb.UsbInterface;
+import android.hardware.usb.UsbManager;
+import android.os.Handler;
+import android.os.HandlerThread;
+
+
+import com.sunvote.xpadapi.util.LogUtil;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+/***
+ * @Auther Elvis
+ */
+public class UsbTransferManager {
+
+ public interface OnUsbConnectListener{
+ boolean onConnect(boolean isConnected);
+ }
+
+ public static final String TAG = UsbTransferManager.class.getSimpleName();
+ private static UsbTransferManager instance = null ;
+ private HandlerThread workThread = new HandlerThread("usb workThread");
+ private Handler workHandler = null;
+ private boolean stop = false;
+ private OnUsbConnectListener onUsbConnectListener;
+
+ public void setOnUsbConnectListener(OnUsbConnectListener onUsbConnectListener) {
+ this.onUsbConnectListener = onUsbConnectListener;
+ }
+
+ private UsbTransferManager(){
+ workThread.start();
+ workHandler = new Handler(workThread.getLooper());
+ }
+
+ public static UsbTransferManager getInstance(){
+ if(instance == null){
+ synchronized(UsbTransferManager.class){
+ if(instance == null){
+ instance = new UsbTransferManager();
+ }
+ }
+ }
+ return instance;
+ }
+
+ public void startWork(){
+ stop = false;
+ workHandler.post(usbConnectInit);
+ }
+
+ public void stopWork(){
+ mUsbDevice = null;
+ mUsbConnection = null;
+ epIn = null;
+ epOut = null;
+ workHandler.removeCallbacks(usbConnectInit);
+ workHandler.removeCallbacks(usbConnect);
+ workHandler.removeCallbacks(usbConnectionReceiverTask);
+ stop = true;
+ }
+
+ private UsbOutputStream outputStream = new UsbOutputStream();
+ private UsbInputStream inputStream = new UsbInputStream();
+
+ public UsbInputStream getInputStream() {
+ return inputStream;
+ }
+
+ public UsbOutputStream getOutputStream() {
+ return outputStream;
+ }
+
+ private long lastOpenTime;
+ private class UsbPermissionReceiver extends BroadcastReceiver {
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ if (ACTION_USB_PERMISSION.equals(action)) {
+ synchronized (this) {
+ UsbDevice device = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
+ if (device.getDeviceName().equals(mUsbDevice.getDeviceName())) {
+ if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
+ // 授权成功,在这里进行打开设备操作
+ if (System.currentTimeMillis() - lastOpenTime > 1000) {
+ lastOpenTime = System.currentTimeMillis();
+ workHandler.removeCallbacks(usbConnectInit);
+ workHandler.removeCallbacks(usbConnect);
+ if(!stop){
+ workHandler.postDelayed(usbConnect,0);
+ }
+ }
+ }else{
+ if(!stop){
+ workHandler.postDelayed(usbConnectInit,20000);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private Runnable usbConnectionReceiverTask = new Runnable() {
+ @Override
+ public void run() {
+ if (usbManager != null) {
+ HashMap map = usbManager.getDeviceList();
+ boolean find = false;
+ for (UsbDevice device : map.values()) {
+ LogUtil.d(TAG, "找到基站: Vid:" + device.getVendorId() + " Pid:" + device.getProductId());
+ if (device.getVendorId() == VendorID && device.getProductId() == ProductID
+ || device.getVendorId() == VendorID_2 && device.getProductId() == ProductID_2
+ || device.getVendorId() == VendorID_3 && device.getProductId() == ProductID_3) {
+ find = true;
+ workHandler.postDelayed(usbConnectionReceiverTask, 1000);
+ break;
+ }
+ }
+ if (!find) {
+ stopWork();
+ startWork();
+ }
+ }
+ }
+ };
+
+ private Runnable usbConnectInit = new Runnable() {
+ @Override
+ public void run() {
+ LogUtil.i(TAG, "发起USB初始化!");
+ boolean find = false;
+ workHandler.removeCallbacks(usbConnectionReceiverTask);
+ if(usbManager != null) {
+ HashMap map = usbManager.getDeviceList();
+ for (UsbDevice device : map.values()) {
+ LogUtil.d(TAG, "找到基站: Vid:" + device.getVendorId() + " Pid:" + device.getProductId());
+ if (device.getVendorId() == VendorID && device.getProductId() == ProductID
+ || device.getVendorId() == VendorID_2 && device.getProductId() == ProductID_2
+ || device.getVendorId() == VendorID_3 && device.getProductId() == ProductID_3) {
+ mUsbDevice = device;
+ find = true;
+ if (!usbManager.hasPermission(device)) {
+ if (usbPermissionReceiver == null) {
+ usbPermissionReceiver = new UsbPermissionReceiver();
+ }
+ // 申请权限
+ Intent intent = new Intent(ACTION_USB_PERMISSION);
+ PendingIntent mPermissionIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0);
+ IntentFilter permissionFilter = new IntentFilter(ACTION_USB_PERMISSION);
+ mContext.registerReceiver(usbPermissionReceiver, permissionFilter);
+ usbManager.requestPermission(device, mPermissionIntent);
+ if(!stop){
+ workHandler.postDelayed(usbConnectInit,20 * 1000);
+ }
+ } else {
+ if(!stop){
+ workHandler.postDelayed(usbConnect,10);
+ }
+ }
+ }
+ }
+
+ }
+ if(!find){
+ workHandler.removeCallbacks(usbConnectInit);
+ if(!stop){
+ workHandler.postDelayed(usbConnectInit,2000);
+ }
+ }
+ }
+ };
+
+
+ private Runnable usbConnect = new Runnable() {
+ @Override
+ public void run() {
+ LogUtil.i(TAG, "发起USB键盘连接!");
+ if(openUsbDevice()){
+ if(onUsbConnectListener != null){
+ onUsbConnectListener.onConnect(true);
+ }
+ workHandler.postDelayed(usbConnectionReceiverTask,2000);
+ };
+ }
+ };
+
+ private Runnable readData = new Runnable() {
+ @Override
+ public void run() {
+ byte[] datas = receiveUsbRequestData();
+ LogUtil.i(TAG, "RECEIVEA DATA:", datas);
+ if(datas != null) {
+ int length = datas.length;
+ try {
+ try {
+ lock.lock();
+ if (linkedList.size() < MAX_CACHE_SIZE) {
+ for (int i = length - 1; i >= 0; i--) {
+ linkedList.push(datas[i]);
+ }
+ }
+ } finally {
+ empty.signal();
+ lock.unlock();
+ }
+ } catch (Exception e) {
+ LogUtil.e(TAG, "UDP receiver message", e);
+ close = true;
+ }
+ if(!stop){
+ workHandler.post(readData);
+ }
+ }else{
+ stopWork();
+ startWork();
+ }
+
+ }
+ };
+
+ /**
+ * 打开连接
+ *
+ * @paramdevice
+ */
+ private boolean openUsbDevice() {
+
+ if (mUsbDevice == null)
+ return false;
+
+ if(mUsbDevice.getInterfaceCount() == 0){
+ return false;
+ }
+ mUsbInterface = mUsbDevice.getInterface(0);
+ setEndpoint(mUsbInterface);
+ mUsbConnection = usbManager.openDevice(mUsbDevice);
+ LogUtil.i(TAG,"打开USB连接");
+ if (mUsbConnection != null) {
+ return mUsbConnection.claimInterface(mUsbInterface, true);
+ }
+ return false;
+ }
+
+ private int sendDataBulkTransfer(byte[] buffer) {
+ final int length = buffer.length;
+ int ref = -100;
+ if (epOut != null && mUsbConnection != null) {
+ ref = mUsbConnection.bulkTransfer(epOut, buffer, length, 100);
+ mUsbConnection.claimInterface(mUsbInterface, true);
+ LogUtil.d(TAG, "发送数据成功有:" + ref);
+ if(ref <0 ){
+ if(onUsbConnectListener != null){
+ onUsbConnectListener.onConnect(false);
+ }
+ workHandler.removeCallbacks(usbConnectionReceiverTask);
+ workHandler.post(usbConnectionReceiverTask);
+ }
+ }else{
+ LogUtil.d(TAG, "未连接:" + ref);
+ }
+ return ref;
+ }
+
+ public byte[] receiveUsbRequestData() {
+ if(epIn != null && mUsbConnection != null) {
+ byte[] bytes = new byte[epIn.getMaxPacketSize()];
+ int ret = mUsbConnection.bulkTransfer(epIn, bytes, bytes.length, 100);
+ if (ret > 0) {
+ return bytes;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * UsbInterface 进行端点设置和通讯
+ *
+ * @param intf
+ */
+ private void setEndpoint(UsbInterface intf) {
+ if (intf == null)
+ return;
+ // 设置接收数据的端点
+ if (intf.getEndpoint(0) != null) {
+ epIn = intf.getEndpoint(0);
+ }
+ // 当端点为2的时候
+ if (intf.getEndpointCount() == 2) {
+ // 设置发送数据的断点
+ if (intf.getEndpoint(1) != null)
+ epOut = intf.getEndpoint(1);
+ }
+ }
+
+ public void setUsbManager(UsbManager usbManager) {
+ this.usbManager = usbManager;
+ }
+
+ public void setContext(Context mContext) {
+ this.mContext = mContext;
+ }
+
+ public class UsbOutputStream extends OutputStream{
+
+ @Override
+ public void write(int b) throws IOException {
+ sendDataBulkTransfer(new byte[]{(byte)b});
+ }
+
+ @Override
+ public void write(byte[] b) throws IOException {
+ sendDataBulkTransfer(b);
+ }
+
+ @Override
+ public void write(byte[] b, int off, int len) throws IOException {
+ byte[] temp = new byte[len];
+ System.arraycopy(b, off, temp, 0, len);
+ sendDataBulkTransfer(temp);
+ }
+ }
+
+ private LinkedList linkedList = new LinkedList();
+ public long MAX_CACHE_SIZE = 4 * 1024;
+ private Lock lock = new ReentrantLock();
+ private Condition empty = lock.newCondition();
+ private boolean close = false;
+ public class UsbInputStream extends InputStream{
+ @Override
+ public int read() throws IOException {
+ if (close) {
+ throw new IOException("the stream has closed");
+ }
+
+ try {
+ lock.lock();
+ while (linkedList.isEmpty()) {
+ try {
+ empty.await();
+ } catch (InterruptedException e) {
+ LogUtil.e(TAG,e);
+ }
+ }
+ return linkedList.pop();
+ } finally {
+ lock.unlock();
+ }
+ }
+
+
+ public boolean isClose() {
+ return close;
+ }
+
+ @Override
+ public void close() throws IOException {
+ close = true;
+ super.close();
+ }
+
+ @Override
+ public int read(byte[] buffer) throws IOException {
+ try {
+ lock.lock();
+ if (buffer == null) {
+ throw new IOException("buffer is empty");
+ }
+ if (close) {
+ throw new IOException("the stream has closed");
+ }
+
+ while (linkedList.isEmpty()) {
+ try {
+ empty.await();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ int index = 0;
+ while (index < buffer.length && !linkedList.isEmpty()) {
+ buffer[index++] = linkedList.pop();
+ }
+ return index;
+ } finally {
+ lock.unlock();
+ }
+ }
+
+
+ @Override
+ public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException {
+ try {
+ lock.lock();
+ if (buffer == null) {
+ throw new IOException("buffer is empty");
+ }
+ if (close) {
+ throw new IOException("the stream has closed");
+ }
+
+ while (linkedList.isEmpty()) {
+ try {
+ empty.await();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ int index = 0;
+ while (index < byteCount && !linkedList.isEmpty()) {
+ index++;
+ buffer[byteOffset++] = linkedList.pop();
+ }
+ return index;
+ } finally {
+ lock.unlock();
+ }
+ }
+ }
+
+ private UsbManager usbManager ;
+ private UsbDevice mUsbDevice;
+ private UsbDeviceConnection mUsbConnection;
+ private UsbInterface mUsbInterface;
+ private UsbEndpoint epOut, epIn;
+ private UsbPermissionReceiver usbPermissionReceiver;
+ private Context mContext ;
+
+ private static final int VendorID = 0x03eb;
+ private static final int ProductID = 0x6201;
+ private static final int VendorID_2 = 0x0d8c;
+ private static final int ProductID_2 = 0xEA10;
+ private static final int VendorID_3 = 0x2F70;
+ private static final int ProductID_3 = 0xEA10;
+ private final String ACTION_USB_PERMISSION = "com.hhd.USB_PERMISSION";
+ private boolean isUsbReceiver = false;
+}
diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/util/ByteUtils.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/util/ByteUtils.java
new file mode 100644
index 0000000..0db81cf
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/util/ByteUtils.java
@@ -0,0 +1,137 @@
+package com.sunvote.xpadapi.util;
+
+public class ByteUtils {
+
+ private ByteUtils() {
+ }
+
+ public static String bytesToHexString(byte[] src, int length) {
+ StringBuilder stringBuilder = new StringBuilder("");
+ if (src == null || src.length <= 0) {
+ return null;
+ }
+ for (int i = 0; i < src.length && i < length; i++) {
+ int v = src[i] & 0xFF;
+ String hv = Integer.toHexString(v);
+ if (hv.length() < 2) {
+ stringBuilder.append(0);
+ }
+ stringBuilder.append(hv);
+ stringBuilder.append(" ");
+ }
+ return stringBuilder.toString();
+ }
+
+ public static String bytesToHexString(byte[] src) {
+ StringBuilder stringBuilder = new StringBuilder("");
+ if (src == null || src.length <= 0) {
+ return null;
+ }
+ for (int i = 0; i < src.length; i++) {
+ int v = src[i] & 0xFF;
+ String hv = Integer.toHexString(v);
+ if (hv.length() < 2) {
+ stringBuilder.append(0);
+ }
+ stringBuilder.append(hv);
+ stringBuilder.append(" ");
+ }
+ return stringBuilder.toString();
+ }
+
+ public static int findBytes(byte[] source,byte[] find,int index){
+ int flag = -1;
+ for (int j = index; j < source.length; j++) {
+ if (source.length >= j + find.length) {
+ if (compareByte(source, j, find)) {
+ flag = j;
+ break;
+ }
+ }
+ }
+ return flag;
+ }
+
+ public static int byte1ToInt(byte b) {
+ int ret = 0;
+ ret += (b & 0x000000FF);
+ return ret;
+ }
+
+ private static boolean compareByte(byte[] source, int start, byte[] find) {
+ if (source.length >= start + find.length) {
+ for (int i = 0; i < find.length; i++) {
+ if (source[start + i] != find[i]) {
+ return false;
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Convert hex string to byte[]
+ *
+ * @param hexString the hex string
+ * @return byte[]
+ */
+ public static byte[] hexStringToBytes(String hexString) {
+ if (hexString == null || hexString.equals("")) {
+ return null;
+ }
+ hexString = hexString.toUpperCase();
+ int length = hexString.length() / 2;
+ char[] hexChars = hexString.toCharArray();
+ byte[] d = new byte[length];
+ for (int i = 0; i < length; i++) {
+ int pos = i * 2;
+ d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1]));
+ }
+ return d;
+ }
+
+ /**
+ * Convert char to byte
+ *
+ * @param c char
+ * @return byte
+ */
+ private static byte charToByte(char c) {
+ return (byte) "0123456789ABCDEF".indexOf(c);
+ }
+
+
+ public static byte[] intToBytes(int value) {
+ byte[] src = new byte[4];
+ src[3] = (byte) ((value >> 24) & 0xFF);
+ src[2] = (byte) ((value >> 16) & 0xFF);
+ src[1] = (byte) ((value >> 8) & 0xFF);
+ src[0] = (byte) (value & 0xFF);
+ return src;
+ }
+
+ public static byte[] int2Bytes(int value) {
+ byte[] src = new byte[2];
+ src[0] = (byte) ((value >> 8) & 0xFF);
+ src[1] = (byte) (value & 0xFF);
+ return src;
+ }
+
+ public static int bytes2Int(byte[] src) {
+ int ret = ((src[1] & 0xFF) | ((src[0] & 0xFF) << 8));
+ return ret;
+ }
+
+ public static String getKeySn(byte[] data) {
+ String sn = "";
+ String CS = "0123456789ABCDEF";
+ for (int i = 0; i < 6; i++) {
+ sn += CS.charAt((data[i] >> 4) & 0xF);
+ sn += CS.charAt((data[i] >> 0) & 0xF);
+ }
+ return sn;
+
+ }
+}
+
diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/util/Cons.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/util/Cons.java
new file mode 100644
index 0000000..3166e06
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/util/Cons.java
@@ -0,0 +1,18 @@
+package com.sunvote.xpadapi.util;
+
+public final class Cons {
+
+ public static final int CMD_BASE_STATUS_CHANGE = 0x71;//基础信标变化
+ public static final int CMD_VOTE_STATUS_CHANGE = 0x72;//投票信标变化
+ public static final int CMD_VOTE_SEND_SUCCESS_RESPONSE = 0x73;//传输入成功通知
+
+ public static final int CMD_CHECK_BASE_STATUS_RESPONSE = 0xF0;//查询和设置各类应答
+ public static final int CMD_VOTE_RESULT_SEND_RESPONSE = 0xF3;//投票结果上传应答
+ public static final int CMD_FIRM_UPDATE_RESPONSE = 0xF8;//固件升级应答
+
+ public static final int CMD_UPLOAD_DATA_RESPONSE = 0x20; //上传指令
+ public static final int CMD_TRANSPARENT_TRANSMISSION = 0x30; //表决器管理类指令,自定义透传指令
+ public static final int CMD_MULTI_PCKAGE_DOWNLOAD = 0x40;//
+ public static final int CMD_COM_COMMUNICATION_TEST_RESPONSE = 0xB0; //串口测试应答
+
+}
diff --git a/C5/xpadapi/src/main/java/com/sunvote/xpadapi/util/Crc16.java b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/util/Crc16.java
new file mode 100644
index 0000000..37bc573
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/util/Crc16.java
@@ -0,0 +1,76 @@
+package com.sunvote.xpadapi.util;
+
+public final class Crc16 {
+ private static int[] crc_ta = { //CRC余式表
+ 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
+ 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
+ };
+
+
+ //标准Crc16效验
+ public static short crc16(byte[] data, int len) {
+ short Crc = 0;
+ byte da;
+ int i = 4;
+ while (len-- != 0) {
+ //da=Crc>>12; /* 暂存CRC的高四位 */
+ da = (byte) (Crc >>> 12); /* 暂存CRC的高四位 */
+ // Crc<<=4; /* CRC左移4位,相当于取CRC的低12位)*/
+ Crc <<= 4; /* CRC左移4位,相当于取CRC的低12位)*/
+ // Crc^=crc_ta[da^(*ptr/16)]; /* CRC的高4位和本字节的前半字节相加后查表计算CRC, 然后加上上一次CRC的余数 */
+ Crc ^= crc_ta[(da ^ (data[i] >>> 4)) & 0xf]; /* CRC的高4位和本字节的前半字节相加后查表计算CRC, 然后加上上一次CRC的余数 */
+ //da=Crc>>12; /* 暂存CRC的高4位 */
+ da = (byte) (Crc >>> 12); /* 暂存CRC的高4位 */
+ // Crc<<=4; /* CRC左移4位, 相当于CRC的低12位) */
+ Crc <<= 4; /* CRC左移4位, 相当于CRC的低12位) */
+ // Crc^=crc_ta[da^ (*ptr&0x0f)];
+ Crc ^= crc_ta[(da ^ data[i]) & 0x0f]; /* CRC的高4位和本字节的后半字节相加后查表计算CRC,
+ 然后再加上上一次CRC的余数 */
+ i++;
+ }
+ return (Crc);
+ }
+
+ public static boolean crc16Check(byte[] data) {
+
+ int xda, xdapoly;
+ int i, j, xdabit;
+ xda = 0xFFFF;
+ xdapoly = 0xA001; // (X**16 + X**15 + X**2 + 1)
+ for (i = 0; i < data.length - 2; i++) {
+ xda ^= data[i];
+ for (j = 0; j < 8; j++) {
+ xdabit = (int) (xda & 0x01);
+ xda >>= 1;
+ if (xdabit == 1)
+ xda ^= xdapoly;
+ }
+ }
+
+ return data[data.length - 2] == (int) (xda & 0xFF) && data[data.length - 1] == (int) (xda >> 8);
+
+ }
+
+ public static int getUnsignedByte(byte data) { //将data字节型数据转换为0~255 (0xFF 即BYTE)。
+ return data & 0x0FF;
+ }
+
+ public static int getUnsignedShort(short data) { //将data字节型数据转换为0~255 (0xFF 即BYTE)。
+ return data & 0x0FFFF;
+ }
+
+ private static void printDataBuf(byte[] buf, int length, String flag) {
+ String tmpStr = new String();
+ for (int i = 0; i < length; i++) {
+ tmpStr += String.format("%x ", buf[i]);
+ }
+ System.out.println(flag + ":" + tmpStr);
+ }
+
+ public static boolean checkPack(byte[] buf) {
+ if (buf.length > 4 && getUnsignedByte(buf[0]) == 0xF5 && getUnsignedByte(buf[1]) == 0xAA && getUnsignedByte(buf[2]) == 0xAA) {
+ return true;
+ }
+ return false;
+ }
+}
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
new file mode 100644
index 0000000..4dc7d4c
--- /dev/null
+++ b/C5/xpadapi/src/main/java/com/sunvote/xpadapi/util/LogUtil.java
@@ -0,0 +1,316 @@
+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/xpadapi/src/main/res/values/strings.xml b/C5/xpadapi/src/main/res/values/strings.xml
new file mode 100644
index 0000000..3fbf065
--- /dev/null
+++ b/C5/xpadapi/src/main/res/values/strings.xml
@@ -0,0 +1,3 @@
+
+ XpadApi
+
diff --git a/C5/xpadapi/src/test/java/com/sunvote/xpadapi/ExampleUnitTest.java b/C5/xpadapi/src/test/java/com/sunvote/xpadapi/ExampleUnitTest.java
new file mode 100644
index 0000000..554c455
--- /dev/null
+++ b/C5/xpadapi/src/test/java/com/sunvote/xpadapi/ExampleUnitTest.java
@@ -0,0 +1,17 @@
+package com.sunvote.xpadapi;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Example local unit test, which will execute on the development machine (host).
+ *
+ * @see Testing documentation
+ */
+public class ExampleUnitTest {
+ @Test
+ public void addition_isCorrect() {
+ assertEquals(4, 2 + 2);
+ }
+}
\ No newline at end of file
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/BaseCmd.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/BaseCmd.class
deleted file mode 100644
index 08ba779..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/BaseCmd.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/ICmd.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/ICmd.class
deleted file mode 100644
index cdf8f79..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/ICmd.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/app/BaseBeaconStateRequest.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/app/BaseBeaconStateRequest.class
deleted file mode 100644
index 8faf151..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/app/BaseBeaconStateRequest.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/app/ModuleHeartBeatCmd.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/app/ModuleHeartBeatCmd.class
deleted file mode 100644
index 5786e17..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/app/ModuleHeartBeatCmd.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/app/MutiPkgDownCmd.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/app/MutiPkgDownCmd.class
deleted file mode 100644
index c2f75ed..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/app/MutiPkgDownCmd.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/app/OtherCmd.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/app/OtherCmd.class
deleted file mode 100644
index 519be3d..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/app/OtherCmd.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/ConfirmBaseBeaconRequest.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/ConfirmBaseBeaconRequest.class
deleted file mode 100644
index 72eaa1f..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/ConfirmBaseBeaconRequest.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/ConfirmBaseBeaconResponse.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/ConfirmBaseBeaconResponse.class
deleted file mode 100644
index 18ea6b7..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/ConfirmBaseBeaconResponse.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/GetVoteDataRequest.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/GetVoteDataRequest.class
deleted file mode 100644
index 28d9c06..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/GetVoteDataRequest.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/GetVoteDataResponse.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/GetVoteDataResponse.class
deleted file mode 100644
index 3dc825a..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/GetVoteDataResponse.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/SettingBaseBeaconRequest.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/SettingBaseBeaconRequest.class
deleted file mode 100644
index 9450fbe..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/SettingBaseBeaconRequest.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/SettingBaseBeaconResponse.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/SettingBaseBeaconResponse.class
deleted file mode 100644
index ea7a370..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/SettingBaseBeaconResponse.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/SettingVoteRequest.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/SettingVoteRequest.class
deleted file mode 100644
index 9411a56..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/SettingVoteRequest.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/SettingVoteResponse.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/SettingVoteResponse.class
deleted file mode 100644
index 7918874..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/SettingVoteResponse.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/manager/BaseStationUpgradeCmd.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/manager/BaseStationUpgradeCmd.class
deleted file mode 100644
index d5fea18..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/manager/BaseStationUpgradeCmd.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/manager/FlatBaseStationSettingCmd.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/manager/FlatBaseStationSettingCmd.class
deleted file mode 100644
index dd648b9..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/manager/FlatBaseStationSettingCmd.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/manager/ReadOrWriteBaseStationConfigCmd.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/manager/ReadOrWriteBaseStationConfigCmd.class
deleted file mode 100644
index 7779c43..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/manager/ReadOrWriteBaseStationConfigCmd.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/manager/ReadOrWriteHardWareConfigCmd.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/manager/ReadOrWriteHardWareConfigCmd.class
deleted file mode 100644
index dc9f54c..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/manager/ReadOrWriteHardWareConfigCmd.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/manager/ReadOrWriteMatchCodeCmd.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/manager/ReadOrWriteMatchCodeCmd.class
deleted file mode 100644
index a75c7fe..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/manager/ReadOrWriteMatchCodeCmd.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/BaseStatusChangeRequest.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/BaseStatusChangeRequest.class
deleted file mode 100644
index a942a75..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/BaseStatusChangeRequest.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/BaseStatusChangeResponse.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/BaseStatusChangeResponse.class
deleted file mode 100644
index a24f1ba..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/BaseStatusChangeResponse.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/CustomCommandControl.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/CustomCommandControl.class
deleted file mode 100644
index 251b3e0..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/CustomCommandControl.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/DownloadSingletonPkg.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/DownloadSingletonPkg.class
deleted file mode 100644
index 2d3ebc5..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/DownloadSingletonPkg.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/DownloadSingletonPkgResponse.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/DownloadSingletonPkgResponse.class
deleted file mode 100644
index fcf3da5..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/DownloadSingletonPkgResponse.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/PushBaseCmd.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/PushBaseCmd.class
deleted file mode 100644
index 223923a..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/PushBaseCmd.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/ReadAndWriteHardwareInformation.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/ReadAndWriteHardwareInformation.class
deleted file mode 100644
index 62544da..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/ReadAndWriteHardwareInformation.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/ReadAndWriteVoterAllocation.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/ReadAndWriteVoterAllocation.class
deleted file mode 100644
index 9e609cf..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/ReadAndWriteVoterAllocation.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/VoteStatusChangeRequest.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/VoteStatusChangeRequest.class
deleted file mode 100644
index 4308e9b..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/VoteStatusChangeRequest.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/VoteStatusChangeResponse.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/VoteStatusChangeResponse.class
deleted file mode 100644
index 54e3aa3..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/VoteStatusChangeResponse.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/GetPkgStateRequest.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/GetPkgStateRequest.class
deleted file mode 100644
index 63beffc..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/GetPkgStateRequest.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/GetPkgStateResponse.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/GetPkgStateResponse.class
deleted file mode 100644
index 734e550..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/GetPkgStateResponse.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/KeyboardParameterStateRequest.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/KeyboardParameterStateRequest.class
deleted file mode 100644
index b225cd1..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/KeyboardParameterStateRequest.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/KeyboardParameterStateResponse.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/KeyboardParameterStateResponse.class
deleted file mode 100644
index e9b1aab..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/KeyboardParameterStateResponse.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/ModeOperationStateRequest.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/ModeOperationStateRequest.class
deleted file mode 100644
index d7c3be4..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/ModeOperationStateRequest.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/ModeOperationStateResponse.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/ModeOperationStateResponse.class
deleted file mode 100644
index ebf8e3d..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/ModeOperationStateResponse.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/QueryBeaconStateRequest.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/QueryBeaconStateRequest.class
deleted file mode 100644
index f8a80e4..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/QueryBeaconStateRequest.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/QueryBeaconStateResponse.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/QueryBeaconStateResponse.class
deleted file mode 100644
index 991bf91..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/QueryBeaconStateResponse.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/QueryOnlineStateRequest.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/QueryOnlineStateRequest.class
deleted file mode 100644
index d8a5cb9..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/QueryOnlineStateRequest.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/QueryOnlineStateResponse.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/QueryOnlineStateResponse.class
deleted file mode 100644
index 0e0742b..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/QueryOnlineStateResponse.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/StateBaseCmd.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/StateBaseCmd.class
deleted file mode 100644
index 839541b..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/StateBaseCmd.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/WorkPattenStateRequest.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/WorkPattenStateRequest.class
deleted file mode 100644
index f854583..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/WorkPattenStateRequest.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/WorkPattenStateResponse.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/WorkPattenStateResponse.class
deleted file mode 100644
index bcba761..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/WorkPattenStateResponse.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/CleanFlashStateRequest.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/CleanFlashStateRequest.class
deleted file mode 100644
index 5961ee7..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/CleanFlashStateRequest.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/CleanFlashStateResponse.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/CleanFlashStateResponse.class
deleted file mode 100644
index 66041cc..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/CleanFlashStateResponse.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/UpgradEntryStateRequest.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/UpgradEntryStateRequest.class
deleted file mode 100644
index 6e94fb0..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/UpgradEntryStateRequest.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/UpgradEntryStateResponse.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/UpgradEntryStateResponse.class
deleted file mode 100644
index dfebc7f..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/UpgradEntryStateResponse.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/UpgradeBaseCmd.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/UpgradeBaseCmd.class
deleted file mode 100644
index 0db63d4..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/UpgradeBaseCmd.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/UpgradeExitStateRequest.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/UpgradeExitStateRequest.class
deleted file mode 100644
index d3c1ec6..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/UpgradeExitStateRequest.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/UpgradeExitStateResponse.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/UpgradeExitStateResponse.class
deleted file mode 100644
index c222372..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/UpgradeExitStateResponse.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/WriteFlashStateRequest.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/WriteFlashStateRequest.class
deleted file mode 100644
index 348d909..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/WriteFlashStateRequest.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/WriteFlashStateResponse.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/WriteFlashStateResponse.class
deleted file mode 100644
index e83bd23..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/WriteFlashStateResponse.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upload/NumberingModeResult.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upload/NumberingModeResult.class
deleted file mode 100644
index f71c747..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upload/NumberingModeResult.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upload/SequenceFormatResult.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upload/SequenceFormatResult.class
deleted file mode 100644
index d2616c6..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upload/SequenceFormatResult.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upload/SingerUploadPkg.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upload/SingerUploadPkg.class
deleted file mode 100644
index eb382ae..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upload/SingerUploadPkg.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upload/TransferResult.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upload/TransferResult.class
deleted file mode 100644
index 4dc9549..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upload/TransferResult.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upload/UploadBaseCmd.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upload/UploadBaseCmd.class
deleted file mode 100644
index ac7b1c3..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upload/UploadBaseCmd.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/protocal/IProtocal.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/protocal/IProtocal.class
deleted file mode 100644
index 1260bf7..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/protocal/IProtocal.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/protocal/Protocol.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/protocal/Protocol.class
deleted file mode 100644
index 1b58b88..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/protocal/Protocol.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/utils/ConvertUtils.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/utils/ConvertUtils.class
deleted file mode 100644
index 07178f1..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/utils/ConvertUtils.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/utils/Crc16.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/utils/Crc16.class
deleted file mode 100644
index 8524ef6..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/utils/Crc16.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/classes/java/main/com/sunvote/utils/EncodeUtils.class b/C5/xpadprotocal/build/classes/java/main/com/sunvote/utils/EncodeUtils.class
deleted file mode 100644
index d320c23..0000000
--- a/C5/xpadprotocal/build/classes/java/main/com/sunvote/utils/EncodeUtils.class
+++ /dev/null
diff --git a/C5/xpadprotocal/build/libs/xpadprotocal.jar b/C5/xpadprotocal/build/libs/xpadprotocal.jar
deleted file mode 100644
index 5abb291..0000000
--- a/C5/xpadprotocal/build/libs/xpadprotocal.jar
+++ /dev/null
diff --git a/C5/xpadprotocal/build/tmp/jar/MANIFEST.MF b/C5/xpadprotocal/build/tmp/jar/MANIFEST.MF
deleted file mode 100644
index 59499bc..0000000
--- a/C5/xpadprotocal/build/tmp/jar/MANIFEST.MF
+++ /dev/null
@@ -1,2 +0,0 @@
-Manifest-Version: 1.0
-