Skip to content

Commit

Permalink
Exécution du simulateur en TU
Browse files Browse the repository at this point in the history
  • Loading branch information
gdepuille committed May 11, 2021
1 parent 8413568 commit 827f662
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package org.arig.robot;

import lombok.SneakyThrows;
import org.arig.robot.NerellOrdonanceur;
import org.arig.robot.config.spring.NerellSimulator;
import org.arig.robot.config.spring.NerellSimulatorTestContext;
import org.arig.robot.constants.IConstantesConfig;
import org.arig.robot.model.ETeam;
import org.arig.robot.model.NerellRobotStatus;
import org.arig.robot.services.IIOService;
import org.arig.robot.services.NerellEcranService;
import org.arig.robot.services.NerellIOServiceBouchon;
import org.arig.robot.system.capteurs.IEcran;
import org.arig.robot.system.capteurs.NerellTestEcran;
import org.arig.robot.utils.ThreadUtils;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = {NerellSimulator.class, NerellSimulatorTestContext.class})
public class NerellSimulatorTest {

@Autowired
private NerellRobotStatus rs;

@Autowired
private NerellOrdonanceur ordonanceur;

@Autowired
private NerellIOServiceBouchon ioService;

@Autowired
private IEcran ecran;

@BeforeClass
public static void before() {
// Définition d'un ID unique pour le nommage des fichiers
final String execId = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
System.setProperty(IConstantesConfig.keyExecutionId, execId);
System.setProperty(IConstantesConfig.disableEcran, "true");

// Surcharge de bean
System.setProperty("spring.main.allow-bean-definition-overriding", "true");
}

@SneakyThrows
@Test(timeout = 300000)
public void runSimulateurTest() {
rs.simulateur(true);

ExecutorService exec = Executors.newSingleThreadExecutor();
exec.submit(() -> ordonanceur.run());

// Mise enclenchement de l'AU
ThreadUtils.sleep(2000); // FIXME Ordonnanceur STEPS
ioService.au(true);

// Selection de la couleur de l'équipe
ThreadUtils.sleep(2000); // FIXME Ordonnanceur STEPS
((NerellTestEcran) ecran).getConfigInfos().setTeam(1); // 1 Jaune, 2 Bleu

// Start calage bordure
ThreadUtils.sleep(2000); // FIXME Ordonnanceur STEPS
((NerellTestEcran) ecran).getConfigInfos().setStartCalibration(true);

// Mise tirette
ThreadUtils.sleep(10000); // FIXME Ordonnanceur STEPS
ioService.tirette(true);

// Start match
ThreadUtils.sleep(2000); // FIXME Ordonnanceur STEPS
ioService.tirette(false);
ThreadUtils.sleep(2000);
while(rs.matchRunning()) {
ThreadUtils.sleep(5000);
}

// Remise tirette fin match
ioService.tirette(true);

// Check all are executed
exec.awaitTermination(10, TimeUnit.SECONDS);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.arig.robot.config.spring;

import org.arig.robot.system.capteurs.IEcran;
import org.arig.robot.system.capteurs.NerellTestEcran;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

@Configuration
public class NerellSimulatorTestContext extends NerellSimulatorContext {

@Override
@Bean
@DependsOn("ecranProcess")
public IEcran ecran() throws Exception {
return new NerellTestEcran();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.arig.robot.system.capteurs;

import lombok.Getter;
import org.arig.robot.model.ecran.GetConfigInfos;
import org.arig.robot.model.ecran.UpdateMatchInfos;
import org.arig.robot.model.ecran.UpdatePhotoInfos;
import org.arig.robot.model.ecran.UpdateStateInfos;

public class NerellTestEcran implements IEcran {

@Getter
private final GetConfigInfos configInfos;

public NerellTestEcran() {
configInfos = new GetConfigInfos();
configInfos.setTeam(-1);
}

@Override
public GetConfigInfos configInfos() {
return configInfos;
}

@Override
public void end() {
}

@Override
public void updateState(final UpdateStateInfos data) {
}

@Override
public void updateMatch(final UpdateMatchInfos data) {
}

@Override
public void updatePhoto(final UpdatePhotoInfos photo) {
}
}

0 comments on commit 827f662

Please sign in to comment.