Removed support for profile handling in parameter groups.
This commit is contained in:
parent
2e4184dc6d
commit
774cae215c
|
@ -38,10 +38,7 @@ static uint16_t eepromConfigSize;
|
|||
|
||||
typedef enum {
|
||||
CR_CLASSICATION_SYSTEM = 0,
|
||||
CR_CLASSICATION_PROFILE1 = 1,
|
||||
CR_CLASSICATION_PROFILE2 = 2,
|
||||
CR_CLASSICATION_PROFILE3 = 3,
|
||||
CR_CLASSICATION_PROFILE_LAST = CR_CLASSICATION_PROFILE3,
|
||||
CR_CLASSICATION_PROFILE_LAST = CR_CLASSICATION_SYSTEM,
|
||||
} configRecordFlags_e;
|
||||
|
||||
#define CR_CLASSIFICATION_MASK (0x3)
|
||||
|
@ -178,23 +175,12 @@ static const configRecord_t *findEEPROM(const pgRegistry_t *reg, configRecordFla
|
|||
bool loadEEPROM(void)
|
||||
{
|
||||
PG_FOREACH(reg) {
|
||||
configRecordFlags_e cls_start, cls_end;
|
||||
if (pgIsSystem(reg)) {
|
||||
cls_start = CR_CLASSICATION_SYSTEM;
|
||||
cls_end = CR_CLASSICATION_SYSTEM;
|
||||
} else {
|
||||
cls_start = CR_CLASSICATION_PROFILE1;
|
||||
cls_end = CR_CLASSICATION_PROFILE_LAST;
|
||||
}
|
||||
for (configRecordFlags_e cls = cls_start; cls <= cls_end; cls++) {
|
||||
int profileIndex = cls - cls_start;
|
||||
const configRecord_t *rec = findEEPROM(reg, cls);
|
||||
const configRecord_t *rec = findEEPROM(reg, CR_CLASSICATION_SYSTEM);
|
||||
if (rec) {
|
||||
// config from EEPROM is available, use it to initialize PG. pgLoad will handle version mismatch
|
||||
pgLoad(reg, profileIndex, rec->pg, rec->size - offsetof(configRecord_t, pg), rec->version);
|
||||
pgLoad(reg, rec->pg, rec->size - offsetof(configRecord_t, pg), rec->version);
|
||||
} else {
|
||||
pgReset(reg, profileIndex);
|
||||
}
|
||||
pgReset(reg);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -225,25 +211,11 @@ static bool writeSettingsToEEPROM(void)
|
|||
.flags = 0
|
||||
};
|
||||
|
||||
if (pgIsSystem(reg)) {
|
||||
// write the only instance
|
||||
record.flags |= CR_CLASSICATION_SYSTEM;
|
||||
config_streamer_write(&streamer, (uint8_t *)&record, sizeof(record));
|
||||
crc = crc16_ccitt_update(crc, (uint8_t *)&record, sizeof(record));
|
||||
config_streamer_write(&streamer, reg->address, regSize);
|
||||
crc = crc16_ccitt_update(crc, reg->address, regSize);
|
||||
} else {
|
||||
// write one instance for each profile
|
||||
for (uint8_t profileIndex = 0; profileIndex < PG_PROFILE_COUNT; profileIndex++) {
|
||||
record.flags = 0;
|
||||
record.flags |= ((profileIndex + 1) & CR_CLASSIFICATION_MASK);
|
||||
config_streamer_write(&streamer, (uint8_t *)&record, sizeof(record));
|
||||
crc = crc16_ccitt_update(crc, (uint8_t *)&record, sizeof(record));
|
||||
const uint8_t *address = reg->address + (regSize * profileIndex);
|
||||
config_streamer_write(&streamer, address, regSize);
|
||||
crc = crc16_ccitt_update(crc, address, regSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
configFooter_t footer = {
|
||||
|
|
|
@ -34,15 +34,9 @@ const pgRegistry_t* pgFind(pgn_t pgn)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static uint8_t *pgOffset(const pgRegistry_t* reg, uint8_t profileIndex)
|
||||
static uint8_t *pgOffset(const pgRegistry_t* reg)
|
||||
{
|
||||
const uint16_t regSize = pgSize(reg);
|
||||
|
||||
uint8_t *base = reg->address;
|
||||
if (!pgIsSystem(reg)) {
|
||||
base += (regSize * profileIndex);
|
||||
}
|
||||
return base;
|
||||
return reg->address;
|
||||
}
|
||||
|
||||
static void pgResetInstance(const pgRegistry_t *reg, uint8_t *base)
|
||||
|
@ -59,18 +53,9 @@ static void pgResetInstance(const pgRegistry_t *reg, uint8_t *base)
|
|||
}
|
||||
}
|
||||
|
||||
void pgReset(const pgRegistry_t* reg, int profileIndex)
|
||||
void pgReset(const pgRegistry_t* reg)
|
||||
{
|
||||
pgResetInstance(reg, pgOffset(reg, profileIndex));
|
||||
}
|
||||
|
||||
void pgResetCurrent(const pgRegistry_t *reg)
|
||||
{
|
||||
if (pgIsSystem(reg)) {
|
||||
pgResetInstance(reg, reg->address);
|
||||
} else {
|
||||
pgResetInstance(reg, *reg->ptr);
|
||||
}
|
||||
pgResetInstance(reg, pgOffset(reg));
|
||||
}
|
||||
|
||||
bool pgResetCopy(void *copy, pgn_t pgn)
|
||||
|
@ -83,44 +68,26 @@ bool pgResetCopy(void *copy, pgn_t pgn)
|
|||
return false;
|
||||
}
|
||||
|
||||
void pgLoad(const pgRegistry_t* reg, int profileIndex, const void *from, int size, int version)
|
||||
void pgLoad(const pgRegistry_t* reg, const void *from, int size, int version)
|
||||
{
|
||||
pgResetInstance(reg, pgOffset(reg, profileIndex));
|
||||
pgResetInstance(reg, pgOffset(reg));
|
||||
// restore only matching version, keep defaults otherwise
|
||||
if (version == pgVersion(reg)) {
|
||||
const int take = MIN(size, pgSize(reg));
|
||||
memcpy(pgOffset(reg, profileIndex), from, take);
|
||||
memcpy(pgOffset(reg), from, take);
|
||||
}
|
||||
}
|
||||
|
||||
int pgStore(const pgRegistry_t* reg, void *to, int size, uint8_t profileIndex)
|
||||
int pgStore(const pgRegistry_t* reg, void *to, int size)
|
||||
{
|
||||
const int take = MIN(size, pgSize(reg));
|
||||
memcpy(to, pgOffset(reg, profileIndex), take);
|
||||
memcpy(to, pgOffset(reg), take);
|
||||
return take;
|
||||
}
|
||||
|
||||
|
||||
void pgResetAll(int profileCount)
|
||||
void pgResetAll()
|
||||
{
|
||||
PG_FOREACH(reg) {
|
||||
if (pgIsSystem(reg)) {
|
||||
pgReset(reg, 0);
|
||||
} else {
|
||||
// reset one instance for each profile
|
||||
for (int profileIndex = 0; profileIndex < profileCount; profileIndex++) {
|
||||
pgReset(reg, profileIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void pgActivateProfile(int profileIndex)
|
||||
{
|
||||
PG_FOREACH(reg) {
|
||||
if (!pgIsSystem(reg)) {
|
||||
uint8_t *ptr = pgOffset(reg, profileIndex);
|
||||
*(reg->ptr) = ptr;
|
||||
}
|
||||
pgReset(reg);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,14 +34,9 @@ typedef enum {
|
|||
PGR_PGN_MASK = 0x0fff,
|
||||
PGR_PGN_VERSION_MASK = 0xf000,
|
||||
PGR_SIZE_MASK = 0x0fff,
|
||||
PGR_SIZE_SYSTEM_FLAG = 0x0000, // documentary
|
||||
PGR_SIZE_PROFILE_FLAG = 0x8000 // start using flags from the top bit down
|
||||
PGR_SIZE_SYSTEM_FLAG = 0x0000 // documentary
|
||||
} pgRegistryInternal_e;
|
||||
|
||||
enum {
|
||||
PG_PROFILE_COUNT = 3
|
||||
};
|
||||
|
||||
// function that resets a single parameter group instance
|
||||
typedef void (pgResetFunc)(void * /* base */, int /* size */);
|
||||
|
||||
|
@ -60,8 +55,6 @@ typedef struct pgRegistry_s {
|
|||
static inline uint16_t pgN(const pgRegistry_t* reg) {return reg->pgn & PGR_PGN_MASK;}
|
||||
static inline uint8_t pgVersion(const pgRegistry_t* reg) {return (uint8_t)(reg->pgn >> 12);}
|
||||
static inline uint16_t pgSize(const pgRegistry_t* reg) {return reg->size & PGR_SIZE_MASK;}
|
||||
static inline uint16_t pgIsSystem(const pgRegistry_t* reg) {return (reg->size & PGR_SIZE_PROFILE_FLAG) == 0;}
|
||||
static inline uint16_t pgIsProfile(const pgRegistry_t* reg) {return (reg->size & PGR_SIZE_PROFILE_FLAG) == PGR_SIZE_PROFILE_FLAG;}
|
||||
|
||||
#define PG_PACKED __attribute__((packed))
|
||||
|
||||
|
@ -89,19 +82,11 @@ extern const uint8_t __pg_resetdata_end[];
|
|||
#define PG_FOREACH(_name) \
|
||||
for (const pgRegistry_t *(_name) = __pg_registry_start; (_name) < __pg_registry_end; _name++)
|
||||
|
||||
#define PG_FOREACH_PROFILE(_name) \
|
||||
PG_FOREACH(_name) \
|
||||
if(pgIsSystem(_name)) \
|
||||
continue; \
|
||||
else \
|
||||
/**/
|
||||
|
||||
// Reset configuration to default (by name)
|
||||
// Only current profile is reset for profile based configs
|
||||
#define PG_RESET_CURRENT(_name) \
|
||||
#define PG_RESET(_name) \
|
||||
do { \
|
||||
extern const pgRegistry_t _name ##_Registry; \
|
||||
pgResetCurrent(&_name ## _Registry); \
|
||||
pgReset(&_name ## _Registry); \
|
||||
} while(0) \
|
||||
/**/
|
||||
|
||||
|
@ -124,15 +109,6 @@ extern const uint8_t __pg_resetdata_end[];
|
|||
struct _dummy \
|
||||
/**/
|
||||
|
||||
// Declare profile config
|
||||
#define PG_DECLARE_PROFILE(_type, _name) \
|
||||
extern _type *_name ## _ProfileCurrent; \
|
||||
static inline const _type* _name(void) { return _name ## _ProfileCurrent; } \
|
||||
static inline _type* _name ## Mutable(void) { return _name ## _ProfileCurrent; } \
|
||||
struct _dummy \
|
||||
/**/
|
||||
|
||||
|
||||
// Register system config
|
||||
#define PG_REGISTER_I(_type, _name, _pgn, _version, _reset) \
|
||||
_type _name ## _System; \
|
||||
|
@ -195,43 +171,6 @@ extern const uint8_t __pg_resetdata_end[];
|
|||
/**/
|
||||
#endif
|
||||
|
||||
#ifdef UNIT_TEST
|
||||
# define _PG_PROFILE_CURRENT_DECL(_type, _name) \
|
||||
_type *_name ## _ProfileCurrent = &_name ## _Storage[0];
|
||||
#else
|
||||
# define _PG_PROFILE_CURRENT_DECL(_type, _name) \
|
||||
_type *_name ## _ProfileCurrent;
|
||||
#endif
|
||||
|
||||
// register profile config
|
||||
#define PG_REGISTER_PROFILE_I(_type, _name, _pgn, _version, _reset) \
|
||||
STATIC_UNIT_TESTED _type _name ## _Storage[PG_PROFILE_COUNT]; \
|
||||
_PG_PROFILE_CURRENT_DECL(_type, _name) \
|
||||
extern const pgRegistry_t _name ## _Registry; \
|
||||
const pgRegistry_t _name ## _Registry PG_REGISTER_ATTRIBUTES = { \
|
||||
.pgn = _pgn | (_version << 12), \
|
||||
.size = sizeof(_type) | PGR_SIZE_PROFILE_FLAG, \
|
||||
.address = (uint8_t*)&_name ## _Storage, \
|
||||
.ptr = (uint8_t **)&_name ## _ProfileCurrent, \
|
||||
_reset, \
|
||||
} \
|
||||
/**/
|
||||
|
||||
#define PG_REGISTER_PROFILE(_type, _name, _pgn, _version) \
|
||||
PG_REGISTER_PROFILE_I(_type, _name, _pgn, _version, .reset = {.ptr = 0}) \
|
||||
/**/
|
||||
|
||||
#define PG_REGISTER_PROFILE_WITH_RESET_FN(_type, _name, _pgn, _version) \
|
||||
extern void pgResetFn_ ## _name(_type *); \
|
||||
PG_REGISTER_PROFILE_I(_type, _name, _pgn, _version, .reset = {.fn = (pgResetFunc*)&pgResetFn_ ## _name}) \
|
||||
/**/
|
||||
|
||||
#define PG_REGISTER_PROFILE_WITH_RESET_TEMPLATE(_type, _name, _pgn, _version) \
|
||||
extern const _type pgResetTemplate_ ## _name; \
|
||||
PG_REGISTER_PROFILE_I(_type, _name, _pgn, _version, .reset = {.ptr = (void*)&pgResetTemplate_ ## _name}) \
|
||||
/**/
|
||||
|
||||
|
||||
// Emit reset defaults for config.
|
||||
// Config must be registered with PG_REGISTER_<xxx>_WITH_RESET_TEMPLATE macro
|
||||
#define PG_RESET_TEMPLATE(_type, _name, ...) \
|
||||
|
@ -245,10 +184,8 @@ extern const uint8_t __pg_resetdata_end[];
|
|||
|
||||
const pgRegistry_t* pgFind(pgn_t pgn);
|
||||
|
||||
void pgLoad(const pgRegistry_t* reg, int profileIndex, const void *from, int size, int version);
|
||||
int pgStore(const pgRegistry_t* reg, void *to, int size, uint8_t profileIndex);
|
||||
void pgResetAll(int profileCount);
|
||||
void pgResetCurrent(const pgRegistry_t *reg);
|
||||
void pgLoad(const pgRegistry_t* reg, const void *from, int size, int version);
|
||||
int pgStore(const pgRegistry_t* reg, void *to, int size);
|
||||
void pgResetAll();
|
||||
bool pgResetCopy(void *copy, pgn_t pgn);
|
||||
void pgReset(const pgRegistry_t* reg, int profileIndex);
|
||||
void pgActivateProfile(int profileIndex);
|
||||
void pgReset(const pgRegistry_t* reg);
|
||||
|
|
|
@ -2974,12 +2974,8 @@ static void backupConfigs(void)
|
|||
{
|
||||
// make copies of configs to do differencing
|
||||
PG_FOREACH(pg) {
|
||||
if (pgIsProfile(pg)) {
|
||||
//memcpy(pg->copy, pg->address, pg->size * MAX_PROFILE_COUNT);
|
||||
} else {
|
||||
memcpy(pg->copy, pg->address, pg->size);
|
||||
}
|
||||
}
|
||||
|
||||
configIsInCopy = true;
|
||||
}
|
||||
|
@ -2987,12 +2983,8 @@ static void backupConfigs(void)
|
|||
static void restoreConfigs(void)
|
||||
{
|
||||
PG_FOREACH(pg) {
|
||||
if (pgIsProfile(pg)) {
|
||||
//memcpy(pg->address, pg->copy, pg->size * MAX_PROFILE_COUNT);
|
||||
} else {
|
||||
memcpy(pg->address, pg->copy, pg->size);
|
||||
}
|
||||
}
|
||||
|
||||
configIsInCopy = false;
|
||||
}
|
||||
|
|
|
@ -312,14 +312,12 @@ uint16_t getCurrentMinthrottle(void)
|
|||
|
||||
void resetConfigs(void)
|
||||
{
|
||||
pgResetAll(MAX_PROFILE_COUNT);
|
||||
pgResetAll();
|
||||
|
||||
#if defined(TARGET_CONFIG)
|
||||
targetConfiguration();
|
||||
#endif
|
||||
|
||||
pgActivateProfile(0);
|
||||
|
||||
#ifndef USE_OSD_SLAVE
|
||||
setPidProfile(0);
|
||||
setControlRateProfile(0);
|
||||
|
|
|
@ -48,7 +48,7 @@ PG_RESET_TEMPLATE(motorConfig_t, motorConfig,
|
|||
TEST(ParameterGroupsfTest, Test_pgResetAll)
|
||||
{
|
||||
memset(motorConfigMutable(), 0, sizeof(motorConfig_t));
|
||||
pgResetAll(0);
|
||||
pgResetAll();
|
||||
EXPECT_EQ(1150, motorConfig()->minthrottle);
|
||||
EXPECT_EQ(1850, motorConfig()->maxthrottle);
|
||||
EXPECT_EQ(1000, motorConfig()->mincommand);
|
||||
|
@ -59,7 +59,7 @@ TEST(ParameterGroupsfTest, Test_pgFind)
|
|||
{
|
||||
memset(motorConfigMutable(), 0, sizeof(motorConfig_t));
|
||||
const pgRegistry_t *pgRegistry = pgFind(PG_MOTOR_CONFIG);
|
||||
pgResetCurrent(pgRegistry);
|
||||
pgReset(pgRegistry);
|
||||
EXPECT_EQ(1150, motorConfig()->minthrottle);
|
||||
EXPECT_EQ(1850, motorConfig()->maxthrottle);
|
||||
EXPECT_EQ(1000, motorConfig()->mincommand);
|
||||
|
@ -68,7 +68,7 @@ TEST(ParameterGroupsfTest, Test_pgFind)
|
|||
motorConfig_t motorConfig2;
|
||||
memset(&motorConfig2, 0, sizeof(motorConfig_t));
|
||||
motorConfigMutable()->dev.motorPwmRate = 500;
|
||||
pgStore(pgRegistry, &motorConfig2, sizeof(motorConfig_t), 0);
|
||||
pgStore(pgRegistry, &motorConfig2, sizeof(motorConfig_t));
|
||||
EXPECT_EQ(1150, motorConfig2.minthrottle);
|
||||
EXPECT_EQ(1850, motorConfig2.maxthrottle);
|
||||
EXPECT_EQ(1000, motorConfig2.mincommand);
|
||||
|
|
Loading…
Reference in New Issue