Public Sub SendPhoto(Data() As Byte)
Dim bc as ByteConverter 'if not already done elsewhere
Dim ChunkSize As Int = 12345 'anything under 29988 should be ok, but let's play it safe for time being
Dim DataBytesToSend As Int
Dim ChunkCount As Int = Floor((Data.Length + ChunkSize - 1) / ChunkSize) 'probably doesn't need Floor() for Int division
Dim CurrChunk As Int = 0
For ChunkStart = 0 to Data.Length Step ChunkSize
CurrChunk = CurrChunk + 1
DataBytesToSend = Data.Length - ChunkStart
If DataBytesToSend > ChunkSize Then
DataBytesToSend = ChunkSize
End If
Dim SendBuffer(12 + DataBytesToSend) As Byte 'allow extra 12 bytes for PTT header
'PTT header per https://dev.proptt2.com/sdk-client-custommessage.html
'Custom Message Basic header
SendBuffer( 0) = 0x01 'Command = SENDPHOTO2CHANNEL
SendBuffer( 1) = 0x01 'ContentType = Chunked message
SendBuffer( 2) = 0x34 'MsgID You can decide it
SendBuffer( 3) = 0x12 'ditto
'Chunking header
SendBuffer( 4) = Bit.ShiftRight(CurrChunk, 8)
SendBuffer( 5) = Bit.And(CurrChunk, 0xFF)
SendBuffer( 6) = Bit.ShiftRight(ChunkCount, 8)
SendBuffer( 7) = Bit.And(ChunkCount, 0xFF)
'Custom Message header
SendBuffer( 8) = 0x02 'Type = Image format: JPEG
SendBuffer( 9) = 0x00 'Reserved: Must be 0x00
SendBuffer(10) = 0x00 'ditto
SendBuffer(11) = 0x00 'ditto
'JPEG image
bc.ArrayCopy(Data, ChunkStart, SendBuffer, 12, DataBytesToSend)
Log(Data.Length & " " & ChunkCount & " " & CurrChunk & " " & ChunkStart & " " & BytesToSend & " " & SendBuffer.Length)
ptChannel.SendPublicCustomMessage(SendBuffer, SendBuffer.Length)
Next
End Sub