118 lines
4.6 KiB
C#
118 lines
4.6 KiB
C#
using AgroBase.Models;
|
|
using AgroBase.Services;
|
|
using Newtonsoft.Json;
|
|
using SharpDX.Text;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace AgroBase.Forms
|
|
{
|
|
public partial class frmGPS : Form
|
|
{
|
|
private MapasModel Mapa;
|
|
private AsyncTaskTimerModel tmrLeitura;
|
|
private List<List<GPSModel>> Trajetoria = new List<List<GPSModel>>();
|
|
private string LogID = DateTime.Now.ToString("dd_MM_yyyy_HH_mm_ss");
|
|
|
|
public frmGPS()
|
|
{
|
|
InitializeComponent();
|
|
|
|
Mapa = new MapasModel()
|
|
{
|
|
pnlMapa = pnlMapa,
|
|
};
|
|
}
|
|
|
|
private void frmGPS_Load(object sender, EventArgs e)
|
|
{
|
|
IniciarMapa();
|
|
tmrLeitura = new AsyncTaskTimerModel("tmrLeitura", tmrLeitura_Tick, 1000, this);
|
|
tmrLeitura.Start();
|
|
}
|
|
|
|
private void frmGPS_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
tmrLeitura.Dispose();
|
|
}
|
|
|
|
private async Task tmrLeitura_Tick()
|
|
{
|
|
var Gps = Variaveis.OperacaoEmAndamento.Sensoriamento.Gps;
|
|
|
|
lblAltitude.Text = "Altitude: " + Gps.Altitude.ToString("0.0") + " m";
|
|
lblDatahora.Text = "Ultima Leitura: " + Gps.DataHora.ToString("HH:mm:ss");
|
|
txtLatitude.Text = Gps.Latitude.ToString();
|
|
txtLongitude.Text = Gps.Longitude.ToString();
|
|
lblPrecisaoHorizontal.Text = "Precisão Horizontal: " + Gps.PrecisaoHorizontal.ToString("0.00");
|
|
lblPrecisaoCm.Text = "Precisão Leitura: " + Gps.PrecisaoCm.ToString("0.00") + " cm";
|
|
lblSatelites.Text = "Satélites Visíveis: " + Gps.NumeroSatelites.ToString();
|
|
lblVelocidade.Text = "Distancia: " + (Gps.Distancia * 100.0).ToString("0.0000") + " cm";
|
|
lblOrientacao.Text = "Orientação: " + Gps.OrientacaoReal.ToString("0.00") + "º (" + Gps.OrientacaoMovimento.ToString("0.00") + "º)";
|
|
lblCursoVerdadeiro.Text = "Curso Verdadeiro: " + Gps.CursoVerdadeiro.ToString("0.00") + "º";
|
|
lblVariacaoMagnetica.Text = "Variação Magnética: " + Gps.VariacaoMagnetica.ToString("0.00") + "º";
|
|
lblFix.Text = "Correção: " + Gps.QualidadeFix.ToString() + " (" + Gps.IdadeCorrecao.ToString("0.0") + " s)";
|
|
|
|
if (chbSalvar.Checked)
|
|
{
|
|
GPSModel leitura = Gps.Clone();
|
|
|
|
if (leitura.Distancia >= TrajetoriaMapaOperacaoModel.DistanciaEntrePontos)
|
|
{
|
|
Trajetoria[Trajetoria.Count - 1].Add(leitura);
|
|
}
|
|
|
|
File.WriteAllText(Variaveis.CaminhoLogsDispositivos + "GPS/" + LogID + ".json", JsonConvert.SerializeObject(Trajetoria, Formatting.None), Encoding.UTF8);
|
|
}
|
|
|
|
if (GPSService.Iniciado)
|
|
{
|
|
int ID = Convert.ToInt32(Variaveis.IsAgroMonitor ? LoRaBaseService.parametrosModel.address : Variaveis.LoraService.ParametrosSet.address);
|
|
GPSService.EnviarCoordenadasParaMapa(Gps.Latitude, Gps.Longitude, Gps.AnguloCarroDefinido, true, ID);
|
|
}
|
|
|
|
if (Variaveis.LoraService.Iniciado && Variaveis.LoraService._ultimoRxDados > DateTime.UtcNow.AddSeconds(-60))
|
|
{
|
|
var GpsBase = VariaveisOperacao.PosicaoBase;
|
|
GPSService.EnviarCoordenadasParaMapa(GpsBase.Latitude, GpsBase.Longitude, GpsBase.AnguloCarroDefinido, false, Variaveis.LoraBaseParametros.address);
|
|
}
|
|
}
|
|
|
|
private void IniciarMapa()
|
|
{
|
|
Mapa.CarregarMapaGPS();
|
|
}
|
|
|
|
private void btnGerarMapa_Click(object sender, EventArgs e)
|
|
{
|
|
MapasService.CriarArquivoMapa(Trajetoria);
|
|
MessageBox.Show("Mapa gerado com sucesso!", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
|
|
private void btnNovaRua_Click(object sender, EventArgs e)
|
|
{
|
|
Trajetoria.Add(new List<GPSModel>());
|
|
}
|
|
|
|
private void chbSalvar_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
if (chbSalvar.Checked && Trajetoria.Count == 0)
|
|
{
|
|
btnNovaRua_Click(sender, e);
|
|
}
|
|
}
|
|
|
|
private void btnLimparRuas_Click(object sender, EventArgs e)
|
|
{
|
|
if (MessageBox.Show("Reiniciar o mapeamento do trajeto?", "Confirmacao", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
|
{
|
|
Trajetoria = new List<List<GPSModel>>();
|
|
btnNovaRua_Click(sender, e);
|
|
}
|
|
}
|
|
}
|
|
}
|