Merge pull request #4024 from martinbudden/bf_test_update
Improved testability
This commit is contained in:
commit
3c2f62a6a9
|
@ -402,12 +402,18 @@ static uint16_t getValueOffset(const clivalue_t *value)
|
|||
return 0;
|
||||
}
|
||||
|
||||
STATIC_UNIT_TESTED void *getValuePointer(const clivalue_t *value)
|
||||
void *cliGetValuePointer(const clivalue_t *value)
|
||||
{
|
||||
const pgRegistry_t* rec = pgFind(value->pgn);
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
const void *ptr = getValuePointer(var);
|
||||
const void *ptr = cliGetValuePointer(var);
|
||||
|
||||
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)
|
||||
{
|
||||
void *ptr = getValuePointer(var);
|
||||
void *ptr = cliGetValuePointer(var);
|
||||
|
||||
switch (var->type & VALUE_TYPE_MASK) {
|
||||
case VAR_UINT8:
|
||||
|
@ -2788,7 +2794,7 @@ STATIC_UNIT_TESTED void cliSet(char *cmdline)
|
|||
default:
|
||||
case VAR_UINT8: {
|
||||
// fetch data pointer
|
||||
uint8_t *data = (uint8_t *)getValuePointer(val) + i;
|
||||
uint8_t *data = (uint8_t *)cliGetValuePointer(val) + i;
|
||||
// store value
|
||||
*data = (uint8_t)atoi((const char*) valPtr);
|
||||
}
|
||||
|
@ -2796,7 +2802,7 @@ STATIC_UNIT_TESTED void cliSet(char *cmdline)
|
|||
|
||||
case VAR_INT8: {
|
||||
// fetch data pointer
|
||||
int8_t *data = (int8_t *)getValuePointer(val) + i;
|
||||
int8_t *data = (int8_t *)cliGetValuePointer(val) + i;
|
||||
// store value
|
||||
*data = (int8_t)atoi((const char*) valPtr);
|
||||
}
|
||||
|
@ -2804,7 +2810,7 @@ STATIC_UNIT_TESTED void cliSet(char *cmdline)
|
|||
|
||||
case VAR_UINT16: {
|
||||
// fetch data pointer
|
||||
uint16_t *data = (uint16_t *)getValuePointer(val) + i;
|
||||
uint16_t *data = (uint16_t *)cliGetValuePointer(val) + i;
|
||||
// store value
|
||||
*data = (uint16_t)atoi((const char*) valPtr);
|
||||
}
|
||||
|
@ -2812,7 +2818,7 @@ STATIC_UNIT_TESTED void cliSet(char *cmdline)
|
|||
|
||||
case VAR_INT16: {
|
||||
// fetch data pointer
|
||||
int16_t *data = (int16_t *)getValuePointer(val) + i;
|
||||
int16_t *data = (int16_t *)cliGetValuePointer(val) + i;
|
||||
// store value
|
||||
*data = (int16_t)atoi((const char*) valPtr);
|
||||
}
|
||||
|
|
|
@ -19,6 +19,10 @@
|
|||
|
||||
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;
|
||||
void cliInit(const struct serialConfig_s *serialConfig);
|
||||
void cliProcess(void);
|
||||
|
|
|
@ -17,6 +17,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "config/parameter_group.h"
|
||||
|
||||
|
||||
typedef enum {
|
||||
TABLE_OFF_ON = 0,
|
||||
|
|
|
@ -53,7 +53,6 @@ extern "C" {
|
|||
|
||||
void cliSet(char *cmdline);
|
||||
void cliGet(char *cmdline);
|
||||
void *getValuePointer(const clivalue_t *value);
|
||||
|
||||
const clivalue_t valueTable[] = {
|
||||
{ "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");
|
||||
int8_t *data = (int8_t *)getValuePointer(&cval);
|
||||
int8_t *data = (int8_t *)cliGetValuePointer(&cval);
|
||||
for(int i=0; i<3; i++){
|
||||
printf("data[%d] = %d\n", i, data[i]);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define USE_PARAMETER_GROUPS
|
||||
|
||||
#define U_ID_0 0
|
||||
|
|
Loading…
Reference in New Issue