summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-10-29 12:26:38 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-10-29 12:26:38 +0100
commitc5b5e7d8d81c210787a378c7c2d7e30db0305c0b (patch)
treebd39be250080b5ef9eccdfe1e9cce26abf437731
parente944d2b3d236c5aeba04455773e5cd8e5f1507c0 (diff)
Autocount invoke
-rw-r--r--counter.erl5
-rw-r--r--rose.erl14
-rw-r--r--tda.erl11
3 files changed, 18 insertions, 12 deletions
diff --git a/counter.erl b/counter.erl
index 915f5a9..6ecd335 100644
--- a/counter.erl
+++ b/counter.erl
@@ -7,6 +7,7 @@ start() ->
count(N) when N > 32767 ->
count(0);
+
count(N) ->
receive
{next, FromPID} ->
@@ -18,13 +19,13 @@ count(N) ->
exit(normal)
end.
-set(N) ->
+set({present, N}) ->
counterPid ! {set, N}.
next() ->
counterPid ! {next, self()},
receive
- {next, N} -> N
+ {next, N} -> {present, N}
end.
stop() ->
diff --git a/rose.erl b/rose.erl
index 650061c..65aa139 100644
--- a/rose.erl
+++ b/rose.erl
@@ -1,6 +1,6 @@
-module(rose).
--export([decode/1, return/3, invoke/3, dispatch/1]).
+-export([decode/1, invoke/2, dispatch/1]).
-include("Remote-Operations-Generic-ROS-PDUs.hrl").
@@ -8,15 +8,17 @@ 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,
+ 'Remote-Operations-Generic-ROS-PDUs':encode('ROS', {returnResult,
+ #'ReturnResult'{invokeId = Id,
result = #'ReturnResult_result'{opcode = Op, result = Data}}}).
-invoke(Id, Op, {ok, Data}) ->
- 'Remote-Operations-Generic-ROS-PDUs':encode('ROS',
- {invoke, #'Invoke'{invokeId = Id, opcode = Op, argument = 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;
diff --git a/tda.erl b/tda.erl
index 863feea..09f0752 100644
--- a/tda.erl
+++ b/tda.erl
@@ -8,19 +8,22 @@
-define(HOST, "192.168.240.20").
-define(PORT, 33333).
-start() -> register(tdaPid, spawn(?MODULE, client, [{dial, ?HOST, ?PORT}])).
+start() ->
+ counter:start(),
+ register(tdaPid, spawn(?MODULE, client, [{dial, ?HOST, ?PORT}])).
stop() ->
+ counter:stop(),
tdaPid ! acse:release().
ext() ->
- tdaPid ! rose:invoke({present, 2}, {local, 51}, csta:lines(ext)).
+ tdaPid ! rose:invoke({local, 51}, csta:lines(ext)).
co() ->
- tdaPid ! rose:invoke({present, 2}, {local, 51}, csta:lines(co)).
+ tdaPid ! rose:invoke({local, 51}, csta:lines(co)).
snapshot(Device) ->
- tdaPid ! rose:invoke({present, 2}, {local, 74}, csta:snapshot(Device)).
+ tdaPid ! rose:invoke({local, 74}, csta:snapshot(Device)).
client({dial, Host, Port}) ->
io:format("Dial ~p:~p~n", [Host, Port]),