196 lines
7.3 KiB
C#
196 lines
7.3 KiB
C#
using AgroBase.Comum;
|
|
using AgroBase.Models.Modules;
|
|
using AgroBase.Services;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using static AgroBase.Models.Enuns;
|
|
|
|
namespace AgroBase.Models
|
|
{
|
|
public class Variaveis
|
|
{
|
|
public static string CaminhoSistema { get; set; } = AppDomain.CurrentDomain.BaseDirectory;
|
|
public static string CaminhoLogsDispositivos { get; } = "Logs/";
|
|
public static string CaminhoOperacoes { get; } = "Operacoes/";
|
|
public static string CaminhoMapasConvertidos { get; } = "Mapas/";
|
|
public static string CaminhoParametros { get; } = "Parametros/";
|
|
public static List<IDispositivosService> DispositivosConectados { get; set; } = new List<IDispositivosService>();
|
|
public static OperacaoModel OperacaoEmAndamento { get; set; } = new OperacaoModel(ModoOperacao.Manual);
|
|
public static MqttService MqttService { get; set; } = new MqttService("localhost", 1883);
|
|
public static List<T_Code> DispositivosConexaoInicial = new List<T_Code>() { T_Code.Dir, T_Code.Mov, T_Code.Atu, T_Code.Sen };
|
|
public static SensorSinaleiroComportamentoModel ComportamentoPorStatus(StatusOperacao? _status = null)
|
|
{
|
|
if (_status == null)
|
|
{
|
|
_status = OperacaoEmAndamento.StatusAtual;
|
|
}
|
|
|
|
SensorSinaleiroComportamentoModel comportamento = new SensorSinaleiroComportamentoModel()
|
|
{
|
|
statusLED = StatusLED.Apagado,
|
|
QtdPiscadas = 0,
|
|
TempoMs = 0,
|
|
PausaMs = 0,
|
|
};
|
|
|
|
switch (_status)
|
|
{
|
|
case StatusOperacao.Parametrizando:
|
|
{
|
|
comportamento = new SensorSinaleiroComportamentoModel()
|
|
{
|
|
statusLED = StatusLED.Aceso,
|
|
QtdPiscadas = 0,
|
|
TempoMs = 0,
|
|
PausaMs = 0,
|
|
};
|
|
break;
|
|
}
|
|
case StatusOperacao.NaoIniciado:
|
|
case StatusOperacao.Concluido:
|
|
{
|
|
comportamento = new SensorSinaleiroComportamentoModel()
|
|
{
|
|
statusLED = StatusLED.Apagado,
|
|
QtdPiscadas = 0,
|
|
TempoMs = 0,
|
|
PausaMs = 0,
|
|
};
|
|
break;
|
|
}
|
|
case StatusOperacao.Aguardando:
|
|
{
|
|
comportamento = new SensorSinaleiroComportamentoModel()
|
|
{
|
|
statusLED = StatusLED.Piscando,
|
|
QtdPiscadas = 1,
|
|
TempoMs = 1000,
|
|
PausaMs = 0,
|
|
};
|
|
break;
|
|
}
|
|
case StatusOperacao.Parado:
|
|
{
|
|
comportamento = new SensorSinaleiroComportamentoModel()
|
|
{
|
|
statusLED = StatusLED.Piscando,
|
|
QtdPiscadas = 1,
|
|
TempoMs = 2000,
|
|
PausaMs = 0,
|
|
};
|
|
break;
|
|
}
|
|
case StatusOperacao.EmAndamento:
|
|
{
|
|
comportamento = new SensorSinaleiroComportamentoModel()
|
|
{
|
|
statusLED = StatusLED.Piscando,
|
|
QtdPiscadas = 3,
|
|
TempoMs = 200,
|
|
PausaMs = 1000,
|
|
};
|
|
break;
|
|
}
|
|
}
|
|
|
|
return comportamento;
|
|
}
|
|
|
|
}
|
|
|
|
public static class FuncoesGlobais
|
|
{
|
|
public static string TimestampToDate(double timestamp, string Formatacao = "HH:mm:ss.fff")
|
|
{
|
|
// Converta o timestamp Unix para DateTime
|
|
// A época Unix começa em 1 de janeiro de 1970
|
|
DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
|
DateTime date = epoch.AddSeconds(timestamp);
|
|
|
|
// Converter a data UTC para a data no fuso horário local do sistema
|
|
DateTime localDate = date.ToLocalTime();
|
|
|
|
// Formate a data para hh:mm:ss.fff (note a correção de MM para mm)
|
|
string formattedDate = localDate.ToString(Formatacao, System.Globalization.CultureInfo.InvariantCulture);
|
|
|
|
return formattedDate;
|
|
}
|
|
|
|
public static double Map(double valor, double deMin, double deMax, double paraMin, double paraMax)
|
|
{
|
|
return paraMin + (valor - deMin) * (paraMax - paraMin) / (deMax - deMin);
|
|
}
|
|
|
|
public static T FindControlRecursive<T>(Control parent, string controlName) where T : Control
|
|
{
|
|
foreach (Control child in parent.Controls)
|
|
{
|
|
if (child is T foundControl && child.Name == controlName)
|
|
{
|
|
return foundControl; // Retorna o controle se encontrado
|
|
}
|
|
else
|
|
{
|
|
T foundInChildren = FindControlRecursive<T>(child, controlName);
|
|
if (foundInChildren != null) return foundInChildren; // Retorna o controle se encontrado em controles filhos
|
|
}
|
|
}
|
|
return null; // Retorna null se o controle não for encontrado
|
|
}
|
|
|
|
public static double ConvertDegreesToRadians(double degrees)
|
|
{
|
|
double radians = (Math.PI / 180) * degrees;
|
|
return (radians);
|
|
}
|
|
|
|
public static void PreencheValorProgressBar(ProgressBar pgb, double Valor)
|
|
{
|
|
pgb.Value =
|
|
Valor >= pgb.Minimum && Valor <= pgb.Maximum ? pgb.Value = Convert.ToInt32(Valor) :
|
|
Valor < pgb.Minimum ? pgb.Value = pgb.Minimum :
|
|
Valor > pgb.Maximum ? pgb.Value = pgb.Maximum :
|
|
pgb.Minimum;
|
|
}
|
|
|
|
public static double CalcularAlturaTriangulo(double a, double b, double c)
|
|
{
|
|
// Verifica se os lados formam um triângulo válido
|
|
if (a + b <= c || a + c <= b || b + c <= a)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
// Calcule a área do triângulo usando a fórmula de Herão
|
|
double s = (a + b + c) / 2.0; // Semiperímetro
|
|
double area = Math.Sqrt(s * (s - a) * (s - b) * (s - c));
|
|
|
|
// Calcule a altura em relação à base c
|
|
double altura = (2 * area) / c;
|
|
|
|
return altura;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public static class VariaveisPortas
|
|
{
|
|
public static int GPS { get; } = 6512;
|
|
public static int CameraSolo { get; } = 6522;
|
|
public static int CameraCaminho { get; } = 6544;
|
|
public static int SocketSolo { get; } = 6568;
|
|
public static int SocketCaminho { get; } = 6588;
|
|
}
|
|
|
|
public static class VariaveisEquipamento
|
|
{
|
|
public static double Largura { get; } = 80;
|
|
}
|
|
|
|
}
|