mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-18 13:55:18 +03:00
Improved testability
This commit is contained in:
parent
9bf338346b
commit
e6bbce53e6
5 changed files with 24 additions and 9 deletions
|
@ -402,12 +402,18 @@ static uint16_t getValueOffset(const clivalue_t *value)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC_UNIT_TESTED void *getValuePointer(const clivalue_t *value)
|
void *cliGetValuePointer(const clivalue_t *value)
|
||||||
{
|
{
|
||||||
const pgRegistry_t* rec = pgFind(value->pgn);
|
const pgRegistry_t* rec = pgFind(value->pgn);
|
||||||
return CONST_CAST(void *, rec->address + getValueOffset(value));
|
return CONST_CAST(void *, rec->address + getValueOffset(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const void *cliGetDefaultPointer(const clivalue_t *value)
|
||||||
|
{
|
||||||
|
const pgRegistry_t* rec = pgFind(value->pgn);
|
||||||
|
return rec->address + getValueOffset(value);
|
||||||
|
}
|
||||||
|
|
||||||
static void dumpPgValue(const clivalue_t *value, uint8_t dumpMask)
|
static void dumpPgValue(const clivalue_t *value, uint8_t dumpMask)
|
||||||
{
|
{
|
||||||
const pgRegistry_t *pg = pgFind(value->pgn);
|
const pgRegistry_t *pg = pgFind(value->pgn);
|
||||||
|
@ -448,7 +454,7 @@ static void dumpAllValues(uint16_t valueSection, uint8_t dumpMask)
|
||||||
|
|
||||||
static void cliPrintVar(const clivalue_t *var, bool full)
|
static void cliPrintVar(const clivalue_t *var, bool full)
|
||||||
{
|
{
|
||||||
const void *ptr = getValuePointer(var);
|
const void *ptr = cliGetValuePointer(var);
|
||||||
|
|
||||||
printValuePointer(var, ptr, full);
|
printValuePointer(var, ptr, full);
|
||||||
}
|
}
|
||||||
|
@ -481,7 +487,7 @@ static void cliPrintVarRange(const clivalue_t *var)
|
||||||
|
|
||||||
static void cliSetVar(const clivalue_t *var, const int16_t value)
|
static void cliSetVar(const clivalue_t *var, const int16_t value)
|
||||||
{
|
{
|
||||||
void *ptr = getValuePointer(var);
|
void *ptr = cliGetValuePointer(var);
|
||||||
|
|
||||||
switch (var->type & VALUE_TYPE_MASK) {
|
switch (var->type & VALUE_TYPE_MASK) {
|
||||||
case VAR_UINT8:
|
case VAR_UINT8:
|
||||||
|
@ -2788,7 +2794,7 @@ STATIC_UNIT_TESTED void cliSet(char *cmdline)
|
||||||
default:
|
default:
|
||||||
case VAR_UINT8: {
|
case VAR_UINT8: {
|
||||||
// fetch data pointer
|
// fetch data pointer
|
||||||
uint8_t *data = (uint8_t *)getValuePointer(val) + i;
|
uint8_t *data = (uint8_t *)cliGetValuePointer(val) + i;
|
||||||
// store value
|
// store value
|
||||||
*data = (uint8_t)atoi((const char*) valPtr);
|
*data = (uint8_t)atoi((const char*) valPtr);
|
||||||
}
|
}
|
||||||
|
@ -2796,7 +2802,7 @@ STATIC_UNIT_TESTED void cliSet(char *cmdline)
|
||||||
|
|
||||||
case VAR_INT8: {
|
case VAR_INT8: {
|
||||||
// fetch data pointer
|
// fetch data pointer
|
||||||
int8_t *data = (int8_t *)getValuePointer(val) + i;
|
int8_t *data = (int8_t *)cliGetValuePointer(val) + i;
|
||||||
// store value
|
// store value
|
||||||
*data = (int8_t)atoi((const char*) valPtr);
|
*data = (int8_t)atoi((const char*) valPtr);
|
||||||
}
|
}
|
||||||
|
@ -2804,7 +2810,7 @@ STATIC_UNIT_TESTED void cliSet(char *cmdline)
|
||||||
|
|
||||||
case VAR_UINT16: {
|
case VAR_UINT16: {
|
||||||
// fetch data pointer
|
// fetch data pointer
|
||||||
uint16_t *data = (uint16_t *)getValuePointer(val) + i;
|
uint16_t *data = (uint16_t *)cliGetValuePointer(val) + i;
|
||||||
// store value
|
// store value
|
||||||
*data = (uint16_t)atoi((const char*) valPtr);
|
*data = (uint16_t)atoi((const char*) valPtr);
|
||||||
}
|
}
|
||||||
|
@ -2812,7 +2818,7 @@ STATIC_UNIT_TESTED void cliSet(char *cmdline)
|
||||||
|
|
||||||
case VAR_INT16: {
|
case VAR_INT16: {
|
||||||
// fetch data pointer
|
// fetch data pointer
|
||||||
int16_t *data = (int16_t *)getValuePointer(val) + i;
|
int16_t *data = (int16_t *)cliGetValuePointer(val) + i;
|
||||||
// store value
|
// store value
|
||||||
*data = (int16_t)atoi((const char*) valPtr);
|
*data = (int16_t)atoi((const char*) valPtr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,10 @@
|
||||||
|
|
||||||
extern uint8_t cliMode;
|
extern uint8_t cliMode;
|
||||||
|
|
||||||
|
struct clivalue_s;
|
||||||
|
void *cliGetValuePointer(const struct clivalue_s *value);
|
||||||
|
const void *cliGetDefaultPointer(const struct clivalue_s *value);
|
||||||
|
|
||||||
struct serialConfig_s;
|
struct serialConfig_s;
|
||||||
void cliInit(const struct serialConfig_s *serialConfig);
|
void cliInit(const struct serialConfig_s *serialConfig);
|
||||||
void cliProcess(void);
|
void cliProcess(void);
|
||||||
|
|
|
@ -17,6 +17,10 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include "config/parameter_group.h"
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
TABLE_OFF_ON = 0,
|
TABLE_OFF_ON = 0,
|
||||||
|
|
|
@ -53,7 +53,6 @@ extern "C" {
|
||||||
|
|
||||||
void cliSet(char *cmdline);
|
void cliSet(char *cmdline);
|
||||||
void cliGet(char *cmdline);
|
void cliGet(char *cmdline);
|
||||||
void *getValuePointer(const clivalue_t *value);
|
|
||||||
|
|
||||||
const clivalue_t valueTable[] = {
|
const clivalue_t valueTable[] = {
|
||||||
{ "array_unit_test", VAR_INT8 | MODE_ARRAY | MASTER_VALUE, .config.array.length = 3, PG_RESERVED_FOR_TESTING_1, 0 }
|
{ "array_unit_test", VAR_INT8 | MODE_ARRAY | MASTER_VALUE, .config.array.length = 3, PG_RESERVED_FOR_TESTING_1, 0 }
|
||||||
|
@ -99,7 +98,7 @@ TEST(CLIUnittest, TestCliSet)
|
||||||
};
|
};
|
||||||
|
|
||||||
printf("\n===============================\n");
|
printf("\n===============================\n");
|
||||||
int8_t *data = (int8_t *)getValuePointer(&cval);
|
int8_t *data = (int8_t *)cliGetValuePointer(&cval);
|
||||||
for(int i=0; i<3; i++){
|
for(int i=0; i<3; i++){
|
||||||
printf("data[%d] = %d\n", i, data[i]);
|
printf("data[%d] = %d\n", i, data[i]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#define USE_PARAMETER_GROUPS
|
#define USE_PARAMETER_GROUPS
|
||||||
|
|
||||||
#define U_ID_0 0
|
#define U_ID_0 0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue