Skip to content

Commit

Permalink
lora min and max frequencies are now longs
Browse files Browse the repository at this point in the history
  • Loading branch information
dernasherbrezon committed Dec 21, 2023
1 parent cd88f87 commit 1d78164
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/main/java/ru/r2cloud/R2Cloud.java
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ private static void populateFrequencies(LoraStatus status, DeviceConfiguration c
if (!cur.getName().equalsIgnoreCase("lora")) {
continue;
}
config.setMinimumFrequency((long) (cur.getMinFrequency() * 1_000_000));
config.setMaximumFrequency((long) (cur.getMaxFrequency() * 1_000_000));
config.setMinimumFrequency(cur.getMinFrequency());
config.setMaximumFrequency(cur.getMaxFrequency());
return;
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/ru/r2cloud/lora/ModulationConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
public class ModulationConfig {

private String name;
private float minFrequency;
private float maxFrequency;
private long minFrequency;
private long maxFrequency;

public String getName() {
return name;
Expand All @@ -14,19 +14,19 @@ public void setName(String name) {
this.name = name;
}

public float getMinFrequency() {
public long getMinFrequency() {
return minFrequency;
}

public void setMinFrequency(float minFrequency) {
public void setMinFrequency(long minFrequency) {
this.minFrequency = minFrequency;
}

public float getMaxFrequency() {
public long getMaxFrequency() {
return maxFrequency;
}

public void setMaxFrequency(float maxFrequency) {
public void setMaxFrequency(long maxFrequency) {
this.maxFrequency = maxFrequency;
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/ru/r2cloud/lora/loraat/LoraAtSerialClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public LoraAtSerialClient(String portDescriptor, int timeout, SerialInterface se
this.serial = serial;
this.clock = clock;
}

@Override
public boolean isSupported() {
List<String> response;
Expand All @@ -52,7 +52,7 @@ public boolean isSupported() {
LOG.info(e.getMessage());
return false;
}
if( response.isEmpty() || response.size() != 1 ) {
if (response.isEmpty() || response.size() != 1) {
return false;
}
return response.get(0).equalsIgnoreCase("1.0");
Expand Down Expand Up @@ -85,8 +85,8 @@ public LoraStatus getStatus() {
}
ModulationConfig loraConfig = new ModulationConfig();
loraConfig.setName(parts[0].toLowerCase());
loraConfig.setMinFrequency(Float.parseFloat(parts[1]));
loraConfig.setMaxFrequency(Float.parseFloat(parts[2]));
loraConfig.setMinFrequency((long) (Float.parseFloat(parts[1]) * 1_000_000));
loraConfig.setMaxFrequency((long) (Float.parseFloat(parts[2]) * 1_000_000));
configs.add(loraConfig);
}
result.setConfigs(configs);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ru/r2cloud/lora/loraat/LoraAtSerialClient2.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public LoraStatus getStatus() {
try {
ModulationConfig loraConfig = new ModulationConfig();
loraConfig.setName(readParameter("AT+GMR"));
loraConfig.setMinFrequency(Float.parseFloat(readParameter("AT+MINFREQ?")));
loraConfig.setMaxFrequency(Float.parseFloat(readParameter("AT+MAXFREQ?")));
loraConfig.setMinFrequency(Long.parseLong(readParameter("AT+MINFREQ?")));
loraConfig.setMaxFrequency(Long.parseLong(readParameter("AT+MAXFREQ?")));
List<ModulationConfig> configs = new ArrayList<>();
configs.add(loraConfig);
result.setStatus("IDLE");
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ru/r2cloud/lora/r2lora/R2loraClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ private static ModulationConfig readConfig(JsonObject obj, String name) {
JsonObject modulationObj = value.asObject();
ModulationConfig result = new ModulationConfig();
result.setName(name);
result.setMaxFrequency(modulationObj.getFloat("maxFreq", 0));
result.setMinFrequency(modulationObj.getFloat("minFreq", 0));
result.setMaxFrequency((long) (modulationObj.getFloat("maxFreq", 0) * 1_000_000));
result.setMinFrequency((long) (modulationObj.getFloat("minFreq", 0) * 1_000_000));
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ public void testStatusSuccess() {
assertEquals(1, status.getConfigs().size());
ModulationConfig config = status.getConfigs().get(0);
assertEquals("2.0", config.getName());
assertEquals(863000000, config.getMinFrequency(), 0.0f);
assertEquals(928000000, config.getMaxFrequency(), 0.0f);
assertEquals(863000000, config.getMinFrequency());
assertEquals(928000000, config.getMaxFrequency());
assertEquals("AT+GMR\r\nAT+MINFREQ?\r\nAT+MAXFREQ?\r\n", new String(baos.toByteArray(), StandardCharsets.ISO_8859_1));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ public void testStatusSuccess() {
assertEquals(1, status.getConfigs().size());
ModulationConfig config = status.getConfigs().get(0);
assertEquals("lora", config.getName());
assertEquals(863, config.getMinFrequency(), 0.0f);
assertEquals(928, config.getMaxFrequency(), 0.0f);
assertEquals(863000000, config.getMinFrequency());
assertEquals(928000000, config.getMaxFrequency());
}

@Test
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/ru/r2cloud/lora/r2lora/R2loraClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public void testStatus() {
assertEquals(1, status.getConfigs().size());
ModulationConfig loraConfig = status.getConfigs().get(0);
assertEquals("lora", loraConfig.getName());
assertEquals(144.0, loraConfig.getMinFrequency(), 0.0001f);
assertEquals(500.1, loraConfig.getMaxFrequency(), 0.0001f);
assertEquals(144000000, loraConfig.getMinFrequency());
assertEquals(500100000, loraConfig.getMaxFrequency());
}

@Test
Expand Down

0 comments on commit 1d78164

Please sign in to comment.