--- /dev/null
+/*
+ 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++);
+}
+
{
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();
}
// 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";
}
//-------------------------------------------------------------------------
int w;
int h;
+ if (m_plugIn)
+ dlclose(m_plugInHandle);
+
//fclose(ft);
#ifdef __WXMSW__
fclose(g_logfile);
void MainFrame::OnToolsPlugInCfgUI(wxUpdateUIEvent& event)
{
- event.Enable(!m_RxRunning);
+ event.Enable(!m_RxRunning && m_plugIn);
}
#else
#include <termios.h>
#include <sys/ioctl.h>
+#include <dlfcn.h>
#endif
#include "codec2.h"
// 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();