SELKIELogger  1.0.0
MPSerial.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Swansea University
3  *
4  * This file is part of the SELKIELogger suite of tools.
5  *
6  * SELKIELogger is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the Free
8  * Software Foundation, either version 3 of the License, or (at your option)
9  * any later version.
10  *
11  * SELKIELogger is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this SELKIELogger product.
18  * If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef SELKIELoggerMP_Serial
22 #define SELKIELoggerMP_Serial
23 
29 #include "SELKIELoggerBase.h"
30 
31 #include <msgpack.h>
32 
38 #include "MPTypes.h"
39 
41 #define MP_SERIAL_BUFF 4096
42 
44 int mp_openConnection(const char *port, const int baudRate);
45 
47 void mp_closeConnection(int handle);
48 
50 bool mp_readMessage(int handle, msg_t *out);
51 
53 bool mp_readMessage_buf(int handle, msg_t *out, uint8_t buf[MP_SERIAL_BUFF], int *index, int *hw);
54 
56 bool mp_packMessage(msgpack_sbuffer *sbuf, const msg_t *out);
57 
59 bool mp_writeMessage(int handle, const msg_t *out);
60 
62 bool mp_writeData(int handle, const msg_t *out);
63 
65 void mp_pack_strarray(msgpack_packer *pack, const strarray *sa);
66 
68 void mp_pack_numarray(msgpack_packer *pack, const size_t entries, const float *fa);
69 
71 bool mp_unpack_strarray(strarray *sa, msgpack_object_array *obj);
72 
74 size_t mp_unpack_numarray(float **sa, msgpack_object_array *obj);
76 #endif
void mp_pack_numarray(msgpack_packer *pack, const size_t entries, const float *fa)
Pack numeric/floating point array.
Definition: MPSerial.c:466
void mp_pack_strarray(msgpack_packer *pack, const strarray *sa)
Pack string array.
Definition: MPSerial.c:446
int mp_openConnection(const char *port, const int baudRate)
Set up a connection to the specified port.
Definition: MPSerial.c:43
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.
Definition: MPSerial.c:101
bool mp_readMessage(int handle, msg_t *out)
Static wrapper around mp_readMessage_buf.
Definition: MPSerial.c:66
bool mp_unpack_strarray(strarray *sa, msgpack_object_array *obj)
Unpack msgpack array into string array.
Definition: MPSerial.c:483
#define MP_SERIAL_BUFF
Default serial buffer allocation size.
Definition: MPSerial.h:41
void mp_closeConnection(int handle)
Close existing connection.
Definition: MPSerial.c:52
bool mp_writeData(int handle, const msg_t *out)
Send message data (only!) to attached device.
Definition: MPSerial.c:397
bool mp_packMessage(msgpack_sbuffer *sbuf, const msg_t *out)
Pack a message into a buffer.
Definition: MPSerial.c:330
bool mp_writeMessage(int handle, const msg_t *out)
Send message to attached device.
Definition: MPSerial.c:382
size_t mp_unpack_numarray(float **sa, msgpack_object_array *obj)
Allocate array of floats and unpack a msgpack array into it.
Definition: MPSerial.c:514
Queuable message.
Definition: messages.h:71
Array of strings.
Definition: strarray.h:43