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
9ddc97a7
authored
Mar 13, 2020
by
pye52
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
已确认天波厂家提供的SDK可用于targetSdkVersion 22以上,且优卡特设备也可使用该方案(只是串口地址不同)
parent
89ccca86
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
13 additions
and
222 deletions
+13
-222
README.md
+2
-1
app/libs/armeabi/libserial_port.so
+0
-0
app/proguard-rules.pro
+0
-3
app/src/main/java/android_serialport_api/SerialPort.java
+0
-57
app/src/main/java/android_serialport_api/SerialPortFinder.java
+0
-113
app/src/main/java/com/bgycc/smartcanteen/qrcode/DefaultQRCodeScan.java
+9
-3
app/src/main/java/com/bgycc/smartcanteen/qrcode/QRCodeScanFactory.java
+2
-2
app/src/main/java/com/bgycc/smartcanteen/qrcode/QUAD.java
+0
-20
app/src/main/java/com/bgycc/smartcanteen/qrcode/TPS.java
+0
-23
No files found.
README.md
View file @
9ddc97a7
...
@@ -20,7 +20,8 @@
...
@@ -20,7 +20,8 @@
5.
优化日志输出,方便测试及后续迭代维护
5.
优化日志输出,方便测试及后续迭代维护
### 注意事项
### 注意事项
-
优卡特p60s受厂家二维码sdk限制,targetSdkVersion必须为22,使用高版本将导致App
**无法在设备上运行!!!切记!!!**
~~优卡特p60s受厂家二维码sdk限制,targetSdkVersion必须为22,使用高版本将导致App
**无法在设备上运行!!!切记!!!**
~~
已确认天波厂家提供的sdk可以在targetSdkVersion 22以上使用,且优卡特设备同样可以使用该方案
### 机型历史
### 机型历史
该项目到现在一共使用过3个机型,按时间顺序排列分别是:
该项目到现在一共使用过3个机型,按时间顺序排列分别是:
...
...
app/libs/armeabi/libserial_port.so
deleted
100644 → 0
View file @
89ccca86
File deleted
app/proguard-rules.pro
View file @
9ddc97a7
...
@@ -168,9 +168,6 @@
...
@@ -168,9 +168,6 @@
#不混淆tps下的所有类
#不混淆tps下的所有类
-keep class com.telpo.tps550.api.
*
* { *; }
-keep class com.telpo.tps550.api.
*
* { *; }
#不混淆serialport下的所有类
-keep class android_serialport_api.
*
* { *; }
#okhttp
#okhttp
-dontwarn okhttp3.
*
*
-dontwarn okhttp3.
*
*
-keep class okhttp3.
*
*{*;}
-keep class okhttp3.
*
*{*;}
...
...
app/src/main/java/android_serialport_api/SerialPort.java
deleted
100644 → 0
View file @
89ccca86
package
android_serialport_api
;
import
java.io.File
;
import
java.io.FileDescriptor
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
/**
* Google官方代码
* 此类的作用为,JNI的调用,用来加载.so文件的
* 获取串口输入输出流
*/
public
class
SerialPort
{
private
FileDescriptor
mFd
;
private
FileInputStream
mFileInputStream
;
private
FileOutputStream
mFileOutputStream
;
static
{
System
.
loadLibrary
(
"serial_port"
);
}
public
SerialPort
(
String
devicePath
,
int
baudRate
,
int
flags
)
throws
SecurityException
{
this
(
new
File
(
devicePath
),
baudRate
,
flags
);
}
private
SerialPort
(
File
device
,
int
baudRate
,
int
flags
)
throws
SecurityException
{
if
(!
device
.
canRead
()
||
!
device
.
canWrite
())
{
try
{
Process
su
=
Runtime
.
getRuntime
().
exec
(
"/system/bin/su"
);
String
cmd
=
"chmod 666 "
+
device
.
getAbsolutePath
()
+
"\n"
+
"exit\n"
;
su
.
getOutputStream
().
write
(
cmd
.
getBytes
());
if
((
su
.
waitFor
()
!=
0
)
||
!
device
.
canRead
()
||
!
device
.
canWrite
())
{
throw
new
RuntimeException
(
"没有串口权限"
);
}
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
"提权失败"
+
e
.
getMessage
(),
e
);
}
}
mFd
=
open
(
device
.
getAbsolutePath
(),
baudRate
,
flags
);
mFileInputStream
=
new
FileInputStream
(
mFd
);
mFileOutputStream
=
new
FileOutputStream
(
mFd
);
}
public
InputStream
getInputStream
()
{
return
mFileInputStream
;
}
public
OutputStream
getOutputStream
()
{
return
mFileOutputStream
;
}
private
native
static
FileDescriptor
open
(
String
path
,
int
baudrate
,
int
flags
);
public
native
void
close
();
}
app/src/main/java/android_serialport_api/SerialPortFinder.java
deleted
100644 → 0
View file @
89ccca86
package
android_serialport_api
;
import
android.util.Log
;
import
java.io.File
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.io.LineNumberReader
;
import
java.util.Iterator
;
import
java.util.Vector
;
/**
* Google官方代码
* 此类的作用为,寻找得到有效的串口的物理地址。
* 如果你本身就知道串口的地址如:ttyS1、ttyS2,那么这个类就可以不用了。
*
*/
public
class
SerialPortFinder
{
public
class
Driver
{
public
Driver
(
String
name
,
String
root
)
{
mDriverName
=
name
;
mDeviceRoot
=
root
;
}
private
String
mDriverName
;
private
String
mDeviceRoot
;
Vector
<
File
>
mDevices
=
null
;
public
Vector
<
File
>
getDevices
()
{
if
(
mDevices
==
null
)
{
mDevices
=
new
Vector
<>();
File
dev
=
new
File
(
"/dev"
);
File
[]
files
=
dev
.
listFiles
();
int
i
;
for
(
i
=
0
;
i
<
files
.
length
;
i
++)
{
if
(
files
[
i
].
getAbsolutePath
().
startsWith
(
mDeviceRoot
))
{
Log
.
d
(
TAG
,
"Found new device: "
+
files
[
i
]);
mDevices
.
add
(
files
[
i
]);
}
}
}
return
mDevices
;
}
public
String
getName
()
{
return
mDriverName
;
}
}
private
static
final
String
TAG
=
"SerialPort"
;
private
Vector
<
Driver
>
mDrivers
=
null
;
Vector
<
Driver
>
getDrivers
()
throws
IOException
{
if
(
mDrivers
==
null
)
{
mDrivers
=
new
Vector
<>();
LineNumberReader
r
=
new
LineNumberReader
(
new
FileReader
(
"/proc/tty/drivers"
));
String
l
;
while
((
l
=
r
.
readLine
())
!=
null
)
{
// Issue 3:
// Since driver name may contain spaces, we do not extract driver name with split()
String
drivername
=
l
.
substring
(
0
,
0x15
).
trim
();
String
[]
w
=
l
.
split
(
" +"
);
if
((
w
.
length
>=
5
)
&&
(
w
[
w
.
length
-
1
].
equals
(
"serial"
)))
{
Log
.
d
(
TAG
,
"Found new driver "
+
drivername
+
" on "
+
w
[
w
.
length
-
4
]);
mDrivers
.
add
(
new
Driver
(
drivername
,
w
[
w
.
length
-
4
]));
}
}
r
.
close
();
}
return
mDrivers
;
}
public
String
[]
getAllDevices
()
{
Vector
<
String
>
devices
=
new
Vector
<
String
>();
// Parse each driver
Iterator
<
Driver
>
itdriv
;
try
{
itdriv
=
getDrivers
().
iterator
();
while
(
itdriv
.
hasNext
())
{
Driver
driver
=
itdriv
.
next
();
Iterator
<
File
>
itdev
=
driver
.
getDevices
().
iterator
();
while
(
itdev
.
hasNext
())
{
String
device
=
itdev
.
next
().
getName
();
String
value
=
String
.
format
(
"%s (%s)"
,
device
,
driver
.
getName
());
devices
.
add
(
value
);
}
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
devices
.
toArray
(
new
String
[
devices
.
size
()]);
}
public
String
[]
getAllDevicesPath
()
{
Vector
<
String
>
devices
=
new
Vector
<
String
>();
// Parse each driver
Iterator
<
Driver
>
itdriv
;
try
{
itdriv
=
getDrivers
().
iterator
();
while
(
itdriv
.
hasNext
())
{
Driver
driver
=
itdriv
.
next
();
Iterator
<
File
>
itdev
=
driver
.
getDevices
().
iterator
();
while
(
itdev
.
hasNext
())
{
String
device
=
itdev
.
next
().
getAbsolutePath
();
devices
.
add
(
device
);
}
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
devices
.
toArray
(
new
String
[
devices
.
size
()]);
}
}
app/src/main/java/com/bgycc/smartcanteen/qrcode/
Base
QRCodeScan.java
→
app/src/main/java/com/bgycc/smartcanteen/qrcode/
Default
QRCodeScan.java
View file @
9ddc97a7
package
com
.
bgycc
.
smartcanteen
.
qrcode
;
package
com
.
bgycc
.
smartcanteen
.
qrcode
;
import
com.blankj.utilcode.util.LogUtils
;
import
com.blankj.utilcode.util.LogUtils
;
import
com.telpo.tps550.api.serial.Serial
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
...
@@ -8,11 +9,13 @@ import java.util.Arrays;
...
@@ -8,11 +9,13 @@ import java.util.Arrays;
import
static
com
.
bgycc
.
smartcanteen
.
utils
.
SmartCanteenUtils
.
TAG
;
import
static
com
.
bgycc
.
smartcanteen
.
utils
.
SmartCanteenUtils
.
TAG
;
public
abstract
class
BaseQRCodeScan
implements
IQRCodeScan
{
public
class
DefaultQRCodeScan
implements
IQRCodeScan
{
private
Serial
serial
;
private
InputStream
serialPortIS
;
private
InputStream
serialPortIS
;
void
setup
(
InputStream
serialPortIS
)
{
public
DefaultQRCodeScan
(
String
filePath
)
throws
Exception
{
this
.
serialPortIS
=
serialPortIS
;
serial
=
new
Serial
(
filePath
,
115200
,
0
);
this
.
serialPortIS
=
serial
.
getInputStream
();
}
}
@Override
@Override
...
@@ -59,6 +62,9 @@ public abstract class BaseQRCodeScan implements IQRCodeScan {
...
@@ -59,6 +62,9 @@ public abstract class BaseQRCodeScan implements IQRCodeScan {
LogUtils
.
w
(
TAG
,
"端口关闭失败: "
+
e
.
getMessage
(),
e
);
LogUtils
.
w
(
TAG
,
"端口关闭失败: "
+
e
.
getMessage
(),
e
);
}
}
}
}
if
(
serial
!=
null
)
{
serial
.
close
();
}
}
}
private
boolean
end
(
byte
[]
buf
)
{
private
boolean
end
(
byte
[]
buf
)
{
...
...
app/src/main/java/com/bgycc/smartcanteen/qrcode/QRCodeScanFactory.java
View file @
9ddc97a7
...
@@ -10,9 +10,9 @@ public class QRCodeScanFactory {
...
@@ -10,9 +10,9 @@ public class QRCodeScanFactory {
public
static
IQRCodeScan
create
()
throws
Exception
{
public
static
IQRCodeScan
create
()
throws
Exception
{
String
model
=
Build
.
MODEL
;
String
model
=
Build
.
MODEL
;
if
(
model
.
contains
(
DeviceProxy
.
DEVICE_MODEL_TPS
))
{
if
(
model
.
contains
(
DeviceProxy
.
DEVICE_MODEL_TPS
))
{
return
new
TPS
(
TPS_PORT
);
return
new
DefaultQRCodeScan
(
TPS_PORT
);
}
else
if
(
model
.
contains
(
DeviceProxy
.
DEVICE_MODEL_QUAD
))
{
}
else
if
(
model
.
contains
(
DeviceProxy
.
DEVICE_MODEL_QUAD
))
{
return
new
QUAD
(
QUAD_PORT
);
return
new
DefaultQRCodeScan
(
QUAD_PORT
);
}
else
{
}
else
{
throw
new
RuntimeException
(
"不明设备型号: "
+
model
);
throw
new
RuntimeException
(
"不明设备型号: "
+
model
);
}
}
...
...
app/src/main/java/com/bgycc/smartcanteen/qrcode/QUAD.java
deleted
100644 → 0
View file @
89ccca86
package
com
.
bgycc
.
smartcanteen
.
qrcode
;
import
android_serialport_api.SerialPort
;
public
class
QUAD
extends
BaseQRCodeScan
{
private
SerialPort
serial
;
public
QUAD
(
String
filePath
)
throws
Exception
{
serial
=
new
SerialPort
(
filePath
,
115200
,
0
);
setup
(
serial
.
getInputStream
());
}
@Override
public
void
close
()
{
super
.
close
();
if
(
serial
!=
null
)
{
serial
.
close
();
}
}
}
app/src/main/java/com/bgycc/smartcanteen/qrcode/TPS.java
deleted
100644 → 0
View file @
89ccca86
package
com
.
bgycc
.
smartcanteen
.
qrcode
;
import
com.telpo.tps550.api.serial.Serial
;
/**
* 天波580C串口读取
*/
public
class
TPS
extends
BaseQRCodeScan
{
private
Serial
serial
;
public
TPS
(
String
filePath
)
throws
Exception
{
serial
=
new
Serial
(
filePath
,
115200
,
0
);
setup
(
serial
.
getInputStream
());
}
@Override
public
void
close
()
{
super
.
close
();
if
(
serial
!=
null
)
{
serial
.
close
();
}
}
}
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