Commit 6fe0f7d4 by patpat

支持天波580C设备

parent 4e45eb68
...@@ -8,6 +8,8 @@ import com.bgycc.smartcanteen.helper.WifiHelpler ...@@ -8,6 +8,8 @@ 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.ModemToolTest
import com.example.zhoukai.modemtooltest.NvConstants import com.example.zhoukai.modemtooltest.NvConstants
import com.maxrocky.vmatrix.module.Device
import com.szxb.jni.libszxb
import java.lang.Exception import java.lang.Exception
class App : Application() { class App : Application() {
...@@ -25,7 +27,11 @@ class App : Application() { ...@@ -25,7 +27,11 @@ class App : Application() {
return sInstances[processName] return sInstances[processName]
} }
fun getDeviceSN(): String { fun getDeviceSN(): String {
return ModemToolTest.getItem(NvConstants.REQUEST_GET_SN) return if (libszxb.isSupport()) {
ModemToolTest.getItem(NvConstants.REQUEST_GET_SN)
} else {
Device.getAndroidId()
}
} }
fun getVersionName(): String { fun getVersionName(): String {
return sVersionName return sVersionName
...@@ -45,6 +51,7 @@ class App : Application() { ...@@ -45,6 +51,7 @@ class App : Application() {
LogUtil.setEnable(AppConfig.DEBUG) LogUtil.setEnable(AppConfig.DEBUG)
WifiHelpler.initialize(this) WifiHelpler.initialize(this)
PayStorage.initialize(this) PayStorage.initialize(this)
Device.initialize(this)
} }
fun isMainProcess(): Boolean { fun isMainProcess(): Boolean {
......
package com.bgycc.smartcanteen.activity package com.bgycc.smartcanteen.activity
import android.content.Context
import android.media.AudioManager import android.media.AudioManager
import android.media.SoundPool import android.media.SoundPool
import android.os.Bundle import android.os.Bundle
import android.os.Handler import android.os.Handler
import android.util.Log import android.util.Log
import android.view.KeyEvent
import android.view.View import android.view.View
import android.view.animation.Animation import android.view.animation.Animation
import android.view.animation.RotateAnimation import android.view.animation.RotateAnimation
...@@ -15,6 +17,7 @@ import com.bgycc.smartcanteen.R ...@@ -15,6 +17,7 @@ import com.bgycc.smartcanteen.R
import com.bgycc.smartcanteen.event.LogEvent import com.bgycc.smartcanteen.event.LogEvent
import com.bgycc.smartcanteen.event.PayStateEvent import com.bgycc.smartcanteen.event.PayStateEvent
import com.bgycc.smartcanteen.event.WifiStateEvent import com.bgycc.smartcanteen.event.WifiStateEvent
import com.bgycc.smartcanteen.helper.EthernetHelper
import com.bgycc.smartcanteen.helper.TimerHelper import com.bgycc.smartcanteen.helper.TimerHelper
import com.bgycc.smartcanteen.helper.WifiHelpler import com.bgycc.smartcanteen.helper.WifiHelpler
import com.bgycc.smartcanteen.server.websocket.event.ConnectStateEvent import com.bgycc.smartcanteen.server.websocket.event.ConnectStateEvent
...@@ -30,10 +33,6 @@ import org.greenrobot.eventbus.ThreadMode ...@@ -30,10 +33,6 @@ import org.greenrobot.eventbus.ThreadMode
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.* import java.util.*
import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.activity_main.*
import java.lang.Exception
import java.util.concurrent.Executors
import java.util.concurrent.ScheduledExecutorService
import java.util.concurrent.TimeUnit
class MainActivity : BaseActivity() { class MainActivity : BaseActivity() {
...@@ -45,6 +44,7 @@ class MainActivity : BaseActivity() { ...@@ -45,6 +44,7 @@ class MainActivity : BaseActivity() {
private var mBeepSoundId = 0 private var mBeepSoundId = 0
private var mPaySuccessSoundId = 0 private var mPaySuccessSoundId = 0
private var mPayFailSoundId = 0 private var mPayFailSoundId = 0
private var mAudioManager: AudioManager? = null
private val mHandler = Handler() private val mHandler = Handler()
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
...@@ -52,6 +52,7 @@ class MainActivity : BaseActivity() { ...@@ -52,6 +52,7 @@ class MainActivity : BaseActivity() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
hideStatusBar() hideStatusBar()
hideNavigation()
initView() initView()
EventBus.getDefault().register(this) EventBus.getDefault().register(this)
...@@ -66,6 +67,7 @@ class MainActivity : BaseActivity() { ...@@ -66,6 +67,7 @@ class MainActivity : BaseActivity() {
} }
private fun init() { private fun init() {
mAudioManager = getSystemService(Context.AUDIO_SERVICE) as AudioManager
mBeepSoundId = mSoundPool.load(assets.openFd("beep.mp3"), 1) mBeepSoundId = mSoundPool.load(assets.openFd("beep.mp3"), 1)
mPaySuccessSoundId = mSoundPool.load(assets.openFd("pay-success.mp3"), 1) mPaySuccessSoundId = mSoundPool.load(assets.openFd("pay-success.mp3"), 1)
mPayFailSoundId = mSoundPool.load(assets.openFd("pay-fail.mp3"), 1) mPayFailSoundId = mSoundPool.load(assets.openFd("pay-fail.mp3"), 1)
...@@ -87,6 +89,7 @@ class MainActivity : BaseActivity() { ...@@ -87,6 +89,7 @@ class MainActivity : BaseActivity() {
_setting_img.startAnimation(anim) _setting_img.startAnimation(anim)
} }
_version.text = "Version: v${App.getVersionName()}(${App.getVersionCode()})" _version.text = "Version: v${App.getVersionName()}(${App.getVersionCode()})"
_eth.text = "Ethernet Mac: ${EthernetHelper.getMacAddress()}"
} }
private fun initTimer() { private fun initTimer() {
...@@ -102,6 +105,27 @@ class MainActivity : BaseActivity() { ...@@ -102,6 +105,27 @@ class MainActivity : BaseActivity() {
TimerHelper.shutdown() TimerHelper.shutdown()
} }
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
Log.i(TAG, "keyCode: $keyCode")
when(keyCode) {
KeyEvent.KEYCODE_NUMPAD_ADD -> {
mAudioManager!!.adjustStreamVolume(
AudioManager.STREAM_SYSTEM,
AudioManager.ADJUST_RAISE,
AudioManager.FLAG_SHOW_UI
)
}
KeyEvent.KEYCODE_NUMPAD_SUBTRACT -> {
mAudioManager!!.adjustStreamVolume(
AudioManager.STREAM_SYSTEM,
AudioManager.ADJUST_LOWER,
AudioManager.FLAG_SHOW_UI
)
}
}
return super.onKeyDown(keyCode, event)
}
fun printQRCode(event: QRCodeEvent) { fun printQRCode(event: QRCodeEvent) {
var msg = "QRCode: " + event.string var msg = "QRCode: " + event.string
if (event.payCodeType != null) { if (event.payCodeType != null) {
......
package com.bgycc.smartcanteen.helper;
import java.net.NetworkInterface;
public class EthernetHelper {
public static String getMacAddress() {
try {
NetworkInterface networkInterface = NetworkInterface.getByName("eth0");
byte[] data = networkInterface.getHardwareAddress();
return String.format("%02x:%02x:%02x:%02x:%02x:%02x", data[0], data[1], data[2], data[3], data[4], data[5]);
} catch (Exception e) {
}
return "02:00:00:00:00:00";
}
}
package com.maxrocky.vmatrix.module
import android.content.Context
import android.provider.Settings
import java.io.BufferedInputStream
import java.lang.Exception
object Device {
private var mAndroidId = ""
private var mSerialNumber = ""
fun initialize(context: Context) {
readAndroidId(context)
readSerialNumber()
}
fun getId(): String {
if (mSerialNumber.isNotEmpty()) return mSerialNumber
return mAndroidId
}
fun getAndroidId(): String {
return mAndroidId
}
fun getSerialNumber(): String {
return mSerialNumber
}
private fun readAndroidId(context: Context) {
mAndroidId = Settings.System.getString(context.contentResolver, Settings.System.ANDROID_ID)
}
private fun readSerialNumber() {
mSerialNumber = ""
val process = Runtime.getRuntime().exec("cat /proc/cpuinfo")
val bis = BufferedInputStream(process.inputStream)
process.waitFor()
val buf = ByteArray(10 * 1024)
val len = bis.read(buf)
val info = String(buf, 0, len)
try {
var result = Regex("^\\s*serial\\s*\\:\\s*(\\S+)\\s*\$", setOf(RegexOption.MULTILINE, RegexOption.IGNORE_CASE)).find(
"$info\n Serial : pp0123456789 "
// info
)
if (result != null && result.groups.size == 2) {
mSerialNumber = result.groups[1]?.value?.toLowerCase() ?: ""
}
} catch (e: Exception) {
mSerialNumber = ""
}
}
}
\ No newline at end of file
...@@ -2,6 +2,7 @@ package com.bgycc.smartcanteen.server.websocket; ...@@ -2,6 +2,7 @@ package com.bgycc.smartcanteen.server.websocket;
import android.util.Log; import android.util.Log;
import android.util.SparseArray; import android.util.SparseArray;
import com.bgycc.smartcanteen.App;
import com.bgycc.smartcanteen.AppConfig; import com.bgycc.smartcanteen.AppConfig;
import com.bgycc.smartcanteen.action.ActionEnum; import com.bgycc.smartcanteen.action.ActionEnum;
import com.bgycc.smartcanteen.action.PayOfflineAction; import com.bgycc.smartcanteen.action.PayOfflineAction;
...@@ -11,6 +12,8 @@ import com.bgycc.smartcanteen.server.websocket.event.RecvMessageEvent; ...@@ -11,6 +12,8 @@ import com.bgycc.smartcanteen.server.websocket.event.RecvMessageEvent;
import com.bgycc.smartcanteen.server.websocket.event.SendMessageEvent; import com.bgycc.smartcanteen.server.websocket.event.SendMessageEvent;
import com.example.zhoukai.modemtooltest.ModemToolTest; import com.example.zhoukai.modemtooltest.ModemToolTest;
import com.example.zhoukai.modemtooltest.NvConstants; import com.example.zhoukai.modemtooltest.NvConstants;
import com.maxrocky.vmatrix.module.Device;
import com.szxb.jni.libszxb;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
import org.java_websocket.client.WebSocketClient; import org.java_websocket.client.WebSocketClient;
import org.java_websocket.drafts.Draft_6455; import org.java_websocket.drafts.Draft_6455;
...@@ -50,8 +53,8 @@ public class MainWebSocket extends WebSocketClient { ...@@ -50,8 +53,8 @@ public class MainWebSocket extends WebSocketClient {
public static void initialize() { public static void initialize() {
if (sInstance == null) { if (sInstance == null) {
try { try {
sDeviceSN = ModemToolTest.getItem(NvConstants.REQUEST_GET_SN); sDeviceSN = App.Companion.getDeviceSN();
if (sDeviceSN == null || sDeviceSN.isEmpty()) return; if (sDeviceSN.isEmpty()) return;
EventBus.getDefault().post(new ConnectStateEvent(ConnectStateEvent.CONNECTING)); EventBus.getDefault().post(new ConnectStateEvent(ConnectStateEvent.CONNECTING));
sInstance = new MainWebSocket(new URI(String.format(AppConfig.getMainWebSocketServerUrl(), sDeviceSN))); sInstance = new MainWebSocket(new URI(String.format(AppConfig.getMainWebSocketServerUrl(), sDeviceSN)));
......
...@@ -5,11 +5,15 @@ import com.bgycc.smartcanteen.action.*; ...@@ -5,11 +5,15 @@ import com.bgycc.smartcanteen.action.*;
import com.bgycc.smartcanteen.event.LogEvent; 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.common.api.serial.Serial;
import com.szxb.jni.libszxb; import com.szxb.jni.libszxb;
import kotlin.jvm.functions.Function2; 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.InputStream;
import java.util.Arrays;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class QRCodeTask { public class QRCodeTask {
...@@ -62,6 +66,20 @@ public class QRCodeTask { ...@@ -62,6 +66,20 @@ public class QRCodeTask {
int lastLen = -1; int lastLen = -1;
byte[] lastBuf; byte[] lastBuf;
Serial tb580cSerial = null;
InputStream tb580cSerialIS = null;
byte[] tb580cSerialBuf = null;
ScanAsyncTask() {
if (Serial.isSupport()) {
try {
tb580cSerial = new Serial("/dev/ttyS0", 115200, 0);
tb580cSerialIS = tb580cSerial.getInputStream();
} catch (Exception e) {
}
}
}
@Override @Override
protected void run(int step, int progress) { protected void run(int step, int progress) {
...@@ -70,14 +88,38 @@ public class QRCodeTask { ...@@ -70,14 +88,38 @@ public class QRCodeTask {
case 0: case 0:
if (progress != 0) break; if (progress != 0) break;
byte[] buf = new byte[1024]; String str = null;
int len = libszxb.getBarcode(buf);
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 (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();
}
boolean changed = checkBarCodeChanged(buf, len); if (str == null) break;
if (!changed || len <= 0) break;
delay(1000);
String str = new String(buf, 0, len);
QRCodeEvent event = new QRCodeEvent(str.getBytes(), str, checkPayCodeType(str)); QRCodeEvent event = new QRCodeEvent(str.getBytes(), str, checkPayCodeType(str));
EventBus.getDefault().post(event); EventBus.getDefault().post(event);
......
package com.bgycc.smartcanteen.util;
public class ByteUtil {
public static byte[] merge(byte[] hand, byte[] tail) {
if (hand == null) {
return tail;
}
byte[] data = new byte[hand.length + tail.length];
System.arraycopy(hand, 0, data, 0, hand.length);
System.arraycopy(tail, 0, data, hand.length, tail.length);
return data;
}
}
...@@ -32,9 +32,19 @@ import android.util.Log; ...@@ -32,9 +32,19 @@ import android.util.Log;
*/ */
public class libszxb { public class libszxb {
private static boolean mSupportSZXB = false;
private static boolean mSupportYMODEM = false;
public static boolean isSupport() {
return mSupportSZXB && mSupportYMODEM;
}
static { static {
try { try {
System.loadLibrary("szxb"); System.loadLibrary("szxb");
String version = getVersion();
if (version != null && !version.isEmpty()) {
mSupportSZXB = true;
}
} catch (Throwable e) { } catch (Throwable e) {
Log.e("jni", "i can't find business so!"); Log.e("jni", "i can't find business so!");
e.printStackTrace(); e.printStackTrace();
...@@ -44,6 +54,7 @@ public class libszxb { ...@@ -44,6 +54,7 @@ public class libszxb {
static { static {
try { try {
System.loadLibrary("ymodem"); System.loadLibrary("ymodem");
mSupportYMODEM = true;
} catch (Throwable e) { } catch (Throwable e) {
Log.e("jni", "i can't find ymodem so!"); Log.e("jni", "i can't find ymodem so!");
e.printStackTrace(); e.printStackTrace();
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
<LinearLayout android:id="@+id/_debug" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="5dp"> <LinearLayout android:id="@+id/_debug" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="5dp">
<TextView android:id="@+id/_version" android:text="Version: v0.0.0" android:textSize="18sp" android:textColor="#888" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/_version" android:text="Version: v0.0.0" android:textSize="18sp" android:textColor="#888" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:id="@+id/_wifi" android:text="Wifi SSID: unknown" android:textSize="18sp" android:textColor="#888" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/_wifi" android:text="Wifi SSID: unknown" android:textSize="18sp" android:textColor="#888" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:id="@+id/_eth" android:text="Ethernet address: unknown" android:textSize="18sp" android:textColor="#888" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:id="@+id/_qrcode" android:text="QRCode: 扫描中..." android:textSize="18sp" android:textColor="#888" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/_qrcode" android:text="QRCode: 扫描中..." android:textSize="18sp" android:textColor="#888" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:id="@+id/_server" android:text="Server: 未连接" android:textSize="18sp" android:textColor="#888" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/_server" android:text="Server: 未连接" android:textSize="18sp" android:textColor="#888" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:id="@+id/_send_msg" android:text="Send: null" android:textSize="18sp" android:textColor="#488" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/_send_msg" android:text="Send: null" android:textSize="18sp" android:textColor="#488" android:layout_width="wrap_content" android:layout_height="wrap_content" />
......
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