v0.0.6
This commit is contained in:
parent
a784bd6549
commit
26d3fce10a
3 changed files with 39 additions and 7 deletions
4
Main.qml
4
Main.qml
|
|
@ -554,7 +554,9 @@ Window {
|
||||||
else {
|
else {
|
||||||
water_level.color = root.water_color;
|
water_level.color = root.water_color;
|
||||||
}
|
}
|
||||||
|
if(root.distance_count > 1000) {
|
||||||
|
root.distance_count = 5;
|
||||||
|
}
|
||||||
console.log("Current reading is: " + current_reading)
|
console.log("Current reading is: " + current_reading)
|
||||||
console.log("Normalized height is: " + normalized_height)
|
console.log("Normalized height is: " + normalized_height)
|
||||||
water_level.current_level = normalized_height;
|
water_level.current_level = normalized_height;
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import java.time.Duration;
|
||||||
public class WaterLevelService extends Service {
|
public class WaterLevelService extends Service {
|
||||||
|
|
||||||
private static float alert_thres_distance = 1000000;
|
private static float alert_thres_distance = 1000000;
|
||||||
|
private boolean bits_flipped = false;
|
||||||
|
|
||||||
public class UDPCommandClient implements Runnable {
|
public class UDPCommandClient implements Runnable {
|
||||||
private DatagramSocket socket_cmd_recv;
|
private DatagramSocket socket_cmd_recv;
|
||||||
|
|
@ -40,13 +41,25 @@ public class WaterLevelService extends Service {
|
||||||
DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
|
DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
|
||||||
socket_cmd_recv.receive(packet);
|
socket_cmd_recv.receive(packet);
|
||||||
String str = new String(buffer, StandardCharsets.UTF_8);
|
String str = new String(buffer, StandardCharsets.UTF_8);
|
||||||
|
Log.d("UDP Service ", "Received command packet " + str);
|
||||||
if(str.startsWith("<SET NAME=ALERT VALUE=")) {
|
if(str.startsWith("<SET NAME=ALERT VALUE=")) {
|
||||||
str = str.replace("<SET NAME=ALERT VALUE=", "");
|
str = str.replace("<SET NAME=ALERT VALUE=", "");
|
||||||
str = str.replace("=", "");
|
str = str.replace("=", "");
|
||||||
str = str.replace(">", "");
|
str = str.replace(">", "");
|
||||||
alert_thres_distance = Float.parseFloat(str);
|
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) {
|
} catch(java.net.SocketTimeoutException e) {
|
||||||
continue;
|
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 ", "Received packet: " + f);
|
||||||
Log.d("UDP Service ", "Threshold is: " + alert_thres_distance);
|
Log.d("UDP Service ", "Threshold is: " + alert_thres_distance);
|
||||||
boolean duration_passed = false;
|
boolean duration_passed = false;
|
||||||
|
|
|
||||||
|
|
@ -61,16 +61,27 @@ void UDPListener::setConfig(float distance, bool flip_bits)
|
||||||
command_socket = new QUdpSocket(this);
|
command_socket = new QUdpSocket(this);
|
||||||
bool bind = command_socket->bind(8181);
|
bool bind = command_socket->bind(8181);
|
||||||
if(bind) {
|
if(bind) {
|
||||||
QNetworkDatagram data;
|
QNetworkDatagram data1, data2;
|
||||||
data.setDestination(QHostAddress::LocalHost, 8178);
|
data1.setDestination(QHostAddress::LocalHost, 8178);
|
||||||
|
data2.setDestination(QHostAddress::LocalHost, 8178);
|
||||||
|
|
||||||
QString s_data = "<SET NAME=ALERT VALUE=" + QString::number(distance) + ">";
|
QString s_data = "<SET NAME=ALERT VALUE=" + QString::number(distance) + ">";
|
||||||
while(s_data.toUtf8().size() != 1024) {
|
while(s_data.toUtf8().size() != 1024) {
|
||||||
s_data += "=";
|
s_data += "=";
|
||||||
}
|
}
|
||||||
data.setData(s_data.toUtf8());
|
data1.setData(s_data.toUtf8());
|
||||||
command_socket->writeDatagram(data);
|
command_socket->writeDatagram(data1);
|
||||||
|
command_socket->flush();
|
||||||
|
QString b_data = "<SET NAME=BITS_FLIPPED VALUE=" + QString((flip_bits ? "TRUE" : "FALSE")) + ">";
|
||||||
|
while(b_data.toUtf8().size() != 1024) {
|
||||||
|
b_data += "=";
|
||||||
|
}
|
||||||
|
data2.setData(b_data.toUtf8());
|
||||||
|
command_socket->writeDatagram(data2);
|
||||||
command_socket->flush();
|
command_socket->flush();
|
||||||
command_socket->close();
|
command_socket->close();
|
||||||
|
command_socket->deleteLater();
|
||||||
|
command_socket = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
averages.clear();
|
averages.clear();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue