-->
Page 1 of 1

Dynamically calling implemented Functions

PostPosted: Thu May 07, 2020 7:51 pm
by Agentsmithers
typedef struct
{
char *at_cmdName;
int8_t at_cmdLen;
void (*at_testCmd)(uint8_t id);
void (*at_queryCmd)(uint8_t id);
void (*at_setupCmd)(uint8_t id, char *pPara);
void (*at_exeCmd)(uint8_t id);
}at_funcationType;

at_funcationType at_custom_cmd[] = {
{"+TEST", 5, NULL, NULL, NULL, myTest_init}, / / ​​connect to the server, and register the corresponding callback.
{"+TESA", 5, NULL, NULL, NULL, myTest1}, // print ok
{"+TESB", 5, NULL, NULL, NULL, myTest2}, // print your own ip address
{"+TESC", 5, NULL, NULL, NULL, myTest3}, / / ​​Get the connected WiFi name password. has a problem
{"+TESD", 5, NULL, NULL, NULL, myTest4}, / / ​​send data test, need to call myTest_init before use
{"+TESE", 5, NULL, NULL, NULL, myTest5},
};


I am reviewing a few ideas on how to dynamically call functions if they exist (I add and remove headers in my projects) and am currently leveraging ifdef directives. However, depending on how the includes are arraigned
some defines can be skipped by mistake. After review, it seems AT Firmware deploys a simular schema to dynamically add additional calls during runtime. Does anyone have a simple snippet of code in this context? I would like to implement this idea but there are some core parts I feel I would like some assistant/ideas on like a sample function to dynamically add to the growing structure. Has anyone implemented a function Schema like this?

Re: Dynamically calling implemented Functions

PostPosted: Fri May 08, 2020 4:02 am
by Pablo2048
The best technique for automagically generated function list/table I have ever seen was in Nekromant's Frankenstein firmware (https://github.com/nekromant/esp8266-frankenstein). It consist of added section to the linker script where was this table automatically build by linker. I'm using same approach in my own firmware with patched Arduino framework in PIO.

Re: Dynamically calling implemented Functions

PostPosted: Fri May 08, 2020 8:04 pm
by Agentsmithers
Pablo2048 wrote:The best technique for automagically generated function list/table I have ever seen was in Nekromant's Frankenstein firmware (https://github.com/nekromant/esp8266-frankenstein). It consist of added section to the linker script where was this table automatically build by linker. I'm using same approach in my own firmware with patched Arduino framework in PIO.


Hey, This is a useful starting point. Thanks, Ill take a dive into the source and see if I can break the basics of it down and create a POC of my own. Any other useful suggestions would be appreciated :)