Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
GingerSoftLANInterconnection
Overview
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王宇航
GingerSoftLANInterconnection
Commits
46f40b6b
Commit
46f40b6b
authored
May 29, 2024
by
王宇航
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1、增加錯誤類型
2、訂單信息增加orderNo 3、發送消息 結果回調 增加errorMessage字段
parent
55a101fd
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
101 additions
and
23 deletions
+101
-23
.idea/deploymentTargetDropDown.xml
+14
-1
app/build.gradle.kts
+1
-1
app/src/main/java/com/example/demo/MainActivity.kt
+38
-9
mylibrary/build.gradle.kts
+1
-1
mylibrary/src/main/java/com/gingersoft/connect/SendCallback.kt
+2
-1
mylibrary/src/main/java/com/gingersoft/connect/bean/MessageBuilder.kt
+5
-2
mylibrary/src/main/java/com/gingersoft/connect/bean/MessageSender.kt
+2
-4
mylibrary/src/main/java/com/gingersoft/connect/bean/OrderInfoBean.java
+20
-0
mylibrary/src/main/java/com/gingersoft/connect/bean/SocketCallbackBean.kt
+9
-0
mylibrary/src/main/java/com/gingersoft/connect/utils/MyWebSocketClient.kt
+9
-4
No files found.
.idea/deploymentTargetDropDown.xml
View file @
46f40b6b
...
...
@@ -3,7 +3,20 @@
<component
name=
"deploymentTargetDropDown"
>
<value>
<entry
key=
"app"
>
<State
/>
<State>
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type
value=
"RUNNING_DEVICE_TARGET"
/>
<deviceKey>
<Key>
<type
value=
"SERIAL_NUMBER"
/>
<value
value=
"9X4TRG5PSCEYZHZX"
/>
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown
value=
"2024-05-28T12:43:00.676406500Z"
/>
</State>
</entry>
</value>
</component>
...
...
app/build.gradle.kts
View file @
46f40b6b
...
...
@@ -9,7 +9,7 @@ android {
defaultConfig {
applicationId = "com.example.gingersoft_connect"
minSdk =
24
minSdk =
19
targetSdk = 34
versionCode = 1
versionName = "1.0"
...
...
app/src/main/java/com/example/demo/MainActivity.kt
View file @
46f40b6b
...
...
@@ -7,10 +7,13 @@ import android.widget.TextView
import
com.example.gingersoft_connect.R
import
com.gingersoft.connect.SendCallback
import
com.gingersoft.connect.bean.Action
import
com.gingersoft.connect.bean.FoodInfoBean
import
com.gingersoft.connect.bean.MessageBuilder
import
com.gingersoft.connect.bean.MessageSender
import
com.gingersoft.connect.bean.OrderInfoBean
import
com.gingersoft.connect.utils.GingerSoftConnect
import
java.text.SimpleDateFormat
import
java.util.Date
class
MainActivity
:
Activity
()
{
...
...
@@ -61,18 +64,44 @@ class MainActivity : Activity() {
tvDisconnect
.
setOnClickListener
{
connect
?.
disconnect
()
}
var
count
=
0
tvSendMsg
.
setOnClickListener
{
msgSender
?.
initSendData
(
Action
.
KitchenInfo
,
OrderInfoBean
())
count
++
val
order
=
OrderInfoBean
().
apply
{
orderId
=
1111L
+
count
orderNo
=
"00$count"
orderType
=
1
pax
=
10
senderId
=
1965
.
toString
()
senderName
=
"Glen$count"
sendTime
=
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
).
format
(
Date
())
sendDeviceId
=
"6464646sdfs"
sendDeviceName
=
"POS$count"
sendOrderCount
=
4
+
count
isFirstSendOrder
=
true
flyPrintInfo
=
"K1-L2"
foodInfoBeanList
=
mutableListOf
<
FoodInfoBean
>().
apply
{
for
(
i
in
0
until
10
)
{
add
(
FoodInfoBean
().
apply
{
foodId
=
"${1 + i}"
printId
=
"1166$i"
orderId
=
1111L
+
count
foodName
=
"這是一個名字超級長的食品,"
quantity
=
count
.
toString
()
price
=
count
*
1.1
type
=
(
i
%
3
)
+
1
parentId
=
"0"
isPrintRedLetter
=
false
}
)
}
}
}
msgSender
?.
initSendData
(
Action
.
KitchenInfo
,
order
)
?.
asyncSend
(
object
:
SendCallback
{
override
fun
callback
(
status
:
Boolean
,
errorCode
:
Int
)
{
override
fun
callback
(
status
:
Boolean
,
errorCode
:
Int
,
errorMessage
:
String
)
{
runOnUiThread
{
tvSendValue
.
text
=
if
(
status
)
"發送成功"
else
when
(
errorCode
)
{
MessageBuilder
.
ERROR_CODE_SEND_TIMEOUT
->
"發送消息超時"
MessageBuilder
.
ERROR_CODE_NOT_CONNECT
->
"未連接到服務器"
MessageBuilder
.
ERROR_CODE_CONNECT_TIMEOUT
->
"連接服務器超時"
else
->
"發生錯誤:$errorCode"
}
tvSendValue
.
text
=
if
(
status
)
"發送成功"
else
"發生錯誤:$errorMessage"
}
}
})
...
...
mylibrary/build.gradle.kts
View file @
46f40b6b
...
...
@@ -9,7 +9,7 @@ android {
compileSdk = 34
defaultConfig {
minSdk =
24
minSdk =
19
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
...
...
mylibrary/src/main/java/com/gingersoft/connect/SendCallback.kt
View file @
46f40b6b
package
com.gingersoft.connect
interface
SendCallback
{
fun
callback
(
status
:
Boolean
,
errorCode
:
Int
)
fun
callback
(
status
:
Boolean
,
errorCode
:
Int
,
errorMessage
:
String
)
}
\ No newline at end of file
mylibrary/src/main/java/com/gingersoft/connect/bean/MessageBuilder.kt
View file @
46f40b6b
package
com.gingersoft.connect.bean
import
com.gingersoft.connect.utils.GingerSoftConnect
import
com.gingersoft.connect.utils.GsonUtils
import
com.gingersoft.connect.utils.MyWebSocketClient
import
java.util.concurrent.atomic.AtomicInteger
...
...
@@ -14,12 +15,14 @@ class MessageBuilder(
const
val
ERROR_CODE_SEND_TIMEOUT
=
100
const
val
ERROR_CODE_NOT_CONNECT
=
101
const
val
ERROR_CODE_CONNECT_TIMEOUT
=
102
const
val
ERROR_CODE_ORDER_INFO_INCORRECT
=
103
// 訂單信息有誤
const
val
ERROR_CODE_DATA_NULL
=
104
// 获取到的数据为null
const
val
ERROR_CODE_ANALYSIS_FAILED
=
105
// 數據解析失敗
}
fun
initSendData
(
action
:
Action
,
sendData
:
SendMsgType
):
MessageSender
{
val
currentMsgCode
=
msgCode
.
incrementAndGet
()
val
msg
=
MessageBean
(
currentMsgCode
,
action
.
toString
(),
sendData
)
val
msg
=
MessageBean
(
currentMsgCode
,
action
.
toString
(),
GsonUtils
.
GsonString
(
sendData
)
)
return
MessageSender
(
connect
,
webSocketClient
,
msg
)
}
...
...
mylibrary/src/main/java/com/gingersoft/connect/bean/MessageSender.kt
View file @
46f40b6b
package
com.gingersoft.connect.bean
import
android.os.Build.VERSION_CODES.P
import
android.util.Log
import
com.gingersoft.connect.SendCallback
import
com.gingersoft.connect.utils.GingerSoftConnect
import
com.gingersoft.connect.utils.GsonUtils
...
...
@@ -52,7 +50,7 @@ class MessageSender(
send
(
callback
)
}
else
{
// 超時
callback
?.
callback
(
false
,
MessageBuilder
.
ERROR_CODE_CONNECT_TIMEOUT
)
callback
?.
callback
(
false
,
MessageBuilder
.
ERROR_CODE_CONNECT_TIMEOUT
,
"連接超時"
)
}
}
}
...
...
@@ -61,7 +59,7 @@ class MessageSender(
private
fun
send
(
callback
:
SendCallback
?)
{
if
(
webSocketClient
.
isClosed
||
webSocketClient
.
isClosing
||
!
webSocketClient
.
isOpen
)
{
callback
?.
callback
(
false
,
MessageBuilder
.
ERROR_CODE_NOT_CONNECT
)
callback
?.
callback
(
false
,
MessageBuilder
.
ERROR_CODE_NOT_CONNECT
,
"未連接設備"
)
}
else
{
webSocketClient
.
sendMsg
(
msg
.
code
.
toString
(),
GsonUtils
.
GsonString
(
msg
),
callback
)
}
...
...
mylibrary/src/main/java/com/gingersoft/connect/bean/OrderInfoBean.java
View file @
46f40b6b
...
...
@@ -9,6 +9,10 @@ public class OrderInfoBean implements SendMsgType {
*/
private
Long
orderId
;
/**
* 訂單編號
*/
private
String
orderNo
;
/**
* 訂單類型
*/
private
int
orderType
;
...
...
@@ -73,6 +77,14 @@ public class OrderInfoBean implements SendMsgType {
this
.
orderId
=
orderId
;
}
public
String
getOrderNo
()
{
return
orderNo
;
}
public
void
setOrderNo
(
String
orderNo
)
{
this
.
orderNo
=
orderNo
;
}
public
int
getOrderType
()
{
return
this
.
orderType
;
}
...
...
@@ -160,4 +172,12 @@ public class OrderInfoBean implements SendMsgType {
public
void
setPrintStatus
(
int
printStatus
)
{
this
.
printStatus
=
printStatus
;
}
public
List
<
FoodInfoBean
>
getFoodInfoBeanList
()
{
return
foodInfoBeanList
;
}
public
void
setFoodInfoBeanList
(
List
<
FoodInfoBean
>
foodInfoBeanList
)
{
this
.
foodInfoBeanList
=
foodInfoBeanList
;
}
}
mylibrary/src/main/java/com/gingersoft/connect/bean/SocketCallbackBean.kt
0 → 100644
View file @
46f40b6b
package
com.gingersoft.connect.bean
class
SocketCallbackBean
(
val
success
:
Boolean
,
val
statusCode
:
Int
,
val
msgCode
:
String
,
val
errorMsg
:
String
)
\ No newline at end of file
mylibrary/src/main/java/com/gingersoft/connect/utils/MyWebSocketClient.kt
View file @
46f40b6b
...
...
@@ -3,6 +3,7 @@ package com.gingersoft.connect.utils
import
android.util.Log
import
com.gingersoft.connect.SendCallback
import
com.gingersoft.connect.bean.MessageBuilder
import
com.gingersoft.connect.bean.SocketCallbackBean
import
kotlinx.coroutines.channels.Channel
import
org.java_websocket.client.WebSocketClient
import
org.java_websocket.handshake.ServerHandshake
...
...
@@ -27,14 +28,14 @@ class MyWebSocketClient(
}
override
fun
onMessage
(
message
:
String
?)
{
val
bean
=
GsonUtils
.
GsonToBean
(
message
,
SocketCallbackBean
::
class
.
java
)
Log
.
e
(
"eeeaaa"
,
"客戶端收到消息:$message"
)
if
(
message
!=
null
&&
map
.
containsKey
(
messag
e
))
{
map
[
message
]
?.
callback
(
true
,
200
)
if
(
bean
!=
null
&&
map
.
containsKey
(
bean
.
msgCod
e
))
{
map
[
message
]
?.
callback
(
bean
.
success
,
bean
.
statusCode
,
bean
.
errorMsg
)
timerMap
[
message
]
?.
cancel
()
}
}
override
fun
onClose
(
code
:
Int
,
reason
:
String
?,
remote
:
Boolean
)
{
listener
?.
onClose
(
code
,
reason
,
remote
)
status
=
2
...
...
@@ -54,7 +55,11 @@ class MyWebSocketClient(
timerMap
[
msgCode
]
=
Timer
()
timerMap
[
msgCode
]
?.
schedule
(
object
:
TimerTask
()
{
override
fun
run
()
{
callback
.
callback
(
false
,
MessageBuilder
.
ERROR_CODE_SEND_TIMEOUT
)
callback
.
callback
(
false
,
MessageBuilder
.
ERROR_CODE_SEND_TIMEOUT
,
"接收服務端響應超時"
)
}
},
10000
)
}
...
...
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