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 create defined message structures in code.
Forum Updated to NodeBB v4.3 + New Features

How to create defined message structures in code.

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 815 Views 1 Watching
  • 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.
  • D Offline
    D Offline
    di98mase
    wrote on last edited by
    #1

    I want do develop a simulator that sends defined messages to a subsystem that I am testing.
    The interface is defined as different data messages. Each request message, sent from my simulator, has a predefined header and a defined data contents and the reply from the subsystem is also defined as different messages with header and data.

    The simulator is kind of simple. It shall send a message and wait for a acknowledge from the subsystem.

    My problem is how to create these different messages in code? What is the best way to create the message structure? The byte order is important and the message structure must be exactly the way they are specified in the interface specification. e.g:
    Header:
    unit8 messageId
    unit8 messageType
    unit16 totalMessageLength
    Data
    uint32 Id
    uint32 name
    unit16 textLength
    unit8(16) text

    What is the best way to create a data structure that represents my message above?

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Hi,
      Just like your text says, use structures ;-)
      make it a typedef and register it with Q_REGISTER_METATYPE so it may be used in Signal/slots connections.
      Or generate a MessageClass containing public member like you described. Also below this class do the register metatyp for Signal/Slots.
      Add member function to fulfill some extra options you need.
      @
      class MessageClass
      {
      public:
      -- your list here --
      public:
      void data(unsigned char *); // Just an example of a member function, no idea what you need for it
      };

      Q_REGISTER_METATYPE(MessageClass); // Enable MOC compiler for Signal/Slots

      OR:

      typedef struct
      {
      -- Your list here!
      };
      @

      Greetz, Jeroen

      1 Reply Last reply
      0
      • D Offline
        D Offline
        di98mase
        wrote on last edited by
        #3

        Ok that's interesting. A class is convenient but how do I ensure that the actual data gets sent in the right order with no gaps between the data elements?
        From Ada95 i remember that I used a compiler instruction called
        @pragma pack@

        this ensured that the compiler always allocated the data without gaps in memory.
        Thanks Jeroentje, now I can start to test the concept:)

        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