summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-10-30 12:24:12 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-10-30 12:24:12 +0100
commit5a6df738a3019b34f2f47c8da7db6f84994570cd (patch)
tree3589795c8c7db7f318b8c96d3bd5dc252484c678
parentc205c6551ae0bdda1b32486209b498870acc7a39 (diff)
Use macros
-rw-r--r--include/opcodes.hrl5
-rw-r--r--src/rose.erl13
-rw-r--r--src/snapshot.erl5
-rw-r--r--src/status.erl5
-rw-r--r--src/tda.erl8
5 files changed, 19 insertions, 17 deletions
diff --git a/include/opcodes.hrl b/include/opcodes.hrl
new file mode 100644
index 0000000..54f3771
--- /dev/null
+++ b/include/opcodes.hrl
@@ -0,0 +1,5 @@
+-define(EVENT, {local, 21}).
+-define(ESCAPE, {local, 51}).
+-define(MONITOR, {local, 71}).
+-define(SNAPSHOT, {local, 74}).
+-define(STATUS, {local, 211}).
diff --git a/src/rose.erl b/src/rose.erl
index 78cfb14..441fa05 100644
--- a/src/rose.erl
+++ b/src/rose.erl
@@ -2,6 +2,7 @@
-export([decode/1, invoke/2, dispatch/1]).
+-include("opcodes.hrl").
-include("Remote-Operations-Generic-ROS-PDUs.hrl").
decode(Data) ->
@@ -20,17 +21,17 @@ invoke(Op, {ok, Data}) ->
dispatch({invoke, #'Invoke'{invokeId = Id, opcode = Op, argument = Data}}) ->
counter:set(Id),
case Op of
- {local, 21} ->
+ ?EVENT ->
ok;
- {local, 51} ->
+ ?ESCAPE ->
{ok, Esc} = escape:decode(Data),
io:format("Esc ~p~n", [Esc]),
ok;
- {local, 71} ->
+ ?MONITOR ->
ok;
- {local, 74} ->
+ ?SNAPSHOT ->
ok;
- {local, 211} ->
+ ?STATUS ->
io:format("Status: ~p~n", [status:value(Data)]),
return(Id, Op, status:encode());
_ ->
@@ -53,7 +54,7 @@ dispatch({reject, #'Reject'{invokeId = Id, problem = Problem}}) ->
dispatch(#'ReturnResult_result'{opcode = Op, result = Data}) ->
case Op of
- {local, 74} ->
+ ?SNAPSHOT ->
{ok, Status} = snapshot:decode(Data),
io:format("Result: ~p~n", [Status]);
_ ->
diff --git a/src/snapshot.erl b/src/snapshot.erl
index c27ba55..4e53cb3 100644
--- a/src/snapshot.erl
+++ b/src/snapshot.erl
@@ -1,13 +1,10 @@
-module(snapshot).
--export([opcode/0, decode/1, encode/1]).
+-export([decode/1, encode/1]).
-include("CSTA-snapshot-device.hrl").
-include("CSTA-device-identifiers.hrl").
-opcode() ->
- {local, 74}.
-
decode(Data) ->
'CSTA-snapshot-device':decode('SnapshotDeviceResult', Data).
diff --git a/src/status.erl b/src/status.erl
index b12b54e..3c419a3 100644
--- a/src/status.erl
+++ b/src/status.erl
@@ -1,12 +1,9 @@
-module(status).
--export([opcode/0, decode/1, encode/0, value/1]).
+-export([decode/1, encode/0, value/1]).
-include("CSTA-system-status.hrl").
-opcode() ->
- {local, 211}.
-
decode(Data) ->
'CSTA-system-status':decode('SystemStatusArg', Data).
diff --git a/src/tda.erl b/src/tda.erl
index 9cac6f7..5fe8bf8 100644
--- a/src/tda.erl
+++ b/src/tda.erl
@@ -3,6 +3,8 @@
-export([start/0, client/1, stop/0]).
-export([ext/0, co/0, snapshot/1]).
+-include("opcodes.hrl").
+
-define(TIMEOUT, 300000).
-define(CONNECT_TIMEOUT, 3000).
-define(HOST, "192.168.240.20").
@@ -16,13 +18,13 @@ stop() ->
tdaPid ! acse:release().
ext() ->
- tdaPid ! rose:invoke({local, 51}, escape:lines(ext)).
+ tdaPid ! rose:invoke(?ESCAPE, escape:lines(ext)).
co() ->
- tdaPid ! rose:invoke({local, 51}, escape:lines(co)).
+ tdaPid ! rose:invoke(?ESCAPE, escape:lines(co)).
snapshot(Device) ->
- tdaPid ! rose:invoke({local, 74}, snapshot:encode(Device)).
+ tdaPid ! rose:invoke(?SNAPSHOT, snapshot:encode(Device)).
client({dial, Host, Port}) ->
io:format("Dial ~p:~p~n", [Host, Port]),