Open yadav9997 opened 2 years ago
Hi @yadav9997,
Problem with Time64 (uint64_t) & "struct ASN__PRIMITIVE_TYPE_s"
What is the exact problem?
which of the below conversion routines (from INTEGER.h) could be you used for the Uint64
You can use the uintmax_t
variants.
@velichkov Thanks a lot for the feedback.
I tried using the asn_umax2INTEGER(INTEGER_t i, uintmax_t l) for long long variable [as below example for Millisecond], when tried to print it only printed 10 digits not the 13 digits and also gave UPER encode error as " value too large " Millisecond = INTEGER (0..4398046511103);
i am trying to assign 13 digit value and then do UPER encode of this value. asn_encode_to_new_buffer(0,ATS_UNALIGNED_BASIC_PER, &asn_DEF_MessageFrame, msgf);
Example: uintmax_t v2 = 1718192021234; printf("size=%d, value=%ju\n",sizeof(v2),v2); asn_umax2INTEGER(&millisecond, v2);
printf("size=%d, value=%ju\n",sizeof(v2),v2);
What are the size and value? Which architecture are you using - x86, x86_64, arm ... ? Which asn1c
do you use, from which repository, branch, commit?
What asn1c
parameters did you use to compile your asn1 files - -fwide-types
, .... ?
asn_umax2INTEGER(&millisecond, v2);
Check the return value of asn_umax2INTEGER
Returns 0 if it was possible to convert, -1 otherwise.
-1/EINVAL: Mandatory argument missing
-1/ERANGE: Value encoded is out of range for long representation
-1/ENOMEM: Memory allocation failed (in asn_*2INTEGER()).
@velichkov Apologies for delay in response.
please find below information:
But when i add the "asn_check_constraints" it shows as below error on the arm device: MessageFrame constraint validation failed: Millisecond: value too large (Millisecond.c:26)
Below is the function of Millisecond.c.26 where "value too large" is being printed int Millisecond_constraint(const asn_TYPE_descriptor_t td, const void sptr, asn_app_constraint_failed_f ctfailcb, void app_key) { const INTEGER_t st = (const INTEGER_t )sptr; long value;
if(!sptr) { ASN__CTFAIL(app_key, td, sptr, "%s: value not given (%s:%d)", td->name, FILE, LINE); return -1; }
if(asn_INTEGER2long(st, &value)) { ASN__CTFAIL(app_key, td, sptr, "%s: value too large (%s:%d)", td->name, FILE, LINE); return -1; }
if((value >= 0 && value <= 4398046511103)) { / Constraint check succeeded / return 0; } else { ASN__CTFAIL(app_key, td, sptr, "%s: constraint failed (%s:%d)", td->name, FILE, LINE); return -1; } }
please let me know if anything more information is needed, thanks alot @velichkov
@velichkov apologies for following up, any possible feedback ?
* Architecture is arm [arm-openwrt-linux-gnueabi] for Device [armv7l GNU/Linux]
So it is 32bit. Can you reproduce this on 32bit x86 processor or 64bit (arm or intel)?
* v0.9.29 of asn1c
Which repository and commit?
* Actually i am using the Makefile for compilation than using the asn1c command line with -fwide-types parameters. please find below Makefile link: https://github.com/mouse07410/asn1c/blob/vlm_master/examples/sample.source.J2735/Makefile
Do you have the same problem with vlm_master
branch of mouse07410's fork?
* asn_umax2INTEGER returns as 0
OK.
* But when i add the "asn_check_constraints" it shows as below error on the arm device: MessageFrame constraint validation failed: Millisecond: value too large (Millisecond.c:26)
Can you provide a minimal, reproducible example (together with asn1, makefiles, etc...)
Thanks a lot @velichkov. please find below details:
Yes, i am using the vlm_master branch of the mouse07410's fork (sorry might not be using latest commit): https://github.com/mouse07410/asn1c/blob/vlm_master/INSTALL.md
please find attached zip-file which contains the asn.1 and makefiles (i am using the Makefile of the vlm_master/examples/sample.source.J2735/Makefile and modifying the .asn1 file with the test_rectangle.asn1) onlinegit.zip
Below is the UPER encoding code used for encoding the rectangle message -**** asn_encode_to_new_buffer_result_t res; int ret;
while(1) { fprintf(stdout,"=======================Rectangle Transmit STARTS ============================================\n"); RectangleMessage_t testrect; MessageFrame_t msgf;
testrect = (calloc(1, sizeof(RectangleMessage_t)));
msgf = calloc(1, sizeof(MessageFrame_t));
memset(msgf, 0, sizeof(MessageFrame_t));
memset(testrect, 0, sizeof(RectangleMessage_t));
//height
uintmax_t h1 = 1718192021234;
printf("size=%d, value=%ju\n",sizeof(h1),h1);
asn_umax2INTEGER(&testrect->height, h1);
//width
uintmax_t w1 = 1718192021237;
printf("size=%d, value=%ju\n",sizeof(w1),w1);
asn_umax2INTEGER(&testrect->width, w1);
/*Message Frame Creation*/
msgf->messageId = DSRCmsgID_rectangleMessage;
msgf->value.present = MessageFrame__value_PR_RectangleMessage;
msgf->value.choice.RectangleMessage = *testrect;
/* Constraints Checking */
ret = asn_check_constraints(&asn_DEF_MessageFrame, msgf, errbuf, &errlen);
if (ret)
{
fprintf(stderr, "MessageFrame constraint validation failed: %s\n", errbuf);
exit(12);
}
//fprintf(stderr,"************************************************************************************************ \n");
/* Constraint Validation: Is the MessageFrame Passed or Failed */
fprintf(stdout, "MessageFrame constraint validation passed.\n");
fprintf(stdout,"------------------------| MessageStructure of RectangleMessage prior to encoding |------------------------\n");
asn_fprint(stdout, &asn_DEF_MessageFrame, msgf);
//xer_fprint(stdout, &asn_DEF_MessageFrame, msgf);
//fprintf(stdout,"==================================================================================\n");
/* UPER Encode */
res = asn_encode_to_new_buffer(0,ATS_UNALIGNED_BASIC_PER, &asn_DEF_MessageFrame, msgf);
if(res.result.encoded < 0)
{
fprintf(stderr,"Value of errno: %d, = %s\n", errno, strerror(errno));
fprintf(stderr, "UPER Encoding for RectangleMessage failed = %d \n", res.result.encoded);
}
else
{
fprintf(stderr, "UPER Encoding for RectangleMessage PASSED \n");
fprintf(stderr,"buf-len=%d\n",res.result.encoded);
}
if (res.buffer)
{
/* Encoded successfully */
v2x_sample_dump_hex("Encoded RectangleMessage Test-Message hex-dump", res.buffer, res.result.encoded);
fprintf(stderr,"\n");
usleep(100000); //send over every 100-msec
}
free(testrect);
free(msgf);
}
it outputs as below: -** =======================Rectangle Transmit STARTS ============================================ size=8, value=1718192021234 size=8, value=1718192021237 MessageFrame constraint validation failed: INTEGER: value too large (RectangleMessage.c:26)
please find attached compiled .c and .h files.
@velichkov apologies for following up, would it be possible to share any valuable feedback ?
@velichkov tried with the latest master repo of the below git-repo and still it gives the same issue:
@yadav9997 If you want to encode/decode a large integer value, both this repo and https://github.com/mouse07410/asn1c will work well. However, if you're trying to use constraints that large, it will not work, sorry. Supporting that would require implementing constraints of type INTEGER_t
(as opposed to int64_t
or such) - the code to do that is not there.
Hi @velichkov @vlm ,
can you please help in sharing any information about which of the below conversion routines (from INTEGER.h) could be you used for the Uint64, thanks:
Uint64 ::= INTEGER (0..18446744073709551615) -- (hex) ff ff ff ff ff ff ff ff
-- -- Integers
Uint3 ::= INTEGER (0..7) -- (hex) 07 Uint8 ::= INTEGER (0..255) -- (hex) ff Uint16 ::= INTEGER (0..65535) -- (hex) ff ff Uint32 ::= INTEGER (0..4294967295)---- -- (hex) ff ff ff ff
Uint64 ::= INTEGER (0..18446744073709551615) -- (hex) ff ff ff ff ff ff ff ff
SequenceOfUint8 ::= SEQUENCE OF Uint8
SequenceOfUint16 ::= SEQUENCE OF Uint16
-- -- Time
Time32 ::= Uint32 Time64 ::= Uint64 ValidityPeriod ::= SEQUENCE { start Time32, duration Duration } Duration ::= CHOICE { microseconds Uint16, milliseconds Uint16, seconds Uint16, minutes Uint16, hours Uint16, sixtyHours Uint16, years Uint16 }
asn1c/skeletons/INTEGER.h
Lines 56 to 75 in 4cc779f /*
Natiwe size-independent conversion of native integers to/from INTEGER. (lsize) is in bytes. Returns 0 if it was possible to convert, -1 otherwise. -1/EINVAL: Mandatory argument missing -1/ERANGE: Value encoded is out of range for long representation -1/ENOMEM: Memory allocation failed (in asn2INTEGER()). / int asn_INTEGER2imax(const INTEGER_t i, intmax_t l); int asn_INTEGER2umax(const INTEGER_t i, uintmax_t l); int asn_imax2INTEGER(INTEGER_t *i, intmax_t l); int asn_umax2INTEGER(INTEGER_t i, uintmax_t l); /
Size-specific conversion helpers. / int asn_INTEGER2long(const INTEGER_t i, long l); int asn_INTEGER2ulong(const INTEGER_t i, unsigned long l); int asn_long2INTEGER(INTEGER_t i, long l); int asn_ulong2INTEGER(INTEGER_t *i, unsigned long l);
Thanks a lot, awaited for your valuable feedback