├── .gitignore
├── .idea
├── .name
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── HelloWear.iml
├── MultiSensorCollecterServerDemo
├── .classpath
├── .gitignore
├── .project
├── .settings
│ └── org.eclipse.jdt.core.prefs
├── README.md
├── libs
│ └── spacesync.jar
└── src
│ └── com
│ └── leocai
│ └── multisensorcollector
│ └── serverdemo
│ └── SensorCollectorServerDemo.java
├── README.md
├── SensorCollector.iml
├── build.gradle
├── detection_unused
├── .gitignore
├── build.gradle
├── detection_unused.iml
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── leocai
│ │ └── detecdtion
│ │ ├── ApplicationTest.java
│ │ └── core
│ │ ├── KeyExtractorTest.java
│ │ ├── MasterTest.java
│ │ └── RandomnessExtractorTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── assets
│ ├── Master.csv
│ ├── MasterShakingDatas
│ ├── Slave.csv
│ └── SlaveShakingDatas
│ ├── java
│ └── com
│ │ └── leocai
│ │ └── detecdtion
│ │ ├── AuthenticationState.java
│ │ ├── DataTransformation.java
│ │ ├── MySensorListener.java
│ │ ├── ParameterLearning.java
│ │ ├── Reconcilation.java
│ │ ├── SensorDataWithIndex.java
│ │ ├── ShakeBufferView.java
│ │ ├── ShakeDetectorOld.java
│ │ ├── blebrodcast
│ │ ├── BleAdvertise.java
│ │ ├── BleBrodcastActivity.java
│ │ ├── BleDiscover.java
│ │ ├── CrossLevelUtils.java
│ │ ├── MixedSensorData.java
│ │ └── ShakeParameters.java
│ │ ├── core
│ │ ├── AccecptedCallBack.java
│ │ ├── ConnectedCallBack.java
│ │ ├── CoreMainActivity.java
│ │ ├── ExcurtionsWithIndexes.java
│ │ ├── KeyExtractor.java
│ │ ├── KeyExtractorActivity.java
│ │ ├── Master.java
│ │ ├── PermutationKeyGenerator.java
│ │ ├── RandomnessExtractor.java
│ │ ├── ReconcilationEndCallBack.java
│ │ ├── ShakeBits.java
│ │ ├── ShakeDatasStore.java
│ │ ├── ShakeKey.java
│ │ ├── ShakingDataGetterCallback.java
│ │ ├── Slave.java
│ │ ├── WearDataGetter.java
│ │ ├── WearDataGetterActivity.java
│ │ └── test
│ │ │ ├── TestBleActivity.java
│ │ │ ├── TestDetectionActivity.java
│ │ │ ├── TestMsgTransferActivity.java
│ │ │ └── TestReconcilationActivity.java
│ │ ├── transformation
│ │ ├── MatrixRotate.java
│ │ ├── MatrixUpdate.java
│ │ └── MatrixUtils.java
│ │ └── utils
│ │ ├── BytesUtils.java
│ │ └── MathUtils.java
│ └── res
│ ├── layout
│ ├── activity_ble_brodcast.xml
│ ├── activity_core_main.xml
│ ├── activity_main.xml
│ ├── activity_test_ble.xml
│ └── activity_test_core.xml
│ ├── menu
│ ├── menu_ble_brodcast.xml
│ ├── menu_core_main.xml
│ ├── menu_main.xml
│ ├── menu_test_ble.xml
│ └── menu_test_core.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── drafts.zip
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── imgs
├── device-2017-01-02-111908.png
├── s1.png
├── s2.png
├── s3.png
├── s4.png
├── s5.png
├── s6.png
└── s7.png
├── multi_sensor_collector
├── .gitignore
├── build.gradle
├── libs
│ ├── accessory-v2.3.0.jar
│ └── sdk-v1.0.0.jar
├── multi_sensor_collector.iml
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── leocai
│ │ └── multidevicesalign
│ │ └── ApplicationTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── leocai
│ │ └── multidevicesalign
│ │ ├── AccessoryConsumer.java
│ │ ├── BleSyncActivity.java
│ │ ├── BleSyncActivitySamsung.java
│ │ ├── CollectorConfig.java
│ │ ├── ConsumerService.java
│ │ ├── MagTestActivity.java
│ │ ├── MainActivity.java
│ │ ├── ShakeBufferView.java
│ │ ├── SimpleDataActivity.java
│ │ └── SimpleDataActivity2.java
│ └── res
│ ├── layout
│ ├── activity_ble_sync.xml
│ ├── activity_gps.xml
│ ├── activity_mag_test.xml
│ ├── activity_main.xml
│ ├── activity_simple_data.xml
│ ├── content_gps.xml
│ ├── content_mag_test.xml
│ ├── content_simple_collection.xml
│ └── content_simple_data.xml
│ ├── menu
│ ├── menu_ble_sync.xml
│ └── menu_main.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── values-v21
│ └── styles.xml
│ ├── values-w820dp
│ └── dimens.xml
│ ├── values
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
│ └── xml
│ └── accessoryservices.xml
├── publiclibs
├── .gitignore
├── build.gradle
├── libs
│ └── spacesync.jar
├── proguard-rules.pro
├── publiclibs.iml
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── leocai
│ │ └── publiclibs
│ │ └── ApplicationTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── leocai
│ │ └── publiclibs
│ │ ├── BleConnection.java
│ │ ├── ConnectedCallBack.java
│ │ ├── PublicConstants.java
│ │ ├── ShakeDetector.java
│ │ ├── ShakeDetectorNew.java
│ │ ├── ShakingData.java
│ │ ├── connection
│ │ ├── BleServer.java
│ │ └── DealWithSample.java
│ │ ├── multidecicealign
│ │ ├── BleClient.java
│ │ ├── FileInitCallBack.java
│ │ ├── MySensorManager.java
│ │ ├── SensorDataWriter.java
│ │ ├── SensorGlobalWriter.java
│ │ ├── SensorSokectWriter.java
│ │ ├── StartCallBack.java
│ │ └── StopCallBack.java
│ │ └── utils
│ │ ├── RollApply.java
│ │ ├── RollApplyFunMean.java
│ │ ├── RollApplyFunc.java
│ │ └── SensorData.java
│ └── res
│ └── values
│ └── strings.xml
├── settings.gradle
├── test
├── unsued1
├── .gitignore
├── build.gradle
├── proguard-rules.pro
├── src
│ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── leocai
│ │ │ └── hellowear
│ │ │ └── ApplicationTest.java
│ └── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ └── com
│ │ │ └── leocai
│ │ │ └── hellowear
│ │ │ ├── BluetoothChatService.java
│ │ │ ├── Constants.java
│ │ │ └── MainActivity.java
│ │ └── res
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── menu
│ │ └── menu_main.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
└── unsued1.iml
├── wear_depracated
├── .gitignore
├── build.gradle
├── proguard-rules.pro
├── src
│ └── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ └── com
│ │ │ └── leocai
│ │ │ └── hellowear
│ │ │ ├── BleActivity.java
│ │ │ ├── BleFileTransfer.java
│ │ │ ├── BluetoothChatService.java
│ │ │ ├── Constants.java
│ │ │ ├── MainActivity.java
│ │ │ ├── ShakeBuffer.java
│ │ │ ├── ShakeDetectorw.java
│ │ │ ├── ShakingDataWear.java
│ │ │ ├── WearActivity.java
│ │ │ ├── WearSensorListener.java
│ │ │ └── utils
│ │ │ ├── ApplyFuncMean.java
│ │ │ ├── ApplyFuncPeak.java
│ │ │ ├── ApplyFuncPeak2.java
│ │ │ ├── RollApply.java
│ │ │ └── RollApplyFunc.java
│ │ └── res
│ │ ├── layout
│ │ ├── activity_ble.xml
│ │ ├── activity_main.xml
│ │ ├── activity_wear.xml
│ │ ├── rect_activity_ble.xml
│ │ ├── rect_activity_main.xml
│ │ ├── round_activity_ble.xml
│ │ └── round_activity_main.xml
│ │ ├── menu
│ │ └── menu_wear.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── attrs_shake_buffer.xml
│ │ ├── dimens.xml
│ │ └── strings.xml
└── wear_depracated.iml
├── weardata_collector
├── .gitignore
├── build.gradle
├── proguard-rules.pro
├── src
│ └── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ └── com
│ │ │ └── leocai
│ │ │ └── weardata
│ │ │ ├── Main2Activity.java
│ │ │ └── MainActivity.java
│ │ └── res
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ ├── activity_main2.xml
│ │ ├── rect_activity_main2.xml
│ │ └── round_activity_main2.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ └── values
│ │ └── strings.xml
└── weardata_collector.iml
└── weardata_depracated
└── weardata_depracated.iml
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea/workspace.xml
4 | /.idea/libraries
5 | .DS_Store
6 | /build
7 | /captures
8 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | SensorCollector
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
22 |
23 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/HelloWear.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/MultiSensorCollecterServerDemo/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/MultiSensorCollecterServerDemo/.gitignore:
--------------------------------------------------------------------------------
1 | /bin/
2 |
--------------------------------------------------------------------------------
/MultiSensorCollecterServerDemo/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | MultiSensorCollecterServerDemo
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/MultiSensorCollecterServerDemo/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=1.7
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11 | org.eclipse.jdt.core.compiler.source=1.7
12 |
--------------------------------------------------------------------------------
/MultiSensorCollecterServerDemo/README.md:
--------------------------------------------------------------------------------
1 | # 多传感器收集程序服务端
2 |
3 | 手机端安装:[Multi-Sensor-DataCollector](https://github.com/LeoCai/Multi-Sensor-DataCollector)中的Multi-Sensor-DataCollector
4 | 安卓子项目
5 |
6 | writecsv必须unchecked(默认是checked)
7 |
8 | ## 简介
9 | 1. 手机控制端用蓝牙监听
10 | 2. pc服务端用socket开始监听
11 | 3. 手机采集端用蓝牙连接手机控制端(输入控制端蓝牙地址)
12 | 4. 手机控制端输入pc端ip地址,控制手机采集端socket连接pc服务端
13 | 5. pc服务端注册数据监听
14 | 6. 手机控制端控制手机采集端进行数据采集
15 | 7. 手机采集端持续收集传感器数据,每次采样以逗号分割
16 | 8. 通过socket发送采样到服务端
17 | 9. 服务端数据监听器接收并解析数据
18 |
19 | ## 依赖项目(目前jar包依赖,建议替换成项目依赖)
20 | [iSpaceSync](https://github.com/LeoCai/iSpaceSync)
21 |
22 |
23 | ## demo代码预览
24 |
25 | ```java
26 | /**
27 | * 服务端
28 | */
29 | private DataServerMultiClient dataServerMultiClient;
30 |
31 | /**
32 | * 缓冲区
33 | */
34 | private MultiClientDataBuffer buffer ;
35 |
36 |
37 | /**
38 | * 监听客户端
39 | * @throws IOException
40 | */
41 | public SensorCollectorServerDemo() throws IOException{
42 | dataServerMultiClient = new DataServerMultiClient();
43 | log("Server Address: " + dataServerMultiClient.getAddress());
44 | dataServerMultiClient.setOnConnectionListener(new OnConnectedListener() {
45 | @Override
46 | public void newClientConnected(String hostAddress) {
47 | log(hostAddress + "connected");
48 | }
49 | });
50 | dataServerMultiClient.startServer();
51 | log("Wait for client connecting..");
52 | log("After Connected, Press Enter to show data!");
53 | }
54 |
55 | public static void main(String[] args) throws IOException {
56 | SensorCollectorServerDemo sensorCollectorServerDemo = new SensorCollectorServerDemo();
57 | Scanner scanner = new Scanner(System.in);
58 | scanner.nextLine();
59 | sensorCollectorServerDemo.readyForReceive();
60 | }
61 |
62 | private static void log(String str) {
63 | System.out.println(str);
64 | }
65 |
66 | /**
67 | * 注册数据监听器
68 | * 准备接收数据
69 | */
70 | private void readyForReceive() {
71 | int clientsNum = dataServerMultiClient.getClientsNum();
72 | buffer = new MultiClientDataBuffer(10, clientsNum);
73 | dataServerMultiClient.addDataListener(this);
74 | log("Ready to receive data!");
75 | try {
76 | dataServerMultiClient.receivedData();
77 | } catch (IOException e1) {
78 | e1.printStackTrace();
79 | }
80 | }
81 |
82 |
83 | /*
84 | * 接收数据
85 | * 第一维代表客户端的索引
86 | * 第二维代表一次采样的所有数据
87 | *
88 | */
89 | @Override
90 | public void update(Observable o, Object arg) {
91 | double[][] data_multiClient = (double[][]) arg;
92 | buffer.add(data_multiClient);
93 | double[] clientFirstData = buffer.getClientFirstData(0);
94 | SingleSensorData sensorData = new SingleSensorData(clientFirstData);//封装数据
95 | System.out.println(Arrays.toString(sensorData.getAcc()));//输出线性加速度
96 | }
97 |
98 | ```
99 |
--------------------------------------------------------------------------------
/MultiSensorCollecterServerDemo/libs/spacesync.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/MultiSensorCollecterServerDemo/libs/spacesync.jar
--------------------------------------------------------------------------------
/MultiSensorCollecterServerDemo/src/com/leocai/multisensorcollector/serverdemo/SensorCollectorServerDemo.java:
--------------------------------------------------------------------------------
1 | package com.leocai.multisensorcollector.serverdemo;
2 |
3 | import java.io.IOException;
4 | import java.util.Arrays;
5 | import java.util.Observable;
6 | import java.util.Observer;
7 | import java.util.Scanner;
8 |
9 | import com.dislab.leocai.spacesync.connection.DataServerMultiClient;
10 | import com.dislab.leocai.spacesync.connection.OnConnectedListener;
11 | import com.dislab.leocai.spacesync.core.MultiClientDataBuffer;
12 | import com.dislab.leocai.spacesync.core.model.SensorDataSequnce;
13 | import com.dislab.leocai.spacesync.core.model.SingleSensorData;
14 | import com.dislab.leocai.spacesync.utils.SpaceSyncConfig;
15 |
16 | public class SensorCollectorServerDemo implements Observer {
17 |
18 | /**
19 | * 服务端
20 | */
21 | private DataServerMultiClient dataServerMultiClient;
22 |
23 | /**
24 | * 缓冲区
25 | */
26 | private MultiClientDataBuffer buffer ;
27 |
28 |
29 | /**
30 | * 监听客户端
31 | * @throws IOException
32 | */
33 | public SensorCollectorServerDemo() throws IOException{
34 | dataServerMultiClient = new DataServerMultiClient();
35 | log("Server Address: " + dataServerMultiClient.getAddress());
36 | dataServerMultiClient.setOnConnectionListener(new OnConnectedListener() {
37 | @Override
38 | public void newClientConnected(String hostAddress) {
39 | log(hostAddress + "connected");
40 | }
41 | });
42 | dataServerMultiClient.startServer();
43 | log("Wait for client connecting..");
44 | log("After Connected, Press Enter to show data!");
45 | }
46 |
47 | public static void main(String[] args) throws IOException {
48 | SensorCollectorServerDemo sensorCollectorServerDemo = new SensorCollectorServerDemo();
49 | Scanner scanner = new Scanner(System.in);
50 | scanner.nextLine();
51 | sensorCollectorServerDemo.readyForReceive();
52 | }
53 |
54 | private static void log(String str) {
55 | System.out.println(str);
56 | }
57 |
58 | /**
59 | * 注册数据监听器
60 | * 准备接收数据
61 | */
62 | private void readyForReceive() {
63 | int clientsNum = dataServerMultiClient.getClientsNum();
64 | buffer = new MultiClientDataBuffer(10, clientsNum);
65 | dataServerMultiClient.addDataListener(this);
66 | log("Ready to receive data!");
67 | try {
68 | dataServerMultiClient.receivedData();
69 | } catch (IOException e1) {
70 | e1.printStackTrace();
71 | }
72 | }
73 |
74 |
75 | /*
76 | * 接收数据
77 | * 第一维代表客户端的索引
78 | * 第二维代表一次采样的所有数据
79 | *
80 | */
81 | @Override
82 | public void update(Observable o, Object arg) {
83 | double[][] data_multiClient = (double[][]) arg;
84 | buffer.add(data_multiClient);
85 | double[] clientFirstData = buffer.getClientFirstData(0);
86 | SingleSensorData sensorData = new SingleSensorData(clientFirstData);//封装数据
87 | System.out.println(Arrays.toString(sensorData.getAcc()));//输出线性加速度
88 | }
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/SensorCollector.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.3.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/detection_unused/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/detection_unused/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.1"
6 |
7 | defaultConfig {
8 | applicationId "com.leocai.detecdtion"
9 | minSdkVersion 19
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | compile 'com.android.support:appcompat-v7:23.0.1'
25 | compile project(':publiclibs')
26 | }
27 |
--------------------------------------------------------------------------------
/detection_unused/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /home/leocai/Android/Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/detection_unused/src/androidTest/java/com/leocai/detecdtion/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.leocai.detecdtion;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/detection_unused/src/androidTest/java/com/leocai/detecdtion/core/KeyExtractorTest.java:
--------------------------------------------------------------------------------
1 | package com.leocai.detecdtion.core;
2 |
3 | import com.leocai.detecdtion.utils.MathUtils;
4 | import com.leocai.publiclibs.ShakingData;
5 |
6 | import junit.framework.TestCase;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | /**
12 | * Created by leocai on 16-1-6.
13 | */
14 | public class KeyExtractorTest extends TestCase {
15 |
16 | public void testGetCors() throws Exception {
17 | KeyExtractor keyExtractor = new Master();
18 | List data1 = new ArrayList<>();
19 | double d1[][] = new double[][]{
20 | {1,2,3,4,5},
21 | {2,3,4,5,6},
22 | {3,4,5,6,7}
23 | };
24 | List data2 = new ArrayList<>();
25 | double d2[][] = new double[][]{
26 | {2,3,1,5,6},
27 | {-3,-4,-5,-6,-7},
28 | {4,5,6,7,8}
29 | };
30 | for (int i = 0; i < d1[0].length; i++) {
31 | ShakingData sd1 = new ShakingData();
32 | sd1.setConvertedData(new double[]{d1[0][i],d1[1][i],d1[2][i]});
33 | data1.add(sd1);
34 | ShakingData sd2 = new ShakingData();
35 | sd2.setConvertedData(new double[]{d2[0][i], d2[1][i], d2[2][i]});
36 | data2.add(sd2);
37 | }
38 | double[] cors = MathUtils.getCors(data1, data2, data1.size());
39 | int i = 0;
40 | }
41 | }
--------------------------------------------------------------------------------
/detection_unused/src/androidTest/java/com/leocai/detecdtion/core/MasterTest.java:
--------------------------------------------------------------------------------
1 | package com.leocai.detecdtion.core;
2 |
3 | import android.util.Log;
4 |
5 | import com.leocai.detecdtion.blebrodcast.ShakeParameters;
6 | import com.leocai.publiclibs.ShakingData;
7 |
8 | import junit.framework.TestCase;
9 |
10 | import java.util.ArrayList;
11 | import java.util.Arrays;
12 | import java.util.List;
13 | import java.util.Random;
14 |
15 | /**
16 | * Created by leocai on 16-1-5.
17 | */
18 | public class MasterTest extends TestCase {
19 | private static final String TAG = "MasterTest";
20 | Master master = new Master();
21 |
22 | @Override
23 | public void setUp() throws Exception {
24 | super.setUp();
25 | List selfShakingData = new ArrayList<>();
26 | Random random = new Random(System.currentTimeMillis());
27 | for (int i = 0; i < 5; i++) {
28 | ShakingData sd = new ShakingData();
29 | double[] cd = new double[]{random.nextDouble()*10,random.nextDouble()*10,random.nextDouble()*10};
30 | sd.setConvertedData(cd);
31 | selfShakingData.add(sd);
32 | }
33 | master.setShakingDatas(selfShakingData);
34 | }
35 |
36 | public void testTrainParameters() throws Exception {
37 |
38 | List trainDatas = new ArrayList<>();
39 | for (int i = 0; i < 5; i++) {
40 | trainDatas.add(new ShakingData());
41 | }
42 | ShakeParameters shakeParameter = master.trainParameters(trainDatas);
43 | // System.out.println(shakeParameter.toString());
44 | }
45 |
46 |
47 |
48 | public void testIterTheta() throws Exception {
49 | System.out.println("asda");
50 | double[] gaccInit = new double[]{1,0,0};
51 | double initTheta = 2;
52 | double[][] initMatrix = master.getInitMatrix(gaccInit,initTheta);
53 | master.transformByParameter(initMatrix, master.getShakingDatas(),master.getShakingDatas().size());
54 | }
55 |
56 |
57 | public void testGetInitMatrix() throws Exception {
58 | double[] gaccInit = new double[]{0,0,1};
59 | double[][] initMatrix = master.getInitMatrix(gaccInit, 0);
60 | double[][] initMatrix2 = master.getInitMatrix(gaccInit, Math.PI/2);
61 | System.out.println(Arrays.toString(initMatrix));
62 |
63 | }
64 |
65 |
66 | public void testTransformByParameter() throws Exception {
67 | List shakingDatas = master.getShakingDatas();
68 | double[] gaccInit = new double[]{0,0,1};
69 | double[][] initMatrix =master.getInitMatrix(gaccInit, Math.PI/2);
70 | List cvDatas = master.transformByParameter(initMatrix, shakingDatas,shakingDatas.size());
71 | System.out.println();
72 | }
73 |
74 | public void testGenerateBits() throws Exception {
75 | List shakingDatas = new ArrayList<>();
76 | for (int i = 0; i < 50; i++) {
77 | shakingDatas.add(new ShakingData());
78 | }
79 | // ShakeBits bits = master.generateBits(shakingDatas);
80 | // Log.d(TAG,bits.toString());
81 | }
82 | }
--------------------------------------------------------------------------------
/detection_unused/src/androidTest/java/com/leocai/detecdtion/core/RandomnessExtractorTest.java:
--------------------------------------------------------------------------------
1 | package com.leocai.detecdtion.core;
2 |
3 | import junit.framework.TestCase;
4 |
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | /**
9 | * Created by leocai on 16-5-23.
10 | */
11 | public class RandomnessExtractorTest extends TestCase {
12 |
13 | private List bitsList = new ArrayList<>();
14 | {
15 | byte[] bitsArray = new byte[]{0,1,0,0,0,1,1,1};
16 | for(byte b:bitsArray){
17 | bitsList.add(b);
18 | }
19 | }
20 | RandomnessExtractor randomnessExtractor = new RandomnessExtractor(bitsList);
21 |
22 | public void testCodeTable() throws Exception {
23 | }
24 |
25 | public void testSubStringByMalkov() throws Exception {
26 |
27 | }
28 |
29 | public void testGetKey() throws Exception {
30 | List key = randomnessExtractor.getKey(bitsList);
31 | System.out.println(key.toString());
32 |
33 | }
34 | }
--------------------------------------------------------------------------------
/detection_unused/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
19 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
--------------------------------------------------------------------------------
/detection_unused/src/main/assets/MasterShakingDatas:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/detection_unused/src/main/assets/MasterShakingDatas
--------------------------------------------------------------------------------
/detection_unused/src/main/assets/SlaveShakingDatas:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/detection_unused/src/main/assets/SlaveShakingDatas
--------------------------------------------------------------------------------
/detection_unused/src/main/java/com/leocai/detecdtion/AuthenticationState.java:
--------------------------------------------------------------------------------
1 | package com.leocai.detecdtion;
2 |
3 | /**
4 | * Created by leocai on 15-12-27.
5 | */
6 | public class AuthenticationState {
7 |
8 | public enum AuState {
9 | TRAIN, RETURN_PARAMETER, TRANSFORMATION, CORSS_LEVEL, WAITE_PARAMETER, RECONCILATION, WAITE_FOR_RECONCIATION;
10 | }
11 |
12 | AuState auState = AuState.TRAIN;
13 |
14 | public AuState getAuState() {
15 | return auState;
16 | }
17 |
18 | public void setAuState(AuState auState) {
19 | this.auState = auState;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/detection_unused/src/main/java/com/leocai/detecdtion/DataTransformation.java:
--------------------------------------------------------------------------------
1 | package com.leocai.detecdtion;
2 |
3 | import com.leocai.detecdtion.blebrodcast.MixedSensorData;
4 | import com.leocai.detecdtion.blebrodcast.ShakeParameters;
5 | import com.leocai.detecdtion.transformation.MatrixUpdate;
6 | import com.leocai.detecdtion.transformation.MatrixUtils;
7 |
8 | /**
9 | * Created by leocai on 15-12-25.
10 | */
11 | public class DataTransformation {
12 | private double[][] newAcc6A;
13 |
14 | public DataTransformation(MixedSensorData selfMixedSensorData, ShakeParameters shakeParameters) {
15 | // double[][] accData = selfMixedSensorData.getLinearAccData();
16 | // double[][] gyrData = selfMixedSensorData.getGyrData();
17 | // double[][] initMatrix6A = ParameterLearning.getInitMatrix(gaccInit6A, initTheta6A);
18 | // MatrixUpdate matrixUpdate6A = new MatrixUpdate();
19 | //
20 | // matrixUpdate6A.setCuMatrix(initMatrix6A);
21 | //
22 | // newAcc6A = new double[0][];
23 | //
24 | // int dataSize = 0;
25 | // for (int i = 0; i < dataSize; i++) {
26 | // double dt = 0.02;
27 | // double[][] cuMatrix6A = matrixUpdate6A.updateMatrixByGYR(selfMixedSensorData.getGyrData()[i], dt);
28 | // newAcc6A[i] = MatrixUtils.convertMatrixToVector(MatrixUtils.multiply(MatrixUtils.convertVectorToMatrix(selfMixedSensorData.getLinearAccData()[i]), cuMatrix6A));//TODO order
29 | // }
30 |
31 | }
32 |
33 | public MixedSensorData getTransformedData() {
34 | return null;
35 | }
36 |
37 | // public MixedSensorData getTransformedData() {
38 | // return newAcc6A;
39 | // }
40 | }
41 |
--------------------------------------------------------------------------------
/detection_unused/src/main/java/com/leocai/detecdtion/Reconcilation.java:
--------------------------------------------------------------------------------
1 | package com.leocai.detecdtion;
2 |
3 | import com.leocai.detecdtion.blebrodcast.BleAdvertise;
4 | import com.leocai.detecdtion.blebrodcast.BleDiscover;
5 |
6 | /**
7 | * Created by leocai on 15-12-25.
8 | */
9 | public class Reconcilation {
10 | public Reconcilation(BleDiscover bleDiscover, BleAdvertise bleAdvertise, byte[] bytes) {
11 |
12 | }
13 |
14 | public void reconcilationData() {
15 |
16 | }
17 |
18 | public void ready() {
19 |
20 | }
21 |
22 | public void startReconcilation() {
23 |
24 | }
25 |
26 | public void reconcilation(byte[] data) {
27 |
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/detection_unused/src/main/java/com/leocai/detecdtion/SensorDataWithIndex.java:
--------------------------------------------------------------------------------
1 | package com.leocai.detecdtion;
2 |
3 | /**
4 | * Created by leocai on 15-12-26.
5 | */
6 | public class SensorDataWithIndex {
7 | private int index;
8 | private double accVal;
9 | private double gyrVal;
10 |
11 | public SensorDataWithIndex(int index, double accVal, double gyrVal) {
12 | this.index = index;
13 | this.accVal = accVal;
14 | this.gyrVal = gyrVal;
15 | }
16 |
17 | public int getIndex() {
18 | return index;
19 | }
20 |
21 | public void setIndex(int index) {
22 | this.index = index;
23 | }
24 |
25 | public double getAccVal() {
26 | return accVal;
27 | }
28 |
29 | public void setAccVal(double accVal) {
30 | this.accVal = accVal;
31 | }
32 |
33 | public double getGyrVal() {
34 | return gyrVal;
35 | }
36 |
37 | public void setGyrVal(double gyrVal) {
38 | this.gyrVal = gyrVal;
39 | }
40 |
41 | @Override
42 | public String toString() {
43 | return "SensorDataWithIndex{" +
44 | "index=" + index +
45 | ", accVal=" + accVal +
46 | ", gyrVal=" + gyrVal +
47 | '}';
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/detection_unused/src/main/java/com/leocai/detecdtion/ShakeBufferView.java:
--------------------------------------------------------------------------------
1 | package com.leocai.detecdtion;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.Paint;
7 | import android.util.AttributeSet;
8 | import android.view.View;
9 |
10 | import com.leocai.publiclibs.ShakingData;
11 |
12 | import java.util.ArrayList;
13 | import java.util.List;
14 | import java.util.Observable;
15 | import java.util.Observer;
16 |
17 | /**
18 | * Created by leocai on 15-12-22.
19 | */
20 | public class ShakeBufferView extends View implements Observer {
21 |
22 |
23 | private MySensorListener mySensorListener;
24 | private Paint paint = new Paint();
25 | private int index;
26 | private List buffer = new ArrayList<>();
27 |
28 | public ShakeBufferView(Context context) {
29 | super(context);
30 | }
31 |
32 | public ShakeBufferView(Context context, AttributeSet attrs) {
33 | super(context, attrs);
34 | }
35 |
36 | public ShakeBufferView(Context context, AttributeSet attrs, int defStyleAttr) {
37 | super(context, attrs, defStyleAttr);
38 | }
39 |
40 | public void setMySensorListener(MySensorListener mySensorListener) {
41 | this.mySensorListener = mySensorListener;
42 | }
43 |
44 | @Override
45 | protected void onDraw(Canvas canvas) {
46 | super.onDraw(canvas);
47 | float totalHeight = getHeight();
48 | float totalWidth = getWidth();
49 |
50 | if(buffer==null) return;
51 | double max = Double.MIN_VALUE;
52 | double min = Double.MAX_VALUE;
53 | for (double b : buffer) {
54 | if (max < b) max = b;
55 | if (min > b) min = b;
56 | }
57 |
58 | paint.setColor(Color.RED);
59 | paint.setStrokeWidth(2);
60 | // List buffer = new ArrayList<>();
61 | // buffer.add(3d);
62 | // buffer.add(5d);
63 | // buffer.add(0.2d);
64 | // canvas.drawPoint(20, 100, paint);
65 | float scaleWidth = 0.9f * totalWidth / buffer.size();
66 | float scaleHeight = (float) (0.5 * totalHeight / (max));
67 | float offY = totalHeight / 1.5f;
68 | for (int i = 1; i < buffer.size(); i++) {
69 | float startX = (i - 1) * scaleWidth,
70 | startY = offY - (float) (buffer.get(i - 1) * scaleHeight),
71 | endX = i * scaleWidth,
72 | endY = offY - (float) (buffer.get(i) * scaleHeight);
73 | canvas.drawLine(startX, startY, endX, endY, paint);
74 | }
75 | // for (double point : buffer) {
76 | // canvas.drawPoint(index * 20, (float) point * 100, paint);
77 | // index++;
78 | // }
79 | }
80 |
81 | @Override
82 | public void update(Observable observable, Object data) {
83 | List datas = (List) data;
84 | if(datas==null) return;
85 | for(ShakingData shakingData:datas){
86 | buffer.add(shakingData.getResultantAccData());
87 | }
88 | postInvalidate();
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/detection_unused/src/main/java/com/leocai/detecdtion/blebrodcast/CrossLevelUtils.java:
--------------------------------------------------------------------------------
1 | package com.leocai.detecdtion.blebrodcast;
2 |
3 | /**
4 | * Created by leocai on 15-12-28.
5 | */
6 | public class CrossLevelUtils {
7 | public static byte[] crossLevel(MixedSensorData mixedSensorData) {
8 | return new byte[0];
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/detection_unused/src/main/java/com/leocai/detecdtion/blebrodcast/MixedSensorData.java:
--------------------------------------------------------------------------------
1 | package com.leocai.detecdtion.blebrodcast;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Created by leocai on 15-12-28.
7 | */
8 | public class MixedSensorData {
9 |
10 | double accData[][];
11 | double gyrData[][];
12 |
13 | public MixedSensorData(double[][] accData, double[][] gyrData) {
14 | this.accData = accData;
15 | this.gyrData = gyrData;
16 | }
17 |
18 | public double[][] getAccData() {
19 | return accData;
20 | }
21 |
22 | public void setAccData(double[][] accData) {
23 | this.accData = accData;
24 | }
25 |
26 | public double[][] getGyrData() {
27 | return gyrData;
28 | }
29 |
30 | public void setGyrData(double[][] gyrData) {
31 | this.gyrData = gyrData;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/detection_unused/src/main/java/com/leocai/detecdtion/blebrodcast/ShakeParameters.java:
--------------------------------------------------------------------------------
1 | package com.leocai.detecdtion.blebrodcast;
2 |
3 | import com.leocai.detecdtion.utils.BytesUtils;
4 |
5 | import java.io.DataInputStream;
6 | import java.io.DataOutputStream;
7 | import java.io.IOException;
8 | import java.io.InputStream;
9 | import java.io.OutputStream;
10 | import java.util.Random;
11 |
12 | /**
13 | * Created by leocai on 15-12-28.
14 | */
15 | public class ShakeParameters {
16 |
17 | private double maxMean;
18 | private double initThetaMaster;
19 |
20 | public ShakeParameters() {
21 | Random random = new Random(System.currentTimeMillis());
22 | initThetaMaster = random.nextDouble();
23 | initThetaSlave = random.nextDouble();
24 | }
25 |
26 | public ShakeParameters(double initThetaMaster, double initThetaSlave, double maxMean) {
27 | this.initThetaMaster=initThetaMaster;
28 | this.initThetaSlave = initThetaSlave;
29 | this.maxMean = maxMean;
30 |
31 | }
32 |
33 | public double getInitThetaSlave() {
34 | return initThetaSlave;
35 | }
36 |
37 | public void setInitThetaSlave(double initThetaSlave) {
38 | this.initThetaSlave = initThetaSlave;
39 | }
40 |
41 | private double initThetaSlave;
42 |
43 | public double getInitThetaMaster() {
44 | return initThetaMaster;
45 | }
46 |
47 | public void setInitThetaMaster(double initThetaMaster) {
48 | this.initThetaMaster = initThetaMaster;
49 | }
50 |
51 | public ShakeParameters(double initThetaMaster) {
52 | this.initThetaMaster = initThetaMaster;
53 | }
54 |
55 | public static ShakeParameters parse(byte[] data) {
56 | return null;
57 | }
58 |
59 | public byte[] getBytes() {
60 | return BytesUtils.doubleToBytes(initThetaMaster);
61 | }
62 |
63 |
64 | public ShakeParameters(double initThetaMaster, double initThetaSlave) {
65 | this.initThetaMaster = initThetaMaster;
66 | this.initThetaSlave = initThetaSlave;
67 | }
68 |
69 | public static ShakeParameters read(InputStream in) throws IOException {
70 | DataInputStream dataInputStream = new DataInputStream(in);
71 | ShakeParameters shakeParameters = new ShakeParameters();
72 | shakeParameters.setInitThetaMaster(dataInputStream.readDouble());
73 | shakeParameters.setInitThetaSlave(dataInputStream.readDouble());
74 | return shakeParameters;
75 | }
76 |
77 | public static void send(OutputStream out, ShakeParameters shakeParameters) throws IOException {
78 | DataOutputStream dataOutputStream = new DataOutputStream(out);
79 | dataOutputStream.writeDouble(shakeParameters.getInitThetaMaster());
80 | dataOutputStream.writeDouble(shakeParameters.getInitThetaSlave());
81 | dataOutputStream.flush();
82 | }
83 |
84 | @Override
85 | public String toString() {
86 | return "ShakeParameters{" +
87 | "maxMean=" + maxMean +
88 | ", initThetaMaster=" + initThetaMaster +
89 | ", initThetaSlave=" + initThetaSlave +
90 | '}';
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/detection_unused/src/main/java/com/leocai/detecdtion/core/AccecptedCallBack.java:
--------------------------------------------------------------------------------
1 | package com.leocai.detecdtion.core;
2 |
3 | /**
4 | * Created by leocai on 16-1-6.
5 | */
6 | public interface AccecptedCallBack {
7 | void onAccepted();
8 | }
9 |
--------------------------------------------------------------------------------
/detection_unused/src/main/java/com/leocai/detecdtion/core/ConnectedCallBack.java:
--------------------------------------------------------------------------------
1 | package com.leocai.detecdtion.core;
2 |
3 | /**
4 | * Created by leocai on 16-1-6.
5 | */
6 | public interface ConnectedCallBack {
7 | void onConnected();
8 | }
9 |
--------------------------------------------------------------------------------
/detection_unused/src/main/java/com/leocai/detecdtion/core/ExcurtionsWithIndexes.java:
--------------------------------------------------------------------------------
1 | package com.leocai.detecdtion.core;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Created by leocai on 16-5-18.
7 | */
8 | public class ExcurtionsWithIndexes {
9 |
10 | private int[] indexes;
11 | private int[] excurtions;
12 |
13 | public ExcurtionsWithIndexes(List excutions, List indexes) {
14 | int len = indexes.size();
15 | this.indexes = new int[len];
16 | for (int i = 0; i < len; i++) {
17 | this.indexes[i] = indexes.get(i);
18 | }
19 | }
20 |
21 | public int[] getIndexes() {
22 | return indexes;
23 | }
24 |
25 | public void setIndexes(int[] indexes) {
26 | this.indexes = indexes;
27 | }
28 |
29 | public int[] getExcurtions() {
30 | return excurtions;
31 | }
32 |
33 | public void setExcurtions(int[] excurtions) {
34 | this.excurtions = excurtions;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/detection_unused/src/main/java/com/leocai/detecdtion/core/KeyExtractorActivity.java:
--------------------------------------------------------------------------------
1 | package com.leocai.detecdtion.core;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.view.Menu;
6 | import android.view.MenuItem;
7 | import android.view.View;
8 | import android.widget.TextView;
9 |
10 | import com.leocai.detecdtion.R;
11 | import com.leocai.detecdtion.ShakeBufferView;
12 | import com.leocai.publiclibs.PublicConstants;
13 | import com.leocai.publiclibs.ShakeDetector;
14 |
15 | import java.util.Observable;
16 | import java.util.Observer;
17 |
18 | public class KeyExtractorActivity extends AppCompatActivity implements Observer {
19 |
20 | private TextView tvLog;
21 |
22 | ShakeBufferView shakeBufferView;
23 |
24 | ShakeDatasStore shakeDatasStore = new ShakeDatasStore();
25 |
26 | ShakeDetector shakeDetector;
27 |
28 | @Override
29 | protected void onCreate(Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | setContentView(R.layout.activity_core_main);
32 | // ShakeBufferView shakeBufferView = (ShakeBufferView)findViewById(R.id.buffer_view);
33 | shakeBufferView = (ShakeBufferView) findViewById(R.id.shakebufferview);
34 |
35 | findViewById(R.id.btn_slave).setOnClickListener(new View.OnClickListener() {
36 | @Override
37 | public void onClick(View v) {
38 | Slave slave = new Slave(PublicConstants.MASTER_ADDRESS);
39 | shakeDetector = new ShakeDetector();
40 | shakeDetector.addObserver(shakeBufferView);
41 | shakeDetector.addObserver(shakeDatasStore);
42 | shakeDatasStore.setFileName("SlaveShakingDatas");
43 | slave.setShakeDetector(shakeDetector);
44 | slave.addObserver(KeyExtractorActivity.this);
45 | }
46 | });
47 | findViewById(R.id.btn_master).setOnClickListener(new View.OnClickListener() {
48 | @Override
49 | public void onClick(View v) {
50 | Master master = new Master();
51 | shakeDetector = new ShakeDetector();
52 | shakeDetector.addObserver(shakeBufferView);
53 | shakeDetector.addObserver(shakeDatasStore);
54 | shakeDatasStore.setFileName("MasterShakingDatas");
55 | master.setShakeDetector(shakeDetector);
56 | master.addObserver(KeyExtractorActivity.this);
57 | }
58 | });
59 |
60 | tvLog = (TextView) findViewById(R.id.tv_log);
61 |
62 | // slave = new MySensorListener(shakeBufferView);
63 | }
64 |
65 |
66 | @Override
67 | protected void onStop() {
68 | super.onStop();
69 | }
70 |
71 | @Override
72 | protected void onDestroy() {
73 | super.onDestroy();
74 | }
75 |
76 | @Override
77 | public boolean onCreateOptionsMenu(Menu menu) {
78 | // Inflate the menu; this adds items to the action bar if it is present.
79 | getMenuInflater().inflate(R.menu.menu_core_main, menu);
80 | return true;
81 | }
82 |
83 | @Override
84 | public boolean onOptionsItemSelected(MenuItem item) {
85 | // Handle action bar item clicks here. The action bar will
86 | // automatically handle clicks on the Home/Up button, so long
87 | // as you specify a parent activity in AndroidManifest.xml.
88 | int id = item.getItemId();
89 |
90 | //noinspection SimplifiableIfStatement
91 | if (id == R.id.action_settings) {
92 | return true;
93 | }
94 |
95 | return super.onOptionsItemSelected(item);
96 | }
97 |
98 | @Override
99 | public void update(Observable observable, final Object data) {
100 | runOnUiThread(new Runnable() {
101 | @Override
102 | public void run() {
103 | tvLog.setText((CharSequence) data);
104 | }
105 | });
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/detection_unused/src/main/java/com/leocai/detecdtion/core/PermutationKeyGenerator.java:
--------------------------------------------------------------------------------
1 | package com.leocai.detecdtion.core;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Arrays;
5 | import java.util.LinkedList;
6 | import java.util.List;
7 | import java.util.Queue;
8 |
9 | /**
10 | * PermutationKeyGenerator
11 | */
12 | public class PermutationKeyGenerator {
13 |
14 | private int numOne;
15 | private int n;
16 | private List> permutations = new ArrayList<>();
17 |
18 | /**
19 | * if generateKey(2,3)
20 | * then output:
21 | * [0, 0, 0]
22 | * [0, 0, 1]
23 | * [0, 1, 0]
24 | * [0, 1, 1]
25 | * [1, 0, 0]
26 | * [1, 0, 1]
27 | * [1, 1, 0]
28 | *
29 | * @param numOne the numbers of one
30 | * @param n
31 | */
32 | public String[] generateKey(int numOne, int n) {
33 | this.numOne = numOne;
34 | this.n = n;
35 | permutations.clear();
36 | List pList = new ArrayList<>();
37 | recursiveGenerate(0, 0, pList);
38 | String keys[] = new String[permutations.size()];
39 | int permutationSize = keys.length;
40 | for (int i = 0; i < permutationSize; i++) {
41 | StringBuilder key = new StringBuilder();
42 | List keyList = permutations.get(i);
43 | for (Integer bit : keyList) key.append(bit);
44 | keys[i] = key.toString();
45 | }
46 | // for(List pm:permutations){
47 | // System.out.println(pm.toString());
48 | // }
49 | return keys;
50 | }
51 |
52 |
53 | private void recursiveGenerate(int cuN, int cuNumOne, List pList) {
54 | if (cuN == n) {
55 | if (cuNumOne == numOne)
56 | permutations.add(pList);
57 | // System.out.println(pList.toString());
58 | return;
59 | }
60 | List newP = new ArrayList<>(pList);
61 | newP.add(0);
62 | cuN += 1;
63 | recursiveGenerate(cuN, cuNumOne, newP);
64 | if (cuNumOne < numOne) {
65 | pList.add(1);
66 | recursiveGenerate(cuN, cuNumOne + 1, pList);
67 | }
68 |
69 | }
70 |
71 | public static void main(String[] args) {
72 | PermutationKeyGenerator pm2 = new PermutationKeyGenerator();
73 | long start = System.nanoTime();
74 | pm2.generateKey(1, 4);
75 | System.out.println((System.nanoTime() - start) / 1000000);
76 |
77 | // start = System.nanoTime();
78 | // pm2.pm2(5, 50);
79 | // System.out.println((System.nanoTime() - start) / 1000000);
80 | }
81 |
82 | }
83 |
--------------------------------------------------------------------------------
/detection_unused/src/main/java/com/leocai/detecdtion/core/ReconcilationEndCallBack.java:
--------------------------------------------------------------------------------
1 | package com.leocai.detecdtion.core;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Created by leocai on 16-1-6.
7 | */
8 | public interface ReconcilationEndCallBack {
9 | void onReconcilationEnd(List bitsList, double mismatchRate);
10 | }
11 |
--------------------------------------------------------------------------------
/detection_unused/src/main/java/com/leocai/detecdtion/core/ShakeBits.java:
--------------------------------------------------------------------------------
1 | package com.leocai.detecdtion.core;
2 |
3 | import java.util.Arrays;
4 | import java.util.List;
5 |
6 | /**
7 | * Created by leocai on 15-12-31.
8 | */
9 | public class ShakeBits {
10 | private List bits;
11 |
12 | public ShakeBits(List bits) {
13 | this.bits = bits;
14 | }
15 |
16 | public List getBits() {
17 | return bits;
18 | }
19 |
20 | public void setBits(List bits) {
21 | this.bits = bits;
22 | }
23 |
24 | @Override
25 | public String toString() {
26 | return "ShakeBits{" +
27 | "bits=" + Arrays.toString(bits.toArray()) +
28 | '}';
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/detection_unused/src/main/java/com/leocai/detecdtion/core/ShakeDatasStore.java:
--------------------------------------------------------------------------------
1 | package com.leocai.detecdtion.core;
2 |
3 | import android.content.Context;
4 | import android.os.Environment;
5 |
6 | import com.leocai.publiclibs.ShakeDetector;
7 | import com.leocai.publiclibs.ShakingData;
8 |
9 | import java.io.BufferedReader;
10 | import java.io.DataOutput;
11 | import java.io.DataOutputStream;
12 | import java.io.File;
13 | import java.io.FileOutputStream;
14 | import java.io.FileWriter;
15 | import java.io.IOException;
16 | import java.io.InputStream;
17 | import java.io.InputStreamReader;
18 | import java.util.ArrayList;
19 | import java.util.List;
20 | import java.util.Observable;
21 | import java.util.Observer;
22 |
23 | /**
24 | * Created by leocai on 16-1-8.
25 | */
26 | public class ShakeDatasStore implements Observer {
27 |
28 | public static final String SLAVE_FILE = "Slave.csv";
29 | public static final String MASTER_FILE = "Master.csv";
30 | private DataOutputStream dataOutput;
31 |
32 | public String getFileName() {
33 | return fileName;
34 | }
35 |
36 | public void setFileName(String fileName) {
37 | this.fileName = fileName;
38 | }
39 |
40 | private String fileName;
41 |
42 | public void initFile(String fileName) {
43 | File file = new File(Environment.getExternalStorageDirectory(),fileName);
44 | try {
45 | dataOutput = new DataOutputStream(new FileOutputStream(file));
46 | } catch (IOException e) {
47 | e.printStackTrace();
48 | }
49 | }
50 |
51 | @Override
52 | public void update(Observable observable, Object data) {
53 | writeTofile((List) data);
54 | }
55 |
56 | public void writeTofile(List data) {
57 | FileWriter fileWriter = null;
58 | try {
59 | fileWriter = new FileWriter(new File(Environment.getExternalStorageDirectory(),fileName));
60 | fileWriter.write(new ShakingData().getCSVHead());
61 | } catch (IOException e) {
62 | e.printStackTrace();
63 | }
64 | if(fileWriter==null) return;
65 | for(ShakingData shakingData:data){
66 | try {
67 | fileWriter.write(shakingData.getCSV());
68 | } catch (IOException e) {
69 | e.printStackTrace();
70 | }
71 | }
72 | try {
73 | fileWriter.flush();
74 | } catch (IOException e) {
75 | e.printStackTrace();
76 | }
77 | }
78 |
79 | public List readFromFile(Context context){
80 | List shakingDatas = new ArrayList<>();
81 | try {
82 | InputStream in = context.getResources().getAssets().open(this.fileName);
83 | BufferedReader bf = new BufferedReader(new InputStreamReader(in));
84 | bf.readLine();
85 | for (int i = 1; i < ShakeDetector.MAX_POINT_SIZE; i++) {
86 | // in.read(buffer);
87 | String dataLine = bf.readLine();
88 | shakingDatas.add(new ShakingData(dataLine));
89 | }
90 | } catch (IOException e) {
91 | e.printStackTrace();
92 | }
93 | return shakingDatas;
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/detection_unused/src/main/java/com/leocai/detecdtion/core/ShakeKey.java:
--------------------------------------------------------------------------------
1 | package com.leocai.detecdtion.core;
2 |
3 | /**
4 | * Created by leocai on 15-12-31.
5 | */
6 | public class ShakeKey {
7 | }
8 |
--------------------------------------------------------------------------------
/detection_unused/src/main/java/com/leocai/detecdtion/core/ShakingDataGetterCallback.java:
--------------------------------------------------------------------------------
1 | package com.leocai.detecdtion.core;
2 |
3 | import com.leocai.publiclibs.ShakingData;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * Created by leocai on 16-1-11.
9 | */
10 | public interface ShakingDataGetterCallback {
11 | void onGetShakingDatas(List shakingDatas);
12 | }
13 |
--------------------------------------------------------------------------------
/detection_unused/src/main/java/com/leocai/detecdtion/core/WearDataGetter.java:
--------------------------------------------------------------------------------
1 | package com.leocai.detecdtion.core;
2 |
3 | import android.bluetooth.BluetoothAdapter;
4 | import android.bluetooth.BluetoothServerSocket;
5 | import android.bluetooth.BluetoothSocket;
6 | import android.util.Log;
7 |
8 | import com.leocai.publiclibs.PublicConstants;
9 | import com.leocai.publiclibs.ShakingData;
10 |
11 | import java.io.IOException;
12 | import java.io.InputStream;
13 | import java.util.ArrayList;
14 | import java.util.List;
15 | import java.util.Observable;
16 |
17 | /**
18 | * ReadDataFrom Wear
19 | * Created by leocai on 16-1-11.
20 | */
21 | public class WearDataGetter extends Observable {
22 |
23 | private static final String TAG = "WearDataGetter";
24 | private BluetoothServerSocket mmServerSocket;
25 |
26 | public WearDataGetter() {
27 | BluetoothAdapter mAdapter = BluetoothAdapter.getDefaultAdapter();
28 |
29 | try {
30 | mmServerSocket = mAdapter.listenUsingInsecureRfcommWithServiceRecord(PublicConstants.NAME_WEAR_DATA,
31 | PublicConstants.WEAR_UUID_INSECURE);
32 | } catch (IOException e) {
33 | e.printStackTrace();
34 | }
35 | }
36 |
37 | public void startListen(final ShakingDataGetterCallback shakingDataGetterCallback){
38 | new Thread(new Runnable() {
39 | @Override
40 | public void run() {
41 | try {
42 | Log.d(TAG,"Ble Listening...");
43 | BluetoothSocket socket = mmServerSocket.accept();
44 | Log.d(TAG,"Ble Connected");
45 | InputStream in = socket.getInputStream();
46 | byte[] buffer = new ShakingData().getBytes();
47 | List shakingDatas = new ArrayList<>();
48 | for (int i = 0; i < PublicConstants.SHAKING_DATA_SIZE; i++) {
49 | in.read(buffer);
50 | ShakingData shakingData = new ShakingData(buffer);
51 | shakingDatas.add(shakingData);
52 | }
53 | in.close();
54 | socket.close();
55 | shakingDataGetterCallback.onGetShakingDatas(shakingDatas);
56 | setChanged();
57 | notifyObservers(shakingDatas);
58 | } catch (IOException e) {
59 | e.printStackTrace();
60 | }
61 | }
62 | }).start();
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/detection_unused/src/main/java/com/leocai/detecdtion/core/test/TestBleActivity.java:
--------------------------------------------------------------------------------
1 | package com.leocai.detecdtion.core.test;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 | import android.view.Menu;
6 | import android.view.MenuItem;
7 | import android.view.View;
8 | import android.widget.Button;
9 | import android.widget.Toast;
10 |
11 | import com.leocai.detecdtion.R;
12 | import com.leocai.detecdtion.core.ShakingDataGetterCallback;
13 | import com.leocai.detecdtion.core.WearDataGetter;
14 | import com.leocai.publiclibs.BleConnection;
15 | import com.leocai.publiclibs.ConnectedCallBack;
16 | import com.leocai.publiclibs.PublicConstants;
17 | import com.leocai.publiclibs.ShakingData;
18 |
19 | import java.io.InputStream;
20 | import java.util.List;
21 |
22 | public class TestBleActivity extends AppCompatActivity {
23 |
24 |
25 | BleConnection bleConnection = new BleConnection();
26 |
27 | WearDataGetter wearDataGetter = new WearDataGetter();
28 |
29 | @Override
30 | protected void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | setContentView(R.layout.activity_test_ble);
33 | findViewById(R.id.btn_server).setOnClickListener(new View.OnClickListener() {
34 | @Override
35 | public void onClick(View v) {
36 | wearDataGetter.startListen(new ShakingDataGetterCallback() {
37 | @Override
38 | public void onGetShakingDatas(List shakingDatas) {
39 |
40 | }
41 | });
42 | }
43 | });
44 |
45 | findViewById(R.id.btn_client).setOnClickListener(new View.OnClickListener() {
46 | @Override
47 | public void onClick(View v) {
48 | bleConnection.connect(PublicConstants.addressSum, new ConnectedCallBack() {
49 | @Override
50 | public void onConnected(InputStream in) {
51 | runOnUiThread(new Runnable() {
52 | @Override
53 | public void run() {
54 | Toast.makeText(TestBleActivity.this, "Connected", Toast.LENGTH_LONG).show();
55 | }
56 | });
57 |
58 | }
59 | });
60 | }
61 | });
62 |
63 | }
64 |
65 | @Override
66 | public boolean onCreateOptionsMenu(Menu menu) {
67 | // Inflate the menu; this adds items to the action bar if it is present.
68 | getMenuInflater().inflate(R.menu.menu_test_ble, menu);
69 | return true;
70 | }
71 |
72 | @Override
73 | public boolean onOptionsItemSelected(MenuItem item) {
74 | // Handle action bar item clicks here. The action bar will
75 | // automatically handle clicks on the Home/Up button, so long
76 | // as you specify a parent activity in AndroidManifest.xml.
77 | int id = item.getItemId();
78 |
79 | //noinspection SimplifiableIfStatement
80 | if (id == R.id.action_settings) {
81 | return true;
82 | }
83 |
84 | return super.onOptionsItemSelected(item);
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/detection_unused/src/main/java/com/leocai/detecdtion/core/test/TestDetectionActivity.java:
--------------------------------------------------------------------------------
1 | package com.leocai.detecdtion.core.test;
2 |
3 | import android.content.Context;
4 | import android.hardware.Sensor;
5 | import android.hardware.SensorEvent;
6 | import android.hardware.SensorEventListener;
7 | import android.hardware.SensorManager;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.os.Bundle;
10 | import android.view.Menu;
11 | import android.view.MenuItem;
12 |
13 | import com.leocai.detecdtion.R;
14 | import com.leocai.detecdtion.ShakeBufferView;
15 | import com.leocai.publiclibs.PublicConstants;
16 | import com.leocai.publiclibs.ShakeDetector;
17 |
18 |
19 | //Test Dection
20 | public class TestDetectionActivity extends AppCompatActivity implements SensorEventListener {
21 |
22 | private SensorManager mSensorManager;
23 | private Sensor mSensorAcc;
24 | private Sensor mSensorGYR;
25 | private ShakeDetector shakeDetector;
26 |
27 | @Override
28 | protected void onCreate(Bundle savedInstanceState) {
29 | super.onCreate(savedInstanceState);
30 | setContentView(R.layout.activity_main);
31 | mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
32 | mSensorAcc = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
33 | mSensorGYR = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
34 | ShakeBufferView shakeBufferView = (ShakeBufferView) findViewById(R.id.buffer_view);
35 | shakeDetector = new ShakeDetector();
36 | shakeDetector.addObserver(shakeBufferView);
37 | mSensorManager.registerListener(this, mSensorAcc, (int) (PublicConstants.SENSOPR_PERIOD * 1000)); // 根据频率调整
38 | mSensorManager.registerListener(this, mSensorGYR, (int) (PublicConstants.SENSOPR_PERIOD * 1000));
39 |
40 | }
41 |
42 | @Override
43 | protected void onStop() {
44 | super.onStop();
45 | mSensorManager.unregisterListener(this, mSensorAcc);
46 | mSensorManager.unregisterListener(this, mSensorGYR);
47 | }
48 |
49 | @Override
50 | protected void onDestroy() {
51 |
52 | super.onDestroy();
53 | mSensorManager.unregisterListener(this, mSensorAcc);
54 | mSensorManager.unregisterListener(this, mSensorGYR);
55 | }
56 |
57 | @Override
58 | public boolean onCreateOptionsMenu(Menu menu) {
59 | // Inflate the menu; this adds items to the action bar if it is present.
60 | getMenuInflater().inflate(R.menu.menu_main, menu);
61 | return true;
62 | }
63 |
64 | @Override
65 | public boolean onOptionsItemSelected(MenuItem item) {
66 | // Handle action bar item clicks here. The action bar will
67 | // automatically handle clicks on the Home/Up button, so long
68 | // as you specify a parent activity in AndroidManifest.xml.
69 | int id = item.getItemId();
70 |
71 | //noinspection SimplifiableIfStatement
72 | if (id == R.id.action_settings) {
73 | return true;
74 | }
75 |
76 | return super.onOptionsItemSelected(item);
77 | }
78 |
79 |
80 | @Override
81 | public void onSensorChanged(SensorEvent event) {
82 | shakeDetector.onSensorChanged(event);
83 | }
84 |
85 | @Override
86 | public void onAccuracyChanged(Sensor sensor, int accuracy) {
87 |
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/detection_unused/src/main/java/com/leocai/detecdtion/core/test/TestMsgTransferActivity.java:
--------------------------------------------------------------------------------
1 | package com.leocai.detecdtion.core.test;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 | import android.util.Log;
6 | import android.view.Menu;
7 | import android.view.MenuItem;
8 | import android.view.View;
9 | import android.widget.TextView;
10 |
11 | import com.leocai.detecdtion.R;
12 | import com.leocai.detecdtion.core.Master;
13 | import com.leocai.detecdtion.core.ShakeDatasStore;
14 | import com.leocai.detecdtion.core.Slave;
15 | import com.leocai.publiclibs.PublicConstants;
16 | import com.leocai.publiclibs.ShakingData;
17 |
18 | import java.util.List;
19 | import java.util.Observable;
20 | import java.util.Observer;
21 |
22 |
23 | /**
24 | * off-line test data
25 | */
26 | public class TestMsgTransferActivity extends AppCompatActivity implements Observer {
27 | private static final String TAG = "TestMsg";
28 | private TextView tvLog;
29 |
30 | private ShakeDatasStore shakeDatasStore = new ShakeDatasStore();
31 |
32 | @Override
33 | protected void onCreate(Bundle savedInstanceState) {
34 | super.onCreate(savedInstanceState);
35 | setContentView(R.layout.activity_core_main);
36 | findViewById(R.id.btn_slave).setOnClickListener(new View.OnClickListener() {
37 | @Override
38 | public void onClick(View v) {
39 | Slave keyExtractor = new Slave(PublicConstants.MASTER_ADDRESS);
40 | shakeDatasStore.setFileName(ShakeDatasStore.SLAVE_FILE);
41 | List shakingDatas =shakeDatasStore.readFromFile(TestMsgTransferActivity.this);
42 | for(ShakingData shakingData:shakingDatas){
43 | Log.d(TAG, shakingData.toString());
44 | }
45 | keyExtractor.addObserver(TestMsgTransferActivity.this);
46 | // List shakingDatas = new ArrayList();
47 | // for (int i = 0; i < 100; i++) {
48 | // shakingDatas.add(new ShakingData());
49 | // }
50 | keyExtractor.onGetShakingDatas(shakingDatas);
51 | }
52 | });
53 | findViewById(R.id.btn_master).setOnClickListener(new View.OnClickListener() {
54 | @Override
55 | public void onClick(View v) {
56 | Master keyExtractor = new Master();
57 | keyExtractor.addObserver(TestMsgTransferActivity.this);
58 | shakeDatasStore.setFileName(ShakeDatasStore.MASTER_FILE);
59 | List shakingDatas =shakeDatasStore.readFromFile(TestMsgTransferActivity.this);
60 | for(ShakingData shakingData:shakingDatas){
61 | Log.d(TAG, shakingData.toString());
62 | }
63 | // List shakingDatas = new ArrayList();
64 | // for (int i = 0; i < 100; i++) {
65 | // shakingDatas.add(new ShakingData());
66 | // }
67 | keyExtractor.onGetShakingDatas(shakingDatas);
68 |
69 | }
70 | });
71 | tvLog = (TextView)findViewById(R.id.tv_log);
72 |
73 | }
74 |
75 | @Override
76 | public boolean onCreateOptionsMenu(Menu menu) {
77 | // Inflate the menu; this adds items to the action bar if it is present.
78 | getMenuInflater().inflate(R.menu.menu_test_core, menu);
79 | return true;
80 | }
81 |
82 | @Override
83 | public boolean onOptionsItemSelected(MenuItem item) {
84 | // Handle action bar item clicks here. The action bar will
85 | // automatically handle clicks on the Home/Up button, so long
86 | // as you specify a parent activity in AndroidManifest.xml.
87 | int id = item.getItemId();
88 |
89 | //noinspection SimplifiableIfStatement
90 | if (id == R.id.action_settings) {
91 | return true;
92 | }
93 |
94 | return super.onOptionsItemSelected(item);
95 | }
96 |
97 | @Override
98 | public void update(Observable observable, final Object data) {
99 | runOnUiThread(new Runnable() {
100 | @Override
101 | public void run() {
102 | tvLog.setText((CharSequence) data);
103 | }
104 | });
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/detection_unused/src/main/java/com/leocai/detecdtion/transformation/MatrixRotate.java:
--------------------------------------------------------------------------------
1 | package com.leocai.detecdtion.transformation;
2 |
3 | /**
4 | * Created by leocai on 15-10-10.
5 | */
6 | public class MatrixRotate {
7 | public static double[][] rotateI2B(double[][] vertexArray, double[][] rotateMatrix) {
8 | return MatrixUtils.multiply(rotateMatrix,MatrixUtils.T(vertexArray));
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/detection_unused/src/main/java/com/leocai/detecdtion/transformation/MatrixUpdate.java:
--------------------------------------------------------------------------------
1 | package com.leocai.detecdtion.transformation;
2 |
3 | /**
4 | * Created by leocai on 15-10-10.
5 | */
6 | public class MatrixUpdate {
7 | private double[][] cuMatrix = new double[][]{
8 | {1,0,0},
9 | {0,1,0},
10 | {0,0,1}
11 | };
12 | private double[][] I = new double[][]{
13 | {1,0,0},
14 | {0,1,0},
15 | {0,0,1}
16 | };
17 |
18 | public double[][] updateMatrix(double[][] matUpdate) {
19 | cuMatrix = MatrixUtils.multiply(cuMatrix, matUpdate);
20 | return cuMatrix;
21 | }
22 |
23 | public double[][] updateMatrixByGYR(double[] gyr, double dt) {
24 | double delta = Math.sqrt(Math.pow(gyr[0] * dt, 2) + Math.pow(gyr[1] * dt, 2) + Math.pow(gyr[2] * dt, 2));
25 | double[][] B = new double[][]{
26 | {0, -gyr[2] * dt, gyr[1] * dt},
27 | {gyr[2] * dt, 0, -gyr[0] * dt},
28 | {-gyr[1] * dt, gyr[0] * dt, 0}
29 | };
30 | double[][] B1 = MatrixUtils.numMultiply(Math.sin(delta) / delta, B);
31 | double[][] B2 = MatrixUtils.numMultiply((1 - Math.cos(delta)) / Math.pow(delta, 2), MatrixUtils.multiply(B, B));
32 | double[][] updateMatrix = MatrixUtils.plus(MatrixUtils.plus(I, B1), B2);
33 | return updateMatrix(updateMatrix);
34 | }
35 |
36 | public double[][] getCuMatrix() {
37 | return cuMatrix;
38 | }
39 |
40 | public void setCuMatrix(double[][] cuMatrix) {
41 | this.cuMatrix = cuMatrix;
42 | }
43 |
44 | public void resetCuMatrix() {
45 | cuMatrix = new double[][]{
46 | {1,0,0},
47 | {0,1,0},
48 | {0,0,1}
49 | };
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/detection_unused/src/main/java/com/leocai/detecdtion/transformation/MatrixUtils.java:
--------------------------------------------------------------------------------
1 | package com.leocai.detecdtion.transformation;
2 |
3 | import java.util.Arrays;
4 |
5 | /**
6 | * Created by leocai on 15-9-29.
7 | */
8 | public class MatrixUtils {
9 |
10 | public static double[][] T(double[][] mat){
11 | double[][] matrix= new double[mat[0].length][mat.length];
12 | for (int i = 0; i < mat.length; i++) {
13 | for (int j = 0; j < mat[0].length; j++) {
14 | matrix[j][i] = mat[i][j];
15 | }
16 | }
17 | return matrix;
18 | }
19 |
20 | public static double[][] floatArrayToMatrix(float[] fv) {
21 | double[][] mat = new double[fv.length / 3][3];
22 | for (int i = 0; i < mat.length; i++) {
23 | mat[i][0] = fv[i * 3];
24 | mat[i][1] = fv[i * 3 + 1];
25 | mat[i][2] = fv[i * 3 + 2];
26 | }
27 | return mat;
28 | }
29 |
30 | public static float[] matrixToFloatArray(double[][] mat){
31 | float [] farray = new float[mat.length*3];
32 | for (int i = 0; i < mat.length; i++) {
33 | for (int j = 0; j < 3; j++) {
34 | farray[i*3+j] = (float) mat[i][j];
35 | }
36 | }
37 | return farray;
38 | }
39 |
40 |
41 |
42 | public static double[][] multiply(double[][] matl, double[][] matr) {
43 | int row = matl.length;
44 | int column = matr[0].length;
45 | double[][] results = new double[row][column];
46 | for (int i = 0; i < row; i++) {
47 | for (int j = 0; j < column; j++) {
48 | double sum = 0;
49 | for (int k = 0; k < matl[0].length; k++) {
50 | sum += matl[i][k] * matr[k][j];
51 | }
52 | results[i][j] = sum;
53 | }
54 | }
55 | return results;
56 | }
57 |
58 | public static void main(String args[]) {
59 | double[][] matl = new double[][]{
60 | {1, 0},
61 | {0, 1}
62 | };
63 | double[][] matr = new double[][]{
64 | {1, 0},
65 | {0, 1}
66 | };
67 | double[][] ret = MatrixUtils.multiply(matl, matr);
68 | System.out.println(Arrays.toString(ret));
69 |
70 | }
71 |
72 | public static void printMatrix(double[][] mat) {
73 | String content = "";
74 | for (int i = 0; i < mat.length; i++) {
75 | for (int j = 0; j < mat[0].length; j++) {
76 | content += mat[i][j] + " ";
77 | }
78 | content += "\n";
79 | }
80 | System.out.print(content);
81 | }
82 |
83 | public static double[][] numMultiply(double num, double[][] mat) {
84 | int row = mat.length;
85 | int column = mat[0].length;
86 | double[][] results = new double[row][column];
87 | for (int i = 0; i < row; i++) {
88 | for (int j = 0; j < column; j++) {
89 | results[i][j] = mat[i][j]*num;
90 | }
91 | }
92 | return results;
93 | }
94 |
95 | public static double[][] plus(double[][] mat1, double[][] mat2) {
96 | int row = mat1.length;
97 | int column = mat1[0].length;
98 | double[][] results = new double[row][column];
99 | for (int i = 0; i < row; i++) {
100 | for (int j = 0; j < column; j++) {
101 | results[i][j] = mat1[i][j]+mat2[i][j];
102 | }
103 | }
104 | return results;
105 | }
106 |
107 | //TODO order
108 | public static double[][] convertVectorToMatrix(double[] vector) {
109 | return new double[][]{{vector[0]},{vector[1]},{vector[2]}};
110 | }
111 |
112 | //TODO orderTest
113 | public static double[] convertMatrixToVector(double[][] matrix) {
114 | return new double[]{matrix[0][0],matrix[1][0],matrix[2][0]};
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/detection_unused/src/main/java/com/leocai/detecdtion/utils/BytesUtils.java:
--------------------------------------------------------------------------------
1 | package com.leocai.detecdtion.utils;
2 |
3 | import com.leocai.detecdtion.SensorDataWithIndex;
4 |
5 | /**
6 | * Created by leocai on 15-12-26.
7 | */
8 | public class BytesUtils {
9 |
10 | public static byte[] intShortToBytes(int val) {
11 | byte[] barray = new byte[2];
12 | barray[0] = (byte) (val >> 8);
13 | barray[1] = (byte) (val & 0xFF);
14 | return barray;
15 | }
16 |
17 | public static byte[] doubleToBytes(double dval) {
18 | int val = (int) (dval * 100);
19 | return intShortToBytes(val);
20 | }
21 |
22 | public static boolean checkSizeType(byte[] bleBytes) {
23 | return bleBytes.length!=6;
24 | }
25 |
26 | public static int getShortIntFromBytes(byte[] sizeBytes,int index0, int index1) {
27 | int val0 = (sizeBytes[index0] & 0xF0) + (sizeBytes[index0] & 0x0F);
28 | int val1 = (sizeBytes[index1] & 0xF0) + (sizeBytes[index1] & 0x0F);
29 | return (val0 << 8) + val1;
30 | }
31 |
32 | public static int getSizeFromBytes(byte[] sizeBytes) {
33 | return getShortIntFromBytes(sizeBytes,0,1);
34 | }
35 |
36 | public static SensorDataWithIndex getSensorDataWithIndexFromBytes(byte[] dbytes) {
37 | int index = getShortIntFromBytes(dbytes,0,1);
38 | double accVal = 1.0 * getShortIntFromBytes(dbytes,2,3) / 100;
39 | double gyrVal = 1.0 * getShortIntFromBytes(dbytes,4,5) / 100;
40 | return new SensorDataWithIndex(index, accVal, gyrVal);
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/detection_unused/src/main/java/com/leocai/detecdtion/utils/MathUtils.java:
--------------------------------------------------------------------------------
1 | package com.leocai.detecdtion.utils;
2 |
3 | import com.leocai.publiclibs.ShakingData;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * Created by leocai on 16-5-3.
9 | */
10 | public class MathUtils {
11 | public static double[] norm(double[] vector) {
12 | double sum = 0;
13 | for (double d : vector) {
14 | sum += Math.pow(d, 2);
15 | }
16 | sum = Math.sqrt(sum);
17 | double[] newVector = new double[vector.length];
18 | for (int i = 0; i < newVector.length; i++) {
19 | newVector[i] = vector[i] / sum;
20 | }
21 | return newVector;
22 | }
23 |
24 | public static double[] crossProduct(double[] a, double[] b) {
25 | return new double[]{a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]};
26 | }
27 |
28 | public static double[] convertFromSphericalToCardinal(double r, double fi, double theta) {
29 | return new double[]{r * Math.sin(fi) * Math.cos(theta), r * Math.sin(fi) * Math.sin(theta), r * Math.cos(fi)};
30 | }
31 |
32 | //TODO correlation
33 | public static double[] getCors(List data1, List data2, int len) {
34 | double[] mean1 = new double[3], mean2 = new double[3], sd1 = new double[3], sd2 = new double[3], cor = new double[3];
35 | for (int i = 0; i < len; i++) {
36 | for (int j = 0; j < 3; j++) {
37 | mean1[j] += data1.get(i).getConvertedData()[j];
38 | mean2[j] += data2.get(i).getConvertedData()[j];
39 | }
40 | }
41 | for (int i = 0; i < 3; i++) {
42 | mean1[i] /= len;
43 | mean2[i] /= len;
44 | }
45 | for (int i = 0; i < len; i++) {
46 | for (int j = 0; j < 3; j++) {
47 | cor[j] += (data1.get(i).getConvertedData()[j] - mean1[j]) * (data2.get(i).getConvertedData()[j] - mean2[j]);
48 | sd1[j] += Math.pow(data1.get(i).getConvertedData()[j] - mean1[j], 2);
49 | sd2[j] += Math.pow(data2.get(i).getConvertedData()[j] - mean2[j], 2);
50 | }
51 | }
52 | for (int i = 0; i < 3; i++) {
53 | sd1[i] = Math.sqrt(sd1[i] / len);
54 | sd2[i] = Math.sqrt(sd2[i] / len);
55 | cor[i] /= len;
56 | }
57 | for (int i = 0; i < 3; i++) {
58 | cor[i] /= (sd1[i] * sd2[i]);
59 | }
60 | return cor;
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/detection_unused/src/main/res/layout/activity_ble_brodcast.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
16 |
17 |
24 |
25 |
34 |
35 |
--------------------------------------------------------------------------------
/detection_unused/src/main/res/layout/activity_core_main.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
17 |
18 |
25 |
26 |
35 |
36 |
44 |
45 |
--------------------------------------------------------------------------------
/detection_unused/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
14 |
15 |
--------------------------------------------------------------------------------
/detection_unused/src/main/res/layout/activity_test_ble.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
16 |
17 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/detection_unused/src/main/res/layout/activity_test_core.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
17 |
18 |
25 |
26 |
--------------------------------------------------------------------------------
/detection_unused/src/main/res/menu/menu_ble_brodcast.xml:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/detection_unused/src/main/res/menu/menu_core_main.xml:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/detection_unused/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/detection_unused/src/main/res/menu/menu_test_ble.xml:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/detection_unused/src/main/res/menu/menu_test_core.xml:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/detection_unused/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/detection_unused/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/detection_unused/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/detection_unused/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/detection_unused/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/detection_unused/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/detection_unused/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/detection_unused/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/detection_unused/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/detection_unused/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/detection_unused/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Detecdtion
3 |
4 | Hello world!
5 | Settings
6 | BleBrodcastActivity
7 | CDB7950D-73F1-4D4D-8E47-C090502DBD63
8 | CDB0950D-73F1-4D4D-8E47-C090502DBD63
9 | CoreMainActivity
10 | TestCoreActivity
11 | TestBleActivity
12 |
13 |
--------------------------------------------------------------------------------
/detection_unused/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/drafts.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/drafts.zip
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Nov 03 21:21:22 CST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/imgs/device-2017-01-02-111908.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/imgs/device-2017-01-02-111908.png
--------------------------------------------------------------------------------
/imgs/s1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/imgs/s1.png
--------------------------------------------------------------------------------
/imgs/s2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/imgs/s2.png
--------------------------------------------------------------------------------
/imgs/s3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/imgs/s3.png
--------------------------------------------------------------------------------
/imgs/s4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/imgs/s4.png
--------------------------------------------------------------------------------
/imgs/s5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/imgs/s5.png
--------------------------------------------------------------------------------
/imgs/s6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/imgs/s6.png
--------------------------------------------------------------------------------
/imgs/s7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/imgs/s7.png
--------------------------------------------------------------------------------
/multi_sensor_collector/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/multi_sensor_collector/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.1"
6 |
7 | defaultConfig {
8 | applicationId "com.leocai.multidevicesalign"
9 | minSdkVersion 19
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 |
21 | }
22 |
23 | dependencies {
24 | compile fileTree(dir: 'libs', include: ['*.jar'])
25 | compile project(':publiclibs')
26 | compile 'com.android.support:appcompat-v7:23.1.1'
27 | compile 'com.android.support:design:23.1.1'
28 | compile files('libs/accessory-v2.3.0.jar')
29 | compile files('libs/sdk-v1.0.0.jar')
30 | }
31 |
--------------------------------------------------------------------------------
/multi_sensor_collector/libs/accessory-v2.3.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/multi_sensor_collector/libs/accessory-v2.3.0.jar
--------------------------------------------------------------------------------
/multi_sensor_collector/libs/sdk-v1.0.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/multi_sensor_collector/libs/sdk-v1.0.0.jar
--------------------------------------------------------------------------------
/multi_sensor_collector/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /home/leocai/Android/Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/multi_sensor_collector/src/androidTest/java/com/leocai/multidevicesalign/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.leocai.multidevicesalign;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/multi_sensor_collector/src/main/java/com/leocai/multidevicesalign/AccessoryConsumer.java:
--------------------------------------------------------------------------------
1 | package com.leocai.multidevicesalign;
2 |
3 |
4 | import android.content.ComponentName;
5 | import android.content.Context;
6 | import android.content.Intent;
7 | import android.content.ServiceConnection;
8 | import android.os.IBinder;
9 | import android.widget.Toast;
10 |
11 | public class AccessoryConsumer {
12 | boolean mIsBound = false;
13 | private Context mActivity;
14 | private ConsumerService mConsumerService = null;
15 | private final ServiceConnection mConnection = new ServiceConnection() {
16 | @Override
17 | public void onServiceConnected(ComponentName className, IBinder service) {
18 | mConsumerService = ((ConsumerService.LocalBinder) service).getService();
19 | }
20 |
21 | @Override
22 | public void onServiceDisconnected(ComponentName className) {
23 | mConsumerService = null;
24 | mIsBound = false;
25 | }
26 | };
27 | public AccessoryConsumer(Context mActivity){
28 | this.mActivity = mActivity;
29 | }
30 | public boolean initial(){
31 | mIsBound = mActivity.bindService(new Intent(mActivity, ConsumerService.class), mConnection, Context.BIND_AUTO_CREATE);
32 | return mIsBound;
33 | }
34 | public void connect(){
35 | if (mIsBound == true && mConsumerService != null) {
36 | mConsumerService.findPeers();
37 | }
38 | }
39 | public void disconnext(){
40 | if (mIsBound == true && mConsumerService != null) {
41 | if (mConsumerService.closeConnection() == false) {
42 | //mActivity.updateTextView("Disconnected");
43 | //mMessageAdapter.clear();
44 | }
45 | }
46 | }
47 | public void start(){
48 | if (mIsBound == true && mConsumerService != null) {
49 | if (mConsumerService.sendData("Hello Accessory!")) {
50 | } else {
51 | }
52 | }
53 | }
54 | public void stop(){
55 | if (mIsBound == true && mConsumerService != null) {
56 | if (mConsumerService.closeConnection() == false) {
57 | //updateTextView("Disconnected");
58 | //mMessageAdapter.clear();
59 | }
60 | }
61 | // Un-bind service
62 | if (mIsBound) {
63 | //unbindService(mConnection);
64 | mIsBound = false;
65 | }
66 | }
67 | }
--------------------------------------------------------------------------------
/multi_sensor_collector/src/main/java/com/leocai/multidevicesalign/CollectorConfig.java:
--------------------------------------------------------------------------------
1 | package com.leocai.multidevicesalign;
2 |
3 | import java.util.UUID;
4 |
5 | /**
6 | * 独立项目的公有变量
7 | * Created by leocai on 16-1-5.
8 | */
9 | public class CollectorConfig {
10 | /**
11 | * 传感器周期 ms单位
12 | */
13 | public static final long SENSOPR_PERIOD = 20;
14 | public static final String MASTER_ADDRESS = "E8:B4:C8:8A:01:C7";
15 | public static final int SHAKING_DATA_SIZE = 50;
16 | public static final UUID WEAR_UUID_INSECURE = UUID.fromString("fa87c0d0-afac-11de-8a39-0800200c9a96");
17 | public static final String NAME_WEAR_DATA = "BluetoothChatWear";
18 | }
19 |
--------------------------------------------------------------------------------
/multi_sensor_collector/src/main/java/com/leocai/multidevicesalign/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.leocai.multidevicesalign;
2 |
3 | import android.content.Context;
4 | import android.hardware.Sensor;
5 | import android.hardware.SensorManager;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.os.Bundle;
8 | import android.view.Menu;
9 | import android.view.MenuItem;
10 | import android.view.View;
11 | import android.widget.Button;
12 |
13 | import com.leocai.publiclibs.multidecicealign.SensorDataWriter;
14 | import com.leocai.publiclibs.multidecicealign.SensorGlobalWriter;
15 |
16 | @Deprecated
17 | public class MainActivity extends AppCompatActivity {
18 |
19 | private SensorManager mSensorManager;
20 | private Sensor mSensorAcc;
21 | private Sensor mSensorGYR;
22 | SensorGlobalWriter sensorGlobalWriter = new SensorGlobalWriter("SensorGlobal.txt");
23 | private boolean stopped = true;
24 | private Sensor mSensorMAG;
25 |
26 |
27 | @Override
28 | protected void onCreate(Bundle savedInstanceState) {
29 | super.onCreate(savedInstanceState);
30 | setContentView(R.layout.activity_main);
31 | mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
32 | mSensorAcc = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
33 | mSensorGYR = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
34 | mSensorMAG = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
35 |
36 |
37 | findViewById(R.id.btn_start).setOnClickListener(new View.OnClickListener() {
38 | @Override
39 | public void onClick(View v) {
40 | if(stopped){
41 | ((Button)v).setText("STOP");
42 | stopped = false;
43 | mSensorManager.registerListener(sensorGlobalWriter, mSensorAcc, (int) (CollectorConfig.SENSOPR_PERIOD * 1000)); // 根据频率调整
44 | mSensorManager.registerListener(sensorGlobalWriter, mSensorGYR, (int) (CollectorConfig.SENSOPR_PERIOD * 1000));
45 | mSensorManager.registerListener(sensorGlobalWriter, mSensorMAG, (int) (CollectorConfig.SENSOPR_PERIOD * 1000));
46 | sensorGlobalWriter.startDetection();
47 | }else{
48 | ((Button)v).setText("START");
49 | stop();
50 | }
51 |
52 | }
53 | });
54 | }
55 |
56 | private void stop() {
57 | mSensorManager.unregisterListener(sensorGlobalWriter, mSensorAcc);
58 | mSensorManager.unregisterListener(sensorGlobalWriter, mSensorGYR);
59 | mSensorManager.unregisterListener(sensorGlobalWriter, mSensorMAG);
60 | sensorGlobalWriter.close();
61 | stopped = true;
62 | }
63 |
64 |
65 |
66 | @Override
67 | public boolean onCreateOptionsMenu(Menu menu) {
68 | // Inflate the menu; this adds items to the action bar if it is present.
69 | getMenuInflater().inflate(R.menu.menu_main, menu);
70 | return true;
71 | }
72 |
73 | @Override
74 | protected void onStop() {
75 | super.onStop();
76 | stop();
77 | }
78 |
79 | @Override
80 | protected void onDestroy() {
81 | super.onDestroy();
82 | stop();
83 | }
84 |
85 | @Override
86 | public boolean onOptionsItemSelected(MenuItem item) {
87 | // Handle action bar item clicks here. The action bar will
88 | // automatically handle clicks on the Home/Up button, so long
89 | // as you specify a parent activity in AndroidManifest.xml.
90 | int id = item.getItemId();
91 |
92 | //noinspection SimplifiableIfStatement
93 | if (id == R.id.action_settings) {
94 | return true;
95 | }
96 |
97 | return super.onOptionsItemSelected(item);
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/multi_sensor_collector/src/main/java/com/leocai/multidevicesalign/ShakeBufferView.java:
--------------------------------------------------------------------------------
1 | package com.leocai.multidevicesalign;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.Paint;
7 | import android.util.AttributeSet;
8 | import android.view.View;
9 |
10 | import com.leocai.publiclibs.ShakingData;
11 |
12 | import java.util.ArrayList;
13 | import java.util.List;
14 | import java.util.Observable;
15 | import java.util.Observer;
16 |
17 | /**
18 | * Created by leocai on 15-12-22.
19 | */
20 | public class ShakeBufferView extends View implements Observer {
21 |
22 |
23 | private Paint paint = new Paint();
24 | private int index;
25 | private List buffer = new ArrayList<>();
26 |
27 | public ShakeBufferView(Context context) {
28 | super(context);
29 | }
30 |
31 | public ShakeBufferView(Context context, AttributeSet attrs) {
32 | super(context, attrs);
33 | }
34 |
35 | public ShakeBufferView(Context context, AttributeSet attrs, int defStyleAttr) {
36 | super(context, attrs, defStyleAttr);
37 | }
38 |
39 |
40 | @Override
41 | protected void onDraw(Canvas canvas) {
42 | super.onDraw(canvas);
43 | float totalHeight = getHeight();
44 | float totalWidth = getWidth();
45 |
46 | if(buffer==null) return;
47 | double max = Double.MIN_VALUE;
48 | double min = Double.MAX_VALUE;
49 | for (double b : buffer) {
50 | if (max < b) max = b;
51 | if (min > b) min = b;
52 | }
53 |
54 | paint.setColor(Color.RED);
55 | paint.setStrokeWidth(2);
56 | float scaleWidth = 0.9f * totalWidth / buffer.size();
57 | float scaleHeight = (float) (0.5 * totalHeight / (max));
58 | float offY = totalHeight / 1.5f;
59 | for (int i = 1; i < buffer.size(); i++) {
60 | float startX = (i - 1) * scaleWidth,
61 | startY = offY - (float) (buffer.get(i - 1) * scaleHeight),
62 | endX = i * scaleWidth,
63 | endY = offY - (float) (buffer.get(i) * scaleHeight);
64 | canvas.drawLine(startX, startY, endX, endY, paint);
65 | }
66 | }
67 |
68 | @Override
69 | public void update(Observable observable, Object data) {
70 | buffer = (List)(data);
71 | postInvalidate();
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/multi_sensor_collector/src/main/java/com/leocai/multidevicesalign/SimpleDataActivity.java:
--------------------------------------------------------------------------------
1 | package com.leocai.multidevicesalign;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.view.View;
6 | import android.widget.Button;
7 | import android.widget.TextView;
8 |
9 | import com.leocai.publiclibs.ShakingData;
10 | import com.leocai.publiclibs.multidecicealign.MySensorManager;
11 |
12 | import java.io.IOException;
13 | import java.util.Observable;
14 | import java.util.Observer;
15 |
16 | public class SimpleDataActivity extends Activity implements Observer {
17 |
18 | TextView tv_log;
19 | Button btn_start;
20 | private boolean start;
21 | private MySensorManager mySensorManager;
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.activity_simple_data);
27 | tv_log = (TextView)findViewById(R.id.tv_log);
28 | btn_start = (Button)findViewById(R.id.btn_start);
29 | mySensorManager = new MySensorManager(this);
30 | try {
31 | mySensorManager.setFileName("simple.csv");
32 | } catch (IOException e) {
33 | e.printStackTrace();
34 | }
35 | mySensorManager.addObserver(this);
36 | mySensorManager.startSensor();
37 | btn_start.setOnClickListener(new View.OnClickListener() {
38 | @Override
39 | public void onClick(View v) {
40 | if(!start){
41 | start = true;
42 | mySensorManager.startDetection();
43 | btn_start.setText("STOP");
44 | }else{
45 | start = false;
46 | mySensorManager.stop();
47 | btn_start.setText("START");
48 | }
49 | }
50 | });
51 |
52 |
53 |
54 | }
55 |
56 | @Override
57 | public void update(Observable observable, Object data) {
58 | final ShakingData newData = (ShakingData) data;
59 |
60 | runOnUiThread(new Runnable() {
61 | @Override
62 | public void run() {
63 | String info = "";
64 | double[] lacc = newData.getLinearAccData();
65 | double[] globalAcc = newData.getConvertedData();
66 | info += "LinearAcc:\n";
67 | for (int i = 0; i < 3; i++) {
68 | info+= String.format("%.2f",lacc[i])+"\n";
69 | }
70 | info += "\nGlobalAcc:\n";
71 | for (int i = 0; i < 3; i++) {
72 | info+= String.format("%.2f",globalAcc[i])+"\n";
73 | }
74 | tv_log.setText(info);
75 | }
76 | });
77 |
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/multi_sensor_collector/src/main/java/com/leocai/multidevicesalign/SimpleDataActivity2.java:
--------------------------------------------------------------------------------
1 | package com.leocai.multidevicesalign;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.view.View;
6 | import android.widget.Button;
7 | import android.widget.TextView;
8 |
9 | import com.leocai.publiclibs.ShakingData;
10 | import com.leocai.publiclibs.multidecicealign.MySensorManager;
11 |
12 | import java.util.Observable;
13 | import java.util.Observer;
14 |
15 | public class SimpleDataActivity2 extends Activity implements Observer {
16 |
17 | TextView tv_log;
18 | Button btn_start;
19 | private boolean start;
20 | AccessoryConsumer accessoryConsumer;
21 |
22 | @Override
23 | protected void onCreate(Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | setContentView(R.layout.activity_simple_data);
26 | tv_log = (TextView)findViewById(R.id.tv_log);
27 | btn_start = (Button)findViewById(R.id.btn_start);
28 | accessoryConsumer = new AccessoryConsumer(this);
29 | accessoryConsumer.initial();
30 | btn_start.setOnClickListener(new View.OnClickListener() {
31 | @Override
32 | public void onClick(View v) {
33 | if(!start){
34 | start = true;
35 | btn_start.setText("STOP");
36 | }else{
37 | start = false;
38 | accessoryConsumer.connect();
39 | btn_start.setText("START");
40 | }
41 | }
42 | });
43 |
44 |
45 |
46 | }
47 |
48 | @Override
49 | public void update(Observable observable, Object data) {
50 | final ShakingData newData = (ShakingData) data;
51 |
52 | runOnUiThread(new Runnable() {
53 | @Override
54 | public void run() {
55 | String info = "";
56 | double[] lacc = newData.getLinearAccData();
57 | double[] globalAcc = newData.getConvertedData();
58 | info += "LinearAcc:\n";
59 | for (int i = 0; i < 3; i++) {
60 | info+= String.format("%.2f",lacc[i])+"\n";
61 | }
62 | info += "\nGlobalAcc:\n";
63 | for (int i = 0; i < 3; i++) {
64 | info+= String.format("%.2f",globalAcc[i])+"\n";
65 | }
66 | tv_log.setText(info);
67 | }
68 | });
69 |
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/multi_sensor_collector/src/main/res/layout/activity_ble_sync.xml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
16 |
17 |
26 |
27 |
35 |
36 |
44 |
45 |
54 |
55 |
64 |
65 |
66 |
67 |
75 |
76 |
84 |
85 |
86 |
87 |
88 |
89 |
--------------------------------------------------------------------------------
/multi_sensor_collector/src/main/res/layout/activity_gps.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
21 |
22 |
23 |
24 |
25 |
26 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/multi_sensor_collector/src/main/res/layout/activity_mag_test.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
21 |
22 |
23 |
24 |
25 |
26 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/multi_sensor_collector/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
10 |
11 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/multi_sensor_collector/src/main/res/layout/activity_simple_data.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
16 |
17 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/multi_sensor_collector/src/main/res/layout/content_gps.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
24 |
25 |
--------------------------------------------------------------------------------
/multi_sensor_collector/src/main/res/layout/content_mag_test.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
23 |
24 |
32 |
33 |
43 |
44 |
54 |
55 |
--------------------------------------------------------------------------------
/multi_sensor_collector/src/main/res/layout/content_simple_collection.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/multi_sensor_collector/src/main/res/layout/content_simple_data.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/multi_sensor_collector/src/main/res/menu/menu_ble_sync.xml:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/multi_sensor_collector/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/multi_sensor_collector/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/multi_sensor_collector/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/multi_sensor_collector/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/multi_sensor_collector/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/multi_sensor_collector/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/multi_sensor_collector/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/multi_sensor_collector/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/multi_sensor_collector/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/multi_sensor_collector/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 | >
2 |
3 |
9 |
10 |
--------------------------------------------------------------------------------
/multi_sensor_collector/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/multi_sensor_collector/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 16dp
6 |
7 |
--------------------------------------------------------------------------------
/multi_sensor_collector/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MultiDevicesAlign
3 |
4 | Hello world!
5 | Settings
6 | BleSyncActivity
7 | SimpleCollectionActivity
8 | SimpleDataActivity
9 | GPSActivity
10 | MagTestActivity
11 |
12 |
--------------------------------------------------------------------------------
/multi_sensor_collector/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/multi_sensor_collector/src/main/res/xml/accessoryservices.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | ]>
28 |
29 |
30 |
38 |
39 |
40 |
41 |
42 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/publiclibs/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/publiclibs/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.1"
6 |
7 | defaultConfig {
8 | minSdkVersion 19
9 | targetSdkVersion 23
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | compile 'com.android.support:appcompat-v7:23.0.1'
24 | compile files('libs/spacesync.jar')
25 | }
26 |
--------------------------------------------------------------------------------
/publiclibs/libs/spacesync.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/publiclibs/libs/spacesync.jar
--------------------------------------------------------------------------------
/publiclibs/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /home/leocai/Android/Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/publiclibs/src/androidTest/java/com/leocai/publiclibs/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.leocai.publiclibs;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/publiclibs/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/publiclibs/src/main/java/com/leocai/publiclibs/BleConnection.java:
--------------------------------------------------------------------------------
1 | package com.leocai.publiclibs;
2 |
3 | import android.bluetooth.BluetoothAdapter;
4 | import android.bluetooth.BluetoothDevice;
5 | import android.bluetooth.BluetoothSocket;
6 |
7 | import java.io.IOException;
8 | import java.io.InputStream;
9 | import java.io.OutputStream;
10 |
11 | /**
12 | * Created by leocai on 16-1-10.
13 | * 蓝牙连接客户端
14 | *
15 | */
16 | public class BleConnection {
17 |
18 | private BluetoothSocket bleSocket;
19 | private BluetoothAdapter mAdapter;
20 | private InputStream in;
21 | private OutputStream out;
22 |
23 | public BleConnection(){
24 | mAdapter = BluetoothAdapter.getDefaultAdapter();
25 | }
26 |
27 | public void connect(String address, final ConnectedCallBack connectedCallBack) {
28 | try {
29 | BluetoothDevice device = mAdapter.getRemoteDevice(address);
30 | bleSocket = device.createInsecureRfcommSocketToServiceRecord(PublicConstants.WEAR_UUID_INSECURE);
31 | new Thread(new Runnable() {
32 | @Override
33 | public void run() {
34 | try {
35 | bleSocket.connect();
36 | setIn(bleSocket.getInputStream());
37 | setOut(bleSocket.getOutputStream());
38 | connectedCallBack.onConnected(in);
39 | } catch (IOException e) {
40 | e.printStackTrace();
41 | }
42 | }
43 | }).start();
44 | } catch (IOException e) {
45 | e.printStackTrace();
46 | }
47 |
48 |
49 | }
50 |
51 | public void close() throws IOException {
52 | bleSocket.close();
53 | }
54 |
55 |
56 | public void setIn(InputStream in) {
57 | this.in = in;
58 | }
59 |
60 | public InputStream getIn() {
61 | return in;
62 | }
63 |
64 | public void setOut(OutputStream out) {
65 | this.out = out;
66 | }
67 |
68 | public OutputStream getOut() {
69 | return out;
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/publiclibs/src/main/java/com/leocai/publiclibs/ConnectedCallBack.java:
--------------------------------------------------------------------------------
1 | package com.leocai.publiclibs;
2 |
3 | import java.io.InputStream;
4 | import java.io.OutputStream;
5 |
6 | /**
7 | * Created by leocai on 16-1-10.
8 | * 回调函数:连接成功
9 | */
10 | public interface ConnectedCallBack {
11 | void onConnected(InputStream out);
12 | }
13 |
--------------------------------------------------------------------------------
/publiclibs/src/main/java/com/leocai/publiclibs/PublicConstants.java:
--------------------------------------------------------------------------------
1 | package com.leocai.publiclibs;
2 |
3 | import java.util.UUID;
4 |
5 | /**
6 | * 一些公有的全局变量
7 | * 包括传感器周期
8 | * 蓝牙地址等
9 | * Created by leocai on 16-1-5.
10 | */
11 | public class PublicConstants {
12 | public static final long SENSOPR_PERIOD = 20;
13 | public static final int SHAKING_DATA_SIZE = 50;
14 | // public static final UUID WEAR_UUID_INSECURE = UUID.fromString("fa87c0d0-afac-11de-8a39-0800200c9a96");
15 | public static final String NAME_WEAR_DATA = "BluetoothChatWear";
16 | public static final String NAME_WEAR_DATA2 = "BluetoothChatWear2";
17 | public static final UUID WEAR_UUID_INSECURE = UUID.fromString("fa87c0d0-afac-11de-8a39-0800200c9a96");
18 | public static final String addressMI = "7C:1D:D9:7D:56:B8";
19 | public static final String addressSum = "B8:C6:8E:B5:A3:06";
20 | public static final String addressSumNote = "B8:B4:C8:8A:01:C7";
21 | public static final String addressMI_BLACK = "58:44:98:48:5B:82";
22 | public static final String addressMeiZu = "22:22:9A:F5:63:F1";
23 |
24 | public static final String addressMI_424 = "58:44:98:48:5B:82";
25 | public static final String addressMI_422 = "58:44:98:E2:9C:92";
26 | public static final String addressSAM_419 = "80:4E:81:C3:31:55";
27 | /**
28 | * 控制主机地址
29 | */
30 | public static final String MASTER_ADDRESS = "58:44:98:48:5B:82";
31 |
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/publiclibs/src/main/java/com/leocai/publiclibs/connection/BleServer.java:
--------------------------------------------------------------------------------
1 | package com.leocai.publiclibs.connection;
2 |
3 | import android.bluetooth.BluetoothAdapter;
4 | import android.bluetooth.BluetoothServerSocket;
5 | import android.bluetooth.BluetoothSocket;
6 |
7 | import com.leocai.publiclibs.PublicConstants;
8 |
9 | import java.io.IOException;
10 | import java.io.OutputStream;
11 | import java.io.PrintWriter;
12 | import java.net.Socket;
13 | import java.util.ArrayList;
14 | import java.util.List;
15 | import java.util.Observable;
16 |
17 | /**
18 | * Created by leocai on 16-1-15.
19 | * 蓝牙主机,用于发指令控制从机开始和结束
20 | */
21 | public class BleServer extends Observable {
22 |
23 | List outs = new ArrayList<>();
24 | List sockets = new ArrayList<>();
25 | private BluetoothServerSocket mmServerSocket;
26 |
27 | private String fileName;
28 | private volatile boolean stop;
29 |
30 | public BleServer() {
31 | BluetoothAdapter mAdapter = BluetoothAdapter.getDefaultAdapter();
32 | try {
33 | mmServerSocket = mAdapter.listenUsingInsecureRfcommWithServiceRecord(PublicConstants.NAME_WEAR_DATA,
34 | PublicConstants.WEAR_UUID_INSECURE);
35 | } catch (IOException e) {
36 | e.printStackTrace();
37 | }
38 | }
39 |
40 | /**
41 | * 监听并发送文件名给其它从计
42 | */
43 | public void listen() {
44 | new Thread(new Runnable() {
45 | @Override
46 | public void run() {
47 | while (!stop) {
48 | try {
49 | BluetoothSocket socket = mmServerSocket.accept();
50 | sockets.add(socket);
51 | OutputStream out = socket.getOutputStream();
52 | outs.add(out);
53 | setChanged();
54 | notifyObservers(outs.size());
55 | } catch (IOException e) {
56 | e.printStackTrace();
57 | }
58 | try {
59 | Thread.sleep(50);
60 | } catch (InterruptedException e) {
61 | e.printStackTrace();
62 | }
63 | }
64 |
65 | }
66 | }).start();
67 |
68 |
69 | }
70 |
71 | /**
72 | * 发送开始指令
73 | */
74 | public void sendStartCommands() {
75 | for (OutputStream out : outs) {
76 | try {
77 | out.write(new byte[]{1});
78 | out.flush();
79 | } catch (IOException e) {
80 | e.printStackTrace();
81 | }
82 | }
83 | }
84 |
85 | /**
86 | * 发送结束指令
87 | */
88 | public void sendStopCommands() {
89 | for (OutputStream out : outs) {
90 | try {
91 | out.write(new byte[]{2});
92 | out.flush();
93 | } catch (IOException e) {
94 | e.printStackTrace();
95 | }
96 | }
97 | }
98 |
99 |
100 | public void sendFileCommands(String fileName) {
101 | for(OutputStream out:outs){
102 | PrintWriter pw = new PrintWriter(out);
103 | pw.write(fileName + "\n");
104 | pw.flush();
105 | }
106 | }
107 |
108 | public void close() {
109 | stop = true;
110 | try {
111 | for(BluetoothSocket socket:sockets){
112 | socket.close();
113 | }
114 | mmServerSocket.close();
115 | } catch (IOException e) {
116 | e.printStackTrace();
117 | }
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/publiclibs/src/main/java/com/leocai/publiclibs/connection/DealWithSample.java:
--------------------------------------------------------------------------------
1 | package com.leocai.publiclibs.connection;
2 |
3 | /**
4 | * Created by leocai on 16-12-17.
5 | */
6 | public interface DealWithSample {
7 |
8 | void dealWithSample(double[] data);
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/publiclibs/src/main/java/com/leocai/publiclibs/multidecicealign/BleClient.java:
--------------------------------------------------------------------------------
1 | package com.leocai.publiclibs.multidecicealign;
2 |
3 | import com.leocai.publiclibs.BleConnection;
4 | import com.leocai.publiclibs.ConnectedCallBack;
5 |
6 | import java.io.IOException;
7 | import java.io.InputStream;
8 |
9 | /**
10 | * 从设备客户端
11 | * Created by leocai on 16-1-15.
12 | */
13 | public class BleClient {
14 |
15 | /**
16 | * 此处可能有问题
17 | * 链接主机的地址
18 | */
19 | private String masterAddress;
20 | InputStream in;
21 |
22 | BleConnection bleConnection = new BleConnection();
23 | private volatile boolean stopped = false;
24 |
25 | /**
26 | * 用蓝牙连结到主机
27 | *
28 | * @param connectedCallBack 连接成功后的回调函数
29 | * @param fileInitCallBack
30 | * @param startCallBack 按下开始的回调函数
31 | * @param stopCallBack
32 | */
33 | public void connect(final ConnectedCallBack connectedCallBack, final FileInitCallBack fileInitCallBack, final StartCallBack startCallBack, final StopCallBack stopCallBack) {
34 | bleConnection.connect(masterAddress, new ConnectedCallBack() {
35 | @Override
36 | public void onConnected(InputStream in) {
37 | connectedCallBack.onConnected(in);
38 | BleClient.this.in = in;
39 | fileInitCallBack.onFileReceived(in);
40 | byte[] buffer = new byte[1];
41 | try {
42 | if (in.read(buffer) != -1)
43 | startCallBack.onStart();
44 | if (in.read(buffer) != -1)
45 | stopCallBack.onStop();
46 | } catch (IOException e) {
47 | e.printStackTrace();
48 | }
49 |
50 | }
51 | });
52 |
53 | }
54 |
55 |
56 | /**
57 | * 调用开始,开始进程完成后调用结束事件
58 | *
59 | * @param startCallBack 开始回调函数
60 | * @param stopCallBack 结束回调函数
61 | */
62 | public void waitForCommand(StartCallBack startCallBack, final StopCallBack stopCallBack) {
63 | byte[] buffer = new byte[1];
64 | try {
65 | in.read(buffer);
66 | if (buffer[0] == 1) startCallBack.onStart();
67 | new Thread(new Runnable() {
68 | @Override
69 | public void run() {
70 | byte[] b2 = new byte[1];
71 | try {
72 | in.read(b2);
73 | if (b2[0] == 2) stopCallBack.onStop();
74 | } catch (IOException e) {
75 | e.printStackTrace();
76 | }
77 | }
78 | }).start();
79 | } catch (IOException e) {
80 | e.printStackTrace();
81 | }
82 | }
83 |
84 | public BleClient(String masterAddress) {
85 | this.masterAddress = masterAddress;
86 | }
87 |
88 | public void close() {
89 | try {
90 | bleConnection.close();
91 | } catch (IOException e) {
92 | e.printStackTrace();
93 | }
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/publiclibs/src/main/java/com/leocai/publiclibs/multidecicealign/FileInitCallBack.java:
--------------------------------------------------------------------------------
1 | package com.leocai.publiclibs.multidecicealign;
2 |
3 | import java.io.InputStream;
4 | import java.io.OutputStream;
5 |
6 | /**
7 | * Created by leocai on 16-12-8.
8 | */
9 | public interface FileInitCallBack {
10 |
11 | void onFileReceived(InputStream in);
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/publiclibs/src/main/java/com/leocai/publiclibs/multidecicealign/MySensorManager.java:
--------------------------------------------------------------------------------
1 | package com.leocai.publiclibs.multidecicealign;
2 |
3 | import android.content.Context;
4 | import android.hardware.Sensor;
5 | import android.hardware.SensorManager;
6 |
7 | import com.leocai.publiclibs.PublicConstants;
8 |
9 | import java.io.IOException;
10 | import java.util.Observer;
11 |
12 | /**
13 | * 传感器管理类
14 | * 用于启动传感器,启动监听,传递事件给观察者
15 | * Created by leocai on 16-1-15.
16 | */
17 | public class MySensorManager {
18 | private SensorManager mSensorManager;
19 | private Sensor mSensorAcc;
20 | private Sensor mSensorGYR;
21 | private Sensor mSensorMAG;
22 | private Sensor mSensorGravity;
23 | private Sensor mSensorLinear;
24 | /**
25 | * 用于写文件的类
26 | */
27 | SensorGlobalWriter sensorGlobalWriter;
28 |
29 | private int frequency;
30 |
31 | public MySensorManager(Context context) {
32 | mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
33 | mSensorAcc = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
34 | mSensorGYR = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
35 | mSensorMAG = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
36 | mSensorGravity = mSensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY);
37 | mSensorLinear = mSensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION);
38 | sensorGlobalWriter = new SensorGlobalWriter();
39 | }
40 |
41 | /**
42 | * 设置写本地文件还是socket通信
43 | * @param globalWriter
44 | * SensorSocketWriter 写socket
45 | * SensorGlobalWriter 写文件
46 | */
47 | public void setGlobalWriter(SensorGlobalWriter globalWriter){
48 | sensorGlobalWriter = globalWriter;
49 | }
50 |
51 | public void startSensor() {
52 | if(frequency==0) frequency = (int) (1000/ PublicConstants.SENSOPR_PERIOD);
53 | mSensorManager.registerListener(sensorGlobalWriter, mSensorAcc, (int) (1000 / frequency * 1000)); // 根据频率调整
54 | mSensorManager.registerListener(sensorGlobalWriter, mSensorGYR, (int) (1000 / frequency * 1000));
55 | mSensorManager.registerListener(sensorGlobalWriter, mSensorMAG, (int) (1000 / frequency * 1000));
56 | mSensorManager.registerListener(sensorGlobalWriter, mSensorGravity, (int) (1000 / frequency * 1000));
57 | mSensorManager.registerListener(sensorGlobalWriter, mSensorLinear, (int) (1000 / frequency * 1000));
58 | }
59 |
60 | public void startDetection() {
61 | sensorGlobalWriter.startDetection();
62 | }
63 |
64 | public void stop() {
65 | sensorGlobalWriter.close();
66 | }
67 |
68 | public void close(){
69 | mSensorManager.unregisterListener(sensorGlobalWriter, mSensorAcc);
70 | mSensorManager.unregisterListener(sensorGlobalWriter, mSensorGYR);
71 | mSensorManager.unregisterListener(sensorGlobalWriter, mSensorMAG);
72 | mSensorManager.unregisterListener(sensorGlobalWriter, mSensorGravity);
73 | mSensorManager.unregisterListener(sensorGlobalWriter, mSensorLinear);
74 | sensorGlobalWriter.close();
75 | }
76 |
77 | /**
78 | * 设置文件名或ip地址
79 | * @param fileName
80 | */
81 | public void setFileName(String fileName) throws IOException {
82 | sensorGlobalWriter.setFileName(fileName);
83 | }
84 |
85 | public void addObserver(Observer observer) {
86 | sensorGlobalWriter.addObserver(observer);
87 | }
88 |
89 | public int getFrequency() {
90 | return frequency;
91 | }
92 |
93 | public void setFrequency(int frequency) {
94 | this.frequency = frequency;
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/publiclibs/src/main/java/com/leocai/publiclibs/multidecicealign/SensorSokectWriter.java:
--------------------------------------------------------------------------------
1 | package com.leocai.publiclibs.multidecicealign;
2 |
3 | import android.util.Log;
4 |
5 | import com.dislab.leocai.spacesync.connection.DataClientImpl;
6 | import com.leocai.publiclibs.PublicConstants;
7 |
8 | import java.io.IOException;
9 |
10 | /**
11 | * 监听传感器数据,用于将传感器数据写到socket中
12 | *
13 | * Created by leocai on 15-12-21.
14 | */
15 | public class SensorSokectWriter extends SensorGlobalWriter{
16 | private static final String TAG = "SensorDataWriter";
17 | private DataClientImpl dataClient;
18 | private volatile boolean stop;
19 |
20 | @Override
21 | public void setFileName(String address) throws IOException {
22 | dataClient.connect(address,10007);
23 | }
24 |
25 | public SensorSokectWriter() {
26 | dataClient = new DataClientImpl();
27 | cuShakingData.setLinearAccData(null);
28 | cuShakingData.setGyrData(null);
29 | cuShakingData.setDt(0);
30 | cuShakingData.setIndex(0);
31 | cuShakingData.setTimeStamp(0);
32 | }
33 |
34 | @Override
35 | public void startDetection() {
36 | stop = false;
37 | new Thread(new Runnable() {
38 | @Override
39 | public void run() {
40 | while (!stop) {
41 | if (cuShakingData.getLinearAccData() == null) continue;
42 | cuShakingData.transform();
43 | notifyObservers(cuShakingData);
44 | setChanged();
45 | try {
46 | Thread.sleep(PublicConstants.SENSOPR_PERIOD);
47 | String info = cuShakingData.getCSV();
48 | Log.d(TAG, info);
49 | dataClient.sendSample(info);
50 | } catch (InterruptedException | IOException e) {
51 | e.printStackTrace();
52 | }
53 | }
54 | }
55 | }).start();
56 | }
57 |
58 | public void close() {
59 | stop = true;
60 | try {
61 | if(dataClient!=null)
62 | dataClient.disconnect();
63 | } catch (IOException e) {
64 | e.printStackTrace();
65 | }
66 | }
67 |
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/publiclibs/src/main/java/com/leocai/publiclibs/multidecicealign/StartCallBack.java:
--------------------------------------------------------------------------------
1 | package com.leocai.publiclibs.multidecicealign;
2 |
3 | /**
4 | * 回调函数:开始事件
5 | * Created by leocai on 16-1-15.
6 | */
7 | public interface StartCallBack {
8 | void onStart();
9 | }
10 |
--------------------------------------------------------------------------------
/publiclibs/src/main/java/com/leocai/publiclibs/multidecicealign/StopCallBack.java:
--------------------------------------------------------------------------------
1 | package com.leocai.publiclibs.multidecicealign;
2 |
3 | /**
4 | * Created by leocai on 16-1-15.
5 | * 回调函数:结束事件
6 | */
7 | public interface StopCallBack {
8 | void onStop();
9 | }
10 |
--------------------------------------------------------------------------------
/publiclibs/src/main/java/com/leocai/publiclibs/utils/RollApply.java:
--------------------------------------------------------------------------------
1 | package com.leocai.publiclibs.utils;
2 |
3 | /**
4 | * Created by leocai on 15-12-23.
5 | */
6 | public class RollApply {
7 |
8 | public static double[][] rollApply(double[][] data, int window, RollApplyFunc rollApplyFunc) {
9 | double[][] newData = new double[data.length][data[0].length];
10 | for (int i = 0; i < data.length; i++) {
11 | int start = i - window / 2, end = i + window / 2;
12 | start = start < 0 ? 0 : start;
13 | end = end >= data.length ? data.length - 1 : end;
14 | double[] val = rollApplyFunc.apply(data, start, end);
15 | newData[i] = val;
16 | }
17 | return newData;
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/publiclibs/src/main/java/com/leocai/publiclibs/utils/RollApplyFunMean.java:
--------------------------------------------------------------------------------
1 | package com.leocai.publiclibs.utils;
2 |
3 | public class RollApplyFunMean implements RollApplyFunc {
4 |
5 | @Override
6 | public double[] apply(double[][] buffer, int start, int end) {
7 | int colNum = buffer[0].length;
8 | int len = end - start + 1;
9 | double[] mean = new double[colNum];
10 | for (int i = start; i <= end; i++) {
11 | for (int j = 0; j < colNum; j++) {
12 | mean[j] += buffer[i][j];
13 | }
14 | }
15 | for (int i = 0; i < colNum; i++) {
16 | mean[i] /= len;
17 | }
18 | return mean;
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/publiclibs/src/main/java/com/leocai/publiclibs/utils/RollApplyFunc.java:
--------------------------------------------------------------------------------
1 | package com.leocai.publiclibs.utils;
2 |
3 |
4 |
5 | /**
6 | * Created by leocai on 15-12-23.
7 | */
8 | public interface RollApplyFunc {
9 |
10 | double[] apply(double[][] buffer, int start, int end);
11 | }
12 |
--------------------------------------------------------------------------------
/publiclibs/src/main/java/com/leocai/publiclibs/utils/SensorData.java:
--------------------------------------------------------------------------------
1 | package com.leocai.publiclibs.utils;
2 |
3 |
4 | import com.dislab.leocai.spacesync.utils.MatrixUtils;
5 | import com.dislab.leocai.spacesync.utils.RotationUtils;
6 |
7 | import java.util.Arrays;
8 |
9 |
10 | public class SensorData {
11 |
12 | private static final int LINEAR_X = 0;
13 | private static final int LINEAR_Y = 1;
14 | private static final int LINEAR_Z = 2;
15 | private static final int GRIVATY_X = 3;
16 | private static final int GRIVATY_Y = 4;
17 | private static final int GRIVATY_Z = 5;
18 | private static final int GYR_X = 6;
19 | private static final int GYR_Y = 7;
20 | private static final int GYR_Z = 8;
21 | private static final int MAG_X = 9;
22 | private static final int MAG_Y = 10;
23 | private static final int MAG_Z = 11;
24 | private static final int GLOBAL_MAG_ACC_X = 12;
25 | private static final int GLOBAL_MAG_ACC_Y = 13;
26 | private static final int GLOBAL_MAG_ACC_Z = 14;
27 | private static final int DT_INDEX = 15;
28 |
29 | private double[][] data;
30 |
31 | public SensorData(double[][] totalDatas) {
32 | this.data = totalDatas;
33 | }
34 |
35 | public double[][] getData() {
36 | return data;
37 | }
38 |
39 | public void setData(double[][] data) {
40 | this.data = data;
41 | }
42 |
43 | public double[][] getLinearAccs() {
44 | return MatrixUtils.selectColumns(data, new int[]{LINEAR_X, LINEAR_Y, LINEAR_Z});
45 | }
46 |
47 | public double[][] getGyrs() {
48 | return MatrixUtils.selectColumns(data, new int[] { GYR_X, GYR_Y, GYR_Z });
49 | }
50 |
51 | public double[] getDT() {
52 | return MatrixUtils.selectColumn(data, DT_INDEX);
53 | }
54 |
55 | public double[][] getInitMatrix() {
56 | return new double[][] { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } };
57 | }
58 |
59 | public double[][] getGravityAccs() {
60 | return MatrixUtils.selectColumns(data, new int[]{GRIVATY_X, GRIVATY_Y, GRIVATY_Z});
61 | }
62 |
63 | @Override
64 | public String toString() {
65 | return "SensorData [data=" + Arrays.toString(data) + "]";
66 | }
67 |
68 | public double[][] getMagnet() {
69 | return MatrixUtils.selectColumns(data, new int[]{MAG_X, MAG_Y, MAG_Z});
70 | }
71 |
72 | public double[][] getGlobalMagAcc() {
73 | return MatrixUtils.selectColumns(data, new int[]{GLOBAL_MAG_ACC_X, GLOBAL_MAG_ACC_Y, GLOBAL_MAG_ACC_Z});
74 | }
75 |
76 | public double[][] getInitGlobalMatrix_G2B() {
77 | double[] gravity_acc = getGravityAccs()[0];
78 | double[] mag_acc = getGlobalMagAcc()[0];
79 | return getRotationMatrixG2BByMag(gravity_acc, mag_acc);
80 | }
81 |
82 | public static double[][] getRotationMatrixG2BByMag(double[] gravity_acc, double[] mag) {
83 | double Ex = mag[0];
84 | double Ey = mag[1];
85 | double Ez = mag[2];
86 | double Ax = gravity_acc[0];
87 | double Ay = gravity_acc[1];
88 | double Az = gravity_acc[2];
89 | double Hx = Ey * Az - Ez * Ay;
90 | double Hy = Ez * Ax - Ex * Az;
91 | double Hz = Ex * Ay - Ey * Ax;
92 | double normH = Math.sqrt(Hx * Hx + Hy * Hy + Hz * Hz);
93 | double invH = 1.0 / normH;
94 | Hx = Hx * invH;
95 | Hy = Hy * invH;
96 | Hz = Hz * invH;
97 | double invA = 1.0 / Math.sqrt(Ax * Ax + Ay * Ay + Az * Az);
98 | Ax = Ax * invA;
99 | Ay = Ay * invA;
100 | Az = Az * invA;
101 | double Mx = Ay * Hz - Az * Hy;
102 | double My = Az * Hx - Ax * Hz;
103 | double Mz = Ax * Hy - Ay * Hx;
104 | return new double[][] {
105 | { Hx, Mx, Ax },
106 | { Hy, My, Ay },
107 | { Hz, Mz, Az } };
108 | }
109 |
110 | public double[][] computeGlobalByMag() {
111 | double[][] gacc = getGravityAccs();
112 | double[][] mag = getMagnet();
113 | double[][] lacc = getLinearAccs();
114 | double[][] global_acc = new double[lacc.length][lacc[0].length];
115 | for (int i = 0; i < data.length; i++) {
116 | double[][] matrix_g2b = getRotationMatrixG2BByMag(gacc[i], mag[i]);
117 | global_acc[i] = RotationUtils.getGlobalData(lacc[i], MatrixUtils.T(matrix_g2b));
118 | }
119 | return global_acc;
120 | }
121 |
122 | }
123 |
--------------------------------------------------------------------------------
/publiclibs/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | PublicLibs
3 |
4 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':unsued1', ':wear_depracated', ':detection_unused', ':multi_sensor_collector', ':publiclibs', ':weardata_collector'
2 |
--------------------------------------------------------------------------------
/test:
--------------------------------------------------------------------------------
1 | asdasd:
2 |
--------------------------------------------------------------------------------
/unsued1/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/unsued1/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.1"
6 |
7 | defaultConfig {
8 | applicationId "com.leocai.hellowear"
9 | minSdkVersion 9
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | wearApp project(':wear_depracated')
25 | compile 'com.android.support:appcompat-v7:23.0.1'
26 | compile 'com.google.android.gms:play-services:7.8.0'
27 | }
28 |
--------------------------------------------------------------------------------
/unsued1/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /home/leocai/Android/Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/unsued1/src/androidTest/java/com/leocai/hellowear/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.leocai.hellowear;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/unsued1/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
14 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/unsued1/src/main/java/com/leocai/hellowear/Constants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.leocai.hellowear;
18 |
19 | /**
20 | * Defines several constants used between {@link BluetoothChatService} and the UI.
21 | */
22 | public interface Constants {
23 |
24 | // Message types sent from the BluetoothChatService Handler
25 | public static final int MESSAGE_STATE_CHANGE = 1;
26 | public static final int MESSAGE_READ = 2;
27 | public static final int MESSAGE_WRITE = 3;
28 | public static final int MESSAGE_DEVICE_NAME = 4;
29 | public static final int MESSAGE_TOAST = 5;
30 |
31 | // Key names received from the BluetoothChatService Handler
32 | public static final String DEVICE_NAME = "device_name";
33 | public static final String TOAST = "toast";
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/unsued1/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/unsued1/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/unsued1/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/unsued1/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/unsued1/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/unsued1/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/unsued1/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/unsued1/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/unsued1/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/unsued1/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/unsued1/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/unsued1/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/unsued1/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | HelloWear
3 |
4 | Hello world!
5 | Settings
6 |
7 |
--------------------------------------------------------------------------------
/unsued1/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/wear_depracated/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/wear_depracated/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 |
4 | android {
5 | compileSdkVersion 23
6 | buildToolsVersion "23.0.1"
7 |
8 | defaultConfig {
9 | applicationId "com.leocai.hellowear"
10 | minSdkVersion 20
11 | targetSdkVersion 23
12 | versionCode 1
13 | versionName "1.0"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 | dependencies {
24 | compile fileTree(dir: 'libs', include: ['*.jar'])
25 | compile 'com.google.android.support:wearable:1.3.0'
26 | compile 'com.google.android.gms:play-services-wearable:7.8.0'
27 | compile project(':publiclibs')
28 | }
29 |
--------------------------------------------------------------------------------
/wear_depracated/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /home/leocai/Android/Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/wear_depracated/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
21 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/wear_depracated/src/main/java/com/leocai/hellowear/BleFileTransfer.java:
--------------------------------------------------------------------------------
1 | package com.leocai.hellowear;
2 |
3 | import android.content.Context;
4 | import android.os.Environment;
5 | import android.widget.Toast;
6 |
7 | import java.io.BufferedReader;
8 | import java.io.File;
9 | import java.io.FileNotFoundException;
10 | import java.io.FileReader;
11 | import java.io.IOException;
12 |
13 | /**
14 | * Created by leocai on 15-11-18.
15 | */
16 | public class BleFileTransfer {
17 |
18 | private BluetoothChatService mChatService;
19 | private Context context;
20 | private int size = 0;
21 |
22 | public void transferFile(Context context, BluetoothChatService mChatService, String fileName) {
23 | this.mChatService = mChatService;
24 | this.context = context;
25 | File file = new File(Environment.getExternalStorageDirectory(),fileName);
26 | try {
27 | BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
28 | String msg;
29 | while((msg = bufferedReader.readLine())!=null){
30 | sendMsg(msg);
31 | size++;
32 | Thread.sleep(50);
33 | // Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
34 | }
35 | bufferedReader.close();
36 | } catch (FileNotFoundException e) {
37 | e.printStackTrace();
38 | } catch (IOException e) {
39 | e.printStackTrace();
40 | } catch (InterruptedException e) {
41 | e.printStackTrace();
42 | }
43 |
44 |
45 | }
46 |
47 | /**
48 | * Sends a message.
49 | *
50 | * @param message A string of text to send.
51 | */
52 | public void sendMsg(String message) {
53 | // Check that we're actually connected before trying anything
54 | if (mChatService.getState() != BluetoothChatService.STATE_CONNECTED) {
55 | Toast.makeText(context, "Not Connected!", Toast.LENGTH_SHORT).show();
56 | return;
57 | }
58 |
59 | // Check that there's actually something to send
60 | if (message.length() > 0) {
61 | // Get the message bytes and tell the BluetoothChatService to write
62 | byte[] send = message.getBytes();
63 | mChatService.write(send);
64 |
65 | }
66 | }
67 |
68 | public int getSize() {
69 | return size;
70 | }
71 |
72 | public void setSize(int size) {
73 | this.size = size;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/wear_depracated/src/main/java/com/leocai/hellowear/Constants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.leocai.hellowear;
18 |
19 | import java.util.UUID;
20 |
21 | /**
22 | * Defines several constants used between {@link BluetoothChatService} and the UI.
23 | */
24 | public interface Constants {
25 |
26 | String fileLogName = "112312.txt";
27 |
28 |
29 | // Message types sent from the BluetoothChatService Handler
30 | int MESSAGE_STATE_CHANGE = 1;
31 | int MESSAGE_READ = 2;
32 | int MESSAGE_WRITE = 3;
33 | int MESSAGE_DEVICE_NAME = 4;
34 | int MESSAGE_TOAST = 5;
35 |
36 | // Key names received from the BluetoothChatService Handler
37 | String DEVICE_NAME = "device_name";
38 | String TOAST = "toast";
39 |
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/wear_depracated/src/main/java/com/leocai/hellowear/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.leocai.hellowear;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.hardware.Sensor;
6 | import android.hardware.SensorEvent;
7 | import android.hardware.SensorEventListener;
8 | import android.hardware.SensorManager;
9 | import android.os.Bundle;
10 | import android.support.wearable.view.WatchViewStub;
11 | import android.widget.TextView;
12 |
13 | import java.util.Arrays;
14 |
15 | public class MainActivity extends Activity implements SensorEventListener {
16 |
17 | private TextView mTextView;
18 | private SensorManager mSensorManager;
19 | private Sensor mSensorAcc;
20 | private Sensor mSensorGYR;
21 | private long timestamp;
22 |
23 |
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.activity_main);
29 | final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
30 | stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
31 | @Override
32 | public void onLayoutInflated(WatchViewStub stub) {
33 | mTextView = (TextView) stub.findViewById(R.id.text);
34 | }
35 | });
36 | mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
37 | mSensorAcc = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
38 | mSensorGYR = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
39 |
40 | mSensorManager.registerListener(this, mSensorAcc, SensorManager.SENSOR_DELAY_FASTEST);
41 | // mSensorManager.registerListener(this, mSensorGYR, SensorManager.SENSOR_DELAY_FASTEST);
42 |
43 |
44 | }
45 |
46 | @Override
47 | public void onSensorChanged(SensorEvent event) {
48 | //event.sensor
49 | Sensor sensor = event.sensor;
50 | if (sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
51 | dealAcc(event);
52 | } else if (sensor.getType() == Sensor.TYPE_GYROSCOPE) {
53 | dealGYR(event);
54 | }
55 | }
56 |
57 | private void dealGYR(SensorEvent event) {
58 | double[] gyrdata = new double[]{event.values[0], event.values[1], event.values[2]};
59 | double dt = 1.0 * (event.timestamp - timestamp) / 1000000000;
60 | if (mTextView != null) {
61 | mTextView.setText(Arrays.toString(gyrdata));
62 | timestamp = event.timestamp;
63 | }
64 |
65 | }
66 |
67 |
68 |
69 | private void dealAcc(SensorEvent event) {
70 |
71 | }
72 |
73 | @Override
74 | public void onAccuracyChanged(Sensor sensor, int accuracy) {
75 |
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/wear_depracated/src/main/java/com/leocai/hellowear/WearSensorListener.java:
--------------------------------------------------------------------------------
1 | package com.leocai.hellowear;
2 |
3 | import android.hardware.Sensor;
4 | import android.hardware.SensorEvent;
5 | import android.hardware.SensorEventListener;
6 | import android.os.Environment;
7 |
8 | import java.io.File;
9 | import java.io.FileWriter;
10 | import java.io.IOException;
11 |
12 | /**
13 | * Created by leocai on 15-11-17.
14 | */
15 | public class WearSensorListener implements SensorEventListener {
16 |
17 | private final BleActivity bleActivity;
18 | private FileWriter fileWriter;
19 | private long startTime = System.nanoTime();
20 | private int accCount = 0;
21 | private int gyrCount = 0;
22 |
23 |
24 | public WearSensorListener(BleActivity bleActivity) {
25 | this.bleActivity = bleActivity;
26 |
27 |
28 | }
29 |
30 | public void initFile(String fileName) {
31 | File file = new File(Environment.getExternalStorageDirectory(),fileName);
32 | try {
33 | fileWriter = new FileWriter(file);
34 | } catch (IOException e) {
35 | e.printStackTrace();
36 | }
37 | }
38 |
39 |
40 | @Override
41 | public void onSensorChanged(SensorEvent event) {
42 | //event.sensor
43 | Sensor sensor = event.sensor;
44 | if (sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
45 | dealAcc(event);
46 | } else if (sensor.getType() == Sensor.TYPE_GYROSCOPE) {
47 | dealGYR(event);
48 | }
49 |
50 | }
51 |
52 | private void dealGYR(SensorEvent event) {
53 | long dt = event.timestamp - startTime;
54 | String msg = "G"+","+event.values[0] + "," + event.values[1] + "," + event.values[2]+","+dt+"\n";
55 | try {
56 | fileWriter.write(msg);
57 | } catch (IOException e) {
58 | e.printStackTrace();
59 | }
60 | // bleActivity.sendMsg();
61 | gyrCount++;
62 | showCount();
63 | }
64 |
65 | private void dealAcc(SensorEvent event) {
66 | long dt = event.timestamp - startTime;
67 | String msg = "A"+","+event.values[0] + "," + event.values[1] + "," + event.values[2]+","+dt+"\n";
68 | try {
69 | fileWriter.write(msg);
70 | } catch (IOException e) {
71 | e.printStackTrace();
72 | }
73 | // bleActivity.sendMsg();
74 | accCount++;
75 | showCount();
76 | }
77 |
78 | private void showCount(){
79 | // String msg = "A:"+accCount+" G:"+gyrCount;
80 | // bleActivity.setInfo(msg);
81 | }
82 |
83 | @Override
84 | public void onAccuracyChanged(Sensor sensor, int accuracy) {
85 |
86 | }
87 |
88 | public void close() {
89 | try {
90 | fileWriter.flush();
91 | fileWriter.close();
92 | } catch (IOException e) {
93 | e.printStackTrace();
94 | }
95 | }
96 |
97 | public String getCountInfo() {
98 | return "A:"+accCount+" G:"+gyrCount;
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/wear_depracated/src/main/java/com/leocai/hellowear/utils/ApplyFuncMean.java:
--------------------------------------------------------------------------------
1 | package com.leocai.hellowear.utils;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Created by leocai on 15-12-23.
7 | */
8 | public class ApplyFuncMean implements RollApplyFunc {
9 | @Override
10 | public double apply(List buffer, int startIndex, int window) {
11 | double mean = 0;
12 | for (int i = startIndex; i < startIndex + window; i++) {
13 | System.out.print(buffer.get(i) + " ");
14 | mean += buffer.get(i);
15 | }
16 | System.out.println();
17 | return mean / window;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/wear_depracated/src/main/java/com/leocai/hellowear/utils/ApplyFuncPeak.java:
--------------------------------------------------------------------------------
1 | package com.leocai.hellowear.utils;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Created by leocai on 15-12-23.
7 | */
8 | public class ApplyFuncPeak implements RollApplyFunc {
9 | @Override
10 | public double apply(List buffer, int startIndex, int window) {
11 | int xCenterIndex = startIndex + (window - 1) / 2;
12 | double center = buffer.get(xCenterIndex), centerPre = buffer.get(xCenterIndex - 1), centerAfter = buffer.get(xCenterIndex + 1);
13 | double mean = 0, sd = 0;
14 | for (int i = startIndex; i < startIndex + window; i++) {
15 | mean += buffer.get(i);
16 | }
17 | mean /= window;
18 | for (int i = startIndex; i < startIndex + window; i++) {
19 | sd += Math.pow(buffer.get(i) - mean, 2);
20 | }
21 | sd = Math.sqrt(sd / window);
22 | if (center > 3
23 | && center > centerPre && center > centerAfter
24 | && center > (mean + 0.3 * sd))
25 | return center;
26 | return 0;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/wear_depracated/src/main/java/com/leocai/hellowear/utils/ApplyFuncPeak2.java:
--------------------------------------------------------------------------------
1 | package com.leocai.hellowear.utils;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Created by leocai on 15-12-23.
7 | */
8 | public class ApplyFuncPeak2 implements RollApplyFunc {
9 | private double meanPeak;
10 |
11 | public ApplyFuncPeak2(double meanPeak) {
12 | this.meanPeak = meanPeak;
13 | }
14 |
15 | @Override
16 | public double apply(List buffer, int startIndex, int window) {
17 | double val = buffer.get(startIndex);
18 | if(val>meanPeak) return 2; else if(val!=0) return 1;
19 | return 0;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/wear_depracated/src/main/java/com/leocai/hellowear/utils/RollApply.java:
--------------------------------------------------------------------------------
1 | package com.leocai.hellowear.utils;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | /**
7 | * Created by leocai on 15-12-23.
8 | */
9 | public class RollApply {
10 |
11 | public static List rollApply(List buffer, int window, RollApplyFunc rollApplyFunc) {
12 | List newBuffer = new ArrayList<>();
13 | for (int i = 0; i < buffer.size() - window + 1; i++) {
14 | Double val = rollApplyFunc.apply(buffer, i, window);
15 | newBuffer.add(val);
16 | }
17 | return newBuffer;
18 | }
19 |
20 | public static void main(String args[]) {
21 |
22 | List buffer = new ArrayList<>();
23 | double bf[] = new double[]{1,2,3,4,5,6,7,8,9,10};
24 | for(double b:bf){
25 | buffer.add(b);
26 | }
27 | List newBf = RollApply.rollApply(buffer, 5, new RollApplyFunc() {
28 | @Override
29 | public double apply(List buffer, int startIndex, int window) {
30 | double mean = 0;
31 | for (int i = startIndex; i < startIndex + window; i++) {
32 | System.out.print(buffer.get(i) + " ");
33 | mean += buffer.get(i);
34 | }
35 | System.out.println();
36 | return mean / window;
37 | }
38 | });
39 | for(double b : newBf){
40 | System.out.println(b);
41 | }
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/wear_depracated/src/main/java/com/leocai/hellowear/utils/RollApplyFunc.java:
--------------------------------------------------------------------------------
1 | package com.leocai.hellowear.utils;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Created by leocai on 15-12-23.
7 | */
8 | public interface RollApplyFunc {
9 |
10 | double apply(List buffer, int startIndex, int window);
11 | }
12 |
--------------------------------------------------------------------------------
/wear_depracated/src/main/res/layout/activity_ble.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
--------------------------------------------------------------------------------
/wear_depracated/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
--------------------------------------------------------------------------------
/wear_depracated/src/main/res/layout/activity_wear.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/wear_depracated/src/main/res/layout/rect_activity_ble.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
21 |
22 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/wear_depracated/src/main/res/layout/rect_activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
9 |
10 |
--------------------------------------------------------------------------------
/wear_depracated/src/main/res/layout/round_activity_ble.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
23 |
24 |
31 |
32 |
37 |
38 |
39 |
45 |
46 |
53 |
54 |
61 |
62 |
69 |
70 |
--------------------------------------------------------------------------------
/wear_depracated/src/main/res/layout/round_activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/wear_depracated/src/main/res/menu/menu_wear.xml:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/wear_depracated/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/wear_depracated/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/wear_depracated/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/wear_depracated/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/wear_depracated/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/wear_depracated/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/wear_depracated/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/wear_depracated/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/wear_depracated/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/wear_depracated/src/main/res/values/attrs_shake_buffer.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/wear_depracated/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/wear_depracated/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | HelloWear
3 | Hello Round World!
4 | Hello Square World!
5 | BleActivity
6 | WearActivity
7 |
8 | Hello world!
9 | Settings
10 |
11 |
--------------------------------------------------------------------------------
/weardata_collector/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/weardata_collector/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 |
4 | android {
5 | compileSdkVersion 23
6 | buildToolsVersion "23.0.1"
7 |
8 | defaultConfig {
9 | applicationId "com.leocai.weardata"
10 | minSdkVersion 20
11 | targetSdkVersion 23
12 | versionCode 1
13 | versionName "1.0"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 | dependencies {
24 | compile fileTree(dir: 'libs', include: ['*.jar'])
25 | compile 'com.google.android.support:wearable:1.3.0'
26 | compile 'com.google.android.gms:play-services-wearable:8.4.0'
27 | compile project(':publiclibs')
28 | }
29 |
--------------------------------------------------------------------------------
/weardata_collector/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /home/leocai/Android/Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/weardata_collector/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
15 |
18 |
19 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/weardata_collector/src/main/java/com/leocai/weardata/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.leocai.weardata;
2 |
3 | import android.os.Bundle;
4 | import android.support.wearable.activity.WearableActivity;
5 | import android.support.wearable.view.BoxInsetLayout;
6 | import android.view.View;
7 | import android.widget.TextView;
8 |
9 | import java.text.SimpleDateFormat;
10 | import java.util.Date;
11 | import java.util.Locale;
12 |
13 | @Deprecated
14 | public class MainActivity extends WearableActivity {
15 |
16 | private static final SimpleDateFormat AMBIENT_DATE_FORMAT =
17 | new SimpleDateFormat("HH:mm", Locale.US);
18 |
19 | private BoxInsetLayout mContainerView;
20 | private TextView mTextView;
21 | private TextView mClockView;
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.activity_main);
27 | setAmbientEnabled();
28 |
29 | mContainerView = (BoxInsetLayout) findViewById(R.id.container);
30 | mTextView = (TextView) findViewById(R.id.tv_info);
31 | mClockView = (TextView) findViewById(R.id.clock);
32 | }
33 |
34 | @Override
35 | public void onEnterAmbient(Bundle ambientDetails) {
36 | super.onEnterAmbient(ambientDetails);
37 | updateDisplay();
38 | }
39 |
40 | @Override
41 | public void onUpdateAmbient() {
42 | super.onUpdateAmbient();
43 | updateDisplay();
44 | }
45 |
46 | @Override
47 | public void onExitAmbient() {
48 | updateDisplay();
49 | super.onExitAmbient();
50 | }
51 |
52 | private void updateDisplay() {
53 | if (isAmbient()) {
54 | mContainerView.setBackgroundColor(getResources().getColor(android.R.color.black));
55 | mTextView.setTextColor(getResources().getColor(android.R.color.white));
56 | mClockView.setVisibility(View.VISIBLE);
57 |
58 | mClockView.setText(AMBIENT_DATE_FORMAT.format(new Date()));
59 | } else {
60 | mContainerView.setBackground(null);
61 | mTextView.setTextColor(getResources().getColor(android.R.color.black));
62 | mClockView.setVisibility(View.GONE);
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/weardata_collector/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
17 |
18 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/weardata_collector/src/main/res/layout/activity_main2.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
--------------------------------------------------------------------------------
/weardata_collector/src/main/res/layout/rect_activity_main2.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
--------------------------------------------------------------------------------
/weardata_collector/src/main/res/layout/round_activity_main2.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
17 |
18 |
27 |
28 |
36 |
37 |
--------------------------------------------------------------------------------
/weardata_collector/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/weardata_collector/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/weardata_collector/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/weardata_collector/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/weardata_collector/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/weardata_collector/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/weardata_collector/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeoCai/Multi-Sensor-DataCollector/5a9169dc3e865e2d26ec4dbc8b7209ba611b4e3a/weardata_collector/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/weardata_collector/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | WearData
3 | Hello World!
4 | Main2Activity
5 | Hello Round World!
6 | Hello Square World!
7 |
8 |
--------------------------------------------------------------------------------