Commit 18faef8dfc45003df2b2aefeda7df638ab4b3b11
1 parent
21fdaeae
下载修改
Showing
16 changed files
with
2608 additions
and
2101 deletions
C5/app/build.gradle
@@ -96,6 +96,7 @@ dependencies { | @@ -96,6 +96,7 @@ dependencies { | ||
96 | compile 'com.github.barteksc:android-pdf-viewer:2.7.0' | 96 | compile 'com.github.barteksc:android-pdf-viewer:2.7.0' |
97 | compile 'cn.yipianfengye.android:zxing-library:2.2' | 97 | compile 'cn.yipianfengye.android:zxing-library:2.2' |
98 | compile 'com.jaredrummler:android-processes:1.1.1' | 98 | compile 'com.jaredrummler:android-processes:1.1.1' |
99 | + implementation project(':util') | ||
99 | } | 100 | } |
100 | 101 | ||
101 | //#解决某些输入文件使用或覆盖了已过时的 API | 102 | //#解决某些输入文件使用或覆盖了已过时的 API |
C5/app/src/main/java/com/sunvote/xpadapp/App.java
@@ -5,13 +5,9 @@ import android.app.ActivityManager.RunningAppProcessInfo; | @@ -5,13 +5,9 @@ import android.app.ActivityManager.RunningAppProcessInfo; | ||
5 | import android.app.Application; | 5 | import android.app.Application; |
6 | import android.content.Context; | 6 | import android.content.Context; |
7 | 7 | ||
8 | -import com.sunvote.udptransfer.UDPModule; | ||
9 | -import com.sunvote.udptransfer.work.BaseStationProcessWork; | ||
10 | -import com.sunvote.util.LogUtil; | ||
11 | import com.sunvote.xpadcomm.XPadApi; | 8 | import com.sunvote.xpadcomm.XPadApi; |
12 | import com.uuzuche.lib_zxing.activity.ZXingLibrary; | 9 | import com.uuzuche.lib_zxing.activity.ZXingLibrary; |
13 | 10 | ||
14 | - | ||
15 | import java.util.List; | 11 | import java.util.List; |
16 | 12 | ||
17 | public class App extends Application { | 13 | public class App extends Application { |
@@ -19,20 +15,14 @@ public class App extends Application { | @@ -19,20 +15,14 @@ public class App extends Application { | ||
19 | 15 | ||
20 | @Override | 16 | @Override |
21 | public void onCreate() { | 17 | public void onCreate() { |
22 | - BaseStationProcessWork.getInstance().setContext(this); | ||
23 | XPad = XPadApi.getInstance(); | 18 | XPad = XPadApi.getInstance(); |
24 | // XPad.getClient().disableLogtoFile(); | 19 | // XPad.getClient().disableLogtoFile(); |
25 | // XPad.getClient().disableModuleLog(); | 20 | // XPad.getClient().disableModuleLog(); |
26 | - XPad.getClient().enablelogtoFile(); | ||
27 | - XPad.getClient().enableModuleLog(); | ||
28 | - XPad.getClient().setContext(this); | ||
29 | ZXingLibrary.initDisplayOpinion(this); | 21 | ZXingLibrary.initDisplayOpinion(this); |
30 | final Thread.UncaughtExceptionHandler uncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler(); | 22 | final Thread.UncaughtExceptionHandler uncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler(); |
31 | Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { | 23 | Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { |
32 | @Override | 24 | @Override |
33 | public void uncaughtException(Thread thread, Throwable ex) { | 25 | public void uncaughtException(Thread thread, Throwable ex) { |
34 | - LogUtil.e(UDPModule.TAG, "carsh(thread id:" + thread.getId() + ",thread name:" + thread.getName() + ")"); | ||
35 | - LogUtil.e(UDPModule.TAG, ex); | ||
36 | if (uncaughtExceptionHandler != null) { | 26 | if (uncaughtExceptionHandler != null) { |
37 | uncaughtExceptionHandler.uncaughtException(thread, ex); | 27 | uncaughtExceptionHandler.uncaughtException(thread, ex); |
38 | } | 28 | } |
C5/app/src/main/java/com/sunvote/xpadapp/MainActivity.java
@@ -6,13 +6,14 @@ import android.app.Fragment; | @@ -6,13 +6,14 @@ import android.app.Fragment; | ||
6 | import android.app.FragmentManager; | 6 | import android.app.FragmentManager; |
7 | import android.app.FragmentTransaction; | 7 | import android.app.FragmentTransaction; |
8 | import android.app.ProgressDialog; | 8 | import android.app.ProgressDialog; |
9 | -import android.app.usage.NetworkStats; | ||
10 | import android.content.BroadcastReceiver; | 9 | import android.content.BroadcastReceiver; |
10 | +import android.content.Context; | ||
11 | import android.content.DialogInterface; | 11 | import android.content.DialogInterface; |
12 | import android.content.Intent; | 12 | import android.content.Intent; |
13 | import android.content.IntentFilter; | 13 | import android.content.IntentFilter; |
14 | import android.content.pm.PackageManager; | 14 | import android.content.pm.PackageManager; |
15 | import android.graphics.Color; | 15 | import android.graphics.Color; |
16 | +import android.hardware.usb.UsbManager; | ||
16 | import android.net.ConnectivityManager; | 17 | import android.net.ConnectivityManager; |
17 | import android.net.Uri; | 18 | import android.net.Uri; |
18 | import android.os.Build; | 19 | import android.os.Build; |
@@ -32,7 +33,7 @@ import android.widget.ImageView; | @@ -32,7 +33,7 @@ import android.widget.ImageView; | ||
32 | import android.widget.TextView; | 33 | import android.widget.TextView; |
33 | import android.widget.Toast; | 34 | import android.widget.Toast; |
34 | 35 | ||
35 | -import com.sunvote.udptransfer.Config; | 36 | +import com.sunvote.sdk.HuaWeiSDK; |
36 | import com.sunvote.util.EncryptUtils; | 37 | import com.sunvote.util.EncryptUtils; |
37 | import com.sunvote.util.LogUtil; | 38 | import com.sunvote.util.LogUtil; |
38 | import com.sunvote.util.SPUtils; | 39 | import com.sunvote.util.SPUtils; |
@@ -60,12 +61,11 @@ import com.sunvote.xpadapp.fragments.MultiContentDetailFragment; | @@ -60,12 +61,11 @@ import com.sunvote.xpadapp.fragments.MultiContentDetailFragment; | ||
60 | import com.sunvote.xpadapp.fragments.MultiContentFragment; | 61 | import com.sunvote.xpadapp.fragments.MultiContentFragment; |
61 | import com.sunvote.xpadapp.fragments.MultiPingshengFragment; | 62 | import com.sunvote.xpadapp.fragments.MultiPingshengFragment; |
62 | import com.sunvote.xpadapp.fragments.MultiTitleFragment; | 63 | import com.sunvote.xpadapp.fragments.MultiTitleFragment; |
63 | -import com.sunvote.xpadapp.fragments.ResultElectionCustomFragment; | ||
64 | -import com.sunvote.xpadapp.fragments.UserResultVoteFragment; | ||
65 | import com.sunvote.xpadapp.fragments.NoFileFragment; | 64 | import com.sunvote.xpadapp.fragments.NoFileFragment; |
66 | import com.sunvote.xpadapp.fragments.OfflineFragment; | 65 | import com.sunvote.xpadapp.fragments.OfflineFragment; |
67 | import com.sunvote.xpadapp.fragments.OnLineFragment; | 66 | import com.sunvote.xpadapp.fragments.OnLineFragment; |
68 | import com.sunvote.xpadapp.fragments.PDFContextShowFragment; | 67 | import com.sunvote.xpadapp.fragments.PDFContextShowFragment; |
68 | +import com.sunvote.xpadapp.fragments.ResultElectionCustomFragment; | ||
69 | import com.sunvote.xpadapp.fragments.ResultElectionFragment; | 69 | import com.sunvote.xpadapp.fragments.ResultElectionFragment; |
70 | import com.sunvote.xpadapp.fragments.ResultMultiVoteFragment; | 70 | import com.sunvote.xpadapp.fragments.ResultMultiVoteFragment; |
71 | import com.sunvote.xpadapp.fragments.ResultVoteFragment; | 71 | import com.sunvote.xpadapp.fragments.ResultVoteFragment; |
@@ -73,6 +73,7 @@ import com.sunvote.xpadapp.fragments.ShowIdFragment; | @@ -73,6 +73,7 @@ import com.sunvote.xpadapp.fragments.ShowIdFragment; | ||
73 | import com.sunvote.xpadapp.fragments.SigninFragment; | 73 | import com.sunvote.xpadapp.fragments.SigninFragment; |
74 | import com.sunvote.xpadapp.fragments.SinginResultFragment; | 74 | import com.sunvote.xpadapp.fragments.SinginResultFragment; |
75 | import com.sunvote.xpadapp.fragments.SingleTitleFragment; | 75 | import com.sunvote.xpadapp.fragments.SingleTitleFragment; |
76 | +import com.sunvote.xpadapp.fragments.UserResultVoteFragment; | ||
76 | import com.sunvote.xpadapp.presenter.ServicePresent; | 77 | import com.sunvote.xpadapp.presenter.ServicePresent; |
77 | import com.sunvote.xpadapp.presenter.XPadPresenter; | 78 | import com.sunvote.xpadapp.presenter.XPadPresenter; |
78 | import com.sunvote.xpadapp.server.BatteryReceiver; | 79 | import com.sunvote.xpadapp.server.BatteryReceiver; |
@@ -93,6 +94,7 @@ import com.sunvote.xpadcomm.XPadApiInterface.ModelInfo; | @@ -93,6 +94,7 @@ import com.sunvote.xpadcomm.XPadApiInterface.ModelInfo; | ||
93 | import com.sunvote.xpadcomm.XPadApiInterface.OnLineInfo; | 94 | import com.sunvote.xpadcomm.XPadApiInterface.OnLineInfo; |
94 | import com.sunvote.xpadcomm.XPadApiInterface.VoteInfo; | 95 | import com.sunvote.xpadcomm.XPadApiInterface.VoteInfo; |
95 | import com.sunvote.xpadcomm.XPadSystem; | 96 | import com.sunvote.xpadcomm.XPadSystem; |
97 | +import com.sunvote.xpadcomm.usb.UsbTransferManager; | ||
96 | 98 | ||
97 | import java.io.File; | 99 | import java.io.File; |
98 | import java.io.UnsupportedEncodingException; | 100 | import java.io.UnsupportedEncodingException; |
@@ -219,6 +221,8 @@ public class MainActivity extends BaseActivity implements ComListener { | @@ -219,6 +221,8 @@ public class MainActivity extends BaseActivity implements ComListener { | ||
219 | private TextView terminalId; | 221 | private TextView terminalId; |
220 | private ImageView service; | 222 | private ImageView service; |
221 | 223 | ||
224 | + private final int Msg_onServiceCommitOk = 63; | ||
225 | + | ||
222 | BatteryReceiver m_receiver; | 226 | BatteryReceiver m_receiver; |
223 | NetWorkStateReceiver netWork_receiver; | 227 | NetWorkStateReceiver netWork_receiver; |
224 | StatusBarView statusBarView; | 228 | StatusBarView statusBarView; |
@@ -248,13 +252,17 @@ public class MainActivity extends BaseActivity implements ComListener { | @@ -248,13 +252,17 @@ public class MainActivity extends BaseActivity implements ComListener { | ||
248 | mOnlineInfo.onLine = 0; | 252 | mOnlineInfo.onLine = 0; |
249 | 253 | ||
250 | presenter = new XPadPresenter(this); | 254 | presenter = new XPadPresenter(this); |
251 | - setOnlineFragment(); | 255 | + |
252 | darkTime = (Integer) SharedPreferencesUtil.getData(MainActivity.this, "darkTime", 3); | 256 | darkTime = (Integer) SharedPreferencesUtil.getData(MainActivity.this, "darkTime", 3); |
253 | brigntLevel = (Integer) SharedPreferencesUtil.getData(MainActivity.this, "bright", 30); | 257 | brigntLevel = (Integer) SharedPreferencesUtil.getData(MainActivity.this, "bright", 30); |
254 | ScreenUtil.setNormalMode(MainActivity.this, brigntLevel); | 258 | ScreenUtil.setNormalMode(MainActivity.this, brigntLevel); |
255 | screenTimer = new Timer(true); | 259 | screenTimer = new Timer(true); |
256 | screenTimer.schedule(screenTask, 1000, 1000); // 延时1000ms后执行,1000ms执行一次 | 260 | screenTimer.schedule(screenTask, 1000, 1000); // 延时1000ms后执行,1000ms执行一次 |
257 | 261 | ||
262 | + UsbTransferManager.getInstance().setUsbManager((UsbManager)getSystemService(Context.USB_SERVICE)); | ||
263 | + UsbTransferManager.getInstance().setContext(this); | ||
264 | + UsbTransferManager.getInstance().startWork(); | ||
265 | + | ||
258 | IntentFilter intentFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); | 266 | IntentFilter intentFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); |
259 | m_receiver = new BatteryReceiver(); | 267 | m_receiver = new BatteryReceiver(); |
260 | registerReceiver(m_receiver, intentFilter); | 268 | registerReceiver(m_receiver, intentFilter); |
@@ -266,7 +274,7 @@ public class MainActivity extends BaseActivity implements ComListener { | @@ -266,7 +274,7 @@ public class MainActivity extends BaseActivity implements ComListener { | ||
266 | 274 | ||
267 | clearApkFile(); | 275 | clearApkFile(); |
268 | FirmUpdateFragment.clearUpdateFile(); | 276 | FirmUpdateFragment.clearUpdateFile(); |
269 | - | 277 | + setOnlineFragment(); |
270 | if(!isUnlock()){ | 278 | if(!isUnlock()){ |
271 | setUnlockScreen(); | 279 | setUnlockScreen(); |
272 | } | 280 | } |
@@ -341,6 +349,7 @@ public class MainActivity extends BaseActivity implements ComListener { | @@ -341,6 +349,7 @@ public class MainActivity extends BaseActivity implements ComListener { | ||
341 | int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | 0x00002000; | 349 | int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | 0x00002000; |
342 | decorView.setSystemUiVisibility(uiOptions); | 350 | decorView.setSystemUiVisibility(uiOptions); |
343 | } | 351 | } |
352 | + XPadSystem.setNavgationGone(this); | ||
344 | } | 353 | } |
345 | 354 | ||
346 | public void showBottomUIMenu() { | 355 | public void showBottomUIMenu() { |
@@ -363,7 +372,10 @@ public class MainActivity extends BaseActivity implements ComListener { | @@ -363,7 +372,10 @@ public class MainActivity extends BaseActivity implements ComListener { | ||
363 | @Override | 372 | @Override |
364 | protected void onResume() { | 373 | protected void onResume() { |
365 | hideBottomUIMenu(); | 374 | hideBottomUIMenu(); |
366 | - setTerminalId(XPadApi.getInstance().getClient().getUdpModuleNO()); | 375 | + if(mOnlineInfo != null){ |
376 | + setTerminalId(mOnlineInfo.keyId); | ||
377 | + } | ||
378 | + HuaWeiSDK.getInstance(this).open(); | ||
367 | super.onResume(); | 379 | super.onResume(); |
368 | } | 380 | } |
369 | 381 | ||
@@ -382,6 +394,7 @@ public class MainActivity extends BaseActivity implements ComListener { | @@ -382,6 +394,7 @@ public class MainActivity extends BaseActivity implements ComListener { | ||
382 | protected void onStop() { | 394 | protected void onStop() { |
383 | LogUtil.i(TAG, "onstop"); | 395 | LogUtil.i(TAG, "onstop"); |
384 | XPadSystem.setNavgationVisible(this); | 396 | XPadSystem.setNavgationVisible(this); |
397 | + HuaWeiSDK.getInstance(this).close(); | ||
385 | super.onStop(); | 398 | super.onStop(); |
386 | } | 399 | } |
387 | 400 | ||
@@ -578,6 +591,9 @@ public class MainActivity extends BaseActivity implements ComListener { | @@ -578,6 +591,9 @@ public class MainActivity extends BaseActivity implements ComListener { | ||
578 | case MSG_CLEAN_FILE: | 591 | case MSG_CLEAN_FILE: |
579 | Toast.makeText(MainActivity.this, "文件清除完成!", Toast.LENGTH_SHORT).show(); | 592 | Toast.makeText(MainActivity.this, "文件清除完成!", Toast.LENGTH_SHORT).show(); |
580 | break; | 593 | break; |
594 | + case Msg_onServiceCommitOk: | ||
595 | + servicePresent.onServiceSubmitSuccess(); | ||
596 | + break; | ||
581 | default: | 597 | default: |
582 | 598 | ||
583 | } | 599 | } |
@@ -772,7 +788,7 @@ public class MainActivity extends BaseActivity implements ComListener { | @@ -772,7 +788,7 @@ public class MainActivity extends BaseActivity implements ComListener { | ||
772 | return; | 788 | return; |
773 | } | 789 | } |
774 | currBillInfo = dbm.getBillInfo(meetingId, voteId); | 790 | currBillInfo = dbm.getBillInfo(meetingId, voteId); |
775 | - roleType = dbm.getKeypadRole(XPadApi.getInstance().getClient().getUdpModuleNO()); | 791 | + roleType = dbm.getKeypadRole(mOnlineInfo.keyId); |
776 | if (currBillInfo == null) { | 792 | if (currBillInfo == null) { |
777 | Toast.makeText(this, "显示批次结果失败,没有找到会议资料", Toast.LENGTH_LONG).show(); | 793 | Toast.makeText(this, "显示批次结果失败,没有找到会议资料", Toast.LENGTH_LONG).show(); |
778 | return; | 794 | return; |
@@ -888,6 +904,9 @@ public class MainActivity extends BaseActivity implements ComListener { | @@ -888,6 +904,9 @@ public class MainActivity extends BaseActivity implements ComListener { | ||
888 | private OfflineFragment offlineFragment; | 904 | private OfflineFragment offlineFragment; |
889 | 905 | ||
890 | private void setOfflineFragment() { | 906 | private void setOfflineFragment() { |
907 | + if(mOnlineInfo != null){ | ||
908 | + setTerminalId(mOnlineInfo.keyId); | ||
909 | + } | ||
891 | service.setImageResource(R.drawable.scan_qrcode); | 910 | service.setImageResource(R.drawable.scan_qrcode); |
892 | FragmentManager fm = getFragmentManager(); | 911 | FragmentManager fm = getFragmentManager(); |
893 | FragmentTransaction transaction = fm.beginTransaction(); | 912 | FragmentTransaction transaction = fm.beginTransaction(); |
@@ -925,6 +944,9 @@ public class MainActivity extends BaseActivity implements ComListener { | @@ -925,6 +944,9 @@ public class MainActivity extends BaseActivity implements ComListener { | ||
925 | private OnLineFragment onLineFragment; | 944 | private OnLineFragment onLineFragment; |
926 | 945 | ||
927 | private void setOnlineFragment() { | 946 | private void setOnlineFragment() { |
947 | + if(mOnlineInfo != null){ | ||
948 | + setTerminalId(mOnlineInfo.keyId); | ||
949 | + } | ||
928 | FragmentManager fm = getFragmentManager(); | 950 | FragmentManager fm = getFragmentManager(); |
929 | FragmentTransaction transaction = fm.beginTransaction(); | 951 | FragmentTransaction transaction = fm.beginTransaction(); |
930 | transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); | 952 | transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); |
@@ -939,8 +961,8 @@ public class MainActivity extends BaseActivity implements ComListener { | @@ -939,8 +961,8 @@ public class MainActivity extends BaseActivity implements ComListener { | ||
939 | LogUtil.i(TAG, "setOnlineFragment"); | 961 | LogUtil.i(TAG, "setOnlineFragment"); |
940 | presenter.getBaseStatus(); | 962 | presenter.getBaseStatus(); |
941 | service.setImageResource(R.drawable.service_server); | 963 | service.setImageResource(R.drawable.service_server); |
942 | - Intent intent = new Intent(this,MoniService.class); | ||
943 | - startService(intent); | 964 | +// Intent intent = new Intent(this,MoniService.class); |
965 | +// startService(intent); | ||
944 | } | 966 | } |
945 | 967 | ||
946 | private void setShowIdFragment() { | 968 | private void setShowIdFragment() { |
@@ -1021,21 +1043,21 @@ public class MainActivity extends BaseActivity implements ComListener { | @@ -1021,21 +1043,21 @@ public class MainActivity extends BaseActivity implements ComListener { | ||
1021 | LogUtil.i(TAG, "ignore redownload"); | 1043 | LogUtil.i(TAG, "ignore redownload"); |
1022 | return; | 1044 | return; |
1023 | } | 1045 | } |
1024 | - if (mKeypadInfo == null) { | 1046 | + if (mOnlineInfo == null) { |
1025 | presenter.getKeypadParam(); | 1047 | presenter.getKeypadParam(); |
1026 | } | 1048 | } |
1027 | if (wifiSsid == null || wifiSsid.length() == 0) { | 1049 | if (wifiSsid == null || wifiSsid.length() == 0) { |
1028 | -// Toast.makeText(this, "wifiSsid is null ", Toast.LENGTH_SHORT).show(); | ||
1029 | -// return; | 1050 | + Toast.makeText(this, "wifiSsid is null ", Toast.LENGTH_SHORT).show(); |
1051 | + return; | ||
1030 | } | 1052 | } |
1031 | if (wifiPwd == null || wifiPwd.length() == 0) { | 1053 | if (wifiPwd == null || wifiPwd.length() == 0) { |
1032 | -// Toast.makeText(this, "wifiPwd is null ", Toast.LENGTH_SHORT).show(); | ||
1033 | -// return; | 1054 | + Toast.makeText(this, "wifiPwd is null ", Toast.LENGTH_SHORT).show(); |
1055 | + return; | ||
1034 | } | 1056 | } |
1035 | if (serverIp == null || serverIp.length() == 0) { | 1057 | if (serverIp == null || serverIp.length() == 0) { |
1036 | -// Toast.makeText(this, "serverIp is null ", Toast.LENGTH_SHORT).show(); | ||
1037 | -// return; | ||
1038 | - serverIp = Config.getInstance().serverIP; | 1058 | + Toast.makeText(this, "serverIp is null ", Toast.LENGTH_SHORT).show(); |
1059 | + return; | ||
1060 | +// serverIp = Config.getInstance().serverIP; | ||
1039 | } | 1061 | } |
1040 | // if(serverPort == 0){ | 1062 | // if(serverPort == 0){ |
1041 | // Toast.makeText(this, "serverPort is 0 ", Toast.LENGTH_SHORT); | 1063 | // Toast.makeText(this, "serverPort is 0 ", Toast.LENGTH_SHORT); |
@@ -1047,12 +1069,12 @@ public class MainActivity extends BaseActivity implements ComListener { | @@ -1047,12 +1069,12 @@ public class MainActivity extends BaseActivity implements ComListener { | ||
1047 | if (downloadFragment == null) { | 1069 | if (downloadFragment == null) { |
1048 | downloadFragment = new DownloadFragment(); | 1070 | downloadFragment = new DownloadFragment(); |
1049 | serverPort = 4002; | 1071 | serverPort = 4002; |
1050 | - downloadFragment.setInfo(wifiSsid, wifiPwd, serverIp, serverPort, XPadApi.getInstance().getClient().getUdpModuleNO()); | 1072 | + downloadFragment.setInfo(wifiSsid, wifiPwd, serverIp, serverPort,mOnlineInfo.keyId); |
1051 | transaction.add(R.id.frame_content, downloadFragment); | 1073 | transaction.add(R.id.frame_content, downloadFragment); |
1052 | transaction.addToBackStack("downloadFragment"); | 1074 | transaction.addToBackStack("downloadFragment"); |
1053 | } else { | 1075 | } else { |
1054 | serverPort = 4002; | 1076 | serverPort = 4002; |
1055 | - downloadFragment.setInfo(wifiSsid, wifiPwd, serverIp, serverPort, XPadApi.getInstance().getClient().getUdpModuleNO()); | 1077 | + downloadFragment.setInfo(wifiSsid, wifiPwd, serverIp, serverPort, mOnlineInfo.keyId); |
1056 | transaction.replace(R.id.frame_content, downloadFragment); | 1078 | transaction.replace(R.id.frame_content, downloadFragment); |
1057 | } | 1079 | } |
1058 | transaction.commitAllowingStateLoss(); | 1080 | transaction.commitAllowingStateLoss(); |
@@ -1252,7 +1274,7 @@ public class MainActivity extends BaseActivity implements ComListener { | @@ -1252,7 +1274,7 @@ public class MainActivity extends BaseActivity implements ComListener { | ||
1252 | return; | 1274 | return; |
1253 | } | 1275 | } |
1254 | currBillInfo = dbm.getBillInfo(meetingId, vote.electInfo.voteid); | 1276 | currBillInfo = dbm.getBillInfo(meetingId, vote.electInfo.voteid); |
1255 | - roleType = dbm.getKeypadRole(XPadApi.getInstance().getClient().getUdpModuleNO()); | 1277 | + roleType = dbm.getKeypadRole(mOnlineInfo.keyId); |
1256 | if (currBillInfo == null) { | 1278 | if (currBillInfo == null) { |
1257 | Toast.makeText(this, "没找到议案信息", Toast.LENGTH_LONG).show(); | 1279 | Toast.makeText(this, "没找到议案信息", Toast.LENGTH_LONG).show(); |
1258 | return; | 1280 | return; |
@@ -1365,7 +1387,7 @@ public class MainActivity extends BaseActivity implements ComListener { | @@ -1365,7 +1387,7 @@ public class MainActivity extends BaseActivity implements ComListener { | ||
1365 | } | 1387 | } |
1366 | if (dbm == null || !dbm.checkDB() || dbm.confId != info.confId) { | 1388 | if (dbm == null || !dbm.checkDB() || dbm.confId != info.confId) { |
1367 | dbm = new DBManager(this, info.confId);// 如果没打开,则打开数据库 | 1389 | dbm = new DBManager(this, info.confId);// 如果没打开,则打开数据库 |
1368 | - roleType = dbm.getKeypadRole(XPadApi.getInstance().getClient().getUdpModuleNO()); | 1390 | + roleType = dbm.getKeypadRole(mOnlineInfo.keyId); |
1369 | } | 1391 | } |
1370 | if (!dbm.checkDB()) { | 1392 | if (!dbm.checkDB()) { |
1371 | Message message = new Message(); | 1393 | Message message = new Message(); |
@@ -1376,7 +1398,7 @@ public class MainActivity extends BaseActivity implements ComListener { | @@ -1376,7 +1398,7 @@ public class MainActivity extends BaseActivity implements ComListener { | ||
1376 | } | 1398 | } |
1377 | if (meetingInfo == null || info.billId <= 1) { | 1399 | if (meetingInfo == null || info.billId <= 1) { |
1378 | meetingInfo = dbm.getMettingInfo(info.confId); | 1400 | meetingInfo = dbm.getMettingInfo(info.confId); |
1379 | - roleType = dbm.getKeypadRole(XPadApi.getInstance().getClient().getUdpModuleNO()); | 1401 | + roleType = dbm.getKeypadRole(mOnlineInfo.keyId); |
1380 | } | 1402 | } |
1381 | 1403 | ||
1382 | if (info.billId == 0) { // 没有议案的情况,显示欢迎界面 | 1404 | if (info.billId == 0) { // 没有议案的情况,显示欢迎界面 |
@@ -1495,7 +1517,9 @@ public class MainActivity extends BaseActivity implements ComListener { | @@ -1495,7 +1517,9 @@ public class MainActivity extends BaseActivity implements ComListener { | ||
1495 | if (dbm == null || !dbm.checkDB() ) { | 1517 | if (dbm == null || !dbm.checkDB() ) { |
1496 | dbm = new DBManager(this, this.meetingId);// 如果没打开,则打开数据库 | 1518 | dbm = new DBManager(this, this.meetingId);// 如果没打开,则打开数据库 |
1497 | } | 1519 | } |
1498 | - roleType = dbm.getKeypadRole(XPadApi.getInstance().getClient().getUdpModuleNO()); | 1520 | + if(mOnlineInfo != null){ |
1521 | + roleType = dbm.getKeypadRole(mOnlineInfo.keyId); | ||
1522 | + } | ||
1499 | // voteInfo.voteid = 1;//debug | 1523 | // voteInfo.voteid = 1;//debug |
1500 | if (voteInfo.voteid > 0 && voteInfo.voteid < 255) { | 1524 | if (voteInfo.voteid > 0 && voteInfo.voteid < 255) { |
1501 | try { | 1525 | try { |
@@ -1680,6 +1704,14 @@ public class MainActivity extends BaseActivity implements ComListener { | @@ -1680,6 +1704,14 @@ public class MainActivity extends BaseActivity implements ComListener { | ||
1680 | } | 1704 | } |
1681 | 1705 | ||
1682 | mOnlineInfo = info; | 1706 | mOnlineInfo = info; |
1707 | + runOnUiThread(new Runnable() { | ||
1708 | + @Override | ||
1709 | + public void run() { | ||
1710 | + if(mOnlineInfo != null){ | ||
1711 | + setTerminalId(mOnlineInfo.keyId); | ||
1712 | + } | ||
1713 | + } | ||
1714 | + }); | ||
1683 | XPadSystem.setStatusBarDataIcon(this, info.tx, info.rx); | 1715 | XPadSystem.setStatusBarDataIcon(this, info.tx, info.rx); |
1684 | XPadSystem.setStatusBarChannel(this, info.chan); | 1716 | XPadSystem.setStatusBarChannel(this, info.chan); |
1685 | XPadSystem.setStatusBarBaseId(this, getString(R.string.base_id) + ":" + info.baseId); | 1717 | XPadSystem.setStatusBarBaseId(this, getString(R.string.base_id) + ":" + info.baseId); |
@@ -1742,6 +1774,15 @@ public class MainActivity extends BaseActivity implements ComListener { | @@ -1742,6 +1774,15 @@ public class MainActivity extends BaseActivity implements ComListener { | ||
1742 | LogUtil.i(TAG, "receve 0x32 wifi pwd:" + wifiPwd); | 1774 | LogUtil.i(TAG, "receve 0x32 wifi pwd:" + wifiPwd); |
1743 | break; | 1775 | break; |
1744 | case 0x33: // ip | 1776 | case 0x33: // ip |
1777 | + boolean zero = false; | ||
1778 | + for(int i = 0 ; i < data.length;i++){ | ||
1779 | + if(data[i] == 0 || data[i] == 0x20){ | ||
1780 | + zero = true; | ||
1781 | + } | ||
1782 | + if(zero){ | ||
1783 | + data[i] = 0x20 ; | ||
1784 | + } | ||
1785 | + } | ||
1745 | serverIp = new String(data).trim(); | 1786 | serverIp = new String(data).trim(); |
1746 | LogUtil.i(TAG, "receve 0x33 server ip:" + serverIp); | 1787 | LogUtil.i(TAG, "receve 0x33 server ip:" + serverIp); |
1747 | break; | 1788 | break; |
@@ -1916,6 +1957,11 @@ public class MainActivity extends BaseActivity implements ComListener { | @@ -1916,6 +1957,11 @@ public class MainActivity extends BaseActivity implements ComListener { | ||
1916 | } | 1957 | } |
1917 | 1958 | ||
1918 | @Override | 1959 | @Override |
1960 | + public void onMultiPackageStartDownload(int downType, int downId) { | ||
1961 | + | ||
1962 | + } | ||
1963 | + | ||
1964 | + @Override | ||
1919 | public void onVoteSubmitError(XPadApi.VoteResultItem item) { | 1965 | public void onVoteSubmitError(XPadApi.VoteResultItem item) { |
1920 | Message message = new Message(); | 1966 | Message message = new Message(); |
1921 | message.obj = item; | 1967 | message.obj = item; |
@@ -1987,6 +2033,13 @@ public class MainActivity extends BaseActivity implements ComListener { | @@ -1987,6 +2033,13 @@ public class MainActivity extends BaseActivity implements ComListener { | ||
1987 | // } | 2033 | // } |
1988 | } | 2034 | } |
1989 | 2035 | ||
2036 | + @Override | ||
2037 | + public void onServiceSubmitSuccess() { | ||
2038 | + Message message = new Message(); | ||
2039 | + message.what = Msg_onServiceCommitOk; | ||
2040 | + myHandler.sendMessage(message); | ||
2041 | + } | ||
2042 | + | ||
1990 | private File checkUpdateApkFile() { | 2043 | private File checkUpdateApkFile() { |
1991 | String filePath = Environment.getExternalStorageDirectory().getPath() + "/sunvote/apk/"; | 2044 | String filePath = Environment.getExternalStorageDirectory().getPath() + "/sunvote/apk/"; |
1992 | File file = new File(filePath); | 2045 | File file = new File(filePath); |
@@ -2060,9 +2113,10 @@ public class MainActivity extends BaseActivity implements ComListener { | @@ -2060,9 +2113,10 @@ public class MainActivity extends BaseActivity implements ComListener { | ||
2060 | LogUtil.i(TAG, "showPDFFragment"); | 2113 | LogUtil.i(TAG, "showPDFFragment"); |
2061 | } | 2114 | } |
2062 | 2115 | ||
2116 | + private ServicePresent servicePresent; | ||
2063 | public void showServiceDialog() { | 2117 | public void showServiceDialog() { |
2064 | View servicePanel = findViewById(R.id.service_panel); | 2118 | View servicePanel = findViewById(R.id.service_panel); |
2065 | - final ServicePresent servicePresent = new ServicePresent(this, servicePanel); | 2119 | + servicePresent = new ServicePresent(this, servicePanel); |
2066 | DialogInterface.OnDismissListener dismissListener = new DialogInterface.OnDismissListener() { | 2120 | DialogInterface.OnDismissListener dismissListener = new DialogInterface.OnDismissListener() { |
2067 | @Override | 2121 | @Override |
2068 | public void onDismiss(DialogInterface dialog) { | 2122 | public void onDismiss(DialogInterface dialog) { |
C5/app/src/main/java/com/sunvote/xpadapp/fragments/AdminFragment.java
@@ -17,12 +17,11 @@ import android.widget.ImageButton; | @@ -17,12 +17,11 @@ import android.widget.ImageButton; | ||
17 | import android.widget.TextView; | 17 | import android.widget.TextView; |
18 | import android.widget.Toast; | 18 | import android.widget.Toast; |
19 | 19 | ||
20 | -import com.sunvote.udptransfer.Config; | ||
21 | import com.sunvote.util.LogUtil; | 20 | import com.sunvote.util.LogUtil; |
21 | +import com.sunvote.util.XPadSystem; | ||
22 | import com.sunvote.xpadapp.R; | 22 | import com.sunvote.xpadapp.R; |
23 | import com.sunvote.xpadapp.base.BaseFragment; | 23 | import com.sunvote.xpadapp.base.BaseFragment; |
24 | import com.sunvote.xpadapp.server.MoniService; | 24 | import com.sunvote.xpadapp.server.MoniService; |
25 | -import com.sunvote.xpadcomm.XPadApi; | ||
26 | 25 | ||
27 | public class AdminFragment extends BaseFragment { | 26 | public class AdminFragment extends BaseFragment { |
28 | private TextView tvModalInfo; | 27 | private TextView tvModalInfo; |
@@ -31,6 +30,7 @@ public class AdminFragment extends BaseFragment { | @@ -31,6 +30,7 @@ public class AdminFragment extends BaseFragment { | ||
31 | private Button btnConfig; | 30 | private Button btnConfig; |
32 | private Button btnPowerOff; | 31 | private Button btnPowerOff; |
33 | private Button btnComTest; | 32 | private Button btnComTest; |
33 | + private Button match; | ||
34 | 34 | ||
35 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | 35 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
36 | View view = inflater.inflate(R.layout.fragment_admin, container, false); | 36 | View view = inflater.inflate(R.layout.fragment_admin, container, false); |
@@ -40,8 +40,9 @@ public class AdminFragment extends BaseFragment { | @@ -40,8 +40,9 @@ public class AdminFragment extends BaseFragment { | ||
40 | btnBack = view.findViewById(R.id.admin_btnback); | 40 | btnBack = view.findViewById(R.id.admin_btnback); |
41 | btnConfig = view.findViewById(R.id.admin_config_mode); | 41 | btnConfig = view.findViewById(R.id.admin_config_mode); |
42 | btnPowerOff = view.findViewById(R.id.admin_btnShutdown); | 42 | btnPowerOff = view.findViewById(R.id.admin_btnShutdown); |
43 | + match = view.findViewById(R.id.match); | ||
43 | 44 | ||
44 | - tvModalInfo.setText(getString(R.string.app_version) + getVersionName() + " "+ getString(R.string.server_ip) + Config.getInstance().serverIP); | 45 | + tvModalInfo.setText(getString(R.string.app_version) + getVersionName()); |
45 | btnBack.setOnClickListener(new OnClickListener() { | 46 | btnBack.setOnClickListener(new OnClickListener() { |
46 | @Override | 47 | @Override |
47 | public void onClick(View v) { | 48 | public void onClick(View v) { |
@@ -58,13 +59,19 @@ public class AdminFragment extends BaseFragment { | @@ -58,13 +59,19 @@ public class AdminFragment extends BaseFragment { | ||
58 | 59 | ||
59 | } | 60 | } |
60 | }); | 61 | }); |
62 | + match.setOnClickListener(new OnClickListener() { | ||
63 | + @Override | ||
64 | + public void onClick(View v) { | ||
65 | + mMainActivity.presenter.execKeypadMatch(0, 0); | ||
66 | + } | ||
67 | + }); | ||
61 | btnPowerOff.setOnClickListener(new OnClickListener() { | 68 | btnPowerOff.setOnClickListener(new OnClickListener() { |
62 | 69 | ||
63 | @Override | 70 | @Override |
64 | public void onClick(View v) { | 71 | public void onClick(View v) { |
65 | AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); | 72 | AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); |
66 | - builder.setMessage("确认要退出应用吗?"); | ||
67 | - builder.setTitle("退出应用"); | 73 | + builder.setMessage("确认关机吗?"); |
74 | + builder.setTitle("退出关机"); | ||
68 | builder.setPositiveButton("确认", new DialogInterface.OnClickListener() { | 75 | builder.setPositiveButton("确认", new DialogInterface.OnClickListener() { |
69 | 76 | ||
70 | @Override | 77 | @Override |
@@ -72,7 +79,8 @@ public class AdminFragment extends BaseFragment { | @@ -72,7 +79,8 @@ public class AdminFragment extends BaseFragment { | ||
72 | dialog.dismiss(); | 79 | dialog.dismiss(); |
73 | Intent intent = new Intent(getActivity(),MoniService.class); | 80 | Intent intent = new Intent(getActivity(),MoniService.class); |
74 | getActivity().stopService(intent); | 81 | getActivity().stopService(intent); |
75 | - getActivity().finish(); | 82 | +// getActivity().finish(); |
83 | + com.sunvote.xpadcomm.XPadSystem.powerOffXPad(getActivity()); | ||
76 | } | 84 | } |
77 | }); | 85 | }); |
78 | builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { | 86 | builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { |
@@ -92,8 +100,30 @@ public class AdminFragment extends BaseFragment { | @@ -92,8 +100,30 @@ public class AdminFragment extends BaseFragment { | ||
92 | 100 | ||
93 | @Override | 101 | @Override |
94 | public void onClick(View v) { | 102 | public void onClick(View v) { |
95 | - XPadApi.getInstance().getClient().searchServarIp(); | ||
96 | - Toast.makeText(getActivity(),"如果服务器IP地址变化,则自动转化一次",Toast.LENGTH_SHORT).show(); | 103 | +// Toast.makeText(getActivity(),"如果服务器IP地址变化,则自动转化一次",Toast.LENGTH_SHORT).show(); |
104 | + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); | ||
105 | + builder.setMessage("确认要退出应用吗?"); | ||
106 | + builder.setTitle("退出应用"); | ||
107 | + builder.setPositiveButton("确认", new DialogInterface.OnClickListener() { | ||
108 | + | ||
109 | + @Override | ||
110 | + public void onClick(DialogInterface dialog, int which) { | ||
111 | + dialog.dismiss(); | ||
112 | + Intent intent = new Intent(getActivity(),MoniService.class); | ||
113 | + getActivity().stopService(intent); | ||
114 | + getActivity().finish(); | ||
115 | + com.sunvote.xpadcomm.XPadSystem.setNavgationVisible(getActivity()); | ||
116 | +// com.sunvote.xpadcomm.XPadSystem.powerOffXPad(getActivity()); | ||
117 | + } | ||
118 | + }); | ||
119 | + builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { | ||
120 | + | ||
121 | + @Override | ||
122 | + public void onClick(DialogInterface dialog, int which) { | ||
123 | + dialog.dismiss(); | ||
124 | + } | ||
125 | + }); | ||
126 | + builder.create().show(); | ||
97 | } | 127 | } |
98 | }); | 128 | }); |
99 | 129 |
C5/app/src/main/java/com/sunvote/xpadapp/fragments/KeypadTestFragment.java
1 | package com.sunvote.xpadapp.fragments; | 1 | package com.sunvote.xpadapp.fragments; |
2 | 2 | ||
3 | -import com.sunvote.udptransfer.Config; | ||
4 | -import com.sunvote.util.LogUtil; | ||
5 | -import com.sunvote.xpadapp.R; | ||
6 | -import com.sunvote.xpadapp.base.SuperBaseFragment; | ||
7 | - | ||
8 | import android.app.FragmentManager; | 3 | import android.app.FragmentManager; |
9 | import android.app.FragmentTransaction; | 4 | import android.app.FragmentTransaction; |
10 | import android.content.pm.PackageInfo; | 5 | import android.content.pm.PackageInfo; |
@@ -12,11 +7,15 @@ import android.content.pm.PackageManager; | @@ -12,11 +7,15 @@ import android.content.pm.PackageManager; | ||
12 | import android.os.Bundle; | 7 | import android.os.Bundle; |
13 | import android.view.LayoutInflater; | 8 | import android.view.LayoutInflater; |
14 | import android.view.View; | 9 | import android.view.View; |
15 | -import android.view.ViewGroup; | ||
16 | import android.view.View.OnClickListener; | 10 | import android.view.View.OnClickListener; |
11 | +import android.view.ViewGroup; | ||
17 | import android.widget.ImageButton; | 12 | import android.widget.ImageButton; |
18 | import android.widget.TextView; | 13 | import android.widget.TextView; |
19 | 14 | ||
15 | +import com.sunvote.util.LogUtil; | ||
16 | +import com.sunvote.xpadapp.R; | ||
17 | +import com.sunvote.xpadapp.base.SuperBaseFragment; | ||
18 | + | ||
20 | public class KeypadTestFragment extends SuperBaseFragment { | 19 | public class KeypadTestFragment extends SuperBaseFragment { |
21 | private TextView tvId; | 20 | private TextView tvId; |
22 | private TextView tvSn; | 21 | private TextView tvSn; |
C5/app/src/main/java/com/sunvote/xpadapp/presenter/ServicePresent.java
@@ -2,33 +2,23 @@ package com.sunvote.xpadapp.presenter; | @@ -2,33 +2,23 @@ package com.sunvote.xpadapp.presenter; | ||
2 | 2 | ||
3 | import android.content.Context; | 3 | import android.content.Context; |
4 | import android.content.DialogInterface; | 4 | import android.content.DialogInterface; |
5 | -import android.os.Looper; | 5 | +import android.util.Log; |
6 | import android.view.LayoutInflater; | 6 | import android.view.LayoutInflater; |
7 | import android.view.View; | 7 | import android.view.View; |
8 | import android.widget.ImageView; | 8 | import android.widget.ImageView; |
9 | 9 | ||
10 | -import com.sunvote.cmd.BaseCmd; | ||
11 | -import com.sunvote.cmd.ICmd; | ||
12 | -import com.sunvote.cmd.state.GetPkgStateResponse; | ||
13 | -import com.sunvote.cmd.upload.SingerUploadPkg; | ||
14 | -import com.sunvote.cmd.upload.TransferResult; | ||
15 | -import com.sunvote.protocal.Protocol; | ||
16 | -import com.sunvote.udptransfer.UDPModule; | ||
17 | -import com.sunvote.udptransfer.work.BaseStationProcessWork; | ||
18 | -import com.sunvote.udptransfer.work.SDKProcessWork; | 10 | +import com.sunvote.util.LogUtil; |
19 | import com.sunvote.xpadapp.MainActivity; | 11 | import com.sunvote.xpadapp.MainActivity; |
20 | import com.sunvote.xpadapp.R; | 12 | import com.sunvote.xpadapp.R; |
21 | import com.sunvote.xpadcomm.XPadApi; | 13 | import com.sunvote.xpadcomm.XPadApi; |
22 | 14 | ||
23 | -import java.util.logging.Handler; | ||
24 | - | ||
25 | /** | 15 | /** |
26 | * Created by XXW on 2017/11/7. | 16 | * Created by XXW on 2017/11/7. |
27 | */ | 17 | */ |
28 | 18 | ||
29 | public class ServicePresent implements View.OnClickListener{ | 19 | public class ServicePresent implements View.OnClickListener{ |
30 | 20 | ||
31 | - private Context context; | 21 | + public MainActivity mMainActivity; |
32 | 22 | ||
33 | private View paper_linear; | 23 | private View paper_linear; |
34 | private View pen_linear; | 24 | private View pen_linear; |
@@ -59,6 +49,7 @@ public class ServicePresent implements View.OnClickListener{ | @@ -59,6 +49,7 @@ public class ServicePresent implements View.OnClickListener{ | ||
59 | private boolean technology; | 49 | private boolean technology; |
60 | 50 | ||
61 | private static byte reqpos = 1 ; | 51 | private static byte reqpos = 1 ; |
52 | + private byte selType; | ||
62 | 53 | ||
63 | private DialogInterface.OnDismissListener dismissListener; | 54 | private DialogInterface.OnDismissListener dismissListener; |
64 | 55 | ||
@@ -70,14 +61,14 @@ public class ServicePresent implements View.OnClickListener{ | @@ -70,14 +61,14 @@ public class ServicePresent implements View.OnClickListener{ | ||
70 | this.dismissListener = dismissListener; | 61 | this.dismissListener = dismissListener; |
71 | } | 62 | } |
72 | 63 | ||
73 | - public ServicePresent(Context context) { | ||
74 | - this.context = context; | 64 | + public ServicePresent(MainActivity context) { |
65 | + this.mMainActivity = context; | ||
75 | rootView = LayoutInflater.from(context).inflate(R.layout.dialog_service,null); | 66 | rootView = LayoutInflater.from(context).inflate(R.layout.dialog_service,null); |
76 | init(); | 67 | init(); |
77 | } | 68 | } |
78 | 69 | ||
79 | - public ServicePresent(Context context,View rootView) { | ||
80 | - this.context = context; | 70 | + public ServicePresent(MainActivity context,View rootView) { |
71 | + this.mMainActivity = context; | ||
81 | this.rootView = rootView; | 72 | this.rootView = rootView; |
82 | init(); | 73 | init(); |
83 | } | 74 | } |
@@ -137,7 +128,6 @@ public class ServicePresent implements View.OnClickListener{ | @@ -137,7 +128,6 @@ public class ServicePresent implements View.OnClickListener{ | ||
137 | technology_linear.setOnClickListener(this); | 128 | technology_linear.setOnClickListener(this); |
138 | submit.setOnClickListener(this); | 129 | submit.setOnClickListener(this); |
139 | initAdmin(); | 130 | initAdmin(); |
140 | - SDKProcessWork.getInstance().registerOnReceiveCmdListener(receiveCmdListener); | ||
141 | } | 131 | } |
142 | 132 | ||
143 | private void initAdmin(){ | 133 | private void initAdmin(){ |
@@ -151,8 +141,8 @@ public class ServicePresent implements View.OnClickListener{ | @@ -151,8 +141,8 @@ public class ServicePresent implements View.OnClickListener{ | ||
151 | clickCount ++ ; | 141 | clickCount ++ ; |
152 | if(clickCount >= 5){ | 142 | if(clickCount >= 5){ |
153 | clickCount = 0 ; | 143 | clickCount = 0 ; |
154 | - if(context instanceof MainActivity){ | ||
155 | - ((MainActivity)context).showAdmin(); | 144 | + if(mMainActivity instanceof MainActivity){ |
145 | + ((MainActivity)mMainActivity).showAdmin(); | ||
156 | } | 146 | } |
157 | } | 147 | } |
158 | } | 148 | } |
@@ -285,43 +275,16 @@ public class ServicePresent implements View.OnClickListener{ | @@ -285,43 +275,16 @@ public class ServicePresent implements View.OnClickListener{ | ||
285 | 275 | ||
286 | public void dismiss(){ | 276 | public void dismiss(){ |
287 | rootView.setVisibility(View.GONE); | 277 | rootView.setVisibility(View.GONE); |
288 | - destroy(); | ||
289 | } | 278 | } |
290 | 279 | ||
291 | 280 | ||
292 | public void sendServiceCmd(final byte type){ | 281 | public void sendServiceCmd(final byte type){ |
293 | - SingerUploadPkg singerUploadPkg = new SingerUploadPkg(); | ||
294 | - singerUploadPkg.setKeyid(BaseStationProcessWork.getInstance().getBaseStationInfo().getKeyId()); | ||
295 | - singerUploadPkg.setAnstype((byte)33); | ||
296 | - singerUploadPkg.getAnsdata()[0] = 4; | ||
297 | - singerUploadPkg.getAnsdata()[1] = type; | ||
298 | - singerUploadPkg.getAnsdata()[2] = ++reqpos; | ||
299 | - final Protocol<SingerUploadPkg> protocal = new Protocol(); | ||
300 | - protocal.setEnableMatchCode(false); | ||
301 | - protocal.setCmd(singerUploadPkg); | ||
302 | - receiveCmdListener.type = type; | ||
303 | - SDKProcessWork.getInstance().execute(protocal); | 282 | + LogUtil.d("ServicePresent", "sendServiceCmd: type:"+ type); |
283 | + selType = type; | ||
284 | + mMainActivity.presenter.submitVote(XPadApi.AnsType_Service,String.valueOf(type)); | ||
304 | } | 285 | } |
305 | - | ||
306 | - class ReceiveCmdListener implements SDKProcessWork.OnReceiveCmdListener{ | ||
307 | - | ||
308 | - public byte type ; | ||
309 | - @Override | ||
310 | - public void onReceiver(Protocol protocol1) { | ||
311 | - ICmd cmd = protocol1.getCmd(); | ||
312 | - if(cmd instanceof GetPkgStateResponse || cmd instanceof TransferResult){ | ||
313 | - new android.os.Handler(Looper.getMainLooper()).post(new Runnable() { | ||
314 | - @Override | ||
315 | - public void run() { | ||
316 | - refreash(type); | ||
317 | - } | ||
318 | - }); | ||
319 | - } | ||
320 | - } | 286 | + public void onServiceSubmitSuccess(){ |
287 | + refreash(selType); | ||
321 | } | 288 | } |
322 | - private ReceiveCmdListener receiveCmdListener = new ReceiveCmdListener(); | ||
323 | 289 | ||
324 | - public void destroy(){ | ||
325 | - SDKProcessWork.getInstance().unregisterOnReceiveCmdListener(receiveCmdListener); | ||
326 | - } | ||
327 | } | 290 | } |
C5/app/src/main/java/com/sunvote/xpadapp/presenter/XPadPresenter.java
@@ -220,6 +220,11 @@ public class XPadPresenter implements ComListener { | @@ -220,6 +220,11 @@ public class XPadPresenter implements ComListener { | ||
220 | } | 220 | } |
221 | 221 | ||
222 | @Override | 222 | @Override |
223 | + public void onMultiPackageStartDownload(int downType, int downId) { | ||
224 | + | ||
225 | + } | ||
226 | + | ||
227 | + @Override | ||
223 | public void onVoteSubmitAllOkSuccess() { | 228 | public void onVoteSubmitAllOkSuccess() { |
224 | cl.onVoteSubmitAllOkSuccess(); | 229 | cl.onVoteSubmitAllOkSuccess(); |
225 | } | 230 | } |
@@ -229,6 +234,11 @@ public class XPadPresenter implements ComListener { | @@ -229,6 +234,11 @@ public class XPadPresenter implements ComListener { | ||
229 | cl.onComCommunicationTest(sendn,checkOk); | 234 | cl.onComCommunicationTest(sendn,checkOk); |
230 | } | 235 | } |
231 | 236 | ||
237 | + @Override | ||
238 | + public void onServiceSubmitSuccess() { | ||
239 | + | ||
240 | + } | ||
241 | + | ||
232 | private IntentFilter batteryLevelFilter; | 242 | private IntentFilter batteryLevelFilter; |
233 | 243 | ||
234 | private void monitorBatteryState() { | 244 | private void monitorBatteryState() { |
C5/app/src/main/java/com/sunvote/xpadcomm/ComListener.java
@@ -14,17 +14,20 @@ public interface ComListener { | @@ -14,17 +14,20 @@ public interface ComListener { | ||
14 | public void onModelEvent(ModelInfo info); | 14 | public void onModelEvent(ModelInfo info); |
15 | public void onBaseEvent( BaseInfo info); | 15 | public void onBaseEvent( BaseInfo info); |
16 | public void onVoteEvent(VoteInfo info); | 16 | public void onVoteEvent(VoteInfo info); |
17 | - public void onVoteSubmitSuccess(XPadApi.VoteResultItem voteResultItem); | ||
18 | - public void onVoteSubmitError(XPadApi.VoteResultItem voteResultItem); | 17 | + public void onVoteSubmitSuccess(XPadApi.VoteResultItem item); |
18 | + public void onVoteSubmitError(XPadApi.VoteResultItem item); | ||
19 | public void onVoteSubmitAllOkSuccess(); | 19 | public void onVoteSubmitAllOkSuccess(); |
20 | public void onKeyPadEvent(KeypadInfo info); | 20 | public void onKeyPadEvent(KeypadInfo info); |
21 | public void onOnLineEvent(OnLineInfo info); | 21 | public void onOnLineEvent(OnLineInfo info); |
22 | public void onCmdData(CmdDataInfo info); | 22 | public void onCmdData(CmdDataInfo info); |
23 | public void onMultiPackageData(byte[] data, int len); | 23 | public void onMultiPackageData(byte[] data, int len); |
24 | + public void onMultiPackageStartDownload(int downType,int downId);//进入下载状态 | ||
24 | 25 | ||
25 | public void onFirmUpdate(int percent); | 26 | public void onFirmUpdate(int percent); |
26 | public void onFirmUpdateResult(boolean success , String msg); | 27 | public void onFirmUpdateResult(boolean success , String msg); |
27 | public void onFirmUpdateInfo(String info); | 28 | public void onFirmUpdateInfo(String info); |
28 | 29 | ||
29 | public void onComCommunicationTest(int sendn,boolean checkOk); | 30 | public void onComCommunicationTest(int sendn,boolean checkOk); |
31 | + public void onServiceSubmitSuccess(); | ||
32 | + | ||
30 | } | 33 | } |
C5/app/src/main/java/com/sunvote/xpadcomm/DownloadFileModule.java
@@ -229,23 +229,7 @@ public class DownloadFileModule { | @@ -229,23 +229,7 @@ public class DownloadFileModule { | ||
229 | } | 229 | } |
230 | 230 | ||
231 | private void sendNextData(byte type ,int index) { | 231 | private void sendNextData(byte type ,int index) { |
232 | - byte[] buffer = new byte[10]; | ||
233 | - buffer[0] = (byte) 0xFE; | ||
234 | - buffer[1] = (byte) 0xAA; | ||
235 | - buffer[2] = flag; | ||
236 | - buffer[3] = type;// | ||
237 | - buffer[4] = (byte) ((index >> 8) & 0xff); | ||
238 | - buffer[5] = (byte) (index & 0xff); | ||
239 | - if (servInetAddress == null) { | ||
240 | - try { | ||
241 | - servInetAddress = InetAddress.getByName(ip); | ||
242 | - } catch (Exception e) { | ||
243 | - LogUtil.e(TAG, e); | ||
244 | - } | ||
245 | - } | ||
246 | - LogUtil.i(TAG,"sendNextData",buffer); | ||
247 | - DatagramPacket packet = new DatagramPacket(buffer, buffer.length, servInetAddress, this.port); | ||
248 | - downloadFileSendThread.sendData(packet); | 232 | + downloadFileSendThread.sendData(flag,type,index,ip,port); |
249 | } | 233 | } |
250 | 234 | ||
251 | public void createAndCleanFolder(String folderName) { | 235 | public void createAndCleanFolder(String folderName) { |
C5/app/src/main/java/com/sunvote/xpadcomm/DownloadFileSendThread.java
@@ -6,6 +6,7 @@ import android.os.HandlerThread; | @@ -6,6 +6,7 @@ import android.os.HandlerThread; | ||
6 | import java.io.IOException; | 6 | import java.io.IOException; |
7 | import java.net.DatagramPacket; | 7 | import java.net.DatagramPacket; |
8 | import java.net.DatagramSocket; | 8 | import java.net.DatagramSocket; |
9 | +import java.net.InetAddress; | ||
9 | import java.net.SocketException; | 10 | import java.net.SocketException; |
10 | 11 | ||
11 | import com.sunvote.util.LogUtil; | 12 | import com.sunvote.util.LogUtil; |
@@ -31,10 +32,30 @@ public class DownloadFileSendThread extends HandlerThread { | @@ -31,10 +32,30 @@ public class DownloadFileSendThread extends HandlerThread { | ||
31 | handler = new Handler(getLooper()); | 32 | handler = new Handler(getLooper()); |
32 | } | 33 | } |
33 | 34 | ||
34 | - public boolean sendData(DatagramPacket packet){ | ||
35 | - this.packet = packet; | ||
36 | - handler.removeCallbacks(task); | ||
37 | - handler.post(task); | 35 | + public boolean sendData(final byte flag,final byte type,final int index,final String ip,final int port){ |
36 | + handler.post(new Runnable() { | ||
37 | + @Override | ||
38 | + public void run() { | ||
39 | + byte[] buffer = new byte[10]; | ||
40 | + buffer[0] = (byte) 0xFE; | ||
41 | + buffer[1] = (byte) 0xAA; | ||
42 | + buffer[2] = flag; | ||
43 | + buffer[3] = type;// | ||
44 | + buffer[4] = (byte) ((index >> 8) & 0xff); | ||
45 | + buffer[5] = (byte) (index & 0xff); | ||
46 | + InetAddress servInetAddress; | ||
47 | + try { | ||
48 | + servInetAddress = InetAddress.getByName(ip); | ||
49 | + } catch (Exception e) { | ||
50 | + LogUtil.e(TAG, e); | ||
51 | + return ; | ||
52 | + } | ||
53 | + LogUtil.i(TAG,"sendNextData",buffer); | ||
54 | + packet = new DatagramPacket(buffer, buffer.length, servInetAddress, port); | ||
55 | + handler.removeCallbacks(task); | ||
56 | + handler.post(task); | ||
57 | + } | ||
58 | + }); | ||
38 | return true; | 59 | return true; |
39 | } | 60 | } |
40 | 61 |
C5/app/src/main/java/com/sunvote/xpadcomm/XPadApi.java
@@ -5,1836 +5,2260 @@ import android.os.Handler; | @@ -5,1836 +5,2260 @@ import android.os.Handler; | ||
5 | import android.os.HandlerThread; | 5 | import android.os.HandlerThread; |
6 | import android.util.Log; | 6 | import android.util.Log; |
7 | 7 | ||
8 | -import com.sunvote.udptransfer.UDPModule; | ||
9 | -import com.sunvote.udptransfer.stream.SunVoteInputStream; | 8 | +import com.sunvote.util.ByteUtils; |
10 | import com.sunvote.util.LogUtil; | 9 | import com.sunvote.util.LogUtil; |
10 | +import com.sunvote.xpadcomm.usb.UsbTransferManager; | ||
11 | 11 | ||
12 | +import java.io.ByteArrayOutputStream; | ||
13 | +import java.io.File; | ||
14 | +import java.io.FileOutputStream; | ||
12 | import java.io.IOException; | 15 | import java.io.IOException; |
16 | +import java.io.InputStream; | ||
13 | import java.io.OutputStream; | 17 | import java.io.OutputStream; |
14 | import java.io.UnsupportedEncodingException; | 18 | import java.io.UnsupportedEncodingException; |
19 | +import java.security.InvalidParameterException; | ||
15 | import java.util.ArrayList; | 20 | import java.util.ArrayList; |
16 | import java.util.Arrays; | 21 | import java.util.Arrays; |
22 | +import java.util.Collections; | ||
17 | import java.util.Iterator; | 23 | import java.util.Iterator; |
18 | - | 24 | +import java.util.List; |
19 | 25 | ||
20 | public class XPadApi implements XPadApiInterface { | 26 | public class XPadApi implements XPadApiInterface { |
21 | - private static String TAG = "XPadApi"; | ||
22 | - private ComListener m_listener; | ||
23 | - private static XPadApi m_xpadApi = null; | ||
24 | - | ||
25 | - private OutputStream mOutputStream; | ||
26 | - private SunVoteInputStream mInputStream; | ||
27 | - private ReadThread mReadThread; | ||
28 | - private ArrayList<VoteResultItem> sendQueen = new ArrayList<VoteResultItem>(); | ||
29 | - private int serialNumber; | ||
30 | - private int allOkSerialNumber; | 27 | + private static String TAG = "XPadApi"; |
28 | + private ComListener m_listener; | ||
29 | + private static XPadApi m_xpadApi = null; | ||
31 | 30 | ||
32 | - private boolean isShowLog = true; | ||
33 | - private boolean isShowOnlineLog = false; | 31 | + private OutputStream mOutputStream; |
32 | + private InputStream mInputStream; | ||
33 | + private ReadThread mReadThread; | ||
34 | + private List<VoteResultItem> sendQueen = Collections.synchronizedList(new ArrayList<VoteResultItem>());//new ArrayList<VoteResultItem>(); | ||
35 | + private volatile int serialNumber; | ||
36 | + private int allOkSerialNumber; | ||
37 | + private int serviceSerialNumber; | ||
34 | 38 | ||
35 | - private OnLineInfo onLineInfo; | ||
36 | - // private boolean hasGetBaseInfo = false; | 39 | + private boolean isShowLog = true; |
40 | + private boolean isShowOnlineLog = false; | ||
37 | 41 | ||
38 | - private UDPModule client ; | 42 | + private OnLineInfo onLineInfo = new OnLineInfo(); |
43 | + private KeypadInfo info = new KeypadInfo(); | ||
44 | + private HandlerThread receiverThread = new HandlerThread("rea"); | ||
45 | + private HandlerThread sendThread = new HandlerThread("send"); | ||
46 | + private Handler taskHandler = null; | ||
47 | + private byte[] baseSign ; | ||
48 | + private byte[] voteSign ; | ||
39 | 49 | ||
40 | - private int writeFrimPageErrCnt = 0; | 50 | + // private boolean hasGetBaseInfo = false; |
41 | 51 | ||
42 | - private HandlerThread sendThread = new HandlerThread("send"); | ||
43 | - private Handler taskHandler = null; | 52 | + private int writeFrimPageErrCnt = 0; |
44 | 53 | ||
45 | - // public SerialPortFinder mSerialPortFinder = new SerialPortFinder(); | 54 | + // public SerialPortFinder mSerialPortFinder = new SerialPortFinder(); |
46 | 55 | ||
47 | - public synchronized static XPadApi getInstance() { | ||
48 | - if (m_xpadApi == null) { | ||
49 | - m_xpadApi = new XPadApi(); | ||
50 | - m_xpadApi.init(); | ||
51 | - } | ||
52 | - return m_xpadApi; | ||
53 | - } | ||
54 | 56 | ||
55 | - public XPadApi() { | ||
56 | - sendThread.start(); | ||
57 | - taskHandler = new Handler(sendThread.getLooper()); | ||
58 | - } | ||
59 | 57 | ||
60 | - public void init() { | ||
61 | - try { | ||
62 | - allOkSerialNumber = -1; | ||
63 | -// mSerialPort = getSerialPort(); | ||
64 | -// mOutputStream = mSerialPort.getOutputStream(); | ||
65 | -// mInputStream = mSerialPort.getInputStream(); | 58 | + private XPadApi(){ |
59 | + sendThread.start(); | ||
60 | + taskHandler = new Handler(sendThread.getLooper()); | ||
61 | + } | ||
66 | 62 | ||
67 | - client = new UDPModule(); | 63 | + public synchronized static XPadApi getInstance() { |
64 | + if (m_xpadApi == null) { | ||
65 | + m_xpadApi = new XPadApi(); | ||
66 | + m_xpadApi.init(); | ||
67 | + } | ||
68 | + return m_xpadApi; | ||
69 | + } | ||
68 | 70 | ||
69 | - mOutputStream = client.getOutputStream(); | ||
70 | - mInputStream = client.getInputStream(); | ||
71 | - mInputStream.setOnBytesReceiver(new SunVoteInputStream.OnBytesReceiver() { | 71 | + public void init() { |
72 | + try { | ||
73 | + LogUtil.d(TAG, "XPadApi.init()"); | ||
74 | + allOkSerialNumber = -1; | ||
75 | + serviceSerialNumber = -1; | ||
76 | +// mSerialPort = getSerialPort(); | ||
77 | +// module = new UDPModule(); | ||
78 | +// mOutputStream = module.getOutputStream(); | ||
79 | +// mInputStream = module.getInputStream(); | ||
80 | +// mOutputStream = mSerialPort.getOutputStream(); | ||
81 | +// mInputStream = mSerialPort.getInputStream(); | ||
82 | + UsbTransferManager.getInstance().setOnUsbConnectListener(new UsbTransferManager.OnUsbConnectListener() { | ||
72 | @Override | 83 | @Override |
73 | - public void onBytesReceiver(byte[] datas, int length) { | ||
74 | -// int rxDataLen = datas[3] + 4;// len | ||
75 | -// checkComData(datas,length); | ||
76 | - LogUtil.i(TAG,"xpadapi rec:" ,datas); | ||
77 | -// dowith(datas,length); | ||
78 | - checkComData(datas,length); | 84 | + public boolean onConnect(boolean isConnected) { |
85 | + if(isConnected){ | ||
86 | + byte[] mBuffer = new byte[0x1F + 4]; | ||
87 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
88 | + mBuffer[0] = (byte) 0xF5; | ||
89 | + mBuffer[1] = (byte) 0xAA; | ||
90 | + mBuffer[2] = (byte) 0xAA; | ||
91 | + mBuffer[3] = (byte) 0x1F; | ||
92 | + | ||
93 | + mBuffer[4] = 0x70; | ||
94 | + mBuffer[5] = 0x03; | ||
95 | + writeToCom(mBuffer); | ||
96 | + } | ||
97 | + try { | ||
98 | + Thread.sleep(100); | ||
99 | + } catch (InterruptedException e) { | ||
100 | + e.printStackTrace(); | ||
101 | + } | ||
102 | + byte[] mBuffer = new byte[0x1F + 4]; | ||
103 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
104 | + mBuffer[0] = (byte) 0xF5; | ||
105 | + mBuffer[1] = (byte) 0xAA; | ||
106 | + mBuffer[2] = (byte) 0xAA; | ||
107 | + mBuffer[3] = (byte) 0x1F; | ||
108 | + | ||
109 | + mBuffer[4] = 0x70; | ||
110 | + mBuffer[5] = 0x04; | ||
111 | + writeToCom(mBuffer); | ||
112 | + return true; | ||
79 | } | 113 | } |
80 | }); | 114 | }); |
81 | - Arrays.fill(broadcastData, (byte) 0x0);// 清空多包结果 | 115 | + mOutputStream = UsbTransferManager.getInstance().getOutputStream(); |
116 | + mInputStream = UsbTransferManager.getInstance().getInputStream(); | ||
117 | + | ||
118 | + Arrays.fill(broadcastData, (byte) 0x0);// 清空多包结果 | ||
82 | 119 | ||
83 | /* Create a receiving thread */ | 120 | /* Create a receiving thread */ |
84 | -// mReadThread = new ReadThread(); | ||
85 | -// mReadThread.start(); | 121 | + mReadThread = new ReadThread(); |
122 | + mReadThread.start(); | ||
86 | 123 | ||
124 | + Log.d(TAG, "XPadApi init"); | ||
87 | // InitThread initThread = new InitThread(); | 125 | // InitThread initThread = new InitThread(); |
126 | +// initThread.start(); | ||
127 | + | ||
128 | + } catch (SecurityException e) { | ||
129 | + e.printStackTrace(); | ||
130 | + } catch (Exception e) { | ||
131 | + e.printStackTrace(); | ||
132 | + } | ||
133 | + } | ||
134 | + | ||
135 | + private class InitThread extends Thread { | ||
136 | + @Override | ||
137 | + public void run() { | ||
138 | + try { | ||
139 | + sleep(100); | ||
140 | + getKeypadParam();// 唤醒 | ||
141 | + sleep(100); | ||
142 | + getKeypadParam(); | ||
143 | + sleep(100); | ||
144 | + getWorkMode(); | ||
145 | + | ||
146 | + } catch (Exception e) { | ||
147 | + // TODO: handle exception | ||
148 | + } | ||
149 | + super.run(); | ||
150 | + } | ||
151 | + } | ||
152 | + | ||
153 | + | ||
154 | + | ||
155 | + public void closeCom() { | ||
156 | + if (mReadThread != null) | ||
157 | + mReadThread.interrupt(); | ||
158 | + | ||
159 | + | ||
160 | +// if(module != null){ | ||
161 | +// module.release(); | ||
162 | +// } | ||
163 | + | ||
164 | +// if (mSerialPort != null) { | ||
165 | +// mSerialPort.close(); | ||
166 | +// mSerialPort = null; | ||
167 | +// } | ||
168 | + } | ||
169 | + | ||
170 | + public static void printDataBuf(byte[] buf, int len, String flag) { | ||
171 | + String tmpStr = new String(); | ||
172 | + for (int i = 0; i < len; i++) { | ||
173 | + tmpStr += String.format("%x ", buf[i]); | ||
174 | + } | ||
175 | + LogUtil.d(TAG, flag + ":" + tmpStr); | ||
176 | + } | ||
177 | + | ||
178 | + public static String getDataBufString(byte[] buf, int len, String flag) { | ||
179 | + String tmpStr = new String(); | ||
180 | + for (int i = 0; i < len; i++) { | ||
181 | + tmpStr += String.format("%x ", buf[i]); | ||
182 | + } | ||
183 | + return flag + ":" + tmpStr; | ||
184 | + } | ||
185 | + | ||
186 | + public static byte[] intToByteArray1(int i) { | ||
187 | + byte[] result = new byte[4]; | ||
188 | + result[0] = (byte) ((i >> 24) & 0xFF); | ||
189 | + result[1] = (byte) ((i >> 16) & 0xFF); | ||
190 | + result[2] = (byte) ((i >> 8) & 0xFF); | ||
191 | + result[3] = (byte) (i & 0xFF); | ||
192 | + return result; | ||
193 | + } | ||
194 | + | ||
195 | + @Override | ||
196 | + public void setComListener(ComListener cl) { | ||
197 | + m_listener = cl; | ||
198 | + | ||
199 | + } | ||
88 | 200 | ||
89 | - } catch (SecurityException e) { | ||
90 | - LogUtil.e(TAG,e); | ||
91 | - } catch (Exception e) { | ||
92 | - LogUtil.e(TAG,e); | ||
93 | - } | ||
94 | - } | ||
95 | - | ||
96 | - public UDPModule getClient() { | ||
97 | - return client; | ||
98 | - } | ||
99 | - | ||
100 | - public void closeCom() { | ||
101 | - if (mReadThread != null) | ||
102 | - mReadThread.interrupt(); | ||
103 | - | ||
104 | - if(client != null){ | ||
105 | - client.release(); | ||
106 | - } | ||
107 | - } | ||
108 | - | ||
109 | - | ||
110 | - public static void printDataBuf(byte[] buf, int len, String flag) { | ||
111 | - String tmpStr = new String(); | ||
112 | - for (int i = 0; i < len; i++) { | ||
113 | - tmpStr += String.format("%x ", buf[i]); | ||
114 | - } | ||
115 | - LogUtil.d(TAG, flag + ":" + tmpStr); | ||
116 | - } | ||
117 | - | ||
118 | - public static String getDataBufString(byte[] buf, int len, String flag) { | ||
119 | - String tmpStr = new String(); | ||
120 | - for (int i = 0; i < len; i++) { | ||
121 | - tmpStr += String.format("%x ", buf[i]); | ||
122 | - } | ||
123 | - return flag + ":" + tmpStr; | ||
124 | - } | ||
125 | - | ||
126 | - public static byte[] intToByteArray1(int i) { | ||
127 | - byte[] result = new byte[4]; | ||
128 | - result[0] = (byte) ((i >> 24) & 0xFF); | ||
129 | - result[1] = (byte) ((i >> 16) & 0xFF); | ||
130 | - result[2] = (byte) ((i >> 8) & 0xFF); | ||
131 | - result[3] = (byte) (i & 0xFF); | ||
132 | - return result; | ||
133 | - } | ||
134 | - | ||
135 | - @Override | ||
136 | - public void setComListener(ComListener cl) { | ||
137 | - m_listener = cl; | ||
138 | - | ||
139 | - } | ||
140 | - public VoteResultItem getVoteResultItem(){ | ||
141 | - return new VoteResultItem(); | ||
142 | - } | ||
143 | - | ||
144 | - private Runnable sendTask = new Runnable() { | ||
145 | - @Override | ||
146 | - public void run() { | ||
147 | - // 从队列中取出待发送数据 | ||
148 | - VoteResultItem voteResultItem = null; | ||
149 | - boolean send = false; | ||
150 | - synchronized (sendQueen) { | ||
151 | - if(sendQueen.size() > 0) { | ||
152 | - Iterator<VoteResultItem> it = sendQueen.iterator(); | ||
153 | - while (it.hasNext()) { | ||
154 | - voteResultItem = it.next(); | ||
155 | - if ((!voteResultItem.sendOk && !send) || voteResultItem.ansType == AnsType_Select) { | ||
156 | - // 取出数据发送 | ||
157 | - if(send){ | ||
158 | - try { | ||
159 | - Thread.sleep(50); | ||
160 | - } catch (InterruptedException e) { | ||
161 | - e.printStackTrace(); | ||
162 | - } | ||
163 | - } | ||
164 | - voteResultItem.status = 1 ; | ||
165 | - writeToCom(voteResultItem.data); | ||
166 | - voteResultItem.sendTimes++; | ||
167 | - send = true; | ||
168 | - } | ||
169 | - } | ||
170 | - } | ||
171 | - } | ||
172 | - // 轮询下一次发送数据 | ||
173 | - taskHandler.removeCallbacks(this); | ||
174 | - taskHandler.postDelayed(this,1000); | ||
175 | - } | ||
176 | - }; | ||
177 | - | ||
178 | - public class VoteResultItem { | ||
179 | - public int serialNo; | ||
180 | - public int status;// 0:未发送 1:已发送 | ||
181 | - public int ansType; // | ||
182 | - public int ansCount;// 批次提交的选项数 | ||
183 | - public int allOK; //1 确认提交 | ||
184 | - public byte[] data; | ||
185 | - public boolean sendOk; | ||
186 | - public int sendTimes = 0; | ||
187 | - /** | ||
188 | - * 用于回调标志结果显示 | ||
189 | - */ | ||
190 | - public String retBack = "" ; | ||
191 | - } | ||
192 | - | ||
193 | - /* | ||
194 | - * function:addToSendQueen params: 发送内容 功能:添加到发送队列 | ||
195 | - */ | ||
196 | - private void addToSendQueen(VoteResultItem item) { | ||
197 | - boolean isComb = false;// 合并 | ||
198 | - synchronized (sendQueen) { | ||
199 | - if (item.ansType == AnsType_BatchSingle && item.allOK != 1) { | ||
200 | - for (int i = 0; i < sendQueen.size(); i++) { | ||
201 | - VoteResultItem it = (VoteResultItem) sendQueen.get(i); | ||
202 | - if (it.status != 1 && it.ansType == AnsType_BatchSingle && it.ansCount < 6) { | ||
203 | - it.data[9 + it.ansCount * 3] = item.data[9]; | ||
204 | - it.data[10 + it.ansCount * 3] = item.data[10]; | ||
205 | - it.data[11 + it.ansCount * 3] = item.data[11]; | ||
206 | - it.ansCount++; | ||
207 | - isComb = true; | ||
208 | - LogUtil.d(TAG, "addToSendQueen isComb=true 合并:" + it.ansCount); | ||
209 | - break; | ||
210 | - } | ||
211 | - } | ||
212 | - } | ||
213 | - } | ||
214 | - | ||
215 | - if (isComb == false) { | ||
216 | - sendQueen.add(item); | ||
217 | - } | ||
218 | - LogUtil.d(TAG, "addToSendQueen serialNo=" + item.serialNo + " size=" + sendQueen.size()); | ||
219 | - // 轮询下一次发送数据 | ||
220 | - taskHandler.removeCallbacks(sendTask); | ||
221 | - taskHandler.post(sendTask); | ||
222 | - | ||
223 | - } | ||
224 | - | ||
225 | - private void sendToModalSuccessResponse(int serialNo){ | ||
226 | - LogUtil.i(TAG,"send vote sendToModalSuccessResponse:" + serialNo); | ||
227 | - synchronized (sendQueen) { | ||
228 | - for (int i = 0; i < sendQueen.size(); i++) { | ||
229 | - VoteResultItem it = (VoteResultItem) sendQueen.get(i); | ||
230 | - if (serialNo == it.serialNo) { | ||
231 | - it.sendOk = true; | ||
232 | - break; | ||
233 | - } | ||
234 | - } | ||
235 | - } | ||
236 | - } | ||
237 | - /* | ||
238 | - * function:addToSendQueen params:流水号 功能:根据流水号删除队列已发送成功的项 | ||
239 | - */ | ||
240 | - private VoteResultItem removeSentItem(int serialNo) { | ||
241 | - LogUtil.d(TAG, "send success : " + serialNo); | ||
242 | - VoteResultItem ret = null; | ||
243 | - synchronized (sendQueen) { | ||
244 | - Iterator<VoteResultItem> it = sendQueen.iterator(); | ||
245 | - while (it.hasNext()) { | ||
246 | - VoteResultItem voteResultItem = it.next(); | ||
247 | - if (voteResultItem.status == 1 && voteResultItem.serialNo == serialNo) { | ||
248 | - voteResultItem.sendOk = true; | ||
249 | - boolean remove = sendQueen.remove(voteResultItem); | ||
250 | - LogUtil.d(TAG, "remove success ? " + remove); | ||
251 | - ret = voteResultItem; | ||
252 | - break; | ||
253 | - } | ||
254 | - } | ||
255 | - } | ||
256 | - return ret; | ||
257 | - } | ||
258 | - | ||
259 | - private void clearSentItems() { | ||
260 | - synchronized (sendQueen){ | ||
261 | - sendQueen.clear(); | ||
262 | - } | ||
263 | - } | ||
264 | - | ||
265 | - @Override | ||
266 | - public void getWorkMode() { | ||
267 | - byte[] mBuffer = new byte[0x1F + 4]; | ||
268 | - Arrays.fill(mBuffer, (byte) 0x0); | ||
269 | - mBuffer[0] = (byte) 0xF5; | ||
270 | - mBuffer[1] = (byte) 0xAA; | ||
271 | - mBuffer[2] = (byte) 0xAA; | ||
272 | - mBuffer[3] = (byte) 0x1F; | ||
273 | - | ||
274 | - mBuffer[4] = 0x70; | ||
275 | - mBuffer[5] = 0x01; | ||
276 | - | ||
277 | - writeToCom(mBuffer); | ||
278 | - } | ||
279 | - | ||
280 | - @Override | ||
281 | - public void setWorkMode(int iMode) { | ||
282 | - | ||
283 | - byte[] mBuffer = new byte[0x1F + 4]; | ||
284 | - // Arrays.fill(mBuffer, (byte) 0x55); | ||
285 | - Arrays.fill(mBuffer, (byte) 0x0); | ||
286 | - mBuffer[0] = (byte) 0xF5; | ||
287 | - mBuffer[1] = (byte) 0xAA; | ||
288 | - mBuffer[2] = (byte) 0xAA; | ||
289 | - mBuffer[3] = (byte) 0x1F; | ||
290 | - | ||
291 | - mBuffer[4] = 0x70; | ||
292 | - mBuffer[5] = 0x02; | ||
293 | - mBuffer[6] = (byte) iMode; | ||
294 | - | ||
295 | - writeToCom(mBuffer); | ||
296 | - } | ||
297 | - | ||
298 | - @Override | ||
299 | - public void getBaseStatus() { | ||
300 | - byte[] mBuffer = new byte[0x1F + 4]; | ||
301 | - Arrays.fill(mBuffer, (byte) 0x0); | ||
302 | - mBuffer[0] = (byte) 0xF5; | ||
303 | - mBuffer[1] = (byte) 0xAA; | ||
304 | - mBuffer[2] = (byte) 0xAA; | ||
305 | - mBuffer[3] = (byte) 0x1F; | ||
306 | - | ||
307 | - mBuffer[4] = 0x70; | ||
308 | - mBuffer[5] = 0x03; | ||
309 | - writeToCom(mBuffer); | ||
310 | - } | ||
311 | - | ||
312 | - @Override | ||
313 | - public void getVoteStatus() { | ||
314 | - byte[] mBuffer = new byte[0x1F + 4]; | ||
315 | - Arrays.fill(mBuffer, (byte) 0x0); | ||
316 | - mBuffer[0] = (byte) 0xF5; | ||
317 | - mBuffer[1] = (byte) 0xAA; | ||
318 | - mBuffer[2] = (byte) 0xAA; | ||
319 | - mBuffer[3] = (byte) 0x1F; | ||
320 | - | ||
321 | - mBuffer[4] = 0x70; | ||
322 | - mBuffer[5] = 0x04; | ||
323 | - writeToCom(mBuffer); | ||
324 | - } | ||
325 | - | ||
326 | - @Override | ||
327 | - public void getKeypadParam() { | ||
328 | - byte[] mBuffer = new byte[0x1F + 4]; | ||
329 | - Arrays.fill(mBuffer, (byte) 0x0); | ||
330 | - mBuffer[0] = (byte) 0xF5; | ||
331 | - mBuffer[1] = (byte) 0xAA; | ||
332 | - mBuffer[2] = (byte) 0xAA; | ||
333 | - mBuffer[3] = (byte) 0x1F; | ||
334 | - | ||
335 | - mBuffer[4] = 0x70; | ||
336 | - mBuffer[5] = 0x05; | ||
337 | - writeToCom(mBuffer); | ||
338 | - } | ||
339 | - | ||
340 | - @Override | ||
341 | - public void setKeypadParam(int keyId, byte[] KEYSN) { | ||
342 | - byte[] mBuffer = new byte[0x1F + 4]; | ||
343 | - Arrays.fill(mBuffer, (byte) 0x0); | ||
344 | - mBuffer[0] = (byte) 0xF5; | ||
345 | - mBuffer[1] = (byte) 0xAA; | ||
346 | - mBuffer[2] = (byte) 0xAA; | ||
347 | - mBuffer[3] = (byte) 0x1F; | ||
348 | - | ||
349 | - mBuffer[4] = 0x70; | ||
350 | - mBuffer[5] = 0x06; | ||
351 | - | ||
352 | - mBuffer[6] = (byte) ((keyId >> 8) & 0xFF);// keyId | ||
353 | - mBuffer[7] = (byte) (keyId & 0xFF); | ||
354 | - | ||
355 | - // mBuffer[8] =(byte) 0xFF; | ||
356 | - System.arraycopy(KEYSN, 0, mBuffer, 8, 6); | ||
357 | - | ||
358 | - byte[] parecode = new byte[4]; | ||
359 | - Arrays.fill(parecode, (byte) 0xFF); | ||
360 | - System.arraycopy(KEYSN, 0, mBuffer, 14, 4); | ||
361 | - | ||
362 | - writeToCom(mBuffer); | ||
363 | - } | ||
364 | - | ||
365 | - @Override | ||
366 | - public void checkOnLine(int volt, int keyinStatus) { | ||
367 | - if(isInComCommunicationTest){ | ||
368 | - return; | ||
369 | - } | ||
370 | - byte[] mBuffer = new byte[0x1F + 4]; | ||
371 | - Arrays.fill(mBuffer, (byte) 0x0); | ||
372 | - mBuffer[0] = (byte) 0xF5; | ||
373 | - mBuffer[1] = (byte) 0xAA; | ||
374 | - mBuffer[2] = (byte) 0xAA; | ||
375 | - mBuffer[3] = (byte) 0x1F; | ||
376 | - | ||
377 | - mBuffer[4] = 0x70; | ||
378 | - mBuffer[5] = 0x07; | ||
379 | - | ||
380 | - mBuffer[6] = (byte) volt; | ||
381 | - mBuffer[7] = (byte) keyinStatus; | ||
382 | - writeToCom(mBuffer); | ||
383 | - } | ||
384 | - | ||
385 | - @Override | ||
386 | - public void execKeypadMatch(int iMode, int channal) { | ||
387 | - byte[] mBuffer = new byte[0x1F + 4]; | ||
388 | - Arrays.fill(mBuffer, (byte) 0x0); | ||
389 | - mBuffer[0] = (byte) 0xF5; | ||
390 | - mBuffer[1] = (byte) 0xAA; | ||
391 | - mBuffer[2] = (byte) 0xAA; | ||
392 | - mBuffer[3] = (byte) 0x1F; | ||
393 | - | ||
394 | - mBuffer[4] = 0x70; | ||
395 | - mBuffer[5] = 0x08; | ||
396 | - | ||
397 | - mBuffer[6] = (byte) iMode; | ||
398 | - mBuffer[7] = (byte) channal; | ||
399 | - writeToCom(mBuffer); | ||
400 | - } | ||
401 | - | ||
402 | - private boolean isInComCommunicationTest = false; | ||
403 | - @Override | ||
404 | - public void comCommunicationTest(int sendn,int okn) { | ||
405 | - isInComCommunicationTest = (sendn != 200); | ||
406 | - byte[] mBuffer = new byte[0x1F + 4]; | ||
407 | - Arrays.fill(mBuffer, (byte) 0x0); | ||
408 | - mBuffer[0] = (byte) 0xF5; | ||
409 | - mBuffer[1] = (byte) 0xAA; | ||
410 | - mBuffer[2] = (byte) 0xAA; | ||
411 | - mBuffer[3] = (byte) 0x1F; | ||
412 | - | ||
413 | - mBuffer[4] = 0x30; | ||
414 | - mBuffer[5] = 0x0; | ||
415 | - mBuffer[6] = 0x0; | ||
416 | - | ||
417 | - mBuffer[7] = 7; | ||
418 | - mBuffer[8] = (byte) sendn; | ||
419 | - mBuffer[9] = (byte) okn; | ||
420 | - mBuffer[10] = (byte)0xAA; | ||
421 | - | ||
422 | - for(int i=1;i<17;i++){ | ||
423 | - mBuffer[10+i] = (byte)i; | ||
424 | - } | ||
425 | - | ||
426 | - writeToCom(mBuffer); | ||
427 | - } | ||
428 | - | ||
429 | - @Override | ||
430 | - public synchronized void submitVote(int ansType, String info) {// byte[] ansData | ||
431 | - | ||
432 | - if (ansType == AnsType_Single) {// 单值 | ||
433 | - byte[] mBuffer = new byte[0x1F + 4]; | ||
434 | - Arrays.fill(mBuffer, (byte) 0x0); | ||
435 | - mBuffer[0] = (byte) 0xF5; | ||
436 | - mBuffer[1] = (byte) 0xAA; | ||
437 | - mBuffer[2] = (byte) 0xAA; | ||
438 | - mBuffer[3] = (byte) 0x1F; | ||
439 | - | ||
440 | - mBuffer[4] = 0x73; | ||
441 | - mBuffer[5] = (byte) serialNumber;// 流水号 | ||
442 | - | ||
443 | - mBuffer[6] = 1;// MSGTYPE 1:ID mode, 2:SN | ||
444 | - mBuffer[7] = (byte) ansType; | ||
445 | - int val = Integer.parseInt(info); | ||
446 | - mBuffer[8] = (byte) val; | ||
447 | - | ||
448 | - VoteResultItem it = new VoteResultItem(); | ||
449 | - it.status = 0; | ||
450 | - it.ansType = ansType; | ||
451 | - it.ansCount = 1; | ||
452 | - it.serialNo = (byte)(serialNumber); | ||
453 | - serialNumberInc(); | ||
454 | - it.data = mBuffer; | ||
455 | - addToSendQueen(it); | ||
456 | - } else if (ansType == AnsType_Select) { | ||
457 | - String[] ary = info.split(","); | ||
458 | - String val = ary[0]; | ||
459 | - int tm = Integer.parseInt(ary[1]); | ||
460 | - | ||
461 | - byte[] mBuffer = new byte[0x1F + 4]; | ||
462 | - Arrays.fill(mBuffer, (byte) 0x0); | ||
463 | - mBuffer[0] = (byte) 0xF5; | ||
464 | - mBuffer[1] = (byte) 0xAA; | ||
465 | - mBuffer[2] = (byte) 0xAA; | ||
466 | - mBuffer[3] = (byte) 0x1F; | ||
467 | - | ||
468 | - mBuffer[4] = 0x73; | ||
469 | - mBuffer[5] = (byte) serialNumber;// 流水号 | ||
470 | - | ||
471 | - mBuffer[6] = 1;// MSGTYPE 1:ID mode, 2:SN | ||
472 | - mBuffer[7] = (byte) ansType; | ||
473 | - | ||
474 | - ; | ||
475 | - mBuffer[8] = (byte) ((tm >> 8) & 0xff); | ||
476 | - mBuffer[9] = (byte) (tm & 0xff); | ||
477 | - | ||
478 | - mBuffer[10] = (byte) ((tm >> 8) & 0xff); | ||
479 | - mBuffer[11] = (byte) (tm & 0xff); | ||
480 | - | ||
481 | - VoteResultItem it = new VoteResultItem(); | ||
482 | - it.retBack = info; | ||
483 | - it.status = 0; | ||
484 | - it.ansType = ansType; | ||
485 | - it.ansCount = 1; | ||
486 | - it.serialNo = (byte)serialNumber; | ||
487 | - serialNumberInc(); | ||
488 | - it.data = mBuffer; | ||
489 | - addToSendQueen(it); | ||
490 | - } else if (ansType == AnsType_Number) { | ||
491 | - byte[] mBuffer = new byte[0x1F + 4]; | ||
492 | - Arrays.fill(mBuffer, (byte) 0x0); | ||
493 | - mBuffer[0] = (byte) 0xF5; | ||
494 | - mBuffer[1] = (byte) 0xAA; | ||
495 | - mBuffer[2] = (byte) 0xAA; | ||
496 | - mBuffer[3] = (byte) 0x1F; | ||
497 | - | ||
498 | - mBuffer[4] = 0x73; | ||
499 | - mBuffer[5] = (byte) serialNumber;// 流水号 | ||
500 | - | ||
501 | - mBuffer[6] = 1;// MSGTYPE 1:ID mode, 2:SN | ||
502 | - mBuffer[7] = (byte) ansType; | ||
503 | - | ||
504 | - byte[] val = util_encodeBCD(info.getBytes()); | ||
505 | - System.arraycopy(val,0,mBuffer,8,8); | ||
506 | - | ||
507 | - VoteResultItem it = new VoteResultItem(); | ||
508 | - it.status = 0; | ||
509 | - it.ansType = ansType; | ||
510 | - it.ansCount = 1; | ||
511 | - it.serialNo = serialNumber; | ||
512 | - serialNumberInc(); | ||
513 | - it.data = mBuffer; | ||
514 | - addToSendQueen(it); | ||
515 | - } else if (ansType == AnsType_LoginIn) { | ||
516 | - byte[] mBuffer = new byte[0x1F + 4]; | ||
517 | - Arrays.fill(mBuffer, (byte) 0x0); | ||
518 | - mBuffer[0] = (byte) 0xF5; | ||
519 | - mBuffer[1] = (byte) 0xAA; | ||
520 | - mBuffer[2] = (byte) 0xAA; | ||
521 | - mBuffer[3] = (byte) 0x1F; | ||
522 | - | ||
523 | - mBuffer[4] = 0x73; | ||
524 | - mBuffer[5] = (byte) serialNumber;// 流水号 | ||
525 | - | ||
526 | - mBuffer[6] = 1;// MSGTYPE 1:ID mode, 2:SN | ||
527 | - mBuffer[7] = (byte) ansType; | ||
528 | - mBuffer[8] = 3;//3 签到信息按BCD码格式 | ||
529 | - byte[] val = util_encodeBCD(info.getBytes()); | ||
530 | - System.arraycopy(val,0,mBuffer,9,9); | ||
531 | - | ||
532 | - VoteResultItem it = new VoteResultItem(); | ||
533 | - it.status = 0; | ||
534 | - it.ansType = ansType; | ||
535 | - it.ansCount = 1; | ||
536 | - it.serialNo = serialNumber; | ||
537 | - serialNumberInc(); | ||
538 | - it.data = mBuffer; | ||
539 | - addToSendQueen(it); | ||
540 | - | ||
541 | - } else if (ansType == AnsType_BatchSingle) { | ||
542 | - | ||
543 | - // String[] ary= info.split(","); | ||
544 | - | ||
545 | - byte[] mBuffer = new byte[0x1F + 4]; | ||
546 | - Arrays.fill(mBuffer, (byte) 0x0); | ||
547 | - mBuffer[0] = (byte) 0xF5; | ||
548 | - mBuffer[1] = (byte) 0xAA; | ||
549 | - mBuffer[2] = (byte) 0xAA; | ||
550 | - mBuffer[3] = (byte) 0x1F; | ||
551 | - | ||
552 | - mBuffer[4] = 0x73; | ||
553 | - mBuffer[5] = (byte) serialNumber;// 流水号 | ||
554 | - | ||
555 | - mBuffer[6] = 1;// MSGTYPE 1:ID mode, 2:SN | ||
556 | - mBuffer[7] = (byte) ansType; | ||
557 | - mBuffer[8] = 0;// ALLOK | ||
558 | - int pos = 9; | ||
559 | - | ||
560 | - String[] item = info.split(":"); | ||
561 | - if (item.length > 1) { | ||
562 | - int num = Integer.parseInt(item[0]); | ||
563 | - int val = Integer.parseInt(item[1]); | ||
564 | - mBuffer[pos++] = (byte) (num >> 8); | ||
565 | - mBuffer[pos++] = (byte) (num & 0xff); | ||
566 | - mBuffer[pos++] = (byte) val; | ||
567 | - } | ||
568 | - | ||
569 | - VoteResultItem it = new VoteResultItem(); | ||
570 | - it.status = 0; | ||
571 | - it.ansType = ansType; | ||
572 | - it.serialNo = serialNumber; | ||
573 | - serialNumberInc(); | ||
574 | - it.ansCount = 1; | ||
575 | - it.data = mBuffer; | ||
576 | - addToSendQueen(it); | ||
577 | - } else if (ansType == AnsType_BatchNumber) { | ||
578 | - byte[] mBuffer = new byte[0x1F + 4]; | ||
579 | - Arrays.fill(mBuffer, (byte) 0x0); | ||
580 | - mBuffer[0] = (byte) 0xF5; | ||
581 | - mBuffer[1] = (byte) 0xAA; | ||
582 | - mBuffer[2] = (byte) 0xAA; | ||
583 | - mBuffer[3] = (byte) 0x1F; | ||
584 | - | ||
585 | - mBuffer[4] = 0x73; | ||
586 | - mBuffer[5] = (byte) serialNumber;// 流水号 | ||
587 | - | ||
588 | - mBuffer[6] = 1;// MSGTYPE 1:ID mode, 2:SN | ||
589 | - mBuffer[7] = (byte) ansType; | ||
590 | - mBuffer[8] = 0;// ALLOK | ||
591 | - | ||
592 | - String[] item = info.split(":"); | ||
593 | - if (item.length > 1) { | ||
594 | - String[] itIndex = item[0].split("_"); | ||
595 | - if(itIndex.length==2){ //综合测评 | ||
596 | - int personId = Integer.parseInt(itIndex[0]); | ||
597 | - int projectId =Integer.parseInt(itIndex[1]); | ||
598 | - mBuffer[9] = (byte)personId; | ||
599 | - mBuffer[10] = (byte)projectId; | ||
600 | - }else { | ||
601 | - int num = Integer.parseInt(item[0]); | ||
602 | - mBuffer[9] = (byte) (num >> 8); | ||
603 | - mBuffer[10] = (byte) (num & 0xff); | ||
604 | - } | ||
605 | - String strNum = item[1]; | ||
606 | - byte[] val = util_encodeBCD(strNum.getBytes()); | ||
607 | - System.arraycopy(val, 0, mBuffer, 11, 4); | ||
608 | - } | ||
609 | - | ||
610 | - VoteResultItem it = new VoteResultItem(); | ||
611 | - it.status = 0; | ||
612 | - it.ansType = ansType; | ||
613 | - it.serialNo = serialNumber; | ||
614 | - serialNumberInc(); | ||
615 | - it.ansCount = 1; | ||
616 | - it.data = mBuffer; | ||
617 | - addToSendQueen(it); | ||
618 | - | ||
619 | - } else if (ansType == AnsType_SelectOther) { | ||
620 | - byte[] mBuffer = new byte[0x1F + 4]; | ||
621 | - Arrays.fill(mBuffer, (byte) 0x0); | ||
622 | - mBuffer[0] = (byte) 0xF5; | ||
623 | - mBuffer[1] = (byte) 0xAA; | ||
624 | - mBuffer[2] = (byte) 0xAA; | ||
625 | - mBuffer[3] = (byte) 0x1F; | ||
626 | - | ||
627 | - mBuffer[4] = 0x73; | ||
628 | - mBuffer[5] = (byte) serialNumber;// 流水号 | ||
629 | - | ||
630 | - mBuffer[6] = 1;// MSGTYPE 1:ID mode, 2:SN | ||
631 | - mBuffer[7] = (byte) ansType; | ||
632 | - mBuffer[8] = 0;// ALLOK | ||
633 | - int pos = 9; | ||
634 | - | ||
635 | - String[] item = info.split(":"); | ||
636 | - if (item.length > 1) { | ||
637 | - int num = Integer.parseInt(item[0]); | ||
638 | - String val = item[1]; | ||
639 | - mBuffer[pos++] = (byte) (num >> 8); | ||
640 | - mBuffer[pos++] = (byte) num; | ||
641 | - | ||
642 | - mBuffer[pos++] = 0;// slot | ||
643 | - try { | ||
644 | - byte[] name = val.getBytes("GB2312"); | ||
645 | - | ||
646 | - System.arraycopy(name, 0, mBuffer, pos, name.length > 16 ? 16 : name.length); | ||
647 | - | ||
648 | - } catch (UnsupportedEncodingException e) { | ||
649 | - LogUtil.e(TAG,e); | ||
650 | - } | ||
651 | - // 名字最多16 | ||
652 | - } | ||
653 | - | ||
654 | - VoteResultItem it = new VoteResultItem(); | ||
655 | - it.retBack = info; | ||
656 | - it.status = 0; | ||
657 | - it.ansType = ansType; | ||
658 | - it.serialNo = (byte)serialNumber; | ||
659 | - serialNumberInc(); | ||
660 | - it.ansCount = 1; | ||
661 | - it.data = mBuffer; | ||
662 | - addToSendQueen(it); | ||
663 | - | ||
664 | - }else if(ansType == AnsType_Service){ | ||
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] = 0x73; | ||
673 | - mBuffer[5] = (byte) serialNumber;// 流水号 | ||
674 | - | ||
675 | - mBuffer[6] = 1;// MSGTYPE 1:ID mode, 2:SN | ||
676 | - mBuffer[7] = (byte) ansType; | ||
677 | - mBuffer[8] = 4; | ||
678 | - int serv_type = Integer.parseInt(info); | ||
679 | - mBuffer[9] = (byte) serv_type; | ||
680 | - | ||
681 | - VoteResultItem it = new VoteResultItem(); | ||
682 | - it.status = 0; | ||
683 | - it.ansType = ansType; | ||
684 | - it.serialNo = serialNumber; | ||
685 | - serialNumberInc(); | ||
686 | - it.ansCount = 1; | ||
687 | - it.data = mBuffer; | ||
688 | - addToSendQueen(it); | ||
689 | - | ||
690 | - } | ||
691 | - } | ||
692 | - | ||
693 | - private int ChoiceValueToInt(String val) { | ||
694 | - int ret = 0; | ||
695 | - for (int i = 0; i < val.length(); i++) { | ||
696 | - char cc = val.charAt(i); | ||
697 | - if (cc < 'I') { | ||
698 | - ret |= 1 << (8 + (cc - 'A')); | ||
699 | - } else { | ||
700 | - ret |= 1 << (cc - 'I'); | ||
701 | - } | ||
702 | - | ||
703 | - } | ||
704 | - | ||
705 | - return ret; | ||
706 | - } | ||
707 | - | ||
708 | - public void submitVoteFource(int ansType, String info) { | ||
709 | - byte[] mBuffer = new byte[0x1F + 4]; | ||
710 | - Arrays.fill(mBuffer, (byte) 0x0); | ||
711 | - mBuffer[0] = (byte) 0xF5; | ||
712 | - mBuffer[1] = (byte) 0xAA; | ||
713 | - mBuffer[2] = (byte) 0xAA; | ||
714 | - mBuffer[3] = (byte) 0x1F; | ||
715 | - | ||
716 | - mBuffer[4] = 0x73; | ||
717 | - mBuffer[5] = (byte) serialNumber;// 流水号 | ||
718 | - | ||
719 | - mBuffer[6] = 1;// MSGTYPE 1:ID mode, 2:SN | ||
720 | - mBuffer[7] = (byte) ansType; | ||
721 | - mBuffer[8] = 0;// ALLOK | ||
722 | - int pos = 9; | ||
723 | - | ||
724 | - String[] item = info.split(":"); | ||
725 | - if (item.length > 1) { | ||
726 | - int num = Integer.parseInt(item[0]); | ||
727 | - String val = item[1]; | ||
728 | - mBuffer[pos++] = (byte) (num >> 8); | ||
729 | - mBuffer[pos++] = (byte) num; | ||
730 | - | ||
731 | - mBuffer[pos++] = 0;// slot | ||
732 | - try { | ||
733 | - byte[] name = val.getBytes("GB2312"); | ||
734 | - | ||
735 | - System.arraycopy(name, 0, mBuffer, pos, name.length > 16 ? 16 : name.length); | ||
736 | - | ||
737 | - } catch (UnsupportedEncodingException e) { | ||
738 | - // TODO Auto-generated catch block | ||
739 | - LogUtil.e(TAG,e); | ||
740 | - } | ||
741 | - // 名字最多16 | ||
742 | - } | ||
743 | - | ||
744 | - VoteResultItem it = new VoteResultItem(); | ||
745 | - it.status = 0; | ||
746 | - it.ansType = ansType; | ||
747 | - it.serialNo = (byte)serialNumber; | ||
748 | - serialNumberInc(); | ||
749 | - it.ansCount = 1; | ||
750 | - it.data = mBuffer; | ||
751 | - addToSendQueen(it); | ||
752 | - } | ||
753 | - | ||
754 | - @Override | ||
755 | - public void submitVoteAllOK() { | ||
756 | - int allokSerialNum = 0xff; | ||
757 | - byte[] mBuffer = new byte[0x1F + 4]; | ||
758 | - Arrays.fill(mBuffer, (byte) 0x0); | ||
759 | - mBuffer[0] = (byte) 0xF5; | ||
760 | - mBuffer[1] = (byte) 0xAA; | ||
761 | - mBuffer[2] = (byte) 0xAA; | ||
762 | - mBuffer[3] = (byte) 0x1F; | ||
763 | - | ||
764 | - mBuffer[4] = 0x73; | ||
765 | - mBuffer[5] = (byte) allokSerialNum;// 流水号 | ||
766 | - | ||
767 | - mBuffer[6] = 1;// MSGTYPE 1:ID mode, 2:SN | ||
768 | - mBuffer[7] = (byte) AnsType_BatchSingle; | ||
769 | - mBuffer[8] = 1;// ALLOK | ||
770 | - | ||
771 | - VoteResultItem it = new VoteResultItem(); | ||
772 | - it.status = 0; | ||
773 | - it.ansType = AnsType_BatchSingle; | ||
774 | - it.serialNo = ((byte)allokSerialNum & 0xff); | ||
775 | - allOkSerialNumber = (byte)allokSerialNum; | ||
776 | - it.ansCount = 1; | ||
777 | - it.allOK = 1; | ||
778 | - it.data = mBuffer; | ||
779 | - addToSendQueen(it); | ||
780 | - | ||
781 | - } | ||
782 | - | ||
783 | - @Override | ||
784 | - public void cancelSubmitVoteAllOK() { | ||
785 | - int cancelAllokSerialNum = 0xfe; | ||
786 | - byte[] mBuffer = new byte[0x1F + 4]; | ||
787 | - Arrays.fill(mBuffer, (byte) 0x0); | ||
788 | - mBuffer[0] = (byte) 0xF5; | ||
789 | - mBuffer[1] = (byte) 0xAA; | ||
790 | - mBuffer[2] = (byte) 0xAA; | ||
791 | - mBuffer[3] = (byte) 0x1F; | ||
792 | - | ||
793 | - mBuffer[4] = 0x73; | ||
794 | - mBuffer[5] = (byte) cancelAllokSerialNum;// 流水号 | ||
795 | - | ||
796 | - mBuffer[6] = 1;// MSGTYPE 1:ID mode, 2:SN | ||
797 | - mBuffer[7] = (byte) AnsType_BatchSingle; | ||
798 | - mBuffer[8] = 0;// ALLOK | ||
799 | - | ||
800 | - VoteResultItem it = new VoteResultItem(); | ||
801 | - it.status = 0; | ||
802 | - it.ansType = AnsType_BatchSingle; | ||
803 | - it.serialNo = cancelAllokSerialNum; | ||
804 | - // allOkSerialNumber = serialNumber; | ||
805 | - it.ansCount = 1; | ||
806 | - it.allOK = 0; | ||
807 | - it.data = mBuffer; | ||
808 | - addToSendQueen(it); | ||
809 | - | ||
810 | - //serialNumber=0; | ||
811 | - } | ||
812 | - | ||
813 | - private void serialNumberInc(){ | ||
814 | - serialNumber++; | ||
815 | - if(serialNumber == 0xfe){ | ||
816 | - serialNumber = 0; | ||
817 | - } | ||
818 | - } | ||
819 | - | ||
820 | - @Override | ||
821 | - public void submitSelectOther(String info) { | ||
822 | - // TODO Auto-generated method stub | ||
823 | - | ||
824 | - } | ||
825 | - | ||
826 | - @Override | ||
827 | - public void submitVoteBySn(byte[] keySn, String info) { | ||
828 | - byte[] mBuffer = new byte[0x1F + 4]; | ||
829 | - Arrays.fill(mBuffer, (byte) 0x0); | ||
830 | - mBuffer[0] = (byte) 0xF5; | ||
831 | - mBuffer[1] = (byte) 0xAA; | ||
832 | - mBuffer[2] = (byte) 0xAA; | ||
833 | - mBuffer[3] = (byte) 0x1F; | ||
834 | - | ||
835 | - mBuffer[4] = 0x73; | ||
836 | - mBuffer[5] = 0x08;// 流水号 | ||
837 | - | ||
838 | - mBuffer[6] = 2;// MSGTYPE | ||
839 | - | ||
840 | - mBuffer[7] = 1;// ANSTYPE | ||
841 | - | ||
842 | - System.arraycopy(keySn, 0, mBuffer, 8, 6);// keysn | ||
843 | - // System.arraycopy(ansData, 0, mBuffer, 8, | ||
844 | - // ansData.length<=16?ansData.length:16); | ||
845 | - // info??? | ||
846 | - writeToCom(mBuffer); | ||
847 | - } | ||
848 | - | ||
849 | - @Override | ||
850 | - public void sendCmdData(int cmdId, byte[] data) { | ||
851 | - byte[] mBuffer = new byte[0x1F + 4]; | ||
852 | - Arrays.fill(mBuffer, (byte) 0x0); | ||
853 | - mBuffer[0] = (byte) 0xF5; | ||
854 | - mBuffer[1] = (byte) 0xAA; | ||
855 | - mBuffer[2] = (byte) 0xAA; | ||
856 | - mBuffer[3] = (byte) 0x1F; | ||
857 | - | ||
858 | - mBuffer[4] = (byte) 0xB0;// 0x30 表决器下载单包类指令 | ||
859 | - | ||
860 | - mBuffer[5] = 0x0;// keyid 填 0 | ||
861 | - mBuffer[6] = 0x0;// keyid | ||
862 | - | ||
863 | - mBuffer[7] = (byte) cmdId;// KCMD | ||
864 | - System.arraycopy(data, 0, mBuffer, 8, data.length);// keysn | ||
865 | - | ||
866 | - writeToCom(mBuffer); | ||
867 | - } | ||
868 | - | ||
869 | - @Override | ||
870 | - public void configMode() { | ||
871 | - byte[] mBuffer = new byte[0x1F + 4]; | ||
872 | - Arrays.fill(mBuffer, (byte) 0x0); | ||
873 | - mBuffer[0] = (byte) 0xF5; | ||
874 | - mBuffer[1] = (byte) 0xAA; | ||
875 | - mBuffer[2] = (byte) 0xAA; | ||
876 | - mBuffer[3] = (byte) 0x1F; | ||
877 | - | ||
878 | - mBuffer[4] = 0x70; | ||
879 | - mBuffer[5] = 0x09; | ||
880 | - | ||
881 | - writeToCom(mBuffer); | ||
882 | - | ||
883 | - } | ||
884 | - | ||
885 | - private byte[] firmFileBuffer; | ||
886 | - private int firmWritePage; | ||
887 | - private int firmWritePageMax; | ||
888 | - | ||
889 | - @Override | ||
890 | - public void startFirmUpdate(byte[] fileBuffer) { | ||
891 | - | ||
892 | - firmFileBuffer = fileBuffer; | ||
893 | - firmWritePage = 0; | ||
894 | - firmWritePageMax = firmFileBuffer.length / 32; | ||
895 | - if (firmWritePageMax % 32 > 0) { | ||
896 | - firmWritePageMax++; | ||
897 | - } | ||
898 | - | ||
899 | - byte[] mBuffer = new byte[0x1F + 4]; | ||
900 | - Arrays.fill(mBuffer, (byte) 0x0); | ||
901 | - mBuffer[0] = (byte) 0xF5; | ||
902 | - mBuffer[1] = (byte) 0xAA; | ||
903 | - mBuffer[2] = (byte) 0xAA; | ||
904 | - mBuffer[3] = (byte) 10; | ||
905 | - | ||
906 | - mBuffer[4] = 0x78; | ||
907 | - mBuffer[5] = 0x01; | ||
908 | - | ||
909 | - writeToCom(mBuffer); | ||
910 | - } | ||
911 | - | ||
912 | - private void keepFirmMode() { | ||
913 | - byte[] mBuffer = new byte[0x1F + 4]; | ||
914 | - Arrays.fill(mBuffer, (byte) 0x0); | ||
915 | - mBuffer[0] = (byte) 0xF5; | ||
916 | - mBuffer[1] = (byte) 0xAA; | ||
917 | - mBuffer[2] = (byte) 0xAA; | ||
918 | - mBuffer[3] = (byte) 10; | ||
919 | - | ||
920 | - mBuffer[4] = 0x78; | ||
921 | - mBuffer[5] = 0x02; | ||
922 | - | ||
923 | - writeToCom(mBuffer); | ||
924 | - } | ||
925 | - | ||
926 | - private void eraseFlash() { | ||
927 | - int file_len = firmFileBuffer.length; | ||
928 | - | ||
929 | - byte[] mBuffer = new byte[0x1F + 4]; | ||
930 | - Arrays.fill(mBuffer, (byte) 0x0); | ||
931 | - mBuffer[0] = (byte) 0xF5; | ||
932 | - mBuffer[1] = (byte) 0xAA; | ||
933 | - mBuffer[2] = (byte) 0xAA; | ||
934 | - mBuffer[3] = (byte) 10; | ||
935 | - | ||
936 | - mBuffer[4] = 0x78; | ||
937 | - mBuffer[5] = 0x03; | ||
938 | - mBuffer[6] = 0; | ||
939 | - mBuffer[7] = (byte) (file_len / 1024); | ||
940 | - | ||
941 | - writeToCom(mBuffer); | ||
942 | - } | ||
943 | - | ||
944 | - private void writeFlash(int page) { | ||
945 | - byte[] mBuffer = new byte[38 + 4]; | ||
946 | - Arrays.fill(mBuffer, (byte) 0x0); | ||
947 | - mBuffer[0] = (byte) 0xF5; | ||
948 | - mBuffer[1] = (byte) 0xAA; | ||
949 | - mBuffer[2] = (byte) 0xAA; | ||
950 | - mBuffer[3] = (byte) 38; | ||
951 | - | ||
952 | - mBuffer[4] = 0x78; | ||
953 | - mBuffer[5] = 0x04; | ||
954 | - | ||
955 | - mBuffer[6] = (byte) (page / 256); | ||
956 | - mBuffer[7] = (byte) (page % 256); | ||
957 | - int pos = 0; | ||
958 | - for (int i = 0; i < 32; i++) { | ||
959 | - pos = page * 32 + i; | ||
960 | - if (pos == firmFileBuffer.length - 1) { | ||
961 | - break; | ||
962 | - } | ||
963 | - mBuffer[8 + i] = firmFileBuffer[pos]; | ||
964 | - } | ||
965 | - LogUtil.d(TAG,"write flash page:"+page); | ||
966 | - writeToCom(mBuffer); | ||
967 | - } | ||
968 | - | ||
969 | - /* | ||
970 | - * status 1: success 2 : fail | ||
971 | - */ | ||
972 | - private void exitFirmUpdate(int status) { | ||
973 | - byte[] mBuffer = new byte[0x1F + 4]; | ||
974 | - Arrays.fill(mBuffer, (byte) 0x0); | ||
975 | - mBuffer[0] = (byte) 0xF5; | ||
976 | - mBuffer[1] = (byte) 0xAA; | ||
977 | - mBuffer[2] = (byte) 0xAA; | ||
978 | - mBuffer[3] = (byte) 10; | ||
979 | - | ||
980 | - mBuffer[4] = 0x78; | ||
981 | - mBuffer[5] = 5; | ||
982 | - mBuffer[6] = (byte) status; | ||
983 | - writeToCom(mBuffer); | ||
984 | - } | ||
985 | - | ||
986 | - public void writeToCom(byte[] data) { | ||
987 | - if (mOutputStream != null) { | ||
988 | - try { | ||
989 | - int crcValue = Crc16.getUnsignedShort(Crc16.crc16(data, data.length - 4 - 2)); | ||
990 | - data[data.length - 2] = (byte) (crcValue >> 8); | ||
991 | - data[data.length - 1] = (byte) (crcValue); | ||
992 | - | ||
993 | - if (isShowLog) { | ||
994 | - if (data[4] == 0x70 && data[5] == 0x07) { | ||
995 | - // Log.d(TAG, "check online"); | ||
996 | - if (isShowOnlineLog) { | ||
997 | - printDataBuf(data, data.length, "send:"); | ||
998 | - } | ||
999 | - } else { | ||
1000 | - printDataBuf(data, data.length, "send:"); | ||
1001 | - } | ||
1002 | - } | ||
1003 | - | ||
1004 | - mOutputStream.write(data); | ||
1005 | - } catch (IOException e) { | ||
1006 | - LogUtil.e(TAG,e); | ||
1007 | - } | ||
1008 | - | ||
1009 | - m_listener.onSendData(data, data.length); | ||
1010 | - } | ||
1011 | - } | ||
1012 | - | ||
1013 | - private byte[] SerDataRx = new byte[100]; | ||
1014 | - int iSerRxN = 0; | ||
1015 | - private byte[] comBuffer = new byte[1024]; | ||
1016 | - | ||
1017 | - private class ReadThread extends Thread { | ||
1018 | - | ||
1019 | - @Override | ||
1020 | - public void run() { | ||
1021 | - super.run(); | ||
1022 | - while (!isInterrupted()) { | ||
1023 | - try { | ||
1024 | - Arrays.fill(comBuffer, (byte) 0x0);// 清空结果 | ||
1025 | - // byte[] buffer = new byte[512];// buffer 64字节 | ||
1026 | - if (mInputStream == null) { | ||
1027 | - return; | ||
1028 | - } | ||
1029 | - int size = mInputStream.read(comBuffer); | ||
1030 | - | ||
1031 | - dowith(comBuffer,size); | ||
1032 | - } catch (IOException e) { | ||
1033 | - LogUtil.e(TAG,e); | ||
1034 | - return; | ||
1035 | - } | ||
1036 | - } | ||
1037 | - } | 201 | + public class VoteResultItem { |
202 | + public int serialNo; | ||
203 | + public int status;// 0:未发送 1:已发送 | ||
204 | + public int ansType; // | ||
205 | + public int ansCount;// 批次提交的选项数 | ||
206 | + public int allOK; //1 确认提交 | ||
207 | + public byte[] data; | ||
208 | + public boolean sendOk; | ||
209 | + public int sendTimes = 0; | ||
210 | + /** | ||
211 | + * 用于回调标志结果显示 | ||
212 | + */ | ||
213 | + public String retBack = "" ; | ||
1038 | } | 214 | } |
1039 | 215 | ||
1040 | - private void dowith(byte[] comBuffer, int size) { | ||
1041 | - if (size > 0 && m_listener != null) { | ||
1042 | - int recvLen = size; | ||
1043 | - int rxDataLen = 0; | ||
1044 | - for (int i = 0; i < recvLen; i++) { | ||
1045 | - if (iSerRxN >= 512) { | ||
1046 | - iSerRxN = 0; | 216 | + private Runnable sendTask = new Runnable() { |
217 | + @Override | ||
218 | + public void run() { | ||
219 | + // 从队列中取出待发送数据 | ||
220 | + VoteResultItem voteResultItem = null; | ||
221 | + boolean send = false; | ||
222 | + synchronized (sendQueen) { | ||
223 | + if(sendQueen.size() > 0) { | ||
224 | + Iterator<VoteResultItem> it = sendQueen.iterator(); | ||
225 | + while (it.hasNext()) { | ||
226 | + voteResultItem = it.next(); | ||
227 | + if ((!voteResultItem.sendOk && !send) || voteResultItem.ansType == AnsType_Select) { | ||
228 | + // 取出数据发送 | ||
229 | + if(send){ | ||
230 | + try { | ||
231 | + Thread.sleep(50); | ||
232 | + } catch (InterruptedException e) { | ||
233 | + e.printStackTrace(); | ||
234 | + } | ||
235 | + } | ||
236 | + voteResultItem.status = 1 ; | ||
237 | + if(voteResultItem.sendTimes < 1){ | ||
238 | + writeToCom(voteResultItem.data); | ||
239 | + } | ||
240 | + voteResultItem.sendTimes++; | ||
241 | + if(voteResultItem.sendTimes > 6){ | ||
242 | + voteResultItem.sendTimes = 0 ; | ||
243 | + } | ||
244 | + send = true; | ||
245 | + } | ||
246 | + } | ||
247 | + } | ||
248 | + } | ||
249 | + // 轮询下一次发送数据 | ||
250 | + taskHandler.removeCallbacks(this); | ||
251 | + taskHandler.postDelayed(this,1000); | ||
252 | + } | ||
253 | + }; | ||
254 | + | ||
255 | + /* | ||
256 | + * function:addToSendQueen params: 发送内容 功能:添加到发送队列 | ||
257 | + */ | ||
258 | + private void addToSendQueen(VoteResultItem item) { | ||
259 | + boolean isComb = false;// 合并 | ||
260 | + synchronized (sendQueen) { | ||
261 | + if (item.ansType == AnsType_BatchSingle && item.allOK != 1) { | ||
262 | + for (int i = 0; i < sendQueen.size(); i++) { | ||
263 | + VoteResultItem it = (VoteResultItem) sendQueen.get(i); | ||
264 | + if (it.status != 1 && it.ansType == AnsType_BatchSingle && it.ansCount < 6) { | ||
265 | + it.data[9 + it.ansCount * 3] = item.data[9]; | ||
266 | + it.data[10 + it.ansCount * 3] = item.data[10]; | ||
267 | + it.data[11 + it.ansCount * 3] = item.data[11]; | ||
268 | + it.ansCount++; | ||
269 | + isComb = true; | ||
270 | + LogUtil.d(TAG, "addToSendQueen isComb=true 合并:" + it.ansCount); | ||
271 | + break; | ||
272 | + } | ||
273 | + } | ||
274 | + } | ||
275 | + } | ||
276 | + | ||
277 | + if (isComb == false) { | ||
278 | + sendQueen.add(item); | ||
279 | + } | ||
280 | + LogUtil.d(TAG, "addToSendQueen serialNo=" + item.serialNo + " size=" + sendQueen.size()); | ||
281 | + // 轮询下一次发送数据 | ||
282 | + taskHandler.removeCallbacks(sendTask); | ||
283 | + taskHandler.post(sendTask); | ||
284 | + } | ||
285 | + | ||
286 | + private void sendToModalSuccessResponse(int serialNo) { | ||
287 | + LogUtil.d(TAG,"sendToModalSuccessResponse:" + serialNo); | ||
288 | + synchronized (sendQueen) { | ||
289 | + Iterator<VoteResultItem> it = sendQueen.iterator(); | ||
290 | + while (it.hasNext()) { | ||
291 | + VoteResultItem voteResultItem = it.next(); | ||
292 | + if (voteResultItem.status == 1 && serialNo == voteResultItem.serialNo) { | ||
293 | + voteResultItem.sendOk = true; | ||
294 | + LogUtil.d(TAG, "set send ok sucess :" + serialNo); | ||
295 | + break; | ||
296 | + } | ||
297 | + } | ||
298 | + } | ||
299 | + } | ||
300 | + | ||
301 | + /* | ||
302 | + * function:addToSendQueen params:流水号 功能:根据流水号删除队列已发送成功的项 | ||
303 | + */ | ||
304 | + private VoteResultItem removeSentItem(int serialNo) { | ||
305 | + LogUtil.d(TAG, "send success : " + serialNo); | ||
306 | + VoteResultItem ret = null; | ||
307 | + synchronized (sendQueen) { | ||
308 | + Iterator<VoteResultItem> it = sendQueen.iterator(); | ||
309 | + while (it.hasNext()) { | ||
310 | + VoteResultItem voteResultItem = it.next(); | ||
311 | + if (voteResultItem.status == 1 && voteResultItem.serialNo == serialNo) { | ||
312 | + voteResultItem.sendOk = true; | ||
313 | + boolean remove = sendQueen.remove(voteResultItem); | ||
314 | + LogUtil.d(TAG, "remove success ? " + remove); | ||
315 | + ret = voteResultItem; | ||
1047 | break; | 316 | break; |
1048 | } | 317 | } |
1049 | - int dd = Crc16.getUnsignedByte(comBuffer[i]); | 318 | + } |
319 | + } | ||
320 | + return ret; | ||
321 | + } | ||
322 | + | ||
323 | + private void clearSentItems() { | ||
324 | + sendQueen.clear(); | ||
325 | + } | ||
326 | + | ||
327 | + @Override | ||
328 | + public void getWorkMode() { | ||
329 | + byte[] mBuffer = new byte[0x1F + 4]; | ||
330 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
331 | + mBuffer[0] = (byte) 0xF5; | ||
332 | + mBuffer[1] = (byte) 0xAA; | ||
333 | + mBuffer[2] = (byte) 0xAA; | ||
334 | + mBuffer[3] = (byte) 0x1F; | ||
335 | + | ||
336 | + mBuffer[4] = 0x70; | ||
337 | + mBuffer[5] = 0x01; | ||
338 | + | ||
339 | + writeToCom(mBuffer); | ||
340 | + } | ||
341 | + | ||
342 | + @Override | ||
343 | + public void setWorkMode(int iMode) { | ||
344 | + | ||
345 | + byte[] mBuffer = new byte[0x1F + 4]; | ||
346 | + // Arrays.fill(mBuffer, (byte) 0x55); | ||
347 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
348 | + mBuffer[0] = (byte) 0xF5; | ||
349 | + mBuffer[1] = (byte) 0xAA; | ||
350 | + mBuffer[2] = (byte) 0xAA; | ||
351 | + mBuffer[3] = (byte) 0x1F; | ||
352 | + | ||
353 | + mBuffer[4] = 0x70; | ||
354 | + mBuffer[5] = 0x02; | ||
355 | + mBuffer[6] = (byte) iMode; | ||
356 | + | ||
357 | + writeToCom(mBuffer); | ||
358 | + } | ||
359 | + | ||
360 | + @Override | ||
361 | + public void getBaseStatus() { | ||
362 | + if(baseSign != null){ | ||
363 | + onBaseInfo(baseSign); | ||
364 | + } | ||
365 | + /* byte[] mBuffer = new byte[0x1F + 4]; | ||
366 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
367 | + mBuffer[0] = (byte) 0xF5; | ||
368 | + mBuffer[1] = (byte) 0xAA; | ||
369 | + mBuffer[2] = (byte) 0xAA; | ||
370 | + mBuffer[3] = (byte) 0x1F; | ||
371 | + | ||
372 | + mBuffer[4] = 0x70; | ||
373 | + mBuffer[5] = 0x03; | ||
374 | + writeToCom(mBuffer);*/ | ||
375 | + } | ||
376 | + | ||
377 | + @Override | ||
378 | + public void getVoteStatus() { | ||
379 | + if(voteSign != null){ | ||
380 | + onVoteInfo(voteSign); | ||
381 | + } | ||
382 | + /*byte[] mBuffer = new byte[0x1F + 4]; | ||
383 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
384 | + mBuffer[0] = (byte) 0xF5; | ||
385 | + mBuffer[1] = (byte) 0xAA; | ||
386 | + mBuffer[2] = (byte) 0xAA; | ||
387 | + mBuffer[3] = (byte) 0x1F; | ||
388 | + | ||
389 | + mBuffer[4] = 0x70; | ||
390 | + mBuffer[5] = 0x04; | ||
391 | + writeToCom(mBuffer);*/ | ||
392 | + | ||
393 | + | ||
394 | + } | ||
395 | + | ||
396 | + @Override | ||
397 | + public void getKeypadParam() { | ||
398 | + byte[] mBuffer = new byte[0x1F + 4]; | ||
399 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
400 | + mBuffer[0] = (byte) 0xF5; | ||
401 | + mBuffer[1] = (byte) 0xAA; | ||
402 | + mBuffer[2] = (byte) 0xAA; | ||
403 | + mBuffer[3] = (byte) 0x1F; | ||
404 | + | ||
405 | + mBuffer[4] = 0x70; | ||
406 | + mBuffer[5] = 0x05; | ||
407 | + writeToCom(mBuffer); | ||
408 | + } | ||
409 | + | ||
410 | + @Override | ||
411 | + public void setKeypadParam(int keyId, byte[] KEYSN) { | ||
412 | + byte[] mBuffer = new byte[0x1F + 4]; | ||
413 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
414 | + mBuffer[0] = (byte) 0xF5; | ||
415 | + mBuffer[1] = (byte) 0xAA; | ||
416 | + mBuffer[2] = (byte) 0xAA; | ||
417 | + mBuffer[3] = (byte) 0x1F; | ||
418 | + | ||
419 | + mBuffer[4] = 0x70; | ||
420 | + mBuffer[5] = 0x06; | ||
421 | + | ||
422 | + mBuffer[6] = (byte) ((keyId >> 8) & 0xFF);// keyId | ||
423 | + mBuffer[7] = (byte) (keyId & 0xFF); | ||
424 | + | ||
425 | + // mBuffer[8] =(byte) 0xFF; | ||
426 | + System.arraycopy(KEYSN, 0, mBuffer, 8, 6); | ||
427 | + | ||
428 | + byte[] parecode = new byte[4]; | ||
429 | + Arrays.fill(parecode, (byte) 0xFF); | ||
430 | + System.arraycopy(KEYSN, 0, mBuffer, 14, 4); | ||
431 | + | ||
432 | + writeToCom(mBuffer); | ||
433 | + } | ||
434 | + | ||
435 | + @Override | ||
436 | + public void checkOnLine(int volt, int keyinStatus) { | ||
437 | + LogUtil.i(TAG ,"HEART BEAT(S):" + volt + " " + System.currentTimeMillis()); | ||
438 | + if (isInComCommunicationTest) { | ||
439 | + return; | ||
440 | + } | ||
441 | + byte[] mBuffer = new byte[0x1F + 4]; | ||
442 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
443 | + mBuffer[0] = (byte) 0xF5; | ||
444 | + mBuffer[1] = (byte) 0xAA; | ||
445 | + mBuffer[2] = (byte) 0xAA; | ||
446 | + mBuffer[3] = (byte) 0x1F; | ||
447 | + | ||
448 | + mBuffer[4] = 0x70; | ||
449 | + mBuffer[5] = 0x07; | ||
450 | + | ||
451 | + mBuffer[6] = (byte) volt; | ||
452 | + mBuffer[7] = (byte) keyinStatus; | ||
453 | + writeToCom(mBuffer); | ||
454 | + } | ||
455 | + | ||
456 | + @Override | ||
457 | + public void execKeypadMatch(int iMode, int channal) { | ||
458 | + byte[] mBuffer = new byte[0x1F + 4]; | ||
459 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
460 | + mBuffer[0] = (byte) 0xF5; | ||
461 | + mBuffer[1] = (byte) 0xAA; | ||
462 | + mBuffer[2] = (byte) 0xAA; | ||
463 | + mBuffer[3] = (byte) 0x1F; | ||
464 | + | ||
465 | + mBuffer[4] = 0x70; | ||
466 | + mBuffer[5] = 0x08; | ||
467 | + | ||
468 | + mBuffer[6] = (byte) iMode; | ||
469 | + mBuffer[7] = (byte) channal; | ||
470 | + writeToCom(mBuffer); | ||
471 | + } | ||
472 | + | ||
473 | + private boolean isInComCommunicationTest = false; | ||
474 | + | ||
475 | + @Override | ||
476 | + public void comCommunicationTest(int sendn, int okn) { | ||
477 | + isInComCommunicationTest = (sendn != 200); | ||
478 | + byte[] mBuffer = new byte[0x1F + 4]; | ||
479 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
480 | + mBuffer[0] = (byte) 0xF5; | ||
481 | + mBuffer[1] = (byte) 0xAA; | ||
482 | + mBuffer[2] = (byte) 0xAA; | ||
483 | + mBuffer[3] = (byte) 0x1F; | ||
484 | + | ||
485 | + mBuffer[4] = 0x30; | ||
486 | + mBuffer[5] = 0x0; | ||
487 | + mBuffer[6] = 0x0; | ||
488 | + | ||
489 | + mBuffer[7] = 7; | ||
490 | + mBuffer[8] = (byte) sendn; | ||
491 | + mBuffer[9] = (byte) okn; | ||
492 | + mBuffer[10] = (byte) 0xAA; | ||
493 | + | ||
494 | + for (int i = 1; i < 17; i++) { | ||
495 | + mBuffer[10 + i] = (byte) i; | ||
496 | + } | ||
497 | + | ||
498 | + writeToCom(mBuffer); | ||
499 | + } | ||
500 | + | ||
501 | + @Override | ||
502 | + public void submitVote(int ansType, String info) {// byte[] ansData | ||
503 | + | ||
504 | + LogUtil.i(TAG,"ansType:" + ansType + ",info:" + info); | ||
505 | + if (ansType == AnsType_Single) {// 单值 | ||
506 | + byte[] mBuffer = new byte[0x1F + 4]; | ||
507 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
508 | + mBuffer[0] = (byte) 0xF5; | ||
509 | + mBuffer[1] = (byte) 0xAA; | ||
510 | + mBuffer[2] = (byte) 0xAA; | ||
511 | + mBuffer[3] = (byte) 0x1F; | ||
512 | + | ||
513 | + mBuffer[4] = 0x73; | ||
514 | + mBuffer[5] = (byte) serialNumber;// 流水号 | ||
515 | + | ||
516 | + mBuffer[6] = 1;// MSGTYPE 1:ID mode, 2:SN | ||
517 | + mBuffer[7] = (byte) ansType; | ||
518 | + int val = Integer.parseInt(info); | ||
519 | + mBuffer[8] = (byte) val; | ||
520 | + | ||
521 | + VoteResultItem it = new VoteResultItem(); | ||
522 | + it.status = 0; | ||
523 | + it.ansType = ansType; | ||
524 | + it.ansCount = 1; | ||
525 | + it.serialNo = serialNumber; | ||
526 | + serialNumberInc(); | ||
527 | + it.data = mBuffer; | ||
528 | + addToSendQueen(it); | ||
529 | + } else if (ansType == AnsType_Select) { | ||
530 | + String[] ary = info.split(","); | ||
531 | + String val = ary[0]; | ||
532 | + int tm = Integer.parseInt(ary[1]); | ||
533 | + | ||
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 | + | ||
541 | + mBuffer[4] = 0x73; | ||
542 | + mBuffer[5] = (byte) serialNumber;// 流水号 | ||
543 | + | ||
544 | + mBuffer[6] = 1;// MSGTYPE 1:ID mode, 2:SN | ||
545 | + mBuffer[7] = (byte) ansType; | ||
546 | + | ||
547 | + ; | ||
548 | + mBuffer[8] = (byte) ((tm >> 8) & 0xff); | ||
549 | + mBuffer[9] = (byte) (tm & 0xff); | ||
550 | + | ||
551 | + mBuffer[10] = (byte) ((tm >> 8) & 0xff); | ||
552 | + mBuffer[11] = (byte) (tm & 0xff); | ||
553 | + | ||
554 | + VoteResultItem it = new VoteResultItem(); | ||
555 | + it.status = 0; | ||
556 | + it.ansType = ansType; | ||
557 | + it.ansCount = 1; | ||
558 | + it.serialNo = serialNumber; | ||
559 | + serialNumberInc(); | ||
560 | + it.data = mBuffer; | ||
561 | + addToSendQueen(it); | ||
562 | +// writeToCom(it.data); | ||
563 | + } else if (ansType == AnsType_Number) { | ||
564 | + byte[] mBuffer = new byte[0x1F + 4]; | ||
565 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
566 | + mBuffer[0] = (byte) 0xF5; | ||
567 | + mBuffer[1] = (byte) 0xAA; | ||
568 | + mBuffer[2] = (byte) 0xAA; | ||
569 | + mBuffer[3] = (byte) 0x1F; | ||
570 | + | ||
571 | + mBuffer[4] = 0x73; | ||
572 | + mBuffer[5] = (byte) serialNumber;// 流水号 | ||
573 | + | ||
574 | + mBuffer[6] = 1;// MSGTYPE 1:ID mode, 2:SN | ||
575 | + mBuffer[7] = (byte) ansType; | ||
576 | + | ||
577 | + byte[] val = util_encodeBCD(info.getBytes()); | ||
578 | + System.arraycopy(val, 0, mBuffer, 8, 8); | ||
579 | + | ||
580 | + VoteResultItem it = new VoteResultItem(); | ||
581 | + it.status = 0; | ||
582 | + it.ansType = ansType; | ||
583 | + it.ansCount = 1; | ||
584 | + it.serialNo = serialNumber; | ||
585 | + serialNumberInc(); | ||
586 | + it.data = mBuffer; | ||
587 | + addToSendQueen(it); | ||
588 | + } else if (ansType == AnsType_LoginIn) { | ||
589 | + byte[] mBuffer = new byte[0x1F + 4]; | ||
590 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
591 | + mBuffer[0] = (byte) 0xF5; | ||
592 | + mBuffer[1] = (byte) 0xAA; | ||
593 | + mBuffer[2] = (byte) 0xAA; | ||
594 | + mBuffer[3] = (byte) 0x1F; | ||
595 | + | ||
596 | + mBuffer[4] = 0x73; | ||
597 | + mBuffer[5] = (byte) serialNumber;// 流水号 | ||
598 | + | ||
599 | + mBuffer[6] = 1;// MSGTYPE 1:ID mode, 2:SN | ||
600 | + mBuffer[7] = (byte) ansType; | ||
601 | + mBuffer[8] = 3;//3 签到信息按BCD码格式 | ||
602 | + byte[] val = util_encodeBCD(info.getBytes()); | ||
603 | + System.arraycopy(val, 0, mBuffer, 9, 9); | ||
604 | + | ||
605 | + VoteResultItem it = new VoteResultItem(); | ||
606 | + it.status = 0; | ||
607 | + it.ansType = ansType; | ||
608 | + it.ansCount = 1; | ||
609 | + it.serialNo = serialNumber; | ||
610 | + serialNumberInc(); | ||
611 | + it.data = mBuffer; | ||
612 | + addToSendQueen(it); | ||
613 | + | ||
614 | + } else if (ansType == AnsType_BatchSingle) { | ||
615 | + | ||
616 | + // String[] ary= info.split(","); | ||
617 | + | ||
618 | + byte[] mBuffer = new byte[0x1F + 4]; | ||
619 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
620 | + mBuffer[0] = (byte) 0xF5; | ||
621 | + mBuffer[1] = (byte) 0xAA; | ||
622 | + mBuffer[2] = (byte) 0xAA; | ||
623 | + mBuffer[3] = (byte) 0x1F; | ||
624 | + | ||
625 | + mBuffer[4] = 0x73; | ||
626 | + mBuffer[5] = (byte) serialNumber;// 流水号 | ||
627 | + | ||
628 | + mBuffer[6] = 1;// MSGTYPE 1:ID mode, 2:SN | ||
629 | + mBuffer[7] = (byte) ansType; | ||
630 | + mBuffer[8] = 0;// ALLOK | ||
631 | + int pos = 9; | ||
632 | + | ||
633 | + String[] item = info.split(":"); | ||
634 | + if (item.length > 1) { | ||
635 | + int num = Integer.parseInt(item[0]); | ||
636 | + int val = Integer.parseInt(item[1]); | ||
637 | + mBuffer[pos++] = (byte) (num >> 8); | ||
638 | + mBuffer[pos++] = (byte) (num & 0xff); | ||
639 | + mBuffer[pos++] = (byte) val; | ||
640 | + } | ||
641 | + | ||
642 | + VoteResultItem it = new VoteResultItem(); | ||
643 | + it.status = 0; | ||
644 | + it.ansType = ansType; | ||
645 | + it.serialNo = serialNumber; | ||
646 | + serialNumberInc(); | ||
647 | + it.ansCount = 1; | ||
648 | + it.data = mBuffer; | ||
649 | + addToSendQueen(it); | ||
650 | + } else if (ansType == AnsType_BatchNumber) { | ||
651 | + byte[] mBuffer = new byte[0x1F + 4]; | ||
652 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
653 | + mBuffer[0] = (byte) 0xF5; | ||
654 | + mBuffer[1] = (byte) 0xAA; | ||
655 | + mBuffer[2] = (byte) 0xAA; | ||
656 | + mBuffer[3] = (byte) 0x1F; | ||
657 | + | ||
658 | + mBuffer[4] = 0x73; | ||
659 | + mBuffer[5] = (byte) serialNumber;// 流水号 | ||
660 | + | ||
661 | + mBuffer[6] = 1;// MSGTYPE 1:ID mode, 2:SN | ||
662 | + mBuffer[7] = (byte) ansType; | ||
663 | + mBuffer[8] = 0;// ALLOK | ||
664 | + | ||
665 | + String[] item = info.split(":"); | ||
666 | + if (item.length > 1) { | ||
667 | + String[] itIndex = item[0].split("_"); | ||
668 | + if (itIndex.length == 2) { //综合测评 | ||
669 | + int personId = Integer.parseInt(itIndex[0]); | ||
670 | + int projectId = Integer.parseInt(itIndex[1]); | ||
671 | + mBuffer[9] = (byte) personId; | ||
672 | + mBuffer[10] = (byte) projectId; | ||
673 | + } else { | ||
674 | + int num = Integer.parseInt(item[0]); | ||
675 | + mBuffer[9] = (byte) (num >> 8); | ||
676 | + mBuffer[10] = (byte) (num & 0xff); | ||
677 | + } | ||
678 | + String strNum = item[1]; | ||
679 | + byte[] val = util_encodeBCD(strNum.getBytes()); | ||
680 | + System.arraycopy(val, 0, mBuffer, 11, 4); | ||
681 | + } | ||
682 | + | ||
683 | + VoteResultItem it = new VoteResultItem(); | ||
684 | + it.status = 0; | ||
685 | + it.ansType = ansType; | ||
686 | + it.serialNo = serialNumber; | ||
687 | + serialNumberInc(); | ||
688 | + it.ansCount = 1; | ||
689 | + it.data = mBuffer; | ||
690 | + addToSendQueen(it); | ||
691 | + | ||
692 | + } else if (ansType == AnsType_SelectOther) { | ||
693 | + byte[] mBuffer = new byte[0x1F + 4]; | ||
694 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
695 | + mBuffer[0] = (byte) 0xF5; | ||
696 | + mBuffer[1] = (byte) 0xAA; | ||
697 | + mBuffer[2] = (byte) 0xAA; | ||
698 | + mBuffer[3] = (byte) 0x1F; | ||
699 | + | ||
700 | + mBuffer[4] = 0x73; | ||
701 | + mBuffer[5] = (byte) serialNumber;// 流水号 | ||
702 | + | ||
703 | + mBuffer[6] = 1;// MSGTYPE 1:ID mode, 2:SN | ||
704 | + mBuffer[7] = (byte) ansType; | ||
705 | + mBuffer[8] = 0;// ALLOK | ||
706 | + int pos = 9; | ||
707 | + | ||
708 | + String[] item = info.split(":"); | ||
709 | + if (item.length > 1) { | ||
710 | + int num = Integer.parseInt(item[0]); | ||
711 | + String val = item[1]; | ||
712 | + mBuffer[pos++] = (byte) (num >> 8); | ||
713 | + mBuffer[pos++] = (byte) num; | ||
714 | + | ||
715 | + mBuffer[pos++] = 0;// slot | ||
716 | + try { | ||
717 | + byte[] name = val.getBytes("GB2312"); | ||
718 | + | ||
719 | + System.arraycopy(name, 0, mBuffer, pos, name.length > 16 ? 16 : name.length); | ||
720 | + | ||
721 | + } catch (UnsupportedEncodingException e) { | ||
722 | + e.printStackTrace(); | ||
723 | + } | ||
724 | + // 名字最多16 | ||
725 | + } | ||
726 | + | ||
727 | + VoteResultItem it = new VoteResultItem(); | ||
728 | + it.status = 0; | ||
729 | + it.ansType = ansType; | ||
730 | + it.serialNo = serialNumber; | ||
731 | + serialNumberInc(); | ||
732 | + it.ansCount = 1; | ||
733 | + it.data = mBuffer; | ||
734 | + addToSendQueen(it); | ||
735 | + | ||
736 | + } else if (ansType == AnsType_Service) { | ||
737 | + byte[] mBuffer = new byte[0x1F + 4]; | ||
738 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
739 | + mBuffer[0] = (byte) 0xF5; | ||
740 | + mBuffer[1] = (byte) 0xAA; | ||
741 | + mBuffer[2] = (byte) 0xAA; | ||
742 | + mBuffer[3] = (byte) 0x1F; | ||
743 | + | ||
744 | + mBuffer[4] = 0x73; | ||
745 | + mBuffer[5] = (byte) serialNumber;// 流水号 | ||
746 | + | ||
747 | + mBuffer[6] = 1;// MSGTYPE 1:ID mode, 2:SN | ||
748 | + mBuffer[7] = (byte) ansType; | ||
749 | + mBuffer[8] = 4; | ||
750 | + int serv_type = Integer.parseInt(info); | ||
751 | + mBuffer[9] = (byte) serv_type; | ||
752 | + | ||
753 | + mBuffer[10] = (byte) serialNumber; | ||
754 | + | ||
755 | + VoteResultItem it = new VoteResultItem(); | ||
756 | + | ||
757 | + serviceSerialNumber = serialNumber; | ||
758 | + | ||
759 | + it.status = 0; | ||
760 | + it.ansType = ansType; | ||
761 | + it.serialNo = serialNumber; | ||
762 | + serialNumberInc(); | ||
763 | + it.ansCount = 1; | ||
764 | + it.data = mBuffer; | ||
765 | + addToSendQueen(it); | ||
766 | + | ||
767 | + } | ||
768 | + } | ||
769 | + | ||
770 | + private int ChoiceValueToInt(String val) { | ||
771 | + int ret = 0; | ||
772 | + for (int i = 0; i < val.length(); i++) { | ||
773 | + char cc = val.charAt(i); | ||
774 | + if (cc < 'I') { | ||
775 | + ret |= 1 << (8 + (cc - 'A')); | ||
776 | + } else { | ||
777 | + ret |= 1 << (cc - 'I'); | ||
778 | + } | ||
779 | + | ||
780 | + } | ||
781 | + | ||
782 | + return ret; | ||
783 | + } | ||
784 | + | ||
785 | + public void submitVoteFource(int ansType, String info) { | ||
786 | + byte[] mBuffer = new byte[0x1F + 4]; | ||
787 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
788 | + mBuffer[0] = (byte) 0xF5; | ||
789 | + mBuffer[1] = (byte) 0xAA; | ||
790 | + mBuffer[2] = (byte) 0xAA; | ||
791 | + mBuffer[3] = (byte) 0x1F; | ||
792 | + | ||
793 | + mBuffer[4] = 0x73; | ||
794 | + mBuffer[5] = (byte) serialNumber;// 流水号 | ||
795 | + | ||
796 | + mBuffer[6] = 1;// MSGTYPE 1:ID mode, 2:SN | ||
797 | + mBuffer[7] = (byte) ansType; | ||
798 | + mBuffer[8] = 0;// ALLOK | ||
799 | + int pos = 9; | ||
800 | + | ||
801 | + String[] item = info.split(":"); | ||
802 | + if (item.length > 1) { | ||
803 | + int num = Integer.parseInt(item[0]); | ||
804 | + String val = item[1]; | ||
805 | + mBuffer[pos++] = (byte) (num >> 8); | ||
806 | + mBuffer[pos++] = (byte) num; | ||
807 | + | ||
808 | + mBuffer[pos++] = 0;// slot | ||
809 | + try { | ||
810 | + byte[] name = val.getBytes("GB2312"); | ||
811 | + | ||
812 | + System.arraycopy(name, 0, mBuffer, pos, name.length > 16 ? 16 : name.length); | ||
813 | + | ||
814 | + } catch (UnsupportedEncodingException e) { | ||
815 | + // TODO Auto-generated catch block | ||
816 | + e.printStackTrace(); | ||
817 | + } | ||
818 | + // 名字最多16 | ||
819 | + } | ||
820 | + | ||
821 | + VoteResultItem it = new VoteResultItem(); | ||
822 | + it.status = 0; | ||
823 | + it.ansType = ansType; | ||
824 | + it.serialNo = serialNumber; | ||
825 | + serialNumberInc(); | ||
826 | + it.ansCount = 1; | ||
827 | + it.data = mBuffer; | ||
828 | + addToSendQueen(it); | ||
829 | + } | ||
830 | + | ||
831 | + @Override | ||
832 | + public void submitVoteAllOK() { | ||
833 | + int allokSerialNum = 0xff; | ||
834 | + byte[] mBuffer = new byte[0x1F + 4]; | ||
835 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
836 | + mBuffer[0] = (byte) 0xF5; | ||
837 | + mBuffer[1] = (byte) 0xAA; | ||
838 | + mBuffer[2] = (byte) 0xAA; | ||
839 | + mBuffer[3] = (byte) 0x1F; | ||
840 | + | ||
841 | + mBuffer[4] = 0x73; | ||
842 | + mBuffer[5] = (byte) allokSerialNum;// 流水号 | ||
843 | + | ||
844 | + mBuffer[6] = 1;// MSGTYPE 1:ID mode, 2:SN | ||
845 | + mBuffer[7] = (byte) AnsType_BatchSingle; | ||
846 | + mBuffer[8] = 1;// ALLOK | ||
847 | + | ||
848 | + VoteResultItem it = new VoteResultItem(); | ||
849 | + it.status = 0; | ||
850 | + it.ansType = AnsType_BatchSingle; | ||
851 | + it.serialNo = allokSerialNum; | ||
852 | + allOkSerialNumber = allokSerialNum; | ||
853 | + it.ansCount = 1; | ||
854 | + it.allOK = 1; | ||
855 | + it.data = mBuffer; | ||
856 | + addToSendQueen(it); | ||
857 | + | ||
858 | + } | ||
859 | + | ||
860 | + public void submitVoteAllOKWithValue(int ansType, String info) { | ||
861 | + LogUtil.i(TAG,"ansType:" + ansType + ",info:" + info); | ||
862 | + int allokSerialNum = 0xff; | ||
863 | + byte[] mBuffer = new byte[0x1F + 4]; | ||
864 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
865 | + mBuffer[0] = (byte) 0xF5; | ||
866 | + mBuffer[1] = (byte) 0xAA; | ||
867 | + mBuffer[2] = (byte) 0xAA; | ||
868 | + mBuffer[3] = (byte) 0x1F; | ||
869 | + | ||
870 | + mBuffer[4] = 0x73; | ||
871 | + mBuffer[5] = (byte) allokSerialNum;// 流水号 | ||
872 | + | ||
873 | + mBuffer[6] = 1;// MSGTYPE 1:ID mode, 2:SN | ||
874 | + mBuffer[7] = (byte) ansType; | ||
875 | + mBuffer[8] = 1;// ALLOK | ||
876 | + | ||
877 | + String[] item = info.split(":"); | ||
878 | + if (item.length > 1) { | ||
879 | + String[] itIndex = item[0].split("_"); | ||
880 | + if (itIndex.length == 2) { //综合测评 | ||
881 | + int personId = Integer.parseInt(itIndex[0]); | ||
882 | + int projectId = Integer.parseInt(itIndex[1]); | ||
883 | + mBuffer[9] = (byte) personId; | ||
884 | + mBuffer[10] = (byte) projectId; | ||
885 | + } else { | ||
886 | + int num = Integer.parseInt(item[0]); | ||
887 | + mBuffer[9] = (byte) (num >> 8); | ||
888 | + mBuffer[10] = (byte) (num & 0xff); | ||
889 | + } | ||
890 | + String strNum = item[1]; | ||
891 | + byte[] val = util_encodeBCD(strNum.getBytes()); | ||
892 | + System.arraycopy(val, 0, mBuffer, 11, 4); | ||
893 | + } | ||
1050 | 894 | ||
1051 | - SerDataRx[iSerRxN] = comBuffer[i];// 先保存数据 | ||
1052 | - switch (iSerRxN) { | ||
1053 | - case 0: | ||
1054 | - if (dd == 0xF5) { | ||
1055 | - iSerRxN++; | 895 | + VoteResultItem it = new VoteResultItem(); |
896 | + it.status = 0; | ||
897 | + it.ansType = ansType; | ||
898 | + it.serialNo = allokSerialNum; | ||
899 | + allOkSerialNumber = allokSerialNum; | ||
900 | + it.ansCount = 1; | ||
901 | + it.allOK = 1; | ||
902 | + it.data = mBuffer; | ||
903 | + addToSendQueen(it); | ||
904 | + | ||
905 | + } | ||
906 | + | ||
907 | + @Override | ||
908 | + public void cancelSubmitVoteAllOK() { | ||
909 | + int cancelAllokSerialNum = 0xfe; | ||
910 | + byte[] mBuffer = new byte[0x1F + 4]; | ||
911 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
912 | + mBuffer[0] = (byte) 0xF5; | ||
913 | + mBuffer[1] = (byte) 0xAA; | ||
914 | + mBuffer[2] = (byte) 0xAA; | ||
915 | + mBuffer[3] = (byte) 0x1F; | ||
916 | + | ||
917 | + mBuffer[4] = 0x73; | ||
918 | + mBuffer[5] = (byte) cancelAllokSerialNum;// 流水号 | ||
919 | + | ||
920 | + mBuffer[6] = 1;// MSGTYPE 1:ID mode, 2:SN | ||
921 | + mBuffer[7] = (byte) AnsType_BatchSingle; | ||
922 | + mBuffer[8] = 0;// ALLOK | ||
923 | + | ||
924 | + VoteResultItem it = new VoteResultItem(); | ||
925 | + it.status = 0; | ||
926 | + it.ansType = AnsType_BatchSingle; | ||
927 | + it.serialNo = cancelAllokSerialNum; | ||
928 | + | ||
929 | + it.ansCount = 1; | ||
930 | + it.allOK = 0; | ||
931 | + it.data = mBuffer; | ||
932 | + addToSendQueen(it); | ||
933 | + | ||
934 | + //serialNumber=0; | ||
935 | + } | ||
936 | + | ||
937 | + private void serialNumberInc() { | ||
938 | + serialNumber++; | ||
939 | + if (serialNumber == 0xfe) { | ||
940 | + serialNumber = 0; | ||
941 | + } | ||
942 | + } | ||
943 | + | ||
944 | + @Override | ||
945 | + public void submitSelectOther(String info) { | ||
946 | + // TODO Auto-generated method stub | ||
947 | + | ||
948 | + } | ||
949 | + | ||
950 | + @Override | ||
951 | + public void submitVoteBySn(byte[] keySn, String info) { | ||
952 | + byte[] mBuffer = new byte[0x1F + 4]; | ||
953 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
954 | + mBuffer[0] = (byte) 0xF5; | ||
955 | + mBuffer[1] = (byte) 0xAA; | ||
956 | + mBuffer[2] = (byte) 0xAA; | ||
957 | + mBuffer[3] = (byte) 0x1F; | ||
958 | + | ||
959 | + mBuffer[4] = 0x73; | ||
960 | + mBuffer[5] = 0x08;// 流水号 | ||
961 | + | ||
962 | + mBuffer[6] = 2;// MSGTYPE | ||
963 | + | ||
964 | + mBuffer[7] = 1;// ANSTYPE | ||
965 | + | ||
966 | + System.arraycopy(keySn, 0, mBuffer, 8, 6);// keysn | ||
967 | + // System.arraycopy(ansData, 0, mBuffer, 8, | ||
968 | + // ansData.length<=16?ansData.length:16); | ||
969 | + // info??? | ||
970 | + writeToCom(mBuffer); | ||
971 | + } | ||
972 | + | ||
973 | + @Override | ||
974 | + public void sendCmdData(int cmdId, byte[] data) { | ||
975 | + byte[] mBuffer = new byte[0x1F + 4]; | ||
976 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
977 | + mBuffer[0] = (byte) 0xF5; | ||
978 | + mBuffer[1] = (byte) 0xAA; | ||
979 | + mBuffer[2] = (byte) 0xAA; | ||
980 | + mBuffer[3] = (byte) 0x1F; | ||
981 | + | ||
982 | + mBuffer[4] = (byte) 0xB0;// 0x30 表决器下载单包类指令 | ||
983 | + | ||
984 | + mBuffer[5] = 0x0;// keyid 填 0 | ||
985 | + mBuffer[6] = 0x0;// keyid | ||
986 | + | ||
987 | + mBuffer[7] = (byte) cmdId;// KCMD | ||
988 | + System.arraycopy(data, 0, mBuffer, 8, data.length);// keysn | ||
989 | + | ||
990 | + writeToCom(mBuffer); | ||
991 | + } | ||
992 | + | ||
993 | + @Override | ||
994 | + public void configMode() { | ||
995 | + byte[] mBuffer = new byte[0x1F + 4]; | ||
996 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
997 | + mBuffer[0] = (byte) 0xF5; | ||
998 | + mBuffer[1] = (byte) 0xAA; | ||
999 | + mBuffer[2] = (byte) 0xAA; | ||
1000 | + mBuffer[3] = (byte) 0x1F; | ||
1001 | + | ||
1002 | + mBuffer[4] = 0x70; | ||
1003 | + mBuffer[5] = 0x09; | ||
1004 | + | ||
1005 | + writeToCom(mBuffer); | ||
1006 | + | ||
1007 | + } | ||
1008 | + | ||
1009 | + private byte[] firmFileBuffer; | ||
1010 | + private int firmWritePage; | ||
1011 | + private int firmWritePageMax; | ||
1012 | + | ||
1013 | + @Override | ||
1014 | + public void startFirmUpdate(byte[] fileBuffer) { | ||
1015 | + firmFileBuffer = fileBuffer; | ||
1016 | + compareCount = 0 ; | ||
1017 | + taskHandler.post(updateTask); | ||
1018 | + } | ||
1019 | + | ||
1020 | + private void keepFirmMode() { | ||
1021 | + byte[] mBuffer = new byte[0x1F + 4]; | ||
1022 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
1023 | + mBuffer[0] = (byte) 0xF5; | ||
1024 | + mBuffer[1] = (byte) 0xAA; | ||
1025 | + mBuffer[2] = (byte) 0xAA; | ||
1026 | + mBuffer[3] = (byte) 10; | ||
1027 | + | ||
1028 | + mBuffer[4] = 0x78; | ||
1029 | + mBuffer[5] = 0x02; | ||
1030 | + | ||
1031 | + writeToCom(mBuffer); | ||
1032 | + } | ||
1033 | + | ||
1034 | + private void eraseFlash() { | ||
1035 | + int file_len = firmFileBuffer.length; | ||
1036 | + byte[] mBuffer = new byte[0x1F + 4]; | ||
1037 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
1038 | + mBuffer[0] = (byte) 0xF5; | ||
1039 | + mBuffer[1] = (byte) 0xAA; | ||
1040 | + mBuffer[2] = (byte) 0xAA; | ||
1041 | + mBuffer[3] = (byte) 10; | ||
1042 | + mBuffer[4] = 0x78; | ||
1043 | + mBuffer[5] = 0x03; | ||
1044 | + mBuffer[6] = 0; | ||
1045 | + mBuffer[7] = (byte) (file_len / 1024); | ||
1046 | + writeToCom(mBuffer); | ||
1047 | + | ||
1048 | + } | ||
1049 | + | ||
1050 | + private Runnable updateTask = new Runnable() { | ||
1051 | + @Override | ||
1052 | + public void run() { | ||
1053 | + firmWritePage = 0; | ||
1054 | + firmWritePageMax = firmFileBuffer.length / 32; | ||
1055 | + if (firmWritePageMax % 32 > 0) { | ||
1056 | + firmWritePageMax++; | ||
1057 | + } | ||
1058 | + | ||
1059 | + byte[] mBuffer = new byte[0x1F + 4]; | ||
1060 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
1061 | + mBuffer[0] = (byte) 0xF5; | ||
1062 | + mBuffer[1] = (byte) 0xAA; | ||
1063 | + mBuffer[2] = (byte) 0xAA; | ||
1064 | + mBuffer[3] = (byte) 10; | ||
1065 | + mBuffer[4] = 0x78; | ||
1066 | + mBuffer[5] = 0x01; | ||
1067 | + writeToCom(mBuffer); | ||
1068 | + if(compareCount < 20){ | ||
1069 | + compareCount++; | ||
1070 | + taskHandler.postDelayed(this,1000); | ||
1071 | + } | ||
1072 | + } | ||
1073 | + }; | ||
1074 | + | ||
1075 | + private void writeFlash(int page) { | ||
1076 | + byte[] mBuffer = new byte[38 + 4]; | ||
1077 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
1078 | + mBuffer[0] = (byte) 0xF5; | ||
1079 | + mBuffer[1] = (byte) 0xAA; | ||
1080 | + mBuffer[2] = (byte) 0xAA; | ||
1081 | + mBuffer[3] = (byte) 38; | ||
1082 | + | ||
1083 | + mBuffer[4] = 0x78; | ||
1084 | + mBuffer[5] = 0x04; | ||
1085 | + | ||
1086 | + mBuffer[6] = (byte) (page / 256); | ||
1087 | + mBuffer[7] = (byte) (page % 256); | ||
1088 | + int pos = 0; | ||
1089 | + for (int i = 0; i < 32; i++) { | ||
1090 | + pos = page * 32 + i; | ||
1091 | + if (pos == firmFileBuffer.length - 1) { | ||
1092 | + break; | ||
1093 | + } | ||
1094 | + mBuffer[8 + i] = firmFileBuffer[pos]; | ||
1095 | + } | ||
1096 | + LogUtil.d(TAG, "write flash page:" + page); | ||
1097 | + writeToCom(mBuffer); | ||
1098 | + } | ||
1099 | + | ||
1100 | + /* | ||
1101 | + * status 1: success 2 : fail | ||
1102 | + */ | ||
1103 | + private void exitFirmUpdate(int status) { | ||
1104 | + byte[] mBuffer = new byte[0x1F + 4]; | ||
1105 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
1106 | + mBuffer[0] = (byte) 0xF5; | ||
1107 | + mBuffer[1] = (byte) 0xAA; | ||
1108 | + mBuffer[2] = (byte) 0xAA; | ||
1109 | + mBuffer[3] = (byte) 10; | ||
1110 | + | ||
1111 | + mBuffer[4] = 0x78; | ||
1112 | + mBuffer[5] = 5; | ||
1113 | + mBuffer[6] = (byte) status; | ||
1114 | + writeToCom(mBuffer); | ||
1115 | + } | ||
1116 | + | ||
1117 | + private void writeToCom(byte[] data) { | ||
1118 | + if (mOutputStream != null) { | ||
1119 | + try { | ||
1120 | + int crcValue = Crc16.getUnsignedShort(Crc16.crc16(data, data.length - 4 - 2)); | ||
1121 | + data[data.length - 2] = (byte) (crcValue >> 8); | ||
1122 | + data[data.length - 1] = (byte) (crcValue); | ||
1123 | + | ||
1124 | + if (isShowLog) { | ||
1125 | + if (data[4] == 0x70 && data[5] == 0x07) { | ||
1126 | + // LogUtil.d(TAG, "check online"); | ||
1127 | + if (isShowOnlineLog) { | ||
1128 | + printDataBuf(data, data.length, "send:"); | ||
1056 | } | 1129 | } |
1057 | - break; | ||
1058 | - case 1: | ||
1059 | - if (dd == 0xAA) | ||
1060 | - iSerRxN++; | ||
1061 | - else { | ||
1062 | - if (dd == 0xF5) | ||
1063 | - iSerRxN = 1; | ||
1064 | - else | ||
1065 | - iSerRxN = 0; | 1130 | + } else { |
1131 | + printDataBuf(data, data.length, "send:"); | ||
1132 | + } | ||
1133 | + } | ||
1134 | + | ||
1135 | + mOutputStream.write(data); | ||
1136 | + } catch (IOException e) { | ||
1137 | + e.printStackTrace(); | ||
1138 | + } | ||
1139 | + | ||
1140 | + m_listener.onSendData(data, data.length); | ||
1141 | + } | ||
1142 | + } | ||
1143 | + | ||
1144 | + private byte[] SerDataRx = new byte[1024]; | ||
1145 | + int iSerRxN = 0; | ||
1146 | + private byte[] comBuffer = new byte[1024]; | ||
1147 | + | ||
1148 | + private class ReadThread extends Thread { | ||
1149 | + | ||
1150 | + @Override | ||
1151 | + public void run() { | ||
1152 | + super.run(); | ||
1153 | + LogUtil.d(TAG, "Xpad ReadThread running "); | ||
1154 | + if (mInputStream != null) { | ||
1155 | + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
1156 | + byte[] bytes = new byte[1024]; | ||
1157 | + int tmpLength = -1; | ||
1158 | + while (!isInterrupted()) { | ||
1159 | + try { | ||
1160 | +// tmpLength = mInputStream.read(bytes); | ||
1161 | + bytes = UsbTransferManager.getInstance().receiveUsbRequestData(); | ||
1162 | + if(bytes == null){ | ||
1163 | + continue; | ||
1066 | } | 1164 | } |
1067 | - break; | ||
1068 | - case 2: | ||
1069 | - if (dd == 0xAA) | ||
1070 | - iSerRxN++; | ||
1071 | - else { | ||
1072 | - if (dd == 0xF5) | ||
1073 | - iSerRxN = 1; | ||
1074 | - else | ||
1075 | - iSerRxN = 0; | 1165 | + tmpLength = bytes.length; |
1166 | + if (tmpLength < 0) { | ||
1167 | + break; | ||
1076 | } | 1168 | } |
1077 | - break; | ||
1078 | - case 3:// len | ||
1079 | - if (dd > 128) // C_SERMAXN | ||
1080 | - iSerRxN = 0; | ||
1081 | - else { | ||
1082 | - iSerRxN++; | 1169 | + // 1. 先检测读取数据到缓冲区 |
1170 | + byteArrayOutputStream.write(bytes, 0, tmpLength); | ||
1171 | + // 2. 判断缓冲区的数据标志是否存在 | ||
1172 | + if (byteArrayOutputStream.size() >= 3) { | ||
1173 | + byte[] temp = byteArrayOutputStream.toByteArray(); | ||
1174 | + int find = ByteUtils.findBytes(temp, new byte[]{(byte) 0xF5, (byte) 0xAA, (byte) 0xAA}, 0); | ||
1175 | + if (find >= 0) { | ||
1176 | + // 3. 标志存在,则继续读取长度 | ||
1177 | + if (byteArrayOutputStream.size() >= find + 4) { | ||
1178 | + int length = ByteUtils.byte1ToInt(byteArrayOutputStream.toByteArray()[find + 3]); | ||
1179 | + if (byteArrayOutputStream.size() >= find + 4 + length) { | ||
1180 | + ByteArrayOutputStream tmp = new ByteArrayOutputStream(); | ||
1181 | + // 4. 根据长度读取包的内容 | ||
1182 | + for (int i = find; i < find + 4 + length; i++) { | ||
1183 | + // 5. 截取包的内容,向外抛出,处理,接着读取下一个包 | ||
1184 | + tmp.write(temp[i]); | ||
1185 | + } | ||
1186 | + | ||
1187 | + //CRC 校验 | ||
1188 | + byte[] datas = tmp.toByteArray(); | ||
1189 | + LogUtil.i(TAG, "RECEIVER DATA:", datas); | ||
1190 | + | ||
1191 | + try { | ||
1192 | + //处理 | ||
1193 | + if(Crc16.checkPack(datas)){ | ||
1194 | + int crc = Crc16.getUnsignedShort(Crc16.crc16(datas,length - 2)); | ||
1195 | + int originCrcValue = 0; | ||
1196 | + originCrcValue |= (datas[length + 2] & 0xff) << 8; | ||
1197 | + originCrcValue |= datas[length + 3] & 0xff; | ||
1198 | + if(crc == originCrcValue){ | ||
1199 | + checkComData(datas, tmp.size()); | ||
1200 | + } | ||
1201 | + } | ||
1202 | + } catch (Exception ex) { | ||
1203 | + LogUtil.i(TAG, "处理命令出错:", ex); | ||
1204 | + } | ||
1205 | + // 7. 剩余数据重新打包处理 | ||
1206 | +// byteArrayOutputStream = new ByteArrayOutputStream(); | ||
1207 | + byteArrayOutputStream.reset(); | ||
1208 | + for (int i = find + 4 + length; i < temp.length; i++) { | ||
1209 | + byteArrayOutputStream.write(temp[i]); | ||
1210 | + } | ||
1211 | + } | ||
1212 | + } | ||
1213 | + } | ||
1083 | } | 1214 | } |
1084 | - break; | ||
1085 | - default: | ||
1086 | - iSerRxN++; | ||
1087 | - rxDataLen = SerDataRx[3] + 4;// len | ||
1088 | - if (rxDataLen <= 3) | ||
1089 | - break; | ||
1090 | - if (iSerRxN == rxDataLen) { | ||
1091 | - if (Crc16.checkPack(SerDataRx)) { | ||
1092 | - int crcValue = Crc16 | ||
1093 | - .getUnsignedShort(Crc16.crc16(SerDataRx, rxDataLen - 4 - 2)); | ||
1094 | - int originCrcValue = 0; | ||
1095 | - originCrcValue |= (SerDataRx[rxDataLen - 2] & 0xff) << 8; | ||
1096 | - originCrcValue |= SerDataRx[rxDataLen - 1] & 0xff; | 1215 | + if (byteArrayOutputStream.size() > 2048) { |
1216 | + LogUtil.i(TAG, "被恶意攻击?或者传输数据错误?丢弃处理!", byteArrayOutputStream.toByteArray()); | ||
1217 | + byteArrayOutputStream.reset(); | ||
1218 | + } | ||
1219 | + } catch (Exception e) { | ||
1220 | + LogUtil.e(TAG, e); | ||
1221 | + } | ||
1222 | + } | ||
1223 | + } | ||
1224 | + } | ||
1225 | + @SuppressLint("NewApi") | ||
1226 | + private void checkComData(byte[] data, int size) { | ||
1227 | + m_listener.onComData(data, size); | ||
1228 | + int cmd = data[4] & 0xFF; | ||
1229 | + switch (cmd) { | ||
1230 | + case CMD_CHECK_BASE_STATUS_RESPONSE:// 查询状态类指令应答 | ||
1231 | + int cmd1 = data[5] & 0xFF; | ||
1232 | + if (cmd1 == 1) {// 返回当前工作模式和版本 | ||
1233 | + ModelInfo info = new ModelInfo(); | ||
1234 | + info.mode = data[6]; | ||
1235 | + info.hModel = data[7] & 0xff; | ||
1236 | + info.sVer = data[8] + "." + data[9] + "." + data[10]; | ||
1237 | + m_listener.onModelEvent(info); | ||
1238 | + } else if (cmd1 == 3) { // 查询基础信标 结果 | ||
1239 | + onBaseInfo(data); | ||
1240 | + } else if (cmd1 == 4) { // 查询投票信标 结果 | ||
1241 | + onVoteInfo(data); | ||
1242 | + } else if (cmd1 == 5 || cmd1 == 6) {// 返回当前键盘参数结果 | ||
1243 | + info.ok = data[6]; | ||
1244 | + info.chan = data[7]; | ||
1245 | + info.keyId = ((data[8] & 0xff) << 8) | (data[9] & 0xff); | ||
1246 | + byte[] sn = Arrays.copyOfRange(data, 10, 16); | ||
1247 | + info.keySn = getKeySn(sn); | ||
1248 | + byte[] mc = Arrays.copyOfRange(data, 16, 19); | ||
1249 | + info.matchCode = new String(mc); | ||
1250 | + m_listener.onKeyPadEvent(info); | ||
1251 | + | ||
1252 | + // if(!hasGetBaseInfo){ //第一次启动时取 | ||
1253 | + // hasGetBaseInfo = true; | ||
1254 | + // getBaseStatus(); | ||
1255 | + // } | ||
1256 | + | ||
1257 | + } else if (cmd1 == 7) {// 查询键盘在线状态结果 | ||
1258 | + OnLineInfo info = new OnLineInfo(); | ||
1259 | + info.onLine = data[6]; | ||
1260 | + info.idMode = data[7]; | ||
1261 | + info.chan = data[8] & 0xff; | ||
1262 | + info.rssi = data[9] & 0xff; | ||
1263 | + LogUtil.i(TAG ,"HEART BEAT(R):" + info.chan + " " + System.currentTimeMillis()); | ||
1264 | + info.tx = data[10]; | ||
1265 | + info.rx = data[11]; | ||
1266 | + info.baseId = data[12] & 0xff; | ||
1267 | + info.keyId = ((data[13] & 0xff) << 8) | (data[14] & 0xff); | ||
1268 | + RFFileUploadModule.getInstance().setKeyid(data,13); | ||
1269 | + byte[] sn = Arrays.copyOfRange(data, 15, 21); | ||
1270 | + info.keySn = getKeySn(sn); | ||
1271 | + m_listener.onOnLineEvent(info); | ||
1272 | + onLineInfo = info; | ||
1273 | + | ||
1274 | + } else if (cmd1 == 8 || cmd1 == 9) { | ||
1275 | + info.cmd1 = cmd1; | ||
1276 | + info.ok = data[6]; | ||
1277 | + info.chan = data[7]; | ||
1278 | + info.keyId = ((data[8] & 0xff) << 8) | (data[9] & 0xff); | ||
1279 | + byte[] sn = Arrays.copyOfRange(data, 10, 16); | ||
1280 | + info.keySn = getKeySn(sn); | ||
1281 | + byte[] mc = Arrays.copyOfRange(data, 16, 19); | ||
1282 | + info.matchCode = new String(mc); | ||
1283 | + m_listener.onKeyPadEvent(info); | ||
1284 | + } | ||
1285 | + | ||
1286 | + break; | ||
1287 | + case CMD_BASE_STATUS_CHANGE:// 基础信标变化(主动下发) | ||
1288 | + | ||
1289 | + responseBaseStatusChange(data, size); | ||
1097 | 1290 | ||
1098 | - if (crcValue != originCrcValue) { | ||
1099 | - System.out.println("recv package crc error!\n"); | 1291 | + onBaseInfo(data); |
1292 | + break; | ||
1293 | + case CMD_VOTE_STATUS_CHANGE:// 投票信标变化 | ||
1294 | + responseVoteStatusChange(data, size); | ||
1295 | + clearSentItems(); | ||
1296 | + onVoteInfo(data); | ||
1297 | + break; | ||
1298 | + | ||
1299 | + case CMD_UPLOAD_DATA_RESPONSE: | ||
1300 | + // 上传文件指令 | ||
1301 | + onMutilPacketRequest(data, size); | ||
1302 | + break; | ||
1303 | + case CMD_VOTE_RESULT_SEND_RESPONSE: | ||
1304 | +// sendToModalSuccessResponse(data[5] & 0xff); | ||
1305 | + break; | ||
1306 | + case CMD_VOTE_SEND_SUCCESS_RESPONSE: | ||
1307 | + responseVoteSendSuccess(data, size); | ||
1308 | + break; | ||
1100 | 1309 | ||
1310 | + case CMD_KEY_MANAGE:// 表决器管理类指令,单包,透传 | ||
1311 | + CmdDataInfo info = new CmdDataInfo(); | ||
1312 | + info.cmd = data[7]; | ||
1313 | + info.data = Arrays.copyOfRange(data, 8, 28); | ||
1314 | + if (info.cmd == 25) { | ||
1315 | + int keyId = (data[5] << 8) | data[6]; | ||
1316 | + if (keyId != 0) { | ||
1317 | + responseClearKeyboardData(data, size); | ||
1318 | + } | ||
1319 | + } else if (info.cmd == 20) { | ||
1320 | + int keyId = (data[5] << 8) | data[6]; | ||
1321 | + if (keyId == onLineInfo.keyId) { | ||
1322 | + responseAuthrizeKeyboardData(data, size); | ||
1323 | + } else { | ||
1324 | + break; | ||
1325 | + } | ||
1326 | + }else if(info.cmd == 50){ | ||
1327 | + responseAuthrizeKeyboardData(data,size); | ||
1328 | + } | ||
1329 | + m_listener.onCmdData(info); | ||
1330 | + break; | ||
1331 | + case CMD_MULTI_PCKAGE_DOWNLOAD: | ||
1332 | + onMultiPackageInfo(data, size); | ||
1333 | + break; | ||
1334 | + case CMD_COM_COMMUNICATION_TEST_RESPONSE: | ||
1335 | + int sendn = data[8] & 0xff; | ||
1336 | + boolean isOk = true; | ||
1337 | + for (int i = 1; i < 17; i++) { | ||
1338 | + if (data[10 + i] != i) { | ||
1339 | + isOk = false; | ||
1340 | + } | ||
1341 | + } | ||
1342 | + m_listener.onComCommunicationTest(sendn, isOk); | ||
1343 | + break; | ||
1344 | + case CMD_FIRM_UPDATE_RESPONSE: | ||
1345 | + taskHandler.removeCallbacks(updateTask); | ||
1346 | + switch (data[5]) { | ||
1347 | + case 2:// '模块询问是否进入DFU | ||
1348 | + keepFirmMode(); | ||
1349 | + try{ | ||
1350 | + Thread.sleep(1000); | ||
1351 | + }catch (Exception ex){} | ||
1352 | + eraseFlash(); | ||
1353 | + break; | ||
1354 | + case 3:// 擦除应答 | ||
1355 | + if (data[8] != 1) { | ||
1356 | + LogUtil.e(TAG, "eraseFlash fail"); | ||
1357 | + m_listener.onFirmUpdateResult(false, "擦除固件失败!"); | ||
1358 | + break; | ||
1359 | + } | ||
1360 | + LogUtil.e(TAG, "eraseFlash ok"); | ||
1361 | + m_listener.onFirmUpdateInfo("擦除固件完成,开始写入..."); | ||
1362 | + CheckFirmReceveThread checkFirmThread = new CheckFirmReceveThread(); | ||
1363 | + checkFirmThread.start(); | ||
1364 | + writeFrimPageErrCnt = 0; | ||
1365 | + writeFlash(firmWritePage); | ||
1366 | + break; | ||
1367 | + case 4:// 写应答 | ||
1368 | + if (data[8] == 1) { | ||
1369 | + firmWritePage++; | ||
1370 | + writeFrimPageErrCnt = 0; | ||
1371 | + if (firmWritePage < firmWritePageMax) { | ||
1372 | + m_listener.onFirmUpdate(firmWritePage * 100 / firmWritePageMax); | ||
1373 | + LogUtil.d(TAG, "write page ok! " + firmWritePage + "/" + firmWritePageMax + " ==" | ||
1374 | + + firmWritePage * 100 / firmWritePageMax + "%"); | ||
1375 | + //sleep(500); | ||
1376 | + writeFlash(firmWritePage); | ||
1101 | } else { | 1377 | } else { |
1102 | - checkComData(SerDataRx, rxDataLen); | 1378 | + m_listener.onFirmUpdateInfo("写入完成"); |
1379 | + m_listener.onFirmUpdate(100); | ||
1380 | + LogUtil.i(TAG, "write 100%"); | ||
1381 | + sleep(2000); | ||
1382 | + exitFirmUpdate(1); | ||
1383 | + LogUtil.i(TAG, "exitFirmUpdate"); | ||
1384 | + m_listener.onFirmUpdateResult(true, null); | ||
1103 | } | 1385 | } |
1104 | - for (int j = 0; j < SerDataRx.length; j++) { | ||
1105 | - SerDataRx[j] = 0; | 1386 | + } else { |
1387 | + LogUtil.d(TAG, "应答写失败 write page error"); | ||
1388 | + } | ||
1389 | + break; | ||
1390 | + case 5: // 退出升级 | ||
1391 | + LogUtil.d(TAG, "exit update!"); | ||
1392 | + m_listener.onFirmUpdateInfo("退出升级模式成功!"); | ||
1393 | + sleep(3000); | ||
1394 | + LogUtil.d(TAG, "sleep 3s getWorkMode!"); | ||
1395 | + for (int i = 0; i < 5; i++) { | ||
1396 | + getWorkMode(); | ||
1397 | + sleep(1000); | ||
1398 | + } | ||
1399 | + byte[] mBuffer = new byte[0x1F + 4]; | ||
1400 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
1401 | + mBuffer[0] = (byte) 0xF5; | ||
1402 | + mBuffer[1] = (byte) 0xAA; | ||
1403 | + mBuffer[2] = (byte) 0xAA; | ||
1404 | + mBuffer[3] = (byte) 0x1F; | ||
1405 | + | ||
1406 | + mBuffer[4] = 0x70; | ||
1407 | + mBuffer[5] = 0x03; | ||
1408 | + writeToCom(mBuffer); | ||
1409 | + | ||
1410 | + break; | ||
1411 | + default: | ||
1412 | + break; | ||
1413 | + } | ||
1414 | + default: | ||
1415 | + break; | ||
1416 | + } | ||
1417 | + | ||
1418 | + } | ||
1419 | + | ||
1420 | + private void sleep(int ms) { | ||
1421 | + try { | ||
1422 | + Thread.sleep(ms); | ||
1423 | + } catch (Exception e) { | ||
1424 | + // TODO: handle exception | ||
1425 | + } | ||
1426 | + } | ||
1427 | + | ||
1428 | + //// 回应模块基础信标变化,模块停止重发,否则模块会不断发送 | ||
1429 | + private void responseBaseStatusChange(byte[] data, int size) { | ||
1430 | + byte[] retData = Arrays.copyOf(data, size); | ||
1431 | + retData[4] = (byte) 0xF1; | ||
1432 | + writeToCom(retData); | ||
1433 | + } | ||
1434 | + | ||
1435 | + | ||
1436 | + | ||
1437 | + // 回应模块投票信标变化,模块停止重发,否则模块会不断发送 | ||
1438 | + private void responseVoteStatusChange(byte[] data, int size) { | ||
1439 | + final byte[] retData = Arrays.copyOf(data, size); | ||
1440 | + retData[4] = (byte) 0xF2; | ||
1441 | + writeToCom(retData); | ||
1442 | + | ||
1443 | + } | ||
1444 | + | ||
1445 | + // 回应发送成功通知 | ||
1446 | + private void responseVoteSendSuccess(byte[] data, int size) { | ||
1447 | + | ||
1448 | + byte[] retData = Arrays.copyOf(data, size); | ||
1449 | + retData[4] = (byte) 0xF3; | ||
1450 | + writeToCom(retData); | ||
1451 | + | ||
1452 | + int serialNo = data[5] & 0xff; | ||
1453 | + VoteResultItem ret = removeSentItem(serialNo); | ||
1454 | + | ||
1455 | + if (serialNo == allOkSerialNumber) { | ||
1456 | + m_listener.onVoteSubmitAllOkSuccess(); | ||
1457 | + allOkSerialNumber = -1; | ||
1458 | + } else if (serialNo == serviceSerialNumber) { | ||
1459 | + m_listener.onServiceSubmitSuccess(); | ||
1460 | + serviceSerialNumber = -1; | ||
1461 | + } else { | ||
1462 | + if (ret != null) { | ||
1463 | + m_listener.onVoteSubmitSuccess(ret); | ||
1464 | + } | ||
1465 | + } | ||
1466 | + } | ||
1467 | + | ||
1468 | + //回复清空键盘数据 | ||
1469 | + private void responseClearKeyboardData(byte[] data, int len) { | ||
1470 | + byte[] retData = Arrays.copyOf(data, len); | ||
1471 | + retData[4] = (byte) 0xB0; | ||
1472 | +// retData[8] = 1; 修改原因:肖翔给的表达:人大的表决就是1,评分的是0 | ||
1473 | + writeToCom(retData); | ||
1474 | + } | ||
1475 | + | ||
1476 | + //回复键盘授权数据 | ||
1477 | + private void responseAuthrizeKeyboardData(byte[] data, int len) { | ||
1478 | + byte[] retData = Arrays.copyOf(data, len); | ||
1479 | + retData[4] = (byte) 0xB0; | ||
1480 | + writeToCom(retData); | ||
1481 | + } | ||
1482 | + | ||
1483 | + | ||
1484 | + } | ||
1485 | + | ||
1486 | + // 处理基础信标变化 | ||
1487 | + private void onBaseInfo(byte[] data) { | ||
1488 | + | ||
1489 | + // Arrays.fill(broadcastData, (byte) 0x0);//清空多包结果 | ||
1490 | + if(data != null){ | ||
1491 | + baseSign = new byte[data.length]; | ||
1492 | + System.arraycopy(data,0,baseSign,0,data.length); | ||
1493 | + } | ||
1494 | + | ||
1495 | + BaseInfo info = new BaseInfo(); | ||
1496 | + info.baseId = data[5] & 0xff;// baseID | ||
1497 | + info.idMode = data[6] & 0xff; | ||
1498 | + info.confId = ((data[7] & 0xff) << 8) | (data[8] & 0xff); | ||
1499 | + | ||
1500 | + info.billId = data[9] & 0xff; | ||
1501 | + info.authCode = (data[10] & 0xff) << 8 | (data[11] & 0xff); | ||
1502 | + info.login = data[12] & 0xff; | ||
1503 | + info.report = data[13] & 0xff; | ||
1504 | + info.offTime = data[14] & 0xff; | ||
1505 | + info.attrib = data[15] & 0xff; | ||
1506 | + info.pageNo = (data[16] & 0xff) << 8 | (data[17] & 0xff); | ||
1507 | + byte[] bname = Arrays.copyOfRange(data, 16, 16 + 12); | ||
1508 | + info.baseName = new String(bname); | ||
1509 | + | ||
1510 | + m_listener.onBaseEvent(info); | ||
1511 | + } | ||
1512 | + | ||
1513 | + // 处理投票信标变化 | ||
1514 | + private void onVoteInfo(byte[] data) { | ||
1515 | + if(data != null){ | ||
1516 | + voteSign = new byte[data.length]; | ||
1517 | + System.arraycopy(data,0,voteSign,0,data.length); | ||
1518 | + } | ||
1519 | + byte[] dt = Arrays.copyOfRange(data, 4, data.length - 4 - 1);// 从len开始,和文档下标统一 | ||
1520 | + VoteInfo info = new VoteInfo(); | ||
1521 | + info.baseId = dt[1] & 0xff; | ||
1522 | + info.nowT = dt[2] & 0xff << 8 | dt[3] & 0xff; | ||
1523 | + info.dataPos = dt[4] & 0xff; | ||
1524 | + info.mode = dt[5] & 0xff; | ||
1525 | + info.mode1_msgType = dt[6] & 0xff; | ||
1526 | + if (info.mode != VoteType_Stop) { | ||
1527 | + serialNumber = 0; | ||
1528 | + } | ||
1529 | + | ||
1530 | + if (info.mode == VoteType_Stop) { // 停止 | ||
1531 | + if (info.mode1_msgType == 2) { // 有结果 | ||
1532 | + | ||
1533 | + info.resultInfo.resultType = dt[7] & 0xff; | ||
1534 | + info.resultInfo.bits = dt[8] & 0xff; | ||
1535 | + info.resultInfo.num0 = (dt[9] & 0xff) << 8 | (dt[10] & 0xff); | ||
1536 | + info.resultInfo.num1 = (dt[11] & 0xff) << 8 | (dt[12] & 0xff); | ||
1537 | + info.resultInfo.num2 = (dt[13] & 0xff) << 8 | (dt[14] & 0xff); | ||
1538 | + info.resultInfo.num3 = (dt[15] & 0xff) << 8 | (dt[16] & 0xff); | ||
1539 | + info.resultInfo.num4 = (dt[17] & 0xff) << 8 | (dt[18] & 0xff); | ||
1540 | + info.resultInfo.num5 = (dt[19] & 0xff) << 8 | (dt[20] & 0xff); | ||
1541 | + info.resultInfo.num6 = (dt[21] & 0xff) << 8 | (dt[22] & 0xff); | ||
1542 | + } | ||
1543 | + } else if (info.mode == VoteType_BatchVote) { | ||
1544 | + printDataBuf(data, data.length, "batchvote:"); | ||
1545 | + info.less = dt[11] & 0xff; | ||
1546 | + info.mode3_secret = dt[12] & 0xff; | ||
1547 | + info.fixballot = dt[13] & 0xff ; | ||
1548 | + if(info.fixballot > 0 ){ | ||
1549 | + info.limitFavor = dt[14] & 0xff ; | ||
1550 | + info.limitOppo = dt[15] & 0xff ; | ||
1551 | + info.limitWaiver = dt[16] & 0xff ; | ||
1552 | + }else{ | ||
1553 | + info.limitFavor = 0 ; | ||
1554 | + info.limitOppo = 0 ; | ||
1555 | + info.limitWaiver = 0; | ||
1556 | + } | ||
1557 | + | ||
1558 | + | ||
1559 | + info.mode2_modify = dt[23] & 0xff; | ||
1560 | + info.voteid = dt[21] & 0xff; | ||
1561 | + } else if (info.mode == VoteType_Choice) { | ||
1562 | + info.mode2_modify = dt[7] & 0xff; | ||
1563 | + info.mode3_secret = dt[8] & 0xff; | ||
1564 | + info.mode4 = dt[9] & 0xff; | ||
1565 | + info.mode5 = dt[10] & 0xff; | ||
1566 | + info.mode6 = dt[11] & 0xff; | ||
1567 | + info.mode7 = dt[12] & 0xff; | ||
1568 | + } else if (info.mode == VoteType_BatchElect) {//选举 | ||
1569 | + info.electInfo.type = dt[6] & 0xff; | ||
1570 | + info.electInfo.random = dt[7] & 0xff; | ||
1571 | + info.electInfo.select = dt[8] & 0xff; | ||
1572 | + info.electInfo.other = dt[9] & 0xff; | ||
1573 | + info.electInfo.less = dt[10] & 0xff; | ||
1574 | + info.electInfo.secrecy = dt[11] & 0xff; | ||
1575 | + info.electInfo.modify = dt[12] & 0xff; | ||
1576 | + info.electInfo.start = dt[13] & 0xff; | ||
1577 | + info.electInfo.end = dt[14] & 0xff; | ||
1578 | + info.electInfo.equityMode = dt[15] & 0xff; | ||
1579 | + info.electInfo.minSelect = dt[16] & 0xff; | ||
1580 | + info.electInfo.voteid = dt[21] & 0xff; | ||
1581 | + | ||
1582 | + } else if (info.mode == VoteType_SingleItemEvalue) {//单项评分 | ||
1583 | + info.singleEvalueInfo.mode1 = dt[6] & 0xff; | ||
1584 | + info.singleEvalueInfo.mode2 = dt[7] & 0xff; | ||
1585 | + info.singleEvalueInfo.mode3 = dt[8] & 0xff; | ||
1586 | + info.singleEvalueInfo.mode4 = dt[9] & 0xff; | ||
1587 | + info.singleEvalueInfo.mode5 = dt[10] & 0xff; | ||
1588 | + info.singleEvalueInfo.mode6 = dt[11] & 0xff; | ||
1589 | + info.singleEvalueInfo.mode7 = dt[12] & 0xff; | ||
1590 | + info.singleEvalueInfo.mode8 = dt[13] & 0xff; | ||
1591 | + info.singleEvalueInfo.mode9 = dt[14] & 0xff; | ||
1592 | + info.singleEvalueInfo.mode10 = dt[15] & 0xff; | ||
1593 | + info.singleEvalueInfo.mode11 = dt[16] & 0xff; | ||
1594 | + info.singleEvalueInfo.mode12 = dt[17] & 0xff; | ||
1595 | + info.singleEvalueInfo.title = new byte[12]; | ||
1596 | + | ||
1597 | + System.arraycopy(dt, 12, info.singleEvalueInfo.title, 0, 12); | ||
1598 | + info.voteid = dt[23] & 0xFF ; | ||
1599 | + info.singleEvalueInfo.number = dt[24] & 0xff; | ||
1600 | + } else if (info.mode == VoteType_BatchEvalue) { | ||
1601 | + info.batchEvalueInfo.mode1 = dt[6] & 0xff; | ||
1602 | + info.batchEvalueInfo.startVal = (dt[7] & 0xff) << 8 | (dt[8] & 0xff); | ||
1603 | + info.batchEvalueInfo.endVal = (dt[9] & 0xff) << 8 | (dt[10] & 0xff); | ||
1604 | + info.batchEvalueInfo.autoMove = dt[11] & 0xff; | ||
1605 | + info.batchEvalueInfo.width1 = dt[12] & 0xff; | ||
1606 | + info.batchEvalueInfo.width2 = dt[13] & 0xff; | ||
1607 | + info.batchEvalueInfo.less = dt[14] & 0xff; | ||
1608 | + info.batchEvalueInfo.secrecy = dt[15] & 0xff; | ||
1609 | + info.batchEvalueInfo.modify = dt[16] & 0xff; | ||
1610 | + info.batchEvalueInfo.ruleStart = dt[17] & 0xff; | ||
1611 | + info.batchEvalueInfo.ruleEnd = dt[18] & 0xff; | ||
1612 | + info.batchEvalueInfo.sliderover = dt[19] & 0xff; | ||
1613 | + info.batchEvalueInfo.billNo = dt[20] & 0xff; | ||
1614 | + info.batchEvalueInfo.billSubNo = ((dt[21] & 0xff) << 8) | (dt[22] & 0xff); | ||
1615 | + | ||
1616 | + } else if (info.mode == VoteType_BatchIDEvalue) { | ||
1617 | + info.batchEvalueInfo.mode1 = dt[6] & 0xff; | ||
1618 | + info.batchEvalueInfo.startVal = (dt[7] & 0xff) << 8 | (dt[8] & 0xff); | ||
1619 | + info.batchEvalueInfo.endVal = (dt[9] & 0xff) << 8 | (dt[10] & 0xff); | ||
1620 | + info.batchEvalueInfo.autoMove = dt[11] & 0xff; | ||
1621 | + info.batchEvalueInfo.width1 = dt[12] & 0xff; | ||
1622 | + info.batchEvalueInfo.width2 = dt[13] & 0xff; | ||
1623 | + info.batchEvalueInfo.less = dt[14] & 0xff; | ||
1624 | + info.batchEvalueInfo.secrecy = dt[15] & 0xff; | ||
1625 | + info.batchEvalueInfo.modify = dt[16] & 0xff; | ||
1626 | + info.batchEvalueInfo.ruleStart = dt[17] & 0xff; | ||
1627 | + info.batchEvalueInfo.ruleEnd = dt[18] & 0xff; | ||
1628 | + info.batchEvalueInfo.sliderover = dt[19] & 0xff; | ||
1629 | + info.batchEvalueInfo.billNo = dt[20] & 0xff; | ||
1630 | + info.batchEvalueInfo.billSubNo = ((dt[21] & 0xff) << 8) | (dt[22] & 0xff); | ||
1631 | + } else { | ||
1632 | + info.mode2_modify = dt[7] & 0xff; | ||
1633 | + info.mode3_secret = dt[8] & 0xff; | ||
1634 | + info.mode4 = dt[9] & 0xff; | ||
1635 | + info.voteid = dt[11] & 0xff; | ||
1636 | + info.file = dt[12] & 0xff; | ||
1637 | + info.init = dt[13] & 0xff; | ||
1638 | + } | ||
1639 | + m_listener.onVoteEvent(info); | ||
1640 | + } | ||
1641 | + | ||
1642 | + public void cleanSendQueue() { | ||
1643 | + LogUtil.i(TAG,"cleanSendQueue"); | ||
1644 | + synchronized (sendQueen){ | ||
1645 | + LogUtil.i(TAG,"投票信标变化,清除已发队列"); | ||
1646 | + for(VoteResultItem temp : sendQueen){ | ||
1647 | + LogUtil.i(TAG,"清除数据",temp.data); | ||
1648 | + } | ||
1649 | + sendQueen.clear(); | ||
1650 | + } | ||
1651 | + } | ||
1652 | + | ||
1653 | + private byte[] broadcastData = new byte[4096]; | ||
1654 | + private byte[] fileData; | ||
1655 | + private int fileLen; | ||
1656 | + private int dataLen; | ||
1657 | + private int lastPackH = -1; | ||
1658 | + | ||
1659 | + private short needBits = 0; | ||
1660 | + private int okBits = 0; | ||
1661 | + private int currDownloadMsgId; | ||
1662 | + private int broadMsgId = -1; | ||
1663 | + private long lastOnMultiPackageDataTime; | ||
1664 | + | ||
1665 | + private int maxPackH; //用于计算收到长度 | ||
1666 | + private int maxPachL; //用于计算收到长度 | ||
1667 | + | ||
1668 | + private int downType; | ||
1669 | + private int downId; | ||
1670 | + | ||
1671 | + private boolean isMineDonwload = false ; | ||
1672 | + | ||
1673 | + /** | ||
1674 | + * 字节 标识符 描述 | ||
1675 | + * 1 DOWNCMD 0x40 下载多包类指令 | ||
1676 | + * 2-3 KEYID 表决器编号,2字节,高位在前 | ||
1677 | + * 一般要指定表决器编号使指定键盘进入或退出下载状态 | ||
1678 | + * 但0x0000广播时候,键盘也执行 | ||
1679 | + * FF01到FFFE时候,是用序列号指定键盘 V4.74 | ||
1680 | + * 低位字节01-FE,表示下载次序,由SDK管理,新下载变化一次, | ||
1681 | + * 键盘收到的时候,记录下,同时,此次序也出现在下载数据包中,这样键盘可判断是否是我可以下载的数据,避免上次下载状态没正常退出而错误接受数据 | ||
1682 | + * 4 DOWNCMD 1 进入或退出下载状态 | ||
1683 | + * 5 DOWNTYPE 多包类型 | ||
1684 | + * 6 DOWNID 数据包标识码 | ||
1685 | + * 7 DCMD 模式 1进入下载 0退出下载 | ||
1686 | + * 8-24 FILENAME 在DOWNTYPE=40下载文件模式时候,是下载文件名称,16字符 | ||
1687 | + * 其他模式参数无意义 | ||
1688 | + * SN 序列号模式时候,6字节键盘序列号,用于指定键盘 | ||
1689 | + * 暂不支持文件下载 | ||
1690 | + * | ||
1691 | + * @param data | ||
1692 | + * @param size | ||
1693 | + */ | ||
1694 | + private void onMultiPackageInfo(byte[] data, int size) { | ||
1695 | + byte[] dt = Arrays.copyOfRange(data, 3, data.length);// 从len开始,和文档下标统一 | ||
1696 | + int downCmd = dt[4]; //1 进入或退出下载状态 | ||
1697 | + | ||
1698 | + int dcmd = dt[7];// 1:进入下载 0:退出下载 | ||
1699 | + | ||
1700 | + if (downCmd == 1) { // 1:进入/退出下载 | ||
1701 | + resopnseMultiPackageMode(data, size); | ||
1702 | + if (dcmd == 1) { //模式 1进入下载 | ||
1703 | + int keyId = (data[5] << 8) | data[6]; | ||
1704 | + if (keyId == onLineInfo.keyId || keyId == 0 || keyId == 0xFFFF) { | ||
1705 | +// isMineDonwload = true; | ||
1706 | + downType = dt[5];// 10即时信息 或 11短信 40 下载文件 | ||
1707 | + downId = dt[6]; ////数据包标识码 | ||
1708 | + LogUtil.d(TAG, " 1:进入下载 。。。。。downType = " + downType + " downId:" + downId); | ||
1709 | + lastPackH = -1; | ||
1710 | + if (downType == 40) { //下载文件模式 @Auther Elvis | ||
1711 | + int packH = (dt[8] & 0xff); | ||
1712 | + int packL = (dt[9] & 0xff); | ||
1713 | + fileLen = packH * 256 + packL + 1; | ||
1714 | + int len = 0; | ||
1715 | + for (int i = 10; i < 26; i++) { | ||
1716 | + if (dt[i] == 0) { | ||
1717 | + break; | ||
1718 | + } | ||
1719 | + len++; | ||
1720 | + } | ||
1721 | + String fileName = "test.txt"; | ||
1722 | + try { | ||
1723 | + fileName = new String(dt, 10, len, "GB2312"); | ||
1724 | + } catch (Exception e) { | ||
1725 | + e.printStackTrace(); | ||
1726 | + } | ||
1727 | + dataLen = fileLen + 36; | ||
1728 | + LogUtil.d(TAG, "下载文件,长度:" + fileLen + ", 文件名:" + fileName); | ||
1729 | + if (fileLen > 0) { | ||
1730 | + fileData = new byte[dataLen]; | ||
1731 | + Arrays.fill(fileData, (byte) 0x0); | ||
1732 | + } | ||
1733 | + | ||
1734 | + try { | ||
1735 | + RFFileDownloadModule.getInstance().getDownloadProcess().setFileName(fileName); | ||
1736 | + RFFileDownloadModule.getInstance().getDownloadProcess().setLength(fileLen - 4); | ||
1737 | + RFFileDownloadModule.getInstance().getDownloadProcess().onStartDownload(); | ||
1738 | + } catch (Exception e1) { | ||
1739 | + } | ||
1740 | + | ||
1741 | + | ||
1742 | + } else if (downType >= 1 && downType <= 3) { | ||
1743 | + m_listener.onMultiPackageStartDownload(downType, downId); | ||
1744 | + maxPackH = 0; | ||
1745 | + maxPachL = 0; | ||
1746 | + Arrays.fill(broadcastData, (byte) 0x0); | ||
1747 | + } else { | ||
1748 | + maxPackH = 0; | ||
1749 | + maxPachL = 0; | ||
1750 | + Arrays.fill(broadcastData, (byte) 0x0); | ||
1751 | + } | ||
1752 | + } | ||
1753 | + } else { //0退出下载 | ||
1754 | + int keyId = (data[5] << 8) | data[6]; | ||
1755 | + if (keyId == onLineInfo.keyId || keyId == 0 || keyId == 0xFFFF) { | ||
1756 | + isMineDonwload = false; | ||
1757 | + LogUtil.d(TAG, dcmd + ": 退出下载。。。。。。。。。"); | ||
1758 | + if (downType == 40) { | ||
1759 | + //@Auther Elvis 添加文件下载逻辑 | ||
1760 | + if (System.currentTimeMillis() - lastOnMultiPackageDataTime > 500) { | ||
1761 | + lastOnMultiPackageDataTime = System.currentTimeMillis(); | ||
1762 | + try { | ||
1763 | + if (fileData != null) { | ||
1764 | + File file = RFFileDownloadModule.getInstance().getDownloadProcess().getFile(); | ||
1765 | + FileOutputStream fileOutputStream = new FileOutputStream(file); | ||
1766 | + fileOutputStream.write(fileData, 0, fileLen - 4); | ||
1767 | + fileOutputStream.flush(); | ||
1768 | + fileOutputStream.close(); | ||
1769 | + fileData = null; | ||
1770 | + RFFileDownloadModule.getInstance().getDownloadProcess().onStopDownload(); | ||
1106 | } | 1771 | } |
1107 | - iSerRxN = 0; | 1772 | + } catch (Exception ex) { |
1773 | + LogUtil.e(TAG, ex); | ||
1774 | + RFFileDownloadModule.getInstance().getDownloadProcess().onDownloadError(ex); | ||
1775 | + } | ||
1776 | + } | ||
1777 | + | ||
1778 | + } else if (downType >= 1 && downType <= 3) { | ||
1779 | + if (System.currentTimeMillis() - lastOnMultiPackageDataTime > 500) { | ||
1780 | + lastOnMultiPackageDataTime = System.currentTimeMillis(); | ||
1781 | + LogUtil.d(TAG, "maxPackH:" + maxPackH + " maxPachL:" + maxPachL); | ||
1782 | + broadcastData[0] = (byte) 0xF4; | ||
1783 | + broadcastData[1] = (byte) 0xF5; | ||
1784 | + broadcastData[2] = (byte) downType; | ||
1785 | + broadcastData[3] = (byte) downId; | ||
1786 | + m_listener.onMultiPackageData(broadcastData, (maxPackH + 1) * 16 + (maxPachL + 1) * 16 + 4); | ||
1787 | + } | ||
1788 | + } | ||
1789 | + } | ||
1790 | + } | ||
1791 | + } else if (downCmd == 2) { // 2:下载数据 | ||
1792 | +// if(isMineDonwload) { | ||
1793 | + int msgid = (byte) dt[6] & 0xFF; | ||
1794 | + byte packH = dt[7];// 数据段 编号 当前最大15(16片) | ||
1795 | + byte packL = dt[8];// 数据片编号 | ||
1796 | + LogUtil.d(TAG, "下载。。。msgId:" + msgid + " packH:" + packH + " apckL:" + packL); | ||
1797 | + | ||
1798 | + if (downType == 40) {// 文件下载 | ||
1799 | + if (lastPackH != packH) { //新的packH | ||
1800 | + LogUtil.i(TAG, "new packH......."); | ||
1801 | + okBits = 0; | ||
1802 | + lastPackH = packH; | ||
1803 | + } | ||
1804 | + int destPos = ((packH & 0xFF) * 16 + (packL & 0xFF)) * 16; | ||
1805 | + if (destPos + 16 <= fileData.length) { | ||
1806 | + System.arraycopy(dt, 9, fileData, destPos, 16); | ||
1807 | + } | ||
1808 | + | ||
1809 | + if ((okBits & (1 << packL)) == 0) {// 添加文件下载逻辑 进度 | ||
1810 | + RFFileDownloadModule.getInstance().getDownloadProcess().onDownloadAddProcess(16); | ||
1811 | + } | ||
1812 | + okBits |= (1 << packL); | ||
1813 | + LogUtil.d(TAG, "packL:" + packL + " okBits:" + okBits); | ||
1814 | + | ||
1815 | + } else {// 广播 | ||
1816 | + | ||
1817 | + | ||
1818 | + if (broadMsgId != msgid) { | ||
1819 | + Arrays.fill(broadcastData, (byte) 0x0); | ||
1820 | + broadMsgId = msgid; | ||
1821 | + okBits = 0; | ||
1822 | + } | ||
1823 | + if (lastPackH != packH) { | ||
1824 | + LogUtil.i(TAG, "new packH......."); | ||
1825 | + needBits = calcBits(packH); | ||
1826 | + okBits = 0; | ||
1827 | + lastPackH = packH; | ||
1828 | + maxPachL = 0; | ||
1829 | + } | ||
1830 | + | ||
1831 | + if (packH > maxPackH) { | ||
1832 | + maxPackH = packH; | ||
1833 | + } | ||
1834 | + if (packL > maxPachL) { | ||
1835 | + maxPachL = packL; | ||
1836 | + } | ||
1837 | + | ||
1838 | + if (downType >= 1 && downType <= 3) { | ||
1839 | + System.arraycopy(dt, 9, broadcastData, (packH * 16 + packL) * 16 + 4, 16); | ||
1840 | + } else { | ||
1841 | + System.arraycopy(dt, 9, broadcastData, packL * 16, 16);//短信 packH 总共多少片, packL 第几片 | ||
1842 | + } | ||
1843 | + okBits |= (1 << packL); | ||
1844 | + LogUtil.d(TAG, "packL:" + packL + " okBits:" + okBits + " needBits:" + (needBits & 0xffff) + " downType:" + downType); | ||
1845 | + if (downType == 0 || downType > 3) { | ||
1846 | + | ||
1847 | + if (okBits == needBits) { | ||
1848 | + if (broadMsgId != currDownloadMsgId) { | ||
1849 | + m_listener.onMultiPackageData(broadcastData, (packH + 1) * 16); | ||
1850 | + currDownloadMsgId = broadMsgId; | ||
1108 | } | 1851 | } |
1852 | + Arrays.fill(broadcastData, (byte) 0x0); | ||
1853 | + broadMsgId = -1; | ||
1854 | + lastPackH = -1; | ||
1855 | + //okBits = 0; | ||
1109 | 1856 | ||
1110 | } | 1857 | } |
1858 | + } | ||
1859 | + } | ||
1860 | +// } | ||
1861 | + } else if (downCmd == 3) { // 3:询问 | ||
1862 | + resopnseMultiPackageQuery(data, size); | ||
1863 | + LogUtil.d(TAG, " 3:询问。。。。。。。。。"); | ||
1864 | + | ||
1865 | + | ||
1866 | + } | ||
1867 | + } | ||
1868 | + | ||
1869 | + private short calcBits(byte packh) { | ||
1870 | + short bits = 0; | ||
1871 | + for (int i = 0; i <= packh; i++) { | ||
1872 | + bits |= (1 << i); | ||
1873 | + } | ||
1874 | + return bits; | ||
1875 | + } | ||
1876 | + | ||
1877 | + private void resopnseMultiPackageMode(byte[] data, int size) { | ||
1878 | + byte[] retData = Arrays.copyOf(data, size); | ||
1879 | + retData[4] = (byte) 0xC0; | ||
1880 | + writeToCom(retData); | ||
1881 | + } | ||
1882 | + | ||
1883 | + private void resopnseMultiPackageQuery(byte[] data, int size) { | ||
1884 | + byte[] retData = Arrays.copyOf(data, size); | ||
1885 | + retData[4] = (byte) 0xC0; | ||
1886 | + int tmpOk = ~okBits; | ||
1887 | + retData[11] = (byte) tmpOk; | ||
1888 | + retData[12] = (byte) (tmpOk >> 8); | ||
1889 | + writeToCom(retData); | ||
1890 | + } | ||
1891 | + | ||
1892 | + public static String getVoteType(int mode) { | ||
1893 | + switch (mode) { | ||
1894 | + case VoteType_Stop: | ||
1895 | + return "VoteType_Stop"; | ||
1896 | + case VoteType_Signin: | ||
1897 | + return "VoteType_Signin"; | ||
1898 | + case VoteType_Vote: | ||
1899 | + return "VoteType_Vote"; | ||
1900 | + case VoteType_BatchVote: | ||
1901 | + return "VoteType_BatchVote"; | ||
1902 | + case VoteType_BatchElect: | ||
1903 | + return "VoteType_BatchElect"; | ||
1904 | + | ||
1905 | + default: | ||
1906 | + break; | ||
1907 | + } | ||
1908 | + return "" + mode; | ||
1909 | + } | ||
1910 | + | ||
1911 | + public static String getKeySn(byte[] data) { | ||
1912 | + String sn = ""; | ||
1913 | + String CS = "0123456789ABCDEF"; | ||
1914 | + for (int i = 0; i < 6; i++) { | ||
1915 | + sn += CS.charAt((data[i] >> 4) & 0xF); | ||
1916 | + sn += CS.charAt((data[i] >> 0) & 0xF); | ||
1917 | + } | ||
1918 | + return sn; | ||
1919 | + | ||
1920 | + } | ||
1921 | + | ||
1922 | + private long writeOkPageNo; | ||
1923 | + private int compareCount; | ||
1924 | + | ||
1925 | + private class CheckFirmReceveThread extends Thread { | ||
1926 | + public void run() { | ||
1927 | + while (true) { | ||
1928 | + try { | ||
1929 | + Thread.sleep(2000); | ||
1930 | + if (writeOkPageNo != firmWritePage) { | ||
1931 | + writeOkPageNo = firmWritePage; | ||
1932 | + //sendMessage(keypadID + ":recv"+lastReceveLength+"\n"); | ||
1933 | + //LogUtil.d(TAG,"CheckReceveThread:check ok!"); | ||
1934 | + compareCount = 0; | ||
1935 | + } else { | ||
1936 | + compareCount++; | ||
1937 | + Thread.sleep(2000); | ||
1938 | + if (compareCount <= 20) { | ||
1939 | + LogUtil.d(TAG, "CheckWriteFirmhread:retry ==========="); | ||
1940 | + | ||
1941 | + m_listener.onFirmUpdateInfo("与入页:" + firmWritePage + "失败, 次数:" + compareCount); | ||
1942 | + writeFlash(firmWritePage); | ||
1943 | + } else { | ||
1944 | + compareCount = 0; | ||
1945 | + | ||
1946 | + LogUtil.d(TAG, "CheckWriteFirmhread:fail , exit!"); | ||
1947 | + | ||
1948 | + LogUtil.e(TAG, "写入扇区" + firmWritePage + "失败!"); | ||
1949 | + m_listener.onFirmUpdateResult(false, "写入扇区" + firmWritePage + "失败!"); | ||
1950 | + exitFirmUpdate(2); | ||
1951 | + | ||
1952 | + break; | ||
1953 | + } | ||
1954 | + } | ||
1955 | + | ||
1956 | + | ||
1957 | + if (firmWritePage > 0 && firmWritePage == firmWritePageMax) { | ||
1958 | + LogUtil.d(TAG, "CheckWriteFirmhread:ok : exit!"); | ||
1111 | break; | 1959 | break; |
1112 | - }// switch | ||
1113 | - } // for | 1960 | + } |
1961 | + | ||
1962 | + } catch (InterruptedException e) { | ||
1963 | + e.printStackTrace(); | ||
1964 | + } | ||
1965 | + | ||
1966 | + } | ||
1967 | + } | ||
1968 | + } | ||
1969 | + | ||
1970 | + ; | ||
1971 | + | ||
1972 | + private static int encodeBCD(byte c) { | ||
1973 | + if (c >= 'a' && c <= 'f') { | ||
1974 | + return 10 + (c - 'a'); | ||
1975 | + } else if (c >= '0' && c <= '9') { | ||
1976 | + return c - '0'; | ||
1977 | + } else if (c >= 'A' && c <= 'F') { | ||
1978 | + return 10 + (c - 'A'); | ||
1979 | + } else if (c == '.') { | ||
1980 | + return 0xE; | ||
1981 | + } | ||
1982 | + return -1; | ||
1983 | + } | ||
1984 | + | ||
1985 | + | ||
1986 | + /** | ||
1987 | + * 把字符串形式转换为字节形式 | ||
1988 | + */ | ||
1989 | + private byte[] util_encodeBCD(byte[] cs) { | ||
1990 | + byte[] rs = new byte[17]; | ||
1991 | + Arrays.fill(rs, (byte) 0xff);// | ||
1992 | + | ||
1993 | + int len = cs.length < 16 ? cs.length : 16; | ||
1994 | + int io = 0; | ||
1995 | + | ||
1996 | + for (int i = 0; i < len; i += 2) { | ||
1997 | + int n = encodeBCD(cs[i]); | ||
1998 | + n <<= 4; | ||
1999 | + if (i + 1 == cs.length) { | ||
2000 | + rs[io++] = (byte) (n | 0xf); | ||
2001 | + break; | ||
2002 | + } | ||
2003 | + | ||
2004 | + n |= encodeBCD(cs[i + 1]); | ||
2005 | + if (n < 0) { | ||
2006 | + break; | ||
2007 | + } | ||
2008 | + rs[io++] = (byte) n; | ||
2009 | + } | ||
2010 | + rs[++io] = 0; | ||
2011 | + return rs; | ||
2012 | + } | ||
2013 | + | ||
2014 | + public static String util_decodeBCD(byte[] cs, int len) { | ||
2015 | + byte[] buf = new byte[8 * 2]; | ||
2016 | + Arrays.fill(buf, (byte) 0); | ||
2017 | + String bcdNum = "0123456789ABCD.F"; | ||
2018 | + String bcdStr = bytesToHexString(cs); | ||
2019 | + for (int i = 0; i < len * 2; i += 2) { | ||
2020 | + byte item = bcdStr.getBytes()[i]; | ||
2021 | + if (item >= '0' && item <= '9') { | ||
2022 | + buf[i] = item; | ||
2023 | + } else if (item == 'E') { | ||
2024 | + buf[i] = '.'; | ||
2025 | + } else if (item == 'F') { | ||
2026 | + buf[i] = 0; | ||
2027 | + break; | ||
2028 | + } | ||
2029 | + | ||
2030 | + item = bcdStr.getBytes()[i + 1]; | ||
2031 | + if (item >= '0' && item <= '9') { | ||
2032 | + buf[i + 1] = item; | ||
2033 | + } else if (item == 'E') { | ||
2034 | + buf[i + 1] = '.'; | ||
2035 | + } else if (item == 'F') { | ||
2036 | + buf[i + 1] = 0; | ||
2037 | + break; | ||
2038 | + } | ||
2039 | + | ||
2040 | + } | ||
2041 | + return new String(buf).trim(); | ||
2042 | + | ||
2043 | + } | ||
1114 | 2044 | ||
2045 | + public static String bytesToHexString(byte[] src) { | ||
2046 | + StringBuilder stringBuilder = new StringBuilder(""); | ||
2047 | + if (src == null || src.length <= 0) { | ||
2048 | + return null; | ||
1115 | } | 2049 | } |
1116 | - } | ||
1117 | - | ||
1118 | - @SuppressLint("NewApi") | ||
1119 | - private void checkComData(byte[] data, int size) { | ||
1120 | - LogUtil.i(TAG,"checkComData",data); | ||
1121 | - m_listener.onComData(data, size); | ||
1122 | - int cmd = data[4] & 0xFF; | ||
1123 | - | ||
1124 | - switch (cmd) { | ||
1125 | - case CMD_CHECK_BASE_STATUS_RESPONSE:// 查询状态类指令应答 | ||
1126 | - int cmd1 = data[5] & 0xFF; | ||
1127 | - if (cmd1 == 1) {// 返回当前工作模式和版本 | ||
1128 | - ModelInfo info = new ModelInfo(); | ||
1129 | - info.mode = data[6]; | ||
1130 | - info.hModel = data[7] & 0xff; | ||
1131 | - info.sVer = data[8] + "." + data[9] + "." + data[10]; | ||
1132 | - m_listener.onModelEvent(info); | ||
1133 | - } else if (cmd1 == 3) { // 查询基础信标 结果 | ||
1134 | - onBaseInfo(data); | ||
1135 | - } else if (cmd1 == 4) { // 查询投票信标 结果 | ||
1136 | - onVoteInfo(data); | ||
1137 | - } else if (cmd1 == 5 || cmd1 == 6) {// 返回当前键盘参数结果 | ||
1138 | - KeypadInfo info = new KeypadInfo(); | ||
1139 | - info.ok = data[6]; | ||
1140 | - info.chan = data[7]; | ||
1141 | - info.keyId = ((data[8] & 0xff) << 8) | (data[9] & 0xff); | ||
1142 | - byte[] sn = Arrays.copyOfRange(data, 10, 16); | ||
1143 | - info.keySn = getKeySn(sn); | ||
1144 | - byte[] mc = Arrays.copyOfRange(data, 16, 19); | ||
1145 | - info.matchCode = new String(mc); | ||
1146 | - m_listener.onKeyPadEvent(info); | ||
1147 | - | ||
1148 | - // if(!hasGetBaseInfo){ //第一次启动时取 | ||
1149 | - // hasGetBaseInfo = true; | ||
1150 | - // getBaseStatus(); | ||
1151 | - // } | ||
1152 | - | ||
1153 | - } else if (cmd1 == 7) {// 查询键盘在线状态结果 | ||
1154 | - OnLineInfo info = new OnLineInfo(); | ||
1155 | - info.onLine = data[6]; | ||
1156 | - info.idMode = data[7]; | ||
1157 | - info.chan = data[8] & 0xff; | ||
1158 | - info.rssi = data[9] & 0xff; | ||
1159 | - info.tx = data[10]; | ||
1160 | - info.rx = data[11]; | ||
1161 | - info.baseId = data[12] & 0xff; | ||
1162 | - info.keyId = ((data[13] & 0xff) << 8) | (data[14] & 0xff); | ||
1163 | - byte[] sn = Arrays.copyOfRange(data, 15, 21); | ||
1164 | - info.keySn = getKeySn(sn); | ||
1165 | - onLineInfo = info; | ||
1166 | - m_listener.onOnLineEvent(info); | ||
1167 | - | ||
1168 | - } else if (cmd1 == 8 || cmd1 == 9) { | ||
1169 | - KeypadInfo info = new KeypadInfo(); | ||
1170 | - info.cmd1 = cmd1; | ||
1171 | - info.ok = data[6]; | ||
1172 | - info.chan = data[7]; | ||
1173 | - info.keyId = ((data[8] & 0xff) << 8) | (data[9] & 0xff); | ||
1174 | - byte[] sn = Arrays.copyOfRange(data, 10, 16); | ||
1175 | - info.keySn = getKeySn(sn); | ||
1176 | - byte[] mc = Arrays.copyOfRange(data, 16, 19); | ||
1177 | - info.matchCode = new String(mc); | ||
1178 | - m_listener.onKeyPadEvent(info); | ||
1179 | - } | ||
1180 | - | ||
1181 | - break; | ||
1182 | - case CMD_BASE_STATUS_CHANGE:// 基础信标变化(主动下发) | ||
1183 | - responseBaseStatusChange(data, size); | ||
1184 | - onBaseInfo(data); | ||
1185 | - break; | ||
1186 | - case CMD_VOTE_STATUS_CHANGE:// 投票信标变化 | ||
1187 | - | ||
1188 | - responseVoteStatusChange(data, size); | ||
1189 | - clearSentItems(); | ||
1190 | - onVoteInfo(data); | ||
1191 | - | ||
1192 | - break; | ||
1193 | - | ||
1194 | - case CMD_VOTE_RESULT_SEND_RESPONSE: | ||
1195 | -// sendToModalSuccessResponse( data[5] & 0xff); | ||
1196 | - break; | ||
1197 | - case CMD_VOTE_SEND_SUCCESS_RESPONSE: | ||
1198 | - sendToModalSuccessResponse( data[5] & 0xff); | ||
1199 | - responseVoteSendSuccess(data, size); | ||
1200 | - break; | ||
1201 | - | ||
1202 | - case CMD_KEY_MANAGE:// 表决器管理类指令,单包,透传 | ||
1203 | - CmdDataInfo info = new CmdDataInfo(); | ||
1204 | - info.cmd = data[7]; | ||
1205 | - info.data = Arrays.copyOfRange(data, 8, 28); | ||
1206 | - if(info.cmd == 25 ){ | ||
1207 | - int keyId = (data[5] << 8) | data[6]; | ||
1208 | - if(keyId != 0) { | ||
1209 | - responseClearKeyboardData(data,size); | ||
1210 | - } | ||
1211 | - }else if(info.cmd == 20){ | ||
1212 | - int keyId = (data[5] << 8) | data[6]; | ||
1213 | - if(keyId == onLineInfo.keyId){ | ||
1214 | - responseAuthrizeKeyboardData(data,size); | ||
1215 | - }else{ | ||
1216 | - break; | ||
1217 | - } | ||
1218 | - } | ||
1219 | - m_listener.onCmdData(info); | ||
1220 | - break; | ||
1221 | - case CMD_MULTI_PCKAGE_DOWNLOAD: | ||
1222 | - onMultiPackageInfo(data, size); | ||
1223 | - break; | ||
1224 | - case CMD_COM_COMMUNICATION_TEST_RESPONSE: | ||
1225 | - int sendn = data[8] & 0xff; | ||
1226 | - boolean isOk = true; | ||
1227 | - for(int i=1;i<17;i++){ | ||
1228 | - if(data[10+i] != i){ | ||
1229 | - isOk = false; | ||
1230 | - } | ||
1231 | - } | ||
1232 | - m_listener.onComCommunicationTest(sendn,isOk); | ||
1233 | - break; | ||
1234 | - case CMD_FIRM_UPDATE_RESPONSE: | ||
1235 | - switch (data[5]) { | ||
1236 | - case 2:// '模块询问是否进入DFU | ||
1237 | - keepFirmMode(); | ||
1238 | - eraseFlash(); | ||
1239 | - break; | ||
1240 | - case 3:// 擦除应答 | ||
1241 | - if (data[8] != 1) { | ||
1242 | - LogUtil.e(TAG, "eraseFlash fail"); | ||
1243 | - m_listener.onFirmUpdateResult(false, "擦除固件失败!"); | ||
1244 | - break; | ||
1245 | - } | ||
1246 | - LogUtil.e(TAG, "eraseFlash ok"); | ||
1247 | - m_listener.onFirmUpdateInfo("擦除固件完成,开始写入..."); | ||
1248 | - CheckFirmReceveThread checkFirmThread = new CheckFirmReceveThread(); | ||
1249 | - checkFirmThread.start(); | ||
1250 | - writeFrimPageErrCnt = 0; | ||
1251 | - writeFlash(firmWritePage); | ||
1252 | - break; | ||
1253 | - case 4:// 写应答 | ||
1254 | - if (data[8] == 1) { | ||
1255 | - firmWritePage++; | ||
1256 | - writeFrimPageErrCnt = 0; | ||
1257 | - if (firmWritePage < firmWritePageMax ) { | ||
1258 | - m_listener.onFirmUpdate(firmWritePage * 100 / firmWritePageMax); | ||
1259 | - LogUtil.d(TAG, "write page ok! " + firmWritePage + "/" + firmWritePageMax + " ==" | ||
1260 | - + firmWritePage * 100 / firmWritePageMax + "%"); | ||
1261 | - writeFlash(firmWritePage); | ||
1262 | - } else { | ||
1263 | - m_listener.onFirmUpdateInfo("写入完成"); | ||
1264 | - m_listener.onFirmUpdate(100); | ||
1265 | - LogUtil.i(TAG, "write 100%"); | ||
1266 | - sleep(2000); | ||
1267 | - exitFirmUpdate(1); | ||
1268 | - LogUtil.i(TAG, "exitFirmUpdate"); | ||
1269 | - m_listener.onFirmUpdateResult(true, null); | ||
1270 | - } | ||
1271 | - } else { | ||
1272 | - LogUtil.d(TAG,"应答写失败 write page error"); | ||
1273 | - } | ||
1274 | - break; | ||
1275 | - case 5: // 退出升级 | ||
1276 | - LogUtil.d(TAG, "exit update!"); | ||
1277 | - m_listener.onFirmUpdateInfo("退出升级模式成功!"); | ||
1278 | - sleep(3000); | ||
1279 | - LogUtil.d(TAG, "sleep 3s getWorkMode!"); | ||
1280 | - for(int i=0;i<5;i++) { | ||
1281 | - getWorkMode(); | ||
1282 | - sleep(1000); | ||
1283 | - } | ||
1284 | - getBaseStatus(); | ||
1285 | - | ||
1286 | - break; | ||
1287 | - default: | ||
1288 | - break; | ||
1289 | - } | ||
1290 | - default: | ||
1291 | - break; | ||
1292 | - } | ||
1293 | - | ||
1294 | - } | ||
1295 | - | ||
1296 | - private void sleep(int ms){ | ||
1297 | - try { | ||
1298 | - Thread.sleep(ms); | ||
1299 | - } catch (Exception e) { | ||
1300 | - } | ||
1301 | - } | ||
1302 | - | ||
1303 | - //// 回应模块基础信标变化,模块停止重发,否则模块会不断发送 | ||
1304 | - private void responseBaseStatusChange(byte[] data, int size) { | ||
1305 | - byte[] retData = Arrays.copyOf(data, size); | ||
1306 | - retData[4] = (byte) 0xF1; | ||
1307 | - writeToCom(retData); | ||
1308 | - } | ||
1309 | - | ||
1310 | - // 处理基础信标变化 | ||
1311 | - private void onBaseInfo(byte[] data) { | ||
1312 | - LogUtil.i(TAG,"onBaseInfo",data); | ||
1313 | - BaseInfo info = new BaseInfo(); | ||
1314 | - info.baseId = data[5] & 0xff;// baseID | ||
1315 | - info.idMode = data[6] & 0xff; | ||
1316 | - info.confId = ((data[7] & 0xff) << 8) | (data[8] & 0xff); | ||
1317 | - | ||
1318 | - info.billId = data[9] & 0xff; | ||
1319 | - info.authCode = (data[10] & 0xff) << 8 | (data[11] & 0xff); | ||
1320 | - info.login = data[12] & 0xff; | ||
1321 | - info.report = data[13] & 0xff; | ||
1322 | - info.offTime = data[14] & 0xff; | ||
1323 | - info.attrib = data[15] & 0xff; | ||
1324 | - info.pageNo = (data[16] & 0xff) << 8 | (data[17] & 0xff); | ||
1325 | - byte[] bname = Arrays.copyOfRange(data, 16, 16 + 12); | ||
1326 | - info.baseName = new String(bname); | ||
1327 | - | ||
1328 | - m_listener.onBaseEvent(info); | ||
1329 | - } | ||
1330 | - | ||
1331 | - // 回应模块投票信标变化,模块停止重发,否则模块会不断发送 | ||
1332 | - private void responseVoteStatusChange(byte[] data, int size) { | ||
1333 | - byte[] retData = Arrays.copyOf(data, size); | ||
1334 | - retData[4] = (byte) 0xF2; | ||
1335 | - writeToCom(retData); | ||
1336 | - } | ||
1337 | - | ||
1338 | - // 回应发送成功通知 | ||
1339 | - private void responseVoteSendSuccess(byte[] data, int size) { | ||
1340 | - | ||
1341 | -// byte[] retData = Arrays.copyOf(data, size); | ||
1342 | -// retData[4] = (byte) 0xF3; | ||
1343 | -// writeToCom(retData); | ||
1344 | - | ||
1345 | - int serialNo = data[5] & 0xff; | ||
1346 | - VoteResultItem item = removeSentItem(serialNo); | ||
1347 | - | ||
1348 | - if ((byte)serialNo == allOkSerialNumber) { | ||
1349 | - m_listener.onVoteSubmitAllOkSuccess(); | ||
1350 | - } else { | ||
1351 | - if(item == null){ | ||
1352 | - LogUtil.e(TAG,"serialNo " + " 丢失???"); | ||
1353 | - } | ||
1354 | - m_listener.onVoteSubmitSuccess(item); | ||
1355 | - } | ||
1356 | - } | ||
1357 | - | ||
1358 | - //回复清空键盘数据 | ||
1359 | - private void responseClearKeyboardData(byte[] data,int len){ | ||
1360 | - byte[] retData = Arrays.copyOf(data, len); | ||
1361 | - retData[4] = (byte) 0xB0; | ||
1362 | - retData[8] = 1; | ||
1363 | - writeToCom(retData); | ||
1364 | - } | ||
1365 | - | ||
1366 | - //回复键盘授权数据 | ||
1367 | - private void responseAuthrizeKeyboardData(byte[] data,int len){ | ||
1368 | - byte[] retData = Arrays.copyOf(data, len); | ||
1369 | - retData[4] = (byte) 0xB0; | ||
1370 | - retData[8] = 1; | ||
1371 | - writeToCom(retData); | ||
1372 | - } | ||
1373 | - | ||
1374 | - // 处理投票信标变化 | ||
1375 | - private void onVoteInfo(byte[] data) { | ||
1376 | - byte[] dt = Arrays.copyOfRange(data, 4, data.length);// 从len开始,和文档下标统一 | ||
1377 | - VoteInfo info = new VoteInfo(); | ||
1378 | - info.baseId = dt[1] & 0xff; | ||
1379 | - info.nowT = dt[2] & 0xff << 8 | dt[3] & 0xff; | ||
1380 | - info.dataPos = dt[4] & 0xff; | ||
1381 | - info.mode = dt[5] & 0xff; | ||
1382 | - info.mode1_msgType = dt[6] & 0xff; | ||
1383 | -// if(info.mode != VoteType_Stop){ | ||
1384 | -// serialNumber = 0; | ||
1385 | -// } | ||
1386 | - | ||
1387 | - if (info.mode == VoteType_Stop) { // 停止 | ||
1388 | - if (info.mode1_msgType == 2) { // 有结果 | ||
1389 | - info.resultInfo.resultType = dt[7] & 0xff; | ||
1390 | - info.resultInfo.bits = dt[8] & 0xff; | ||
1391 | - info.resultInfo.num0 = (dt[9] & 0xff) << 8 | (dt[10] & 0xff); | ||
1392 | - info.resultInfo.num1 = (dt[11] & 0xff) << 8 | (dt[12] & 0xff); | ||
1393 | - info.resultInfo.num2 = (dt[13] & 0xff) << 8 | (dt[14] & 0xff); | ||
1394 | - info.resultInfo.num3 = (dt[15] & 0xff) << 8 | (dt[16] & 0xff); | ||
1395 | - info.resultInfo.num4 = (dt[17] & 0xff) << 8 | (dt[18] & 0xff); | ||
1396 | - info.resultInfo.num5 = (dt[19] & 0xff) << 8 | (dt[20] & 0xff); | ||
1397 | - if(dt.length > 22){ | ||
1398 | - info.resultInfo.num6 = (dt[21] & 0xff) << 8 | (dt[22] & 0xff); | ||
1399 | - } | ||
1400 | - } | ||
1401 | - } else if (info.mode == VoteType_BatchVote) { | ||
1402 | - printDataBuf(data, data.length, "batchvote:"); | ||
1403 | - if(dt.length > 23){ | ||
1404 | - info.mode2_modify = dt[23] & 0xff; | ||
1405 | - } | ||
1406 | - info.mode3_secret = dt[12] & 0xff; | ||
1407 | - info.less = dt[11] & 0xff; | ||
1408 | - info.mode3_secret = dt[12] & 0xff; | ||
1409 | - info.fixballot = dt[13] & 0xff ; | ||
1410 | - if(info.fixballot > 0 ){ | ||
1411 | - info.limitFavor = dt[14] & 0xff ; | ||
1412 | - info.limitOppo = dt[15] & 0xff ; | ||
1413 | - info.limitWaiver = dt[16] & 0xff ; | ||
1414 | - }else{ | ||
1415 | - info.limitFavor = 0 ; | ||
1416 | - info.limitOppo = 0 ; | ||
1417 | - info.limitWaiver = 0; | ||
1418 | - } | ||
1419 | - info.voteid = dt[21] & 0xff; | ||
1420 | - } else if (info.mode == VoteType_Choice) { | ||
1421 | - info.mode2_modify = dt[7] & 0xff; | ||
1422 | - info.mode3_secret = dt[8] & 0xff; | ||
1423 | - info.mode4 = dt[9] & 0xff; | ||
1424 | - info.mode5 = dt[10] & 0xff; | ||
1425 | - info.mode6 = dt[11] & 0xff; | ||
1426 | - info.mode7 = dt[12] & 0xff; | ||
1427 | - }else if(info.mode == VoteType_BatchElect) {//选举 | ||
1428 | - info.electInfo.type = dt[6] & 0xff; | ||
1429 | - info.electInfo.random = dt[7] & 0xff; | ||
1430 | - info.electInfo.select = dt[8] & 0xff; | ||
1431 | - info.electInfo.other = dt[9] & 0xff; | ||
1432 | - info.electInfo.less = dt[10] & 0xff; | ||
1433 | - info.electInfo.secrecy = dt[11] & 0xff; | ||
1434 | - info.electInfo.modify = dt[12] & 0xff; | ||
1435 | - info.electInfo.start = dt[13] & 0xff; | ||
1436 | - info.electInfo.end = dt[14] & 0xff; | ||
1437 | - info.electInfo.equityMode = dt[15] & 0xff; | ||
1438 | - info.electInfo.minSelect = dt[16] & 0xff; | ||
1439 | - info.electInfo.voteid = dt[21] & 0xff; | ||
1440 | - | ||
1441 | - }else if(info.mode == VoteType_SingleItemEvalue) {//单项评分 | ||
1442 | - info.singleEvalueInfo.mode1 = dt[6] & 0xff; | ||
1443 | - info.singleEvalueInfo.mode2 = dt[7] & 0xff; | ||
1444 | - info.singleEvalueInfo.mode3 = dt[8] & 0xff; | ||
1445 | - info.singleEvalueInfo.mode4 = dt[9] & 0xff; | ||
1446 | - info.singleEvalueInfo.mode5 = dt[10] & 0xff; | ||
1447 | - info.singleEvalueInfo.mode6 = dt[11] & 0xff; | ||
1448 | - info.singleEvalueInfo.mode7 = dt[12] & 0xff; | ||
1449 | - info.singleEvalueInfo.mode8 = dt[13] & 0xff; | ||
1450 | - info.singleEvalueInfo.mode9 = dt[14] & 0xff; | ||
1451 | - info.singleEvalueInfo.mode10 = dt[15] & 0xff; | ||
1452 | - info.singleEvalueInfo.mode11 = dt[16] & 0xff; | ||
1453 | - info.singleEvalueInfo.mode12 = dt[17] & 0xff; | ||
1454 | - info.singleEvalueInfo.title = new byte[12]; | ||
1455 | - | ||
1456 | - System.arraycopy(dt, 12, info.singleEvalueInfo.title, 0, 12); | ||
1457 | - if(dt.length > 24){ | ||
1458 | - info.singleEvalueInfo.number = dt[24] & 0xff; | ||
1459 | - } | ||
1460 | - }else if(info.mode == VoteType_BatchEvalue) { | ||
1461 | - info.batchEvalueInfo.mode1 = dt[6] & 0xff; | ||
1462 | - info.batchEvalueInfo.startVal = (dt[7] & 0xff) << 8 | (dt[8] & 0xff); | ||
1463 | - info.batchEvalueInfo.endVal = (dt[9] & 0xff) << 8 | (dt[10] & 0xff); | ||
1464 | - info.batchEvalueInfo.autoMove = dt[11] & 0xff; | ||
1465 | - info.batchEvalueInfo.width1 = dt[12] & 0xff; | ||
1466 | - info.batchEvalueInfo.width2 = dt[13] & 0xff; | ||
1467 | - info.batchEvalueInfo.less = dt[14] & 0xff; | ||
1468 | - info.batchEvalueInfo.secrecy = dt[15] & 0xff; | ||
1469 | - info.batchEvalueInfo.modify = dt[16] & 0xff; | ||
1470 | - info.batchEvalueInfo.ruleStart = dt[17] & 0xff; | ||
1471 | - info.batchEvalueInfo.ruleEnd = dt[18] & 0xff; | ||
1472 | - info.batchEvalueInfo.sliderover = dt[19] & 0xff; | ||
1473 | - }else if(info.mode == VoteType_BatchIDEvalue){ | ||
1474 | - info.batchEvalueInfo.mode1 = dt[6] & 0xff; | ||
1475 | - info.batchEvalueInfo.startVal = (dt[7] & 0xff) << 8 | (dt[8] & 0xff); | ||
1476 | - info.batchEvalueInfo.endVal = (dt[9] & 0xff) << 8 | (dt[10] & 0xff); | ||
1477 | - info.batchEvalueInfo.autoMove = dt[11] & 0xff; | ||
1478 | - info.batchEvalueInfo.width1 = dt[12] & 0xff; | ||
1479 | - info.batchEvalueInfo.width2 = dt[13] & 0xff; | ||
1480 | - info.batchEvalueInfo.less = dt[14] & 0xff; | ||
1481 | - info.batchEvalueInfo.secrecy = dt[15] & 0xff; | ||
1482 | - info.batchEvalueInfo.modify = dt[16] & 0xff; | ||
1483 | - info.batchEvalueInfo.ruleStart = dt[17] & 0xff; | ||
1484 | - info.batchEvalueInfo.ruleEnd = dt[18] & 0xff; | ||
1485 | - info.batchEvalueInfo.sliderover = dt[19] & 0xff; | ||
1486 | - } else { | ||
1487 | - info.mode2_modify = dt[7] & 0xff; | ||
1488 | - info.mode3_secret = dt[8] & 0xff; | ||
1489 | - info.mode4 = dt[9] & 0xff; | ||
1490 | - info.voteid = dt[11] & 0xff; | ||
1491 | - info.file = dt[12] & 0xff; | ||
1492 | - info.init = dt[13] & 0xff; | ||
1493 | - } | ||
1494 | - m_listener.onVoteEvent(info); | ||
1495 | - } | ||
1496 | - | ||
1497 | - | ||
1498 | - | ||
1499 | - private byte[] broadcastData = new byte[4096]; | ||
1500 | - private byte[] fileData; | ||
1501 | - private int fileLen; | ||
1502 | - private int lastPackH = -1; | ||
1503 | - | ||
1504 | - private short needBits = 0; | ||
1505 | - private int okBits = 0; | ||
1506 | - private int currDownloadMsgId; | ||
1507 | - private int broadMsgId = -1; | ||
1508 | - private long lastOnMultiPackageDataTime; | ||
1509 | - | ||
1510 | - private int maxPackH; //用于计算收到长度 | ||
1511 | - private int maxPachL; //用于计算收到长度 | ||
1512 | - | ||
1513 | - private int downType; | ||
1514 | - private int downId; | ||
1515 | - | ||
1516 | - | ||
1517 | - private void onMultiPackageInfo(byte[] data, int size) { | ||
1518 | - byte[] dt = Arrays.copyOfRange(data, 3, data.length);// 从len开始,和文档下标统一 | ||
1519 | - int downCmd = dt[4]; //1 进入或退出下载状态 | ||
1520 | - downType = dt[5];// 10即时信息 或 11短信 | ||
1521 | - downId = dt[6]; ////数据包标识码 | ||
1522 | - int dcmd = dt[7];// 1:进入下载 0:退出下载 | ||
1523 | - | ||
1524 | - if (downCmd == 1) { // 1:进入/退出下载 | ||
1525 | - resopnseMultiPackageMode(data, size); | ||
1526 | - if (dcmd == 1) {//模式 1进入下载 | ||
1527 | - | ||
1528 | - Log.d(TAG, " 1:进入下载 。。。。。downType = " + downType + " downId:"+downId); | ||
1529 | -// m_listener.onMultiPackageStartDownload(downType,downId); | ||
1530 | - if (downType == 40 ) {//下载文件模式 | ||
1531 | - lastPackH = -1; | ||
1532 | - int packH = dt[8]; | ||
1533 | - int packL = dt[9] + 1; | ||
1534 | - fileLen = (packH * 16 + packL) * 16 ; | ||
1535 | - LogUtil.d(TAG, "下载文件,长度:" + fileLen); | ||
1536 | - fileData = new byte[fileLen]; | ||
1537 | - Arrays.fill(fileData, (byte) 0x0); | ||
1538 | - | ||
1539 | - } else if (downType >=1 && downType <=3) { | ||
1540 | - maxPackH = 0; | ||
1541 | - maxPachL = 0; | ||
1542 | - Arrays.fill(broadcastData, (byte) 0x0); | ||
1543 | - | ||
1544 | - } | ||
1545 | - } else { //0退出下载 | ||
1546 | - LogUtil.d(TAG, dcmd + ": 退出下载。。。。。。。。。"); | ||
1547 | - if (downType == 40) { | ||
1548 | - if (System.currentTimeMillis() - lastOnMultiPackageDataTime > 500) { | ||
1549 | - lastOnMultiPackageDataTime = System.currentTimeMillis(); | ||
1550 | - m_listener.onMultiPackageData(fileData, fileLen -4 ); | ||
1551 | - } | ||
1552 | - | ||
1553 | - }else if(downType >=1 && downType <=3){ | ||
1554 | - if (System.currentTimeMillis() - lastOnMultiPackageDataTime > 500) { | ||
1555 | - lastOnMultiPackageDataTime = System.currentTimeMillis(); | ||
1556 | - Log.d(TAG, "maxPackH:" + maxPackH + " maxPachL:" + maxPachL); | ||
1557 | - broadcastData[0] = (byte) 0xF4 ; | ||
1558 | - broadcastData[1] = (byte) 0xF5 ; | ||
1559 | - broadcastData[2] = (byte) downType; | ||
1560 | - broadcastData[3] = (byte) downId; | ||
1561 | - m_listener.onMultiPackageData(broadcastData, (maxPackH+1) * 16 + (maxPachL+1) * 16 + 4); | ||
1562 | - } | ||
1563 | - } | ||
1564 | - } | ||
1565 | - } else if (downCmd == 2) { // 2:下载数据 | ||
1566 | - int msgid = (byte) dt[6]; | ||
1567 | - byte packH = dt[7];// 数据段 编号 当前最大15(16片) | ||
1568 | - byte packL = dt[8];// 数据片编号 | ||
1569 | - LogUtil.d(TAG, "下载。。。msgId:" + msgid + " packH:" + packH + " apckL:" + packL); | ||
1570 | - | ||
1571 | - if (downType == 40) {// 文件下载 | ||
1572 | - if (lastPackH != packH) { //新的packH | ||
1573 | - LogUtil.i(TAG, "new packH......."); | ||
1574 | - okBits = 0; | ||
1575 | - lastPackH = packH; | ||
1576 | - } | ||
1577 | - System.arraycopy(dt, 9, fileData, (packH * 16 + packL) * 16, 16); | ||
1578 | - okBits |= (1 << packL); | ||
1579 | - LogUtil.d(TAG, "packL:" + packL + " okBits:" + okBits); | ||
1580 | - | ||
1581 | - } else {// 广播 | ||
1582 | - needBits = calcBits(packH); | ||
1583 | - if (broadMsgId != msgid) { | ||
1584 | - Arrays.fill(broadcastData, (byte) 0x0); | ||
1585 | - broadMsgId = msgid; | ||
1586 | - okBits = 0; | ||
1587 | - } | ||
1588 | - System.arraycopy(dt, 9, broadcastData, packL * 16, 16); | ||
1589 | - okBits |= (1 << packL); | ||
1590 | - LogUtil.d(TAG, "packL:" + packL + " okBits:" + okBits + " needBits:" + needBits); | ||
1591 | - if (okBits == needBits) { | ||
1592 | - if (broadMsgId != currDownloadMsgId) { | ||
1593 | - m_listener.onMultiPackageData(broadcastData, (packH + 1) * 16); | ||
1594 | - currDownloadMsgId = broadMsgId; | ||
1595 | - } | ||
1596 | - Arrays.fill(broadcastData, (byte) 0x0); | ||
1597 | - broadMsgId = msgid; | ||
1598 | - okBits = 0; | ||
1599 | - } | ||
1600 | - /*needBits = calcBits(packH); | ||
1601 | - | ||
1602 | - if (broadMsgId != msgid) { | ||
1603 | - Arrays.fill(broadcastData, (byte) 0x0); | ||
1604 | - broadMsgId = msgid; | ||
1605 | - okBits = 0; | ||
1606 | - } | ||
1607 | - System.arraycopy(dt, 9, broadcastData, packL * 16, 16); | ||
1608 | - if (lastPackH != packH) { | ||
1609 | - Log.i(TAG, "new packH......."); | ||
1610 | - needBits = calcBits((byte)16); | ||
1611 | - okBits = 0; | ||
1612 | - lastPackH = packH; | ||
1613 | - maxPachL = 0; | ||
1614 | - } | ||
1615 | - | ||
1616 | - if(packH> maxPackH){ | ||
1617 | - maxPackH = packH; | ||
1618 | - } | ||
1619 | - if(packL > maxPachL){ | ||
1620 | - maxPachL = packL; | ||
1621 | - } | ||
1622 | - | ||
1623 | - if(downType >=1 && downType <=3){ | ||
1624 | - System.arraycopy(dt, 9, broadcastData, (packH * 16 + packL) * 16 + 4, 16); | ||
1625 | - }else { | ||
1626 | - System.arraycopy(dt, 9, broadcastData, (packH * 16 + packL) * 16, 16); | ||
1627 | - } | ||
1628 | - okBits |= (1 << packL); | ||
1629 | - Log.d(TAG, "packL:" + packL + " okBits:" + okBits + " needBits:" + (needBits & 0xffff) + " downType" + downType); | ||
1630 | - if( downType > 3) { | ||
1631 | - | ||
1632 | - if (okBits == needBits) { | ||
1633 | - if (broadMsgId != currDownloadMsgId) { | ||
1634 | - m_listener.onMultiPackageData(broadcastData, (maxPackH * 16 + maxPachL) * 16 ); | ||
1635 | - currDownloadMsgId = broadMsgId; | ||
1636 | - } | ||
1637 | - Arrays.fill(broadcastData, (byte) 0x0); | ||
1638 | - broadMsgId = msgid; | ||
1639 | - okBits = 0; | ||
1640 | - | ||
1641 | - } | ||
1642 | - }*/ | ||
1643 | - } | ||
1644 | - } else if (downCmd == 3) { // 3:询问 | ||
1645 | - resopnseMultiPackageQuery(data, size); | ||
1646 | - Log.d(TAG, " 3:询问。。。。。。。。。"); | ||
1647 | - } | ||
1648 | - } | ||
1649 | - | ||
1650 | - private short calcBits(byte packh) { | ||
1651 | - short bits = 0; | ||
1652 | - for (int i = 0; i <= packh; i++) { | ||
1653 | - bits |= (1 << i); | ||
1654 | - } | ||
1655 | - return bits; | ||
1656 | - } | ||
1657 | - | ||
1658 | - private void resopnseMultiPackageMode(byte[] data, int size) { | ||
1659 | - byte[] retData = Arrays.copyOf(data, size); | ||
1660 | - retData[4] = (byte) 0xC0; | ||
1661 | - writeToCom(retData); | ||
1662 | - } | ||
1663 | - | ||
1664 | - private void resopnseMultiPackageQuery(byte[] data, int size) { | ||
1665 | - byte[] retData = Arrays.copyOf(data, size); | ||
1666 | - retData[4] = (byte) 0xC0; | ||
1667 | - int tmpOk = ~okBits; | ||
1668 | - retData[11] = (byte) tmpOk; | ||
1669 | - retData[12] = (byte) (tmpOk >> 8); | ||
1670 | - writeToCom(retData); | ||
1671 | - } | ||
1672 | - | ||
1673 | - public static String getVoteType(int mode) { | ||
1674 | - switch (mode) { | ||
1675 | - case VoteType_Stop: | ||
1676 | - return "VoteType_Stop"; | ||
1677 | - case VoteType_Signin: | ||
1678 | - return "VoteType_Signin"; | ||
1679 | - case VoteType_Vote: | ||
1680 | - return "VoteType_Vote"; | ||
1681 | - case VoteType_BatchVote: | ||
1682 | - return "VoteType_BatchVote"; | ||
1683 | - case VoteType_BatchElect: | ||
1684 | - return "VoteType_BatchElect"; | ||
1685 | - | ||
1686 | - default: | ||
1687 | - break; | ||
1688 | - } | ||
1689 | - return "" + mode; | ||
1690 | - } | ||
1691 | - | ||
1692 | - public static String getKeySn(byte[] data) { | ||
1693 | - String sn = ""; | ||
1694 | - String CS = "0123456789ABCDEF"; | ||
1695 | - for (int i = 0; i < 6; i++) { | ||
1696 | - sn += CS.charAt((data[i] >> 4) & 0xF); | ||
1697 | - sn += CS.charAt((data[i] >> 0) & 0xF); | ||
1698 | - } | ||
1699 | - return sn; | ||
1700 | - | ||
1701 | - } | ||
1702 | - | ||
1703 | - private long writeOkPageNo; | ||
1704 | - private int compareCount; | ||
1705 | - private class CheckFirmReceveThread extends Thread{ | ||
1706 | - public void run() { | ||
1707 | - while (true) { | ||
1708 | - try { | ||
1709 | - Thread.sleep(1000); | ||
1710 | - if(writeOkPageNo != firmWritePage ){ | ||
1711 | - writeOkPageNo = firmWritePage; | ||
1712 | - //sendMessage(keypadID + ":recv"+lastReceveLength+"\n"); | ||
1713 | - //LogUtil.d(TAG,"CheckReceveThread:check ok!"); | ||
1714 | - compareCount = 0; | ||
1715 | - }else{ | ||
1716 | - compareCount ++; | ||
1717 | - | ||
1718 | - if(compareCount <= 20){ | ||
1719 | - LogUtil.d(TAG,"CheckWriteFirmhread:retry ==========="); | ||
1720 | - | ||
1721 | - m_listener.onFirmUpdateInfo("与入页:"+firmWritePage +"失败, 次数:" + compareCount); | ||
1722 | - writeFlash(firmWritePage); | ||
1723 | - }else{ | ||
1724 | - compareCount = 0; | ||
1725 | - | ||
1726 | - LogUtil.d(TAG,"CheckWriteFirmhread:fail , exit!"); | ||
1727 | - | ||
1728 | - LogUtil.e(TAG, "写入扇区" + firmWritePage + "失败!"); | ||
1729 | - m_listener.onFirmUpdateResult(false, "写入扇区" + firmWritePage + "失败!"); | ||
1730 | - exitFirmUpdate(2); | ||
1731 | - | ||
1732 | - break; | ||
1733 | - } | ||
1734 | - } | ||
1735 | - | ||
1736 | - | ||
1737 | - | ||
1738 | - if (firmWritePage > 0 && firmWritePage == firmWritePageMax) { | ||
1739 | - LogUtil.d(TAG,"CheckWriteFirmhread:ok : exit!"); | ||
1740 | - break; | ||
1741 | - } | ||
1742 | - | ||
1743 | - } catch (InterruptedException e) { | ||
1744 | - e.printStackTrace(); | ||
1745 | - } | ||
1746 | - | ||
1747 | - } | ||
1748 | - } | ||
1749 | - }; | ||
1750 | - | ||
1751 | - private static int encodeBCD(byte c) { | ||
1752 | - if (c >= 'a' && c <= 'f') { | ||
1753 | - return 10 + (c - 'a'); | ||
1754 | - }else if (c >= '0' && c <= '9') { | ||
1755 | - return c - '0'; | ||
1756 | - }else if (c >= 'A' && c <= 'F') { | ||
1757 | - return 10 + (c - 'A'); | ||
1758 | - }else if(c == '.'){ | ||
1759 | - return 0xE; | ||
1760 | - } | ||
1761 | - return -1; | ||
1762 | - } | ||
1763 | - | ||
1764 | - | ||
1765 | - /** | ||
1766 | - *把字符串形式转换为字节形式 | ||
1767 | - */ | ||
1768 | - private byte[] util_encodeBCD(byte[] cs) { | ||
1769 | - byte[] rs = new byte[17]; | ||
1770 | - Arrays.fill(rs, (byte) 0xff);// | ||
1771 | - | ||
1772 | - int len = cs.length<16 ? cs.length : 16; | ||
1773 | - int io = 0; | ||
1774 | - | ||
1775 | - for (int i = 0; i < len ; i+=2) { | ||
1776 | - int n = encodeBCD(cs[i]); | ||
1777 | - n <<= 4; | ||
1778 | - if(i+1 == cs.length){ | ||
1779 | - rs[io++] = (byte) (n|0xf); | ||
1780 | - break; | ||
1781 | - } | ||
1782 | - | ||
1783 | - n |= encodeBCD(cs[i+1]); | ||
1784 | - if (n < 0) { | ||
1785 | - break; | ||
1786 | - } | ||
1787 | - rs[io++] = (byte)n; | ||
1788 | - } | ||
1789 | - rs[++io] = 0; | ||
1790 | - return rs; | ||
1791 | - } | ||
1792 | - | ||
1793 | - public static String util_decodeBCD(byte[] cs , int len){ | ||
1794 | - byte[] buf = new byte[8*2]; | ||
1795 | - Arrays.fill(buf,(byte) 0); | ||
1796 | - String bcdNum = "0123456789ABCD.F"; | ||
1797 | - String bcdStr = bytesToHexString(cs); | ||
1798 | - for(int i=0;i<len*2;i+=2){ | ||
1799 | - byte item = bcdStr.getBytes()[i]; | ||
1800 | - if(item >= '0' && item <= '9') { | ||
1801 | - buf[i] = item; | ||
1802 | - }else if(item == 'E' ){ | ||
1803 | - buf[i] = '.'; | ||
1804 | - }else if(item == 'F' ){ | ||
1805 | - buf[i] = 0; | ||
1806 | - break; | ||
1807 | - } | ||
1808 | - | ||
1809 | - item = bcdStr.getBytes()[i+1]; | ||
1810 | - if(item >= '0' && item <= '9') { | ||
1811 | - buf[i+1] = item ; | ||
1812 | - }else if(item == 'E' ){ | ||
1813 | - buf[i+1] = '.'; | ||
1814 | - }else if(item == 'F' ){ | ||
1815 | - buf[i+1] = 0; | ||
1816 | - break; | ||
1817 | - } | ||
1818 | - | ||
1819 | - } | ||
1820 | - return new String(buf).trim(); | ||
1821 | - | ||
1822 | - } | ||
1823 | - | ||
1824 | - public static String bytesToHexString(byte[] src){ | ||
1825 | - StringBuilder stringBuilder = new StringBuilder(""); | ||
1826 | - if (src == null || src.length <= 0) { | ||
1827 | - return null; | ||
1828 | - } | ||
1829 | - for (int i = 0; i < src.length; i++) { | ||
1830 | - int v = src[i] & 0xFF; | ||
1831 | - String hv = Integer.toHexString(v); | ||
1832 | - if (hv.length() < 2) { | ||
1833 | - stringBuilder.append(0); | ||
1834 | - } | ||
1835 | - stringBuilder.append(hv); | ||
1836 | - } | ||
1837 | - return stringBuilder.toString().toUpperCase(); | ||
1838 | - } | 2050 | + for (int i = 0; i < src.length; i++) { |
2051 | + int v = src[i] & 0xFF; | ||
2052 | + String hv = Integer.toHexString(v); | ||
2053 | + if (hv.length() < 2) { | ||
2054 | + stringBuilder.append(0); | ||
2055 | + } | ||
2056 | + stringBuilder.append(hv); | ||
2057 | + } | ||
2058 | + return stringBuilder.toString().toUpperCase(); | ||
2059 | + } | ||
2060 | + | ||
2061 | + | ||
2062 | + /** | ||
2063 | + * @param length 长度 | ||
2064 | + * @param filename 文件名 | ||
2065 | + * @Auther Elvis | ||
2066 | + * 主动发起文件申请 | ||
2067 | + */ | ||
2068 | + public void applyFileUpload(int length, String filename, byte anstype,byte index) { | ||
2069 | + byte[] mBuffer = new byte[0x1F + 4]; | ||
2070 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
2071 | + mBuffer[0] = (byte) 0xF5; | ||
2072 | + mBuffer[1] = (byte) 0xAA; | ||
2073 | + mBuffer[2] = (byte) 0xAA; | ||
2074 | + mBuffer[3] = (byte) 0x1F; | ||
2075 | + | ||
2076 | + mBuffer[4] = 0x73; | ||
2077 | + mBuffer[5] = (byte) 0XFF;// 流水号 | ||
2078 | + mBuffer[6] = (byte) 0X01;// 流水号 | ||
2079 | + | ||
2080 | + mBuffer[7] = (byte) 15;// MSGTYPE | ||
2081 | + | ||
2082 | + mBuffer[8] = (byte) anstype;// ANSTYPE 添加5 文件上传指令 | ||
2083 | + mBuffer[9] = index;// 高位 | ||
2084 | +// mBuffer[10] = (byte) length;// 低位 | ||
2085 | + | ||
2086 | +// byte[] bytes = new byte[16]; | ||
2087 | +// try { | ||
2088 | +// if (filename != null) { | ||
2089 | +// bytes = filename.getBytes("GB2312"); | ||
2090 | +// } | ||
2091 | +// } catch (UnsupportedEncodingException e) { | ||
2092 | +// e.printStackTrace(); | ||
2093 | +// } | ||
2094 | +// | ||
2095 | +// if (bytes != null) { | ||
2096 | +// for (int i = 0; i < 16 && i < bytes.length; i++) { | ||
2097 | +// mBuffer[11 + i] = bytes[i]; | ||
2098 | +// } | ||
2099 | +// } | ||
2100 | + | ||
2101 | + writeToCom(mBuffer); | ||
2102 | + } | ||
2103 | + | ||
2104 | + /** | ||
2105 | + * @param keyid 键盘id | ||
2106 | + * @param packid 包id | ||
2107 | + * @param packH 段id | ||
2108 | + * @param packL 片id | ||
2109 | + * @param datas 数据 | ||
2110 | + * @Auther Elvis | ||
2111 | + */ | ||
2112 | + public void uploadFileData(byte[] keyid, byte packid, byte packH, byte packL, byte[] datas, byte packtype) { | ||
2113 | + uploadFileData(keyid, packid, packH, packL, datas, 0, datas.length, packtype); | ||
2114 | + } | ||
2115 | + | ||
2116 | + /** | ||
2117 | + * @param keyid 键盘编号 | ||
2118 | + * @param packid 包id | ||
2119 | + * @param packH 数据段id | ||
2120 | + * @param packL 数据片id | ||
2121 | + * @param datas 数据 | ||
2122 | + * @param offset 偏移位置 | ||
2123 | + * @param length 长度 | ||
2124 | + * @Auther Elvis | ||
2125 | + * 上传数据包(多包应答) | ||
2126 | + */ | ||
2127 | + public void uploadFileData(byte[] keyid, byte packid, byte packH, byte packL, byte[] datas, int offset, int length, byte packtype) { | ||
2128 | + LogUtil.i(TAG, "onMutilPacketData packid=" + packid + ",packH=" + packH + ",packL=" + packL + ",offset=" + offset); | ||
2129 | + byte[] mBuffer = new byte[0x1F + 4]; | ||
2130 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
2131 | + mBuffer[0] = (byte) 0xF5; | ||
2132 | + mBuffer[1] = (byte) 0xAA; | ||
2133 | + mBuffer[2] = (byte) 0xAA; | ||
2134 | + mBuffer[3] = (byte) 0x1F; | ||
2135 | + | ||
2136 | + mBuffer[4] = (byte) 0xA0; | ||
2137 | + if(keyid == null || keyid.length < 2){ | ||
2138 | + if(onLineInfo != null){ | ||
2139 | + keyid[0] = (byte)((onLineInfo.keyId >> 8 ) & 0xFF) ; | ||
2140 | + keyid[1] = (byte)((onLineInfo.keyId ) & 0xFF) ; | ||
2141 | + }else{ | ||
2142 | + keyid = new byte[2]; | ||
2143 | + } | ||
2144 | + } | ||
2145 | + mBuffer[5] = keyid[0]; | ||
2146 | + mBuffer[6] = keyid[1]; | ||
2147 | + | ||
2148 | + mBuffer[7] = 2;//CMD 1 回应多包数据 | ||
2149 | + mBuffer[8] = packtype;//PACKTYPE 多包类型 | ||
2150 | + mBuffer[9] = packid;//数据包标识码 | ||
2151 | + mBuffer[10] = packH;//数据段编号 | ||
2152 | + mBuffer[11] = packL;//数据片编号 | ||
2153 | + for (int i = 0; i < length && i < 16 && i < datas.length - offset; i++) { | ||
2154 | + mBuffer[12 + i] = datas[offset + i]; | ||
2155 | + } | ||
2156 | + writeToCom(mBuffer); | ||
2157 | + } | ||
2158 | + | ||
2159 | + /** | ||
2160 | + * @param packid 包id | ||
2161 | + * @Auther Elvis | ||
2162 | + * 多包接收确认(多包接收应答) | ||
2163 | + */ | ||
2164 | + public void packetConfirmation(byte[] keyid, byte packid, byte packH, byte packL, byte[] names, byte packtype) { | ||
2165 | + LogUtil.i(TAG, "onMutilPacketRespone packid=" + packid + ",packH=" + packH + ",packL=" + packL + ",names=" + names); | ||
2166 | + byte[] mBuffer = new byte[0x1F + 4]; | ||
2167 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
2168 | + mBuffer[0] = (byte) 0xF5; | ||
2169 | + mBuffer[1] = (byte) 0xAA; | ||
2170 | + mBuffer[2] = (byte) 0xAA; | ||
2171 | + mBuffer[3] = (byte) 0x1F; | ||
2172 | + | ||
2173 | + mBuffer[4] = (byte) 0xA0; | ||
2174 | + if(keyid == null || keyid.length < 2){ | ||
2175 | + if(onLineInfo != null){ | ||
2176 | + keyid[0] = (byte)((onLineInfo.keyId >> 8 ) & 0xFF) ; | ||
2177 | + keyid[1] = (byte)((onLineInfo.keyId ) & 0xFF) ; | ||
2178 | + }else{ | ||
2179 | + keyid = new byte[2]; | ||
2180 | + } | ||
2181 | + } | ||
2182 | + mBuffer[5] = keyid[0]; | ||
2183 | + mBuffer[6] = keyid[1]; | ||
2184 | + | ||
2185 | + mBuffer[7] = 1;//CMD 1 | ||
2186 | + mBuffer[8] = packtype;//PACKTYPE 多包类型 | ||
2187 | + mBuffer[9] = packid;//数据包标识码 | ||
2188 | + mBuffer[10] = packH; | ||
2189 | + mBuffer[11] = packL; | ||
2190 | + if (names != null) { | ||
2191 | + for (int i = 0; i < 14 && i < names.length; i++) { | ||
2192 | + mBuffer[12 + i] = names[i]; | ||
2193 | + } | ||
2194 | + } | ||
2195 | + writeToCom(mBuffer); | ||
2196 | + } | ||
2197 | + | ||
2198 | + /** | ||
2199 | + * @param packid 包id | ||
2200 | + * @param packH 数据段id | ||
2201 | + * @Auther Elvis | ||
2202 | + * 多包接收完毕确认(多包接收完毕确认应答) | ||
2203 | + */ | ||
2204 | + public void packetReceptionConfirmed(byte[] keyid, byte packid, byte packH, byte packtype) { | ||
2205 | + LogUtil.i(TAG, "onMutilPacketRespone packid=" + packid + ",packH=" + packH); | ||
2206 | + byte[] mBuffer = new byte[0x1F + 4]; | ||
2207 | + Arrays.fill(mBuffer, (byte) 0x0); | ||
2208 | + mBuffer[0] = (byte) 0xF5; | ||
2209 | + mBuffer[1] = (byte) 0xAA; | ||
2210 | + mBuffer[2] = (byte) 0xAA; | ||
2211 | + mBuffer[3] = (byte) 0x1F; | ||
2212 | + | ||
2213 | + mBuffer[4] = (byte) 0xA0; | ||
2214 | + if(keyid == null || keyid.length < 2){ | ||
2215 | + if(onLineInfo != null){ | ||
2216 | + keyid[0] = (byte)((onLineInfo.keyId >> 8 ) & 0xFF) ; | ||
2217 | + keyid[1] = (byte)((onLineInfo.keyId ) & 0xFF) ; | ||
2218 | + }else{ | ||
2219 | + keyid = new byte[2]; | ||
2220 | + } | ||
2221 | + } | ||
2222 | + mBuffer[5] = keyid[0]; | ||
2223 | + mBuffer[6] = keyid[1]; | ||
2224 | + | ||
2225 | + mBuffer[7] = 3;//CMD 3 多包接收完毕应答 | ||
2226 | + mBuffer[8] = packtype;//PACKTYPE 多包类型 | ||
2227 | + mBuffer[9] = packid;//数据包标识码 | ||
2228 | + writeToCom(mBuffer); | ||
2229 | + } | ||
2230 | + | ||
2231 | + /** | ||
2232 | + * @param datas 基站传递过来的数据 | ||
2233 | + * @param length 长度 | ||
2234 | + * @Auther Elvis | ||
2235 | + */ | ||
2236 | + public void onMutilPacketRequest(byte[] datas, int length) { | ||
2237 | + LogUtil.i(TAG ,"onMutilPacketRequest",datas); | ||
2238 | + byte[] keyid = new byte[2]; | ||
2239 | + keyid[0] = datas[5]; | ||
2240 | + keyid[1] = datas[6]; | ||
2241 | + byte packid = datas[9]; | ||
2242 | + byte packH = datas[10]; | ||
2243 | + byte[] packLs = new byte[2]; | ||
2244 | + packLs[0] = datas[11]; | ||
2245 | + packLs[1] = datas[12]; | ||
2246 | + | ||
2247 | + int keyId = (keyid[0] << 8) | keyid[1]; | ||
2248 | + if (keyId == onLineInfo.keyId) { | ||
2249 | + if (datas[8] == 5) { | ||
2250 | + RFFileUploadModule.getInstance().onUploadFile(datas[7], keyid, packid, packH, packLs); | ||
2251 | + } | ||
2252 | + if (datas[8] == 3) { | ||
2253 | + RFMessageUploadModule.getInstance().onUploadMessage(datas[7], keyid, packid, packH, packLs); | ||
2254 | + } | ||
2255 | + } | ||
2256 | + } | ||
2257 | + | ||
2258 | + public void openSendData(byte[] datas){ | ||
2259 | + writeToCom(datas); | ||
2260 | + } | ||
2261 | + | ||
2262 | + | ||
1839 | 2263 | ||
1840 | } | 2264 | } |
C5/app/src/main/java/com/sunvote/xpadcomm/XPadApiInterface.java
@@ -41,6 +41,7 @@ public interface XPadApiInterface { | @@ -41,6 +41,7 @@ public interface XPadApiInterface { | ||
41 | public static final int CMD_FIRM_UPDATE_RESPONSE = 0xF8;//固件升级应答 | 41 | public static final int CMD_FIRM_UPDATE_RESPONSE = 0xF8;//固件升级应答 |
42 | 42 | ||
43 | public static final int CMD_COM_COMMUNICATION_TEST_RESPONSE = 0xB0; //串口测试应答 | 43 | public static final int CMD_COM_COMMUNICATION_TEST_RESPONSE = 0xB0; //串口测试应答 |
44 | + public static final int CMD_UPLOAD_DATA_RESPONSE = 0x20; //上传指令 | ||
44 | /******************************************************************************* | 45 | /******************************************************************************* |
45 | ******************************************************************************/ | 46 | ******************************************************************************/ |
46 | 47 | ||
@@ -54,7 +55,7 @@ public interface XPadApiInterface { | @@ -54,7 +55,7 @@ public interface XPadApiInterface { | ||
54 | public static final int VoteType_Choice = 10; | 55 | public static final int VoteType_Choice = 10; |
55 | public static final int VoteType_BatchVote = 20;//批次 | 56 | public static final int VoteType_BatchVote = 20;//批次 |
56 | public static final int VoteType_BatchElect = 22;//选举 | 57 | public static final int VoteType_BatchElect = 22;//选举 |
57 | - public static final int VoteType_BatchEvalue = 30; //带名称二维表评测模式 综合测评 | 58 | + public static final int VoteType_BatchEvalue = 30; //带名称二维表评测模式 综合测评 |
58 | public static final int VoteType_BatchIDEvalue = 31; //编号式二维表评测模式 综合测评 | 59 | public static final int VoteType_BatchIDEvalue = 31; //编号式二维表评测模式 综合测评 |
59 | 60 | ||
60 | 61 | ||
@@ -78,21 +79,22 @@ public interface XPadApiInterface { | @@ -78,21 +79,22 @@ public interface XPadApiInterface { | ||
78 | public void getVoteStatus();//查询投票信标 | 79 | public void getVoteStatus();//查询投票信标 |
79 | 80 | ||
80 | public void getKeypadParam(); //查询键盘参数 | 81 | public void getKeypadParam(); //查询键盘参数 |
81 | - public void setKeypadParam(int keyId,byte[] KEYSN ); //设置键盘参数 | 82 | + public void setKeypadParam(int keyId, byte[] KEYSN); //设置键盘参数 |
82 | 83 | ||
83 | 84 | ||
84 | - public void checkOnLine(int volt,int keyinStatus);//查询在线状态 | 85 | + public void checkOnLine(int volt, int keyinStatus);//查询在线状态 |
85 | 86 | ||
86 | - public void execKeypadMatch(int iMode,int channal);//执行配对 | 87 | + public void execKeypadMatch(int iMode, int channal);//执行配对 |
87 | public void configMode();//进入配置模式 | 88 | public void configMode();//进入配置模式 |
88 | 89 | ||
89 | - public void comCommunicationTest(int sendn,int okn);//串口测试 | 90 | + public void comCommunicationTest(int sendn, int okn);//串口测试 |
90 | /* | 91 | /* |
91 | * 上传类 | 92 | * 上传类 |
92 | */ | 93 | */ |
93 | public void submitVote(int ansType, String info);//ID模式结果 | 94 | public void submitVote(int ansType, String info);//ID模式结果 |
94 | - public void submitVoteBySn(byte[] keySn,String info); //SN模式结果 | 95 | + public void submitVoteBySn(byte[] keySn, String info); //SN模式结果 |
95 | public void submitVoteAllOK(); //确认提交 | 96 | public void submitVoteAllOK(); //确认提交 |
97 | + public void submitVoteAllOKWithValue(int ansType, String info);//确认提交带某项结果 | ||
96 | public void cancelSubmitVoteAllOK(); | 98 | public void cancelSubmitVoteAllOK(); |
97 | public void submitSelectOther(String info); | 99 | public void submitSelectOther(String info); |
98 | 100 | ||
@@ -127,23 +129,6 @@ public interface XPadApiInterface { | @@ -127,23 +129,6 @@ public interface XPadApiInterface { | ||
127 | public int offTime;//自动关机时间 | 129 | public int offTime;//自动关机时间 |
128 | public int attrib;//表决器特性:背光模式+蜂鸣器模式等等 | 130 | public int attrib;//表决器特性:背光模式+蜂鸣器模式等等 |
129 | public String baseName; //基站名称,最多12字节 | 131 | public String baseName; //基站名称,最多12字节 |
130 | - | ||
131 | - @Override | ||
132 | - public String toString() { | ||
133 | - return "BaseInfo{" + | ||
134 | - "baseId=" + baseId + | ||
135 | - ", idMode=" + idMode + | ||
136 | - ", confId=" + confId + | ||
137 | - ", billId=" + billId + | ||
138 | - ", pageNo=" + pageNo + | ||
139 | - ", authCode=" + authCode + | ||
140 | - ", login=" + login + | ||
141 | - ", report=" + report + | ||
142 | - ", offTime=" + offTime + | ||
143 | - ", attrib=" + attrib + | ||
144 | - ", baseName='" + baseName + '\'' + | ||
145 | - '}'; | ||
146 | - } | ||
147 | } | 132 | } |
148 | 133 | ||
149 | public class ModelInfo{ | 134 | public class ModelInfo{ |
@@ -174,6 +159,28 @@ public interface XPadApiInterface { | @@ -174,6 +159,28 @@ public interface XPadApiInterface { | ||
174 | public String keySn; | 159 | public String keySn; |
175 | public int comError=0; | 160 | public int comError=0; |
176 | 161 | ||
162 | + @Override | ||
163 | + public boolean equals(Object o) { | ||
164 | + if (this == o) return true; | ||
165 | + if (o == null || getClass() != o.getClass()) return false; | ||
166 | + OnLineInfo that = (OnLineInfo) o; | ||
167 | + return onLine == that.onLine && | ||
168 | + idMode == that.idMode && | ||
169 | + chan == that.chan && | ||
170 | + rssi == that.rssi && | ||
171 | + tx == that.tx && | ||
172 | + rx == that.rx && | ||
173 | + baseId == that.baseId && | ||
174 | + keyId == that.keyId && | ||
175 | + comError == that.comError && | ||
176 | + (keySn == that.keySn || (keySn != null && keySn.equals(that.keySn))); | ||
177 | + } | ||
178 | + | ||
179 | + @Override | ||
180 | + public int hashCode() { | ||
181 | + | ||
182 | + return Arrays.hashCode(new Object[]{onLine, idMode, chan, rssi, tx, rx, baseId, keyId, keySn, comError}); | ||
183 | + } | ||
177 | } | 184 | } |
178 | 185 | ||
179 | 186 | ||
@@ -200,8 +207,8 @@ public interface XPadApiInterface { | @@ -200,8 +207,8 @@ public interface XPadApiInterface { | ||
200 | 207 | ||
201 | /** | 208 | /** |
202 | * 是否带票数限定,,对批次表决、批次评议、批次自定义评议有效 | 209 | * 是否带票数限定,,对批次表决、批次评议、批次自定义评议有效 |
203 | - 0 不限定 | ||
204 | - 1 带票数限定 | 210 | + 0 不限定 |
211 | + 1 带票数限定 | ||
205 | */ | 212 | */ |
206 | public int fixballot; | 213 | public int fixballot; |
207 | /** | 214 | /** |
@@ -225,36 +232,67 @@ public interface XPadApiInterface { | @@ -225,36 +232,67 @@ public interface XPadApiInterface { | ||
225 | public int less;//[11] | 232 | public int less;//[11] |
226 | 233 | ||
227 | @Override | 234 | @Override |
228 | - public String toString() { | ||
229 | - return "VoteInfo{" + | ||
230 | - "baseId=" + baseId + | ||
231 | - ", nowT=" + nowT + | ||
232 | - ", dataPos=" + dataPos + | ||
233 | - ", mode=" + mode + | ||
234 | - ", mode1_msgType=" + mode1_msgType + | ||
235 | - ", mode2_modify=" + mode2_modify + | ||
236 | - ", mode3_secret=" + mode3_secret + | ||
237 | - ", mode4=" + mode4 + | ||
238 | - ", mode5=" + mode5 + | ||
239 | - ", mode6=" + mode6 + | ||
240 | - ", mode7=" + mode7 + | ||
241 | - ", fixballot=" + fixballot + | ||
242 | - ", limitFavor=" + limitFavor + | ||
243 | - ", limitOppo=" + limitOppo + | ||
244 | - ", limitWaiver=" + limitWaiver + | ||
245 | - ", voteid=" + voteid + | ||
246 | - ", file=" + file + | ||
247 | - ", init=" + init + | ||
248 | - ", less=" + less + | ||
249 | - ", resultInfo=" + resultInfo + | ||
250 | - ", electInfo=" + electInfo + | ||
251 | - ", singleEvalueInfo=" + singleEvalueInfo + | ||
252 | - ", batchEvalueInfo=" + batchEvalueInfo + | ||
253 | - '}'; | 235 | + public boolean equals(Object o) { |
236 | + if (this == o) return true; | ||
237 | + if (o == null || getClass() != o.getClass()) return false; | ||
238 | + | ||
239 | + VoteInfo voteInfo = (VoteInfo) o; | ||
240 | + | ||
241 | + if (baseId != voteInfo.baseId) return false; | ||
242 | + if (nowT != voteInfo.nowT) return false; | ||
243 | + if (dataPos != voteInfo.dataPos) return false; | ||
244 | + if (mode != voteInfo.mode) return false; | ||
245 | + if (mode1_msgType != voteInfo.mode1_msgType) return false; | ||
246 | + if (mode2_modify != voteInfo.mode2_modify) return false; | ||
247 | + if (mode3_secret != voteInfo.mode3_secret) return false; | ||
248 | + if (mode4 != voteInfo.mode4) return false; | ||
249 | + if (mode5 != voteInfo.mode5) return false; | ||
250 | + if (mode6 != voteInfo.mode6) return false; | ||
251 | + if (mode7 != voteInfo.mode7) return false; | ||
252 | + if (fixballot != voteInfo.fixballot) return false; | ||
253 | + if (limitFavor != voteInfo.limitFavor) return false; | ||
254 | + if (limitOppo != voteInfo.limitOppo) return false; | ||
255 | + if (limitWaiver != voteInfo.limitWaiver) return false; | ||
256 | + if (voteid != voteInfo.voteid) return false; | ||
257 | + if (file != voteInfo.file) return false; | ||
258 | + if (init != voteInfo.init) return false; | ||
259 | + if (less != voteInfo.less) return false; | ||
260 | + if (!resultInfo.equals(voteInfo.resultInfo)) return false; | ||
261 | + if (!electInfo.equals(voteInfo.electInfo)) return false; | ||
262 | + if (!singleEvalueInfo.equals(voteInfo.singleEvalueInfo)) return false; | ||
263 | + return batchEvalueInfo.equals(voteInfo.batchEvalueInfo); | ||
264 | + } | ||
265 | + | ||
266 | + @Override | ||
267 | + public int hashCode() { | ||
268 | + int result = baseId; | ||
269 | + result = 31 * result + nowT; | ||
270 | + result = 31 * result + dataPos; | ||
271 | + result = 31 * result + mode; | ||
272 | + result = 31 * result + mode1_msgType; | ||
273 | + result = 31 * result + mode2_modify; | ||
274 | + result = 31 * result + mode3_secret; | ||
275 | + result = 31 * result + mode4; | ||
276 | + result = 31 * result + mode5; | ||
277 | + result = 31 * result + mode6; | ||
278 | + result = 31 * result + mode7; | ||
279 | + result = 31 * result + fixballot; | ||
280 | + result = 31 * result + limitFavor; | ||
281 | + result = 31 * result + limitOppo; | ||
282 | + result = 31 * result + limitWaiver; | ||
283 | + result = 31 * result + voteid; | ||
284 | + result = 31 * result + file; | ||
285 | + result = 31 * result + init; | ||
286 | + result = 31 * result + less; | ||
287 | + result = 31 * result + resultInfo.hashCode(); | ||
288 | + result = 31 * result + electInfo.hashCode(); | ||
289 | + result = 31 * result + singleEvalueInfo.hashCode(); | ||
290 | + result = 31 * result + batchEvalueInfo.hashCode(); | ||
291 | + return result; | ||
254 | } | 292 | } |
255 | 293 | ||
256 | public ResultInfo resultInfo = new ResultInfo(); | 294 | public ResultInfo resultInfo = new ResultInfo(); |
257 | - public class ResultInfo{ //结果 | 295 | + public class ResultInfo{//结果 |
258 | public int resultType;//[7] 结果显示类型 。 如 0为 签到 1为表决 | 296 | public int resultType;//[7] 结果显示类型 。 如 0为 签到 1为表决 |
259 | public int bits;// [8] | 297 | public int bits;// [8] |
260 | public int num0;//[9-10] | 298 | public int num0;//[9-10] |
@@ -266,24 +304,9 @@ public interface XPadApiInterface { | @@ -266,24 +304,9 @@ public interface XPadApiInterface { | ||
266 | public int num6;//[21,22] | 304 | public int num6;//[21,22] |
267 | 305 | ||
268 | @Override | 306 | @Override |
269 | - public String toString() { | ||
270 | - return "ResultInfo{" + | ||
271 | - "resultType=" + resultType + | ||
272 | - ", bits=" + bits + | ||
273 | - ", num0=" + num0 + | ||
274 | - ", num1=" + num1 + | ||
275 | - ", num2=" + num2 + | ||
276 | - ", num3=" + num3 + | ||
277 | - ", num4=" + num4 + | ||
278 | - ", num5=" + num5 + | ||
279 | - ", num6=" + num6 + | ||
280 | - '}'; | ||
281 | - } | ||
282 | - | ||
283 | - @Override | ||
284 | public boolean equals(Object o) { | 307 | public boolean equals(Object o) { |
285 | if (this == o) return true; | 308 | if (this == o) return true; |
286 | - if (!(o instanceof ResultInfo)) return false; | 309 | + if (o == null || getClass() != o.getClass()) return false; |
287 | 310 | ||
288 | ResultInfo that = (ResultInfo) o; | 311 | ResultInfo that = (ResultInfo) o; |
289 | 312 | ||
@@ -329,27 +352,9 @@ public interface XPadApiInterface { | @@ -329,27 +352,9 @@ public interface XPadApiInterface { | ||
329 | public int voteid;//[21] | 352 | public int voteid;//[21] |
330 | 353 | ||
331 | @Override | 354 | @Override |
332 | - public String toString() { | ||
333 | - return "ElectInfo{" + | ||
334 | - "type=" + type + | ||
335 | - ", random=" + random + | ||
336 | - ", select=" + select + | ||
337 | - ", other=" + other + | ||
338 | - ", less=" + less + | ||
339 | - ", secrecy=" + secrecy + | ||
340 | - ", modify=" + modify + | ||
341 | - ", start=" + start + | ||
342 | - ", end=" + end + | ||
343 | - ", equityMode=" + equityMode + | ||
344 | - ", minSelect=" + minSelect + | ||
345 | - ", voteid=" + voteid + | ||
346 | - '}'; | ||
347 | - } | ||
348 | - | ||
349 | - @Override | ||
350 | public boolean equals(Object o) { | 355 | public boolean equals(Object o) { |
351 | if (this == o) return true; | 356 | if (this == o) return true; |
352 | - if (!(o instanceof ElectInfo)) return false; | 357 | + if (o == null || getClass() != o.getClass()) return false; |
353 | 358 | ||
354 | ElectInfo electInfo = (ElectInfo) o; | 359 | ElectInfo electInfo = (ElectInfo) o; |
355 | 360 | ||
@@ -403,29 +408,9 @@ public interface XPadApiInterface { | @@ -403,29 +408,9 @@ public interface XPadApiInterface { | ||
403 | public int number;//[24] | 408 | public int number;//[24] |
404 | 409 | ||
405 | @Override | 410 | @Override |
406 | - public String toString() { | ||
407 | - return "SingleItemEvalueInfo{" + | ||
408 | - "mode1=" + mode1 + | ||
409 | - ", mode2=" + mode2 + | ||
410 | - ", mode3=" + mode3 + | ||
411 | - ", mode4=" + mode4 + | ||
412 | - ", mode5=" + mode5 + | ||
413 | - ", mode6=" + mode6 + | ||
414 | - ", mode7=" + mode7 + | ||
415 | - ", mode8=" + mode8 + | ||
416 | - ", mode9=" + mode9 + | ||
417 | - ", mode10=" + mode10 + | ||
418 | - ", mode11=" + mode11 + | ||
419 | - ", mode12=" + mode12 + | ||
420 | - ", title=" + Arrays.toString(title) + | ||
421 | - ", number=" + number + | ||
422 | - '}'; | ||
423 | - } | ||
424 | - | ||
425 | - @Override | ||
426 | public boolean equals(Object o) { | 411 | public boolean equals(Object o) { |
427 | if (this == o) return true; | 412 | if (this == o) return true; |
428 | - if (!(o instanceof SingleItemEvalueInfo)) return false; | 413 | + if (o == null || getClass() != o.getClass()) return false; |
429 | 414 | ||
430 | SingleItemEvalueInfo that = (SingleItemEvalueInfo) o; | 415 | SingleItemEvalueInfo that = (SingleItemEvalueInfo) o; |
431 | 416 | ||
@@ -479,29 +464,13 @@ public interface XPadApiInterface { | @@ -479,29 +464,13 @@ public interface XPadApiInterface { | ||
479 | public int ruleStart;//[7]; | 464 | public int ruleStart;//[7]; |
480 | public int ruleEnd;//[7]; | 465 | public int ruleEnd;//[7]; |
481 | public int sliderover;//[7]; | 466 | public int sliderover;//[7]; |
482 | - | ||
483 | - @Override | ||
484 | - public String toString() { | ||
485 | - return "BatchEvalueInfo{" + | ||
486 | - "mode1=" + mode1 + | ||
487 | - ", startVal=" + startVal + | ||
488 | - ", endVal=" + endVal + | ||
489 | - ", autoMove=" + autoMove + | ||
490 | - ", width1=" + width1 + | ||
491 | - ", width2=" + width2 + | ||
492 | - ", less=" + less + | ||
493 | - ", secrecy=" + secrecy + | ||
494 | - ", modify=" + modify + | ||
495 | - ", ruleStart=" + ruleStart + | ||
496 | - ", ruleEnd=" + ruleEnd + | ||
497 | - ", sliderover=" + sliderover + | ||
498 | - '}'; | ||
499 | - } | 467 | + public int billNo; // 议案编号 |
468 | + public int billSubNo ; // 议案子编号 | ||
500 | 469 | ||
501 | @Override | 470 | @Override |
502 | public boolean equals(Object o) { | 471 | public boolean equals(Object o) { |
503 | if (this == o) return true; | 472 | if (this == o) return true; |
504 | - if (!(o instanceof BatchEvalueInfo)) return false; | 473 | + if (o == null || getClass() != o.getClass()) return false; |
505 | 474 | ||
506 | BatchEvalueInfo that = (BatchEvalueInfo) o; | 475 | BatchEvalueInfo that = (BatchEvalueInfo) o; |
507 | 476 | ||
@@ -516,7 +485,9 @@ public interface XPadApiInterface { | @@ -516,7 +485,9 @@ public interface XPadApiInterface { | ||
516 | if (modify != that.modify) return false; | 485 | if (modify != that.modify) return false; |
517 | if (ruleStart != that.ruleStart) return false; | 486 | if (ruleStart != that.ruleStart) return false; |
518 | if (ruleEnd != that.ruleEnd) return false; | 487 | if (ruleEnd != that.ruleEnd) return false; |
519 | - return sliderover == that.sliderover; | 488 | + if (sliderover != that.sliderover) return false; |
489 | + if (billNo != that.billNo) return false; | ||
490 | + return billSubNo == that.billSubNo; | ||
520 | } | 491 | } |
521 | 492 | ||
522 | @Override | 493 | @Override |
@@ -533,61 +504,12 @@ public interface XPadApiInterface { | @@ -533,61 +504,12 @@ public interface XPadApiInterface { | ||
533 | result = 31 * result + ruleStart; | 504 | result = 31 * result + ruleStart; |
534 | result = 31 * result + ruleEnd; | 505 | result = 31 * result + ruleEnd; |
535 | result = 31 * result + sliderover; | 506 | result = 31 * result + sliderover; |
507 | + result = 31 * result + billNo; | ||
508 | + result = 31 * result + billSubNo; | ||
536 | return result; | 509 | return result; |
537 | } | 510 | } |
538 | } | 511 | } |
539 | 512 | ||
540 | - @Override | ||
541 | - public boolean equals(Object o) { | ||
542 | - if (this == o) return true; | ||
543 | - if (!(o instanceof VoteInfo)) return false; | ||
544 | - | ||
545 | - VoteInfo voteInfo = (VoteInfo) o; | ||
546 | - | ||
547 | - if (baseId != voteInfo.baseId) return false; | ||
548 | - if (nowT != voteInfo.nowT) return false; | ||
549 | - if (dataPos != voteInfo.dataPos) return false; | ||
550 | - if (mode != voteInfo.mode) return false; | ||
551 | - if (mode1_msgType != voteInfo.mode1_msgType) return false; | ||
552 | - if (mode2_modify != voteInfo.mode2_modify) return false; | ||
553 | - if (mode3_secret != voteInfo.mode3_secret) return false; | ||
554 | - if (mode4 != voteInfo.mode4) return false; | ||
555 | - if (mode5 != voteInfo.mode5) return false; | ||
556 | - if (mode6 != voteInfo.mode6) return false; | ||
557 | - if (mode7 != voteInfo.mode7) return false; | ||
558 | - if (voteid != voteInfo.voteid) return false; | ||
559 | - if (file != voteInfo.file) return false; | ||
560 | - if (init != voteInfo.init) return false; | ||
561 | - if (less != voteInfo.less) return false; | ||
562 | - if (!resultInfo.equals(voteInfo.resultInfo)) return false; | ||
563 | - if (!electInfo.equals(voteInfo.electInfo)) return false; | ||
564 | - if (!singleEvalueInfo.equals(voteInfo.singleEvalueInfo)) return false; | ||
565 | - return batchEvalueInfo.equals(voteInfo.batchEvalueInfo); | ||
566 | - } | ||
567 | - | ||
568 | - @Override | ||
569 | - public int hashCode() { | ||
570 | - int result = baseId; | ||
571 | - result = 31 * result + nowT; | ||
572 | - result = 31 * result + dataPos; | ||
573 | - result = 31 * result + mode; | ||
574 | - result = 31 * result + mode1_msgType; | ||
575 | - result = 31 * result + mode2_modify; | ||
576 | - result = 31 * result + mode3_secret; | ||
577 | - result = 31 * result + mode4; | ||
578 | - result = 31 * result + mode5; | ||
579 | - result = 31 * result + mode6; | ||
580 | - result = 31 * result + mode7; | ||
581 | - result = 31 * result + voteid; | ||
582 | - result = 31 * result + file; | ||
583 | - result = 31 * result + init; | ||
584 | - result = 31 * result + less; | ||
585 | - result = 31 * result + resultInfo.hashCode(); | ||
586 | - result = 31 * result + electInfo.hashCode(); | ||
587 | - result = 31 * result + singleEvalueInfo.hashCode(); | ||
588 | - result = 31 * result + batchEvalueInfo.hashCode(); | ||
589 | - return result; | ||
590 | - } | ||
591 | 513 | ||
592 | //Deprecated blow | 514 | //Deprecated blow |
593 | // public int voteMode;// 表决模式 | 515 | // public int voteMode;// 表决模式 |
@@ -613,18 +535,35 @@ public interface XPadApiInterface { | @@ -613,18 +535,35 @@ public interface XPadApiInterface { | ||
613 | public int modify; //0 不允许修改 1 允许修改, | 535 | public int modify; //0 不允许修改 1 允许修改, |
614 | 536 | ||
615 | @Override | 537 | @Override |
616 | - public String toString() { | ||
617 | - return "BatchVoteInfo{" + | ||
618 | - "start=" + start + | ||
619 | - ", end=" + end + | ||
620 | - ", mode1=" + mode1 + | ||
621 | - ", less=" + less + | ||
622 | - ", secret=" + secret + | ||
623 | - ", fixballot=" + fixballot + | ||
624 | - ", limit=" + Arrays.toString(limit) + | ||
625 | - ", rule=" + rule + | ||
626 | - ", modify=" + modify + | ||
627 | - '}'; | 538 | + public boolean equals(Object o) { |
539 | + if (this == o) return true; | ||
540 | + if (o == null || getClass() != o.getClass()) return false; | ||
541 | + | ||
542 | + BatchVoteInfo that = (BatchVoteInfo) o; | ||
543 | + | ||
544 | + if (start != that.start) return false; | ||
545 | + if (end != that.end) return false; | ||
546 | + if (mode1 != that.mode1) return false; | ||
547 | + if (less != that.less) return false; | ||
548 | + if (secret != that.secret) return false; | ||
549 | + if (fixballot != that.fixballot) return false; | ||
550 | + if (rule != that.rule) return false; | ||
551 | + if (modify != that.modify) return false; | ||
552 | + return Arrays.equals(limit, that.limit); | ||
553 | + } | ||
554 | + | ||
555 | + @Override | ||
556 | + public int hashCode() { | ||
557 | + int result = start; | ||
558 | + result = 31 * result + end; | ||
559 | + result = 31 * result + mode1; | ||
560 | + result = 31 * result + less; | ||
561 | + result = 31 * result + secret; | ||
562 | + result = 31 * result + fixballot; | ||
563 | + result = 31 * result + Arrays.hashCode(limit); | ||
564 | + result = 31 * result + rule; | ||
565 | + result = 31 * result + modify; | ||
566 | + return result; | ||
628 | } | 567 | } |
629 | } | 568 | } |
630 | 569 | ||
@@ -644,7 +583,41 @@ public interface XPadApiInterface { | @@ -644,7 +583,41 @@ public interface XPadApiInterface { | ||
644 | public int equityMode; | 583 | public int equityMode; |
645 | public int minSelect; | 584 | public int minSelect; |
646 | 585 | ||
586 | + @Override | ||
587 | + public boolean equals(Object o) { | ||
588 | + if (this == o) return true; | ||
589 | + if (o == null || getClass() != o.getClass()) return false; | ||
590 | + | ||
591 | + BatchSelectInfo that = (BatchSelectInfo) o; | ||
592 | + | ||
593 | + if (type != that.type) return false; | ||
594 | + if (random != that.random) return false; | ||
595 | + if (select != that.select) return false; | ||
596 | + if (other != that.other) return false; | ||
597 | + if (less != that.less) return false; | ||
598 | + if (secrecy != that.secrecy) return false; | ||
599 | + if (modify != that.modify) return false; | ||
600 | + if (start != that.start) return false; | ||
601 | + if (end != that.end) return false; | ||
602 | + if (equityMode != that.equityMode) return false; | ||
603 | + return minSelect == that.minSelect; | ||
604 | + } | ||
647 | 605 | ||
606 | + @Override | ||
607 | + public int hashCode() { | ||
608 | + int result = type; | ||
609 | + result = 31 * result + random; | ||
610 | + result = 31 * result + select; | ||
611 | + result = 31 * result + other; | ||
612 | + result = 31 * result + less; | ||
613 | + result = 31 * result + secrecy; | ||
614 | + result = 31 * result + modify; | ||
615 | + result = 31 * result + start; | ||
616 | + result = 31 * result + end; | ||
617 | + result = 31 * result + equityMode; | ||
618 | + result = 31 * result + minSelect; | ||
619 | + return result; | ||
620 | + } | ||
648 | } | 621 | } |
649 | 622 | ||
650 | 623 |
C5/app/src/main/java/com/sunvote/xpadcomm/XPadSystem.java
@@ -4,7 +4,9 @@ package com.sunvote.xpadcomm; | @@ -4,7 +4,9 @@ package com.sunvote.xpadcomm; | ||
4 | import android.content.Context; | 4 | import android.content.Context; |
5 | import android.content.Intent; | 5 | import android.content.Intent; |
6 | 6 | ||
7 | +import com.sunvote.sdk.HuaWeiSDK; | ||
7 | import com.sunvote.util.LogUtil; | 8 | import com.sunvote.util.LogUtil; |
9 | +import com.sunvote.xpadapp.MainActivity; | ||
8 | import com.sunvote.xpadapp.R; | 10 | import com.sunvote.xpadapp.R; |
9 | 11 | ||
10 | public class XPadSystem { | 12 | public class XPadSystem { |
@@ -144,6 +146,7 @@ public class XPadSystem { | @@ -144,6 +146,7 @@ public class XPadSystem { | ||
144 | if (intent != null) { | 146 | if (intent != null) { |
145 | context.startActivity(intent); | 147 | context.startActivity(intent); |
146 | } | 148 | } |
149 | + HuaWeiSDK.getInstance((MainActivity)context).powerOffXPad(); | ||
147 | } | 150 | } |
148 | 151 | ||
149 | public static void rebootXPad(Context context) { | 152 | public static void rebootXPad(Context context) { |
@@ -152,7 +155,7 @@ public class XPadSystem { | @@ -152,7 +155,7 @@ public class XPadSystem { | ||
152 | if (intent != null) { | 155 | if (intent != null) { |
153 | context.startActivity(intent); | 156 | context.startActivity(intent); |
154 | } | 157 | } |
155 | - | 158 | + HuaWeiSDK.getInstance((MainActivity)context).rebootXPad(); |
156 | 159 | ||
157 | } | 160 | } |
158 | 161 | ||
@@ -161,6 +164,9 @@ public class XPadSystem { | @@ -161,6 +164,9 @@ public class XPadSystem { | ||
161 | Intent intent = new Intent(); | 164 | Intent intent = new Intent(); |
162 | intent.setAction("com.along.intent.Navigation_VISIBLE"); | 165 | intent.setAction("com.along.intent.Navigation_VISIBLE"); |
163 | context.sendBroadcast(intent); | 166 | context.sendBroadcast(intent); |
167 | + HuaWeiSDK.getInstance((MainActivity)context).setHomeButtonDisabled(false); | ||
168 | + HuaWeiSDK.getInstance((MainActivity)context).setStatusBarExpandPanelDisabled(false); | ||
169 | + HuaWeiSDK.getInstance((MainActivity)context).setTaskButtonDisabled(false); | ||
164 | } | 170 | } |
165 | 171 | ||
166 | public static void setNavgationGone(Context context){ | 172 | public static void setNavgationGone(Context context){ |
@@ -168,6 +174,9 @@ public class XPadSystem { | @@ -168,6 +174,9 @@ public class XPadSystem { | ||
168 | Intent intent = new Intent(); | 174 | Intent intent = new Intent(); |
169 | intent.setAction("com.along.intent.Navigation_GONE"); | 175 | intent.setAction("com.along.intent.Navigation_GONE"); |
170 | context.sendBroadcast(intent); | 176 | context.sendBroadcast(intent); |
177 | + HuaWeiSDK.getInstance((MainActivity)context).setHomeButtonDisabled(true); | ||
178 | + HuaWeiSDK.getInstance((MainActivity)context).setStatusBarExpandPanelDisabled(true); | ||
179 | + HuaWeiSDK.getInstance((MainActivity)context).setTaskButtonDisabled(true); | ||
171 | } | 180 | } |
172 | 181 | ||
173 | public static void goToSleep(Context context){ | 182 | public static void goToSleep(Context context){ |
C5/app/src/main/res/layout/fragment_admin.xml
@@ -13,6 +13,19 @@ | @@ -13,6 +13,19 @@ | ||
13 | android:orientation="horizontal"> | 13 | android:orientation="horizontal"> |
14 | 14 | ||
15 | <Button | 15 | <Button |
16 | + android:id="@+id/match" | ||
17 | + android:layout_width="0dp" | ||
18 | + android:layout_height="60dp" | ||
19 | + android:layout_marginRight="80dp" | ||
20 | + android:layout_weight="1" | ||
21 | + android:background="@color/blue" | ||
22 | + android:gravity="center" | ||
23 | + android:text="配对" | ||
24 | + android:textColor="@color/white" | ||
25 | + android:textSize="@dimen/big_text_p5" | ||
26 | + android:textStyle="bold" /> | ||
27 | + | ||
28 | + <Button | ||
16 | android:id="@+id/admin_config_mode" | 29 | android:id="@+id/admin_config_mode" |
17 | android:layout_width="0dp" | 30 | android:layout_width="0dp" |
18 | android:layout_height="60dp" | 31 | android:layout_height="60dp" |
@@ -25,6 +38,8 @@ | @@ -25,6 +38,8 @@ | ||
25 | android:textSize="@dimen/big_text_p5" | 38 | android:textSize="@dimen/big_text_p5" |
26 | android:textStyle="bold" /> | 39 | android:textStyle="bold" /> |
27 | 40 | ||
41 | + | ||
42 | + | ||
28 | <Button | 43 | <Button |
29 | android:id="@+id/admin_btnComTest" | 44 | android:id="@+id/admin_btnComTest" |
30 | android:layout_width="0dp" | 45 | android:layout_width="0dp" |
@@ -32,7 +47,7 @@ | @@ -32,7 +47,7 @@ | ||
32 | android:layout_weight="1" | 47 | android:layout_weight="1" |
33 | android:background="@color/blue" | 48 | android:background="@color/blue" |
34 | android:gravity="center" | 49 | android:gravity="center" |
35 | - android:text="重定向服务器" | 50 | + android:text="退出应用" |
36 | android:textColor="@color/white" | 51 | android:textColor="@color/white" |
37 | android:textSize="@dimen/big_text_p5" | 52 | android:textSize="@dimen/big_text_p5" |
38 | android:textStyle="bold" /> | 53 | android:textStyle="bold" /> |
@@ -71,7 +86,7 @@ | @@ -71,7 +86,7 @@ | ||
71 | android:layout_alignParentBottom="true" | 86 | android:layout_alignParentBottom="true" |
72 | android:layout_centerHorizontal="true" | 87 | android:layout_centerHorizontal="true" |
73 | android:layout_marginBottom="50dp" | 88 | android:layout_marginBottom="50dp" |
74 | - android:text="APP版本:1.1.2.6 基站IP:192.168.0.136" | 89 | + android:text="APP版本:1.1.2.6" |
75 | android:textColor="@color/white" | 90 | android:textColor="@color/white" |
76 | android:textSize="@dimen/big_text_p4" /> | 91 | android:textSize="@dimen/big_text_p4" /> |
77 | 92 |
C5/app/src/main/res/values/strings.xml
@@ -131,7 +131,7 @@ | @@ -131,7 +131,7 @@ | ||
131 | <string name="piao">票</string> | 131 | <string name="piao">票</string> |
132 | <string name="ren">人</string> | 132 | <string name="ren">人</string> |
133 | <string name="reboot">重启</string> | 133 | <string name="reboot">重启</string> |
134 | - <string name="shutdown">退出应用</string> | 134 | + <string name="shutdown">关机</string> |
135 | <string name="comtest">串口测试</string> | 135 | <string name="comtest">串口测试</string> |
136 | <string name="getDeviceInfo">读设备信息</string> | 136 | <string name="getDeviceInfo">读设备信息</string> |
137 | <string name="comtest_interval">串口测试间隔</string> | 137 | <string name="comtest_interval">串口测试间隔</string> |
C5/util/src/main/java/com/sunvote/util/ByteUtils.java
@@ -119,4 +119,35 @@ public class ByteUtils { | @@ -119,4 +119,35 @@ public class ByteUtils { | ||
119 | 119 | ||
120 | return true; | 120 | return true; |
121 | } | 121 | } |
122 | + | ||
123 | + public static int findBytes(byte[] source,byte[] find,int index){ | ||
124 | + int flag = -1; | ||
125 | + for (int j = index; j < source.length; j++) { | ||
126 | + if (source.length >= j + find.length) { | ||
127 | + if (compareByte(source, j, find)) { | ||
128 | + flag = j; | ||
129 | + break; | ||
130 | + } | ||
131 | + } | ||
132 | + } | ||
133 | + return flag; | ||
134 | + } | ||
135 | + | ||
136 | + private static boolean compareByte(byte[] source, int start, byte[] find) { | ||
137 | + if (source.length >= start + find.length) { | ||
138 | + for (int i = 0; i < find.length; i++) { | ||
139 | + if (source[start + i] != find[i]) { | ||
140 | + return false; | ||
141 | + } | ||
142 | + } | ||
143 | + return true; | ||
144 | + } | ||
145 | + return false; | ||
146 | + } | ||
147 | + | ||
148 | + public static int byte1ToInt(byte b) { | ||
149 | + int ret = 0; | ||
150 | + ret += (b & 0x000000FF); | ||
151 | + return ret; | ||
152 | + } | ||
122 | } | 153 | } |