From c2d2a8f7e45af0f0aa4bc9a75def642fe65f92b1 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 7 Oct 2025 16:33:33 -0700 Subject: [PATCH] Update simulator.py --- etc/simulator.py | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/etc/simulator.py b/etc/simulator.py index d88398a..7e12bab 100644 --- a/etc/simulator.py +++ b/etc/simulator.py @@ -9,6 +9,7 @@ projectName = "example_handler" # name of _handler function to match the functio randomNode = False # Set to True to use random node IDs # bot.py Simulated functions +deviceID = 1 # represents the device/node number def get_NodeID(): nodeList = [4258675309, 1212121212, 1234567890, 9876543210] if randomNode: @@ -16,22 +17,43 @@ def get_NodeID(): else: nodeID = nodeList[0] return nodeID +nodeID = get_NodeID() # assign a nodeID def get_name_from_number(nodeID, length='short', interface=1): # return random name for nodeID names = ["Max","Molly","Jake","Kelly"] return names[nodeID % len(names)] +#simulate GPS locations for testing +locations = [ + (48.200909, -123.25719), + (48.330283,-123.260703), + (48.342735,-122.987911), + (48.205591,-122.998448) + ] +lat, lon = random.choice(locations) # pick a random location +location = f"{lat},{lon}" # # end Initialization of the tool + + + + # # Function to handle, or the project in test +from modules.games.quiz import * +# # Project handler function code here - +# example handler function canada() def example_handler(message, nodeID, deviceID): - 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 + if message != "": + # put code in test here + msg = f"Hello {get_name_from_number(nodeID)}, simulator ready for testing {projectName} project! on device {deviceID}" + msg += f" Your location is {location}" + msg += f" you said: {message}" + + + return msg + + + # # end of function test code @@ -42,7 +64,7 @@ if __name__ == '__main__': # represents the bot's main loop 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, nodeInt) # Call the project handler under test + projectResponse = globals()[projectName]("", nodeID, deviceID) # call the handler function once to start while True: # represents the onReceive() loop in the bot.py projectResponse = "" responseLength = 0 @@ -51,7 +73,7 @@ if __name__ == '__main__': # represents the bot's main loop packet = input(f"CLIENT {nodeID} INPUT: " ) # Emulate the client input if packet != "": #try: - projectResponse = globals()[projectName](message = packet, nodeID = nodeID, deviceID = nodeInt) + projectResponse = globals()[projectName](message = packet, nodeID = nodeID, deviceID = deviceID) # call the handler function # except Exception as e: # logger.error(f"System: Handler: {e}") # projectResponse = "Error in handler"