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

Adding support keySimulator in remotecontrollers #120

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions framework/core/commonRemote.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from framework.core.remoteControllerModules.skyProc import remoteSkyProc
from framework.core.remoteControllerModules.arduino import remoteArduino
from framework.core.remoteControllerModules.none import remoteNone
from framework.core.remoteControllerModules.keySimulator import keySimulator
TB-1993 marked this conversation as resolved.
Show resolved Hide resolved

class remoteControllerMapping():
def __init__(self, log:logModule, mappingConfig:dict):
Expand Down Expand Up @@ -75,7 +76,7 @@ def getMappedKey(self, key:str):
prefix = self.currentMap.get("prefix")
returnedKey=self.currentMap["codes"].get(key)
if prefix:
returnedKey = prefix+key
returnedKey = prefix + returnedKey
return returnedKey

def getKeyMap(self):
Expand Down Expand Up @@ -132,6 +133,8 @@ def __init__(self, log:logModule, remoteConfig:dict, **kwargs:dict):
self.remoteController = remoteSkyProc( self.log, remoteConfig )
elif self.type == "arduino":
self.remoteController = remoteArduino (self.log, remoteConfig)
elif self.type == "keySimulator":
self.remoteController = keySimulator (self.log, remoteConfig)
else: # remoteNone otherwise
self.remoteController = remoteNone( self.log, remoteConfig )

Expand All @@ -150,14 +153,7 @@ def __decodeRemoteMapConfig(self):
with open(configFile) as inputFile:
inputFile.seek(0, os.SEEK_SET)
config = yaml.full_load(inputFile)
keyDictionary = {}
for key, val in config.items():
if isinstance(val, dict):
for k, v in val.items():
keyDictionary[k] = v
else:
keyDictionary[key] = val
return keyDictionary
return config.get("remoteMaps", [])

def sendKey(self, keycode:dict, delay:int=1, repeat:int=1, randomRepeat:int=0):
"""Send a key to the remoteCommander
Expand Down Expand Up @@ -192,4 +188,4 @@ def setKeyMap( self, name:dict ):
def getKeyMap( self ):
"""Get the Key Translation Map
"""
self.remoteMap.getKeyMap()
return self.remoteMap.getKeyMap()
59 changes: 59 additions & 0 deletions framework/core/remoteControllerModules/keySimulator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import os
import time
import subprocess
from framework.core.logModule import logModule
from framework.core.commandModules.sshConsole import sshConsole


class KeySimulator:

def __init__(self, log: logModule, remoteConfig: dict):
"""Initialize the KeySimulator class.

Args:
log (logModule): Logging module instance.
remoteConfig (dict): Key simulator configuration.
"""
self.log = log
self.remoteConfig = remoteConfig
self.prompt = r"\$ "
TB-1993 marked this conversation as resolved.
Show resolved Hide resolved

# Initialize SSH session
self.session = sshConsole(
address=self.remoteConfig.get("ip"),
Ulrond marked this conversation as resolved.
Show resolved Hide resolved
username=self.remoteConfig.get("username"),
password=self.remoteConfig.get("password"),
known_hosts=self.remoteConfig.get("known_hosts"),
port=int(self.remoteConfig.get("port")),
tamilarasi-t12 marked this conversation as resolved.
Show resolved Hide resolved
)

self.firstKeyPressInTc = True

def sendKey(self, key: str, repeat: int = 1, delay: int = 0) -> bool:
"""Send a key command with specified repeats and interval.

Args:
key (str): The key to send.
repeat (int): Number of times to send the key.
delay (int): Delay between key presses in seconds.

Returns:
bool: Result of the command verification.
"""
result = True
verify = True
keyword = "term start init 1"
Ulrond marked this conversation as resolved.
Show resolved Hide resolved

# Send the key command
self.session.write(f"{key}")

if verify:
output = self.session.read_until(self.prompt)

# Check for the presence of a keyword in the output
if keyword and keyword not in output:
result = True
else:
time.sleep(delay)
tamilarasi-t12 marked this conversation as resolved.
Show resolved Hide resolved

return result