Java Reference
In-Depth Information
// The current implementation displays the result on the
// standard output
protected synchronized void
writeOut(String data) {
System.out.println(data);
}
// the following two methods synchronize the read and
// write operations of the robot's position performed by
// the robot's devices
public void
readPosition(Position position) {
synchronized
(
this
.position) {
this
.position.copyTo(position);
}
}
public void
writePosition(Position position) {
synchronized
(
this
.position) {
position.copyTo(
this
.position);
}
}
// starts the robot's devices
public void
start() {
platform.start();
for
(
int
i
#
0; i < sensors.size(); i
!!
) {
Device sensor
#
(Device) sensors.get(i);
sensor.start();
}
}
// The println() method parses a string that specifies a
// command according to the following format :
// "<deviceName>.<command> <parameter>".
// It invokes the println() method of that device. Returns
// false if the device name is incorrect
public boolean
println(String p_command) {
int
indexInit
#
p_command.indexOf(".");
if
(indexInit < 0)
return false
;
String deviceName
#
p_command.substring(0, indexInit);
String command
#
p_command.substring(indexInit
!
1);
if
(deviceName.equals(
this
.name)
&& command.equalsIgnoreCase("GETPOS")) {
writeOut("GETPOS X
#
"
!
position.getX()
!
" Y
#
"
!
position.getY()
!
" DIR
#
"
!
Math.toDegrees(position.getT()));
}
else if
(deviceName.equals(platform.name))
return
platform.println(command);