57 lines
1.6 KiB
C#
57 lines
1.6 KiB
C#
using AgroBase.Models;
|
|
using AgroBase.Services;
|
|
using OperationControl.Services;
|
|
using OperationControl.Windows;
|
|
using System.Diagnostics;
|
|
|
|
namespace OperationControl.Models
|
|
{
|
|
public class AppShell
|
|
{
|
|
private readonly System.Timers.Timer tmrComunicacao = new(1000) { AutoReset = true };
|
|
private int tmrComunicacaoTicks = 0;
|
|
private bool tmrComunicacaoTicking = false;
|
|
|
|
public MainWindow Main { get; private set; }
|
|
|
|
public void Inicializar()
|
|
{
|
|
Show();
|
|
|
|
APIService.IniciarRotinas();
|
|
Variaveis.IniciarMQTT();
|
|
|
|
tmrComunicacao.Elapsed += (_, __) => tmrComunicacao_Elapsed();
|
|
tmrComunicacao.Start();
|
|
}
|
|
|
|
private void Show()
|
|
{
|
|
// Aqui você decide qual janela é a inicial de fato
|
|
Main = new MainWindow();
|
|
Main.Show();
|
|
}
|
|
|
|
private void tmrComunicacao_Elapsed()
|
|
{
|
|
if (tmrComunicacaoTicking) return;
|
|
tmrComunicacaoTicking = true;
|
|
try
|
|
{
|
|
if (tmrComunicacaoTicks % (VariaveisEquipamento.TempoEntrePingsConexao / 1000) == 0 && Variaveis.GpsService != null)
|
|
{
|
|
VariaveisControleOperacao.EnviarDadosPosicao(Variaveis.GpsService.UltimaLeitura);
|
|
}
|
|
VariaveisControleOperacao.EnviarDadosHeartbeat();
|
|
VariaveisControleOperacao.AtualizarListaRoversNaRede();
|
|
}
|
|
finally
|
|
{
|
|
tmrComunicacaoTicks++;
|
|
tmrComunicacaoTicking = false;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|