package com.yesway.drivingbehaviorcollect.service;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.app.Service;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.location.LocationProvider;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Binder;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.Messenger;
import android.os.RemoteException;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;
import com.yesway.drivingbehaviorcollect.activity.MyApplication;
import com.yesway.drivingbehaviorcollect.activity.R;
import com.yesway.drivingbehaviorcollect.entity.AcceleratedSpeed;
import com.yesway.drivingbehaviorcollect.entity.AngleSpeed;
import com.yesway.drivingbehaviorcollect.filter.MeanFilter;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.Timer;
import java.util.TimerTask;
public class DataCollectService extends Service implements SensorEventListener, LocationListener {
private static final String TAG = "DataCollectService";
private LocationManager locationManager;
private SensorManager sensorManager;
private String collectFileNameGyro = "gyrodata.csv";
private String collectFileNameAccel = "acceldata.csv";
private String headerTableGyro = "x axis,y axis,z axis,speed,x anagle,y anagle,z anagle,angle,date,time,calculateResult";
private String headerTableAccel = "x axis,y axis,z axis,speed,timestamp,currtime,result";
private PrintWriter printWriterGyro;
private PrintWriter printWriterAccel;
private List<AngleSpeed> listAngleSpeed = new ArrayList<AngleSpeed>();
private List<AcceleratedSpeed> listAcceleratedSpeed = new ArrayList<AcceleratedSpeed>();
// 偏心率
public static final float EPSILON = 0.000000001f;
// 10亿纳秒=1秒
private static final float NS2S = 1.0f / 1000000000.0f;
// 均值滤波窗口
private static final int MEAN_FILTER_WINDOW = 10;
// 最小样本计数
private static final int MIN_SAMPLE_COUNT = 30;
// 是否初始化了方位
private boolean hasInitialOrientation = false;
// 是否初始化了校准
private boolean stateInitializedCalibrated = false;
private int accelerationSampleCount = 0;
private int magneticSampleCount = 0;
private long timestampOldCalibrated = 0;
private float lastXAxisAngle = -1;
private float lastXAxisAngleByRotationVector = -1;
private long currTimeGyro;
private long lastTimeGyro;
private long currTimeAccel;
private long lastTimeAccel;
private DecimalFormat df;
private float[] rotationVectorMatrix;
// Calibrated maths.
private float[] currentRotationMatrixCalibrated;
private float[] deltaRotationMatrixCalibrated;
private float[] deltaRotationVectorCalibrated;
private float[] gyroscopeOrientationCalibrated;
private float[] initialRotationMatrix;
private float[] acceleration;
private float[] magnetic;
// 均值过滤器
private MeanFilter accelerationFilter;
private MeanFilter magneticFilter;
private float[] gravity;
private static final float ALPHA = 0.8f;
private float azimuthGPS = -1;
// private DataCollectBinder dataCollectBinder;
private float xAngle;
private float yAngle;
private float zAngle;
private static int turnLeft;
private static int turnRight;
private static int addSpeed;
private static int cutSpeed;
private Intent intentReceiver;
private Messenger messengerActivity;
private Messenger messagerService;
private SoundPool soundPool;
private HashMap<Integer, Integer> soundMap = new HashMap<Integer, Integer>();
private Toast toast;
private Handler handlerService = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
case 0:
messengerActivity = msg.replyTo;
break;
case 1:
++turnLeft;
soundPool.play(soundMap.get(1), 0.1f, 0.1f, 0, 0, 1);
//TTSController.getInstance(DataCollectService.this).playTextFromLinkedList("亲,左转弯了");
sendMsg();
toast = Toast.makeText(DataCollectService.this, "左转弯了", Toast.LENGTH_SHORT);
toast.show();
break;
case 2:
++turnRight;
soundPool.play(soundMap.get(2), 0.1f, 0.1f, 0, 0, 1);
// TTSController.getInstance(DataCollectService.this).playTextFromLinkedList("亲,右转弯了");
sendMsg();
toast = Toast.makeText(DataCollectService.this, "右转弯了", Toast.LENGTH_SHORT);
toast.show();
break;
case 3:
++addSpeed;
soundPool.play(soundMap.get(3), 0.1f, 0.1f, 0, 0, 1);
//TTSController.getInstance(DataCollectService.this).playTextFromLinkedList("亲,急加速了");
sendMsg();
toast = Toast.makeText(DataCollectService.this, "急加速了", Toast.LENGTH_SHORT);
toast.show();
break;
case 4:
++cutSpeed;
soundPool.play(soundMap.get(4), 0.1f, 0.1f, 0, 0, 1);
//TTSController.getInstance(DataCollectService.this).playTextFromLinkedList("亲,急减速了");
sendMsg();
toast = Toast.makeText(DataCollectService.this, "急减速了", Toast.LENGTH_SHORT);
toast.show();
break;
default:
break;
}
}
};
public void sendMsg() {
if (messengerActivity == null)
return;
Bundle bundle;
Message msg1;
bundle = new Bundle();
bundle.putInt("turnLeft", turnLeft);
bundle.putInt("turnRight", turnRight);
bundle.putInt("addSpeed", addSpeed);
bundle.putInt("cutSpeed", cutSpeed);
msg1 = new Message();
msg1.what = 1;
msg1.setData(bundle);
try {
messengerActivity.send(msg1);
} catch (RemoteException e) {
e.printStackTrace();
}
}
private Timer timer;
private TimerTask timerTask = new TimerTask() {
@Override
public void run() {
if (messengerActivity == null)
return;
Bundle bundle;
Message msg1;
bundle = new Bundle();
bundle.putFloat("x", gyroscopeOrientationCalibrated[0]);
bundle.putFloat("y", gyroscopeOrientationCalibrated[1]);
bundle.putFloat("z", gyroscopeOrientationCalibrated[2]);
bundle.putFloat("g", azimuthGPS);
msg1 = new Message();
msg1.what = 0;
try {
msg1.setData(bundle);
messengerActivity.send(msg1);
} catch (RemoteException e) {
e.printStackTrace();
}
}
};
public Messenger getMessag
没有合适的资源?快使用搜索试试~ 我知道了~
传感器分类:感知环境的、感知距离的、感知运动的、感知方位的.zip
共30个文件
xml:8个
java:8个
png:4个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 101 浏览量
2024-01-24
11:25:59
上传
评论
收藏 7.33MB ZIP 举报
温馨提示
传感器分类:感知环境的、感知距离的、感知运动的、感知方位的 1 方向传感器:Sensor.TYPE_ORIENTATION 2 加速度传感器:Sensor.TYPE_ACCELEROMETER 3 线性加速度传感器:Sensor.TYPE_LINEAR_ACCELERATION 4 光传感器:Sensor.TYPE_LIGHT 5 磁场传感器:Sensor.TYPE_MAGNETIC_FIELD 6 距离传感器:Sensor.TYPE_PROXIMITY 7 温度传感器:Sensor.TYPE_TEMPERATURE 8 旋转向量传感器:Sensor.TYPE_ROTATION_VECTOR 9 角速度传感器:Sensor.TYPE_GYROSCOPE//gyroscope 10 重力传感器:Sensor.TYPE_GRAVITY 11 压力传感器:Sensor.TYPE_PRESSURE
资源推荐
资源详情
资源评论
收起资源包目录
传感器分类:感知环境的、感知距离的、感知运动的、感知方位的.zip (30个子文件)
android-amap-drivingbehavior-collect-master
src
androidTest
java
com
yesway
drivingbehaviorcollect
activity
ApplicationTest.java 373B
main
assets
tts
xiaofeng.jet 1.27MB
common.jet 4.11MB
xiaoyan.jet 3.91MB
java
com
yesway
drivingbehaviorcollect
activity
MyApplication.java 2KB
MainActivity.java 16KB
service
DataCollectService.java 31KB
filter
MeanFilter.java 2KB
entity
AngleSpeed.java 2KB
AcceleratedSpeed.java 2KB
util
AppConfig.java 182B
res
drawable-mdpi
ic_launcher.png 5KB
drawable-xhdpi
ic_launcher.png 14KB
drawable-xxhdpi
ic_launcher.png 19KB
menu
menu_main.xml 361B
values-w820dp
dimens.xml 358B
values
dimens.xml 211B
strings.xml 224B
styles.xml 194B
layout
login.xml 2KB
activity_main.xml 23KB
raw
accelebration_jia.mp3 29KB
turnover_right.mp3 25KB
turnover_left.mp3 21KB
accelebration_jian.mp3 25KB
drawable-hdpi
ic_launcher.png 9KB
AndroidManifest.xml 2KB
proguard-rules.pro 649B
build.gradle 607B
drivingbehaviorcollect.iml 7KB
共 30 条
- 1
资源评论
博士僧小星
- 粉丝: 1774
- 资源: 5875
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功