SELKIELogger  1.0.0
LPMSConnection.h File Reference
#include <stdbool.h>
#include "SELKIELoggerBase.h"
#include "LPMSTypes.h"
Include dependency graph for LPMSConnection.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define LPMS_BUFF   1024
 Default serial buffer allocation size.
 

Functions

int lpms_openConnection (const char *device, const int baud)
 Open connection to an LPMS serial device. More...
 
void lpms_closeConnection (int handle)
 Close LPMS serial connection. More...
 
bool lpms_readMessage (int handle, lpms_message *out)
 Static wrapper around lpms_readMessage_buf. More...
 
bool lpms_readMessage_buf (int handle, lpms_message *out, uint8_t buf[LPMS_BUFF], size_t *index, size_t *hw)
 Read data from handle, and parse message if able. More...
 
bool lpms_find_messages (int handle, size_t numtypes, const uint8_t types[], int timeout, lpms_message *out, uint8_t buf[LPMS_BUFF], size_t *index, size_t *hw)
 Read data from handle until first of specified message types is found. More...
 
bool lpms_send_command (const int handle, lpms_message *m)
 Write command defined by structure to handle.
 
bool lpms_send_command_mode (const int handle)
 Shortcut: Send LPMS_MSG_MODE_CMD.
 
bool lpms_send_stream_mode (const int handle)
 Shortcut: Send LPMS_MSG_MODE_STREAM.
 
bool lpms_send_get_config (const int handle)
 Shortcut: Send LPMS_MSG_GET_OUTPUTS.
 

Detailed Description

LPMS connection handling

Definition in file LPMSConnection.h.

Function Documentation

◆ lpms_closeConnection()

void lpms_closeConnection ( int  handle)

Close LPMS serial connection.

Parameters
[in]handleFile handle from lpms_openConnection()

Definition at line 48 of file LPMSConnection.c.

◆ lpms_find_messages()

bool lpms_find_messages ( int  handle,
size_t  numtypes,
const uint8_t  types[],
int  timeout,
lpms_message out,
uint8_t  buf[LPMS_BUFF],
size_t *  index,
size_t *  hw 
)

Read data from handle until first of specified message types is found.

Read messages from serial data and discard them until a message matching one of the provided types is seen, or a timeout is reached.

Uses lpms_readMessage_buf() internally, and can make use of the same buffer if the same buf, index, and hw parameters are passed in.

Parameters
[in]handleFile descriptor from lpms_openConnection()
[in]numtypesNumber of entries in types[]
[in]typesArray of message/commands to match.
See also
LPMS Message types
Parameters
[in]timeoutNumber of seconds to wait for matching message
[out]outPointer to message structure to fill with data
[in,out]bufSerial data buffer
[in,out]indexCurrent search position within buf
[in,out]hwEnd of current valid data in buf
Returns
True if a matching message type was found, false otherwise.

Definition at line 157 of file LPMSConnection.c.

◆ lpms_openConnection()

int lpms_openConnection ( const char *  device,
const int  baud 
)

Open connection to an LPMS serial device.

Delegates to openSerialConnection() to open the serial device.

Parameters
[in]devicePath to device to open
[in]baudBaud rate to connect with (as integer)
Returns
Status of openSerialConnection() call

Definition at line 40 of file LPMSConnection.c.

◆ lpms_readMessage()

bool lpms_readMessage ( int  handle,
lpms_message out 
)

Static wrapper around lpms_readMessage_buf.

For single threaded development and testing, uses static variables rather than requiring state to be tracked by caller.

See lpms_readMessage_buf() for full description.

Parameters
[in]handleFile descriptor from lpms_openConnection()
[out]outPointer to message structure to fill with data
Returns
True if out now contains a valid message, false otherwise.

Definition at line 63 of file LPMSConnection.c.

◆ lpms_readMessage_buf()

bool lpms_readMessage_buf ( int  handle,
lpms_message out,
uint8_t  buf[LPMS_BUFF],
size_t *  index,
size_t *  hw 
)

Read data from handle, and parse message if able.

Pulls data from handle and stores it in buf, tracking the current search position in index and the current fill level/buffer high water mark in hw

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

Parameters
[in]handleFile descriptor from lpms_openConnection()
[out]outPointer to message structure to fill with data
[in,out]bufSerial data buffer
[in,out]indexCurrent search position within buf
[in,out]hwEnd of current valid data in buf
Returns
True if out now contains a valid message, false otherwise.

Definition at line 87 of file LPMSConnection.c.