From cdbef62e70fdc5a224c4509d8e63cc65f43af65a Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Fri, 28 Feb 2025 12:45:35 +0000 Subject: [PATCH] Add some real messages to ASN.1 and handle pings on server --- server/.gitignore | 1 + server/asn1/StudySystemProtocol.asn1 | 33 ++++++++++++++++++++++++++-- server/src/session_server.erl | 13 ++++++----- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/server/.gitignore b/server/.gitignore index 5b03e2e..f9e95ed 100644 --- a/server/.gitignore +++ b/server/.gitignore @@ -1,3 +1,4 @@ _build/* *.beam src/StudySystemProtocol.erl +include/* diff --git a/server/asn1/StudySystemProtocol.asn1 b/server/asn1/StudySystemProtocol.asn1 index af43d69..b460c10 100644 --- a/server/asn1/StudySystemProtocol.asn1 +++ b/server/asn1/StudySystemProtocol.asn1 @@ -1,11 +1,40 @@ StudySystemProtocol DEFINITIONS EXPLICIT TAGS ::= BEGIN +ActivityType ::= ENUMERATED { + reading(0), + exercises(1) +} + +Session ::= SEQUENCE { + subjectId INTEGER, + type ActivityType, + timestamp INTEGER, + minutes INTEGER +} + Request ::= CHOICE { - foo [0] NULL + ping [0] NULL, + listPrioritizedActivities [1] NULL, + logSession [2] Session +} + +PrioritizedActivity ::= SEQUENCE { + subjectId INTEGER, + subjectName UTF8String, + type ActivityType, + priority INTEGER +} + +Error ::= ENUMERATED { + invalidRequest(0), + invalidArguments(1), + serverError(2) } Response ::= CHOICE { - msg [0] UTF8String + error [0] Error, + ack [1] NULL, + prioritizedActivities [2] SEQUENCE OF PrioritizedActivity } END diff --git a/server/src/session_server.erl b/server/src/session_server.erl index 4883d2a..c814fe8 100644 --- a/server/src/session_server.erl +++ b/server/src/session_server.erl @@ -23,13 +23,14 @@ handle_cast(_Msg, State) -> handle_info({ssl, Socket, Data}, State) -> case 'StudySystemProtocol':decode('Request', Data) of - {ok, {foo, _}} -> - {ok, Encoded} - = 'StudySystemProtocol':encode('Response', {msg, "Foo"}), + {ok, {ping, _}} -> + {ok, Encoded} = 'StudySystemProtocol':encode( + 'Response', {ack, 'NULL'}), ok = ssl:send(Socket, Encoded); - Result -> - io:format("Invalid message: ~p~n", [Result]), - ok + {error, {asn1, _Reason}} -> + {ok, Encoded} = 'StudySystemProtocol':encode( + 'Response', {error, invalidRequest}), + ok = ssl:send(Socket, Encoded) end, {noreply, State}; handle_info({ssl_closed, _Socket}, State) ->