Commit 6d9503bc64a8b64982063d4647b1208043372803

Authored by 孙向锦
1 parent 8ae9de2b

添加一个模块

Showing 109 changed files with 3361 additions and 8 deletions

Too many changes.

To preserve performance only 100 of 109 files are displayed.

C5/app/src/main/res/layout/fragment_result_multi_vote.xml
... ... @@ -44,13 +44,15 @@
44 44  
45 45 <TextView
46 46 android:id="@+id/multi_vote_result_title_num"
47   - android:layout_width="20dp"
  47 + android:layout_width="80dp"
48 48 android:layout_height="wrap_content"
49 49 android:layout_marginLeft="5dp"
50 50 android:gravity="center"
51   - android:textColor="@color/white"
52   - android:textSize="@dimen/big_text_p6"
53   - android:textStyle="bold" />
  51 + android:layout_centerVertical="true"
  52 + android:textColor="@color/yellow"
  53 + android:textSize="@dimen/big_text_p4"
  54 + android:textStyle="bold"
  55 + android:text="序号"/>
54 56  
55 57 <TextView
56 58 android:id="@+id/multi_vote_result_title_name"
... ...
C5/app/src/main/res/layout/list_multi_vote_result_item.xml
... ... @@ -14,7 +14,7 @@
14 14  
15 15 <TextView
16 16 android:id="@+id/list_multi_result_item_num"
17   - android:layout_width="50dp"
  17 + android:layout_width="80dp"
18 18 android:layout_height="wrap_content"
19 19 android:layout_marginLeft="5dp"
20 20 android:gravity="center"
... ...
C5/settings.gradle
1   -include ':app', ':udpmodule', ':xpadprotocal', ':util', ':sunvoteadapter', 'txpad', 'sunvotesdk','testproject'
  1 +include ':app', ':udpmodule', ':xpadprotocal', ':util', ':sunvoteadapter', 'txpad', 'sunvotesdk','testproject',':xpadapi'
  2 +
2 3 \ No newline at end of file
... ...
C5/xpadapi/.gitignore 0 → 100644
  1 +/build
... ...
C5/xpadapi/build.gradle 0 → 100644
  1 +apply plugin: 'com.android.library'
  2 +
  3 +android {
  4 + compileSdkVersion 28
  5 +
  6 +
  7 +
  8 + defaultConfig {
  9 + minSdkVersion 21
  10 + targetSdkVersion 28
  11 + versionCode 1
  12 + versionName "1.0"
  13 +
  14 + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  15 +
  16 + }
  17 +
  18 + buildTypes {
  19 + release {
  20 + minifyEnabled false
  21 + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  22 + }
  23 + }
  24 +
  25 +}
  26 +
  27 +dependencies {
  28 + implementation fileTree(include: ['*.jar'], dir: 'libs')
  29 + implementation 'com.android.support:appcompat-v7:28.0.0'
  30 + testImplementation 'junit:junit:4.12'
  31 + androidTestImplementation 'com.android.support.test:runner:1.0.2'
  32 + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
  33 + implementation project(':udpmodule')
  34 +}
... ...
C5/xpadapi/proguard-rules.pro 0 → 100644
  1 +# Add project specific ProGuard rules here.
  2 +# You can control the set of applied configuration files using the
  3 +# proguardFiles setting in build.gradle.
  4 +#
  5 +# For more details, see
  6 +# http://developer.android.com/guide/developing/tools/proguard.html
  7 +
  8 +# If your project uses WebView with JS, uncomment the following
  9 +# and specify the fully qualified class name to the JavaScript interface
  10 +# class:
  11 +#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
  12 +# public *;
  13 +#}
  14 +
  15 +# Uncomment this to preserve the line number information for
  16 +# debugging stack traces.
  17 +#-keepattributes SourceFile,LineNumberTable
  18 +
  19 +# If you keep the line number information, uncomment this to
  20 +# hide the original source file name.
  21 +#-renamesourcefileattribute SourceFile
... ...
C5/xpadapi/src/androidTest/java/com/sunvote/xpadapi/ExampleInstrumentedTest.java 0 → 100644
  1 +package com.sunvote.xpadapi;
  2 +
  3 +import android.content.Context;
  4 +import android.support.test.InstrumentationRegistry;
  5 +import android.support.test.runner.AndroidJUnit4;
  6 +
  7 +import org.junit.Test;
  8 +import org.junit.runner.RunWith;
  9 +
  10 +import static org.junit.Assert.*;
  11 +
  12 +/**
  13 + * Instrumented test, which will execute on an Android device.
  14 + *
  15 + * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
  16 + */
  17 +@RunWith(AndroidJUnit4.class)
  18 +public class ExampleInstrumentedTest {
  19 + @Test
  20 + public void useAppContext() {
  21 + // Context of the app under test.
  22 + Context appContext = InstrumentationRegistry.getTargetContext();
  23 +
  24 + assertEquals("com.sunvote.xpadapi.test", appContext.getPackageName());
  25 + }
  26 +}
... ...
C5/xpadapi/src/main/AndroidManifest.xml 0 → 100644
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3 + package="com.sunvote.xpadapi">
  4 +
  5 + <application>
  6 + <service
  7 + android:name=".service.XpadApiService"
  8 + android:enabled="true"
  9 + android:exported="true"></service>
  10 + </application>
  11 +
  12 +</manifest>
0 13 \ No newline at end of file
... ...
C5/xpadapi/src/main/aidl/com/sunvote/xpadapi/ISunvoteApi.aidl 0 → 100644
  1 +// ISunvoteApi.aidl
  2 +package com.sunvote.xpadapi;
  3 +
  4 +// Declare any non-default types here with import statements
  5 +
  6 +interface ISunvoteApi {
  7 +
  8 +
  9 + /**
  10 + * 数据包接收
  11 + */
  12 +
  13 +
  14 + /**
  15 + * 基础信标
  16 + */
  17 +
  18 + /**
  19 + * 投票信标
  20 + */
  21 +
  22 +
  23 + /**
  24 + * 基础信标
  25 + */
  26 +
  27 + /**
  28 + * 30透传包
  29 + */
  30 +
  31 + /**
  32 + * 40透传包
  33 + */
  34 +}
  35 +
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/SendPacket.java 0 → 100644
  1 +package com.sunvote.xpadapi.service;
  2 +
  3 +public class SendPacket {
  4 +
  5 + private byte[] datas;
  6 +
  7 + /**
  8 + * 0 未发送
  9 + * 1 已发送
  10 + * 2 发送成功
  11 + */
  12 + private int sendOK ;
  13 +
  14 + /**
  15 + * 发送次数
  16 + */
  17 + private int sendTimes;
  18 +
  19 + /**
  20 + * 是否有序 有序需要第一个才发送
  21 + * 无序,则可全部发送
  22 + */
  23 + private boolean canAll;
  24 +
  25 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/SenderManager.java 0 → 100644
  1 +package com.sunvote.xpadapi.service;
  2 +
  3 +import com.sunvote.xpadapi.service.bean.BatchNumberVote;
  4 +import com.sunvote.xpadapi.service.bean.BatchSingleVote;
  5 +import com.sunvote.xpadapi.service.bean.LoginInVote;
  6 +import com.sunvote.xpadapi.service.bean.NumberVote;
  7 +import com.sunvote.xpadapi.service.bean.Packet;
  8 +import com.sunvote.xpadapi.service.bean.SelectOtherVote;
  9 +import com.sunvote.xpadapi.service.bean.SelectVote;
  10 +import com.sunvote.xpadapi.service.bean.ServiceTypeVote;
  11 +import com.sunvote.xpadapi.service.bean.SingleVote;
  12 +import com.sunvote.xpadapi.service.listener.OnSendPacket;
  13 +import com.sunvote.xpadapi.service.listener.OnSender;
  14 +
  15 +public final class SenderManager {
  16 +
  17 + private static SenderManager instance = null;
  18 +
  19 + private SenderManager() {
  20 + }
  21 +
  22 + public static SenderManager getInstance() {
  23 + if (instance == null) {
  24 + synchronized (SenderManager.class) {
  25 + if (instance == null) {
  26 + instance = new SenderManager();
  27 + }
  28 + }
  29 + }
  30 + return instance;
  31 + }
  32 +
  33 + /**
  34 + * 发送
  35 + *
  36 + * @param singleVote
  37 + */
  38 + public void sendSingleVote(final SingleVote singleVote) {
  39 + sendSingleVote(singleVote, null);
  40 + }
  41 +
  42 + public void sendVoteAllOK(final OnSender<SingleVote> sender) {
  43 + SingleVote singleVote = new SingleVote(1);
  44 + sendSingleVote(singleVote, sender);
  45 + }
  46 +
  47 + public void sendSingleVote(final SingleVote singleVote, final OnSender<SingleVote> onSender) {
  48 + if (singleVote != null) {
  49 + byte[] datas = singleVote.toBytes();
  50 + XpadApiServiceInfoProxyManager.getInstance().sendPacket(datas, new OnSendPacket() {
  51 + @Override
  52 + public void onSuccess(Packet packet) {
  53 + if (onSender != null) {
  54 + onSender.onSuccess(singleVote);
  55 + }
  56 + }
  57 +
  58 + @Override
  59 + public void onFail(Packet packet) {
  60 + if (onSender != null) {
  61 + onSender.onFail(singleVote);
  62 + }
  63 + }
  64 + });
  65 + } else {
  66 + if (onSender != null) {
  67 + onSender.onFail(singleVote);
  68 + }
  69 + }
  70 + }
  71 +
  72 + public void sendSelectVote(final SelectVote selectVote) {
  73 + sendSelectVote(selectVote, null);
  74 + }
  75 +
  76 + public void sendSelectVote(final SelectVote selectVote, final OnSender<SelectVote> onSender) {
  77 + if (selectVote != null) {
  78 + XpadApiServiceInfoProxyManager.getInstance().sendPacket(selectVote.toBytes(), new OnSendPacket() {
  79 + @Override
  80 + public void onSuccess(Packet packet) {
  81 + if (onSender != null) {
  82 + onSender.onSuccess(selectVote);
  83 + }
  84 + }
  85 +
  86 + @Override
  87 + public void onFail(Packet packet) {
  88 + if (onSender != null) {
  89 + onSender.onFail(selectVote);
  90 + }
  91 + }
  92 + });
  93 + } else {
  94 + if (onSender != null) {
  95 + onSender.onFail(selectVote);
  96 + }
  97 + }
  98 + }
  99 +
  100 + public void sendNumberVote(final NumberVote numberVote) {
  101 + sendNumberVote(numberVote, null);
  102 + }
  103 +
  104 + public void sendNumberVote(final NumberVote numberVote, final OnSender<NumberVote> sender) {
  105 + if (numberVote != null) {
  106 + XpadApiServiceInfoProxyManager.getInstance().sendPacket(numberVote.toBytes(), new OnSendPacket() {
  107 + @Override
  108 + public void onSuccess(Packet packet) {
  109 + if (sender != null) {
  110 + sender.onSuccess(numberVote);
  111 + }
  112 + }
  113 +
  114 + @Override
  115 + public void onFail(Packet packet) {
  116 + if (sender != null) {
  117 + sender.onFail(numberVote);
  118 + }
  119 + }
  120 + });
  121 + } else {
  122 + if (sender != null) {
  123 + sender.onFail(numberVote);
  124 + }
  125 + }
  126 + }
  127 +
  128 + public void sendLoginInVote(final LoginInVote loginInVote) {
  129 + sendLoginInVote(loginInVote, null);
  130 + }
  131 +
  132 + public void sendLoginInVote(final LoginInVote loginInVote, final OnSender<LoginInVote> sender) {
  133 + if (loginInVote != null) {
  134 + XpadApiServiceInfoProxyManager.getInstance().sendPacket(loginInVote.toBytes(), new OnSendPacket() {
  135 + @Override
  136 + public void onSuccess(Packet packet) {
  137 + if (sender != null) {
  138 + sender.onSuccess(loginInVote);
  139 + }
  140 + }
  141 +
  142 + @Override
  143 + public void onFail(Packet packet) {
  144 + if (sender != null) {
  145 + sender.onFail(loginInVote);
  146 + }
  147 + }
  148 + });
  149 + } else {
  150 + if (sender != null) {
  151 + sender.onFail(loginInVote);
  152 + }
  153 + }
  154 + }
  155 +
  156 + public void sendCancelAllBatchSingleVote(final OnSender<BatchSingleVote> sender) {
  157 + BatchSingleVote batchSingleVote = new BatchSingleVote();
  158 + sendBatchSingleVote(batchSingleVote, sender);
  159 + }
  160 +
  161 + public void sendSubmitlAllBatchSingleVote(final OnSender<BatchSingleVote> sender) {
  162 + BatchSingleVote batchSingleVote = new BatchSingleVote();
  163 + batchSingleVote.setAllOk(1);
  164 + sendBatchSingleVote(batchSingleVote, sender);
  165 + }
  166 +
  167 + public void sendBatchSingleVote(final BatchSingleVote batchSingleVote) {
  168 + sendBatchSingleVote(batchSingleVote, null);
  169 + }
  170 +
  171 + public void sendBatchSingleVote(final BatchSingleVote batchSingleVote, final OnSender<BatchSingleVote> sender) {
  172 + if (batchSingleVote != null) {
  173 + XpadApiServiceInfoProxyManager.getInstance().sendPacket(batchSingleVote.toBytes(), new OnSendPacket() {
  174 + @Override
  175 + public void onSuccess(Packet packet) {
  176 + if (sender != null) {
  177 + sender.onSuccess(batchSingleVote);
  178 + }
  179 + }
  180 +
  181 + @Override
  182 + public void onFail(Packet packet) {
  183 + if (sender != null) {
  184 + sender.onFail(batchSingleVote);
  185 + }
  186 + }
  187 + });
  188 + } else {
  189 + if (sender != null) {
  190 + sender.onFail(batchSingleVote);
  191 + }
  192 + }
  193 + }
  194 +
  195 + public void sendBatchNumberVoteOK(final BatchNumberVote batchNumberVote, final OnSender<BatchNumberVote> sender) {
  196 + batchNumberVote.setAllOk(1);
  197 + sendBatchNumberVote(batchNumberVote, sender);
  198 + }
  199 +
  200 + public void sendBatchNumberVote(final BatchNumberVote batchNumberVote) {
  201 + sendBatchNumberVote(batchNumberVote, null);
  202 + }
  203 +
  204 + public void sendBatchNumberVote(final BatchNumberVote batchNumberVote, final OnSender<BatchNumberVote> sender) {
  205 + if (batchNumberVote != null) {
  206 + XpadApiServiceInfoProxyManager.getInstance().sendPacket(batchNumberVote.toBytes(), new OnSendPacket() {
  207 + @Override
  208 + public void onSuccess(Packet packet) {
  209 + if (sender != null) {
  210 + sender.onSuccess(batchNumberVote);
  211 + }
  212 + }
  213 +
  214 + @Override
  215 + public void onFail(Packet packet) {
  216 + if (sender != null) {
  217 + sender.onFail(batchNumberVote);
  218 + }
  219 + }
  220 + });
  221 + } else {
  222 + if (sender != null) {
  223 + sender.onFail(batchNumberVote);
  224 + }
  225 + }
  226 + }
  227 +
  228 + public void sendSelectOtherVote(SelectOtherVote selectOtherVote) {
  229 + sendSelectOtherVote(selectOtherVote, null);
  230 + }
  231 +
  232 + public void sendSelectOtherVote(final SelectOtherVote selectOtherVote, final OnSender<SelectOtherVote> sender) {
  233 + if (selectOtherVote != null) {
  234 + XpadApiServiceInfoProxyManager.getInstance().sendPacket(selectOtherVote.toBytes(), new OnSendPacket() {
  235 + @Override
  236 + public void onSuccess(Packet packet) {
  237 + if (sender != null) {
  238 + sender.onSuccess(selectOtherVote);
  239 + }
  240 + }
  241 +
  242 + @Override
  243 + public void onFail(Packet packet) {
  244 + if (sender != null) {
  245 + sender.onFail(selectOtherVote);
  246 + }
  247 + }
  248 + });
  249 + } else {
  250 + if (sender != null) {
  251 + sender.onFail(selectOtherVote);
  252 + }
  253 + }
  254 + }
  255 +
  256 + public void sendServiceTypeVote(final ServiceTypeVote serviceTypeVote) {
  257 + sendServiceTypeVote(serviceTypeVote, null);
  258 + }
  259 +
  260 + public void sendServiceTypeVote(final ServiceTypeVote serviceTypeVote, final OnSender<ServiceTypeVote> sender) {
  261 + if (serviceTypeVote != null) {
  262 + XpadApiServiceInfoProxyManager.getInstance().sendPacket(serviceTypeVote.toBytes(), new OnSendPacket() {
  263 + @Override
  264 + public void onSuccess(Packet packet) {
  265 + if (sender != null) {
  266 + sender.onSuccess(serviceTypeVote);
  267 + }
  268 + }
  269 +
  270 + @Override
  271 + public void onFail(Packet packet) {
  272 + if (sender != null) {
  273 + sender.onFail(serviceTypeVote);
  274 + }
  275 + }
  276 + });
  277 + } else {
  278 + if (sender != null) {
  279 + sender.onFail(serviceTypeVote);
  280 + }
  281 + }
  282 + }
  283 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/SerialManager.java 0 → 100644
  1 +package com.sunvote.xpadapi.service;
  2 +
  3 +public final class SerialManager {
  4 +
  5 + private static SerialManager instance = null ;
  6 +
  7 + private SerialManager(){
  8 + }
  9 +
  10 + public static SerialManager getInstance(){
  11 + if(instance == null){
  12 + synchronized(SerialManager.class){
  13 + if(instance == null){
  14 + instance = new SerialManager();
  15 + }
  16 + }
  17 + }
  18 + return instance;
  19 + }
  20 +
  21 + private byte seq = 0 ;
  22 +
  23 + public byte getSeq() {
  24 + if (seq == 0xfe) {
  25 + seq = 0 ;
  26 + }
  27 + return ++seq;
  28 + }
  29 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/XpadApiService.java 0 → 100644
  1 +package com.sunvote.xpadapi.service;
  2 +
  3 +import android.app.Service;
  4 +import android.content.BroadcastReceiver;
  5 +import android.content.Context;
  6 +import android.content.Intent;
  7 +import android.content.IntentFilter;
  8 +import android.hardware.usb.UsbManager;
  9 +import android.os.Handler;
  10 +import android.os.HandlerThread;
  11 +import android.os.IBinder;
  12 +
  13 +import com.sunvote.udptransfer.UDPModule;
  14 +import com.sunvote.udptransfer.stream.SunVoteInputStream;
  15 +import com.sunvote.udptransfer.work.BaseStationProcessWork;
  16 +import com.sunvote.udptransfer.work.RepeatMessageManager;
  17 +import com.sunvote.udptransfer.work.SDKProcessWork;
  18 +import com.sunvote.xpadapi.ISunvoteApi;
  19 +import com.sunvote.xpadapi.service.bean.HeartBeat;
  20 +import com.sunvote.xpadapi.service.bean.Packet;
  21 +import com.sunvote.xpadapi.service.listener.OnDataReceiver;
  22 +import com.sunvote.xpadapi.service.bean.BaseInfo;
  23 +import com.sunvote.xpadapi.service.bean.BaseVoteInfo;
  24 +import com.sunvote.xpadapi.service.bean.KeypadInfo;
  25 +import com.sunvote.xpadapi.service.bean.ModelInfo;
  26 +import com.sunvote.xpadapi.service.bean.OnLineInfo;
  27 +import com.sunvote.xpadapi.usb.UsbTransferManager;
  28 +import com.sunvote.xpadapi.util.ByteUtils;
  29 +import com.sunvote.xpadapi.util.Cons;
  30 +import com.sunvote.xpadapi.util.Crc16;
  31 +import com.sunvote.xpadapi.util.LogUtil;
  32 +
  33 +import java.io.ByteArrayOutputStream;
  34 +import java.io.IOException;
  35 +import java.util.ArrayList;
  36 +import java.util.Arrays;
  37 +import java.util.Collections;
  38 +import java.util.List;
  39 +
  40 +public class XpadApiService extends Service {
  41 +
  42 + private static final String TAG = XpadApiService.class.getSimpleName();
  43 + private List<OnDataReceiver> onDataReceiverList = new ArrayList<>();
  44 + private int batteryLevel = 0;
  45 + private List<Packet> innerList = Collections.synchronizedList(new ArrayList<Packet>());
  46 + private OnDataReceiver onDataReceiver = new OnDataReceiver() {
  47 + @Override
  48 + public void onDataReceiver(byte[] datas) {
  49 + LogUtil.i(TAG, "onDataReceiver", datas);
  50 + for (OnDataReceiver temp : onDataReceiverList) {
  51 + if (temp != null) {
  52 + try {
  53 + temp.onDataReceiver(datas);
  54 + } catch (Exception ex) {
  55 + LogUtil.e(TAG, "onDataReceiver", ex);
  56 + }
  57 + }
  58 + }
  59 + }
  60 +
  61 + @Override
  62 + public void onDataSender(byte[] datas) {
  63 + LogUtil.i(TAG, "onDataSender", datas);
  64 + for (OnDataReceiver temp : onDataReceiverList) {
  65 + if (temp != null) {
  66 + try {
  67 + temp.onDataSender(datas);
  68 + } catch (Exception ex) {
  69 + LogUtil.e(TAG, "onDataSender", ex);
  70 + }
  71 + }
  72 + }
  73 + }
  74 + };
  75 +
  76 + public XpadApiService() {
  77 + }
  78 +
  79 + public int registerOnDataReceiver(OnDataReceiver onDataReceiver) {
  80 + for (OnDataReceiver temp : onDataReceiverList) {
  81 + if (temp == onDataReceiver) {
  82 + return 0;
  83 + }
  84 + }
  85 + onDataReceiverList.add(onDataReceiver);
  86 + return 1;
  87 + }
  88 +
  89 + @Override
  90 + public void onCreate() {
  91 + super.onCreate();
  92 +
  93 + sendThread = new HandlerThread("send");
  94 + receiverThread = new HandlerThread("receiver");
  95 + sendThread.start();
  96 + receiverThread.start();
  97 +
  98 + taskHandler = new Handler(sendThread.getLooper());
  99 + IntentFilter batteryLevelFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
  100 + registerReceiver(batteryLevelRcvr, batteryLevelFilter);
  101 + XpadApiServiceInfoProxyManager.getInstance().setService(this);
  102 +
  103 + receiverDatas();
  104 + }
  105 +
  106 + private void receiverDatas() {
  107 + SunVoteInputStream sunVoteInputStream = new SunVoteInputStream();
  108 + sunVoteInputStream.setOnBytesReceiver(new SunVoteInputStream.OnBytesReceiver() {
  109 + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  110 + @Override
  111 + public void onBytesReceiver(byte[] bytes, int len) {
  112 + // 1. 先检测读取数据到缓冲区
  113 + byteArrayOutputStream.write(bytes, 0, bytes.length);
  114 + if (byteArrayOutputStream.size() >= 3) {
  115 + byte[] temp = byteArrayOutputStream.toByteArray();
  116 + int find = ByteUtils.findBytes(temp, new byte[]{(byte) 0xF5, (byte) 0xAA, (byte) 0xAA}, 0);
  117 + if (find >= 0) {
  118 + // 3. 标志存在,则继续读取长度
  119 + if (byteArrayOutputStream.size() >= find + 4) {
  120 + int length = ByteUtils.byte1ToInt(byteArrayOutputStream.toByteArray()[find + 3]);
  121 + if (byteArrayOutputStream.size() >= find + 4 + length) {
  122 + ByteArrayOutputStream tmp = new ByteArrayOutputStream();
  123 + // 4. 根据长度读取包的内容
  124 + for (int i = find; i < find + 4 + length; i++) {
  125 + // 5. 截取包的内容,向外抛出,处理,接着读取下一个包
  126 + tmp.write(temp[i]);
  127 + }
  128 + //CRC 校验
  129 + byte[] datas = tmp.toByteArray();
  130 + LogUtil.i(TAG, "RECEIVER DATA:", datas);
  131 +
  132 + try {
  133 + //处理
  134 + doWith(datas);
  135 + } catch (Exception ex) {
  136 + LogUtil.i(TAG, "处理命令出错:", ex);
  137 + }
  138 + // 7. 剩余数据重新打包处理
  139 + byteArrayOutputStream.reset();
  140 + for (int i = find + 4 + length; i < temp.length; i++) {
  141 + byteArrayOutputStream.write(temp[i]);
  142 + }
  143 + }
  144 + }
  145 + }
  146 + }
  147 + }
  148 + });
  149 + SDKProcessWork.getInstance().setInputStream(sunVoteInputStream);
  150 + BaseStationProcessWork.getInstance().start();
  151 + RepeatMessageManager.getInstance().start();
  152 + SDKProcessWork.getInstance().start();
  153 + }
  154 +
  155 + @Override
  156 + public void onDestroy() {
  157 + unregisterReceiver(batteryLevelRcvr);
  158 + super.onDestroy();
  159 + }
  160 +
  161 + private HandlerThread sendThread = null;
  162 + private HandlerThread receiverThread = null;
  163 + private Handler taskHandler = null;
  164 + private boolean receivering = true;
  165 +
  166 +
  167 + @Override
  168 + public IBinder onBind(Intent intent) {
  169 + return stub;
  170 + }
  171 +
  172 + private final ISunvoteApi.Stub stub = new ISunvoteApi.Stub() {
  173 +
  174 + };
  175 +
  176 + private UsbTransferManager.OnUsbConnectListener connectListener = new UsbTransferManager.OnUsbConnectListener() {
  177 + @Override
  178 + public boolean onConnect(boolean isConnected) {
  179 + if (isConnected) {
  180 + //
  181 + getKeypadParam();
  182 + sleepTimes(100);
  183 + getWorkMode();
  184 + }
  185 + return true;
  186 + }
  187 + };
  188 +
  189 + private Runnable sendTask = new Runnable() {
  190 + @Override
  191 + public void run() {
  192 + // 从队列中取出待发送数据
  193 + List<Packet> sendList = XpadApiServiceInfoProxyManager.getInstance().getSendList();
  194 + boolean isSend = false;
  195 + for (Packet p : sendList) {
  196 + if (p.needSend() && !isSend) {// 按照顺序发送
  197 + p.addSendCount();
  198 + sendPacket(p);
  199 + isSend = true;
  200 + }
  201 + if (p.needSend() && isSend && p.isSync()) {// 并行发送
  202 + sleepTimes(50);// 模块不能发送太快
  203 + p.addSendCount();
  204 + sendPacket(p);
  205 + }
  206 + if (!p.needSend() && (p.getOnSendPacket() != null)) {
  207 + p.getOnSendPacket().onFail(p);
  208 + }
  209 + }
  210 + if (!isSend) {
  211 + LogUtil.i(TAG, "没有要提交的数据,检查是否有查询包发送");
  212 + if (innerList.size() > 0) {
  213 + synchronized (innerList) {
  214 + for (Packet packet : innerList) {
  215 + sendPacket(packet);
  216 + sleepTimes(50);
  217 + }
  218 + }
  219 + }
  220 + }
  221 +
  222 + if (!isSend) {// 没有数据发送? 那就发送心跳吧
  223 + LogUtil.i(TAG, "没有任何数据要发送,则发送心跳包");
  224 + sendData(new HeartBeat((byte) batteryLevel, (byte) 0).toBytes());
  225 + }
  226 + // 轮询下一次发送数据
  227 + taskHandler.removeCallbacks(this);
  228 + taskHandler.postDelayed(this, 1000);
  229 + }
  230 + };
  231 +
  232 + private void doWith(byte[] datas) {
  233 + onDataReceiver.onDataReceiver(datas);
  234 + switch (datas[4] & 0xFF) {
  235 + case Cons.CMD_CHECK_BASE_STATUS_RESPONSE:
  236 + checkBaseStatusResponse(datas);
  237 + break;
  238 + case Cons.CMD_VOTE_RESULT_SEND_RESPONSE:
  239 + voteResultSendResponse(datas);
  240 + break;
  241 + case Cons.CMD_FIRM_UPDATE_RESPONSE:
  242 + firmUpdateResponse(datas);
  243 + break;
  244 +
  245 + case Cons.CMD_BASE_STATUS_CHANGE:
  246 + baseStatusChange(datas);
  247 + break;
  248 + case Cons.CMD_VOTE_STATUS_CHANGE:
  249 + voteStatusChange(datas);
  250 + break;
  251 + case Cons.CMD_VOTE_SEND_SUCCESS_RESPONSE:
  252 + voteSendSuccessResponse(datas);
  253 + break;
  254 +
  255 + case Cons.CMD_UPLOAD_DATA_RESPONSE:
  256 + uploadDataResponse(datas);
  257 + break;
  258 + case Cons.CMD_TRANSPARENT_TRANSMISSION:
  259 + transparentTransmission(datas);
  260 + break;
  261 + case Cons.CMD_MULTI_PCKAGE_DOWNLOAD:
  262 + break;
  263 + case Cons.CMD_COM_COMMUNICATION_TEST_RESPONSE:
  264 + break;
  265 +
  266 + }
  267 + }
  268 +
  269 + private void transparentTransmission(byte[] datas) {
  270 + }
  271 +
  272 + private void uploadDataResponse(byte[] datas) {
  273 + }
  274 +
  275 + private void voteSendSuccessResponse(byte[] datas) {
  276 + responseChange(datas, 4, (byte) 0xF3);
  277 + int serialNo = datas[5] & 0xff;
  278 + Packet packet = XpadApiServiceInfoProxyManager.getInstance().findPacket(serialNo);
  279 + if (packet != null && packet.getOnSendPacket() != null) {
  280 + packet.getOnSendPacket().onSuccess(packet);
  281 + }
  282 + }
  283 +
  284 + private void sendInnerPacket(Packet packet) {
  285 + synchronized (innerList) {
  286 + for (Packet temp : innerList) {
  287 + if (temp.getSendNo() == packet.getSendNo()) {
  288 + return;
  289 + }
  290 + }
  291 + innerList.add(packet);
  292 + }
  293 + immediately();
  294 + }
  295 +
  296 + public void immediately(){
  297 + taskHandler.removeCallbacks(sendTask);
  298 + taskHandler.post(sendTask);
  299 + }
  300 +
  301 + private void voteStatusChange(byte[] datas) {
  302 + responseChange(datas, 4, (byte) 0xF2);
  303 + saveVoteInfo(datas);
  304 + }
  305 +
  306 + private void baseStatusChange(byte[] datas) {
  307 + responseChange(datas, 4, (byte) 0xF1);
  308 + saveBaseInfo(datas);
  309 + }
  310 +
  311 + private void firmUpdateResponse(byte[] datas) {
  312 + }
  313 +
  314 + private void voteResultSendResponse(byte[] datas) {
  315 +
  316 + }
  317 +
  318 + private void checkBaseStatusResponse(byte[] datas) {
  319 + switch (datas[5] & 0xFF) {
  320 + case 1://当前工作模式和版本
  321 + case 2://当前工作模式和版本
  322 + saveModelInfo(datas);
  323 + break;
  324 + case 3:
  325 + saveBaseInfo(datas);
  326 + break;
  327 + case 4:
  328 + saveVoteInfo(datas);
  329 + break;
  330 + case 5:
  331 + case 6:
  332 + saveKeypadInfo(datas);
  333 + break;
  334 + case 7:
  335 + saveOnLineInfo(datas);
  336 + break;
  337 + case 8:
  338 + case 9:
  339 + saveKeypadInfo(datas);
  340 + break;
  341 + }
  342 + }
  343 +
  344 + private void saveOnLineInfo(byte[] datas) {
  345 + OnLineInfo info = new OnLineInfo();
  346 + info.setOnLine(datas[6] & 0xff);
  347 + info.setIdMode(datas[7] & 0xff);
  348 + info.setChan(datas[8] & 0xff);
  349 + info.setRssi(datas[9] & 0xff);
  350 + info.setTx(datas[10] & 0xff);
  351 + info.setRx(datas[11] & 0xff);
  352 + info.setBaseId(datas[12] & 0xff);
  353 + info.setKeyId(((datas[13] & 0xff) << 8) | (datas[14] & 0xff));
  354 + byte[] sn = Arrays.copyOfRange(datas, 15, 21);
  355 + info.setKeySn(ByteUtils.getKeySn(sn));
  356 + XpadApiServiceInfoProxyManager.getInstance().setOnLineInfo(info);
  357 + }
  358 +
  359 + private void saveKeypadInfo(byte[] datas) {
  360 + KeypadInfo info = new KeypadInfo();
  361 + info.setOk(datas[6] & 0xff);
  362 + info.setChan(datas[7] & 0xff);
  363 + info.setKeyId(((datas[8] & 0xff) << 8) | (datas[9] & 0xff));
  364 + byte[] sn = Arrays.copyOfRange(datas, 10, 16);
  365 + info.setKeySn(ByteUtils.getKeySn(sn));
  366 + byte[] mc = Arrays.copyOfRange(datas, 16, 19);
  367 + info.setMatchCode(new String(mc));
  368 + XpadApiServiceInfoProxyManager.getInstance().setKeypadInfo(info);
  369 + }
  370 +
  371 + private void saveVoteInfo(byte[] datas) {
  372 + BaseVoteInfo info = new BaseVoteInfo();
  373 + info.setBaseId(datas[1] & 0xff);
  374 + info.setNowT(datas[2] & 0xff << 8 | datas[3] & 0xff);
  375 + info.setDataPos(datas[4] & 0xff);
  376 + info.setMode(datas[5] & 0xff);
  377 + info.setModes(datas);
  378 + XpadApiServiceInfoProxyManager.getInstance().setBaseVoteInfo(info);
  379 + }
  380 +
  381 + /**
  382 + * 保存基础信标信息
  383 + *
  384 + * @param data
  385 + */
  386 + private void saveBaseInfo(byte[] data) {
  387 + BaseInfo info = new BaseInfo();
  388 + info.setBaseId(data[5] & 0xff);// baseID
  389 + info.setIdMode(data[6] & 0xff);
  390 + info.setConfId(((data[7] & 0xff) << 8) | (data[8] & 0xff));
  391 + info.setBillId(data[9] & 0xff);
  392 + info.setAuthCode((data[10] & 0xff) << 8 | (data[11] & 0xff));
  393 + info.setLogin(data[12] & 0xff);
  394 + info.setReport(data[13] & 0xff);
  395 + info.setOffTime(data[14] & 0xff);
  396 + info.setAttrib(data[15] & 0xff);
  397 + info.setPageNo((data[16] & 0xff) << 8 | (data[17] & 0xff));
  398 + byte[] bname = Arrays.copyOfRange(data, 16, 16 + 12);
  399 + info.setBaseName(new String(bname));
  400 + XpadApiServiceInfoProxyManager.getInstance().setBaseInfo(info);
  401 + }
  402 +
  403 + private void saveModelInfo(byte[] datas) {
  404 + ModelInfo info = new ModelInfo();
  405 + info.setMode(datas[6] & 0xff);
  406 + info.sethModel(datas[7] & 0xff);
  407 + info.setsVer((datas[8] & 0xff) + "." + (datas[9] & 0xff) + "." + (datas[10] & 0xff));
  408 + XpadApiServiceInfoProxyManager.getInstance().setModelInfo(info);
  409 + }
  410 +
  411 +
  412 + private void responseChange(byte[] data, int pos, byte res) {
  413 + byte[] retData = Arrays.copyOf(data, data.length);
  414 + retData[pos] = res;
  415 + sendData(data);
  416 + }
  417 +
  418 + private void roundCRC(byte[] data) {
  419 + int crcValue = Crc16.getUnsignedShort(Crc16.crc16(data, data.length - 4 - 2));
  420 + data[data.length - 2] = (byte) (crcValue >> 8);
  421 + data[data.length - 1] = (byte) (crcValue);
  422 + }
  423 +
  424 + public void sendPacket(Packet packet) {
  425 + sendData(packet.getDatas());
  426 + }
  427 +
  428 + public void sendData(byte[] datas) {
  429 + roundCRC(datas);
  430 + onDataReceiver.onDataSender(datas);
  431 + try {
  432 + SDKProcessWork.getInstance().execute(datas,datas.length);
  433 + } catch (Exception e) {
  434 + LogUtil.e(TAG, e);
  435 + }
  436 + }
  437 +
  438 + private void sleepTimes(long times) {
  439 + try {
  440 + Thread.sleep(times);
  441 + } catch (Exception e) {
  442 + e.printStackTrace();
  443 + }
  444 + }
  445 +
  446 + BroadcastReceiver batteryLevelRcvr = new BroadcastReceiver() {
  447 +
  448 + public void onReceive(Context context, Intent intent) {
  449 + if (Intent.ACTION_BATTERY_CHANGED.equals(intent.getAction())) {
  450 + int rawlevel = intent.getIntExtra("level", -1);
  451 + int scale = intent.getIntExtra("scale", -1);
  452 + int status = intent.getIntExtra("status", -1);
  453 + int health = intent.getIntExtra("health", -1);
  454 + int voltage = intent.getIntExtra("voltage", 0);
  455 + int level = -1; // percentage, or -1 for unknown
  456 + if (rawlevel >= 0 && scale > 0) {
  457 + level = (rawlevel * 100) / scale;
  458 + }
  459 +
  460 + float val = (float) voltage / 1000;
  461 + batteryLevel = (int) (val / 0.04);
  462 +
  463 + }
  464 + }
  465 + };
  466 +
  467 + public void getKeypadParam() {
  468 + byte[] mBuffer = new byte[0x1F + 4];
  469 + Arrays.fill(mBuffer, (byte) 0x0);
  470 + mBuffer[0] = (byte) 0xF5;
  471 + mBuffer[1] = (byte) 0xAA;
  472 + mBuffer[2] = (byte) 0xAA;
  473 + mBuffer[3] = (byte) 0x1F;
  474 +
  475 + mBuffer[4] = 0x70;
  476 + mBuffer[5] = 0x05;
  477 + Packet packet = new Packet();
  478 + packet.setDatas(mBuffer);
  479 + packet.setSendNo(Packet.GetKeypadParam);
  480 + sendInnerPacket(packet);
  481 + }
  482 +
  483 + public void getWorkMode() {
  484 + byte[] mBuffer = new byte[0x1F + 4];
  485 + Arrays.fill(mBuffer, (byte) 0x0);
  486 + mBuffer[0] = (byte) 0xF5;
  487 + mBuffer[1] = (byte) 0xAA;
  488 + mBuffer[2] = (byte) 0xAA;
  489 + mBuffer[3] = (byte) 0x1F;
  490 + mBuffer[4] = 0x70;
  491 + mBuffer[5] = 0x01;
  492 + Packet packet = new Packet();
  493 + packet.setDatas(mBuffer);
  494 + packet.setSendNo(Packet.GetWorkModeNum);
  495 + sendInnerPacket(packet);
  496 + }
  497 +
  498 + public void setWorkMode(int iMode) {
  499 + byte[] mBuffer = new byte[0x1F + 4];
  500 + Arrays.fill(mBuffer, (byte) 0x0);
  501 + mBuffer[0] = (byte) 0xF5;
  502 + mBuffer[1] = (byte) 0xAA;
  503 + mBuffer[2] = (byte) 0xAA;
  504 + mBuffer[3] = (byte) 0x1F;
  505 + mBuffer[4] = 0x70;
  506 + mBuffer[5] = 0x02;
  507 + mBuffer[6] = (byte) iMode;
  508 + Packet packet = new Packet();
  509 + packet.setDatas(mBuffer);
  510 + packet.setSendNo(Packet.SetWorkModeNum);
  511 + sendInnerPacket(packet);
  512 + }
  513 +
  514 + public void getBaseStatus() {
  515 + byte[] mBuffer = new byte[0x1F + 4];
  516 + Arrays.fill(mBuffer, (byte) 0x0);
  517 + mBuffer[0] = (byte) 0xF5;
  518 + mBuffer[1] = (byte) 0xAA;
  519 + mBuffer[2] = (byte) 0xAA;
  520 + mBuffer[3] = (byte) 0x1F;
  521 + mBuffer[4] = 0x70;
  522 + mBuffer[5] = 0x03;
  523 + Packet packet = new Packet();
  524 + packet.setDatas(mBuffer);
  525 + packet.setSendNo(Packet.BaseStatusNum);
  526 + sendInnerPacket(packet);
  527 + }
  528 +
  529 + public void getVoteStatus() {
  530 + byte[] mBuffer = new byte[0x1F + 4];
  531 + Arrays.fill(mBuffer, (byte) 0x0);
  532 + mBuffer[0] = (byte) 0xF5;
  533 + mBuffer[1] = (byte) 0xAA;
  534 + mBuffer[2] = (byte) 0xAA;
  535 + mBuffer[3] = (byte) 0x1F;
  536 + mBuffer[4] = 0x70;
  537 + mBuffer[5] = 0x04;
  538 + Packet packet = new Packet();
  539 + packet.setDatas(mBuffer);
  540 + packet.setSendNo(Packet.VoteStatusNum);
  541 + sendInnerPacket(packet);
  542 + }
  543 +
  544 + public void execKeypadMatch(int iMode, int channal) {
  545 + byte[] mBuffer = new byte[0x1F + 4];
  546 + Arrays.fill(mBuffer, (byte) 0x0);
  547 + mBuffer[0] = (byte) 0xF5;
  548 + mBuffer[1] = (byte) 0xAA;
  549 + mBuffer[2] = (byte) 0xAA;
  550 + mBuffer[3] = (byte) 0x1F;
  551 + mBuffer[4] = 0x70;
  552 + mBuffer[5] = 0x08;
  553 + mBuffer[6] = (byte) iMode;
  554 + mBuffer[7] = (byte) channal;
  555 + Packet packet = new Packet();
  556 + packet.setDatas(mBuffer);
  557 + packet.setSendNo(Packet.ExecKeypadMatchNum);
  558 + sendInnerPacket(packet);
  559 + }
  560 +
  561 + public void comCommunicationTest(int sendn, int okn) {
  562 + byte[] mBuffer = new byte[0x1F + 4];
  563 + Arrays.fill(mBuffer, (byte) 0x0);
  564 + mBuffer[0] = (byte) 0xF5;
  565 + mBuffer[1] = (byte) 0xAA;
  566 + mBuffer[2] = (byte) 0xAA;
  567 + mBuffer[3] = (byte) 0x1F;
  568 + mBuffer[4] = 0x30;
  569 + mBuffer[5] = 0x0;
  570 + mBuffer[6] = 0x0;
  571 + mBuffer[7] = 7;
  572 + mBuffer[8] = (byte) sendn;
  573 + mBuffer[9] = (byte) okn;
  574 + mBuffer[10] = (byte) 0xAA;
  575 +
  576 + for (int i = 1; i < 17; i++) {
  577 + mBuffer[10 + i] = (byte) i;
  578 + }
  579 +
  580 + Packet packet = new Packet();
  581 + packet.setDatas(mBuffer);
  582 + packet.setSendNo(Packet.CommunicationTestMatchNum);
  583 + sendInnerPacket(packet);
  584 + }
  585 +
  586 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/XpadApiServiceInfoProxyManager.java 0 → 100644
  1 +package com.sunvote.xpadapi.service;
  2 +
  3 +import com.sunvote.xpadapi.service.bean.BaseInfo;
  4 +import com.sunvote.xpadapi.service.bean.BaseVoteInfo;
  5 +import com.sunvote.xpadapi.service.bean.KeypadInfo;
  6 +import com.sunvote.xpadapi.service.bean.ModelInfo;
  7 +import com.sunvote.xpadapi.service.bean.OnLineInfo;
  8 +import com.sunvote.xpadapi.service.bean.Packet;
  9 +import com.sunvote.xpadapi.service.listener.BaseInfoChanageListener;
  10 +import com.sunvote.xpadapi.service.listener.BaseVoteInfoChanageListener;
  11 +import com.sunvote.xpadapi.service.listener.KeyPadinfoChanageListener;
  12 +import com.sunvote.xpadapi.service.listener.ModelInfoChanageListener;
  13 +import com.sunvote.xpadapi.service.listener.OnSendPacket;
  14 +import com.sunvote.xpadapi.service.listener.OnlineInfoChanageListener;
  15 +import com.sunvote.xpadapi.util.LogUtil;
  16 +
  17 +import java.util.ArrayList;
  18 +import java.util.Collections;
  19 +import java.util.List;
  20 +
  21 +/**
  22 + * 服务信息
  23 + */
  24 +public final class XpadApiServiceInfoProxyManager {
  25 +
  26 + public static final String TAG = XpadApiServiceInfoProxyManager.class.getSimpleName();
  27 + private static XpadApiServiceInfoProxyManager instance = null ;
  28 + private List<Packet> sendList = Collections.synchronizedList(new ArrayList<Packet>());
  29 + private Object lock = new Object();
  30 + private String charset = "GB2312" ;
  31 + private XpadApiService service;
  32 +
  33 + public void setCharset(String charset) {
  34 + this.charset = charset;
  35 + }
  36 +
  37 + public void setService(XpadApiService service) {
  38 + this.service = service;
  39 + }
  40 +
  41 + public XpadApiService getService() {
  42 + return service;
  43 + }
  44 +
  45 + public String getCharset() {
  46 + return charset;
  47 + }
  48 +
  49 + private XpadApiServiceInfoProxyManager(){
  50 + }
  51 +
  52 + public static XpadApiServiceInfoProxyManager getInstance(){
  53 + if(instance == null){
  54 + synchronized(XpadApiServiceInfoProxyManager.class){
  55 + if(instance == null){
  56 + instance = new XpadApiServiceInfoProxyManager();
  57 + }
  58 + }
  59 + }
  60 + return instance;
  61 + }
  62 +
  63 + private ModelInfo modelInfo;
  64 + private ModelInfoChanageListener modelInfoListener;
  65 +
  66 + public void setModelInfo(ModelInfo modelInfo) {
  67 + if(modelInfoListener != null){
  68 + try{
  69 + modelInfoListener.onModelInfoChanage(modelInfo);
  70 + }catch (Exception ex){
  71 + LogUtil.e(TAG,"onModelInfoChanage",ex);
  72 + }
  73 + }
  74 + this.modelInfo = modelInfo;
  75 + }
  76 +
  77 + public ModelInfo getModelInfo() {
  78 + return modelInfo;
  79 + }
  80 +
  81 + public void setModelInfoListener(ModelInfoChanageListener modelInfoListener) {
  82 + this.modelInfoListener = modelInfoListener;
  83 + }
  84 +
  85 + private BaseInfo baseInfo;
  86 + private BaseInfoChanageListener baseInfoListener;
  87 +
  88 + public void setBaseInfo(BaseInfo baseInfo) {
  89 + if(baseInfoListener != null){
  90 + try {
  91 + baseInfoListener.onBaseInfoChange(baseInfo);
  92 + }catch (Exception ex){
  93 + LogUtil.e(TAG,"onBaseInfoChange",ex);
  94 + }
  95 + }
  96 + this.baseInfo = baseInfo;
  97 + }
  98 +
  99 + public BaseInfo getBaseInfo() {
  100 + return baseInfo;
  101 + }
  102 +
  103 + public void setBaseInfoListener(BaseInfoChanageListener baseInfoListener) {
  104 + this.baseInfoListener = baseInfoListener;
  105 + }
  106 +
  107 + private BaseVoteInfo baseVoteInfo;
  108 + private BaseVoteInfoChanageListener baseVoteInfoListener;
  109 +
  110 + public void setBaseVoteInfo(BaseVoteInfo baseVoteInfo) {
  111 + if(baseVoteInfoListener != null){
  112 + try {
  113 + baseVoteInfoListener.onBaseVoteInfoListener(baseVoteInfo);
  114 + }catch (Exception ex){
  115 + LogUtil.e(TAG,"onBaseVoteInfoListener",ex);
  116 + }
  117 + }
  118 + this.baseVoteInfo = baseVoteInfo;
  119 + }
  120 +
  121 + public BaseVoteInfo getBaseVoteInfo() {
  122 + return baseVoteInfo;
  123 + }
  124 +
  125 + public void setBaseVoteInfoListener(BaseVoteInfoChanageListener baseVoteInfoListener) {
  126 + this.baseVoteInfoListener = baseVoteInfoListener;
  127 + }
  128 +
  129 + private KeypadInfo keypadInfo;
  130 + private KeyPadinfoChanageListener keyPadinfoChanageListener;
  131 +
  132 + public void setKeypadInfo(KeypadInfo keypadInfo) {
  133 + if(keyPadinfoChanageListener != null){
  134 + try{
  135 + keyPadinfoChanageListener.onKeyPadinfoChanage(keypadInfo);
  136 + }catch (Exception ex){
  137 + LogUtil.e(TAG,"onKeyPadinfoChanage",ex);
  138 + }
  139 + }
  140 + this.keypadInfo = keypadInfo;
  141 + }
  142 +
  143 + public KeypadInfo getKeypadInfo() {
  144 + if(keypadInfo == null){
  145 + keypadInfo = new KeypadInfo();
  146 + }
  147 + return keypadInfo;
  148 + }
  149 +
  150 + public void setKeyPadinfoChanageListener(KeyPadinfoChanageListener keyPadinfoChanageListener) {
  151 + this.keyPadinfoChanageListener = keyPadinfoChanageListener;
  152 + }
  153 +
  154 + private OnLineInfo onLineInfo;
  155 + private OnlineInfoChanageListener onlineInfoChanageListener;
  156 +
  157 + public void setOnLineInfo(OnLineInfo onLineInfo) {
  158 + if(onlineInfoChanageListener != null){
  159 + try{
  160 + onlineInfoChanageListener.onOnlineInfoChanage(onLineInfo);
  161 + }catch (Exception ex){
  162 + LogUtil.e(TAG,"onOnlineInfoChanage",ex);
  163 + }
  164 + }
  165 + this.onLineInfo = onLineInfo;
  166 + }
  167 +
  168 + public OnLineInfo getOnLineInfo() {
  169 + return onLineInfo;
  170 + }
  171 +
  172 + public void setOnlineInfoChanageListener(OnlineInfoChanageListener onlineInfoChanageListener) {
  173 + this.onlineInfoChanageListener = onlineInfoChanageListener;
  174 + }
  175 +
  176 + public void sendPacket(byte[] datas,final OnSendPacket sendPacket){
  177 + Packet packet = new Packet();
  178 + packet.setDatas(datas);
  179 + packet.setSendNo(datas[5] & 0xFF);
  180 + packet.setOnSendPacket(new OnSendPacket() {
  181 + @Override
  182 + public void onSuccess(Packet packet) {
  183 + synchronized (lock){
  184 + sendList.remove(packet);
  185 + }
  186 + try{
  187 + sendPacket.onSuccess(packet);
  188 + }catch (Exception ex){
  189 + LogUtil.e(TAG,"sendPacket.onSuccess",ex);
  190 + }
  191 + }
  192 +
  193 + @Override
  194 + public void onFail(Packet packet) {
  195 + synchronized (lock){
  196 + sendList.remove(packet);
  197 + }
  198 + try{
  199 + sendPacket.onFail(packet);
  200 + }catch (Exception ex){
  201 + LogUtil.e(TAG,"sendPacket.onFail",ex);
  202 + }
  203 + }
  204 + });
  205 + synchronized (lock){
  206 + if(!exsit(packet)){
  207 + sendList.add(packet);
  208 + }
  209 + }
  210 + if(service != null){
  211 + service.immediately();
  212 + }
  213 + }
  214 +
  215 + public List<Packet> getSendList() {
  216 + return sendList;
  217 + }
  218 +
  219 + private boolean exsit(Packet packet){
  220 + for(Packet packet1: sendList){
  221 + if(packet.getSendNo() == packet1.getSendNo()){
  222 + return true;
  223 + }
  224 + }
  225 + return false;
  226 + }
  227 +
  228 + public Packet findPacket(int sendNo){
  229 + for(Packet packet: sendList){
  230 + if(packet.getSendNo() == sendNo){
  231 + return packet;
  232 + }
  233 + }
  234 + return null;
  235 + }
  236 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/BaseInfo.java 0 → 100644
  1 +package com.sunvote.xpadapi.service.bean;
  2 +
  3 +public class BaseInfo {
  4 + private int baseId;//基站编号
  5 + private int idMode;//基站识别模式,1编号、2序列号
  6 + private int confId;//会议资料UID编号,1-65535,高位字节在前
  7 + private int billId;//议题编号
  8 + private int pageNo; //议案页码
  9 + private int authCode;//授权号,2字节,高位在前,0-0xFFFF
  10 + private int login;//登录申请模式(后台签到模式),是否需要IC卡、登录码(
  11 + private int report;//表决器报告状态模式和指定语言
  12 + private int offTime;//自动关机时间
  13 + private int attrib;//表决器特性:背光模式+蜂鸣器模式等等
  14 + private String baseName; //基站名称,最多12字节
  15 +
  16 + public int getBaseId() {
  17 + return baseId;
  18 + }
  19 +
  20 + public void setBaseId(int baseId) {
  21 + this.baseId = baseId;
  22 + }
  23 +
  24 + public int getIdMode() {
  25 + return idMode;
  26 + }
  27 +
  28 + public void setIdMode(int idMode) {
  29 + this.idMode = idMode;
  30 + }
  31 +
  32 + public int getConfId() {
  33 + return confId;
  34 + }
  35 +
  36 + public void setConfId(int confId) {
  37 + this.confId = confId;
  38 + }
  39 +
  40 + public int getBillId() {
  41 + return billId;
  42 + }
  43 +
  44 + public void setBillId(int billId) {
  45 + this.billId = billId;
  46 + }
  47 +
  48 + public int getPageNo() {
  49 + return pageNo;
  50 + }
  51 +
  52 + public void setPageNo(int pageNo) {
  53 + this.pageNo = pageNo;
  54 + }
  55 +
  56 + public int getAuthCode() {
  57 + return authCode;
  58 + }
  59 +
  60 + public void setAuthCode(int authCode) {
  61 + this.authCode = authCode;
  62 + }
  63 +
  64 + public int getLogin() {
  65 + return login;
  66 + }
  67 +
  68 + public void setLogin(int login) {
  69 + this.login = login;
  70 + }
  71 +
  72 + public int getReport() {
  73 + return report;
  74 + }
  75 +
  76 + public void setReport(int report) {
  77 + this.report = report;
  78 + }
  79 +
  80 + public int getOffTime() {
  81 + return offTime;
  82 + }
  83 +
  84 + public void setOffTime(int offTime) {
  85 + this.offTime = offTime;
  86 + }
  87 +
  88 + public int getAttrib() {
  89 + return attrib;
  90 + }
  91 +
  92 + public void setAttrib(int attrib) {
  93 + this.attrib = attrib;
  94 + }
  95 +
  96 + public String getBaseName() {
  97 + return baseName;
  98 + }
  99 +
  100 + public void setBaseName(String baseName) {
  101 + this.baseName = baseName;
  102 + }
  103 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/BaseVoteInfo.java 0 → 100644
  1 +package com.sunvote.xpadapi.service.bean;
  2 +
  3 +import com.sunvote.xpadapi.service.listener.IModesVoteInfo;
  4 +
  5 +/**
  6 + * 字节 标识符 描述
  7 + 1 CMD 0x72 投票信标变化
  8 + 2 BADDH 基站编号,保证有效数据从第3字节开始,和查询指令相同
  9 + 3,4 NOWT 时标值,2字节,高位在前
  10 + 从投票启动开始的时间,用于表决器同步计时,20ms为单位,最大约21分钟,最大0xFFFF不自动变为0
  11 + 5 DATAPOS 表决序号(结果记录序号)
  12 + 1-0xFF,值发生变化的时候,代表是新的一轮表决开始
  13 +
  14 + 6 MODE 投票模式
  15 + Bit7=1表示继续表决,表决器重新提交数据,用于系统恢复,表决器可继续输入或使用原先结果;=0 正常表决
  16 + 低7位是表决模式:
  17 + 1-9是政务应用 10-19商务应用和教育 20-29多项和批次 30-39二维表评测 40-50管理类
  18 +
  19 + 7-25 MODES 投票参数,具体和MODE有关,不同模式下参数意义不同
  20 +
  21 + */
  22 +public class BaseVoteInfo {
  23 +
  24 + private int baseId;//[1]基站编号
  25 + private int nowT;//[2,3]
  26 + private int dataPos;//[4]
  27 + private int mode;// [5] 表决模式
  28 +
  29 + private IModesVoteInfo modes;
  30 +
  31 + public int getBaseId() {
  32 + return baseId;
  33 + }
  34 +
  35 + public void setBaseId(int baseId) {
  36 + this.baseId = baseId;
  37 + }
  38 +
  39 + public int getNowT() {
  40 + return nowT;
  41 + }
  42 +
  43 + public void setNowT(int nowT) {
  44 + this.nowT = nowT;
  45 + }
  46 +
  47 + public int getDataPos() {
  48 + return dataPos;
  49 + }
  50 +
  51 + public void setDataPos(int dataPos) {
  52 + this.dataPos = dataPos;
  53 + }
  54 +
  55 + public int getMode() {
  56 + return mode;
  57 + }
  58 +
  59 + public void setMode(int mode) {
  60 + this.mode = mode;
  61 + }
  62 +
  63 + public IModesVoteInfo getModes() {
  64 + return modes;
  65 + }
  66 +
  67 + public void setModes(byte[] datas) {
  68 + this.modes = modes;
  69 + }
  70 +
  71 +
  72 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/BatchNumberVote.java 0 → 100644
  1 +package com.sunvote.xpadapi.service.bean;
  2 +
  3 +import com.sunvote.xpadapi.service.SerialManager;
  4 +
  5 +import java.util.Arrays;
  6 +
  7 +/**
  8 + * 批次评分值结果
  9 + */
  10 +public class BatchNumberVote extends Vote {
  11 +
  12 + public static final int AnsType_BatchNumber = 23;
  13 +
  14 + private int personId;
  15 + private int projectId;
  16 + private String strNum;
  17 +
  18 + public BatchNumberVote(int personId, int projectId, String strNum) {
  19 + super(AnsType_BatchNumber);
  20 + this.personId = personId;
  21 + this.projectId = projectId;
  22 + this.strNum = strNum;
  23 + }
  24 +
  25 + public BatchNumberVote() {
  26 + super(AnsType_BatchNumber);
  27 + }
  28 +
  29 + public void setPersonId(int personId) {
  30 + this.personId = personId;
  31 + }
  32 +
  33 + public void setProjectId(int projectId) {
  34 + this.projectId = projectId;
  35 + }
  36 +
  37 + public void setStrNum(String strNum) {
  38 + this.strNum = strNum;
  39 + }
  40 +
  41 + @Override
  42 + public byte[] toBytes() {
  43 + byte[] mBuffer = new byte[0x1F + 4];
  44 + Arrays.fill(mBuffer, (byte) 0x0);
  45 + mBuffer[0] = (byte) 0xF5;
  46 + mBuffer[1] = (byte) 0xAA;
  47 + mBuffer[2] = (byte) 0xAA;
  48 + mBuffer[3] = (byte) 0x1F;
  49 + mBuffer[4] = 0x73;
  50 + mBuffer[5] = SerialManager.getInstance().getSeq();
  51 + mBuffer[6] = msgType;
  52 + mBuffer[7] = (byte) ansType;
  53 + mBuffer[8] = (byte)ok;// ALLOK
  54 + if (projectId != 0) {
  55 + mBuffer[9] = (byte) personId;
  56 + mBuffer[10] = (byte) projectId;
  57 + } else {
  58 + mBuffer[9] = (byte) (personId >> 8);
  59 + mBuffer[10] = (byte) (personId & 0xff);
  60 + }
  61 + byte[] val = util_encodeBCD(strNum.getBytes());
  62 + System.arraycopy(val, 0, mBuffer, 11, 4);
  63 + return mBuffer;
  64 + }
  65 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/BatchSingleVote.java 0 → 100644
  1 +package com.sunvote.xpadapi.service.bean;
  2 +
  3 +import com.sunvote.xpadapi.service.SerialManager;
  4 +
  5 +import java.util.Arrays;
  6 +
  7 +public class BatchSingleVote extends Vote{
  8 +
  9 + public static final int AnsType_BatchSingle = 21 ;
  10 +
  11 + private int num;
  12 + private int val ;
  13 +
  14 + public BatchSingleVote(int num, int val) {
  15 + super(AnsType_BatchSingle);
  16 + this.num = num;
  17 + this.val = val;
  18 + }
  19 +
  20 + /**
  21 + * 不设计任何值,则为取消全部投票
  22 + */
  23 + public BatchSingleVote() {
  24 + super(AnsType_BatchSingle);
  25 + }
  26 +
  27 + public void setNum(int num) {
  28 + this.num = num;
  29 + }
  30 +
  31 + public void setVal(int val) {
  32 + this.val = val;
  33 + }
  34 +
  35 + @Override
  36 + public byte[] toBytes() {
  37 + byte[] mBuffer = new byte[0x1F + 4];
  38 + Arrays.fill(mBuffer, (byte) 0x0);
  39 + mBuffer[0] = (byte) 0xF5;
  40 + mBuffer[1] = (byte) 0xAA;
  41 + mBuffer[2] = (byte) 0xAA;
  42 + mBuffer[3] = (byte) 0x1F;
  43 + mBuffer[4] = 0x73;
  44 + mBuffer[5] = (byte) SerialManager.getInstance().getSeq();
  45 + mBuffer[6] = msgType;
  46 + mBuffer[7] = (byte) ansType;
  47 + mBuffer[8] = (byte)ok;// ALLOK
  48 + int pos = 9;
  49 + mBuffer[pos++] = (byte) (num >> 8);
  50 + mBuffer[pos++] = (byte) (num & 0xff);
  51 + mBuffer[pos++] = (byte) val;
  52 + return mBuffer;
  53 + }
  54 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/HeartBeat.java 0 → 100644
  1 +package com.sunvote.xpadapi.service.bean;
  2 +
  3 +import java.util.Arrays;
  4 +
  5 +public class HeartBeat {
  6 +
  7 + private byte volt;
  8 + private byte keyinStatus;
  9 +
  10 + public HeartBeat(byte volt, byte keyinStatus) {
  11 + this.volt = volt;
  12 + this.keyinStatus = keyinStatus;
  13 + }
  14 +
  15 + public HeartBeat() {
  16 + }
  17 +
  18 + public void setKeyinStatus(byte keyinStatus) {
  19 + this.keyinStatus = keyinStatus;
  20 + }
  21 +
  22 + public void setVolt(byte volt) {
  23 + this.volt = volt;
  24 + }
  25 +
  26 + public byte[] toBytes(){
  27 + byte[] mBuffer = new byte[0x1F + 4];
  28 + Arrays.fill(mBuffer, (byte) 0x0);
  29 + mBuffer[0] = (byte) 0xF5;
  30 + mBuffer[1] = (byte) 0xAA;
  31 + mBuffer[2] = (byte) 0xAA;
  32 + mBuffer[3] = (byte) 0x1F;
  33 + mBuffer[4] = 0x70;
  34 + mBuffer[5] = 0x07;
  35 + mBuffer[6] = (byte) volt;
  36 + mBuffer[7] = (byte) keyinStatus;
  37 + return mBuffer;
  38 + }
  39 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/KeypadInfo.java 0 → 100644
  1 +package com.sunvote.xpadapi.service.bean;
  2 +
  3 +public class KeypadInfo {
  4 +
  5 + private int cmd1;//8:match 9:config
  6 + private int ok;
  7 + private int chan;
  8 + private int keyId;//键盘编号,高位在前
  9 + private String keySn;//6字节键盘序列号
  10 + private String matchCode;//4字节配对码
  11 +
  12 + public int getCmd1() {
  13 + return cmd1;
  14 + }
  15 +
  16 + public void setCmd1(int cmd1) {
  17 + this.cmd1 = cmd1;
  18 + }
  19 +
  20 + public int getOk() {
  21 + return ok;
  22 + }
  23 +
  24 + public void setOk(int ok) {
  25 + this.ok = ok;
  26 + }
  27 +
  28 + public int getChan() {
  29 + return chan;
  30 + }
  31 +
  32 + public void setChan(int chan) {
  33 + this.chan = chan;
  34 + }
  35 +
  36 + public int getKeyId() {
  37 + return keyId;
  38 + }
  39 +
  40 + public void setKeyId(int keyId) {
  41 + this.keyId = keyId;
  42 + }
  43 +
  44 + public String getKeySn() {
  45 + return keySn;
  46 + }
  47 +
  48 + public void setKeySn(String keySn) {
  49 + this.keySn = keySn;
  50 + }
  51 +
  52 + public String getMatchCode() {
  53 + return matchCode;
  54 + }
  55 +
  56 + public void setMatchCode(String matchCode) {
  57 + this.matchCode = matchCode;
  58 + }
  59 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/LoginInVote.java 0 → 100644
  1 +package com.sunvote.xpadapi.service.bean;
  2 +
  3 +import com.sunvote.xpadapi.service.SerialManager;
  4 +
  5 +import java.util.Arrays;
  6 +
  7 +public class LoginInVote extends Vote{
  8 +
  9 + public static final int AnsType_LoginIn = 16 ;
  10 +
  11 + private String info ;
  12 +
  13 + public LoginInVote(String info) {
  14 + super(AnsType_LoginIn);
  15 + this.info = info;
  16 + }
  17 +
  18 + public void setInfo(String info) {
  19 + this.info = info;
  20 + }
  21 +
  22 + public byte[] toBytes(){
  23 + byte[] mBuffer = new byte[0x1F + 4];
  24 + Arrays.fill(mBuffer, (byte) 0x0);
  25 + mBuffer[0] = (byte) 0xF5;
  26 + mBuffer[1] = (byte) 0xAA;
  27 + mBuffer[2] = (byte) 0xAA;
  28 + mBuffer[3] = (byte) 0x1F;
  29 +
  30 + mBuffer[4] = 0x73;
  31 + mBuffer[5] = SerialManager.getInstance().getSeq();
  32 +
  33 + mBuffer[6] = (byte)msgType;
  34 + mBuffer[7] = (byte) ansType;
  35 + mBuffer[8] = 3;//3 签到信息按BCD码格式
  36 + byte[] val = util_encodeBCD(info.getBytes());
  37 + System.arraycopy(val, 0, mBuffer, 9, 9);
  38 + return mBuffer;
  39 + }
  40 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/ModelInfo.java 0 → 100644
  1 +package com.sunvote.xpadapi.service.bean;
  2 +
  3 +public class ModelInfo {
  4 + private int mode;//模块当前主从模式 1 基站模式(主) 2 键盘模式(从)
  5 + private int hModel;//硬件型号,数字
  6 + private String sVer;//固件版本,3位数字,例如 0.1.0
  7 +
  8 + public int getMode() {
  9 + return mode;
  10 + }
  11 +
  12 + public void setMode(int mode) {
  13 + this.mode = mode;
  14 + }
  15 +
  16 + public int gethModel() {
  17 + return hModel;
  18 + }
  19 +
  20 + public void sethModel(int hModel) {
  21 + this.hModel = hModel;
  22 + }
  23 +
  24 + public String getsVer() {
  25 + return sVer;
  26 + }
  27 +
  28 + public void setsVer(String sVer) {
  29 + this.sVer = sVer;
  30 + }
  31 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/NumberVote.java 0 → 100644
  1 +package com.sunvote.xpadapi.service.bean;
  2 +
  3 +import com.sunvote.xpadapi.service.SerialManager;
  4 +
  5 +import java.util.Arrays;
  6 +
  7 +public class NumberVote extends Vote{
  8 +
  9 + public static final int AnsType_Number = 3;
  10 + private String info;
  11 +
  12 + public void setInfo(String info) {
  13 + this.info = info;
  14 + }
  15 +
  16 + public NumberVote(String info) {
  17 + super(AnsType_Number);
  18 + this.info = info;
  19 + }
  20 +
  21 + public NumberVote() {
  22 + super(AnsType_Number);
  23 + }
  24 +
  25 + public byte[] toBytes(){
  26 + byte[] mBuffer = new byte[0x1F + 4];
  27 + Arrays.fill(mBuffer, (byte) 0x0);
  28 + mBuffer[0] = (byte) 0xF5;
  29 + mBuffer[1] = (byte) 0xAA;
  30 + mBuffer[2] = (byte) 0xAA;
  31 + mBuffer[3] = (byte) 0x1F;
  32 + mBuffer[4] = 0x73;
  33 + mBuffer[5] = SerialManager.getInstance().getSeq();
  34 + mBuffer[6] = (byte)msgType;
  35 + mBuffer[7] = (byte) ansType;
  36 + byte[] val = util_encodeBCD(info.getBytes());
  37 + System.arraycopy(val, 0, mBuffer, 8, 8);
  38 +
  39 + return mBuffer;
  40 + }
  41 +
  42 +
  43 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/OnLineInfo.java 0 → 100644
  1 +package com.sunvote.xpadapi.service.bean;
  2 +
  3 +public class OnLineInfo {
  4 + private int onLine; //键盘是否在线 1 在线 2 离线
  5 + private int idMode;//基站的识别模式
  6 + private int chan; //当前频点号
  7 + private int rssi; //接收到基站的信号强度RSSI值,负数,越小表示信号越大
  8 + private int tx; //1表示刚才1秒内有提交数据过 0 表示没有
  9 + private int rx; //1 表示刚才1秒内收到过基站的投票指令(特指投票中) 0 表示没有
  10 + private int baseId;
  11 + private int keyId;
  12 + private String keySn;
  13 + private int comError=0;
  14 +
  15 + public int getOnLine() {
  16 + return onLine;
  17 + }
  18 +
  19 + public void setOnLine(int onLine) {
  20 + this.onLine = onLine;
  21 + }
  22 +
  23 + public int getIdMode() {
  24 + return idMode;
  25 + }
  26 +
  27 + public void setIdMode(int idMode) {
  28 + this.idMode = idMode;
  29 + }
  30 +
  31 + public int getChan() {
  32 + return chan;
  33 + }
  34 +
  35 + public void setChan(int chan) {
  36 + this.chan = chan;
  37 + }
  38 +
  39 + public int getRssi() {
  40 + return rssi;
  41 + }
  42 +
  43 + public void setRssi(int rssi) {
  44 + this.rssi = rssi;
  45 + }
  46 +
  47 + public int getTx() {
  48 + return tx;
  49 + }
  50 +
  51 + public void setTx(int tx) {
  52 + this.tx = tx;
  53 + }
  54 +
  55 + public int getRx() {
  56 + return rx;
  57 + }
  58 +
  59 + public void setRx(int rx) {
  60 + this.rx = rx;
  61 + }
  62 +
  63 + public int getBaseId() {
  64 + return baseId;
  65 + }
  66 +
  67 + public void setBaseId(int baseId) {
  68 + this.baseId = baseId;
  69 + }
  70 +
  71 + public int getKeyId() {
  72 + return keyId;
  73 + }
  74 +
  75 + public void setKeyId(int keyId) {
  76 + this.keyId = keyId;
  77 + }
  78 +
  79 + public String getKeySn() {
  80 + return keySn;
  81 + }
  82 +
  83 + public void setKeySn(String keySn) {
  84 + this.keySn = keySn;
  85 + }
  86 +
  87 + public int getComError() {
  88 + return comError;
  89 + }
  90 +
  91 + public void setComError(int comError) {
  92 + this.comError = comError;
  93 + }
  94 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/Packet.java 0 → 100644
  1 +package com.sunvote.xpadapi.service.bean;
  2 +
  3 +import com.sunvote.xpadapi.service.listener.OnSendPacket;
  4 +
  5 +public class Packet {
  6 +
  7 + public static final int OVER_TIME_COUNTS = 6;
  8 +
  9 + public static final int BaseStatusNum = 1 ;
  10 + public static final int VoteStatusNum = 2 ;
  11 + public static final int ExecKeypadMatchNum = 6 ;
  12 + public static final int GetWorkModeNum = 11 ;
  13 + public static final int SetWorkModeNum = 12 ;
  14 + public static final int GetKeypadParam = 13 ;
  15 +
  16 + public static final int CommunicationTestMatchNum = 30 ;
  17 +
  18 + private int sendNo ;
  19 + private byte[] datas;
  20 + private int sendCount = 0 ;
  21 + private boolean isSync = false;
  22 +
  23 + private OnSendPacket onSendPacket;
  24 +
  25 + public int getSendNo() {
  26 + return sendNo;
  27 + }
  28 +
  29 + public void setSendNo(int sendNo) {
  30 + this.sendNo = sendNo;
  31 + }
  32 +
  33 + public byte[] getDatas() {
  34 + return datas;
  35 + }
  36 +
  37 + public void setDatas(byte[] datas) {
  38 + this.datas = datas;
  39 + }
  40 +
  41 + public OnSendPacket getOnSendPacket() {
  42 + return onSendPacket;
  43 + }
  44 +
  45 + public void setOnSendPacket(OnSendPacket onSendPacket) {
  46 + this.onSendPacket = onSendPacket;
  47 + }
  48 +
  49 + public void addSendCount(){
  50 + sendCount ++ ;
  51 + }
  52 +
  53 + public boolean needSend(){
  54 + if(sendCount < OVER_TIME_COUNTS){
  55 + return true;
  56 + }
  57 + return false;
  58 + }
  59 +
  60 + public boolean isSync() {
  61 + return isSync;
  62 + }
  63 +
  64 + public void setSync(boolean sync) {
  65 + isSync = sync;
  66 + }
  67 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/SelectOtherVote.java 0 → 100644
  1 +package com.sunvote.xpadapi.service.bean;
  2 +
  3 +import com.sunvote.xpadapi.service.SerialManager;
  4 +import com.sunvote.xpadapi.service.XpadApiServiceInfoProxyManager;
  5 +import com.sunvote.xpadapi.util.LogUtil;
  6 +
  7 +import java.util.Arrays;
  8 +
  9 +public class SelectOtherVote extends Vote {
  10 +
  11 + public static final int AnsType_SelectOther = 26;
  12 +
  13 + private int num;
  14 + private String info;
  15 +
  16 + public SelectOtherVote(int num, String info) {
  17 + super(AnsType_SelectOther);
  18 + this.num = num;
  19 + this.info = info;
  20 + }
  21 +
  22 + public SelectOtherVote() {
  23 + super(AnsType_SelectOther);
  24 + }
  25 +
  26 + public void setNum(int num) {
  27 + this.num = num;
  28 + }
  29 +
  30 + public void setInfo(String info) {
  31 + this.info = info;
  32 + }
  33 +
  34 + @Override
  35 + public byte[] toBytes() {
  36 + byte[] mBuffer = new byte[0x1F + 4];
  37 + Arrays.fill(mBuffer, (byte) 0x0);
  38 + mBuffer[0] = (byte) 0xF5;
  39 + mBuffer[1] = (byte) 0xAA;
  40 + mBuffer[2] = (byte) 0xAA;
  41 + mBuffer[3] = (byte) 0x1F;
  42 + mBuffer[4] = 0x73;
  43 + mBuffer[5] = SerialManager.getInstance().getSeq();// 流水号
  44 + mBuffer[6] = (byte)msgType;
  45 + mBuffer[7] = (byte) ansType;
  46 + mBuffer[8] = (byte) ok;// ALLOK
  47 + int pos = 9;
  48 + mBuffer[pos++] = (byte) (num >> 8);
  49 + mBuffer[pos++] = (byte) num;
  50 + mBuffer[pos++] = 0;// slot
  51 + try {
  52 + byte[] name = info.getBytes(XpadApiServiceInfoProxyManager.getInstance().getCharset());
  53 + System.arraycopy(name, 0, mBuffer, pos, name.length > 16 ? 16 : name.length);
  54 + } catch (Exception e) {
  55 + LogUtil.e(XpadApiServiceInfoProxyManager.TAG, "SelectOtherVote", e);
  56 + }
  57 + return mBuffer;
  58 + }
  59 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/SelectVote.java 0 → 100644
  1 +package com.sunvote.xpadapi.service.bean;
  2 +
  3 +import com.sunvote.xpadapi.service.SerialManager;
  4 +
  5 +import java.util.Arrays;
  6 +
  7 +public class SelectVote extends Vote{
  8 +
  9 + public final static int SELECT_VOTE_TYPE = 2;
  10 +
  11 + private int content;
  12 + private int time;
  13 +
  14 + public SelectVote(int content, int time) {
  15 + super(SELECT_VOTE_TYPE);
  16 + this.content = content;
  17 + this.time = time;
  18 + }
  19 +
  20 + public SelectVote() {
  21 + super(SELECT_VOTE_TYPE);
  22 + }
  23 + public void setContent(int content) {
  24 + this.content = content;
  25 + }
  26 +
  27 + public void setTime(int time) {
  28 + this.time = time;
  29 + }
  30 +
  31 + public byte[] toBytes(){
  32 + byte[] mBuffer = new byte[0x1F + 4];
  33 + Arrays.fill(mBuffer, (byte) 0x0);
  34 + mBuffer[0] = (byte) 0xF5;
  35 + mBuffer[1] = (byte) 0xAA;
  36 + mBuffer[2] = (byte) 0xAA;
  37 + mBuffer[3] = (byte) 0x1F;
  38 + mBuffer[4] = 0x73;
  39 + mBuffer[5] = SerialManager.getInstance().getSeq();
  40 + mBuffer[6] = msgType;
  41 + mBuffer[7] = (byte) ansType;
  42 + mBuffer[8] = (byte) ((time >> 8) & 0xff);// 原来的计算居然是这样 没懂
  43 + mBuffer[9] = (byte) (time & 0xff);
  44 + mBuffer[10] = (byte) ((time >> 8) & 0xff);
  45 + mBuffer[11] = (byte) (time & 0xff);
  46 + return mBuffer;
  47 + }
  48 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/ServiceTypeVote.java 0 → 100644
  1 +package com.sunvote.xpadapi.service.bean;
  2 +
  3 +import com.sunvote.xpadapi.service.SerialManager;
  4 +
  5 +import java.util.Arrays;
  6 +
  7 +/**
  8 + * 服务申请
  9 + */
  10 +public class ServiceTypeVote extends Vote {
  11 +
  12 + public static final int AnsType_Service = 33;
  13 +
  14 + private int serviceType = 0;
  15 +
  16 + public ServiceTypeVote(int serviceType) {
  17 + super(AnsType_Service);
  18 + this.serviceType = serviceType;
  19 + }
  20 +
  21 + public ServiceTypeVote() {
  22 + super(AnsType_Service);
  23 + }
  24 +
  25 + public void setServiceType(int serviceType) {
  26 + this.serviceType = serviceType;
  27 + }
  28 +
  29 + @Override
  30 + public byte[] toBytes() {
  31 + byte[] mBuffer = new byte[0x1F + 4];
  32 + Arrays.fill(mBuffer, (byte) 0x0);
  33 + mBuffer[0] = (byte) 0xF5;
  34 + mBuffer[1] = (byte) 0xAA;
  35 + mBuffer[2] = (byte) 0xAA;
  36 + mBuffer[3] = (byte) 0x1F;
  37 + mBuffer[4] = 0x73;
  38 + mBuffer[5] = SerialManager.getInstance().getSeq();// 流水号
  39 + mBuffer[6] = msgType;
  40 + mBuffer[7] = (byte) ansType;
  41 + mBuffer[8] = 4;
  42 + mBuffer[9] = (byte) serviceType;
  43 + mBuffer[10] = mBuffer[5];
  44 + return mBuffer;
  45 + }
  46 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/SingleVote.java 0 → 100644
  1 +package com.sunvote.xpadapi.service.bean;
  2 +
  3 +import com.sunvote.xpadapi.service.SerialManager;
  4 +
  5 +import java.util.Arrays;
  6 +
  7 +public class SingleVote extends Vote {
  8 +
  9 + private int info;
  10 +
  11 + public SingleVote(int info) {
  12 + super(1);
  13 + this.info = info;
  14 + }
  15 +
  16 + public SingleVote() {
  17 + super(1);
  18 + }
  19 +
  20 + public void setInfo(int info) {
  21 + this.info = info;
  22 + }
  23 +
  24 + public byte[] toBytes() {
  25 + byte[] mBuffer = new byte[0x1F + 4];
  26 + Arrays.fill(mBuffer, (byte) 0x0);
  27 + mBuffer[0] = (byte) 0xF5;
  28 + mBuffer[1] = (byte) 0xAA;
  29 + mBuffer[2] = (byte) 0xAA;
  30 + mBuffer[3] = (byte) 0x1F;
  31 + mBuffer[4] = 0x73;
  32 + mBuffer[5] = SerialManager.getInstance().getSeq();
  33 + mBuffer[6] = msgType;
  34 + mBuffer[7] = (byte) ansType;
  35 + mBuffer[8] = (byte) info;
  36 + return mBuffer;
  37 + }
  38 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/Vote.java 0 → 100644
  1 +package com.sunvote.xpadapi.service.bean;
  2 +
  3 +import com.sunvote.xpadapi.service.SerialManager;
  4 +
  5 +import java.util.Arrays;
  6 +
  7 +public class Vote {
  8 +
  9 + protected int ansType = 16;
  10 + protected static byte msgType = 1;// MSGTYPE 1:ID mode, 2:SN
  11 + private String info;
  12 + protected int ok;
  13 +
  14 + public Vote(int ansType) {
  15 + this.ansType = ansType;
  16 + }
  17 +
  18 + public static void setMsgTypeIdModel() {
  19 + msgType = 1;
  20 + }
  21 +
  22 + public static void setMsgTypeSnModel() {
  23 + msgType = 2;
  24 + }
  25 +
  26 + public void setInfo(String info) {
  27 + this.info = info;
  28 + }
  29 +
  30 + public void setOk(int ok) {
  31 + this.ok = ok;
  32 + }
  33 +
  34 + /**
  35 + * 把字符串形式转换为字节形式
  36 + */
  37 + protected byte[] util_encodeBCD(byte[] cs) {
  38 + byte[] rs = new byte[17];
  39 + Arrays.fill(rs, (byte) 0xff);//
  40 +
  41 + int len = cs.length < 16 ? cs.length : 16;
  42 + int io = 0;
  43 +
  44 + for (int i = 0; i < len; i += 2) {
  45 + int n = encodeBCD(cs[i]);
  46 + n <<= 4;
  47 + if (i + 1 == cs.length) {
  48 + rs[io++] = (byte) (n | 0xf);
  49 + break;
  50 + }
  51 +
  52 + n |= encodeBCD(cs[i + 1]);
  53 + if (n < 0) {
  54 + break;
  55 + }
  56 + rs[io++] = (byte) n;
  57 + }
  58 + rs[++io] = 0;
  59 + return rs;
  60 + }
  61 +
  62 + protected int encodeBCD(byte c) {
  63 + if (c >= 'a' && c <= 'f') {
  64 + return 10 + (c - 'a');
  65 + } else if (c >= '0' && c <= '9') {
  66 + return c - '0';
  67 + } else if (c >= 'A' && c <= 'F') {
  68 + return 10 + (c - 'A');
  69 + } else if (c == '.') {
  70 + return 0xE;
  71 + }
  72 + return -1;
  73 + }
  74 +
  75 + public byte[] toBytes() {
  76 + byte[] mBuffer = new byte[0x1F + 4];
  77 + Arrays.fill(mBuffer, (byte) 0x0);
  78 + mBuffer[0] = (byte) 0xF5;
  79 + mBuffer[1] = (byte) 0xAA;
  80 + mBuffer[2] = (byte) 0xAA;
  81 + mBuffer[3] = (byte) 0x1F;
  82 + mBuffer[4] = 0x73;
  83 + mBuffer[5] = SerialManager.getInstance().getSeq();
  84 + mBuffer[6] = msgType;
  85 + mBuffer[7] = (byte) ansType;
  86 + mBuffer[8] = (byte)ok;
  87 + int pos = 9;
  88 + if(info != null) {
  89 + String[] item = info.split(":");
  90 + if (item.length > 1) {
  91 + int num = Integer.parseInt(item[0]);
  92 + String val = item[1];
  93 + mBuffer[pos++] = (byte) (num >> 8);
  94 + mBuffer[pos++] = (byte) num;
  95 + mBuffer[pos++] = 0;// slot
  96 + try {
  97 + byte[] name = val.getBytes("GB2312");
  98 + System.arraycopy(name, 0, mBuffer, pos, name.length > 16 ? 16 : name.length);
  99 + } catch (Exception e) {
  100 + }
  101 + }
  102 + }
  103 + return mBuffer;
  104 + }
  105 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/BaseInfoChanageListener.java 0 → 100644
  1 +package com.sunvote.xpadapi.service.listener;
  2 +
  3 +import com.sunvote.xpadapi.service.bean.BaseInfo;
  4 +
  5 +public interface BaseInfoChanageListener {
  6 +
  7 + void onBaseInfoChange(BaseInfo newBaseInfo);
  8 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/BaseVoteInfoChanageListener.java 0 → 100644
  1 +package com.sunvote.xpadapi.service.listener;
  2 +
  3 +import com.sunvote.xpadapi.service.bean.BaseVoteInfo;
  4 +
  5 +public interface BaseVoteInfoChanageListener {
  6 +
  7 + void onBaseVoteInfoListener(BaseVoteInfo newBaseVoteInfo);
  8 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/IModesVoteInfo.java 0 → 100644
  1 +package com.sunvote.xpadapi.service.listener;
  2 +
  3 +public interface IModesVoteInfo {
  4 +
  5 +
  6 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/KeyPadinfoChanageListener.java 0 → 100644
  1 +package com.sunvote.xpadapi.service.listener;
  2 +
  3 +import com.sunvote.xpadapi.service.bean.KeypadInfo;
  4 +
  5 +public interface KeyPadinfoChanageListener {
  6 +
  7 + void onKeyPadinfoChanage(KeypadInfo newKeypadInfo);
  8 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/ModelInfoChanageListener.java 0 → 100644
  1 +package com.sunvote.xpadapi.service.listener;
  2 +
  3 +import com.sunvote.xpadapi.service.bean.ModelInfo;
  4 +
  5 +public interface ModelInfoChanageListener {
  6 +
  7 + void onModelInfoChanage(ModelInfo newModelInfo);
  8 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/OnDataReceiver.java 0 → 100644
  1 +package com.sunvote.xpadapi.service.listener;
  2 +
  3 +public interface OnDataReceiver {
  4 +
  5 + /**
  6 + * 收到信息
  7 + * @param datas
  8 + */
  9 + void onDataReceiver(byte[] datas);
  10 +
  11 + /**
  12 + * 发出的信息
  13 + * @param datas
  14 + */
  15 + void onDataSender(byte[] datas);
  16 +
  17 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/OnSendPacket.java 0 → 100644
  1 +package com.sunvote.xpadapi.service.listener;
  2 +
  3 +import com.sunvote.xpadapi.service.bean.Packet;
  4 +
  5 +public interface OnSendPacket {
  6 +
  7 + void onSuccess(Packet packet);
  8 +
  9 + void onFail(Packet packet);
  10 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/OnSender.java 0 → 100644
  1 +package com.sunvote.xpadapi.service.listener;
  2 +
  3 +public interface OnSender<T> {
  4 +
  5 + void onSuccess(T t);
  6 +
  7 + void onFail(T t);
  8 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/OnlineInfoChanageListener.java 0 → 100644
  1 +package com.sunvote.xpadapi.service.listener;
  2 +
  3 +import com.sunvote.xpadapi.service.bean.OnLineInfo;
  4 +
  5 +public interface OnlineInfoChanageListener {
  6 +
  7 + void onOnlineInfoChanage(OnLineInfo newOnlineInfo);
  8 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/usb/UsbTransferManager.java 0 → 100644
  1 +package com.sunvote.xpadapi.usb;
  2 +
  3 +import android.app.PendingIntent;
  4 +import android.content.BroadcastReceiver;
  5 +import android.content.Context;
  6 +import android.content.Intent;
  7 +import android.content.IntentFilter;
  8 +import android.hardware.usb.UsbDevice;
  9 +import android.hardware.usb.UsbDeviceConnection;
  10 +import android.hardware.usb.UsbEndpoint;
  11 +import android.hardware.usb.UsbInterface;
  12 +import android.hardware.usb.UsbManager;
  13 +import android.os.Handler;
  14 +import android.os.HandlerThread;
  15 +
  16 +
  17 +import com.sunvote.xpadapi.util.LogUtil;
  18 +
  19 +import java.io.IOException;
  20 +import java.io.InputStream;
  21 +import java.io.OutputStream;
  22 +import java.util.HashMap;
  23 +import java.util.LinkedList;
  24 +import java.util.concurrent.locks.Condition;
  25 +import java.util.concurrent.locks.Lock;
  26 +import java.util.concurrent.locks.ReentrantLock;
  27 +
  28 +/***
  29 + * @Auther Elvis
  30 + */
  31 +public class UsbTransferManager {
  32 +
  33 + public interface OnUsbConnectListener{
  34 + boolean onConnect(boolean isConnected);
  35 + }
  36 +
  37 + public static final String TAG = UsbTransferManager.class.getSimpleName();
  38 + private static UsbTransferManager instance = null ;
  39 + private HandlerThread workThread = new HandlerThread("usb workThread");
  40 + private Handler workHandler = null;
  41 + private boolean stop = false;
  42 + private OnUsbConnectListener onUsbConnectListener;
  43 +
  44 + public void setOnUsbConnectListener(OnUsbConnectListener onUsbConnectListener) {
  45 + this.onUsbConnectListener = onUsbConnectListener;
  46 + }
  47 +
  48 + private UsbTransferManager(){
  49 + workThread.start();
  50 + workHandler = new Handler(workThread.getLooper());
  51 + }
  52 +
  53 + public static UsbTransferManager getInstance(){
  54 + if(instance == null){
  55 + synchronized(UsbTransferManager.class){
  56 + if(instance == null){
  57 + instance = new UsbTransferManager();
  58 + }
  59 + }
  60 + }
  61 + return instance;
  62 + }
  63 +
  64 + public void startWork(){
  65 + stop = false;
  66 + workHandler.post(usbConnectInit);
  67 + }
  68 +
  69 + public void stopWork(){
  70 + mUsbDevice = null;
  71 + mUsbConnection = null;
  72 + epIn = null;
  73 + epOut = null;
  74 + workHandler.removeCallbacks(usbConnectInit);
  75 + workHandler.removeCallbacks(usbConnect);
  76 + workHandler.removeCallbacks(usbConnectionReceiverTask);
  77 + stop = true;
  78 + }
  79 +
  80 + private UsbOutputStream outputStream = new UsbOutputStream();
  81 + private UsbInputStream inputStream = new UsbInputStream();
  82 +
  83 + public UsbInputStream getInputStream() {
  84 + return inputStream;
  85 + }
  86 +
  87 + public UsbOutputStream getOutputStream() {
  88 + return outputStream;
  89 + }
  90 +
  91 + private long lastOpenTime;
  92 + private class UsbPermissionReceiver extends BroadcastReceiver {
  93 + public void onReceive(Context context, Intent intent) {
  94 + String action = intent.getAction();
  95 + if (ACTION_USB_PERMISSION.equals(action)) {
  96 + synchronized (this) {
  97 + UsbDevice device = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
  98 + if (device.getDeviceName().equals(mUsbDevice.getDeviceName())) {
  99 + if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
  100 + // 授权成功,在这里进行打开设备操作
  101 + if (System.currentTimeMillis() - lastOpenTime > 1000) {
  102 + lastOpenTime = System.currentTimeMillis();
  103 + workHandler.removeCallbacks(usbConnectInit);
  104 + workHandler.removeCallbacks(usbConnect);
  105 + if(!stop){
  106 + workHandler.postDelayed(usbConnect,0);
  107 + }
  108 + }
  109 + }else{
  110 + if(!stop){
  111 + workHandler.postDelayed(usbConnectInit,20000);
  112 + }
  113 + }
  114 + }
  115 + }
  116 + }
  117 + }
  118 + }
  119 +
  120 + private Runnable usbConnectionReceiverTask = new Runnable() {
  121 + @Override
  122 + public void run() {
  123 + if (usbManager != null) {
  124 + HashMap<String, UsbDevice> map = usbManager.getDeviceList();
  125 + boolean find = false;
  126 + for (UsbDevice device : map.values()) {
  127 + LogUtil.d(TAG, "找到基站: Vid:" + device.getVendorId() + " Pid:" + device.getProductId());
  128 + if (device.getVendorId() == VendorID && device.getProductId() == ProductID
  129 + || device.getVendorId() == VendorID_2 && device.getProductId() == ProductID_2
  130 + || device.getVendorId() == VendorID_3 && device.getProductId() == ProductID_3) {
  131 + find = true;
  132 + workHandler.postDelayed(usbConnectionReceiverTask, 1000);
  133 + break;
  134 + }
  135 + }
  136 + if (!find) {
  137 + stopWork();
  138 + startWork();
  139 + }
  140 + }
  141 + }
  142 + };
  143 +
  144 + private Runnable usbConnectInit = new Runnable() {
  145 + @Override
  146 + public void run() {
  147 + LogUtil.i(TAG, "发起USB初始化!");
  148 + boolean find = false;
  149 + workHandler.removeCallbacks(usbConnectionReceiverTask);
  150 + if(usbManager != null) {
  151 + HashMap<String, UsbDevice> map = usbManager.getDeviceList();
  152 + for (UsbDevice device : map.values()) {
  153 + LogUtil.d(TAG, "找到基站: Vid:" + device.getVendorId() + " Pid:" + device.getProductId());
  154 + if (device.getVendorId() == VendorID && device.getProductId() == ProductID
  155 + || device.getVendorId() == VendorID_2 && device.getProductId() == ProductID_2
  156 + || device.getVendorId() == VendorID_3 && device.getProductId() == ProductID_3) {
  157 + mUsbDevice = device;
  158 + find = true;
  159 + if (!usbManager.hasPermission(device)) {
  160 + if (usbPermissionReceiver == null) {
  161 + usbPermissionReceiver = new UsbPermissionReceiver();
  162 + }
  163 + // 申请权限
  164 + Intent intent = new Intent(ACTION_USB_PERMISSION);
  165 + PendingIntent mPermissionIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0);
  166 + IntentFilter permissionFilter = new IntentFilter(ACTION_USB_PERMISSION);
  167 + mContext.registerReceiver(usbPermissionReceiver, permissionFilter);
  168 + usbManager.requestPermission(device, mPermissionIntent);
  169 + if(!stop){
  170 + workHandler.postDelayed(usbConnectInit,20 * 1000);
  171 + }
  172 + } else {
  173 + if(!stop){
  174 + workHandler.postDelayed(usbConnect,10);
  175 + }
  176 + }
  177 + }
  178 + }
  179 +
  180 + }
  181 + if(!find){
  182 + workHandler.removeCallbacks(usbConnectInit);
  183 + if(!stop){
  184 + workHandler.postDelayed(usbConnectInit,2000);
  185 + }
  186 + }
  187 + }
  188 + };
  189 +
  190 +
  191 + private Runnable usbConnect = new Runnable() {
  192 + @Override
  193 + public void run() {
  194 + LogUtil.i(TAG, "发起USB键盘连接!");
  195 + if(openUsbDevice()){
  196 + if(onUsbConnectListener != null){
  197 + onUsbConnectListener.onConnect(true);
  198 + }
  199 + workHandler.postDelayed(usbConnectionReceiverTask,2000);
  200 + };
  201 + }
  202 + };
  203 +
  204 + private Runnable readData = new Runnable() {
  205 + @Override
  206 + public void run() {
  207 + byte[] datas = receiveUsbRequestData();
  208 + LogUtil.i(TAG, "RECEIVEA DATA:", datas);
  209 + if(datas != null) {
  210 + int length = datas.length;
  211 + try {
  212 + try {
  213 + lock.lock();
  214 + if (linkedList.size() < MAX_CACHE_SIZE) {
  215 + for (int i = length - 1; i >= 0; i--) {
  216 + linkedList.push(datas[i]);
  217 + }
  218 + }
  219 + } finally {
  220 + empty.signal();
  221 + lock.unlock();
  222 + }
  223 + } catch (Exception e) {
  224 + LogUtil.e(TAG, "UDP receiver message", e);
  225 + close = true;
  226 + }
  227 + if(!stop){
  228 + workHandler.post(readData);
  229 + }
  230 + }else{
  231 + stopWork();
  232 + startWork();
  233 + }
  234 +
  235 + }
  236 + };
  237 +
  238 + /**
  239 + * 打开连接
  240 + *
  241 + * @paramdevice
  242 + */
  243 + private boolean openUsbDevice() {
  244 +
  245 + if (mUsbDevice == null)
  246 + return false;
  247 +
  248 + if(mUsbDevice.getInterfaceCount() == 0){
  249 + return false;
  250 + }
  251 + mUsbInterface = mUsbDevice.getInterface(0);
  252 + setEndpoint(mUsbInterface);
  253 + mUsbConnection = usbManager.openDevice(mUsbDevice);
  254 + LogUtil.i(TAG,"打开USB连接");
  255 + if (mUsbConnection != null) {
  256 + return mUsbConnection.claimInterface(mUsbInterface, true);
  257 + }
  258 + return false;
  259 + }
  260 +
  261 + private int sendDataBulkTransfer(byte[] buffer) {
  262 + final int length = buffer.length;
  263 + int ref = -100;
  264 + if (epOut != null && mUsbConnection != null) {
  265 + ref = mUsbConnection.bulkTransfer(epOut, buffer, length, 100);
  266 + mUsbConnection.claimInterface(mUsbInterface, true);
  267 + LogUtil.d(TAG, "发送数据成功有:" + ref);
  268 + if(ref <0 ){
  269 + if(onUsbConnectListener != null){
  270 + onUsbConnectListener.onConnect(false);
  271 + }
  272 + workHandler.removeCallbacks(usbConnectionReceiverTask);
  273 + workHandler.post(usbConnectionReceiverTask);
  274 + }
  275 + }else{
  276 + LogUtil.d(TAG, "未连接:" + ref);
  277 + }
  278 + return ref;
  279 + }
  280 +
  281 + public byte[] receiveUsbRequestData() {
  282 + if(epIn != null && mUsbConnection != null) {
  283 + byte[] bytes = new byte[epIn.getMaxPacketSize()];
  284 + int ret = mUsbConnection.bulkTransfer(epIn, bytes, bytes.length, 100);
  285 + if (ret > 0) {
  286 + return bytes;
  287 + }
  288 + }
  289 + return null;
  290 + }
  291 +
  292 + /**
  293 + * UsbInterface 进行端点设置和通讯
  294 + *
  295 + * @param intf
  296 + */
  297 + private void setEndpoint(UsbInterface intf) {
  298 + if (intf == null)
  299 + return;
  300 + // 设置接收数据的端点
  301 + if (intf.getEndpoint(0) != null) {
  302 + epIn = intf.getEndpoint(0);
  303 + }
  304 + // 当端点为2的时候
  305 + if (intf.getEndpointCount() == 2) {
  306 + // 设置发送数据的断点
  307 + if (intf.getEndpoint(1) != null)
  308 + epOut = intf.getEndpoint(1);
  309 + }
  310 + }
  311 +
  312 + public void setUsbManager(UsbManager usbManager) {
  313 + this.usbManager = usbManager;
  314 + }
  315 +
  316 + public void setContext(Context mContext) {
  317 + this.mContext = mContext;
  318 + }
  319 +
  320 + public class UsbOutputStream extends OutputStream{
  321 +
  322 + @Override
  323 + public void write(int b) throws IOException {
  324 + sendDataBulkTransfer(new byte[]{(byte)b});
  325 + }
  326 +
  327 + @Override
  328 + public void write(byte[] b) throws IOException {
  329 + sendDataBulkTransfer(b);
  330 + }
  331 +
  332 + @Override
  333 + public void write(byte[] b, int off, int len) throws IOException {
  334 + byte[] temp = new byte[len];
  335 + System.arraycopy(b, off, temp, 0, len);
  336 + sendDataBulkTransfer(temp);
  337 + }
  338 + }
  339 +
  340 + private LinkedList<Byte> linkedList = new LinkedList<Byte>();
  341 + public long MAX_CACHE_SIZE = 4 * 1024;
  342 + private Lock lock = new ReentrantLock();
  343 + private Condition empty = lock.newCondition();
  344 + private boolean close = false;
  345 + public class UsbInputStream extends InputStream{
  346 + @Override
  347 + public int read() throws IOException {
  348 + if (close) {
  349 + throw new IOException("the stream has closed");
  350 + }
  351 +
  352 + try {
  353 + lock.lock();
  354 + while (linkedList.isEmpty()) {
  355 + try {
  356 + empty.await();
  357 + } catch (InterruptedException e) {
  358 + LogUtil.e(TAG,e);
  359 + }
  360 + }
  361 + return linkedList.pop();
  362 + } finally {
  363 + lock.unlock();
  364 + }
  365 + }
  366 +
  367 +
  368 + public boolean isClose() {
  369 + return close;
  370 + }
  371 +
  372 + @Override
  373 + public void close() throws IOException {
  374 + close = true;
  375 + super.close();
  376 + }
  377 +
  378 + @Override
  379 + public int read(byte[] buffer) throws IOException {
  380 + try {
  381 + lock.lock();
  382 + if (buffer == null) {
  383 + throw new IOException("buffer is empty");
  384 + }
  385 + if (close) {
  386 + throw new IOException("the stream has closed");
  387 + }
  388 +
  389 + while (linkedList.isEmpty()) {
  390 + try {
  391 + empty.await();
  392 + } catch (InterruptedException e) {
  393 + e.printStackTrace();
  394 + }
  395 + }
  396 + int index = 0;
  397 + while (index < buffer.length && !linkedList.isEmpty()) {
  398 + buffer[index++] = linkedList.pop();
  399 + }
  400 + return index;
  401 + } finally {
  402 + lock.unlock();
  403 + }
  404 + }
  405 +
  406 +
  407 + @Override
  408 + public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException {
  409 + try {
  410 + lock.lock();
  411 + if (buffer == null) {
  412 + throw new IOException("buffer is empty");
  413 + }
  414 + if (close) {
  415 + throw new IOException("the stream has closed");
  416 + }
  417 +
  418 + while (linkedList.isEmpty()) {
  419 + try {
  420 + empty.await();
  421 + } catch (InterruptedException e) {
  422 + e.printStackTrace();
  423 + }
  424 + }
  425 + int index = 0;
  426 + while (index < byteCount && !linkedList.isEmpty()) {
  427 + index++;
  428 + buffer[byteOffset++] = linkedList.pop();
  429 + }
  430 + return index;
  431 + } finally {
  432 + lock.unlock();
  433 + }
  434 + }
  435 + }
  436 +
  437 + private UsbManager usbManager ;
  438 + private UsbDevice mUsbDevice;
  439 + private UsbDeviceConnection mUsbConnection;
  440 + private UsbInterface mUsbInterface;
  441 + private UsbEndpoint epOut, epIn;
  442 + private UsbPermissionReceiver usbPermissionReceiver;
  443 + private Context mContext ;
  444 +
  445 + private static final int VendorID = 0x03eb;
  446 + private static final int ProductID = 0x6201;
  447 + private static final int VendorID_2 = 0x0d8c;
  448 + private static final int ProductID_2 = 0xEA10;
  449 + private static final int VendorID_3 = 0x2F70;
  450 + private static final int ProductID_3 = 0xEA10;
  451 + private final String ACTION_USB_PERMISSION = "com.hhd.USB_PERMISSION";
  452 + private boolean isUsbReceiver = false;
  453 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/util/ByteUtils.java 0 → 100644
  1 +package com.sunvote.xpadapi.util;
  2 +
  3 +public class ByteUtils {
  4 +
  5 + private ByteUtils() {
  6 + }
  7 +
  8 + public static String bytesToHexString(byte[] src, int length) {
  9 + StringBuilder stringBuilder = new StringBuilder("");
  10 + if (src == null || src.length <= 0) {
  11 + return null;
  12 + }
  13 + for (int i = 0; i < src.length && i < length; i++) {
  14 + int v = src[i] & 0xFF;
  15 + String hv = Integer.toHexString(v);
  16 + if (hv.length() < 2) {
  17 + stringBuilder.append(0);
  18 + }
  19 + stringBuilder.append(hv);
  20 + stringBuilder.append(" ");
  21 + }
  22 + return stringBuilder.toString();
  23 + }
  24 +
  25 + public static String bytesToHexString(byte[] src) {
  26 + StringBuilder stringBuilder = new StringBuilder("");
  27 + if (src == null || src.length <= 0) {
  28 + return null;
  29 + }
  30 + for (int i = 0; i < src.length; i++) {
  31 + int v = src[i] & 0xFF;
  32 + String hv = Integer.toHexString(v);
  33 + if (hv.length() < 2) {
  34 + stringBuilder.append(0);
  35 + }
  36 + stringBuilder.append(hv);
  37 + stringBuilder.append(" ");
  38 + }
  39 + return stringBuilder.toString();
  40 + }
  41 +
  42 + public static int findBytes(byte[] source,byte[] find,int index){
  43 + int flag = -1;
  44 + for (int j = index; j < source.length; j++) {
  45 + if (source.length >= j + find.length) {
  46 + if (compareByte(source, j, find)) {
  47 + flag = j;
  48 + break;
  49 + }
  50 + }
  51 + }
  52 + return flag;
  53 + }
  54 +
  55 + public static int byte1ToInt(byte b) {
  56 + int ret = 0;
  57 + ret += (b & 0x000000FF);
  58 + return ret;
  59 + }
  60 +
  61 + private static boolean compareByte(byte[] source, int start, byte[] find) {
  62 + if (source.length >= start + find.length) {
  63 + for (int i = 0; i < find.length; i++) {
  64 + if (source[start + i] != find[i]) {
  65 + return false;
  66 + }
  67 + }
  68 + return true;
  69 + }
  70 + return false;
  71 + }
  72 +
  73 + /**
  74 + * Convert hex string to byte[]
  75 + *
  76 + * @param hexString the hex string
  77 + * @return byte[]
  78 + */
  79 + public static byte[] hexStringToBytes(String hexString) {
  80 + if (hexString == null || hexString.equals("")) {
  81 + return null;
  82 + }
  83 + hexString = hexString.toUpperCase();
  84 + int length = hexString.length() / 2;
  85 + char[] hexChars = hexString.toCharArray();
  86 + byte[] d = new byte[length];
  87 + for (int i = 0; i < length; i++) {
  88 + int pos = i * 2;
  89 + d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1]));
  90 + }
  91 + return d;
  92 + }
  93 +
  94 + /**
  95 + * Convert char to byte
  96 + *
  97 + * @param c char
  98 + * @return byte
  99 + */
  100 + private static byte charToByte(char c) {
  101 + return (byte) "0123456789ABCDEF".indexOf(c);
  102 + }
  103 +
  104 +
  105 + public static byte[] intToBytes(int value) {
  106 + byte[] src = new byte[4];
  107 + src[3] = (byte) ((value >> 24) & 0xFF);
  108 + src[2] = (byte) ((value >> 16) & 0xFF);
  109 + src[1] = (byte) ((value >> 8) & 0xFF);
  110 + src[0] = (byte) (value & 0xFF);
  111 + return src;
  112 + }
  113 +
  114 + public static byte[] int2Bytes(int value) {
  115 + byte[] src = new byte[2];
  116 + src[0] = (byte) ((value >> 8) & 0xFF);
  117 + src[1] = (byte) (value & 0xFF);
  118 + return src;
  119 + }
  120 +
  121 + public static int bytes2Int(byte[] src) {
  122 + int ret = ((src[1] & 0xFF) | ((src[0] & 0xFF) << 8));
  123 + return ret;
  124 + }
  125 +
  126 + public static String getKeySn(byte[] data) {
  127 + String sn = "";
  128 + String CS = "0123456789ABCDEF";
  129 + for (int i = 0; i < 6; i++) {
  130 + sn += CS.charAt((data[i] >> 4) & 0xF);
  131 + sn += CS.charAt((data[i] >> 0) & 0xF);
  132 + }
  133 + return sn;
  134 +
  135 + }
  136 +}
  137 +
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/util/Cons.java 0 → 100644
  1 +package com.sunvote.xpadapi.util;
  2 +
  3 +public final class Cons {
  4 +
  5 + public static final int CMD_BASE_STATUS_CHANGE = 0x71;//基础信标变化
  6 + public static final int CMD_VOTE_STATUS_CHANGE = 0x72;//投票信标变化
  7 + public static final int CMD_VOTE_SEND_SUCCESS_RESPONSE = 0x73;//传输入成功通知
  8 +
  9 + public static final int CMD_CHECK_BASE_STATUS_RESPONSE = 0xF0;//查询和设置各类应答
  10 + public static final int CMD_VOTE_RESULT_SEND_RESPONSE = 0xF3;//投票结果上传应答
  11 + public static final int CMD_FIRM_UPDATE_RESPONSE = 0xF8;//固件升级应答
  12 +
  13 + public static final int CMD_UPLOAD_DATA_RESPONSE = 0x20; //上传指令
  14 + public static final int CMD_TRANSPARENT_TRANSMISSION = 0x30; //表决器管理类指令,自定义透传指令
  15 + public static final int CMD_MULTI_PCKAGE_DOWNLOAD = 0x40;//
  16 + public static final int CMD_COM_COMMUNICATION_TEST_RESPONSE = 0xB0; //串口测试应答
  17 +
  18 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/util/Crc16.java 0 → 100644
  1 +package com.sunvote.xpadapi.util;
  2 +
  3 +public final class Crc16 {
  4 + private static int[] crc_ta = { //CRC余式表
  5 + 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
  6 + 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
  7 + };
  8 +
  9 +
  10 + //标准Crc16效验
  11 + public static short crc16(byte[] data, int len) {
  12 + short Crc = 0;
  13 + byte da;
  14 + int i = 4;
  15 + while (len-- != 0) {
  16 + //da=Crc>>12; /* 暂存CRC的高四位 */
  17 + da = (byte) (Crc >>> 12); /* 暂存CRC的高四位 */
  18 + // Crc<<=4; /* CRC左移4位,相当于取CRC的低12位)*/
  19 + Crc <<= 4; /* CRC左移4位,相当于取CRC的低12位)*/
  20 + // Crc^=crc_ta[da^(*ptr/16)]; /* CRC的高4位和本字节的前半字节相加后查表计算CRC, 然后加上上一次CRC的余数 */
  21 + Crc ^= crc_ta[(da ^ (data[i] >>> 4)) & 0xf]; /* CRC的高4位和本字节的前半字节相加后查表计算CRC, 然后加上上一次CRC的余数 */
  22 + //da=Crc>>12; /* 暂存CRC的高4位 */
  23 + da = (byte) (Crc >>> 12); /* 暂存CRC的高4位 */
  24 + // Crc<<=4; /* CRC左移4位, 相当于CRC的低12位) */
  25 + Crc <<= 4; /* CRC左移4位, 相当于CRC的低12位) */
  26 + // Crc^=crc_ta[da^ (*ptr&0x0f)];
  27 + Crc ^= crc_ta[(da ^ data[i]) & 0x0f]; /* CRC的高4位和本字节的后半字节相加后查表计算CRC,
  28 + 然后再加上上一次CRC的余数 */
  29 + i++;
  30 + }
  31 + return (Crc);
  32 + }
  33 +
  34 + public static boolean crc16Check(byte[] data) {
  35 +
  36 + int xda, xdapoly;
  37 + int i, j, xdabit;
  38 + xda = 0xFFFF;
  39 + xdapoly = 0xA001; // (X**16 + X**15 + X**2 + 1)
  40 + for (i = 0; i < data.length - 2; i++) {
  41 + xda ^= data[i];
  42 + for (j = 0; j < 8; j++) {
  43 + xdabit = (int) (xda & 0x01);
  44 + xda >>= 1;
  45 + if (xdabit == 1)
  46 + xda ^= xdapoly;
  47 + }
  48 + }
  49 +
  50 + return data[data.length - 2] == (int) (xda & 0xFF) && data[data.length - 1] == (int) (xda >> 8);
  51 +
  52 + }
  53 +
  54 + public static int getUnsignedByte(byte data) { //将data字节型数据转换为0~255 (0xFF 即BYTE)。
  55 + return data & 0x0FF;
  56 + }
  57 +
  58 + public static int getUnsignedShort(short data) { //将data字节型数据转换为0~255 (0xFF 即BYTE)。
  59 + return data & 0x0FFFF;
  60 + }
  61 +
  62 + private static void printDataBuf(byte[] buf, int length, String flag) {
  63 + String tmpStr = new String();
  64 + for (int i = 0; i < length; i++) {
  65 + tmpStr += String.format("%x ", buf[i]);
  66 + }
  67 + System.out.println(flag + ":" + tmpStr);
  68 + }
  69 +
  70 + public static boolean checkPack(byte[] buf) {
  71 + if (buf.length > 4 && getUnsignedByte(buf[0]) == 0xF5 && getUnsignedByte(buf[1]) == 0xAA && getUnsignedByte(buf[2]) == 0xAA) {
  72 + return true;
  73 + }
  74 + return false;
  75 + }
  76 +}
... ...
C5/xpadapi/src/main/java/com/sunvote/xpadapi/util/LogUtil.java 0 → 100644
  1 +package com.sunvote.xpadapi.util;
  2 +
  3 +import android.os.Environment;
  4 +import android.util.Log;
  5 +
  6 +import java.io.File;
  7 +import java.io.FileWriter;
  8 +import java.io.IOException;
  9 +import java.text.SimpleDateFormat;
  10 +import java.util.Date;
  11 +
  12 +public class LogUtil {
  13 +
  14 + private static FileWriter fileWriter;
  15 +
  16 + public static final int VERBOSE_LEVER = 2;
  17 + public static final int DEBUG_LEVER = 3;
  18 + public static final int INFO_LEVER = 4;
  19 + public static final int WARN_LEVER = 5;
  20 + public static final int ERROR_LEVER = 6;
  21 + public static final int ASSERT_LEVER = 7;
  22 +
  23 + public static int lever = VERBOSE_LEVER - 1 ;
  24 +
  25 + private static boolean logToFile = false;
  26 + private static boolean logToLogcat = true ;
  27 +
  28 + private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH.mm.ss.SSS");
  29 +
  30 + LogUtil() {
  31 + throw new RuntimeException("Stub!");
  32 + }
  33 +
  34 + public static int v(String tag, String msg) {
  35 + if (VERBOSE_LEVER > lever) {
  36 + if(logToLogcat){
  37 + Log.v(tag, msg);
  38 + }
  39 + inputToFile("(V):" + msg );
  40 + }
  41 + return -1;
  42 + }
  43 +
  44 + private static void init(){
  45 + if(fileWriter == null){
  46 + synchronized (LogUtil.class) {
  47 + if(fileWriter == null) {
  48 + try {
  49 + File path = new File(Environment.getExternalStorageDirectory().getPath() + "/sunvote/log");
  50 + if (!path.exists()) {
  51 + path.mkdirs();
  52 + }
  53 + File file = new File(Environment.getExternalStorageDirectory().getPath()
  54 + + "/sunvote/log/" + simpleDateFormat.format(new Date())+".txt");
  55 + if (!file.exists()) {
  56 + file.createNewFile();
  57 + }
  58 + fileWriter = new FileWriter(file, true);
  59 +
  60 + } catch (Exception ex) {
  61 + ex.printStackTrace();
  62 + fileWriter = null;
  63 + }
  64 + }
  65 + }
  66 + }
  67 + }
  68 +
  69 + public static void enableLogToFile(){
  70 + logToFile = true;
  71 + }
  72 +
  73 + public static void disabelLogToFile(){
  74 + logToFile = false;
  75 + }
  76 +
  77 + public static void enableLogToLogcat(){
  78 + logToLogcat = true;
  79 + }
  80 +
  81 + public static void disableLogToLogcat(){
  82 + logToLogcat = false;
  83 + }
  84 +
  85 + public static void enableLog(){
  86 + lever = VERBOSE_LEVER - 1;
  87 + }
  88 +
  89 + public static void disableLog(){
  90 + lever = ASSERT_LEVER ;
  91 + }
  92 +
  93 + public static int v(String tag, String msg, Throwable tr) {
  94 + if(VERBOSE_LEVER > lever){
  95 + if(logToLogcat) {
  96 + Log.v(tag, msg, tr);
  97 + }
  98 + inputToFile("(V):" + msg + Log.getStackTraceString(tr));
  99 + }
  100 + return -1;
  101 + }
  102 +
  103 + public static int d(String tag, String msg) {
  104 + if(DEBUG_LEVER > lever){
  105 + if(logToLogcat) {
  106 + Log.d(tag, msg);
  107 + }
  108 + inputToFile("(D):" + msg );
  109 + }
  110 + return -1;
  111 + }
  112 +
  113 + public static int d(String tag, String msg, Throwable tr) {
  114 + if(DEBUG_LEVER > lever){
  115 + if(logToLogcat){
  116 + Log.d(tag,msg,tr);
  117 + }
  118 + inputToFile("(D):" + msg + Log.getStackTraceString(tr));
  119 + }
  120 + return -1;
  121 + }
  122 +
  123 + public static int i(String tag, String msg) {
  124 + if(INFO_LEVER > lever){
  125 + if(logToLogcat){
  126 + Log.i(tag,msg);
  127 + }
  128 + inputToFile("(I):" + msg );
  129 + }
  130 + return -1;
  131 + }
  132 +
  133 + public static int i(String tag, String msg, Throwable tr) {
  134 + if(INFO_LEVER > lever){
  135 + if(logToLogcat){
  136 + Log.i(tag,msg,tr);
  137 + }
  138 + inputToFile("(I):" + msg + Log.getStackTraceString(tr));
  139 + }
  140 + return -1;
  141 + }
  142 +
  143 + public static int i(String tag,byte[] msg){
  144 + String msgStr = ByteUtils.bytesToHexString(msg);
  145 + return i(tag,msgStr);
  146 + }
  147 +
  148 + public static int i(String tag,String msgTag, byte[] msg){
  149 + String msgStr = ByteUtils.bytesToHexString(msg);
  150 + return i(tag,msgTag + ":\r\n" + msgStr);
  151 + }
  152 +
  153 + public static int v(String tag,String msgTag, byte[] msg){
  154 + String msgStr = ByteUtils.bytesToHexString(msg);
  155 + return v(tag,msgTag + ":\r\n" + msgStr);
  156 + }
  157 +
  158 + public static int i(String tag,String msgTag, byte[] msg,int length){
  159 + String msgStr = ByteUtils.bytesToHexString(msg,length);
  160 + return i(tag,msgTag + ":\r\n" + msgStr);
  161 + }
  162 +
  163 + public static int v(String tag,String msgTag, byte[] msg,int length){
  164 + String msgStr = ByteUtils.bytesToHexString(msg,length);
  165 + return v(tag,msgTag + ":\r\n" + msgStr);
  166 + }
  167 +
  168 + public static int i(String tag,byte[] msg,Throwable tr){
  169 + String msgStr = ByteUtils.bytesToHexString(msg);
  170 + return i(tag,msgStr,tr);
  171 + }
  172 +
  173 + public static int i(String tag,String msgTag,byte[] msg,Throwable tr){
  174 + String msgStr = ByteUtils.bytesToHexString(msg);
  175 + return i(tag,msgTag + ":\r\n" + msgStr,tr);
  176 + }
  177 +
  178 + public static int w(String tag, String msg) {
  179 + if(WARN_LEVER > lever){
  180 + if(logToLogcat){
  181 + Log.w(tag,msg);
  182 + }
  183 + inputToFile("(V):" + msg);
  184 + }
  185 + return -1;
  186 + }
  187 +
  188 + public static int w(String tag, String msg, Throwable tr) {
  189 + if(WARN_LEVER > lever){
  190 + if(logToLogcat){
  191 + Log.w(tag,msg,tr);
  192 + }
  193 + inputToFile("(W):" + msg + Log.getStackTraceString(tr));
  194 + }
  195 + return -1;
  196 + }
  197 +
  198 + public static boolean isLoggable(String s, int i){
  199 + return Log.isLoggable(s,i);
  200 + }
  201 +
  202 + public static int w(String tag, Throwable tr) {
  203 + if(WARN_LEVER > lever){
  204 + if(logToLogcat){
  205 + Log.w(tag,tr);
  206 + }
  207 + inputToFile("(W):" + Log.getStackTraceString(tr));
  208 + }
  209 + return -1;
  210 + }
  211 +
  212 + public static int e(String tag, String msg) {
  213 + if(ERROR_LEVER > lever){
  214 + if(logToLogcat){
  215 + Log.e(tag,msg);
  216 + }
  217 + inputToFile("(E):" + msg);
  218 + }
  219 + return -1;
  220 + }
  221 +
  222 + public static int e(String tag,Throwable tr){
  223 + String message = "ERROR" ;
  224 + if(tr != null && tr.getMessage() != null){
  225 + message = tr.getMessage();
  226 + }
  227 + return e(tag,message,tr);
  228 + }
  229 +
  230 + public static int e(String tag, String msg, Throwable tr) {
  231 + if(ERROR_LEVER > lever){
  232 + if(logToLogcat){
  233 + Log.e(tag,msg,tr);
  234 + }
  235 + inputToFile("(E):" + msg + Log.getStackTraceString(tr));
  236 + }
  237 + return -1;
  238 + }
  239 +
  240 + public static int wtf(String tag, String msg) {
  241 + if(ASSERT_LEVER > lever){
  242 + if(logToLogcat){
  243 + Log.wtf(tag,msg);
  244 + }
  245 + inputToFile("(WTF):" + msg);
  246 + }
  247 + return -1;
  248 + }
  249 +
  250 + public static int wtf(String tag, Throwable tr) {
  251 + if(ASSERT_LEVER > lever){
  252 + if(logToLogcat){
  253 + Log.wtf(tag,tr);
  254 + }
  255 + inputToFile("(WTF):" + Log.getStackTraceString(tr));
  256 + }
  257 + return -1;
  258 + }
  259 +
  260 + public static int wtf(String tag, String msg, Throwable tr) {
  261 + if(ASSERT_LEVER > lever){
  262 + if(logToLogcat){
  263 + Log.wtf(tag,msg,tr);
  264 + }
  265 + inputToFile("(WTF):" + msg + Log.getStackTraceString(tr));
  266 + }
  267 + return -1;
  268 + }
  269 +
  270 + public static String getStackTraceString(Throwable tr) {
  271 + return Log.getStackTraceString(tr);
  272 + }
  273 +
  274 +
  275 + public static void stack(){
  276 + Throwable throwable = new Throwable();
  277 + // 需要处理TAG 要读出上面class method的信息,后续添上
  278 + i("STACK",getStackTraceString(throwable));
  279 + }
  280 +
  281 + private synchronized static void inputToFile(String msg){
  282 + if(logToFile) {
  283 + String time = simpleDateFormat.format(new Date());
  284 + try {
  285 + init();
  286 + String log = time + "(" + Thread.currentThread().getName() + ",id=" + Thread.currentThread().getId() + ")" + msg + "\r\n";
  287 + if(onLogMessage != null){
  288 + onLogMessage.onLog(time + ":" + msg + "\r\n");
  289 + }
  290 + fileWriter.write(log);
  291 + fileWriter.flush();
  292 + } catch (Exception ex) {
  293 + ex.printStackTrace();
  294 + if(fileWriter != null){
  295 + try {
  296 + fileWriter.close();
  297 + } catch (IOException e) {
  298 + e.printStackTrace();
  299 + }
  300 + }
  301 + fileWriter = null;
  302 + }
  303 + }
  304 + }
  305 +
  306 + private static OnLogMessage onLogMessage;
  307 +
  308 + public static void setOnLogMessage(OnLogMessage onLogMessage) {
  309 + LogUtil.onLogMessage = onLogMessage;
  310 + }
  311 +
  312 + public static interface OnLogMessage{
  313 + void onLog(String log);
  314 + }
  315 +}
  316 +
... ...
C5/xpadapi/src/main/res/values/strings.xml 0 → 100644
  1 +<resources>
  2 + <string name="app_name">XpadApi</string>
  3 +</resources>
... ...
C5/xpadapi/src/test/java/com/sunvote/xpadapi/ExampleUnitTest.java 0 → 100644
  1 +package com.sunvote.xpadapi;
  2 +
  3 +import org.junit.Test;
  4 +
  5 +import static org.junit.Assert.*;
  6 +
  7 +/**
  8 + * Example local unit test, which will execute on the development machine (host).
  9 + *
  10 + * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
  11 + */
  12 +public class ExampleUnitTest {
  13 + @Test
  14 + public void addition_isCorrect() {
  15 + assertEquals(4, 2 + 2);
  16 + }
  17 +}
0 18 \ No newline at end of file
... ...
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/BaseCmd.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/ICmd.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/app/BaseBeaconStateRequest.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/app/ModuleHeartBeatCmd.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/app/MutiPkgDownCmd.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/app/OtherCmd.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/ConfirmBaseBeaconRequest.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/ConfirmBaseBeaconResponse.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/GetVoteDataRequest.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/GetVoteDataResponse.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/SettingBaseBeaconRequest.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/SettingBaseBeaconResponse.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/SettingVoteRequest.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/SettingVoteResponse.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/manager/BaseStationUpgradeCmd.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/manager/FlatBaseStationSettingCmd.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/manager/ReadOrWriteBaseStationConfigCmd.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/manager/ReadOrWriteHardWareConfigCmd.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/basestation/manager/ReadOrWriteMatchCodeCmd.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/BaseStatusChangeRequest.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/BaseStatusChangeResponse.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/CustomCommandControl.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/DownloadSingletonPkg.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/DownloadSingletonPkgResponse.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/PushBaseCmd.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/ReadAndWriteHardwareInformation.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/ReadAndWriteVoterAllocation.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/VoteStatusChangeRequest.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/push/VoteStatusChangeResponse.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/GetPkgStateRequest.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/GetPkgStateResponse.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/KeyboardParameterStateRequest.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/KeyboardParameterStateResponse.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/ModeOperationStateRequest.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/ModeOperationStateResponse.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/QueryBeaconStateRequest.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/QueryBeaconStateResponse.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/QueryOnlineStateRequest.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/QueryOnlineStateResponse.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/StateBaseCmd.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/WorkPattenStateRequest.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/state/WorkPattenStateResponse.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/CleanFlashStateRequest.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/CleanFlashStateResponse.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/UpgradEntryStateRequest.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/UpgradEntryStateResponse.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/UpgradeBaseCmd.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/UpgradeExitStateRequest.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/UpgradeExitStateResponse.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/WriteFlashStateRequest.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upgrade/WriteFlashStateResponse.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upload/NumberingModeResult.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upload/SequenceFormatResult.class deleted
No preview for this file type
C5/xpadprotocal/build/classes/java/main/com/sunvote/cmd/upload/SingerUploadPkg.class deleted
No preview for this file type