obu-firmware builds against vanetza-idf from microbu-esp32c5/external, but that tree was gitignored, so a clone of this repository could not build the firmware it ships. It is now committed here as ordinary files in its own folder, microbu-esp32c5/: the colleague's commit cf4b99f plus the V2X2MAP bridge's signature verification (--trust) used on the bench. Nothing is fetched from or pushed to the colleague's repository; this repository and its remotes carry everything. The folder's own .gitignore keeps build output, downloaded components and private key material out, as it did there; the committed file set is identical to that repository's tracked files. The ESP32-C5 is still flashed from obu-firmware/, which only takes vanetza-idf from microbu-esp32c5/, so the two stay separate folders. FLASHING.md says how to take a newer version of the colleague's tree (copy it over the folder, rebuild, test, commit).
80 lines
2.6 KiB
C
80 lines
2.6 KiB
C
/*
|
|
* Copyright (c) 2017 Lev Walkin <vlm@lionet.info>.
|
|
* All rights reserved.
|
|
* Redistribution and modifications are permitted subject to BSD license.
|
|
*/
|
|
#include "asn_internal.h"
|
|
#include "NativeInteger.h"
|
|
|
|
/*
|
|
* Decode the chunk of JSON text encoding INTEGER.
|
|
*/
|
|
asn_dec_rval_t
|
|
NativeInteger_decode_jer(const asn_codec_ctx_t *opt_codec_ctx,
|
|
const asn_TYPE_descriptor_t *td,
|
|
const asn_jer_constraints_t* constraints,
|
|
void **sptr, const void *buf_ptr,
|
|
size_t size) {
|
|
const asn_INTEGER_specifics_t *specs =
|
|
(const asn_INTEGER_specifics_t *)td->specifics;
|
|
asn_dec_rval_t rval;
|
|
INTEGER_t st;
|
|
void *st_ptr = (void *)&st;
|
|
long *native = (long *)*sptr;
|
|
|
|
if(!native) {
|
|
native = (long *)(*sptr = CALLOC(1, sizeof(*native)));
|
|
if(!native) ASN__DECODE_FAILED;
|
|
}
|
|
|
|
memset(&st, 0, sizeof(st));
|
|
rval = INTEGER_decode_jer(opt_codec_ctx, td, constraints, &st_ptr, buf_ptr, size);
|
|
if(rval.code == RC_OK) {
|
|
long l;
|
|
if((specs&&specs->field_unsigned)
|
|
? asn_INTEGER2ulong(&st, (unsigned long *)&l) /* sic */
|
|
: asn_INTEGER2long(&st, &l)) {
|
|
rval.code = RC_FAIL;
|
|
rval.consumed = 0;
|
|
} else {
|
|
*native = l;
|
|
}
|
|
} else {
|
|
/*
|
|
* Cannot restart from the middle;
|
|
* there is no place to save state in the native type.
|
|
* Request a continuation from the very beginning.
|
|
*/
|
|
rval.consumed = 0;
|
|
}
|
|
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_INTEGER, &st);
|
|
return rval;
|
|
}
|
|
|
|
asn_enc_rval_t
|
|
NativeInteger_encode_jer(const asn_TYPE_descriptor_t *td,
|
|
const asn_jer_constraints_t* constraints,
|
|
const void *sptr, int ilevel,
|
|
enum jer_encoder_flags_e flags,
|
|
asn_app_consume_bytes_f *cb, void *app_key) {
|
|
const asn_INTEGER_specifics_t *specs =
|
|
(const asn_INTEGER_specifics_t *)td->specifics;
|
|
char scratch[32]; /* Enough for 64-bit int */
|
|
asn_enc_rval_t er = {0,0,0};
|
|
const long *native = (const long *)sptr;
|
|
|
|
(void)ilevel;
|
|
(void)flags;
|
|
|
|
if(!native) ASN__ENCODE_FAILED;
|
|
|
|
er.encoded = snprintf(scratch, sizeof(scratch),
|
|
(specs && specs->field_unsigned)
|
|
? "%lu" : "%ld", *native);
|
|
if(er.encoded <= 0 || (size_t)er.encoded >= sizeof(scratch)
|
|
|| cb(scratch, er.encoded, app_key) < 0)
|
|
ASN__ENCODE_FAILED;
|
|
|
|
ASN__ENCODED_OK(er);
|
|
}
|