Skip to content

Commit

Permalink
Merge pull request #173 from sparkfun/feature/arm-port-part1
Browse files Browse the repository at this point in the history
Feature/arm port part1
  • Loading branch information
gigapod authored Nov 13, 2024
2 parents fa64bba + ba90f48 commit 5f20268
Show file tree
Hide file tree
Showing 45 changed files with 539 additions and 138 deletions.
1 change: 1 addition & 0 deletions src/core/flux_base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ flux_sdk_add_source_files(
flxCore.h
flxCoreDevice.cpp
flxCoreDevice.h
flxDeviceValueTypes.h
flxCoreEvent.h
flxCoreEvent.cpp
flxCoreEventID.h
Expand Down
1 change: 1 addition & 0 deletions src/core/flux_base/flxCoreLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <WString.h>
#include <map>
#include <stdarg.h>
#include <stdexcept>
#include <vector>

#include "flxCoreEventID.h"
Expand Down
86 changes: 82 additions & 4 deletions src/core/flux_base/flxCoreParam.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,43 @@
#include "flxCoreTypes.h"
#include "flxUtils.h"

// Define a type used to enumerate parameter value types (not data types, but values, like temp, accel)

typedef uint16_t flxParamValueType_t;

const flxParamValueType_t kParamValueNone = 0;

//----------------------------------------------------------------------------------------
// flxParameter
//
// Base/Core Parameter Class
//
// From an abstract sense, a basic parameter - nothing more

//
class flxParameter : public flxDescriptor
{
bool _isEnabled;
flxParamValueType_t _valueType;

public:
flxParameter() : _isEnabled{true} {};
flxParameter() : _isEnabled{true}, _valueType{kParamValueNone}
{
}

bool enabled(void)
{
return _isEnabled;
}

flxParamValueType_t valueType(void)
{
return _valueType;
}
void setValueType(flxParamValueType_t type)
{
_valueType = type;
}

virtual void setEnabled(bool enabled)
{
_isEnabled = enabled;
Expand Down Expand Up @@ -292,6 +310,14 @@ class _flxParameterOut : public _flxDataOut<T>, public flxParameterOutScalar
(*this)(obj, name);
}

void operator()(Object *obj, const char *name, const char *desc, flxParamValueType_t vtype)
{
// Value type
setValueType(vtype);

// cascade to other version of method
(*this)(obj, name, desc);
}
// override to deal with dirty status of object.
void setEnabled(bool bEnabled)
{
Expand Down Expand Up @@ -488,6 +514,14 @@ class flxParameterOutString : public flxParameterOutScalar, public _flxDataOutSt
(*this)(obj, name);
}

void operator()(Object *obj, const char *name, const char *desc, flxParamValueType_t vtype)
{
// Value type
setValueType(vtype);

// cascade to other version of method
(*this)(obj, name, desc);
}
// override to deal with dirty status of object.
void setEnabled(bool bEnabled)
{
Expand Down Expand Up @@ -641,6 +675,14 @@ class flxParameterOutArrayType : public flxParameterOutArray
(*this)(obj, name);
}

void operator()(Object *obj, const char *name, const char *desc, flxParamValueType_t vtype)
{
// Value type
setValueType(vtype);

// cascade to other version of method
(*this)(obj, name, desc);
}
// override to deal with dirty status of object.
void setEnabled(bool bEnabled)
{
Expand Down Expand Up @@ -805,7 +847,14 @@ class flxParameterOutArrayString : public flxParameterOutArray
// cascade to other version of method
(*this)(obj, name);
}
void operator()(Object *obj, const char *name, const char *desc, flxParamValueType_t vtype)
{
// Value type
setValueType(vtype);

// cascade to other version of method
(*this)(obj, name, desc);
}
// override to deal with dirty status of object.
void setEnabled(bool bEnabled)
{
Expand Down Expand Up @@ -913,6 +962,14 @@ class _flxParameterIn : public flxParameterIn, public _flxDataIn<T>
(*this)(obj, name);
}

void operator()(Object *obj, const char *name, const char *desc, flxParamValueType_t vtype)
{
// Value type
setValueType(vtype);

// cascade to other version of method
(*this)(obj, name, desc);
}
//---------------------------------------------------------------------------------
void set(T const &value)
{
Expand Down Expand Up @@ -1063,6 +1120,14 @@ class flxParameterInString : public flxParameterIn, _flxDataInString
(*this)(obj, name);
}

void operator()(Object *obj, const char *name, const char *desc, flxParamValueType_t vtype)
{
// Value type
setValueType(vtype);

// cascade to other version of method
(*this)(obj, name, desc);
}
//---------------------------------------------------------------------------------
void set(std::string const &value)
{
Expand Down Expand Up @@ -1188,6 +1253,15 @@ template <class Object, void (Object::*_setter)()> class flxParameterInVoid : pu
(*this)(obj, name);
}

void operator()(Object *obj, const char *name, const char *desc, flxParamValueType_t vtype)
{
// Value type
setValueType(vtype);

// cascade to other version of method
(*this)(obj, name, desc);
}

//---------------------------------------------------------------------------------
void set()
{
Expand Down Expand Up @@ -1229,9 +1303,10 @@ template <class Object, void (Object::*_setter)()> class flxParameterInVoid : pu

// Use some macro magic to determine which actual call to make based on the number of passed in
// parameters..
#define _spGetRegAttributeMacro(_1, _2, _3, _NAME_, ...) _NAME_
#define _spGetRegAttributeMacro(_1, _2, _3, _4, _NAME_, ...) _NAME_
#define flxRegister(...) \
_spGetRegAttributeMacro(__VA_ARGS__, flxRegisterDesc, flxRegisterName, flxRegisterObj)(__VA_ARGS__)
_spGetRegAttributeMacro(__VA_ARGS__, flxRegisterValueType, flxRegisterDesc, flxRegisterName, \
flxRegisterObj)(__VA_ARGS__)

#define flxRegisterObj(_obj_name_) _obj_name_(this, #_obj_name_)

Expand All @@ -1241,6 +1316,9 @@ template <class Object, void (Object::*_setter)()> class flxParameterInVoid : pu
// User provided Name and description
#define flxRegisterDesc(_obj_name_, _name_, _desc_) _obj_name_(this, _name_, _desc_)

// For parameters - user provided value type
#define flxRegisterValueType(_obj_name_, _name_, _desc_, _type_) _obj_name_(this, _name_, _desc_, _type_)

// Define a object type that supports parameter lists (input and output)
class flxOperation : public flxObject, public _flxParameterContainer
{
Expand Down
63 changes: 42 additions & 21 deletions src/core/flux_base/flxCoreProps.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,22 +250,26 @@ class _flxPropertyBase : public flxProperty, public _flxDataIn<T>, public _flxDa
{

public:
_flxPropertyBase() : _isHidden{HIDDEN}, _isSecure{SECURE}
_flxPropertyBase() : _flags{0}
{
if (HIDDEN)
setHidden();
if (SECURE)
_flags |= kIsSecure;
}

bool hidden()
{
return _isHidden;
return (_flags & kIsHidden == kIsHidden);
}
// Add a method that allows the property to be hidden if public
void setHidden(void)
{
_isHidden = true;
_flags |= kIsHidden;
}
bool secure()
{
return _isSecure;
return (_flags & kIsSecure == kIsSecure);
}
//---------------------------------------------------------------------------------
flxDataType_t type()
Expand Down Expand Up @@ -299,7 +303,7 @@ class _flxPropertyBase : public flxProperty, public _flxDataIn<T>, public _flxDa
bool status = true;

// We don't save hidden or secure properties if this is an external source
if (stBlk->kind() == flxStorage::flxStorageKindInternal || (!_isHidden && !_isSecure))
if (stBlk->kind() == flxStorage::flxStorageKindInternal || (!hidden() && !secure()))
{
T c = get();
bool status = stBlk->write(name(), c);
Expand Down Expand Up @@ -382,8 +386,10 @@ class _flxPropertyBase : public flxProperty, public _flxDataIn<T>, public _flxDa
}

private:
bool _isHidden;
bool _isSecure;
static constexpr const uint8_t kIsHidden = 0x1;
static constexpr const uint8_t kIsSecure = 0x2;

uint8_t _flags;
};

//----------------------------------------------------------------------------------------
Expand All @@ -402,22 +408,26 @@ class _flxPropertyBaseString : public flxProperty, _flxDataInString, _flxDataOut
flxDataLimitType<std::string> *_dataLimit;

public:
_flxPropertyBaseString() : _dataLimit{nullptr}, _isHidden{HIDDEN}, _isSecure{SECURE}
_flxPropertyBaseString() : _dataLimit{nullptr}, _flags{0}
{
if (HIDDEN)
setHidden();
if (SECURE)
_flags |= kIsSecure;
}

bool hidden()
{
return _isHidden;
return (_flags & kIsHidden == kIsHidden);
}
// Add a method that allows the property to be hidden if public
void setHidden(void)
{
_isHidden = true;
_flags |= kIsHidden;
}
bool secure()
{
return _isSecure;
return (_flags & kIsSecure == kIsSecure);
}

flxDataType_t type()
Expand Down Expand Up @@ -466,17 +476,17 @@ class _flxPropertyBaseString : public flxProperty, _flxDataInString, _flxDataOut

// If this is a secure string and storage is internal, the strings are stored
// encrypted
if (stBlk->kind() == flxStorage::flxStorageKindInternal && _isSecure)
if (stBlk->kind() == flxStorage::flxStorageKindInternal && secure())
return stBlk->saveSecureString(name(), get().c_str());

// If we are saving to an external source, we don't save hidden values or secure values.
// But, for secure props, we to write the key and a blank string (makes it easier to enter values)

// We don't save hidden or secure properties if this is an external source
if (stBlk->kind() == flxStorage::flxStorageKindInternal || !_isHidden)
if (stBlk->kind() == flxStorage::flxStorageKindInternal || !hidden())
{
// if a secure property and external storage, set value to an empty string
std::string c = (stBlk->kind() == flxStorage::flxStorageKindExternal && _isSecure) ? "" : get();
std::string c = (stBlk->kind() == flxStorage::flxStorageKindExternal && secure()) ? "" : get();

status = stBlk->writeString(name(), c.c_str());
if (!status)
Expand All @@ -491,7 +501,7 @@ class _flxPropertyBaseString : public flxProperty, _flxDataInString, _flxDataOut
size_t len;

// Secure string?
if (stBlk->kind() == flxStorage::flxStorageKindInternal && _isSecure)
if (stBlk->kind() == flxStorage::flxStorageKindInternal && secure())
{
// get buffer length. Note, add one to make sure we have room for line termination
len = stBlk->getBytesLength(name()) + 1;
Expand Down Expand Up @@ -565,8 +575,10 @@ class _flxPropertyBaseString : public flxProperty, _flxDataInString, _flxDataOut
};

private:
bool _isHidden;
bool _isSecure;
static constexpr const uint8_t kIsHidden = 0x1;
static constexpr const uint8_t kIsSecure = 0x2;

uint8_t _flags;
};

//----------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -636,7 +648,7 @@ class _flxPropertyTypedRW : public _flxPropertyBase<T, HIDDEN, SECURE>
void operator()(Object *obj, bool skipAdd = false)
{
// my_object must be derived from _flxPropertyContainer
static_assert(std::is_base_of<_flxPropertyContainer, Object>::value, "TypedRW: invalid object");
// static_assert(std::is_base_of<_flxPropertyContainer, Object>::value, "TypedRW: invalid object");

my_object = obj;
assert(my_object);
Expand Down Expand Up @@ -676,6 +688,9 @@ class _flxPropertyTypedRW : public _flxPropertyBase<T, HIDDEN, SECURE>
{
if (!my_object) // would normally throw an exception, but not very Arduino like!
{
if (_hasInitial)
return _initialValue;

flxLogM_E(kMsgParentObjNotSet, "property");
return (T)0;
}
Expand All @@ -687,8 +702,10 @@ class _flxPropertyTypedRW : public _flxPropertyBase<T, HIDDEN, SECURE>
{
if (!my_object)
{
flxLogM_E(kMsgParentObjNotSet, "property");
return; // would normally throw an exception, but not very Arduino like!
// cache the value until we are connected to the containing object
_hasInitial = true;
_initialValue = value;
return;
}

(my_object->*_setter)(value);
Expand Down Expand Up @@ -1291,6 +1308,8 @@ class flxPropertyRWString : public _flxPropertyBaseString<HIDDEN, SECURE>
{
if (!my_object)
{
if (_hasInitial)
return _initialValue;
flxLogM_E(kMsgParentObjNotSet, "property");
return "";
}
Expand All @@ -1303,7 +1322,9 @@ class flxPropertyRWString : public _flxPropertyBaseString<HIDDEN, SECURE>
{
if (!my_object)
{
flxLogM_E(kMsgParentObjNotSet, "property");
_hasInitial = true;
_initialValue = value;

return;
}

Expand Down
4 changes: 3 additions & 1 deletion src/core/flux_base/flxCoreTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <string>
#include <type_traits>
#include <vector>
#include <stdexcept>

#include "flxCoreLog.h"
#include "flxUtils.h"
Expand Down Expand Up @@ -283,6 +282,9 @@ enum flxDataType_t : std::uint8_t
flxTypeDouble = 0x28,
flxTypeString = 0x21
};
const flxDataType_t flxDataTypeArray[] = {flxTypeNone, flxTypeBool, flxTypeInt8, flxTypeUInt8,
flxTypeInt16, flxTypeUInt16, flxTypeInt32, flxTypeUInt32,
flxTypeFloat, flxTypeDouble, flxTypeString};

/*******************************************************************************
* @brief A constexpr function that returns the flxDataType_t value for a given type.
Expand Down
1 change: 1 addition & 0 deletions src/core/flux_base/flxDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <vector>

#include "flxCoreDevice.h"
#include "flxDeviceValueTypes.h"
#include "flxFlux.h"

//----------------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 5f20268

Please sign in to comment.