Browse Source

完善代码,修改代码中的缺陷

zhoutao 4 days ago
parent
commit
207c660a08

+ 15 - 4
compile.bat

@@ -10,9 +10,20 @@ if not exist "%OUTPUT_DIR%" mkdir "%OUTPUT_DIR%"
 :: 设置输出文件名  
 set "OUTPUT_FILE=%OUTPUT_DIR%\aplm8000sdk.js"  
   
-:: 设置编译器选项(如果有需要的话,可以添加优化选项、定义等)  
-set "COMPILER_OPTIONS1=-O3 -s WASM=1 -Wall -Wextra"  
-set "COMPILER_OPTIONS2=-sINITIAL_MEMORY=1024mb -sTOTAL_STACK=67108864 -sSTACK_SIZE=10485760"
+:: 设置编译器基本选项
+:: -02:2级优化,级别越高优化的越多体积越小;
+:: -flto:启用链接时优化, 在编译和链接阶段进行全局优化,可能提升代码性能
+:: -msimd128:启用 WebAssembly的SIMD(单指令多数据)指令集,允许使用 128位SIMD指令(如 i8x16、f32x4),加速向量化计算(如 FFT、图像处理)
+set "COMPILER_OPTIONS1=-O2 -flto -msimd128 -s WASM=1 -s BUILD_AS_WORKER=1 -s ENVIRONMENT='worker' -Wall -Wextra"  
+
+:: 设置编译器内存选项
+:: -s ALLOW_MEMORY_GROWTH=1:允许 WebAssembly 内存动态增长,WASM 默认内存固定大小(如 16MB),此选项允许运行时按需扩展内存
+:: -s INITIAL_MEMORY=128MB:初始化内存大小
+set "COMPILER_OPTIONS2=-s ALLOW_MEMORY_GROWTH=1 -s INITIAL_MEMORY=128MB -s TOTAL_STACK=20MB -s STACK_SIZE=2MB"
+
+::设置编译器多线程选项
+::set "COMPILER_THREAD=-s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=2 -s PROXY_TO_PTHREAD"
+
 
 ::系统入口模块
 set "MAIN=main.c"
@@ -82,7 +93,7 @@ set "UTILS=%COMPLEX% %DISTANCE% %SORT% %FFT% %LOOPLIST%"
 set "SOURCE_FILES=%MAIN% %EXCHANGE% %DEMODULATION% %BASESTATION% %LOCATION% %ROUTE% %LCT_DATA% %LCT_IMU% %SYSMAIN% %UTILS%"
 
 :: 使用emcc编译源文件  
-emcc  %SOURCE_FILES% -o %OUTPUT_FILE%  %COMPILER_OPTIONS2%
+emcc  %SOURCE_FILES% -o %OUTPUT_FILE%  %COMPILER_OPTIONS1%  %COMPILER_OPTIONS2%
 
 
 :: 检查编译是否成功,%errorlevel%是一个特殊的变量,保存了emcc命令的退出代码,要是不为0则标识失败

+ 1 - 1
main.c

@@ -45,7 +45,7 @@ void main_read_wav()
 {
     // const char *pFileName = "E:\\work\\ips8000\\aplm8000sdk\\wave\\zcq(20251203-09).wav";
     //  const char *pFileName = "E:\\work\\ips8000\\aplm8000sdk\\wave\\rec5-0-5(0245)-btsx.wav";
-    const char *pFileName = "E:\\work\\ips8000\\aplm8000sdk\\wave\\zcq_6bts_rect_0327.wav";
+    const char *pFileName = "E:\\work\\ips8000\\aplm8000sdk\\wave\\zcq_one_40mi_huawei_3bts_.wav";
     int16 *pwData = NULL; // 音频数据存储地址
     uint8 byIsOver = 0;
     uint16 wCounter = 0;

+ 0 - 2
main.h

@@ -5,8 +5,6 @@
 
 // 内部接口
 void main_module_init();
-
-void main_generate_test_data();
 void main_read_wav();
 void main_read_bin();
 void main_test_matrix();

+ 0 - 2
src/modules/basestation/bts_ampl.c

@@ -28,7 +28,6 @@ void bts_ampl_main(PUB_LOCATION_DATA_T *pstLocationDataList, BTS_AMPL_MIRROR_DAT
 
     flt32 fMaxValue = 0;
     uint16 wMaxValueIndex = 0;
-    flt32 fSnr = 0;
 
     //// 遍历基站,镜像数据(包括一秒数据和多秒数据)
     for (uint8 i = 0; i < PUB_SYS_CARRIER_NUM; i++)
@@ -121,7 +120,6 @@ void bts_ampl_main(PUB_LOCATION_DATA_T *pstLocationDataList, BTS_AMPL_MIRROR_DAT
 void bts_ampl_check_freq_valid(PUB_LOCATION_DATA_T *pstLocationData, BTS_AMPL_MIRROR_DATA_T *pstBtsAmplMirrorData)
 {
     uint16 wStartIndex = 0;
-    uint16 wMeanStartIndex = 0; // 计算均值
 
     flt32 fTmpValue = 0; // 临时变量
     flt32 *pfOneSecondData = NULL;

+ 54 - 54
src/modules/basestation/bts_main.c

@@ -60,7 +60,6 @@ int32 *bts_main_get_install_bts_list()
 void bts_main(PUB_LOCATION_DATA_T *pstLocationDataList, ROUTE_NEARBY_BTS_LIST *pstNearbyBtsList, PUB_LCT_BTS_LIST_T *pstLctBtsList)
 {
     uint8 byRemainder = 0;
-    PUB_LCT_BTS_LIST_T stLctBtsList = {0};
 
     // 镜像定位数据
     // bts_mirror_main(pstLocationDataList, gBts_astBtsAmplMirrorDataList);
@@ -252,12 +251,12 @@ void bts_main_gen_test_bts()
     pstHead->astLocalBtsList[0].dwBtsId = 10001;
     pstHead->astLocalBtsList[0].dwFreqIndex = 3;
     pstHead->astLocalBtsList[0].dwSlot = 0;
-    pstHead->astLocalBtsList[0].dwLctType = 2;
-    pstHead->astLocalBtsList[0].dwTwoBtsNum = 0;
-    pstHead->astLocalBtsList[0].adwTwoBtsList[0] = 0;
+    pstHead->astLocalBtsList[0].dwLctType = 1;
+    pstHead->astLocalBtsList[0].dwTwoBtsNum = 1;
+    pstHead->astLocalBtsList[0].adwTwoBtsList[0] = 10002;
     pstHead->astLocalBtsList[0].dwCoordX = 0;
     pstHead->astLocalBtsList[0].dwCoordY = 0;
-    pstHead->astLocalBtsList[0].dwCoordZ = 300;
+    pstHead->astLocalBtsList[0].dwCoordZ = 200;
 
     // 2号基站
     pstHead->astLocalBtsList[1].dwBuildId = 1;
@@ -265,12 +264,13 @@ void bts_main_gen_test_bts()
     pstHead->astLocalBtsList[1].dwBtsId = 10002;
     pstHead->astLocalBtsList[1].dwFreqIndex = 4;
     pstHead->astLocalBtsList[1].dwSlot = 1;
-    pstHead->astLocalBtsList[1].dwLctType = 2;
-    pstHead->astLocalBtsList[1].dwTwoBtsNum = 0;
-    pstHead->astLocalBtsList[1].adwTwoBtsList[0] = 0;
-    pstHead->astLocalBtsList[1].dwCoordX = 2500;
+    pstHead->astLocalBtsList[1].dwLctType = 1;
+    pstHead->astLocalBtsList[1].dwTwoBtsNum = 2;
+    pstHead->astLocalBtsList[1].adwTwoBtsList[0] = 10001;
+    pstHead->astLocalBtsList[1].adwTwoBtsList[1] = 10003;
+    pstHead->astLocalBtsList[1].dwCoordX = 4000;
     pstHead->astLocalBtsList[1].dwCoordY = 0;
-    pstHead->astLocalBtsList[1].dwCoordZ = 300;
+    pstHead->astLocalBtsList[1].dwCoordZ = 200;
     pstHead->astLocalBtsList[1].adwBluetoothMac[0] = 1; // 蓝牙mac0
     pstHead->astLocalBtsList[1].adwBluetoothMac[1] = 2; // 蓝牙mac1
     pstHead->astLocalBtsList[1].adwBluetoothMac[2] = 3; // 蓝牙mac2
@@ -281,53 +281,53 @@ void bts_main_gen_test_bts()
     pstHead->astLocalBtsList[2].dwBtsId = 10003;
     pstHead->astLocalBtsList[2].dwFreqIndex = 5;
     pstHead->astLocalBtsList[2].dwSlot = 2;
-    pstHead->astLocalBtsList[2].dwLctType = 2;
+    pstHead->astLocalBtsList[2].dwLctType = 1;
     pstHead->astLocalBtsList[2].dwTwoBtsNum = 0;
     pstHead->astLocalBtsList[2].adwTwoBtsList[0] = 10002;
-    pstHead->astLocalBtsList[2].dwCoordX = 5000;
+    pstHead->astLocalBtsList[2].dwCoordX = 8000;
     pstHead->astLocalBtsList[2].dwCoordY = 0;
-    pstHead->astLocalBtsList[2].dwCoordZ = 300;
-
-    // 4号基站
-    pstHead->astLocalBtsList[3].dwBuildId = 1;
-    pstHead->astLocalBtsList[3].dwLayerId = 15;
-    pstHead->astLocalBtsList[3].dwBtsId = 10004;
-    pstHead->astLocalBtsList[3].dwFreqIndex = 6;
-    pstHead->astLocalBtsList[3].dwSlot = 3;
-    pstHead->astLocalBtsList[3].dwCoordX = 5000;
-    pstHead->astLocalBtsList[3].dwCoordY = 2500;
-    pstHead->astLocalBtsList[3].dwCoordZ = 300;
-    pstHead->astLocalBtsList[3].dwLctType = 2;
-    pstHead->astLocalBtsList[3].dwTwoBtsNum = 0;
-    pstHead->astLocalBtsList[3].adwTwoBtsList[0] = 10003;
-
-    // 5号基站
-    pstHead->astLocalBtsList[4].dwBuildId = 1;
-    pstHead->astLocalBtsList[4].dwLayerId = 15;
-    pstHead->astLocalBtsList[4].dwBtsId = 10005;
-    pstHead->astLocalBtsList[4].dwFreqIndex = 7;
-    pstHead->astLocalBtsList[4].dwSlot = 0;
-    pstHead->astLocalBtsList[4].dwCoordX = 2500;
-    pstHead->astLocalBtsList[4].dwCoordY = 2500;
-    pstHead->astLocalBtsList[4].dwCoordZ = 300;
-    pstHead->astLocalBtsList[4].dwLctType = 2;
-    pstHead->astLocalBtsList[4].dwTwoBtsNum = 0;
-    pstHead->astLocalBtsList[4].adwTwoBtsList[0] = 10003;
-
-    // 6号基站
-    pstHead->astLocalBtsList[5].dwBuildId = 1;
-    pstHead->astLocalBtsList[5].dwLayerId = 15;
-    pstHead->astLocalBtsList[5].dwBtsId = 10006;
-    pstHead->astLocalBtsList[5].dwFreqIndex = 2;
-    pstHead->astLocalBtsList[5].dwSlot = 1;
-    pstHead->astLocalBtsList[5].dwCoordX = 0;
-    pstHead->astLocalBtsList[5].dwCoordY = 2500;
-    pstHead->astLocalBtsList[5].dwCoordZ = 300;
-    pstHead->astLocalBtsList[5].dwLctType = 2;
-    pstHead->astLocalBtsList[5].dwTwoBtsNum = 0;
-    pstHead->astLocalBtsList[5].adwTwoBtsList[0] = 10003;
-
-    pstHead->dwBtsNum = 6;
+    pstHead->astLocalBtsList[2].dwCoordZ = 200;
+
+    // // 4号基站
+    // pstHead->astLocalBtsList[3].dwBuildId = 1;
+    // pstHead->astLocalBtsList[3].dwLayerId = 15;
+    // pstHead->astLocalBtsList[3].dwBtsId = 10004;
+    // pstHead->astLocalBtsList[3].dwFreqIndex = 6;
+    // pstHead->astLocalBtsList[3].dwSlot = 3;
+    // pstHead->astLocalBtsList[3].dwCoordX = 5000;
+    // pstHead->astLocalBtsList[3].dwCoordY = 2500;
+    // pstHead->astLocalBtsList[3].dwCoordZ = 300;
+    // pstHead->astLocalBtsList[3].dwLctType = 2;
+    // pstHead->astLocalBtsList[3].dwTwoBtsNum = 0;
+    // pstHead->astLocalBtsList[3].adwTwoBtsList[0] = 10003;
+
+    // // 5号基站
+    // pstHead->astLocalBtsList[4].dwBuildId = 1;
+    // pstHead->astLocalBtsList[4].dwLayerId = 15;
+    // pstHead->astLocalBtsList[4].dwBtsId = 10005;
+    // pstHead->astLocalBtsList[4].dwFreqIndex = 7;
+    // pstHead->astLocalBtsList[4].dwSlot = 0;
+    // pstHead->astLocalBtsList[4].dwCoordX = 2500;
+    // pstHead->astLocalBtsList[4].dwCoordY = 2500;
+    // pstHead->astLocalBtsList[4].dwCoordZ = 300;
+    // pstHead->astLocalBtsList[4].dwLctType = 2;
+    // pstHead->astLocalBtsList[4].dwTwoBtsNum = 0;
+    // pstHead->astLocalBtsList[4].adwTwoBtsList[0] = 10003;
+
+    // // 6号基站
+    // pstHead->astLocalBtsList[5].dwBuildId = 1;
+    // pstHead->astLocalBtsList[5].dwLayerId = 15;
+    // pstHead->astLocalBtsList[5].dwBtsId = 10006;
+    // pstHead->astLocalBtsList[5].dwFreqIndex = 2;
+    // pstHead->astLocalBtsList[5].dwSlot = 1;
+    // pstHead->astLocalBtsList[5].dwCoordX = 0;
+    // pstHead->astLocalBtsList[5].dwCoordY = 2500;
+    // pstHead->astLocalBtsList[5].dwCoordZ = 300;
+    // pstHead->astLocalBtsList[5].dwLctType = 2;
+    // pstHead->astLocalBtsList[5].dwTwoBtsNum = 0;
+    // pstHead->astLocalBtsList[5].adwTwoBtsList[0] = 10003;
+
+    pstHead->dwBtsNum = 3;
 }
 
 // 显示安装基站

+ 0 - 1
src/modules/basestation/bts_sync.c

@@ -505,7 +505,6 @@ void bts_sync_cal_slot_sync_offset(uint8 *pbySignalSoltList, uint8 byBtsSetSlot,
 {
     uint8 byZeroSlotIndex = 0;
     uint8 byBtsSlotIndex = 0;
-    int8 byIndexGap = 0; // 与0号时隙的的间隔
 
     // 抽取时隙索引
     for (uint8 i = 0; i < PUB_SYS_SLOT_NUM; i++)

+ 2 - 4
src/modules/basestation/bts_track.c

@@ -27,8 +27,6 @@ void bts_track_by_main(BTS_AMPL_MIRROR_DATA_T *pstBtsAmplMirrorDataList, PUB_LOC
     BTS_INSTALL_BTS_T *pstInstallBtsData = NULL;
 
     PUB_LCT_BTS_T stMainBts = {0}; // 主站
-    uint8 byFreqIndex = 0;
-    uint8 byBtsFlag = 0;
 
     // 当前帧不需要跟踪基站
     byRemainder = dwFrameNo % PUB_SYS_SLOT_NUM;
@@ -107,7 +105,7 @@ void bts_track_gen_location_bts_by_main_bts(PUB_LCT_BTS_T stMainBts, BTS_INSTALL
         {
             // 检查两个基站间的距离是否满足要求
             fDistance = bts_track_cal_pp_distance(stMainBts.dwCoordX, stMainBts.dwCoordY, stSlaveBts.dwCoordX, stSlaveBts.dwCoordY);
-            if (fDistance <= PUB_BTS_VALID_DISTANCE) // 距离合法
+            if (fDistance <= PUB_BTS_VALID_DISTANCE_THRES) // 距离合法
             {
                 stTmpBts.dwMainBtsFlag = 2; // 从站
                 stTmpBts.dwBuildId = stSlaveBts.dwBuildId;
@@ -176,7 +174,7 @@ void bts_track_by_coord(PUB_CURRENT_LCT_RESULT_T stCurrentLctPoint, PUB_LCT_BTS_
         {
             // 计算当前定位点与该安装基站间的距离
             fDistance = bts_track_cal_pp_distance(stCurrentLctPoint.stCoord.dwX, stCurrentLctPoint.stCoord.dwY, stInstallBts.dwCoordX, stInstallBts.dwCoordY);
-            if (fDistance <= PUB_BTS_VALID_DISTANCE) // 距离合法
+            if (fDistance <= PUB_BTS_VALID_DISTANCE_THRES) // 距离合法
             {
                 stTmpBts.dwMainBtsFlag = 2; // 从站
                 stTmpBts.dwBuildId = stInstallBts.dwBuildId;

+ 2 - 6
src/modules/imu/imu.c

@@ -22,13 +22,13 @@ void imu_init()
     memset(&gImu_afAccDataList, 0, sizeof(flt32) * IMU_ACC_LIST_LEN);
 
     // 加速度噪声
-    gImu_stInitParam.fNoiseX = -0.0057304;
+    gImu_stInitParam.fNoiseX = -0.0047304;
     gImu_stInitParam.fNoiseY = 0.047326;  // 0.057326
     gImu_stInitParam.fNoiseZ = -0.015313; //-0.984687
 
     // 选峰参数
     gImu_stInitParam.dwPeakPeakDistance = 35; // 35; // 峰间距
-    gImu_stInitParam.dwPeakValueThres = 102;  // 102; // 峰值门限
+    gImu_stInitParam.dwPeakValueThres = 100;  // 100为了适配苹果手机  // 102; // 峰值门限
 
     printf("imu init ok \n");
 
@@ -109,7 +109,6 @@ void imu_save_acc_xyz(uint32 dwAccListLen)
 uint32 imu_cal_distance_lct()
 {
     uint8 byMoveFlag = 0;
-    uint8 byEndIndex = 0;
 
     if (!gImu_byRunFlag)
     {
@@ -126,12 +125,9 @@ uint32 imu_cal_distance_lct()
 uint32 imu_cal_distance()
 {
     uint8 byResult = 0;
-    uint32 dwStartTimestamp = 0;                            // 开始时间戳头,队列往前推1.25秒
     flt32 afAccDataList[IMU_ACC_LIST_ONE_SECOND_LEN] = {0}; // 有效加速度点队列(1秒)
     uint8 byAccDataListLen = 0;                             // 有效加速度点队列长度
 
-    uint8 byPeakValueIndexListLen = 0;
-
     uint8 byMoveFlag = 0;
 
     // 系统处于初始化阶段

+ 1 - 1
src/modules/lctdata/lctdata.c

@@ -112,7 +112,7 @@ void lctdata_update_lct_data_by_lct_coord(PUB_LOCATION_DATA_T *pstLctDataList, P
             {
                 // 计算定位坐标点到安装基站之间的距离
                 fDistance = util_distance_cal_p2p_distance(pstLctResult->stCoord.dwX, pstLctResult->stCoord.dwY, pstOneInstallBts->dwCoordX, pstOneInstallBts->dwCoordY);
-                if (fDistance <= PUB_BTS_VALID_DISTANCE)
+                if (fDistance <= PUB_BTS_VALID_DISTANCE_THRES)
                 { // 距离有效
                     stLctBtsList.astLocationBts[byBtsCounter].dwFreqIndex = pstOneInstallBts->dwFreqIndex;
                     stLctBtsList.astLocationBts[byBtsCounter].dwBtsId = pstOneInstallBts->dwBtsId;

+ 1 - 3
src/modules/location/lct_coordcal.c

@@ -176,7 +176,6 @@ void lct_coordcal_select_valid_bts_by_fp_and_ampl(PUB_LOCATION_DATA_T *pstLctDat
 {
     LCT_FIRSTPATH_T stBtsFirstPath = {0};
     LCT_FIRSTPATH_T *pststBtsFirstPath = NULL;
-    LCT_FIRSTPATH_T *pststTmpFirstPath = NULL;
 
     PUB_LOCATION_DATA_T *pstLctData = NULL;
     uint8 byFreqIndex = 0;
@@ -663,8 +662,7 @@ void lct_coordcal_prediction_coord(COORD_T *pstPredictionCoord, uint8 *pbyPredic
 {
     LCT_COORDSEL_MEAN_COORD_T *pstData = (LCT_COORDSEL_MEAN_COORD_T *)&gLct_stMeanLctCoordList; // 定位点队列
     uint8 byMeanListLen = pstData->byListLen;                                                   // 定位点队列长度
-    LCT_COORDSEL_ORIGINAL_COORD_T *pstOriginalLctCoordList = &gLct_stOriginalLctCoordList;
-    uint8 byOriginalListLen = pstOriginalLctCoordList->byListLen;
+    // LCT_COORDSEL_ORIGINAL_COORD_T *pstOriginalLctCoordList = &gLct_stOriginalLctCoordList;
 
     flt32 fDisX = 0;
     flt32 fDisY = 0;

+ 168 - 57
src/modules/location/lct_coordcal_one.c

@@ -33,15 +33,8 @@ void lct_coordcal_one_dimension_location(PUB_LOCATION_DATA_T *pstLctDataList, ui
     LCT_LINEAR_MINIMUM_LIST_T stLinearMinmumList = {0};
 
     uint8 byCounter = 0;
-    LCT_FIRSTPATH_T astValidBtsList[2] = {0};     // 1维基站对
-    uint8 byValidBtsNum = 0;                      // 有效基站数量
-    LCT_FIRSTPATH_T *pstMainBtsFirstPaht = NULL;  // 主站
-    LCT_FIRSTPATH_T *pstSlaveBtsFirstPaht = NULL; // 从站
-
-    PUB_LOCATION_DATA_T *pstLctData = NULL;
-    uint8 byFreqIndex = 0;
-    int16 wIndexGap = 0;
-    COORD_T stAheadCoord = {0}; // 上一个点坐标
+    LCT_FIRSTPATH_T astValidBtsList[2] = {0}; // 1维基站对
+    uint8 byValidBtsNum = 0;                  // 有效基站数量
 
     uint16 wPoints = 0;
     uint16 wRefPointMatrixRow = 0; // 参考点矩阵行
@@ -63,7 +56,8 @@ void lct_coordcal_one_dimension_location(PUB_LOCATION_DATA_T *pstLctDataList, ui
     }
 
     // 组织1维基站对(两个基站为1对)
-    lct_coordcal_organize_one_dimension_bts_duad(byFirstPathFlag, pstValidBtsList, byValidBtsListLen, &stBtsDuadList);
+    // lct_coordcal_organize_one_dimension_bts_duad(byFirstPathFlag, pstValidBtsList, byValidBtsListLen, &stBtsDuadList);
+    lct_coordcal_one_organize_bts_duad(byFirstPathFlag, pstValidBtsList, byValidBtsListLen, &stBtsDuadList);
 
     // 计算线性定位参考点
     stLinearMinmumList.byValidFlag = 0;
@@ -81,7 +75,7 @@ void lct_coordcal_one_dimension_location(PUB_LOCATION_DATA_T *pstLctDataList, ui
         // 基站2
         stSecondCoord.dwX = astValidBtsList[1].dwCoordX;
         stSecondCoord.dwY = astValidBtsList[1].dwCoordY;
-        stFirstCoord.dwZ = astValidBtsList[1].dwCoordZ;
+        stSecondCoord.dwZ = astValidBtsList[1].dwCoordZ;
 
         // 系统处于跟踪阶段
         wPoints = 0;
@@ -90,7 +84,7 @@ void lct_coordcal_one_dimension_location(PUB_LOCATION_DATA_T *pstLctDataList, ui
             // 两基站
             if (stBtsDuadData.byBtsNum == 2)
             {
-                byTwoBtsLctFlag = 1; // 两站定位标识符
+                // byTwoBtsLctFlag = 1; // 两站定位标识符
 
                 // 检查预测坐标是否在一维基站内部
                 byInsideFlag = lct_coordcal_check_one_dimension_inside(stFirstCoord, stSecondCoord, stPredictionCoord);
@@ -111,6 +105,8 @@ void lct_coordcal_one_dimension_location(PUB_LOCATION_DATA_T *pstLctDataList, ui
                     // 两个基站有效,进行1维定位
                     if (byValidBtsNum == 2)
                     {
+                        byTwoBtsLctFlag++;
+
                         // 生成线性参考点
                         lct_coordcal_build_linear_ref_point(byPredictionFlag, stPredictionCoord, stFirstCoord, stSecondCoord, &stLinearFunc, gLct_astLocationRefPoint, &wRefPointMatrixRow, &wRefPointMatrixCol);
                         wPoints = wRefPointMatrixRow * wRefPointMatrixCol; // 定位参考点数量
@@ -132,13 +128,6 @@ void lct_coordcal_one_dimension_location(PUB_LOCATION_DATA_T *pstLctDataList, ui
                             if (byResult)
                             {
                                 wPoints = 1;
-
-                                // 二次校验定位坐标
-
-                                // // 调整无效基站的第一径
-                                // pstMainBtsFirstPaht = &astValidBtsList[0];
-                                // pstSlaveBtsFirstPaht = &pstValidBtsList[1];
-                                // lct_coordcal_adjust_first_path_index(pstLctDataList, byFirstPathFlag, &stSelRefPoint, pstMainBtsFirstPaht, pstSlaveBtsFirstPaht);
                             }
                         }
                     }
@@ -166,7 +155,7 @@ void lct_coordcal_one_dimension_location(PUB_LOCATION_DATA_T *pstLctDataList, ui
             // 两级站定位
             if (stBtsDuadData.byBtsNum == 2)
             {
-                byTwoBtsLctFlag = 1; // 两站定位标识符
+                byTwoBtsLctFlag++;
 
                 // 构建1维定位的线性方程
                 lct_coordcal_build_linear_func(stFirstCoord, stSecondCoord, &stLinearFunc);
@@ -234,12 +223,11 @@ void lct_coordcal_one_dimension_location(PUB_LOCATION_DATA_T *pstLctDataList, ui
     // 校验定位坐标合法性
     if (byFirstPathFlag == CAL_PATH)
     {
-        // 校验计算径结果
-        lct_coordcal_check_linear_lct_coord_valid(1, &stLinearMinmumList);
-
         // 保存输出参数
         if (stLinearMinmumList.byCalMinimumListLen > 0)
         {
+            lct_coordcal_check_linear_lct_coord_valid(1, &stLinearMinmumList); // 校验计算径结果
+
             pstMinmumValueList->byLinearCalMinimumListLen = 1;
             pstMinmumValueList->astLinearCalMinimumList[0].stCoord = stLinearMinmumList.astCalMinimumList[0].stCoord;
             pstMinmumValueList->astLinearCalMinimumList[0].fDelayDeviationSum = stLinearMinmumList.astCalMinimumList[0].fDelayDeviationSum;
@@ -247,12 +235,11 @@ void lct_coordcal_one_dimension_location(PUB_LOCATION_DATA_T *pstLctDataList, ui
     }
     else
     {
-        // 校验跟踪径结果
-        lct_coordcal_check_linear_lct_coord_valid(2, &stLinearMinmumList);
-
         // 保存输出参数
         if (stLinearMinmumList.byTrackMinimumListLen > 0)
         {
+            lct_coordcal_check_linear_lct_coord_valid(2, &stLinearMinmumList); // 校验跟踪径结果
+
             pstMinmumValueList->byLinearTrackMinimumListLen = 1;
             pstMinmumValueList->astLinearTrackMinimumList[0].stCoord = stLinearMinmumList.astTrackMinimumList[0].stCoord;
             pstMinmumValueList->astLinearTrackMinimumList[0].fDelayDeviationSum = stLinearMinmumList.astTrackMinimumList[0].fDelayDeviationSum;
@@ -262,6 +249,114 @@ void lct_coordcal_one_dimension_location(PUB_LOCATION_DATA_T *pstLctDataList, ui
     return;
 }
 
+// 组织1维基站对(2个基站为1对)
+// byFirstPathType:第一径类型,0:计算径,1:跟踪径
+// pstValidBtsList:有效基站队列
+// byValidBtsListLen:有效基站队列长度
+// pstBtsDuadList:基站对队列
+void lct_coordcal_one_organize_bts_duad(uint8 byFirstPathType, LCT_FIRSTPATH_T *pstValidBtsList, uint8 byValidBtsListLen, LCT_COORDCAL_ONE_DIMENSION_BTS_DUAD_LIST_T *pstBtsDuadList)
+{
+    uint8 byBtsDuadCounter = 0; // 计算对计数器
+    LCT_COORDCAL_ONE_DIMENSION_BTS_DUAD_T stBtsDuadData = {0};
+
+    LCT_FIRSTPATH_T *pstMainBtsPath = NULL;
+    uint32 dwMainBtsId = 0;
+
+    LCT_FIRSTPATH_T *pstSlaveBtsPath = NULL;
+    uint32 dwSlaveBtsId = 0;
+
+    flt32 fSnr = 0;
+    flt32 fMaxValue = 0;
+
+    // 组织1维基站对(两个基站为1对)
+    for (uint8 i = 0; i < byValidBtsListLen; i++)
+    {
+        pstMainBtsPath = &pstValidBtsList[i];  // 主站第一径数
+        dwMainBtsId = pstMainBtsPath->dwBtsId; // 主站ID
+
+        // 主站定位类型,1:1维定位,2:二维定位,3:1维和2维定位
+        fSnr = 0;
+        fMaxValue = 0;
+        if (pstMainBtsPath->dwLctType == 1 || pstMainBtsPath->dwLctType == 3)
+        {
+            fMaxValue = pstMainBtsPath->fMaxAmplValue; // 最大值
+
+            // 保存基站snr
+            if (byFirstPathType == CAL_PATH)
+            {
+                fSnr = pstMainBtsPath->fCalPathIndexSnr;
+            }
+            else
+            {
+                fSnr = pstMainBtsPath->fTrackPathIndexSnr;
+            }
+
+            // 遍历要与主站进行两站定位的从站
+            for (uint8 j = 0; j < pstMainBtsPath->dwTwoBtsNum; j++)
+            {
+                dwSlaveBtsId = pstMainBtsPath->adwTwoBtsList[j]; // 从站ID
+                for (uint8 k = i + 1; k < byValidBtsListLen; k++)
+                {
+                    pstSlaveBtsPath = &pstValidBtsList[k]; // 从站第一径数据
+                    if (pstSlaveBtsPath->dwBtsId == dwSlaveBtsId)
+                    {
+                        pstBtsDuadList->astBtsDuadList[byBtsDuadCounter].dwFirstBtsId = dwMainBtsId;
+                        pstBtsDuadList->astBtsDuadList[byBtsDuadCounter].dwSecondBtsId = dwSlaveBtsId;
+                        pstBtsDuadList->astBtsDuadList[byBtsDuadCounter].byBtsNum = 2;
+                        memcpy(&pstBtsDuadList->astBtsDuadList[byBtsDuadCounter].astBtsList[0], pstMainBtsPath, sizeof(LCT_FIRSTPATH_T));
+                        memcpy(&pstBtsDuadList->astBtsDuadList[byBtsDuadCounter].astBtsList[1], pstSlaveBtsPath, sizeof(LCT_FIRSTPATH_T));
+
+                        // 修改主站标识符
+                        pstBtsDuadList->astBtsDuadList[byBtsDuadCounter].astBtsList[0].byMainFlag = 0;
+                        pstBtsDuadList->astBtsDuadList[byBtsDuadCounter].astBtsList[1].byMainFlag = 0;
+                        if (pstBtsDuadList->astBtsDuadList[byBtsDuadCounter].astBtsList[0].fCalPathIndexSnr > pstBtsDuadList->astBtsDuadList[byBtsDuadCounter].astBtsList[1].fCalPathIndexSnr)
+                        {
+                            pstBtsDuadList->astBtsDuadList[byBtsDuadCounter].astBtsList[0].byMainFlag = 1;
+                        }
+                        else
+                        {
+                            pstBtsDuadList->astBtsDuadList[byBtsDuadCounter].astBtsList[1].byMainFlag = 1;
+                        }
+
+                        // 保存基站snr
+                        if (byFirstPathType == CAL_PATH)
+                        {
+                            fSnr += pstSlaveBtsPath->fCalPathIndexSnr;
+                            fMaxValue += pstSlaveBtsPath->fMaxAmplValue;
+                        }
+                        else
+                        {
+                            fSnr += pstSlaveBtsPath->fTrackPathIndexSnr;
+                            fMaxValue += pstSlaveBtsPath->fMaxAmplValue;
+                        }
+                        pstBtsDuadList->astBtsDuadList[byBtsDuadCounter].fSnr = fSnr;
+                        pstBtsDuadList->astBtsDuadList[byBtsDuadCounter].fAmplMaxValue = fMaxValue;
+
+                        pstBtsDuadList->byBtsDuadNum++;
+                        byBtsDuadCounter++;
+                    }
+                }
+            }
+        }
+    }
+
+    // 对最大值进行排序
+    for (uint8 i = 0; i < pstBtsDuadList->byBtsDuadNum; i++)
+    {
+        for (uint8 j = i + 1; j < pstBtsDuadList->byBtsDuadNum; j++)
+        {
+            if (pstBtsDuadList->astBtsDuadList[j].fAmplMaxValue > pstBtsDuadList->astBtsDuadList[i].fAmplMaxValue)
+            {
+                stBtsDuadData = pstBtsDuadList->astBtsDuadList[i];
+                pstBtsDuadList->astBtsDuadList[i] = pstBtsDuadList->astBtsDuadList[j];
+                pstBtsDuadList->astBtsDuadList[j] = stBtsDuadData;
+            }
+        }
+    }
+
+    return;
+}
+
 // 组织1维基站对(2个基站为1对)
 // byFirstPathType:第一径类型,0:计算径,1:跟踪径
 // pstValidBtsList:有效基站队列
@@ -477,11 +572,6 @@ void lct_coordcal_check_one_dimension_bts_firstpath_valid(uint8 byPredictionFlag
     uint16 wIndexGap = 0;
     uint8 byCounter = 0;
 
-    COORD_T stFirstBts = {0}; // 第一个基站坐标
-    flt32 fDistFirstBts = 0;
-    COORD_T stSecondBts = {0}; // 第二个基站坐标
-    flt32 fDistSecondBts = 0;
-
     // 检查基站有效性
     for (uint8 i = 0; i < 2; i++)
     {
@@ -677,8 +767,6 @@ void lct_coordcal_build_linear_func(COORD_T stBts1Coord, COORD_T stBts2Coord, LC
 // pstCoord:坐标
 void lct_coordcal_recal_linear_ref_point(LCT_COORDCAL_LINEAR_FUNC_T *pstLinearFunc, COORD_T *pstCoord)
 {
-    int32 dwTmpCoord = 0;
-
     //// 二次修正极小值
     // 不垂直于坐标轴
     if (pstLinearFunc->byVerticalFlag == 0)
@@ -770,13 +858,10 @@ void lct_coordcal_check_linear_lct_coord_valid(uint8 byMinmumValueType, LCT_LINE
 
     LCT_LINEAR_LCT_COORD_T astLinearLctCoord[LCT_MINIMUM_NUM] = {0};
     uint8 byCounter = 0;
-    COORD_T stCoord = {0};
     flt32 fDeviation = 0;
-    flt32 fMinDeviation = FLT_MAX;
     uint8 byMinIndex = 0;
     flt32 fX = 0;
     flt32 fY = 0;
-    flt32 fZ = 0;
 
     // 极小值长度
     if (byMinmumValueType == 1)
@@ -1099,7 +1184,7 @@ uint8 lct_coordcal_zero_dimension_location(PUB_LOCATION_DATA_T *pstLctDataList,
     flt32 fOffsetDistanceX = 0; // X轴偏移距离
     flt32 fOffsetDistanceY = 0; // X轴偏移距离
     flt32 fFactor = 0;
-    uint8 byResult = 0;
+    uint8 byResult = 0; // 返回结果
 
     // 平滑坐标队列中有数据
     if (gLct_stMeanLctCoordList.byListLen > 0)
@@ -1142,18 +1227,20 @@ uint8 lct_coordcal_zero_dimension_location(PUB_LOCATION_DATA_T *pstLctDataList,
             // 轴速度不为0
             if (gLct_dwSpeedY != 0 && gLct_dwSpeedX != 0)
             {
-                fFactor = abs(gLct_dwSpeedY) / abs(gLct_dwSpeedX);
-                fOffsetDistance = fOffsetDistance * fOffsetDistance;
-                fOffsetDistance /= fFactor * fFactor + 1;
+                fFactor = (flt32)(abs(gLct_dwSpeedY)) / abs(gLct_dwSpeedX);
+                // fOffsetDistance = fOffsetDistance * fOffsetDistance;
+                // fOffsetDistance /= fFactor * fFactor + 1;
 
-                fOffsetDistanceX = fOffsetDistance;
                 fOffsetDistanceY = fOffsetDistance * fFactor;
+                fOffsetDistanceX = fOffsetDistance * (1 - fFactor);
             }
+            // X轴速度为0
             else if (gLct_dwSpeedX == 0)
             {
                 fOffsetDistanceX = 0;
                 fOffsetDistanceY = fOffsetDistance;
             }
+            // Y轴速度为0
             else if (gLct_dwSpeedY == 0)
             {
                 fOffsetDistanceX = fOffsetDistance;
@@ -1167,27 +1254,43 @@ uint8 lct_coordcal_zero_dimension_location(PUB_LOCATION_DATA_T *pstLctDataList,
                 // X轴轴距大
                 if (pstLinearFunc->byDirection == 1)
                 {
-                    stAheadCoord.dwX += gLct_byDirectionX * fOffsetDistanceX; // 移动距离是Y轴的3倍
-                    stAheadCoord.dwY = pstLinearFunc->fK * stAheadCoord.dwX + pstLinearFunc->fB;
+                    if (gLct_byDirectionX != 0)
+                    {
+                        stAheadCoord.dwX += gLct_byDirectionX * fOffsetDistanceX; // 移动距离是Y轴的3倍
+                        stAheadCoord.dwY = pstLinearFunc->fK * stAheadCoord.dwX + pstLinearFunc->fB;
+                        byResult = 1;
+                    }
                 }
                 // Y轴轴距大
                 else
                 {
-                    stAheadCoord.dwY += gLct_byDirectionY * fOffsetDistanceY; // 移动距离是X轴的3倍
-                    stAheadCoord.dwX = (int32)(stAheadCoord.dwY - pstLinearFunc->fB) / pstLinearFunc->fK;
+                    if (gLct_byDirectionY != 0)
+                    {
+                        stAheadCoord.dwY += gLct_byDirectionY * fOffsetDistanceY; // 移动距离是X轴的3倍
+                        stAheadCoord.dwX = (int32)(stAheadCoord.dwY - pstLinearFunc->fB) / pstLinearFunc->fK;
+                        byResult = 1;
+                    }
                 }
             }
             // 垂直于X坐标轴
             else if (pstLinearFunc->byVerticalFlag == 1)
             {
-                stAheadCoord.dwX = pstLinearFunc->dwValueCoordX;
-                stAheadCoord.dwY += gLct_byDirectionY * fOffsetDistanceY;
+                if (gLct_byDirectionY != 0)
+                {
+                    stAheadCoord.dwX = pstLinearFunc->dwValueCoordX;
+                    stAheadCoord.dwY += gLct_byDirectionY * fOffsetDistanceY;
+                    byResult = 1;
+                }
             }
             // 垂直于Y坐标轴
             else if (pstLinearFunc->byVerticalFlag == 2)
             {
-                stAheadCoord.dwX += gLct_byDirectionX * fOffsetDistanceX;
-                stAheadCoord.dwY = pstLinearFunc->dwValueCoordY;
+                if (gLct_byDirectionX != 0)
+                {
+                    stAheadCoord.dwX += gLct_byDirectionX * fOffsetDistanceX;
+                    stAheadCoord.dwY = pstLinearFunc->dwValueCoordY;
+                    byResult = 1;
+                }
             }
         }
         // 第一径偏移量无效
@@ -1198,20 +1301,22 @@ uint8 lct_coordcal_zero_dimension_location(PUB_LOCATION_DATA_T *pstLctDataList,
             {
                 stAheadCoord.dwX += gLct_dwSpeedX;
                 stAheadCoord.dwY += gLct_dwSpeedY;
+                byResult = 1;
             }
             else if (gLct_byDirectionX != 0)
             {
                 stAheadCoord.dwX += gLct_dwSpeedX;
+                byResult = 1;
             }
             else if (gLct_byDirectionY != 0)
             {
                 stAheadCoord.dwY += gLct_dwSpeedY;
+                byResult = 1;
             }
         }
 
         // 保存数据
         memcpy(pstRefPoint, &stAheadCoord, sizeof(COORD_T));
-        byResult = 1;
     }
 
     return byResult;
@@ -1233,8 +1338,8 @@ void lct_coordcal_adjust_first_path_index(PUB_LOCATION_DATA_T *pstLctDataList, u
     fSlaveBtsDist = util_distance_cal_p2p_distance(pstLctCoord->dwX, pstLctCoord->dwY, pstSlaveBtsFirstPath->dwCoordX, pstSlaveBtsFirstPath->dwCoordY);
 
     // 基站从站帧内索引
-    fTimeDelay = ((fMainBtsDist - fSlaveBtsDist) / 343) * 1000 * 1000; // 单位微妙
-    dwIndexDiff = (fTimeDelay * 48) / 1000;                            // 相位差
+    fTimeDelay = ((fMainBtsDist - fSlaveBtsDist) / PUB_AUDIO_SPEED) * 1000 * 1000; // 单位微妙
+    dwIndexDiff = (fTimeDelay * 48) / 1000;                                        // 相位差
 
     // 修正从站第一径索引
     byFreqIndex = pstSlaveBtsFirstPath->byFreqIndex;
@@ -1267,7 +1372,7 @@ uint8 lct_coordcal_single_bts_location(PUB_LOCATION_DATA_T *pstLctDataList, LCT_
     flt32 fOffsetDistance = 0; // 前后两点偏移距离
     uint8 byMoveDirection = 0; // 1:X轴,2:Y轴
     COORD_T stAheadCoord = {0};
-    uint8 byResult = 0;
+    uint8 byResult = 0; // 返回结果
 
     // 平滑坐标队列中至少有2个点
     if (gLct_stMeanLctCoordList.byListLen > 1)
@@ -1305,12 +1410,13 @@ uint8 lct_coordcal_single_bts_location(PUB_LOCATION_DATA_T *pstLctDataList, LCT_
         if (byValidFlag)
         {
             fOffsetDistance = abs(wIndexGap) * 0.7; // 偏移距离,可正也可负
-            if (fOffsetDistance > 250 || fOffsetDistance < 150)
+            if (fOffsetDistance > 250 || fOffsetDistance < 120)
             {
-                fOffsetDistance = 200;
+                fOffsetDistance = 185;
             }
 
-            // 计算定位点坐标
+            //// 计算定位点坐标
+            // 在X轴与Y轴上都有移动
             if (gLct_byDirectionX != 0 && gLct_byDirectionY != 0)
             {
                 fOffsetDistance = fOffsetDistance * fOffsetDistance;
@@ -1329,14 +1435,17 @@ uint8 lct_coordcal_single_bts_location(PUB_LOCATION_DATA_T *pstLctDataList, LCT_
                     stAheadCoord.dwX += gLct_byDirectionX * fOffsetDistance;
                     stAheadCoord.dwY += gLct_byDirectionY * fOffsetDistance * 3; // 移动距离是X轴的3倍
                 }
+                byResult = 1;
             }
             else if (gLct_byDirectionX != 0)
             {
                 stAheadCoord.dwX += gLct_byDirectionX * fOffsetDistance;
+                byResult = 1;
             }
             else if (gLct_byDirectionY != 0)
             {
                 stAheadCoord.dwY += gLct_byDirectionY * fOffsetDistance;
+                byResult = 1;
             }
         }
         // 第一径偏移量无效
@@ -1347,20 +1456,22 @@ uint8 lct_coordcal_single_bts_location(PUB_LOCATION_DATA_T *pstLctDataList, LCT_
             {
                 stAheadCoord.dwX += gLct_dwSpeedX;
                 stAheadCoord.dwY += gLct_dwSpeedY;
+                byResult = 1;
             }
             else if (gLct_byDirectionX != 0)
             {
                 stAheadCoord.dwX += gLct_dwSpeedX;
+                byResult = 1;
             }
             else if (gLct_byDirectionY != 0)
             {
                 stAheadCoord.dwY += gLct_dwSpeedY;
+                byResult = 1;
             }
         }
 
         // 保存数据
         memcpy(pstRefPoint, &stAheadCoord, sizeof(COORD_T));
-        byResult = 1;
     }
 
     return byResult;

+ 1 - 0
src/modules/location/lct_coordcal_one.h

@@ -11,6 +11,7 @@
 
 // 一维定位
 void lct_coordcal_one_dimension_location(PUB_LOCATION_DATA_T *pstLctDataList, uint8 byPredictionFlag, COORD_T stPredictionCoord, LCT_FIRSTPATH_T *pstValidBtsList, uint8 byValidBtsListLen, uint8 byTrackCoordFlag, LCT_MINIMUM_VALUE_GROUP_T *pstMinmumValueList);
+void lct_coordcal_one_organize_bts_duad(uint8 byFirstPathType, LCT_FIRSTPATH_T *pstValidBtsList, uint8 byValidBtsListLen, LCT_COORDCAL_ONE_DIMENSION_BTS_DUAD_LIST_T *pstBtsDuadList);
 void lct_coordcal_organize_one_dimension_bts_duad(uint8 byFirstPathType, LCT_FIRSTPATH_T *pstValidBtsList, uint8 byValidBtsListLen, LCT_COORDCAL_ONE_DIMENSION_BTS_DUAD_LIST_T *pstBtsDuadList);
 void lct_coordcal_check_one_dimension_bts_firstpath_valid(uint8 byPredictionFlag, COORD_T stPredictionCoord, PUB_LOCATION_DATA_T *pstLctDataList, uint8 byFirstpathFlag, LCT_FIRSTPATH_T *pstValidBtsList, uint8 *pbyValidBtsCounter);
 uint8 lct_coordcal_check_one_dimension_inside(COORD_T stBts1Coord, COORD_T stBts2Coord, COORD_T stPredictionCoord);

+ 6 - 8
src/modules/location/lct_coordcal_two.c

@@ -283,7 +283,7 @@ void lct_coordcal_cal_ref_point_delay_deviation_with_tdoa(COORD_T *pstRefPointMa
 
     COORD_T stSlaveBtsCoord;    // 从站坐标
     uint32 dwSlaveBtsIndex = 0; // 从站第一径索引
-    flt32 fSlaveSnr = 0;
+    // flt32 fSlaveSnr = 0;
 
     flt32 fMainBtsTimeLen = 0;   // 当前参考点到主站的传输时长,单位微秒
     flt32 fSlaveBtsTimeLen = 0;  // 当前参考点到从站的传输时长,单位微秒
@@ -352,12 +352,12 @@ void lct_coordcal_cal_ref_point_delay_deviation_with_tdoa(COORD_T *pstRefPointMa
                     if (byFirstPathFlag <= 0)
                     { // 计算径
                         dwSlaveBtsIndex = pstFirstPathList[i].dwCalPathIndex;
-                        fSlaveSnr = pstFirstPathList[i].fCalPathIndexSnr;
+                        // fSlaveSnr = pstFirstPathList[i].fCalPathIndexSnr;
                     }
                     else
                     { // 跟踪径
                         dwSlaveBtsIndex = pstFirstPathList[i].dwTrackPathIndex;
-                        fSlaveSnr = pstFirstPathList[i].fTrackPathIndexSnr;
+                        // fSlaveSnr = pstFirstPathList[i].fTrackPathIndexSnr;
                     }
 
                     // 计算参考定位点到从站的传输时长
@@ -402,7 +402,7 @@ void lct_coordcal_cal_ref_point_distance_deviation_with_toa(uint32 dwBtsToaFpOff
 
     COORD_T stSlaveBtsCoord;    // 从站坐标
     uint32 dwSlaveBtsIndex = 0; // 从站第一径索引
-    flt32 fSlaveSnr = 0;
+    // flt32 fSlaveSnr = 0;
 
     flt32 fSlaveBtsDistance = 0;       // 参考点到从站的距离,单位厘米
     flt32 fSlaveBtsSignalDistance = 0; // 从站信号距离
@@ -430,12 +430,12 @@ void lct_coordcal_cal_ref_point_distance_deviation_with_toa(uint32 dwBtsToaFpOff
                 if (byFirstPathFlag <= 0)
                 { // 计算径
                     dwSlaveBtsIndex = pstFirstPathList[i].dwCalPathIndex;
-                    fSlaveSnr = pstFirstPathList[i].fCalPathIndexSnr;
+                    // fSlaveSnr = pstFirstPathList[i].fCalPathIndexSnr;
                 }
                 else
                 { // 跟踪径
                     dwSlaveBtsIndex = pstFirstPathList[i].dwTrackPathIndex;
-                    fSlaveSnr = pstFirstPathList[i].fTrackPathIndexSnr;
+                    // fSlaveSnr = pstFirstPathList[i].fTrackPathIndexSnr;
                 }
 
                 // 计算参考定位点到从站的距离
@@ -770,8 +770,6 @@ void lct_coordcal_dbcheck_minimum_value(uint8 byFirstPathFlag, PUB_LCT_BTS_LIST_
     int32 dwY = 0;
 
     uint8 byValidCounter = 0;
-    uint8 byXflag = 0;
-    uint8 byYflag = 0;
 
     ////计算端点坐标的最大值与最小值
     for (uint8 i = 0; i < pstLctBtsList->byBtsNum; i++)

+ 3 - 3
src/modules/location/lct_coordsel.c

@@ -99,7 +99,7 @@ void lct_coordsel_filter_jump_coord(LCT_COORDSEL_OPTIMUM_COORD_T *pstMinimumValu
 void lct_coordsel_sel_optimum_coord_by_prediction_coord(LCT_MINIMUM_VALUE_GROUP_T *pstMinimumValueGroup, COORD_T stPredictionCoord, LCT_COORDSEL_OPTIMUM_COORD_T *pstOptimumCoord)
 {
     uint8 byCounter = 0; // 极小值个数
-    uint8 byOldCounter = 0;
+    // uint8 byOldCounter = 0;
     LCT_COORDSEL_OPTIMUM_COORD_T astMinimumValueList[LCT_COORDSEL_MINIMUM_VALUE_NUM] = {0}; // 极小值队列
     LCT_COORDSEL_OPTIMUM_COORD_T stOptimumCoord1 = {0};                                     // 1维最优坐标
     LCT_COORDSEL_OPTIMUM_COORD_T stOptimumCoord2 = {0};                                     // 2维最优坐标
@@ -110,7 +110,7 @@ void lct_coordsel_sel_optimum_coord_by_prediction_coord(LCT_MINIMUM_VALUE_GROUP_
     //// 选1维坐标
     //  组织1维极小值队列
     lct_coordsel_organization_minimum_value_list(1, pstMinimumValueGroup, astMinimumValueList, &byCounter);
-    byOldCounter = byCounter;
+    // byOldCounter = byCounter;
 
     // 选择1维最终坐标
     lct_coordsel_select_final_coord_by_variance(astMinimumValueList, byCounter, stPredictionCoord, &stOptimumCoord1, &byResult1);
@@ -120,7 +120,7 @@ void lct_coordsel_sel_optimum_coord_by_prediction_coord(LCT_MINIMUM_VALUE_GROUP_
     //  组织2维极小值队列
     byCounter = 0;
     lct_coordsel_organization_minimum_value_list(2, pstMinimumValueGroup, astMinimumValueList, &byCounter);
-    byOldCounter = byCounter;
+    // byOldCounter = byCounter;
 
     // 选择2维最终坐标
     lct_coordsel_select_final_coord_by_variance(astMinimumValueList, byCounter, stPredictionCoord, &stOptimumCoord2, &byResult2);

+ 4 - 13
src/modules/location/lct_firstpath.c

@@ -62,17 +62,11 @@ void lct_firstpath_init(LCT_FIRSTPATH_PARAM_T stFirstPathParam)
 // pstFirstPathList:第一径数据队列(返回参数)
 void lct_firstpath_main(PUB_LCT_BTS_LIST_T *pstLctBtsList, PUB_LOCATION_DATA_T *pstLctDataList, LCT_FIRSTPATH_LIST_T *pstFirstPathList)
 {
-    uint32 dwFrameNo = 0;
-    uint8 byRemainder = 0;
-    int32 dwSyncOffset = 0;
-
     uint8 byLctBtsNum = pstLctBtsList->byBtsNum; // 有效定位基站组的基站个数
     PUB_LCT_BTS_T *pstLctBts = NULL;             // 定位基站
     PUB_LOCATION_DATA_T *pstLctData = NULL;      // 定位数据
     uint8 byFreqIndex = 0;                       // 基站频率索引
 
-    uint16 wAheadFrameFirstIndex = 0; // 上一次帧内第一径索引
-
     uint16 wMaxValueIndex = 0;
     flt32 fMaxValue; // 最大值
     uint16 wAnchorIndex = 0;
@@ -100,7 +94,7 @@ void lct_firstpath_main(PUB_LCT_BTS_LIST_T *pstLctBtsList, PUB_LOCATION_DATA_T *
         // TODO测试
         if (PUB_DEBUG_ENABLE)
         {
-            if (pstLctData->byFreqIndex < 8 && pstLctData->dwFrameNo > 1000)
+            if (pstLctData->dwFrameNo > 400)
             {
                 char *pfileName = "E:\\work\\ips8000\\aplm8000sdk\\output\\lctdata\\firstpath.bin";
                 util_write_flt32_to_bin_file(pfileName, PUB_SLOT_FRAME_LEN, gg_afOneFrameLocationData, 1);
@@ -148,7 +142,7 @@ void lct_firstpath_main(PUB_LCT_BTS_LIST_T *pstLctBtsList, PUB_LOCATION_DATA_T *
                 // TODO测试
                 if (PUB_DEBUG_ENABLE)
                 {
-                    if (pstLctData->byFreqIndex < 8 && pstLctData->dwFrameNo > 1000)
+                    if (pstLctData->dwFrameNo > 400)
                     {
                         printf("frame no:%d, freq index:%d, sync index:%d, cal frame index:%d, cal index:%d\n", pstLctData->dwFrameNo - 1, pstFirstPath->byFreqIndex, pstLctData->dwSignalSyncIndex, pstFirstPath->wFrameCalIndex, pstFirstPath->dwCalPathIndex);
                         uint8 byTmp = 0;
@@ -195,7 +189,7 @@ void lct_firstpath_main(PUB_LCT_BTS_LIST_T *pstLctBtsList, PUB_LOCATION_DATA_T *
             // TODO测试
             if (PUB_DEBUG_ENABLE)
             {
-                if (pstFirstPath->wFrameTrackIndex > 0 && pstLctData->byFreqIndex < 8 && pstLctData->dwFrameNo > 1000)
+                if (pstLctData->dwFrameNo > 400)
                 {
                     printf("frame no:%d, freq index:%d, sync index:%d, track frame index:%d, track index:%d\n", pstLctData->dwFrameNo - 1, pstFirstPath->byFreqIndex, pstLctData->dwSignalSyncIndex, pstFirstPath->wFrameTrackIndex, pstFirstPath->dwTrackPathIndex);
                     uint8 byTmp = 0;
@@ -269,7 +263,6 @@ void lct_firstpath_cal_calpath(flt32 *pfLocationData, uint16 wAheadFrameFirstPat
     uint16 wPeakListLen = 0;                     // 峰值索引队列长度
 
     uint16 wAnchorIndex = 0; // 帧内锚点索引
-    flt32 fThresholdWithAnchor = 0;
 
     uint16 wFirstPathLen = 0; // 第一径队列长度
 
@@ -969,7 +962,7 @@ void lct_firstpath_cal_first_path_by_sinc(flt32 *pfData, uint16 wMaxValueIndex,
 {
     flt32 *pfSincDataModel = g_afSincFilterDataList;       // sinc模型
     uint8 bySincFactor = gg_stFirstPathParam.bySincFactor; // sinc因子
-    flt32 fSnr = 0;
+    // flt32 fSnr = 0;
     flt32 fSincFactor = 0;    // sinc门限因子
     flt32 fSincThreshold = 0; // sinc门限
     uint16 wSincValueIndex = 0;
@@ -1757,7 +1750,6 @@ void lct_firstpath_save_first_path_data(PUB_LOCATION_DATA_T *pstLctData, LCT_FIR
     byFreqIndex = pstLctData->byFreqIndex;                        // 频率索引
     pstResultData = &pstPredictionDirectionDataList[byFreqIndex]; // 预测方向的数据
     dwBackupIndex = pstResultData->dwFirstPathBackupIndex;        // 数据备份索引
-    flt32 fAmpl = 0;
 
     if (dwBackupIndex < LCT_FIRST_PATH_BACKUP_NUM)
     {
@@ -1803,7 +1795,6 @@ void lct_firstpath_prediction_move_direction(LCT_FIRSTPATH_PREDICTION_DIRECTION_
     uint32 dwFrameGap = 0;
 
     uint8 byAheadTendency = 0;
-    uint8 byCurrentTendency = 0;
 
     for (uint8 i = 0; i < PUB_SYS_CARRIER_NUM; i++)
     {

+ 0 - 10
src/modules/location/lct_main.c

@@ -64,19 +64,12 @@ void lct_main_reset()
 void lct_main(PUB_LCT_BTS_LIST_T *pstLctBtsList, PUB_LOCATION_DATA_T *pstLctDataList, PUB_CURRENT_LCT_RESULT_T *pstCurrentLctResult)
 {
     uint8 byRemainder = 0;
-
-    LCT_FIRSTPATH_T *pstFirstPathList = NULL;
-    uint8 byBtsNum = 0;
-
     LCT_MINIMUM_VALUE_GROUP_T stMinimumValueGroup = {0}; // 极小值数据组
 
     uint8 byPredictionFlag = 0;      // 预测坐标成功标识符
     COORD_T stPredictionCoord = {0}; // 预测坐标
 
     uint16 wMinimumNum = 0;
-    uint8 byCalMinimumNum = 0;
-    uint8 byTrackMinimumNum = 0;
-    uint8 byPredicMinimumNum = 0;
 
     LCT_COORDSEL_OPTIMUM_COORD_T stOptimumCoord = {0}; // 最优坐标
 
@@ -84,7 +77,6 @@ void lct_main(PUB_LCT_BTS_LIST_T *pstLctBtsList, PUB_LOCATION_DATA_T *pstLctData
     int32 dwMainBtsBuildId = 0;
     int32 dwMainBtsLayerId = 0;
 
-    uint8 byFlag = 0;
     COORD_T stMeanCoord = {0};
 
     PUB_LOCATION_DATA_T *pstLctData = NULL;
@@ -465,8 +457,6 @@ void lct_main_mean_original_coord(LCT_COORDSEL_ORIGINAL_COORD_T *pstOriginalLctC
 void lct_main_organize_lct_result(int32 dwBuildId, int32 dwLayerId, LCT_FIRSTPATH_LIST_T *pstFirstPathList, COORD_T *pstMeanCoord, COORD_T *pstInsertPoint, uint32 dwImuMoveFlag, PUB_CURRENT_LCT_RESULT_T *pstCurrentLctResult)
 {
     uint8 byBtsNum = pstFirstPathList->byBtsNum;
-    PUB_LCT_BTS_T *pstLctBtsData = NULL;
-    uint8 byExist = 0;
 
     // 1、 保存定位坐标坐标
     if (!gLct_byBezierCurveListEnabled)

+ 2 - 5
src/modules/location/lct_prediction.c

@@ -26,12 +26,10 @@ void lct_prediction_current_coord_by_history(int32 dwBulidId, int32 dwLayerId, C
     LCT_COORDSEL_MEAN_COORD_T *pstData = (LCT_COORDSEL_MEAN_COORD_T *)&gLct_stMeanLctCoordList; // 平滑定位点队列
     uint8 byMeanListLen = pstData->byListLen;                                                   // 平滑定位点队列长度
 
-    LCT_COORDSEL_ORIGINAL_COORD_T *pstOriginalLctCoordList = &gLct_stOriginalLctCoordList; // 原始定位点队列
-    uint8 byOriginalListLen = pstOriginalLctCoordList->byListLen;                          // 原始定位点队列长度
+    // LCT_COORDSEL_ORIGINAL_COORD_T *pstOriginalLctCoordList = &gLct_stOriginalLctCoordList; // 原始定位点队列
 
     COORD_T stPrediction = {0};
     COORD_T *pstBaseCoord = NULL;
-    uint8 byChangeXY = 0; // X轴或Y轴变化大,1:X轴变化大,2:Y轴变化大
 
     // 处于同一大楼和楼层
     if (dwBulidId == gg_stSysStatus.dwBuildId && dwLayerId == gg_stSysStatus.dwLayerId)
@@ -116,8 +114,7 @@ void lct_prediction_prediction_phone_move_tendency(LCT_FIRSTPATH_PREDICTION_DIRE
     uint32 dwFrameGap = 0;                         // 帧间隔,间隔为8方才合法
 
     // 运动趋势,1:靠近,2:远离,0:趋势不一致
-    uint8 byAheadTendency = 0;   // 前一次运动趋势
-    uint8 byCurrentTendency = 0; // 当前运动趋势
+    uint8 byAheadTendency = 0; // 前一次运动趋势
 
     for (uint8 i = 0; i < PUB_SYS_CARRIER_NUM; i++)
     {

+ 0 - 1
src/modules/route/route_bluetooth.c

@@ -61,7 +61,6 @@ uint8 route_bluetooth_find_bluetooth_bts_from_install_bts(ROUTE_BLUETOOTH_BTS_T
     BTS_INSTALL_BTS_T stInstallBts = {0};
 
     uint8 byValidFlag = 0;
-
     for (uint8 i = 0; i < byBleBtsNum; i++)
     {
         stBluetoothBts = pstBluetoothBtsList[i];

+ 2 - 3
src/modules/route/route_main.c

@@ -59,8 +59,7 @@ void route_main(ROUTE_NEARBY_BTS_LIST *pstOutNearbyBtsList)
     ROUTE_BTS_LIST_T *pstRouteBtsList = NULL;          // 路由基站数据队列(包括蓝牙站和wifi站),由js注入
     ROUTE_BLUETOOTH_BTS_T *pstBluetoothBtsList = NULL; // 蓝牙站数据队列
     ROUTE_WIFI_BTS_T *pstWifiBtsList = NULL;           // wifi站数据队列
-    uint8 byRemainder = 0;
-    BTS_INSTALL_BTS_T stMainBtsData = {0}; // 主站(最强蓝牙或者wifi标识的基站)
+    BTS_INSTALL_BTS_T stMainBtsData = {0};             // 主站(最强蓝牙或者wifi标识的基站)
 
     pstInstallBtsList = (BTS_INSTALL_BTS_LIST_T *)bts_main_get_install_bts_list(); // 获得安装基站
     pstRouteBtsList = (ROUTE_BTS_LIST_T *)gRoute_pdwRouteBtsList;                  // 获得路由基站数据队列(包括蓝牙站和wifi站)
@@ -166,7 +165,7 @@ void route_main_get_bts_list_by_main_bts(BTS_INSTALL_BTS_T stMinBts, BTS_INSTALL
             fDistance = util_distance_cal_p2p_distance(stMinBts.dwCoordX, stMinBts.dwCoordY, stSlaveBts.dwCoordX, stSlaveBts.dwCoordY);
 
             // 主从站之间的距离有效
-            if (fDistance <= PUB_BTS_VALID_DISTANCE)
+            if (fDistance <= PUB_BTS_VALID_DISTANCE_THRES)
             {
                 pstOutBtsList->astBtsList[byCounter] = stSlaveBts;
                 byCounter++;

+ 17 - 17
src/sysdefine/struct_bts.h

@@ -9,31 +9,31 @@
 #include "./datatype.h"
 #include "./sysmacro.h"
 
-// 幅度模块宏定义
+// 幅度模块宏
 #define BTS_AMPL_MIRROR_SECONDS 4                            // 镜像秒数,几秒计算一次最强频点
 #define BTS_AMPL_MIRROR_FRAMES (4 * BTS_AMPL_MIRROR_SECONDS) // 镜像帧数,每秒4帧
-#define BTS_AMPL_MAIN_BTS_AMPL_VALID_THRESHOLD 1500          // 主站幅度有效门限(用户在某个时刻一定会更靠近某个基站,所以该基站幅度至少要大于该门限值)
-#define BTS_AMPL_BTS_AMPL_VALID_THRESHOLD 350                // 基站幅度有效门限
-#define BTS_AMPL_BTS_SNR_VALID_THRESHOLD 5                   // 基站SNR有效门限
+#define BTS_AMPL_MAIN_BTS_AMPL_VALID_THRESHOLD 500           // 减低门限,适配基站安装较高的场景 //1500          // 主站幅度有效门限(用户在某个时刻一定会更靠近某个基站,所以该基站幅度至少要大于该门限值)
+#define BTS_AMPL_BTS_AMPL_VALID_THRESHOLD 250                // 减低门限,适配基站安装较高的场景 //350                // 基站幅度有效门限
+#define BTS_AMPL_BTS_SNR_VALID_THRESHOLD 3.5                 // 减低门限,适配基站安装较高的场景 //5                   // 基站SNR有效门限
 
-// 同步模块宏定义
+// 同步模块宏
 #define BTS_SYNC_STABLE_SYNC_FRAMES BTS_AMPL_MIRROR_FRAMES // 同步帧数,即几帧进行一次同步
 
 // 计算基站ID
 #define BTS_BTS_NUM 5000 // 基站最大规模数量
 
-// 基站模块参数
-typedef struct
-{
-    // 幅度模块
-    int32 dwValidAmplThres;    // 有效幅度门限,默认值500
-    int32 dwValidSnrThres;     // 有效snr门限,放大100倍保存,默认值500
-    int32 dwAmplRatioThres;    // 当前幅度与上一次有效幅度之比门限,放大100倍保存,默认值15
-    int32 dwBtsAmplValidTimes; // 幅度有效次数,默认值2,在一个周期内,只有2次及以上次有效,才能判定该基站有效
-
-    // 同步模块
-    int32 dwMainBtsValidAmplThres; // 主站有效幅度门限,默认值1500
-} BTS_AMPL_PARAM_T;
+// // 基站模块参数
+// typedef struct
+// {
+//     // 幅度模块
+//     int32 dwValidAmplThres;    // 有效幅度门限,默认值500
+//     int32 dwValidSnrThres;     // 有效snr门限,放大100倍保存,默认值500
+//     int32 dwAmplRatioThres;    // 当前幅度与上一次有效幅度之比门限,放大100倍保存,默认值15
+//     int32 dwBtsAmplValidTimes; // 幅度有效次数,默认值2,在一个周期内,只有2次及以上次有效,才能判定该基站有效
+
+//     // 同步模块
+//     int32 dwMainBtsValidAmplThres; // 主站有效幅度门限,默认值1500
+// } BTS_AMPL_PARAM_T;
 
 // 基站幅度镜像数据结构
 typedef struct

+ 4 - 4
src/sysdefine/sysmacro.h

@@ -39,11 +39,11 @@
 // 信号采样率
 #define PUB_SIGNAL_SAMPLE_RATIO 48000
 
-// 信号同步向左偏移量,6000约42米(5000约35米)
-#define PUB_SYNC_INDEX_OFFSET_NUM 5600 // 40米
+// 信号同步向左偏移量,6000约42米
+#define PUB_SYNC_INDEX_OFFSET_NUM 6000 // 42米 = 6000 * 343 / 48000
 
-// TODO 基站有效距离,单位米,28
-#define PUB_BTS_VALID_DISTANCE ((PUB_SYNC_INDEX_OFFSET_NUM * PUB_AUDIO_SPEED) / PUB_SIGNAL_SAMPLE_RATIO)
+#define PUB_BTS_MAX_GAP_DISTANCE 40                                                                  // 基站间最大间距40
+#define PUB_BTS_VALID_DISTANCE_THRES (PUB_BTS_MAX_GAP_DISTANCE + (PUB_BTS_MAX_GAP_DISTANCE * 0.10f)) // 基站有效距离门限 = 基站最大间距 + 基站最大间距*0.15
 
 // 参与定位的基站,最多9个
 #define PUB_LCT_BTS_MAX_NUM PUB_SYS_CARRIER_NUM

+ 4 - 4
src/sysmain/sysmain.c

@@ -91,9 +91,9 @@ void sysmain_init_lct()
     stLctCoordcalParam.dwFirstPahtSnrThres = 35;        // 二维第一径信噪有效门限(放大10倍)
     stLctCoordcalParam.dwFirstPathIndexJumpThres = 720; // 二维第一径跳变门限
 
-    // 判断一维基站第一径是否有效参数
-    stLctCoordcalParam.dwOneFirstPahtValueThres = 300;     // 一维第一径幅度有效门限
-    stLctCoordcalParam.dwOneFirstPahtSnrThres = 50;        // 一维第一径信噪有效门限(放大10倍)
+    // 判断一维基站第一径是否有效参数,相比于二维门限要求有所提高
+    stLctCoordcalParam.dwOneFirstPahtValueThres = 250;     // 一维第一径幅度有效门限
+    stLctCoordcalParam.dwOneFirstPahtSnrThres = 40;        // 一维第一径信噪有效门限(放大10倍)
     stLctCoordcalParam.dwOneFirstPathIndexJumpThres = 500; // 一维第一径跳变门限
 
     stLctCoordcalParam.dwBtsEdgeExpendLen = 150;            // 基站围成的矩形框向外扩展长度,默认值150
@@ -103,7 +103,7 @@ void sysmain_init_lct()
     // 选择最优定位坐标模块参数
     LCT_COORDSEL_PARAM_T stLctCoordselParam = {0};
     stLctCoordselParam.dwValidDistanceThres = 400; // 极小值点到前一个点的有效距离门限
-    stLctCoordselParam.dwPredictionRadius = 250;   // 预测半径(极小值点必须在以预测点为圆心圆内)
+    stLctCoordselParam.dwPredictionRadius = 250;   // 预测半径(极小值点必须在以预测点为圆心圆内)
 
     //// 定位模块初始化
     lct_main_init(stFirstPathParam, stLctCoordcalParam, stLctCoordselParam);

+ 5 - 5
src/utils/fft.c

@@ -51,7 +51,7 @@ static flt32 gFFT_afSin8192[8192] = {0};
 
 void util_fft_init()
 {
-    int i = 0;
+    // int i = 0;
     int j = 0;
     int k = 0;
 
@@ -59,8 +59,8 @@ void util_fft_init()
     int L = 0; // 蝶形运算的级数
     int B = 0; // 蝶形运算的两个输入数据的间隔
 
-    flt32 fCosValue = 0;
-    flt32 fSinValue = 0;
+    // flt32 fCosValue = 0;
+    // flt32 fSinValue = 0;
     flt32 *pfCosData = NULL;
     flt32 *pfSinData = NULL;
 
@@ -268,7 +268,7 @@ int util_fft_fft(int data_frame_length, float *data_real_ptr, float *data_imag_p
     int k = 0;
     int r = 0;
 
-    int P = 0; // 旋转因子指数
+    // int P = 0; // 旋转因子指数
     int L = 0; // 蝶形运算的级数
     int B = 0; // 蝶形运算的两个输入数据的间隔
 
@@ -371,7 +371,7 @@ int util_fft_ifft(int data_frame_length, float *data_real_ptr, float *data_imag_
     int k = 0;
     int r = 0;
 
-    int P = 0; // 旋转因子指数
+    // int P = 0; // 旋转因子指数
     int L = 0; // 蝶形运算的级数
     int B = 0; // 蝶形运算的两个输入数据的间隔
 

File diff suppressed because it is too large
+ 0 - 1723
wasm/aplm8000sdk.js


BIN
wasm/aplm8000sdk.wasm


+ 182 - 0
wasm/aplm8000sdk.worker.js

@@ -0,0 +1,182 @@
+/**
+ * @license
+ * Copyright 2015 The Emscripten Authors
+ * SPDX-License-Identifier: MIT
+ */
+
+// Pthread Web Worker startup routine:
+// This is the entry point file that is loaded first by each Web Worker
+// that executes pthreads on the Emscripten application.
+
+'use strict';
+
+var Module = {};
+
+// Node.js support
+var ENVIRONMENT_IS_NODE = typeof process == 'object' && typeof process.versions == 'object' && typeof process.versions.node == 'string';
+if (ENVIRONMENT_IS_NODE) {
+  // Create as web-worker-like an environment as we can.
+
+  // See the parallel code in shell.js, but here we don't need the condition on
+  // multi-environment builds, as we do not have the need to interact with the
+  // modularization logic as shell.js must (see link.py:node_es6_imports and
+  // how that is used in link.py).
+
+  var nodeWorkerThreads = require('worker_threads');
+
+  var parentPort = nodeWorkerThreads.parentPort;
+
+  parentPort.on('message', (data) => onmessage({ data: data }));
+
+  var fs = require('fs');
+  var vm = require('vm');
+
+  Object.assign(global, {
+    self: global,
+    require,
+    Module,
+    location: {
+      // __filename is undefined in ES6 modules, and import.meta.url only in ES6
+      // modules.
+      href: __filename
+    },
+    Worker: nodeWorkerThreads.Worker,
+    importScripts: (f) => vm.runInThisContext(fs.readFileSync(f, 'utf8'), {filename: f}),
+    postMessage: (msg) => parentPort.postMessage(msg),
+    performance: global.performance || { now: Date.now },
+  });
+}
+
+// Thread-local guard variable for one-time init of the JS state
+var initializedJS = false;
+
+function threadPrintErr(...args) {
+  var text = args.join(' ');
+  // See https://github.com/emscripten-core/emscripten/issues/14804
+  if (ENVIRONMENT_IS_NODE) {
+    fs.writeSync(2, text + '\n');
+    return;
+  }
+  console.error(text);
+}
+function threadAlert(...args) {
+  var text = args.join(' ');
+  postMessage({cmd: 'alert', text, threadId: Module['_pthread_self']()});
+}
+var err = threadPrintErr;
+self.alert = threadAlert;
+
+Module['instantiateWasm'] = (info, receiveInstance) => {
+  // Instantiate from the module posted from the main thread.
+  // We can just use sync instantiation in the worker.
+  var module = Module['wasmModule'];
+  // We don't need the module anymore; new threads will be spawned from the main thread.
+  Module['wasmModule'] = null;
+  var instance = new WebAssembly.Instance(module, info);
+  // TODO: Due to Closure regression https://github.com/google/closure-compiler/issues/3193,
+  // the above line no longer optimizes out down to the following line.
+  // When the regression is fixed, we can remove this if/else.
+  return receiveInstance(instance);
+}
+
+// Turn unhandled rejected promises into errors so that the main thread will be
+// notified about them.
+self.onunhandledrejection = (e) => {
+  throw e.reason || e;
+};
+
+function handleMessage(e) {
+  try {
+    if (e.data.cmd === 'load') { // Preload command that is called once per worker to parse and load the Emscripten code.
+
+    // Until we initialize the runtime, queue up any further incoming messages.
+    let messageQueue = [];
+    self.onmessage = (e) => messageQueue.push(e);
+
+    // And add a callback for when the runtime is initialized.
+    self.startWorker = (instance) => {
+      // Notify the main thread that this thread has loaded.
+      postMessage({ 'cmd': 'loaded' });
+      // Process any messages that were queued before the thread was ready.
+      for (let msg of messageQueue) {
+        handleMessage(msg);
+      }
+      // Restore the real message handler.
+      self.onmessage = handleMessage;
+    };
+
+      // Module and memory were sent from main thread
+      Module['wasmModule'] = e.data.wasmModule;
+
+      // Use `const` here to ensure that the variable is scoped only to
+      // that iteration, allowing safe reference from a closure.
+      for (const handler of e.data.handlers) {
+        Module[handler] = (...args) => {
+          postMessage({ cmd: 'callHandler', handler, args: args });
+        }
+      }
+
+      Module['wasmMemory'] = e.data.wasmMemory;
+
+      Module['buffer'] = Module['wasmMemory'].buffer;
+
+      Module['ENVIRONMENT_IS_PTHREAD'] = true;
+
+      if (typeof e.data.urlOrBlob == 'string') {
+        importScripts(e.data.urlOrBlob);
+      } else {
+        var objectUrl = URL.createObjectURL(e.data.urlOrBlob);
+        importScripts(objectUrl);
+        URL.revokeObjectURL(objectUrl);
+      }
+    } else if (e.data.cmd === 'run') {
+      // Pass the thread address to wasm to store it for fast access.
+      Module['__emscripten_thread_init'](e.data.pthread_ptr, /*is_main=*/0, /*is_runtime=*/0, /*can_block=*/1);
+
+      // Await mailbox notifications with `Atomics.waitAsync` so we can start
+      // using the fast `Atomics.notify` notification path.
+      Module['__emscripten_thread_mailbox_await'](e.data.pthread_ptr);
+
+      // Also call inside JS module to set up the stack frame for this pthread in JS module scope
+      Module['establishStackSpace']();
+      Module['PThread'].receiveObjectTransfer(e.data);
+      Module['PThread'].threadInitTLS();
+
+      if (!initializedJS) {
+        initializedJS = true;
+      }
+
+      try {
+        Module['invokeEntryPoint'](e.data.start_routine, e.data.arg);
+      } catch(ex) {
+        if (ex != 'unwind') {
+          // The pthread "crashed".  Do not call `_emscripten_thread_exit` (which
+          // would make this thread joinable).  Instead, re-throw the exception
+          // and let the top level handler propagate it back to the main thread.
+          throw ex;
+        }
+      }
+    } else if (e.data.cmd === 'cancel') { // Main thread is asking for a pthread_cancel() on this thread.
+      if (Module['_pthread_self']()) {
+        Module['__emscripten_thread_exit'](-1);
+      }
+    } else if (e.data.target === 'setimmediate') {
+      // no-op
+    } else if (e.data.cmd === 'checkMailbox') {
+      if (initializedJS) {
+        Module['checkMailbox']();
+      }
+    } else if (e.data.cmd) {
+      // The received message looks like something that should be handled by this message
+      // handler, (since there is a e.data.cmd field present), but is not one of the
+      // recognized commands:
+      err(`worker.js received unknown command ${e.data.cmd}`);
+      err(e.data);
+    }
+  } catch(ex) {
+    Module['__emscripten_thread_crashed']?.();
+    throw ex;
+  }
+};
+
+self.onmessage = handleMessage;

Some files were not shown because too many files changed in this diff