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
568f96b1
authored
Mar 13, 2020
by
pye52
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加指令执行过程中的日志输出
parent
f9ec85fc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
1 deletions
+20
-1
app/src/main/java/com/bgycc/smartcanteen/command/LogCommandHandler.java
+10
-1
app/src/main/java/com/bgycc/smartcanteen/command/WifiConfigCommandHandler.java
+7
-0
app/src/main/java/com/bgycc/smartcanteen/viewModel/CommandViewModel.java
+3
-0
No files found.
app/src/main/java/com/bgycc/smartcanteen/command/LogCommandHandler.java
View file @
568f96b1
...
...
@@ -69,6 +69,7 @@ public class LogCommandHandler extends CommandHandler {
}
catch
(
ParseException
e
)
{
LogUtils
.
w
(
TAG
,
"日志上传,结束时间解析失败: "
+
data
.
toString
(),
e
);
}
LogUtils
.
d
(
TAG
,
"筛选从"
+
startTime
.
toString
()
+
"到"
+
endTime
.
toString
()
+
"的日志文件"
);
}
// 检查传入的指定日期是否合法
...
...
@@ -114,6 +115,7 @@ public class LogCommandHandler extends CommandHandler {
}
else
{
logDir
=
new
File
(
LogUtils
.
getConfig
().
getDir
());
}
LogUtils
.
d
(
TAG
,
"待上传日志文件类型: "
+
logType
);
return
logDir
;
}
...
...
@@ -124,6 +126,7 @@ public class LogCommandHandler extends CommandHandler {
FileUtils
.
delete
(
dir
);
}
boolean
result
=
dir
.
mkdirs
();
LogUtils
.
d
(
TAG
,
"临时目录创建"
+
(
result
?
"成功"
:
"失败"
));
if
(
result
)
{
return
dir
;
}
else
{
...
...
@@ -139,11 +142,16 @@ public class LogCommandHandler extends CommandHandler {
List
<
File
>
logFiles
=
FileUtils
.
listFilesInDirWithFilter
(
src
,
filter
,
false
,
null
);
boolean
copyResult
=
true
;
wait
(
"筛选目标日志文件"
,
10
);
int
count
=
0
;
File
descFile
;
boolean
tempCopyResult
;
for
(
File
file
:
logFiles
)
{
descFile
=
new
File
(
descDir
,
file
.
getName
());
copyResult
=
copyResult
&&
FileUtils
.
copy
(
file
,
descFile
);
tempCopyResult
=
FileUtils
.
copy
(
file
,
descFile
);
copyResult
=
copyResult
&&
tempCopyResult
;
if
(
tempCopyResult
)
count
++;
}
LogUtils
.
d
(
TAG
,
"待上传日志文件总数: "
+
logFiles
.
size
()
+
", 复制成功文件总数: "
+
count
);
return
!
logFiles
.
isEmpty
()
&&
copyResult
;
}
...
...
@@ -156,6 +164,7 @@ public class LogCommandHandler extends CommandHandler {
"_"
+
format
.
format
(
endTime
)
+
"_"
+
deviceSN
+
".zip"
;
fileNameForServer
=
fileNameForServer
.
replace
(
" "
,
"_"
);
LogUtils
.
d
(
TAG
,
"开始上传日志: "
+
fileNameForServer
);
RequestBody
requestBody
=
RequestBody
.
create
(
zip
,
MediaType
.
parse
(
"application/x-zip-compressed"
));
MultipartBody
.
Part
body
=
MultipartBody
.
Part
.
createFormData
(
"file"
,
fileNameForServer
,
requestBody
);
try
{
...
...
app/src/main/java/com/bgycc/smartcanteen/command/WifiConfigCommandHandler.java
View file @
568f96b1
...
...
@@ -6,8 +6,11 @@ import com.bgycc.smartcanteen.entity.Command;
import
com.bgycc.smartcanteen.entity.CommandResponse
;
import
com.bgycc.smartcanteen.entity.CommandWifiConfig
;
import
com.bgycc.smartcanteen.utils.NetworkUtils
;
import
com.blankj.utilcode.util.LogUtils
;
import
com.google.gson.Gson
;
import
static
com
.
bgycc
.
smartcanteen
.
utils
.
SmartCanteenUtils
.
TAG
;
public
class
WifiConfigCommandHandler
extends
CommandHandler
{
private
static
final
long
DEFAULT_DELAY
=
3000
;
private
static
final
long
POLLING_DELAY
=
100
;
...
...
@@ -28,6 +31,7 @@ public class WifiConfigCommandHandler extends CommandHandler {
if
(!
NetworkUtils
.
setEnable
(
true
))
{
String
failedMessage
=
"无法启动Wifi"
;
wait
(
failedMessage
,
5
);
LogUtils
.
e
(
TAG
,
failedMessage
);
Thread
.
sleep
(
DEFAULT_DELAY
);
return
failedResult
(
failedMessage
);
}
...
...
@@ -39,6 +43,7 @@ public class WifiConfigCommandHandler extends CommandHandler {
String
type
=
data
.
getType
();
wait
(
"正在配置Wifi"
,
10
);
LogUtils
.
d
(
TAG
,
"开始配置wifi, ssid: "
+
ssid
+
", identity: "
+
identity
+
", pwd: "
+
pwd
+
", type: "
+
type
);
try
{
NetworkUtils
.
connect
(
ssid
,
identity
,
pwd
,
type
);
// 轮训检查wifi是否链接成功
...
...
@@ -50,10 +55,12 @@ public class WifiConfigCommandHandler extends CommandHandler {
}
String
message
=
"Wifi配置成功"
;
wait
(
message
,
50
);
LogUtils
.
d
(
TAG
,
message
);
Thread
.
sleep
(
DEFAULT_DELAY
);
return
successResult
(
message
);
}
}
catch
(
Exception
e
)
{
LogUtils
.
e
(
TAG
,
"链接wifi过程出错: "
+
e
.
getMessage
(),
e
);
Thread
.
sleep
(
DEFAULT_DELAY
);
return
failedResult
(
e
.
getMessage
());
}
...
...
app/src/main/java/com/bgycc/smartcanteen/viewModel/CommandViewModel.java
View file @
568f96b1
...
...
@@ -125,6 +125,7 @@ public class CommandViewModel extends ViewModel implements CommandProgressCallba
@Override
public
void
run
()
{
CommandHandler
handler
=
null
;
LogUtils
.
d
(
TAG
,
"开始执行指令: "
+
command
.
toString
());
try
{
switch
(
command
.
getAction
())
{
case
Command
.
LOG_UPLOAD
:
...
...
@@ -155,6 +156,7 @@ public class CommandViewModel extends ViewModel implements CommandProgressCallba
commandState
.
postValue
(
new
CommandState
(
CommandState
.
WAIT
));
CommandResponse
response
=
handler
.
run
();
if
(
response
==
null
)
{
LogUtils
.
d
(
TAG
,
"指令无返回结果"
);
return
;
}
if
(
response
.
success
())
{
...
...
@@ -177,6 +179,7 @@ public class CommandViewModel extends ViewModel implements CommandProgressCallba
LogUtils
.
w
(
TAG
,
e
.
getMessage
(),
e
);
}
finally
{
command
.
finish
();
LogUtils
.
d
(
TAG
,
"指令执行完毕: "
+
command
.
toString
());
commandRepository
.
updateCommand
(
command
);
}
}
...
...
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