Share My Creation a tool to store strings and binaries in inline code with PROGMEM

i created a small tool to move automatically string from code to PROGMEM part and creating the inline part.

this tool is a script running on pspad.
- first you have to install this script in pspad (in directory pspad/Script/VBScript) and to run "recompile scripts".
after, a menu Script is availabe with submenus:
- Scripts => B4R => "PROGMEM create"
- Scripts => B4R => "PROGMEM remove"
- Scripts => B4R => "PROGMEM Extract strings"
- Scripts => B4R => "Create Static.bas"
- Scripts => B4R => "Gzip => Static.bas"
- Scripts => B4R => "text => Static.bas"
- Scripts => B4R => "Static.bas => Gzip file"

with both scripts you can add PROGMEM at your code and remove it after if needed. Script ares in VBS, easy to modify to adapt at your need

- after, you can load your code B4R in pspad
- you have to add a tag on each line where you want a string moving to PROGMEM
5 tags are available : '<str1> '<str2> '<str3> '<str4> '<str5> to store strings in 5 different tables
- and with file B4R active, you can run in menu PROGMEM create
=> it will create a new file where string highlighted by a tag are removed from code and moved to inline part.
=> inline part is created
=> sub P_get(a, b) is created to extract a string and to move it to P_buff
=> P_buff is added in Sub Process_Globals
=> inline routings are added

- you can check file created because with PROGMEM, we recover the strings in P_buff (Arraybyte buffer) and some modifications in your code will be needed
=> if we can use string in P_buff in ArrayByte format, code with PROGMEM don't use more stack.
=> if we have to us bc.stringfrombyte, we will quickly need 6000bytes in stack, we have to avoid !
=> each time we have to modify ArrayByte to String, it is better to use a dedicated sub


it is a tool for my usage, but you can check if it can help you also


one example is provided with the script : 2 test code for rAWOT library , one without PROGMEM, and one created with PROGMEM

12/12/2021 new version including creation of static.bas file with binary or text files included in PROGMEM srtructure
21/12/2021 new version with option to extract a Gzip/png/jpg file from PROGMEM structure. (B4R module or arduino.h)
 

Attachments

  • B4Rprogmem_v3.zip
    8.3 KB · Views: 219
Last edited:

candide

Active Member
Licensed User
12/12/2021 new version with 5 scripts:
this tool is a script running on pspad.
- first you have to install this script in pspad (in directory pspad/Script/VBScript) and to run "recompile scripts".
after, a menu Script is availabe with submenus:
- Scripts => B4R => "PROGMEM create"
- Scripts => B4R => "PROGMEM remove"
- Scripts => B4R => "PROGMEM Extract strings"
- Scripts => B4R => "Create Static.bas"
- Scripts => B4R => "Gzip => Static.bas"
- Scripts => B4R => "text => Static.bas"

Scripts description::
1) Scripts => B4R => "PROGMEM create"
move automatic of a project with strings in the code to a project with strings in PROGMEM
open with PSPad the project xxxx.B4R
after, on each line with a string to move we have to add a tag '<str1>, '<str2>, '<str2> to '<str15>
efter run the script B4R => PROGMEM Create
- a PROGMEM structure is added
- the first string on each lines highligted by a tag will be moved to a PROGMEM structure
- in code string is replaced
exemple of transfert:
- before:
Sub m6_authorization(index As Byte)
aWOT.res_println("<html>") '<str1>
aWOT.res_println("<head>") '<str1>
aWOT.res_println("<meta charset='utf-8'>") '<str1>
- after:
Sub m6_authorization(index As Byte)
P_get(1,0):aWOT.res_println1(P_buff) '<str1>
P_get(1,1):aWOT.res_println1(P_buff) '<str1>
P_get(1,2):aWOT.res_println1(P_buff) '<str1>
and in the back of the filr
#if C
#include <avr/pgmspace.h>
char strx[164];
const char str1_0[] PROGMEM = "<html>";
const char str1_1[] PROGMEM = "<head>";
const char str1_2[] PROGMEM = "<meta charset='utf-8'>";
const char str1_3[] PROGMEM = "<style>";

2) Scripts => B4R => "PROGMEM remove"
move of strings from PROGMEM to code
run the script B4R => PROGMEM Remove
it make inverse transfert

3) Scripts => B4R => "PROGMEM Extract strings"
extract strings from PROGMEM to a texte file
it is easy after to create several files with the texte of application, to store it in flash with LittleFS
run PROGMEM Extract
- a new file is created with all strings in PROGMEM, one string by line.
- it is easy after to create several file with strings divided by fonction

4) Scripts => B4R => "Create Static.bas"
Create a static file "static.bas empty
it is base to add PROGMEM content in text format like index.htm or in binary format like gzip files of pictures
run B4R => Create static.bas

5) Scripts => B4R => "Gzip => Static.bas"
Add gzip, png, jpg or others binary files in static.bas file in MROGMEM format
a file static.bas must be created and open and active in PSPad
this script open a dialog box to select a file and it is added in static.bas file under PROGMEM format
you can add several files one by one, 20 binary files max with this script
run B4R => gzip => static.bas
- the file is added in static.bas file, in a PROGMEM structure ready to use
- a function GetByte(table, index) is created/updated to read hte file byte by byte
- a function GetLength(Table) is created/updated to interrogate the length of file

6) Scripts => B4R => "text => Static.bas"
Add texte files in static.bas file in PROGMEM format
this script open a dialog box to select a text file and it is added in static.bas file under PROGMEM format
you can add several files one by one, 20 text files max with this script
run B4R => txt => static.bas
- the file is added in a static.bas file, in a PROGMEM structure for strings
- a function Getstring(table, index) is created/updated to read strings one by one and to push it in buffer P_buff
- a buffer P_buff is available to read a string after GetString

at end, we have a static.bas file and if we rename it in P.bas, it is ready to be integreted in a B4R project.
if you want an other name than P.bas, for PROGMEM used for stringss,you will have to do some small modifications on C code
- " b4r_p::_p_buff->data = strx;" if P_buff is in a module P.bas
- " b4r_static::_p_buff->data = strx;" if P_buff is in a module Static.bas
- " b4r_main::_p_buff->data = strx;" if P_buff is in main.bas file

for binary files, we have 2 functions:
- P.GetByte(table, index)
will give a byte stored in P.bas file
- P.Getlength(table)
will provide length of table

for text file, we have a function and strings will be available in a buffer
- P.Getstring(table, index)
will give a string pointed by table + index
- P.P_buff is the buffer where string is available

new file added on top of thread
 
Top