summaryrefslogtreecommitdiff
path: root/tda.erl
blob: 5d263503d82b1e889aacb8053b3a3038b2fc8db8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
-module(tda).

-export([associate_request/0, associate_result/1]).
-export([release_request/0, release_result/1]).
-export([associate_abort/1]).
-export([system_status/1]).

-include("ACSE-1.hrl").
-include("CSTA-application-context-information-csta3.hrl").
-include("Remote-Operations-Generic-ROS-PDUs.hrl").

associate_request() ->
	Ver = {newDefinition, #'NewACSEUserInformationForCSTA'{
				 cSTAVersion = [versionFive]}},
	{ok, Enc} = 'CSTA-application-context-information-csta3':encode(
		'ACSEUserInformationForCSTA', Ver),
	Pdu = #'AARQ-apdu'{'application-context-name' = {1, 3, 12, 0, 218},
		'user-information' = [#'EXTERNAL'{
			'direct-reference' = {1, 3, 12, 0, 285, 200},
			encoding = {'single-ASN1-type', Enc}
		}]},
	'ACSE-1':encode('AARQ-apdu', Pdu).

% Accept
% <<97,47,128,2,7,128,161,7,6,5,43,12,0,129,90,162,3,2,1,0,163,5,161,3,2,1,1,190,20,40,18,6,7,43,12,0,130,29,129,72,160,7,160,5,3,3,0,8,0>>
% Reject
% <<97,25,128,2,7,128,161,7,6,5,43,12,0,129,90,162,3,2,1,1,163,5,161,3,2,1,1>>
associate_result(Bin) ->
	{ok, Pdu} = 'ACSE-1':decode('AARE-apdu', Bin),
	case Pdu#'AARE-apdu'.result of
		accepted ->
			[UI] = Pdu#'AARE-apdu'.'user-information',
			{_, Enc} = UI#'EXTERNAL'.encoding,
			{ok, {_, Ver}} = 'CSTA-application-context-information-csta3':decode(
				'ACSEUserInformationForCSTA', Enc),
			{Pdu#'AARE-apdu'.result,
			 Pdu#'AARE-apdu'.'result-source-diagnostic',
			 Ver#'NewACSEUserInformationForCSTA'.cSTAVersion};
		'rejected-permanent' ->
			{Pdu#'AARE-apdu'.result,
			 Pdu#'AARE-apdu'.'result-source-diagnostic'};
		'rejected-transient' ->
			{Pdu#'AARE-apdu'.result,
			 Pdu#'AARE-apdu'.'result-source-diagnostic'}
	end.

release_request() ->
	'ACSE-1':encode('RLRQ-apdu', #'RLRQ-apdu'{}).

release_result(Bin) ->
	'ACSE-1':decode('RLRE-apdu', Bin).

% <<100,3,128,1,0>>
associate_abort(Bin) ->
	{ok, Pdu} = 'ACSE-1':decode('ABRT-apdu', Bin),
	Pdu#'ABRT-apdu'.'abort-source'.

% <<161,12,2,1,1,2,2,0,211,48,3,10,1,2>>
% <<162,11,2,1,1,48,6,2,2,0,211,5,0>>
system_status(Bin) ->
	Inv = #'Invoke'{invokeId = 1, opcode = {local, 211}},
	io:format("~p~n", [Inv]),
	case 'Remote-Operations-Generic-ROS-PDUs':encode('Invoke', Inv) of
		{ok, Invoke} -> Invoke;
		{error, Reason} -> Reason
	end.