Skip to content

Commit

Permalink
start adding discovery functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
kcl93 committed May 6, 2021
1 parent 2adbd1e commit 0c0a5fb
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 29 deletions.
7 changes: 7 additions & 0 deletions src/muComBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,11 @@ int8_t muComBase::linkFunction(uint8_t index, muComFunc function)



#ifndef MUCOM_DEACTIVATE_DISCOVERY
int8_t muComBase::_linkVariable(uint8_t index, uint8_t *var, uint8_t size, muCom_LinkedVariableType type)
#else
int8_t muComBase::linkVariable(uint8_t index, uint8_t *var, uint8_t size)
#endif
{
if(index >= this->_linked_var_num)
{
Expand All @@ -214,6 +218,9 @@ int8_t muComBase::linkVariable(uint8_t index, uint8_t *var, uint8_t size)

this->_linked_var[index].addr = var;
this->_linked_var[index].size = size;
#ifndef MUCOM_DEACTIVATE_DISCOVERY
this->_linked_var[index].type = type;
#endif

return MUCOM_OK;
}
Expand Down
123 changes: 94 additions & 29 deletions src/muComBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
//Deactivate for improved performance and slightly redused flash usage at own risk
//#define MUCOM_DEACTIVATE_THREADLOCK

//Optional define to remove support for discovery of linked variables and functions
//Deactivating this functionality can be used in a closed system after debugging to save flash and RAM
//#define MUCOM_DEACTIVATE_DISCOVERY

//Defines for the return values of the muCom interface functions
#define MUCOM_OK 0 //!< OK. No error.
#define MUCOM_ERR -1 //!< Misc. error!
Expand All @@ -39,6 +43,25 @@
#define MUCOM_EXECUTE_REQUEST 0x60


/**
\brief Standard variable constants that can be linked via MUCOM
*/
enum muCom_LinkedVariableType : uint8_t
{
MUCOM_INT8 = 0,
MUCOM_INT16 = 1,
MUCOM_INT32 = 2,
MUCOM_INT64 = 3,
MUCOM_UINT8 = 4,
MUCOM_UINT16 = 5,
MUCOM_UINT32 = 6,
MUCOM_UINT64 = 7,
MUCOM_FLOAT = 8,
MUCOM_DOUBLE = 9,
MUCOM_ARRAY = 10
};


/**
\brief Function prototype for functions that can be invoked by the muCom interface
*/
Expand All @@ -52,6 +75,9 @@ struct muCom_LinkedVariable_str
{
uint8_t* addr;
uint8_t size;
#ifndef MUCOM_DEACTIVATE_DISCOVERY
muCom_LinkedVariableType type;
#endif
};


Expand Down Expand Up @@ -98,6 +124,10 @@ class muComBase
//Internal function to enable interrupts
virtual void _enableInterrupts(void) = 0;

#ifndef MUCOM_DEACTIVATE_DISCOVERY
int8_t _linkVariable(uint8_t index, uint8_t *var, uint8_t size, muCom_LinkedVariableType type);
#endif


public:
/**
Expand Down Expand Up @@ -150,37 +180,72 @@ class muComBase
\param[in] size Size of the variable/buffer in bytes (only neccessary when linking buffers)
\return MUCOM_OK if all is alright
*/
int8_t linkVariable(uint8_t index, uint8_t *var, uint8_t size);

inline int8_t linkVariable(uint8_t index, uint8_t *var)
{ return this->linkVariable(index, (uint8_t*)var, sizeof(uint8_t)); }
#ifndef MUCOM_DEACTIVATE_DISCOVERY
inline int8_t linkVariable(uint8_t index, uint8_t *var, uint8_t size)
{ return this->_linkVariable(index, var, size, MUCOM_ARRAY); }

inline int8_t linkVariable(uint8_t index, int8_t *var)
{ return this->linkVariable(index, (uint8_t*)var, sizeof(int8_t)); }

inline int8_t linkVariable(uint8_t index, uint16_t *var)
{ return this->linkVariable(index, (uint8_t*)var, sizeof(uint16_t)); }

inline int8_t linkVariable(uint8_t index, int16_t *var)
{ return this->linkVariable(index, (uint8_t*)var, sizeof(int16_t)); }

inline int8_t linkVariable(uint8_t index, uint32_t *var)
{ return this->linkVariable(index, (uint8_t*)var, sizeof(uint32_t)); }

inline int8_t linkVariable(uint8_t index, int32_t *var)
{ return this->linkVariable(index, (uint8_t*)var, sizeof(int32_t)); }

inline int8_t linkVariable(uint8_t index, uint64_t *var)
{ return this->linkVariable(index, (uint8_t*)var, sizeof(uint64_t)); }

inline int8_t linkVariable(uint8_t index, int64_t *var)
{ return this->linkVariable(index, (uint8_t*)var, sizeof(int64_t)); }

inline int8_t linkVariable(uint8_t index, float *var)
{ return this->linkVariable(index, (uint8_t*)var, sizeof(float)); }
inline int8_t linkVariable(uint8_t index, uint8_t *var)
{ return this->_linkVariable(index, (uint8_t*)var, sizeof(uint8_t), MUCOM_UINT8); }

inline int8_t linkVariable(uint8_t index, int8_t *var)
{ return this->_linkVariable(index, (uint8_t*)var, sizeof(int8_t), MUCOM_INT8); }

inline int8_t linkVariable(uint8_t index, uint16_t *var)
{ return this->_linkVariable(index, (uint8_t*)var, sizeof(uint16_t), MUCOM_UINT16); }

inline int8_t linkVariable(uint8_t index, int16_t *var)
{ return this->_linkVariable(index, (uint8_t*)var, sizeof(int16_t), MUCOM_INT16); }

inline int8_t linkVariable(uint8_t index, uint32_t *var)
{ return this->_linkVariable(index, (uint8_t*)var, sizeof(uint32_t), MUCOM_UINT32); }

inline int8_t linkVariable(uint8_t index, int32_t *var)
{ return this->_linkVariable(index, (uint8_t*)var, sizeof(int32_t), MUCOM_INT32); }

inline int8_t linkVariable(uint8_t index, uint64_t *var)
{ return this->_linkVariable(index, (uint8_t*)var, sizeof(uint64_t), MUCOM_UINT64); }

inline int8_t linkVariable(uint8_t index, int64_t *var)
{ return this->_linkVariable(index, (uint8_t*)var, sizeof(int64_t), MUCOM_INT64); }

inline int8_t linkVariable(uint8_t index, float *var)
{ return this->_linkVariable(index, (uint8_t*)var, sizeof(float), MUCOM_FLOAT); }

inline int8_t linkVariable(uint8_t index, double *var)
{ return this->_linkVariable(index, (uint8_t*)var, sizeof(double), MUCOM_DOUBLE); }
#else
int8_t linkVariable(uint8_t index, uint8_t *var, uint8_t size)

inline int8_t linkVariable(uint8_t index, uint8_t *var)
{ return this->linkVariable(index, (uint8_t*)var, sizeof(uint8_t)); }

inline int8_t linkVariable(uint8_t index, int8_t *var)
{ return this->linkVariable(index, (uint8_t*)var, sizeof(int8_t)); }

inline int8_t linkVariable(uint8_t index, uint16_t *var)
{ return this->linkVariable(index, (uint8_t*)var, sizeof(uint16_t)); }

inline int8_t linkVariable(uint8_t index, int16_t *var)
{ return this->linkVariable(index, (uint8_t*)var, sizeof(int16_t)); }

inline int8_t linkVariable(uint8_t index, uint32_t *var)
{ return this->linkVariable(index, (uint8_t*)var, sizeof(uint32_t)); }

inline int8_t linkVariable(uint8_t index, int32_t *var)
{ return this->linkVariable(index, (uint8_t*)var, sizeof(int32_t)); }

inline int8_t linkVariable(uint8_t index, uint64_t *var)
{ return this->linkVariable(index, (uint8_t*)var, sizeof(uint64_t)); }

inline int8_t linkVariable(uint8_t index, int64_t *var)
{ return this->linkVariable(index, (uint8_t*)var, sizeof(int64_t)); }

inline int8_t linkVariable(uint8_t index, double *var)
{ return this->linkVariable(index, (uint8_t*)var, sizeof(double)); }
inline int8_t linkVariable(uint8_t index, float *var)
{ return this->linkVariable(index, (uint8_t*)var, sizeof(float)); }

inline int8_t linkVariable(uint8_t index, double *var)
{ return this->linkVariable(index, (uint8_t*)var, sizeof(double)); }
#endif

/**
\brief Invoke a function at the communication partner
Expand Down

0 comments on commit 0c0a5fb

Please sign in to comment.