Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
SocketDemo
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
朱世闯
SocketDemo
Commits
393af7a8
Commit
393af7a8
authored
Mar 09, 2022
by
UIUANG\Zsc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改传称
parent
3956d706
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
133 additions
and
72 deletions
+133
-72
vcs.xml
.idea/vcs.xml
+6
-0
build.gradle
DigiTransfer/build.gradle
+6
-5
DigiScaleTransfer.java
...main/java/com/wmdigit/digitransfer/DigiScaleTransfer.java
+9
-6
ObjectHandler.java
.../java/com/wmdigit/digitransfer/handler/ObjectHandler.java
+1
-1
Printer.java
...c/main/java/com/wmdigit/digitransfer/handler/Printer.java
+15
-0
ScalesApiHandler.java
...va/com/wmdigit/digitransfer/handler/ScalesApiHandler.java
+95
-60
build.gradle
app/build.gradle
+1
-0
No files found.
.idea/vcs.xml
0 → 100644
View file @
393af7a8
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"VcsDirectoryMappings"
>
<mapping
directory=
"$PROJECT_DIR$"
vcs=
"Git"
/>
</component>
</project>
\ No newline at end of file
DigiTransfer/build.gradle
View file @
393af7a8
...
...
@@ -8,8 +8,8 @@ android {
defaultConfig
{
minSdkVersion
21
targetSdkVersion
31
versionCode
1
versionName
"1.0.
0
"
versionCode
4
versionName
"1.0.
4
"
testInstrumentationRunner
"androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles
"consumer-rules.pro"
...
...
@@ -27,7 +27,7 @@ android {
}
android
.
libraryVariants
.
all
{
variant
->
variant
.
outputs
.
all
{
outputFileName
=
"${project.name}_v"
+
android
.
defaultConfig
.
versionName
+
'_sdk.
a
ar'
outputFileName
=
"${project.name}_v"
+
android
.
defaultConfig
.
versionName
+
'_sdk.
j
ar'
}
}
}
...
...
@@ -42,8 +42,9 @@ dependencies {
}
task
makeJar
(
type:
Copy
)
{
def
outAar
=
"${project.name}_v"
+
android
.
defaultConfig
.
versionName
+
"_sdk.jar"
//删除存在的
delete
'build/libs/
myjar.jar'
delete
'build/libs/
'
+
outAar
//设置拷贝的文件
from
(
'build/intermediates/aar_main_jar/release/'
)
//打进jar包后的文件目录
...
...
@@ -53,7 +54,7 @@ task makeJar(type: Copy) {
//(我们只关心classes.jar这个文件)
include
(
'classes.jar'
)
//重命名
rename
(
'classes.jar'
,
'myjar.jar'
)
rename
(
'classes.jar'
,
outAar
)
}
makeJar
.
dependsOn
(
build
)
\ No newline at end of file
DigiTransfer/src/main/java/com/wmdigit/digitransfer/DigiScaleTransfer.java
View file @
393af7a8
...
...
@@ -5,6 +5,7 @@ import android.util.Log;
import
com.wmdigit.digitransfer.exception.ErrCode
;
import
com.wmdigit.digitransfer.exception.ScalesApiException
;
import
com.wmdigit.digitransfer.handler.ObjectHandler
;
import
com.wmdigit.digitransfer.handler.Printer
;
import
com.wmdigit.digitransfer.util.NetWorkUtils
;
import
java.io.IOException
;
...
...
@@ -16,26 +17,28 @@ public class DigiScaleTransfer {
private
static
DigiScaleTransfer
instance
;
private
int
addressFour
;
private
ObjectHandler
scalesApiHandler
;
private
Printer
printer
;
private
final
String
TAG
=
DigiScaleTransfer
.
this
.
getClass
().
getSimpleName
();
private
ServerSocket
serverSocket
;
public
static
DigiScaleTransfer
getInstance
(
ObjectHandler
scalesApiHandler
)
{
public
static
DigiScaleTransfer
getInstance
(
ObjectHandler
scalesApiHandler
,
Printer
printer
)
{
if
(
instance
==
null
)
{
instance
=
new
DigiScaleTransfer
(
scalesApiHandler
);
instance
=
new
DigiScaleTransfer
(
scalesApiHandler
,
printer
);
}
return
instance
;
}
private
DigiScaleTransfer
(
ObjectHandler
scalesApiHandler
)
{
private
DigiScaleTransfer
(
ObjectHandler
scalesApiHandler
,
Printer
printer
)
{
this
.
scalesApiHandler
=
scalesApiHandler
;
this
.
printer
=
printer
;
String
hostAddress
=
null
;
hostAddress
=
NetWorkUtils
.
getLocalIp
();
int
of
=
hostAddress
.
lastIndexOf
(
"."
);
String
addressFourStr
=
hostAddress
.
substring
(
of
+
1
);
addressFour
=
Integer
.
parseInt
(
addressFourStr
);
Log
.
i
(
"AT"
,
hostAddress
);
printer
.
d
(
"ip地址:"
+
hostAddress
);
}
...
...
@@ -55,8 +58,8 @@ public class DigiScaleTransfer {
try
{
socket
=
serverSocket
.
accept
();
int
localPort
=
serverSocket
.
getLocalPort
();
Log
.
i
(
"port"
,
"端口号"
+
localPort
);
scalesApiHandler
.
setSocket
(
socket
,
addressFour
);
printer
.
i
(
"端口号"
+
localPort
);
scalesApiHandler
.
setSocket
(
socket
,
addressFour
,
printer
);
ThreadCacheManager
.
getExecutorService
().
execute
(
scalesApiHandler
);
// Thread thread = new Thread(this.scalesApiHandler);
// thread.start();
...
...
DigiTransfer/src/main/java/com/wmdigit/digitransfer/handler/ObjectHandler.java
View file @
393af7a8
...
...
@@ -10,6 +10,6 @@ public interface ObjectHandler extends Runnable{
void
downPlu
(
Commodity
commodity
);
void
setSocket
(
Socket
socket
,
int
addressFour
);
void
setSocket
(
Socket
socket
,
int
addressFour
,
Printer
printer
);
}
DigiTransfer/src/main/java/com/wmdigit/digitransfer/handler/Printer.java
0 → 100644
View file @
393af7a8
package
com
.
wmdigit
.
digitransfer
.
handler
;
public
interface
Printer
{
void
i
(
String
msg
);
void
v
(
String
msg
);
void
d
(
String
msg
);
void
w
(
String
msg
);
void
e
(
String
msg
);
// void v(String format, Object... args)
}
DigiTransfer/src/main/java/com/wmdigit/digitransfer/handler/ScalesApiHandler.java
View file @
393af7a8
...
...
@@ -15,6 +15,7 @@ import java.nio.ByteOrder;
public
abstract
class
ScalesApiHandler
implements
ObjectHandler
{
private
Socket
socket
;
private
int
addressFour
;
private
Printer
printer
;
public
ScalesApiHandler
()
{
}
...
...
@@ -30,7 +31,7 @@ public abstract class ScalesApiHandler implements ObjectHandler {
byteBuffer
.
put
(
mReceivedBuffer
,
0
,
read
);
byteBuffer
.
order
(
ByteOrder
.
LITTLE_ENDIAN
).
flip
();
byte
[]
byteArray
=
byteBuffer
.
array
();
System
.
out
.
println
(
Hex2BytesUtils
.
bytesToHexString2
(
byteArray
));
printer
.
d
(
Hex2BytesUtils
.
bytesToHexString2
(
byteArray
));
switch
(
byteArray
[
0
])
{
case
(
byte
)
247
:
String
hexString
=
Hex2BytesUtils
.
bytesToHexString
(
byteArray
);
...
...
@@ -38,10 +39,10 @@ public abstract class ScalesApiHandler implements ObjectHandler {
String
hex2
;
if
(
addressFour
>
153
)
{
hex2
=
"F74F00000"
+
addressFour
;
}
else
{
}
else
{
hex2
=
"F74F000000"
+
hex
;
}
System
.
out
.
println
(
hex2
);
printer
.
d
(
hex2
);
if
(
hexString
.
equals
(
"F74F00000000"
))
{
String
s1
=
"00 00 00 "
+
hex
+
" 00 b6 00 00 00 00 00 01 00 00 00 01 00 00 00 00 16 01 04 01 00 20 10 01 24 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 60 03 "
+
"77 5e e0 c0 a8 31 "
+
...
...
@@ -52,7 +53,7 @@ public abstract class ScalesApiHandler implements ObjectHandler {
replyCommand
(
bytes1
);
}
else
if
(
hexString
.
equals
(
hex2
))
{
System
.
out
.
println
(
hex2
);
// printer.d
(hex2);
byte
[]
bytes1
=
new
byte
[
1
];
bytes1
[
0
]
=
(
byte
)
226
;
replyCommand
(
bytes1
);
...
...
@@ -79,7 +80,7 @@ public abstract class ScalesApiHandler implements ObjectHandler {
// System.out.println("条码格式BarcodeFormat:" + barcodeFormat);
commodity
.
setBarcodeFormat
(
barcodeFormat
);
// byte[] bytes1 = subBytes(receivedBytes, 19, 1);
String
labelFormat1
=
ByteBufferUtils
.
bytesToString
(
byteBuffer
,
1
);
String
labelFormat1
=
ByteBufferUtils
.
bytesToString
(
byteBuffer
,
1
);
commodity
.
setLabelFormat1
(
labelFormat1
);
// System.out.println("条码前缀" + labelFormat1);
...
...
@@ -87,70 +88,55 @@ public abstract class ScalesApiHandler implements ObjectHandler {
String
itemCode
=
ByteBufferUtils
.
bytesToString
(
byteBuffer
,
5
).
replaceAll
(
"(0)+$"
,
""
);
// System.out.println("项目代码:" + itemCode);
commodity
.
setItemCode
(
itemCode
);
byteBuffer
.
position
(
byteBuffer
.
position
()
+
1
);
byteBuffer
.
position
(
byteBuffer
.
position
()
+
1
);
String
groupNo
=
String
.
valueOf
(
ByteBufferUtils
.
bytesToInteger
(
byteBuffer
,
2
));
// System.out.println("MGNo 主组:" + groupNo);
commodity
.
setMgNo
(
groupNo
);
int
usedByDate
=
ByteBufferUtils
.
bytesToInteger
(
byteBuffer
,
2
);
//
System.out.println("售出日期:UsedByDate:" + usedByDate);
System
.
out
.
println
(
"售出日期:UsedByDate:"
+
usedByDate
);
commodity
.
setUsedByDate
(
usedByDate
);
int
sellByDate
=
ByteBufferUtils
.
bytesToInteger
(
byteBuffer
,
2
);
//
System.out.println("保质期:SellByDate:" + sellByDate);
System
.
out
.
println
(
"保质期:SellByDate:"
+
sellByDate
);
commodity
.
setSellByDate
(
sellByDate
);
int
packedByDate
=
ByteBufferUtils
.
bytesToInteger
(
byteBuffer
,
2
);
// System.out.println("包装日期,PackedByDate:" + packedByDate);
commodity
.
setPackedByDate
(
packedByDate
);
// System.out.println("包装日期,PackedByDate:" + packedByDate);
byteBuffer
.
position
(
48
);
int
traceabilityFlag
=
ByteBufferUtils
.
bytesToInt
(
byteBuffer
);
int
traceabilityNo
=
ByteBufferUtils
.
bytesToInteger
(
byteBuffer
,
2
);
System
.
out
.
println
(
"追溯码开关"
+
traceabilityFlag
+
",追溯码内容"
+
traceabilityNo
);
System
.
out
.
println
(
"包装日期,PackedByDate:"
+
packedByDate
);
commodity
.
setPackedByDate
(
packedByDate
);
byteBuffer
.
position
(
152
);
int
commodity1Start
=
byteBuffer
.
get
();
if
(
commodity1Start
==
3
)
{
int
commodity1Font
=
ByteBufferUtils
.
bytesToInt
(
byteBuffer
);
System
.
out
.
println
(
"commodity1Font:"
+
commodity1Font
);
int
commodity1Length
=
ByteBufferUtils
.
bytesToInt
(
byteBuffer
);
String
commodity1
=
ByteBufferUtils
.
bytesToHexString
(
byteBuffer
,
commodity1Length
);
commodity
.
setCommodity1
(
commodity1
);
int
commodity2Start
=
byteBuffer
.
get
();
if
(
commodity2Start
==
13
)
{
int
commodity2Font
=
ByteBufferUtils
.
bytesToInt
(
byteBuffer
);
System
.
out
.
println
(
"commodity2Font:"
+
commodity2Font
);
int
commodity2Length
=
ByteBufferUtils
.
bytesToInt
(
byteBuffer
);
String
commodity2
=
ByteBufferUtils
.
bytesToHexString
(
byteBuffer
,
commodity2Length
);
commodity
.
setCommodity2
(
commodity2
);
int
commodity3Start
=
byteBuffer
.
get
();
if
(
commodity3Start
==
13
)
{
int
commodity3Font
=
ByteBufferUtils
.
bytesToInt
(
byteBuffer
);
System
.
out
.
println
(
"commodity3Font:"
+
commodity3Font
);
int
commodity3Length
=
ByteBufferUtils
.
bytesToInt
(
byteBuffer
);
String
commodity3
=
ByteBufferUtils
.
bytesToHexString
(
byteBuffer
,
commodity3Length
);
commodity
.
setCommodity3
(
commodity3
);
byte
commodity4Start
=
byteBuffer
.
get
();
if
(
commodity4Start
==
13
)
{
int
commodity4Font
=
ByteBufferUtils
.
bytesToInt
(
byteBuffer
);
System
.
out
.
println
(
"commodity4Font:"
+
commodity4Font
);
int
commodity4Length
=
ByteBufferUtils
.
bytesToInt
(
byteBuffer
);
String
commodity4
=
ByteBufferUtils
.
bytesToHexString
(
byteBuffer
,
commodity4Length
);
commodity
.
setCommodity4
(
commodity4
);
byte
ingredient1Start
=
byteBuffer
.
get
();
if
(
ingredient1Start
==
12
)
{
getIngredient
(
byteBuffer
,
commodity
);
}
}
else
{
getIngredient
(
byteBuffer
,
commodity
);
}
}
else
{
getIngredient
(
byteBuffer
,
commodity
);
}
}
else
if
(
commodity1Start
==
12
)
{
getIngredient
(
byteBuffer
,
commodity
);
// int pos = 152;
// int i = 0;
// boolean isResult = true;
// while (isResult) {
//
// }
for
(
int
pos
=
152
;
pos
>
0
;
pos
--)
{
printer
.
i
(
"pos:"
+
pos
);
byteBuffer
.
position
(
pos
);
int
commodity1Start
=
byteBuffer
.
get
();
printer
.
i
(
"commodity1Start= "
+
commodity1Start
);
if
(
commodity1Start
==
3
)
{
getCommodity
(
byteBuffer
,
commodity
);
byteBuffer
.
position
(
pos
-
104
);
int
traceabilityFlag
=
ByteBufferUtils
.
bytesToInt
(
byteBuffer
);
int
traceabilityNo
=
ByteBufferUtils
.
bytesToInteger
(
byteBuffer
,
2
);
printer
.
d
(
"追溯码开关"
+
traceabilityFlag
+
",追溯码内容"
+
traceabilityNo
);
break
;
}
}
// else {
// byteBuffer.position(150);
// commodity1Start = byteBuffer.get();
// if (commodity1Start == 3) {
// getCommodity(byteBuffer, commodity);
// }else {
// byteBuffer.position(148);
// commodity1Start = byteBuffer.get();
// if (commodity1Start == 3) {
// getCommodity(byteBuffer, commodity);
// }
// }
// }
downPlu
(
commodity
);
...
...
@@ -161,10 +147,10 @@ public abstract class ScalesApiHandler implements ObjectHandler {
break
;
case
(
byte
)
176
:
byteBuffer
.
position
(
12
);
int
i
=
byteBuffer
.
array
().
length
-
1
-
12
;
int
i
=
byteBuffer
.
array
().
length
-
1
-
12
;
byte
[]
bytes
=
new
byte
[
i
];
byteBuffer
.
get
(
bytes
);
String
s
=
new
String
(
byteArray
,
"GBK"
);
String
s
=
new
String
(
byteArray
,
"GBK"
);
System
.
out
.
println
(
s
);
byte
[]
bytes4
=
new
byte
[
1
];
...
...
@@ -190,9 +176,54 @@ public abstract class ScalesApiHandler implements ObjectHandler {
}
private
void
getCommodity
(
ByteBuffer
byteBuffer
,
Commodity
commodity
)
throws
UnsupportedEncodingException
{
int
commodity1Font
=
ByteBufferUtils
.
bytesToInt
(
byteBuffer
);
printer
.
d
(
"commodity1Font:"
+
commodity1Font
);
int
commodity1Length
=
ByteBufferUtils
.
bytesToInt
(
byteBuffer
);
String
commodity1
=
ByteBufferUtils
.
bytesToHexString
(
byteBuffer
,
commodity1Length
);
commodity
.
setCommodity1
(
commodity1
);
int
commodity2Start
=
byteBuffer
.
get
();
if
(
commodity2Start
==
13
)
{
int
commodity2Font
=
ByteBufferUtils
.
bytesToInt
(
byteBuffer
);
// System.out.println("commodity2Font:" + commodity2Font);
int
commodity2Length
=
ByteBufferUtils
.
bytesToInt
(
byteBuffer
);
String
commodity2
=
ByteBufferUtils
.
bytesToHexString
(
byteBuffer
,
commodity2Length
);
commodity
.
setCommodity2
(
commodity2
);
int
commodity3Start
=
byteBuffer
.
get
();
if
(
commodity3Start
==
13
)
{
int
commodity3Font
=
ByteBufferUtils
.
bytesToInt
(
byteBuffer
);
// System.out.println("commodity3Font:" + commodity3Font);
int
commodity3Length
=
ByteBufferUtils
.
bytesToInt
(
byteBuffer
);
String
commodity3
=
ByteBufferUtils
.
bytesToHexString
(
byteBuffer
,
commodity3Length
);
commodity
.
setCommodity3
(
commodity3
);
byte
commodity4Start
=
byteBuffer
.
get
();
if
(
commodity4Start
==
13
)
{
int
commodity4Font
=
ByteBufferUtils
.
bytesToInt
(
byteBuffer
);
// System.out.println("commodity4Font:" + commodity4Font);
int
commodity4Length
=
ByteBufferUtils
.
bytesToInt
(
byteBuffer
);
String
commodity4
=
ByteBufferUtils
.
bytesToHexString
(
byteBuffer
,
commodity4Length
);
commodity
.
setCommodity4
(
commodity4
);
byte
ingredient1Start
=
byteBuffer
.
get
();
if
(
ingredient1Start
==
12
)
{
getIngredient
(
byteBuffer
,
commodity
);
}
}
else
{
getIngredient
(
byteBuffer
,
commodity
);
}
}
else
{
getIngredient
(
byteBuffer
,
commodity
);
}
}
else
if
(
commodity2Start
==
12
)
{
getIngredient
(
byteBuffer
,
commodity
);
}
}
private
void
getIngredient
(
ByteBuffer
byteBuffer
,
Commodity
commodity
)
throws
UnsupportedEncodingException
{
int
Ingredient1Font
=
ByteBufferUtils
.
bytesToInt
(
byteBuffer
);
System
.
out
.
println
(
"Ingredient1Font:"
+
Ingredient1Font
);
if
(
Ingredient1Font
==
0
)
{
return
;
}
int
ingredient1Length
=
ByteBufferUtils
.
bytesToInt
(
byteBuffer
);
String
ingredient1
=
ByteBufferUtils
.
bytesToHexString
(
byteBuffer
,
ingredient1Length
);
commodity
.
setIngredient1
(
ingredient1
);
...
...
@@ -240,7 +271,10 @@ public abstract class ScalesApiHandler implements ObjectHandler {
private
void
getSpecialMessage
(
ByteBuffer
byteBuffer
,
Commodity
commodity
)
throws
UnsupportedEncodingException
{
int
SpecialMessage1Font
=
ByteBufferUtils
.
bytesToInt
(
byteBuffer
);
System
.
out
.
println
(
"SpecialMessage1Font:"
+
SpecialMessage1Font
);
printer
.
d
(
"SpecialMessage1Font:"
+
SpecialMessage1Font
);
if
(
SpecialMessage1Font
==
0
)
{
return
;
}
int
specialMessage1Length
=
ByteBufferUtils
.
bytesToInt
(
byteBuffer
);
String
specialMessage1
=
ByteBufferUtils
.
bytesToHexString
(
byteBuffer
,
specialMessage1Length
);
commodity
.
setSpecialMessage1
(
specialMessage1
);
...
...
@@ -275,9 +309,10 @@ public abstract class ScalesApiHandler implements ObjectHandler {
}
@Override
public
void
setSocket
(
Socket
socket
,
int
addressFour
)
{
public
void
setSocket
(
Socket
socket
,
int
addressFour
,
Printer
printer
)
{
this
.
socket
=
socket
;
this
.
addressFour
=
addressFour
;
this
.
printer
=
printer
;
}
@Override
...
...
app/build.gradle
View file @
393af7a8
...
...
@@ -39,6 +39,7 @@ dependencies {
implementation
project
(
path:
':Transfer'
)
implementation
files
(
'libs\\wintecscales.jar'
)
implementation
project
(
path:
':DigiTransfer'
)
implementation
files
(
'libs\\DigiTransfer_v1.0.3_sdk.jar'
)
testImplementation
'junit:junit:4.+'
androidTestImplementation
'androidx.test.ext:junit:1.1.1'
androidTestImplementation
'androidx.test.espresso:espresso-core:3.2.0'
...
...
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