test/main.c
authoryu.dongliang <18588496441@163.com>
Wed, 27 Sep 2023 10:46:21 +0000 (18:46 +0800)
committeryu.dongliang <18588496441@163.com>
Wed, 27 Sep 2023 10:46:21 +0000 (18:46 +0800)
test/Makefile [new file with mode: 0644]
test/main.c [new file with mode: 0644]

diff --git a/test/Makefile b/test/Makefile
new file mode 100644 (file)
index 0000000..0b8c383
--- /dev/null
@@ -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 (file)
index 0000000..bf8a940
--- /dev/null
@@ -0,0 +1,65 @@
+#include<stdio.h>
+#include<stdlib.h>
+#include<string.h>
+#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;
+}