C/C++ Question a tool to help a wrapper creation

candide

Active Member
Licensed User
for myself to answer at my need, i tried to create a tool helping at wrapper creating.
i started in VBS and with PSPad editor because PSPad is a freeware, it is a very good editor with multiples features but also because it is easy to extend with VBS or JS.

Installation :
  • First solution: a new install
    • Download PSPad , (freeware) and install it in c:\PSPad editor or another root area.
    • Activate vbs scripts in PSPad parameters
    • In PSPad parameters, Add PSPad at Windows 10 contextual menu, it will help at files loading
    • Install this vbs script in PSPad editor\script\VBSscript (zip of this thread)
    • In PSPAad menu, now you have « scripts » menu and under « recompile scripts » => run it
    • After that, in script menu you have a sub-menu « B4R » and « Help »

  • Second solution: download a full portable version PSPad with script installed and vbs helps.
And you can install it directly in c:\PSPad editor (or another root area)​

How it is working :
First you have to load xxx.h file of arduino library in PSPad
After run this script in 4 steps:
  • with h file arduino active, run "Creation of a file rxxx.h.clean file"
    • you can check, modify the new file before next step
  • with h.clean file active, run "Creation a rxxx.cpp file for B4R library"
    • you can check, modify the new file before next step, or modify h.clean file if needed and run again process above
  • with cpp file active, run "Creation of rxxx.h file for B4R library"
    • you can check, modify the new file before next step, or modify h.clean file, or modify cpp file if needed and run again process above
  • with h file active, run "Creation of rxxx.xml file for B4R library"
    • you can check, modify the new file before next step, or modify h.clean file, or modify cpp file if needed and run again process above
  • And when you think your library finished you can clean all comment lines and you can test it

don't hope it will do 100% of the work for a wrapper creation, but it should manage basic part and you can focus on complex cases.

update 2020/01/12
new version with less issues and able to manage creation of wrapper with or without backend, tocreate 3 loop in wrapper to monitor event in library and to launch a sub in B4R and to create also 3 callback from library when events from library are provided by callback.

the tool is based on a vbs script running in PSPad editor.
a guide can help at understanding of the tool
2 examples of libraries Test and TEST1 are available with B4R project to test the tool and to create/analyse all cases of interface between arduino library and B4R.

update 2021/01/21
update of TEST1 wrapper with an example of interface "get" and "set" with library arduino in case of enum and structure.
 

Attachments

  • Test_library.zip
    10.4 KB · Views: 419
  • B4Rlibrary2_tool.zip
    19.1 KB · Views: 476
  • B4Rlibrary_guide v3_c.pdf
    226.9 KB · Views: 476
  • TEST1_library.v2.zip
    11 KB · Views: 400
Last edited:

hatzisn

Expert
Licensed User
Longtime User
Maybe this should be moved to tutorials.
 

Laurent95

Active Member
Licensed User
Longtime User
Hi,
Interesting, that always gave me headache to try to wrap some librairies in B4R.
Hopefully that this will help us for good bases in futur, thank you for the work ?

And for PSPad Editor, good choice, it will allow me to use it in web servers implementation for the html, css, js code.
The cherry on the cake as we're habit to say in France ;)

Have a nice day.
Laurent
 

Michael1968

Active Member
Licensed User
Longtime User
Hi,
i'm new in wrapping librarys
I would test the script...very interesting..great work..but
if i select the lib in the library manager i get an error "Error parsing librarys"
i have changed some calls and recompile..but i could not finde the problem.

i have attach my example lib .
 

Attachments

  • rAXP192.zip
    8.6 KB · Views: 394

candide

Active Member
Licensed User
i think we have a few things to change to make rAXP192 working :
- in all files created we have " __attribute__((deprecated))" we have to remove this part in .cpp.clean file
- in new cpp file we have "void B4RAXP192::SetCoulombClear(?? )" => we need "void B4RAXP192::SetCoulombClear( )"
in arduino h file we have "void B4RAXP192::DeepSleep(uint64_t time_in_us)" but uint64_t (8 bytes) don't exist in B4X. We can try Ulong (4 bytes) on B4R side if 4 bytes is enought or 2 Ulong, or an array if 8 bytes are needed...
in arduino h file we have "void Read6BytesStorage( uint8_t * bufPtr );" buf content is sent back from arduino library to B4X: we have to modify manually this part to make it working.

version in attached file seem correct, but i have issue at compilation B4R with library AXP192 added

Vérification...
D:\B4R\BAR_AP~1\TEST_A~1\Objects\bin\sketch\AXP192.cpp: In member function 'void AXP192::begin(bool, bool, bool, bool, bool)':
AXP192.cpp:10:5: error: 'Wire1' was not declared in this scope
Wire1.begin(21, 22);
^
D:\B4R\BAR_AP~1\TEST_A~1\Objects\bin\sketch\AXP192.cpp: In member function 'void AXP192::Write1Byte(uint8_t, uint8_t)':
AXP192.cpp:63:5: error: 'Wire1' was not declared in this scope
Wire1.beginTransmission(0x34);
^
D:\B4R\BAR_AP~1\TEST_A~1\Objects\bin\sketch\AXP192.cpp: In member function 'uint8_t AXP192::Read8bit(uint8_t)':
AXP192.cpp:71:5: error: 'Wire1' was not declared in this scope
Wire1.beginTransmission(0x34);

=> i have same issue when i try to use same library in Arduino directly, it seems not linked with B4R

sketch\AXP192.cpp: In member function 'void AXP192::begin(bool, bool, bool, bool, bool)':
sketch\AXP192.cpp:10:5: error: 'Wire1' was not declared in this scope
Wire1.begin(21, 22);
^
sketch\AXP192.cpp: In member function 'void AXP192::Write1Byte(uint8_t, uint8_t)':
sketch\AXP192.cpp:63:5: error: 'Wire1' was not declared in this scope
Wire1.beginTransmission(0x34);
^
sketch\AXP192.cpp: In member function 'uint8_t AXP192::Read8bit(uint8_t)':
sketch\AXP192.cpp:71:5: error: 'Wire1' was not declared in this scope
Wire1.beginTransmission(0x34);


gook luck for next step
 

Attachments

  • rAXP192.zip
    8.1 KB · Views: 406
Last edited:

Michael1968

Active Member
Licensed User
Longtime User
i think we have a few things to change to make rAXP192 working :
- in all files created we have " __attribute__((deprecated))" we have to remove this part in .cpp.clean file
- in new cpp file we have "void B4RAXP192::SetCoulombClear(?? )" => we need "void B4RAXP192::SetCoulombClear( )"
in arduino h file we have "void B4RAXP192::DeepSleep(uint64_t time_in_us)" but uint64_t (8 bytes) don't exist in B4X. We can try Ulong (4 bytes) on B4R side if 4 bytes is enought or 2 Ulong, or an array if 8 bytes are needed...
in arduino h file we have "void Read6BytesStorage( uint8_t * bufPtr );" buf content is sent back from arduino library to B4X: we have to modify manually this part to make it working.

version in attached file seem correct, but i have issue at compilation B4R with library AXP192 added

Vérification...
D:\B4R\BAR_AP~1\TEST_A~1\Objects\bin\sketch\AXP192.cpp: In member function 'void AXP192::begin(bool, bool, bool, bool, bool)':
AXP192.cpp:10:5: error: 'Wire1' was not declared in this scope
Wire1.begin(21, 22);
^
D:\B4R\BAR_AP~1\TEST_A~1\Objects\bin\sketch\AXP192.cpp: In member function 'void AXP192::Write1Byte(uint8_t, uint8_t)':
AXP192.cpp:63:5: error: 'Wire1' was not declared in this scope
Wire1.beginTransmission(0x34);
^
D:\B4R\BAR_AP~1\TEST_A~1\Objects\bin\sketch\AXP192.cpp: In member function 'uint8_t AXP192::Read8bit(uint8_t)':
AXP192.cpp:71:5: error: 'Wire1' was not declared in this scope
Wire1.beginTransmission(0x34);

=> i have same issue when i try to use same library in Arduino directly, it seems not linked with B4R

sketch\AXP192.cpp: In member function 'void AXP192::begin(bool, bool, bool, bool, bool)':
sketch\AXP192.cpp:10:5: error: 'Wire1' was not declared in this scope
Wire1.begin(21, 22);
^
sketch\AXP192.cpp: In member function 'void AXP192::Write1Byte(uint8_t, uint8_t)':
sketch\AXP192.cpp:63:5: error: 'Wire1' was not declared in this scope
Wire1.beginTransmission(0x34);
^
sketch\AXP192.cpp: In member function 'uint8_t AXP192::Read8bit(uint8_t)':
sketch\AXP192.cpp:71:5: error: 'Wire1' was not declared in this scope
Wire1.beginTransmission(0x34);


gook luck for next step

many thanks for your help

after remove DeepSleep i can compile in b4r without problem.
now i can check the functions.
next step for me is to compare my code with your code to understand the different and create the wraper again by myself.
did you make any changes in your vbscript?

THX
best regards
Michael:):D
 
Last edited:

candide

Active Member
Licensed User
update 2020/01/12
new version with less issues and able to manage creation of wrapper with or without backend, able to create 3 loop in wrapper to monitor event in library and to launch a sub in B4R and to create also 3 callback from library when events from library are provided by callback.

the tool is based on a vbs script running in PSPad editor.
a guide can help at understanding of the tool
2 examples of libraries Test and TEST1 are available with B4R project to test the tool and to create/analyze several cases of interface between arduino library and B4R.

all files are in the first post
 

highflyer

Member
Licensed User
Longtime User
Hello Candide, while trying to create a wrapper for a TFT library, at the second step (Create new CPP file) I get the following error:

error.png
 

candide

Active Member
Licensed User
please to provide xxx.cpp.clean file created from cpp file arduino, and i will check, something is not correct on line 259.

or you can provide link to this library and i will check what we can do
 

highflyer

Member
Licensed User
Longtime User
In attachment the oiginal .h and the .h.clean files....
 

Attachments

  • TFT_SPI.zip
    19 KB · Views: 378

candide

Active Member
Licensed User
more than 250 functions, 2 class and several extensions, i am not sure we can create a wrapper for this type of library :confused:

i will check if i can do something, but i am not sure to have enough knowledge for this big challenge.
 

pucki

Active Member
Licensed User
Longtime User
Hi
I wanted to create a wrapper for the library attached below, but your tool only shows me the error message (see attached image).

Can you help me with that.

https://github.com/DFRobot/DFRobotDFPlayerMini

Since the forum doesn't show me the attachment, here's a link to it to be on the safe side.

Greetings

Pucki

ps: Sorry for my bad english, i use google translator to make it easier to understand.
 

Attachments

  • Error-1.jpg
    Error-1.jpg
    117.8 KB · Views: 228

candide

Active Member
Licensed User
i agree, it is not simple to create a wrapper, and this tool is only to help.

to explain a little :
with the script "clean arduino h file" you should have result like below in "DFRobotDFPlayerMini.h.clean_first.txt"

in this file we have to remove everything between "class" and "public" and file will like be "DFRobotDFPlayerMini.h.clean_final.txt"

after i can run"create new cpp file" and i have file "rDFRobotDFPlayerMini.cpp"
(no error in my case)
in case of error, in windows in the back, you have inputs to understand where is the problem, minimal is last line managed by the script.
to show this LOG windows, go in PSP menu "windows" and active "Show/Hide LOG window"

if you look at new cpp file and if you search for "??" you can see an error in creation:
bool B4RDFRobotDFPlayerMini::begin(?? Stream& stream, bool isACK, bool doReset)
{
return dfrobotdfplayermini.begin(?? Stream& stream, isACK, doReset);
}
=> a stream cannot come directly from B4R
on this point, we have 2 ways :
or we create Serial/SoftwareSerial links in wrapper, and in B4R project we have to provide index of Serial to create
or we have to convert BARStream to Stream. and Serial/SoftwareSerial can be created in B4R project.

Sorry, i didn't do more yet...
 

Attachments

  • DFRobotDFPlayerMini.h.clean_first.txt
    4.2 KB · Views: 244
  • DFRobotDFPlayerMini.h.clean_end.txt
    3.4 KB · Views: 252
  • rDFRobotDFPlayerMini.cpp.txt
    7.6 KB · Views: 218
Last edited:

candide

Active Member
Licensed User
to continue on DFRobotDFPlayerMini library , we can try management of stream in this way:
B4X:
    bool B4RDFRobotDFPlayerMini::begin(B4RStream* stream, bool isACK, bool doReset)
    {
       return dfrobotdfplayermini.begin(*stream->wrappedClient, isACK, doReset);
    }

and we can create h file and html file (files added)

after, we can install this library in rDFRobotDFPlayerMini directory, with other libraries. html file will be added with others html files.

B4R is launched, and rDFRobotDFPlayerMini is available
we can create a new project like "test_DFRobotDFPlayerMini"

first, library is added to project
=> we can check if no error found in html file read
=> we can compile the project, just to see if compilation of new library is OK
if no issue, we can try to use this library.
basic code can be something like that :
B4X:
Sub Process_Globals
    Public Serial1 As Serial
    Private wifi As ESP8266WiFi
    Private DFP As DFRobotDFPlayerMini
    Private SSerial1 As SoftwareSerial
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    SSerial1.Initialize(9800, 12, 14)
    DFP.begin(SSerial1.Stream,True,True)
    Log("AppStart")
    'example of connecting to a local network
    If wifi.Connect2("SSID", "PASSWORD") Then
        Log("Connected to network")
    Else
        Log("Failed to connect to network")
    End If
End Sub
if compilation is Ok, we can suppose library is OK. Next step is to test with hard.

Please to try if it is working !
 

Attachments

  • rDFRobotDFPlayerMini.cpp.txt
    7.6 KB · Views: 274
  • rDFRobotDFPlayerMini.h.txt
    4.2 KB · Views: 231
  • rDFRobotDFPlayerMini.xml.txt
    14.9 KB · Views: 221
  • rDFRobotDFPlayerMini.zip
    25.4 KB · Views: 217

pucki

Active Member
Licensed User
Longtime User
Thank you

in test it, and say then in if in works

Greating

Pucki
 
Top