Prototype cleanup 2
This commit is contained in:
parent
46a9cc3ee9
commit
bda89ca795
|
@ -266,17 +266,17 @@ PierMesh has two main events loops to learn about: the TUI and the service.
|
|||
|
||||
## TUI
|
||||
|
||||
[🔗 Docs](https://git.utopic.work/PierMesh/piermesh/src/branch/main/docs/ui.md)
|
||||
[🔗 Docs](https://git.utopic.work/PierMesh/piermesh/src/branch/main/docs/tlog.md)
|
||||
|
||||
[🔗 Source](https://git.utopic.work/PierMesh/piermesh/src/branch/main/src/ui.py)
|
||||
[🔗 Source](https://git.utopic.work/PierMesh/piermesh/src/branch/main/src/tlog.py)
|
||||
|
||||
The TUI is provided via [Textual's](https://textual.textualize.io/) library. It's a relatively simple application that gives us a quick overview of system statistics in the way of memory and cpu usage as well as scrollable logs. You can toggle full screen logs with f and close the TUI and service with q.
|
||||
The TUI is provided via [curses](https://docs.python.org/3/howto/curses.html) library. It's a relatively simple application that gives us a quick overview of system statistics in the way of memory and cpu usage as well as logs you can scroll with the directional keys
|
||||
|
||||
## The Service
|
||||
|
||||
PierMesh runs a number of loops under the hood. These are primarily initialized in the main loop of run with a special logging loop outside of that.
|
||||
|
||||
Note that we make heavy use of [Meshtastic's Python API](https://github.com/meshtastic/python).
|
||||
Note that we make use of [Meshtastic's Python API](https://github.com/meshtastic/python).
|
||||
|
||||
### run
|
||||
|
||||
|
@ -288,18 +288,18 @@ Note that we make heavy use of [Meshtastic's Python API](https://github.com/mesh
|
|||
|
||||
In run.main we (in order)
|
||||
1. Initialize the `Node` class to a global `nodeOb`.
|
||||
2. Wait for x seconds determined by command line arguments (see the falin and marcille scripts in scripts)
|
||||
2. Wait for x seconds determined by command line arguments (see the falin script in scripts)
|
||||
3. Initialize our `Transceiver` class (and the corresponding hardware)
|
||||
4. Initialize our `Server` class
|
||||
5. Create an async task running the `Node.spongeListen` method which looks for updates from the filter system
|
||||
6. Kick the loop on with `await asyncio.sleep(1)` (we do this to kick on all async loops so I will omit this step going forward)
|
||||
7. Create an async task running the `Transceiver.checkProgress` method which checks for packet reception progress and resends packets if necessary
|
||||
7. Create an async task running the `Transceiver.checkProgress` method which checks for packet reception progress and resends packets if necessary (currently not in use)
|
||||
8. Create an async task running `Node.monitor` which checks and reports system usage
|
||||
9. Create an async task running the `Transceiver.announce` method which broadcasts a `Packets.Message` containing network mapping information
|
||||
10. Last we start the `Microdot` server loop
|
||||
|
||||
### ..
|
||||
Travelling out of the run.main thread to the primary ____main____ code we see the other two threads: one running the `logPassLoop` loop which is created in the same way as the main thread: `lplThread = threading.Thread(target=asyncio.run, args=(logPassLoop(),))` and one running the TUI loop which has it's own system we just kick on by instantiating the TUI class and calling .run() on.
|
||||
Travelling out of the run.main thread to the primary ____main____ code we see the other thread running the TUI loop which has it's own system we just kick on by running .runLogUI
|
||||
|
||||
## Packet lifecycle
|
||||
|
||||
|
|
13
readme.md
13
readme.md
|
@ -2,8 +2,6 @@
|
|||
# PierMesh
|
||||
## A new internet, a fresh start
|
||||
|
||||
This is the monorepo for PierMesh.
|
||||
|
||||
# Docs
|
||||
|
||||
You can find the full docs here: [docs/](https://git.utopic.work/PierMesh/piermesh/src/branch/main/docs)
|
||||
|
@ -15,24 +13,25 @@ Note: these instructions will probably only work on Linux at the moment
|
|||
Note: check the scripts to make sure they'll work with your system, and in general I recommend checking scripts before you run them
|
||||
|
||||
Follow Meshtastic's guide on setting up your device: [https://meshtastic.org/docs/getting-started/](https://meshtastic.org/docs/getting-started/)
|
||||
|
||||
Make sure you have the latest Python installed
|
||||
|
||||
Make sure you have pip and venv installed
|
||||
|
||||
```
|
||||
git clone https://git.utopic.work/PierMesh/piermesh
|
||||
|
||||
cd piermesh
|
||||
|
||||
python -m venv .
|
||||
python -m venv .venv
|
||||
|
||||
source bin/activate
|
||||
source .venv/bin/activate
|
||||
|
||||
pip install -r requirements.txt
|
||||
|
||||
cd src
|
||||
|
||||
chmod a+x ./scripts/falin
|
||||
|
||||
./scripts/falin
|
||||
python run.py
|
||||
```
|
||||
|
||||
# License text
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
Nickname = node1
|
||||
StartupDelay = 0
|
||||
WebUIPort = 5000
|
||||
ShowTUI = False
|
||||
ShowTUI = True
|
||||
|
||||
[OPERATOR_REQUIRED]
|
||||
TransceiverPort = /dev/ttyACM0
|
||||
|
|
|
@ -4,17 +4,17 @@ PierMesh has two main events loops to learn about: the TUI and the service.
|
|||
|
||||
## TUI
|
||||
|
||||
[🔗 Docs](https://git.utopic.work/PierMesh/piermesh/src/branch/main/docs/ui.md)
|
||||
[🔗 Docs](https://git.utopic.work/PierMesh/piermesh/src/branch/main/docs/tlog.md)
|
||||
|
||||
[🔗 Source](https://git.utopic.work/PierMesh/piermesh/src/branch/main/src/ui.py)
|
||||
[🔗 Source](https://git.utopic.work/PierMesh/piermesh/src/branch/main/src/tlog.py)
|
||||
|
||||
The TUI is provided via [Textual's](https://textual.textualize.io/) library. It's a relatively simple application that gives us a quick overview of system statistics in the way of memory and cpu usage as well as scrollable logs. You can toggle full screen logs with f and close the TUI and service with q.
|
||||
The TUI is provided via [curses](https://docs.python.org/3/howto/curses.html) library. It's a relatively simple application that gives us a quick overview of system statistics in the way of memory and cpu usage as well as logs you can scroll with the directional keys
|
||||
|
||||
## The Service
|
||||
|
||||
PierMesh runs a number of loops under the hood. These are primarily initialized in the main loop of run with a special logging loop outside of that.
|
||||
|
||||
Note that we make heavy use of [Meshtastic's Python API](https://github.com/meshtastic/python).
|
||||
Note that we make use of [Meshtastic's Python API](https://github.com/meshtastic/python).
|
||||
|
||||
### run
|
||||
|
||||
|
@ -26,18 +26,18 @@ Note that we make heavy use of [Meshtastic's Python API](https://github.com/mesh
|
|||
|
||||
In run.main we (in order)
|
||||
1. Initialize the `Node` class to a global `nodeOb`.
|
||||
2. Wait for x seconds determined by command line arguments (see the falin and marcille scripts in scripts)
|
||||
2. Wait for x seconds determined by command line arguments (see the falin script in scripts)
|
||||
3. Initialize our `Transceiver` class (and the corresponding hardware)
|
||||
4. Initialize our `Server` class
|
||||
5. Create an async task running the `Node.spongeListen` method which looks for updates from the filter system
|
||||
6. Kick the loop on with `await asyncio.sleep(1)` (we do this to kick on all async loops so I will omit this step going forward)
|
||||
7. Create an async task running the `Transceiver.checkProgress` method which checks for packet reception progress and resends packets if necessary
|
||||
7. Create an async task running the `Transceiver.checkProgress` method which checks for packet reception progress and resends packets if necessary (currently not in use)
|
||||
8. Create an async task running `Node.monitor` which checks and reports system usage
|
||||
9. Create an async task running the `Transceiver.announce` method which broadcasts a `Packets.Message` containing network mapping information
|
||||
10. Last we start the `Microdot` server loop
|
||||
|
||||
### ..
|
||||
Travelling out of the run.main thread to the primary ____main____ code we see the other two threads: one running the `logPassLoop` loop which is created in the same way as the main thread: `lplThread = threading.Thread(target=asyncio.run, args=(logPassLoop(),))` and one running the TUI loop which has it's own system we just kick on by instantiating the TUI class and calling .run() on.
|
||||
Travelling out of the run.main thread to the primary ____main____ code we see the other thread running the TUI loop which has it's own system we just kick on by running .runLogUI
|
||||
|
||||
## Packet lifecycle
|
||||
|
||||
|
|
45
src/run.py
45
src/run.py
|
@ -129,7 +129,7 @@ if __name__ == "__main__":
|
|||
else:
|
||||
if "ShowTUI" in config["OPERATOR_OVERRIDES"]:
|
||||
showTUI = config["OPERATOR_OVERRIDES"]["ShowTUI"]
|
||||
showTUI = bool(showTUI)
|
||||
showTUI = showTUI == "True"
|
||||
psk = False
|
||||
if argConfig.override:
|
||||
if not argConfig.PSK:
|
||||
|
@ -274,15 +274,14 @@ class Node:
|
|||
"""
|
||||
Monitor and log ram and cpu usage
|
||||
"""
|
||||
global tuiOb
|
||||
global tuiOb, logger
|
||||
while True:
|
||||
if tuiOb != None:
|
||||
if tuiOb is not None and showTUI:
|
||||
await asyncio.sleep(10)
|
||||
memmb = self.proc.memory_info().rss / (1024 * 1024)
|
||||
memmb = round(memmb, 2)
|
||||
cpup = self.proc.cpu_percent(interval=1)
|
||||
logger.log(
|
||||
10,
|
||||
logger.info(
|
||||
" MEM: {0} mB | CPU: {1} %".format(
|
||||
memmb,
|
||||
cpup,
|
||||
|
@ -290,6 +289,17 @@ class Node:
|
|||
)
|
||||
tuiOb.do_set_cpu_percent(float(cpup))
|
||||
tuiOb.do_set_mem(memmb)
|
||||
elif not showTUI:
|
||||
await asyncio.sleep(10)
|
||||
memmb = self.proc.memory_info().rss / (1024 * 1024)
|
||||
memmb = round(memmb, 2)
|
||||
cpup = self.proc.cpu_percent(interval=1)
|
||||
logger.info(
|
||||
" MEM: {0} mB | CPU: {1} %".format(
|
||||
memmb,
|
||||
cpup,
|
||||
),
|
||||
)
|
||||
else:
|
||||
logger.log(20, "No TUI object, waiting 5 seconds...")
|
||||
await asyncio.sleep(5)
|
||||
|
@ -306,6 +316,7 @@ class Node:
|
|||
-----
|
||||
We use a common technique here that calls the function from our preloaded actions via dictionary entry
|
||||
"""
|
||||
global logger
|
||||
while True:
|
||||
while (len(self.todo) >= 1):
|
||||
try:
|
||||
|
@ -484,17 +495,23 @@ def initLogger(nodeName, tolog, tui=True):
|
|||
"""
|
||||
global logger
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.propagate = not tui
|
||||
logger.propagate = False
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
||||
vh = VHandler(logging.DEBUG, tolog)
|
||||
|
||||
formatter = logging.Formatter(
|
||||
'%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
|
||||
vh.setFormatter(formatter)
|
||||
if tui:
|
||||
vh = VHandler(logging.DEBUG, tolog)
|
||||
|
||||
logger.addHandler(vh)
|
||||
vh.setFormatter(formatter)
|
||||
|
||||
logger.addHandler(vh)
|
||||
else:
|
||||
sh = logging.StreamHandler()
|
||||
sh.setLevel(logging.DEBUG)
|
||||
sh.setFormatter(formatter)
|
||||
logger.addHandler(sh)
|
||||
|
||||
dt = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||
|
||||
|
@ -507,14 +524,14 @@ def initLogger(nodeName, tolog, tui=True):
|
|||
if __name__ == "__main__":
|
||||
try:
|
||||
tolog = queue.Queue()
|
||||
initLogger(nodeNickname, tolog)
|
||||
initLogger(nodeNickname, tolog, tui=showTUI)
|
||||
mainThread = threading.Thread(target=uvloop.run, args=(main(),))
|
||||
mainThread.start()
|
||||
# TODO: Waiting for this to finish when no tui
|
||||
# TODO: Logging to screen when no tui
|
||||
if showTUI:
|
||||
tlog.runLogUI(tolog, nodeNickname)
|
||||
# else:
|
||||
else:
|
||||
# TODO: Resource logging
|
||||
print("No TUI")
|
||||
except Exception:
|
||||
print(traceback.format_exc())
|
||||
os._exit(1)
|
||||
|
|
Loading…
Reference in New Issue