forked from powerapi-ng/powerapi-scala
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: implement the PowerSPY module
- Loading branch information
Showing
25 changed files
with
1,431 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/org/powerapi/module/powerspy/BluetoothDevice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* This software is licensed under the GNU Affero General Public License, quoted below. | ||
* | ||
* This file is a part of PowerAPI. | ||
* | ||
* Copyright (C) 2011-2014 Inria, University of Lille 1. | ||
* | ||
* PowerAPI is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* PowerAPI is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with PowerAPI. | ||
* | ||
* If not, please consult http://www.gnu.org/licenses/agpl-3.0.html. | ||
*/ | ||
package org.powerapi.module.powerspy; | ||
|
||
import java.io.Closeable; | ||
|
||
public interface BluetoothDevice extends Closeable { | ||
public void send(String message); | ||
public String recv(long timeout, boolean errorOnTimeout); | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/org/powerapi/module/powerspy/IEEE754Utils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* This software is licensed under the GNU Affero General Public License, quoted below. | ||
* | ||
* This file is a part of PowerAPI. | ||
* | ||
* Copyright (C) 2011-2014 Inria, University of Lille 1. | ||
* | ||
* PowerAPI is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* PowerAPI is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with PowerAPI. | ||
* | ||
* If not, please consult http://www.gnu.org/licenses/agpl-3.0.html. | ||
*/ | ||
package org.powerapi.module.powerspy; | ||
|
||
import java.nio.ByteOrder; | ||
|
||
public class IEEE754Utils { | ||
public static Float fromString(String bits) throws NumberFormatException { | ||
if (ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN)) { | ||
char[] bitsCharArray = bits.toCharArray(); | ||
|
||
for (int i = 0; i < bitsCharArray.length / 2; i += 2) { | ||
char first = bitsCharArray[i]; | ||
char second = bitsCharArray[i + 1]; | ||
bitsCharArray[i] = bitsCharArray[bitsCharArray.length - i - 2]; | ||
bitsCharArray[i + 1] = bitsCharArray[bitsCharArray.length - i - 1]; | ||
bitsCharArray[bitsCharArray.length - i - 2] = first; | ||
bitsCharArray[bitsCharArray.length - i - 1] = second; | ||
} | ||
|
||
bits = String.valueOf(bitsCharArray); | ||
} | ||
|
||
return Float.intBitsToFloat(Integer.valueOf(bits, 16)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* This software is licensed under the GNU Affero General Public License, quoted below. | ||
* | ||
* This file is a part of PowerAPI. | ||
* | ||
* Copyright (C) 2011-2014 Inria, University of Lille 1. | ||
* | ||
* PowerAPI is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* PowerAPI is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with PowerAPI. | ||
* | ||
* If not, please consult http://www.gnu.org/licenses/agpl-3.0.html. | ||
*/ | ||
package org.powerapi.module.powerspy; | ||
|
||
public interface PowerSpy extends BluetoothDevice, PowerSpyListenable { | ||
static final long DEFAULT_TIMEOUT = 3000; | ||
|
||
void startPowerMonitoring(); | ||
void stopPowerMonitoring(); | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/org/powerapi/module/powerspy/PowerSpyEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* This software is licensed under the GNU Affero General Public License, quoted below. | ||
* | ||
* This file is a part of PowerAPI. | ||
* | ||
* Copyright (C) 2011-2014 Inria, University of Lille 1. | ||
* | ||
* PowerAPI is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* PowerAPI is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with PowerAPI. | ||
* | ||
* If not, please consult http://www.gnu.org/licenses/agpl-3.0.html. | ||
*/ | ||
package org.powerapi.module.powerspy; | ||
|
||
public class PowerSpyEvent { | ||
private final Double currentRMS; | ||
private final Float uScale; | ||
private final Float iScale; | ||
|
||
public PowerSpyEvent(Double currentRMS, Float uScale, Float iScale) { | ||
this.currentRMS = currentRMS; | ||
this.uScale = uScale; | ||
this.iScale = iScale; | ||
} | ||
|
||
public Double getCurrentRMS() { | ||
return currentRMS; | ||
} | ||
|
||
public Float getUScale() { | ||
return uScale; | ||
} | ||
|
||
public Float getIScale() { | ||
return iScale; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/org/powerapi/module/powerspy/PowerSpyListenable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* This software is licensed under the GNU Affero General Public License, quoted below. | ||
* | ||
* This file is a part of PowerAPI. | ||
* | ||
* Copyright (C) 2011-2014 Inria, University of Lille 1. | ||
* | ||
* PowerAPI is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* PowerAPI is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with PowerAPI. | ||
* | ||
* If not, please consult http://www.gnu.org/licenses/agpl-3.0.html. | ||
*/ | ||
package org.powerapi.module.powerspy; | ||
|
||
public interface PowerSpyListenable { | ||
void addPowerSpyListener(PowerSpyListener listener); | ||
void removePowerSpyListener(PowerSpyListener listener); | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/org/powerapi/module/powerspy/PowerSpyListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* This software is licensed under the GNU Affero General Public License, quoted below. | ||
* | ||
* This file is a part of PowerAPI. | ||
* | ||
* Copyright (C) 2011-2014 Inria, University of Lille 1. | ||
* | ||
* PowerAPI is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* PowerAPI is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with PowerAPI. | ||
* | ||
* If not, please consult http://www.gnu.org/licenses/agpl-3.0.html. | ||
*/ | ||
package org.powerapi.module.powerspy; | ||
|
||
public interface PowerSpyListener { | ||
void dataUpdated(PowerSpyEvent event); | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/org/powerapi/module/powerspy/PowerSpyVersion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* This software is licensed under the GNU Affero General Public License, quoted below. | ||
* | ||
* This file is a part of PowerAPI. | ||
* | ||
* Copyright (C) 2011-2014 Inria, University of Lille 1. | ||
* | ||
* PowerAPI is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* PowerAPI is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with PowerAPI. | ||
* | ||
* If not, please consult http://www.gnu.org/licenses/agpl-3.0.html. | ||
*/ | ||
package org.powerapi.module.powerspy; | ||
|
||
public enum PowerSpyVersion { | ||
POWERSPY_V1, | ||
POWERSPY_V2 | ||
} |
Oops, something went wrong.