Skip to content

Commit

Permalink
[75] updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mirage22 committed Dec 14, 2024
1 parent a8ed463 commit 28143b7
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 168 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
public class MessageServerTest {
private static final Logger LOGGER = LoggerFactory.getLogger(MessageServerTest.class);
private static final int TIMEOUT_SEC = 30;
private static final String CONST_MYUUID = "myuuid";
private static final String CONST_MY_UUID = "myuuid";
private static final String PROPERTY_SERVER_NAME = "ServerName";
private static final int SERVER_LISTEN_DELAY_MILLIS = 250;
private static final String LOCALHOST_VALUE = "localhost";
Expand All @@ -53,6 +53,7 @@ public class MessageServerTest {

@Test
void clientServerMessagePassingTest() throws Exception {

final var messageCache = new ArrayList<>();
final var messagesLatch = new CountDownLatch(3);

Expand Down Expand Up @@ -85,7 +86,7 @@ void clientServerMessagePassingTest() throws Exception {
}

var messageReceiverConfig = ConfigurationFactory.createEmptyConfiguration();
var messageReceiver = new MessageClient(messageServer.getListeningURI(), CONST_MYUUID, messageReceiverConfig);
var messageReceiver = new MessageClient(messageServer.getListeningURI(), CONST_MY_UUID, messageReceiverConfig);
if (exception != null) {
throw exception;
}
Expand Down Expand Up @@ -147,7 +148,7 @@ void testMessageTypes() throws Exception {
}

Configuration clientConfig = ConfigurationFactory.createEmptyConfiguration();
MessageClient client = new MessageClient(messageServer.getListeningURI(), CONST_MYUUID, clientConfig);
MessageClient client = new MessageClient(messageServer.getListeningURI(), CONST_MY_UUID, clientConfig);
if (exception != null) {
throw exception;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class RemoteContextTests {

@Test
void discoveryOfDiscoveryEnabledRoboContextTest() throws RoboBuilderException, IOException {
var expectedMetaDataName = "Caprica";
var expectedMetaDataClass = "Cylon";

RoboBuilder builder = new RoboBuilder(SystemUtil.getInputStreamByResourceName("testDiscoverableSystem.xml"));
RoboContext ctx = builder.build();
ctx.start();
Expand All @@ -75,8 +78,8 @@ void discoveryOfDiscoveryEnabledRoboContextTest() throws RoboBuilderException, I
RoboContextDescriptor descriptor = service.getDescriptor("6");

assertFalse(service.getDiscoveredContexts().isEmpty());
assertEquals(descriptor.getMetadata().get("name"), "Caprica");
assertEquals(descriptor.getMetadata().get("class"), "Cylon");
assertEquals(expectedMetaDataName, descriptor.getMetadata().get("name"));
assertEquals(expectedMetaDataClass, descriptor.getMetadata().get("class"));
ctx.shutdown();
}

Expand Down
100 changes: 52 additions & 48 deletions robo4j-hw-rpi/src/main/java/com/robo4j/hw/rpi/gps/Location.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,63 +18,67 @@

/**
* A 2D location on earth.
*
*
* @author Marcus Hirt (@hirt)
* @author Miro Wengner (@miragemiko)
*/
public final class Location {
private static final String STR_DEGREE = "\u00B0";
private static final String STR_MINUTE = "'"; // "\u2032";
private static final String STR_SECOND = "\""; // \u2033";
private static final String STR_DEGREE = "\u00B0";
private static final String STR_MINUTE = "'"; // "\u2032";
private static final String STR_SECOND = "\""; // \u2033";
public static final int DEGREE_MINS = 60;
public static final int DEGREE_SECONDS = 3600;

private final float latitude;
private final float longitude;

private final float latitude;
private final float longitude;
/**
* Creates a new location.
*
* @param latitude the latitude in decimal degrees.
* @param longitude the longitude in decimal degrees.
*/
public Location(float latitude, float longitude) {
this.latitude = latitude;
this.longitude = longitude;
}

/**
* Creates a new location.
*
* @param latitude
* the latitude in decimal degrees.
* @param longitude
* the longitude in decimal degrees.
*/
public Location(float latitude, float longitude) {
this.latitude = latitude;
this.longitude = longitude;
}
/**
* @return the decimal degree for the latitude.
*/
public float getLatitude() {
return latitude;
}

/**
* @return the decimal degree for the latitude.
*/
public float getLatitude() {
return latitude;
}
/**
* @return the decimal degree for the longitude.
*/
public float getLongitude() {
return longitude;
}

/**
* @return the decimal degree for the longitude.
*/
public float getLongitude() {
return longitude;
}
/**
* Returns the coordinates as a String in degrees, minutes and seconds format.
*
* @return the coordinates as a String in degrees, minutes and seconds format.
*/
public String asDMS() {
return String.format("%s%s %s%s", toDMS(latitude), latitude > 0 ? "N" : "S", toDMS(longitude), longitude > 0 ? "E" : "W");
}

/**
* Returns the coordinates as a String in degrees, minutes and seconds format.
*
* @return the coordinates as a String in degrees, minutes and seconds format.
*/
public String asDMS() {
return String.format("%s%s %s%s", toDMS(latitude), latitude > 0 ? "N" : "S", toDMS(longitude), longitude > 0 ? "E" : "W");
}
private Object toDMS(float coordinateInDegree) {
int degreesIntAbs = Math.abs((int) coordinateInDegree);
int minute = convertDegreesByConversionType(degreesIntAbs, DEGREE_MINS);
int second = convertDegreesByConversionType(degreesIntAbs, DEGREE_SECONDS);
return String.format("%d%s%d%s%d%s", degreesIntAbs, STR_DEGREE, minute, STR_MINUTE, second, STR_SECOND);
}

private Object toDMS(float coordinate) {
int deg = Math.abs((int) coordinate);
int minute = Math.abs((int) (coordinate * 60) % 60);
int second = Math.abs((int) (coordinate * 3600) % 60);
return String.format("%d%s%d%s%d%s", deg, STR_DEGREE, minute, STR_MINUTE, second, STR_SECOND);
}
@Override
public String toString() {
return asDMS();
}

@Override
public String toString() {
return asDMS();
}
private int convertDegreesByConversionType(int degree, int multiplier) {
return (degree * multiplier) % DEGREE_MINS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,28 +81,24 @@ short intToShort(int value) {
*/
void setColorByMatrixToBuffer(short x, short y, BiColor color) {
switch (color) {
case RED:
case RED -> {
// Turn on red LED.
buffer[y] |= _BV(intToShort(x + 8));
// Turn off green LED.
buffer[y] &= (short) ~_BV(x);
break;
case YELLOW:
}
case YELLOW -> {
// Turn on green and red LED.
buffer[y] |= (short) (_BV(intToShort(x + 8)) | _BV(x));
break;
case GREEN:
}
case GREEN -> {
// Turn on green LED.
buffer[y] |= _BV(x);
// Turn off red LED.
buffer[y] &= (short) ~_BV(intToShort(x + 8));
break;
case OFF:
buffer[y] &= (short) (~_BV(x) & ~_BV(intToShort(x + 8)));
break;
default:
LOGGER.warn("setColorByMatrixToBuffer: {}", color);
break;
}
case OFF -> buffer[y] &= (short) (~_BV(x) & ~_BV(intToShort(x + 8)));
default -> LOGGER.warn("setColorByMatrixToBuffer: {}", color);
}
}

Expand Down Expand Up @@ -134,36 +130,31 @@ void setValue(int n, short v, boolean dp) {
*/
void setColorToBarBuffer(short a, short c, BiColor color) {
switch (color) {
case RED:
case RED -> {
// Turn on red LED.
buffer[c] |= _BV(a);
// Turn off green LED.
buffer[c] &= (short) ~_BV(intToShort(a + 8));
break;
case YELLOW:
}
case YELLOW -> {
// Turn on red and green LED.
buffer[c] |= (short) (_BV(a) | _BV(intToShort(a + 8)));
break;
case GREEN:
}
case GREEN -> {
// Turn on green LED.
buffer[c] |= _BV(intToShort(a + 8));
// Turn off red LED.
buffer[c] &= (short) ~_BV(a);
break;
case OFF:
}
case OFF -> {
// Turn off red and green LED.
buffer[c] &= (short) (~_BV(a) & ~_BV(intToShort(a + 8)));
break;
default:
LOGGER.warn("setColorToBarBuffer: {}", color);
break;
}
default -> LOGGER.warn("setColorToBarBuffer: {}", color);
}
}

private void initiate(int brightness) throws IOException {
// i2CConfig.write((byte) (OSCILLATOR_TURN_ON)); // Turn on oscilator
// i2CConfig.write(blinkRate(HT16K33_BLINK_OFF));
// i2CConfig.write(setBrightness(brightness));
writeByte((byte) (OSCILLATOR_TURN_ON)); // Turn on oscilator
writeByte(blinkRate(HT16K33_BLINK_OFF));
writeByte(setBrightness(brightness));
Expand All @@ -172,8 +163,6 @@ private void initiate(int brightness) throws IOException {
private void writeDisplay() throws IOException {
int address = 0;
for (short value : buffer) {
// i2CConfig.write(address++, (byte) (buffer[i] & 0xFF));
// i2CConfig.write(address++, (byte) (buffer[i] >> 8));
writeByte(address++, (byte) (value & 0xFF));
writeByte(address++, (byte) (value >> 8));
}
Expand Down
Loading

0 comments on commit 28143b7

Please sign in to comment.