某无线通信设备ODU设备, 具有以下功能:
- 查看发射功率, 设置发射功率.
- 查看发射频率, 设置发射频率.
- 查看带宽, 修改带宽.
- 查看设备概述(个指标的值).
后来对该产品做了升级, 研发成了ODU330产品:
这个产品, 新增加了以下功能:
- 查看当前的误码率.
- 查看误码率告警门限
- 设置误码率告警门限
参考:
OUD.h
#pragma once
#include <string>
class ODU
{
public:
ODU();
~ODU();
float get_tx_power();
int get_tx_freq();
float get_band_width();
bool set_tx_power(float tx_power);
bool set_tx_freq(int tx_freq);
bool set_band_width(float band_width);
std::string description();
protected:
float tx_power; /* 发射功率 */
int tx_freq; /* 发射频率 */
float band_width; /* 带宽, 单位: M*/
};
ODU.cpp
#include "ODU.h"
#include <sstream>
using namespace std;
ODU::ODU()
{
}
ODU::~ODU()
{
}
float ODU::get_tx_power()
{
return tx_power;
}
int ODU::get_tx_freq()
{
return tx_freq;
}
float ODU::get_band_width()
{
return band_width;
}
bool ODU::set_tx_power(float tx_power)
{
this->tx_power = tx_power;
return true;
}
bool ODU::set_tx_freq(int tx_freq)
{
this->tx_freq = tx_freq;
return true;
}
bool ODU::set_band_width(float band_width)
{
this->band_width = band_width;
return true;
}
std::string ODU::description()
{
stringstream ret;
ret << "发射功率:" << tx_power << "\t发射功率:" << tx_freq
<< "\t带宽:" << band_width;
return ret.str();
}
ODU330.h
#pragma once
#include "ODU.h"
#include <string>
using namespace std;
class ODU330 :public ODU
{
public:
ODU330();
~ODU330();
float get_warn_threshold(); /* 获取告警门限 */
bool set_warn_threshold(float warn_threshold); /* 设置告警门限*/
float get_error_rate(); /* 获取当前的误码率 */
string description(); /* 描述 */
private:
float warn_threshold; /* 告警门限 */
};
ODU330.cpp
#include "ODU330.h"
#include "ODU.h"
#include <sstream>
using namespace std;
ODU330::ODU330()
{
}
ODU330::~ODU330()
{
}
float ODU330::get_warn_threshold()
{
return warn_threshold;
}
bool ODU330::set_warn_threshold(float warn_threshold)
{
this->warn_threshold = warn_threshold;
return true;
}
float ODU330::get_error_rate()
{
return 0.00005f; /* 模拟值 */
}
string ODU330::description()
{
stringstream ret;
ret << "发射功率: " << get_tx_power() << "\t发射频率:" << get_tx_freq()
<< "\t带宽:" << get_band_width() << "\t误码率:" << get_error_rate()
<< "\t告警门限:" << get_warn_threshold();
return ret.str();
}
main.cpp
#include <iostream>
#include "ODU.h"
#include "ODU330.h"
using namespace std;
int main()
{
ODU odu1;
odu1.set_band_width(500);
odu1.set_tx_freq(114000);
odu1.set_tx_power(45);
cout << odu1.description() << endl;
ODU330 odu2;
odu2.set_band_width(600);
odu2.set_tx_freq(119000);
odu2.set_tx_power(48);
odu2.set_warn_threshold(0.0001);
cout << odu2.description() << endl;
system("pause");
return 0;
}
运行环境: vs2019
运行结果:
结语:
学到的知识要, 多复习, 多总结, 多敲. 需要时间的积累, 才能引起质的改变. 自己写不出来的永远是别人的.
分享一下我的技巧: 代数法把具体的数字带进去, 看看能能能找到规律(掌握思想).
还有就是画图, 也很重要. 用笔画出来, 把数代进去, 方法虽然笨, 但真的很实用, 好记忆不如烂笔头!!!
我是小白, 如果存在问题, 欢迎大神给予评判指正.
错了不可怕, 可怕的是找不出bug
今日是: 2020年5月3日, (由于疫情的原因)在家里整天坐在电脑前, 眼神逐渐从大到小.写博客, 就当写写日记吧!!!,
希望给个赞: 反正你又不亏, 顺便而已