Compare commits

...

3 Commits

9 changed files with 222 additions and 194 deletions

View File

@ -1,18 +1,17 @@
import systemTime from '@ohos.systemDateTime';
import { timeSynchronization } from '../../api';
export function isSevenDaysAgo(date, days = 2) {
const today = new Date(); // 当前日期
const target = new Date(date); // 需要判断的日期
console.info("listFile succeed1", JSON.stringify(target));
const diff = today.getTime() - target.getTime(); // 计算两个日期之间的毫秒数差异
const diffDays = diff / (1000 * 60 * 60 * 24); // 将毫秒转换为天数
console.info("listFile succeed2", JSON.stringify(diffDays));
// 如果差异天数正好是2则原日期是当前日期的前2天
console.log('diffDays', diffDays, days)
return diffDays >= (Number(days));
}
// export function isSevenDaysAgo(date, days = 2) {
// const today = new Date(); // 当前日期
// const target = new Date(date); // 需要判断的日期
// console.info("listFile succeed1", JSON.stringify(target));
//
// const diff = today.getTime() - target.getTime(); // 计算两个日期之间的毫秒数差异
// const diffDays = diff / (1000 * 60 * 60 * 24); // 将毫秒转换为天数
// console.info("listFile succeed2", JSON.stringify(diffDays));
// // 如果差异天数正好是2则原日期是当前日期的前2天
// console.log('diffDays', diffDays, days)
// return diffDays >= (Number(days));
// }
// export async function writeLog(path,param){
// return
@ -62,15 +61,15 @@ export function dateFormat(t) {
return year + "-" + fill(month) + "-" + fill(day) + " " + fill(hours) + ":" + fill(minutes) + ":" + fill(seconds);
}
export function dateVersionFormat(t) {
let year = t.getFullYear()
let month = t.getMonth() + 1
let day = t.getDate()
let hours = t.getHours()
let minutes = t.getMinutes()
let seconds = t.getSeconds()
return year + "." + fill(month) + "." + fill(day) + "." + fill(hours);
}
// export function dateVersionFormat(t) {
// let year = t.getFullYear()
// let month = t.getMonth() + 1
// let day = t.getDate()
// let hours = t.getHours()
// let minutes = t.getMinutes()
// let seconds = t.getSeconds()
// return year + "." + fill(month) + "." + fill(day) + "." + fill(hours);
// }
//同步时时间
@ -134,40 +133,40 @@ export async function getCurrentTime(type?: timeType): Promise<string> {
}
//获取时分秒毫秒
export async function getCurrentHourTime(): Promise<string> {
const date = await systemTime.getDate();
const year = date.getFullYear();
let month = date.getMonth() + 1;
let h = date.getHours();
h = h < 10 ? '0' + h : h;
let m = date.getMinutes();
m = m < 10 ? '0' + m : m;
let s = date.getSeconds();
s = s < 10 ? '0' + s : s;
let ss = date.getMilliseconds();
let nowSS = ''
if (ss < 10) {
nowSS = '00' + ss
}
if (ss >= 10 && ss < 100) {
nowSS = '0' + s
}
return `${h}${m}${s}${nowSS || ss}`
}
// export async function getCurrentHourTime(): Promise<string> {
//
// const date = await systemTime.getDate();
// const year = date.getFullYear();
// let month = date.getMonth() + 1;
// let h = date.getHours();
// h = h < 10 ? '0' + h : h;
// let m = date.getMinutes();
// m = m < 10 ? '0' + m : m;
// let s = date.getSeconds();
// s = s < 10 ? '0' + s : s;
// let ss = date.getMilliseconds();
// let nowSS = ''
// if (ss < 10) {
// nowSS = '00' + ss
// }
// if (ss >= 10 && ss < 100) {
// nowSS = '0' + s
// }
// return `${h}${m}${s}${nowSS || ss}`
// }
//时间戳转日期
export function formatTime(time: number): string {
const h = parseInt(time / 3600)
const minute = parseInt(time / 60 % 60)
const second = Math.ceil(time % 60)
const hours = h < 10 ? '0' + h : h
const formatSecond = second > 59 ? 59 : second
return `${hours > 0 ? `${hours}:` : `${hours}:`}${minute < 10 ? '0' + minute : minute}:${formatSecond < 10 ?
'0' + formatSecond : formatSecond}`
}
// export function formatTime(time: number): string {
// const h = parseInt(time / 3600)
// const minute = parseInt(time / 60 % 60)
// const second = Math.ceil(time % 60)
//
// const hours = h < 10 ? '0' + h : h
// const formatSecond = second > 59 ? 59 : second
// return `${hours > 0 ? `${hours}:` : `${hours}:`}${minute < 10 ? '0' + minute : minute}:${formatSecond < 10 ?
// '0' + formatSecond : formatSecond}`
//
// }
// 根据指定个数分割数组

View File

@ -1,3 +1,6 @@
export const DbTag = '[DBTag]';
export const SerialPortTag = '[SerialPortTag]';
export const SerialPortTag = '[SerialPortTag]';
// usb tag
export const UsbTag = '[UsbTag]';

View File

@ -46,6 +46,7 @@ import {
User
} from '../model';
import { GetSyncData } from '../utils/table/Operation';
import dayTs from '../utils/Date';
@Entry
@Component
@ -162,8 +163,8 @@ struct Index {
this.singlePlay = AppStorage.get('singlePlay')
this.startTime = time.split(' ')[1]
this.startFullTime = await getCurrentTime(1);
this.startHourTime = await getCurrentHourTime()
// this.startHourTime = await getCurrentHourTime()
this.startTime = dayTs().format("HHmmssSSS")
this.startExamTime = time
setInterval(async () => {
@ -708,10 +709,11 @@ struct Index {
Row() {
Text('考试用时:').fontColor('#E5CCA1').fontSize(this.FONTSIZE)
Text(formatTime(this.examTime)).fontColor('#FFF').fontSize(this.FONTSIZE)
// Text(formatTime(this.examTime)).fontColor('#FFF').fontSize(this.FONTSIZE)
Text(dayTs(this.examTime).format("YYYY-MM-DD HH:mm:ss")).fontColor('#FFF').fontSize(this.FONTSIZE)
}.margin({ bottom: 10 })
if (this.examSubject == 3) {
if (this.examSubject == "3") {
Row() {
if (this.judgeConfigObj['375'] == '0') {
Text(`应行驶:${this.examMileage}m`)

View File

@ -40,6 +40,7 @@ import {
import { BusinessError } from '@ohos.base';
import { GetSyncData } from '../utils/table/Operation';
import { GetCurrentUserKeyValue } from './UserInfo/utils';
import dayTs from '../utils/Date';
@Entry
@Component
@ -1004,7 +1005,8 @@ struct UserInfo {
async beginExam(): Promise<BeginExamRequest> {
// const { examSubject, plateNo } = this.carInfo;
const date = new Date()
const startHourTime = await getCurrentHourTime()
// const startHourTime = await getCurrentHourTime()
const startHourTime = dayTs().format("HHmmssSSS")
AppStorage.setOrCreate('startHourTime', startHourTime)
const photoBase64 = await this.getPhoto();
if (photoBase64 == '') {

View File

@ -1,120 +0,0 @@
// 导入USB接口api包。
import usb from '@ohos.usbManager';
const LOGTAG = 'USBSERVICES'
//字符串转字节
function stringToArr(str){
var arr = [];
for (var i = 0, j = str.length; i < j; ++i) {
arr.push(str.charCodeAt(i));
}
return arr
}
//plc数据转成无锡科研所usb字节数据
function plcStrToWXCodeArr(wuXiDataStr){
const arr = stringToArr(wuXiDataStr);
//数据包总长度 有效长度
let packetSize = 65,maxDataSize = 63;
let packetArr = []
const loop = Math.ceil(arr.length / maxDataSize)
for(let i = 0; i< loop; i++){
const thisPacket = arr.slice(i * maxDataSize,(i + 1) * maxDataSize)
const oSize = maxDataSize - thisPacket.length;
//补齐0x00
if(oSize > 0){
let oSizeArr = []
for(let j = 0;j < oSize;j++){oSizeArr.push(0x00)}
packetArr.push([thisPacket.length].concat(thisPacket).concat(oSizeArr));
}else{
packetArr.push([thisPacket.length].concat(thisPacket));
}
}
return packetArr
}
export default class UsbService{
private devicepipe : usb.USBDevicePipe
private outEndpoint: usb.USBEndpoint
public isWXUSBDevice:Boolean
constructor() {
//是否是无锡检测设备
this.isWXUSBDevice = false
this.devicepipe
this.init()
}
init = async()=>{
// 获取设备列表。
let deviceList : Array<usb.USBDevice> = usb.getDevices();
deviceList.forEach(async (device:usb.USBDevice) => {
const {vendorId,productId} = device;
console.log(LOGTAG,JSON.stringify(device));
//无锡所检测设备接入
if(vendorId === 6790 && productId === 58409){
// if(vendorId === 2385 && productId === 5734){
// 申请操作指定的device的操作权限。
try {
let bool = usb.hasRight(device.name);
console.info(LOGTAG,'bool =>' + bool)
const isExit = await usb.requestRight(device.name);
console.info(LOGTAG,'isExit =>' + isExit)
if(isExit){
let devicepipe : usb.USBDevicePipe = usb.connectDevice(device);
let interfaces = device.configs[0].interfaces[0];
let ret = usb.claimInterface(devicepipe, interfaces,true);
console.info(LOGTAG,'ret =>' + ret);
if(ret === 0 ){
let outEndpoint : usb.USBEndpoint = interfaces.endpoints[1];
let inEndpoint : usb.USBEndpoint = interfaces.endpoints[0];
this.isWXUSBDevice = true;
this.devicepipe = devicepipe
this.outEndpoint = outEndpoint
}else{
console.info(LOGTAG,'usb claimInterface failed')
}
}else{
console.info(LOGTAG,'isExit =>' +'false')
}
} catch (e) {
console.info(LOGTAG,'e=>' + JSON.stringify(e))
}
}
});
}
sendUSB =async (wuXiDataStr) => {
console.info(LOGTAG,'正在发送数据')
const {devicepipe,isWXUSBDevice,outEndpoint} = this;
console.info(LOGTAG,'正在发送数据')
if(isWXUSBDevice){
console.info(LOGTAG,wuXiDataStr)
const codeArr = plcStrToWXCodeArr(wuXiDataStr);
for(let i = 0; i < codeArr.length;i++){
try {
console.info(LOGTAG,'正在发送数据')
const f = await usb.bulkTransfer(devicepipe, outEndpoint, new Uint8Array(codeArr[i]))
console.info(LOGTAG,'发送成功数据长度为:' + f)
} catch (e) {
console.info(LOGTAG,JSON.stringify(e))
}
}
}else{
console.info(LOGTAG,'usb设备初始化失败')
}
}
}
// export default initUsbServicesFn

View File

@ -4,10 +4,34 @@ enum timeType {
fulltime = 1
}
// 获取当前时间
export function GetCurrentTime(type?: timeType): string {
if (type === 1) {
return dayTs().format("YYYYMMDDHHmmss")
} else {
return dayTs().format("YYYY-MM-DD HH:mm:ss")
}
}
//是否是多少天前
export function IsDaysAgo(date: string | number | Date, days: number = 2): boolean {
const today = dayTs(); // 当前日期
const target = dayTs(date).format("YYYY-MM-DD HH:mm:ss.SSS"); // 需要判断的日期
// 计算两个日期之间的差异天数
const diffDays = today.diff(target, 'day');
// 如果差异天数大于等于指定天数,则返回 true
return diffDays >= days;
}
/**
* 字符串转字节数组
* @param str
* @returns
*/
export function StringToBytes(str: string): Uint8Array {
const bytes = new Uint8Array(str.length);
for (let i = 0; i < str.length; i++) {
bytes[i] = str.charCodeAt(i);
}
return bytes;
}

View File

@ -0,0 +1,119 @@
// 导入USB接口api包。
import usb from '@ohos.usbManager';
import { UsbTag } from '../config';
import { StringToBytes } from './Common';
//plc数据转成无锡科研所usb字节数据
function plcStrToWXCodeArr(wuXiDataStr: string) {
// const arr = stringToArr(wuXiDataStr);
const arr = StringToBytes(wuXiDataStr);
// 数据包总长度和有效长度
const maxDataSize: number = 63;
// 存储所有数据包的数组
const packetArr: number[][] = [];
// 计算需要的数据包数量
const loop: number = Math.ceil(arr.length / maxDataSize);
for (let i = 0; i < loop; i++) {
// 截取当前数据包的数据
const thisPacket: number[] = Array.from(arr.slice(i * maxDataSize, (i + 1) * maxDataSize));
// 计算需要补齐的长度
const oSize: number = maxDataSize - thisPacket.length;
// 创建当前数据包
const packet: number[] = [thisPacket.length, ...thisPacket];
// 如果需要补齐,则填充 0x00
if (oSize > 0) {
packet.push(...new Array(oSize).fill(0x00));
}
// 将当前数据包添加到结果数组中
packetArr.push(packet);
}
return packetArr;
}
export default class UsbService {
public isWXUSBDevice: Boolean
private devicepipe: usb.USBDevicePipe
private outEndpoint: usb.USBEndpoint
sendUSB = async (wuXiDataStr: string) => {
console.info(UsbTag, '正在发送数据')
console.info(UsbTag, '正在发送数据')
if (this.isWXUSBDevice) {
console.info(UsbTag, wuXiDataStr)
const codeArr = plcStrToWXCodeArr(wuXiDataStr);
for (let i = 0; i < codeArr.length; i++) {
try {
console.info(UsbTag, '正在发送数据')
const f = await usb.bulkTransfer(this.devicepipe, this.outEndpoint, new Uint8Array(codeArr[i]))
console.info(UsbTag, '发送成功数据长度为:' + f)
} catch (e) {
console.info(UsbTag, JSON.stringify(e))
}
}
} else {
console.info(UsbTag, 'usb设备初始化失败')
}
}
init = async () => {
// 获取设备列表。
let deviceList: Array<usb.USBDevice> = usb.getDevices();
deviceList.forEach(async (device: usb.USBDevice) => {
console.log(UsbTag, JSON.stringify(device));
//无锡所检测设备接入
if (device.vendorId === 6790 && device.productId === 58409) {
// if(vendorId === 2385 && productId === 5734){
// 申请操作指定的device的操作权限。
try {
let bool = usb.hasRight(device.name);
console.info(UsbTag, 'bool =>' + bool)
const isExit = await usb.requestRight(device.name);
console.info(UsbTag, 'isExit =>' + isExit)
if (isExit) {
let devicepipe: usb.USBDevicePipe = usb.connectDevice(device);
let interfaces = device.configs[0].interfaces[0];
let ret = usb.claimInterface(devicepipe, interfaces, true);
console.info(UsbTag, 'ret =>' + ret);
if (ret === 0) {
let outEndpoint: usb.USBEndpoint = interfaces.endpoints[1];
this.isWXUSBDevice = true;
this.devicepipe = devicepipe
this.outEndpoint = outEndpoint
} else {
console.info(UsbTag, 'usb claimInterface failed')
}
} else {
console.info(UsbTag, 'isExit =>' + 'false')
}
} catch (e) {
console.info(UsbTag, 'e=>' + JSON.stringify(e))
}
}
});
}
constructor() {
//是否是无锡检测设备
this.isWXUSBDevice = false
this.devicepipe
this.init()
}
}
// export default initUsbServicesFn

View File

@ -1,13 +1,13 @@
import photoAccessHelper from '@ohos.file.photoAccessHelper';
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import { dateFormat, getCurrentTime, isSevenDaysAgo } from '../common/utils/tools';
// import rtsp_server from '@ohos.rtsprecord';
import { dateFormat, getCurrentTime } from '../common/utils/tools';
import record from '@ohos.rtsprecord';
import { FileHelper } from '../common/service/FileHelper';
import FileUtil from '../common/utils/File';
import { GlobalConfig } from '../config';
import promptAction from '@ohos.promptAction';
import common from '@ohos.app.ability.common';
import { IsDaysAgo } from './Common';
const rtsp_server = record.createServer();
//开始录屏
@ -50,7 +50,6 @@ export async function startRecordVideo(param, td, context, dir, path?, index?) {
fileName = `${date}_${path}_${index || num}.mp4`
}
// @ts-ignore
var recordResult = rtsp_server.startRecordVideo(context, video_uri, fileName, date, dir);
const handleId = recordResult.dataInt;
reslove(handleId)
@ -68,7 +67,6 @@ export async function endRecordVideo(record_handleObj) {
for (let key in record_handleObj) {
if (rtsp_server != null && record_handleObj[key] > 0) {
console.log(`Rtsprecord endRecordVideo begin`);
// @ts-ignore
var recordResult = rtsp_server.endRecordVideo(record_handleObj[key]);
console.log(`Rtsprecord endRecordVideo record_handle` + record_handleObj[key].dataInt + ` filename:` +
record_handleObj[key].fileName);
@ -144,7 +142,7 @@ export async function getUserAlbumItemByDisplayName(displayName: string, day?,
const albums = await fetchResult.getLastObject();
console.log('get getUserAlbumItemByDisplayName album111', albums.albumName)
if (isSevenDaysAgo(albums.albumName, day)) {
if (IsDaysAgo(albums.albumName, day)) {
deleteAllFileByPiC(albums.albumName, type)
}
console.log('get getUserAlbumItemByDisplayName album',)
@ -204,7 +202,7 @@ export async function delPic(day: number, type: number) {
let albumName = albums[i].albumName
// isSevenDaysAgo(albumName, day)
console.log('albumNamealbumName', albumName)
if (isSevenDaysAgo(albumName, day) && albumName != 'jt' && albumName != 'pz') {
if (IsDaysAgo(albumName, day) && albumName != 'jt' && albumName != 'pz') {
deleteAllFileByPiC(albumName, type)
}
@ -220,7 +218,6 @@ export async function takePhoto(param, context, dir, flag = 1, callback?) {
console.log('baoyihubaoyihu', video_uri, flag)
console.log(`baoyihu Rtsprecord baohaowen getVideoSnapshot fileName` + fileName);
// @ts-ignore
// var snapResult = rtsp_server.getVideoSnapshot(context, video_uri, '', dir);
if (flag == 0) {
rtsp_server.detectVideoSnapshotSize(video_uri, fileName, (err, snapResult) => {

View File

@ -1,8 +1,10 @@
import media from '@ohos.multimedia.media';
import App from '@system.app';
import { BusinessError } from '@ohos.base';
type AVPlayerCallback = (status: string, val?: string) => void;
export class voiceService {
private avPlayer: any = null;
private avPlayer: media.AVPlayer = null;
private fileSize: number = -1;
private fd: number = 0;
private playerName: string = '';
@ -10,7 +12,7 @@ export class voiceService {
private endFlag: Boolean = false;
private mediaArray: Array<any> = [];
constructor(callBack) {
constructor(callBack: AVPlayerCallback) {
// 创建avPlayer实例对象
media.createAVPlayer().then(video => {
this.avPlayer = video
@ -21,11 +23,11 @@ export class voiceService {
}
// 注册avplayer回调函数
setAVPlayerCallback(callBack) {
setAVPlayerCallback(callBack: AVPlayerCallback) {
console.log('jiangsong avPlayerFdSrc setAVPlayerCallback begin')
// error回调监听函数,当avPlayer在操作过程中出现错误时调用reset接口触发重置流程
this.avPlayer.on('error', (err) => {
this.avPlayer.on('error', (err: BusinessError) => {
console.error(`Invoke avPlayer failed, code is ${err.code}, message is ${err.message}`);
this.avPlayer.reset(); // 调用reset重置资源触发idle状态
})
@ -52,7 +54,7 @@ export class voiceService {
console.info('jiangsong AVPlayerstate initialized called.');
this.avPlayer.prepare().then(() => {
console.info('jiangsong AVPlayer prepare succeeded.');
}, (err) => {
}, (err: BusinessError) => {
console.error(`jiangsong Invoke prepare failed, code is ${err.code}, message is ${err.message}`);
});
callBack('initialized');
@ -91,7 +93,7 @@ export class voiceService {
// 以下为使用资源管理接口获取打包在HAP内的媒体资源文件并通过fdSrc属性进行播放示例
avPlayerFdSrc(name) {
const context=AppStorage.get('context')
const context = AppStorage.get('context')
context.resourceManager.getRawFd(name, async (error, value) => {
if (error != null) {
console.log(`jiangsong callback getRawFd failed error code: ${error.code}, message: ${error.message}.`);