summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rose.erl18
-rw-r--r--tda.erl24
2 files changed, 21 insertions, 21 deletions
diff --git a/rose.erl b/rose.erl
new file mode 100644
index 0000000..14af5d9
--- /dev/null
+++ b/rose.erl
@@ -0,0 +1,18 @@
+-module(rose).
+
+-export([decode/1, encode/3, dispatch/1]).
+
+-include("Remote-Operations-Generic-ROS-PDUs.hrl").
+
+decode(Msg) -> 'Remote-Operations-Generic-ROS-PDUs':decode('ROS', Msg).
+
+encode(Id, Op, Msg) -> 'Remote-Operations-Generic-ROS-PDUs':encode('ROS',
+ {returnResult, #'ReturnResult'{invokeId = Id,
+ result = #'ReturnResult_result'{opcode = Op, result = Msg}}}).
+
+dispatch(#'Invoke'{invokeId = Id, opcode = Op}) ->
+ case Op of
+ {local, 211} ->
+ {ok, Status} = rose:encode(Id, Op, <<5,0>>),
+ Status
+ end.
diff --git a/tda.erl b/tda.erl
index 0f47516..b2e7042 100644
--- a/tda.erl
+++ b/tda.erl
@@ -1,9 +1,6 @@
-module(tda).
-export([start/0, client/1, stop/0]).
--export([rose/1]).
-
--include("Remote-Operations-Generic-ROS-PDUs.hrl").
-define(TIMEOUT, 300000).
-define(CONNECT_TIMEOUT, 3000).
@@ -57,12 +54,10 @@ loop(Sock) ->
timeout
end.
-rose(Msg) -> 'Remote-Operations-Generic-ROS-PDUs':decode('ROS', Msg).
-
decode(Sock, Msg) ->
case dispatch(Msg) of
rose ->
- {ok, Rose} = rose(Msg),
+ {ok, Rose} = rose:decode(Msg),
io:format("ROSE> ~p~n", [Rose]),
rose_handler(Sock, Rose);
acse ->
@@ -71,15 +66,10 @@ decode(Sock, Msg) ->
acse:accepted(Acse)
end.
-rose_handler(Sock, {invoke, Rose}) ->
- gen_tcp:send(Sock, invoke_handler(Rose)),
+rose_handler(Sock, {invoke, Msg}) ->
+ gen_tcp:send(Sock, rose:dispatch(Msg)),
ok.
-invoke_handler(#'Invoke'{invokeId = Id, opcode = Op}) ->
- case Op of
- {_, 211} -> system_status(Id, Op)
- end.
-
dispatch(<<Head:8,_/binary>>) ->
case Head of
96 -> acse;
@@ -90,11 +80,3 @@ dispatch(<<Head:8,_/binary>>) ->
161 -> rose;
162 -> rose
end.
-
-system_status(Id, Op) ->
- RR = #'ReturnResult_result'{opcode = Op, result = <<5,0>>},
- R = #'ReturnResult'{invokeId = Id, result = RR},
- case 'Remote-Operations-Generic-ROS-PDUs':encode('ROS', {returnResult, R}) of
- {ok, Invoke} -> Invoke;
- {error, Reason} -> Reason
- end.