From 24e0dbdb98587b30a4cfde1596a4358db0b11182 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Mon, 4 Sep 2023 17:41:07 +0300 Subject: [PATCH 01/17] FAST AF ljinux.api.isdir() --- source/ljinux.py | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/source/ljinux.py b/source/ljinux.py index 4f850671..76ecf074 100644 --- a/source/ljinux.py +++ b/source/ljinux.py @@ -224,7 +224,7 @@ def clear_process_storage() -> None: import busio from microcontroller import cpu from storage import remount, VfsFat, mount, getmount - from os import chdir, rmdir, mkdir, sync, getcwd, listdir, remove, sync + from os import chdir, rmdir, mkdir, sync, getcwd, listdir, remove, sync, stat from math import trunc import time @@ -693,31 +693,21 @@ def isdir(dirr, rdir=None): """ res = 2 - bckdir = getcwd() while dirr.endswith("/") and (dirr != "/"): dirr = dirr[:-1] - if rdir is None: - if "/" in dirr and dirr not in ["/", "&/"]: - rdir = dirr[: dirr.rfind("/")] - if not len(rdir): - rdir = "/" - dirr = dirr[dirr.rfind("/") + 1 :] - cddd = ljinux.api.betterpath(rdir) - else: - cddd = bckdir - else: - cddd = ljinux.api.betterpath(rdir) - dirr = ljinux.api.betterpath(dirr) - chdir(cddd) # We assume ref dir exists + olddir = getcwd() + if rdir is not None: + chdir(ljinux.api.betterpath(rdir)) + del rdir try: - chdir(dirr) - chdir(bckdir) - res = 1 # It's a dir - except OSError: # we are still in cddd - if dirr in listdir(): + if stat(ljinux.api.betterpath(dirr))[0] == 32768: res = 0 - chdir(bckdir) - del cddd, rdir, dirr, bckdir + else: + res = 1 + except OSError: + pass + chdir(olddir) + del olddir return res def betterpath(back=None): From 88f8b75f1fabc8a33415afb4a8005e97cd4048b7 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Sat, 9 Sep 2023 00:35:07 +0300 Subject: [PATCH 02/17] Add ftp --- .gitmodules | 3 +++ other/CircuitPython_FTP_Server | 1 + 2 files changed, 4 insertions(+) create mode 160000 other/CircuitPython_FTP_Server diff --git a/.gitmodules b/.gitmodules index 2eb48d4a..a83f65ce 100644 --- a/.gitmodules +++ b/.gitmodules @@ -25,3 +25,6 @@ [submodule "other/cptoml"] path = other/cptoml url = https://github.com/bill88t/cptoml +[submodule "other/CircuitPython_FTP_Server"] + path = other/CircuitPython_FTP_Server + url = https://github.com/bill88t/CircuitPython_FTP_Server diff --git a/other/CircuitPython_FTP_Server b/other/CircuitPython_FTP_Server new file mode 160000 index 00000000..07682477 --- /dev/null +++ b/other/CircuitPython_FTP_Server @@ -0,0 +1 @@ +Subproject commit 0768247717650620a0e16f9e2ad5304bb599edbd From 30bb28f38071f99540f5a65b20cc8745b2d84d26 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Sat, 9 Sep 2023 11:39:39 +0300 Subject: [PATCH 03/17] Add repl.py --- rootfilesystem/repl.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 rootfilesystem/repl.py diff --git a/rootfilesystem/repl.py b/rootfilesystem/repl.py new file mode 100644 index 00000000..37bbf625 --- /dev/null +++ b/rootfilesystem/repl.py @@ -0,0 +1,12 @@ +import board +import digitalio +import microcontroller +import sys +import os + +try: + import wifi +except ImportError: + pass + +print("\x1b[2J\x1b[3J\x1b[HWelcome to the ljinux REPL environment!") From 8c42411135e64f404bf5c7c7ac6a62be0d1913ee Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Sat, 9 Sep 2023 11:40:46 +0300 Subject: [PATCH 04/17] Exit to ftp mode --- other/binextra/netutils/ftpd.lja | 1 + other/binextra/netutils/ftpd.py | 7 +++++++ rootfilesystem/ftp_serv.py | 20 ++++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 other/binextra/netutils/ftpd.lja create mode 100644 other/binextra/netutils/ftpd.py create mode 100644 rootfilesystem/ftp_serv.py diff --git a/other/binextra/netutils/ftpd.lja b/other/binextra/netutils/ftpd.lja new file mode 100644 index 00000000..3b2440a9 --- /dev/null +++ b/other/binextra/netutils/ftpd.lja @@ -0,0 +1 @@ +fpexec /bin/ftpd.py diff --git a/other/binextra/netutils/ftpd.py b/other/binextra/netutils/ftpd.py new file mode 100644 index 00000000..6f24f941 --- /dev/null +++ b/other/binextra/netutils/ftpd.py @@ -0,0 +1,7 @@ +rename_process("ftpd") +term.write("Exiting to FTP..") +from supervisor import set_next_code_file + +set_next_code_file("ftp_serv.py") +del set_next_code_file +ljinux.based.run("reload") diff --git a/rootfilesystem/ftp_serv.py b/rootfilesystem/ftp_serv.py new file mode 100644 index 00000000..3141ea0d --- /dev/null +++ b/rootfilesystem/ftp_serv.py @@ -0,0 +1,20 @@ +import wifi +from socketpool import SocketPool +from ftp_server import ftp +from supervisor import reload + +if not wifi.radio.connected: + print("No wifi") + reload() + +pool = SocketPool(wifi.radio) +ftps = ftp(pool, str(wifi.radio.ipv4_address)) +print("Starting Ljinux ftp server..") +try: + ftps.serve_till_quit() +except KeyboardInterrupt: + pass +finally: + ftps.deinit() +print("Reloading Ljinux..") +reload() From c804db7dafe78f3eca028358fab0392c381a7099 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Sat, 9 Sep 2023 11:43:16 +0300 Subject: [PATCH 05/17] Enable ftp for the boards. --- .../extras/CircuitPython_FTP_Server.src.ftp_server.other | 0 .../extras/CircuitPython_FTP_Server.src.ftp_server.other | 0 .../extras/CircuitPython_FTP_Server.src.ftp_server.other | 0 .../extras/CircuitPython_FTP_Server.src.ftp_server.other | 0 .../extras/CircuitPython_FTP_Server.src.ftp_server.other | 0 .../extras/CircuitPython_FTP_Server.src.ftp_server.other | 0 .../extras/CircuitPython_FTP_Server.src.ftp_server.other | 0 .../extras/CircuitPython_FTP_Server.src.ftp_server.other | 0 .../extras/CircuitPython_FTP_Server.src.ftp_server.other | 0 9 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 Boardfiles/adafruit_feather_esp32s2/extras/CircuitPython_FTP_Server.src.ftp_server.other create mode 100644 Boardfiles/adafruit_feather_esp32s3_tft/extras/CircuitPython_FTP_Server.src.ftp_server.other create mode 100644 Boardfiles/beetle-esp32-c3/extras/CircuitPython_FTP_Server.src.ftp_server.other create mode 100644 Boardfiles/lolin_s2_mini/extras/CircuitPython_FTP_Server.src.ftp_server.other create mode 100644 Boardfiles/m5stack_timer_camera_x/extras/CircuitPython_FTP_Server.src.ftp_server.other create mode 100644 Boardfiles/raspberry_pi_pico_w/extras/CircuitPython_FTP_Server.src.ftp_server.other create mode 100644 Boardfiles/waveshare_esp32s2_pico/extras/CircuitPython_FTP_Server.src.ftp_server.other create mode 100644 Boardfiles/yd_esp32_s3_n16r8/extras/CircuitPython_FTP_Server.src.ftp_server.other create mode 100644 Boardfiles/yd_esp32_s3_n8r8/extras/CircuitPython_FTP_Server.src.ftp_server.other diff --git a/Boardfiles/adafruit_feather_esp32s2/extras/CircuitPython_FTP_Server.src.ftp_server.other b/Boardfiles/adafruit_feather_esp32s2/extras/CircuitPython_FTP_Server.src.ftp_server.other new file mode 100644 index 00000000..e69de29b diff --git a/Boardfiles/adafruit_feather_esp32s3_tft/extras/CircuitPython_FTP_Server.src.ftp_server.other b/Boardfiles/adafruit_feather_esp32s3_tft/extras/CircuitPython_FTP_Server.src.ftp_server.other new file mode 100644 index 00000000..e69de29b diff --git a/Boardfiles/beetle-esp32-c3/extras/CircuitPython_FTP_Server.src.ftp_server.other b/Boardfiles/beetle-esp32-c3/extras/CircuitPython_FTP_Server.src.ftp_server.other new file mode 100644 index 00000000..e69de29b diff --git a/Boardfiles/lolin_s2_mini/extras/CircuitPython_FTP_Server.src.ftp_server.other b/Boardfiles/lolin_s2_mini/extras/CircuitPython_FTP_Server.src.ftp_server.other new file mode 100644 index 00000000..e69de29b diff --git a/Boardfiles/m5stack_timer_camera_x/extras/CircuitPython_FTP_Server.src.ftp_server.other b/Boardfiles/m5stack_timer_camera_x/extras/CircuitPython_FTP_Server.src.ftp_server.other new file mode 100644 index 00000000..e69de29b diff --git a/Boardfiles/raspberry_pi_pico_w/extras/CircuitPython_FTP_Server.src.ftp_server.other b/Boardfiles/raspberry_pi_pico_w/extras/CircuitPython_FTP_Server.src.ftp_server.other new file mode 100644 index 00000000..e69de29b diff --git a/Boardfiles/waveshare_esp32s2_pico/extras/CircuitPython_FTP_Server.src.ftp_server.other b/Boardfiles/waveshare_esp32s2_pico/extras/CircuitPython_FTP_Server.src.ftp_server.other new file mode 100644 index 00000000..e69de29b diff --git a/Boardfiles/yd_esp32_s3_n16r8/extras/CircuitPython_FTP_Server.src.ftp_server.other b/Boardfiles/yd_esp32_s3_n16r8/extras/CircuitPython_FTP_Server.src.ftp_server.other new file mode 100644 index 00000000..e69de29b diff --git a/Boardfiles/yd_esp32_s3_n8r8/extras/CircuitPython_FTP_Server.src.ftp_server.other b/Boardfiles/yd_esp32_s3_n8r8/extras/CircuitPython_FTP_Server.src.ftp_server.other new file mode 100644 index 00000000..e69de29b From 532cfc7e3e6b9ad8df1a206fcc3c465f0cd099d6 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Sat, 9 Sep 2023 11:43:50 +0300 Subject: [PATCH 06/17] Up the jpkg api version in help --- LjinuxRoot/etc/jpkg/data/help.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LjinuxRoot/etc/jpkg/data/help.txt b/LjinuxRoot/etc/jpkg/data/help.txt index 9959b4a8..cb15bda7 100644 --- a/LjinuxRoot/etc/jpkg/data/help.txt +++ b/LjinuxRoot/etc/jpkg/data/help.txt @@ -1,4 +1,4 @@ -Ljinux package manager version 0. +Ljinux package manager version 1. Usage: jpkg install package_file.jpkg From 2624dacdb08c30b750ba8ca76a1a868c7355ec38 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Sat, 9 Sep 2023 23:12:44 +0300 Subject: [PATCH 07/17] A tiny addition to gitignore. --- .gitignore | 1 + Manual.txt | 264 +++++++++++++++++++++++++++++++++++------------------ 2 files changed, 178 insertions(+), 87 deletions(-) diff --git a/.gitignore b/.gitignore index 46f4f4df..7ac83e1d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ source/build_* *.pyc *.xml *.iml +.directory diff --git a/Manual.txt b/Manual.txt index b55dbb29..7b24eea0 100644 --- a/Manual.txt +++ b/Manual.txt @@ -5,13 +5,35 @@ Official repository: [https://github.com/bill88t/ljinux] +Index table: +1. Basic commands : line +2. Scripting : line +3. Errors : line +4. Api functions : line +5. jCurses : line +6. Led activity : line +7. BetterPath : line +8. GPIO Usage : line +9. Network driver usage : line + /---------------| ----<| Basic commands | \---------------| -help [COMMAND] -Outputs a basic list of commands to serial out +alias [COMMAND=data] + +Runs data, whenever command is typed + + +bell + +Ring the bell on the current terminal + + +cat [file] + +Catenates the contents of file [file] cd [DIR]... @@ -20,12 +42,87 @@ Changes to specified directory Please refer to the betterpath section, on more info on how does the ljinux filesystem appear. +clear + +Clear the current terminal + + +date [set]... + +View the time, or set it +Valid format "date set dd mm yyyy hr mm ss" + + +detect + +Fetch the term.detect_size() for context updating + + +devmode [-q] + +Enables usb access and other development features. +This prohibits write access to the built in filesystem. +The notice can be skipped by passing -q. +This can be reverted by setting `usb_access = false` under +section [LJINUX] in the board's `/settings.toml`. + + +df [-h] + +Report all attached file system's space usage. + + +disconnect + +Immediately disconnect the current terminal, if it can be disconnected. + + +dmesg + +Prints out the current dmesg log. + + echo [DATA]... -Print some variables or text +Print some variables or text. + +ed [FILE] -var [DATA]... +A line-oriented text editor. + + +exit [CODE] + +Exits ljinux with an exit code, default = 0 +If ran over a remote connection, disconnects instead. + + +false + +Returns false. + + +free [-b/-k/-m/-g] + +Display memory usage. + + + + +--- +help [COMMAND] + +Outputs a basic list of commands to serial out + + + + + + + + +var [DATA]... (DEPRECATED, SOON TO BE REPLACED) Create a new variable. syntax: var a = "ok" Numbers do not need brackets. @@ -71,24 +168,6 @@ pwd Outputs the current directory -display [OPERATION] [OPERATION DATA] - -Displays something on the i2c display -Returns object id, do not lose it -Budget didnt allow porting wayland, so i made farland -operations: - -text -dot -line -rectangle -square -circle -rhombus -move -delete - - exec [FILE] Loads an .lja file and executes it's commands @@ -97,35 +176,23 @@ Loads an .lja file and executes it's commands pexec [-n] [python commands] Runs python commands --n suppresses the ciruitpy text -fpexec [-n] [file] +fpexec [file] -Same as pexec but uses a file instead +Runs a python file in a new process. -wait [TIME] +sleep [TIME] [TIME] in seconds -exit [CODE] -Exit the current process with an exit code, default = 0 -date [set]... - -View the time, or set it -Valid format "date set dd mm yyyy hr mm ss" -su - -Disable security, asks for password -Password can be found in /etc/passwd :) - neofetch @@ -137,22 +204,8 @@ history [save/load/clear] Displays the history -njinx - -An integrated webserver -Please configure /etc/njinx/njinx.conf beforehand -whois [name] - -Finds and returns the ip of the given domain. - - -devmode - -Enables usb access and other development features -This prohibits write access to the built in filesystem - reboot [mode] @@ -160,22 +213,17 @@ Reboots the microcontroller Optionally you can pass a reboot [mode] (safemode, uf2, bootloader) -dmesg - -Prints out the dmesg log -cat [file] -Prints the contents of file [file] -head [n] [file] +head [-n] [file] Print the first [-n number] lines of file [file]. -tail [n] [file] +tail [-n] [file] Print the last [-n number] lines of file [file]. @@ -200,39 +248,45 @@ detect Fetch the term.detect_size() for context updating -waitforserial +less [file] + +opposite for more, except we don't have more.. + + +reload + +Exit and immediately reload ljinux -Waits for a serial connection. Should absolutely be used into Init.lja if you're gonna use jcurses. -less [file] -opposite for more, except we don't have more.. /----------| ----<| Scripting | \----------| -Based script files need to have the .lja file extension. All internal or external commands can be used in scripts. +Based script files need to have the .lja file extension. All internal or external commands +can be used in scripts. To have a script appear as a command, put it in /LjinuxRoot/bin/ or in the /bin of the sdcard. -To create a comment, simply write COMMENT in the beginning of the line. To execute python code, you are advised to use pexec & fpexec. The scope is the same as the one of ljinux and you can call & alter ljinux data freely. +This however is very unsafe (as in, you may touch foreign variables), and you are instead advised +to use the given variable container storage. -To access argj from based scripts containing pexec, the best way is to use ljinux.based.user_vars["argj"].split() +When fpexec is called, the code is given an empty container storage under `pv[get_pid()]`. +You can manipulate it either directly or with the `vr` functions. More info in the Container Storage +section of the manual. - /---------------| -----<| Repo & Mirrors | - \---------------| +To access shell input you can use `ljinux.api.xarg()` or `ljinux.based.user_vars["argj"].split()`. +You can find more info regarding xarg under it's api documentation. -The source & releases of Ljinux are primarily being made available to Github at: https://github.com/bill88t/ljinux -However it is also mirrored to my self-hosted Gitea instance at: https://git.port1.cf/bill88t/ljinux /-------| ----<| Errors | \-------| + The different errors used by the based shell. CODE: ljinux.based.error([number]) @@ -255,13 +309,15 @@ CODE: The network interface is not functional 6 : Display not attached - The display is not connected correctly + The display is not connected / registered. -7 : Filesystem unwritable, pi in developer mode - This error shows up when a write to the internal storage occures while developer mode is enabled. +7 : Filesystem unwritable, board in developer mode + This error shows up when a write to the internal storage occures while developer mode + is enabled. By CircuitPython design, when the internal storage is being made available from usb, - it is unwritable to the os. - To disable developer mode, delete the file "devm" from the root of LJINUX, and run the command "reboot" + it is unwritable to ljinux. + To disable developer mode, set `usb_access = false` under section [LJINUX] in the board's + `/settings.toml`. 8 : Missing files This error occurs when files needed for the command to run are missing. @@ -279,7 +335,31 @@ CODE: The variable name specified is already in use, and can't be modified in this way. 13 : Terminal too small, minimum size: size: - The current terminal size is too small, resize the terminal to a size bigger than the one specified. + The current terminal size is too small, resize the terminal to a size bigger than + the one specified. + +14 : Is a file + What was passed, is a file, when it shouldn't. + +15 : Is a directory + What was passed, is a directory, when it shouldn't. + +16 : Directory not empty + The directory should have been empty, but wasn't. + +17 : Not a directory + What was passed, is not a directory, when it should. + +18 : Not a file + What was passed, is not a file, when it should. + +19 : Not a device + What was passed, is not a device, when it should. + +20 : Unhandled exception + Under fpexec execution, an exception was raised that was not caught by any code from within + the fpexec code, and it was instead caught by ljinux. + /--------------| ----<| Api Functions | @@ -360,8 +440,17 @@ Based, by default, creates the "term" jcurses object. Useful functions: + - .write(strr=str, end="\n") + The default write function for ljinux. + Always prints to the active terminal only. + + - .nwrite(strr=str) + Same as `.write`, but does not print "\n" at the end. + It saves byte size when there are 25 septilion `end=""`'s. + Always prints to the active terminal only. + - .detect_size() - Detects the size of the terminal & returns it as [rows, collumns] + Detects the size of the terminal & returns it as [rows, collumns] - .detect_pos() Detects the current cursor position & returns it as [row, collumn] @@ -425,9 +514,9 @@ It work by mapping: And treating all subsequent paths by that rule. It additionally maps "~" to the user's home directory, and "-" to the previous directory. - /-----------| -----<| GPIO Usage | - \-----------| + /-----------| [ ] +----<| GPIO Usage | [ DEPRECATED, SOON TO BE REPLACED!!! ] + \-----------| [ ] From within the based shell you can use the unused GPIO pins as variables. Example: @@ -453,28 +542,29 @@ Example 3: \---------------------| To use the built-in circuitpython module "wifi" as your network connection: - - Ensure you have run "make wifi" from the host computer. - If you haven't, run "devmode" from within ljinux, to enable usb access, - and perform the module installation. Then delete the file "devm" from - the board's root, and reboot ljinux. - Run "modprobe driver_wifi as network" to load the ljinux wifi driver. You can optionally add it to /boot/Init.lja, to load it on boot. - Use iwctl to configure the wifi connection. For info on how to use iwctl, please refer to [https://wiki.archlinux.org/title/iwd] + - You connections will automatically be stored into &/settings.toml. + You can automatically reconnect on reboot by running `iwctl station wifi auto`. + To use a w5500 ethernet module: - Ensure you have run "make w5500" from the host computer. If you haven't, run "devmode" from within ljinux, to enable usb access, - and perform the module installation. Then delete the file "devm" from - the board's root, and reboot ljinux. + and perform the module installation. Then disable developer mode (as stated above) + and reboot ljinux. - Run "modprobe driver_w5500 as network" to load the ljinux wifi driver. You can optionally add it to /boot/Init.lja, to load it on boot. - Use eth to configure the network interface. For more information please refer to the manpage by running "man eth". + This is not implemented. Good luck. /-----------------------------| ----<| Contributions to the project | \-----------------------------| -To commit to the project, make sure you have pre-commit installed and you have run `pre-commit install`. +To commit to the project, make sure you have pre-commit installed (package name: python-pre-commit) +and you have run `pre-commit install` inside of the repo folder. From 21d9bcb06d541ff37a53432edb6081887359d0b2 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Sat, 9 Sep 2023 23:13:24 +0300 Subject: [PATCH 08/17] Revert "A tiny addition to gitignore." This reverts commit 2624dacdb08c30b750ba8ca76a1a868c7355ec38. --- .gitignore | 1 - Manual.txt | 264 ++++++++++++++++++----------------------------------- 2 files changed, 87 insertions(+), 178 deletions(-) diff --git a/.gitignore b/.gitignore index 7ac83e1d..46f4f4df 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,3 @@ source/build_* *.pyc *.xml *.iml -.directory diff --git a/Manual.txt b/Manual.txt index 7b24eea0..b55dbb29 100644 --- a/Manual.txt +++ b/Manual.txt @@ -5,35 +5,13 @@ Official repository: [https://github.com/bill88t/ljinux] -Index table: -1. Basic commands : line -2. Scripting : line -3. Errors : line -4. Api functions : line -5. jCurses : line -6. Led activity : line -7. BetterPath : line -8. GPIO Usage : line -9. Network driver usage : line - /---------------| ----<| Basic commands | \---------------| +help [COMMAND] -alias [COMMAND=data] - -Runs data, whenever command is typed - - -bell - -Ring the bell on the current terminal - - -cat [file] - -Catenates the contents of file [file] +Outputs a basic list of commands to serial out cd [DIR]... @@ -42,87 +20,12 @@ Changes to specified directory Please refer to the betterpath section, on more info on how does the ljinux filesystem appear. -clear - -Clear the current terminal - - -date [set]... - -View the time, or set it -Valid format "date set dd mm yyyy hr mm ss" - - -detect - -Fetch the term.detect_size() for context updating - - -devmode [-q] - -Enables usb access and other development features. -This prohibits write access to the built in filesystem. -The notice can be skipped by passing -q. -This can be reverted by setting `usb_access = false` under -section [LJINUX] in the board's `/settings.toml`. - - -df [-h] - -Report all attached file system's space usage. - - -disconnect - -Immediately disconnect the current terminal, if it can be disconnected. - - -dmesg - -Prints out the current dmesg log. - - echo [DATA]... -Print some variables or text. - +Print some variables or text -ed [FILE] -A line-oriented text editor. - - -exit [CODE] - -Exits ljinux with an exit code, default = 0 -If ran over a remote connection, disconnects instead. - - -false - -Returns false. - - -free [-b/-k/-m/-g] - -Display memory usage. - - - - ---- -help [COMMAND] - -Outputs a basic list of commands to serial out - - - - - - - - -var [DATA]... (DEPRECATED, SOON TO BE REPLACED) +var [DATA]... Create a new variable. syntax: var a = "ok" Numbers do not need brackets. @@ -168,6 +71,24 @@ pwd Outputs the current directory +display [OPERATION] [OPERATION DATA] + +Displays something on the i2c display +Returns object id, do not lose it +Budget didnt allow porting wayland, so i made farland +operations: + +text +dot +line +rectangle +square +circle +rhombus +move +delete + + exec [FILE] Loads an .lja file and executes it's commands @@ -176,23 +97,35 @@ Loads an .lja file and executes it's commands pexec [-n] [python commands] Runs python commands +-n suppresses the ciruitpy text -fpexec [file] +fpexec [-n] [file] -Runs a python file in a new process. +Same as pexec but uses a file instead -sleep [TIME] +wait [TIME] [TIME] in seconds +exit [CODE] +Exit the current process with an exit code, default = 0 +date [set]... + +View the time, or set it +Valid format "date set dd mm yyyy hr mm ss" +su + +Disable security, asks for password +Password can be found in /etc/passwd :) + neofetch @@ -204,8 +137,22 @@ history [save/load/clear] Displays the history +njinx + +An integrated webserver +Please configure /etc/njinx/njinx.conf beforehand +whois [name] + +Finds and returns the ip of the given domain. + + +devmode + +Enables usb access and other development features +This prohibits write access to the built in filesystem + reboot [mode] @@ -213,17 +160,22 @@ Reboots the microcontroller Optionally you can pass a reboot [mode] (safemode, uf2, bootloader) +dmesg + +Prints out the dmesg log +cat [file] +Prints the contents of file [file] -head [-n] [file] +head [n] [file] Print the first [-n number] lines of file [file]. -tail [-n] [file] +tail [n] [file] Print the last [-n number] lines of file [file]. @@ -248,45 +200,39 @@ detect Fetch the term.detect_size() for context updating -less [file] - -opposite for more, except we don't have more.. - - -reload - -Exit and immediately reload ljinux +waitforserial +Waits for a serial connection. Should absolutely be used into Init.lja if you're gonna use jcurses. +less [file] +opposite for more, except we don't have more.. /----------| ----<| Scripting | \----------| -Based script files need to have the .lja file extension. All internal or external commands -can be used in scripts. +Based script files need to have the .lja file extension. All internal or external commands can be used in scripts. To have a script appear as a command, put it in /LjinuxRoot/bin/ or in the /bin of the sdcard. +To create a comment, simply write COMMENT in the beginning of the line. To execute python code, you are advised to use pexec & fpexec. The scope is the same as the one of ljinux and you can call & alter ljinux data freely. -This however is very unsafe (as in, you may touch foreign variables), and you are instead advised -to use the given variable container storage. -When fpexec is called, the code is given an empty container storage under `pv[get_pid()]`. -You can manipulate it either directly or with the `vr` functions. More info in the Container Storage -section of the manual. +To access argj from based scripts containing pexec, the best way is to use ljinux.based.user_vars["argj"].split() -To access shell input you can use `ljinux.api.xarg()` or `ljinux.based.user_vars["argj"].split()`. -You can find more info regarding xarg under it's api documentation. + /---------------| +----<| Repo & Mirrors | + \---------------| +The source & releases of Ljinux are primarily being made available to Github at: https://github.com/bill88t/ljinux +However it is also mirrored to my self-hosted Gitea instance at: https://git.port1.cf/bill88t/ljinux /-------| ----<| Errors | \-------| - The different errors used by the based shell. CODE: ljinux.based.error([number]) @@ -309,15 +255,13 @@ CODE: The network interface is not functional 6 : Display not attached - The display is not connected / registered. + The display is not connected correctly -7 : Filesystem unwritable, board in developer mode - This error shows up when a write to the internal storage occures while developer mode - is enabled. +7 : Filesystem unwritable, pi in developer mode + This error shows up when a write to the internal storage occures while developer mode is enabled. By CircuitPython design, when the internal storage is being made available from usb, - it is unwritable to ljinux. - To disable developer mode, set `usb_access = false` under section [LJINUX] in the board's - `/settings.toml`. + it is unwritable to the os. + To disable developer mode, delete the file "devm" from the root of LJINUX, and run the command "reboot" 8 : Missing files This error occurs when files needed for the command to run are missing. @@ -335,31 +279,7 @@ CODE: The variable name specified is already in use, and can't be modified in this way. 13 : Terminal too small, minimum size: size: - The current terminal size is too small, resize the terminal to a size bigger than - the one specified. - -14 : Is a file - What was passed, is a file, when it shouldn't. - -15 : Is a directory - What was passed, is a directory, when it shouldn't. - -16 : Directory not empty - The directory should have been empty, but wasn't. - -17 : Not a directory - What was passed, is not a directory, when it should. - -18 : Not a file - What was passed, is not a file, when it should. - -19 : Not a device - What was passed, is not a device, when it should. - -20 : Unhandled exception - Under fpexec execution, an exception was raised that was not caught by any code from within - the fpexec code, and it was instead caught by ljinux. - + The current terminal size is too small, resize the terminal to a size bigger than the one specified. /--------------| ----<| Api Functions | @@ -440,17 +360,8 @@ Based, by default, creates the "term" jcurses object. Useful functions: - - .write(strr=str, end="\n") - The default write function for ljinux. - Always prints to the active terminal only. - - - .nwrite(strr=str) - Same as `.write`, but does not print "\n" at the end. - It saves byte size when there are 25 septilion `end=""`'s. - Always prints to the active terminal only. - - .detect_size() - Detects the size of the terminal & returns it as [rows, collumns] + Detects the size of the terminal & returns it as [rows, collumns] - .detect_pos() Detects the current cursor position & returns it as [row, collumn] @@ -514,9 +425,9 @@ It work by mapping: And treating all subsequent paths by that rule. It additionally maps "~" to the user's home directory, and "-" to the previous directory. - /-----------| [ ] -----<| GPIO Usage | [ DEPRECATED, SOON TO BE REPLACED!!! ] - \-----------| [ ] + /-----------| +----<| GPIO Usage | + \-----------| From within the based shell you can use the unused GPIO pins as variables. Example: @@ -542,29 +453,28 @@ Example 3: \---------------------| To use the built-in circuitpython module "wifi" as your network connection: + - Ensure you have run "make wifi" from the host computer. + If you haven't, run "devmode" from within ljinux, to enable usb access, + and perform the module installation. Then delete the file "devm" from + the board's root, and reboot ljinux. - Run "modprobe driver_wifi as network" to load the ljinux wifi driver. You can optionally add it to /boot/Init.lja, to load it on boot. - Use iwctl to configure the wifi connection. For info on how to use iwctl, please refer to [https://wiki.archlinux.org/title/iwd] - - You connections will automatically be stored into &/settings.toml. - You can automatically reconnect on reboot by running `iwctl station wifi auto`. - To use a w5500 ethernet module: - Ensure you have run "make w5500" from the host computer. If you haven't, run "devmode" from within ljinux, to enable usb access, - and perform the module installation. Then disable developer mode (as stated above) - and reboot ljinux. + and perform the module installation. Then delete the file "devm" from + the board's root, and reboot ljinux. - Run "modprobe driver_w5500 as network" to load the ljinux wifi driver. You can optionally add it to /boot/Init.lja, to load it on boot. - Use eth to configure the network interface. For more information please refer to the manpage by running "man eth". - This is not implemented. Good luck. /-----------------------------| ----<| Contributions to the project | \-----------------------------| -To commit to the project, make sure you have pre-commit installed (package name: python-pre-commit) -and you have run `pre-commit install` inside of the repo folder. +To commit to the project, make sure you have pre-commit installed and you have run `pre-commit install`. From 2fdb3b532ffcc1c9324b3d175276af22bd6aafaf Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Sat, 9 Sep 2023 23:16:39 +0300 Subject: [PATCH 09/17] Tiny .gitignore addition --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 46f4f4df..7ac83e1d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ source/build_* *.pyc *.xml *.iml +.directory From c32f62abbec80d3e40050905011ef9907eda5b2e Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Sun, 10 Sep 2023 14:12:41 +0300 Subject: [PATCH 10/17] Wget to netutils --- {LjinuxRoot/bin => other/binextra/netutils}/wget.lja | 0 {LjinuxRoot/bin => other/binextra/netutils}/wget.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {LjinuxRoot/bin => other/binextra/netutils}/wget.lja (100%) rename {LjinuxRoot/bin => other/binextra/netutils}/wget.py (100%) diff --git a/LjinuxRoot/bin/wget.lja b/other/binextra/netutils/wget.lja similarity index 100% rename from LjinuxRoot/bin/wget.lja rename to other/binextra/netutils/wget.lja diff --git a/LjinuxRoot/bin/wget.py b/other/binextra/netutils/wget.py similarity index 100% rename from LjinuxRoot/bin/wget.py rename to other/binextra/netutils/wget.py From 33e10cfd3c3b7777c2f6c534fb275275e2ec812a Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Sun, 10 Sep 2023 14:13:27 +0300 Subject: [PATCH 11/17] Push updated manual --- Manual.txt | 457 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 343 insertions(+), 114 deletions(-) diff --git a/Manual.txt b/Manual.txt index b55dbb29..add8dd3c 100644 --- a/Manual.txt +++ b/Manual.txt @@ -4,14 +4,43 @@ \======================================/ Official repository: [https://github.com/bill88t/ljinux] +This manual is up to date with commit c32f62abbec80d3e40050905011ef9907eda5b2e @ 10/sep/2023. +Anything passed that point is not covered by this manual. + + /------------| +----<| Index table | + \------------| + +0. Index table : line 10 +1. Basic commands : line 27 +2. Scripting : line 337 +3. Errors : line 358 +4. Api functions : line 436 +5. jCurses : line 504 +6. Led activity : line 559 +7. BetterPath : line 573 +8. GPIO Usage : line 593 +9. Network driver usage : line 617 +10. Isolated processes : line 643 +11. Contributions : line 702 /---------------| ----<| Basic commands | \---------------| -help [COMMAND] +alias [COMMAND=data] + +Runs data, whenever command is typed + + +bell + +Ring the bell on the current terminal -Outputs a basic list of commands to serial out + +cat [file] + +Catenates the contents of file [file] cd [DIR]... @@ -20,214 +49,311 @@ Changes to specified directory Please refer to the betterpath section, on more info on how does the ljinux filesystem appear. +clear + +Clear the current terminal + + +date [set]... + +View the time, or set it +Valid format "date set dd mm yyyy hr mm ss" + + +detect + +Fetch the term.detect_size() for context updating + + +devmode [-q] + +Enables usb access and other development features. +This prohibits write access to the built in filesystem. +The notice can be skipped by passing -q. +This can be reverted by setting `usb_access = false` under +section [LJINUX] in the board's `/settings.toml`. + + +df [-h] + +Report all attached file system's space usage. + + +disconnect + +Immediately disconnect the current terminal, if it can be disconnected. + + +dmesg + +Prints out the current dmesg log. + + echo [DATA]... -Print some variables or text +Print some variables or text. -var [DATA]... +ed [FILE] -Create a new variable. syntax: var a = "ok" -Numbers do not need brackets. -The command itself is optional (a = "is also valid") -GPIO pins can be allocated like: a = GP9 -and used by setting them to either 0 or 1: a = 1 +A line-oriented text editor. -unset [Variable] +exec [FILE] -Deletes a Variable. -Can also be used on GPIO variables. -The GPIO will be deinit and free'ed. +false +Returns false. -uname [-a] -Print system information +exit [CODE] +Exits ljinux with an exit code, default = 0 +If ran over a remote connection, disconnects instead. -mkdir [DIR]... -Make a new directory +fpexec [file] +Runs a python file in a new process. -rmdir [DIR]... -Delete a directory +free [-b/-k/-m/-g] +Display memory usage. -rm [FILE]... -Delete a file +halt +Sync all filesystems, and halt the system. -ls [OPTIONS]... [DIR]... -Outputs the directory listing +head [-n int] [FILE] +Output the first part of files. +By default displays the first 10 lines of the FILE. -pwd -Outputs the current directory +help [COMMAND] +Displays all currently discovered commands. -display [OPERATION] [OPERATION DATA] -Displays something on the i2c display -Returns object id, do not lose it -Budget didnt allow porting wayland, so i made farland -operations: +history [save/load/clear] -text -dot -line -rectangle -square -circle -rhombus -move -delete +Displays the command history. -exec [FILE] +hostname [VALUE] -Loads an .lja file and executes it's commands +Displays the hostname if no VALUE is passed, else sets it +to that VALUE. -pexec [-n] [python commands] +jpkg [install/uninstall/list] [PACKAGE(S)] -Runs python commands --n suppresses the ciruitpy text +The built-in ljinux package manager. +For more information run `jpkg --help`, `man jpkg` or +view section JPKG. -fpexec [-n] [file] +jz [-q/-d/--decompress] [JZ ARCHIVE] [TARGET DIRECTORY] -Same as pexec but uses a file instead +Decompress a .jz archive to the TARGET DIRECTORY. +Extracts to '.' if not specified. -wait [TIME] +ledset [int / int int int] -[TIME] in seconds +Set the led to the given value(s). -exit [CODE] +less [FILE] -Exit the current process with an exit code, default = 0 +Opposite of more, a simple file viewer. -date [set]... +ls [OPTIONS]... [DIR]... -View the time, or set it -Valid format "date set dd mm yyyy hr mm ss" +Outputs the directory listing. + + +man [COMMAND] + +Display the manual for the given [COMMAND] with `less`. + + +mkdir [DIR]... + +Make a new directory + + +modprobe [MODULE as MODULE_TYPE] +Load a kernel MODULE with it's type specified by MODULE_TYPE. -su -Disable security, asks for password -Password can be found in /etc/passwd :) +nano [FILE] + +A text editor similar to GNU/nano. neofetch -View some system info +A simple system info viewer. +Much less bloated than it's linux counterpart. -history [save/load/clear] +pexec [-n] [python commands] -Displays the history +Runs python commands in the current process. -njinx +pinout -An integrated webserver -Please configure /etc/njinx/njinx.conf beforehand +Displays the current board's pinout map. -whois [name] +pwd -Finds and returns the ip of the given domain. +Print the current working directory. -devmode +python -Enables usb access and other development features -This prohibits write access to the built in filesystem +Opens a virtual python REPL. +To pass commands instead of actually opening the REPL, use pexec instead. +To pass files to run instead of actually opening the REPL, use fpexec instead. -reboot [mode] +random -Reboots the microcontroller -Optionally you can pass a reboot [mode] (safemode, uf2, bootloader) +Returns a random number. Displays it if based is not silenced. -dmesg +reboot [MODE] -Prints out the dmesg log +Reboots ljinux and the board. +Optionally, you can pass a reboot MODE from: [safemode, uf2, bootloader] -cat [file] +reload -Prints the contents of file [file] +Reloads ljinux fully. -head [n] [file] +rm [FILE(S)]... -Print the first [-n number] lines of file [file]. +Delete FILE(S). +Recursive deletes not yet supported. -tail [n] [file] +rmdir [DIR]... + +Delete an empty directory. + -Print the last [-n number] lines of file [file]. +runparts [FOLDER] + +Run all the .py files in a folder by alphabetic order. +Used by init. sensors -Prints the current system sensors data +Print the current system sensors and their current values. -pinout +sleep [TIME] -Prints the current board's pinout map +Sleep TIME, in seconds. -man [COMMAND] +sync -Print the manual for the given [COMMAND] +Sync all currently attached filesystems. -detect +tail [-n int] [FILE] + +Opposite of head. +Output the last part of files. +By default displays the last 10 lines of the FILE. + + +title [TEXT] + +Sets the terminal title to the TEXT. + +top + +Display the current process stack, along with useful info. + + +touch [FILE] + +Create a new FILE. + + +true + +Returns true. -Fetch the term.detect_size() for context updating +unalias [ALIAS] -waitforserial +Removes ALIAS. + + +uname [-a] + +Print system information + + +Loads an .lja file and executes it's commands + + +unset [Variable] + +Deletes a Variable. +Can also be used on GPIO variables. +The GPIO will be deinitialized. + + +var [DATA]... (!!!DEPRECATED, SOON TO BE REPLACED!!!) + +Create a new variable. syntax: var a = "ok" +Numbers do not need brackets. +The command itself is optional (a = "is also valid") +GPIO pins can be allocated like: a = GP9 +and used by setting them to either 0 or 1: a = 1 -Waits for a serial connection. Should absolutely be used into Init.lja if you're gonna use jcurses. +watch [-s] [-n SECONDS] [COMMAND] -less [file] +Run a COMMAND every n SECONDS (default 2 seconds). +Hide the titlebar text with `-s`. -opposite for more, except we don't have more.. /----------| ----<| Scripting | \----------| -Based script files need to have the .lja file extension. All internal or external commands can be used in scripts. +Based script files need to have the .lja file extension. All internal or external commands +can be used in scripts. To have a script appear as a command, put it in /LjinuxRoot/bin/ or in the /bin of the sdcard. -To create a comment, simply write COMMENT in the beginning of the line. To execute python code, you are advised to use pexec & fpexec. The scope is the same as the one of ljinux and you can call & alter ljinux data freely. +This however is very unsafe (as in, you may touch foreign variables), and you are instead advised +to use the given variable container storage. -To access argj from based scripts containing pexec, the best way is to use ljinux.based.user_vars["argj"].split() +When fpexec is called, the code is given an empty container storage under `pv[get_pid()]`. +You can manipulate it either directly or with the `vr` functions. More info in the Container Storage +section of the manual. - /---------------| -----<| Repo & Mirrors | - \---------------| +To access shell input you can use `ljinux.api.xarg()` or `ljinux.based.user_vars["argj"].split()`. +You can find more info regarding xarg under it's api documentation. -The source & releases of Ljinux are primarily being made available to Github at: https://github.com/bill88t/ljinux -However it is also mirrored to my self-hosted Gitea instance at: https://git.port1.cf/bill88t/ljinux /-------| ----<| Errors | @@ -255,13 +381,15 @@ CODE: The network interface is not functional 6 : Display not attached - The display is not connected correctly + The display is not connected / registered. -7 : Filesystem unwritable, pi in developer mode - This error shows up when a write to the internal storage occures while developer mode is enabled. +7 : Filesystem unwritable, board in developer mode + This error shows up when a write to the internal storage occures while developer mode + is enabled. By CircuitPython design, when the internal storage is being made available from usb, - it is unwritable to the os. - To disable developer mode, delete the file "devm" from the root of LJINUX, and run the command "reboot" + it is unwritable to ljinux. + To disable developer mode, set `usb_access = false` under section [LJINUX] in the board's + `/settings.toml`. 8 : Missing files This error occurs when files needed for the command to run are missing. @@ -279,7 +407,31 @@ CODE: The variable name specified is already in use, and can't be modified in this way. 13 : Terminal too small, minimum size: size: - The current terminal size is too small, resize the terminal to a size bigger than the one specified. + The current terminal size is too small, resize the terminal to a size bigger than + the one specified. + +14 : Is a file + What was passed, is a file, when it shouldn't. + +15 : Is a directory + What was passed, is a directory, when it shouldn't. + +16 : Directory not empty + The directory should have been empty, but wasn't. + +17 : Not a directory + What was passed, is not a directory, when it should. + +18 : Not a file + What was passed, is not a file, when it should. + +19 : Not a device + What was passed, is not a device, when it should. + +20 : Unhandled exception + Under fpexec execution, an exception was raised that was not caught by any code from within + the fpexec code, and it was instead caught by ljinux. + /--------------| ----<| Api Functions | @@ -348,6 +500,7 @@ Available from: specified if found Otherwise, it returns the input + /--------| ----<| jCurses | \--------| @@ -360,8 +513,17 @@ Based, by default, creates the "term" jcurses object. Useful functions: + - .write(strr=str, end="\n") + The default write function for ljinux. + Always prints to the active terminal only. + + - .nwrite(strr=str) + Same as `.write`, but does not print "\n" at the end. + It saves byte size when there are 25 septilion `end=""`'s. + Always prints to the active terminal only. + - .detect_size() - Detects the size of the terminal & returns it as [rows, collumns] + Detects the size of the terminal & returns it as [rows, collumns] - .detect_pos() Detects the current cursor position & returns it as [row, collumn] @@ -393,6 +555,7 @@ jCurses does not depend onto ljinux. More documentation on jcurses will be added later. + /-------------| ----<| Led activity | \-------------| @@ -406,6 +569,7 @@ Red when an error occurs, Yellow on activity and Blue when waiting. + /-----------| ----<| BetterPath | \-----------| @@ -425,9 +589,10 @@ It work by mapping: And treating all subsequent paths by that rule. It additionally maps "~" to the user's home directory, and "-" to the previous directory. - /-----------| -----<| GPIO Usage | - \-----------| + + /-----------| [ ] +----<| GPIO Usage | [ DEPRECATED, SOON TO BE REPLACED!!! ] + \-----------| [ ] From within the based shell you can use the unused GPIO pins as variables. Example: @@ -448,33 +613,97 @@ Example 3: b = a echo b + /---------------------| ----<| Network driver usage | \---------------------| To use the built-in circuitpython module "wifi" as your network connection: - - Ensure you have run "make wifi" from the host computer. - If you haven't, run "devmode" from within ljinux, to enable usb access, - and perform the module installation. Then delete the file "devm" from - the board's root, and reboot ljinux. - Run "modprobe driver_wifi as network" to load the ljinux wifi driver. You can optionally add it to /boot/Init.lja, to load it on boot. - Use iwctl to configure the wifi connection. For info on how to use iwctl, please refer to [https://wiki.archlinux.org/title/iwd] + - You connections will automatically be stored into &/settings.toml. + You can automatically reconnect on reboot by running `iwctl station wifi auto`. + To use a w5500 ethernet module: - Ensure you have run "make w5500" from the host computer. If you haven't, run "devmode" from within ljinux, to enable usb access, - and perform the module installation. Then delete the file "devm" from - the board's root, and reboot ljinux. + and perform the module installation. Then disable developer mode (as stated above) + and reboot ljinux. - Run "modprobe driver_w5500 as network" to load the ljinux wifi driver. You can optionally add it to /boot/Init.lja, to load it on boot. - Use eth to configure the network interface. For more information please refer to the manpage by running "man eth". + This is not implemented. Good luck. + + + /-------------------| +----<| Isolated processes | + \-------------------| + +During ljinux execution every variable created persists across processes. +And every process can access any other process's stuff. Securitey! +Having a parser that effectively blocks touching other processes would be +too much of an overhead and impractical. + +Still, it's possible there are variable nameshakes and forgotten variables. +(If you use variable "i", your parent process could also be using it, and you could +break some loop, causing a `while True`) +(If you do not delete your variable before the program exit, it WILL REMAIN!) + +For this I made a container storage for processes. +Whenever fpexec is run, the code inside gets a pid. +You can read that value with `get_pid()`. +Every process also gets a dict in `pv`. +This dict will be automatically deleted after the process is exited. + +You can directly access from python it as `pv[get_pid()]`. + +To set a (new) variable directly from python, +run `pv[get_pid()]["new_variable_name"] = whatever_value`. + +However that is long and ugly. There are functions for managing container varibles. +To set a variable: +`vr("variable_name", value)` + +To get the value: +`vr("variable_name")` + +To add a value to a variable: +`vrp("variable_name", value)` +`vrp("variable_name")` # += 1 to the variable. + +To subtract a value from a variable: +`vrm("variable_name", value)` +`vrm("variable_name")` # -= 1 to the variable. + +To append a value to a variable: +`vra("variable_name", value)` + +To delete a variable: +`vrd("variable_name")` + +Still if you want to iterate with for, you have to do this: +```py +for pv[get_pid()]["i"] in vr("some_list"): + vr("data", vr("i") * potatoes) +``` + +You can use read-only properties of the variables just fine with `vr`. +`vr("socket").accept()` + +But if you need to write to it, you need to access it directly. +`pv[get_pid()]["list"].pop(2)` + /-----------------------------| ----<| Contributions to the project | \-----------------------------| -To commit to the project, make sure you have pre-commit installed and you have run `pre-commit install`. +To commit to the project, make sure you have pre-commit installed. +On Arch Linux the packaged is named "python-pre-commit". +And then you have run `pre-commit install` inside of the repo. +Then upon committing changes, they will be immediately formatted. From 3ea9149d121410f977246f87728ca1408cc04c02 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Sun, 10 Sep 2023 16:36:32 +0300 Subject: [PATCH 12/17] telnet use memoryview --- other/telnet_console.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/other/telnet_console.py b/other/telnet_console.py index 8f41cc92..b29b85a7 100644 --- a/other/telnet_console.py +++ b/other/telnet_console.py @@ -119,10 +119,10 @@ def _rt(self) -> None: """ while len(self._tx_buf) > 32: # Bulk try: - self._conn.send(self._tx_buf[:32]) + self._conn.send(memoryview(self._tx_buf)[:32]) except BrokenPipeError: self.disconnect() - self._tx_buf = self._tx_buf[32:] + self._tx_buf = memoryview(self._tx_buf)[32:] if len(self._tx_buf): # regular try: self._conn.send(self._tx_buf) @@ -165,7 +165,7 @@ def _rr(self, block=False) -> None: while self.connected: # Will get interrupted by except size = self._conn.recv_into(self._rx_buf, self._maxbuf) if size: - self._ps_buf += self._rx_buf[:size] + self._ps_buf += memoryview(self._rx_buf)[:size] del size except OSError: pass @@ -211,7 +211,7 @@ def read(self, count=None): # many types returned: Bytes, None. else: self._rr(block=count is None) count = len(self._ps_buf) - res = bytes(self._ps_buf[:count]) + res = bytes(memoryview(self._ps_buf)[:count]) self._ps_buf = self._ps_buf[count:] return res else: From be248e3673e0fc2503bc2ce54e3c40c9913aee6f Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Mon, 18 Sep 2023 20:21:15 +0300 Subject: [PATCH 13/17] cd, date, sensors improvements --- LjinuxRoot/bin/cd.py | 17 ++++++++++------- LjinuxRoot/bin/date.py | 2 +- LjinuxRoot/bin/sensors.py | 20 ++++++++++++++------ 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/LjinuxRoot/bin/cd.py b/LjinuxRoot/bin/cd.py index 3b242b5a..3577a81b 100644 --- a/LjinuxRoot/bin/cd.py +++ b/LjinuxRoot/bin/cd.py @@ -3,15 +3,18 @@ try: vr("dirr", ljinux.api.getvar("argj").split()[1]) if vr("dirr") != "-": - chdir(ljinux.api.betterpath(vr("dirr"))) - if vr("capdir") != getcwd(): - ljinux.based.user_vars["prevdir"] = vr("capdir") + vr("dr", ljinux.api.isdir(vr("dirr"))) + if vr("dr") == 1: + chdir(ljinux.api.betterpath(vr("dirr"))) + if vr("capdir") != getcwd(): + ljinux.api.setvar("prevdir", vr("capdir")) + elif not vr("dr"): + ljinux.based.error(14, "cd") + else: + ljinux.based.error(17, "cd") else: chdir(ljinux.based.user_vars["prevdir"]) + ljinux.api.setvar("prevdir", vr("capdir")) ljinux.based.olddir = getcwd() -except OSError: - term.write( - "Error: '" + ljinux.api.getvar("argj").split()[1] + "' Directory does not exist" - ) except IndexError: pass diff --git a/LjinuxRoot/bin/date.py b/LjinuxRoot/bin/date.py index a2ccb4cc..c62b9601 100644 --- a/LjinuxRoot/bin/date.py +++ b/LjinuxRoot/bin/date.py @@ -24,7 +24,7 @@ else: raise IndexError except IndexError: - pv[get_pid()]["tt"] = time.localtime() + vr("tt", time.localtime()) vr( "dat", [ diff --git a/LjinuxRoot/bin/sensors.py b/LjinuxRoot/bin/sensors.py index c552edac..bc66224d 100644 --- a/LjinuxRoot/bin/sensors.py +++ b/LjinuxRoot/bin/sensors.py @@ -1,6 +1,14 @@ -term.write( - "cpu_thermal\nAdapter: Cpu device\ntemp1: +" - + str(cpu.temperature)[:5] - + "°C" - + ("\nvoltage1: " + str(cpu.voltage) + "v" if cpu.voltage is not None else "") -) +rename_process("sensors") +vr("no", True) +if cpu.temperature is not None: + vr("no", False) + term.write( + "cpu_thermal\nAdapter: Cpu device\ntemp1: +" + str(cpu.temperature)[:5] + "°C" + ) + +if cpu.voltage is not None: + vr("no", False) + term.write("voltage1: " + str(cpu.voltage) + "V") + +if vr("no"): + term.write("No sensors detected!") From 09cc592e5deb2d17d8e5a9cc4f95ff6ed5ee8f56 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Mon, 18 Sep 2023 20:21:46 +0300 Subject: [PATCH 14/17] iwctl fix --- other/binextra/netutils/iwctl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/other/binextra/netutils/iwctl.py b/other/binextra/netutils/iwctl.py index 3c467f81..1c75098f 100644 --- a/other/binextra/netutils/iwctl.py +++ b/other/binextra/netutils/iwctl.py @@ -337,7 +337,7 @@ vr("best_index", vr("stored_networks").index(vr("i"))) else: # We already have a network we can use vr( - "cind", stored_networks.index(vr("i")) + "cind", vr("stored_networks").index(vr("i")) ) # To test if it's better if vr("best_index") > vr("cind"): # It's a better network From be23847903530391cea355488c1600f9b50cb0a0 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Mon, 18 Sep 2023 20:22:10 +0300 Subject: [PATCH 15/17] Add devices dict --- source/ljinux.py | 1 + 1 file changed, 1 insertion(+) diff --git a/source/ljinux.py b/source/ljinux.py index 76ecf074..97a0bf19 100644 --- a/source/ljinux.py +++ b/source/ljinux.py @@ -466,6 +466,7 @@ def systemprints(mod, tx1, tx2=None): class ljinux: modules = {} + devices = {} def deinit_consoles() -> None: for i in vr("consoles", pid=0).keys(): From cce2a30286eb0f670b8c6714123694a16ef35f79 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Fri, 22 Sep 2023 22:15:08 +0300 Subject: [PATCH 16/17] Update modules --- other/Adafruit_CircuitPython_HTTPServer | 2 +- other/Adafruit_CircuitPython_NTP | 2 +- other/Adafruit_CircuitPython_Requests | 2 +- other/Adafruit_CircuitPython_SD | 2 +- other/Adafruit_CircuitPython_Wiznet5k | 2 +- other/CircuitPython_FTP_Server | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/other/Adafruit_CircuitPython_HTTPServer b/other/Adafruit_CircuitPython_HTTPServer index be65668a..ed41a3f6 160000 --- a/other/Adafruit_CircuitPython_HTTPServer +++ b/other/Adafruit_CircuitPython_HTTPServer @@ -1 +1 @@ -Subproject commit be65668ab4a13dd4d3cbb9fa0ac076e86700abed +Subproject commit ed41a3f6d189cc310e9d39bd3e3a1fd6ab210a86 diff --git a/other/Adafruit_CircuitPython_NTP b/other/Adafruit_CircuitPython_NTP index a87669f3..57aba31b 160000 --- a/other/Adafruit_CircuitPython_NTP +++ b/other/Adafruit_CircuitPython_NTP @@ -1 +1 @@ -Subproject commit a87669f3fa6967585a1b33e3fd582cf67a6c7bcc +Subproject commit 57aba31beb1bd8bc567f770357bf4ff943a2d125 diff --git a/other/Adafruit_CircuitPython_Requests b/other/Adafruit_CircuitPython_Requests index 36f1bb0f..87ae429b 160000 --- a/other/Adafruit_CircuitPython_Requests +++ b/other/Adafruit_CircuitPython_Requests @@ -1 +1 @@ -Subproject commit 36f1bb0f1b739a06b7e2782580ce08eecf17c78a +Subproject commit 87ae429b75a4836709749f363657f71061e1b409 diff --git a/other/Adafruit_CircuitPython_SD b/other/Adafruit_CircuitPython_SD index 5537f452..8fecea94 160000 --- a/other/Adafruit_CircuitPython_SD +++ b/other/Adafruit_CircuitPython_SD @@ -1 +1 @@ -Subproject commit 5537f452959b4f2d44742f24808fac7f7098c03d +Subproject commit 8fecea94a6b6e9b33ef36dfcd40c053b186755af diff --git a/other/Adafruit_CircuitPython_Wiznet5k b/other/Adafruit_CircuitPython_Wiznet5k index f313673c..6d3e9090 160000 --- a/other/Adafruit_CircuitPython_Wiznet5k +++ b/other/Adafruit_CircuitPython_Wiznet5k @@ -1 +1 @@ -Subproject commit f313673c71140935498860b82dbde24c2c4993b0 +Subproject commit 6d3e9090057dbb1e07606e067e74bc0349f4b29f diff --git a/other/CircuitPython_FTP_Server b/other/CircuitPython_FTP_Server index 07682477..525719be 160000 --- a/other/CircuitPython_FTP_Server +++ b/other/CircuitPython_FTP_Server @@ -1 +1 @@ -Subproject commit 0768247717650620a0e16f9e2ad5304bb599edbd +Subproject commit 525719beb427e241ace7fcf9a19a604f86cc4f7a From 751764993f1625d4856e68d273a6bd0468ada8f5 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Fri, 22 Sep 2023 23:24:14 +0300 Subject: [PATCH 17/17] telnet error fixes --- LjinuxRoot/bin/stringproccessing/line_wrap.py | 2 +- other/telnet_console.py | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/LjinuxRoot/bin/stringproccessing/line_wrap.py b/LjinuxRoot/bin/stringproccessing/line_wrap.py index 8e90a610..85ddc75b 100644 --- a/LjinuxRoot/bin/stringproccessing/line_wrap.py +++ b/LjinuxRoot/bin/stringproccessing/line_wrap.py @@ -1,7 +1,7 @@ rename_process("line_wrap") vr("l", pv[get_parent_pid()]["lines"]) vr("lines", [], pid=get_parent_pid()) -vr("sizee", term.detect_size()) +vr("sizee", term.detect_size(3)) for pv[get_pid()]["i"] in vr("l"): vr("rem", vr("i")) if vr("rem") != "": diff --git a/other/telnet_console.py b/other/telnet_console.py index b29b85a7..6e9b4fce 100644 --- a/other/telnet_console.py +++ b/other/telnet_console.py @@ -117,17 +117,15 @@ def _rt(self) -> None: The internal transmit function. Clears the tx bytearray. """ - while len(self._tx_buf) > 32: # Bulk + sent = 0 + while sent != len(self._tx_buf): # Bulk try: - self._conn.send(memoryview(self._tx_buf)[:32]) - except BrokenPipeError: - self.disconnect() - self._tx_buf = memoryview(self._tx_buf)[32:] - if len(self._tx_buf): # regular - try: - self._conn.send(self._tx_buf) + sent += self._conn.send(memoryview(self._tx_buf)[sent:]) + except OSError: # EAGAIN for some reason. + pass except BrokenPipeError: self.disconnect() + break self._tx_buf = bytearray() def disconnect(self) -> None: