summaryrefslogtreecommitdiff
path: root/src/rose.erl
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-10-29 14:00:41 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-10-29 14:00:41 +0100
commitfc86381ccac10fa30aefe76996a716ae1d677f5b (patch)
treec7a0c6c2ab9ab0c254bdb01088c2aad3119ff277 /src/rose.erl
parentb9697094228db7832e75a8699a2678338f7c7c22 (diff)
Prepare for rebar
Diffstat (limited to 'src/rose.erl')
-rw-r--r--src/rose.erl64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/rose.erl b/src/rose.erl
new file mode 100644
index 0000000..c720dd8
--- /dev/null
+++ b/src/rose.erl
@@ -0,0 +1,64 @@
+-module(rose).
+
+-export([decode/1, invoke/2, dispatch/1]).
+
+-include("Remote-Operations-Generic-ROS-PDUs.hrl").
+
+decode(Data) ->
+ 'Remote-Operations-Generic-ROS-PDUs':decode('ROS', Data).
+
+return(Id, Op, {ok, Data}) ->
+ 'Remote-Operations-Generic-ROS-PDUs':encode('ROS', {returnResult,
+ #'ReturnResult'{invokeId = Id,
+ result = #'ReturnResult_result'{opcode = Op, result = Data}}}).
+
+invoke(Op, {ok, Data}) ->
+ Id = counter:next(),
+ 'Remote-Operations-Generic-ROS-PDUs':encode('ROS', {invoke,
+ #'Invoke'{invokeId = Id, opcode = Op, argument = Data}}).
+
+dispatch({invoke, #'Invoke'{invokeId = Id, opcode = Op, argument = Data}}) ->
+ counter:set(Id),
+ case Op of
+ {local, 21} ->
+ ok;
+ {local, 51} ->
+ {ok, Esc} = csta:decode(Data),
+ io:format("Esc ~p~n", [Esc]),
+ ok;
+ {local, 71} ->
+ ok;
+ {local, 74} ->
+ ok;
+ {local, 211} ->
+ {ok, Status} = csta:decodeStatus(Data),
+ io:format("Status: ~p~n", [Status]),
+ return(Id, Op, csta:statusOk());
+ _ ->
+ error
+ end;
+
+dispatch({returnResult, #'ReturnResult'{invokeId = Id, result = Data}}) ->
+ counter:set(Id),
+ dispatch(Data);
+
+dispatch({returnError, #'ReturnError'{invokeId = Id, errcode = Code, parameter = Par}}) ->
+ counter:set(Id),
+ io:format("Err: ~p ~p~n", [Code, Par]),
+ error;
+
+dispatch({reject, #'Reject'{invokeId = Id, problem = Problem}}) ->
+ counter:set(Id),
+ io:format("Problem: ~p~n", [Problem]),
+ error;
+
+dispatch(#'ReturnResult_result'{opcode = Op, result = Data}) ->
+ case Op of
+ {local, 74} ->
+ {ok, Status} = 'CSTA-snapshot-device':decode(
+ 'SnapshotDeviceResult', Data),
+ io:format("Result: ~p~n", [Status]);
+ _ ->
+ io:format("Result: ~p~n", [Data])
+ end,
+ ok.