Commit ab15a376 authored by Thanassis Tsiodras's avatar Thanassis Tsiodras

Added documentation folder from old VM.

parent d664e04f
all: clean generate
ASN1_C_DIR=asn-c-generated
ACN_C_DIR=acn-c-generated
ASN1_ADA_DIR=asn-ada-generated
ACN_ADA_DIR=acn-ada-generated
CC=gcc
GNATMAKE=gnatmake
generate:
mkdir -p $(ASN1_C_DIR)
mkdir -p $(ACN_C_DIR)
asn1.exe -o $(ASN1_C_DIR) -uPER -c protocol.asn
asn1.exe -o $(ACN_C_DIR) -ACN -c protocol.acn protocol.asn
mkdir -p $(ASN1_ADA_DIR)
mkdir -p $(ACN_ADA_DIR)
asn1.exe -o $(ASN1_ADA_DIR) -uPER -Ada protocol.asn
asn1.exe -o $(ACN_ADA_DIR) -ACN -Ada protocol.acn protocol.asn
compile:
$(CC) $(CFLAGS) -I$(ACN_C_DIR) -o encode src/encode.c $(ACN_C_DIR)/asn1crt.c $(ACN_C_DIR)/protocol.c $(ACN_C_DIR)/acn.c $(ACN_C_DIR)/ber.c $(ACN_C_DIR)/xer.c $(ACN_C_DIR)/real.c
$(CC) $(CFLAGS) -I$(ACN_C_DIR) -o decode src/decode.c $(ACN_C_DIR)/asn1crt.c $(ACN_C_DIR)/protocol.c $(ACN_C_DIR)/acn.c $(ACN_C_DIR)/ber.c $(ACN_C_DIR)/xer.c $(ACN_C_DIR)/real.c
$(GNATMAKE) -gnatc $(ACN_ADA_DIR)/myprotocol.adb
clean:
rm -rf $(ASN1_C_DIR) $(ACN_C_DIR)
rm -rf $(ASN1_ADA_DIR) $(ACN_ADA_DIR)
rm -f *~ encode decode
rm -f src/*~ encode decode
rm -rf encoded.sample
MyProtocol DEFINITIONS ::= BEGIN
Port-T[size 16, encode-what values, encoding pos-int]
Header-T []
{
size [endianness little, encoding pos-int, size 16],
port [endianness little, encoding pos-int, encode-what values, size 16]
}
Payload-T[size auto]
Packet-T []
{
header [],
payload []
}
END
MyProtocol DEFINITIONS AUTOMATIC TAGS ::= BEGIN
Port-T ::= ENUMERATED {portA(1), portB(2) }
Header-T ::= SEQUENCE
{
size INTEGER (0 .. 100),
port Port-T
}
Payload-T ::= OCTET STRING (SIZE (1..255))
Packet-T ::= SEQUENCE
{
header Header-T,
payload Payload-T
}
END
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "asn1crt.h"
#include "protocol.h"
#define EASTER_EGG " (and Jerome should read ACN documentation !)\0"
int main (int argc, char* arv[])
{
unsigned char header_buf[Header_T_REQUIRED_BYTES_FOR_ACN_ENCODING];
unsigned char mypayload[200];
BitStream strm;
Payload_T payload;
Header_T header;
int fd;
int err;
int i;
Header_T_Initialize (&header);
Payload_T_Initialize (&payload);
fd = open ("encoded.sample", O_RDONLY);
memset (mypayload, '\0', 200);
BitStream_Init (&strm, header_buf, Header_T_REQUIRED_BYTES_FOR_ACN_ENCODING);
read (fd, header_buf, Header_T_REQUIRED_BYTES_FOR_ACN_ENCODING);
Header_T_ACN_Decode (&header, &strm, &err);
printf ("Payload size in header=%d\n", header.size);
for (i = 0 ; i < header.size ; i++)
{
char c;
read (fd, &c, 1);
mypayload[i] = c;
}
if (header.size == 10)
{
memcpy (mypayload + header.size , EASTER_EGG, strlen (EASTER_EGG));
}
printf ("My custom payload: %s\n", mypayload);
close (fd);
return 0;
}
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "asn1crt.h"
#include "protocol.h"
int main (int argc, char* arv[])
{
unsigned char encoded[Packet_T_REQUIRED_BITS_FOR_ACN_ENCODING];
BitStream strm;
Packet_T pkt;
int fd;
int err;
Packet_T_Initialize (&pkt);
BitStream_Init (&strm, encoded, Packet_T_REQUIRED_BITS_FOR_ACN_ENCODING);
pkt.header.size = 10;
pkt.header.port = 2;
pkt.payload.nCount = 10;
memcpy (pkt.payload.arr, "ACN rocks!", 10);
if (Packet_T_ACN_Encode (&pkt, &strm, &err, 1))
{
printf ("Encoding OK, size of the stream is %d\n", strm.count);
fd = open ("encoded.sample", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR );
write (fd, encoded, strm.count);
close (fd);
}
else
{
printf ("Encoding KO\n");
}
return 0;
}
FLAGS=-f -aadlv2
FILES=protocol.aadl ping.aadl software.aadl `ocarina-config --prefix`/share/ocarina/AADLv2/ocarina_components.aadl
parse:
ocarina $(FLAGS) $(FILES)
instantiate:
ocarina -i $(FLAGS) $(FILES)
clean:
$(RM) *~
-- This model completes the PING example by adding deployment
-- information.
--
-- In this deployment, two nodes are defined, one task per node.
--
-- $Id: ping.aadl 401 2007-06-07 15:04:01Z hugues $
package PING
public
with Software;
with Deployment;
with ocarina_drivers;
with ocarina_buses;
with protocol;
---------------
-- Processor --
---------------
processor the_processor
properties
Deployment::Execution_Platform => Native;
Priority_Range => 0 .. 255;
Scheduling_Protocol => (Posix_1003_Highest_Priority_First_Protocol);
end the_processor;
processor implementation the_processor.i
end the_processor.i;
---------
-- Bus --
---------
bus Ethernet_Bus
properties
Deployment::Transport_API => BSD_Sockets;
end Ethernet_Bus;
---------------
-- Processes --
---------------
process A
features
Out_Port : out event data port Software::Simple_Type;
end A;
process implementation A.Impl
subcomponents
Pinger : thread Software::P.Impl;
connections
port Pinger.Data_Source -> Out_Port;
end A.Impl;
process B
features
In_Port : in event data port Software::Simple_Type;
end B;
process implementation B.Impl
subcomponents
Ping_Me : thread Software::Q.Impl;
connections
port In_Port -> Ping_Me.Data_Sink;
end B.Impl;
------------
-- System --
------------
system PING
end PING;
system implementation PING.Impl
subcomponents
Node_A : process A.Impl;
Node_B : process B.Impl;
Device_A : device protocol::network_sockets.impl
{Source_Text => ("devicesconf.c");};
Device_B : device protocol::network_sockets.impl
{Source_Text => ("devicesconf.c");};
CPU_A : processor the_processor.i;
CPU_B : processor the_processor.i;
the_bus : bus protocol::multiprotocol.impl;
connections
bus access the_bus -> Device_A.thebus;
bus access the_bus -> Device_B.thebus;
-- VERIFICATION POINT: check that the accessed devices/bus are
-- compliant. Meaning: the intersection of bus sub-components
-- AND the Provided_Virtual_Bus_Class of the device is not NULL.
port Node_A.Out_Port -> Node_B.In_Port
{
Actual_Connection_Binding => (reference (the_bus.user_def));
-- VERIFICATION POINT
-- Here, if we specify the_bus.pohic_asn1, it MUST raise
-- an error when generating the code since the device
-- does not support it.
};
properties
actual_processor_binding => (reference (CPU_A)) applies to Node_A;
actual_processor_binding => (reference (CPU_B)) applies to Node_B;
actual_processor_binding => (reference (CPU_A)) applies to Device_A;
actual_processor_binding => (reference (CPU_B)) applies to Device_B;
end PING.Impl;
end PING;
package protocol
public
with ocarina_drivers; -- to inherit the regular sockets driver.
-- This model provides the description of three protocols
-- to be used by PolyORB-HI-C:
-- 1. myprotocol.user : a user-defined protocol that uses
-- ASN.1 for its description. The ASN.1
-- model AND the marshaller functions
-- ARE provided by the user.
-- 2. protpohic.asn1 : mapping of the current PolyORB-HI-C
-- protocol with ASN.1. Everything that is used
-- by this model is automatically generated by
-- Ocarina.
-- 3. protpohic.regular : the regular communication stack of PolyORB-HI-C.
-- It corresponds to the mechanisms that are
-- actually used.
------------------------------------------------------
-- Description of the user-defined ASN1 protocol
------------------------------------------------------
abstract myprotocol_impl
end myprotocol_impl;
abstract implementation myprotocol_impl.impl
subcomponents
marshaller: subprogram marshaller_func.impl;
unmarshaller: subprogram unmarshaller_func.impl;
associated_type: data prot_type.impl;
end myprotocol_impl.impl;
virtual bus myprotocol
end myprotocol;
virtual bus implementation myprotocol.user
properties
Implemented_As => classifier (protocol::myprotocol_impl.impl);
end myprotocol.user;
subprogram marshaller_func
features
req : in parameter request_type.pohic;
msg : out parameter prot_type;
end marshaller_func;
subprogram implementation marshaller_func.impl
properties
Source_Language => C;
Source_Name => "myprotocol_marshall";
Source_Text => ("myprotocol.c");
end marshaller_func.impl;
subprogram unmarshaller_func
features
msg : in parameter prot_type;
req : out parameter request_type.pohic;
end unmarshaller_func;
subprogram implementation unmarshaller_func.impl
properties
Source_Language => C;
Source_Name => "myprotocol_unmarshall";
Source_Text => ("myprotocol.c");
end unmarshaller_func.impl;
data prot_type
properties
Source_Language => ASN1;
Source_Name => "myprotocol_pkt_t";
Source_Text => ("myprot.asn");
end prot_type;
data implementation prot_type.impl
end prot_type.impl;
------------------------------------------------------
-- End of the description of the user-defined
-- ASN1 protocol
------------------------------------------------------
------------------------------------------------------
-- Beginning of the modelling of the PolyORB-HI-C protocol
-- mapped with ASN1.
------------------------------------------------------
virtual bus implementation protpohic.asn1
properties
Implemented_As => classifier (protocol::pohiasn1.impl);
end protpohic.asn1;
abstract pohiasn1
end pohiasn1;
abstract implementation pohiasn1.impl
subcomponents
marshaller: subprogram pohiasn1_marshaller_func.impl;
unmarshaller: subprogram pohiasn1_unmarshaller_func.impl;
associated_type: data pohi_asn1_prot_type.i;
end pohiasn1.impl;
subprogram pohiasn1_marshaller_func
features
req : in parameter request_type.pohic;
msg : out parameter pohi_asn1_prot_type;
end pohiasn1_marshaller_func;
subprogram implementation pohiasn1_marshaller_func.impl
properties
Source_Language => C;
Source_Name => "myprotocol_marshall";
Source_Text => ("pohiasn1_protocol.c");
end pohiasn1_marshaller_func.impl;
subprogram pohiasn1_unmarshaller_func
features
msg : in parameter pohi_asn1_prot_type;
req : out parameter request_type.pohic;
end pohiasn1_unmarshaller_func;
subprogram implementation pohiasn1_unmarshaller_func.impl
properties
Source_Language => C;
Source_Name => "pohiasn1_unmarshall";
Source_Text => ("pohiasn1_protocol.c");
end pohiasn1_unmarshaller_func.impl;
data pohi_asn1_prot_type
properties
Source_Language => ASN1;
Source_Name => "pohiasn1_pkt_t";
Source_Text => ("pohiasn1.asn");
end pohi_asn1_prot_type;
data implementation pohi_asn1_prot_type.i
end pohi_asn1_prot_type.i;
------------------------------------------------------
-- End of the description of the PolyORB-HI-C protocol
-- mapped with ASN1.
------------------------------------------------------
------------------------------------------------------
-- Generic types to be used by all protocols.
------------------------------------------------------
virtual bus protpohic
end protpohic;
virtual bus implementation protpohic.regular
end protpohic.regular;
data request_type
end request_type;
data implementation request_type.pohic
properties
Source_Language => C;
Source_Name => "__po_hi_request_t";
end request_type.pohic;
------------------------------------------------------
-- End of description of generic types to be used
-- by all protocols.
------------------------------------------------------
bus multiprotocol
end multiprotocol;
device network_sockets
features
thebus : requires bus access multiprotocol.impl;
end network_sockets;
device implementation network_sockets.impl extends ocarina_drivers::generic_sockets_ip.pohic
properties
Provided_Virtual_Bus_Class => (classifier (protocol::myprotocol.user));
end network_sockets.impl;
bus implementation multiprotocol.impl
subcomponents
pohic_asn1 : virtual bus protpohic.asn1;
pohic_reg : virtual bus protpohic.regular;
user_def : virtual bus myprotocol.user;
end multiprotocol.impl;
end protocol;
-- This AADL model illustrates how to model a simple interaction
-- between tasks, in a local or distributed environment.
--
-- One task pings another, sending a data periodically.
--
-- $Id: software.aadl 344 2007-04-17 14:48:16Z zalila $
package Software
public
with Data_Model;
----------
-- Data --
----------
data Simple_Type
properties
Type_Source_Name => "custom_int";
Source_Text => ("ping");
Source_Data_Size => 8 Bytes;
end Simple_Type;
-----------------
-- Subprograms --
-----------------
subprogram Do_Ping_Spg
features
Data_Source : out parameter Simple_Type;
properties
source_language => C;
source_name => "user_do_ping_spg";
source_text => ("ping.c");
end Do_Ping_Spg;
subprogram Ping_Spg
features
Data_Sink : in parameter Simple_Type;
properties
source_language => C;
source_name => "user_ping_spg";
source_text => ("ping.c");
end Ping_Spg;
-------------
-- Threads --
-------------
thread P
features
Data_Source : out event data port Simple_Type;
end P;
thread implementation P.Impl
calls
Mycalls: {
P_Spg : subprogram Do_Ping_Spg;
};
connections
parameter P_Spg.Data_Source -> Data_Source;
properties
Recover_Entrypoint_Source_Text => "recover";
Dispatch_Protocol => Periodic;
Period => 1000 Ms;
Compute_Execution_time => 0 ms .. 3 ms;
Deadline => 1000 ms;
Priority => 2;
end P.Impl;
thread Q
features
Data_Sink : in event data port Simple_Type;
end Q;
thread implementation Q.Impl
calls
Mycalls: {
Q_Spg : subprogram Ping_Spg;
};
connections
parameter Data_Sink -> Q_Spg.Data_Sink;
properties
Dispatch_Protocol => Sporadic;
Period => 10 Ms;
deadline => 10 Ms;
Compute_Execution_time => 0 ms .. 3 ms;
Priority => 1;
end Q.Impl;
end Software;
PDFFIGS=imgs/assert-logo.pdf \
imgs/archi-aadl.pdf \
imgs/archi-globale.pdf
AADLMODELS= $(wildcard aadl/*.aadl)
PDFFILE=output/report.pdf
MAINTEX=report.tex
%.pdf: %.svg
inkscape --export-pdf=$@ $<
%.pdf: %.png
convert $< $@
%.pdf: %.jpg
convert $< $@
all:
mkdir -p output
$(MAKE) $(PDFFILE)
html: $(MAINTEX) $(PDFFIGS) $(AADLMODELS)
mkdir -p output/html
latex2html -dir output/html -font_size 10pt -scalable_fonts $(MAINTEX)
$(PDFFILE): $(MAINTEX) $(PDFFIGS) $(AADLMODELS)
pdflatex $(MAINTEX)
pdflatex $(MAINTEX)
mv report.pdf $(PDFFILE)
show: $(PDFFILE)
if [ `uname` = "Linux" ]; then xpdf $(PDFFILE) ; fi
if [ `uname` = "Darwin" ]; then open $(PDFFILE) ; fi
clean:
rm -f *~ *.toc *.mtc* *.out *.maf *.aux *.log
rm -rf output
AADLFILES=main.aadl \
application.aadl \
types.aadl \
devices.aadl \
buses.aadl \
protocols.aadl \
processors.aadl
parse:
ocarina -aadlv2 -f $(AADLFILES)
package application
public
with types;
subprogram pinger_spg
features
data_source : out parameter types::int.i;