Dafocus logo a&apm;b logo

The generations process and examples

The diagram below summarizes how Encodix works. Several advanced features and details are hidden for simplicity.

Picture 2

N.Description
1 Encodix users write the messages description files.
These files are expressed by using a specific formal syntax which resembles ETSI specification documents: this makes really easy to write and maintain message description files.
In this way, all messages and information elements are specified down to bit-level detail.

In this example, we declare a simple GSM-04.07 message:

gsm-0407 MY_MESSAGE {
	ProtocolDiscriminator = 0101;  
	MessageType           = 1X001101;    
	4- foo    M  TV     1  integer;      /* 4 bit integer */  
	23 bar    O  TLV    3  MY_SUB_FIELD; /* see below */
}

/* Custom sub field */

bit-field MY_SUB_FIELD {
	size: 1 octet;  
	bits 1-5 partA integer;  
	bits 6-8 partB integer;
}
2 Encodix is an executable which reads the messages description file (1).
It produces some .h and .c files (.pr files if SDL output is activated).
3 The data structure file is a .h file generated by Encodix (2) which contains one C typedef per each message and information element defined in the messages description file (1).
This file contains user-friendly, abstract structured data types which are completely unrelated to their encoding format.For the example above, it generates:

typedef struct _c_MY_SUB_FIELD {
	int partA;
	int partB;
} c_MY_SUB_FIELD;

typedef struct _c_MY_MESSAGE {
	int foo;
	c_MY_SUB_FIELD bar;
	ED_BOOLEAN bar_Present;
} c_MY_MESSAGE;
4 Encodix (2) generates an encoding C function per each message.
Each function of these receives a pointer to a structure (3) and a pointer to a buffer (6).
After the execution of one of these functions, the contents of the input structure will be encoded in the output binary buffer which will be ready to be used.
For MY_MESSAGE, it generates:

long ENCODE_c_MY_MESSAGE (char* Buffer, const c_MY_MESSAGE* Source);
5 Encodix (2) generates an decoding C function per each message.
Each function of these receives a pointer to a structure (3) and a pointer to a buffer (6). After the execution of one of these functions, the contents of the input structure will be filled with the values decoded from the input binary buffer.
For MY_MESSAGE, it generates:

long DECODE_c_MY_MESSAGE (const char* Buffer, c_MY_MESSAGE* Destin, long Length);
6 A char buffer must be provided when encoding and decoding in order to store the encoded version. See the examples below and above.
7/8 Once code is generated, users can encode messages.
In this example we need to encode an instance of "MY_MESSAGE" by setting "foo" to 2 and writing into "bar.partA" value 3 and "bar.partB" value 4:

char Buffer [50];
c_MY_MESSAGE myMsg;
long LenInBits;
myMsg.foo = 2;
myMsg.bar.partA = 3;
myMsg.bar.partB = 4;
myMsg.bar_Present = ED_TRUE; 

/* Optional field: mark it as present! */
LenInBits = ENCODE_c_MY_MESSAGE (Buffer, &myMsg);

/* Now "LenInBits" contains the length of the
encoded message expressed in bits. Buffer
contains an encoded message */
We had to specify only sensible data, without having care of writing protocol discriminator, skip indicator, information elements tags and lenghts and bit alignments: all these tasks are performed by the Encodix generated function.
9/10 Same thing happens when we need to decode.
In this example we need to decode a buffer containing an instance of "MY_MESSAGE":

/* Buffer is a const char* containing the message */
/* Len is a long containing the buffer length from the layer below */
c_MY_MESSAGE myMsg;
DECODE_c_MY_MESSAGE (Buffer, &myMsg, Length);
/* Now myMsg contains the decoded data: use it somehow */
printf ("foo is %d\n", myMsg.foo);

Encodix description... >>>
The CSN.1 module... >>>
The Access module... >>>
The generations process and examples... >>>