├── .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 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 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 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /HelloWear.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 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 | 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 |