123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463 |
- // 秒寻科技
- // 计算主站ID。计算“载波最强幅度队列”中的基站的ID,“载波最强幅度队列”一般包含3个基站,也可能是2个基站
- // zt
- // 2023-03-12
- #include "../../includes/includes.h"
- //// 定义仅本模块使用的全局变量
- // 基站镜像数据
- BTS_ID_MIRROR_DATA_T gBts_astBtsIdMirrorDataList[PUB_SYS_CARRIER_NUM] = {0};
- // 2次方队列
- uint32 gBts_adwPow2Table[32] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 2147483648};
- // 基站ID队列
- uint32 gBts_adwBtsIdList[PUB_BTS_ID_NUM] = {2097150, 2097146, 2097142, 2097134, 2097130, 2097118, 2097114, 2097110, 2097086, 2097082, 2097078, 2097070, 2097066, 2097022, 2097018, 2097014, 2097006, 2097002, 2096990, 2096986, 2096982, 2096894, 2096890, 2096886, 2096878, 2096874, 2096862, 2096858, 2096854, 2096830, 2096826, 2096822, 2096814, 2096810, 2096638, 2096634, 2096630, 2096622, 2096618, 2096606, 2096602, 2096598, 2096574, 2096570, 2096566, 2096558, 2096554, 2096510, 2096506, 2096502, 2096494, 2096490, 2096478, 2096474, 2096470, 2096126, 2096122, 2096118, 2096110, 2096106, 2096094, 2096090, 2096086, 2096062, 2096058, 2096054, 2096046, 2096042, 2095998, 2095994, 2095990, 2095982, 2095978, 2095966, 2095962, 2095958, 2095870, 2095866, 2095862, 2095854, 2095850, 2095838, 2095834, 2095830, 2095806, 2095802, 2095798, 2095790, 2095786, 2095098, 2095094, 2095086, 2095082, 2095070, 2095066, 2095062, 2095038, 2095034, 2095030, 2095022, 2095018, 2094974, 2094970, 2094966, 2094958, 2094954, 2094942, 2094938, 2094934, 2094846, 2094842, 2094838, 2094830, 2094826, 2094814, 2094810, 2094806, 2094782, 2094778, 2094774, 2094766, 2094762, 2094590, 2094586, 2094582, 2094574, 2094570, 2094558, 2094554, 2094550, 2094526, 2094522, 2094518, 2094510, 2094506, 2094462, 2094458, 2094454, 2094446, 2094442, 2094430, 2094426, 2094422, 2093046, 2093038, 2093034, 2093022, 2093018, 2093014, 2092990, 2092986, 2092982, 2092974, 2092970, 2092926, 2092922, 2092918, 2092910, 2092906, 2092894, 2092890, 2092886, 2092798, 2092794, 2092790, 2092782, 2092778, 2092766, 2092762, 2092758, 2092734, 2092730, 2092726, 2092718, 2092714, 2092538, 2092534, 2092526, 2092522, 2092510, 2092506, 2092502, 2092478, 2092474, 2092470, 2092462, 2092458, 2092414, 2092410, 2092406, 2092398, 2092394, 2092382, 2092378, 2092374, 2092026, 2092022, 2092014, 2092010, 2091998, 2091994, 2091990, 2091966, 2091962, 2091958, 2091950, 2091946, 2091902, 2091898, 2091894, 2091886, 2091882, 2091870, 2091866, 2091862, 2091774, 2091770, 2091766, 2091758, 2091754, 2091742, 2091738, 2091734, 2091710, 2091706, 2091702, 2091694, 2091690, 2088926, 2088922, 2088918, 2088894, 2088890, 2088886, 2088878, 2088874, 2088830, 2088826, 2088822, 2088814, 2088810, 2088798, 2088794, 2088790, 2088698, 2088694, 2088686, 2088682, 2088670, 2088666, 2088662, 2088638, 2088634, 2088630, 2088622, 2088618, 2088442, 2088438, 2088430, 2088426, 2088414, 2088410, 2088406, 2088382, 2088378, 2088374, 2088366, 2088362, 2088318, 2088314, 2088310, 2088302, 2088298, 2088286, 2088282, 2088278, 2087930, 2087926, 2087918, 2087914, 2087902, 2087898, 2087894, 2087870, 2087866, 2087862, 2087854, 2087850, 2087806, 2087802, 2087798, 2087790, 2087786, 2087774, 2087770, 2087766, 2087674, 2087670, 2087662, 2087658, 2087646, 2087642, 2087638, 2087614, 2087610, 2087606, 2087598, 2087594, 2086894, 2086890, 2086878, 2086874, 2086870, 2086846, 2086842, 2086838, 2086830, 2086826, 2086782, 2086778, 2086774, 2086766, 2086762, 2086750, 2086746, 2086742, 2086650, 2086646, 2086638, 2086634, 2086622, 2086618, 2086614, 2086590, 2086586, 2086582, 2086574, 2086570, 2086394, 2086390, 2086382, 2086378, 2086366, 2086362, 2086358, 2086334, 2086330, 2086326, 2086318, 2086314, 2086270, 2086266, 2086262, 2086254, 2086250, 2086238, 2086234, 2086230, 2080634, 2080630, 2080622, 2080618, 2080606, 2080602, 2080598, 2080506, 2080502, 2080494, 2080490, 2080478, 2080474, 2080470, 2080446, 2080442, 2080438, 2080430, 2080426, 2080250, 2080246, 2080238, 2080234, 2080222, 2080218, 2080214, 2080190, 2080186, 2080182, 2080174, 2080170, 2080122, 2080118, 2080110, 2080106, 2080094, 2080090, 2080086, 2079734, 2079726, 2079722, 2079710, 2079706, 2079702, 2079678, 2079674, 2079670, 2079662, 2079658, 2079610, 2079606, 2079598, 2079594, 2079582, 2079578, 2079574, 2079482, 2079478, 2079470, 2079466, 2079454, 2079450, 2079446, 2079422, 2079418, 2079414, 2079406, 2079402, 2078698, 2078686, 2078682, 2078678, 2078654, 2078650, 2078646, 2078638, 2078634, 2078586, 2078582, 2078574, 2078570, 2078558, 2078554, 2078550, 2078458, 2078454, 2078446, 2078442, 2078430, 2078426, 2078422, 2078398, 2078394, 2078390, 2078382, 2078378, 2078202, 2078198, 2078190, 2078186, 2078174, 2078170, 2078166, 2078142, 2078138, 2078134, 2078126, 2078122, 2078074, 2078070, 2078062, 2078058, 2078046, 2078042, 2078038, 2076630, 2076606, 2076602, 2076598, 2076590, 2076586, 2076538, 2076534, 2076526, 2076522, 2076510, 2076506, 2076502, 2076410, 2076406, 2076398, 2076394, 2076382, 2076378, 2076374, 2076350, 2076346, 2076342, 2076334, 2076330, 2076150, 2076142, 2076138, 2076126, 2076122, 2076118, 2076094, 2076090, 2076086, 2076078, 2076074, 2076026, 2076022, 2076014, 2076010, 2075998, 2075994, 2075990, 2075630, 2075626, 2075614, 2075610, 2075606, 2075582, 2075578, 2075574, 2075566, 2075562, 2075514, 2075510, 2075502, 2075498, 2075486, 2075482, 2075478, 2075386, 2075382, 2075374, 2075370, 2075358, 2075354, 2075350, 2075326, 2075322, 2075318, 2075310, 2075306, 2063862, 2063854, 2063850, 2063838, 2063834, 2063830, 2063802, 2063798, 2063790, 2063786, 2063738, 2063734, 2063726, 2063722, 2063710, 2063706, 2063702, 2063342, 2063338, 2063326, 2063322, 2063318, 2063290, 2063286, 2063278, 2063274, 2063226, 2063222, 2063214, 2063210, 2063198, 2063194, 2063190, 2063098, 2063094, 2063086, 2063082, 2063070, 2063066, 2063062, 2063034, 2063030, 2063022, 2063018, 2062298, 2062294, 2062266, 2062262, 2062254, 2062250, 2062202, 2062198, 2062190, 2062186, 2062174, 2062170, 2062166, 2062074, 2062070, 2062062, 2062058, 2062046, 2062042, 2062038, 2062010, 2062006, 2061998, 2061994, 2061814, 2061806, 2061802, 2061790, 2061786, 2061782, 2061754, 2061750, 2061742, 2061738, 2061690, 2061686, 2061678, 2061674, 2061662, 2061658, 2061654, 2060214, 2060206, 2060202, 2060154, 2060150, 2060142, 2060138, 2060126, 2060122, 2060118, 2060026, 2060022, 2060014, 2060010, 2059998, 2059994, 2059990, 2059962, 2059958, 2059950, 2059946, 2059758, 2059754, 2059742, 2059738, 2059734, 2059706, 2059702, 2059694, 2059690, 2059642, 2059638, 2059630, 2059626, 2059614, 2059610, 2059606, 2059242, 2059230, 2059226, 2059222, 2059194, 2059190, 2059182, 2059178, 2059130, 2059126, 2059118, 2059114, 2059102, 2059098, 2059094, 2059002, 2058998, 2058990, 2058986, 2058974, 2058970, 2058966, 2058938, 2058934, 2058926, 2058922, 2056030, 2056026, 2056022, 2055926, 2055918, 2055914, 2055902, 2055898, 2055894, 2055866, 2055862, 2055854, 2055850, 2055662, 2055658, 2055646, 2055642, 2055638, 2055610, 2055606, 2055598, 2055594, 2055546, 2055542, 2055534, 2055530, 2055518, 2055514, 2055510, 2055146, 2055134, 2055130, 2055126, 2055098, 2055094, 2055086, 2055082, 2055034, 2055030, 2055022, 2055018, 2055006, 2055002, 2054998, 2054902, 2054894, 2054890, 2054878, 2054874, 2054870, 2054842, 2054838, 2054830, 2054826, 2054074, 2054070, 2054062, 2054058, 2054010, 2054006, 2053998, 2053994, 2053982, 2053978, 2053974, 2053878, 2053870, 2053866, 2053854, 2053850, 2053846, 2053818, 2053814, 2053806, 2053802, 2053614, 2053610, 2053598, 2053594, 2053590, 2053562, 2053558, 2053550, 2053546, 2053498, 2053494, 2053486, 2053482, 2053470, 2053466, 2053462, 2029498, 2029494, 2029486, 2029482, 2029434, 2029430, 2029422, 2029418, 2029402, 2029398, 2029302, 2029294, 2029290, 2029274, 2029270, 2029242, 2029238, 2029230, 2029226, 2029038, 2029034, 2029018, 2029014, 2028986, 2028982, 2028974, 2028970, 2028922, 2028918, 2028910, 2028906, 2028890, 2028886, 2027382, 2027374, 2027370, 2027354, 2027350, 2027254, 2027246, 2027242, 2027226, 2027222, 2027194, 2027190, 2027182, 2027178, 2026986, 2026970, 2026966, 2026938, 2026934, 2026926, 2026922, 2026874, 2026870, 2026862, 2026858, 2026842, 2026838, 2026458, 2026454, 2026426, 2026422, 2026414, 2026410, 2026362, 2026358, 2026350, 2026346, 2026330, 2026326, 2026230, 2026222, 2026218, 2026202, 2026198, 2026170, 2026166, 2026158, 2026154, 2023130, 2023126, 2023098, 2023094, 2023086, 2023082, 2022890, 2022874, 2022870, 2022842, 2022838, 2022830, 2022826, 2022778, 2022774, 2022766, 2022762, 2022746, 2022742, 2022362, 2022358, 2022330, 2022326, 2022318, 2022314, 2022266, 2022262, 2022254, 2022250, 2022234, 2022230, 2022126, 2022122, 2022106, 2022102, 2022074, 2022070, 2022062, 2022058, 2021294, 2021290, 2021242, 2021238, 2021230, 2021226, 2021210, 2021206, 2021102, 2021098, 2021082, 2021078, 2021050, 2021046, 2021038, 2021034, 2020842, 2020826, 2020822, 2020794, 2020790, 2020782, 2020778, 2020730, 2020726, 2020718, 2020714, 2020698, 2020694, 2014582, 2014574, 2014570, 2014554, 2014550, 2014166, 2014138, 2014134, 2014126, 2014122, 2014070, 2014062, 2014058, 2014042, 2014038, 2013934, 2013930, 2013914, 2013910, 2013882, 2013878, 2013870, 2013866, 2013098, 2013046, 2013038, 2013034, 2013018, 2013014, 2012910, 2012906, 2012890, 2012886, 2012858, 2012854, 2012846, 2012842, 2012650, 2012634, 2012630, 2012602, 2012598, 2012590, 2012586, 2012534, 2012526, 2012522, 2012506, 2012502, 2010966, 2010862, 2010858, 2010842, 2010838, 2010810, 2010806, 2010798, 2010794, 2010586, 2010582, 2010554, 2010550, 2010542, 2010538, 2010486, 2010478, 2010474, 2010458, 2010454, 2010042, 2010038, 2010030, 2010026, 2009974, 2009966, 2009962, 2009946, 2009942, 2009838, 2009834, 2009818, 2009814, 2009786, 2009782, 2009774, 2009770, 1957338, 1957334, 1957306, 1957302, 1957290, 1957238, 1957226, 1957210, 1957206, 1956794, 1956790, 1956778, 1956726, 1956714, 1956698, 1956694, 1956586, 1956570, 1956566, 1956538, 1956534, 1956522, 1955690, 1955674, 1955670, 1955562, 1955546, 1955542, 1955514, 1955510, 1955498, 1955290, 1955286, 1955258, 1955254, 1955242, 1955190, 1955178, 1955162, 1955158, 1948522, 1948506, 1948502, 1948394, 1948378, 1948374, 1948346, 1948342, 1948330, 1947498, 1947482, 1947478, 1947370, 1947354, 1947350, 1947322, 1947318, 1947306, 1947098, 1947094, 1947066, 1947062, 1947050, 1946986, 1946970, 1946966, 1945302, 1945274, 1945270, 1945258, 1945046, 1945018, 1945014, 1945002, 1944938, 1944922, 1944918, 1944490, 1944426, 1944410, 1944406, 1944298, 1944282, 1944278, 1944250, 1944246, 1944234, 1930710, 1930678, 1930666, 1930602, 1930586, 1930582, 1928886, 1928874, 1928630, 1928618, 1928554, 1928538, 1928534, 1928106, 1928042, 1928026, 1928022, 1927914, 1927898, 1927894, 1927862, 1927850, 1924442, 1924438, 1924010, 1923946, 1923930, 1923926, 1923802, 1923798, 1923766, 1923754, 1922778, 1922774, 1922742, 1922730, 1922486, 1922474, 1922410, 1922394, 1922390, 1797546, 1797482, 1797466, 1796970, 1796954, 1796826, 1796778, 1792858, 1792682, 1791658, 1791402, 1791338, 1791322, 1758890, 1758634, 1758570, 1747626};
- //// 导出全局变量
- extern uint32 gg_dwFrameNo; // 全局帧号
- extern PUB_SYS_STATUS_T gg_stSysStatus; // 系统状态
- extern flt32 gg_afOneFrameLocationData[PUB_SLOT_FRAME_LEN]; // 一帧临时定位数据
- // 模块初始化
- void bts_id_init()
- {
- // 基站ID镜像数据
- memset(gBts_astBtsIdMirrorDataList, 0, sizeof(BTS_ID_MIRROR_DATA_T) * PUB_SYS_CARRIER_NUM);
- }
- // 模块主控函数
- // pstLocationDataList:定位数据队列
- // pstBtsAmplMirrorDataList:基站幅度镜像数据队列
- // pstBtsMaxAmplDataList:载波最强幅度队列
- // pstJudgementMainBtsList:判决主站队列(返回值)
- void bts_id_main(BTS_AMPL_MIRROR_DATA_T *pstBtsAmplMirrorDataList, PUB_LOCATION_DATA_T *pstLocationDataList, BTS_ID_JUDGEMENT_MAIN_BTS_T *pstJudgementMainBtsList)
- {
- // 镜像基站ID每bit的表征幅度
- bts_id_mirror_data(pstBtsAmplMirrorDataList, gBts_astBtsIdMirrorDataList);
- // 计算主站ID
- bts_id_cal_main_bts_id(gBts_astBtsIdMirrorDataList, pstLocationDataList, pstJudgementMainBtsList);
- }
- // 镜像计算基站ID的数据,每4帧中的最大值作为基站ID该bit位上的表征幅度值
- // pstLocationDataList:定位数据队列
- // pstBtsAmplMirrorDataList:基站幅度镜像数据队列
- // pstBtsIdMirrorDataList:基站ID镜像数据队列(返回参数)
- void bts_id_mirror_data(BTS_AMPL_MIRROR_DATA_T *pstBtsAmplMirrorDataList, BTS_ID_MIRROR_DATA_T *pstBtsIdMirrorDataList)
- {
- BTS_AMPL_MIRROR_DATA_T *pstBtsAmplMirrorData = NULL;
- BTS_ID_MIRROR_DATA_T *pstBtsIdMirrorData = NULL;
- uint32 dwFrameNo = 0; // 当前帧号
- uint8 byRemainder = 0;
- uint8 byBitIndex = 0; // 基站编号的bit索引,每bit对应一帧定位数据
- // 遍历每个载波,镜像数据
- for (uint8 i = 0; i < PUB_SYS_CARRIER_NUM; i++)
- {
- pstBtsAmplMirrorData = &pstBtsAmplMirrorDataList[i]; // 基站幅度镜像数据
- pstBtsIdMirrorData = &pstBtsIdMirrorDataList[i]; // 基站ID镜像数据
- dwFrameNo = gg_dwFrameNo - 1; // 前一帧的帧号
- if (dwFrameNo > 0)
- {
- byRemainder = dwFrameNo % PUB_SYS_SLOT_NUM;
- if (byRemainder == 0)
- {
- byBitIndex = pstBtsIdMirrorData->byBitIndex; // 基站编号的bit索引
- pstBtsIdMirrorData->afBitMaxAmplitude[byBitIndex] = pstBtsAmplMirrorData->fOneSecondMaxValue; // 保存该bit的表征幅度
- // 维护基站ID的bit索引
- pstBtsIdMirrorData->byBitIndex++; // bit索引后移一位
- if (pstBtsIdMirrorData->byBitIndex >= PUBLIC_BTS_ID_BITS_NUM)
- {
- pstBtsIdMirrorData->byBitIndex = 0; // bit索引复位
- }
- }
- }
- }
- return;
- }
- // 计算主站的ID
- // pstBtsIdMirrorDataList:基站ID镜像数据列表
- // pstBtsMaxAmplDataList:最强幅度频点队列
- // pstJudgementMainBtsList:判决主站队列(返回参数)
- void bts_id_cal_main_bts_id(BTS_ID_MIRROR_DATA_T *pstBtsIdMirrorDataList, PUB_LOCATION_DATA_T *pstLocationDataList, BTS_ID_JUDGEMENT_MAIN_BTS_T *pstJudgementMainBtsList)
- {
- uint8 byFlag = 0;
- BTS_ID_MIRROR_DATA_T *pstBtsIdMirrorData = NULL;
- uint8 abyMaxIndexList[3] = {0}; // 基站ID镜像幅度前3强
- uint8 byIndex = 0;
- PUB_LOCATION_DATA_T *pstLocationData = NULL;
- uint16 wFrameNo = 0; // 帧号
- uint8 byRemainder = 0; // 取模余数
- uint8 byShiftTimes = 0;
- uint32 dwBtsId = 0;
- uint8 byMainBtsCounter = 0;
- uint8 byExistFlag = 0;
- // 判决主站队列复位
- memset(pstJudgementMainBtsList, 0, sizeof(BTS_ID_JUDGEMENT_MAIN_BTS_T));
- // 帧号满足计算基站ID的条件
- if (gg_dwFrameNo > PUBLIC_BTS_ID_FRAMES)
- {
- // 手机处于基站捕获阶段,每帧都要计算主站ID,直到计算正确为止
- if (!gg_stSysStatus.byBtsCaptureFlag)
- {
- byRemainder = (gg_dwFrameNo - 1) % PUB_SYS_SLOT_NUM;
- if (byRemainder == 0) // 本帧需要计算基站ID
- {
- // 对基站ID幅度进行排序
- bts_id_ampl_sort(pstBtsIdMirrorDataList, abyMaxIndexList);
- // 计算前3强基站ID
- for (uint8 i = 0; i < 3; i++)
- {
- byIndex = abyMaxIndexList[i];
- pstBtsIdMirrorData = &pstBtsIdMirrorDataList[byIndex];
- byFlag = bts_id_cal_bts_id(pstBtsIdMirrorData, &dwBtsId, &byShiftTimes);
- if (byFlag == RET_OK)
- {
- // 检查该主站ID是否已经在判决主站队列中
- byExistFlag = 0;
- for (uint8 j = 0; j < byMainBtsCounter; j++)
- {
- if (pstJudgementMainBtsList->astBtsList[j].dwBtsId == dwBtsId && pstJudgementMainBtsList->astBtsList[j].byFreqIndex == byIndex)
- {
- byExistFlag = 1;
- break;
- }
- }
- // 不不存在
- if (!byExistFlag)
- {
- // 保存判决主站队列
- pstLocationData = &pstLocationDataList[byIndex];
- pstJudgementMainBtsList->astBtsList[byMainBtsCounter].dwBtsId = dwBtsId;
- pstJudgementMainBtsList->astBtsList[byMainBtsCounter].byFreqIndex = byIndex;
- pstJudgementMainBtsList->astBtsList[byMainBtsCounter].bySlot = pstLocationData->byCalSlot;
- pstJudgementMainBtsList->astBtsList[byMainBtsCounter].byShiftTimes = byShiftTimes;
- byMainBtsCounter++;
- }
- }
- }
- }
- }
- else
- {
- byRemainder = (gg_dwFrameNo - 1) % PUBLIC_BTS_ID_FRAMES;
- if (byRemainder == 0) // 本帧需要计算基站ID
- {
- // 对基站ID幅度进行排序
- bts_id_ampl_sort(pstBtsIdMirrorDataList, abyMaxIndexList);
- // 计算前3强基站ID
- for (uint8 i = 0; i < 3; i++)
- {
- byIndex = abyMaxIndexList[i];
- pstBtsIdMirrorData = &pstBtsIdMirrorDataList[byIndex];
- byFlag = bts_id_cal_bts_id(pstBtsIdMirrorData, &dwBtsId, &byShiftTimes);
- if (byFlag == RET_OK)
- {
- // 检查该主站ID是否已经在判决主站队列中
- byExistFlag = 0;
- for (uint8 j = 0; j < byMainBtsCounter; j++)
- {
- if (pstJudgementMainBtsList->astBtsList[j].dwBtsId == dwBtsId && pstJudgementMainBtsList->astBtsList[j].byFreqIndex == byIndex)
- {
- byExistFlag = 1;
- break;
- }
- }
- // 不不存在
- if (!byExistFlag)
- {
- // 保存判决主站队列
- pstLocationData = &pstLocationDataList[byIndex];
- pstJudgementMainBtsList->astBtsList[byMainBtsCounter].dwBtsId = dwBtsId;
- pstJudgementMainBtsList->astBtsList[byMainBtsCounter].byFreqIndex = byIndex;
- pstJudgementMainBtsList->astBtsList[byMainBtsCounter].bySlot = pstLocationData->byCalSlot;
- pstJudgementMainBtsList->astBtsList[byMainBtsCounter].byShiftTimes = byShiftTimes;
- byMainBtsCounter++;
- }
- }
- }
- }
- }
- }
- pstJudgementMainBtsList->byBtsNum = byMainBtsCounter; // 保存计算主站数量
- return;
- }
- // 对基站ID的幅度进行排序
- // pstBtsIdMirrorDataList:基站ID镜像数据队列
- void bts_id_ampl_sort(BTS_ID_MIRROR_DATA_T *pstBtsIdMirrorDataList, uint8 *pbySortIndexList)
- {
- flt32 fMaxValue = 0;
- uint8 byMaxValueIndex = 0;
- flt32 fScecondMaxValue = 0;
- uint8 byScecondMaxValueIndex = 0;
- flt32 fThirdMaxValue = 0;
- uint8 byThirdMaxValueIndex = 0;
- // 计算基站ID各bit幅度的平均值
- for (uint8 i = 0; i < PUB_SYS_CARRIER_NUM; i++)
- {
- for (uint8 j = 0; j < PUBLIC_BTS_ID_BITS_NUM; j++)
- {
- pstBtsIdMirrorDataList[i].fAvarageValue += pstBtsIdMirrorDataList[i].afBitMaxAmplitude[j] / PUBLIC_BTS_ID_BITS_NUM;
- }
- }
- // 找出最大值索引
- for (uint8 i = 0; i < PUB_SYS_CARRIER_NUM; i++)
- {
- if (pstBtsIdMirrorDataList[i].fAvarageValue > fMaxValue)
- {
- fMaxValue = pstBtsIdMirrorDataList[i].fAvarageValue;
- byMaxValueIndex = i;
- }
- }
- // 找出次大值索引
- for (uint8 i = 0; i < PUB_SYS_CARRIER_NUM; i++)
- {
- if (i != byMaxValueIndex)
- {
- if (pstBtsIdMirrorDataList[i].fAvarageValue > fScecondMaxValue)
- {
- fScecondMaxValue = pstBtsIdMirrorDataList[i].fAvarageValue;
- byScecondMaxValueIndex = i;
- }
- }
- }
- // 找第三大值索引
- for (uint8 i = 0; i < PUB_SYS_CARRIER_NUM; i++)
- {
- if (i != byMaxValueIndex && i != byScecondMaxValueIndex)
- {
- if (pstBtsIdMirrorDataList[i].fAvarageValue > fThirdMaxValue)
- {
- fThirdMaxValue = pstBtsIdMirrorDataList[i].fAvarageValue;
- byThirdMaxValueIndex = i;
- }
- }
- }
- pbySortIndexList[0] = byMaxValueIndex;
- pbySortIndexList[1] = byScecondMaxValueIndex;
- pbySortIndexList[2] = byThirdMaxValueIndex;
- return;
- }
- // 计算基站ID
- // pstBtsIdMirrorData:基站ID镜像数据
- // pdwResultBtsId:计算出来的基站ID
- // pbyShiftTimes:循环右移次数
- // 返回值:0:计算成功,1:计算失败,未能算出基站ID
- uint8 bts_id_cal_bts_id(BTS_ID_MIRROR_DATA_T *pstBtsIdMirrorData, uint32 *pdwResultBtsId, uint8 *pbyShiftTimes)
- {
- flt32 fThreshold = 0; // 基站ID判决门限
- uint32 dwJudgementBtsId = 0;
- uint8 byFlag = 0;
- // 计算抽样判决门限
- fThreshold = bts_id_cal_bit_judgement_threshold(pstBtsIdMirrorData->afBitMaxAmplitude);
- // 判决基站BIT,生成基站ID
- dwJudgementBtsId = bts_id_judgement_bits(pstBtsIdMirrorData->afBitMaxAmplitude, fThreshold);
- // 检查基站ID
- byFlag = bts_id_check_bts_id(dwJudgementBtsId, gBts_adwBtsIdList, pdwResultBtsId, pbyShiftTimes);
- if (byFlag != RET_OK)
- {
- return RET_FAIL;
- }
- // printf("cal main bts id:%d\n", *pdwResultBtsId);
- return RET_OK;
- }
- // 计算基站ID的bit判决门限
- // pfBitMaxAmplitude:基站编号各bit位的幅度表征值
- // 返回值,判决门限
- uint32 bts_id_cal_bit_judgement_threshold(flt32 *pfBitMaxAmplitude)
- {
- flt32 fThreshold = 0;
- flt32 fTmp = 0;
- flt32 fMaxValue = 0;
- flt32 fMinValue = FLT_MAX;
- flt32 fFactore = ((flt32)PUBLIC_BTS_ID_JUDGEMENT_FACTOR) / 100;
- // 查找队列中的最大值和最小值
- for (uint8 i = 0; i < PUBLIC_BTS_ID_BITS_NUM; i++)
- {
- fTmp = pfBitMaxAmplitude[i];
- if (fTmp > fMaxValue)
- {
- fMaxValue = fTmp;
- }
- if (fTmp < fMinValue)
- {
- fMinValue = fTmp;
- }
- }
- // 计算判决门限 = MaxValue * 判决因子(百分数) + MinValue * (1 - 判决因子)
- // 判决因子默认值为:15%
- fThreshold = fMaxValue * fFactore + fMinValue * (1 - fFactore);
- // dwThreshold = 5 * dwMinValue;
- return fThreshold;
- }
- // 根据判断门限判决各bit是0还是1,大于门限则判决为1
- // pfBitMaxAmplitude:基站编号各bit位的幅度表征值
- // fThreshold:判决门限
- // 返回值,基站ID
- uint32 bts_id_judgement_bits(flt32 *pfBitMaxAmplitude, flt32 fThreshold)
- {
- uint32 dwBtsId = 0;
- flt32 fBitAmplitude = 0;
- flt32 fPreBitAmplitude = 0;
- flt32 fNextBitAmplitude = 0;
- uint8 byBitValue = 0;
- uint32 dwMask = 0;
- flt32 fTmp = 0;
- // 逐位判决
- for (uint8 i = 0; i < PUBLIC_BTS_ID_BITS_NUM; i++)
- {
- byBitValue = 0;
- fBitAmplitude = pfBitMaxAmplitude[i];
- // 判断当前位的后一位幅度值
- if ((i + 1) < PUBLIC_BTS_ID_BITS_NUM)
- {
- fNextBitAmplitude = pfBitMaxAmplitude[i + 1];
- }
- else
- {
- fNextBitAmplitude = pfBitMaxAmplitude[i - 1];
- }
- // 判断当前位的前一位幅度值
- if ((i - 1) < 0)
- {
- fPreBitAmplitude = pfBitMaxAmplitude[PUBLIC_BTS_ID_BITS_NUM - 1];
- }
- else
- {
- fPreBitAmplitude = pfBitMaxAmplitude[i - 1];
- }
- // bit幅度表征值大于判决门限,理论判为1
- if (fBitAmplitude > fThreshold)
- {
- // 校验是否错判,如果当前位是1,则当前位前后位必有一位可能是0
- if ((fBitAmplitude > (0.25 * fNextBitAmplitude)) || (fBitAmplitude > (0.25 * fPreBitAmplitude)))
- {
- byBitValue = 1;
- }
- }
- // bit幅度表征值小于判决门限,理论判为0
- else
- {
- // 校验是否错判,如果当前位是0,则当前位前后位必然为1
- if ((fBitAmplitude > (0.35 * fNextBitAmplitude)) || (fBitAmplitude > (0.35 * fPreBitAmplitude)))
- {
- byBitValue = 1;
- }
- }
- // 保存当前bit位值
- if (byBitValue)
- {
- dwMask = gBts_adwPow2Table[PUBLIC_BTS_ID_BITS_NUM - 1 - i];
- dwBtsId |= dwMask;
- }
- }
- return dwBtsId;
- }
- // 检查判决ID是否正确
- // dwCalBtsId:判决基站ID
- // pdwBtsIdList:本地基站ID列表
- // pbyRightShift:右移次数
- // 返回值:0检查Ok,非0:检查不OK
- uint8 bts_id_check_bts_id(uint32 dwCalBtsId, uint32 *pdwBtsIdList, uint32 *pdwBtsId, uint8 *pbyRightShift)
- {
- uint32 dwBtsIdShift = dwCalBtsId;
- uint8 byExist = 0; // 从本地基站ID列表中找到
- for (uint16 i = 0; i < PUBLIC_BTS_ID_BITS_NUM; i++)
- {
- for (uint16 j = 0; j < PUB_BTS_ID_NUM; j++)
- {
- if (pdwBtsIdList[j] == dwBtsIdShift)
- {
- byExist = 1;
- break;
- }
- }
- // 检查OK
- if (byExist)
- {
- *pbyRightShift = i;
- *pdwBtsId = dwBtsIdShift;
- break;
- }
- else
- {
- // 右移一位
- dwBtsIdShift = bts_id_circle_right_shift(dwBtsIdShift);
- }
- }
- if (!byExist)
- {
- return RET_FAIL;
- }
- return RET_OK;
- }
- // 循环右移基站ID
- // dwBtsId:基站ID
- // 返回值:右移后的基站ID
- uint32 bts_id_circle_right_shift(uint32 dwBtsId)
- {
- uint32 dwShiftBtsId = dwBtsId;
- uint32 dwMask = gBts_adwPow2Table[PUBLIC_BTS_ID_BITS_NUM - 1];
- uint32 dwLastBit = dwBtsId & 1; // 取出最后一位
- dwShiftBtsId = dwShiftBtsId >> 1; // 右移一位
- // 若最后一位为1,则将最高位置1
- if (dwLastBit)
- {
- dwShiftBtsId = dwShiftBtsId | dwMask;
- }
- return dwShiftBtsId;
- }
|