-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwrapper.c
132 lines (104 loc) · 3.65 KB
/
wrapper.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include <Python.h>
#include "wrapper.h"
/* Docstrings */
static char module_docstring[] =
"This library is a wrapper ";
/* Available functions */
static PyObject *_Init_ADC(PyObject *self, PyObject *args);
static PyObject *_Read_Single_Channel(PyObject *self, PyObject *args);
static PyObject *_Init_Single_Channel(PyObject *self, PyObject *args);
static PyObject *_ADC_Stop(PyObject *self, PyObject *args);
static PyObject *_thread1(PyObject *self, PyObject *args);
static PyObject *_kill_flag(PyObject *self, PyObject *args);
/* Module specification */
static PyMethodDef module_methods[] = {
// {"chi2", chi2_chi2, METH_VARARGS, chi2_docstring},
{"init", _Init_ADC, METH_VARARGS, {"Initializes the ADC"}},
{"read_channel", _Read_Single_Channel, METH_VARARGS, {"Reads a given channel"}},
{"init_channel", _Init_Single_Channel, METH_VARARGS, {"Initializes a given channel"}},
{"stop", _ADC_Stop, 0, {"Closes the ADC"}},
{"run", _thread1, METH_VARARGS, {"Runs the main program"}},
{"kill", _kill_flag, METH_VARARGS, {"Softly kills the program"}},
{NULL, NULL, 0, NULL}
};
/* Initialize the module */
//~ PyMODINIT_FUNC initads1256(void)
//~ {
//~ PyObject *m = Py_InitModule3("ads1256", module_methods, module_docstring);
//~ if (m == NULL)
//~ return;
//~ }
static struct PyModuleDef initads1256 =
{
PyModuleDef_HEAD_INIT,
"ads1256", /* name of module */
module_docstring, /* module documentation, may be NULL */
-1, /* size of per-interpreter state of the module, or -1 if the module keeps state in global variables. */
module_methods
};
PyMODINIT_FUNC PyInit_ads1256(void)
{
return PyModule_Create(&initads1256);
}
static PyObject *_Init_ADC(PyObject *self, PyObject *args)
{
double gain, sps;
unsigned char mode;
PyObject *yerr_obj;
printf("ERROR");
/* Parse the input tuple */
if (!PyArg_ParseTuple(args,"ddb",&gain,&sps,&mode,&yerr_obj))
return NULL;
/* execute the code */
Init_ADC(gain,sps,mode);
Py_RETURN_NONE;
}
static PyObject *_Read_Single_Channel(PyObject *self, PyObject *args)
{
unsigned char ch;
int value;
PyObject *yerr_obj;
/* Parse the input tuple */
if (!PyArg_ParseTuple(args, "b", &ch,&yerr_obj))
return NULL;
value = Read_Single_Channel(ch);
return Py_BuildValue("l", value);
}
static PyObject *_Init_Single_Channel(PyObject *self, PyObject *args)
{
unsigned char ch;
PyObject *yerr_obj;
/* Parse the input tuple */
if (!PyArg_ParseTuple(args, "b", &ch,&yerr_obj))
return NULL;
Init_Single_Channel(ch);
Py_RETURN_NONE;
}
static PyObject *_ADC_Stop(PyObject *self, PyObject *args)
{
/* execute the code */
int value = ADC_Stop();
/* Build the output tuple */
PyObject *ret = Py_BuildValue("i",value);
return ret;
}
static PyObject *_thread1(PyObject *self, PyObject *args)
{
double duration, gain, latitude, longitude, elevation;
char *stationcode, *instrumentstring, *stationchannel,*path;
int end;
unsigned char mode;
PyObject *yerr_obj;
/* Parse the input tuple */
if (!PyArg_ParseTuple(args,"dbdssdddss",&duration,&mode,&gain,&stationcode,&stationchannel,&latitude,&longitude,&elevation,&instrumentstring,&path,&yerr_obj))
return NULL;
/* execute the code */
end = thread1(duration,mode,gain,stationcode,stationchannel,latitude,longitude,elevation,instrumentstring,path);
return Py_BuildValue("i", end);
}
static PyObject *_kill_flag(PyObject *self, PyObject *args)
{
/* execute the code */
killProgram();
Py_RETURN_NONE;
}