29 static int _varIdsMax = 0;
30 static int _firstFree = _UNDEFINED;
31 static int _blobSize = 2;
32 static int _varCount = 0;
36 static int find(int32_t varId)
40 for (i = 0; i < _varIdsMax; ++i)
42 if (_varIds[i] == varId)
return i;
43 if (_varIds[i] == _FREE_ENTRY && _firstFree == _UNDEFINED) _firstFree = i;
46 if(_firstFree == _UNDEFINED && _varIdsMax <
MON_MAX_VARS) {
47 _firstFree = _varIdsMax;
55 logTrace(
"Subscribe variable %08x with rate %d", varId, rate);
62 if (pos == _UNDEFINED) {
66 if (_firstFree != _UNDEFINED && ( _blobSize + s ) <=
MON_MAX_BLOB) {
67 _varIds[_firstFree] = varId;
68 _rates[_firstFree] = rate;
69 _firstFree = _UNDEFINED;
87 for (i = 0; i < count; ++i)
99 if (pos == _UNDEFINED)
return;
101 _varIds[pos] = _FREE_ENTRY;
103 if (_firstFree == _UNDEFINED || _firstFree > pos) _firstFree = pos;
107 void monUnsubscribe(int32_t * varIds,
int count)
110 for (i = 0; i < count; ++i)
123 logTrace(
"Configured rate: %d", rate);
129 uint8_t * varCountPtr = buffer->
cur;
132 for (i = offset; i < _varIdsMax; ++i)
134 if (_varIds[i] == _FREE_ENTRY)
continue;
136 if (rate < _rates[i])
continue;
138 logTrace(
"Variable %08x rate %d", _varIds[i], _rates[i]);
142 if (
dbFree(buffer) < 4 + size) {
144 buffer->
cur = varCountPtr;
152 if (!
xsReadDB(_varIds[i], buffer))
return -1;
155 buffer->
cur = varCountPtr;
bool monSubscribeVars(int32_t *varIds, int count, int rate)
Subscribe to array of variables.
#define MON_MAX_VARS
Maximum number of variables which can be monitored.
bool dbWriteI32(DataBuffer *buf, int32_t i)
Writes an 32 bits signed integer.
#define E_NOTFOUND
Generic error: not found (ID or resource.
static int vidVarSize(int varID)
Returns the total size of the variable.
bool xsVarExists(int varID)
Returns whether or not the specified variable exists.
Defines a DataBuffer structure.
#define E_INVARGUMENT
Generic error: invalid argument.
static uint32_t dbFree(DataBuffer *buf)
Returns the number of bytes still free in the buffer.
bool monSubscribeVar(int32_t varId, int rate)
Subscribe to a variable.
void monUnsubscribeVar(int32_t varId)
Unsubscribe to a variable.
Manages the global system error.
bool xsReadDB(int varID, DataBuffer *target)
Reads variable into target data buffer from variable structure.
#define E_OUTOFMEMORY
Generic error: There is no more memory.
This module is responsible for distributing error codes.
#define LOG_DEF(NAME,...)
Define a logger for a module.
int monUpdate(DataBuffer *buffer, int offset, int rate)
Write update variable information into the specified buffer.
The monitor module is responsible for sending variables to the remote party based on subscription...
#define MON_MAX_BLOB
Maximim blob size.
static bool vidIsReadable(int varID)
Checks if a variable is readable.
bool errSet(uint32_t code, const char *error, const char *name)
Sets an error.
Implements a generic logger facility.
Access provides 'introspective' access to process variables.
uint8_t * cur
Current Pointer.
Defines the variable ID format.
bool dbWriteU16(DataBuffer *buf, uint16_t u)
Writes a unsigned short (16 bits unsigned) integer.