commit cd6b4559bc88ccb38392ef477ce254b6cff71d40 Author: zwf Date: Tue Sep 3 08:41:23 2024 +0800 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f0c20a1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,77 @@ +# Built application files +*.apk +*.ap_ +*.aab + +# Files for the ART/Dalvik VM +*.dex + +# Java class files +*.class + +# Generated files +bin/ +gen/ +out/ + +# 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 +.idea/caches + +# 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 +.externalNativeBuild + +# 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/ diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..ae78c11 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,113 @@ + + + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + + ^$ + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .* + + http://schemas.android.com/apk/res/android + + + ANDROID_ATTRIBUTE_ORDER + +
+
+ + + + .* + + .* + + + BY_NAME + +
+
+
+
+
+
\ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..61a9130 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml new file mode 100644 index 0000000..b268ef3 --- /dev/null +++ b/.idea/deploymentTargetSelector.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/migrations.xml b/.idea/migrations.xml new file mode 100644 index 0000000..f8051a6 --- /dev/null +++ b/.idea/migrations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..3378229 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..a3ad9ad --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/other.xml b/.idea/other.xml new file mode 100644 index 0000000..94c96f6 --- /dev/null +++ b/.idea/other.xml @@ -0,0 +1,318 @@ + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/Apk/1-SystemCore_v4.9.9_9.zip b/Apk/1-SystemCore_v4.9.9_9.zip new file mode 100644 index 0000000..f76a56a Binary files /dev/null and b/Apk/1-SystemCore_v4.9.9_9.zip differ diff --git a/README.en.md b/README.en.md new file mode 100644 index 0000000..5003802 --- /dev/null +++ b/README.en.md @@ -0,0 +1,36 @@ +# display2.0 + +#### Description +重构display + +#### Software Architecture +Software architecture description + +#### Installation + +1. xxxx +2. xxxx +3. xxxx + +#### Instructions + +1. xxxx +2. xxxx +3. xxxx + +#### Contribution + +1. Fork the repository +2. Create Feat_xxx branch +3. Commit your code +4. Create Pull Request + + +#### Gitee Feature + +1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md +2. Gitee blog [blog.gitee.com](https://blog.gitee.com) +3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) +4. The most valuable open source project [GVP](https://gitee.com/gvp) +5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) +6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/README.md b/README.md new file mode 100644 index 0000000..853d910 --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# display2.0 + +#### 介绍 +重构display + +#### 软件架构 +软件架构说明 + + +#### 更新日志 +2.0_v_0.1:重构第一版 +2.0_v_0.2:兼容所有需要用到display的设备 +2.0_v_0.3:修复M60不显示,需要启动时重启千兆网 +2.0_v_0.4:1.优化通讯,找卡 + 2.完善巡检功能 +2.0_v_0.5:1.增加参数备份恢复功能 +2.0_v_0.7:1.修复fpga类型的接收卡升级程序失败 +2.0_v_0.8:1.修复T6类型接收卡参数恢复,字体花屏问题 + 2.修复fpga类型的接收卡无法恢复参数问题 +2.0_v_0.9:1.修复4.0找卡不稳定问题 +2.0_v_1.1:1.anlu芯片fpga升级 +2021.3.21 2.0_v_1.2 修复M60fpga版本查询 +2021.3.22 2.0_v_1.3 尝试优化M60千兆网口不显示 + diff --git a/TestData.txt b/TestData.txt new file mode 100644 index 0000000..3f9ac6f --- /dev/null +++ b/TestData.txt @@ -0,0 +1,17 @@ +测试数据 +1.显示颜色块 +帧头 协议类型 命令类型 应答位 长度 数据域 CRC校验 +7e 7e 55 01 01 00 0c 00 00 00 00 00 00 80 00 40 00 FF 00 00 AA BB CC DD + +2.画线 +帧头 协议类型 命令类型 应答位 长度 数据域 CRC校验 +7e 7e 55 01 01 00 19 00 02 00 00 00 00 80 00 40 00 00 00 00 01 00 FF FF 01 00 00 00 00 80 07 38 04 AA BB CC DD +7E 7E 55 01 01 01 19 00 02 00 00 00 00 00 40 00 40 00 00 00 02 FF FF FF 01 00 00 00 00 00 00 00 00 ED 96 5D 7A +7E 7E 55 01 01 01 22 00 02 00 00 00 00 00 40 00 40 00 00 00 02 FF FF FF 01 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 82 17 AD D7 + +7e 7e 55 01 01 00 19 00 02 00 00 00 00 80 00 40 00 00 00 00 01 FF FF FF 01 00 00 00 00 0E 00 00 00 AA BB CC DD +7e 7e 55 01 01 00 19 00 02 00 00 00 00 80 00 40 00 00 00 00 01 FF FF FF 01 00 00 00 00 0D 00 00 00 AA BB CC DD +2.查询版本 +帧头 协议类型 命令类型 应答位 长度 数据域 CRC校验 +7e 7e 55 01 02 01 00 00 F5 E5 47 AA AA BB CC DD +回7E 7E 55 01 02 00 04 00 63 00 01 02 D4 F9 8E 55 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..43b2613 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,93 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 26 + buildToolsVersion "26.0.0" + defaultConfig { + applicationId "com.xixun.display" + minSdkVersion 15 + targetSdkVersion 26 + versionCode 104 + versionName "2.0_v_4.1" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + ndk { + abiFilters "armeabi-v7a" + + } + } + signingConfigs { + Display { + keyAlias 'xixuncard' + keyPassword '66399266' + storeFile file('D:\\develop\\data\\data\\display\\SignKey_Sysolution.jks') + storePassword '66399266' + } + C {//49.1 + keyAlias 'xixun' + keyPassword '123456' + storeFile file('D:/develop/xixun/signedFile/keystore/xixun-c.keystore') + storePassword '123456' + } + D {//3288 + keyAlias 'xixun' + keyPassword '123456' + storeFile file('D:/develop/xixun/signedFile/keystore/xixun-d.keystore') + storePassword '123456' + } + M {//meige + keyAlias 'xixun' + keyPassword '123456' + storeFile file('D:/develop/xixun/signedFile/keystore/xixun-m.keystore') + storePassword '123456' + } + } +// xixuncard 66399266 + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + signingConfig signingConfigs.C + } + debug { + signingConfig signingConfigs.C + } + } + compileOptions { + targetCompatibility = 1.8 + sourceCompatibility = 1.8 + } + android.applicationVariants.all { variant -> + variant.outputs.all { output -> + def outputFile = output.outputFile + if (outputFile != null && outputFile.name.endsWith('.apk')) { +// outputFileName = "display${defaultConfig.versionName}-Y08.apk" + outputFileName = "display${defaultConfig.versionName}-C-M7s.apk" +// outputFileName = "/home/joey/work/app/card-system/system-core/ralease/" + fileName + } + } + } + /*sourceSets { + main { + jniLibs.srcDirs = ['libs'] + } + }*/ +} + +dependencies { + //compile 'com.android.support:multidex:1.0.1' + implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation 'com.android.support:appcompat-v7:26.1.0' + implementation 'com.android.support.constraint:constraint-layout:1.0.2' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'com.android.support.test:runner:1.0.1' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' + implementation files('libs/task_dto5.jar') + // implementation files('libs/xixun_card_setting_1.2.2.jar') + //implementation files('libs/org.apache.commons.codec-1.8.jar') + implementation 'com.koushikdutta.async:androidasync:2.2.1' + implementation files('src/main/java/libs/gson-2.2.4.jar') + implementation files('libs/jackson.jar') + // implementation files('libs/xixun_card_setting_1.2.2.jar') + implementation files('libs/xixun_alahover.jar') + implementation files('libs/zip4j_1.3.1.jar') +} diff --git a/app/debug/output.json b/app/debug/output.json new file mode 100644 index 0000000..a2af169 --- /dev/null +++ b/app/debug/output.json @@ -0,0 +1 @@ +[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":99,"versionName":"2.0_v_3.0_t","enabled":true,"outputFile":"display2.0_v_3.0_t-ralease.apk","fullName":"debug","baseName":"debug"},"path":"display2.0_v_3.0_t-ralease.apk","properties":{}}] \ No newline at end of file diff --git a/app/libs/armeabi-v7a/libFrameBuffer.so b/app/libs/armeabi-v7a/libFrameBuffer.so new file mode 100644 index 0000000..5e46981 Binary files /dev/null and b/app/libs/armeabi-v7a/libFrameBuffer.so differ diff --git a/app/libs/armeabi-v7a/libMulti.so b/app/libs/armeabi-v7a/libMulti.so new file mode 100644 index 0000000..2189429 Binary files /dev/null and b/app/libs/armeabi-v7a/libMulti.so differ diff --git a/app/libs/armeabi-v7a/libSpiDevice.so b/app/libs/armeabi-v7a/libSpiDevice.so new file mode 100644 index 0000000..101915f Binary files /dev/null and b/app/libs/armeabi-v7a/libSpiDevice.so differ diff --git a/app/libs/armeabi/libFrameBuffer.so b/app/libs/armeabi/libFrameBuffer.so new file mode 100644 index 0000000..1927f40 Binary files /dev/null and b/app/libs/armeabi/libFrameBuffer.so differ diff --git a/app/libs/armeabi/libMulti.so b/app/libs/armeabi/libMulti.so new file mode 100644 index 0000000..413c0a8 Binary files /dev/null and b/app/libs/armeabi/libMulti.so differ diff --git a/app/libs/armeabi/libSpiDevice.so b/app/libs/armeabi/libSpiDevice.so new file mode 100644 index 0000000..e7c2446 Binary files /dev/null and b/app/libs/armeabi/libSpiDevice.so differ diff --git a/app/libs/armeabi/libfriendlyarm-hardware.so b/app/libs/armeabi/libfriendlyarm-hardware.so new file mode 100644 index 0000000..6834491 Binary files /dev/null and b/app/libs/armeabi/libfriendlyarm-hardware.so differ diff --git a/app/libs/jackson.jar b/app/libs/jackson.jar new file mode 100644 index 0000000..9929c93 Binary files /dev/null and b/app/libs/jackson.jar differ diff --git a/app/libs/org.apache.commons.codec-1.8.jar b/app/libs/org.apache.commons.codec-1.8.jar new file mode 100644 index 0000000..1889c3c Binary files /dev/null and b/app/libs/org.apache.commons.codec-1.8.jar differ diff --git a/app/libs/task_dto5.jar b/app/libs/task_dto5.jar new file mode 100644 index 0000000..b679593 Binary files /dev/null and b/app/libs/task_dto5.jar differ diff --git a/app/libs/xixun_alahover.jar b/app/libs/xixun_alahover.jar new file mode 100644 index 0000000..38c9a33 Binary files /dev/null and b/app/libs/xixun_alahover.jar differ diff --git a/app/libs/xixun_card_setting_1.2.2.jar b/app/libs/xixun_card_setting_1.2.2.jar new file mode 100644 index 0000000..62eb51f Binary files /dev/null and b/app/libs/xixun_card_setting_1.2.2.jar differ diff --git a/app/libs/zip4j_1.3.1.jar b/app/libs/zip4j_1.3.1.jar new file mode 100644 index 0000000..fc6610a Binary files /dev/null and b/app/libs/zip4j_1.3.1.jar differ 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/release/display2.0_V0.1.zip b/app/release/display2.0_V0.1.zip new file mode 100644 index 0000000..3266b03 Binary files /dev/null and b/app/release/display2.0_V0.1.zip differ diff --git a/app/release/display2.0_v5.1.8.4.zip b/app/release/display2.0_v5.1.8.4.zip new file mode 100644 index 0000000..a783890 Binary files /dev/null and b/app/release/display2.0_v5.1.8.4.zip differ diff --git a/app/release/display2.0_v_0.2.zip b/app/release/display2.0_v_0.2.zip new file mode 100644 index 0000000..88fedca Binary files /dev/null and b/app/release/display2.0_v_0.2.zip differ diff --git a/app/release/display2.0_v_0.3.zip b/app/release/display2.0_v_0.3.zip new file mode 100644 index 0000000..6397b04 Binary files /dev/null and b/app/release/display2.0_v_0.3.zip differ diff --git a/app/release/display2.0_v_0.4.zip b/app/release/display2.0_v_0.4.zip new file mode 100644 index 0000000..cd25f8a Binary files /dev/null and b/app/release/display2.0_v_0.4.zip differ diff --git a/app/release/display2.0_v_0.5.zip b/app/release/display2.0_v_0.5.zip new file mode 100644 index 0000000..f9e61d6 Binary files /dev/null and b/app/release/display2.0_v_0.5.zip differ diff --git a/app/release/display2.0_v_0.6.zip b/app/release/display2.0_v_0.6.zip new file mode 100644 index 0000000..93a7a1b Binary files /dev/null and b/app/release/display2.0_v_0.6.zip differ diff --git a/app/release/display2.0_v_0.7.zip b/app/release/display2.0_v_0.7.zip new file mode 100644 index 0000000..f8ce648 Binary files /dev/null and b/app/release/display2.0_v_0.7.zip differ diff --git a/app/release/display2.0_v_0.8.zip b/app/release/display2.0_v_0.8.zip new file mode 100644 index 0000000..513b4e5 Binary files /dev/null and b/app/release/display2.0_v_0.8.zip differ diff --git a/app/release/display2.0_v_0.9.zip b/app/release/display2.0_v_0.9.zip new file mode 100644 index 0000000..57c7eff Binary files /dev/null and b/app/release/display2.0_v_0.9.zip differ diff --git a/app/release/display2.0_v_1.1.zip b/app/release/display2.0_v_1.1.zip new file mode 100644 index 0000000..4d6f5f5 Binary files /dev/null and b/app/release/display2.0_v_1.1.zip differ diff --git a/app/release/display2.0_v_1.2.zip b/app/release/display2.0_v_1.2.zip new file mode 100644 index 0000000..a29a10c Binary files /dev/null and b/app/release/display2.0_v_1.2.zip differ diff --git a/app/release/display2.0_v_1.3.zip b/app/release/display2.0_v_1.3.zip new file mode 100644 index 0000000..79391f5 Binary files /dev/null and b/app/release/display2.0_v_1.3.zip differ diff --git a/app/release/display2.0_v_1.4-debug.zip b/app/release/display2.0_v_1.4-debug.zip new file mode 100644 index 0000000..d19c58a Binary files /dev/null and b/app/release/display2.0_v_1.4-debug.zip differ diff --git a/app/release/display2.0_v_1.4.zip b/app/release/display2.0_v_1.4.zip new file mode 100644 index 0000000..f10f612 Binary files /dev/null and b/app/release/display2.0_v_1.4.zip differ diff --git a/app/release/display2.0_v_1.5.zip b/app/release/display2.0_v_1.5.zip new file mode 100644 index 0000000..7f94d89 Binary files /dev/null and b/app/release/display2.0_v_1.5.zip differ diff --git a/app/release/display2.0_v_1.6.zip b/app/release/display2.0_v_1.6.zip new file mode 100644 index 0000000..fa2d1e2 Binary files /dev/null and b/app/release/display2.0_v_1.6.zip differ diff --git a/app/release/display2.0_v_1.7.zip b/app/release/display2.0_v_1.7.zip new file mode 100644 index 0000000..8875516 Binary files /dev/null and b/app/release/display2.0_v_1.7.zip differ diff --git a/app/release/display2.0_v_1.8-T.zip b/app/release/display2.0_v_1.8-T.zip new file mode 100644 index 0000000..d6fe256 Binary files /dev/null and b/app/release/display2.0_v_1.8-T.zip differ diff --git a/app/release/display2.0_v_1.8.zip b/app/release/display2.0_v_1.8.zip new file mode 100644 index 0000000..20d4b89 Binary files /dev/null and b/app/release/display2.0_v_1.8.zip differ diff --git a/app/release/display2.0_v_1.9-1-ralease.zip b/app/release/display2.0_v_1.9-1-ralease.zip new file mode 100644 index 0000000..363ede2 Binary files /dev/null and b/app/release/display2.0_v_1.9-1-ralease.zip differ diff --git a/app/release/display2.0_v_1.9-ralease.zip b/app/release/display2.0_v_1.9-ralease.zip new file mode 100644 index 0000000..44fb1e2 Binary files /dev/null and b/app/release/display2.0_v_1.9-ralease.zip differ diff --git a/app/release/display2.0_v_2.0-ralease.zip b/app/release/display2.0_v_2.0-ralease.zip new file mode 100644 index 0000000..4d569b6 Binary files /dev/null and b/app/release/display2.0_v_2.0-ralease.zip differ diff --git a/app/release/display2.0_v_2.2-ralease.zip b/app/release/display2.0_v_2.2-ralease.zip new file mode 100644 index 0000000..504b531 Binary files /dev/null and b/app/release/display2.0_v_2.2-ralease.zip differ diff --git a/app/release/display2.0_v_2.3-ralease.zip b/app/release/display2.0_v_2.3-ralease.zip new file mode 100644 index 0000000..2f81210 Binary files /dev/null and b/app/release/display2.0_v_2.3-ralease.zip differ diff --git a/app/release/display2.0_v_2.4-ralease-px30.zip b/app/release/display2.0_v_2.4-ralease-px30.zip new file mode 100644 index 0000000..fc2ea0e Binary files /dev/null and b/app/release/display2.0_v_2.4-ralease-px30.zip differ diff --git a/app/release/display2.0_v_2.5-ralease-px30.zip b/app/release/display2.0_v_2.5-ralease-px30.zip new file mode 100644 index 0000000..76e03c1 Binary files /dev/null and b/app/release/display2.0_v_2.5-ralease-px30.zip differ diff --git a/app/release/display2.0_v_2.5-ralease.zip b/app/release/display2.0_v_2.5-ralease.zip new file mode 100644 index 0000000..1958b4a Binary files /dev/null and b/app/release/display2.0_v_2.5-ralease.zip differ diff --git a/app/release/display2.0_v_2.6-ralease.zip b/app/release/display2.0_v_2.6-ralease.zip new file mode 100644 index 0000000..ff8f5b6 Binary files /dev/null and b/app/release/display2.0_v_2.6-ralease.zip differ diff --git a/app/release/display2.0_v_2.7-ralease.zip b/app/release/display2.0_v_2.7-ralease.zip new file mode 100644 index 0000000..7856277 Binary files /dev/null and b/app/release/display2.0_v_2.7-ralease.zip differ diff --git a/app/release/display2.0_v_2.8-debug.zip b/app/release/display2.0_v_2.8-debug.zip new file mode 100644 index 0000000..b04c664 Binary files /dev/null and b/app/release/display2.0_v_2.8-debug.zip differ diff --git a/app/release/display2.0_v_2.9-ralease.zip b/app/release/display2.0_v_2.9-ralease.zip new file mode 100644 index 0000000..a502090 Binary files /dev/null and b/app/release/display2.0_v_2.9-ralease.zip differ diff --git a/app/release/display2.0_v_3.0-ralease.zip b/app/release/display2.0_v_3.0-ralease.zip new file mode 100644 index 0000000..90cbec9 Binary files /dev/null and b/app/release/display2.0_v_3.0-ralease.zip differ diff --git a/app/release/display2.0_v_3.1-ralease-px30.zip b/app/release/display2.0_v_3.1-ralease-px30.zip new file mode 100644 index 0000000..592f3a2 Binary files /dev/null and b/app/release/display2.0_v_3.1-ralease-px30.zip differ diff --git a/app/release/display2.0_v_3.2-ralease.zip b/app/release/display2.0_v_3.2-ralease.zip new file mode 100644 index 0000000..13f8966 Binary files /dev/null and b/app/release/display2.0_v_3.2-ralease.zip differ diff --git a/app/release/display2.0_v_3.3-ralease-px30.zip b/app/release/display2.0_v_3.3-ralease-px30.zip new file mode 100644 index 0000000..b938e4c Binary files /dev/null and b/app/release/display2.0_v_3.3-ralease-px30.zip differ diff --git a/app/release/display2.0_v_3.3-ralease.zip b/app/release/display2.0_v_3.3-ralease.zip new file mode 100644 index 0000000..23b9981 Binary files /dev/null and b/app/release/display2.0_v_3.3-ralease.zip differ diff --git a/app/release/display2.0_v_3.7-px30.zip b/app/release/display2.0_v_3.7-px30.zip new file mode 100644 index 0000000..a3955ae Binary files /dev/null and b/app/release/display2.0_v_3.7-px30.zip differ diff --git a/app/release/display2.0_v_3.8-D.zip b/app/release/display2.0_v_3.8-D.zip new file mode 100644 index 0000000..cc0384a Binary files /dev/null and b/app/release/display2.0_v_3.8-D.zip differ diff --git a/app/release/display2.0_v_3.8-Y08.zip b/app/release/display2.0_v_3.8-Y08.zip new file mode 100644 index 0000000..673642f Binary files /dev/null and b/app/release/display2.0_v_3.8-Y08.zip differ diff --git a/app/release/display2.0_v_3.9-D.zip b/app/release/display2.0_v_3.9-D.zip new file mode 100644 index 0000000..96fffda Binary files /dev/null and b/app/release/display2.0_v_3.9-D.zip differ diff --git a/app/release/display2.0_v_3.9-Y08.zip b/app/release/display2.0_v_3.9-Y08.zip new file mode 100644 index 0000000..ad2ee55 Binary files /dev/null and b/app/release/display2.0_v_3.9-Y08.zip differ diff --git a/app/release/display2.0_v_4.1-C-M7s.zip b/app/release/display2.0_v_4.1-C-M7s.zip new file mode 100644 index 0000000..60b2cad Binary files /dev/null and b/app/release/display2.0_v_4.1-C-M7s.zip differ diff --git a/app/release/display2.0_v_4.1-D-M80.zip b/app/release/display2.0_v_4.1-D-M80.zip new file mode 100644 index 0000000..9a28328 Binary files /dev/null and b/app/release/display2.0_v_4.1-D-M80.zip differ diff --git a/app/release/output.json b/app/release/output.json new file mode 100644 index 0000000..2b5f5ba --- /dev/null +++ b/app/release/output.json @@ -0,0 +1 @@ +[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":104,"versionName":"2.0_v_4.1","enabled":true,"outputFile":"display2.0_v_4.1-C-M7s.apk","fullName":"release","baseName":"release"},"path":"display2.0_v_4.1-C-M7s.apk","properties":{}}] \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..a8cbb7f --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/aidl/com/xixun/display/MyAidl.aidl b/app/src/main/aidl/com/xixun/display/MyAidl.aidl new file mode 100644 index 0000000..7149b4c --- /dev/null +++ b/app/src/main/aidl/com/xixun/display/MyAidl.aidl @@ -0,0 +1,27 @@ +// MyAidl.aidl +package com.xixun.display; +import com.xixun.display.RecCardInfo; +// Declare any non-default types here with import statements + +interface MyAidl { + boolean setBrightness(boolean manual, int brightness); + int getBrightness(); + int getReceivedCardNum(); + int getVersionBy3288(); + int getVersionSpi(); + int setOffset(int screenX,int screenY,int cutW,int cutH,int so1X,int so1Y,int so2X,int so2Y); + boolean backUpData(); + boolean restoreData(); + String getOtherVer(); + boolean rebootByFPGA(); + boolean setRelayState(int port,int vcs,String state); + String getRelayState(int port,int vcs); + void setRGB(int red,int green,int blue); + String getBoxSize(); + void startPointCheck(); + List getPointCheckData(); + void savePort(int port); + RecCardInfo getRecinfo(); + void setRecCardRelaySwitch(boolean isSwitch); + +} diff --git a/app/src/main/aidl/com/xixun/display/RecCardInfo.aidl b/app/src/main/aidl/com/xixun/display/RecCardInfo.aidl new file mode 100644 index 0000000..fa0123c --- /dev/null +++ b/app/src/main/aidl/com/xixun/display/RecCardInfo.aidl @@ -0,0 +1,5 @@ +// RecCardInfo.aidl +package com.xixun.display; + +parcelable RecCardInfo; + diff --git a/app/src/main/aidl/com/xixun/joey/uart/BytesData.aidl b/app/src/main/aidl/com/xixun/joey/uart/BytesData.aidl new file mode 100644 index 0000000..cf7ca6e --- /dev/null +++ b/app/src/main/aidl/com/xixun/joey/uart/BytesData.aidl @@ -0,0 +1,3 @@ +package com.xixun.joey.uart; + +parcelable BytesData; \ No newline at end of file diff --git a/app/src/main/aidl/com/xixun/joey/uart/IUartListener.aidl b/app/src/main/aidl/com/xixun/joey/uart/IUartListener.aidl new file mode 100644 index 0000000..314975d --- /dev/null +++ b/app/src/main/aidl/com/xixun/joey/uart/IUartListener.aidl @@ -0,0 +1,10 @@ +package com.xixun.joey.uart; + +import com.xixun.joey.uart.BytesData; + +interface IUartListener { + /** + * data: 返回接收到的串口数据 + */ + void onReceive(inout BytesData data); +} \ No newline at end of file diff --git a/app/src/main/aidl/com/xixun/joey/uart/IUartService.aidl b/app/src/main/aidl/com/xixun/joey/uart/IUartService.aidl new file mode 100644 index 0000000..0ed90fe --- /dev/null +++ b/app/src/main/aidl/com/xixun/joey/uart/IUartService.aidl @@ -0,0 +1,9 @@ +package com.xixun.joey.uart; + +import com.xixun.joey.uart.IUartListener; + +interface IUartService { + boolean config(String devPathName, int baud); + void read(String devPathName, IUartListener listener); + boolean write(String devPathName, in byte[] data); +} \ No newline at end of file diff --git a/app/src/main/aidl/com/xixun/lay/safe/Safe.aidl b/app/src/main/aidl/com/xixun/lay/safe/Safe.aidl new file mode 100644 index 0000000..3ad62e6 --- /dev/null +++ b/app/src/main/aidl/com/xixun/lay/safe/Safe.aidl @@ -0,0 +1,21 @@ +package com.xixun.lay.safe; + +// Declare any non-default types here with import statements + +interface Safe { + /** + * safe加密定制aidl + */ + //安全SDK接口初始化 + int init(); + //设置日志打印等级 + void setLogLevel(int logLevel); + //获取当前安全SDK的版本信息 + int getSdkVersion(); + //获取当前安全通信连接状态 + int getSafeConnectState(); + //与网关服务器建立安全通道 + int createSafeConnect(String url); + //关闭与网关服务器建立的安全通道 + int destroySafeConnect(); +} diff --git a/app/src/main/aidl/com/xixun/util/PlayerInfo.aidl b/app/src/main/aidl/com/xixun/util/PlayerInfo.aidl new file mode 100644 index 0000000..258b1d2 --- /dev/null +++ b/app/src/main/aidl/com/xixun/util/PlayerInfo.aidl @@ -0,0 +1,19 @@ + +package com.xixun.util; + +interface PlayerInfo { + String getProgramName(); + String getVersion(); + void setScreenWidth(int w); + void setScreenHeight(int h); + void taskScreenshot(String cmdId); + void setExternalTemperature(float t); + void setInternalTemperature(float t); + void setHumidity(float h); + boolean forcePlayProgram(String pid); + boolean finishForcePlay(); + String getCurProgramId(); + void setUSBProgramPwd(String pwd); + String executeJsonCommand(String json); + void pausePlayer(boolean b); +} \ No newline at end of file diff --git a/app/src/main/assets/CustomConfig.properties b/app/src/main/assets/CustomConfig.properties new file mode 100644 index 0000000..6758e17 --- /dev/null +++ b/app/src/main/assets/CustomConfig.properties @@ -0,0 +1,11 @@ +{ +#򿪹رմӡݵ־ +"xixun.config.log":true, +#򿪹رմӡҪ־ +"xixun.config.alllog":true, +# +"xixun.config.fenghuo":false, + +#ǷѶĵ +"xixun.config.is_xixun":true +} diff --git a/app/src/main/assets/fonts/dreamled.ttf b/app/src/main/assets/fonts/dreamled.ttf new file mode 100644 index 0000000..cc0a4b0 Binary files /dev/null and b/app/src/main/assets/fonts/dreamled.ttf differ diff --git a/app/src/main/assets/fonts/swise721.ttf b/app/src/main/assets/fonts/swise721.ttf new file mode 100644 index 0000000..04fa48c Binary files /dev/null and b/app/src/main/assets/fonts/swise721.ttf differ diff --git a/app/src/main/assets/fpga/c002.rpd b/app/src/main/assets/fpga/c002.rpd new file mode 100644 index 0000000..fc24a8f Binary files /dev/null and b/app/src/main/assets/fpga/c002.rpd differ diff --git a/app/src/main/java/android/os/SystemProperties.java b/app/src/main/java/android/os/SystemProperties.java new file mode 100644 index 0000000..e94b7ff --- /dev/null +++ b/app/src/main/java/android/os/SystemProperties.java @@ -0,0 +1,104 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package android.os; + +import java.util.ArrayList; + +public class SystemProperties { + public static final int PROP_NAME_MAX = 31; + public static final int PROP_VALUE_MAX = 91; + private static final ArrayList sChangeCallbacks = new ArrayList(); + + public SystemProperties() { + } + + private static native String native_get(String var0); + + private static native String native_get(String var0, String var1); + + private static native int native_get_int(String var0, int var1); + + private static native long native_get_long(String var0, long var1); + + private static native boolean native_get_boolean(String var0, boolean var1); + + private static native void native_set(String var0, String var1); + + private static native void native_add_change_callback(); + + public static String get(String key) { + if(key.length() > 31) { + throw new IllegalArgumentException("key.length > 31"); + } else { + return native_get(key); + } + } + + public static String get(String key, String def) { + if(key.length() > 31) { + throw new IllegalArgumentException("key.length > 31"); + } else { + return native_get(key, def); + } + } + + public static int getInt(String key, int def) { + if(key.length() > 31) { + throw new IllegalArgumentException("key.length > 31"); + } else { + return native_get_int(key, def); + } + } + + public static long getLong(String key, long def) { + if(key.length() > 31) { + throw new IllegalArgumentException("key.length > 31"); + } else { + return native_get_long(key, def); + } + } + + public static boolean getBoolean(String key, boolean def) { + if(key.length() > 31) { + throw new IllegalArgumentException("key.length > 31"); + } else { + return native_get_boolean(key, def); + } + } + + public static void set(String key, String val) { + if(key.length() > 31) { + throw new IllegalArgumentException("key.length > 31"); + } else if(val != null && val.length() > 91) { + throw new IllegalArgumentException("val.length > 91"); + } else { + native_set(key, val); + } + } + + public static void addChangeCallback(Runnable callback) { + synchronized(sChangeCallbacks) { + if(sChangeCallbacks.size() == 0) { + native_add_change_callback(); + } + + sChangeCallbacks.add(callback); + } + } + + static void callChangeCallbacks() { + synchronized(sChangeCallbacks) { + if(sChangeCallbacks.size() != 0) { + ArrayList callbacks = new ArrayList(sChangeCallbacks); + + for(int i = 0; i < callbacks.size(); ++i) { + ((Runnable)callbacks.get(i)).run(); + } + + } + } + } +} diff --git a/app/src/main/java/cd b/app/src/main/java/cd new file mode 100644 index 0000000..1d9a1f4 --- /dev/null +++ b/app/src/main/java/cd @@ -0,0 +1,30 @@ + +D:\Project\Display\app\src\main\java>set ProjectName=Display + +D:\Project\Display\app\src\main\java>set stryear=18 + +D:\Project\Display\app\src\main\java>set strmonth=07 + +D:\Project\Display\app\src\main\java>set strday=30 + +D:\Project\Display\app\src\main\java>set strdatetime=180730 + +D:\Project\Display\app\src\main\java>set ObjectPath=E:\Backup\Project\Display + +D:\Project\Display\app\src\main\java>mkdir E:\Backup\Project\Display + +D:\Project\Display\app\src\main\java>del /f/s/q .\Display.zip + +D:\Project\Display\app\src\main\java>del /f/s/q E:\Backup\Project\Display\Display180730a.zip +ɾļ - E:\Backup\Project\Display\Display180730a.zip + +D:\Project\Display\app\src\main\java>mkdir E:\Backup\Project\Display + +D:\Project\Display\app\src\main\java>"C:\Program Files\2345Soft\HaoZip\HaoZipC.exe" a -tzip .\Display.zip -psamtone1 .\Display +ɨļ... + +ѹĵ .\Display.zip + + +D:\Project\Display\app\src\main\java>copy .\Display.zip E:\Backup\Project\Display\Display180730a.zip +Ѹ 1 ļ diff --git a/app/src/main/java/com/amused/joey/crash/AppCrashInfo.java b/app/src/main/java/com/amused/joey/crash/AppCrashInfo.java new file mode 100644 index 0000000..d8b037c --- /dev/null +++ b/app/src/main/java/com/amused/joey/crash/AppCrashInfo.java @@ -0,0 +1,17 @@ +package com.amused.joey.crash; + +/** + * Project: JoeyTools + * Create : joey + * Date : 2019/01/30 16:38 + * Description: + */ +public class AppCrashInfo { + public String key; + public String value; + + AppCrashInfo(String key, String value) { + this.key = key; + this.value = value; + } +} diff --git a/app/src/main/java/com/amused/joey/crash/CrashHelper.java b/app/src/main/java/com/amused/joey/crash/CrashHelper.java new file mode 100644 index 0000000..6d52973 --- /dev/null +++ b/app/src/main/java/com/amused/joey/crash/CrashHelper.java @@ -0,0 +1,221 @@ +package com.amused.joey.crash; + +/** + * Project: JoeyTools + * Create : joey + * Date : 2019/01/30 13:10 + * Description: + */ + +import android.annotation.SuppressLint; +import android.content.Context; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.os.Build; +import android.util.Log; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.lang.reflect.Field; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; + +/** + * UncaughtException处理类,当程序发生Uncaught异常的时候,由该类来接管程序,并记录发送错误报告. + * 需要在Application中注册,为了要在程序启动器就监控整个程序。 + */ +public class CrashHelper implements Thread.UncaughtExceptionHandler { + private final static String TAG = "CrashHelper"; + @SuppressLint("StaticFieldLeak") + private final static DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.US); + + private Builder builder; + //系统默认的UncaughtException处理类 + private Thread.UncaughtExceptionHandler defaultHandler; + // 用来存储发生崩溃时的设备信息和异常信息 + private List crashInfos; + + private CrashHelper(Builder builder) { + crashInfos = new ArrayList<>(); + this.builder = builder; + //获取系统默认的UncaughtException处理器 + defaultHandler = Thread.getDefaultUncaughtExceptionHandler(); + //设置该CrashHandler为程序的默认处理器 + Thread.setDefaultUncaughtExceptionHandler(this); + } + + public void addCrashInfosAppend(String key, String value) { + if (null == builder.crashInfosAppend) { + builder.crashInfosAppend = new ArrayList<>(); + } + builder.crashInfosAppend.add(new AppCrashInfo(key, value)); + } + + /* 当UncaughtException发生时会转入该函数来处理 */ + @Override + public void uncaughtException(Thread thread, Throwable throwable) { + if ((null == throwable) && (null != defaultHandler)) { + defaultHandler.uncaughtException(thread, throwable); + } else { + handleException(throwable); + //退出进程 + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + android.os.Process.killProcess(android.os.Process.myPid()); + System.exit(1); + } + } + + private String getAppName(PackageInfo packageInfo) { + int labelRes = packageInfo.applicationInfo.labelRes; + return builder.context.getResources().getString(labelRes); + } + + private void handlerExceptionVersionInfo() throws PackageManager.NameNotFoundException { + PackageManager packageManager = builder.context.getPackageManager(); + PackageInfo packageInfo = packageManager.getPackageInfo(builder.context.getPackageName(), PackageManager.GET_ACTIVITIES); + // APP版本信息 + if (null != packageInfo) { + String appName = getAppName(packageInfo); + crashInfos.add(new AppCrashInfo("ApplicationName", appName)); + crashInfos.add(new AppCrashInfo("PackageName", packageInfo.packageName)); + crashInfos.add(new AppCrashInfo("VersionName", (null != packageInfo.versionName)? packageInfo.versionName: "NULL")); + crashInfos.add(new AppCrashInfo("VersionCode", String.valueOf(packageInfo.versionCode))); +// UiToast.showMessage(builder.context, appName + " has crashed, exit it !", false); + } else { +// UiToast.showMessage(builder.context, builder.context.getPackageName() + " has crashed, exit it !", false); + } + } + + private void handleExceptionCustomInfo() { + // 自定义崩溃环境信息 + if (null != builder.crashInfosAppend) { + crashInfos.addAll(builder.crashInfosAppend); + } + } + + private void handleExceptionDeviceInfo() throws IllegalAccessException { + // 设备信息 + Field[] fields = Build.class.getDeclaredFields(); + for (Field field : fields) { + field.setAccessible(true); + crashInfos.add(new AppCrashInfo(field.getName(), field.get(null).toString())); + } + } + + private void handleExceptionThrowable(Throwable throwable) { + // 崩溃信息 + StringWriter writer = new StringWriter(); + PrintWriter printWriter = new PrintWriter(writer); + throwable.printStackTrace(printWriter); + Throwable cause = throwable.getCause(); + while (null != cause) { + cause.printStackTrace(printWriter); + cause = cause.getCause(); + } + printWriter.close(); + crashInfos.add(new AppCrashInfo("CrashThrowable", writer.toString())); + } + + private void handleException(Throwable throwable) { + try { + crashInfos.add(new AppCrashInfo("CrashTime", new Date().toString())); + handlerExceptionVersionInfo(); + handleExceptionCustomInfo(); + handleExceptionDeviceInfo(); + handleExceptionThrowable(throwable); + + saveToFile(); + } catch (PackageManager.NameNotFoundException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /* 如果可能,保存错误信息到文件中 */ + private void saveToFile() throws IOException { + StringBuilder infoStr = new StringBuilder(); + for (int index = 0; index < crashInfos.size(); ++index) { + AppCrashInfo info = crashInfos.get(index); +// infoStr.append(entry.getKey().toUpperCase(Locale.US)); + infoStr.append(info.key); + infoStr.append(": "); + infoStr.append(info.value); + infoStr.append("\r\n"); + } + if (null != builder.logFilePrefix) { + String time = formatter.format(new Date()); + String fileName = builder.logFilePrefix + "_" + time + ".log"; + File dir = builder.context.getFilesDir(); + if (!dir.exists()) { + dir.mkdirs(); + } + // File log = new File(dir, fileName); + // File log = new File("/sdcard/", fileName); + File log = new File("/mnt/sdcard/", fileName); + FileOutputStream fos = new FileOutputStream(log.getAbsoluteFile()); + fos.write(infoStr.toString().getBytes()); + fos.close(); + if (null != builder.onCrashListener) { + builder.onCrashListener.onCrash(log, crashInfos, infoStr); + } else { + Log.e(TAG, infoStr.toString()); + } + } else { + if (null != builder.onCrashListener) { + builder.onCrashListener.onCrash(null, crashInfos, infoStr); + } + } + } + + public static class Builder { + private Context context; + private OnCrashListener onCrashListener; + private String logFilePrefix; + // 发生崩溃时记录用户自定义的信息 + private List crashInfosAppend; + + public Builder(Context context) { + this.context = context; + } + + public Builder setOnCrashListener(OnCrashListener onCrashListener) { + this.onCrashListener = onCrashListener; + return this; + } + + public Builder setLogFilePrefix(String logFilePrefix) { + this.logFilePrefix = logFilePrefix; + return this; + } + + public Builder addCrashInfosAppend(String key, String value) { + if (null == crashInfosAppend) { + crashInfosAppend = new ArrayList<>(); + } + crashInfosAppend.add(new AppCrashInfo(key, value)); + return this; + } + + public CrashHelper build() { + return new CrashHelper(this); + } + } +} diff --git a/app/src/main/java/com/amused/joey/crash/OnCrashListener.java b/app/src/main/java/com/amused/joey/crash/OnCrashListener.java new file mode 100644 index 0000000..6e77826 --- /dev/null +++ b/app/src/main/java/com/amused/joey/crash/OnCrashListener.java @@ -0,0 +1,20 @@ +package com.amused.joey.crash; + +import java.io.File; +import java.util.List; + +/** + * Project: JoeyTools + * Create : joey + * Date : 2019/01/30 13:36 + * Description: + */ +public interface OnCrashListener { + /** + * 当发生崩溃时触发,注意:crashLog可能为空 + * @param crashLog + * @param crashData + * @param crashInfo + */ + public void onCrash(File crashLog, List crashData, StringBuilder crashInfo); +} diff --git a/app/src/main/java/com/iflyings/android/fpgadetect/FpgaDetect.java b/app/src/main/java/com/iflyings/android/fpgadetect/FpgaDetect.java new file mode 100644 index 0000000..8eb1d42 --- /dev/null +++ b/app/src/main/java/com/iflyings/android/fpgadetect/FpgaDetect.java @@ -0,0 +1,51 @@ +package com.iflyings.android.fpgadetect; + +import android.util.Log; + +import com.xixun.display.MyLog; +import com.xixun.display.backup.SendData; + + +public class FpgaDetect { + public SendData sendData; + + public FpgaDetect() { + sendData = new SendData(); + getRecvCardRamBuffer(0, 0, 0, 0L, null, 0); + } + /// + /// 读取接收卡数据 + /// + /// 发送卡索引 + /// 接收卡索引 + /// 读取的地址,地址以4字节为单位 + /// 读取的字节数(4字节对齐) + /// 返回的读取数据 + /// 错误码, 成功返回 0 + private int getRecvCardRamBuffer(int netPort, int cardIndex, long vcsNumber, long memAddress, byte[] buffer, int size) { + if (size == 0) { + return 0; + } + if(sendData == null){ + MyLog.e("sendData is null...."); + } + int i = sendData.vcs_dat_r_badPoint(netPort, cardIndex, vcsNumber, memAddress, buffer, size/4, 2); + Log.i("zwf", "getRecvCardRamBuffer....."+i); + return i; + } + + /// + /// 读取接收卡坏点信息 + /// + /// 发送卡索引 + /// 接收卡索引 + /// 箱体宽 + /// 箱体高 + /// 返回的点状态,每个点一个字节,坐标根据箱体宽高索引,bit6.7=unused, bit4.5=B, bit2.3=G,bit0.1=R,0表示正常,其它值表示异常 + /// 错误码 + public native int checkRecvCardBadPoint(int netPort, int cardIndex, long vcsNumber, int boxWidth, int boxHeight, byte[] array); + + static { + System.loadLibrary("fpga-detect"); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/xixun/communicate/PointCheck/PointCheck.java b/app/src/main/java/com/xixun/communicate/PointCheck/PointCheck.java new file mode 100644 index 0000000..b316796 --- /dev/null +++ b/app/src/main/java/com/xixun/communicate/PointCheck/PointCheck.java @@ -0,0 +1,19 @@ +package com.xixun.communicate.PointCheck; + +import java.util.ArrayList; +import java.util.List; + +public class PointCheck{ + public int width; + public int height; + public int receiverCount; + public List receivers; + + public PointCheck(int w, int h, int rc, List< ReceiverCard> cards){ + width = w; + height = h; + receiverCount = rc; + receivers = cards; + + } +} \ No newline at end of file diff --git a/app/src/main/java/com/xixun/communicate/PointCheck/ReceiverCard.java b/app/src/main/java/com/xixun/communicate/PointCheck/ReceiverCard.java new file mode 100644 index 0000000..99859d2 --- /dev/null +++ b/app/src/main/java/com/xixun/communicate/PointCheck/ReceiverCard.java @@ -0,0 +1,14 @@ + +package com.xixun.communicate.PointCheck; + +public class ReceiverCard{ + public int receiverNumber; + public int totalPoints; + public int breakPoints; + + public ReceiverCard(int r, int t, int b){ + receiverNumber = r; + totalPoints = t; + breakPoints = b; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/xixun/communicate/Protocol/NET_COMMU_TYPE.java b/app/src/main/java/com/xixun/communicate/Protocol/NET_COMMU_TYPE.java new file mode 100644 index 0000000..f700fb8 --- /dev/null +++ b/app/src/main/java/com/xixun/communicate/Protocol/NET_COMMU_TYPE.java @@ -0,0 +1,61 @@ +package com.xixun.communicate.Protocol; + +/** + * Created by Administrator on 2018/01/18. + */ + +public enum NET_COMMU_TYPE { + NONE(0x00), + TICK(1), + FPGA_MOONCELL(2), + + UART_SENSOR(3), + UART_FPGA(4), + UART_EXTENSION(5), + + MOONCELL_FPAG(7), + FGPA_UPDATE_ACK(0x09), + FGPA_VERSION_ACK(0x3C), + + FGPA_UPDATE(0x09+0x40), + FGPA_VERSION(0x3C+0x40), + NUM(0xFF); + + // 定义私有变量 + private int ucCommandType=0; + + // 构造函数,枚举类型只能为私有 + NET_COMMU_TYPE(int ucCommandType) { + this.ucCommandType = ucCommandType; + } + + public static NET_COMMU_TYPE GetEnumValue(byte ucCommandType){ // 手写的从int到enum的转换函数 + switch(ucCommandType) { + case 0: return NONE; + case 1: return TICK; + case 2: return FPGA_MOONCELL; + + case 3: return UART_SENSOR; + case 4: return UART_FPGA; + case 5: return UART_EXTENSION; + + case 7: return MOONCELL_FPAG; + case 0x09: return FGPA_UPDATE_ACK; + case 0x3C: return FGPA_VERSION_ACK; + + case (0x09+0x40): return FGPA_UPDATE; + case (0x3C+0x40): return FGPA_VERSION; + + + default: return NONE; + } + } + public byte getValue() + { return (byte)ucCommandType; + } + @Override + public String toString() { + return String.valueOf(ucCommandType); + } + +} diff --git a/app/src/main/java/com/xixun/communicate/SpiDevice.java b/app/src/main/java/com/xixun/communicate/SpiDevice.java new file mode 100644 index 0000000..69c074c --- /dev/null +++ b/app/src/main/java/com/xixun/communicate/SpiDevice.java @@ -0,0 +1,57 @@ +package com.xixun.communicate; + +import com.xixun.display.MyLog; +import java.io.FileDescriptor; + +/** + * Created by Administrator on 2018/05/12. + */ + +public class SpiDevice { + private FileDescriptor fileDescriptor=null; + private String deviceName="/dev/spidev0.0"; + private int iBaudRate=12*1000*1000;//12000000;//16675000; if iSpiMaxBaudRate != 12Mhz y30 wil have problem; + private int mode=1; + static { + try { + System.loadLibrary("SpiDevice");// 在java代码中引入libs目录下的库函数,文件名为【libhello.so】。注意,引入时的文件名要去掉前面的lib和后面的.so + System.out.println("[Loading] --> Load library libSpiDevice.so success!"); + } catch (Exception e) { + System.out.println("[Loading] --> Can't load library libSpiDevice.so !"); + e.printStackTrace(); + } + } + + + public SpiDevice(String deviceName, int iBaudRate,int mode) { + this.deviceName=deviceName; + this.iBaudRate=iBaudRate; + this.mode=mode; + } + + public void spiDeveiceOpen() { + fileDescriptor=Open(deviceName,iBaudRate,mode); + MyLog.i("SpiDevice.java Open Device:"+deviceName + " ,fileDescriptor = "+ fileDescriptor); + if (fileDescriptor==null){ + MyLog.i("SpiDevice.java Open Device Fail:"+deviceName); + }else { + MyLog.i("SpiDevice.java Open Device Success:"+deviceName); + } + } + + public void Exit(){ + MyLog.i(" "+ Thread.currentThread().getStackTrace()[2].getFileName() + "-->" + + "Function: " +Thread.currentThread().getStackTrace()[2].getMethodName() + "-->" + + "Line" +Thread.currentThread().getStackTrace()[2].getLineNumber() + ":\r\n" + ); + Close(); + fileDescriptor=null; + } + + +// public native FileDescriptor Open(String deviceName, int iBaudRate); + public native FileDescriptor Open(String deviceName, int iBaudRate,int mode); + public native int Operator(byte [] Databuffer,int iLength); + public native int Trans(byte []sendBuf, byte []recvBuf, int iLength); + public native int Close(); +} diff --git a/app/src/main/java/com/xixun/communicate/Task/PollingWorker.java b/app/src/main/java/com/xixun/communicate/Task/PollingWorker.java new file mode 100644 index 0000000..7170595 --- /dev/null +++ b/app/src/main/java/com/xixun/communicate/Task/PollingWorker.java @@ -0,0 +1,69 @@ +package com.xixun.communicate.Task; + +import com.xixun.display.MyLog; + +import java.util.concurrent.ConcurrentHashMap; + + +public class PollingWorker extends Thread { + private static final ConcurrentHashMap pollingWorkers = new ConcurrentHashMap(); + + private Worker worker; + private long delay; + private long interval; + + public Worker getWorker() { + return worker; + } + + /** + * 添加一个任务 + * @param delay: 延迟多久开始执行 + * @param interval:间隔时间 + * @param worker + */ + public void addWorker(long delay, long interval, Worker worker) { + this.delay = delay; + this.interval = interval; + this.worker = worker; + if ("".equals(worker.getName())) { + worker.setName("Worker$" + (pollingWorkers.size() + 1)); + } + if (null == pollingWorkers.putIfAbsent(worker, this)) { + this.start(); + MyLog.i("Hire worker ==> " + worker.getName()); + } + } + + /** + * 移除一个任务 + * @param worker + */ + public static void fireWorker(Worker worker) { + synchronized(pollingWorkers) { + if (pollingWorkers.containsKey(worker)) { + PollingWorker pollingWorker = pollingWorkers.get(worker); + pollingWorkers.remove(worker); + pollingWorker.interrupt(); + MyLog.i("Fire worker ==> " + worker.getName()); + } + } + } + + @Override + public void run() { + try { + if (delay > 0) { + Thread.sleep(delay); + } + while (!isInterrupted()) { + worker.exec(); + // 轮寻任务至少间隔10ms,防止出现死循环 + Thread.sleep((interval > 10) ? interval: 10); + } + } catch (InterruptedException e) { + e.printStackTrace(); + interrupt(); + } + } +} diff --git a/app/src/main/java/com/xixun/communicate/Task/Worker.java b/app/src/main/java/com/xixun/communicate/Task/Worker.java new file mode 100644 index 0000000..4337607 --- /dev/null +++ b/app/src/main/java/com/xixun/communicate/Task/Worker.java @@ -0,0 +1,18 @@ +package com.xixun.communicate.Task; + +public abstract class Worker { + private String name; + + public abstract void exec(); + + public String getName() { + if (null == name) { + name = ""; + } + return name; + } + public Worker setName(String name) { + this.name = name; + return this; + } +} diff --git a/app/src/main/java/com/xixun/communicate/WorkParams.java b/app/src/main/java/com/xixun/communicate/WorkParams.java new file mode 100644 index 0000000..c42a3a5 --- /dev/null +++ b/app/src/main/java/com/xixun/communicate/WorkParams.java @@ -0,0 +1,100 @@ +package com.xixun.communicate; + +import android.content.Context; + +import com.xixun.display.MyLog; +import com.xixun.display.controller.XixunController; +import com.xixun.display.utils.Configurations; +import com.xixun.display.utils.FileOperator; + +import java.io.File; + +public class WorkParams { + public int iLightValue= 50; + + public int iDirection=1; + public int iCarriageNumber=0; + public String strStationNumber="G1234"; + + + public String strProgramStart="strProgramStart"; + private Configurations configurations=null; + + + public WorkParams(Context ctx){ + configurations = Configurations.getConfigurations(ctx); + + if (strProgramStart.equals(configurations.getValue("strProgramStart"))==false) { + MyLog.i(Thread.currentThread().getStackTrace()[2].getFileName() + "-->" + + "Function: " + Thread.currentThread().getStackTrace()[2].getMethodName() + "-->" + + "Line" + Thread.currentThread().getStackTrace()[2].getLineNumber() + + " First initial work paramters."); + pushBaseParams(); // 第一次运行。 + }else{ + pullBaseParams(); + } + } + + public void pushBaseParams(){ + configurations.setValue("strProgramStart", strProgramStart); + configurations.setIntValue("iLightValue", iLightValue); + + /*if (XixunController.get().bDisplay_RailWay) { + configurations.setIntValue("iDirection", iDirection); + configurations.setIntValue("iCarriageNumber", iCarriageNumber); + configurations.setValue("strStationNumber", strStationNumber); + }*/ + } + + public void pullBaseParams(){ + iLightValue = configurations.getIntValue("iLightValue"); + + /*if (XixunController.get().bDisplay_RailWay) { + iDirection = configurations.getIntValue("iDirection"); + iCarriageNumber = configurations.getIntValue("iCarriageNumber"); + strStationNumber = configurations.getValue("strStationNumber"); + }*/ + } + + public void Backup(String strDirectPath) + { + String strSoureceFile=XixunController.get().GetAppPath() + + "/shared_prefs/" + + Configurations.strConfigFileName + + ".xml"; + String strDirectFile=strDirectPath + + Configurations.strConfigFileName + + ".xml"; + + //MyLog.i("strSoureceFile= " +strSoureceFile); + //MyLog.i("strDirectFile= " +strDirectFile); + + pushBaseParams(); + FileOperator.copyFile(strSoureceFile, strDirectFile); + } + + + public void Recover(String strDirectPath) + { + String strDirectFile =XixunController.get().GetAppPath() + + "/shared_prefs/" + + Configurations.strConfigFileName + + ".xml"; + String strSoureceFile =strDirectPath + + Configurations.strConfigFileName + + ".xml"; + + File file=new File(strSoureceFile); + if (file.exists()==false) return; + + //MyLog.i("strSoureceFile= " +strSoureceFile); + //MyLog.i("strDirectFile= " +strDirectFile); + + FileOperator.copyFile(strSoureceFile, strDirectFile); + + pullBaseParams(); + } + + + // /data/data/com.xixun.display/shared_prefs/DisplayAppConfig.xml +} diff --git a/app/src/main/java/com/xixun/display/AIDLService.java b/app/src/main/java/com/xixun/display/AIDLService.java new file mode 100644 index 0000000..1b8bf07 --- /dev/null +++ b/app/src/main/java/com/xixun/display/AIDLService.java @@ -0,0 +1,18 @@ +package com.xixun.display; + +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; +import android.support.annotation.Nullable; + +public class AIDLService extends Service { + + + @Nullable + @Override + public IBinder onBind(Intent intent) { + return null; + } + + +} diff --git a/app/src/main/java/com/xixun/display/BootReceiver.java b/app/src/main/java/com/xixun/display/BootReceiver.java new file mode 100644 index 0000000..157719d --- /dev/null +++ b/app/src/main/java/com/xixun/display/BootReceiver.java @@ -0,0 +1,23 @@ +package com.xixun.display; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; + +/** + + * @Description 功能描述: 该类用来实现该app开机自动运行 + */ + +public class BootReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + MyLog.i("自启动程序即将执行"); + Intent newIntent = new Intent(context, MainActivity.class); + newIntent.setPackage(MyApp.getInstance().getPackageName()); + // 注意,必须添加这个标记,否则启动会失败 + newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(newIntent); + } + +} diff --git a/app/src/main/java/com/xixun/display/MainActivity.java b/app/src/main/java/com/xixun/display/MainActivity.java new file mode 100644 index 0000000..566b8ac --- /dev/null +++ b/app/src/main/java/com/xixun/display/MainActivity.java @@ -0,0 +1,100 @@ +package com.xixun.display; + +import android.Manifest; +import android.annotation.SuppressLint; +import android.app.Activity; +import android.app.ActivityManager; +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.os.Build; +import android.os.Bundle; +import android.os.Environment; +import android.support.annotation.NonNull; +import android.support.v4.app.ActivityCompat; +import android.support.v4.content.ContextCompat; +import android.telephony.SubscriptionInfo; +import android.telephony.SubscriptionManager; +import android.telephony.TelephonyManager; +import android.widget.Toast; + +import java.io.File; +import java.io.IOException; +import java.util.List; +import net.lingala.zip4j.core.ZipFile; + +import static java.lang.Thread.sleep; + + +@SuppressLint("NewApi") + +public class MainActivity extends Activity{ + private static final int REQUEST_EXTERNAL_STORAGE = 1; + private static String[] PERMISSIONS_STORAGE = {Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.WRITE_EXTERNAL_STORAGE }; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); +// checkApp(); +// File diskConfigZip = new File("/mnt/media_rw/D8E6-3415/", "program.zip"); +// extractFile(diskConfigZip,new File("/mnt/media_rw/D8E6-3415/"),"888"); + //动态申请权限0 + verifyStoragePermissions(this); + MyLog.i("start display activity"); + Intent autoRun = new Intent(this, MyService.class); + MyApp.getInstance().startService(autoRun); + finish(); + MyLog.i("finish display activity"); + + /*Intent aidl = new Intent(this, AIDLService.class); + startService(aidl); + finish();*/ + } + // Storage Permissions + /** + * 动态申请权限 + * @param activity + */ + public static void verifyStoragePermissions(Activity activity) { + // Check if we have write permission + int permission = ActivityCompat.checkSelfPermission(activity, + Manifest.permission.WRITE_EXTERNAL_STORAGE); + if (permission != PackageManager.PERMISSION_GRANTED) { + // We don't have permission so prompt the user + ActivityCompat.requestPermissions(activity, PERMISSIONS_STORAGE, + REQUEST_EXTERNAL_STORAGE); + } + } + @Override + protected void onDestroy() { + super.onDestroy(); + } + + public boolean isTopActivity(String activity,Context context) { + ActivityManager am = (ActivityManager)context.getSystemService(context.ACTIVITY_SERVICE); + ComponentName cn = am.getRunningTasks(1).get(0).topActivity; + return cn.getClassName().toString().contains(activity); + } + + + public void extractFile(File file, File destDir, String passwd) { + ZipFile zip = null; + try { + zip = new ZipFile(file); + if (zip.isEncrypted()) { + zip.setPassword(passwd); + } + if (null == destDir) { + zip.extractAll(MyApp.getContext().getFilesDir().getAbsolutePath()); + } else { + zip.extractAll(destDir.getAbsolutePath()); + } + } catch (Exception e) { + e.printStackTrace(); + } + } +} + + diff --git a/app/src/main/java/com/xixun/display/MyApp.java b/app/src/main/java/com/xixun/display/MyApp.java new file mode 100644 index 0000000..f2e629b --- /dev/null +++ b/app/src/main/java/com/xixun/display/MyApp.java @@ -0,0 +1,749 @@ +package com.xixun.display; + +import android.annotation.SuppressLint; +import android.app.Application; +import android.content.Context; +import android.content.Intent; +import android.graphics.Point; +import android.os.Build; +import android.os.Parcel; +import android.os.SystemClock; +import android.os.UserHandle; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.xixun.display.controller.FactoryCard; +import com.xixun.display.controller.XixunCard; +import com.xixun.display.domain.StructNetBuffer; +import com.xixun.unique.BoardCard; +import com.xixun.unique.CardType; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.Inet4Address; +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.nio.ByteBuffer; +import java.nio.CharBuffer; +import java.nio.charset.Charset; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.Enumeration; +import java.util.List; +import java.util.Locale; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.LinkedBlockingDeque; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; +import java.util.zip.CRC32; + +public class MyApp extends Application { + + public static final String DEFAULT_CardID = "Android-00001"; + private static MyApp instance; + private static Context context; + private static ObjectMapper mapper; + private final static int cpuCore = Runtime.getRuntime().availableProcessors(); + private static ThreadPoolExecutor threadPool; + public static final CountDownLatch verfyOver = new CountDownLatch(1); + private static FactoryCard factory; + private static XixunCard card; + private static CardType cardType; + public static UserHandle userHandleALL; + + public static Point size; + + public MyApp() { + threadPool = new ThreadPoolExecutor(cpuCore + 1, cpuCore * 2 + 1, 10, TimeUnit.MINUTES, new LinkedBlockingDeque()); + } + + @Override + public void onCreate() { + super.onCreate(); + context=getApplicationContext(); + try { + mapper = new ObjectMapper(); + instance = this; + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static Context getContext() { + return context; + } + + /* 获取当前控制卡 */ + public synchronized static XixunCard card() { + if (null == card) { + card = factory.getProxy(getCardType()); + } + return card; + } + public static CardType getCardType() { + synchronized (MyApp.class) { + if (null == cardType) { + cardType = new BoardCard().getCardType(); + MyLog.i("Card type -> " + cardType.toString()); + } + return cardType; + } + } + public static void setFactory(FactoryCard factory) { + MyApp.factory = factory; + } + + public static MyApp getInstance() { + return instance; + } + public static void executeThread(Runnable r) { + if (threadPool.getActiveCount() < threadPool.getCorePoolSize()) { +// MyLog.e(threadPool.getCorePoolSize() + " " + threadPool.getActiveCount() + " " + threadPool.getCompletedTaskCount() + " " + r.getClass()); + threadPool.execute(r); + } else { +// MyLog.e("Create new Thread ==> " + r.getClass()); + new Thread(r).start(); + } + } + + public static Point getMaxSize() { + if (size==null){ + size = new Point(); + size.x = 128; + size.y = 64; + } + return size; + } + public static void setMaxSize(int x,int y) { + size = new Point(); + size.x = x; + size.y = y; + } + + /** + * 高字节在前,低字节在后 + * @param value + * @param len + * @return + */ + public static byte[] intToBytesH_L(int value, int len) { + byte[] data = new byte[((len >= 4) || (0 == len))? 4: len]; + int offset = 0; + + try { + for (int i = 0; i < data.length; ++i) { + data[i] = (byte)((value >> offset) & 0xff); + offset += 8; + } + } catch (Exception e) { + e.printStackTrace(); + } + + return data; + } + + /** + * 低字节在前,高字节在后 + * @param value + * @param len + * @return + */ + + public static byte[] intToBytesL_H(int value, int len) { + byte[] data = new byte[((len >= 4) || (0 == len))? 4: len]; + int offset = 0; + + try { + for (int i = data.length-1; i >= 0; --i) { + data[i] = (byte)((value >> offset) & 0xff); + offset += 8; + } + } catch (Exception e) { + e.printStackTrace(); + } + + return data; + } + + public static int bytesToInt(byte[] value, boolean bigEndian) { + int data = 0; + int offset = 0; + if (null != value) { + int len = (value.length >= 4? 4: value.length); + for (int i = 0; i < len; ++i) { + offset = (bigEndian? (len - i - 1): i) * 8; + data |= ((value[i] & 0xff) << offset); + } + } else { + MyLog.d("bytesToInt: There have a null point."); + } + return data; + } + + // long类型转成byte数组 + public static byte[] longToBytes(long number, int len) { + long temp = number; + byte[] b = new byte[len]; + + for (int i = 0; i < b.length; i++) { + // 将最低位保存在最低位 + b[i] = new Long(temp & 0xff).byteValue(); + // 向右移8位 + temp = temp >> 8; + } + return b; + } + + + public static void sleepForMillisecond(long ms) { + try { + Thread.sleep(ms); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + public static void sleepForSecond(long second) { + sleepForMillisecond(second * 1000); + } + + public static boolean checkHeader(StructNetBuffer structNetBuffer) { + boolean res = false; + try { + byte[] headerbs = structNetBuffer.getHeaderbs(); +// MyLog.showBytes("headerbs",headerbs,0); + byte[] checdCodeBs = structNetBuffer.getHeader().getCheck_code(); +// MyLog.showBytes("checdCodeBs",checdCodeBs,0); + int bsum = 0; +// byte check_code = 0; + for (int i=0;i<=23;i++){ + bsum =bsum +(headerbs[i]& 0xFF); + } + /*for (int i=0;i<=3;i++){ + check_code+=checdCodeBs[i]; + MyLog.i("check_code:"+check_code); + }*/ + int check_code = MyApp.bytesToInt(checdCodeBs,true); +// MyLog.d("b====="+bsum); +// MyLog.d("check_code====="+check_code); + res = (bsum==check_code); + }catch (Exception e){ + StructNetBuffer structNetBufferttt = structNetBuffer; + } + return res; + } + + /** + * 比较校验码 + * @param b1 + * @param b2 + * @return + */ + public static boolean compareCheckCode(byte[] b1,byte[] b2) { + int bsum = 0; +// byte check_code = 0; + for (int i=0;i<=23;i++){ + bsum =bsum +(b1[i]& 0xFF); + } + int check_code = MyApp.bytesToInt(b2,true); +// MyLog.i("b====="+bsum); +// MyLog.i("check_code====="+check_code); + boolean res = (bsum==check_code); + return res; + } + + /** + * 计算Header校验码 + * @param bytes + * @return + */ + public static byte[] calcHeaderCheckCode(byte[] bytes) { + int bsum = 0; + for (int i=0;i + * @return + */ + public static T[] concatAll(T[] first, T[]... rest) { + int totalLength = first.length; + for (T[] array : rest) { + totalLength += array.length; + } + T[] result = Arrays.copyOf(first, totalLength); + int offset = first.length; + for (T[] array : rest) { + System.arraycopy(array, 0, result, offset, array.length); + offset += array.length; + } + return result; + } + + public static ObjectMapper getMapper() { + return mapper; + } + + public static byte[] getMac(){ + byte[] macAddress = new byte[6]; + NetworkInterface networkInterface = null; + + try { + networkInterface = NetworkInterface.getByName("eth0"); + + if (networkInterface == null) { + networkInterface = NetworkInterface.getByName("wlan0"); + } + if (networkInterface == null) { + return macAddress; + } + macAddress = networkInterface.getHardwareAddress(); + } catch (SocketException e) { + e.printStackTrace(); + return macAddress; + } + MyLog.showBytes("macAddress",macAddress,0); + return macAddress; + } + + public static char calccrc8(char[] bs,int n) //效验成功则crc返回0 + { + int i,x; + char crc,crcbuff; + crc=0; + for(x = 0; x < n; x++) + { + crcbuff=bs[x]; + for(i = 0; i < 8; i++) //解释一下这层循环的语句 + { + if(((crc ^ crcbuff)&0x01)==0) //为什么? + crc >>= 1; + else + { //0001 1000 + crc ^= 0x18; //为什么? + crc >>= 1; + crc |= 0x80; //1000 0000 //为什么? + } + crcbuff >>= 1; + } + } + MyLog.i("crc:"+(crc & 0xff)); + return crc; + } + + public static byte[] getVersion(){//版本 + byte[] vsrsionBs = new byte[8]; + vsrsionBs[0]= (byte) 0xE0;//类型 + vsrsionBs[1]= (byte) 0x01;//主版本 + vsrsionBs[2]= (byte) 0x01;//子版本 + vsrsionBs[3]= (byte) 0xE0;//控制码 + vsrsionBs[4]= (byte) 0xA5;//功能码1 + vsrsionBs[5]= (byte) 0x02;//功能码2 + //vsrsionBs[6]= (byte) 0x00;//功能码3 + //vsrsionBs[7]= (byte) 0x00;//功能码4 +// System.arraycopy(vsrsionlBsTemp,0,vsrsionBs,0,vsrsionlBsTemp.length); + return vsrsionBs; + } + + public static byte[] getDeviceId(){//ID + byte[] deviceIDBs = new byte[8]; + byte[] deviceIDTemp = caclDeviceId(); + System.arraycopy(deviceIDTemp,0,deviceIDBs,0,deviceIDTemp.length); + return deviceIDBs; + } + + /** + * 唯一ID:使用MAC地址 + * @return + */ + private static byte[] caclDeviceId(){ + byte[] mac = getMac(); + byte[] deviceIDBs = new byte[8]; + deviceIDBs[0] = (byte) 0xA5; +// deviceIDBs[1] = mac[1]; +// deviceIDBs[2] = mac[0]; +// deviceIDBs[3] = mac[1]; +// deviceIDBs[4] = mac[2]; +// deviceIDBs[5] = mac[3]; +// deviceIDBs[6] = mac[4]; + //计算第七位为校验 + byte[] newBs = new byte[mac.length+1]; + newBs[0] = (byte) 0xA5; + System.arraycopy(mac,0,newBs,1,mac.length); +// String str = new String(newBs); + /*char[] cs = getChars(newBs); + MyLog.i("cs:"+cs.length); + char calc = calccrc8(cs,cs.length); + byte[] charbs = charToByte(calc); + MyLog.showBytes("charbs",charbs,0);*/ + MyLog.showBytes("DeviceId",newBs,0); +// char[] cs = {0xA5,0xA4,0xD4,0xB2,0xEF,0x47,0xF5}; +// char[] cs = {0xA5,0xA4,0xD4,0xB2,0x7F,0xC2,0x4C}; + char[] cs = getChars(newBs); + char c = calccrc8(cs,cs.length); + + deviceIDBs[7] = (byte) c; + + + System.arraycopy(mac,0,deviceIDBs,1,mac.length); + return deviceIDBs; + } + public static byte[] charToByte(char c) { + byte[] b = new byte[1]; + b[0] = (byte) ((c & 0xFF00) >> 8); + b[1] = (byte) (c & 0xFF); + return b; + } + public static char[] getChars(byte[] bytes) { + Charset cs = Charset.forName("ISO-8859-1"); + ByteBuffer bb = ByteBuffer.allocate(bytes.length); + bb.put(bytes); + bb.flip(); + CharBuffer cb = cs.decode(bb); + return cb.array(); + } + + public static byte[] getProductModel(){//产品型号:卡号 + byte[] productModelBs = new byte[32]; + String productModel = getCardID(); + byte[] productModelBsTemp = productModel.getBytes(); + System.arraycopy(productModelBsTemp,0,productModelBs,0,productModelBsTemp.length); + return productModelBs; + } + + private static String getCardID(){ + String cardId = getCardId(); + return cardId; + } + + public static byte[] getSoNum(){//网口数量 + byte[] soSumBs = new byte[4]; + int num = MyApp.card().getPortNumber(); + byte[] soSumTemp = intToBytesL_H(num,4); + System.arraycopy(soSumTemp,0,soSumBs,soSumBs.length-soSumTemp.length,soSumTemp.length); + return soSumBs; + } + + public static byte[] getRunTime(){//运行时间 00,00,00,01 + byte[] runTimeBs = new byte[4]; + long time = SystemClock.elapsedRealtime(); + byte[] runTimeTemp = longToBytes(time,4); + System.arraycopy(runTimeTemp,0,runTimeBs,runTimeBs.length-runTimeTemp.length,runTimeTemp.length); + return runTimeBs; + } + + public static byte[] getSystemTime(){//系统时间 + byte[] systemTimeBs = new byte[8]; + long time = System.currentTimeMillis(); + byte[] systemTimeTemp = longToBytes(time,8); + System.arraycopy(systemTimeTemp,0,systemTimeBs,systemTimeBs.length-systemTimeTemp.length,systemTimeTemp.length); + return systemTimeBs; + } + + /** + * 时间戳转时间字符串 + * @param seconds + * @param format + * @return + */ + public static String timeStamp2Date(String seconds,String format) { + if(seconds == null || seconds.isEmpty() || seconds.equals("null")){ + return ""; + } + if(format == null || format.isEmpty()){ + format = "yyyy-MM-dd HH:mm:ss"; + } + SimpleDateFormat sdf = new SimpleDateFormat(format); + return sdf.format(new Date(Long.valueOf(seconds))); + } + + public static long dateToStamp(String str){ + try{ + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date date = simpleDateFormat.parse(str); + long ts = date.getTime(); + System.out.println(ts); + return ts; + }catch (Exception e){ + MyLog.i(e.toString()); + } + return 0; + } + + /** + * 获取设备id + * 自定义mid + * @return + */ + public static String getCardId() { + File cardID = new File("/data/joey/signed/", "card.id"); + byte[] content = readFileByte(cardID, 0); + if ((null == content) || (0 == content.length)) { + return DEFAULT_CardID; + } else { + return cardIdToStr(content); + } + } + + public static byte[] readFileByte(File file, int len) { + try { + if (file.exists()) { + FileInputStream fis = new FileInputStream(file); + byte[] content = new byte[(len <= 0)? fis.available(): len]; + fis.read(content); + fis.close(); + return content; + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + public static String cardIdToStr(byte[] var1) { + byte[] var2 = new byte[]{97, 119, 38, 3, 46, 112, 36, 93, 58, 100, 103, 62, 115, 112, 114, 51, 43, 61, 2, 101, 119}; + if (var1.length < 40) { + return ""; + } else { + for(int var3 = 0; var3 < 20; ++var3) { + var1[var3] = (byte)(var1[var3 * 2] - var2[var3] - var3 - (var1[var3 * 2 + 1] - 3)); + } + + String var4 = new String(var1); + if (var4.length() >= 13) { + var4 = var4.substring(0, 13); + } + + return var4; + } + } + /** + * 获取当前时间, format:时间格式 + * + * @return + */ + public static String getCurrentDateString(String format) { + String result = null; + SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.getDefault()); + Date nowDate = new Date(); + result = sdf.format(nowDate); + return result; + } + + public static List getIpAddressString() { + List ips = new ArrayList<>(); + try { + /*if (checkLan()){ + //获取有线网ip + MyLog.i("插入有线网"); + return getLocalIp(); + }else { + + }*/ + for (Enumeration enNetI = NetworkInterface.getNetworkInterfaces(); enNetI.hasMoreElements(); ) { + NetworkInterface netI = enNetI.nextElement(); + for (Enumeration enumIpAddr = netI.getInetAddresses(); enumIpAddr.hasMoreElements(); ) { + InetAddress inetAddress = enumIpAddr.nextElement(); + if (inetAddress instanceof Inet4Address && !inetAddress.isLoopbackAddress()) { + ips.add(inetAddress.getHostAddress()); + } + } + } + } catch (SocketException e) { + e.printStackTrace(); + } + return ips; + } + + //检查网线有没有插 + public static boolean checkLan(){ + Process p=null; + BufferedReader in=null; + try { + p = Runtime.getRuntime().exec("cat /sys/class/net/eth0/carrier"); + in = new BufferedReader(new InputStreamReader(p.getInputStream())); + String line = null; + String value = ""; + while ((line = in.readLine()) != null) { + if("0".equals(line)){ + return false; + } + if("1".equals(line)){ + return true; + } + } + } catch (Exception e) { + e.printStackTrace(); + } finally{ + if(in!=null){ + try { + in.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + return false; + } + + /** + * 得到有线网关的IP地址 + * + * @return + */ + private static String getLocalIp() { + try { + // 获取本地设备的所有网络接口 + Enumeration enumerationNi = NetworkInterface + .getNetworkInterfaces(); + while (enumerationNi.hasMoreElements()) { + NetworkInterface networkInterface = enumerationNi.nextElement(); + String interfaceName = networkInterface.getDisplayName(); + + // 如果是有限网卡 + if (interfaceName.equals("eth0")) { + Enumeration enumIpAddr = networkInterface.getInetAddresses(); + while (enumIpAddr.hasMoreElements()) { + // 返回枚举集合中的下一个IP地址信息 + InetAddress inetAddress = enumIpAddr.nextElement(); + // 不是回环地址,并且是ipv4的地址 + if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) { + return inetAddress.getHostAddress(); + } + } + }else { + for (Enumeration enNetI = NetworkInterface.getNetworkInterfaces(); enNetI.hasMoreElements(); ) { + NetworkInterface netI = enNetI.nextElement(); + for (Enumeration enumIpAddr = netI.getInetAddresses(); enumIpAddr.hasMoreElements(); ) { + InetAddress inetAddress = enumIpAddr.nextElement(); + if (inetAddress instanceof Inet4Address && !inetAddress.isLoopbackAddress()) { + return inetAddress.getHostAddress(); + } + } + } + } + } + + } catch (SocketException e) { + e.printStackTrace(); + } + return ""; + + } + + public static byte[] intToBytes(int value, int len) { + byte[] data = new byte[((len >= 4) || (0 == len))? 4: len]; + int offset = 0; + + try { + for (int i = 0; i < data.length; ++i) { + data[i] = (byte)((value >> offset) & 0xff); + offset += 8; + } + } catch (Exception e) { + e.printStackTrace(); + } + + return data; + } +// public static void sendXixunAppBroadcast(final Intent intent) { +// instance.sendBroadcast(intent); +// } + + @SuppressLint({ "NewApi", "Recycle" }) + private static UserHandle initUserHandleAll() { + Parcel parcel = Parcel.obtain(); + parcel.writeInt(-1); + return new UserHandle(parcel); + } + + @SuppressLint("NewApi") + public static void sendXixunAppBroadcast(final Intent intent) { + executeThread(new Runnable() { + @SuppressLint("MissingPermission") + @Override + public void run() { +// intent.setPackage(instance.getPackageName()); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + if (null == userHandleALL) { + userHandleALL = initUserHandleAll(); + } + instance.sendBroadcastAsUser(intent, userHandleALL); + MyLog.e("sendBroadcastAsUser..."); + } else { + MyLog.e("sendBroadcast..."); + instance.sendBroadcast(intent); + } +// MyLog.e("Send broadcast ==> " + intent.getAction()); + } + }); + } + + /** + * 字节转bit + * @param b + * @return + */ + public static String byteToBitString(byte b) { + StringBuilder sb = new StringBuilder(); + for (int i = 7; i >= 0; i--) { + sb.append((b >> i) & 1); + if(i!=0){ + sb.append(","); + } + + } + return sb.toString(); + } + + public static long crc32(byte[] data){ + CRC32 c = new CRC32(); + c.reset();//Resets CRC-32 to initial value. + c.update(data, 0, data.length);//将数据丢入CRC32解码器 + long value = c.getValue();//获取CRC32 的值 默认返回值类型为long 用于保证返回值是一个正数 + return value; + } + //小端模式 + public static long bytesToLong(byte[] value) { + long data = 0; + + if (null != value) { + int len = (value.length >= 4? 4: value.length); + for (int i = 0; i < len; ++i) { + data |= ((value[i] & 0xff) << (i * 8)); + } + } else { + MyLog.d("bytesToLong: There have a null point."); + } + return data & 0xFFFFFFFFL; + } +} diff --git a/app/src/main/java/com/xixun/display/MyLog.java b/app/src/main/java/com/xixun/display/MyLog.java new file mode 100644 index 0000000..84673db --- /dev/null +++ b/app/src/main/java/com/xixun/display/MyLog.java @@ -0,0 +1,281 @@ +package com.xixun.display; + +import android.annotation.SuppressLint; +import android.util.Log; + +import com.xixun.display.utils.CustomConfig; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; + +public class MyLog { + private static final String TAG = "DisplayAPP"; + + public static void sleepForMillisecond(long ms) { + try { + Thread.sleep(ms); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + public static void sleepForSecond(long second) { + sleepForMillisecond(second * 1000); + } + private static String formatStr(String msg) { + StringBuilder show=new StringBuilder(""); + + show.append(msg); + for (int index = 70; index < show.length(); index += 70) { + if (' ' == show.charAt(index - 1)) { + show.insert(index - 1, '\n'); + } else if (' ' == show.charAt(index - 2)) { + show.insert(index - 2, '\n'); + } else { + show.insert(index, '\n'); + } + } + + return show.toString(); + } + + /** + * 重要日志 + * @param msg + */ + public static void i(String msg) { + if (CustomConfig.getInstance().allLog){ + writeLog(msg,false); + Log.i(TAG, formatStr(msg)); + } + } + + /** + * 数据日志 + * @param msg + */ + public static void d(String msg) { + if (CustomConfig.getInstance().isLog){ + writeLog(msg,false); + Log.d(TAG, formatStr(msg)); + } + } + + public static void e(String msg) { + if (CustomConfig.getInstance().allLog){ + writeLog(msg,false); + Log.e(TAG, formatStr(msg)); + } + } + + public static void v(String msg) { + if (CustomConfig.getInstance().isLog){ + writeLog(msg,false); + Log.v(TAG, formatStr(msg)); + } + } + + public static void w(String msg) { + if (CustomConfig.getInstance().allLog){ + writeLog(msg,false); + Log.w(TAG, formatStr(msg)); + } + } + + @SuppressLint("DefaultLocale") + public static void showBytesHex(String title, byte[] msg, int len) { + StringBuilder show=new StringBuilder(""); + int showNum = 0; + int iData = 0; + + /*if ((null != title) && (!title.equals(""))) { + show.append(title + ": "); + } else { + show.append("Hex: "); + }*/ + if (null != msg) { + showNum = (0 == len)? msg.length: len; + if (showNum > msg.length) { + showNum = msg.length; + } + for (int i = 0; i < showNum; ++i) { + iData = msg[i] & 0xff; + if (iData < 16) { + show.append('0'); + } + show.append(Integer.toHexString(iData).toUpperCase()); + show.append(' '); + } + } else { + show.append("Message is null."); + } + d(show.toString()); + writeLogHex(show.toString(),title); +// MyApp.writeLog(show.toString(), false); + } + + @SuppressLint("DefaultLocale") + public static void showBytes(String title, byte[] msg, int len) { + if (CustomConfig.getInstance().isLog){ + StringBuilder show=new StringBuilder(""); + int showNum = 0; + int iData = 0; + + if ((null != title) && (!title.equals(""))) { + show.append(title + ": "); + } else { + show.append("Hex: "); + } + if (null != msg) { + showNum = (0 == len)? msg.length: len; + if (showNum > msg.length) { + showNum = msg.length; + } + for (int i = 0; i < showNum; ++i) { + iData = msg[i] & 0xff; + if (iData < 16) { + show.append('0'); + } + show.append(Integer.toHexString(iData).toUpperCase()); + show.append(' '); + } + } else { + show.append("Message is null."); + } + d(show.toString()); + // MyApp.writeLog(show.toString(), false); + } + } + + @SuppressLint("DefaultLocale") + public static void showLong(String title, long[] msg) { + /*StringBuilder show=new StringBuilder(""); + int showNum = 0; + long iData = 0; + + if ((null != title) && (!title.equals(""))) { + show.append(title + ": "); + } else { + show.append("Hex: "); + } + if (null != msg) { + showNum = (0 == len)? msg.length: len; + if (showNum > msg.length) { + showNum = msg.length; + } + for (int i = 0; i < showNum; ++i) { + iData = (int) msg[i]; + if (iData < 16) { + show.append('0'); + } + show.append(iData); + show.append(' '); + } + } else { + show.append("Message is null."); + }*/ +// d(show.toString()); +// MyApp.writeLog(show.toString(), false); + + for(int i = 0;i " + stack.getMethodName() + + " -> " + stack.getLineNumber() + + ((null != msg)? (": " + msg): "")); + } + + /*public static void json(Object obj) { + try { + Log.i(TAG, MyApp.getMapper().writeValueAsString(obj)); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + }*/ + /** + * 向文件中写入参数数据信息 + * + * @param info + */ + public static boolean writeLogHex(String info,String addr) { + try { +// String log ="7e 7e 55 43 "; + String log =""; + log += info; + log += "\n"; + File logFile = MyApp.getInstance().getFileStreamPath(addr+".txt"); + if (logFile.exists()) { + logFile.delete(); + } + FileOutputStream fileOutputStream = new FileOutputStream(logFile, true); + OutputStreamWriter ouStreamWriter = new OutputStreamWriter(fileOutputStream, "UTF-8"); + ouStreamWriter.write(log); + ouStreamWriter.close(); + fileOutputStream.close(); + return true; + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return false; + } + /** + * 向文件中写入日志信息 + * + * @param info + */ + public static boolean writeLog(String info, boolean enter) { + try { + String log = MyApp.getCurrentDateString("yyyy-MM-dd HH:mm:ss:SSS") + ": "; + if (enter) { + log += "\n\t"; + } + log += info; + log += "\n"; + String cardName = MyApp.getCardId(); + if (!cardName.equals("Android-00001")) { + File logFile = MyApp.getInstance().getFileStreamPath("displayLogs.txt"); + if (logFile.exists() && logFile.length() > 10 * 1024 * 1024) { + logFile.delete(); + } + FileOutputStream fileOutputStream = new FileOutputStream(logFile, true); + OutputStreamWriter ouStreamWriter = new OutputStreamWriter(fileOutputStream, "UTF-8"); + if (0 == logFile.length()) { + ouStreamWriter.write(cardName + ":\n\n"); + } + ouStreamWriter.write(log); + ouStreamWriter.close(); + fileOutputStream.close(); + } + return true; + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return false; + } + + public static String getIntToHex(int iValue) + { + String str = "0x"+Integer.toHexString(iValue).toUpperCase(); + return str; + } + public static String intToHexNo0x(int iValue) + { return ""+Integer.toHexString(iValue).toUpperCase(); + } +} diff --git a/app/src/main/java/com/xixun/display/MyService.java b/app/src/main/java/com/xixun/display/MyService.java new file mode 100644 index 0000000..2049892 --- /dev/null +++ b/app/src/main/java/com/xixun/display/MyService.java @@ -0,0 +1,76 @@ +package com.xixun.display; + +import android.app.Service; +import android.content.Intent; +import android.os.Build; +import android.os.IBinder; +import android.support.annotation.RequiresApi; + +import com.xixun.display.controller.FactoryCard; +import com.xixun.display.controller.XixunCard; +import com.xixun.display.controller.XixunController; +import com.xixun.display.controller.impl.ControllerB; +import com.xixun.display.controller.impl.ControllerC; +import com.xixun.display.controller.impl.ControllerD; +import com.xixun.display.controller.impl.ControllerM; +import com.xixun.display.controller.impl.ControllerP; +import com.xixun.display.controller.impl.ControllerUnknown; +import com.xixun.display.controller.impl.ControllerWX; +import com.xixun.display.controller.impl.ControllerYZ; +import com.xixun.unique.CardType; + +public class MyService extends Service { + @Override + public IBinder onBind(Intent intent){ + return null; + } + + + @Override + public void onCreate() { + super.onCreate(); + MyLog.i("Starting display service ..."); + MyApp.executeThread(new Runnable() { + @Override + public void run() { + // 初始化各种控制卡,供后期根据ROM类型来加载相对应的处理逻辑 + FactoryCard factory = new FactoryCard(); + factory.addItem(CardType.B, ControllerB.class) + .addItem(CardType.P, ControllerP.class) + .addItem(CardType.W, ControllerWX.class) + .addItem(CardType.X, ControllerWX.class) + .addItem(CardType.Y, ControllerYZ.class) + .addItem(CardType.Z, ControllerYZ.class) + .addItem(CardType.M, ControllerM.class) + .addItem(CardType.D, ControllerD.class) + .addItem(CardType.D_2, ControllerD.class) + .addItem(CardType.C, ControllerC.class) + .addItem(CardType.UNKNOWN, ControllerUnknown.class); + MyApp.setFactory(factory); + // 当前控制卡使用的特殊接口,CardType.init(); + MyApp.card().init(); + // Android通用接口 + XixunController.get().init(); + } + }); + } + + @RequiresApi(api = Build.VERSION_CODES.O) + @Override + public void onDestroy() { + // 销毁时重新启动Service + /* MyLog.i(" "+ Thread.currentThread().getStackTrace()[2].getFileName() + "-->" + + "Function: " +Thread.currentThread().getStackTrace()[2].getMethodName() + "-->" + + "Line" +Thread.currentThread().getStackTrace()[2].getLineNumber() + ":\r\n" + ); + MyLog.i("On destory main service, restart myself ..."); + Intent intent = new Intent(); + intent.setClass(this, MyService.class); + MyApp.getInstance().startForegroundService(intent);*/ + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + return START_STICKY; + } +} diff --git a/app/src/main/java/com/xixun/display/RecCardInfo.java b/app/src/main/java/com/xixun/display/RecCardInfo.java new file mode 100644 index 0000000..c2e9232 --- /dev/null +++ b/app/src/main/java/com/xixun/display/RecCardInfo.java @@ -0,0 +1,216 @@ +package com.xixun.display; + +import android.os.Parcel; +import android.os.Parcelable; + + +/** + * Date:2024/1/11 + * Time:10:59 + * author:zwf + */ + +public class RecCardInfo implements Parcelable { + private float temperature;//温度 + private double voltage;//电压 + private int humidity;//湿度 + private int light;//亮度 + private int smoke;//烟雾 + private String isHigh1; + private String isHigh2; + private String isHigh3; + private String isHigh4; + private String isHigh5; + private String isHigh6; + private byte switchState; + + public RecCardInfo() { + } + + @Override + public String toString() { + return "RecCardInfo{" + + "temperature=" + temperature + + ", voltage=" + voltage + + ", humidity=" + humidity + + ", light=" + light + + ", smoke=" + smoke + + ", isHigh1='" + isHigh1 + '\'' + + ", isHigh2='" + isHigh2 + '\'' + + ", isHigh3='" + isHigh3 + '\'' + + ", isHigh4='" + isHigh4 + '\'' + + ", isHigh5='" + isHigh5 + '\'' + + ", isHigh6='" + isHigh6 + '\'' + + ", switchState='" + switchState + '\'' + + '}'; + } + + public RecCardInfo(float temperature, double voltage, int humidity, int light, int smoke, String isHigh1, String isHigh2, String isHigh3, String isHigh4, String isHigh5,String isHigh6,byte switchState) { + this.temperature = temperature; + this.voltage = voltage; + this.humidity = humidity; + this.light = light; + this.smoke = smoke; + this.isHigh1 = isHigh1; + this.isHigh2 = isHigh2; + this.isHigh3 = isHigh3; + this.isHigh4 = isHigh4; + this.isHigh5 = isHigh5; + this.isHigh6 = isHigh6; + this.switchState = switchState; + } + + public float getTemperature() { + return temperature; + } + + public void setTemperature(float temperature) { + this.temperature = temperature; + } + + public double getVoltage() { + return voltage; + } + + public void setVoltage(double voltage) { + this.voltage = voltage; + } + + public int getHumidity() { + return humidity; + } + + public void setHumidity(int humidity) { + this.humidity = humidity; + } + + public int getLight() { + return light; + } + + public void setLight(int light) { + this.light = light; + } + + public int getSmoke() { + return smoke; + } + + public void setSmoke(int smoke) { + this.smoke = smoke; + } + + public String getIsHigh1() { + return isHigh1; + } + + public void setIsHigh1(String isHigh1) { + this.isHigh1 = isHigh1; + } + + public String getIsHigh2() { + return isHigh2; + } + + public void setIsHigh2(String isHigh2) { + this.isHigh2 = isHigh2; + } + + public String getIsHigh3() { + return isHigh3; + } + + public void setIsHigh3(String isHigh3) { + this.isHigh3 = isHigh3; + } + + public String getIsHigh4() { + return isHigh4; + } + + public void setIsHigh4(String isHigh4) { + this.isHigh4 = isHigh4; + } + + public String getIsHigh5() { + return isHigh5; + } + + public void setIsHigh5(String isHigh5) { + this.isHigh5 = isHigh5; + } + + public String getIsHigh6() { + return isHigh6; + } + + public void setIsHigh6(String isHigh6) { + this.isHigh6 = isHigh6; + } + + public static Creator getCREATOR() { + return CREATOR; + } + + public byte getSwitchState() { + return switchState; + } + + public void setSwitchState(byte switchState) { + this.switchState = switchState; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + // TODO Auto-generated method stub + /*将RecCardInfo的成员写入Parcel, + * 注:Parcel中的数据是按顺序写入和读取的,即先被写入的就会先被读取出来 + */ + dest.writeFloat(temperature); + dest.writeDouble(voltage); + dest.writeInt(humidity); + dest.writeInt(light); + dest.writeInt(smoke); + dest.writeString(isHigh1); + dest.writeString(isHigh2); + dest.writeString(isHigh3); + dest.writeString(isHigh4); + dest.writeString(isHigh5); + dest.writeString(isHigh6); + dest.writeByte(switchState); + + } + + //该静态域是必须要有的,而且名字必须是CREATOR,否则会出错 + public static final Creator CREATOR = new Creator() { + @Override + public RecCardInfo createFromParcel(Parcel source) { + float temperature = source.readFloat(); + double voltage = source.readDouble(); + int humidity = source.readInt(); + int light = source.readInt(); + int smoke = source.readInt(); + String isHigh1 = source.readString(); + String isHigh2 = source.readString(); + String isHigh3 = source.readString(); + String isHigh4 = source.readString(); + String isHigh5 = source.readString(); + String isHigh6 = source.readString(); + byte state = source.readByte(); + return new RecCardInfo(temperature, voltage, humidity,light, smoke,isHigh1,isHigh2,isHigh3,isHigh4,isHigh5,isHigh6,state); + } + + @Override + public RecCardInfo[] newArray(int size) { + // TODO Auto-generated method stub + //RecCardInfo + return new RecCardInfo[size]; + } + }; + +} diff --git a/app/src/main/java/com/xixun/display/SettingsService.java b/app/src/main/java/com/xixun/display/SettingsService.java new file mode 100644 index 0000000..cc66617 --- /dev/null +++ b/app/src/main/java/com/xixun/display/SettingsService.java @@ -0,0 +1,202 @@ +package com.xixun.display; + +import android.app.Service; +import android.content.Context; +import android.content.Intent; +import android.os.IBinder; +import android.os.RemoteException; + +import com.xixun.display.backup.SendData; +import com.xixun.display.backup.Vcxbase; +import com.xixun.display.controller.BaseController; +import com.xixun.display.utils.DisplayConfig; + +import org.json.JSONObject; + +import java.util.List; + +import static com.xixun.display.backup.Vcxbase.io_type_reg; +import static com.xixun.display.backup.Vcxbase.make_vcs_io_address; + +public class SettingsService extends Service { + public static Context context; + + @Override + public void onCreate() { +// MyLog.i("Create communication service successful."); + context = this; + super.onCreate(); + } + public static Context getContext() { + return context; + } + @Override + public IBinder onBind(Intent arg0) { +// MyLog.i("Bind communication service successful."); + return new MyBinder(); + } + + /*private final*/ class MyBinder extends MyAidl.Stub { + /* + 设置屏幕亮度 + */ + @Override + public boolean setBrightness(boolean flag, int brightness) throws RemoteException { + MyLog.i("setBrightness............"+brightness); + //update start定制内容:Y30非97BC的版本以64级亮度执行 + /*MooncellFpga mooncellFpga = clientsManage.ledCardCommunication.mooncellFpga; + String oldFpgaVersion = mooncellFpga.getFpgaVersion();//FPGA版本 + String cardName = ledCardCommunication.GetSerialNumber();//卡号 + if (cardName.startsWith("Y30") && !"0x97BC".equals(oldFpgaVersion) && brightness<=64){ + brightness *=4; + } else if (brightness > 64){ + return false; + }*/ + //update end + boolean result= MyApp.card().setBrightness(brightness); + if (!result){ + result= MyApp.card().setBrightness(brightness); + } + if (result){ + DisplayConfig.saveBrightness(brightness); + } + return result; + } + + /* + 获取屏幕亮度 + */ + @Override + public int getBrightness() throws RemoteException { + int result = MyApp.card().getBrightness(); + MyLog.i("getBrightness==============="+result); + //update start定制内容:Y30非97BC的版本以64级亮度执行 + /* MooncellFpga mooncellFpga = clientsManage.ledCardCommunication.mooncellFpga; + String oldFpgaVersion = mooncellFpga.getFpgaVersion();//FPGA版本 + String cardName = ledCardCommunication.GetSerialNumber();//卡号 + if (cardName.startsWith("Y30") && !"0x97BC".equals(oldFpgaVersion)){ + return result/4; + }*/ + //update end + return result==256 ? 255 : result; + } + + /* + 获取接收卡数量 + */ + @Override + public int getReceivedCardNum() throws RemoteException { + int receivedCardNum= 0; + for (int i = 0;i getPointCheckData() throws RemoteException { + return MyApp.card().returnBadPointData(); + } + + @Override + public void savePort(int port) throws RemoteException { + MyApp.card().setPortToConfig(port); + } + + @Override + public RecCardInfo getRecinfo() throws RemoteException { + return MyApp.card().getRecData(); + } + + @Override + public void setRecCardRelaySwitch(boolean isSwitch) throws RemoteException { + MyApp.card().setRecCardRelaySwitch(isSwitch); + } + + + + + } +} diff --git a/app/src/main/java/com/xixun/display/backup/BackUpBuffer.java b/app/src/main/java/com/xixun/display/backup/BackUpBuffer.java new file mode 100644 index 0000000..c4e123b --- /dev/null +++ b/app/src/main/java/com/xixun/display/backup/BackUpBuffer.java @@ -0,0 +1,76 @@ +package com.xixun.display.backup; + +import com.xixun.display.MyApp; +import com.xixun.display.MyLog; + +public class BackUpBuffer { + public InsHeader insHeader; + public byte[] insHeaderbs; + public byte[] data; + + public BackUpBuffer() { + this.insHeader = new InsHeader(); + } + + public InsHeader getInsHeader() { + return insHeader; + } + + public void setInsHeader(InsHeader insHeader) { + this.insHeader = insHeader; + } + + public byte[] getInsHeaderbs() { + return insHeaderbs; + } + + public void setInsHeaderbs(byte[] insHeaderbs) { + this.insHeaderbs = insHeaderbs; + } + + public byte[] getData() { + return data; + } + + public void setData(byte[] data) { + this.data = data; + } + + + public boolean checkData() { + //先判断version是不是0xAA + boolean checkVer = (0xAA == (insHeader.version[0] & 0xFF)); + //在判断header_chksum是否正确 + byte[] checdCodeBs = insHeader.getHeader_chksum(); + int bsum = 0; +// byte check_code = 0; + for (int i=0;i> 8) & 0x00FFFFFF) ^ crc_tab[(int) ((crc ^dat[(int) i]) & 0xFF)]; + } + return (crc ^ 0xFFFFFFFF); + } + + public byte calc_crc8(byte[] dat, long len) { + int i,x; + byte crc=0,crcbuff; + for(x = 0; x < dat.length; x++) { + crcbuff= dat[x]; + for(i = 0; i < 8; i++) { + if(((crc ^ crcbuff)&0x01)==0){ + crc = (byte) (((crc & 0xff) >> 1) & 0xff); + } else { + crc ^= 0x18; + crc = (byte) (((crc & 0xff) >> 1) & 0xff); + crc |= 0x80; + } + crcbuff = (byte) (((crcbuff & 0xff) >> 1) & 0xff); + } + } +// MyLog.i("crc========="+Define.PrintIntToHex(crc)); + return crc; + } + // A1 A2 A3 A4 + public byte calc_crc8_test(byte[] dat, long len) { + int i,x; + byte crc=0,crcbuff; + for(x = 0; x < dat.length; x++) { + crcbuff= dat[x]; + for(i = 0; i < 8; i++) { + if(((crc ^ crcbuff)&0x01)==0){ + crc = (byte) (((crc & 0xff) >> 1) & 0xff); + } else { + crc ^= 0x18; + crc = (byte) (((crc & 0xff) >> 1) & 0xff); + crc |= 0x80; + } +// MyLog.i("x========="+x); +// MyLog.i("i========="+i); +// MyLog.i("crc========="+Define.PrintIntToHex(crc)); + crcbuff = (byte) (((crcbuff & 0xff) >> 1) & 0xff); + } + } + return crc; + } + +} diff --git a/app/src/main/java/com/xixun/display/backup/InsGigeIoDatHeader.java b/app/src/main/java/com/xixun/display/backup/InsGigeIoDatHeader.java new file mode 100644 index 0000000..3f69984 --- /dev/null +++ b/app/src/main/java/com/xixun/display/backup/InsGigeIoDatHeader.java @@ -0,0 +1,121 @@ +package com.xixun.display.backup; + + +import com.xixun.display.MyLog; + +/** + * 网口连接信息索引 + */ +public class InsGigeIoDatHeader { + public byte[] vcs_cnts; //2 + public byte[] gige_port; //1 + public byte[] hub; // 若>=1表示使用HUB. + + public byte[] hub_port; //1 + public byte[] type; //1 + public byte[] dat_index_unit_size; //2 + + public byte[] dat_index_bgn_addr; //4 + + + public InsGigeIoDatHeader() { + this.vcs_cnts = new byte[2]; + this.gige_port = new byte[1]; + this.hub = new byte[1]; + this.hub_port = new byte[1]; + this.type = new byte[1]; + this.dat_index_unit_size = new byte[2]; + this.dat_index_bgn_addr = new byte[4]; + } + + public byte[] getVcs_cnts() { + return vcs_cnts; + } + + public void setVcs_cnts(byte[] vcs_cnts) { + this.vcs_cnts = vcs_cnts; + } + + public byte[] getGige_port() { + return gige_port; + } + + public void setGige_port(byte[] gige_port) { + this.gige_port = gige_port; + } + + public byte[] getHub() { + return hub; + } + + public void setHub(byte[] hub) { + this.hub = hub; + } + + public byte[] getHub_port() { + return hub_port; + } + + public void setHub_port(byte[] hub_port) { + this.hub_port = hub_port; + } + + public byte[] getType() { + return type; + } + + public void setType(byte[] type) { + this.type = type; + } + + public byte[] getDat_index_unit_size() { + return dat_index_unit_size; + } + + public void setDat_index_unit_size(byte[] dat_index_unit_size) { + this.dat_index_unit_size = dat_index_unit_size; + } + + public byte[] getDat_index_bgn_addr() { + return dat_index_bgn_addr; + } + + public void setDat_index_bgn_addr(byte[] dat_index_bgn_addr) { + this.dat_index_bgn_addr = dat_index_bgn_addr; + } + + public void fillData(byte[] data){ + System.arraycopy(data,0,vcs_cnts,0,vcs_cnts.length); + System.arraycopy(data,vcs_cnts.length,gige_port,0,gige_port.length); + System.arraycopy(data,vcs_cnts.length + +gige_port.length,hub,0,hub.length); + System.arraycopy(data,vcs_cnts.length + +gige_port.length + +hub.length,hub_port,0,hub_port.length); + System.arraycopy(data,vcs_cnts.length + +gige_port.length + +hub.length + +hub_port.length,type,0,type.length); + System.arraycopy(data,vcs_cnts.length + +gige_port.length + +hub.length + +hub_port.length + +type.length,dat_index_unit_size,0,dat_index_unit_size.length); + System.arraycopy(data,vcs_cnts.length + +gige_port.length + +hub.length + +hub_port.length + +type.length + +dat_index_unit_size.length,dat_index_bgn_addr,0,dat_index_bgn_addr.length); + } + + public void pln(){ + MyLog.showBytes("vcs_cnts",vcs_cnts,0); + MyLog.showBytes("gige_port",gige_port,0); + MyLog.showBytes("hub",hub,0); + MyLog.showBytes("hub_port",hub_port,0); + MyLog.showBytes("type",type,0); + MyLog.showBytes("dat_index_unit_size",dat_index_unit_size,0); + MyLog.showBytes("dat_index_bgn_addr",dat_index_bgn_addr,0); + } +} diff --git a/app/src/main/java/com/xixun/display/backup/InsHeader.java b/app/src/main/java/com/xixun/display/backup/InsHeader.java new file mode 100644 index 0000000..bca764f --- /dev/null +++ b/app/src/main/java/com/xixun/display/backup/InsHeader.java @@ -0,0 +1,170 @@ +package com.xixun.display.backup; + +import com.xixun.display.MyLog; + +public class InsHeader { + // 巡检数据头 + // 00h + public byte[] version; // 固定为AAh + public byte[] storage_mask; // 数据存储掩码 bit0: 有无显示屏压缩数据 bit1: 有无原始箱体配置指令数据 bit2: 表示有无压缩箱体配置指令数据 bit4: 有无发送卡fpga配置数据 + public byte[] header_size; //2字节 + + // 01h + public byte[] vcm_basic_dat_addr; // 数据基地址 4字节 + + // 显示屏文件压缩回读参数 + // 02h + public byte[] vcm_display_cfg_dat_addr; // flash中显示屏数据的地址 4字节 + public byte[] vcm_display_cfg_dat_size; //4字节 + + + // 原始箱体参数(上/下位机巡检使用) + // 08h + public byte[] vcm_box_cfg_dat_addr; // flash中显示屏数据的地址 4字节 + public byte[] vcm_box_cfg_dat_size; //4字节 + + + // 压缩箱体参数(上位机巡检使用) + // 0Bh + public byte[] vcm_compress_box_cfg_dat_addr; // flash中显示屏数据的地址 4字节 + public byte[] vcm_compress_box_cfg_dat_size; //4字节 + + // 发送卡数据 (云端或本地巡检使用) + // 11h + public byte[] vcm_cfg_dat_addr; //4字节 + public byte[] vcm_cfg_dat_size; //4字节 + // 16h + public byte[] header_crc; // 包头32位crc + public byte[] header_chksum; // 包头32位校验和 + + + public byte[] getVersion() { + return version; + } + + public void setVersion(byte[] version) { + this.version = version; + } + + public byte[] getStorage_mask() { + return storage_mask; + } + + public void setStorage_mask(byte[] storage_mask) { + this.storage_mask = storage_mask; + } + + public byte[] getHeader_size() { + return header_size; + } + + public void setHeader_size(byte[] header_size) { + this.header_size = header_size; + } + + public byte[] getVcm_basic_dat_addr() { + return vcm_basic_dat_addr; + } + + public void setVcm_basic_dat_addr(byte[] vcm_basic_dat_addr) { + this.vcm_basic_dat_addr = vcm_basic_dat_addr; + } + + public byte[] getVcm_display_cfg_dat_addr() { + return vcm_display_cfg_dat_addr; + } + + public void setVcm_display_cfg_dat_addr(byte[] vcm_display_cfg_dat_addr) { + this.vcm_display_cfg_dat_addr = vcm_display_cfg_dat_addr; + } + + public byte[] getVcm_display_cfg_dat_size() { + return vcm_display_cfg_dat_size; + } + + public void setVcm_display_cfg_dat_size(byte[] vcm_display_cfg_dat_size) { + this.vcm_display_cfg_dat_size = vcm_display_cfg_dat_size; + } + + public byte[] getVcm_box_cfg_dat_addr() { + return vcm_box_cfg_dat_addr; + } + + public void setVcm_box_cfg_dat_addr(byte[] vcm_box_cfg_dat_addr) { + this.vcm_box_cfg_dat_addr = vcm_box_cfg_dat_addr; + } + + public byte[] getVcm_box_cfg_dat_size() { + return vcm_box_cfg_dat_size; + } + + public void setVcm_box_cfg_dat_size(byte[] vcm_box_cfg_dat_size) { + this.vcm_box_cfg_dat_size = vcm_box_cfg_dat_size; + } + + public byte[] getVcm_compress_box_cfg_dat_addr() { + return vcm_compress_box_cfg_dat_addr; + } + + public void setVcm_compress_box_cfg_dat_addr(byte[] vcm_compress_box_cfg_dat_addr) { + this.vcm_compress_box_cfg_dat_addr = vcm_compress_box_cfg_dat_addr; + } + + public byte[] getVcm_compress_box_cfg_dat_size() { + return vcm_compress_box_cfg_dat_size; + } + + public void setVcm_compress_box_cfg_dat_size(byte[] vcm_compress_box_cfg_dat_size) { + this.vcm_compress_box_cfg_dat_size = vcm_compress_box_cfg_dat_size; + } + + public byte[] getVcm_cfg_dat_addr() { + return vcm_cfg_dat_addr; + } + + public void setVcm_cfg_dat_addr(byte[] vcm_cfg_dat_addr) { + this.vcm_cfg_dat_addr = vcm_cfg_dat_addr; + } + + public byte[] getVcm_cfg_dat_size() { + return vcm_cfg_dat_size; + } + + public void setVcm_cfg_dat_size(byte[] vcm_cfg_dat_size) { + this.vcm_cfg_dat_size = vcm_cfg_dat_size; + } + + public byte[] getHeader_crc() { + return header_crc; + } + + public void setHeader_crc(byte[] header_crc) { + this.header_crc = header_crc; + } + + public byte[] getHeader_chksum() { + return header_chksum; + } + + public void setHeader_chksum(byte[] header_chksum) { + this.header_chksum = header_chksum; + } + + + public void prn() { + MyLog.showBytes("version",version,0); + MyLog.showBytes("storage_mask",storage_mask,0); + MyLog.showBytes("header_size",header_size,0); + MyLog.showBytes("vcm_basic_dat_addr",vcm_basic_dat_addr,0); + MyLog.showBytes("vcm_display_cfg_dat_addr",vcm_display_cfg_dat_addr,0); + MyLog.showBytes("vcm_display_cfg_dat_size",vcm_display_cfg_dat_size,0); + MyLog.showBytes("vcm_box_cfg_dat_addr",vcm_box_cfg_dat_addr,0); + MyLog.showBytes("vcm_box_cfg_dat_size",vcm_box_cfg_dat_size,0); + MyLog.showBytes("vcm_compress_box_cfg_dat_addr",vcm_compress_box_cfg_dat_addr,0); + MyLog.showBytes("vcm_compress_box_cfg_dat_size",vcm_compress_box_cfg_dat_size,0); + MyLog.showBytes("vcm_cfg_dat_addr",vcm_cfg_dat_addr,0); + MyLog.showBytes("vcm_cfg_dat_size",vcm_cfg_dat_size,0); + MyLog.showBytes("header_crc",header_crc,0); + MyLog.showBytes("header_chksum",header_chksum,0); + } +} diff --git a/app/src/main/java/com/xixun/display/backup/InsVcmCfgDatParas.java b/app/src/main/java/com/xixun/display/backup/InsVcmCfgDatParas.java new file mode 100644 index 0000000..dfae74a --- /dev/null +++ b/app/src/main/java/com/xixun/display/backup/InsVcmCfgDatParas.java @@ -0,0 +1,106 @@ +package com.xixun.display.backup; + +/** + * 发送卡数据 + */ +public class InsVcmCfgDatParas { + + public byte[] ver; // 固定 0xAAAAAA01 + public byte[] header_size; // 包头数据大小 + + // 0Ch + public byte[] gige_port_count; + public byte[] gige_port_cfg_unit_size; + public byte[] vcm_gige_port_cfg_addr; + + public byte[] img_ctl_dat_size; + public byte[] vcm_img_ctl_dat_addr; + + public byte[] vcm_cfg_dat_paras_chksum; + + public InsVcmCfgDatParas() { + this.ver = new byte[4]; + this.header_size = new byte[4]; + this.gige_port_count = new byte[4]; + this.gige_port_cfg_unit_size = new byte[4]; + this.vcm_gige_port_cfg_addr = new byte[4]; + this.img_ctl_dat_size = new byte[4]; + this.vcm_img_ctl_dat_addr = new byte[4]; + this.vcm_cfg_dat_paras_chksum = new byte[4]; + } + + public byte[] getVer() { + return ver; + } + + public void setVer(byte[] ver) { + this.ver = ver; + } + + public byte[] getHeader_size() { + return header_size; + } + + public void setHeader_size(byte[] header_size) { + this.header_size = header_size; + } + + public byte[] getGige_port_count() { + return gige_port_count; + } + + public void setGige_port_count(byte[] gige_port_count) { + this.gige_port_count = gige_port_count; + } + + public byte[] getGige_port_cfg_unit_size() { + return gige_port_cfg_unit_size; + } + + public void setGige_port_cfg_unit_size(byte[] gige_port_cfg_unit_size) { + this.gige_port_cfg_unit_size = gige_port_cfg_unit_size; + } + + public byte[] getVcm_gige_port_cfg_addr() { + return vcm_gige_port_cfg_addr; + } + + public void setVcm_gige_port_cfg_addr(byte[] vcm_gige_port_cfg_addr) { + this.vcm_gige_port_cfg_addr = vcm_gige_port_cfg_addr; + } + + public byte[] getImg_ctl_dat_size() { + return img_ctl_dat_size; + } + + public void setImg_ctl_dat_size(byte[] img_ctl_dat_size) { + this.img_ctl_dat_size = img_ctl_dat_size; + } + + public byte[] getVcm_img_ctl_dat_addr() { + return vcm_img_ctl_dat_addr; + } + + public void setVcm_img_ctl_dat_addr(byte[] vcm_img_ctl_dat_addr) { + this.vcm_img_ctl_dat_addr = vcm_img_ctl_dat_addr; + } + + public byte[] getVcm_cfg_dat_paras_chksum() { + return vcm_cfg_dat_paras_chksum; + } + + public void setVcm_cfg_dat_paras_chksum(byte[] vcm_cfg_dat_paras_chksum) { + this.vcm_cfg_dat_paras_chksum = vcm_cfg_dat_paras_chksum; + } + + public void fillData(byte[] data){ + System.arraycopy(data,0,ver,0,ver.length); + System.arraycopy(data,4,header_size,0,header_size.length); + System.arraycopy(data,8,gige_port_count,0,gige_port_count.length); + System.arraycopy(data,12,gige_port_cfg_unit_size,0,gige_port_cfg_unit_size.length); + System.arraycopy(data,16,vcm_gige_port_cfg_addr,0,vcm_gige_port_cfg_addr.length); + System.arraycopy(data,20,img_ctl_dat_size,0,img_ctl_dat_size.length); + System.arraycopy(data,24,vcm_img_ctl_dat_addr,0,vcm_img_ctl_dat_addr.length); + System.arraycopy(data,28,vcm_cfg_dat_paras_chksum,0,vcm_cfg_dat_paras_chksum.length); + } +} diff --git a/app/src/main/java/com/xixun/display/backup/InsVcsCmdIndex.java b/app/src/main/java/com/xixun/display/backup/InsVcsCmdIndex.java new file mode 100644 index 0000000..5ca7f6a --- /dev/null +++ b/app/src/main/java/com/xixun/display/backup/InsVcsCmdIndex.java @@ -0,0 +1,43 @@ +package com.xixun.display.backup; + +public class InsVcsCmdIndex { + public byte[] vcm_cmd_pkt_addr; + public byte[] cmd_pkt_cnt; + public byte[] cmd_pkt_unit_size; + + public InsVcsCmdIndex() { + this.vcm_cmd_pkt_addr = new byte[4]; + this.cmd_pkt_cnt = new byte[4]; + this.cmd_pkt_unit_size = new byte[4]; + } + + public byte[] getVcm_cmd_pkt_addr() { + return vcm_cmd_pkt_addr; + } + + public void setVcm_cmd_pkt_addr(byte[] vcm_cmd_pkt_addr) { + this.vcm_cmd_pkt_addr = vcm_cmd_pkt_addr; + } + + public byte[] getCmd_pkt_cnt() { + return cmd_pkt_cnt; + } + + public void setCmd_pkt_cnt(byte[] cmd_pkt_cnt) { + this.cmd_pkt_cnt = cmd_pkt_cnt; + } + + public byte[] getCmd_pkt_unit_size() { + return cmd_pkt_unit_size; + } + + public void setCmd_pkt_unit_size(byte[] cmd_pkt_unit_size) { + this.cmd_pkt_unit_size = cmd_pkt_unit_size; + } + + public void fillData(byte[] data){ + System.arraycopy(data,0,vcm_cmd_pkt_addr,0,vcm_cmd_pkt_addr.length); + System.arraycopy(data,4,cmd_pkt_cnt,0,cmd_pkt_cnt.length); + System.arraycopy(data,8,cmd_pkt_unit_size,0,cmd_pkt_unit_size.length); + } +} diff --git a/app/src/main/java/com/xixun/display/backup/InsVcsDatIndex.java b/app/src/main/java/com/xixun/display/backup/InsVcsDatIndex.java new file mode 100644 index 0000000..2e84f1b --- /dev/null +++ b/app/src/main/java/com/xixun/display/backup/InsVcsDatIndex.java @@ -0,0 +1,79 @@ +package com.xixun.display.backup; + +/** + * 接收卡地址索引 + */ +public class InsVcsDatIndex { + public byte[] vcs; + public byte[] vcm_box_chk_dat_idx; + public byte[] vcm_box_cfg_dat_idx; + public byte[] vcm_box_gamma_dat_idx; + public byte[] vcm_box_xy_dat_idx; + public byte[] vcm_box_save_dat_idx; + + public InsVcsDatIndex() { + this.vcs = new byte[2]; + this.vcm_box_chk_dat_idx = new byte[2]; + this.vcm_box_cfg_dat_idx = new byte[2]; + this.vcm_box_gamma_dat_idx = new byte[2]; + this.vcm_box_xy_dat_idx = new byte[2]; + this.vcm_box_save_dat_idx = new byte[2]; + } + + public byte[] getVcs() { + return vcs; + } + + public void setVcs(byte[] vcs) { + this.vcs = vcs; + } + + public byte[] getVcm_box_chk_dat_idx() { + return vcm_box_chk_dat_idx; + } + + public void setVcm_box_chk_dat_idx(byte[] vcm_box_chk_dat_idx) { + this.vcm_box_chk_dat_idx = vcm_box_chk_dat_idx; + } + + public byte[] getVcm_box_cfg_dat_idx() { + return vcm_box_cfg_dat_idx; + } + + public void setVcm_box_cfg_dat_idx(byte[] vcm_box_cfg_dat_idx) { + this.vcm_box_cfg_dat_idx = vcm_box_cfg_dat_idx; + } + + public byte[] getVcm_box_gamma_dat_idx() { + return vcm_box_gamma_dat_idx; + } + + public void setVcm_box_gamma_dat_idx(byte[] vcm_box_gamma_dat_idx) { + this.vcm_box_gamma_dat_idx = vcm_box_gamma_dat_idx; + } + + public byte[] getVcm_box_xy_dat_idx() { + return vcm_box_xy_dat_idx; + } + + public void setVcm_box_xy_dat_idx(byte[] vcm_box_xy_dat_idx) { + this.vcm_box_xy_dat_idx = vcm_box_xy_dat_idx; + } + + public byte[] getVcm_box_save_dat_idx() { + return vcm_box_save_dat_idx; + } + + public void setVcm_box_save_dat_idx(byte[] vcm_box_save_dat_idx) { + this.vcm_box_save_dat_idx = vcm_box_save_dat_idx; + } + + public void fillData(byte[] data){ + System.arraycopy(data,0,vcs,0,vcs.length); + System.arraycopy(data,2,vcm_box_chk_dat_idx,0,vcm_box_chk_dat_idx.length); + System.arraycopy(data,4,vcm_box_cfg_dat_idx,0,vcm_box_cfg_dat_idx.length); + System.arraycopy(data,6,vcm_box_gamma_dat_idx,0,vcm_box_gamma_dat_idx.length); + System.arraycopy(data,8,vcm_box_xy_dat_idx,0,vcm_box_xy_dat_idx.length); + System.arraycopy(data,10,vcm_box_save_dat_idx,0,vcm_box_save_dat_idx.length); + } +} diff --git a/app/src/main/java/com/xixun/display/backup/InsVcsIoDatItem.java b/app/src/main/java/com/xixun/display/backup/InsVcsIoDatItem.java new file mode 100644 index 0000000..8c609f6 --- /dev/null +++ b/app/src/main/java/com/xixun/display/backup/InsVcsIoDatItem.java @@ -0,0 +1,46 @@ +package com.xixun.display.backup; + +/** + * 接收卡数据包 + */ +public class InsVcsIoDatItem { + public byte[] vcm_io_dat_fls_addr; + public byte[] vcs_io_dat_addr; + public byte[] vcs_io_dat_len; + + public InsVcsIoDatItem() { + this.vcm_io_dat_fls_addr = new byte[4]; + this.vcs_io_dat_addr = new byte[4]; + this.vcs_io_dat_len = new byte[4]; + } + + public byte[] getVcm_io_dat_fls_addr() { + return vcm_io_dat_fls_addr; + } + + public void setVcm_io_dat_fls_addr(byte[] vcm_io_dat_fls_addr) { + this.vcm_io_dat_fls_addr = vcm_io_dat_fls_addr; + } + + public byte[] getVcs_io_dat_addr() { + return vcs_io_dat_addr; + } + + public void setVcs_io_dat_addr(byte[] vcs_io_dat_addr) { + this.vcs_io_dat_addr = vcs_io_dat_addr; + } + + public byte[] getVcs_io_dat_len() { + return vcs_io_dat_len; + } + + public void setVcs_io_dat_len(byte[] vcs_io_dat_len) { + this.vcs_io_dat_len = vcs_io_dat_len; + } + + public void fillData(byte[] data){ + System.arraycopy(data,0,vcm_io_dat_fls_addr,0,vcm_io_dat_fls_addr.length); + System.arraycopy(data,4,vcs_io_dat_addr,0,vcs_io_dat_addr.length); + System.arraycopy(data,8,vcs_io_dat_len,0,vcs_io_dat_len.length); + } +} diff --git a/app/src/main/java/com/xixun/display/backup/ReCardHeader.java b/app/src/main/java/com/xixun/display/backup/ReCardHeader.java new file mode 100644 index 0000000..ebb099c --- /dev/null +++ b/app/src/main/java/com/xixun/display/backup/ReCardHeader.java @@ -0,0 +1,667 @@ +package com.xixun.display.backup; + +import com.xixun.display.MyApp; + +public class ReCardHeader { + public byte[] reCardHeader; + // 原始箱体参数索引数据头 + public byte[] ver; // 固定 0xAAAAAA01 + public byte[] header_size; // 包头数据大小 + + public byte[] box_dat_type; // 箱体数据类型 + // 0Ch + public byte[] vcm_gige_access_dat_bgn_addr; + public byte[] gige_access_addr_cnt; // 千兆网访问地址数量 + public byte[] gige_access_item_unit_size; + + public byte[] vcm_box_chk_dat_bgn_addr; + public byte[] box_chk_dat_cnts; + public byte[] box_chk_dat_index_unit_size; + + public byte[] vcm_box_cfg_dat_bgn_addr; + public byte[] box_cfg_dat_cnts; + public byte[] box_cfg_dat_index_unit_size; + + public byte[] vcm_box_gamma_dat_bgn_addr; + public byte[] box_gamma_dat_cnts; + public byte[] box_gamma_dat_index_unit_size; + + public byte[] enable_broardcast_save_xy; // 是否支持广播固化数据,若支持则忽略执行vcs_save_xy_dat_addr逻辑固化接收卡位置 + public byte[] vcs_save_xy_dat_addr; // 如果不支持广播固化,则需要使用当前地址替换vcs_send_xy_dat_addr发送地址进行数据写入 + public byte[] vcs_send_xy_dat_addr; + + public byte[] vcs_gamma_save_mode; // 若为1表示使用60套gamma逻辑固化 + + public byte[] vcm_box_xy_dat_bgn_addr; + public byte[] box_xy_dat_cnts; + public byte[] box_xy_dat_unit_size; + + public byte[] vcm_box_save_dat_bgn_addr; + public byte[] box_save_dat_item_cnts; + public byte[] box_save_dat_item_unit_size; + + public byte[] vcs_cfg_dat_paras_chksum; + + public ReCardHeader() { + this.reCardHeader = new byte[26*4]; + this.ver = new byte[4]; + this.header_size = new byte[4]; + this.box_dat_type = new byte[4]; + this.vcm_gige_access_dat_bgn_addr = new byte[4]; + this.gige_access_addr_cnt = new byte[4]; + this.gige_access_item_unit_size = new byte[4]; + this.vcm_box_chk_dat_bgn_addr = new byte[4]; + this.box_chk_dat_cnts = new byte[4]; + this.box_chk_dat_index_unit_size = new byte[4]; + this.vcm_box_cfg_dat_bgn_addr = new byte[4]; + this.box_cfg_dat_cnts = new byte[4]; + this.box_cfg_dat_index_unit_size = new byte[4]; + this.vcm_box_gamma_dat_bgn_addr = new byte[4]; + this.box_gamma_dat_cnts = new byte[4]; + this.box_gamma_dat_index_unit_size = new byte[4]; + this.enable_broardcast_save_xy = new byte[4]; + this.vcs_save_xy_dat_addr = new byte[4]; + this.vcs_send_xy_dat_addr = new byte[4]; + this.vcs_gamma_save_mode = new byte[4]; + this.vcm_box_xy_dat_bgn_addr = new byte[4]; + this.box_xy_dat_cnts = new byte[4]; + this.box_xy_dat_unit_size = new byte[4]; + this.vcm_box_save_dat_bgn_addr = new byte[4]; + this.box_save_dat_item_cnts = new byte[4]; + this.box_save_dat_item_unit_size = new byte[4]; + this.vcs_cfg_dat_paras_chksum = new byte[4]; + } + + public byte[] getReCardHeader() { + return reCardHeader; + } + + public void setReCardHeader(byte[] reCardHeader) { + this.reCardHeader = reCardHeader; + //填充其他数据 + fillDataToReCardHeaderOtherValue(); + } + + public byte[] getVer() { + return ver; + } + + public void setVer(byte[] ver) { + this.ver = ver; + } + + public byte[] getHeader_size() { + return header_size; + } + + public void setHeader_size(byte[] header_size) { + this.header_size = header_size; + } + + public byte[] getBox_dat_type() { + return box_dat_type; + } + + public void setBox_dat_type(byte[] box_dat_type) { + this.box_dat_type = box_dat_type; + } + + public byte[] getVcm_gige_access_dat_bgn_addr() { + return vcm_gige_access_dat_bgn_addr; + } + + public void setVcm_gige_access_dat_bgn_addr(byte[] vcm_gige_access_dat_bgn_addr) { + this.vcm_gige_access_dat_bgn_addr = vcm_gige_access_dat_bgn_addr; + } + + public byte[] getGige_access_addr_cnt() { + return gige_access_addr_cnt; + } + + public void setGige_access_addr_cnt(byte[] gige_access_addr_cnt) { + this.gige_access_addr_cnt = gige_access_addr_cnt; + } + + public byte[] getGige_access_item_unit_size() { + return gige_access_item_unit_size; + } + + public void setGige_access_item_unit_size(byte[] gige_access_item_unit_size) { + this.gige_access_item_unit_size = gige_access_item_unit_size; + } + + public byte[] getVcm_box_chk_dat_bgn_addr() { + return vcm_box_chk_dat_bgn_addr; + } + + public void setVcm_box_chk_dat_bgn_addr(byte[] vcm_box_chk_dat_bgn_addr) { + this.vcm_box_chk_dat_bgn_addr = vcm_box_chk_dat_bgn_addr; + } + + public byte[] getBox_chk_dat_cnts() { + return box_chk_dat_cnts; + } + + public void setBox_chk_dat_cnts(byte[] box_chk_dat_cnts) { + this.box_chk_dat_cnts = box_chk_dat_cnts; + } + + public byte[] getBox_chk_dat_index_unit_size() { + return box_chk_dat_index_unit_size; + } + + public void setBox_chk_dat_index_unit_size(byte[] box_chk_dat_index_unit_size) { + this.box_chk_dat_index_unit_size = box_chk_dat_index_unit_size; + } + + public byte[] getVcm_box_cfg_dat_bgn_addr() { + return vcm_box_cfg_dat_bgn_addr; + } + + public void setVcm_box_cfg_dat_bgn_addr(byte[] vcm_box_cfg_dat_bgn_addr) { + this.vcm_box_cfg_dat_bgn_addr = vcm_box_cfg_dat_bgn_addr; + } + + public byte[] getBox_cfg_dat_cnts() { + return box_cfg_dat_cnts; + } + + public void setBox_cfg_dat_cnts(byte[] box_cfg_dat_cnts) { + this.box_cfg_dat_cnts = box_cfg_dat_cnts; + } + + public byte[] getBox_cfg_dat_index_unit_size() { + return box_cfg_dat_index_unit_size; + } + + public void setBox_cfg_dat_index_unit_size(byte[] box_cfg_dat_index_unit_size) { + this.box_cfg_dat_index_unit_size = box_cfg_dat_index_unit_size; + } + + public byte[] getVcm_box_gamma_dat_bgn_addr() { + return vcm_box_gamma_dat_bgn_addr; + } + + public void setVcm_box_gamma_dat_bgn_addr(byte[] vcm_box_gamma_dat_bgn_addr) { + this.vcm_box_gamma_dat_bgn_addr = vcm_box_gamma_dat_bgn_addr; + } + + public byte[] getBox_gamma_dat_cnts() { + return box_gamma_dat_cnts; + } + + public void setBox_gamma_dat_cnts(byte[] box_gamma_dat_cnts) { + this.box_gamma_dat_cnts = box_gamma_dat_cnts; + } + + public byte[] getBox_gamma_dat_index_unit_size() { + return box_gamma_dat_index_unit_size; + } + + public void setBox_gamma_dat_index_unit_size(byte[] box_gamma_dat_index_unit_size) { + this.box_gamma_dat_index_unit_size = box_gamma_dat_index_unit_size; + } + + public byte[] getEnable_broardcast_save_xy() { + return enable_broardcast_save_xy; + } + + public void setEnable_broardcast_save_xy(byte[] enable_broardcast_save_xy) { + this.enable_broardcast_save_xy = enable_broardcast_save_xy; + } + + public byte[] getVcs_save_xy_dat_addr() { + return vcs_save_xy_dat_addr; + } + + public void setVcs_save_xy_dat_addr(byte[] vcs_save_xy_dat_addr) { + this.vcs_save_xy_dat_addr = vcs_save_xy_dat_addr; + } + + public byte[] getVcs_send_xy_dat_addr() { + return vcs_send_xy_dat_addr; + } + + public void setVcs_send_xy_dat_addr(byte[] vcs_send_xy_dat_addr) { + this.vcs_send_xy_dat_addr = vcs_send_xy_dat_addr; + } + + public byte[] getVcs_gamma_save_mode() { + return vcs_gamma_save_mode; + } + + public void setVcs_gamma_save_mode(byte[] vcs_gamma_save_mode) { + this.vcs_gamma_save_mode = vcs_gamma_save_mode; + } + + public byte[] getVcm_box_xy_dat_bgn_addr() { + return vcm_box_xy_dat_bgn_addr; + } + + public void setVcm_box_xy_dat_bgn_addr(byte[] vcm_box_xy_dat_bgn_addr) { + this.vcm_box_xy_dat_bgn_addr = vcm_box_xy_dat_bgn_addr; + } + + public byte[] getBox_xy_dat_cnts() { + return box_xy_dat_cnts; + } + + public void setBox_xy_dat_cnts(byte[] box_xy_dat_cnts) { + this.box_xy_dat_cnts = box_xy_dat_cnts; + } + + public byte[] getBox_xy_dat_unit_size() { + return box_xy_dat_unit_size; + } + + public void setBox_xy_dat_unit_size(byte[] box_xy_dat_unit_size) { + this.box_xy_dat_unit_size = box_xy_dat_unit_size; + } + + public byte[] getVcm_box_save_dat_bgn_addr() { + return vcm_box_save_dat_bgn_addr; + } + + public void setVcm_box_save_dat_bgn_addr(byte[] vcm_box_save_dat_bgn_addr) { + this.vcm_box_save_dat_bgn_addr = vcm_box_save_dat_bgn_addr; + } + + public byte[] getBox_save_dat_item_cnts() { + return box_save_dat_item_cnts; + } + + public void setBox_save_dat_item_cnts(byte[] box_save_dat_item_cnts) { + this.box_save_dat_item_cnts = box_save_dat_item_cnts; + } + + public byte[] getBox_save_dat_item_unit_size() { + return box_save_dat_item_unit_size; + } + + public void setBox_save_dat_item_unit_size(byte[] box_save_dat_item_unit_size) { + this.box_save_dat_item_unit_size = box_save_dat_item_unit_size; + } + + public byte[] getVcs_cfg_dat_paras_chksum() { + return vcs_cfg_dat_paras_chksum; + } + + public void setVcs_cfg_dat_paras_chksum(byte[] vcs_cfg_dat_paras_chksum) { + this.vcs_cfg_dat_paras_chksum = vcs_cfg_dat_paras_chksum; + } + + + private void fillDataToReCardHeaderOtherValue() { + System.arraycopy(reCardHeader,0,ver,0,ver.length); + System.arraycopy(reCardHeader,ver.length,header_size,0,header_size.length); + System.arraycopy(reCardHeader,ver.length + +header_size.length,box_dat_type,0,box_dat_type.length); + System.arraycopy(reCardHeader,ver.length + +header_size.length + +box_dat_type.length,vcm_gige_access_dat_bgn_addr,0,vcm_gige_access_dat_bgn_addr.length); + System.arraycopy(reCardHeader,ver.length + +header_size.length + +box_dat_type.length + +vcm_gige_access_dat_bgn_addr.length,gige_access_addr_cnt,0,gige_access_addr_cnt.length); + System.arraycopy(reCardHeader,ver.length + +header_size.length + +box_dat_type.length + +vcm_gige_access_dat_bgn_addr.length + +gige_access_addr_cnt.length,gige_access_item_unit_size,0,gige_access_item_unit_size.length); + System.arraycopy(reCardHeader,ver.length + +header_size.length + +box_dat_type.length + +vcm_gige_access_dat_bgn_addr.length + +gige_access_addr_cnt.length + +gige_access_item_unit_size.length,vcm_box_chk_dat_bgn_addr,0,vcm_box_chk_dat_bgn_addr.length); + System.arraycopy(reCardHeader,ver.length + +header_size.length + +box_dat_type.length + +vcm_gige_access_dat_bgn_addr.length + +gige_access_addr_cnt.length + +gige_access_item_unit_size.length + +vcm_box_chk_dat_bgn_addr.length,box_chk_dat_cnts,0,box_chk_dat_cnts.length); + System.arraycopy(reCardHeader,ver.length + +header_size.length + +box_dat_type.length + +vcm_gige_access_dat_bgn_addr.length + +gige_access_addr_cnt.length + +gige_access_item_unit_size.length + +vcm_box_chk_dat_bgn_addr.length+ + box_chk_dat_cnts.length,box_chk_dat_index_unit_size,0,box_chk_dat_index_unit_size.length); + System.arraycopy(reCardHeader,ver.length + +header_size.length + +box_dat_type.length + +vcm_gige_access_dat_bgn_addr.length + +gige_access_addr_cnt.length + +gige_access_item_unit_size.length + +vcm_box_chk_dat_bgn_addr.length+ + box_chk_dat_cnts.length + +box_chk_dat_index_unit_size.length,vcm_box_cfg_dat_bgn_addr,0,vcm_box_cfg_dat_bgn_addr.length); + System.arraycopy(reCardHeader,ver.length + +header_size.length + +box_dat_type.length + +vcm_gige_access_dat_bgn_addr.length + +gige_access_addr_cnt.length + +gige_access_item_unit_size.length + +vcm_box_chk_dat_bgn_addr.length+ + box_chk_dat_cnts.length + +box_chk_dat_index_unit_size.length + +vcm_box_cfg_dat_bgn_addr.length,box_cfg_dat_cnts,0,box_cfg_dat_cnts.length); + System.arraycopy(reCardHeader,ver.length + +header_size.length + +box_dat_type.length + +vcm_gige_access_dat_bgn_addr.length + +gige_access_addr_cnt.length + +gige_access_item_unit_size.length + +vcm_box_chk_dat_bgn_addr.length+ + box_chk_dat_cnts.length + +box_chk_dat_index_unit_size.length + +vcm_box_cfg_dat_bgn_addr.length + +box_cfg_dat_cnts.length,box_cfg_dat_index_unit_size,0,box_cfg_dat_index_unit_size.length); + System.arraycopy(reCardHeader,ver.length + +header_size.length + +box_dat_type.length + +vcm_gige_access_dat_bgn_addr.length + +gige_access_addr_cnt.length + +gige_access_item_unit_size.length + +vcm_box_chk_dat_bgn_addr.length+ + box_chk_dat_cnts.length + +box_chk_dat_index_unit_size.length + +vcm_box_cfg_dat_bgn_addr.length + +box_cfg_dat_cnts.length + +box_cfg_dat_index_unit_size.length,vcm_box_gamma_dat_bgn_addr,0,vcm_box_gamma_dat_bgn_addr.length); + System.arraycopy(reCardHeader,ver.length + +header_size.length + +box_dat_type.length + +vcm_gige_access_dat_bgn_addr.length + +gige_access_addr_cnt.length + +gige_access_item_unit_size.length + +vcm_box_chk_dat_bgn_addr.length+ + box_chk_dat_cnts.length + +box_chk_dat_index_unit_size.length + +vcm_box_cfg_dat_bgn_addr.length + +box_cfg_dat_cnts.length + +box_cfg_dat_index_unit_size.length + +vcm_box_gamma_dat_bgn_addr.length,box_gamma_dat_cnts,0,box_gamma_dat_cnts.length); + System.arraycopy(reCardHeader,ver.length + +header_size.length + +box_dat_type.length + +vcm_gige_access_dat_bgn_addr.length + +gige_access_addr_cnt.length + +gige_access_item_unit_size.length + +vcm_box_chk_dat_bgn_addr.length+ + box_chk_dat_cnts.length + +box_chk_dat_index_unit_size.length + +vcm_box_cfg_dat_bgn_addr.length + +box_cfg_dat_cnts.length + +box_cfg_dat_index_unit_size.length + +vcm_box_gamma_dat_bgn_addr.length + +box_gamma_dat_cnts.length,box_gamma_dat_index_unit_size,0,box_gamma_dat_index_unit_size.length); + System.arraycopy(reCardHeader,ver.length + +header_size.length + +box_dat_type.length + +vcm_gige_access_dat_bgn_addr.length + +gige_access_addr_cnt.length + +gige_access_item_unit_size.length + +vcm_box_chk_dat_bgn_addr.length+ + box_chk_dat_cnts.length + +box_chk_dat_index_unit_size.length + +vcm_box_cfg_dat_bgn_addr.length + +box_cfg_dat_cnts.length + +box_cfg_dat_index_unit_size.length + +vcm_box_gamma_dat_bgn_addr.length + +box_gamma_dat_cnts.length + +box_gamma_dat_index_unit_size.length,enable_broardcast_save_xy,0,enable_broardcast_save_xy.length); + System.arraycopy(reCardHeader,ver.length + +header_size.length + +box_dat_type.length + +vcm_gige_access_dat_bgn_addr.length + +gige_access_addr_cnt.length + +gige_access_item_unit_size.length + +vcm_box_chk_dat_bgn_addr.length+ + box_chk_dat_cnts.length + +box_chk_dat_index_unit_size.length + +vcm_box_cfg_dat_bgn_addr.length + +box_cfg_dat_cnts.length + +box_cfg_dat_index_unit_size.length + +vcm_box_gamma_dat_bgn_addr.length + +box_gamma_dat_cnts.length + +box_gamma_dat_index_unit_size.length + +enable_broardcast_save_xy.length,vcs_save_xy_dat_addr,0,vcs_save_xy_dat_addr.length); + System.arraycopy(reCardHeader,ver.length + +header_size.length + +box_dat_type.length + +vcm_gige_access_dat_bgn_addr.length + +gige_access_addr_cnt.length + +gige_access_item_unit_size.length + +vcm_box_chk_dat_bgn_addr.length + +box_chk_dat_cnts.length + +box_chk_dat_index_unit_size.length + +vcm_box_cfg_dat_bgn_addr.length + +box_cfg_dat_cnts.length + +box_cfg_dat_index_unit_size.length + +vcm_box_gamma_dat_bgn_addr.length + +box_gamma_dat_cnts.length + +box_gamma_dat_index_unit_size.length + +enable_broardcast_save_xy.length + +vcs_save_xy_dat_addr.length,vcs_send_xy_dat_addr,0,vcs_send_xy_dat_addr.length); + System.arraycopy(reCardHeader,ver.length + +header_size.length + +box_dat_type.length + +vcm_gige_access_dat_bgn_addr.length + +gige_access_addr_cnt.length + +gige_access_item_unit_size.length + +vcm_box_chk_dat_bgn_addr.length + +box_chk_dat_cnts.length + +box_chk_dat_index_unit_size.length + +vcm_box_cfg_dat_bgn_addr.length + +box_cfg_dat_cnts.length + +box_cfg_dat_index_unit_size.length + +vcm_box_gamma_dat_bgn_addr.length + +box_gamma_dat_cnts.length + +box_gamma_dat_index_unit_size.length + +enable_broardcast_save_xy.length + +vcs_save_xy_dat_addr.length + +vcs_send_xy_dat_addr.length,vcs_gamma_save_mode,0,vcs_gamma_save_mode.length); + System.arraycopy(reCardHeader,ver.length + +header_size.length + +box_dat_type.length + +vcm_gige_access_dat_bgn_addr.length + +gige_access_addr_cnt.length + +gige_access_item_unit_size.length + +vcm_box_chk_dat_bgn_addr.length + +box_chk_dat_cnts.length + +box_chk_dat_index_unit_size.length + +vcm_box_cfg_dat_bgn_addr.length + +box_cfg_dat_cnts.length + +box_cfg_dat_index_unit_size.length + +vcm_box_gamma_dat_bgn_addr.length + +box_gamma_dat_cnts.length + +box_gamma_dat_index_unit_size.length + +enable_broardcast_save_xy.length + +vcs_save_xy_dat_addr.length + +vcs_send_xy_dat_addr.length + +vcs_gamma_save_mode.length,vcm_box_xy_dat_bgn_addr,0,vcm_box_xy_dat_bgn_addr.length); + System.arraycopy(reCardHeader,ver.length + +header_size.length + +box_dat_type.length + +vcm_gige_access_dat_bgn_addr.length + +gige_access_addr_cnt.length + +gige_access_item_unit_size.length + +vcm_box_chk_dat_bgn_addr.length + +box_chk_dat_cnts.length + +box_chk_dat_index_unit_size.length + +vcm_box_cfg_dat_bgn_addr.length + +box_cfg_dat_cnts.length + +box_cfg_dat_index_unit_size.length + +vcm_box_gamma_dat_bgn_addr.length + +box_gamma_dat_cnts.length + +box_gamma_dat_index_unit_size.length + +enable_broardcast_save_xy.length + +vcs_save_xy_dat_addr.length + +vcs_send_xy_dat_addr.length + +vcs_gamma_save_mode.length + +vcm_box_xy_dat_bgn_addr.length,box_xy_dat_cnts,0,box_xy_dat_cnts.length); + System.arraycopy(reCardHeader,ver.length + +header_size.length + +box_dat_type.length + +vcm_gige_access_dat_bgn_addr.length + +gige_access_addr_cnt.length + +gige_access_item_unit_size.length + +vcm_box_chk_dat_bgn_addr.length + +box_chk_dat_cnts.length + +box_chk_dat_index_unit_size.length + +vcm_box_cfg_dat_bgn_addr.length + +box_cfg_dat_cnts.length + +box_cfg_dat_index_unit_size.length + +vcm_box_gamma_dat_bgn_addr.length + +box_gamma_dat_cnts.length + +box_gamma_dat_index_unit_size.length + +enable_broardcast_save_xy.length + +vcs_save_xy_dat_addr.length + +vcs_send_xy_dat_addr.length + +vcs_gamma_save_mode.length + +vcm_box_xy_dat_bgn_addr.length + +box_xy_dat_cnts.length,box_xy_dat_unit_size,0,box_xy_dat_unit_size.length); + System.arraycopy(reCardHeader,ver.length + +header_size.length + +box_dat_type.length + +vcm_gige_access_dat_bgn_addr.length + +gige_access_addr_cnt.length + +gige_access_item_unit_size.length + +vcm_box_chk_dat_bgn_addr.length + +box_chk_dat_cnts.length + +box_chk_dat_index_unit_size.length + +vcm_box_cfg_dat_bgn_addr.length + +box_cfg_dat_cnts.length + +box_cfg_dat_index_unit_size.length + +vcm_box_gamma_dat_bgn_addr.length + +box_gamma_dat_cnts.length + +box_gamma_dat_index_unit_size.length + +enable_broardcast_save_xy.length + +vcs_save_xy_dat_addr.length + +vcs_send_xy_dat_addr.length + +vcs_gamma_save_mode.length + +vcm_box_xy_dat_bgn_addr.length + +box_xy_dat_cnts.length + +box_xy_dat_unit_size.length,vcm_box_save_dat_bgn_addr,0,vcm_box_save_dat_bgn_addr.length); + System.arraycopy(reCardHeader,ver.length + +header_size.length + +box_dat_type.length + +vcm_gige_access_dat_bgn_addr.length + +gige_access_addr_cnt.length + +gige_access_item_unit_size.length + +vcm_box_chk_dat_bgn_addr.length + +box_chk_dat_cnts.length + +box_chk_dat_index_unit_size.length + +vcm_box_cfg_dat_bgn_addr.length + +box_cfg_dat_cnts.length + +box_cfg_dat_index_unit_size.length + +vcm_box_gamma_dat_bgn_addr.length + +box_gamma_dat_cnts.length + +box_gamma_dat_index_unit_size.length + +enable_broardcast_save_xy.length + +vcs_save_xy_dat_addr.length + +vcs_send_xy_dat_addr.length + +vcs_gamma_save_mode.length + +vcm_box_xy_dat_bgn_addr.length + +box_xy_dat_cnts.length + +box_xy_dat_unit_size.length + +vcm_box_save_dat_bgn_addr.length,box_save_dat_item_cnts,0,box_save_dat_item_cnts.length); + System.arraycopy(reCardHeader,ver.length + +header_size.length + +box_dat_type.length + +vcm_gige_access_dat_bgn_addr.length + +gige_access_addr_cnt.length + +gige_access_item_unit_size.length + +vcm_box_chk_dat_bgn_addr.length + +box_chk_dat_cnts.length + +box_chk_dat_index_unit_size.length + +vcm_box_cfg_dat_bgn_addr.length + +box_cfg_dat_cnts.length + +box_cfg_dat_index_unit_size.length + +vcm_box_gamma_dat_bgn_addr.length + +box_gamma_dat_cnts.length + +box_gamma_dat_index_unit_size.length + +enable_broardcast_save_xy.length + +vcs_save_xy_dat_addr.length + +vcs_send_xy_dat_addr.length + +vcs_gamma_save_mode.length + +vcm_box_xy_dat_bgn_addr.length + +box_xy_dat_cnts.length + +box_xy_dat_unit_size.length + +vcm_box_save_dat_bgn_addr.length + +box_save_dat_item_cnts.length,box_save_dat_item_unit_size,0,box_save_dat_item_unit_size.length); + System.arraycopy(reCardHeader,ver.length + +header_size.length + +box_dat_type.length + +vcm_gige_access_dat_bgn_addr.length + +gige_access_addr_cnt.length + +gige_access_item_unit_size.length + +vcm_box_chk_dat_bgn_addr.length + +box_chk_dat_cnts.length + +box_chk_dat_index_unit_size.length + +vcm_box_cfg_dat_bgn_addr.length + +box_cfg_dat_cnts.length + +box_cfg_dat_index_unit_size.length + +vcm_box_gamma_dat_bgn_addr.length + +box_gamma_dat_cnts.length + +box_gamma_dat_index_unit_size.length + +enable_broardcast_save_xy.length + +vcs_save_xy_dat_addr.length + +vcs_send_xy_dat_addr.length + +vcs_gamma_save_mode.length + +vcm_box_xy_dat_bgn_addr.length + +box_xy_dat_cnts.length + +box_xy_dat_unit_size.length + +vcm_box_save_dat_bgn_addr.length + +box_save_dat_item_cnts.length + +box_save_dat_item_unit_size.length,vcs_cfg_dat_paras_chksum,0,vcs_cfg_dat_paras_chksum.length); + + /*MyLog.showBytes("ver",ver,0); + MyLog.showBytes("header_size",header_size,0); + MyLog.showBytes("box_dat_type",box_dat_type,0); + MyLog.showBytes("vcm_gige_access_dat_bgn_addr",vcm_gige_access_dat_bgn_addr,0); + MyLog.showBytes("gige_access_addr_cnt",gige_access_addr_cnt,0); + MyLog.showBytes("gige_access_item_unit_size",gige_access_item_unit_size,0); + MyLog.showBytes("vcm_box_chk_dat_bgn_addr",vcm_box_chk_dat_bgn_addr,0); + MyLog.showBytes("box_chk_dat_cnts",box_chk_dat_cnts,0); + MyLog.showBytes("box_chk_dat_index_unit_size",box_chk_dat_index_unit_size,0); + MyLog.showBytes("vcm_box_cfg_dat_bgn_addr",vcm_box_cfg_dat_bgn_addr,0); + MyLog.showBytes("box_cfg_dat_cnts",box_cfg_dat_cnts,0); + MyLog.showBytes("box_cfg_dat_index_unit_size",box_cfg_dat_index_unit_size,0); + MyLog.showBytes("vcm_box_gamma_dat_bgn_addr",vcm_box_gamma_dat_bgn_addr,0); + MyLog.showBytes("box_gamma_dat_cnts",box_gamma_dat_cnts,0); + MyLog.showBytes("box_gamma_dat_index_unit_size",box_gamma_dat_index_unit_size,0); + MyLog.showBytes("enable_broardcast_save_xy",enable_broardcast_save_xy,0); + MyLog.showBytes("vcs_save_xy_dat_addr",vcs_save_xy_dat_addr,0); + MyLog.showBytes("vcs_send_xy_dat_addr",vcs_send_xy_dat_addr,0); + MyLog.showBytes("vcs_gamma_save_mode",vcs_gamma_save_mode,0); + MyLog.showBytes("vcm_box_xy_dat_bgn_addr",vcm_box_xy_dat_bgn_addr,0); + MyLog.showBytes("box_xy_dat_cnts",box_xy_dat_cnts,0); + MyLog.showBytes("box_xy_dat_unit_size",box_xy_dat_unit_size,0); + MyLog.showBytes("vcm_box_save_dat_bgn_addr",vcm_box_save_dat_bgn_addr,0); + MyLog.showBytes("box_save_dat_item_cnts",box_save_dat_item_cnts,0); + MyLog.showBytes("box_save_dat_item_unit_size",box_save_dat_item_unit_size,0); + MyLog.showBytes("vcs_cfg_dat_paras_chksum",vcs_cfg_dat_paras_chksum,0);*/ + } + + public boolean checkData() { + //先判断version是不是0xAAAAAA01 + boolean checkVer = (0xAAAAAA01 == (MyApp.bytesToInt(getVer(),false))); + //在判断header_chksum是否正确 + byte[] checdCodeBs = getVcs_cfg_dat_paras_chksum(); + int bsum = 0; +// byte check_code = 0; + for (int i=0;i=48){ + byte[] headerbs = new byte[dataLen]; + byte[] newData = new byte[data.length-dataLen]; +// byte[] check = new byte[4]; + + //拷贝数据到BackUpBuffer --> InsHeader + System.arraycopy(data, 0,headerbs, 0, dataLen); +// MyLog.showBytes("headerbs===",headerbs,0); + backUpBuffer.setInsHeaderbs(headerbs); + //将headerbs数据赋值到header + backUpBuffer.headerbsToHeader(); + + //拷贝数据到BackUpBuffer --> data + System.arraycopy(data, dataLen,newData, 0, newData.length); + backUpBuffer.setData(newData); +// structNetBuffer.toString();//打印数据 + + return backUpBuffer; + } + }catch (Exception e){ + e.printStackTrace(); + } + return backUpBuffer; + } + + /** + * 更新位置 + * p_ins_vcs_cfg_dat_header : reCardHeader + * p_gige_header :insGigeIoDatHeader + * p_ins_vcs_dat_index :insVcsDatIndex + * @param reCardHeader + * @param basic_fls_dat_adr + * @return + */ + + public int ins_update_vcs_offset(ReCardHeader reCardHeader, long basic_fls_dat_adr) + { + MyLog.i("---------------ins_update_vcs_offset---------------------"); + int errorcode = 0 ; + long ul_temp_dat_addr, ul_temp_dat_size, ul_gige_addr_idx ; + + _ins_enable_all_vcs_data_write(MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false),1); // 开启写 + for (ul_gige_addr_idx = 0; ul_gige_addr_idx < MyApp.bytesToInt(reCardHeader.getGige_access_addr_cnt(),false); ul_gige_addr_idx ++) { + ul_temp_dat_addr = basic_fls_dat_adr + MyApp.bytesToInt(reCardHeader.getVcm_gige_access_dat_bgn_addr(),false) + ul_gige_addr_idx * MyApp.bytesToInt(reCardHeader.getGige_access_item_unit_size(),false); + //读取数据 +// vcm_fls_r(ul_temp_dat_addr,p_static_buff,sizeof(ins_gige_io_dat_header)); + byte[] resInsGigeIoDatHeader = MyApp.card().flashRead((int) ul_temp_dat_addr,12); +// MyLog.showBytes("resInsGigeIoDatHeader",resInsGigeIoDatHeader,0); + //填充数据 + //ins_gige_io_dat_header *p_gige_header = (ins_gige_io_dat_header *)p_static_buff; + InsGigeIoDatHeader insGigeIoDatHeader = new InsGigeIoDatHeader(); + insGigeIoDatHeader.fillData(resInsGigeIoDatHeader); +// insGigeIoDatHeader.pln(); + + for (long vcs_idx = 0; vcs_idx < MyApp.bytesToInt(insGigeIoDatHeader.getVcs_cnts(),false); vcs_idx++) + { + ul_temp_dat_addr = basic_fls_dat_adr + MyApp.bytesToInt(reCardHeader.getVcm_gige_access_dat_bgn_addr(),false) + MyApp.bytesToInt(insGigeIoDatHeader.getDat_index_bgn_addr(),false) + + vcs_idx * MyApp.bytesToInt(insGigeIoDatHeader.getDat_index_unit_size(),false); + +// ins_vcs_dat_index *p_ins_vcs_dat_index = (ins_vcs_dat_index *)(p_static_buff + sizeof(ins_gige_io_dat_header)); +// vcm_fls_r(ul_temp_dat_addr,p_ins_vcs_dat_index,sizeof(ins_vcs_dat_index)); + byte[] resInsVcsDatIndex = MyApp.card().flashRead((int) ul_temp_dat_addr,12); + InsVcsDatIndex insVcsDatIndex = new InsVcsDatIndex(); + insVcsDatIndex.fillData(resInsVcsDatIndex); + + long vcs_combine_addr = Vcxbase.make_gige_vcs_address(MyApp.bytesToInt(insGigeIoDatHeader.getHub(),false) >= 1 ? (MyApp.bytesToInt(insGigeIoDatHeader.getHub(),false) - 1) : 0, MyApp.bytesToInt(insGigeIoDatHeader.getHub_port(),false), MyApp.bytesToInt(insVcsDatIndex.getVcs(),false), MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false)); + + ul_temp_dat_addr = basic_fls_dat_adr + MyApp.bytesToInt(reCardHeader.getVcm_box_xy_dat_bgn_addr(),false) + + MyApp.bytesToInt(insVcsDatIndex.getVcm_box_xy_dat_idx(),false) * MyApp.bytesToInt(reCardHeader.getBox_xy_dat_unit_size(),false); +// vcm_fls_r(ul_temp_dat_addr,p_dynamic_buff,p_ins_vcs_cfg_dat_header->box_xy_dat_unit_size); + byte[] p_dynamic_buff = MyApp.card().flashRead((int) ul_temp_dat_addr,MyApp.bytesToInt(reCardHeader.getBox_xy_dat_unit_size(),false)); + byte[] newBuff = new byte[8]; + System.arraycopy(p_dynamic_buff,0,newBuff,0,p_dynamic_buff.length); + + ul_temp_dat_size = MyApp.bytesToInt(reCardHeader.getBox_xy_dat_unit_size(),false); + + if (MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false) == vcs_t6_type) { +// memset((void*)(p_dynamic_buff+p_ins_vcs_cfg_dat_header->box_xy_dat_unit_size),0,MyApp.bytesToInt(reCardHeader.getBox_xy_dat_unit_size(),false)); +// byte[] temp = new byte[MyApp.bytesToInt(reCardHeader.getBox_xy_dat_unit_size(),false)]; +// System.arraycopy(temp,0,p_dynamic_buff,/*MyApp.bytesToInt(reCardHeader.getBox_xy_dat_unit_size(),false)*/0,temp.length); + ul_temp_dat_size = 8; + } + +// vcs_dat_w(p_gige_header->gige_port, vcs_combine_addr, p_ins_vcs_cfg_dat_header->vcs_send_xy_dat_addr, p_dynamic_buff, ul_temp_dat_size / 4, p_ins_vcs_cfg_dat_header->box_dat_type & 0xf,NO_PKT_INTERVAL_MS); + MyLog.i("vcs_dat_w.................."); + vcs_dat_w(MyApp.bytesToInt(insGigeIoDatHeader.getGige_port(),false), vcs_combine_addr, MyApp.bytesToInt(reCardHeader.getVcs_send_xy_dat_addr(),false), newBuff, (int) (ul_temp_dat_size / 4), MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false) & 0xf,Vcxbase.NO_PKT_INTERVAL_MS); + if (MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false) != vcs_t6_type) { + vcs_dat_w(MyApp.bytesToInt(insGigeIoDatHeader.getGige_port(),false), vcs_combine_addr, MyApp.bytesToInt(reCardHeader.getVcs_send_xy_dat_addr(),false), newBuff, (int) (ul_temp_dat_size / 4), MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false) & 0xf,Vcxbase.NO_PKT_INTERVAL_MS); + + } + } + } + return errorcode; + } + + + /*public void vcs_dat_w(long gige_port, long vcs_number, long vcs_dat_addr,byte[] p_dat, long len, int vcs_type,int pkt_interval_ms){ + MyLog.showBytes("gige_port:",MyApp.intToBytesH_L((int) gige_port,4),0); + MyLog.showBytes("vcs_number:",MyApp.intToBytesH_L((int) vcs_number,4),0); + MyLog.showBytes("vcs_dat_addr:",MyApp.intToBytesH_L((int) vcs_dat_addr,4),0); + MyLog.showBytes("p_dat:",p_dat,0); + Crc crc = new Crc(); + long res = crc.calc_crc32(p_dat,p_dat.length); + MyLog.showBytes("crc",MyApp.intToBytesH_L((int) res,4),0); + + MyLog.i("len:"+len); + MyLog.i("vcs_type:"+(vcs_type)); + MyLog.i("pkt_interval_ms:"+(pkt_interval_ms)); + MyLog.i("---------------------------------------------------"); +// MyApp.sleepForSecond(2); +// byte[] d = new byte[4]; +// _vcs_w(0x00,0x10ff0fff,0xda000162,d,1,0); + +// vcs_addr_init(0); + hub_addr_init(0); + + }*/ + + + /** + * vcs_dat_w + * @param gige_port + * @param vcs_number + * @param vcs_dat_addr + * @param p_dat + * @param len + * @param vcs_type + * @param pkt_interval_ms + * @return + */ + public int vcs_dat_w( long gige_port, long vcs_number, long vcs_dat_addr,byte[] p_dat, int len, int vcs_type,int pkt_interval_ms){ + MyLog.i("--------------vcs_dat_w--------------------"); + int i_ret = 0 ; + int iCount = len / Vcxbase.MAX_VCS_PKT_DAT_UNIT_SIZE ; + int iMod = len % Vcxbase.MAX_VCS_PKT_DAT_UNIT_SIZE ; + for (int i = 0; i < iCount; i ++) + { + byte[] newData = new byte[Vcxbase.MAX_VCS_PKT_DAT_UNIT_SIZE*4]; + System.arraycopy(p_dat,i*Vcxbase.MAX_VCS_PKT_DAT_UNIT_SIZE*4,newData,0,newData.length); + i_ret = _vcs_w(gige_port + ,vcs_number + ,vcs_dat_addr + i*Vcxbase.MAX_VCS_PKT_DAT_UNIT_SIZE + ,newData + ,Vcxbase.MAX_VCS_PKT_DAT_UNIT_SIZE + ,vcs_type); + if ( 0 != i_ret ) { + return i_ret ; + } + if (pkt_interval_ms < 0) + { + if ((vcs_dat_addr & io_type_fls) == io_type_fls ) { + MyApp.sleepForMillisecond(300); + } + else + { + if ((vcs_dat_addr & io_type_srm) == io_type_srm) { + MyApp.sleepForMillisecond(10); + } + } + } + else + { + if (pkt_interval_ms>0) { + MyApp.sleepForMillisecond(pkt_interval_ms); + } + } + } + if (iMod>0){ + byte[] newiModData = new byte[iMod*4]; + System.arraycopy(p_dat,iCount*Vcxbase.MAX_VCS_PKT_DAT_UNIT_SIZE*4,newiModData,0,newiModData.length); + i_ret = _vcs_w(gige_port + ,vcs_number + ,vcs_dat_addr + iCount * Vcxbase.MAX_VCS_PKT_DAT_UNIT_SIZE + ,newiModData + ,iMod + ,vcs_type); + if ( 0 != i_ret ) { + return i_ret ; + } + if (pkt_interval_ms < 0) + { + if ((vcs_dat_addr & io_type_fls) == io_type_fls ) { + MyApp.sleepForMillisecond(300); + } + else + { + if ((vcs_dat_addr & io_type_srm) == io_type_srm) { + MyApp.sleepForMillisecond(10); + } + } + } + else + { + if (pkt_interval_ms>0) { + MyApp.sleepForMillisecond(pkt_interval_ms); + } + } + } + return i_ret ; + } +// public int _vcs_read_cmd_with_fcard( long ul_gig_idx, long vcs_number){ +// byte[] cmd = new byte[4]; +// long ul_reg_ctl_cmd_address = make_vcs_io_address(io_type_reg, 0x106); +//// cmd[3] = (byte) (enable<<4); +// vcs_dat_r(ul_gig_idx,vcs_number,ul_reg_ctl_cmd_address,cmd ,1,Vcxbase.vcs_muti_card_type) ; +// return 0; +// } + + public int vcs_dat_r( long gige_port, long vcs_number, long vcs_dat_addr,byte[] p_dat, int len, int vcs_type){ + MyLog.i("--------------vcs_dat_r--------------------"); + int i_ret = 0 ; + int iCount = len / Vcxbase.MAX_VCS_PKT_DAT_UNIT_SIZE ; + int iMod = len % Vcxbase.MAX_VCS_PKT_DAT_UNIT_SIZE ; + for (int i = 0; i < iCount; i ++) + { + byte[] newData = new byte[Vcxbase.MAX_VCS_PKT_DAT_UNIT_SIZE*4]; + i_ret = _vcs_r(gige_port + ,vcs_number + ,vcs_dat_addr + i*Vcxbase.MAX_VCS_PKT_DAT_UNIT_SIZE + ,newData + ,Vcxbase.MAX_VCS_PKT_DAT_UNIT_SIZE + ,vcs_type); + MyLog.showBytes("newData",newData,0); + if ( 0 != i_ret ) { + return i_ret ; + } + System.arraycopy(newData,0,p_dat,i*Vcxbase.MAX_VCS_PKT_DAT_UNIT_SIZE*4,newData.length); + + } + if (iMod>0){ + byte[] newiModData = new byte[iMod*4]; + i_ret = _vcs_r(gige_port + ,vcs_number + ,vcs_dat_addr + iCount * Vcxbase.MAX_VCS_PKT_DAT_UNIT_SIZE + ,newiModData + ,iMod + ,vcs_type); + MyLog.showBytes("newiModData",newiModData,0); + if ( 0 != i_ret ) { + return i_ret ; + } + System.arraycopy(newiModData,0,p_dat,iCount*Vcxbase.MAX_VCS_PKT_DAT_UNIT_SIZE*4,newiModData.length); + } + return i_ret ; + } + public int vcs_dat_r_badPoint( long gige_port,int cardIdx ,long vcs_number, long vcs_dat_addr,byte[] p_dat, int len, int vcs_type){ + MyLog.i("--------------vcs_dat_r--------------------"); + int i_ret = 0 ; + int iCount = len / Vcxbase.MAX_VCS_PKT_DAT_UNIT_SIZE ; + MyLog.e("iCount----"+iCount); + int iMod = len % Vcxbase.MAX_VCS_PKT_DAT_UNIT_SIZE ; + MyLog.e("iMod----"+iMod); + for (int i = 0; i < iCount; i ++) + { + byte[] newData = new byte[Vcxbase.MAX_VCS_PKT_DAT_UNIT_SIZE*4]; + i_ret = _vcs_r(gige_port + ,vcs_number + ,vcs_dat_addr + i*Vcxbase.MAX_VCS_PKT_DAT_UNIT_SIZE + ,newData + ,Vcxbase.MAX_VCS_PKT_DAT_UNIT_SIZE + ,vcs_type); + // MyLog.showBytes("newData",newData,0); + if ( 0 != i_ret ) { + return i_ret ; + } + System.arraycopy(newData,0,p_dat,i*Vcxbase.MAX_VCS_PKT_DAT_UNIT_SIZE*4,newData.length); + + } + if (iMod>0){ + byte[] newiModData = new byte[iMod*4]; + i_ret = _vcs_r(gige_port + ,vcs_number + ,vcs_dat_addr + iCount * Vcxbase.MAX_VCS_PKT_DAT_UNIT_SIZE + ,newiModData + ,iMod + ,vcs_type); + // MyLog.showBytes("newiModData",newiModData,0); + if ( 0 != i_ret ) { + return i_ret ; + } + System.arraycopy(newiModData,0,p_dat,iCount*Vcxbase.MAX_VCS_PKT_DAT_UNIT_SIZE*4,newiModData.length); + } + return i_ret ; + } + + + + + public int _vcs_r( long gige_port, long vcs_number, long vcs_dat_addr,byte[] p_dat, int len, int vcs_type) + { + int result = -1; + int offfset = 0; + byte[] bs = new byte[22]; +// byte[] header = new byte[22]; + bs[offfset++] = (byte) 0x9A; + bs[offfset++] = (byte) 0x0D; + bs[offfset++] = (byte) ((len>>8) & 0xff);//高8bit + bs[offfset++] = (byte) ((len>>0) & 0xff);//低8bit + + bs[offfset++] = (byte) ((vcs_number>>24) & 0xff);// + bs[offfset++] = (byte) ((vcs_number>>16) & 0xff);// + bs[offfset++] = (byte) ((byte) ((vcs_number>>8) & 0xff)|(vcs_type<<4));// + bs[offfset++] = (byte) ((vcs_number>>0) & 0xff);// + + bs[offfset++] = (byte) 0x00; + bs[offfset++] = (byte) 0x00; + bs[offfset++] = (byte) 0x00; + bs[offfset++] = (byte) 0x00; + + bs[offfset++] = (byte) ((vcs_dat_addr>>24) & 0xff);// + bs[offfset++] = (byte) ((vcs_dat_addr>>16) & 0xff);// + bs[offfset++] = (byte) ((vcs_dat_addr>>8) & 0xff);// + bs[offfset++] = (byte) ((vcs_dat_addr>>0) & 0xff);// + + bs[offfset++] = (byte) 0x00; + bs[offfset++] = (byte) 0x00; + + byte[] crcD = new byte[18]; + System.arraycopy(bs,0,crcD,0,18); + Crc cr = new Crc(); + long crc = cr.calc_crc32(crcD,crcD.length); + + bs[offfset++] = (byte) ((crc>>24) & 0xff);// + bs[offfset++] = (byte) ((crc>>16) & 0xff);// + bs[offfset++] = (byte) ((crc>>8) & 0xff);// + bs[offfset++] = (byte) ((crc>>0) & 0xff);// + + + MyApp.card().IOSPIRes(true,MyApp.card().getGigPortWriteAddrByCmdEnd((int) gige_port),bs,offfset) ; + + + long[] newLong = new long[len]; + + int timeoutcount = 20; + int i_cur_gige_port = (int) (gige_port & 0xff); + // + if (i_cur_gige_port>=MyApp.bytesToInt(MyApp.getSoNum(),true)){//是广播的 + MyLog.i("is ff "+i_cur_gige_port); + result = 2; + return result; + } + + byte[] reBuff = new byte[2048]; + while (timeoutcount!=0){ + MyApp.sleepForMillisecond(1); + int re = (int) (MyApp.card().get_gig_port_status(Vcxbase.PORT_HAVE_NEW_PACK) & (1<>8) & 0xff);//高8bit + bs[offfset++] = (byte) ((len>>0) & 0xff);//低8bit + bs[offfset++] = (byte) ((vcs_number>>24) & 0xff);// + bs[offfset++] = (byte) ((vcs_number>>16) & 0xff);// + bs[offfset++] = (byte) ((byte) ((vcs_number>>8) & 0xff)|(vcs_type<<4));// + bs[offfset++] = (byte) ((vcs_number>>0) & 0xff);// + + bs[offfset++] = (byte) 0x00; + bs[offfset++] = (byte) 0x00; + bs[offfset++] = (byte) 0x00; + bs[offfset++] = (byte) 0x00; + + bs[offfset++] = (byte) ((vcs_dat_addr>>24) & 0xff);// + bs[offfset++] = (byte) ((vcs_dat_addr>>16) & 0xff);// + bs[offfset++] = (byte) ((vcs_dat_addr>>8) & 0xff);// + bs[offfset++] = (byte) ((vcs_dat_addr>>0) & 0xff);// + + bs[offfset++] = (byte) 0x00; + bs[offfset++] = (byte) 0x00; + + byte[] crcD = new byte[18]; + System.arraycopy(bs,0,crcD,0,18); + Crc cr = new Crc(); + long crc = cr.calc_crc32(crcD,crcD.length); + + bs[offfset++] = (byte) ((crc>>24) & 0xff);// + bs[offfset++] = (byte) ((crc>>16) & 0xff);// + bs[offfset++] = (byte) ((crc>>8) & 0xff);// + bs[offfset++] = (byte) ((crc>>0) & 0xff);// + + System.arraycopy(p_dat,0,bs,offfset,len*4); + offfset+=(len*4); + long crcData = cr.calc_crc32(p_dat,len*4); + + bs[offfset++] = (byte) ((crcData>>24) & 0xff);// + bs[offfset++] = (byte) ((crcData>>16) & 0xff);// + bs[offfset++] = (byte) ((crcData>>8) & 0xff);// + bs[offfset++] = (byte) ((crcData>>0) & 0xff);// + + MyApp.card().IOSPIRes(true,MyApp.card().getGigPortWriteAddrByCmdEnd((int) gige_port),bs,offfset) ; + + return 0; + } + + + + public long[] vcs_addr_init( long combine_gige_port){ + MyLog.i("-----------------vcs_addr_init---------------------"); + int i_ret = 0; + int offfset = 0; + int len = 16; + int vcs_dat_addr = 0x35000CDD; + byte[] bs = new byte[22+64+4]; + bs[offfset++] = (byte) 0x9A; + bs[offfset++] = (byte) 0x3D; + bs[offfset++] = (byte) ((len>>8) & 0xff);//高8bit + bs[offfset++] = (byte) ((len>>0) & 0xff);//低8bit + bs[offfset++] = (byte) 0x10;// + bs[offfset++] = (byte) 0xff;// + bs[offfset++] = (byte) 0xff;// + bs[offfset++] = (byte) 0xff;// + + bs[offfset++] = (byte) 0x00; + bs[offfset++] = (byte) 0x00; + bs[offfset++] = (byte) 0x00; + bs[offfset++] = (byte) 0x00; + + bs[offfset++] = (byte) ((vcs_dat_addr>>24) & 0xff);// + bs[offfset++] = (byte) ((vcs_dat_addr>>16) & 0xff);// + bs[offfset++] = (byte) ((vcs_dat_addr>>8) & 0xff);// + bs[offfset++] = (byte) ((vcs_dat_addr>>0) & 0xff);// + + bs[offfset++] = (byte) 0x00; + bs[offfset++] = (byte) 0x00; + + byte[] crcD = new byte[18]; + System.arraycopy(bs,0,crcD,0,18); + Crc cr = new Crc(); + long crc = cr.calc_crc32(crcD,crcD.length); + + bs[offfset++] = (byte) ((crc>>24) & 0xff);// + bs[offfset++] = (byte) ((crc>>16) & 0xff);// + bs[offfset++] = (byte) ((crc>>8) & 0xff);// + bs[offfset++] = (byte) ((crc>>0) & 0xff);// + + byte[] crcDatas = new byte[64]; + System.arraycopy(bs,22,crcDatas,0,64); + offfset+=64; + long crcData = cr.calc_crc32(crcDatas,len*4); + + bs[offfset++] = (byte) ((crcData>>24) & 0xff);// + bs[offfset++] = (byte) ((crcData>>16) & 0xff);// + bs[offfset++] = (byte) ((crcData>>8) & 0xff);// + bs[offfset++] = (byte) ((crcData>>0) & 0xff);// + MyLog.showBytes("bs",bs,0); + MyLog.i("offfset:"+offfset); + MyApp.card().IOSPIRes(true,MyApp.card().getGigPortWriteAddrByCmdEnd((int) combine_gige_port),bs,offfset) ; + + long[] newLong = new long[len]; + int cur_gige_port = (int) (combine_gige_port & 0xff); + int timeoutcount = 20; + // + if (cur_gige_port>=MyApp.bytesToInt(MyApp.getSoNum(),true)){//是广播的 + MyLog.i("is ff "+cur_gige_port); + return newLong; + }else { + byte[] reBuff = new byte[2048]; + while (timeoutcount!=0){ + MyApp.sleepForMillisecond(1); + int re = (int) (MyApp.card().get_gig_port_status(Vcxbase.PORT_HAVE_NEW_PACK) & (1<>8) & 0xff);//高8bit + bs[offfset++] = (byte) ((len>>0) & 0xff);//低8bit + bs[offfset++] = (byte) ((combine_gige_port>>24) & 0xff);// + bs[offfset++] = (byte) ((combine_gige_port>>16) & 0xff);// + bs[offfset++] = (byte) 0xff;// + bs[offfset++] = (byte) 0xff;// + + bs[offfset++] = (byte) 0x00; + bs[offfset++] = (byte) 0x00; + bs[offfset++] = (byte) 0x00; + bs[offfset++] = (byte) 0x00; + + bs[offfset++] = (byte) ((vcs_dat_addr>>24) & 0xff);// + bs[offfset++] = (byte) ((vcs_dat_addr>>16) & 0xff);// + bs[offfset++] = (byte) ((vcs_dat_addr>>8) & 0xff);// + bs[offfset++] = (byte) ((vcs_dat_addr>>0) & 0xff);// + + bs[offfset++] = (byte) 0x00; + bs[offfset++] = (byte) 0x00; + + byte[] crcD = new byte[18]; + System.arraycopy(bs,0,crcD,0,18); + Crc cr = new Crc(); + long crc = cr.calc_crc32(crcD,crcD.length); + + bs[offfset++] = (byte) ((crc>>24) & 0xff);// + bs[offfset++] = (byte) ((crc>>16) & 0xff);// + bs[offfset++] = (byte) ((crc>>8) & 0xff);// + bs[offfset++] = (byte) ((crc>>0) & 0xff);// + + byte[] crcDatas = new byte[len*4]; + System.arraycopy(bs,22,crcDatas,0,len*4); + offfset+=(len*4); + long crcData = cr.calc_crc32(crcDatas,len*4); + + bs[offfset++] = (byte) ((crcData>>24) & 0xff);// + bs[offfset++] = (byte) ((crcData>>16) & 0xff);// + bs[offfset++] = (byte) ((crcData>>8) & 0xff);// + bs[offfset++] = (byte) ((crcData>>0) & 0xff);// +// MyLog.showBytes("bs",bs,0); +// MyLog.i("offfset:"+offfset); + MyApp.card().IOSPIRes(true,MyApp.card().getGigPortWriteAddrByCmdEnd((int) combine_gige_port),bs,offfset) ; + + long[] newLong = new long[MyApp.bytesToInt(MyApp.getSoNum(),true)]; + int cur_gige_port = (int) (combine_gige_port & 0xff); + int timeoutcount = 4; + // + byte[] reBuff = new byte[2048]; + while (timeoutcount!=0){ + MyApp.sleepForMillisecond(1); + int re = (int) (MyApp.card().get_gig_port_status(Vcxbase.PORT_HAVE_NEW_PACK) & (1<>8) & 0xff);//高8bit + bs[offfset++] = (byte) ((len>>0) & 0xff);//低8bit + bs[offfset++] = (byte) ((combine_gige_port>>24) & 0xff);// + bs[offfset++] = (byte) ((combine_gige_port>>16) & 0xff);// + bs[offfset++] = (byte) 0x0f;// + bs[offfset++] = (byte) 0x0f;// + + bs[offfset++] = (byte) 0x00; + bs[offfset++] = (byte) 0x00; + bs[offfset++] = (byte) 0x00; + bs[offfset++] = (byte) 0x00; + + bs[offfset++] = (byte) ((vcs_dat_addr>>24) & 0xff);// + bs[offfset++] = (byte) ((vcs_dat_addr>>16) & 0xff);// + bs[offfset++] = (byte) ((vcs_dat_addr>>8) & 0xff);// + bs[offfset++] = (byte) ((vcs_dat_addr>>0) & 0xff);// + + bs[offfset++] = (byte) 0x00; + bs[offfset++] = (byte) 0x00; + + byte[] crcD = new byte[18]; + System.arraycopy(bs,0,crcD,0,18); + Crc cr = new Crc(); + long crc = cr.calc_crc32(crcD,crcD.length); + + bs[offfset++] = (byte) ((crc>>24) & 0xff);// + bs[offfset++] = (byte) ((crc>>16) & 0xff);// + bs[offfset++] = (byte) ((crc>>8) & 0xff);// + bs[offfset++] = (byte) ((crc>>0) & 0xff);// + + + for (int i = 0; i < 4096; i ++) { + if (0!=data[i]) { + bs[(i/8) + offfset] |= 1<<(i%8); + } + } + for (int i = 0; i < 128; i ++){ + for (int s=0,e = 3;s>24) & 0xff);// + bs[offfset++] = (byte) ((ul_timeout>>16) & 0xff);// + bs[offfset++] = (byte) ((ul_timeout>>8) & 0xff);// + bs[offfset++] = (byte) ((ul_timeout>>0) & 0xff);// + + + + byte[] crcDatas = new byte[512+4]; + System.arraycopy(bs,22,crcDatas,0,512+4); +// offfset+=(len*4); + long crcData = cr.calc_crc32(crcDatas,512+4); + + bs[offfset++] = (byte) ((crcData>>24) & 0xff);// + bs[offfset++] = (byte) ((crcData>>16) & 0xff);// + bs[offfset++] = (byte) ((crcData>>8) & 0xff);// + bs[offfset++] = (byte) ((crcData>>0) & 0xff);// +// MyLog.showBytes("bs",bs,0); +// MyLog.i("offfset:"+offfset); + + byte[] te = new byte[4]; + System.arraycopy(bs,22,te,0,4); +// MyLog.showBytes("22===========",te,0); + System.arraycopy(bs,512+22,te,0,4); +// MyLog.showBytes("512+22===========",te,0); + MyApp.card().IOSPIRes(true,MyApp.card().getGigPortWriteAddrByCmdEnd((int) combine_gige_port),bs,offfset) ; + } + + + public int enable_vcs_write_cmd_with_fcard( long ul_gig_idx, long vcs_number,int enable){ + byte[] cmd = new byte[4]; + long ul_reg_ctl_cmd_address = make_vcs_io_address(io_type_reg, 0x03); + cmd[3] = (byte) (enable<<4); + vcs_dat_w(ul_gig_idx,vcs_number,ul_reg_ctl_cmd_address,cmd ,1,Vcxbase.vcs_fpga_type, DEF_PKT_INTERVAL_MS) ; + return 0; + } + + + public void _ins_enable_all_vcs_data_write( int vcs_type,int enable) + { + MyLog.i("--------------------_ins_enable_all_vcs_data_write--------------------"); + byte[] p_ram_buff =new byte[4096]; + if (vcs_type == vcs_t6_type) + { + memset(p_ram_buff,(enable!=0)?0x0:0x1,4096); + enable_vcs_write_cmd_with_tcard(vcm_port_broadcast_address,p_ram_buff,(enable!=0) ? 0 : Vcxbase.MAX_LOCK_WRITE_TIME_MS); + } + else + { + enable_vcs_write_cmd_with_fcard(vcm_port_broadcast_address,Vcxbase.fcard_vcs_broadcast_address,enable); + } + } + + public void memset(byte[] p_ram_buff, int val, int len) { + for (int i=0;ibox_cfg_dat_index_unit_size,p_vcs_data_index->cmd_pkt_unit_size); +// ins_vcs_io_dat_item *p_vcs_io_dat_header = (ins_vcs_io_dat_item *)(p_static_buff+p_ins_vcs_cfg_dat_header->box_cfg_dat_index_unit_size); + + p_static_buff = MyApp.card().flashRead((int) ul_cur_cfg_dat_header_idx_adr,12); + InsVcsIoDatItem insVcsIoDatItem = new InsVcsIoDatItem(); + insVcsIoDatItem.fillData(p_static_buff); + + + long ul_cmd_dat_fls_addr = basic_fls_dat_adr + MyApp.bytesToInt(reCardHeader.getVcm_box_cfg_dat_bgn_addr(),false) + MyApp.bytesToInt(insVcsIoDatItem.getVcm_io_dat_fls_addr(),false) ; + + if (MyApp.bytesToInt(insVcsIoDatItem.getVcs_io_dat_addr(),false) == make_vcs_io_address(io_type_reg, 0x03) + && MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false) == Vcxbase.vcs_fpga_type + && MyApp.bytesToInt(insVcsIoDatItem.getVcs_io_dat_len(),false) == 4) + { +// vcm_fls_r(ul_cmd_dat_fls_addr,&cmd.value,MyApp.bytesToInt(insVcsIoDatItem.getVcs_io_dat_len(),false)); + byte[] cmdValue = MyApp.card().flashRead((int) ul_cmd_dat_fls_addr,MyApp.bytesToInt(insVcsIoDatItem.getVcs_io_dat_len(),false)); + + /*if (cmd.cb.kill_cross == 1) { + kill_cross = 1; + } + if (cmd.cb.low_gray_dat_to_ic == 1) { + low_gray_dat_to_ic = 1; + }*/ + + kill_cross = 1; + low_gray_dat_to_ic = 1; + cfgdone = 1; + continue ; + } +// MyLog.i("ul_cmd_dat_fls_addr====="+Define.PrintIntToHex((int) ul_cmd_dat_fls_addr)); +// MyLog.i("getVcs_io_dat_len====="+MyApp.bytesToInt(insVcsIoDatItem.getVcs_io_dat_len(),false)); +// MyLog.i("getVcs_io_dat_addr====="+Define.PrintIntToHex((int) MyApp.bytesToInt(insVcsIoDatItem.getVcs_io_dat_addr(),false))); +// MyLog.showBytes("getVcs_io_dat_addr=====",insVcsIoDatItem.getVcs_io_dat_addr(),0); + _ins_broardcast_vcs_write_dat(ul_cmd_dat_fls_addr,MyApp.bytesToInt(insVcsIoDatItem.getVcs_io_dat_len(),false), (char) MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false),MyApp.bytesToInt(insVcsIoDatItem.getVcs_io_dat_addr(),false)); + + if (MyApp.bytesToInt(insVcsIoDatItem.getVcs_io_dat_addr(),false) == make_vcs_io_address(io_type_reg, 0x104) + && MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false) == vcs_t6_type) { + MyApp.sleepForMillisecond(200); + } + } + + if (kill_cross == 1 || low_gray_dat_to_ic == 1 || cfgdone == 1) + { + cmd[3] = (byte) (kill_cross<<5); + cmd[3] = (byte) (low_gray_dat_to_ic<<6); + vcs_dat_w(vcm_port_broadcast_address, Vcxbase.fcard_vcs_broadcast_address, make_vcs_io_address(io_type_reg, 0x03), cmd, 1, MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false), DEF_PKT_INTERVAL_MS); + } + } + if (MyApp.bytesToInt(reCardHeader.getBox_cfg_dat_cnts(),false) > 0) { + _ins_enable_all_vcs_data_write(MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false),1); // 开启写 + + MyApp.sleepForMillisecond(1); + + long ul_dat_index_addr = basic_fls_dat_adr + MyApp.bytesToInt(reCardHeader.getVcm_box_save_dat_bgn_addr(),false); +// vcm_fls_r(ul_dat_index_addr,p_static_buff,MyApp.bytesToInt(reCardHeader.getBox_save_dat_item_unit_size(),false)); +// ins_vcs_cmd_index *p_vcs_data_index = (ins_vcs_cmd_index *)p_static_buff ; + byte[] p_static_buff = MyApp.card().flashRead((int) ul_dat_index_addr,12); + InsVcsCmdIndex insVcsCmdIndex = new InsVcsCmdIndex(); + insVcsCmdIndex.fillData(p_static_buff); + + for ( long ul_pkt_idx = 0; ul_pkt_idx < MyApp.bytesToInt(insVcsCmdIndex.getCmd_pkt_cnt(),false); ul_pkt_idx++) + { + long ul_cur_cfg_dat_header_idx_adr = basic_fls_dat_adr + MyApp.bytesToInt(reCardHeader.getVcm_box_save_dat_bgn_addr(),false) + MyApp.bytesToInt(insVcsCmdIndex.getVcm_cmd_pkt_addr(),false) + ul_pkt_idx * MyApp.bytesToInt(insVcsCmdIndex.getCmd_pkt_unit_size(),false); + +// vcm_fls_r(ul_cur_cfg_dat_header_idx_adr,p_static_buff+ MyApp.bytesToInt(reCardHeader.getBox_save_dat_item_unit_size(),false),p_vcs_data_index->cmd_pkt_unit_size); +// ins_vcs_io_dat_item *p_vcs_io_dat_header = (ins_vcs_io_dat_item *)(p_static_buff+MyApp.bytesToInt(reCardHeader.getBox_save_dat_item_unit_size(),false)); + + p_static_buff = MyApp.card().flashRead((int) ul_cur_cfg_dat_header_idx_adr,12); + InsVcsIoDatItem insVcsIoDatItem = new InsVcsIoDatItem(); + insVcsIoDatItem.fillData(p_static_buff); + + if (MyApp.bytesToInt(insVcsIoDatItem.getVcs_io_dat_len(),false) > 0) { + // 写数据 + +// vcm_fls_r(basic_fls_dat_adr+MyApp.bytesToInt(reCardHeader.getVcm_box_save_dat_bgn_addr(),false) + MyApp.bytesToInt(insVcsIoDatItem.getVcm_io_dat_fls_addr(),false) +// ,p_ram_buff,MyApp.bytesToInt(insVcsIoDatItem.getVcs_io_dat_len(),false)); + + byte[] p_ram_buff= MyApp.card().flashRead((int) basic_fls_dat_adr+MyApp.bytesToInt(reCardHeader.getVcm_box_save_dat_bgn_addr(),false) + MyApp.bytesToInt(insVcsIoDatItem.getVcm_io_dat_fls_addr(),false),MyApp.bytesToInt(insVcsIoDatItem.getVcs_io_dat_len(),false)); + vcs_dat_w(vcm_port_broadcast_address, MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false) == vcs_t6_type ? tcard_vcs_broadcast_address : Vcxbase.fcard_vcs_broadcast_address + , MyApp.bytesToInt(insVcsIoDatItem.getVcs_io_dat_addr(),false), p_ram_buff, MyApp.bytesToInt(insVcsIoDatItem.getVcs_io_dat_len(),false) / 4, MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false) + , DEF_PKT_INTERVAL_MS); + } + else + { + if ((MyApp.bytesToInt(insVcsIoDatItem.getVcs_io_dat_addr(),false) >> 24) == 0xff) { +// delay_ms(); + MyApp.sleepForMillisecond(MyApp.bytesToInt(insVcsIoDatItem.getVcs_io_dat_addr(),false) & 0xffffff); + } + } + } + } + return errorcode ; + } + + /** + * 更新发送卡数据 + */ + public void updateVcmData(long basic_fls_dat_adr,int vcm_cfg_dat_addr) { + InsVcmCfgDatParas insVcmCfgDatParas = new InsVcmCfgDatParas(); + byte[] p_static_buff = null; + long ul_temp_dat_addr, ul_gige_addr_idx ; + /* 更新发送卡参数 */ +// if (Vcm_box_cfg_dat_size > 0/* && (MyApp.bytesToInt(backUpBuffer.getInsHeader().getStorage_mask(),false) & (1<<3))*/) + if (MyApp.bytesToInt(backUpBuffer.getInsHeader().getVcm_cfg_dat_size(),false) > 0/* && (MyApp.bytesToInt(backUpBuffer.getInsHeader().getStorage_mask(),false) & (1<<3))*/) + { +// p_ins_vcm_cfg_dat_paras_header = (ins_vcm_cfg_dat_paras*)p_static_buff; + ul_temp_dat_addr = basic_fls_dat_adr + vcm_cfg_dat_addr; +// p_static_buff=MyApp.card().flashRead(ul_temp_dat_addr,sizeof(ins_vcm_cfg_dat_paras)); + p_static_buff=MyApp.card().flashRead((int) ul_temp_dat_addr,MyApp.bytesToInt(backUpBuffer.getInsHeader().getVcm_cfg_dat_size(),false)); +// p_static_buff += insVcmCfgDatParas.getHeader_size() ; + insVcmCfgDatParas.fillData(p_static_buff); +// MyLog.showBytes("p_static_buff",p_static_buff,0); + int i_ret = ins_update_vcm_dat_cfg(insVcmCfgDatParas,ul_temp_dat_addr); +// MyLog.i("i_ret=============="+i_ret); + /*if (i_ret != 0) { + break; + }*/ + } + } + + + /** + * 发送卡配置数据(云端数据配置发送卡) + * @param insVcmCfgDatParas + * @param basic_fls_dat_adr + * @return + */ + public int ins_update_vcm_dat_cfg(InsVcmCfgDatParas insVcmCfgDatParas,long basic_fls_dat_adr) + { + int errorcode = 0 ; + byte[] p_static_buff = null; + long ul_temp_dat_addr, ul_gige_addr_idx ; + + for (ul_gige_addr_idx = 0; ul_gige_addr_idx < MyApp.bytesToInt(insVcmCfgDatParas.getGige_port_count(),false); ul_gige_addr_idx ++) + { + ul_temp_dat_addr = basic_fls_dat_adr + MyApp.bytesToInt(insVcmCfgDatParas.getVcm_gige_port_cfg_addr(),false) + ul_gige_addr_idx * MyApp.bytesToInt(insVcmCfgDatParas.getGige_port_cfg_unit_size(),false); + //flash读 + p_static_buff=MyApp.card().flashRead((int) ul_temp_dat_addr,MyApp.bytesToInt(insVcmCfgDatParas.getGige_port_cfg_unit_size(),false)); + + //spi写 + MyApp.card().IOSPIRes(true,MyApp.card().vm_get_fpga_gige_cfg_addr((int) ul_gige_addr_idx),p_static_buff,MyApp.bytesToInt(insVcmCfgDatParas.getGige_port_cfg_unit_size(),false)); + } + + ul_temp_dat_addr = basic_fls_dat_adr + MyApp.bytesToInt(insVcmCfgDatParas.getVcm_img_ctl_dat_addr(),false); + p_static_buff = MyApp.card().flashRead((int) ul_temp_dat_addr,MyApp.bytesToInt(insVcmCfgDatParas.getImg_ctl_dat_size(),false)); + + MyApp.card().IOSPIRes(true,MyApp.card().vm_get_fpga_control_reg_addr(),p_static_buff,MyApp.bytesToInt(insVcmCfgDatParas.getImg_ctl_dat_size(),false)); + +// if (is_enable_autosave()) // 保存FLASH +// { + for (ul_gige_addr_idx = 0; ul_gige_addr_idx < MyApp.bytesToInt(insVcmCfgDatParas.getGige_port_count(),false); ul_gige_addr_idx ++) + { + ul_temp_dat_addr = basic_fls_dat_adr + MyApp.bytesToInt(insVcmCfgDatParas.getVcm_gige_port_cfg_addr(),false) + ul_gige_addr_idx * MyApp.bytesToInt(insVcmCfgDatParas.getGige_port_cfg_unit_size(),false); + p_static_buff=MyApp.card().flashRead((int) ul_temp_dat_addr,MyApp.bytesToInt(insVcmCfgDatParas.getGige_port_cfg_unit_size(),false)); + +// ul_temp_dat_addr = get_fls_gig_port_cfg_dat_addr(ul_gige_addr_idx) ; + ul_temp_dat_addr = MyApp.card().vm_get_fls_gige_dat_addr(ul_gige_addr_idx) ; + + if ((ul_temp_dat_addr & 0xfff) == 0){ +// vcm_fls_e(ul_temp_dat_addr >> 12,1); + } + MyApp.card().flashWrite(p_static_buff, (int) ul_temp_dat_addr,MyApp.bytesToInt(insVcmCfgDatParas.getGige_port_cfg_unit_size(),false)); + } + + ul_temp_dat_addr = basic_fls_dat_adr + MyApp.bytesToInt(insVcmCfgDatParas.getVcm_img_ctl_dat_addr(),false); + p_static_buff=MyApp.card().flashRead((int) ul_temp_dat_addr,MyApp.bytesToInt(insVcmCfgDatParas.getImg_ctl_dat_size(),false)); + + ul_temp_dat_addr = MyApp.card().vm_get_fls_control_reg_dat_addr() ; +// vcm_fls_e(ul_temp_dat_addr >> 12,1); + + MyApp.card().flashWrite(p_static_buff, (int) ul_temp_dat_addr,MyApp.bytesToInt(insVcmCfgDatParas.getImg_ctl_dat_size(),false)); +// } + + return errorcode; + } + + + /** + * p_ins_vcs_cfg_dat_header : reCardHeader + * p_gige_header :insGigeIoDatHeader + * p_ins_vcs_dat_index :insVcsDatIndex + * @param reCardHeader + * @param basic_fls_dat_adr + * @param dat_type + * @param ul_dat_idx + * @param enable + */ + void _ins_enable_vcs_data_write(ReCardHeader reCardHeader, long basic_fls_dat_adr,char dat_type, long ul_dat_idx,char enable) + { + byte[] p_ram_buff = new byte[4096]; + long ul_temp_dat_addr, ul_gige_addr_idx ; + + _ins_enable_all_vcs_data_write(MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false),0); // 禁用写 + + // 打开仅允许的写 + for (ul_gige_addr_idx = 0; ul_gige_addr_idx < MyApp.bytesToInt(reCardHeader.getGige_access_addr_cnt(),false); ul_gige_addr_idx ++) + { + ul_temp_dat_addr = basic_fls_dat_adr + MyApp.bytesToInt(reCardHeader.getVcm_gige_access_dat_bgn_addr(),false) + ul_gige_addr_idx * MyApp.bytesToInt(reCardHeader.getGige_access_item_unit_size(),false); +// vcm_fls_r(ul_temp_dat_addr,p_dynamic_buff,sizeof(ins_gige_io_dat_header)); + + byte[] p_dynamic_buff = MyApp.card().flashRead((int) ul_temp_dat_addr,12); + InsGigeIoDatHeader insGigeIoDatHeader = new InsGigeIoDatHeader(); + insGigeIoDatHeader.fillData(p_dynamic_buff); + +// ins_gige_io_dat_header *p_gige_header = (ins_gige_io_dat_header *)p_dynamic_buff; + + long _cur_gige_combine_addr = Vcxbase.make_gige_address(MyApp.bytesToInt(insGigeIoDatHeader.getGige_port(),false), MyApp.bytesToInt(insGigeIoDatHeader.getHub(),false) >= 1 ? (MyApp.bytesToInt(insGigeIoDatHeader.getHub(),false) - 1) : 0, + MyApp.bytesToInt(insGigeIoDatHeader.getHub_port(),false)); + if (MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false) == vcs_t6_type) + { + memset(p_ram_buff,0,4096); + enable_vcs_write_cmd_with_tcard(_cur_gige_combine_addr,p_ram_buff,0); // 解除当前网口串联的接收卡写访问 + memset(p_ram_buff,1,4096); + } + + for ( long vcs_idx = 0; vcs_idx < MyApp.bytesToInt(insGigeIoDatHeader.getVcs_cnts(),false); vcs_idx++) + { + ul_temp_dat_addr = basic_fls_dat_adr + MyApp.bytesToInt(reCardHeader.getVcm_gige_access_dat_bgn_addr(),false) + MyApp.bytesToInt(insGigeIoDatHeader.getDat_index_bgn_addr(),false) + + vcs_idx * MyApp.bytesToInt(insGigeIoDatHeader.getDat_index_unit_size(),false) ; + +// ins_vcs_dat_index *p_ins_vcs_dat_index = (ins_vcs_dat_index *)(p_dynamic_buff + sizeof(ins_gige_io_dat_header)); +// vcm_fls_r(ul_temp_dat_addr,p_ins_vcs_dat_index,sizeof(ins_vcs_dat_index)); + + byte[] resInsVcsDatIndex = MyApp.card().flashRead((int) ul_temp_dat_addr,12); + InsVcsDatIndex insVcsDatIndex = new InsVcsDatIndex(); + insVcsDatIndex.fillData(resInsVcsDatIndex); + + long vcs_combine_addr = Vcxbase.make_gige_vcs_address(MyApp.bytesToInt(insGigeIoDatHeader.getHub(),false) >= 1 ? (MyApp.bytesToInt(insGigeIoDatHeader.getHub(),false) - 1) : 0, + MyApp.bytesToInt(insGigeIoDatHeader.getHub_port(),false), MyApp.bytesToInt(insVcsDatIndex.getVcs(),false), MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false)); + + if (MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false) == vcs_t6_type){ + if (dat_type == 0x0 && MyApp.bytesToInt(insVcsDatIndex.getVcm_box_gamma_dat_idx(),false) == ul_dat_idx) // gamma dat idx + { + p_ram_buff[MyApp.bytesToInt(insVcsDatIndex.getVcs(),false)] = 0 ; + } + if (dat_type == 0x1 && MyApp.bytesToInt(insVcsDatIndex.getVcm_box_cfg_dat_idx(),false) == ul_dat_idx) // box cfg cmd idx + { + p_ram_buff[MyApp.bytesToInt(insVcsDatIndex.getVcs(),false)] = 0 ; + } + } else { + if (dat_type == 0x0 && MyApp.bytesToInt(insVcsDatIndex.getVcm_box_gamma_dat_idx(), false) == ul_dat_idx) // gamma dat idx + { + enable_vcs_write_cmd_with_fcard(_cur_gige_combine_addr, vcs_combine_addr, 1); + } + if (dat_type == 0x1 && MyApp.bytesToInt(insVcsDatIndex.getVcm_box_cfg_dat_idx(), false) == ul_dat_idx) // box cfg cmd idx + { + enable_vcs_write_cmd_with_fcard(_cur_gige_combine_addr, vcs_combine_addr, 1); + } + } + + } + if (MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false) == vcs_t6_type) + { + enable_vcs_write_cmd_with_tcard(_cur_gige_combine_addr,p_ram_buff,Vcxbase.MAX_LOCK_WRITE_TIME_MS); // 网口串联的接收卡写访问 + } + } + } + + /** + * p_ins_vcs_cfg_dat_header : reCardHeader + * * p_gige_header :insGigeIoDatHeader + * * p_ins_vcs_dat_index :insVcsDatIndex + * @param reCardHeader + * @param basic_fls_dat_adr + * @param dat_type + * @param ul_dat_idx + * @param ul_vcs_dat_io_addr + * @param p_dat + * @param dat_size + */ + void _ins_vcs_data_write_with_type(ReCardHeader reCardHeader, long basic_fls_dat_adr,char dat_type, long ul_dat_idx, long ul_vcs_dat_io_addr, byte[] p_dat, long dat_size) + { + long ul_temp_dat_addr, ul_gige_addr_idx ; + for (ul_gige_addr_idx = 0; ul_gige_addr_idx < MyApp.bytesToInt(reCardHeader.getGige_access_addr_cnt(),false); ul_gige_addr_idx ++) + { + ul_temp_dat_addr = basic_fls_dat_adr + MyApp.bytesToInt(reCardHeader.getVcm_gige_access_dat_bgn_addr(),false) + ul_gige_addr_idx * MyApp.bytesToInt(reCardHeader.getGige_access_item_unit_size(),false); +// vcm_fls_r(ul_temp_dat_addr,p_dynamic_buff,sizeof(ins_gige_io_dat_header)); +// +// ins_gige_io_dat_header *p_gige_header = (ins_gige_io_dat_header *)p_dynamic_buff; + byte[] p_dynamic_buff = MyApp.card().flashRead((int) ul_temp_dat_addr,12); + InsGigeIoDatHeader insGigeIoDatHeader = new InsGigeIoDatHeader(); + insGigeIoDatHeader.fillData(p_dynamic_buff); + + long _cur_gige_combine_addr = Vcxbase.make_gige_address(MyApp.bytesToInt(insGigeIoDatHeader.getGige_port(),false), MyApp.bytesToInt(insGigeIoDatHeader.getHub(),false) >= 1 ? (MyApp.bytesToInt(insGigeIoDatHeader.getHub(),false) - 1) : 0, + MyApp.bytesToInt(insGigeIoDatHeader.getHub_port(),false)); + + for ( long vcs_idx = 0; vcs_idx < MyApp.bytesToInt(insGigeIoDatHeader.getVcs_cnts(),false); vcs_idx++) + { + ul_temp_dat_addr = basic_fls_dat_adr + MyApp.bytesToInt(reCardHeader.getVcm_gige_access_dat_bgn_addr(),false) + MyApp.bytesToInt(insGigeIoDatHeader.getDat_index_bgn_addr(),false) + + vcs_idx * MyApp.bytesToInt(insGigeIoDatHeader.getDat_index_unit_size(),false) ; + +// ins_vcs_dat_index *p_ins_vcs_dat_index = (ins_vcs_dat_index *)(p_dynamic_buff + sizeof(ins_gige_io_dat_header)); +// vcm_fls_r(ul_temp_dat_addr,p_ins_vcs_dat_index,sizeof(ins_vcs_dat_index)); + byte[] resInsVcsDatIndex = MyApp.card().flashRead((int) ul_temp_dat_addr,12); + InsVcsDatIndex insVcsDatIndex = new InsVcsDatIndex(); + insVcsDatIndex.fillData(resInsVcsDatIndex); + + long vcs_combine_addr = Vcxbase.make_gige_vcs_address(MyApp.bytesToInt(insGigeIoDatHeader.getHub(),false) >= 1 ? (MyApp.bytesToInt(insGigeIoDatHeader.getHub(),false) - 1) : 0, + MyApp.bytesToInt(insGigeIoDatHeader.getHub_port(),false), MyApp.bytesToInt(insVcsDatIndex.getVcs(),false), MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false)); + + if (MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false) == Vcxbase.vcs_fpga_type) + { + if (dat_type == 0x0 && MyApp.bytesToInt(insVcsDatIndex.getVcm_box_gamma_dat_idx(),false) == ul_dat_idx) // gamma dat idx + { + vcs_dat_w(_cur_gige_combine_addr, vcs_combine_addr, ul_vcs_dat_io_addr, p_dat, (int) dat_size, MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false), DEF_PKT_INTERVAL_MS); + } + if (dat_type == 0x1 && MyApp.bytesToInt(insVcsDatIndex.getVcm_box_cfg_dat_idx(),false) == ul_dat_idx) // box cfg cmd idx + { + vcs_dat_w(_cur_gige_combine_addr, vcs_combine_addr, ul_vcs_dat_io_addr, p_dat, (int) dat_size, MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false), DEF_PKT_INTERVAL_MS); + } + } + } + } + } + + /** + * p_ins_vcs_cfg_dat_header : reCardHeader + * * p_gige_header :insGigeIoDatHeader + * * p_ins_vcs_dat_index :insVcsDatIndex + * @param dat_fls_addr + * @param dat_len + * @param vcs_type + * @param vcs_dat_io_addr + * @return + */ + + int _ins_broardcast_vcs_write_dat( long dat_fls_addr, long dat_len, char vcs_type, long vcs_dat_io_addr) + { +// MyLog.i("dat_fls_addr:"+ Define.PrintIntToHex((int) dat_fls_addr)); +// MyLog.i("dat_len:"+Define.PrintIntToHex((int) dat_len)); +// MyLog.i("vcs_type:"+Define.PrintIntToHex(vcs_type)); +// MyLog.i("vcs_dat_io_addr:"+Define.PrintIntToHex((int) vcs_dat_io_addr)); + + int i_ret = 0 ; + + long div_unit = Vcxbase.MAX_VCS_PKT_DAT_UNIT_SIZE * 4 ; + long iCount = dat_len / div_unit ; + long iMod = dat_len % div_unit ; + + for ( long i = 0; i < iCount; i ++){ +// vcm_fls_r(dat_fls_addr+i*div_unit,p_ram_buff,div_unit); + byte[] p_ram_buff = MyApp.card().flashRead((int)(dat_fls_addr+i*div_unit),(int)div_unit); +// MyLog.showBytes("p_ram_buff",p_ram_buff,32); + i_ret = vcs_dat_w(vcm_port_broadcast_address + ,tcard_vcs_broadcast_address + ,vcs_dat_io_addr + i*Vcxbase.MAX_VCS_PKT_DAT_UNIT_SIZE + ,p_ram_buff + ,Vcxbase.MAX_VCS_PKT_DAT_UNIT_SIZE + ,vcs_type + , DEF_PKT_INTERVAL_MS + ); + } + if (iMod>0 && (iMod%4) == 0) + { +// vcm_fls_r(dat_fls_addr+iCount*div_unit,p_ram_buff,iMod); + byte[] p_ram_buff = MyApp.card().flashRead((int)(dat_fls_addr+iCount*div_unit),(int)iMod); +// MyLog.showBytes("p_ram_buff",p_ram_buff,32); + i_ret = vcs_dat_w(vcm_port_broadcast_address + ,tcard_vcs_broadcast_address + ,vcs_dat_io_addr + iCount*Vcxbase.MAX_VCS_PKT_DAT_UNIT_SIZE + ,p_ram_buff + ,(int)iMod/4 + ,vcs_type + , DEF_PKT_INTERVAL_MS + ); + } + return i_ret ; + } + + + /** + *调整伽马 + * @param reCardHeader + * @return + */ + public int ins_update_vcs_gamma(ReCardHeader reCardHeader, long basic_fls_dat_adr){ + MyLog.i("-----------------ins_update_vcs_gamma----------------"); + int errorcode = 0 ; + + _ins_enable_all_vcs_data_write( MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false),1); // 开启写 + + MyApp.sleepForMillisecond(10); + + if ( MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false) == vcs_t6_type ) + { + byte[] p_ram_buff = new byte[4]; + memset(p_ram_buff, 0xA5, 4); + vcs_dat_w(vcm_port_broadcast_address, tcard_vcs_broadcast_address, make_vcs_io_address(io_type_reg, 0x103), p_ram_buff, 1, MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false), DEF_PKT_INTERVAL_MS); + + MyApp.sleepForMillisecond(2); + + memset(p_ram_buff, 0, 4); + p_ram_buff[0] = (byte) 0xA5; // 关闭 + p_ram_buff[3] = 0x07; + + vcs_dat_w(vcm_port_broadcast_address, tcard_vcs_broadcast_address, make_vcs_io_address(io_type_reg, 0x104), p_ram_buff, 1, MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false), DEF_PKT_INTERVAL_MS); + + MyApp.sleepForMillisecond(50); + } + byte[] p_ram_buff = new byte[4096]; + for ( long ul_gamma_item_idx = 0; ul_gamma_item_idx < MyApp.bytesToInt(reCardHeader.getBox_gamma_dat_cnts(),false); ul_gamma_item_idx ++) + { + // 屏蔽不需要发送的接收卡 , 同时打开需要写入的接收卡 + _ins_enable_vcs_data_write(reCardHeader,basic_fls_dat_adr,(char)0x0,ul_gamma_item_idx,(char)1); + + MyApp.sleepForMillisecond(100); + + long ul_dat_index_addr = basic_fls_dat_adr + MyApp.bytesToInt(reCardHeader.getVcm_box_gamma_dat_bgn_addr(),false) + ul_gamma_item_idx * MyApp.bytesToInt(reCardHeader.getBox_gamma_dat_index_unit_size(),false); +// vcm_fls_r(ul_dat_index_addr,p_static_buff,p_ins_vcs_cfg_dat_header->box_gamma_dat_index_unit_size); +// ins_vcs_cmd_index *p_vcs_data_index = (ins_vcs_cmd_index *)p_static_buff ; + + byte[] p_static_buff = MyApp.card().flashRead((int) ul_dat_index_addr,12); + InsVcsCmdIndex insVcsCmdIndex = new InsVcsCmdIndex(); + insVcsCmdIndex.fillData(p_static_buff); + + long ul_gamma_dat_fls_addr = basic_fls_dat_adr + MyApp.bytesToInt(reCardHeader.getVcm_box_gamma_dat_bgn_addr(),false) + MyApp.bytesToInt(insVcsCmdIndex.getVcm_cmd_pkt_addr(),false) ; + + if (MyApp.bytesToInt(insVcsCmdIndex.getCmd_pkt_unit_size(),false) < 4096) { + continue; + } + if ( MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false) == vcs_t6_type ) + { + long ul_gamma_count = 60, ul_brightness; + long ul_dat_addr = (894 - ul_gamma_count) * 0x400; + long[] p_src_gamma_value = new long[1024]; + +// vcm_fls_r(ul_gamma_dat_fls_addr,p_ram_buff,4096); + byte[] p_ram_buff_tmp = new byte[4096]; + p_ram_buff_tmp = MyApp.card().flashRead((int) ul_gamma_dat_fls_addr,4096); + for (int i = 0;i<3;i++){ + vcs_dat_w(vcm_port_broadcast_address, tcard_vcs_broadcast_address, make_vcs_io_address(io_type_fls, (int) (0x80400 + (i * 0x400))) + , p_ram_buff_tmp, 0x400, MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false),DEF_PKT_INTERVAL_MS); + + } + +// MyApp.sleepForMillisecond(300); + p_ram_buff_tmp[0] = (byte) 0xA5; + p_ram_buff_tmp[1] = (byte) 0xA5; + p_ram_buff_tmp[2] = (byte) 0xA5; + p_ram_buff_tmp[3] = (byte) 0xA5; + vcs_dat_w(vcm_port_broadcast_address, tcard_vcs_broadcast_address, make_vcs_io_address(io_type_reg, (int) (0x103)) + , p_ram_buff_tmp, 1, MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false),DEF_PKT_INTERVAL_MS); + + p_ram_buff_tmp[0] = (byte) 0xA5; + p_ram_buff_tmp[1] = 0; + p_ram_buff_tmp[2] = 0; + p_ram_buff_tmp[3] = 0x07; + vcs_dat_w(vcm_port_broadcast_address, tcard_vcs_broadcast_address, make_vcs_io_address(io_type_reg, (int) (0x104)) + , p_ram_buff_tmp, 1, MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false),DEF_PKT_INTERVAL_MS); + MyApp.sleepForMillisecond(100); + + p_ram_buff_tmp = MyApp.card().flashRead((int) ul_gamma_dat_fls_addr,4096); +// long[] p_dst_gamma_value = p_ram_buff; + long ul_gamma_bit_levels = _get_gamma_value_with_t6(p_ram_buff_tmp,p_src_gamma_value); + for ( long gamma_idx = 1; gamma_idx <= ul_gamma_count; gamma_idx ++) + { + +// short *p_src_gamma_value = ( short *)p_dynamic_buff ; +// short *p_dst_gamma_value = ( short *)p_ram_buff ; + if (gamma_idx <= 50) { + ul_brightness = gamma_idx; + } + else { + ul_brightness = (gamma_idx - 50) * 5 + 50; + } +// _mc_dck_gama_scale_by_brightness(p_src_gamma_value, ul_gamma_bit_levels,p_dst_gamma_value, ul_brightness); + long[] p_ram_buffLong = new long[(int) ul_gamma_bit_levels]; + +// if (gamma_idx == 1){ +// MyLog.showLong("p_src_gamma_value+"+gamma_idx,p_src_gamma_value); +// } + + if (ul_brightness==100){ + System.arraycopy(p_src_gamma_value,0,p_ram_buffLong,0, (int) ul_gamma_bit_levels); + }else { + _mc_dck_gama_scale_by_brightness(p_src_gamma_value, ul_gamma_bit_levels,p_ram_buffLong, ul_brightness); + } +// if (gamma_idx == 1){ +// MyLog.showLong("p_ram_buffLong_new+"+gamma_idx,p_ram_buffLong); +// } +// memcpy(p_src_gamma_value,p_dst_gamma_value,ul_gamma_bit_levels*sizeof( short)); +// System.arraycopy(p_dst_gamma_value,0,p_src_gamma_value,0, (int) ul_gamma_bit_levels); +// System.arraycopy(p_ram_buff,0,p_src_gamma_value,0, (int) ul_gamma_bit_levels); + // 组合gamma + if (ul_gamma_bit_levels == 256) + { + for ( long idx = 0; idx < ul_gamma_bit_levels; idx++) + { + long tmp_val = p_ram_buffLong[(int) idx] ; + /*if (gamma_idx==1){ + MyLog.i("idx="+idx+"====="+tmp_val); + }*/ + tmp_val <<= 4; + + for ( long grp_gmma_idx = 0; grp_gmma_idx < 4; grp_gmma_idx++) + { + p_ram_buff[(int) (idx * 12 + grp_gmma_idx * 3 + 0)] = (byte) ((tmp_val >> 0) & 0xff); + p_ram_buff[(int) (idx * 12 + grp_gmma_idx * 3 + 1)] = (byte) ((tmp_val >> 8) & 0xff); + p_ram_buff[(int) (idx * 12 + grp_gmma_idx * 3 + 2)] = (byte) ((tmp_val >> 16) & 0x0f); + /*if (gamma_idx==1){ + MyLog.i(idx * 12 + grp_gmma_idx * 3 + 0+"==="+p_ram_buff[(int) (idx * 12 + grp_gmma_idx * 3 + 0)]); + MyLog.i(idx * 12 + grp_gmma_idx * 3 + 1+"==="+p_ram_buff[(int) (idx * 12 + grp_gmma_idx * 3 + 1)]); + MyLog.i(idx * 12 + grp_gmma_idx * 3 + 2+"==="+p_ram_buff[(int) (idx * 12 + grp_gmma_idx * 3 + 2)]); + }*/ + } + } +// if (gamma_idx==1){ +// MyLog.i("addr:"+(ul_dat_addr + (gamma_idx-1) * 0x400)); +//// MyLog.showBytes("p_ram_buff",p_ram_buff,3072); +// } + }else{ + for ( long idx = 0; idx < ul_gamma_bit_levels; idx++) + { + long tmp_val = p_ram_buffLong[(int) idx] ; + tmp_val <<= 4; + p_ram_buff[(int) (idx * 3 + 0)] = (byte) ((tmp_val >> 0) & 0xff); + p_ram_buff[(int) (idx * 3 + 1)] = (byte) ((tmp_val >> 8) & 0xff); + p_ram_buff[(int) (idx * 3 + 2)] = (byte) ((tmp_val >> 16) & 0x0f); + } + } + + long gamma_id = 0x9A + ul_brightness; + System.arraycopy(MyApp.longToBytes(gamma_id,4),0,p_ram_buff,4096 - 8,4); + gamma_id = ul_brightness; + System.arraycopy(MyApp.longToBytes(gamma_id,4),0,p_ram_buff,4096 - 12,4); +// memcpy(&p_ram_buff[4096 - 8], &gamma_id, 4); + Crc crc = new Crc(); + long gamma_crc32 = crc.calc_crc32(p_ram_buff,4092); +// gamma_crc32 = htonl(gamma_crc32); +// memcpy(&p_ram_buff[4092], &gamma_crc32, 4); + System.arraycopy(MyApp.intToBytesL_H((int) gamma_crc32,4),0,p_ram_buff,4092,4); + + // 下发gamma +// MyLog.showBytes("p_ram_buff=",p_ram_buff,128); + /* if (gamma_idx==1){ + MyLog.i("addr:"+(ul_dat_addr + (gamma_idx-1) * 0x400)); +// MyLog.showBytes("p_ram_buff",p_ram_buff,3072); + for (int i=0;i<3072;i++){ +// MyLog.i("p_ram_buff:"+p_ram_buff[i]); + p_ram_buff[i] = (byte) 0x88; + } + }*/ + + + + vcs_dat_w(vcm_port_broadcast_address, tcard_vcs_broadcast_address, make_vcs_io_address(io_type_srm, (int) (ul_dat_addr + (gamma_idx-1) * 0x400)) + , p_ram_buff, 0x400, MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false),DEF_PKT_INTERVAL_MS); + /* if (gamma_idx==1){ + MyLog.i("addr:"+(ul_dat_addr + (gamma_idx-1) * 0x400)); + MyLog.showBytes("p_ram_buff",p_ram_buff,3072); + }*/ + } + + // 固化gamma数据 + long mapSdmBgnAddr = (894 - ul_gamma_count); + long mapFlsBgnAddr = 0x82400 / 0x400; + char bWrite = 1; + long mapCount = ul_gamma_count; + + memset(p_ram_buff, 0, 12); + + p_ram_buff[0 + 0] = (byte) ((mapSdmBgnAddr >> 8) & 0xff); + p_ram_buff[0 + 1] = (byte) ((mapSdmBgnAddr >> 0) & 0xff); + p_ram_buff[0 + 2] = (byte) ((mapFlsBgnAddr >> 8) & 0xff); + p_ram_buff[0 + 3] = (byte) ((mapFlsBgnAddr >> 0) & 0xff); + p_ram_buff[4 + 0] = (byte) 0xCA; + p_ram_buff[4 + 1] = (byte) ((bWrite!=0) ? 0x4E : 0x00); + p_ram_buff[4 + 2] = (byte) ((mapCount >> 8) & 0xff); + p_ram_buff[4 + 3] = (byte) ((mapCount >> 0) & 0xff); + + +// short byteSum = calc_chksum32(p_ram_buff, 8); + int byteSum = MyApp.calcCheckCode(p_ram_buff); + + p_ram_buff[8 + 0] = (byte) 0xCA; + p_ram_buff[8 + 1] = (byte) 0xA1; + p_ram_buff[8 + 2] = (byte) ((byteSum >> 8) & 0xff); + p_ram_buff[8 + 3] = (byte) ((byteSum >> 0) & 0xff); + + vcs_dat_w(vcm_port_broadcast_address, tcard_vcs_broadcast_address,make_vcs_io_address(io_type_reg, 0x2F2) + , p_ram_buff, 3, MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false),DEF_PKT_INTERVAL_MS); + + + } + else + { + long ul_srm_dat_sector_a0 = 0xD1; + long ul_fls_dat_sector_a0 = 0x1f0; + long ul_dat_sector_n = 3; + + // 写数据到sdram + + + if (MyApp.bytesToInt(insVcsCmdIndex.getCmd_pkt_unit_size(),false) == 4096) + { +// vcm_fls_r(ul_gamma_dat_fls_addr,p_ram_buff,4096); + p_ram_buff = MyApp.card().flashRead((int) ul_gamma_dat_fls_addr,4096); + + for ( long _dat_item_idx = 0; _dat_item_idx < ul_dat_sector_n; _dat_item_idx++) { + vcs_dat_w(vcm_port_broadcast_address, Vcxbase.fcard_vcs_broadcast_address, make_vcs_io_address(io_type_srm, (int) ((ul_srm_dat_sector_a0 + _dat_item_idx) * 0x400)), p_ram_buff, + 0x400, MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false),DEF_PKT_INTERVAL_MS); + } + }else{ + for ( long _dat_item_idx = 0; _dat_item_idx < ul_dat_sector_n; _dat_item_idx++) { +// vcm_fls_r(ul_gamma_dat_fls_addr+_dat_item_idx*4096,p_ram_buff,4096); + + p_ram_buff = MyApp.card().flashRead((int) ((int) ul_gamma_dat_fls_addr+_dat_item_idx*4096),4096); + vcs_dat_w(vcm_port_broadcast_address, Vcxbase.fcard_vcs_broadcast_address, make_vcs_io_address(io_type_srm, (int) ((ul_srm_dat_sector_a0 + _dat_item_idx) * 0x400)), p_ram_buff, + 0x400, MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false),DEF_PKT_INTERVAL_MS); + } + } + + /*镜像SDRAM数据到FLASH*/ + long fpga_mirr_cmd_val = 0; + fpga_mirr_cmd_val |= (ul_srm_dat_sector_a0 << 0) ; + fpga_mirr_cmd_val |= (ul_fls_dat_sector_a0 << 9) ; + fpga_mirr_cmd_val |= (ul_dat_sector_n << 19) ; + fpga_mirr_cmd_val |= (1 << 29) ; + fpga_mirr_cmd_val |= (1 << 30) ; + + byte[] bs = new byte[4] ; + bs[0] = (byte) ((fpga_mirr_cmd_val >> 24) & 0xff); + bs[1] = (byte) ((fpga_mirr_cmd_val >> 16) & 0xff); + bs[2] = (byte) ((fpga_mirr_cmd_val >> 8) & 0xff); + bs[3] = (byte) ((fpga_mirr_cmd_val >> 0) & 0xff); + + _ins_vcs_data_write_with_type(reCardHeader,basic_fls_dat_adr,(char) 0x0,ul_gamma_item_idx, make_vcs_io_address(io_type_reg, 0x02),bs,1); + + } + } + // 等待数据固化完成 + _ins_enable_all_vcs_data_write(MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false),1); // 允许写 + + if (MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false) == vcs_t6_type) + { + MyApp.sleepForMillisecond(60 * 300);// 固化等待gamma数据执行完成 + byte[] p_ram_buff_tmp = new byte[4]; + p_ram_buff_tmp[0] = (byte) 0xAA; + p_ram_buff_tmp[1] = 0; + p_ram_buff_tmp[2] = 0; + p_ram_buff_tmp[3] = 0x07; + vcs_dat_w(vcm_port_broadcast_address, tcard_vcs_broadcast_address, make_vcs_io_address(io_type_reg, (int) (0x104)) + , p_ram_buff_tmp, 1, MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false),DEF_PKT_INTERVAL_MS); + + p_ram_buff_tmp[0] = (byte) 0xA5; + p_ram_buff_tmp[1] = 0; + p_ram_buff_tmp[2] = 0; + p_ram_buff_tmp[3] = 0x07; + vcs_dat_w(vcm_port_broadcast_address, tcard_vcs_broadcast_address, make_vcs_io_address(io_type_reg, (int) (0x105)) + , p_ram_buff_tmp, 1, MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false),DEF_PKT_INTERVAL_MS); + MyApp.sleepForMillisecond(300); + } + else + { + MyApp.sleepForMillisecond(1500); // 等待sdram->flash镜像完成 + // 加载gamma数据 + byte[] dat = {(byte) 0x80,0x37, (byte) 0xC3, (byte) 0xFD}; + + vcs_dat_w(vcm_port_broadcast_address, Vcxbase.fcard_vcs_broadcast_address, make_vcs_io_address(io_type_reg, 0x02), dat, 1, MyApp.bytesToInt(reCardHeader.getBox_dat_type(),false),DEF_PKT_INTERVAL_MS); + + MyApp.sleepForMillisecond(500); //等待sdram->flash镜像完成 + } + return errorcode ; + } + + public int _mc_dck_gama_scale_by_brightness(long[] aui_gama_tbl, long ui_tbl_size, long[] aui_out_gama_tbl, long ui_brightness_percent) + { + + if (100 <= ui_brightness_percent) { + return 0; + } + long idx_gama ; + char b_continuous_inc = 1; + for (idx_gama = 1; idx_gama < ui_tbl_size; idx_gama++) + { + if (aui_gama_tbl[(int) idx_gama] < aui_gama_tbl[(int) (idx_gama - 1)]) { + b_continuous_inc = 0; + break; + } + } + + if (b_continuous_inc!=0) + { + if (0 < ui_brightness_percent && 0 < ui_tbl_size) + { + long u32_pos_idx = ui_tbl_size - 1; + double df_max_gama = ui_brightness_percent * aui_gama_tbl[(int) (ui_tbl_size - 1)] / 100.0; + for (int idx = 0; idx < ui_tbl_size; idx++) + { + if (aui_gama_tbl[idx] > df_max_gama) + { + u32_pos_idx = idx; + if (0 < idx) + { + double df_gap_1 = aui_gama_tbl[idx] - df_max_gama; + double df_gap_2 = df_max_gama - aui_gama_tbl[idx - 1]; + if (df_gap_1 > df_gap_2) + { + u32_pos_idx = idx - 1; + } + } + break; + } + } + double df_slope_value = u32_pos_idx * 1.0 / (ui_tbl_size - 1); + for (int idx = 0; idx < ui_tbl_size; idx++) + { + int i_new_idx = (int)((double)(idx * df_slope_value) + 0.5); + if (i_new_idx >= ui_tbl_size) { + i_new_idx = (int) (ui_tbl_size - 1); + } + aui_out_gama_tbl[idx] = aui_gama_tbl[i_new_idx]; + } + } + } + else + { + double df_scal_percent = ui_brightness_percent / 100.0; + for (idx_gama = 0; idx_gama < ui_tbl_size; idx_gama++) + { + aui_gama_tbl[(int) idx_gama] = (long) (((double)aui_gama_tbl[(int) idx_gama] * df_scal_percent) + 0.5); + } + } + + return 0; + } + + public long _get_gamma_value_with_t6( byte[] p_gamma_dat, long[] p_out_gamma_value){ + /* byte[] bs = new byte[4]; + int a = 0xEC; + int b = 0xc6; + int c = 0x01; + + bs[1]= (byte) a; + bs[2]= (byte) b; + bs[3]= (byte) c; + MyLog.showBytes("bs======",bs,0); + long lll = MyApp.bytesToInt(bs,true); + MyLog.i("lll======="+lll);*/ + + long _cur_gamma_value = 0; + byte[] p_temp_gamma_dat = p_gamma_dat; + long same_group_gamma_cnts = 0; + long ul_gamma_item_idx = 0; + for (ul_gamma_item_idx = 0; ul_gamma_item_idx < 256; ul_gamma_item_idx++) + { + char bSame = 1; + for (long gamma_group_item_idx = 1; gamma_group_item_idx < 4; gamma_group_item_idx++) + { + //分4段 + for (long idx = 0;idx < 3;idx ++) { + if (p_temp_gamma_dat[(int) (ul_gamma_item_idx*12 + 0)] != p_temp_gamma_dat[(int) (ul_gamma_item_idx*12 + gamma_group_item_idx*3 + 0)] || + p_temp_gamma_dat[(int) (ul_gamma_item_idx*12 + 1)] != p_temp_gamma_dat[(int) (ul_gamma_item_idx*12 + gamma_group_item_idx*3 + 1)] || + p_temp_gamma_dat[(int) (ul_gamma_item_idx*12 + 2)] != p_temp_gamma_dat[(int) (ul_gamma_item_idx*12 + gamma_group_item_idx*3 + 2)] + ) + { + bSame = 0 ; + break; + } + + } + +// if (memcmp(p_temp_gamma_dat, p_temp_gamma_dat + gamma_group_item_idx * 3, 3) != 0) { +// bSame = 0 ; +// break; +// } + } + if (bSame!=0) { + same_group_gamma_cnts ++ ; + } + // p_temp_gamma_dat += 12; + } + p_temp_gamma_dat = p_gamma_dat; + + if (same_group_gamma_cnts >= 128) // 8bit + { + for (ul_gamma_item_idx = 0; ul_gamma_item_idx < 256; ul_gamma_item_idx++) + { + byte[] temp = new byte[4]; + temp[1] = p_temp_gamma_dat[(int) (ul_gamma_item_idx*12+2)]; + temp[2] = p_temp_gamma_dat[(int) (ul_gamma_item_idx*12+1)]; + temp[3] = p_temp_gamma_dat[(int) (ul_gamma_item_idx*12+0)]; +// _cur_gamma_value = (p_temp_gamma_dat[(int) (ul_gamma_item_idx*12+0)]) + (p_temp_gamma_dat[(int) (ul_gamma_item_idx*12+1)] *256) + (p_temp_gamma_dat[(int) (ul_gamma_item_idx*12+2)] *65536); + _cur_gamma_value = MyApp.bytesToInt(temp,true); + _cur_gamma_value = _cur_gamma_value >> 4; +// MyLog.i("_cur_gamma_value:"+_cur_gamma_value); + + p_out_gamma_value[(int) ul_gamma_item_idx] = (_cur_gamma_value & 0xffff); + +// p_temp_gamma_dat += 12; + } + same_group_gamma_cnts = 256; + } + else // 10 bit + { + for (ul_gamma_item_idx = 0; ul_gamma_item_idx < 1024; ul_gamma_item_idx++) + { + + byte[] temp = new byte[4]; + temp[1] = p_temp_gamma_dat[(int) (ul_gamma_item_idx*3+2)]; + temp[2] = p_temp_gamma_dat[(int) (ul_gamma_item_idx*3+1)]; + temp[3] = p_temp_gamma_dat[(int) (ul_gamma_item_idx*3+0)]; + +// ul_gamma_item_idx = ( long)(( long)p_temp_gamma_dat[(int) (ul_gamma_item_idx*3+0)]) | ( long)(( long)p_temp_gamma_dat[(int) (ul_gamma_item_idx*3+1)] << 8) | ( long)(( long)p_temp_gamma_dat[(int) (ul_gamma_item_idx*3+2)] << 16); + _cur_gamma_value = MyApp.bytesToInt(temp,true); + _cur_gamma_value >>= 4; + + p_out_gamma_value[(int) ul_gamma_item_idx] = (_cur_gamma_value & 0xffff); + +// p_temp_gamma_dat += 3; + } + same_group_gamma_cnts = 1024; + } + + return same_group_gamma_cnts ; + } + +} diff --git a/app/src/main/java/com/xixun/display/backup/Vcxbase.java b/app/src/main/java/com/xixun/display/backup/Vcxbase.java new file mode 100644 index 0000000..842414d --- /dev/null +++ b/app/src/main/java/com/xixun/display/backup/Vcxbase.java @@ -0,0 +1,103 @@ +package com.xixun.display.backup; + +public class Vcxbase { + public static int ltcp_pket_size=22; + public static int ltcp_pre_bytes=2; + public static int ltcp_ext_bytes=2; + public static int ltcp_dat_crc_bytes=4; + + public static int ltcp_pkt_header_size=22; + public static int ltcp_pkt_header_no_crc_size=18; + + + public static int ltcp_packet_ext_size=2; + public static int ltcp_packet_header_size=22; + + public static int ltcp_packet_crc_size=4; + + + public static int io_type_srm=0xd0000000; + public static int io_type_reg=0xda000000; + public static int io_type_fls=0xdf000000; + public static int make_vcs_io_address(int io_type,int addr){ + return io_type+addr; + } + + public static int vcm_port_broadcast_address=0xff; + + public static int hub_broadcast_address=0x10ff0000; + + public static int all_vcs_broadcast_address=0x10ffffff; + public static int fcard_vcs_broadcast_address=0x10ff2fff; + public static int tcard_vcs_broadcast_address=0x10ff0fff; + + public static int vcs_broadcast_address=0xfff; + public static int vcs_broadcast_type=0xf; + + public static int vcs_t6_type=0; + public static int vcs_muti_card_type=1; + public static int vcs_fpga_type=2; + // hub_idx : hub地址序号,范围: 0~ffh 如果为0xff表示广播 + // hub_port: hub端口序号,范围: 0~10h,如果为0x10表示广播 + // vcs: 接收卡序号,范围: 0 ~ fffh , 如果为fffh表示广播. + // type: 接收卡类型, 范围0~fh ,如果为fh表示广播. + // vcs_tcard_type = 0 ; vcs_mcard_type = 1 , vcs_fcard_type = 2 , vcs_broardcast_type = 0xf ; + public static int make_gige_vcs_address(int hub_idx,int hub_port,int vcs,int type){ + return (int) ((((long)(hub_port&0xff))<<24) | ((( long)(hub_idx&0xff)) << 16) | ((( long)(type&0xf)) << 12) | ((( long)(vcs&0xfff)) << 0)); + } + + public static int vcs_at_hub_idx(int vcs) { + return (int) (((long)((( long)vcs) >> 16) ) & 0xff); + } + public static int vcs_at_hub_port(int vcs) { + return (int) ((( long)((( long)vcs) >> 24) ) & 0xff); + } + public static int vcs_at_type(int vcs){ + return (int) (((long)(((long)vcs) >> 12) ) & 0xf); + } + public static int vcs_at_addr(int vcs){ + return (int) ((( long)((( long)vcs) >> 0) ) & 0xfff); + } + + public static int make_gige_address(int gige_idx,int hub_idx,int hub_port){ + return (int) (((( long)(hub_port&0xff))<<24) | ((( long)(hub_idx&0xff)) << 16) | ((( long)(gige_idx&0xff)) << 0)); + + } + public static int gige_at_hub_idx(int addr){ + return (int) ((( long)((( long)addr) >> 16) ) & 0xff); + } + public static int gige_at_hub_port(int addr){ + return (int) ((( long)((( long)addr) >> 24) ) & 0xff); + } + public static int gige_at_port(int addr){ + return (int) ((( long)((( long)addr) >> 0) ) & 0xf); + } + + public static int vcx_io_address(int ha,int type,int la){ + return make_long(((type)<<12) | (la) , ha); + } + + public static int make_long(int a, int b){ + return (int) ((( short)((( long)(a)) & 0xffff)) | (( long)(( short)((( long)(b)) & 0xffff))) << 16); + + } + public static int BOOT_INFO_ADDR1=0X7C; //BOOT信息存储的扇区号 + public static int BOOT_INFO_ADDR2=0X7E; //备份的BOOT信息存储的扇区号 + + public static int USB_WRITE_TIMEOUT=500; + public static int PACK_HEAD_SIZE=16; + public static int MAX_PACKET_SIZE=146; + public static int MIN_PACKET_SIZE=18; + + public static int NO_PKT_INTERVAL_MS=0; + public static int MAX_VCS_PKT_DAT_UNIT_SIZE=256; + + public static int PORT_IS_BASY= 0x1; + public static int PORT_HAVE_NEW_PACK= 0x2; + + public static int PORT_IS_CONNECT= 0x4; + public static int PORT_IS_BACKUP= 0x8; + + public static int DEF_PKT_INTERVAL_MS=-1; + public static int MAX_LOCK_WRITE_TIME_MS=0xFFFF; +} diff --git a/app/src/main/java/com/xixun/display/controller/BaseController.java b/app/src/main/java/com/xixun/display/controller/BaseController.java new file mode 100644 index 0000000..ecaccbe --- /dev/null +++ b/app/src/main/java/com/xixun/display/controller/BaseController.java @@ -0,0 +1,3410 @@ +package com.xixun.display.controller; + +import android.content.Intent; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.graphics.Color; +import android.graphics.Point; +import android.os.Build; +import android.os.Environment; +import android.support.annotation.RequiresApi; + +import com.google.gson.Gson; +import com.google.gson.JsonSyntaxException; +import com.google.gson.reflect.TypeToken; +import com.iflyings.android.fpgadetect.FpgaDetect; +import com.xixun.communicate.Protocol.NET_COMMU_TYPE; +import com.xixun.communicate.SpiDevice; +import com.xixun.communicate.WorkParams; +import com.xixun.display.MyApp; +import com.xixun.display.MyLog; +import com.xixun.display.RecCardInfo; +import com.xixun.display.backup.BackUpBuffer; +import com.xixun.display.backup.Crc; +import com.xixun.display.backup.SendData; +import com.xixun.display.backup.Vcxbase; +import com.xixun.display.domain.Header; +import com.xixun.display.domain.Reg; +import com.xixun.display.domain.StructNetBuffer; +import com.xixun.display.domain.Variable; +import com.xixun.display.file.DiskType; + +import com.xixun.display.screenshow.Line; +import com.xixun.display.screenshow.Lines; +import com.xixun.display.screenshow.PageParams; +import com.xixun.display.screenshow.PageUI; +import com.xixun.display.screenshow.Rectangle; +import com.xixun.display.screenshow.Rectangles; +import com.xixun.display.screenshow.TopWindow; +import com.xixun.display.utils.CustomConfig; +import com.xixun.display.utils.Define; +import com.xixun.display.utils.DisplayConfig; +import com.xixun.display.utils.OtherData; +import com.xixun.display.utils.ShellUtils; +import com.xixun.display.utils.Utils; +import com.xixun.joey.aidlset.CardServiceObj; +import com.xixun.unique.CardType; + +import org.json.JSONObject; + +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.io.RandomAccessFile; +import java.lang.reflect.Type; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.zip.CRC32; + +import static com.xixun.display.backup.Vcxbase.DEF_PKT_INTERVAL_MS; +import static com.xixun.display.backup.Vcxbase.io_type_reg; +import static com.xixun.display.backup.Vcxbase.io_type_srm; +import static com.xixun.display.backup.Vcxbase.make_vcs_io_address; +import static com.xixun.display.domain.Variable.STREAM_SYNC_HEAD; +import static java.lang.Thread.sleep; + +public abstract class BaseController{ + + public static SpiDevice spiDevice = null; + public String deviceName="/dev/spidev0.0"; + public int baudRate=12*1000*1000; + public int mode=1; + + public String strStoragePath=null; + public RandomAccessFile fpgaParamsFile = null; + public RandomAccessFile fpgaRegFile = null; + public WorkParams workParams=null; + public Reg reg = null; + public boolean isReply; + public StructNetBuffer structNetBuffer = null; + + public BackUpBuffer backUpBuffer = null; + public int maxSize= 0; + + boolean bFirst = true; + + + byte[] GiGData_DataBuffer = new byte[2048]; + public ByteBuffer buffer; + public byte crc = 0; + public static int fpgaType =-1; + public static int pcbVersion =-1; + SendData sendData = new SendData(); + Map keyValues = new LinkedHashMap<>(); + String xixun_config_path = ""; + + //主动复位 + public static byte[] rebootReset = {0x7E,0x7E,0x55,(byte) 0xFE,0x00,0x00,0x00,0x00,(byte) 0x01,0x00,0x00,0x00,(byte) 0x03,(byte) 0x8D}; + + /*public abstract void startApSwitchTask(); + public abstract void ifConfigEth();*/ + public abstract void initSpi(); + public abstract void specialTaskForCard(); + public abstract File getFpgaFile(boolean main); + public FpgaDetect fpgaDetect; + + //使能数据 + public static byte[] xixun_enable = {(byte) 0xE5, (byte) 0xA8, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6F, 0x60, 0x33, (byte) 0x9A}; + public static byte[] xixun_enable2 = {(byte) 0xE5, (byte) 0xA8, 0x00, 0x3C, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0xA5}; + public void init() { + buffer = ByteBuffer.allocate(4096); + //初始化spi + initSpi(); + specialTaskForCard(); + //检查创建flash文件 + CreateWorkFolder(); + initFpgaFile(); + //初始化模拟寄存器 + initReg(); + + InitialWorkParams(); + + initDisplay(); + + initFpga(); +// if (!CustomConfig.getInstance().is_xixun){ + getFpgaVersion(); +// }else{ + getAllVersion(); +// } + //熙讯初始化 + initXixunConfig(); + //读取准确信息通知CardSystem + readMooncellFpgaData(); + //初始化亮度等 + initBrightness(); +// test(); + +// testSpi(); + +// backUpData(); + +// restoreData(); + +// testCrc(); +// getRelayState(0,0); +// setRelayState(0,0,"1_1,2_1,3_0,4_1,5_0,6_1,7_0,8_1"); +// getRelayState(0,0); + + // fpgaDetect = new FpgaDetect(); +// setRGB(255,0,0); + + +// restoreData(); +// test(); + + } + + public void test(){ + +// byte[] read_buff = new byte[4]; +// //箱体大小 +// sendData.vcs_dat_r(0,Vcxbase.fcard_vcs_broadcast_address,make_vcs_io_address(io_type_srm, 0x08),read_buff,read_buff.length/4,Vcxbase.vcs_fpga_type); +// MyLog.showBytes("read_buff---------",read_buff,0); +// //寄存器读 +// sendData.vcs_dat_r(0,Vcxbase.fcard_vcs_broadcast_address,make_vcs_io_address(io_type_reg, 0x03),read_buff,read_buff.length,Vcxbase.vcs_fpga_type); +// MyLog.showBytes("read_buff---------",read_buff,0); +// //寄存器写 +// read_buff[2] = (byte) (read_buff[2]+0x01); +//// sendData.vcs_dat_w(read_buff); +// //读取坏点数据 +// byte[] read_buff_data = new byte[48]; +// sendData.vcs_dat_r(0,Vcxbase.fcard_vcs_broadcast_address,make_vcs_io_address(io_type_srm, 0x30400),read_buff_data,read_buff_data.length/4,Vcxbase.vcs_fpga_type); +// MyLog.showBytes("read_buff---------",read_buff_data,0); + + /*SendData sendData = new SendData(); + *//*byte[] p_ram_buff = new byte[4096]; + for (int i = 0;i<4096;i++){ + p_ram_buff[i]=0x55; + } + byte[] p_ram_buff_tmp = new byte[4]; + p_ram_buff_tmp[0] = (byte) 0xA5; + p_ram_buff_tmp[1] = 0; + p_ram_buff_tmp[2] = 0; + p_ram_buff_tmp[3] = 0x07; + sendData.vcs_dat_w(vcm_port_broadcast_address, tcard_vcs_broadcast_address, make_vcs_io_address(io_type_reg, (int) (0x104)) + , p_ram_buff_tmp, 1, 0,DEF_PKT_INTERVAL_MS); + MyApp.sleepForMillisecond(100); + sendData.vcs_dat_w(vcm_port_broadcast_address, tcard_vcs_broadcast_address, make_vcs_io_address(io_type_srm, 0xD0800) + , p_ram_buff, 0x400, 0,DEF_PKT_INTERVAL_MS);*//* + + + byte[] read_buff = new byte[4096]; + +// vcs_addr_init(0xff); + + long gige_port = 1; + long vcs_number = 0; + int len = 1; + sendData.vcs_dat_r(gige_port,vcs_number,make_vcs_io_address(io_type_reg, 0x106),read_buff,len,Vcxbase.vcs_muti_card_type);*/ + } + + public void testCrc(){ + byte[] data = {(byte) 0xA1, (byte) 0xA2, (byte) 0xA3, (byte) 0xA4}; + Crc cr = new Crc(); + crc = cr.calc_crc8_test(data,data.length); + } + + public void initBrightness(){ + MyLog.e("initBrightness..."+DisplayConfig.getBrightness()); + setBrightness(DisplayConfig.getBrightness()); + } + + public void testSpi(){ + byte[] reBuff = new byte[256]; + IOSPI(false,0xA70000,reBuff,reBuff.length); + MyLog.showBytes("testSpi",reBuff,0); + } + + private void initFpgaFile() { + try { + fpgaRegFile = new RandomAccessFile(strStoragePath + Define.MOONCELL_FPGA_REG_FILE_NAME, "rws"); + fpgaParamsFile = new RandomAccessFile(strStoragePath + Define.MOONCELL_FPGA_PARAMS_FILE_NAME, "rws"); + }catch (Exception e){ + e.printStackTrace(); + } + } + + public void CreateWorkFolder() { + try { + File file =null; + // 优先SD卡存储目录,空间比较大: + strStoragePath= Environment.getExternalStorageDirectory().getPath(); //"/mnt/sdcard" + file = new File(strStoragePath + Define.STORAGE_PATH); + if (!file.exists()){ + Define.CreateFolder(strStoragePath+Define.STORAGE_PATH); //STORAGE_PATH = “Sysolution” + // 均无存储空间,就放在APP安装目录下,卸载或升级参数易丢失。 + if (!file.exists()) { + strStoragePath = GetAppPath(); + Define.CreateFolder(strStoragePath + Define.STORAGE_PATH); + } + MyLog.i("strStoragePath= " +strStoragePath+Define.STORAGE_PATH); + + Define.CreateFolder(strStoragePath+Define.WORK_FILES_PATH); + Define.CreateFolder(strStoragePath+Define.RECE_FILES_PATH); + ShellUtils.execCommand("chmod -R 777 "+ strStoragePath+Define.WORK_FILES_PATH, true); + ShellUtils.execCommand("chmod -R 777 "+ strStoragePath+Define.RECE_FILES_PATH, true); + } + + xixun_config_path = strStoragePath+Define.STORAGE_PATH+"/xixun_ledset.json"; + File xixu_file = new File(xixun_config_path); + if (!xixu_file.exists()){ + xixu_file.createNewFile(); + ShellUtils.execCommand("chmod -R 777 "+ xixun_config_path, true); + } + }catch (Exception e){ + e.printStackTrace(); + } + } + + public String GetAppPath() { + return MyApp.getContext().getFilesDir().getAbsolutePath(); + } + + /** + * 初始化寄存器 + */ + private void initReg() { + MyLog.i("initReg--------------"); + reg = DisplayConfig.getReg(); + reg.setVersion(MyApp.getVersion()); + reg.setDeviceId(MyApp.getDeviceId()); + reg.setProductModel(MyApp.getProductModel()); + reg.setSoNum(MyApp.getSoNum()); + reg.setRunTime(MyApp.getRunTime()); + reg.finish(); + MyLog.i("initReg finish--------------"); + DisplayConfig.getReg().getAll(); + } + + public void InitialWorkParams() { + workParams = new WorkParams(MyApp.getContext()); + } + public void initFpga(){//系统配置 + /* start config */ + byte[] ac_buf = new byte[8]; + + ac_buf[3] = 0; // card type + + ac_buf[4+0] = 0x6f & 0xff; + ac_buf[4+1] = 0x60 & 0xff; + ac_buf[4+2] = 0x33 & 0xff; + ac_buf[4+3] = (byte) (0x9a & 0xff); + + IOSPIRes(true,0xA80000,ac_buf,8); + + byte[] ac_buf2 = new byte[4]; + ac_buf2[3] = (byte) (0xa5 & 0xff); + IOSPIRes(true,0xA8003C,ac_buf2,4); + } + + public boolean initDisplay() { + /* 增加数据到32网口 */ + byte[] ac_dat = new byte[1024]; + long ul_reg_addr, ul_fls_addr, ul_dat_unit_size = 1024; + + long vcm_gige_count = MyApp.bytesToInt(MyApp.getSoNum(),true);//网口数量 + // 网口数据 + for ( long gige_port_idx = 0; gige_port_idx < vcm_gige_count; gige_port_idx++) + { + ul_reg_addr = vm_get_fpga_gige_cfg_addr(gige_port_idx); + ul_fls_addr = vm_get_fls_gige_dat_addr(gige_port_idx); + // 读取数据 + ac_dat = flashRead((int) ul_fls_addr, (int) ul_dat_unit_size); + MyLog.showBytes("flash读:"+Define.PrintIntToHex((int) ul_fls_addr),ac_dat,0); + // 写入数据 +// MyLog.showBytes("SPI写:",ac_dat,0); + IOSPIRes(true,ul_reg_addr, ac_dat, ul_dat_unit_size); + // 验证数据 + } + // 图像控制寄存器 + ul_dat_unit_size = vm_get_fpga_control_reg_size(); + ul_reg_addr = vm_get_fpga_control_reg_addr(); + ul_fls_addr = vm_get_fls_control_reg_dat_addr(); + // 读取数据 + ac_dat = flashRead((int) ul_fls_addr ,(int) ul_dat_unit_size); + MyLog.showBytes("flash读1:"+ul_fls_addr,ac_dat,0); + // 写入数据 + + //52 + ac_dat[52] = 0; + ac_dat[53] = 0; + ac_dat[54] = 0; + ac_dat[55] = 0; + ac_dat[56] = 0; + ac_dat[57] = 0; + ac_dat[58] = 0; + +// MyLog.showBytes("SPI写:",ac_dat,0); + IOSPIRes(true,ul_reg_addr, ac_dat, ul_dat_unit_size); + + /*if (CustomConfig.getInstance().is_xixun){ + ul_dat_unit_size = vm_get_fpga_control_reg_size(); + ul_reg_addr = vm_get_fpga_control_reg_addr(); + // 读取数据 + ac_dat = flashRead((int) ul_reg_addr ,(int) ul_dat_unit_size); + MyLog.showBytes("flash读:"+Define.PrintIntToHex((int) ul_reg_addr),ac_dat,0); + IOSPIRes(true,ul_reg_addr, ac_dat, ul_dat_unit_size); + }*/ + return true; + } + public long vm_get_fpga_gige_cfg_addr( long gige_port_idx) + { + long ul_addr = 0; + long ul_cfg_dat_unit_size = 1024; + if (gige_port_idx >= 0 && gige_port_idx <= 7){ + ul_addr = 0xA70000 + (ul_cfg_dat_unit_size * gige_port_idx); + } + else if (gige_port_idx >= 8 && gige_port_idx <= 15){ + ul_addr = 0xA82000 + (ul_cfg_dat_unit_size * (gige_port_idx - 8)); + } + else if (gige_port_idx >= 16 && gige_port_idx <= 31){ + ul_addr = 0xA84000 + (ul_cfg_dat_unit_size * (gige_port_idx - 16)); + } + return ul_addr; + } + public long vm_get_fls_gige_dat_addr( long gige_port_idx) + { + long ul_addr = 0; + long ul_dat_unit_size = 1024; + if (gige_port_idx >= 0 && gige_port_idx <= 7){ + ul_addr = 0x8C000 + (ul_dat_unit_size * gige_port_idx); + } + else if (gige_port_idx >= 8 && gige_port_idx <= 15){ + ul_addr = 0x8F000 + (ul_dat_unit_size * (gige_port_idx - 8)); + } + else if (gige_port_idx >= 16 && gige_port_idx <= 31){ + ul_addr = 0xA0000 + (ul_dat_unit_size * (gige_port_idx - 16)); + } + return ul_addr; + } + + public long vm_get_fpga_control_reg_size() + { + return 256; + } + public long vm_get_fpga_control_reg_addr() + { + return 0xA72000; + } + public long vm_get_fls_control_reg_dat_addr() + { + return 0x8E000; + } + + /** + * 从上位机接收数据 + * @param data + * @param sendStream + */ + public void receDataFromPC(byte[] data, DataOutputStream sendStream){ + try{ +// MyLog.showBytes("data",data,20); + //填充数据/返回StructNetBuffer + structNetBuffer = fillDataFromPC(data); + if (structNetBuffer!=null){ + //校验header + boolean res = MyApp.checkHeader(structNetBuffer); +// MyLog.i("校验是否通过:"+res); + if (res){ //校验通过就发给设备 + //发送到设备端 + sendDataToCard(structNetBuffer,sendStream); + } + } + }catch (Exception e){ + e.printStackTrace(); + } + } + + private boolean is_mc_Command(byte[] heads) { + return Arrays.equals(heads, new byte[]{0x55, 0x55, (byte) 0xA1}); + } + + byte[] redundantData = null; + int redundantDataNormalLenth = 0;//剩余数据应该的长度 + /** + * 填充数据来自上位机 + * @param data + */ + public StructNetBuffer fillDataFromPC(byte[] data) { +// MyLog.showBytes("data",data,0); + /*byte[] newData = dealWithDataBuffer(data); + if (newData!=null && newData.length>0){ + structNetBuffer = fillData(newData); + }*/ + structNetBuffer = fillData(data); + return structNetBuffer; + } + + + byte[] endData = null; + int dataLenth = 0; + /** + * 处理粘包拆包的问题 + * @return + */ + public byte[] dealWithDataBuffer(byte[] data){ +// MyLog.showBytes("data",data,0); + //计算crc8 + if (data.length>28){ + //获取包头 + boolean isMc = isMCData(data); + if (isMc){ + //获取该包数据长度 + dataLenth = getDataLenth(data)+28+4; + if (dataLenth==data.length){ + //正常数据 + return data; + }else if (dataLenthdata.length){ + //包头正确,但少了数据,需要等下一次数据 + MyLog.i("data.length:"+data.length); + endData = new byte[data.length]; + System.arraycopy(data, 0,endData, 0, data.length); + MyLog.i("包头正确,但少了数据,需要等下一次数据"); + return null; + } + } else { + //包头不对,尾部数据,少包了,拼接上一次余下的数据 + MyLog.i("包头不对,尾部数据,少包了,拼接上一次余下的数据"); + MyLog.i("endData:"+endData.length); + MyLog.i("data.length:"+data.length); + int head_tail_Lenth = endData.length+data.length; + byte[] head_tail_data = new byte[head_tail_Lenth]; + System.arraycopy(endData, 0,head_tail_data, 0, endData.length); + System.arraycopy(data, 0,head_tail_data, endData.length, data.length); + return head_tail_data; + } + } + return data; + + } + + //判断包头 + public boolean isMCData(byte[] data){ + byte[] heads = {data[0],data[1],data[2]}; + boolean isMc = is_mc_Command(heads); + return isMc; + } + + //获取数据长度 + public int getDataLenth(byte[] data){ + byte[] dLen = {data[8],data[9]}; + int dataLen = MyApp.bytesToInt(dLen,true); + return dataLen; + } + + public StructNetBuffer fillData(byte[] data){ + byte[] newData = dealWithDataBuffer(data); + Crc cr = new Crc(); + if (newData!=null && isMCData(newData)){ + crc = cr.calc_crc8(newData,newData.length); +// MyLog.i("newData.len---------="+newData.length); +// MyLog.showBytes("newdata",newData,0); + byte[] dLen = {newData[8],newData[9]}; + int dataLen = MyApp.bytesToInt(dLen,true); + byte[] bdata = new byte[dataLen]; + Header header = new Header(); + structNetBuffer = new StructNetBuffer(bdata,header); + + if ((0x0D & 0xff) ==newData[3]){//表示读 +// MyLog.i("读命令.............."); +// System.arraycopy(newData, 0,newData, 0, data.length); + //拷贝数据到structNetBuffer + System.arraycopy(newData, 0,structNetBuffer.getHeaderbs(), 0, 28); + }else {//写 +// MyLog.i("写命令.............."); +// MyLog.i("newData:"+newData.length); + if (newData!=null && newData.length>0){ +// MyLog.i("dataLen:"+dataLen); + int newLen = newData.length; +// byte[] newData = new byte[28+dataLen+4]; +// System.arraycopy(data, 0,newData, 0, newData.length); + //拷贝数据到structNetBuffer + System.arraycopy(newData, 0,structNetBuffer.getHeaderbs(), 0, 28); + System.arraycopy(newData, 28,structNetBuffer.getData() , 0, newLen-28-4); + System.arraycopy(newData, newLen-4,structNetBuffer.getCheck() , 0, 4); +// structNetBuffer.toString();//打印数据 + }else { + return null; + } + } + structNetBuffer.headerbsToHeader(); + } + return structNetBuffer; + } + + /** + * 发送数据到设备端/获取到设备数据/发送给上位机 + * @param structNetBuffer + */ + public void sendDataToCard(StructNetBuffer structNetBuffer,DataOutputStream sendStream) { + try{ +// MyLog.d("Starttime sendDataToCard..."); + //设备端处理过后 + //获取读写状态 + getR_WStatue(structNetBuffer); + //区分命令 + checkCmd(structNetBuffer); +// readOrWrite(structNetBuffer); + if (isReply){ + sendDataToPC(structNetBuffer,sendStream); + } + }catch (Exception e){ + e.printStackTrace(); + } + } + + private void getR_WStatue(StructNetBuffer structNetBuffer) { + Header header = structNetBuffer.getHeader(); + switch (header.getSrv()[0] & 0xff){ + case Variable.SRV_READ_DATA://读数据 + case Variable.SRV_ANSWER_WRITE://有应答的写 + isReply = true; + break; + case Variable.SRV_NOANSWER_WRITE://无应答的写 + isReply = false; + break; + default: + MyLog.i("没有相应的命令..."); + break; + } + } + + private StructNetBuffer checkCmd(StructNetBuffer structNetBuffer) { + Header header = structNetBuffer.getHeader(); + byte[] cmds = header.getCmd(); + byte[] newCmd = {cmds[0],cmds[1],cmds[2]}; + int cmd = MyApp.bytesToInt(newCmd,true); + switch (cmd){ + case Variable.CMD_TEST://测试命令 + testCmd(structNetBuffer); + break; + case Variable.CMD_2: + structNetBuffer = spiController(structNetBuffer); + break; + case Variable.FLASH_R_W://flash读写命令 + structNetBuffer = flashController(structNetBuffer); + break; + case Variable.REG_R_W://寄存器操作命令 + structNetBuffer = regController(structNetBuffer); + break; + case Variable.Time_R_W://系统时间操作命令 + structNetBuffer = timeController(structNetBuffer); + break; + case Variable.GIG_R_W://GIG千兆网操作命令 + MyLog.i("GIG千兆网操作命令!"); + structNetBuffer = gigController(structNetBuffer); + case Variable.FIND_FLAG://查询操作命令 +// structNetBuffer = findController(structNetBuffer); +// 遇到此命令将structNetBuffer.header.option改为不是0的数返回应答 + byte[] option = {0x01,0x02}; + structNetBuffer.getHeader().setOption(option); + break; + default: + MyLog.i("没有找到匹配的命令!"); + break; + } + return structNetBuffer; + } + private void testCmd(StructNetBuffer structNetBuffer) { + Header header = structNetBuffer.getHeader(); + //需要返回的数据 + int len = MyApp.bytesToInt(header.getLen(),true); + byte[] newData = new byte[len]; + for (int i = 0; i= 8 && ul_gig_port_idx <= 15) + ul_gig_reg_addr = 0x880000 + (ul_gig_port_idx - 8) * 0x10000; + else + ul_gig_reg_addr = 0; + return ul_gig_reg_addr ; + } + + public int getGigPortWriteAddrByCmdEnd(int cmdEnd){ + int ul_gig_reg_addr; + int ul_gig_port_idx = cmdEnd & 0xff; + if (ul_gig_port_idx < 8) + ul_gig_reg_addr = 0x600000 + ul_gig_port_idx*0x10000; + else if (ul_gig_port_idx >= 8 && ul_gig_port_idx <= 15) + ul_gig_reg_addr = 0x800000 + (ul_gig_port_idx-8)*0x10000; + else + ul_gig_reg_addr = 0xff0000; + return ul_gig_reg_addr ; + } + + + //不是FE就是有效,有效才去判断千兆网忙状态,读取710000的值,不等于0代表忙 + public long vmGetFpgaGigeIdxFromGigeSendAddr(long addr){ + long ul_gige_port_idx = 0xfe; + long ul_addr = 0; + long ul_dat_unit_size = 0x10000; + if (addr != 0xFF0000){ + for (long gige_port_idx = 0; gige_port_idx < MyApp.bytesToInt(reg.getSoNum(),true); gige_port_idx++){ + if (gige_port_idx >= 0 && gige_port_idx <= 7){ + ul_addr = 0x600000 + (ul_dat_unit_size * gige_port_idx); + }else if (gige_port_idx >= 8 && gige_port_idx <= 15){ + ul_addr = 0x800000 + (ul_dat_unit_size * (gige_port_idx - 8)); + }else if (gige_port_idx >= 16 && gige_port_idx <= 31){ + ul_addr = 0x400000 + (ul_dat_unit_size * (gige_port_idx - 16)); + } + if (ul_addr == addr) { + ul_gige_port_idx = gige_port_idx; + break; + } + } + } else { + ul_gige_port_idx = 0xff; + } + return ul_gige_port_idx; + } + /** + * gig 千兆网控制器 + * @param structNetBuffer + * @return + */ + private StructNetBuffer gigController(StructNetBuffer structNetBuffer) { + Header header = structNetBuffer.getHeader(); + switch (header.getSrv()[0] & 0xff){ + case Variable.SRV_READ_DATA://读数据 + structNetBuffer = gigReadControl(structNetBuffer); + break; + case Variable.SRV_NOANSWER_WRITE://无应答的写 + gigWriteControl(structNetBuffer); + break; + case Variable.SRV_ANSWER_WRITE://有应答的写 + structNetBuffer = gigWriteControl(structNetBuffer); + break; + default: + MyLog.i("没有相应的命令..."); + break; + } + return structNetBuffer; + } + + /** + * gig 写 + * @param structNetBuffer + * @return + */ + private StructNetBuffer gigWriteControl(StructNetBuffer structNetBuffer) { + byte[] newCmd = {structNetBuffer.getHeader().getCmd()[3]};//cmd命令最后一位 + int cmd = MyApp.bytesToInt(newCmd,true); + int len = MyApp.bytesToInt(structNetBuffer.getHeader().getLen(),true); + byte[] data = structNetBuffer.getData(); + int addr = getGigPortWriteAddrByCmdEnd(cmd);//生成新的地址 + /*while (isBusySpi(addr)){ + MyLog.i("SPI write is busy..."); + MyApp.sleepForMillisecond(200); + }*/ + MyLog.e("addr====="+Define.PrintIntToHex((int) addr)); + byte[] resBuffer = IOSPI(true,addr,data,len); + structNetBuffer.setData(resBuffer); + return structNetBuffer; + } + + /** + * gig 读 + * @param structNetBuffer + * @return + */ + private StructNetBuffer gigReadControl(StructNetBuffer structNetBuffer) { + byte[] newCmd = {structNetBuffer.getHeader().getCmd()[3]};//cmd命令最后一位 + int cmd = MyApp.bytesToInt(newCmd,true); + int len = MyApp.bytesToInt(structNetBuffer.getHeader().getLen(),true); + byte[] data = structNetBuffer.getData(); + + + return structNetBuffer; + } + + /** + * 操作系统时间控制器 + * @param structNetBuffer + * @return + */ + private StructNetBuffer timeController(StructNetBuffer structNetBuffer) { + Header header = structNetBuffer.getHeader(); + switch (header.getSrv()[0] & 0xff){ + case Variable.SRV_READ_DATA://读数据 + structNetBuffer = timeReadControl(structNetBuffer); + break; + case Variable.SRV_NOANSWER_WRITE://无应答的写 + timeWriteControl(structNetBuffer); + break; + case Variable.SRV_ANSWER_WRITE://有应答的写 + structNetBuffer = timeWriteControl(structNetBuffer); + break; + default: + MyLog.i("没有相应的命令..."); + break; + } + return structNetBuffer; + } + + /** + * 设置系统时间 + * @param structNetBuffer + * @return + */ + private StructNetBuffer timeWriteControl(StructNetBuffer structNetBuffer) { + int len = MyApp.bytesToInt(structNetBuffer.getHeader().getLen(),true); + byte[] data = structNetBuffer.getData(); + byte[] timeData = new byte[8]; + System.arraycopy(data,data.length-timeData.length,timeData,0,timeData.length); + byte[] yearbs = {timeData[0],timeData[1]}; + int year = MyApp.bytesToInt(yearbs,true); + byte[] monthBs = {timeData[2]}; + int month = MyApp.bytesToInt(monthBs,true); + byte[] dayBs = {timeData[3]}; + int day = MyApp.bytesToInt(dayBs,true); + + byte[] hoursBs = {timeData[5]}; + int hours = MyApp.bytesToInt(hoursBs,true); + byte[] minBs = {timeData[6]}; + int min = MyApp.bytesToInt(minBs,true); + byte[] secondsBs = {timeData[7]}; + int seconds = MyApp.bytesToInt(secondsBs,true); + + String timeStr = year+"-"+month+"-"+day+" "+hours+":"+min+":"+seconds; + MyLog.i("timeStr:"+timeStr); + long timeStamp = MyApp.dateToStamp(timeStr); + //设置系统时间 + setSystemTime(timeStamp); + return structNetBuffer; + } + + private void setSystemTime(long timeStamp) { + //设置系统时间,没有系统权限,交给CardSystem去做 +// SystemClock.setCurrentTimeMillis(timeStamp); + MyLog.i("setSystemTime:"+timeStamp); + JSONObject object = new JSONObject(); + try { + object.put("id", "display_setSystemTime_success"); + object.put("_type", "SetSystemTime"); + object.put("time", timeStamp); + MyLog.i("executeJsonCommand...SetSystemTime"); + CardServiceObj.executeJsonCommand(object.toString()); + }catch (Exception e) { + MyLog.i( "aidl disconnect!" ); + e.printStackTrace(); + } +// } + } + + /** + * 读取系统时间 + * @param structNetBuffer + * @return + */ + private StructNetBuffer timeReadControl(StructNetBuffer structNetBuffer) { + int len = MyApp.bytesToInt(structNetBuffer.getHeader().getLen(),true); + byte[] data = structNetBuffer.getData(); + byte[] timeData = new byte[8]; + long nowTime = System.currentTimeMillis(); + String timeStr = MyApp.timeStamp2Date(""+nowTime,"yyyy:MM:dd:HH:mm:ss");//3,4,5,--->5,6,7 + MyLog.i("timeStr:"+timeStr); + String[] strs = timeStr.split(":"); + int lenth = 1; + for (int i = 0;i255){ + int len = MyApp.bytesToInt(structNetBuffer.getHeader().getLen(),true); + byte[] data = structNetBuffer.getData(); + byte[] resBuffer = regWrite(data,addr,len); + MyLog.showBytes("regWriteControl",resBuffer,0); + structNetBuffer.setData(resBuffer); + }else { + MyLog.i("addr:"+addr); + } + return structNetBuffer; + } + + private byte[] regWrite(byte[] data, int addr, int len) { + Reg reg = DisplayConfig.getReg(); + byte[] regAll = reg.getAll(); + System.arraycopy(data,0,regAll,addr,len); + reg.finish(); + return data; + } + + /** + * 读寄存器 + * @param structNetBuffer + * @return + */ + private StructNetBuffer regReadControl(StructNetBuffer structNetBuffer) { + int addr = MyApp.bytesToInt(structNetBuffer.getHeader().getAddr_dat(),true); + int len = MyApp.bytesToInt(structNetBuffer.getHeader().getLen(),true); +// byte[] data = structNetBuffer.getData(); + byte[] resBuffer = regRead(addr,len); +// MyLog.showBytes("regReadControl",resBuffer,0); + structNetBuffer.setData(resBuffer); + return structNetBuffer; + } + + private byte[] regRead(int addr,int len) { + reg = DisplayConfig.getReg(); + byte[] regAll = reg.getAll(); + MyLog.showBytes("网口数量:",reg.getSoNum(),0); +// MyLog.e("网口数量===="+reg.getSoNum()); + byte[] resBs = new byte[len]; + System.arraycopy(regAll,addr,resBs,0,len); + return resBs; + } + + /** + *操作flash + * @param structNetBuffer + */ + private StructNetBuffer flashController(StructNetBuffer structNetBuffer) { + Header header = structNetBuffer.getHeader(); + switch (header.getSrv()[0] & 0xff){ + case Variable.SRV_READ_DATA://读数据 + structNetBuffer = flashReadControl(structNetBuffer); + break; + case Variable.SRV_NOANSWER_WRITE://无应答的写 + flashWriteControl(structNetBuffer); + break; + case Variable.SRV_ANSWER_WRITE://有应答的写 + structNetBuffer = flashWriteControl(structNetBuffer); + break; + default: + MyLog.i("没有相应的命令..."); + break; + } + return structNetBuffer; + + } + + private StructNetBuffer flashWriteControl(StructNetBuffer structNetBuffer) { + int addr = MyApp.bytesToInt(structNetBuffer.getHeader().getAddr_dat(),true); + int len = MyApp.bytesToInt(structNetBuffer.getHeader().getLen(),true); + byte[] data = structNetBuffer.getData(); + MyLog.showBytes("flashWriteControl",data,0); + byte[] resBuffer = flashWrite(data,addr,len); + byte[] readBuffer = flashRead(addr,len); + MyLog.showBytes("flashRead",readBuffer,0); + structNetBuffer.setData(resBuffer); + return structNetBuffer; + } + + private StructNetBuffer flashReadControl(StructNetBuffer structNetBuffer) { + int addr = MyApp.bytesToInt(structNetBuffer.getHeader().getAddr_dat(),true); + int len = MyApp.bytesToInt(structNetBuffer.getHeader().getLen(),true); + byte[] resBuffer = flashRead(addr,len); + structNetBuffer.setData(resBuffer); + return structNetBuffer; + } + + /** + * 发送数据到PC端上位机 + */ + public void sendDataToPC(StructNetBuffer structNetBuffer, DataOutputStream sendStream){ + try{ + byte[] headerBs = structNetBuffer.getHeaderbs(); + byte[] data = structNetBuffer.getData(); + byte[] check = structNetBuffer.getCheck(); + byte[] resBuffer = new byte[headerBs.length+data.length+check.length]; + + byte[] option = {(byte) 0xA5, (byte) (crc & 0xff)}; + headerBs[22] = option[0]; + headerBs[23] = option[1]; + + System.arraycopy(headerBs, 0,resBuffer, 0, headerBs.length); + System.arraycopy(data, 0,resBuffer , headerBs.length, data.length); + System.arraycopy(check, 0,resBuffer , headerBs.length+data.length, check.length); +// MyLog.showBytes("sendDataToPC",resBuffer,0); + Header header = structNetBuffer.getHeader(); + switch (header.getSrv()[0] & 0xff){ + case Variable.SRV_ANSWER_WRITE: +// MyLog.showBytes("有应答写",headerBs,0); + sendStream.write(headerBs,0,headerBs.length); + break; + default: +// MyLog.showBytes("sendDataToPC",resBuffer,0); + sendStream.write(resBuffer,0,resBuffer.length); + break; + } +// sendStream.write(resBuffer,0,resBuffer.length); + sendStream.flush(); + }catch (Exception e){ + e.printStackTrace(); + } + } + + public StructNetBuffer spiController(StructNetBuffer structNetBuffer) { + int iAddress = MyApp.bytesToInt(structNetBuffer.getHeader().getAddr_dat(),true); + byte[] data = structNetBuffer.getData(); + int len = MyApp.bytesToInt(structNetBuffer.getHeader().getLen(),true); + byte[] resBs = null; + + Header header = structNetBuffer.getHeader(); + switch (header.getSrv()[0] & 0xff){ + case Variable.SRV_READ_DATA://读数据 + resBs = IOSPI(false,iAddress,data,len); + break; + case Variable.SRV_NOANSWER_WRITE://无应答的写 + case Variable.SRV_ANSWER_WRITE://有应答的写 + /*while (isBusySpi(iAddress)){ + MyLog.i("SPI write is busy..."); + MyApp.sleepForMillisecond(200); + }*/ +// MyLog.showBytes("wiAddress====="+Define.PrintIntToHex((int) iAddress),data,0); + resBs = IOSPI(true,iAddress,data,len); + break; + default: + MyLog.i("没有相应的命令..."); + break; + } + structNetBuffer.setData(resBs); + return structNetBuffer; + } + + public boolean isBusySpi(int iAddress){ + //判断是否忙状态 + long addr = vmGetFpgaGigeIdxFromGigeSendAddr(iAddress); + if (0xfe != addr){//有效 + //判断千兆网忙状态 + byte[] spiBuffer = new byte[64]; + IOSPI(false,0x710000,spiBuffer,spiBuffer.length); + byte[] busyStatue = new byte[4]; + +// System.arraycopy(spiBuffer,0,resBuffer,12+4,4);//支持状态 4 +// System.arraycopy(spiBuffer,4,resBuffer,12+4+4,4);//连接状态 4 + System.arraycopy(spiBuffer,4+4,busyStatue,0,4);//忙状态 4 +// System.arraycopy(spiBuffer,4+4+4,resBuffer,12+4+4+4+4,4);//备份 4 +// System.arraycopy(spiBuffer,4+4+4+4,resBuffer,12+4+4+4+4+4,4);//新包 4 +// System.arraycopy(spiBuffer,4+4+4+4+4,resBuffer,12+4+4+4+4+4+4,4);//支持多窗口 4 +// System.arraycopy(spiBuffer,4+4+4+4+4+4,resBuffer,12+4+4+4+4+4+4+32,32);//窗口数量 32 + + /*if (0!=MyApp.bytesToInt(busyStatue,true)){ + //代表忙需要等待 + MyLog.i("busy------------------------------------"); + return true; + }*/ +// MyLog.showBytes("spiBuffer",spiBuffer,4); + for ( int i = 0 ; i < 2 ; i ++ ) + { + if (0!=(spiBuffer[(i*2) + 1 + 0] & (0x01 << 1))) + { +// MyLog.i("busy------------------------------------"); + return true; + } + } + + } + return false; + } + + public byte[] IOSPI(boolean bWrite, int iAddress, byte[] ac_data, int iLength) { + MyLog.d("IOSPI "+(bWrite ? "Write":"read")+",iAddress:"+Define.PrintIntToHex((int) iAddress)); + + /*if (spiDevice==null){ + spiDevice = new SpiDevice(); + }*/ + + if (bWrite){ +// MyLog.showBytes("spiw",ac_data,0); + while (true){ + boolean res = isBusySpi(iAddress); + if (!res){ + break; + } + } + } + int iProtocalAddBytes = 8; + int iOffset = 0; + int len = 0; + + if (MyApp.getCardType() == CardType.P) { + if (iLength >= 2048) + len = 3072; + else if ((iLength >= 1024) && (iLength < 2048)) + len = 2048; + else if (iLength < 1024) + len = (int) (iLength + iProtocalAddBytes); + } else{ + len = 4096; + } + + byte[] dataBuffer = new byte[len];// new byte[iLength + iProtocalAddBytes];//[iLength + iProtocalAddBytes] + // ============================================================================================================================== + /*for (int i = 0; i < dataBuffer.length; i++) + dataBuffer[i] = 0;*/ + // e5 aa + dataBuffer[iOffset++] = (byte) ((bWrite) ? Variable.MOONCELL_FPGA_WRITE_FLAG : Variable.MOONCELL_FPGA_READ_FLAG); // 读写标志。 + dataBuffer[iOffset++] = (byte) (iAddress >> 16); // 地址。 + dataBuffer[iOffset++] = (byte) (iAddress >> 8); + dataBuffer[iOffset++] = (byte) (iAddress >> 0); + dataBuffer[iOffset++] = (byte) (iLength >> 8); // 长度。 + dataBuffer[iOffset++] = (byte) (iLength >> 0); + dataBuffer[iOffset++] = 0x00; // 空白。 + dataBuffer[iOffset++] = 0x00; // 空白。 + + if (bWrite) { //写操作,把用户传进来的写的正文内容,拷贝到spi数据包的正文段 + System.arraycopy(ac_data, 0, dataBuffer, iOffset, iLength); // 正文内容。 + } + iOffset += iLength; + + if (MyApp.getCardType() == CardType.P) { + if (iOffset >= 2056) { + iOffset = 3072; + } else if ((iOffset > 1024) && (iOffset < 2048)) { + iOffset = 2048; + } + } + +//add start by V42.1保存接收卡参数 + if (Variable.MOONCELL_FPGA_WRITE_FLAG == dataBuffer[0]){ + //符合以下几个地址才存储数据0XA70000,0XA70400,0XA72000,0xA80000,0xA8003C + if (0XA70000 == iAddress + || 0XA70400 == iAddress + || 0xA80000 == iAddress + || 0xA8003C == iAddress){ + //保存参数 + byte[] newData = new byte[dataBuffer.length]; + System.arraycopy(dataBuffer,1,newData,0,3); + System.arraycopy(dataBuffer,7,newData,3,dataBuffer.length-7); +// MyLog.showBytesHex(iAddress+"",dataBuffer,0); + Intent intent = new Intent("xixun.intent.action.ReceiveCardValue"); +// intent.putExtra(Define.PrintIntToHex((int) iAddress),newData); + intent.putExtra("values",newData); + MyApp.sendXixunAppBroadcast(intent); + } + } +// if (0x700000 == iAddress){ +// MyLog.showBytes("0x700000",dataBuffer,0); +// } + //add end +// MyLog.showBytes("sendData"+Define.PrintIntToHex((int) iAddress),dataBuffer,0); + if (!bWrite) {//读 +// MyLog.showBytes("readdata"+Define.PrintIntToHex((int) iAddress),dataBuffer,0); + } +// MyLog.showBytes("readdata",dataBuffer,0); + int res = spiDevice.Operator(dataBuffer, iOffset); + if (!bWrite) {//读 + System.arraycopy(dataBuffer, iProtocalAddBytes, ac_data, 0, iLength); +// if (0x700000 == iAddress){ +// MyLog.showBytes("readbuff:"+Define.PrintIntToHex((int) iAddress),dataBuffer,0); +// } + } +// MyLog.showBytes("resData"+Define.PrintIntToHex((int) iAddress),ac_data,0); + return ac_data; + } + + public int IOSPIRes(boolean bWrite, long iAddress, byte[] ac_data, long iLength) { + MyLog.d("IOSPIRes "+(bWrite ? "Write":"read")+",iAddress:"+Define.PrintIntToHex((int) iAddress)); + if (bWrite){ +// MyLog.showBytes("IOSPIRes",ac_data,0); + while (true){ + boolean res = isBusySpi((int) iAddress); + if (!res){ + break; + } + } + } + /*if (spiDevice==null){ + spiDevice = new SpiDevice(); + }*/ + int iProtocalAddBytes = 8; + int iOffset = 0; + int len = 0; + + if (MyApp.getCardType() == CardType.P) { + if (iLength >= 2048) + len = 3072; + else if ((iLength >= 1024) && (iLength < 2048)) + len = 2048; + else if (iLength < 1024) + len = (int) (iLength + iProtocalAddBytes); + } else{ + len = 4096; + } + + byte[] dataBuffer = new byte[len];// new byte[iLength + iProtocalAddBytes];//[iLength + iProtocalAddBytes] + // ============================================================================================================================== + /*for (int i = 0; i < dataBuffer.length; i++) + dataBuffer[i] = 0;*/ + // e5 aa + dataBuffer[iOffset++] = (byte) ((bWrite) ? Variable.MOONCELL_FPGA_WRITE_FLAG : Variable.MOONCELL_FPGA_READ_FLAG); // 读写标志。 + dataBuffer[iOffset++] = (byte) (iAddress >> 16); // 地址。 + dataBuffer[iOffset++] = (byte) (iAddress >> 8); + dataBuffer[iOffset++] = (byte) (iAddress >> 0); + dataBuffer[iOffset++] = (byte) (iLength >> 8); // 长度。 + dataBuffer[iOffset++] = (byte) (iLength >> 0); + dataBuffer[iOffset++] = 0x00; // 空白。 + dataBuffer[iOffset++] = 0x00; // 空白。 + + if (bWrite) { //写操作,把用户传进来的写的正文内容,拷贝到spi数据包的正文段 + System.arraycopy(ac_data, 0, dataBuffer, iOffset, (int) iLength); // 正文内容。 + } + iOffset += iLength; + + if (MyApp.getCardType() == CardType.P) { + if (iOffset >= 2056) { + iOffset = 3072; + } else if ((iOffset > 1024) && (iOffset < 2048)) { + iOffset = 2048; + } + } + //add start by V42.1保存接收卡参数 + if (Variable.MOONCELL_FPGA_WRITE_FLAG == dataBuffer[0]){ + //符合以下几个地址才存储数据0XA70000,0XA70400,0XA72000,0xA80000,0xA8003C + if (0XA70000 == iAddress + || 0XA70400 == iAddress + || 0xA80000 == iAddress + || 0xA8003C == iAddress){ + //保存参数 + byte[] newData = new byte[dataBuffer.length]; + System.arraycopy(dataBuffer,1,newData,0,3); + System.arraycopy(dataBuffer,7,newData,3,dataBuffer.length-7); +// MyLog.showBytesHex(iAddress+"",dataBuffer,0); + Intent intent = new Intent("xixun.intent.action.ReceiveCardValue"); +// intent.putExtra(Define.PrintIntToHex((int) iAddress),newData); + intent.putExtra("values",newData); + MyApp.sendXixunAppBroadcast(intent); + } + } +// if (0xA72034 == iAddress){ +// MyLog.showBytes("0xA72034",dataBuffer,0); +// } + //add end +// if (bWrite){ +// MyLog.showBytes("bWritedata",dataBuffer,0); +// } +// MyLog.showBytes("readdata",dataBuffer,0); + int res = spiDevice.Operator(dataBuffer, iOffset); + if (!bWrite) {//读 + System.arraycopy(dataBuffer, iProtocalAddBytes, ac_data, 0, (int)iLength); +// if (0x700000 == iAddress){ +// MyLog.showBytes("readbuff:"+Define.PrintIntToHex((int) iAddress),dataBuffer,0); +// } + } + return res; + } + + /** + * Flash读 + * @param iAddress + * @param iLength + * @return + */ + public byte[] flashRead(int iAddress, int iLength) { + byte[] readBuffer = new byte[iLength]; + try { + fpgaParamsFile.seek(iAddress); + fpgaParamsFile.read(readBuffer); + } catch (Exception e) { + e.printStackTrace(); + } +// MyLog.showBytes("flashRead "+iAddress,readBuffer,0); + return readBuffer; + } + + /** + * Flash写 + * @param iAddress + * @param iLength + * @return + */ + public byte[] flashWrite(byte[] writeData, int iAddress, int iLength) { + MyLog.i("flashWrite : iAddress=" + Define.PrintIntToHex((int) iAddress) + "; iLength=" + iLength); + try { + fpgaParamsFile.seek(iAddress); + fpgaParamsFile.write(writeData, 0, iLength); +// WriteAck(writeData); + } catch (Exception e) { + e.printStackTrace(); + } + return writeData; + } + + public void WriteAck(byte[] writeData) { + if (writeData == null) return; + int iLength = (writeData.length > Define.iDetectBytes) ? Define.iDetectBytes : writeData.length; + for (int i = 0; i < iLength; i++) + writeData[i] = (byte) Define.UCHAR_SPECTIAL_FLAG;// 发送应答标志,接收方会检测到缓存所有数据变化才认为收到应答。 +// TransData_Byte(NET_COMMU_TYPE.FPGA_MOONCELL.getValue(), (byte) 0, (byte) 0x01, writeData, iLength); + } + + public long get_gig_port_status(int mask){ + byte[] dat = new byte[64]; + long bit_status = 0; + char ac_addr_offset = 0; + int i_gig_count = MyApp.bytesToInt(MyApp.getSoNum(),true);//网口数量; + + IOSPIRes(false,0x710000,dat,dat.length); + for ( int i = 0 ; i < i_gig_count ; i ++ ) + { + if(i >= 8) + { + ac_addr_offset = 4; + } + if (0!=(mask & Vcxbase.PORT_IS_CONNECT)) + { + if (0!=(dat[(i*2) + 1 + ac_addr_offset] & (0x01 << 0))) + { + bit_status |= (1<> 24); // 亮度调节 +// MyLog.e("DataBuffer[0] >> 24 ="+DataBuffer[0]); + DataBuffer[iOffset++] = (byte) (iValue >> 16); +// MyLog.e("DataBuffer[1] >> 16 = "+DataBuffer[1]); + DataBuffer[iOffset++] = (byte) (iValue >> 8); +// MyLog.e("DataBuffer[2] >> 8 = "+DataBuffer[2]); + DataBuffer[iOffset++] = (byte) (iValue >> 0); +// MyLog.e("DataBuffer[3] >> 0 = "+DataBuffer[3]); + DataBuffer[iOffset++] = (byte) (0); // 亮度使能。 + DataBuffer[iOffset++] = (byte) (0); + DataBuffer[iOffset++] = (byte) (0); + DataBuffer[iOffset++] = (byte) (0xA5); + // A72000 +// MyLog.showBytes("setBrightness",DataBuffer,0); + int result = IOSPIRes(true, Variable.MOONCELL_FPGA_MIRROR_ADDRESS_PICTURE_CONTROL + Variable.MOONCELL_FPGA_MIRROR_ADDRESS_PICTURE_CONTROL_LIGHT_OFFSET,DataBuffer, iOffset); + return (result >= 0) ? true : false; + }catch (Exception e){ + e.printStackTrace(); + } + return false; + } + + int LightMidify(int iLightValue){ // 0~0x100. + if (iLightValue < 0) return -1; + if (iLightValue > 0x100) return -1; + iLightValue *= 2; // 0~0x200. //4// 十位。 +// MyLog.e("iLightValue20==="+(iLightValue << 20)); +// MyLog.e("iLightValue10==="+(iLightValue << 10)); +// MyLog.e("iLightValue0==="+(iLightValue)); + return (iLightValue << 20 | iLightValue << 10 | iLightValue);// RGB同样的颜色。 + } + + /** + * 获取亮度 + * @return + */ + public int getBrightness() { + try { + byte[] DataBuffer = new byte[8]; + int result = IOSPIRes(false, Variable.MOONCELL_FPGA_MIRROR_ADDRESS_PICTURE_CONTROL + Variable.MOONCELL_FPGA_MIRROR_ADDRESS_PICTURE_CONTROL_LIGHT_OFFSET, DataBuffer, DataBuffer.length); + int iValue = ((DataBuffer[0] & 0xFF) << 24) + ((DataBuffer[1] & 0xFF) << 16) + ((DataBuffer[2] & 0xFF) << 8) + ((DataBuffer[3] & 0xFF) << 0); + return LightMidifyOff(iValue); + }catch (Exception e){ + e.printStackTrace(); + } + return -1; + } + + public int LightMidifyOff(int iValue) // 0~0x100. + { + return (iValue >> 20 & iValue >> 10 & iValue) / 2;// RGB同样的颜色。 + } + + /** + * 通过读取数据检测数据是否正常 + * 并且发送给Cardsystem用于判断是否是mooncell程序 + */ + boolean bit_version; + public void readMooncellFpgaData() { + /*if (!CustomConfig.getInstance().is_xixun){ + byte[] fpgaData = new byte[32]; + int result =IOSPIRes(false, 0x700020,fpgaData, 32); + // MyLog.i("------------result = "+result+" cnt = "+cnt); + MyLog.showBytes("Read_Mooncell_Fpga_Version",fpgaData,0); + if (((fpgaData[4] == 0x54) && (fpgaData[5] == 0x41) && (fpgaData[6] == 0x32) && (fpgaData[7] == 0x30))||((fpgaData[4] == 0x56) && (fpgaData[5] == 0x33) && (fpgaData[6] == 0x30) && (fpgaData[7] == 0x00))) { + bit_version = true; + } else { + bit_version = false; + } + }else{ + bit_version = true; + }*/ + MyApp.executeThread(new Runnable() { + @Override + public void run() { + Send_Version_to_CardSystem(true); +// Send_to_CardSystem_Test(); + } + }); + /*if (CustomConfig.getInstance().fenghuo){ + MyApp.executeThread(new Runnable() { + @Override + public void run() { + checkApp(); + } + }); + }*/ + } + + public void Send_Version_to_CardSystem(boolean flag) { + MyLog.i("Send_Version_to_CardSystem11111111111111111111111"+flag); + JSONObject object = new JSONObject(); + try { + object.put("id", "display_brightness_success"); + object.put("_type", "IsHardwareMooncell"); +// object.put("mooncell", flag); + object.put("mooncell", true); + MyLog.i("executeJsonCommand..."); + CardServiceObj.executeJsonCommand(object.toString()); + }catch (Exception e) { + MyLog.i( "aidl disconnect!" ); + e.printStackTrace(); + } + MyLog.i(" -------FPGA version = "+flag); +// } + } + + public void Send_to_CardSystem_Test() { + JSONObject object = new JSONObject(); + try { + object.put("id", "98e8d3cd47fad6ce8e3f7b8d42cb4d9b"); + object.put("_type", "GetCardAlias"); + MyLog.i("Send_to_CardSystem_Test..."); + String res = CardServiceObj.executeJsonCommand(object.toString()); + MyLog.i( "res = "+res ); + }catch (Exception e) { + MyLog.i( "aidl disconnect!" ); + e.printStackTrace(); + } + } + + /** + * @MethodName: + * @Description: 获取接收卡数量 + * @author: Lay + * @date: 2020/12/7 15:52 + */ + public int getReceivedCardNumber(int iPortNumberIndex, int iReceCardType){ // type:0~F,各种接收卡类型,F通播。 + int iReceivedCardNumber = 0; + byte[] DataBuffer = new byte[64]; + if (ReceivedCard_Operator(true, false, iPortNumberIndex, + Variable.HUB_BOARDCAST_ADDRESS, Variable.RECEIVED_CARD_TYPE_BOARDCASE, Variable.RECEIVED_CARD_BOARDCAST_ADDRESS, + 0x35000CDD, DataBuffer, DataBuffer.length) == 0) { + MyLog.showBytes("DataBuffer2222222222",DataBuffer,0); + if (ReceivedCard_WaitAck(DataBuffer, DataBuffer.length) == 0) { + //Define.PrintBuffer("Read Rece Len",DataBuffer,DataBuffer.length); + iReceivedCardNumber = Define.hton_l(Define.GetIntFromByte(DataBuffer, iReceCardType * 4)); + } + } + MyLog.i("iReceivedCardNumber=" + iReceivedCardNumber); + + return iReceivedCardNumber; + } + int ReceivedCard_Operator(boolean bWrite, boolean bNeedWriteAck, int iPortID, int iHight16Address, int iCardType, int iCardID, int iDataAddress, byte[] Databuffer, int iLength) { + int iWorkResault = 0; + if (iLength > 0) + if (Databuffer == null) return -1; + + byte[] TransBuffer = new byte[Variable.MOONCELL_FPGA_REG_ADDRESS_BASIC_STEP]; //0x10000 = 65536 + + int iOffset = 0; + // Head: + { + TransBuffer[iOffset++] = (byte) 0x9A; + TransBuffer[iOffset++] = (byte) (bWrite ? ((bNeedWriteAck) ? 0xAD : 0x3D) : 0x0D); + Define.SetShortToByte(Define.htons((iLength / 4)), TransBuffer, iOffset); + iOffset += 2; + Define.SetIntToByte(Define.hton_l(vcx_io_address(iHight16Address, iCardType, iCardID & Variable.RECEIVED_CARD_BOARDCAST_ADDRESS)), TransBuffer, iOffset); // TA + iOffset += 4; // 0xFFF + Define.SetIntToByte(Define.hton_l(vcx_io_address(0xf0, 0, 0x55)), TransBuffer, iOffset); // SA + iOffset += 4; + Define.SetIntToByte(Define.hton_l(iDataAddress), TransBuffer, iOffset); // PIO iDataAddress = 0XD00DFC00 + iOffset += 4; + Define.SetShortToByte(0, TransBuffer, iOffset); // ANS + iOffset += 2; + CRC32 crc32 = new CRC32(); + crc32.update(TransBuffer, 0, iOffset); + Define.SetIntToByte(Define.hton_l((int) crc32.getValue()), TransBuffer, iOffset); + iOffset += 4; + } + // Text: + if (bWrite) { + System.arraycopy(Databuffer, 0, TransBuffer, iOffset, iLength); + iOffset += iLength; + // Check: + CRC32 crc32 = new CRC32(); + crc32.update(Databuffer, 0, iLength); + Define.SetIntToByte(Define.hton_l((int) crc32.getValue()), TransBuffer, iOffset); + iOffset += 4; + } + // Trans: + //modified by alahover 20190413 -start + //SpiOperator(true, PX_ADDR(iPortID), TransBuffer, iOffset); + // MyLog.i("-------fw 6"); + MyLog.i("PX_ADDR(iPortID)------------="+Define.PrintIntToHex((int) PX_ADDR(iPortID))); + IOSPIRes(true, PX_ADDR(iPortID), TransBuffer, iOffset); + //modified by alahover 20190413 -end + if (bWrite) { + if (bNeedWriteAck) { + if ((iCardID & Variable.RECEIVED_CARD_BOARDCAST_ADDRESS) < Variable.RECEIVED_CARD_BOARDCAST_ADDRESS) // 增加对HUB设备的判断. + { + if (ReceivedCard_WaitAck(Databuffer, iLength) == 0) + if (Databuffer[0] != 0) iWorkResault = 0; + } + } + } else { + iWorkResault = ReceivedCard_WaitAck(Databuffer, iLength); + } + return iWorkResault; + } + public int PX_ADDR(int n) { + return (n == Variable.PX_BROARDCAST) ? Variable.BROARDCAST_SEND_REG_ADDR : (Variable.MOONCELL_FPGA_REG_ADDRESS_BASIC_SEND + n * Variable.MOONCELL_FPGA_REG_ADDRESS_BASIC_STEP); + } + public int vcx_io_address(int ha, int type, int la) { + return make_long((type << 12) | la, ha); + } + + public int make_long(int a, int b) { + return (a & 0xffff) | (b << 16); + } + public int loword(long a) { + return (int)((a) & 0xffff); + } + public int hiword(long a) { + return (int)((a>>16) & 0xffff); + } + + public int ReceivedCard_WaitAck(byte[] Databuffer, int iLength) { + int iWorkResault = -1; + if (iLength > 0) + if (Databuffer == null) return iWorkResault; + CRC32 crc32 = new CRC32(); + int iTimes = 100; + do { + while (iTimes > 0) { + iTimes--; + try { + sleep(5); + } catch (InterruptedException e) { + e.printStackTrace(); + } + if (GetGiGData() == 0) + if (GiGData_DataBuffer[0] == 0x04) { + MyLog.i("Rece Data"); + break; + } + } + if (GiGData_DataBuffer[0] != 0x04) { + MyLog.i("No Data"); + break; + } + crc32.update(GiGData_DataBuffer, 16 + 2 + 22, iLength); + int iReceCrc32 = Define.hton_l(Define.GetIntFromByte(GiGData_DataBuffer, 16 + 2 + 22 + iLength)); + if (iReceCrc32 != (int) (crc32.getValue())) // 接收过来的CRC低16位数据为0。 + { + MyLog.i("Crc Error: iReceCrc32=" + Integer.toHexString(iReceCrc32).toUpperCase()); + MyLog.i("crc32.getValue()=" + Integer.toHexString((int) crc32.getValue()).toUpperCase()); + break; + } + System.arraycopy(GiGData_DataBuffer, 16 + 2 + 22, Databuffer, 0, iLength); + iWorkResault = 0; + } while (false); + return iWorkResault; + } + + public int GetGiGData() { + int iWorkResault = -1; + /*for (int i = 0; i < GiGData_DataBuffer.length; i++) + GiGData_DataBuffer[i] = (byte) 0; // 无数据返回空。*/ + GiGData_DataBuffer = new byte[GiGData_DataBuffer.length]; + byte bitStatus = getMultiPortHaveData(); +// MyLog.i("bitStatus==========="+bitStatus); + if (bitStatus != 0) { // 表示px port 接收一个VCS数据包ing + for (int i = 0; i < Variable.MOONCELL_FPGA_PORT_NUMBER; i++) { + if ((bitStatus & (1 << i)) != 0) { + byte[] DataBuffer = new byte[2048]; + MyLog.i("GetGiGData==========="+(Variable.MOONCELL_FPGA_REG_ADDRESS_BASIC_RECV + i * Variable.MOONCELL_FPGA_REG_ADDRESS_BASIC_STEP)); + if (IOSPIRes(false,(Variable.MOONCELL_FPGA_REG_ADDRESS_BASIC_RECV + i * Variable.MOONCELL_FPGA_REG_ADDRESS_BASIC_STEP),DataBuffer, DataBuffer.length) >= 0) { + int iAliableLength = (int) ((DataBuffer[DataBuffer.length - 2] & 0xff) << 8 | (DataBuffer[DataBuffer.length - 1] & 0xff)); + if (iAliableLength > 16 && iAliableLength <= 1460 && DataBuffer[0] == (byte) 0x55 && DataBuffer[1] == (byte) 0x55){ + synchronized (GiGData_DataBuffer) { + GiGData_DataBuffer[0] = 0x04; + GiGData_DataBuffer[1] = (byte) ((iAliableLength >> 8) & 0xff); + GiGData_DataBuffer[2] = (byte) ((iAliableLength >> 0) & 0xff); + GiGData_DataBuffer[3] = (byte) i; + System.arraycopy(DataBuffer, 0, GiGData_DataBuffer, 16, iAliableLength);//+4); // 4:For CRC Code. + } + iWorkResault = 0; + } + } + } + } + } + return iWorkResault; + } + public byte getMultiPortHaveData() { + byte bitStatus = 0; + byte gigNums = 8;// GetDisplayNetPortNum() ; // Px口状态标志 + byte[] DataBuffer = new byte[gigNums * 2]; // Bit2:Px口接收VCS数据包状态:0表示空闲,1表示接收到一个VCS数据包 +// MyLog.i("getMultiPortHaveData..............."); + if (IOSPIRes(false,Variable.MOONCELL_FPGA_REG_ADDRESS_MULTI_PORT_STATUS,DataBuffer, DataBuffer.length) >= 0) { + for (int i = 0; i < gigNums; i++) { + if ((DataBuffer[(i * 2) + 1] & (0x01 << 2)) != 0) + bitStatus |= (1 << i); + } + } + return bitStatus; + } + + + public boolean getFpgaBusy(){ + try { + int index= 0; + byte[] DataBuffer = new byte[13 + 6 + 1 + 4 + 100]; + GetVersion(true, (byte) 0x7c, DataBuffer, DataBuffer.length); + MyLog.showBytes("FpgaUpgrade_GetVersion",DataBuffer,0); + byte[] data = new byte[4]; + System.arraycopy(DataBuffer,0,data,0,data.length); + if (Arrays.equals(data, new byte[]{0x7e, 0x7e, 0x55,0x3A})){//表示是安陆芯片的数据 + index +=12; //忙状态 + int isBusy = DataBuffer[index]; + return isBusy==1; + } + }catch (Exception e){ + e.printStackTrace(); + } + return false; + } + + public boolean getDataCrc(){ + try { + int index= 0; + byte[] DataBuffer = new byte[13 + 6 + 1 + 4 + 100]; + GetVersion(true, (byte) 0x7c, DataBuffer, DataBuffer.length); + MyLog.showBytes("FpgaUpgrade_GetVersion",DataBuffer,0); + byte[] data = new byte[4]; + System.arraycopy(DataBuffer,0,data,0,data.length); + if (Arrays.equals(data, new byte[]{0x7e, 0x7e, 0x55,0x3A})){//表示是安陆芯片的数据 + index +=14; //检验和是否正确 + int isCrc = DataBuffer[index]; + return isCrc==1; + } + }catch (Exception e){ + e.printStackTrace(); + } + return false; + } + + /** + * 获取当前FPGA版本 + * + * @return + */ + public int getFpgaVersion() { + FpgaUpgrade_GetVersion(); // 第一次不正确。 + int iOldVersion = FpgaUpgrade_GetVersion(); + MyLog.i("mcl Version= " + Define.PrintIntToHex(iOldVersion)); + if (iOldVersion==0){ + byte[] xixunVersion = getFpgaVersion_xixun(); + iOldVersion = MyApp.bytesToInt(xixunVersion,true); + String ver = Define.PrintIntToHexNo0x(iOldVersion); + MyLog.i("xixun Version= " + ver); + } + return iOldVersion; + } + + public int FpgaUpgrade_GetVersion() { + int fpgaVersion = 0; + try { + int index= 0; + byte[] DataBuffer = new byte[13 + 6 + 1 + 4 + 100]; + GetVersion(true, (byte) 0x7c, DataBuffer, DataBuffer.length); +// MyLog.showBytes("FpgaUpgrade_GetVersion",DataBuffer,0); + byte[] data = new byte[4]; + System.arraycopy(DataBuffer,0,data,0,data.length); + if (Arrays.equals(data, new byte[]{0x7e, 0x7e, 0x55,0x3A})){//表示是安陆芯片的数据 + index +=12; //忙状态 +// int isBusy = DataBuffer[index]; + index +=2; //数据校验 + //获取fpgaVesion + index +=34; + System.arraycopy(DataBuffer, index, data, 0, data.length); + fpgaVersion = MyApp.bytesToInt(data, false); +// MyLog.i("fpgaVesion===="+fpgaVersion); + //获取FpgaType + index +=4; + System.arraycopy(DataBuffer, index, data, 0, data.length); + fpgaType = MyApp.bytesToInt(data, false); +// MyLog.i("fpgaType===="+fpgaType); + //获取PcbName + index +=4; + System.arraycopy(DataBuffer, index, data, 0, data.length); + pcbVersion = MyApp.bytesToInt(data, false); +// MyLog.i("pcbVersion===="+pcbVersion); + }else { + byte[] version = new byte[2]; + System.arraycopy(DataBuffer,16,version,0,version.length); + fpgaVersion = MyApp.bytesToInt(version,false); + } + }catch (Exception e){ + e.printStackTrace(); + } + MyLog.e("fpgaVersion========"+fpgaVersion); + return fpgaVersion; + } + + public int FpgaUpgrade_TransData_Byte(boolean bWrite, byte ucCommand, byte[] resDataBuffer, int iLength) { + int iProtocalReceAddBytes = 200; + int iProtocalAddBytes = 13; + int iOffset = 0; + byte[] dataBuffer = new byte[iLength + iProtocalAddBytes + iProtocalReceAddBytes]; + if (bWrite) { + dataBuffer[iOffset++] = STREAM_SYNC_HEAD; // 0x7E,同步头。 + dataBuffer[iOffset++] = STREAM_SYNC_HEAD; // 0x7E。 + dataBuffer[iOffset++] = Variable.STREAM_SYNC_HEAD2; // 0x55。 + dataBuffer[iOffset++] = ucCommand; + Define.SetIntToByte(0, dataBuffer, iOffset); // 保留字。 + iOffset += 4; + Define.SetIntToByte(iLength, dataBuffer, iOffset); // 正文长度。 + iOffset += 4; + if (resDataBuffer != null && iLength > 0) { + System.arraycopy(resDataBuffer, 0, dataBuffer, iOffset, iLength); // 正文内容。 + iOffset += iLength; + } + dataBuffer[iOffset] = Define.GetCheckCodeIn8(dataBuffer, 3, iOffset); // 校验码,累加和取反。 +// dataBuffer[iOffset] = (byte) 0x8d; + iOffset++; + } else iOffset = iLength; + // mask by feng 2019-11-6 + if (bFirst) { + spiDevice.Operator(dataBuffer, dataBuffer.length); // 第一次运行不正确。 + MyApp.sleepForMillisecond(10); + } + if (spiDevice.Operator(dataBuffer, dataBuffer.length) > 0) { + System.arraycopy(dataBuffer, iOffset, resDataBuffer, 0, Variable.FGPA_UPDATE_ADD_BYTES); + bFirst = false; + return 0; + } + return -1; + } + + public int GetVersion(boolean bWrite, byte ucCommand, byte[] resDataBuffer, int iLength) { + int iOffset = 0; + byte[] dataBuffer = new byte[iLength + 213]; + if (bWrite) { + dataBuffer[iOffset++] = STREAM_SYNC_HEAD; // 0x7E,同步头。 + dataBuffer[iOffset++] = STREAM_SYNC_HEAD; // 0x7E。 + dataBuffer[iOffset++] = Variable.STREAM_SYNC_HEAD2; // 0x55。 + dataBuffer[iOffset++] = ucCommand; + Define.SetIntToByte(0, dataBuffer, iOffset); // 保留字。 + iOffset += 4; + Define.SetIntToByte(iLength, dataBuffer, iOffset); // 正文长度。 + iOffset += 4; + if (resDataBuffer != null && iLength > 0) { + System.arraycopy(resDataBuffer, 0, dataBuffer, iOffset, iLength); // 正文内容。 + iOffset += iLength; + } +// dataBuffer[iOffset] = Define.GetCheckCodeIn8(dataBuffer, 3, iOffset); // 校验码,累加和取反。 + dataBuffer[iOffset] = (byte) 0x8d; + iOffset++; + } else iOffset = iLength; +// MyLog.showBytes("resDataBuffer",dataBuffer,0); + // mask by feng 2019-11-6 + if (bFirst) { + spiDevice.Operator(dataBuffer, dataBuffer.length); // 第一次运行不正确。 + MyApp.sleepForMillisecond(10); + } +// byte[] resdata = new byte[dataBuffer.length]; +// MyLog.showBytes("GetVersion",dataBuffer,0); + int res = spiDevice.Operator(dataBuffer, dataBuffer.length); +// int res = spiDevice.Trans(dataBuffer,resdata,dataBuffer.length); +// MyLog.showBytes("resdata",dataBuffer,0); +// MyLog.i("res====="+res); + if (res> 0) { + System.arraycopy(dataBuffer, iOffset, resDataBuffer, 0, Variable.FGPA_UPDATE_ADD_BYTES); + bFirst = false; + return 0; + } + return -1; + } + + public boolean FpgaUpgrade_EnterUpgradeMode() { + // return FpgaUpgrade_GetVersion(streamPort)==FGPA_UPDATE_EMPTY_VERSION; + // modified byfw 2019-4-18 -----start 修正了fpga升级问题 在m60上实现可用 + return FpgaUpgrade_GetVersion() == 0x101 || FpgaUpgrade_GetVersion() == 0x100; +// return FpgaUpgrade_GetVersion() == 256; + // modified byfw 2019-4-18 -----end + } + + public int getFpgaType(){ + int index= 0; + byte[] DataBuffer = new byte[137]; + GetVersion(true, (byte) 0x7c, DataBuffer, DataBuffer.length); + MyLog.showBytes("FpgaUpgrade_GetVersion",DataBuffer,0); + byte[] data = new byte[4]; + System.arraycopy(DataBuffer,0,data,0,data.length); + if (Arrays.equals(data, new byte[]{0x7e, 0x7e, 0x55,0x3A})){//表示是新的数据协议 + //获取FpgaType + index +=52; + System.arraycopy(DataBuffer, index, data, 0, data.length); + int fpgaType = MyApp.bytesToInt(data, false); + MyLog.i("fpgaType===="+fpgaType); + return fpgaType; + } + return -1; + } + + /** + * 升级fpga + * @param strFileName + */ + public boolean fpgaUpgrade(String strFileName){ + try { + String[] strFileNames = strFileName.split("/"); + String fpgaName = strFileNames[strFileNames.length-1]; +// String fpgaType = fpgaName.split("_")[1]; + if (Variable.FPGA_TYPE_ANLU==getFpgaType()){//ANLU芯片 + return fpgaUpgradeAnlu(fpgaName,strFileName); + }else if (Variable.FPGA_TYPE_LATTICS==getFpgaType()){//LATTICS芯片 + return false; + }else{//altera芯片 + return fpgaUpgradeAltera(strFileName); + } + }catch (Exception e){ + e.printStackTrace(); + return false; + } + } + + private boolean fpgaUpgradeAnlu(String fpgaName,String strFileName) { + MyLog.i("fpgaUpgradeAnlu......."); + String fpgaVerHex = Define.PrintIntToHex(getFpgaVersion()); + String fpgaVer = fpgaVerHex.substring(2); + MyLog.i("当前版本:"+fpgaVer+",要升级的版本:"+strFileName); + if (strFileName.contains(fpgaVer)){ + return false; + } + //组装进入升级模式协议数据 + byte[] upgradeModeData = getDataToUpgradeMode(fpgaName); + //发送进入升级模式协议 + boolean res = sendDataToUpgradeMode(upgradeModeData); + if (res){ + //发送数据 + sendFpgaDataAnlu(strFileName); + } + //查询版本协议 + int newFpgaVer = getFpgaVersion(); + String newFpgaVers = Define.PrintIntToHexNo0x(newFpgaVer); + return strFileName.contains(newFpgaVers); + } + + /** + * 发送fpga数据Anlu + */ + private void sendFpgaDataAnlu(String strFileName) { + try { + int iTransCounter = 0, iTransLength = 0, iPacketNum = 1; + RandomAccessFile fpgaUpgradeFile = new RandomAccessFile(strFileName, "r"); + //MyLog.i("FpgaUpgrade Step 001: Open success strFileName: "+strFileName); + int iOffset = 0; + byte[] DataBuffer = new byte[0x400]; + byte[] dataBuffer = new byte[DataBuffer.length + 0x0C + Variable.FGPA_UPDATE_ADD_BYTES]; + MyLog.i("Anlu FpgaUpgrade Step 03: Ready send data..."); + while (iTransCounter < fpgaUpgradeFile.length()) { + iOffset = 0; + MyLog.i("iTransCounter=========="+iTransCounter); + fpgaUpgradeFile.seek(iTransCounter); + //MyLog.i("FpgaUpgrade Step 032"); + if ((iTransLength = fpgaUpgradeFile.read(DataBuffer)) < 0) { + MyLog.i("FpgaUpgrade fail from read file offset at " + Define.PrintIntToHex(iTransCounter)); + return; + } + Define.SetIntToByte(0x0C, dataBuffer, iOffset); // 固定的命令识别符。 + iOffset += 4; + Define.SetIntToByte(0x00000000, dataBuffer, iOffset); // 板卡号,主卡为0。 + iOffset += 4; + Define.SetIntToByte(iTransCounter, dataBuffer, iOffset); // 包号。 + iOffset += 4; + System.arraycopy(DataBuffer, 0, dataBuffer, iOffset, iTransLength); // 正文内容。 + iOffset += iTransLength; + + FpgaUpgrade_TransData_Byte(true, NET_COMMU_TYPE.FGPA_UPDATE.getValue(), dataBuffer, iOffset); + //查询校验和是否正确 + boolean isCrc = getDataCrc(); + if (isCrc){ + iTransCounter += iTransLength; + iPacketNum++; + } + for (int i = 0; i < 50; i++) { + boolean isBusy = getFpgaBusy(); + if (isBusy){ + MyLog.i("busy..............."+i); + MyApp.sleepForMillisecond(20); + }else { + break; + } + } + } + MyLog.i("FpgaUpgrade Step 03: Send data ok."); + // 发送完毕命令。 + { + MyLog.i("FpgaUpgrade Step 04: Send finish command."); + iOffset = 0; + Define.SetIntToByte(0x00, dataBuffer, iOffset); // 固定的命令识别符。 + iOffset += 4; + Define.SetIntToByte(0x00000000, dataBuffer, iOffset); // 板卡号,主卡为0。 + iOffset += 4; + Define.SetIntToByte(0x08080000, dataBuffer, iOffset); // 包号。 + iOffset += 4; + FpgaUpgrade_TransData_Byte(true, NET_COMMU_TYPE.FGPA_UPDATE.getValue(), dataBuffer, iOffset); + //sleep(FGPA_UPDATE_PACKET_INTERVAL); + MyLog.i("FpgaUpgrade Step 04: Send finish ok."); + } + }catch (Exception e){ + e.printStackTrace(); + } + } + + /** + * 发送进入升级模式协议,返回是否可以升级 + * @param upgradeModeData + */ + private boolean sendDataToUpgradeMode(byte[] upgradeModeData) { + MyLog.showBytes("upgradeModeData",upgradeModeData,0); + spiDevice.Operator(upgradeModeData,upgradeModeData.length); + MyLog.showBytes("upgradeModeData",upgradeModeData,0); + byte[] revData = new byte[upgradeModeData.length/2]; + System.arraycopy(upgradeModeData,upgradeModeData.length/2,revData,0,revData.length); + //判断是否可以升级 + return isUpgrade(revData); + } + + private boolean isUpgrade(byte[] revData) { + byte[] data = new byte[4]; + System.arraycopy(revData,0,data,0,data.length); + if (Arrays.equals(data, new byte[]{0x7e, 0x7e, 0x55,0x5A})){ + //获取到FPGA返回的对比状态 + MyLog.showBytes("revData",revData,0); + boolean isOKFpgaVesion = (0x01 == revData[12]); + boolean isOKFpgaType = (0x01 == revData[16]); + boolean isOKpcbVesion = (0x01 == revData[20]); + if (isOKFpgaVesion && isOKFpgaType && isOKpcbVesion){ + MyLog.i("fpga version,type and pcb version are legal..."); + return true; + } else { + if (!isOKFpgaVesion){ + MyLog.i("fpga version don't match..."); + } + if (!isOKFpgaType){ + MyLog.i("fpga type don't match..."); + } + if (!isOKpcbVesion){ + MyLog.i("pcb version don't match..."); + } + MyApp.sleepForMillisecond(100); + } + }else { + MyLog.i("data head error..."); + } + return false; + } + + /** + * 组装使FPGA进入升级模式数据 + * @return + */ + private byte[] getDataToUpgradeMode(String fileName) { + byte[] msg = new byte[33+33]; + try { + String fpgaName = fileName.split("\\.")[0]; + MyLog.i("fileName========"+fpgaName); + byte[] fpgaType = new byte[4]; + String[] fileNames = fpgaName.split("_"); + String fpgaVerStr = fileNames[0].substring(1,5); + //Str类型的B103->Hex类型的 + int fpgaVerInt = Integer.parseInt(fpgaVerStr, 16); + if (fileNames.length>1){ + switch (fileNames[1]){ + case "altera": + fpgaType = new byte[]{0x00, 0x00, 0x00, 0x00}; + break; + case "anlu": + fpgaType = new byte[]{0x01, 0x00, 0x00, 0x00}; + break; + case "lattice": + fpgaType = new byte[]{0x02, 0x00, 0x00, 0x00}; + break; + default: + break; + } + //数据长度 + msg[8] = 0x14; + //默认数据 + byte[] defaultData = {0x7e, 0x7e, 0x55, 0x59}; + byte[] fpgaVer = MyApp.intToBytes(fpgaVerInt,4); + byte[] pcbVer = MyApp.intToBytes(Integer.parseInt(fileNames[2]),4); + System.arraycopy(defaultData, 0,msg, 0, defaultData.length); + System.arraycopy(fpgaVer, 0,msg, 12, fpgaVer.length); + System.arraycopy(fpgaType, 0,msg, 16, fpgaType.length); + System.arraycopy(pcbVer, 0,msg, 20, pcbVer.length); + msg[32] = (byte) 0x8D; + } + }catch (Exception e){ + e.printStackTrace(); + } + return msg; + } + + private boolean fpgaUpgradeAltera(String strFileName) { + try{ + String fpgaVerHex = Define.PrintIntToHex(getFpgaVersion()); + String fpgaVer = fpgaVerHex.substring(2); + MyLog.i("当前版本:"+fpgaVer+",要升级的版本:"+strFileName); + if (strFileName.contains(fpgaVer)){ + return false; + } + int iTryCounter = 0, iOldVersion = 0; + int iNewVersion = 0; + MyLog.i("FpgaUpgrade Step 00: strFileName: " + strFileName); + RandomAccessFile fpgaUpgradeFile = new RandomAccessFile(strFileName, "r"); + //MyLog.i("FpgaUpgrade Step 001: Open success strFileName: "+strFileName); + int iOffset = 0; + byte[] DataBuffer = new byte[0x400]; + byte[] dataBuffer = new byte[DataBuffer.length + 0x0C + Variable.FGPA_UPDATE_ADD_BYTES]; +// // 获取旧版本FPGA。 +// FpgaUpgrade_GetVersion(); // 第一次不正确。 +// iOldVersion = FpgaUpgrade_GetVersion(); +// MyLog.i("FpgaUpgrade_GetVersion Step 01: Ready..."+Define.PrintIntToHex(iOldVersion)); +// for (int cnt = 0; cnt < 10; cnt++) { +// sleep(100); +// iOldVersion = FpgaUpgrade_GetVersion(); +// if (iOldVersion != -1){ +// break; +// } +// } + MyLog.i("FpgaUpgrade Step 01: Old Fpga Version= " +fpgaVerHex); + // 开始命令。 + MyLog.i("FpgaUpgrade Step : Ready into update mode..."); + iTryCounter = 0; + while (true) { + iOffset = 0; + Define.SetIntToByte(0x0C, dataBuffer, iOffset); // 固定的命令识别符。 + iOffset += 4; + Define.SetIntToByte(0x00000000, dataBuffer, iOffset); // 板卡号,主卡为0。 + iOffset += 4; + Define.SetIntToByte(0x00080400, dataBuffer, iOffset); // 包号。 + iOffset += 4; + FpgaUpgrade_TransData_Byte(true, NET_COMMU_TYPE.FGPA_UPDATE.getValue(), dataBuffer, iOffset); + sleep(Variable.FGPA_UPDATE_PACKET_INTERVAL * 30); + if (FpgaUpgrade_EnterUpgradeMode()) { + break; + } + MyLog.i("跳转后 Fpga Version= " + Define.PrintIntToHex(getFpgaVersion())); + iTryCounter++; + if (iTryCounter > 10) { + MyLog.i("FpgaUpgrade fail from reset fpga into update mode."); + return false; + } + } + MyLog.i("FpgaUpgrade Step 02: Enter into update mode ok."); + + // 发送FPGA文件数据。 + int iTransCounter = 0, iTransLength = 0, iPacketNum = 1; + MyLog.i("FpgaUpgrade Step 03: Ready send data..."); + while (iTransCounter < fpgaUpgradeFile.length()) { + //MyLog.i("FpgaUpgrade Step 031: iPacketNum="+iPacketNum + " iTransCounter="+Define.PrintIntToHex(iTransCounter)); + fpgaUpgradeFile.seek(iTransCounter); + //MyLog.i("FpgaUpgrade Step 032"); + if ((iTransLength = fpgaUpgradeFile.read(DataBuffer)) < 0) { + MyLog.i("FpgaUpgrade fail from read file offset at " + Define.PrintIntToHex(iTransCounter)); + return false; + } + //MyLog.i("FpgaUpgrade Step 033"); + //Define.PrintBuffer("File",DataBuffer,48); + + iOffset = 0; + Define.SetIntToByte(0x0C, dataBuffer, iOffset); // 固定的命令识别符。 + iOffset += 4; + Define.SetIntToByte(0x00000000, dataBuffer, iOffset); // 板卡号,主卡为0。 + iOffset += 4; + Define.SetIntToByte(iTransCounter, dataBuffer, iOffset); // 包号。 + iOffset += 4; + System.arraycopy(DataBuffer, 0, dataBuffer, iOffset, iTransLength); // 正文内容。 + iOffset += iTransLength; + + FpgaUpgrade_TransData_Byte(true, NET_COMMU_TYPE.FGPA_UPDATE.getValue(), dataBuffer, iOffset); + + /*int iRetValue = FpgaUpgrade_GetIntData(dataBuffer, NET_COMMU_TYPE.FGPA_UPDATE_ACK, 4); // FPGA收完正确的数据。 + //MyLog.i("iRetValue =" + iRetValue); + if (iRetValue == 0x00000001) // 发送命令正确。 + {*/ + iTransCounter += iTransLength; + iPacketNum++; +// } + } + MyLog.i("FpgaUpgrade Step 03: Send data ok."); + // 发送完毕命令。 + { + MyLog.i("FpgaUpgrade Step 04: Send finish command."); + iOffset = 0; + Define.SetIntToByte(0x0C, dataBuffer, iOffset); // 固定的命令识别符。 + iOffset += 4; + Define.SetIntToByte(0x00000000, dataBuffer, iOffset); // 板卡号,主卡为0。 + iOffset += 4; + Define.SetIntToByte(0x00080000, dataBuffer, iOffset); // 包号。 + iOffset += 4; + FpgaUpgrade_TransData_Byte(true, NET_COMMU_TYPE.FGPA_UPDATE.getValue(), dataBuffer, iOffset); + //sleep(FGPA_UPDATE_PACKET_INTERVAL); + MyLog.i("FpgaUpgrade Step 04: Send finish ok."); + } + // 获取新版本FPGA。 + iTryCounter = 0; + while (true) { + sleep(300); + if (FpgaUpgrade_EnterUpgradeMode() == false) { + for (int cnt = 0; cnt < 10; cnt++) { + sleep(100); + iNewVersion = FpgaUpgrade_GetVersion(); + if (iNewVersion != -1) + break; + } + MyLog.i("FpgaUpgrade Step 05: iNewVersion=" + Integer.toHexString(iNewVersion)); + break; + } + iTryCounter++; + if (iTryCounter > 50) break; + } + }catch (Exception e){ + e.printStackTrace(); + } + return true; + } + + void FpgaInitial() { + try { + { + byte[] DataBuffer = new byte[Variable.MOONCELL_FPGA_MIRROR_ADDRESS_BASIC_STEP]; + for (int i = 0; i < Variable.MOONCELL_FPGA_PORT_NUMBER; i++) { // MOONCELL_FPGA_PORT_NUMBER = 8 + fpgaParamsFile.seek(Variable.MOONCELL_FPGA_FLASH_ADDRESS_GPORT_PARAMS + i * Variable.MOONCELL_FPGA_MIRROR_ADDRESS_BASIC_STEP); + if (fpgaParamsFile.read(DataBuffer) >= 0) { + // A70000 + 0X400 * i + flashWrite( DataBuffer, Variable.MOONCELL_FPGA_MIRROR_ADDRESS_BASIC + i * Variable.MOONCELL_FPGA_MIRROR_ADDRESS_BASIC_STEP, DataBuffer.length); // length = 1k + } else { + } + } + } + { + byte[] DataBuffer = new byte[256]; + fpgaParamsFile.seek(Variable.MOONCELL_FPGA_FLASH_ADDRESS_PICTURE_CONTROL); + if (fpgaParamsFile.read(DataBuffer) >= 0) { + int iRealLight = -1, iOffset = 0; + + //if (ledCardCommunication != null) + // iRealLight = ledCardCommunication.Get_Light(); + +// int iValue = LightMidify(ledCardCommunication.clientsManage.ms.workParams.iLightValue); // 获取到非法的亮度会设置为0,黑屏。 + int iValue = 255; + if (iValue > 0) { + iOffset = Variable.MOONCELL_FPGA_MIRROR_ADDRESS_PICTURE_CONTROL_LIGHT_OFFSET; + MyLog.i("初始化亮度............." + iValue); + DataBuffer[iOffset++] = (byte) (iValue >> 24); + DataBuffer[iOffset++] = (byte) (iValue >> 16); + DataBuffer[iOffset++] = (byte) (iValue >> 8); + DataBuffer[iOffset++] = (byte) (iValue >> 0); + DataBuffer[iOffset++] = (byte) 0; // 亮度使能。 + DataBuffer[iOffset++] = (byte) 0; + DataBuffer[iOffset++] = (byte) 0; + DataBuffer[iOffset++] = (byte) 0xA5; + } else { + iOffset = Variable.MOONCELL_FPGA_MIRROR_ADDRESS_PICTURE_CONTROL_LIGHT_ENABLE_OFFSET; // 0X38 + DataBuffer[iOffset++] = (byte) 0; // 亮度禁止。 + DataBuffer[iOffset++] = (byte) 0; + DataBuffer[iOffset++] = (byte) 0; + DataBuffer[iOffset++] = (byte) 0; + } + // A72000 + flashWrite(DataBuffer, Variable.MOONCELL_FPGA_MIRROR_ADDRESS_PICTURE_CONTROL, DataBuffer.length); + } else { + MyLog.i(Thread.currentThread().getStackTrace()[2].getFileName() + "-->" + + Thread.currentThread().getStackTrace()[2].getMethodName() + "()-->" + + "L" + Thread.currentThread().getStackTrace()[2].getLineNumber() + ":\r\n" + + " Error:" + "Can't Read data from fpgaParamsFile MOONCELL_FPGA_FLASH_ADDRESS_PICTURE_CONTROL @ 0x" + + Long.toHexString(Variable.MOONCELL_FPGA_FLASH_ADDRESS_PICTURE_CONTROL).toUpperCase() + + "\r\n\r\n" + ); + } + } + //if (false) + { + boolean bNeedSetPortNum = true; + byte[] DataBuffer = new byte[16]; + fpgaParamsFile.seek(Variable.MOONCELL_FPGA_FLASH_ADDRESS_GPORT_NUM_PARAMS); + if (fpgaParamsFile.read(DataBuffer) >= 0) { + if (DataBuffer[0] == (byte) 0xAA) + if (DataBuffer[1] == (byte) 0xAA) + if (DataBuffer[2] == (byte) 0xAA) + if (DataBuffer[3] == (byte) 0xAA) + if (DataBuffer[7] == (byte) 0x02) + if (DataBuffer[8] == (byte) 0x55) + if (DataBuffer[9] == (byte) 0x55) + if (DataBuffer[10] == (byte) 0x55) + if (DataBuffer[11] == (byte) 0x55) + bNeedSetPortNum = false; + + + } else { + MyLog.i(Thread.currentThread().getStackTrace()[2].getFileName() + "-->" + + Thread.currentThread().getStackTrace()[2].getMethodName() + "()-->" + + "L" + Thread.currentThread().getStackTrace()[2].getLineNumber() + ":\r\n" + + " Error:" + "Can't Read data from fpgaParamsFile MOONCELL_FPGA_FLASH_ADDRESS_GPORT_NUM_PARAMS @ 0x" + + Long.toHexString(Variable.MOONCELL_FPGA_FLASH_ADDRESS_GPORT_NUM_PARAMS).toUpperCase() + + "\r\n\r\n" + ); + } + if (bNeedSetPortNum) { + int iOffset = 0; + DataBuffer[iOffset++] = (byte) 0xAA; + DataBuffer[iOffset++] = (byte) 0xAA; + DataBuffer[iOffset++] = (byte) 0xAA; + DataBuffer[iOffset++] = (byte) 0xAA; + + DataBuffer[iOffset++] = (byte) 0x00; + DataBuffer[iOffset++] = (byte) 0x00; + DataBuffer[iOffset++] = (byte) 0x00; + DataBuffer[iOffset++] = (byte) 0x02; // 千兆网口端口数量. + + DataBuffer[iOffset++] = (byte) 0x55; + DataBuffer[iOffset++] = (byte) 0x55; + DataBuffer[iOffset++] = (byte) 0x55; + DataBuffer[iOffset++] = (byte) 0x55; + + fpgaParamsFile.seek(Variable.MOONCELL_FPGA_FLASH_ADDRESS_GPORT_NUM_PARAMS); + fpgaParamsFile.write(DataBuffer); + } + // + } + /* + */ + //MyLog.i(Thread.currentThread().getStackTrace()[2].getMethodName() + " L" + Thread.currentThread().getStackTrace()[2].getLineNumber() + " curAddr="); + //GigeInial(); + FpgaSystemConfig(); + } catch (Exception e) { + MyLog.i(Thread.currentThread().getStackTrace()[2].getFileName() + "-->" + + Thread.currentThread().getStackTrace()[2].getMethodName() + "()-->" + + "L" + Thread.currentThread().getStackTrace()[2].getLineNumber() + ":\r\n" + + " Error:" + e.getMessage() + "\r\n\r\n" + ); + } + } + void FpgaSystemConfig() { + int iOffset = 0; + byte[] DataBuffer = new byte[16 * 4]; + DataBuffer[3] = 0; + + iOffset = 4; + DataBuffer[iOffset++] = (byte) 0x6F; + DataBuffer[iOffset++] = (byte) 0x60; + DataBuffer[iOffset++] = (byte) 0x33; + DataBuffer[iOffset++] = (byte) 0x9A; + + iOffset = 63; + DataBuffer[iOffset++] = (byte) 0xA5; + + flashWrite(DataBuffer, Variable.MOONCELL_FPGA_MIRROR_ADDRESS_SYSTEM_CONFIG, DataBuffer.length); + } + + void VirtuleFpgaParamsFileInitial() { + if (Define.FileExist(strStoragePath + Define.MOONCELL_FPGA_PARAMS_FILE_NAME, Define.FLASH_SIZE)) + return; + byte[] dataBuffer = new byte[Define.FLASH_SIZE]; + for (int i = 0; i < dataBuffer.length; i++) dataBuffer[i] = (byte) 0; + synchronized (this) { + try { + fpgaParamsFile.seek(0); + fpgaParamsFile.write(dataBuffer); + } catch (Exception e) { + MyLog.i(Thread.currentThread().getStackTrace()[2].getFileName() + "-->" + + "Function: " + Thread.currentThread().getStackTrace()[2].getMethodName() + "-->" + + "Line" + Thread.currentThread().getStackTrace()[2].getLineNumber() + ":\r\n" + + " Error:" + e.getMessage() + "\r\n\r\n" + ); + } + } + } + + void VirtuleRegsFileInitial() { + if (Define.FileExist(strStoragePath + Define.MOONCELL_FPGA_REG_FILE_NAME, Variable.REG_SIZE)) return; + byte[] DataBuffer = new byte[Variable.REG_SIZE]; // REG_SIZE = 4k * 256 + for (int i = 0; i < DataBuffer.length; i++) DataBuffer[i] = (byte) 0; // DataBuffer 清 0 + { + int iOffset = 0; + DataBuffer[iOffset++] = (byte) 0x93; + DataBuffer[iOffset++] = (byte) 0x00; + DataBuffer[iOffset++] = (byte) 0x00; + DataBuffer[iOffset++] = (byte) 0x00; + + DataBuffer[iOffset++] = (byte) 0x00; + DataBuffer[iOffset++] = (byte) 0x18; + DataBuffer[iOffset++] = (byte) 0x04; + DataBuffer[iOffset++] = (byte) 0x21; + + for (; iOffset < 16; ) DataBuffer[iOffset++] = (byte) iOffset; + } + synchronized (this) { + try { + fpgaRegFile.seek(0); + fpgaRegFile.write(DataBuffer); + } catch (Exception e) { + MyLog.i(Thread.currentThread().getStackTrace()[2].getFileName() + "-->" + + "Function: " + Thread.currentThread().getStackTrace()[2].getMethodName() + "-->" + + "Line" + Thread.currentThread().getStackTrace()[2].getLineNumber() + ":\r\n" + + " Error:" + e.getMessage() + "\r\n\r\n" + ); + } + } + } + public void TransData_Byte(byte ucCommand, byte ucIdence, byte ucPipeId, byte[] DataBuffer, int iLength) { + try { + int iOffset = 0; + byte[] dataBuffer = new byte[iLength + 13]; + + dataBuffer[iOffset++] = STREAM_SYNC_HEAD; // 0x7E,同步头。 + dataBuffer[iOffset++] = STREAM_SYNC_HEAD; // 0x7E。 + dataBuffer[iOffset++] = Variable.STREAM_SYNC_HEAD2; // 0x55。 + dataBuffer[iOffset++] = ucCommand; + + dataBuffer[iOffset++] = ucIdence; // 分组号。 + dataBuffer[iOffset++] = ucPipeId; // 应答管道号。 + dataBuffer[iOffset++] = 0; // 保留字。 + dataBuffer[iOffset++] = 0; // 保留字。 + + Define.SetIntToByte(iLength, dataBuffer, iOffset); // 正文长度。 + iOffset += 4; + if (DataBuffer != null && iLength > 0) { + System.arraycopy(DataBuffer, 0, dataBuffer, iOffset, iLength); // 正文内容。 + iOffset += iLength; + } + dataBuffer[iOffset] = Define.GetCheckCodeIn8(dataBuffer, 3, iOffset); // 校验码,累加和取反。 +// iOffset++; + }catch (Exception e){ + e.printStackTrace(); + } + } + + public void fillDataToBackUpBuffer(byte[] data) { + backUpBuffer =new BackUpBuffer(); + try{ + byte[] dLen = {data[2],data[3]}; + int dataLen = MyApp.bytesToInt(dLen,false); + MyLog.i("dataLen:"+dataLen); + if (0!=dataLen && data.length>=48){ + byte[] headerbs = new byte[dataLen]; + byte[] newData = new byte[data.length-dataLen]; +// byte[] check = new byte[4]; + + //拷贝数据到BackUpBuffer --> InsHeader + System.arraycopy(data, 0,headerbs, 0, dataLen); +// MyLog.showBytes("headerbs===",headerbs,0); + backUpBuffer.setInsHeaderbs(headerbs); + //将headerbs数据赋值到header + backUpBuffer.headerbsToHeader(); + + //拷贝数据到BackUpBuffer --> data + System.arraycopy(data, dataLen,newData, 0, newData.length); + backUpBuffer.setData(newData); + } + }catch (Exception e){ + e.printStackTrace(); + } + } + + /** + * flash读:280000读取头数据中最大size的数据保存文件上传云端 + * flash写:往0x280000写云端所有数据,再调用巡检 + */ + /** + * 回读参数备份 + * @return + */ + public boolean backUpData(){ + //查询数据 + byte[] bs = flashRead(0x280000,256); + //填充数据 + fillDataToBackUpBuffer(bs); + //获取到最大size + if (backUpBuffer !=null){ + maxSize = MyApp.bytesToInt(backUpBuffer.getInsHeader().getVcm_cfg_dat_addr(),false) + +MyApp.bytesToInt(backUpBuffer.getInsHeader().getVcm_cfg_dat_size(),false); + MyLog.i("maxSize ===="+maxSize); + }else { + MyLog.i("backUpBuffer is null..."); + } + //读取所有数据 + byte[] allData = flashRead(0x280000,maxSize); +// MyLog.showBytes("allData",allData,0); + //写入数据到文件 + boolean res = writeData(allData); + return res; + } + + /** + * 恢复参数 + * @return + */ + public boolean restoreData(){ + //获取参数 + File mc_data = new File(strStoragePath+"/Sysolution/mc_data.config"); + //读取数据转成byte[] + byte[] data = readFileByte(mc_data,0); + //发送参数 + byte[] resData = flashWrite(data,0x280000,data.length); + if (resData.length==data.length){ + //开始巡检 + inspection(); + } + return true; + } + + + /** + *巡检 + */ + public void inspection(){ + byte[] bs = flashRead(0x280000,256); + sendData.parsingData(bs); + } + + public boolean writeData(byte[] data) { + String filePath = strStoragePath+"/Sysolution/"; + String fileName = "mc_data.config"; + try { + File file = makeFilePath(filePath,fileName); +// ShellUtils.execCommand("chmod -R 777 "+ file.getAbsolutePath(), true); + FileOutputStream fileOutputStream = new FileOutputStream(file); + fileOutputStream.write(data); + fileOutputStream.close(); + return true; + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return false; + } + + // 生成文件 + public File makeFilePath(String filePath, String fileName) { + File file = null; + makeRootDirectory(filePath); + try { + file = new File(filePath + fileName); + if (!file.exists()) { + file.createNewFile(); + } + } catch (Exception e) { + e.printStackTrace(); + } + return file; + } + + // 生成文件夹 + public static void makeRootDirectory(String filePath) { + File file = null; + try { + file = new File(filePath); + if (!file.exists()) { + file.mkdir(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public byte[] readFileByte(File file, int len) { + try { + if (file.exists()) { + FileInputStream fis = new FileInputStream(file); + byte[] content = new byte[(len <= 0)? fis.available(): len]; + fis.read(content); + fis.close(); + return content; + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + protected File getFpgaFileImpl(String prefix) { + File dest = null; + File kernel = new File(DiskType.KERNEL.getPath()); + if (kernel.exists() && kernel.isDirectory()) { + File[] files = kernel.listFiles(); + for (File file : files) { + if (!file.getName().endsWith("rpd")) { + continue ; + } + if (!file.getName().startsWith(prefix)) { + continue ; + } + if (null == dest) { + dest = file; + continue ; + } + if (file.lastModified() > dest.lastModified()) { + dest.delete(); + dest = file; + } else { + file.delete(); + } + } + } + return dest; + } + + /* 检查是否为第一次启动 若为第一次启动则,检查是否打开WIFI,检查是否客户定制等 */ + public boolean checkIsFirstStart() { + // 如果没有签名过, 说明是第一次启动 + return !new File("/data/joey/signed/card.id").exists(); + } + + public boolean checkApp(){ + MyLog.i("check app........."); + //检测是否安装播放器 + String playerName = "com.xixun.xixunplayer"; + String playerNameActivity = "com.xixun.xixunplayer.MainActivity"; + String playerNameActivity2 = "com.xixun.xixunplayer.MainActivity"; + if (isPackageInstalled(playerName)){ + /*if (isTopActivity(playerNameActivity,MyApp.getContext()) || isTopActivity(playerNameActivity2,MyApp.getContext())){ + MyLog.i(playerName+" 已启动..."); + return true; + }else { + MyLog.i(playerName+" 未启动..."); + }*/ + PackageManager packageManager = MyApp.getContext().getPackageManager(); + Intent it = packageManager.getLaunchIntentForPackage(playerName); + MyApp.getContext().startActivity(it); + }else { + MyLog.i(playerName+" 未安装..."); + } + return false; + } + + public static boolean isPackageInstalled(String packageName) { + if ((null == packageName) || packageName.equals("")) + return false; + try { + ApplicationInfo info = MyApp.getInstance().getPackageManager().getApplicationInfo(packageName, 0); + return info != null; + } catch (PackageManager.NameNotFoundException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } + + /** + * 查询8路继电器状态 + * @param port + * @param vcs + * @return + */ + public String getRelayState(int port, int vcs) { + SendData sendData = new SendData(); + byte[] read_buff = new byte[4]; + sendData.vcs_addr_init(0xff); + int len = 1; + sendData.vcs_dat_r(port,vcs,make_vcs_io_address(io_type_reg, 0x106),read_buff,len,Vcxbase.vcs_muti_card_type); + MyLog.showBytes("read_buff",read_buff,0); + int res = read_buff[2]; + StringBuilder stringBuilder = new StringBuilder(); + for (int i = 1; i <= 8; i++) { + int state = Utils.getByBit(res,i); + MyLog.e("state======="+state); + stringBuilder.append(i+"_"+state); + if (i != 8){ + stringBuilder.append(","); + } + } + MyLog.e(stringBuilder.toString()); + return stringBuilder.toString(); + } + + /** + * 设置8路继电器状态 + * @param port + * @param vcs + * @param state + * @return + */ + public boolean setRelayState(int port, int vcs,String state) { + SendData sendData = new SendData(); + byte[] write_buff = new byte[4]; + sendData.vcs_addr_init(0xff); + int len = 1; + String[] ss = state.split(",");//1_0,2_1... + String binary = ""; + for (int i = ss.length-1; i >=0; i--) { + String[] s = ss[i].split("_"); + binary += s[1]; + } + MyLog.e("binary===="+binary); + int commDec = Integer.valueOf(binary,2); + MyLog.e("commDec===="+commDec); + write_buff[0] = (byte) 0xA0; + write_buff[2] = (byte) commDec; + write_buff[3] = (byte) 0xff; + MyLog.showBytes("write_buff",write_buff,0);//00 00 8B 00 + byte[] flag = new byte[4]; + for (int i = 0; i < flag.length; i++) { + flag[i] = (byte) 0xA5; + } + sendData.vcs_dat_w(port,vcs,make_vcs_io_address(io_type_reg, 0xff),flag,len,Vcxbase.vcs_muti_card_type, DEF_PKT_INTERVAL_MS); + sendData.vcs_dat_w(port,vcs,make_vcs_io_address(io_type_reg, 0x0),write_buff,len,Vcxbase.vcs_muti_card_type, DEF_PKT_INTERVAL_MS); + return true; + } + + public void setRGB(int red,int green,int blue){ +// MyLog.e("setRGB=================="); + //T6 +// sendData.vcs_dat_w(Vcxbase.vcm_port_broadcast_address, +// Vcxbase.tcard_vcs_broadcast_address, +// Vcxbase.make_vcs_io_address(io_type_reg,0x161), +// _build_tcard_brightness_data(red*128,green*128,blue*128), +// 3, +// Vcxbase.vcs_t6_type, +// 0); + //fpga + sendData.vcs_dat_w(Vcxbase.vcm_port_broadcast_address, + Vcxbase.fcard_vcs_broadcast_address, + Vcxbase.make_vcs_io_address(io_type_reg,0), + _build_fpgacard_brightness_data(red/2,green/2,blue/2), + 1, + Vcxbase.vcs_fpga_type, + 0); + } + public byte[] _build_tcard_brightness_data(int r,int g,int b) + { + byte[] dat = new byte[12] ; +// memset(dat,0,sizeof(dat)); + + dat[0*4+2] = (byte) ((r >> 8) & 0xff); + dat[0*4+3] = (byte) ((r >> 0) & 0xff); + + dat[1*4+2] = (byte) ((g >> 8) & 0xff); + dat[1*4+3] = (byte) ((g >> 0) & 0xff); + + dat[2*4+2] = (byte) ((b >> 8) & 0xff); + dat[2*4+3] = (byte) ((b >> 0) & 0xff); + + return dat; + } + public byte[] _build_fpgacard_brightness_data(int r,int g,int b) + { + byte[] dat = new byte[4] ; + + dat[1] = (byte) b; + dat[2] = (byte) g; + dat[3] = (byte) r; + + MyLog.showBytes("rgb",dat,0); + return dat; + } + + /** + * 获取箱体大小 + */ + Map map_vcs_wh = new HashMap<>(); + Map map_vcs_offset = new HashMap<>(); + Map map_screen_size = new HashMap<>(); + public String getBoxSizeStr(){ + map_vcs_wh.clear(); + map_vcs_offset.clear(); + map_screen_size.clear(); + int min_x = 0xffff , min_y = 0xffff , max_x = 0 , max_y = 0; + byte[] read_buff = new byte[4]; + byte[] w = new byte[2]; + byte[] h = new byte[2]; + byte[] vcs_data = new byte[4]; + byte[] x = new byte[2]; + byte[] y = new byte[2]; + int port = DisplayConfig.getPort(); + MyLog.e("DisplayConfig getPort is..."+port); + long[] len = sendData.vcs_addr_init(port); + long count = len[Vcxbase.vcs_fpga_type];//获取接收卡数量 + MyLog.e("接收卡数量--------"+count); + for (int i = 0; i < count; i++) { + int cur_x, cur_y, cur_w ,cur_h; + sendData.vcs_dat_r(port, i, make_vcs_io_address(io_type_reg, 0x01), vcs_data, vcs_data.length / 4, Vcxbase.vcs_fpga_type);//获取当前接收卡偏移 + System.arraycopy(vcs_data,2,x,0,x.length); + System.arraycopy(vcs_data,0,y,0,x.length); + cur_x = MyApp.bytesToInt(x, true); + cur_y = MyApp.bytesToInt(y, true); + map_vcs_offset.put((long)make_long(0, i), (long)make_long(cur_x, cur_y)); + MyLog.e("当前接收卡偏移x---"+cur_x); // 16 0 + MyLog.e("当前接收卡偏移y---"+cur_x); //0 0 + sendData.vcs_dat_r(port, i, make_vcs_io_address(Vcxbase.io_type_srm, 0x08), read_buff, read_buff.length / 4, Vcxbase.vcs_fpga_type);//获取箱体大小 + MyLog.showBytes("getBoxSizeStr read_buff---------",read_buff,0); + System.arraycopy(read_buff,2,w,0,w.length); + System.arraycopy(read_buff,0,h,0,h.length); + cur_w = MyApp.bytesToInt(w, true); + cur_h = MyApp.bytesToInt(h, true); + MyLog.e("当前接收卡箱体大小宽度"+cur_w); //16 16 + MyLog.e("当前接收卡箱体大小高度"+cur_h);//8 8 + map_vcs_wh.put((long)make_long(0, i), (long)make_long(cur_w, cur_h)); + min_x = Math.min(cur_x,min_x); + min_y = Math.min(cur_y,min_y); + max_x = Math.max(cur_x+cur_w,max_x); + max_y = Math.max(cur_y+cur_h,max_y); + } + int screen_w = max_x ; + int screen_h = max_y ; + MyLog.e("箱体大小screen_w"+screen_w); + MyLog.e("箱体大小screen_h"+screen_h); + map_screen_size.put("screen_w",screen_w); + map_screen_size.put("screen_h",screen_h); + String boxSize = screen_w+"-"+screen_h; + //startPointCheck(); + //MyApp.sleepForMillisecond(10*1000); + //getPointCheckData(); + return boxSize; + } + /** + * 开启点检 + */ + + public void startPointCheck(){ + MyApp.executeThread(new Runnable() { + @Override + public void run() { + byte[] read_buff = new byte[4]; +// sendData.vcs_dat_r(DisplayConfig.getPort(),Vcxbase.fcard_vcs_broadcast_address,make_vcs_io_address(io_type_reg, 0x03),read_buff,read_buff.length/4,Vcxbase.vcs_fpga_type); +// MyLog.showBytes("read_buff---------",read_buff,0); + //寄存器写 + read_buff[2] = (byte) (read_buff[2]+0x01); + sendData.vcs_dat_w(DisplayConfig.getPort(),Vcxbase.fcard_vcs_broadcast_address,make_vcs_io_address(io_type_reg, 0x03),read_buff,read_buff.length/4,Vcxbase.vcs_fpga_type,Vcxbase.DEF_PKT_INTERVAL_MS); + MyApp.sleepForMillisecond(10*1000); + getPointCheckData(); + } + }); + + + } + + /** + * 获取点检数据 + * @return + */ + public ArrayList strList = new ArrayList<>(); // 创建一个 ArrayList 对象 + public void getPointCheckData(){ + fpgaDetect = new FpgaDetect(); + strList.clear(); + Integer screen_w = map_screen_size.get("screen_w"); + Integer screen_h = map_screen_size.get("screen_h"); + MyLog.e("screen_w---"+screen_w); + MyLog.e("screen_h---"+screen_h); + byte[] p_screen_pt_dat = new byte[screen_w*screen_h]; + long[] vcs_data = sendData.vcs_addr_init(DisplayConfig.getPort()); + long num = vcs_data[Vcxbase.vcs_fpga_type];//获取接收卡数量 + MyLog.e("当前接收卡数量---getPointCheckData---"+num); + for (int vcs = 0; vcs < num; vcs++) { + int curx = loword(map_vcs_offset.get((long)make_long(0, (int) vcs))); + int cury = hiword(map_vcs_offset.get((long)make_long(0,(int)vcs))); + int curw = loword(map_vcs_wh.get((long)make_long(0,(int)vcs))); + int curh = hiword(map_vcs_wh.get((long)make_long(0,(int)vcs))); + int ptsize = curw * curh; + byte[] box_pt_dat = new byte[curw*curh]; + fpgaDetect.checkRecvCardBadPoint(DisplayConfig.getPort(), vcs,vcs, curw, curh, box_pt_dat); + for (long idx = 0;idx < ptsize;idx++) { + long box_x = idx % curw ; + long box_y = idx / curw ; + long screen_idx = (box_x + curx) + (box_y + cury) * screen_w; + p_screen_pt_dat[(int)screen_idx] = box_pt_dat[(int)idx]; + if (box_pt_dat[(int)idx] != 0) + { + MyLog.e("bad point ---"+vcs); + } + } + //MyLog.showBytes("bad point bytes is...",box_pt_dat,0); + } + int bad_point_cnt = 0; + for (int screen_x = 0 ;screen_x < screen_w;screen_x ++) + { + for (int screen_y = 0 ;screen_y < screen_h;screen_y ++) + { + int screen_idx = screen_x + (screen_y * screen_w) ; + + if (p_screen_pt_dat[screen_idx] != 0) { + bad_point_cnt ++ ; + MyLog.e("bad x point ---"+screen_x); + MyLog.e("bad y point ---"+screen_y); + String str=(screen_x+1)+"-"+(screen_y+1); + strList.add(str); + + } + } + } + MyLog.e("bad point number: ---"+bad_point_cnt); + //return strList; + } + public List returnBadPointData(){ + return strList; + } + + int index_lenth = 6;//长度位置 + int index_main = 8;//正文位置 + byte cmd_xixun = 0; + /** + * 从上位机接收数据 + * @param data + */ + public void receDataFromPC_Xixun(byte[] data, DataOutputStream sendStream){ + try{ +// MyLog.showBytes("data"+data.length,data,0); + byte protocolType = data[3];//协议类型 + cmd_xixun = data[4];//命令码 01-7F为安卓处理的数据,0xFF为fpga数据,正文段需转发到fpga + if (0x01 == protocolType || 0x02 == protocolType) {//处理智能设置数据 + //获取长度 + byte[] len = {data[6],data[7]}; + int dataLen = MyApp.bytesToInt(len,false); + //获取正文段数据 + byte[] mainData = new byte[dataLen]; + System.arraycopy(data,8,mainData,0,dataLen); + switch (cmd_xixun) { + case 0x01://智能设置 + smartSetting(mainData); + break; + case 0x02://获取版本 + byte[] version = getAllVersion(); + sendDataToPC_Xixun(version,sendStream); + break; + case (byte) 0xFF://转发到fpga + byte[] resData = sendToFpga(mainData); + if (resData!=null){ + byte[] sendDataToPC = fillData_Xixun(resData); + sendDataToPC_Xixun(sendDataToPC,sendStream); + } + break; + default: + break; + } +// if(0x01 == protocolType && (byte)0xFF == cmd_xixun && data.length>60){//保存数据,初始化时加载 +// //获取地址作为key data[57],data[58],data[59],data[60] +// boolean isSame = (data[57]==data[60]); +// if (isSame){ +// String key = MyLog.intToHexNo0x(data[57]); +// key = key+key+key+key; +// MyLog.e("key========"+key); +// keyValues.put(key,data); +// write_xixun(keyValues); +// } +// } + } + }catch (Exception e){ + e.printStackTrace(); + } + } + + /** + * 智能设置画面 + */ + private void smartSetting(byte[] mainData){ + byte pattern = mainData[0]; + //获取窗口 + PageParams params = new PageParams(); + switch (pattern){ + case 0: + MyLog.e("简单红绿蓝"); + //简单红绿蓝,窗口直接显示 + params.setPage(PageUI.SHOW_BLOCK); + break; + case 1: + MyLog.e("画矩形"); + //画矩形 + params.setPage(PageUI.SHOW_RECTANGLE); + //获取矩形总数量 + int rectangleNum = mainData[12]; + //获取矩形背景颜色 + int rectangleColor = Color.argb(0xFF,mainData[13]&0xff,mainData[14]&0xff,mainData[15]&0xff); + Rectangles rectangles = new Rectangles(rectangleNum,rectangleColor); + //获取矩形的数据域 + byte[] rectangleData = new byte[rectangleNum*8];//一个矩形8个字节的属性 + System.arraycopy(mainData,16,rectangleData,0,rectangleData.length); + //遍历循环获取每个矩形 + for (int i = 0; i < rectangleNum; i++) { + //获取每个矩形参数 + byte[] temp = new byte[2]; + System.arraycopy(rectangleData,i*8,temp,0,temp.length); //sx + int rectangleSX = MyApp.bytesToInt(temp,false); + System.arraycopy(rectangleData,(i*8)+2,temp,0,temp.length); //sy + int rectangleSY = MyApp.bytesToInt(temp,false); + System.arraycopy(rectangleData,(i*8)+4,temp,0,temp.length); //width + int rectangleWidth = MyApp.bytesToInt(temp,false); + System.arraycopy(rectangleData,(i*8)+6,temp,0,temp.length); //height + int rectangleHeight = MyApp.bytesToInt(temp,false); + Rectangle rectangle = new Rectangle(rectangleSX,rectangleSY,rectangleWidth,rectangleHeight); + rectangles.getRectangleList().add(rectangle); + } + params.setRectangles(rectangles); + break; + case 2: + MyLog.e("画线"); + //画线 + params.setPage(PageUI.SHOW_LINE); + //获取直线总数量 + int lineNum = mainData[12]; + //获取直线颜色 + int lineColor = Color.argb(0xFF,mainData[13]&0xff,mainData[14]&0xff,mainData[15]&0xff); + //获取直线宽度 + int lineWidth = mainData[16]; + Lines lines = new Lines(lineNum,lineColor,lineWidth); + //获取直线的数据域 + byte[] lineData = new byte[lineNum*8];//一根直线8个字节的属性 + System.arraycopy(mainData,17,lineData,0,lineData.length); + //遍历循环获取每个直线 + for (int i = 0; i < lineNum; i++) { + //获取每个直线参数 + byte[] temp = new byte[2]; + System.arraycopy(lineData,i*8,temp,0,temp.length); //lineSX + int lineSX = MyApp.bytesToInt(temp,false); + System.arraycopy(lineData,(i*8)+2,temp,0,temp.length); //lineSY + int lineSY = MyApp.bytesToInt(temp,false); + System.arraycopy(lineData,(i*8)+4,temp,0,temp.length); //lineEX + int lineEX = MyApp.bytesToInt(temp,false); + System.arraycopy(lineData,(i*8)+6,temp,0,temp.length); //lineEY + int lineEY = MyApp.bytesToInt(temp,false); + Line line = new Line(lineSX,lineSY,lineEX,lineEY); + lines.getLineList().add(line); + } + params.setLines(lines); + break; + case 3: + params.setPage(PageUI.SHOW_NOTHING); + break; + default: + MyLog.e("异常pattern类型"); + break; + } + params = getInitParams(mainData,params); +// MyLog.e(params.toString()); + TopWindow.getInstance().changePage(params); + } + /** + * 获取窗口params + */ + private PageParams getInitParams(byte[] patternData,PageParams params){ + if (PageUI.SHOW_NOTHING != params.getPage()){ + //获取起点 + byte[] startx = {patternData[1],patternData[2]}; + int startX = MyApp.bytesToInt(startx,false); + byte[] starty = {patternData[3],patternData[4]}; + int startY = MyApp.bytesToInt(starty,false); + Point start = new Point(startX,startY); + //获取宽高 + byte[] w = {patternData[5],patternData[6]}; + int W = MyApp.bytesToInt(w,false); + byte[] h = {patternData[7],patternData[8]}; + int H = MyApp.bytesToInt(h,false); + MyApp.setMaxSize(W,H); + Point end = new Point(startX+W,startY+H); + //获取颜色 + int color = Color.argb(0xFF,patternData[9]&0xff,patternData[10]&0xff,patternData[11]&0xff); + params.setStart(start); + params.setEnd(end); + params.setColor(color); + } + return params; + } + + /** + * 获取版本信息 + * */ + private byte[] getAllVersion(){ + //获取APP版本 + int appCode = 0; + try { + PackageManager manager = MyApp.getContext().getPackageManager(); + PackageInfo info = manager.getPackageInfo(MyApp.getContext().getPackageName(), 0); + appCode = info.versionCode; + MyLog.e("appCode="+appCode); + } catch (PackageManager.NameNotFoundException e) { + e.printStackTrace(); + } + byte[] appCodeD = MyApp.intToBytesH_L(appCode,2); + //获取FPGA版本 + byte[] fpgaVersion = getFpgaVersion_xixun(); + int fpgaVersionInt = MyApp.bytesToInt(fpgaVersion,true); + MyLog.e("fpgaVersionInt="+fpgaVersionInt); + String strFpgaVersion = MyLog.getIntToHex(fpgaVersionInt); + MyLog.showBytes("fpgaVersion = "+strFpgaVersion,fpgaVersion,0); + if (strFpgaVersion.contains("A042")){ + //初始化参数 +// flashRead() + } + //组装数据返回 + byte[] mainData = new byte[appCodeD.length+fpgaVersion.length]; + System.arraycopy(appCodeD,0,mainData,0,appCodeD.length);//appcode + System.arraycopy(fpgaVersion,0,mainData,appCodeD.length,fpgaVersion.length);//fpgaversion + byte[] versionData = fillData_Xixun(mainData); + return versionData; + } +//AA 70 00 00 00 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 + private byte[] getFpgaVersion_xixun(){ + byte[] getFpgaVersion = new byte[72]; + getFpgaVersion[0] = (byte) 0xAA; + getFpgaVersion[1] = 0x70; + getFpgaVersion[5] = 0x40; + byte[] resFpgaVersion = sendToFpga(getFpgaVersion); + + byte[] fpgaVersion = new byte[4]; + fpgaVersion[0] = resFpgaVersion[32]; + fpgaVersion[1] = resFpgaVersion[33]; + fpgaVersion[2] = resFpgaVersion[34]; + fpgaVersion[3] = resFpgaVersion[35]; + return fpgaVersion; + } + /** + * 发送数据到FPGA + * */ + private byte[] sendToFpga(byte[] mainData){ + boolean isWrite_xixun = (mainData[0] == (byte)0xe5); + boolean isRead_xixun = (mainData[0] == (byte)0xAA); + byte[] addrs = new byte[3]; + System.arraycopy(mainData,1,addrs,0,addrs.length); + int addr = MyApp.bytesToInt(addrs,true); +// MyLog.showBytes("sendToFpga:"+isWrite_xixun + " iAddress:"+Define.PrintIntToHex((int) addr)+" data:",mainData,0); + MyLog.e("addr:"+Define.PrintIntToHex((int) addr)); + if (isWrite_xixun && addr==0xA72000){ + flashWrite(mainData,0xA72000,mainData.length); + //处理,去除网口数量,P口宽高数据再下发 + mainData = removeByte(mainData); + MyLog.showBytes("1111111mainData",mainData,0); + }else if(isRead_xixun && addr==0xA72000){ + byte[] flashReadData = flashRead(0xA72000,256); + return flashReadData; + } + MyLog.showBytes("sendToFpga:"+isWrite_xixun + " iAddress:"+Define.PrintIntToHex((int) addr)+" data:",mainData,0); + spiDevice.Operator(mainData,mainData.length); + byte[] newMainData = new byte[mainData.length-8]; + System.arraycopy(mainData,8,newMainData,0,newMainData.length); + if (isWrite_xixun){ +// flashWrite(mainData,addr,mainData.length); +// byte[] ac_dat = flashRead(addr ,88); +// MyLog.showBytes("flash读:"+Define.PrintIntToHex((int) addr),ac_dat,0); + }else{ +// MyLog.showBytes("resToFpga",newMainData,0); + return newMainData; + } + return null; + } + /* + * int addr = MyApp.bytesToInt(structNetBuffer.getHeader().getAddr_dat(),true); + int len = MyApp.bytesToInt(structNetBuffer.getHeader().getLen(),true); + byte[] data = structNetBuffer.getData(); + MyLog.showBytes("flashWriteControl",data,0); + byte[] resBuffer = flashWrite(data,addr,len);*/ + +byte[] removeByte(byte[] mainData){ + //网口数量 + int portNum = mainData[20]; + int newDataLength = mainData.length-(portNum*4+1); + byte[] newData = new byte[newDataLength]; + //复制头0-19 + System.arraycopy(mainData,0,newData,0,20); + //复制P口数据 + for (int i= 0;i keyValues) { + Gson gson = new Gson(); + try { + FileWriter fileWriter = new FileWriter(xixun_config_path,false); + gson.toJson(keyValues, fileWriter); + fileWriter.flush(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void read_xixun() { + Gson gson = new Gson(); + Map read_data = new LinkedHashMap<>(); + Type type = new TypeToken>(){}.getType(); + try { + FileReader reader = new FileReader(xixun_config_path); + read_data = gson.fromJson(reader, type); + if (read_data!=null){ + for (Map.Entry entry : read_data.entrySet()) { + MyLog.showBytes(entry.getKey(),entry.getValue(),0); + receDataFromPC_Xixun(entry.getValue(),null); + } + } + } catch (IOException e) { + e.printStackTrace(); + }catch (JsonSyntaxException js){ + js.printStackTrace(); + } + } + + public void initXixunConfig(){ + int res = spiDevice.Operator(OtherData.a70000,OtherData.a70000.length); + MyLog.e("res ==== "+res); + res = spiDevice.Operator(OtherData.a70400,OtherData.a70400.length); + MyLog.e("res ==== "+res); + res = spiDevice.Operator(OtherData.a80000,OtherData.a80000.length); + MyLog.e("res ==== "+res); + res = spiDevice.Operator(OtherData.a8003c,OtherData.a8003c.length); + MyLog.e("res ==== "+res); +// read_xixun(); + byte[] flashReadData = flashRead(0xA72000,256); + flashReadData = removeByte(flashReadData); + MyLog.showBytes("flashReadData:",flashReadData,0); + res = spiDevice.Operator(flashReadData,flashReadData.length); + MyLog.e("res ==== "+res); + } + + + /** + * 获取接收卡传感器参数 + */ + public RecCardInfo getRecData(){ + byte[] bytes = new byte[48]; + sendData.vcs_dat_r(0, Vcxbase.fcard_vcs_broadcast_address, make_vcs_io_address(io_type_srm, 0x3B420), bytes, bytes.length / 4, Vcxbase.vcs_fpga_type); + byte[] header = new byte[4]; + byte[] temperature = new byte[3]; + byte[] voltage = new byte[3]; + byte[] humidity = new byte[3]; + byte[] light = new byte[3]; + byte[] smoke = new byte[3]; + byte[] power = new byte[3]; + byte[] reg = new byte[3]; + System.arraycopy(bytes,0,header,0,header.length); + if(!(header[0]==0xC1 && header[1]==0xC3 && header[2]==0xC5 && header[3]==0xC7)){ + //MyLog.e("传感器数据获取失败..."); + } + System.arraycopy(bytes,header.length+5,temperature,0,temperature.length); + System.arraycopy(bytes,header.length+temperature.length+6,voltage,0,voltage.length); + System.arraycopy(bytes,header.length+temperature.length+6+4,humidity,0,humidity.length); + System.arraycopy(bytes,header.length+temperature.length+6+4+4,light,0,light.length); + System.arraycopy(bytes,header.length+temperature.length+6+4+4+4,smoke,0,smoke.length); + System.arraycopy(bytes,header.length+temperature.length+6+4+4+4+4,power,0,power.length); + System.arraycopy(bytes,41,reg,0,reg.length); + + MyLog.showBytes("header",header,0); + MyLog.showBytes("temperature",temperature,0); + MyLog.showBytes("voltage",voltage,0); + MyLog.showBytes("humidity",humidity,0); + MyLog.showBytes("light",light,0); + MyLog.showBytes("smoke...",smoke,0); + MyLog.showBytes("power...",power,0); + MyLog.showBytes("reg...",reg,0); + MyLog.showBytes("bytes...",bytes,0); + int i = MyApp.bytesToInt(temperature, true); + int v = MyApp.bytesToInt(voltage, true); + float temp= (i-27315)/100; + double vol =0; + BigDecimal versionRate = BigDecimal.valueOf((double) v / 100); + //保留两位小数 + vol = versionRate.setScale(2, RoundingMode.HALF_UP).doubleValue(); + int hum = MyApp.bytesToInt(humidity, true); + MyLog.i("温度...."+temp); + MyLog.i("电压...."+vol); + MyLog.i("湿度...."+hum); + MyLog.i("光照...."+MyApp.bytesToInt(light, true)); + MyLog.i("烟雾...."+MyApp.bytesToInt(smoke, true)); + String bitString = MyApp.byteToBitString(power[2]); + String[] strings = bitString.split(","); + String isHigh1 = strings[strings.length-1]; + String isHigh2 = strings[strings.length-2]; + String isHigh3 = strings[strings.length-3]; + String isHigh4 = strings[strings.length-4]; + String isHigh5 = strings[strings.length-5]; + String isHigh6 = strings[strings.length-6]; +// MyLog.e("isHigh1...."+isHigh1+"...isHigh2...."+isHigh2+"...isHigh3..."+isHigh3+"...isHigh4..."+isHigh4+"...isHigh5..."+isHigh5+"...isHigh6..."+isHigh6); + RecCardInfo recCardInfo = new RecCardInfo(); + recCardInfo.setTemperature(temp); + recCardInfo.setVoltage(vol); + recCardInfo.setHumidity(hum); + recCardInfo.setLight(MyApp.bytesToInt(light, true)); + recCardInfo.setSmoke(MyApp.bytesToInt(smoke, true)); + recCardInfo.setIsHigh1(isHigh1); + recCardInfo.setIsHigh2(isHigh2); + recCardInfo.setIsHigh3(isHigh3); + recCardInfo.setIsHigh4(isHigh4); + recCardInfo.setIsHigh5(isHigh5); + recCardInfo.setIsHigh6(isHigh6); + recCardInfo.setSwitchState(reg[2]); + return recCardInfo; + } + /** + * 控制接收卡继电器开关 + * @param isSwitch + */ + + public void setRecCardRelaySwitch(boolean isSwitch){ + byte[] buffer = new byte[48]; + if(isSwitch){ + buffer[43] = (byte) 0xA5; + MyLog.i("打开继电器..."); + }else { + buffer[43] = (byte) 0x00; + MyLog.i("关闭继电器..."); + } + sendData.vcs_dat_w(0,Vcxbase.fcard_vcs_broadcast_address,make_vcs_io_address(io_type_srm, 0x3B420),buffer,buffer.length/4,Vcxbase.vcs_fpga_type,DEF_PKT_INTERVAL_MS); + } + +} + + + diff --git a/app/src/main/java/com/xixun/display/controller/CardBroadcast.java b/app/src/main/java/com/xixun/display/controller/CardBroadcast.java new file mode 100644 index 0000000..5992b2c --- /dev/null +++ b/app/src/main/java/com/xixun/display/controller/CardBroadcast.java @@ -0,0 +1,80 @@ +package com.xixun.display.controller; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; + +import com.xixun.display.MyApp; +import com.xixun.display.MyLog; + +import java.io.File; + +public class CardBroadcast { + private Context context; + public CardBroadcast() { + context = MyApp.getContext(); + } + + public void taskRegister() { + registerNormal(); + } + + private void registerNormal(){ + IntentFilter filter = new IntentFilter(); + filter.addAction("xixun.intent.action.REBOOT"); + filter.addAction("com.xixun.pixel.detect"); + filter.addAction("xixun.intent.action.UPGRADE_FPGA"); +// filter.addAction("xixun.intent.action.ALARM_REPORT"); + BroadcastReceiver receiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + try { + String action = intent.getAction(); + if (action.equals("com.xixun.pixel.detect")) { + /*if (XixunController.get().clientsManage != null && XixunController.get().clientsManage.ledCardCommunication != null && XixunController.get().clientsManage.ledCardCommunication.mooncellFpga != null) { + String data = XixunController.get().clientsManage.ledCardCommunication.mooncellFpga.check_bad_led(); + Intent intent_fw = new Intent("com.xixun.pixel.detect.answer"); + intent_fw.putExtra("data", data); + context.sendBroadcast(intent_fw); + }*/ + }else if (action.equals("xixun.intent.action.REBOOT")) { + + }else if (action.equals("xixun.intent.action.UPGRADE_FPGA")) { + // String path = intent.getStringExtra("path"); + String path = "/data/joey/kernel"; + MyLog.i("Fpga upgade path ==> " + path); +// for (String pathname : new File(path).list()) { + File mainRpd = MyApp.card().getFpgaFile(true); + String pathname = mainRpd.getAbsolutePath(); + if (pathname.endsWith(".rpd")) { + final String strFileNameAndPath =pathname; + MyLog.i("Fpga update file: "+strFileNameAndPath); + try { + MyApp.executeThread(new Runnable() { + @Override + public void run() { + boolean res = MyApp.card().fpgaUpgrade(strFileNameAndPath); + if (res){ + MyApp.sleepForSecond(3); + MyApp.card().init(); + } + } + }); + } catch (Exception e) { + MyLog.i("fpga Upgrade Exception"+e.toString()); + } + } + +// } + }else{ + + } + }catch(Exception e){ + e.printStackTrace(); + } + } + }; + context.registerReceiver(receiver, filter); + } +} diff --git a/app/src/main/java/com/xixun/display/controller/FactoryCard.java b/app/src/main/java/com/xixun/display/controller/FactoryCard.java new file mode 100644 index 0000000..405d948 --- /dev/null +++ b/app/src/main/java/com/xixun/display/controller/FactoryCard.java @@ -0,0 +1,89 @@ +package com.xixun.display.controller; + +import com.xixun.display.MyLog; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.concurrent.ConcurrentHashMap; + +/** + * 一个工具类,此项目中作用为根据不通控制卡的ROM,选择创建当前设备的合适策略 + * @author joey + * + * @param 返回的接口类型 + * @param 选择依据 + */ +public class FactoryCard implements InvocationHandler { + public static boolean ENABLE_LOGGER_HARDWARE = false; + + private ConcurrentHashMap> factorys = new ConcurrentHashMap>(); + private R bean; + private R proxyBean; + private KEY curKey; + + public FactoryCard() { } + + /* 继承自同一接口的策略加载 */ + public FactoryCard addItem(KEY key, Class value) { + factorys.putIfAbsent(key, value); + return this; + } + + @SuppressWarnings("unchecked") + public synchronized R getProxy(KEY key) { + try { + if ((null != proxyBean) && curKey.equals(key)) { + return proxyBean; + } + curKey = key; + Class checkBean = factorys.get(key); + Class clazz = Class.forName(checkBean.getName()); + bean = (R) clazz.newInstance(); + proxyBean = (R) Proxy.newProxyInstance(clazz.getClassLoader(), clazz.getInterfaces(), this); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + return proxyBean; + } + + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + Object result = method.invoke(bean, args); + if (ENABLE_LOGGER_HARDWARE) { + StringBuilder logger = new StringBuilder("Invoke method ==> "); + logger.append(method.getName()); + logger.append("("); + if (null == args) { + logger.append(")"); + } else { + for (int index = 0; index < args.length; ++index) { + Object object = args[index]; + logger.append(isPrimitive(object)? object: args[index].getClass().getSimpleName()); + logger.append((index != (args.length - 1))? ", ": ")"); + } + } + logger.append(" ==> "); + if (null == result) { + logger.append("void"); + } else { + logger.append(isPrimitive(result)? result: result.getClass().getSimpleName()); + } + MyLog.i(logger.toString()); + } + return result; + } + + /* 判断一个对象是否是基本类型或基本类型的封装类型 */ + private boolean isPrimitive(Object obj) { + try { + return ((Class)obj.getClass().getField("TYPE").get(null)).isPrimitive(); + } catch (Exception e) { + return false; + } + } +} diff --git a/app/src/main/java/com/xixun/display/controller/HardwareControler.java b/app/src/main/java/com/xixun/display/controller/HardwareControler.java new file mode 100644 index 0000000..d872cdd --- /dev/null +++ b/app/src/main/java/com/xixun/display/controller/HardwareControler.java @@ -0,0 +1,117 @@ +package com.xixun.display.controller; +import android.util.Log; + +public class HardwareControler +{ + /* File */ + static public native int open(String devName, int flags); + static public native int write(int fd, byte[] data); + static public native int read(int fd, byte[] buf, int len); + static public native int select(int fd, int sec, int usec); + static public native void close(int fd); + static public native int ioctlWithIntValue(int fd, int cmd, int value); + + /* Serial Port */ + static public native int openSerialPort( String devName, long baud, int dataBits, int stopBits ); + static public native int openSerialPortEx( String devName + , long baud + , int dataBits + , int stopBits + , String parityBit + , String flowCtrl + ); + + /* LED */ + static public native int setLedState( int ledID, int ledState ); + + /* PWM */ + static public native int PWMPlay(int frequency); + static public native int PWMStop(); + static public native int PWMPlayEx(int gpioPin, int frequency); + static public native int PWMStopEx(int gpioPin); + + /* ADC */ + static public native int readADC(); + static public native int readADCWithChannel(int channel); + static public native int[] readADCWithChannels(int[] channels); + + /* I2C */ + static public native int setI2CSlave(int fd, int slave); + static public native int setI2CTimeout(int fd, int timeout); + static public native int setI2CRetries(int fd, int retries); + static public native int I2CReadByteData(int fd, int pos, int wait_us); + static public native int I2CReadByte(int fd, int wait_us); + static public native int I2CWriteByteData(int fd, int pos, byte byteData, int wait_us); + static public native int I2CWriteByte(int fd, byte byteData, int wait_us); + + /* Discard */ static public native byte readByteFromI2C(int fd, int pos, int wait_ms); + /* Discard */ static public native int writeByteToI2C(int fd, int pos, byte byteData, int wait_ms); + /* Discard */ static public native int writeByteToI2C2(int fd, byte byteData, int wait_ms); + + /* SPI */ + static public native int setSPIWriteBitsPerWord( int spi_fd, int bits ); + static public native int setSPIReadBitsPerWord( int spi_fd, int bits ); + static public native int setSPIBitOrder( int spi_fd, int order); + static public native int setSPIClockDivider( int spi_fd, int divider); + static public native int setSPIMaxSpeed( int spi_fd, int spi_speed); + static public native int setSPIDataMode( int spi_fd, int mode); + static public native int SPItransferOneByte( int spi_fd, byte byteData, int spi_delay, int spi_speed, int spi_bits); + static public native int SPItransferBytes(int spi_fd, byte[] writeData, byte[] readBuff, int spi_delay, int spi_speed, int spi_bits); + static public native int writeBytesToSPI(int spi_fd, byte[] writeData, int spi_delay, int spi_speed, int spi_bits); + static public native int readBytesFromSPI(int spi_fd, byte[] readBuff, int spi_delay, int spi_speed, int spi_bits); + + /* GPIO */ + static public native int exportGPIOPin(int pin); + static public native int unexportGPIOPin(int pin); + //GPIOEnum.LOW or GPIOEnum.HIGH + static public native int setGPIOValue(int pin, int value); + static public native int getGPIOValue(int pin); + //GPIOEnum.IN or GPIOEnum.OUT + static public native int setGPIODirection(int pin, int direction); + static public native int getGPIODirection(int pin); + + /* OldInterface: for EEPROM */ + static public native int openI2CDevice(); + static public native int writeByteDataToI2C(int fd, int pos, byte byteData); + static public native int readByteDataFromI2C(int fd, int pos); + + static public native int getBoardType(); + /* getBoardType return value: */ + public static final int S3C6410_COMMON = 6410; + public static final int S5PV210_COMMON = 210; + public static final int S5P4412_COMMON = 4412; + public static final int S5P4418_BASE = 4418; + public static final int NanoPi2 = S5P4418_BASE+0; + public static final int NanoPC_T2 = S5P4418_BASE+1; + public static final int NanoPi_S2 = S5P4418_BASE+2; + public static final int Smart4418 = S5P4418_BASE+3; + public static final int NanoPi2_Fire = S5P4418_BASE+4; + public static final int NanoPi_M2 = S5P4418_BASE+5; + public static final int NanoPi_M2A = S5P4418_BASE+7; + public static final int Smart4418SDK = S5P4418_BASE+0x103; + public static final int S5P4418_MAX = Smart4418SDK; + public static final int S5P6818_BASE = 6818; + public static final int NanoPC_T3 = S5P6818_BASE+1; + public static final int NanoPi_S3 = S5P6818_BASE+2; + public static final int Smart6818 = S5P6818_BASE+3; + public static final int NanoPi_M3 = S5P6818_BASE+7; + public static final int S5P6818_MAX = NanoPi_M3; + + static public boolean isS5P4418Board() { + int boardtype = getBoardType(); + return boardtype>=S5P4418_BASE && boardtype<=S5P4418_MAX; + } + + static public boolean isS5P6818Board() { + int boardtype = getBoardType(); + return boardtype>=S5P6818_BASE && boardtype<=S5P6818_MAX; + } + + static { + try { + System.loadLibrary("friendlyarm-hardware"); + } catch (UnsatisfiedLinkError e) { + Log.d("HardwareControler", "libfriendlyarm-hardware library not found!"); + } + } +} diff --git a/app/src/main/java/com/xixun/display/controller/XixunCard.java b/app/src/main/java/com/xixun/display/controller/XixunCard.java new file mode 100644 index 0000000..2d9b949 --- /dev/null +++ b/app/src/main/java/com/xixun/display/controller/XixunCard.java @@ -0,0 +1,46 @@ +package com.xixun.display.controller; + + +import com.xixun.display.RecCardInfo; + +import java.io.DataOutputStream; +import java.io.File; +import java.io.OutputStream; +import java.util.List; + +public interface XixunCard { + void init(); + int getPortNumber(); + boolean setBrightness(int brightness); + int getBrightness(); + void receDataFromPC(byte[] data, DataOutputStream sendStream); + void receDataFromPC_Xixun(byte[] data, DataOutputStream sendStream); + int getReceivedCardNumber(int iPortNumberIndex, int iReceCardType); + int getFpgaVersion(); + boolean backUpData(); + boolean restoreData(); + boolean fpgaUpgrade(String string); + byte[] flashRead(int iAddress, int iLength); + byte[] flashWrite(byte[] writeData, int iAddress, int iLength); + int IOSPIRes(boolean bWrite, long iAddress, byte[] ac_data, long iLength); + int getGigPortWriteAddrByCmdEnd(int cmdEnd); + long get_gig_port_status(int mask); + int getGigPortReadAddrByCmdEnd(int cmdEnd); + long vm_get_fpga_gige_cfg_addr(long gige_port_idx); + long vm_get_fls_gige_dat_addr(long gige_port_idx); + long vm_get_fpga_control_reg_size(); + long vm_get_fpga_control_reg_addr(); + long vm_get_fls_control_reg_dat_addr(); + boolean rebootByFPGA(); + File getFpgaFile(boolean b); + String getRelayState(int port, int vcs); + boolean setRelayState(int port, int vcs, String state); + void setRGB(int red,int green,int blue); + String getBoxSizeStr(); + void startPointCheck(); + void getPointCheckData(); + void setPortToConfig(int port); + List returnBadPointData(); + RecCardInfo getRecData(); + void setRecCardRelaySwitch(boolean isSwitch); +} diff --git a/app/src/main/java/com/xixun/display/controller/XixunController.java b/app/src/main/java/com/xixun/display/controller/XixunController.java new file mode 100644 index 0000000..977c640 --- /dev/null +++ b/app/src/main/java/com/xixun/display/controller/XixunController.java @@ -0,0 +1,103 @@ +package com.xixun.display.controller; + +import com.xixun.communicate.Task.PollingWorker; +import com.xixun.communicate.Task.Worker; +import com.xixun.display.MyApp; +import com.xixun.display.MyLog; +import com.xixun.display.R; +import com.xixun.display.domain.Variable; +import com.xixun.display.file.DiskType; +import com.xixun.display.file.FilesOpr; +import com.xixun.display.ledset.ServerTCP_S; +import com.xixun.display.ledset.ServerUDP; +import com.xixun.display.utils.CustomConfig; + +import java.io.File; + +import static java.lang.Thread.sleep; + +public class XixunController { + private static class Holder { + private static final XixunController instance = new XixunController(); + } + + public static XixunController get() { + return Holder.instance; + } + + public void init(){ + + /*RefreshDisplayInitail(); + + VirtuleRegsFileInitial(); + VirtuleFpgaParamsFileInitial(); + FpgaInitial();*/ + + //监听广播 +// new CardBroadcast().taskRegister(); + + //启动监听上位机 +// new ServerUDP().start(); + + new ServerTCP_S().start(); + //写码 +// writeCode(); + } + + private int codeCount = 0; + public void writeCode() { + new PollingWorker().addWorker(10*1000, 30*1000, new Worker() { + @Override + public void exec() { + if (codeCount>=20){ + codeCount = 0; + } + byte[] sendData= Variable.codeheadbs.get(codeCount); + MyLog.e("写码codeCount="+codeCount); +// MyLog.showBytes("写码codeCount="+codeCount,sendData,sendData.length); + MyApp.card().IOSPIRes(true,0xFF0000, sendData,sendData.length); + codeCount ++; + } + }); + } + + public String GetAppPath() { + return MyApp.getContext().getFilesDir().getAbsolutePath()+"/.."; + } + + public void AppRestart(){ + System.exit(0); + } + + /** + * 获取控制卡id + * @return + */ + public String getCardName() { + File cardID = new File(DiskType.SIGNED.getPath(), MyApp.getInstance().getString(R.string.file_card_id)); + byte[] content = FilesOpr.readFileByte(cardID, 0); + if ((null == content) || (0 == content.length)) { + return MyApp.getInstance().getString(R.string.default_card_name); + } else { + return cardIdToStr(content); + } + } + + public static String cardIdToStr(byte[] var1) { + byte[] var2 = new byte[]{97, 119, 38, 3, 46, 112, 36, 93, 58, 100, 103, 62, 115, 112, 114, 51, 43, 61, 2, 101, 119}; + if (var1.length < 40) { + return ""; + } else { + for (int var3 = 0; var3 < 20; ++var3) { + var1[var3] = (byte) (var1[var3 * 2] - var2[var3] - var3 - (var1[var3 * 2 + 1] - 3)); + } + + String var4 = new String(var1); + if (var4.length() >= 13) { + var4 = var4.substring(0, 13); + } + + return var4; + } + } +} diff --git a/app/src/main/java/com/xixun/display/controller/impl/ControllerB.java b/app/src/main/java/com/xixun/display/controller/impl/ControllerB.java new file mode 100644 index 0000000..ff93abe --- /dev/null +++ b/app/src/main/java/com/xixun/display/controller/impl/ControllerB.java @@ -0,0 +1,362 @@ +package com.xixun.display.controller.impl; + +import android.os.SystemClock; + +import com.xixun.communicate.SpiDevice; +import com.xixun.communicate.Task.PollingWorker; +import com.xixun.communicate.Task.Worker; +import com.xixun.display.MyApp; +import com.xixun.display.MyLog; +import com.xixun.display.controller.BaseController; +import com.xixun.display.controller.XixunCard; +import com.xixun.joey.aidlset.CardServiceObj; + +import org.json.JSONObject; + +import java.io.File; + +/** + * M60 + * @author xixun + * + */ +public class ControllerB extends BaseController implements XixunCard { + + JSONObject gpioInput_JasonBoject=null; + JSONObject gpioOutput_JasonBoject=null; + JSONObject gpioConfig_JasonBoject=null; + /**/ + static final int I2C_PORT='I'; + static final int I2C_SDA=4; + static final int I2C_CLK=5; + static final int GIG_RESET=6; + static final int FPGA_nConfigDone=8; + + static final int PHY_RST_PORT='I'; + static final int PHY_RST=6; + + @Override + public void initSpi() { + deviceName = "/dev/spidev0.0"; +// baudRate=12*1000*1000; + baudRate=2*1000*1000; + mode=1; + spiDevice = new SpiDevice(deviceName,baudRate,mode); + if (spiDevice!=null){ + spiDevice.spiDeveiceOpen(); + } + } + + + @Override + public int getPortNumber() { + return 2; + } + + @Override + public File getFpgaFile(boolean main) { + return getFpgaFileImpl(main? "m": "s"); + } + + @Override + public void specialTaskForCard() { + CardServiceObj.binderServer(); + try{ + { + gpioConfig_JasonBoject= new JSONObject(); + gpioConfig_JasonBoject.put("id", "None"); + gpioConfig_JasonBoject.put("_type", "OperationGPIO"); + gpioConfig_JasonBoject.put("method", 0); + } + + { + gpioInput_JasonBoject= new JSONObject(); + gpioInput_JasonBoject.put("id", "None"); + gpioInput_JasonBoject.put("_type", "OperationGPIO"); + gpioInput_JasonBoject.put("method", 1); + } + + { + gpioOutput_JasonBoject= new JSONObject(); + gpioOutput_JasonBoject.put("id", "None"); + gpioOutput_JasonBoject.put("_type", "OperationGPIO"); + gpioOutput_JasonBoject.put("method", 2); + } + + GpioConfig('B',6,true); + GpioOutput('B',6,true); + // NCE. + GpioConfig('B',7,false); + // nConfigDone. + GpioConfig('I',8,false); + long ms = SystemClock.elapsedRealtime();//系统启动至今的时间,毫秒 + if (ms/1000 < 120){//小于两分钟则执行这个 + for (int i = 0; i < 5; i++) { + MyLog.e("PhyIntial..."); + PhyIntial(); + MyApp.sleepForMillisecond(500); + } + } + }catch (Exception e){ + e.printStackTrace(); + } + + + new PollingWorker().addWorker(10*1000, 10*1000, new Worker() { + @Override + public void exec() { + //查询接收卡数量 + int receivedCardNum= 0; + for (int i = 0;i<2;i++){ +// receivedCardNum +=MyApp.card().getReceivedCardNumber(i,0xF);//接收卡数量 + } + MyLog.i("接收卡数据:"+receivedCardNum); + if (receivedCardNum<1){ + //复位千兆网 + MyLog.i("复位千兆网口..."); +// PhyReset(); + } + } + }); + + } + + @Override + public boolean rebootByFPGA() { + return false; + } + + public void MDIO_OUTPUT(){ GpioConfig(I2C_PORT,I2C_SDA,true); } + public void MDIO_INPUT(){ GpioConfig(I2C_PORT,I2C_SDA,false); } + public void MDIO_HIGH(){ GpioOutput(I2C_PORT,I2C_SDA,true); } + public void MDIO_LOW(){ GpioOutput(I2C_PORT,I2C_SDA,false); } + public boolean MDIO_GET(){ return GpioInput(I2C_PORT,4); } + + public void MDC_OUTPUT(){ GpioConfig(I2C_PORT,I2C_CLK,true); } + public void MDC_HIGH(){ GpioOutput(I2C_PORT,I2C_CLK,true); } + public void MDC_LOW(){ GpioOutput(I2C_PORT,I2C_CLK,false); } + + public void RST_OUTPUT(){ GpioConfig(PHY_RST_PORT,PHY_RST,true); } + public void RST_HIGH(){ GpioOutput(PHY_RST_PORT,PHY_RST,true); } + public void RST_LOW(){ GpioOutput(PHY_RST_PORT,PHY_RST,false); } + + public void PhyReset(){ + RST_OUTPUT(); + RST_HIGH(); + MyApp.sleepForMillisecond(100); + RST_LOW(); + MyApp.sleepForMillisecond(100); + RST_HIGH(); + MyApp.sleepForMillisecond(100); + } + + + public void PhyIntial(){ + PhyReset(); + WritePhyData(0x00,0x09,0x1A00); + WritePhyData(0x01,0x09,0x1A00); + } + + public void WritePhyData(int uiPhyAddress,int uiRegAddress,int iData){ + int i; + MDC_OUTPUT(); + MDIO_OUTPUT(); + MyApp.sleepForMillisecond(10); + for(i=0;i<32;i++){ + MDC_LOW(); + MyApp.sleepForMillisecond(1); + MDIO_HIGH(); //1 + MyApp.sleepForMillisecond(1); + MDC_HIGH(); + } + + MDC_LOW(); + MDIO_LOW(); //0 + MDC_HIGH(); + + MDC_LOW(); + MDIO_HIGH(); //1 + MDC_HIGH(); + + MDC_LOW(); + MDIO_LOW(); //0 + MDC_HIGH(); + + MDC_LOW(); + MDIO_HIGH(); //1 + MDC_HIGH(); + for(i=5;i>=1;i--){ + if((uiPhyAddress & (1<<(i-1)))!=0) { + MDC_LOW(); + MDIO_HIGH(); //1 + MDC_HIGH(); + } else{ + MDC_LOW(); + MDIO_LOW(); //0 + MDC_HIGH(); + + } + } + + for(i=5;i>=1;i--){ + if((uiRegAddress & (1<<(i-1)))!=0){ + MDC_LOW(); + MDIO_HIGH(); //1 + MDC_HIGH(); + + }else{ + MDC_LOW(); + MDIO_LOW(); //0 + MDC_HIGH(); + + } + } + MDC_LOW(); + MDIO_HIGH(); //1 + MDC_HIGH(); + + MDC_LOW(); + MDIO_LOW(); //0 + MDC_HIGH(); + + for(i=16;i>=1;i--){ + if((iData & (1<<(i-1)))!=0){ + MDC_LOW(); + MDIO_HIGH(); //1 + MDC_HIGH(); + + }else{ + MDC_LOW(); + MDIO_LOW(); //0 + MDC_HIGH(); + } + } + MDIO_HIGH(); + + } + + + public int ReadPhyData(int uiPhyAddress,int uiRegAddress){ + int temp=0,i=0; + + MDC_OUTPUT(); + MDIO_OUTPUT(); + MyApp.sleepForMillisecond(10); + + for(i=0;i<32;i++){ + MDC_LOW(); + MDIO_HIGH(); //1 + MDC_HIGH(); + } + MDC_LOW(); + MDIO_LOW(); //0 + MDC_HIGH(); + + MDC_LOW(); + MDIO_HIGH(); //1 + MDC_HIGH(); + + MDC_LOW(); + MDIO_HIGH(); //1 + MDC_HIGH(); + + MDC_LOW(); + MDIO_LOW(); //0 + MDC_HIGH(); + + + for(i=5;i>=1;i--){ + if((uiPhyAddress & (1<<(i-1)))!=0){ + MDC_LOW(); + MDIO_HIGH(); //1 + MDC_HIGH(); + + }else{ + MDC_LOW(); + MDIO_LOW(); //0 + MDC_HIGH(); + } + } + + for(i=5;i>=1;i--){ + if((uiRegAddress & (1<<(i-1)))!=0){ + MDC_LOW(); + MDIO_HIGH(); //1 + MDC_HIGH(); + }else{ + MDC_LOW(); + MDIO_LOW(); //0 + MDC_HIGH(); + } + } + + MDIO_INPUT(); + MyApp.sleepForMillisecond(10); + + MDC_LOW(); + MDC_HIGH(); + + MDC_LOW(); + MDC_HIGH(); + + temp=0; + for(i=16;i>=1;i--){ + MDC_LOW(); + if(MDIO_GET()){ + temp |= 1<<(i-1); + } + MDC_HIGH(); + } + return temp; + } + + public String GpioConfig(int ucPortId,int iPinId,boolean bOutput){ + String strPinState = null; + try { + gpioConfig_JasonBoject.put("group", ucPortId); + gpioConfig_JasonBoject.put("num", iPinId); + gpioConfig_JasonBoject.put("value", bOutput? 1: 0); + strPinState = CardServiceObj.executeJsonCommand(gpioConfig_JasonBoject.toString()); + } + catch (Exception e) { + MyLog.i(" "+ Thread.currentThread().getStackTrace()[2].getFileName() + "-->" + + "Function: " +Thread.currentThread().getStackTrace()[2].getMethodName() + "-->" + + "Line" +Thread.currentThread().getStackTrace()[2].getLineNumber() + ":\r\n" + ); + } + return strPinState; + } + + public void GpioOutput(int ucPortId,int iPinId,boolean bHighLevel) { + try { + gpioOutput_JasonBoject.put("group", ucPortId); + gpioOutput_JasonBoject.put("num", iPinId); + gpioOutput_JasonBoject.put("value", bHighLevel? 1:0); + String strPinState = CardServiceObj.executeJsonCommand(gpioOutput_JasonBoject.toString()); + } + catch (Exception e) { + MyLog.i(" "+ Thread.currentThread().getStackTrace()[2].getFileName() + "-->" + + "Function: " +Thread.currentThread().getStackTrace()[2].getMethodName() + "-->" + + "Line" +Thread.currentThread().getStackTrace()[2].getLineNumber() + ":\r\n" + ); + } + } + + public boolean GpioInput(int ucPortId,int iPinId){ + if (gpioConfig_JasonBoject==null) return false; + + try { + gpioInput_JasonBoject.put("group", ucPortId); + gpioInput_JasonBoject.put("num", iPinId); + gpioInput_JasonBoject.put("value", 0); + String strPinState = CardServiceObj.executeJsonCommand(gpioInput_JasonBoject.toString()); + } + catch (Exception e) { + MyLog.i(" "+ Thread.currentThread().getStackTrace()[2].getFileName() + "-->" + + "Function: " +Thread.currentThread().getStackTrace()[2].getMethodName() + "-->" + + "Line" +Thread.currentThread().getStackTrace()[2].getLineNumber() + ":\r\n" + ); + } + return false; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/xixun/display/controller/impl/ControllerC.java b/app/src/main/java/com/xixun/display/controller/impl/ControllerC.java new file mode 100644 index 0000000..0099c13 --- /dev/null +++ b/app/src/main/java/com/xixun/display/controller/impl/ControllerC.java @@ -0,0 +1,49 @@ +package com.xixun.display.controller.impl; + + +import com.xixun.communicate.SpiDevice; +import com.xixun.display.MyLog; +import com.xixun.display.controller.BaseController; +import com.xixun.display.controller.XixunCard; + +import java.io.File; + +/** + * + * @ClassName: ControllerC + * @Description: PX30 + * @author: Lay + * @date: 2021-12-23 下午2:27:30 + * @Copyright: 2020 https://ledok.cn/ Inc. All rights reserved. + * 注意:本内容仅限于上海熙讯电子科技有限公司内部传阅,禁止外泄以及用于其他的商业目的 + */ +public class ControllerC extends BaseController implements XixunCard { + @Override + public void initSpi() { + MyLog.i("init spi C..."); + deviceName = "/dev/spidev0.0"; + baudRate=12*1000*1000; + mode=3; + spiDevice = new SpiDevice(deviceName,baudRate,mode); + if (spiDevice!=null){ + spiDevice.spiDeveiceOpen(); + } + } + + @Override + public void specialTaskForCard() { + + } + @Override + public File getFpgaFile(boolean main) { + return getFpgaFileImpl(main? "y": "s"); + } + @Override + public int getPortNumber() { + return 2; + } + @Override + public boolean rebootByFPGA() { + return false; + } +} diff --git a/app/src/main/java/com/xixun/display/controller/impl/ControllerD.java b/app/src/main/java/com/xixun/display/controller/impl/ControllerD.java new file mode 100644 index 0000000..8c9c201 --- /dev/null +++ b/app/src/main/java/com/xixun/display/controller/impl/ControllerD.java @@ -0,0 +1,66 @@ +package com.xixun.display.controller.impl; + + +import com.xixun.communicate.SpiDevice; +import com.xixun.display.MyApp; +import com.xixun.display.MyLog; +import com.xixun.display.controller.BaseController; +import com.xixun.display.controller.XixunCard; +import com.xixun.unique.CardType; + +import java.io.File; + +/** + * + * @ClassName: ControllerD + * @Description: 3288 包含M7X和Y7X系列控制卡控制类 + * @author: Lay + * @date: 2020-1-16 下午2:27:30 + * @Copyright: 2020 https://ledok.cn/ Inc. All rights reserved. + * 注意:本内容仅限于上海熙讯电子科技有限公司内部传阅,禁止外泄以及用于其他的商业目的 + */ +public class ControllerD extends BaseController implements XixunCard { + @Override + public void initSpi() { + deviceName = "/dev/spidev2.0"; + baudRate=18*1000*1000; + mode=3; + spiDevice = new SpiDevice(deviceName,baudRate,mode); + if (spiDevice!=null){ + spiDevice.spiDeveiceOpen(); + } + } + + @Override + public void specialTaskForCard() { + /*new PollingWorker().addWorker(0, 3000, new Worker() { + @Override + public void exec() { + getFpgaVersion(); + } + });*/ + } + + @Override + public int getPortNumber() { + if (MyApp.getCardType() == CardType.D_2) { + return 4; + }else{ + return 2; + } + } + + @Override + public File getFpgaFile(boolean main) { + return getFpgaFileImpl(main? "y": "s"); + } + + @Override + public boolean rebootByFPGA() { + byte[] newData = new byte[14]; + System.arraycopy(rebootReset ,0,newData,0,rebootReset.length); + MyLog.showBytes("newData",newData,0); + int res = spiDevice.Operator(newData,newData.length); + return res>0 ? true : false; + } +} diff --git a/app/src/main/java/com/xixun/display/controller/impl/ControllerM.java b/app/src/main/java/com/xixun/display/controller/impl/ControllerM.java new file mode 100644 index 0000000..d8005a5 --- /dev/null +++ b/app/src/main/java/com/xixun/display/controller/impl/ControllerM.java @@ -0,0 +1,59 @@ +package com.xixun.display.controller.impl; + +import android.os.SystemClock; + +import com.xixun.communicate.SpiDevice; +import com.xixun.display.MyLog; +import com.xixun.display.controller.BaseController; +import com.xixun.display.controller.XixunCard; +import com.xixun.display.controller.XixunController; + +import java.io.File; + +/** + * + * @ClassName: ControllerM + * @Description: 美格23.4系列控制卡控制类,Y60代表 + * @author: Lay + * @date: 2019-7-10 下午5:33:29 + * + * @Copyright: 2019 https://ledok.cn/ Inc. All rights reserved. + * 注意:本内容仅限于上海熙讯电子科技有限公司内部传阅,禁止外泄以及用于其他的商业目的 + */ +public class ControllerM extends BaseController implements XixunCard { + + @Override + public void initSpi() { + deviceName = "/dev/spidev0.0"; + baudRate=12*1000*1000; + mode=1; + spiDevice = new SpiDevice(deviceName,baudRate,mode); + if (spiDevice!=null){ + spiDevice.spiDeveiceOpen(); + } + } + + @Override + public void specialTaskForCard() { + MyLog.e("elapsedRealtime "+ SystemClock.elapsedRealtime()/1000); + } + + @Override + public int getPortNumber() { + return 2; + } + @Override + public boolean rebootByFPGA() { + return false; + } + + @Override + public File getFpgaFile(boolean main) { + if (XixunController.get().getCardName().startsWith("y")){ + return getFpgaFileImpl(main? "y": "s"); + }else { + return getFpgaFileImpl(main? "e": "s"); + } + } + +} diff --git a/app/src/main/java/com/xixun/display/controller/impl/ControllerP.java b/app/src/main/java/com/xixun/display/controller/impl/ControllerP.java new file mode 100644 index 0000000..c3e51da --- /dev/null +++ b/app/src/main/java/com/xixun/display/controller/impl/ControllerP.java @@ -0,0 +1,63 @@ +package com.xixun.display.controller.impl; + +import android.os.SystemClock; + +import com.xixun.communicate.SpiDevice; +import com.xixun.display.MyApp; +import com.xixun.display.MyLog; +import com.xixun.display.controller.BaseController; +import com.xixun.display.controller.XixunCard; +import com.xixun.joey.aidlset.CardServiceObj; + +import org.json.JSONObject; + +import java.io.File; + +/** + * E30为代表 + * @author xixun + * + */ +public class ControllerP extends BaseController implements XixunCard { + + @Override + public void initSpi() { + deviceName = "/dev/spidev-lynq"; + baudRate=12*1000*1000; + mode=1; + spiDevice = new SpiDevice(deviceName,baudRate,mode); + spiDevice.spiDeveiceOpen(); + } + + @Override + public void specialTaskForCard() { + /*CardServiceObj.binderServer(); + try{ + MyLog.e("e30 gpio............"); + JSONObject gpioOutput_JasonBoject= new JSONObject(); + gpioOutput_JasonBoject.put("id", "None"); + gpioOutput_JasonBoject.put("_type", "OperationGPIO"); + gpioOutput_JasonBoject.put("method", 2); + gpioOutput_JasonBoject.put("num", 8); + gpioOutput_JasonBoject.put("value", 1); + CardServiceObj.executeJsonCommand(gpioOutput_JasonBoject.toString()); + }catch (Exception e){ + e.printStackTrace(); + }*/ + } + + @Override + public int getPortNumber() { + return 1; + } + + @Override + public boolean rebootByFPGA() { + return false; + } + + @Override + public File getFpgaFile(boolean main) { + return getFpgaFileImpl(main? "e": "s"); + } +} diff --git a/app/src/main/java/com/xixun/display/controller/impl/ControllerUnknown.java b/app/src/main/java/com/xixun/display/controller/impl/ControllerUnknown.java new file mode 100644 index 0000000..4d259e4 --- /dev/null +++ b/app/src/main/java/com/xixun/display/controller/impl/ControllerUnknown.java @@ -0,0 +1,34 @@ +package com.xixun.display.controller.impl; + + +import com.xixun.display.controller.BaseController; +import com.xixun.display.controller.XixunCard; + +import java.io.File; + +public class ControllerUnknown extends BaseController implements XixunCard { + + @Override + public void initSpi() { + + } + + @Override + public void specialTaskForCard() { + + } + + @Override + public int getPortNumber() { + return 0; + } + @Override + public boolean rebootByFPGA() { + return false; + } + + @Override + public File getFpgaFile(boolean main) { + return getFpgaFileImpl(main? "e": "s"); + } +} diff --git a/app/src/main/java/com/xixun/display/controller/impl/ControllerWX.java b/app/src/main/java/com/xixun/display/controller/impl/ControllerWX.java new file mode 100644 index 0000000..66006f1 --- /dev/null +++ b/app/src/main/java/com/xixun/display/controller/impl/ControllerWX.java @@ -0,0 +1,43 @@ +package com.xixun.display.controller.impl; + +import com.xixun.communicate.SpiDevice; +import com.xixun.display.controller.BaseController; +import com.xixun.display.controller.XixunCard; + +import java.io.File; + +/** + * 4418 + * @author xixun + * + */ +public class ControllerWX extends BaseController implements XixunCard { + + @Override + public void initSpi() { + deviceName = "/dev/spidev0.0"; + baudRate=12*1000*1000; + mode=1; + spiDevice = new SpiDevice(deviceName,baudRate,mode); + spiDevice.spiDeveiceOpen(); + } + + @Override + public void specialTaskForCard() { + + } + + @Override + public int getPortNumber() { + return 1; + } + @Override + public boolean rebootByFPGA() { + return false; + } + + @Override + public File getFpgaFile(boolean main) { + return getFpgaFileImpl(main? "y": "s"); + } +} diff --git a/app/src/main/java/com/xixun/display/controller/impl/ControllerYZ.java b/app/src/main/java/com/xixun/display/controller/impl/ControllerYZ.java new file mode 100644 index 0000000..2686fd7 --- /dev/null +++ b/app/src/main/java/com/xixun/display/controller/impl/ControllerYZ.java @@ -0,0 +1,44 @@ +package com.xixun.display.controller.impl; + +import com.xixun.communicate.SpiDevice; +import com.xixun.display.controller.BaseController; +import com.xixun.display.controller.XixunCard; + +import java.io.File; + +/** + * 210 + * @author xixun + * + */ +public class ControllerYZ extends BaseController implements XixunCard { + + @Override + public void initSpi() { + deviceName = "/dev/spidev0.0"; + baudRate=12*1000*1000; + mode=1; + spiDevice = new SpiDevice(deviceName,baudRate,mode); + spiDevice.spiDeveiceOpen(); + } + + @Override + public void specialTaskForCard() { + + } + + @Override + public int getPortNumber() { + return 1; + } + + @Override + public boolean rebootByFPGA() { + return false; + } + + @Override + public File getFpgaFile(boolean main) { + return getFpgaFileImpl(main? "y": "s"); + } +} diff --git a/app/src/main/java/com/xixun/display/domain/Header.java b/app/src/main/java/com/xixun/display/domain/Header.java new file mode 100644 index 0000000..199a313 --- /dev/null +++ b/app/src/main/java/com/xixun/display/domain/Header.java @@ -0,0 +1,160 @@ +package com.xixun.display.domain; + +import com.xixun.display.MyApp; +import com.xixun.display.MyLog; + +public class Header { + /*private char pre; //55 55 //00,01 + private char ver; //02 + + //srv 服务码 0D:读数据 3D:无应答的写 AD:有应答的写 + private char srv; //03 + + //cmd: FE000000:测试网络通讯速度 + //DA000000: + //DB000000:flash读写 + //DD000000:寄存器 + //DE000000:设置时间 + //DF000000:GIG千兆网写数据 + private long cmd ; //4字节 //04,05,06,07 + private short len;//2 //08,09 + private long addr_dst; //10,11,12,13 + private long addr_src; //04,15,16,17 + private long addr_dat; //18,19,20,21 数据地址 + private short option; //22,23 + private long check_code;*/ //24,25,26,27 + + private byte[] pre; + private byte[] ver; + private byte[] srv; + private byte[] cmd; + private byte[] len; + private byte[] addr_dst; + private byte[] addr_src; + private byte[] addr_dat; + private byte[] option; + private byte[] check_code; + + + public byte[] getPre() { + return pre; + } + + public void setPre(byte[] pre) { + this.pre = pre; + } + + public byte[] getVer() { + return ver; + } + + public void setVer(byte[] ver) { + this.ver = ver; + } + + public byte[] getSrv() { + return srv; + } + + public void setSrv(byte[] srv) { + this.srv = srv; + } + + public byte[] getCmd() { + return cmd; + } + + public void setCmd(byte[] cmd) { + this.cmd = cmd; + } + + public byte[] getLen() { + return len; + } + + public void setLen(byte[] len) { + this.len = len; + } + + public byte[] getAddr_dst() { + return addr_dst; + } + + public void setAddr_dst(byte[] addr_dst) { + this.addr_dst = addr_dst; + } + + public byte[] getAddr_src() { + return addr_src; + } + + public void setAddr_src(byte[] addr_src) { + this.addr_src = addr_src; + } + + public byte[] getAddr_dat() { + return addr_dat; + } + + public void setAddr_dat(byte[] addr_dat) { + this.addr_dat = addr_dat; + } + + public byte[] getOption() { + return option; + } + + public void setOption(byte[] option) { + this.option = option; + } + + public byte[] getCheck_code() { + return check_code; + } + + public void setCheck_code(byte[] check_code) { + this.check_code = check_code; + } + + public byte[] concatHeader() { + byte[] newData = new byte[28]; + System.arraycopy(pre, 0,newData, 0, pre.length); + System.arraycopy(ver, 0,newData, pre.length, ver.length); + System.arraycopy(srv, 0,newData, pre.length+ver.length, srv.length); + System.arraycopy(cmd, 0,newData, pre.length+ver.length+srv.length, cmd.length); + System.arraycopy(len, 0,newData, pre.length+ver.length+srv.length+cmd.length, len.length); + System.arraycopy(addr_dst, 0,newData, pre.length+ver.length+srv.length+cmd.length+len.length, addr_dst.length); + System.arraycopy(addr_src, 0,newData, pre.length+ver.length+srv.length+cmd.length+len.length+addr_dst.length, addr_src.length); + System.arraycopy(addr_dat, 0,newData, pre.length+ver.length+srv.length+cmd.length+len.length+addr_dst.length+addr_src.length, addr_dat.length); + System.arraycopy(option, 0,newData, pre.length+ver.length+srv.length+cmd.length+len.length+addr_dst.length+addr_src.length+addr_dat.length, option.length); + + //计算校验码 + check_code = MyApp.calcHeaderCheckCode(newData); + MyLog.showBytes("计算check_code:",check_code,0); + + System.arraycopy(check_code, 0,newData, pre.length+ver.length+srv.length+cmd.length+len.length+addr_dst.length+addr_src.length+addr_dat.length+option.length, check_code.length); + return newData; + } + + /*public byte[] byteMerger(){ + List result = new ArrayList(); + + return result.toArray(); + }*/ + + @Override + public String toString() { + MyLog.showBytes("pre",pre,0); + MyLog.showBytes("ver",ver,0); + MyLog.showBytes("srv",srv,0); + MyLog.showBytes("cmd",cmd,0); + MyLog.showBytes("len",len,0); + MyLog.showBytes("addr_dst",addr_dst,0); + MyLog.showBytes("addr_src",addr_src,0); + MyLog.showBytes("addr_dat",addr_dat,0); + MyLog.showBytes("option",option,0); + MyLog.showBytes("check_code",check_code,0); + MyLog.d("--------------------------------------------------------------"); + return ""; + } +} diff --git a/app/src/main/java/com/xixun/display/domain/Reg.java b/app/src/main/java/com/xixun/display/domain/Reg.java new file mode 100644 index 0000000..ca21f55 --- /dev/null +++ b/app/src/main/java/com/xixun/display/domain/Reg.java @@ -0,0 +1,155 @@ +package com.xixun.display.domain; + +import com.xixun.display.MyApp; +import com.xixun.display.utils.DisplayConfig; + +public class Reg { + + //addr_dat + + public byte[] all; + //版本 8 + //类型:E0 主版本: 子版本: 控制码:E0 功能码1,2,3,4:A5,02,00,00 + public byte[] version; + //设备ID 8 + public byte[] deviceId; + //产品型号 32 + public byte[] productModel; + //网卡数量 4 + public byte[] soNum; //位置:A4 + //运行时间:卡运行了多久 4 + public byte[] runTime; //位置:A8 + //系统时间 8 + public byte[] systemTime; + //其他 + public byte[] other; + + public Reg() { + } + + public Reg(int len) { + this.all = new byte[len]; + this.version = MyApp.getVersion(); + this.deviceId = MyApp.getDeviceId(); + this.productModel = MyApp.getProductModel(); + this.soNum = MyApp.getSoNum(); + this.runTime = MyApp.getRunTime(); + this.systemTime = MyApp.getSystemTime(); + } + + public Reg(int len, byte[] version, byte[] deviceId, byte[] productModel, byte[] soNum, byte[] runTime, byte[] systemTime) { + this.all = new byte[len]; + this.version = version; + this.deviceId = deviceId; + this.productModel = productModel; + this.soNum = soNum; + this.runTime = runTime; + this.systemTime = systemTime; + } + + public byte[] getAll() { + celcAll(); + return all; + } + + public void setAll(byte[] all) { + this.all = all; + } + + public byte[] getVersion() { + return version; + } + + public void setVersion(byte[] version) { + this.version = version; + } + + public byte[] getDeviceId() { + return deviceId; + } + + public void setDeviceId(byte[] deviceId) { + this.deviceId = deviceId; + } + + public byte[] getProductModel() { + return productModel; + } + + public void setProductModel(byte[] productModel) { + this.productModel = productModel; + } + + public byte[] getSoNum() { + return soNum; + } + + public void setSoNum(byte[] soNum) { + this.soNum = soNum; + } + + public byte[] getRunTime() { + return runTime; + } + + public void setRunTime(byte[] runTime) { + this.runTime = runTime; + } + + public byte[] getSystemTime() { + return systemTime; + } + + public void setSystemTime(byte[] systemTime) { + this.systemTime = systemTime; + } + + public byte[] getOther() { + return other; + } + + public void setOther(byte[] other) { + this.other = other; + } + + public void celcAll(){ + runTime = MyApp.getRunTime(); + systemTime = MyApp.getSystemTime(); + System.arraycopy(version,0,all,0,version.length); + System.arraycopy(deviceId,0,all,version.length,deviceId.length); + System.arraycopy(productModel,0,all,(version.length+deviceId.length),productModel.length); + System.arraycopy(soNum,0,all,(version.length+deviceId.length+productModel.length),soNum.length); + System.arraycopy(runTime,0,all,0xA4,runTime.length); + System.arraycopy(systemTime,0,all,0xA8,systemTime.length); + /*MyLog.showBytes("version",version,0); + MyLog.showBytes("deviceId",deviceId,0); + MyLog.showBytes("productModel",productModel,0); + MyLog.showBytes("soNum",soNum,0); + MyLog.showBytes("runTime",runTime,0); + MyLog.showBytes("systemTime",systemTime,0);*/ +// MyLog.showBytes("RegAll",all,0); + } + + /*public void celcSingle(){ + runTime = MyApp.getRunTime(); + systemTime = MyApp.getSystemTime(); + System.arraycopy(version,0,all,0,version.length); + System.arraycopy(deviceId,0,all,version.length,deviceId.length); + System.arraycopy(productModel,0,all,(version.length+deviceId.length),productModel.length); + System.arraycopy(soNum,0,all,(version.length+deviceId.length+productModel.length),soNum.length); + System.arraycopy(runTime,0,all,(version.length+deviceId.length+productModel.length+soNum.length),runTime.length); + System.arraycopy(systemTime,0,all,(version.length+deviceId.length+productModel.length+soNum.length+runTime.length),systemTime.length); + MyLog.showBytes("version",version,0); + MyLog.showBytes("deviceId",deviceId,0); + MyLog.showBytes("productModel",productModel,0); + MyLog.showBytes("soNum",soNum,0); + MyLog.showBytes("runTime",runTime,0); + MyLog.showBytes("systemTime",systemTime,0); + MyLog.showBytes("All",all,0); + }*/ + + public void finish(){ + //将数据保存到config中 + DisplayConfig.setReg(this); + } +} diff --git a/app/src/main/java/com/xixun/display/domain/StructNetBuffer.java b/app/src/main/java/com/xixun/display/domain/StructNetBuffer.java new file mode 100644 index 0000000..df5b98c --- /dev/null +++ b/app/src/main/java/com/xixun/display/domain/StructNetBuffer.java @@ -0,0 +1,82 @@ +package com.xixun.display.domain; + +import com.xixun.display.MyLog; + +/** + * 用于封装收到和发出的数据 + */ +public class StructNetBuffer { + private Header header; + private byte[] headerbs; + private byte[] data; + private byte[] check; + + public StructNetBuffer() { + } + + public StructNetBuffer( byte[] data,Header header) { + this.headerbs = new byte[28]; + this.data = data; + this.check = new byte[4]; + this.header = header; + } + + public Header getHeader() { + return header; + } + + public void setHeader(Header header) { + this.header = header; + } + + public byte[] getHeaderbs() { + return headerbs; + } + + public void setHeaderbs(byte[] headerbs) { + this.headerbs = headerbs; + } + + public byte[] getData() { + return data; + } + + public void setData(byte[] data) { + this.data = data; + } + + public byte[] getCheck() { + return check; + } + + public void setCheck(byte[] check) { + this.check = check; + } + + + @Override + public String toString() { + MyLog.showBytes("headerbs",headerbs,0); + MyLog.showBytes("data",data,0); + MyLog.showBytes("check",check,0); + MyLog.i("--------------------------------------------------------------"); + return ""; + } + + /** + * 将header的数据填充到Header对象中 + */ + public void headerbsToHeader() { + header.setPre(new byte[]{headerbs[0], headerbs[1]}); + header.setVer(new byte[]{headerbs[2]}); + header.setSrv(new byte[]{headerbs[3]}); + header.setCmd(new byte[]{headerbs[4],headerbs[5],headerbs[6],headerbs[7]}); + header.setLen(new byte[]{headerbs[8],headerbs[9]}); + header.setAddr_dst(new byte[]{headerbs[10],headerbs[11],headerbs[12],headerbs[13]}); + header.setAddr_src(new byte[]{headerbs[14],headerbs[15],headerbs[16],headerbs[17]}); + header.setAddr_dat(new byte[]{headerbs[18],headerbs[19],headerbs[20],headerbs[21]}); + header.setOption(new byte[]{headerbs[22],headerbs[23]}); + header.setCheck_code(new byte[]{headerbs[24],headerbs[25],headerbs[26],headerbs[27]}); +// header.toString(); + } +} diff --git a/app/src/main/java/com/xixun/display/domain/TagVcmGigePortState.java b/app/src/main/java/com/xixun/display/domain/TagVcmGigePortState.java new file mode 100644 index 0000000..031cf47 --- /dev/null +++ b/app/src/main/java/com/xixun/display/domain/TagVcmGigePortState.java @@ -0,0 +1,68 @@ +package com.xixun.display.domain; + +public class TagVcmGigePortState { + /*long msg; //描述 12 + long connectStatus; //连接状态 4 + long busyStatus; //忙状态 4 + long haveVcsPktStatus; //有新包 4 + long isBackupStatus; //备份 4 + char isEnableMutiWnd; //支持多窗口 4 + char doneWndCnts[16]; //窗口数量 32 + + + + int get_gig_port_status_info(VcmGigePortState *sta) + { + int errcode = -1; + unsigned char dat[64]; + unsigned char ac_addr_offset = 0; + memset(sta, 0, sizeof(VcmGigePortState)); + + errcode = vcm_ram_r(0x710000, dat, sizeof(dat)); + if (0 == errcode) + { + sta->isEnableMutiWnd = ((dat[16] >> 4) == 0xA) ? 1 : 0 ; + + int i_gig_count = get_vcm_gig_count(); + for (int i = 0; i < i_gig_count; i++) + { + if (i >= 8) + { + ac_addr_offset = 4; + } + { + if (dat[(i * 2) + 1 + ac_addr_offset] & (0x01 << 0)) + { + sta->connectStatus |= (1 << i); + } + } + + { + if (dat[(i * 2) + 1 + ac_addr_offset] & (0x01 << 1)) + { + sta->busyStatus |= (1 << i); + } + } + + { + if (dat[(i * 2) + 1 + ac_addr_offset] & (0x01 << 2)) + { + sta->haveVcsPktStatus |= (1 << i); + } + } + { + if (dat[(i * 2) + 1 + ac_addr_offset] & (0x01 << 4)) + { + sta->isBackupStatus |= (1 << i); + } + } + if (sta->isEnableMutiWnd) + { + sta->doneWndCnts[i] = dat[(i * 2) + ac_addr_offset]; + } + } + } + + return errcode; + }*/ +} diff --git a/app/src/main/java/com/xixun/display/domain/Variable.java b/app/src/main/java/com/xixun/display/domain/Variable.java new file mode 100644 index 0000000..95c144a --- /dev/null +++ b/app/src/main/java/com/xixun/display/domain/Variable.java @@ -0,0 +1,107 @@ +package com.xixun.display.domain; + +import com.xixun.display.utils.Define; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class Variable { + + public static final int UDP_PORT=9988; + public static final int TCP_PORT=9999; + public static final int TCP_PORT_S=9977; + + public static final int REG_PAGE_SIZE = 4 * 1024; + public static final int REG_SIZE = REG_PAGE_SIZE * 256; + + /*public static final int CMD_TEST=0xFE000000; + public static final int CMD_2=0xDA000000; + public static final int FLASH_R_W=0xDB000000; //flash读写标志 + public static final int REG_R_W=0xDD000000; //寄存器读写标志 + public static final int Time_R_W=0xDE000000; //系统时间读写标志 + public static final int GIG_R_W=0xDF000000; //系统时间读写标志*/ + + public static final int CMD_TEST=0xFE0000; + public static final int CMD_2=0xDA0000; + public static final int FLASH_R_W=0xDB0000; //flash读写标志 + public static final int REG_R_W=0xDD0000; //寄存器读写标志 + public static final int Time_R_W=0xDE0000; //系统时间读写标志 + public static final int GIG_R_W=0xDF0000; //系统时间读写标志 + public static final int FIND_FLAG=0xDC0000; //查询命令标志 + + public static final int SRV_READ_DATA=0x0D;//读数据 + public static final int SRV_NOANSWER_WRITE=0x3D;//无应答写 + public static final int SRV_ANSWER_WRITE= 0xAD;//有应答写 + + public static final byte MOONCELL_FPGA_WRITE_FLAG = (byte) 0xE5; + public static final byte MOONCELL_FPGA_READ_FLAG = (byte) 0xAA; + + //0xA5000001 + + + public static byte STREAM_SYNC_HEAD = (0x7E); + public static byte STREAM_SYNC_HEAD2 = (0x55); + public static int MAX_PACKET_SIZE = (Define.FLASH_PAGE_SIZE * 4);//Define.FLASH_SIZE); + + public static final int MOONCELL_FPGA_FLASH_ADDRESS_GPORT_NUM_PARAMS = 0x80 * Define.FLASH_PAGE_SIZE; + public static final int MOONCELL_FPGA_FLASH_ADDRESS_GPORT_PARAMS = 0x8C * Define.FLASH_PAGE_SIZE; + public static final int MOONCELL_FPGA_FLASH_ADDRESS_PICTURE_CONTROL = 0x8E * Define.FLASH_PAGE_SIZE; + public static final int MOONCELL_FPGA_MIRROR_ADDRESS_BASIC_STEP = 0x100 * 4; + public static final int MOONCELL_FPGA_MIRROR_ADDRESS_BASIC = 0xA70000; + public static final int MOONCELL_FPGA_PORT_NUMBER = 8; + public static final int MOONCELL_FPGA_MIRROR_ADDRESS_PICTURE_CONTROL = MOONCELL_FPGA_MIRROR_ADDRESS_BASIC + MOONCELL_FPGA_MIRROR_ADDRESS_BASIC_STEP * 8; // 0xA70000 0x100*4 * 8 = A72000 + public static final int MOONCELL_FPGA_MIRROR_ADDRESS_PICTURE_CONTROL_LIGHT_OFFSET = 0x0D * 4; // 0X34 + public static final int MOONCELL_FPGA_MIRROR_ADDRESS_PICTURE_CONTROL_LIGHT_ENABLE_OFFSET = 0x0E * 4; // 0X38 + + public static final int MOONCELL_FPGA_MIRROR_ADDRESS_SYSTEM_CONFIG = 0xA80000; + + public static int HUB_BOARDCAST_ADDRESS = 0x10FF; + public static int RECEIVED_CARD_BOARDCAST_ADDRESS = 0xFFF; // 0:第一个接收卡,。。 + public static int RECEIVED_CARD_TYPE_BOARDCASE = 0xF; + + public static int PX_BROARDCAST = 0xFF; // 0:第一个网口,。。。 + public static int BROARDCAST_SEND_REG_ADDR = 0xFF0000; + + public static final int MOONCELL_FPGA_REG_ADDRESS_BASIC_STEP = 0x10000; + public static final int MOONCELL_FPGA_REG_ADDRESS_BASIC_SEND = 0x600000; + + public static final int MOONCELL_FPGA_REG_ADDRESS_BASIC_RECV = 0x680000; + + public static final int MOONCELL_FPGA_REG_ADDRESS_MULTI_PORT_STATUS = 0x710000; + + public static final int FGPA_UPDATE_ADD_BYTES = 100; + public static final int FGPA_UPDATE_PACKET_INTERVAL = 10; + + + + + public static final int FPGA_TYPE_ALTERA = 0; + public static final int FPGA_TYPE_ANLU = 1; + public static final int FPGA_TYPE_LATTICS= 2; + +// public static byte[] codehead = new byte[]{(byte) 0x9A,0x3D,0x00,0x01,0x10,(byte) 0xFF,0x2F,(byte) 0xFF,0x00,(byte) 0xF0,0x00,0x55,(byte) 0xDA,0x00,0x01,0x10,0x00,0x00,(byte) 0xBC,0x07,(byte) 0xFA,0x19,(byte) 0xA7,(byte) 0xDA,0x55,(byte) 0xEC,0x1F,(byte) 0x96,0x49,0x04}; + public static List codeheadbs = Arrays.asList( + new byte[]{(byte) 0x9A,0x3D,0x00,0x02,0x10,(byte) 0xFF, 0x0F,(byte) 0xFF,0x00,(byte)0xF0,0x00,0x55,(byte) 0xDA, 0x00, 0x01, 0x10, 0x00, 0x00, (byte) 0xB5, 0x4B, 0x4B, (byte) 0x98, 0x37, (byte) 0xFA, (byte) 0xEC, (byte) 0xDD, 0x05, 0x3B, 0x16, 0x04, 0x3E, (byte) 0xD2, 0x0B, 0x06}, + new byte[]{(byte) 0x9A,0x3D,0x00,0x01,0x10,(byte) 0xFF,0x2F,(byte) 0xFF,0x00,(byte) 0xF0,0x00,0x55,(byte) 0xDA,0x00,0x01,0x10,0x00,0x00,(byte) 0xBC,0x07,(byte) 0xFA,0x19,(byte) 0xA7,(byte) 0xDA,0x55,(byte) 0xEC,0x1F,(byte) 0x96,0x49,0x04}, + new byte[]{(byte) 0x9A,0x3D,0x00,0x02,0x10,(byte) 0xFF,0x0F,(byte) 0xFF,0x00,(byte) 0xF0,0x00,0x55,(byte) 0xDA,0x00,0x01,0x10,0x00,0x00,(byte) 0xB5,0x4B,0x4B,(byte) 0x98,(byte) 0x89,(byte) 0x93,(byte) 0x8A,0x60,0x5D,0x29,(byte) 0x9B,0x68,0x0E,0x48,0x7D,0x61}, + new byte[]{(byte) 0x9A,0x3D,0x00,0x01,0x10,(byte) 0xFF,0x2F,(byte) 0xFF,0x00,(byte) 0xF0,0x00,0x55,(byte) 0xDA,0x00,0x01,0x10,0x00,0x00,(byte) 0xBC,0x07,(byte) 0xFA,0x19,(byte) 0xA7,(byte) 0xDA,0x55,(byte) 0xEC,0x1F,(byte) 0x96,0x49,0x04}, + new byte[]{(byte) 0x9A,0x3D,0x00,0x02,0x10,(byte) 0xFF,0x0F,(byte) 0xFF,0x00,(byte) 0xF0,0x00,0x55,(byte) 0xDA,0x00,0x01,0x10,0x00,0x00,(byte) 0xB5,0x4B,0x4B,(byte) 0x98,0x3D,0x79,0x75,(byte) 0x9A,0x71,0x29,(byte) 0xB4,(byte) 0xA8,0x7E,(byte) 0xF8,0x55,0x0E}, + new byte[]{(byte) 0x9A,0x3D,0x00,0x01,0x10,(byte) 0xFF,0x2F,(byte) 0xFF,0x00,(byte) 0xF0,0x00,0x55,(byte) 0xDA,0x00,0x01,0x10,0x00,0x00,(byte) 0xBC,0x07,(byte) 0xFA,0x19,(byte) 0xA7,(byte) 0xDA,0x55,(byte) 0xEC,0x1F,(byte) 0x96,0x49,0x04}, + new byte[]{(byte) 0x9A,0x3D,0x00,0x02,0x10,(byte) 0xFF,0x0F,(byte) 0xFF,0x00,(byte) 0xF0,0x00,0x55,(byte) 0xDA,0x00,0x01,0x10,0x00,0x00,(byte) 0xB5,0x4B,0x4B,(byte) 0x98,(byte) 0xA3,0x33,0x1B,0x3D,(byte) 0xE5,0x07,(byte) 0xDE,0x43,(byte) 0xFC,0x4B,0x51,(byte) 0x92}, + new byte[]{(byte) 0x9A,0x3D,0x00,0x01,0x10,(byte) 0xFF,0x2F,(byte) 0xFF,0x00,(byte) 0xF0,0x00,0x55,(byte) 0xDA,0x00,0x01,0x10,0x00,0x00,(byte) 0xBC,0x07,(byte) 0xFA,0x19,(byte) 0xA7,(byte) 0xDA,0x55,(byte) 0xEC,0x1F,(byte) 0x96,0x49,0x04}, + new byte[]{(byte) 0x9A,0x3D,0x00,0x02,0x10,(byte) 0xFF,0x0F,(byte) 0xFF,0x00,(byte) 0xF0,0x00,0x55,(byte) 0xDA,0x00,0x01,0x10,0x00,0x00,(byte) 0xB5,0x4B,0x4B,(byte) 0x98,0x7A,(byte) 0xDC,(byte) 0xCD,0x4C,0x19,0x19,0x70,(byte) 0xBF,0x4E,(byte) 0xA3,(byte) 0xD4,0x23}, + new byte[]{(byte) 0x9A,0x3D,0x00,0x01,0x10,(byte) 0xFF,0x2F,(byte) 0xFF,0x00,(byte) 0xF0,0x00,0x55,(byte) 0xDA,0x00,0x01,0x10,0x00,0x00,(byte) 0xBC,0x07,(byte) 0xFA,0x19,(byte) 0xA7,(byte) 0xDA,0x55,(byte) 0xEC,0x1F,(byte) 0x96,0x49,0x04}, + new byte[]{(byte) 0x9A,0x3D,0x00,0x02,0x10,(byte) 0xFF,0x0F,(byte) 0xFF,0x00,(byte) 0xF0,0x00,0x55,(byte) 0xDA,0x00,0x01,0x10,0x00,0x00,(byte) 0xB5,0x4B,0x4B,(byte) 0x98,0x03,(byte) 0x9F,0x25,(byte) 0xA6,(byte) 0xE6,(byte) 0x8A,0x48,(byte) 0xD0,(byte) 0xFB,(byte) 0xEE,(byte) 0xB7,(byte) 0x87}, + new byte[]{(byte) 0x9A,0x3D,0x00,0x01,0x10,(byte) 0xFF,0x2F,(byte) 0xFF,0x00,(byte) 0xF0,0x00,0x55,(byte) 0xDA,0x00,0x01,0x10,0x00,0x00,(byte) 0xBC,0x07,(byte) 0xFA,0x19,(byte) 0xA7,(byte) 0xDA,0x55,(byte) 0xEC,0x1F,(byte) 0x96,0x49,0x04}, + new byte[]{(byte) 0x9A,0x3D,0x00,0x02,0x10,(byte) 0xFF,0x0F,(byte) 0xFF,0x00,(byte) 0xF0,0x00,0x55,(byte) 0xDA,0x00,0x01,0x10,0x00,0x00,(byte) 0xB5,0x4B,0x4B,(byte) 0x98,0x68,0x1E,(byte) 0xC1,0x0D,0x61,0x61,0x3D,0x21,(byte) 0x9F,(byte) 0xE7,(byte) 0xE3,(byte) 0xC5}, + new byte[]{(byte) 0x9A,0x3D,0x00,0x01,0x10,(byte) 0xFF,0x2F,(byte) 0xFF,0x00,(byte) 0xF0,0x00,0x55,(byte) 0xDA,0x00,0x01,0x10,0x00,0x00,(byte) 0xBC,0x07,(byte) 0xFA,0x19,(byte) 0xA7,(byte) 0xDA,0x55,(byte) 0xEC,0x1F,(byte) 0x96,0x49,0x04}, + new byte[]{(byte) 0x9A,0x3D,0x00,0x02,0x10,(byte) 0xFF,0x0F,(byte) 0xFF,0x00,(byte) 0xF0,0x00,0x55,(byte) 0xDA,0x00,0x01,0x10,0x00,0x00,(byte) 0xB5,0x4B,0x4B,(byte) 0x98,0x30,0x02,0x62,(byte) 0xAC,0x44,(byte) 0x98,0x04,(byte) 0xC6,0x76,(byte) 0x86,(byte) 0xC5,0x58}, + new byte[]{(byte) 0x9A,0x3D,0x00,0x01,0x10,(byte) 0xFF,0x2F,(byte) 0xFF,0x00,(byte) 0xF0,0x00,0x55,(byte) 0xDA,0x00,0x01,0x10,0x00,0x00,(byte) 0xBC,0x07,(byte) 0xFA,0x19,(byte) 0xA7,(byte) 0xDA,0x55,(byte) 0xEC,0x1F,(byte) 0x96,0x49,0x04}, + new byte[]{(byte) 0x9A,0x3D,0x00,0x02,0x10,(byte) 0xFF,0x0F,(byte) 0xFF,0x00,(byte) 0xF0,0x00,0x55,(byte) 0xDA,0x00,0x01,0x10,0x00,0x00,(byte) 0xB5,0x4B,0x4B,(byte) 0x98,0x6C,(byte) 0xE7,(byte) 0x80,0x17,(byte) 0xC4,0x31,(byte) 0x99,(byte) 0xDD,0x6C,0x76,(byte) 0xC4,(byte) 0x82}, + new byte[]{(byte) 0x9A,0x3D,0x00,0x01,0x10,(byte) 0xFF,0x2F,(byte) 0xFF,0x00,(byte) 0xF0,0x00,0x55,(byte) 0xDA,0x00,0x01,0x10,0x00,0x00,(byte) 0xBC,0x07,(byte) 0xFA,0x19,(byte) 0xA7,(byte) 0xDA,0x55,(byte) 0xEC,0x1F,(byte) 0x96,0x49,0x04}, + new byte[]{(byte) 0x9A,0x3D,0x00,0x02,0x10,(byte) 0xFF,0x0F,(byte) 0xFF,0x00,(byte) 0xF0,0x00,0x55,(byte) 0xDA,0x00,0x01,0x10,0x00,0x00,(byte) 0xB5,0x4B,0x4B,(byte) 0x98,(byte) 0x98,(byte) 0xF0,0x6E,0x17,(byte) 0x9C,0x6A,0x66,0x6A,0x31,0x11,0x3B,(byte) 0xC1}, + new byte[]{(byte) 0x9A,0x3D,0x00,0x01,0x10,(byte) 0xFF,0x2F,(byte) 0xFF,0x00,(byte) 0xF0,0x00,0x55,(byte) 0xDA,0x00,0x01,0x10,0x00,0x00,(byte) 0xBC,0x07,(byte) 0xFA,0x19,(byte) 0xA7,(byte) 0xDA,0x55,(byte) 0xEC,0x1F,(byte) 0x96,0x49,0x04} + ); + +} diff --git a/app/src/main/java/com/xixun/display/file/DiskType.java b/app/src/main/java/com/xixun/display/file/DiskType.java new file mode 100644 index 0000000..a51cf93 --- /dev/null +++ b/app/src/main/java/com/xixun/display/file/DiskType.java @@ -0,0 +1,49 @@ +package com.xixun.display.file; + +import com.xixun.display.MyApp; +import com.xixun.display.MyLog; +import com.xixun.display.R; + +public enum DiskType { + UNKNOW, + KERNEL, + CONFIG, + SIGNED, + TMP, + + HOME_FILES; + + public static DiskType findDiskType(int type) { + for (DiskType dt : DiskType.values()) { + if (dt.ordinal() == type) { + return dt; + } + } + MyLog.i("Unknow this disk type -> " + type); + return HOME_FILES; + } + + public String getPath() { + String path = null; + + switch (this) { + case KERNEL: + path = MyApp.getInstance().getString(R.string.card_kernel); + break; + case CONFIG: + path = MyApp.getInstance().getString(R.string.card_config); + break; + case SIGNED: + path = MyApp.getInstance().getString(R.string.card_signed); + break; + case TMP: + path = MyApp.getInstance().getString(R.string.card_tmp); + break; + default: + path = MyApp.getInstance().getFilesDir().getPath() + "/"; + break; + } + + return path; + } +} diff --git a/app/src/main/java/com/xixun/display/file/FilesOpr.java b/app/src/main/java/com/xixun/display/file/FilesOpr.java new file mode 100644 index 0000000..b29678b --- /dev/null +++ b/app/src/main/java/com/xixun/display/file/FilesOpr.java @@ -0,0 +1,30 @@ +package com.xixun.display.file; + +import android.content.Context; + +import com.xixun.display.MyApp; + + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +public class FilesOpr { + private final static Context context = MyApp.getInstance(); + + private FilesOpr() { } + public static byte[] readFileByte(File file, int len) { + try { + if (file.exists()) { + FileInputStream fis = new FileInputStream(file); + byte[] content = new byte[(len <= 0)? fis.available(): len]; + fis.read(content); + fis.close(); + return content; + } + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } +} diff --git a/app/src/main/java/com/xixun/display/ledset/NetPacket.java b/app/src/main/java/com/xixun/display/ledset/NetPacket.java new file mode 100644 index 0000000..16ff521 --- /dev/null +++ b/app/src/main/java/com/xixun/display/ledset/NetPacket.java @@ -0,0 +1,71 @@ +package com.xixun.display.ledset; + +public class NetPacket { + boolean send; + private byte[] head; + private byte[] serialNum; + private byte[] groupNum; + private byte[] reserve; + private int contentLen; + private byte[] content; + private byte checkCode; + + public NetPacket() { + + } + + NetPacket(byte[] cmd) { + + } + + public boolean getIsSend() { + return send; + } + + public void setSend(boolean send) { + this.send = send; + } + + public byte[] getHead() { + return head; + } + public void setHead(byte[] head) { + this.head = head; + } + public void setHead(int index, byte value) { + head[index] = value; + } + + public int getContentLen() { + return contentLen; + } + public void setContentLen(int contentLen) { + this.contentLen = contentLen; + } + + public byte[] getContent() { + return content; + } + public void setContent(byte[] content) { + this.content = content; + } + + public byte getCheckCode() { + return checkCode; + } + public void setCheckCode(byte checkCode) { + this.checkCode = checkCode; + } + + private byte getSumByte(byte[] field) { + byte sum = 0; + + if (null != field) { + for (int i = 0; i < field.length; ++i) { + sum += field[i]; + } + } + + return sum; + } +} diff --git a/app/src/main/java/com/xixun/display/ledset/ServerTCP.java b/app/src/main/java/com/xixun/display/ledset/ServerTCP.java new file mode 100644 index 0000000..0483b53 --- /dev/null +++ b/app/src/main/java/com/xixun/display/ledset/ServerTCP.java @@ -0,0 +1,172 @@ +package com.xixun.display.ledset; + +import com.xixun.display.MyApp; +import com.xixun.display.MyLog; +import com.xixun.display.domain.Variable; +import com.xixun.display.utils.DisplayConfig; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.Socket; +import java.util.ArrayList; +import java.util.List; + +//作为客户端 +public class ServerTCP implements Runnable{ + public static String SERVICE_IP = ""; + public static String service_ip = ""; + public static boolean isConnected = false; + public Socket mySocket = null; + public DataInputStream receStream=null; + public DataOutputStream sendStream=null; + List list = new ArrayList<>(); + + + public ServerTCP(String service_ip) { + this.service_ip = service_ip; + } + + public void start() { + new Thread(new Runnable() { + @SuppressWarnings("resource") + public void run() { + MyLog.i("Start ServerTCP ..."); + try { +// if (!list.contains(ipAddr)){ +// list.add(ipAddr); +// if (!checkConnect()){ + if (mySocket!=null){ + MyLog.i("close..........................."); + isConnected = false; + mySocket.close(); + return; + } + mySocket = new Socket(); + mySocket.setReceiveBufferSize(8192);//tcp缓存 + MyLog.i("connect ServerTCP ..."+service_ip); + mySocket.connect(new InetSocketAddress(service_ip, Variable.TCP_PORT)); + mySocket.setKeepAlive(true); + mySocket.setTcpNoDelay(true); + MyLog.i("isConnected:"+mySocket.isConnected()); + isConnected = mySocket.isConnected(); +// new Connection(socket).start(); + redlyRead(); +// } +// }else { +// MyLog.i("socket is Connected..."); +// } + }catch (Exception e){ + try { + mySocket.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + e.printStackTrace(); + } + } + }).start(); + } + + private void redlyRead() { + new Thread(new Runnable() { + @SuppressWarnings("resource") + public void run() { + try { + receStream=new DataInputStream(mySocket.getInputStream()); + sendStream=new DataOutputStream(mySocket.getOutputStream()); + byte[] data=new byte[2048]; + while (true){ + int len=0; + if ((len=receStream.read(data))!=-1){ + byte[] newData = new byte[len]; + System.arraycopy(data,0,newData,0,len); +// MyLog.showBytes("receDataFromPC:",newData,0); + MyApp.card().receDataFromPC(newData,sendStream); + } + } + } catch (IOException e) { + try { + sendStream.close(); + mySocket.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + e.printStackTrace(); + }finally { + try { + receStream.close(); + sendStream.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } + }).start(); + } + + @Override + public void run() { + start(); + /*NetPacket packet = new NetPacket(); + MyLog.showBytes("packet.getData",packet.getContent(),0); + try { + list.clear(); + isConnected = false; + socket.close(); + } catch (IOException e) { + e.printStackTrace(); + } + *//*while (socket!=null && !socket.isConnected()){ + try { + MyLog.i("try connect ..."); + socket.connect(new InetSocketAddress(SERVICE_IP, port)); + }catch (Exception e){ + e.printStackTrace(); + } + }*//* + //封装数据 +// dealData(packet.getContent()); + //请求接口*/ + } + + + private class Connection extends Thread { + private Socket socket; + + Connection(Socket socket) { + try { + this.socket = socket; + receStream=new DataInputStream(socket.getInputStream()); + sendStream=new DataOutputStream(socket.getOutputStream()); + byte[] data=new byte[2048]; + while (true){ + int len=receStream.read(data); +// MyLog.d("len1===="+len); + byte[] newData = new byte[len]; + System.arraycopy(data,0,newData,0,len); +// MyLog.i("starttime:"+System.currentTimeMillis()); +// MyLog.showBytes("receDataFromPC:",newData,0); + MyApp.card().receDataFromPC(newData,sendStream); + } +// socket.close(); + } catch (IOException e) { + e.printStackTrace(); +// reconnect(); + }finally { + } + } + } + + private boolean checkConnect(){ + try { + mySocket.sendUrgentData(0xFF); // 发送心跳包 + MyLog.i("目前是处于链接状态!"); + return true; + }catch (Exception e){ + MyLog.i("目前是处于断开状态!"); + return false; + } + } +} diff --git a/app/src/main/java/com/xixun/display/ledset/ServerTCP_S.java b/app/src/main/java/com/xixun/display/ledset/ServerTCP_S.java new file mode 100644 index 0000000..9e62767 --- /dev/null +++ b/app/src/main/java/com/xixun/display/ledset/ServerTCP_S.java @@ -0,0 +1,195 @@ +package com.xixun.display.ledset; + +import com.xixun.display.MyApp; +import com.xixun.display.MyLog; +import com.xixun.display.domain.Variable; +import com.xixun.display.utils.DisplayConfig; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.InetSocketAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +//作为服务端 +public class ServerTCP_S implements Runnable{ + public Socket mySocket = null; + public ServerSocket serverSocket = null; + public DataInputStream receStream=null; + public DataOutputStream sendStream=null; + public Socket client = null; + List list = new ArrayList<>(); + byte[] receData = new byte[2048]; + + public void start() { + try { + serverSocket = new ServerSocket(); + serverSocket.setReceiveBufferSize(8192);//tcp缓存 + serverSocket.bind(new InetSocketAddress(Variable.TCP_PORT_S));//绑定端口 + while(true){ + MyLog.i("Start ServerTCP_S ..."); + client = serverSocket.accept();//这里是阻塞方法 + String clientAddr = client.getInetAddress().getHostAddress(); + System.out.println("服务器端已经启动,等待客户端请求......"+clientAddr); + serverSocket.setReuseAddress(true);//设置为可复用 + new Thread(new TaskTCP(client)).start(); + } + }catch (Exception e){ + try { + serverSocket.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + e.printStackTrace(); + } + } + + private boolean isXixunCommand(byte[] heads) { + return Arrays.equals(heads, new byte[]{0x7e, 0x7e, 0x55}); + } + + @Override + public void run() { + start(); + } + + private class TaskTCP implements Runnable { + private Socket client; + + public TaskTCP(Socket client) { + this.client = client; + } + + @Override + public void run() { + try { + receStream=new DataInputStream(client.getInputStream()); + sendStream=new DataOutputStream(client.getOutputStream()); + while(true) { + //协议长度是正文数据长度+协议固定长度12 + int length = receStream.read(receData);//有效数据长度 + if (length>0){ + byte[] newData = new byte[length]; + System.arraycopy(receData,0,newData,0,length); +// MyLog.showBytes("initdata",newData,0); + dealWithDataBuffer(newData); + + + /*byte[] heads = new byte[3]; + System.arraycopy(newData,0,heads,0,heads.length); + if (isXixunCommand(heads)){ + DisplayConfig.saveProtocolType(1); + //校验 + byte[] sendDataCheckCode = new byte[4]; + System.arraycopy(newData,newData.length-4,sendDataCheckCode,0,sendDataCheckCode.length); + long checkCode = MyApp.bytesToLong(sendDataCheckCode);//数据段里的校验码 + byte[] crcData = new byte[newData.length-4]; + System.arraycopy(newData,0,crcData,0,crcData.length); + long crcCode = MyApp.crc32(crcData);//通过数据计算出来的校验码 + MyLog.i("checkCode:"+checkCode+";crcCode:"+crcCode); + if (checkCode == crcCode){ + //校验通过 + MyApp.card().receDataFromPC_Xixun(newData,sendStream); + }else { + MyLog.e("crc code error"); + } + }*/ + } + } + } catch (Exception e) { + // TODO: handle exception + e.printStackTrace(); + try { + receStream.close(); + sendStream.close(); + client.close(); + }catch (Exception el){ + el.printStackTrace(); + } + }finally { + try { + receStream.close(); + sendStream.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } + byte[] hendData = null; + /** + * 处理粘包拆包的问题 + * @return + */ + public void dealWithDataBuffer(byte[] data){ + byte[] heads = new byte[3]; + System.arraycopy(data,0,heads,0,heads.length); + if (data.length>=12){ + //获取包头 + if (isXixunCommand(heads)){//包头对 + sendDataTrue(data); + } else { + //包头不对,尾部数据,少包了,拼接上一次余下的数据,,拼接之后还得进入到此方法进行拆包操作 +// splicingData(data); + } + } + } + + private void sendDataTrue(byte[] data) { + byte[] totalData = data; + int dataLenth = 0; +// MyLog.i("111111totalData.length"+totalData.length); + if (totalData.length>=12){ + byte[] dataLength_b = {data[6],data[7]}; + int dataLength_i = MyApp.bytesToInt(dataLength_b,false); + dataLenth = dataLength_i+12; +// dataLenth = getDataLenth(totalData)+12; +// MyLog.i("111111dataLenth"+dataLenth); + if (dataLenth>totalData.length){ + //说明进来的数据长度不够,属于残包,需要等待下一次进来的数据进行组合 + hendData = totalData; + return; + } + }else { + hendData = totalData; + return; + } + //按现有长度获取到的数据 + byte[] sendData = new byte[dataLenth]; + System.arraycopy(totalData,0,sendData,0,dataLenth); +// MyLog.showBytes("获取默认的数据",sendData,0); + //获取正常的数据 + sendData = new byte[dataLenth]; + System.arraycopy(totalData,0,sendData,0,dataLenth); +// MyLog.showBytes("sendData",sendData,0); + //校验 + //获取到 + byte[] sendDataCheckCode = new byte[4]; + System.arraycopy(sendData,sendData.length-4,sendDataCheckCode,0,sendDataCheckCode.length); + long checkCode = MyApp.bytesToLong(sendDataCheckCode);//数据段里的校验码 + byte[] crcData = new byte[sendData.length-4]; + System.arraycopy(sendData,0,crcData,0,crcData.length); + long crcCode = MyApp.crc32(crcData);//通过数据计算出来的校验码 + MyLog.i("checkCode:"+checkCode+";crcCode:"+crcCode); + //发送 + if (checkCode == crcCode){ + //校验通过 +// MyLog.showBytes("sendData",sendData,0); + MyApp.card().receDataFromPC_Xixun(sendData,sendStream); + }else { + MyLog.e("crc code error"); + } + //递归处理余下的数据 + if (totalData.length>dataLenth){ + byte[] tempData = new byte[totalData.length-sendData.length]; + System.arraycopy(totalData,dataLenth,tempData,0,tempData.length); + sendDataTrue(tempData); + } + } + } +} diff --git a/app/src/main/java/com/xixun/display/ledset/ServerUDP.java b/app/src/main/java/com/xixun/display/ledset/ServerUDP.java new file mode 100644 index 0000000..17ce755 --- /dev/null +++ b/app/src/main/java/com/xixun/display/ledset/ServerUDP.java @@ -0,0 +1,114 @@ +package com.xixun.display.ledset; + +import com.xixun.display.MyApp; +import com.xixun.display.MyLog; +import com.xixun.display.domain.Variable; + +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.SocketException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ServerUDP { + private static int UDP_LEN = 64; + private DatagramSocket server = null; + private int netType = 0; + public static boolean START_TCP = false; +// public ServerTCP serverTCP = new ServerTCP(); + public Map ipMap = new HashMap(); + List list = new ArrayList<>(); + + public void start() { + new Thread(new Runnable() { + public void run() { + MyLog.i("Start ServerUDP ..."); + try { +// MyApp.verfyOver.await(10, TimeUnit.SECONDS); + server = new DatagramSocket(Variable.UDP_PORT); +// MyLog.i("Start server for receive ledset command(UDP)111 ..."); + while (!server.isClosed()) { +// MyLog.i("Start server for receive ledset command(UDP)222 ..."); + DatagramPacket packet = new DatagramPacket(new byte[UDP_LEN], UDP_LEN); + server.receive(packet); + MyApp.executeThread(new TaskUDP(packet)); + Thread.sleep(100); + } + } catch (SocketException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + server.close(); + } + } + }).start(); + } + + private class TaskUDP implements Runnable { + private DatagramPacket packet; + + public TaskUDP(DatagramPacket packet) { + this.packet = packet; + } + + @Override + public void run() { + try{ + boolean hasIp = false; + MyLog.i("ip+port:"+packet.getAddress()+":"+packet.getPort()); + //收到的udp数据 + byte[] udpData = packet.getData(); + MyLog.showBytes("packet.getData",udpData,0); + String msg = new String(udpData); + MyLog.i("msg..."+msg); + //判断数据有效性 + if (0xA5==(udpData[16]&0xff)){ + //获取ip的数量 + int ipSum = udpData[19]; + //获取到所有的ip + byte[] ip_index_3_s = new byte[ipSum]; + System.arraycopy(udpData,20,ip_index_3_s,0,ipSum); +// MyLog.showBytes("所有已连接的ip",ip_index_3_s,0); + + //本机IP + List localIps = MyApp.getIpAddressString(); + for (String localIp : localIps) { +// MyLog.i("本机IP:"+localIp); + //获取IP最后地址 + String[] ips = localIp.split("\\."); + int ip_index_3 = Integer.parseInt(ips[3]); +// MyLog.i("ip_index_3:"+ip_index_3); + //判断是否包含本机ip + for (byte ip:ip_index_3_s){ + MyLog.i("ip=========:"+(ip&0xff)); + if (ip_index_3 == (ip&0xff)){ +// MyLog.i("包含本机ip:"+ip_index_3+",证明已连接!"); + hasIp = true; + break; + } + } + if (hasIp){ + break; + } + } + String service_ip =packet.getAddress().getHostAddress(); + MyLog.i("service_ip:"+service_ip); + //收到广播之后判断是否连接 + + if (!hasIp){ + MyApp.executeThread(new ServerTCP(service_ip)); + } + }else { + MyLog.i("无效udp数据..."); + } + + }catch (Exception e){ + e.printStackTrace(); + } + } + } + +} diff --git a/app/src/main/java/com/xixun/display/screenshow/CardView.java b/app/src/main/java/com/xixun/display/screenshow/CardView.java new file mode 100644 index 0000000..4602f09 --- /dev/null +++ b/app/src/main/java/com/xixun/display/screenshow/CardView.java @@ -0,0 +1,100 @@ +package com.xixun.display.screenshow; + +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.Point; +import android.os.Handler; +import android.view.View; + +import com.xixun.display.MyLog; + +public class CardView extends View implements Runnable { + private Context context; + private StringBuilder cardInfo; + private Handler handler; + private Point curPoint; + private Paint paint; + private PageParams params; + private Rectangles rectangles; + private Lines lines; + + public CardView(Context context) { + super(context); + } + + public CardView(Context context, PageParams params) { + super(context); + try { + this.context = context; + this.params = params; + handler = new Handler(); + paint = new Paint(); + curPoint = new Point(); + this.setWillNotDraw(false); + } catch (Exception e) { + e.printStackTrace(); + } + } + private void showRectangle(Rectangles rectangles) { +// int rectangleNum = rectangles.getRectangleNum(); +// int rectangleColor = rectangles.getRectangleColor(); + + } + + @Override + protected void onDraw(Canvas canvas) { + PageUI pageUI = params.getPage(); + setBackgroundColor(params.getColor()); + switch (pageUI){ + case SHOW_BLOCK://显示块 + break; + case SHOW_RECTANGLE://矩形 + this.rectangles =params.getRectangles(); + //绘制矩形 + paint.setColor(rectangles.getRectangleColor()); + for(Rectangle rectangle :rectangles.getRectangleList()){ + MyLog.i("矩形:("+rectangle.getRectangleSX()+","+rectangle.getRectangleSY()+")->("+rectangle.getRectangleWidth()+","+rectangle.getRectangleHeight()+")"); +// RectF rectF=new RectF(rectangle.getRectangleSX(),rectangle.getRectangleSY(),rectangle.getRectangleWidth(),rectangle.getRectangleHeight()); + canvas.drawRect(rectangle.getRectangleSX(), rectangle.getRectangleSY(), rectangle.getRectangleWidth(), rectangle.getRectangleHeight(), paint); +// canvas.drawRect(rectF, paint); + } + break; + case SHOW_LINE://直线 + this.lines = params.getLines(); + paint.setColor(lines.getLineColor()); + paint.setStrokeWidth(lines.getLineWidth()); + for(Line line :lines.getLineList()){ + MyLog.i("直线:("+line.getLineSX()+","+line.getLineSY()+")->("+line.getLineEX()+","+line.getLineEY()+")"); + canvas.drawLine(line.getLineSX(), line.getLineSY(), line.getLineEX(), line.getLineEY(), paint); + } + break; + case SHOW_NOTHING://什么都不显示 + break; + default: + break; + } + } + + public void flush(PageParams params) { + try { + this.params = params; + handler.removeCallbacks(this); +// initView(params); + this.postInvalidate(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + public void run() { + // TODO Auto-generated method stub +// MyLog.i("run ..."); +// if ((0 == color) && params.get(0).getPage() == PageUI.SHOW_GRAY) { +// MyApp.sleepForSecond(1); +// } + this.postInvalidate(); +// handler.postDelayed(this, settleTime); + } +} diff --git a/app/src/main/java/com/xixun/display/screenshow/Line.java b/app/src/main/java/com/xixun/display/screenshow/Line.java new file mode 100644 index 0000000..9144698 --- /dev/null +++ b/app/src/main/java/com/xixun/display/screenshow/Line.java @@ -0,0 +1,48 @@ +package com.xixun.display.screenshow; + +public class Line { + private int lineSX; //起点横坐标 + private int lineSY; //起点纵坐标 + private int lineEX; //终点横坐标 + private int lineEY; //终点纵坐标 + + public Line(int lineSX, int lineSY, int lineEX, int lineEY) { + this.lineSX = lineSX; + this.lineSY = lineSY; + this.lineEX = lineEX; + this.lineEY = lineEY; + } + + public int getLineSX() { + return lineSX; + } + + public void setLineSX(int lineSX) { + this.lineSX = lineSX; + } + + public int getLineSY() { + return lineSY; + } + + public void setLineSY(int lineSY) { + this.lineSY = lineSY; + } + + public int getLineEX() { + return lineEX; + } + + public void setLineEX(int lineEX) { + this.lineEX = lineEX; + } + + public int getLineEY() { + return lineEY; + } + + public void setLineEY(int lineEY) { + this.lineEY = lineEY; + } +} + diff --git a/app/src/main/java/com/xixun/display/screenshow/Lines.java b/app/src/main/java/com/xixun/display/screenshow/Lines.java new file mode 100644 index 0000000..1a13db5 --- /dev/null +++ b/app/src/main/java/com/xixun/display/screenshow/Lines.java @@ -0,0 +1,52 @@ +package com.xixun.display.screenshow; + +import java.util.ArrayList; +import java.util.List; + +public class Lines { + private int lineNum; //直线总数量 + private int lineColor; //颜色 + private int lineWidth; //线宽 + private List lineList ; + + + public Lines(int lineNum, int lineColor, int lineWidth) { + this.lineNum = lineNum; + this.lineColor = lineColor; + this.lineWidth = lineWidth; + this.lineList = new ArrayList<>(); + } + + public int getLineNum() { + return lineNum; + } + + public void setLineNum(int lineNum) { + this.lineNum = lineNum; + } + + public int getLineColor() { + return lineColor; + } + + public void setLineColor(int lineColor) { + this.lineColor = lineColor; + } + + public int getLineWidth() { + return lineWidth; + } + + public void setLineWidth(int lineWidth) { + this.lineWidth = lineWidth; + } + + public List getLineList() { + return lineList; + } + + public void setLineList(List lineList) { + this.lineList = lineList; + } +} + diff --git a/app/src/main/java/com/xixun/display/screenshow/PageParams.java b/app/src/main/java/com/xixun/display/screenshow/PageParams.java new file mode 100644 index 0000000..dd89b9d --- /dev/null +++ b/app/src/main/java/com/xixun/display/screenshow/PageParams.java @@ -0,0 +1,108 @@ +package com.xixun.display.screenshow; + +import android.graphics.Point; + +import com.xixun.display.MyApp; + +public class PageParams { + private PageUI page; //view类型 普通,画矩形,画直线 + private Point start; //窗口开始坐标 + private Point end; //窗口结束坐标 + private int color; //窗口背景颜色 + private Lines lines; //直线 + private Rectangles rectangles; //矩形 + + public PageParams() { + + } + public PageParams(PageUI page) { + setPage(page); + setStart(new Point(0, 0)); + setEnd(MyApp.getMaxSize()); + } + + public PageParams(PageUI page, Point start, Point end, int color) { + this.page = page; + this.start = start; + this.end = end; + this.color = color; + } + + public PageUI getPage() { + return page; + } + + public void setPage(PageUI page) { + this.page = page; + } + + public Point getStart() { + return start; + } + + public void setStart(Point point) { + /*try { + Point maxSize = MyApp.getMaxSize(); + start = new Point(); + start.x = Math.min(maxSize.x, point.x); + start.y = Math.min(maxSize.y, point.y); + } catch (Exception e) { + e.printStackTrace(); + }*/ + this.start = point; + } + + public Point getEnd() { + return end; + } + + public void setEnd(Point point) { + /*try { + Point maxSize = MyApp.getMaxSize(); + end = new Point(); + end.x = Math.min(maxSize.x, point.x + 1); + end.y = Math.min(maxSize.y, point.y); + } catch (Exception e) { + e.printStackTrace(); + }*/ + this.end = point; + } + + public int getColor() { + return color; + } + + public void setColor(int color) { + this.color = color; + } + + public Lines getLines() { + return lines; + } + + public void setLines(Lines lines) { + this.lines = lines; + } + + public Rectangles getRectangles() { + return rectangles; + } + + public void setRectangles(Rectangles rectangles) { + this.rectangles = rectangles; + } + + + @Override + public String toString() { + return "PageParams{" + + "page=" + page + + ", start=" + start + + ", end=" + end + + ", color=" + color + + ", lines=" + lines + + ", rectangles=" + rectangles + + '}'; + } +} + diff --git a/app/src/main/java/com/xixun/display/screenshow/PageUI.java b/app/src/main/java/com/xixun/display/screenshow/PageUI.java new file mode 100644 index 0000000..8095b12 --- /dev/null +++ b/app/src/main/java/com/xixun/display/screenshow/PageUI.java @@ -0,0 +1,17 @@ +package com.xixun.display.screenshow; + +public enum PageUI { + SHOW_BLOCK,//块 + SHOW_RECTANGLE,//矩形 + SHOW_LINE,//直线 + SHOW_NOTHING; + + public static PageUI findByIndex(int index) { + for (PageUI ui : values()) { + if (index == ui.ordinal()) { + return ui; + } + } + return SHOW_NOTHING; + } +} diff --git a/app/src/main/java/com/xixun/display/screenshow/Rectangle.java b/app/src/main/java/com/xixun/display/screenshow/Rectangle.java new file mode 100644 index 0000000..c143345 --- /dev/null +++ b/app/src/main/java/com/xixun/display/screenshow/Rectangle.java @@ -0,0 +1,48 @@ +package com.xixun.display.screenshow; + +public class Rectangle { + private int rectangleSX; //起点横坐标 + private int rectangleSY; //起点纵坐标 + private int rectangleWidth; //宽度 + private int rectangleHeight; //高度 + + public Rectangle(int rectangleSX, int rectangleSY, int rectangleWidth, int rectangleHeight) { + this.rectangleSX = rectangleSX; + this.rectangleSY = rectangleSY; + this.rectangleWidth = rectangleWidth; + this.rectangleHeight = rectangleHeight; + } + + public int getRectangleSX() { + return rectangleSX; + } + + public void setRectangleSX(int rectangleSX) { + this.rectangleSX = rectangleSX; + } + + public int getRectangleSY() { + return rectangleSY; + } + + public void setRectangleSY(int rectangleSY) { + this.rectangleSY = rectangleSY; + } + + public int getRectangleWidth() { + return rectangleWidth; + } + + public void setRectangleWidth(int rectangleWidth) { + this.rectangleWidth = rectangleWidth; + } + + public int getRectangleHeight() { + return rectangleHeight; + } + + public void setRectangleHeight(int rectangleHeight) { + this.rectangleHeight = rectangleHeight; + } +} + diff --git a/app/src/main/java/com/xixun/display/screenshow/Rectangles.java b/app/src/main/java/com/xixun/display/screenshow/Rectangles.java new file mode 100644 index 0000000..dcb6f42 --- /dev/null +++ b/app/src/main/java/com/xixun/display/screenshow/Rectangles.java @@ -0,0 +1,41 @@ +package com.xixun.display.screenshow; + +import java.util.ArrayList; +import java.util.List; + +public class Rectangles { + private int rectangleNum; //矩形总数量 + private int rectangleColor; // + private List rectangleList; + + public Rectangles(int rectangleNum, int rectangleColor) { + this.rectangleNum = rectangleNum; + this.rectangleColor = rectangleColor; + this.rectangleList = new ArrayList<>(); + } + + public int getRectangleNum() { + return rectangleNum; + } + + public void setRectangleNum(int rectangleNum) { + this.rectangleNum = rectangleNum; + } + + public int getRectangleColor() { + return rectangleColor; + } + + public void setRectangleColor(int rectangleColor) { + this.rectangleColor = rectangleColor; + } + + public List getRectangleList() { + return rectangleList; + } + + public void setRectangleList(List rectangleList) { + this.rectangleList = rectangleList; + } +} + diff --git a/app/src/main/java/com/xixun/display/screenshow/TopWindow.java b/app/src/main/java/com/xixun/display/screenshow/TopWindow.java new file mode 100644 index 0000000..7574c97 --- /dev/null +++ b/app/src/main/java/com/xixun/display/screenshow/TopWindow.java @@ -0,0 +1,232 @@ +package com.xixun.display.screenshow; + +import android.annotation.SuppressLint; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.graphics.PixelFormat; +import android.graphics.Point; +import android.os.Handler; +import android.os.Message; +import android.view.Gravity; +import android.view.LayoutInflater; +import android.view.MotionEvent; +import android.view.View; +import android.view.View.OnGenericMotionListener; +import android.view.View.OnTouchListener; +import android.view.WindowManager; +import android.view.WindowManager.LayoutParams; + + +import com.xixun.display.MyApp; +import com.xixun.display.MyLog; +import com.xixun.display.R; +import com.xixun.smartled.mainkit.MainThreadKit; + +import java.util.Stack; + +@SuppressLint({ "HandlerLeak", "SimpleDateFormat" }) +public class TopWindow { + private static TopWindow instance; + + private static final int SHOW_CUSTOM_VIEW = 0; + private static final int POP_STACK_VIEW = 1; + private static final int UPDATE_TOP_VIEW = 2; + private static final int REMOVE_TOP_VIEW = 3; + + private static WindowManager wm; + private static Stack viewStack; + private static LayoutParams topLayout; + private static View mainWindow; + private static Handler handler; + private static CardView customView; + private Point lastPoint = new Point(); + + private TopWindow() { + MainThreadKit.runOnMainThreadAsync(new Runnable() { + @Override + public void run() { + try { + MyLog.i("Create top window ..."); + wm = (WindowManager) MyApp.getInstance().getSystemService(Context.WINDOW_SERVICE); + viewStack = new Stack(); + createMainWindow(1.0f); + handler = createHandler(); + customView = null; + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + + public static TopWindow getInstance() { + if (null == instance) { + instance = new TopWindow(); + } + return instance; + } + + public void init() { } + + public synchronized void changePage(final PageParams params) { + MainThreadKit.runOnMainThreadSync(new Runnable() { + @Override + public void run() { + Message msg = Message.obtain(); +// msg.what = SHOW_CUSTOM_VIEW; + msg.obj = params; + handler.sendMessage(msg); + } + }); + } + @SuppressLint("InflateParams") + private void createMainWindow(float alpha) { + LayoutInflater inflater = LayoutInflater.from(MyApp.getInstance()); + + topLayout = createLayout(new Point(), MyApp.getMaxSize(), alpha); + mainWindow = inflater.inflate(R.layout.main, null); + mainWindow.setLayerType(View.LAYER_TYPE_HARDWARE, null); +// surfaceView = (SurfaceView) mainWindow.findViewById(R.id.surfaceView); + mainWindow.setOnGenericMotionListener(new OnGenericMotionListener() { + @Override + public boolean onGenericMotion(View v, MotionEvent event) { + try { + switch (event.getButtonState()) { + case MotionEvent.ACTION_DOWN: + break; + case MotionEvent.ACTION_SCROLL: + case MotionEvent.BUTTON_SECONDARY: + removeTopView(); + break; + default: + break; + } + } catch (Exception e) { + e.printStackTrace(); + } + + return false; + } + }); + MyApp.getInstance().registerReceiver(new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + if (action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) { + removeTopView(); + } + } + }, new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); + viewStack.push(mainWindow); + wm.addView(mainWindow, topLayout); + } + + public synchronized void removeTopView() { + MyLog.i("removeTopView......"); + Message msg = Message.obtain(); + + msg.what = REMOVE_TOP_VIEW; + handler.sendMessage(msg); + } + + private LayoutParams createLayout(Point start, Point size, float alpha) { + LayoutParams layout = new LayoutParams(); + layout.x = start.x; + layout.y = start.y; + layout.width = size.x; + layout.height = size.y; + layout.gravity = Gravity.LEFT | Gravity.TOP; + layout.type = LayoutParams.TYPE_SYSTEM_OVERLAY;//修复关屏覆盖不了conn发的顶层网页节目 + layout.flags = LayoutParams.FLAG_LAYOUT_IN_SCREEN; + //layout.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN; + layout.format = PixelFormat.TRANSLUCENT; + layout.alpha = alpha; + return layout; + } + + @SuppressWarnings("unchecked") + private void execCustomView(Object obj) { + PageParams params = (PageParams) obj; + if (PageUI.SHOW_NOTHING == params.getPage()){ + if (null != customView) { + wm.removeViewImmediate(customView); + customView = null; + } + }else { +// Point maxSize = MyApp.getMaxSize(); +// topLayout.width = maxSize.x; +// topLayout.height = maxSize.y; +// topLayout.alpha = 1.0f; + if (null == customView) { +// if (true) { + customView = new CardView(MyApp.getInstance(), params); +// customView.setLayerType(View.LAYER_TYPE_HARDWARE, null);//px30测试斜线时有暗亮 + setViewTouchListener(customView); + LayoutParams layoutParams = createLayout(new Point(), MyApp.getMaxSize(), 1.0f); + wm.addView(customView, layoutParams); + } else { + customView.flush(params); + } + } + } + + @SuppressLint("HandlerLeak") + private Handler createHandler() { + Handler handler = new Handler() { + @Override + public void handleMessage(Message msg) { + View view = null; + try { + switch (msg.what) { + case SHOW_CUSTOM_VIEW: + execCustomView(msg.obj); + break; + case POP_STACK_VIEW: + view = viewStack.pop(); + wm.addView(view, (LayoutParams)msg.obj); + viewStack.push(view); + break; + case UPDATE_TOP_VIEW: + view = viewStack.pop(); + wm.updateViewLayout(view, (LayoutParams)msg.obj); + viewStack.push(view); + break; + case REMOVE_TOP_VIEW: + if (!viewStack.isEmpty()) { + wm.removeViewImmediate(viewStack.pop()); + } + break; + default: + break; + } + } catch (Exception e) { + e.printStackTrace(); + } + } + }; + return handler; + } + + private void setViewTouchListener(View view) { + view.setOnTouchListener(new OnTouchListener() { + @SuppressLint("ClickableViewAccessibility") @Override + public boolean onTouch(View v, MotionEvent event) { + if (MotionEvent.ACTION_SCROLL == event.getButtonState()) { + removeTopShowUI(); + while(!viewStack.isEmpty()) { + wm.removeViewImmediate(viewStack.pop()); + } + } + return false; + } + }); + } + private void removeTopShowUI() { + if (null != customView) { + wm.removeViewImmediate(customView); + customView = null; + } + } +} diff --git a/app/src/main/java/com/xixun/display/utils/Base64.java b/app/src/main/java/com/xixun/display/utils/Base64.java new file mode 100644 index 0000000..5f50da2 --- /dev/null +++ b/app/src/main/java/com/xixun/display/utils/Base64.java @@ -0,0 +1,108 @@ +package com.xixun.display.utils; + +import java.lang.reflect.Method; + +/** + * Created by Administrator on 2018/08/18. + */ + +public class Base64 { + + /** + * writer: huhx + */ + private static final String CODES = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; + + // base64解密 + public static byte[] base64Decode(String input) { + if (input.length() % 4 != 0) { + input=input.substring(0,input.length()-input.length() % 4); + //throw new IllegalArgumentException("Invalid base64 input"); + } + byte decoded[] = new byte[((input.length() * 3) / 4) - (input.indexOf('=') > 0 ? (input.length() - input.indexOf('=')) : 0)]; + char[] inChars = input.toCharArray(); + int j = 0; + int b[] = new int[4]; + for (int i = 0; i < inChars.length; i += 4) { + // This could be made faster (but more complicated) by precomputing + // these index locations. + b[0] = CODES.indexOf(inChars[i]); + b[1] = CODES.indexOf(inChars[i + 1]); + b[2] = CODES.indexOf(inChars[i + 2]); + b[3] = CODES.indexOf(inChars[i + 3]); + decoded[j++] = (byte) ((b[0] << 2) | (b[1] >> 4)); + if (b[2] < 64) { + decoded[j++] = (byte) ((b[1] << 4) | (b[2] >> 2)); + if (b[3] < 64) { + decoded[j++] = (byte) ((b[2] << 6) | b[3]); + } + } + } + return decoded; + } + + // base64加密 + public static String base64Encode(byte[] in) { + StringBuilder out = new StringBuilder((in.length * 4) / 3); + int b; + for (int i = 0; i < in.length; i += 3) { + b = (in[i] & 0xFC) >> 2; + out.append(CODES.charAt(b)); + b = (in[i] & 0x03) << 4; + if (i + 1 < in.length) { + b |= (in[i + 1] & 0xF0) >> 4; + out.append(CODES.charAt(b)); + b = (in[i + 1] & 0x0F) << 2; + if (i + 2 < in.length) { + b |= (in[i + 2] & 0xC0) >> 6; + out.append(CODES.charAt(b)); + b = in[i + 2] & 0x3F; + out.append(CODES.charAt(b)); + } else { + out.append(CODES.charAt(b)); + out.append('='); + } + } else { + out.append(CODES.charAt(b)); + out.append("=="); + } + } + return out.toString(); + } + + public static void main(String[] args) { + String input = "I love you, huhx!"; + String encode = base64Encode(input.getBytes()); + System.out.println("encode: " + encode); + + String decode = new String(base64Decode(encode)); + System.out.println("decode: " + decode); + } + + + /*** + * encode by Base64 + */ + public static String encodeBase64(byte[]input) throws Exception{ + Class clazz=Class.forName("com.sun.org.apache.xerces.internal.impl.dv.util.Base64"); + Method mainMethod= clazz.getMethod("encode", byte[].class); + mainMethod.setAccessible(true); + Object retObj=mainMethod.invoke(null, new Object[]{input}); + return (String)retObj; + } + /*** + * decode by Base64 + */ + public static byte[] decodeBase64(String input) throws Exception{ + Class clazz=Class.forName("com.sun.org.apache.xerces.internal.impl.dv.util.Base64"); + if (clazz==null) return null; + Method mainMethod= clazz.getMethod("decode", String.class); + if (mainMethod==null) return null; + + mainMethod.setAccessible(true); + Object retObj=mainMethod.invoke(null, input); + return (byte[])retObj; + } + + +} diff --git a/app/src/main/java/com/xixun/display/utils/CardID.java b/app/src/main/java/com/xixun/display/utils/CardID.java new file mode 100644 index 0000000..10f6be1 --- /dev/null +++ b/app/src/main/java/com/xixun/display/utils/CardID.java @@ -0,0 +1,60 @@ +package com.xixun.display.utils; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; + +public class CardID { + public static final String DEFAULT_CardID = "Android-00001"; + /** + * 获取设备id + * 自定义mid + * @return + * 例如:y6m-322-40182 + */ + public static String getCardId() { + File cardID = new File("/data/joey/signed/", "card.id"); + byte[] content = readFileByte(cardID, 0); + if ((null == content) || (0 == content.length)) { + return DEFAULT_CardID; + } else { + return cardIdToStr(content); + } + } + + public static byte[] readFileByte(File file, int len) { + try { + if (file.exists()) { + FileInputStream fis = new FileInputStream(file); + byte[] content = new byte[(len <= 0)? fis.available(): len]; + fis.read(content); + fis.close(); + return content; + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + public static String cardIdToStr(byte[] var1) { + byte[] var2 = new byte[]{97, 119, 38, 3, 46, 112, 36, 93, 58, 100, 103, 62, 115, 112, 114, 51, 43, 61, 2, 101, 119}; + if (var1.length < 40) { + return ""; + } else { + for(int var3 = 0; var3 < 20; ++var3) { + var1[var3] = (byte)(var1[var3 * 2] - var2[var3] - var3 - (var1[var3 * 2 + 1] - 3)); + } + + String var4 = new String(var1); + if (var4.length() >= 13) { + var4 = var4.substring(0, 13); + } + + return var4; + } + } +} diff --git a/app/src/main/java/com/xixun/display/utils/Configurations.java b/app/src/main/java/com/xixun/display/utils/Configurations.java new file mode 100644 index 0000000..6a7c99c --- /dev/null +++ b/app/src/main/java/com/xixun/display/utils/Configurations.java @@ -0,0 +1,65 @@ +package com.xixun.display.utils; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.content.SharedPreferences; +import android.content.SharedPreferences.Editor; + +/* + * + */ +public class Configurations { + + public static String strConfigFileName ="Configurations"; + public static Configurations config; + private SharedPreferences sharedPreferences=null; + + public static Configurations getConfigurations(Context ctx){ + if(config == null){ + config = new Configurations(ctx); + } + return config; + } + + @SuppressLint("WorldReadableFiles") + @SuppressWarnings("deprecation") + private Configurations(Context ctx){ + sharedPreferences = ctx.getSharedPreferences(strConfigFileName, + Context.MODE_PRIVATE | Context.MODE_PRIVATE); + } + + public void setValue(String id, String val){ + if (sharedPreferences==null) return; + + Editor editor = sharedPreferences.edit(); + editor.putString(id, val); + editor.commit(); + //Log.i("Configuration", "set value " + id + " :" + val); + } + public String getValue(String id){ + if (sharedPreferences==null) return null; + return sharedPreferences.getString(id, ""); + } + + public void setIntValue(String id, int val){ + if (sharedPreferences==null) return; + Editor editor = sharedPreferences.edit(); + editor.putInt(id, val); + editor.commit(); + } + public int getIntValue(String id){ + if (sharedPreferences==null) return -1; + return sharedPreferences.getInt(id, 0); + } + + public void setBooleanValue(String id, boolean val){ + if (sharedPreferences==null) return; + Editor editor = sharedPreferences.edit(); + editor.putInt(id, val?1:0); + editor.commit(); + } + public boolean getBooleanValue(String id){ + if (sharedPreferences==null) return false; + return (sharedPreferences.getInt(id, 0)==1); + } +} diff --git a/app/src/main/java/com/xixun/display/utils/CustomConfig.java b/app/src/main/java/com/xixun/display/utils/CustomConfig.java new file mode 100644 index 0000000..9c5c923 --- /dev/null +++ b/app/src/main/java/com/xixun/display/utils/CustomConfig.java @@ -0,0 +1,95 @@ +package com.xixun.display.utils; + +import android.content.res.AssetManager; + +import com.xixun.display.MyApp; + +import org.json.JSONObject; + +import java.io.Closeable; +import java.io.IOException; +import java.io.InputStream; + +/** + * @ClassName: CustomConfig + * @Description: 配置文件,取值与assets/CustomConfig.properties + * @author: Lay + * @date: 2021/6/17 10:18 + * + * @Copyright: 2020 https://ledok.cn/ Inc. All rights reserved. + * 注意:本内容仅限于上海熙讯电子科技有限公司内部传阅,禁止外泄以及用于其他的商业目的 + */ +public class CustomConfig { + private static CustomConfig mInstance; + public boolean isLog = true; + public boolean allLog = true; + public boolean fenghuo = false; + public boolean is_xixun = false; + + private static final String XIXUN_CONFIG_LOG = "xixun.config.log"; + private static final String XIXUN_CONFIG_ALL_LOG = "xixun.config.alllog"; + private static final String XIXUN_CONFIG_FENGHUO = "xixun.config.fenghuo"; + private static final String XIXUN_CONFIG_IS_XIXUN = "xixun.config.is_xixun"; + + public static CustomConfig getInstance() { + if (mInstance == null) { + synchronized (CustomConfig.class) { + if (mInstance == null) { + mInstance = new CustomConfig(); + } + } + } + return mInstance; + } + + public CustomConfig() { + getConfigFromConfigProp(); + } + + private void getConfigFromConfigProp() { + try { + AssetManager assetManager = MyApp.getContext().getAssets(); + InputStream open = assetManager.open("CustomConfig.properties"); + int len; + StringBuilder configMsg = new StringBuilder(); + byte[] buff = new byte[1024]; + while ((len = open.read(buff)) != -1) { + configMsg.append(new String(buff, 0, len)); + } + closeIO(open); + String config = configMsg.toString().trim(); + JSONObject configJson = new JSONObject(config); + + if (configJson.has(XIXUN_CONFIG_LOG)) { + isLog = configJson.getBoolean(XIXUN_CONFIG_LOG); + } + if (configJson.has(XIXUN_CONFIG_ALL_LOG)) { + allLog = configJson.getBoolean(XIXUN_CONFIG_ALL_LOG); + } + if (configJson.has(XIXUN_CONFIG_FENGHUO)) { + fenghuo = configJson.getBoolean(XIXUN_CONFIG_FENGHUO); + } + if (configJson.has(XIXUN_CONFIG_IS_XIXUN)) { + is_xixun = configJson.getBoolean(XIXUN_CONFIG_IS_XIXUN); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + + public static void closeIO(Closeable... closeables) { + if (closeables == null) { + return; + } + for (Closeable closeable : closeables) { + if (closeable != null) { + try { + closeable.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/xixun/display/utils/Define.java b/app/src/main/java/com/xixun/display/utils/Define.java new file mode 100644 index 0000000..7e3d933 --- /dev/null +++ b/app/src/main/java/com/xixun/display/utils/Define.java @@ -0,0 +1,485 @@ +package com.xixun.display.utils; + +import android.os.Environment; +import android.os.SystemClock; + +import com.xixun.display.MyLog; + +import java.io.File; +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * Created by Administrator on 2018/04/10. + */ + +public class Define { + public static final Boolean bRunOnDebug = false;//true;// + public static final Boolean bRunOn_GpsReport = false;//true;// + public static final Boolean bRunOnDebug418 = true;// false;// + + public static boolean bSyncPlay_Main_Sub=false;//true;// + + public static final int FLASH_PAGE_SIZE=4 * 1024; + public static final int FLASH_SECTIONT_NUM=1024; + public static final int FLASH_SIZE=FLASH_PAGE_SIZE * FLASH_SECTIONT_NUM; + + public static final int iTimeOut_CommandAck = 1200; + + + public static final byte UCHAR_SPECTIAL_FLAG = (0x55); + public static final byte UCHAR_SPECTIAL_FLAG_REVERSE = (byte)~UCHAR_SPECTIAL_FLAG; + public static final int UINT_SPECTIAL_FLAG = (0x55AA55AA); + public static final int UINT_SPECTIAL_FLAG_REVERSE = ~UINT_SPECTIAL_FLAG; + public static final String STRING_SPECTIAL_FLAG = "55AA55AA"; + public static final String STRING_SPECTIAL_FLAG_REVERSE = "AA55AA55"; + + public static final String AllNetBroadcaseIP = "255.255.255.255"; + + public static final int iDetectBytes = 20; + + public static final String strEqual = "="; + public static final String strFunc = "Func" +strEqual; + public static final String strAddress = "Address" +strEqual; + public static final String strLength = "Length" +strEqual; + public static final String strStringLength = "StringLength" + strEqual; + + + public static final String strParamsSeg = ";"; + + public static final String strFlashRead = "FlashRead"; + public static final String strFlashWrite = "FlashWrite"; + public static final String strFpgaRead = "FpgaRead"; + public static final String strFpgaWrite = "FpgaWrite"; + public static final String strRegRead = "RegRead"; + public static final String strRegWrite = "RegWrite"; + public static final String strGetGiGData = "GetGiGData "; + public static final String strReset = "Reset"; + + + public static final String ROOT_PATH= "/";// SD_CARD_PATH // mainActivity.getApplicationContext().getFilesDir().getAbsolutePath(); + public static final String SD_CARD_PATH= "/mnt/sdcard/"; +// public static final String SD_CARD_PATH= "/sdcard/"; + + public static final String STORAGE_PATH= "/Sysolution";//"/storage/sdcard0/Samtone/"; + public static final String RECE_FILES_PATH=STORAGE_PATH+ "/ReceFiles"; + public static final String WORK_FILES_PATH=STORAGE_PATH + "/WorkFiles"; + + + public static String _MOONCELL_FPGA_PARAMS_FILE_NAME="/MC_FpgaParams"; + public static String MOONCELL_FPGA_PARAMS_FILE_NAME=WORK_FILES_PATH+_MOONCELL_FPGA_PARAMS_FILE_NAME; + + public static String _MOONCELL_FPGA_REG_FILE_NAME="/MC_RegsParams"; + public static String MOONCELL_FPGA_REG_FILE_NAME=WORK_FILES_PATH+_MOONCELL_FPGA_REG_FILE_NAME; // "Sysolution/" "WorkFiles/" MC_RegsParams" + + + public static final String _MAIN_LOGO_FILE_NAME="MainLogo"; + public static final String _GUEST_LOGO_FILE_NAME="GuestLogo"; + public static final String MAIN_LOGO_FILE_NAME=RECE_FILES_PATH+_MAIN_LOGO_FILE_NAME; + + public static void Shell(String strCommand) + { + if (strCommand==null) return; + if (strCommand.length()<=0) return; + + MyLog.i( "ShellCommand: "+strCommand ); + try { + /* Missing read/write permission, trying to chmod the file */ + Process su; + su = Runtime.getRuntime().exec("/system/bin/su"); + String cmd = strCommand + "\nexit\n"; + su.getOutputStream().write(cmd.getBytes()); + } catch (Exception e) { + e.printStackTrace(); + //throw new SecurityException(); + } + } + + public static void SetFileAuthority(boolean bXixunSuCommand,String fileName) + { + MyLog.i("chmod 777 "+ fileName); + //ShellUtils.execCommand("chmod 777 "+ fileName, bXixunSuCommand, true); + // ShellUtils.execCommand("chmod 777 "+ fileName, false, true); + ShellUtils.execCommand("chmod 777 "+ fileName, bXixunSuCommand, true); + // ShellUtils.execCommand("chmod 777 "+ "/mnt/sdcard", bXixunSuCommand, true); + // MyLog.i("chmod 777 xxx"); + //ShellUtils.execCommand("ls "+ fileName + " -l", true, true); + } + + public static boolean FileExist(String fileName,long fileLength) + { boolean bRightFile=false; + File file=new File(fileName); + if (file==null) { + MyLog.i("Empty file:"+fileName); + return false; + } + bRightFile=(file.length()==fileLength); + if (bRightFile==false) + { + MyLog.i(fileName + " File length:"+file.length()); + MyLog.i(fileName + " need length:"+fileLength); + } + return bRightFile; + } + + public static int CreateFolder(String fileName) + { + MyLog.i("Creat Folder :" + fileName); + + File file=new File(fileName); + if (file.exists()) + if (file.isDirectory()) return 0; + + boolean res = file.mkdirs(); + MyLog.i("res====="+res); + + file=new File(fileName); + if (file.exists()) return 0; + MyLog.i("Creat Folder Fail 1:" + fileName); + + ShellUtils.execCommand("mkdir "+ fileName, true, true); + ShellUtils.execCommand("chmod -R 777 "+ fileName, true, true); + file=new File(fileName); + if (file.exists()) return 0; + + MyLog.i("Creat Folder Fail 2 :" + fileName); + return -1; + + } + + public static void FileCopy(String strSourceFile,String strDirecrtFile) + { FileOperator.copyDir(strSourceFile,strDirecrtFile); + ShellUtils.execCommand("cp -af "+ strSourceFile+ " "+ strDirecrtFile,false); + MyLog.i("cp -af "+ strSourceFile+ " "+ strDirecrtFile); + } + + + public static int SetIntToBye(int iValue,byte [] pBuffer,int iOffset) + { if (pBuffer==null) return -1; + pBuffer[iOffset++]=(byte) (iValue>>0);// 正文长度。 + pBuffer[iOffset++]=(byte) (iValue>>8); + pBuffer[iOffset++]=(byte) (iValue>>16); + pBuffer[iOffset++]=(byte) (iValue>>24); + return 0; + } + + public static int GetBtyeToInt(byte [] pBuffer,int iOffset) + { long iValue=0; + if (pBuffer==null) return -1; + + // MyLog.i("-----------iRetValue= "+pBuffer[0]+" "+pBuffer[1]+" "+pBuffer[2]+" "+pBuffer[3]); + + iValue|=(pBuffer[iOffset++]<<0)&0xFF; + iValue|=(long)(pBuffer[iOffset++]<<8)&0xFF00; + iValue|=(long)(pBuffer[iOffset++]<<16)&0xFF0000; + iValue|=(long)(pBuffer[iOffset++]<<24)&0xFF000000; + return (int)iValue; + } + + public static int SetUshortToBye(int iValue,byte [] pBuffer,int iOffset) + { if (pBuffer==null) return -1; + pBuffer[iOffset++]=(byte) (iValue>>0);// 正文长度。 + pBuffer[iOffset++]=(byte) (iValue>>8); + return 0; + } + + public static int GetBtyeToUshort(byte [] pBuffer,int iOffset) + { long iValue=0; + if (pBuffer==null) return -1; + iValue|=(pBuffer[iOffset++]<<0)&0xFF; + iValue|=(long)(pBuffer[iOffset++]<<8)&0xFF00; + return (int)iValue; + } + + + public static int SetShortToByte(int iValue, byte[] pBuffer, int iOffset) + { + if (pBuffer == null) return -1; + pBuffer[iOffset++] = (byte)(iValue >> 0);// 正文长度。 + pBuffer[iOffset++] = (byte)(iValue >> 8); + return 0; + } + + public static int SetIntToByte(int iValue, byte[] pBuffer, int iOffset) + { + if (pBuffer == null) return -1; + pBuffer[iOffset++] = (byte)(iValue >> 0);// 正文长度。 + pBuffer[iOffset++] = (byte)(iValue >> 8); + pBuffer[iOffset++] = (byte)(iValue >> 16); + pBuffer[iOffset++] = (byte)(iValue >> 24); + return 0; + } + + public static int GetIntFromByte(byte[] pBuffer, int iOffset) + { + int iValue = 0; + if (pBuffer == null) return -1; + + iValue += ((pBuffer[iOffset++]&0xff) << 0); + iValue += ((pBuffer[iOffset++]&0xff) << 8); + iValue += ((pBuffer[iOffset++]&0xff) << 16); + iValue += ((pBuffer[iOffset++]&0xff) << 24); + return iValue; + } + + public static byte GetCheckCodeIn8(byte[] pBuffer, int iStart, int iEnd) + { + byte ucCheckCode = 0; + for (; iStart < iEnd; iStart++) ucCheckCode += pBuffer[iStart]; + return (byte)~ucCheckCode; + } + + + public static byte GetCheckCodeIn811(byte [] pBuffer,int iOffset,int iEndOffset) + { int i=0; + byte ucCheckCode=0; + for (i=iOffset;i>8); // 以8位二进制数的形式暂存CRC的高8位 + + crcval<<=8; // 左移8位,相当于CRC的低8位乘以 + crcval&=0xFFFF; + crcval ^= g_crctab16[(da^pDat[iOffset++])&0xFF]; // 高8位和当前字节相加后再查表求CRC ,再加上以前的CRC + } + return crcval&0xFFFF; + } + + public static int Crc16_Add(int uiCrc,byte ucNewData) + { return (uiCrc >>> 8) ^ table[(uiCrc ^ ucNewData) & 0xff]; + } + + public static int Crc16(byte[] bytes) { + int crc = 0x0000; + + for (byte b : bytes) { + crc = (crc >>> 8) ^ table[(crc ^ b) & 0xff]; + } + return crc; + } + + public static int Crc32 (byte [] pDat, long length) + { + + int crc = 0xFFFFFFFF; + for (int i = 0; i < length; i++) + { + crc = ((crc >> 8)&0x00FFFFFF) ^ g_crctab32[(crc ^ pDat[i])&0xFF]; + } + MyLog.i("Crc32:0x"+Long.toHexString((crc ^ 0xFFFFFFFF)&0xFFFFFFFF).toUpperCase()); + return (crc ^ 0xFFFFFFFF)&0xFFFFFFFF; + } + + static int []g_crctab16={ // CRC余式表 + 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, + 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, + 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, + 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, + 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, + 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, + 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, + 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, + 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, + 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, + 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, + 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, + 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, + 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, + 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, + 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, + 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, + 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, + 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, + 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, + 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, + 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, + 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, + 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, + 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, + 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, + 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, + 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, + 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, + 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, + 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, + 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0 + }; + static int[] table = { + 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, + 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440, + 0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40, + 0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841, + 0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40, + 0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41, + 0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641, + 0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040, + 0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240, + 0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441, + 0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41, + 0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840, + 0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41, + 0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40, + 0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640, + 0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041, + 0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240, + 0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441, + 0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41, + 0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840, + 0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41, + 0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40, + 0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640, + 0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041, + 0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241, + 0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440, + 0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40, + 0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841, + 0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40, + 0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41, + 0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641, + 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040, + }; + + + static int [] g_crctab32= { + 0x00000000,0x77073096,0xee0e612c,0x990951ba,0x076dc419,0x706af48f,0xe963a535,0x9e6495a3, + 0x0edb8832,0x79dcb8a4,0xe0d5e91e,0x97d2d988,0x09b64c2b,0x7eb17cbd,0xe7b82d07,0x90bf1d91, + 0x1db71064,0x6ab020f2,0xf3b97148,0x84be41de,0x1adad47d,0x6ddde4eb,0xf4d4b551,0x83d385c7, + 0x136c9856,0x646ba8c0,0xfd62f97a,0x8a65c9ec,0x14015c4f,0x63066cd9,0xfa0f3d63,0x8d080df5, + 0x3b6e20c8,0x4c69105e,0xd56041e4,0xa2677172,0x3c03e4d1,0x4b04d447,0xd20d85fd,0xa50ab56b, + 0x35b5a8fa,0x42b2986c,0xdbbbc9d6,0xacbcf940,0x32d86ce3,0x45df5c75,0xdcd60dcf,0xabd13d59, + 0x26d930ac,0x51de003a,0xc8d75180,0xbfd06116,0x21b4f4b5,0x56b3c423,0xcfba9599,0xb8bda50f, + 0x2802b89e,0x5f058808,0xc60cd9b2,0xb10be924,0x2f6f7c87,0x58684c11,0xc1611dab,0xb6662d3d, + 0x76dc4190,0x01db7106,0x98d220bc,0xefd5102a,0x71b18589,0x06b6b51f,0x9fbfe4a5,0xe8b8d433, + 0x7807c9a2,0x0f00f934,0x9609a88e,0xe10e9818,0x7f6a0dbb,0x086d3d2d,0x91646c97,0xe6635c01, + 0x6b6b51f4,0x1c6c6162,0x856530d8,0xf262004e,0x6c0695ed,0x1b01a57b,0x8208f4c1,0xf50fc457, + 0x65b0d9c6,0x12b7e950,0x8bbeb8ea,0xfcb9887c,0x62dd1ddf,0x15da2d49,0x8cd37cf3,0xfbd44c65, + 0x4db26158,0x3ab551ce,0xa3bc0074,0xd4bb30e2,0x4adfa541,0x3dd895d7,0xa4d1c46d,0xd3d6f4fb, + 0x4369e96a,0x346ed9fc,0xad678846,0xda60b8d0,0x44042d73,0x33031de5,0xaa0a4c5f,0xdd0d7cc9, + 0x5005713c,0x270241aa,0xbe0b1010,0xc90c2086,0x5768b525,0x206f85b3,0xb966d409,0xce61e49f, + 0x5edef90e,0x29d9c998,0xb0d09822,0xc7d7a8b4,0x59b33d17,0x2eb40d81,0xb7bd5c3b,0xc0ba6cad, + 0xedb88320,0x9abfb3b6,0x03b6e20c,0x74b1d29a,0xead54739,0x9dd277af,0x04db2615,0x73dc1683, + 0xe3630b12,0x94643b84,0x0d6d6a3e,0x7a6a5aa8,0xe40ecf0b,0x9309ff9d,0x0a00ae27,0x7d079eb1, + 0xf00f9344,0x8708a3d2,0x1e01f268,0x6906c2fe,0xf762575d,0x806567cb,0x196c3671,0x6e6b06e7, + 0xfed41b76,0x89d32be0,0x10da7a5a,0x67dd4acc,0xf9b9df6f,0x8ebeeff9,0x17b7be43,0x60b08ed5, + 0xd6d6a3e8,0xa1d1937e,0x38d8c2c4,0x4fdff252,0xd1bb67f1,0xa6bc5767,0x3fb506dd,0x48b2364b, + 0xd80d2bda,0xaf0a1b4c,0x36034af6,0x41047a60,0xdf60efc3,0xa867df55,0x316e8eef,0x4669be79, + 0xcb61b38c,0xbc66831a,0x256fd2a0,0x5268e236,0xcc0c7795,0xbb0b4703,0x220216b9,0x5505262f, + 0xc5ba3bbe,0xb2bd0b28,0x2bb45a92,0x5cb36a04,0xc2d7ffa7,0xb5d0cf31,0x2cd99e8b,0x5bdeae1d, + 0x9b64c2b0,0xec63f226,0x756aa39c,0x026d930a,0x9c0906a9,0xeb0e363f,0x72076785,0x05005713, + 0x95bf4a82,0xe2b87a14,0x7bb12bae,0x0cb61b38,0x92d28e9b,0xe5d5be0d,0x7cdcefb7,0x0bdbdf21, + 0x86d3d2d4,0xf1d4e242,0x68ddb3f8,0x1fda836e,0x81be16cd,0xf6b9265b,0x6fb077e1,0x18b74777, + 0x88085ae6,0xff0f6a70,0x66063bca,0x11010b5c,0x8f659eff,0xf862ae69,0x616bffd3,0x166ccf45, + 0xa00ae278,0xd70dd2ee,0x4e048354,0x3903b3c2,0xa7672661,0xd06016f7,0x4969474d,0x3e6e77db, + 0xaed16a4a,0xd9d65adc,0x40df0b66,0x37d83bf0,0xa9bcae53,0xdebb9ec5,0x47b2cf7f,0x30b5ffe9, + 0xbdbdf21c,0xcabac28a,0x53b39330,0x24b4a3a6,0xbad03605,0xcdd70693,0x54de5729,0x23d967bf, + 0xb3667a2e,0xc4614ab8,0x5d681b02,0x2a6f2b94,0xb40bbe37,0xc30c8ea1,0x5a05df1b,0x2d02ef8d + }; + + public static int htons(int s){ return ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff));} + public static int htonl(int l){ return ( (((l) & 0xff000000) >> 24) | (((l) & 0x00ff0000) >> 8) | (((l) & 0x0000ff00) << 8) | (((l) & 0x000000ff) << 24) );} + + public static int hton_l(int data) + { int lValue=0; + lValue|=(data>>0)&0xFF; + lValue<<=8; + lValue|=(data>>8)&0xFF; + lValue<<=8; + lValue|=(data>>16)&0xFF; + lValue<<=8; + lValue|=(data>>24)&0xFF; + //MyLog.i(Thread.currentThread().getStackTrace()[2].getMethodName() + " L" + Thread.currentThread().getStackTrace()[2].getLineNumber() + + // " data="+Long.toHexString(data).toUpperCase() + " lValue="+Long.toHexString(lValue).toUpperCase()); + + return lValue&0xFFFFFFFF; + } + + + //检查sd卡存不存在,并且获取路径 + public String getSDPath(){ + File sdDir = null; + boolean sdCardExist = Environment.getExternalStorageState() + .equals(Environment.MEDIA_MOUNTED);//判断sd卡是否存在 + if(sdCardExist) + { + sdDir = Environment.getExternalStorageDirectory();//获取跟目录 + } + + return sdDir.toString(); + } + +} diff --git a/app/src/main/java/com/xixun/display/utils/DisplayConfig.java b/app/src/main/java/com/xixun/display/utils/DisplayConfig.java new file mode 100644 index 0000000..fc74b86 --- /dev/null +++ b/app/src/main/java/com/xixun/display/utils/DisplayConfig.java @@ -0,0 +1,129 @@ +package com.xixun.display.utils; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.content.SharedPreferences; +import android.util.Base64; + +import com.xixun.display.MyApp; +import com.xixun.display.MyLog; +import com.xixun.display.domain.Reg; + +@SuppressLint("WorldWriteableFiles") +public class DisplayConfig { + private static final String CONFIG_NAME = "DisplayConfig"; + private static SharedPreferences configMyself = null; + //private static int tryTimes = 5; + + private static synchronized SharedPreferences getConfigMyself() { + if (null == configMyself) { + Context context = MyApp.getInstance(); + configMyself = context.getSharedPreferences(CONFIG_NAME, Context.MODE_PRIVATE); + } + return configMyself; + } + /*//通用json + public static boolean setGeneralJson(String json) { + return getConfigMyself().edit().putString("GeneralJson", json).commit(); + } + public static String getGeneralJson() { + return getConfigMyself().getString("GeneralJson", MyApp.runningInformation.generalJson); + }*/ + + /*public static boolean setReg(byte[] bs) { + return getConfigMyself().edit().p +// return getConfigMyself().edit().putString("GeneralJson", json).commit(); + } + public static String getGeneralJson() { + return getConfigMyself().getString("GeneralJson", MyApp.runningInformation.generalJson); + }*/ + + public static Reg getReg() { + String base64 = getConfigMyself().getString("RegValue", null); + if (null != base64) { + try { + String str = new String(Base64.decode(base64.getBytes(), 0)); + Reg reg = MyApp.getMapper().readValue(str, Reg.class); + return reg; + } catch (Exception e) { + e.printStackTrace(); + } + } + return new Reg(1024); + } + + public static boolean setReg(Reg reg) { + try { + String str = MyApp.getMapper().writeValueAsString(reg); + return getConfigMyself().edit().putString("RegValue", new String(Base64.encode(str.getBytes(), 0))).commit(); + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } + + public static boolean saveBrightness(int brightness) { + try { + return getConfigMyself().edit().putInt("Brightness", brightness).commit(); + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } + + public static int getBrightness() { + return getConfigMyself().getInt("Brightness", 255); + } + + public static boolean saveProtocolType(int ProtocolType) { + try { + return getConfigMyself().edit().putInt("ProtocolType", ProtocolType).commit(); + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } + public static boolean saveBoxWidth(int width) { + try { + return getConfigMyself().edit().putInt("width", width).commit(); + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } + + //0:MC + public static int getProtocolType() { + return getConfigMyself().getInt("ProtocolType", 2); + } + public static int getBoxWidth() { + return getConfigMyself().getInt("width", 0); + } + + public static boolean saveBoxHeight(int height) { + try { + return getConfigMyself().edit().putInt("height", height).commit(); + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } + + public static int getBoxHeight() { + return getConfigMyself().getInt("height", 0); + } + + public static boolean savePort(int port) { + try { + MyLog.e("port-----"+port); + return getConfigMyself().edit().putInt("port", port).commit(); + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } + + public static int getPort() { + return getConfigMyself().getInt("port", 0); + } +} diff --git a/app/src/main/java/com/xixun/display/utils/FileOperator.java b/app/src/main/java/com/xixun/display/utils/FileOperator.java new file mode 100644 index 0000000..73a01c9 --- /dev/null +++ b/app/src/main/java/com/xixun/display/utils/FileOperator.java @@ -0,0 +1,156 @@ +package com.xixun.display.utils; + +/** + * Created by Administrator on 2018/06/06. + */ +import com.xixun.display.MyLog; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.OutputStream; +/** + * + * @ClassName: FileOperator + * @Description: 文件操作类,删除文件或文件目录 + * @author: SAU_LC66 + * @date: 2014-09-25 19:01 + */ + +public class FileOperator { + + /** + * 复制文件目录 + * @param srcDir 要复制的源目录 eg:/mnt/sdcard/DB + * @param destDir 复制到的目标目录 eg:/mnt/sdcard/db/ + * @return + */ + public static boolean copyDir(String srcDir, String destDir){ + MyLog.i("copyDir srcDir: "+ srcDir); + MyLog.i("copyDir destDir: "+ destDir); + + File sourceDir = new File(srcDir); + //判断文件目录是否存在 + if(!sourceDir.exists()){ + MyLog.i("sourceDir: "+ srcDir+ " Not Folder."); + return false; + } + //判断是否是目录 + if (sourceDir.isDirectory()) { + File[] fileList = sourceDir.listFiles(); + File targetDir = new File(destDir); + //创建目标目录 + if(!targetDir.exists()){ + targetDir.mkdirs(); + } + //遍历要复制该目录下的全部文件 + for(int i= 0;i "+ destFile); + try{ + InputStream streamFrom = new FileInputStream(srcFile); + OutputStream streamTo = new FileOutputStream(destFile); + byte buffer[]=new byte[1024]; + int len; + while ((len= streamFrom.read(buffer)) > 0){ + streamTo.write(buffer, 0, len); + } + streamFrom.close(); + streamTo.close(); + return true; + } catch(Exception ex){ + ex.printStackTrace(); + return false; + } + } + + + /** + * 把文件拷贝到某一目录下 + * @param srcFile + * @param destDir + * @return + */ + public static boolean copyFileToDir(String srcFile, String destDir){ + MyLog.i("------------1 copyFile: "+ srcFile +" --> "+ destDir); + File fileDir = new File(destDir); + if (!fileDir.exists()) { + fileDir.mkdir(); + } + String destFile = destDir +"/" + new File(srcFile).getName(); + try{ + InputStream streamFrom = new FileInputStream(srcFile); + OutputStream streamTo = new FileOutputStream(destFile); + byte buffer[]=new byte[1024]; + int len; + while ((len= streamFrom.read(buffer)) > 0){ + streamTo.write(buffer, 0, len); + } + streamFrom.close(); + streamTo.close(); + return true; + } catch(Exception ex){ + ex.printStackTrace(); + return false; + } + } + + + /** + * 移动文件目录到某一路径下 + * @param srcFile + * @param destDir + * @return + */ + public static boolean moveFile(String srcFile, String destDir) { + //复制后删除原目录 + if (copyDir(srcFile, destDir)) { + deleteFile(new File(srcFile)); + return true; + } + return false; + } + + /** + * 删除文件(包括目录) + * @param delFile + */ + public static void deleteFile(File delFile) { + //如果是目录递归删除 + if (delFile.isDirectory()) { + File[] files = delFile.listFiles(); + for (File file : files) { + deleteFile(file); + } + }else{ + delFile.delete(); + } + //如果不执行下面这句,目录下所有文件都删除了,但是还剩下子目录空文件夹 + delFile.delete(); + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/xixun/display/utils/LocationUtils.java b/app/src/main/java/com/xixun/display/utils/LocationUtils.java new file mode 100644 index 0000000..a3d8a21 --- /dev/null +++ b/app/src/main/java/com/xixun/display/utils/LocationUtils.java @@ -0,0 +1,156 @@ +package com.xixun.display.utils; + +import android.Manifest; +import android.content.Context; +import android.content.pm.PackageManager; +import android.location.Criteria; +import android.location.Location; +import android.location.LocationListener; +import android.location.LocationManager; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v4.app.ActivityCompat; +import android.text.TextUtils; + +public class LocationUtils { + + private static final long REFRESH_TIME = 5000L; + private static final float METER_POSITION = 0.0f; + private static ILocationListener mLocationListener; + private static LocationListener listener = new MyLocationListener(); + + private static class MyLocationListener implements LocationListener { + @Override + public void onLocationChanged(Location location) {//定位改变监听 + if (mLocationListener != null) { + mLocationListener.onSuccessLocation(location); + } + } + + @Override + public void onStatusChanged(String provider, int status, Bundle extras) {//定位状态监听 + + } + + @Override + public void onProviderEnabled(String provider) {//定位状态可用监听 + + } + + @Override + public void onProviderDisabled(String provider) {//定位状态不可用监听 + + } + } + + /** + * GPS获取定位方式 + */ + public static Location getGPSLocation(@NonNull Context context) { + Location location = null; + LocationManager manager = getLocationManager(context); + //高版本的权限检查 + if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + return null; + } + if (manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {//是否支持GPS定位 + //获取最后的GPS定位信息,如果是第一次打开,一般会拿不到定位信息,一般可以请求监听,在有效的时间范围可以获取定位信息 + location = manager.getLastKnownLocation(LocationManager.GPS_PROVIDER); + } + return location; + } + + /** + * network获取定位方式 + */ + public static Location getNetWorkLocation(Context context) { + Location location = null; + LocationManager manager = getLocationManager(context); + //高版本的权限检查 + // if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + // return null; + // } + if (manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {//是否支持Network定位 + //获取最后的network定位信息 + location = manager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); + } + return location; + } + + /** + * 获取最好的定位方式 + */ + public static Location getBestLocation(Context context, Criteria criteria) { + Location location; + LocationManager manager = getLocationManager(context); + if (criteria == null) { + criteria = new Criteria(); + } + String provider = manager.getBestProvider(criteria, true); + if (TextUtils.isEmpty(provider)) { + //如果找不到最适合的定位,使用network定位 + location = getNetWorkLocation(context); + } else { + //高版本的权限检查 + // if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED + // && ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + // return null; + // } + //获取最适合的定位方式的最后的定位权限 + location = manager.getLastKnownLocation(provider); + } + return location; + } + + /** + * 定位监听 + */ + public static void addLocationListener(Context context, String provider, ILocationListener locationListener) { + + addLocationListener(context, provider, REFRESH_TIME, METER_POSITION, locationListener); + } + + /** + * 定位监听 + */ + public static void addLocationListener(Context context, String provider, long time, float meter, ILocationListener locationListener) { + if (locationListener != null) { + mLocationListener = locationListener; + } + if (listener == null) { + listener = new MyLocationListener(); + } + LocationManager manager = getLocationManager(context); + if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED + && ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + return; + } + manager.requestLocationUpdates(provider, time, meter, listener); + } + + /** + * 取消定位监听 + */ + public static void unRegisterListener(Context context) { + if (listener != null) { + LocationManager manager = getLocationManager(context); + if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED + && ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + return; + } + //移除定位监听 + manager.removeUpdates(listener); + } + } + + private static LocationManager getLocationManager(@NonNull Context context) { + return (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); + } + + /** + * 自定义接口 + */ + public interface ILocationListener { + void onSuccessLocation(Location location); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/xixun/display/utils/OtherData.java b/app/src/main/java/com/xixun/display/utils/OtherData.java new file mode 100644 index 0000000..4e59fdd --- /dev/null +++ b/app/src/main/java/com/xixun/display/utils/OtherData.java @@ -0,0 +1,194 @@ +package com.xixun.display.utils; + +public class OtherData { + public static byte[] data ={ + 0x00,0x00,0x00,0x00,0x01, (byte) 0xF4,0x04,(byte) 0xB0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 + ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 + ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,(byte) 0xE7,(byte) 0xF9,(byte) 0xFE,0x00,0x00,0x00,(byte) 0xA5,0x05,(byte) 0xDC,0x27,0x14 + ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14 + ,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x00,0x00,0x00,0x00,0x14,0x14 + ,0x14,0x14,0x14,0x14,0x14,0x14,0x00,0x00,0x14,0x14,0x00,0x00,0x14,0x14,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 + ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 + ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 + ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 + ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 + ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 + ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 + }; + public static byte[] intToByteArray(int i) { + byte[] result = new byte[2]; +// result[0] = (byte)((i >> 24) & 0xFF); +// result[1] = (byte)((i >> 16) & 0xFF); + result[0] = (byte)((i >> 8) & 0xFF); + result[1] = (byte)(i & 0xFF); + return result; + } + + + /*0-1:大屏左;2-3大屏上;4-5:截取宽;6-7:截取高;12-13:网口1Y;14-15:网口1X;16-17:网口2Y;18-19:网口2X + 00 20 00 40 01 F4 04 B0 00 00 00 00 00 40 00 20 00 40 + 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 + 00 00 00 00 00 00 00 00 00 00 00 1F E7 F9 FE 00 00 00 A5 05 DC 27 14 + 00 00 00 00 00 00 00 00 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 + 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 00 00 00 00 14 14 + 14 14 14 14 14 14 00 00 14 14 00 00 14 14 00 00 00 00 00 00 00 00 00 + 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 + 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 + 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 + 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 + 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 + 00 00 00 00 00 00 00 00*/ + + + public static byte[] a70000 ={//网口1 + (byte)0XE5, (byte)0XA7, 0X00, 0X00, (byte)0X04, 0X00, 0X00, 0X00, (byte)0X55, (byte)0X55, (byte)0X9A, (byte)0X3D, 0X00, 0X00, (byte)0X10, (byte)0XFF, + (byte)0XFF, (byte)0XFF, 0X00, 0X00, (byte)0X30, (byte)0XC9, (byte)0X35, 0X00, (byte)0X0C, (byte)0XAA, 0X00, 0X00, (byte)0XBF, (byte)0XA2, (byte)0X92, (byte)0XFE, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, (byte)0X55, (byte)0X55, (byte)0X9A, (byte)0X3D, 0X00, 0X00, (byte)0X10, (byte)0XFF, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, (byte)0X35, 0X00, (byte)0X0C, (byte)0XBB, 0X00, 0X00, (byte)0X52, (byte)0X2C, (byte)0X30, (byte)0X53, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, (byte)0X55, (byte)0X55, (byte)0X9A, (byte)0X3D, 0X00, 0X00, (byte)0X10, (byte)0XFF, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, (byte)0X35, 0X00, (byte)0X0C, (byte)0XCC, 0X00, 0X00, (byte)0X03, (byte)0X92, (byte)0X4E, (byte)0X86, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, (byte)0X55, (byte)0X55, (byte)0X9A, (byte)0X3D, 0X00, (byte)0X01, (byte)0X10, (byte)0XFF, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, (byte)0X35, 0X00, (byte)0X0C, (byte)0X11, 0X00, 0X00, (byte)0X3F, (byte)0X38, (byte)0X33, (byte)0X0D, + 0X00, 0X00, (byte)0X06, 0X00, (byte)0X77, (byte)0X1E, (byte)0X78, (byte)0X9A, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + (byte)0X55, (byte)0X55, (byte)0X9A, (byte)0X3D, 0X00, (byte)0X60, (byte)0X10, (byte)0XFF, (byte)0X1F, (byte)0XFF, 0X00, 0X00, 0X00, 0X00, (byte)0XD0, (byte)0XD0, + 0X00, 0X00, 0X00, 0X00, (byte)0X38, (byte)0X04, (byte)0XCF, (byte)0XB6, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, (byte)0X01, (byte)0X10, (byte)0XFF, (byte)0XFF, (byte)0XFF, + 0X00, 0X00, 0X00, (byte)0XF0, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, //x + 0X00, 0X00, //y + (byte)0X03, 0X00, //高度 + (byte)0X03, 0X00,//宽度 + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, (byte)0X64, (byte)0X69, (byte)0X73, (byte)0X70, (byte)0X6C, (byte)0X61, (byte)0X79, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, (byte)0X7B, (byte)0X38, (byte)0X32, (byte)0X43, (byte)0X31, (byte)0X42, (byte)0X32, (byte)0X41, + (byte)0X31, (byte)0X2D, (byte)0X35, (byte)0X30, (byte)0X35, (byte)0X30, (byte)0X2D, (byte)0X34, (byte)0X42, (byte)0X32, (byte)0X46, (byte)0X2D, (byte)0X39, (byte)0X35, (byte)0X42, (byte)0X45, + (byte)0X2D, (byte)0X46, (byte)0X32, (byte)0X38, (byte)0X39, (byte)0X30, (byte)0X31, (byte)0X34, (byte)0X42, (byte)0X34, (byte)0X33, (byte)0X35, (byte)0X30, (byte)0X7D, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, (byte)0X40, (byte)0X40, (byte)0XEF, (byte)0XE3 + + + }; + public static byte[] a70400 ={//网口2 + (byte)0XE5, (byte)0XA7, 0X00, 0X00, (byte)0X04, 0X00, 0X00, 0X00, (byte)0X55, (byte)0X55, (byte)0X9A, (byte)0X3D, 0X00, 0X00, (byte)0X10, (byte)0XFF, + (byte)0XFF, (byte)0XFF, 0X00, 0X00, (byte)0X30, (byte)0XC9, (byte)0X35, 0X00, (byte)0X0C, (byte)0XAA, 0X00, 0X00, (byte)0XBF, (byte)0XA2, (byte)0X92, (byte)0XFE, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, (byte)0X55, (byte)0X55, (byte)0X9A, (byte)0X3D, 0X00, 0X00, (byte)0X10, (byte)0XFF, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, (byte)0X35, 0X00, (byte)0X0C, (byte)0XBB, 0X00, 0X00, (byte)0X52, (byte)0X2C, (byte)0X30, (byte)0X53, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, (byte)0X55, (byte)0X55, (byte)0X9A, (byte)0X3D, 0X00, 0X00, (byte)0X10, (byte)0XFF, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, (byte)0X35, 0X00, (byte)0X0C, (byte)0XCC, 0X00, 0X00, (byte)0X03, (byte)0X92, (byte)0X4E, (byte)0X86, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, (byte)0X55, (byte)0X55, (byte)0X9A, (byte)0X3D, 0X00, (byte)0X01, (byte)0X10, (byte)0XFF, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, (byte)0X35, 0X00, (byte)0X0C, (byte)0X11, 0X00, 0X00, (byte)0X3F, (byte)0X38, (byte)0X33, (byte)0X0D, + 0X00, 0X00, (byte)0X06, 0X00, (byte)0X77, (byte)0X1E, (byte)0X78, (byte)0X9A, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + (byte)0X55, (byte)0X55, (byte)0X9A, (byte)0X3D, 0X00, (byte)0X60, (byte)0X10, (byte)0XFF, (byte)0X1F, (byte)0XFF, 0X00, 0X00, 0X00, 0X00, (byte)0XD0, (byte)0XD0, + 0X00, 0X00, 0X00, 0X00, (byte)0X38, (byte)0X04, (byte)0XCF, (byte)0XB6, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, (byte)0X01, (byte)0X10, (byte)0XFF, (byte)0XFF, (byte)0XFF, + 0X00, 0X00, 0X00, (byte)0XF0, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, //x + 0X00, 0X00, //y + (byte)0X03, 0X00, //高度 + (byte)0X03, 0X00,//宽度 + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, (byte)0X64, (byte)0X69, (byte)0X73, (byte)0X70, (byte)0X6C, (byte)0X61, (byte)0X79, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, (byte)0X7B, (byte)0X38, (byte)0X32, (byte)0X43, (byte)0X31, (byte)0X42, (byte)0X32, (byte)0X41, + (byte)0X31, (byte)0X2D, (byte)0X35, (byte)0X30, (byte)0X35, (byte)0X30, (byte)0X2D, (byte)0X34, (byte)0X42, (byte)0X32, (byte)0X46, (byte)0X2D, (byte)0X39, (byte)0X35, (byte)0X42, (byte)0X45, + (byte)0X2D, (byte)0X46, (byte)0X32, (byte)0X38, (byte)0X39, (byte)0X30, (byte)0X31, (byte)0X34, (byte)0X42, (byte)0X34, (byte)0X33, (byte)0X35, (byte)0X30, (byte)0X7D, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, + 0X00, 0X00, 0X00, 0X00, (byte)0X40, (byte)0X40, (byte)0XEF, (byte)0XE3 + + }; + public static byte[] a80000 ={ + (byte) 0xE5,(byte) 0xA8,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x6F,0x60,0x33,(byte) 0x9A + }; + public static byte[] a8003c ={ + (byte) 0xE5, (byte) 0xA8,0x00,0x3C,0x00,0x04,0x00,0x00,0x00,0x00,0x00, (byte) 0xA5 + }; +} diff --git a/app/src/main/java/com/xixun/display/utils/ShellUtils.java b/app/src/main/java/com/xixun/display/utils/ShellUtils.java new file mode 100644 index 0000000..bfdde96 --- /dev/null +++ b/app/src/main/java/com/xixun/display/utils/ShellUtils.java @@ -0,0 +1,228 @@ +package com.xixun.display.utils; + +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.List; + +/** + * ShellUtils + *
    + * Check root + *
  • {@link ShellUtils#checkRootPermission()}
  • + *
+ *
    + * Execte command + *
  • {@link ShellUtils#execCommand(String, boolean)}
  • + *
  • {@link ShellUtils#execCommand(String, boolean, boolean)}
  • + *
  • {@link ShellUtils#execCommand(List, boolean)}
  • + *
  • {@link ShellUtils#execCommand(List, boolean, boolean)}
  • + *
  • {@link ShellUtils#execCommand(String[], boolean)}
  • + *
  • {@link ShellUtils#execCommand(String[], boolean, boolean)}
  • + *
+ * + * @author Trinea 2013-5-16 + */ +public class ShellUtils { + public static final String COMMAND_SU = "su"; + public static final String COMMAND_XIXUNSU = "xixunsu"; + private static final String COMMAND_SH = "sh"; + private static final String COMMAND_EXIT = "exit\n"; + private static final String COMMAND_LINE_END = "\n"; + public static boolean xixunsu = true;//false;// + + /** + * check whether has root permission + * + * @return + */ + public static boolean checkRootPermission() { + return execCommand("echo root", true, false).result == 0; + } + + /** + * execute shell command, default return result msg + * + * @param command command + * @param isRoot whether need to run with root + * @return + * @see ShellUtils#execCommand(String[], boolean, boolean) + */ + public static CommandResult execCommand(String command, boolean isRoot) { + return execCommand(new String[] {command}, isRoot, true); + } + + /** + * execute shell commands, default return result msg + * + * @param commands command list + * @param isRoot whether need to run with root + * @return + * @see ShellUtils#execCommand(String[], boolean, boolean) + */ + public static CommandResult execCommand(List commands, boolean isRoot) { + return execCommand(commands == null ? null : commands.toArray(new String[] {}), isRoot, true); + } + + /** + * execute shell commands, default return result msg + * + * @param commands command array + * @param isRoot whether need to run with root + * @return + * @see ShellUtils#execCommand(String[], boolean, boolean) + */ + public static CommandResult execCommand(String[] commands, boolean isRoot) { + return execCommand(commands, isRoot, true); + } + + /** + * execute shell command + * + * @param command command + * @param isRoot whether need to run with root + * @param isNeedResultMsg whether need result msg + * @return + * @see ShellUtils#execCommand(String[], boolean, boolean) + */ + public static CommandResult execCommand(String command, boolean isRoot, boolean isNeedResultMsg) { + return execCommand(new String[] {command}, isRoot, isNeedResultMsg); + } + + /** + * execute shell commands + * + * @param commands command list + * @param isRoot whether need to run with root + * @param isNeedResultMsg whether need result msg + * @return + * @see ShellUtils#execCommand(String[], boolean, boolean) + */ + public static CommandResult execCommand(List commands, boolean isRoot, boolean isNeedResultMsg) { + return execCommand(commands == null ? null : commands.toArray(new String[] {}), isRoot, isNeedResultMsg); + } + + /** + * execute shell commands + * + * @param commands command array + * @param isRoot whether need to run with root + * @param isNeedResultMsg whether need result msg + * @return
    + *
  • if isNeedResultMsg is false, {@link CommandResult#successMsg} is null and + * {@link CommandResult#errorMsg} is null.
  • + *
  • if {@link CommandResult#result} is -1, there maybe some excepiton.
  • + *
+ */ + public static CommandResult execCommand(String[] commands, boolean isRoot, boolean isNeedResultMsg) { + int result = -1; + String cmdSu = null; + + if (commands == null || commands.length == 0) { + return new CommandResult(result, null, null); + } + + Process process = null; + BufferedReader successResult = null; + BufferedReader errorResult = null; + StringBuilder successMsg = null; + StringBuilder errorMsg = null; + + DataOutputStream os = null; + try { + cmdSu = xixunsu? COMMAND_XIXUNSU: COMMAND_SU; + //modified by alahover 20190415 -start +// process = Runtime.getRuntime().exec(isRoot ? cmdSu : COMMAND_SH); + process = Runtime.getRuntime().exec(COMMAND_SH); + //masked process = Runtime.getRuntime().exec(COMMAND_SH);//isRoot ? cmdSu : COMMAND_SH); + //modified by alahover 20190415 -end + //process = Runtime.getRuntime().exec(isRoot ? cmdSu : COMMAND_SH); + + os = new DataOutputStream(process.getOutputStream()); + for (String command : commands) { + if (command == null) { + continue; + } + // donnot use os.writeBytes(commmand), avoid chinese charset error + os.writeBytes(command + COMMAND_LINE_END); + os.flush(); + } + os.writeBytes(COMMAND_EXIT); + os.flush(); + + result = process.waitFor(); + // get command result + if (isNeedResultMsg) { + successMsg = new StringBuilder(); + errorMsg = new StringBuilder(); + successResult = new BufferedReader(new InputStreamReader(process.getInputStream())); + errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream())); + String s; + while ((s = successResult.readLine()) != null) { + successMsg.append(s); + successMsg.append("\r\n"); + } + while ((s = errorResult.readLine()) != null) { + errorMsg.append(s); + errorMsg.append("\r\n"); + } + } + } catch (IOException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + if (os != null) { + os.close(); + } + if (successResult != null) { + successResult.close(); + } + if (errorResult != null) { + errorResult.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + + if (process != null) { + //process.destroy(); + } + } + return new CommandResult(result, successMsg == null ? null : successMsg.toString(), errorMsg == null ? null + : errorMsg.toString()); + } + + /** + * result of command + *
    + *
  • {@link CommandResult#result} means result of command, 0 means normal, else means error, same to excute in + * linux shell
  • + *
  • {@link CommandResult#successMsg} means success message of command result
  • + *
  • {@link CommandResult#errorMsg} means error message of command result
  • + *
+ * + * @author Trinea 2013-5-16 + */ + public static class CommandResult { + + /** result of command **/ + public int result; + /** success message of command result **/ + public String successMsg; + /** error message of command result **/ + public String errorMsg; + + public CommandResult(int result) { + this.result = result; + } + + public CommandResult(int result, String successMsg, String errorMsg) { + this.result = result; + this.successMsg = successMsg; + this.errorMsg = errorMsg; + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/xixun/display/utils/Utils.java b/app/src/main/java/com/xixun/display/utils/Utils.java new file mode 100644 index 0000000..e9d06d6 --- /dev/null +++ b/app/src/main/java/com/xixun/display/utils/Utils.java @@ -0,0 +1,29 @@ +package com.xixun.display.utils; + +public class Utils { + + public static void sleepForMillisecond(long ms) { + try { + Thread.sleep(ms); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + public static void sleepForSecond(long second) { + sleepForMillisecond(second * 1000); + } + + + + /** + * 获取一个int类型的值的bitNum位是多少 + * @param targetNum + * @param bitNum + * @return + */ + public static int getByBit(int targetNum, int bitNum) { + int tmpInt = 1 << bitNum - 1; + return (targetNum & tmpInt) / tmpInt; + } +} diff --git a/app/src/main/java/com/xixun/joey/aidlset/CardServiceObj.java b/app/src/main/java/com/xixun/joey/aidlset/CardServiceObj.java new file mode 100644 index 0000000..2458a6d --- /dev/null +++ b/app/src/main/java/com/xixun/joey/aidlset/CardServiceObj.java @@ -0,0 +1,58 @@ +package com.xixun.joey.aidlset; + +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.ServiceConnection; +import android.os.IBinder; + +import com.xixun.display.MyApp; +import com.xixun.display.MyLog; + +public class CardServiceObj { + + public static CardService cardService; + + public static void binderServer() { + //请仔细看服务端清单文件中的配置信息 + Intent intent = new Intent("com.xixun.joey.aidlset.SettingsService"); + intent.setPackage("com.xixun.joey.cardsystem"); + MyApp.getContext().bindService(intent,new ServiceConnection() { + @Override + //如果绑定成功回调此方法 + public void onServiceConnected(ComponentName name, IBinder service) { + MyLog.i("onServiceConnected..."); + cardService = CardService.Stub.asInterface(service); + MyApp.sleepForSecond(1); + if (cardService != null){ + MyLog.i("cardService is not null..."); + } + } + + @Override + //解除绑定,回调此方法 + public void onServiceDisconnected(ComponentName name) { + MyLog.i("onServiceDisconnected..."); + cardService=null; + } + }, Context.BIND_AUTO_CREATE); + MyLog.i("*********************************"); + } + + public static String executeJsonCommand(String json){ + try { + while (cardService == null){ + binderServer(); + MyLog.sleepForSecond(2); + if (cardService != null){ + break; + } + } + String result = cardService.executeJsonCommand(json); + return result; + } catch (Exception e) { + e.printStackTrace(); + return e.toString(); + } + } +} diff --git a/app/src/main/java/com/xixun/joey/uart/BytesData.java b/app/src/main/java/com/xixun/joey/uart/BytesData.java new file mode 100644 index 0000000..8c55ea0 --- /dev/null +++ b/app/src/main/java/com/xixun/joey/uart/BytesData.java @@ -0,0 +1,57 @@ +package com.xixun.joey.uart; + +import android.os.Parcel; +import android.os.Parcelable; + +public class BytesData implements Parcelable { + private byte[] data; + + public BytesData() { + data = new byte[1]; + } + + public BytesData(byte[] data) { + if (null != data) { + this.data = data; + } else { + this.data = new byte[1]; + } + } + + public BytesData(Parcel source) { + readFromParcel(source); + } + + public byte[] getData() { + return data; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(data.length); + dest.writeByteArray(data); + } + + public void readFromParcel(Parcel in) { + data = new byte[in.readInt()]; + in.readByteArray(data); + } + + public static final Creator CREATOR = new Creator() { + + @Override + public BytesData createFromParcel(Parcel source) { + return new BytesData(source); + } + + @Override + public BytesData[] newArray(int size) { + return new BytesData[size]; + } + }; +} diff --git a/app/src/main/java/com/xixun/lededitor/FrameBuffer.java b/app/src/main/java/com/xixun/lededitor/FrameBuffer.java new file mode 100644 index 0000000..0bd01d7 --- /dev/null +++ b/app/src/main/java/com/xixun/lededitor/FrameBuffer.java @@ -0,0 +1,42 @@ +package com.xixun.lededitor; + +import java.io.FileDescriptor; + +/** + * Created by Administrator on 2018/07/04. + */ + +public class FrameBuffer { + static String DeviceName="/dev/graphics/fb0"; + FileDescriptor fileDescriptor=null; + String deviceName=DeviceName; + + + static { + System.loadLibrary("FrameBuffer");// 在java代码中引入libs目录下的库函数,文件名为【libhello.so】。注意,引入时的文件名要去掉前面的lib和后面的.so + } + + public FrameBuffer() { + DeveiceOpen(); + } + + + void DeveiceOpen() + { + //Define.SetFileAuthority(true,deviceName); + fileDescriptor=Open(deviceName); + if (fileDescriptor==null) + System.out.println("Open Device Fail:"+deviceName); + else System.out.println("Open Device Success:"+deviceName); + } + + public int DeveiceWrite(int [] Databuffer,int iOffset,int iLength) + { + return Write(Databuffer,iOffset,iLength); + } + + + public native FileDescriptor Open(String deviceName); + public native int Write(int [] Databuffer,int iOffset,int iLength); + public native int Close(); +} diff --git a/app/src/main/java/com/xixun/lededitor/Multi.java b/app/src/main/java/com/xixun/lededitor/Multi.java new file mode 100644 index 0000000..1ea9870 --- /dev/null +++ b/app/src/main/java/com/xixun/lededitor/Multi.java @@ -0,0 +1,18 @@ +package com.xixun.lededitor; + +/** + * Created by Administrator on 2018/07/07. + */ + +public class Multi { + + + static { + System.loadLibrary("Multi"); + } + + public Multi() { + Start(); + } + public native int Start(); +} diff --git a/app/src/main/java/com/xixun/smartled/mainkit/HandlerPoster.java b/app/src/main/java/com/xixun/smartled/mainkit/HandlerPoster.java new file mode 100644 index 0000000..5a121c9 --- /dev/null +++ b/app/src/main/java/com/xixun/smartled/mainkit/HandlerPoster.java @@ -0,0 +1,122 @@ +package com.xixun.smartled.mainkit; + +import android.os.Handler; +import android.os.Looper; +import android.os.Message; +import android.os.SystemClock; + +import java.util.LinkedList; +import java.util.Queue; + +public class HandlerPoster extends Handler { + private final Queue asyncPool; + private final Queue syncPool; + private final int maxMillisInsideHandleMessage; + private boolean asyncActive; + private boolean syncActive; + + HandlerPoster(Looper looper, int maxMillisInsideHandleMessage) { + super(looper); + this.maxMillisInsideHandleMessage = maxMillisInsideHandleMessage; + asyncPool = new LinkedList(); + syncPool = new LinkedList(); + } + + void dispose() { + this.removeCallbacksAndMessages(null); + this.asyncPool.clear(); + this.syncPool.clear(); + } + + void async(Runnable runnable) { + synchronized (asyncPool) { + asyncPool.offer(runnable); + if (!asyncActive) { + asyncActive = true; + if (!sendMessage(obtainMessage(0, PostMethod.ASYNC))) { + throw new RuntimeException("Could not send handler message"); + } + } + } + } + + void sync(SyncPost post) { + synchronized (syncPool) { + syncPool.offer(post); + if (!syncActive) { + syncActive = true; + if (!sendMessage(obtainMessage(0, PostMethod.SYNC))) { + throw new RuntimeException("Could not send handler message"); + } + } + } + } + + @Override + public void handleMessage(Message msg) { + boolean rescheduled = false; + switch ((PostMethod)msg.obj) { + case ASYNC: + try { + long started = SystemClock.uptimeMillis(); + while (true) { + Runnable runnable = asyncPool.poll(); + if (runnable == null) { + synchronized (asyncPool) { + // Check again, this time in synchronized + runnable = asyncPool.poll(); + if (runnable == null) { + asyncActive = false; + break; + } + } + } + runnable.run(); + long timeInMethod = SystemClock.uptimeMillis() - started; + if (timeInMethod >= maxMillisInsideHandleMessage) { + if (!sendMessage(obtainMessage(0, PostMethod.ASYNC))) { + throw new RuntimeException("Could not send handler message"); + } + rescheduled = true; + break; + } + } + } finally { + asyncActive = rescheduled; + } + break; + case SYNC: + try { + long started = SystemClock.uptimeMillis(); + while (true) { + SyncPost post = syncPool.poll(); + if (post == null) { + synchronized (syncPool) { + // Check again, this time in synchronized + post = syncPool.poll(); + if (post == null) { + syncActive = false; + break; + } + } + } + post.run(); + long timeInMethod = SystemClock.uptimeMillis() - started; + if (timeInMethod >= maxMillisInsideHandleMessage) { + if (!sendMessage(obtainMessage(0, PostMethod.SYNC))) { + throw new RuntimeException("Could not send handler message"); + } + rescheduled = true; + break; + } + } + } finally { + syncActive = rescheduled; + } + break; + default: + super.handleMessage(msg); + break; + } + } +} diff --git a/app/src/main/java/com/xixun/smartled/mainkit/MainThreadKit.java b/app/src/main/java/com/xixun/smartled/mainkit/MainThreadKit.java new file mode 100644 index 0000000..d2a8163 --- /dev/null +++ b/app/src/main/java/com/xixun/smartled/mainkit/MainThreadKit.java @@ -0,0 +1,58 @@ +package com.xixun.smartled.mainkit; + +import android.os.Looper; + +public class MainThreadKit { + private static HandlerPoster mainPoster; + + private static HandlerPoster getMainPoster() { + if (mainPoster == null) { + synchronized (MainThreadKit.class) { + if (mainPoster == null) { + mainPoster = new HandlerPoster(Looper.getMainLooper(), 20); + } + } + } + return mainPoster; + } + + /** + * Asynchronously + * The child thread asynchronous run relative to the main thread, + * not blocking the child thread + * + * @param runnable Runnable Interface + */ + public static void runOnMainThreadAsync(Runnable runnable) { + if (Looper.myLooper() == Looper.getMainLooper()) { + runnable.run(); + return; + } + getMainPoster().async(runnable); + } + + /** + * Synchronously + * The child thread relative thread synchronization operation, + * blocking the child thread, + * thread for the main thread to complete + * + * @param runnable Runnable Interface + */ + public static void runOnMainThreadSync(Runnable runnable) { + if (Looper.myLooper() == Looper.getMainLooper()) { + runnable.run(); + return; + } + SyncPost poster = new SyncPost(runnable); + getMainPoster().sync(poster); + poster.waitRun(); + } + + public static void dispose() { + if (mainPoster != null) { + mainPoster.dispose(); + mainPoster = null; + } + } +} diff --git a/app/src/main/java/com/xixun/smartled/mainkit/PostMethod.java b/app/src/main/java/com/xixun/smartled/mainkit/PostMethod.java new file mode 100644 index 0000000..5a01e75 --- /dev/null +++ b/app/src/main/java/com/xixun/smartled/mainkit/PostMethod.java @@ -0,0 +1,6 @@ +package com.xixun.smartled.mainkit; + +public enum PostMethod { + SYNC, + ASYNC +} diff --git a/app/src/main/java/com/xixun/smartled/mainkit/SyncPost.java b/app/src/main/java/com/xixun/smartled/mainkit/SyncPost.java new file mode 100644 index 0000000..d55a255 --- /dev/null +++ b/app/src/main/java/com/xixun/smartled/mainkit/SyncPost.java @@ -0,0 +1,36 @@ +package com.xixun.smartled.mainkit; + +public class SyncPost { + private boolean end = false; + private Runnable runnable; + + SyncPost(Runnable runnable) { + this.runnable = runnable; + } + + public void run() { + synchronized (this) { + runnable.run(); + end = true; + try { + this.notifyAll(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + public void waitRun() { + if (!end) { + synchronized (this) { + if (!end) { + try { + this.wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } + } +} diff --git a/app/src/main/java/com/xixun/unique/BoardCard.java b/app/src/main/java/com/xixun/unique/BoardCard.java new file mode 100644 index 0000000..b846eec --- /dev/null +++ b/app/src/main/java/com/xixun/unique/BoardCard.java @@ -0,0 +1,103 @@ +package com.xixun.unique; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; + + +import android.os.SystemProperties; +import android.util.Log; + +import com.xixun.display.MyLog; + +/** + * 根据读到的卡设备判断不同的CardType型号 + * @author xixun + * + */ +public class BoardCard { + private static final String TAG = "DisPlayAPP"; + + public byte[] readFile(String fileName) { + FileInputStream fis = null; + byte[] content = null; + + try { + fis = new FileInputStream(fileName); + content = new byte[fis.available()]; + fis.read(content); + fis.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + return content; + } + + public CardType getCardType() { + CardType type = CardType.UNKNOWN; + String product = android.os.Build.PRODUCT; + String device = android.os.Build.DEVICE; + String model = android.os.Build.MODEL; + String display = android.os.Build.DISPLAY; + + if (product.equals("sugar_ref001") && device.equals("sugar-ref001") && model.equals("QY-A20")) { + type = CardType.B; + } else if (product.equals("full_mini210") && device.equals("mini210") && model.equals("Full Android on MINI210")) { + type = CardType.Y; + File file = new File("/data/joey/recovery/devicepara"); + if (file.exists()) { + byte[] readBytes = readFile(file.getAbsolutePath()); + String content = new String(readBytes); + if (content.contains("framerate = 30") + && content.contains("width = 1280") + && content.contains("height = 1024")) { + type = CardType.Z; + } + } + } else if (product.equals("simcom72_cwet_kk") && device.equals("simcom72_cwet_kk") && model.equals("simcom72_cwet_kk")) { + type = display.startsWith("ALPS.KK1.MP7.SIM5000A")? CardType.F: CardType.E; + } else if (product.equals("sugar_ref001") && device.equals("sugar-ref001") && model.equals("M2-XIXUN")) { + type = CardType.L; + } else if (product.equals("octopus_f1") && device.equals("octopus-f1")) { + if (model.equals("M6") || model.equals("M7")) { + type = CardType.N; + } + } else if ((product.equals("full_instk8735_6t") && device.equals("instk8735_6t") && model.equals("instk8735_6t")) + || (product.equals("full_instk8735_3t") && device.equals("instk8735_3t") && model.equals("instk8735_3t"))) { + if ("MRA58K test-keys".equals(display) || "SHXX_540".equals(display)) { + type = CardType.Q; + } else if ("SHXX_540_SPI".equals(display) || "full_instk8735_6t-eng 6.0 MRA58K 1536144349 test-keys".equals(display)) { + type = CardType.P; + } + } else if (product.equals("aosp_nanopi2") && device.equals("nanopi2") && model.equals("AOSP on NanoPi 2")) { + String rilSo = "/system/lib/libhuawei-ril.so"; + type = rilSo.equals(SystemProperties.get("rild.libpath", rilSo))? CardType.X: CardType.W; +// type = CardType.X; + } else if (product.equalsIgnoreCase("full_instk8735_32t_ei") && device.equals("instk8735_32t") && model.equals("instk8735_32t")) { + type = CardType.M; + }else if (product.equalsIgnoreCase("msm8909_ei") && device.equals("msm8909") && model.equals("msm8909")) { + type = CardType.M;//7.1 + }else if (product.equals("rk3288") && device.equals("rk3288") && model.equals("rk3288")) { + type = CardType.D; + }else if (device.equals("rk3288") && (product.equals("rk3288_1") || model.equals("rk3288_1"))) { + type = CardType.D; + }else if (product.equals("rk3288_2") && device.equals("rk3288") && model.equals("rk3288")) { + type = CardType.D_2; + }else if (product.equals("rk3326_evb") && device.equals("rk3326_evb") && model.equals("rk3326_evb")) { + type = CardType.C; + } + MyLog.i("type:"+type+";product:"+product+";device:"+device+";model:"+model+";display:"+display); + if (type == CardType.UNKNOWN) { + Log.d(TAG, "Product: " + product); + Log.d(TAG, "Device: " + device); + Log.d(TAG, "Model: " + model); + Log.d(TAG, "Display: " + display); + } + + return type; + } +} diff --git a/app/src/main/java/com/xixun/unique/CardType.java b/app/src/main/java/com/xixun/unique/CardType.java new file mode 100644 index 0000000..da794f4 --- /dev/null +++ b/app/src/main/java/com/xixun/unique/CardType.java @@ -0,0 +1,29 @@ +package com.xixun.unique; + +public enum CardType { + B, // A20 + Moonsell or M60 + C, //PX30 + D, //3288 30.2 + D_1, //3288 31.1 + D_2, + D_ZC, //ZC_328 + D_ZD, //ZC_339 + E, // SIM5000 + F, // SIM5000A + L, // GuoRui M2 + M, // MeiGe19.2 + M_F, // MeiGe19.6 + M_EI, // MeiGe + M_EI7, // MeiGe 7.1 + N, // GuoRui + P, // YiKe 540x960_SPI + Q, // YiKe 540x960 15.4 + R, // mooncell_mid + R_1, // mooncell_box + W, // Friendlyarm 4418 移远模块 + X, // Friendlyarm 4418 华为模块 + Y, // Friendlyarm smart210(Y10) + Z, // Friendlyarm smart210(Y20) + UNKNOWN +} + \ No newline at end of file diff --git a/app/src/main/java/com_xixun_communicate_SpiDevice.h b/app/src/main/java/com_xixun_communicate_SpiDevice.h new file mode 100644 index 0000000..f8f5d7d --- /dev/null +++ b/app/src/main/java/com_xixun_communicate_SpiDevice.h @@ -0,0 +1,45 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class com_xixun_communicate_SpiDevice */ + +#ifndef _Included_com_xixun_communicate_SpiDevice +#define _Included_com_xixun_communicate_SpiDevice +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: com_xixun_communicate_SpiDevice + * Method: Open + * Signature: (Ljava/lang/String;I)Ljava/io/FileDescriptor; + */ +JNIEXPORT jobject JNICALL Java_com_xixun_communicate_SpiDevice_Open + (JNIEnv *, jobject, jstring, jint); + +/* + * Class: com_xixun_communicate_SpiDevice + * Method: Read + * Signature: ([BI)I + */ +JNIEXPORT jint JNICALL Java_com_xixun_communicate_SpiDevice_Read + (JNIEnv *, jobject, jbyteArray, jint); + +/* + * Class: com_xixun_communicate_SpiDevice + * Method: Write + * Signature: ([BI)I + */ +JNIEXPORT jint JNICALL Java_com_xixun_communicate_SpiDevice_Write + (JNIEnv *, jobject, jbyteArray, jint); + +/* + * Class: com_xixun_communicate_SpiDevice + * Method: Close + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_com_xixun_communicate_SpiDevice_Close + (JNIEnv *, jobject); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/app/src/main/java/com_xixun_lededitor_FrameBuffer.h b/app/src/main/java/com_xixun_lededitor_FrameBuffer.h new file mode 100644 index 0000000..51203fe --- /dev/null +++ b/app/src/main/java/com_xixun_lededitor_FrameBuffer.h @@ -0,0 +1,29 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class com_xixun_lededitor_FrameBuffer */ + +#ifndef _Included_com_xixun_lededitor_FrameBuffer +#define _Included_com_xixun_lededitor_FrameBuffer +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: com_xixun_lededitor_FrameBuffer + * Method: Open + * Signature: (Ljava/lang/String;I)Ljava/io/FileDescriptor; + */ +JNIEXPORT jobject JNICALL Java_com_xixun_lededitor_FrameBuffer_Open + (JNIEnv *, jobject, jstring, jint); + +/* + * Class: com_xixun_lededitor_FrameBuffer + * Method: Close + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_com_xixun_lededitor_FrameBuffer_Close + (JNIEnv *, jobject); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/app/src/main/java/com_xixun_lededitor_Multi.h b/app/src/main/java/com_xixun_lededitor_Multi.h new file mode 100644 index 0000000..6e90cf1 --- /dev/null +++ b/app/src/main/java/com_xixun_lededitor_Multi.h @@ -0,0 +1,21 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class com_xixun_lededitor_Multi */ + +#ifndef _Included_com_xixun_lededitor_Multi +#define _Included_com_xixun_lededitor_Multi +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: com_xixun_lededitor_Multi + * Method: Start + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_com_xixun_lededitor_Multi_Start + (JNIEnv *, jobject); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/app/src/main/java/jni/Android.mk b/app/src/main/java/jni/Android.mk new file mode 100644 index 0000000..34e6804 --- /dev/null +++ b/app/src/main/java/jni/Android.mk @@ -0,0 +1,2 @@ +# 最外层的mk 这一句的意思是执行内层文件下的所有mk文件 +include $(call all-subdir-makefiles) \ No newline at end of file diff --git a/app/src/main/java/jni/Application.mk b/app/src/main/java/jni/Application.mk new file mode 100644 index 0000000..3a26f35 --- /dev/null +++ b/app/src/main/java/jni/Application.mk @@ -0,0 +1,5 @@ +APP_ABI := armeabi armeabi-v7a +#armeabi x86 +#Application.mk文件的目的是,描述在你的应用程序中所有需要的模块(即静态库或动态库) +#APP_ABI 的值以空格区分,代表要支持的架构,默认值为【armeabi】。其他架构,ARMv7 【armeabi-v7a】;IA-32【 x86】 +#每增加一个架构,编译后都会在lib目录下生成一个相应的文件夹,文件夹下的文件都是同名的.so文件(当然文件内容不一样) \ No newline at end of file diff --git a/app/src/main/java/jni/FrameBuffer/Android.mk b/app/src/main/java/jni/FrameBuffer/Android.mk new file mode 100644 index 0000000..46c9b00 --- /dev/null +++ b/app/src/main/java/jni/FrameBuffer/Android.mk @@ -0,0 +1,11 @@ +LOCAL_PATH := $(call my-dir) +# C/C++代码所在目录,也就是我们的jni目录,不必修改 +include $(CLEAR_VARS) +LOCAL_MODULE :=FrameBuffer +# 对应打包成函数库的名字,编译器会自动在前面加上lib,在后面加上.so,最终结果就是libhello.so +LOCAL_SRC_FILES := FrameBuffer.c + +LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -llog +# 对应的c代码的文件名,即FrameBuffer.c +include $(BUILD_SHARED_LIBRARY) +LOCAL_JNI_SHARED_LIBRARIES := libFrameBuffer \ No newline at end of file diff --git a/app/src/main/java/jni/FrameBuffer/FrameBuffer.c b/app/src/main/java/jni/FrameBuffer/FrameBuffer.c new file mode 100644 index 0000000..75831e8 --- /dev/null +++ b/app/src/main/java/jni/FrameBuffer/FrameBuffer.c @@ -0,0 +1,189 @@ +// +// Created by Administrator on 2018/07/04. +// + +#include "FrameBuffer.h" + + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include /* or */ +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + + +#include + + +#include +static const char *TAG="Framebuffer"; +#define LOGI(fmt, args...) __android_log_print(ANDROID_LOG_INFO, TAG, fmt, ##args) +#define LOGD(fmt, args...) __android_log_print(ANDROID_LOG_DEBUG, TAG, fmt, ##args) +#define LOGE(fmt, args...) __android_log_print(ANDROID_LOG_ERROR, TAG, fmt, ##args) + + +int iFileHandle=0; +jobject mFileDescriptor=NULL; +unsigned int * fbp=NULL; +int screensize=0; +struct fb_fix_screeninfo finfo; +struct fb_var_screeninfo vinfo; + +JNIEXPORT jobject JNICALL Java_com_xixun_lededitor_FrameBuffer_Open(JNIEnv * env, jobject obj, jstring deviceName) + { int iWorkResault=-1; + + { + jboolean isCopy; + const char * pDeviceName= (*env)->GetStringUTFChars(env, deviceName, &isCopy); + LOGD("Open %s.", pDeviceName); + iFileHandle = open(pDeviceName, O_RDWR); + + // modified byfw 2019-4-19 ------------start + (*env)->ReleaseStringUTFChars(env, deviceName, pDeviceName); + // modified byfw 2019-4-19 ------------end + + + if (iFileHandle<0) + { + /* Throw an exception */ + LOGE("Can't open device:%s",deviceName); + /* TODO: throw an exception */ + return NULL; + } + // (*env)->ReleaseStringUTFChars(env, deviceName, pDeviceName); + } + + { + + + + jint location; + if (ioctl(iFileHandle, FBIOGET_FSCREENINFO, &finfo)) { + LOGE("Error reading fixed information.\n"); + return NULL; + } + // Get variable screen information + if (ioctl(iFileHandle, FBIOGET_VSCREENINFO, &vinfo)) { + LOGE("Error reading variable information.\n"); + return NULL; + } + screensize = finfo.smem_len; + LOGD("screensize 0x%X.", screensize); + // screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel >> 3 // >>3 表示算出字节数 + fbp = (unsigned int * )mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED,iFileHandle, 0); + if ((int)fbp == -1) { + LOGE("Error: failed to map framebuffer device to memory.\n"); + return NULL; + } + } + + { + jclass cFileDescriptor = (*env)->FindClass(env, "java/io/FileDescriptor"); + jmethodID iFileDescriptor = (*env)->GetMethodID(env, cFileDescriptor, "", "()V"); + jfieldID descriptorID = (*env)->GetFieldID(env, cFileDescriptor, "descriptor", "I"); + mFileDescriptor = (*env)->NewObject(env, cFileDescriptor, iFileDescriptor); + (*env)->SetIntField(env, mFileDescriptor, descriptorID, (jint)iFileHandle); + + (*env)->DeleteLocalRef(env,cFileDescriptor); + } + + return mFileDescriptor; + } + +int bFirstFrameBuffer=0; +JNIEXPORT jint JNICALL Java_com_xixun_lededitor_FrameBuffer_Write(JNIEnv * env, jobject obj, jintArray Databuffer, jint iOffset, jint iLength) +{ + if (iOffset<0) return -1; + if (iOffset>screensize/sizeof(int)/2) return -1; + + if (iLength<=0) return -1; + if (iLength>screensize/sizeof(int)/2) iLength=screensize/sizeof(int)/2; + + if (iFileHandle<=0) return -1; + if (Databuffer==NULL) return -1; + + //LOGD("FrameBuffer_Write iLength=%d.",iLength); + + jint * array= (*env)->GetIntArrayElements(env,Databuffer,0); + + { iOffset+=(bFirstFrameBuffer? 0 : (screensize/sizeof(int)/2)); + } + + { int i=0; + for (i=0;iReleaseIntArrayElements(env,Databuffer,array,0); + bFirstFrameBuffer= (bFirstFrameBuffer)?0:1; + return 0; +} +/* + * Class: com_xixun_lededitor_FrameBuffer + * Method: Close + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_com_xixun_lededitor_FrameBuffer_Close(JNIEnv * env, jobject obj) +{ + munmap(fbp, screensize); + close(iFileHandle); + (*env)->DeleteLocalRef(env,mFileDescriptor); + return 0; +} \ No newline at end of file diff --git a/app/src/main/java/jni/FrameBuffer/FrameBuffer.h b/app/src/main/java/jni/FrameBuffer/FrameBuffer.h new file mode 100644 index 0000000..050e713 --- /dev/null +++ b/app/src/main/java/jni/FrameBuffer/FrameBuffer.h @@ -0,0 +1,37 @@ +// +// Created by Administrator on 2018/07/04. +// + +#ifndef WAITINGWORK_FRAMEBUFFER_H +#define WAITINGWORK_FRAMEBUFFER_H +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class com_xixun_lededitor_FrameBuffer */ + +#ifndef _Included_com_xixun_lededitor_FrameBuffer +#define _Included_com_xixun_lededitor_FrameBuffer +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: com_xixun_lededitor_FrameBuffer + * Method: Open + * Signature: (Ljava/lang/String;I)Ljava/io/FileDescriptor; + */ +JNIEXPORT jobject JNICALL Java_com_xixun_lededitor_FrameBuffer_Open + (JNIEnv *, jobject, jstring); + +/* + * Class: com_xixun_lededitor_FrameBuffer + * Method: Close + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_com_xixun_lededitor_FrameBuffer_Close + (JNIEnv *, jobject); + +#ifdef __cplusplus +} +#endif +#endif + +#endif //WAITINGWORK_FRAMEBUFFER_H diff --git a/app/src/main/java/jni/HardwareControler/Android.mk b/app/src/main/java/jni/HardwareControler/Android.mk new file mode 100644 index 0000000..0496064 --- /dev/null +++ b/app/src/main/java/jni/HardwareControler/Android.mk @@ -0,0 +1,11 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := $(call all-subdir-java-files) + +LOCAL_PACKAGE_NAME := LCD1602 + +LOCAL_CERTIFICATE := platform +LOCAL_MODULE_TAGS := eng + +include $(BUILD_PACKAGE) diff --git a/app/src/main/java/jni/JniOperator.txt b/app/src/main/java/jni/JniOperator.txt new file mode 100644 index 0000000..9563b05 --- /dev/null +++ b/app/src/main/java/jni/JniOperator.txt @@ -0,0 +1,101 @@ +、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、 +Jni调用程序步骤: +1:从安卓编辑编译环境的Terminal命令窗口,进入项目com目录的上一级目录: +D: +cd D:\Project\Display\app\src\main\java + +2:在项目总新建与jni同名的SpiDevice.java类;内部声明要用到的本地化C语言函数名称; + +3:编译生成头文件,com_xixun_communicate_SpiDevice.h,用于在C语言中创建符合Java规范的同名函数: +javah com.xixun.lededitor.Multi + +4:在com目录的上一级建立jni目录, + 建立编译平台文件:Application.mk + 建立总库编译文件:Android.mk + + 建立jni\SpiDevice目录: + 建立SpiDevice.c文件, + 建立库编译文件:Android.mk + +5:命令行输入,编译并生成库文件: +C:\Users\Administrator\AppData\Local\Android\Sdk\ndk-bundle\ndk-build.cmd + +6:复制库文件到安装目录中: +xcopy D:\Project\Display\app\src\main\java\libs /e D:\Project\Display\app\libs\ /y + + +、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、 + + +7.在使用的地方动态加载动态库: + static { + System.loadLibrary("SpiDevice");// 在java代码中引入libs目录下的库函数,文件名为【libhello.so】。注意,引入时的文件名要去掉前面的lib和后面的.so + } + + + + + + + + + + + + + + + + + + + + + +、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、 +5:复制libSpi.so到Y卡/system/lib/目录下: +E: +cd E:\Download\Android\adbgjb_24069\adb +adb shell + +E:\Download\Android\adbgjb_24069\adb\adb shell +chmod 777 /system/lib/libSpiDevice.so +E:\Download\Android\adbgjb_24069\adb\adb push D:\Project\waitingwork\app\src\main\java\libs\armeabi-v7a\libSpiDevice.so /mnt/sdcard/Sysolution/ReceFiles + + +6.在使用的地方动态加载动态库: + static { + System.loadLibrary("SpiDevice");// 在java代码中引入libs目录下的库函数,文件名为【libhello.so】。注意,引入时的文件名要去掉前面的lib和后面的.so + } + + + +E: +cd E:\Download\Android\adbgjb_24069\adb + +adb shell +adb connect 192.168.0.254:5555 +adb connect 192.168.0.83 + +M50、M60: + /data/data/com.xixun.display/files/Sysolution/WorkFiles/ +E:\Download\Android\adbgjb_24069\adb\adb push D:\nfs\c001.rpd /mnt/sdcard/Sysolution/ReceFiles +E:\Download\Android\adbgjb_24069\adb\adb push D:\nfs\c002.rpd /mnt/sdcard/Sysolution/ReceFiles +E:\Download\Android\adbgjb_24069\adb\adb push D:\nfs\c003.rpd /mnt/sdcard/Sysolution/ReceFiles +E:\Download\Android\adbgjb_24069\adb\adb push D:\nfs\c004.rpd /mnt/sdcard/Sysolution/ReceFiles + +Y卡: +E:\Download\Android\adbgjb_24069\adb\adb push D:\nfs\c003.rpd /Sysolution/ReceFiles +E:\Download\Android\adbgjb_24069\adb\adb push D:\nfs\c004.rpd /Sysolution/ReceFiles + +解决设备权限为777还不能访问的命令: setenforce 0 + + +adb uninstall com.xixun.joey.cardsystem +adb uninstall com.xixun.joey.systemcore +adb shell rm /system/app/CardSystem* +adb shell rm /system/app/SystemCore* +adb shell reboot + +cp d:\nfs\c00*.rpd /Sysolution/ReceFiles/ +E:\Download\Android\adbgjb_24069\adb push d:\nfs\c00*.rpd /Sysolution/ReceFiles/ diff --git a/app/src/main/java/jni/Multi/Android.mk b/app/src/main/java/jni/Multi/Android.mk new file mode 100644 index 0000000..7625069 --- /dev/null +++ b/app/src/main/java/jni/Multi/Android.mk @@ -0,0 +1,50 @@ +LOCAL_PATH := $(call my-dir) +# C/C++代码所在目录,也就是我们的jni目录,不必修改 + +include $(CLEAR_VARS) + +LOCAL_MODULE :=Multi +# 对应打包成函数库的名字,编译器会自动在前面加上lib,在后面加上.so,最终结果就是libhello.so + +LOCAL_SRC_FILES := Multi.c + +LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -llog +# 对应的c代码的文件名,Multi.c +include $(BUILD_SHARED_LIBRARY) +LOCAL_JNI_SHARED_LIBRARIES := libMulti + + + + +##LOCAL_PATH := $(call my-dir) +# C/C++代码所在目录,也就是我们的jni目录,不必修改 +##include $(CLEAR_VARS) +##LOCAL_MODULE :=Multi +# 对应打包成函数库的名字,编译器会自动在前面加上lib,在后面加上.so,最终结果就是libhello.so + +# 扫描目录下的所有源文件,引入多个目录(包括子目录)下的多个后缀名的源文件 +##MY_FILES_PATH := $(LOCAL_PATH) \ +## $(LOCAL_PATH)/../../Classes + +##MY_FILES_SUFFIX := %.cpp %.c %.cc + +##My_All_Files := $(foreach src_path,$(MY_FILES_PATH), $(shell find "$(src_path)" -type f) ) +##My_All_Files := $(My_All_Files:$(MY_CPP_PATH)/./%=$(MY_CPP_PATH)%) +##MY_SRC_LIST := $(filter $(MY_FILES_SUFFIX),$(My_All_Files)) +##MY_SRC_LIST := $(MY_SRC_LIST:$(LOCAL_PATH)/%=%) +#LOCAL_SRC_FILES := $(MY_SRC_LIST) +##LOCAL_SRC_FILES := Multi.c +#以上代码中,变量MY_FILES_PATH保存源文件所在目录,MY_FILES_SUFFIX保存源文件的后缀名 + +##LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -llog +# 对应的c代码的文件名,即FrameBuffer.c + +##include $(BUILD_SHARED_LIBRARY) +##LOCAL_JNI_SHARED_LIBRARIES := libMulti + +#BUILD_STATIC_LIBRARY:编译为静态库。 +#BUILD_SHARED_LIBRARY :编译为动态库 +#BUILD_EXECUTABLE:编译为Native C可执行程序 +#在编译过程输出android.mk文件中变量的值,就可以观察分析问题所在了,使用代码 +##$(warning $(LOCAL_SRC_FILES)) +#就可以在编译过程中从终端窗口中观察到变量LOCAL_SRC_FILES的值 \ No newline at end of file diff --git a/app/src/main/java/jni/Multi/Multi.c b/app/src/main/java/jni/Multi/Multi.c new file mode 100644 index 0000000..3ee385d --- /dev/null +++ b/app/src/main/java/jni/Multi/Multi.c @@ -0,0 +1,9 @@ + +#include +#include "Multi.h" + +JNIEXPORT jint JNICALL Java_com_xixun_lededitor_Multi_Start(JNIEnv * env, jobject obj) +{ + RUN_TRACE; + return 0; +} diff --git a/app/src/main/java/jni/Multi/Multi.h b/app/src/main/java/jni/Multi/Multi.h new file mode 100644 index 0000000..b1089b1 --- /dev/null +++ b/app/src/main/java/jni/Multi/Multi.h @@ -0,0 +1,13 @@ +// +// Created by Administrator on 2018/07/07. +// + +#ifndef WAITINGWORK_MULTI_H +#define WAITINGWORK_MULTI_H + +/**/ +#define RUN_TRACE \ +{ printf("%s-->%s()-->L%d!\r\n",__FILE__,__FUNCTION__,__LINE__); \ +} + +#endif //WAITINGWORK_MULTI_H diff --git a/app/src/main/java/jni/SpiDevice/Android.mk b/app/src/main/java/jni/SpiDevice/Android.mk new file mode 100644 index 0000000..e9698a7 --- /dev/null +++ b/app/src/main/java/jni/SpiDevice/Android.mk @@ -0,0 +1,14 @@ +LOCAL_PATH := $(call my-dir) +# C/C++代码所在目录,也就是我们的jni目录,不必修改 + +include $(CLEAR_VARS) + +LOCAL_MODULE :=SpiDevice +# 对应打包成函数库的名字,编译器会自动在前面加上lib,在后面加上.so,最终结果就是libhello.so + +LOCAL_SRC_FILES := SpiDevice.c + +LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -llog +# 对应的c代码的文件名,即SpiDevice.c +include $(BUILD_SHARED_LIBRARY) +LOCAL_JNI_SHARED_LIBRARIES := libSpiDevice diff --git a/app/src/main/java/jni/SpiDevice/SpiDevice.c b/app/src/main/java/jni/SpiDevice/SpiDevice.c new file mode 100644 index 0000000..b1a71a2 --- /dev/null +++ b/app/src/main/java/jni/SpiDevice/SpiDevice.c @@ -0,0 +1,197 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#include +static const char *TAG="SpiDevice"; +#define LOGI(fmt, args...) __android_log_print(ANDROID_LOG_INFO, TAG, fmt, ##args) +#define LOGD(fmt, args...) __android_log_print(ANDROID_LOG_DEBUG, TAG, fmt, ##args) +#define LOGE(fmt, args...) __android_log_print(ANDROID_LOG_ERROR, TAG, fmt, ##args) + +int iFileHandle=0; +int iBaudRate=0; +jobject mFileDescriptor=NULL; + +struct spi_ioc_transfer spiIocTransfer = { + .delay_usecs = 0, + .speed_hz = 12*1000*1000, + .bits_per_word = 8, + }; + + +JNIEXPORT jobject JNICALL Java_com_xixun_communicate_SpiDevice_Open (JNIEnv * env, jobject obj, jstring deviceName, jint iBaudRate0,jint mode) +{ int iWorkResault=-1; + int ret ; + + iBaudRate=iBaudRate0; + spiIocTransfer.speed_hz=iBaudRate; + + { + jboolean isCopy; + const char * pDeviceName= (*env)->GetStringUTFChars(env, deviceName, &isCopy); + LOGD("SpiDevice.c Open %s. Baud Rate=%d", pDeviceName,iBaudRate0); + iFileHandle = open(pDeviceName, O_RDWR);//"/dev/spidev0.0",O_RDWR);// + // modified byfw 2019-4-19 ------------start + (*env)->ReleaseStringUTFChars(env, deviceName, pDeviceName); + // modified byfw 2019-4-19 ------------end + if (iFileHandle<0) + { + /* Throw an exception */ + LOGE("SpiDevice.c Can't open device:%s,Error:%s!",deviceName,strerror(errno));//); + /* TODO: throw an exception */ + return -1; + } + // (*env)->ReleaseStringUTFChars(env, deviceName, pDeviceName); + } + if (iBaudRate0>0) + { LOGD("SpiDevice.c Set spi max speed %d.",iBaudRate); + iWorkResault = ioctl(iFileHandle, SPI_IOC_WR_MAX_SPEED_HZ, &iBaudRate); + if (iWorkResault<0) + { LOGE("SpiDevice.c Can't set max send speed:%d bps",iBaudRate); + return NULL; + } + + iWorkResault = ioctl(iFileHandle, SPI_IOC_RD_MAX_SPEED_HZ, &iBaudRate); + if (iWorkResault<0) + { LOGE("SpiDevice.c Can't set max receive speed:%d bps",iBaudRate); + return NULL; + } + } + /*spi mode*/ + ret = ioctl(iFileHandle, SPI_IOC_WR_MODE32, &mode); + if (ret == -1) + LOGE("can't set spi WR mode"); + ret = ioctl(iFileHandle, SPI_IOC_RD_MODE32, &mode); + if (ret == -1) + LOGE("can't get spi RD mode"); + { + jclass cFileDescriptor = (*env)->FindClass(env, "java/io/FileDescriptor"); + jmethodID iFileDescriptor = (*env)->GetMethodID(env, cFileDescriptor, "", "()V"); + jfieldID descriptorID = (*env)->GetFieldID(env, cFileDescriptor, "descriptor", "I"); + mFileDescriptor = (*env)->NewObject(env, cFileDescriptor, iFileDescriptor); + (*env)->SetIntField(env, mFileDescriptor, descriptorID, (jint)iFileHandle); + + (*env)->DeleteLocalRef(env,cFileDescriptor); + } + + return mFileDescriptor; +} + +JNIEXPORT jint JNICALL Java_com_xixun_communicate_SpiDevice_Operator(JNIEnv * env, jobject obj, jbyteArray Databuffer, jint iLength) +{ + + int iWorkResault=-1; + if (iLength<=0) return iWorkResault; + if (iFileHandle<=0) return iWorkResault; + if (Databuffer==NULL) return iWorkResault; + + + jbyte* array= (*env)->GetByteArrayElements(env,Databuffer,0); + + spiIocTransfer.tx_buf=spiIocTransfer.rx_buf=(unsigned long)array; + spiIocTransfer.len=iLength; + iWorkResault=ioctl(iFileHandle, SPI_IOC_MESSAGE(1), &spiIocTransfer); + + (*env)->ReleaseByteArrayElements(env,Databuffer,array,0); + + return iWorkResault; + +} + + +JNIEXPORT jint JNICALL Java_com_xixun_communicate_SpiDevice_Trans(JNIEnv * env, jobject obj, jbyteArray sendBuf, jbyteArray recvBuf, jint iLength){ + int i = 0; + int iWorkResault = -1; + jbyte* sendArray= (*env)->GetByteArrayElements(env,sendBuf,0); + jbyte* recvArray= (*env)->GetByteArrayElements(env,recvBuf,0); + + spiIocTransfer.tx_buf=(unsigned long)sendArray; + spiIocTransfer.rx_buf=(unsigned long)recvArray; + spiIocTransfer.len=iLength; + + + + iWorkResault=ioctl(iFileHandle, SPI_IOC_MESSAGE(1), &spiIocTransfer); + for(; iReleaseByteArrayElements(env,sendBuf,sendArray,0); + (*env)->ReleaseByteArrayElements(env,recvBuf,recvArray,0); + return iWorkResault; +} + + +JNIEXPORT jint JNICALL Java_com_xixun_communicate_SpiDevice_Close(JNIEnv * env, jobject obj) +{ + close(iFileHandle); + //(*env)->DeleteLocalRef(env,mFileDescriptor); + return 0; +} + + + + +/* + +static void transfer() +{ + jint i=0,iCounter=0,ret=0; + uint8_t tx[32] = { + 0xAA, + 0x70,0x00,0x00, + + 0x00,0x20, + 0x00,0x00 + //0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + //0x40, 0x00, 0x00, 0x00, 0x00, 0x95, + //0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + //0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + //0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + //0xDE, 0xAD, 0xBE, 0xEF, 0xBA, 0xAD, + //0xF0, 0x0D, + }; + uint8_t rx[40] = {0, }; + + struct spi_ioc_transfer tr = { + .tx_buf = (unsigned long)tx, + .rx_buf = (unsigned long)rx, + .len = sizeof(tx), + .delay_usecs = 0, + .speed_hz = iBaudRate, + .bits_per_word = 8, + }; + +printf("Send:"); + for (i = 0; i < sizeof(tx); i++) { + if (!(i % 16)) + puts(""); + LOGD("%.2X ", tx[i]); + } + puts(""); + + for (i=0;i sources; + //如果该值为false,它会在播放时长到达后结束播放,否则他会循环播放直到list中最长的那个layer播放结束时结束播放 + public boolean repeat; +} diff --git a/app/src/main/java/program/Program.java b/app/src/main/java/program/Program.java new file mode 100644 index 0000000..f727aa3 --- /dev/null +++ b/app/src/main/java/program/Program.java @@ -0,0 +1,32 @@ +package program; + +import java.io.Serializable; +import java.util.List; + +public class Program implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = 1134231658567190712L; + public String id; //请使用UUID赋值 + public String name; //好记的名字(节目名字) + public int width; //节目宽 + public int height; //节目高度 + public String departmentId; //=空字符串 + public int repeat; //该属性定义它和其他节目轮流播放时它在该轮连续重复次数,如果只有它一个节目,那么赋值1和赋值大于1等效。 + public List schedules; //定时播放的时刻表 + public List layers; //所有素材都包含在该list中 + public boolean playSourceOnTime; //无意义 + public String commandId; //赋值null或空字符串 + public int priority; //决定多个节目时它的播放次序,数字越小优先级越高 + public int departmentPriority; //无意义 + public boolean loop; //无意义 + public boolean downloaded; //false + public long totalSize; //将layers中的sources的size累加赋值给他,表示节目所有素材占用的空间 + public String savePath; //无需赋值 + public boolean isOthers; //如果为true,则该节目来自第三方接口,不是来自我们自己的web,二次开发请务必赋值为true + public int __v; //=0 + public int version; //2为简易节目,9为定点节目,其他为高级节目,请赋值其他。 + +} diff --git a/app/src/main/java/program/Schedule.java b/app/src/main/java/program/Schedule.java new file mode 100644 index 0000000..1d08092 --- /dev/null +++ b/app/src/main/java/program/Schedule.java @@ -0,0 +1,35 @@ +package program; + +import java.io.Serializable; +import java.util.List; + +public class Schedule implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = -4674371293621169643L; + + public String name; //事件表名字 + + public DateType dateType; //参考DateType + + public String startDate; //起始日期 + + public String endDate; //结束日期 + + public TimeType timeType; //参考TimeType + + public String startTime; //起始时间 + + public String endTime; //结束时间 + + public FilterType filterType; //如果不按月或按星期几过滤请赋值null,参考FilterType + + public List weekFilter; //Sunday=1 + + public List monthFilter; //Jan=1 + + +} + diff --git a/app/src/main/java/program/Source.java b/app/src/main/java/program/Source.java new file mode 100644 index 0000000..7ac4911 --- /dev/null +++ b/app/src/main/java/program/Source.java @@ -0,0 +1,29 @@ +package program; + +import java.io.Serializable; + +public class Source implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = 438996068963825910L; + public String id; //UUID进行赋值 + public String md5; //素材如果有大小需要计算它的md5 + public String name; //素材名字 + public int left; //显示在左上角的坐标 + public int top; + public int width; //宽高 + public int height; + public long size; //文件大小 + public int paddingBefore; //无需关心 + public int playTime; //起始播放时间 + public int timeSpan; //持续播放时长 + public String url; //从其他链接下载素材 + public String localPath; //无需关心该属性 + public EffectType entryEffect; //入场特效 + public int entryEffectTimeSpan; //入场特效播放时长 + public EffectType exitEffect; //出场特效 + public int exitEffectTimeSpan; //出场特效播放时长 + public int index; //list中的索引值 +} diff --git a/app/src/main/java/program/Test.java b/app/src/main/java/program/Test.java new file mode 100644 index 0000000..5dcbab4 --- /dev/null +++ b/app/src/main/java/program/Test.java @@ -0,0 +1,26 @@ +package program; + + +import java.util.ArrayList; +import java.util.List; + +//import com.google.gson.Gson; + +public class Test { + + public static void main(String[] args) { + // TODO Auto-generated method stub + + //Program program = new Program(); + //String id = CreateUUID.getId(); + Source source = new Source(); + Layer layer = new Layer(); + layer.repeat = true; + List sources = new ArrayList(); + sources.add(source); + layer.sources = sources; + //Gson gson = new Gson(); + //String jsonData = gson.toJson(layer); + //System.out.println(jsonData); + } +} diff --git a/app/src/main/java/program/TimeType.java b/app/src/main/java/program/TimeType.java new file mode 100644 index 0000000..f70b9a5 --- /dev/null +++ b/app/src/main/java/program/TimeType.java @@ -0,0 +1,6 @@ +package program; + +public enum TimeType { + Range, //两个时间区间 + All //整个时间段 +} diff --git a/app/src/main/jniLibs/arm64-v8a/libFrameBuffer.so b/app/src/main/jniLibs/arm64-v8a/libFrameBuffer.so new file mode 100644 index 0000000..1927f40 Binary files /dev/null and b/app/src/main/jniLibs/arm64-v8a/libFrameBuffer.so differ diff --git a/app/src/main/jniLibs/arm64-v8a/libMulti.so b/app/src/main/jniLibs/arm64-v8a/libMulti.so new file mode 100644 index 0000000..413c0a8 Binary files /dev/null and b/app/src/main/jniLibs/arm64-v8a/libMulti.so differ diff --git a/app/src/main/jniLibs/arm64-v8a/libSpiDevice.so b/app/src/main/jniLibs/arm64-v8a/libSpiDevice.so new file mode 100644 index 0000000..e7c2446 Binary files /dev/null and b/app/src/main/jniLibs/arm64-v8a/libSpiDevice.so differ diff --git a/app/src/main/jniLibs/arm64-v8a/libfpga-detect.so b/app/src/main/jniLibs/arm64-v8a/libfpga-detect.so new file mode 100644 index 0000000..f889aed Binary files /dev/null and b/app/src/main/jniLibs/arm64-v8a/libfpga-detect.so differ diff --git a/app/src/main/jniLibs/arm64-v8a/libfriendlyarm-hardware.so b/app/src/main/jniLibs/arm64-v8a/libfriendlyarm-hardware.so new file mode 100644 index 0000000..6834491 Binary files /dev/null and b/app/src/main/jniLibs/arm64-v8a/libfriendlyarm-hardware.so differ diff --git a/app/src/main/jniLibs/armeabi-v7a/libFrameBuffer.so b/app/src/main/jniLibs/armeabi-v7a/libFrameBuffer.so new file mode 100644 index 0000000..1927f40 Binary files /dev/null and b/app/src/main/jniLibs/armeabi-v7a/libFrameBuffer.so differ diff --git a/app/src/main/jniLibs/armeabi-v7a/libMulti.so b/app/src/main/jniLibs/armeabi-v7a/libMulti.so new file mode 100644 index 0000000..413c0a8 Binary files /dev/null and b/app/src/main/jniLibs/armeabi-v7a/libMulti.so differ diff --git a/app/src/main/jniLibs/armeabi-v7a/libSpiDevice.so b/app/src/main/jniLibs/armeabi-v7a/libSpiDevice.so new file mode 100644 index 0000000..e7c2446 Binary files /dev/null and b/app/src/main/jniLibs/armeabi-v7a/libSpiDevice.so differ diff --git a/app/src/main/jniLibs/armeabi-v7a/libfpga-detect.so b/app/src/main/jniLibs/armeabi-v7a/libfpga-detect.so new file mode 100644 index 0000000..17e07e2 Binary files /dev/null and b/app/src/main/jniLibs/armeabi-v7a/libfpga-detect.so differ diff --git a/app/src/main/jniLibs/armeabi-v7a/libfriendlyarm-hardware.so b/app/src/main/jniLibs/armeabi-v7a/libfriendlyarm-hardware.so new file mode 100644 index 0000000..6834491 Binary files /dev/null and b/app/src/main/jniLibs/armeabi-v7a/libfriendlyarm-hardware.so differ diff --git a/app/src/main/jniLibs/armeabi/libFrameBuffer.so b/app/src/main/jniLibs/armeabi/libFrameBuffer.so new file mode 100644 index 0000000..1927f40 Binary files /dev/null and b/app/src/main/jniLibs/armeabi/libFrameBuffer.so differ diff --git a/app/src/main/jniLibs/armeabi/libMulti.so b/app/src/main/jniLibs/armeabi/libMulti.so new file mode 100644 index 0000000..413c0a8 Binary files /dev/null and b/app/src/main/jniLibs/armeabi/libMulti.so differ diff --git a/app/src/main/jniLibs/armeabi/libSpiDevice.so b/app/src/main/jniLibs/armeabi/libSpiDevice.so new file mode 100644 index 0000000..e7c2446 Binary files /dev/null and b/app/src/main/jniLibs/armeabi/libSpiDevice.so differ diff --git a/app/src/main/jniLibs/armeabi/libfriendlyarm-hardware.so b/app/src/main/jniLibs/armeabi/libfriendlyarm-hardware.so new file mode 100644 index 0000000..6834491 Binary files /dev/null and b/app/src/main/jniLibs/armeabi/libfriendlyarm-hardware.so differ 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..c7bd21d --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + 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..d5fccc5 --- /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..97dcc80 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,29 @@ + + + + + + diff --git a/app/src/main/res/layout/main.xml b/app/src/main/res/layout/main.xml new file mode 100644 index 0000000..363c45b --- /dev/null +++ b/app/src/main/res/layout/main.xml @@ -0,0 +1,13 @@ + + + + + + \ 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..a2f5908 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..1b52399 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..ff10afd 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..115a4c7 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..dcd3cd8 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..459ca60 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..8ca12fe 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..8e19b41 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..b824ebd 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..4c19a13 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..0dc58a6 --- /dev/null +++ b/app/src/main/res/values/colors.xml @@ -0,0 +1,9 @@ + + + #3F51B5 + #303F9F + #FF4081 + + #01000000 + #FF008000 + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..1ca74b0 --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,14 @@ + + Display + Android-00001 + /data/joey/config/ + /data/joey/kernel/ + /data/joey/signed/ + card.id + card.sig + card.verfy + /data/joey/tmp/ + fpga.hcp4 + fpga.cas + gry.mif + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..0abdc2f --- /dev/null +++ b/app/src/main/res/values/styles.xml @@ -0,0 +1,15 @@ + + + + + + diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..11e7717 --- /dev/null +++ b/build.gradle @@ -0,0 +1,35 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + + repositories { + maven { url 'https://maven.aliyun.com/repository/public' } + maven { url 'https://maven.aliyun.com/repository/central' } + maven { url 'https://maven.aliyun.com/repository/google' } + maven { url 'https://maven.aliyun.com/repository/gradle-plugin' } + google() + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:3.2.1' + + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + maven { url 'https://maven.aliyun.com/repository/public' } + maven { url 'https://maven.aliyun.com/repository/central' } + maven { url 'https://maven.aliyun.com/repository/google' } + maven { url 'https://maven.aliyun.com/repository/gradle-plugin' } + google() + jcenter() + } +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..4daa82b --- /dev/null +++ b/gradle.properties @@ -0,0 +1,19 @@ +# 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 + +#android.useDeprecateNDK=true diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..13372ae 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..1b7840a --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Sat Apr 13 15:07:34 CST 2019 +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 100644 index 0000000..9d82f78 --- /dev/null +++ b/gradlew @@ -0,0 +1,160 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# 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 +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# 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 + +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" ] ; 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 + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..8a0b282 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,90 @@ +@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 + +@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= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@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 Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_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=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +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/p.bat b/p.bat new file mode 100644 index 0000000..59523ff --- /dev/null +++ b/p.bat @@ -0,0 +1,15 @@ +@echo off + +set stryear=%date:~2,2% +set strmonth=%date:~5,2% +set strday=%date:~8,2% +set strdatetime=%stryear%%strmonth%%strday% + + + +del /f/s/q .\Apk\2*.* +del /f/s/q *Apk*.zip + +"C:\Program Files\2345Soft\HaoZip\HaoZipC.exe" a -tzip .\Apk\Display.zip -p66399266 .\release\app-release.apk +rename .\Apk\Display.zip 2-DisplayApp%strdatetime%a.zip + diff --git a/release/output.json b/release/output.json new file mode 100644 index 0000000..5fe9a8c --- /dev/null +++ b/release/output.json @@ -0,0 +1 @@ +[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":1},"path":"app-release.apk","properties":{"packageId":"com.xixun.display","split":"","minSdkVersion":"15"}}] \ No newline at end of file diff --git a/release/p.lnk b/release/p.lnk new file mode 100644 index 0000000..045f112 Binary files /dev/null and b/release/p.lnk differ diff --git a/release/release/output.json b/release/release/output.json new file mode 100644 index 0000000..82eda4d --- /dev/null +++ b/release/release/output.json @@ -0,0 +1 @@ +[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"v5.1.1","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}] \ No newline at end of file diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..e7b4def --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +include ':app' diff --git a/so_bk/armeabi-v7a/libFrameBuffer.so b/so_bk/armeabi-v7a/libFrameBuffer.so new file mode 100644 index 0000000..db0ad89 Binary files /dev/null and b/so_bk/armeabi-v7a/libFrameBuffer.so differ diff --git a/so_bk/armeabi-v7a/libMulti.so b/so_bk/armeabi-v7a/libMulti.so new file mode 100644 index 0000000..114d50d Binary files /dev/null and b/so_bk/armeabi-v7a/libMulti.so differ diff --git a/so_bk/armeabi-v7a/libSpiDevice.so b/so_bk/armeabi-v7a/libSpiDevice.so new file mode 100644 index 0000000..5f4287b Binary files /dev/null and b/so_bk/armeabi-v7a/libSpiDevice.so differ diff --git a/so_bk/armeabi/libFrameBuffer.so b/so_bk/armeabi/libFrameBuffer.so new file mode 100644 index 0000000..ab2fec3 Binary files /dev/null and b/so_bk/armeabi/libFrameBuffer.so differ diff --git a/so_bk/armeabi/libMulti.so b/so_bk/armeabi/libMulti.so new file mode 100644 index 0000000..c407ab3 Binary files /dev/null and b/so_bk/armeabi/libMulti.so differ diff --git a/so_bk/armeabi/libSpiDevice.so b/so_bk/armeabi/libSpiDevice.so new file mode 100644 index 0000000..d38fcb7 Binary files /dev/null and b/so_bk/armeabi/libSpiDevice.so differ