Skip to content

Commit

Permalink
BNER: Add weak function stubs for BNER fixed encoded PDUs
Browse files Browse the repository at this point in the history
  • Loading branch information
ringlej committed Nov 29, 2017
1 parent 08e4b29 commit 194762f
Show file tree
Hide file tree
Showing 6 changed files with 714 additions and 15 deletions.
26 changes: 25 additions & 1 deletion libasn1compiler/asn1c_C.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <asn1fix_crange.h> /* constraint groker from libasn1fix */
#include <asn1fix_export.h> /* other exportables from libasn1fix */
#include <asn1parser.h>
#include <regex.h>

typedef struct tag2el_s {
struct asn1p_type_tag_s el_tag;
Expand Down Expand Up @@ -75,6 +76,24 @@ enum etd_spec {
};
static int emit_type_DEF(arg_t *arg, asn1p_expr_t *expr, enum tvm_compat tv_mode, int tags_count, int all_tags_count, int elements_count, enum etd_spec);

static int is_bner_pdu_regex_init = 0;
static regex_t bner_pdu_regex;

static int init_bner(void) {
int ret = 0;

if(!is_bner_pdu_regex_init) {
ret = regcomp(&bner_pdu_regex, "BACnet.*PDU", 0);
if(ret == 0) is_bner_pdu_regex_init = 1;
}

return ret;
}
static int is_bner_fixed_pdu(const char *pdu_type_name) {
init_bner();
return (regexec(&bner_pdu_regex, pdu_type_name, 0, NULL, 0) == 0);
}

#define C99_MODE (!(arg->flags & A1C_NO_C99))
#define UNNAMED_UNIONS (arg->flags & A1C_UNNAMED_UNIONS)
#define HIDE_INNER_DEFS (arg->embed && !(arg->flags & A1C_ALL_DEFS_GLOBAL))
Expand Down Expand Up @@ -2980,7 +2999,12 @@ emit_type_DEF(arg_t *arg, asn1p_expr_t *expr, enum tvm_compat tv_mode, int tags_
if (!p2)
p2 = strdup(p);

OUT("&asn_OP_%s,\n", p2);
if(arg->flags & A1C_GEN_BNER
&& is_bner_fixed_pdu(expr->Identifier)) {
OUT("&asn_OP_%s,\n", expr_id);
} else {
OUT("&asn_OP_%s,\n", p2);
}

if(tags_count) {
OUT("asn_DEF_%s_tags_%d,\n",
Expand Down
29 changes: 15 additions & 14 deletions skeletons/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,21 @@ check_PROGRAMS = \
check-converter_c89_example

# BNER Support
libasn1cskeletons_la_SOURCES += \
bner_decoder.c bner_decoder.h \
bner_encoder.c bner_encoder.h \
bner_support.c bner_support.h \
constr_CHOICE_bner.c \
constr_SEQUENCE_bner.c \
constr_SEQUENCE_OF_bner.c \
ANY_bner.c \
BOOLEAN_bner.c \
INTEGER_bner.c \
NativeInteger_bner.c \
NativeReal_bner.c \
NULL_bner.c \
OCTET_STRING_bner.c \
libasn1cskeletons_la_SOURCES += \
bner_decoder.c bner_decoder.h \
bner_encoder.c bner_encoder.h \
bner_fixed_stubs.c bner_fixed_stubs.h \
bner_support.c bner_support.h \
constr_CHOICE_bner.c \
constr_SEQUENCE_bner.c \
constr_SEQUENCE_OF_bner.c \
ANY_bner.c \
BOOLEAN_bner.c \
INTEGER_bner.c \
NativeInteger_bner.c \
NativeReal_bner.c \
NULL_bner.c \
OCTET_STRING_bner.c \
REAL_bner.c

LDADD = -lm
Expand Down
Loading

0 comments on commit 194762f

Please sign in to comment.