From abb3e1bb47ba18a90966361305dfa77a75148fe1 Mon Sep 17 00:00:00 2001 From: lvyuankang <1344032923@qq.com> Date: Mon, 29 Jul 2024 09:51:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=8C=E4=B8=AD=E5=BF=83=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ets/common/service/indexService.ts | 118 ++++++++++-------- 1 file changed, 63 insertions(+), 55 deletions(-) diff --git a/entry/src/main/ets/common/service/indexService.ts b/entry/src/main/ets/common/service/indexService.ts index e3504872..7ff8c3f7 100644 --- a/entry/src/main/ets/common/service/indexService.ts +++ b/entry/src/main/ets/common/service/indexService.ts @@ -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) @@ -79,20 +82,20 @@ export async function getDoubleCeneterTable(param) { return new Promise(async (reslove, reject) => { // MA_SYSSET双中心下做合并表格操作 const db = new AccountTable(() => { - }, MA_SYSSET); + }, MA_SYSSET, param.context); 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) + 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) + await getDataBaseTable({ tableName: 'MA_SYSSET' }, param) + await getMySystemSetTable({ tableName: 'MA_SYSSET' }, param) } }) - },param.context) + }, param.context) const typeObj = { 'MA_MARKRULE': false, 'MA_SYSTEMPARM': false, @@ -113,7 +116,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 +133,7 @@ export async function getDoubleCeneterTable(param) { }) } + //单中心存表 export async function getSingleCenterTable(param) { return new Promise((reslove, reject) => { @@ -209,11 +213,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 +234,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 +250,9 @@ export async function takePhotoFn(context) { map[key] = false globalThis.spzd[key] = false } - setTimeout(()=>{ + setTimeout(() => { takePhotoFn() - },3000) + }, 3000) }) } } @@ -259,14 +263,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 +283,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 +329,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)