Commit 8b39fc2e authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Some packaging cleanup

parent 694fab34
#!/usr/bin/julia
struct moberg_status
result::Clong
end
function check_OK(status::moberg_status)
if status.result != 0
error("Moberg call failed with errno $(status.result)")
end
end
mutable struct moberg
handle::Ptr{Nothing}
end
function moberg()
handle = ccall((:moberg_new, "libmoberg"), Ptr{Nothing}, ())
println(handle)
m = moberg(handle)
function close(h::moberg)
println(h)
ccall((:moberg_free, "libmoberg"), Nothing, (Ptr{Nothing},),
h.handle)
end
finalizer(close, m)
m
end
mutable struct moberg_analog_in
context::Ptr{Nothing}
do_read::Ptr{Nothing}
handle::moberg
moberg_analog_in(m::moberg, index::Unsigned) = (
self = new();
check_OK(ccall((:moberg_analog_in_open, "libmoberg"),
moberg_status,
(Ptr{Nothing}, Cint, Ref{moberg_analog_in}),
m.handle, index, self));
self.handle = m;
function close(channel::moberg_analog_in)
println(channel)
ccall((:moberg_analog_in_close, "libmoberg"),
moberg_status,
(Ptr{Nothing}, Cint, moberg_analog_in),
channel.handle.handle, index, self)
end;
finalizer(close, self);
self
)
end
mutable struct moberg_analog_out
context::Ptr{Nothing}
do_write::Ptr{Nothing}
handle::moberg
moberg_analog_out(m::moberg, index::Unsigned) = (
self = new();
check_OK(ccall((:moberg_analog_out_open, "libmoberg"),
moberg_status,
(Ptr{Nothing}, Cint, Ref{moberg_analog_out}),
m.handle, index, self));
self.handle = m;
function close(channel::moberg_analog_out)
println(channel)
ccall((:moberg_analog_out_close, "libmoberg"),
moberg_status,
(Ptr{Nothing}, Cint, moberg_analog_out),
channel.handle.handle, index, self)
end;
finalizer(close, self);
self
)
end
function read(ain::moberg_analog_in)
result = Ref{Cdouble}(0.0)
check_OK(ccall(ain.do_read,
moberg_status,
(Ptr{Nothing}, Ptr{Cdouble}),
ain.context, result))
return result[]
end
function write(aout::moberg_analog_out, value::Cdouble)
check_OK(ccall(aout.do_write,
moberg_status,
(Ptr{Nothing}, Cdouble),
aout.context, value))
end
function test()
m = moberg()
println(m)
for v in -10.0:2.0:10
for i in 30:31
try
aout = moberg_analog_out(m, Unsigned(i))
value = v + i - 32;
write(aout, value)
print("$value ")
catch
println("analog_out $i does not exist")
end
end
println()
sleep(0.1)
for j in 30:33
try
ain = moberg_analog_in(m, Unsigned(j))
println(read(ain))
catch
println("analog_in $j does not exist")
end
end
println()
GC.gc()
end
end
test()
println("DONE")
GC.gc()
println("Really DONE")
#!/usr/bin/julia
push!(LOAD_PATH, ".")
using MobergIO
import MobergIO: read, write
function test()
m = MobergIO.Moberg()
println(m)
for v in -10.0:2.0:10
for i in 30:31
try
aout = MobergIO.AnalogOut(m, Unsigned(i))
value = v + i - 32;
write(aout, value)
print("$value ")
catch ex
println("analog_out $i does not exist $(ex)")
end
end
println()
sleep(0.01)
for j in 30:33
try
ain = MobergIO.AnalogIn(m, Unsigned(j))
println(read(ain))
catch ex
println("analog_in $j does not exist $(ex)")
end
end
println()
# GC.gc()
end
for v in false:true
for i in 30:36
try
dout = MobergIO.DigitalOut(m, Unsigned(i))
value = xor(v, isodd(i))
write(dout, value)
print("$value ")
catch ex
println("digital_out $i does not exist $(ex)")
end
end
println()
for i in 30:36
try
din = MobergIO.DigitalIn(m, Unsigned(i))
print("$(read(din)) ")
catch ex
println("digital_out $i does not exist $(ex)")
end
end
println()
println()
sleep(0.01)
end
end
test()
println("DONE")
GC.gc()
println("Really DONE")
...@@ -5,11 +5,19 @@ Summary: Library for abstracting physical I/O ...@@ -5,11 +5,19 @@ Summary: Library for abstracting physical I/O
License: GPLv3 License: GPLv3
Source0: https://gitlab.control.lth.se/anders_blomdell/moberg/-/archive/master/moberg-__MOBERG_VERSION__.tar.gz Source0: https://gitlab.control.lth.se/anders_blomdell/moberg/-/archive/master/moberg-__MOBERG_VERSION__.tar.gz
%if 0%{!?python3_pkgversion:1}
%define python3_pkgversion 3
%endif
BuildRequires: gcc BuildRequires: gcc
BuildRequires: comedilib-devel BuildRequires: comedilib-devel
BuildRequires: valgrind BuildRequires: valgrind
BuildRequires: libxdg-basedir-devel BuildRequires: libxdg-basedir-devel
BuildRequires: java-devel BuildRequires: java-devel
BuildRequires: python2-devel
BuildRequires: python3-devel
BuildRequires: julia
%description %description
Shared library for abstracting physical process I/O (analog, digital Shared library for abstracting physical process I/O (analog, digital
...@@ -45,6 +53,27 @@ Requires: %{name}-devel = %{version}-%{release} ...@@ -45,6 +53,27 @@ Requires: %{name}-devel = %{version}-%{release}
%description matlab %description matlab
Matlab support files for %{name} Matlab support files for %{name}
%package -n python2-%{name}
Summary: Python2 support files for %{name}
Requires: %{name} = %{version}-%{release}
%description -n python2-%{name}
Python2 support files for %{name}
%package -n python%{python3_pkgversion}-%{name}
Summary: Python3 support files for %{name}
Requires: %{name} = %{version}-%{release}
%description -n python%{python3_pkgversion}-%{name}
Python3 support files for %{name}
%package -n MobergIO.jl
Summary: Julia support files for %{name}
Requires: %{name} = %{version}-%{release}
%description -n MobergIO.jl
Julia support files for %{name}
%prep %prep
%setup -q -n %{name}-__MOBERG_VERSION__ %setup -q -n %{name}-__MOBERG_VERSION__
...@@ -66,6 +95,7 @@ cp build/moberg ${RPM_BUILD_ROOT}%{_sbindir} ...@@ -66,6 +95,7 @@ cp build/moberg ${RPM_BUILD_ROOT}%{_sbindir}
mkdir -p ${RPM_BUILD_ROOT}%{_includedir} mkdir -p ${RPM_BUILD_ROOT}%{_includedir}
cp moberg.h ${RPM_BUILD_ROOT}%{_includedir} cp moberg.h ${RPM_BUILD_ROOT}%{_includedir}
# devel # devel
cp moberg_config.h ${RPM_BUILD_ROOT}%{_includedir} cp moberg_config.h ${RPM_BUILD_ROOT}%{_includedir}
cp moberg_device.h ${RPM_BUILD_ROOT}%{_includedir} cp moberg_device.h ${RPM_BUILD_ROOT}%{_includedir}
...@@ -73,6 +103,7 @@ cp moberg_inline.h ${RPM_BUILD_ROOT}%{_includedir} ...@@ -73,6 +103,7 @@ cp moberg_inline.h ${RPM_BUILD_ROOT}%{_includedir}
cp moberg_module.h ${RPM_BUILD_ROOT}%{_includedir} cp moberg_module.h ${RPM_BUILD_ROOT}%{_includedir}
cp moberg_parser.h ${RPM_BUILD_ROOT}%{_includedir} cp moberg_parser.h ${RPM_BUILD_ROOT}%{_includedir}
# Java
JAVA_ARCH=$(adaptors/java/src/getProperty_os_arch) JAVA_ARCH=$(adaptors/java/src/getProperty_os_arch)
mkdir -p ${RPM_BUILD_ROOT}/opt/java/se.lth.control.realtime.Moberg/jre/lib/${JAVA_ARCH} mkdir -p ${RPM_BUILD_ROOT}/opt/java/se.lth.control.realtime.Moberg/jre/lib/${JAVA_ARCH}
mkdir -p ${RPM_BUILD_ROOT}/opt/java/se.lth.control.realtime.Moberg/jre/lib/ext mkdir -p ${RPM_BUILD_ROOT}/opt/java/se.lth.control.realtime.Moberg/jre/lib/ext
...@@ -83,7 +114,7 @@ cp adaptors/java/build/libse_lth_control_realtime_moberg_Moberg.so \ ...@@ -83,7 +114,7 @@ cp adaptors/java/build/libse_lth_control_realtime_moberg_Moberg.so \
cp adaptors/java/build/Moberg.jar \ cp adaptors/java/build/Moberg.jar \
${RPM_BUILD_ROOT}/opt/java/se.lth.control.realtime.Moberg/jre/lib/ext/ ${RPM_BUILD_ROOT}/opt/java/se.lth.control.realtime.Moberg/jre/lib/ext/
# Matlab
mkdir -p ${RPM_BUILD_ROOT}/opt/matlab/src/moberg mkdir -p ${RPM_BUILD_ROOT}/opt/matlab/src/moberg
mkdir -p ${RPM_BUILD_ROOT}%{_includedir} mkdir -p ${RPM_BUILD_ROOT}%{_includedir}
cp adaptors/matlab/moberg4simulink.h ${RPM_BUILD_ROOT}%{_includedir} cp adaptors/matlab/moberg4simulink.h ${RPM_BUILD_ROOT}%{_includedir}
...@@ -92,6 +123,23 @@ cp adaptors/matlab/*in.c ${RPM_BUILD_ROOT}/opt/matlab/src/moberg ...@@ -92,6 +123,23 @@ cp adaptors/matlab/*in.c ${RPM_BUILD_ROOT}/opt/matlab/src/moberg
cp adaptors/matlab/*out.c ${RPM_BUILD_ROOT}/opt/matlab/src/moberg cp adaptors/matlab/*out.c ${RPM_BUILD_ROOT}/opt/matlab/src/moberg
cp adaptors/matlab/Makefile.mex ${RPM_BUILD_ROOT}/opt/matlab/src/moberg/Makefile cp adaptors/matlab/Makefile.mex ${RPM_BUILD_ROOT}/opt/matlab/src/moberg/Makefile
# Python
(
cd adaptors/python
export MOBERG_VERSION=__MOBERG_VERSION__
%{__python2} setup.py install -O1 \
--root=$RPM_BUILD_ROOT --prefix /usr \
--record=INSTALLED_python2
%{__python3} setup.py install -O1 \
--root=$RPM_BUILD_ROOT --prefix /usr \
--record=INSTALLED_python3
)
# Julia
mkdir -p ${RPM_BUILD_ROOT}/opt/julia/packages/MobergIO/src
cp adaptors/julia/* ${RPM_BUILD_ROOT}/opt/julia/packages/MobergIO/src
%files %files
%defattr(-,root,root,-) %defattr(-,root,root,-)
%{_includedir}/moberg.h %{_includedir}/moberg.h
...@@ -105,12 +153,12 @@ cp adaptors/matlab/Makefile.mex ${RPM_BUILD_ROOT}/opt/matlab/src/moberg/Makefile ...@@ -105,12 +153,12 @@ cp adaptors/matlab/Makefile.mex ${RPM_BUILD_ROOT}/opt/matlab/src/moberg/Makefile
%files devel %files devel
%defattr(-,root,root,-) %defattr(-,root,root,-)
%{_includedir}/moberg_inline.h
%{_includedir}/moberg_config.h %{_includedir}/moberg_config.h
%{_includedir}/moberg_device.h %{_includedir}/moberg_device.h
%{_includedir}/moberg_inline.h %{_includedir}/moberg_inline.h
%{_includedir}/moberg_module.h %{_includedir}/moberg_module.h
%{_includedir}/moberg_parser.h %{_includedir}/moberg_parser.h
%{_libdir}/libmoberg_libtest.so
%files java %files java
%defattr(-,root,root,-) %defattr(-,root,root,-)
...@@ -121,3 +169,13 @@ cp adaptors/matlab/Makefile.mex ${RPM_BUILD_ROOT}/opt/matlab/src/moberg/Makefile ...@@ -121,3 +169,13 @@ cp adaptors/matlab/Makefile.mex ${RPM_BUILD_ROOT}/opt/matlab/src/moberg/Makefile
%{_libdir}/libmoberg4simulink.so %{_libdir}/libmoberg4simulink.so
/opt/matlab/src/moberg/* /opt/matlab/src/moberg/*
%{_includedir}/moberg4simulink.h %{_includedir}/moberg4simulink.h
%files -n python2-%{name} -f adaptors/python/INSTALLED_python2
%defattr(-,root,root,-)
%files -n python%{python3_pkgversion}-%{name} -f adaptors/python/INSTALLED_python3
%defattr(-,root,root,-)
%files -n MobergIO.jl
%defattr(-,root,root,-)
/opt/julia/packages/MobergIO
\ No newline at end of file
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