实现定位数据报文

serial
BlueMatthew 1 year ago
parent eff3d3c918
commit 53e309397a

@ -7,6 +7,7 @@
#include "PhoneDevice.h"
#include "PhoneDevice2.h"
#include <sys/system_properties.h>
#include <AndroidHelper.h>
#include <android/multinetwork.h>
@ -375,7 +376,12 @@ Java_com_xypower_mpapp_MicroPhotoService_sendHeartbeat(
extern "C" JNIEXPORT void JNICALL
Java_com_xypower_mpapp_MicroPhotoService_updatePosition(
JNIEnv* env,
jobject pThis, jlong handler, jdouble lon, jdouble lat, jlong ts) {
jobject pThis, jlong handler, jdouble lon, jdouble lat, jdouble radius, jlong ts) {
if (handler == 0)
{
return;
}
CTerminal* pTerminal = reinterpret_cast<CTerminal *>(handler);
IDevice* dev = pTerminal->GetDevice();
@ -385,7 +391,7 @@ Java_com_xypower_mpapp_MicroPhotoService_updatePosition(
}
CPhoneDevice* phoneDevice = (CPhoneDevice *)dev;
phoneDevice->UpdatePosition(lon, lat, ts);
phoneDevice->UpdatePosition(lon, lat, radius, ts);
}
extern "C" JNIEXPORT jboolean JNICALL

@ -1285,11 +1285,11 @@ std::string CPhoneDevice::GetFileName() const
return mPath;
}
void CPhoneDevice::UpdatePosition(double lon, double lat, time_t ts)
void CPhoneDevice::UpdatePosition(double lon, double lat, double radius, time_t ts)
{
if (m_listener != NULL)
{
return m_listener->OnPositionDataArrived(lon, lat, ts);
return m_listener->OnPositionDataArrived(lon, lat, radius, ts);
}
}

@ -197,7 +197,7 @@ public:
bool GetNextScheduleItem(uint32_t tsBasedZero, uint32_t scheduleTime, vector<uint32_t>& items);
void UpdatePosition(double lon, double lat, time_t ts);
void UpdatePosition(double lon, double lat, double radius, time_t ts);
bool OnVideoReady(bool result, const char* path, unsigned int photoId);
void UpdateSignalLevel(int signalLevel);

@ -1,6 +1,5 @@
package com.xypower.mpapp;
import static java.lang.System.err;
import static java.lang.System.loadLibrary;
import android.app.AlarmManager;
@ -229,6 +228,8 @@ public class MicroPhotoService extends Service {
// Environment.getExternalStoragePublicDirectory(String)
// registerHeartbeatTimer(getHeartbeatDuration());
requestPosition();
}
@Override
public void onDestroy() {
@ -705,6 +706,15 @@ public class MicroPhotoService extends Service {
Date date = new Date();
long startTime = (date.getTime() + 999) / 1000;
service.updateCaptureSchedule(startTime);
try {
Location location = mLocationManager.getLastKnownLocation(mLocateType);
if (location != null) {
service.updatePosition(service.mNativeHandle, location.getLongitude(), location.getLatitude(), location.getAccuracy(), location.getTime() / 1000);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
};
@ -890,21 +900,23 @@ public class MicroPhotoService extends Service {
if (mLocationManager == null) {
mLocationManager = (LocationManager) getSystemService (Context.LOCATION_SERVICE);
if (!mLocationManager.isProviderEnabled(GPS_LOCATION_NAME)) {
if (!mLocationManager.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) {
return false;
}
mLocateType = mLocationManager.GPS_PROVIDER;
// Set Listener
mLocationManager.requestLocationUpdates(mLocateType, 100,0, mLocationListener);
}
Location location = mLocationManager.getLastKnownLocation(mLocateType);
if (location != null) {
updatePosition(mNativeHandle, location.getLongitude(), location.getLatitude(), location.getTime());
if (location != null && mNativeHandle != 0) {
updatePosition(mNativeHandle, location.getLongitude(), location.getLatitude(), location.getAccuracy(), location.getTime() / 1000);
}
// Set Listener
mLocationManager.requestLocationUpdates(mLocateType, 100,0, locationListener);
return true;
} catch (SecurityException ex) {
ex.printStackTrace();
}
return false;
@ -944,6 +956,7 @@ public class MicroPhotoService extends Service {
try {
final TelephonyManager telephonyManager = (TelephonyManager) getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
SignalStrength ss = telephonyManager.getSignalStrength();
if (ss != null) {
return ss.getLevel();
}
@ -1095,7 +1108,7 @@ cellSignalStrengthGsm.getDbm();
protected native boolean notifyToTakePhoto(long handler, int channel, int preset, long scheduleTime, boolean photoOrVideo);
protected native boolean sendHeartbeat(long handler, int signalLevel);
protected native boolean reloadConfigs(long handler);
protected native void updatePosition(long handler, double lon, double lat, long ts);
protected native void updatePosition(long handler, double lon, double lat, double radius, long ts);
protected native boolean uninit(long handler);
protected native void recordingFinished(long handler, boolean result, String path, long videoId);
public static native void setOtgState(boolean enabled);
@ -1103,19 +1116,18 @@ cellSignalStrengthGsm.getDbm();
public static native String getSerialNumber();
////////////////////////GPS////////////////////
private static final String GPS_LOCATION_NAME = android.location.LocationManager.GPS_PROVIDER;
// private static final String GPS_LOCATION_NAME = android.location.LocationManager.GPS_PROVIDER;
private LocationManager mLocationManager;
private String mLocateType;
private LocationListener locationListener = new LocationListener() {
private LocationListener mLocationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
updatePosition(mNativeHandle, location.getLongitude(), location.getLatitude(), location.getTime());
// Log.i(TAG, "Time: " + location.getTime());
// Log.i(TAG, "经度:" + location.getLongitude());
// Log.i(TAG, "纬度:" + location.getLatitude());
// Log.i(TAG, "海拔:" + location.getAltitude());
if (mNativeHandle != 0) {
updatePosition(mNativeHandle, location.getLongitude(), location.getLatitude(), location.getAccuracy(), location.getTime() / 1000);
}
Log.i(TAG, "Time:" + location.getTime() + " Lon=" + location.getLongitude() + "Lat=" + location.getLatitude() + "Alt=" + location.getAltitude());
}
@Override

Loading…
Cancel
Save