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
a79befc2
Commit
a79befc2
authored
Aug 10, 2024
by
王宇航
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.6.1
1、調整一下,更靈活,但是對接必須按順序來調用方法
parent
307257db
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
42 deletions
+41
-42
mylibrary/src/main/java/com/gingersoft/connect/utils/GingerSoftConnect.kt
+35
-0
mylibrary/src/main/java/com/gingersoft/connect/utils/NSDUtils.kt
+6
-3
mylibrary/src/main/java/com/gingersoft/connect/utils/SoldOut.kt
+0
-39
No files found.
mylibrary/src/main/java/com/gingersoft/connect/utils/GingerSoftConnect.kt
View file @
a79befc2
package
com.gingersoft.connect.utils
import
android.content.Context
import
com.gingersoft.connect.bean.MessageBuilder
import
java.net.InetSocketAddress
import
java.net.URI
class
GingerSoftConnect
{
...
...
@@ -32,4 +34,36 @@ class GingerSoftConnect {
fun
onError
(
ex
:
Exception
?)
{}
}
/**
* 接收數據的服務
*/
private
var
mWebSocketServer
:
MyWebSocketServer
?
=
null
private
var
nsdUtils
:
NSDUtils
?
=
null
fun
registerDiscoveryService
(
context
:
Context
)
{
// 註冊NSD,讓後面開啟的KDS能主動找到POS設備,然後從POS設備拿食品信息
nsdUtils
=
NSDUtils
()
nsdUtils
?.
registerKDS
(
context
)
}
fun
startMsgReceiveService
()
{
// 開啟服務,接收KDS發來的消息
mWebSocketServer
=
MyWebSocketServer
(
InetSocketAddress
(
12581
))
mWebSocketServer
?.
isReuseAddr
=
true
// 設置地址可複用,避免APP被用戶強制殺掉後,再次打開報錯Address already in use
mWebSocketServer
?.
start
()
}
/**
* 插入自己的數據處理類
* 目前系統有的都在Action中,以後新增功能,不需要改這個庫,在KDS和POS端調整即可
*/
fun
inputTransmitter
(
type
:
String
,
process
:
MsgProcess
)
{
MsgParser
.
parserMap
[
type
]
=
process
}
fun
unregisterDiscoveryService
()
{
mWebSocketServer
?.
stop
()
}
}
\ No newline at end of file
mylibrary/src/main/java/com/gingersoft/connect/utils/NSDUtils.kt
View file @
a79befc2
...
...
@@ -18,12 +18,15 @@ class NSDUtils {
fun
registerKDS
(
context
:
Context
)
{
val
nsdManager
=
context
.
getSystemService
(
Context
.
NSD_SERVICE
)
as
NsdManager
// 先註銷之前的
unregisterService
(
context
)
val
serviceInfo
=
NsdServiceInfo
()
serviceInfo
.
serviceName
=
serviceName
serviceInfo
.
serviceType
=
serviceType
serviceInfo
.
port
=
1258
3
serviceInfo
.
port
=
1258
2
registrationListener
=
NSDRegistrationListener
()
// 註冊,這樣KDS才能收到
nsdManager
.
registerService
(
serviceInfo
,
NsdManager
.
PROTOCOL_DNS_SD
,
...
...
@@ -59,12 +62,12 @@ class NSDUtils {
}
}
fun
unregisterService
(
context
:
Context
)
{
private
fun
unregisterService
(
context
:
Context
)
{
if
(
registrationListener
!=
null
&&
registrationListener
!!
.
isRegistered
)
{
try
{
val
nsdManager
=
context
.
getSystemService
(
Context
.
NSD_SERVICE
)
as
NsdManager
nsdManager
.
unregisterService
(
registrationListener
)
}
catch
(
e
:
IllegalArgumentException
)
{
}
catch
(
_
:
IllegalArgumentException
)
{
}
finally
{
registrationListener
=
null
...
...
mylibrary/src/main/java/com/gingersoft/connect/utils/SoldOut.kt
deleted
100644 → 0
View file @
307257db
package
com.gingersoft.connect.utils
import
android.content.Context
import
com.gingersoft.connect.bean.Action
import
com.gingersoft.connect.bean.GetFoodInfoProcess
import
com.gingersoft.connect.bean.GetSoldOutInfoProcess
import
java.net.InetSocketAddress
object
SoldOut
{
/**
* 接收數據的服務
*/
private
var
mWebSocketServer
:
MyWebSocketServer
?
=
null
private
var
nsdUtils
:
NSDUtils
?
=
null
fun
init
(
context
:
Context
)
{
// 註冊NSD,讓後面開啟的KDS能主動找到POS設備,然後從POS設備拿食品信息
nsdUtils
=
NSDUtils
()
nsdUtils
?.
registerKDS
(
context
)
// 開啟服務,接收KDS發來的消息
mWebSocketServer
=
MyWebSocketServer
(
InetSocketAddress
(
12581
))
mWebSocketServer
?.
isReuseAddr
=
true
// 設置地址可複用,避免APP被用戶強制殺掉後,再次打開報錯Address already in use
mWebSocketServer
?.
start
()
}
fun
initFoodInfoTransmitter
(
process
:
GetFoodInfoProcess
)
{
MsgParser
.
parserMap
[
Action
.
FoodInfo
.
toString
()]
=
process
}
fun
initSoldOutInfoTransmitter
(
process
:
GetSoldOutInfoProcess
)
{
MsgParser
.
parserMap
[
Action
.
SoldOutInfo
.
toString
()]
=
process
}
fun
stopServer
()
{
mWebSocketServer
?.
stop
()
}
}
\ No newline at end of file
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