QDataStream

  1. ‹ Older
  2. 5 weeks ago

    Seems like a hard way to do it, but this works for me.

    ============
    function decodeQ64 (QBlock As MemoryBlock, firstByte As Integer) As String

    Const blockSize = 8
    Const stringSize = 16

    Dim m As New MemoryBlock(blockSize)
    Dim i, hVal As Integer
    Dim aVal As Int64
    Dim pFactor( stringSize ) As Int64
    Dim byteValue As integer
    Dim s, h1 As String

    for i = stringSize DownTo 1
    pFactor( i ) = Pow( stringSize, stringSize - i )
    Next

    for i = 0 to blockSize - 1
    m.Byte(i) = QBlock.Byte( firstByte + i )
    Next

    for i = 0 to blockSize - 1
    byteValue = m.Byte( i )
    h1 = hex( byteValue )
    if len( h1 ) = 1 Then h1 = "0" + h1
    s = s + h1
    Next

    for i = 1 to stringSize

    hVal = asc( mid( s, i, 1 ) )

    Select case hVal
    Case 48 to 57
    hVal = hVal - 48
    Case 65 to 70
    hVal = ( hVal - 65) + 10
    End

    aVal = aVal + (hVal * pFactor( i ) )

    Next
    Return str( aVal )
    =============

    Is there an easier way to do this???

  3. Norman P

    Mar 21 Pre-Release Testers, Xojo Pro Enjoying Whistler BC
    Edited 5 weeks ago

    @Ed S Seems like a hard way to do it, but this works for me.

    The first bunch of lines is just me setting up the memory block with the data you suggested to show how using LITTLEENDIAN and Uint64Value would do this for you

    Literally you need 2 lines

    1. littlendian = false
    2. read the Uint64 from whatever offset
    mb.LittleEndian = false
    dim beI64 as Uint64 = mb.UInt64Value(0)

    Is the code getting a string that is the hex representation ? ie "00" , "00" or BYTES with those values ?

    IE/ would my little sample need to be

    dim mb as new memoryblock(8)
    mb.UInt8Value(0) = val(" &h" + "00")
    mb.UInt8Value(1) = val(" &h" + "00")
    mb.UInt8Value(2) = val(" &h" + "00")
    mb.UInt8Value(3) = val(" &h" + "00")
    mb.UInt8Value(4) = val(" &h" + "00")
    mb.UInt8Value(5) = val(" &h" + "36")
    mb.UInt8Value(6) = val(" &h" + "85")
    mb.UInt8Value(7) = val(" &h" + "08")
    
    mb.LittleEndian = false
    dim beI64 as Uint64 = mb.UInt64Value(0)
    
    break
    
  4. Edited 5 weeks ago

    I'm setting littlendian here in UDPSocket.DataAvailable

    Dim d As DataGram
    Dim mb1, mb As MemoryBlock

    d = UDPSocket1.Read
    mb = d.Data
    if mb <> NIL Then
    mb1 = mb
    mb1.LittleEndian = False
    end

    HexDump( mb1 )

    Then in HexDump I call my function

    if wsjtxData.Size = 0 Then Return
    .
    {Other code to dump the hex of the dataGram)
    .
    if wsjtxData.Byte( 11 ) = 1 Then
    s = decodeQ64( wsjtxData, 22 )
    outPut.AppendText s + chr( 13 )
    end

  5. Norman P

    Mar 21 Pre-Release Testers, Xojo Pro Enjoying Whistler BC

    ah you want to see the bytes from the block in hex ....... I though you just wanted the decimal value from the memry block based on your first post and what I replied with
    and that returns the decimal converted value with just the lines I posted
    if you wanted to add that as a string you could just use STR or FORMAT on the value the two lines I posted return

  6. Hi Norman

    I need to stop trying to do it the other way and listen to your good advice.

    Really I don't care about the individual bytes. I DO want to return the decimal value.

    Let me change gears and see if I can make it work the way you have shown.

    My wife says I'm like a dog with a bone. Once I start chewing it's hard to get me to pay attention.

    Thanks for your help!

  7. Norman wrote:

    Is the code getting a string that is the hex representation ? ie "00" , "00" or BYTES with those values ?

    Answer
    the code is getting BYTES in a dataGram

  8. Sample data (hex dump)

    AD BC CB DA 00 00 00 02 00 00 00 01 00 00 00 06 . . . . . . . . . . . . . . . .
    57 53 4A 54 2D 58 00 00 00 00 00 36 85 08 00 00 W S J T - X . . . . . 6 . . . .
    00 03 46 54 38 00 00 00 06 4A 52 36 45 5A 45 00 . . F T 8 . . . . J R 6 E Z E .
    00 00 01 33 00 00 00 03 46 54 38 01 00 01 00 00 . . . 3 . . . . F T 8 . . . . .
    05 16 00 00 03 E8 00 00 00 05 57 31 4B 4F 4B 00 . . . . . . . . . . W 1 K O K .
    00 00 04 44 4D 30 34 00 00 00 04 50 4D 35 33 00 . . . D M 0 4 . . . . P M 5 3 .
    FF FF FF FF 00 . . . . .

  9. Norman P

    Mar 21 Pre-Release Testers, Xojo Pro Enjoying Whistler BC

    yeah if the MB already has the bytes and you just want the decimal value then

    dim beI64 as Uint64 = mb.UInt64Value(offset) /// start at whatever byte offset in the memory block you need <<<

    will give you an unsigned int 64 (8 bytes) with one line of code

    instead of

    if wsjtxData.Byte( 11 ) = 1 Then
      s = decodeQ64( wsjtxData, 22 )
      outPut.AppendText s + chr( 13 )
    end if

    and all the code in decodeQ64 you can do

    if wsjtxData.Byte( 11 ) = 1 Then
      dim beI64 as Uint64 = mb.UInt64Value(offset)
      outPut.AppendText s + str(beI64) + chr(13) // you might use end of line here
    end 
  10. Norman P

    Mar 21 Pre-Release Testers, Xojo Pro Enjoying Whistler BC

    yeah if thats from the debugger then the data your seeing is the debugger writing it in hex just so you can read it :P
    in the memory block its raw bytes

  11. Norman...

    Many many thanks... I have re-written the code and it is now working as I hoped.

    Your help and patience very much appreciated.

  12. I still have another question...

    I need to convert this Qt Data Type

    float 32-bit floating point number using the standard IEEE 754 format

    into a double.

    Here is a sample value as hex:

    3F D3 33 33 40 00 00 00

  13. Maurizio R

    Mar 23 Pre-Release Testers, Xojo Pro

    A 32 bit float is named Single in Xojo.

  14. I'm concerned that 3F D3 33 33 40 00 00 00 (from the data stream) seems to be a 64 bit number.

  15. Norman P

    Mar 23 Pre-Release Testers, Xojo Pro Enjoying Whistler BC

    @Ed S I'm concerned that 3F D3 33 33 40 00 00 00 (from the data stream) seems to be a 64 bit number.

    3F D3 33 33 40 00 00 00 is more than 32 bits for sure

    3F D3 33 33 would be 32 bits
    40 00 00 00 would be 32 bits as well

  16. OK perhaps there are 2 32 bit floats... just in case, how do you turn a 64 bit float into a xojo number?

  17. Norman P

    Mar 23 Pre-Release Testers, Xojo Pro Enjoying Whistler BC
    Edited 5 weeks ago

    same trick as the memoryblock one before for an integer
    just read at a specific offset

    see http://docs.xojo.com/MemoryBlock

  18. Ed S

    Mar 23 Answer

    Bingo!! Thanks Norman.

  19. Norman P

    Mar 23 Pre-Release Testers, Xojo Pro Enjoying Whistler BC

    @Ed S Bingo!! Thanks Norman.

    Woohoo BINGO !!! .. whats the prize ? :P

  20. Bingo bango bongo, I don't want to leave the Congo. Oh no, no, no!
    Bingo bango bongo, I'm so happy in the jungle, I refuse to go.

    Danny Kaye and the Andrews Sisters:
    https://www.youtube.com/watch?v=ugW2INtnl84

    Are you old enough to remember?

  21. Norman P

    Mar 23 Pre-Release Testers, Xojo Pro Enjoying Whistler BC

    Old enough to know who they are
    Young enough to not have watched them :)

  22. Newer ›

or Sign Up to reply!