libRBR  v1.2.3
RBR instrument communication API
RBRInstrument.h
Go to the documentation of this file.
1 
16 #ifndef LIBRBR_RBRINSTRUMENT_H
17 #define LIBRBR_RBRINSTRUMENT_H
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 #include <inttypes.h>
24 #include <stdbool.h>
25 #include <stdlib.h>
26 
28 
36 extern const char *RBRINSTRUMENT_LIB_NAME;
43 extern const char *RBRINSTRUMENT_LIB_VERSION;
49 extern const char *RBRINSTRUMENT_LIB_BUILD_DATE;
50 
62 #ifndef RBRINSTRUMENT_COMMAND_BUFFER_MAX
63 #define RBRINSTRUMENT_COMMAND_BUFFER_MAX 120
64 #endif
65 
78 #ifndef RBRINSTRUMENT_RESPONSE_BUFFER_MAX
79 #define RBRINSTRUMENT_RESPONSE_BUFFER_MAX 1024
80 #endif
81 
92 #ifndef RBRINSTRUMENT_CHANNEL_MAX
93 #define RBRINSTRUMENT_CHANNEL_MAX 32
94 #endif
95 
97 #define xstr(s) str(s)
98 
99 #define str(s) #s
100 
101 #define RBRINSTRUMENT_CHANNEL_MAX_LEN sizeof(xstr(RBRINSTRUMENT_CHANNEL_MAX))
102 
109 #define RBRINSTRUMENT_CHANNEL_NAME_MAX 31
110 
116 #define RBRINSTRUMENT_CHANNEL_TYPE_MAX 11
117 
123 #define RBRINSTRUMENT_CHANNEL_UNIT_MAX 7
124 
131 #define RBRINSTRUMENT_CHANNEL_LABEL_MAX 31
132 
139 #define RBRINSTRUMENT_DATETIME_MIN 946684800000LL
140 
147 #define RBRINSTRUMENT_DATETIME_MAX 4102444799000LL
148 
154 #define RBRINSTRUMENT_ID_MODEL_MAX 14
155 
161 #define RBRINSTRUMENT_ID_VERSION_MAX 7
162 
168 #define RBRINSTRUMENT_ID_MODE_MAX 10
169 
181 typedef int64_t RBRInstrumentDateTime;
182 
191 typedef int32_t RBRInstrumentPeriod;
192 
200 typedef enum RBRInstrumentError
201 {
240 
270 
280 typedef struct RBRInstrumentId
281 {
287  uint32_t serial;
289  uint16_t fwtype;
293 
296 {
308 
321 
322 struct RBRInstrument;
323 
346  const struct RBRInstrument *instrument,
347  RBRInstrumentDateTime *time);
348 
366  const struct RBRInstrument *instrument,
367  RBRInstrumentDateTime time);
368 
412  const struct RBRInstrument *instrument,
413  void *data,
414  int32_t *size);
415 
443  const struct RBRInstrument *instrument,
444  const void *const data,
445  int32_t size);
446 
447 struct RBRInstrumentSample;
448 
473  const struct RBRInstrument *instrument,
474  const struct RBRInstrumentSample *const sample);
475 
483 {
486 
489 
492 
495 
503 
511 
518 {
530 
539 
543 typedef struct RBRInstrumentResponse
544 {
577  char *response;
579 
591 typedef struct RBRInstrument
592 {
599 
606 
609 
617 
619  void *userData;
620 
623 
626 
634 
642 
651 
661 
670 
676 } RBRInstrument;
677 
759  const RBRInstrumentCallbacks *callbacks,
760  RBRInstrumentDateTime commandTimeout,
761  void *userData);
762 
774 
782  const RBRInstrument *instrument);
783 
792  const RBRInstrument *instrument);
793 
802  RBRInstrumentDateTime commandTimeout);
803 
814 void *RBRInstrument_getUserData(const RBRInstrument *instrument);
815 
823 void RBRInstrument_setUserData(RBRInstrument *instrument, void *userData);
824 
847  const RBRInstrument *instrument);
848 
884  const RBRInstrument *instrument);
885 
886 /* To help keep declarations and documentation organized and discoverable,
887  * instrument commands and structures are broken out into individual
888  * categorical headers. */
889 #include "RBRInstrumentCommands.h"
890 
891 #ifdef __cplusplus
892 }
893 #endif
894 
895 #endif /* LIBRBR_RBRINSTRUMENT_H */
RBRInstrumentSleepCallback
RBRInstrumentError(* RBRInstrumentSleepCallback)(const struct RBRInstrument *instrument, RBRInstrumentDateTime time)
Callback to suspend instrument activity for a fixed amount of time.
Definition: RBRInstrument.h:365
RBRINSTRUMENT_MISSING_CALLBACK
@ RBRINSTRUMENT_MISSING_CALLBACK
Definition: RBRInstrument.h:209
RBRInstrument
struct RBRInstrument RBRInstrument
Core library context object.
RBRInstrument::responseBuffer
uint8_t responseBuffer[RBRINSTRUMENT_RESPONSE_BUFFER_MAX]
Data received from the instrument.
Definition: RBRInstrument.h:660
RBRINSTRUMENT_UNKNOWN_GENERATION
@ RBRINSTRUMENT_UNKNOWN_GENERATION
Definition: RBRInstrument.h:306
RBRInstrument::callbacks
RBRInstrumentCallbacks callbacks
The set of callbacks to be used by the connection.
Definition: RBRInstrument.h:608
RBRInstrumentResponse::type
RBRInstrumentResponseType type
The type of this response: informational, warning, or error.
Definition: RBRInstrument.h:561
RBRInstrumentResponse::response
char * response
The response, if available.
Definition: RBRInstrument.h:577
RBRInstrument::userData
void * userData
Arbitrary user data; useful in callbacks.
Definition: RBRInstrument.h:619
RBRInstrument_getLastHardwareErrorMessage
const char * RBRInstrument_getLastHardwareErrorMessage(const RBRInstrument *instrument)
Get the error message which resulted from the last instrument command, if applicable.
RBRInstrumentResponse
A command response returned by the instrument.
Definition: RBRInstrument.h:543
RBRInstrumentHardwareError
RBRInstrumentHardwareError
Errors which can be returned by the instrument.
Definition: RBRInstrumentHardwareErrors.h:23
RBRINSTRUMENT_LOGGER3
@ RBRINSTRUMENT_LOGGER3
Definition: RBRInstrument.h:302
RBRInstrument::managedAllocation
bool managedAllocation
Whether the instance memory was dynamically allocated by the constructor.
Definition: RBRInstrument.h:675
RBRINSTRUMENT_ERROR_COUNT
@ RBRINSTRUMENT_ERROR_COUNT
Definition: RBRInstrument.h:236
RBRINSTRUMENT_RESPONSE_INFO
@ RBRINSTRUMENT_RESPONSE_INFO
Definition: RBRInstrument.h:520
RBRInstrumentGeneration
RBRInstrumentGeneration
Generations of RBR instruments.
Definition: RBRInstrument.h:295
RBRInstrumentId::serial
uint32_t serial
Definition: RBRInstrument.h:287
RBRInstrument_open
RBRInstrumentError RBRInstrument_open(RBRInstrument **instrument, const RBRInstrumentCallbacks *callbacks, RBRInstrumentDateTime commandTimeout, void *userData)
Establish a connection with an instrument and initialize the context.
RBRInstrumentDateTime
int64_t RBRInstrumentDateTime
Definition: RBRInstrument.h:181
RBRINSTRUMENT_LIB_NAME
const char * RBRINSTRUMENT_LIB_NAME
The library name.
RBRInstrumentGeneration_name
const char * RBRInstrumentGeneration_name(RBRInstrumentGeneration generation)
Get a human-readable string name for a generation.
RBRInstrumentId::mode
char mode[RBRINSTRUMENT_ID_MODE_MAX+1]
Definition: RBRInstrument.h:291
RBRINSTRUMENT_ID_MODE_MAX
#define RBRINSTRUMENT_ID_MODE_MAX
The maximum number of characters in the instrument mode.
Definition: RBRInstrument.h:168
RBRInstrumentCallbacks::time
RBRInstrumentTimeCallback time
Callback to get the current platform time in milliseconds.
Definition: RBRInstrument.h:485
RBRInstrument_setCommandTimeout
void RBRInstrument_setCommandTimeout(RBRInstrument *instrument, RBRInstrumentDateTime commandTimeout)
Set the command timeout.
RBRINSTRUMENT_TIMEOUT
@ RBRINSTRUMENT_TIMEOUT
Definition: RBRInstrument.h:213
RBRInstrument::responseBufferLength
int32_t responseBufferLength
The number of used bytes in the response buffer.
Definition: RBRInstrument.h:625
RBRInstrumentHardwareErrors.h
Instrument hardware errors.
RBRInstrumentId
struct RBRInstrumentId RBRInstrumentId
Instrument id command parameters.
RBRInstrumentId
Instrument id command parameters.
Definition: RBRInstrument.h:280
RBRInstrumentPeriod
int32_t RBRInstrumentPeriod
A periodic parameter.
Definition: RBRInstrument.h:191
RBRInstrumentResponse
struct RBRInstrumentResponse RBRInstrumentResponse
A command response returned by the instrument.
RBRINSTRUMENT_LIB_VERSION
const char * RBRINSTRUMENT_LIB_VERSION
The library version.
RBRINSTRUMENT_RESPONSE_WARNING
@ RBRINSTRUMENT_RESPONSE_WARNING
Definition: RBRInstrument.h:522
RBRInstrumentCallbacks
struct RBRInstrumentCallbacks RBRInstrumentCallbacks
A set of callbacks from library to user code.
RBRInstrumentCallbacks::write
RBRInstrumentWriteCallback write
Called to write data to the physical instrument.
Definition: RBRInstrument.h:494
RBRINSTRUMENT_RESPONSE_ERROR
@ RBRINSTRUMENT_RESPONSE_ERROR
Definition: RBRInstrument.h:524
RBRInstrument::response
RBRInstrumentResponse response
The most recent response received from the instrument.
Definition: RBRInstrument.h:669
RBRInstrumentId::model
char model[RBRINSTRUMENT_ID_MODEL_MAX+1]
Definition: RBRInstrument.h:283
RBRInstrument::commandTimeout
RBRInstrumentDateTime commandTimeout
The command timeout in milliseconds.
Definition: RBRInstrument.h:616
RBRINSTRUMENT_LOGGER1
@ RBRINSTRUMENT_LOGGER1
Definition: RBRInstrument.h:298
RBRInstrumentCallbacks
A set of callbacks from library to user code.
Definition: RBRInstrument.h:482
RBRINSTRUMENT_HARDWARE_ERROR
@ RBRINSTRUMENT_HARDWARE_ERROR
Definition: RBRInstrument.h:221
RBRINSTRUMENT_RESPONSE_TYPE_COUNT
@ RBRINSTRUMENT_RESPONSE_TYPE_COUNT
Definition: RBRInstrument.h:526
RBRInstrumentResponseType
RBRInstrumentResponseType
The types of responses returned by the instrument.
Definition: RBRInstrument.h:517
RBRInstrument_close
RBRInstrumentError RBRInstrument_close(RBRInstrument *instrument)
Terminate the instrument connection and release any held resources.
RBRInstrumentSampleCallback
RBRInstrumentError(* RBRInstrumentSampleCallback)(const struct RBRInstrument *instrument, const struct RBRInstrumentSample *const sample)
Callback to feed streaming sample data into user code.
Definition: RBRInstrument.h:472
RBRInstrumentError
RBRInstrumentError
Errors which can be returned from library functions.
Definition: RBRInstrument.h:200
RBRInstrumentWriteCallback
RBRInstrumentError(* RBRInstrumentWriteCallback)(const struct RBRInstrument *instrument, const void *const data, int32_t size)
Callback to write data to the physical instrument.
Definition: RBRInstrument.h:442
RBRInstrumentId::fwtype
uint16_t fwtype
Definition: RBRInstrument.h:289
RBRInstrument::commandBuffer
uint8_t commandBuffer[RBRINSTRUMENT_COMMAND_BUFFER_MAX]
The next command to be sent to the instrument.
Definition: RBRInstrument.h:650
RBRINSTRUMENT_RESPONSE_UNKNOWN_TYPE
@ RBRINSTRUMENT_RESPONSE_UNKNOWN_TYPE
Definition: RBRInstrument.h:528
RBRInstrumentSample
An instrument sample.
Definition: RBRInstrumentStreaming.h:492
RBRInstrument_getGeneration
RBRInstrumentGeneration RBRInstrument_getGeneration(const RBRInstrument *instrument)
Get the generation of an instrument.
RBRInstrumentId::version
char version[RBRINSTRUMENT_ID_VERSION_MAX+1]
Definition: RBRInstrument.h:285
RBRINSTRUMENT_CALLBACK_ERROR
@ RBRINSTRUMENT_CALLBACK_ERROR
Definition: RBRInstrument.h:211
RBRINSTRUMENT_ID_VERSION_MAX
#define RBRINSTRUMENT_ID_VERSION_MAX
The maximum number of characters in the instrument firmware version.
Definition: RBRInstrument.h:161
RBRInstrument_getUserData
void * RBRInstrument_getUserData(const RBRInstrument *instrument)
Get the pointer to arbitrary user data.
RBRINSTRUMENT_LIB_BUILD_DATE
const char * RBRINSTRUMENT_LIB_BUILD_DATE
The library build date.
RBRINSTRUMENT_ALLOCATION_FAILURE
@ RBRINSTRUMENT_ALLOCATION_FAILURE
Definition: RBRInstrument.h:205
RBRInstrument::lastActivityTime
RBRInstrumentDateTime lastActivityTime
The time at which instrument communication last occurred.
Definition: RBRInstrument.h:633
RBRInstrumentResponse::error
RBRInstrumentHardwareError error
The instrument warning or error number, if applicable.
Definition: RBRInstrument.h:570
RBRInstrument::commandBufferLength
int32_t commandBufferLength
The number of used bytes in the command buffer.
Definition: RBRInstrument.h:622
RBRINSTRUMENT_COMMUNICATION_ERROR
@ RBRINSTRUMENT_COMMUNICATION_ERROR
Definition: RBRInstrument.h:234
RBRInstrumentCallbacks::sleep
RBRInstrumentSleepCallback sleep
Callback to suspend activity for a fixed amount of time.
Definition: RBRInstrument.h:488
RBRInstrumentCallbacks::read
RBRInstrumentReadCallback read
Called to read data from the physical instrument.
Definition: RBRInstrument.h:491
RBRINSTRUMENT_SUCCESS
@ RBRINSTRUMENT_SUCCESS
Definition: RBRInstrument.h:203
RBRInstrument::id
struct RBRInstrumentId id
The instrument identifier.
Definition: RBRInstrument.h:598
RBRINSTRUMENT_ID_MODEL_MAX
#define RBRINSTRUMENT_ID_MODEL_MAX
The maximum number of characters in the instrument model name.
Definition: RBRInstrument.h:154
RBRInstrumentResponseType_name
const char * RBRInstrumentResponseType_name(RBRInstrumentResponseType type)
Get a human-readable string name for a response type.
RBRINSTRUMENT_SAMPLE
@ RBRINSTRUMENT_SAMPLE
Definition: RBRInstrument.h:232
RBRInstrument_setUserData
void RBRInstrument_setUserData(RBRInstrument *instrument, void *userData)
Change the arbitrary user data pointer.
RBRInstrumentCallbacks::sampleBuffer
struct RBRInstrumentSample * sampleBuffer
Where to put sample data for consumption by the sample callback.
Definition: RBRInstrument.h:509
RBRInstrument::lastResponseLength
int32_t lastResponseLength
The length in bytes of the most recent response.
Definition: RBRInstrument.h:641
RBRINSTRUMENT_COMMAND_BUFFER_MAX
#define RBRINSTRUMENT_COMMAND_BUFFER_MAX
The size of the buffer storing commands destined for the instrument.
Definition: RBRInstrument.h:63
RBRInstrumentReadCallback
RBRInstrumentError(* RBRInstrumentReadCallback)(const struct RBRInstrument *instrument, void *data, int32_t *size)
Callback to read data from the physical instrument.
Definition: RBRInstrument.h:411
RBRINSTRUMENT_BUFFER_TOO_SMALL
@ RBRINSTRUMENT_BUFFER_TOO_SMALL
Definition: RBRInstrument.h:207
RBRINSTRUMENT_UNKNOWN_ERROR
@ RBRINSTRUMENT_UNKNOWN_ERROR
Definition: RBRInstrument.h:238
RBRInstrument_getCommandTimeout
RBRInstrumentDateTime RBRInstrument_getCommandTimeout(const RBRInstrument *instrument)
Get the command timeout.
RBRINSTRUMENT_INVALID_PARAMETER_VALUE
@ RBRINSTRUMENT_INVALID_PARAMETER_VALUE
Definition: RBRInstrument.h:225
RBRInstrument_getLastHardwareError
RBRInstrumentHardwareError RBRInstrument_getLastHardwareError(const RBRInstrument *instrument)
Get the error which resulted from the last instrument command, if applicable.
RBRInstrument::generation
RBRInstrumentGeneration generation
The generation of the instrument.
Definition: RBRInstrument.h:605
RBRInstrumentCallbacks::sample
RBRInstrumentSampleCallback sample
Called when streaming sample data has been received.
Definition: RBRInstrument.h:502
RBRInstrument
Core library context object.
Definition: RBRInstrument.h:591
RBRINSTRUMENT_RESPONSE_BUFFER_MAX
#define RBRINSTRUMENT_RESPONSE_BUFFER_MAX
The size of the buffer storing instrument responses.
Definition: RBRInstrument.h:79
RBRINSTRUMENT_CHECKSUM_ERROR
@ RBRINSTRUMENT_CHECKSUM_ERROR
Definition: RBRInstrument.h:223
RBRInstrumentCommands.h
Entry point for instrument command declarations.
RBRINSTRUMENT_UNSUPPORTED
@ RBRINSTRUMENT_UNSUPPORTED
Definition: RBRInstrument.h:215
RBRINSTRUMENT_LOGGER2
@ RBRINSTRUMENT_LOGGER2
Definition: RBRInstrument.h:300
RBRINSTRUMENT_GENERATION_COUNT
@ RBRINSTRUMENT_GENERATION_COUNT
Definition: RBRInstrument.h:304
RBRInstrumentError_name
const char * RBRInstrumentError_name(RBRInstrumentError error)
Get a human-readable string name for a library error.
RBRInstrumentTimeCallback
RBRInstrumentError(* RBRInstrumentTimeCallback)(const struct RBRInstrument *instrument, RBRInstrumentDateTime *time)
Callback to get the current platform time in milliseconds.
Definition: RBRInstrument.h:345