Skip to content

Commit

Permalink
[69] logger add
Browse files Browse the repository at this point in the history
  • Loading branch information
mirage22 committed Oct 8, 2024
1 parent a603936 commit 094d15d
Show file tree
Hide file tree
Showing 36 changed files with 881 additions and 822 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
*/
public interface ILegoSensor {

DigitalPortEnum getPort();
DigitalPortEnum port();

SensorTypeEnum getType();
SensorTypeEnum type();

String getData();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ public SensorWrapper(Sensor sensor, DigitalPortEnum port, SensorTypeEnum sensorT
}

@Override
public SensorTypeEnum getType() {
public SensorTypeEnum type() {
return sensorType;
}

@Override
public DigitalPortEnum getPort() {
public DigitalPortEnum port() {
return port;
}

Expand Down
9 changes: 9 additions & 0 deletions robo4j-units-lego/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,17 @@
<groupId>com.robo4j</groupId>
<artifactId>robo4j-socket-http</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<!-- TEST -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,40 @@
import com.robo4j.RoboReference;
import com.robo4j.hw.lego.util.EscapeButtonUtil;
import com.robo4j.util.SystemUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.FileInputStream;
import java.io.InputStream;

/**
* GripperSonicTankPlatformExample is the simple example of tank platform based LegoEV3 device
*
*
* @author Marcus Hirt (@hirt)
* @author Miroslav Wengner (@miragemiko)
*/
public class GripperSonicTankPlatformExample {
private static final Logger LOGGER = LoggerFactory.getLogger(GripperSonicTankPlatformExample.class);

public static void main(String[] args) throws Exception {
final String robo4jConfig= "robo4jGripperSonicTankPlatform.xml";
final String robo4jConfig = "robo4jGripperSonicTankPlatform.xml";
InputStream settings = GripperSonicTankPlatformExample.class.getClassLoader().getResourceAsStream(robo4jConfig);
if (args.length != 1) {
System.out.println(String.format("No file specified, using default %s", robo4jConfig));
LOGGER.info("No file specified, using default {}", robo4jConfig);
} else {
settings = new FileInputStream(args[0]);
}

final RoboBuilder builder = new RoboBuilder();
if(settings == null){
System.out.println("Could not find the settings for test!");
if (settings == null) {
LOGGER.warn("Could not find the settings for test!");
System.exit(2);
}

builder.add(settings);
RoboContext system = builder.build();
System.out.println("State before start:");
System.out.println(SystemUtil.printStateReport(system));
LOGGER.info("State before start:");
LOGGER.info(SystemUtil.printStateReport(system));


system.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
import com.robo4j.RoboReference;
import com.robo4j.hw.lego.util.EscapeButtonUtil;
import com.robo4j.util.SystemUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.FileInputStream;
import java.io.InputStream;

/**
* InfraPushTankPlatformExample lego platform example with push and infra red sensor
Expand All @@ -32,28 +33,28 @@
* @author Miroslav Wengner (@miragemiko)
*/
public class InfraPushTankPlatformExample {
private static final Logger LOGGER = LoggerFactory.getLogger(InfraPushTankPlatformExample.class);

public static void main(String[] args) throws Exception {
final String robo4jSystem = "robo4jSystem.xml";
final String robo4jConfig= "robo4jInfraPushTankPlatformExample.xml";
final InputStream systemSystem = InfraSensorExample.class.getClassLoader().getResourceAsStream(robo4jSystem);
InputStream settings = GripperSonicTankPlatformExample.class.getClassLoader().getResourceAsStream(robo4jConfig);
final var robo4jSystem = "robo4jSystem.xml";
final var robo4jConfig = "robo4jInfraPushTankPlatformExample.xml";
final var systemSystem = InfraSensorExample.class.getClassLoader().getResourceAsStream(robo4jSystem);
var settings = GripperSonicTankPlatformExample.class.getClassLoader().getResourceAsStream(robo4jConfig);
if (args.length != 1) {
System.out.println(String.format("No file specified, using default %s", robo4jConfig));
LOGGER.info("No file specified, using default {}", robo4jConfig);
} else {
settings = new FileInputStream(args[0]);
}

final RoboBuilder builder = new RoboBuilder(systemSystem);
if(settings == null){
System.out.println("Could not find the settings for test!");
final var builder = new RoboBuilder(systemSystem);
if (settings == null) {
LOGGER.warn("Could not find the settings for test!");
System.exit(2);
}

builder.add(settings);
RoboContext system = builder.build();
System.out.println(SystemUtil.printStateReport(system));

LOGGER.info(SystemUtil.printStateReport(system));

system.start();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,49 +21,51 @@
import com.robo4j.RoboReference;
import com.robo4j.hw.lego.util.EscapeButtonUtil;
import com.robo4j.util.SystemUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.FileInputStream;
import java.io.InputStream;

/**
* @author Marcus Hirt (@hirt)
* @author Miroslav Wengner (@miragemiko)
*/
public class InfraSensorExample {
private static final Logger LOGGER = LoggerFactory.getLogger(InfraSensorExample.class);

public static void main(String[] args) throws Exception {
final String robo4jConfig = "robo4jInfraExample.xml";
InputStream settings = InfraSensorExample.class.getClassLoader().getResourceAsStream(robo4jConfig);
if (args.length != 1) {
System.out.println(String.format("No file specified, using default %s", robo4jConfig));
} else {
settings = new FileInputStream(args[0]);
}
public static void main(String[] args) throws Exception {
final var robo4jConfig = "robo4jInfraExample.xml";
var settings = InfraSensorExample.class.getClassLoader().getResourceAsStream(robo4jConfig);
if (args.length != 1) {
LOGGER.info("No file specified, using default {}", robo4jConfig);
} else {
settings = new FileInputStream(args[0]);
}

final RoboBuilder builder = new RoboBuilder();
if (settings == null) {
System.out.println("Could not find the settings for test!");
System.exit(2);
}
final var builder = new RoboBuilder();
if (settings == null) {
LOGGER.warn("Could not find the settings for test!");
System.exit(2);
}

builder.add(settings);
RoboContext system = builder.build();
System.out.println("State before start:");
System.out.println(SystemUtil.printStateReport(system));
builder.add(settings);
RoboContext system = builder.build();
LOGGER.info("State before start:");
LOGGER.info(SystemUtil.printStateReport(system));

system.start();
system.start();

RoboReference<String> lcd = system.getReference("lcd");
lcd.sendMessage("Robo4J.io");
RoboReference<String> lcd = system.getReference("lcd");
lcd.sendMessage("Robo4J.io");

RoboReference<String> infraSensor = system.getReference("infraSensor");
infraSensor.sendMessage("start");
RoboReference<String> infraSensor = system.getReference("infraSensor");
infraSensor.sendMessage("start");

shutdown(system);
}
shutdown(system);
}

private static void shutdown(RoboContext system) {
EscapeButtonUtil.waitForPressAndRelease();
system.shutdown();
}
private static void shutdown(RoboContext system) {
EscapeButtonUtil.waitForPressAndRelease();
system.shutdown();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,22 @@

import com.robo4j.RoboContext;
import com.robo4j.RoboUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* @author Marcus Hirt (@hirt)
* @author Miroslav Wengner (@miragemiko)
*/
public class ReportController extends RoboUnit<Object> {
private static final Logger LOGGER = LoggerFactory.getLogger(ReportController.class);

public ReportController(RoboContext context, String id) {
super(Object.class, context, id);
}

@Override
public void onMessage(Object message) {
System.out.println(getClass().getSimpleName() + "report: " + message.toString());
LOGGER.info("report: {}", message.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import com.robo4j.hw.lego.ILegoMotor;
import com.robo4j.hw.lego.enums.AnalogPortEnum;
import com.robo4j.hw.lego.enums.MotorTypeEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Simple LegoMindstorm Mock Motor
Expand All @@ -28,6 +30,8 @@
*/
public class MotorTestWrapper implements ILegoMotor {

private static final Logger LOGGER = LoggerFactory.getLogger(MotorTestWrapper.class);

private final AnalogPortEnum port;
private final MotorTypeEnum type;
private boolean moving;
Expand All @@ -52,25 +56,25 @@ public MotorTypeEnum getType() {
@Override
public void forward() {
moving = true;
System.out.println(String.format("MotorTest.forward port:%s, type: %s, moving: %b ", port, type, moving));
LOGGER.info("MotorTest.forward port:{}, type: {}, moving: {} ", port, type, moving);
}

@Override
public void backward() {
moving = true;
System.out.println(String.format("MotorTest.backward port:%s, type: %s, moving: %b ", port, type, moving));
LOGGER.info("MotorTest.backward port:{}, type: {}, moving: {} ", port, type, moving);
}

@Override
public void stop() {
moving = false;
System.out.println(String.format("MotorTest.stop port:%s, type: %s, moving: %b ", port, type, moving));
LOGGER.info("MotorTest.stop port:{}, type: {}, moving: {} ", port, type, moving);

}

@Override
public void rotate(int val) {
System.out.println("rotate: " + val);
LOGGER.info("rotate: {}", val);
}

@Override
Expand All @@ -80,14 +84,14 @@ public boolean isMoving() {

@Override
public void setSpeed(int speed) {
System.out.println("speed: " + speed);
LOGGER.info("speed: {}", speed);
this.speed = speed;
}

@Override
public void close() {
moving = false;
System.out.println(String.format("MotorTest.close port:%s, type: %s, moving: %b ", port, type, moving));
LOGGER.info("MotorTest.close port:{}, type: {}, moving: {} ", port, type, moving);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,52 +19,37 @@
import com.robo4j.hw.lego.ILegoSensor;
import com.robo4j.hw.lego.enums.DigitalPortEnum;
import com.robo4j.hw.lego.enums.SensorTypeEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Simple LegoMindstorm Mock Sensor
*
* @author Marcus Hirt (@hirt)
* @author Miro Wengner (@miragemiko)
*/
public class SensorTestWrapper implements ILegoSensor {

private final DigitalPortEnum port;
private final SensorTypeEnum type;

public SensorTestWrapper(DigitalPortEnum port, SensorTypeEnum type) {
this.port = port;
this.type = type;
}

@Override
public DigitalPortEnum getPort() {
return port;
}

@Override
public SensorTypeEnum getType() {
return type;
}

@Override
public String getData() {
System.out.println(String.format("SensorTest.getData port:%s, type: %s", port, type));
return "data";
}

@Override
public void activate(boolean status) {
System.out.println(String.format("SensorTest.activate %s, port:%s, type: %s", status, port, type));
}

@Override
public void close() {
System.out.println(String.format("SensorTest.close port:%s, type: %s", port, type));
}

@Override
public String toString() {
return "SensorTestWrapper{" + "port=" + port + ", type=" + type + '}';
}
public record SensorTestWrapper(DigitalPortEnum port, SensorTypeEnum type) implements ILegoSensor {
private static final Logger LOGGER = LoggerFactory.getLogger(SensorTestWrapper.class);

@Override
public String getData() {
LOGGER.info("SensorTest.getData port:{}, type: {}", port, type);
return "data";
}

@Override
public void activate(boolean status) {
LOGGER.info("SensorTest.activate {}, port:{}, type: {}", status, port, type);
}

@Override
public void close() {
LOGGER.info("SensorTest.close port:{}, type: {}", port, type);
}

@Override
public String toString() {
return "SensorTestWrapper{" + "port=" + port + ", type=" + type + '}';
}

}
Loading

0 comments on commit 094d15d

Please sign in to comment.