Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Michel Roelofs
dt_ctrl
Commits
bab5bbe6
Commit
bab5bbe6
authored
Jun 06, 2013
by
Jeroen Vreeken
Browse files
new work in progress patch from daan.
'work-in-progress-daan-2013-06-05-idn-rd-wr-ok.diff' This branch is now based on the sercos branch.
parent
23e227be
Changes
33
Hide whitespace changes
Inline
Side-by-side
common/include/controller_block.h
deleted
100644 → 0
View file @
23e227be
/*
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2007, 2009, 2013
Copyright Stichting C.A. Muller Radioastronomiestation, 2007, 2009, 2013
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _INCLUDE_CONTROLLER_BLOCK_H_
#define _INCLUDE_CONTROLLER_BLOCK_H_
#include
<stddef.h>
#include
<stdint.h>
#include
<stdbool.h>
#include
<math.h>
#include
<pthread.h>
#include
<semaphore.h>
#include
<stdarg.h>
enum
controller_block_term_type
{
CONTROLLER_BLOCK_TERM_VOID
,
/* Special case for checks... do NOT use! */
CONTROLLER_BLOCK_TERM_FLOAT
,
CONTROLLER_BLOCK_TERM_BOOL
,
CONTROLLER_BLOCK_TERM_UINT8
,
CONTROLLER_BLOCK_TERM_UINT16
,
CONTROLLER_BLOCK_TERM_UINT32
,
CONTROLLER_BLOCK_TERM_SINT8
,
CONTROLLER_BLOCK_TERM_SINT16
,
CONTROLLER_BLOCK_TERM_SINT32
,
};
/* Each off the inputs and outputs of the block is described with this struct.
For inputs: the value pointer pointer has to be filled in when building the
network.
For outputs: the value pointer is filled at block creation.
*/
struct
controller_block_outterm
{
char
*
name
;
enum
controller_block_term_type
type
;
union
{
void
*
v
;
float
*
f
;
bool
*
b
;
uint8_t
*
u8
;
uint16_t
*
u16
;
uint32_t
*
u32
;
int8_t
*
s8
;
int16_t
*
s16
;
int32_t
*
s32
;
}
value
;
struct
controller_block
*
source
;
/* terminal of source (if not this one) */
struct
controller_block_outterm
*
sourceterm
;
};
struct
controller_block_interm
{
char
*
name
;
enum
controller_block_term_type
type
;
union
{
void
**
v
;
float
**
f
;
bool
**
b
;
uint8_t
**
u8
;
uint16_t
**
u16
;
uint32_t
**
u32
;
int8_t
**
s8
;
int16_t
**
s16
;
int32_t
**
s32
;
}
value
;
struct
controller_block
*
otherside
;
struct
controller_block_interm
*
ghostof
;
/* link back to owning block */
struct
controller_block
*
block
;
};
/* List of interms which must be created in the block's input pointer.
This structure and its helper functions can only be used for normal
inputs which have no 'ghosts' and which are located in the private
structure.
name: name of the input terminal
type: type of the input terminal
priv_offset: offset within the private structure where the target
pointer is located.
*/
struct
controller_block_interm_list
{
char
*
name
;
enum
controller_block_term_type
type
;
size_t
priv_offset
;
};
/* List of outterms which must be created in the block's output pointer.
This structure and its helper functions can only be used for normal
outputs which have no 'ghosts' and which are located in the private
structure.
name: name of the output terminal
type: type of the output terminal
priv_offset: offset within the private structure where the source
pointer is located.
*/
struct
controller_block_outterm_list
{
char
*
name
;
enum
controller_block_term_type
type
;
size_t
priv_offset
;
};
/* Starting point for a block.
Additional data a block might need can be pointed to by the private pointer.
*/
struct
controller_block
{
char
*
name
;
/* instance name this block */
char
*
type
;
/* generic type of the block */
char
*
context
;
/* Which context 'owns' this block */
/* List of inputs */
int
inputs
;
struct
controller_block_interm
*
input
;
/* List of outputs */
int
outputs
;
struct
controller_block_outterm
*
output
;
/* List of params */
int
params
;
struct
controller_block_param_list
*
param
;
void
(
*
calculate
)(
struct
controller_block
*
);
void
(
*
param_get
)(
struct
controller_block
*
,
int
,
void
*
);
void
(
*
param_set
)(
struct
controller_block
*
,
int
,
va_list
);
/* Incomplete type for private data */
struct
controller_block_private
*
private
;
};
struct
controller_trace
{
void
*
ptr
;
enum
controller_block_term_type
type
;
float
*
buffer
;
size_t
len
;
size_t
wr_pos
;
size_t
rd_pos
;
};
struct
controller_block_link
{
char
*
outblock
;
char
*
outterm
;
char
*
inblock
;
char
*
interm
;
int
chain
;
char
*
type
;
};
/* 64bit continuous counter */
extern
uint64_t
controller_time_nseconds
;
extern
uint32_t
controller_time_seconds
;
extern
uint32_t
controller_time_samplenr
;
extern
uint32_t
controller_samplenr
;
int
controller_block_create
(
char
*
type
,
char
*
name
,
va_list
ap
);
void
controller_block_add
(
struct
controller_block
*
newblock
);
struct
controller_block
*
controller_block_find
(
char
*
name
);
int
controller_block_nr
(
void
);
struct
controller_block
*
controller_block_get
(
int
nr
);
struct
controller_block_outterm
*
controller_block_find_outterm
(
struct
controller_block
*
block
,
char
*
output
);
int
controller_block_add_float_input
(
struct
controller_block
*
blk
,
char
*
name
,
float
**
ptr
);
int
controller_block_add_bool_input
(
struct
controller_block
*
blk
,
char
*
name
,
bool
**
ptr
);
int
controller_block_add_sint16_input
(
struct
controller_block
*
blk
,
char
*
name
,
int16_t
**
ptr
);
int
controller_block_add_sint32_input
(
struct
controller_block
*
blk
,
char
*
name
,
int32_t
**
ptr
);
int
controller_block_add_float_output
(
struct
controller_block
*
blk
,
char
*
name
,
float
*
ptr
);
int
controller_block_add_bool_output
(
struct
controller_block
*
blk
,
char
*
name
,
bool
*
ptr
);
int
controller_block_add_uint16_output
(
struct
controller_block
*
blk
,
char
*
name
,
uint16_t
*
ptr
);
int
controller_block_add_sint32_output
(
struct
controller_block
*
blk
,
char
*
name
,
int32_t
*
ptr
);
int
controller_block_add_sint16_output
(
struct
controller_block
*
blk
,
char
*
name
,
int16_t
*
ptr
);
int
controller_block_interm_list_init
(
struct
controller_block
*
block
,
struct
controller_block_interm_list
*
list
);
int
controller_block_outterm_list_init
(
struct
controller_block
*
block
,
struct
controller_block_outterm_list
*
list
);
int
controller_block_output_get_float
(
char
*
block
,
char
*
param
,
float
*
value
);
int
controller_block_connect
(
char
*
outblock
,
char
*
outterm
,
char
*
inblock
,
char
*
interm
,
int
chain
);
int
controller_block_link
(
void
);
struct
controller_block_link
*
controller_block_link_get
(
int
nr
);
int
controller_block_link_nr
(
void
);
int
controller_block_sample_init
(
void
);
void
controller_block_calculate
(
void
);
char
*
controller_block_context_get
(
void
);
void
controller_block_context_set
(
char
*
new_context
);
/* Helper function to create a new block */
struct
controller_block
*
controller_block_alloc
(
char
*
type
,
char
*
name
,
size_t
private_size
);
void
controller_block_free
(
struct
controller_block
*
blk
);
#define RPM2RADS(val) ((val)*2.0*M_PI/60.0)
#define RADS2RPM(val) ((val)*60.0/(2.0*M_PI))
#define DEG2RAD(val) ((val)*2.0*M_PI/360.0)
#define RAD2DEG(val) ((val)*360.0/(2.0*M_PI))
/*
controller_block_param
*/
/* List of params which must be initialized in the block's param pointer */
struct
controller_block_param_list
{
char
*
name
;
bool
sample
;
/* True: all access to params must be 'sample safe' */
};
void
controller_block_param_init
(
void
);
int
controller_block_param_list_init
(
struct
controller_block
*
block
,
struct
controller_block_param_list
*
list
);
int
controller_block_param_set
(
char
*
block
,
char
*
param
,
va_list
);
int
controller_block_param_get
(
char
*
block
,
char
*
param
,
void
*
value
);
void
controller_block_param_handle
(
void
);
/*
controller_block_trace
*/
void
controller_block_trace_init
(
int
max
);
int
controller_block_trace_add
(
char
*
block
,
char
*
outterm
,
struct
controller_trace
*
trace
);
void
controller_block_trace_del
(
struct
controller_trace
*
trace
);
void
controller_block_trace_wait
(
void
);
void
controller_block_trace
(
void
);
#endif
common/include/controller_block.h
0 → 120000
View file @
bab5bbe6
..
/
..
/
controller
/
controller
/
controller_block
.
h
\ No newline at end of file
controller/Makefile
View file @
bab5bbe6
...
...
@@ -17,17 +17,16 @@ endif
dt_ctrl_LDFLAGS
=
`
./controller/block_list.sh lib/
*
.a
`
\
-lcontroller
-lethercat
-llog
-lshell
-ldt_azimuth
-ldt_elevation
-lcontroller
-lethercat
-lsercos
-llog
-lshell
\
-ldt_azimuth
-ldt_elevation
all
:
dt_ctrl
\
test
\
controller
dt_ctrl
:
lib/libcontroller.la lib/libethercat.la lib/libdt_azimuth.la lib/libdt_elevation.la
dt_ctrl
:
lib/libcontroller.la lib/libethercat.la lib/libsercos.la
\
lib/libdt_azimuth.la lib/libdt_elevation.la
lib/libethercat.la
:
lib/libcontroller.la
lib/libdt_azimuth.la
:
lib/libcontroller.la
lib/libdt_elevation.la
:
lib/libcontroller.la
dt_ctrl
:
dt_ctrl.o
...
...
@@ -42,20 +41,31 @@ lib/libcontroller.la:
@
echo
" SUBDIR:
$@
"
@
$(MAKE)
-C
controller
lib/libdt_azimuth.la
:
lib/libcontroller.la
lib/libdt_azimuth.la
:
lib
@
echo
" SUBDIR:
$@
"
@
$(MAKE)
-C
dt_azimuth
lib/libdt_elevation.la
:
lib/libcontroller.la
lib/libdt_elevation.la
:
lib
@
echo
" SUBDIR:
$@
"
@
$(MAKE)
-C
dt_elevation
lib/libethercat.la
:
lib/liblog.la lib/libshell.la lib
lib/libethercat.la
:
lib/liblog.la lib/libshell.la lib/libcontroller.la
lib/libethercat.la
:
lib/libsercos.la
lib/libethercat.la
:
lib/libethercat.la
:
lib
@
echo
" SUBDIR:
$@
"
@
$(MAKE)
-C
ec
lib/libsercos.la
:
lib/libcontroller.la
lib/libsercos.la
:
@
echo
" SUBDIR:
$@
"
@
$(MAKE)
-C
sercos
lib/libshell.la
:
lib/liblog.la lib
@
echo
" SUBDIR:
$@
"
@
$(MAKE)
-C
shell
...
...
@@ -78,6 +88,7 @@ clean:
$(MAKE)
-C
dt_azimuth clean
$(MAKE)
-C
dt_elevation clean
$(MAKE)
-C
ec clean
$(MAKE)
-C
sercos clean
$(MAKE)
-C
test
clean
$(MAKE)
-C
shell clean
$(MAKE)
-C
log clean
controller/controller/Makefile
View file @
bab5bbe6
...
...
@@ -58,6 +58,7 @@ CONTROLLERSRCS= \
controller_sample.c
\
controller_dumpdot.c
\
controller_load.c
\
controller_load_variable.c
\
controller_load_parser.tab.c
\
controller_load_parser.yy.c
...
...
controller/controller/controller_block.c
View file @
bab5bbe6
...
...
@@ -23,7 +23,6 @@
#include
<math.h>
#include
<pthread.h>
#include
<dlfcn.h>
#include
<errno.h>
#include
"controller_block.h"
#include
"controller_sample.h"
...
...
@@ -57,7 +56,7 @@ int controller_block_create(char *type, char *name, va_list ap)
handle
=
dlopen
(
NULL
,
RTLD_NOW
);
if
(
!
handle
)
{
log_send
(
LOG_T_ERROR
,
"
Error getting
handle from dlopen(): %s"
,
dlerror
());
"
Could not get
handle from dlopen(): %s"
,
dlerror
());
return
-
1
;
}
...
...
@@ -68,12 +67,12 @@ int controller_block_create(char *type, char *name, va_list ap)
if
(
create_func
)
{
if
(
!
create_func
(
name
,
ap
))
{
log_send
(
LOG_T_ERROR
,
"
Error:
%s() failed"
,
symbol
);
log_send
(
LOG_T_ERROR
,
"%s() failed"
,
symbol
);
ret
=
-
1
;
}
}
else
{
log_send
(
LOG_T_ERROR
,
"
Error
find
ing
function %s for block %s"
,
symbol
,
type
);
"
Could not
find function %s for block %s"
,
symbol
,
type
);
ret
=
-
1
;
}
...
...
@@ -214,7 +213,7 @@ int controller_block_sample_init(void)
for
(
j
=
0
;
j
<
blocks
[
i
]
->
inputs
;
j
++
)
{
if
(
*
blocks
[
i
]
->
input
[
j
].
value
.
v
==
NULL
)
{
log_send
(
LOG_T_ERROR
,
"%s.%s is not connected!"
,
"
input
%s.%s is not connected!"
,
blocks
[
i
]
->
name
,
blocks
[
i
]
->
input
[
j
].
name
);
check
=
false
;
...
...
@@ -573,201 +572,3 @@ void controller_block_free(struct controller_block *blk)
free
(
blk
);
}
struct
controller_block_interm
*
controller_block_add_input
(
struct
controller_block
*
blk
,
char
*
name
,
enum
controller_block_term_type
type
)
{
int
inputs
;
int
idx
;
struct
controller_block_interm
*
input
;
inputs
=
blk
->
inputs
+
1
;
if
(
inputs
==
1
)
{
input
=
malloc
(
sizeof
(
struct
controller_block_interm
));
}
else
{
input
=
realloc
(
blk
->
input
,
inputs
*
sizeof
(
struct
controller_block_interm
));
}
if
(
input
==
NULL
)
return
NULL
;
blk
->
inputs
=
inputs
;
blk
->
input
=
input
;
idx
=
inputs
-
1
;
input
[
idx
].
name
=
name
;
input
[
idx
].
type
=
type
;
input
[
idx
].
ghostof
=
NULL
;
return
&
input
[
idx
];
}
int
controller_block_add_float_input
(
struct
controller_block
*
blk
,
char
*
name
,
float
**
ptr
)
{
struct
controller_block_interm
*
input
;
input
=
controller_block_add_input
(
blk
,
name
,
CONTROLLER_BLOCK_TERM_FLOAT
);
if
(
input
==
NULL
)
return
ENOMEM
;
input
->
value
.
f
=
ptr
;
return
0
;
}
int
controller_block_add_bool_input
(
struct
controller_block
*
blk
,
char
*
name
,
bool
**
ptr
)
{
struct
controller_block_interm
*
input
;
input
=
controller_block_add_input
(
blk
,
name
,
CONTROLLER_BLOCK_TERM_BOOL
);
if
(
input
==
NULL
)
return
ENOMEM
;
input
->
value
.
b
=
ptr
;
return
0
;
}
int
controller_block_add_sint16_input
(
struct
controller_block
*
blk
,
char
*
name
,
int16_t
**
ptr
)
{
struct
controller_block_interm
*
input
;
input
=
controller_block_add_input
(
blk
,
name
,
CONTROLLER_BLOCK_TERM_SINT16
);
if
(
input
==
NULL
)
return
ENOMEM
;
input
->
value
.
v
=
(
void
**
)
ptr
;
return
0
;
}
int
controller_block_add_sint32_input
(
struct
controller_block
*
blk
,
char
*
name
,
int32_t
**
ptr
)
{
struct
controller_block_interm
*
input
;
input
=
controller_block_add_input
(
blk
,
name
,
CONTROLLER_BLOCK_TERM_SINT32
);
if
(
input
==
NULL
)
return
ENOMEM
;
input
->
value
.
v
=
(
void
**
)
ptr
;
return
0
;
}
struct
controller_block_outterm
*
controller_block_add_output
(
struct
controller_block
*
blk
,
char
*
name
,
enum
controller_block_term_type
type
)
{
int
outputs
;
int
idx
;
struct
controller_block_outterm
*
output
;
outputs
=
blk
->
outputs
+
1
;
if
(
outputs
==
1
)
{
output
=
malloc
(
sizeof
(
struct
controller_block_outterm
));
}
else
{
output
=
realloc
(
blk
->
output
,
outputs
*
sizeof
(
struct
controller_block_outterm
));
}
if
(
output
==
NULL
)
return
NULL
;
blk
->
outputs
=
outputs
;
blk
->
output
=
output
;
idx
=
outputs
-
1
;
output
[
idx
].
name
=
name
;
output
[
idx
].
type
=
type
;
output
[
idx
].
source
=
blk
;
return
&
output
[
idx
];
}
int
controller_block_add_float_output
(
struct
controller_block
*
blk
,
char
*
name
,
float
*
ptr
)
{
struct
controller_block_outterm
*
output
;
output
=
controller_block_add_output
(
blk
,
name
,
CONTROLLER_BLOCK_TERM_FLOAT
);
if
(
output
==
NULL
)
return
ENOMEM
;
output
->
value
.
f
=
ptr
;
return
0
;
}
int
controller_block_add_bool_output
(
struct
controller_block
*
blk
,
char
*
name
,
bool
*
ptr
)
{
struct
controller_block_outterm
*
output
;
output
=
controller_block_add_output
(
blk
,
name
,
CONTROLLER_BLOCK_TERM_BOOL
);
if
(
output
==
NULL
)
return
ENOMEM
;
output
->
value
.
b
=
ptr
;
return
0
;
}
int
controller_block_add_uint16_output
(
struct
controller_block
*
blk
,
char
*
name
,
uint16_t
*
ptr
)
{
struct
controller_block_outterm
*
output
;
output
=
controller_block_add_output
(
blk
,
name
,
CONTROLLER_BLOCK_TERM_UINT16
);
if
(
output
==
NULL
)
return
ENOMEM
;
output
->
value
.
v
=
ptr
;
return
0
;
}
int
controller_block_add_sint32_output
(
struct
controller_block
*
blk
,
char
*
name
,
int32_t
*
ptr
)
{
struct
controller_block_outterm
*
output
;
output
=
controller_block_add_output
(
blk
,
name
,
CONTROLLER_BLOCK_TERM_SINT32
);
if
(
output
==
NULL
)
return
ENOMEM
;
output
->
value
.
v
=
ptr
;
return
0
;
}
int
controller_block_add_sint16_output
(
struct
controller_block
*
blk
,
char
*
name
,
int16_t
*
ptr
)
{
struct
controller_block_outterm
*
output
;
output
=
controller_block_add_output
(
blk
,
name
,
CONTROLLER_BLOCK_TERM_SINT16
);
if
(
output
==
NULL
)
return
ENOMEM
;
output
->
value
.
v
=
ptr
;
return
0
;
}
controller/controller/controller_block.h
View file @
bab5bbe6
...
...
@@ -180,26 +180,6 @@ struct controller_block *controller_block_get(int nr);
struct
controller_block_outterm
*
controller_block_find_outterm
(
struct
controller_block
*
block
,
char
*
output
);
int
controller_block_add_float_input
(
struct
controller_block
*
blk
,
char
*
name
,
float
**
ptr
);
int
controller_block_add_bool_input
(
struct
controller_block
*
blk
,
char
*
name
,
bool
**
ptr
);
int
controller_block_add_sint16_input
(
struct
controller_block
*
blk
,
char
*
name
,
int16_t
**
ptr
);
int
controller_block_add_sint32_input
(
struct
controller_block
*
blk
,
char
*
name
,
int32_t
**
ptr
);
int
controller_block_add_float_output
(
struct
controller_block
*
blk
,
char
*
name
,
float
*
ptr
);
int
controller_block_add_bool_output
(
struct
controller_block
*
blk
,
char
*
name
,
bool
*
ptr
);
int
controller_block_add_uint16_output
(
struct
controller_block
*
blk
,
char
*
name
,
uint16_t
*
ptr
);
int
controller_block_add_sint32_output
(
struct
controller_block
*
blk
,
char
*
name
,
int32_t
*
ptr
);
int
controller_block_add_sint16_output
(
struct
controller_block
*
blk
,
char
*
name
,
int16_t
*
ptr
);
int
controller_block_interm_list_init
(
struct
controller_block
*
block
,
struct
controller_block_interm_list
*
list
);
int
controller_block_outterm_list_init
(
struct
controller_block
*
block
,
...
...
controller/controller/controller_load.c
View file @
bab5bbe6
...
...
@@ -215,13 +215,15 @@ int controller_load_block_param_set(char *block, char *param, yyscan_t scanner)
return
controller_block_param_set
(
block
,
param
,
extra
->
va_list
);
}