Browse Source

更新TCP及文件操作

module-tcpserver-mqtt-t4j-faceSDK
zmt 3 years ago
parent
commit
482581370d
  1. 31
      uniappWWW/unipluginDemo/utils/8inFileOperate.js
  2. 7
      uniappWWW/unipluginDemo/utils/download.js
  3. 16
      zmt_module/src/main/java/io/dcloud/zmt_module/tcpServer/TCPTask.java
  4. 5
      zmt_module/src/main/java/io/dcloud/zmt_module/tcpServer/TcpServer.java

31
uniappWWW/unipluginDemo/utils/8inFileOperate.js

@ -1,6 +1,13 @@
import downloadImg from "./download.js"
/*
*V1.0
*基于5+ IO 封装的基础文件操作库 业务函数 为人脸识别操作提供文件处理功能
*使用范围:(7in,8in)Android 11 Pad
*更新日期:2022/06/09
*/
/*
fileName: 需要查询的目录名
*/
async function getFileChildrenList(fileName){
@ -20,6 +27,7 @@ async function getFileChildrenList(fileName){
fileName: 需要删除的文件名
*/
async function deleteAndroidFaceImage(fileName){
console.log("deleteAndroidFaceImage:",fileName)
let item = {
"deleteFile" : true,
"name": fileName
@ -60,6 +68,9 @@ async function deleteAndroidFaceImage(fileName){
*/
async function downloadFileList(res){
// await asyncSetTimeOut(3000) //延时,手动断网,模拟下载失败
let clearUNI = await clearUniDownloadFace();
console.log("清空doc结果:",clearUNI)
return new Promise(async(rs,rj)=>{
let {list,request_time,total} = res
console.log(request_time,total);
@ -183,7 +194,7 @@ async function downloadFileImg(item) {
}
let reNamePathEntry = await downloadImg.moveFileTo(savedFilePathEntry, faceSyncEntry, newName); //重命名文件到人脸库同步文件夹
// console.log(savedFilePath,newName,reNamePathEntry.fullPath)
console.log("重命名后:",savedFilePath,newName,reNamePathEntry.fullPath)
return reNamePathEntry.fullPath;
}
@ -212,6 +223,24 @@ async function clearDownloadFace(fileName){
console.log(fileName,"删除:",e);
})
}
//递归清空本地临时下载目录及子目录
async function clearUniDownloadFace(){
let fs = await downloadImg.requestFileSystem(plus.io.PRIVATE_DOC); //获取所要操作根目录File System
// let faceSyncEntry = await downloadImg.getDirectory({
// //在PUBLIC_DOWNLOADS下定义人脸库同步文件夹[fileName]
// OriginPathEntry: fs.root,
// newFileName: fileName
// });
// let newNameFileEntry = await downloadImg.resolveLocalFileSystemURL(faceSyncEntry.fullPath).catch(
// e => {
// console.log('操作目标文件', e);
// });
await downloadImg.removeFileAll(fs).then(e=>{
console.log("删除uni _Doc缓存文件:",e);
})
}
module.exports = {
downloadFileImg,
clearDownloadFace,

7
uniappWWW/unipluginDemo/utils/download.js

@ -1,3 +1,10 @@
/*
*V1.0
*基于5+ IO 封装的基础文件操作库
*更新日期:2022/06/09
*/
let downloadTask;

16
zmt_module/src/main/java/io/dcloud/zmt_module/tcpServer/TCPTask.java

@ -34,6 +34,11 @@ public class TCPTask {
public void task(final Integer port, final UniJSCallback uniJSCallback){
// System.out.println("AsyncTask thread running... ==>>>44444444:"+port+ server.isServerBound());
System.out.println("task666:"+port+ server);
if(server!=null){
return;
}
this.server = new TcpServer();
// this.server = server.initSocket(port,uniJSCallback);
@ -69,19 +74,16 @@ public class TCPTask {
// myCallback.tcpCallback(data);
// myTcpCallback.tcpCallback(data);//回调到zmtClass给uni端
uniJSCallback.invokeAndKeepAlive(data);
try {
Thread.sleep(100); //定义休眠时间
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(TAG+"已回调给UNI信息:"+data.toJSONString());
}else{
}
try {
Thread.sleep(1000); //定义休眠时间
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

5
zmt_module/src/main/java/io/dcloud/zmt_module/tcpServer/TcpServer.java

@ -206,6 +206,11 @@ public class TcpServer {
Runnable mRunnable = new Runnable() {
@Override
public void run() {
if(mServer==null){
return;
}
System.out.println(TAG+"TCP mServer :"+mServer);
try {
mOutStream = mServer.getOutputStream();
mPrinter = new PrintWriter(new OutputStreamWriter(mOutStream,Charset.forName(charsetName)));

Loading…
Cancel
Save