Commit 568f96b1 by pye52

增加指令执行过程中的日志输出

parent f9ec85fc
...@@ -69,6 +69,7 @@ public class LogCommandHandler extends CommandHandler { ...@@ -69,6 +69,7 @@ public class LogCommandHandler extends CommandHandler {
} catch (ParseException e) { } catch (ParseException e) {
LogUtils.w(TAG, "日志上传,结束时间解析失败: " + data.toString(), e); LogUtils.w(TAG, "日志上传,结束时间解析失败: " + data.toString(), e);
} }
LogUtils.d(TAG, "筛选从" + startTime.toString() + "到" + endTime.toString() + "的日志文件");
} }
// 检查传入的指定日期是否合法 // 检查传入的指定日期是否合法
...@@ -114,6 +115,7 @@ public class LogCommandHandler extends CommandHandler { ...@@ -114,6 +115,7 @@ public class LogCommandHandler extends CommandHandler {
} else { } else {
logDir = new File(LogUtils.getConfig().getDir()); logDir = new File(LogUtils.getConfig().getDir());
} }
LogUtils.d(TAG, "待上传日志文件类型: " + logType);
return logDir; return logDir;
} }
...@@ -124,6 +126,7 @@ public class LogCommandHandler extends CommandHandler { ...@@ -124,6 +126,7 @@ public class LogCommandHandler extends CommandHandler {
FileUtils.delete(dir); FileUtils.delete(dir);
} }
boolean result = dir.mkdirs(); boolean result = dir.mkdirs();
LogUtils.d(TAG, "临时目录创建" + (result ? "成功" : "失败"));
if (result) { if (result) {
return dir; return dir;
} else { } else {
...@@ -139,11 +142,16 @@ public class LogCommandHandler extends CommandHandler { ...@@ -139,11 +142,16 @@ public class LogCommandHandler extends CommandHandler {
List<File> logFiles = FileUtils.listFilesInDirWithFilter(src, filter, false, null); List<File> logFiles = FileUtils.listFilesInDirWithFilter(src, filter, false, null);
boolean copyResult = true; boolean copyResult = true;
wait("筛选目标日志文件", 10); wait("筛选目标日志文件", 10);
int count = 0;
File descFile; File descFile;
boolean tempCopyResult;
for (File file : logFiles) { for (File file : logFiles) {
descFile = new File(descDir, file.getName()); 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; return !logFiles.isEmpty() && copyResult;
} }
...@@ -156,6 +164,7 @@ public class LogCommandHandler extends CommandHandler { ...@@ -156,6 +164,7 @@ public class LogCommandHandler extends CommandHandler {
"_" + format.format(endTime) + "_" + format.format(endTime) +
"_" + deviceSN + ".zip"; "_" + deviceSN + ".zip";
fileNameForServer = fileNameForServer.replace(" ", "_"); fileNameForServer = fileNameForServer.replace(" ", "_");
LogUtils.d(TAG, "开始上传日志: " + fileNameForServer);
RequestBody requestBody = RequestBody.create(zip, MediaType.parse("application/x-zip-compressed")); RequestBody requestBody = RequestBody.create(zip, MediaType.parse("application/x-zip-compressed"));
MultipartBody.Part body = MultipartBody.Part.createFormData("file", fileNameForServer, requestBody); MultipartBody.Part body = MultipartBody.Part.createFormData("file", fileNameForServer, requestBody);
try { try {
......
...@@ -6,8 +6,11 @@ import com.bgycc.smartcanteen.entity.Command; ...@@ -6,8 +6,11 @@ import com.bgycc.smartcanteen.entity.Command;
import com.bgycc.smartcanteen.entity.CommandResponse; import com.bgycc.smartcanteen.entity.CommandResponse;
import com.bgycc.smartcanteen.entity.CommandWifiConfig; import com.bgycc.smartcanteen.entity.CommandWifiConfig;
import com.bgycc.smartcanteen.utils.NetworkUtils; import com.bgycc.smartcanteen.utils.NetworkUtils;
import com.blankj.utilcode.util.LogUtils;
import com.google.gson.Gson; import com.google.gson.Gson;
import static com.bgycc.smartcanteen.utils.SmartCanteenUtils.TAG;
public class WifiConfigCommandHandler extends CommandHandler { public class WifiConfigCommandHandler extends CommandHandler {
private static final long DEFAULT_DELAY = 3000; private static final long DEFAULT_DELAY = 3000;
private static final long POLLING_DELAY = 100; private static final long POLLING_DELAY = 100;
...@@ -28,6 +31,7 @@ public class WifiConfigCommandHandler extends CommandHandler { ...@@ -28,6 +31,7 @@ public class WifiConfigCommandHandler extends CommandHandler {
if (!NetworkUtils.setEnable(true)) { if (!NetworkUtils.setEnable(true)) {
String failedMessage = "无法启动Wifi"; String failedMessage = "无法启动Wifi";
wait(failedMessage, 5); wait(failedMessage, 5);
LogUtils.e(TAG, failedMessage);
Thread.sleep(DEFAULT_DELAY); Thread.sleep(DEFAULT_DELAY);
return failedResult(failedMessage); return failedResult(failedMessage);
} }
...@@ -39,6 +43,7 @@ public class WifiConfigCommandHandler extends CommandHandler { ...@@ -39,6 +43,7 @@ public class WifiConfigCommandHandler extends CommandHandler {
String type = data.getType(); String type = data.getType();
wait("正在配置Wifi", 10); wait("正在配置Wifi", 10);
LogUtils.d(TAG, "开始配置wifi, ssid: " + ssid + ", identity: " + identity + ", pwd: " + pwd + ", type: " + type);
try { try {
NetworkUtils.connect(ssid, identity, pwd, type); NetworkUtils.connect(ssid, identity, pwd, type);
// 轮训检查wifi是否链接成功 // 轮训检查wifi是否链接成功
...@@ -50,10 +55,12 @@ public class WifiConfigCommandHandler extends CommandHandler { ...@@ -50,10 +55,12 @@ public class WifiConfigCommandHandler extends CommandHandler {
} }
String message = "Wifi配置成功"; String message = "Wifi配置成功";
wait(message, 50); wait(message, 50);
LogUtils.d(TAG, message);
Thread.sleep(DEFAULT_DELAY); Thread.sleep(DEFAULT_DELAY);
return successResult(message); return successResult(message);
} }
} catch (Exception e) { } catch (Exception e) {
LogUtils.e(TAG, "链接wifi过程出错: " + e.getMessage(), e);
Thread.sleep(DEFAULT_DELAY); Thread.sleep(DEFAULT_DELAY);
return failedResult(e.getMessage()); return failedResult(e.getMessage());
} }
......
...@@ -125,6 +125,7 @@ public class CommandViewModel extends ViewModel implements CommandProgressCallba ...@@ -125,6 +125,7 @@ public class CommandViewModel extends ViewModel implements CommandProgressCallba
@Override @Override
public void run() { public void run() {
CommandHandler handler = null; CommandHandler handler = null;
LogUtils.d(TAG, "开始执行指令: " + command.toString());
try { try {
switch (command.getAction()) { switch (command.getAction()) {
case Command.LOG_UPLOAD: case Command.LOG_UPLOAD:
...@@ -155,6 +156,7 @@ public class CommandViewModel extends ViewModel implements CommandProgressCallba ...@@ -155,6 +156,7 @@ public class CommandViewModel extends ViewModel implements CommandProgressCallba
commandState.postValue(new CommandState(CommandState.WAIT)); commandState.postValue(new CommandState(CommandState.WAIT));
CommandResponse response = handler.run(); CommandResponse response = handler.run();
if (response == null) { if (response == null) {
LogUtils.d(TAG, "指令无返回结果");
return; return;
} }
if (response.success()) { if (response.success()) {
...@@ -177,6 +179,7 @@ public class CommandViewModel extends ViewModel implements CommandProgressCallba ...@@ -177,6 +179,7 @@ public class CommandViewModel extends ViewModel implements CommandProgressCallba
LogUtils.w(TAG, e.getMessage(), e); LogUtils.w(TAG, e.getMessage(), e);
} finally { } finally {
command.finish(); command.finish();
LogUtils.d(TAG, "指令执行完毕: " + command.toString());
commandRepository.updateCommand(command); commandRepository.updateCommand(command);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment