Hi, I know there have been some topics but I'm curious if there is a more efficient solution to my problem.
As most of you probably know in VB6 CopyMemory is a very fast and efficient way to copy bytes between different data types.
I use it frequently to fill arrays with data or get data out of arrays into variables.
One of my use cases would be sth. like this:
As you can see it is super simple to split data from a serial stream (held in a byte array) into its components.
In B4X I'm not sure what the best way to do this would be, I'm trying sth. like this, which works but is kind of a mess:
Any recommendations?
As most of you probably know in VB6 CopyMemory is a very fast and efficient way to copy bytes between different data types.
I use it frequently to fill arrays with data or get data out of arrays into variables.
One of my use cases would be sth. like this:
VB6 CopyMemory:
Public Function DecodeFullHPS3DMessage(ByRef MessagePayload() As Byte, ByRef AvgDist As Long, ByRef MaxDist As Long, ByRef MinDist As Long, ByRef DepthData() As Byte)
AvgDist = 0
CopyMemory AvgDist, MessagePayload(2), 2
MaxDist = 0
CopyMemory MaxDist, MessagePayload(12), 2
MinDist = 0
CopyMemory MinDist, MessagePayload(14), 2
ReDim DepthData(19199)
CopyMemory DepthData(0), MessagePayload(24), 19200
End Function
In B4X I'm not sure what the best way to do this would be, I'm trying sth. like this, which works but is kind of a mess:
B4X:
Private bytes4(4) As Byte
bytes4(3) = MessagePayload(2)
bytes4(2) = MessagePayload(3)
AvgDist = BC.intsFromBytes(bytes4)(0)
bytes4(3) = MessagePayload(12)
bytes4(2) = MessagePayload(13)
MaxDist = BC.intsFromBytes(bytes4)(0)
bytes4(3) = MessagePayload(14)
bytes4(2) = MessagePayload(15)
MinDist = BC.intsFromBytes(bytes4)(0)
Private DepthData(19200) As Byte
BC.ArrayCopy(MessagePayload, 24, DepthData, 0, 19200)
Any recommendations?