123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Net.Http;
- using System.Net.Sockets;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using XdCxRhDW.Dto;
- using XdCxRhDW.Sender.Properties;
- namespace XdCxRhDW.Sender
- {
- public partial class Form1 : DevExpress.XtraEditors.XtraForm
- {
- public Form1()
- {
- InitializeComponent();
- }
- CancellationTokenSource cts1;
- private async void btn1_Click(object sender, EventArgs e)
- {
- layoutControlItem1.Enabled = false;
- layoutControlItem7.Enabled = false;
- if (btn1.Text == "推送")
- {
- try
- {
- cts1 = new CancellationTokenSource();
- btn1.Text = "停止";
- var addrArr = txtAddr1.Text.Trim().Replace(":", ":").Split(":".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
- string ip = addrArr[0];
- int port = Convert.ToInt32(addrArr[1]);
- if (txtTskType.EditValue == null)
- {
- Log($"请选择定位类型");
- return;
- }
- string tskType = txtTskType.EditValue.ToString();
- using (var client = new HttpClient())
- {
- try
- {
- var lines = File.ReadAllLines("Simulation_Data2023.dat");
- int idx = 1;
- string url = string.Format("http://{0}:{1}/Api/Pos/", ip, port);
- if (tskType == "X1D1CX")//一星一地测向定位
- {
- url += "PosX1D1Async";
- }
- if (tskType == "X2D1")//两星一地定位
- {
- url += "PosX2D1Async";
- }
- if (tskType == "RH")//融合定位
- {
- url += "PosRHAsync";
- }
- foreach (var line in lines)
- {
- if (string.IsNullOrWhiteSpace(line)) continue;
- var items = line.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
- SendDto dto = new SendDto()
- {
- SignalTime = DateTime.Now,
- SxDto = Convert.ToDouble(items[0]),
- XdDto = Convert.ToDouble(items[1]),
- MainYbDto = Convert.ToDouble(items[2]),
- AdjaYbDto = Convert.ToDouble(items[3]),
- CxRes = Convert.ToDouble(items[4]),
- MainX = Convert.ToDouble(items[7]),
- MainY = Convert.ToDouble(items[8]),
- MainZ = Convert.ToDouble(items[9]),
- AdjaX = Convert.ToDouble(items[10]),
- AdjaY = Convert.ToDouble(items[11]),
- AdjaZ = Convert.ToDouble(items[12]),
- SatTxLon = IniFiles.ReadValue<double>("Station_Data2023", "卫星接收天线", "Lon"),
- SatTxLat = IniFiles.ReadValue<double>("Station_Data2023", "卫星接收天线", "Lat"),
- CdbTxLon = IniFiles.ReadValue<double>("Station_Data2023", "超短波接收天线", "Lon"),
- CdbTxLat = IniFiles.ReadValue<double>("Station_Data2023", "超短波接收天线", "Lat"),
- CxLon = IniFiles.ReadValue<double>("Station_Data2023", "侧向站", "Lon"),
- CxLat = IniFiles.ReadValue<double>("Station_Data2023", "侧向站", "Lat"),
- RefLon = IniFiles.ReadValue<double>("Station_Data2023", "参考站", "Lon"),
- RefLat = IniFiles.ReadValue<double>("Station_Data2023", "参考站", "Lat"),
- };
- var content = new StringContent(JsonConvert.SerializeObject(dto), System.Text.Encoding.UTF8, "application/json");
- var response = await client.PostAsync(url, content);
- Log($"已向[{txtAddr1.Text}]发送第{idx++}条仿真结果");
- }
- }
- catch (Exception ex)
- {
- Log($"向[{txtAddr1.Text}]发送结果失败.{ex.Message}");
- }
- }
- }
- catch (Exception ex)
- {
- Log(ex);
- }
- finally
- {
- btn1.Text = "推送";
- layoutControlItem1.Enabled = true;
- layoutControlItem7.Enabled = true;
- }
- }
- else
- {
- cts1?.Cancel();
- }
- }
- private void Log(string msg)
- {
- try
- {
- if (this.InvokeRequired)
- {
- this.Invoke(new Action(() =>
- {
- if (listBoxControl1.ItemCount > 5000)
- listBoxControl1.Items.Clear();
- listBoxControl1.Items.Insert(0, $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}--{msg}");
- listBoxControl1.SelectedIndex = 0;
- }));
- }
- else
- {
- if (listBoxControl1.ItemCount > 5000)
- listBoxControl1.Items.Clear();
- listBoxControl1.Items.Insert(0, $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}--{msg}");
- listBoxControl1.SelectedIndex = 0;
- }
- }
- catch
- { }
- }
- private void Log(Exception ex)
- {
- try
- {
- if (this.InvokeRequired)
- {
- this.Invoke(new Action(() =>
- {
- if (listBoxControl1.ItemCount > 5000)
- listBoxControl1.Items.Clear();
- listBoxControl1.Items.Insert(0, $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}--{ex.Message}");
- listBoxControl1.SelectedIndex = 0;
- }));
- }
- else
- {
- if (listBoxControl1.ItemCount > 5000)
- listBoxControl1.Items.Clear();
- listBoxControl1.Items.Insert(0, $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}--{ex.Message}");
- listBoxControl1.SelectedIndex = 0;
- }
- }
- catch
- { }
- }
- private void listBoxControl1_MouseClick(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Right)
- {
- popupMenu1.ShowPopup(MousePosition);
- }
- }
- private void btnClear_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
- {
- listBoxControl1.Items.Clear();
- }
- private void btnCopyAll_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
- {
- StringBuilder sb = new StringBuilder();
- foreach (var item in listBoxControl1.Items)
- {
- sb.AppendLine(item.ToString());
- }
- var data = sb.ToString();
- if (string.IsNullOrWhiteSpace(data)) return;
- Clipboard.SetText(sb.ToString());
- }
- }
- }
|