Skip to content

Commit afddb0e

Browse files
author
wenlong
committed
complete
1 parent bb50bd7 commit afddb0e

File tree

13 files changed

+312
-51
lines changed

13 files changed

+312
-51
lines changed

libs/comobd-3G-SDK-1.0.0.jar

-1.53 KB
Binary file not shown.

src/com/obd/app/bean/DROInfo.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class DROInfo {
2525
public String BRAKES;
2626
public String MINRPM;
2727
public String MILES;
28+
public String note;
2829
public void setMILES(String arg){
2930
MILES = arg;
3031
}

src/com/obd/app/bean/RSOInfo.java

Lines changed: 111 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,128 @@
11
package com.obd.app.bean;
22

3+
import com.obd.utils.MyLog;
4+
35
public class RSOInfo {
46
public String MPH;
7+
public String MILE_T;
8+
public String VBAT;
9+
public String ECT;
510
public String TIMES;
611
public String SPD;
712
public String RPM;
8-
9-
public void setMPH(String arg){
10-
MPH = arg;
13+
public String LOD;
14+
public void setLOD(String arg){
15+
LOD = arg;
1116
}
12-
public void setTIMES(String arg){
13-
TIMES = arg;
17+
public void setRPM(String arg){
18+
RPM = arg;
1419
}
1520
public void setSPD(String arg){
1621
SPD = arg;
22+
}
23+
public void setTIMES(String arg){
24+
TIMES = arg;
25+
}
26+
public void setECT(String arg){
27+
ECT = arg;
28+
}
29+
public void setVBAT(String arg){
30+
VBAT = arg;
31+
}
32+
public void setMPH(String arg){
33+
MPH = arg;
1734
}
18-
public void setRPM(String arg){
19-
RPM = arg;
35+
public void setMILE_T(String arg){
36+
MILE_T = arg;
37+
}
38+
public int getMPH(){
39+
int mph=0;
40+
try{
41+
mph = (int)(Float.parseFloat(MPH)*1000);
42+
}catch (Exception e) {
43+
// TODO: handle exception
44+
}
45+
MyLog.D("mph="+mph);
46+
return mph;
47+
}
48+
public int getMILE_T(){
49+
int miles = 0;
50+
try{
51+
miles = Integer.parseInt(MILE_T)*100;
52+
}catch (Exception e) {
53+
// TODO: handle exception
54+
}
55+
56+
return miles;
57+
}
58+
public String getR(){
59+
String ret = null;
60+
ret = String.format("&R,%s,%s,%d,%d", getMILE_T(),0,getMPH(),getTimes());
61+
return ret;
2062
}
21-
public String getDisplay(){
63+
64+
65+
public int getTimes(){
66+
int times = 0;
67+
try{
68+
times = Integer.parseInt(TIMES);
69+
}catch (Exception e) {
70+
// TODO: handle exception
71+
}
72+
return times;
73+
}
74+
public String getQ(){
2275
String ret = null;
23-
ret = String.format("&R%s,%s,%s,%s,&F%s", 0,0,0,TIMES,SPD);
76+
int ect=0,vbat=0,rmp=0,spd=0;
77+
try{
78+
ect = Integer.parseInt(ECT) + 40;
79+
vbat = (int)(Float.parseFloat(VBAT)*1000);
80+
rmp = (int)(Float.parseFloat(RPM)*4);
81+
spd = Integer.parseInt(SPD);
82+
}catch (Exception e) {
83+
// TODO: handle exception
84+
}
85+
StringBuffer buffer = new StringBuffer();
86+
buffer.append("&Q");
87+
//buffer.append(String.format("0x050x%02x",ect));
88+
buffer.append((char)(0x05));
89+
buffer.append((char)(ect));
90+
91+
//buffer.append(String.format("0x420x%02x0x%02x",vbat/256,vbat%256));
92+
buffer.append((char)(0x42));
93+
buffer.append((char)(vbat/256));
94+
buffer.append((char)(vbat%256));
95+
96+
//buffer.append(String.format("0x0C0x%02x0x%02x",rmp/256,rmp%256));
97+
buffer.append((char)(0x0C));
98+
buffer.append((char)(rmp/256));
99+
buffer.append((char)(rmp%256));
100+
101+
//buffer.append(String.format("0x0D0x%02x",spd));
102+
buffer.append((char)(0x0D));
103+
buffer.append((char)(spd));
104+
105+
ret = buffer.toString();
106+
107+
MyLog.D("ret = "+ret+",len = "+ret.length());
108+
return ret;
109+
}
110+
111+
/*
112+
* 获取速度,单位两节
113+
*/
114+
public String getSpd(){
115+
String ret = "0";
116+
float spd = 0.0f;
117+
int spd_j = 0;
118+
try {
119+
spd = Float.parseFloat(SPD);
120+
spd_j = (int)(spd*0.54f/2);
121+
} catch (Exception e) {
122+
// TODO: handle exception
123+
}
124+
ret = String.format("%02d", spd_j);
125+
MyLog.I("getSpd="+ret);
24126
return ret;
25127
}
26128
}

src/com/obd/observer/DRObserver.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import com.comobd.zyobd.observer.DRONObserver;
88
import com.comobd.zyobd.port.Subject;
9+
import com.obd.service.DataSyncService;
910
import com.obd.simpleexample.StatusInface;
1011

1112
import de.greenrobot.event.EventBus;
@@ -28,7 +29,7 @@ public void update(JSONObject jsonString) {
2829
// TODO Auto-generated method stub
2930
super.update(jsonString);
3031
//StatusInface.getInstance().postRSO(jsonString);
31-
EventBus.getDefault().post(jsonString);
32+
DataSyncService.postEvent(2, jsonString);
3233
Log.e(TAG, jsonString.toString());
3334
}
3435

src/com/obd/observer/RSObserver.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import com.comobd.zyobd.observer.RPMSPDObserver;
99
import com.comobd.zyobd.port.Subject;
10+
import com.obd.service.DataSyncService;
1011

1112
import de.greenrobot.event.EventBus;
1213

@@ -27,7 +28,7 @@ public RSObserver(Subject subject) {
2728
public void update(JSONObject jsonString) {
2829
// TODO Auto-generated method stub
2930
super.update(jsonString);
30-
31+
DataSyncService.postEvent(1, jsonString);
3132
Log.e(TAG, jsonString.toString());
3233
}
3334

src/com/obd/receiver/BootReceiver.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.obd.receiver;
22
import com.obd.service.DataSyncService;
3+
import com.obd.simpleexample.MainActivity;
34

45
import android.content.BroadcastReceiver;
56
import android.content.ComponentName;
@@ -13,7 +14,11 @@ public class BootReceiver extends BroadcastReceiver{
1314
@Override
1415
public void onReceive(Context arg0, Intent arg1) {
1516
Log.i("tt","onReceive-----"+arg1.getAction());
16-
arg0.startService(new Intent(arg0, DataSyncService.class));
17+
//arg0.startService(new Intent(arg0, DataSyncService.class));
18+
Intent intent = new Intent();
19+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
20+
intent.setClass(arg0, MainActivity.class);
21+
arg0.startActivity(intent);
1722
}
1823

1924
}

src/com/obd/service/DataSyncService.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import android.content.Context;
3333
import android.content.Intent;
3434
import android.os.Binder;
35+
import android.os.Handler;
3536
import android.os.IBinder;
3637
import android.telephony.PhoneStateListener;
3738
import android.telephony.SignalStrength;
@@ -97,6 +98,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
9798

9899
LocationClient mLocClient;
99100
MyLocationListenner myListener= new MyLocationListenner();
101+
Handler mHandler = new Handler();
100102
// 定位初始化
101103
private void locationInit(){
102104
mLocClient = new LocationClient(this);
@@ -106,7 +108,16 @@ private void locationInit(){
106108
option.setCoorType("bd09ll"); // 设置坐标类型
107109
option.setScanSpan(30*1000);
108110
mLocClient.setLocOption(option);
109-
mLocClient.start();
111+
112+
mHandler.postDelayed(new Runnable() {
113+
114+
@Override
115+
public void run() {
116+
// TODO Auto-generated method stub
117+
mLocClient.start();
118+
}
119+
}, 0*1000);
120+
110121
Log.d(TAG,"百度定位 初始化成功");
111122
}
112123
public class MyLocationListenner implements BDLocationListener {
@@ -122,8 +133,9 @@ public void onReceivePoi(BDLocation poiLocation) {}
122133
}
123134

124135
public void saveLastPos(BDLocation location){
125-
QuickShPref.putValueObject(QuickShPref.LAT, location.getLatitude());
126-
QuickShPref.putValueObject(QuickShPref.LON, location.getLongitude());
136+
QuickShPref.putValueObject(QuickShPref.LAT, (float)(location.getLatitude()));
137+
QuickShPref.putValueObject(QuickShPref.LON, (float)(location.getLongitude()));
138+
StatusInface.getInstance().getTime();
127139
MyLog.D("百度定位地址保存成功");
128140
}
129141
public static void openADB(){
@@ -206,12 +218,13 @@ public void onSignalStrengthsChanged(SignalStrength signalStrength){
206218
}
207219
}
208220

209-
public void onEventMainThread(String ret) {
210-
StatusInface.getInstance().vehicleResult(ret);
221+
public void onEventMainThread(String result) {
222+
MyLog.D("onEventMainThread String ret="+result);
223+
//StatusInface.getInstance().vehicleResult(result);
211224
}
212225
public void onEventMainThread(JsonMsg msg) {
213226
switch (msg.what) {
214-
case 0:
227+
case 2:
215228
StatusInface.getInstance().DROinface(msg.obj);
216229
break;
217230
case 1:
@@ -223,4 +236,11 @@ public void onEventMainThread(JsonMsg msg) {
223236

224237
}
225238

239+
public static void postEvent(int what,JSONObject json){
240+
JsonMsg msg = new JsonMsg();
241+
msg.what = what;
242+
msg.obj = json;
243+
EventBus.getDefault().post(msg);
244+
}
245+
226246
}

src/com/obd/simpleexample/MainActivity.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
package com.obd.simpleexample;
22

3+
import java.io.IOException;
4+
35
import android.app.Activity;
46
import android.content.Intent;
57
import android.os.Bundle;
8+
import android.os.Handler;
69
import android.util.Log;
710
import android.view.Menu;
811

912
import com.comobd.zyobd.api.OBDAPI;
1013
import com.obd.observer.BObserver;
1114
import com.obd.service.DataSyncService;
15+
import com.obd.utils.MyLog;
1216
import com.umeng.analytics.MobclickAgent;
1317

1418
public class MainActivity extends Activity {
@@ -19,7 +23,7 @@ protected void onCreate(Bundle savedInstanceState) {
1923
setContentView(R.layout.activity_main);
2024

2125
startService(new Intent(this, DataSyncService.class));
22-
Log.d("TAG", "MainActivity onCreate");
26+
MyLog.E("MainActivity onCreate");
2327
}
2428

2529
@Override
@@ -40,8 +44,26 @@ protected void onPause() {
4044
protected void onResume() {
4145
// TODO Auto-generated method stub
4246
super.onResume();
47+
mHandler.postDelayed(mSyncRunnable, 3000);
4348
// MobclickAgent.onResume(this);
4449
}
50+
51+
Handler mHandler = new Handler();
52+
53+
Runnable mSyncRunnable = new Runnable(){
4554

55+
@Override
56+
public void run() {
57+
// TODO Auto-generated method stub
58+
try {
59+
Runtime.getRuntime().exec("sync");
60+
} catch (IOException e) {
61+
// TODO Auto-generated catch block
62+
e.printStackTrace();
63+
}
64+
MyLog.E("sync 执行成功");
65+
}
66+
67+
};
4668

4769
}

0 commit comments

Comments
 (0)