Skip to main content

C2xParsePacket

Open topic with navigation CAPL Functions » Car2x » C2xParsePacket

Function Syntax

long C2xParsePacket(long packet)

Description

Reinterprets the packet after externally defined binary payload data has been assigned to the packet. When parts of the packet are already available as byte array from external sources, for example gateways or traffic intersection geometry design tools (for MAP packet), these binary byte arrays can be applied to the packet by using C2xSetTokenData function. Here mentioned are byte arrays representing the whole header payload parts like wsmp_t/data, dsmp/data or btp/data and not the data of specific concrete payload tokens. By calling C2xParsePacket the packet will be reinterpreted, so directly after the call the values of each token existed in external data are accessible (see the example). This function fails when the external data applied to the packet cannot be successfully interpreted by using database message definitions.

Parameters

  • packet: Handle of a packet that has been created with C2xInitPacket or was obtained via callback function parameter.

Return Values

Example

void ApplyASN1DataCN(long packet, byte asn1data[], long asn1length)
{
  C2xResizeToken(packet, "dsmp", "data", asn1length*8);
  C2xSetTokenData(packet, "dsmp", "data", asn1length, asn1data);
  C2xParsePacket(packet);
}

void ApplyASN1DataEU(long packet, byte asn1data[], long asn1length)
{
  C2xResizeToken(packet, "btp", "data", asn1length*8);
  C2xSetTokenData(packet, "btp", "data", asn1length, asn1data);
  C2xParsePacket(packet);
}

void ApplyASN1DataUS(long packet, byte asn1data[], long asn1length)
{
  C2xResizeToken(packet, "wsmp_t", "data", asn1length*8);
  C2xSetTokenData(packet, "wsmp_t", "data", asn1length, asn1data);
  C2xParsePacket(packet);
}

variables
{
  long hBSM; // Handle to the new BasicSatetyMessage
  byte asn1Payload[3000]; // Holds external data
  long asn1Payload_length;
}

// Emulate the external ASN.1 data source ("asn1Payload" byte array) by copying the data from an existing packet
long OnPreTxBasicSafetyMessage(LONG packet)
{
  C2xSetTokenInt(packet, "BasicSafetyMessage", "value.basicSafetyMessage.coreData.msgCnt", 2);
  C2xCompletePacket(packet);
  // Get external data, "asn1Payload" can be also set
  // via gateway data, loaded from file, etc.
  asn1Payload_length = C2xGetTokenData(packet, "wsmp_t", "data", elcount(asn1Payload), asn1Payload);
  hBSM = C2xInitPacket("wsmp_t","");
  // Paste external data on a new US BasicSafety message
  ApplyASN1Data(hBSM, asn1Payload,asn1Payload_length);
  write("msgCnt = %d", C2xGetTokenInt(hBSM, "BasicSafetyMessage", "value.basicSafetyMessage.coreData.msgCnt"));
  C2xOutputPacket(hBSM);
  return 0;
}

See Also