agrobot_base/AgroBase/AgroBase/Models/Modules/SensoriamentoModel.cs

1664 lines
59 KiB
C#
Raw Normal View History

2024-12-03 20:55:25 +00:00
using AgroBase.Forms.IHM;
using AgroBase.Services;
using Newtonsoft.Json;
2023-11-30 00:41:22 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
2024-07-26 19:54:25 +00:00
using static AgroBase.Models.Enums;
2023-11-30 00:41:22 +00:00
namespace AgroBase.Models.Modules
{
public class SensoriamentoModel : DispositivoBaseModel
2023-11-30 00:41:22 +00:00
{
public string Modulo_ID { get; set; } = T_Code.Sen.ToString();
2024-12-02 19:12:39 +00:00
public string IP { get; set; } = Variaveis.FaixaIPwifi + ".12";
public bool RequisitarDados { get; set; } = false;
private bool _MensagemConexaoRecebida { get; set; } = false;
public bool MensagemConexaoRecebida(bool Reset = false)
{
if (Reset)
{
_MensagemConexaoRecebida = false;
}
return _MensagemConexaoRecebida;
}
public static int _TaxaAmostragem { get; set; } = 1000;
2023-11-30 00:41:22 +00:00
public bool Conectado { get; set; } = false;
public static int LogsManter { get; set; } = 60;
2024-04-15 10:57:37 +00:00
public static PinoutDataModel Pinout { get; set; }
public static bool ExpansorGPIO { get; set; } = false;
2024-04-01 11:03:25 +00:00
public static List<FuncoesPinout> Funcoes { get; set; } = new List<FuncoesPinout>()
{
FuncoesPinout.SDA,
FuncoesPinout.SCL,
};
2023-11-30 00:41:22 +00:00
public List<SensorModel> Sensores { get; set; }
2024-07-12 19:44:56 +00:00
public List<SensorSinaleiroModel> Sinaleiros { get; set; }
2024-07-18 18:00:14 +00:00
public List<SensorReleModel> Reles { get; set; }
2024-07-24 20:04:55 +00:00
public List<SensorServoModel> Servos { get; set; }
2024-07-12 19:44:56 +00:00
public string CameraID_Caminho { get; set; } = "";
public List<string> CameraID_Solo { get; set; } = new List<string>();
2024-10-29 19:53:27 +00:00
public UltrasonicA05Configuracoes ConfiguracaoSensorUltrassom { get; set; }
2024-05-24 20:05:51 +00:00
public double BateriaCargaConsumida { get; set; }
public SensoriamentoMensagemJsonModel DadosLeitura { get; set; } = new SensoriamentoMensagemJsonModel();
public LoRaParametrosModel LoRaParametrosBase { get; set; } = new LoRaParametrosModel()
{
address = 0x01,
channel = 0x17,
tranMode = LoRaService.CodigosTipoTransmissao["Fixed"],
baudRate = LoRaService.CodigosBaudRates[9600],
airRate = LoRaService.CodigosAirRates[2.4],
packetSize = LoRaService.CodigosPacketSizes[200],
worCycle = LoRaService.CodigosWorCycles[4000],
power = LoRaService.CodigosPowers[22],
};
2023-11-30 00:41:22 +00:00
public AsyncTaskTimerModel tmrRegistrador;
2024-12-05 12:52:28 +00:00
private int _TempoReconexaoComponentes = 5;
private int _VezesLeituraReconexao = 0;
2023-11-30 00:41:22 +00:00
public static SensoriamentoModel CarregarParametrosIniciais()
{
return new SensoriamentoModel()
{
2024-07-18 18:00:14 +00:00
CameraID_Caminho = "",
CameraID_Solo = new List<string>()
{
"",
""
},
Sinaleiros = new List<SensorSinaleiroModel>()
{
new SensorSinaleiroModel()
{
ID = "LEDMN",
Descricao = "Sinaleiro indicação de modo Manual ativo",
Componente = S_Code.sLED,
Funcoes = new List<FuncoesPinout>()
{
FuncoesPinout.Sinaleiro,
2024-04-26 19:34:58 +00:00
},
2024-07-26 19:54:25 +00:00
Comportamento = VariaveisEquipamento.ComportamentoPorStatus(StatusOperacao.NaoIniciado)
},
new SensorSinaleiroModel()
{
ID = "LEDAT",
Descricao = "Sinaleiro indicação de modo Automático ativo",
Componente = S_Code.sLED,
Funcoes = new List<FuncoesPinout>()
{
FuncoesPinout.Sinaleiro,
2024-04-26 19:34:58 +00:00
},
2024-07-26 19:54:25 +00:00
Comportamento = VariaveisEquipamento.ComportamentoPorStatus(StatusOperacao.NaoIniciado)
},
new SensorSinaleiroModel()
{
ID = "LEDOP",
Descricao = "Sinaleiro indicação do status da operação ativa",
Componente = S_Code.sLED,
Funcoes = new List<FuncoesPinout>()
{
FuncoesPinout.Sinaleiro,
2024-04-26 19:34:58 +00:00
},
2024-07-26 19:54:25 +00:00
Comportamento = VariaveisEquipamento.ComportamentoPorStatus(StatusOperacao.NaoIniciado)
},
},
2023-11-30 00:41:22 +00:00
Sensores = new List<SensorModel>()
{
new SensorModel()
{
2024-01-18 19:22:28 +00:00
ID = "TMVET",
Descricao = "Temperatura Motor Esquerdo Trás",
Prioridade = 0,
Componente = S_Code.sTMP,
Aferir = true,
Testando = false,
Funcoes = new List<FuncoesPinout>()
{
FuncoesPinout.TMP,
},
DelayAmostragem = 200,
2024-01-31 17:23:52 +00:00
UnidadeMedida = "ºC",
Parametros = new List<string[]>()
{
new string[] { "V offset", "-1.038" },
},
2024-01-18 19:22:28 +00:00
},
new SensorModel()
{
ID = "TMVEF",
Descricao = "Temperatura Motor Esquerdo Frente",
Prioridade = 0,
Componente = S_Code.sTMP,
Aferir = true,
Testando = false,
Funcoes = new List<FuncoesPinout>()
{
FuncoesPinout.TMP,
},
DelayAmostragem = 200,
2024-01-31 17:23:52 +00:00
UnidadeMedida = "ºC",
Parametros = new List<string[]>()
{
new string[] { "V offset", "-1.038" },
},
2024-01-18 19:22:28 +00:00
},
new SensorModel()
{
ID = "TMVDT",
Descricao = "Temperatura Motor Direito Trás",
Prioridade = 0,
Componente = S_Code.sTMP,
Aferir = true,
Testando = false,
Funcoes = new List<FuncoesPinout>()
{
FuncoesPinout.TMP,
},
DelayAmostragem = 200,
2024-01-31 17:23:52 +00:00
UnidadeMedida = "ºC",
Parametros = new List<string[]>()
{
new string[] { "V offset", "-1.038" },
},
2024-01-18 19:22:28 +00:00
},
new SensorModel()
{
ID = "TMVDF",
Descricao = "Temperatura Motor Direito Frente",
Prioridade = 0,
Componente = S_Code.sTMP,
Aferir = true,
Testando = false,
Funcoes = new List<FuncoesPinout>()
{
FuncoesPinout.TMP,
},
DelayAmostragem = 200,
2024-01-31 17:23:52 +00:00
UnidadeMedida = "ºC",
Parametros = new List<string[]>()
{
new string[] { "V offset", "-1.038" },
},
2024-01-18 19:22:28 +00:00
},
2024-07-24 20:04:55 +00:00
/*new SensorModel()
2024-01-18 19:22:28 +00:00
{
2024-04-15 10:57:37 +00:00
ID = "AB3V",
2023-11-30 00:41:22 +00:00
Prioridade = 10,
2024-04-15 10:57:37 +00:00
Descricao = "Corrente no Barramento 3V",
2023-11-30 00:41:22 +00:00
Componente = S_Code.sCOR,
Aferir = true,
Inicializado = false,
Testando = false,
Funcoes = new List<FuncoesPinout>()
{
FuncoesPinout.I2C,
2024-01-23 17:10:34 +00:00
},
DelayAmostragem = 500,
2024-01-31 17:23:52 +00:00
UnidadeMedida = "A",
2024-01-23 17:10:34 +00:00
Parametros = new List<string[]>()
{
2024-04-15 10:57:37 +00:00
new string[] { "Endereço I2C", "0x44" },
new string[] { "CI", "219" }
},
2024-07-24 20:04:55 +00:00
},*/
new SensorModel()
{
2024-04-15 10:57:37 +00:00
ID = "AB5V",
Prioridade = 10,
2024-04-15 10:57:37 +00:00
Descricao = "Corrente no Barramento 5V",
Componente = S_Code.sCOR,
Aferir = true,
Testando = false,
Funcoes = new List<FuncoesPinout>()
{
FuncoesPinout.I2C,
},
DelayAmostragem = 500,
UnidadeMedida = "A",
Parametros = new List<string[]>()
{
new string[] { "Endereço I2C", "0x41" },
2024-07-24 20:04:55 +00:00
new string[] { "Corrente Max", "3.2" }
},
},
2024-07-24 20:04:55 +00:00
/*new SensorModel()
{
2024-04-15 10:57:37 +00:00
ID = "AB7V2",
Prioridade = 10,
2024-04-15 10:57:37 +00:00
Descricao = "Corrente no Barramento 7,2V",
Componente = S_Code.sCOR,
Aferir = true,
Inicializado = false,
Testando = false,
Funcoes = new List<FuncoesPinout>()
{
FuncoesPinout.I2C,
},
DelayAmostragem = 500,
UnidadeMedida = "A",
Parametros = new List<string[]>()
{
2024-04-15 10:57:37 +00:00
new string[] { "Endereço I2C", "0x40" },
new string[] { "CI", "219" }
},
2024-07-24 20:04:55 +00:00
},*/
new SensorModel()
{
2024-04-15 10:57:37 +00:00
ID = "AB12V",
Prioridade = 10,
2024-04-15 10:57:37 +00:00
Descricao = "Corrente no Barramento 12V",
Componente = S_Code.sCOR,
Aferir = true,
Testando = false,
Funcoes = new List<FuncoesPinout>()
{
FuncoesPinout.I2C,
},
DelayAmostragem = 500,
UnidadeMedida = "A",
Parametros = new List<string[]>()
{
2024-07-24 20:04:55 +00:00
new string[] { "Endereço I2C", "0x40" },
new string[] { "Corrente Max", "100" }
2023-11-30 00:41:22 +00:00
},
},
2024-01-24 12:53:39 +00:00
new SensorModel()
{
ID = "TBAT",
Descricao = "Temperatura da bateria",
Prioridade = 5,
Componente = S_Code.sTMP,
Aferir = true,
Testando = false,
Funcoes = new List<FuncoesPinout>()
{
FuncoesPinout.TMP,
},
DelayAmostragem = 500,
2024-01-31 17:23:52 +00:00
UnidadeMedida = "ºC",
Parametros = new List<string[]>()
{
new string[] { "V offset", "0.0000" },
},
2024-01-24 12:53:39 +00:00
},
2024-07-24 20:04:55 +00:00
/*new SensorModel()
{
ID = "SUESQ",
Descricao = "Sensor Ultrassom Esquerdo",
Prioridade = 2,
Componente = S_Code.sULT,
Aferir = true,
Inicializado = false,
Testando = false,
Funcoes = new List<FuncoesPinout>()
{
FuncoesPinout.Echo,
FuncoesPinout.Trigger,
},
DelayAmostragem = 1000,
UnidadeMedida = "cm",
Parametros = new List<string[]>(),
},
new SensorModel()
{
ID = "SUDIR",
Descricao = "Sensor Ultrassom Direito",
Prioridade = 2,
Componente = S_Code.sULT,
Aferir = true,
Inicializado = false,
Testando = false,
Funcoes = new List<FuncoesPinout>()
{
FuncoesPinout.Echo,
FuncoesPinout.Trigger,
},
DelayAmostragem = 1000,
UnidadeMedida = "cm",
Parametros = new List<string[]>(),
},
2024-03-13 18:33:13 +00:00
new SensorModel()
{
2024-04-26 19:34:58 +00:00
ID = "SMAG",
2024-03-13 18:33:13 +00:00
Descricao = "Sensor Magnetômetro",
Prioridade = 15,
Componente = S_Code.sMAG,
Aferir = true,
Inicializado = false,
Testando = false,
Funcoes = new List<FuncoesPinout>()
{
FuncoesPinout.I2C,
},
DelayAmostragem = 500,
UnidadeMedida = "º",
Parametros = new List<string[]>(),
},
2024-04-15 10:57:37 +00:00
new SensorModel()
{
ID = "SNR_F",
Descricao = "Sensor Sonar Frontal",
Prioridade = 20,
Componente = S_Code.sSNR,
Aferir = true,
Inicializado = false,
Testando = false,
Funcoes = new List<FuncoesPinout>()
{
FuncoesPinout.Echo,
FuncoesPinout.Trigger,
FuncoesPinout.ServoX,
FuncoesPinout.ServoY,
},
DelayAmostragem = 1000,
UnidadeMedida = "cm/º",
Parametros = new List<string[]>()
{
new string[] { "Angulo X Acrescentar", "5" },
new string[] { "Angulo Y Acrescentar", "30" },
},
2024-04-23 11:23:05 +00:00
LimiteMinimo = 40,
LimiteMaximo = 9999,
2024-07-24 20:04:55 +00:00
},*/
2024-04-15 10:57:37 +00:00
2024-04-01 11:03:25 +00:00
},
2024-07-18 18:00:14 +00:00
Reles = new List<SensorReleModel>()
{
new SensorReleModel()
{
ID = "RLLRA",
Descricao = "Relé modo operação LoRa",
Componente = S_Code.sRLE,
2024-07-24 20:04:55 +00:00
Controlar = true,
2024-07-18 18:00:14 +00:00
Funcoes = new List<FuncoesPinout>()
{
FuncoesPinout.Rele,
},
StatusControle = Estado.Desligado,
},
2024-07-24 20:04:55 +00:00
},
Servos = new List<SensorServoModel>()
{
new SensorServoModel()
{
ID = "FRO_ET",
Descricao = "Freio Motor ET",
Componente = S_Code.sFRO,
Controlar = true,
Funcoes = new List<FuncoesPinout>()
{
FuncoesPinout.ServoFreio,
},
_AnguloControle = 0,
},
new SensorServoModel()
{
ID = "FRO_EF",
Descricao = "Freio Motor EF",
Componente = S_Code.sFRO,
Controlar = false,
Funcoes = new List<FuncoesPinout>()
{
FuncoesPinout.ServoFreio,
},
_AnguloControle = 0,
},
new SensorServoModel()
{
ID = "FRO_DT",
Descricao = "Freio Motor DT",
Componente = S_Code.sFRO,
Controlar = true,
Funcoes = new List<FuncoesPinout>()
{
FuncoesPinout.ServoFreio,
},
_AnguloControle = 0,
},
new SensorServoModel()
{
ID = "FRO_DF",
Descricao = "Freio Motor DF",
Componente = S_Code.sFRO,
Controlar = false,
Funcoes = new List<FuncoesPinout>()
{
FuncoesPinout.ServoFreio,
},
_AnguloControle = 0,
},
2024-07-18 18:00:14 +00:00
}
2023-11-30 00:41:22 +00:00
};
}
2024-12-02 19:12:39 +00:00
public void LimparDados<T>(T _dados)
2024-07-18 18:00:14 +00:00
{
2024-12-02 19:12:39 +00:00
var Dados = _dados as SensoriamentoModel;
2024-07-18 18:00:14 +00:00
Dados.Conectado = false;
Dados.DadosLeitura = new SensoriamentoMensagemJsonModel();
Dados.DadosLeitura.Momento = DateTime.MinValue;
2024-07-24 20:04:55 +00:00
Dados.Reles.ForEach(x =>
{
x.StatusControle = Estado.Desligado;
2024-10-29 19:53:27 +00:00
});
Dados.Servos.ForEach(x =>
{
x._AnguloControle = 0;
2024-10-29 19:53:27 +00:00
});
ReiniciarLeituras(Dados);
}
2024-12-02 19:12:39 +00:00
public void ReiniciarLeituras(SensoriamentoModel Dados)
2024-10-29 19:53:27 +00:00
{
Dados.Reles.ForEach(x =>
{
x.Leitura = null;
2024-07-24 20:04:55 +00:00
});
Dados.Sinaleiros.ForEach(x =>
{
x.Leitura = null;
2024-07-24 20:04:55 +00:00
});
2024-07-18 18:00:14 +00:00
Dados.Sensores.ForEach(x =>
{
x.Leitura = null;
2024-07-18 18:00:14 +00:00
});
2024-07-24 20:04:55 +00:00
Dados.Servos.ForEach(x =>
{
x.Leitura = null;
2024-07-24 20:04:55 +00:00
});
2024-07-18 18:00:14 +00:00
}
public Dictionary<string, List<string>> ProtocoloConfiguracao(bool Conectar)
2023-11-30 00:41:22 +00:00
{
// Inicializar o dicionário
var configDictionary = new Dictionary<string, List<string>>() { { Modulo_ID, new List<string>() } };
// Adicionar configurações dos Sensores que devem ser aferidos
var sensoresConfig = SensoresConfig(Conectar);
configDictionary[Modulo_ID].AddRange(sensoresConfig);
// Adicionar configurações dos Sinaleiros
var sinaleirosConfig = SinaleirosConfig(Conectar);
configDictionary[Modulo_ID].AddRange(sinaleirosConfig);
2024-07-18 18:00:14 +00:00
// Adicionar configurações dos Reles
var relesConfig = RelesConfig(Conectar);
2024-07-18 18:00:14 +00:00
configDictionary[Modulo_ID].AddRange(relesConfig);
2024-07-24 20:04:55 +00:00
// Adicionar configurações dos Servos
var servosConfig = ServosConfig(Conectar);
2024-07-24 20:04:55 +00:00
configDictionary[Modulo_ID].AddRange(servosConfig);
2024-12-05 12:52:28 +00:00
if (!Conectado || configDictionary.Any(x => x.Value.Count() > 0))
2024-12-02 19:12:39 +00:00
{
// Adicionar configuração do ProtocoloMOD
var protocoloMOD = ModConfig(Conectar);
configDictionary[Modulo_ID].Add(protocoloMOD);
}
return configDictionary;
}
private string ModConfig(bool Conectar)
{
string protocoloMOD =
2024-04-26 19:34:58 +00:00
((int)F_Code.Cfg).ToString() + SerialService.SplitMessage +
((int)T_Code.Mod).ToString() + SerialService.SplitParams +
2024-04-26 19:34:58 +00:00
(Conectar ? "1" : "0") + SerialService.SplitParams +
_TaxaAmostragem.ToString() + SerialService.SplitParams +
(RequisitarDados ? "1" : "0") + SerialService.SplitParams +
PinoutModel.PinoProtocolo(Pinout, Funcoes, SerialService.SplitParams);
return protocoloMOD;
}
private string[] SensoresConfig(bool Conectar)
{
var sensoresConfig = Sensores
.Where(x => x.Aferir && x.Inicializado != Conectar)
.GroupBy(x => x.Componente)
.Select(x =>
((int)F_Code.Cfg).ToString() + SerialService.SplitMessage +
((int)T_Code.Sen).ToString() + SerialService.SplitParams +
((int)x.Key).ToString() + SerialService.SplitParams +
string.Join(SerialService.SplitConfig, x.Select(y => y.ProtocoloConfiguracao(Pinout, Conectar)))
).ToArray();
return sensoresConfig;
}
private string[] SinaleirosConfig(bool Conectar)
{
var sinaleirosConfig = Sinaleiros
.Where(x => x.Inicializado != Conectar)
.GroupBy(x => x.Componente)
.Select(x =>
((int)F_Code.Cfg).ToString() + SerialService.SplitMessage +
((int)T_Code.Sen).ToString() + SerialService.SplitParams +
((int)x.Key).ToString() + SerialService.SplitParams +
string.Join(SerialService.SplitConfig, x.Select(y => y.ProtocoloConfiguracao(Pinout, Conectar)))
).ToArray();
return sinaleirosConfig;
}
private string[] RelesConfig(bool Conectar)
{
var relesConfig = Reles
.Where(x => x.Controlar && x.Inicializado != Conectar)
.GroupBy(x => x.Componente)
.Select(x =>
((int)F_Code.Cfg).ToString() + SerialService.SplitMessage +
((int)T_Code.Sen).ToString() + SerialService.SplitParams +
((int)x.Key).ToString() + SerialService.SplitParams +
string.Join(SerialService.SplitConfig, x.Select(y => y.ProtocoloConfiguracao(Pinout, Conectar)))
).ToArray();
return relesConfig;
}
private string[] ServosConfig(bool Conectar)
{
var servosConfig = Servos
.Where(x => x.Controlar && x.Inicializado != Conectar)
.GroupBy(x => x.Componente)
.Select(x =>
((int)F_Code.Cfg).ToString() + SerialService.SplitMessage +
((int)T_Code.Sen).ToString() + SerialService.SplitParams +
((int)x.Key).ToString() + SerialService.SplitParams +
string.Join(SerialService.SplitConfig, x.Select(y => y.ProtocoloConfiguracao(Pinout, Conectar)))
).ToArray();
return servosConfig;
2023-11-30 00:41:22 +00:00
}
public string ProtocoloVerificacao(bool Completo)
{
if (Completo)
{
string ProtocoloCheck =
//SerialService.BeginLine +
"0" + SerialService.SplitMessage +
Modulo_ID + SerialService.SplitMessage +
((int)F_Code.Chk).ToString() + SerialService.SplitMessage +
"check" +
SerialService.EndLine;
return ProtocoloCheck;
}
else
{
string ProtocoloCheck = ((int)F_Code.Chk).ToString() + SerialService.SplitMessage + "check";
return ProtocoloCheck;
}
}
private string ProtocoloAquisicaoDados()
2024-07-18 18:00:14 +00:00
{
string ProtocoloReq = ((int)F_Code.Req).ToString() + SerialService.SplitMessage + "req";
return ProtocoloReq;
2024-07-18 18:00:14 +00:00
}
public void RecebeProtocoloModulo(string Protocolo)
2023-11-30 00:41:22 +00:00
{
try
2023-11-30 00:41:22 +00:00
{
if (string.IsNullOrWhiteSpace(Protocolo))
2024-01-18 19:22:28 +00:00
{
Console.WriteLine("Protocolo recebido está vazio ou nulo.");
2024-01-18 19:22:28 +00:00
return;
}
Protocolo = Protocolo.Substring(0, Protocolo.Length - 1);
2024-07-24 20:04:55 +00:00
// Valida se o protocolo possui um formato esperado
if (Protocolo.Length <= 1 || !Protocolo.EndsWith("}"))
2023-11-30 00:41:22 +00:00
{
Console.WriteLine("Protocolo recebido está em um formato inválido.");
2023-11-30 00:41:22 +00:00
return;
}
//Console.WriteLine($"JSON recebido: {Protocolo}");
// Tenta desserializar o JSON
var dadosLeitura = JsonConvert.DeserializeObject<SensoriamentoMensagemJsonModel>(Protocolo);
if (dadosLeitura == null)
{
Console.WriteLine("Falha ao desserializar o JSON.");
return;
}
dadosLeitura.Momento = DateTime.Now;
AtualizaDadosComponentes(dadosLeitura);
}
catch (JsonException ex)
{
Console.WriteLine($"Erro ao processar o JSON recebido: {ex.Message}");
}
catch (Exception ex)
{
Console.WriteLine($"Erro inesperado no processamento do protocolo: {ex.Message}");
}
}
2023-11-30 00:41:22 +00:00
private void AtualizaDadosComponentes(SensoriamentoMensagemJsonModel dadosLeitura)
{
DadosLeitura = dadosLeitura;
2023-11-30 00:41:22 +00:00
DefineStatusConexao(Modulo_ID, true);
2023-11-30 00:41:22 +00:00
if (Variaveis.OperacaoEmAndamento.DispMvd != null)
{
Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.ForEach(Modulo => Modulo.AtualizarSensoresMotor());
2023-11-30 00:41:22 +00:00
}
}
public void DefineStatusConexao(string Mod_ID, bool conecatdo)
{
if (Mod_ID == Modulo_ID)
{
Conectado = conecatdo;
}
}
2023-11-30 00:41:22 +00:00
public string GetTaxaAmostragem()
{
return _TaxaAmostragem.ToString("00000");
}
public void SetTaxaAmostragem(int TaxaAmostragem)
{
_TaxaAmostragem = TaxaAmostragem;
}
public bool GetStatusConexao()
{
Conectado = DadosLeitura.Conectado && DadosLeitura.Momento.AddMilliseconds(10 * _TaxaAmostragem) >= DateTime.Now;
2023-11-30 00:41:22 +00:00
return Conectado;
}
public string GetIP()
{
return IP;
}
2024-01-03 10:52:37 +00:00
public void IniciarRegistrador()
{
if (!(tmrRegistrador?.IsRunning ?? false))
{
LimparDados(this);
PararRegistrador();
tmrRegistrador = new AsyncTaskTimerModel("tmrRegistrador_" + T_Code.Sen.ToString(), tmrRegistrador_Tick, _TaxaAmostragem);
tmrRegistrador.Start();
}
}
2024-01-03 10:52:37 +00:00
public void PararRegistrador()
{
tmrRegistrador?.Dispose();
2024-01-03 10:52:37 +00:00
}
public async Task tmrRegistrador_Tick()
{
tmrRegistrador.SetInterval(_TaxaAmostragem);
bool _conectado = DadosLeitura.Conectado && DadosLeitura.Momento.AddMilliseconds(10 * _TaxaAmostragem) >= DateTime.Now;
DefineStatusConexao(Modulo_ID, _conectado);
2024-12-05 12:52:28 +00:00
if (SerialService.DispositivosMapeados.Any(x => x.Dispositivo == T_Code.Sen) && (_VezesLeituraReconexao >= _TempoReconexaoComponentes))
{
Variaveis.OperacaoEmAndamento.DispSen?.EnviarProtocolosConfiguracao();
_VezesLeituraReconexao = 0;
}
else
{
_VezesLeituraReconexao++;
}
2024-12-03 20:55:25 +00:00
if (Conectado)
{
2024-12-03 20:55:25 +00:00
if (RequisitarDados)
{
RequisitarDadosModulo();
}
VerificaControleLeitura();
}
}
public void RequisitarDadosModulo()
2024-07-26 19:54:25 +00:00
{
if (Variaveis.OperacaoEmAndamento.DispSen != null)
{
string ProtocoloAquisicao = ProtocoloAquisicaoDados();
Variaveis.OperacaoEmAndamento.DispSen.AdicionarMensagemFila(Modulo_ID, ProtocoloAquisicao, true, false);
}
2024-07-26 19:54:25 +00:00
}
2024-10-03 18:21:30 +00:00
public (bool, List<string>) StatusModulosSEN()
{
var _Sensores = Sensores.Where(x => x.Aferir).ToList();
var _SensoresComFalha = _Sensores.Where(x => !x.Inicializado).ToList();
bool _sensoresOperantes = _SensoresComFalha.Count() < _Sensores.Count();
var _Sinaleiros = Sinaleiros.ToList();
var _SinaleirosComFalha = _Sinaleiros.Where(x => !x.Inicializado).ToList();
bool _sinaleirosOperantes = !_SinaleirosComFalha.Any();
var _Reles = Reles.Where(x => x.Controlar).ToList();
var _RelesComFalha = _Reles.Where(x => !x.Inicializado).ToList();
bool _relesOperantes = !_RelesComFalha.Any();
var _Servos = Servos.Where(x => x.Controlar).ToList();
var _ServosComFalha = _Servos.Where(x => !x.Inicializado).ToList();
bool _servosOperantes = !_ServosComFalha.Any();
bool _sensoriamentoOperante = _sensoresOperantes && _relesOperantes && _servosOperantes;
List<string> ModsComFalha =
_SensoresComFalha.Select(x => x.ID)
.Union(_SinaleirosComFalha.Select(x => x.ID))
.Union(_RelesComFalha.Select(x => x.ID))
.Union(_ServosComFalha.Select(x => x.ID))
.ToList();
return (_sensoriamentoOperante, ModsComFalha);
}
2024-12-03 20:55:25 +00:00
private void VerificaControleLeitura()
{
if (!frmDiagnosticos.Diagnosticando)
{
var ledOP = Sinaleiros.FirstOrDefault(x => x.ID == "LEDOP" && x.Inicializado);
var ledAT = Sinaleiros.FirstOrDefault(x => x.ID == "LEDAT" && x.Inicializado);
var ledMN = Sinaleiros.FirstOrDefault(x => x.ID == "LEDMN" && x.Inicializado);
var comportamento = VariaveisEquipamento.ComportamentoPorStatus();
if (ledOP != null && (!ledOP.Comportamento.Equals(comportamento) || (ledOP.LeituraComando != comportamento.statusLED)))
{
GeneralJoystick.EnviarComandoSensoriamento(S_Code.sLED, ledOP.ID, comportamento);
}
var statusLedAt = Variaveis.OperacaoEmAndamento.Modo == ModoOperacao.MapaGPS ? StatusLED.Aceso : StatusLED.Apagado;
if (ledAT != null && (!ledAT.Comportamento.statusLED.Equals(statusLedAt) || (ledAT.LeituraComando != statusLedAt)))
{
ledAT.Comportamento.statusLED = statusLedAt;
GeneralJoystick.EnviarComandoSensoriamento(S_Code.sLED, ledAT.ID, ledAT.Comportamento);
}
var statusLedMn = Variaveis.OperacaoEmAndamento.Modo == ModoOperacao.Manual ? StatusLED.Aceso : StatusLED.Apagado;
if (ledMN != null && (!ledMN.Comportamento.statusLED.Equals(statusLedMn) || (ledMN.LeituraComando != statusLedMn)))
{
ledMN.Comportamento.statusLED = statusLedMn;
GeneralJoystick.EnviarComandoSensoriamento(S_Code.sLED, ledMN.ID, ledMN.Comportamento);
}
2024-12-05 12:52:28 +00:00
foreach (var rele in Reles.Where(x => x.Controlar && x.Inicializado))
2024-12-03 20:55:25 +00:00
{
2024-12-05 12:52:28 +00:00
if (rele.StatusControle != rele.LeituraEstado)
{
GeneralJoystick.EnviarComandoSensoriamento(S_Code.sRLE, rele.ID, rele.StatusControle);
}
2024-12-03 20:55:25 +00:00
}
2024-12-05 12:52:28 +00:00
foreach (var servo in Servos.Where(x => x.Controlar && x.Inicializado))
2024-12-03 20:55:25 +00:00
{
2024-12-05 12:52:28 +00:00
if (servo._AnguloControle != servo.LeituraAngulo)
{
GeneralJoystick.EnviarComandoSensoriamento(S_Code.sFRO, servo.ID, servo._AnguloControle);
}
2024-12-03 20:55:25 +00:00
}
}
}
2024-10-03 18:21:30 +00:00
2023-11-30 00:41:22 +00:00
}
public class SensorModel
{
public string ID { get; set; }
public int Prioridade { get; set; }
public string Descricao { get; set; }
public S_Code Componente { get; set; }
public bool Aferir { get; set; } = false;
public int DelayAmostragem { get; set; } = 500;
private dynamic _leitura = null;
public dynamic Leitura
{
get
{
switch (Componente)
{
case S_Code.sTMP:
_leitura = Variaveis.OperacaoEmAndamento.DispSen?.Dados?.DadosLeitura?.SensoresTemperatura?.FirstOrDefault(x => x.ID == ID);
break;
case S_Code.sCOR:
_leitura = Variaveis.OperacaoEmAndamento.DispSen?.Dados?.DadosLeitura?.SensoresCorrente?.FirstOrDefault(x => x.ID == ID);
break;
case S_Code.sFLX:
_leitura = Variaveis.OperacaoEmAndamento.DispAtu?.Dados?.DadosLeitura?.SensoresFluxo?.FirstOrDefault(x => x.ID == ID);
break;
case S_Code.sPRS:
_leitura = Variaveis.OperacaoEmAndamento.DispAtu?.Dados?.DadosLeitura?.SensoresPressao?.FirstOrDefault(x => x.ID == ID);
break;
case S_Code.sMAS:
_leitura = Variaveis.OperacaoEmAndamento.DispAtu?.Dados?.DadosLeitura?.SensoresMassa?.FirstOrDefault(x => x.ID == ID);
break;
default:
_leitura = null;
break;
}
return _leitura;
}
set
{
_leitura = value;
}
}
public bool Inicializado
{
get
{
return Leitura?.Iniciado ?? false;
}
}
2023-11-30 00:41:22 +00:00
public bool Testando { get; set; } = false;
public List<FuncoesPinout> Funcoes { get; set; }
2024-01-23 17:10:34 +00:00
public List<string[]> Parametros { get; set;} = new List<string[]>();
2023-11-30 00:41:22 +00:00
public string UnidadeMedida { get; set; }
2024-01-31 17:23:52 +00:00
public double LimiteMaximo { get; set; }
public double LimiteMinimo { get; set; }
2023-11-30 00:41:22 +00:00
public List<SenSensorimanetoGrafico> LogGrafico = new List<SenSensorimanetoGrafico>();
public string ProtocoloConfiguracao(PinoutDataModel Pinout, bool Conectar)
2023-11-30 00:41:22 +00:00
{
2024-04-15 10:57:37 +00:00
var _pinout = new PinoutDataModel()
{
ExpansorGPIO = Pinout.ExpansorGPIO,
EnderecoExpansor = Pinout.EnderecoExpansor,
Pinos = Pinout.Pinos.ToList(),
};
_pinout.Pinos = _pinout.Pinos.Where(x => x.ComponenteID == ID).ToList();
2024-04-26 19:34:58 +00:00
string Protocolo =
ID + SerialService.SplitSubParams +
(Conectar ? "1" : "0") + SerialService.SplitSubParams +
PinoutModel.PinoProtocolo(_pinout, Funcoes, SerialService.SplitSubParams);
2024-01-23 17:10:34 +00:00
foreach (var Parametro in Parametros)
{
Protocolo += SerialService.SplitSubParams + Parametro[1];
2024-01-23 17:10:34 +00:00
}
2024-01-18 19:22:28 +00:00
return Protocolo;
2023-11-30 00:41:22 +00:00
}
}
public class SensorSinaleiroModel
{
public string ID { get; set; }
public string Descricao { get; set; }
public S_Code Componente { get; set; }
public List<FuncoesPinout> Funcoes { get; set; }
public SensorSinaleiroComportamentoModel Comportamento { get; set; }
private FirmwareSinaleiro _leitura = null;
public FirmwareSinaleiro Leitura
{
get
{
_leitura = Variaveis.OperacaoEmAndamento.DispSen?.Dados?.DadosLeitura?.Sinaleiros?.FirstOrDefault(x => x.ID == ID);
return _leitura;
}
set
{
_leitura = value;
}
}
public bool Inicializado
{
get
{
return Leitura?.Iniciado ?? false;
}
}
2024-12-03 20:55:25 +00:00
public StatusLED LeituraComando
{
get
{
return Leitura?.Comando ?? StatusLED.Apagado;
}
}
public StatusLED LeituraStatus
{
get
{
return Leitura?.Leitura ?? StatusLED.Apagado;
}
}
public string ProtocoloConfiguracao(PinoutDataModel Pinout, bool Conectar)
{
2024-04-15 10:57:37 +00:00
var _pinout = new PinoutDataModel()
{
ExpansorGPIO = Pinout.ExpansorGPIO,
EnderecoExpansor = Pinout.EnderecoExpansor,
Pinos = Pinout.Pinos.ToList(),
};
_pinout.Pinos = _pinout.Pinos.Where(x => x.ComponenteID == ID).ToList();
string Protocolo =
ID + SerialService.SplitSubParams +
(Conectar ? "1" : "0") + SerialService.SplitSubParams +
PinoutModel.PinoProtocolo(_pinout, Funcoes, SerialService.SplitSubParams);
return Protocolo;
}
public string ProtocoloComando()
{
string ProtocoloSinaleiro =
2024-04-26 19:34:58 +00:00
((int)F_Code.Cmd).ToString() + SerialService.SplitMessage +
ID + SerialService.SplitParams +
((int)Componente) + SerialService.SplitParams +
2024-04-26 19:34:58 +00:00
(int)Comportamento.statusLED + SerialService.SplitParams +
Comportamento.QtdPiscadas.ToString() + SerialService.SplitParams +
Comportamento.TempoMs.ToString() + SerialService.SplitParams +
Comportamento.PausaMs.ToString();
return ProtocoloSinaleiro;
}
2024-07-18 18:00:14 +00:00
}
public class SensorReleModel
{
public string ID { get; set; }
public string Descricao { get; set; }
public S_Code Componente { get; set; }
public List<FuncoesPinout> Funcoes { get; set; }
2024-07-24 20:04:55 +00:00
public bool Controlar { get; set; }
public bool AtuacaoNivelAlto { get; set; }
2024-07-18 18:00:14 +00:00
public Estado StatusControle { get; set; }
private FirmwareRele _leitura = null;
public FirmwareRele Leitura
{
get
{
_leitura = Variaveis.OperacaoEmAndamento.DispSen?.Dados?.DadosLeitura?.Reles?.FirstOrDefault(x => x.ID == ID);
return _leitura;
}
set
{
_leitura = value;
}
}
public bool Inicializado
{
get
{
return Leitura?.Iniciado ?? false;
}
}
2024-12-03 20:55:25 +00:00
public Estado LeituraEstado
{
get
{
return Leitura?.Leitura ?? Estado.Desligado;
}
}
2024-07-18 18:00:14 +00:00
public string ProtocoloConfiguracao(PinoutDataModel Pinout, bool Conectar)
2024-07-18 18:00:14 +00:00
{
var _pinout = new PinoutDataModel()
{
ExpansorGPIO = Pinout.ExpansorGPIO,
EnderecoExpansor = Pinout.EnderecoExpansor,
Pinos = Pinout.Pinos.ToList(),
};
_pinout.Pinos = _pinout.Pinos.Where(x => x.ComponenteID == ID).ToList();
string Protocolo =
ID + SerialService.SplitSubParams +
(Conectar ? "1" : "0") + SerialService.SplitSubParams +
(AtuacaoNivelAlto ? "1" : "0") + SerialService.SplitSubParams +
PinoutModel.PinoProtocolo(_pinout, Funcoes, SerialService.SplitSubParams);
2024-07-18 18:00:14 +00:00
return Protocolo;
}
public string ProtocoloComando()
{
2024-07-24 20:04:55 +00:00
string ProtocoloRele =
2024-07-18 18:00:14 +00:00
((int)F_Code.Cmd).ToString() + SerialService.SplitMessage +
ID + SerialService.SplitParams +
((int)Componente) + SerialService.SplitParams +
2024-07-18 18:00:14 +00:00
(int)StatusControle;
2024-07-24 20:04:55 +00:00
return ProtocoloRele;
}
}
public class SensorServoModel
{
public string ID { get; set; }
public string Descricao { get; set; }
public S_Code Componente { get; set; }
public List<FuncoesPinout> Funcoes { get; set; }
public bool Controlar { get; set; }
public int _AnguloControle { get; set; }
private FirmwareServoFreio _leitura = null;
public FirmwareServoFreio Leitura
{
get
{
_leitura = Variaveis.OperacaoEmAndamento.DispSen?.Dados?.DadosLeitura?.ServoFreios?.FirstOrDefault(x => x.ID == ID);
return _leitura;
}
set
{
_leitura = value;
}
}
public bool Inicializado
{
get
{
return Leitura?.Iniciado ?? false;
}
}
2024-12-03 20:55:25 +00:00
public double LeituraAngulo
{
get
{
return Leitura?.Angulo ?? 0;
}
}
2024-07-24 20:04:55 +00:00
public string ProtocoloConfiguracao(PinoutDataModel Pinout, bool Conectar)
2024-07-24 20:04:55 +00:00
{
var _pinout = new PinoutDataModel()
{
ExpansorGPIO = Pinout.ExpansorGPIO,
EnderecoExpansor = Pinout.EnderecoExpansor,
Pinos = Pinout.Pinos.ToList(),
};
2024-11-25 12:14:59 +00:00
bool incremental = true;
var freio = Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.FirstOrDefault(x => ID.Contains(x.Modulo_ID));
if (freio != null)
{
incremental = freio.MovMotor.ConfigFreio.Incremental;
}
2024-07-24 20:04:55 +00:00
_pinout.Pinos = _pinout.Pinos.Where(x => x.ComponenteID == ID).ToList();
string Protocolo =
ID + SerialService.SplitSubParams +
(Conectar ? "1" : "0") + SerialService.SplitSubParams +
(incremental ? "1" : "0") + SerialService.SplitSubParams +
PinoutModel.PinoProtocolo(_pinout, Funcoes, SerialService.SplitSubParams);
2024-07-24 20:04:55 +00:00
return Protocolo;
}
public string ProtocoloComando()
{
string ProtocoloFreio =
((int)F_Code.Cmd).ToString() + SerialService.SplitMessage +
ID + SerialService.SplitParams +
((int)Componente) + SerialService.SplitParams +
2024-07-24 20:04:55 +00:00
_AnguloControle;
return ProtocoloFreio;
2024-07-18 18:00:14 +00:00
}
}
2024-07-18 18:00:14 +00:00
public class SensorSinaleiroComportamentoModel
{
public StatusLED statusLED { get; set; }
public int QtdPiscadas { get; set; } = 0;
public int TempoMs { get; set; } = 0;
public int PausaMs { get; set; } = 0;
2024-07-18 18:00:14 +00:00
public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
{
return false;
}
SensorSinaleiroComportamentoModel other = (SensorSinaleiroComportamentoModel)obj;
return statusLED == other.statusLED &&
QtdPiscadas == other.QtdPiscadas &&
TempoMs == other.TempoMs &&
PausaMs == other.PausaMs;
}
public override int GetHashCode()
{
unchecked // Permite overflow de inteiros
{
int hash = 17;
hash = hash * 23 + statusLED.GetHashCode();
hash = hash * 23 + QtdPiscadas.GetHashCode();
hash = hash * 23 + TempoMs.GetHashCode();
hash = hash * 23 + PausaMs.GetHashCode();
return hash;
}
}
public static bool operator ==(SensorSinaleiroComportamentoModel left, SensorSinaleiroComportamentoModel right)
{
if (ReferenceEquals(left, right))
{
return true;
}
if ((object)left == null || (object)right == null)
{
return false;
}
return left.Equals(right);
}
public static bool operator !=(SensorSinaleiroComportamentoModel left, SensorSinaleiroComportamentoModel right)
{
return !(left == right);
}
}
2023-11-30 00:41:22 +00:00
public class SenSensorimanetoGrafico
{
public DateTime Momento { get; set; }
public string ComponenteID { get; set; }
public S_Code Componente { get; set; }
public double Leitura1 { get; set; }
public double Leitura2 { get; set; }
public double Leitura3 { get; set; }
public double Leitura4 { get; set; }
public bool AlarmeMaxima { get; set; }
public bool AlarmeMinima { get; set; }
}
2024-04-15 10:57:37 +00:00
public class FirmwareSensorTemperatura
{
public string ID { get; set; }
2024-12-05 12:52:28 +00:00
private bool _iniciado = false;
public bool Iniciado
{
get
{
if (Variaveis.OperacaoEmAndamento.DispSen.Dados.DadosLeitura.Momento.AddMilliseconds(5 * SensoriamentoModel._TaxaAmostragem) < DateTime.Now)
{
_iniciado = false;
}
return _iniciado;
}
set
{
_iniciado = value;
}
}
private int _leitura;
public int Leitura
{
get { return _leitura; }
set
{
_leitura = value;
AtualizarTemperatura();
}
}
private double _atual;
public double Temperatura { get { return _atual; } }
public double ValorMaximo { get; set; }
public double ValorMinimo { get; set; }
public double LimiteMaximo
{
get
{
var sensor = Variaveis.OperacaoEmAndamento.DispSen.Dados.Sensores.FirstOrDefault(x => x.ID == ID);
if (sensor != null)
{
return sensor.LimiteMaximo;
}
return 0;
}
}
public double LimiteMinimo
{
get
{
var sensor = Variaveis.OperacaoEmAndamento.DispSen.Dados.Sensores.FirstOrDefault(x => x.ID == ID);
if (sensor != null)
{
return sensor.LimiteMinimo;
}
return 0;
}
}
private void AtualizarTemperatura()
{
if (Variaveis.OperacaoEmAndamento.DispSen != null)
{
SensorModel Sensor = Variaveis.OperacaoEmAndamento.DispSen.Dados.Sensores.FirstOrDefault(x => x.ID == ID);
if (Sensor != null && Sensor.Parametros.Count > 0 && Sensor.Parametros[0].Length > 1)
{
if (double.TryParse(Sensor.Parametros[0][1].Replace(".", ","), out double fatorCalibracao))
{
_atual = FuncoesMatematicas.CalcularTemperatura(_leitura, fatorCalibracao);
AtualizarExtremos();
}
else
{
Console.WriteLine($"Erro ao converter o parâmetro de calibração para o sensor {ID}");
}
}
}
}
private void AtualizarExtremos()
{
if (_atual > ValorMaximo)
{
ValorMaximo = _atual;
}
if (_atual < ValorMinimo || ValorMinimo == 0)
{
ValorMinimo = _atual;
}
}
}
public class FirmwareSensorCorrente
{
public string ID { get; set; }
2024-12-05 12:52:28 +00:00
private bool _iniciado = false;
public bool Iniciado
{
get
{
if (Variaveis.OperacaoEmAndamento.DispSen.Dados.DadosLeitura.Momento.AddMilliseconds(5 * SensoriamentoModel._TaxaAmostragem) < DateTime.Now)
{
_iniciado = false;
}
return _iniciado;
}
set
{
_iniciado = value;
}
}
public double BusVoltage { get; set; }
public double ShuntVoltage { get; set; }
public double? Current
{
get
{
return _atual;
}
set
{
_atual = value ?? 0;
AtualizarExtremos();
}
}
public double Power { get; set; }
public double ValorMaximo { get; set; }
public double ValorMinimo { get; set; }
public double LimiteMaximo
{
get
{
var sensor = Variaveis.OperacaoEmAndamento.DispSen.Dados.Sensores.FirstOrDefault(x => x.ID == ID);
if (sensor != null)
{
return sensor.LimiteMaximo;
}
return 0;
}
}
public double LimiteMinimo
{
get
{
var sensor = Variaveis.OperacaoEmAndamento.DispSen.Dados.Sensores.FirstOrDefault(x => x.ID == ID);
if (sensor != null)
{
return sensor.LimiteMinimo;
}
return 0;
}
}
private double _atual = 0;
private void AtualizarExtremos()
{
if (_atual > ValorMaximo)
{
ValorMaximo = _atual;
}
if (_atual < ValorMinimo || ValorMinimo == 0)
{
ValorMinimo = _atual;
}
}
}
public class FirmwareSinaleiro
{
public string ID { get; set; }
2024-12-05 12:52:28 +00:00
private bool _iniciado = false;
public bool Iniciado
{
get
{
if (Variaveis.OperacaoEmAndamento.DispSen.Dados.DadosLeitura.Momento.AddMilliseconds(5 * SensoriamentoModel._TaxaAmostragem) < DateTime.Now)
{
_iniciado = false;
}
return _iniciado;
}
set
{
_iniciado = value;
}
}
public StatusLED Leitura { get; set; }
2024-12-03 20:55:25 +00:00
public StatusLED Comando { get; set; }
}
public class FirmwareRele
{
public string ID { get; set; }
2024-12-05 12:52:28 +00:00
private bool _iniciado = false;
public bool Iniciado
{
get
{
if (Variaveis.OperacaoEmAndamento.DispSen.Dados.DadosLeitura.Momento.AddMilliseconds(5 * SensoriamentoModel._TaxaAmostragem) < DateTime.Now)
{
_iniciado = false;
}
return _iniciado;
}
set
{
_iniciado = value;
}
}
public Estado Leitura { get; set; }
}
public class FirmwareServoFreio
{
public string ID { get; set; }
2024-12-05 12:52:28 +00:00
private bool _iniciado = false;
public bool Iniciado
{
get
{
if (Variaveis.OperacaoEmAndamento.DispSen.Dados.DadosLeitura.Momento.AddMilliseconds(5 * SensoriamentoModel._TaxaAmostragem) < DateTime.Now)
{
_iniciado = false;
}
return _iniciado;
}
set
{
_iniciado = value;
}
}
public int Angulo { get; set; }
}
public class FirmwareSensorFluxo
{
public string ID { get; set; }
2024-12-05 12:52:28 +00:00
private bool _iniciado = false;
public bool Iniciado
2024-12-02 19:12:39 +00:00
{
2024-12-05 12:52:28 +00:00
get
{
if (Variaveis.OperacaoEmAndamento.DispAtu.Dados.DadosLeitura.Momento.AddMilliseconds(5 * AtuadorModel._TaxaAmostragem) < DateTime.Now)
{
_iniciado = false;
}
return _iniciado;
}
set
{
_iniciado = value;
}
}
public int Pulsos { get; set; }
private int _periodo;
public int Periodo
{
get
{
return _periodo;
}
2024-12-02 19:12:39 +00:00
set
{
2024-12-05 12:52:28 +00:00
_periodo = value;
2024-12-02 19:12:39 +00:00
AtualizarVazao();
}
}
private double _atual;
public double Vazao { get { return _atual; } }
public double ValorMaximo { get; set; }
public double ValorMinimo { get; set; }
public double LimiteMaximo
{
get
{
var sensor = Variaveis.OperacaoEmAndamento.DispAtu.Dados.Sensores.FirstOrDefault(x => x.ID == ID);
if (sensor != null)
{
return sensor.LimiteMaximo;
}
return 0;
}
}
public double LimiteMinimo
{
get
{
var sensor = Variaveis.OperacaoEmAndamento.DispAtu.Dados.Sensores.FirstOrDefault(x => x.ID == ID);
if (sensor != null)
{
return sensor.LimiteMinimo;
}
return 0;
}
}
private void AtualizarVazao()
{
//_atual = Variaveis.OperacaoEmAndamento.DispAtu.Dados.VazaoFluxoMLpS;
if (Periodo == 0)
{
_atual = 0;
}
else
{
2024-12-05 12:52:28 +00:00
double Frequencia = ((double)Pulsos / (double)Periodo * 1000);
2024-12-02 19:12:39 +00:00
//double vazao = (_LeituraPulsos * FatorLeitura) / ((double)_LeituraPeriodo / 1000);
//double vazao = ((double)1 / FatorLeitura) * (60 * 1000 / _LeituraPeriodo);
//double vazao = ((double)_LeituraPulsos / (((double)_LeituraPeriodo / 1000) * 8.1)) + 3;
//double Fator = (double)_LeituraPulsos / (double)_LeituraPeriodo;
//double vazao = ((double)_LeituraPulsos / (double)_LeituraPeriodo * 1000) * ;
//double vazao = Frequencia * 1.22;
double Rh = 0.0047;
double Rt = 0.0037;
double vazao = (Frequencia * 2 * Math.PI * Rh * Math.PI * (Rt * Rt)) * 1000000;
2024-12-05 12:52:28 +00:00
Console.WriteLine("Pulsos: " + Pulsos + " - Periodo: " + Periodo + " ms - Vazão: " + vazao.ToString("0.00000"));
2024-12-02 19:12:39 +00:00
_atual = vazao;
}
AtualizarExtremos();
}
private void AtualizarExtremos()
{
if (_atual > ValorMaximo)
{
ValorMaximo = _atual;
}
if (_atual < ValorMinimo || ValorMinimo == 0)
{
ValorMinimo = _atual;
}
}
}
public class FirmwareSensorMassa
{
public string ID { get; set; }
2024-12-05 12:52:28 +00:00
private bool _iniciado = false;
public bool Iniciado
{
get
{
if (Variaveis.OperacaoEmAndamento.DispAtu.Dados.DadosLeitura.Momento.AddMilliseconds(5 * AtuadorModel._TaxaAmostragem) < DateTime.Now)
{
_iniciado = false;
}
return _iniciado;
}
set
{
_iniciado = value;
}
}
private double _leitura;
public double Leitura
2024-12-02 19:12:39 +00:00
{
get { return _leitura; }
set
{
_leitura = value;
AtualizarMassa();
}
}
private double _atual;
public double Massa { get { return _atual; } }
public double ValorMaximo { get; set; }
public double ValorMinimo { get; set; }
public double LimiteMaximo
{
get
{
var sensor = Variaveis.OperacaoEmAndamento.DispAtu.Dados.Sensores.FirstOrDefault(x => x.ID == ID);
if (sensor != null)
{
return sensor.LimiteMaximo;
}
return 0;
}
}
public double LimiteMinimo
{
get
{
var sensor = Variaveis.OperacaoEmAndamento.DispAtu.Dados.Sensores.FirstOrDefault(x => x.ID == ID);
if (sensor != null)
{
return sensor.LimiteMinimo;
}
return 0;
}
}
private void AtualizarMassa()
{
if (Variaveis.OperacaoEmAndamento.DispAtu != null)
{
double leituraMassa = _leitura * -1;
leituraMassa += Variaveis.OperacaoEmAndamento.DispAtu.Dados._MassaLeituraExtra;
double FatorLeitura = Variaveis.OperacaoEmAndamento.DispAtu.Dados._MassaRef / Variaveis.OperacaoEmAndamento.DispAtu.Dados._MassaLeituraRef;
_atual = FatorLeitura * leituraMassa;
AtualizarExtremos();
}
}
private void AtualizarExtremos()
{
if (_atual > ValorMaximo)
{
ValorMaximo = _atual;
}
if (_atual < ValorMinimo || ValorMinimo == 0)
{
ValorMinimo = _atual;
}
}
}
public class FirmwareSensorPressao
{
public string ID { get; set; }
2024-12-05 12:52:28 +00:00
private bool _iniciado = false;
public bool Iniciado
{
get
{
if (Variaveis.OperacaoEmAndamento.DispAtu.Dados.DadosLeitura.Momento.AddMilliseconds(5 * AtuadorModel._TaxaAmostragem) < DateTime.Now)
{
_iniciado = false;
}
return _iniciado;
}
set
{
_iniciado = value;
}
}
2024-12-02 19:12:39 +00:00
public double Leitura { get; set; }
public double Pressao { get; set; }
}
public class SensoriamentoMensagemJsonModel
{
public bool Conectado { get; set; }
public string Mod_ID { get; set; }
public DateTime Momento { get; set; }
public List<FirmwareSensorTemperatura> SensoresTemperatura { get; set; } = new List<FirmwareSensorTemperatura>();
public List<FirmwareSensorCorrente> SensoresCorrente { get; set; } = new List<FirmwareSensorCorrente>();
public List<FirmwareSinaleiro> Sinaleiros { get; set; } = new List<FirmwareSinaleiro>();
public List<FirmwareRele> Reles { get; set; } = new List<FirmwareRele>();
public List<FirmwareServoFreio> ServoFreios { get; set; } = new List<FirmwareServoFreio>();
}
2023-11-30 00:41:22 +00:00
}