Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to see what data is being send
Forum Updated to NodeBB v4.3 + New Features

How to see what data is being send

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 361 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Aeroplane123
    wrote on last edited by
    #1

    I have a function

    uint16_t Widget::writeFlashPage(uint8_t pageId, uint8_t *data, uint16_t pageSize){
    
        uint16_t payLoadSize = pageSize + 1;
        uint16_t cmdSize = payLoadSize + 8;
    
        uint8_t cmd[3000];
    
        memcpy(cmd, "x", 4);
        cmd[4] =  CMD_SENDING_FIRMWARE_PAGE & 0xFF;
        cmd[5] = (CMD_SENDING_FIRMWARE_PAGE << 8) & 0xFF;
        cmd[6] = (uint8_t)(payLoadSize & 0xFF);
        cmd[7] = (uint8_t)(payLoadSize >>8);
        cmd[8] = pageId;
    
        memcpy(&cmd[9], data, pageSize);
    
        cmd[8 + payLoadSize] = calcChecksum(cmd, cmdSize);
    
        char* cmdChar = reinterpret_cast<char*>(cmd); // this conversion is needed so we can send via serial port!
    
        bool success = serialPort.write(cmdChar, cmdSize + 1);
     
    

    How can I see what data is being sent to the serial port via qDebug()?

    JonBJ 1 Reply Last reply
    0
    • A Aeroplane123

      @JonB Ah yes I can see that now. Thanks.
      Indecently when I use qDebug() cmdChar; the output is just "x" and nothing else. Surely this is not correct?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #6

      @Aeroplane123
      That is probably because it has something like x followed by a byte of \0, which it takes as a C string terminator and does not show any further bytes.

      To get qDebug() to show what is really there you will need something like:

      QByteArray ba(cmd, cmdSize + 1);
      qDebug() << ba;
      // or
      qDebug() << ba.toHex(':');
      
      1 Reply Last reply
      0
      • A Aeroplane123

        I have a function

        uint16_t Widget::writeFlashPage(uint8_t pageId, uint8_t *data, uint16_t pageSize){
        
            uint16_t payLoadSize = pageSize + 1;
            uint16_t cmdSize = payLoadSize + 8;
        
            uint8_t cmd[3000];
        
            memcpy(cmd, "x", 4);
            cmd[4] =  CMD_SENDING_FIRMWARE_PAGE & 0xFF;
            cmd[5] = (CMD_SENDING_FIRMWARE_PAGE << 8) & 0xFF;
            cmd[6] = (uint8_t)(payLoadSize & 0xFF);
            cmd[7] = (uint8_t)(payLoadSize >>8);
            cmd[8] = pageId;
        
            memcpy(&cmd[9], data, pageSize);
        
            cmd[8 + payLoadSize] = calcChecksum(cmd, cmdSize);
        
            char* cmdChar = reinterpret_cast<char*>(cmd); // this conversion is needed so we can send via serial port!
        
            bool success = serialPort.write(cmdChar, cmdSize + 1);
         
        

        How can I see what data is being sent to the serial port via qDebug()?

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #2

        @Aeroplane123
        Umm, what about qDebug() << cmd;? is that what you mean??

        BTW, in your previous thread on this code I told you that

        cmd[5] = (CMD_SENDING_FIRMWARE_PAGE << 8) & 0xFF;

        is wrong. Shame you have chosen to ignore this?

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Aeroplane123
          wrote on last edited by
          #3

          Hi can you explain why it is wrong?

          JonBJ 1 Reply Last reply
          0
          • A Aeroplane123

            Hi can you explain why it is wrong?

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #4

            @Aeroplane123
            The code you have will always evaluate to precisely a byte of 0. I doubt that is what you intended!

            Your << is the wrong operator. Your code for cmd[7] = (uint8_t)(payLoadSize >>8); does the same thing but correctly uses the >> operator here.

            A 1 Reply Last reply
            0
            • JonBJ JonB

              @Aeroplane123
              The code you have will always evaluate to precisely a byte of 0. I doubt that is what you intended!

              Your << is the wrong operator. Your code for cmd[7] = (uint8_t)(payLoadSize >>8); does the same thing but correctly uses the >> operator here.

              A Offline
              A Offline
              Aeroplane123
              wrote on last edited by
              #5

              @JonB Ah yes I can see that now. Thanks.
              Indecently when I use qDebug() cmdChar; the output is just "x" and nothing else. Surely this is not correct?

              JonBJ 1 Reply Last reply
              0
              • A Aeroplane123

                @JonB Ah yes I can see that now. Thanks.
                Indecently when I use qDebug() cmdChar; the output is just "x" and nothing else. Surely this is not correct?

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #6

                @Aeroplane123
                That is probably because it has something like x followed by a byte of \0, which it takes as a C string terminator and does not show any further bytes.

                To get qDebug() to show what is really there you will need something like:

                QByteArray ba(cmd, cmdSize + 1);
                qDebug() << ba;
                // or
                qDebug() << ba.toHex(':');
                
                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved