diff --git a/src/main/java/ru/r2cloud/R2Cloud.java b/src/main/java/ru/r2cloud/R2Cloud.java index cae21948..5f6c2dfc 100644 --- a/src/main/java/ru/r2cloud/R2Cloud.java +++ b/src/main/java/ru/r2cloud/R2Cloud.java @@ -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; } } diff --git a/src/main/java/ru/r2cloud/lora/ModulationConfig.java b/src/main/java/ru/r2cloud/lora/ModulationConfig.java index 7c16cc45..06d7e5ac 100644 --- a/src/main/java/ru/r2cloud/lora/ModulationConfig.java +++ b/src/main/java/ru/r2cloud/lora/ModulationConfig.java @@ -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; @@ -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; } diff --git a/src/main/java/ru/r2cloud/lora/loraat/LoraAtSerialClient.java b/src/main/java/ru/r2cloud/lora/loraat/LoraAtSerialClient.java index 97d9867a..4d66c7b3 100644 --- a/src/main/java/ru/r2cloud/lora/loraat/LoraAtSerialClient.java +++ b/src/main/java/ru/r2cloud/lora/loraat/LoraAtSerialClient.java @@ -42,7 +42,7 @@ public LoraAtSerialClient(String portDescriptor, int timeout, SerialInterface se this.serial = serial; this.clock = clock; } - + @Override public boolean isSupported() { List response; @@ -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"); @@ -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); diff --git a/src/main/java/ru/r2cloud/lora/loraat/LoraAtSerialClient2.java b/src/main/java/ru/r2cloud/lora/loraat/LoraAtSerialClient2.java index c1a6d3e6..378af5bd 100644 --- a/src/main/java/ru/r2cloud/lora/loraat/LoraAtSerialClient2.java +++ b/src/main/java/ru/r2cloud/lora/loraat/LoraAtSerialClient2.java @@ -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 configs = new ArrayList<>(); configs.add(loraConfig); result.setStatus("IDLE"); diff --git a/src/main/java/ru/r2cloud/lora/r2lora/R2loraClient.java b/src/main/java/ru/r2cloud/lora/r2lora/R2loraClient.java index 1f4f1da8..38183a87 100644 --- a/src/main/java/ru/r2cloud/lora/r2lora/R2loraClient.java +++ b/src/main/java/ru/r2cloud/lora/r2lora/R2loraClient.java @@ -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; } diff --git a/src/test/java/ru/r2cloud/lora/loraat/LoraAtSerialClient2Test.java b/src/test/java/ru/r2cloud/lora/loraat/LoraAtSerialClient2Test.java index 2b7653a9..43bded60 100644 --- a/src/test/java/ru/r2cloud/lora/loraat/LoraAtSerialClient2Test.java +++ b/src/test/java/ru/r2cloud/lora/loraat/LoraAtSerialClient2Test.java @@ -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)); } diff --git a/src/test/java/ru/r2cloud/lora/loraat/LoraAtSerialClientTest.java b/src/test/java/ru/r2cloud/lora/loraat/LoraAtSerialClientTest.java index 852781cb..62f9c206 100644 --- a/src/test/java/ru/r2cloud/lora/loraat/LoraAtSerialClientTest.java +++ b/src/test/java/ru/r2cloud/lora/loraat/LoraAtSerialClientTest.java @@ -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 diff --git a/src/test/java/ru/r2cloud/lora/r2lora/R2loraClientTest.java b/src/test/java/ru/r2cloud/lora/r2lora/R2loraClientTest.java index c841a01a..a2da724e 100644 --- a/src/test/java/ru/r2cloud/lora/r2lora/R2loraClientTest.java +++ b/src/test/java/ru/r2cloud/lora/r2lora/R2loraClientTest.java @@ -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