Commit 18e76909 by patpat

删除旧机型sdk,完善新机型扫码

parent 9bc26031
...@@ -4,13 +4,12 @@ import android.app.ActivityManager ...@@ -4,13 +4,12 @@ import android.app.ActivityManager
import android.app.Application import android.app.Application
import android.content.Context import android.content.Context
import com.bgycc.smartcanteen.Storage.PayStorage import com.bgycc.smartcanteen.Storage.PayStorage
import com.bgycc.smartcanteen.helper.TimerHelper
import com.bgycc.smartcanteen.helper.WifiHelpler import com.bgycc.smartcanteen.helper.WifiHelpler
import com.bgycc.smartcanteen.util.LogUtil import com.bgycc.smartcanteen.util.LogUtil
import com.example.zhoukai.modemtooltest.ModemToolTest
import com.example.zhoukai.modemtooltest.NvConstants
import com.maxrocky.vmatrix.module.Device import com.maxrocky.vmatrix.module.Device
import com.szxb.jni.libszxb
import java.lang.Exception import java.lang.Exception
import kotlin.system.exitProcess
class App : Application() { class App : Application() {
...@@ -27,11 +26,7 @@ class App : Application() { ...@@ -27,11 +26,7 @@ class App : Application() {
return sInstances[processName] return sInstances[processName]
} }
fun getDeviceSN(): String { fun getDeviceSN(): String {
return if (libszxb.isSupport()) { return Device.getAndroidId()
ModemToolTest.getItem(NvConstants.REQUEST_GET_SN)
} else {
Device.getAndroidId()
}
} }
fun getVersionName(): String { fun getVersionName(): String {
return sVersionName return sVersionName
...@@ -39,6 +34,10 @@ class App : Application() { ...@@ -39,6 +34,10 @@ class App : Application() {
fun getVersionCode(): Int { fun getVersionCode(): Int {
return sVersionCode return sVersionCode
} }
fun exit() {
TimerHelper.shutdown()
exitProcess(0)
}
} }
override fun onCreate() { override fun onCreate() {
......
...@@ -7,7 +7,7 @@ public class AppConfig { ...@@ -7,7 +7,7 @@ public class AppConfig {
PROD PROD
} }
public static final Server SERVER = Server.DEV; public static final Server SERVER = Server.DEV;
public static final boolean DEBUG = true; public static final boolean DEBUG = false;
public static String getMainWebSocketServerUrl() { public static String getMainWebSocketServerUrl() {
switch (SERVER) { switch (SERVER) {
......
...@@ -46,13 +46,14 @@ class MainActivity : BaseActivity() { ...@@ -46,13 +46,14 @@ class MainActivity : BaseActivity() {
private var mPayFailSoundId = 0 private var mPayFailSoundId = 0
private var mAudioManager: AudioManager? = null private var mAudioManager: AudioManager? = null
private val mHandler = Handler() private val mHandler = Handler()
private var mTimerId = -1L
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
hideActionBar() hideActionBar()
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
hideStatusBar() hideStatusBar()
hideNavigation() keepScreenOn(true)
initView() initView()
EventBus.getDefault().register(this) EventBus.getDefault().register(this)
...@@ -60,10 +61,16 @@ class MainActivity : BaseActivity() { ...@@ -60,10 +61,16 @@ class MainActivity : BaseActivity() {
initTimer() initTimer()
} }
override fun onResume() {
super.onResume()
hideNavigation()
}
override fun onDestroy() { override fun onDestroy() {
uninitTimer() uninitTimer()
EventBus.getDefault().unregister(this) EventBus.getDefault().unregister(this)
super.onDestroy() super.onDestroy()
App.exit()
} }
private fun init() { private fun init() {
...@@ -96,7 +103,7 @@ class MainActivity : BaseActivity() { ...@@ -96,7 +103,7 @@ class MainActivity : BaseActivity() {
} }
private fun initTimer() { private fun initTimer() {
TimerHelper.loop({ _, _ -> mTimerId = TimerHelper.loop({ _, _ ->
mHandler.post { mHandler.post {
_wifi.text = "Wifi Mac: ${WifiHelpler.getMacAddress()} SSID: ${WifiHelpler.getSSID()} IP: ${WifiHelpler.getIpString()}" _wifi.text = "Wifi Mac: ${WifiHelpler.getMacAddress()} SSID: ${WifiHelpler.getSSID()} IP: ${WifiHelpler.getIpString()}"
_time.text = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).format(Date()) _time.text = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).format(Date())
...@@ -105,7 +112,7 @@ class MainActivity : BaseActivity() { ...@@ -105,7 +112,7 @@ class MainActivity : BaseActivity() {
} }
private fun uninitTimer() { private fun uninitTimer() {
TimerHelper.shutdown() TimerHelper.cancel(mTimerId)
} }
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean { override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
......
...@@ -2,10 +2,8 @@ package com.bgycc.smartcanteen.task ...@@ -2,10 +2,8 @@ package com.bgycc.smartcanteen.task
import android.content.Context import android.content.Context
import android.media.AudioManager import android.media.AudioManager
import android.util.Log
import com.bgycc.smartcanteen.App import com.bgycc.smartcanteen.App
import com.bgycc.smartcanteen.helper.TimerHelper import com.bgycc.smartcanteen.helper.TimerHelper
import com.szxb.jni.libszxb
object ButtonTask { object ButtonTask {
...@@ -19,7 +17,7 @@ object ButtonTask { ...@@ -19,7 +17,7 @@ object ButtonTask {
mAudioManager = App.getDefault().getSystemService(Context.AUDIO_SERVICE) as AudioManager mAudioManager = App.getDefault().getSystemService(Context.AUDIO_SERVICE) as AudioManager
mTimerId = TimerHelper.loop({ _, _ -> mTimerId = TimerHelper.loop({ _, _ ->
val buf = ByteArray(5) val buf = ByteArray(5)
libszxb.devicekey(buf) // libszxb.devicekey(buf)
// Log.i(TAG, String.format("%02x %02x %02x %02x", buf[0], buf[1], buf[2], buf[3])); // Log.i(TAG, String.format("%02x %02x %02x %02x", buf[0], buf[1], buf[2], buf[3]));
if (buf[1].toInt() == 1) { if (buf[1].toInt() == 1) {
mAudioManager!!.adjustStreamVolume( mAudioManager!!.adjustStreamVolume(
......
...@@ -7,14 +7,11 @@ import com.bgycc.smartcanteen.event.LogEvent; ...@@ -7,14 +7,11 @@ import com.bgycc.smartcanteen.event.LogEvent;
import com.bgycc.smartcanteen.helper.TimerHelper; import com.bgycc.smartcanteen.helper.TimerHelper;
import com.bgycc.smartcanteen.server.websocket.MainWebSocket; import com.bgycc.smartcanteen.server.websocket.MainWebSocket;
import com.bgycc.smartcanteen.util.ByteUtil; import com.bgycc.smartcanteen.util.ByteUtil;
import com.common.api.serial.Serial; import com.bgycc.smartcanteen.util.LogUtil;
import com.szxb.jni.libszxb;
import kotlin.jvm.functions.Function2;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.File; import java.io.File;
import java.io.InputStream;
import java.util.Arrays; import java.util.Arrays;
import java.util.regex.Pattern; import java.util.regex.Pattern;
...@@ -36,6 +33,7 @@ public class QRCodeTask { ...@@ -36,6 +33,7 @@ public class QRCodeTask {
} }
private ScanAsyncTask mScanAsyncTask; private ScanAsyncTask mScanAsyncTask;
private QRCodeThread mQRCodeThread;
private QRCodeTask() {} private QRCodeTask() {}
...@@ -47,6 +45,8 @@ public class QRCodeTask { ...@@ -47,6 +45,8 @@ public class QRCodeTask {
if (!support()) return; if (!support()) return;
if (mScanAsyncTask == null) { if (mScanAsyncTask == null) {
mQRCodeThread = new QRCodeThread();
mQRCodeThread.start();
mScanAsyncTask = new ScanAsyncTask(); mScanAsyncTask = new ScanAsyncTask();
TimerHelper.INSTANCE.loop(new TimerHelper.LoopTask() { TimerHelper.INSTANCE.loop(new TimerHelper.LoopTask() {
@Override @Override
...@@ -61,28 +61,65 @@ public class QRCodeTask { ...@@ -61,28 +61,65 @@ public class QRCodeTask {
public void stop() { public void stop() {
mScanAsyncTask = null; mScanAsyncTask = null;
mQRCodeThread.interrupt();
} }
private class ScanAsyncTask extends AsyncTask { private class QRCodeThread extends Thread {
long lastReadTime = 0;
byte[] buf = null;
int len = 0;
int lastLen = -1; private synchronized void pushBuf(byte[] b, int l) {
byte[] lastBuf; if (b == null || b.length == 0 || l <= 0) return;
Serial tb580cSerial = null;
SerialPort p60sSerial = null; b = Arrays.copyOfRange(b, 0, l);
InputStream tb580cSerialIS = null; buf = ByteUtil.merge(buf, b);
byte[] tb580cSerialBuf = null; len += l;
lastReadTime = System.currentTimeMillis();
ScanAsyncTask() { }
p60sSerial = SerialPort.build(new File("/dev/ttyS6"), 9600, 0);
if (Serial.isSupport()) { public synchronized String getResult() {
if (len == 0) return null;
if ((System.currentTimeMillis() - lastReadTime) < 190) return null;
String result = new String(buf, 0, len);
buf = null;
len = 0;
return result;
}
@Override
public void run() {
SerialPort serial = SerialPort.build(new File("/dev/ttyS6"), 115200, 0);
if (serial == null) return;
while (true) {
try { try {
tb580cSerial = new Serial("/dev/ttyS0", 115200, 0); byte[] b = new byte[64];
tb580cSerialIS = tb580cSerial.getInputStream(); int l = serial.getInputStream().read(b);
pushBuf(b, l);
} catch (Exception e) { } catch (Exception e) {
} }
try {
Thread.sleep(0);
} catch (InterruptedException e) {
break;
}
} }
try {
serial.getInputStream().close();
serial.getOutputStream().close();
} catch (Exception e) {}
serial.close();
} }
}
private class ScanAsyncTask extends AsyncTask {
int lastLen = -1;
byte[] lastBuf;
@Override @Override
protected void run(int step, int progress) { protected void run(int step, int progress) {
...@@ -91,53 +128,7 @@ public class QRCodeTask { ...@@ -91,53 +128,7 @@ public class QRCodeTask {
case 0: case 0:
if (progress != 0) break; if (progress != 0) break;
String str = null; String str = mQRCodeThread.getResult();
try {
if (libszxb.isSupport()) { // 深圳小兵Q6
byte[] buf = new byte[1024];
int len = libszxb.getBarcode(buf);
boolean changed = checkBarCodeChanged(buf, len);
if (!changed || len <= 0) break;
delay(1000);
str = new String(buf, 0, len);
} else if (p60sSerial != null) {
byte[] buf = null;
int len = 0;
try {
while (true) {
byte[] b = new byte[64];
int l = p60sSerial.getInputStream().read(b);
if (l == 0) break;
buf = ByteUtil.merge(buf, b);
len += l;
}
delay(1000);
str = new String(buf, 0, len);
} catch (Exception e) {
e.printStackTrace();
}
} else if (tb580cSerial != null && tb580cSerialIS != null) { // 天波580C
byte[] buffer = new byte[64];
int size = tb580cSerialIS.read(buffer);
buffer = Arrays.copyOfRange(buffer, 0, size);
tb580cSerialBuf = ByteUtil.merge(tb580cSerialBuf, buffer);
if (tb580cSerialBuf != null && tb580cSerialBuf.length > 1 &&
tb580cSerialBuf[tb580cSerialBuf.length - 2] == (byte) 0x0D &&
tb580cSerialBuf[tb580cSerialBuf.length - 1] == (byte) 0x0A)
{
str = new String(tb580cSerialBuf, 0, tb580cSerialBuf.length - 2);
tb580cSerialBuf = null;
} else {
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
if (str == null) break; if (str == null) break;
QRCodeEvent event = new QRCodeEvent(str.getBytes(), str, checkPayCodeType(str)); QRCodeEvent event = new QRCodeEvent(str.getBytes(), str, checkPayCodeType(str));
......
...@@ -2,6 +2,8 @@ package com.bgycc.smartcanteen.util; ...@@ -2,6 +2,8 @@ package com.bgycc.smartcanteen.util;
import android.util.Log; import android.util.Log;
import java.util.Locale;
public class LogUtil { public class LogUtil {
private static boolean sEnable = false; private static boolean sEnable = false;
...@@ -29,4 +31,14 @@ public class LogUtil { ...@@ -29,4 +31,14 @@ public class LogUtil {
if (!sEnable) return; if (!sEnable) return;
Log.e(tag, log); Log.e(tag, log);
} }
public static void print(String tag, byte[] data) {
if (!sEnable) return;
String text = String.format(Locale.getDefault(), "byte[%d]", data == null ? 0 : data.length);
for (byte i : data) {
text += String.format(" %02X", i);
}
Log.i(tag, text);
}
} }
package com.common.api.serial;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class Serial {
private static boolean mSupport = false;
public static boolean isSupport() {
return mSupport;
}
public static final int MODE_PRINTER = 0;
public static final int MODE_ICC = 1;
public static final int MODE_PINPAD = 2;
private native static FileDescriptor open(String path, int baudrate, int flags);
public native void close();
private native static int switch_mode(int mode);
/*
* Do not remove or rename the field mFd: it is used by native method
* close();
*/
private FileDescriptor mFd;
private FileInputStream mFileInputStream;
private FileOutputStream mFileOutputStream;
public Serial(String path, int baud, int flags) throws FileNotFoundException, SecurityException, IOException {
// String cmd;
File device = new File(path);
if (!device.exists()) {
throw new FileNotFoundException();
}
mFd = open(path, baud, flags);
if (mFd == null) {
throw new IOException();
}
mFileInputStream = new FileInputStream(mFd);
mFileOutputStream = new FileOutputStream(mFd);
}
public InputStream getInputStream() {
return mFileInputStream;
}
public OutputStream getOutputStream() {
return mFileOutputStream;
}
public int switchMode(int mode) {
return switch_mode(mode);
}
static {
try {
System.loadLibrary("common_serial");
mSupport = true;
} catch (Exception e) {
}
}
}
package com.example.zhoukai.modemtooltest;
public class ModemToolTest {
// Used to load the 'native-lib' library on application startup.
static {
System.loadLibrary("native-lib");
}
/**
* A native method that is implemented by the 'native-lib' native library,
* which is packaged with this application.
*/
public static native String stringFromJNI();
/**
* A native method that is implemented by the 'native-lib' native library,
* which is used to get the value of nv items listed in {@link NvConstants}.
*/
public static native String getItem(int nvid);
/**
* A native method that is implemented by the 'native-lib' native library,
* which is used to set the value of nv items listed in {@link NvConstants}.
*/
public static native int setItem(int nvid, String value);
}
\ No newline at end of file
package com.example.zhoukai.modemtooltest;
/**
* Created by zhoukai on 17-1-3.
* request id of nv items
* support the access of following nv items
*/
public class NvConstants {
//the request id of reading imei
public static final int REQUEST_GET_IMEI = 1;
//the request id of writing imei
public static final int REQUEST_SET_IMEI = 2;
//the request id of reading wifi mac address
public static final int REQUEST_GET_MAC_ADDRESS = 3;
//the request id of writing wifi mac address
public static final int REQUEST_SET_MAC_ADDRESS = 4;
//the request id of reading QSN , customers can use it to customize their own sn
public static final int REQUEST_GET_QSN = 5;
//the request id of writing QSN
public static final int REQUEST_SET_QSN = 6;
//the request id of reading SN , the value is corresponding with sn presented on SC20 module
public static final int REQUEST_GET_SN = 7;
//the request id of writing SN
public static final int REQUEST_SET_SN = 8;
//the request id of reading MEID
public static final int REQUEST_GET_MEID = 9;
//the request id of writing MEID
public static final int REQUEST_SET_MEID = 10;
}
/**
* Project Name:Q6
* File Name:libtest.java
* Package Name:com.szxb.jni
* Date:Apr 13, 20177:37:45 PM
* Copyright (c) 2017, chenzhou1025@126.com All Rights Reserved.
*
*/
package com.szxb.jni;
import java.io.IOException;
import java.util.Calendar;
import java.util.GregorianCalendar;
//import com.szxb.q6lib.MainActivity;
import android.content.res.AssetManager;
import android.os.SystemClock;
import android.util.Log;
/**
* ClassName:libtest <br/>
* Function: TODO ADD FUNCTION. <br/>
* Reason: TODO ADD REASON. <br/>
* Date: Apr 13, 2017 7:37:45 PM <br/>
*
* @author lilei
* @version
* @since JDK 1.6
* @see
*/
public class libszxb {
private static boolean mSupportSZXB = false;
private static boolean mSupportYMODEM = false;
public static boolean isSupport() {
return mSupportSZXB && mSupportYMODEM;
}
static {
try {
System.loadLibrary("szxb");
String version = getVersion();
if (version != null && !version.isEmpty()) {
mSupportSZXB = true;
}
} catch (Throwable e) {
Log.e("jni", "i can't find business so!");
e.printStackTrace();
}
}
static {
try {
System.loadLibrary("ymodem");
mSupportYMODEM = true;
} catch (Throwable e) {
Log.e("jni", "i can't find ymodem so!");
e.printStackTrace();
}
}
static {
try {
System.loadLibrary("halcrypto");
} catch (Throwable e) {
Log.e("jni", "i can't find halcrypto so!");
e.printStackTrace();
}
}
//公交车接口
public native static void deviceReset();
public static native int deviceTime(byte[] buf, boolean flag);
public static native int devicekey(byte[] recv);
public static native int getEnvironment(byte[] recv);
public static native int getBarcode(byte[] recv);
public static native int setNixietube(byte[] nos);
public static native int setLed(byte[] leds);
public static native String getVersion();
public static native String getCarInfo();
public static native int doTrans(byte[] buf,int len);
//485
public static native int deviceSerialSetBaudrate(int devNo,int Baudrate);
public static native int deviceSerialSend(int devNo,byte[] sendBuf,int sendLen);
public static native int deviceSerialRecv(int devNo,byte[] recvBuf,int timeOut);
//串口0
public static native int serialSetBaudrate(int Baudrate);
public static native int serialSend(byte[]sendBuf, int sendLen);
public static native int serialRecv(byte[]recvBuf, int timeOut);
public static native int serialOpen();
public static native int serialClose();
public static int deviceSettime(int year, int month, int date, int hour,
int min, int sec) {
byte[] settime = new byte[8];
settime[0] = (byte) ((year>>8)&0xff);
settime[1] = (byte) (year&0xff);
settime[2] = (byte) (month&0xff);
settime[3] = (byte) (date&0xff);
settime[4] = (byte) (hour&0xff);
settime[5] = (byte) (min&0xff);
settime[6] = (byte) (sec&0xff);
return libszxb.deviceTime(settime, true);
}
public static Calendar deviceGettime() {
int ret;
byte[] gettime = new byte[8];
ret = libszxb.deviceTime(gettime, false);
if (0 == ret) {
int year = ((gettime[0]<<8) & 0xff00) | (gettime[1] & 0xff);
return new GregorianCalendar(year, gettime[2]-1, gettime[3],gettime[4],gettime[5],gettime[6]);
}
return null;
}
//更新固件
public static native int ymodemUpdate(AssetManager ass, String filename);
public static native int ymodemUpdate_ftp(String filename);
public static native int ymodemUpdate_stm(AssetManager ass, String filename);
//加密
public static native String RSA_public_decrypt(String strN,String sInput,int e);
public static native String Hash1(String inputStr);
public static native String Hash224(String inputStr);
public static native byte TripleDES(byte[] pszData, byte[] pszResult,byte[] pszKey, byte nFlag);
public static native byte SingleDES(byte[] pszSrc, byte[]pszDst,byte[] pszDesKey, byte nFlag);
//非接接口
public native static int RFIDModuleOpen();
public native static int RFIDMoudleClose();
public native static int RFID_setAnt(int value);
public native static String MifareGetSNR(byte[] cardType);
public native static String TypeA_RATS();
public native static String[] RFID_APDU(String sendApdu);
public native static int RFIDAuthenCard(byte nBlock, byte keyType,byte[] key);
public static native int RFIDReadCard(byte nBlock, byte[] buf);
public static native int RFIDWriteCard(byte nBlock, byte[] buf);
public static native int RFIDInitValue(byte nBlock, int nMoney);
public static native int RFIDInctValue(byte nBlock, int nMoney);
public static native int RFIDDectValue(byte nBlock, int nMoney);
public static native int RFIDReadValue(byte nBlock, int nMoney);
public static native int RFIDRestor(byte nSrcBlock, byte nDesBlock);
//psam卡接口
public static native int OpenPsamMoudle();
public static native int ClosePsamModule();
public static native String psamCardReset(int baud,int slot);
public static native String[] psamCardSendAPDUT0(int slot ,String sendApdu);
//接触卡接口
// public static native int ICcardOpen();
// public static native int ICcardClose();
// public static native String CpuCardPowerOn(byte slot);
// public static native int CpuCardPowerOff(byte slot);
// public static native String[] CpuCardSendAPDU(byte slot,String sendData);
//磁条接口
// public native static int msr_open();
//
// public native static int msr_close();
//
// public native static int msr_poll(int nTimeout_MS);
//
// public native static int msr_get_track_error(int nTrackIndex);
//
// public native static int msr_get_track_data_length(int nTrackIndex);
//
// public native static int msr_get_track_data(int nTrackIndex, byte byteArry[], int nLength);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment