config.h management tool

This forum is dedicated to software development related to MultiWii.
It is not the right place to submit a setup problem.
Software download
Post Reply
scanman
Posts: 74
Joined: Thu Jun 21, 2012 9:26 am
Location: Durban, South Africa
Contact:

config.h management tool

Post by scanman »

I am writing some software to manage multiple config.h files.
Every time a new version comes out, it takes many minutes to just figure out if there are new defines in the config file, and setup all the settings you need.

I have written some software that will manage your config files. You setup your "favourite" settings and store them. Then when a new config.h file comes along, the software automatically checks for new #defines, identifies them and adds your favourites to the list . You can then create a file with the new settings and your favourites that work.

Its not finished yet, currently I am parsing the text in the file.
If there is enough interest in this tool i intend making it opensource.
All comments are welcome here.
the screen showing your favourites . it also parses the data into "sections" as commented in the multiwii config.h
the screen showing your favourites . it also parses the data into "sections" as commented in the multiwii config.h

scanman
Posts: 74
Joined: Thu Jun 21, 2012 9:26 am
Location: Durban, South Africa
Contact:

Re: config.h management tool

Post by scanman »

screenshot showing the values in one of the sections

screenshot showing the values in one of the sections
screenshot showing the values in one of the sections

copterrichie
Posts: 2261
Joined: Sat Feb 19, 2011 8:30 pm

Re: config.h management tool

Post by copterrichie »

Kudos, would be nice if this was integrated into the GUI.

User avatar
Hamburger
Posts: 2578
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

Re: config.h management tool

Post by Hamburger »

As the config.h file does not follow any strict syntax (except C language), your program has to rely on some guesswork. Please point out what those characteristics are, so we may have a chance to follow. For example you somehow identify the sections based on some heuristics - but we could accidentally add some nasty comment that would throw your code off. We do not want that to happen, so maybe you best tell us.

I do not see the need for a tool but your mileage may vary. For me, I do not touch the config.h but keep one file for each copter with all the particular defines and undefs. For this file I add an include in MWii.ino between config.h and def.h. Can even have all copterX.h files in the MultiWii folder without a problem. To scan for new features & changes in config.h a simple diff between versions is all it takes.

scanman
Posts: 74
Joined: Thu Jun 21, 2012 9:26 am
Location: Durban, South Africa
Contact:

Re: config.h management tool

Post by scanman »

you are correct. the config.h is quite uniform, but there are a few scenarios i need to spend some time on.

it basically reads the file line by line and looks for #define and //#define
it strips out whitespace where needed.
Those are the only 2 interesting types of lines, the other lines are loaded but ignored.
it also looks for /* and then the word "SECTION" and takes what follows as the section.

I haven't done the file generation yet, there is no reason to put all the comments in the file, however i'll probably make it an option so you can choose comments or not, (I keep the line number in the data so there is no reason why i cant re-write it in the correct order) . I doubt if reproduce exactly the current config.h with all the comments.

It uses an XML file to store its favourites. It is written in VB.Net so if you want to include it in WinGui, we should convert early. have only spent 4 hours on it so theres no loss if you want to change direction.

I will make it so you can store favourites for multiple models.

It also looks for things like:
1. complete commented lines starting with /* and with nothing else except spaces and stars e.g. /********* *******/
2. single commented lines


Here is the section of code that parses each line in the file, this is the "decision maker"


Sub fn_ParseLine(ByVal sline As String, ByRef sType As String, ByRef sName As String, ByRef sVal As String, ByRef sSECTION As String)
'split the line and try and find out its elements
sName = ""
sVal = ""
sSECTION = ""
Dim snew As String = sline.Trim
snew = snew.Replace(" ", " ")
snew = snew.Replace(" ", " ")
snew = snew.Replace(" ", " ")

'split the string up
Dim s() As String = snew.Trim.Split(" ")
If s.Length = 0 Then
sType = "blank"
Exit Sub
End If

'check if it contains only comments
Dim bHasOtherChars As Boolean = False
For i As Integer = 0 To s.Length - 1
'go through each character in the string
Dim c As String
For ich As Integer = 1 To s(i).Length
c = Mid(s(i), ich, 1)
If c <> "" And c <> " " And c <> s_CommentChar1 And c <> s_CommentChar2 Then
bHasOtherChars = True
Exit For
End If
Next
If bHasOtherChars Then Exit For
Next

If Not bHasOtherChars Then
'its a comment only line
sType = "WhiteSpace"
Exit Sub
End If


'check if this is a section header
If snew.Contains(s_Section) Then
'find out the section
For i As Integer = 0 To s.Length - 1
If s(i).ToUpper.Trim = s_Section.ToUpper.Trim Then
If i + 1 <= s.Length - 1 Then
sSECTION = s(i + 1)
End If
End If
Next
End If

'check if this is a multi comment line "/*"
If Strings.Left(snew, Len(s_CommentChar1 & s_CommentChar2)) = s_CommentChar1 & s_CommentChar2 Then
sType = "Comment"
Exit Sub
End If

' Dim sCommentDefine As String = s_CommentString.Trim & s_DefineString.Trim
'get the data out the string if the string is long enough
If s.Length >= 1 Then
sType = s(0)
' If sType.ToUpper.Trim <> s_DefineString.ToUpper.Trim Then
'sType = "other"
' Exit Sub
' End If
End If
If s.Length >= 2 Then
sName = s(1)
End If
If s.Length >= 3 Then
sVal = s(2)
End If

'its a commented out value, so set it to zero
If Strings.Left(sVal, Len(s_CommentString)) = s_CommentString Then
sVal = ""
End If

End Sub
Last edited by scanman on Sun Mar 10, 2013 9:31 pm, edited 1 time in total.

scanman
Posts: 74
Joined: Thu Jun 21, 2012 9:26 am
Location: Durban, South Africa
Contact:

Re: config.h management tool

Post by scanman »

these are the main string elements it checks for:

Const s_DefineString As String = "#define"
Const s_CommentString As String = "//"
Const s_CommentChar1 As String = "/"
Const s_CommentChar2 As String = "*"
Const s_Section As String = "SECTION "

User avatar
mbrak
Posts: 136
Joined: Sat Dec 03, 2011 8:08 pm
Location: Germany, Lemgo

Re: config.h management tool

Post by mbrak »

+1

that tool is very needful !

scanman
Posts: 74
Joined: Thu Jun 21, 2012 9:26 am
Location: Durban, South Africa
Contact:

Re: config.h management tool

Post by scanman »

Here is the first version (Windows ) for someone to please test.
1. Download the exe from here
multiwiiConfigManager.zip
(20.6 KiB) Downloaded 169 times

2. unzip it into any folder
3. Run the exe. It will create a favourites.xml file in the same folder. Click on "New Model..." and type in the name of your model , dog, cat , girlfriend , mother etc.,
4. You will have no favourites for the new model so click on the "Config File" tab and click the "Open Config File" button and browse to the miltiwii config.h file you have that is working .
5. A whole lot of new tabs will be created, one for each section in the config.h . you can look through the defines and put the checkbox on for the ones you want to include in your favourites.
6. Click the "Copy Selected To Favourites" button. All these defines will be added to your model
7. Go back to the "Favourites" tab and click "Create new config file", select the config file in your multiwii folder and save it.
8. It overwrites the config.h file with your favourites but first backs it up into the same folder as the exe.

Whenever you want to create a new config.h file with your settings, then just repeat step 7.

tovrin
Posts: 705
Joined: Tue Sep 20, 2011 4:08 pm

Re: config.h management tool

Post by tovrin »

@ Hamburger, how do you do a diff? I keep hearing about this, and i know its a coder thing, but i am not a coder.

I have to make only one oddball change when setting my quad up for next version and I simply do a search for RC Function in the first tab and change my end points, but a tool like scanmans isn't necessarily a bad idea, considering some people do some really major changes, to mixing tables, for instance.

User avatar
Hamburger
Posts: 2578
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

Re: config.h management tool

Post by Hamburger »

@tovrin
yes, diff is a text tool well suited for program code. There are some versions with gui for all relevant platforms out there, so I've heard.
To shortcut, for a diff between selected versions of config.h one can also use the google repository itself
http://code.google.com/p/multiwii/sourc ... d/config.h has 'diff' on the right hand side.

scanman
Posts: 74
Joined: Thu Jun 21, 2012 9:26 am
Location: Durban, South Africa
Contact:

Re: config.h management tool

Post by scanman »

im working on a quick diff function so the tool will show you the differences between your model and the loaded config.h file, will be ready tomorrow

User avatar
diyboy
Posts: 28
Joined: Sun Sep 30, 2012 7:12 pm

Re: config.h management tool

Post by diyboy »

Cool...! :D

tovrin
Posts: 705
Joined: Tue Sep 20, 2011 4:08 pm

Re: config.h management tool

Post by tovrin »

@hamburger
thank you, i did not know this, I used the google link to look at a diff of the config.h file and this is super cool, i truly appreciate the tip!

scanman
Posts: 74
Joined: Thu Jun 21, 2012 9:26 am
Location: Durban, South Africa
Contact:

Re: config.h management tool

Post by scanman »

here is a preview of the next version which shows the diff between your model and the config.h file. it shows 3 types of differences: items in your favourites but not in the config.h, items missing from your favourites, and items where the value in your favourites is different.


I still need to do some housekeeping - making less columns appear, plus i need to implement the buttons to copy the diferences across to your favourites, i will make another version on the weekend if flying weather is not great.

multiwiiConfigManager1.1.zip
(22.46 KiB) Downloaded 146 times


multiwiidiff.JPG

Post Reply