Skip to content

Commit 7ecb17a

Browse files
author
wenlong
committed
last
1 parent afddb0e commit 7ecb17a

File tree

8 files changed

+106
-44
lines changed

8 files changed

+106
-44
lines changed

res/layout/activity_main.xml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,21 @@
1010
android:layout_centerHorizontal="true"
1111
android:layout_centerVertical="true"
1212
android:text="@string/hello_world" />
13-
13+
14+
<Button
15+
android:id="@+id/start"
16+
android:layout_width="match_parent"
17+
android:layout_height="wrap_content"
18+
android:layout_alignParentTop="true"
19+
android:text="启动"
20+
android:onClick="onClick"
21+
/>
22+
<Button
23+
android:id="@+id/stop"
24+
android:layout_width="match_parent"
25+
android:layout_height="wrap_content"
26+
android:layout_below="@+id/start"
27+
android:text="熄火"
28+
android:onClick="onClick"
29+
/>
1430
</RelativeLayout>

res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
<string name="app_name">SimpleExample</string>
55
<string name="menu_settings">Settings</string>
66
<string name="hello_world">Hello world!</string>
7-
7+
<string name="stop">{"MAF":"0\r\n","AVGSPD":"029","STARTS":"068","MILE-T":"0003.6","MAXRPM":"11642","POWER":"0","RACLS":"000","FUELS":"0037.241","FUEL-T":"000.605","MAXACL":"008","TIMES":"0007.7","MAXSPD":"030","BRAKES":"000","MINRPM":"00000","MILES":"005558.7"}</string>
88
</resources>

src/com/obd/service/DataSyncService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public void onSignalStrengthsChanged(SignalStrength signalStrength){
220220

221221
public void onEventMainThread(String result) {
222222
MyLog.D("onEventMainThread String ret="+result);
223-
//StatusInface.getInstance().vehicleResult(result);
223+
StatusInface.getInstance().vehicleResult(result);
224224
}
225225
public void onEventMainThread(JsonMsg msg) {
226226
switch (msg.what) {

src/com/obd/simpleexample/MainActivity.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,26 @@
22

33
import java.io.IOException;
44

5+
import org.json.JSONException;
6+
import org.json.JSONObject;
7+
58
import android.app.Activity;
69
import android.content.Intent;
710
import android.os.Bundle;
811
import android.os.Handler;
912
import android.util.Log;
1013
import android.view.Menu;
14+
import android.view.View;
1115

1216
import com.comobd.zyobd.api.OBDAPI;
17+
import com.obd.app.bean.JsonMsg;
1318
import com.obd.observer.BObserver;
1419
import com.obd.service.DataSyncService;
1520
import com.obd.utils.MyLog;
1621
import com.umeng.analytics.MobclickAgent;
1722

23+
import de.greenrobot.event.EventBus;
24+
1825
public class MainActivity extends Activity {
1926

2027
@Override
@@ -26,6 +33,31 @@ protected void onCreate(Bundle savedInstanceState) {
2633
MyLog.E("MainActivity onCreate");
2734
}
2835

36+
public void onClick(View v){
37+
switch (v.getId()) {
38+
case R.id.start:
39+
EventBus.getDefault().post("IGNITION");
40+
break;
41+
case R.id.stop:
42+
JsonMsg msg = new JsonMsg();
43+
msg.what = 2;
44+
String json = getString(R.string.stop);
45+
MyLog.D( json);
46+
47+
try {
48+
msg.obj = new JSONObject(json);
49+
} catch (JSONException e) {
50+
// TODO Auto-generated catch block
51+
e.printStackTrace();
52+
}
53+
54+
EventBus.getDefault().post(msg);
55+
break;
56+
default:
57+
break;
58+
}
59+
}
60+
2961
@Override
3062
public boolean onCreateOptionsMenu(Menu menu) {
3163
// Inflate the menu; this adds items to the action bar if it is present.
@@ -37,15 +69,15 @@ public boolean onCreateOptionsMenu(Menu menu) {
3769
protected void onPause() {
3870
// TODO Auto-generated method stub
3971
super.onPause();
40-
// MobclickAgent.onPause(this);
72+
MobclickAgent.onPause(this);
4173
}
4274

4375
@Override
4476
protected void onResume() {
4577
// TODO Auto-generated method stub
4678
super.onResume();
4779
mHandler.postDelayed(mSyncRunnable, 3000);
48-
// MobclickAgent.onResume(this);
80+
MobclickAgent.onResume(this);
4981
}
5082

5183
Handler mHandler = new Handler();

src/com/obd/simpleexample/StatusInface.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ public static StatusInface getInstance(){
3636
}
3737

3838
public void vehicleResult(String result){
39-
MyLog.E("vehicleResult result="+result);
4039
if(START.equalsIgnoreCase(result)){
41-
MyLog.E("onStart true");
4240
onStart(true);
4341
}else if(STOP.equalsIgnoreCase(result)){
4442

@@ -107,13 +105,10 @@ public String getStartS1(){
107105
return ret;
108106
}
109107
public void doOnstart(){
110-
MyLog.E("doOnstart enter");
111108
String content = String.format("%s&S1,0,,%s#", getShortHead(),getTime());
112-
MyLog.E("doOnstart insert " + content);
113109
startS1 = content;
114-
MyLog.E("doOnstart insert complete");
115-
DBmanager.getInase().insert(content);
116-
DBmanager.getInase().insertBackup(content);
110+
// DBmanager.getInase().insert(content);
111+
// DBmanager.getInase().insertBackup(content);
117112
isStartOn = true;
118113
QuickShPref.putValueObject(QuickShPref.IsStartOn, isStartOn);
119114
}
@@ -128,12 +123,12 @@ public void onStop(DROInfo info){
128123
if(!isStartOn){
129124
MyLog.W("警告:收到熄火消息时 isStartOn="+isStartOn);
130125
}
131-
132-
String content = String.format("%s&S2,%s,%sE,%sN,%d,%d,5,%s,%s,%s,%s,0#", getShortHead(),getTime(),
133-
FloatToString(QuickShPref.getFloat(QuickShPref.LON)),FloatToString(QuickShPref.getFloat(QuickShPref.LAT)),
134-
info.getMILESM(),info.getFuleSmL(),info.RACLS,info.BRAKES,info.STARTS,info.STARTS);
135-
DBmanager.getInase().insert(content);
136-
DBmanager.getInase().insertBackupNote(content, info.note);
126+
mDROInfo = info;
127+
// String content = String.format("%s&S2,%s,%sE,%sN,%d,%d,5,%s,%s,%s,%s,0#", getShortHead(),getTime(),
128+
// FloatToString(QuickShPref.getFloat(QuickShPref.LON)),FloatToString(QuickShPref.getFloat(QuickShPref.LAT)),
129+
// info.getMILESM(),info.getFuleSmL(),info.RACLS,info.BRAKES,info.STARTS,info.STARTS);
130+
// DBmanager.getInase().insert(content);
131+
// DBmanager.getInase().insertBackupNote(content, info.note);
137132
isStartOn = false;
138133
QuickShPref.putValueObject(QuickShPref.IsStartOn, isStartOn);
139134
mSpd = "00";

src/com/obd/simpleexample/StatusVehicle.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ public String callBack(String result) {
2020
// TODO Auto-generated method stub
2121
Log.e(TAG, result);
2222
//StatusInface.getInstance().postVehicle(result);
23-
//EventBus.getDefault().post(result);
24-
MyLog.E("callBack result="+result);
25-
StatusInface.getInstance().vehicleResult(result);
23+
EventBus.getDefault().post(result);
24+
//MyLog.E("callBack result="+result);
25+
//StatusInface.getInstance().vehicleResult(result);
2626
return result;
2727
}
2828

src/com/obd/utils/QuickShPref.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class QuickShPref {
2323
public static String LAT = "lat";
2424
public static String LON = "lon";
2525
public static String Time = "time";
26-
26+
public static String TimeGPS = "TimeGPS";
2727
private static SharedPreferences sSharedPreferences;
2828
private static Editor sEditor;
2929

src/com/obd/widget/GetLoaction.java

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.obd.widget;
22

33
import java.nio.Buffer;
4+
import java.text.SimpleDateFormat;
5+
import java.util.Date;
46
import java.util.Random;
57
import java.util.regex.Matcher;
68
import java.util.regex.Pattern;
@@ -16,7 +18,7 @@
1618

1719

1820
public class GetLoaction {
19-
public static final boolean isDebug = false;
21+
public static final boolean isDebug = true;
2022

2123
public String mIMEI = "33333333333";
2224
int mGSMsingle;
@@ -41,9 +43,15 @@ public String uploadPos(BDLocation location) {
4143
double lon = location.getLongitude();
4244
double lat = location.getLatitude();//gps.mLat; // 纬度
4345

46+
// 如果经纬度为0,则不上报
47+
if (lon == 0 || lat == 0) {
48+
return null;
49+
}
50+
4451
if(isDebug){
4552
Random random = new Random();
46-
lon = lon+0.001f*random.nextInt(10);
53+
lon = lon+0.0001f*random.nextInt(100);
54+
lat = lat+0.0001f*random.nextInt(100);
4755
}
4856

4957
int SatelliteNumber = location.getSatelliteNumber();
@@ -59,10 +67,7 @@ public String uploadPos(BDLocation location) {
5967
f = 0x0F; // 基站 15
6068
}
6169

62-
// 如果经纬度为0,则不上报
63-
if (lon == 0 || lat == 0) {
64-
return null;
65-
}
70+
6671

6772

6873
int lonDu = (int) lon;
@@ -106,20 +111,23 @@ public String uploadPos(BDLocation location) {
106111
buffer.append("&B0000000000");
107112

108113
GetLoactionHead = buffer.toString();
109-
// buffer.append("&O"+SatelliteNumber);
110-
// buffer.append("&N"+mGSMsingle);
111-
112-
// buffer.append(",&Q0x050x030x0C0x010x12");
113-
// if(StatusInface.getInstance().getStartS1() != null){
114-
// buffer.append("&S1,0,,"+StatusInface.getInstance().getTime());
115-
// }else{
116-
// MyLog.D("getStartS1 = null");
117-
// }
118-
// DROInfo mDROInfo = StatusInface.getInstance().getDROInfo();
119-
// if(mDROInfo!=null){
120-
// buffer.append(String.format("&S2,%s,%sE,%sN,%d,%d,5,%s,%s,%s,%s,0", StatusInface.getInstance().getTime(),
121-
// lonString,latString,mDROInfo.getMILESM(),mDROInfo.getFuleSmL(),mDROInfo.RACLS,mDROInfo.BRAKES,mDROInfo.STARTS,mDROInfo.STARTS));
122-
// }
114+
115+
if(StatusInface.getInstance().getStartS1() != null){
116+
buffer.append("&S1,0,,"+StatusInface.getInstance().getTime());
117+
DBmanager.getInase().insertBackup(buffer.toString());
118+
}else{
119+
DROInfo mDROInfo = StatusInface.getInstance().getDROInfo();
120+
if(mDROInfo != null){
121+
buffer.append(String.format("&S2,%s,%sE,%sN,%d,%d,5,%s,%s,%s,%s,0", StatusInface.getInstance().getTime(),
122+
lonString,latString,mDROInfo.getMILESM(),mDROInfo.getFuleSmL(),
123+
mDROInfo.RACLS,mDROInfo.BRAKES,mDROInfo.STARTS,mDROInfo.STARTS));
124+
DBmanager.getInase().insertBackupNote(buffer.toString(),mDROInfo.note);
125+
}else{
126+
buffer.append("&O"+SatelliteNumber);
127+
buffer.append("&N"+mGSMsingle);
128+
}
129+
}
130+
123131
//buffer.append("&S2,20150318111758,11356.1966E,2233.1303N,13300,6100,5,6,7,1200,900,5");
124132
buffer.append('#');
125133

@@ -167,8 +175,7 @@ private String formatTime(String time){
167175
return null;
168176

169177
if(isDebug){
170-
Random random = new Random();
171-
s = random.nextInt(60);
178+
return getTime();
172179
}
173180
} catch (Exception e) {
174181
// TODO: handle exception
@@ -179,4 +186,16 @@ private String formatTime(String time){
179186
}
180187
return ret;
181188
}
189+
public String getTime(){
190+
Date date = new Date();
191+
192+
if(date.getYear()<114){
193+
return null;
194+
}
195+
196+
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
197+
String t=format.format(new Date());
198+
199+
return t;
200+
}
182201
}

0 commit comments

Comments
 (0)