From b966891f352c3c3a89d33d8220bccd6e230c0474 Mon Sep 17 00:00:00 2001 From: wangzhongjie Date: Wed, 5 Mar 2025 10:07:32 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build-profile.json5 | 10 +++--- entry/build-profile.json5 | 5 +++ entry/oh-package-lock.json5 | 8 +++-- entry/src/main/ets/tcp2byte/index.ts | 50 ++++++++++++++++------------ hvigor/hvigor-config.json5 | 4 +-- oh-package-lock.json5 | 8 +++-- 6 files changed, 50 insertions(+), 35 deletions(-) diff --git a/build-profile.json5 b/build-profile.json5 index 5d0750fa..60be28d1 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -4,13 +4,13 @@ { "name": "default", "material": { - "certpath": "/Users/surenjun/.ohos/config/openharmony/auto_ohos_default_subject-two_com.oh.dts.cer", - "storePassword": "0000001BE4BBADDF656A884E7A7BB5FD51F64FBB61DD24A944FEA969482DD693210ED5FF3D29F13642E3A3", + "certpath": "/Users/wangzhongjie/.ohos/config/openharmony/default_subject-two_Kl4t-ZSvZeuUm9s8O-e6FIH2VFR_OaNyhDP8kPjIWgU=.cer", + "storePassword": "0000001B1A6C605B348CE1F76970E037662E7240FC9A88762FF9CC0FBF41CD85BB9F44F66A7002A0A4226D", "keyAlias": "debugKey", - "keyPassword": "0000001BDEFFDC280B45617E7FC447CB21F2D133540301F543454643D3F5E9F6E5ED2A583A7FA92B260433", - "profile": "/Users/surenjun/.ohos/config/openharmony/auto_ohos_default_subject-two_com.oh.dts.p7b", + "keyPassword": "0000001B0C7AC8946180EE4BBCB5880D04DF499C741EBA9485672DD1C6902D3944018F866199FFD1B10B30", + "profile": "/Users/wangzhongjie/.ohos/config/openharmony/default_subject-two_Kl4t-ZSvZeuUm9s8O-e6FIH2VFR_OaNyhDP8kPjIWgU=.p7b", "signAlg": "SHA256withECDSA", - "storeFile": "/Users/surenjun/.ohos/config/openharmony/auto_ohos_default_subject-two_com.oh.dts.p12" + "storeFile": "/Users/wangzhongjie/.ohos/config/openharmony/default_subject-two_Kl4t-ZSvZeuUm9s8O-e6FIH2VFR_OaNyhDP8kPjIWgU=.p12" } } ], diff --git a/entry/build-profile.json5 b/entry/build-profile.json5 index 2160ea13..6cfa095d 100644 --- a/entry/build-profile.json5 +++ b/entry/build-profile.json5 @@ -2,6 +2,11 @@ "apiType": 'stageMode', "buildOption": { "externalNativeOptions": { + "abiFilters": [ + "arm64-v8a", + "armeabi-v7a", + "x86_64" + ], "path": "./src/main/cpp/CMakeLists.txt", "arguments": "", "cppFlags": "", diff --git a/entry/oh-package-lock.json5 b/entry/oh-package-lock.json5 index bc40219d..1f023b33 100644 --- a/entry/oh-package-lock.json5 +++ b/entry/oh-package-lock.json5 @@ -1,13 +1,15 @@ { - "lockfileVersion": 1, + "lockfileVersion": 2, "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", "specifiers": { "@ohos/hypium@1.0.6": "@ohos/hypium@1.0.6" }, "packages": { "@ohos/hypium@1.0.6": { - "resolved": "https://repo.harmonyos.com/ohpm/@ohos/hypium/-/hypium-1.0.6.tgz", - "integrity": "sha512-bb3DWeWhYrFqj9mPFV3yZQpkm36kbcK+YYaeY9g292QKSjOdmhEIQR2ULPvyMsgSR4usOBf5nnYrDmaCCXirgQ==" + "resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/hypium/-/hypium-1.0.6.tgz", + "integrity": "sha512-bb3DWeWhYrFqj9mPFV3yZQpkm36kbcK+YYaeY9g292QKSjOdmhEIQR2ULPvyMsgSR4usOBf5nnYrDmaCCXirgQ==", + "registryType": "ohpm", + "shasum": "3f5fed65372633233264b3447705b0831dfe7ea1" } } } \ No newline at end of file diff --git a/entry/src/main/ets/tcp2byte/index.ts b/entry/src/main/ets/tcp2byte/index.ts index 3f37d965..eb5f2dc5 100644 --- a/entry/src/main/ets/tcp2byte/index.ts +++ b/entry/src/main/ets/tcp2byte/index.ts @@ -2,18 +2,19 @@ import socket from '@ohos.net.socket' import util from '@ohos.util' import promptAction from '@ohos.promptAction' import TcpToByte from './utils/tcp2byte' -import {bytesToDecimal} from './utils/tools' +import { bytesToDecimal } from './utils/tools' + const TAG = '[TCP2BYTE]' interface RES { - code: number|string, + code: number | string, message?: string } const config = { - address: '114.55.125.222', - port: 50189 + address: '172.37.55.191', + port: 40000 } export default async function tcp2ByteRequest(data): Promise { @@ -27,7 +28,11 @@ export default async function tcp2ByteRequest(data): Promise { console.info(TAG, 'sendData=>' + JSON.stringify(sendData)) try { - await tcpClient.connect({address: {address, port}}) + await tcpClient.connect({ + address: { + address, port + } + }) //发送消息 handSendMessage(tcpClient, data.sjbs, sendData) } catch (e) { @@ -41,8 +46,8 @@ export default async function tcp2ByteRequest(data): Promise { //收到消息 tcpClient.on('message', (data) => { - const res = handReceiveMessage(tcpClient, sendData, data) - if(res){ + const res = handReceiveMessage(tcpClient, sendData, data.message) + if (res) { tcpClient.close() resolve(res) } @@ -68,7 +73,7 @@ export default async function tcp2ByteRequest(data): Promise { function handSendMessage(client: socket.TCPSocket, type, data) { switch (type) { - //开始考试 过程照片 考试结束需要分包 + //开始考试 过程照片 考试结束需要分包 case '02-21-000009': case '02-21-000012': case '02-21-000014': @@ -83,45 +88,46 @@ function handSendMessage(client: socket.TCPSocket, type, data) { client.send({ data: new Uint8Array(data).buffer }) break; - default:break; + default: + break; } } //处理接收的数据 -function handReceiveMessage(client: socket.TCPSocket, sendData, receiveData):RES { +function handReceiveMessage(client: socket.TCPSocket, sendData, receiveData): RES { console.info(TAG, 'receiveData=>' + JSON.stringify(receiveData)) //返回的消息类型 const messageType = receiveData[1]; //流水号 - const lsh = bytesToDecimal([receiveData[2],receiveData[3]]); + const lsh = bytesToDecimal([receiveData[2], receiveData[3]]); //开始补包 - if(messageType === 0xF0){ + if (messageType === 0xF0) { //获取消息体长度 const messageLength = receiveData[12] //分包总数 - const packages = receiveData.slice(13,13 + messageLength*2); + const packages = receiveData.slice(13, 13 + messageLength * 2); const forArr = new Array(packages).fill(1) - forArr.forEach((item,index)=>{ + forArr.forEach((item, index) => { const start = index * 2; const end = start + 2; - const packageIndex = bytesToDecimal([start,end]); + const packageIndex = bytesToDecimal([start, end]); console.info(TAG, '补包内容' + JSON.stringify(new Uint8Array(sendData[packageIndex]))) - client.send({data:new Uint8Array(sendData[packageIndex]).buffer}); + client.send({ data: new Uint8Array(sendData[packageIndex]).buffer }); }) - }else{ - const decoder = util.TextDecoder.create('utf-8'); - const messageLength = bytesToDecimal([receiveData[9],receiveData[10]]); + } else { + const decoder = util.TextDecoder.create('utf-8'); + const messageLength = bytesToDecimal([receiveData[9], receiveData[10]]); const markLength = receiveData[11]; - const markContent = decoder.decodeWithStream(receiveData.slice(12, 12 + markLength )); + const markContent = decoder.decodeWithStream(receiveData.slice(12, 12 + markLength)); console.info(TAG, 'markContent=>' + markContent) const tipLength = receiveData[13]; const messageContent = decoder.decodeWithStream(receiveData.slice(13 + markLength, 13 + markLength + tipLength)); console.info(TAG, 'messageContent=>' + messageContent) return { - code:markContent, - message:messageContent + code: markContent, + message: messageContent } } } \ No newline at end of file diff --git a/hvigor/hvigor-config.json5 b/hvigor/hvigor-config.json5 index 122677b1..64655e69 100644 --- a/hvigor/hvigor-config.json5 +++ b/hvigor/hvigor-config.json5 @@ -1,6 +1,6 @@ { - "hvigorVersion": "3.0.9", + "hvigorVersion": "3.2.4", "dependencies": { - "@ohos/hvigor-ohos-plugin": "3.0.9" + "@ohos/hvigor-ohos-plugin": "3.2.4" } } \ No newline at end of file diff --git a/oh-package-lock.json5 b/oh-package-lock.json5 index bc40219d..1f023b33 100644 --- a/oh-package-lock.json5 +++ b/oh-package-lock.json5 @@ -1,13 +1,15 @@ { - "lockfileVersion": 1, + "lockfileVersion": 2, "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", "specifiers": { "@ohos/hypium@1.0.6": "@ohos/hypium@1.0.6" }, "packages": { "@ohos/hypium@1.0.6": { - "resolved": "https://repo.harmonyos.com/ohpm/@ohos/hypium/-/hypium-1.0.6.tgz", - "integrity": "sha512-bb3DWeWhYrFqj9mPFV3yZQpkm36kbcK+YYaeY9g292QKSjOdmhEIQR2ULPvyMsgSR4usOBf5nnYrDmaCCXirgQ==" + "resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/hypium/-/hypium-1.0.6.tgz", + "integrity": "sha512-bb3DWeWhYrFqj9mPFV3yZQpkm36kbcK+YYaeY9g292QKSjOdmhEIQR2ULPvyMsgSR4usOBf5nnYrDmaCCXirgQ==", + "registryType": "ohpm", + "shasum": "3f5fed65372633233264b3447705b0831dfe7ea1" } } } \ No newline at end of file From 5d367da241f281d3d0e480cb553ca7fd07e3f167 Mon Sep 17 00:00:00 2001 From: wangzhongjie Date: Wed, 5 Mar 2025 10:57:06 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/tcp2byte/index.ts | 50 ++++++++++++++++------------ 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/entry/src/main/ets/tcp2byte/index.ts b/entry/src/main/ets/tcp2byte/index.ts index 4a280351..dcb838f3 100644 --- a/entry/src/main/ets/tcp2byte/index.ts +++ b/entry/src/main/ets/tcp2byte/index.ts @@ -2,18 +2,19 @@ import socket from '@ohos.net.socket' import util from '@ohos.util' import promptAction from '@ohos.promptAction' import TcpToByte from './utils/tcp2byte' -import {bytesToDecimal} from './utils/tools' +import { bytesToDecimal } from './utils/tools' + const TAG = '[TCP2BYTE]' interface RES { - code: number|string, + code: number | string, message?: string } const config = { - address: '114.55.125.222', - port: 50189 + address: '172.37.55.191', + port: 40000 } export default async function tcp2ByteRequest(data): Promise { @@ -27,7 +28,11 @@ export default async function tcp2ByteRequest(data): Promise { console.info(TAG, 'sendData=>' + JSON.stringify(sendData)) try { - await tcpClient.connect({address: {address, port}}) + await tcpClient.connect({ + address: { + address, port + } + }) //发送消息 handSendMessage(tcpClient, data.sjbs, sendData) } catch (e) { @@ -42,7 +47,7 @@ export default async function tcp2ByteRequest(data): Promise { //收到消息 tcpClient.on('message', (data) => { const res = handReceiveMessage(tcpClient, sendData, data.message) - if(res){ + if (res) { tcpClient.close() resolve(res) } @@ -68,7 +73,7 @@ export default async function tcp2ByteRequest(data): Promise { function handSendMessage(client: socket.TCPSocket, type, data) { switch (type) { - //开始考试 过程照片 考试结束需要分包 + //开始考试 过程照片 考试结束需要分包 case '02-21-000009': case '02-21-000012': case '02-21-000014': @@ -83,45 +88,46 @@ function handSendMessage(client: socket.TCPSocket, type, data) { client.send({ data: new Uint8Array(data).buffer }) break; - default:break; + default: + break; } } //处理接收的数据 -function handReceiveMessage(client: socket.TCPSocket, sendData, receiveData):RES { +function handReceiveMessage(client: socket.TCPSocket, sendData, receiveData: ArrayBuffer): RES { //返回的消息类型 const messageType = receiveData[1]; //流水号 - const lsh = bytesToDecimal([receiveData[2],receiveData[3]]); + const lsh = bytesToDecimal([receiveData[2], receiveData[3]]); //开始补包 - if(messageType === 0xF0){ + if (messageType === 0xF0) { //获取消息体长度 const messageLength = receiveData[12] //分包总数 - const packages = receiveData.slice(13,13 + messageLength*2); + const packages = receiveData.slice(13, 13 + messageLength * 2); const forArr = new Array(packages).fill(1) - forArr.forEach((item,index)=>{ + forArr.forEach((item, index) => { const start = index * 2; const end = start + 2; - const packageIndex = bytesToDecimal([start,end]); + const packageIndex = bytesToDecimal([start, end]); console.info(TAG, '补包内容' + JSON.stringify(new Uint8Array(sendData[packageIndex]))) - client.send({data:new Uint8Array(sendData[packageIndex]).buffer}); + client.send({ data: new Uint8Array(sendData[packageIndex]).buffer }); }) - }else{ - const decoder = util.TextDecoder.create('utf-8'); - const messageLength = bytesToDecimal([receiveData[9],receiveData[10]]); - const markLength = receiveData[11].buffer; - const markContent = decoder.decodeWithStream(receiveData.slice(12, 12 + markLength )); + } else { + const decoder = util.TextDecoder.create('utf-8'); + const messageLength = bytesToDecimal([receiveData[9], receiveData[10]]); + const markLength = receiveData[11]; + const markContent = decoder.decodeWithStream(receiveData.slice(12, 12 + markLength)); console.info(TAG, 'markContent=>' + markContent) const tipLength = receiveData[13].buffer; const messageContent = decoder.decodeWithStream(receiveData.slice(13 + markLength, 13 + markLength + tipLength)); console.info(TAG, 'messageContent=>' + messageContent) return { - code:markContent, - message:messageContent + code: markContent, + message: messageContent } } } \ No newline at end of file From 097711c46c03b685fc83a906659f0e5d240a6771 Mon Sep 17 00:00:00 2001 From: wangzhongjie Date: Wed, 5 Mar 2025 11:22:14 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/tcp2byte/index.ts | 48 ++++++++++++++++------------ 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/entry/src/main/ets/tcp2byte/index.ts b/entry/src/main/ets/tcp2byte/index.ts index 3fdbc7bf..5dec3f24 100644 --- a/entry/src/main/ets/tcp2byte/index.ts +++ b/entry/src/main/ets/tcp2byte/index.ts @@ -2,18 +2,19 @@ import socket from '@ohos.net.socket' import util from '@ohos.util' import promptAction from '@ohos.promptAction' import TcpToByte from './utils/tcp2byte' -import {bytesToDecimal} from './utils/tools' +import { bytesToDecimal } from './utils/tools' + const TAG = '[TCP2BYTE]' interface RES { - code: number|string, + code: number | string, message?: string } const config = { - address: '114.55.125.222', - port: 50189 + address: '172.37.55.191', + port: 40000 } export default async function tcp2ByteRequest(data): Promise { @@ -27,7 +28,11 @@ export default async function tcp2ByteRequest(data): Promise { console.info(TAG, 'sendData=>' + JSON.stringify(sendData)) try { - await tcpClient.connect({address: {address, port}}) + await tcpClient.connect({ + address: { + address, port + } + }) //发送消息 handSendMessage(tcpClient, data.sjbs, sendData) } catch (e) { @@ -42,7 +47,7 @@ export default async function tcp2ByteRequest(data): Promise { //收到消息 tcpClient.on('message', (data) => { const res = handReceiveMessage(tcpClient, sendData, data.message) - if(res){ + if (res) { tcpClient.close() resolve(res) } @@ -68,7 +73,7 @@ export default async function tcp2ByteRequest(data): Promise { function handSendMessage(client: socket.TCPSocket, type, data) { switch (type) { - //开始考试 过程照片 考试结束需要分包 + //开始考试 过程照片 考试结束需要分包 case '02-21-000009': case '02-21-000012': case '02-21-000014': @@ -83,46 +88,47 @@ function handSendMessage(client: socket.TCPSocket, type, data) { client.send({ data: new Uint8Array(data).buffer }) break; - default:break; + default: + break; } } //处理接收的数据 -function handReceiveMessage(client: socket.TCPSocket, sendData, rData:ArrayBuffer):RES { +function handReceiveMessage(client: socket.TCPSocket, sendData, rData: ArrayBuffer): RES { const receiveData = new Uint8Array(rData) //返回的消息类型 const messageType = receiveData[1]; //流水号 - const lsh = bytesToDecimal([receiveData[2],receiveData[3]]); + const lsh = bytesToDecimal([receiveData[2], receiveData[3]]); //开始补包 - if(messageType === 0xF0){ + if (messageType === 0xF0) { //获取消息体长度 const messageLength = receiveData[12] //分包总数 - const packages = bytesToDecimal(receiveData.slice(13,13 + messageLength*2)); + const packages = bytesToDecimal(receiveData.slice(13, 13 + messageLength * 2)); const forArr = new Array(packages).fill(1) - forArr.forEach((item,index)=>{ + forArr.forEach((item, index) => { const start = index * 2; const end = start + 2; - const packageIndex = bytesToDecimal([start,end]); + const packageIndex = bytesToDecimal([start, end]); console.info(TAG, '补包内容' + JSON.stringify(new Uint8Array(sendData[packageIndex]))) - client.send({data:new Uint8Array(sendData[packageIndex]).buffer}); + client.send({ data: new Uint8Array(sendData[packageIndex]).buffer }); }) - }else{ - const decoder = util.TextDecoder.create('utf-8'); - const messageLength = bytesToDecimal([receiveData[9],receiveData[10]]); + } else { + const decoder = util.TextDecoder.create('utf-8'); + const messageLength = bytesToDecimal([receiveData[9], receiveData[10]]); const markLength = receiveData[11]; - const markContent = decoder.decodeWithStream(receiveData.slice(12, 12 + markLength )); + const markContent = decoder.decodeWithStream(receiveData.slice(12, 12 + markLength)); console.info(TAG, 'markContent=>' + markContent) const tipLength = receiveData[13]; const messageContent = decoder.decodeWithStream(receiveData.slice(13 + markLength, 13 + markLength + tipLength)); console.info(TAG, 'messageContent=>' + messageContent) return { - code:markContent, - message:messageContent + code: markContent, + message: messageContent } } } \ No newline at end of file