- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在运行传感器和位置服务,数据被传递到 TraceManager 文件,该文件在其中进行处理并传递到 TraceCWrapper 以映射到共享 C 库 .so ,看来传感器和位置数据是很好并在 TraceManager 中接收,然后将其传递到 TraceCWrapper,但是应用程序在几秒钟后崩溃,我得到的唯一错误行是:
A/libc:致命信号 11 (SIGSEGV)、代码 1 (SEGV_MAPERR)、tid 29938 中的故障地址 0x8 (AsyncTask #1)、pid 29870 (pp.traceandroid)
public class TraceManager extends AppCompatActivity {
private String TAG = "TraceManager";
private int phoneAngle = 0;
private double initialStepCalibrationOffset;
private int initialPointingAngleDeg = 0;
private int initialAlignmentMode = 0;
private int startingFloorID = 0;
private LatLng startingLatLong;
private double startingAccuracy = 1.0;
private Context context;
private boolean isMagConsistentAtInit = false;
private boolean isMagValid = true;
private Timer callBackTimer;
private String[] contentsStatic;
private String[] contentsDynamic;
private boolean isRunning = false;
private TraceCWrapper traceCWrapper = new TraceCWrapper();
Handler callbackHandler = new Handler();
Runnable callbackRunnable;
//internal use only
private boolean _traceCDontActuallyUse;
// The interval, in seconds, for providing trace updates.
public ObservableDouble updateCallbackInterval = new ObservableDouble(0){
@Override
public void addOnPropertyChangedCallback(@NonNull OnPropertyChangedCallback callback) {
if(isRunning){
stopCallbackTimer();
startCallbackTimer();
}
super.addOnPropertyChangedCallback(callback);
}
};
private double updateCallBackIntervalValue = updateCallbackInterval.get();
/// A Boolean value
public ObservableBoolean allowsBackgroundExecution = new ObservableBoolean(false){
@Override
public void addOnPropertyChangedCallback(@NonNull OnPropertyChangedCallback callback) {
if(isRunning){
stopUpdatingTrace();
startUpdatingTrace();
}
super.addOnPropertyChangedCallback(callback);
}
};
private boolean allowsBackgroundExecutionValue = allowsBackgroundExecution.get();
public TraceManager(Context context){
this.context=context;
}
public TraceManager(){
}
public void initialiseTrace(String[] mapFloors,
String[] initialDynamicMaps,
int phoneRelativeToBodyDegree, //this comes from onboarding?
double updateCallBackIntervalValue,
boolean allowsBackgroundExecutionValue,
double initialStepCalibrationOffset, //standard
String[] iBeaconUUIDs,
int startingFloorID,
LatLng startingLatLong, //this is form the starting node
double startingAccuracy, //
boolean _traceCDontActuallyUse,
int phoneOrientation,
int phoneOrientationUse,
boolean magntometerValid
){
this.contentsStatic = mapFloors;
this.contentsDynamic = initialDynamicMaps;
this.phoneAngle = phoneRelativeToBodyDegree;
this.initialStepCalibrationOffset = initialStepCalibrationOffset;
this.updateCallbackInterval = updateCallbackInterval;
this.allowsBackgroundExecution = allowsBackgroundExecution;
this.isMagValid = magntometerValid;
if(!(iBeaconUUIDs.length <=0)){
LocationProvider.arrayOfUUIDsToDetect = iBeaconUUIDs;
}else{
Log.i(TAG, "TraceManager.init: ignoring ibeaconUIDs, because it is empty. Default used");
};
this.startingFloorID = startingFloorID;
this.startingLatLong = startingLatLong;
this.startingAccuracy = startingAccuracy;
this.initialPointingAngleDeg = phoneOrientation;
this.initialAlignmentMode = phoneOrientationUse;
//internal use only
this._traceCDontActuallyUse = _traceCDontActuallyUse;
}
//Functions
/// Broadcast Receiver to get readings from MotionProvider/service
public void startUpdatingSensors(){
//Start sensor service
Intent startService = new Intent(TraceManager.this, SensorService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(startService);
} else {
startService(startService);
}
}
/// Starts the generation of trace updates.
public void startUpdatingTrace(){
//Start Sensors
//startUpdatingSensors();
//register for sensorBroadcast
BroadcastReceiver sensorReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "imu Received");
TCIMUEvent tcimuEvent = (TCIMUEvent) intent.getSerializableExtra("imu");
traceCWrapper.provideDeviceMotion(tcimuEvent, 1, 90, RotationMode.PortraitYUp);
}
};
LocalBroadcastManager.getInstance(context).registerReceiver(
sensorReceiver, new IntentFilter("imuCreated")
);
//register for locationBroadcast
//register for sensorBroadcast
BroadcastReceiver locationReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "location Received");
TCLocationEvent tcLocationEvent = (TCLocationEvent) intent.getSerializableExtra("locationCreated");
Log.d(TAG, "Inlocation reciever");
traceCWrapper.provideLocation(tcLocationEvent);
}
};
LocalBroadcastManager.getInstance(context).registerReceiver(
locationReceiver, new IntentFilter("locationCreated")
);
Log.d(TAG, "inside updating trace");
//Start CallbackTimer
startCallbackTimer();
}
private void CallbackUpdate() {
/* callbackRunnable = new Runnable(){
@Override
public void run() {
Log.d(TAG, "calling callback");
traceCWrapper.getLatestTraceResult();
callbackHandler.postDelayed(this, 1000);
}
};*/
}
private void startCallbackTimer(){
Log.d(TAG, "I get in here callback");
callbackRunnable = new Runnable(){
@Override
public void run() {
Log.d(TAG, "calling callback");
traceCWrapper.getLatestTraceResult();
callbackHandler.postDelayed(this, 1000);
}
};
callbackHandler.postDelayed(callbackRunnable, 1000);
}
private void stopCallbackTimer(){
callbackHandler.removeCallbacks(callbackRunnable);
}
//Calls TraceCWrapper upadate maps and passes the dynamic maps
/* public void updateMaps(String[] dynamicMaps){
traceCWrapper.updateMaps(dynamicMaps dynamicmaps){
}
}*/
public void stopUpdatingTrace(){
boolean stopSensors = true;
if(stopSensors){
stopUpdatingSensors();
}
//Callback Timer
stopCallbackTimer();
//State
isRunning = false;
//Trace terminate
if (_traceCDontActuallyUse == false){
traceCWrapper.terminate();
}
}
private void stopUpdatingSensors() {
//todo
//stop the event bus
//stop the service
}
@RequiresApi(api = Build.VERSION_CODES.O)
public void provideManualLocation(TraceManualLocation manualLocation){
if(isRunning){
}else{
Log.e(TAG, "Calling provideManualLocation, but is running is set to false");
}
if(!_traceCDontActuallyUse){
traceCWrapper.provideManualLocation(manualLocation);
}
}
@RequiresApi(api = Build.VERSION_CODES.O)
public void provideManualHeadingCorrection(TraceManualHeading traceManualHeading){
if(isRunning){
}else{
Log.e(TAG, "Calling provideHeadingCorrection, but is running is set to false");
}
if (!_traceCDontActuallyUse){
traceCWrapper.provideManualHeading(traceManualHeading);
}
}
public void updateParameter(TraceCVarParameter traceCVarParameter, double value){
if(isRunning){
}else{
Log.e(TAG, "Calling updateparameter, but is running is set to false");
}
//todo
//callback async
}
//Private [START]
boolean isInitialised = false;
public boolean isInitialised() {
if(!isInitialised){
}else{
//todo
//send to didfinishinitialisation? confirm isMagConsistentAtInit is true
}
return isInitialised;
}
private boolean isMagConsistantAtInit = false;
private Timer callbackTimer;
/* public traceCallBack(int seconds){
callBackTimer = new Timer();
callBackTimer.schedule(new callUpdate(), seconds*1000);
}*/
class callUpdate extends TimerTask{
@Override
public void run() {
//traceCWrapper.getLatestTraceResult();
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_trace_manager);
}
}
我没有足够的空间来添加 TraceCWrapper 文件,但库加载为:
static CLibrary lib = Native.loadLibrary("com.waymap.app.traceandroid", CLibrary.class);
作为主要示例,traceCWrapper.provideDeviceMotion() 方法在 TraceCWrapper 中接收为:
//Provide Device Motion
public static boolean provideDeviceMotion(TCIMUEvent mTCIMUEvent, int Status, double userHeadingDeg, float rotationMode){
DeviceMotion dM = new DeviceMotion();
dM.setTcimuEvent(mTCIMUEvent);
dM.setStatus(Status);
dM.setUserHeadingDeg(userHeadingDeg);
dM.setRotationMode(rotationMode);
if(isRunning) {
new sendToTraceHandleImuEvent().execute(dM);
isInitalized = true;
return isInitalized;
}else{
Log.i(TAG, "IMU update ignored as not running");
isInitalized = false;
return isInitalized;
}
}
public static class sendToTraceHandleImuEvent extends AsyncTask<DeviceMotion,Void,Void>{
@Override
protected Void doInBackground(DeviceMotion... devicemotions) {
/*public class Arg extends Structure {
public devicemotions[] var1 = new byte[9];
public devicemotions[] var2 = new byte[5];
}*/
Log.d(TAG, "InTraceCwrapper Again, provideIMU");
lib.TraceHandleImuEvent(devicemotions[0].getTcimuEvent(), devicemotions[0].getStatus(), devicemotions[0].getUserHeadingDeg(), devicemotions[0].getRotationMode());
return null;
}
}
您将不得不原谅大量的日志记录和多余的代码,因为我已经为此奋斗了一段时间。
当传递我的 TCIMUEvent 时,我使用如下结构注释:
@Structure.FieldOrder({ "time", "accel", "accelValid", "mag", "magValid", "gyro", "gyroValid", "pressure", "pressureValid", "temperature", "temperatureValid"})
public class TCIMUEvent extends Structure implements Serializable {
public double time;
public float[] accel = new float[3];
public boolean accelValid;
public float[] mag = new float[3];
public boolean magValid;
public float[] gyro = new float[3];
public boolean gyroValid;
public float pressure;
public boolean pressureValid;
public float temperature;
public boolean temperatureValid;
public TCIMUEvent(double time, float[] accel, boolean accelValid, float[] mag, boolean magValid, float[] gyro, boolean gyroValid, float pressure, boolean pressureValid, float temperature, boolean temperatureValid) {
this.time = time;
this.accel = accel;
this.accelValid = accelValid;
this.mag = mag;
this.magValid = magValid;
this.gyro = gyro;
this.gyroValid = gyroValid;
this.pressure = pressure;
this.pressureValid = pressureValid;
this.temperature = temperature;
this.temperatureValid = temperatureValid;
}
}
所需的 Java C 映射:
My Java Library to map:
void TracehandleLocationEvent(TCLocationEvent tcLocationEvent);
void TracehandleManualLocationEvent(TCManualLocationEvent tcManualLocationEvent);
void TracehandleManualHeadingEvent(TCManualHeadingEvent tcManualHeadingEvent);
void TracehandleManualInitialLocation(TCLocationEvent initialLocationEvent);
void TraceHandleImuEvent(TCIMUEvent tcimuEvent, int Status, double userHeadingDeg, float rotationMode);
void TraceGetResult(Double uptime, Pointer traceResult_out);
-------- These map retrospectively to C:---------
void TraceHandleLocationEvent (const Trace_locationSample_t *locationSample)
void TraceHandleManualLocationEvent(const Trace_manualLocationSample_t
*manualLocationSample)
void TraceHandleManualHeadingEvent(const Trace_manualHeadingSample_t
*manualHeadingSample)
void TraceHandleLocationEvent (const Trace_locationSample_t *locationSample)
void TraceHandleImuEvent(Trace_imuDataSample_t *imuDataSample, int *status,
double *userHeadingDeg, StrapdownStreaming_RotationMode *currentRotateMode)
void TraceGetResult(double time, Trace_Result_t *TraceResult)
新的映射看起来像这样,对象的结构与上面原始问题中的格式相同:
void TracehandleLocationEvent(TCLocationEvent tcLocationEvent);
void TracehandleManualLocationEvent(TCManualLocationEvent tcManualLocationEvent);
void TracehandleManualHeadingEvent(TCManualHeadingEvent tcManualHeadingEvent);
void TracehandleManualInitialLocation(TCLocationEvent initialLocationEvent);
void TraceGetResult(DoubleByReference uptime, TCResult traceResult_out);
void TraceHandleImuEvent(TCIMUEvent tcimuEvent, IntByReference status, DoubleByReference heading, FloatByReference rotationMode);
现在抛出的错误与我的 Structure 对象中的空构造函数有关:
java.lang.Error: Structure.getFieldOrder() on class com.dataTypes.TCLocationEvent returns names ([altitude, coordinate, horizontalAccuracy, timestamp, verticalAccuracy]) which do not match declared field names ([])
at com.sun.jna.Structure.getFields(Structure.java:1089)
at com.sun.jna.Structure.deriveLayout(Structure.java:1232)
at com.sun.jna.Structure.calculateSize(Structure.java:1159)
at com.sun.jna.Structure.calculateSize(Structure.java:1111)
at com.sun.jna.Structure.allocateMemory(Structure.java:414)
at com.sun.jna.Structure.<init>(Structure.java:205)
at com.sun.jna.Structure.<init>(Structure.java:193)
at com.sun.jna.Structure.<init>(Structure.java:180)
at com.sun.jna.Structure.<init>(Structure.java:172)
at com.dataTypes.TCLocationEvent.<init>(TCLocationEvent.java:30)
at com.locationGetter.LocationService.<clinit>(LocationService.java:39)
最佳答案
JNA 映射的 SIGSEGV 错误通常是由于访问不属于您的 native 内存而引起的。问题各不相同,但首先要查看的是结构类型映射和方法/函数参数映射。
作为一个具体示例(可能还有更多),您的代码包含以下映射:
void TraceHandleImuEvent(TCIMUEvent tcimuEvent, int Status,
double userHeadingDeg, float rotationMode);
但是, native 映射此处不需要 int
、double
和 float
。它需要指针:
void TraceHandleImuEvent(Trace_imuDataSample_t *imuDataSample, int *status,
double *userHeadingDeg, StrapdownStreaming_RotationMode *currentRotateMode)
(像 TCIMUEvent
这样的结构在作为参数传递时会自动映射到它们的指针,所以没问题。)
发生的情况是,您正在传递一个 int
来表示状态(例如 8),但 native 代码认为“内存位置 0x8
存储了一个整数。 ”您不拥有该内存,因此会出现错误。
IntByReference
将是此处以及许多函数参数的正确类型映射。
关于java - 了解导致信号 11 (SIGSEGV)、代码 1 (SEGV_MAPERR) 几秒钟后出现错误的 Android 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61733321/
我开始在 Ethereum blockchain 上了解如何开发智能合约以及如何写 web-script用于与智能合约交互(购买、销售、统计......)我得出了该怎么做的结论。我想知道我是否正确理解
我正在 UIView 中使用 CATransform3DMakeRotation,并且我正在尝试进行 45º,变换就像向后放置一样: 这是我拥有的“代码”,但显然没有这样做。 CATransform3
我目前正在测试 WebRTC 的功能,但我有一些脑逻辑问题。 WebRTC 究竟是什么? 我只读了“STUN”、“P2P”和其他...但是在技术方面什么是正确的 WebRTC(见下一个) 我需要什么
我在看 DelayedInit在 Scala in Depth ... 注释是我对代码的理解。 下面的 trait 接受一个非严格计算的参数(由于 => ),并返回 Unit .它的行为类似于构造函数
谁能给我指出一个用图片和简单的代码片段解释 WCF 的资源。我厌倦了谷歌搜索并在所有搜索结果中找到相同的“ABC”文章。 最佳答案 WCF 是一项非常复杂的技术,在我看来,它的文档记录非常少。启动和运
我期待以下 GetArgs.hs打印出传递给它的参数。 import System.Environment main = do args main 3 4 3 :39:1: Coul
private int vbo; private int ibo; vbo = glGenBuffers(); ibo = glGenBuffers(); glBindBuffer(GL_ARRAY_
我正在尝试一个 for 循环。我添加了一个 if 语句以在循环达到 30 时停止循环。 我见过i <= 10将运行 11 次,因为循环在达到 10 次时仍会运行。 如果有设置 i 的 if 语句,为什
我正在尝试了解 WSGI 的功能并需要一些帮助。 到目前为止,我知道它是一种服务器和应用程序之间的中间件,用于将不同的应用程序框架(位于服务器端)与应用程序连接,前提是相关框架具有 WSGI 适配器。
我是 Javascript 的新手,我正在尝试绕过 while 循环。我了解它们的目的,我想我了解它们的工作原理,但我在使用它们时遇到了麻烦。 我希望 while 值自身重复,直到两个随机数相互匹配。
我刚刚偶然发现Fabric并且文档并没有真正说明它是如何工作的。 我有根据的猜测是您需要在客户端和服务器端都安装它。 Python 代码存储在客户端,并在命令运行时通过 Fabric 的有线协议(pr
我想了解 ConditionalWeakTable .和有什么区别 class ClassA { static readonly ConditionalWeakTable OtherClass
关闭。这个问题需要更多focused .它目前不接受答案。 想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post . 5年前关闭。 Improve this questi
我还没有成功找到任何可以引导我理解 UIPickerView 和 UIPickerView 模型的好例子。有什么建议吗? 最佳答案 为什么不使用默认的 Apple 文档示例?这是来自苹果文档的名为 U
我在看foldM为了获得关于如何使用它的直觉。 foldM :: Monad m => (a -> b -> m a) -> a -> [b] -> m a 在这个简单的例子中,我只返回 [Just
答案What are _mm_prefetch() locality hints?详细说明提示的含义。 我的问题是:我想要哪一个? 我正在处理一个被重复调用数十亿次的函数,其中包含一些 int 参数。
我一直在读这个article了解 gcroot 模板。我明白 gcroot provides handles into the garbage collected heap 然后 the handle
提供了一个用例: 流处理架构;事件进入 Kafka,然后由带有 MongoDB 接收器的作业进行处理。 数据库名称:myWebsite集合:用户 并且作业接收 users 集合中的 user 记录。
你好 我想更详细地了解 NFS 文件系统。我偶然发现了《NFS 图解》这本书,不幸的是它只能作为谷歌图书提供,所以有些页面丢失了。有人可能有另一个很好的资源,这将是在较低级别上了解 NFS 的良好开始
我无法理解这个问题,哪个更随机? rand() 或: rand() * rand() 我发现这是一个真正的脑筋急转弯,你能帮我吗? 编辑: 凭直觉,我知道数学答案是它们同样随机,但我忍不住认为,如果您
我是一名优秀的程序员,十分优秀!