Best way to parse Arduino boards.txt
-
Here a sample of the Arduino boards.txt file:
############################################################## yun.name=Arduino Yún yun.upload.via_ssh=true yun.vid.0=0x2341 yun.pid.0=0x0041 yun.vid.1=0x2341 yun.pid.1=0x8041 yun.vid.2=0x2A03 yun.pid.2=0x0041 yun.vid.3=0x2A03 yun.pid.3=0x8041 yun.upload_port.0.vid=0x2341 yun.upload_port.0.pid=0x0041 yun.upload_port.1.vid=0x2341 yun.upload_port.1.pid=0x8041 yun.upload_port.2.vid=0x2A03 yun.upload_port.2.pid=0x0041 yun.upload_port.3.vid=0x2A03 yun.upload_port.3.pid=0x8041 yun.upload_port.4.board=yun yun.upload.tool=avrdude yun.upload.tool.default=avrdude yun.upload.tool.network=arduino_ota yun.upload.protocol=avr109 yun.upload.maximum_size=28672 yun.upload.maximum_data_size=2560 yun.upload.speed=57600 yun.upload.disable_flushing=true yun.upload.use_1200bps_touch=true yun.upload.wait_for_upload_port=true yun.bootloader.tool=avrdude yun.bootloader.tool.default=avrdude yun.bootloader.low_fuses=0xff yun.bootloader.high_fuses=0xd8 yun.bootloader.extended_fuses=0xfb yun.bootloader.file=caterina/Caterina-Yun.hex yun.bootloader.noblink=caterina/Caterina-Yun-noblink.hex yun.bootloader.unlock_bits=0x3F yun.bootloader.lock_bits=0x2F yun.build.mcu=atmega32u4 yun.build.f_cpu=16000000L yun.build.vid=0x2341 yun.build.pid=0x8041 yun.build.usb_product="Arduino Yun" yun.build.board=AVR_YUN yun.build.core=arduino yun.build.variant=yun yun.build.extra_flags={build.usb_flags} ############################################################## uno.name=Arduino Uno uno.vid.0=0x2341 uno.pid.0=0x0043 uno.vid.1=0x2341 uno.pid.1=0x0001 uno.vid.2=0x2A03 uno.pid.2=0x0043 uno.vid.3=0x2341 uno.pid.3=0x0243 uno.upload_port.0.vid=0x2341 uno.upload_port.0.pid=0x0043 uno.upload_port.1.vid=0x2341 uno.upload_port.1.pid=0x0001 uno.upload_port.2.vid=0x2A03 uno.upload_port.2.pid=0x0043 uno.upload_port.3.vid=0x2341 uno.upload_port.3.pid=0x0243 uno.upload_port.4.board=uno uno.upload.tool=avrdude uno.upload.tool.default=avrdude uno.upload.tool.network=arduino_ota uno.upload.protocol=arduino uno.upload.maximum_size=32256 uno.upload.maximum_data_size=2048 uno.upload.speed=115200 uno.bootloader.tool=avrdude uno.bootloader.tool.default=avrdude uno.bootloader.low_fuses=0xFF uno.bootloader.high_fuses=0xDE uno.bootloader.extended_fuses=0xFD uno.bootloader.unlock_bits=0x3F uno.bootloader.lock_bits=0x0F uno.bootloader.file=optiboot/optiboot_atmega328.hex uno.build.mcu=atmega328p uno.build.f_cpu=16000000L uno.build.board=AVR_UNO uno.build.core=arduino uno.build.variant=standard ##############################################################
I want to store this information to make searches.
Examples:- given a vid = 0x2341 and a pid = 0x0243 which board(s) fit(s) ?
- which is the upload speed for the board named "Leonardo" ?
I'm not asking you to code for me, I'm just asking for some hints about the best approach: how to parse the document, how to store the information, etc...
Any idea is appreciated.
-
@Mark81 said in Best way to parse Arduino boards.txt:
I'm just asking for some hints about the best approach: how to parse the document, how to store the information, etc...
Create this as
QFile
, read every line and split the substrings by=
.
Then you have some sort ofKey <-> Value
pairs.Edit:
To improve it even more, you could create a
struct
or class, which includes all settings from your config file(s). Then you can easily compareArduino_X.name
withArduino_Y.name
and any other settings. -
Hi,
If you need to manage complex queries, you could also store that data in a SQLite database using the Qt SQL module.
-
Thank you guys,
of course I'm able to do what you said manually.I was wondering if there were any smart approach to automate the process, i.e. deducing the schema and mapping the data automatically. For example, using a generic map ("name", "value") instead of the specific names, in order to append all the fields (even the optional ones not present in all boards).
If there is not such a way I'm going to create a data struct manually (I have to retrieve all the optional fields) as usual.
-
If you read line by line and add all substrings as
key
orvalue
, as I've said, it stays dynamic and you can add as much lines as you want. Whether you create a structure or not is up to you :)And even in a struct you could have something like "Additional information" where you put device specific stuff or options, which are not included in every "board"