This commit is contained in:
commit
81ac1e7aa3
|
@ -0,0 +1,27 @@
|
|||
# Built application files
|
||||
*.apk
|
||||
*.ap_
|
||||
|
||||
# Files for the Dalvik VM
|
||||
*.dex
|
||||
|
||||
# Java class files
|
||||
*.class
|
||||
|
||||
# Generated files
|
||||
bin/
|
||||
gen/
|
||||
|
||||
# Gradle files
|
||||
.gradle/
|
||||
build/
|
||||
|
||||
# Local configuration file (sdk path, etc)
|
||||
local.properties
|
||||
|
||||
# Proguard folder generated by Eclipse
|
||||
proguard/
|
||||
|
||||
#Log Files
|
||||
*.log
|
||||
.idea/*
|
Binary file not shown.
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.id="Display-1" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="java-gradle" name="Java-Gradle">
|
||||
<configuration>
|
||||
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
|
||||
<option name="BUILDABLE" value="false" />
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.id="Display-general" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="java-gradle" name="Java-Gradle">
|
||||
<configuration>
|
||||
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
|
||||
<option name="BUILDABLE" value="false" />
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.id="display" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -0,0 +1 @@
|
|||
/build
|
|
@ -0,0 +1,49 @@
|
|||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion 26
|
||||
defaultConfig {
|
||||
applicationId "com.xixun.display"
|
||||
minSdkVersion 15
|
||||
targetSdkVersion 26
|
||||
versionCode 40
|
||||
versionName "5.1.8.7"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
android.applicationVariants.all { variant ->
|
||||
variant.outputs.all { output ->
|
||||
def outputFile = output.outputFile
|
||||
if (outputFile != null && outputFile.name.endsWith('.apk')) {
|
||||
outputFileName = "display_v${defaultConfig.versionName}.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')
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":40,"versionName":"5.1.8.7-yh","enabled":true,"outputFile":"display_v5.1.8.7-yh.apk","fullName":"release","baseName":"release"},"path":"display_v5.1.8.7-yh.apk","properties":{}}]
|
|
@ -0,0 +1,60 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.xixun.display">
|
||||
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
|
||||
<application
|
||||
android:name=".MyApp"
|
||||
android:allowBackup="true"
|
||||
android:background="@android:color/transparent"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:shadowRadius="0.0"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@android:style/Theme.Translucent">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:configChanges="orientation|keyboardHidden">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<receiver
|
||||
android:name=".BootReceiver"
|
||||
android:enabled="true"
|
||||
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
|
||||
<intent-filter android:priority="1000">
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
<category android:name="android.intent.category.HOME" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<service
|
||||
android:name=".MyService"
|
||||
android:enabled="true"
|
||||
android:exported="true">
|
||||
<intent-filter><action android:name="com.xixun.display.AIDLService"></action>
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<!--<service android:name=".AIDLService"-->
|
||||
<!--android:enabled="true"-->
|
||||
<!--android:exported="true">-->
|
||||
<!--<intent-filter><action android:name="com.xixun.display.AIDLService"></action>-->
|
||||
<!--</intent-filter>-->
|
||||
<!--</service>-->
|
||||
</application>
|
||||
|
||||
</manifest>
|
|
@ -0,0 +1,12 @@
|
|||
// MyAidl.aidl
|
||||
package com.xixun.display;
|
||||
|
||||
// Declare any non-default types here with import statements
|
||||
|
||||
interface MyAidl {
|
||||
boolean setBrightness(boolean manual, int brightness);
|
||||
int getBrightness();
|
||||
int getReceivedCardNum();
|
||||
int getVersionBy3288();
|
||||
int setOffset(int screenX,int screenY,int cutW,int cutH,int so1X,int so1Y,int so2X,int so2Y);
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
package com.xixun.joey.uart;
|
||||
|
||||
parcelable BytesData;
|
|
@ -0,0 +1,10 @@
|
|||
package com.xixun.joey.uart;
|
||||
|
||||
import com.xixun.joey.uart.BytesData;
|
||||
|
||||
interface IUartListener {
|
||||
/**
|
||||
* data: 返回接收到的串口数据
|
||||
*/
|
||||
void onReceive(inout BytesData data);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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();
|
||||
}
|
|
@ -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);
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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<Runnable> sChangeCallbacks = new ArrayList<Runnable>();
|
||||
|
||||
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<Runnable> callbacks = new ArrayList<Runnable>(sChangeCallbacks);
|
||||
|
||||
for(int i = 0; i < callbacks.size(); ++i) {
|
||||
((Runnable)callbacks.get(i)).run();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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 个文件。
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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<AppCrashInfo> 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<AppCrashInfo> 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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<AppCrashInfo> crashData, StringBuilder crashInfo);
|
||||
}
|
|
@ -0,0 +1,136 @@
|
|||
package com.xixun.communicate;
|
||||
|
||||
import android.os.RemoteException;
|
||||
|
||||
import com.xixun.joey.uart.BytesData;
|
||||
import com.xixun.joey.uart.IUartListener;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2018/03/24.
|
||||
*/
|
||||
|
||||
public class AidlSerialPort {
|
||||
LedCardCommunication ledCardCommunication=null;
|
||||
String aidlDeviceName=null;
|
||||
int iBaudRate=0;
|
||||
|
||||
public AidlSerialPort(LedCardCommunication ledCardCommunication,String aidlDeviceName,int iBaudRate)
|
||||
{
|
||||
this.ledCardCommunication=ledCardCommunication;
|
||||
this.aidlDeviceName=aidlDeviceName;
|
||||
this.iBaudRate=iBaudRate;
|
||||
|
||||
if (aidlDeviceName==null) return;
|
||||
if (ledCardCommunication==null) return;
|
||||
if (ledCardCommunication.clientsManage==null) return;
|
||||
if (ledCardCommunication.clientsManage.ms==null) return;
|
||||
if (ledCardCommunication.clientsManage.ms.serialPorts==null) return;
|
||||
|
||||
new Thread() {
|
||||
public void run() {
|
||||
Process();
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
void Process()
|
||||
{
|
||||
try {
|
||||
if (iBaudRate>0) ledCardCommunication.clientsManage.ms.serialPorts.config(aidlDeviceName,iBaudRate);
|
||||
bReady=true;
|
||||
System.out.println("-------------------IUartListener");
|
||||
ledCardCommunication.clientsManage.ms.serialPorts.read(aidlDeviceName, new IUartListener.Stub() {
|
||||
@Override
|
||||
public void onReceive(BytesData DataBuffer) throws RemoteException {
|
||||
|
||||
if (NeedExit()) return;
|
||||
if (GetReady()==false) return;
|
||||
|
||||
if (DataBuffer==null)
|
||||
{
|
||||
ledCardCommunication.Request_Exit();
|
||||
return;
|
||||
}
|
||||
|
||||
byte [] dataBuffer=DataBuffer.getData();
|
||||
System.out.println(Arrays.toString(dataBuffer));
|
||||
if (dataBuffer==null)
|
||||
{
|
||||
ledCardCommunication.Request_Exit();
|
||||
return;
|
||||
}
|
||||
|
||||
if (dataBuffer.length<=0)
|
||||
{
|
||||
ledCardCommunication.Request_Exit();
|
||||
return;
|
||||
}
|
||||
|
||||
if (FunctionCallBack!=null) {
|
||||
FunctionCallBack.LastReceDataProcess(dataBuffer, dataBuffer.length);
|
||||
System.out.println("-----------ReceBuffer1");
|
||||
}
|
||||
else
|
||||
{
|
||||
String receive = "";
|
||||
for (byte data : DataBuffer.getData()) {
|
||||
receive += "0x" + Integer.toHexString(data & 0xFF) + " ";
|
||||
}
|
||||
System.out.println(receive);
|
||||
}
|
||||
dataBuffer=null;
|
||||
}
|
||||
});
|
||||
} catch (RemoteException e) {
|
||||
System.out.println(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"
|
||||
);
|
||||
ledCardCommunication.Request_Exit();
|
||||
}
|
||||
}
|
||||
|
||||
public void TransData_Byte(byte[] DataBuffer, int iLength) {
|
||||
if (NeedExit()) return;
|
||||
if (GetReady() == false) return;
|
||||
if (ledCardCommunication.clientsManage.ms.serialPorts == null) return;
|
||||
|
||||
// 复制实际需要的字节缓冲。
|
||||
byte[] DataBufferTemp = new byte[iLength];
|
||||
System.arraycopy(DataBuffer, 0, DataBufferTemp, 0, iLength);
|
||||
//System.out.println(aidlDeviceName + " Aidl Trans iLength= " + iLength);
|
||||
|
||||
try {
|
||||
ledCardCommunication.clientsManage.ms.serialPorts.write(aidlDeviceName, DataBufferTemp);
|
||||
} catch (RemoteException e) {
|
||||
System.out.println(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"
|
||||
);
|
||||
ledCardCommunication.Request_Exit();
|
||||
}
|
||||
}
|
||||
IFunctionCallBack FunctionCallBack=null;
|
||||
public void SetCallFunc(IFunctionCallBack FunctionCallBack) {
|
||||
this.FunctionCallBack = FunctionCallBack;
|
||||
}
|
||||
|
||||
boolean bReady=false;
|
||||
public boolean GetReady() { return bReady; }
|
||||
|
||||
Boolean bNeedExit=false;
|
||||
boolean NeedExit() { return bNeedExit; }
|
||||
|
||||
public void Exit()
|
||||
{ if (bNeedExit) return;
|
||||
bNeedExit=true;
|
||||
bReady=false;
|
||||
System.out.println(aidlDeviceName+ " "+ Thread.currentThread().getStackTrace()[2].getFileName() + "-->"
|
||||
+ "Function: " +Thread.currentThread().getStackTrace()[2].getMethodName()
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
package com.xixun.communicate;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,168 @@
|
|||
package com.xixun.communicate;
|
||||
|
||||
import com.xixun.display.MyLog;
|
||||
|
||||
import java.net.Socket;
|
||||
import java.util.LinkedList;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 17/3/31.
|
||||
*/
|
||||
|
||||
public class ClientManage {
|
||||
ClientsManage clientsManage=null;
|
||||
private String clientIpAddress=null;
|
||||
public SendFile sendFile=null;
|
||||
public TcpCommunication tcpCommunication=null;
|
||||
|
||||
private LinkedList sendFileAndCommandList = null;
|
||||
|
||||
ClientManage(ClientsManage clientsManage,String clientIpAddress){
|
||||
|
||||
sendFileAndCommandList = new LinkedList();
|
||||
|
||||
this.clientsManage=clientsManage;
|
||||
// 先建立套接字接受服务程序;
|
||||
|
||||
// 获取到IP地址;
|
||||
this.clientIpAddress=clientIpAddress;
|
||||
//MyLog.i("Clinet Display IP:" +clientIpAddress + " Connectted!");
|
||||
/*
|
||||
new Thread() {
|
||||
public void run() {
|
||||
BackgroundSendFileAndCommand();
|
||||
}
|
||||
}.start();
|
||||
*/
|
||||
|
||||
new Thread() {
|
||||
public void run() {
|
||||
Process();
|
||||
}
|
||||
}.start();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void TransData_Byte(byte ucCommand,byte ucIdence, byte ucPipeId, byte[] DataBuffer, int iLength)
|
||||
{
|
||||
if (NeedExit()) return;
|
||||
|
||||
if (tcpCommunication != null)
|
||||
tcpCommunication.TransData_Byte(ucCommand, ucIdence, ucPipeId,DataBuffer, iLength);
|
||||
}
|
||||
|
||||
public Boolean IdenceJundge(String strIdence)
|
||||
{
|
||||
if (strIdence == null) return true;
|
||||
if (strIdence.equals(GetIpAddress())) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public String GetIpAddress()
|
||||
{
|
||||
return clientIpAddress;
|
||||
}
|
||||
|
||||
public void SettcpCommunicationSocket(Socket socket)
|
||||
{ if (tcpCommunication!=null) tcpCommunication.Exit();
|
||||
tcpCommunication = new TcpCommunication(this,socket);
|
||||
}
|
||||
|
||||
public void SetSendFileSocket(Socket socket)
|
||||
{ if (sendFile!=null) sendFile.Exit();
|
||||
sendFile = new SendFile(this,socket);
|
||||
}
|
||||
|
||||
public boolean Client_IdenceJundge(String strClientIdence)
|
||||
{ if (strClientIdence==null) return true;
|
||||
if (strClientIdence.equals(Get_ClientIpAddress())) return true;
|
||||
if (strClientIdence.equals(Get_DisplayID())) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public String Get_DisplayID()
|
||||
{ if (tcpCommunication!=null)
|
||||
return tcpCommunication.GetDisplayID();
|
||||
return null;
|
||||
}
|
||||
|
||||
private void BackgroundSendFileAndCommand() {
|
||||
while (NeedExit()==false) {
|
||||
if (sendFileAndCommandList.size() != 0) {
|
||||
FileBackground background = (FileBackground) sendFileAndCommandList.getFirst();
|
||||
try {
|
||||
if (background!=null)
|
||||
{ if (sendFile!=null) sendFile.SendFilePro(background.pathFile, background.strObjectName);
|
||||
//if (tcpCommunication != null) tcpCommunication.TransCommand(background.stringVlaue);
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
sendFileAndCommandList.removeFirst();
|
||||
} else try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String Get_ClientIpAddress() { return clientIpAddress; }
|
||||
|
||||
private void Process()
|
||||
{
|
||||
while(NeedExit()==false)
|
||||
{
|
||||
try {
|
||||
Thread.sleep(3000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Boolean bHaveRequest = false;
|
||||
public void Request_Exit()
|
||||
{
|
||||
if (bHaveRequest) return;
|
||||
bHaveRequest = true;
|
||||
|
||||
if (NeedExit()) return;
|
||||
|
||||
MyLog.i("ClientManage Request_Exit.");
|
||||
|
||||
if (clientIpAddress != null)
|
||||
if (clientsManage!=null)
|
||||
clientsManage.Request_Exit(clientIpAddress);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Boolean bNeedExit=false;
|
||||
boolean NeedExit() { return bNeedExit; }
|
||||
|
||||
public void Exit() {
|
||||
if (NeedExit()) return;
|
||||
bNeedExit=true;
|
||||
|
||||
// 关中间服务;
|
||||
if (sendFile!=null) sendFile.Exit();
|
||||
// 关套接字连接;
|
||||
if (tcpCommunication!=null) tcpCommunication.Exit();
|
||||
|
||||
if (sendFileAndCommandList!=null) sendFileAndCommandList.clear();
|
||||
|
||||
clientsManage=null;
|
||||
clientIpAddress=null;
|
||||
sendFile=null;
|
||||
tcpCommunication=null;
|
||||
|
||||
sendFileAndCommandList = null;
|
||||
|
||||
MyLog.i(clientIpAddress+" "+ Thread.currentThread().getStackTrace()[2].getFileName() + "-->"
|
||||
+ "Function: " +Thread.currentThread().getStackTrace()[2].getMethodName() + "-->"
|
||||
+ "Line" +Thread.currentThread().getStackTrace()[2].getLineNumber() + ":\r\n"
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,518 @@
|
|||
package com.xixun.communicate;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.xixun.display.BuildConfig;
|
||||
import com.xixun.display.MainActivity;
|
||||
import com.xixun.display.MyApp;
|
||||
import com.xixun.display.MyLog;
|
||||
import com.xixun.display.MyService;
|
||||
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import static java.lang.Thread.sleep;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 17/3/31.
|
||||
*/
|
||||
public class ClientsManage {
|
||||
// 二次开发接口部分:
|
||||
public static final int IP_PORT_BASE = 31296; // 一组TCP/UDP通讯起始端口。
|
||||
public static final int IP_PORT_BROADCAST = IP_PORT_BASE+0;
|
||||
public static final int IP_PORT_3G_OR_INTERNET_REPORT_TO_HOST = IP_PORT_BASE+1;
|
||||
public static final int IP_PORT_STRING = IP_PORT_BASE+2;
|
||||
public static final int IP_PORT_NO_STRING = IP_PORT_BASE+3;
|
||||
|
||||
public static final int UDP_PORT = IP_PORT_BASE+10;
|
||||
public static final int TCP_PORT_COMMUNICATION = IP_PORT_BASE + 11;
|
||||
public static final int TCP_PORT_FILE_SEND = IP_PORT_BASE + 12;
|
||||
public static final int UDP_PORT_ACTIVE = IP_PORT_BASE+13;
|
||||
public static final int TCP_PORT_FILE_RECE = IP_PORT_BASE + 14;
|
||||
public static final int UDP_PORT_SEND_SYNC_TIME = IP_PORT_BASE+15;
|
||||
public static final int UDP_GPS_REPORT = IP_PORT_BASE+16;
|
||||
|
||||
public static final int HEART_INTERVAL = Define.bRunOnDebug ? 300:3000;
|
||||
|
||||
|
||||
public LedCardCommunication ledCardCommunication=null;
|
||||
|
||||
|
||||
LinkedList clientsTable=null;
|
||||
|
||||
public ServerSocket serverSocket_tcpCommunication = null;
|
||||
public ServerSocket serverSocket_SendFile = null;
|
||||
public DatagramSocket udpSendSocket =null;
|
||||
InetSocketAddress inetSocketAddress =null;
|
||||
|
||||
//UdpRece udpRece=null;
|
||||
|
||||
public MyService ms=null;
|
||||
|
||||
public ClientsManage(MyService service) {
|
||||
ms = service;
|
||||
clientsTable = new LinkedList();
|
||||
|
||||
new Thread() {
|
||||
public void run() {
|
||||
Process();
|
||||
}
|
||||
}.start();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void TransData_Byte(String strIdence, byte ucCommand,byte ucIdence, byte ucPipeId, byte[] DataBuffer, int iLength)
|
||||
{
|
||||
if (NeedExit()) return;
|
||||
if (clientsTable == null) return;
|
||||
|
||||
for (int iOffset=0;iOffset<clientsTable.size();iOffset++) {
|
||||
if (NeedExit()) return;
|
||||
ClientManage clientManage = (ClientManage) clientsTable.get(iOffset);
|
||||
if (clientManage == null) continue;
|
||||
if (clientManage.NeedExit()) continue;
|
||||
if (clientManage.IdenceJundge(strIdence)) {
|
||||
clientManage.TransData_Byte(ucCommand, ucIdence, ucPipeId, DataBuffer, iLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 获取当前客户端的连接数。
|
||||
public int Clients_GetConnectNumber(){ if (NeedExit()) return 0;
|
||||
if (clientsTable==null) return 0;
|
||||
return clientsTable.size();
|
||||
}
|
||||
|
||||
|
||||
// 得到某显示屏的内部参数
|
||||
public ClientManage Get_ClientManage(String clientID)
|
||||
{ if (NeedExit()) return null;
|
||||
if (clientID==null) return null;
|
||||
if (clientID.length()==0) return null;
|
||||
|
||||
for (int iOffset=0;iOffset<clientsTable.size();iOffset++) {
|
||||
if (NeedExit()) return null;
|
||||
ClientManage clientManage=(ClientManage)clientsTable.get(iOffset);
|
||||
if (clientManage==null) continue;
|
||||
if (clientManage.NeedExit()) continue;
|
||||
|
||||
if (clientManage.Client_IdenceJundge(clientID)) return clientManage;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void Process(){
|
||||
ledCardCommunication=new LedCardCommunication(this,"127.0.0.1",IP_PORT_NO_STRING);
|
||||
new Thread() {
|
||||
public void run() {
|
||||
Clients_tcpCommunication_ConnectProcess();
|
||||
}
|
||||
}.start();
|
||||
/*
|
||||
new Thread() {
|
||||
public void run() {
|
||||
Clients_SendFile_ConnectProcess();
|
||||
}
|
||||
}.start();
|
||||
*/
|
||||
if (ledCardCommunication.bTestInNewFpga==false) {
|
||||
new Thread() {
|
||||
public void run() {
|
||||
Clients_UdpSendBroadcaseInformations();
|
||||
}
|
||||
}.start();// 最后开始UDP通播.
|
||||
}
|
||||
|
||||
if (Define.bSyncPlay_Main_Sub) {
|
||||
new Thread() {
|
||||
public void run() {
|
||||
Clients_UdpSendTime();
|
||||
}
|
||||
}.start();// 最后开始UDP通播.
|
||||
}
|
||||
else{
|
||||
//udpRece=new UdpRece(UDP_PORT_SEND_SYNC_TIME);
|
||||
}
|
||||
while (NeedExit()==false) {
|
||||
for (int iOffset = 0; iOffset < clientsTable.size(); iOffset++) {
|
||||
if (NeedExit()) return;
|
||||
ClientManage hostManage = (ClientManage) clientsTable.get(iOffset);
|
||||
if (hostManage == null) continue;
|
||||
if (hostManage.NeedExit()) continue;
|
||||
|
||||
}
|
||||
if (bRequestRestart) // false
|
||||
{
|
||||
MyLog.i(" "+ Thread.currentThread().getStackTrace()[2].getFileName() + "-->"
|
||||
+ "Function: " +Thread.currentThread().getStackTrace()[2].getMethodName() + "-->"
|
||||
+ "Line" +Thread.currentThread().getStackTrace()[2].getLineNumber() + ": Received Exit.\r\n"
|
||||
);
|
||||
Exit(null);
|
||||
break;
|
||||
}
|
||||
if (strExitIdence != null) //strExitIdence = null
|
||||
{
|
||||
Exit(strExitIdence);
|
||||
strExitIdence = null;
|
||||
}
|
||||
MyLog.sleepForSecond(5);
|
||||
}
|
||||
}
|
||||
|
||||
private void Clients_tcpCommunication_ConnectProcess(){
|
||||
int iCounter=0;
|
||||
while(!NeedExit()) {
|
||||
try {
|
||||
//serverSocket = new ServerSocket(TCP_PORT_COMMUNICATION);
|
||||
// if (serverSocket_tcpCommunication == null){
|
||||
serverSocket_tcpCommunication = new ServerSocket();
|
||||
serverSocket_tcpCommunication.setReuseAddress(true); // 设置为可复用.
|
||||
serverSocket_tcpCommunication.bind(new InetSocketAddress(TCP_PORT_COMMUNICATION)); // 31307
|
||||
// }
|
||||
// MyLog.i("----------------------------Wait Port Connect: "+TCP_PORT_COMMUNICATION);
|
||||
// iCounter=0;
|
||||
while (!NeedExit()) {
|
||||
MyLog.i("Wait for client =======================================");
|
||||
Socket socket = serverSocket_tcpCommunication.accept();//set ip point
|
||||
if (NeedExit()) // N
|
||||
{ socket.close();
|
||||
break;
|
||||
}
|
||||
synchronized (this) { // 等待ledsyncset打开建立连接
|
||||
socket.setReuseAddress(true);
|
||||
String clientIpAddress = socket.getInetAddress().getHostAddress(); // clientIpAddress = 192.168.1.127
|
||||
if (clientIpAddress == null) continue;
|
||||
if (clientIpAddress.length() < 8) continue;
|
||||
MyLog.i("----------------------------New IP Connect: "+clientIpAddress);
|
||||
if (Get_ClientManage(clientIpAddress) == null) {
|
||||
ClientManage clientManage = new ClientManage(this, clientIpAddress);
|
||||
if (clientManage == null) continue;
|
||||
clientsTable.add(clientManage);
|
||||
}
|
||||
|
||||
ClientManage clientManage = Get_ClientManage(clientIpAddress);
|
||||
if (clientManage != null) clientManage.SettcpCommunicationSocket(socket);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
/*if (NeedExit() == false)
|
||||
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"
|
||||
);*/
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
ClientsExit();
|
||||
if (serverSocket_tcpCommunication != null) {
|
||||
serverSocket_tcpCommunication.close();
|
||||
serverSocket_tcpCommunication=null;
|
||||
}
|
||||
sleep(2000);
|
||||
|
||||
iCounter++;
|
||||
if (iCounter>100) {
|
||||
break;
|
||||
}
|
||||
}catch (Exception e) {}
|
||||
|
||||
|
||||
}
|
||||
Exit(null);
|
||||
}
|
||||
|
||||
public void Clients_SendFile_ConnectProcess(){
|
||||
int iCounter=0;
|
||||
while(NeedExit()==false) {
|
||||
try {
|
||||
serverSocket_SendFile = new ServerSocket();
|
||||
serverSocket_SendFile.setReuseAddress(true);
|
||||
serverSocket_SendFile.bind(new InetSocketAddress(TCP_PORT_FILE_SEND));
|
||||
|
||||
while (NeedExit() == false) {
|
||||
Socket socket = serverSocket_SendFile.accept();
|
||||
if (NeedExit()) break;
|
||||
iCounter=0;
|
||||
synchronized (this) {
|
||||
String clientIpAddress = socket.getInetAddress().getHostAddress();
|
||||
if (clientIpAddress == null) continue;
|
||||
if (clientIpAddress.length() < 8) continue;
|
||||
if (Get_ClientManage(clientIpAddress) == null) {
|
||||
ClientManage clientManage = new ClientManage(this, clientIpAddress);
|
||||
if (clientManage == null) continue;
|
||||
clientsTable.add(clientManage);
|
||||
}
|
||||
ClientManage clientManage = Get_ClientManage(clientIpAddress);
|
||||
if (clientManage != null) clientManage.SetSendFileSocket(socket);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (NeedExit() == false)
|
||||
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"
|
||||
);
|
||||
}
|
||||
try {
|
||||
if (serverSocket_SendFile != null) {
|
||||
serverSocket_SendFile.close();
|
||||
serverSocket_SendFile=null;
|
||||
}
|
||||
iCounter++;
|
||||
if (iCounter>1000) {
|
||||
sleep(1000);
|
||||
break;
|
||||
}
|
||||
}catch (Exception e) {}
|
||||
}
|
||||
Exit(null);
|
||||
}
|
||||
|
||||
public void Clients_UdpSendBroadcaseInformations() {
|
||||
int iCounter=0;
|
||||
while(!NeedExit()) {
|
||||
try {
|
||||
String strSendString=
|
||||
"iTcpPort=" + TCP_PORT_COMMUNICATION + ";"
|
||||
// + "iSendFilePort=" + TCP_PORT_FILE_SEND+ ";"
|
||||
// + "iReceFilePort=" + TCP_PORT_FILE_RECE+ ";"
|
||||
+ "iHeartInterval=" + HEART_INTERVAL+ ";";
|
||||
iCounter=0;
|
||||
while (ledCardCommunication.Get_DisplayID()==null){
|
||||
if (NeedExit()) return;
|
||||
iCounter++;
|
||||
if (iCounter>5) break;
|
||||
sleep(HEART_INTERVAL);
|
||||
MyLog.i( "Wait Get ID:"+strSendString );
|
||||
}
|
||||
if (ledCardCommunication.Get_DisplayID()!=null)
|
||||
{ strSendString+= "DisplayID=" + ledCardCommunication.Get_DisplayID()+ ";";
|
||||
strSendString+=" ver:"+BuildConfig.VERSION_NAME;
|
||||
}
|
||||
else
|
||||
{
|
||||
strSendString+= "DisplayID=" + "XiXun-Display" + ";";
|
||||
}
|
||||
List<String> strBoardCastIp=null;
|
||||
DatagramPacket sendPacket =null;
|
||||
byte sendDataBuffer[] = strSendString.getBytes();
|
||||
|
||||
if(udpSendSocket==null){
|
||||
udpSendSocket = new DatagramSocket(null);
|
||||
udpSendSocket.setReuseAddress(true);
|
||||
udpSendSocket.bind(new InetSocketAddress(UDP_PORT));
|
||||
}
|
||||
while (!NeedExit())
|
||||
{
|
||||
try {
|
||||
sleep(HEART_INTERVAL); // 第一次时,先等待其他服务端口套接字线程准备好。
|
||||
} catch (InterruptedException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
if ((strBoardCastIp!=NetDevicesManage.GetBoardCastIp())||(sendPacket==null))
|
||||
{ iCounter=0;
|
||||
while ((strBoardCastIp=NetDevicesManage.GetBoardCastIp())==null)
|
||||
{ if (NeedExit()) return;
|
||||
iCounter++;
|
||||
if (iCounter>5) break;
|
||||
|
||||
sleep(HEART_INTERVAL);
|
||||
MyLog.i( "Wait Get GetBoardCastIp");
|
||||
}
|
||||
if (strBoardCastIp==null) {
|
||||
strBoardCastIp=new ArrayList<>();
|
||||
strBoardCastIp.add(Define.AllNetBroadcaseIP);
|
||||
}
|
||||
}
|
||||
// MyLog.i("UDP_PORT="+UDP_PORT+": "+strSendString+ " Board: " +strBoardCastIp);
|
||||
for (String ip : strBoardCastIp) {
|
||||
// MyLog.i(ip);
|
||||
sendPacket = new DatagramPacket(sendDataBuffer, sendDataBuffer.length, InetAddress.getByName(ip), UDP_PORT);
|
||||
udpSendSocket.send(sendPacket);
|
||||
}
|
||||
}
|
||||
}catch(Exception e){
|
||||
if (false) // 180720a
|
||||
if (NeedExit()==false)
|
||||
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"
|
||||
);
|
||||
}finally {
|
||||
if (udpSendSocket!=null) {
|
||||
udpSendSocket.close();
|
||||
udpSendSocket=null;
|
||||
}
|
||||
}
|
||||
try {
|
||||
sleep(HEART_INTERVAL);
|
||||
} catch (InterruptedException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
Exit(null);
|
||||
}
|
||||
|
||||
public void Clients_UdpSendTime() {
|
||||
int iCounter=0;
|
||||
//return;
|
||||
while(NeedExit()==false) {
|
||||
|
||||
try {
|
||||
if (udpSendSocket == null){
|
||||
udpSendSocket = new DatagramSocket(null);
|
||||
udpSendSocket.setReuseAddress(true);
|
||||
udpSendSocket.bind(new InetSocketAddress(UDP_PORT_SEND_SYNC_TIME));
|
||||
}
|
||||
|
||||
while (!NeedExit()){
|
||||
String str ="Time="+ Define.GetTimeMs();
|
||||
byte sendDataBuffer[] = str.getBytes();
|
||||
DatagramPacket sendPacket = new DatagramPacket(sendDataBuffer, sendDataBuffer.length, InetAddress.getByName(Define.AllNetBroadcaseIP), UDP_PORT_SEND_SYNC_TIME);
|
||||
try {
|
||||
sleep(HEART_INTERVAL); // sleep(1000); // 第一次时,先等待其他服务端口套接字线程准备好。
|
||||
} catch (InterruptedException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
//iCounter=0;
|
||||
udpSendSocket.send(sendPacket);
|
||||
MyLog.i( str );
|
||||
}
|
||||
}catch(Exception e){
|
||||
if (!NeedExit())
|
||||
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"
|
||||
);
|
||||
}finally {
|
||||
if (udpSendSocket!=null) {
|
||||
udpSendSocket.close();
|
||||
udpSendSocket=null;
|
||||
}
|
||||
//iCounter++;
|
||||
if (iCounter>10)
|
||||
break;
|
||||
}
|
||||
}
|
||||
Exit(null);
|
||||
}
|
||||
|
||||
|
||||
boolean bRequestRestart=false;
|
||||
String strExitIdence = null;
|
||||
public void Request_Exit(String strDeviceIdence) // 不能直接调用Exit,调用的线程会被阻塞,列表不被删除。
|
||||
{
|
||||
// 全局申请退出优先级高。
|
||||
if (strDeviceIdence == null) {
|
||||
bRequestRestart=true;
|
||||
return;
|
||||
}
|
||||
|
||||
// 有其他身份待退出,等待退出结束。
|
||||
int iCounter = 0;
|
||||
while (strExitIdence != null) {
|
||||
try { sleep(100);}catch (Exception e) {}
|
||||
iCounter++;
|
||||
if (iCounter > 60) break;
|
||||
}
|
||||
|
||||
MyLog.i("ClientsManage Request_Exit:" + strDeviceIdence);
|
||||
strExitIdence = strDeviceIdence;
|
||||
}
|
||||
|
||||
Boolean bNeedExit=false;
|
||||
public boolean NeedExit() { return bNeedExit; }
|
||||
|
||||
public void ClientsExit()
|
||||
{ synchronized (this) {
|
||||
if (clientsTable.size() > 0) {
|
||||
for (int iOffset = clientsTable.size() - 1; iOffset >= 0; iOffset--) { // 从最后一个开始删除。
|
||||
ClientManage clientManage = (ClientManage) clientsTable.get(iOffset);
|
||||
if (clientManage == null) continue;
|
||||
clientManage.Exit();
|
||||
clientsTable.remove(iOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Exit(String clientID)
|
||||
{ if (NeedExit()) return;
|
||||
|
||||
if (clientID==null) {
|
||||
bNeedExit = true;
|
||||
|
||||
if (ledCardCommunication!=null) ledCardCommunication.Exit();
|
||||
//if (udpRece!=null) udpRece.Exit();
|
||||
}
|
||||
|
||||
synchronized (this) {
|
||||
if (clientsTable.size() > 0) {
|
||||
for (int iOffset = clientsTable.size() - 1; iOffset >= 0; iOffset--) { // 从最后一个开始删除。
|
||||
ClientManage clientManage = (ClientManage) clientsTable.get(iOffset);
|
||||
|
||||
if (clientManage == null) continue;
|
||||
|
||||
if (clientManage.Client_IdenceJundge(clientID)) {
|
||||
clientManage.Exit();
|
||||
clientsTable.remove(iOffset);
|
||||
//break; // 删完不直接退出,防止有重复的控制卡列表。
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (clientID == null) {
|
||||
try {
|
||||
clientsTable.clear();
|
||||
if (serverSocket_tcpCommunication != null) {
|
||||
serverSocket_tcpCommunication.close();
|
||||
serverSocket_tcpCommunication=null;
|
||||
}
|
||||
if (serverSocket_SendFile != null) {
|
||||
serverSocket_SendFile.close();
|
||||
serverSocket_SendFile=null;
|
||||
}
|
||||
if (udpSendSocket != null) {
|
||||
udpSendSocket.close();
|
||||
udpSendSocket=null;
|
||||
}
|
||||
}catch (Exception e) {
|
||||
if (NeedExit() == false)
|
||||
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"
|
||||
);
|
||||
}
|
||||
MyLog.i(" "+ Thread.currentThread().getStackTrace()[2].getFileName() + "-->"
|
||||
+ "Function: " +Thread.currentThread().getStackTrace()[2].getMethodName() + "-->"
|
||||
+ "Line" +Thread.currentThread().getStackTrace()[2].getLineNumber() + ":\r\n"
|
||||
);
|
||||
ms.AppRestart();
|
||||
}
|
||||
|
||||
//if (clientsTable.size() == 0) Activity.AppRestart();
|
||||
|
||||
|
||||
MyLog.i(" "+ Thread.currentThread().getStackTrace()[2].getFileName() + "-->"
|
||||
+ "Function: " +Thread.currentThread().getStackTrace()[2].getMethodName() + "-->"
|
||||
+ "Line" +Thread.currentThread().getStackTrace()[2].getLineNumber() + ":\r\n"
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package com.xixun.communicate;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
public class Configurations {
|
||||
|
||||
public static String strConfigFileName ="DisplayAppConfig";
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,480 @@
|
|||
package com.xixun.communicate;
|
||||
|
||||
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 = true;//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;
|
||||
|
||||
file.mkdir();
|
||||
|
||||
file=new File(fileName);
|
||||
if (file.exists()) return 0;
|
||||
MyLog.i("Creat Folder Fail 1:" + fileName);
|
||||
|
||||
ShellUtils.execCommand("mkdir "+ 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<iEndOffset;i++) {
|
||||
ucCheckCode += pBuffer[i];
|
||||
//MyLog.i(" pBuffer="+pBuffer[i]+" ucCheckCode="+ucCheckCode);
|
||||
}
|
||||
//MyLog.i("---------------------------------------------------------------ucCheckCode="+ucCheckCode);
|
||||
return (byte)~ucCheckCode;
|
||||
}
|
||||
|
||||
public static void PrintBuffer(String strBufferName,byte [] DataBuffer)
|
||||
{ if (DataBuffer==null) return;
|
||||
PrintBuffer(strBufferName,DataBuffer,DataBuffer.length);
|
||||
}
|
||||
|
||||
public static void PrintBuffer(String strBufferName,byte [] DataBuffer,int iLength)
|
||||
{
|
||||
|
||||
if (DataBuffer==null) return;
|
||||
if (iLength>DataBuffer.length) iLength=DataBuffer.length;
|
||||
String receive = "";
|
||||
|
||||
for (int i = 0; i < iLength; i++)
|
||||
{ if (i%16==0) receive += "\r\n";
|
||||
receive += "0x";
|
||||
if ((DataBuffer[i] & 0xFF) < 0x10) receive += "0";
|
||||
receive += Integer.toHexString(DataBuffer[i] & 0xFF).toUpperCase() + " ";
|
||||
|
||||
}
|
||||
MyLog.i("" + ((strBufferName==null) ? "Data":strBufferName)+" = " + receive);
|
||||
}
|
||||
|
||||
public static String PrintIntToHex(int iValue)
|
||||
{ return "0x"+Integer.toHexString(iValue).toUpperCase();
|
||||
}
|
||||
|
||||
public static void SetTime(String strTime)
|
||||
{
|
||||
long lValue=Long.parseLong(strTime);
|
||||
if (lValue<0) return;
|
||||
|
||||
//Date date=new Date();
|
||||
//date.setTime(lValue);
|
||||
SystemClock.setCurrentTimeMillis(lValue);
|
||||
|
||||
}
|
||||
|
||||
public static long GetTimeMs() {
|
||||
Date date = new Date();
|
||||
return date.getTime();//DateToLong(date);//
|
||||
}
|
||||
|
||||
public static long DateToLong(Date time){
|
||||
SimpleDateFormat st=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//yyyyMMddHHmmss
|
||||
return Long.parseLong(st.format(time));
|
||||
}
|
||||
|
||||
public static Date StringToDate(String s){
|
||||
Date date=null;
|
||||
SimpleDateFormat sd=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
try {
|
||||
date=sd.parse(s);
|
||||
} catch (java.text.ParseException e) {
|
||||
MyLog.i("输入的日期格式有误!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return date;
|
||||
}
|
||||
|
||||
public static int chksum_crc16 (byte [] pDat, int iOffset,int length)
|
||||
{
|
||||
byte da=0;
|
||||
int k =0;
|
||||
int crcval = 0;
|
||||
|
||||
for(k=0;k < length;k++)
|
||||
{
|
||||
da= (byte)(crcval>>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(android.os.Environment.MEDIA_MOUNTED);//判断sd卡是否存在
|
||||
if(sdCardExist)
|
||||
{
|
||||
sdDir = Environment.getExternalStorageDirectory();//获取跟目录
|
||||
}
|
||||
|
||||
return sdDir.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package com.xixun.communicate;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 16/11/20.
|
||||
*/
|
||||
|
||||
public class FileBackground {
|
||||
String pathFile;
|
||||
String strObjectName;
|
||||
String stringVlaue;
|
||||
|
||||
FileBackground(
|
||||
String pathFile,
|
||||
String strObjectName,
|
||||
String stringVlaue){
|
||||
|
||||
this.pathFile= pathFile;
|
||||
this.strObjectName= strObjectName;
|
||||
this.stringVlaue= stringVlaue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------------------------------
|
||||
Software file run for Java or Android OS,Disgned by Ronson Xu.
|
||||
Copyright (c) 2000-2017 XiXun/Sysolution/Samtone/Helecsoft roftware, Inc.All rights reserved.
|
||||
|
||||
If have any question contanct Ronson Xu :
|
||||
Mobile: +8613266638838,+8613661471201;
|
||||
Email: xrs@xixunled.com,Ronson@samtone.com
|
||||
|
||||
Thank you!
|
||||
;-)
|
||||
-------------------------------------------------------------------------------------------------*/
|
|
@ -0,0 +1,156 @@
|
|||
package com.xixun.communicate;
|
||||
|
||||
/**
|
||||
* 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<fileList.length;i++){
|
||||
|
||||
|
||||
if(fileList[i].isDirectory()){//如果如果是子目录进行递归
|
||||
copyDir(fileList[i].getPath()+ "/",
|
||||
destDir + fileList[i].getName() + "/");
|
||||
}else{//如果是文件则进行文件拷贝
|
||||
copyFile(fileList[i].getPath(), destDir +fileList[i].getName());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}else {
|
||||
copyFileToDir(srcDir,destDir);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 复制文件(非目录)
|
||||
* @param srcFile 要复制的源文件
|
||||
* @param destFile 复制到的目标文件
|
||||
* @return
|
||||
*/
|
||||
public static boolean copyFile(String srcFile, String destFile){
|
||||
MyLog.i("------------ 0 copyFile: "+ srcFile +" --> "+ 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();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
package com.friendlyarm.AndroidSDK;
|
||||
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!");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
package com.xixun.communicate;
|
||||
|
||||
/*
|
||||
*/
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.koushikdutta.async.http.AsyncHttpClient;
|
||||
import com.koushikdutta.async.http.AsyncHttpPost;
|
||||
import com.koushikdutta.async.http.AsyncHttpResponse;
|
||||
import com.koushikdutta.async.http.body.JSONObjectBody;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import static android.content.ContentValues.TAG;
|
||||
import static java.lang.Thread.sleep;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2018/08/17.
|
||||
*/
|
||||
|
||||
public class HttpLan {
|
||||
JSONObject json0 =null;
|
||||
Object obj=new Object();
|
||||
public String getAlias() {
|
||||
|
||||
AsyncHttpPost post = new AsyncHttpPost("http://127.0.0.1:2016/settings");
|
||||
try {
|
||||
Log.e(TAG, "=========== getJsonParams ==============");
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("_id", "AAA");
|
||||
json.put("_type", "GetCardAlias");
|
||||
JSONObjectBody body = new JSONObjectBody(json);
|
||||
post.setBody(body);
|
||||
AsyncHttpClient.getDefaultInstance().executeString(post, new AsyncHttpClient.StringCallback() {
|
||||
@Override
|
||||
public void onCompleted(Exception e, AsyncHttpResponse res, String json) {
|
||||
if (null != e) {
|
||||
e.printStackTrace();
|
||||
} else {
|
||||
Log.e(TAG, json);
|
||||
try {
|
||||
json0 = new JSONObject(json);
|
||||
|
||||
} catch (Exception e0) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
int iCounter=0;
|
||||
while (json0==null) {
|
||||
sleep(100);
|
||||
iCounter++;
|
||||
if (iCounter>30) break;
|
||||
}
|
||||
if (json0!=null) {
|
||||
String strAlias = (String) json0.get("alias");
|
||||
//MyLog.i("========0=================strAlias: "+strAlias);
|
||||
byte[] bt = Base64.base64Decode(strAlias);
|
||||
//byte[] bt= Base64.decodeBase64(strAlias);
|
||||
if (bt != null) {
|
||||
//MyLog.i("========2=================Alias: " + new String(bt));
|
||||
return new String(bt);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/*
|
||||
|
||||
public String getReultForHttpPost(String name,String pwd) throws IOException {
|
||||
//服务器 :服务器项目 :servlet名称
|
||||
String path="http://127.0.0.1:2016/test/test";
|
||||
HttpPost httpPost=new HttpPost(path);
|
||||
List<NameValuePair>list=new ArrayList<NameValuePair>();
|
||||
list.add(new BasicNameValuePair("name", name));
|
||||
list.add(new BasicNameValuePair("pwd", pwd));
|
||||
httpPost.setEntity(new UrlEncodedFormEntity(list,HTTP.UTF_8));//编者按:与HttpGet区别所在,这里是将参数用List传递
|
||||
|
||||
String result="";
|
||||
|
||||
HttpResponse response=new DefaultHttpClient().execute(httpPost);
|
||||
if(response.getStatusLine().getStatusCode()==200){
|
||||
HttpEntity entity=response.getEntity();
|
||||
result=EntityUtils.toString(entity, HTTP.UTF_8);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void Test()
|
||||
{ JSONObject obj =null;
|
||||
|
||||
try {
|
||||
|
||||
obj = new JSONObject();
|
||||
obj.put("_id", UUID.randomUUID());
|
||||
obj.put("_type", "GetCardAlias");
|
||||
String str_obj = obj.toString();
|
||||
|
||||
Log.i("yzd", str_obj);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.xixun.communicate;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2018/04/18.
|
||||
*/
|
||||
|
||||
|
||||
public interface IFunctionCallBack {
|
||||
|
||||
public void LastSendDataProcess(byte[] DataBuffer,int iLength);
|
||||
public void LastReceDataProcess(byte[] DataBuffer,int iLength);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,156 @@
|
|||
package com.xixun.communicate;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,372 @@
|
|||
package com.xixun.communicate;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2018/01/19.
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
|
||||
import com.xixun.display.MyLog;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.InterfaceAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.sql.SQLOutput;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class NetDevicesManage {
|
||||
|
||||
public LinkedList hostsTable=null;
|
||||
|
||||
private boolean bNetChange=false;
|
||||
private WifiManager wifiManager =null;
|
||||
|
||||
private LedCardCommunication ledCardCommunication=null;
|
||||
|
||||
public NetDevicesManage(LedCardCommunication ledCardCommunication) {
|
||||
|
||||
this.ledCardCommunication=ledCardCommunication;
|
||||
|
||||
if (true)
|
||||
new Thread() {
|
||||
public void run() {
|
||||
Process();
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
void Process() {
|
||||
if (ledCardCommunication==null) return;
|
||||
if (ledCardCommunication.clientsManage==null) return;
|
||||
if (ledCardCommunication.clientsManage.ms==null) return;
|
||||
|
||||
hostsTable=new LinkedList();
|
||||
//获取wifi服务
|
||||
wifiManager = (WifiManager) ledCardCommunication.clientsManage.ms.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
|
||||
|
||||
|
||||
while (NeedExit() == false) {
|
||||
Wifi_SetOn();
|
||||
getLocalIpAddress();
|
||||
try {
|
||||
Thread.sleep(8000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
hostsTable.clear();
|
||||
}
|
||||
|
||||
public String getLocalIpAddress()
|
||||
{
|
||||
try
|
||||
{ int iCounter=0;
|
||||
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();)
|
||||
{
|
||||
NetworkInterface intf = en.nextElement();
|
||||
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();)
|
||||
{
|
||||
InetAddress inetAddress = enumIpAddr.nextElement();
|
||||
if (!inetAddress.isLoopbackAddress())
|
||||
if (inetAddress.isSiteLocalAddress())
|
||||
{
|
||||
String strIpAddress=inetAddress.getHostAddress().toString();
|
||||
//MyLog.i("=====================IP1: "+strIpAddress);
|
||||
|
||||
if (strIpAddress!=null) {
|
||||
iCounter++;
|
||||
if (JundgeHostExist(strIpAddress) == false) {
|
||||
hostsTable.add(strIpAddress);
|
||||
MyLog.i("Add new IP Adddress: " + strIpAddress);
|
||||
bNetChange = true;
|
||||
}
|
||||
}
|
||||
//MyLog.i("=====================");
|
||||
//MyLog.i("IP1: "+inetAddress.getHostAddress().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (false)
|
||||
if (iCounter!=hostsTable.size())
|
||||
{ iCounter=hostsTable.size();
|
||||
bNetChange=true;
|
||||
MyLog.i("Clear All IP Adddress: " + hostsTable.size());
|
||||
}
|
||||
}
|
||||
catch (SocketException e) {
|
||||
if (NeedExit() == false)
|
||||
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"
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String GetLocalIP()
|
||||
{ if (hostsTable.size()==0) return null;
|
||||
return (String) hostsTable.get(0);
|
||||
}
|
||||
|
||||
|
||||
boolean JundgeHostExist(String hostIP)
|
||||
{ for (int iOffset=0;iOffset<hostsTable.size();iOffset++) {
|
||||
//MyLog.i("--------IP"+iOffset+" : "+(String)hostsTable.get(iOffset));
|
||||
if (hostIP.equals((String)hostsTable.get(iOffset))) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static List<String> GetBoardCastIp() {
|
||||
List<String> ips = new ArrayList<>();
|
||||
//MyLog.i( "=================10");
|
||||
try {
|
||||
Enumeration<NetworkInterface> eni = NetworkInterface.getNetworkInterfaces();
|
||||
while (eni.hasMoreElements()) {
|
||||
NetworkInterface networkCard = eni.nextElement();
|
||||
if (!networkCard.isUp()) { // 判断网卡是否在使用
|
||||
continue;
|
||||
}
|
||||
//MyLog.i( "=================11");
|
||||
|
||||
String DisplayName = networkCard.getDisplayName();
|
||||
|
||||
List<InterfaceAddress> addressList = networkCard.getInterfaceAddresses();
|
||||
Iterator<InterfaceAddress> addressIterator = addressList.iterator();
|
||||
|
||||
//MyLog.i( "=================12");
|
||||
while (addressIterator.hasNext()) {
|
||||
InterfaceAddress interfaceAddress = addressIterator.next();
|
||||
InetAddress address = interfaceAddress.getAddress();
|
||||
if (address.isLoopbackAddress()) {
|
||||
continue;
|
||||
}
|
||||
String hostAddress = address.getHostAddress();
|
||||
if (!hostAddress.contains(":")) {
|
||||
//MyLog.i( "=================13");
|
||||
String maskAddress = calcMaskByPrefixLength(interfaceAddress.getNetworkPrefixLength());
|
||||
String gateway = calcSubnetAddress(hostAddress, maskAddress);
|
||||
|
||||
String broadcastAddress = null;
|
||||
InetAddress broadcast = interfaceAddress.getBroadcast();
|
||||
if (broadcast != null)
|
||||
broadcastAddress = broadcast.getHostAddress();
|
||||
|
||||
// MyLog.i("----- DisplayName = " + DisplayName);
|
||||
// MyLog.i("----- address = " + hostAddress);
|
||||
// MyLog.i("----- mask = " + maskAddress);
|
||||
// MyLog.i("----- gateway = " + gateway);
|
||||
// MyLog.i("----- broadcast = " + broadcastAddress + "\n");
|
||||
if (null != broadcastAddress) {
|
||||
ips.add(broadcastAddress);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ips;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void printIpAddress() {
|
||||
try {
|
||||
Enumeration<NetworkInterface> eni = NetworkInterface.getNetworkInterfaces();
|
||||
while (eni.hasMoreElements()) {
|
||||
|
||||
NetworkInterface networkCard = eni.nextElement();
|
||||
if (!networkCard.isUp()) { // 判断网卡是否在使用
|
||||
continue;
|
||||
}
|
||||
|
||||
String DisplayName = networkCard.getDisplayName();
|
||||
|
||||
List<InterfaceAddress> addressList = networkCard.getInterfaceAddresses();
|
||||
Iterator<InterfaceAddress> addressIterator = addressList.iterator();
|
||||
while (addressIterator.hasNext()) {
|
||||
InterfaceAddress interfaceAddress = addressIterator.next();
|
||||
InetAddress address = interfaceAddress.getAddress();
|
||||
if (!address.isLoopbackAddress()) {
|
||||
String hostAddress = address.getHostAddress();
|
||||
|
||||
if (hostAddress.indexOf(":") > 0) {
|
||||
} else {
|
||||
String maskAddress = calcMaskByPrefixLength(interfaceAddress.getNetworkPrefixLength());
|
||||
String gateway = calcSubnetAddress(hostAddress, maskAddress);
|
||||
|
||||
String broadcastAddress = null;
|
||||
InetAddress broadcast = interfaceAddress.getBroadcast();
|
||||
if (broadcast != null)
|
||||
broadcastAddress = broadcast.getHostAddress();
|
||||
|
||||
MyLog.i("----- DisplayName = " + DisplayName);
|
||||
MyLog.i("----- address = " + hostAddress);
|
||||
MyLog.i("----- mask = " + maskAddress);
|
||||
MyLog.i("----- gateway = " + gateway);
|
||||
MyLog.i("----- broadcast = " + broadcastAddress + "\n");
|
||||
MyLog.i("----- NetworkInterface Separator ----\n\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static String calcMaskByPrefixLength(int length) {
|
||||
|
||||
int mask = 0xffffffff << (32 - length);
|
||||
int partsNum = 4;
|
||||
int bitsOfPart = 8;
|
||||
int maskParts[] = new int[partsNum];
|
||||
int selector = 0x000000ff;
|
||||
|
||||
for (int i = 0; i < maskParts.length; i++) {
|
||||
int pos = maskParts.length - 1 - i;
|
||||
maskParts[pos] = (mask >> (i * bitsOfPart)) & selector;
|
||||
}
|
||||
|
||||
String result = "";
|
||||
result = result + maskParts[0];
|
||||
for (int i = 1; i < maskParts.length; i++) {
|
||||
result = result + "." + maskParts[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String calcSubnetAddress(String ip, String mask) {
|
||||
String result = "";
|
||||
try {
|
||||
// calc sub-net IP
|
||||
InetAddress ipAddress = InetAddress.getByName(ip);
|
||||
InetAddress maskAddress = InetAddress.getByName(mask);
|
||||
|
||||
byte[] ipRaw = ipAddress.getAddress();
|
||||
byte[] maskRaw = maskAddress.getAddress();
|
||||
|
||||
int unsignedByteFilter = 0x000000ff;
|
||||
int[] resultRaw = new int[ipRaw.length];
|
||||
for (int i = 0; i < resultRaw.length; i++) {
|
||||
resultRaw[i] = (ipRaw[i] & maskRaw[i] & unsignedByteFilter);
|
||||
}
|
||||
|
||||
// make result string
|
||||
result = result + resultRaw[0];
|
||||
for (int i = 1; i < resultRaw.length; i++) {
|
||||
result = result + "." + resultRaw[i];
|
||||
}
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String GetBoardCastIp(String strIP,String strMask)
|
||||
{
|
||||
if (strIP==null) return Define.AllNetBroadcaseIP;
|
||||
if (strIP.length()<"1.1.1.1".length()) return Define.AllNetBroadcaseIP;
|
||||
if (strMask==null) return Define.AllNetBroadcaseIP;
|
||||
if (strMask.length()<"1.1.1.1".length()) return Define.AllNetBroadcaseIP;
|
||||
|
||||
//MyLog.i("strIP: "+strIP);
|
||||
//MyLog.i("strMask: "+strMask);
|
||||
|
||||
int iCounter=0;
|
||||
int IpSeg[]=new int[4];
|
||||
int MaskSeg[]=new int[4];
|
||||
int BocastIPSeg[]=new int[4];
|
||||
|
||||
String[] strIPs = strIP.split("\\.");
|
||||
String[] strMasks = strMask.split("\\.");
|
||||
|
||||
if (strIPs.length!=4) return Define.AllNetBroadcaseIP;
|
||||
if (strMasks.length!=4) return Define.AllNetBroadcaseIP;
|
||||
|
||||
// 把网段换算成整数值。
|
||||
{ iCounter=0;
|
||||
for (String string : strIPs)
|
||||
IpSeg[iCounter++]=Integer.parseInt(string);
|
||||
|
||||
iCounter=0;
|
||||
for (String string : strMasks)
|
||||
MaskSeg[iCounter++]=Integer.parseInt(string);
|
||||
}
|
||||
// 按位算出精确的通播地址。
|
||||
{
|
||||
for (iCounter=0;iCounter<4;iCounter++)
|
||||
{ BocastIPSeg[iCounter]=0;
|
||||
|
||||
for (int i=0;i<8;i++)
|
||||
{
|
||||
if ((MaskSeg[iCounter]&(1<<i))==0) // 掩码为0,则通播地址需为1.
|
||||
{ BocastIPSeg[iCounter]|=(1<<i);
|
||||
}
|
||||
else // 掩码为1,则通播地址为IP地址对应的位.
|
||||
{ if ((IpSeg[iCounter]&(1<<i))!=0)
|
||||
BocastIPSeg[iCounter]|=(1<<i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ""+BocastIPSeg[0]+"."+BocastIPSeg[1]+"."+BocastIPSeg[2]+"."+BocastIPSeg[3];
|
||||
}
|
||||
|
||||
|
||||
void Wifi_SetOn()
|
||||
{ //判断wifi是否开启
|
||||
//if (!wifiManager.isWifiEnabled())
|
||||
{
|
||||
wifiManager.setWifiEnabled(true);
|
||||
}
|
||||
/* */
|
||||
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
||||
int ipAddress = wifiInfo.getIpAddress();
|
||||
String ip = intToIp(ipAddress);
|
||||
MyLog.i("=====================Wifi_SetOn:"+ip);
|
||||
//wifiManager.isScanAlwaysAvailable()
|
||||
}
|
||||
|
||||
|
||||
private String intToIp(int i) {
|
||||
return (i & 0xFF ) + "." +
|
||||
((i >> 8 ) & 0xFF) + "." +
|
||||
((i >> 16 ) & 0xFF) + "." +
|
||||
( i >> 24 & 0xFF) ;
|
||||
}
|
||||
|
||||
//根据Wifi信息获取本地Mac
|
||||
public String getLocalMacAddressFromWifiInfo(){
|
||||
if (wifiManager==null) return null;
|
||||
WifiInfo info = wifiManager.getConnectionInfo();
|
||||
if (info==null) return null;
|
||||
return info.getMacAddress(); // 88:e3:ab:eb:ab:a2
|
||||
}
|
||||
|
||||
|
||||
Boolean bNeedExit=false;
|
||||
boolean NeedExit() { return bNeedExit; }
|
||||
|
||||
public void Exit() {
|
||||
if (NeedExit()) return;
|
||||
bNeedExit=true;
|
||||
if (hostsTable!=null) hostsTable.clear();
|
||||
MyLog.i(" "+ Thread.currentThread().getStackTrace()[2].getFileName() + "-->"
|
||||
+ "Function: " +Thread.currentThread().getStackTrace()[2].getMethodName() + "-->"
|
||||
+ "Line" +Thread.currentThread().getStackTrace()[2].getLineNumber() + ":\r\n"
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package com.xixun.communicate;
|
||||
|
||||
public class OffsetData {
|
||||
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*/
|
||||
}
|
|
@ -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<ReceiverCard> receivers;
|
||||
|
||||
public PointCheck(int w, int h, int rc, List< ReceiverCard> cards){
|
||||
width = w;
|
||||
height = h;
|
||||
receiverCount = rc;
|
||||
receivers = cards;
|
||||
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.xixun.communicate.Protocol;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2018/06/11.
|
||||
*/
|
||||
|
||||
public enum FRAME_PROTCAL_STAGE {
|
||||
|
||||
NONE,
|
||||
HEAD,
|
||||
NAMEPALAT,
|
||||
TEXT,
|
||||
ETX,
|
||||
CHECK,
|
||||
TAIL,
|
||||
NUM
|
||||
}
|
|
@ -0,0 +1,206 @@
|
|||
package com.xixun.communicate.Protocol;
|
||||
|
||||
import com.xixun.communicate.Define;
|
||||
import com.xixun.communicate.IFunctionCallBack;
|
||||
import com.xixun.display.MyLog;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2018/06/08.
|
||||
*/
|
||||
|
||||
public class Modbus {
|
||||
public static int MAX_PACKET_SIZE = (0x20);
|
||||
public static final byte MODBUS_COMMAND_CARRIAGE_NUMBER = (0x06);
|
||||
public static final byte MODBUS_COMMAND_TRAIN_NUMBER = (0x10);
|
||||
|
||||
|
||||
public byte ucCommandType = 0;
|
||||
public int iReceLength = 0;
|
||||
public int iRegAddress=0;
|
||||
public byte[] ReceBuffer = new byte[MAX_PACKET_SIZE];
|
||||
|
||||
int uiCrcCheckCode = 0;
|
||||
int iReceCounter = 0;
|
||||
|
||||
FRAME_PROTCAL_STAGE frameProtocalStage = FRAME_PROTCAL_STAGE.HEAD;
|
||||
|
||||
byte ucDeviceAddress=0;
|
||||
|
||||
IFunctionCallBack FunctionCallBack=null;
|
||||
public Modbus(byte ucDeviceAddress,IFunctionCallBack FunctionCallBack)
|
||||
{ this.ucDeviceAddress=ucDeviceAddress;
|
||||
this.FunctionCallBack = FunctionCallBack;
|
||||
}
|
||||
|
||||
public void ReceFrame(byte ucReceData)
|
||||
{
|
||||
ReceBuffer[iReceCounter++] = (frameProtocalStage==FRAME_PROTCAL_STAGE.CHECK)? 0 : ucReceData;
|
||||
|
||||
ReceBuffer[iReceCounter] = 0; // 补零,用作字符串结束符。
|
||||
|
||||
//System.out.println("frameProtocalStage= "+frameProtocalStage + " Data: "+ Long.toHexString(ucReceData).toUpperCase());
|
||||
|
||||
switch (frameProtocalStage)
|
||||
{
|
||||
case HEAD:
|
||||
if (ReceHead(ucReceData)) frameProtocalStage = FRAME_PROTCAL_STAGE.NAMEPALAT;
|
||||
break;
|
||||
case NAMEPALAT:
|
||||
if (ReceNamepalat(ucReceData)) frameProtocalStage = (iReceLength > 0) ? FRAME_PROTCAL_STAGE.TEXT : FRAME_PROTCAL_STAGE.CHECK;
|
||||
break;
|
||||
case TEXT:
|
||||
if (ReceText(ucReceData)) frameProtocalStage = FRAME_PROTCAL_STAGE.CHECK;
|
||||
break;
|
||||
case CHECK:
|
||||
if (ReceCheck(ucReceData))
|
||||
if (FunctionCallBack != null) {
|
||||
FunctionCallBack.LastReceDataProcess(ReceBuffer, iReceLength);
|
||||
MyLog.i("-----------ReceBuffer2");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ReceClear();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Boolean ReceHead(byte ucReceData)
|
||||
{
|
||||
switch (iReceCounter)
|
||||
{
|
||||
case 1:
|
||||
if (ucReceData != ucDeviceAddress) ReceClear();
|
||||
else
|
||||
{
|
||||
uiCrcCheckCode=0;
|
||||
uiCrcCheckCode= Define.Crc16_Add(uiCrcCheckCode,ucReceData);
|
||||
|
||||
iReceCounter=0;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
ReceClear();
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Boolean ReceNamepalat(byte ucReceData)
|
||||
{ uiCrcCheckCode=Define.Crc16_Add(uiCrcCheckCode,ucReceData);
|
||||
//System.out.println("Received iReceCounter: " + iReceCounter);
|
||||
switch(iReceCounter)
|
||||
{
|
||||
case 1:
|
||||
ucCommandType=ucReceData;
|
||||
switch (ucCommandType)
|
||||
{
|
||||
case MODBUS_COMMAND_CARRIAGE_NUMBER:
|
||||
iReceLength=2;
|
||||
break;
|
||||
case MODBUS_COMMAND_TRAIN_NUMBER:
|
||||
iReceLength=6;
|
||||
break;
|
||||
default:
|
||||
ReceClear();
|
||||
break;
|
||||
}
|
||||
//System.out.println("Received Command: " + ucCommandType);
|
||||
break;
|
||||
case 2:
|
||||
iRegAddress=((int)ucReceData)<<8;
|
||||
break;
|
||||
case 3:
|
||||
iRegAddress|=ucReceData;
|
||||
if (iRegAddress>1024) ReceClear();
|
||||
else {
|
||||
//System.out.println("Received iRegAddress: " + iRegAddress);
|
||||
iReceCounter=0;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ReceClear();
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Boolean ReceText(byte ucReceData)
|
||||
{ uiCrcCheckCode=Define.Crc16_Add(uiCrcCheckCode,ucReceData);
|
||||
if (iReceCounter == iReceLength)
|
||||
{ //iReceCounter=0; // 会清掉数据。
|
||||
MyLog.i(" uiCrcCheckCode: 0x" + Long.toHexString(uiCrcCheckCode).toUpperCase());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Boolean ReceCheck(byte ucReceData)
|
||||
{ // 兼容校验码高低字节,均可先后传。
|
||||
switch(iReceCounter-iReceLength)
|
||||
{
|
||||
case 1:
|
||||
if ((uiCrcCheckCode%0x100)!=(ucReceData&0xFF)) { // 先传低字节校验码。
|
||||
MyLog.i(" (uiCrcCheckCode%0x100): 0x" + Long.toHexString((uiCrcCheckCode%0x100)).toUpperCase());
|
||||
MyLog.i(" ucReceData: 0x" + Long.toHexString(((int)ucReceData)).toUpperCase());
|
||||
|
||||
if (uiCrcCheckCode/0x100!=(ucReceData&0xFF)) { // 先传高字节校验码。
|
||||
MyLog.i(" (uiCrcCheckCode/0x100): 0x" + Long.toHexString((uiCrcCheckCode / 0x100)).toUpperCase());
|
||||
MyLog.i(" ucReceData: 0x" + Long.toHexString((ucReceData)).toUpperCase());
|
||||
//忽略校验码 ReceClear();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
ReceClear();
|
||||
if (uiCrcCheckCode/0x100!=(ucReceData&0xFF)) { // 再传高字节校验码。
|
||||
MyLog.i(" (uiCrcCheckCode/0x100): 0x" + Long.toHexString((uiCrcCheckCode / 0x100)).toUpperCase());
|
||||
MyLog.i(" ucReceData: 0x" + Long.toHexString((ucReceData)).toUpperCase());
|
||||
|
||||
if ((uiCrcCheckCode%0x100)!=(ucReceData&0xFF)) { // 再传低字节校验码。
|
||||
MyLog.i(" (uiCrcCheckCode%0x100): 0x" + Long.toHexString((uiCrcCheckCode%0x100)).toUpperCase());
|
||||
MyLog.i(" ucReceData: 0x" + Long.toHexString(((int)ucReceData)).toUpperCase());
|
||||
//忽略校验码 return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
ReceClear();
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void ReceClear()
|
||||
{
|
||||
frameProtocalStage = FRAME_PROTCAL_STAGE.HEAD;
|
||||
iReceCounter=0;
|
||||
}
|
||||
|
||||
public void TransData_Byte(byte ucAddress, byte ucCommand, int uiRegAddress,byte[] DataBuffer, int iLength)
|
||||
{
|
||||
int iOffset = 0;
|
||||
byte[] dataBuffer = new byte[iLength + 6];
|
||||
|
||||
dataBuffer[iOffset++] = ucAddress;
|
||||
dataBuffer[iOffset++] = ucCommand;
|
||||
dataBuffer[iOffset++] = (byte)(uiRegAddress>>8); // 寄存器地址高。
|
||||
dataBuffer[iOffset++] = (byte)(uiRegAddress); // 寄存器地址低。
|
||||
|
||||
if (DataBuffer!=null && iLength>0) {
|
||||
System.arraycopy(DataBuffer, 0, dataBuffer, iOffset, iLength); // 正文内容。
|
||||
iOffset += iLength;
|
||||
}
|
||||
|
||||
int uiCrc=Define.chksum_crc16(dataBuffer,0,iOffset);
|
||||
|
||||
dataBuffer[iOffset++] = (byte)(uiCrc); // CRC16低字节。
|
||||
dataBuffer[iOffset++] = (byte)(uiCrc>>8); // CRC16高字节。
|
||||
|
||||
if (FunctionCallBack!=null) FunctionCallBack.LastSendDataProcess(dataBuffer, iOffset);
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,228 @@
|
|||
package com.xixun.communicate.Protocol;
|
||||
|
||||
import com.xixun.communicate.Define;
|
||||
import com.xixun.communicate.IFunctionCallBack;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2018/01/17.
|
||||
*/
|
||||
|
||||
public class StreamPort {
|
||||
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 int iReceLength = 0;
|
||||
|
||||
byte ucCheckCode = 0;
|
||||
int iReceCounter = 0;
|
||||
boolean bCheck = true;
|
||||
|
||||
public NET_COMMU_TYPE ucCommandType = NET_COMMU_TYPE.NONE;
|
||||
public byte ucIdence = 0;
|
||||
public byte ucPipeId = 0;
|
||||
//added by alahover 20190412 -start
|
||||
public boolean m_bAck = false;
|
||||
//added by alahover 20190412 -end
|
||||
|
||||
public byte[] ReceBuffer = new byte[MAX_PACKET_SIZE + 256];
|
||||
FRAME_PROTCAL_STAGE frameProtocalStage = FRAME_PROTCAL_STAGE.HEAD;
|
||||
|
||||
public String clientIpAddress = null;
|
||||
|
||||
IFunctionCallBack FunctionCallBack = null;
|
||||
|
||||
public StreamPort() {
|
||||
}
|
||||
|
||||
public StreamPort(String clientIpAddress, boolean bCheck, IFunctionCallBack FunctionCallBack) {
|
||||
this.clientIpAddress = clientIpAddress;
|
||||
this.bCheck = bCheck;
|
||||
this.FunctionCallBack = FunctionCallBack;
|
||||
}
|
||||
|
||||
public boolean ReceFrame(byte ucReceData) {
|
||||
//System.out.println("ReceFrame "+" Data: "+ ucReceData);
|
||||
ReceBuffer[iReceCounter++] = ucReceData;
|
||||
ReceBuffer[iReceCounter] = 0; // 补零,用作字符串结束符。
|
||||
|
||||
//System.out.println("frameProtocalStage= "+frameProtocalStage + " Data: "+ ucReceData);
|
||||
|
||||
switch (frameProtocalStage) {
|
||||
case HEAD:
|
||||
if (ReceHead(ucReceData)) frameProtocalStage = FRAME_PROTCAL_STAGE.NAMEPALAT;
|
||||
break;
|
||||
case NAMEPALAT:
|
||||
if (ReceNamepalat(ucReceData))
|
||||
frameProtocalStage = (iReceLength > 0) ? FRAME_PROTCAL_STAGE.TEXT : FRAME_PROTCAL_STAGE.CHECK;
|
||||
break;
|
||||
case TEXT:
|
||||
if (ReceText(ucReceData)) frameProtocalStage = FRAME_PROTCAL_STAGE.CHECK;
|
||||
break;
|
||||
case CHECK:
|
||||
if (ReceCheck(ucReceData)) {
|
||||
//System.out.println("ReceFrame Step 00 ucCommandType="+ucCommandType);
|
||||
if (FunctionCallBack != null) {
|
||||
FunctionCallBack.LastReceDataProcess(null, 0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
ReceClear();
|
||||
break;
|
||||
default:
|
||||
ReceClear();
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Boolean ReceHead(byte ucReceData) {
|
||||
switch (iReceCounter) {
|
||||
case 1:
|
||||
case 2:
|
||||
//System.out.println("12 STREAM_SYNC_HEAD= "+STREAM_SYNC_HEAD + " Data: "+ ucReceData);
|
||||
if (ucReceData != STREAM_SYNC_HEAD) {
|
||||
if (ucReceData != STREAM_SYNC_HEAD2) ReceClear();
|
||||
else {
|
||||
if (iReceCounter == 2) iReceCounter = 3; // 第一个“STREAM_SYNC_HEAD”可能丢失,补上一个。
|
||||
else ReceClear();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
//System.out.println("3 frameProtocalStage= "+frameProtocalStage + " Data: "+ ucReceData);
|
||||
if (ucReceData != STREAM_SYNC_HEAD2) ReceClear();
|
||||
break;
|
||||
case 4:
|
||||
//System.out.println("4 frameProtocalStage= "+frameProtocalStage + " Data: "+ ucReceData);
|
||||
ReceClear();
|
||||
ucCheckCode = ucReceData; // 命令类型开始计数。
|
||||
ucIdence = 0;
|
||||
ucPipeId = 0;
|
||||
ucCommandType = NET_COMMU_TYPE.GetEnumValue(ucReceData);
|
||||
//System.out.println("ReceHead Received Command: " + ucCommandType);
|
||||
return true;
|
||||
default:
|
||||
ReceClear();
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Boolean ReceNamepalat(byte ucReceData) {
|
||||
ucCheckCode += ucReceData;
|
||||
|
||||
switch (iReceCounter) {
|
||||
case 1:
|
||||
ucIdence = ucReceData;
|
||||
break;
|
||||
case 2:
|
||||
ucPipeId = ucReceData;
|
||||
break;
|
||||
//20190412 added by alahover -start
|
||||
case 3:
|
||||
if (ucReceData == 1)
|
||||
m_bAck = true;
|
||||
else
|
||||
m_bAck = false;
|
||||
break;
|
||||
//20190412 added by alahover -end
|
||||
case 8:
|
||||
iReceLength = Define.GetIntFromByte(ReceBuffer, 4);
|
||||
ReceClear();
|
||||
//System.out.println("-----------------Received Command Length: " + iReceLength);
|
||||
if (iReceLength <= ReceBuffer.length) return true;
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Boolean ReceText(byte ucReceData) {
|
||||
ucCheckCode += ucReceData;
|
||||
return (iReceCounter == iReceLength);
|
||||
}
|
||||
|
||||
Boolean ReceCheck(byte ucReceData) {
|
||||
if (ucCheckCode == ~ucReceData) {
|
||||
ReceBuffer[iReceCounter] = '\0'; // 补零,防止字符串。
|
||||
return true;
|
||||
} else {
|
||||
//System.out.println("iReceLength="+iReceLength+ ", Need CheckCode: " + "0x" + Integer.toHexString((~ucCheckCode)& 0xFF) + ", Error Received: " + "0x" + Integer.toHexString(ucReceData& 0xFF));
|
||||
}
|
||||
if (bCheck == false) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void ReceClear() {
|
||||
frameProtocalStage = FRAME_PROTCAL_STAGE.HEAD;
|
||||
iReceCounter = 0;
|
||||
}
|
||||
|
||||
public void TransData_Byte(byte ucCommand, byte ucIdence, byte ucPipeId, byte[] DataBuffer, int iLength) {
|
||||
int iOffset = 0;
|
||||
//System.out.println("1 Trans Command: "+ucCommand);
|
||||
|
||||
byte[] dataBuffer = new byte[iLength + 13];
|
||||
|
||||
dataBuffer[iOffset++] = STREAM_SYNC_HEAD; // 0x7E,同步头。
|
||||
dataBuffer[iOffset++] = STREAM_SYNC_HEAD; // 0x7E。
|
||||
dataBuffer[iOffset++] = 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++;
|
||||
|
||||
if (FunctionCallBack != null) {
|
||||
FunctionCallBack.LastSendDataProcess(dataBuffer, iOffset);
|
||||
// System.out.println("---------LastSendDataProcess ok iOffset="+iOffset);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 功能:从spi读取发送接收卡参数,保存成文件
|
||||
*/
|
||||
public int GetFpgaParamFileFromSpi(String strFileName) {
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "StreamPort{" +
|
||||
"iReceLength=" + iReceLength +
|
||||
", ucCheckCode=" + ucCheckCode +
|
||||
", iReceCounter=" + iReceCounter +
|
||||
", bCheck=" + bCheck +
|
||||
", ucCommandType=" + ucCommandType +
|
||||
", ucIdence=" + ucIdence +
|
||||
", ucPipeId=" + ucPipeId +
|
||||
", m_bAck=" + m_bAck +
|
||||
", ReceBuffer=" + Arrays.toString(ReceBuffer) +
|
||||
", frameProtocalStage=" + frameProtocalStage +
|
||||
", clientIpAddress='" + clientIpAddress + '\'' +
|
||||
", FunctionCallBack=" + FunctionCallBack +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
|
@ -0,0 +1,225 @@
|
|||
package com.xixun.communicate;
|
||||
|
||||
import android.location.Criteria;
|
||||
import android.location.Location;
|
||||
|
||||
import com.xixun.display.MainActivity;
|
||||
import com.xixun.display.MyLog;
|
||||
import com.xixun.display.MyService;
|
||||
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2018/08/09.
|
||||
* 163.53.193.72
|
||||
*/
|
||||
|
||||
public class Report
|
||||
{
|
||||
LedCardCommunication ledCardCommunication=null;
|
||||
MyService ms=null;
|
||||
String strCardID=null;
|
||||
String strDoMain=null;
|
||||
int iPort=0;
|
||||
|
||||
String strIpAddress=null;
|
||||
|
||||
|
||||
DatagramSocket udpSendSocket =null;
|
||||
|
||||
public Report(LedCardCommunication ledCardCommunication,String strDoMain,int iPort)
|
||||
{ this.ledCardCommunication=ledCardCommunication;
|
||||
this.strDoMain=strDoMain;
|
||||
this.iPort=iPort;
|
||||
|
||||
if (ledCardCommunication==null) return;
|
||||
|
||||
if (strDoMain==null) return;
|
||||
if (strDoMain.length()<"w.c".length()) return;
|
||||
|
||||
ms=ledCardCommunication.clientsManage.ms;
|
||||
this.strCardID=ledCardCommunication.Get_DisplayID();
|
||||
|
||||
|
||||
new Thread() {
|
||||
public void run() {
|
||||
Process();
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
private void Process()
|
||||
{ Criteria c = new Criteria();//Criteria类是设置定位的标准信息(系统会根据你的要求,匹配最适合你的定位供应商),一个定位的辅助信息的类
|
||||
|
||||
|
||||
{
|
||||
c.setPowerRequirement(Criteria.POWER_LOW);//设置低耗电
|
||||
c.setAltitudeRequired(true);//设置需要海拔
|
||||
c.setBearingAccuracy(Criteria.ACCURACY_COARSE);//设置COARSE精度标准
|
||||
c.setAccuracy(Criteria.ACCURACY_LOW);//设置低精度
|
||||
//... Criteria 还有其他属性,就不一一介绍了
|
||||
Location best = LocationUtils.getBestLocation(ms, c);
|
||||
|
||||
if (best == null) {
|
||||
MyLog.i("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Best location is null");
|
||||
} else {
|
||||
MyLog.i("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!best location: lat==" + best.getLatitude() + " lng==" + best.getLongitude());
|
||||
}
|
||||
|
||||
|
||||
Location net = LocationUtils.getNetWorkLocation(ms);
|
||||
if (net == null) {
|
||||
MyLog.i("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!net location is null");
|
||||
} else {
|
||||
MyLog.i("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!net location: lat==" + net.getLatitude() + " lng==" + net.getLongitude());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
while(NeedExit()==false) {
|
||||
|
||||
try {
|
||||
Thread.sleep(5*1000); // sleep(1000); // 第一次时,先等待其他服务端口套接字线程准备好。
|
||||
|
||||
try{
|
||||
InetAddress x = java.net.InetAddress.getByName(strDoMain);
|
||||
strIpAddress = x.getHostAddress();//得到字符串形式的ip地址.
|
||||
|
||||
if (strIpAddress==null) continue;
|
||||
if (strIpAddress.length()<"1.1.1.1".length()) continue;
|
||||
|
||||
MyLog.i(strDoMain+" IP:"+strIpAddress);
|
||||
|
||||
//strIpAddress="192.168.1.255";//112";
|
||||
}
|
||||
catch (UnknownHostException e)
|
||||
{ //e.printStackTrace();
|
||||
//MyLog.i("域名解析出错");
|
||||
continue;
|
||||
}
|
||||
|
||||
udpSendSocket = new DatagramSocket(null);
|
||||
udpSendSocket.setReuseAddress(true);
|
||||
udpSendSocket.bind(new InetSocketAddress(iPort));
|
||||
|
||||
String staAlias=null;
|
||||
int iCounter=0;
|
||||
|
||||
while (NeedExit()==false)
|
||||
{
|
||||
Location best = LocationUtils.getBestLocation(ms, c);
|
||||
|
||||
iCounter++;
|
||||
if (iCounter>10)
|
||||
{
|
||||
iCounter=0;
|
||||
staAlias=null;
|
||||
}
|
||||
if (staAlias==null)
|
||||
{
|
||||
staAlias=ledCardCommunication.GetAlias();
|
||||
}
|
||||
|
||||
//if (best != null)
|
||||
{
|
||||
String str =
|
||||
"{"
|
||||
+ "\"CardID\":\"" + strCardID
|
||||
+ "\",\"Alias\":\"" + staAlias
|
||||
+ "\",\"Display\":\"" + (ledCardCommunication.GetSecreenOn()?"ON":"OFF")
|
||||
+ "\",\"PlayProgram\":\"" + ledCardCommunication.GetPlayProgram()
|
||||
+ "\",\"Latitude\":\"" + ((best != null) ? best.getLatitude() :null)
|
||||
+ "\",\"Longitude\":\"" + ((best != null) ? best.getLongitude() :null)
|
||||
+ "\",\"Speed\":\"" + ((best != null) ? best.getSpeed() :null)
|
||||
|
||||
+"\"}";
|
||||
byte sendDataBuffer[] = str.getBytes();
|
||||
DatagramPacket sendPacket = new DatagramPacket(sendDataBuffer, sendDataBuffer.length, InetAddress.getByName(strIpAddress), iPort);
|
||||
udpSendSocket.send(sendPacket);
|
||||
MyLog.i( str );
|
||||
}
|
||||
|
||||
|
||||
Thread.sleep(15*1000);
|
||||
}
|
||||
}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"
|
||||
);
|
||||
}finally {
|
||||
if (udpSendSocket!=null) {
|
||||
udpSendSocket.close();
|
||||
udpSendSocket=null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过GPS获取定位信息
|
||||
|
||||
public void getGPSLocation() {
|
||||
Location gps = LocationUtils.getGPSLocation(this);
|
||||
if (gps == null) {
|
||||
//设置定位监听,因为GPS定位,第一次进来可能获取不到,通过设置监听,可以在有效的时间范围内获取定位信息
|
||||
LocationUtils.addLocationListener(context, LocationManager.GPS_PROVIDER, new LocationUtils.ILocationListener() {
|
||||
@Override
|
||||
public void onSuccessLocation(Location location) {
|
||||
if (location != null) {
|
||||
Toast.makeText(MainActivity.this, "gps onSuccessLocation location: lat==" + location.getLatitude() + " lng==" + location.getLongitude(), Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Toast.makeText(MainActivity.this, "gps location is null", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Toast.makeText(this, "gps location: lat==" + gps.getLatitude() + " lng==" + gps.getLongitude(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 通过网络等获取定位信息
|
||||
|
||||
private void getNetworkLocation() {
|
||||
Location net = LocationUtils.getNetWorkLocation(Activity);
|
||||
if (net == null) {
|
||||
Toast.makeText(this, "net location is null", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Toast.makeText(this, "network location: lat==" + net.getLatitude() + " lng==" + net.getLongitude(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 采用最好的方式获取定位信息
|
||||
|
||||
private void getBestLocation() {
|
||||
Criteria c = new Criteria();//Criteria类是设置定位的标准信息(系统会根据你的要求,匹配最适合你的定位供应商),一个定位的辅助信息的类
|
||||
c.setPowerRequirement(Criteria.POWER_LOW);//设置低耗电
|
||||
c.setAltitudeRequired(true);//设置需要海拔
|
||||
c.setBearingAccuracy(Criteria.ACCURACY_COARSE);//设置COARSE精度标准
|
||||
c.setAccuracy(Criteria.ACCURACY_LOW);//设置低精度
|
||||
//... Criteria 还有其他属性,就不一一介绍了
|
||||
Location best = LocationUtils.getBestLocation(Activity, c);
|
||||
if (best == null) {
|
||||
Toast.makeText(this, " best location is null", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Toast.makeText(this, "best location: lat==" + best.getLatitude() + " lng==" + best.getLongitude(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
boolean bNeedExit=false;
|
||||
public boolean NeedExit() { return bNeedExit; }
|
||||
|
||||
public void Exit()
|
||||
{ if (NeedExit()) return;
|
||||
bNeedExit=true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,233 @@
|
|||
package com.xixun.communicate;
|
||||
|
||||
|
||||
import com.xixun.display.MyLog;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 16/11/15.
|
||||
*/
|
||||
enum ReceFileState {
|
||||
NONE,
|
||||
READY,
|
||||
FILE_EXIST,
|
||||
SUCCESS
|
||||
}
|
||||
|
||||
public class SendFile{
|
||||
private ReceFileState receFileState = ReceFileState.NONE;
|
||||
|
||||
Socket socket=null;
|
||||
DataInputStream receStream=null;
|
||||
DataOutputStream sendStream=null;
|
||||
|
||||
boolean bReady = false;
|
||||
public boolean GetReady() { return bReady; }
|
||||
|
||||
private ClientManage clientManage=null;
|
||||
private String clientIpAddress=null;
|
||||
|
||||
SendFile(ClientManage clientManage,Socket socket)
|
||||
{ this.clientManage=clientManage;
|
||||
this.socket=socket;
|
||||
|
||||
clientIpAddress=socket.getInetAddress().getHostAddress();
|
||||
|
||||
new Thread() {
|
||||
public void run() {
|
||||
Process();
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
private void Process()
|
||||
{ try {
|
||||
receStream = new DataInputStream(socket.getInputStream());
|
||||
sendStream = new DataOutputStream(socket.getOutputStream());
|
||||
bReady=true;
|
||||
|
||||
while (GetReady() && (NeedExit()==false)) {
|
||||
try {
|
||||
String fileState = receStream.readUTF();
|
||||
//System.out.println("Rece File State: "+ fileState);
|
||||
|
||||
switch (fileState)
|
||||
{
|
||||
case "FileReceReady":
|
||||
receFileState = ReceFileState.READY;
|
||||
break;
|
||||
case "FileExist":
|
||||
receFileState = ReceFileState.FILE_EXIST;
|
||||
break;
|
||||
case "FileReceSuccess":
|
||||
receFileState = ReceFileState.SUCCESS;
|
||||
break;
|
||||
default:
|
||||
receFileState = ReceFileState.NONE;
|
||||
break;
|
||||
}
|
||||
|
||||
//System.out.println("Rece File State: "+ fileState + " Value=" +receFileState);
|
||||
} catch (Exception e) {
|
||||
if (NeedExit()==false || GetReady())
|
||||
System.out.println(clientIpAddress+ " " + 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"
|
||||
);
|
||||
stop();
|
||||
break;
|
||||
} finally {
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
stop();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean WaitCommandAck(int iDelayMs) {
|
||||
while (iDelayMs > 0) {
|
||||
if (NeedExit()) break;
|
||||
if (GetReady()==false) break;
|
||||
|
||||
if (receFileState != ReceFileState.NONE) return true;
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e1) {
|
||||
e1.printStackTrace();
|
||||
break;
|
||||
}
|
||||
iDelayMs -= 100;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int SendFilePro(String pathFile, String strObjectName) throws IOException {
|
||||
int size = -1;
|
||||
long fileLength = 0;
|
||||
int iWorkResault = 0;
|
||||
byte[] buffer = new byte[1024];
|
||||
FileInputStream fileInputStream = null;
|
||||
DataInputStream dataInputStream = null;
|
||||
|
||||
if (NeedExit()) return -1;
|
||||
if (GetReady()==false) return -1;
|
||||
if (sendStream == null) return -1;
|
||||
|
||||
if (pathFile == null) return 0;
|
||||
if (pathFile.length()<=0) return -1;
|
||||
if (strObjectName == null) return 0;
|
||||
if (strObjectName.length()<=0) return -1;
|
||||
|
||||
//System.out.println(clientIpAddress+" Send FileName: \"" + pathFile + ", to File Name :" + strObjectName);
|
||||
|
||||
File file=new File(pathFile);
|
||||
if (file.exists()==false) return -1;
|
||||
|
||||
|
||||
|
||||
try {
|
||||
|
||||
synchronized (this) {
|
||||
int length = 0;
|
||||
fileInputStream = new FileInputStream(pathFile);
|
||||
dataInputStream = new DataInputStream(fileInputStream);
|
||||
|
||||
fileLength = new File(pathFile).length();
|
||||
|
||||
receFileState = ReceFileState.NONE;
|
||||
|
||||
|
||||
sendStream.writeUTF(strObjectName);
|
||||
sendStream.flush();
|
||||
sendStream.writeLong(fileLength);
|
||||
sendStream.flush();
|
||||
|
||||
WaitCommandAck(5000);
|
||||
switch (receFileState)
|
||||
{ case READY:
|
||||
receFileState = ReceFileState.NONE;
|
||||
while (NeedExit()==false) {
|
||||
if (GetReady()==false) break;
|
||||
if ((length = dataInputStream.read(buffer)) <= 0) break;
|
||||
sendStream.write(buffer, 0, length);
|
||||
}
|
||||
sendStream.flush();
|
||||
if (NeedExit()==false || (GetReady()))
|
||||
WaitCommandAck(5000);
|
||||
if (NeedExit() || (GetReady()==false))
|
||||
MyLog.i(clientIpAddress+ " Need exit,FileName: \"" + pathFile + ", to File Name :" + strObjectName + " may be sendded!");
|
||||
else if (receFileState == ReceFileState.SUCCESS)
|
||||
MyLog.i(clientIpAddress+" FileName: \"" + pathFile + "\" Lenth: " + fileLength + ", to File Name :" + strObjectName + " Send Ok!");
|
||||
else
|
||||
MyLog.i(clientIpAddress+" FileName: \"" + pathFile + "\" Lenth: " + fileLength + ", to File Name :" + strObjectName + " UnknowState:" + receFileState);
|
||||
break;
|
||||
case FILE_EXIST:
|
||||
MyLog.i(clientIpAddress+" FileName: \"" + pathFile + "\" Have Exist,Needn't Send!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (NeedExit()==false || GetReady())
|
||||
MyLog.i(clientIpAddress+ " "+ 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"
|
||||
);
|
||||
stop();
|
||||
//System.out.println(clientIpAddress+ " FileName: \"" + pathFile + "\" Send Error!");
|
||||
iWorkResault = -1;
|
||||
} finally {
|
||||
try {
|
||||
} catch (Exception e1) {
|
||||
if (dataInputStream != null) dataInputStream.close();
|
||||
if (fileInputStream != null) fileInputStream.close();
|
||||
}
|
||||
|
||||
}
|
||||
return iWorkResault;
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
//if (GetReady()==false) return;
|
||||
try {
|
||||
bReady = false;
|
||||
|
||||
if (NeedExit()==false) // 非外部请求造成的退出,需要注销当前显示屏。
|
||||
clientManage.Request_Exit();
|
||||
|
||||
if (receStream != null) receStream.close();
|
||||
if (sendStream != null) sendStream.close();
|
||||
if (socket != null) socket.close();
|
||||
} catch (Exception e) { }
|
||||
if (NeedExit()==false)
|
||||
MyLog.i(clientIpAddress+ " "+ Thread.currentThread().getStackTrace()[2].getFileName() + "-->"
|
||||
+ "Function: " +Thread.currentThread().getStackTrace()[2].getMethodName()
|
||||
);
|
||||
}
|
||||
|
||||
boolean bNeedExit=false;
|
||||
public boolean NeedExit() { return bNeedExit; }
|
||||
public void Exit()
|
||||
{ if (bNeedExit) return;
|
||||
bNeedExit=true;
|
||||
stop();
|
||||
|
||||
MyLog.i(" "+ Thread.currentThread().getStackTrace()[2].getFileName() + "-->"
|
||||
+ "Function: " +Thread.currentThread().getStackTrace()[2].getMethodName() + "-->"
|
||||
+ "Line" +Thread.currentThread().getStackTrace()[2].getLineNumber() + ":\r\n"
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,155 @@
|
|||
package com.xixun.communicate;
|
||||
import com.xixun.communicate.Protocol.Modbus;
|
||||
import com.xixun.display.MyLog;
|
||||
import com.xixun.display.MyService;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2018/06/08.
|
||||
*/
|
||||
|
||||
public class SerialExtension {
|
||||
LedCardCommunication ledCardCommunication=null;
|
||||
|
||||
public AidlSerialPort aidlSerialPort=null;
|
||||
|
||||
Modbus modbus=null;
|
||||
|
||||
|
||||
SerialExtension(LedCardCommunication ledCardCommunication)
|
||||
{ this.ledCardCommunication=ledCardCommunication;
|
||||
|
||||
new Thread() {
|
||||
public void run() {
|
||||
Process();
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
void Process()
|
||||
{
|
||||
try {
|
||||
MyLog.i("12SerialExtension-》Process");
|
||||
modbus = new Modbus((byte)0x01,new IFunctionCallBack() {
|
||||
@Override
|
||||
public void LastSendDataProcess(byte[] DataBuffer, int iLength) { // 协议包数据最终发送。数据打包完后最终发送
|
||||
TransProcess(DataBuffer,iLength);
|
||||
}
|
||||
@Override
|
||||
public void LastReceDataProcess(byte[] DataBuffer, int iLength) { // 协议包数据最终接收。数据解包完后最终处理。
|
||||
ReceProcess();
|
||||
}
|
||||
});
|
||||
MyLog.i("------------------AidlSerialPort");
|
||||
aidlSerialPort = new AidlSerialPort(ledCardCommunication, LedCardCommunication.serialDeviceName_Extention, 9600);
|
||||
bReady=true;
|
||||
|
||||
aidlSerialPort.SetCallFunc(new IFunctionCallBack() {
|
||||
@Override
|
||||
public void LastSendDataProcess(byte[] DataBuffer, int iLength) { // AIDL 裸数据发送。暂时不用。
|
||||
TransProcess(DataBuffer,iLength);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void LastReceDataProcess(byte[] DataBuffer, int iLength) { // AIDL 裸数据接收。每个字节都会调用
|
||||
if (NeedExit()) return;
|
||||
if (GetReady()==false) return;
|
||||
|
||||
if (DataBuffer==null)
|
||||
{
|
||||
ledCardCommunication.Request_Exit();
|
||||
return;
|
||||
}
|
||||
|
||||
if (iLength<=0)
|
||||
{
|
||||
ledCardCommunication.Request_Exit();
|
||||
return;
|
||||
}
|
||||
|
||||
//MyLog.i("iLength= "+iLength);
|
||||
//if (false)
|
||||
for (int i=0;i<iLength;i++ )
|
||||
{
|
||||
//MyLog.i("" + Integer.toHexString(DataBuffer[i] & 0xFF) + " ");
|
||||
modbus.ReceFrame(DataBuffer[i]);
|
||||
}
|
||||
}
|
||||
});
|
||||
} 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"
|
||||
);
|
||||
ledCardCommunication.Request_Exit();
|
||||
}
|
||||
|
||||
while (NeedExit()==false){
|
||||
try {
|
||||
Thread.sleep(3000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
ledCardCommunication.Request_Exit();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void ReceProcess() {
|
||||
int iLength = 0;
|
||||
if (NeedExit()) return;
|
||||
if (GetReady()==false) return;
|
||||
|
||||
if (ledCardCommunication==null) return;
|
||||
if (ledCardCommunication.clientsManage==null) return;
|
||||
if (ledCardCommunication.clientsManage.ms==null) return;
|
||||
|
||||
MyLog.i("modbus.ucCommandType="+modbus.ucCommandType);
|
||||
|
||||
switch (modbus.ucCommandType)
|
||||
{
|
||||
case Modbus.MODBUS_COMMAND_CARRIAGE_NUMBER:
|
||||
ledCardCommunication.clientsManage.ms.workParams.iDirection=modbus.ReceBuffer[0];
|
||||
ledCardCommunication.clientsManage.ms.workParams.iCarriageNumber=modbus.ReceBuffer[1];
|
||||
break;
|
||||
case Modbus.MODBUS_COMMAND_TRAIN_NUMBER:
|
||||
if (ledCardCommunication.clientsManage.ms.workParams.strStationNumber==null) return;
|
||||
ledCardCommunication.clientsManage.ms.workParams.strStationNumber=
|
||||
new String(modbus.ReceBuffer,0,modbus.iReceLength-1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
ledCardCommunication.clientsManage.ms.workParams.pushBaseParams();
|
||||
ledCardCommunication.clientsManage.ms.SendMessage(MyService.MSG_CHANGE_NONE,"");
|
||||
}
|
||||
|
||||
void TransProcess(byte[] DataBuffer, int iLength) {
|
||||
if (NeedExit()) return;
|
||||
if (GetReady() == false) return;
|
||||
if (aidlSerialPort == null) return;
|
||||
|
||||
aidlSerialPort.TransData_Byte(DataBuffer,iLength);
|
||||
}
|
||||
|
||||
|
||||
boolean bReady=false;
|
||||
public boolean GetReady() { return bReady; }
|
||||
|
||||
boolean bNeedExit=false;
|
||||
public boolean NeedExit() { return bNeedExit; }
|
||||
|
||||
public void Exit()
|
||||
{ if (NeedExit()) return;
|
||||
bNeedExit=true;
|
||||
|
||||
if (aidlSerialPort != null) aidlSerialPort.Exit();
|
||||
aidlSerialPort=null;
|
||||
|
||||
MyLog.i(" "+ Thread.currentThread().getStackTrace()[2].getFileName() + "-->"
|
||||
+ "Function: " +Thread.currentThread().getStackTrace()[2].getMethodName() + "-->"
|
||||
+ "Line" +Thread.currentThread().getStackTrace()[2].getLineNumber() + ":\r\n"
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* Copyright 2009 Cedric Priscal
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.xixun.communicate;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.xixun.display.MyLog;
|
||||
|
||||
public class SerialPort {
|
||||
|
||||
private static final String TAG = "SerialPort";
|
||||
|
||||
/*
|
||||
* Do not remove or rename the field mFd: it is used by native method close();
|
||||
*/
|
||||
private FileDescriptor mFd;
|
||||
private FileInputStream mFileInputStream;
|
||||
private FileOutputStream mFileOutputStream;
|
||||
|
||||
public SerialPort(File device, int baudrate, int flags) throws SecurityException, IOException {
|
||||
|
||||
/* Check access permission */
|
||||
if (!device.canRead() || !device.canWrite()) {
|
||||
try {
|
||||
/* Missing read/write permission, trying to chmod the file */
|
||||
Process su;
|
||||
su = Runtime.getRuntime().exec("/system/bin/su");
|
||||
String cmd = "chmod 666 " + device.getAbsolutePath() + "\n"
|
||||
+ "exit\n";
|
||||
su.getOutputStream().write(cmd.getBytes());
|
||||
if ((su.waitFor() != 0) || !device.canRead()
|
||||
|| !device.canWrite()) {
|
||||
throw new SecurityException();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new SecurityException();
|
||||
}
|
||||
}
|
||||
MyLog.i("======================device.getAbsolutePath():"+ device.getAbsolutePath());
|
||||
mFd = open(device.getAbsolutePath(), baudrate, flags);
|
||||
if (mFd == null) {
|
||||
Log.e(TAG, "native open returns null");
|
||||
throw new IOException();
|
||||
}
|
||||
mFileInputStream = new FileInputStream(mFd);
|
||||
mFileOutputStream = new FileOutputStream(mFd);
|
||||
}
|
||||
|
||||
// Getters and setters
|
||||
public InputStream getInputStream() {
|
||||
return mFileInputStream;
|
||||
}
|
||||
|
||||
public OutputStream getOutputStream() {
|
||||
return mFileOutputStream;
|
||||
}
|
||||
|
||||
// JNI
|
||||
private native static FileDescriptor open(String path, int baudrate, int flags);
|
||||
public native void close();
|
||||
static {
|
||||
System.loadLibrary("serial_port");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,228 @@
|
|||
package com.xixun.communicate;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ShellUtils
|
||||
* <ul>
|
||||
* <strong>Check root</strong>
|
||||
* <li>{@link ShellUtils#checkRootPermission()}</li>
|
||||
* </ul>
|
||||
* <ul>
|
||||
* <strong>Execte command</strong>
|
||||
* <li>{@link ShellUtils#execCommand(String, boolean)}</li>
|
||||
* <li>{@link ShellUtils#execCommand(String, boolean, boolean)}</li>
|
||||
* <li>{@link ShellUtils#execCommand(List, boolean)}</li>
|
||||
* <li>{@link ShellUtils#execCommand(List, boolean, boolean)}</li>
|
||||
* <li>{@link ShellUtils#execCommand(String[], boolean)}</li>
|
||||
* <li>{@link ShellUtils#execCommand(String[], boolean, boolean)}</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author <a href="http://www.trinea.cn" target="_blank">Trinea</a> 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<String> 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<String> 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 <ul>
|
||||
* <li>if isNeedResultMsg is false, {@link CommandResult#successMsg} is null and
|
||||
* {@link CommandResult#errorMsg} is null.</li>
|
||||
* <li>if {@link CommandResult#result} is -1, there maybe some excepiton.</li>
|
||||
* </ul>
|
||||
*/
|
||||
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
|
||||
* <ul>
|
||||
* <li>{@link CommandResult#result} means result of command, 0 means normal, else means error, same to excute in
|
||||
* linux shell</li>
|
||||
* <li>{@link CommandResult#successMsg} means success message of command result</li>
|
||||
* <li>{@link CommandResult#errorMsg} means error message of command result</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author <a href="http://www.trinea.cn" target="_blank">Trinea</a> 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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
package com.xixun.communicate;
|
||||
|
||||
import com.xixun.display.MyLog;
|
||||
import com.xixun.unique.BoardCard;
|
||||
import com.xixun.unique.CardType;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
|
||||
import static android.system.OsConstants.O_RDWR;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2018/05/12.
|
||||
*/
|
||||
|
||||
public class SpiDevice {
|
||||
public static String DeviceName="/dev/spidev0.0";
|
||||
public static int iSpiMaxBaudRate=12*1000*1000;//12000000;//16675000; if iSpiMaxBaudRate != 12Mhz y30 wil have problem;
|
||||
public static int MODE = 1;
|
||||
|
||||
FileDescriptor fileDescriptor=null;
|
||||
String deviceName=DeviceName;
|
||||
int iBaudRate=iSpiMaxBaudRate;
|
||||
int mode=MODE;
|
||||
|
||||
MooncellFpga fatherClass=null;
|
||||
|
||||
public boolean GetReady()
|
||||
{
|
||||
return (fileDescriptor!=null);
|
||||
}
|
||||
|
||||
public SpiDevice(MooncellFpga fatherClass) {
|
||||
this.fatherClass=fatherClass;
|
||||
SpiDeveiceOpen();
|
||||
}
|
||||
|
||||
public SpiDevice(MooncellFpga fatherClass,String deviceName) {
|
||||
this.fatherClass=fatherClass;
|
||||
this.deviceName=deviceName;
|
||||
SpiDeveiceOpen();
|
||||
}
|
||||
|
||||
public SpiDevice(MooncellFpga fatherClass,String deviceName, int iBaudRate) {
|
||||
this.fatherClass=fatherClass;
|
||||
this.deviceName=deviceName;
|
||||
this.iBaudRate=iBaudRate;
|
||||
SpiDeveiceOpen();
|
||||
}
|
||||
|
||||
public SpiDevice(MooncellFpga fatherClass,String deviceName, int iBaudRate,int mode) {
|
||||
this.fatherClass=fatherClass;
|
||||
this.deviceName=deviceName;
|
||||
this.iBaudRate=iBaudRate;
|
||||
this.mode=mode;
|
||||
SpiDeveiceOpen();
|
||||
}
|
||||
|
||||
public void SpiDeveiceOpen() {
|
||||
int bSetBrg=1;
|
||||
if (fatherClass!=null) {
|
||||
if (LedCardCommunication.bTestInNewFpga) iBaudRate=0;
|
||||
if (fatherClass.ledCardCommunication.CardType("Y"))
|
||||
Define.SetFileAuthority(fatherClass.bXixunSuCommand, deviceName);
|
||||
if (fatherClass.ledCardCommunication.CardType("E"))
|
||||
iBaudRate=1000000*6;
|
||||
if (CardType.D == new BoardCard().getCardType() || CardType.D_1 == new BoardCard().getCardType()){
|
||||
deviceName = "/dev/spidev2.0";
|
||||
iBaudRate = 12*1000*1000;
|
||||
mode = 3;
|
||||
}
|
||||
if (CardType.C == new BoardCard().getCardType()){
|
||||
deviceName = "/dev/spidev0.0";
|
||||
iBaudRate = 12*1000*1000;
|
||||
mode = 3;
|
||||
}
|
||||
}
|
||||
fileDescriptor=Open(deviceName,iBaudRate,mode);
|
||||
if( fileDescriptor == null ) {
|
||||
MyLog.i("it is v19.1");
|
||||
deviceName = "/dev/spidev0.0";
|
||||
fileDescriptor = Open("/dev/spidev0.0", 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();
|
||||
}
|
|
@ -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<Worker, PollingWorker> pollingWorkers = new ConcurrentHashMap<Worker, PollingWorker>();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,568 @@
|
|||
package com.xixun.communicate;
|
||||
|
||||
import com.xixun.communicate.Protocol.NET_COMMU_TYPE;
|
||||
import com.xixun.communicate.Protocol.StreamPort;
|
||||
import com.xixun.display.MyLog;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.net.Socket;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 16/11/9.
|
||||
*/
|
||||
|
||||
public class TcpCommunication{
|
||||
private Socket socket=null;
|
||||
private String clientIpAddress=null;
|
||||
ClientManage clientManage=null;
|
||||
public DataInputStream receStream=null;
|
||||
public DataOutputStream sendStream=null;
|
||||
|
||||
public static StreamPort streamPort = null;
|
||||
|
||||
TcpCommunication(ClientManage clientManage,Socket socket)
|
||||
{ this.clientManage=clientManage;
|
||||
this.socket=socket;
|
||||
clientIpAddress=clientManage.GetIpAddress();//socket.getInetAddress().getHostAddress();
|
||||
|
||||
new Thread() {
|
||||
public void run() {
|
||||
Process();
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
private void Process() {
|
||||
try {
|
||||
receStream=new DataInputStream(socket.getInputStream());
|
||||
sendStream=new DataOutputStream(socket.getOutputStream());
|
||||
|
||||
streamPort = new StreamPort(clientIpAddress,true,new IFunctionCallBack() {
|
||||
@Override
|
||||
public void LastSendDataProcess(byte[] DataBuffer, int iLength) {
|
||||
LastTransProcess(DataBuffer,iLength);
|
||||
}
|
||||
@Override
|
||||
public void LastReceDataProcess(byte[] DataBuffer, int iLength) {
|
||||
LastReceProcess();
|
||||
}
|
||||
});
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try{
|
||||
ReceCommand();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
bReady=true;
|
||||
}catch (Exception e) {
|
||||
//if (NeedExit()==false || GetReady())
|
||||
MyLog.i(clientIpAddress+ " "+ 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"
|
||||
);
|
||||
}
|
||||
|
||||
while (NeedExit() == false)
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(ClientsManage.HEART_INTERVAL);
|
||||
TransData_Byte(NET_COMMU_TYPE.TICK.getValue(),(byte)0,(byte)0,null, 0); // 周期发送随意数据,用于检测链路状态,检测链接是否通讯正常。
|
||||
}
|
||||
catch (Exception e)
|
||||
{ //if (NeedExit() == false)
|
||||
MyLog.i(clientIpAddress+ " "+ 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"
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
Tick_Counter(); // iCounter++;
|
||||
if (Tick_TimeOut())
|
||||
{ MyLog.i("---------------------Time Out.");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
MyLog.i(clientIpAddress+ " " + Thread.currentThread().getStackTrace()[2].getFileName() + "-->"
|
||||
+ "Function: " + Thread.currentThread().getStackTrace()[2].getMethodName() + "-->"
|
||||
+ "Line" + Thread.currentThread().getStackTrace()[2].getLineNumber() + ":\r\n"
|
||||
);
|
||||
Stop();
|
||||
}
|
||||
|
||||
|
||||
int iCounter = 0;
|
||||
public void Tick()
|
||||
{
|
||||
iCounter = 0;
|
||||
}
|
||||
|
||||
void Tick_Counter()
|
||||
{
|
||||
iCounter++;
|
||||
// MyLog.i("Tick_Counter = " +iCounter);
|
||||
}
|
||||
|
||||
Boolean Tick_TimeOut()
|
||||
{
|
||||
return (iCounter > 6);
|
||||
}
|
||||
|
||||
public void TransData_Byte(byte ucCommand,byte ucIdence, byte ucPipeId, byte[] DataBuffer, int iLength)
|
||||
{
|
||||
if (NeedExit()) return;
|
||||
|
||||
if (streamPort!=null)
|
||||
streamPort.TransData_Byte(ucCommand,ucIdence, ucPipeId,DataBuffer,iLength);
|
||||
}
|
||||
|
||||
|
||||
private void ReceCommand() {
|
||||
byte[] receDataBuffer=new byte[StreamPort.MAX_PACKET_SIZE+256];
|
||||
|
||||
// MyLog.i("--------------------------fw");
|
||||
|
||||
while (NeedExit()==false) {
|
||||
int iReceLenth=0;
|
||||
if (socket==null) break;
|
||||
if (socket.isConnected()==false) break;
|
||||
|
||||
if (GetReady()==false) break;
|
||||
if (sendStream==null) break;
|
||||
try {
|
||||
iReceLenth=receStream.read(receDataBuffer);
|
||||
// MyLog.i("--------------------------iReceLenth = "+iReceLenth);
|
||||
} catch (Exception e) {
|
||||
//if (NeedExit()==false ||GetReady())
|
||||
MyLog.i(clientIpAddress+ " "+ 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"
|
||||
);
|
||||
break;
|
||||
}
|
||||
//MyLog.i("iReceLenth= "+iReceLenth);
|
||||
for (int i=0;i<iReceLenth;i++ ) {
|
||||
//MyLog.i("i= "+i+ " Data="+receDataBuffer[i]);
|
||||
streamPort.ReceFrame(receDataBuffer[i]);
|
||||
}
|
||||
}
|
||||
MyLog.i(clientIpAddress+ " " + Thread.currentThread().getStackTrace()[2].getFileName() + "-->"
|
||||
+ "Function: " + Thread.currentThread().getStackTrace()[2].getMethodName() + "-->"
|
||||
+ "Line" + Thread.currentThread().getStackTrace()[2].getLineNumber() + ":\r\n"
|
||||
);
|
||||
Stop();
|
||||
}
|
||||
|
||||
void LastTransProcess(byte[] DataBuffer, int iLength) {
|
||||
if (sendStream == null) return;
|
||||
if (socket == null) return;
|
||||
if (socket.isConnected() == false) return;
|
||||
// MyLog.i("LastTransProcess()");
|
||||
try {
|
||||
sendStream.write(DataBuffer, 0, iLength);
|
||||
sendStream.flush();
|
||||
} catch (Exception e) {
|
||||
Stop();
|
||||
{
|
||||
//if (NeedExit() == false)
|
||||
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 LastReceProcess()
|
||||
{
|
||||
if (NeedExit()) return;
|
||||
if (clientManage==null) return;
|
||||
if (clientManage.clientsManage==null) return;
|
||||
if (clientManage.clientsManage.ledCardCommunication==null) return;
|
||||
|
||||
Tick();
|
||||
switch (streamPort.ucCommandType)
|
||||
{
|
||||
case TICK:
|
||||
// Tick();
|
||||
break;
|
||||
case FPGA_MOONCELL:
|
||||
if (clientManage.clientsManage.ledCardCommunication.mooncellFpga==null) break;
|
||||
clientManage.clientsManage.ledCardCommunication.mooncellFpga.Operation(streamPort);
|
||||
break;
|
||||
|
||||
case UART_SENSOR:
|
||||
//if (clientManage.clientsManage.ledCardCommunication.aidlSerialPort_Sensor==null) break;
|
||||
//clientManage.clientsManage.ledCardCommunication.aidlSerialPort_Sensor.// uart_Sensor.
|
||||
// TransData_Byte(streamPort.ReceBuffer,streamPort.iReceLength);
|
||||
break;
|
||||
case UART_FPGA:
|
||||
if (clientManage.clientsManage.ledCardCommunication.mooncellFpga==null) break;
|
||||
|
||||
synchronized (clientManage.clientsManage.ledCardCommunication.mooncellFpga.objFpgaReadOrWrite)
|
||||
{ byte[] DataBuffer = new byte[StreamPort.MAX_PACKET_SIZE + 256];
|
||||
int iOffset=0;
|
||||
int data=0;
|
||||
// VGA 状态寄存器。
|
||||
iOffset=0;
|
||||
|
||||
for (int i =0;i<0x100;i++) DataBuffer[iOffset++]=(byte)0x00;
|
||||
//if (false)
|
||||
clientManage.clientsManage.ledCardCommunication.mooncellFpga.
|
||||
//modified by alahover 20190413 -start
|
||||
//SpiOperator(false,(0x70<<16)+ (0x00<<8) + 0x00,DataBuffer,iOffset);
|
||||
SpiOperator(false,(0x70<<16)+ (0x00<<8) + 0x00,DataBuffer,iOffset,true);
|
||||
//modified by alahover 20190413 -end
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
// 亮度使能。
|
||||
|
||||
iOffset=0;
|
||||
//MyLog.i("-------fw 7");
|
||||
for (int i =0;i<0x04;i++) DataBuffer[iOffset++]=(byte)0xA5;
|
||||
//if (false)
|
||||
clientManage.clientsManage.ledCardCommunication.mooncellFpga.
|
||||
//modified by alahover 20190413 -start
|
||||
//SpiOperator(true,(0xA7<<16)+ (0x20<<8) + 0x0E*4,DataBuffer,iOffset);
|
||||
|
||||
SpiOperator(true,(0xA7<<16)+ (0x20<<8) + 0x0E*4,DataBuffer,iOffset,false);
|
||||
//modified by alahover 20190413 -end
|
||||
//if (false)
|
||||
while (data<0x70000000)
|
||||
{
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
// 亮度调节。
|
||||
iOffset=0;
|
||||
int iValue = data << 20 | data << 10 | data;
|
||||
DataBuffer[iOffset++] = (byte) (iValue >> 24);
|
||||
DataBuffer[iOffset++] = (byte) (iValue >> 16);
|
||||
DataBuffer[iOffset++] = (byte) (iValue >> 8);
|
||||
DataBuffer[iOffset++] = (byte) (iValue >> 0);
|
||||
|
||||
clientManage.clientsManage.ledCardCommunication.mooncellFpga.
|
||||
//modified by alahover 20190413 -start
|
||||
// SpiOperator(true,(0xA7<<16)+ (0x20<<8) + 0x0D*4,DataBuffer,iOffset);
|
||||
|
||||
SpiOperator(true,(0xA7<<16)+ (0x20<<8) + 0x0D*4,DataBuffer,iOffset,false);
|
||||
//modified by alahover 20190413 -end
|
||||
// MyLog.i("-------fw 8");
|
||||
|
||||
data += 0x10;
|
||||
if (data>=0x400) data=0;
|
||||
MyLog.i("data= "+data);
|
||||
}
|
||||
|
||||
/*
|
||||
iOffset=0;
|
||||
|
||||
DataBuffer[iOffset++] = (byte) 0x7E;
|
||||
DataBuffer[iOffset++] = (byte) 0x7E;
|
||||
DataBuffer[iOffset++] = (byte) 0x55;
|
||||
DataBuffer[iOffset++] = (byte) 0x7C;
|
||||
|
||||
DataBuffer[iOffset++] = (byte) 0x00;
|
||||
DataBuffer[iOffset++] = (byte) 0x00;
|
||||
DataBuffer[iOffset++] = (byte) 0x00;
|
||||
DataBuffer[iOffset++] = (byte) 0x00;
|
||||
|
||||
DataBuffer[iOffset++] = (byte) 8+2;
|
||||
DataBuffer[iOffset++] = (byte) 0x00+1;
|
||||
DataBuffer[iOffset++] = (byte) 0x00;
|
||||
DataBuffer[iOffset++] = (byte) 0x00;
|
||||
|
||||
DataBuffer[iOffset++] = (byte) 0x00;
|
||||
DataBuffer[iOffset++] = (byte) 0x00;
|
||||
|
||||
DataBuffer[iOffset++]=(byte)0xAA;
|
||||
DataBuffer[iOffset++]=(byte)0x70;
|
||||
DataBuffer[iOffset++]=(byte)0x00;
|
||||
DataBuffer[iOffset++]=(byte)0x00;
|
||||
DataBuffer[iOffset++]=(byte)0x01;
|
||||
DataBuffer[iOffset++]=(byte)0x00;
|
||||
DataBuffer[iOffset++]=(byte)0x00;
|
||||
DataBuffer[iOffset++]=(byte)0x00;
|
||||
|
||||
for (int i =0;i<0x100;i++) DataBuffer[iOffset++]=(byte)0x00;
|
||||
|
||||
DataBuffer[iOffset] = (byte) GetCheckCodeIn8(DataBuffer,3, iOffset); // 校验码。
|
||||
iOffset++;
|
||||
|
||||
if (false)
|
||||
{}//clientManage.clientsManage.ledCardCommunication.mooncellFpga.
|
||||
// TransData_Byte((byte)0,DataBuffer,iOffset);
|
||||
|
||||
*/
|
||||
/*
|
||||
|
||||
DataBuffer[iOffset++] = (byte) 0x7E;
|
||||
DataBuffer[iOffset++] = (byte) 0x7E;
|
||||
DataBuffer[iOffset++] = (byte) 0x55;
|
||||
DataBuffer[iOffset++] = (byte) 0x7C;
|
||||
|
||||
DataBuffer[iOffset++] = (byte) 0x00;
|
||||
DataBuffer[iOffset++] = (byte) 0x00;
|
||||
DataBuffer[iOffset++] = (byte) 0x00;
|
||||
DataBuffer[iOffset++] = (byte) 0x00;
|
||||
|
||||
DataBuffer[iOffset++] = (byte) 12+2;
|
||||
DataBuffer[iOffset++] = (byte) 0x00;
|
||||
DataBuffer[iOffset++] = (byte) 0x00;
|
||||
DataBuffer[iOffset++] = (byte) 0x00;
|
||||
|
||||
DataBuffer[iOffset++] = (byte) 0x00;
|
||||
DataBuffer[iOffset++] = (byte) 0x00;
|
||||
|
||||
|
||||
DataBuffer[iOffset++]=(byte)0xE5;
|
||||
|
||||
DataBuffer[iOffset++]=(byte)0xA7;
|
||||
DataBuffer[iOffset++]=(byte)0x20;
|
||||
DataBuffer[iOffset++]=(byte)0x0E *4;
|
||||
|
||||
DataBuffer[iOffset++]=(byte)0x00;
|
||||
DataBuffer[iOffset++]=(byte)0x04;
|
||||
|
||||
DataBuffer[iOffset++]=(byte)0x00;
|
||||
DataBuffer[iOffset++]=(byte)0x00;
|
||||
|
||||
for (int i =0;i<0x04;i++) DataBuffer[iOffset++]=(byte)0xA5;
|
||||
|
||||
|
||||
|
||||
DataBuffer[iOffset] = (byte) GetCheckCodeIn8(DataBuffer,3, iOffset); // 校验码。
|
||||
iOffset++;
|
||||
|
||||
//if (false)
|
||||
clientManage.clientsManage.ledCardCommunication.mooncellFpga.
|
||||
TransData_Byte((byte)0,DataBuffer,iOffset);
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
// 回读亮度调节。
|
||||
iOffset=0;
|
||||
DataBuffer[iOffset++]=(byte)0xAA;
|
||||
|
||||
DataBuffer[iOffset++]=(byte)0xA7;
|
||||
DataBuffer[iOffset++]=(byte)0x20;
|
||||
DataBuffer[iOffset++]=(byte)0x0D*4;
|
||||
|
||||
DataBuffer[iOffset++]=(byte)0x00;
|
||||
DataBuffer[iOffset++]=(byte)0x08;
|
||||
|
||||
DataBuffer[iOffset++]=(byte)0x00;
|
||||
DataBuffer[iOffset++]=(byte)0x00;
|
||||
for (int i =0;i<0x08;i++) DataBuffer[iOffset++]=0;
|
||||
/*
|
||||
DataBuffer[iOffset++] = (byte) 0x7E;
|
||||
DataBuffer[iOffset++] = (byte) 0x7E;
|
||||
DataBuffer[iOffset++] = (byte) 0x55;
|
||||
DataBuffer[iOffset++] = (byte) 0x7C;
|
||||
|
||||
DataBuffer[iOffset++] = (byte) 0x00;
|
||||
DataBuffer[iOffset++] = (byte) 0x00;
|
||||
DataBuffer[iOffset++] = (byte) 0x00;
|
||||
DataBuffer[iOffset++] = (byte) 0x00;
|
||||
|
||||
DataBuffer[iOffset++] = (byte) 12+2;
|
||||
DataBuffer[iOffset++] = (byte) 0x00;
|
||||
DataBuffer[iOffset++] = (byte) 0x00;
|
||||
DataBuffer[iOffset++] = (byte) 0x00;
|
||||
|
||||
DataBuffer[iOffset++] = (byte) 0x00;
|
||||
DataBuffer[iOffset++] = (byte) 0x00;
|
||||
|
||||
|
||||
|
||||
|
||||
DataBuffer[iOffset++] = (byte) 0xE5;
|
||||
|
||||
DataBuffer[iOffset++] = (byte) 0xA7;
|
||||
DataBuffer[iOffset++] = (byte) 0x20;
|
||||
DataBuffer[iOffset++] = (byte) 0x0D * 4;
|
||||
|
||||
DataBuffer[iOffset++] = (byte) 0x00;
|
||||
DataBuffer[iOffset++] = (byte) 0x04;
|
||||
|
||||
DataBuffer[iOffset++] = (byte) 0x00;
|
||||
DataBuffer[iOffset++] = (byte) 0x00;
|
||||
|
||||
|
||||
int iValue = data << 20 | data << 10 | data;
|
||||
MyLog.i("Received Command3 iValue: " + iValue);
|
||||
DataBuffer[iOffset++] = (byte) (iValue >> 24);
|
||||
DataBuffer[iOffset++] = (byte) (iValue >> 16);
|
||||
DataBuffer[iOffset++] = (byte) (iValue >> 8);
|
||||
DataBuffer[iOffset++] = (byte) (iValue >> 0);
|
||||
|
||||
DataBuffer[iOffset] = (byte) GetCheckCodeIn8(DataBuffer,3, iOffset); // 校验码。
|
||||
|
||||
//MyLog.i("iOffset= "+iOffset);
|
||||
//MyLog.i("DataBuffer[iOffset]= "+DataBuffer[iOffset]);
|
||||
|
||||
iOffset++;
|
||||
|
||||
|
||||
|
||||
|
||||
MyLog.i("data= "+data);
|
||||
//if (false)
|
||||
clientManage.clientsManage.ledCardCommunication.mooncellFpga.
|
||||
TransData_Byte((byte) 0, DataBuffer, iOffset);
|
||||
|
||||
if (false)
|
||||
clientManage.clientsManage.ledCardCommunication.mooncellFpga.
|
||||
TransData_Byte((byte)0,DataBuffer,iOffset);
|
||||
// 写。
|
||||
iOffset=0;
|
||||
DataBuffer[iOffset++]=(byte)0xE5;
|
||||
|
||||
DataBuffer[iOffset++]=(byte)0xA7;
|
||||
DataBuffer[iOffset++]=(byte)0x20;
|
||||
DataBuffer[iOffset++]=(byte)0x00;
|
||||
|
||||
DataBuffer[iOffset++]=(byte)0x00;
|
||||
DataBuffer[iOffset++]=(byte)0x08;
|
||||
|
||||
DataBuffer[iOffset++]=(byte)0x00;
|
||||
DataBuffer[iOffset++]=(byte)0x00;
|
||||
for (int i =0;i<0x08;i++) DataBuffer[iOffset++]=(byte) i;
|
||||
clientManage.clientsManage.ledCardCommunication.mooncellFpga.
|
||||
TransData_Byte((byte)0,DataBuffer,iOffset);
|
||||
// 回读。
|
||||
iOffset=0;
|
||||
DataBuffer[iOffset++]=(byte)0xAA;
|
||||
|
||||
DataBuffer[iOffset++]=(byte)0xA7;
|
||||
DataBuffer[iOffset++]=(byte)0x20;
|
||||
DataBuffer[iOffset++]=(byte)0x00;
|
||||
|
||||
DataBuffer[iOffset++]=(byte)0x00;
|
||||
DataBuffer[iOffset++]=(byte)0x08;
|
||||
|
||||
DataBuffer[iOffset++]=(byte)0x00;
|
||||
DataBuffer[iOffset++]=(byte)0x00;
|
||||
for (int i =0;i<0x08;i++) DataBuffer[iOffset++]=0;
|
||||
clientManage.clientsManage.ledCardCommunication.mooncellFpga.
|
||||
TransData_Byte((byte)0,DataBuffer,iOffset);
|
||||
*/
|
||||
}
|
||||
|
||||
break;
|
||||
case UART_EXTENSION:
|
||||
if (clientManage.clientsManage.ledCardCommunication.aidlSerialPort_Extention==null) break;
|
||||
|
||||
MyLog.i("Received Command: " + streamPort.ucCommandType);
|
||||
|
||||
{ byte[] DataBuffer = new byte[StreamPort.MAX_PACKET_SIZE + 256];
|
||||
int iOffset=0;
|
||||
|
||||
iOffset=0;
|
||||
DataBuffer[iOffset++] = (byte) 0x7E;
|
||||
DataBuffer[iOffset++] = (byte) 0x7E;
|
||||
DataBuffer[iOffset++] = (byte) 0x55;
|
||||
DataBuffer[iOffset++] = (byte) 0x71;
|
||||
|
||||
Define.SetIntToByte(0, DataBuffer, iOffset);
|
||||
iOffset +=4;
|
||||
|
||||
Define.SetIntToByte(streamPort.iReceLength+1+13, DataBuffer, iOffset);
|
||||
iOffset +=4;
|
||||
|
||||
DataBuffer[iOffset++] = (byte) 1;
|
||||
|
||||
{ DataBuffer[iOffset++] = (byte) 0x7E;
|
||||
DataBuffer[iOffset++] = (byte) 0x7E;
|
||||
DataBuffer[iOffset++] = (byte) 0x55;
|
||||
int iOffsetStart=iOffset;
|
||||
DataBuffer[iOffset++] = (byte) 0x31;
|
||||
Define.SetIntToByte(0, DataBuffer, iOffset);
|
||||
iOffset +=4;
|
||||
|
||||
Define.SetIntToByte(streamPort.iReceLength, DataBuffer, iOffset);
|
||||
iOffset +=4;
|
||||
|
||||
if (streamPort.ReceBuffer!=null && streamPort.iReceLength>0) {
|
||||
System.arraycopy(streamPort.ReceBuffer, 0, DataBuffer, iOffset, streamPort.iReceLength); // 正文内容。
|
||||
iOffset += streamPort.iReceLength;
|
||||
}
|
||||
DataBuffer[iOffset] = Define.GetCheckCodeIn8(DataBuffer, iOffsetStart, iOffset); // 校验码,累加和取反。
|
||||
iOffset++;
|
||||
}
|
||||
|
||||
DataBuffer[iOffset] = Define.GetCheckCodeIn8(DataBuffer, 3, iOffset); // 校验码,累加和取反。
|
||||
iOffset++;
|
||||
|
||||
clientManage.clientsManage.ledCardCommunication.aidlSerialPort_Extention.
|
||||
TransData_Byte(DataBuffer,iOffset);
|
||||
|
||||
MyLog.i("Send Length= "+iOffset + "; streamPort.iReceLength="+ streamPort.iReceLength);
|
||||
}
|
||||
//clientManage.clientsManage.ledCardCommunication.aidlSerialPort_Extention.// uart_Extension.
|
||||
// TransData_Byte(streamPort.ReceBuffer,streamPort.iReceLength);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
//if (false)
|
||||
try {
|
||||
bReady=false;
|
||||
|
||||
if (NeedExit()==false) // 非外部请求造成的退出,需要注销当前显示屏。
|
||||
clientManage.Request_Exit();
|
||||
|
||||
if (receStream!=null) receStream.close();
|
||||
receStream=null;
|
||||
if (sendStream!=null) sendStream.close();
|
||||
sendStream=null;
|
||||
if (socket!=null) socket.close();
|
||||
socket=null;
|
||||
|
||||
clientManage=null;
|
||||
} catch (Exception e) {}
|
||||
//if (NeedExit()==false)
|
||||
MyLog.i(clientIpAddress+ " "+ Thread.currentThread().getStackTrace()[2].getFileName() + "-->"
|
||||
+ "Function: " +Thread.currentThread().getStackTrace()[2].getMethodName()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
String strDisplayID=null;
|
||||
public String GetDisplayID() { return strDisplayID;}
|
||||
|
||||
boolean bReady=false;
|
||||
public boolean GetReady() { return bReady; }
|
||||
|
||||
boolean bNeedExit=false;
|
||||
boolean NeedExit() { return bNeedExit; }
|
||||
|
||||
public void Exit()
|
||||
{ if (bNeedExit) return;
|
||||
bNeedExit=true;
|
||||
Stop();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,158 @@
|
|||
package com.xixun.communicate;
|
||||
|
||||
import com.xixun.communicate.Protocol.NET_COMMU_TYPE;
|
||||
import com.xixun.display.MyLog;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2018/01/22.
|
||||
*
|
||||
*
|
||||
Y卡:
|
||||
fpga: /dev/s3c2410_serial2
|
||||
sensor: /dev/s3c2410_serial1
|
||||
GPS/RF: /dev/s3c2410_serial3
|
||||
----------------------------------------------
|
||||
E卡:
|
||||
/dev/ttyMT1
|
||||
|
||||
*/
|
||||
|
||||
public class Uart {
|
||||
LedCardCommunication ledCardCommunication=null;
|
||||
|
||||
SerialPort serialPort=null;
|
||||
FileOutputStream mOutputStream=null;
|
||||
FileInputStream mInputStream=null;
|
||||
|
||||
String strUartDeviceName=null;
|
||||
int iBaudRate=0;
|
||||
byte ucCommandType= NET_COMMU_TYPE.NONE.getValue();
|
||||
|
||||
public Uart(LedCardCommunication ledCardCommunication,String strUartDeviceName,int iBaudRate)
|
||||
{
|
||||
this.ledCardCommunication=ledCardCommunication;
|
||||
this.strUartDeviceName=strUartDeviceName;
|
||||
this.iBaudRate=iBaudRate;
|
||||
|
||||
|
||||
if (strUartDeviceName==LedCardCommunication.serialDeviceName_Sensor) ucCommandType=NET_COMMU_TYPE.UART_SENSOR.getValue();
|
||||
if (strUartDeviceName==LedCardCommunication.serialDeviceName_Fpga) ucCommandType=NET_COMMU_TYPE.UART_FPGA.getValue();
|
||||
if (strUartDeviceName==LedCardCommunication.serialDeviceName_Extention) ucCommandType=NET_COMMU_TYPE.UART_EXTENSION.getValue();
|
||||
|
||||
//android_serialport_api.SerialPortFinder serialPortFinder=new android_serialport_api.SerialPortFinder();
|
||||
//serialPortFinder.getAllDevices();
|
||||
new Thread() {
|
||||
public void run() {
|
||||
Process();
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
|
||||
void Process()
|
||||
{
|
||||
try {
|
||||
serialPort=new SerialPort(new File(strUartDeviceName),iBaudRate,0);//"/dev/ttySAC0" // "/dev/ttyMT3" // "/dev/s3c2410_serial3"
|
||||
if (serialPort==null)
|
||||
{ Stop();
|
||||
return;
|
||||
}
|
||||
|
||||
mOutputStream=(FileOutputStream) serialPort.getOutputStream();
|
||||
mInputStream=(FileInputStream) serialPort.getInputStream();
|
||||
|
||||
bReady=true;
|
||||
|
||||
} catch (SecurityException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
int iLength=0;
|
||||
byte[] DataBuffer =new byte[1024*8];
|
||||
|
||||
while (NeedExit()==false) {
|
||||
if (mInputStream==null) break;
|
||||
|
||||
try {
|
||||
iLength=mInputStream.read(DataBuffer);
|
||||
if (iLength==0) continue;
|
||||
if (iLength<0)
|
||||
{
|
||||
Stop();
|
||||
break;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
ReceDataProcess(DataBuffer,iLength);
|
||||
|
||||
try {
|
||||
Thread.sleep(1);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
Stop();
|
||||
}
|
||||
|
||||
void ReceDataProcess(byte[] DataBuffer,int iLength)
|
||||
{
|
||||
ledCardCommunication.clientsManage.TransData_Byte(null,ucCommandType,(byte)0,(byte)0,DataBuffer,iLength);
|
||||
MyLog.i("Rece DataBuffer: "+DataBuffer[0]);
|
||||
}
|
||||
|
||||
public void TransData_Byte(byte ucCommand, byte ucIdence, byte ucPipeId,byte[] DataBuffer, int iLength)
|
||||
{ if (NeedExit()) return;
|
||||
if (GetReady()==false) return;
|
||||
|
||||
try {
|
||||
mOutputStream.write(DataBuffer,0,iLength);
|
||||
mOutputStream.flush();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
try {
|
||||
bReady=false;
|
||||
|
||||
if (mInputStream!=null) mInputStream.close();
|
||||
if (mOutputStream!=null) mOutputStream.close();
|
||||
if (serialPort!=null) serialPort.close();
|
||||
|
||||
} catch (Exception e) {}
|
||||
if (NeedExit()==false)
|
||||
MyLog.i(strUartDeviceName+ " "+ Thread.currentThread().getStackTrace()[2].getFileName() + "-->"
|
||||
+ "Function: " +Thread.currentThread().getStackTrace()[2].getMethodName()
|
||||
);
|
||||
}
|
||||
|
||||
boolean bReady=false;
|
||||
public boolean GetReady() { return bReady; }
|
||||
|
||||
Boolean bNeedExit=false;
|
||||
boolean NeedExit() { return bNeedExit; }
|
||||
|
||||
public void Exit()
|
||||
{ if (bNeedExit) return;
|
||||
bNeedExit=true;
|
||||
|
||||
Stop();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,114 @@
|
|||
package com.xixun.communicate;
|
||||
|
||||
import com.xixun.display.MyLog;
|
||||
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetAddress;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2018/05/21.
|
||||
*/
|
||||
|
||||
public class UdpRece {
|
||||
|
||||
static final int BUFFER_SIZE = 1024;
|
||||
int iHostPort=0;
|
||||
|
||||
UdpRece(int iHostPort)
|
||||
{ this.iHostPort=iHostPort;
|
||||
|
||||
new Thread() {
|
||||
public void run() {
|
||||
Process();
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
private void Process()
|
||||
{
|
||||
while (NeedExit()==false) {
|
||||
try {
|
||||
byte[] receDataBufferSize = new byte[BUFFER_SIZE];
|
||||
DatagramSocket udpReceSocket = new DatagramSocket(iHostPort);
|
||||
DatagramPacket recePacket = new DatagramPacket(receDataBufferSize, receDataBufferSize.length);
|
||||
|
||||
while (NeedExit()==false)
|
||||
{ udpReceSocket.receive(recePacket);
|
||||
ReceDataProcess(recePacket);
|
||||
}
|
||||
|
||||
udpReceSocket.close();
|
||||
}catch (Exception e) {
|
||||
if (NeedExit()==false)
|
||||
MyLog.i(Thread.currentThread().getStackTrace()[2].getFileName() + "-->"
|
||||
+ this.getClass() + "-->"
|
||||
+ "Function: " +Thread.currentThread().getStackTrace()[2].getMethodName() + "-->"
|
||||
+ "Line" +Thread.currentThread().getStackTrace()[2].getLineNumber() + ":\r\n"
|
||||
+ " Error:" + e.getMessage() + "\r\n\r\n"
|
||||
);
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void ReceDataProcess(DatagramPacket recePacket)
|
||||
{ // 通过数据报得到发送方的IP.
|
||||
InetAddress inetAddress_HostIP=recePacket.getAddress();
|
||||
String hostIP=inetAddress_HostIP.getHostAddress();
|
||||
//MyLog.i("==================================================== rIP:" + hostIP);
|
||||
if (ReceCommand(new String(recePacket.getData(),0,recePacket.getLength()))<0) return;
|
||||
}
|
||||
|
||||
public int ReceCommand(String receDataBuffer)
|
||||
{ int i=0,iWorkResault=0,iOffset=0,iReceLenth=receDataBuffer.length();
|
||||
|
||||
if (iReceLenth<=0) return -1;
|
||||
|
||||
while(iOffset<iReceLenth)
|
||||
{
|
||||
String receToatlCommand=receDataBuffer.substring(iOffset);
|
||||
|
||||
MyLog.i("-------------receToatlCommand:" + receToatlCommand);
|
||||
int iCommandSize=receToatlCommand.indexOf(';'); // 发送方有可能没有发送时间信息,也就没有分号。
|
||||
|
||||
if (iCommandSize>0) iOffset++;
|
||||
else iCommandSize = iReceLenth - iOffset; // 无命令结束符,只有一条命令,或最后一条命令。
|
||||
iOffset+=iCommandSize;
|
||||
|
||||
{ String receSubCommand = receToatlCommand.substring(0, iCommandSize);
|
||||
|
||||
int iCommandParamsStart=receSubCommand.indexOf('=');
|
||||
String strValue=receSubCommand.substring(iCommandParamsStart + 1);
|
||||
//MyLog.i("strValue:" + strValue);
|
||||
//long lValue=Long.parseLong(strValue);
|
||||
//if (iValue<0) return -1;
|
||||
//MyLog.i("lValue:" + lValue);
|
||||
|
||||
|
||||
|
||||
if (receSubCommand.indexOf("Time")==0)
|
||||
{ Define.SetTime(strValue);
|
||||
}
|
||||
else
|
||||
if (receSubCommand.indexOf("Light")==0)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
//MyLog.i("---------------------------------------Rece:" + receDataBuffer);
|
||||
return iWorkResault;
|
||||
}
|
||||
|
||||
boolean bNeedExit=false;
|
||||
public Boolean NeedExit() { return bNeedExit; }
|
||||
public void Exit()
|
||||
{ if (NeedExit()) return;
|
||||
bNeedExit=true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
package com.xixun.communicate;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.xixun.display.MyLog;
|
||||
import com.xixun.display.MyService;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class WorkParams {
|
||||
public int iLightValue=LedCardCommunication.LIGHT_START_VALUE;
|
||||
|
||||
public int iDirection=1;
|
||||
public int iCarriageNumber=0;
|
||||
public String strStationNumber="G1234";
|
||||
|
||||
|
||||
public String strProgramStart="strProgramStart";
|
||||
private Configurations configurations=null;
|
||||
|
||||
MyService ms=null;
|
||||
|
||||
public WorkParams(MyService service, Context ctx){
|
||||
ms = service;
|
||||
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 (ms.bDisplay_RailWay) {
|
||||
configurations.setIntValue("iDirection", iDirection);
|
||||
configurations.setIntValue("iCarriageNumber", iCarriageNumber);
|
||||
configurations.setValue("strStationNumber", strStationNumber);
|
||||
}
|
||||
}
|
||||
|
||||
public void pullBaseParams(){
|
||||
iLightValue = configurations.getIntValue("iLightValue");
|
||||
|
||||
if (ms.bDisplay_RailWay) {
|
||||
iDirection = configurations.getIntValue("iDirection");
|
||||
iCarriageNumber = configurations.getIntValue("iCarriageNumber");
|
||||
strStationNumber = configurations.getValue("strStationNumber");
|
||||
}
|
||||
}
|
||||
|
||||
public void Backup(String strDirectPath)
|
||||
{
|
||||
String strSoureceFile=ms.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 =ms.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
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.xixun.communicate;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2018/04/22.
|
||||
*/
|
||||
|
||||
public class giginfo {
|
||||
// 负偏移
|
||||
public int negative_x =0;
|
||||
public int negative_y =0 ;
|
||||
// 主辅
|
||||
public char imgsel=0; // 0 表示主 1表示辅
|
||||
// 网口发送图像位置
|
||||
public int img_x=0;
|
||||
public int img_y=0;
|
||||
public int img_w=1280;
|
||||
public int img_h=512;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.xixun.display;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
public class AIDLService extends Service {
|
||||
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
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("自启动程序即将执行");
|
||||
// MyLog.sleepForSecond(5);
|
||||
Intent mBootIntent = new Intent(context, MainActivity.class);
|
||||
//下面这句话必须加上才能开机自动运行app的界面
|
||||
mBootIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(mBootIntent);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
package com.xixun.display;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.ServiceConnection;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.Message;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.util.Log;
|
||||
|
||||
import com.xixun.communicate.ClientsManage;
|
||||
import com.xixun.communicate.Define;
|
||||
import com.xixun.communicate.LedCardCommunication;
|
||||
import com.xixun.communicate.WorkParams;
|
||||
import com.xixun.joey.uart.IUartService;
|
||||
import com.xixun.util.PlayerInfo;
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import static java.lang.Thread.sleep;
|
||||
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
|
||||
public class MainActivity extends Activity{
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
//动态申请权限
|
||||
verifyStoragePermissions(this);
|
||||
Log.i("_yzd", "start display activity");
|
||||
Intent autoRun = new Intent(this, MyService.class);
|
||||
startService(autoRun);
|
||||
finish();
|
||||
Log.i("_yzd", "finish display activity");
|
||||
|
||||
/*Intent aidl = new Intent(this, AIDLService.class);
|
||||
startService(aidl);
|
||||
finish();*/
|
||||
}
|
||||
// Storage Permissions
|
||||
private static final int REQUEST_EXTERNAL_STORAGE = 1;
|
||||
private static String[] PERMISSIONS_STORAGE = {Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.WRITE_EXTERNAL_STORAGE };
|
||||
|
||||
/**
|
||||
* 动态申请权限
|
||||
* @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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package com.xixun.display;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import com.amused.joey.crash.AppCrashInfo;
|
||||
import com.amused.joey.crash.CrashHelper;
|
||||
import com.amused.joey.crash.OnCrashListener;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public class MyApp extends Application {
|
||||
/*@Override
|
||||
public void onCreate() {
|
||||
new CrashHelper.Builder(this)
|
||||
.setLogFilePrefix("display")
|
||||
.setOnCrashListener(new OnCrashListener() {
|
||||
@Override
|
||||
public void onCrash(File crashLog, List<AppCrashInfo> crashData, StringBuilder crashInfo) {
|
||||
if (null != crashLog) {
|
||||
System.out.println("=-======================================================================== null" + crashLog.getAbsolutePath());
|
||||
} else {
|
||||
System.out.println("=-=========================== null");
|
||||
}
|
||||
}
|
||||
})
|
||||
.build();
|
||||
|
||||
|
||||
}*/
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.xixun.display;
|
||||
|
||||
import android.database.ContentObserver;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
|
||||
public class MyContentObserver extends ContentObserver {
|
||||
Handler mHandler;
|
||||
public MyContentObserver(Handler handler) {
|
||||
super(handler);
|
||||
mHandler = handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(boolean selfChange) {
|
||||
super.onChange(selfChange);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(boolean selfChange, Uri uri) {
|
||||
super.onChange(selfChange, uri);
|
||||
Message message = Message.obtain();
|
||||
message.obj = uri;
|
||||
mHandler.sendMessage(message);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
package com.xixun.display;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.util.Log;
|
||||
|
||||
import com.xixun.lay.safe.Safe;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
public static void i(String msg) {
|
||||
Log.i(TAG, formatStr(msg));
|
||||
}
|
||||
|
||||
public static void d(String msg) {
|
||||
Log.d(TAG, formatStr(msg));
|
||||
}
|
||||
|
||||
public static void e(String msg) {
|
||||
Log.e(TAG, formatStr(msg));
|
||||
}
|
||||
|
||||
public static void v(String msg) {
|
||||
Log.v(TAG, formatStr(msg));
|
||||
}
|
||||
|
||||
public static void w(String msg) {
|
||||
Log.w(TAG, formatStr(msg));
|
||||
}
|
||||
|
||||
@SuppressLint("DefaultLocale")
|
||||
public static void showBytes(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());
|
||||
// MyApp.writeLog(show.toString(), false);
|
||||
}
|
||||
|
||||
public static void debugLine() {
|
||||
debugLine(null);
|
||||
}
|
||||
|
||||
public static void debugLine(String msg) {
|
||||
StackTraceElement stack = Thread.currentThread().getStackTrace()[(null == msg)? 4: 3];
|
||||
Log.d(TAG, stack.getClassName()
|
||||
+ " -> " + 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();
|
||||
}
|
||||
}*/
|
||||
}
|
|
@ -0,0 +1,560 @@
|
|||
package com.xixun.display;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.ServiceConnection;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.Message;
|
||||
import android.os.RemoteException;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import com.xixun.communicate.ClientsManage;
|
||||
import com.xixun.communicate.Define;
|
||||
import com.xixun.communicate.LedCardCommunication;
|
||||
import com.xixun.communicate.MooncellFpga;
|
||||
import com.xixun.communicate.TcpCommunication;
|
||||
import com.xixun.communicate.WorkParams;
|
||||
import com.xixun.joey.uart.IUartService;
|
||||
import com.xixun.util.PlayerInfo;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static java.lang.Thread.sleep;
|
||||
|
||||
public class MyService extends Service {
|
||||
public static boolean bDisplay_RailWay=false;
|
||||
static int brightness;
|
||||
static boolean manual;
|
||||
|
||||
public PlayerInfo playerInfo=null;
|
||||
public boolean bUseSerialPort=false;
|
||||
ClientsManage clientsManage=null;
|
||||
public LedCardCommunication ledCardCommunication = null;
|
||||
public WorkParams workParams=null;
|
||||
public String strStoragePath=null;
|
||||
BreakpointReceiver fw_receiver;
|
||||
BroadcastReceiver receiver_brightness;
|
||||
public Handler handlerRefreshDisplay=null;
|
||||
Boolean bNeedExit=false;
|
||||
public IUartService serialPorts=null;
|
||||
private boolean isBound_IUartService = false; // add byfw 2019/1/30
|
||||
private boolean isBound_PlayerInfo = false; // add byfw 2019/1/30
|
||||
|
||||
public MyService() {
|
||||
}
|
||||
/*@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
// TODO: Return the communication channel to the service.
|
||||
throw new UnsupportedOperationException("Not yet implemented");
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent)
|
||||
{
|
||||
return new MyBinder();
|
||||
}
|
||||
|
||||
class MyBinder extends MyAidl.Stub
|
||||
{
|
||||
/*
|
||||
设置屏幕亮度
|
||||
*/
|
||||
@Override
|
||||
public boolean setBrightness(boolean manual, int brightness) throws RemoteException
|
||||
{
|
||||
MyLog.i("setBrightness............"+brightness);
|
||||
if (ledCardCommunication == null){
|
||||
ledCardCommunication = clientsManage.ledCardCommunication;
|
||||
}
|
||||
|
||||
//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= ledCardCommunication.LightPro(manual,brightness);
|
||||
int count = 0;
|
||||
if (!result){
|
||||
while (true){
|
||||
count++;
|
||||
MyLog.i("ledCardCommunication.LightPro..........."+brightness);
|
||||
result = ledCardCommunication.LightPro(manual,brightness);
|
||||
MyLog.sleepForMillisecond(1000);
|
||||
if (result){
|
||||
count = 0;
|
||||
break;
|
||||
}
|
||||
if (count>20){
|
||||
//退出本程序
|
||||
MyLog.i("exit display.....");
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
获取屏幕亮度
|
||||
*/
|
||||
@Override
|
||||
public int getBrightness() throws RemoteException {
|
||||
if (ledCardCommunication == null){
|
||||
ledCardCommunication = clientsManage.ledCardCommunication;
|
||||
}
|
||||
int result = ledCardCommunication.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 {
|
||||
MooncellFpga mooncellFpga = clientsManage.ledCardCommunication.mooncellFpga;
|
||||
int port1 = mooncellFpga.ReceivedCard_GetNumber(0,0xF);//接收卡数量
|
||||
int port2 = mooncellFpga.ReceivedCard_GetNumber(1,0xF);//接收卡数量
|
||||
MyLog.i("port1=="+port1+";port2="+port2);
|
||||
return port1+port2;
|
||||
}
|
||||
|
||||
/*
|
||||
获取3288系列卡fpga版本
|
||||
*/
|
||||
@Override
|
||||
public int getVersionBy3288() throws RemoteException {
|
||||
if (ledCardCommunication == null){
|
||||
ledCardCommunication = clientsManage.ledCardCommunication;
|
||||
}
|
||||
MooncellFpga mooncellFpga = clientsManage.ledCardCommunication.mooncellFpga;
|
||||
int fpgaVersion = mooncellFpga.getFpgaVersion();
|
||||
// MyLog.i("fpgaVersion:"+fpgaVersion);
|
||||
return fpgaVersion;
|
||||
}
|
||||
|
||||
//设置偏移
|
||||
@Override
|
||||
public int setOffset(int screenX, int screenY,int cutW,int cutH, int so1X, int so1Y, int so2X, int so2Y) throws RemoteException {
|
||||
return clientsManage.ledCardCommunication.mooncellFpga.setOffset(screenX,screenY,cutW,cutH,so1X,so1Y,so2X,so2Y);
|
||||
}
|
||||
}
|
||||
|
||||
public int readFpgaInfo() {
|
||||
MyLog.i("registerFpgaInfoBroadcast.......");
|
||||
byte[] fpgacmd = {0x7E,0x7E,0x55,0x7C,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00, (byte) 0xE6,0x0C,0x00,0x00, (byte) 0x8D};
|
||||
byte[] newFpgacmd = new byte[65];
|
||||
byte[] fpgatemp = null;
|
||||
System.arraycopy(fpgacmd, 0, newFpgacmd, 0, fpgacmd.length);
|
||||
// Define.showBytes("fpgacmd",newFpgacmd,0);
|
||||
//请求fpga
|
||||
int res = clientsManage.ledCardCommunication.mooncellFpga.spiDevice.Operator(newFpgacmd,newFpgacmd.length);
|
||||
fpgacmd = new byte[49];
|
||||
System.arraycopy(newFpgacmd, 17, fpgacmd, 0, fpgacmd.length-1);
|
||||
// Define.showBytes("fpgacmdback",fpgacmd,0);
|
||||
if (res > 0 && fpgacmd != null){
|
||||
// MyLog.showBytes("fpgacmd",fpgacmd,0);
|
||||
/*if (!Arrays.equals(fpgacmd,fpgatemp)){//如果数据相同就不需要发送
|
||||
fpgatemp = fpgacmd;
|
||||
if (ledCardCommunication != null){
|
||||
MyLog.i("sendToCardSystem..............");
|
||||
// ledCardCommunication.sendToCardSystem(fpgacmd);
|
||||
} else{
|
||||
MyLog.i("------------ledCardCommunication = null ");
|
||||
}
|
||||
}*/
|
||||
}else {
|
||||
MyLog.i("fpgacmd send fail or back is null...");
|
||||
}
|
||||
newFpgacmd = new byte[65];
|
||||
MyLog.showBytes("newFpgacmd===",newFpgacmd,0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
Log.i("_yzd", "display service on create");
|
||||
CreateWorkFolder();
|
||||
|
||||
InitialWorkParams();
|
||||
|
||||
// registerBrightnessBroadcast();
|
||||
|
||||
registerRebootBroadcast();
|
||||
|
||||
fw_receiver = new BreakpointReceiver();
|
||||
IntentFilter fw_filter = new IntentFilter();
|
||||
fw_filter.addAction("com.xixun.pixel.detect");
|
||||
registerReceiver(fw_receiver, fw_filter);
|
||||
|
||||
RefreshDisplayInitail();
|
||||
|
||||
new Thread() {
|
||||
public void run() {
|
||||
Process();
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
public void SendMessage(int iMessage,String strCommand)
|
||||
{
|
||||
if (handlerRefreshDisplay==null) return;
|
||||
Message msg = handlerRefreshDisplay.obtainMessage(iMessage,strCommand);
|
||||
handlerRefreshDisplay.sendMessage(msg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void RefreshDisplayInitail() {
|
||||
handlerRefreshDisplay = new Handler() {
|
||||
public void handleMessage(Message msg) {
|
||||
String string = (String) msg.obj;
|
||||
MyLog.i("==============================Msg.ID:" + msg.what + ",Params:" + string);
|
||||
switch (msg.what)
|
||||
{
|
||||
case MSG_CHANGE_APP_RESTART:
|
||||
MyLog.i( " "+ Thread.currentThread().getStackTrace()[2].getFileName() + "-->"
|
||||
+ "Function: " +Thread.currentThread().getStackTrace()[2].getMethodName() + "-->"
|
||||
+ "Line" +Thread.currentThread().getStackTrace()[2].getLineNumber() + ": Received Restart Command.\r\n"
|
||||
);
|
||||
System.exit(0);
|
||||
break;
|
||||
case MSG_CHANGE_INFOMATIONS_BASE:
|
||||
{ int iCommandParamsStart=string.indexOf('=');
|
||||
if (iCommandParamsStart>0) {
|
||||
int iOffset=0;
|
||||
for (iOffset=0;iOffset<string.length();iOffset++)
|
||||
{ char ucChar=string.charAt(iOffset);
|
||||
if (ucChar>=0x21 && ucChar<0x80) break;
|
||||
}
|
||||
String strCommand=string.substring(iOffset,iCommandParamsStart); // 2: 发送方会以UTF格式自动添加2个字节的标识长度.
|
||||
iCommandParamsStart++;
|
||||
String strParams=string.substring(iCommandParamsStart);
|
||||
|
||||
//MyLog.i("strCommand: " + strCommand +"; strParams: " + strParams);
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
super.handleMessage(msg);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
Log.i("_yzd", "destroy display service");
|
||||
if( receiver_brightness != null) {
|
||||
unregisterReceiver(receiver_brightness);
|
||||
receiver_brightness = null;
|
||||
}
|
||||
if (LedCardCommunication.receiver != null) {
|
||||
unregisterReceiver(LedCardCommunication.receiver);
|
||||
LedCardCommunication.receiver = null;
|
||||
}
|
||||
if( isBound_IUartService ) {
|
||||
unbindService(serviceConnection_IUartService);
|
||||
isBound_IUartService = false;
|
||||
}
|
||||
if(isBound_PlayerInfo) {
|
||||
unbindService(serviceConnection_PlayerInfo);
|
||||
isBound_PlayerInfo = false;
|
||||
}
|
||||
if( fw_receiver != null) {
|
||||
unregisterReceiver(fw_receiver);
|
||||
}
|
||||
MyLog.i(" "+ Thread.currentThread().getStackTrace()[2].getFileName() + "-->"
|
||||
+ "Function: " +Thread.currentThread().getStackTrace()[2].getMethodName() + "-->"
|
||||
+ "Line" +Thread.currentThread().getStackTrace()[2].getLineNumber() + ":\r\n"
|
||||
);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
public boolean isAppForeground(Context context){
|
||||
return true;
|
||||
}
|
||||
|
||||
public class BreakpointReceiver extends BroadcastReceiver{
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
||||
if( intent.getAction().equals("com.xixun.pixel.detect") )
|
||||
{
|
||||
try {
|
||||
MyLog.i("----------- " + intent.getAction().equals("com.xixun.pixel.detect"));
|
||||
if (clientsManage != null && clientsManage.ledCardCommunication != null && clientsManage.ledCardCommunication.mooncellFpga != null) {
|
||||
String data = clientsManage.ledCardCommunication.mooncellFpga.check_bad_led();
|
||||
Intent intent_fw = new Intent("com.xixun.pixel.detect.answer");
|
||||
intent_fw.putExtra("data", data);
|
||||
sendBroadcast(intent_fw);
|
||||
}
|
||||
}catch(Exception e){e.printStackTrace();}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*private void registerBrightnessBroadcast() {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction("xixun.intent.action.REFRESH_BRIGHTNESS");
|
||||
receiver_brightness = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
brightness = intent.getIntExtra("brightness", 0);
|
||||
manual = intent.getBooleanExtra("manual", true);
|
||||
if (ledCardCommunication == null){
|
||||
ledCardCommunication = clientsManage.ledCardCommunication;
|
||||
}
|
||||
boolean result= ledCardCommunication.LightPro(brightness);
|
||||
if (!result){//再尝试一遍
|
||||
MyLog.i("ledCardCommunication.LightPro..........."+brightness);
|
||||
result = ledCardCommunication.LightPro(brightness);
|
||||
}
|
||||
MyLog.sleepForMillisecond(200);
|
||||
if (!result){
|
||||
//退出本程序
|
||||
MyLog.i("exit display.....");
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
};
|
||||
this.registerReceiver(receiver_brightness, filter);
|
||||
}*/
|
||||
|
||||
public boolean Get_Manual(){
|
||||
return manual;
|
||||
}
|
||||
|
||||
//========================= 2019 2 20===========================================================
|
||||
// modified byfw 2019-2-20 --start 收到reboot后屏幕亮度调位0, 针对old-Y30 reboot出现企鹅问题。
|
||||
public static String REBOOT = "xixun.intent.action.REBOOT";
|
||||
BroadcastReceiver receiver_reboot = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (REBOOT.equals(intent.getAction())) {
|
||||
LedCardCommunication.reboot_cmd = true;
|
||||
MyLog.i("------------rebootcmd");
|
||||
|
||||
}else
|
||||
LedCardCommunication.reboot_cmd = false;
|
||||
}
|
||||
};
|
||||
private void registerRebootBroadcast() {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(REBOOT);
|
||||
|
||||
this.registerReceiver(receiver_reboot, filter);
|
||||
}
|
||||
// modified byfw 2019-2-20 --end
|
||||
//====================================================================================
|
||||
|
||||
private static void closeStream(Closeable stream) {
|
||||
if (stream != null) {
|
||||
try {
|
||||
stream.close();
|
||||
} catch (Exception e) {
|
||||
// nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Process()
|
||||
{
|
||||
if (bUseSerialPort) { // false
|
||||
Aidl_SerialPortsInitial();
|
||||
System.out.printf("124124414");
|
||||
|
||||
while (NeedExit() == false) {
|
||||
if (serialPorts != null) break;
|
||||
MyLog.i("Wait serialPorts connect.");
|
||||
try {
|
||||
sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Aidl_PlayerInfo();
|
||||
|
||||
if (!NeedExit()) {
|
||||
Clients_Register(); //客户机的注册
|
||||
while (!NeedExit())
|
||||
{
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (clientsManage==null) break;
|
||||
if (clientsManage.NeedExit()) break;
|
||||
}
|
||||
Clients_UnRegister(null);
|
||||
MyLog.i("Clients_UnRegister ");
|
||||
}
|
||||
MyLog.i(" "+ Thread.currentThread().getStackTrace()[2].getFileName() + "-->"
|
||||
+ "Function: " +Thread.currentThread().getStackTrace()[2].getMethodName() + "-->"
|
||||
+ "Line" +Thread.currentThread().getStackTrace()[2].getLineNumber() + ":\r\n"
|
||||
);
|
||||
}
|
||||
|
||||
public void Clients_Register() // 设备注册。
|
||||
{ Clients_UnRegister(null);
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
clientsManage=new ClientsManage(this);
|
||||
}
|
||||
|
||||
public void Clients_UnRegister(String displayID) // 设备注销,displayID:null,对所有显示屏操作。
|
||||
{ if (clientsManage!=null)
|
||||
clientsManage.Exit(displayID);
|
||||
if (displayID==null) clientsManage=null;
|
||||
}
|
||||
|
||||
ServiceConnection serviceConnection_IUartService = new ServiceConnection() {
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName name) {
|
||||
serialPorts = null;
|
||||
MyLog.i(" "+ Thread.currentThread().getStackTrace()[2].getFileName() + "-->"
|
||||
+ "Function: " + Thread.currentThread().getStackTrace()[2].getMethodName() + "-->"
|
||||
+ "Line" + Thread.currentThread().getStackTrace()[2].getLineNumber() + " Serial Exit.\r\n"
|
||||
);
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName name, IBinder iBinder) {
|
||||
try {
|
||||
serialPorts = IUartService.Stub.asInterface(iBinder);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public void Aidl_SerialPortsInitial() {
|
||||
try {
|
||||
Intent intent = new Intent("xixun.intent.action.UART_SERVICE");
|
||||
intent.setPackage("com.xixun.joey.cardsystem");
|
||||
isBound_IUartService = bindService(intent, serviceConnection_IUartService, BIND_AUTO_CREATE); // add byfw 2019/1/30
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
ServiceConnection serviceConnection_PlayerInfo = new ServiceConnection() {
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName name) {
|
||||
playerInfo = null;
|
||||
MyLog.i(" "+ Thread.currentThread().getStackTrace()[2].getFileName() + "-->"
|
||||
+ "Function: " + Thread.currentThread().getStackTrace()[2].getMethodName() + "-->"
|
||||
+ "Line" + Thread.currentThread().getStackTrace()[2].getLineNumber() + " PlayerInfo Exit.\r\n"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName name, IBinder iBinder) {
|
||||
try {
|
||||
playerInfo = PlayerInfo.Stub.asInterface(iBinder);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public void Aidl_PlayerInfo() {
|
||||
try {
|
||||
|
||||
Intent intent = new Intent(ACTION_PLAYER);
|
||||
intent.setPackage(PACKAGE_PLAYER);
|
||||
// bindService(intent, serviceConnection_PlayerInfo, BIND_AUTO_CREATE);
|
||||
isBound_PlayerInfo = bindService(intent, serviceConnection_PlayerInfo, BIND_AUTO_CREATE); // add byfw 2019/1/30
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CreateWorkFolder()
|
||||
{ File file =null;
|
||||
// 优先SD卡存储目录,空间比较大:M50:16GB。
|
||||
strStoragePath= Define.SD_CARD_PATH; //"/mnt/sdcard/"
|
||||
Define.CreateFolder(strStoragePath+Define.STORAGE_PATH); //STORAGE_PATH = “Sysolution”
|
||||
file = new File(strStoragePath + Define.STORAGE_PATH);
|
||||
if (file.exists()==false) {
|
||||
// 固定存储目录,空间比较比较小:Y卡:512MB。
|
||||
strStoragePath = Define.ROOT_PATH; // “/”
|
||||
Define.CreateFolder(strStoragePath + Define.STORAGE_PATH);
|
||||
file = new File(strStoragePath + Define.STORAGE_PATH);
|
||||
|
||||
// 均无存储空间,就放在APP安装目录下,卸载或升级参数易丢失。
|
||||
if (file.exists() == false) {
|
||||
strStoragePath = GetAppPath();
|
||||
Define.CreateFolder(strStoragePath + Define.STORAGE_PATH);
|
||||
}
|
||||
}
|
||||
MyLog.i("strStoragePath= " +strStoragePath);
|
||||
|
||||
Define.CreateFolder(strStoragePath+Define.WORK_FILES_PATH);
|
||||
Define.CreateFolder(strStoragePath+Define.RECE_FILES_PATH);
|
||||
}
|
||||
|
||||
public String GetAppPath()
|
||||
{
|
||||
return getApplicationContext().getFilesDir().getAbsolutePath()+"/..";
|
||||
}
|
||||
|
||||
public void InitialWorkParams()
|
||||
{
|
||||
workParams = new WorkParams(this,this.getApplicationContext());
|
||||
}
|
||||
|
||||
|
||||
public void AppRestart(){
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
boolean NeedExit() { return bNeedExit; }
|
||||
|
||||
public static final int MSG_CHANGE_NONE=0;
|
||||
public static final int MSG_CHANGE_APP_RESTART=MSG_CHANGE_NONE+1;
|
||||
public static final int MSG_CHANGE_INFOMATIONS_BASE= MSG_CHANGE_NONE + 100;
|
||||
static final String ACTION_PLAYER ="com.xixun.action.PlayerInfo";
|
||||
public static final String PACKAGE_PLAYER="com.xixun.xixunplayer";
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/java" isTestSource="true" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -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<BytesData> CREATOR = new Creator<BytesData>() {
|
||||
|
||||
@Override
|
||||
public BytesData createFromParcel(Parcel source) {
|
||||
return new BytesData(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BytesData[] newArray(int size) {
|
||||
return new BytesData[size];
|
||||
}
|
||||
};
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package com.xixun.lededitor;
|
||||
|
||||
import com.xixun.communicate.Define;
|
||||
|
||||
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();
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user