lora-gateway / esxp1302

An 8-channel ESP32 LoRa Gateway based on SX1302
Other
33 stars 17 forks source link

main.c and lora_pkt_fwd.c doesn't contain the same code #10

Closed dennis4lora closed 3 weeks ago

dennis4lora commented 4 months ago

Currently, main.c is a hard link to lora_pkt_fwd.c (per commit: change soft link to hard link to support Windows PlatformIO compile).

However, the content of them doesn't match any more after a few commits.

This issue needs to be addressed. One solution is only keep one of them to avoid duplication...

danielkucera commented 4 months ago

Hi @dennis4lora , which file is used when you compile the project? For me it is main.c, I can safely delete lora_pkt_fwd.c

dennis4lora commented 4 months ago

Hi, @danielkucera :

there are a few app_main() defined in the main/test/ folder for testing purpose, and can't co-exist with lora_pkt_fwd.c or each other, but I think they could be useful. So in my design, I only include a main.c but soft-link it to whichever app_main() we want, and the default file is lora_pkt_fwd.c.

It works well until we want to support it under Windows, so I use hard-link instead of soft-link (that's why you can safely remove lora_pkt_fwd.c). I thought it works, until today, I just realized that recent commits only updates main.c, while lora_pkt_fwd.c has not been updated.

So I guess a better solution is removing the duplication and don't keep main.c at all. Then one way to choose which app_main been used is by controlling the main/CMakeLists.txt directly. However, this way feels a little ugly... :laughing:

danielkucera commented 4 months ago

I see. Can you potentially create one generic main which will call other apps? So they all get compiled and only the one(s) being called will get linked.

dennis4lora commented 4 months ago

In fact, in the future, I'll collect all of the test programs together and all are available from a mini-shell command line (as partly done in dev branch https://github.com/lora-gateway/esxp1302/blob/dev/main/libloragw-test/cli4test.c).

Then there will only have 2 app_main left (one for pkt_fwd and one for the tests); then the user can decide which app_main they want and choose it by set a MACRO flag or from command line, and this issue will be closed. :smile:

dennis4lora commented 3 weeks ago

There is no main.c anymore, and this issue can be closed now.

To choose whether to use main/packet_forwarder/lora_pkt_fwd.c or main/libloragw-test/cli4test.clibloragw-test/cli4test.c to provide main(), just control the value of MACRO CONFIG_LIBLORAGW_TEST (default is 0).

Currently in run_me.sh, it sets as this:

idf.py -DCONFIG_LIBLORAGW_TEST=0 app