summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <quax@moccu.com>2015-10-23 15:54:17 +0200
committerDimitri Sokolyuk <quax@moccu.com>2015-10-23 15:54:17 +0200
commite0125b84c61b2b045b9b5e4ce8d3afa1070dd5fe (patch)
tree13dea9620383e06976093c64a55aa12d87bd911d
parente1c2586b0b433a9909dea2c0263b5892970ebba6 (diff)
Simplify ASN.1
-rw-r--r--Remote-Operations-Generic-ROS-PDUs.erl392
-rw-r--r--rose/Remote-Operations-Generic-ROS-PDUs.asn186
2 files changed, 413 insertions, 65 deletions
diff --git a/Remote-Operations-Generic-ROS-PDUs.erl b/Remote-Operations-Generic-ROS-PDUs.erl
index 63d06ea..1e8eb90 100644
--- a/Remote-Operations-Generic-ROS-PDUs.erl
+++ b/Remote-Operations-Generic-ROS-PDUs.erl
@@ -17,6 +17,10 @@
legacy_erlang_types/0]).
-export(['dialyzer-suppressions'/1]).
-export([
+'enc_ROS'/2,
+'enc_Invoke'/2,
+'enc_ReturnResult'/2,
+'enc_ReturnError'/2,
'enc_Reject'/2,
'enc_GeneralProblem'/2,
'enc_InvokeProblem'/2,
@@ -27,6 +31,10 @@
]).
-export([
+'dec_ROS'/2,
+'dec_Invoke'/2,
+'dec_ReturnResult'/2,
+'dec_ReturnError'/2,
'dec_Reject'/2,
'dec_GeneralProblem'/2,
'dec_InvokeProblem'/2,
@@ -79,6 +87,10 @@ try decode_disp(Type, element(1, ber_decode_nif(Data))) of
end
end.
+encode_disp('ROS',Data) -> 'enc_ROS'(Data);
+encode_disp('Invoke',Data) -> 'enc_Invoke'(Data);
+encode_disp('ReturnResult',Data) -> 'enc_ReturnResult'(Data);
+encode_disp('ReturnError',Data) -> 'enc_ReturnError'(Data);
encode_disp('Reject',Data) -> 'enc_Reject'(Data);
encode_disp('GeneralProblem',Data) -> 'enc_GeneralProblem'(Data);
encode_disp('InvokeProblem',Data) -> 'enc_InvokeProblem'(Data);
@@ -89,6 +101,10 @@ encode_disp('InvokeId',Data) -> 'enc_InvokeId'(Data);
encode_disp(Type,_Data) -> exit({error,{asn1,{undefined_type,Type}}}).
+decode_disp('ROS',Data) -> 'dec_ROS'(Data);
+decode_disp('Invoke',Data) -> 'dec_Invoke'(Data);
+decode_disp('ReturnResult',Data) -> 'dec_ReturnResult'(Data);
+decode_disp('ReturnError',Data) -> 'dec_ReturnError'(Data);
decode_disp('Reject',Data) -> 'dec_Reject'(Data);
decode_disp('GeneralProblem',Data) -> 'dec_GeneralProblem'(Data);
decode_disp('InvokeProblem',Data) -> 'dec_InvokeProblem'(Data);
@@ -116,6 +132,367 @@ info() ->
%%================================
+%% ROS
+%%================================
+'enc_ROS'(Val) ->
+ 'enc_ROS'(Val, []).
+
+'enc_ROS'(Val, TagIn) ->
+ {EncBytes,EncLen} = case element(1,Val) of
+ invoke ->
+ 'enc_Invoke'(element(2,Val), [<<161>>]);
+ returnResult ->
+ 'enc_ReturnResult'(element(2,Val), [<<162>>]);
+ returnError ->
+ 'enc_ReturnError'(element(2,Val), [<<163>>]);
+ reject ->
+ 'enc_Reject'(element(2,Val), [<<164>>]);
+ Else ->
+ exit({error,{asn1,{invalid_choice_type,Else}}})
+ end,
+
+encode_tags(TagIn, EncBytes, EncLen).
+
+
+
+
+'dec_ROS'(Tlv) ->
+ 'dec_ROS'(Tlv, []).
+
+'dec_ROS'(Tlv, TagIn) ->
+Tlv1 = match_tags(Tlv, TagIn),
+case (case Tlv1 of [CtempTlv1] -> CtempTlv1; _ -> Tlv1 end) of
+
+%% 'invoke'
+ {131073, V1} ->
+ {invoke, 'dec_Invoke'(V1, [])};
+
+
+%% 'returnResult'
+ {131074, V1} ->
+ {returnResult, 'dec_ReturnResult'(V1, [])};
+
+
+%% 'returnError'
+ {131075, V1} ->
+ {returnError, 'dec_ReturnError'(V1, [])};
+
+
+%% 'reject'
+ {131076, V1} ->
+ {reject, 'dec_Reject'(V1, [])};
+
+ Else ->
+ exit({error,{asn1,{invalid_choice_tag,Else}}})
+ end
+.
+
+
+%%================================
+%% Invoke
+%%================================
+'enc_Invoke'(Val) ->
+ 'enc_Invoke'(Val, [<<48>>]).
+
+'enc_Invoke'(Val, TagIn) ->
+{_,Cindex1, Cindex2, Cindex3, Cindex4} = Val,
+
+%%-------------------------------------------------
+%% attribute invokeId(1) External Remote-Operations-Generic-ROS-PDUs:InvokeId
+%%-------------------------------------------------
+ {EncBytes1,EncLen1} = 'enc_InvokeId'(Cindex1, []),
+
+%%-------------------------------------------------
+%% attribute linkedId(2) with type CHOICE OPTIONAL
+%%-------------------------------------------------
+ {EncBytes2,EncLen2} = case Cindex2 of
+ asn1_NOVALUE -> {<<>>,0};
+ _ ->
+ 'enc_Invoke_linkedId'(Cindex2, [])
+ end,
+
+%%-------------------------------------------------
+%% attribute opcode(3) External Remote-Operations-Information-Objects:Code
+%%-------------------------------------------------
+ {EncBytes3,EncLen3} = 'Remote-Operations-Information-Objects':'enc_Code'(Cindex3, []),
+
+%%-------------------------------------------------
+%% attribute argument(4) with type ASN1_OPEN_TYPE OPTIONAL
+%%-------------------------------------------------
+ {EncBytes4,EncLen4} = case Cindex4 of
+ asn1_NOVALUE -> {<<>>,0};
+ _ ->
+ encode_open_type(Cindex4, [])
+ end,
+
+ BytesSoFar = [EncBytes1, EncBytes2, EncBytes3, EncBytes4],
+LenSoFar = EncLen1 + EncLen2 + EncLen3 + EncLen4,
+encode_tags(TagIn, BytesSoFar, LenSoFar).
+
+
+
+%%================================
+%% Invoke_linkedId
+%%================================
+'enc_Invoke_linkedId'(Val, TagIn) ->
+ {EncBytes,EncLen} = case element(1,Val) of
+ present ->
+ encode_integer(element(2,Val), [<<128>>]);
+ absent ->
+ encode_null(element(2,Val), [<<129>>]);
+ Else ->
+ exit({error,{asn1,{invalid_choice_type,Else}}})
+ end,
+
+encode_tags(TagIn, EncBytes, EncLen).
+
+
+
+
+'dec_Invoke'(Tlv) ->
+ 'dec_Invoke'(Tlv, [16]).
+
+'dec_Invoke'(Tlv, TagIn) ->
+ %%-------------------------------------------------
+ %% decode tag and length
+ %%-------------------------------------------------
+Tlv1 = match_tags(Tlv, TagIn),
+
+%%-------------------------------------------------
+%% attribute invokeId(1) External Remote-Operations-Generic-ROS-PDUs:InvokeId
+%%-------------------------------------------------
+[V1|Tlv2] = Tlv1,
+Term1 = 'dec_InvokeId'(V1, []),
+
+%%-------------------------------------------------
+%% attribute linkedId(2) with type CHOICE OPTIONAL
+%%-------------------------------------------------
+{Term2,Tlv3} = case Tlv2 of
+[V2 = {131072,_}|TempTlv3] ->
+ {'dec_Invoke_linkedId'(V2, []), TempTlv3};
+[V2 = {131073,_}|TempTlv3] ->
+ {'dec_Invoke_linkedId'(V2, []), TempTlv3};
+ _ ->
+ { asn1_NOVALUE, Tlv2}
+end,
+
+%%-------------------------------------------------
+%% attribute opcode(3) External Remote-Operations-Information-Objects:Code
+%%-------------------------------------------------
+[V3|Tlv4] = Tlv3,
+Term3 = 'Remote-Operations-Information-Objects':'dec_Code'(V3, []),
+
+%%-------------------------------------------------
+%% attribute argument(4) with type ASN1_OPEN_TYPE OPTIONAL
+%%-------------------------------------------------
+{Term4,Tlv5} = case Tlv4 of
+[V4|TempTlv5] ->
+ {decode_open_type_as_binary(V4, []), TempTlv5};
+ _ ->
+ { asn1_NOVALUE, Tlv4}
+end,
+
+case Tlv5 of
+[] -> true;_ -> exit({error,{asn1, {unexpected,Tlv5}}}) % extra fields not allowed
+end,
+ {'Invoke', Term1, Term2, Term3, Term4}.
+
+'dec_Invoke_linkedId'(Tlv, TagIn) ->
+Tlv1 = match_tags(Tlv, TagIn),
+case (case Tlv1 of [CtempTlv1] -> CtempTlv1; _ -> Tlv1 end) of
+
+%% 'present'
+ {131072, V1} ->
+ {present, decode_integer(V1, [])};
+
+
+%% 'absent'
+ {131073, V1} ->
+ {absent, decode_null(V1, [])};
+
+ Else ->
+ exit({error,{asn1,{invalid_choice_tag,Else}}})
+ end
+.
+
+
+%%================================
+%% ReturnResult
+%%================================
+'enc_ReturnResult'(Val) ->
+ 'enc_ReturnResult'(Val, [<<48>>]).
+
+'enc_ReturnResult'(Val, TagIn) ->
+{_,Cindex1, Cindex2} = Val,
+
+%%-------------------------------------------------
+%% attribute invokeId(1) External Remote-Operations-Generic-ROS-PDUs:InvokeId
+%%-------------------------------------------------
+ {EncBytes1,EncLen1} = 'enc_InvokeId'(Cindex1, []),
+
+%%-------------------------------------------------
+%% attribute result(2) with type SEQUENCE OPTIONAL
+%%-------------------------------------------------
+ {EncBytes2,EncLen2} = case Cindex2 of
+ asn1_NOVALUE -> {<<>>,0};
+ _ ->
+ 'enc_ReturnResult_result'(Cindex2, [<<48>>])
+ end,
+
+ BytesSoFar = [EncBytes1, EncBytes2],
+LenSoFar = EncLen1 + EncLen2,
+encode_tags(TagIn, BytesSoFar, LenSoFar).
+
+
+
+%%================================
+%% ReturnResult_result
+%%================================
+'enc_ReturnResult_result'(Val, TagIn) ->
+ {_,Cindex1, Cindex2} = Val,
+
+%%-------------------------------------------------
+%% attribute opcode(1) External Remote-Operations-Information-Objects:Code
+%%-------------------------------------------------
+ {EncBytes1,EncLen1} = 'Remote-Operations-Information-Objects':'enc_Code'(Cindex1, []),
+
+%%-------------------------------------------------
+%% attribute result(2) with type ASN1_OPEN_TYPE
+%%-------------------------------------------------
+ {EncBytes2,EncLen2} = encode_open_type(Cindex2, []),
+
+ BytesSoFar = [EncBytes1, EncBytes2],
+LenSoFar = EncLen1 + EncLen2,
+encode_tags(TagIn, BytesSoFar, LenSoFar).
+
+
+'dec_ReturnResult'(Tlv) ->
+ 'dec_ReturnResult'(Tlv, [16]).
+
+'dec_ReturnResult'(Tlv, TagIn) ->
+ %%-------------------------------------------------
+ %% decode tag and length
+ %%-------------------------------------------------
+Tlv1 = match_tags(Tlv, TagIn),
+
+%%-------------------------------------------------
+%% attribute invokeId(1) External Remote-Operations-Generic-ROS-PDUs:InvokeId
+%%-------------------------------------------------
+[V1|Tlv2] = Tlv1,
+Term1 = 'dec_InvokeId'(V1, []),
+
+%%-------------------------------------------------
+%% attribute result(2) with type SEQUENCE OPTIONAL
+%%-------------------------------------------------
+{Term2,Tlv3} = case Tlv2 of
+[{16,V2}|TempTlv3] ->
+ {'dec_ReturnResult_result'(V2, []), TempTlv3};
+ _ ->
+ { asn1_NOVALUE, Tlv2}
+end,
+
+case Tlv3 of
+[] -> true;_ -> exit({error,{asn1, {unexpected,Tlv3}}}) % extra fields not allowed
+end,
+ {'ReturnResult', Term1, Term2}.
+
+'dec_ReturnResult_result'(Tlv, TagIn) ->
+ %%-------------------------------------------------
+ %% decode tag and length
+ %%-------------------------------------------------
+Tlv1 = match_tags(Tlv, TagIn),
+
+%%-------------------------------------------------
+%% attribute opcode(1) External Remote-Operations-Information-Objects:Code
+%%-------------------------------------------------
+[V1|Tlv2] = Tlv1,
+Term1 = 'Remote-Operations-Information-Objects':'dec_Code'(V1, []),
+
+%%-------------------------------------------------
+%% attribute result(2) with type ASN1_OPEN_TYPE
+%%-------------------------------------------------
+[V2|Tlv3] = Tlv2,
+Term2 = decode_open_type_as_binary(V2, []),
+
+case Tlv3 of
+[] -> true;_ -> exit({error,{asn1, {unexpected,Tlv3}}}) % extra fields not allowed
+end,
+ {'ReturnResult_result', Term1, Term2}.
+
+
+
+%%================================
+%% ReturnError
+%%================================
+'enc_ReturnError'(Val) ->
+ 'enc_ReturnError'(Val, [<<48>>]).
+
+'enc_ReturnError'(Val, TagIn) ->
+{_,Cindex1, Cindex2, Cindex3} = Val,
+
+%%-------------------------------------------------
+%% attribute invokeId(1) External Remote-Operations-Generic-ROS-PDUs:InvokeId
+%%-------------------------------------------------
+ {EncBytes1,EncLen1} = 'enc_InvokeId'(Cindex1, []),
+
+%%-------------------------------------------------
+%% attribute errcode(2) External Remote-Operations-Information-Objects:Code
+%%-------------------------------------------------
+ {EncBytes2,EncLen2} = 'Remote-Operations-Information-Objects':'enc_Code'(Cindex2, []),
+
+%%-------------------------------------------------
+%% attribute parameter(3) with type ASN1_OPEN_TYPE OPTIONAL
+%%-------------------------------------------------
+ {EncBytes3,EncLen3} = case Cindex3 of
+ asn1_NOVALUE -> {<<>>,0};
+ _ ->
+ encode_open_type(Cindex3, [])
+ end,
+
+ BytesSoFar = [EncBytes1, EncBytes2, EncBytes3],
+LenSoFar = EncLen1 + EncLen2 + EncLen3,
+encode_tags(TagIn, BytesSoFar, LenSoFar).
+
+
+'dec_ReturnError'(Tlv) ->
+ 'dec_ReturnError'(Tlv, [16]).
+
+'dec_ReturnError'(Tlv, TagIn) ->
+ %%-------------------------------------------------
+ %% decode tag and length
+ %%-------------------------------------------------
+Tlv1 = match_tags(Tlv, TagIn),
+
+%%-------------------------------------------------
+%% attribute invokeId(1) External Remote-Operations-Generic-ROS-PDUs:InvokeId
+%%-------------------------------------------------
+[V1|Tlv2] = Tlv1,
+Term1 = 'dec_InvokeId'(V1, []),
+
+%%-------------------------------------------------
+%% attribute errcode(2) External Remote-Operations-Information-Objects:Code
+%%-------------------------------------------------
+[V2|Tlv3] = Tlv2,
+Term2 = 'Remote-Operations-Information-Objects':'dec_Code'(V2, []),
+
+%%-------------------------------------------------
+%% attribute parameter(3) with type ASN1_OPEN_TYPE OPTIONAL
+%%-------------------------------------------------
+{Term3,Tlv4} = case Tlv3 of
+[V3|TempTlv4] ->
+ {decode_open_type_as_binary(V3, []), TempTlv4};
+ _ ->
+ { asn1_NOVALUE, Tlv3}
+end,
+
+case Tlv4 of
+[] -> true;_ -> exit({error,{asn1, {unexpected,Tlv4}}}) % extra fields not allowed
+end,
+ {'ReturnError', Term1, Term2, Term3}.
+
+
+
+%%================================
%% Reject
%%================================
'enc_Reject'(Val) ->
@@ -398,6 +775,13 @@ case (case Tlv1 of [CtempTlv1] -> CtempTlv1; _ -> Tlv1 end) of
ber_decode_nif(B) ->
asn1rt_nif:decode_ber_tlv(B).
+ber_encode([Tlv]) ->
+ ber_encode(Tlv);
+ber_encode(Tlv) when is_binary(Tlv) ->
+ Tlv;
+ber_encode(Tlv) ->
+ asn1rt_nif:encode_ber_tlv(Tlv).
+
decode_integer(Tlv, TagIn) ->
Bin = match_tags(Tlv, TagIn),
Len = byte_size(Bin),
@@ -413,6 +797,9 @@ decode_null(Tlv, Tags) ->
exit({error,{asn1,{decode_null,Val}}})
end.
+decode_open_type_as_binary(Tlv, TagIn) ->
+ ber_encode(match_tags(Tlv, TagIn)).
+
encode_integer(Val) ->
Bytes =
if
@@ -463,6 +850,11 @@ encode_length(L) ->
encode_null(_Val, TagIn) ->
encode_tags(TagIn, [], 0).
+encode_open_type(Val, T) when is_list(Val) ->
+ encode_open_type(list_to_binary(Val), T);
+encode_open_type(Val, Tag) ->
+ encode_tags(Tag, Val, byte_size(Val)).
+
encode_tags(TagIn, {BytesSoFar,LenSoFar}) ->
encode_tags(TagIn, BytesSoFar, LenSoFar).
diff --git a/rose/Remote-Operations-Generic-ROS-PDUs.asn1 b/rose/Remote-Operations-Generic-ROS-PDUs.asn1
index e62bd48..f854b0a 100644
--- a/rose/Remote-Operations-Generic-ROS-PDUs.asn1
+++ b/rose/Remote-Operations-Generic-ROS-PDUs.asn1
@@ -3,39 +3,23 @@ DEFINITIONS IMPLICIT TAGS ::=
BEGIN
-- exports everything
IMPORTS OPERATION, ERROR FROM Remote-Operations-Information-Objects{joint-iso-itu-t remote-operations(4) informationObjects(5) version1(0)};
-ROS {InvokeId:InvokeIdSet, OPERATION:Invokable, OPERATION:Returnable} ::= CHOICE
+ROS ::= CHOICE
{
- invoke [1] Invoke {{InvokeIdSet}, {Invokable}},
- returnResult [2] ReturnResult {{Returnable}},
- returnError [3] ReturnError {{Errors{{Returnable}}}},
+ invoke [1] Invoke,
+ returnResult [2] ReturnResult,
+ returnError [3] ReturnError,
reject [4] Reject
}
-(CONSTRAINED BY { -- must conform to the above definition -- }
-! RejectProblem : general-unrecognisedPDU)
-Invoke {InvokeId:InvokeIdSet, OPERATION:Operations} ::= SEQUENCE
+Invoke ::= SEQUENCE
{
- invokeId InvokeId (InvokeIdSet)
- (CONSTRAINED BY {-- must be unambiguous --}
- ! RejectProblem : invoke-duplicateInvocation),
- linkedId CHOICE {
- present [0] IMPLICIT present < InvokeId,
- absent [1] IMPLICIT NULL
- }
- (CONSTRAINED BY {-- must identify an outstanding operation --}
- ! RejectProblem : invoke-unrecognisedLinkedId)
- (CONSTRAINED BY {-- which has one or more linked operations--}
- ! RejectProblem : invoke-linkedResponseUnexpected)
- OPTIONAL,
- opcode OPERATION.&operationCode
- ({Operations}
- ! RejectProblem : invoke-unrecognisedOperation),
- argument OPERATION.&ArgumentType
- ({Operations} {@opcode}
- ! RejectProblem : invoke-mistypedArgument)
- OPTIONAL
+ invokeId InvokeId,
+ linkedId CHOICE {
+ present [0] IMPLICIT present < InvokeId,
+ absent [1] IMPLICIT NULL
+ } OPTIONAL,
+ opcode OPERATION.&operationCode,
+ argument OPERATION.&ArgumentType OPTIONAL
}
-(CONSTRAINED BY { -- must conform to the above definition -- }
-! RejectProblem : general-mistypedPDU)
(
WITH COMPONENTS
{...,
@@ -45,50 +29,24 @@ Invoke {InvokeId:InvokeIdSet, OPERATION:Operations} ::= SEQUENCE
{...,
linkedId PRESENT,
opcode
- (CONSTRAINED BY {-- must be in the &Linked field of the associated operation --}
- ! RejectProblem : invoke-unexpectedLinkedOperation)
}
)
-ReturnResult {OPERATION:Operations}::= SEQUENCE
+ReturnResult ::= SEQUENCE
{
- invokeId InvokeId
- (CONSTRAINED BY {-- must be that for an outstanding operation --}
- ! RejectProblem : returnResult-unrecognisedInvocation)
- (CONSTRAINED BY {-- which returns a result --}
- ! RejectProblem : returnResult-resultResponseUnexpected),
+ invokeId InvokeId,
result SEQUENCE
{
- opcode OPERATION.&operationCode
- ({Operations})(CONSTRAINED BY {-- identified by invokeId --}
- ! RejectProblem : returnResult-unrecognisedInvocation),
- result OPERATION.&ResultType
- ({Operations} {@.opcode}
- ! RejectProblem : returnResult-mistypedResult)
- }
- OPTIONAL
+ opcode OPERATION.&operationCode,
+ result OPERATION.&ResultType
+ } OPTIONAL
}
-(CONSTRAINED BY { -- must conform to the above definition -- }
-! RejectProblem : general-mistypedPDU)
-ReturnError {ERROR:Errors} ::= SEQUENCE
+ReturnError ::= SEQUENCE
{
- invokeId InvokeId
- (CONSTRAINED BY {-- must be that for an outstanding operation --}
- ! RejectProblem : returnError-unrecognisedInvocation)
- (CONSTRAINED BY {-- which returns an error --}
- ! RejectProblem : returnError-errorResponseUnexpected),
- errcode ERROR.&errorCode
- ({Errors}
- ! RejectProblem : returnError-unrecognisedError)
- (CONSTRAINED BY {-- must be in the &Errors field of the associated --
- -- operation --}
- ! RejectProblem : returnError-unexpectedError),
- parameter ERROR.&ParameterType
- ({Errors}{@errcode}
- ! RejectProblem : returnError-mistypedParameter) OPTIONAL
+ invokeId InvokeId,
+ errcode ERROR.&errorCode,
+ parameter ERROR.&ParameterType OPTIONAL
}
-(CONSTRAINED BY { -- must conform to the above definition -- }
-! RejectProblem : general-mistypedPDU)
Reject ::= SEQUENCE
{
invokeId InvokeId,
@@ -100,8 +58,6 @@ Reject ::= SEQUENCE
returnError [3] ReturnErrorProblem
}
}
-(CONSTRAINED BY { -- must conform to the above definition -- }
-! RejectProblem : general-mistypedPDU)
GeneralProblem ::= INTEGER
{
unrecognisedPDU (0),