Skip to content

Commit 2389d10

Browse files
author
davidgraeff
committed
Fix crashes in all outlets window, fix NFC, add not reachable hint
1 parent c769b79 commit 2389d10

38 files changed

+1204
-734
lines changed

.idea/workspace.xml

Lines changed: 453 additions & 331 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/app.iml

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
<component name="FacetManager">
44
<facet type="android" name="Android">
55
<configuration>
6-
<option name="SELECTED_BUILD_VARIANT" value="release" />
7-
<option name="ASSEMBLE_TASK_NAME" value="assembleRelease" />
8-
<option name="COMPILE_JAVA_TASK_NAME" value="compileReleaseJava" />
9-
<option name="SOURCE_GEN_TASK_NAME" value="generateReleaseSources" />
6+
<option name="SELECTED_BUILD_VARIANT" value="debug" />
7+
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
8+
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugJava" />
9+
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
10+
<option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
1011
<option name="ALLOW_USER_CONFIGURATION" value="false" />
1112
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
1213
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
@@ -21,21 +22,26 @@
2122
</facet>
2223
</component>
2324
<component name="NewModuleRootManager" inherit-compiler-output="false">
24-
<output url="file://$MODULE_DIR$/build/classes/release" />
25+
<output url="file://$MODULE_DIR$/build/classes/debug" />
2526
<exclude-output />
2627
<content url="file://$MODULE_DIR$">
27-
<sourceFolder url="file://$MODULE_DIR$/build/source/r/release" isTestSource="false" generated="true" />
28-
<sourceFolder url="file://$MODULE_DIR$/build/source/aidl/release" isTestSource="false" generated="true" />
29-
<sourceFolder url="file://$MODULE_DIR$/build/source/buildConfig/release" isTestSource="false" generated="true" />
30-
<sourceFolder url="file://$MODULE_DIR$/build/source/rs/release" isTestSource="false" generated="true" />
31-
<sourceFolder url="file://$MODULE_DIR$/build/res/rs/release" type="java-resource" />
32-
<sourceFolder url="file://$MODULE_DIR$/src/release/aidl" isTestSource="false" />
33-
<sourceFolder url="file://$MODULE_DIR$/src/release/assets" isTestSource="false" />
34-
<sourceFolder url="file://$MODULE_DIR$/src/release/java" isTestSource="false" />
35-
<sourceFolder url="file://$MODULE_DIR$/src/release/jni" isTestSource="false" />
36-
<sourceFolder url="file://$MODULE_DIR$/src/release/rs" isTestSource="false" />
37-
<sourceFolder url="file://$MODULE_DIR$/src/release/res" type="java-resource" />
38-
<sourceFolder url="file://$MODULE_DIR$/src/release/resources" type="java-resource" />
28+
<sourceFolder url="file://$MODULE_DIR$/build/source/r/debug" isTestSource="false" generated="true" />
29+
<sourceFolder url="file://$MODULE_DIR$/build/source/aidl/debug" isTestSource="false" generated="true" />
30+
<sourceFolder url="file://$MODULE_DIR$/build/source/buildConfig/debug" isTestSource="false" generated="true" />
31+
<sourceFolder url="file://$MODULE_DIR$/build/source/rs/debug" isTestSource="false" generated="true" />
32+
<sourceFolder url="file://$MODULE_DIR$/build/res/rs/debug" type="java-resource" />
33+
<sourceFolder url="file://$MODULE_DIR$/build/source/r/test/debug" isTestSource="true" />
34+
<sourceFolder url="file://$MODULE_DIR$/build/source/aidl/test/debug" isTestSource="true" />
35+
<sourceFolder url="file://$MODULE_DIR$/build/source/buildConfig/test/debug" isTestSource="true" />
36+
<sourceFolder url="file://$MODULE_DIR$/build/source/rs/test/debug" isTestSource="true" />
37+
<sourceFolder url="file://$MODULE_DIR$/build/res/rs/test/debug" type="java-test-resource" />
38+
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
39+
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" isTestSource="false" />
40+
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
41+
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
42+
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
43+
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
44+
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
3945
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
4046
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" isTestSource="false" />
4147
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />

app/src/main/AndroidManifest.xml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="oly.netpowerctrl"
4-
android:versionCode="10"
5-
android:versionName="1.5b">
4+
android:versionCode="12"
5+
android:versionName="1.7">
66

7-
<!-- Api level 16: Android 4.1 27. Juni 2012 -->
7+
<!-- Api level 16: Android 4.1 27. Juni 2012 -->
88
<uses-sdk
99
android:minSdkVersion="16"
1010
android:targetSdkVersion="17" />
1111

1212
<uses-permission android:name="android.permission.INTERNET" />
1313
<uses-permission android:name="android.permission.NFC" />
14-
<uses-permission android:name="android.launcher.permission.INSTALL_SHORTCUT" />
14+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
15+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
16+
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
17+
18+
<permission
19+
android:name="oly.netpowerctrl.plugins"
20+
android:label="@string/app_name"
21+
android:description="@string/app_name"
22+
android:protectionLevel="signature" />
1523

1624
<application
1725
android:name="oly.netpowerctrl.main.NetpowerctrlApplication"
@@ -22,12 +30,14 @@
2230
android:name="oly.netpowerctrl.main.NetpowerctrlActivity"
2331
android:label="@string/app_name"
2432
android:launchMode="singleTask"
25-
android:configChanges="keyboardHidden|orientation|screenSize"
2633
android:theme="@style/Theme.CustomLightTheme">
2734
<intent-filter>
2835
<action android:name="android.intent.action.MAIN" />
2936
<category android:name="android.intent.category.LAUNCHER" />
3037
</intent-filter>
38+
<intent-filter>
39+
<action android:name="android.intent.action.MAIN" />
40+
</intent-filter>
3141
<intent-filter>
3242
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
3343
<category android:name="android.intent.category.DEFAULT" />
@@ -84,10 +94,6 @@
8494
android:name="oly.netpowerctrl.anelservice.NetpowerctrlService"
8595
android:permission="android.permission.INTERNET" />
8696

87-
<service
88-
android:name="oly.netpowerctrl.test.TestService"
89-
android:permission="android.permission.INTERNET" />
90-
9197
<service android:name="oly.netpowerctrl.widget.WidgetUpdateService" />
9298
</application>
9399

app/src/main/java/oly/netpowerctrl/anelservice/DeviceQuery.java

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
import java.net.DatagramPacket;
77
import java.net.DatagramSocket;
88
import java.net.InetAddress;
9+
import java.util.ArrayList;
910
import java.util.Collection;
1011
import java.util.Iterator;
1112

1213
import oly.netpowerctrl.R;
14+
import oly.netpowerctrl.datastructure.DeviceCommand;
1315
import oly.netpowerctrl.datastructure.DeviceInfo;
1416
import oly.netpowerctrl.main.NetpowerctrlApplication;
1517
import oly.netpowerctrl.utils.ShowToast;
@@ -33,14 +35,35 @@ public void run() {
3335
}
3436
};
3537

36-
public DeviceQuery(Context context, DeviceUpdateStateOrTimeout target, Collection<DeviceInfo> devices_to_observe) {
38+
public DeviceQuery(Context context, DeviceUpdateStateOrTimeout target, DeviceInfo device_to_observe) {
3739
this.target = target;
38-
this.devices_to_observe = devices_to_observe;
40+
this.devices_to_observe = new ArrayList<DeviceInfo>();
41+
devices_to_observe.add(device_to_observe);
42+
43+
// Register on main application object to receive device updates
44+
NetpowerctrlApplication.instance.addUpdateDeviceState(this);
45+
46+
timeoutHandler.postDelayed(timeoutRunnable, 1200);
47+
// Send out broadcast
48+
sendQuery(context, device_to_observe.HostName, device_to_observe.SendPort);
49+
}
50+
51+
public DeviceQuery(Context context, DeviceUpdateStateOrTimeout target,
52+
Collection<DeviceInfo> devices_to_observe, boolean queryForNewDevices) {
53+
this.target = target;
54+
this.devices_to_observe = new ArrayList<DeviceInfo>(devices_to_observe);
55+
56+
// Register on main application object to receive device updates
57+
NetpowerctrlApplication.instance.addUpdateDeviceState(this);
3958

4059
timeoutHandler.postDelayed(timeoutRunnable, 1200);
60+
4161
// Send out broadcast
42-
for (DeviceInfo di : devices_to_observe)
43-
sendQuery(context, di.HostName, di.SendPort);
62+
if (queryForNewDevices)
63+
sendBroadcastQuery(context);
64+
else
65+
for (DeviceInfo di : devices_to_observe)
66+
sendQuery(context, di.HostName, di.SendPort);
4467
}
4568

4669
public void notifyAndRemove(DeviceInfo received_data) {
@@ -59,10 +82,22 @@ public void notifyAndRemove(DeviceInfo received_data) {
5982
}
6083

6184
private void freeSelf() {
85+
target.onDeviceQueryFinished(devices_to_observe.size());
6286
NetpowerctrlApplication.instance.removeUpdateDeviceState(this);
6387
}
6488

65-
public static void sendQuery(final Context context, final String hostname, final int port) {
89+
/**
90+
* Used to be used only from the DeviceSend class for requesting an update
91+
* after a command has been send
92+
*
93+
* @param context
94+
* @param device_command
95+
*/
96+
static void sendQuery(final Context context, DeviceCommand device_command) {
97+
sendQuery(context, device_command.dest.getHostAddress(), device_command.port);
98+
}
99+
100+
private static void sendQuery(final Context context, final String hostname, final int port) {
66101
new Thread(new Runnable() {
67102
public void run() {
68103
try {
@@ -82,7 +117,7 @@ public void run() {
82117
}).start();
83118
}
84119

85-
public static void sendBroadcastQuery(final Context context) {
120+
private static void sendBroadcastQuery(final Context context) {
86121
for (int port : NetpowerctrlApplication.instance.getAllSendPorts())
87122
sendQuery(context, "255.255.255.255", port);
88123
}

app/src/main/java/oly/netpowerctrl/anelservice/DeviceSend.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ public class DeviceSend {
1818
/**
1919
* Bulk version of sendOutlet. Send changes for each device in only one packet per device.
2020
*
21-
* @param context The context of the activity for showing toast messages and
22-
* getResources
23-
* @param device_commands Bulk command per device
21+
* @param context The context of the activity for showing toast messages and
22+
* getResources
23+
* @param device_commands Bulk command per device
2424
*/
2525
static public void sendOutlet(final Context context, final Collection<DeviceCommand> device_commands, final boolean requestNewValuesAfterSend) {
2626
// udp sending in own thread
@@ -44,7 +44,7 @@ public void run() {
4444
// request new values from each device
4545

4646
for (DeviceCommand device_command : device_commands) {
47-
DeviceQuery.sendQuery(context, device_command.dest.getHostAddress(), device_command.port);
47+
DeviceQuery.sendQuery(context, device_command);
4848
}
4949
}
5050

@@ -79,7 +79,7 @@ public void run() {
7979
}
8080

8181
// request new values
82-
DeviceQuery.sendQuery(context, device.dest.getHostAddress(), device.port);
82+
DeviceQuery.sendQuery(context, device);
8383
}
8484
} catch (final IOException e) {
8585
ShowToast.FromOtherThread(context, context.getResources().getString(R.string.error_sending_inquiry) + ": "

app/src/main/java/oly/netpowerctrl/anelservice/DeviceUpdateStateOrTimeout.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ public interface DeviceUpdateStateOrTimeout {
99
void onDeviceTimeout(DeviceInfo di);
1010

1111
void onDeviceUpdated(DeviceInfo di);
12+
13+
void onDeviceQueryFinished(int timeout_devices);
1214
}

app/src/main/java/oly/netpowerctrl/anelservice/DiscoveryThread.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,42 @@ void parsePacket(final String message, int receive_port) {
7777
int disabledOutlets = 0;
7878
int numOutlets = 8; // normally, the device sends info for 8 outlets no matter how many are actually equipped
7979

80-
if (msg.length > 14)
80+
// Current firmware v4
81+
if (msg.length > 14) {
8182
try {
8283
disabledOutlets = Integer.parseInt(msg[14]);
8384
} catch (NumberFormatException ignored) {
8485
}
86+
try {
87+
di.HttpPort = Integer.parseInt(msg[15]);
88+
} catch (NumberFormatException ignored) {
89+
di.HttpPort = 80;
90+
}
91+
// IO ports
92+
if (msg.length > 23) {
93+
for (int i = 16; i <= 23; ++i) {
94+
String io_port[] = msg[i].split(",");
95+
if (io_port.length != 3) continue;
96+
// Filter out inputs
97+
if (io_port[1].equals("1"))
98+
continue;
99+
100+
OutletInfo oi = new OutletInfo(di);
101+
oi.OutletNumber = i - 16 + 1; // 1-based
102+
oi.setDescriptionByDevice(io_port[0]);
103+
oi.State = io_port[1].equals("1");
104+
di.IOs.add(oi);
105+
}
106+
di.Temperature = msg[24];
107+
di.FirmwareVersion = msg[25];
108+
}
85109

86-
if (msg.length < 14)
110+
}
111+
// For old firmwares
112+
else if (msg.length < 14) {
87113
numOutlets = msg.length - 6;
114+
di.HttpPort = 80;
115+
}
88116

89117
for (int i = 0; i < numOutlets; i++) {
90118
String outlet[] = msg[6 + i].split(",");

app/src/main/java/oly/netpowerctrl/anelservice/NetpowerctrlService.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import java.util.ArrayList;
1010
import java.util.List;
11+
import java.util.Set;
1112

1213
import oly.netpowerctrl.datastructure.DeviceInfo;
1314
import oly.netpowerctrl.main.NetpowerctrlApplication;
@@ -19,6 +20,8 @@ public class NetpowerctrlService extends Service {
1920
private ArrayList<DeviceUpdate> observer = new ArrayList<DeviceUpdate>();
2021
private ArrayList<DeviceError> errorObserver = new ArrayList<DeviceError>();
2122

23+
private DeviceInfo temporary_device = null;
24+
2225
public void registerDeviceUpdateObserver(DeviceUpdate o) {
2326
if (!observer.contains(o))
2427
observer.add(o);
@@ -69,6 +72,15 @@ public void run() {
6972
});
7073
}
7174

75+
public void removeTemporaryDevice(DeviceInfo device) {
76+
if (temporary_device == device)
77+
temporary_device = null;
78+
}
79+
80+
public void replaceTemporaryDevice(DeviceInfo device) {
81+
temporary_device = device;
82+
}
83+
7284
public class LocalBinder extends Binder {
7385
public NetpowerctrlService getService() {
7486
// Return this instance of LocalService so clients can call public methods
@@ -92,7 +104,11 @@ public boolean onUnbind(Intent intent) {
92104
private void startDiscoveryThreads() {
93105
// only start if not yet running
94106
if (discoveryThreads.size() == 0) {
95-
for (int port : NetpowerctrlApplication.instance.getAllReceivePorts()) {
107+
Set<Integer> ports = NetpowerctrlApplication.instance.getAllReceivePorts();
108+
if (temporary_device != null)
109+
ports.add(temporary_device.ReceivePort);
110+
111+
for (int port : ports) {
96112
DiscoveryThread thr = new DiscoveryThread(port, this);
97113
thr.start();
98114
discoveryThreads.add(thr);

app/src/main/java/oly/netpowerctrl/datastructure/DeviceCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public byte getSwitchByte() {
6868

6969
static public Collection<DeviceCommand> fromOutletCommandGroup(Scene og) {
7070
TreeMap<String, DeviceCommand> deviceCommands = new TreeMap<String, DeviceCommand>();
71-
for (SceneOutlet c : og.commands) {
71+
for (SceneOutlet c : og.sceneOutlets) {
7272
if (!deviceCommands.containsKey(c.device_mac)) {
7373
deviceCommands.put(c.device_mac, new DeviceCommand(c.outletinfo.device));
7474
}

0 commit comments

Comments
 (0)