summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--acse.erl10
-rw-r--r--rose.erl21
-rw-r--r--tda.erl26
3 files changed, 28 insertions, 29 deletions
diff --git a/acse.erl b/acse.erl
index 110f530..e8f0d70 100644
--- a/acse.erl
+++ b/acse.erl
@@ -4,7 +4,7 @@
-include("CSTA-application-context-information-csta3.hrl").
-export([associate/0, release/0]).
--export([decode/1, check/1]).
+-export([decode/1, dispatch/1]).
ui() ->
{ok, UI} = 'CSTA-application-context-information-csta3':encode(
@@ -24,10 +24,12 @@ release() -> 'ACSE-1':encode('ACSE-apdu', {rlrq, #'RLRQ-apdu'{}}).
decode(Msg) -> 'ACSE-1':decode('ACSE-apdu', Msg).
-check({aare, #'AARE-apdu'{result = Result}}) ->
+dispatch({aare, #'AARE-apdu'{result = Result}}) ->
case Result of
accepted -> ok;
_ -> error
end;
-check({rlre, _}) -> ok;
-check({abrt, _}) -> error.
+
+dispatch({rlre, _}) -> ok;
+
+dispatch({abrt, _}) -> error.
diff --git a/rose.erl b/rose.erl
index 7bd5764..9ac3895 100644
--- a/rose.erl
+++ b/rose.erl
@@ -4,18 +4,25 @@
-include("Remote-Operations-Generic-ROS-PDUs.hrl").
-decode(Msg) -> 'Remote-Operations-Generic-ROS-PDUs':decode('ROS', Msg).
+decode(Data) -> 'Remote-Operations-Generic-ROS-PDUs':decode('ROS', Data).
-return(Id, Op, {ok, Msg}) -> 'Remote-Operations-Generic-ROS-PDUs':encode('ROS',
+return(Id, Op, {ok, Data}) -> 'Remote-Operations-Generic-ROS-PDUs':encode('ROS',
{returnResult, #'ReturnResult'{invokeId = Id,
- result = #'ReturnResult_result'{opcode = Op, result = Msg}}}).
+ result = #'ReturnResult_result'{opcode = Op, result = Data}}}).
-invoke(Id, Op, {ok, Msg}) -> 'Remote-Operations-Generic-ROS-PDUs':encode('ROS',
- {invoke, #'Invoke'{invokeId = Id, opcode = Op, argument = Msg}}).
+invoke(Id, Op, {ok, Data}) -> 'Remote-Operations-Generic-ROS-PDUs':encode('ROS',
+ {invoke, #'Invoke'{invokeId = Id, opcode = Op, argument = Data}}).
dispatch({invoke, #'Invoke'{invokeId = Id, opcode = Op}}) ->
case Op of
{local, 211} -> return(Id, Op, status:status());
- {local, 51} -> ok
+ {local, 51} -> ok;
+ _ -> error
end;
-dispatch({returnResult, result = #'ReturnResult'{result = #'ReturnResult_result'{result = Msg}}}) -> {result, Msg}.
+
+dispatch({returnResult, #'ReturnResult'{result = Data}}) ->
+ dispatch(Data);
+
+dispatch(#'ReturnResult_result'{result = Data}) ->
+ io:format("Result: ~p~n", [Data]),
+ ok.
diff --git a/tda.erl b/tda.erl
index 8096f92..3008b5e 100644
--- a/tda.erl
+++ b/tda.erl
@@ -39,22 +39,20 @@ loop(Sock) ->
inet:setopts(Sock, [{active, once}]),
receive
{ok, Reply} ->
- io:format("Send ~p~n", [Reply]),
+ %io:format("Send ~p~n", [Reply]),
gen_tcp:send(Sock, Reply);
{tcp, Sock, Data} ->
- io:format("Got ~p~n", [Data]),
+ %io:format("Got ~p~n", [Data]),
case decode(Data) of
- ok ->
- ok;
- {ok, Reply} ->
- tdaPid ! {ok, Reply};
- error ->
- exit(error)
+ {ok, Reply} -> tdaPid ! {ok, Reply};
+ ok -> ok;
+ error -> exit(error)
end;
{tcp_closed, _} ->
io:format("Connection closed~n", []),
exit(closed)
after ?TIMEOUT ->
+ io:format("Connection timed out~n", []),
exit(timeout)
end,
loop(Sock).
@@ -64,19 +62,11 @@ decode(Data) ->
rose ->
{ok, Rose} = rose:decode(Data),
io:format("ROSE> ~p~n", [Rose]),
- case rose:dispatch(Rose) of
- {ok, Result} ->
- {ok, Result};
- {result, Data} ->
- io:format("Result: ~p~n", [Data]),
- ok;
- {ok} ->
- ok
- end;
+ rose:dispatch(Rose);
acse ->
{ok, Acse} = acse:decode(Data),
io:format("ACSE> ~p~n", [Acse]),
- acse:check(Acse)
+ acse:dispatch(Acse)
end.
dispatch(<<Head:8,_/binary>>) ->