Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Enhance config system #626

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open

Conversation

howard0su
Copy link
Contributor

We need reduce the size of the ROM of overall configuration subsystem.

Here is the ideas:

  1. Use table to do data driven as much as possible.
  2. The table to parse can be used to write out the configuration file, this can save lots of ROM.

while I am doing refectoring, add the test cases to cover.

Copy link
Contributor

@PhracturedBlue PhracturedBlue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am concerned about making changes to the config parser without having tests 1st. We need to have high confidence of being able to parse existing model files.
I'd probably prefer to 1st see a PR implementing tests validating the existing system (with whatever minimal changes are needed to write tests), and then have a 2nd PR with the new system.

src/config/display.c Show resolved Hide resolved
@howard0su
Copy link
Contributor Author

sure. of course, we need tests. My thinking is create several configuration files and read it in. then write it out, read it in again. and validate between stage.
Display and Tx is relative straightforward. but Model is full of small logic.

@howard0su howard0su force-pushed the config branch 4 times, most recently from da78683 to 503a1d4 Compare January 23, 2019 13:25
@howard0su
Copy link
Contributor Author

do you mind I first get the code of config.* and related tests in? then Display.c, then tx.c, then module.c with the corresponding tests? @PhracturedBlue

@howard0su howard0su changed the title [WIP] Enhence config system [WIP] Enhance config system Jan 24, 2019
@howard0su
Copy link
Contributor Author

@PhracturedBlue config.* contains new infra to support configure system. it has most part I want and please review. I will work on converting the existing code to new model piece by piece.

Copy link
Contributor

@PhracturedBlue PhracturedBlue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall, i like this direction. We need to ensure we get enough testing or that our test-cases are sufficient before committing it though.

src/config/display.c Outdated Show resolved Hide resolved
src/config/config.c Show resolved Hide resolved
src/config/display.c Outdated Show resolved Hide resolved
}

int write_int2(void* ptr, const struct struct_map *map, int map_size,
const u16* defaults, int defaults_size, FILE* fh) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you rename this? from its name i'd expect it to write a single int, but it actually writes a whole struct of them. 'write_ints_from_map' or something more descriptive

Copy link
Contributor Author

@howard0su howard0su Feb 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I will do it later. assign_int -> parse_ini_map, write_int ->write_ini_map, write_int2 ->write_ini_map_defaults

static const char * const MODEL_TYPE_VAL[MODELTYPE_LAST] = { "heli", "plane", "multi" };

#define MATCH_SECTION(s) (strcasecmp(section, s) == 0)
#define MATCH_START(x,y) (strncasecmp(x, y, sizeof(y)-1) == 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint Error:

33:  Missing space after ,  

static const char * const MIXER_MUXTYPE_VAL[MUX_LAST] = {
"replace", "multiply", "add", "max", "min", "delay",
#if HAS_EXTENDED_AUDIO
"beep","voice",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint Error:

75:  Missing space after ,  


static const char MIXER_CURVETYPE[] = "curvetype";
static const char * const MIXER_CURVETYPE_VAL[CURVE_MAX+1] = {
"none", "fixed", "min/max", "zero/max", "greater-than-0", "less-than-0", "absval",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint Error:

81:  Weird number of spaces at line-start.  Are you using a 2-space indent?  

{
int i = 0;
while(1) {
if(s1[i] == s2[i]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint Error:

199:  Missing space before ( in while(  
200:  Missing space before ( in if(  

|| (s2[i] == ' ' && s1[i] == '_')
|| (s1[i] == ' ' && s2[i] == '_'))
{
if(s1[i] == '\0')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint Error:

206:  Missing space before ( in if(  

const char *tmp;
char cmp[10];
for (i = 0; i <= NUM_SOURCES; i++) {
if(mapstrcasecmp(INPUT_SourceNameReal(cmp, i), ptr) == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint Error:

222:  Missing space before ( in if(  

#define SWITCH_NOSTOCK ((1 << INP_HOLD0) | (1 << INP_HOLD1) | \
(1 << INP_FMOD0) | (1 << INP_FMOD1))
if ((Transmitter.ignore_src & SWITCH_NOSTOCK) == SWITCH_NOSTOCK) {
if(mapstrcasecmp("FMODE0", ptr) == 0 ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint Error:

227:  Missing space before ( in if(  

mapstrcasecmp("HOLD1", ptr) == 0)
break;
}
#endif //HAS_SWITCHES_NOSTOCK
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint Error:

233:  At least two spaces is best between code and comments  
233:  Should have a space between // and comment  

}
}
for (i = 0; i < 4; i++) {
if(mapstrcasecmp(tx_stick_names[i], ptr) == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint Error:

238:  Missing space before ( in if(  

}
i = 0;
while((tmp = INPUT_MapSourceName(i++, &val))) {
if(mapstrcasecmp(tmp, ptr) == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint Error:

243:  Missing space before ( in while(  
244:  Missing space before ( in if(  

{
u8 i;
for (i = 0; i <= NUM_TX_BUTTONS; i++) {
if(strcasecmp(INPUT_ButtonName(i), value) == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint Error:

256:  Missing space before ( in if(  

const char **popts = opts;
int idx = 0;
while(*popts) {
if(mapstrcasecmp(*popts, key) == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint Error:

268:  Missing space before ( in while(  
269:  Missing space before ( in if(  

int start = exact_atoi(popts[0]);
int end = exact_atoi(popts[1]);
int is_num = ((start != 0 || end != 0) && (popts[2] == 0 || (popts[3] == 0 && exact_atoi(popts[2]) != 0))) ? 1 : 0;
if(is_num) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint Error:

274:  Missing space before ( in if(  

}
int val = 0;
while(popts[val]) {
if(mapstrcasecmp(popts[val], value) == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint Error:

279:  Missing space before ( in while(  
280:  Missing space before ( in if(  

while(*popts) {
popts++;
}
popts++; //Go to next option
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint Error:

289:  Should have a space between // and comment  
290:  Missing space before ( in while(  
293:  At least two spaces is best between code and comments  
293:  Should have a space between // and comment  

};
static const char * parse_partial_int_list(const char *ptr, void *vals, int *max_count, int type)
{
//const char *origptr = ptr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint Error:

306:  Should have a space between // and comment  

int sign = 0;

while(1) {
if(*ptr == ',' || *ptr == '\0') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint Error:

311:  Missing space before ( in while(  
312:  Missing space before ( in if(  

--*max_count;
if (*max_count == 0 || *ptr == '\0')
return ptr;
} else if(*ptr == '-') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint Error:

335:  Missing space before ( in if(  

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants