diff --git a/examples/configs/example_rack_config.yml b/examples/configs/example_rack_config.yml index 1b89f0d..9a2cfb5 100644 --- a/examples/configs/example_rack_config.yml +++ b/examples/configs/example_rack_config.yml @@ -71,6 +71,8 @@ rackConfig: # [ type: "olimex", ip: "192.168.0.17", port: 7, map: "llama_rc6", config: "remote_commander.yml" ] # [ type: "skyProc", map: "skyq_map", config: "remote_commander.yml" ] # [ type: "None" ] + # To use keySimulator RDK Middleware is required + # [ type: "keySimulator", ip: "192.168.50.99", port: 10022, username: "root", password: '', map: "keysimulator_rdk", config: "rdk_keymap.yml" ] # [ outbound: optional ] - This section is used to configure paths for downloads and uploads from your test # supported usage: diff --git a/framework/core/commonRemote.py b/framework/core/commonRemote.py index cb173f5..44c7950 100644 --- a/framework/core/commonRemote.py +++ b/framework/core/commonRemote.py @@ -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 class remoteControllerMapping(): def __init__(self, log:logModule, mappingConfig:dict): @@ -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): @@ -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 ) @@ -157,7 +160,7 @@ def __decodeRemoteMapConfig(self): keyDictionary[k] = v else: keyDictionary[key] = val - return keyDictionary + return keyDictionary.get("remoteMaps") def sendKey(self, keycode:dict, delay:int=1, repeat:int=1, randomRepeat:int=0): """Send a key to the remoteCommander @@ -192,4 +195,4 @@ def setKeyMap( self, name:dict ): def getKeyMap( self ): """Get the Key Translation Map """ - self.remoteMap.getKeyMap() + return self.remoteMap.getKeyMap() diff --git a/framework/core/remoteControllerModules/keySimulator.py b/framework/core/remoteControllerModules/keySimulator.py new file mode 100644 index 0000000..08f027b --- /dev/null +++ b/framework/core/remoteControllerModules/keySimulator.py @@ -0,0 +1,78 @@ +# ** ***************************************************************************** +# * +# * If not stated otherwise in this file or this component's LICENSE file the +# * following copyright and licenses apply: +# * +# * Copyright 2023 RDK Management +# * +# * Licensed under the Apache License, Version 2.0 (the "License"); +# * you may not use this file except in compliance with the License. +# * You may obtain a copy of the License at +# * +# * +# http://www.apache.org/licenses/LICENSE-2.0 +# * +# * Unless required by applicable law or agreed to in writing, software +# * distributed under the License is distributed on an "AS IS" BASIS, +# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# * See the License for the specific language governing permissions and +# * limitations under the License. +# * +# * ****************************************************************************** +# * +# * ** Project : RAFT +# * ** @addtogroup : core.remoteControllerModules +# * ** @date : 27/11/2024 +# * ** +# * ** @brief : remote keySimulator +# * ** +# * ****************************************************************************** +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 + + # Initialize SSH session + self.session = sshConsole( + address=self.remoteConfig.get("ip"), + username=self.remoteConfig.get("username"), + password=self.remoteConfig.get("password"), + known_hosts=self.remoteConfig.get("known_hosts"), + port=int(self.remoteConfig.get("port")), + prompt=self.remoteConfig.get("prompt"), + log=self.log, + ) + + def sendKey(self, key: str, repeat: int, delay: int): + """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 = False + + # Send the key command + for _ in range(repeat): + result = self.session.write(f"keySimulator -k{key}", wait_for_prompt=True) + time.sleep(delay) + + return result