Giter VIP home page Giter VIP logo

Comments (10)

velichkov avatar velichkov commented on September 26, 2024

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.

from asn1c.

yadav9997 avatar yadav9997 commented on September 26, 2024

@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);

from asn1c.

velichkov avatar velichkov commented on September 26, 2024

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()).

from asn1c.

yadav9997 avatar yadav9997 commented on September 26, 2024

@velichkov
Apologies for delay in response.

please find below information:

  • Architecture is arm [arm-openwrt-linux-gnueabi] for Device [armv7l GNU/Linux]
  • v0.9.29 of asn1c
  • 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
  • asn_umax2INTEGER returns as 0
  • 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

from asn1c.

yadav9997 avatar yadav9997 commented on September 26, 2024

@velichkov apologies for following up, any possible feedback ?

from asn1c.

velichkov avatar velichkov commented on September 26, 2024
* 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...)

from asn1c.

yadav9997 avatar yadav9997 commented on September 26, 2024

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)

testrec.zip

please find attached compiled .c and .h files.

from asn1c.

yadav9997 avatar yadav9997 commented on September 26, 2024

@velichkov apologies for following up, would it be possible to share any valuable feedback ?

from asn1c.

yadav9997 avatar yadav9997 commented on September 26, 2024

@velichkov tried with the latest master repo of the below git-repo and still it gives the same issue:

https://github.com/mouse07410/asn1c

from asn1c.

mouse07410 avatar mouse07410 commented on September 26, 2024

@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.

from asn1c.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.