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
69ae40f0
authored
May 20, 2020
by
pye52
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
删除冗余设计(不再需要响应服务器的check_device指令)
parent
fc38dd28
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
118 deletions
+0
-118
app/src/main/java/com/bgycc/smartcanteen/entity/CheckDevice.java
+0
-99
app/src/main/java/com/bgycc/smartcanteen/socket/SCWebSocketClient.java
+0
-19
No files found.
app/src/main/java/com/bgycc/smartcanteen/entity/CheckDevice.java
deleted
100644 → 0
View file @
fc38dd28
package
com
.
bgycc
.
smartcanteen
.
entity
;
import
java.util.Objects
;
public
class
CheckDevice
{
private
String
action
;
private
CheckDeviceData
data
;
private
long
serialNumber
;
public
CheckDevice
(
String
action
,
String
deviceSN
)
{
this
.
action
=
action
;
this
.
data
=
new
CheckDeviceData
(
deviceSN
);
this
.
serialNumber
=
System
.
currentTimeMillis
();
}
public
String
getAction
()
{
return
action
;
}
public
void
setAction
(
String
action
)
{
this
.
action
=
action
;
}
public
CheckDeviceData
getData
()
{
return
data
;
}
public
void
setData
(
CheckDeviceData
data
)
{
this
.
data
=
data
;
}
public
long
getSerialNumber
()
{
return
serialNumber
;
}
public
void
setSerialNumber
(
long
serialNumber
)
{
this
.
serialNumber
=
serialNumber
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
return
false
;
CheckDevice
that
=
(
CheckDevice
)
o
;
return
serialNumber
==
that
.
serialNumber
&&
Objects
.
equals
(
action
,
that
.
action
)
&&
Objects
.
equals
(
data
,
that
.
data
);
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
action
,
data
,
serialNumber
);
}
@Override
public
String
toString
()
{
return
"CheckDevice{"
+
"action='"
+
action
+
'\''
+
", data="
+
data
+
", serialNumber="
+
serialNumber
+
'}'
;
}
private
static
class
CheckDeviceData
{
private
String
equipmentId
;
private
CheckDeviceData
(
String
deviceSN
)
{
this
.
equipmentId
=
deviceSN
;
}
public
String
getEquipmentId
()
{
return
equipmentId
;
}
public
void
setEquipmentId
(
String
equipmentId
)
{
this
.
equipmentId
=
equipmentId
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
return
false
;
CheckDeviceData
that
=
(
CheckDeviceData
)
o
;
return
Objects
.
equals
(
equipmentId
,
that
.
equipmentId
);
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
equipmentId
);
}
@Override
public
String
toString
()
{
return
"CheckDeviceData{"
+
"equipmentId='"
+
equipmentId
+
'\''
+
'}'
;
}
}
}
app/src/main/java/com/bgycc/smartcanteen/socket/SCWebSocketClient.java
View file @
69ae40f0
...
...
@@ -3,13 +3,11 @@ package com.bgycc.smartcanteen.socket;
import
android.annotation.SuppressLint
;
import
android.net.ConnectivityManager
;
import
android.net.Network
;
import
android.text.TextUtils
;
import
androidx.annotation.NonNull
;
import
androidx.lifecycle.LiveData
;
import
androidx.lifecycle.MutableLiveData
;
import
com.bgycc.smartcanteen.entity.CheckDevice
;
import
com.bgycc.smartcanteen.entity.Heartbeat
;
import
com.bgycc.smartcanteen.executor.SCTaskExecutor
;
import
com.bgycc.smartcanteen.state.ConnectState
;
...
...
@@ -45,8 +43,6 @@ public class SCWebSocketClient extends WebSocketClient {
private
static
final
long
SWITCH_INTERVAL
=
10
*
1000
;
private
static
final
String
RESPONSE_ACTION
=
"action"
;
private
static
final
String
RESPONSE_DATA
=
"data"
;
private
static
final
String
CHECK_DEVICE
=
"CHECK_DEVICE"
;
private
static
SCWebSocketClient
instance
;
private
Gson
gson
;
...
...
@@ -169,21 +165,6 @@ public class SCWebSocketClient extends WebSocketClient {
if
(
jsonObject
.
has
(
RESPONSE_ACTION
))
{
action
=
jsonObject
.
get
(
RESPONSE_ACTION
).
getAsString
();
}
// 是否服务器下发的心跳通知(响应则告知服务器设备未断开链接)
if
(
action
.
equals
(
CHECK_DEVICE
))
{
String
data
=
""
;
if
(
jsonObject
.
has
(
RESPONSE_DATA
))
{
data
=
jsonObject
.
get
(
RESPONSE_DATA
).
getAsString
();
}
if
(!
TextUtils
.
isEmpty
(
data
))
{
CheckDevice
ack
=
new
CheckDevice
(
CHECK_DEVICE
,
data
);
String
requestStr
=
gson
.
toJson
(
ack
);
send
(
requestStr
);
}
// 该指令不需要向外通知Listener
LogUtils
.
d
(
TAG
,
"后台下发心跳包: "
+
response
);
return
;
}
LogUtils
.
d
(
TAG
,
"收到后台消息: "
+
response
);
for
(
SCWebSocketListener
l
:
listener
)
{
l
.
onMessage
(
action
,
jsonObject
,
response
);
...
...
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