{"id":1522,"date":"2014-01-09T15:30:06","date_gmt":"2014-01-09T14:30:06","guid":{"rendered":"http:\/\/www.objectis-software.com\/support\/?p=1522"},"modified":"2021-01-26T10:58:20","modified_gmt":"2021-01-26T09:58:20","slug":"ocf-server-ocfembeddeds-user-guide","status":"publish","type":"post","link":"https:\/\/www.objectis-software.com\/support\/ocf-server-ocfembeddeds-user-guide\/","title":{"rendered":"Ocf Server (OcfEmbedded+OcfApiServer)&#8217;s User Guide"},"content":{"rendered":"\n<p>Welcome on the Ocf Server (Ocf Embedded + OcfApiServer)&#8217;s User Guide. This post will help you to get started Ocf Server, from the installation to use instructions.<\/p>\n\n\n\n<p>You can also <a href=\"http:\/\/www.objectis-software.com\/support\/download\/user-guides\/OcfEmbedded_-_Programmer_guide_1.3.pdf\" target=\"_blank\" rel=\"noopener noreferrer\">get the PDF here<\/a>.<\/p>\n\n\n\n<p>Here is the contents:<\/p>\n\n\n\n<ol type=\"1\"><li>Introduction<\/li><li>Principles<\/li><li>Package files\n<ol type=\"1\">\n<li>Structure<\/li>\n<li>Descriptions<\/li>\n<\/ol>\n<\/li><li>Porting procedure<\/li><li>Porting file adaptation (OcfEmbeddedPort.h)\n<ol type=\"1\">\n<li>Choosing memory area<\/li>\n<li>Features enable\/disable<\/li>\n<li>Required functions<\/li>\n<\/ol>\n<\/li><li>Protocol integration\n<ol type=\"1\">\n<li>Dictionary publication<\/li>\n<\/ol>\n<\/li><li>Server protocol\n<ol type=\"1\">\n<li>Server C++\n<ol type=\"1\">\n<li>Serial server<\/li>\n<li>Dictionary publication<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li><li>Polling Example<\/li><li>RX only interrupt Example<\/li><li>RX\/TX interrupt Example<\/li><li>UDP server<\/li><li>Example<\/li><\/ol>\n\n\n\n<ul><li>Server C#\n<ol type=\"1\">\n<li>Create a server in .NET application<\/li>\n<li>Create a secure native server for .NET application (communication with AES encryption)<\/li>\n<li>Execute the Ocf server (call cyclically)<\/li>\n<\/ol>\n<\/li><\/ul>\n\n\n\n<p>Let&#8217;s begin!<\/p>\n\n\n\n<h2>1. Introduction<\/h2>\n\n\n\n<p>Ocf Server (OcfEmbedded) is necessary to use any Objectis products in order to connect your Client (it can be <a title=\"oStudio - Live Tuning\" href=\"http:\/\/www.objectis-software.com\/product\/ostudio-live-tuning-live-debugging-functional-tests\/\">oStudio &#8211; Live Tuning<\/a> or your own application). You will find bellow the basic informations to set your Server.<\/p>\n\n\n\n<h2>2. Principles<\/h2>\n\n\n\n<p>The embedded client application publishes variables and functions through helpful macros:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">\nOCFE_BEGIN(ocfEntries)\n\tOCFE_VARIABLE(VarStruct.D, OCFE_TYPE_SHORT)\n\tOCFE_VARIABLE(VarStruct.I, OCFE_TYPE_CHAR)\n\tOCFE_VARIABLE(VarBool, OCFE_TYPE_BOOL)\n\tOCFE_VARIABLE(VarShort, OCFE_TYPE_SHORT)\n\tOCFE_VARIABLE(VarInteger, OCFE_TYPE_INT)\n\tOCFE_VARIABLE(VarFloat, OCFE_TYPE_FLOAT)\n\tOCFE_VARIABLE(VarString, OCFE_TYPE_STRING)\n\tOCFE_VARIABLE_READONLY(VarChar, OCFE_TYPE_CHAR)\n\tOCFE_VARIABLE_READONLY(VarLong, OCFE_TYPE_LONG)\n\tOCFE_FUNCTION_VOID(VarFunction)\nOCFE_END\n<\/pre><\/pre>\n\n\n\n<p>After connecting the target to oStudio Live Tuning, the live debugger allows browsing of all the dictionary content and to use the variables or functions in watches, traces, etc.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"http:\/\/www.objectis-software.com\/support\/wp-content\/uploads\/2014\/01\/ocfe_principles1.jpg\"><img loading=\"lazy\" width=\"246\" height=\"312\" src=\"http:\/\/www.objectis-software.com\/support\/wp-content\/uploads\/2014\/01\/ocfe_principles1.jpg\" alt=\"ocfe_principles1\" class=\"wp-image-1538\" srcset=\"https:\/\/www.objectis-software.com\/support\/wp-content\/uploads\/2014\/01\/ocfe_principles1.jpg 246w, https:\/\/www.objectis-software.com\/support\/wp-content\/uploads\/2014\/01\/ocfe_principles1-236x300.jpg 236w\" sizes=\"(max-width: 246px) 100vw, 246px\" \/><\/a><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" width=\"594\" height=\"184\" src=\"http:\/\/www.objectis-software.com\/support\/wp-content\/uploads\/2014\/01\/ocfe_principles2.jpg\" alt=\"ocfe_principles2\" class=\"wp-image-1539\" srcset=\"https:\/\/www.objectis-software.com\/support\/wp-content\/uploads\/2014\/01\/ocfe_principles2.jpg 594w, https:\/\/www.objectis-software.com\/support\/wp-content\/uploads\/2014\/01\/ocfe_principles2-300x92.jpg 300w\" sizes=\"(max-width: 594px) 100vw, 594px\" \/><\/figure><\/div>\n\n\n\n<h2>3. Package files<\/h2>\n\n\n\n<h3>3.1 Structure<\/h3>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" width=\"733\" height=\"452\" src=\"http:\/\/www.objectis-software.com\/support\/wp-content\/uploads\/2014\/01\/ocfe_structure.jpg\" alt=\"ocfe_structure\" class=\"wp-image-1540\" srcset=\"https:\/\/www.objectis-software.com\/support\/wp-content\/uploads\/2014\/01\/ocfe_structure.jpg 733w, https:\/\/www.objectis-software.com\/support\/wp-content\/uploads\/2014\/01\/ocfe_structure-300x184.jpg 300w\" sizes=\"(max-width: 733px) 100vw, 733px\" \/><\/figure><\/div>\n\n\n\n<h3>3.2 Descriptions<\/h3>\n\n\n\n<p>The first step is to integrate the four OcfeEmbedded files into a project.<\/p>\n\n\n\n<ul><li>OcfEmbeddedPort.h (Porting file, editable to suit the platform)<\/li><li>OcfEmbedded.h (File to include in the main program file)<\/li><li>OcfEmbeddedProtocol.h (Protocol process header file)<\/li><li>OcfEmbeddedProtocol.c (Protocol process body file)<\/li><\/ul>\n\n\n\n<h2>4. Porting procedure<\/h2>\n\n\n\n<ol type=\"1\"><li>Make the protocol compile using the OcfEmbeddedPort file to adjust target specification (optional).<br>See chapter 5. : Porting file adaptation (OcfEmbeddedPort.h)<\/li><li>Program the Serial or UDP server to establish a link between the server and the client.<br>See chapter 7. : Server protocol<\/li><li>Publish variables and functions and connect oStudio Live Tuning<br>See chapter 6. : Protocol integration, which shows how to publish variables and functions<br>See <a href=\"\/support\/getting-started-with-livetuning\" data-type=\"URL\" data-id=\"\/support\/getting-started-with-livetuning\" target=\"_blank\" rel=\"noreferrer noopener\">oStudio &#8211; Live Tuning<\/a> to discover the full potential of this tool.<\/li><\/ol>\n\n\n\n<h2>5. Porting file adaptation (OcfEmbeddedPort.h)<\/h2>\n\n\n\n<p>The OcfEmbeddedPort.h porting file is in most cases ready to use. But if necessary, you can adapt the parameters of OcfEmbedded to suit your needs.<\/p>\n\n\n\n<h3>5.1 Choosing memory area<\/h3>\n\n\n\n<p>With the compilation constant OCFE_MEMORY_AREA you can choose where the OcfEmbedded protocol process data is stored.<br>If you leave it blank, the data is placed to the default memory area.<\/p>\n\n\n\n<p>Standard declaration:<\/p>\n\n\n\n<ul><li>You can let the compiler choose (most common use) :<br> <pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\"> #define OCFE_MEMORY_AREA <\/pre><\/pre> <\/li><li>You can also precise it :<br> <pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\"> #define OCFE_MEMORY_AREA __xdata <\/pre><\/pre> <p>or<\/p> <pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\"> #define OCFE_MEMORY_AREA pdata <\/pre><\/pre> <\/li><\/ul>\n\n\n\n<h3>5.2 Features enable\/disable<\/h3>\n\n\n\n<p>Several features are activated by default. But they can be disabled depending on the needs or capabilities of the processor.<br>To disable a feature, just comment it.<\/p>\n\n\n\n<ul><li> <pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\"> #define OCFE_ENABLE_FLOAT <\/pre><\/pre> <p>\u00a0<\/p>Enable float capability for the protocol. It must be activated to publish float variables.<br><p>Saves a little code memory space when disabled.<\/p> <\/li><li> <pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\"> #define OCFE_ENABLE_DOUBLE <\/pre><\/pre> <p>\u00a0<\/p> <p>Enable double capability for the protocol. It must be activated to publish double variables.<br>Saves a little code memory space when disabled.<\/p> <\/li><li> <pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\"> #define OCFE_ENABLE_STRING <\/pre><\/pre> <p>\u00a0<\/p> <p>Enable string capability for the protocol. It must be activated to publish string variables (char array).<br>Saves a little code memory space and a little data memory space when disabled.<\/p> <\/li><li> <pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\"> #define OCFE_ENABLE_FUNCTION <\/pre><\/pre> <p>\u00a0<\/p> <p>Enable function invocation for the protocol. It must be activated to publish functions.<br>Saves a little code memory space when disabled.<\/p> <\/li><li> <pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\"> #define OCFE_ENABLE_FRAME_NUMERATOR <\/pre><\/pre> <p>\u00a0<\/p> <p>Enable frame numerator security for the protocol. This activates the frame number copy for the response to the client when it is queried, and thus enhances the robustness of the protocol.<br>Saves a little data memory space when disabled.<\/p> <\/li><li> <pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\"> #define OCFE_ENABLE_CHECKSUM <\/pre><\/pre> <p>\u00a0<\/p> <p>Enable checksum control security for the protocol. This activates the checksum for the reception and the transmission of each communication, which considerably enhances the robustness of the protocol<br>Saves a little data memory space and significant processing time when disabled.<\/p> <\/li><\/ul>\n\n\n\n<h3>5.3 Required functions<\/h3>\n\n\n\n<p>Other parameters are required functions for the protocol process. Normally they are all contained in the standard libraries compilers. But if needed, you can change the functions involved and replace them with your own.<\/p>\n\n\n\n<h2>6. Protocol integration<\/h2>\n\n\n\n<h3>6.1 Dictionary publication<\/h3>\n\n\n\n<p>First you have to define the dictionary of variables and functions that you want to publish. There are six macros used to do this. Example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">\nOCFE_BEGIN(ocfEntries)\n\tOCFE_VARIABLE(VarStruct.D, OCFE_TYPE_SHORT)\n\tOCFE_VARIABLE(VarStruct.I, OCFE_TYPE_CHAR)\n\tOCFE_VARIABLE(VarBool, OCFE_TYPE_BOOL)\n\tOCFE_VARIABLE(VarShort, OCFE_TYPE_SHORT)\n\tOCFE_VARIABLE(VarInteger, OCFE_TYPE_INT)\n\tOCFE_VARIABLE(VarFloat, OCFE_TYPE_FLOAT)\n\tOCFE_VARIABLE(VarString, OCFE_TYPE_STRING)\n\tOCFE_VARIABLE_READONLY(VarChar, OCFE_TYPE_CHAR)\n\tOCFE_VARIABLE_READONLY(VarLong, OCFE_TYPE_LONG)\n\tOCFE_FUNCTION_VOID(VarFunction)\nOCFE_END\n<\/pre><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" width=\"237\" height=\"311\" src=\"http:\/\/www.objectis-software.com\/support\/wp-content\/uploads\/2014\/01\/ocfe_dictionarypublication.jpg\" alt=\"ocfe_dictionarypublication\" class=\"wp-image-1537\" srcset=\"https:\/\/www.objectis-software.com\/support\/wp-content\/uploads\/2014\/01\/ocfe_dictionarypublication.jpg 237w, https:\/\/www.objectis-software.com\/support\/wp-content\/uploads\/2014\/01\/ocfe_dictionarypublication-228x300.jpg 228w\" sizes=\"(max-width: 237px) 100vw, 237px\" \/><\/figure><\/div>\n\n\n\n<ul><li>\n<pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">\nOCFE_BEGIN(dictionaryName)\n<\/pre><\/pre>\n<p>&nbsp;<\/p>\n<p>Declaration of a dictionary with name dictionaryName. Dictionary must be declared in an area accessible by the function that will publish it.<br>NB. You can use a specific memory area placement with xdata, pdata, __idata etc. keywords if necessary. e.g.<\/p>\n<pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">OCFE_BEGIN(xdata ocfEntries)<\/pre><\/pre>\n<\/li><li>\n<pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">\nOCFE_END\n<\/pre><\/pre>\n<p>&nbsp;<\/p>\n<p>Must be placed at the end of the dictionary declaration<\/p>\n<\/li><li>\n<pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">\nOCFE_VARIABLE(variableName,  ocfeType)\n<\/pre><\/pre>\n<p>&nbsp;<\/p>\n<p>Allows the publication of a variable in read\/write mode. Specify the variable name and the ocfeType (c.f. 6.1.1 Ocfe variables type).<br>NB. The published variable must be accessible where the dictionary is declared.<\/p>\n<\/li><li>\n<pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">\nOCFE_VARIABLE_READONLY(variableName,  ocfeType)\n<\/pre><\/pre>\n<p>&nbsp;<\/p>\n<p>Allows the publication of a variable in read only mode. Specify the variable name and the ocfeType (c.f. 6.1.1 Ocfe variables type).<br>NB. The published variable must be accessible where the dictionary is declared.<\/p>\n<\/li><li>\n<pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">\nOCFE_FUNCTION_VOID(functionName)\n<\/pre><\/pre>\n<p>&nbsp;<\/p>\n<p>Allows the publication of a function with no return value to be invoked by a client (oStudio). Specify the function name.<br>NB. The published function must be accessible where the dictionary is declared.<\/p>\n<\/li><li>\n<pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">\nOCFE_FUNCTION_RET(functionName)\n<\/pre><\/pre>\n<p>&nbsp;<\/p>\n<p>Allows the publication of a function with a return value to be invoked by a client (oStudio). Specify the function name.<br>NB. The published function must be accessible where the dictionary is declared.<\/p>\n<\/li><\/ul>\n\n\n\n<h4>&nbsp;<\/h4>\n\n\n\n<h4>6.1.1 Ocfe variable type<\/h4>\n\n\n\n<p>There are several publishable types of variable. You must precise them in the dictionary declaration.<\/p>\n\n\n\n<ul><li>\n<pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">\nOCFE_TYPE_BOOL\n<\/pre><\/pre>\n<p>&nbsp;<\/p>\n<p>To publish a Boolean representation of a variable. The source variable can be a BOOL or a char variable.<\/p>\n<\/li><li>\n<pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">\nOCFE_TYPE_CHAR\n<\/pre><\/pre>\n<p>&nbsp;<\/p>\n<p>To publish a char ASCII character representation of a char variable.<\/p>\n<\/li><li>\n<pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">\nOCFE_TYPE_SHORT\n<\/pre><\/pre>\n<p>&nbsp;<\/p>\n<p>To publish a short variable.<\/p>\n<\/li><li>\n<pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">\nOCFE_TYPE_INT\n<\/pre><\/pre>\n<p>&nbsp;<\/p>\n<p>To publish a int variable.<\/p>\n<\/li><li>\n<pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">\nOCFE_TYPE_LONG\n<\/pre><\/pre>\n<p>&nbsp;<\/p>\n<p>To publish a long variable.<\/p>\n<\/li><li>\n<pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">\nOCFE_TYPE_FLOAT\n<\/pre><\/pre>\n<p>&nbsp;<\/p>\n<p>To publish a float variable.<\/p>\n<\/li><li>\n<pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">\nOCFE_TYPE_DOUBLE\n<\/pre><\/pre>\n<p>&nbsp;<\/p>\n<p>To publish a double variable.<\/p>\n<\/li><li>\n<pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">\nOCFE_TYPE_STRING\n<\/pre><\/pre>\n<p>&nbsp;<\/p>\n<p>To publish ASCII string representation of a char array variable.<\/p>\n<\/li><\/ul>\n\n\n\n<h4>6.1.2 Example of declaration<\/h4>\n\n\n\n<p>\/\/Variables declaration :<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">\nBOOL Light = TRUE;\ndouble MainVelocity = 2.12;\nlong HoursUsed = 23;\nchar Type[] = &quot;Robot X22&quot;;\nchar RobotVersion[] = &quot;V4.15&quot;;\nstruct\n{\n\tstruct\n\t{\n\t\tint X;\n\t\tdouble Y;\n\t\tlong Z;\n\t} AxisA;\n\tstruct\n\t{\n\t\tint X;\n\t\tdouble Y;\n\t\tlong Z;\n\t} AxisB;\n\tint Rotate;\n} Robot;\n\nvoid PowerEnable()\n{\n\tprintf(&quot;Power enabled\\n&quot;);\n}\n\nchar* FunctionWithReturn()\n{\n\tprintf(&quot;Function ret called correctly\\n&quot;);\n\treturn &quot;Function ret called correctly&quot;;\n}\n\n<\/pre><\/pre>\n\n\n\n<p>\/\/ Dictionary declaration:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">\nOCFE_BEGIN(ocfEntries)\n\tOCFE_VARIABLE(Light,  OCFE_TYPE_BOOL)\n\tOCFE_VARIABLE(MainVelocity, OCFE_TYPE_DOUBLE)\n\tOCFE_VARIABLE(HoursUsed, OCFE_TYPE_INT)\n\tOCFE_VARIABLE_READONLY(Type, OCFE_TYPE_STRING)\n\tOCFE_VARIABLE_READONLY(RobotVersion, OCFE_TYPE_STRING)\n\tOCFE_VARIABLE(Robot.AxisA.X, OCFE_TYPE_INT)\n\tOCFE_VARIABLE(Robot.AxisA.Y, OCFE_TYPE_DOUBLE)\n\tOCFE_VARIABLE(Robot.AxisA.Z, OCFE_TYPE_LONG)\n\tOCFE_VARIABLE_READONLY(Robot.AxisB.X, OCFE_TYPE_INT)\n\tOCFE_VARIABLE(Robot.AxisB.Y, OCFE_TYPE_DOUBLE)\n\tOCFE_VARIABLE(Robot.AxisB.Z, OCFE_TYPE_LONG)\n\tOCFE_VARIABLE(Robot.Rotate, OCFE_TYPE_INT)\n\tOCFE_FUNCTION_VOID(PowerEnable)\n\tOCFE_FUNCTION_RET(FunctionWithReturn)\nOCFE_END\n<\/pre><\/pre>\n\n\n\n<h2>7. Server protocol<\/h2>\n\n\n\n<h3>7.1 Server C++<\/h3>\n\n\n\n<h4>7.1.1 Serial server<\/h4>\n\n\n\n<p>There are two functions and one variable used for serial communication<\/p>\n\n\n\n<dl>\n<dt>\n<pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">\nOcfeStreamContext\n<\/pre><\/pre>\n<p>&nbsp;<\/p>\n<\/dt>\n<dd>Is the type that must be used to declare the context variable for serial communication.<\/dd>\n<dt>\n<pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">\nOcfeUInt16 OcfeCharacterReceived(\n                                    OcfeVariableEntry* ocfeDictionnary,\n                                    OcfeStreamContext *context,\n                                    char c);\n<\/pre><\/pre>\n<p>&nbsp;<\/p>\n<\/dt>\n<dd>When you receive a character by a serial connection, you must pass it to the Ocfe protocol with this function.\n<p>&nbsp;<\/p>\n<h5>Parameters<\/h5>\n<pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">OcfeVariableEntry* ocfeDictionnar<\/pre><\/pre>\n<p>Is the pointer to the dictionary used.<\/p>\n<pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">OcfeStreamContext *context<\/pre><\/pre>\n<p>Is the pointer to the StreamContext variable used.<\/p>\n<pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">char* c<\/pre><\/pre>\n<p>Is the received character.<\/p>\n<h5>Returns<\/h5>\n<p>A short representation of the amount of characters that are ready to be sent. You can use this value to know if the system is ready to send a response.<\/p>\n<\/dd>\n<dt>\n<pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">\nOcfeUInt16 OcfeCharacterToSend(OcfeStreamContext *context, char* c);\n<\/pre><\/pre>\n<p>&nbsp;<\/p>\n<\/dt>\n<dd>\n<h5>Parameters<\/h5>\n<p>This function is used to get the next Ocfe character to send.<\/p>\n<pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">OcfeStreamContext *context<\/pre><\/pre>\n<p>Is the pointer to the current stream context.<\/p>\n<pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">char* c<\/pre><\/pre>\n<p>Is the received character.<\/p>\n<h5>Returns<\/h5>\n<p>A short representation of the amount of characters that are ready to be sent.<\/p>\n<\/dd>\n<\/dl>\n\n\n\n<h4>7.1.2 Polling Example<\/h4>\n\n\n\n<p>This is an example in polling mode. Simply check the new received character from a serial connection and send it to the Ocf Embedded process.<br>When a character is ready to be sent by the Ocf Embedded process, it will be sent.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">\nOcfeStreamContext streamContext;\nchar c;\n\n\/\/Main loop\nvoid ReadSendOcfeCycle()\n{\n\tif(ReadChar(&amp;amp;amp;c)) \/\/Read serial character received\n\t\t\/\/Transmit character in ocfe processing\n\t\tOcfeCharacterReceived(ocfEntries, &amp;amp;amp;streamContext, c);\n\n\t\/\/Get character to send in ocfe processed buffer\n\tif(OcfeCharacterToSend(&amp;amp;amp;streamContext, &amp;amp;amp;c))\n\t\tWriteChar(c); \/\/Write next character on serial com\n\n}\n\nwhile(1)\n{\n\tApplicationCycle(); \/\/Main application process\n\tReadSendOcfeCycle(); \/\/Ocfe protocol process (non blocking)\n}\n\n<\/pre><\/pre>\n\n\n\n<h4>7.1.3 RX only interrupt Example<\/h4>\n\n\n\n<p>This is an example in half interrupt mode. When a new character is received from a serial connection it is sent to the Ocf Embedded process.<br>When a character is ready to be sent by the Ocf Embedded process, it will be sent directly from the Rx ISR handle.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">\n\/\/EUSART isr process\nvoid interrupt ISR()\n{\n\tstatic OcfeStreamContext streamContext;\n\tchar c;\n\n\tif(RXInterrupt) \/\/ Check if receive flag is set\n\t{\n\t\t\/\/Transmit character to Ocfe process\n\t\tif(OcfeCharacterReceived(ocfEntries, &amp;amp;amp;streamContext, ReceivedChar))\n\t\t{ \t\/\/while Ocfe is ready to send\n\t\t\t\/\/Get next character to send\n\t\t\twhile(OcfeCharacterToSend(&amp;amp;amp;streamContext, &amp;amp;amp;c)\n\t\t\t\tWriteChar(c); \/\/Send next character\n\t\t}\n\t}\n}\n<\/pre><\/pre>\n\n\n\n<h4>7.1.4 RX\/TX interrupt Example<\/h4>\n\n\n\n<p>This is an example in full interrupt mode. When a new character is received from a serial connection, it is sent to the Ocf Embedded process.<br>When a character is ready to be sent by the Ocf Embedded process, it will be sent directly from the Rx ISR handle. But only the first one will result in triggering Tx interrupts. The remaining characters will be sent by the Tx ISR handle.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">\n\/\/EUSART isr process\nvoid interrupt ISR()\n{\n\tstatic OcfeStreamContext streamContext;\n\tchar c;\n\n\tif(RXInterrupt) \/\/ Check if receive flag is set\n\t{\t\/\/Transmit character to Ocfe process\n\t\tif(OcfeCharacterReceived(ocfEntries, &amp;amp;amp;streamContext, RCREG))\n\t\t{   \t\/\/if Ocfe is ready to send\n\t\t\t\/\/Get first character to send\n\t\t\tOcfeCharacterToSend(&amp;amp;amp;streamContext, &amp;amp;amp;c);\n\t\t\tWriteChar(c); \/\/Send first character\n\t\t\tTxInterruptEnable = 1; \/\/ Enable TX interrupt\n\t\t}\n\t}\n\tif(TXInterrupt) \/\/ Check if transmit flag is set\n\t{\n\t\t if(OcfeCharacterToSend(&amp;amp;amp;streamContext, &amp;amp;amp;c)) \/\/if Ocfe is ready to send\n\t\t\tWriteChar(c); \/\/Send next Ocfe character\n\t\t else\n\t\t\tTxInterruptEnable = 0; \/\/ Disable TX interrupt\n\t}\n}\n<\/pre><\/pre>\n\n\n\n<h4>7.1.5 UDP server<\/h4>\n\n\n\n<p>There is only one variable and only one function used for UDP communication.<\/p>\n\n\n\n<dl>\n<dt>\n<pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">\nOcfePacketContext\n<\/pre><\/pre>\n<p>&nbsp;<\/p>\n<\/dt>\n<dd>Is the type which must be used to declare the context variable for UDP communication.\n<p>&nbsp;<\/p>\n<\/dd>\n<dt>\n<pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">\nOcfeUInt16 OcfeExecute (\n\t\t\tOcfeVariableEntry* ocfeDictionnary,\n\t\t\tOcfeContext *context,\n\t\t\tOcfeUInt16 inputDataLength);\n\n\n<\/pre><\/pre>\n<\/dt>\n<dd>\n<h5>Parameters<\/h5>\n<p>When you receive a packet from a UDP connection, you must pass it to the Ocfe protocol with this function.<\/p>\n<pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">OcfeVariableEntry* ocfeDictionnary<\/pre><\/pre>\n<p>Is the pointer to the used dictionary.<\/p>\n<pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">OcfeContext *context<\/pre><\/pre>\n<p>Is the pointer to the used PacketContext variable.<\/p>\n<pre><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">OcfeUInt16 inputDataLength<\/pre><\/pre>\n<p>Is the received characters count.<\/p>\n<h5>Returns<\/h5>\n<p>A short representation of the number of character that are ready to be sent.<\/p>\n<\/dd>\n<\/dl>\n\n\n\n<h4>7.1.6 Example<\/h4>\n\n\n\n<p>This is an example in polling mode. Simply check the new received packets from the UDP connection and send it to the Ocf Embedded process.<br>You have to directly use the buffer of packetContext (packetContext.Buffer) and fill it with the new packet received from the UDP connection.<br>When a response packet is ready to be sent by the Ocf Embedded process, it will be sent.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><pre class=\"brush: cpp; light: true; title: ; notranslate\" title=\"\">\nint count;\nOcfePacketContext packetContext;\n\nOpenUdp();\n\nwhile(1)\n{\n\t\/\/Read udp message received\n\tcount = ReadUdp(&amp;amp;amp;udpSocket, packetContext.Buffer, sizeof(OcfeBuffer))\n\t\/\/Process message\n\tcount = OcfeExecute(ocfEntries, &amp;amp;amp;packetContext, count);\n\t\/\/Send udp response\n\tsendUdp(&amp;amp;amp;packetSocket, packetContext.Buffer, count);\n}\n\nCloseSocket(&amp;amp;amp;udpSocket);\n<\/pre><\/pre>\n\n\n\n<h3>7.2 Server C#<\/h3>\n\n\n\n<h4>7.2.1 Create a server in .NET application<\/h4>\n\n\n\n<p>-&gt;TCP connexion also available<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><pre class=\"brush: csharp; light: true; title: ; notranslate\" title=\"\">\nPrototype :\npublic static OcfApiServer CreateOcfNativeUdpServer(\n\tInt32 port, object targetObject,\n\tInvocationAccess access = InvocationAccess.Public);\n\nSample :\nOcfApi.CreateOcfNativeUdpServer(10000, root, out server);\n<\/pre><\/pre>\n\n\n\n<h4>7.2.2 Create a secure native server for .NET application (communication with AES encryption)<\/h4>\n\n\n\n<p>-&gt; TCP connexion also available<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><pre class=\"brush: csharp; light: true; title: ; notranslate\" title=\"\">\nPrototype :\npublic static OcfApiServer CreateOcfNativeUdpEncryptedServer(\n   Int32 port, string passphrase, object targetObject, InvocationAccess access = InvocationAccess.Public);\n<\/pre><\/pre>\n\n\n\n<h4>7.2.2 Execute the Ocf server (call cyclically)<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><pre class=\"brush: csharp; light: true; title: ; notranslate\" title=\"\">\nPrototype :\npublic static void ExecuteOcfServer(OcfApiServer server, TimeSpan timeout = TimeSpan.FromMilliseconds(1))\n\nSample :\nfor (;;)\n   OcfApi.ExecuteOcfServer(server);\n<\/pre><\/pre>\n\n\n\n<p><br><!-- Simple Share Buttons Adder (8.4.6) simplesharebuttons.com --><div class=\"ssba-classic-2 ssba ssbp-wrap alignleft ssbp--theme-1\"><div style=\"text-align:left\"><span class=\"ssba-share-text\">Share this...<\/span><br\/><a data-site=\"facebook\" class=\"ssba_facebook_share ssba_share_link\" href=\"https:\/\/www.facebook.com\/sharer.php?t=Ocf Server (OcfEmbedded+OcfApiServer)&#8217;s User Guide&u=https:\/\/www.objectis-software.com\/support\/wp-json\/wp\/v2\/posts\/1522\"  target=_blank  style=\"color:; background-color: ; height: 48px; width: 48px; \" ><img src=\"https:\/\/www.objectis-software.com\/support\/wp-content\/plugins\/simple-share-buttons-adder\/buttons\/somacro\/facebook.png\" style=\"width: 35px;\" title=\"facebook\" class=\"ssba ssba-img\" alt=\"Share on facebook\" \/><div title=\"Facebook\" class=\"ssbp-text\">Facebook<\/div><\/a><a data-site=\"pinterest\" class=\"ssba_pinterest_share ssba_share_link\" href=\"https:\/\/pinterest.com\/pin\/create\/button\/?description=Ocf Server (OcfEmbedded+OcfApiServer)&#8217;s User Guide&media=&url=https:\/\/www.objectis-software.com\/support\/wp-json\/wp\/v2\/posts\/1522\"  target=_blank  style=\"color:; background-color: ; height: 48px; width: 48px; \" ><img src=\"https:\/\/www.objectis-software.com\/support\/wp-content\/plugins\/simple-share-buttons-adder\/buttons\/somacro\/pinterest.png\" style=\"width: 35px;\" title=\"pinterest\" class=\"ssba ssba-img\" alt=\"Share on pinterest\" \/><div title=\"Pinterest\" class=\"ssbp-text\">Pinterest<\/div><\/a><a data-site=\"twitter\" class=\"ssba_twitter_share ssba_share_link\" href=\"https:\/\/twitter.com\/intent\/tweet?text=Ocf Server (OcfEmbedded+OcfApiServer)&#8217;s User Guide&url=https:\/\/www.objectis-software.com\/support\/wp-json\/wp\/v2\/posts\/1522&via=\"  target=_blank  style=\"color:; background-color: ; height: 48px; width: 48px; \" ><img src=\"https:\/\/www.objectis-software.com\/support\/wp-content\/plugins\/simple-share-buttons-adder\/buttons\/somacro\/twitter.png\" style=\"width: 35px;\" title=\"twitter\" class=\"ssba ssba-img\" alt=\"Share on twitter\" \/><div title=\"Twitter\" class=\"ssbp-text\">Twitter<\/div><\/a><a data-site=\"linkedin\" class=\"ssba_linkedin_share ssba_share_link\" href=\"https:\/\/www.linkedin.com\/shareArticle?title=Ocf Server (OcfEmbedded+OcfApiServer)&#8217;s User Guide&url=https:\/\/www.objectis-software.com\/support\/wp-json\/wp\/v2\/posts\/1522\"  target=_blank  style=\"color:; background-color: ; height: 48px; width: 48px; \" ><img src=\"https:\/\/www.objectis-software.com\/support\/wp-content\/plugins\/simple-share-buttons-adder\/buttons\/somacro\/linkedin.png\" style=\"width: 35px;\" title=\"linkedin\" class=\"ssba ssba-img\" alt=\"Share on linkedin\" \/><div title=\"Linkedin\" class=\"ssbp-text\">Linkedin<\/div><\/a><\/div><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Welcome on the Ocf Server (Ocf Embedded + OcfApiServer)&#8217;s User Guide. This post will help you to get started Ocf Server, from the installation to use instructions. You can also get the PDF here. Here is the contents: Introduction Principles Package files Structure Descriptions Porting procedure Porting file adaptation (OcfEmbeddedPort.h) Choosing memory area Features enable\/disable Required functions Protocol integration Dictionary publication Server protocol Server C++ Serial server Dictionary publication Polling Example RX only interrupt Example RX\/TX interrupt Example UDP server Example Server C# Create a server in .NET application Create a secure native server for .NET application (communication with AES <a class=\"blog-more btn btn-xxs btn-primary\" href=\"https:\/\/www.objectis-software.com\/support\/ocf-server-ocfembeddeds-user-guide\/\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[40],"tags":[21,52,23,42,47,36],"_links":{"self":[{"href":"https:\/\/www.objectis-software.com\/support\/wp-json\/wp\/v2\/posts\/1522"}],"collection":[{"href":"https:\/\/www.objectis-software.com\/support\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.objectis-software.com\/support\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.objectis-software.com\/support\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.objectis-software.com\/support\/wp-json\/wp\/v2\/comments?post=1522"}],"version-history":[{"count":108,"href":"https:\/\/www.objectis-software.com\/support\/wp-json\/wp\/v2\/posts\/1522\/revisions"}],"predecessor-version":[{"id":2085,"href":"https:\/\/www.objectis-software.com\/support\/wp-json\/wp\/v2\/posts\/1522\/revisions\/2085"}],"wp:attachment":[{"href":"https:\/\/www.objectis-software.com\/support\/wp-json\/wp\/v2\/media?parent=1522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.objectis-software.com\/support\/wp-json\/wp\/v2\/categories?post=1522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.objectis-software.com\/support\/wp-json\/wp\/v2\/tags?post=1522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}