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 9 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
2 changes: 2 additions & 0 deletions examples/configs/example_rack_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
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()
87 changes: 87 additions & 0 deletions framework/core/remoteControllerModules/keySimulator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#** *****************************************************************************
# *
# * 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
from framework.core.rcCodes import rcCode as rc


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
)


def sendKey(self, key: rc, repeat: int , delay: int ):
"""Send a key command with specified repeats and interval.

Args:
key (rc): The key to send.
tamilarasi-t12 marked this conversation as resolved.
Show resolved Hide resolved
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
keyword = "term start init 1"
Ulrond marked this conversation as resolved.
Show resolved Hide resolved

# Send the key command
for _ in range(repeat):
self.session.write(f"{key}")
time.sleep(delay)

# Read output after sending keys
output = self.session.read_until(self.prompt)

# Check for the presence of a keyword in the output
if keyword in output:
result = True
tamilarasi-t12 marked this conversation as resolved.
Show resolved Hide resolved
tamilarasi-t12 marked this conversation as resolved.
Show resolved Hide resolved

return result