以Cat62格式雷达数据为例,十六进制雷达数据部分代码:
3e0120bf7da4ffee0085
雷达数据使用2个字符(1个字节)标识,在这里是“3e”,转换为十进制数为62。
雷达数据类型父类:
base_header_processor.h
//
// Created by qiaowei on 2024-02-02.
//#ifndef RADARDATACONTROLLER_BASE_HEADER_PROCESSOR_H
#define RADARDATACONTROLLER_BASE_HEADER_PROCESSOR_H#include <QString>namespace processor {/*** @copyright 2003-2024* @date 10:54* @author qiao wei* @version 1.0* @brief 解析雷达数据中雷达类型的接口。返回雷达类型标识类型标识为int类型。* @history*/class BaseHeaderProcessor {public:/*** @author qiao wei* @brief 返回雷达数据的类型标识。* @param track_data 需要解析的雷达数据。* @param position_index 雷达类型标识最后一个字符在字符串track_data的索引。* @return 雷达数据类型。* @history*/virtual int processor(const QString& track_data,int begin_position,int& readed_data_end_position) = 0;};} // processor#endif //RADARDATACONTROLLER_BASE_HEADER_PROCESSOR_H
cat_62_header_processor.h
//
// Created by qiaowei on 2024-02-02.
//#ifndef RADARDATACONTROLLER_CAT_62_HEADER_PROCESSOR_H
#define RADARDATACONTROLLER_CAT_62_HEADER_PROCESSOR_H#include <QObject>
#include <QString>#include "../baseprocess/base_header_processor.h"namespace processor {class Cat62HeaderProcessor : public QObject, public BaseHeaderProcessor {public:explicit Cat62HeaderProcessor(QObject* parent = nullptr);virtual ~Cat62HeaderProcessor() override;/*** @author qiao wei* @brief 读取track_data字符串中雷达数据类型并将类型返回,是Cat62还是Cat21。* @param track_data 十六进制雷达数据。* @param readed_data_end_position 雷达数据中数据头最后一个字符的索引。* @return 雷达数据类型。* @history*/virtual int processor(const QString& track_data,int begin_position,int& readed_data_end_position) override;};} // processor#endif //RADARDATACONTROLLER_CAT_62_HEADER_PROCESSOR_H
cat_62_header_processor.cpp
//
// Created by qiaowei on 2024-02-02.
//#include "cat_62_header_processor.h"namespace processor {Cat62HeaderProcessor::Cat62HeaderProcessor(QObject* parent) : QObject(parent) {}Cat62HeaderProcessor::~Cat62HeaderProcessor() {}int Cat62HeaderProcessor::processor(const QString& track_data,int begin_position,int& readed_data_end_position) {// 雷达数据中数据类型项最后一个字符的索引。readed_data_end_position = 1;return track_data.mid(begin_position, 2).toInt(nullptr, 16);}} // processor
main.cpp
#include <string>#include <QApplication>
#include <QVector>
#include <QtDebug>
#include <QString>#include "./form/main_window.h"
#include "./cat62process/cat62_fspec_processor.h"
#include "./cat62process/cat_62_length_processor.h"
#include "./cat62process/cat_62_header_processor.h"using std::string;using form::MainWindow;
using processor::Cat62FspecProcessor;
using processor::Cat62HeaderProcessor;
using processor::Cat62LengthProcessor;int main(int argc,char *argv[]) {QApplication a(argc, argv);// MainWindow* main_window{new MainWindow{nullptr}};
// main_window->show();QString content = "3e0120bf7da4ffee00859";int end_position{0};Cat62HeaderProcessor* header_processor{new Cat62HeaderProcessor{}};qDebug()<< header_processor->processor(content, 0, end_position);return QApplication::exec();
}
测试结果: