341 lines
9.1 KiB
TypeScript
Raw Normal View History

2024-02-22 10:40:35 +08:00
// @ts-nocheck
import promptAction from '@ohos.promptAction'
2024-08-05 09:47:44 +08:00
import router from '@ohos.router'
2024-05-09 13:42:56 +08:00
import { dateFormat } from '../utils/tools'
2024-02-22 10:40:35 +08:00
import FileUtil from '../../common/utils/File'
2024-08-05 09:47:44 +08:00
import AccountTable from '../../common/database/tables/AccountTable'
import MA_SYSSET from '../../common/constants/MA_SYSSET'
2024-07-29 09:51:49 +08:00
import { takePhoto } from '../../common/service/videoService'
2024-05-09 13:42:56 +08:00
2024-02-22 10:40:35 +08:00
import {
2024-07-29 09:51:49 +08:00
delSyncTable,
2024-05-09 13:42:56 +08:00
getDataBaseTable,
getMySystemSetTable,
2024-07-29 09:51:49 +08:00
upDataZhongxinginitialization,
upDateTable
2024-02-22 10:40:35 +08:00
} from '../../common/service/initable'
2024-05-09 13:42:56 +08:00
import { GlobalConfig } from '../../config/index'
2024-05-16 09:53:10 +08:00
import testNapi from '@ohos.hiserialsdk'
2024-07-29 09:51:49 +08:00
let num = 0
export async function getliushuiNum(context) {
2024-05-09 13:42:56 +08:00
console.log('getLiushuihao')
2024-06-27 20:53:36 +08:00
const fileUtil = new FileUtil(context)
2024-07-29 09:51:49 +08:00
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
2024-05-09 13:42:56 +08:00
}
2024-07-29 09:51:49 +08:00
globalThis.lshNo = str
2024-05-09 13:42:56 +08:00
// return str
2024-07-29 09:51:49 +08:00
} else {
num = Number(JSON.parse(data).value) + 1
let str = num.toString()
for (let i = 0; str.length <= 5; i++) {
str = '0' + str
2024-05-09 13:42:56 +08:00
}
2024-07-29 09:51:49 +08:00
globalThis.lshNo = str
2024-05-09 13:42:56 +08:00
// return str
}
}
2024-07-29 09:51:49 +08:00
2024-02-22 10:40:35 +08:00
//配置流水号
2024-05-09 13:42:56 +08:00
export async function setliushuiNum(context) {
const fileUtil = new FileUtil(context)
try {
const fileData = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/liushui.txt');
const date = new Date()
const time1 = JSON.parse(fileData).date.split(' ')[0]
const time2 = dateFormat(date).split(' ')[0]
if (time1 == time2) {
const param = {
date: dateFormat(date),
value: Number(JSON.parse(fileData).value) + 1
}
const folderPath = await fileUtil.initFolder(`/config`);
fileUtil.addFile(`${folderPath}/liushui.txt`, JSON.stringify(param))
return
}
const param = {
date: dateFormat(date),
value: 0
2024-02-22 10:40:35 +08:00
}
2024-05-09 13:42:56 +08:00
const folderPath = await fileUtil.initFolder(`/config`);
fileUtil.addFile(`${folderPath}/liushui.txt`, JSON.stringify(param))
} catch (err) {
2024-02-22 10:40:35 +08:00
const date = new Date()
const param = {
2024-05-09 13:42:56 +08:00
date: dateFormat(date),
value: 0
2024-02-22 10:40:35 +08:00
}
const folderPath = await fileUtil.initFolder(`/config`);
fileUtil.addFile(`${folderPath}/liushui.txt`, JSON.stringify(param))
2024-05-09 13:42:56 +08:00
}
2024-02-22 10:40:35 +08:00
}
//双中心表
2024-06-27 20:53:36 +08:00
export async function getDoubleCeneterTable(param) {
2024-05-09 13:42:56 +08:00
return new Promise(async (reslove, reject) => {
// MA_SYSSET双中心下做合并表格操作
2024-07-29 14:29:32 +08:00
delSyncTable('MA_SYSSET', param.context).then(async () => {
await getDataBaseTable({ tableName: 'MA_SYSSET' }, param)
await getMySystemSetTable({ tableName: 'MA_SYSSET' }, param)
})
2024-05-09 13:42:56 +08:00
const typeObj = {
'MA_MARKRULE': false,
'MA_SYSTEMPARM': false,
'MA_MAP_COLLECT': false,
'MA_MAP_COLLECT_SHAPE': false,
'MA_MAP_ITEMCLASS': false,
'MA_MAP_POINT': false,
'MA_MAP_POINT_ITEM': false,
'MA_MAP_ROAD': false,
'MA_MAP_ROAD_LANE': false,
'MA_MAP_SUBITEM': false,
'ES_CARINFO': false,
'ES_EXAMPOINTDETAIL': false,
'MA_MARKRULESET': false,
'ES_CAR_VIDEO_PARAMETER': false,
'MA_CDSBINFO': false,
'MA_ITEMINFO': false,
'MA_T_CARPARMSET': false
}
for (let key in typeObj) {
2024-08-05 09:47:44 +08:00
typeObj[key] = await upDateTable({ tableName: key }, param)
2024-05-09 13:42:56 +08:00
if (!typeObj[key]) {
promptAction.showToast({
message: `未能查询到${key}表数据, 请先检查网络是否连接正常`,
duration: 3000
});
reslove(false)
return
}
}
reslove(true)
2024-08-05 09:47:44 +08:00
router.pushUrl({
url: 'pages/ExaminerLogin',
}, router.RouterMode.Single);
2024-05-09 13:42:56 +08:00
})
2024-02-22 10:40:35 +08:00
}
2024-07-29 09:51:49 +08:00
2024-02-22 10:40:35 +08:00
//单中心存表
2024-06-27 20:53:36 +08:00
export async function getSingleCenterTable(param) {
2024-05-09 13:42:56 +08:00
return new Promise((reslove, reject) => {
2024-06-27 20:53:36 +08:00
upDataZhongxinginitialization(param).then((result) => {
2024-08-14 17:26:27 +08:00
console.log('teststetfinsh01')
2024-05-09 13:42:56 +08:00
if (result) {
reslove(true)
} else {
2024-07-05 09:08:17 +08:00
// promptAction.showToast({
// title: '提示',
// message: '联网更新失败,请检查网络后重新更新',
// buttons: [
// {
// text: '确认',
// color: '#000000',
// },
// {
// text: '取消',
// color: '#000000',
// }
// ],
// })
// .then(data => {
// reslove(false)
// })
// .catch(err => {
// reslove(false)
// })
2024-07-09 11:11:31 +08:00
console.log('联网更新失败,请检查网络后重新更新')
2024-08-13 11:50:38 +08:00
// promptAction.showToast({
// message: `联网更新表数据失败,请重新更新`,
// duration: 3000
// });
2024-05-09 13:42:56 +08:00
reslove(false)
}
}).catch((error) => {
2024-05-16 09:53:10 +08:00
reslove(false)
2024-05-09 13:42:56 +08:00
console.log(error)
2024-02-22 10:40:35 +08:00
})
2024-05-09 13:42:56 +08:00
})
2024-03-12 15:32:48 +08:00
}
2024-05-09 13:42:56 +08:00
2024-06-27 20:53:36 +08:00
2024-05-09 13:42:56 +08:00
let interval
export async function takePhotoFn(context) {
let param = {
videoNum: '1',
spls: '1',
wz: '0,0',
faceFlag: false,
shuiying: true,
pztd: '2',
ljlx: '',
ip: '192.168.36.94',
port: '554',
userName: 'admin',
pwd: '12345qwe',
td1: '1',
td2: '2',
td3: '3',
td4: '4',
videoRecord1: false,
videoRecord2: true,
videoRecord3: false,
videoRecord4: false,
text1: '',
text2: '',
text3: '',
dolt: '',
fontSize: '',
rlls: '1',
spzd4: false,
spzd3: false,
spzd2: false,
spzd1: false,
zdyz: '5',
}
2024-07-29 09:51:49 +08:00
globalThis.spzd = {
spzd1: false,
spzd2: false,
spzd3: false,
spzd4: false,
2024-05-09 13:42:56 +08:00
}
globalThis.takePhotoNum = 0
const map = {}
const fileUtil = new FileUtil(context)
const fileData = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/config3.txt');
console.log('sizesize', fileData)
param = JSON.parse(fileData)
console.log('paramparam')
clearInterval(interval)
2024-05-16 09:53:10 +08:00
interval = setTimeout(async () => {
2024-05-09 13:42:56 +08:00
const arr = ['spzd1', 'spzd2', 'spzd3', 'spzd4']
for (let key in map) {
map[key] = false
// param[key] = false
}
2024-07-29 09:51:49 +08:00
for (let i = 0; i <= arr.length - 1; i++) {
2024-08-08 18:09:06 +08:00
let key1 = arr[i]
if (param[key1]) {
2024-05-09 13:42:56 +08:00
param.pztd = param[`td${Number(i) + 1}`]
2024-08-08 18:09:06 +08:00
takePhoto(param, context, 'jt/', 0, (data) => {
2024-05-09 13:42:56 +08:00
if (Number(data.fileSize) <= (Number(param.zdyz) * 1000)) {
2024-08-08 18:09:06 +08:00
console.log('getPhtot0000')
map[key1] = true
2024-05-09 13:42:56 +08:00
promptAction.showToast({
message: `视频遮挡`,
duration: 3000
});
2024-08-08 18:09:06 +08:00
globalThis.spzd[key1] = true
2024-05-09 13:42:56 +08:00
} else {
2024-08-08 18:09:06 +08:00
map[key1] = false
globalThis.spzd[key1] = false
2024-05-09 13:42:56 +08:00
}
2024-08-08 18:09:06 +08:00
console.log('getPhtot0000')
2024-07-29 09:51:49 +08:00
setTimeout(() => {
2024-05-16 09:53:10 +08:00
takePhotoFn()
2024-07-29 09:51:49 +08:00
}, 3000)
2024-05-09 13:42:56 +08:00
})
2024-08-08 18:09:06 +08:00
2024-05-09 13:42:56 +08:00
}
}
globalThis.takePhotoNum++
2024-05-16 09:53:10 +08:00
if (globalThis.takePhotoNum >= 20) {
2024-05-09 13:42:56 +08:00
globalThis.takePhotoNum = 0
2024-05-16 09:53:10 +08:00
// deleteAllFileByPiC('jt')
2024-05-09 13:42:56 +08:00
}
}, 3000)
2024-05-16 09:53:10 +08:00
}
2024-07-29 09:51:49 +08:00
2024-05-16 09:53:10 +08:00
let fd
2024-07-29 09:51:49 +08:00
const devPath = "/dev/ttyS3"
2024-05-30 15:52:03 +08:00
function openChuankouFn(callback) {
2024-05-29 10:13:37 +08:00
console.log('SerialOpen in indexservice, path=' + devPath)
2024-05-30 15:52:03 +08:00
2024-07-29 09:51:49 +08:00
testNapi.SerialOpenAsync(devPath, (fd) => {
2024-05-30 15:52:03 +08:00
globalThis.fd = fd;
2024-07-29 09:51:49 +08:00
globalThis.num = 0
2024-05-30 15:52:03 +08:00
let parity = 0x4e; // 'N'
let ret = testNapi.SerialSetAsync(globalThis.fd, 115200, 0, 8, 1, parity, (ret) => {
callback()
});
});
2024-05-16 09:53:10 +08:00
}
2024-05-27 17:25:20 +08:00
2024-05-16 09:53:10 +08:00
function getChuankouFnMsg() {
let timeout = 50000; // 2秒超时
let databuff = [0x61, 0xAA, 0x0A, 0X15, 0X00]; // send ABCDE
2024-07-29 09:51:49 +08:00
console.log('fdfd', globalThis.fd)
2024-05-29 10:13:37 +08:00
console.log('zzc 1 try send msg')
2024-07-29 09:51:49 +08:00
testNapi.SerialSendAsync(globalThis.fd, databuff, (ret) => {
2024-05-29 10:13:37 +08:00
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')
2024-07-29 09:51:49 +08:00
console.log('revTestInfo', revTestInfo.recevedBuf.length)
2024-05-16 09:53:10 +08:00
2024-05-29 10:13:37 +08:00
const message = revTestInfo?.recevedBuf?.toString()
2024-07-29 09:51:49 +08:00
console.log('chuankou', message)
2024-05-29 10:13:37 +08:00
if (message == '') {
console.log('zzc error msg is emptry')
2024-07-29 09:51:49 +08:00
globalThis.num = 1
2024-05-29 10:13:37 +08:00
console.log('zzc 9 num=3 close serial')
// clearInterval(chuankou)
testNapi.SerialClose(globalThis.fd);
2024-07-29 09:51:49 +08:00
globalThis.fd = null
2024-05-29 10:13:37 +08:00
getChuankouFn()
return
}
const msg = message?.split(',')
2024-07-29 09:51:49 +08:00
if (!msg?.length) {
2024-05-16 09:53:10 +08:00
2024-05-29 10:13:37 +08:00
} else if (msg[0] != '98' || msg[1] != '85' || msg.length < 9) {
2024-05-16 09:53:10 +08:00
2024-07-29 09:51:49 +08:00
} else if (msg.length < 12) {
2024-05-29 10:13:37 +08:00
} else {
2024-07-29 09:51:49 +08:00
globalThis.chuankoMsg = msg[9]
2024-05-29 10:13:37 +08:00
}
console.log('zzc 5 sleep 1s')
2024-07-29 09:51:49 +08:00
setTimeout(() => {
2024-05-29 10:13:37 +08:00
getChuankouFnMsg()
2024-07-29 09:51:49 +08:00
}, 500)
2024-05-29 10:13:37 +08:00
// hilog.info(0x0000, 'testTag', 'Test NAPI SerialRecvAsync callback in');
// hilog.info(0x0000, 'testTag', 'Test NAPI SerialRecvAsync recevedLen = %{public}d', revTestInfo.recevedLen);
// hilog.info(0x0000, 'testTag', 'Test NAPI SerialRecvAsync recevedBuf = %{public}s', revTestInfo.recevedBuf.toString());
});
});
// let revTestInfo = testNapi?.SerialRecv(globalThis.fd, timeout);
2024-05-16 09:53:10 +08:00
}
2024-07-29 09:51:49 +08:00
2024-05-27 17:25:20 +08:00
let chuankou
2024-07-29 09:51:49 +08:00
export async function getChuankouFn() {
if (globalThis.fd) {
2024-05-16 09:53:10 +08:00
return
}
2024-05-30 15:52:03 +08:00
openChuankouFn(getChuankouFnMsg)
2024-05-29 10:13:37 +08:00
// clearInterval(chuankou)
// chuankou=setInterval(()=>{
2024-05-30 15:52:03 +08:00
// getChuankouFnMsg()
2024-05-29 10:13:37 +08:00
// },1000)
2024-05-16 09:53:10 +08:00
2024-05-09 13:42:56 +08:00
}