feat:修改
This commit is contained in:
parent
b80d575b96
commit
738e83c356
@ -3,7 +3,6 @@ import util from '@ohos.util'
|
||||
import promptAction from '@ohos.promptAction'
|
||||
import TcpToByte from './utils/tcp2byte'
|
||||
import {bytesToDecimal} from './utils/tools'
|
||||
|
||||
const TAG = '[TCP2BYTE]'
|
||||
|
||||
|
||||
@ -12,9 +11,10 @@ interface RES {
|
||||
message?: string
|
||||
}
|
||||
|
||||
|
||||
const config = {
|
||||
address: '172.37.55.191',
|
||||
port: 40000
|
||||
address: '114.55.125.222',
|
||||
port: 50189
|
||||
}
|
||||
|
||||
export default async function tcp2ByteRequest(data): Promise<RES> {
|
||||
@ -28,11 +28,7 @@ export default async function tcp2ByteRequest(data): Promise<RES> {
|
||||
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) {
|
||||
@ -78,7 +74,6 @@ function handSendMessage(client: socket.TCPSocket, type, data) {
|
||||
case '02-21-000012':
|
||||
case '02-21-000014':
|
||||
data.forEach((item) => {
|
||||
console.log(TAG, JSON.stringify(item))
|
||||
client.send({ data: new Uint8Array(item).buffer })
|
||||
})
|
||||
break;
|
||||
@ -88,17 +83,18 @@ 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 {
|
||||
|
||||
const receiveData = new Uint8Array(rData)
|
||||
console.info(TAG, 'receiveData=>' + JSON.stringify(receiveData))
|
||||
//返回的消息类型
|
||||
const messageType = receiveData[1];
|
||||
console.info(TAG, 'receiveData messageType=>' + JSON.stringify(receiveData))
|
||||
|
||||
//流水号
|
||||
const lsh = bytesToDecimal([receiveData[2],receiveData[3]]);
|
||||
|
||||
@ -122,10 +118,10 @@ function handReceiveMessage(client: socket.TCPSocket, sendData, rData: ArrayBuff
|
||||
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)
|
||||
console.info(TAG + messageType, 'markContent=>' + markContent)
|
||||
const tipLength = receiveData[13];
|
||||
const messageContent = decoder.decodeWithStream(receiveData.slice(13 + markLength, 13 + markLength + tipLength));
|
||||
console.info(TAG, 'messageContent=>' + messageContent)
|
||||
console.info(TAG + messageType, 'messageContent=>' + messageContent)
|
||||
return {
|
||||
code:markContent,
|
||||
message:messageContent
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user