made naming consistent, persistant data being saved and restored OK, first 2 plugin...
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 1 Feb 2016 23:50:10 +0000 (23:50 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 1 Feb 2016 23:50:10 +0000 (23:50 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2676 01035d8c-6547-0410-b346-abe4f91aad63

freedv-dev/src/afreedvplugin.c [new file with mode: 0644]
freedv-dev/src/dlg_plugin.cpp
freedv-dev/src/fdmdv2_main.cpp
freedv-dev/src/fdmdv2_main.h

diff --git a/freedv-dev/src/afreedvplugin.c b/freedv-dev/src/afreedvplugin.c
new file mode 100644 (file)
index 0000000..6f7b082
--- /dev/null
@@ -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 <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+/* 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++);
+}
+
index 0b1e47c3f0e7fe84a3a09c7646e174c2543c2abe..68610f4212f226c616303099445bb6c6701bd269 100644 (file)
@@ -121,7 +121,8 @@ void PlugInDlg::ExchangeData(int inout)
     {
         for (i=0; i<m_numParam; i++) {
           wxGetApp().m_txtPlugInParam[i] = m_txtCtrlParam[i]->GetValue();
-          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();
     }
index 59338b2e2bbce071167dfe1fcb35badcdba1fc3c..ba63ce54169b675259990edea0be374b8150af74 100644 (file)
@@ -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; i<nparams; i++) {
+                fprintf(stderr, "  plugin param name[%d]: %s\n", i, param_names[i]);
+                m_plugInParamName[i] = param_names[i];
+                wxString configStr = "/" + m_plugInName + "/" + m_plugInParamName[i];
+                wxGetApp().m_txtPlugInParam[i] = pConfig->Read(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);
 }
 
 
index 74af02da006d1852fdc420834c42d92c529cc891..096576311967caa6ac124fbaf7aa39bfc9512856 100644 (file)
@@ -62,6 +62,7 @@
 #else
 #include <termios.h>
 #include <sys/ioctl.h>
+#include <dlfcn.h>
 #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();