Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tammo Jan Dijkema
dt_ctrl
Commits
f3e2571a
Commit
f3e2571a
authored
Aug 17, 2015
by
Jeroen Vreeken
Browse files
Add command_joystick command generator.
Can be used to quickly send float setpoints for testing.
parent
f0084dc0
Changes
5
Hide whitespace changes
Inline
Side-by-side
common/command/build.mk
View file @
f3e2571a
COMMAND_TARGETS
+=
$(LIBDIR)
/libcommand.la
COMMAND_TARGETS
+=
$(DIR)
/command_list
$(DIR)
/command_send
COMMAND_TARGETS
+=
$(DIR)
/command_list
$(DIR)
/command_send
$(DIR)
/command_joystick
ARCHSRCS
:=
$(DIR)
/command.c
$(DIR)
/command_tcp.c
...
...
@@ -28,9 +28,17 @@ $(DIR)/command_send: libcommand.la
$(DIR)/
command_send_LDFLAGS
+=
-lcommand
$(DIR)/command_send
:
$(COMMAND_SEND_OBJS)
SRCS
+=
$(ARCHSRCS)
$(COMMAND_LIST_SRCS)
$(COMMAND_SEND_SRCS)
COMMAND_JOYSTICK_SRCS
:=
$(DIR)
/command_joystick.c
COMMAND_JOYSTICK_OBJS
:=
$(COMMAND_JOYSTICK_SRCS:.c=.o)
$(DIR)/command_joystick
:
libcommand.la
$(DIR)/
command_joystick_LDFLAGS
+=
-lcommand
$(DIR)/command_joystick
:
$(COMMAND_JOYSTICK_OBJS)
SRCS
+=
$(ARCHSRCS)
$(COMMAND_LIST_SRCS)
$(COMMAND_SEND_SRCS)
$(COMMAND_JOYSTICK_SRCS)
TARGETS
+=
$(COMMAND_TARGETS)
CLEAN
+=
$(COMMAND_TARGETS)
$(ARCHOBJS)
\
$(COMMAND_LIST_OBJS)
\
$(COMMAND_SEND_OBJS)
\
$(COMMAND_JOYSTICK_OBJS)
\
$(LIBDIR)
/libcommand.a
common/command/command_joystick
0 → 100755
View file @
f3e2571a
File added
common/command/command_joystick.c
0 → 100644
View file @
f3e2571a
/*
Copyright Jeroen Vreeken (jeroen@vreeken.net), 2015
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/>.
*/
#include
<stdio.h>
#include
<fcntl.h>
#include
<linux/joystick.h>
#include
<command/command.h>
#include
<dt_port_numbers.h>
#include
<stdbool.h>
static
bool
found_name
=
false
;
static
bool
found_float
=
false
;
static
bool
found_setpoint
=
false
;
static
char
*
arg_name
;
static
void
handler_list_entry
(
struct
command
*
command
,
char
*
name
,
enum
command_value_type
type
,
char
*
unit
,
int
typec
,
enum
command_ptype
typev
[])
{
int
i
;
if
(
strcmp
(
name
,
arg_name
))
return
;
found_name
=
true
;
found_float
=
(
type
==
COMMAND_VALUE_TYPE_FLOAT
);
for
(
i
=
0
;
i
<
typec
;
i
++
)
{
if
(
typev
[
i
]
==
COMMAND_PTYPE_SETPOINT
)
found_setpoint
=
true
;
}
}
int
main
(
int
argc
,
char
**
argv
)
{
struct
command
*
command
;
char
*
id
=
"command_joystick"
;
char
*
host
;
short
port
=
21000
;
char
*
js_dev
;
int
fd_joy
=
-
1
;
if
(
argc
<
5
)
{
printf
(
"Usage: %s <host> <port> <name> <joystick dev>
\n
"
,
argv
[
0
]);
printf
(
"Example: %s localhost %d spgname /dev/input/js0"
,
argv
[
0
],
port
);
return
1
;
}
host
=
argv
[
1
];
port
=
atoi
(
argv
[
2
]);
arg_name
=
argv
[
3
];
js_dev
=
argv
[
4
];
fd_joy
=
open
(
js_dev
,
O_RDONLY
);
if
(
fd_joy
<
0
)
{
perror
(
"Could not open joystick device"
);
return
1
;
}
ioctl
(
fd_joy
,
FIONBIO
,
&
(
int
){
1
});
command
=
command_open
(
host
,
port
);
command
->
handler_list_entry
=
handler_list_entry
;
while
(
command_state_get
(
command
)
!=
COMMAND_STATE_READY
&&
command_state_get
(
command
)
!=
COMMAND_STATE_DISCONNECTED
)
{
fd_set
fdrx
;
int
high
=
0
;
FD_ZERO
(
&
fdrx
);
command_fd_set
(
command
,
&
fdrx
,
&
high
);
select
(
high
+
1
,
&
fdrx
,
NULL
,
NULL
,
NULL
);
command_handle
(
command
,
&
fdrx
);
}
if
(
command_state_get
(
command
)
==
COMMAND_STATE_DISCONNECTED
)
{
printf
(
"Not connected.
\n
"
);
return
1
;
}
if
(
!
found_name
)
{
printf
(
"Could not find spg '%s'
\n
"
,
arg_name
);
return
1
;
}
if
(
!
found_float
)
{
printf
(
"Only float type is supported
\n
"
);
return
1
;
}
if
(
!
found_setpoint
)
{
printf
(
"Setpoint command is not supported
\n
"
);
return
1
;
}
command
->
type
=
COMMAND_VALUE_TYPE_FLOAT
;
command_id_set
(
command
,
id
);
command_name_set
(
command
,
arg_name
);
do
{
fd_set
fdrx
;
int
high
;
FD_ZERO
(
&
fdrx
);
FD_SET
(
fd_joy
,
&
fdrx
);
high
=
fd_joy
;
command_fd_set
(
command
,
&
fdrx
,
&
high
);
select
(
high
+
1
,
&
fdrx
,
NULL
,
NULL
,
NULL
);
command_handle
(
command
,
&
fdrx
);
if
(
FD_ISSET
(
fd_joy
,
&
fdrx
))
{
struct
js_event
event
;
ssize_t
ret
=
read
(
fd_joy
,
&
event
,
sizeof
(
event
));
if
(
ret
==
sizeof
(
event
))
{
if
(
event
.
type
&
JS_EVENT_AXIS
&&
event
.
number
==
0
)
{
struct
command_entry
entry
;
entry
.
type
=
COMMAND_PTYPE_SETPOINT
;
entry
.
value
.
f
=
(
float
)
event
.
value
/
32768
.
0
;
command_send
(
command
,
&
entry
);
}
}
}
}
while
(
1
);
return
0
;
}
controller/ec/block_stoeber.c
View file @
f3e2571a
...
...
@@ -619,13 +619,13 @@ static struct controller_block *block_stoeber_create(char *name, int argc, va_li
if
(
!
stoeber
)
goto
err_malloc
;
sprintf
(
trx_name
,
"%s
_
tx"
,
name
);
sprintf
(
trx_name
,
"%s
/
tx"
,
name
);
stoeber_tx
=
controller_block_alloc
(
"stoeber_tx"
,
name
,
0
);
goto
err_malloc_tx
;
stoeber_tx
->
private
=
stoeber
->
private
;
sprintf
(
trx_name
,
"%s
_
rx"
,
name
);
sprintf
(
trx_name
,
"%s
/
rx"
,
name
);
stoeber_rx
=
controller_block_alloc
(
"stoeber_rx"
,
name
,
0
);
if
(
!
stoeber_rx
)
goto
err_malloc_rx
;
...
...
controller/vesp/block_vesp_controller.c
View file @
f3e2571a
...
...
@@ -192,13 +192,13 @@ static struct controller_block * block_vesp_controller_create(char *name,
if
(
!
(
controller
=
controller_block_alloc
(
"vesp_controller"
,
name
,
sizeof
(
struct
controller_block_private
))))
return
NULL
;
asprintf
(
&
name_tmp
,
"%s
_
rx"
,
name
);
asprintf
(
&
name_tmp
,
"%s
/
rx"
,
name
);
if
(
!
(
controller_rx
=
controller_block_alloc
(
"vesp_controller_rx"
,
name_tmp
,
0
)))
goto
err_controller
;
free
(
name_tmp
);
controller_rx
->
private
=
controller
->
private
;
asprintf
(
&
name_tmp
,
"%s
_
tx"
,
name
);
asprintf
(
&
name_tmp
,
"%s
/
tx"
,
name
);
if
(
!
(
controller_tx
=
controller_block_alloc
(
"vesp_controller_tx"
,
name_tmp
,
0
)))
goto
err_controller
;
free
(
name_tmp
);
...
...
@@ -251,7 +251,7 @@ static struct controller_block * block_vesp_controller_create(char *name,
goto
err_dev
;
}
if
(
vesp_bus_add_input
(
controller
,
controller
->
private
->
bus
,
if
(
vesp_bus_add_input
(
controller
_rx
,
controller
->
private
->
bus
,
address
,
VESP_RESP_OOB
,
sizeof
(
struct
rx_packet
),
rx_callback
))
goto
err_bus_input
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment