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

xbusparser.c File Reference

xbusparser.c File Reference

Go to the source code of this file.

Enumerations

enum  XbusParserState {
  XBPS_Preamble, XBPS_BusId, XBPS_MessageId, XBPS_Length,
  XBPS_ExtendedLengthMsb, XBPS_ExtendedLengthLsb, XBPS_Payload, XBPS_Checksum
}
 

XbusParser states.

More...

Functions

size_t XbusParser_mem (void)
 Get the amount of memory needed for the XbusParser structure.
struct XbusParser * XbusParser_create (struct XbusParserCallback const *callback)
 Create a new XbusParser object.
void XbusParser_destroy (struct XbusParser *parser)
 Frees an XbusParser structure allocated by XbusParser_create().
struct XbusParser * XbusParser_init (void *parserMem, struct XbusParserCallback const *callback)
 Initializes an XbusParser in the passed memory location.
static void parseDeviceId (struct XbusParser *parser, uint8_t const *rawData)
 Parse an XMID_DeviceId message to extract the device ID value.
static void parseOutputConfig (struct XbusParser *parser, uint8_t const *rawData)
 Parse an XMID_OutputConfig message.
static void parseMessagePayload (struct XbusParser *parser)
 Converts raw Xbus payload data to native structures if possible.
void prepareForPayload (struct XbusParser *parser)
 Prepare for receiving a message payload.
void XbusParser_parseByte (struct XbusParser *parser, const uint8_t byte)
 Parse a byte of data from a motion tracker.
void XbusParser_parseBuffer (struct XbusParser *parser, uint8_t const *buf, size_t bufSize)
 Parse a buffer of data received from a motion tracker.

Detailed Description

Copyright (C) Xsens Technologies B.V., 2015.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Definition in file xbusparser.c.


Enumeration Type Documentation

XbusParser states.

Enumerator:
XBPS_Preamble 

Looking for preamble.

XBPS_BusId 

Waiting for bus ID.

XBPS_MessageId 

Waiting for message ID.

XBPS_Length 

Waiting for length.

XBPS_ExtendedLengthMsb 

Waiting for extended length MSB.

XBPS_ExtendedLengthLsb 

Waiting for extended length LSB.

XBPS_Payload 

Reading payload.

XBPS_Checksum 

Waiting for checksum.

Definition at line 25 of file xbusparser.c.


Function Documentation

static void parseDeviceId ( struct XbusParser *  parser,
uint8_t const *  rawData 
) [static]

Parse an XMID_DeviceId message to extract the device ID value.

Replaces the raw Xbus message data with the device ID.

Definition at line 111 of file xbusparser.c.

static void parseMessagePayload ( struct XbusParser *  parser ) [static]

Converts raw Xbus payload data to native structures if possible.

Raw data payloads are converted to native data structures and the message data pointer is changed to point to the native structure. The raw data is automatically deallocated.

Definition at line 161 of file xbusparser.c.

static void parseOutputConfig ( struct XbusParser *  parser,
uint8_t const *  rawData 
) [static]

Parse an XMID_OutputConfig message.

Replaces the raw Xbus message data with an array of OutputConfiguration structures.

Definition at line 132 of file xbusparser.c.

void prepareForPayload ( struct XbusParser *  parser )

Prepare for receiving a message payload.

Requests a memory area to store the received data to using the registered callbacks.

Definition at line 189 of file xbusparser.c.

struct XbusParser* XbusParser_create ( struct XbusParserCallback const *  callback ) [read]

Create a new XbusParser object.

Parameters:
callbackPointer to callback structure containing callback functions for memory management and handling received messages.
Returns:
Pointer the new XbusParser structure.

Uses malloc to allocate the memory required for the parser.

Definition at line 70 of file xbusparser.c.

void XbusParser_destroy ( struct XbusParser *  parser )

Frees an XbusParser structure allocated by XbusParser_create().

Definition at line 83 of file xbusparser.c.

struct XbusParser* XbusParser_init ( void *  parserMem,
struct XbusParserCallback const *  callback 
) [read]

Initializes an XbusParser in the passed memory location.

Parameters:
parserMemPointer to memory to use for storing parser state. Should be at least as big as the value returned by XbusParser_mem().
callbackPointer to callback structure containing callback functions for memory management and handling received messages.
Returns:
Initialized XbusParser structure.

Definition at line 96 of file xbusparser.c.

size_t XbusParser_mem ( void   )

Get the amount of memory needed for the XbusParser structure.

Definition at line 57 of file xbusparser.c.

void XbusParser_parseBuffer ( struct XbusParser *  parser,
uint8_t const *  buf,
size_t  bufSize 
)

Parse a buffer of data received from a motion tracker.

Definition at line 290 of file xbusparser.c.

void XbusParser_parseByte ( struct XbusParser *  parser,
const uint8_t  byte 
)

Parse a byte of data from a motion tracker.

When a complete message is received the user will be notified by a call to the handleMessage() callback function.

Definition at line 201 of file xbusparser.c.