Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • anders_blomdell/moberg
  • cont-frb/moberg
  • mattiasf/moberg
3 results
Select Git revision
Show changes
Commits on Source (67)
Showing
with 280 additions and 23 deletions
LIBRARIES=libmoberg.so
MOBERG_VERSION=$(shell git describe --tags | sed -e 's/^v//;s/-/_/g' )
MOBERG_VERSION=$(shell git describe --tags \
| sed -re 's/^v//;s/-(.*)-(.*)$$/.dev\1+\2/')
CCFLAGS+=-Wall -Werror -I$(shell pwd) -O3 -g
LDFLAGS+=-L$(shell pwd)/build/ -lmoberg
PLUGINS:=$(wildcard plugins/*)
ADAPTORS:=$(wildcard adaptors/*)
PLUGINS:=$(sort $(wildcard plugins/*))
ADAPTORS:=$(sort $(wildcard adaptors/*))
export CCFLAGS LDFLAGS
LDFLAGS_parse_config=-ldl
#-export-dynamic
......@@ -23,7 +24,7 @@ build/lib build:
mkdir -p $@
%: build/%.o Makefile
$(CC) $(LDFLAGS) $(LDFLAGS_$(*)) -o $@ $(filter %.o,$^)
$(CC) -o $@ $(filter %.o,$^) $(LDFLAGS) $(LDFLAGS_$(*))
build/%.o: %.c Makefile
$(CC) $(CCFLAGS) -c -o $@ $<
......@@ -62,13 +63,13 @@ test: all
$(MAKE) -C test test
clean:
rm -f build/*.so
rm -f build/*.mex*
rm -rf build/
rm -f *~
rm -f moberg-*.spec
rm -f moberg-*.tar.gz
make -C test clean
for d in $(ADAPTORS) ; do make -C $$d clean ; done
for d in $(PLUGINS) ; do make -C $$d clean ; done
build/libmoberg.so: build/lib/moberg.o
build/libmoberg.so: build/lib/moberg_config.o
......@@ -79,3 +80,9 @@ build/lib/%.o: moberg_inline.h
build/lib/moberg.o: moberg_config.h
build/lib/moberg.o: moberg_module.h
build/lib/moberg.o: moberg_parser.h
build/lib/moberg_device.o: moberg.h
build/lib/moberg_device.o: moberg_channel.h
build/lib/moberg_device.o: moberg_config.h
build/lib/moberg_device.o: moberg_device.h
build/lib/moberg_device.o: moberg_inline.h
*.class
......@@ -3,9 +3,10 @@ JARNAME=Moberg
TARFILE=java_se.lth.control.realtime.Moberg-$(VERSION).tar.gz
JNINAME=se_lth_control_realtime_moberg_Moberg
JAVAH_PATH=$(shell javah -Xbootclasspath/p:build -version >/dev/null 2>&1 && \
echo -Xbootclasspath/p:build || echo -bootclasspath build)
JNI_INCLUDE=/usr/lib/jvm/java/include/
JAVA_HOME=$(shell realpath /usr/bin/javac | sed 's|/bin/javac||')
JNI_INCLUDE=$(JAVA_HOME)/include/
JNI_INCLUDE=$(JAVA_HOME)/include/
CC=gcc
CC_JNI_FLAGS=-Wall -Werror -shared -fPIC \
-I$(JNI_INCLUDE) -I$(JNI_INCLUDE)/linux \
......@@ -44,7 +45,7 @@ JAVAC: $(JAVAFILES:%.java=build/%.class)
build/%.class: src/%.java
# Recompile all javafiles at once (do JIT compilation once)
mkdir -p build
cd src ; javac -d ../build -target 1.5 -source 1.5 $(JAVAFILES)
cd src ; javac -d ../build $(JAVAFILES)
build/$(JARNAME).jar: JAVAC
jar -cf $@ \
......@@ -53,7 +54,8 @@ build/$(JARNAME).jar: JAVAC
build/%.h: $(shell echo $(JNINAME:%=build/%.class) | sed -e 's:_:/:g')
# Too many dependencies, base the ones we need on $* (matches % above)
javah -o $@ -force $(JAVAH_PATH) $(shell echo $* | sed -e s/_/./g)
cd src ; javac -h ../$(dir $@) -d ../build \
$(shell echo $* | sed -e 's|_|/|g').java
build/lib%.so: $(JNINAME:%=build/%.h) $(JNINAME:%=src/%.c)
# Too many dependencies, base the ones we need on $* (matches % above)
......
......@@ -35,8 +35,13 @@ public class AnalogIn extends IOChannel {
Moberg.analogInClose(index);
}
@Deprecated
public double get() throws IOChannelException {
return Moberg.analogIn(index);
}
public double read() throws IOChannelException {
return Moberg.analogIn(index);
}
}
......@@ -39,8 +39,13 @@ public class AnalogOut extends IOChannel {
Moberg.analogOutClose(index);
}
@Deprecated
public void set(double value) throws IOChannelException {
Moberg.analogOut(index, value);
}
public double write(double value) throws IOChannelException {
return Moberg.analogOut(index, value);
}
}
......@@ -37,8 +37,13 @@ public class DigitalIn extends IOChannel {
Moberg.digitalInClose(index);
}
@Deprecated
public boolean get() throws IOChannelException {
return Moberg.digitalIn(index);
}
public boolean read() throws IOChannelException {
return Moberg.digitalIn(index);
}
}
......@@ -36,8 +36,13 @@ public class DigitalOut extends IOChannel {
Moberg.digitalOutClose(index);
}
@Deprecated
public void set(boolean value) throws IOChannelException {
Moberg.digitalOut(index, value);
}
public boolean write(boolean value) throws IOChannelException {
return Moberg.digitalOut(index, value);
}
}
......@@ -37,8 +37,13 @@ public class EncoderIn extends IOChannel {
Moberg.encoderInClose(index);
}
@Deprecated
public long get() throws IOChannelException {
return Moberg.encoderIn(index);
}
public long read() throws IOChannelException {
return Moberg.encoderIn(index);
}
}
......@@ -25,7 +25,8 @@ import java.util.BitSet;
public abstract class IOChannel {
private static HashMap allocations = new HashMap();
private static class AllocationMap extends HashMap<String, BitSet> {}
private static AllocationMap allocations = new AllocationMap();
public final int index;
private BitSet allocation;
......
......@@ -28,7 +28,7 @@ public class Moberg {
public static native void analogOutOpen(int index) throws MobergException;
public static native void analogOutClose(int index) throws MobergException;
public static native void analogOut(int index, double value) throws MobergException;
public static native double analogOut(int index, double value) throws MobergException;
public static native void digitalInOpen(int index) throws MobergException;
public static native void digitalInClose(int index) throws MobergException;
......@@ -36,7 +36,7 @@ public class Moberg {
public static native void digitalOutOpen(int index) throws MobergException;
public static native void digitalOutClose(int index) throws MobergException;
public static native void digitalOut(int index, boolean value) throws MobergException;
public static native boolean digitalOut(int index, boolean value) throws MobergException;
public static native void encoderInOpen(int index) throws MobergException;
public static native void encoderInClose(int index) throws MobergException;
......
......@@ -113,7 +113,7 @@ struct {
static int up()
{
if (g_moberg.count <= 0) {
g_moberg.moberg = moberg_new(NULL);
g_moberg.moberg = moberg_new();
}
g_moberg.count++;
return 0;
......@@ -139,7 +139,7 @@ static struct channel *channel_get(struct list *list, int index)
static int channel_set(struct list *list, int index, struct channel channel)
{
if (list->capacity < index) {
if (list->capacity <= index) {
int capacity = index + 1;
void *new = realloc(list->channel, capacity * sizeof(*list->channel));
if (new) {
......@@ -261,16 +261,19 @@ Java_se_lth_control_realtime_moberg_Moberg_analogOutClose(
}
JNIEXPORT void JNICALL
JNIEXPORT double JNICALL
Java_se_lth_control_realtime_moberg_Moberg_analogOut(
JNIEnv *env, jobject obj, jint index, jdouble value
JNIEnv *env, jobject obj, jint index, jdouble desired
)
{
struct channel *channel = channel_get(&analog_out, index);
if (! channel) {
throwMobergNotOpenException(env, index);
return 0.0;
} else {
channel->analog_out.write(channel->analog_out.context, value);
double actual;
channel->analog_out.write(channel->analog_out.context, desired, &actual);
return actual;
}
}
......@@ -354,16 +357,19 @@ Java_se_lth_control_realtime_moberg_Moberg_digitalOutClose(
}
}
JNIEXPORT void JNICALL
JNIEXPORT jboolean JNICALL
Java_se_lth_control_realtime_moberg_Moberg_digitalOut(
JNIEnv *env, jobject obj, jint index, jboolean value
JNIEnv *env, jobject obj, jint index, jboolean desired
)
{
struct channel *channel = channel_get(&digital_out, index);
if (! channel) {
throwMobergNotOpenException(env, index);
return 0;
} else {
channel->digital_out.write(channel->digital_out.context, value);
int actual;
channel->digital_out.write(channel->digital_out.context, desired, &actual);
return actual;
}
}
......
MobergIO.jl is licensed under the MIT License:
> Copyright (c) 2021: Anders Blomdell
>
> Permission is hereby granted, free of charge, to any person obtaining
> a copy of this software and associated documentation files (the
> "Software"), to deal in the Software without restriction, including
> without limitation the rights to use, copy, modify, merge, publish,
> distribute, sublicense, and/or sell copies of the Software, and to
> permit persons to whom the Software is furnished to do so, subject to
> the following conditions:
>
> The above copyright notice and this permission notice shall be
> included in all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
> NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
> LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
> OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
> WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
all:
name = "MobergIO"
uuid = "9bdc2bb6-e40d-4944-bd5f-2bf890d3f651"
authors = ["Anders Blomdell <anders.blomdell@control.lth.se>"]
version = "1.0.0"
[compat]
julia = "1"
[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
[targets]
test = ["Test"]
# MobergIO.jl
A library for connecting to various input/output libraries with a common interface.
You need a local configuration and installation of Moberg for this package to work properly, see: [github.com/ControlLTH/moberg](https://github.com/ControlLTH/moberg).
mutable struct AnalogIn <: AbstractMobergIn
moberg::Ptr{Nothing}
index::UInt32
channel::MobergInChannel
function AnalogIn(moberg::Moberg, index::Unsigned)
channel = MobergInChannel(0,0)
moberg_handle = moberg.handle
checkOK(ccall((:moberg_analog_in_open, "libmoberg"),
Status,
(Ptr{Nothing}, Cint, Ref{MobergInChannel}),
moberg_handle, index, channel))
self = new(moberg_handle, index, channel)
finalizer(close, self)
self
end
end
function close(ain::AnalogIn)
DEBUG && println("closing $(ain)")
checkOK(ccall((:moberg_analog_in_close, "libmoberg"),
Status,
(Ptr{Nothing}, Cint, MobergInChannel),
ain.moberg, ain.index, ain.channel))
end
function read(ain::AnalogIn)
result = Ref{Cdouble}(0.0)
checkOK(ccall(ain.channel.read,
Status,
(Ptr{Nothing}, Ptr{Cdouble}),
ain.channel.context, result))
return result[]
end
mutable struct AnalogOut <: AbstractMobergOut
moberg::Ptr{Nothing}
index::UInt32
channel::MobergOutChannel
function AnalogOut(moberg::Moberg, index::Unsigned)
channel = MobergOutChannel(0,0)
moberg_handle = moberg.handle
checkOK(ccall((:moberg_analog_out_open, "libmoberg"),
Status,
(Ptr{Nothing}, Cint, Ref{MobergOutChannel}),
moberg_handle, index, channel));
self = new(moberg_handle, index, channel)
finalizer(close, self)
self
end
end
function close(aout::AnalogOut)
DEBUG && println("closing $(aout)")
checkOK(ccall((:moberg_analog_out_close, "libmoberg"),
Status,
(Ptr{Nothing}, Cint, MobergOutChannel),
aout.moberg, aout.index, aout.channel))
end
function write(aout::AnalogOut, value::Cdouble)
result = Ref{Cdouble}(0.0)
checkOK(ccall(aout.channel.write,
Status,
(Ptr{Nothing}, Cdouble, Ptr{Cdouble}),
aout.channel.context, value, result))
return result[];
end
mutable struct DigitalIn <: AbstractMobergIn
moberg::Ptr{Nothing}
index::UInt32
channel::MobergInChannel
function DigitalIn(moberg::Moberg, index::Unsigned)
channel = MobergInChannel(0,0)
moberg_handle = moberg.handle
checkOK(ccall((:moberg_digital_in_open, "libmoberg"),
Status,
(Ptr{Nothing}, Cint, Ref{MobergInChannel}),
moberg_handle, index, channel));
self = new(moberg_handle, index, channel)
finalizer(close, self)
self
end
end
function close(din::DigitalIn)
DEBUG && println("closing $(din)")
checkOK(ccall((:moberg_digital_in_close, "libmoberg"),
Status,
(Ptr{Nothing}, Cint, MobergInChannel),
din.moberg, din.index, din.channel))
end
function read(din::DigitalIn)
result = Ref{Cint}(0)
checkOK(ccall(din.channel.read,
Status,
(Ptr{Nothing}, Ptr{Cint}),
din.channel.context, result))
return result[] != 0
end
mutable struct DigitalOut <: AbstractMobergOut
moberg::Ptr{Nothing}
index::UInt32
channel::MobergOutChannel
function DigitalOut(moberg::Moberg, index::Unsigned)
channel = MobergOutChannel(0,0)
moberg_handle = moberg.handle
checkOK(ccall((:moberg_digital_out_open, "libmoberg"),
Status,
(Ptr{Nothing}, Cint, Ref{MobergOutChannel}),
moberg_handle, index, channel))
self = new(moberg_handle, index, channel)
finalizer(close, self)
self
end
end
function close(dout::DigitalOut)
DEBUG && println("closing $(dout)")
checkOK(ccall((:moberg_digital_out_close, "libmoberg"),
Status,
(Ptr{Nothing}, Cint, MobergOutChannel),
dout.moberg, dout.index, dout.channel))
end
function write(dout::DigitalOut, value::Bool)
result = Ref{Cint}(0)
checkOK(ccall(dout.channel.write,
Status,
(Ptr{Nothing}, Cint, Ptr{Cint}),
dout.channel.context, value ? 1 : 0, result))
return result[] != 0
end
"""
encoder_in = EncoderIn(moberg::Moberg, index::Unsigned)
Example usage:
encoder_in = EncoderIn(m, UInt32(40))
result = read(encoder_in)
"""
mutable struct EncoderIn <: AbstractMobergIn
moberg::Ptr{Nothing}
index::UInt32
channel::MobergInChannel
function EncoderIn(moberg::Moberg, index::Unsigned)
channel = MobergInChannel(0,0)
moberg_handle = moberg.handle
checkOK(ccall((:moberg_encoder_in_open, "libmoberg"),
Status,
(Ptr{Nothing}, Cint, Ref{MobergInChannel}),
moberg_handle, index, channel))
self = new(moberg_handle, index, channel)
finalizer(close, self)
self
end
end
function close(ein::EncoderIn)
DEBUG && println("closing $(ein)")
checkOK(ccall((:moberg_encoder_in_close, "libmoberg"),
Status,
(Ptr{Nothing}, Cint, MobergInChannel),
ein.moberg, ein.index, ein.channel))
end
function read(ein::EncoderIn)
result = Ref{Clong}(0)
checkOK(ccall(ein.channel.read,
Status,
(Ptr{Nothing}, Ptr{Clong}),
ein.channel.context, result))
return result[]
end