Menu

Accessing values in SEQUENCE of CHOICE

Help
Jens
2012-08-29
2013-03-19
  • Jens

    Jens - 2012-08-29

    I've been twiddling around with asn1c to use it as part of my degree project which is related to the european variant of Car2X Communication.

    At this stage, I can encode and decode messages with the methods you provided in the asn1c support code.
    Xer_fprint and asn_fprint are working just fine,however, I'm unable to extract certain values from the decoded buffer manually.

    For most of the values stored therein, this is pretty straight forward. Unfortunately, I did not accomplish to extract the values from the "vehicleCommonParameters" sequence from the snipped below:

    ItsPduPayload ::= SEQUENCE {
      protocolVersion   INTEGER (0..255),
    --
    -------------- snip-----------------
    --
      protocolMsg CHOICE {
     -------------- snip-----------------
         coopAwareness      [2]CoopAwarenessMessage
     -------------- snip-----------------
      }
    }
    CoopAwarenessMessage ::= SEQUENCE {
      stationCharacteristics SEQUENCE {
        mobileStation   BOOLEAN,
        privateStation  BOOLEAN,
        physicalRelevant    BOOLEAN
      },
      vehicleCommonParameters SEQUENCE SIZE(0..64) OF TaggedValue
    }
    TaggedValue ::= CHOICE {
      vehicleType           [1] VehicleType,
    --
    -------------- snip-----------------
    --
      text              [39] Text
    }
    Text ::= UTF8String(SIZE(1..64))
    

    Decoding the message, I ended up with a data structure and a buffer in memory constructed like this:

    //header
      /* CoopAwarenessMessage */
      typedef struct CoopAwarenessMessage {
          struct stationCharacteristics {
              BOOLEAN_t  mobileStation;
              BOOLEAN_t  privateStation;
              BOOLEAN_t  physicalRelevant;
              
              /* Context for parsing across buffer boundaries */
              asn_struct_ctx_t _asn_ctx;
          } stationCharacteristics;
          struct vehicleCommonParameters {
              A_SEQUENCE_OF(struct TaggedValue) list;
              
              /* Context for parsing across buffer boundaries */
              asn_struct_ctx_t _asn_ctx;
          } vehicleCommonParameters;
          
          /* Context for parsing across buffer boundaries */
          asn_struct_ctx_t _asn_ctx;
      } CoopAwarenessMessage_t;
      /* Dependencies */
      typedef enum TaggedValue_PR {
          TaggedValue_PR_NOTHING,   /* No components present */
          TaggedValue_PR_vehicleType,   // this should be int 39
          //------------snip-----------------------
          TaggedValue_PR_text,
      } TaggedValue_PR;
      /* TaggedValue */
      typedef struct TaggedValue {
          TaggedValue_PR present;
          union TaggedValue_u {
              VehicleType_t  vehicleType;
    
              //------------snip-----------------------
              Text_t     text;
          } choice;
          
          /* Context for parsing across buffer boundaries */
          asn_struct_ctx_t _asn_ctx;
      } TaggedValue_t;
    // main
    m_pPayload->protocolMsg.choice.coopAwareness.vehicleCommonParameters.list"
    /* (where list is of type TaggedValue_t**)*/
    

    Having a look into your data structure, my last attempt to access the OCTETString value in "text" was as follows

        TaggedValue_t** tValue = m_pPayload->protocolMsg.choice.coopAwareness.vehicleCommonParameters.list.array;
        Text_t text;
        text.size = tValue[TaggedValue_PR_text]->choice.text.size;
        text.buf = tValue[TaggedValue_PR_text]->choice.text.buf;
    

    However, this did not do the trick. Any idea, how I can access data stored in multiple sequences like this?

    I'm using asn1c V.0.9.22 with GNU G++ 4.6.2.

     
  • Lev Walkin

    Lev Walkin - 2012-08-30

    Instead of tValue use tValue, tValue, etc, up to protocolMsg.choice.coopAwareness.vehicleCommonParameters.list.length.

     
  • Jens

    Jens - 2012-09-05

    Good advice, cheers!

    Just one hint - there is no attribute "length"; there is just the "size" attribute which rather gives the byte boundaries in bits.

    Eg. this list carries exactly 40 elements. "size", unfortunately, returns 64 though.  Might this be a bug?

     
  • Jens

    Jens - 2012-09-05

    Oh, hang on. My fault. "length" still does not exist, but "count" does - and my IDE's autocomplete just screwed it up….
    Sorry about that.

     

Log in to post a comment.