def send_report(self, trigger, analyzer):
     filter_report = self.create_vm_reports(trigger, analyzer)
     ip = Emulator.get_emulator().get_remote_ip()
     filter_report['emulator'] = ip
     if Utils.isTestingMode():
         print "FINAL REPORT "
         print filter_report
     else:
         Utils.notify(Utils.get_VM_Manager(), 'report', filter_report)
 def extract_storage(self):
     emulator = Emulator.get_emulator()
     directory = self.extracted_storage_dir()
     if not os.path.exists(directory):
         os.makedirs(directory)
     # dump internal memory and sdcard
     emulator.run_adb_command(
         "pull /data/data/" + self.analyzer.get_package_name() + " " + self.internal_storage_dir())
     emulator.run_adb_command("pull /sdcard/" + " " + self.modified_sdcard_dir())
 def __init__(self):
     self.get_apk_from_manager()
     self.trigger = Trigger.get_trigger_for(self.get_filter_tag(), self.get_package_name(), self.get_description())
     self.reporter = Reporter.get_reporter_for(self.get_filter_tag(), self.get_package_name(),
         self.get_description())
     self.analyzer = Analyzer.get_analyzer_for(self.get_filter_tag(), self.get_package_name(),
         self.get_description())
     self.emulator = Emulator.get_emulator_for(self.get_filter_tag(), self.get_package_name(),
         self.get_description())
     self.error_queue = multiprocessing.Queue()
     self.setup_device()
 def create_vm_reports(self, trigger_rep, analyzer_rep):
     # create final report to send VM Manager
     ip = Emulator.get_emulator().get_remote_ip()
     return {'status': 'ERROR', 'emulator': ip, 'description': {'errors': 'Called abstract method from reporter'}}
def main(args):
    playersControllers = dict()
    # Read the controller configuration
    playersControllers = controllers.loadControllerConfig(
        args.p1index, args.p1guid, args.p1name, args.p1devicepath,
        args.p1nbaxes, args.p2index, args.p2guid, args.p2name,
        args.p2devicepath, args.p2nbaxes, args.p3index, args.p3guid,
        args.p3name, args.p3devicepath, args.p3nbaxes, args.p4index,
        args.p4guid, args.p4name, args.p4devicepath, args.p4nbaxes,
        args.p5index, args.p5guid, args.p5name, args.p5devicepath,
        args.p5nbaxes)
    # find the system to run
    systemName = args.system
    eslog.log("Running system: {}".format(systemName))
    system = Emulator(systemName, args.rom)
    eslog.debug("Settings: {}".format(system.config))
    if "emulator" in system.config and "core" in system.config:
        eslog.log("emulator: {}, core: {}".format(system.config["emulator"],
                                                  system.config["core"]))
    else:
        if "emulator" in system.config:
            eslog.log("emulator: {}".format(system.config["emulator"]))

    # the resolution must be changed before configuration while the configuration may depend on it (ie bezels)
    wantedGameMode = generators[system.config['emulator']].getResolutionMode(
        system.config)
    systemMode = videoMode.getCurrentMode()
    resolutionChanged = False
    exitCode = -1
    try:
        eslog.log("current video mode: {}".format(systemMode))
        eslog.log("wanted video mode: {}".format(wantedGameMode))
        if wantedGameMode != 'default' and wantedGameMode != systemMode:
            videoMode.changeMode(wantedGameMode)
            resolutionChanged = True
        gameResolution = videoMode.getCurrentResolution()
        eslog.log("resolution: {}x{}".format(str(gameResolution["width"]),
                                             str(gameResolution["height"])))

        # savedir: create the save directory if not already done
        dirname = os.path.join(batoceraFiles.savesDir, system.name)
        if not os.path.exists(dirname):
            os.makedirs(dirname)

        # core
        effectiveCore = ""
        if "core" in system.config and system.config["core"] is not None:
            effectiveCore = system.config["core"]
        effectiveRom = ""
        if args.rom is not None:
            effectiveRom = args.rom

        # run a script before emulator starts
        callExternalScripts("/userdata/system/scripts", "gameStart", [
            systemName, system.config['emulator'], effectiveCore, effectiveRom
        ])

        # run the emulator
        exitCode = runCommand(generators[system.config['emulator']].generate(
            system, args.rom, playersControllers, gameResolution))

        # run a script after emulator shuts down
        callExternalScripts("/userdata/system/scripts", "gameStop", [
            systemName, system.config['emulator'], effectiveCore, effectiveRom
        ])

    finally:
        # always restore the resolution
        if resolutionChanged:
            try:
                videoMode.changeMode(systemMode)
            except Exception:
                pass  # don't fail
    # exit
    return exitCode
 def get_emulator(self):
     return Emulator.get_emulator()
def main(args, maxnbplayers):
    playersControllers = dict()

    controllersInput = []
    for p in range(1, maxnbplayers+1):
        ci = {}
        ci["index"]      = getattr(args, "p{}index"     .format(p))
        ci["guid"]       = getattr(args, "p{}guid"      .format(p))
        ci["name"]       = getattr(args, "p{}name"      .format(p))
        ci["devicepath"] = getattr(args, "p{}devicepath".format(p))
        ci["nbbuttons"]  = getattr(args, "p{}nbbuttons" .format(p))
        ci["nbhats"]     = getattr(args, "p{}nbhats"    .format(p))
        ci["nbaxes"]     = getattr(args, "p{}nbaxes"    .format(p))
        controllersInput.append(ci)

    # Read the controller configuration
    playersControllers = controllers.loadControllerConfig(controllersInput)
    # find the system to run
    systemName = args.system
    eslog.log("Running system: {}".format(systemName))
    system = Emulator(systemName, args.rom)

    if args.emulator is not None:
        system.config["emulator"] = args.emulator
        self.config["emulator-forced"] = True
    if args.core is not None:
        system.config["core"] = args.core
        self.config["core-forced"] = True

    eslog.debug("Settings: {}".format(system.config))
    if "emulator" in system.config and "core" in system.config:
        eslog.log("emulator: {}, core: {}".format(system.config["emulator"], system.config["core"]))
    else:
        if "emulator" in system.config:
            eslog.log("emulator: {}".format(system.config["emulator"]))

    # the resolution must be changed before configuration while the configuration may depend on it (ie bezels)
    wantedGameMode = generators[system.config['emulator']].getResolutionMode(system.config)
    systemMode = videoMode.getCurrentMode()

    resolutionChanged = False
    exitCode = -1
    try:
        # lower the resolution if mode is auto
        newsystemMode = systemMode # newsystemmode is the mode after minmax (ie in 1K if tv was in 4K), systemmode is the mode before (ie in es)
        if system.config["videomode"] == "" or system.config["videomode"] == "default":
            eslog.log("minTomaxResolution")
            eslog.log("video mode before minmax: {}".format(systemMode))
            videoMode.minTomaxResolution()
            newsystemMode = videoMode.getCurrentMode()
            if newsystemMode != systemMode:
                resolutionChanged = True

        eslog.log("current video mode: {}".format(newsystemMode))
        eslog.log("wanted video mode: {}".format(wantedGameMode))

        if wantedGameMode != 'default' and wantedGameMode != newsystemMode:
            videoMode.changeMode(wantedGameMode)
            resolutionChanged = True
        gameResolution = videoMode.getCurrentResolution()

        # if resolution is reversed (ie ogoa boards), reverse it in the gameResolution to have it correct
        if system.isOptSet('resolutionIsReversed') and system.getOptBoolean('resolutionIsReversed') == True:
            x = gameResolution["width"]
            gameResolution["width"]  = gameResolution["height"]
            gameResolution["height"] = x
        eslog.log("resolution: {}x{}".format(str(gameResolution["width"]), str(gameResolution["height"])))

        # savedir: create the save directory if not already done
        dirname = os.path.join(batoceraFiles.savesDir, system.name)
        if not os.path.exists(dirname):
            os.makedirs(dirname)

        # core
        effectiveCore = ""
        if "core" in system.config and system.config["core"] is not None:
            effectiveCore = system.config["core"]
        effectiveRom = ""
        if args.rom is not None:
            effectiveRom = args.rom

        # network options
        if args.netplaymode is not None:
            system.config["netplay.mode"] = args.netplaymode
        if args.netplaypass is not None:
            system.config["netplay.password"] = args.netplaypass
        if args.netplayip is not None:
            system.config["netplay.server.ip"] = args.netplayip
        if args.netplayport is not None:
            system.config["netplay.server.port"] = args.netplayport

        # autosave arguments
        if args.state_slot is not None:
            system.config["state_slot"] = args.state_slot
        if args.autosave is not None:
            system.config["autosave"] = args.autosave

        # run a script before emulator starts
        callExternalScripts("/usr/share/batocera/configgen/scripts", "gameStart", [systemName, system.config['emulator'], effectiveCore, effectiveRom])
        callExternalScripts("/userdata/system/scripts", "gameStart", [systemName, system.config['emulator'], effectiveCore, effectiveRom])

        # run the emulator
        try:
            Evmapy.start(systemName, system.config['emulator'], effectiveCore, effectiveRom, playersControllers)
            exitCode = runCommand(generators[system.config['emulator']].generate(system, args.rom, playersControllers, gameResolution))
        finally:
            Evmapy.stop()

        # run a script after emulator shuts down
        callExternalScripts("/userdata/system/scripts", "gameStop", [systemName, system.config['emulator'], effectiveCore, effectiveRom])
        callExternalScripts("/usr/share/batocera/configgen/scripts", "gameStop", [systemName, system.config['emulator'], effectiveCore, effectiveRom])
   
    finally:
        # always restore the resolution
        if resolutionChanged:
            try:
                videoMode.changeMode(systemMode)
            except Exception:
                pass # don't fail
    # exit
    return exitCode
    comm_packet_pb2.WayPoint(Name="WayPoint A",
                             Distance=0.707107,
                             Heading=-45.0),
    comm_packet_pb2.WayPoint(Name="WayPoint B",
                             Distance=0.707107,
                             Heading=45.0),
    comm_packet_pb2.WayPoint(Name="WayPoint C",
                             Distance=0.707107,
                             Heading=135.0),
    comm_packet_pb2.WayPoint(Name="WayPoint D",
                             Distance=0.707107,
                             Heading=270.0)
]

# Use one global Emulator instance for all tests
wbEmulator = Emulator()


class UtCommandAndTracking(unittest.TestCase):
    def setUp(self):
        self.serialComm = SerialCommunication("./ttyclient")
        self.testArticle = CommandAndTracking()
        self.testArticle.connectToWheelBot(self.serialComm)

    def test_commandRoute1(self):
        self.testArticle.loadWayPoints(test_route_1)
        self.testArticle.commandRoute()


if __name__ == '__main__':
    logging.basicConfig(stream=sys.stderr,
 def get_emulator(self):
     return Emulator.get_emulator()
Exemple #10
0
import generators.fba2x.fba2xConfig as fba2xConfig
import settings.unixSettings as unixSettings

fba2xCustom = os.path.abspath(
    os.path.join(os.path.dirname(__file__), 'tmp/fba2x.cfg'))

# Cloning config files
shutil.copyfile(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../resources/fba2x.cfg.origin')), \
                fba2xCustom)

fbaSettings = unixSettings.UnixSettings(fba2xCustom)

# test Systems
fba2xNormal = Emulator(name='fba',
                       videomode='4',
                       ratio='auto',
                       smooth='1',
                       emulator='fba2x')
fba2x43 = Emulator(name='fba',
                   videomode='4',
                   ratio='4/3',
                   smooth='0',
                   shaders='scanlines',
                   emulator='fba2x')
fba2x169 = Emulator(name='fba', videomode='4', ratio='16/9', emulator='fba2x')


class TestFBAConfig(unittest.TestCase):
    def setUp(self):
        # Injecting test file
        fba2xConfig.fbaSettings = fbaSettings
# Injecting test es_input
controllersConfig.esInputs = os.path.abspath(
    os.path.join(os.path.dirname(__file__), "tmp/es_input.cfg"))
# Injecting retroarch configuration
libretroControllers.libretroSettings.settingsFile = RETROARCH_CONFIG
# Test objects
basicInputs1 = {
    'a': controllersConfig.Input("a", "button", "10", "1"),
    'hotkey': controllersConfig.Input("hotkey", "button", "10", "1")
}
basicController1 = controllersConfig.Controller("contr1", "joypad", "GUID1",
                                                "0", "Joypad1RealName",
                                                basicInputs1)
PS3UUID = "060000004c0500006802000000010000"
GPIOUUID = "15000000010000000100000000010000"
snes = Emulator('snes', 'snes', 'libretro')


class TestLibretroController(unittest.TestCase):
    def test_generate_simple_controller(self):
        config = libretroControllers.generateControllerConfig(basicController1)
        self.assertEquals(config['input_device'], '"Joypad1RealName"')
        self.assertEquals(config['input_driver'], '"udev"')
        self.assertEquals(config['input_a_btn'], '10')

    def test_generate_ps3_controller_buttons(self):
        controllers = controllersConfig.loadControllerConfig(
            0, PS3UUID, "p1controller", -1, 0, "p2controller", -1, 0,
            "p3controller", -1, 0, "p4controller")
        config = libretroControllers.generateControllerConfig(controllers["1"])
        self.assertEquals(config['input_device'], '"p1controller"')
Exemple #12
0
    ViceGenerator(),
    'reicast':
    ReicastGenerator(),
    'dolphin':
    DolphinGenerator(),
    'ppsspp':
    PPSSPPGenerator(),
    'advancemame':
    AdvMameGenerator()
}

# List emulators with their cores rest mupen64, scummvm
emulators = dict()
# Nintendo
emulators["snes"] = Emulator(name='snes',
                             emulator='libretro',
                             core='pocketsnes')
emulators["nes"] = Emulator(name='nes', emulator='libretro', core='fceunext')
emulators["n64"] = Emulator(name='n64',
                            emulator='mupen64plus',
                            core='gliden64')
emulators["gba"] = Emulator(name='gba', emulator='libretro', core='gpsp')
emulators["gb"] = Emulator(name='gb', emulator='libretro', core='gambatte')
emulators["gbc"] = Emulator(name='gbc', emulator='libretro', core='gambatte')
emulators["fds"] = Emulator(name='fds', emulator='libretro', core='nestopia')
emulators["virtualboy"] = Emulator(name='virtualboy',
                                   emulator='libretro',
                                   core='vb')
emulators["gamecube"] = Emulator(name='gamecube', emulator='dolphin')
emulators["wii"] = Emulator(name='wii', emulator='dolphin')
# Sega
Exemple #13
0
from BPAgent import BPAgent
from Emulator import Emulator

#CartPole-v0
#Pong-v0
game = 'CartPole-v0'
seed = 50
height = 160
dimensionality = 4
actions = 2
learning_rate = 1e-4
agent = BPAgent(height, dimensionality, actions, learning_rate, seed)

emulator = Emulator(game, agent, seed)

emulator.start()