diff --git a/.gitignore b/.gitignore
index 56cc642..3a16b7b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,85 +1,9 @@
-# Built application files
-*.apk
-*.aar
-*.ap_
-*.aab
-
-# Files for the ART/Dalvik VM
-*.dex
-
-# Java class files
-*.class
-
-# Generated files
-bin/
-gen/
-out/
-# Uncomment the following line in case you need and you don't have the release build type files in your app
-# release/
-
-# Gradle files
-.gradle/
-build/
-
-# Local configuration file (sdk path, etc)
-local.properties
-
-# Proguard folder generated by Eclipse
-proguard/
-
-# Log Files
-*.log
-
-# Android Studio Navigation editor temp files
-.navigation/
-
-# Android Studio captures folder
-captures/
-
-# IntelliJ
*.iml
-.idea/workspace.xml
-.idea/tasks.xml
-.idea/gradle.xml
-.idea/assetWizardSettings.xml
-.idea/dictionaries
-.idea/libraries
-# Android Studio 3 in .gitignore file.
-.idea/caches
-.idea/modules.xml
-# Comment next line if keeping position of elements in Navigation Editor is relevant for you
-.idea/navEditor.xml
-
-# Keystore files
-# Uncomment the following lines if you do not want to check your keystore files in.
-#*.jks
-#*.keystore
-
-# External native build folder generated in Android Studio 2.2 and later
+.gradle
+/local.properties
+.idea
+.DS_Store
+/build
+/captures
.externalNativeBuild
-.cxx/
-
-# Google Services (e.g. APIs or Firebase)
-# google-services.json
-
-# Freeline
-freeline.py
-freeline/
-freeline_project_description.json
-
-# fastlane
-fastlane/report.xml
-fastlane/Preview.html
-fastlane/screenshots
-fastlane/test_output
-fastlane/readme.md
-
-# Version control
-vcs.xml
-
-# lint
-lint/intermediates/
-lint/generated/
-lint/outputs/
-lint/tmp/
-# lint/reports/
+.cxx
\ No newline at end of file
diff --git a/app/.gitignore b/app/.gitignore
new file mode 100644
index 0000000..796b96d
--- /dev/null
+++ b/app/.gitignore
@@ -0,0 +1 @@
+/build
diff --git a/app/build.gradle b/app/build.gradle
new file mode 100644
index 0000000..3d917f5
--- /dev/null
+++ b/app/build.gradle
@@ -0,0 +1,31 @@
+apply plugin: 'com.android.application'
+
+android {
+ compileSdkVersion 28
+ buildToolsVersion "28.0.3"
+
+ defaultConfig {
+ applicationId "cn.qd.peiwen.demo"
+ minSdkVersion 19
+ targetSdkVersion 28
+ versionCode 1
+ versionName "1.0"
+ }
+
+ buildTypes {
+ release {
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
+ }
+ }
+
+}
+
+dependencies {
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
+ implementation project(path: ':pwc02incubatormodule')
+ implementation 'com.github.bingfeng1225:PWSerialPort:1.1.5'
+
+ implementation 'androidx.appcompat:appcompat:1.2.0'
+ implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
+}
diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro
new file mode 100644
index 0000000..f1b4245
--- /dev/null
+++ b/app/proguard-rules.pro
@@ -0,0 +1,21 @@
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..f62af34
--- /dev/null
+++ b/app/src/main/AndroidManifest.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/cn/qd/peiwen/demo/MainActivity.java b/app/src/main/java/cn/qd/peiwen/demo/MainActivity.java
new file mode 100644
index 0000000..e485583
--- /dev/null
+++ b/app/src/main/java/cn/qd/peiwen/demo/MainActivity.java
@@ -0,0 +1,69 @@
+package cn.qd.peiwen.demo;
+
+import androidx.appcompat.app.AppCompatActivity;
+import cn.haier.bio.medical.incubator.c02.C02IncubatorManager;
+import cn.haier.bio.medical.incubator.c02.IC02IncubatorListener;
+import cn.qd.peiwen.serialport.PWSerialPort;
+
+import android.os.Build;
+import android.os.Bundle;
+import android.util.Log;
+
+public class MainActivity extends AppCompatActivity implements IC02IncubatorListener {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+ String path = "/dev/ttyS4";
+ if ("magton".equals(Build.MODEL)) {
+ path = "/dev/ttyS2";
+ }
+ C02IncubatorManager.getInstance().init(path);
+ C02IncubatorManager.getInstance().changeListener(this);
+ C02IncubatorManager.getInstance().enable();
+ }
+
+ @Override
+ public void onC02IncubatorReady() {
+
+ }
+
+ @Override
+ public void onC02IncubatorConnected() {
+
+ }
+
+ @Override
+ public void onC02IncubatorSwitchWriteModel() {
+ if (!"magton".equals(Build.MODEL)) {
+ PWSerialPort.writeFile("/sys/class/gpio/gpio24/value", "0");
+ } else {
+ PWSerialPort.writeFile("/sys/class/misc/sunxi-acc/acc/sochip_acc", "1");
+ }
+ }
+
+ @Override
+ public void onC02IncubatorSwitchReadModel() {
+ if (!"magton".equals(Build.MODEL)) {
+ PWSerialPort.writeFile("/sys/class/gpio/gpio24/value", "1");
+ } else {
+ PWSerialPort.writeFile("/sys/class/misc/sunxi-acc/acc/sochip_acc", "0");
+ }
+ }
+
+ @Override
+ public void onC02IncubatorPrint(String message) {
+ Log.e("TAG","" + message);
+ }
+
+ @Override
+ public void onC02IncubatorException(Throwable throwable) {
+
+ }
+
+ @Override
+ public void onC02IncubatorPackageReceived(byte[] data) {
+
+ }
+}
diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml
new file mode 100644
index 0000000..2b068d1
--- /dev/null
+++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml
new file mode 100644
index 0000000..07d5da9
--- /dev/null
+++ b/app/src/main/res/drawable/ic_launcher_background.xml
@@ -0,0 +1,170 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
new file mode 100644
index 0000000..4fc2444
--- /dev/null
+++ b/app/src/main/res/layout/activity_main.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
new file mode 100644
index 0000000..eca70cf
--- /dev/null
+++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
new file mode 100644
index 0000000..eca70cf
--- /dev/null
+++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png
new file mode 100644
index 0000000..a571e60
Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
new file mode 100644
index 0000000..61da551
Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png differ
diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png
new file mode 100644
index 0000000..c41dd28
Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
new file mode 100644
index 0000000..db5080a
Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png differ
diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..6dba46d
Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
new file mode 100644
index 0000000..da31a87
Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ
diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
new file mode 100644
index 0000000..15ac681
Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
new file mode 100644
index 0000000..b216f2d
Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ
diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
new file mode 100644
index 0000000..f25a419
Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
new file mode 100644
index 0000000..e96783c
Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
new file mode 100644
index 0000000..030098f
--- /dev/null
+++ b/app/src/main/res/values/colors.xml
@@ -0,0 +1,6 @@
+
+
+ #6200EE
+ #3700B3
+ #03DAC5
+
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
new file mode 100644
index 0000000..644a7c9
--- /dev/null
+++ b/app/src/main/res/values/strings.xml
@@ -0,0 +1,3 @@
+
+ App
+
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
new file mode 100644
index 0000000..5885930
--- /dev/null
+++ b/app/src/main/res/values/styles.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
diff --git a/build.gradle b/build.gradle
new file mode 100644
index 0000000..4ac3884
--- /dev/null
+++ b/build.gradle
@@ -0,0 +1,25 @@
+buildscript {
+ repositories {
+ google()
+ jcenter()
+ maven { url 'https://jitpack.io' }
+ }
+ dependencies {
+ classpath 'com.android.tools.build:gradle:3.5.0'
+ classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
+ // NOTE: Do not place your application dependencies here; they belong
+ // in the individual module build.gradle files
+ }
+}
+
+allprojects {
+ repositories {
+ google()
+ jcenter()
+ maven { url 'https://jitpack.io' }
+ }
+}
+
+task clean(type: Delete) {
+ delete rootProject.buildDir
+}
\ No newline at end of file
diff --git a/gradle.properties b/gradle.properties
new file mode 100644
index 0000000..199d16e
--- /dev/null
+++ b/gradle.properties
@@ -0,0 +1,20 @@
+# Project-wide Gradle settings.
+# IDE (e.g. Android Studio) users:
+# Gradle settings configured through the IDE *will override*
+# any settings specified in this file.
+# For more details on how to configure your build environment visit
+# http://www.gradle.org/docs/current/userguide/build_environment.html
+# Specifies the JVM arguments used for the daemon process.
+# The setting is particularly useful for tweaking memory settings.
+org.gradle.jvmargs=-Xmx1536m
+# When configured, Gradle will run in incubating parallel mode.
+# This option should only be used with decoupled projects. More details, visit
+# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
+# org.gradle.parallel=true
+# AndroidX package structure to make it clearer which packages are bundled with the
+# Android operating system, and which are packaged with your app's APK
+# https://developer.android.com/topic/libraries/support-library/androidx-rn
+android.useAndroidX=true
+# Automatically convert third-party libraries to use AndroidX
+android.enableJetifier=true
+
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..f6b961f
Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..74f6737
--- /dev/null
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Thu Mar 12 09:18:23 CST 2020
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
diff --git a/gradlew b/gradlew
new file mode 100755
index 0000000..cccdd3d
--- /dev/null
+++ b/gradlew
@@ -0,0 +1,172 @@
+#!/usr/bin/env sh
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn () {
+ echo "$*"
+}
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+ NONSTOP* )
+ nonstop=true
+ ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+ JAVACMD=`cygpath --unix "$JAVACMD"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Escape application args
+save () {
+ for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
+ echo " "
+}
+APP_ARGS=$(save "$@")
+
+# Collect all arguments for the java command, following the shell quoting and substitution rules
+eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
+
+# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
+if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
+ cd "$(dirname "$0")"
+fi
+
+exec "$JAVACMD" "$@"
diff --git a/gradlew.bat b/gradlew.bat
new file mode 100644
index 0000000..f955316
--- /dev/null
+++ b/gradlew.bat
@@ -0,0 +1,84 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windows variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/pwc02incubatormodule/.gitignore b/pwc02incubatormodule/.gitignore
new file mode 100644
index 0000000..796b96d
--- /dev/null
+++ b/pwc02incubatormodule/.gitignore
@@ -0,0 +1 @@
+/build
diff --git a/pwc02incubatormodule/build.gradle b/pwc02incubatormodule/build.gradle
new file mode 100644
index 0000000..fe29f90
--- /dev/null
+++ b/pwc02incubatormodule/build.gradle
@@ -0,0 +1,30 @@
+apply plugin: 'com.android.library'
+apply plugin: 'com.github.dcendents.android-maven'
+group='com.github.bingfeng1225'
+
+android {
+ compileSdkVersion 28
+ buildToolsVersion "28.0.3"
+
+
+ defaultConfig {
+ minSdkVersion 19
+ targetSdkVersion 28
+ versionCode 1
+ versionName "1.0"
+ }
+
+ buildTypes {
+ release {
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
+ }
+ }
+
+}
+
+dependencies {
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
+ implementation 'com.github.bingfeng1225:PWSerialPort:1.1.5'
+ implementation group: 'io.netty', name: 'netty-all', version: '4.1.43.Final'
+}
diff --git a/pwc02incubatormodule/consumer-rules.pro b/pwc02incubatormodule/consumer-rules.pro
new file mode 100644
index 0000000..e69de29
diff --git a/pwc02incubatormodule/proguard-rules.pro b/pwc02incubatormodule/proguard-rules.pro
new file mode 100644
index 0000000..f1b4245
--- /dev/null
+++ b/pwc02incubatormodule/proguard-rules.pro
@@ -0,0 +1,21 @@
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile
diff --git a/pwc02incubatormodule/src/main/AndroidManifest.xml b/pwc02incubatormodule/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..f9d8deb
--- /dev/null
+++ b/pwc02incubatormodule/src/main/AndroidManifest.xml
@@ -0,0 +1,2 @@
+
diff --git a/pwc02incubatormodule/src/main/java/cn/haier/bio/medical/incubator/c02/C02IncubatorManager.java b/pwc02incubatormodule/src/main/java/cn/haier/bio/medical/incubator/c02/C02IncubatorManager.java
new file mode 100644
index 0000000..7ab6874
--- /dev/null
+++ b/pwc02incubatormodule/src/main/java/cn/haier/bio/medical/incubator/c02/C02IncubatorManager.java
@@ -0,0 +1,63 @@
+package cn.haier.bio.medical.incubator.c02;
+
+/***
+ * 超低温变频、T系列、双系统主控板通讯
+ *
+ */
+public class C02IncubatorManager {
+ private C02IncubatorSerialPort serialPort;
+ private static C02IncubatorManager manager;
+
+ public static C02IncubatorManager getInstance() {
+ if (manager == null) {
+ synchronized (C02IncubatorManager.class) {
+ if (manager == null)
+ manager = new C02IncubatorManager();
+ }
+ }
+ return manager;
+ }
+
+ private C02IncubatorManager() {
+
+ }
+
+ public void init(String path) {
+ if(this.serialPort == null){
+ this.serialPort = new C02IncubatorSerialPort();
+ this.serialPort.init(path);
+ }
+ }
+
+ public void enable() {
+ if(null != this.serialPort){
+ this.serialPort.enable();
+ }
+ }
+
+ public void disable() {
+ if(null != this.serialPort){
+ this.serialPort.disable();
+ }
+ }
+
+ public void release() {
+ if(null != this.serialPort){
+ this.serialPort.release();
+ this.serialPort = null;
+ }
+ }
+
+ public void sendData(byte[] data) {
+ if (null != this.serialPort) {
+ this.serialPort.sendData(data);
+ }
+ }
+
+ public void changeListener(IC02IncubatorListener listener) {
+ if(null != this.serialPort){
+ this.serialPort.changeListener(listener);
+ }
+ }
+}
+
diff --git a/pwc02incubatormodule/src/main/java/cn/haier/bio/medical/incubator/c02/C02IncubatorSerialPort.java b/pwc02incubatormodule/src/main/java/cn/haier/bio/medical/incubator/c02/C02IncubatorSerialPort.java
new file mode 100644
index 0000000..30894bc
--- /dev/null
+++ b/pwc02incubatormodule/src/main/java/cn/haier/bio/medical/incubator/c02/C02IncubatorSerialPort.java
@@ -0,0 +1,284 @@
+package cn.haier.bio.medical.incubator.c02;
+
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.os.Looper;
+import android.os.Message;
+
+import java.io.IOException;
+import java.lang.ref.WeakReference;
+
+import cn.qd.peiwen.serialport.PWSerialPortHelper;
+import cn.qd.peiwen.serialport.PWSerialPortListener;
+import cn.qd.peiwen.serialport.PWSerialPortState;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+
+class C02IncubatorSerialPort implements PWSerialPortListener {
+ private ByteBuf buffer;
+ private HandlerThread thread;
+ private PWSerialPortHelper helper;
+ private C02IncubatorHandler handler;
+
+ private boolean ready = false;
+ private boolean enabled = false;
+ private WeakReference listener;
+
+ public C02IncubatorSerialPort() {
+ }
+
+ public void init(String path) {
+ this.createHandler();
+ this.createHelper(path);
+ this.createBuffer();
+ }
+
+ public void enable() {
+ if (this.isInitialized() && !this.enabled) {
+ this.enabled = true;
+ this.helper.open();
+ }
+ }
+
+ public void disable() {
+ if (this.isInitialized() && this.enabled) {
+ this.enabled = false;
+ this.helper.close();
+ }
+ }
+
+ public void release() {
+ this.listener = null;
+ this.destoryHandler();
+ this.destoryHelper();
+ this.destoryBuffer();
+ }
+
+ public void sendData(byte[] data) {
+ if (this.isInitialized() && this.enabled) {
+ Message msg = Message.obtain();
+ msg.what = 0x00;
+ msg.obj = data;
+ this.handler.sendMessage(msg);
+ }
+ }
+
+ public void changeListener(IC02IncubatorListener listener) {
+ this.listener = new WeakReference<>(listener);
+ }
+
+ private boolean isInitialized() {
+ if (this.handler == null) {
+ return false;
+ }
+ if (this.helper == null) {
+ return false;
+ }
+ return this.buffer != null;
+ }
+
+ private void createHelper(String path) {
+ if (this.helper == null) {
+ this.helper = new PWSerialPortHelper("C02IncubatorSerialPort");
+ this.helper.setTimeout(5);
+ this.helper.setPath(path);
+ this.helper.setBaudrate(9600);
+ this.helper.init(this);
+ }
+ }
+
+ private void destoryHelper() {
+ if (null != this.helper) {
+ this.helper.release();
+ this.helper = null;
+ }
+ }
+
+ private void createHandler() {
+ if (this.thread == null && this.handler == null) {
+ this.thread = new HandlerThread("C02IncubatorSerialPort");
+ this.thread.start();
+ this.handler = new C02IncubatorHandler(this.thread.getLooper());
+ }
+ }
+
+ private void destoryHandler() {
+ if (null != this.thread) {
+ this.thread.quitSafely();
+ this.thread = null;
+ this.handler = null;
+ }
+ }
+
+ private void createBuffer() {
+ if (this.buffer == null) {
+ this.buffer = Unpooled.buffer(4);
+ }
+ }
+
+ private void destoryBuffer() {
+ if (null != this.buffer) {
+ this.buffer.release();
+ this.buffer = null;
+ }
+ }
+
+ private void write(byte[] data) {
+ if (!this.isInitialized() || !this.enabled) {
+ return;
+ }
+ this.helper.writeAndFlush(data);
+ if (null != this.listener && null != this.listener.get()) {
+ this.listener.get().onC02IncubatorPrint("C02IncubatorSerialPort Send:" + C02IncubatorTools.bytes2HexString(data, true, ", "));
+ }
+ }
+
+ private void switchReadModel() {
+ if (null != this.listener && null != this.listener.get()) {
+ this.listener.get().onC02IncubatorSwitchReadModel();
+ }
+ }
+
+ private void switchWriteModel() {
+ if (null != this.listener && null != this.listener.get()) {
+ this.listener.get().onC02IncubatorSwitchWriteModel();
+ }
+ }
+
+ private boolean ignorePackage() {
+ boolean result = false;
+ int index = C02IncubatorTools.indexOf(this.buffer, C02IncubatorTools.HEADER);
+ if (index != -1) {
+ result = true;
+ byte[] data = new byte[index];
+ this.buffer.readBytes(data, 0, data.length);
+ this.buffer.discardReadBytes();
+ if (null != this.listener && null != this.listener.get()) {
+ this.listener.get().onC02IncubatorPrint("C02IncubatorSerialPort 指令丢弃:" + C02IncubatorTools.bytes2HexString(data, true, ", "));
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public void onConnected(PWSerialPortHelper helper) {
+ if (!this.isInitialized() || !helper.equals(this.helper)) {
+ return;
+ }
+ this.ready = false;
+ this.buffer.clear();
+ this.switchReadModel();
+ if (null != this.listener && null != this.listener.get()) {
+ this.listener.get().onC02IncubatorConnected();
+ }
+ }
+
+ @Override
+ public void onReadThreadReleased(PWSerialPortHelper helper) {
+ if (!this.isInitialized() || !helper.equals(this.helper)) {
+ return;
+ }
+ if (null != this.listener && null != this.listener.get()) {
+ this.listener.get().onC02IncubatorPrint("C02IncubatorSerialPort read thread released");
+ }
+ }
+
+ @Override
+ public void onException(PWSerialPortHelper helper, Throwable throwable) {
+ if (!this.isInitialized() || !helper.equals(this.helper)) {
+ return;
+ }
+ this.ready = false;
+ if (null != this.listener && null != this.listener.get()) {
+ this.listener.get().onC02IncubatorException(throwable);
+ }
+ }
+
+ @Override
+ public void onStateChanged(PWSerialPortHelper helper, PWSerialPortState state) {
+ if (!this.isInitialized() || !helper.equals(this.helper)) {
+ return;
+ }
+ if (null != this.listener && null != this.listener.get()) {
+ this.listener.get().onC02IncubatorPrint("C02IncubatorSerialPort state changed: " + state.name());
+ }
+ }
+
+ @Override
+ public void onByteReceived(PWSerialPortHelper helper, byte[] buffer, int length) throws IOException {
+ if (!this.isInitialized() || !helper.equals(this.helper)) {
+ return;
+ }
+ this.buffer.writeBytes(buffer, 0, length);
+ while (this.buffer.readableBytes() >= 4) {
+ byte[] header = new byte[C02IncubatorTools.HEADER.length];
+ this.buffer.getBytes(0, header);
+ byte command = this.buffer.getByte(3);
+ if (!C02IncubatorTools.checkHeader(header) || !C02IncubatorTools.checkCommand(command)) {
+ if (this.ignorePackage()) {
+ continue;
+ } else {
+ break;
+ }
+ }
+ int frameLength = 0xFF & this.buffer.getByte(2) + 3;
+ if (this.buffer.readableBytes() < frameLength) {
+ break;
+ }
+ this.buffer.markReaderIndex();
+ byte[] data = new byte[frameLength];
+ this.buffer.readBytes(data, 0, data.length);
+
+ if (!C02IncubatorTools.checkFrame(data)) {
+ this.buffer.resetReaderIndex();
+ //当前包不合法 丢掉正常的包头以免重复判断
+ this.buffer.skipBytes(4);
+ this.buffer.discardReadBytes();
+ continue;
+ }
+ this.buffer.discardReadBytes();
+ if (!this.ready) {
+ this.ready = true;
+ if (null != this.listener && null != this.listener.get()) {
+ this.listener.get().onC02IncubatorReady();
+ }
+ }
+ this.switchWriteModel();
+ if (null != this.listener && null != this.listener.get()) {
+ this.listener.get().onC02IncubatorPrint("C02IncubatorSerialPort Recv:" + C02IncubatorTools.bytes2HexString(data, true, ", "));
+ }
+ Message msg = Message.obtain();
+ msg.obj = data;
+ msg.what = 0x01;
+ this.handler.sendMessage(msg);
+ }
+ }
+
+
+ private class C02IncubatorHandler extends Handler {
+ public C02IncubatorHandler(Looper looper) {
+ super(looper);
+ }
+
+ @Override
+ public void handleMessage(Message msg) {
+ super.handleMessage(msg);
+ switch (msg.what) {
+ case 0: {
+ byte[] message = (byte[]) msg.obj;
+ if (null != message && message.length > 0) {
+ C02IncubatorSerialPort.this.write(message);
+ }
+ C02IncubatorSerialPort.this.switchReadModel();
+ break;
+ }
+ case 0x01:
+ if (null != C02IncubatorSerialPort.this.listener && null != C02IncubatorSerialPort.this.listener.get()) {
+ C02IncubatorSerialPort.this.listener.get().onC02IncubatorPackageReceived( (byte[]) msg.obj);
+ }
+ break;
+ }
+
+ }
+ }
+}
diff --git a/pwc02incubatormodule/src/main/java/cn/haier/bio/medical/incubator/c02/C02IncubatorTools.java b/pwc02incubatormodule/src/main/java/cn/haier/bio/medical/incubator/c02/C02IncubatorTools.java
new file mode 100644
index 0000000..c58f124
--- /dev/null
+++ b/pwc02incubatormodule/src/main/java/cn/haier/bio/medical/incubator/c02/C02IncubatorTools.java
@@ -0,0 +1,137 @@
+package cn.haier.bio.medical.incubator.c02;
+
+
+import java.util.Arrays;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+
+class C02IncubatorTools {
+
+ public static final byte[] HEADER = {(byte) 0xAA, (byte) 0x55};
+ public static final byte[] COMMANDS = {(byte) 0x21, (byte) 0x22};
+
+ public static boolean checkHeader(byte[] header) {
+ return Arrays.equals(HEADER, header);
+ }
+
+ public static boolean checkFrame(byte[] data) {
+ byte[] crc = new byte[]{data[data.length - 2], data[data.length - 1]};
+ byte[] check = computeCRC16Code(data, 2, data.length - 4);
+ return Arrays.equals(crc, check);
+ }
+
+ public static boolean checkCommand(byte command) {
+ for (byte item : COMMANDS) {
+ if (item == command) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static byte[] short2Bytes(short value) {
+ byte bytes[] = new byte[2];
+ bytes[0] = (byte) (0xff & (value >> 8));
+ bytes[1] = (byte) (0xff & value);
+ return bytes;
+ }
+
+ public static String bytes2HexString(byte[] data, boolean hexFlag, String separator) {
+ if (data == null) {
+ throw new IllegalArgumentException("The data can not be blank");
+ }
+ return bytes2HexString(data, 0, data.length, hexFlag, separator);
+ }
+
+ public static String bytes2HexString(byte[] data, int offset, int len, boolean hexFlag, String separator) {
+ if (data == null) {
+ throw new IllegalArgumentException("The data can not be blank");
+ }
+ if (offset < 0 || offset > data.length - 1) {
+ throw new IllegalArgumentException("The offset index out of bounds");
+ }
+ if (len < 0 || offset + len > data.length) {
+ throw new IllegalArgumentException("The len can not be < 0 or (offset + len) index out of bounds");
+ }
+ String format = "%02X";
+ if (hexFlag) {
+ format = "0x%02X";
+ }
+ StringBuffer buffer = new StringBuffer();
+ for (int i = offset; i < offset + len; i++) {
+ buffer.append(String.format(format, data[i]));
+ if (separator == null) {
+ continue;
+ }
+ if (i != (offset + len - 1)) {
+ buffer.append(separator);
+ }
+ }
+ return buffer.toString();
+ }
+
+ public static byte[] computeCRC16Code(byte[] data, int offset, int len) {
+ if (data == null) {
+ throw new IllegalArgumentException("The data can not be blank");
+ }
+ if (offset < 0 || offset > data.length - 1) {
+ throw new IllegalArgumentException("The offset index out of bounds");
+ }
+ if (len < 0 || offset + len > data.length) {
+ throw new IllegalArgumentException("The len can not be < 0 or (offset + len) index out of bounds");
+ }
+ int crc = 0xFFFF;
+ for (int pos = offset; pos < offset + len; pos++) {
+ if (data[pos] < 0) {
+ crc ^= (int) data[pos] + 256; // XOR byte into least sig. byte of
+ // crc
+ } else {
+ crc ^= (int) data[pos]; // XOR byte into least sig. byte of crc
+ }
+ for (int i = 8; i != 0; i--) { // Loop over each bit
+ if ((crc & 0x0001) != 0) { // If the LSB is set
+ crc >>= 1; // Shift right and XOR 0xA001
+ crc ^= 0x8408;
+ } else {
+ // Else LSB is not set
+ crc >>= 1; // Just shift right
+ }
+ }
+ }
+
+ return short2Bytes((short) crc);
+ }
+
+ public static int indexOf(ByteBuf haystack, byte[] needle) {
+ //遍历haystack的每一个字节
+ for (int i = haystack.readerIndex(); i < haystack.writerIndex(); i++) {
+ int needleIndex;
+ int haystackIndex = i;
+ /*haystack是否出现了delimiter,注意delimiter是一个ChannelBuffer(byte[])
+ 例如对于haystack="ABC\r\nDEF",needle="\r\n"
+ 那么当haystackIndex=3时,找到了“\r”,此时needleIndex=0
+ 继续执行循环,haystackIndex++,needleIndex++,
+ 找到了“\n”
+ 至此,整个needle都匹配到了
+ 程序然后执行到if (needleIndex == needle.capacity()),返回结果
+ */
+ for (needleIndex = 0; needleIndex < needle.length; needleIndex++) {
+ if (haystack.getByte(haystackIndex) != needle[needleIndex]) {
+ break;
+ } else {
+ haystackIndex++;
+ if (haystackIndex == haystack.writerIndex() && needleIndex != needle.length - 1) {
+ return -1;
+ }
+ }
+ }
+
+ if (needleIndex == needle.length) {
+ // Found the needle from the haystack!
+ return i - haystack.readerIndex();
+ }
+ }
+ return -1;
+ }
+}
diff --git a/pwc02incubatormodule/src/main/java/cn/haier/bio/medical/incubator/c02/IC02IncubatorListener.java b/pwc02incubatormodule/src/main/java/cn/haier/bio/medical/incubator/c02/IC02IncubatorListener.java
new file mode 100644
index 0000000..354ca2e
--- /dev/null
+++ b/pwc02incubatormodule/src/main/java/cn/haier/bio/medical/incubator/c02/IC02IncubatorListener.java
@@ -0,0 +1,17 @@
+package cn.haier.bio.medical.incubator.c02;
+
+public interface IC02IncubatorListener {
+ void onC02IncubatorReady();
+
+ void onC02IncubatorConnected();
+
+ void onC02IncubatorSwitchWriteModel();
+
+ void onC02IncubatorSwitchReadModel();
+
+ void onC02IncubatorPrint(String message);
+
+ void onC02IncubatorException(Throwable throwable);
+
+ void onC02IncubatorPackageReceived(byte[] data);
+}
diff --git a/settings.gradle b/settings.gradle
new file mode 100644
index 0000000..dec0007
--- /dev/null
+++ b/settings.gradle
@@ -0,0 +1,2 @@
+include ':app'
+include ':pwc02incubatormodule'