Skip to content

Commit

Permalink
Filter out warning when connecting (#1369)
Browse files Browse the repository at this point in the history
  • Loading branch information
supertick authored Nov 25, 2023
1 parent ed46df7 commit 3e3e911
Show file tree
Hide file tree
Showing 8 changed files with 1,386 additions and 1,338 deletions.
2,672 changes: 1,340 additions & 1,332 deletions src/main/java/org/myrobotlab/arduino/Msg.java

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/main/java/org/myrobotlab/arduino/virtual/MrlComm.java
Original file line number Diff line number Diff line change
Expand Up @@ -1018,4 +1018,9 @@ public void neoPixelSetBrightness(Integer deviceId, Integer brightness) {

}

public boolean isConnecting() {
// TODO Auto-generated method stub
return false;
}

}
18 changes: 16 additions & 2 deletions src/main/java/org/myrobotlab/service/Arduino.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ public static class I2CDeviceMap {
boolean boardInfoEnabled = true;

private long boardInfoRequestTs;

/**
* connecting is true while the arduino is in the process of connecting
* to a port
*/
protected boolean connecting = false;

@Deprecated /*
* should develop a MrlSerial on Arduinos and
Expand Down Expand Up @@ -535,7 +541,7 @@ public VirtualArduino getVirtual() {
*/
@Override
public void connect(String port, int rate, int databits, int stopbits, int parity) {

connecting = true;
if (port == null) {
warn("%s attempted to connect with a null port", getName());
return;
Expand Down Expand Up @@ -596,6 +602,7 @@ public void connect(String port, int rate, int databits, int stopbits, int parit
sleep(30);
}

connecting = false;
log.info("waited {} ms for Arduino {} to say hello", System.currentTimeMillis() - startBoardRequestTs, getName());

// we might be connected now
Expand Down Expand Up @@ -1341,6 +1348,10 @@ public boolean isAttached(Attachable service) {
public boolean isAttached(String name) {
return deviceList.containsKey(name);
}

public boolean isConnecting() {
return connecting;
}

@Override
public boolean isConnected() {
Expand Down Expand Up @@ -1595,13 +1606,16 @@ public BoardInfo publishBoardInfo(Integer version/* byte */,

boardInfo = new BoardInfo(version, boardTypeId, boardTypeName, microsPerLoop, sram, activePins, arrayToDeviceSummary(deviceSummary), boardInfoRequestTs);

// connected now
connecting = false;

boardInfoRequestTs = System.currentTimeMillis();

log.debug("Version return by Arduino: {}", boardInfo.getVersion());
log.debug("Board type currently set: {} => {}", boardTypeId, boardTypeName);

if (lastBoardInfo == null || !lastBoardInfo.getBoardTypeName().equals(board)) {
log.warn("setting board to type {}", board);
log.info("setting board to type {}", boardInfo.getBoardTypeName());
this.board = boardInfo.getBoardTypeName();
// we don't invoke, because
// it might get into a race condition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public BoardInfo publishBoardInfo(Integer version/* byte */,
public String publishMRLCommError(String errorMsg);

public PinData[] publishPinArray(int[] data);


public boolean isConnecting();

public String getName();

public Integer publishUltrasonicSensorData(Integer deviceId, Integer echoTime);
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/resource/Arduino/MrlComm/MrlNeopixel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ void MrlNeopixel::setAnimation(byte animation, byte red, byte green, byte blue,
{
animationIndex = animation;
x = 0;
y = 0;
z = 0;
color = Adafruit_NeoPixel::Color(red, green, blue, white);
wait = wait_ms;
if (animation == 0)
Expand Down
11 changes: 8 additions & 3 deletions src/main/resources/resource/Arduino/generate/Msg.java.template
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ public class %javaClass% {
msgSize = 0;
Arrays.fill(ioCmd, 0); // FIXME - optimize - remove
// warn(String.format("Arduino->MRL error - bad magic number %d - %d rx errors", newByte, ++errorServiceToHardwareRxCnt));
log.warn("Arduino->MRL error - bad magic number {} - {} rx errors", newByte, ++errorServiceToHardwareRxCnt);
if (!arduino.isConnecting()){
log.warn("Arduino->MRL error - bad magic number {} - {} rx errors", newByte, ++errorServiceToHardwareRxCnt);
}
}
continue;
} else if (byteCount.get() == 2) {
Expand Down Expand Up @@ -267,7 +269,10 @@ public class %javaClass% {
}

if (!clearToSend) {
log.warn("NOT CLEAR TO SEND! resetting parser!");
if (!arduino.isConnecting()) {
// we're connecting, so we're going to ignore the message.
log.warn("NOT CLEAR TO SEND! resetting parser!");
}
// We opened the port, and we got some data that isn't a Begin message.
// so, I think we need to reset the parser and continue processing bytes...
// there will be errors until the next magic byte is seen.
Expand Down Expand Up @@ -482,7 +487,7 @@ public class %javaClass% {
}

public void waitForAck(){
if (!ackEnabled) {
if (!ackEnabled || serial == null || !serial.isConnected()) {
return;
}
// if there's a pending message, we need to wait for the ack to be received.
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/org/myrobotlab/arduino/MrlCommDirectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -366,4 +366,10 @@ public Object invoke(String method, Object... params) {
return null;
}

@Override
public boolean isConnecting() {
// TODO Auto-generated method stub
return false;
}

}
6 changes: 6 additions & 0 deletions src/test/java/org/myrobotlab/service/VirtualArduinoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,10 @@ public Object invoke(String method, Object... params) {
return null;
}

@Override
public boolean isConnecting() {
// TODO Auto-generated method stub
return false;
}

}

0 comments on commit 3e3e911

Please sign in to comment.