Compare commits
	
		
			4 Commits
		
	
	
		
			e51f80f783
			...
			246980c371
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					246980c371 | ||
| 
						 | 
					8489d70c58 | ||
| 
						 | 
					1336100978 | ||
| 
						 | 
					0a9c068f43 | 
@ -1,167 +0,0 @@
 | 
				
			|||||||
class Md5 {
 | 
					 | 
				
			||||||
  private static _inst: Md5;
 | 
					 | 
				
			||||||
  public static get Instance(): Md5 {
 | 
					 | 
				
			||||||
    return this._inst || (this._inst = new Md5());
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  public get_md5(str: string): string {
 | 
					 | 
				
			||||||
    return this.md5(str);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  split(target: string | any[], step: number, markString: boolean = typeof target === "string") {
 | 
					 | 
				
			||||||
    if (typeof target === "string") target = target.split("");
 | 
					 | 
				
			||||||
    let result: any[] = target.map(
 | 
					 | 
				
			||||||
      (_, index: number) =>
 | 
					 | 
				
			||||||
        index % step === 0
 | 
					 | 
				
			||||||
          ? Array.from(Array(step).keys()).map((x: number) => target[index + x])
 | 
					 | 
				
			||||||
          : []
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
      .filter((x: any[]) => x.length > 0);
 | 
					 | 
				
			||||||
    if (markString) result = result.map((x: any[]) => x.join(""))
 | 
					 | 
				
			||||||
    return result;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  padding(str: string | any[], length: number, char: string, tail: boolean = true, isArray: boolean = Array.isArray(str)) {
 | 
					 | 
				
			||||||
    let arr;
 | 
					 | 
				
			||||||
    if (Array.isArray(str)) {
 | 
					 | 
				
			||||||
      arr = str;
 | 
					 | 
				
			||||||
    } else {
 | 
					 | 
				
			||||||
      arr = str.split("");
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    const paddingStr: any[] = this.range(length - str.length).map(() => char);
 | 
					 | 
				
			||||||
    const result = tail ? arr.concat(paddingStr) : paddingStr.concat(arr);
 | 
					 | 
				
			||||||
    return isArray ? result : result.join("");
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  little_endian(charCode: number) {
 | 
					 | 
				
			||||||
    return this.split(this.padding(charCode.toString(16), 8, "0", false), 2).reverse().join("");
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  range(...args: number[]) {
 | 
					 | 
				
			||||||
    const start: number = args.length === 1 ? 0 : args[0];
 | 
					 | 
				
			||||||
    const end: number = args.length === 2 ? args[1] : args[0] - 1;
 | 
					 | 
				
			||||||
    return Array.from(Array(end - start + 1).keys()).map((x: number) => x + start);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  to_binary(code: number, bit: number = 8, max: number = Math.pow(2, bit) - 1) {
 | 
					 | 
				
			||||||
    if (code < 0) throw new Error("code should be greater than: 0");
 | 
					 | 
				
			||||||
    if (code > max) throw new Error("code should be less than: " + max);
 | 
					 | 
				
			||||||
    return this.padding(code.toString(2), bit, "0", false);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  to_hex(code: number, bit: number = 8, max: number = Math.pow(16, bit) - 1) {
 | 
					 | 
				
			||||||
    if (code < 0) throw new Error("code should be greater than: 0");
 | 
					 | 
				
			||||||
    if (code > max) throw new Error("code should be less than: " + max);
 | 
					 | 
				
			||||||
    return this.padding(code.toString(16), bit, "0", false);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  to_code(str: string) {
 | 
					 | 
				
			||||||
    if (str.substr(0, 2).toLowerCase() === "0b") return parseInt(str.substr(2, 8), 2);
 | 
					 | 
				
			||||||
    if (str.substr(0, 2).toLowerCase() === "0x") return parseInt(str.substr(2, 8), 16);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  utf16_to_utf8(str: string) {
 | 
					 | 
				
			||||||
    return str.split("").map((char: string) => this.utf8_encode(char)).join("");
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  utf8_encode(char: string) {
 | 
					 | 
				
			||||||
    let utftext = "";
 | 
					 | 
				
			||||||
    const c = char.charCodeAt(0);
 | 
					 | 
				
			||||||
    if (c < 128) {
 | 
					 | 
				
			||||||
      utftext += String.fromCharCode(c);
 | 
					 | 
				
			||||||
    } else if ((c > 127) && (c < 2048)) {
 | 
					 | 
				
			||||||
      utftext += String.fromCharCode((c >> 6) | 0b11000000);
 | 
					 | 
				
			||||||
      utftext += String.fromCharCode((c & 0b00111111) | 0b10000000);
 | 
					 | 
				
			||||||
    } else {
 | 
					 | 
				
			||||||
      utftext += String.fromCharCode((c >> 12) | 0b11100000);
 | 
					 | 
				
			||||||
      utftext += String.fromCharCode(((c >> 6) & 0b00111111) | 0b10000000);
 | 
					 | 
				
			||||||
      utftext += String.fromCharCode((c & 0b00111111) | 0b10000000);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    return utftext;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  uint_add(...args: number[]) {
 | 
					 | 
				
			||||||
    const t = Uint32Array.from([0]);
 | 
					 | 
				
			||||||
    const x = Uint32Array.from(args);
 | 
					 | 
				
			||||||
    x.forEach(n => t[0] = t[0] + n);
 | 
					 | 
				
			||||||
    return t[0];
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  loop_shift_left(n: number, bits: number) {
 | 
					 | 
				
			||||||
    return (n << bits) | (n >>> (32 - bits));
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  A = 0x67452301;
 | 
					 | 
				
			||||||
  B = 0xefcdab89;
 | 
					 | 
				
			||||||
  C = 0x98badcfe;
 | 
					 | 
				
			||||||
  D = 0x10325476;
 | 
					 | 
				
			||||||
  F(b: number, c: number, d: number) {
 | 
					 | 
				
			||||||
    return (b & c) | (~b & d);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  G(b: number, c: number, d: number) {
 | 
					 | 
				
			||||||
    return (b & d) | (c & ~d);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  H(b: number, c: number, d: number) {
 | 
					 | 
				
			||||||
    return b ^ c ^ d;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  I(b: number, c: number, d: number) {
 | 
					 | 
				
			||||||
    return c ^ (b | ~d)
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  S = [
 | 
					 | 
				
			||||||
    7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
 | 
					 | 
				
			||||||
    5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
 | 
					 | 
				
			||||||
    4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
 | 
					 | 
				
			||||||
    6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21
 | 
					 | 
				
			||||||
  ]
 | 
					 | 
				
			||||||
  T(i: number) {
 | 
					 | 
				
			||||||
    return Math.floor(Math.pow(2, 32) * Math.abs(Math.sin(i + 1)));
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  x_index(i: number) {
 | 
					 | 
				
			||||||
    if (i >= 0 && i <= 15) return i;
 | 
					 | 
				
			||||||
    if (i >= 16 && i <= 31) return (5 * i + 1) % 16;
 | 
					 | 
				
			||||||
    if (i >= 32 && i <= 47) return (3 * i + 5) % 16;
 | 
					 | 
				
			||||||
    if (i >= 48 && i <= 63) return (7 * i) % 16;
 | 
					 | 
				
			||||||
    return 0;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  wrap(m: any) {
 | 
					 | 
				
			||||||
    return (a: number, b: number, c: number, d: number, x: number, s: number, t: number) => {
 | 
					 | 
				
			||||||
      // 循环左移
 | 
					 | 
				
			||||||
      return this.uint_add(this.loop_shift_left(this.uint_add(a, m(b, c, d), x, t), s), b);
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  porcess_message(str: string) {
 | 
					 | 
				
			||||||
    const length = str.length;
 | 
					 | 
				
			||||||
    const length_of_zero = Math.ceil(length / 64) * 64 - length - 8 - 1;
 | 
					 | 
				
			||||||
    str += String.fromCharCode(0b10000000);
 | 
					 | 
				
			||||||
    const strArray = this.padding(str.split(""), length + 1 + length_of_zero, String.fromCharCode(0));
 | 
					 | 
				
			||||||
    const tail = this.split(this.padding(this.to_binary(length * 8 % Math.pow(2, 64)), 64, "0"), 8).map(x => parseInt(x, 2));
 | 
					 | 
				
			||||||
    const head = (strArray as any[]).map(x => x.charCodeAt(0));
 | 
					 | 
				
			||||||
    return Uint32Array.from(
 | 
					 | 
				
			||||||
      this.split(head.concat(tail), 4)
 | 
					 | 
				
			||||||
        .map(x =>
 | 
					 | 
				
			||||||
          x.map((t: number) => this.padding(t.toString(16), 2, "0", false)).join("")
 | 
					 | 
				
			||||||
        )
 | 
					 | 
				
			||||||
        .map(x => parseInt(x, 16))
 | 
					 | 
				
			||||||
        .map(x => parseInt(this.little_endian(x), 16))
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  fghi(i: number) {
 | 
					 | 
				
			||||||
    if (i >= 0 && i <= 15) return this.F;
 | 
					 | 
				
			||||||
    if (i >= 16 && i <= 31) return this.G;
 | 
					 | 
				
			||||||
    if (i >= 32 && i <= 47) return this.H;
 | 
					 | 
				
			||||||
    if (i >= 48 && i <= 63) return this.I;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  fghi_wrapped(i: number) {
 | 
					 | 
				
			||||||
    return this.wrap(this.fghi(i));
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  //------------------------------------------------
 | 
					 | 
				
			||||||
  md5(str: string) {
 | 
					 | 
				
			||||||
    str = this.utf16_to_utf8(str);
 | 
					 | 
				
			||||||
    const uint32_array = this.porcess_message(str);
 | 
					 | 
				
			||||||
    const result = Uint32Array.from([this.A, this.B, this.C, this.D]);
 | 
					 | 
				
			||||||
    const chunks = this.split(Array.from(uint32_array), 16);
 | 
					 | 
				
			||||||
    for (const chunk of chunks) {
 | 
					 | 
				
			||||||
      const a = result[0];
 | 
					 | 
				
			||||||
      const b = result[1];
 | 
					 | 
				
			||||||
      const c = result[2];
 | 
					 | 
				
			||||||
      const d = result[3];
 | 
					 | 
				
			||||||
      for (let i = 0; i < 64; i++) {
 | 
					 | 
				
			||||||
        result[(4 - i % 4) % 4] = this.fghi_wrapped(i)(result[(4 - i % 4) % 4], result[((4 - i % 4) + 1) % 4], result[((4 - i % 4) + 2) % 4], result[((4 - i % 4) + 3) % 4], chunk[this.x_index(i)], this.S[i], this.T(i))
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
      result[0] = a + result[0];
 | 
					 | 
				
			||||||
      result[1] = b + result[1];
 | 
					 | 
				
			||||||
      result[2] = c + result[2];
 | 
					 | 
				
			||||||
      result[3] = d + result[3];
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    return Array.from(result).map(x => this.little_endian(x)).join("").toLowerCase();
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
export default Md5
 | 
					 | 
				
			||||||
@ -4,11 +4,10 @@ export interface TakePhotoCallbackData {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface ObtainSignalDataConfigType {
 | 
					export interface ObtainSignalDataConfigType {
 | 
				
			||||||
  //   UDP配置
 | 
					  //   三代机后置机UDP配置
 | 
				
			||||||
  udpLocalIp?: string
 | 
					  udpLocalIp?: string
 | 
				
			||||||
  udpLocalIpPort?: string
 | 
					  udpLocalIpPort?: string
 | 
				
			||||||
  udpOppositeIp?: string
 | 
					  udpOppositeIp?: string
 | 
				
			||||||
  udpOppositeIpPort?: string
 | 
					  udpOppositeIpPort?: string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -1,6 +1,5 @@
 | 
				
			|||||||
import router from '@ohos.router';
 | 
					import router from '@ohos.router';
 | 
				
			||||||
import TopLogo from './compontents/TopLogo';
 | 
					import TopLogo from './compontents/TopLogo';
 | 
				
			||||||
import Md5 from '../common/utils/md5';
 | 
					 | 
				
			||||||
import promptAction from '@ohos.promptAction';
 | 
					import promptAction from '@ohos.promptAction';
 | 
				
			||||||
import errorMsgDialog from './compontents/errorMsgDialog';
 | 
					import errorMsgDialog from './compontents/errorMsgDialog';
 | 
				
			||||||
import imageBtn from './compontents/imageBtn';
 | 
					import imageBtn from './compontents/imageBtn';
 | 
				
			||||||
@ -8,6 +7,7 @@ import { UserLoginType } from '../model/ExaminerLogin';
 | 
				
			|||||||
import { BusinessError } from '@ohos.base';
 | 
					import { BusinessError } from '@ohos.base';
 | 
				
			||||||
import { examinerLogin } from '../api/login';
 | 
					import { examinerLogin } from '../api/login';
 | 
				
			||||||
import { CarInfoType, ExaminerLoginInfo } from '../model/index';
 | 
					import { CarInfoType, ExaminerLoginInfo } from '../model/index';
 | 
				
			||||||
 | 
					import { CryptoJS } from '@ohos/crypto-js';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Entry
 | 
					@Entry
 | 
				
			||||||
@ -95,11 +95,13 @@ struct Index {
 | 
				
			|||||||
                      return
 | 
					                      return
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    const carInfo: CarInfoType = AppStorage.get<CarInfoType>('carInfo')
 | 
					                    const carInfo: CarInfoType = AppStorage.get<CarInfoType>('carInfo')
 | 
				
			||||||
 | 
					                    let password: string = CryptoJS.MD5(this.inputTextArr[1]).toString();
 | 
				
			||||||
                    const param: UserLoginType = {
 | 
					                    const param: UserLoginType = {
 | 
				
			||||||
                      carId: carInfo.carId as string,
 | 
					                      carId: carInfo.carId as string,
 | 
				
			||||||
                      examinationRoomId: carInfo.examinationRoomId as string,
 | 
					                      examinationRoomId: carInfo.examinationRoomId as string,
 | 
				
			||||||
                      username: this.inputTextArr[0],
 | 
					                      username: this.inputTextArr[0],
 | 
				
			||||||
                      password: Md5.Instance.get_md5(this.inputTextArr[1])
 | 
					                      // password: Md5.Instance.get_md5(this.inputTextArr[1])
 | 
				
			||||||
 | 
					                      password
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    this.type = '2'
 | 
					                    this.type = '2'
 | 
				
			||||||
                    this.errorDialog.open()
 | 
					                    this.errorDialog.open()
 | 
				
			||||||
 | 
				
			|||||||
@ -1,7 +1,6 @@
 | 
				
			|||||||
import { examinationStuAbsent, getExaminationItem, getExaminationStudentInfo } from '../api/userInfo';
 | 
					import { examinationStuAbsent, getExaminationItem, getExaminationStudentInfo } from '../api/userInfo';
 | 
				
			||||||
import router from '@ohos.router';
 | 
					import router from '@ohos.router';
 | 
				
			||||||
import TopLogo from './compontents/TopLogo';
 | 
					import TopLogo from './compontents/TopLogo';
 | 
				
			||||||
import Md5 from '../common/utils/md5';
 | 
					 | 
				
			||||||
import FaceCompare from './compontents/FaceCompare';
 | 
					import FaceCompare from './compontents/FaceCompare';
 | 
				
			||||||
import { writeObjectOut } from '../api/judge';
 | 
					import { writeObjectOut } from '../api/judge';
 | 
				
			||||||
import testNapi from '@ohos.idcard';
 | 
					import testNapi from '@ohos.idcard';
 | 
				
			||||||
@ -18,6 +17,7 @@ import { judgeConfig } from './judgeSDK/utils/judgeConfig';
 | 
				
			|||||||
import { initJudgeUdp } from '../common/utils/UdpJudge';
 | 
					import { initJudgeUdp } from '../common/utils/UdpJudge';
 | 
				
			||||||
import errorMsgDialog from './compontents/errorMsgDialog';
 | 
					import errorMsgDialog from './compontents/errorMsgDialog';
 | 
				
			||||||
import imageBtn from './compontents/imageBtn';
 | 
					import imageBtn from './compontents/imageBtn';
 | 
				
			||||||
 | 
					import { CryptoJS } from '@ohos/crypto-js';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
  BeginExamRequest,
 | 
					  BeginExamRequest,
 | 
				
			||||||
@ -664,9 +664,11 @@ struct UserInfo {
 | 
				
			|||||||
    this.type = '2'
 | 
					    this.type = '2'
 | 
				
			||||||
    this.errorDialog.open()
 | 
					    this.errorDialog.open()
 | 
				
			||||||
    this.updateTimeLimit = true
 | 
					    this.updateTimeLimit = true
 | 
				
			||||||
    const param = `<getExaminationStudentInfoReq><head><checkCode>${Md5.Instance.get_md5(this.carInfo.carId +
 | 
					    let md5Message: string = CryptoJS.MD5(this.carInfo.carId +
 | 
				
			||||||
    this.carInfo.examinationRoomId +
 | 
					    this.carInfo.examinationRoomId +
 | 
				
			||||||
    this.examinerLoginInfo.username)}</checkCode></head><body><carId>${this.carInfo.carId}</carId><examinationRoomId>${this.carInfo.examinationRoomId}</examinationRoomId><examinerName>${this.examinerLoginInfo.username}</examinerName><sfzmhm></sfzmhm></body></getExaminationStudentInfoReq>`
 | 
					    this.examinerLoginInfo.username).toString();
 | 
				
			||||||
 | 
					    const param =
 | 
				
			||||||
 | 
					      `<getExaminationStudentInfoReq><head><checkCode>${md5Message}</checkCode></head><body><carId>${this.carInfo.carId}</carId><examinationRoomId>${this.carInfo.examinationRoomId}</examinationRoomId><examinerName>${this.examinerLoginInfo.username}</examinerName><sfzmhm></sfzmhm></body></getExaminationStudentInfoReq>`
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
      getExaminationStudentInfo(param).then(async (res) => {
 | 
					      getExaminationStudentInfo(param).then(async (res) => {
 | 
				
			||||||
        console.log("temp log ", JSON.stringify(res))
 | 
					        console.log("temp log ", JSON.stringify(res))
 | 
				
			||||||
 | 
				
			|||||||
@ -1,227 +0,0 @@
 | 
				
			|||||||
class Md5 {
 | 
					 | 
				
			||||||
  private static _inst: Md5;
 | 
					 | 
				
			||||||
  A = 0x67452301;
 | 
					 | 
				
			||||||
  B = 0xefcdab89;
 | 
					 | 
				
			||||||
  C = 0x98badcfe;
 | 
					 | 
				
			||||||
  D = 0x10325476;
 | 
					 | 
				
			||||||
  S = [
 | 
					 | 
				
			||||||
    7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
 | 
					 | 
				
			||||||
    5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
 | 
					 | 
				
			||||||
    4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
 | 
					 | 
				
			||||||
    6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21
 | 
					 | 
				
			||||||
  ]
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  public static get Instance(): Md5 {
 | 
					 | 
				
			||||||
    return this._inst || (this._inst = new Md5());
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  public get_md5(str: string): string {
 | 
					 | 
				
			||||||
    return this.md5(str);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  split(target: string | any[], step: number, markString: boolean = typeof target === "string") {
 | 
					 | 
				
			||||||
    if (typeof target === "string") {
 | 
					 | 
				
			||||||
      target = target.split("");
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    let result: any[] = target.map(
 | 
					 | 
				
			||||||
      (_, index: number) =>
 | 
					 | 
				
			||||||
      index % step === 0
 | 
					 | 
				
			||||||
        ? Array.from(Array(step).keys()).map((x: number) => target[index + x])
 | 
					 | 
				
			||||||
        : []
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
      .filter((x: any[]) => x.length > 0);
 | 
					 | 
				
			||||||
    if (markString) {
 | 
					 | 
				
			||||||
      result = result.map((x: any[]) => x.join(""))
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    return result;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  padding(str: string | any[], length: number, char: string, tail: boolean = true,
 | 
					 | 
				
			||||||
    isArray: boolean = Array.isArray(str)) {
 | 
					 | 
				
			||||||
    let arr;
 | 
					 | 
				
			||||||
    if (Array.isArray(str)) {
 | 
					 | 
				
			||||||
      arr = str;
 | 
					 | 
				
			||||||
    } else {
 | 
					 | 
				
			||||||
      arr = str.split("");
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    const paddingStr: any[] = this.range(length - str.length).map(() => char);
 | 
					 | 
				
			||||||
    const result = tail ? arr.concat(paddingStr) : paddingStr.concat(arr);
 | 
					 | 
				
			||||||
    return isArray ? result : result.join("");
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  little_endian(charCode: number) {
 | 
					 | 
				
			||||||
    return this.split(this.padding(charCode.toString(16), 8, "0", false), 2).reverse().join("");
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  range(...args: number[]) {
 | 
					 | 
				
			||||||
    const start: number = args.length === 1 ? 0 : args[0];
 | 
					 | 
				
			||||||
    const end: number = args.length === 2 ? args[1] : args[0] - 1;
 | 
					 | 
				
			||||||
    return Array.from(Array(end - start + 1).keys()).map((x: number) => x + start);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  to_binary(code: number, bit: number = 8, max: number = Math.pow(2, bit) - 1) {
 | 
					 | 
				
			||||||
    if (code < 0) {
 | 
					 | 
				
			||||||
      throw new Error("code should be greater than: 0");
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if (code > max) {
 | 
					 | 
				
			||||||
      throw new Error("code should be less than: " + max);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    return this.padding(code.toString(2), bit, "0", false);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  to_hex(code: number, bit: number = 8, max: number = Math.pow(16, bit) - 1) {
 | 
					 | 
				
			||||||
    if (code < 0) {
 | 
					 | 
				
			||||||
      throw new Error("code should be greater than: 0");
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if (code > max) {
 | 
					 | 
				
			||||||
      throw new Error("code should be less than: " + max);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    return this.padding(code.toString(16), bit, "0", false);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  to_code(str: string) {
 | 
					 | 
				
			||||||
    if (str.substr(0, 2).toLowerCase() === "0b") {
 | 
					 | 
				
			||||||
      return parseInt(str.substr(2, 8), 2);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if (str.substr(0, 2).toLowerCase() === "0x") {
 | 
					 | 
				
			||||||
      return parseInt(str.substr(2, 8), 16);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  utf16_to_utf8(str: string) {
 | 
					 | 
				
			||||||
    return str.split("").map((char: string) => this.utf8_encode(char)).join("");
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  utf8_encode(char: string) {
 | 
					 | 
				
			||||||
    let utftext = "";
 | 
					 | 
				
			||||||
    const c = char.charCodeAt(0);
 | 
					 | 
				
			||||||
    if (c < 128) {
 | 
					 | 
				
			||||||
      utftext += String.fromCharCode(c);
 | 
					 | 
				
			||||||
    } else if ((c > 127) && (c < 2048)) {
 | 
					 | 
				
			||||||
      utftext += String.fromCharCode((c >> 6) | 0b11000000);
 | 
					 | 
				
			||||||
      utftext += String.fromCharCode((c & 0b00111111) | 0b10000000);
 | 
					 | 
				
			||||||
    } else {
 | 
					 | 
				
			||||||
      utftext += String.fromCharCode((c >> 12) | 0b11100000);
 | 
					 | 
				
			||||||
      utftext += String.fromCharCode(((c >> 6) & 0b00111111) | 0b10000000);
 | 
					 | 
				
			||||||
      utftext += String.fromCharCode((c & 0b00111111) | 0b10000000);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    return utftext;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  uint_add(...args: number[]) {
 | 
					 | 
				
			||||||
    const t = Uint32Array.from([0]);
 | 
					 | 
				
			||||||
    const x = Uint32Array.from(args);
 | 
					 | 
				
			||||||
    x.forEach(n => t[0] = t[0] + n);
 | 
					 | 
				
			||||||
    return t[0];
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  loop_shift_left(n: number, bits: number) {
 | 
					 | 
				
			||||||
    return (n << bits) | (n >>> (32 - bits));
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  F(b: number, c: number, d: number) {
 | 
					 | 
				
			||||||
    return (b & c) | (~b & d);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  G(b: number, c: number, d: number) {
 | 
					 | 
				
			||||||
    return (b & d) | (c & ~d);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  H(b: number, c: number, d: number) {
 | 
					 | 
				
			||||||
    return b ^ c ^ d;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  I(b: number, c: number, d: number) {
 | 
					 | 
				
			||||||
    return c ^ (b | ~d)
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  T(i: number) {
 | 
					 | 
				
			||||||
    return Math.floor(Math.pow(2, 32) * Math.abs(Math.sin(i + 1)));
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  x_index(i: number) {
 | 
					 | 
				
			||||||
    if (i >= 0 && i <= 15) {
 | 
					 | 
				
			||||||
      return i;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if (i >= 16 && i <= 31) {
 | 
					 | 
				
			||||||
      return (5 * i + 1) % 16;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if (i >= 32 && i <= 47) {
 | 
					 | 
				
			||||||
      return (3 * i + 5) % 16;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if (i >= 48 && i <= 63) {
 | 
					 | 
				
			||||||
      return (7 * i) % 16;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    return 0;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  wrap(m: any) {
 | 
					 | 
				
			||||||
    return (a: number, b: number, c: number, d: number, x: number, s: number, t: number) => {
 | 
					 | 
				
			||||||
      // 循环左移
 | 
					 | 
				
			||||||
      return this.uint_add(this.loop_shift_left(this.uint_add(a, m(b, c, d), x, t), s), b);
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  porcess_message(str: string) {
 | 
					 | 
				
			||||||
    const length = str.length;
 | 
					 | 
				
			||||||
    const length_of_zero = Math.ceil(length / 64) * 64 - length - 8 - 1;
 | 
					 | 
				
			||||||
    str += String.fromCharCode(0b10000000);
 | 
					 | 
				
			||||||
    const strArray = this.padding(str.split(""), length + 1 + length_of_zero, String.fromCharCode(0));
 | 
					 | 
				
			||||||
    const tail =
 | 
					 | 
				
			||||||
      this.split(this.padding(this.to_binary(length * 8 % Math.pow(2, 64)), 64, "0"), 8).map(x => parseInt(x, 2));
 | 
					 | 
				
			||||||
    const head = (strArray as any[]).map(x => x.charCodeAt(0));
 | 
					 | 
				
			||||||
    return Uint32Array.from(
 | 
					 | 
				
			||||||
      this.split(head.concat(tail), 4)
 | 
					 | 
				
			||||||
        .map(x =>
 | 
					 | 
				
			||||||
        x.map((t: number) => this.padding(t.toString(16), 2, "0", false)).join("")
 | 
					 | 
				
			||||||
        )
 | 
					 | 
				
			||||||
        .map(x => parseInt(x, 16))
 | 
					 | 
				
			||||||
        .map(x => parseInt(this.little_endian(x), 16))
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  fghi(i: number) {
 | 
					 | 
				
			||||||
    if (i >= 0 && i <= 15) {
 | 
					 | 
				
			||||||
      return this.F;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if (i >= 16 && i <= 31) {
 | 
					 | 
				
			||||||
      return this.G;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if (i >= 32 && i <= 47) {
 | 
					 | 
				
			||||||
      return this.H;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if (i >= 48 && i <= 63) {
 | 
					 | 
				
			||||||
      return this.I;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  fghi_wrapped(i: number) {
 | 
					 | 
				
			||||||
    return this.wrap(this.fghi(i));
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  //------------------------------------------------
 | 
					 | 
				
			||||||
  md5(str: string) {
 | 
					 | 
				
			||||||
    str = this.utf16_to_utf8(str);
 | 
					 | 
				
			||||||
    const uint32_array = this.porcess_message(str);
 | 
					 | 
				
			||||||
    const result = Uint32Array.from([this.A, this.B, this.C, this.D]);
 | 
					 | 
				
			||||||
    const chunks = this.split(Array.from(uint32_array), 16);
 | 
					 | 
				
			||||||
    for (const chunk of chunks) {
 | 
					 | 
				
			||||||
      const a = result[0];
 | 
					 | 
				
			||||||
      const b = result[1];
 | 
					 | 
				
			||||||
      const c = result[2];
 | 
					 | 
				
			||||||
      const d = result[3];
 | 
					 | 
				
			||||||
      for (let i = 0; i < 64; i++) {
 | 
					 | 
				
			||||||
        result[(4 - i % 4) % 4] =
 | 
					 | 
				
			||||||
          this.fghi_wrapped(i)(result[(4 - i % 4) % 4], result[((4 - i % 4) + 1) % 4], result[((4 - i % 4) + 2) % 4],
 | 
					 | 
				
			||||||
            result[((4 - i % 4) + 3) % 4], chunk[this.x_index(i)], this.S[i], this.T(i))
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
      result[0] = a + result[0];
 | 
					 | 
				
			||||||
      result[1] = b + result[1];
 | 
					 | 
				
			||||||
      result[2] = c + result[2];
 | 
					 | 
				
			||||||
      result[3] = d + result[3];
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    return Array.from(result).map(x => this.little_endian(x)).join("").toLowerCase();
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
export default Md5
 | 
					 | 
				
			||||||
@ -4,7 +4,8 @@ import { BusinessError } from '@ohos.base'
 | 
				
			|||||||
const TAG = '[TcpClient]'
 | 
					const TAG = '[TcpClient]'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TcpClient {
 | 
					export default class TcpClient {
 | 
				
			||||||
 | 
					  private static instance: TcpClient
 | 
				
			||||||
  private localIp: string = ''
 | 
					  private localIp: string = ''
 | 
				
			||||||
  private localIpPort: string = ''
 | 
					  private localIpPort: string = ''
 | 
				
			||||||
  private oppositeIp: string = ''
 | 
					  private oppositeIp: string = ''
 | 
				
			||||||
@ -12,7 +13,6 @@ class TcpClient {
 | 
				
			|||||||
  private tcpSendNum: number = 0
 | 
					  private tcpSendNum: number = 0
 | 
				
			||||||
  private tcp: socket.TCPSocket = null
 | 
					  private tcp: socket.TCPSocket = null
 | 
				
			||||||
  private events: Array<Function> = []
 | 
					  private events: Array<Function> = []
 | 
				
			||||||
  private static instance: TcpClient
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  constructor() {
 | 
					  constructor() {
 | 
				
			||||||
    if (!TcpClient.instance) {
 | 
					    if (!TcpClient.instance) {
 | 
				
			||||||
@ -31,9 +31,13 @@ class TcpClient {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  bindTcp(): Promise<void> {
 | 
					  bindTcp(): Promise<void> {
 | 
				
			||||||
    return this.tcp.bind({ address: this.localIp, port: parseInt(this.localIpPort), family: 1 }).then(() => {
 | 
					    return this.tcp.bind({
 | 
				
			||||||
 | 
					      address: this.localIp, port: parseInt(this.localIpPort), family: 1
 | 
				
			||||||
 | 
					    }).then(() => {
 | 
				
			||||||
      return this.tcp.connect({
 | 
					      return this.tcp.connect({
 | 
				
			||||||
        address: { address: this.oppositeIp, port: parseInt(this.oppositeIpPort) },
 | 
					        address: {
 | 
				
			||||||
 | 
					          address: this.oppositeIp, port: parseInt(this.oppositeIpPort)
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
        timeout: 6000
 | 
					        timeout: 6000
 | 
				
			||||||
      })
 | 
					      })
 | 
				
			||||||
    }).then(() => {
 | 
					    }).then(() => {
 | 
				
			||||||
@ -66,7 +70,9 @@ class TcpClient {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  sendMsg(data: string): Promise<void> {
 | 
					  sendMsg(data: string): Promise<void> {
 | 
				
			||||||
    return this.tcp?.send({ data }).catch(async (err: BusinessError) => {
 | 
					    return this.tcp?.send({
 | 
				
			||||||
 | 
					      data
 | 
				
			||||||
 | 
					    }).catch(async (err: BusinessError) => {
 | 
				
			||||||
      this.tcpSendNum++
 | 
					      this.tcpSendNum++
 | 
				
			||||||
      if (this.tcpSendNum > 10) {
 | 
					      if (this.tcpSendNum > 10) {
 | 
				
			||||||
        this.tcpSendNum = 0
 | 
					        this.tcpSendNum = 0
 | 
				
			||||||
@ -77,4 +83,4 @@ class TcpClient {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const tcpClient = new TcpClient()
 | 
					// export const tcpClient = new TcpClient()
 | 
				
			||||||
@ -91,25 +91,25 @@ export default class UdpClient {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//  获取后置机信号
 | 
					//  获取后置机信号
 | 
				
			||||||
class ObjUdpClient extends UdpClient {
 | 
					// class ObjUdpClient extends UdpClient {
 | 
				
			||||||
  async init(context: common.UIAbilityContext) {
 | 
					//   async init(context: common.UIAbilityContext) {
 | 
				
			||||||
    try {
 | 
					//     try {
 | 
				
			||||||
      const fileUtil = new FileUtils(context)
 | 
					//       const fileUtil = new FileUtils(context)
 | 
				
			||||||
      const data = await fileUtil.readFile("" + '/config/ipConfig.txt');
 | 
					//       const data = await fileUtil.readFile("" + '/config/ipConfig.txt');
 | 
				
			||||||
      if (data?.length > 0) {
 | 
					//       if (data?.length > 0) {
 | 
				
			||||||
        const result: IPConfig = JSON.parse(data)
 | 
					//         const result: IPConfig = JSON.parse(data)
 | 
				
			||||||
        this.create(result.udplocalIp, result.udplocalIpPort, result.udpOppositeIp, result.udpOppositeIpPort)
 | 
					//         this.create(result.udplocalIp, result.udplocalIpPort, result.udpOppositeIp, result.udpOppositeIpPort)
 | 
				
			||||||
      }
 | 
					//       }
 | 
				
			||||||
    } catch (e) {
 | 
					//     } catch (e) {
 | 
				
			||||||
      promptAction.showToast({
 | 
					//       promptAction.showToast({
 | 
				
			||||||
        message: "初始化obj udp失败"
 | 
					//         message: "初始化obj udp失败"
 | 
				
			||||||
      })
 | 
					//       })
 | 
				
			||||||
    }
 | 
					//     }
 | 
				
			||||||
  }
 | 
					//   }
 | 
				
			||||||
}
 | 
					// }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 给中心发送消息
 | 
					// 给中心发送GPS消息
 | 
				
			||||||
class CenterUDPClient extends UdpClient {
 | 
					class centerUDPClient extends UdpClient {
 | 
				
			||||||
  async init(context: common.UIAbilityContext) {
 | 
					  async init(context: common.UIAbilityContext) {
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
      const fileUtil = new FileUtils(context)
 | 
					      const fileUtil = new FileUtils(context)
 | 
				
			||||||
@ -146,10 +146,10 @@ class LightUDPClient extends UdpClient {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// obj
 | 
					// obj
 | 
				
			||||||
export const objUDPClient = new ObjUdpClient()
 | 
					// export const objUDPClient = new ObjUdpClient()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 中心
 | 
					// 中心GPS
 | 
				
			||||||
export const centerUDPClient = new CenterUDPClient()
 | 
					export const CenterUDPClient = new centerUDPClient()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 顶灯
 | 
					// 顶灯
 | 
				
			||||||
export const lightUDPClient = new LightUDPClient()
 | 
					export const lightUDPClient = new LightUDPClient()
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										45
									
								
								entry/src/main/ets/utils/business/CentralHeartbeat.ets
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								entry/src/main/ets/utils/business/CentralHeartbeat.ets
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,45 @@
 | 
				
			|||||||
 | 
					// 中心心跳/发送消息
 | 
				
			||||||
 | 
					import { EnvironmentConfigurationType } from '../../model';
 | 
				
			||||||
 | 
					import UdpClient from '../UdpUtils';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class centralHeartbeat {
 | 
				
			||||||
 | 
					  private centralHeartbeatUdp: UdpClient;
 | 
				
			||||||
 | 
					  private timer: number = -1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  constructor() {
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // 初始化
 | 
				
			||||||
 | 
					  init() {
 | 
				
			||||||
 | 
					    let config: EnvironmentConfigurationType =
 | 
				
			||||||
 | 
					      AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration")
 | 
				
			||||||
 | 
					    this.centralHeartbeatUdp = new UdpClient();
 | 
				
			||||||
 | 
					    this.centralHeartbeatUdp.create(config.udplocalIp, config.udplocalIpPort, config.udpOppositeIp,
 | 
				
			||||||
 | 
					      config.udpOppositeIpPort);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // 接受中心远程指令
 | 
				
			||||||
 | 
					  getData(callback: (data: ArrayBuffer) => void) {
 | 
				
			||||||
 | 
					    this.centralHeartbeatUdp.onMessage((data: ArrayBuffer) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      callback(data);
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // 发送消息
 | 
				
			||||||
 | 
					  sendData() {
 | 
				
			||||||
 | 
					    // 组装消息,一秒发送一次
 | 
				
			||||||
 | 
					    let data = "1";
 | 
				
			||||||
 | 
					    this.timer = setInterval(() => {
 | 
				
			||||||
 | 
					      this.centralHeartbeatUdp.sendMsg(data);
 | 
				
			||||||
 | 
					    }, 1000);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  //  关闭所有动作
 | 
				
			||||||
 | 
					  close() {
 | 
				
			||||||
 | 
					    clearInterval(this.timer);
 | 
				
			||||||
 | 
					    this.centralHeartbeatUdp.close()
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const CentralHeartbeat = new centralHeartbeat();
 | 
				
			||||||
							
								
								
									
										44
									
								
								entry/src/main/ets/utils/business/DifferentialSignal.ets
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								entry/src/main/ets/utils/business/DifferentialSignal.ets
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,44 @@
 | 
				
			|||||||
 | 
					//差分信号
 | 
				
			||||||
 | 
					import { EnvironmentConfigurationType } from '../../model';
 | 
				
			||||||
 | 
					import TcpClient from '../TcpUtils';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class differentialSignal {
 | 
				
			||||||
 | 
					  private differentialSignalTcp: TcpClient;
 | 
				
			||||||
 | 
					  private timer: number = -1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  constructor() {
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  init() {
 | 
				
			||||||
 | 
					    this.differentialSignalTcp = new TcpClient();
 | 
				
			||||||
 | 
					    let config: EnvironmentConfigurationType =
 | 
				
			||||||
 | 
					      AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration")
 | 
				
			||||||
 | 
					    this.differentialSignalTcp.init(config.tcplocalIp, config.tcplocalIpPort, config.tcpOppositeIp,
 | 
				
			||||||
 | 
					      config.tcpOppositePort);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // 发送消息
 | 
				
			||||||
 | 
					  sendData() {
 | 
				
			||||||
 | 
					    // 组装消息,一秒发送五次
 | 
				
			||||||
 | 
					    let data = "1";
 | 
				
			||||||
 | 
					    this.timer = setInterval(() => {
 | 
				
			||||||
 | 
					      this.differentialSignalTcp.sendMsg(data);
 | 
				
			||||||
 | 
					    }, 200);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  //   获取消息
 | 
				
			||||||
 | 
					  getData(callback: (data: ArrayBuffer) => void) {
 | 
				
			||||||
 | 
					    this.differentialSignalTcp.onMessage((data: ArrayBuffer) => {
 | 
				
			||||||
 | 
					      callback(data);
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // 关闭所有动作
 | 
				
			||||||
 | 
					  close() {
 | 
				
			||||||
 | 
					    clearInterval(this.timer);
 | 
				
			||||||
 | 
					    this.differentialSignalTcp.close()
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const DifferentialSignal = new differentialSignal();
 | 
				
			||||||
@ -1,12 +1,11 @@
 | 
				
			|||||||
import { GlobalConfig } from '../../config'
 | 
					import { GlobalConfig } from '../../config'
 | 
				
			||||||
import { ObtainSignalDataConfigType } from '../../model'
 | 
					import { EnvironmentConfigurationType } from '../../model'
 | 
				
			||||||
import UdpClient from '../UdpUtils'
 | 
					import UdpClient from '../UdpUtils'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 获取PLC GPS信号
 | 
				
			||||||
class obtainSignalData {
 | 
					class obtainSignalData {
 | 
				
			||||||
  // 三代机UDP
 | 
					  // 三代机UDP
 | 
				
			||||||
  private thirdGenerationMachineUdp: UdpClient
 | 
					  private thirdGenerationMachineUdp: UdpClient
 | 
				
			||||||
  // 三代机UDP配置
 | 
					 | 
				
			||||||
  private thirdGenerationMachineUdpConfig: ObtainSignalDataConfigType
 | 
					 | 
				
			||||||
  // 几代机
 | 
					  // 几代机
 | 
				
			||||||
  private modelNo: string = "3"
 | 
					  private modelNo: string = "3"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -15,16 +14,16 @@ class obtainSignalData {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  //   一些初始化
 | 
					  //   一些初始化
 | 
				
			||||||
  init(config: ObtainSignalDataConfigType) {
 | 
					  init() {
 | 
				
			||||||
    this.thirdGenerationMachineUdpConfig = config
 | 
					 | 
				
			||||||
    if (this.modelNo === "0") {
 | 
					    if (this.modelNo === "0") {
 | 
				
			||||||
    } else if (this.modelNo === "1") {
 | 
					    } else if (this.modelNo === "1") {
 | 
				
			||||||
 | 
					 | 
				
			||||||
    } else if (this.modelNo === "2") {
 | 
					    } else if (this.modelNo === "2") {
 | 
				
			||||||
    } else if (this.modelNo === "3") {
 | 
					    } else if (this.modelNo === "3") {
 | 
				
			||||||
      //   初始化UDP
 | 
					      //   初始化UDP
 | 
				
			||||||
 | 
					      let config: EnvironmentConfigurationType =
 | 
				
			||||||
 | 
					        AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration")
 | 
				
			||||||
      this.thirdGenerationMachineUdp = new UdpClient()
 | 
					      this.thirdGenerationMachineUdp = new UdpClient()
 | 
				
			||||||
      this.thirdGenerationMachineUdp.create(config.udpLocalIp, config.udpLocalIpPort, config.udpOppositeIp,
 | 
					      this.thirdGenerationMachineUdp.create(config.udplocalIp, config.udplocalIpPort, config.udpOppositeIp,
 | 
				
			||||||
        config.udpOppositeIpPort)
 | 
					        config.udpOppositeIpPort)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -52,6 +51,20 @@ class obtainSignalData {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    //   一体机
 | 
					    //   一体机
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  //   发送数据
 | 
				
			||||||
 | 
					  sendData(data: string) {
 | 
				
			||||||
 | 
					    //   一代机
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    //   二代机
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    //   三代机 通过UDP发送数据
 | 
				
			||||||
 | 
					    if (this.modelNo === "3") {
 | 
				
			||||||
 | 
					      this.thirdGenerationMachineUdp.sendMsg(data)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    //   一体机
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const ObtainSignalData = new obtainSignalData()
 | 
					export const ObtainSignalData = new obtainSignalData()
 | 
				
			||||||
@ -5,9 +5,17 @@
 | 
				
			|||||||
  "lockfileVersion": 3,
 | 
					  "lockfileVersion": 3,
 | 
				
			||||||
  "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
 | 
					  "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
 | 
				
			||||||
  "specifiers": {
 | 
					  "specifiers": {
 | 
				
			||||||
 | 
					    "@ohos/crypto-js@2.0.3": "@ohos/crypto-js@2.0.3",
 | 
				
			||||||
    "@ohos/hypium@1.0.6": "@ohos/hypium@1.0.6"
 | 
					    "@ohos/hypium@1.0.6": "@ohos/hypium@1.0.6"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "packages": {
 | 
					  "packages": {
 | 
				
			||||||
 | 
					    "@ohos/crypto-js@2.0.3": {
 | 
				
			||||||
 | 
					      "name": "@ohos/crypto-js",
 | 
				
			||||||
 | 
					      "version": "2.0.3",
 | 
				
			||||||
 | 
					      "integrity": "sha512-LuHaR1kD5PxnOXnuR1fWvPwGtbed9Q/QGzk6JOh8y5Wdzvi8brPesODZiaWf9scOVRHsbTPOtZw91vWB35p1vQ==",
 | 
				
			||||||
 | 
					      "resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/crypto-js/-/crypto-js-2.0.3.har",
 | 
				
			||||||
 | 
					      "registryType": "ohpm"
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
    "@ohos/hypium@1.0.6": {
 | 
					    "@ohos/hypium@1.0.6": {
 | 
				
			||||||
      "name": "@ohos/hypium",
 | 
					      "name": "@ohos/hypium",
 | 
				
			||||||
      "version": "1.0.6",
 | 
					      "version": "1.0.6",
 | 
				
			||||||
 | 
				
			|||||||
@ -9,5 +9,7 @@
 | 
				
			|||||||
  "description": "Please describe the basic information.",
 | 
					  "description": "Please describe the basic information.",
 | 
				
			||||||
  "main": "",
 | 
					  "main": "",
 | 
				
			||||||
  "version": "1.0.0",
 | 
					  "version": "1.0.0",
 | 
				
			||||||
  "dependencies": {}
 | 
					  "dependencies": {
 | 
				
			||||||
 | 
					    "@ohos/crypto-js": "2.0.3"
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user