|
SELKIELogger
1.0.0
|

Files | |
| file | MPSerial.h |
| file | MPTypes.h |
Macros | |
| #define | MP_SERIAL_BUFF 4096 |
| Default serial buffer allocation size. | |
| #define | MP_SYNC_BYTE1 0x94 |
| MP Serial synchronisation byte 1. More... | |
| #define | MP_SYNC_BYTE2 0x55 |
| MP Serial synchronisation byte 2. More... | |
Typedefs | |
| typedef msg_t | mp_message_t |
| Internal representation of SELKIE logger messages. More... | |
Functions | |
| int | mp_openConnection (const char *port, const int baudRate) |
| Set up a connection to the specified port. More... | |
| void | mp_closeConnection (int handle) |
| Close existing connection. More... | |
| bool | mp_readMessage (int handle, msg_t *out) |
| Static wrapper around mp_readMessage_buf. More... | |
| bool | mp_readMessage_buf (int handle, msg_t *out, uint8_t buf[MP_SERIAL_BUFF], int *index, int *hw) |
| Read data from handle, and parse message if able. More... | |
| bool | mp_packMessage (msgpack_sbuffer *sbuf, const msg_t *out) |
| Pack a message into a buffer. More... | |
| bool | mp_writeMessage (int handle, const msg_t *out) |
| Send message to attached device. More... | |
| bool | mp_writeData (int handle, const msg_t *out) |
| Send message data (only!) to attached device. More... | |
| void | mp_pack_strarray (msgpack_packer *pack, const strarray *sa) |
| Pack string array. More... | |
| void | mp_pack_numarray (msgpack_packer *pack, const size_t entries, const float *fa) |
| Pack numeric/floating point array. More... | |
| bool | mp_unpack_strarray (strarray *sa, msgpack_object_array *obj) |
| Unpack msgpack array into string array. More... | |
| size_t | mp_unpack_numarray (float **sa, msgpack_object_array *obj) |
| Allocate array of floats and unpack a msgpack array into it. More... | |
Support for internal message pack based data format, including support for serial devices and data files
| #define MP_SYNC_BYTE1 0x94 |
| #define MP_SYNC_BYTE2 0x55 |
| typedef msg_t mp_message_t |
Internal representation of SELKIE logger messages.
All messages are MessagePacked arrays with 4 elements. First element is fixed integer 0x55 Second element is a source ID (0-127) Third element is a channel ID (0-127) Fourth element is source specific data, which can be:
These elements are the same as the members of the msg_t type defined in base/messages.h, with the addition of the initial sync byte.
The use of the initial sync byte and fixed length array provide a two byte signature (0x94 0x55) that can be used to identify message boundaries.
There is no checksumming of transmitted messages under this scheme.
| void mp_closeConnection | ( | int | handle | ) |
Close existing connection.
Currently just closes the file descriptor passed as handle
| [in] | handle | File descriptor opened with mp_openConnection() |
Definition at line 52 of file MPSerial.c.
| int mp_openConnection | ( | const char * | port, |
| const int | baudRate | ||
| ) |
Set up a connection to the specified port.
Currently just wraps openSerialConnection()
| [in] | port | Target character device (i.e. Serial port) |
| [in] | baudRate | Target baud rate |
Definition at line 43 of file MPSerial.c.
| void mp_pack_numarray | ( | msgpack_packer * | pack, |
| const size_t | entries, | ||
| const float * | fa | ||
| ) |
Pack numeric/floating point array.
Helper function for mp_packMessage()
Packs float array into supplied msgpack_packer object
| [in] | pack | Pointer to msgpack packer object - must already be initialised |
| [in] | entries | Number of entries in array |
| [in] | fa | Pointer to float array to be packed |
Definition at line 466 of file MPSerial.c.
| void mp_pack_strarray | ( | msgpack_packer * | pack, |
| const strarray * | sa | ||
| ) |
Pack string array.
Helper function for mp_packMessage()
Packs string array into supplied msgpack_packer object
| [in] | pack | Pointer to msgpack packer object - must already be initialised |
| [in] | sa | Pointer to string array to be packed |
Definition at line 446 of file MPSerial.c.
| bool mp_packMessage | ( | msgpack_sbuffer * | sbuf, |
| const msg_t * | out | ||
| ) |
Pack a message into a buffer.
Pack a message into the provided buffer, ready for writing. The buffer is initialised by this function, and destroyed on error.
Caller is responsible for destroying buffer after use
| [out] | sbuf | msgpack_sbuffer to write into |
| [in] | out | Message to pack into buffer |
Definition at line 330 of file MPSerial.c.
| bool mp_readMessage | ( | int | handle, |
| msg_t * | out | ||
| ) |
Static wrapper around mp_readMessage_buf.
For single threaded development and testing, uses static variables rather than requiring state to be tracked by caller.
See mp_readMessage_buf() for full description.
| [in] | handle | File descriptor from mp_openConnection() |
| [out] | out | Pointer to message structure to fill with data |
Definition at line 66 of file MPSerial.c.
| bool mp_readMessage_buf | ( | int | handle, |
| msg_t * | out, | ||
| uint8_t | buf[MP_SERIAL_BUFF], | ||
| int * | index, | ||
| int * | hw | ||
| ) |
Read data from handle, and parse message if able.
This function maintains a message buffer (allocated by the caller), filling it from the file handle provided. This handle can be anything supported by read(), but would usually be a file or a serial port.
The index (current search position) and hw (high water / end of valid data) values are also provided by the caller, but will be updated by this function.
If a valid message is found then it is written to the structure provided as a parameter and the function returns true.
If a message cannot be read, the function returns false and the float value field is set to an error value:
| [in] | handle | File descriptor from mp_openConnection() |
| [out] | out | Pointer to message structure to fill with data |
| [in,out] | buf | Serial data buffer |
| [in,out] | index | Current search position within buf |
| [in,out] | hw | End of current valid data in buf |
Definition at line 101 of file MPSerial.c.
| size_t mp_unpack_numarray | ( | float ** | fa, |
| msgpack_object_array * | obj | ||
| ) |
Allocate array of floats and unpack a msgpack array into it.
Helper function for mp_readMessage_buf()
Unpacks a msgpack_object_array into an array of floats, provided all msgpack_objects are strings.
| [out] | fa | Pointer to float pointer (will be set to base address of array) |
| [in] | obj | MessagePacked array |
Definition at line 514 of file MPSerial.c.
| bool mp_unpack_strarray | ( | strarray * | sa, |
| msgpack_object_array * | obj | ||
| ) |
Unpack msgpack array into string array.
Helper function for mp_readMessage_buf()
Unpacks a msgpack_object_array into a string array, provided all msgpack_objects are strings.
| [in] | sa | Pointer to string array to be updated |
| [in] | obj | MessagePacked array |
Definition at line 483 of file MPSerial.c.
| bool mp_writeData | ( | int | handle, |
| const msg_t * | out | ||
| ) |
Send message data (only!) to attached device.
Extract message data and writes it (unformatted) to a file descriptor
| [in] | handle | File descriptor from mp_openConnection() |
| [in] | out | Pointer to message structure containing data to be extracted. |
handle Definition at line 397 of file MPSerial.c.
| bool mp_writeMessage | ( | int | handle, |
| const msg_t * | out | ||
| ) |
Send message to attached device.
Packs message using mp_packMessage and writes it to a file descriptor
| [in] | handle | File descriptor from mp_openConnection() |
| [in] | out | Pointer to message structure to be sent. |
handle Definition at line 382 of file MPSerial.c.