From daeb81614661946d7955403a0e881745aff1a016 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Mon, 1 Feb 2016 23:50:10 +0000 Subject: [PATCH] made naming consistent, persistant data being saved and restored OK, first 2 plugin function calls doing something sensible git-svn-id: https://svn.code.sf.net/p/freetel/code@2676 01035d8c-6547-0410-b346-abe4f91aad63 --- freedv-dev/src/afreedvplugin.c | 75 ++++++++++++++++++++++++++++++++++ freedv-dev/src/dlg_plugin.cpp | 3 +- freedv-dev/src/fdmdv2_main.cpp | 54 +++++++++++++++++++++--- freedv-dev/src/fdmdv2_main.h | 3 ++ 4 files changed, 128 insertions(+), 7 deletions(-) create mode 100644 freedv-dev/src/afreedvplugin.c diff --git a/freedv-dev/src/afreedvplugin.c b/freedv-dev/src/afreedvplugin.c new file mode 100644 index 00000000..6f7b0824 --- /dev/null +++ b/freedv-dev/src/afreedvplugin.c @@ -0,0 +1,75 @@ +/* + afreedvplugin.c + David Rowe Feb 2016 + + Sample FreeDV plugin + + TODO: + [ ] plugin to call back to functions + [ ] ability to list .so's/DLLs and scan + [ ] where do we put plugins? + [ ] Windows build and test environment + + $ gcc -Wall -fPIC -c afreedvplugin.c + $ gcc -shared -Wl,-soname,afreedvplugin.so -o afreedvplugin.so afreedvplugin.o +*/ + +#include +#include +#include + +/* functions plugin can call */ + +int plugin_alert(char string[]); +int plugin_get_persistant(char name[], char value[]); +int plugin_set_persistant(char name[], char value[]); + +struct APLUGIN_STATES { + int counter; +}; + +/* plugin functions called by host, we need to write these */ + +void plugin_name(char name[]) { + sprintf(name, "aFreeDVplugIn"); +} + +/* + Text fields will be created for nparams, using the names + in *param_names[]. These fields we be saved to persistent + storage as name/param_names[0], name/param_names[1] .... +*/ + +void *plugin_open(char *param_names[], int *nparams) { + struct APLUGIN_STATES *states; + + strcpy(param_names[0], "SymbolRate"); + strcpy(param_names[1], "NumTones"); + *nparams = 2; + + states = (struct APLUGIN_STATES *)malloc(sizeof(struct APLUGIN_STATES)); + if (states == NULL) { + plugin_alert("Problem starting plugin!"); + return NULL; + } + states->counter = 0; + + return (void*)states; +} + +void plugin_close(void *states) { + free(states); +} + +void plugin_start(void *states) { +} + +void plugin_stop(void *states) { +} + +void plugin_rx_samples(void *s, short samples[], int n) { + struct APLUGIN_STATES *states = (struct APLUGIN_STATES*)s; + printf("Got n=%d samples!\n", n); + printf("samples[0] = %d samples[%d-1] = %d counter = %d\n", samples[0], n, samples[n-1], states->counter++); +} + diff --git a/freedv-dev/src/dlg_plugin.cpp b/freedv-dev/src/dlg_plugin.cpp index 0b1e47c3..68610f42 100644 --- a/freedv-dev/src/dlg_plugin.cpp +++ b/freedv-dev/src/dlg_plugin.cpp @@ -121,7 +121,8 @@ void PlugInDlg::ExchangeData(int inout) { for (i=0; iGetValue(); - pConfig->Write(wxT("/PlugIn/" + m_name + "/" + m_paramName[i]), wxGetApp().m_txtPlugInParam[i]); + wxString configStr = "/" + m_name + "/" + m_paramName[i]; + pConfig->Write(configStr, wxGetApp().m_txtPlugInParam[i]); } pConfig->Flush(); } diff --git a/freedv-dev/src/fdmdv2_main.cpp b/freedv-dev/src/fdmdv2_main.cpp index 59338b2e..ba63ce54 100644 --- a/freedv-dev/src/fdmdv2_main.cpp +++ b/freedv-dev/src/fdmdv2_main.cpp @@ -527,11 +527,50 @@ MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent) // Look for Plug In - m_plugIn = true; - m_plugInName = "MyModem"; - m_numPlugInParam = 2; - m_plugInParamName[0] = "Symbol Rate"; - m_plugInParamName[1] = "Num Tones"; + m_plugIn = false; + m_plugInHandle = dlopen("/home/david/tmp/modem_api/afreedvplugin.so", RTLD_LAZY); + + if (m_plugInHandle) { + fprintf(stderr, "plugin: .so found\n"); + + // lets get some information abt the plugIn + + void (*plugin_namefp)(char s[]); + void *(*plugin_openfp)(char *param_names[], int *nparams); + + plugin_namefp = (void (*)(char*))dlsym(m_plugInHandle, "plugin_name"); + plugin_openfp = (void* (*)(char**,int *))dlsym(m_plugInHandle, "plugin_open"); + + if ((plugin_namefp != NULL) && (plugin_openfp != NULL)) { + + char s[256]; + m_plugIn = true; + (plugin_namefp)(s); + fprintf(stderr, "plugin name: %s\n", s); + m_plugInName = s; + + char param_name1[80], param_name2[80]; + char *param_names[2] = {param_name1, param_name2}; + int nparams, i; + m_plugInStates = (plugin_openfp)(param_names, &nparams); + m_numPlugInParam = nparams; + for(i=0; iRead(configStr, wxT("")); + } + } + else { + fprintf(stderr, "plugin: fps not found...\n"); + } + } + + //m_plugIn = true; + //m_plugInName = "MyModem"; + //m_numPlugInParam = 2; + //m_plugInParamName[0] = "Symbol Rate"; + //m_plugInParamName[1] = "Num Tones"; } //------------------------------------------------------------------------- @@ -544,6 +583,9 @@ MainFrame::~MainFrame() int w; int h; + if (m_plugIn) + dlclose(m_plugInHandle); + //fclose(ft); #ifdef __WXMSW__ fclose(g_logfile); @@ -2182,7 +2224,7 @@ void MainFrame::OnToolsPlugInCfg(wxCommandEvent& event) void MainFrame::OnToolsPlugInCfgUI(wxUpdateUIEvent& event) { - event.Enable(!m_RxRunning); + event.Enable(!m_RxRunning && m_plugIn); } diff --git a/freedv-dev/src/fdmdv2_main.h b/freedv-dev/src/fdmdv2_main.h index 74af02da..09657631 100644 --- a/freedv-dev/src/fdmdv2_main.h +++ b/freedv-dev/src/fdmdv2_main.h @@ -62,6 +62,7 @@ #else #include #include +#include #endif #include "codec2.h" @@ -581,10 +582,12 @@ class MainFrame : public TopFrame // plugin details + void *m_plugInHandle; bool m_plugIn; wxString m_plugInName; int m_numPlugInParam; wxString m_plugInParamName[PLUGIN_MAX_PARAMS]; + void *m_plugInStates; }; void txRxProcessing(); -- 2.25.1