2025-11-12 11:15:07 +00:00
using System.Windows ;
using OperationControl.Controls ;
2025-11-14 17:11:58 +00:00
using OperationControl.Models ;
using System.Windows.Controls ;
using System.Windows.Media ;
2025-11-24 16:05:50 +00:00
using LibVLCSharp.Shared ;
2025-11-24 19:58:20 +00:00
using System.Windows.Input ;
2025-11-24 16:05:50 +00:00
using System.IO ;
2025-11-24 19:58:20 +00:00
using MediaPlayer = LibVLCSharp . Shared . MediaPlayer ;
2025-11-24 16:05:50 +00:00
using ComboBox = System . Windows . Controls . ComboBox ;
using Application = System . Windows . Application ;
using MessageBox = System . Windows . MessageBox ;
2025-11-24 19:58:20 +00:00
using Brush = System . Windows . Media . Brush ;
using Brushes = System . Windows . Media . Brushes ;
using Label = System . Windows . Controls . Label ;
2025-11-28 10:19:39 +00:00
using Newtonsoft.Json.Linq ;
2025-11-28 19:44:53 +00:00
using AgroBase.Models.Operadores ;
2025-12-04 13:51:11 +00:00
using System.Collections.ObjectModel ;
using System.ComponentModel ;
using System.Windows.Threading ;
2025-11-12 11:15:07 +00:00
namespace OperationControl.Windows
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
2025-12-04 13:51:11 +00:00
public partial class MainWindow : Window , INotifyPropertyChanged
2025-11-12 11:15:07 +00:00
{
2025-11-24 16:05:50 +00:00
private LibVLC _libVLC ;
private MediaPlayer _playerFront ;
private MediaPlayer _playerWeed ;
private Media _mediaFront ;
private Media _mediaWeed ;
2025-11-12 11:15:07 +00:00
public MainWindow ( )
{
InitializeComponent ( ) ;
2025-11-28 19:44:53 +00:00
cmbDir_Direcao . Items . Clear ( ) ;
cmbDir_Direcao . Items . Add ( "Parado" ) ;
cmbDir_Direcao . Items . Add ( "Direita" ) ;
cmbDir_Direcao . Items . Add ( "Esquerda" ) ;
cmbDir_Direcao . SelectedIndex = 0 ;
2025-11-14 17:11:58 +00:00
2025-11-28 19:44:53 +00:00
cmbDir_Movimento . Items . Clear ( ) ;
foreach ( var m in Enum . GetNames ( typeof ( AgroBase . Models . Enums . TipoMovimentoDirecional ) ) )
cmbDir_Movimento . Items . Add ( m ) ;
cmbDir_Movimento . SelectedIndex = 0 ;
2025-11-14 17:11:58 +00:00
AtualizarListaDispositivos ( new List < string > ( ) { VariaveisControleOperacao . SelectedRoverId } ) ;
2025-11-27 13:31:09 +00:00
graficoAcompanhamento = new GraficoModel ( pltSaude_Acompanhamento ) ;
2025-11-12 11:15:07 +00:00
2025-12-04 13:51:11 +00:00
DataContext = this ;
2025-11-12 11:15:07 +00:00
2025-11-26 20:00:16 +00:00
//DataContext = this;
2025-11-12 11:15:07 +00:00
// atualizar as caixas
2025-11-14 17:11:58 +00:00
//BBoxes3D.SetBboxes(new[]
//{
// new AgroBase.Models.LivoxBboxModel{ cx=1.2, cy=0.5, cz=0.4, d=0.6, w=0.4, h=0.8 },
// new AgroBase.Models.LivoxBboxModel{ cx=3.0, cy=-0.7, cz=0.6, d=0.8, w=0.5, h=1.2 },
//});
2025-11-24 16:05:50 +00:00
// Opções focadas em baixa latência
_libVLC = new LibVLC (
"--network-caching=1000" , // ms (ajusta depois)
"--clock-jitter=0" ,
"--clock-synchro=0"
) ;
// Player da câmera frontal
_playerFront = new MediaPlayer ( _libVLC ) ;
VideoFront . MediaPlayer = _playerFront ;
_playerWeed = new MediaPlayer ( _libVLC ) ;
VideoWeed . MediaPlayer = _playerWeed ;
Loaded + = MainWindow_Loaded ;
Closed + = MainWindow_Closed ;
2025-12-04 13:51:11 +00:00
_toastTimer = new DispatcherTimer
{
Interval = TimeSpan . FromSeconds ( 6 ) // tempo do toast na tela
} ;
_toastTimer . Tick + = ( s , e ) = >
{
_toastTimer . Stop ( ) ;
ToastAlerta = null ;
} ;
2025-11-24 16:05:50 +00:00
}
private void MainWindow_Loaded ( object sender , RoutedEventArgs e )
{
2025-11-12 11:15:07 +00:00
}
2025-11-24 16:05:50 +00:00
private void MainWindow_Closed ( object? sender , EventArgs e )
{
PararStreamCameraFrontal ( true ) ;
PararStreamCameraErvas ( true ) ;
_libVLC ? . Dispose ( ) ;
}
2025-11-14 17:11:58 +00:00
#region DISPOSITIVOS
public void AtualizarListaDispositivos ( List < string > dispositivos )
{
2025-11-24 16:05:50 +00:00
Application . Current . Dispatcher . BeginInvoke ( new Action ( ( ) = >
2025-11-14 17:11:58 +00:00
{
2025-11-24 16:05:50 +00:00
try
2025-11-14 17:11:58 +00:00
{
2025-11-24 16:05:50 +00:00
cmbDispositivo . Items . Clear ( ) ;
foreach ( var d in dispositivos )
2025-11-14 17:11:58 +00:00
{
2025-11-24 16:05:50 +00:00
cmbDispositivo . Items . Add ( d ) ;
if ( ! MAP . markers . Added ( d ) )
2025-11-14 17:11:58 +00:00
{
2025-11-24 16:05:50 +00:00
if ( d = = VariaveisControleOperacao . BaseMarkerID )
{
MAP . markers . AddMarker (
d ,
true ,
lat : Variaveis . GpsService ? . UltimaLeitura ? . Latitude ? ? 0 ,
lon : Variaveis . GpsService ? . UltimaLeitura ? . Longitude ? ? 0 ,
heading : Variaveis . GpsService ? . UltimaLeitura ? . OrientacaoReal ? ? 0 ,
label : "Base"
) ;
}
else
{
var rover = VariaveisControleOperacao . RoversNaRede . FirstOrDefault ( x = > x . RoverId = = d ) ;
if ( rover ! = null )
{
MAP . markers . AddMarker (
d ,
false ,
lat : rover . DadosLeitura ? . Gps ? . Latitude ? ? 0 ,
lon : rover . DadosLeitura ? . Gps ? . Longitude ? ? 0 ,
heading : rover . DadosLeitura ? . Gps ? . AnguloCarroDefinido ? ? 0
) ;
}
}
2025-11-14 17:11:58 +00:00
}
}
2025-11-24 16:05:50 +00:00
int idx_selected = dispositivos . IndexOf ( VariaveisControleOperacao . SelectedRoverId ) ;
if ( idx_selected > - 1 )
cmbDispositivo . SelectedIndex = idx_selected ;
2025-11-14 17:11:58 +00:00
}
2025-11-24 16:05:50 +00:00
catch ( Exception exUi )
{
Variaveis . MostrarLog ( $"Erro ao atualizar UI lista dispositivos: {exUi.Message}" ) ;
}
} ) ) ;
2025-11-14 17:11:58 +00:00
}
private void cmbDispositivo_SelectionChanged ( object sender , System . Windows . Controls . SelectionChangedEventArgs e )
{
2025-11-24 16:05:50 +00:00
var selecionado = ( ( ComboBox ) sender ) . SelectedItem ;
if ( selecionado = = null ) return ;
bool dados_base = selecionado = = VariaveisControleOperacao . BaseMarkerID ;
if ( dados_base & & ! VariaveisControleOperacao . BaseEmFoco )
{
PararStreamCameraFrontal ( ) ;
PararStreamCameraErvas ( ) ;
}
VariaveisControleOperacao . SelectedRoverId = selecionado . ToString ( ) ;
MAP . markers . SetMarkerFocused ( selecionado . ToString ( ) , true ) ;
AtualizarDadosTela_Telemetria ( selecionado . ToString ( ) ) ;
brdResumo . IsEnabled = ! dados_base ;
brdDiagnostico . IsEnabled = ! dados_base ;
brdControle . IsEnabled = ! dados_base ;
brdAjustesOperacao . IsEnabled = ! dados_base ;
if ( ! dados_base )
{
btnParametros_Atualizar_Click ( sender , e ) ;
IniciarStreamCameraFrontal ( ) ;
IniciarStreamCameraErvas ( ) ;
}
2025-11-14 17:11:58 +00:00
}
2025-11-24 16:05:50 +00:00
public void LimparDadosTela_Telemetria ( string rover_id )
2025-11-14 17:11:58 +00:00
{
2025-11-24 16:05:50 +00:00
Application . Current . Dispatcher . BeginInvoke ( new Action ( ( ) = >
{
try
{
if ( ! string . IsNullOrEmpty ( rover_id ) )
{
//MAP.markers.RemoveMarker(rover_id);
//cmbDispositivo.Items.Remove(rover_id);
}
else
{
//cmbDispositivo.SelectedIndex = 0;
}
}
catch ( Exception exUi )
{
Variaveis . MostrarLog ( $"Erro ao atualizar UI telemetria (clear): {exUi.Message}" ) ;
}
} ) ) ;
2025-11-14 17:11:58 +00:00
}
public void AtualizarDadosTela_Telemetria ( string rover_id )
{
2025-11-24 16:05:50 +00:00
bool dados_base = rover_id = = VariaveisControleOperacao . BaseMarkerID ;
2025-11-24 19:58:20 +00:00
var rover = VariaveisControleOperacao . RoversNaRede . FirstOrDefault ( x = > x . RoverId = = rover_id ) ;
var dados_leitura = rover ? . DadosLeitura ;
2025-11-24 16:05:50 +00:00
if ( dados_base )
{
MAP . markers . UpdateMarkerPosition ( rover_id , lat : Variaveis . GpsService ? . UltimaLeitura ? . Latitude , lon : Variaveis . GpsService ? . UltimaLeitura ? . Longitude , heading : Variaveis . GpsService ? . UltimaLeitura ? . OrientacaoReal ) ;
}
2025-11-24 19:58:20 +00:00
else if ( dados_leitura ! = null )
2025-11-24 16:05:50 +00:00
{
2025-11-24 19:58:20 +00:00
var simulacao = dados_leitura . Controle ? . SimulacaoMPC ? . Select ( x = > new double [ ] { x . longitude , x . latitude } ) ? . ToList ( ) ;
2025-11-26 20:00:16 +00:00
MAP . markers . UpdateMarkerPosition ( rover_id , lat : dados_leitura . Gps ? . Latitude , lon : dados_leitura . Gps ? . Longitude , heading : dados_leitura . Gps ? . OrientacaoReal , predict : simulacao ) ;
2025-11-24 19:58:20 +00:00
MAP . markers . UpdateMarkerInfo ( rover_id , status : dados_leitura . StatusOperacao ) ;
2025-11-24 16:05:50 +00:00
}
2025-12-04 13:51:11 +00:00
if ( rover ! = null & & dados_leitura ? . ModulosSaude ! = null )
{
SeveridadeAlerta DeParaStatus ( AgroBase . Models . Enums . StatusModulo status , bool mandatorio )
{
switch ( status )
{
case AgroBase . Models . Enums . StatusModulo . Operante :
return SeveridadeAlerta . Info ;
case AgroBase . Models . Enums . StatusModulo . Alerta :
return SeveridadeAlerta . Warning ;
case AgroBase . Models . Enums . StatusModulo . Falha :
return ( mandatorio ) ? SeveridadeAlerta . Critical : SeveridadeAlerta . Error ;
case AgroBase . Models . Enums . StatusModulo . Conectado :
return ( mandatorio ) ? SeveridadeAlerta . Warning : SeveridadeAlerta . Info ;
case AgroBase . Models . Enums . StatusModulo . Desconectado :
return ( mandatorio ) ? SeveridadeAlerta . Critical : SeveridadeAlerta . Error ;
default :
return SeveridadeAlerta . Info ;
}
}
foreach ( var mod in dados_leitura . ModulosSaude )
{
if ( mod . saude_individual . Any ( ) )
{
foreach ( var ind in mod . saude_individual )
{
if ( ind . status ! = AgroBase . Models . Enums . StatusModulo . Operante )
{
AdicionarAlerta ( rover . RoverId , mod . modulo , DeParaStatus ( ind . status , ind . em_uso ) , string . Join ( ", " , ind . motivos ) , Mod_ID : ind . label ) ;
}
else
{
RemoverAlerta ( rover . RoverId , mod . modulo , Mod_ID : ind . label ) ;
}
}
}
else
{
if ( mod . status ! = AgroBase . Models . Enums . StatusModulo . Operante )
{
AdicionarAlerta ( rover . RoverId , mod . modulo , DeParaStatus ( mod . status , rover . ModulosMandatorios ? . Any ( x = > x . Dispositivo = = mod . modulo & & x . Mandatorio ) ? ? false ) , string . Join ( ", " , mod . motivos ) ) ;
}
else
{
RemoverAlerta ( rover . RoverId , mod . modulo ) ;
}
}
}
}
2025-11-14 17:11:58 +00:00
if ( rover_id ! = VariaveisControleOperacao . SelectedRoverId ) return ;
2025-11-24 16:05:50 +00:00
Application . Current . Dispatcher . BeginInvoke ( new Action ( ( ) = >
2025-11-14 17:11:58 +00:00
{
2025-11-24 16:05:50 +00:00
try
{
if ( rover_id = = VariaveisControleOperacao . BaseMarkerID )
{
Variaveis . MostrarLog ( $"Atualizando dados da tela para a base" ) ;
2025-11-14 17:11:58 +00:00
2025-11-26 20:00:16 +00:00
lblDispositivos_Status . Content = VariaveisControleOperacao . StatusBase . ToString ( ) ;
AplicarStatusModuloNaLabel ( lblDispositivos_Status , VariaveisControleOperacao . StatusBase , true , false ) ;
2025-11-24 16:05:50 +00:00
AtualizarDadosTela_GNSS ( Variaveis . GpsService ? . UltimaLeitura ? ? new AgroBase . Models . GPSModel ( ) , marker_id : VariaveisControleOperacao . BaseMarkerID ) ;
AtualizarDadosTela_Heading ( Variaveis . GpsService ? . UltimaLeitura ? . AnguloCarroDefinido ? ? 0 ) ;
}
else
{
2025-11-24 19:58:20 +00:00
if ( dados_leitura = = null ) return ;
2025-11-24 16:05:50 +00:00
Variaveis . MostrarLog ( $"Atualizando dados da tela para o dispositivo {rover_id}" ) ;
2025-11-26 20:00:16 +00:00
lblDispositivos_Status . Content = ( rover ? . DadosLeitura ? . Status ? ? AgroBase . Models . Enums . StatusModulo . Desconectado ) . ToString ( ) ;
AplicarStatusModuloNaLabel ( lblDispositivos_Status , rover ? . DadosLeitura ? . Status ? ? AgroBase . Models . Enums . StatusModulo . Desconectado , true , false ) ;
2025-11-24 19:58:20 +00:00
AtualizarDadosTela_Diagnosticos ( rover ) ;
2025-11-28 19:44:53 +00:00
AtualizarDadosTela_Resumo_Conexao ( dados_leitura ) ;
2025-11-24 19:58:20 +00:00
if ( dados_leitura . Trajetoria ! = null )
AtualizarDadosTela_Resumo ( dados_leitura ) ;
if ( dados_leitura . Gps ! = null )
AtualizarDadosTela_GNSS ( dados_leitura . Gps , marker_id : rover_id ) ;
if ( dados_leitura . Controle ! = null )
2025-11-27 13:31:09 +00:00
AtualizarDadosTela_Controle ( dados_leitura . Controle , dados_leitura . Direcional . AnguloMedio , dados_leitura . Movimentacao . VelocidadeMedia , dados_leitura . Emergencia , ! dados_leitura . OperacaoIniciada , dados_leitura . StatusOperacao = = AgroBase . Models . Enums . StatusOperacao . Calibrando ) ;
2025-11-24 16:05:50 +00:00
//if (rover.Value.Controle != null)
// AtualizarDadosTela_ParametrosOperacao(rover.Value.Controle);
2025-11-24 19:58:20 +00:00
if ( dados_leitura . Trajetoria ! = null )
AtualizarDadosTela_Mapa ( dados_leitura . Trajetoria ) ;
if ( dados_leitura . Gps ! = null )
AtualizarDadosTela_Heading ( dados_leitura . Gps . AnguloCarroDefinido , dados_leitura . Modo = = AgroBase . Models . Enums . ModoOperacao . Manual ? double . NaN : dados_leitura . Trajetoria . AnguloCaminho ) ;
if ( dados_leitura . IMU ! = null )
AtualizarDadosTela_IMU ( dados_leitura . IMU . InclinacaoLateral , dados_leitura . IMU . InclinacaoFrontal ) ;
2025-12-02 18:42:15 +00:00
if ( rover . Controle ! = null )
AtualizarDadosTela_Pulverizador ( dados_leitura ) ;
2025-11-24 19:58:20 +00:00
if ( dados_leitura . LivoxLidar ! = null )
AtualizarDadostela_LIDAR ( dados_leitura . LivoxLidar . bboxes ) ;
2025-11-24 16:05:50 +00:00
}
}
catch ( Exception exUi )
{
Variaveis . MostrarLog ( $"Erro ao atualizar UI telemetria (set): {exUi.Message}" ) ;
}
} ) ) ;
}
#endregion
#region RESUMO OPERACIONAL
public void AtualizarDadosTela_Resumo ( AgroBase . Models . OperacaoSensoriamentoLogModel dados )
{
Application . Current . Dispatcher . BeginInvoke ( new Action ( ( ) = >
2025-11-14 17:11:58 +00:00
{
2025-11-24 16:05:50 +00:00
try
{
pgbResumo_RuaAtual . Value = dados . Trajetoria . PercentualRuaAtual ;
2025-11-26 20:00:16 +00:00
lblResumo_RuaAtual . Content = $"{dados.Trajetoria.CorredorAtual.DistanciaPercorridaCorredor.ToString(" 0.00 ")} m / {dados.Trajetoria.CorredorAtual.DistanciaTotal.ToString(" 0.00 ")} m ({dados.Trajetoria.CorredorAtual.Idx + 1})" ;
2025-11-24 16:05:50 +00:00
pgbResumo_AreaTotal . Value = dados . Trajetoria . PercentualOperacao ;
2025-11-26 20:00:16 +00:00
lblResumo_AreaTotal . Content = $"{dados.Trajetoria.DistanciaPercorrida.ToString(" 0.00 ")} m / {dados.Trajetoria.DistanciaTotal.ToString(" 0.00 ")} m" ;
2025-11-24 16:05:50 +00:00
pgbResumo_Bateria . Value = dados . Bateria . PorcentagemBateria ;
2025-11-26 20:00:16 +00:00
lblResumo_Bateria . Content = $"{dados.Bateria.TensaoInstantanea.ToString(" 0.00 ")} V ({TimeSpan.FromMinutes(dados.Bateria.TempoEstimadoRestanteMinutos)})" ;
2025-11-24 16:05:50 +00:00
pgbResumo_Herbicida . Value = dados . Atuador . PercentualReservatorio ;
2025-11-26 20:00:16 +00:00
lblResumo_Herbicida . Content = $"{dados.Atuador.VolumeReservatorio.ToString(" 0.00 ")} L ({0.ToString(" 0.00 ")} m)" ;
2025-11-24 16:05:50 +00:00
pgbResumo_Infestacao . Value = dados . Atuador . PercentualErvasTerreno ;
lblResumo_Infestacao . Content = $"{dados.Atuador.VazaoMedia.ToString(" 0.00 ")}" ;
lblResumo_OperacaoLiberada . Content = $"Operação " + ( dados . OperacaoLiberada ? "🔓 Liberada" : "🔒 Bloqueada" ) ;
lblResumo_OperacaoModo . Content = $"Modo {dados.Modo}" ;
lblResumo_OperacaoStatus . Content = $"Status {dados.StatusOperacao}" + ( dados . StatusOperacao = = AgroBase . Models . Enums . StatusOperacao . Aguardando ? $" ({dados.TempoAguardandoSeg.ToString(" 0 ")})" : "" ) ;
lblResumo_StatusCarro . Content = $"Carro {dados.Trajetoria.StatusCarro}" ;
lblResumo_TemperaturaGeral . Content = $"Temperatura {(dados.DadosPerformance.CPU_temp ?? 0).ToString(" 0.00 ")} °C" ;
2025-11-26 20:00:16 +00:00
lblResumo_OperacaoDuracao . Content = $"Duração {dados.TempoDecorrido.ToString(" HH : mm : ss ")} / " + ( string . IsNullOrEmpty ( dados . Trajetoria . TempoEstimadoOperacao ) ? "00:00:00" : dados . Trajetoria . TempoEstimadoOperacao ) ;
2025-11-24 16:05:50 +00:00
}
catch ( Exception exUi )
{
Variaveis . MostrarLog ( $"Erro ao atualizar UI Resumo: {exUi.Message}" ) ;
}
} ) ) ;
}
2025-11-14 17:11:58 +00:00
2025-11-28 19:44:53 +00:00
public void AtualizarDadosTela_Resumo_Conexao ( AgroBase . Models . OperacaoSensoriamentoLogModel dados )
{
Application . Current . Dispatcher . BeginInvoke ( new Action ( ( ) = >
{
try
{
var conexao = dados . ModulosSaude ? . FirstOrDefault ( x = > x . modulo = = AgroBase . Models . Enums . T_Code . Ipb ) ;
double conexao_saude = conexao ? . saude ? ? 0 ;
double conexao_latencia = conexao ? . detalhes ? [ "avg_rtt" ] ? . Value < double > ( ) ? ? 0.0 ;
double conexao_perda = conexao ? . detalhes ? [ "loss_pct" ] ? . Value < double > ( ) ? ? 0.0 ;
double bwTot = conexao ? . detalhes ? [ "bw_total_mbps" ] ? . Value < double > ( ) ? ? 0 ;
pgbResumo_Conexao . Value = conexao_saude ;
lblResumo_Conexao . Content = $"{conexao_latencia:0.00} ms {conexao_perda:0.00}% {bwTot:0.00} Mbps" ;
}
catch ( Exception exUi )
{
Variaveis . MostrarLog ( $"Erro ao atualizar UI Resumo_Conexao: {exUi.Message}" ) ;
}
} ) ) ;
}
2025-11-24 16:05:50 +00:00
#endregion
2025-11-14 17:11:58 +00:00
2025-11-24 19:58:20 +00:00
#region DIAGNOSTICOS
2025-12-04 13:51:11 +00:00
private Label _labelModuloSelecionado ;
private GraficoModel graficoAcompanhamento ;
2025-11-24 19:58:20 +00:00
private void AtualizarDadosTela_Diagnosticos ( AgroBase . Models . Operacoes . OperacaoParametrosModel dados )
{
2025-11-25 20:14:31 +00:00
lblDiagnosticos_Impedimento . Text = "Impedimento: " + ( string . IsNullOrEmpty ( dados . DadosLeitura . ErroOperacaoLiberada ) ? "Nenhum" : dados . DadosLeitura . ErroOperacaoLiberada . Replace ( "\n\n" , "; " ) ) ;
2025-11-24 19:58:20 +00:00
// Canvas que está dentro do Border
var canvas = brdDiagnostico . Child as Canvas ;
if ( canvas = = null )
return ;
// Percorre apenas labels dentro do Canvas com o prefixo desejado
foreach ( var lbl in canvas . Children . OfType < Label > ( ) . Where ( x = > x . Name . StartsWith ( "lblDiagnosticos_" ) ) )
{
2025-11-27 13:31:09 +00:00
( var modulo , var mod_label , var s_code , var iniciado ) = GetModuleData ( lbl ) ;
2025-11-24 19:58:20 +00:00
if ( modulo = = AgroBase . Models . Enums . T_Code . Vzo )
continue ;
// Procura a saúde desse módulo
2025-11-28 19:44:53 +00:00
var saude = dados . DadosLeitura . ModulosSaude ? . FirstOrDefault ( x = > x . modulo = = modulo ) ;
2025-11-25 20:14:31 +00:00
if ( saude = = null & & false )
2025-11-24 19:58:20 +00:00
continue ;
2025-11-25 20:14:31 +00:00
var individual = saude ? . saude_individual ? . FirstOrDefault ( x = > x . label = = mod_label ) ;
2025-11-24 19:58:20 +00:00
2025-11-25 20:14:31 +00:00
bool em_uso = mod_label ! = "" ? dados . DadosLeitura . ModulosMandatorios ? . FirstOrDefault ( x = > x . Dispositivo = = modulo ) ? . ComponentesEmUso ? . Any ( x = > x . Key = = mod_label & & x . Value ) ? ? false : dados . ModulosMandatorios ? . Any ( x = > x . Dispositivo = = modulo & & x . Utilizar ) ? ? false ;
2025-11-24 19:58:20 +00:00
// Aplica cor de acordo com o status
2025-11-25 20:14:31 +00:00
AplicarStatusModuloNaLabel ( lbl , individual ? . status ? ? saude ? . status ? ? AgroBase . Models . Enums . StatusModulo . Desconectado , em_uso ) ;
2025-11-24 19:58:20 +00:00
}
2025-11-25 20:14:31 +00:00
2025-11-26 20:00:16 +00:00
PreencherAbaAcompanhamento ( false ) ;
PreencherAbaOpcoes ( false ) ;
2025-11-24 19:58:20 +00:00
}
2025-11-26 20:00:16 +00:00
private void AplicarStatusModuloNaLabel ( Label lbl , AgroBase . Models . Enums . StatusModulo status , bool mandatorio , bool icone = true )
2025-11-24 19:58:20 +00:00
{
// você pode ajustar essas cores depois
Brush back ;
Brush fore = Brushes . White ;
switch ( status )
{
case AgroBase . Models . Enums . StatusModulo . Desconectado :
back = mandatorio ? Brushes . Red : Brushes . Gray ;
break ;
case AgroBase . Models . Enums . StatusModulo . Conectado :
back = Brushes . SteelBlue ;
break ;
case AgroBase . Models . Enums . StatusModulo . Falha :
back = Brushes . Red ;
break ;
case AgroBase . Models . Enums . StatusModulo . Alerta :
back = Brushes . Orange ;
break ;
case AgroBase . Models . Enums . StatusModulo . Operante :
back = Brushes . Green ;
break ;
default :
back = Brushes . DarkGray ;
break ;
}
lbl . Background = back ;
lbl . Foreground = fore ;
2025-11-26 20:00:16 +00:00
if ( icone )
{
string text = lbl . Content ? . ToString ( ) ? ? "" ;
text = text . Remove ( 0 , 2 ) ;
lbl . Content = ( mandatorio ? "🔒" : "🔓" ) + text ;
}
2025-11-24 19:58:20 +00:00
}
2025-11-27 13:31:09 +00:00
private ( AgroBase . Models . Enums . T_Code , string , AgroBase . Models . Enums . S_Code , bool ) GetModuleData ( Label lbl )
2025-11-24 19:58:20 +00:00
{
2025-11-27 13:31:09 +00:00
bool iniciado = false ;
if ( lbl = = null ) return ( AgroBase . Models . Enums . T_Code . Vzo , "" , AgroBase . Models . Enums . S_Code . sVZO , iniciado ) ;
2025-11-25 20:14:31 +00:00
2025-11-24 19:58:20 +00:00
string lbl_name = lbl . Name . Replace ( "lblDiagnosticos_" , "" ) ;
string [ ] pts = lbl_name . Split ( '_' ) ;
string mod_name = pts [ 0 ] ;
string mod_label = pts . Length > 1 ? pts [ 1 ] : "" ;
if ( ! Enum . TryParse < AgroBase . Models . Enums . T_Code > ( mod_name , ignoreCase : true , out var modulo ) )
2025-11-27 13:31:09 +00:00
return ( AgroBase . Models . Enums . T_Code . Vzo , "" , AgroBase . Models . Enums . S_Code . sVZO , iniciado ) ;
2025-11-24 19:58:20 +00:00
2025-11-26 20:00:16 +00:00
string tag = ( lbl . Tag ? ? "sVZO" ) . ToString ( ) ;
Enum . TryParse < AgroBase . Models . Enums . S_Code > ( tag , ignoreCase : true , out var s_code ) ;
2025-11-27 13:31:09 +00:00
var rover = VariaveisControleOperacao . RoverEmFoco ;
if ( rover ! = null )
{
switch ( modulo )
{
case AgroBase . Models . Enums . T_Code . Mov :
iniciado = rover . DadosLeitura ? . Movimentacao ? . Dados ? . FirstOrDefault ( x = > x . ID = = mod_label ) ? . Iniciado ? ? false ;
break ;
case AgroBase . Models . Enums . T_Code . Dir :
2025-12-08 17:32:23 +00:00
iniciado = rover . DadosLeitura ? . Direcional ? . Dados ? . FirstOrDefault ( x = > x . Modulo_ID = = mod_label ) ? . Inicializado ? ? false ;
2025-11-27 13:31:09 +00:00
break ;
case AgroBase . Models . Enums . T_Code . Atu :
2025-11-28 10:19:39 +00:00
if ( string . IsNullOrEmpty ( mod_label ) )
2025-11-28 19:44:53 +00:00
iniciado = rover . DadosLeitura ? . DispositivosMapeados ? . FirstOrDefault ( x = > x . Dispositivo = = modulo ) ? . Saude > 0 ;
2025-11-28 10:19:39 +00:00
else
2025-11-28 19:44:53 +00:00
rover . DadosLeitura ? . Atuador ? . Iniciados ? . TryGetValue ( mod_label , out iniciado ) ;
2025-11-27 13:31:09 +00:00
break ;
case AgroBase . Models . Enums . T_Code . Sen :
2025-11-28 10:19:39 +00:00
if ( string . IsNullOrEmpty ( mod_label ) )
2025-11-28 19:44:53 +00:00
iniciado = rover . DadosLeitura ? . DispositivosMapeados ? . FirstOrDefault ( x = > x . Dispositivo = = modulo ) ? . Saude > 0 ;
2025-11-28 10:19:39 +00:00
else
rover . DadosLeitura . Iniciados ? . TryGetValue ( mod_label , out iniciado ) ;
break ;
case AgroBase . Models . Enums . T_Code . Imu :
2025-11-28 19:44:53 +00:00
iniciado = rover . DadosLeitura ? . IMU ? . Iniciado ? ? false ;
2025-11-28 10:19:39 +00:00
break ;
case AgroBase . Models . Enums . T_Code . Npc :
case AgroBase . Models . Enums . T_Code . Ipb :
iniciado = rover . Alive ;
break ;
case AgroBase . Models . Enums . T_Code . Lra :
2025-11-28 19:44:53 +00:00
iniciado = rover . DadosLeitura ? . DadosLoRa ? . Conectado ? ? false ;
2025-11-27 13:31:09 +00:00
break ;
2025-11-28 10:19:39 +00:00
case AgroBase . Models . Enums . T_Code . Cam :
case AgroBase . Models . Enums . T_Code . Snr :
case AgroBase . Models . Enums . T_Code . Lvx :
2025-11-27 13:31:09 +00:00
case AgroBase . Models . Enums . T_Code . Gps :
2025-11-28 19:44:53 +00:00
iniciado = rover . DadosLeitura ? . DispositivosMapeados ? . FirstOrDefault ( x = > x . Dispositivo = = modulo ) ? . Saude > 0 ;
2025-11-27 13:31:09 +00:00
break ;
}
}
return ( modulo , mod_label , s_code , iniciado ) ;
2025-11-24 19:58:20 +00:00
}
private void DiagnosticoModulo_Click ( object sender , MouseButtonEventArgs e )
{
if ( sender is not Label lbl )
return ;
// desfazer seleção antiga
if ( _labelModuloSelecionado ! = null )
{
_labelModuloSelecionado . BorderBrush = Brushes . Transparent ;
_labelModuloSelecionado . BorderThickness = new Thickness ( 1 ) ;
_labelModuloSelecionado . Effect = null ;
}
// selecionar a nova
_labelModuloSelecionado = lbl ;
_labelModuloSelecionado . BorderBrush = Brushes . Yellow ;
_labelModuloSelecionado . BorderThickness = new Thickness ( 2 ) ;
// opcional — glow bonito
_labelModuloSelecionado . Effect = new System . Windows . Media . Effects . DropShadowEffect
{
Color = System . Windows . Media . Colors . Yellow ,
BlurRadius = 8 ,
ShadowDepth = 0 ,
Opacity = 0.9
} ;
2025-11-25 20:14:31 +00:00
AtualizarDetalhesModulo ( ) ;
2025-11-25 12:17:19 +00:00
}
2025-11-25 20:14:31 +00:00
private void AtualizarDetalhesModulo ( )
2025-11-25 12:17:19 +00:00
{
2025-11-27 13:31:09 +00:00
( var modulo , var label , var s_code , var iniciado ) = GetModuleData ( _labelModuloSelecionado ) ;
2025-11-24 19:58:20 +00:00
if ( modulo = = AgroBase . Models . Enums . T_Code . Vzo )
return ;
2025-11-25 12:17:19 +00:00
var rover = VariaveisControleOperacao . RoverEmFoco ;
var saude = rover ? . DadosLeitura ? . ModulosSaude ? . FirstOrDefault ( x = > x . modulo = = modulo ) ;
var dispositivo = rover ? . DadosLeitura ? . DispositivosMapeados ? . FirstOrDefault ( x = > x . Dispositivo = = modulo & & x . Mod_ID = = label ) ;
2025-11-25 20:14:31 +00:00
if ( dispositivo = = null & & saude = = null & & false )
2025-11-25 12:17:19 +00:00
{
MessageBox . Show ( $"Sem dados para o módulo {modulo} ({label})" ) ;
return ;
}
var individual = saude ? . saude_individual ? . FirstOrDefault ( x = > x . label = = label ) ;
2025-11-25 20:14:31 +00:00
var status = individual ? . status ? ? saude ? . status ? ? AgroBase . Models . Enums . StatusModulo . Desconectado ;
var motivos = string . Join ( ", " , ( individual ? . motivos ? ? saude ? . motivos ) ? ? new List < string > ( ) ) ;
2025-11-25 12:17:19 +00:00
lblSaude_Descricao . Content = $"Módulo {modulo} {label}" ;
2025-11-27 13:31:09 +00:00
lblSaude_Iniciado . Content = ( iniciado ? "Iniciado" : "Não Iniciado" ) ;
2025-11-28 10:19:39 +00:00
lblSaude_Iniciado . Foreground = new SolidColorBrush ( iniciado ? System . Windows . Media . Colors . Green : System . Windows . Media . Colors . Red ) ;
2025-11-25 12:17:19 +00:00
lblSaude_Status . Content = $"{individual?.status ?? saude?.status ?? AgroBase.Models.Enums.StatusModulo.Desconectado} (Saúde {individual?.saude ?? saude?.saude ?? 0}%)" ;
lblSaude_CAN . Content = $"CAN {dispositivo?.VelocidadeBarramento ?? 0} ms" ;
lblSaude_Latencia . Content = $"Latência {dispositivo?.Latencia ?? 0} ms" ;
2025-11-25 20:14:31 +00:00
lblSaude_Impedimento . Text = $"Impedimento: {motivos ?? " Nenhum "}" ;
2025-11-25 12:17:19 +00:00
bool mandatorio = rover ? . ModulosMandatorios ? . Any ( x = > x . Dispositivo = = modulo & & x . Mandatorio ) ? ? false ;
2025-11-25 20:14:31 +00:00
//var cu = rover?.ModulosMandatorios?.FirstOrDefault(x => x.Dispositivo == modulo)?.ComponentesEmUso.FirstOrDefault(x => x.Key == label);
//bool em_uso = individual?.em_uso ?? (cu?.Key != null ? cu?.Value : null) ?? rover?.ModulosMandatorios?.Any(x => x.Dispositivo == modulo && x.Utilizar) ?? false;
//bool em_uso = rover?.ModulosMandatorios?.FirstOrDefault(x => x.Dispositivo == modulo)?.ComponentesEmUso?.Any(x => x.Key == label) ?? false;
bool em_uso = label ! = "" ? rover ? . ModulosMandatorios ? . FirstOrDefault ( x = > x . Dispositivo = = modulo ) ? . ComponentesEmUso ? . Any ( x = > x . Key = = label & & x . Value ) ? ? false : rover ? . ModulosMandatorios ? . Any ( x = > x . Dispositivo = = modulo & & x . Utilizar ) ? ? false ;
2025-11-25 12:17:19 +00:00
chbSaude_Mandatorio . IsChecked = mandatorio ;
chbSaude_EmUso . IsChecked = em_uso ;
2025-11-25 20:14:31 +00:00
2025-11-28 19:44:53 +00:00
PreencherAbaCondicoesOperacionais ( saude ? . condicoes_operacionais ) ;
PreencherAbaAcompanhamento ( true ) ;
PreencherAbaOpcoes ( true ) ;
2025-12-08 17:32:23 +00:00
PreencherAbaLogs ( rover . DadosLeitura ? . Logs ? . Where ( x = > x . Dispositivo = = modulo ) ) ;
2025-11-28 19:44:53 +00:00
}
private void PreencherAbaCondicoesOperacionais ( List < ManagerWorkerMessageResponseModulosPendentesSaudeCondicoesModel > condicoes )
{
2025-11-25 20:14:31 +00:00
lstSaude_CondicoesOperacionais . Items . Clear ( ) ;
2025-11-28 19:44:53 +00:00
if ( condicoes ! = null )
2025-11-25 20:14:31 +00:00
{
2025-11-28 19:44:53 +00:00
foreach ( var cond in condicoes )
2025-11-25 20:14:31 +00:00
{
lstSaude_CondicoesOperacionais . Items . Add ( $"{cond.descricao} (Valor: {cond.valor}, Severidade: {cond.severidade:0}%)" ) ;
}
}
}
2025-11-26 20:00:16 +00:00
private void PreencherAbaAcompanhamento ( bool inicial )
2025-11-25 20:14:31 +00:00
{
2025-11-27 13:31:09 +00:00
( var modulo , var label , var s_code , var iniciado ) = GetModuleData ( _labelModuloSelecionado ) ;
2025-11-25 20:14:31 +00:00
if ( modulo = = AgroBase . Models . Enums . T_Code . Vzo )
return ;
2025-11-27 13:31:09 +00:00
DateTime ? momento = VariaveisControleOperacao . RoverEmFoco ? . DadosLeitura ? . Momento ;
2025-11-26 20:00:16 +00:00
switch ( modulo )
{
case AgroBase . Models . Enums . T_Code . Sen :
2025-11-27 13:31:09 +00:00
switch ( s_code )
2025-11-26 20:00:16 +00:00
{
2025-11-27 13:31:09 +00:00
case AgroBase . Models . Enums . S_Code . sCOR :
var barramento = VariaveisControleOperacao . RoverEmFoco ? . DadosLeitura ? . Bateria ? . Barramentos ? . FirstOrDefault ( x = > x . ID = = label ) ;
graficoAcompanhamento . Atualizar ( inicial , momento , new List < GraficoModel . GraficoParametrosModel > ( )
2025-11-26 20:00:16 +00:00
{
2025-11-27 13:31:09 +00:00
new GraficoModel . GraficoParametrosModel ( )
2025-11-26 20:00:16 +00:00
{
2025-11-27 13:31:09 +00:00
Label = "Corrente" ,
Unidade = "mA" ,
Valor = barramento ? . Corrente
} ,
new GraficoModel . GraficoParametrosModel ( )
{
Label = "Tensão" ,
Unidade = "V" ,
Valor = barramento ? . Tensao
} ,
new GraficoModel . GraficoParametrosModel ( )
{
Label = "Potência" ,
Unidade = "mW" ,
Valor = barramento ? . Potencia
} ,
new GraficoModel . GraficoParametrosModel ( )
{
Label = "Energia" ,
Unidade = "J" ,
Valor = barramento ? . Energia
} ,
new GraficoModel . GraficoParametrosModel ( )
{
Label = "Temperatura" ,
Unidade = "°C" ,
Valor = barramento ? . Temperatura
} ,
} ) ;
break ;
case AgroBase . Models . Enums . S_Code . sNTC :
var ntc = VariaveisControleOperacao . RoverEmFoco ? . DadosLeitura ? . Temperaturas ? . FirstOrDefault ( x = > x . Key = = label ) . Value ;
graficoAcompanhamento . Atualizar ( inicial , momento , new List < GraficoModel . GraficoParametrosModel > ( )
2025-11-26 20:00:16 +00:00
{
2025-11-27 13:31:09 +00:00
new GraficoModel . GraficoParametrosModel ( )
{
Label = "Temperatura" ,
Unidade = "°C" ,
Valor = ntc
} ,
} ) ;
break ;
2025-11-26 20:00:16 +00:00
}
break ;
case AgroBase . Models . Enums . T_Code . Atu :
2025-11-27 13:31:09 +00:00
var atu = VariaveisControleOperacao . RoverEmFoco ? . DadosLeitura ? . Atuador ;
switch ( s_code )
2025-11-26 20:00:16 +00:00
{
2025-11-27 13:31:09 +00:00
case AgroBase . Models . Enums . S_Code . sBIC :
var b = VariaveisControleOperacao . RoverEmFoco ? . DadosLeitura ? . Controle ? . BicosAtuados ? . FirstOrDefault ( x = > x . ID = = label ) ;
graficoAcompanhamento . Atualizar ( inicial , momento , new List < GraficoModel . GraficoParametrosModel > ( )
2025-11-26 20:00:16 +00:00
{
2025-11-27 13:31:09 +00:00
new GraficoModel . GraficoParametrosModel ( )
{
Label = "Cmd" ,
Unidade = "" ,
Valor = ( b ? . ComandoAtuar ? ? false ) ? 100 : 0
} ,
new GraficoModel . GraficoParametrosModel ( )
{
Label = "Vazão" ,
Unidade = "mL/s" ,
Valor = b ? . MediaNivelFluxo
} ,
} ) ;
break ;
case AgroBase . Models . Enums . S_Code . sBMB :
graficoAcompanhamento . Atualizar ( inicial , momento , new List < GraficoModel . GraficoParametrosModel > ( )
2025-11-26 20:00:16 +00:00
{
2025-11-27 13:31:09 +00:00
new GraficoModel . GraficoParametrosModel ( )
{
Label = "Cmd" ,
Unidade = "" ,
Valor = ( atu ? . ComandoBomba ? ? false ) ? 100 : 0
} ,
new GraficoModel . GraficoParametrosModel ( )
{
Label = "Potência" ,
Unidade = "%" ,
Valor = atu ? . LeituraPotenciaBomba
} ,
new GraficoModel . GraficoParametrosModel ( )
{
Label = "Pressão" ,
Unidade = "psi" ,
Valor = atu ? . PressaoLinha
} ,
} ) ;
break ;
case AgroBase . Models . Enums . S_Code . sPRS :
graficoAcompanhamento . Atualizar ( inicial , momento , new List < GraficoModel . GraficoParametrosModel > ( )
2025-11-26 20:00:16 +00:00
{
2025-11-27 13:31:09 +00:00
new GraficoModel . GraficoParametrosModel ( )
{
Label = "Pressão" ,
Unidade = "psi" ,
Valor = atu ? . PressaoLinha
} ,
} ) ;
break ;
case AgroBase . Models . Enums . S_Code . sFLX :
graficoAcompanhamento . Atualizar ( inicial , momento , new List < GraficoModel . GraficoParametrosModel > ( )
2025-11-26 20:00:16 +00:00
{
2025-11-27 13:31:09 +00:00
new GraficoModel . GraficoParametrosModel ( )
{
Label = "Fluxo" ,
Unidade = "mL/s" ,
Valor = atu ? . VazaoInstantanea
} ,
} ) ;
break ;
case AgroBase . Models . Enums . S_Code . sMAS :
graficoAcompanhamento . Atualizar ( inicial , momento , new List < GraficoModel . GraficoParametrosModel > ( )
{
new GraficoModel . GraficoParametrosModel ( )
{
Label = "Volume" ,
Unidade = "L" ,
Valor = atu ? . VolumeReservatorio
} ,
new GraficoModel . GraficoParametrosModel ( )
{
Label = "Percentual" ,
Unidade = "%" ,
Valor = atu ? . PercentualReservatorio
} ,
} ) ;
break ;
2025-11-26 20:00:16 +00:00
}
2025-11-27 13:31:09 +00:00
break ;
2025-11-26 20:00:16 +00:00
case AgroBase . Models . Enums . T_Code . Mov :
2025-11-27 13:31:09 +00:00
var mov = VariaveisControleOperacao . RoverEmFoco ? . DadosLeitura ? . Movimentacao ? . Dados ? . FirstOrDefault ( x = > x . ID = = label ) ;
graficoAcompanhamento . Atualizar ( inicial , momento , new List < GraficoModel . GraficoParametrosModel > ( )
2025-11-26 20:00:16 +00:00
{
2025-11-27 13:31:09 +00:00
new GraficoModel . GraficoParametrosModel ( )
2025-11-26 20:00:16 +00:00
{
2025-11-27 13:31:09 +00:00
Label = "Tensão" ,
Unidade = "V" ,
Valor = mov ? . Tensao
} ,
new GraficoModel . GraficoParametrosModel ( )
{
Label = "Corrente M" ,
Unidade = "A" ,
Valor = mov ? . Corrente_Motor
} ,
new GraficoModel . GraficoParametrosModel ( )
{
Label = "Corrente B" ,
Unidade = "A" ,
Valor = mov ? . Corrente_Barramento
} ,
new GraficoModel . GraficoParametrosModel ( )
{
Label = "Ciclo" ,
Unidade = "%" ,
Valor = mov ? . CicloTrabalho
} ,
new GraficoModel . GraficoParametrosModel ( )
{
Label = "Temperatura" ,
Unidade = "°C" ,
Valor = mov ? . TemperaturaDriver
} ,
new GraficoModel . GraficoParametrosModel ( )
{
Label = "RPM" ,
Unidade = "" ,
Valor = mov ? . RPM_Roda
} ,
} ) ;
2025-11-26 20:00:16 +00:00
break ;
2025-11-27 13:31:09 +00:00
case AgroBase . Models . Enums . T_Code . Npc :
var npc = VariaveisControleOperacao . RoverEmFoco ? . DadosLeitura ? . DadosPerformance ;
graficoAcompanhamento . Atualizar ( inicial , momento , new List < GraficoModel . GraficoParametrosModel > ( )
{
new GraficoModel . GraficoParametrosModel ( )
{
Label = "GPU" ,
Unidade = "%" ,
Valor = npc ? . GPU_load
} ,
new GraficoModel . GraficoParametrosModel ( )
{
Label = "GPU" ,
Unidade = "°C" ,
Valor = npc ? . GPU_temp
} ,
new GraficoModel . GraficoParametrosModel ( )
{
Label = "CPU" ,
Unidade = "%" ,
Valor = npc ? . CPU_load
} ,
new GraficoModel . GraficoParametrosModel ( )
{
Label = "CPU" ,
Unidade = "°C" ,
Valor = npc ? . CPU_temp
} ,
new GraficoModel . GraficoParametrosModel ( )
{
Label = "RAM" ,
Unidade = "MB" ,
Valor = npc ? . RAM_usage
} ,
} ) ;
2025-11-26 20:00:16 +00:00
break ;
2025-11-28 10:19:39 +00:00
case AgroBase . Models . Enums . T_Code . Ipb :
var conexao = VariaveisControleOperacao . RoverEmFoco ? . DadosLeitura ? . ModulosSaude ? . FirstOrDefault ( x = > x . modulo = = AgroBase . Models . Enums . T_Code . Ipb ) ;
double saude = conexao ? . saude ? ? 0 ;
double latencia = conexao ? . detalhes ? [ "avg_rtt" ] ? . Value < double > ( ) ? ? 0.0 ;
2025-11-28 19:44:53 +00:00
double timeout = conexao ? . detalhes ? [ "tmout_pct" ] ? . Value < double > ( ) ? ? 0.0 ;
2025-11-28 10:19:39 +00:00
double perda = conexao ? . detalhes ? [ "loss_pct" ] ? . Value < double > ( ) ? ? 0.0 ;
double jitter = conexao ? . detalhes ? [ "jitter" ] ? . Value < double > ( ) ? ? 0.0 ;
double bwTotal = conexao ? . detalhes ? [ "bw_total_mbps" ] ? . Value < double > ( ) ? ? 0 ;
double errRate = conexao ? . detalhes ? [ "err_rate" ] ? . Value < double > ( ) ? ? 0 ;
graficoAcompanhamento . Atualizar ( inicial , momento , new List < GraficoModel . GraficoParametrosModel > ( )
{
new GraficoModel . GraficoParametrosModel ( )
{
Label = "Latência" ,
Unidade = "ms" ,
Valor = latencia
} ,
new GraficoModel . GraficoParametrosModel ( )
2025-11-28 19:44:53 +00:00
{
Label = "Jitter" ,
Unidade = "ms" ,
Valor = jitter
} ,
new GraficoModel . GraficoParametrosModel ( )
{
Label = "Timeout" ,
Unidade = "%" ,
Valor = timeout
} ,
new GraficoModel . GraficoParametrosModel ( )
2025-11-28 10:19:39 +00:00
{
Label = "Perda" ,
Unidade = "%" ,
Valor = perda
} ,
new GraficoModel . GraficoParametrosModel ( )
{
2025-11-28 19:44:53 +00:00
Label = "Erro" ,
Unidade = "%" ,
Valor = errRate
2025-11-28 10:19:39 +00:00
} ,
new GraficoModel . GraficoParametrosModel ( )
{
Label = "Banda" ,
Unidade = "Mbps" ,
Valor = bwTotal
} ,
2025-11-28 19:44:53 +00:00
} ) ;
break ;
case AgroBase . Models . Enums . T_Code . Gps :
var gps = VariaveisControleOperacao . RoverEmFoco ? . DadosLeitura ? . Gps ;
graficoAcompanhamento . Atualizar ( inicial , momento , new List < GraficoModel . GraficoParametrosModel > ( )
{
2025-11-28 10:19:39 +00:00
new GraficoModel . GraficoParametrosModel ( )
{
2025-11-28 19:44:53 +00:00
Label = "Precisão" ,
Unidade = "cm" ,
Valor = gps ? . PrecisaoCm ? ? 0
} ,
new GraficoModel . GraficoParametrosModel ( )
{
Label = "Altitude" ,
Unidade = "m" ,
Valor = gps ? . Altitude ? ? 0
} ,
new GraficoModel . GraficoParametrosModel ( )
{
Label = "Idade" ,
Unidade = "s" ,
Valor = gps ? . IdadeCorrecao ? ? - 1
} ,
new GraficoModel . GraficoParametrosModel ( )
{
Label = "Satelites" ,
2025-11-28 10:19:39 +00:00
Unidade = "%" ,
2025-11-28 19:44:53 +00:00
Valor = gps ? . NumeroSatelites ? ? 0
2025-11-28 10:19:39 +00:00
} ,
} ) ;
break ;
2025-11-26 20:00:16 +00:00
}
2025-11-27 13:31:09 +00:00
graficoAcompanhamento . Limpar ( momento ) ;
2025-11-25 20:14:31 +00:00
}
2025-11-26 20:00:16 +00:00
private void PreencherAbaOpcoes ( bool inicial )
{
2025-11-27 13:31:09 +00:00
( var modulo , var label , var s_code , var iniciado ) = GetModuleData ( _labelModuloSelecionado ) ;
2025-11-26 20:00:16 +00:00
if ( modulo = = AgroBase . Models . Enums . T_Code . Vzo )
return ;
2025-11-28 19:44:53 +00:00
var rover = VariaveisControleOperacao . RoverEmFoco ? . DadosLeitura ;
2025-11-26 20:00:16 +00:00
if ( inicial )
{
txtOpcoes_SemDados . Visibility = Visibility . Collapsed ;
panelOpcoes_Bico . Visibility = Visibility . Collapsed ;
2025-12-02 18:42:15 +00:00
panelOpcoes_Atuador . Visibility = Visibility . Collapsed ;
2025-11-26 20:00:16 +00:00
panelOpcoes_Bomba . Visibility = Visibility . Collapsed ;
2025-11-28 19:44:53 +00:00
panelOpcoes_Direcional . Visibility = Visibility . Collapsed ;
panelOpcoes_GPS . Visibility = Visibility . Collapsed ;
2025-11-26 20:00:16 +00:00
}
2025-11-28 19:44:53 +00:00
switch ( modulo )
2025-11-26 20:00:16 +00:00
{
2025-11-28 19:44:53 +00:00
case AgroBase . Models . Enums . T_Code . Atu :
{
switch ( s_code )
{
2025-12-02 18:42:15 +00:00
case AgroBase . Models . Enums . S_Code . sMOD :
panelOpcoes_Atuador . Visibility = Visibility . Visible ;
if ( inicial )
{
sldBarra_Altura . Value = ( rover ? . Controle ? . AlturaBarra ? ? 0 ) ;
}
lblBarra_Altura . Foreground = new SolidColorBrush ( Math . Round ( sldBarra_Altura . Value ) = = Math . Round ( rover ? . Controle ? . AlturaBarra ? ? 0 , 0 ) ? System . Windows . Media . Colors . Black : System . Windows . Media . Colors . Red ) ;
break ;
2025-11-28 19:44:53 +00:00
case AgroBase . Models . Enums . S_Code . sBIC :
{
panelOpcoes_Bico . Visibility = Visibility . Visible ;
var bico = rover ? . Controle ? . BicosAtuados ? . FirstOrDefault ( x = > x . ID = = label ) ;
bool comando = bico ? . ComandoAtuar ? ? false ;
var leitura = bico ? . ValoresLeituras ? . FirstOrDefault ( x = > x . funcao = = AgroBase . Models . Modules . FuncoesPinout . EstadoLeitura ) ? . atual ? . valor ;
txtBico_Titulo . Text = $"Bico {label} - Testes" ;
txtBico_Comando . Text = comando ? "Ligado" : "Desligado" ;
txtBico_StatusReal . Text = leitura ! = null & & ( AgroBase . Models . Enums . Estado ) Enum . Parse ( typeof ( AgroBase . Models . Enums . Estado ) , leitura . ToString ( ) , true ) = = AgroBase . Models . Enums . Estado . Ligado ? "Ligado" : "Desligado" ;
txtBico_TempoLigado . Text = ( bico ? . TempoAtuado ? ? 0 ) . ToString ( "0.00" ) + " ms" ;
txtBico_Vazao . Text = ( bico ? . MediaNivelFluxo ? ? 0 ) . ToString ( "0.00" ) + " L/min" ;
txtBico_Pressao . Text = ( rover ? . Atuador ? . PressaoLinha ? ? 0 ) . ToString ( "0.00" ) + " psi" ;
txtBico_Atuacoes . Text = ( bico ? . Atuacoes ? ? 0 ) . ToString ( ) ;
2025-12-02 18:42:15 +00:00
if ( inicial )
{
txtBico_AnguloAbertura . Text = ( bico ? . AnguloAbertura ? ? 0 ) . ToString ( ) ;
sldBico_Angular . Value = ( bico ? . AnguloControle ? ? 0 ) ;
}
lblBico_Angulo . Foreground = new SolidColorBrush ( Math . Round ( sldBico_Angular . Value ) = = Math . Round ( bico ? . AnguloControle ? ? 0 , 0 ) ? System . Windows . Media . Colors . Black : System . Windows . Media . Colors . Red ) ;
txtBico_AnguloAbertura . Foreground = new SolidColorBrush ( Convert . ToInt32 ( txtBico_AnguloAbertura . Text ) = = Convert . ToInt32 ( bico ? . AnguloAbertura ? ? 0 ) ? System . Windows . Media . Colors . Black : System . Windows . Media . Colors . Red ) ;
2025-11-28 19:44:53 +00:00
break ;
}
case AgroBase . Models . Enums . S_Code . sBMB :
{
panelOpcoes_Bomba . Visibility = Visibility . Visible ;
bool comando = rover ? . Atuador ? . ComandoBomba ? ? false ;
bool leitura = rover ? . Atuador ? . LeituraComandoBomba ? ? false ;
var potencia = rover ? . Atuador ? . LeituraPotenciaBomba ? ? 0 ;
txtBomba_Comando . Text = comando ? "Ligado" : "Desligado" ;
txtBomba_StatusReal . Text = leitura ? "Ligado" : "Desligado" ;
txtBomba_PressaoLinha . Text = ( rover ? . Atuador ? . PressaoLinha ? ? 0 ) . ToString ( "0.00" ) + " psi" ;
txtBomba_Potencia . Text = potencia . ToString ( "0" ) + " %" ;
break ;
}
default :
txtOpcoes_SemDados . Visibility = Visibility . Visible ;
break ;
}
break ;
}
case AgroBase . Models . Enums . T_Code . Dir :
2025-11-26 20:00:16 +00:00
{
2025-11-28 19:44:53 +00:00
panelOpcoes_Direcional . Visibility = Visibility . Visible ;
2025-12-08 17:32:23 +00:00
var mod = rover ? . Direcional ? . Dados ? . FirstOrDefault ( x = > x . Modulo_ID = = label ) ;
AgroBase . Models . Enums . Sentido sentido_sp = mod ? . Sentido_SP ? ? AgroBase . Models . Enums . Sentido . Parado ;
2025-11-28 19:44:53 +00:00
AgroBase . Models . Enums . Sentido sentido = mod ? . SentidoReal ? ? AgroBase . Models . Enums . Sentido . Parado ;
double angulo_sp = mod ? . Angulo_SP ? ? 0 ;
2025-12-04 13:51:11 +00:00
double angulo = mod ? . AnguloDriver ? ? 0 ;
2025-11-28 19:44:53 +00:00
txtDir_Titulo . Text = $"Direcional {label} - Testes" ;
txtDir_SentidoSP . Text = sentido_sp . ToString ( ) ;
txtDir_Sentido . Text = sentido . ToString ( ) ;
txtDir_AnguloSP . Text = $"{angulo_sp:0.00}°" ;
txtDir_Angulo . Text = $"{angulo:0.00}°" ;
2025-11-26 20:00:16 +00:00
break ;
}
2025-11-28 19:44:53 +00:00
case AgroBase . Models . Enums . T_Code . Gps :
2025-11-26 20:00:16 +00:00
{
2025-11-28 19:44:53 +00:00
panelOpcoes_GPS . Visibility = Visibility . Visible ;
var dados = rover ? . Gps ;
if ( inicial )
{
sldGps_LeverArmLateral . Value = ( dados ? . LeverArmLateral ? ? 0 ) / 10.0 ;
sldGps_LeverArmFrontal . Value = ( dados ? . LeverArmFrontal ? ? 0 ) / 10.0 ;
}
lblGps_LeverArmLateral . Content = $"{(sldGps_LeverArmLateral.Value * 10.0):00} cm" ;
lblGps_LeverArmLateral . Foreground = new SolidColorBrush ( Math . Round ( sldGps_LeverArmLateral . Value * 10.0 , 0 ) = = Math . Round ( dados ? . LeverArmLateral ? ? 0 , 0 ) ? System . Windows . Media . Colors . Black : System . Windows . Media . Colors . Red ) ;
lblGps_LeverArmFrontal . Content = $"{(sldGps_LeverArmFrontal.Value * 10.0):00} cm" ;
lblGps_LeverArmFrontal . Foreground = new SolidColorBrush ( Math . Round ( sldGps_LeverArmFrontal . Value * 10.0 , 0 ) = = Math . Round ( dados ? . LeverArmFrontal ? ? 0 , 0 ) ? System . Windows . Media . Colors . Black : System . Windows . Media . Colors . Red ) ;
txtGps_Correcao . Text = ( dados ? . QualidadeFix ? ? AgroBase . Models . Enums . TiposCorrecaoGPS . SemCorrecao ) . ToString ( ) ;
txtGps_Idade . Text = ( dados ? . IdadeCorrecao ? ? - 1 ) . ToString ( ) ;
txtGps_Precisao . Text = ( dados ? . PrecisaoCm ? ? - 1 ) . ToString ( ) ;
txtGps_NSatelites . Text = ( dados ? . NumeroSatelites ? ? 0 ) . ToString ( ) ;
txtGps_DistBase . Text = ( Variaveis . GpsService . IsConnected ? AgroBase . Models . GPSUtils . DistanciaEntrePontos ( dados ? ? new AgroBase . Models . GPSModel ( ) , Variaveis . GpsService . UltimaLeitura ) : 0 ) . ToString ( ) ;
txtGps_Orientacao . Text = ( dados ? . OrientacaoReal ? ? 0 ) . ToString ( ) ;
2025-11-26 20:00:16 +00:00
break ;
}
default :
txtOpcoes_SemDados . Visibility = Visibility . Visible ;
break ;
}
}
2025-12-08 17:32:23 +00:00
private void PreencherAbaLogs ( IEnumerable < AgroBase . Models . OperacaoSensoriamentoLogErrosModel > logs )
{
lstSaude_Logs . Items . Clear ( ) ;
if ( logs ! = null )
{
foreach ( var log in logs )
{
lstSaude_Logs . Items . Add ( log . Momento . ToString ( "HH:mm:ss.fff" ) + " - " + log . Mensagem ) ;
}
}
}
2025-12-02 18:42:15 +00:00
#region Atuador
private void sldBarra_Altura_ValueChanged ( object sender , RoutedPropertyChangedEventArgs < double > e )
{
2025-12-04 13:51:11 +00:00
if ( lblBarra_Altura ! = null )
lblBarra_Altura . Content = $"{Convert.ToInt32(sldBarra_Altura.Value):00} cm" ;
2025-12-02 18:42:15 +00:00
}
private void btnBarra_Mover_Click ( object sender , RoutedEventArgs e )
{
( var modulo , var label , var s_code , var iniciado ) = GetModuleData ( _labelModuloSelecionado ) ;
if ( modulo ! = AgroBase . Models . Enums . T_Code . Atu & & s_code ! = AgroBase . Models . Enums . S_Code . sMOD )
return ;
2025-12-04 13:51:11 +00:00
VariaveisControleOperacao . EnviarComandoAtuador ( label , altura : Convert . ToInt32 ( sldBarra_Altura . Value ) ) ;
2025-12-02 18:42:15 +00:00
}
#endregion
2025-11-28 19:44:53 +00:00
#region Bico pulverizador
2025-11-25 20:14:31 +00:00
private void btnBico_Ligar_Click ( object sender , RoutedEventArgs e )
{
2025-11-27 13:31:09 +00:00
( var modulo , var label , var s_code , var iniciado ) = GetModuleData ( _labelModuloSelecionado ) ;
2025-11-26 20:00:16 +00:00
if ( modulo ! = AgroBase . Models . Enums . T_Code . Atu & & s_code ! = AgroBase . Models . Enums . S_Code . sBIC )
2025-11-25 20:14:31 +00:00
return ;
2025-12-02 18:42:15 +00:00
VariaveisControleOperacao . EnviarComandoAtuador ( label , status : true ) ;
2025-11-25 20:14:31 +00:00
}
private void btnBico_Desligar_Click ( object sender , RoutedEventArgs e )
{
2025-11-27 13:31:09 +00:00
( var modulo , var label , var s_code , var iniciado ) = GetModuleData ( _labelModuloSelecionado ) ;
2025-11-26 20:00:16 +00:00
if ( modulo ! = AgroBase . Models . Enums . T_Code . Atu & & s_code ! = AgroBase . Models . Enums . S_Code . sBIC )
2025-11-25 20:14:31 +00:00
return ;
2025-12-02 18:42:15 +00:00
VariaveisControleOperacao . EnviarComandoAtuador ( label , status : false ) ;
2025-11-24 19:58:20 +00:00
}
2025-11-28 19:44:53 +00:00
private void sldBico_Angular_ValueChanged ( object sender , RoutedPropertyChangedEventArgs < double > e )
{
2025-12-02 18:42:15 +00:00
lblBico_Angulo . Content = $"{Convert.ToInt32(sldBico_Angular.Value):00}°" ;
}
private void btnBico_Mover_Click ( object sender , RoutedEventArgs e )
{
( var modulo , var label , var s_code , var iniciado ) = GetModuleData ( _labelModuloSelecionado ) ;
if ( modulo ! = AgroBase . Models . Enums . T_Code . Atu & & s_code ! = AgroBase . Models . Enums . S_Code . sBIC )
return ;
VariaveisControleOperacao . EnviarComandoAtuador ( label , angulo_controle : Convert . ToInt32 ( sldBico_Angular . Value ) ) ;
}
private void btnBico_AnguloAberturaSalvar_Click ( object sender , RoutedEventArgs e )
{
( var modulo , var label , var s_code , var iniciado ) = GetModuleData ( _labelModuloSelecionado ) ;
if ( modulo ! = AgroBase . Models . Enums . T_Code . Atu & & s_code ! = AgroBase . Models . Enums . S_Code . sBIC )
return ;
VariaveisControleOperacao . EnviarComandoAtuador ( label , angulo_abertura : int . Parse ( txtBico_AnguloAbertura . Text ) ) ;
2025-11-28 19:44:53 +00:00
}
#endregion
#region Bomba pressurizadora
2025-11-26 20:00:16 +00:00
private void btnBomba_Ligar_Click ( object sender , RoutedEventArgs e )
{
2025-11-27 13:31:09 +00:00
( var modulo , var label , var s_code , var iniciado ) = GetModuleData ( _labelModuloSelecionado ) ;
2025-11-26 20:00:16 +00:00
if ( modulo ! = AgroBase . Models . Enums . T_Code . Atu & & s_code ! = AgroBase . Models . Enums . S_Code . sBMB )
return ;
2025-12-02 18:42:15 +00:00
VariaveisControleOperacao . EnviarComandoAtuador ( label , status : true ) ;
2025-11-26 20:00:16 +00:00
}
private void btnBomba_Desligar_Click ( object sender , RoutedEventArgs e )
{
2025-11-27 13:31:09 +00:00
( var modulo , var label , var s_code , var iniciado ) = GetModuleData ( _labelModuloSelecionado ) ;
2025-11-26 20:00:16 +00:00
if ( modulo ! = AgroBase . Models . Enums . T_Code . Atu & & s_code ! = AgroBase . Models . Enums . S_Code . sBMB )
return ;
2025-12-02 18:42:15 +00:00
VariaveisControleOperacao . EnviarComandoAtuador ( label , status : false ) ;
2025-11-26 20:00:16 +00:00
}
private void sldBomba_PressaoAlvo_ValueChanged ( object sender , RoutedPropertyChangedEventArgs < double > e )
{
lblBomba_PressaoAlvo . Content = $"{e.NewValue:0} psi" ;
}
2025-11-28 19:44:53 +00:00
#endregion
#region Direcional
private void btnDir_Referenciar_Click ( object sender , RoutedEventArgs e )
{
( var modulo , var label , var s_code , var iniciado ) = GetModuleData ( _labelModuloSelecionado ) ;
if ( modulo ! = AgroBase . Models . Enums . T_Code . Dir )
return ;
VariaveisControleOperacao . EnviarComandoReferenciamento ( mod_id : label ) ;
}
private void btnDir_Movimentar_Click ( object sender , RoutedEventArgs e )
{
( var modulo , var label , var s_code , var iniciado ) = GetModuleData ( _labelModuloSelecionado ) ;
if ( modulo ! = AgroBase . Models . Enums . T_Code . Dir )
return ;
AgroBase . Models . Enums . TipoMovimentoDirecional tipo = ( AgroBase . Models . Enums . TipoMovimentoDirecional ) Enum . Parse ( typeof ( AgroBase . Models . Enums . TipoMovimentoDirecional ) , cmbDir_Movimento . Text ) ;
AgroBase . Models . Enums . Direcao direcao = ( AgroBase . Models . Enums . Direcao ) Enum . Parse ( typeof ( AgroBase . Models . Enums . Direcao ) , cmbDir_Direcao . Text ) ;
double angulo = Convert . ToInt32 ( sldDir_Angulo . Value ) ;
VariaveisControleOperacao . EnviarComandoDirecional ( direcao , angulo , tipo , mod_id : label ) ;
}
private void sldDir_Angulo_ValueChanged ( object sender , RoutedPropertyChangedEventArgs < double > e )
{
lblDir_Angulo . Content = $"{Convert.ToInt32(sldDir_Angulo.Value)}°" ;
}
#endregion
#region Gnss
private void btnGps_Salvar_Click ( object sender , RoutedEventArgs e )
{
VariaveisControleOperacao . EnviarComandoLeverArm ( lateral : sldGps_LeverArmLateral . Value * 10.0 , frontal : sldGps_LeverArmFrontal . Value * 10.0 ) ;
}
private void sldGps_LeverArmLateral_ValueChanged ( object sender , RoutedPropertyChangedEventArgs < double > e )
{
lblGps_LeverArmLateral . Content = $"{(sldGps_LeverArmLateral.Value * 10.0):00} cm" ;
}
private void sldGps_LeverArmFrontal_ValueChanged ( object sender , RoutedPropertyChangedEventArgs < double > e )
{
lblGps_LeverArmFrontal . Content = $"{(sldGps_LeverArmFrontal.Value * 10.0):00} cm" ;
}
#endregion
2025-11-25 12:17:19 +00:00
private void btnSaude_Salvar_Click ( object sender , RoutedEventArgs e )
2025-11-24 19:58:20 +00:00
{
2025-11-27 13:31:09 +00:00
( var modulo , var label , var s_code , var iniciado ) = GetModuleData ( _labelModuloSelecionado ) ;
2025-11-25 12:17:19 +00:00
if ( modulo = = AgroBase . Models . Enums . T_Code . Vzo )
return ;
2025-11-24 19:58:20 +00:00
var rover = VariaveisControleOperacao . RoverEmFoco ;
2025-11-25 20:14:31 +00:00
if ( rover = = null )
2025-11-24 19:58:20 +00:00
{
MessageBox . Show ( $"Sem dados para o módulo {modulo} ({label})" ) ;
return ;
}
2025-11-25 20:14:31 +00:00
var mod = rover . ModulosMandatorios . FirstOrDefault ( x = > x . Dispositivo = = modulo ) ;
if ( mod = = null )
2025-11-25 12:17:19 +00:00
{
2025-11-25 20:14:31 +00:00
mod = new AgroBase . Models . OperacaoModulosMandatoriosModel ( )
{
Dispositivo = modulo ,
ComponentesEmUso = new Dictionary < string , bool > ( )
} ;
rover . ModulosMandatorios . Add ( mod ) ;
2025-11-25 12:17:19 +00:00
}
2025-11-25 20:14:31 +00:00
mod . Mandatorio = chbSaude_Mandatorio . IsChecked ? ? false ;
if ( string . IsNullOrEmpty ( label ) )
{
mod . Utilizar = chbSaude_EmUso . IsChecked ? ? false ;
}
else
{
mod . ComponentesEmUso [ label ] = chbSaude_EmUso . IsChecked ? ? false ;
}
2025-11-25 12:17:19 +00:00
VariaveisControleOperacao . EnviarParametrosOperacao ( new AgroBase . Models . Operacoes . OperacaoParametrosModel ( )
{
ModulosMandatorios = rover . ModulosMandatorios ,
} ) ;
2025-11-24 19:58:20 +00:00
}
2025-11-28 19:44:53 +00:00
2025-11-24 19:58:20 +00:00
#endregion
2025-11-24 16:05:50 +00:00
#region POSICAO
2025-11-14 17:11:58 +00:00
2025-11-24 16:05:50 +00:00
public void AtualizarDadosTela_GNSS ( AgroBase . Models . GPSModel dados , string? marker_id = null , double progresso = double . NaN )
{
Application . Current . Dispatcher . BeginInvoke ( new Action ( ( ) = >
{
try
{
bool dados_base = marker_id = = VariaveisControleOperacao . BaseMarkerID ;
lblGNSS_Posicao . Foreground = new SolidColorBrush ( dados . Inicializado ? System . Windows . Media . Colors . Green : System . Windows . Media . Colors . Red ) ;
lblGNSS_Correcao . Content = $"Correção {dados.QualidadeFix} " +
( dados . QualidadeFix = = AgroBase . Models . Enums . TiposCorrecaoGPS . BaseFix ?
( dados . OrientacaoReal . ToString ( "0.00" ) + "°" ) :
( ( dados . Ntrip_ativado ? "N" : "B" ) + $" {dados.IdadeCorrecao.ToString(" 0.0 ")} s" ) ) ;
lblGNSS_Satelites . Content = $"Satélites {dados.NumeroSatelites} ({dados.PrecisaoCm.ToString(" 0.00 ")} cm)" ;
lblGNSS_Altitude . Content = $"Altitude {dados.Altitude.ToString(" 0.00 ")} m" ;
if ( dados_base )
{
2025-11-28 19:44:53 +00:00
btnGNSS_FixarBase . Visibility = Visibility . Visible ;
2025-11-24 16:05:50 +00:00
if ( double . IsNaN ( progresso ) )
{
2025-11-28 19:44:53 +00:00
lblGNSS_Progresso . Visibility = Visibility . Collapsed ;
2025-11-24 16:05:50 +00:00
}
else
{
lblGNSS_Progresso . Visibility = Visibility . Visible ;
lblGNSS_Progresso . Content = $"{progresso.ToString(" 0.00 ")}%" ;
}
bool gnss_fix_preciso = new List < AgroBase . Models . Enums . TiposCorrecaoGPS > ( ) { AgroBase . Models . Enums . TiposCorrecaoGPS . RTKFixo , AgroBase . Models . Enums . TiposCorrecaoGPS . RTKFlutuante } . Contains ( Variaveis . GpsService ? . UltimaLeitura ? . QualidadeFix ? ? AgroBase . Models . Enums . TiposCorrecaoGPS . SemCorrecao ) ;
bool gnss_fixado = Variaveis . GpsService ? . BaseFix ? . CorrecaoAbsoluta ? ? false ;
bool gnss_fixando = btnGNSS_FixarBase . Content . ToString ( ) = = "Parar" ;
btnGNSS_FixarBase . IsEnabled = ( gnss_fix_preciso & & ! gnss_fixado ) | | gnss_fixando | | gnss_fixado ;
btnGNSS_FixarBase . Content = gnss_fixado | | ! gnss_fixando ? "Fixar" : "Parar" ;
}
else
{
2025-11-28 19:44:53 +00:00
btnGNSS_FixarBase . Visibility = Visibility . Collapsed ;
lblGNSS_Progresso . Visibility = Visibility . Collapsed ;
2025-11-24 16:05:50 +00:00
}
}
catch ( Exception exUi )
{
Variaveis . MostrarLog ( $"Erro ao atualizar UI GNSS: {exUi.Message}" ) ;
}
} ) ) ;
2025-11-14 17:11:58 +00:00
}
2025-11-24 16:05:50 +00:00
private void btnGNSS_FixarBase_Click ( object sender , RoutedEventArgs e )
{
2025-11-28 19:44:53 +00:00
if ( ! Variaveis . GpsService . BaseFix . FixLiberado )
2025-11-24 16:05:50 +00:00
{
2025-11-28 19:44:53 +00:00
if ( Variaveis . GpsService . BaseFix . CorrecaoAbsoluta )
2025-11-24 16:05:50 +00:00
{
2025-11-28 19:44:53 +00:00
var res = MessageBox . Show ( "Mudar posição da base?" , "Tem certeza que deseja fixar a posição da base novamente?" , MessageBoxButton . YesNo , MessageBoxImage . Question ) ;
if ( res = = MessageBoxResult . Yes )
2025-11-24 16:05:50 +00:00
{
btnGNSS_FixarBase . Content = "Parar" ;
Variaveis . GpsService . BaseFix . FixLiberado = true ;
2025-11-28 19:44:53 +00:00
Task . Run ( async ( ) = > await Variaveis . GpsService . ConfigurarModulo ( ) ) ;
2025-11-24 16:05:50 +00:00
}
}
else
{
2025-11-28 19:44:53 +00:00
btnGNSS_FixarBase . Content = "Parar" ;
Variaveis . GpsService . BaseFix . FixLiberado = true ;
2025-11-24 16:05:50 +00:00
}
}
else
{
2025-11-28 19:44:53 +00:00
btnGNSS_FixarBase . Content = "Fixar" ;
Variaveis . GpsService . BaseFix . FixLiberado = false ;
2025-11-24 16:05:50 +00:00
}
}
2025-11-14 17:11:58 +00:00
#endregion
2025-11-24 16:05:50 +00:00
#region CONTROLE
2025-11-14 17:11:58 +00:00
2025-11-24 16:05:50 +00:00
public void AtualizarDadosTela_Controle ( AgroBase . Models . OperacaoControleModel controle , double angulo , double velocidade , bool emergencia , bool pausa , bool refing )
2025-11-14 17:11:58 +00:00
{
2025-11-24 16:05:50 +00:00
Application . Current . Dispatcher . BeginInvoke ( new Action ( ( ) = >
{
try
{
CTRL . AtualizarDadosControle (
angSp : controle . Angulo ,
angCur : angulo ,
tipoMov : controle . TipoMovimento ,
velSp : controle . PercentualVelocidadeSPKmh ,
velKmh : velocidade ,
emg : emergencia ,
pause : pausa ,
refing : refing
) ;
}
catch ( Exception exUi )
{
Variaveis . MostrarLog ( $"Erro ao atualizar UI Controle: {exUi.Message}" ) ;
}
} ) ) ;
2025-11-14 17:11:58 +00:00
}
#endregion
2025-11-24 16:05:50 +00:00
#region PARAMETROS DA OPERACAO
2025-11-14 17:11:58 +00:00
2025-11-24 16:05:50 +00:00
public void AtualizarDadosTela_ParametrosOperacao ( AgroBase . Models . Operacoes . OperacaoParametrosControleModel ? controle )
{
if ( controle = = null ) return ;
Application . Current . Dispatcher . BeginInvoke ( new Action ( ( ) = >
{
try
{
txtParametros_VelCErvas . Text = controle . MovVelocidadeCErvasPercent . ToString ( ) ;
txtParametros_VelSErvas . Text = controle . MovVelocidadeSErvasPercent . ToString ( ) ;
txtParametros_AngMax . Text = controle . DirAnguloMaximo . ToString ( ) ;
txtParametros_RoiAtuacao . Text = controle . AtuPercentualInicioPulverizacao . ToString ( ) ;
txtParametros_AreaAtuacao . Text = controle . AtuAlturaAreaPulverizacao . ToString ( ) ;
txtParametros_PressaoLiha . Text = controle . AtuPressaoLinha . ToString ( ) ;
txtParametros_PctErvaOn . Text = controle . AtuPercentualErvasBicoOn . ToString ( ) ;
txtParametros_PctErvaOff . Text = controle . AtuPercentualErvasBicoOff . ToString ( ) ;
txtParametros_TempoOn . Text = controle . AtuDuracaoAtuacao . ToString ( ) ;
chbParametros_Pulverizador . IsChecked = controle . PulverizadorAutomatico ;
chbParametros_Frenagem . IsChecked = controle . FrenagemAutomatica ;
chbParametros_Sonar . IsChecked = controle . SonarAtivado ;
}
catch ( Exception exUi )
{
Variaveis . MostrarLog ( $"Erro ao atualizar UI Parametros da Operacao: {exUi.Message}" ) ;
}
} ) ) ;
}
private void btnParametros_Salvar_Click ( object sender , RoutedEventArgs e )
{
var modo = ( CTRL . TgManual . IsChecked ? ? false ) ? AgroBase . Models . Enums . ModoOperacao . Manual : AgroBase . Models . Enums . ModoOperacao . MapaGPS ;
2025-11-25 12:17:19 +00:00
var rover = VariaveisControleOperacao . RoverEmFoco ;
2025-11-24 16:05:50 +00:00
VariaveisControleOperacao . EnviarParametrosOperacao ( new AgroBase . Models . Operacoes . OperacaoParametrosModel ( )
{
Modo = modo ,
Descricao = "Operacao da base" ,
QtdCamerasSolo = 1 ,
2025-11-25 12:17:19 +00:00
QtdBicos = 4 ,
2025-11-24 16:05:50 +00:00
CapacidadeReservatorio = 45 ,
Controle = new AgroBase . Models . Operacoes . OperacaoParametrosControleModel ( )
{
MovimentoAutomatico = modo ! = AgroBase . Models . Enums . ModoOperacao . Manual ,
SonarAtivado = chbParametros_Sonar . IsChecked ? ? false ,
FrenagemAutomatica = chbParametros_Frenagem . IsChecked ? ? false ,
MovVelocidadeCErvasPercent = int . Parse ( txtParametros_VelCErvas . Text ) ,
MovVelocidadeSErvasPercent = int . Parse ( txtParametros_VelSErvas . Text ) ,
DirAnguloMaximo = int . Parse ( txtParametros_AngMax . Text ) ,
DirTipoMovimento = AgroBase . Models . Enums . TiposControladorDirecional . MPC ,
DirVelocidadeMovimento = 50 ,
PulverizadorAutomatico = chbParametros_Pulverizador . IsChecked ? ? false ,
AtuPercentualErvasBicoOn = double . Parse ( txtParametros_PctErvaOn . Text ) ,
AtuPercentualErvasBicoOff = double . Parse ( txtParametros_PctErvaOff . Text ) ,
AtuDuracaoAtuacao = int . Parse ( txtParametros_TempoOn . Text ) ,
AtuAlturaAreaPulverizacao = double . Parse ( txtParametros_AreaAtuacao . Text ) ,
AtuPercentualInicioPulverizacao = double . Parse ( txtParametros_RoiAtuacao . Text ) ,
AtuPressaoLinha = double . Parse ( txtParametros_PressaoLiha . Text ) ,
} ,
2025-11-25 12:17:19 +00:00
ModulosMandatorios = rover ? . ModulosMandatorios ,
ParametrosMandatorios = rover ? . ParametrosMandatorios ,
2025-11-24 16:05:50 +00:00
RuasPercorrer = MAP . RuasMapaCarregado . Where ( x = > x . Selected ) . Select ( x = > x . Id ) . ToList ( ) ,
Mapa = MAP . CriarDadosMapa ( )
} ) ;
}
private void btnParametros_Atualizar_Click ( object sender , RoutedEventArgs e )
2025-11-14 17:11:58 +00:00
{
2025-11-24 19:58:20 +00:00
VariaveisControleOperacao . RequisitarParametrosOperacao ( ) ;
2025-11-14 17:11:58 +00:00
}
#endregion
#region MAPA
private void MAP_MarkerClicked ( object? sender , MapMarkerManager . MarkerClickedEventArgs e )
{
if ( string . IsNullOrEmpty ( e . MarkerId ) )
{
2025-11-24 16:05:50 +00:00
Variaveis . MostrarLog ( $"Sem rover em foco" ) ;
LimparDadosTela_Telemetria ( e . MarkerId ) ;
2025-11-14 17:11:58 +00:00
}
else
{
2025-11-24 16:05:50 +00:00
Variaveis . MostrarLog ( $"Rover em foco: {e.MarkerId}" ) ;
int idx = cmbDispositivo . Items . IndexOf ( e . MarkerId ) ;
cmbDispositivo . SelectedIndex = idx ;
2025-11-14 17:11:58 +00:00
}
}
private void MAP_StreetMapClicked ( object? sender , MapViewControl . StreetMapClickedEventArgs e )
{
Variaveis . MostrarLog ( $"Rua clicada: {e.StreetId}. Ruas selecionadas: {string.Join(" , ", e.SelectedStreetsIds)}" ) ;
}
2025-11-24 16:05:50 +00:00
private void AtualizarDadosTela_Mapa ( AgroBase . Models . OperacaoSensoriamentoLogTrajetoriaModel Trajetoria )
{
lblMapaInfo_Debug . Content = $"" +
$"Próximo Ponto: {Trajetoria.ProximoPonto.idxPonto} | " +
( Trajetoria . ProximoPonto . Aproximando ? "Aproximando" : "Afastando" ) + " | " +
$"Distância próximo ponto: {Trajetoria.ProximoPonto.DistanciaAtual.ToString(" 0.00 ")} m | " +
$"Distância ponto anterior: {Trajetoria.PontoAtual.DistanciaAtual.ToString(" 0.00 ")} m | " +
$"Corredor: " + ( Trajetoria . CorredorAtual . Dentro ? "Dentro" : "Fora" ) + " | " +
$"Margem: " + ( Trajetoria . NaMargemDoCorredor ? "Sim" : "Não" ) + " | " +
$"Disância Esquerda: {(Trajetoria.DistanciaEsquerda * 100.0).ToString(" 0.00 ")} cm | " +
$"Distância Direita: {(Trajetoria.DistanciaDireita * 100.0).ToString(" 0.00 ")} cm | " +
$"Status: {Trajetoria.StatusCarro}" ;
double erroLateral = ( Trajetoria . DistanciaEsquerda - Trajetoria . DistanciaDireita ) / 2.0 * 100.0 ;
AtualizarDadosTela_IMU ( erro_lateral : erroLateral ) ;
}
2025-11-14 17:11:58 +00:00
#endregion
2025-11-24 16:05:50 +00:00
#region HEADING
2025-11-14 17:11:58 +00:00
2025-11-24 16:05:50 +00:00
public void AtualizarDadosTela_Heading ( double headingRover , double headingCourse = double . NaN )
2025-11-14 17:11:58 +00:00
{
2025-11-24 16:05:50 +00:00
Application . Current . Dispatcher . BeginInvoke ( new Action ( ( ) = >
{
try
{
HDG . Heading = headingRover ;
HDG . CourseHeading = headingCourse ;
}
catch ( Exception exUi )
{
Variaveis . MostrarLog ( $"Erro ao atualizar UI Heading: {exUi.Message}" ) ;
}
} ) ) ;
2025-11-14 17:11:58 +00:00
}
#endregion
2025-11-24 16:05:50 +00:00
#region IMU
2025-11-14 17:11:58 +00:00
2025-11-24 16:05:50 +00:00
public void AtualizarDadosTela_IMU ( double? roll = null , double? pitch = null , double? erro_lateral = null )
2025-11-14 17:11:58 +00:00
{
2025-11-24 16:05:50 +00:00
Application . Current . Dispatcher . BeginInvoke ( new Action ( ( ) = >
2025-11-14 17:11:58 +00:00
{
2025-11-24 16:05:50 +00:00
try
2025-11-14 17:11:58 +00:00
{
2025-11-24 16:05:50 +00:00
if ( roll ! = null ) IMU . RollDeg = ( double ) roll ;
if ( pitch ! = null ) IMU . PitchDeg = ( double ) pitch ;
if ( erro_lateral ! = null ) IMU . LateralError = ( double ) erro_lateral ;
2025-11-14 17:11:58 +00:00
}
2025-11-24 16:05:50 +00:00
catch ( Exception exUi )
{
Variaveis . MostrarLog ( $"Erro ao atualizar UI IMU: {exUi.Message}" ) ;
}
} ) ) ;
}
#endregion
#region CAMERA FRONTAL
private void IniciarStreamCameraFrontal ( )
{
var path = @"streams\camera_frontal.sdp" ;
if ( ! File . Exists ( path ) )
{
string stream =
"v=0\r\n" +
"o=- 0 0 IN IP4 0.0.0.0\r\n" +
"s=OAK H264\r\n" +
"c=IN IP4 0.0.0.0\r\n" +
"t=0 0\r\n" +
"m=video 5000 RTP/AVP 96\r\n" +
"a=rtpmap:96 H264/90000\r\n" +
"a=fmtp:96 packetization-mode=1\r\n" ;
File . WriteAllText ( path , stream ) ;
2025-11-14 17:11:58 +00:00
}
2025-11-24 16:05:50 +00:00
_mediaFront ? . Dispose ( ) ; // limpa antigo, se existir
_mediaFront = new Media ( _libVLC , path , FromType . FromPath ) ;
// _mediaFront.AddOption(":network-caching=150"); // se quiser por arquivo
2025-11-14 17:11:58 +00:00
2025-11-24 16:05:50 +00:00
_playerFront . Play ( _mediaFront ) ;
2025-11-14 17:11:58 +00:00
2025-11-24 16:05:50 +00:00
VariaveisControleOperacao . EnviarComandoTransmissaoVideo ( AgroBase . Models . Enums . T_Code . Snr , true ) ;
}
private void PararStreamCameraFrontal ( bool finalizar = false )
2025-11-14 17:11:58 +00:00
{
2025-11-24 16:05:50 +00:00
_playerFront ? . Stop ( ) ;
if ( finalizar )
2025-11-14 17:11:58 +00:00
{
2025-11-24 16:05:50 +00:00
_mediaFront ? . Dispose ( ) ;
_mediaFront = null ;
_playerFront ? . Dispose ( ) ;
_playerFront = null ;
}
2025-11-14 17:11:58 +00:00
2025-11-24 16:05:50 +00:00
VariaveisControleOperacao . EnviarComandoTransmissaoVideo ( AgroBase . Models . Enums . T_Code . Snr , false ) ;
}
#endregion
#region CAMERA ERVAS
private void IniciarStreamCameraErvas ( )
{
var path = @"streams\camera_ervas.sdp" ;
if ( ! File . Exists ( path ) )
{
string stream =
"v=0\r\n" +
"o=- 0 0 IN IP4 0.0.0.0\r\n" +
"s=OAK H264\r\n" +
"c=IN IP4 0.0.0.0\r\n" +
"t=0 0\r\n" +
"m=video 5002 RTP/AVP 96\r\n" + // <- porta 5001
"a=rtpmap:96 H264/90000\r\n" +
"a=fmtp:96 packetization-mode=1\r\n" ;
File . WriteAllText ( path , stream ) ;
2025-11-14 17:11:58 +00:00
}
2025-11-24 16:05:50 +00:00
_mediaWeed ? . Dispose ( ) ;
_mediaWeed = new Media ( _libVLC , path , FromType . FromPath ) ;
// _mediaWeed.AddOption(":network-caching=150");
_playerWeed . Play ( _mediaWeed ) ;
VariaveisControleOperacao . EnviarComandoTransmissaoVideo ( AgroBase . Models . Enums . T_Code . Cam , true ) ;
}
private void PararStreamCameraErvas ( bool finalizar = false )
{
_playerWeed ? . Stop ( ) ;
if ( finalizar )
2025-11-14 17:11:58 +00:00
{
2025-11-24 16:05:50 +00:00
_mediaWeed ? . Dispose ( ) ;
_mediaWeed = null ;
_playerWeed ? . Dispose ( ) ;
_playerWeed = null ;
2025-11-14 17:11:58 +00:00
}
2025-11-24 16:05:50 +00:00
VariaveisControleOperacao . EnviarComandoTransmissaoVideo ( AgroBase . Models . Enums . T_Code . Cam , false ) ;
}
#endregion
#region PULVERIZADOR
2025-12-02 18:42:15 +00:00
private void AtualizarDadosTela_Pulverizador ( AgroBase . Models . OperacaoSensoriamentoLogModel dados )
{
ATU . ComprimentoBarraCm = AgroBase . Models . VariaveisEquipamento . ComprimentoBarraPulverizadoraCm ;
ATU . DistanciaEntreBicosCm = AgroBase . Models . VariaveisEquipamento . DistanciaEntreBicosCm ;
ATU . AlturaBarra = dados ? . Controle ? . AlturaBarra ? ? AgroBase . Models . VariaveisEquipamento . AlturaBarraPulverizadoraCm ;
2025-12-04 13:51:11 +00:00
ATU . IsBombaOn = dados ? . Atuador ? . LeituraComandoBomba ? ? false ;
ATU . PressaoLinha = dados ? . Atuador ? . PressaoLinha ? ? 0 ;
ATU . VazaoInstantanea = dados ? . Atuador ? . VazaoInstantanea ? ? 0 ;
ATU . TempoAtuado = ( dados ? . Atuador ? . TempoBombaAtuada ? ? 0 ) / 1000.0 ;
double erroLateral = ( ( dados ? . Trajetoria ? . DistanciaEsquerda ? ? 0 ) - ( dados ? . Trajetoria ? . DistanciaDireita ? ? 0 ) ) / 2.0 * 100.0 ;
ATU . LarguraRuaCm = 100.0 ;
ATU . ErroLateralCm = erroLateral ;
2025-12-02 18:42:15 +00:00
2025-12-04 13:51:11 +00:00
if ( ATU . QtdBicos ! = dados ? . Controle ? . BicosAtuados ? . Count )
2025-12-02 18:42:15 +00:00
{
2025-12-04 13:51:11 +00:00
ATU . QtdBicos = dados ? . Controle ? . BicosAtuados ? . Count ? ? AgroBase . Models . VariaveisEquipamento . QuantidadeBicosPulverizadores ;
2025-12-02 18:42:15 +00:00
}
foreach ( var bico in ATU . Bicos )
{
2025-12-04 13:51:11 +00:00
var _bc = dados ? . Controle ? . BicosAtuados ? . FirstOrDefault ( x = > ( x . Posicao - 1 ) = = bico . Index ) ;
2025-12-02 18:42:15 +00:00
if ( _bc = = null ) continue ;
bico . OpeningAngle = _bc . AnguloAbertura ;
bico . AnguloControle = _bc . AnguloControle ;
bico . IsCommandOn = _bc . ComandoAtuar ;
bico . IsSpraying = ( AgroBase . Models . Enums . Estado ) ( _bc . ValoresLeituras . FirstOrDefault ( x = > x . funcao = = AgroBase . Models . Modules . FuncoesPinout . EstadoLeitura ) ? . atual ? . valor ? ? AgroBase . Models . Enums . Estado . Desligado ) = = AgroBase . Models . Enums . Estado . Ligado ;
bico . Vazao = _bc . MediaNivelFluxo ;
bico . Atuacoes = _bc . Atuacoes ;
bico . TempoAtuado = _bc . TempoAtuado / 1000.0 ;
}
}
2025-11-14 17:11:58 +00:00
#endregion
#region LIDAR
public void AtualizarDadostela_LIDAR ( List < AgroBase . Models . LivoxBboxModel > bboxes )
{
2025-11-24 16:05:50 +00:00
Application . Current . Dispatcher . BeginInvoke ( new Action ( ( ) = >
{
try
{
BBoxes3D . SetBboxes ( bboxes ) ;
}
catch ( Exception exUi )
{
Variaveis . MostrarLog ( $"Erro ao atualizar UI Lidar: {exUi.Message}" ) ;
}
} ) ) ;
2025-11-14 17:11:58 +00:00
}
2025-11-25 12:17:19 +00:00
2025-11-25 20:14:31 +00:00
2025-11-28 19:44:53 +00:00
2025-12-02 18:42:15 +00:00
2025-12-04 13:51:11 +00:00
2025-11-14 17:11:58 +00:00
#endregion
2025-12-04 13:51:11 +00:00
#region ALERTAS
2025-11-12 11:15:07 +00:00
2025-12-04 13:51:11 +00:00
public ObservableCollection < AlertaModel > AlertasAtivos { get ; } = new ( ) ;
2025-11-12 11:15:07 +00:00
2025-12-04 13:51:11 +00:00
private AlertaModel _toastAlerta ;
public AlertaModel ToastAlerta
2025-11-27 13:31:09 +00:00
{
2025-12-04 13:51:11 +00:00
get = > _toastAlerta ;
set
{
if ( _toastAlerta = = value ) return ;
_toastAlerta = value ;
OnPropertyChanged ( nameof ( ToastAlerta ) ) ;
}
2025-11-27 13:31:09 +00:00
}
2025-12-04 13:51:11 +00:00
private readonly DispatcherTimer _toastTimer ;
2025-11-27 13:31:09 +00:00
2025-12-04 13:51:11 +00:00
public event PropertyChangedEventHandler PropertyChanged ;
protected void OnPropertyChanged ( string name ) = > PropertyChanged ? . Invoke ( this , new PropertyChangedEventArgs ( name ) ) ;
2025-11-27 13:31:09 +00:00
2025-12-04 13:51:11 +00:00
private System . Windows . Point _scrollDragStartPoint ;
private double _scrollDragStartOffset ;
private bool _isDraggingScroll ;
2025-11-27 13:31:09 +00:00
2025-12-04 13:51:11 +00:00
private void svAlertas_PreviewMouseLeftButtonDown ( object sender , MouseButtonEventArgs e )
2025-11-27 13:31:09 +00:00
{
2025-12-04 13:51:11 +00:00
if ( sender is ScrollViewer sv )
{
_isDraggingScroll = true ;
_scrollDragStartPoint = e . GetPosition ( sv ) ;
_scrollDragStartOffset = sv . HorizontalOffset ;
sv . CaptureMouse ( ) ;
}
2025-11-27 13:31:09 +00:00
}
2025-12-04 13:51:11 +00:00
private void svAlertas_PreviewMouseMove ( object sender , System . Windows . Input . MouseEventArgs e )
2025-11-27 13:31:09 +00:00
{
2025-12-04 13:51:11 +00:00
if ( _isDraggingScroll & & sender is ScrollViewer sv & & e . LeftButton = = MouseButtonState . Pressed )
2025-11-27 13:31:09 +00:00
{
2025-12-04 13:51:11 +00:00
var currentPoint = e . GetPosition ( sv ) ;
var deltaX = currentPoint . X - _scrollDragStartPoint . X ;
// Inverte o sinal pra "puxar" pro lado que arrasta
sv . ScrollToHorizontalOffset ( _scrollDragStartOffset - deltaX ) ;
2025-11-27 13:31:09 +00:00
}
2025-12-04 13:51:11 +00:00
}
2025-11-27 13:31:09 +00:00
2025-12-04 13:51:11 +00:00
private void svAlertas_PreviewMouseLeftButtonUp ( object sender , MouseButtonEventArgs e )
{
if ( sender is ScrollViewer sv )
2025-11-27 13:31:09 +00:00
{
2025-12-04 13:51:11 +00:00
_isDraggingScroll = false ;
sv . ReleaseMouseCapture ( ) ;
2025-11-27 13:31:09 +00:00
}
2025-12-04 13:51:11 +00:00
}
2025-11-27 13:31:09 +00:00
2025-12-04 13:51:11 +00:00
public void AdicionarAlerta ( string Rover_ID , AgroBase . Models . Enums . T_Code Modulo , SeveridadeAlerta Severidade , string Mensagem , string? Mod_ID = null )
{
Application . Current . Dispatcher . BeginInvoke ( new Action ( ( ) = >
{
try
{
var existente = AlertasAtivos . FirstOrDefault ( x = > x . Rover_ID = = Rover_ID & & x . Modulo = = Modulo & & x . Mod_ID = = Mod_ID ) ;
if ( existente = = null )
{
var alerta = new AlertaModel
{
Rover_ID = Rover_ID ,
Severidade = Severidade ,
Modulo = Modulo ,
Mod_ID = Mod_ID ,
Mensagem = Mensagem ,
Timestamp = DateTime . Now ,
} ;
AlertasAtivos . Add ( alerta ) ;
// 🔔 dispara o toast para NOVO alerta
MostrarToast ( alerta ) ;
}
else
{
existente . Mensagem = Mensagem ;
existente . Severidade = Severidade ;
}
}
catch ( Exception exUi )
{
Variaveis . MostrarLog ( $"Erro ao adicionar alerta: {exUi.Message}" ) ;
}
} ) ) ;
}
2025-11-27 13:31:09 +00:00
2025-12-04 13:51:11 +00:00
public void RemoverAlerta ( string Rover_ID , AgroBase . Models . Enums . T_Code Modulo , SeveridadeAlerta ? Severidade = null , string? Mod_ID = null )
{
Application . Current . Dispatcher . BeginInvoke ( new Action ( ( ) = >
{
try
{
var alerta = AlertasAtivos . FirstOrDefault ( x = > x . Rover_ID = = Rover_ID & & x . Modulo = = Modulo & & x . Mod_ID = = Mod_ID & & ( Severidade ! = null ? x . Severidade = = Severidade : true ) ) ;
if ( alerta ! = null )
{
AlertasAtivos . Remove ( alerta ) ;
}
}
catch ( Exception exUi )
{
Variaveis . MostrarLog ( $"Erro ao remover alerta: {exUi.Message}" ) ;
}
} ) ) ;
2025-11-27 13:31:09 +00:00
}
2025-12-04 13:51:11 +00:00
private void Alerta_MouseLeftButtonUp ( object sender , MouseButtonEventArgs e )
2025-11-27 13:31:09 +00:00
{
2025-12-04 13:51:11 +00:00
if ( sender is Border border & & border . DataContext is AlertaModel alerta )
2025-11-27 13:31:09 +00:00
{
2025-12-04 13:51:11 +00:00
var nome = $"lblDiagnosticos_{alerta.Modulo.ToString().ToUpper()}" + ( ( ! string . IsNullOrEmpty ( alerta . Mod_ID ) & & alerta . Mod_ID ! = AgroBase . Models . Enums . S_Code . sMOD . ToString ( ) ) ? $"_{alerta.Mod_ID}" : "" ) ;
var nome_mod = $"lblDiagnosticos_{alerta.Modulo.ToString().ToUpper()}" ;
var label = this . FindName ( nome ) as Label ;
if ( label = = null ) label = this . FindName ( nome_mod ) as Label ;
if ( label ! = null )
{
if ( alerta . Rover_ID ! = VariaveisControleOperacao . SelectedRoverId )
{
int idx = cmbDispositivo . Items . IndexOf ( alerta . Rover_ID ) ;
cmbDispositivo . SelectedIndex = idx ;
}
DiagnosticoModulo_Click ( label , e ) ;
}
2025-11-27 13:31:09 +00:00
}
}
2025-12-04 13:51:11 +00:00
private void MostrarToast ( AlertaModel alerta )
2025-11-27 13:31:09 +00:00
{
2025-12-04 13:51:11 +00:00
ToastAlerta = alerta ;
_toastTimer . Stop ( ) ;
_toastTimer . Start ( ) ;
2025-11-27 13:31:09 +00:00
}
2025-12-04 13:51:11 +00:00
private void ToastAlerta_MouseLeftButtonUp ( object sender , MouseButtonEventArgs e )
2025-11-27 13:31:09 +00:00
{
2025-12-04 13:51:11 +00:00
var alerta = ToastAlerta ;
if ( alerta = = null )
return ;
_toastTimer . Stop ( ) ;
ToastAlerta = null ;
2025-11-27 13:31:09 +00:00
2025-12-04 13:51:11 +00:00
var nome = $"lblDiagnosticos_{alerta.Modulo.ToString().ToUpper()}" + ( ( ! string . IsNullOrEmpty ( alerta . Mod_ID ) & & alerta . Mod_ID ! = AgroBase . Models . Enums . S_Code . sMOD . ToString ( ) ) ? $"_{alerta.Mod_ID}" : "" ) ;
var nome_mod = $"lblDiagnosticos_{alerta.Modulo.ToString().ToUpper()}" ;
var label = this . FindName ( nome ) as Label ;
if ( label = = null ) label = this . FindName ( nome_mod ) as Label ;
if ( label ! = null )
2025-11-27 13:31:09 +00:00
{
2025-12-04 13:51:11 +00:00
if ( alerta . Rover_ID ! = VariaveisControleOperacao . SelectedRoverId )
{
int idx = cmbDispositivo . Items . IndexOf ( alerta . Rover_ID ) ;
cmbDispositivo . SelectedIndex = idx ;
}
DiagnosticoModulo_Click ( label , e ) ;
2025-11-27 13:31:09 +00:00
}
}
2025-12-04 13:51:11 +00:00
#endregion
2025-11-27 13:31:09 +00:00
}
2025-12-04 13:51:11 +00:00
2025-11-27 13:31:09 +00:00
2025-11-12 11:15:07 +00:00
}