mirror of
https://github.com/SpudGunMan/meshing-around.git
synced 2026-03-28 17:32:36 +01:00
60 lines
2.3 KiB
Python
60 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
# # Simulate meshing-around de K7MHI 2024
|
|
from modules.log import * # err? Move .py out of etc/ and place it in the root of the project
|
|
import time
|
|
import random
|
|
|
|
# Initialize the tool
|
|
projectName = "example_handler" # name of _handler function to match the function name under test
|
|
randomNode = False # Set to True to use random node IDs
|
|
|
|
def get_NodeID():
|
|
nodeList = [4258675309, 1212121212, 1234567890, 9876543210]
|
|
if randomNode:
|
|
nodeID = random.choice(nodeList) # get a random node ID
|
|
else:
|
|
nodeID = nodeList[0]
|
|
return nodeID
|
|
# # end Initialization of the tool
|
|
|
|
# # Function to handle, or the project in test
|
|
|
|
|
|
def example_handler(nodeID, message):
|
|
readableTime = time.ctime(time.time())
|
|
msg = "Hello World! "
|
|
msg += f" You are Node ID: {nodeID} "
|
|
msg += f" Its: {readableTime} "
|
|
msg += f" You just sent: {message}"
|
|
return msg
|
|
|
|
|
|
# # end of function test code
|
|
|
|
# # Simulate the meshing-around mesh-bot for prototyping new projects
|
|
if __name__ == '__main__': # represents the bot's main loop
|
|
packet = ""
|
|
nodeInt = 1 # represents the device/node number
|
|
logger.info(f"System: Meshing-Around Simulator Starting for {projectName}")
|
|
nodeID = get_NodeID() # assign a nodeID
|
|
projectResponse = globals()[projectName](nodeID, " ") # Call the project handler under test
|
|
while True: # represents the onReceive() loop in the bot.py
|
|
projectResponse = ""
|
|
responseLength = 0
|
|
if randomNode:
|
|
nodeID = get_NodeID() # assign a random nodeID
|
|
packet = input(f"CLIENT {nodeID} INPUT: " ) # Emulate the client input
|
|
if packet != "":
|
|
#try:
|
|
projectResponse = globals()[projectName](nodeID, packet) # Call the project handler under test
|
|
# except Exception as e:
|
|
# logger.error(f"System: Handler: {e}")
|
|
# projectResponse = "Error in handler"
|
|
if projectResponse:
|
|
responseLength = len(projectResponse) # Evaluate the response length
|
|
logger.info(f"Device:{nodeInt} " + CustomFormatter.red + f"Sending {responseLength} long DM: " +\
|
|
CustomFormatter.white + projectResponse + CustomFormatter.purple + " To: " + CustomFormatter.white + str(nodeID))
|
|
time.sleep(0.5)
|
|
nodeID = get_NodeID() # assign a nodeID
|
|
# # End of launcher
|