Compare commits

..

No commits in common. "9e7e1fc4e9c432a837439aaeb9b646b1f1b1446e" and "30255599e1cd73690937149a2cdbcd0e37015221" have entirely different histories.

6 changed files with 42 additions and 104 deletions

View File

@ -446,10 +446,6 @@ function setSyncCenterSqlData(key, res, param) {
console.log('mapName[key]', mapName[key], key)
sqlInsertCommonFn(mapName[key], arrList, param.context).then((result) => {
console.log(key, '表建立成功')
writeLog('PLC',{
time:dateFormat(new Date()),
PLC:`${key} 表建立成功`,
})
if (result) {
resolve(true)
} else {

View File

@ -2,8 +2,6 @@ import socket from '@ohos.net.socket';
import hilog from '@ohos.hilog';
import { getTCP } from './GlobalTcp';
import prompt from '@ohos.prompt';
import FileUtil from './File';
import { dateFormat } from './tools';
const TAG = 'socketTag[TcpDemo.TcpClient]'
@ -27,10 +25,6 @@ export default class TcpClient {
onError(callback?) {
this.tcp.on('error', err => {
this.writeLog({
time:dateFormat(new Date()),
PLC:`${TAG} tcpOnerror ${JSON.stringify(err)}`,
})
console.log(TAG, 'tcpOnerror', JSON.stringify(err))
setTimeout(async () => {
getTCP()
@ -78,10 +72,6 @@ export default class TcpClient {
address: this.localIp, port: parseInt(this.localIpPort), family: 1
}, err => {
if (err) {
this.writeLog({
time:dateFormat(new Date()),
PLC:`${TAG} testTag tcp bind faile ${JSON.stringify(err)}`,
})
console.log('testTag tcp bind faile');
globalThis.getCloseTcp = true
hilog.info(0x0000, 'testTag', "tcpBinderror:" + JSON.stringify(err));
@ -90,10 +80,6 @@ export default class TcpClient {
}
globalThis.getCloseTcp = false
console.log('testTag tcp bind success');
this.writeLog({
time:dateFormat(new Date()),
PLC:`${TAG} testTag tcp bind success`,
})
resolve(false)
})
})
@ -122,10 +108,7 @@ export default class TcpClient {
keepAlive: true,
}, err => {
if (err) {
this.writeLog({
time:dateFormat(new Date()),
PLC:`${TAG} tcp connect rebind success`,
})
console.log('testTagtestTag000,error')
if(this.num>3){
return
}
@ -150,10 +133,8 @@ export default class TcpClient {
getTCP()
resolve(false)
}, 2000)
this.writeLog({
time:dateFormat(new Date()),
PLC:`${TAG} tcp connect error`,
})
console.log('testTagtestTag000,error')
});
})
}
@ -174,10 +155,6 @@ export default class TcpClient {
onMessage(callback?) {
this.tcp.on('message', value => {
this.writeLog({
time:dateFormat(new Date()),
PLC:`${TAG} Tcponmessage`,
})
console.log(TAG, 'Tcponmessage', value)
globalThis.tcpUdpError = false
@ -211,13 +188,7 @@ export default class TcpClient {
// callback(value.message)
});
}
async writeLog(param){
const fileUtil = new FileUtil(globalThis.context)
const date=dateFormat(new Date).split(' ')[0]
const folderPath = await fileUtil.initFolder(`/PLC/${date}`);
fileUtil.editFile(`${folderPath}/plcLog.txt`, JSON.stringify(param)+`\n`)
}
offTcp(callback) {
console.log(TAG, 'tcpofff')

View File

@ -86,17 +86,9 @@ export default class UdpClientByCenter {
// globalThis.closeHeartSocket=false
this.isWorking = true
console.log(`${TAG} getUDPudp rebind success`);
this.writeLog({
time:dateFormat(new Date()),
PLC:`${TAG} getUDPudp rebind success`,
})
}).catch(err => {
//globalThis.closeHeartSocket=true
this.isWorking = false
this.writeLog({
time:dateFormat(new Date()),
PLC:`${TAG} getUDPudp rebind failed:${JSON.stringify(err)}`,
})
console.log(`${TAG} getUDPudp rebind failed:${JSON.stringify(err)}`);
});
}
@ -107,16 +99,10 @@ export default class UdpClientByCenter {
});
promise.then(() => {
this.isWorking = true
this.writeLog({
time:dateFormat(new Date()),
PLC:`${TAG} getUDPudp bind success`,
})
console.log(`${TAG} getUDPudp bind success`);
}).catch(err => {
this.isWorking = false
this.writeLog({
time:dateFormat(new Date()),
PLC:`${TAG} getUDPudp bind error${JSON.stringify(err)},localIp:${this.localIpPort},port:${this.localIpPort}`,
})
console.log(`${TAG} getUDPudp bind failed:${JSON.stringify(err)}`);
});
}
@ -180,12 +166,9 @@ export default class UdpClientByCenter {
sendMsg(msg, sendCallback?)
{
console.log(`${TAG}getUDPudpCLient sendMsg enter oppositeIp:${this.oppositeIp},oppositeIpPort:${this.oppositeIpPort},localIp:${this.localIp},localIpPort:${this.localIpPort}`);
if (!this.isWorking ) {
console.log(`${TAG}getUDPudpCLient sendMsg is closed return `);
this.writeLog({
time:dateFormat(new Date()),
PLC:`${TAG}getUDPudpCLient sendMsg is closed return oppositeIp:${this.oppositeIp},oppositeIpPort:${this.oppositeIpPort},localIp:${this.localIp},localIpPort:${this.localIpPort}`,
})
if(sendCallback) {
sendCallback()
}
@ -202,15 +185,9 @@ export default class UdpClientByCenter {
if (sendCallback) {
sendCallback()
}
this.writeLog({
time:dateFormat(new Date()),
PLC:`${TAG}getUDPudpCLient udp send success: oppositeIp:${this.oppositeIp},oppositeIpPort:${this.oppositeIpPort},localIp:${this.localIp},localIpPort:${this.localIpPort}`,
})
console.log(`${TAG}getUDPudpCLient udp send success:oppositeIp${this.oppositeIp},oppositeIpPort:${this.oppositeIpPort},localIp:${this.localIp},localIpPort,${this.localIpPort}`);
}).catch(err => {
this.writeLog({
time:dateFormat(new Date()),
PLC:`${TAG}getUDPudpCLient udp send fail:oppositeIp${this.oppositeIp},oppositeIpPort:${this.oppositeIpPort},localIp:${this.localIp},localIpPort,${this.localIpPort}${JSON.stringify(err)}`,
})
console.log(`${TAG}getUDPudpCLient udp send fail:oppositeIp${this.oppositeIp},oppositeIpPort:${this.oppositeIpPort},localIp:${this.localIp},localIpPort,${this.localIpPort}`);
promptAction.showToast({
message:`${TAG}getUDPudpCLient udp send fail:oppositeIp${this.oppositeIp},oppositeIpPort:${this.oppositeIpPort},localIp:${this.localIp},localIpPort,${this.localIpPort}`,
duration:4000
@ -231,10 +208,7 @@ export default class UdpClientByCenter {
onError_Callback(callback?) {
this.udp.on('error', async err => {
this.isWorking = false;
this.writeLog({
time:dateFormat(new Date()),
PLC:'getUDPUdpClientByCenter onError err:' + JSON.stringify(err)+this.oppositeIpPort,
})
console.log('getUDPUdpClientByCenter onError err:' + JSON.stringify(err),this.oppositeIpPort);
callback && callback()
});
}
@ -242,7 +216,10 @@ export default class UdpClientByCenter {
onError_resend(callback?) {
this.udp.on('error', async err => {
this.isWorking = false;
console.log(TAG, 'getUDPudpError', JSON.stringify(err))
await this.bindUdp()
await this.sendMsg('111', null)
await this.onMessage_1(callback)
callback && callback()
});
}
@ -288,19 +265,13 @@ export default class UdpClientByCenter {
console.log('getUDPUdpClientByCenter enter closeUdp ip:' + this.localIp + ' port:' + this.localIpPort);
this.udp.close(err => {
if (err) {
this.writeLog({
time:dateFormat(new Date()),
PLC:'getUDPUdpClientByCenter closeUdp err:' + JSON.stringify(err)+this.oppositeIpPort,
})
console.log('getUDPUdpClientByCenter closeUdp failed ip:' + this.localIp + ' port:' + this.localIpPort + ' err:' + JSON.stringify(err));
} else {
this.isWorking = false
if (callback != null) {
callback()
}
this.writeLog({
time:dateFormat(new Date()),
PLC:'getUDPUdpClientByCenter closeUdp succeed:' + JSON.stringify(err)+this.oppositeIpPort,
})
console.log('getUDPUdpClientByCenter closeUdp succeed ip:' + this.localIp + ' port:' + this.localIpPort);
}
})
}

View File

@ -70,7 +70,11 @@ export default async function request(req: any) {
if(res.head.resultCode === '0'){
return res
}else{
globalThis.type='1'
const resultMessage = res?.body?.resultMessage || res?.head?.resultMessage
// AppStorage.SetOrCreate('errorMsg', 1);
globalThis.title=decodeURIComponent(resultMessage)
globalThis.errorDialog.open()
prompt.showToast({
message: decodeURIComponent(resultMessage),
duration: 3000
@ -85,6 +89,14 @@ export default async function request(req: any) {
if(resObj.resultCode === '0') {
return res
}else {
globalThis.type='1'
if(!host){
// AppStorage.SetOrCreate('errorMsg', 1);
globalThis.title=decodeURIComponent(resObj.resultMessage)
globalThis.errorDialog.open()
}
prompt.showToast({
message: decodeURIComponent(resObj.resultMessage),
duration: 3000
@ -150,9 +162,8 @@ function handleCenterCode(msgXml,isNewCenter){
const {code,message,keystr} = result
if(code != '1'){
const rMessage = decodeURIComponent(message as string)
// globalThis.title=rMessage
// globalThis.type='1'
// globalThis.errorDialog.open()
globalThis.title=rMessage
globalThis.errorDialog.open()
prompt.showToast({
message:rMessage,
duration: 3000
@ -175,9 +186,8 @@ function handleCenterCode(msgXml,isNewCenter){
message: decodeURIComponent(message as string),
duration: 3000
});
// globalThis.type='1'
// globalThis.title=decodeURIComponent(message as string)
// globalThis.errorDialog.open()
globalThis.title=decodeURIComponent(message as string)
globalThis.errorDialog.open()
return {code,message:decodeURIComponent(message)}
}else{
return { code }

View File

@ -1,14 +1,7 @@
//@ts-ignore
import systemTime from '@ohos.systemDateTime';
import { expect } from '@ohos/hypium';
import FileUtil from './File';
export async function writeLog(path,param){
const fileUtil = new FileUtil(globalThis.context)
const date=dateFormat(new Date).split(' ')[0]
const folderPath = await fileUtil.initFolder(`/${path}/${date}`);
fileUtil.editFile(`${folderPath}/plcLog.txt`, JSON.stringify(param)+`\n`)
}
///**时间格式化*/
//export function dateFormat(fmt, date) {
// var ret;

View File

@ -18,8 +18,6 @@ import { voiceService } from '../common/service/voiceService';
import errorMsgDialog from './compontents/errorMsgDialog'
import { getSyncData } from '../common/service/initable';
import GetDistance from '../common/utils/GetDistance'
// import VoiceAnnounce from './judgeSDK/utils/voiceAnnouncements';
@Entry
@Component
struct Index {
@ -332,16 +330,15 @@ struct Index {
}
async heartMsg() {
console.log('kkkkmmm')
const arr = [globalThis.signNum || 0, globalThis.statue || 1]
let tmpList = [];
let tmpList = [];d
tmpList.push(string2Bytes(arr[0], 1 * 8)[0])
tmpList.push(string2Bytes(arr[1], 1 * 8)[0])
const str = globalThis.lsh || '0000000000000'
for (let i = 0; i < str.length; i++) {
tmpList.push(string2Bytes(str.charCodeAt(i), 1 * 8)[0])
}
console.log('kkkkmmm.carInfo', JSON.stringify(globalThis.carInfo))
console.log('globalThis.carInfo', JSON.stringify(globalThis.carInfo))
const param = {
id: 31,
@ -412,7 +409,7 @@ struct Index {
}
async initParams() {
deleteAllFIleLog(GlobalConfig.comoonfileWriteAddress + '/PLC/')
deleteAllFIleLog()
//设置plc udp 同步requesthost
await getUDP(this.context, false)
this.loading = false
@ -428,9 +425,9 @@ struct Index {
this.hasAuth = globalThis.hasAuth;
initJudgeUdp()
takePhotoFn(this.context)
console.log('deviceIddeviceId', globalThis.deviceNo, this.deviceNo)
clearInterval(this.interval)
this.interval = setInterval(() => {
console.log('kkkkmmm')
this.num++
setliushuiNum(this.context)
getliushuiNum(this.context)