asn1c
asn1c copied to clipboard
OCTET_STRING encoding issue with UPER
I'm using the SAE J2735-2016 .ASN file. I'm trying to encode an RTCM message (decode works), but it's failing on the OCTET_STRING_uper.c (line 268). As you can see there's a really big number in this debug message which doesn't look right:
Encoding RTCMmessage into 17179869185 units of 8 bits (1..1023, effective 10) (OCTET_STRING_uper.c:252)
Failed to encode element RTCMmessage (OCTET_STRING_uper.c:268)
Failed to encode element RTCMmessageList (constr_SEQUENCE_OF_uper.c:82)
Failed to encode element value (OPEN_TYPE_uper.c:114)
J2735 Encoded: out=-1
Freeing RTCMmessage as OCTET STRING (/home/neal/ProbeStar/GitHub/libj2735v2016/src/OCTET_STRING.c:102)
The C code is here:
#include "MessageFrame.h"
static int msg_count = 1;
int j2735_encode(const char *raw, int size, char *buf, int max)
{
MessageFrame_t frame;
memset(&frame, 0, sizeof(frame));
RTCMcorrections_t *rtcm = &frame.value.choice.RTCMcorrections;
A_SEQUENCE_OF(RTCMmessageList_t) list;
memset(&list, 0, sizeof(list));
if (!raw || !buf)
return 0;
// clip
if (size > 1023)
size = 1023;
printf("J2735 Encoded: in=%d, max=%d\n", size, max);
// build message
RTCMmessage_t *oct = OCTET_STRING_new_fromBuf(&asn_DEF_RTCMmessage, raw, size);
ASN_SEQUENCE_ADD(&list, oct);
// build correction
rtcm->msgCnt = msg_count++;
if (msg_count>=128)
msg_count = 1;
rtcm->rev = RTCM_Revision_rtcmRev2;
rtcm->timeStamp = NULL;
rtcm->anchorPoint = NULL;
rtcm->rtcmHeader = NULL;
rtcm->regional = NULL;
ASN_SEQUENCE_ADD(&rtcm->msgs, &list);
// build frame
frame.messageId = 28; // RTCM
frame.value.present = MessageFrame__value_PR_RTCMcorrections;
// encode
asn_enc_rval_t rc;
rc = uper_encode_to_buffer(&asn_DEF_MessageFrame, NULL, &frame, buf, max);
printf("J2735 Encoded: out=%ld\n", rc.encoded);
free(oct);
// check
if (rc.encoded == -1)
return -1;
return rc.encoded;
}