-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtdoa.cpp
More file actions
52 lines (40 loc) · 1.76 KB
/
tdoa.cpp
File metadata and controls
52 lines (40 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "javatoc.h"
#include <jni.h>
#include "tdoa.h"
JNIEXPORT jint
JNICALL Java_com_xlmf_feature_location_calculation_service_impl_CalServiceImpl_tdoaCalc
(JNIEnv *env, jobject obj, jobjectArray bsVec, jdoubleArray timeVec, jint numBs, jobject ms)
{
FILE *logFile = fopen("/home/zhenghao/test_xlmf/zh_xlmf.log", "a");
if (logFile == NULL) {
fprintf(stderr, "Error opening log file!\n");
return -1; // 返回错误
}
tdoa_pos_t *bs_array = (tdoa_pos_t *) malloc(numBs * sizeof(tdoa_pos_t));
tdoa_time_t *time_array = (tdoa_time_t *) malloc(numBs * sizeof(tdoa_time_t));
for (int i = 0; i < numBs; i++) {
jobject bs = env->GetObjectArrayElement(bsVec, i);
jclass cls = env->GetObjectClass(bs);
jfieldID xField = env->GetFieldID(cls, "x", "D");
jfieldID yField = env->GetFieldID(cls, "y", "D");
jfieldID zField = env->GetFieldID(cls, "z", "D");
bs_array[i].x = env->GetDoubleField(bs, xField);
bs_array[i].y = env->GetDoubleField(bs, yField);
bs_array[i].z = env->GetDoubleField(bs, zField);
}
env->GetDoubleArrayRegion(timeVec, 0, numBs, time_array);
jclass msClass = env->GetObjectClass(ms);
jfieldID fxField = env->GetFieldID(msClass, "x", "D");
jfieldID fyField = env->GetFieldID(msClass, "y", "D");
jfieldID fzField = env->GetFieldID(msClass, "z", "D");
tdoa_pos_t tmp;
jint result = VelPos::tdoa_calc_1(bs_array, time_array, numBs, &tmp);
env->SetDoubleField(ms, fxField, tmp.x);
env->SetDoubleField(ms, fyField, tmp.y);
env->SetDoubleField(ms, fzField, tmp.z);
fprintf(logFile, "cal result is: tmp.x=%f, y=%f, z=%f\n", tmp.x, tmp.y, tmp.z);
free(bs_array);
free(time_array);
fclose(logFile);
return result;
}