Skip to content

Commit

Permalink
better lora-at response filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
dernasherbrezon committed Dec 22, 2023
1 parent 1d78164 commit 2cb3638
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/main/java/ru/r2cloud/lora/loraat/LoraAtSerialClient2.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public LoraStatus getStatus() {
LoraStatus result = new LoraStatus();
try {
ModulationConfig loraConfig = new ModulationConfig();
loraConfig.setName(readParameter("AT+GMR"));
loraConfig.setName("lora");
loraConfig.setMinFrequency(Long.parseLong(readParameter("AT+MINFREQ?")));
loraConfig.setMaxFrequency(Long.parseLong(readParameter("AT+MAXFREQ?")));
List<ModulationConfig> configs = new ArrayList<>();
Expand Down Expand Up @@ -183,6 +183,8 @@ private List<String> sendRequest(String request) throws LoraAtException {
if (!port.openPort()) {
throw new LoraAtException("can't open port: " + portDescriptor);
}
//TODO send \r\n before any command
//TODO discard everything
try {
port.getOutputStream().write((request + "\r\n").getBytes(StandardCharsets.ISO_8859_1));
} catch (IOException e) {
Expand Down Expand Up @@ -213,15 +215,15 @@ private static List<String> readResponse(SerialPortInterface port) throws IOExce
if (curLine.length() == 0) {
continue;
}
if (curLine.startsWith("E ")) {
if (curLine.startsWith("E ") || curLine.startsWith("[0;32mE")) {
LOG.error("response: {}", curLine);
} else if (curLine.startsWith("W ")) {
} else if (curLine.startsWith("W ") || curLine.startsWith("[0;32mW")) {
LOG.warn("response: {}", curLine);
} else {
LOG.info("response: {}", curLine);
}
// skip logging
if (curLine.startsWith("I ") || curLine.startsWith("W ") || curLine.startsWith("E ")) {
if (curLine.startsWith("I ") || curLine.startsWith("W ") || curLine.startsWith("E ") || curLine.contains("[") || curLine.contains("(")) {
continue;
}
if (curLine.equalsIgnoreCase("ERROR")) {
Expand Down

0 comments on commit 2cb3638

Please sign in to comment.