Skip to content

Commit

Permalink
beautify discovery service
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanSST committed Jul 30, 2023
1 parent 3b90b15 commit 0263c12
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 16 deletions.
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,24 @@ This code will run on a Raspberry PI in a chicken barn. There are scales under t

### Epic v1: Chicken scale recognizes weight change and sends message about state (which chicken, an egg) via Whatsapp

* Story: (done) create Webservice GET base
* Story: (done) using Github Actions to automatic build and create an image
* Story: (done) install current Docker image on Raspberry PI and start it initially
* Story: (done) create structure with timer service pulling dummy scale service and show data via GET service
* Story: (done) give calibrate webservice operation for load cell
* Story: (done) create scale service that delivers current weight

* Story: change discovery webserivce to use DO instead of strings
* Story: write tests and mock for scale service
* Story: respect box/UID of load cell
* Story: Integration test with whole process

* Story: get current weight and calculate the "state" (chicken, egg)
* Story: Integration test with whole process
* Story: integrate Whatsapp and send messages
* Story: integrate Prometheus
* Story: manage chickens
* Story: read data from scale and show by webservice (GET)


* Story: (done) change discovery webservice to use DO instead of strings
* Story: (done) create scale service that delivers current weight
* Story: (done) give calibrate webservice operation for load cell
* Story: (done) create structure with timer service pulling dummy scale service and show data via GET service
* Story: (done) install current Docker image on Raspberry PI and start it initially
* Story: (done) using Github Actions to automatic build and create an image
* Story: (done) create Webservice GET base


### Epic v2: Recognize chicken
* Story: manage chickens
* Story: integrate Prometheus
2 changes: 1 addition & 1 deletion raspi/docker-chicken-farm.service
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ExecStart=/usr/bin/docker run -d --restart unless-stopped \
-p 8080:8080 --network="host" \
--name chicken-farm stephanst/chicken-farm:latest
ExecStop=/usr/bin/docker stop chicken-farm
TimeoutSec=120
TimeoutSec=300

[Install]
WantedBy=multi-user.target
4 changes: 2 additions & 2 deletions src/main/java/ch/stephan/chickenfarm/dto/Discovery.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package ch.stephan.chickenfarm.dto;

public record Discovery(String uid, String connectedUid, int position, String hardwareVersion, String firmwareVersion,
int deviceIdentifier, int enumerationType) {
public record Discovery(String uid, String parentUid, String position, String hardwareVersion, String firmwareVersion,
String deviceIdentifier, String enumerationType) {
}
30 changes: 28 additions & 2 deletions src/main/java/ch/stephan/chickenfarm/scale/ScaleService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.stereotype.Service;

import com.tinkerforge.AlreadyConnectedException;
import com.tinkerforge.BrickHAT;
import com.tinkerforge.BrickletLoadCellV2;
import com.tinkerforge.IPConnection;
import com.tinkerforge.NetworkException;
Expand Down Expand Up @@ -103,15 +104,40 @@ private final class EnumerateListenerImpl implements IPConnection.EnumerateListe
public void enumerate(String uid, String connectedUid, char position, short[] hardwareVersion,
short[] firmwareVersion, int deviceIdentifier, short enumerationType) {

Discovery discovery = new Discovery(uid, connectedUid, position, asString(hardwareVersion),
asString(firmwareVersion), deviceIdentifier, enumerationType);
Discovery discovery = new Discovery(uid, connectedUid, Character.toString(position),
asString(hardwareVersion), asString(firmwareVersion), deviceAsString(deviceIdentifier),
enumAsString(enumerationType));
discoveryResult.add(discovery);
}

private String asString(short[] version) {
return version[0] + "." + version[1] + "." + version[2];
}

private String enumAsString(short enumerationType) {
switch (enumerationType) {
case IPConnection.ENUMERATION_TYPE_AVAILABLE:
return "AVAILABLE";
case IPConnection.ENUMERATION_TYPE_CONNECTED:
return "CONNECTED";
case IPConnection.ENUMERATION_TYPE_DISCONNECTED:
return "DISCONNECTED";
default:
return "UNKNOWN";
}
}

private String deviceAsString(int deviceIdentifier) {
switch (deviceIdentifier) {
case BrickletLoadCellV2.DEVICE_IDENTIFIER:
return "Load Cell V2 Bricklet";
case BrickHAT.DEVICE_IDENTIFIER:
return "HAT Brick";
default:
return String.valueOf(deviceIdentifier);
}
}

}

}

0 comments on commit 0263c12

Please sign in to comment.