From: yu.dongliang <18588496441@163.com> Date: Wed, 27 Sep 2023 10:46:21 +0000 (+0800) Subject: test/main.c X-Git-Url: http://baseworks.info/?a=commitdiff_plain;h=f3877bfa77273b0dbc569bdaa118808d8e3b6d24;p=ses.git 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; +}