Commit e1e561633f99b94d20defcdb6c3c4eb321c1e017

Authored by 孙向锦
1 parent 9e36c270

移除一个分支

Showing 48 changed files with 1 additions and 4098 deletions
C5/settings.gradle
1   -include ':app', ':udpmodule', ':xpadprotocal', ':util', ':sunvoteadapter', 'txpad', 'sunvotesdk','testproject',':xpadapi'
  1 +include ':app', ':udpmodule', ':xpadprotocal', ':util', ':sunvoteadapter', 'txpad', 'sunvotesdk','testproject'
2 2  
3 3 \ No newline at end of file
... ...
C5/xpadapi/.gitignore deleted
1   -/build
C5/xpadapi/build.gradle deleted
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 deleted
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 deleted
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 deleted
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>
13 0 \ No newline at end of file
C5/xpadapi/src/main/aidl/com/sunvote/xpadapi/ISunvoteApi.aidl deleted
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/XpadApiService.java deleted
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.os.Handler;
9   -import android.os.HandlerThread;
10   -import android.os.IBinder;
11   -
12   -import com.sunvote.udptransfer.stream.SunVoteInputStream;
13   -import com.sunvote.udptransfer.work.BaseStationProcessWork;
14   -import com.sunvote.udptransfer.work.RepeatMessageManager;
15   -import com.sunvote.udptransfer.work.SDKProcessWork;
16   -import com.sunvote.util.LogUtil;
17   -import com.sunvote.xpadapi.ISunvoteApi;
18   -import com.sunvote.xpadapi.service.bean.BaseInfo;
19   -import com.sunvote.xpadapi.service.bean.BaseVoteInfo;
20   -import com.sunvote.xpadapi.service.bean.HeartBeat;
21   -import com.sunvote.xpadapi.service.bean.KeypadInfo;
22   -import com.sunvote.xpadapi.service.bean.ModelInfo;
23   -import com.sunvote.xpadapi.service.bean.OnLineInfo;
24   -import com.sunvote.xpadapi.service.bean.Packet;
25   -import com.sunvote.xpadapi.service.listener.OnDataReceiver;
26   -import com.sunvote.xpadapi.service.logic.XpadApiServiceInfoProxyManager;
27   -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   -
32   -import java.io.ByteArrayOutputStream;
33   -import java.util.ArrayList;
34   -import java.util.Arrays;
35   -import java.util.Collections;
36   -import java.util.List;
37   -
38   -/**
39   - * @Author Elvis
40   - */
41   -public class XpadApiService extends Service {
42   -
43   - private static final String TAG = XpadApiService.class.getSimpleName();
44   - private List<OnDataReceiver> onDataReceiverList = new ArrayList<>();
45   - private int batteryLevel = 0;
46   - private List<Packet> innerList = Collections.synchronizedList(new ArrayList<Packet>());
47   - private OnDataReceiver onDataReceiver = new OnDataReceiver() {
48   - @Override
49   - public void onDataReceiver(byte[] datas) {
50   - LogUtil.i(TAG, "onDataReceiver", datas);
51   - for (OnDataReceiver temp : onDataReceiverList) {
52   - if (temp != null) {
53   - try {
54   - temp.onDataReceiver(datas);
55   - } catch (Exception ex) {
56   - LogUtil.e(TAG, "onDataReceiver" + temp.getClass().getSimpleName(), ex);
57   - }
58   - }
59   - }
60   - }
61   -
62   - @Override
63   - public void onDataSender(byte[] datas) {
64   - LogUtil.i(TAG, "onDataSender", datas);
65   - for (OnDataReceiver temp : onDataReceiverList) {
66   - if (temp != null) {
67   - try {
68   - temp.onDataSender(datas);
69   - } catch (Exception ex) {
70   - LogUtil.e(TAG, "onDataSender", ex);
71   - }
72   - }
73   - }
74   - }
75   - };
76   -
77   - public XpadApiService() {
78   - }
79   -
80   - public int registerOnDataReceiver(OnDataReceiver onDataReceiver) {
81   - for (OnDataReceiver temp : onDataReceiverList) {
82   - if (temp == onDataReceiver) {
83   - return 0;
84   - }
85   - }
86   - onDataReceiverList.add(onDataReceiver);
87   - return 1;
88   - }
89   -
90   - @Override
91   - public void onCreate() {
92   - super.onCreate();
93   -
94   - sendThread = new HandlerThread("send");
95   - receiverThread = new HandlerThread("receiver");
96   - sendThread.start();
97   - receiverThread.start();
98   -
99   - taskHandler = new Handler(sendThread.getLooper());
100   - IntentFilter batteryLevelFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
101   - registerReceiver(batteryLevelRcvr, batteryLevelFilter);
102   - XpadApiServiceInfoProxyManager.getInstance().setService(this);
103   -
104   - receiverDatas();
105   - }
106   -
107   - private void receiverDatas() {
108   - SunVoteInputStream sunVoteInputStream = new SunVoteInputStream();
109   - sunVoteInputStream.setOnBytesReceiver(new SunVoteInputStream.OnBytesReceiver() {
110   - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
111   - @Override
112   - public void onBytesReceiver(byte[] bytes, int len) {
113   - // 1. 先检测读取数据到缓冲区
114   - byteArrayOutputStream.write(bytes, 0, bytes.length);
115   - if (byteArrayOutputStream.size() >= 3) {
116   - byte[] temp = byteArrayOutputStream.toByteArray();
117   - int find = ByteUtils.findBytes(temp, new byte[]{(byte) 0xF5, (byte) 0xAA, (byte) 0xAA}, 0);
118   - if (find >= 0) {
119   - // 3. 标志存在,则继续读取长度
120   - if (byteArrayOutputStream.size() >= find + 4) {
121   - int length = ByteUtils.byte1ToInt(byteArrayOutputStream.toByteArray()[find + 3]);
122   - if (byteArrayOutputStream.size() >= find + 4 + length) {
123   - ByteArrayOutputStream tmp = new ByteArrayOutputStream();
124   - // 4. 根据长度读取包的内容
125   - for (int i = find; i < find + 4 + length; i++) {
126   - // 5. 截取包的内容,向外抛出,处理,接着读取下一个包
127   - tmp.write(temp[i]);
128   - }
129   - //CRC 校验
130   - byte[] datas = tmp.toByteArray();
131   - LogUtil.i(TAG, "RECEIVER DATA:", datas);
132   -
133   - try {
134   - //处理
135   - doWith(datas);
136   - } catch (Exception ex) {
137   - LogUtil.i(TAG, "处理命令出错:", ex);
138   - }
139   - // 7. 剩余数据重新打包处理
140   - byteArrayOutputStream.reset();
141   - for (int i = find + 4 + length; i < temp.length; i++) {
142   - byteArrayOutputStream.write(temp[i]);
143   - }
144   - }
145   - }
146   - }
147   - }
148   - }
149   - });
150   - SDKProcessWork.getInstance().setInputStream(sunVoteInputStream);
151   - BaseStationProcessWork.getInstance().start();
152   - RepeatMessageManager.getInstance().start();
153   - SDKProcessWork.getInstance().start();
154   - }
155   -
156   - @Override
157   - public void onDestroy() {
158   - unregisterReceiver(batteryLevelRcvr);
159   - super.onDestroy();
160   - }
161   -
162   - private HandlerThread sendThread = null;
163   - private HandlerThread receiverThread = null;
164   - private Handler taskHandler = null;
165   - private boolean receivering = true;
166   -
167   -
168   - @Override
169   - public IBinder onBind(Intent intent) {
170   - return stub;
171   - }
172   -
173   - private final ISunvoteApi.Stub stub = new ISunvoteApi.Stub() {
174   -
175   - };
176   -
177   - private Runnable sendTask = new Runnable() {
178   - @Override
179   - public void run() {
180   - // 从队列中取出待发送数据
181   - List<Packet> sendList = XpadApiServiceInfoProxyManager.getInstance().getSendList();
182   - boolean isSend = false;
183   - for (Packet p : sendList) {
184   - if (p.needSend() && !isSend) {// 按照顺序发送
185   - p.addSendCount();
186   - sendPacket(p);
187   - isSend = true;
188   - }
189   - if (p.needSend() && isSend && p.isSync()) {// 并行发送
190   - sleepTimes(50);// 模块不能发送太快
191   - p.addSendCount();
192   - sendPacket(p);
193   - }
194   - if (!p.needSend() && (p.getOnSendPacket() != null)) {
195   - p.getOnSendPacket().onFail(p);
196   - }
197   - }
198   - if (!isSend) {
199   - LogUtil.i(TAG, "没有要提交的数据,检查是否有查询包发送");
200   - if (innerList.size() > 0) {
201   - synchronized (innerList) {
202   - for (Packet packet : innerList) {
203   - sendPacket(packet);
204   - sleepTimes(50);
205   - }
206   - }
207   - }
208   - }
209   -
210   - if (!isSend) {// 没有数据发送? 那就发送心跳吧
211   - LogUtil.i(TAG, "没有任何数据要发送,则发送心跳包");
212   - sendData(new HeartBeat((byte) batteryLevel, (byte) 0).toBytes());
213   - }
214   - // 轮询下一次发送数据
215   - taskHandler.removeCallbacks(this);
216   - taskHandler.postDelayed(this, 1000);
217   - }
218   - };
219   -
220   - private void doWith(byte[] datas) {
221   - onDataReceiver.onDataReceiver(datas);
222   - switch (datas[4] & 0xFF) {
223   - case Cons.CMD_CHECK_BASE_STATUS_RESPONSE:
224   - checkBaseStatusResponse(datas);
225   - break;
226   - case Cons.CMD_VOTE_RESULT_SEND_RESPONSE:
227   - voteResultSendResponse(datas);
228   - break;
229   - case Cons.CMD_FIRM_UPDATE_RESPONSE:
230   - firmUpdateResponse(datas);
231   - break;
232   -
233   - case Cons.CMD_BASE_STATUS_CHANGE:
234   - baseStatusChange(datas);
235   - break;
236   - case Cons.CMD_VOTE_STATUS_CHANGE:
237   - voteStatusChange(datas);
238   - break;
239   - case Cons.CMD_VOTE_SEND_SUCCESS_RESPONSE:
240   - voteSendSuccessResponse(datas);
241   - break;
242   -
243   - case Cons.CMD_UPLOAD_DATA_RESPONSE:
244   - uploadDataResponse(datas);
245   - break;
246   - case Cons.CMD_TRANSPARENT_TRANSMISSION:
247   - transparentTransmission(datas);
248   - break;
249   - case Cons.CMD_MULTI_PCKAGE_DOWNLOAD:
250   - break;
251   - case Cons.CMD_COM_COMMUNICATION_TEST_RESPONSE:
252   - break;
253   -
254   - }
255   - }
256   -
257   - private void transparentTransmission(byte[] datas) {
258   - }
259   -
260   - private void uploadDataResponse(byte[] datas) {
261   - }
262   -
263   - private void voteSendSuccessResponse(byte[] datas) {
264   - responseChange(datas, 4, (byte) 0xF3);
265   - int serialNo = datas[5] & 0xff;
266   - Packet packet = XpadApiServiceInfoProxyManager.getInstance().findPacket(serialNo);
267   - if (packet != null && packet.getOnSendPacket() != null) {
268   - packet.getOnSendPacket().onSuccess(packet);
269   - }
270   - }
271   -
272   - private void sendInnerPacket(Packet packet) {
273   - synchronized (innerList) {
274   - for (Packet temp : innerList) {
275   - if (temp.getSendNo() == packet.getSendNo()) {
276   - return;
277   - }
278   - }
279   - innerList.add(packet);
280   - }
281   - immediately();
282   - }
283   -
284   - public void immediately(){
285   - taskHandler.removeCallbacks(sendTask);
286   - taskHandler.post(sendTask);
287   - }
288   -
289   - private void voteStatusChange(byte[] datas) {
290   - responseChange(datas, 4, (byte) 0xF2);
291   - saveVoteInfo(datas);
292   - }
293   -
294   - private void baseStatusChange(byte[] datas) {
295   - responseChange(datas, 4, (byte) 0xF1);
296   - saveBaseInfo(datas);
297   - }
298   -
299   - private void firmUpdateResponse(byte[] datas) {
300   -
301   - }
302   -
303   - private void voteResultSendResponse(byte[] datas) {
304   - // 下层模块收到了,说明不了什么,所以不干什么
305   - }
306   -
307   - private void checkBaseStatusResponse(byte[] datas) {
308   - switch (datas[5] & 0xFF) {
309   - case 1://当前工作模式和版本
310   - case 2://当前工作模式和版本
311   - saveModelInfo(datas);
312   - break;
313   - case 3:
314   - saveBaseInfo(datas);
315   - break;
316   - case 4:
317   - saveVoteInfo(datas);
318   - break;
319   - case 5:
320   - case 6:
321   - saveKeypadInfo(datas);
322   - break;
323   - case 7:
324   - saveOnLineInfo(datas);
325   - break;
326   - case 8:
327   - case 9:
328   - saveKeypadInfo(datas);
329   - break;
330   - }
331   - }
332   -
333   - private void saveOnLineInfo(byte[] datas) {
334   - OnLineInfo info = new OnLineInfo();
335   - info.setOnLine(datas[6] & 0xff);
336   - info.setIdMode(datas[7] & 0xff);
337   - info.setChan(datas[8] & 0xff);
338   - info.setRssi(datas[9] & 0xff);
339   - info.setTx(datas[10] & 0xff);
340   - info.setRx(datas[11] & 0xff);
341   - info.setBaseId(datas[12] & 0xff);
342   - info.setKeyId(((datas[13] & 0xff) << 8) | (datas[14] & 0xff));
343   - byte[] sn = Arrays.copyOfRange(datas, 15, 21);
344   - info.setKeySn(ByteUtils.getKeySn(sn));
345   - XpadApiServiceInfoProxyManager.getInstance().setOnLineInfo(info);
346   - }
347   -
348   - private void saveKeypadInfo(byte[] datas) {
349   - KeypadInfo info = new KeypadInfo();
350   - info.setOk(datas[6] & 0xff);
351   - info.setChan(datas[7] & 0xff);
352   - info.setKeyId(((datas[8] & 0xff) << 8) | (datas[9] & 0xff));
353   - byte[] sn = Arrays.copyOfRange(datas, 10, 16);
354   - info.setKeySn(ByteUtils.getKeySn(sn));
355   - byte[] mc = Arrays.copyOfRange(datas, 16, 19);
356   - info.setMatchCode(new String(mc));
357   - XpadApiServiceInfoProxyManager.getInstance().setKeypadInfo(info);
358   - }
359   -
360   - private void saveVoteInfo(byte[] datas) {
361   - BaseVoteInfo info = new BaseVoteInfo();
362   - info.setBaseId(datas[1] & 0xff);
363   - info.setNowT(datas[2] & 0xff << 8 | datas[3] & 0xff);
364   - info.setDataPos(datas[4] & 0xff);
365   - info.setMode(datas[5] & 0xff);
366   - info.setModes(datas);
367   - XpadApiServiceInfoProxyManager.getInstance().setBaseVoteInfo(info);
368   - }
369   -
370   - /**
371   - * 保存基础信标信息
372   - *
373   - * @param data
374   - */
375   - private void saveBaseInfo(byte[] data) {
376   - BaseInfo info = new BaseInfo();
377   - info.setBaseId(data[5] & 0xff);// baseID
378   - info.setIdMode(data[6] & 0xff);
379   - info.setConfId(((data[7] & 0xff) << 8) | (data[8] & 0xff));
380   - info.setBillId(data[9] & 0xff);
381   - info.setAuthCode((data[10] & 0xff) << 8 | (data[11] & 0xff));
382   - info.setLogin(data[12] & 0xff);
383   - info.setReport(data[13] & 0xff);
384   - info.setOffTime(data[14] & 0xff);
385   - info.setAttrib(data[15] & 0xff);
386   - info.setPageNo((data[16] & 0xff) << 8 | (data[17] & 0xff));
387   - byte[] bname = Arrays.copyOfRange(data, 16, 16 + 12);
388   - info.setBaseName(new String(bname));
389   - XpadApiServiceInfoProxyManager.getInstance().setBaseInfo(info);
390   - }
391   -
392   - private void saveModelInfo(byte[] datas) {
393   - ModelInfo info = new ModelInfo();
394   - info.setMode(datas[6] & 0xff);
395   - info.sethModel(datas[7] & 0xff);
396   - info.setsVer((datas[8] & 0xff) + "." + (datas[9] & 0xff) + "." + (datas[10] & 0xff));
397   - XpadApiServiceInfoProxyManager.getInstance().setModelInfo(info);
398   - }
399   -
400   -
401   - private void responseChange(byte[] data, int pos, byte res) {
402   - byte[] retData = Arrays.copyOf(data, data.length);
403   - retData[pos] = res;
404   - sendData(data);
405   - }
406   -
407   - private void roundCRC(byte[] data) {
408   - int crcValue = Crc16.getUnsignedShort(Crc16.crc16(data, data.length - 4 - 2));
409   - data[data.length - 2] = (byte) (crcValue >> 8);
410   - data[data.length - 1] = (byte) (crcValue);
411   - }
412   -
413   - public void sendPacket(Packet packet) {
414   - sendData(packet.getDatas());
415   - }
416   -
417   - public void sendData(byte[] datas) {
418   - roundCRC(datas);
419   - onDataReceiver.onDataSender(datas);
420   - try {
421   - SDKProcessWork.getInstance().execute(datas,datas.length);
422   - } catch (Exception e) {
423   - LogUtil.e(TAG, e);
424   - }
425   - }
426   -
427   - private void sleepTimes(long times) {
428   - try {
429   - Thread.sleep(times);
430   - } catch (Exception e) {
431   - e.printStackTrace();
432   - }
433   - }
434   -
435   - BroadcastReceiver batteryLevelRcvr = new BroadcastReceiver() {
436   -
437   - public void onReceive(Context context, Intent intent) {
438   - if (Intent.ACTION_BATTERY_CHANGED.equals(intent.getAction())) {
439   - int rawlevel = intent.getIntExtra("level", -1);
440   - int scale = intent.getIntExtra("scale", -1);
441   - int status = intent.getIntExtra("status", -1);
442   - int health = intent.getIntExtra("health", -1);
443   - int voltage = intent.getIntExtra("voltage", 0);
444   - int level = -1; // percentage, or -1 for unknown
445   - if (rawlevel >= 0 && scale > 0) {
446   - level = (rawlevel * 100) / scale;
447   - }
448   -
449   - float val = (float) voltage / 1000;
450   - batteryLevel = (int) (val / 0.04);
451   -
452   - }
453   - }
454   - };
455   -
456   - public void getKeypadParam() {
457   - byte[] mBuffer = new byte[0x1F + 4];
458   - Arrays.fill(mBuffer, (byte) 0x0);
459   - mBuffer[0] = (byte) 0xF5;
460   - mBuffer[1] = (byte) 0xAA;
461   - mBuffer[2] = (byte) 0xAA;
462   - mBuffer[3] = (byte) 0x1F;
463   -
464   - mBuffer[4] = 0x70;
465   - mBuffer[5] = 0x05;
466   - Packet packet = new Packet();
467   - packet.setDatas(mBuffer);
468   - packet.setSendNo(Packet.GetKeypadParam);
469   - sendInnerPacket(packet);
470   - }
471   -
472   - public void getWorkMode() {
473   - byte[] mBuffer = new byte[0x1F + 4];
474   - Arrays.fill(mBuffer, (byte) 0x0);
475   - mBuffer[0] = (byte) 0xF5;
476   - mBuffer[1] = (byte) 0xAA;
477   - mBuffer[2] = (byte) 0xAA;
478   - mBuffer[3] = (byte) 0x1F;
479   - mBuffer[4] = 0x70;
480   - mBuffer[5] = 0x01;
481   - Packet packet = new Packet();
482   - packet.setDatas(mBuffer);
483   - packet.setSendNo(Packet.GetWorkModeNum);
484   - sendInnerPacket(packet);
485   - }
486   -
487   - public void setWorkMode(int iMode) {
488   - byte[] mBuffer = new byte[0x1F + 4];
489   - Arrays.fill(mBuffer, (byte) 0x0);
490   - mBuffer[0] = (byte) 0xF5;
491   - mBuffer[1] = (byte) 0xAA;
492   - mBuffer[2] = (byte) 0xAA;
493   - mBuffer[3] = (byte) 0x1F;
494   - mBuffer[4] = 0x70;
495   - mBuffer[5] = 0x02;
496   - mBuffer[6] = (byte) iMode;
497   - Packet packet = new Packet();
498   - packet.setDatas(mBuffer);
499   - packet.setSendNo(Packet.SetWorkModeNum);
500   - sendInnerPacket(packet);
501   - }
502   -
503   - public void getBaseStatus() {
504   - byte[] mBuffer = new byte[0x1F + 4];
505   - Arrays.fill(mBuffer, (byte) 0x0);
506   - mBuffer[0] = (byte) 0xF5;
507   - mBuffer[1] = (byte) 0xAA;
508   - mBuffer[2] = (byte) 0xAA;
509   - mBuffer[3] = (byte) 0x1F;
510   - mBuffer[4] = 0x70;
511   - mBuffer[5] = 0x03;
512   - Packet packet = new Packet();
513   - packet.setDatas(mBuffer);
514   - packet.setSendNo(Packet.BaseStatusNum);
515   - sendInnerPacket(packet);
516   - }
517   -
518   - public void getVoteStatus() {
519   - byte[] mBuffer = new byte[0x1F + 4];
520   - Arrays.fill(mBuffer, (byte) 0x0);
521   - mBuffer[0] = (byte) 0xF5;
522   - mBuffer[1] = (byte) 0xAA;
523   - mBuffer[2] = (byte) 0xAA;
524   - mBuffer[3] = (byte) 0x1F;
525   - mBuffer[4] = 0x70;
526   - mBuffer[5] = 0x04;
527   - Packet packet = new Packet();
528   - packet.setDatas(mBuffer);
529   - packet.setSendNo(Packet.VoteStatusNum);
530   - sendInnerPacket(packet);
531   - }
532   -
533   - public void execKeypadMatch(int iMode, int channal) {
534   - byte[] mBuffer = new byte[0x1F + 4];
535   - Arrays.fill(mBuffer, (byte) 0x0);
536   - mBuffer[0] = (byte) 0xF5;
537   - mBuffer[1] = (byte) 0xAA;
538   - mBuffer[2] = (byte) 0xAA;
539   - mBuffer[3] = (byte) 0x1F;
540   - mBuffer[4] = 0x70;
541   - mBuffer[5] = 0x08;
542   - mBuffer[6] = (byte) iMode;
543   - mBuffer[7] = (byte) channal;
544   - Packet packet = new Packet();
545   - packet.setDatas(mBuffer);
546   - packet.setSendNo(Packet.ExecKeypadMatchNum);
547   - sendInnerPacket(packet);
548   - }
549   -
550   - public void comCommunicationTest(int sendn, int okn) {
551   - byte[] mBuffer = new byte[0x1F + 4];
552   - Arrays.fill(mBuffer, (byte) 0x0);
553   - mBuffer[0] = (byte) 0xF5;
554   - mBuffer[1] = (byte) 0xAA;
555   - mBuffer[2] = (byte) 0xAA;
556   - mBuffer[3] = (byte) 0x1F;
557   - mBuffer[4] = 0x30;
558   - mBuffer[5] = 0x0;
559   - mBuffer[6] = 0x0;
560   - mBuffer[7] = 7;
561   - mBuffer[8] = (byte) sendn;
562   - mBuffer[9] = (byte) okn;
563   - mBuffer[10] = (byte) 0xAA;
564   -
565   - for (int i = 1; i < 17; i++) {
566   - mBuffer[10 + i] = (byte) i;
567   - }
568   -
569   - Packet packet = new Packet();
570   - packet.setDatas(mBuffer);
571   - packet.setSendNo(Packet.CommunicationTestMatchNum);
572   - sendInnerPacket(packet);
573   - }
574   -
575   - public void applyFileUpload(int length, String filename, byte anstype,byte index) {
576   - byte[] mBuffer = new byte[0x1F + 4];
577   - Arrays.fill(mBuffer, (byte) 0x0);
578   - mBuffer[0] = (byte) 0xF5;
579   - mBuffer[1] = (byte) 0xAA;
580   - mBuffer[2] = (byte) 0xAA;
581   - mBuffer[3] = (byte) 0x1F;
582   - mBuffer[4] = 0x73;
583   - mBuffer[5] = (byte) 0XFF;// 流水号
584   - mBuffer[6] = (byte) 0X01;// 流水号
585   - mBuffer[7] = (byte) 15;// MSGTYPE
586   - mBuffer[8] = (byte) anstype;// ANSTYPE 添加5 文件上传指令
587   - mBuffer[9] = index;// 高位
588   - Packet packet = new Packet();
589   - packet.setDatas(mBuffer);
590   - packet.setSendNo(Packet.CommunicationTestMatchNum);
591   - sendInnerPacket(packet);
592   - }
593   -
594   - public void packetReceptionConfirmed(byte[] keyid, byte packid, byte packH, byte packtype) {
595   - byte[] mBuffer = new byte[0x1F + 4];
596   - Arrays.fill(mBuffer, (byte) 0x0);
597   - mBuffer[0] = (byte) 0xF5;
598   - mBuffer[1] = (byte) 0xAA;
599   - mBuffer[2] = (byte) 0xAA;
600   - mBuffer[3] = (byte) 0x1F;
601   -
602   - mBuffer[4] = (byte) 0xA0;
603   - int keyId = XpadApiServiceInfoProxyManager.getInstance().getKeypadInfo().getKeyId();
604   - mBuffer[5] = (byte)((keyId >> 8) & 0xFF);
605   - mBuffer[6] = (byte)((keyId) & 0xFF);
606   -
607   - mBuffer[7] = 3;//CMD 3 多包接收完毕应答
608   - mBuffer[8] = packtype;//PACKTYPE 多包类型
609   - mBuffer[9] = packid;//数据包标识码
610   - Packet packet = new Packet();
611   - packet.setDatas(mBuffer);
612   - packet.setSendNo(Packet.CommunicationTestMatchNum);
613   - sendInnerPacket(packet);
614   - }
615   -
616   - public void uploadFileData(byte[] keyid, byte packid, byte packH, byte packL, byte[] datas, byte packtype) {
617   - uploadFileData(keyid, packid, packH, packL, datas, 0, datas.length, packtype);
618   - }
619   -
620   - /**
621   - * @param keyid 键盘编号
622   - * @param packid 包id
623   - * @param packH 数据段id
624   - * @param packL 数据片id
625   - * @param datas 数据
626   - * @param offset 偏移位置
627   - * @param length 长度
628   - * @Auther Elvis
629   - * 上传数据包(多包应答)
630   - */
631   - public void uploadFileData(byte[] keyid, byte packid, byte packH, byte packL, byte[] datas, int offset, int length, byte packtype) {
632   - LogUtil.i(TAG, "onMutilPacketData packid=" + packid + ",packH=" + packH + ",packL=" + packL + ",offset=" + offset);
633   - byte[] mBuffer = new byte[0x1F + 4];
634   - Arrays.fill(mBuffer, (byte) 0x0);
635   - mBuffer[0] = (byte) 0xF5;
636   - mBuffer[1] = (byte) 0xAA;
637   - mBuffer[2] = (byte) 0xAA;
638   - mBuffer[3] = (byte) 0x1F;
639   -
640   - mBuffer[4] = (byte) 0xA0;
641   - int keyId = XpadApiServiceInfoProxyManager.getInstance().getKeypadInfo().getKeyId();
642   - mBuffer[5] = (byte)((keyId >> 8) & 0xFF);
643   - mBuffer[6] = (byte)((keyId) & 0xFF);
644   -
645   - mBuffer[7] = 2;//CMD 1 回应多包数据
646   - mBuffer[8] = packtype;//PACKTYPE 多包类型
647   - mBuffer[9] = packid;//数据包标识码
648   - mBuffer[10] = packH;//数据段编号
649   - mBuffer[11] = packL;//数据片编号
650   - for (int i = 0; i < length && i < 16 && i < datas.length - offset; i++) {
651   - mBuffer[12 + i] = datas[offset + i];
652   - }
653   - Packet packet = new Packet();
654   - packet.setDatas(mBuffer);
655   - packet.setSendNo(Packet.CommunicationTestMatchNum);
656   - sendInnerPacket(packet);
657   - }
658   -
659   - /**
660   - * @param packid 包id
661   - * 多包接收确认(多包接收应答)
662   - */
663   - public void packetConfirmation(byte[] keyid, byte packid, byte packH, byte packL, byte[] names, byte packtype) {
664   - LogUtil.i(TAG, "onMutilPacketRespone packid=" + packid + ",packH=" + packH + ",packL=" + packL + ",names=" + names);
665   - byte[] mBuffer = new byte[0x1F + 4];
666   - Arrays.fill(mBuffer, (byte) 0x0);
667   - mBuffer[0] = (byte) 0xF5;
668   - mBuffer[1] = (byte) 0xAA;
669   - mBuffer[2] = (byte) 0xAA;
670   - mBuffer[3] = (byte) 0x1F;
671   -
672   - mBuffer[4] = (byte) 0xA0;
673   - int keyId = XpadApiServiceInfoProxyManager.getInstance().getKeypadInfo().getKeyId();
674   - mBuffer[5] = (byte)((keyId >> 8) & 0xFF);
675   - mBuffer[6] = (byte)((keyId) & 0xFF);
676   - mBuffer[5] = keyid[0];
677   - mBuffer[6] = keyid[1];
678   -
679   - mBuffer[7] = 1;//CMD 1
680   - mBuffer[8] = packtype;//PACKTYPE 多包类型
681   - mBuffer[9] = packid;//数据包标识码
682   - mBuffer[10] = packH;
683   - mBuffer[11] = packL;
684   - if (names != null) {
685   - for (int i = 0; i < 14 && i < names.length; i++) {
686   - mBuffer[12 + i] = names[i];
687   - }
688   - }
689   -
690   - Packet packet = new Packet();
691   - packet.setDatas(mBuffer);
692   - packet.setSendNo(Packet.CommunicationTestMatchNum);
693   - sendInnerPacket(packet);
694   - }
695   -
696   - private void keepFirmMode() {
697   - byte[] mBuffer = new byte[0x1F + 4];
698   - Arrays.fill(mBuffer, (byte) 0x0);
699   - mBuffer[0] = (byte) 0xF5;
700   - mBuffer[1] = (byte) 0xAA;
701   - mBuffer[2] = (byte) 0xAA;
702   - mBuffer[3] = (byte) 10;
703   -
704   - mBuffer[4] = 0x78;
705   - mBuffer[5] = 0x02;
706   -
707   - Packet packet = new Packet();
708   - packet.setDatas(mBuffer);
709   - packet.setSendNo(Packet.CommunicationTestMatchNum);
710   - sendInnerPacket(packet);
711   - }
712   -
713   - private void eraseFlash(int fileLen) {
714   - byte[] mBuffer = new byte[0x1F + 4];
715   - Arrays.fill(mBuffer, (byte) 0x0);
716   - mBuffer[0] = (byte) 0xF5;
717   - mBuffer[1] = (byte) 0xAA;
718   - mBuffer[2] = (byte) 0xAA;
719   - mBuffer[3] = (byte) 10;
720   - mBuffer[4] = 0x78;
721   - mBuffer[5] = 0x03;
722   - mBuffer[6] = 0;
723   - mBuffer[7] = (byte) (fileLen / 1024);
724   -
725   - Packet packet = new Packet();
726   - packet.setDatas(mBuffer);
727   - packet.setSendNo(Packet.CommunicationTestMatchNum);
728   - sendInnerPacket(packet);
729   - }
730   -}
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/bean/BaseInfo.java deleted
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 deleted
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 deleted
1   -package com.sunvote.xpadapi.service.bean;
2   -
3   -import com.sunvote.xpadapi.service.logic.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 deleted
1   -package com.sunvote.xpadapi.service.bean;
2   -
3   -import com.sunvote.xpadapi.service.logic.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 deleted
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 deleted
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 deleted
1   -package com.sunvote.xpadapi.service.bean;
2   -
3   -import com.sunvote.xpadapi.service.logic.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 deleted
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 deleted
1   -package com.sunvote.xpadapi.service.bean;
2   -
3   -import com.sunvote.xpadapi.service.logic.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 deleted
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 deleted
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 deleted
1   -package com.sunvote.xpadapi.service.bean;
2   -
3   -import com.sunvote.xpadapi.service.logic.SerialManager;
4   -import com.sunvote.xpadapi.service.logic.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 deleted
1   -package com.sunvote.xpadapi.service.bean;
2   -
3   -import com.sunvote.xpadapi.service.logic.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 deleted
1   -package com.sunvote.xpadapi.service.bean;
2   -
3   -import com.sunvote.xpadapi.service.logic.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 deleted
1   -package com.sunvote.xpadapi.service.bean;
2   -
3   -import com.sunvote.xpadapi.service.logic.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 deleted
1   -package com.sunvote.xpadapi.service.bean;
2   -
3   -import com.sunvote.xpadapi.service.logic.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/AbsDownloadProcess.java deleted
1   -package com.sunvote.xpadapi.service.listener;
2   -
3   -import java.io.File;
4   -import java.io.IOException;
5   -
6   -/**
7   - * Created by Elvis on 2018/3/20 11:18
8   - * Email:Eluis@psunsky.com
9   - * 版权所有:长沙中天电子设计开发有限公司
10   - * Description: 人大通用版XPadAppRendaMac
11   - */
12   -
13   -public abstract class AbsDownloadProcess {
14   -
15   - private static String foldPath = "/sdcard/Sunvote/download/";
16   -
17   - protected static String fileName = "default.obj";
18   -
19   - private long length ;
20   - private long curComplete = 0 ;
21   -
22   - private static File file ;
23   -
24   - public File getFile() {
25   - if(file == null){
26   - curComplete = 0 ;
27   - File folder = new File(foldPath);
28   - if(!folder.exists()){
29   - folder.mkdirs();
30   - }
31   - if(fileName == null || "".equals(fileName.trim())){
32   - fileName = "default.obj" ;
33   - }
34   - file = new File(foldPath , fileName);
35   - file.deleteOnExit();
36   - if(!file.exists()){
37   - try {
38   - file.createNewFile();
39   - } catch (IOException e) {
40   - onDownloadError(e);
41   - }
42   - }
43   - }
44   - return file;
45   - }
46   -
47   - protected long getLength() {
48   - return length;
49   - }
50   -
51   - public String getFoldPath() {
52   - return foldPath;
53   - }
54   -
55   - protected void setLength(long length) {
56   - this.length = length;
57   - curComplete = 0 ;
58   - }
59   -
60   - public void setFileName(String fileName) {
61   - if(!(fileName == null || "".equals(fileName.trim()))) {
62   - this.fileName = fileName;
63   - file = null;
64   - }
65   - }
66   -
67   - protected String getFileName() {
68   - return fileName;
69   - }
70   -
71   - public void setFoldPath(String foldPath) {
72   - this.foldPath = foldPath;
73   - }
74   -
75   - protected void onStartDownload(){
76   - onStartDownload(getFile(),getLength());
77   - }
78   -
79   - public abstract void onStartDownload(File file,long length);
80   -
81   - protected void onDownloadAddProcess(int curPack) {
82   - curComplete += curPack;
83   - double result = 0;
84   - if(curComplete <= length){
85   - result = (double)curComplete / length ;
86   - }else{
87   - result = 1;
88   - }
89   -
90   - try{
91   - onDownloadProcess(result);
92   - }catch (Exception ex){
93   - ex.printStackTrace();
94   - }
95   - try{
96   - int ri = (int)(result * 100);
97   - onDownloadProcess(ri + "%");
98   - }catch (Exception ex){
99   - ex.printStackTrace();
100   - }
101   - }
102   -
103   - public abstract void onDownloadProcess(double process);
104   -
105   - public abstract void onDownloadProcess(String process);
106   -
107   - protected void onStopDownload(){
108   - onStopDownload(getFile());
109   - }
110   -
111   - public abstract void onStopDownload(File file);
112   -
113   - public abstract void onDownloadError(Exception e);
114   -
115   -}
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/BaseInfoChanageListener.java deleted
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 deleted
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 deleted
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/IUploadListener.java deleted
1   -package com.sunvote.xpadapi.service.listener;
2   -
3   -/**
4   - * Created by Elvis on 2018/3/22 13:43
5   - * Email:Eluis@psunsky.com
6   - * 版权所有:长沙中天电子设计开发有限公司
7   - * Description: 人大通用版XPadAppRendaMac
8   - */
9   -public interface IUploadListener {
10   -
11   - public void onUploadStart();
12   -
13   - public void onUploadProcess(double process);
14   -
15   - public void onUploadStop();
16   -
17   - public void onFail();
18   -}
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/listener/KeyPadinfoChanageListener.java deleted
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 deleted
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 deleted
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 deleted
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 deleted
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 deleted
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/service/logic/RFFileDownloadModule.java deleted
1   -package com.sunvote.xpadapi.service.logic;
2   -
3   -import android.os.Handler;
4   -import android.os.Looper;
5   -
6   -import com.sunvote.util.LogUtil;
7   -import com.sunvote.xpadapi.service.listener.AbsDownloadProcess;
8   -
9   -import java.io.File;
10   -
11   -/**
12   - * Created by Elvis on 2018/3/20 11:16
13   - * Email:Eluis@psunsky.com
14   - * 版权所有:长沙中天电子设计开发有限公司
15   - * Description: 文件下载模块
16   - */
17   -public class RFFileDownloadModule {
18   -
19   - private RFFileDownloadModule(){
20   - handler = new Handler(Looper.getMainLooper());
21   - }
22   - private Handler handler ;
23   - private long overtime = 15 * 1000 ;
24   - private static RFFileDownloadModule instance = new RFFileDownloadModule();
25   -
26   - public static RFFileDownloadModule getInstance() {
27   - return instance;
28   - }
29   -
30   - private AbsDownloadProcess downloadProcess;
31   - private AbsDownloadProcess tdownloadProcess = new AbsDownloadProcess() {
32   -
33   - private boolean start = false;
34   - private double process = 0 ;
35   - private Runnable runnable = new Runnable() {
36   - @Override
37   - public void run() {
38   - onDownloadError(new Exception("overtime"));
39   - }
40   - };
41   -
42   - @Override
43   - public void onStartDownload(File file, long length) {
44   - start = true;
45   - process = 0;
46   - LogUtil.i("onStartDownload", file.getName() + "," + length);
47   - if(downloadProcess != null){
48   - downloadProcess.onStartDownload(file,length);
49   - }
50   - handler.removeCallbacks(runnable);
51   - handler.postDelayed(runnable,overtime);
52   - }
53   -
54   - @Override
55   - public void onDownloadProcess(double process) {
56   - this.process = process;
57   - LogUtil.i("onDownloadProcess", "process," + process);
58   - if(downloadProcess != null && start){
59   - downloadProcess.onDownloadProcess(process);
60   - }
61   - handler.removeCallbacks(runnable);
62   - handler.postDelayed(runnable,overtime);
63   - }
64   -
65   - @Override
66   - public void onDownloadProcess(String process) {
67   - LogUtil.i("onDownloadProcess", "process," + process);
68   - if(downloadProcess != null && start){
69   - downloadProcess.onDownloadProcess(process);
70   - }
71   - handler.removeCallbacks(runnable);
72   - handler.postDelayed(runnable,overtime);
73   - }
74   -
75   - @Override
76   - public void onStopDownload(File file) {
77   - LogUtil.i("onStopDownload", "process," + file.getName());
78   - if(downloadProcess != null && start){
79   - if(process >= 1.0){
80   - downloadProcess.onStopDownload(file);
81   - }else{
82   - downloadProcess.onDownloadError(new Exception("file download error"));
83   - }
84   - }
85   - start = false;
86   - handler.removeCallbacks(runnable);
87   - file.deleteOnExit();
88   - }
89   -
90   - @Override
91   - public void onDownloadError(Exception e) {
92   - LogUtil.i("onStopDownload", "error", e);
93   - if(downloadProcess != null && start){
94   - downloadProcess.onDownloadError(e);
95   - }
96   - start = false;
97   - handler.removeCallbacks(runnable);
98   - }
99   - };
100   -
101   - public void setOvertime(long overtime) {
102   - if(overtime > 0){
103   - this.overtime = overtime;
104   - }
105   - }
106   -
107   - public synchronized void registerDownloadProcess(AbsDownloadProcess downloadProcess){
108   - this.downloadProcess = downloadProcess ;
109   - }
110   -
111   - public synchronized void unRegisterDownloadProcess(AbsDownloadProcess downloadProcess){
112   - this.downloadProcess = null;
113   - }
114   -
115   - protected synchronized AbsDownloadProcess getDownloadProcess() {
116   -
117   - return tdownloadProcess;
118   - }
119   -
120   -
121   -}
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/logic/RFFileUploadModule.java deleted
1   -package com.sunvote.xpadapi.service.logic;
2   -
3   -import android.os.Handler;
4   -import android.os.HandlerThread;
5   -
6   -import com.sunvote.util.LogUtil;
7   -import com.sunvote.xpadapi.service.listener.IUploadListener;
8   -
9   -import java.io.File;
10   -import java.io.FileInputStream;
11   -import java.io.IOException;
12   -import java.io.UnsupportedEncodingException;
13   -
14   -/**
15   - * Created by Elvis on 2018/3/21 16:13
16   - * Email:Eluis@psunsky.com
17   - * 版权所有:长沙中天电子设计开发有限公司
18   - * Description: 文件上传模块
19   - */
20   -public class RFFileUploadModule {
21   -
22   - public static final byte PACKTYPE = 5 ;
23   - public static final int SLEEP_TIME = 25 ;
24   - public static byte index = 0 ;
25   - private RFFileUploadModule(){
26   - handlerThread = new HandlerThread(RFFileUploadModule.class.getSimpleName());
27   - handlerThread.start();
28   - handler = new Handler(handlerThread.getLooper());
29   - }
30   -
31   - private static RFFileUploadModule instance ;
32   -
33   - public static RFFileUploadModule getInstance() {
34   - if(instance == null){
35   - synchronized (RFFileUploadModule.class){
36   - if(instance == null){
37   - instance = new RFFileUploadModule();
38   - }
39   - }
40   - }
41   - return instance;
42   - }
43   -
44   - private IUploadListener uploadListener = new IUploadListener() {
45   - @Override
46   - public void onUploadStart() {
47   - System.out.println("onUploadStart");
48   - }
49   -
50   - @Override
51   - public void onUploadProcess(double process) {
52   - System.out.println("onUploadProcess:" + process);
53   - }
54   -
55   - @Override
56   - public void onUploadStop() {
57   - System.out.println("onUploadStop");
58   - }
59   -
60   - @Override
61   - public void onFail() {
62   - System.out.println("onFail");
63   - }
64   - };
65   -
66   -
67   - private String filename;
68   - private byte[] datas = new byte[1024];
69   - private int length = 1024;
70   - private HandlerThread handlerThread ;
71   - private Handler handler ;
72   - private byte[] keyid = new byte[2];
73   - private Runnable task;
74   - private int packTotal ;
75   - private boolean isStop = false ;
76   -
77   - /**
78   - * 文件名不能超过16个字符(中文不能超过8个),超过16个字符将会出现截断。
79   - * 文件长度不能超过65535个字节
80   - * @param file 文件
81   - * @return 是否成功发起上传
82   - */
83   - public boolean uploadFile(File file){
84   - LogUtil.i("RFFileUploadModule","uploadFile" + file);
85   - if(file != null){
86   - length = (int)file.length();
87   - filename = file.getName();
88   - datas = new byte[length+4];
89   - FileInputStream fis = null ;
90   - try {
91   - fis = new FileInputStream(file);
92   - int start = 0 ;
93   - // 把文件数据读入字节数组。
94   - while(start < length){
95   - int ret = fis.read(datas,start,length-start);
96   - if(ret < 0){
97   - break;
98   - }
99   - start += ret ;
100   - }
101   - datas[length] = 0x13 ;
102   - datas[length + 1] = 0x0 ;
103   - datas[length + 2] = 0x10 ;
104   - datas[length + 3] = 0x0 ;
105   -
106   - if(start >= length){
107   - task = new A0(filename,length);
108   - handler.removeCallbacks(task);
109   - handler.post(task);
110   - return true;
111   - }
112   -
113   - } catch (Exception e) {
114   - e.printStackTrace();
115   - }finally {
116   - if(fis != null){
117   - try {
118   - fis.close();
119   - } catch (IOException e) {
120   - e.printStackTrace();
121   - }
122   - fis = null;
123   - }
124   - }
125   - }
126   - return false;
127   - }
128   -
129   - public void setKeyid(byte[] keyid) {
130   - setKeyid(keyid,0);
131   - }
132   - public void setKeyid(byte[] keyid,int start) {
133   - this.keyid[0] = keyid[start];
134   - this.keyid[1] = keyid[start+1];
135   - }
136   -
137   - public void onUploadFile(byte data, byte[] keyid, byte packid, byte packH, byte[] packLs) {
138   - if (data == 1) {
139   - setKeyid(keyid);
140   - packetConfirmation(packid);
141   - }
142   - if (data == 2) {
143   - uploadData(packid, packH, packLs);
144   - }
145   - if (data == 3) {
146   - packetReceptionConfirmed(packid, packH);
147   - }
148   - }
149   -
150   - public void uploadData(byte packid, byte packH, byte[] packLs){
151   - System.out.println("uploadData");
152   - handler.removeCallbacks(task);
153   - if(task instanceof A2){
154   - ((A2)task).setStop(true);
155   - }
156   - task = new A2(keyid,packid,packH,datas,packLs);
157   - handler.post(task);
158   - if(uploadListener != null){
159   - double process = 0 ;
160   - if(packTotal > 0){
161   - int count = 0 ;
162   - int sen = (packLs[1] & 0xFF) * 256 + (packLs[0] & 0XFF);
163   - for(int i = 0 ; i < 16 ; i++){
164   - if((sen & (1 << i)) == 0){
165   - count ++ ;
166   - }
167   - }
168   - int been = packH * 16 + count ;
169   - if(been > packTotal){
170   - been = packTotal ;
171   - }
172   - process = (double)(been) / packTotal ;
173   - }
174   - uploadListener.onUploadProcess(process);
175   - }
176   - }
177   -
178   - public void packetConfirmation(byte packid){
179   - System.out.println("packetConfirmation");
180   - handler.removeCallbacks(task);
181   - byte[] names = null;
182   - if(filename != null){
183   - try {
184   - names = filename.getBytes("GB2312");
185   - } catch (UnsupportedEncodingException e) {
186   - e.printStackTrace();
187   - }
188   - }
189   - task = new A1(keyid,(byte)((length + 4 ) / 65535), (byte)(((length + 4) % 65535) / 256),(byte)((length + 4) % 256),names);
190   - handler.post(task);
191   - }
192   -
193   - public void packetReceptionConfirmed(byte packid,byte packH){
194   - System.out.println("packetReceptionConfirmed");
195   - handler.removeCallbacks(task);
196   - task = new A3(keyid,packid,packH);
197   - handler.post(task);
198   - }
199   -
200   - public boolean uploadFile(byte[] datas){
201   - System.out.println("uploadFile" + datas);
202   - if(datas != null){
203   - length = datas.length ;
204   - filename = null ;
205   - this.datas = new byte[length + 4];
206   - System.arraycopy(datas,0,this.datas,0,length);
207   - datas[length] = 0x13 ;
208   - datas[length + 1] = 0x0 ;
209   - datas[length + 2] = 0x10 ;
210   - datas[length + 3] = 0x0 ;
211   - task = new A0(filename,length);
212   - handler.removeCallbacks(task);
213   - handler.post(task);
214   - return true;
215   - }
216   - return false;
217   - }
218   -
219   -
220   - public void setUploadListener(IUploadListener uploadListener) {
221   - this.uploadListener = uploadListener;
222   - }
223   -
224   - class A0 implements Runnable{
225   - private int length ;
226   - private String filename;
227   - private int times ;
228   - public A0(String filename,int length){
229   - this.length = length ;
230   - this.filename = filename;
231   - packTotal = length / 16 + 1;
232   - times = 0 ;
233   - index++;
234   - }
235   -
236   - @Override
237   - public void run() {
238   - LogUtil.i("RFFileUploadModule","A0 run");
239   - XpadApiServiceInfoProxyManager.getInstance().getService().applyFileUpload(this.length,this.filename,PACKTYPE,index);
240   - times ++ ;
241   - if(task != null && times < 5){
242   - handler.removeCallbacks(task);
243   - handler.postDelayed(task,5000);
244   - }
245   - }
246   - }
247   -
248   - class A1 implements Runnable{
249   -
250   - private byte[] keyid;
251   - private byte packid ;
252   - private byte packH ;
253   - private byte packL ;
254   - private byte[] names ;
255   - private int times ;
256   -
257   - public A1(byte[] keyid, byte packid,byte packH,byte packL,byte[] names) {
258   - LogUtil.i("RFFileUploadModule","A1");
259   - this.keyid = keyid;
260   - this.packid = packid;
261   - this.packH = packH ;
262   - this.packL = packL ;
263   - this.names = names ;
264   - times = 0 ;
265   - }
266   -
267   - @Override
268   - public void run() {
269   - LogUtil.i("RFFileUploadModule","A1 run");
270   - XpadApiServiceInfoProxyManager.getInstance().getService().packetConfirmation(this.keyid,this.packid,this.packH,this.packL,this.names,PACKTYPE);
271   - times ++ ;
272   - if(task != null && times < 5){
273   - handler.removeCallbacks(task);
274   - handler.postDelayed(task,5000);
275   - }
276   - if(uploadListener != null){
277   - uploadListener.onUploadStart();
278   - isStop = false;
279   - }
280   - }
281   - }
282   -
283   - class A2 implements Runnable{
284   - private byte[] keyid;
285   - private byte packid;
286   - private byte packH;
287   - private byte[] datas ;
288   - private byte[] packLs;
289   - private int times ;
290   - private boolean stop = false;
291   -
292   - public void setStop(boolean stop) {
293   - this.stop = stop;
294   - }
295   -
296   - public A2(byte[] keyid, byte packid, byte packH, byte[] datas, byte[] packLs) {
297   - LogUtil.i("RFFileUploadModule","A2");
298   - this.keyid = keyid;
299   - this.packid = packid;
300   - this.packH = packH;
301   - this.datas = datas;
302   - this.packLs = packLs;
303   - times = 0 ;
304   - }
305   -
306   - @Override
307   - public void run() {
308   - LogUtil.i("RFFileUploadModule","A2 run");
309   - int packLsi = (packLs[1] & 0xFF) * 256 + (packLs[0] & 0xFF);
310   - int offset = 0 ;
311   - int length = 16;
312   - System.out.println("packLsi:" + packLsi);
313   - for(byte packL = 0 ;packL < 16 && !stop ;packL ++) {
314   - if((packLsi & (1 << packL)) != 0){
315   - offset = ((packid * 65535) + (packH) * 256 + 16 * (packL)) & 0xFFFF;
316   - XpadApiServiceInfoProxyManager.getInstance().getService().uploadFileData(this.keyid, this.packid, this.packH, (byte)(packL ), this.datas, offset, length,PACKTYPE);
317   - // need sleep ????
318   - try{
319   - Thread.sleep(SLEEP_TIME);
320   - } catch (Exception e) {
321   - e.printStackTrace();
322   - }
323   - }
324   - }
325   -
326   - times ++ ;
327   - if(task != null && times < 5){
328   - handler.removeCallbacks(task);
329   - handler.postDelayed(task,5000);
330   - }
331   - }
332   - }
333   -
334   - class A3 implements Runnable{
335   - private byte[] keyid;
336   - private byte packid ;
337   - private byte packH;
338   - private int times ;
339   -
340   - public A3(byte[] keyid, byte packid, byte packH) {
341   - LogUtil.i("RFFileUploadModule","A3");
342   - this.keyid = keyid;
343   - this.packid = packid;
344   - this.packH = packH;
345   - times = 0 ;
346   - }
347   -
348   - @Override
349   - public void run() {
350   - LogUtil.i("RFFileUploadModule","A3 run");
351   - XpadApiServiceInfoProxyManager.getInstance().getService().packetReceptionConfirmed(this.keyid,this.packid,this.packH,PACKTYPE);
352   - if(uploadListener != null && !isStop){
353   - isStop = true;
354   - uploadListener.onUploadStop();
355   - }
356   - }
357   - }
358   -}
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/logic/RFMessageUploadModule.java deleted
1   -package com.sunvote.xpadapi.service.logic;
2   -
3   -import android.os.Handler;
4   -import android.os.HandlerThread;
5   -
6   -import java.io.UnsupportedEncodingException;
7   -
8   -/**
9   - * Created by Elvis on 2018/3/27 9:48
10   - * Email:Eluis@psunsky.com
11   - * 版权所有:长沙中天电子设计开发有限公司
12   - * Description: 人大通用版
13   - * 短消息上传模块
14   - */
15   -public class RFMessageUploadModule {
16   -
17   - public static final byte PACKTYPE = 3 ;
18   - private static RFMessageUploadModule instance ;
19   -
20   - private IUploadListener uploadListener ;
21   -
22   - private String filename;
23   - private byte[] datas = "test message".getBytes();
24   - private int length = 1024;
25   - private HandlerThread handlerThread ;
26   - private Handler handler ;
27   - private byte[] keyid;
28   - private Runnable task;
29   - private int packTotal ;
30   - private boolean stop = false;
31   -
32   - private RFMessageUploadModule(){
33   - handlerThread = new HandlerThread(RFMessageUploadModule.class.getSimpleName());
34   - handlerThread.start();
35   - handler = new Handler(handlerThread.getLooper());
36   - }
37   -
38   - public static RFMessageUploadModule getInstance() {
39   - if(instance == null){
40   - instance = new RFMessageUploadModule();
41   - }
42   - return instance;
43   - }
44   -
45   - public void setMessageContent(byte[] messageContent) {
46   - this.datas = messageContent;
47   - uploadMsgData(datas);
48   - removeTask();
49   - }
50   -
51   - public void setMessageContent(String message) {
52   - try {
53   - this.datas = message.getBytes("GB2312");
54   - uploadMsgData(datas);
55   - removeTask();
56   - handler.removeCallbacks(failCall);
57   - handler.postDelayed(failCall,10000);
58   - } catch (Exception e) {
59   - e.printStackTrace();
60   - }
61   - }
62   -
63   - private boolean uploadMsgData(byte[] ds){
64   - System.out.println("uploadMsgData" + ds);
65   - if(ds != null){
66   - length = ds.length ;
67   - filename = null ;
68   - this.datas = new byte[length ];
69   - System.arraycopy(ds,0,this.datas,0,length);
70   -// this.datas[length] = 0x13 ;
71   -// this.datas[length + 1] = 0x0 ;
72   -// this.datas[length + 2] = 0x10 ;
73   -// this.datas[length + 3] = 0x0 ;
74   - task = new A0(filename,length);
75   - handler.removeCallbacks(task);
76   - handler.post(task);
77   - return true;
78   - }
79   - return false;
80   - }
81   -
82   -
83   - public void setKeyid(byte[] keyid) {
84   - this.keyid = keyid;
85   - }
86   -
87   - public void uploadData(byte packid, byte packH, byte[] packLs){
88   - System.out.println("uploadData");
89   - handler.removeCallbacks(task);
90   - task = new A2(keyid,packid,packH,datas,packLs);
91   - handler.post(task);
92   - if(uploadListener != null){
93   - double process = 0 ;
94   - if(packTotal > 0){
95   - int count = 0 ;
96   - int sen = (packLs[1] & 0xFF) * 256 + (packLs[0] & 0XFF);
97   - for(int i = 0 ; i < 16 ; i++){
98   - if((sen & (1 << i)) != 0){
99   - count ++ ;
100   - }
101   - }
102   - process = (double)(packH * 16 + count) / packTotal ;
103   - }
104   - uploadListener.onUploadProcess(process);
105   - }
106   - }
107   -
108   - public void packetConfirmation(byte packid){
109   - System.out.println("packetConfirmation");
110   - handler.removeCallbacks(task);
111   - byte[] names = null;
112   - if(filename != null){
113   - try {
114   - names = filename.getBytes("GB2312");
115   - } catch (UnsupportedEncodingException e) {
116   - e.printStackTrace();
117   - }
118   - }
119   - task = new A1(keyid,(byte)((length ) / 65535), (byte)(((length ) % 65535) / 256),(byte)(((length ) % 256 / 16 + (length % 16 == 0 ? 0 : 1))),names);
120   - handler.post(task);
121   - }
122   -
123   - public void packetReceptionConfirmed(byte packid,byte packH){
124   - System.out.println("packetReceptionConfirmed");
125   - handler.removeCallbacks(task);
126   - task = new A3(keyid,packid,packH);
127   - handler.post(task);
128   - }
129   -
130   - public boolean uploadMessage(byte[] datas){
131   - System.out.println("uploadMsgData" + datas);
132   - if(datas != null){
133   - length = datas.length ;
134   - filename = null ;
135   - this.datas = new byte[length ];
136   - System.arraycopy(datas,0,this.datas,0,length);
137   -// datas[length] = 0x13 ;
138   -// datas[length + 1] = 0x0 ;
139   -// datas[length + 2] = 0x10 ;
140   -// datas[length + 3] = 0x0 ;
141   - task = new A0(filename,length);
142   - handler.removeCallbacks(task);
143   - handler.post(task);
144   - return true;
145   - }
146   - return false;
147   - }
148   -
149   -
150   - public void setUploadListener(IUploadListener uploadListener) {
151   - this.uploadListener = uploadListener;
152   - }
153   -
154   - class A0 implements Runnable{
155   - private int length ;
156   - private String filename;
157   - private int times ;
158   - public A0(String filename,int length){
159   - this.length = length ;
160   - this.filename = filename;
161   - packTotal = length / 16 + 1;
162   - times = 0 ;
163   - }
164   -
165   - @Override
166   - public void run() {
167   - XPadApi.getInstance().applyFileUpload(this.length,this.filename,PACKTYPE,RFFileUploadModule.index);
168   - }
169   - }
170   -
171   - class A1 implements Runnable{
172   -
173   - private byte[] keyid;
174   - private byte packid ;
175   - private byte packH ;
176   - private byte packL ;
177   - private byte[] names ;
178   - private int times ;
179   -
180   - public A1(byte[] keyid, byte packid,byte packH,byte packL,byte[] names) {
181   - this.keyid = keyid;
182   - this.packid = packid;
183   - this.packH = packH ;
184   - this.packL = packL ;
185   - this.names = names ;
186   - times = 0 ;
187   - }
188   -
189   - @Override
190   - public void run() {
191   - XPadApi.getInstance().packetConfirmation(this.keyid,this.packid,this.packH,this.packL,this.names,PACKTYPE);
192   - times ++ ;
193   - if(task != null && times < 5){
194   - handler.postDelayed(task,1000);
195   - }
196   - if(uploadListener != null){
197   - uploadListener.onUploadStart();
198   - }
199   -
200   - handler.removeCallbacks(failCall);
201   - handler.postDelayed(failCall,10000);
202   - }
203   - }
204   -
205   - class A2 implements Runnable{
206   - private byte[] keyid;
207   - private byte packid;
208   - private byte packH;
209   - private byte[] datas ;
210   - private byte[] packLs;
211   - private int times ;
212   -
213   - public A2(byte[] keyid, byte packid, byte packH, byte[] datas, byte[] packLs) {
214   - this.keyid = keyid;
215   - this.packid = packid;
216   - this.packH = packH;
217   - this.datas = datas;
218   - this.packLs = packLs;
219   - times = 0 ;
220   - }
221   -
222   - @Override
223   - public void run() {
224   -
225   - int packLsi = packLs[1] * 256 + packLs[0];
226   - int offset = 0 ;
227   - int length = 16;
228   - System.out.println("packLsi:" + packLsi);
229   - for(byte packL = 0 ;packL < 16 ;packL ++) {
230   - if((packLsi & (1 << packL)) != 0){
231   - offset = ((packid * 65535) + (packH) * 256 + 16 * (packL)) & 0xFFFF;
232   - XPadApi.getInstance().uploadFileData(this.keyid, this.packid, this.packH, (byte)(packL), this.datas, offset, length,PACKTYPE);
233   - try{
234   - Thread.sleep(50);
235   - } catch (Exception e) {
236   - e.printStackTrace();
237   - }
238   - }
239   - }
240   - times ++ ;
241   - if(task != null && times < 5){
242   - handler.postDelayed(task,1000);
243   - }
244   - handler.removeCallbacks(failCall);
245   - handler.postDelayed(failCall,10000);
246   - }
247   - }
248   -
249   - class A3 implements Runnable{
250   - private byte[] keyid;
251   - private byte packid ;
252   - private byte packH;
253   -
254   - public A3(byte[] keyid, byte packid, byte packH) {
255   - this.keyid = keyid;
256   - this.packid = packid;
257   - this.packH = packH;
258   - }
259   -
260   - @Override
261   - public void run() {
262   - XPadApi.getInstance().packetReceptionConfirmed(this.keyid,this.packid,this.packH,PACKTYPE);
263   - if(uploadListener != null){
264   - uploadListener.onUploadStop();
265   - }
266   - handler.removeCallbacks(failCall);
267   - }
268   - }
269   -
270   - public void onUploadMessage(byte data, byte[] keyid, byte packid, byte packH, byte[] packLs) {
271   - LogUtil.i("RFMessageUploadModule","onUploadMessage:" + data);
272   - if (data == 1) {
273   - setKeyid(keyid);
274   - packetConfirmation(packid);
275   - }
276   - if (data == 2) {
277   - uploadData(packid, packH, packLs);
278   - }
279   - if (data == 3) {
280   - packetReceptionConfirmed(packid, packH);
281   - }
282   - }
283   -
284   - private void removeTask(){
285   - handler.postDelayed(new Runnable() {
286   - @Override
287   - public void run() {
288   - handler.removeCallbacks(task);
289   - }
290   - },5000);
291   - }
292   -
293   - private Runnable failCall = new Runnable() {
294   - @Override
295   - public void run() {
296   - if(uploadListener != null){
297   - uploadListener.onFail();
298   - }
299   - }
300   - };
301   -}
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/logic/SendPacket.java deleted
1   -package com.sunvote.xpadapi.service.logic;
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/logic/SenderManager.java deleted
1   -package com.sunvote.xpadapi.service.logic;
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.setOk(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.setOk(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/logic/SerialManager.java deleted
1   -package com.sunvote.xpadapi.service.logic;
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/logic/XpadApiServiceInfoProxyManager.java deleted
1   -package com.sunvote.xpadapi.service.logic;
2   -
3   -import com.sunvote.xpadapi.service.XpadApiService;
4   -import com.sunvote.xpadapi.service.bean.BaseInfo;
5   -import com.sunvote.xpadapi.service.bean.BaseVoteInfo;
6   -import com.sunvote.xpadapi.service.bean.KeypadInfo;
7   -import com.sunvote.xpadapi.service.bean.ModelInfo;
8   -import com.sunvote.xpadapi.service.bean.OnLineInfo;
9   -import com.sunvote.xpadapi.service.bean.Packet;
10   -import com.sunvote.xpadapi.service.listener.BaseInfoChanageListener;
11   -import com.sunvote.xpadapi.service.listener.BaseVoteInfoChanageListener;
12   -import com.sunvote.xpadapi.service.listener.KeyPadinfoChanageListener;
13   -import com.sunvote.xpadapi.service.listener.ModelInfoChanageListener;
14   -import com.sunvote.xpadapi.service.listener.OnSendPacket;
15   -import com.sunvote.xpadapi.service.listener.OnlineInfoChanageListener;
16   -import com.sunvote.xpadapi.util.LogUtil;
17   -
18   -import java.util.ArrayList;
19   -import java.util.Collections;
20   -import java.util.List;
21   -
22   -/**
23   - * 服务信息
24   - */
25   -public final class XpadApiServiceInfoProxyManager {
26   -
27   - public static final String TAG = XpadApiServiceInfoProxyManager.class.getSimpleName();
28   - private static XpadApiServiceInfoProxyManager instance = null ;
29   - private List<Packet> sendList = Collections.synchronizedList(new ArrayList<Packet>());
30   - private Object lock = new Object();
31   - private String charset = "GB2312" ;
32   - private XpadApiService service;
33   -
34   - public void setCharset(String charset) {
35   - this.charset = charset;
36   - }
37   -
38   - public void setService(XpadApiService service) {
39   - this.service = service;
40   - }
41   -
42   - public XpadApiService getService() {
43   - return service;
44   - }
45   -
46   - public String getCharset() {
47   - return charset;
48   - }
49   -
50   - private XpadApiServiceInfoProxyManager(){
51   - }
52   -
53   - public static XpadApiServiceInfoProxyManager getInstance(){
54   - if(instance == null){
55   - synchronized(XpadApiServiceInfoProxyManager.class){
56   - if(instance == null){
57   - instance = new XpadApiServiceInfoProxyManager();
58   - }
59   - }
60   - }
61   - return instance;
62   - }
63   -
64   - private ModelInfo modelInfo;
65   - private ModelInfoChanageListener modelInfoListener;
66   -
67   - public void setModelInfo(ModelInfo modelInfo) {
68   - this.modelInfo = modelInfo;
69   - if(modelInfoListener != null){
70   - try{
71   - modelInfoListener.onModelInfoChanage(modelInfo);
72   - }catch (Exception ex){
73   - LogUtil.e(TAG,"onModelInfoChanage",ex);
74   - }
75   - }
76   - }
77   -
78   - public ModelInfo getModelInfo() {
79   - return modelInfo;
80   - }
81   -
82   - public void setModelInfoListener(ModelInfoChanageListener modelInfoListener) {
83   - this.modelInfoListener = modelInfoListener;
84   - }
85   -
86   - private BaseInfo baseInfo;
87   - private BaseInfoChanageListener baseInfoListener;
88   -
89   - public void setBaseInfo(BaseInfo baseInfo) {
90   - this.baseInfo = baseInfo;
91   - if(baseInfoListener != null){
92   - try {
93   - baseInfoListener.onBaseInfoChange(baseInfo);
94   - }catch (Exception ex){
95   - LogUtil.e(TAG,"onBaseInfoChange",ex);
96   - }
97   - }
98   -
99   - }
100   -
101   - public BaseInfo getBaseInfo() {
102   - return baseInfo;
103   - }
104   -
105   - public void setBaseInfoListener(BaseInfoChanageListener baseInfoListener) {
106   - this.baseInfoListener = baseInfoListener;
107   - }
108   -
109   - private BaseVoteInfo baseVoteInfo;
110   - private BaseVoteInfoChanageListener baseVoteInfoListener;
111   -
112   - public void setBaseVoteInfo(BaseVoteInfo baseVoteInfo) {
113   - this.baseVoteInfo = baseVoteInfo;
114   - if(baseVoteInfoListener != null){
115   - try {
116   - baseVoteInfoListener.onBaseVoteInfoListener(baseVoteInfo);
117   - }catch (Exception ex){
118   - LogUtil.e(TAG,"onBaseVoteInfoListener",ex);
119   - }
120   - }
121   -
122   - }
123   -
124   - public BaseVoteInfo getBaseVoteInfo() {
125   - return baseVoteInfo;
126   - }
127   -
128   - public void setBaseVoteInfoListener(BaseVoteInfoChanageListener baseVoteInfoListener) {
129   - this.baseVoteInfoListener = baseVoteInfoListener;
130   - }
131   -
132   - private KeypadInfo keypadInfo;
133   - private KeyPadinfoChanageListener keyPadinfoChanageListener;
134   -
135   - public void setKeypadInfo(KeypadInfo keypadInfo) {
136   - this.keypadInfo = keypadInfo;
137   - if(keyPadinfoChanageListener != null){
138   - try{
139   - keyPadinfoChanageListener.onKeyPadinfoChanage(keypadInfo);
140   - }catch (Exception ex){
141   - LogUtil.e(TAG,"onKeyPadinfoChanage",ex);
142   - }
143   - }
144   -
145   - }
146   -
147   - public KeypadInfo getKeypadInfo() {
148   - if(keypadInfo == null){
149   - keypadInfo = new KeypadInfo();
150   - }
151   - return keypadInfo;
152   - }
153   -
154   - public void setKeyPadinfoChanageListener(KeyPadinfoChanageListener keyPadinfoChanageListener) {
155   - this.keyPadinfoChanageListener = keyPadinfoChanageListener;
156   - }
157   -
158   - private OnLineInfo onLineInfo;
159   - private OnlineInfoChanageListener onlineInfoChanageListener;
160   -
161   - public void setOnLineInfo(OnLineInfo onLineInfo) {
162   - this.onLineInfo = onLineInfo;
163   - if(onlineInfoChanageListener != null){
164   - try{
165   - onlineInfoChanageListener.onOnlineInfoChanage(onLineInfo);
166   - }catch (Exception ex){
167   - LogUtil.e(TAG,"onOnlineInfoChanage",ex);
168   - }
169   - }
170   - }
171   -
172   - public OnLineInfo getOnLineInfo() {
173   - return onLineInfo;
174   - }
175   -
176   - public void setOnlineInfoChanageListener(OnlineInfoChanageListener onlineInfoChanageListener) {
177   - this.onlineInfoChanageListener = onlineInfoChanageListener;
178   - }
179   -
180   - public void sendPacket(byte[] datas,final OnSendPacket sendPacket){
181   - Packet packet = new Packet();
182   - packet.setDatas(datas);
183   - packet.setSendNo(datas[5] & 0xFF);
184   - packet.setOnSendPacket(new OnSendPacket() {
185   - @Override
186   - public void onSuccess(Packet packet) {
187   - synchronized (lock){
188   - sendList.remove(packet);
189   - }
190   - try{
191   - sendPacket.onSuccess(packet);
192   - }catch (Exception ex){
193   - LogUtil.e(TAG,"sendPacket.onSuccess",ex);
194   - }
195   - }
196   -
197   - @Override
198   - public void onFail(Packet packet) {
199   - synchronized (lock){
200   - sendList.remove(packet);
201   - }
202   - try{
203   - sendPacket.onFail(packet);
204   - }catch (Exception ex){
205   - LogUtil.e(TAG,"sendPacket.onFail",ex);
206   - }
207   - }
208   - });
209   - synchronized (lock){
210   - if(!exsit(packet)){
211   - sendList.add(packet);
212   - }
213   - }
214   - if(service != null){
215   - service.immediately();
216   - }
217   - }
218   -
219   - public List<Packet> getSendList() {
220   - return sendList;
221   - }
222   -
223   - private boolean exsit(Packet packet){
224   - for(Packet packet1: sendList){
225   - if(packet.getSendNo() == packet1.getSendNo()){
226   - return true;
227   - }
228   - }
229   - return false;
230   - }
231   -
232   - public Packet findPacket(int sendNo){
233   - for(Packet packet: sendList){
234   - if(packet.getSendNo() == sendNo){
235   - return packet;
236   - }
237   - }
238   - return null;
239   - }
240   -}
C5/xpadapi/src/main/java/com/sunvote/xpadapi/usb/UsbTransferManager.java deleted
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 deleted
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 deleted
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 deleted
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/res/values/strings.xml deleted
1   -<resources>
2   - <string name="app_name">XpadApi</string>
3   -</resources>
C5/xpadapi/src/test/java/com/sunvote/xpadapi/ExampleUnitTest.java deleted
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   -}
18 0 \ No newline at end of file