工作:雷达数据解析,获取FSPEC标志位

105 篇文章 5 订阅
7 篇文章 0 订阅

package processdata;


/**
 * @copyright 2003-2024
 * @author    qiao wei
 * @date      2024-01-21
 * @version   1.0
 * @brief     对欧控(Euro control)标准中雷达数据的FSPEC内容进行解析。适用读取Cat62格式数据。
 * @history   name/date/brief
 */
public class FspecProcessor {
    
    public FspecProcessor() {}
    
    /**
     * @author  qiao wei
     * @brief   处理雷达数据中的FSPEC内容。从完整可用的雷达数据中提取对应的FSPEC,将FSPEC中的内容按规范转换
     *          成int[]并返回。
     * @param   content 需要处理的雷达数据。
     * @param   beginPosition 数据的起始位置。
     * @param   step FSPEC数据的步长。每个字节由2个字符组成,步长为2。
     * @return  
     * @throws  NumberFormatException 将String格式数据转换为int类型抛出异常。
     * @history 
     */
    public int[] result(String content, int beginPosition, int step) {
        // 计数器。统计从参数content读取FSPEC字节的个数。
        int count = 0;
        
        // 保存转换成类型int后的FSPEC数据,一次只保存1个字节。
        int value = 0;
        
        // 保存1个字节的FSPEC数据。
        String aByteFspecContent = null;
        
        // 保存FSPEC数据。
        StringBuffer fspecContentBuffer = new StringBuffer();
        
        while (true) {
            /**
             * 获取雷达数据中的FSPEC数据,将FSPCES数据保存到fspecContentBuffer,因为FSPEC是由多个字节组成,每次读
             * 取2个字符(2个字符等于1个字节)。
             */
            aByteFspecContent = content.substring(beginPosition, beginPosition + step);
            
            try {
                value = Integer.parseInt(aByteFspecContent, 16);
                fspecContentBuffer.append(aByteFspecContent);
                count++;
            } catch (NumberFormatException exception) {
                exception.printStackTrace();
            }
            
            // 判断读取的FSPEC数据是否到结尾,如果没到结尾,继续读取2字节数据,反之直接退出循环。
            if ((THE_0_POSITION_VALUE & value) == THE_0_POSITION_VALUE) {
                // 将起始位后移1个字节(2个字符)。
                beginPosition += step;
            } else {
                break;
            }
        }

        return convertFspecToIntArray(fspecContentBuffer.toString(), count);
    }

    public static void main(String[] args) {
        FspecProcessor process = new FspecProcessor();
        String content = "3e0120bf7da4ffee00859880007205a0010f7f00dd4ca4158f60fd0e02030a65000d0072df1820c07892130d0072df182002c601010176f005540000bf7da4ffee00859880007376c0010dd2e0dc05bc1780bdfeeefc9c005900541173cb3820c0896188541173cb382003a001010176f005a40000bf7da4ffee0085988000771d00010f0160ddbb311bb37ffd1dfeea0065004544b8c37820c006a12f4544b8c37820034401010176f005f40000bf7da4ffee0085988000773ca0010ee1a0dda5091bdd52fd000167003d00508678e60820c04ba950508678e60820044201010176f005040000bf7da4ffee0085988000785a2001105f00df28131d033701b0fc8c0426002c1339e72820c071c2282c1339e728200a2601010176f005cc0000";
        String content01 = "3e03a9bf4da4ffee008599000054ba400128cb80f2f92ef07d02ff92024e0e3b012b0101015ef800fbffc6bf4da4ffee00859900005443a00128f920f32301efedadffb9028c01eb0b870101015ef801b4ff14bf4da4ffee0085990000555a6001286040f291ddf14056ff26fcda035209780101015ef40414007fbf4da4ffee0085990000567e2001277200f1aa97f2a6e300ac01780a1c02db0101015ef800ceffcabf7da4ffee00859900005b6de00128c340f34598f8780afffe03d00a760020b0f9d39ce0ef07f14c780a1320b0f9d39ce0ffaf0000000000000000000000000000ffaf000000000000000008e801010146f005a40000bf7da4ffee00859900005deda00128cdc0f37052fb713bfffc04290ade000d0072cf3820ef07f14c7892310d0072cf3820ffaf0000000000000000000000000000ffaf000000000000000004da01010146f005540000bf7da4ffee00859900005f340001286760f31aa3fcf9ecfff4fc190184000420b8df0820ef07f14c440c5c0420b8df0820ffaf0000000000000000000000000000ffaf0000000000000000007301010146f004280000bf7da4ffee008599000061278001284f80f31d94ff4d67fffefc9e019800058177e38c20ef07f14c505ca4058177e38c20858601b6061c061cfffb0005ff9c00007e6c078a000000e8005f00bb01010146f0061c0000bf7da4ffee008599000064e9a0012878c0f3799703c4e3000804310365000c8237e79c60ef07f14c780ff10c8237e79c60fc2101ea05a405a400dc000500640000fe43092c000001190069017b01010146f005a40000bf7da4ffee00859900006878a001275ac0f298a5080eedfce702220a68000d0072e39820ef07f14c7892140d0072e39820d51101ee05540554ff4dfffb00640000d5c70840000001260069017601010146f005540000bf7da4ffee00859900006ba38001272fa0f2a0550bd734fea503770355000c3074cf1820ef07f14c78115b0c3074cf1820eb1601d405540554ffc3fffbff9c0000eea308400000011500640b3801010146f005550000bf7da4ffee00859900006fa18001269b40f2554610a134fcce0167006200508671e79820ef07f14c4ba94d508671e79820cdf701e805040504001f000a00000000cead07ae0000012e0069027401010146f005040000bf7da4ffee008599000075494001280c20f40102175144fcf10154005c002c1335e71820ef07f14c71be102c1335e71820cdf701f205040504ffcd000500000000cead0753000001340069078d01010146f005050000";
//        process.result(content01, 6, 2);

        
//
//        int value = 0;
//
//        try {
//            value = Integer.parseInt("bf", 16);
//        } catch (NumberFormatException e) {
//            throw new RuntimeException(e);
//        }

        int[] array = process.convertFspecToIntArray("bf4da4", 3);
        
        for (int i = 0; i != array.length; ++i) {
            System.out.print(array[i]);
            
            if (i % 7 != 0) {
                System.out.print(",");
            }
        }
        
        System.out.println("successful");
    }
    
    /**
     * @author  qiao wei
     * @brief   将存储FSPEC内容由十六进制的字符串转换为二进制的int[]。
     * @param   content FSPEC内容字符串。
     * @param   count FSPEC内容的字节数。因为参数content是2个字符组成1个字节,所以count数为字符串中字符数量的一半。
     * @return  FSPEC内容转换为二进制后的int[]数组。
     * @throws  NumberFormatException 将String格式数据转换为int类型抛出异常。
     * @history name/date/brief
     */
    private int[] convertFspecToIntArray(String content, int count) {
        /**
         * 雷达数据中,2个字符表示1个字节。
         * 根据字节数设置对应的int[]容量。1个字节是8位二进制数。
         */
        int byteCount = content.length() / 2;
        int[] array = new int[byteCount * 8];
        
        // 步长。
        final int step = 2;
        int startPosition = 0;
        int value = 0;
        
        for (int index = 0; index != count; index++) {
            try {
                value = Integer.parseInt(content.substring(startPosition, startPosition + step), 16);
            } catch (NumberFormatException exception) {
                exception.printStackTrace();
            }
            
            insertBinaryValueToArray(array, value, index * 8);
            startPosition += step;
        }
        
        return array;
    }
    
    /**
     * @author  qiao wei
     * @brief   将数据value以二进制数的格式保存到数组int[]的指定位置处。传入的value是1个字节,将其转换为8位二进制数
     *          从左向右保存,因为每次只能保存1个字节的数据,保存多个字节的数据需要依次保存到数组int[]中,
     * @param   array 存储二进制数的数组。
     * @param   value FSPES数据中的1个字节。
     * @return  
     * @throws  
     * @history name/date/brief
     */
    private void insertBinaryValueToArray(int[] array, int value, int beginPosition) {
        final int count = 8;
        
        /**
         * 1:依次遍历value值的每一位(8位二进制,从左侧高位开始依次遍历),并将二级制值保存到数组。
         * 2:右移1位。依次读取value中每一位二进制值。
         */
        for (int i = 0; i != count; ++i) {
            array[beginPosition + i] = ((128 == (value & THE_7_POSITION_VALUE)) ? 1 : 0);
            value = value << 1;
        }
    }
    
    /**
     * @author qiao wei
     * @brief  标识位,通过与运算判断字节最后一位是否为0。0B00000001。
     */
    final static int THE_0_POSITION_VALUE = 1;
    
    /**
     * @author qiao wei
     * @brief  0B10000000。
     */
    final static int THE_7_POSITION_VALUE = 128;
}

  • 7
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值