Compare commits
5 Commits
23ea400ee3
...
b987bac5f0
| Author | SHA1 | Date | |
|---|---|---|---|
| b987bac5f0 | |||
| 3bbf35a1db | |||
| 33a719a462 | |||
| abb3e1bb47 | |||
| bf8e2226a7 |
@ -3,42 +3,45 @@ import promptAction from '@ohos.promptAction'
|
||||
import router from '@ohos.router'
|
||||
import { dateFormat } from '../utils/tools'
|
||||
import FileUtil from '../../common/utils/File'
|
||||
import AccountTable from '../../common/database/tables/AccountTable';
|
||||
import MA_SYSSET from '../../common/constants/MA_SYSSET';
|
||||
import { takePhoto, deleteAllFileByPiC } from '../../common/service/videoService'
|
||||
import AccountTable from '../../common/database/tables/AccountTable'
|
||||
import MA_SYSSET from '../../common/constants/MA_SYSSET'
|
||||
import { takePhoto } from '../../common/service/videoService'
|
||||
|
||||
import {
|
||||
getDataBaseTable,
|
||||
upDateTable,
|
||||
getMySystemSetTable,
|
||||
delSyncTable,
|
||||
upDataZhongxinginitialization
|
||||
getDataBaseTable,
|
||||
getMySystemSetTable,
|
||||
upDataZhongxinginitialization,
|
||||
upDateTable
|
||||
} from '../../common/service/initable'
|
||||
import { GlobalConfig } from '../../config/index'
|
||||
import testNapi from '@ohos.hiserialsdk'
|
||||
let num=0
|
||||
export async function getliushuiNum(context){
|
||||
|
||||
let num = 0
|
||||
|
||||
export async function getliushuiNum(context) {
|
||||
console.log('getLiushuihao')
|
||||
const fileUtil = new FileUtil(context)
|
||||
const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress+'/config/liushui.txt');
|
||||
if(data === '' || data === undefined){
|
||||
num=0
|
||||
let str=num.toString()
|
||||
for(let i=0;str.length<=5;i++){
|
||||
str='0'+str
|
||||
const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/liushui.txt');
|
||||
if (data === '' || data === undefined) {
|
||||
num = 0
|
||||
let str = num.toString()
|
||||
for (let i = 0; str.length <= 5; i++) {
|
||||
str = '0' + str
|
||||
}
|
||||
globalThis.lshNo=str
|
||||
globalThis.lshNo = str
|
||||
// return str
|
||||
}else{
|
||||
num=Number(JSON.parse(data).value)+1
|
||||
let str=num.toString()
|
||||
for(let i=0;str.length<=5;i++){
|
||||
str='0'+str
|
||||
} else {
|
||||
num = Number(JSON.parse(data).value) + 1
|
||||
let str = num.toString()
|
||||
for (let i = 0; str.length <= 5; i++) {
|
||||
str = '0' + str
|
||||
}
|
||||
globalThis.lshNo=str
|
||||
globalThis.lshNo = str
|
||||
// return str
|
||||
}
|
||||
}
|
||||
|
||||
//配置流水号
|
||||
export async function setliushuiNum(context) {
|
||||
const fileUtil = new FileUtil(context)
|
||||
@ -78,21 +81,11 @@ export async function setliushuiNum(context) {
|
||||
export async function getDoubleCeneterTable(param) {
|
||||
return new Promise(async (reslove, reject) => {
|
||||
// MA_SYSSET双中心下做合并表格操作
|
||||
const db = new AccountTable(() => {
|
||||
}, MA_SYSSET);
|
||||
db.getRdbStore(() => {
|
||||
db.query('0', async (array) => {
|
||||
if (array.length) {
|
||||
delSyncTable('MA_SYSSET').then(async () => {
|
||||
await getDataBaseTable({ tableName: 'MA_SYSSET' },param)
|
||||
await getMySystemSetTable({ tableName: 'MA_SYSSET' },param)
|
||||
})
|
||||
} else {
|
||||
await getDataBaseTable({ tableName: 'MA_SYSSET' },param)
|
||||
await getMySystemSetTable({ tableName: 'MA_SYSSET' },param)
|
||||
}
|
||||
})
|
||||
},param.context)
|
||||
delSyncTable('MA_SYSSET', param.context).then(async () => {
|
||||
await getDataBaseTable({ tableName: 'MA_SYSSET' }, param)
|
||||
await getMySystemSetTable({ tableName: 'MA_SYSSET' }, param)
|
||||
})
|
||||
|
||||
const typeObj = {
|
||||
'MA_MARKRULE': false,
|
||||
'MA_SYSTEMPARM': false,
|
||||
@ -113,7 +106,7 @@ export async function getDoubleCeneterTable(param) {
|
||||
'MA_T_CARPARMSET': false
|
||||
}
|
||||
for (let key in typeObj) {
|
||||
typeObj[key] = await upDateTable({ tableName: key },param)
|
||||
typeObj[key] = await upDateTable({ tableName: key }, param)
|
||||
if (!typeObj[key]) {
|
||||
promptAction.showToast({
|
||||
message: `未能查询到${key}表数据, 请先检查网络是否连接正常`,
|
||||
@ -130,6 +123,7 @@ export async function getDoubleCeneterTable(param) {
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
//单中心存表
|
||||
export async function getSingleCenterTable(param) {
|
||||
return new Promise((reslove, reject) => {
|
||||
@ -209,11 +203,11 @@ export async function takePhotoFn(context) {
|
||||
spzd1: false,
|
||||
zdyz: '5',
|
||||
}
|
||||
globalThis.spzd={
|
||||
spzd1:false,
|
||||
spzd2:false,
|
||||
spzd3:false,
|
||||
spzd4:false,
|
||||
globalThis.spzd = {
|
||||
spzd1: false,
|
||||
spzd2: false,
|
||||
spzd3: false,
|
||||
spzd4: false,
|
||||
}
|
||||
globalThis.takePhotoNum = 0
|
||||
const map = {}
|
||||
@ -230,11 +224,11 @@ export async function takePhotoFn(context) {
|
||||
map[key] = false
|
||||
// param[key] = false
|
||||
}
|
||||
for(let i=0;i<=arr.length-1;i++){
|
||||
let key=arr[i]
|
||||
for (let i = 0; i <= arr.length - 1; i++) {
|
||||
let key = arr[i]
|
||||
if (param[key]) {
|
||||
param.pztd = param[`td${Number(i) + 1}`]
|
||||
takePhoto(param, context, 'jt/',0,(data)=>{
|
||||
takePhoto(param, context, 'jt/', 0, (data) => {
|
||||
if (Number(data.fileSize) <= (Number(param.zdyz) * 1000)) {
|
||||
map[key] = true
|
||||
promptAction.showToast({
|
||||
@ -246,9 +240,9 @@ export async function takePhotoFn(context) {
|
||||
map[key] = false
|
||||
globalThis.spzd[key] = false
|
||||
}
|
||||
setTimeout(()=>{
|
||||
setTimeout(() => {
|
||||
takePhotoFn()
|
||||
},3000)
|
||||
}, 3000)
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -259,14 +253,16 @@ export async function takePhotoFn(context) {
|
||||
}
|
||||
}, 3000)
|
||||
}
|
||||
|
||||
let fd
|
||||
const devPath="/dev/ttyS3"
|
||||
const devPath = "/dev/ttyS3"
|
||||
|
||||
function openChuankouFn(callback) {
|
||||
console.log('SerialOpen in indexservice, path=' + devPath)
|
||||
|
||||
testNapi.SerialOpenAsync(devPath, (fd)=> {
|
||||
testNapi.SerialOpenAsync(devPath, (fd) => {
|
||||
globalThis.fd = fd;
|
||||
globalThis.num=0
|
||||
globalThis.num = 0
|
||||
let parity = 0x4e; // 'N'
|
||||
let ret = testNapi.SerialSetAsync(globalThis.fd, 115200, 0, 8, 1, parity, (ret) => {
|
||||
callback()
|
||||
@ -277,42 +273,42 @@ function openChuankouFn(callback) {
|
||||
function getChuankouFnMsg() {
|
||||
let timeout = 50000; // 2秒超时
|
||||
let databuff = [0x61, 0xAA, 0x0A, 0X15, 0X00]; // send ABCDE
|
||||
console.log('fdfd',globalThis.fd)
|
||||
console.log('fdfd', globalThis.fd)
|
||||
console.log('zzc 1 try send msg')
|
||||
testNapi.SerialSendAsync(globalThis.fd, databuff,(ret)=>{
|
||||
testNapi.SerialSendAsync(globalThis.fd, databuff, (ret) => {
|
||||
console.log('zzc 2 send finished')
|
||||
console.log('zzc 3 try receive msg')
|
||||
testNapi.SerialRecvAsync(globalThis.fd, timeout, (revTestInfo) => {
|
||||
console.log('zzc 4 received msg')
|
||||
console.log('revTestInfo',revTestInfo.recevedBuf.length)
|
||||
console.log('revTestInfo', revTestInfo.recevedBuf.length)
|
||||
|
||||
const message = revTestInfo?.recevedBuf?.toString()
|
||||
console.log('chuankou',message)
|
||||
console.log('chuankou', message)
|
||||
if (message == '') {
|
||||
console.log('zzc error msg is emptry')
|
||||
globalThis.num=1
|
||||
globalThis.num = 1
|
||||
console.log('zzc 9 num=3 close serial')
|
||||
// clearInterval(chuankou)
|
||||
testNapi.SerialClose(globalThis.fd);
|
||||
globalThis.fd=null
|
||||
globalThis.fd = null
|
||||
getChuankouFn()
|
||||
return
|
||||
}
|
||||
const msg = message?.split(',')
|
||||
if(!msg?.length){
|
||||
if (!msg?.length) {
|
||||
|
||||
} else if (msg[0] != '98' || msg[1] != '85' || msg.length < 9) {
|
||||
|
||||
} else if(msg.length<12){
|
||||
} else if (msg.length < 12) {
|
||||
|
||||
} else {
|
||||
globalThis.chuankoMsg=msg[9]
|
||||
globalThis.chuankoMsg = msg[9]
|
||||
}
|
||||
|
||||
console.log('zzc 5 sleep 1s')
|
||||
setTimeout(()=>{
|
||||
setTimeout(() => {
|
||||
getChuankouFnMsg()
|
||||
},500)
|
||||
}, 500)
|
||||
|
||||
// hilog.info(0x0000, 'testTag', 'Test NAPI SerialRecvAsync callback in');
|
||||
// hilog.info(0x0000, 'testTag', 'Test NAPI SerialRecvAsync recevedLen = %{public}d', revTestInfo.recevedLen);
|
||||
@ -323,9 +319,11 @@ function getChuankouFnMsg() {
|
||||
// let revTestInfo = testNapi?.SerialRecv(globalThis.fd, timeout);
|
||||
|
||||
}
|
||||
|
||||
let chuankou
|
||||
export async function getChuankouFn(){
|
||||
if(globalThis.fd){
|
||||
|
||||
export async function getChuankouFn() {
|
||||
if (globalThis.fd) {
|
||||
return
|
||||
}
|
||||
openChuankouFn(getChuankouFnMsg)
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
// @ts-nocheck
|
||||
import data_rdb from '@ohos.data.rdb';
|
||||
import UIAbility from '@ohos.app.ability.UIAbility';
|
||||
import { initCenterCache,initCenterCacheByKSPT,initEsModel,initialization } from '../../api/index'
|
||||
import { initCenterCache, initCenterCacheByKSPT, initEsModel, initialization } from '../../api/index';
|
||||
import { dateFormat } from '../utils/tools';
|
||||
import AccountTable from '../database/tables/AccountTable';
|
||||
import MA_MARKRULE from '../constants/MA_MARKRULE';
|
||||
@ -23,12 +21,12 @@ import MA_ITEMINFO from '../constants/MA_ITEMINFO';
|
||||
import MA_T_CARPARMSET from '../constants/MA_T_CARPARMSET';
|
||||
import ES_CAR_VIDEO_PARAMETER from '../constants/ES_CAR_VIDEO_PARAMETER';
|
||||
import IpConfigTable from '../constants/IpConfigTable';
|
||||
import CommonConstants from '../constants/CommonConstants'
|
||||
import DeviceInfoTable from '../constants/DeviceInfoTable'
|
||||
import USER from '../constants/USER'
|
||||
import CommonConstants from '../constants/CommonConstants';
|
||||
import DeviceInfoTable from '../constants/DeviceInfoTable';
|
||||
import USER from '../constants/USER';
|
||||
import util from '@ohos.util';
|
||||
import zlib from '@ohos.zlib';
|
||||
import FileModel from '../../pages/judgeSDK/utils/fileModel';
|
||||
|
||||
// @ts-nocheck
|
||||
//读表
|
||||
//参数平台
|
||||
@ -51,155 +49,126 @@ const map = {
|
||||
'MA_ITEMINFO': MA_ITEMINFO,
|
||||
'MA_T_CARPARMSET': MA_T_CARPARMSET,
|
||||
'ES_CAR_VIDEO_PARAMETER': ES_CAR_VIDEO_PARAMETER,
|
||||
'USER':USER,
|
||||
'IpConfigTable':IpConfigTable,
|
||||
'DeviceInfoTable':DeviceInfoTable,
|
||||
'CommonConstants':CommonConstants
|
||||
'USER': USER,
|
||||
'IpConfigTable': IpConfigTable,
|
||||
'DeviceInfoTable': DeviceInfoTable,
|
||||
'CommonConstants': CommonConstants
|
||||
}
|
||||
const centerToMap={
|
||||
'ItemInfo':MA_ITEMINFO,
|
||||
'MarkRule':MA_MARKRULE,
|
||||
'SystemParm':MA_SYSTEMPARM,
|
||||
'mapCollectList':MA_MAP_COLLECT,
|
||||
'mapCollectshapeList':MA_MAP_COLLECT_SHAPE,
|
||||
const centerToMap = {
|
||||
'ItemInfo': MA_ITEMINFO,
|
||||
'MarkRule': MA_MARKRULE,
|
||||
'SystemParm': MA_SYSTEMPARM,
|
||||
'mapCollectList': MA_MAP_COLLECT,
|
||||
'mapCollectshapeList': MA_MAP_COLLECT_SHAPE,
|
||||
'Map_Collect': MA_MAP_COLLECT,
|
||||
'Map_Collect_Shape': MA_MAP_COLLECT_SHAPE,
|
||||
'Map_ItemClass':MA_MAP_ITEMCLASS,
|
||||
'Map_Point':MA_MAP_POINT,
|
||||
'Map_Point_Item':MA_MAP_POINT_ITEM,
|
||||
'Map_Road':MA_MAP_ROAD,
|
||||
'Map_Road_Lane':MA_MAP_ROAD_LANE,
|
||||
'Map_SubItem':MA_MAP_SUBITEM,
|
||||
'Sysset':MA_SYSSET,
|
||||
'CarInfo':ES_CARINFO,
|
||||
'Map_ItemClass': MA_MAP_ITEMCLASS,
|
||||
'Map_Point': MA_MAP_POINT,
|
||||
'Map_Point_Item': MA_MAP_POINT_ITEM,
|
||||
'Map_Road': MA_MAP_ROAD,
|
||||
'Map_Road_Lane': MA_MAP_ROAD_LANE,
|
||||
'Map_SubItem': MA_MAP_SUBITEM,
|
||||
'Sysset': MA_SYSSET,
|
||||
'CarInfo': ES_CARINFO,
|
||||
// 'ES_EXAMPOINTDETAIL':ES_EXAMPOINTDETAIL,
|
||||
'MarkRuleSet':MA_MARKRULE,
|
||||
'Cdsbinfo':MA_CDSBINFO,
|
||||
'T_CarParmSet':MA_T_CARPARMSET,
|
||||
'MarkRuleSet': MA_MARKRULE,
|
||||
'Cdsbinfo': MA_CDSBINFO,
|
||||
'T_CarParmSet': MA_T_CARPARMSET,
|
||||
// 'ES_CAR_VIDEO_PARAMETER':ES_CAR_VIDE0pO_PARAMETER
|
||||
}
|
||||
|
||||
function sqlInsertCommonFn(tableName,resultArr,context?){
|
||||
return new Promise((resolve,reject)=>{
|
||||
function sqlInsertCommonFn(tableName, resultArr, context?, delFlag = true) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const accountTable = new AccountTable(() => {
|
||||
}, map[tableName],context);
|
||||
}, map[tableName], context);
|
||||
accountTable.getRdbStore(() => {
|
||||
accountTable.query('0', async (result) => {
|
||||
accountTable.query('0', async (result) => {
|
||||
// console.log('表长度',result.length,tableName)
|
||||
if (result.length == 0) {
|
||||
let INSERT_SQL = "INSERT INTO "+tableName
|
||||
+ " ("+ map[tableName].ACCOUNT_TABLE.columns.toString()+") VALUES "
|
||||
let INSERT_SQL = "INSERT INTO " + tableName
|
||||
+ " (" + map[tableName].ACCOUNT_TABLE.columns.toString() + ") VALUES "
|
||||
|
||||
resultArr.map((data,i) => {
|
||||
data.id=`${i}`
|
||||
let str='('
|
||||
map[tableName].ACCOUNT_TABLE.columns.map((res,index)=>{
|
||||
if(map[tableName].ACCOUNT_TABLE.columns.length-1==index){
|
||||
str+=data[res]?`"${data[res]}"`:'NULL'
|
||||
}else{
|
||||
str+=(data[res]?`"${data[res]}"`:'NULL')+','
|
||||
resultArr.map((data, i) => {
|
||||
data.id = `${i}`
|
||||
let str = '('
|
||||
map[tableName].ACCOUNT_TABLE.columns.map((res, index) => {
|
||||
if (map[tableName].ACCOUNT_TABLE.columns.length - 1 == index) {
|
||||
str += data[res] ? `"${data[res]}"` : 'NULL'
|
||||
} else {
|
||||
str += (data[res] ? `"${data[res]}"` : 'NULL') + ','
|
||||
}
|
||||
})
|
||||
if(i==resultArr.length-1){
|
||||
str+=')'
|
||||
}else{
|
||||
str+='),'
|
||||
if (i == resultArr.length - 1) {
|
||||
str += ')'
|
||||
} else {
|
||||
str += '),'
|
||||
}
|
||||
INSERT_SQL+=str
|
||||
INSERT_SQL += str
|
||||
})
|
||||
accountTable.sqlOperate(INSERT_SQL,tableName,(val)=>{
|
||||
console.log('sqlsqlinsert,',val,'tableName',tableName)
|
||||
accountTable.sqlOperate(INSERT_SQL, tableName, (val) => {
|
||||
console.log('sqlsqlinsert,', val, 'tableName', tableName)
|
||||
resolve(val)
|
||||
})
|
||||
}
|
||||
else {
|
||||
await delSyncTable(tableName,context)
|
||||
const result= await sqlInsertCommonFn(tableName,resultArr,context)
|
||||
if (delFlag) {
|
||||
await delSyncTable(tableName, context)
|
||||
}
|
||||
const result = await sqlInsertCommonFn(tableName, resultArr, context)
|
||||
resolve(result)
|
||||
}
|
||||
}, true);
|
||||
},context);
|
||||
}, context);
|
||||
})
|
||||
}
|
||||
|
||||
//参数平台
|
||||
export async function getDataBaseTable(params,reqParam) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const accountTable = new AccountTable(() => {
|
||||
}, map[params.tableName],context);
|
||||
accountTable.getRdbStore(() => {
|
||||
accountTable.query('0', async (result) => {
|
||||
if (result.length != 0) {
|
||||
resolve();
|
||||
return
|
||||
} else {
|
||||
const date = new Date()
|
||||
if(!reqParam?.paraKdid){
|
||||
prompt.showToast({
|
||||
message: 'paraKdid获取失败',
|
||||
duration: 3000
|
||||
});
|
||||
return
|
||||
}
|
||||
const str = { "head": { "time": dateFormat(date) },
|
||||
"body":
|
||||
{ "tableName": params.tableName, // 表名
|
||||
"paraKdid": reqParam.paraKdid, //参数平台kdid
|
||||
"examinationRoomId": reqParam.examinationRoomId, //考试平台kdid
|
||||
"typeRsp": "0" // 赋默认值0,无需改变
|
||||
}
|
||||
}
|
||||
let res: any = await initCenterCache(str,reqParam.centerHost)
|
||||
if( res.body[params.tableName].length==0){
|
||||
resolve();
|
||||
return
|
||||
}
|
||||
|
||||
let INSERT_SQL = "INSERT INTO "+params.tableName
|
||||
+ " ("+ map[params.tableName].ACCOUNT_TABLE.columns.toString()+") VALUES "
|
||||
if(params.tableName=='MA_SYSSET'){
|
||||
res.body[params.tableName]= res.body[params.tableName].filter(res=>{
|
||||
return res['v_no']>=300&&res['v_no']<=700
|
||||
})
|
||||
}
|
||||
|
||||
res.body[params.tableName].map((data,i) => {
|
||||
// data.id=`${i}`
|
||||
data.id=i
|
||||
let str='('
|
||||
map[params.tableName].ACCOUNT_TABLE.columns.map((res,index)=>{
|
||||
if(map[params.tableName].ACCOUNT_TABLE.columns.length-1==index){
|
||||
str+=data[res]?`"${data[res]}"`:'NULL'
|
||||
}else{
|
||||
str+=(data[res]?`"${data[res]}"`:'NULL')+','
|
||||
}
|
||||
})
|
||||
if(i==res.body[params.tableName].length-1){
|
||||
str+=')'
|
||||
}else{
|
||||
str+='),'
|
||||
}
|
||||
INSERT_SQL+=str
|
||||
})
|
||||
|
||||
accountTable.sqlOperate(INSERT_SQL,params.tableName,()=>{
|
||||
resolve(true)
|
||||
})
|
||||
}
|
||||
}, true);
|
||||
},reqParam.context);
|
||||
export async function getDataBaseTable(params, reqParam) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const date = new Date()
|
||||
if (!reqParam?.paraKdid) {
|
||||
prompt.showToast({
|
||||
message: 'paraKdid获取失败',
|
||||
duration: 3000
|
||||
});
|
||||
return
|
||||
}
|
||||
const str = { "head": { "time": dateFormat(date) },
|
||||
"body":
|
||||
{ "tableName": params.tableName, // 表名
|
||||
"paraKdid": reqParam.paraKdid, //参数平台kdid
|
||||
"examinationRoomId": reqParam.examinationRoomId, //考试平台kdid
|
||||
"typeRsp": "0" // 赋默认值0,无需改变
|
||||
}
|
||||
}
|
||||
let res: any = await initCenterCache(str, reqParam.centerHost)
|
||||
if (res.body[params.tableName].length == 0) {
|
||||
resolve();
|
||||
return
|
||||
}
|
||||
if (params.tableName == 'MA_SYSSET') {
|
||||
res.body[params.tableName] = res.body[params.tableName].filter(res => {
|
||||
return res['v_no'] >= 300 && res['v_no'] <= 700
|
||||
})
|
||||
}
|
||||
sqlInsertCommonFn(param.tableName, res.body[params.tableName]).then((val) => {
|
||||
reslove(val)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
//依据数组和表名更新sql表
|
||||
export async function upDateTableByArray(tableName,arr) {
|
||||
sqlInsertCommonFn(tableName,arr)
|
||||
export async function upDateTableByArray(tableName, arr) {
|
||||
sqlInsertCommonFn(tableName, arr)
|
||||
}
|
||||
|
||||
//更新双中心表
|
||||
export async function upDateTable(params,reqParam) {
|
||||
export async function upDateTable(params, reqParam) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const date = new Date()
|
||||
let paraKdid=reqParam?.paraKdid||''
|
||||
let examinationRoomId=reqParam?.examinationRoomId||''
|
||||
if(!paraKdid|| !examinationRoomId){
|
||||
let paraKdid = reqParam?.paraKdid || ''
|
||||
let examinationRoomId = reqParam?.examinationRoomId || ''
|
||||
if (!paraKdid || !examinationRoomId) {
|
||||
resolve(false)
|
||||
return
|
||||
}
|
||||
@ -212,17 +181,17 @@ export async function upDateTable(params,reqParam) {
|
||||
"typeRsp": "0" // 赋默认值0,无需改变
|
||||
}
|
||||
}
|
||||
const url=globalThis.timeInfo.url
|
||||
const url = globalThis.timeInfo.url
|
||||
|
||||
initCenterCache(str,url).then(async (res)=>{
|
||||
if(!res||res==undefined||res==''){
|
||||
initCenterCache(str, url).then(async (res) => {
|
||||
if (!res || res == undefined || res == '') {
|
||||
resolve(false)
|
||||
return
|
||||
}
|
||||
try {
|
||||
const result=await sqlInsertCommonFn(params.tableName,res.body[params.tableName],reqParam.context)
|
||||
const result = await sqlInsertCommonFn(params.tableName, res.body[params.tableName], reqParam.context)
|
||||
resolve(result)
|
||||
}catch (error){
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
})
|
||||
@ -230,10 +199,10 @@ export async function upDateTable(params,reqParam) {
|
||||
}
|
||||
|
||||
//考试平台
|
||||
export async function getMySystemSetTable(params,reqParam) {
|
||||
export async function getMySystemSetTable(params, reqParam) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const date = new Date()
|
||||
if(!reqParam.paraKdid){
|
||||
if (!reqParam.paraKdid) {
|
||||
prompt.showToast({
|
||||
message: 'paraKdid获取失败',
|
||||
duration: 3000
|
||||
@ -248,17 +217,17 @@ export async function getMySystemSetTable(params,reqParam) {
|
||||
"typeRsp": "0" // 赋默认值0,无需改变
|
||||
}
|
||||
}
|
||||
initCenterCacheByKSPT(str,reqParam.url).then((res)=>{
|
||||
if( res.body[params.tableName].length==0){
|
||||
initCenterCacheByKSPT(str, reqParam.url).then((res) => {
|
||||
if (res.body[params.tableName].length == 0) {
|
||||
resolve();
|
||||
return
|
||||
}
|
||||
if(params.tableName=='MA_SYSSET'){
|
||||
res.body[params.tableName]= res.body[params.tableName].filter(res=>{
|
||||
return res['v_no']<300 || res['v_no']>700
|
||||
if (params.tableName == 'MA_SYSSET') {
|
||||
res.body[params.tableName] = res.body[params.tableName].filter(res => {
|
||||
return res['v_no'] < 300 || res['v_no'] > 700
|
||||
})
|
||||
}
|
||||
sqlInsertCommonFn(params.tableName,res.body[params.tableName],reqParam.context).then((result)=>{
|
||||
sqlInsertCommonFn(params.tableName, res.body[params.tableName], reqParam.context, false).then((result) => {
|
||||
resolve(result)
|
||||
})
|
||||
})
|
||||
@ -269,10 +238,10 @@ export async function getMySystemSetTable(params,reqParam) {
|
||||
}
|
||||
|
||||
//依据表名同步获取数据
|
||||
export async function getSyncData(tableName,context?) {
|
||||
export async function getSyncData(tableName, context?) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const accountTable = new AccountTable(() => {
|
||||
}, map[tableName],context);
|
||||
}, map[tableName], context);
|
||||
accountTable.getRdbStore(() => {
|
||||
accountTable.query('0', async (result) => {
|
||||
resolve(result)
|
||||
@ -282,22 +251,22 @@ export async function getSyncData(tableName,context?) {
|
||||
|
||||
}
|
||||
|
||||
export async function delSyncTable(tableName,context?){
|
||||
return new Promise((resolve,reject)=>{
|
||||
export async function delSyncTable(tableName, context?) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const accountTable = new AccountTable(() => {
|
||||
}, map[tableName],context);
|
||||
accountTable.deleteTableData((ret)=>{
|
||||
}, map[tableName], context);
|
||||
accountTable.deleteTableData((ret) => {
|
||||
console.log('删除成功')
|
||||
resolve(true)
|
||||
},tableName,context)
|
||||
}, tableName, context)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
//获取车模、场地模型
|
||||
export async function getEsCarModel(context){
|
||||
export async function getEsCarModel(context) {
|
||||
const date = new Date()
|
||||
if(!globalThis.timeInfo?.paraKdid){
|
||||
if (!globalThis.timeInfo?.paraKdid) {
|
||||
prompt.showToast({
|
||||
message: 'paraKdid获取失败',
|
||||
duration: 3000
|
||||
@ -307,23 +276,23 @@ export async function getEsCarModel(context){
|
||||
const carStr = { "head": { "time": dateFormat(date) },
|
||||
"body":
|
||||
{
|
||||
"rtkType":"1",//1:车模 2:场地模型
|
||||
"rspType":"0", //返回类型
|
||||
"rtkType": "1", //1:车模 2:场地模型
|
||||
"rspType": "0", //返回类型
|
||||
"paraKdid": globalThis.timeInfo.paraKdid, //参数平台kdid
|
||||
"examinationRoomId": globalThis.timeInfo.kdid, //考试平台kdid
|
||||
// "carMac":"MAC-HCPAD-210",
|
||||
"carMac":globalThis.deviceNo
|
||||
"carMac": globalThis.deviceNo
|
||||
}
|
||||
}
|
||||
const venueStr = { "head": { "time": dateFormat(date) },
|
||||
const venueStr = { "head": { "time": dateFormat(date) },
|
||||
"body":
|
||||
{
|
||||
"rtkType":"2",//1:车模 2:场地模型
|
||||
"rspType":"0", //返回类型
|
||||
"rtkType": "2", //1:车模 2:场地模型
|
||||
"rspType": "0", //返回类型
|
||||
"paraKdid": globalThis.timeInfo.paraKdid, //参数平台kdid
|
||||
"examinationRoomId": globalThis.timeInfo.kdid, //考试平台kdid
|
||||
// "carMac":"MAC-HCPAD-210",
|
||||
"carMac":globalThis.deviceNo
|
||||
"carMac": globalThis.deviceNo
|
||||
}
|
||||
}
|
||||
|
||||
@ -335,48 +304,48 @@ export async function getEsCarModel(context){
|
||||
const venueModel = venueRes.body.ES_MODEL[0][2];
|
||||
|
||||
let tmpBase64Array = carModel.split("\r\n")
|
||||
let newBase64Str:string = '';
|
||||
let newBase64Str: string = '';
|
||||
for (let i = 0; i < tmpBase64Array.length; ++i) {
|
||||
newBase64Str += tmpBase64Array[i];
|
||||
}
|
||||
const base64 = new util.Base64();
|
||||
let result = base64.decodeSync(newBase64Str);
|
||||
const fileModel= new FileModel(context);
|
||||
const fileModel = new FileModel(context);
|
||||
await fileModel.initFolder()
|
||||
await fileModel.storingFiles(result.buffer)
|
||||
}
|
||||
|
||||
export async function upDataZhongxinginitialization(param){
|
||||
export async function upDataZhongxinginitialization(param) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if(!param.carId){
|
||||
if (!param.carId) {
|
||||
resolve(false)
|
||||
return
|
||||
}
|
||||
const str = {
|
||||
"carId": param.carId, // 表名
|
||||
"carId": param.carId, // 表名
|
||||
"examinationRoomId": param.examinationRoomId, //考试平台kdid
|
||||
videoVersion:'1.0',
|
||||
judgeVersion:param.judgeVersion,
|
||||
shellVersion: param.shellVersion,
|
||||
host:param.host
|
||||
videoVersion: '1.0',
|
||||
judgeVersion: param.judgeVersion,
|
||||
shellVersion: param.shellVersion,
|
||||
host: param.host
|
||||
}
|
||||
console.log('daihai2',JSON.stringify(str))
|
||||
console.log('daihai2', JSON.stringify(str))
|
||||
|
||||
initialization(str).then(async (res)=>{
|
||||
console.log('daihai3',JSON.stringify(res))
|
||||
if(!res){
|
||||
initialization(str).then(async (res) => {
|
||||
console.log('daihai3', JSON.stringify(res))
|
||||
if (!res) {
|
||||
resolve(false)
|
||||
return
|
||||
}
|
||||
let flag
|
||||
console.log('resposestart')
|
||||
|
||||
for(let key in res.initializationRsp.body){
|
||||
if(!centerToMap[key]){
|
||||
for (let key in res.initializationRsp.body) {
|
||||
if (!centerToMap[key]) {
|
||||
continue
|
||||
}
|
||||
const data= await setSyncCenterSqlData(key,res,param)
|
||||
if(!data){
|
||||
const data = await setSyncCenterSqlData(key, res, param)
|
||||
if (!data) {
|
||||
resolve(false)
|
||||
}
|
||||
}
|
||||
@ -385,52 +354,53 @@ export async function upDataZhongxinginitialization(param){
|
||||
|
||||
console.log('resposestart')
|
||||
|
||||
}).catch((Error)=>{
|
||||
}).catch((Error) => {
|
||||
resolve(false)
|
||||
})
|
||||
})
|
||||
}
|
||||
function setSyncCenterSqlData(key,res,param){
|
||||
return new Promise((resolve,reject)=>{
|
||||
const mapName={
|
||||
'ItemInfo':'MA_ITEMINFO',
|
||||
'MarkRule':'MA_MARKRULE',
|
||||
'SystemParm':'MA_SYSTEMPARM',
|
||||
|
||||
function setSyncCenterSqlData(key, res, param) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const mapName = {
|
||||
'ItemInfo': 'MA_ITEMINFO',
|
||||
'MarkRule': 'MA_MARKRULE',
|
||||
'SystemParm': 'MA_SYSTEMPARM',
|
||||
'Map_Collect': 'MA_MAP_COLLECT',
|
||||
'Map_Collect_Shape': 'MA_MAP_COLLECT_SHAPE',
|
||||
'Map_ItemClass':'MA_MAP_ITEMCLASS',
|
||||
'Map_Point':'MA_MAP_POINT',
|
||||
'Map_Point_Item':'MA_MAP_POINT_ITEM',
|
||||
'Map_Road':'MA_MAP_ROAD',
|
||||
'Map_Road_Lane':'MA_MAP_ROAD_LANE',
|
||||
'Map_SubItem':'MAP_SUBITEM',
|
||||
'Sysset':'MA_SYSSET',
|
||||
'CarInfo':'ES_CARINFO',
|
||||
'Map_ItemClass': 'MA_MAP_ITEMCLASS',
|
||||
'Map_Point': 'MA_MAP_POINT',
|
||||
'Map_Point_Item': 'MA_MAP_POINT_ITEM',
|
||||
'Map_Road': 'MA_MAP_ROAD',
|
||||
'Map_Road_Lane': 'MA_MAP_ROAD_LANE',
|
||||
'Map_SubItem': 'MAP_SUBITEM',
|
||||
'Sysset': 'MA_SYSSET',
|
||||
'CarInfo': 'ES_CARINFO',
|
||||
// 'ES_EXAMPOINTDETAIL':ES_EXAMPOINTDETAIL,
|
||||
'MarkRuleSet':'MA_MARKRULESET',
|
||||
'Cdsbinfo':'MA_CDSBINFO',
|
||||
'T_CarParmSet':'MA_T_CARPARMSET',
|
||||
'MarkRuleSet': 'MA_MARKRULESET',
|
||||
'Cdsbinfo': 'MA_CDSBINFO',
|
||||
'T_CarParmSet': 'MA_T_CARPARMSET',
|
||||
// 'ES_CAR_VIDEO_PARAMETER':ES_CAR_VIDE0pO_PARAMETER
|
||||
}
|
||||
// const accountTable = new AccountTable(() => {
|
||||
// }, centerToMap[key],param.context);
|
||||
let arrList
|
||||
if(res.initializationRsp.body[key].record instanceof Array){
|
||||
arrList =res.initializationRsp.body[key].record
|
||||
}else{
|
||||
arrList=[res.initializationRsp.body[key].record]
|
||||
if (res.initializationRsp.body[key].record instanceof Array) {
|
||||
arrList = res.initializationRsp.body[key].record
|
||||
} else {
|
||||
arrList = [res.initializationRsp.body[key].record]
|
||||
}
|
||||
console.log('mapName[key]',mapName[key],key)
|
||||
sqlInsertCommonFn(mapName[key],arrList,param.context).then((result)=>{
|
||||
console.log(key,'表建立成功')
|
||||
if(result){
|
||||
console.log('mapName[key]', mapName[key], key)
|
||||
sqlInsertCommonFn(mapName[key], arrList, param.context).then((result) => {
|
||||
console.log(key, '表建立成功')
|
||||
if (result) {
|
||||
resolve(true)
|
||||
}else{
|
||||
} else {
|
||||
resolve(false)
|
||||
}
|
||||
}).catch((msg)=>{
|
||||
}).catch((msg) => {
|
||||
reject(false)
|
||||
console.log(key,'表建立失败')
|
||||
console.log(key, '表建立失败')
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@ -1,74 +1,76 @@
|
||||
import TcpClient from './TcpClient';
|
||||
import { getSyncData} from '../service/initable'
|
||||
import { getSyncData } from '../service/initable';
|
||||
import hilog from '@ohos.hilog';
|
||||
|
||||
export async function getTCP() {
|
||||
|
||||
getSyncData('IpConfigTable').then(async (result:Array<any>)=>{
|
||||
console.log('result222',JSON.stringify(result))
|
||||
if(result.length){
|
||||
if(globalThis.TcpClient&&globalThis.getCloseTcp){
|
||||
globalThis.TcpClient.closeTcp(async ()=>{
|
||||
getSyncData('IpConfigTable').then(async (result: Array<any>) => {
|
||||
console.log('result222', JSON.stringify(result))
|
||||
if (result.length) {
|
||||
if (globalThis.TcpClient && globalThis.TcpClient.closeTcp) {
|
||||
globalThis.TcpClient.closeTcp(async () => {
|
||||
// const tcpClient: TcpClient =new TcpClient(result[0].tcplocalIp, result[0].tcplocalIpPort,result[0].tcpOppositeIp,result[0].tcpOppositePort)
|
||||
// globalThis.TcpClient = tcpClient
|
||||
setTimeout(async ()=>{
|
||||
await globalThis.TcpClient.rebindTcp(result[0].tcplocalIp, result[0].tcplocalIpPort,result[0].tcpOppositeIp,result[0].tcpOppositePort)
|
||||
setTimeout(async () => {
|
||||
await globalThis.TcpClient.rebindTcp(result[0].tcplocalIp, result[0].tcplocalIpPort, result[0].tcpOppositeIp, result[0].tcpOppositePort)
|
||||
await globalThis.TcpClient.connectTcp()
|
||||
await globalThis.TcpClient.sendMsg('1002')//1002
|
||||
globalThis.TcpClient.onError((val)=>{
|
||||
setTimeout(()=>{
|
||||
globalThis.TcpClient.sendMsg('1002')//1002
|
||||
if(val){
|
||||
await globalThis.TcpClient.sendMsg('1002') //1002
|
||||
globalThis.TcpClient.onError((val) => {
|
||||
setTimeout(() => {
|
||||
globalThis.TcpClient.sendMsg('1002') //1002
|
||||
if (val) {
|
||||
// const msg=val.substring(5,val.length-1)
|
||||
console.log('socketTag[PLC.UdpClient] status:',globalThis.udpClient.getStatus())
|
||||
console.log('socketTag[PLC.UdpClient] status:', globalThis.udpClient.getStatus())
|
||||
globalThis.udpClient?.sendMsg(val)
|
||||
}
|
||||
},1000)
|
||||
}, 1000)
|
||||
})
|
||||
await globalThis.TcpClient.onMessage((val)=>{
|
||||
setTimeout(()=>{
|
||||
globalThis.TcpClient.sendMsg('1002')//1002
|
||||
if(val){
|
||||
await globalThis.TcpClient.onMessage((val) => {
|
||||
setTimeout(() => {
|
||||
globalThis.TcpClient.sendMsg('1002') //1002
|
||||
if (val) {
|
||||
// const msg=val.substring(5,val.length-1)
|
||||
console.log('socketTag[PLC.UdpClient] status:',globalThis.udpClient.getStatus())
|
||||
console.log('socketTag[PLC.UdpClient] status:', globalThis.udpClient.getStatus())
|
||||
globalThis.udpClient?.sendMsg(val)
|
||||
}
|
||||
},1000)
|
||||
}, 1000)
|
||||
|
||||
})
|
||||
},2000)
|
||||
}, 2000)
|
||||
})
|
||||
|
||||
}else{
|
||||
const tcpClient: TcpClient =new TcpClient(result[0].tcplocalIp, result[0].tcplocalIpPort,result[0].tcpOppositeIp,result[0].tcpOppositePort)
|
||||
} else {
|
||||
const tcpClient: TcpClient = new TcpClient(result[0].tcplocalIp, result[0].tcplocalIpPort, result[0].tcpOppositeIp, result[0].tcpOppositePort)
|
||||
globalThis.TcpClient = tcpClient
|
||||
await globalThis.TcpClient.bindTcp()
|
||||
await globalThis.TcpClient.connectTcp()
|
||||
await globalThis.TcpClient.sendMsg('1002')//1002
|
||||
globalThis.TcpClient.onError((val)=>{
|
||||
await globalThis.TcpClient.sendMsg('1002') //1002
|
||||
globalThis.TcpClient.onError((val) => {
|
||||
hilog.info(0x0000, 'testTag', "valvalval2" + JSON.stringify(val));
|
||||
setTimeout(()=>{
|
||||
globalThis.TcpClient.sendMsg('1002')//1002
|
||||
if(val&& globalThis.udpClient?.sendMsg){
|
||||
setTimeout(() => {
|
||||
globalThis.TcpClient.sendMsg('1002') //1002
|
||||
if (val && globalThis.udpClient?.sendMsg) {
|
||||
globalThis.udpClient?.sendMsg(val)
|
||||
}
|
||||
},1000)
|
||||
}, 1000)
|
||||
})
|
||||
await globalThis.TcpClient.onMessage((val)=>{
|
||||
await globalThis.TcpClient.onMessage((val) => {
|
||||
hilog.info(0x0000, 'testTag', "valvalval2" + JSON.stringify(val));
|
||||
setTimeout(()=>{
|
||||
globalThis.TcpClient.sendMsg('1002')//1002
|
||||
if(val&& globalThis.udpClient?.sendMsg){
|
||||
setTimeout(() => {
|
||||
globalThis.TcpClient.sendMsg('1002') //1002
|
||||
if (val && globalThis.udpClient?.sendMsg) {
|
||||
globalThis.udpClient?.sendMsg(val)
|
||||
}
|
||||
},1000)
|
||||
}, 1000)
|
||||
|
||||
})
|
||||
}
|
||||
// globalThis.udpClient = new UdpClient(result[0].localIp, result[0].localIpPort,result[0].oppositeIp,result[0].oppositeIpPort)
|
||||
|
||||
}else{
|
||||
globalThis.TcpClient={}
|
||||
globalThis.TcpClient.onMessage=()=>{}
|
||||
} else {
|
||||
globalThis.TcpClient = {}
|
||||
globalThis.TcpClient.onMessage = () => {
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@ -1,176 +1,189 @@
|
||||
import socket from '@ohos.net.socket';
|
||||
import buffer from '@ohos.buffer';
|
||||
|
||||
const TAG = 'socketTag[TcpDemo.TcpClient]'
|
||||
import prompt from '@ohos.prompt'
|
||||
import hilog from '@ohos.hilog';
|
||||
|
||||
const TAG = 'socketTag[TcpDemo.TcpClient]'
|
||||
|
||||
export default class TcpClient {
|
||||
private localIp: string = ''
|
||||
private localIpPort: string = ''
|
||||
private oppositeIp: string = ''
|
||||
private oppositeIpPort: string = ''
|
||||
private localIp: string = ''
|
||||
private localIpPort: string = ''
|
||||
private oppositeIp: string = ''
|
||||
private oppositeIpPort: string = ''
|
||||
|
||||
private tcp: any = null
|
||||
private tcp: any = null
|
||||
|
||||
constructor(tcplocalIp: string, tcplocalIpPort:string,tcpOppositeIp: string,tcpOppositePort:string) {
|
||||
this.localIp = tcplocalIp
|
||||
this.oppositeIp = tcpOppositeIp
|
||||
this.localIpPort = tcplocalIpPort
|
||||
this.oppositeIpPort = tcpOppositePort
|
||||
console.log(TAG,'new Tcp',this.localIp,this.localIpPort,this.oppositeIp,this.oppositeIpPort)
|
||||
this.tcp = socket.constructTCPSocketInstance();
|
||||
}
|
||||
onError(callback?){
|
||||
this.tcp.on('error', err => {
|
||||
console.log(TAG,'tcpOnerror', JSON.stringify(err))
|
||||
setTimeout(async ()=>{
|
||||
await this.bindTcp()
|
||||
await this.connectTcp()
|
||||
this.onMessage(callback)
|
||||
},2000)
|
||||
// this.closeUdp(()=>{
|
||||
// this.bindUdp()
|
||||
// })
|
||||
constructor(tcplocalIp: string, tcplocalIpPort: string, tcpOppositeIp: string, tcpOppositePort: string) {
|
||||
this.localIp = tcplocalIp
|
||||
this.oppositeIp = tcpOppositeIp
|
||||
this.localIpPort = tcplocalIpPort
|
||||
this.oppositeIpPort = tcpOppositePort
|
||||
console.log(TAG, 'new Tcp', this.localIp, this.localIpPort, this.oppositeIp, this.oppositeIpPort)
|
||||
this.tcp = socket.constructTCPSocketInstance();
|
||||
}
|
||||
|
||||
onError(callback?) {
|
||||
this.tcp.on('error', err => {
|
||||
console.log(TAG, 'tcpOnerror', JSON.stringify(err))
|
||||
setTimeout(async () => {
|
||||
await this.bindTcp()
|
||||
await this.connectTcp()
|
||||
this.onMessage(callback)
|
||||
}, 2000)
|
||||
// this.closeUdp(()=>{
|
||||
// this.bindUdp()
|
||||
// })
|
||||
});
|
||||
}
|
||||
|
||||
rebindTcp(localIp: string, localIpPort: string, oppositeIp: string, oppositeIpPort: string) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.localIp = localIp
|
||||
this.oppositeIp = oppositeIp
|
||||
this.localIpPort = localIpPort
|
||||
this.oppositeIpPort = oppositeIpPort
|
||||
console.log(TAG, 'tcpreBind', this.localIp, this.localIpPort)
|
||||
let promise = this.tcp.bind({
|
||||
address: this.localIp, port: parseInt(this.localIpPort), family: 1
|
||||
}, err => {
|
||||
if (err) {
|
||||
globalThis.getCloseTcp = true
|
||||
hilog.info(0x0000, 'testTag', "tcpreBinderror:" + JSON.stringify(err));
|
||||
resolve(true)
|
||||
}
|
||||
console.log('testTag,rebindtestTag tcp bind success');
|
||||
globalThis.getCloseTcp = false
|
||||
resolve(false)
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
// let promise = this.udp.bind({
|
||||
// // address: '192.168.7.170', port: 20122, family: 1
|
||||
// // address: '192.168.7.170', port: 31013, family: 1
|
||||
// address: this.localIp, port: parseInt(this.localIpPort), family: 1
|
||||
// });
|
||||
|
||||
}
|
||||
|
||||
bindTcp() {
|
||||
console.log(TAG, 'tcpbind', this.localIp, 'localIp', this.localIpPort)
|
||||
return new Promise((resolve, reject) => {
|
||||
let promise = this.tcp.bind({
|
||||
address: this.localIp, port: parseInt(this.localIpPort), family: 1
|
||||
}, err => {
|
||||
if (err) {
|
||||
console.log('testTag tcp bind faile');
|
||||
globalThis.getCloseTcp = true
|
||||
hilog.info(0x0000, 'testTag', "tcpBinderror:" + JSON.stringify(err));
|
||||
resolve(true)
|
||||
return
|
||||
}
|
||||
globalThis.getCloseTcp = false
|
||||
console.log('testTag tcp bind success');
|
||||
resolve(false)
|
||||
})
|
||||
})
|
||||
console.log('localIp', this.localIp)
|
||||
console.log('localIpPort', this.localIpPort)
|
||||
// let promise = this.udp.bind({
|
||||
// // address: '192.168.7.170', port: 20122, family: 1
|
||||
// // address: '192.168.7.170', port: 31013, family: 1
|
||||
// address: this.localIp, port: parseInt(this.localIpPort), family: 1
|
||||
// });
|
||||
|
||||
|
||||
}
|
||||
|
||||
connectTcp() {
|
||||
console.log(TAG, 'tcpConnect', this.oppositeIp, 'localIp', this.oppositeIpPort)
|
||||
return new Promise((resolve, reject) => {
|
||||
let promise = this.tcp.connect({
|
||||
address: {
|
||||
address: this.oppositeIp, port: parseInt(this.oppositeIpPort), family: 1
|
||||
}, timeout: 6000
|
||||
});
|
||||
promise.then(() => {
|
||||
|
||||
this.tcp.setExtraOptions({
|
||||
keepAlive: true,
|
||||
// OOBInline: true,
|
||||
// TCPNoDelay: true,
|
||||
// socketLinger: { on:true, linger:10 },
|
||||
// receiveBufferSize: 1000,
|
||||
// sendBufferSize: 1000,
|
||||
// reuseAddress: true,
|
||||
// socketTimeout: 3000,
|
||||
}, err => {
|
||||
if (err) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
rebindTcp(localIp: string, localIpPort:string,oppositeIp: string,oppositeIpPort:string){
|
||||
return new Promise((resolve, reject)=>{
|
||||
this.localIp = localIp
|
||||
this.oppositeIp = oppositeIp
|
||||
this.localIpPort = localIpPort
|
||||
this.oppositeIpPort = oppositeIpPort
|
||||
console.log(TAG,'tcpreBind', this.localIp,this.localIpPort)
|
||||
let promise=this.tcp.bind({ address: this.localIp, port:parseInt(this.localIpPort), family: 1 }, err => {
|
||||
if (err) {
|
||||
globalThis.getCloseTcp=true
|
||||
hilog.info(0x0000, 'testTag', "tcpreBinderror:" + JSON.stringify(err));
|
||||
resolve(true)
|
||||
}
|
||||
console.log('testTag,rebindtestTag tcp bind success');
|
||||
globalThis.getCloseTcp=false
|
||||
resolve(false)
|
||||
globalThis.getCloseTcp = false
|
||||
resolve(true)
|
||||
}).catch(err => {
|
||||
globalThis.getCloseTcp = true
|
||||
setTimeout(() => {
|
||||
this.connectTcp()
|
||||
resolve(false)
|
||||
}, 2000)
|
||||
console.log('testTagconnect,error')
|
||||
|
||||
})
|
||||
})
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
// let promise = this.udp.bind({
|
||||
// // address: '192.168.7.170', port: 20122, family: 1
|
||||
// // address: '192.168.7.170', port: 31013, family: 1
|
||||
// address: this.localIp, port: parseInt(this.localIpPort), family: 1
|
||||
// });
|
||||
sendMsg(msg: string) {
|
||||
console.log(TAG, 'tcpSend', msg.length, msg)
|
||||
return new Promise((reslove, reject) => {
|
||||
let promise = this.tcp.send({
|
||||
data: msg
|
||||
});
|
||||
promise.then(() => {
|
||||
reslove(true)
|
||||
}).catch(err => {
|
||||
reslove(false)
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
bindTcp() {
|
||||
console.log(TAG,'tcpbind',this.localIp,'localIp',this.localIpPort)
|
||||
return new Promise((resolve,reject)=>{
|
||||
let promise=this.tcp.bind({ address: this.localIp, port:parseInt(this.localIpPort), family: 1 }, err => {
|
||||
if (err) {
|
||||
console.log('testTag tcp bind faile');
|
||||
globalThis.getCloseTcp=true
|
||||
hilog.info(0x0000, 'testTag', "tcpBinderror:" + JSON.stringify(err));
|
||||
resolve(true)
|
||||
return
|
||||
}
|
||||
globalThis.getCloseTcp=false
|
||||
console.log('testTag tcp bind success');
|
||||
resolve(false)
|
||||
})
|
||||
})
|
||||
console.log('localIp',this.localIp)
|
||||
console.log('localIpPort',this.localIpPort)
|
||||
// let promise = this.udp.bind({
|
||||
// // address: '192.168.7.170', port: 20122, family: 1
|
||||
// // address: '192.168.7.170', port: 31013, family: 1
|
||||
// address: this.localIp, port: parseInt(this.localIpPort), family: 1
|
||||
// });
|
||||
onMessage(callback?) {
|
||||
this.tcp.on('message', value => {
|
||||
console.log(TAG, 'Tcponmessage', value.length, value)
|
||||
|
||||
// console.log('messageLengt',,value.message.length))
|
||||
console.log('testTagtcpmsg')
|
||||
// console.log("on message, message:" + value.message+ ", remoteInfo:" )
|
||||
if (value) {
|
||||
let dataView = new DataView(value.message)
|
||||
// const Arraybuffer=buffer.from(value.message, 5, dataView?.byteLength);
|
||||
const Arraybuffer = value.message.slice(5, dataView?.byteLength);
|
||||
|
||||
}
|
||||
connectTcp(){
|
||||
console.log(TAG,'tcpConnect',this.oppositeIp,'localIp',this.oppositeIpPort)
|
||||
return new Promise((resolve,reject)=>{
|
||||
let promise = this.tcp.connect({ address: {address: this.oppositeIp, port: parseInt(this.oppositeIpPort), family: 1} , timeout: 6000});
|
||||
promise.then(() => {
|
||||
callback && callback(Arraybuffer)
|
||||
} else {
|
||||
callback && callback('')
|
||||
}
|
||||
// callback(value.message)
|
||||
});
|
||||
}
|
||||
|
||||
this.tcp.setExtraOptions({
|
||||
keepAlive: true,
|
||||
// OOBInline: true,
|
||||
// TCPNoDelay: true,
|
||||
// socketLinger: { on:true, linger:10 },
|
||||
// receiveBufferSize: 1000,
|
||||
// sendBufferSize: 1000,
|
||||
// reuseAddress: true,
|
||||
// socketTimeout: 3000,
|
||||
},err => {
|
||||
if (err) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
globalThis.getCloseTcp=false
|
||||
resolve(true)
|
||||
}).catch(err => {
|
||||
globalThis.getCloseTcp=true
|
||||
setTimeout(()=>{
|
||||
this.connectTcp()
|
||||
},2000)
|
||||
console.log('testTagconnect,error')
|
||||
offTcp(callback) {
|
||||
console.log(TAG, 'tcpofff')
|
||||
|
||||
});
|
||||
})
|
||||
}
|
||||
this.tcp.off('testTagofmessg', callback);
|
||||
}
|
||||
|
||||
sendMsg(msg: string) {
|
||||
console.log(TAG,'tcpSend',msg.length,msg)
|
||||
return new Promise((reslove,reject)=>{
|
||||
let promise = this.tcp.send({
|
||||
data:msg
|
||||
});
|
||||
promise.then(() => {
|
||||
reslove(true)
|
||||
}).catch(err => {
|
||||
reslove(false)
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
onMessage(callback?) {
|
||||
this.tcp.on('message', value => {
|
||||
console.log(TAG,'Tcponmessage',value.length,value)
|
||||
|
||||
// console.log('messageLengt',,value.message.length))
|
||||
console.log('testTagtcpmsg')
|
||||
// console.log("on message, message:" + value.message+ ", remoteInfo:" )
|
||||
if (value) {
|
||||
let dataView = new DataView(value.message)
|
||||
// const Arraybuffer=buffer.from(value.message, 5, dataView?.byteLength);
|
||||
const Arraybuffer=value.message.slice(5, dataView?.byteLength);
|
||||
|
||||
callback&&callback(Arraybuffer)
|
||||
}else{
|
||||
callback&&callback('')
|
||||
}
|
||||
// callback(value.message)
|
||||
});
|
||||
}
|
||||
offTcp(callback) {
|
||||
console.log(TAG,'tcpofff')
|
||||
|
||||
this.tcp.off('testTagofmessg', callback);
|
||||
}
|
||||
closeTcp(callback) {
|
||||
return new Promise((reslove,reject)=>{
|
||||
console.log(TAG,'tcpClose')
|
||||
let promise = this.tcp.close();
|
||||
promise.then(() => {
|
||||
globalThis.getCloseTcp=true
|
||||
console.log(TAG,'tcpCloseSuccess')
|
||||
callback()
|
||||
reslove(true)
|
||||
}).catch(err => {
|
||||
console.log(TAG,'tcpClosefailed')
|
||||
reslove(false)
|
||||
});
|
||||
})
|
||||
}
|
||||
closeTcp(callback) {
|
||||
return new Promise((reslove, reject) => {
|
||||
console.log(TAG, 'tcpClose')
|
||||
let promise = this.tcp.close();
|
||||
promise.then(() => {
|
||||
globalThis.getCloseTcp = true
|
||||
console.log(TAG, 'tcpCloseSuccess')
|
||||
callback()
|
||||
reslove(true)
|
||||
}).catch(err => {
|
||||
console.log(TAG, 'tcpClosefailed')
|
||||
reslove(false)
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -111,7 +111,7 @@ export default struct Index {
|
||||
carConfigurationInfoFn() {
|
||||
if (globalThis.singlePlay) {
|
||||
//
|
||||
const str = "1:5;2:5;3:5;4:5;5:5;6:5;7:5;8:5;9:5;10:5;11:5;12:5;13:5;14:5;15:5;16:5;17:5;18:5;19:5;20:5;21:5;22:2;23:5;24:5;25:5;"
|
||||
const str = "1:5;2:5;3:5;4:5;5:5;6:5;7:5;8:5;9:5;10:5;11:5;12:5;13:5;14:5;15:5;16:5;17:5;18:5;19:5;20:5;21:5;22:2;23:5;24:5"
|
||||
const data = str.split(';')
|
||||
this.checkList = []
|
||||
const list = data
|
||||
@ -166,7 +166,7 @@ export default struct Index {
|
||||
|
||||
getPLCInfo() {
|
||||
const that = this
|
||||
globalThis.udpClient && globalThis.udpClient.onMessage_1((msg) => {
|
||||
globalThis.udpClient.onMessage_1 && globalThis.udpClient.onMessage_1((msg) => {
|
||||
if (!this.breakFlag) {
|
||||
return
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user