实现定位数据报文

serial
BlueMatthew 1 year ago
parent eff3d3c918
commit 53e309397a

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

@ -1285,11 +1285,11 @@ std::string CPhoneDevice::GetFileName() const
return mPath; 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) 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); 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); bool OnVideoReady(bool result, const char* path, unsigned int photoId);
void UpdateSignalLevel(int signalLevel); void UpdateSignalLevel(int signalLevel);

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

Loading…
Cancel
Save