tcp修改 #58
@ -12,6 +12,7 @@ export async function getDeviceInfo(context) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const fileUtil = new FileUtil(context)
|
||||
const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/deviceNo.txt');
|
||||
console.log('globalThis.deviceNoglobalThis.deviceNo',data)
|
||||
if (data === '' || data === undefined) {
|
||||
promptAction.showToast({
|
||||
message: `请先进行设备注册`,
|
||||
@ -21,7 +22,8 @@ export async function getDeviceInfo(context) {
|
||||
} else {
|
||||
const fileData=JSON.parse(data)
|
||||
globalThis.deviceNo = fileData.deviceName
|
||||
getCarInfo()
|
||||
console.log('globalThis.deviceNo', globalThis.deviceNo)
|
||||
// getCarInfo()
|
||||
resolve(fileData.deviceName)
|
||||
}
|
||||
})
|
||||
@ -30,6 +32,8 @@ export async function getDeviceInfo(context) {
|
||||
//获取考车信息
|
||||
export async function getCarInfo() {
|
||||
let date = new Date();
|
||||
console.log('globalThis.carInfo2222', globalThis.deviceNo)
|
||||
|
||||
let params = { time: dateFormat(date), deviceNo: globalThis.deviceNo };
|
||||
let res: any = await obtainCarExamInfo(params)
|
||||
if (!res?.obtainCarExamInfoRsp?.body) {
|
||||
@ -38,7 +42,7 @@ export async function getCarInfo() {
|
||||
// }, router.RouterMode.Single);
|
||||
} else {
|
||||
globalThis.carInfo = res.obtainCarExamInfoRsp.body
|
||||
console.log('globalThis.carInfo', JSON.stringify(globalThis.carInfo));
|
||||
console.log('globalThis.carInfo2222', JSON.stringify(res));
|
||||
// globalThis.carInfo.carId=res.obtainCarExamInfoRsp.body.carId
|
||||
globalThis.carInfo.plateNo = decodeURIComponent(globalThis.carInfo.plateNo)
|
||||
}
|
||||
|
||||
@ -13,6 +13,7 @@ export async function getUDP(context,errorFlag?) {
|
||||
return new Promise(async (reslove,reject)=>{
|
||||
const fileUtil = new FileUtil(context)
|
||||
const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/ipConfig.txt');
|
||||
console.log('ttttt',data)
|
||||
if (data === '' || data === undefined) {
|
||||
console.log(` getUDP has no IPConfigTable `);
|
||||
globalThis.udpClient = {}
|
||||
@ -45,6 +46,7 @@ export async function getUDP(context,errorFlag?) {
|
||||
else {
|
||||
// 未绑定
|
||||
console.log(` getUDP has no udclent and bind `);
|
||||
console.log('ttttttdata',JSON.stringify(result))
|
||||
const udpClient: UdpClientByCenter = new UdpClientByCenter(result.udplocalIp, result.udplocalIpPort, result.udpOppositeIp, result.udpOppositeIpPort)
|
||||
udpClient.bindUdp()
|
||||
udpClient.sendMsg('111')
|
||||
@ -62,7 +64,7 @@ export async function getUDP(context,errorFlag?) {
|
||||
}
|
||||
})
|
||||
getChuankouFn()
|
||||
reslove(`http://${result[0].centerIp}:${result[0].centerPort}`)
|
||||
reslove(`http://${result.centerIp}:${result.centerPort}`)
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import socket from '@ohos.net.socket';
|
||||
import hilog from '@ohos.hilog';
|
||||
import { getTCP } from './GlobalTcp';
|
||||
import prompt from '@ohos.prompt';
|
||||
|
||||
const TAG = 'socketTag[TcpDemo.TcpClient]'
|
||||
|
||||
@ -166,18 +167,22 @@ export default class TcpClient {
|
||||
} else {
|
||||
callback && callback('')
|
||||
}
|
||||
clearInterval(globalThis.intervaltcp)
|
||||
globalThis.intervaltcp=setInterval(()=>{
|
||||
setTimeout(async () => {
|
||||
//程序断开
|
||||
if (globalThis.tcpUdpError) {
|
||||
this.num++
|
||||
console.log(TAG,'tcp信号丢失')
|
||||
if(this.num==3){
|
||||
getTCP()
|
||||
this.num=0
|
||||
}
|
||||
prompt.showToast({
|
||||
message: 'tcp信号丢失',
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
globalThis.tcpUdpError = true;
|
||||
}, 2000)
|
||||
},3000)
|
||||
|
||||
// callback(value.message)
|
||||
});
|
||||
}
|
||||
|
||||
@ -176,15 +176,15 @@ export default class UdpClient {
|
||||
//程序断开
|
||||
lightLineUdp?.send(globalThis.plcUdpError ? arrRedBuffer : (isJudge ? arrGreenBugger : arrBlueBuffer));
|
||||
if (globalThis.plcUdpError) {
|
||||
num++
|
||||
// num++
|
||||
console.log(TAG,'plc udp信号丢失')
|
||||
if(num==3){
|
||||
// if(num==3){
|
||||
getUDP(globalThis.context,true)
|
||||
// await this.bindUdp()
|
||||
// await this.sendMsg('111')
|
||||
// await this.onMessage(callback)
|
||||
num=0
|
||||
}
|
||||
// num=0
|
||||
// }
|
||||
prompt.showToast({
|
||||
message: 'plc udp信号丢失',
|
||||
duration: 2000
|
||||
|
||||
@ -3,6 +3,9 @@ import convertxml from '@ohos.convertxml';
|
||||
import prompt from '@ohos.prompt'
|
||||
import { sendGreen } from '../../pages/judgeSDK/utils/judgeCommon';
|
||||
import {GlobalConfig} from '../../config/index'
|
||||
import FileUtil from '../../common/utils/File';
|
||||
import { dateFormat } from '../utils/tools'
|
||||
|
||||
const config = {
|
||||
host:GlobalConfig.host,
|
||||
}
|
||||
@ -36,16 +39,31 @@ export default async function request(req: any) {
|
||||
try {
|
||||
let baseUrl=host?host:globalThis.host
|
||||
// let baseUrl=host?config.csptHost:config.host'
|
||||
console.log('响应头地址' + paramsStr)
|
||||
|
||||
console.log('响应头地址' + baseUrl)
|
||||
// writeLog({
|
||||
// time:dateFormat(new Date()),
|
||||
// url,
|
||||
// extraData: JSON.stringify(data),
|
||||
// state:'start'
|
||||
// })
|
||||
const {result,responseCode} = await httpRequest.request(`${baseUrl}${url}${paramsStr}`, options);
|
||||
// fileUtil.editFile(`${folderPath}/request.txt`, JSON.stringify(arrList))
|
||||
// writeLog({
|
||||
// time:dateFormat(new Date()),
|
||||
// url,
|
||||
// result:JSON.stringify(result),
|
||||
// extraData: JSON.stringify(data),
|
||||
// state:'end'
|
||||
// })
|
||||
console.log('响应头地址' + JSON.stringify(result))
|
||||
let res:any = xml ? xmlToJson(result,url) : result;
|
||||
console.log('响应头地址' + JSON.stringify(res))
|
||||
|
||||
let resObj = null;
|
||||
if(typeof res === "string"){
|
||||
res=JSON.parse(res)
|
||||
}
|
||||
|
||||
//处理中心服务code
|
||||
if(res.Envelope){
|
||||
const msgXml = res.Envelope.Body.writeObjectOutResponse.return;
|
||||
@ -99,7 +117,12 @@ export default async function request(req: any) {
|
||||
}
|
||||
|
||||
}
|
||||
async function writeLog(param){
|
||||
const fileUtil = new FileUtil(globalThis.context)
|
||||
const folderPath = await fileUtil.initFolder(`/errorMsg/`);
|
||||
fileUtil.editFile(`${folderPath}/request.txt`, JSON.stringify(param)+`\n`)
|
||||
|
||||
}
|
||||
//xml格式转JSON
|
||||
function xmlToJson(result,url) {
|
||||
console.log("xmlToJson begin",url);
|
||||
|
||||
@ -319,7 +319,10 @@ struct Index {
|
||||
}
|
||||
|
||||
async onPageShow() {
|
||||
console.log('ttttt',1111)
|
||||
this.userAuth();
|
||||
console.log('ttttt2222',1111)
|
||||
|
||||
this.vocObj = new voiceService(async (status, val, next) => {
|
||||
});
|
||||
|
||||
@ -336,15 +339,7 @@ struct Index {
|
||||
this.createAlbum()
|
||||
|
||||
this.num=0
|
||||
clearInterval(this.interval)
|
||||
this.interval = setInterval(() => {
|
||||
this.num++
|
||||
setliushuiNum(this.context)
|
||||
getliushuiNum(this.context)
|
||||
if(this.num>=3){
|
||||
this.heartMsg()
|
||||
}
|
||||
}, 1000)
|
||||
|
||||
|
||||
//
|
||||
// const TcpClient: TcpClient =new TcpClient(result[0].tcplocalIp, result[0].tcplocalIpPort,result[0].tcpOppositeIp,result[0].tcpOppositePort)
|
||||
@ -388,18 +383,28 @@ struct Index {
|
||||
//设置plc udp 同步requesthost
|
||||
await getUDP(this.context,false)
|
||||
this.loading = false
|
||||
takePhotoFn(this.context)
|
||||
console.log('globalThis.deviceNo000')
|
||||
await getDeviceInfo(this.context)
|
||||
// await getCarInfo()
|
||||
// await getUDP2(this.context,false)
|
||||
// getTCP()
|
||||
await getCarInfo()
|
||||
await getUDP2(this.context,false)
|
||||
getTCP()
|
||||
this.deviceId= globalThis.carInfo.carNo
|
||||
await setCurrentTime();
|
||||
this.carNum = globalThis.carInfo.plateNo;
|
||||
this.version = globalThis.version;
|
||||
this.hasAuth = globalThis.hasAuth;
|
||||
initJudgeUdp()
|
||||
takePhotoFn(this.context)
|
||||
console.log('deviceIddeviceId',globalThis.deviceNo,this.deviceNo)
|
||||
clearInterval(this.interval)
|
||||
this.interval = setInterval(() => {
|
||||
this.num++
|
||||
setliushuiNum(this.context)
|
||||
getliushuiNum(this.context)
|
||||
if(this.num>=3){
|
||||
this.heartMsg()
|
||||
}
|
||||
}, 1000)
|
||||
//下载模型
|
||||
// await this.getModel()
|
||||
// const arr = [0x55, 0xaa, 0x01, 0x00, 0x02, 0x01, 0x03, 0x00]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user