From 55bedf3292656dccfea59bde7cc9af9ba2a616cc Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Mon, 9 Nov 2015 01:44:10 +0100 Subject: Add error, acse:encode --- src/pbx_acse.erl | 14 +++++++------- src/pbx_conn.erl | 8 +++++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/pbx_acse.erl b/src/pbx_acse.erl index 5b37964..d7d1114 100644 --- a/src/pbx_acse.erl +++ b/src/pbx_acse.erl @@ -3,10 +3,9 @@ -include("ACSE-1.hrl"). -include("CSTA-application-context-information-csta3.hrl"). --export([associate/0, release/0]). --export([decode/1, dispatch/1]). +-export([encode/1, decode/1, dispatch/1]). -associate() -> +encode(associate) -> {ok, UI} = 'CSTA-application-context-information-csta3':encode( 'ACSEUserInformationForCSTA', {newDefinition, #'NewACSEUserInformationForCSTA'{cSTAVersion = [versionFive]}}), @@ -15,10 +14,11 @@ associate() -> 'application-context-name' = {1, 3, 12, 0, 218}, 'user-information' = [#'EXTERNAL'{ 'direct-reference' = {1, 3, 12, 0, 285, 200}, - encoding = {'single-ASN1-type', UI}}]}}). - -release() -> - 'ACSE-1':encode('ACSE-apdu', {rlrq, #'RLRQ-apdu'{}}). + encoding = {'single-ASN1-type', UI}}]}}); +encode(release) -> + 'ACSE-1':encode('ACSE-apdu', {rlrq, #'RLRQ-apdu'{}}); +encode(Data) -> + 'ACSE-1':encode('ACSE-apdu', Data). decode(Data) -> 'ACSE-1':decode('ACSE-apdu', Data). diff --git a/src/pbx_conn.erl b/src/pbx_conn.erl index af3dbc0..3b7465a 100644 --- a/src/pbx_conn.erl +++ b/src/pbx_conn.erl @@ -13,7 +13,7 @@ start_link() -> gen_server:start_link({local, ?SERVER}, ?MODULE, [?HOST, ?PORT], []). init(Args) -> - send(pbx_acse:associate()), + send(pbx_acse:encode(associate)), [Host, Port] = Args, gen_tcp:connect(Host, Port, [binary, {packet, 2}]). @@ -22,7 +22,9 @@ handle_call(_Request, _From, Socket) -> handle_cast({ok, Reply}, Socket) -> gen_tcp:send(Socket, Reply), - {noreply, Socket}. + {noreply, Socket}; +handle_cast({error, Reason}, Socket) -> + {stop, Reason, Socket}. handle_info({tcp, _, Data}, Socket) -> case pbx_acse:decode(Data) of @@ -38,7 +40,7 @@ handle_info({tcp_closed, _}, Socket) -> {stop, normal, Socket}. terminate(_Reason, Socket) -> - send(pbx_acse:release()), + send(pbx_acse:encode(release)), gen_tcp:close(Socket). code_change(_OldVsn, Socket, _Extra) -> -- cgit v1.2.3