From fc86381ccac10fa30aefe76996a716ae1d677f5b Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Thu, 29 Oct 2015 14:00:41 +0100 Subject: Prepare for rebar --- src/rose.erl | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/rose.erl (limited to 'src/rose.erl') 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. -- cgit v1.2.3