v0.0.6
This commit is contained in:
parent
a784bd6549
commit
26d3fce10a
1 changed files with 39 additions and 7 deletions
|
|
@ -23,6 +23,7 @@ import java.time.Duration;
|
|||
public class WaterLevelService extends Service {
|
||||
|
||||
private static float alert_thres_distance = 1000000;
|
||||
private boolean bits_flipped = false;
|
||||
|
||||
public class UDPCommandClient implements Runnable {
|
||||
private DatagramSocket socket_cmd_recv;
|
||||
|
|
@ -40,13 +41,25 @@ public class WaterLevelService extends Service {
|
|||
DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
|
||||
socket_cmd_recv.receive(packet);
|
||||
String str = new String(buffer, StandardCharsets.UTF_8);
|
||||
Log.d("UDP Service ", "Received command packet " + str);
|
||||
if(str.startsWith("<SET NAME=ALERT VALUE=")) {
|
||||
str = str.replace("<SET NAME=ALERT VALUE=", "");
|
||||
str = str.replace("=", "");
|
||||
str = str.replace(">", "");
|
||||
alert_thres_distance = Float.parseFloat(str);
|
||||
}
|
||||
Log.d("UDP Service ", "Received command packet " + str);
|
||||
else if(str.startsWith("<SET NAME=BITS_FLIPPED VALUE=")) {
|
||||
str = str.replace("<SET NAME=BITS_FLIPPED VALUE=", "");
|
||||
str = str.replace("=", "");
|
||||
str = str.replace(">", "");
|
||||
Log.d("UDP Service ", "Flipping " + str);
|
||||
if(str.toLowerCase() == "false") {
|
||||
bits_flipped = false;
|
||||
}
|
||||
else if(str.toLowerCase() == "true") {
|
||||
bits_flipped = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -105,7 +118,13 @@ public class WaterLevelService extends Service {
|
|||
} catch(java.net.SocketTimeoutException e) {
|
||||
continue;
|
||||
}
|
||||
float f = ByteBuffer.wrap(buffer).order(ByteOrder.LITTLE_ENDIAN).getFloat();
|
||||
float f;
|
||||
if(bits_flipped) {
|
||||
f = ByteBuffer.wrap(buffer).order(ByteOrder.LITTLE_ENDIAN).getFloat();
|
||||
}
|
||||
else {
|
||||
f = ByteBuffer.wrap(buffer).order(ByteOrder.BIG_ENDIAN).getFloat();
|
||||
}
|
||||
Log.d("UDP Service ", "Received packet: " + f);
|
||||
Log.d("UDP Service ", "Threshold is: " + alert_thres_distance);
|
||||
boolean duration_passed = false;
|
||||
|
|
|
|||
Loading…
Reference in a new issue