Studio:Scl msg

From STRIDE Wiki
Jump to navigation Jump to search

Examples

Five examples of the scl_msg pragma are shown below:

  1. The first example uses the scl_msg pragma to define a set of messages without payloads.
  2. The second example uses the scl_msg pragma to define a one-way command and a two-way command/response. Both messages are defined with a command payload.
  3. The third example uses the scl_msg pragma to define a one-way-response, a two-way command/response and a broadcast response; all with message payloads.
  4. The fourth example uses the scl_msg pragma to define a two-way command/response with associated payloads.
  5. The fifth example uses the scl_msg pragma and the void parameter to define a two-way command/response with a response payload and an empty command payload.

Example 1

   /* STRIDE Message IDs (SMIDs) defining messages without payloads */
   /* SUID = 1, Message Type = One-way Command */
   #define OneWayCmd 1 | srMT_ONEc 
   /* SUID = 2, Message Type = One-way Response */
   #define OneWayRsp 2 | srMT_ONEr
   /* SUID = 3, Message Type = Two-way Command/Response  */
   #define TwoWayMsg 3 | srMT_TWO  
   /* SUID = 4, Message Type = Broadcast Response  */
   #define BrdCstRsp 4 | srMT_BRD
   /* Use the scl_msg pragma to identify the four messages without payloads */
   #pragma scl_msg(1)
   #pragma scl_msg(2)
   #pragma scl_msg(3)
   #pragma scl_msg(4)

Example 2

   /* STRIDE Message IDs (SMIDs) defining messages with command payloads. */
   /* SUID = 1, Message Type = One-way Command,                      */
   /* Command Send Type = By Pointer, Pointer Memory Usage = Private */
   #define OneWayCmd 1 | srMT_ONEc | srST_CMD_PTR | srPU_CMD_PRI
   /* SUID = 2, Message Type = Two-way Command/Response,            */
   /* Command Send Type = By Value                                  */
   #define TwoWayMsg 2 | srMT_TWO  | srST_CMD_VAL

   /* Structure defining the command payload used with both messages */
   typedef struct {
       int f1;
       char f2;
   } CmdPayload_t;

   /* Use the scl_msg pragma to associate the command payload with both SMIDs */
   #pragma scl_msg(1)
   #pragma scl_msg(2)

Example 3

   /* STRIDE Message IDs (SMIDs) defining messages with response payloads. */
   /* SUID = 1, Message Type = One-way Response,                   */
   /* Response Send Type = By Pointer, Pointer Memory Usage = Pool */
   #define OneWayRsp 1 | srMT_ONEr | srST_RSP_PTR | srPU_RSP_POL
   /* SUID = 2, Message Type = Two-way Command/Response,            */
   /* Command Send Type = No Payload, Response Send Type = By Value */
   #define TwoWayMsg 2 | srMT_TWO  | srST_RSP_VAL
   /* SUID = 3, Message Type = Broadcast Response,                 */
   /* Response Send Type = By Pointer, Pointer Memory Usage = Pool */
   #define BrdCstRsp 3 | srMT_BRD  | srST_RSP_PTR | srPU_RSP_POL

   /* Structure defining the response payload used with the messages */
   typedef struct {
       int f1;
       char f2;
   } RspPayload_t;

   /* Use the scl_msg pragma to associate the payload with each of the SMIDs */
   #pragma scl_msg( 1, RspPayload_t )
   #pragma scl_msg( 2, RspPayload_t )
   #pragma scl_msg( 3, RspPayload_t )

Example 4

   #include <sr.h>
   /* STRIDE Message ID (SMID) defining a two-way message with    */
   /* with a command and a response payload.                      */
   /* SUID = 1, Message Type = Two-way Command/Response,          */
   /* Command Send Type = By Value, Response Send Type = By Value */ 
   #define TwoWayMsg 1 | srMT_TWO | srST_CMD_VAL | srST_RSP_VAL
    
   /* Structure defining the command payload for the message */
   typedef struct {
       int f1;
       char f2;
   } CmdPayload_p;

   /* Structure defining the response payload for the message */
   typedef struct {
       short f1;
       float f2;
   } RspPayload_r;

   /* Use the scl_msg pragma to associate both payloads with the SMID */
   #pragma scl_msg ( TwoWayMsg, CmdPayload_p, RspPayload_r )

Example 5

   #include <sr.h>
   /* STRIDE Message ID (SMID) defining a two-way message with    */
   /* with a command and a response payload.                      */
   /* SUID = 1, Message Type = Two-way Command/Response,          */
   /* Command Send Type = By Value, Response Send Type = By Value */ 
   #define TwoWayMsg 1 | srMT_TWO |  srST_RSP_VAL 

   /* Structure defining the command payload for the message */
   typedef struct {
       int f1;
       char f2;
   } CmdPayload_p;

   /* Structure defining the response payload for the message */
   typedef struct {
       short f1;
       float f2;
   } RspPayload_r;

   /* Use the scl_msg pragma to associate both payloads with the SMID */
   #pragma scl_msg ( TwoWayMsg, void, RspPayload_r )