Commit 92cad39a authored by Anders Blomdell's avatar Anders Blomdell
Browse files

MEX fixes, build moberg_tool

parent b1f65077
LIBRARIES=libmoberg.so
MOBERG_VERSION=$(shell git describe --tags | sed -e 's/^v//;s/-/_/g' )
CCFLAGS+=-Wall -Werror -I$(shell pwd) -g
CCFLAGS+=-Wall -Werror -I$(shell pwd) -O3 -g
LDFLAGS+=-L$(shell pwd)/build/ -lmoberg
PLUGINS:=$(wildcard plugins/*)
ADAPTORS:=$(wildcard adaptors/*)
......@@ -8,7 +8,7 @@ export CCFLAGS LDFLAGS
LDFLAGS_parse_config=-ldl
#-export-dynamic
all: $(LIBRARIES:%=build/%) $(PLUGINS) $(ADAPTORS)
all: $(LIBRARIES:%=build/%) build/moberg $(PLUGINS) $(ADAPTORS)
echo $(PLUGINS)
echo $(CCFLAGS)
......@@ -16,6 +16,9 @@ build/libmoberg.so: Makefile | build
$(CC) -o $@ $(CCFLAGS) -shared -fPIC -I. \
$(filter %.o,$^) -lxdg-basedir -ldl
build/moberg: moberg_tool.c Makefile | build
$(CC) -o $@ $(CCFLAGS) $< -L../build -lmoberg
build/lib build:
mkdir -p $@
......
*.mex*
\ No newline at end of file
......@@ -8,11 +8,11 @@ TARGETS=realtimer \
encoderin
EXTRAFLAGS_realtimer=
EXTRAFLAGS_analogin=-lmoberg4simulink
EXTRAFLAGS_analogout=-lmoberg4simulink
EXTRAFLAGS_digitalin=-lmoberg4simulink
EXTRAFLAGS_digitalout=-lmoberg4simulink
EXTRAFLAGS_encoderin=-lmoberg4simulink
EXTRAFLAGS_analogin=-lmoberg4simulink -lmoberg
EXTRAFLAGS_analogout=-lmoberg4simulink -lmoberg
EXTRAFLAGS_digitalin=-lmoberg4simulink -lmoberg
EXTRAFLAGS_digitalout=-lmoberg4simulink -lmoberg
EXTRAFLAGS_encoderin=-lmoberg4simulink -lmoberg
all: $(TARGETS:%=%.$(SUFFIX))
......
......@@ -132,11 +132,12 @@ static void mdlOutputs(SimStruct *S, int_T tid)
{
int i;
real_T *y = ssGetOutputPortRealSignal(S, 1);
for (i = 0 ; i < ssGetNumPWork(S) ; i++) {
struct moberg_analog_in *ain = (struct moberg_analog_in*)pwork[i];
if (! ain->read(ain->context, &y[i])) {
if (! moberg_OK(ain->read(ain->context, &y[i]))) {
static char error[256];
double *channel = mxGetPr(ssGetSFcnParam(S,1));
sprintf(error, "Failed to read analogin #%d", (int)channel[i]);
ssSetErrorStatus(S, error);
}
......
......@@ -131,12 +131,17 @@ static void mdlOutputs(SimStruct *S, int_T tid)
y[0] = *up[0]+1;
}
{
InputRealPtrsType up = ssGetInputPortRealSignalPtrs(S,1);
int i;
InputRealPtrsType up = ssGetInputPortRealSignalPtrs(S,1);
for (i = 0 ; i < ssGetNumPWork(S) ; i++) {
struct moberg_analog_out *aout = (struct moberg_analog_out*)pwork[i];
aout->write(aout->context, *up[i]);
if (! moberg_OK(aout->write(aout->context, *up[i]))) {
static char error[256];
double *channel = mxGetPr(ssGetSFcnParam(S,1));
sprintf(error, "Failed to write analogout #%d", (int)channel[i]);
ssSetErrorStatus(S, error);
}
}
}
}
......
......@@ -137,7 +137,12 @@ static void mdlOutputs(SimStruct *S, int_T tid)
for (i = 0 ; i < ssGetNumPWork(S) ; i++) {
struct moberg_digital_in *din = (struct moberg_digital_in*)pwork[i];
int value;
din->read(din->context, &value);
if (! moberg_OK(din->read(din->context, &value))) {
static char error[256];
double *channel = mxGetPr(ssGetSFcnParam(S,1));
sprintf(error, "Failed to read digitalin #%d", (int)channel[i]);
ssSetErrorStatus(S, error);
}
y[i] = value;
}
}
......
......@@ -131,12 +131,17 @@ static void mdlOutputs(SimStruct *S, int_T tid)
y[0] = *up[0]+1;
}
{
InputRealPtrsType up = ssGetInputPortRealSignalPtrs(S,1);
int i;
InputRealPtrsType up = ssGetInputPortRealSignalPtrs(S,1);
for (i = 0 ; i < ssGetNumPWork(S) ; i++) {
struct moberg_digital_out *dout = (struct moberg_digital_out*)pwork[i];
dout->write(dout->context, *up[i]);
if (! moberg_OK(dout->write(dout->context, *up[i]))) {
static char error[256];
double *channel = mxGetPr(ssGetSFcnParam(S,1));
sprintf(error, "Failed to write digitalout #%d", (int)channel[i]);
ssSetErrorStatus(S, error);
}
}
}
}
......
......@@ -136,7 +136,12 @@ static void mdlOutputs(SimStruct *S, int_T tid)
for (i = 0 ; i < ssGetNumPWork(S) ; i++) {
struct moberg_encoder_in *ein = (struct moberg_encoder_in*)pwork[i];
long value;
ein->read(ein->context, &value);
if (! moberg_OK(ein->read(ein->context, &value))) {
static char error[256];
double *channel = mxGetPr(ssGetSFcnParam(S,1));
sprintf(error, "Failed to read encoderin #%d", (int)channel[i]);
ssSetErrorStatus(S, error);
}
y[i] = value;
}
}
......
......@@ -61,6 +61,8 @@ rm -rf ${RPM_BUILD_ROOT}
mkdir -p ${RPM_BUILD_ROOT}%{_libdir}
cp build/libmoberg*.so ${RPM_BUILD_ROOT}%{_libdir}
mkdir -p ${RPM_BUILD_ROOT}%{_sbindir}
cp build/moberg ${RPM_BUILD_ROOT}%{_sbindir}
mkdir -p ${RPM_BUILD_ROOT}%{_includedir}
cp moberg.h ${RPM_BUILD_ROOT}%{_includedir}
......@@ -89,6 +91,7 @@ cp adaptors/matlab/Makefile.mex ${RPM_BUILD_ROOT}/opt/matlab/src/moberg/Makefile
%{_includedir}/moberg.h
%{_libdir}/libmoberg.so
%{_libdir}/libmoberg_serial2002.so
%{_sbindir}/moberg
%files comedi
%defattr(-,root,root,-)
......
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <moberg.h>
void usage(char *prog) {
fprintf(stderr, "%s [ --start | --stop | -h | --help ]\n", prog);
}
int main(int argc, char *argv[])
{
if (argc == 2 && strcmp(argv[1], "--start") == 0) {
struct moberg *moberg = moberg_new(NULL);
moberg_start(moberg, stdout);
moberg_free(moberg);
} else if (argc == 2 && strcmp(argv[1], "--stop") == 0) {
struct moberg *moberg = moberg_new(NULL);
moberg_stop(moberg, stdout);
moberg_free(moberg);
} else if (argc == 2 && strcmp(argv[1], "-h") == 0) {
usage(argv[0]);
} else if (argc == 2 && strcmp(argv[1], "--help") == 0) {
usage(argv[0]);
} else {
usage(argv[0]);
exit(1);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment