Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
huangzhicong
/
SmartCanteen
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
6fe0f7d4
authored
Aug 13, 2019
by
patpat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
支持天波580C设备
parent
4e45eb68
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
185 additions
and
9 deletions
+185
-9
app/src/main/java/com/bgycc/smartcanteen/App.kt
+8
-1
app/src/main/java/com/bgycc/smartcanteen/activity/MainActivity.kt
+28
-4
app/src/main/java/com/bgycc/smartcanteen/helper/EthernetHelper.java
+18
-0
app/src/main/java/com/bgycc/smartcanteen/module/Device.kt
+56
-0
app/src/main/java/com/bgycc/smartcanteen/server/websocket/MainWebSocket.java
+5
-2
app/src/main/java/com/bgycc/smartcanteen/task/QRCodeTask.java
+44
-2
app/src/main/java/com/bgycc/smartcanteen/util/ByteUtil.java
+14
-0
app/src/main/java/com/szxb/jni/libszxb.java
+11
-0
app/src/main/res/layout/activity_main.xml
+1
-0
No files found.
app/src/main/java/com/bgycc/smartcanteen/App.kt
View file @
6fe0f7d4
...
...
@@ -8,6 +8,8 @@ import com.bgycc.smartcanteen.helper.WifiHelpler
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.szxb.jni.libszxb
import
java.lang.Exception
class
App
:
Application
()
{
...
...
@@ -25,7 +27,11 @@ class App : Application() {
return
sInstances
[
processName
]
}
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
{
return
sVersionName
...
...
@@ -45,6 +51,7 @@ class App : Application() {
LogUtil
.
setEnable
(
AppConfig
.
DEBUG
)
WifiHelpler
.
initialize
(
this
)
PayStorage
.
initialize
(
this
)
Device
.
initialize
(
this
)
}
fun
isMainProcess
():
Boolean
{
...
...
app/src/main/java/com/bgycc/smartcanteen/activity/MainActivity.kt
View file @
6fe0f7d4
package
com.bgycc.smartcanteen.activity
import
android.content.Context
import
android.media.AudioManager
import
android.media.SoundPool
import
android.os.Bundle
import
android.os.Handler
import
android.util.Log
import
android.view.KeyEvent
import
android.view.View
import
android.view.animation.Animation
import
android.view.animation.RotateAnimation
...
...
@@ -15,6 +17,7 @@ import com.bgycc.smartcanteen.R
import
com.bgycc.smartcanteen.event.LogEvent
import
com.bgycc.smartcanteen.event.PayStateEvent
import
com.bgycc.smartcanteen.event.WifiStateEvent
import
com.bgycc.smartcanteen.helper.EthernetHelper
import
com.bgycc.smartcanteen.helper.TimerHelper
import
com.bgycc.smartcanteen.helper.WifiHelpler
import
com.bgycc.smartcanteen.server.websocket.event.ConnectStateEvent
...
...
@@ -30,10 +33,6 @@ import org.greenrobot.eventbus.ThreadMode
import
java.text.SimpleDateFormat
import
java.util.*
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
()
{
...
...
@@ -45,6 +44,7 @@ class MainActivity : BaseActivity() {
private
var
mBeepSoundId
=
0
private
var
mPaySuccessSoundId
=
0
private
var
mPayFailSoundId
=
0
private
var
mAudioManager
:
AudioManager
?
=
null
private
val
mHandler
=
Handler
()
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
...
...
@@ -52,6 +52,7 @@ class MainActivity : BaseActivity() {
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
activity_main
)
hideStatusBar
()
hideNavigation
()
initView
()
EventBus
.
getDefault
().
register
(
this
)
...
...
@@ -66,6 +67,7 @@ class MainActivity : BaseActivity() {
}
private
fun
init
()
{
mAudioManager
=
getSystemService
(
Context
.
AUDIO_SERVICE
)
as
AudioManager
mBeepSoundId
=
mSoundPool
.
load
(
assets
.
openFd
(
"beep.mp3"
),
1
)
mPaySuccessSoundId
=
mSoundPool
.
load
(
assets
.
openFd
(
"pay-success.mp3"
),
1
)
mPayFailSoundId
=
mSoundPool
.
load
(
assets
.
openFd
(
"pay-fail.mp3"
),
1
)
...
...
@@ -87,6 +89,7 @@ class MainActivity : BaseActivity() {
_setting_img
.
startAnimation
(
anim
)
}
_version
.
text
=
"Version: v${App.getVersionName()}(${App.getVersionCode()})"
_eth
.
text
=
"Ethernet Mac: ${EthernetHelper.getMacAddress()}"
}
private
fun
initTimer
()
{
...
...
@@ -102,6 +105,27 @@ class MainActivity : BaseActivity() {
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
)
{
var
msg
=
"QRCode: "
+
event
.
string
if
(
event
.
payCodeType
!=
null
)
{
...
...
app/src/main/java/com/bgycc/smartcanteen/helper/EthernetHelper.java
0 → 100644
View file @
6fe0f7d4
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"
;
}
}
app/src/main/java/com/bgycc/smartcanteen/module/Device.kt
0 → 100644
View file @
6fe0f7d4
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
app/src/main/java/com/bgycc/smartcanteen/server/websocket/MainWebSocket.java
View file @
6fe0f7d4
...
...
@@ -2,6 +2,7 @@ package com.bgycc.smartcanteen.server.websocket;
import
android.util.Log
;
import
android.util.SparseArray
;
import
com.bgycc.smartcanteen.App
;
import
com.bgycc.smartcanteen.AppConfig
;
import
com.bgycc.smartcanteen.action.ActionEnum
;
import
com.bgycc.smartcanteen.action.PayOfflineAction
;
...
...
@@ -11,6 +12,8 @@ import com.bgycc.smartcanteen.server.websocket.event.RecvMessageEvent;
import
com.bgycc.smartcanteen.server.websocket.event.SendMessageEvent
;
import
com.example.zhoukai.modemtooltest.ModemToolTest
;
import
com.example.zhoukai.modemtooltest.NvConstants
;
import
com.maxrocky.vmatrix.module.Device
;
import
com.szxb.jni.libszxb
;
import
org.greenrobot.eventbus.EventBus
;
import
org.java_websocket.client.WebSocketClient
;
import
org.java_websocket.drafts.Draft_6455
;
...
...
@@ -50,8 +53,8 @@ public class MainWebSocket extends WebSocketClient {
public
static
void
initialize
()
{
if
(
sInstance
==
null
)
{
try
{
sDeviceSN
=
ModemToolTest
.
getItem
(
NvConstants
.
REQUEST_GET_SN
);
if
(
sDeviceSN
==
null
||
sDeviceSN
.
isEmpty
())
return
;
sDeviceSN
=
App
.
Companion
.
getDeviceSN
(
);
if
(
sDeviceSN
.
isEmpty
())
return
;
EventBus
.
getDefault
().
post
(
new
ConnectStateEvent
(
ConnectStateEvent
.
CONNECTING
));
sInstance
=
new
MainWebSocket
(
new
URI
(
String
.
format
(
AppConfig
.
getMainWebSocketServerUrl
(),
sDeviceSN
)));
...
...
app/src/main/java/com/bgycc/smartcanteen/task/QRCodeTask.java
View file @
6fe0f7d4
...
...
@@ -5,11 +5,15 @@ import com.bgycc.smartcanteen.action.*;
import
com.bgycc.smartcanteen.event.LogEvent
;
import
com.bgycc.smartcanteen.helper.TimerHelper
;
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
kotlin.jvm.functions.Function2
;
import
org.greenrobot.eventbus.EventBus
;
import
org.json.JSONObject
;
import
java.io.InputStream
;
import
java.util.Arrays
;
import
java.util.regex.Pattern
;
public
class
QRCodeTask
{
...
...
@@ -62,6 +66,20 @@ public class QRCodeTask {
int
lastLen
=
-
1
;
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
protected
void
run
(
int
step
,
int
progress
)
{
...
...
@@ -70,14 +88,38 @@ public class QRCodeTask {
case
0
:
if
(
progress
!=
0
)
break
;
String
str
=
null
;
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
);
String
str
=
new
String
(
buf
,
0
,
len
);
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
();
}
if
(
str
==
null
)
break
;
QRCodeEvent
event
=
new
QRCodeEvent
(
str
.
getBytes
(),
str
,
checkPayCodeType
(
str
));
EventBus
.
getDefault
().
post
(
event
);
...
...
app/src/main/java/com/bgycc/smartcanteen/util/ByteUtil.java
0 → 100644
View file @
6fe0f7d4
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
;
}
}
app/src/main/java/com/szxb/jni/libszxb.java
View file @
6fe0f7d4
...
...
@@ -32,9 +32,19 @@ import android.util.Log;
*/
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
();
...
...
@@ -44,6 +54,7 @@ public class libszxb {
static
{
try
{
System
.
loadLibrary
(
"ymodem"
);
mSupportYMODEM
=
true
;
}
catch
(
Throwable
e
)
{
Log
.
e
(
"jni"
,
"i can't find ymodem so!"
);
e
.
printStackTrace
();
...
...
app/src/main/res/layout/activity_main.xml
View file @
6fe0f7d4
...
...
@@ -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"
>
<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/_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/_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"
/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment