Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F60528638
syncvar.h
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Apr 30, 21:24
Size
1 KB
Mime Type
text/x-c++
Expires
Thu, May 2, 21:24 (2 d)
Engine
blob
Format
Raw Data
Handle
17368118
Attached To
R2671 HHRI-software
syncvar.h
View Options
#ifndef SYNCVAR_H
#define SYNCVAR_H
#include <stdexcept>
#include <QString>
#include <QList>
#include "../../Firmware/src/definitions.h"
typedef comm_VarType VarType;
typedef comm_VarAccess VarAccess;
/**
* @addtogroup HriBoardLib
* @{
*/
/**
* @brief Variable that can be synchronized with its HRI board counterpart.
*/
class SyncVarBase
{
public:
SyncVarBase(int index, QString name, VarAccess access,
uint8_t* data, int size);
virtual ~SyncVarBase() = default;
int getIndex() const;
QString getName() const;
int getSize() const;
VarAccess getAccess() const;
QByteArray getData() const;
void setData(QByteArray newData);
bool isUpToDate() const;
void setOutOfDate();
virtual double toDouble() const = 0;
virtual void fromDouble(double value) = 0;
private:
int index; ///< Index of the SyncVar in the list.
QString name; ///< Name describing the SyncVar.
VarAccess access; ///< Access rights of the variable.
bool upToDate; ///< Indicates whether the local value is up-to-date or not.
uint8_t *const data;
const int size;
};
template<typename T>
class SyncVar : public SyncVarBase
{
public:
SyncVar(int index, QString name, VarAccess access, int varSize) :
SyncVarBase(index, name, access, (uint8_t*)&value, varSize)
{
}
~SyncVar() = default;
void setLocalValue(T value)
{
this->value = value;
}
T getLocalValue()
{
return value;
}
double toDouble() const override
{
return (double)value;
}
void fromDouble(double value) override
{
this->value = (T)value;
}
protected:
T value;
};
SyncVarBase* makeSyncVar(VarType type, int index, QString name,
VarAccess access);
/**
* @}
*/
#endif // SYNCVAR_H
Event Timeline
Log In to Comment