mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-19 14:25:20 +03:00
Added pgResetCopy function and tests
This commit is contained in:
parent
0e055b460b
commit
e78a225ed3
4 changed files with 129 additions and 0 deletions
|
@ -71,6 +71,16 @@ void pgResetCurrent(const pgRegistry_t *reg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool pgResetCopy(void *copy, pgn_t pgn)
|
||||||
|
{
|
||||||
|
const pgRegistry_t *reg = pgFind(pgn);
|
||||||
|
if (reg) {
|
||||||
|
pgResetInstance(reg, copy);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void pgLoad(const pgRegistry_t* reg, int profileIndex, const void *from, int size, int version)
|
void pgLoad(const pgRegistry_t* reg, int profileIndex, const void *from, int size, int version)
|
||||||
{
|
{
|
||||||
pgResetInstance(reg, pgOffset(reg, profileIndex));
|
pgResetInstance(reg, pgOffset(reg, profileIndex));
|
||||||
|
|
|
@ -17,6 +17,9 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
typedef uint16_t pgn_t;
|
typedef uint16_t pgn_t;
|
||||||
|
|
||||||
// parameter group registry flags
|
// parameter group registry flags
|
||||||
|
@ -225,5 +228,6 @@ void pgLoad(const pgRegistry_t* reg, int profileIndex, const void *from, int siz
|
||||||
int pgStore(const pgRegistry_t* reg, void *to, int size, uint8_t profileIndex);
|
int pgStore(const pgRegistry_t* reg, void *to, int size, uint8_t profileIndex);
|
||||||
void pgResetAll(int profileCount);
|
void pgResetAll(int profileCount);
|
||||||
void pgResetCurrent(const pgRegistry_t *reg);
|
void pgResetCurrent(const pgRegistry_t *reg);
|
||||||
|
bool pgResetCopy(void *copy, pgn_t pgn);
|
||||||
void pgReset(const pgRegistry_t* reg, int profileIndex);
|
void pgReset(const pgRegistry_t* reg, int profileIndex);
|
||||||
void pgActivateProfile(int profileIndex);
|
void pgActivateProfile(int profileIndex);
|
||||||
|
|
|
@ -690,6 +690,28 @@ $(OBJECT_DIR)/cms_unittest : \
|
||||||
|
|
||||||
$(CXX) $(CXX_FLAGS) $^ -o $(OBJECT_DIR)/$@
|
$(CXX) $(CXX_FLAGS) $^ -o $(OBJECT_DIR)/$@
|
||||||
|
|
||||||
|
$(OBJECT_DIR)/config/parameter_group.o : \
|
||||||
|
$(USER_DIR)/config/parameter_group.c \
|
||||||
|
$(USER_DIR)/config/parameter_group.h \
|
||||||
|
$(GTEST_HEADERS)
|
||||||
|
|
||||||
|
@mkdir -p $(dir $@)
|
||||||
|
$(CC) $(C_FLAGS) $(TEST_CFLAGS) -c $(USER_DIR)/config/parameter_group.c -o $@
|
||||||
|
|
||||||
|
$(OBJECT_DIR)/parameter_groups_unittest.o : \
|
||||||
|
$(TEST_DIR)/parameter_groups_unittest.cc \
|
||||||
|
$(GTEST_HEADERS)
|
||||||
|
|
||||||
|
@mkdir -p $(dir $@)
|
||||||
|
$(CXX) $(CXX_FLAGS) $(TEST_CFLAGS) -c $(TEST_DIR)/parameter_groups_unittest.cc -o $@
|
||||||
|
|
||||||
|
$(OBJECT_DIR)/parameter_groups_unittest : \
|
||||||
|
$(OBJECT_DIR)/parameter_groups_unittest.o \
|
||||||
|
$(OBJECT_DIR)/config/parameter_group.o \
|
||||||
|
$(OBJECT_DIR)/gtest_main.a
|
||||||
|
|
||||||
|
$(CXX) $(CXX_FLAGS) $^ -o $(OBJECT_DIR)/$@
|
||||||
|
|
||||||
|
|
||||||
## test : Build and run the Unit Tests
|
## test : Build and run the Unit Tests
|
||||||
test: $(TESTS:%=test-%)
|
test: $(TESTS:%=test-%)
|
||||||
|
|
93
src/test/unit/parameter_groups_unittest.cc
Normal file
93
src/test/unit/parameter_groups_unittest.cc
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Cleanflight.
|
||||||
|
*
|
||||||
|
* Cleanflight is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Cleanflight is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include "build/debug.h"
|
||||||
|
|
||||||
|
#include <platform.h>
|
||||||
|
|
||||||
|
#include "config/parameter_group.h"
|
||||||
|
#include "config/parameter_group_ids.h"
|
||||||
|
|
||||||
|
#include "io/motors.h"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
PG_DECLARE(motorConfig_t, motorConfig);
|
||||||
|
|
||||||
|
PG_REGISTER_WITH_RESET_TEMPLATE(motorConfig_t, motorConfig, PG_MOTOR_CONFIG, 1);
|
||||||
|
|
||||||
|
PG_RESET_TEMPLATE(motorConfig_t, motorConfig,
|
||||||
|
.minthrottle = 1150,
|
||||||
|
.maxthrottle = 1850,
|
||||||
|
.mincommand = 1000,
|
||||||
|
.motorPwmRate = 400,
|
||||||
|
);
|
||||||
|
|
||||||
|
#include "unittest_macros.h"
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
TEST(ParameterGroupsfTest, Test_pgResetAll)
|
||||||
|
{
|
||||||
|
memset(motorConfig(), 0, sizeof(motorConfig_t));
|
||||||
|
pgResetAll(0);
|
||||||
|
EXPECT_EQ(1150, motorConfig()->minthrottle);
|
||||||
|
EXPECT_EQ(1850, motorConfig()->maxthrottle);
|
||||||
|
EXPECT_EQ(1000, motorConfig()->mincommand);
|
||||||
|
EXPECT_EQ(400, motorConfig()->motorPwmRate);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(ParameterGroupsfTest, Test_pgFind)
|
||||||
|
{
|
||||||
|
memset(motorConfig(), 0, sizeof(motorConfig_t));
|
||||||
|
const pgRegistry_t *pgRegistry = pgFind(PG_MOTOR_CONFIG);
|
||||||
|
pgResetCurrent(pgRegistry);
|
||||||
|
EXPECT_EQ(1150, motorConfig()->minthrottle);
|
||||||
|
EXPECT_EQ(1850, motorConfig()->maxthrottle);
|
||||||
|
EXPECT_EQ(1000, motorConfig()->mincommand);
|
||||||
|
EXPECT_EQ(400, motorConfig()->motorPwmRate);
|
||||||
|
|
||||||
|
motorConfig_t motorConfig2;
|
||||||
|
memset(&motorConfig2, 0, sizeof(motorConfig_t));
|
||||||
|
motorConfig()->motorPwmRate = 500;
|
||||||
|
pgStore(pgRegistry, &motorConfig2, sizeof(motorConfig_t), 0);
|
||||||
|
EXPECT_EQ(1150, motorConfig2.minthrottle);
|
||||||
|
EXPECT_EQ(1850, motorConfig2.maxthrottle);
|
||||||
|
EXPECT_EQ(1000, motorConfig2.mincommand);
|
||||||
|
EXPECT_EQ(500, motorConfig2.motorPwmRate);
|
||||||
|
|
||||||
|
motorConfig_t motorConfig3;
|
||||||
|
memset(&motorConfig3, 0, sizeof(motorConfig_t));
|
||||||
|
pgResetCopy(&motorConfig3, PG_MOTOR_CONFIG);
|
||||||
|
EXPECT_EQ(1150, motorConfig3.minthrottle);
|
||||||
|
EXPECT_EQ(1850, motorConfig3.maxthrottle);
|
||||||
|
EXPECT_EQ(1000, motorConfig3.mincommand);
|
||||||
|
EXPECT_EQ(400, motorConfig3.motorPwmRate);
|
||||||
|
}
|
||||||
|
|
||||||
|
// STUBS
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue