Basic implementation of Xbus message parsing and generation for embedded processors. The code has no dependencies and should also work for other MCU architectures than ARM provided a C99 compiler is available.

Dependents:   MTi-1_example_LPC1768 MTi-1_rikbeun MTi-1_example MTi-1_example

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers xbusparser.h Source File

xbusparser.h

Go to the documentation of this file.
00001 /*!
00002  * \file
00003  * \copyright Copyright (C) Xsens Technologies B.V., 2015.
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
00006  * use this file except in compliance with the License. You may obtain a copy
00007  * of the License at
00008  *
00009  * http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00013  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
00014  * License for the specific language governing permissions and limitations
00015  * under the License.
00016  */
00017 
00018 #ifndef __XBUSPARSER_H
00019 #define __XBUSPARSER_H
00020 
00021 #include <stddef.h>
00022 #include <stdint.h>
00023 #include "xbusmessage.h "
00024 
00025 #ifdef __cplusplus
00026 extern "C" {
00027 #endif
00028 
00029 struct XbusParser;
00030 
00031 /*!
00032  * \brief Callback function structure for use with the XbusParser.
00033  */
00034 struct XbusParserCallback
00035 {
00036     /*!
00037      * \brief Allocate a buffer for message reception.
00038      * \param bufSize The size of the buffer to allocate.
00039      * \returns Pointer to buffer to use for message reception, or NULL if
00040      * a buffer cannot be allocated.
00041      *
00042      * \note It is the resposibility of the user to deallocate the message
00043      * data buffers pointed to by XbusMessage structures passed to the
00044      * handleMessage() callback function.
00045      */
00046     void* (*allocateBuffer)(size_t bufSize);
00047 
00048     /*!
00049      * \brief Deallocate a buffer that was previously allocated by a call to
00050      * allocateBuffer.
00051      */
00052     void (*deallocateBuffer)(void const* buffer);
00053 
00054     /*!
00055      * \brief Handle a received message.
00056      *
00057      * \note If the passed XbusMessage structure has a non-null data pointer
00058      * then it is the responsibility of the user to free this once handling
00059      * of the message is complete.
00060      */
00061     void (*handleMessage)(struct XbusMessage const* message);
00062 };
00063 
00064 size_t XbusParser_mem(void);
00065 struct XbusParser* XbusParser_create(struct XbusParserCallback const* callback);
00066 void XbusParser_destroy(struct XbusParser* parser);
00067 struct XbusParser* XbusParser_init(void* parserMem, struct XbusParserCallback const* callback);
00068 
00069 void XbusParser_parseByte(struct XbusParser* parser, uint8_t byte);
00070 void XbusParser_parseBuffer(struct XbusParser* parser, uint8_t const* buf, size_t bufSize);
00071 
00072 #ifdef __cplusplus
00073 }
00074 #endif // extern "C"
00075 
00076 #endif // __XBUSPARSER_H