Skip to content

Commit

Permalink
Integrate sceUsbGps with Android Location API
Browse files Browse the repository at this point in the history
  • Loading branch information
Florin9doi committed Aug 26, 2017
1 parent 393b369 commit 50fb98c
Show file tree
Hide file tree
Showing 17 changed files with 391 additions and 22 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,8 @@ add_library(${CoreLibName} ${CoreLinkType}
Core/CoreTiming.h
Core/CwCheat.cpp
Core/CwCheat.h
Core/GPS.cpp
Core/GPS.h
Core/HDRemaster.cpp
Core/HDRemaster.h
Core/ThreadEventQueue.h
Expand Down
2 changes: 2 additions & 0 deletions Core/Core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@
<ClCompile Include="..\ext\udis86\udis86.c" />
<ClCompile Include="AVIDump.cpp" />
<ClCompile Include="FileSystems\BlobFileSystem.cpp" />
<ClCompile Include="GPS.cpp" />
<ClCompile Include="HLE\KUBridge.cpp" />
<ClCompile Include="MIPS\IR\IRAsm.cpp" />
<ClCompile Include="MIPS\IR\IRCompALU.cpp" />
Expand Down Expand Up @@ -527,6 +528,7 @@
<ClInclude Include="..\ext\udis86\udis86.h" />
<ClInclude Include="AVIDump.h" />
<ClInclude Include="FileSystems\BlobFileSystem.h" />
<ClInclude Include="GPS.h" />
<ClInclude Include="HLE\KUBridge.h" />
<ClInclude Include="MIPS\IR\IRFrontend.h" />
<ClInclude Include="MIPS\IR\IRInst.h" />
Expand Down
6 changes: 6 additions & 0 deletions Core/Core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,9 @@
<ClCompile Include="FileSystems\BlobFileSystem.cpp">
<Filter>FileSystems</Filter>
</ClCompile>
<ClCompile Include="GPS.cpp">
<Filter>Core</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="ELF\ElfReader.h">
Expand Down Expand Up @@ -1256,6 +1259,9 @@
<ClInclude Include="FileSystems\BlobFileSystem.h">
<Filter>FileSystems</Filter>
</ClInclude>
<ClInclude Include="GPS.h">
<Filter>Core</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="CMakeLists.txt" />
Expand Down
74 changes: 74 additions & 0 deletions Core/GPS.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright (c) 2012- PPSSPP Project.

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.

// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/

// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.

#include <time.h>
#include "Core/GPS.h"

GpsData gpsData;
SatData satData;

void GPS::init() {
time_t currentTime;
time(&currentTime);
setGpsTime(&currentTime);

gpsData.hdop = 1.0f;
gpsData.latitude = 51.510357f;
gpsData.longitude = -0.116773f;
gpsData.altitude = 19.0f;
gpsData.speed = 3.0f;
gpsData.bearing = 35.0f;

satData.satellites_in_view = 6;
for (int i = 0; i < satData.satellites_in_view; i++) {
satData.satInfo[i].id = i + 1; // 1 .. 32
satData.satInfo[i].elevation = i * 10;
satData.satInfo[i].azimuth = i * 50;
satData.satInfo[i].snr = 0;
satData.satInfo[i].good = 1;
}
}

void GPS::setGpsTime(time_t *time) {
struct tm *gpsTime;
gpsTime = localtime(time);

gpsData.year = (short)(gpsTime->tm_year + 1900);
gpsData.month = (short)(gpsTime->tm_mon + 1);
gpsData.date = (short)gpsTime->tm_mday;
gpsData.hour = (short)gpsTime->tm_hour;
gpsData.minute = (short)gpsTime->tm_min;
gpsData.second = (short)gpsTime->tm_sec;
}

void GPS::setGpsData(float latitude, float longitude, float altitude, float speed, float bearing, long long gpsTime) {
setGpsTime((time_t*)&gpsTime);

gpsData.latitude = latitude;
gpsData.longitude = longitude;
gpsData.altitude = altitude;
gpsData.speed = speed;
gpsData.bearing = bearing;
}

GpsData* GPS::getGpsData() {
return &gpsData;
}

SatData* GPS::getSatData() {
return &satData;
}
64 changes: 64 additions & 0 deletions Core/GPS.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright (c) 2012- PPSSPP Project.

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.

// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/

// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.

#pragma once

#pragma pack(push)
#pragma pack(1)

typedef struct {
short year;
short month;
short date;
short hour;
short minute;
short second;
float garbage1;
float hdop;
float garbage2;
float latitude;
float longitude;
float altitude;
float garbage3;
float speed;
float bearing;
} GpsData;

typedef struct {
unsigned char id;
unsigned char elevation;
short azimuth;
unsigned char snr;
unsigned char good;
short garbage;
} SatInfo;

typedef struct {
short satellites_in_view;
short garbage;
SatInfo satInfo[24];
} SatData;

#pragma pack(pop)

namespace GPS {
void init();
void setGpsTime(time_t *time);
void setGpsData(float latitude, float longitude, float altitude, float speed, float bearing, long long time);
GpsData *getGpsData();
SatData *getSatData();
}
3 changes: 3 additions & 0 deletions Core/HLE/sceKernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
#include "scePsmf.h"
#include "sceImpose.h"
#include "sceUsb.h"
#include "sceUsbGps.h"
#include "scePspNpDrm_user.h"
#include "sceVaudio.h"
#include "sceHeap.h"
Expand Down Expand Up @@ -132,6 +133,7 @@ void __KernelInit()
__SslInit();
__ImposeInit();
__UsbInit();
__UsbGpsInit();
__FontInit();
__NetInit();
__NetAdhocInit();
Expand Down Expand Up @@ -261,6 +263,7 @@ void __KernelDoState(PointerWrap &p)
__UmdDoState(p);
__UtilityDoState(p);
__UsbDoState(p);
__UsbGpsDoState(p);
__VaudioDoState(p);
__HeapDoState(p);

Expand Down
11 changes: 8 additions & 3 deletions Core/HLE/sceUsb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,14 @@ static int sceUsbStop(const char* driverName, u32 argsSize, u32 argsPtr) {

static int sceUsbGetState() {
ERROR_LOG(HLE, "UNIMPL sceUsbGetState");
int state = (usbStarted ? USB_STATUS_STARTED : USB_STATUS_STOPPED)
| (usbConnected ? USB_STATUS_CONNECTED : USB_STATUS_DISCONNECTED)
| (usbActivated ? USB_STATUS_ACTIVATED : USB_STATUS_DEACTIVATED);
int state = 0;
if (!usbStarted) {
state = 0x80243007;
} else {
state = USB_STATUS_STARTED
| (usbConnected ? USB_STATUS_CONNECTED : USB_STATUS_DISCONNECTED)
| (usbActivated ? USB_STATUS_ACTIVATED : USB_STATUS_DEACTIVATED);
}
return state;
}

Expand Down
50 changes: 46 additions & 4 deletions Core/HLE/sceUsbGps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,66 @@
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.

#include "base/NativeApp.h"
#include "Common/ChunkFile.h"
#include "Core/GPS.h"
#include "Core/HLE/HLE.h"
#include "Core/HLE/FunctionWrappers.h"
#include "Core/HLE/sceUsbGps.h"
#include "Core/MemMapHelpers.h"

enum UsbStatus {
enum GpsStatus {
GPS_STATE_OFF = 0,
GPS_STATE_ACTIVATING1 = 1,
GPS_STATE_ACTIVATING2 = 2,
GPS_STATE_ON = 3,
};

GpsStatus gpsStatus = GPS_STATE_OFF;

void __UsbGpsInit() {
gpsStatus = GPS_STATE_OFF;
}

void __UsbGpsDoState(PointerWrap &p) {
auto s = p.Section("sceUsbGps", 1, 4);
if (!s)
return;

p.Do(gpsStatus);
}

static int sceUsbGpsGetState(u32 stateAddr) {
ERROR_LOG(HLE, "UNIMPL sceUsbGpsGetData(%08x)", stateAddr);
ERROR_LOG(HLE, "UNIMPL sceUsbGpsGetState(%08x)", stateAddr);
if (Memory::IsValidAddress(stateAddr)) {
Memory::Write_U32(gpsStatus, stateAddr);
}
return 0;
}

static int sceUsbGpsOpen() {
ERROR_LOG(HLE, "UNIMPL sceUsbGpsOpen");
GPS::init();
gpsStatus = GPS_STATE_ON;
System_SendMessage("gps_command", "open");
return 0;
}

static int sceUsbGpsClose() {
ERROR_LOG(HLE, "UNIMPL sceUsbGpsClose");
gpsStatus = GPS_STATE_OFF;
System_SendMessage("gps_command", "close");
return 0;
}

static int sceUsbGpsGetData(u32 gpsDataAddr, u32 satDataAddr) {
ERROR_LOG(HLE, "UNIMPL sceUsbGpsGetData");
if (Memory::IsValidRange(gpsDataAddr, sizeof(GpsData))) {
Memory::WriteStruct(gpsDataAddr, GPS::getGpsData());
}
if (Memory::IsValidRange(satDataAddr, sizeof(SatData))) {
Memory::WriteStruct(satDataAddr, GPS::getSatData());
}
return 0;
}

Expand All @@ -43,9 +85,9 @@ const HLEFunction sceUsbGps[] =
{0X54D26AA4, nullptr, "sceUsbGpsGetInitDataLocation", '?', "" },
{0X63D1F89D, nullptr, "sceUsbGpsResetInitialPosition", '?', "" },
{0X69E4AAA8, nullptr, "sceUsbGpsSaveInitData", '?', "" },
{0X6EED4811, nullptr, "sceUsbGpsClose", '?', "" },
{0X6EED4811, &WrapI_V<sceUsbGpsClose>, "sceUsbGpsClose", 'i', "" },
{0X7C16AC3A, &WrapI_U<sceUsbGpsGetState>, "sceUsbGpsGetState", 'i', "x"},
{0X934EC2B2, nullptr, "sceUsbGpsGetData", '?', "" },
{0X934EC2B2, &WrapI_UU<sceUsbGpsGetData>, "sceUsbGpsGetData", 'i', "xx" },
{0X9D8F99E8, nullptr, "sceUsbGpsSetPowerSaveMode", '?', "" },
{0X9F267D34, &WrapI_V<sceUsbGpsOpen>, "sceUsbGpsOpen", 'i', "" },
{0XA259CD67, nullptr, "sceUsbGpsReset", '?', "" },
Expand Down
3 changes: 3 additions & 0 deletions Core/HLE/sceUsbGps.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@
#pragma once

void Register_sceUsbGps();

void __UsbGpsInit();
void __UsbGpsDoState(PointerWrap &p);
5 changes: 5 additions & 0 deletions UI/NativeApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
#include "Core/Config.h"
#include "Core/Core.h"
#include "Core/FileLoaders/DiskCachingFileLoader.h"
#include "Core/GPS.h"
#include "Core/Host.h"
#include "Core/Reporting.h"
#include "Core/SaveState.h"
Expand Down Expand Up @@ -1118,3 +1119,7 @@ void NativeShutdown() {
void NativePermissionStatus(SystemPermission permission, PermissionStatus status) {
// TODO: Send this through the screen system? Nicer than listening to string messages
}

void PushNewGpsData(float latitude, float longitude, float altitude, float speed, float bearing, long long time) {
GPS::setGpsData(latitude, longitude, altitude, speed, bearing, time);
}
8 changes: 6 additions & 2 deletions android/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@
<uses-feature android:name="android.hardware.screen.landscape" android:required="false" />
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
<uses-feature android:name="android.software.leanback" android:required="false" />
<uses-feature android:name="android.hardware.gamepad" android:required="false"/>
<uses-feature android:name="android.hardware.gamepad" android:required="false" />
<uses-feature android:name="android.hardware.location.gps" android:required="false" />
<uses-feature android:name="android.hardware.location.network" android:required="false" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="archos.permission.FULLSCREEN.FULL" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="archos.permission.FULLSCREEN.FULL" />
<uses-permission-sdk-23 android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission-sdk-23 android:name="android.permission.ACCESS_FINE_LOCATION" />

<supports-screens
android:largeScreens="true"
Expand Down
1 change: 1 addition & 0 deletions android/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ EXEC_AND_LIB_FILES := \
$(SRC)/Core/Config.cpp \
$(SRC)/Core/CoreTiming.cpp \
$(SRC)/Core/CwCheat.cpp \
$(SRC)/Core/GPS.cpp \
$(SRC)/Core/HDRemaster.cpp \
$(SRC)/Core/Host.cpp \
$(SRC)/Core/Loaders.cpp \
Expand Down
5 changes: 5 additions & 0 deletions android/jni/app-android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,11 @@ extern "C" jint JNICALL Java_org_ppsspp_ppsspp_NativeApp_getDesiredBackbufferHei
return desiredBackbufferSizeY;
}

extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_pushNewGpsData(JNIEnv *, jclass,
jfloat latitude, jfloat longitude, jfloat altitude, jfloat speed, jfloat bearing, jlong time) {
PushNewGpsData(latitude, longitude, altitude, speed, bearing, time);
}

// Call this under frameCommandLock.
static void ProcessFrameCommands(JNIEnv *env) {
while (!frameCommands.empty()) {
Expand Down
Loading

0 comments on commit 50fb98c

Please sign in to comment.