532 lines
18 KiB
C#
532 lines
18 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using AdamThinkDevicesData;
|
||
|
||
using Newtonsoft.Json;
|
||
using static InterfaceManager;
|
||
using System;
|
||
using UnityEngine.UI;
|
||
using UnityEngine.EventSystems;
|
||
|
||
|
||
/*
|
||
地面无线电干扰对无人机的干扰通常是指对其数据链通信频点的干扰,而不是卫星定位频点的干扰。
|
||
|
||
无人机通常通过数据链与地面控制站进行通信,用于传输指令、图像、视频等数据。这些数据链通信频点通常在特定频段内使用,例如2.4GHz或5.8GHz等。地面无线电干扰可能会在这些频点上发射无关信号,导致无人机与地面控制站之间的通信受到干扰。
|
||
|
||
卫星定位频点(如GPS)通常用于无人机的导航和定位。地面无线电干扰通常不会直接干扰到这些卫星定位频点,因为这些频点由卫星系统控制并具有较高的抗干扰能力。然而,如果地面无线电干扰源的信号干扰范围广泛,可能会产生杂散信号,从而影响无人机的GPS接收机的性能。
|
||
|
||
需要注意的是,针对无人机的干扰行为是非法且危险的,违反了无人机的安全运行规定。在使用无人机或遇到无人机干扰时,应当及时报告相关部门并采取相应的措施。
|
||
*/
|
||
/// <summary>
|
||
/// 地面无线电干扰控制
|
||
/// </summary>
|
||
public class TerrestrialRadioInterferenceManger : MonoBehaviour
|
||
{
|
||
|
||
public EquipmentCommon equipmentCommon;
|
||
|
||
public string deviceID;
|
||
|
||
public static List<TerrestrialRadioInterferenceManger> terrestrialRadioInterferenceMangers = new List<TerrestrialRadioInterferenceManger>();
|
||
#region 地面无线电干扰数据
|
||
/// <summary>
|
||
/// 干扰频率
|
||
/// </summary>
|
||
public string InterferingFrequency;
|
||
/// <summary>
|
||
/// 干扰模式
|
||
/// </summary>
|
||
public string InterferenceMode;
|
||
/// <summary>
|
||
/// 发射功率
|
||
/// </summary>
|
||
public string TransmittedPower;
|
||
/// <summary>
|
||
/// 干扰角度
|
||
/// </summary>
|
||
public string InterferenceAngle;
|
||
/// <summary>
|
||
/// 干扰距离
|
||
/// </summary>
|
||
public string InterferenceDistance;
|
||
|
||
#endregion
|
||
|
||
public float detectionRadius = 5f; // 检测范围半径
|
||
|
||
#region 启动暂停
|
||
private bool _isStartRehearsing = false;
|
||
/// <summary>
|
||
/// 是否正在预演
|
||
/// </summary>
|
||
public bool isStartRehearsing
|
||
{
|
||
get { return _isStartRehearsing; }
|
||
set
|
||
{
|
||
if (_isStartRehearsing != value)
|
||
{
|
||
_isStartRehearsing = value;
|
||
OnActivationChanged?.Invoke(_isStartRehearsing);
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 布尔值变化时触发的事件
|
||
/// </summary>
|
||
public event System.Action<bool> OnActivationChanged;
|
||
/// <summary>
|
||
/// 协程对象
|
||
/// </summary>
|
||
private Coroutine timerCoroutine;
|
||
/// <summary>
|
||
/// 定时器运行状态
|
||
/// </summary>
|
||
private bool isTimerRunning = false;
|
||
/// <summary>
|
||
/// 间隔时间
|
||
/// </summary>
|
||
public float interval = 5.0f;
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 爆炸预制体
|
||
/// </summary>
|
||
public GameObject explodePrefab;
|
||
/// <summary>
|
||
/// 飞机迫降的速度
|
||
/// </summary>
|
||
public float speed = 1;
|
||
/// <summary>
|
||
/// 地面的图层
|
||
/// </summary>
|
||
public LayerMask ground;
|
||
/// <summary>
|
||
/// 干扰的频率
|
||
/// </summary>
|
||
//public Toggle toggle1, toggle2, toggle3, toggle4, toggle5, toggle6, toggle7;
|
||
|
||
/// <summary>
|
||
/// 探测频段设置
|
||
/// </summary>
|
||
public List<Toggle> togInterferenceBand = new List<Toggle>();
|
||
/// <summary>
|
||
/// 激活选择波段页面
|
||
/// </summary>
|
||
public Image Waveimage;
|
||
/// <summary>
|
||
/// 关闭页面按钮
|
||
/// </summary>
|
||
public Button buttonoff;
|
||
/// <summary>
|
||
/// 接收最终的频段
|
||
/// </summary>
|
||
public string disturb;
|
||
/// <summary>
|
||
/// 接收接口的频段
|
||
/// </summary>
|
||
public string InterferingFrequency1;
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
private bool onlyOne = true;
|
||
void Awake()
|
||
{
|
||
terrestrialRadioInterferenceMangers.Add(this);
|
||
// 订阅布尔值变化事件
|
||
OnActivationChanged += OnActivationChangedHandler;
|
||
}
|
||
void Start()
|
||
{
|
||
equipmentCommon = GetComponent<EquipmentCommon>();
|
||
_isStartRehearsing = GlobalFlag.isStartRehearsing;
|
||
Waveband();
|
||
}
|
||
|
||
private void Waveband()
|
||
{
|
||
|
||
//探测频段设置
|
||
foreach (Toggle toggle in togInterferenceBand)
|
||
{
|
||
toggle.onValueChanged.AddListener(delegate { InterferenceBand(toggle); });
|
||
}
|
||
|
||
buttonoff.onClick.AddListener(() =>
|
||
{
|
||
Waveimage.gameObject.SetActive(false);
|
||
});
|
||
}
|
||
|
||
/// <summary>
|
||
/// 探索频段设置
|
||
/// </summary>
|
||
/// <param name="change"></param>
|
||
void InterferenceBand(Toggle change)
|
||
{
|
||
if (change.isOn)
|
||
{
|
||
disturb = change.transform.name;
|
||
|
||
equipmentCommon.SetDatabaseInfo("scan_rate", disturb);
|
||
}
|
||
}
|
||
private void disturb1()
|
||
{
|
||
if (InterferingFrequency1.Length > 0)
|
||
{
|
||
string[] str = InterferingFrequency1.Split(',');
|
||
for (int i = 0; i < str.Length; i++)
|
||
{
|
||
var tog = togInterferenceBand.Find(x => x.transform.name == str[i]);
|
||
if(tog)
|
||
tog.gameObject.SetActive(true);
|
||
}
|
||
}
|
||
}
|
||
|
||
// Update is called once per frame
|
||
void Update()
|
||
{
|
||
if (WRJs.Count > 0 && isDo)
|
||
{
|
||
isDo = false;
|
||
Transform wrj = WRJs.Dequeue();
|
||
Interferencemode(wrj);
|
||
}
|
||
|
||
//Interferencemode();
|
||
//Angularrange();
|
||
}
|
||
|
||
|
||
public GraphicRaycaster RaycastInCanvas;
|
||
|
||
|
||
|
||
#region 启动暂停
|
||
/// <summary>
|
||
/// 导条变化调用
|
||
/// </summary>
|
||
/// <param name="newValue"></param>
|
||
public void OnActivationChangedHandler(bool newValue)
|
||
{
|
||
if (newValue)
|
||
{
|
||
StartTimer();
|
||
}
|
||
else
|
||
{
|
||
StopTimer();
|
||
}
|
||
}
|
||
|
||
|
||
IEnumerator Timer()
|
||
{
|
||
while (true)
|
||
{
|
||
//Debug.Log("Timer fired at: " + Time.time);
|
||
yield return new WaitForSeconds(0.5f); // 等待一段时间后继续执行
|
||
RadioDisturbance();
|
||
//Interferencemode();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 开启
|
||
/// </summary>
|
||
public void StartTimer()
|
||
{
|
||
if (equipmentCommon.isPlayer && timerCoroutine == null)
|
||
{
|
||
timerCoroutine = StartCoroutine(Timer());
|
||
isTimerRunning = true;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 停止
|
||
/// </summary>
|
||
public void StopTimer()
|
||
{
|
||
if (equipmentCommon.isPlayer && timerCoroutine != null)
|
||
{
|
||
StopCoroutine(timerCoroutine);
|
||
timerCoroutine = null;
|
||
isTimerRunning = false;
|
||
}
|
||
}
|
||
#endregion
|
||
/// <summary>
|
||
/// 检索到的同频段无人机
|
||
/// </summary>
|
||
Queue<Transform> WRJs = new Queue<Transform>();
|
||
/// <summary>
|
||
/// 逐个驱离
|
||
/// </summary>
|
||
private bool isDo = true;
|
||
/// <summary>
|
||
/// 数据写入
|
||
/// </summary>
|
||
/// <param name="weaponitemone"></param>
|
||
public void FillInTheData(List<List_paraItem> weaponitemone, string _deviceId)
|
||
{
|
||
deviceID = _deviceId;
|
||
for (int i = 0; i < weaponitemone.Count; i++)
|
||
{
|
||
switch (weaponitemone[i].para_name)
|
||
{
|
||
case "干扰频率:":
|
||
string[] str = weaponitemone[i].para_value.Split(',');
|
||
if (str.Length > 0)
|
||
{
|
||
for (int j = 0; j < str.Length; j++)
|
||
{
|
||
switch (str[j])
|
||
{
|
||
case "0":
|
||
InterferingFrequency1 += "UHF" + ",";
|
||
break;
|
||
case "1":
|
||
InterferingFrequency1 += "L" + ",";
|
||
break;
|
||
case "2":
|
||
InterferingFrequency1 += "S" + ",";
|
||
break;
|
||
case "3":
|
||
InterferingFrequency1 += "C" + ",";
|
||
break;
|
||
case "4":
|
||
InterferingFrequency1 += "X" + ",";
|
||
break;
|
||
case "5":
|
||
InterferingFrequency1 += "Ku" + ",";
|
||
break;
|
||
case "6":
|
||
InterferingFrequency1 += "Ka" + ",";
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
break;
|
||
case "干扰模式:":
|
||
switch (weaponitemone[i].para_value)
|
||
{
|
||
case "0":
|
||
InterferenceMode = "驱离";
|
||
break;
|
||
case "1":
|
||
InterferenceMode = "迫降";
|
||
break;
|
||
default:
|
||
InterferenceMode = "驱离";
|
||
break;
|
||
}
|
||
break;
|
||
case "发射功率:":
|
||
switch (weaponitemone[i].para_value)
|
||
{
|
||
case "0":
|
||
TransmittedPower = "10~30W";
|
||
break;
|
||
case "1":
|
||
TransmittedPower = "30~50W";
|
||
break;
|
||
case "2":
|
||
TransmittedPower = "50~100W";
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
break;
|
||
case "干扰角度:":
|
||
InterferenceAngle = weaponitemone[i].para_value;
|
||
break;
|
||
case "干扰距离:":
|
||
InterferenceDistance = weaponitemone[i].para_value;
|
||
detectionRadius = float.Parse(InterferenceDistance);
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
disturb1();//激活对应接口里的波段
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 干扰模式
|
||
/// </summary>
|
||
public void Interferencemode(Transform wrj)
|
||
{
|
||
UnmannedAerialVehicleManage unmannedAerialVehicleManage = wrj.GetComponent<UnmannedAerialVehicleManage>();
|
||
if (unmannedAerialVehicleManage)
|
||
{
|
||
unmannedAerialVehicleManage = wrj.GetComponent<UnmannedAerialVehicleManage>();
|
||
unmannedAerialVehicleManage.CheckSatellitePositioningFrequency(
|
||
InterferenceMode);
|
||
var nowData = GetSyncData(unmannedAerialVehicleManage);
|
||
MyNetMQClient.instance.Send(nowData);
|
||
//DeviceManager.Instance.send2roomStr.Enqueue(nowData);
|
||
//MQTTManager.instance.SendData(MQTTManager.instance.WRJExpel, nowData);
|
||
}
|
||
UnmannedAerialVehicle unmannedAerialVehicle = wrj.GetComponent<UnmannedAerialVehicle>();
|
||
if (unmannedAerialVehicle && unmannedAerialVehicle.transform.localPosition != Vector3.zero)
|
||
{
|
||
unmannedAerialVehicle = wrj.GetComponent<UnmannedAerialVehicle>();
|
||
unmannedAerialVehicle.CheckSatellitePositioningFrequency(
|
||
InterferenceMode);
|
||
var nowData = GetSyncData(unmannedAerialVehicle);
|
||
MyNetMQClient.instance.Send(nowData);
|
||
//DeviceManager.Instance.send2roomStr.Enqueue(nowData);
|
||
//MQTTManager.instance.SendData(MQTTManager.instance.WRJDitch, nowData);
|
||
}
|
||
isDo = true;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 无人机整体驱离
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
protected string GetSyncData(UnmannedAerialVehicleManage unmannedAerialVehicleManage)
|
||
{
|
||
return string.Format("{0},{1},{2}", "WRJExpel", unmannedAerialVehicleManage.equipmentCommon.deviceID, InterferenceMode);
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="unmannedAerialVehicle"></param>
|
||
/// <returns></returns>
|
||
protected string GetSyncData(UnmannedAerialVehicle unmannedAerialVehicle)
|
||
{
|
||
return string.Format("{0},{1},{2},{3}", "WRJDitch", unmannedAerialVehicle.unmannedAerialVehicleManage.equipmentCommon.deviceID, unmannedAerialVehicle.serialNumber, InterferenceMode);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 开启无线电干扰
|
||
/// </summary>
|
||
public void RadioDisturbance()
|
||
{
|
||
Collider[] colliders = Physics.OverlapSphere(transform.position, detectionRadius * 1000 / 5);// 检索范围内的所有碰撞体
|
||
|
||
for (int i = 0; i < colliders.Length; i++)
|
||
{
|
||
if (colliders[i].transform.tag == "WRJ")
|
||
{
|
||
UnmannedAerialVehicleManage unmannedAerialVehicleManage = colliders[i].GetComponent<UnmannedAerialVehicleManage>();
|
||
//Debug.Log("检测到无人机: " + col.name);
|
||
UnmannedAerialVehicle unmannedAerialVehicle = colliders[i].GetComponent<UnmannedAerialVehicle>();
|
||
if (unmannedAerialVehicleManage)
|
||
{
|
||
//Debug.Log(col.name+"数据链通信频点...:" + unmannedAerialVehicle.dataLinkCommunicationFrequency);
|
||
if (unmannedAerialVehicleManage.dataLinkCommunicationFrequency == "" || disturb == "") continue;//无数据不执行
|
||
//if (unmannedAerialVehicleManage.dataLinkCommunicationFrequency == InterferingFrequency)
|
||
if (unmannedAerialVehicleManage.dataLinkCommunicationFrequency == disturb)
|
||
{
|
||
Debug.Log("干扰...:" + colliders[i].name + "成功。");
|
||
//unmannedAerialVehicle.BeAssaulted("无线电干扰");
|
||
Vector3 one = unmannedAerialVehicleManage.transform.position - transform.position;
|
||
float angue = Vector3.Angle(one, transform.forward);
|
||
if (float.Parse(InterferenceAngle) >= angue)
|
||
{
|
||
WRJs.Enqueue(unmannedAerialVehicleManage.transform);
|
||
}
|
||
}
|
||
}
|
||
else if (unmannedAerialVehicle)
|
||
{
|
||
//Debug.Log(col.name+"数据链通信频点...:" + unmannedAerialVehicle.dataLinkCommunicationFrequency);
|
||
if (unmannedAerialVehicle.dataLinkCommunicationFrequency == "" || disturb == "") continue;//无数据不执行
|
||
//if (unmannedAerialVehicle.dataLinkCommunicationFrequency == InterferingFrequency)
|
||
if (unmannedAerialVehicle.dataLinkCommunicationFrequency == disturb)
|
||
{
|
||
Debug.Log("干扰...:" + colliders[i].name + "成功。");
|
||
//unmannedAerialVehicle.BeAssaulted("无线电干扰");
|
||
Vector3 one = unmannedAerialVehicle.transform.position - transform.position;
|
||
float angue = Vector3.Angle(one, transform.forward);
|
||
if (float.Parse(InterferenceAngle) >= angue)
|
||
{
|
||
WRJs.Enqueue(unmannedAerialVehicle.transform);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
///上传日志
|
||
/// </summary>
|
||
/// <param name="deviceID"></param>
|
||
public void UploadLog(string _log)
|
||
{
|
||
|
||
List<UploadLogMain> uploadLogMains = new List<UploadLogMain>();
|
||
UploadLogMain uploadLogMain = new UploadLogMain();
|
||
uploadLogMain.PracticeId = GlobalFlag.practiceSubjectID;
|
||
uploadLogMain.ThinkId = GlobalFlag.currentThinkId;
|
||
uploadLogMain.log = _log;
|
||
uploadLogMains.Add(uploadLogMain);
|
||
string uploadLogMainJson = JsonConvert.SerializeObject(uploadLogMains);
|
||
WWWForm wWWForm = new WWWForm();
|
||
wWWForm.AddField("data", uploadLogMainJson);
|
||
Debug.Log(uploadLogMainJson);
|
||
StartCoroutine(PostString(Url_Addpracticelog, wWWForm, data =>
|
||
{
|
||
Debug.Log(data);
|
||
}));
|
||
}
|
||
|
||
|
||
|
||
private void OnDestroy()
|
||
{
|
||
Destroy(Waveimage.gameObject);
|
||
OnActivationChanged -= OnActivationChangedHandler;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 干扰无人机角度范围
|
||
/// </summary>
|
||
/// <exception cref="NotImplementedException"></exception>
|
||
private void Angularrange()
|
||
{
|
||
Collider[] collider = Physics.OverlapSphere(transform.position, 300);
|
||
for (int i = 0; i < collider.Length; i++)
|
||
{
|
||
if (collider[i].transform.tag == "WRJ")
|
||
{
|
||
UnmannedAerialVehicle unmannedAerialVehicle = collider[i].GetComponent<UnmannedAerialVehicle>();
|
||
Vector3 one = unmannedAerialVehicle.transform.position - transform.position;
|
||
float angue = Vector3.Angle(transform.forward, one);
|
||
if (float.Parse(InterferenceAngle) >= angue)
|
||
{
|
||
//Debug.LogError("目标出现在范围内");
|
||
}
|
||
else
|
||
{
|
||
//Debug.LogError("目标没有出现在范围里面");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void OnMouseDown()
|
||
{
|
||
if (!GlobalFlag.isStartRehearsing && GlobalFlag.blueOrRed == 1 && Input.GetMouseButtonDown(0))
|
||
{
|
||
GameManager.Instance.GetAllImportance();
|
||
Waveimage.transform.position = Camera.main.WorldToScreenPoint(transform.position);
|
||
Waveimage.gameObject.SetActive(true);
|
||
}
|
||
}
|
||
}
|