From 67be2e45933e6ab0320f34e7b6dde9c51feeaab2 Mon Sep 17 00:00:00 2001 From: yangbinbin Date: Tue, 9 May 2017 09:00:19 +0800 Subject: [PATCH 01/12] Create version.txt --- version.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 version.txt diff --git a/version.txt b/version.txt new file mode 100644 index 0000000..aabe6ec --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +21 From 37c8fa97fdbcab183635570b0f0be5432f05d17f Mon Sep 17 00:00:00 2001 From: "yangbinbin_ytu@163.com" Date: Mon, 15 May 2017 08:23:30 +0800 Subject: [PATCH 02/12] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.txt b/version.txt index aabe6ec..2bd5a0a 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -21 +22 From 87f557c15c9d955d60cec1538ffc9658324b1c01 Mon Sep 17 00:00:00 2001 From: yangbinbin Date: Fri, 19 May 2017 09:27:52 +0800 Subject: [PATCH 03/12] Update version.txt --- version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.txt b/version.txt index 2bd5a0a..d00491f 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -22 +1 From 9255357ae6626d6eef52a784656c8b7193371f97 Mon Sep 17 00:00:00 2001 From: ybb Date: Mon, 22 May 2017 00:07:45 -0700 Subject: [PATCH 04/12] add ac decoder --- ac_decoder.cpp | 251 +++++++++++++++++++++++++++++++++++++++++++++++++ ac_decoder.h | 52 ++++++++++ 2 files changed, 303 insertions(+) create mode 100755 ac_decoder.cpp create mode 100755 ac_decoder.h diff --git a/ac_decoder.cpp b/ac_decoder.cpp new file mode 100755 index 0000000..0535bd1 --- /dev/null +++ b/ac_decoder.cpp @@ -0,0 +1,251 @@ +#include "stdafx.h" +#include "ac_decoder.h" + +ac_decoder::ac_decoder() + :check_stat_interval(10) +{ + next_check_time = time(NULL) + check_stat_interval ; +} + +ac_decode_result_t ac_decoder::decode(unsigned char ac[2] ) +{ + ac_decode_result_t result ; + memset(&result ,0 ,sizeof(ac_decode_result_t)); + + result.type = AC_MODE_NA ; + + time_t now = time(NULL) ; + if(now > next_check_time) + { + commit_ac_mode_stat() ; + next_check_time = now + check_stat_interval ; + } + + /* + AC数据全为0,应该是硬件数据错误 + */ + if(ac[0]+ac[1]==0) + return result; + + //X位恒为零 + if(ac[1]&0x40) + return result; + + /* + AC原始数据格式为: SPI,0,0,C1, A1,C2,A2,C4 ,A4,X,B1,D1,B2,D2,B4,D4 , + 转换后数据格式为: 00 A4 A2 A1 , 00 B4 B2 B1 , SPI C4 C2 C1 , 00 D4 D2 D1 + */ + + unsigned short modeac = + ((ac[0] & 0x10) ? 0x0010 : 0) | // C1 + ((ac[0] & 0x08) ? 0x1000 : 0) | // A1 + ((ac[0] & 0x04) ? 0x0020 : 0) | // C2 + ((ac[0] & 0x02) ? 0x2000 : 0) | // A2 + ((ac[0] & 0x01) ? 0x0040 : 0) | // C4 + ((ac[1] & 0x80) ? 0x4000 : 0) | // A4 + ((ac[1] & 0x20) ? 0x0100 : 0) | // B1 + ((ac[1] & 0x10) ? 0x0001 : 0) | // D1 + ((ac[1] & 0x08) ? 0x0200 : 0) | // B2 + ((ac[1] & 0x04) ? 0x0002 : 0) | // D2 + ((ac[1] & 0x02) ? 0x0400 : 0) | // B4 + ((ac[1] & 0x01) ? 0x0004 : 0) | // D4 + ((ac[0] & 0x80) ? 0x0080 : 0); // SPI + + int ac_type = get_ac_type(modeac) ; + if(ac_type == AC_MODE_NA) + { + return result ; + } + else if(ac_type == AC_MODE_A) + { + result.type = AC_MODE_A ; + result.squawk = modeac & 0x7777 ; + result.is_spi = modeac & 0x0080?true:false ; + return result ; + } + else + { + result.type = AC_MODE_C ; + int alt = modeA2modeC(modeac) ; + result.altitude = (alt==AC_INVALID_ALTITUDE)?AC_INVALID_ALTITUDE:(alt*100); + return result ; + } + +} + +int ac_decoder::get_ac_type(unsigned short modeac ) +{ + + /* + modeac参数排列顺序: + 00 A4 A2 A1 00 B4 B2 B1 SPI C4 C2 C1 00 D4 D2 D1 + */ +#define MIN_AC_COUNT 3 + + /* + 如果SPI脉冲出现,则为A模式 + */ + if(modeac&0x0080) + { + return AC_MODE_A ; + } + + /* + a.如果squawk为特殊的三个号码,则为A模式 + */ + unsigned short squawk = modeac&0x7777 ; + if(squawk ==0x7500 || + squawk ==0x7600 || + squawk == 0x7700) + return AC_MODE_A ; + + /* + b.如果C4 C2 C1的解码结果C 为0、5、7 之一时,判定为A 模式识别代码 + c.如果D4 D2 D1的解码结果D 为1、2、3、5、6、7 之一时,判定为A 模式识别代码 + */ + int cvalue = (modeac>>4)&0x0007 ; + int dvalue = modeac&0x0007; + + if((cvalue==0 || + cvalue==5 || + cvalue==7)|| + (dvalue==1 || + dvalue==2 || + dvalue==3 || + dvalue==5 || + dvalue==6 || + dvalue==7) + ) + { + unsigned int counted =get_mode_count_stat(a_mode_stat , modeac); + inc_mode_stat(a_mode_stat,modeac); + if(counted ==-1 || counted >MIN_AC_COUNT) + { + //第一次收到此报文,或者检测周期内已经多次收到报文 + return AC_MODE_A ; + } + else + { + //检验是A模式代码,但是收到相同报文太少,则可能是硬件接收错误, + //保守认为其是错误的报文 + return AC_MODE_NA ; + } + } + + //报文不能肯定为A模式报文,可能为C模式或者A模式,进行后续判断 + unsigned int counted =get_mode_count_stat(na_mode_stat ,modeac); + if(counted >MIN_AC_COUNT) + { + /* + 此AC报文多次稳定出现,则可能是A代码,或者是巡航高度飞行的飞机. + 将此报文按照C模式进行解码,如果位于名航巡航高度(5100~14900米)(16700~48900 英尺) + ,即认为是C模式代码,否则认为是A代码 + */ + + int altitude = AC_INVALID_ALTITUDE ; + int modeC = modeA2modeC(modeac); + if (modeC != AC_INVALID_ALTITUDE) + { + altitude = modeC * 100; + if(altitude >=16700 && altitude <=48900) + { + //目标高度满足民航飞行高度要求,认为是C模式代码 + return AC_MODE_C ; + } + else + { + //不在民航指定的高度内飞行,认为是A模式代码 + inc_mode_stat(a_mode_stat , modeac); + return AC_MODE_A ; + } + } + else + { + //按照C模式解码失败,则认为是A模式代码 + inc_mode_stat(a_mode_stat , modeac); + return AC_MODE_A ; + } + + } + + //完全无法确认的报文 + inc_mode_stat(na_mode_stat , modeac); + return AC_MODE_NA; +} +int ac_decoder::modeA2modeC(unsigned int modea) +{ + unsigned int FiveHundreds = 0; + unsigned int OneHundreds = 0; + + if ((modea & 0xFFFF8889) != 0 || // check zero bits are zero, D1 set is illegal + (modea & 0x000000F0) == 0) { // C1,,C4 cannot be Zero + return AC_INVALID_ALTITUDE; + } + + if (modea & 0x0010) {OneHundreds ^= 0x007;} // C1 + if (modea & 0x0020) {OneHundreds ^= 0x003;} // C2 + if (modea & 0x0040) {OneHundreds ^= 0x001;} // C4 + + // Remove 7s from OneHundreds (Make 7->5, snd 5->7). + if ((OneHundreds & 5) == 5) {OneHundreds ^= 2;} + + // Check for invalid codes, only 1 to 5 are valid + if (OneHundreds > 5) { + return AC_INVALID_ALTITUDE; + } + + //if (ModeA & 0x0001) {FiveHundreds ^= 0x1FF;} // D1 never used for altitude + if (modea & 0x0002) {FiveHundreds ^= 0x0FF;} // D2 + if (modea & 0x0004) {FiveHundreds ^= 0x07F;} // D4 + + if (modea & 0x1000) {FiveHundreds ^= 0x03F;} // A1 + if (modea & 0x2000) {FiveHundreds ^= 0x01F;} // A2 + if (modea & 0x4000) {FiveHundreds ^= 0x00F;} // A4 + + if (modea & 0x0100) {FiveHundreds ^= 0x007;} // B1 + if (modea & 0x0200) {FiveHundreds ^= 0x003;} // B2 + if (modea & 0x0400) {FiveHundreds ^= 0x001;} // B4 + + // Correct order of OneHundreds. + if (FiveHundreds & 1) {OneHundreds = 6 - OneHundreds;} + + return ((FiveHundreds * 5) + OneHundreds - 13); +} + + int ac_decoder::get_mode_count_stat(ac_count_stat_t& which , unsigned short modea) +{ + ac_count_stat_t::const_iterator it = which.find(modea); + return (it==which.end())?-1:(it->second.counted) ; +} + +void ac_decoder::inc_mode_stat(ac_count_stat_t& which , unsigned short modea ) +{ + //printf("which = %d\r\n" , which.size()); + ac_count_stat_t::iterator it = which.find(modea); + if(it== which.end()) { + ac_count_stat_item_t item = {0,1 }; + which.insert(std::make_pair(modea , item)); + } + else + { + it->second.counting++ ; + } +} + +void ac_decoder::commit_ac_mode_stat() +{ + ac_count_stat_t ::iterator it =a_mode_stat.begin(); + for(; it!=a_mode_stat.end(); ++it) + { + it->second.counted = it->second.counting ; + it->second.counting = 0 ; + } + + it =na_mode_stat.begin(); + for(; it!=na_mode_stat.end(); ++it) + { + it->second.counted = it->second.counting ; + it->second.counting = 0 ; + } +} + diff --git a/ac_decoder.h b/ac_decoder.h new file mode 100755 index 0000000..c8780bd --- /dev/null +++ b/ac_decoder.h @@ -0,0 +1,52 @@ +#ifndef __AC_DECODER_INCLUDE__ +#define __AC_DECODER_INCLUDE__ +#include + +#include +#include "ending.h" + +//A模式,应答机编码 +#define AC_MODE_A 1 +//C模式高度编码 +#define AC_MODE_C 2 +//无法区分 +#define AC_MODE_NA 0 +//无效的高度 +#define AC_INVALID_ALTITUDE -1 + +typedef struct ac_decode_result +{ + int type ; + unsigned short squawk ; + bool is_spi ; + int altitude ; +}ac_decode_result_t ; + + +class ac_decoder +{ +public: + ac_decoder() ; + ac_decode_result_t decode(unsigned char ac[2]) ; +private: + typedef struct ac_count_stat_item + { + int counted; + int counting ; + }ac_count_stat_item_t; + typedef std::map ac_count_stat_t ; +private: + int get_ac_type(unsigned short modeac) ; + int get_mode_count_stat(ac_count_stat_t& which , unsigned short modea); + void inc_mode_stat(ac_count_stat_t& which ,unsigned short modea); + void commit_ac_mode_stat(); + int modeA2modeC(unsigned int modea) ; + +private: + time_t next_check_time ; + const int check_stat_interval ; + ac_count_stat_t a_mode_stat ; + ac_count_stat_t na_mode_stat ; +} ; + +#endif From f88f8c37f4cc6c748de8c2c29df663027bde18a6 Mon Sep 17 00:00:00 2001 From: ybb Date: Mon, 22 May 2017 02:07:07 -0700 Subject: [PATCH 05/12] add ac decoder --- .idea/encodings.xml | 6 + .idea/misc.xml | 4 + .idea/mlat-client.iml | 11 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + ac_decode_c.c | 0 ac_decoder.cpp | 477 ++++++++++++++++++++---------------------- ac_decoder.h | 87 ++++---- ac_decoder_c.h | 28 +++ modes_message.c | 18 +- setup.py | 9 +- 11 files changed, 346 insertions(+), 308 deletions(-) create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/mlat-client.iml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 ac_decode_c.c create mode 100644 ac_decoder_c.h diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..ade3b8d --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..4e1dbee --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/mlat-client.iml b/.idea/mlat-client.iml new file mode 100644 index 0000000..6711606 --- /dev/null +++ b/.idea/mlat-client.iml @@ -0,0 +1,11 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..c8a1d06 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ac_decode_c.c b/ac_decode_c.c new file mode 100644 index 0000000..e69de29 diff --git a/ac_decoder.cpp b/ac_decoder.cpp index 0535bd1..4a53548 100755 --- a/ac_decoder.cpp +++ b/ac_decoder.cpp @@ -1,251 +1,226 @@ -#include "stdafx.h" -#include "ac_decoder.h" - -ac_decoder::ac_decoder() - :check_stat_interval(10) -{ - next_check_time = time(NULL) + check_stat_interval ; -} - -ac_decode_result_t ac_decoder::decode(unsigned char ac[2] ) -{ - ac_decode_result_t result ; - memset(&result ,0 ,sizeof(ac_decode_result_t)); - - result.type = AC_MODE_NA ; - - time_t now = time(NULL) ; - if(now > next_check_time) - { - commit_ac_mode_stat() ; - next_check_time = now + check_stat_interval ; - } - - /* - AC数据全为0,应该是硬件数据错误 - */ - if(ac[0]+ac[1]==0) - return result; - - //X位恒为零 - if(ac[1]&0x40) - return result; - - /* - AC原始数据格式为: SPI,0,0,C1, A1,C2,A2,C4 ,A4,X,B1,D1,B2,D2,B4,D4 , - 转换后数据格式为: 00 A4 A2 A1 , 00 B4 B2 B1 , SPI C4 C2 C1 , 00 D4 D2 D1 - */ - - unsigned short modeac = - ((ac[0] & 0x10) ? 0x0010 : 0) | // C1 - ((ac[0] & 0x08) ? 0x1000 : 0) | // A1 - ((ac[0] & 0x04) ? 0x0020 : 0) | // C2 - ((ac[0] & 0x02) ? 0x2000 : 0) | // A2 - ((ac[0] & 0x01) ? 0x0040 : 0) | // C4 - ((ac[1] & 0x80) ? 0x4000 : 0) | // A4 - ((ac[1] & 0x20) ? 0x0100 : 0) | // B1 - ((ac[1] & 0x10) ? 0x0001 : 0) | // D1 - ((ac[1] & 0x08) ? 0x0200 : 0) | // B2 - ((ac[1] & 0x04) ? 0x0002 : 0) | // D2 - ((ac[1] & 0x02) ? 0x0400 : 0) | // B4 - ((ac[1] & 0x01) ? 0x0004 : 0) | // D4 - ((ac[0] & 0x80) ? 0x0080 : 0); // SPI - - int ac_type = get_ac_type(modeac) ; - if(ac_type == AC_MODE_NA) - { - return result ; - } - else if(ac_type == AC_MODE_A) - { - result.type = AC_MODE_A ; - result.squawk = modeac & 0x7777 ; - result.is_spi = modeac & 0x0080?true:false ; - return result ; - } - else - { - result.type = AC_MODE_C ; - int alt = modeA2modeC(modeac) ; - result.altitude = (alt==AC_INVALID_ALTITUDE)?AC_INVALID_ALTITUDE:(alt*100); - return result ; - } - -} - -int ac_decoder::get_ac_type(unsigned short modeac ) -{ - - /* - modeac参数排列顺序: - 00 A4 A2 A1 00 B4 B2 B1 SPI C4 C2 C1 00 D4 D2 D1 - */ -#define MIN_AC_COUNT 3 - - /* - 如果SPI脉冲出现,则为A模式 - */ - if(modeac&0x0080) - { - return AC_MODE_A ; - } - - /* - a.如果squawk为特殊的三个号码,则为A模式 - */ - unsigned short squawk = modeac&0x7777 ; - if(squawk ==0x7500 || - squawk ==0x7600 || - squawk == 0x7700) - return AC_MODE_A ; - - /* - b.如果C4 C2 C1的解码结果C 为0、5、7 之一时,判定为A 模式识别代码 - c.如果D4 D2 D1的解码结果D 为1、2、3、5、6、7 之一时,判定为A 模式识别代码 - */ - int cvalue = (modeac>>4)&0x0007 ; - int dvalue = modeac&0x0007; - - if((cvalue==0 || - cvalue==5 || - cvalue==7)|| - (dvalue==1 || - dvalue==2 || - dvalue==3 || - dvalue==5 || - dvalue==6 || - dvalue==7) - ) - { - unsigned int counted =get_mode_count_stat(a_mode_stat , modeac); - inc_mode_stat(a_mode_stat,modeac); - if(counted ==-1 || counted >MIN_AC_COUNT) - { - //第一次收到此报文,或者检测周期内已经多次收到报文 - return AC_MODE_A ; - } - else - { - //检验是A模式代码,但是收到相同报文太少,则可能是硬件接收错误, - //保守认为其是错误的报文 - return AC_MODE_NA ; - } - } - - //报文不能肯定为A模式报文,可能为C模式或者A模式,进行后续判断 - unsigned int counted =get_mode_count_stat(na_mode_stat ,modeac); - if(counted >MIN_AC_COUNT) - { - /* - 此AC报文多次稳定出现,则可能是A代码,或者是巡航高度飞行的飞机. - 将此报文按照C模式进行解码,如果位于名航巡航高度(5100~14900米)(16700~48900 英尺) - ,即认为是C模式代码,否则认为是A代码 - */ - - int altitude = AC_INVALID_ALTITUDE ; - int modeC = modeA2modeC(modeac); - if (modeC != AC_INVALID_ALTITUDE) - { - altitude = modeC * 100; - if(altitude >=16700 && altitude <=48900) - { - //目标高度满足民航飞行高度要求,认为是C模式代码 - return AC_MODE_C ; - } - else - { - //不在民航指定的高度内飞行,认为是A模式代码 - inc_mode_stat(a_mode_stat , modeac); - return AC_MODE_A ; - } - } - else - { - //按照C模式解码失败,则认为是A模式代码 - inc_mode_stat(a_mode_stat , modeac); - return AC_MODE_A ; - } - - } - - //完全无法确认的报文 - inc_mode_stat(na_mode_stat , modeac); - return AC_MODE_NA; -} -int ac_decoder::modeA2modeC(unsigned int modea) -{ - unsigned int FiveHundreds = 0; - unsigned int OneHundreds = 0; - - if ((modea & 0xFFFF8889) != 0 || // check zero bits are zero, D1 set is illegal - (modea & 0x000000F0) == 0) { // C1,,C4 cannot be Zero - return AC_INVALID_ALTITUDE; - } - - if (modea & 0x0010) {OneHundreds ^= 0x007;} // C1 - if (modea & 0x0020) {OneHundreds ^= 0x003;} // C2 - if (modea & 0x0040) {OneHundreds ^= 0x001;} // C4 - - // Remove 7s from OneHundreds (Make 7->5, snd 5->7). - if ((OneHundreds & 5) == 5) {OneHundreds ^= 2;} - - // Check for invalid codes, only 1 to 5 are valid - if (OneHundreds > 5) { - return AC_INVALID_ALTITUDE; - } - - //if (ModeA & 0x0001) {FiveHundreds ^= 0x1FF;} // D1 never used for altitude - if (modea & 0x0002) {FiveHundreds ^= 0x0FF;} // D2 - if (modea & 0x0004) {FiveHundreds ^= 0x07F;} // D4 - - if (modea & 0x1000) {FiveHundreds ^= 0x03F;} // A1 - if (modea & 0x2000) {FiveHundreds ^= 0x01F;} // A2 - if (modea & 0x4000) {FiveHundreds ^= 0x00F;} // A4 - - if (modea & 0x0100) {FiveHundreds ^= 0x007;} // B1 - if (modea & 0x0200) {FiveHundreds ^= 0x003;} // B2 - if (modea & 0x0400) {FiveHundreds ^= 0x001;} // B4 - - // Correct order of OneHundreds. - if (FiveHundreds & 1) {OneHundreds = 6 - OneHundreds;} - - return ((FiveHundreds * 5) + OneHundreds - 13); -} - - int ac_decoder::get_mode_count_stat(ac_count_stat_t& which , unsigned short modea) -{ - ac_count_stat_t::const_iterator it = which.find(modea); - return (it==which.end())?-1:(it->second.counted) ; -} - -void ac_decoder::inc_mode_stat(ac_count_stat_t& which , unsigned short modea ) -{ - //printf("which = %d\r\n" , which.size()); - ac_count_stat_t::iterator it = which.find(modea); - if(it== which.end()) { - ac_count_stat_item_t item = {0,1 }; - which.insert(std::make_pair(modea , item)); - } - else - { - it->second.counting++ ; - } -} - -void ac_decoder::commit_ac_mode_stat() -{ - ac_count_stat_t ::iterator it =a_mode_stat.begin(); - for(; it!=a_mode_stat.end(); ++it) - { - it->second.counted = it->second.counting ; - it->second.counting = 0 ; - } - - it =na_mode_stat.begin(); - for(; it!=na_mode_stat.end(); ++it) - { - it->second.counted = it->second.counting ; - it->second.counting = 0 ; - } -} - +#include "ac_decoder.h" +#include +#include +#include + +ac_decoder::ac_decoder() + :check_stat_interval(10) +{ + next_check_time = time(NULL) + check_stat_interval ; +} + +ac_decode_result_t ac_decoder::decode(unsigned char ac[2] ) +{ + ac_decode_result_t result ; + memset(&result ,0 ,sizeof(ac_decode_result_t)); + + result.type = AC_MODE_NA ; + + time_t now = time(NULL) ; + if(now > next_check_time) + { + commit_ac_mode_stat() ; + next_check_time = now + check_stat_interval ; + } + + if(ac[0]+ac[1]==0) + return result; + + if(ac[1]&0x40) + return result; + + unsigned short modeac = + ((ac[0] & 0x10) ? 0x0010 : 0) | // C1 + ((ac[0] & 0x08) ? 0x1000 : 0) | // A1 + ((ac[0] & 0x04) ? 0x0020 : 0) | // C2 + ((ac[0] & 0x02) ? 0x2000 : 0) | // A2 + ((ac[0] & 0x01) ? 0x0040 : 0) | // C4 + ((ac[1] & 0x80) ? 0x4000 : 0) | // A4 + ((ac[1] & 0x20) ? 0x0100 : 0) | // B1 + ((ac[1] & 0x10) ? 0x0001 : 0) | // D1 + ((ac[1] & 0x08) ? 0x0200 : 0) | // B2 + ((ac[1] & 0x04) ? 0x0002 : 0) | // D2 + ((ac[1] & 0x02) ? 0x0400 : 0) | // B4 + ((ac[1] & 0x01) ? 0x0004 : 0) | // D4 + ((ac[0] & 0x80) ? 0x0080 : 0); // SPI + + int ac_type = get_ac_type(modeac) ; + if(ac_type == AC_MODE_NA) + { + return result ; + } + else if(ac_type == AC_MODE_A) + { + result.type = AC_MODE_A ; + result.squawk = modeac & 0x7777 ; + result.is_spi = modeac & 0x0080?true:false ; + return result ; + } + else + { + result.type = AC_MODE_C ; + int alt = modeA2modeC(modeac) ; + result.altitude = (alt==AC_INVALID_ALTITUDE)?AC_INVALID_ALTITUDE:(alt*100); + return result ; + } + +} + +int ac_decoder::get_ac_type(unsigned short modeac ) +{ + +#define MIN_AC_COUNT 3 + + if(modeac&0x0080) + { + return AC_MODE_A ; + } + + unsigned short squawk = modeac&0x7777 ; + if(squawk ==0x7500 || + squawk ==0x7600 || + squawk == 0x7700) + return AC_MODE_A ; + + int cvalue = (modeac>>4)&0x0007 ; + int dvalue = modeac&0x0007; + + if((cvalue==0 || + cvalue==5 || + cvalue==7)|| + (dvalue==1 || + dvalue==2 || + dvalue==3 || + dvalue==5 || + dvalue==6 || + dvalue==7) + ) + { + unsigned int counted =get_mode_count_stat(a_mode_stat , modeac); + inc_mode_stat(a_mode_stat,modeac); + if(counted ==-1 || counted >MIN_AC_COUNT) + { + return AC_MODE_A ; + } + else + { + return AC_MODE_NA ; + } + } + + unsigned int counted =get_mode_count_stat(na_mode_stat ,modeac); + if(counted >MIN_AC_COUNT) + { + int altitude = AC_INVALID_ALTITUDE ; + int modeC = modeA2modeC(modeac); + if (modeC != AC_INVALID_ALTITUDE) + { + altitude = modeC * 100; + if(altitude >=16700 && altitude <=48900) + { + return AC_MODE_C ; + } + else + { + inc_mode_stat(a_mode_stat , modeac); + return AC_MODE_A ; + } + } + else + { + inc_mode_stat(a_mode_stat , modeac); + return AC_MODE_A ; + } + + } + + inc_mode_stat(na_mode_stat , modeac); + return AC_MODE_NA; +} +int ac_decoder::modeA2modeC(unsigned int modea) +{ + unsigned int FiveHundreds = 0; + unsigned int OneHundreds = 0; + + if ((modea & 0xFFFF8889) != 0 || // check zero bits are zero, D1 set is illegal + (modea & 0x000000F0) == 0) { // C1,,C4 cannot be Zero + return AC_INVALID_ALTITUDE; + } + + if (modea & 0x0010) {OneHundreds ^= 0x007;} // C1 + if (modea & 0x0020) {OneHundreds ^= 0x003;} // C2 + if (modea & 0x0040) {OneHundreds ^= 0x001;} // C4 + + // Remove 7s from OneHundreds (Make 7->5, snd 5->7). + if ((OneHundreds & 5) == 5) {OneHundreds ^= 2;} + + // Check for invalid codes, only 1 to 5 are valid + if (OneHundreds > 5) { + return AC_INVALID_ALTITUDE; + } + + //if (ModeA & 0x0001) {FiveHundreds ^= 0x1FF;} // D1 never used for altitude + if (modea & 0x0002) {FiveHundreds ^= 0x0FF;} // D2 + if (modea & 0x0004) {FiveHundreds ^= 0x07F;} // D4 + + if (modea & 0x1000) {FiveHundreds ^= 0x03F;} // A1 + if (modea & 0x2000) {FiveHundreds ^= 0x01F;} // A2 + if (modea & 0x4000) {FiveHundreds ^= 0x00F;} // A4 + + if (modea & 0x0100) {FiveHundreds ^= 0x007;} // B1 + if (modea & 0x0200) {FiveHundreds ^= 0x003;} // B2 + if (modea & 0x0400) {FiveHundreds ^= 0x001;} // B4 + + // Correct order of OneHundreds. + if (FiveHundreds & 1) {OneHundreds = 6 - OneHundreds;} + + return ((FiveHundreds * 5) + OneHundreds - 13); +} + + int ac_decoder::get_mode_count_stat(ac_count_stat_t& which , unsigned short modea) +{ + ac_count_stat_t::const_iterator it = which.find(modea); + return (it==which.end())?-1:(it->second.counted) ; +} + +void ac_decoder::inc_mode_stat(ac_count_stat_t& which , unsigned short modea ) +{ + //printf("which = %d\r\n" , which.size()); + ac_count_stat_t::iterator it = which.find(modea); + if(it== which.end()) { + ac_count_stat_item_t item = {0,1 }; + which.insert(std::make_pair(modea , item)); + } + else + { + it->second.counting++ ; + } +} + +void ac_decoder::commit_ac_mode_stat() +{ + ac_count_stat_t ::iterator it =a_mode_stat.begin(); + for(; it!=a_mode_stat.end(); ++it) + { + it->second.counted = it->second.counting ; + it->second.counting = 0 ; + } + + it =na_mode_stat.begin(); + for(; it!=na_mode_stat.end(); ++it) + { + it->second.counted = it->second.counting ; + it->second.counting = 0 ; + } +} + + + +ac_decoder* global_ac_decoder_ptr = NULL ; + ac_decode_resultd ac_decode(unsigned char ac[2]) +{ + if(global_ac_decoder_ptr == NULL) + global_ac_decoder_ptr = new ac_decoder() ; + + return global_ac_decoder_ptr->decode(ac); +} diff --git a/ac_decoder.h b/ac_decoder.h index c8780bd..bdc0cd9 100755 --- a/ac_decoder.h +++ b/ac_decoder.h @@ -1,52 +1,35 @@ -#ifndef __AC_DECODER_INCLUDE__ -#define __AC_DECODER_INCLUDE__ -#include - -#include -#include "ending.h" - -//A模式,应答机编码 -#define AC_MODE_A 1 -//C模式高度编码 -#define AC_MODE_C 2 -//无法区分 -#define AC_MODE_NA 0 -//无效的高度 -#define AC_INVALID_ALTITUDE -1 - -typedef struct ac_decode_result -{ - int type ; - unsigned short squawk ; - bool is_spi ; - int altitude ; -}ac_decode_result_t ; - - -class ac_decoder -{ -public: - ac_decoder() ; - ac_decode_result_t decode(unsigned char ac[2]) ; -private: - typedef struct ac_count_stat_item - { - int counted; - int counting ; - }ac_count_stat_item_t; - typedef std::map ac_count_stat_t ; -private: - int get_ac_type(unsigned short modeac) ; - int get_mode_count_stat(ac_count_stat_t& which , unsigned short modea); - void inc_mode_stat(ac_count_stat_t& which ,unsigned short modea); - void commit_ac_mode_stat(); - int modeA2modeC(unsigned int modea) ; - -private: - time_t next_check_time ; - const int check_stat_interval ; - ac_count_stat_t a_mode_stat ; - ac_count_stat_t na_mode_stat ; -} ; - -#endif +#ifndef __AC_DECODER_INCLUDE__ +#define __AC_DECODER_INCLUDE__ +#include +#include +#include "ac_decoder_c.h" + + + +class ac_decoder +{ +public: + ac_decoder() ; + ac_decode_result_t decode(unsigned char ac[2]) ; +private: + typedef struct ac_count_stat_item + { + int counted; + int counting ; + }ac_count_stat_item_t; + typedef std::map ac_count_stat_t ; +private: + int get_ac_type(unsigned short modeac) ; + int get_mode_count_stat(ac_count_stat_t& which , unsigned short modea); + void inc_mode_stat(ac_count_stat_t& which ,unsigned short modea); + void commit_ac_mode_stat(); + int modeA2modeC(unsigned int modea) ; + +private: + time_t next_check_time ; + const int check_stat_interval ; + ac_count_stat_t a_mode_stat ; + ac_count_stat_t na_mode_stat ; +} ; + +#endif diff --git a/ac_decoder_c.h b/ac_decoder_c.h new file mode 100644 index 0000000..77fb28c --- /dev/null +++ b/ac_decoder_c.h @@ -0,0 +1,28 @@ +#ifndef __AC_DECODER_INCLUDE_C_INCLUDE_ +#define __AC_DECODER_INCLUDE_C_INCLUDE_ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct ac_decode_resultd +{ + int type ; + unsigned short squawk ; + int is_spi ; + int altitude ; +}ac_decode_result_t ; + +#define AC_MODE_A 1 +#define AC_MODE_C 2 +#define AC_MODE_NA 0 +#define AC_INVALID_ALTITUDE -1 + + +ac_decode_result_t ac_decode(unsigned char ac[2]) ; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/modes_message.c b/modes_message.c index 724fab8..7613d3b 100644 --- a/modes_message.c +++ b/modes_message.c @@ -17,6 +17,7 @@ */ #include "_modes.h" +#include "ac_decoder_c.h" /* methods / type behaviour */ static PyObject *modesmessage_new(PyTypeObject *type, PyObject *args, PyObject *kwds); @@ -112,11 +113,14 @@ static PyTypeObject modesmessageType = { modesmessage_new, /* tp_new */ }; + /* * module setup */ int modesmessage_module_init(PyObject *m) { + + if (PyType_Ready(&modesmessageType) < 0) return -1; @@ -382,11 +386,23 @@ static int decode(modesmessage *self) Py_CLEAR(self->altitude); if (self->datalen == 2) { + + unsigned char ac[2] ; + memcpy(ac , self->data , 2); + + ac_decode_result_t ac_ret = ac_decode(ac) ; + if(ac_ret.type == AC_MODE_A) + { self->df = DF_MODEAC; - self->address = PyLong_FromLong((self->data[0] << 8) | self->data[1]); + int ac_fix_icao = 0x00FF0000 | ac_ret.squawk ; + self->address = PyLong_FromLong(ac_fix_icao) ; self->valid = 1; + printf("A Mode:%06X\r\n" ,self->address ); return 0; } + else + return -1; + } self->df = (self->data[0] >> 3) & 31; diff --git a/setup.py b/setup.py index 92de640..bc622cc 100755 --- a/setup.py +++ b/setup.py @@ -25,13 +25,14 @@ more_warnings = False extra_compile_args = [] -if more_warnings and get_default_compiler() == 'unix': +#if more_warnings and get_default_compiler() == 'unix': # let's assume this is GCC - extra_compile_args.append('-Wpointer-arith') +# extra_compile_args.append('-Wpointer-arith') +# include_dirs=['/usr/include/x86_64-linux-gnu/c++/6'] modes_ext = Extension('_modes', - sources=['_modes.c', 'modes_reader.c', 'modes_message.c', 'modes_crc.c'], - extra_compile_args=extra_compile_args) + sources=['ac_decoder.cpp' ,'_modes.c', 'modes_reader.c', 'modes_message.c', 'modes_crc.c' ], + extra_compile_args=extra_compile_args ) setup(name='MlatClient', version=CLIENT_VERSION, From 7864dc1ef736c423e73fd050a23e7f51554533e1 Mon Sep 17 00:00:00 2001 From: ybb Date: Mon, 22 May 2017 02:35:24 -0700 Subject: [PATCH 06/12] add ignore file --- .gitignore | 2 ++ .idea/encodings.xml | 6 ------ 2 files changed, 2 insertions(+), 6 deletions(-) delete mode 100644 .idea/encodings.xml diff --git a/.gitignore b/.gitignore index 03d9374..3d4eb7b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ build dist *.so test*.sh +.idea/* +.idea/ diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index ade3b8d..0000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From ed8aa53860b10cfa4363c44cc4f7d88473451a51 Mon Sep 17 00:00:00 2001 From: ybb Date: Mon, 22 May 2017 02:38:19 -0700 Subject: [PATCH 07/12] delete .idea --- .idea/misc.xml | 4 ---- .idea/mlat-client.iml | 11 ----------- .idea/modules.xml | 8 -------- .idea/vcs.xml | 6 ------ 4 files changed, 29 deletions(-) delete mode 100644 .idea/misc.xml delete mode 100644 .idea/mlat-client.iml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 4e1dbee..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/mlat-client.iml b/.idea/mlat-client.iml deleted file mode 100644 index 6711606..0000000 --- a/.idea/mlat-client.iml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index c8a1d06..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From 4270587413929e137c238c72c3d7d713a639a960 Mon Sep 17 00:00:00 2001 From: ybb Date: Tue, 6 Jun 2017 17:45:29 -0700 Subject: [PATCH 08/12] remove ac_decode_c.c --- ac_decode_c.c | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 ac_decode_c.c diff --git a/ac_decode_c.c b/ac_decode_c.c deleted file mode 100644 index e69de29..0000000 From aa4365b96576c92592190bd6692a72b64eb8de19 Mon Sep 17 00:00:00 2001 From: ybb Date: Tue, 6 Jun 2017 18:47:04 -0700 Subject: [PATCH 09/12] add ac mode --- ac_decoder.cpp | 4 ++-- mlat/client/coordinator.py | 23 ++++++++++++++++++++++- mlat/client/jsonclient.py | 2 +- modes_message.c | 33 +++++++++++++++++---------------- modes_reader.c | 13 +++++++++++-- nogps.sh | 1 + 6 files changed, 54 insertions(+), 22 deletions(-) create mode 100755 nogps.sh diff --git a/ac_decoder.cpp b/ac_decoder.cpp index 4a53548..52aa576 100755 --- a/ac_decoder.cpp +++ b/ac_decoder.cpp @@ -96,7 +96,7 @@ int ac_decoder::get_ac_type(unsigned short modeac ) dvalue==7) ) { - unsigned int counted =get_mode_count_stat(a_mode_stat , modeac); + int counted =get_mode_count_stat(a_mode_stat , modeac); inc_mode_stat(a_mode_stat,modeac); if(counted ==-1 || counted >MIN_AC_COUNT) { @@ -108,7 +108,7 @@ int ac_decoder::get_ac_type(unsigned short modeac ) } } - unsigned int counted =get_mode_count_stat(na_mode_stat ,modeac); + int counted =get_mode_count_stat(na_mode_stat ,modeac); if(counted >MIN_AC_COUNT) { int altitude = AC_INVALID_ALTITUDE ; diff --git a/mlat/client/coordinator.py b/mlat/client/coordinator.py index fcab6ad..3197e7e 100644 --- a/mlat/client/coordinator.py +++ b/mlat/client/coordinator.py @@ -149,7 +149,12 @@ def update_aircraft(self, now): ac = self.aircraft.get(icao) if not ac: ac = Aircraft(icao) - ac.requested = (icao in self.requested_traffic) + + if(icao>0xFF0000): + ac.requested = (icao in self.requested_modeac) + else: + ac.requested = (icao in self.requested_traffic) + ac.rate_measurement_start = now self.aircraft[icao] = ac @@ -432,6 +437,22 @@ def received_df17(self, message, now): self.server.send_sync(ac.even_message, ac.odd_message) def received_modeac(self, message, now): + #AC Mode + ac = self.aircraft.get(message.address) + if not ac: + ac = Aircraft(message.address) + ac.requested = (message.address in self.requested_modeac) + ac.messages += 1 + ac.last_message_time = now + ac.rate_measurement_start = now + self.aircraft[message.address] = ac + return # wait for more messages + + ac.messages += 1 + ac.last_message_time = now + if ac.messages < 10: + return + if message.address not in self.requested_modeac: return diff --git a/mlat/client/jsonclient.py b/mlat/client/jsonclient.py index 60572ba..d961704 100644 --- a/mlat/client/jsonclient.py +++ b/mlat/client/jsonclient.py @@ -36,7 +36,7 @@ from mlat.client.util import log, monotonic_time from mlat.client.stats import global_stats -DEBUG = False +DEBUG = True # UDP protocol submessages diff --git a/modes_message.c b/modes_message.c index 7613d3b..3eaa78f 100644 --- a/modes_message.c +++ b/modes_message.c @@ -386,22 +386,23 @@ static int decode(modesmessage *self) Py_CLEAR(self->altitude); if (self->datalen == 2) { - - unsigned char ac[2] ; - memcpy(ac , self->data , 2); - - ac_decode_result_t ac_ret = ac_decode(ac) ; - if(ac_ret.type == AC_MODE_A) - { - self->df = DF_MODEAC; - int ac_fix_icao = 0x00FF0000 | ac_ret.squawk ; - self->address = PyLong_FromLong(ac_fix_icao) ; - self->valid = 1; - printf("A Mode:%06X\r\n" ,self->address ); - return 0; - } - else - return -1; + //AC Message decode , A Mode Start With 0xFFXXXX + + unsigned char ac[2] ; + memcpy(ac , self->data , 2); + + ac_decode_result_t ac_ret = ac_decode(ac) ; + if(ac_ret.type == AC_MODE_A) + { + self->df = DF_MODEAC; + int ac_fix_icao = 0x00FF0000 | ac_ret.squawk ; + self->address = PyLong_FromLong(ac_fix_icao) ; + self->valid = 1; + printf("A Mode:%06X\r\n" ,ac_fix_icao); + return 0; + } + else + return -1; } self->df = (self->data[0] >> 3) & 31; diff --git a/modes_reader.c b/modes_reader.c index 1257ee4..6ca7e2a 100644 --- a/modes_reader.c +++ b/modes_reader.c @@ -1384,11 +1384,20 @@ static int filter_message(modesreader *self, PyObject *o) modesmessage *message = (modesmessage *)o; if (message->df == DF_MODEAC) { + if (self->seen != NULL && self->seen != Py_None) + { + if (PySet_Add(self->seen, message->address) < 0) { + printf("DF_MODEAC PySet_Add Failed!\r\n") ; + + return -1; + } + } + + if (self->modeac_filter != NULL && self->modeac_filter != Py_None) { return PySequence_Contains(self->modeac_filter, message->address); } - - return 1; + return 0; } if (!message->valid) { diff --git a/nogps.sh b/nogps.sh new file mode 100755 index 0000000..e68eec4 --- /dev/null +++ b/nogps.sh @@ -0,0 +1 @@ +mlat-client --input-type sbs --input-connect 10.1.1.172:10001 --server 127.0.0.1:12590 --lon 121.429367 --lat 37.525049 --alt 35 --user SHDL From 0f481807f0d30d4a12f0b02c3f4d7321e851f755 Mon Sep 17 00:00:00 2001 From: ybb Date: Tue, 6 Jun 2017 18:56:44 -0700 Subject: [PATCH 10/12] debug --- mlat/client/coordinator.py | 1 + modes_reader.c | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/mlat/client/coordinator.py b/mlat/client/coordinator.py index 3197e7e..ab3cdbd 100644 --- a/mlat/client/coordinator.py +++ b/mlat/client/coordinator.py @@ -438,6 +438,7 @@ def received_df17(self, message, now): def received_modeac(self, message, now): #AC Mode + print("received_modeac : " ,message.addresss ) ac = self.aircraft.get(message.address) if not ac: ac = Aircraft(message.address) diff --git a/modes_reader.c b/modes_reader.c index 6ca7e2a..bd66e7c 100644 --- a/modes_reader.c +++ b/modes_reader.c @@ -1387,8 +1387,6 @@ static int filter_message(modesreader *self, PyObject *o) if (self->seen != NULL && self->seen != Py_None) { if (PySet_Add(self->seen, message->address) < 0) { - printf("DF_MODEAC PySet_Add Failed!\r\n") ; - return -1; } } From 8f3d8ee5bb2000194a57c21fd9c866ea872fed0a Mon Sep 17 00:00:00 2001 From: ybb Date: Tue, 6 Jun 2017 18:59:04 -0700 Subject: [PATCH 11/12] aaaa --- modes_reader.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modes_reader.c b/modes_reader.c index bd66e7c..14139ff 100644 --- a/modes_reader.c +++ b/modes_reader.c @@ -1383,6 +1383,7 @@ static int filter_message(modesreader *self, PyObject *o) { modesmessage *message = (modesmessage *)o; +/* if (message->df == DF_MODEAC) { if (self->seen != NULL && self->seen != Py_None) { @@ -1397,7 +1398,7 @@ static int filter_message(modesreader *self, PyObject *o) } return 0; } - +*/ if (!message->valid) { return self->want_invalid_messages; /* don't process further, contents are dubious */ } From b2c9b0416f90e8f40a7f5fafb1fa2bbc90bb9be6 Mon Sep 17 00:00:00 2001 From: ybb Date: Tue, 6 Jun 2017 20:49:40 -0700 Subject: [PATCH 12/12] add AC Mode --- mlat/client/coordinator.py | 28 ++++++++++++++-------------- modes_message.c | 9 ++++++--- modes_reader.c | 17 ++++++++++------- 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/mlat/client/coordinator.py b/mlat/client/coordinator.py index ab3cdbd..8e5353b 100644 --- a/mlat/client/coordinator.py +++ b/mlat/client/coordinator.py @@ -50,7 +50,7 @@ class Coordinator: update_interval = 5.0 report_interval = 30.0 stats_interval = 900.0 - position_expiry_age = 30.0 + position_expiry_age = 5.0 expiry_age = 60.0 def __init__(self, receiver, server, outputs, freq, allow_anon, allow_modeac): @@ -149,12 +149,7 @@ def update_aircraft(self, now): ac = self.aircraft.get(icao) if not ac: ac = Aircraft(icao) - - if(icao>0xFF0000): - ac.requested = (icao in self.requested_modeac) - else: - ac.requested = (icao in self.requested_traffic) - + ac.requested = (icao in self.requested_traffic) ac.rate_measurement_start = now self.aircraft[icao] = ac @@ -357,8 +352,8 @@ def received_df_misc(self, message, now): return # Candidate for MLAT - if now - ac.last_position_time < self.position_expiry_age: - return # reported position recently, no need for mlat + #if now - ac.last_position_time < self.position_expiry_age: + # return # reported position recently, no need for mlat self.server.send_mlat(message) def received_df11(self, message, now): @@ -381,8 +376,8 @@ def received_df11(self, message, now): return # Candidate for MLAT - if now - ac.last_position_time < self.position_expiry_age: - return # reported position recently, no need for mlat + #if now - ac.last_position_time < self.position_expiry_age: + # return # reported position recently, no need for mlat self.server.send_mlat(message) def received_df17(self, message, now): @@ -435,14 +430,16 @@ def received_df17(self, message, now): # this is a useful reference message pair self.server.send_sync(ac.even_message, ac.odd_message) + self.server.send_mlat(message) def received_modeac(self, message, now): #AC Mode - print("received_modeac : " ,message.addresss ) + + #print("received_modeac : " ,message.address ) ac = self.aircraft.get(message.address) if not ac: ac = Aircraft(message.address) - ac.requested = (message.address in self.requested_modeac) + ac.requested = (message.address in self.requested_traffic) ac.messages += 1 ac.last_message_time = now ac.rate_measurement_start = now @@ -454,7 +451,10 @@ def received_modeac(self, message, now): if ac.messages < 10: return - if message.address not in self.requested_modeac: + ac.recent_adsb_positions += 1 + #if message.address not in self.requested_modeac: + # return + if not ac.requested: return self.server.send_mlat(message) diff --git a/modes_message.c b/modes_message.c index 3eaa78f..13c6fc1 100644 --- a/modes_message.c +++ b/modes_message.c @@ -385,12 +385,12 @@ static int decode(modesmessage *self) Py_CLEAR(self->address); Py_CLEAR(self->altitude); + if (self->datalen == 2) { //AC Message decode , A Mode Start With 0xFFXXXX unsigned char ac[2] ; memcpy(ac , self->data , 2); - ac_decode_result_t ac_ret = ac_decode(ac) ; if(ac_ret.type == AC_MODE_A) { @@ -398,13 +398,16 @@ static int decode(modesmessage *self) int ac_fix_icao = 0x00FF0000 | ac_ret.squawk ; self->address = PyLong_FromLong(ac_fix_icao) ; self->valid = 1; - printf("A Mode:%06X\r\n" ,ac_fix_icao); return 0; } else - return -1; + { + self->valid = 0; + } + } + self->df = (self->data[0] >> 3) & 31; if ((self->df < 16 && self->datalen != 7) || (self->df >= 16 && self->datalen != 14)) { diff --git a/modes_reader.c b/modes_reader.c index 14139ff..d5c8138 100644 --- a/modes_reader.c +++ b/modes_reader.c @@ -1383,7 +1383,6 @@ static int filter_message(modesreader *self, PyObject *o) { modesmessage *message = (modesmessage *)o; -/* if (message->df == DF_MODEAC) { if (self->seen != NULL && self->seen != Py_None) { @@ -1393,16 +1392,20 @@ static int filter_message(modesreader *self, PyObject *o) } - if (self->modeac_filter != NULL && self->modeac_filter != Py_None) { - return PySequence_Contains(self->modeac_filter, message->address); - } - return 0; + // if (self->modeac_filter != NULL && self->modeac_filter != Py_None) { + // return PySequence_Contains(self->modeac_filter, message->address); + // } + // return -1; + + return 1 ; } -*/ - if (!message->valid) { + + + if (!message->valid) { return self->want_invalid_messages; /* don't process further, contents are dubious */ } + if (self->seen != NULL && self->seen != Py_None) { if (message->df == 11 || message->df == 17 || message->df == 18) { /* note that we saw this aircraft, even if the message is filtered.