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

added functions in the js interpreter, more serial cmds (not ready to merge) #226

Closed
wants to merge 0 commits into from

Conversation

eadmaster
Copy link
Contributor

@eadmaster eadmaster commented Aug 27, 2024

added:

  • JS functions serialPrintln(string), serialCmd(string), playAudioFile(filename), tone(freq, duration), irTransmitFile(filename), subghzTransmitFile(filename), badusbRunFile(filename), badusbSetup(), badusbPrint(string), badusbPress(keycode), badusbHold(keycode), badusbRelease(keycode), irRead(), subghzSetFrequency(freq_as_float), subghzRead(), dialogMessage(msg), dialogError(msg), dialogPickFile(path), dialogViewFile(path), keyboard(), storageRead(path), storageWrite(path, data), exit() (wiki page to be updated with full docs)
  • added CRC32 and MD5 in file manager, "Run JS" launcher
  • new serial commands: storage md5, storage crc32, storage write, webui, subghz|badusb tx_from_buffer
  • hardcoded serial cmd aliases: ls, dir, rm, del, md, cat, type, play, rf, bu, set, decrypt, run
  • global wifiIP address var, SAFE_STACK_BUFFER_SIZE

@eadmaster
Copy link
Contributor Author

@bmorcelli : any idea why this exit function is not working?

I'd like a function to exit from a JS script from within the script itself.

@Niximkk
Copy link
Contributor

Niximkk commented Aug 27, 2024

Can we have the audio related functions on the interpreter too? 🥺

@eadmaster
Copy link
Contributor Author

eadmaster commented Aug 27, 2024

Can we have the audio related functions on the interpreter too? 🥺

as alternative, to reduce extra code wrapping, you can do this in a js script:

serialCmd("music_player myfile.wav")
serialCmd("tone 500 500")

EDIT: btw for better readability i could add a wrapper to this.

@Niximkk
Copy link
Contributor

Niximkk commented Aug 27, 2024

i see, really smart...

@eadmaster
Copy link
Contributor Author

i'm adding more JS functions, most of them are just serial cmd wrappers, some are not.

@eadmaster eadmaster changed the title added serial functions in the js interpreter, more serial cmds added serial functions in the js interpreter, more serial cmds (not ready to merge) Aug 27, 2024
@bmorcelli
Copy link
Collaborator

@bmorcelli : any idea why this exit function is not working?

I'd like a function to exit from a JS script from within the script itself.

Learned something new about this functionality... once you start it, it won't pass through the loop again, until an error is sent into the exit...

So This line

goto END;

can be changed to interpreter_start= false;

and these conditions

if(!checkPrevPress() && !checkNextPress()) interpreter_start=false;

can be deleted.. I will comment this in the review

use the exit function like this, and it will work ok:

static duk_ret_t native_exit(duk_context *ctx) {
  duk_error(ctx, DUK_ERR_ERROR, "Script exited by user request");  // This will make the JavaSccript code to stop running
  interpreter_start= false; // for now it will make the loop function on main.cpp to go to the main while().
  return 0;
}

Use this for now and I will make some changes into the Ibnterpreter workflow after we merge your additions.

Comment on lines 472 to 475
if(!checkPrevPress() && !checkNextPress()) interpreter_start=false;
#if defined (CARDPUTER)
if(checkEscPress()) interpreter_start=false;
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

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

These conditions can be deleted

src/main.cpp Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

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

The goto End; in line 362 must be replaced by: interpreter_start=false;

Copy link
Contributor Author

@eadmaster eadmaster Aug 28, 2024

Choose a reason for hiding this comment

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

just tried those changes, but exit() still does not work .

In the meanwhile i've added some high-level Dialog and Storage functions.

@eadmaster
Copy link
Contributor Author

Any suggestion for the Core series envs failing to build due to insufficient iram0?

@eadmaster eadmaster changed the title added serial functions in the js interpreter, more serial cmds (not ready to merge) added functions in the js interpreter, more serial cmds (not ready to merge) Aug 27, 2024
Comment on lines 5 to 8
#include "core/serialcmds.h"
#include "modules/rf/rf.h"
#include "modules/ir/ir_read.h"
#include "modules/others/bad_usb.h"
Copy link
Collaborator

@bmorcelli bmorcelli Aug 27, 2024

Choose a reason for hiding this comment

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

try adding
#pragma once
in the firs line of these header files.. if it works, add them into all .h files

an in all core files

@bmorcelli
Copy link
Collaborator

Now, looking deep i to the code, I suspect that the IRAM problem of the Core Devices is the calling of all these libs in the passwords.h/cpp

I am studying a way to enhance that, but I think we should not add more core functionalities with new libs... StickCs are already at 98% of iram memory as well

@bmorcelli
Copy link
Collaborator

If the goal os protect the passwords saved in the bruce.conf file, I think we should use a simpler solution, nothing so fancy, atm..

Im trying to get BLE functions back to the stock Arduino libs to release some more IRAM memory.. so maybe this AES encryption/decryption function needs to be adopted in a near future

@eadmaster
Copy link
Contributor Author

eadmaster commented Aug 28, 2024

i'll try to comment some stuff in serialcmds.cpp too, i can remove the cjson dep.

For the password stuff, these could be used to store user custom secrets as well:
#123

If it turns out mbed aes is taking too much iram, i could use another lib.

EDIT: building with LITE_VERSION=1 on these old core boards won't solve the problem?

@bmorcelli
Copy link
Collaborator

LITE_VERSION may "solve" it..

But for this password encryption I think that simple math solutions might be better than using dedicated libs

It isn't a bank password to spend a lot of resources..

I think that if we use simple base64, Ceasar Cypher, or even a bit or 2 left shift would be enough for this application, and won't use a lot of resources..

The ideia of saving the passwords in plain text is to give the StickC users to edit this file in the computer and upload again to the device avoiding typing (that for these devices is fkng annoying).. if we encrypt it, it won't be possible to use this way

@eadmaster
Copy link
Contributor Author

But for this password encryption I think that simple math solutions might be better than using dedicated libs

I've tried removing the password module completely and commenting some stuff in serialcmd, but it is still failing to build:

$ pio run -e m5stack-core4mb
...
/home/andy/github/Bruce/.pio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/m5stack-core4mb/firmware.elf section `.iram0.text' will not fit in region `iram0_0_seg'
/home/andy/github/Bruce/.pio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: IRAM0 segment data does not fit.
/home/andy/github/Bruce/.pio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: region `iram0_0_seg' overflowed by 1428 bytes
collect2: error: ld returned 1 exit status
*** [.pio/build/m5stack-core4mb/firmware.elf] Error 1

with LITE_VERSION=1 it's still not enough.

@bmorcelli
Copy link
Collaborator

@eadmaster
Copy link
Contributor Author

eadmaster commented Aug 28, 2024

Try removing this library https://github.com/eadmaster/Bruce/blob/fa239bd7551e76e7a210865d2b1092ca8087f716/platformio.ini#L69

did not work, only adding more features into lite mode worked for me (all RF features or all BT features).

@bmorcelli
Copy link
Collaborator

Ok, then..

I will keep researching a way to reduce the IRAM usage

@bmorcelli
Copy link
Collaborator

I will wait you deploy your changes to the interpreter, so then I look into the exit function.. I've tested it the way I sent you and did work for me..

@bmorcelli
Copy link
Collaborator

bmorcelli commented Aug 29, 2024

In my research I found that this is an ESP32 problem with the linker, many functions are being stored in IRAM instead of flash, and it doesn't happen with ESP32-S3 chips...

Maybe downgrading to older versions of platformio Arduino-esp32 framework can help with it, or recompile the libraries (I have some experience with this subject) with proper changes to use with these devices . References

I've added some linker flags in the last PR to monitor the ram memory usage, and differences are huge between esp32 (~99%) and esp32s3 (~28%)

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.

3 participants