From f3877bfa77273b0dbc569bdaa118808d8e3b6d24 Mon Sep 17 00:00:00 2001 From: "yu.dongliang" <18588496441@163.com> Date: Wed, 27 Sep 2023 18:46:21 +0800 Subject: [PATCH] test/main.c --- test/Makefile | 16 +++++++++++++ test/main.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 test/Makefile create mode 100644 test/main.c diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..0b8c383 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,16 @@ +CFILES += main.c +CFILES += ../scf_eda.pb-c.c +CFILES += ../scf_eda_pb.c + +CFLAGS += -g +CFLAGS += -I../ + +LDFLAGS += -lm +LDFLAGS += -lprotobuf-c +LDFLAGS += -lcairo + +all: + gcc $(CFLAGS) $(CFILES) $(LDFLAGS) + +clean: + rm *.o diff --git a/test/main.c b/test/main.c new file mode 100644 index 0000000..bf8a940 --- /dev/null +++ b/test/main.c @@ -0,0 +1,65 @@ +#include +#include +#include +#include"ses_core.h" + +int main(int argc, char* argv[]) +{ + ScfEcomponent* B; + ScfEcomponent* D0; + ScfEcomponent* D1; + ScfEcomponent* D2; + ScfEcomponent* R0; + ScfEcomponent* R1; + ScfEfunction* f; + ScfEboard* b; + + b = scf_eboard__alloc(); + f = scf_efunction__alloc("test"); + + EDA_INST_ADD_COMPONENT(f, B, SCF_EDA_Battery); + + B->pins[SCF_EDA_Battery_NEG]->flags = SCF_EDA_PIN_NEG; + B->pins[SCF_EDA_Battery_POS]->flags = SCF_EDA_PIN_POS; + + EDA_INST_ADD_COMPONENT(f, D0, SCF_EDA_Diode); + EDA_INST_ADD_COMPONENT(f, D1, SCF_EDA_Diode); + EDA_INST_ADD_COMPONENT(f, D2, SCF_EDA_Diode); + + EDA_INST_ADD_COMPONENT(f, R0, SCF_EDA_Resistor); + EDA_INST_ADD_COMPONENT(f, R1, SCF_EDA_Resistor); + + EDA_PIN_ADD_PIN(D0, SCF_EDA_Diode_POS, B, SCF_EDA_Battery_POS); + EDA_PIN_ADD_PIN(D0, SCF_EDA_Diode_NEG, D1, SCF_EDA_Battery_POS); + EDA_PIN_ADD_PIN(D1, SCF_EDA_Diode_NEG, R1, 1); + EDA_PIN_ADD_PIN(R1, 0, B, SCF_EDA_Battery_NEG); + + EDA_PIN_ADD_PIN(R0, 1, B, SCF_EDA_Battery_POS); + EDA_PIN_ADD_PIN(R0, 0, D2, SCF_EDA_Diode_POS); + EDA_PIN_ADD_PIN(D2, SCF_EDA_Diode_NEG, D1, SCF_EDA_Diode_NEG); + + scf_eboard__add_function(b, f); + + size_t len = scf_eboard__get_packed_size(b); + + scf_loge("len: %ld\n", len); + + uint8_t* buf = malloc(len); + if (!buf) { + scf_eboard__free(b); + return -ENOMEM; + } + + scf_eboard__pack(b, buf); + scf_eboard__free(b); + b = NULL; + + FILE* fp = fopen("./test.pb", "wb"); + if (!fp) + return -EINVAL; + + fwrite(buf, len, 1, fp); + fclose(fp); + + return 0; +} -- 2.25.1