Initial commit

This commit is contained in:
2020-07-19 20:32:50 -04:00
commit 2bb5027d11
24 changed files with 677 additions and 0 deletions

84
.gitignore vendored Normal file
View File

@@ -0,0 +1,84 @@
##############################
## Java
##############################
.mtj.tmp/
*.class
*.jar
*.war
*.ear
*.nar
hs_err_pid*
##############################
## Maven
##############################
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
pom.xml.bak
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar
##############################
## Gradle
##############################
bin/
build/
.gradle
.gradletasknamecache
gradle-app.setting
!gradle-wrapper.jar
##############################
## IntelliJ
##############################
out/
#.idea/
#.idea_modules/
#*.iml
*.ipr
*.iws
##############################
## Eclipse
##############################
.settings/
bin/
tmp/
.metadata
.classpath
.project
*.tmp
*.bak
*.swp
*~.nib
local.properties
.loadpath
.factorypath
##############################
## NetBeans
##############################
nbproject/private/
build/
nbbuild/
dist/
nbdist/
nbactions.xml
nb-configuration.xml
##############################
## Visual Studio Code
##############################
.vscode/
.code-workspace
##############################
## OS X
##############################
.DS_Store

3
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

View File

@@ -0,0 +1,26 @@
<component name="ArtifactManager">
<artifact type="jar" name="BluetoothHRService:jar">
<output-path>$PROJECT_DIR$/out/artifacts/BluetoothHRService_jar</output-path>
<root id="archive" name="BluetoothHRService.jar">
<element id="module-output" name="BluetoothHRService" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/log4j/log4j/1.2.17/log4j-1.2.17.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/slf4j/slf4j-log4j12/1.7.30/slf4j-log4j12-1.7.30.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/1.7.30/slf4j-api-1.7.30.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/github/hypfvieh/bluez-dbus/0.1.1/bluez-dbus-0.1.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/github/hypfvieh/dbus-java/3.0.1/dbus-java-3.0.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/github/hypfvieh/java-utils/1.0.5/java-utils-1.0.5.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/ch/qos/logback/logback-core/1.2.3/logback-core-1.2.3.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/apache/commons/commons-lang3/3.8.1/commons-lang3-3.8.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/influxdb/influxdb-java/2.17/influxdb-java-2.17.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/squareup/retrofit2/retrofit/2.6.2/retrofit-2.6.2.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/squareup/retrofit2/converter-moshi/2.6.2/converter-moshi-2.6.2.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/squareup/moshi/moshi/1.8.0/moshi-1.8.0.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/msgpack/msgpack-core/0.8.18/msgpack-core-0.8.18.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/squareup/okhttp3/okhttp/3.14.4/okhttp-3.14.4.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/squareup/okio/okio/1.17.2/okio-1.17.2.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/squareup/okhttp3/logging-interceptor/3.14.4/logging-interceptor-3.14.4.jar" path-in-jar="/" />
</root>
</artifact>
</component>

16
.idea/compiler.xml generated Normal file
View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="BluetoothHRService" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
<module name="BluetoothHRService" target="1.8" />
</bytecodeTargetLevel>
</component>
</project>

1
.idea/description.html generated Normal file
View File

@@ -0,0 +1 @@
<html>Simple <b>Java</b> application that includes a class with <code>main()</code> method</html>

6
.idea/encodings.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>

20
.idea/jarRepositories.xml generated Normal file
View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>

View File

@@ -0,0 +1,16 @@
<component name="libraryTable">
<library name="com.github.hypfvieh:bluez-dbus:0.1.1" type="repository">
<properties maven-id="com.github.hypfvieh:bluez-dbus:0.1.1" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/github/hypfvieh/bluez-dbus/0.1.1/bluez-dbus-0.1.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/github/hypfvieh/dbus-java/3.0.1/dbus-java-3.0.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/github/hypfvieh/java-utils/1.0.5/java-utils-1.0.5.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/ch/qos/logback/logback-core/1.2.3/logback-core-1.2.3.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/apache/commons/commons-lang3/3.8.1/commons-lang3-3.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

10
.idea/libraries/log4j_log4j_1_2_17.xml generated Normal file
View File

@@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="log4j:log4j:1.2.17" type="repository">
<properties maven-id="log4j:log4j:1.2.17" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/log4j/log4j/1.2.17/log4j-1.2.17.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@@ -0,0 +1,17 @@
<component name="libraryTable">
<library name="org.influxdb:influxdb-java:2.17" type="repository">
<properties maven-id="org.influxdb:influxdb-java:2.17" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/influxdb/influxdb-java/2.17/influxdb-java-2.17.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/squareup/retrofit2/retrofit/2.6.2/retrofit-2.6.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/squareup/retrofit2/converter-moshi/2.6.2/converter-moshi-2.6.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/squareup/moshi/moshi/1.8.0/moshi-1.8.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/msgpack/msgpack-core/0.8.18/msgpack-core-0.8.18.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/squareup/okhttp3/okhttp/3.14.4/okhttp-3.14.4.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/squareup/okio/okio/1.17.2/okio-1.17.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/squareup/okhttp3/logging-interceptor/3.14.4/logging-interceptor-3.14.4.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@@ -0,0 +1,12 @@
<component name="libraryTable">
<library name="org.slf4j:slf4j-log4j12:1.7.30" type="repository">
<properties maven-id="org.slf4j:slf4j-log4j12:1.7.30" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-log4j12/1.7.30/slf4j-log4j12-1.7.30.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/1.7.30/slf4j-api-1.7.30.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/log4j/log4j/1.2.17/log4j-1.2.17.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

16
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectKey">
<option name="state" value="project://e2804f05-5315-4fc6-a121-c522a6c26470" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/BluetoothHRService.iml" filepath="$PROJECT_DIR$/BluetoothHRService.iml" />
</modules>
</component>
</project>

3
.idea/project-template.xml generated Normal file
View File

@@ -0,0 +1,3 @@
<template>
<input-field default="com.company">IJ_BASE_PACKAGE</input-field>
</template>

124
.idea/uiDesigner.xml generated Normal file
View File

@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

19
BluetoothHRService.iml Normal file
View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_11">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="org.slf4j:slf4j-log4j12:1.7.30" level="project" />
<orderEntry type="library" name="log4j:log4j:1.2.17" level="project" />
<orderEntry type="library" name="com.github.hypfvieh:bluez-dbus:0.1.1" level="project" />
<orderEntry type="library" name="org.influxdb:influxdb-java:2.17" level="project" />
</component>
</module>

4
config.properties Normal file
View File

@@ -0,0 +1,4 @@
InfluxDBURL=http://arrakis.chrispr.lan:8086
InfluxDBUsername=airreport
InfluxDBPassword=airreport
InfluxDBDatabase=heartrate

16
pom.xml Normal file
View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<groupId>com.chrispr</groupId>
<artifactId>BluetoothHRService</artifactId>
<version>1.0-SNAPSHOT</version>
</project>

View File

@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: com.chrispr.bluetooth.heartrate.Main

View File

@@ -0,0 +1,105 @@
package com.chrispr.bluetooth;
import com.chrispr.bluetooth.heartrate.Main;
import com.chrispr.utility.Event;
import com.github.hypfvieh.bluetooth.DeviceManager;
import com.github.hypfvieh.bluetooth.wrapper.BluetoothDevice;
import com.github.hypfvieh.bluetooth.wrapper.BluetoothGattCharacteristic;
import com.github.hypfvieh.bluetooth.wrapper.BluetoothGattService;
import org.bluez.exceptions.BluezFailedException;
import org.bluez.exceptions.BluezInProgressException;
import org.bluez.exceptions.BluezNotPermittedException;
import org.bluez.exceptions.BluezNotSupportedException;
import org.freedesktop.dbus.exceptions.DBusException;
import org.freedesktop.dbus.handlers.AbstractPropertiesChangedHandler;
import org.freedesktop.dbus.interfaces.Properties;
import org.freedesktop.dbus.types.Variant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
// This class helps implement bluetooth characteristic notification events by receiving them
// from the DBUS interface and parsing them for easier consumption
public class BluetoothNotificationSubscriber extends AbstractPropertiesChangedHandler {
private BluetoothDevice device;
private BluetoothGattService service;
private BluetoothGattCharacteristic characteristic;
private String CharacteristicUUID;
private String CharacteristicDBUSPath;
private List<IBluetoothCharacteristicNotification> handlers;
private Logger logger = LoggerFactory.getLogger(BluetoothNotificationSubscriber.class);
public BluetoothNotificationSubscriber(BluetoothDevice device, BluetoothGattService service, BluetoothGattCharacteristic characteristic) {
this.device = device;
this.service = service;
this.characteristic = characteristic;
this.CharacteristicUUID = characteristic.getUuid();
this.CharacteristicDBUSPath = characteristic.getDbusPath();
handlers = new ArrayList<IBluetoothCharacteristicNotification>();
registerPropertyChangedHandler();
SubscribeToCharacteristicNotifications();
}
public void addHandler(IBluetoothCharacteristicNotification handler) {
handlers.add(handler);
}
public void removeHandler(IBluetoothCharacteristicNotification handler) {
handlers.remove(handler);
}
//Assumes the DeviceManager has already been created
private void registerPropertyChangedHandler() {
DeviceManager manager = DeviceManager.getInstance();
try {
manager.registerPropertyHandler(this);
} catch (DBusException e) {
logger.error(e.toString());
}
}
private void SubscribeToCharacteristicNotifications() {
try {
characteristic.startNotify();
} catch (BluezFailedException e) {
logger.error(e.toString());
} catch (BluezInProgressException e) {
logger.error(e.toString());
} catch (BluezNotSupportedException e) {
logger.error(e.toString());
} catch (BluezNotPermittedException e) {
logger.error(e.toString());
}
}
@Override
public void handle(Properties.PropertiesChanged propertiesChanged) {
if (!propertiesChanged.getPath().equals(CharacteristicDBUSPath))
return;
Map<String, Variant<?>> propMap = propertiesChanged.getPropertiesChanged();
Iterator<Map.Entry<String, Variant<?>>> it = propMap.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, Variant<?>> entry = it.next();
Object object = entry.getValue().getValue();
logger.debug("[{}] {} -> {} uuid:{}", object.getClass().getName(), entry.getKey(), object, CharacteristicUUID);
if ((object == null) || !(object instanceof byte[])) {
continue;
}
byte[] data = (byte[]) object;
logger.debug("New characteristic received, calling handler");
for(IBluetoothCharacteristicNotification handler : handlers) {
handler.handleNewNotification(device, service, characteristic, data);
}
}
}
}

View File

@@ -0,0 +1,10 @@
package com.chrispr.bluetooth;
import com.github.hypfvieh.bluetooth.wrapper.BluetoothDevice;
import com.github.hypfvieh.bluetooth.wrapper.BluetoothGattCharacteristic;
import com.github.hypfvieh.bluetooth.wrapper.BluetoothGattService;
public interface IBluetoothCharacteristicNotification {
public void handleNewNotification(BluetoothDevice device, BluetoothGattService service, BluetoothGattCharacteristic characteristic, byte[] value);
}

View File

@@ -0,0 +1,134 @@
package com.chrispr.bluetooth.heartrate;
import com.chrispr.bluetooth.BluetoothNotificationSubscriber;
import com.chrispr.bluetooth.IBluetoothCharacteristicNotification;
import com.github.hypfvieh.bluetooth.DeviceManager;
import com.github.hypfvieh.bluetooth.wrapper.*;
import org.apache.log4j.BasicConfigurator;
import org.bluez.exceptions.BluezFailedException;
import org.bluez.exceptions.BluezInProgressException;
import org.bluez.exceptions.BluezNotPermittedException;
import org.bluez.exceptions.BluezNotSupportedException;
import org.freedesktop.dbus.exceptions.DBusException;
import org.influxdb.InfluxDB;
import org.influxdb.InfluxDBFactory;
import org.influxdb.dto.Point;
import org.influxdb.dto.Query;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.FileInputStream;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.TimeUnit;
public class Main {
public static Logger logger = LoggerFactory.getLogger(Main.class);
public static String HeartRateServiceUUID = "0000180d-0000-1000-8000-00805f9b34fb";
public static String HeartRateCharacteristicUUID = "00002a37-0000-1000-8000-00805f9b34fb";
public static InfluxDB DB;
private static LocalDateTime lastUpdate;
public static void main(String[] args) throws InterruptedException, IOException {
// Set up a simple configuration that logs on the console.
BasicConfigurator.configure();
logger.info("Heart Rate Monitor started");
DeviceManager manager;
try {
DeviceManager.createInstance(false);
manager =DeviceManager.getInstance();
} catch (DBusException e) {
logger.error(e.toString());
e.printStackTrace();
return;
}
//load settings
Properties props = new Properties();
FileInputStream in = new FileInputStream("config.properties");
props.load(in);
in.close();
DB = InfluxDBFactory.connect(props.getProperty("InfluxDBURL"), props.getProperty("InfluxDBUsername"), props.getProperty("InfluxDBPassword"));
DB.ping();
String databaseName = props.getProperty("InfluxDBDatabase");
DB.query(new Query("CREATE DATABASE " + databaseName));
DB.setDatabase(databaseName);
logger.debug("Scanning for HR monitor");
BluetoothDevice heartRateDevice;
while(true) {
List<BluetoothDevice> devices = manager.scanForBluetoothDevices(1000);
Optional<BluetoothDevice> device = devices.stream().filter(bt -> bt.getName().contains("TICKR")).findAny();
if(device.isPresent()) {
heartRateDevice = device.get();
break;
}
else
logger.debug("Device not found, scanning again..");
}
heartRateDevice.connect();
heartRateDevice.refreshGattServices();
while(!heartRateDevice.isServicesResolved())
Thread.sleep(100);
BluetoothGattService heartRateService = heartRateDevice.getGattServiceByUuid(HeartRateServiceUUID);
if(heartRateService == null) {
logger.error("The expected service was not found on the device");
return;
}
BluetoothGattCharacteristic heartRateCharacteristic = heartRateService.getGattCharacteristicByUuid(HeartRateCharacteristicUUID);
if(heartRateCharacteristic == null) {
logger.error("The expected characteristic was not found on the device");
return;
}
BluetoothNotificationSubscriber subscriber = new BluetoothNotificationSubscriber(heartRateDevice, heartRateService, heartRateCharacteristic);
subscriber.addHandler((device, service, characteristic, value) -> {
byte contactValue = value[0];
if(contactValue != 6 && contactValue != 22) {
logger.info("ignoring reading due to lack of skin contact");
return;
}
byte hrValue = value[1];
logger.info("Got good heart rate reading of {} bpm", (int)hrValue);
//attempt to log to InfluxDB
Point p = Point.measurement("rate")
.time(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
.addField("bpm", hrValue)
.build();
DB.write(p);
lastUpdate = LocalDateTime.now();
});
while(true){
if(heartRateDevice.isConnected()) {
if(lastUpdate != null && lastUpdate.plusMinutes(2).compareTo(java.time.LocalDateTime.now()) < 0) {
try {
heartRateCharacteristic.startNotify();
} catch (Exception e) {
e.printStackTrace();
}
}
Thread.sleep(10000);
}
else {
while (!heartRateDevice.isConnected()) {
try {
heartRateDevice.connect();
} catch (Exception ex) {
logger.debug(ex.toString());
}
Thread.sleep(10000);
}
try {
heartRateCharacteristic.startNotify();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}

View File

@@ -0,0 +1,18 @@
package com.chrispr.utility;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Consumer;
// Simple implementation of event handler / observable /etc
public class Event<T> {
private Set<Consumer<T>> listeners = new HashSet();
public void addListener(Consumer<T> listener) {
listeners.add(listener);
}
public void broadcast(T args) {
listeners.forEach(x -> x.accept(args));
}
}