finalizado implantacao CAN para ATU e SEN
This commit is contained in:
parent
86cbe678c9
commit
1712254d9c
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -42,7 +42,7 @@
|
|||
|
||||
public enum T_Code
|
||||
{
|
||||
Vzo = 200,
|
||||
Vzo = 0,
|
||||
Mov = 100,
|
||||
Dir = 101,
|
||||
Sen = 102,
|
||||
|
|
|
|||
|
|
@ -230,9 +230,9 @@ namespace AgroBase.Models.Modules
|
|||
Funcoes = new List<FuncoesPinout>()
|
||||
{
|
||||
FuncoesPinout.ENA,
|
||||
FuncoesPinout.CS,
|
||||
FuncoesPinout.INA,
|
||||
FuncoesPinout.INB,
|
||||
//FuncoesPinout.CS,
|
||||
//FuncoesPinout.INA,
|
||||
//FuncoesPinout.INB,
|
||||
FuncoesPinout.PWM,
|
||||
}
|
||||
}
|
||||
|
|
@ -288,7 +288,7 @@ namespace AgroBase.Models.Modules
|
|||
Valor = "0",
|
||||
QtdBytes = 1,
|
||||
Escalar = false,
|
||||
Enviar = true
|
||||
Enviar = false
|
||||
},
|
||||
new SensorParametroModel()
|
||||
{
|
||||
|
|
@ -296,7 +296,7 @@ namespace AgroBase.Models.Modules
|
|||
Valor = "4.5",
|
||||
QtdBytes = 1,
|
||||
Escalar = true,
|
||||
Enviar = true
|
||||
Enviar = false
|
||||
},
|
||||
new SensorParametroModel()
|
||||
{
|
||||
|
|
@ -304,7 +304,7 @@ namespace AgroBase.Models.Modules
|
|||
Valor = "174",
|
||||
QtdBytes = 1,
|
||||
Escalar = false,
|
||||
Enviar = true
|
||||
Enviar = false
|
||||
},
|
||||
}
|
||||
},
|
||||
|
|
@ -380,9 +380,10 @@ namespace AgroBase.Models.Modules
|
|||
if (!CanService.IsConnected)
|
||||
{
|
||||
CanService.DefinirPortaCOM(porta);
|
||||
CanService.RegistrarHandler(Dispositivo, _AtuHandler);
|
||||
}
|
||||
|
||||
CanService.RegistrarHandler(_EnderecoCAN, _AtuHandler);
|
||||
|
||||
if (CanService.IsConnected)
|
||||
{
|
||||
RequisitarDadosModulo(F_Code.ChkTx);
|
||||
|
|
@ -392,6 +393,7 @@ namespace AgroBase.Models.Modules
|
|||
if (Conectado)
|
||||
{
|
||||
DefinirDispositivo();
|
||||
Variaveis.OperacaoEmAndamento.DispAtu?.EnviarProtocolosConfiguracao();
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -432,13 +434,17 @@ namespace AgroBase.Models.Modules
|
|||
// Inicializar o dicionário
|
||||
List<byte[]> config = new List<byte[]>();
|
||||
|
||||
if (!Conectado)
|
||||
if (!DadosLeitura.Conectado)
|
||||
{
|
||||
// Adicionar configuração do ProtocoloMOD
|
||||
var protocoloMOD = ModConfig(Conectar);
|
||||
config.Add(protocoloMOD);
|
||||
}
|
||||
|
||||
// Adicionar configurações dos Sensores que devem ser aferidos
|
||||
List<byte[]> sensoresConfig = SensoresConfig(Conectar);
|
||||
config.AddRange(sensoresConfig);
|
||||
|
||||
// Adicionar configurações dos Bicos
|
||||
List<byte[]> bicosConfig = BicosConfig(Conectar);
|
||||
config.AddRange(bicosConfig);
|
||||
|
|
@ -447,14 +453,10 @@ namespace AgroBase.Models.Modules
|
|||
List<byte[]> bombasConfig = BombasConfig(Conectar);
|
||||
config.AddRange(bombasConfig);
|
||||
|
||||
// Adicionar configurações dos Sensores que devem ser aferidos
|
||||
List<byte[]> sensoresConfig = SensoresConfig(Conectar);
|
||||
config.AddRange(sensoresConfig);
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
public byte[] ModConfig(bool Conectar)
|
||||
private byte[] ModConfig(bool Conectar)
|
||||
{
|
||||
var pinos = PinoutModel.PinoProtocolo(Pinout, Funcoes, false);
|
||||
|
||||
|
|
@ -462,8 +464,7 @@ namespace AgroBase.Models.Modules
|
|||
{
|
||||
(byte)S_Code.sMOD,
|
||||
(byte)(Conectar ? 1 : 0),
|
||||
(byte)(_TaxaAmostragem >> 8),
|
||||
(byte)(_TaxaAmostragem & 0xFF),
|
||||
(byte)(_TaxaAmostragem / 10),
|
||||
(byte)(RequisitarDados ? 1 : 0),
|
||||
};
|
||||
config.AddRange(pinos);
|
||||
|
|
@ -609,7 +610,7 @@ namespace AgroBase.Models.Modules
|
|||
}
|
||||
|
||||
|
||||
if (Conectado)
|
||||
if (DadosLeitura.Conectado)
|
||||
{
|
||||
if (RequisitarDados)
|
||||
{
|
||||
|
|
@ -887,18 +888,31 @@ namespace AgroBase.Models.Modules
|
|||
|
||||
public byte[] ProtocoloConfiguracao(PinoutDataModel pinout, bool conectar)
|
||||
{
|
||||
var pino = pinout.Pinos.FirstOrDefault(p => p.ComponenteID == ID);
|
||||
byte pressaoMax = (byte)Variaveis.OperacaoEmAndamento.Controle.PressaoLinha;
|
||||
|
||||
return new byte[]
|
||||
var _pinout = new PinoutDataModel()
|
||||
{
|
||||
ExpansorGPIO = pinout.ExpansorGPIO,
|
||||
EnderecoGPIO = pinout.EnderecoGPIO,
|
||||
ExpansorADS = pinout.ExpansorADS,
|
||||
EnderecoADS = pinout.EnderecoADS,
|
||||
Pinos = pinout.Pinos.ToList(),
|
||||
};
|
||||
_pinout.Pinos = _pinout.Pinos.Where(x => x.ComponenteID == ID).ToList();
|
||||
|
||||
List<byte> config = new List<byte>()
|
||||
{
|
||||
(byte)Componente,
|
||||
(byte)ID_Num,
|
||||
(byte)(conectar ? 1 : 0),
|
||||
pressaoMax,
|
||||
(byte)(pino?.Barramento ?? TiposBarramentos.CONTROLADOR),
|
||||
(byte)(pino?.Pino ?? PinoutUtils.PINO_INVALIDO)
|
||||
};
|
||||
|
||||
byte[] pinos = PinoutModel.PinoProtocolo(_pinout, Funcoes, false);
|
||||
|
||||
config.AddRange(pinos);
|
||||
|
||||
return config.ToArray();
|
||||
}
|
||||
|
||||
public (F_Code, byte[]) ProtocoloComando()
|
||||
|
|
@ -907,7 +921,6 @@ namespace AgroBase.Models.Modules
|
|||
F_Code.CmdTx,
|
||||
new byte[]
|
||||
{
|
||||
(byte)F_Code.CmdTx,
|
||||
(byte)S_Code.sBMB,
|
||||
(byte)ID_Num,
|
||||
(byte)(ComandoAtuar ? Estado.Ligado : Estado.Desligado),
|
||||
|
|
@ -1159,6 +1172,16 @@ namespace AgroBase.Models.Modules
|
|||
|
||||
public class AtuHandler : ICanMessageHandler
|
||||
{
|
||||
private double ConverterByteParaDouble(byte[] data, int idx)
|
||||
{
|
||||
int raw = (data[idx] << 8) | data[idx + 1];
|
||||
short _short = (short)raw;
|
||||
double _value = _short / 100.0;
|
||||
|
||||
return _value;
|
||||
}
|
||||
|
||||
|
||||
public void ProcessarMensagem(CanMessage mensagem)
|
||||
{
|
||||
F_Code func = (F_Code)mensagem.DataRx[0];
|
||||
|
|
@ -1183,6 +1206,153 @@ namespace AgroBase.Models.Modules
|
|||
item.Versao = versao;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
S_Code componente = (S_Code)data[0];
|
||||
int CompID_Num = data[1];
|
||||
bool Iniciado = data[2] == 1;
|
||||
|
||||
//Console.WriteLine($"[ATU] Componente={componente.ToString()}, ID_Num={CompID_Num}, Iniciado={Iniciado}, Data={FuncoesGlobais.ConverterComandoBytesParaTexto(data)}");
|
||||
|
||||
switch (componente)
|
||||
{
|
||||
case S_Code.sBIC:
|
||||
{
|
||||
var bico = Variaveis.OperacaoEmAndamento.DispAtu.Dados.BicosPulverizadores.FirstOrDefault(x => x.ID_Num == CompID_Num);
|
||||
var _bico = item.BicosPulverizadores.FirstOrDefault(x => x.ID == bico.ID);
|
||||
if (_bico == null)
|
||||
{
|
||||
_bico = new FirmwareRele()
|
||||
{
|
||||
ID = bico.ID,
|
||||
Iniciado = Iniciado,
|
||||
Leitura = Estado.Desligado
|
||||
};
|
||||
item.BicosPulverizadores.Add(_bico);
|
||||
}
|
||||
|
||||
Estado estado = (Estado)data[3];
|
||||
|
||||
if (_bico != null)
|
||||
{
|
||||
_bico.Iniciado = Iniciado;
|
||||
_bico.Leitura = estado;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case S_Code.sFLX:
|
||||
{
|
||||
var sensor = Variaveis.OperacaoEmAndamento.DispAtu.Dados.Sensores.FirstOrDefault(x => x.ID_Num == CompID_Num);
|
||||
var _sensor = item.SensoresFluxo.FirstOrDefault(x => x.ID == sensor.ID);
|
||||
if (_sensor == null)
|
||||
{
|
||||
_sensor = new FirmwareSensorFluxo()
|
||||
{
|
||||
ID = sensor.ID,
|
||||
Iniciado = Iniciado,
|
||||
Vazao = -1,
|
||||
};
|
||||
item.SensoresFluxo.Add(_sensor);
|
||||
}
|
||||
double vazao = ConverterByteParaDouble(data, 3);
|
||||
|
||||
if (_sensor != null)
|
||||
{
|
||||
_sensor.Iniciado = Iniciado;
|
||||
_sensor.Vazao = vazao;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case S_Code.sMAS:
|
||||
{
|
||||
var sensor = Variaveis.OperacaoEmAndamento.DispAtu.Dados.Sensores.FirstOrDefault(x => x.ID_Num == CompID_Num);
|
||||
var _sensor = item.SensoresMassa.FirstOrDefault(x => x.ID == sensor.ID);
|
||||
if (_sensor == null)
|
||||
{
|
||||
_sensor = new FirmwareSensorMassa()
|
||||
{
|
||||
ID = sensor.ID,
|
||||
Iniciado = Iniciado,
|
||||
Massa = -1,
|
||||
};
|
||||
item.SensoresMassa.Add(_sensor);
|
||||
}
|
||||
double massa = ConverterByteParaDouble(data, 3);
|
||||
|
||||
if (_sensor != null)
|
||||
{
|
||||
_sensor.Iniciado = Iniciado;
|
||||
_sensor.Massa = massa;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case S_Code.sPRS:
|
||||
{
|
||||
var sensor = Variaveis.OperacaoEmAndamento.DispAtu.Dados.Sensores.FirstOrDefault(x => x.ID_Num == CompID_Num);
|
||||
var _sensor = item.SensoresPressao.FirstOrDefault(x => x.ID == sensor.ID);
|
||||
if (_sensor == null)
|
||||
{
|
||||
_sensor = new FirmwareSensorPressao()
|
||||
{
|
||||
ID = sensor.ID,
|
||||
Iniciado = Iniciado,
|
||||
Pressao = -1,
|
||||
};
|
||||
item.SensoresPressao.Add(_sensor);
|
||||
}
|
||||
double pressao = ConverterByteParaDouble(data, 3);
|
||||
|
||||
if (_sensor != null)
|
||||
{
|
||||
_sensor.Iniciado = Iniciado;
|
||||
_sensor.Pressao = pressao;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case S_Code.sBMB:
|
||||
{
|
||||
var bomba = Variaveis.OperacaoEmAndamento.DispAtu.Dados.BombasPressurizadoras.FirstOrDefault(x => x.ID_Num == CompID_Num);
|
||||
var _bomba = item.BombasPressurizadoras.FirstOrDefault(x => x.ID == bomba.ID);
|
||||
if (_bomba == null)
|
||||
{
|
||||
_bomba = new FirmwareBombaPressurizadora()
|
||||
{
|
||||
ID = bomba.ID,
|
||||
Iniciado = Iniciado,
|
||||
Estado = Estado.Desligado,
|
||||
Potencia = 0,
|
||||
Pressao = -1,
|
||||
PressaoSP = -1,
|
||||
};
|
||||
item.BombasPressurizadoras.Add(_bomba);
|
||||
}
|
||||
|
||||
Estado estado = (Estado)data[3];
|
||||
int percentualPotencia = data[4];
|
||||
int pressaoSp = data[5];
|
||||
int pressaoAtual = data[6];
|
||||
|
||||
if (_bomba != null)
|
||||
{
|
||||
_bomba.Iniciado = Iniciado;
|
||||
_bomba.Estado = estado;
|
||||
_bomba.Potencia = percentualPotencia;
|
||||
_bomba.PressaoSP = pressaoSp;
|
||||
_bomba.Pressao = pressaoAtual;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
default:
|
||||
{
|
||||
Console.WriteLine($"[ATU] Resposta {func.ToString()} recebida. Parametros nao mapeados: {FuncoesGlobais.ConverterComandoBytesParaTexto(data)}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
item.UltimoComandoRespondido = DateTime.Now;
|
||||
|
|
|
|||
|
|
@ -570,9 +570,10 @@ namespace AgroBase.Models.Modules
|
|||
if (!CanService.IsConnected)
|
||||
{
|
||||
CanService.DefinirPortaCOM(porta);
|
||||
CanService.RegistrarHandler(Dispositivo, _SenHandler);
|
||||
}
|
||||
|
||||
CanService.RegistrarHandler(_EnderecoCAN, _SenHandler);
|
||||
|
||||
if (CanService.IsConnected)
|
||||
{
|
||||
RequisitarDadosModulo(F_Code.ChkTx);
|
||||
|
|
@ -701,7 +702,7 @@ namespace AgroBase.Models.Modules
|
|||
{
|
||||
var config = new List<byte[]>();
|
||||
|
||||
foreach (var rele in Reles.Where(x => x.Controlar /*&& x.Inicializado != Conectar*/))
|
||||
foreach (var rele in Reles.Where(x => x.Controlar && x.Inicializado != Conectar))
|
||||
{
|
||||
var payload = rele.ProtocoloConfiguracao(Pinout, Conectar);
|
||||
if (payload != null)
|
||||
|
|
@ -812,7 +813,7 @@ namespace AgroBase.Models.Modules
|
|||
|
||||
tmrRegistrador.SetInterval(_TaxaAmostragem);
|
||||
|
||||
if (false && SerialService.DispositivosMapeados.Any(x => x.Dispositivo == T_Code.Sen) && (_VezesLeituraReconexao >= _TempoReconexaoComponentes))
|
||||
if (SerialService.DispositivosMapeados.Any(x => x.Dispositivo == T_Code.Sen) && (_VezesLeituraReconexao >= _TempoReconexaoComponentes))
|
||||
{
|
||||
Variaveis.OperacaoEmAndamento.DispSen?.EnviarProtocolosConfiguracao();
|
||||
|
||||
|
|
@ -994,7 +995,14 @@ namespace AgroBase.Models.Modules
|
|||
_pinout.Pinos = _pinout.Pinos.Where(x => x.ComponenteID == ID).ToList();
|
||||
if (_pinout.Pinos.Count > 0)
|
||||
{
|
||||
byte[] pinos = PinoutModel.PinoProtocolo(_pinout, Funcoes, true);
|
||||
List<S_Code> sensoresApenasBarramentoControlador = new List<S_Code>()
|
||||
{
|
||||
S_Code.sBMB,
|
||||
S_Code.sMAS
|
||||
};
|
||||
bool enviaBarramento = !sensoresApenasBarramentoControlador.Contains(Componente);
|
||||
|
||||
byte[] pinos = PinoutModel.PinoProtocolo(_pinout, Funcoes, enviaBarramento);
|
||||
config.AddRange(pinos);
|
||||
}
|
||||
|
||||
|
|
@ -1491,22 +1499,19 @@ namespace AgroBase.Models.Modules
|
|||
{
|
||||
public string ID { get; set; }
|
||||
public bool Iniciado { get; set; }
|
||||
public int Pulsos { get; set; }
|
||||
private int _periodo;
|
||||
public int Periodo
|
||||
private double _vazao;
|
||||
public double Vazao
|
||||
{
|
||||
get
|
||||
{
|
||||
return _periodo;
|
||||
return _vazao;
|
||||
}
|
||||
set
|
||||
{
|
||||
_periodo = value;
|
||||
AtualizarVazao();
|
||||
_vazao = value;
|
||||
AtualizarExtremos();
|
||||
}
|
||||
}
|
||||
private double _atual;
|
||||
public double Vazao { get { return _atual; } }
|
||||
public double ValorMaximo { get; set; }
|
||||
public double ValorMinimo { get; set; }
|
||||
public double LimiteMaximo
|
||||
|
|
@ -1534,45 +1539,15 @@ namespace AgroBase.Models.Modules
|
|||
}
|
||||
}
|
||||
|
||||
private void AtualizarVazao()
|
||||
{
|
||||
//_atual = Variaveis.OperacaoEmAndamento.DispAtu.Dados.VazaoFluxoMLpS;
|
||||
if (Periodo == 0)
|
||||
{
|
||||
_atual = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
double Frequencia = ((double)Pulsos / (double)Periodo * 1000);
|
||||
//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;
|
||||
|
||||
Console.WriteLine("Pulsos: " + Pulsos + " - Periodo: " + Periodo + " ms - Vazão: " + vazao.ToString("0.00000"));
|
||||
|
||||
_atual = vazao;
|
||||
}
|
||||
AtualizarExtremos();
|
||||
}
|
||||
|
||||
private void AtualizarExtremos()
|
||||
{
|
||||
if (_atual > ValorMaximo)
|
||||
if (_vazao > ValorMaximo)
|
||||
{
|
||||
ValorMaximo = _atual;
|
||||
ValorMaximo = _vazao;
|
||||
}
|
||||
if (_atual < ValorMinimo || ValorMinimo == 0)
|
||||
if (_vazao < ValorMinimo || ValorMinimo == 0)
|
||||
{
|
||||
ValorMinimo = _atual;
|
||||
ValorMinimo = _vazao;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1582,18 +1557,19 @@ namespace AgroBase.Models.Modules
|
|||
{
|
||||
public string ID { get; set; }
|
||||
public bool Iniciado { get; set; }
|
||||
private double _leitura;
|
||||
public double Leitura
|
||||
private double _massa;
|
||||
public double Massa
|
||||
{
|
||||
get { return _leitura; }
|
||||
get
|
||||
{
|
||||
return _massa;
|
||||
}
|
||||
set
|
||||
{
|
||||
_leitura = value;
|
||||
AtualizarMassa();
|
||||
_massa = value;
|
||||
AtualizarExtremos();
|
||||
}
|
||||
}
|
||||
private double _atual;
|
||||
public double Massa { get { return _atual; } }
|
||||
public double ValorMaximo { get; set; }
|
||||
public double ValorMinimo { get; set; }
|
||||
public double LimiteMaximo
|
||||
|
|
@ -1621,29 +1597,15 @@ namespace AgroBase.Models.Modules
|
|||
}
|
||||
}
|
||||
|
||||
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)
|
||||
if (_massa > ValorMaximo)
|
||||
{
|
||||
ValorMaximo = _atual;
|
||||
ValorMaximo = _massa;
|
||||
}
|
||||
if (_atual < ValorMinimo || ValorMinimo == 0)
|
||||
if (_massa < ValorMinimo || ValorMinimo == 0)
|
||||
{
|
||||
ValorMinimo = _atual;
|
||||
ValorMinimo = _massa;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1793,7 +1755,7 @@ namespace AgroBase.Models.Modules
|
|||
int CompID_Num = data[1];
|
||||
bool Iniciado = data[2] == 1;
|
||||
|
||||
Console.WriteLine($"[SEN] Componente={componente.ToString()}, ID_Num={CompID_Num}, Iniciado={Iniciado}");
|
||||
//Console.WriteLine($"[SEN] Componente={componente.ToString()}, ID_Num={CompID_Num}, Iniciado={Iniciado}");
|
||||
|
||||
switch (componente)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -49,15 +49,15 @@ namespace AgroBase.Services
|
|||
private static AsyncTaskTimerModel tmrEnviarCAN;
|
||||
private static AsyncTaskTimerModel tmrOuvirCAN;
|
||||
private static StringBuilder SerialCANBuffer = new StringBuilder();
|
||||
private static readonly ConcurrentDictionary<T_Code, ICanMessageHandler> _roteadores = new ConcurrentDictionary<T_Code, ICanMessageHandler>();
|
||||
private static readonly ConcurrentDictionary<byte, ICanMessageHandler> _roteadores = new ConcurrentDictionary<byte, ICanMessageHandler>();
|
||||
private static byte? _ultimoIdEnviado = null;
|
||||
|
||||
private static List<CanMessage> Mensagens = new List<CanMessage>();
|
||||
|
||||
|
||||
public static void RegistrarHandler(T_Code dispositivo, ICanMessageHandler handler)
|
||||
public static void RegistrarHandler(byte endereco, ICanMessageHandler handler)
|
||||
{
|
||||
_roteadores[dispositivo] = handler;
|
||||
_roteadores[endereco] = handler;
|
||||
}
|
||||
|
||||
public static void DefinirPortaCOM(SerialPort Porta)
|
||||
|
|
@ -163,14 +163,14 @@ namespace AgroBase.Services
|
|||
|
||||
if (mensagem == null)
|
||||
{
|
||||
mensagem = new CanMessage { Id = (byte)id, DataRx = data, Dispositivo = mensagensPorID.FirstOrDefault()?.Dispositivo ?? T_Code.Vzo };
|
||||
mensagem = new CanMessage { Id = (byte)id, DataRx = data };
|
||||
}
|
||||
|
||||
mensagem.DataRx = data;
|
||||
mensagem.Respondido = true;
|
||||
mensagem.RespondidoEm = DateTime.Now;
|
||||
|
||||
if (_roteadores.TryGetValue(mensagem.Dispositivo, out var handler))
|
||||
if (_roteadores.TryGetValue(mensagem.Id, out var handler))
|
||||
{
|
||||
handler.ProcessarMensagem(mensagem);
|
||||
}
|
||||
|
|
@ -189,6 +189,7 @@ namespace AgroBase.Services
|
|||
{
|
||||
if (_serialPort?.IsOpen != true) return;
|
||||
|
||||
// Monta o payload com funcCode + dados + CRC
|
||||
var dados = new List<byte> { funcCodeTx };
|
||||
if (payload != null)
|
||||
dados.AddRange(payload);
|
||||
|
|
@ -196,9 +197,7 @@ namespace AgroBase.Services
|
|||
byte crc = CalcularChecksum(id, dados.ToArray());
|
||||
dados.Add(crc);
|
||||
|
||||
//Console.WriteLine($"[CAN OUT] ID: {id:X2} | Func: {funcCode:X2} | Payload: {BitConverter.ToString(dados.ToArray())}");
|
||||
|
||||
var msg = new CanMessage
|
||||
var novaMensagem = new CanMessage
|
||||
{
|
||||
Momento = DateTime.Now,
|
||||
Dispositivo = Dispositivo,
|
||||
|
|
@ -211,19 +210,26 @@ namespace AgroBase.Services
|
|||
|
||||
lock (Mensagens)
|
||||
{
|
||||
if (Mensagens.Any(x =>
|
||||
x.Id == msg.Id && // do mesmo Id
|
||||
x.funcCodeTx == msg.funcCodeTx && // da mesma funcao
|
||||
x.DataTx.SequenceEqual(msg.DataTx) && // com os mesmos comandos
|
||||
(!x.Enviado || (x.ComResposta && !x.Respondido)) // ainda nao enviadas ou que aguarda uma resposta
|
||||
))
|
||||
// Limpa mensagens antigas antes de avaliar
|
||||
LimparMensagensAntigas();
|
||||
|
||||
var existente = Mensagens.FirstOrDefault(x =>
|
||||
x.Id == novaMensagem.Id &&
|
||||
x.funcCodeTx == novaMensagem.funcCodeTx &&
|
||||
x.ComResposta == novaMensagem.ComResposta &&
|
||||
x.DataTx.SequenceEqual(novaMensagem.DataTx) &&
|
||||
(!x.Enviado || (x.ComResposta && !x.Respondido)) // Está pendente
|
||||
);
|
||||
|
||||
if (existente != null)
|
||||
{
|
||||
// Já existe mensagem igual aguardando ou pendente
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Mensagens.Add(msg);
|
||||
}
|
||||
|
||||
// Log e adiciona
|
||||
//Console.WriteLine($"[MSG] - MENSAGEM ADICIONADA NA FILA para o módulo {Dispositivo} - {FuncoesGlobais.ConverterComandoBytesParaTexto(novaMensagem.DataTx)}");
|
||||
Mensagens.Add(novaMensagem);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -269,8 +275,6 @@ namespace AgroBase.Services
|
|||
|
||||
private static async Task EnviarCAN()
|
||||
{
|
||||
LimparMensagensAntigas();
|
||||
|
||||
if (_serialPort?.IsOpen != true) return;
|
||||
|
||||
CanMessage msg = ObterProximaMensagem();
|
||||
|
|
@ -312,7 +316,7 @@ namespace AgroBase.Services
|
|||
{
|
||||
_serialPort.Write(comando);
|
||||
|
||||
Console.WriteLine($"[CAN] Frame enviado: {comando}");
|
||||
//Console.WriteLine($"[CAN] Frame enviado: {comando}");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -320,11 +324,11 @@ namespace AgroBase.Services
|
|||
{
|
||||
lock (Mensagens)
|
||||
{
|
||||
var limite = DateTime.Now.AddSeconds(-10);
|
||||
var limite = DateTime.Now.AddSeconds(-5); // ⏱ 5 segundos de validade
|
||||
Mensagens.RemoveAll(x =>
|
||||
(!x.ComResposta && x.Enviado) || // mensagens enviadas que nao exigem resposta
|
||||
(x.Respondido && x.RespondidoEm < limite) || // mensagens respondidas a mais de 5 segundos
|
||||
(x.Enviado && x.EnviadoEm < limite && !x.Respondido) // mensagens enviadas e nao respondidas a mais de 5 segundos
|
||||
(!x.ComResposta && x.Enviado) || // Mensagem que não precisa resposta e já foi enviada
|
||||
(x.ComResposta && x.Respondido && x.RespondidoEm < limite) || // Resposta antiga
|
||||
(x.ComResposta && x.Enviado && !x.Respondido && x.EnviadoEm < limite) // Enviada mas nunca respondida e já passou do prazo
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,6 @@ namespace AgroBase.Services
|
|||
if (!CanService.IsConnected)
|
||||
{
|
||||
CanService.DefinirPortaCOM(porta);
|
||||
CanService.RegistrarHandler(Dispositivo, _MksHandler);
|
||||
}
|
||||
|
||||
if (CanService.IsConnected)
|
||||
|
|
@ -62,6 +61,7 @@ namespace AgroBase.Services
|
|||
foreach (var Modulo in Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.Where(x => !x.DirMotor.Inicializado))
|
||||
{
|
||||
byte Addr = Modulo.DirMotor.EnderecoByte;
|
||||
CanService.RegistrarHandler(Addr, _MksHandler);
|
||||
|
||||
// Envia comando relevante para verificar o dispositivo
|
||||
RequisitarDado(Addr, MksFuncCode.Versao);
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -1 +1 @@
|
|||
{"tmrRegistrador":{"_uiControl":null,"State":2,"IsRunning":false,"IsStopped":true,"IsCreated":false,"Interval":1000,"StackTrace":"AtuadorModel.IniciarRegistrador","Id":"tmrRegistrador_Atu","TimeTick":"00:00:00"},"_AtuHandler":{},"Dispositivo":103,"Modulo_ID":"Atu","_EnderecoCAN":18,"_TaxaAmostragem":1000,"RequisitarDados":true,"Conectado":false,"QuantidadeBicos":4,"DensidadeHerbicida":1.1,"BicosPulverizadores":[{"ID":"B01","ID_Num":71,"Posicao":1,"Componente":11,"AtuacaoNivelAlto":true,"ComandoAtuar":false,"Comandar":true,"Testando":false,"Funcoes":[21],"LeituraStatusBico":false,"MediaNivelFluxo":0.0,"Leitura":null,"Inicializado":false,"Atuacoes":0,"InicioAtuacao":"0001-01-01T00:00:00","TempoAtuado":0.0},{"ID":"B02","ID_Num":72,"Posicao":2,"Componente":11,"AtuacaoNivelAlto":true,"ComandoAtuar":false,"Comandar":true,"Testando":false,"Funcoes":[21],"LeituraStatusBico":false,"MediaNivelFluxo":0.0,"Leitura":null,"Inicializado":false,"Atuacoes":0,"InicioAtuacao":"0001-01-01T00:00:00","TempoAtuado":0.0},{"ID":"B03","ID_Num":73,"Posicao":3,"Componente":11,"AtuacaoNivelAlto":true,"ComandoAtuar":false,"Comandar":true,"Testando":false,"Funcoes":[21],"LeituraStatusBico":false,"MediaNivelFluxo":0.0,"Leitura":null,"Inicializado":false,"Atuacoes":0,"InicioAtuacao":"0001-01-01T00:00:00","TempoAtuado":0.0},{"ID":"B04","ID_Num":74,"Posicao":4,"Componente":11,"AtuacaoNivelAlto":true,"ComandoAtuar":false,"Comandar":true,"Testando":false,"Funcoes":[21],"LeituraStatusBico":false,"MediaNivelFluxo":0.0,"Leitura":null,"Inicializado":false,"Atuacoes":0,"InicioAtuacao":"0001-01-01T00:00:00","TempoAtuado":0.0}],"BombasPressurizadoras":[{"ID":"BOMBA","ID_Num":51,"ComandoAtuar":false,"Componente":14,"LeituraEstado":false,"Comandar":true,"Testando":false,"Funcoes":[14,35,36,37,5],"LeituraPotencia":0.0,"LeituraPressaoSP":0.0,"LeituraPressao":0.0,"Leitura":null,"Inicializado":false}],"Sensores":[{"LogGrafico":[],"ID":"FLXLN","ID_Num":61,"Descricao":"Fluxo na linha principal","Componente":8,"Aferir":true,"Leitura":null,"Inicializado":false,"Funcoes":[25],"Parametros":[],"UnidadeMedida":"mL/s","LimiteMaximo":0.0,"LimiteMinimo":0.0},{"LogGrafico":[],"ID":"MASRS","ID_Num":62,"Descricao":"Massa do reservatório de herbicida","Componente":10,"Aferir":true,"Leitura":null,"Inicializado":false,"Funcoes":[22,23],"Parametros":[],"UnidadeMedida":"Kg","LimiteMaximo":0.0,"LimiteMinimo":0.0},{"LogGrafico":[],"ID":"PRSLN","ID_Num":63,"Descricao":"Pressão na linha principal","Componente":12,"Aferir":true,"Leitura":null,"Inicializado":false,"Funcoes":[24],"Parametros":[{"Descricao":"Vmin","Valor":"0","QtdBytes":1,"Escalar":false,"Enviar":true},{"Descricao":"Vmax","Valor":"4.5","QtdBytes":1,"Escalar":true,"Enviar":true},{"Descricao":"Pmax","Valor":"174","QtdBytes":1,"Escalar":false,"Enviar":true}],"UnidadeMedida":"psi","LimiteMaximo":0.0,"LimiteMinimo":0.0}],"BombaPressurizadora":{"ID":"BOMBA","ID_Num":51,"ComandoAtuar":false,"Componente":14,"LeituraEstado":false,"Comandar":true,"Testando":false,"Funcoes":[14,35,36,37,5],"LeituraPotencia":0.0,"LeituraPressaoSP":0.0,"LeituraPressao":0.0,"Leitura":null,"Inicializado":false},"ScriptDeteccaoErvas":"weed_detector_oak-1_0.py","DadosLeitura":{"Momento":"0001-01-01T00:00:00","Conectado":false,"Dispositivo":0,"Versao":0,"Mod_ID":null,"QualidadeWifi":0,"LatenciaLoop":0,"BicosPulverizadores":[],"BombasPressurizadoras":[],"SensoresFluxo":[],"SensoresMassa":[],"SensoresPressao":[],"UltimoComandoRespondido":"0001-01-01T00:00:00"},"_MassaRef":0.8,"_MassaLeituraRef":40876.37,"_MassaLeituraExtra":1895800.0,"MassaReservatorio":0.0,"VolumeReservatorio":0.0,"PercentualReservatorio":0.0,"VolumeVazaoAferido":0.0,"_FluxoMlRef":600.0,"_FluxoPulsoRef":538.0,"VazaoFluxoMLpSInstantanea":0.0,"VazaoFluxoMLpSMedia":0.0,"VolumeVazaoML":0.0,"InicioAtuacao":"0001-01-01T00:00:00","TempoAtuado":0.0,"_PressaoVmin":0.0,"_PressaoVmax":4.5,"_PressaoMax":174.045,"PressaoLinha":0.0,"PressaoLinhaCalc":0.0,"PercentualErvasTerreno":0.0}
|
||||
{"tmrRegistrador":{"_uiControl":null,"State":2,"IsRunning":false,"IsStopped":true,"IsCreated":false,"Interval":1000,"StackTrace":"AtuadorModel.IniciarRegistrador","Id":"tmrRegistrador_Atu","TimeTick":"00:00:00"},"_AtuHandler":{},"Dispositivo":103,"Modulo_ID":"Atu","_EnderecoCAN":18,"_TaxaAmostragem":1000,"RequisitarDados":true,"Conectado":false,"QuantidadeBicos":4,"DensidadeHerbicida":1.1,"BicosPulverizadores":[{"ID":"B01","ID_Num":71,"Posicao":1,"Componente":11,"AtuacaoNivelAlto":true,"ComandoAtuar":false,"Comandar":true,"Testando":false,"Funcoes":[21],"LeituraStatusBico":false,"MediaNivelFluxo":0.0,"Leitura":null,"Inicializado":false,"Atuacoes":0,"InicioAtuacao":"0001-01-01T00:00:00","TempoAtuado":0.0},{"ID":"B02","ID_Num":72,"Posicao":2,"Componente":11,"AtuacaoNivelAlto":true,"ComandoAtuar":false,"Comandar":true,"Testando":false,"Funcoes":[21],"LeituraStatusBico":false,"MediaNivelFluxo":0.0,"Leitura":null,"Inicializado":false,"Atuacoes":0,"InicioAtuacao":"0001-01-01T00:00:00","TempoAtuado":0.0},{"ID":"B03","ID_Num":73,"Posicao":3,"Componente":11,"AtuacaoNivelAlto":true,"ComandoAtuar":false,"Comandar":true,"Testando":false,"Funcoes":[21],"LeituraStatusBico":false,"MediaNivelFluxo":0.0,"Leitura":null,"Inicializado":false,"Atuacoes":0,"InicioAtuacao":"0001-01-01T00:00:00","TempoAtuado":0.0},{"ID":"B04","ID_Num":74,"Posicao":4,"Componente":11,"AtuacaoNivelAlto":true,"ComandoAtuar":false,"Comandar":true,"Testando":false,"Funcoes":[21],"LeituraStatusBico":false,"MediaNivelFluxo":0.0,"Leitura":null,"Inicializado":false,"Atuacoes":0,"InicioAtuacao":"0001-01-01T00:00:00","TempoAtuado":0.0}],"BombasPressurizadoras":[{"ID":"BOMBA","ID_Num":51,"ComandoAtuar":false,"Componente":14,"LeituraEstado":false,"Comandar":true,"Testando":false,"Funcoes":[14,5],"LeituraPotencia":0.0,"LeituraPressaoSP":0.0,"LeituraPressao":0.0,"Leitura":null,"Inicializado":false}],"Sensores":[{"LogGrafico":[],"ID":"FLXLN","ID_Num":61,"Descricao":"Fluxo na linha principal","Componente":8,"Aferir":true,"Leitura":null,"Inicializado":false,"Funcoes":[25],"Parametros":[],"UnidadeMedida":"mL/s","LimiteMaximo":0.0,"LimiteMinimo":0.0},{"LogGrafico":[],"ID":"MASRS","ID_Num":62,"Descricao":"Massa do reservatório de herbicida","Componente":10,"Aferir":true,"Leitura":null,"Inicializado":false,"Funcoes":[22,23],"Parametros":[],"UnidadeMedida":"Kg","LimiteMaximo":0.0,"LimiteMinimo":0.0},{"LogGrafico":[],"ID":"PRSLN","ID_Num":63,"Descricao":"Pressão na linha principal","Componente":12,"Aferir":true,"Leitura":null,"Inicializado":false,"Funcoes":[24],"Parametros":[{"Descricao":"Vmin","Valor":"0","QtdBytes":1,"Escalar":false,"Enviar":false},{"Descricao":"Vmax","Valor":"4.5","QtdBytes":1,"Escalar":true,"Enviar":false},{"Descricao":"Pmax","Valor":"174","QtdBytes":1,"Escalar":false,"Enviar":false}],"UnidadeMedida":"psi","LimiteMaximo":0.0,"LimiteMinimo":0.0}],"BombaPressurizadora":{"ID":"BOMBA","ID_Num":51,"ComandoAtuar":false,"Componente":14,"LeituraEstado":false,"Comandar":true,"Testando":false,"Funcoes":[14,5],"LeituraPotencia":0.0,"LeituraPressaoSP":0.0,"LeituraPressao":0.0,"Leitura":null,"Inicializado":false},"ScriptDeteccaoErvas":"weed_detector_oak-1_0.py","DadosLeitura":{"Momento":"0001-01-01T00:00:00","Conectado":false,"Dispositivo":0,"Versao":0,"Mod_ID":null,"QualidadeWifi":0,"LatenciaLoop":0,"BicosPulverizadores":[],"BombasPressurizadoras":[],"SensoresFluxo":[],"SensoresMassa":[],"SensoresPressao":[],"UltimoComandoRespondido":"0001-01-01T00:00:00"},"_MassaRef":0.8,"_MassaLeituraRef":40876.37,"_MassaLeituraExtra":1895800.0,"MassaReservatorio":0.0,"VolumeReservatorio":0.0,"PercentualReservatorio":0.0,"VolumeVazaoAferido":0.0,"_FluxoMlRef":600.0,"_FluxoPulsoRef":538.0,"VazaoFluxoMLpSInstantanea":0.0,"VazaoFluxoMLpSMedia":0.0,"VolumeVazaoML":0.0,"InicioAtuacao":"0001-01-01T00:00:00","TempoAtuado":0.0,"_PressaoVmin":0.0,"_PressaoVmax":4.5,"_PressaoMax":174.045,"PressaoLinha":0.0,"PressaoLinhaCalc":0.0,"PercentualErvasTerreno":0.0}
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -1 +1 @@
|
|||
{"ExpansorGPIO":false,"EnderecoExpansor":"","Pinos":[{"Controlador":0,"Barramento":0,"Pino":99,"Descricao":"1","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":98,"Descricao":"2","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":97,"Descricao":"3","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":4,"Descricao":"4","Funcao":22,"Habilitado":true,"ComponenteID":"MASRS"},{"Controlador":0,"Barramento":0,"Pino":5,"Descricao":"5","Funcao":23,"Habilitado":true,"ComponenteID":"MASRS"},{"Controlador":0,"Barramento":0,"Pino":6,"Descricao":"6","Funcao":24,"Habilitado":true,"ComponenteID":"PRSLN"},{"Controlador":0,"Barramento":0,"Pino":7,"Descricao":"7","Funcao":25,"Habilitado":true,"ComponenteID":"FLXLN"},{"Controlador":0,"Barramento":0,"Pino":15,"Descricao":"8","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":16,"Descricao":"9","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":17,"Descricao":"10","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":18,"Descricao":"11","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":8,"Descricao":"12","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":3,"Descricao":"13","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":46,"Descricao":"14","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":9,"Descricao":"15","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":10,"Descricao":"16","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":11,"Descricao":"17","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":12,"Descricao":"18","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":13,"Descricao":"19","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":14,"Descricao":"20","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":96,"Descricao":"21","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":95,"Descricao":"22","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":94,"Descricao":"23","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":93,"Descricao":"24","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":19,"Descricao":"25","Funcao":21,"Habilitado":true,"ComponenteID":"B01"},{"Controlador":0,"Barramento":0,"Pino":20,"Descricao":"26","Funcao":21,"Habilitado":true,"ComponenteID":"B02"},{"Controlador":0,"Barramento":0,"Pino":21,"Descricao":"27","Funcao":21,"Habilitado":true,"ComponenteID":"B03"},{"Controlador":0,"Barramento":0,"Pino":47,"Descricao":"28","Funcao":21,"Habilitado":true,"ComponenteID":"B04"},{"Controlador":0,"Barramento":0,"Pino":48,"Descricao":"29","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":45,"Descricao":"30","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":0,"Descricao":"31","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":35,"Descricao":"32","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":36,"Descricao":"33","Funcao":35,"Habilitado":true,"ComponenteID":"BOMBA"},{"Controlador":0,"Barramento":0,"Pino":37,"Descricao":"34","Funcao":37,"Habilitado":true,"ComponenteID":"BOMBA"},{"Controlador":0,"Barramento":0,"Pino":38,"Descricao":"35","Funcao":36,"Habilitado":true,"ComponenteID":"BOMBA"},{"Controlador":0,"Barramento":0,"Pino":39,"Descricao":"36","Funcao":5,"Habilitado":true,"ComponenteID":"BOMBA"},{"Controlador":0,"Barramento":0,"Pino":40,"Descricao":"37","Funcao":14,"Habilitado":true,"ComponenteID":"BOMBA"},{"Controlador":0,"Barramento":0,"Pino":41,"Descricao":"38","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":42,"Descricao":"39","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":2,"Descricao":"40","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":1,"Descricao":"41","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":44,"Descricao":"42","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":43,"Descricao":"43","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":92,"Descricao":"44","Funcao":0,"Habilitado":false,"ComponenteID":""}]}
|
||||
{"ExpansorGPIO":false,"EnderecoGPIO":"","ExpansorADS":false,"EnderecoADS":"","Pinos":[{"Controlador":0,"Barramento":0,"Pino":99,"Descricao":"1","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":98,"Descricao":"2","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":97,"Descricao":"3","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":4,"Descricao":"4","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":5,"Descricao":"5","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":6,"Descricao":"6","Funcao":24,"Habilitado":true,"ComponenteID":"PRSLN"},{"Controlador":0,"Barramento":0,"Pino":7,"Descricao":"7","Funcao":25,"Habilitado":true,"ComponenteID":"FLXLN"},{"Controlador":0,"Barramento":0,"Pino":15,"Descricao":"8","Funcao":22,"Habilitado":true,"ComponenteID":"MASRS"},{"Controlador":0,"Barramento":0,"Pino":16,"Descricao":"9","Funcao":23,"Habilitado":true,"ComponenteID":"MASRS"},{"Controlador":0,"Barramento":0,"Pino":17,"Descricao":"10","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":18,"Descricao":"11","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":8,"Descricao":"12","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":3,"Descricao":"13","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":46,"Descricao":"14","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":9,"Descricao":"15","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":10,"Descricao":"16","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":11,"Descricao":"17","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":12,"Descricao":"18","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":13,"Descricao":"19","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":14,"Descricao":"20","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":96,"Descricao":"21","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":95,"Descricao":"22","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":94,"Descricao":"23","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":93,"Descricao":"24","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":19,"Descricao":"25","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":20,"Descricao":"26","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":21,"Descricao":"27","Funcao":21,"Habilitado":true,"ComponenteID":"B01"},{"Controlador":0,"Barramento":0,"Pino":47,"Descricao":"28","Funcao":21,"Habilitado":true,"ComponenteID":"B02"},{"Controlador":0,"Barramento":0,"Pino":48,"Descricao":"29","Funcao":21,"Habilitado":true,"ComponenteID":"B03"},{"Controlador":0,"Barramento":0,"Pino":45,"Descricao":"30","Funcao":21,"Habilitado":true,"ComponenteID":"B04"},{"Controlador":0,"Barramento":0,"Pino":0,"Descricao":"31","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":35,"Descricao":"32","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":36,"Descricao":"33","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":37,"Descricao":"34","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":38,"Descricao":"35","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":39,"Descricao":"36","Funcao":5,"Habilitado":true,"ComponenteID":"BOMBA"},{"Controlador":0,"Barramento":0,"Pino":40,"Descricao":"37","Funcao":14,"Habilitado":true,"ComponenteID":"BOMBA"},{"Controlador":0,"Barramento":0,"Pino":41,"Descricao":"38","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":42,"Descricao":"39","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":2,"Descricao":"40","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":1,"Descricao":"41","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":44,"Descricao":"42","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":43,"Descricao":"43","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":0,"Barramento":0,"Pino":92,"Descricao":"44","Funcao":0,"Habilitado":false,"ComponenteID":""}]}
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -25,7 +25,7 @@
|
|||
<meta name="viewport" content="width=device-width,
|
||||
initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
||||
<style>
|
||||
#map_63de7e88b4e21b03e29d47e821dcbdd6 {
|
||||
#map_3347a224b4ed0e03a73bf2bfbd634524 {
|
||||
position: relative;
|
||||
width: 100.0%;
|
||||
height: 100.0%;
|
||||
|
|
@ -39,14 +39,14 @@
|
|||
<body>
|
||||
|
||||
|
||||
<div class="folium-map" id="map_63de7e88b4e21b03e29d47e821dcbdd6" ></div>
|
||||
<div class="folium-map" id="map_3347a224b4ed0e03a73bf2bfbd634524" ></div>
|
||||
|
||||
</body>
|
||||
<script>
|
||||
|
||||
|
||||
var map_63de7e88b4e21b03e29d47e821dcbdd6 = L.map(
|
||||
"map_63de7e88b4e21b03e29d47e821dcbdd6",
|
||||
var map_3347a224b4ed0e03a73bf2bfbd634524 = L.map(
|
||||
"map_3347a224b4ed0e03a73bf2bfbd634524",
|
||||
{
|
||||
center: [0.0, 0.0],
|
||||
crs: L.CRS.EPSG3857,
|
||||
|
|
@ -60,13 +60,13 @@
|
|||
|
||||
|
||||
|
||||
var tile_layer_9961a3b33a81e9b26bba34e095616283 = L.tileLayer(
|
||||
var tile_layer_8a418b9c4d12515117f5026207c11e69 = L.tileLayer(
|
||||
"https://tile.openstreetmap.org/{z}/{x}/{y}.png",
|
||||
{"attribution": "\u0026copy; \u003ca href=\"https://www.openstreetmap.org/copyright\"\u003eOpenStreetMap\u003c/a\u003e contributors", "detectRetina": false, "maxNativeZoom": 19, "maxZoom": 19, "minZoom": 0, "noWrap": false, "opacity": 1, "subdomains": "abc", "tms": false}
|
||||
);
|
||||
|
||||
|
||||
tile_layer_9961a3b33a81e9b26bba34e095616283.addTo(map_63de7e88b4e21b03e29d47e821dcbdd6);
|
||||
tile_layer_8a418b9c4d12515117f5026207c11e69.addTo(map_3347a224b4ed0e03a73bf2bfbd634524);
|
||||
|
||||
</script>
|
||||
|
||||
|
|
@ -87,7 +87,7 @@
|
|||
}
|
||||
trajeto_json_add({"features": []});
|
||||
|
||||
trajeto_json.addTo(map_63de7e88b4e21b03e29d47e821dcbdd6);
|
||||
trajeto_json.addTo(map_3347a224b4ed0e03a73bf2bfbd634524);
|
||||
|
||||
function adicionarGeometria(novaGeometria) {
|
||||
trajeto_json.addData(novaGeometria);
|
||||
|
|
@ -145,7 +145,7 @@
|
|||
|
||||
var marcadorDinamico = L.marker([0, 0], {
|
||||
icon: customIcon
|
||||
}).addTo(map_63de7e88b4e21b03e29d47e821dcbdd6);
|
||||
}).addTo(map_3347a224b4ed0e03a73bf2bfbd634524);
|
||||
|
||||
// Conectar ao broker MQTT
|
||||
const client = mqtt.connect('ws://localhost:9001'); // Use wss para conexão segura
|
||||
|
|
@ -183,7 +183,7 @@
|
|||
marcadorDinamico.setRotationAngle(angulo);
|
||||
|
||||
adicionarCoordenada("Tj", [novaLongitude, novaLatitude]);
|
||||
map_63de7e88b4e21b03e29d47e821dcbdd6.setView(novaPosicao, map_63de7e88b4e21b03e29d47e821dcbdd6.getZoom());
|
||||
map_3347a224b4ed0e03a73bf2bfbd634524.setView(novaPosicao, map_3347a224b4ed0e03a73bf2bfbd634524.getZoom());
|
||||
});
|
||||
|
||||
function calcularOrientacao(P1latitude, P1longitude, P2latitude, P2longitude) {
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,451 @@
|
|||
// Dispositivo: Atuador
|
||||
// Versão Firmware: 9
|
||||
// Ultima atualização: 10/04/2025
|
||||
// Atualização: Implementado comunicacao CAN
|
||||
|
||||
#include "C:\ZendionInc\agrobot_base\Firmware\Modulos\SerialService.h"
|
||||
#include "C:\ZendionInc\agrobot_base\Firmware\Modulos\CanService.h"
|
||||
#include "C:\ZendionInc\agrobot_base\Firmware\Modulos\EepromService.h"
|
||||
#include "C:\ZendionInc\agrobot_base\Firmware\Modulos\Utils.h"
|
||||
#include "C:\ZendionInc\agrobot_base\Firmware\Modulos\Pinout.h"
|
||||
#include "C:\ZendionInc\agrobot_base\Firmware\Modulos\ReleModel.h"
|
||||
#include "C:\ZendionInc\agrobot_base\Firmware\Modulos\BombaPressurizadoraModel.h"
|
||||
#include "C:\ZendionInc\agrobot_base\Firmware\Modulos\SensorFluxoModel.h"
|
||||
#include "C:\ZendionInc\agrobot_base\Firmware\Modulos\SensorMassaModel.h"
|
||||
#include "C:\ZendionInc\agrobot_base\Firmware\Modulos\SensorPressaoModel.h"
|
||||
|
||||
|
||||
// Configurações do CAN
|
||||
uint8_t CanID = 0x12;
|
||||
CanService canService = CanService(CanID);
|
||||
|
||||
#define D_Code Atu
|
||||
int VERSION = 9;
|
||||
const String Mod_ID = "Atu";
|
||||
|
||||
#define _pinoLED RGB_BUILTIN
|
||||
|
||||
bool Conectado = false;
|
||||
bool Verificando = false;
|
||||
|
||||
int _TaxaAmostragem = 1000;
|
||||
volatile bool RequisitarDados = false;
|
||||
int latenciaLoop = 0;
|
||||
|
||||
|
||||
std::vector<Rele*> listaBicos;
|
||||
std::vector<BombaPressurizadora*> listaBombas;
|
||||
std::vector<SensorFluxo*> listaSensoresFluxo;
|
||||
std::vector<SensorMassa*> listaSensoresMassa;
|
||||
std::vector<SensorPressao*> listaSensoresPressao;
|
||||
|
||||
|
||||
void setup() {
|
||||
delay(5000);
|
||||
|
||||
// Registrar callback para processar mensagens CAN recebidas
|
||||
canService.setReceiveCallback([](int packetSize, int senderId, byte funcCode, byte* data, int dataLength) {
|
||||
std::vector<uint8_t> fullData;
|
||||
fullData.push_back(funcCode); // Primeiro byte é sempre o funcCode
|
||||
for (int i = 0; i < dataLength; i++) {
|
||||
fullData.push_back(data[i]);
|
||||
}
|
||||
|
||||
ProcessarFrameCAN(fullData);
|
||||
});
|
||||
|
||||
canService.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
unsigned long startLoop = millis();
|
||||
|
||||
if (!RequisitarDados) {
|
||||
enviarLogsPeriodicamente();
|
||||
}
|
||||
|
||||
canService.loop();
|
||||
|
||||
for (auto* bomba : listaBombas) {
|
||||
bomba->Loop();
|
||||
}
|
||||
for (auto* sensor : listaSensoresFluxo) {
|
||||
sensor->Loop();
|
||||
}
|
||||
|
||||
delay(1);
|
||||
|
||||
latenciaLoop = millis() - startLoop;
|
||||
}
|
||||
|
||||
// Função para enviar logs do sensor periodicamente
|
||||
unsigned long ultimoEnvioLogs = 0;
|
||||
const unsigned long intervaloEnvioLogs = 1000; // 1 segundo
|
||||
void enviarLogsPeriodicamente() {
|
||||
unsigned long tempoAtual = millis();
|
||||
// Verifica se o intervalo de 5 segundos já passou
|
||||
if (tempoAtual - ultimoEnvioLogs >= intervaloEnvioLogs) {
|
||||
ultimoEnvioLogs = tempoAtual; // Atualiza o tempo do último envio
|
||||
|
||||
enviarDadosSensores(); // Chama o método que já envia os dados do sensor via MQTT
|
||||
}
|
||||
}
|
||||
|
||||
void enviarDadosSensores() {
|
||||
if (Conectado && !Verificando) {
|
||||
PrintTela("Atualizando dados dos sensores...");
|
||||
|
||||
// Aferir dados dos sensores
|
||||
for (auto* bico : listaBicos) {
|
||||
if (bico != nullptr) {
|
||||
bico->RequisitarDados();
|
||||
EnviarDadosCAN(static_cast<uint8_t>(S_Code::sBIC), bico->MontarMensagemCAN());
|
||||
}
|
||||
}
|
||||
|
||||
// Aferir dados dos sensores
|
||||
for (auto* sensor : listaSensoresFluxo) {
|
||||
if (sensor != nullptr) {
|
||||
sensor->RequisitarDados();
|
||||
EnviarDadosCAN(static_cast<uint8_t>(S_Code::sFLX), sensor->MontarMensagemCAN());
|
||||
}
|
||||
}
|
||||
|
||||
// Aferir dados dos sensores
|
||||
for (auto* sensor : listaSensoresMassa) {
|
||||
if (sensor != nullptr) {
|
||||
sensor->RequisitarDados();
|
||||
EnviarDadosCAN(static_cast<uint8_t>(S_Code::sMAS), sensor->MontarMensagemCAN());
|
||||
}
|
||||
}
|
||||
|
||||
// Aferir dados dos sensores
|
||||
for (auto* sensor : listaSensoresPressao) {
|
||||
if (sensor != nullptr) {
|
||||
sensor->RequisitarDados();
|
||||
EnviarDadosCAN(static_cast<uint8_t>(S_Code::sPRS), sensor->MontarMensagemCAN());
|
||||
}
|
||||
}
|
||||
|
||||
// Aferir dados dos sensores
|
||||
for (auto* bomba : listaBombas) {
|
||||
if (bomba != nullptr) {
|
||||
bomba->RequisitarDados();
|
||||
EnviarDadosCAN(static_cast<uint8_t>(S_Code::sBMB), bomba->MontarMensagemCAN());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void EnviarDadosCAN(uint8_t f_code, std::vector<uint8_t> data) {
|
||||
canService.enviarMensagem(f_code, data);
|
||||
}
|
||||
|
||||
|
||||
void ProcessarFrameCAN(std::vector<uint8_t> data) {
|
||||
if (data.size() < 1) return;
|
||||
|
||||
F_Code funcao = (F_Code)data[0];
|
||||
|
||||
switch (funcao) {
|
||||
case ChkTx: ProcessarChk(); break;
|
||||
case ReqTx: ProcessarReq(); break;
|
||||
case CmdTx: ProcessarCmd(data); break;
|
||||
case CfgTx: ProcessarCfg(data); break;
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessarChk() {
|
||||
Verificando = true;
|
||||
std::vector<uint8_t> data = canService.MontarFrameChk(D_Code, Conectado, VERSION);
|
||||
EnviarDadosCAN(static_cast<uint8_t>(F_Code::ChkRx), data);
|
||||
Verificando = false;
|
||||
}
|
||||
|
||||
void ProcessarReq() {
|
||||
enviarDadosSensores();
|
||||
}
|
||||
|
||||
void ProcessarCfg(std::vector<uint8_t> data) {
|
||||
S_Code sensorTipo = (S_Code)data[1];
|
||||
|
||||
switch (sensorTipo) {
|
||||
case sMOD: {
|
||||
if (data.size() < 7) return;
|
||||
bool conectar = data[2] == 1;
|
||||
int taxa = data[3] * 10;
|
||||
bool requisitar = data[4] == 1;
|
||||
int pinoSDA = data[5];
|
||||
int pinoSCL = data[6];
|
||||
|
||||
if (pinoSDA != PINO_INVALIDO && pinoSCL != PINO_INVALIDO) {
|
||||
//_pinoSDA = PinoModel(pinoSDA, CONTROLADOR, _INPUT);
|
||||
//_pinoSCL = PinoModel(pinoSCL, CONTROLADOR, _INPUT);
|
||||
|
||||
//Wire.end();
|
||||
//Wire.begin(_pinoSDA.num, _pinoSCL.num);
|
||||
|
||||
//PrintTela("I2C inicializado nos pinos SDA=" + String(pinoSDA) + " e SCL=" + String(pinoSCL));
|
||||
}
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
_TaxaAmostragem = taxa;
|
||||
RequisitarDados = requisitar;
|
||||
Verificando = false;
|
||||
Conectado = conectar;
|
||||
|
||||
ProcessarChk();
|
||||
|
||||
LimparListasComponentes();
|
||||
|
||||
PrintTela("Configuracao do modulo concluida");
|
||||
|
||||
break;
|
||||
}
|
||||
case sBIC: {
|
||||
if (data.size() < 7) return;
|
||||
uint8_t idNum = data[2];
|
||||
bool conectar = data[3] == 1;
|
||||
bool atuacaoNivelAlto = data[4] == 1;
|
||||
TiposBarramentos tipoBarramento = (TiposBarramentos)data[5];
|
||||
int pino = data[6];
|
||||
auto it = std::find_if(listaBicos.begin(), listaBicos.end(),
|
||||
[idNum](Rele* s) { return s->ID_Num == idNum; });
|
||||
if (conectar) {
|
||||
if (it == listaBicos.end()) {
|
||||
Rele* sensor = new Rele(Mod_ID, "sBIC_" + String(idNum));
|
||||
sensor->ID_Num = idNum;
|
||||
sensor->_pino = PinoModel(pino, tipoBarramento, _OUTPUT);
|
||||
sensor->AtuacaoNivelAlto = atuacaoNivelAlto;
|
||||
sensor->Inicializar();
|
||||
listaBicos.push_back(sensor);
|
||||
PrintTela("Rele adicionado via CAN: sBIC_" + String(idNum));
|
||||
}
|
||||
} else {
|
||||
if (it != listaBicos.end()) {
|
||||
Rele* sensor = *it;
|
||||
sensor->Desligar();
|
||||
delete sensor;
|
||||
listaBicos.erase(it);
|
||||
PrintTela("Bico removido via CAN: sBIC_" + String(idNum));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case sFLX: {
|
||||
if (data.size() < 6) return;
|
||||
uint8_t idNum = data[2];
|
||||
bool conectar = data[3] == 1;
|
||||
TiposBarramentos tipoBarramento = (TiposBarramentos)data[4];
|
||||
int pino = data[5];
|
||||
auto it = std::find_if(listaSensoresFluxo.begin(), listaSensoresFluxo.end(),
|
||||
[idNum](SensorFluxo* s) { return s->ID_Num == idNum; });
|
||||
if (conectar) {
|
||||
if (it == listaSensoresFluxo.end()) {
|
||||
SensorFluxo* sensor = new SensorFluxo(Mod_ID, "sFLX_" + String(idNum));
|
||||
sensor->ID_Num = idNum;
|
||||
sensor->_pino = PinoModel(pino, tipoBarramento, _INPUT, DIGITAL);
|
||||
sensor->Inicializar();
|
||||
listaSensoresFluxo.push_back(sensor);
|
||||
PrintTela("Sensor de Fluxo adicionado via CAN: sFLX_" + String(idNum));
|
||||
}
|
||||
} else {
|
||||
if (it != listaSensoresFluxo.end()) {
|
||||
SensorFluxo* sensor = *it;
|
||||
sensor->Desligar();
|
||||
delete sensor;
|
||||
listaSensoresFluxo.erase(it);
|
||||
PrintTela("Sensor de Fluxo removido via CAN: sFLX_" + String(idNum));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case sPRS: {
|
||||
if (data.size() < 6) return;
|
||||
uint8_t idNum = data[2];
|
||||
bool conectar = data[3] == 1;
|
||||
TiposBarramentos tipoBarramento = (TiposBarramentos)data[4];
|
||||
int pino = data[5];
|
||||
auto it = std::find_if(listaSensoresPressao.begin(), listaSensoresPressao.end(),
|
||||
[idNum](SensorPressao* s) { return s->ID_Num == idNum; });
|
||||
if (conectar) {
|
||||
if (it == listaSensoresPressao.end()) {
|
||||
SensorPressao* sensor = new SensorPressao(Mod_ID, "sPRS_" + String(idNum));
|
||||
sensor->ID_Num = idNum;
|
||||
sensor->_pino = PinoModel(pino, tipoBarramento, _INPUT, ANALOGICO);
|
||||
sensor->Inicializar();
|
||||
listaSensoresPressao.push_back(sensor);
|
||||
PrintTela("Sensor de Pressao adicionado via CAN: sPRS_" + String(idNum));
|
||||
}
|
||||
} else {
|
||||
if (it != listaSensoresPressao.end()) {
|
||||
SensorPressao* sensor = *it;
|
||||
sensor->Desligar();
|
||||
delete sensor;
|
||||
listaSensoresPressao.erase(it);
|
||||
PrintTela("Sensor de Pressao removido via CAN: sPRS_" + String(idNum));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case sMAS: {
|
||||
if (data.size() < 6) return;
|
||||
uint8_t idNum = data[2];
|
||||
bool conectar = data[3] == 1;
|
||||
int pinoDt = data[4];
|
||||
int pinoSck = data[5];
|
||||
//uint16_t offsetInt = ((uint16_t)data[6] << 8) | data[7];
|
||||
//float offset = offsetInt / 100.0;
|
||||
|
||||
auto it = std::find_if(listaSensoresMassa.begin(), listaSensoresMassa.end(),
|
||||
[idNum](SensorMassa* s) { return s->ID_Num == idNum; });
|
||||
if (conectar) {
|
||||
if (it == listaSensoresMassa.end()) {
|
||||
SensorMassa* sensor = new SensorMassa(Mod_ID, "sMAS_" + String(idNum));
|
||||
sensor->ID_Num = idNum;
|
||||
sensor->_pinoDT = PinoModel(pinoDt, CONTROLADOR, _INPUT, DIGITAL);
|
||||
sensor->_pinoSCK = PinoModel(pinoSck, CONTROLADOR, _OUTPUT);
|
||||
//sensor->_Offset = offset;
|
||||
sensor->Inicializar();
|
||||
listaSensoresMassa.push_back(sensor);
|
||||
PrintTela("Sensor de Massa adicionado via CAN: sMAS_" + String(idNum));
|
||||
}
|
||||
} else {
|
||||
if (it != listaSensoresMassa.end()) {
|
||||
SensorMassa* sensor = *it;
|
||||
sensor->Desligar();
|
||||
delete sensor;
|
||||
listaSensoresMassa.erase(it);
|
||||
PrintTela("Sensor de Massa removido via CAN: sMAS_" + String(idNum));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case sBMB: {
|
||||
if (data.size() < 7) return;
|
||||
uint8_t idNum = data[2];
|
||||
bool conectar = data[3] == 1;
|
||||
int pressaoSp = (int)data[4];
|
||||
int pinoEn = data[5];
|
||||
int pinoPwm = data[6];
|
||||
|
||||
auto it = std::find_if(listaBombas.begin(), listaBombas.end(),
|
||||
[idNum](BombaPressurizadora* s) { return s->ID_Num == idNum; });
|
||||
if (conectar) {
|
||||
if (it == listaBombas.end()) {
|
||||
BombaPressurizadora* bomba = new BombaPressurizadora(Mod_ID, "sBMB_" + String(idNum));
|
||||
|
||||
if (listaSensoresPressao.size() > 0) {
|
||||
if (listaSensoresPressao[0]->Iniciado) {
|
||||
bomba->sensorPressao = listaSensoresPressao[0];
|
||||
}
|
||||
}
|
||||
if (bomba->sensorPressao == nullptr) {
|
||||
PrintTela("Nenhum sensor de pressão disponível para associar à bomba.");
|
||||
delete bomba;
|
||||
return;
|
||||
}
|
||||
|
||||
bomba->ID_Num = idNum;
|
||||
bomba->_pinoEN = PinoModel(pinoEn, CONTROLADOR, _OUTPUT);
|
||||
bomba->_pinoPWM = PinoModel(pinoPwm, CONTROLADOR, _PWM);
|
||||
bomba->_PressaoSP = (double)pressaoSp;
|
||||
|
||||
bomba->Inicializar();
|
||||
listaBombas.push_back(bomba);
|
||||
PrintTela("Bomba Pressurizadora adicionado via CAN: sBMB_" + String(idNum));
|
||||
}
|
||||
} else {
|
||||
if (it != listaBombas.end()) {
|
||||
BombaPressurizadora* bomba = *it;
|
||||
bomba->Desligar();
|
||||
delete bomba;
|
||||
listaBombas.erase(it);
|
||||
PrintTela("Bomba Pressurizadora removido via CAN: sBMB_" + String(idNum));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void ProcessarCmd(std::vector<uint8_t> data) {
|
||||
if (data.size() < 3) return;
|
||||
|
||||
S_Code componente = (S_Code)data[1];
|
||||
uint8_t id = data[2];
|
||||
|
||||
switch (componente) {
|
||||
case sBIC: {
|
||||
if (data.size() < 4) return;
|
||||
for (auto* _rele : listaBicos) {
|
||||
if (_rele != nullptr) {
|
||||
if (_rele->ID_Num == id) {
|
||||
_rele->AtualizarStatus((Estado)data[3]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case sBMB: {
|
||||
if (data.size() < 6) return;
|
||||
|
||||
Estado novoEstado = (Estado)data[3];
|
||||
int pressao = (int)data[4];
|
||||
|
||||
for (auto* _bomba : listaBombas) {
|
||||
if (_bomba && _bomba->ID_Num == id) {
|
||||
_bomba->_EstadoControle = novoEstado;
|
||||
_bomba->_PressaoSP = (double)pressao;
|
||||
_bomba->AlterarStatusBomba();
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void LimparListasComponentes() {
|
||||
for (auto* bico : listaBicos) {
|
||||
bico->Desligar();
|
||||
PrintTela("Bico " + bico->_ID + " desligado.");
|
||||
delete bico;
|
||||
}
|
||||
listaBicos.clear();
|
||||
|
||||
for (auto* bomba : listaBombas) {
|
||||
bomba->Desligar();
|
||||
PrintTela("Bomba Pressurizadora " + bomba->_ID + " desligada.");
|
||||
delete bomba;
|
||||
}
|
||||
listaBombas.clear();
|
||||
|
||||
for (auto* sensor : listaSensoresFluxo) {
|
||||
sensor->Desligar();
|
||||
PrintTela("Sensor de Fluxo " + sensor->_ID + " desligado.");
|
||||
delete sensor;
|
||||
}
|
||||
listaSensoresFluxo.clear();
|
||||
|
||||
for (auto* sensor : listaSensoresMassa) {
|
||||
sensor->Desligar();
|
||||
PrintTela("Sensor de Massa " + sensor->_ID + " desligado.");
|
||||
delete sensor;
|
||||
}
|
||||
listaSensoresMassa.clear();
|
||||
|
||||
for (auto* sensor : listaSensoresPressao) {
|
||||
sensor->Desligar();
|
||||
PrintTela("Sensor de Pressao " + sensor->_ID + " desligado.");
|
||||
delete sensor;
|
||||
}
|
||||
listaSensoresPressao.clear();
|
||||
}
|
||||
|
|
@ -19,6 +19,7 @@ class BombaPressurizadora {
|
|||
|
||||
String Mod_ID;
|
||||
String _ID;
|
||||
int ID_Num;
|
||||
PinoModel _pinoEN;
|
||||
PinoModel _pinoCS;
|
||||
PinoModel _pinoINA;
|
||||
|
|
@ -26,9 +27,9 @@ class BombaPressurizadora {
|
|||
PinoModel _pinoPWM;
|
||||
int _canal = 0;
|
||||
|
||||
double _Kp = 3.0;
|
||||
double _Ki = 2.2;
|
||||
double _Kd = 0.5;
|
||||
float _Kp = 3.0;
|
||||
float _Ki = 2.2;
|
||||
float _Kd = 0.5;
|
||||
const int histerese = 3;
|
||||
bool bombaDesligadaPorPressao = false;
|
||||
PID* _PID = nullptr;
|
||||
|
|
@ -54,10 +55,15 @@ class BombaPressurizadora {
|
|||
PrintTela(_ID + " ja inicializado");
|
||||
return;
|
||||
}
|
||||
|
||||
if (sensorPressao == nullptr) {
|
||||
PrintTela("Sensor de pressao nao definido, bomba nao sera inicializada");
|
||||
Iniciado = false;
|
||||
return;
|
||||
}
|
||||
|
||||
_EstadoControle = Desligado;
|
||||
_pinoEN.Conectar(_EstadoControle);
|
||||
AtualizarLeitura();
|
||||
_pinoCS.Conectar();
|
||||
_pinoINA.Conectar(false);
|
||||
_pinoINB.Conectar(true);
|
||||
|
|
@ -69,13 +75,20 @@ class BombaPressurizadora {
|
|||
ledcWrite(_canal, _PressaoSP);
|
||||
}
|
||||
|
||||
_PID = new PID(&sensorPressao->Pressao, &PotenciaLeitura, &_PressaoSP, _Kp, _Ki, _Kd, DIRECT);
|
||||
_PID->SetOutputLimits(ZeroRampa, RampaMax);
|
||||
_PID->SetMode(AUTOMATIC);
|
||||
Iniciado = _pinoEN.Definido() && _pinoPWM.Definido();
|
||||
|
||||
PrintTela(_ID + " Iniciado");
|
||||
|
||||
Iniciado = true;
|
||||
AtualizarLeitura();
|
||||
|
||||
if (Iniciado) {
|
||||
_PID = new PID(&sensorPressao->Pressao, &PotenciaLeitura, &_PressaoSP, _Kp, _Ki, _Kd, DIRECT);
|
||||
_PID->SetOutputLimits(ZeroRampa, RampaMax);
|
||||
_PID->SetMode(AUTOMATIC);
|
||||
|
||||
PrintTela(_ID + " iniciado");
|
||||
}
|
||||
else {
|
||||
PrintTela(_ID + " nao iniciado");
|
||||
}
|
||||
}
|
||||
|
||||
void Desligar() {
|
||||
|
|
@ -86,6 +99,8 @@ class BombaPressurizadora {
|
|||
|
||||
delete _PID;
|
||||
_PID = nullptr;
|
||||
delete sensorPressao;
|
||||
sensorPressao = nullptr;
|
||||
|
||||
// Redefinir as configurações para os valores iniciais
|
||||
_pinoPWM.Desconectar();
|
||||
|
|
@ -100,22 +115,19 @@ class BombaPressurizadora {
|
|||
Iniciado = false;
|
||||
}
|
||||
|
||||
void AtualizarLeitura() {
|
||||
EstadoLeitura = _pinoEN.get() == 1 ? Ligado : Desligado;
|
||||
PercentualPotenciaLeitura = (PotenciaLeitura / RampaMax) * 100;
|
||||
}
|
||||
|
||||
void AlterarStatusBomba() {
|
||||
bool status = _EstadoControle == Ligado;
|
||||
if (Iniciado) {
|
||||
bool status = _EstadoControle == Ligado;
|
||||
|
||||
_pinoEN.set(status);
|
||||
|
||||
AtualizarLeitura();
|
||||
_pinoEN.set(status);
|
||||
|
||||
AtualizarLeitura();
|
||||
}
|
||||
}
|
||||
|
||||
void Loop() {
|
||||
if (Iniciado && sensorPressao != nullptr) {
|
||||
sensorPressao->AferirPressao();
|
||||
if (Iniciado) {
|
||||
sensorPressao->RequisitarDados();
|
||||
double _PressaoAtual = sensorPressao->Pressao; // Obtém a leitura mais recente
|
||||
|
||||
if (_PressaoAtual >= (_PressaoSP + histerese)) {
|
||||
|
|
@ -138,6 +150,34 @@ class BombaPressurizadora {
|
|||
}
|
||||
}
|
||||
|
||||
void RequisitarDados() {
|
||||
|
||||
}
|
||||
|
||||
std::vector<uint8_t> MontarMensagemCAN() {
|
||||
std::vector<uint8_t> data;
|
||||
|
||||
data.push_back(ID_Num); // Byte 0 - ID do sensor
|
||||
data.push_back(Iniciado ? 1 : 0); // Byte 1 - Status
|
||||
|
||||
data.push_back(EstadoLeitura);
|
||||
data.push_back(PercentualPotenciaLeitura);
|
||||
data.push_back((int)_PressaoSP);
|
||||
data.push_back((int)sensorPressao->Pressao);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
void AtualizarLeitura() {
|
||||
if (Iniciado) {
|
||||
EstadoLeitura = _pinoEN.get() == 1 ? Ligado : Desligado;
|
||||
PercentualPotenciaLeitura = (PotenciaLeitura / RampaMax) * 100;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ class Rele {
|
|||
std::vector<uint8_t> data;
|
||||
data.push_back(ID_Num);
|
||||
data.push_back(Iniciado ? 1 : 0);
|
||||
data.push_back(_Status ? 1 : 0);
|
||||
data.push_back(_Status);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ class SensorFluxo {
|
|||
// Definições
|
||||
String Mod_ID = "";
|
||||
String _ID;
|
||||
int ID_Num;
|
||||
PinoModel _pino;
|
||||
|
||||
unsigned long tempoAnterior = 0;
|
||||
|
|
@ -29,6 +30,7 @@ class SensorFluxo {
|
|||
// Consumo
|
||||
unsigned int _PulsosLeitura = 0;
|
||||
unsigned long _PeriodoTotalLeitura = 0;
|
||||
float _Vazao = 0;
|
||||
|
||||
void Inicializar() {
|
||||
if (Iniciado) {
|
||||
|
|
@ -38,11 +40,16 @@ class SensorFluxo {
|
|||
|
||||
_pino.Conectar();
|
||||
|
||||
ResetarEstado();
|
||||
|
||||
PrintTela(_ID + " Iniciado");
|
||||
Iniciado = _pino.Definido();
|
||||
|
||||
Iniciado = true;
|
||||
if (Iniciado) {
|
||||
ResetarEstado();
|
||||
|
||||
PrintTela(_ID + " iniciado");
|
||||
}
|
||||
else {
|
||||
PrintTela(_ID + " nao iniciado");
|
||||
}
|
||||
}
|
||||
|
||||
void Desligar() {
|
||||
|
|
@ -61,16 +68,10 @@ class SensorFluxo {
|
|||
Iniciado = false;
|
||||
}
|
||||
|
||||
void AtualizarLeitura() {
|
||||
_PulsosLeitura = _Pulsos;
|
||||
_PeriodoTotalLeitura = _PeriodoTotal;
|
||||
|
||||
ReiniciarAmostragem();
|
||||
void RequisitarDados() {
|
||||
AtualizarLeitura();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Método principal de leitura
|
||||
void Loop() {
|
||||
if (Iniciado) {
|
||||
bool Leitura = _pino.get() == 1;
|
||||
|
|
@ -89,7 +90,33 @@ class SensorFluxo {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
std::vector<uint8_t> MontarMensagemCAN() {
|
||||
std::vector<uint8_t> data;
|
||||
|
||||
data.push_back(ID_Num); // Byte 0 - ID do sensor
|
||||
data.push_back(Iniciado ? 1 : 0); // Byte 1 - Status
|
||||
|
||||
uint16_t vazaoEscalada = (uint16_t)(_Vazao * 100);
|
||||
data.push_back(vazaoEscalada >> 8);
|
||||
data.push_back(vazaoEscalada & 0xFF);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
void AtualizarLeitura() {
|
||||
if (Iniciado) {
|
||||
_PulsosLeitura = _Pulsos;
|
||||
_PeriodoTotalLeitura = _PeriodoTotal;
|
||||
_Vazao = CalcularVazao(_Pulsos, _PeriodoTotal);
|
||||
|
||||
ReiniciarAmostragem();
|
||||
}
|
||||
}
|
||||
|
||||
// Reseta o estado do sensor
|
||||
void ResetarEstado() {
|
||||
_Pulsos = 0;
|
||||
|
|
@ -105,6 +132,19 @@ class SensorFluxo {
|
|||
_PeriodoTotal = 0;
|
||||
}
|
||||
|
||||
float CalcularVazao(uint16_t pulsos, unsigned long periodoMs) {
|
||||
if (periodoMs == 0) return 0;
|
||||
|
||||
float frequencia = (float)pulsos / (float)periodoMs * 1000.0; // Hz
|
||||
const float Rh = 0.0047; // raio interno do tubo
|
||||
const float Rt = 0.0037; // raio interno do rotor
|
||||
|
||||
float vazao_m3s = frequencia * 2.0 * PI * Rh * PI * (Rt * Rt); // m³/s
|
||||
float vazao_ml_s = vazao_m3s * 1e6; // ml/s
|
||||
|
||||
return vazao_ml_s;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -19,13 +19,19 @@ class SensorMassa {
|
|||
|
||||
String Mod_ID;
|
||||
String _ID;
|
||||
int ID_Num;
|
||||
PinoModel _pinoDT;
|
||||
PinoModel _pinoSCK;
|
||||
|
||||
float _Offset = 1895800.0;
|
||||
float _MassaRef = 0.8;
|
||||
float _MassaLeituraRef = 40876.37;
|
||||
|
||||
HX711 balanca = HX711();
|
||||
SimpleKalmanFilter filtro = SimpleKalmanFilter(2, 2, 0.01);
|
||||
|
||||
double leituraMassa = 0;
|
||||
float Massa = 0;
|
||||
|
||||
bool Iniciado = false;
|
||||
|
||||
|
|
@ -42,7 +48,10 @@ class SensorMassa {
|
|||
|
||||
Iniciado = true;
|
||||
|
||||
PrintTela(_ID + " Iniciado");
|
||||
PrintTela(_ID + " iniciado");
|
||||
}
|
||||
else {
|
||||
PrintTela(_ID + " nao iniciado");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -61,15 +70,43 @@ class SensorMassa {
|
|||
Iniciado = false;
|
||||
}
|
||||
|
||||
void AferirMassa() {
|
||||
float leitura = balanca.get_units(5);
|
||||
leituraMassa = filtro.updateEstimate(leitura);
|
||||
}
|
||||
|
||||
void RequisitarDados() {
|
||||
AferirMassa();
|
||||
}
|
||||
|
||||
std::vector<uint8_t> MontarMensagemCAN() {
|
||||
std::vector<uint8_t> data;
|
||||
|
||||
data.push_back(ID_Num); // Byte 0 - ID do sensor
|
||||
data.push_back(Iniciado ? 1 : 0); // Byte 1 - Status
|
||||
|
||||
uint16_t massaEscalada = (uint16_t)(Massa * 100);
|
||||
data.push_back(massaEscalada >> 8);
|
||||
data.push_back(massaEscalada & 0xFF);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private:
|
||||
void AferirMassa() {
|
||||
if (Iniciado) {
|
||||
float leitura = balanca.get_units(5);
|
||||
leituraMassa = filtro.updateEstimate(leitura);
|
||||
Massa = CalcularMassa(leituraMassa);
|
||||
}
|
||||
}
|
||||
|
||||
float CalcularMassa(float _leitura) {
|
||||
double leituraMassa = _leitura * -1;
|
||||
leituraMassa += _Offset;
|
||||
|
||||
float FatorLeitura = _MassaRef / _MassaLeituraRef;
|
||||
float massa = FatorLeitura * leituraMassa;
|
||||
return massa;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ class SensorPressao {
|
|||
// Definições
|
||||
String Mod_ID = "";
|
||||
String _ID;
|
||||
int ID_Num;
|
||||
PinoModel _pino;
|
||||
|
||||
double _Vmin = 0.0;
|
||||
|
|
@ -42,9 +43,14 @@ class SensorPressao {
|
|||
|
||||
_pino.Conectar(); // Conecta o pino antes de criar a tarefa
|
||||
|
||||
Iniciado = true;
|
||||
Iniciado = _pino.Definido();
|
||||
|
||||
PrintTela(_ID + " Iniciado");
|
||||
if (Iniciado) {
|
||||
PrintTela(_ID + " iniciado");
|
||||
}
|
||||
else {
|
||||
PrintTela(_ID + " nao iniciado");
|
||||
}
|
||||
}
|
||||
|
||||
void Desligar() {
|
||||
|
|
@ -60,17 +66,34 @@ class SensorPressao {
|
|||
PrintTela(_ID + " Desligado");
|
||||
}
|
||||
|
||||
void AferirPressao() {
|
||||
leitura = _pino.get();
|
||||
double leituraPressao = filtro.updateEstimate(leitura);
|
||||
|
||||
double tensao = fmap(leituraPressao, 0.0, 4095.0, 0.0, 3300.0) / 1000.0;
|
||||
Pressao = fmap(tensao, _Vmin, _Vmax, 0.0, _Pmax);
|
||||
}
|
||||
|
||||
void RequisitarDados() {
|
||||
AferirPressao();
|
||||
}
|
||||
|
||||
std::vector<uint8_t> MontarMensagemCAN() {
|
||||
std::vector<uint8_t> data;
|
||||
|
||||
data.push_back(ID_Num); // Byte 0 - ID do sensor
|
||||
data.push_back(Iniciado ? 1 : 0); // Byte 1 - Status
|
||||
|
||||
uint16_t pressaoEscalada = (uint16_t)(Pressao * 100);
|
||||
data.push_back(pressaoEscalada >> 8);
|
||||
data.push_back(pressaoEscalada & 0xFF);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
void AferirPressao() {
|
||||
if (Iniciado) {
|
||||
leitura = _pino.get();
|
||||
double leituraPressao = filtro.updateEstimate(leitura);
|
||||
|
||||
double tensao = fmap(leituraPressao, 0.0, 4095.0, 0.0, 3300.0) / 1000.0;
|
||||
Pressao = fmap(tensao, _Vmin, _Vmax, 0.0, _Pmax);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -78,8 +78,8 @@ class Sinaleiro {
|
|||
std::vector<uint8_t> data;
|
||||
data.push_back(ID_Num);
|
||||
data.push_back(Iniciado ? 1 : 0);
|
||||
data.push_back(_StatusLeitura ? 1 : 0);
|
||||
data.push_back(_Status ? 1 : 0);
|
||||
data.push_back(_StatusLeitura);
|
||||
data.push_back(_Status);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,9 +33,7 @@ int _TaxaAmostragem = 1000;
|
|||
volatile bool RequisitarDados = false;
|
||||
int latenciaLoop = 0;
|
||||
|
||||
//PinoModel _pinoSDA = PinoModel(21, CONTROLADOR, _INPUT);
|
||||
PinoModel _pinoSDA = PinoModel(1, CONTROLADOR, _INPUT);
|
||||
//PinoModel _pinoSCL = PinoModel(22, CONTROLADOR, _INPUT);
|
||||
PinoModel _pinoSCL = PinoModel(2, CONTROLADOR, _INPUT);
|
||||
|
||||
|
||||
|
|
@ -81,7 +79,7 @@ void loop() {
|
|||
latenciaLoop = millis() - startLoop;
|
||||
}
|
||||
|
||||
// Função para enviar logs do sensor periodicamente via MQTT
|
||||
// Função para enviar logs do sensor periodicamente
|
||||
unsigned long ultimoEnvioLogs = 0;
|
||||
const unsigned long intervaloEnvioLogs = 1000; // 1 segundo
|
||||
void enviarLogsPeriodicamente() {
|
||||
|
|
@ -103,9 +101,6 @@ void enviarDadosSensores() {
|
|||
sensor->RequisitarDados();
|
||||
EnviarDadosCAN(static_cast<uint8_t>(S_Code::sTMP), sensor->MontarMensagemCAN());
|
||||
}
|
||||
else {
|
||||
PrintTela("Sensor sTMP invalido");
|
||||
}
|
||||
}
|
||||
|
||||
for (auto* sensor : listaSensoresCorrente) {
|
||||
|
|
@ -113,9 +108,6 @@ void enviarDadosSensores() {
|
|||
sensor->RequisitarDados();
|
||||
EnviarDadosCAN(static_cast<uint8_t>(S_Code::sCOR), sensor->MontarMensagemCAN());
|
||||
}
|
||||
else {
|
||||
PrintTela("Sensor sCOR invalido");
|
||||
}
|
||||
}
|
||||
|
||||
for (auto* sensor : listaSinaleiros) {
|
||||
|
|
@ -123,9 +115,6 @@ void enviarDadosSensores() {
|
|||
sensor->RequisitarDados();
|
||||
EnviarDadosCAN(static_cast<uint8_t>(S_Code::sLED), sensor->MontarMensagemCAN());
|
||||
}
|
||||
else {
|
||||
PrintTela("Sensor sLED invalido");
|
||||
}
|
||||
}
|
||||
|
||||
for (auto* sensor : listaReles) {
|
||||
|
|
@ -133,9 +122,6 @@ void enviarDadosSensores() {
|
|||
sensor->RequisitarDados();
|
||||
EnviarDadosCAN(static_cast<uint8_t>(S_Code::sRLE), sensor->MontarMensagemCAN());
|
||||
}
|
||||
else {
|
||||
PrintTela("Sensor sRLE invalido");
|
||||
}
|
||||
}
|
||||
|
||||
for (auto* sensor : listaServoFreios) {
|
||||
|
|
@ -143,9 +129,6 @@ void enviarDadosSensores() {
|
|||
sensor->RequisitarDados();
|
||||
EnviarDadosCAN(static_cast<uint8_t>(S_Code::sFRO), sensor->MontarMensagemCAN());
|
||||
}
|
||||
else {
|
||||
PrintTela("Sensor sFRO invalido");
|
||||
}
|
||||
}
|
||||
|
||||
for (auto* sensor : listaSensoresPotenciometros) {
|
||||
|
|
@ -153,9 +136,6 @@ void enviarDadosSensores() {
|
|||
sensor->AferirAngulo();
|
||||
EnviarDadosCAN(static_cast<uint8_t>(S_Code::sPOT), sensor->MontarMensagemCAN());
|
||||
}
|
||||
else {
|
||||
PrintTela("Sensor sPOT invalido");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -190,54 +170,6 @@ void ProcessarReq() {
|
|||
enviarDadosSensores();
|
||||
}
|
||||
|
||||
void ProcessarCmd(std::vector<uint8_t> data) {
|
||||
if (data.size() < 3) return;
|
||||
|
||||
S_Code componente = (S_Code)data[1];
|
||||
uint8_t id = data[2];
|
||||
|
||||
switch (componente) {
|
||||
case sLED: {
|
||||
if (data.size() < 7) return;
|
||||
for (auto* _led : listaSinaleiros) {
|
||||
if (_led->ID_Num == id) {
|
||||
_led->_Status = (StatusLED)data[3];
|
||||
_led->_Qtd = data[4];
|
||||
_led->_TempoMs = (uint16_t)data[5] * 10;
|
||||
_led->_PausaMs = (uint16_t)data[6] * 10;
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case sRLE: {
|
||||
if (data.size() < 4) return;
|
||||
for (auto* _rele : listaReles) {
|
||||
if (_rele->ID_Num == id) {
|
||||
_rele->AtualizarStatus((Estado)data[3]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case sFRO: {
|
||||
if (data.size() < 4) return;
|
||||
for (auto* _freio : listaServoFreios) {
|
||||
if (_freio->ID_Num == id) {
|
||||
_freio->AtualizarAngulo(data[3]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessarCfg(std::vector<uint8_t> data) {
|
||||
S_Code sensorTipo = (S_Code)data[1];
|
||||
|
||||
|
|
@ -268,12 +200,7 @@ void ProcessarCfg(std::vector<uint8_t> data) {
|
|||
|
||||
ProcessarChk();
|
||||
|
||||
listaReles.clear();
|
||||
listaSinaleiros.clear();
|
||||
listaServoFreios.clear();
|
||||
listaSensoresCorrente.clear();
|
||||
listaSensoresTemperatura.clear();
|
||||
listaSensoresPotenciometros.clear();
|
||||
LimparListasComponentes();
|
||||
|
||||
PrintTela("Configuracao do modulo concluida");
|
||||
|
||||
|
|
@ -429,7 +356,96 @@ void ProcessarCfg(std::vector<uint8_t> data) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void ProcessarCmd(std::vector<uint8_t> data) {
|
||||
if (data.size() < 3) return;
|
||||
|
||||
S_Code componente = (S_Code)data[1];
|
||||
uint8_t id = data[2];
|
||||
|
||||
switch (componente) {
|
||||
case sLED: {
|
||||
if (data.size() < 7) return;
|
||||
for (auto* _led : listaSinaleiros) {
|
||||
if (_led->ID_Num == id) {
|
||||
_led->_Status = (StatusLED)data[3];
|
||||
_led->_Qtd = data[4];
|
||||
_led->_TempoMs = (uint16_t)data[5] * 10;
|
||||
_led->_PausaMs = (uint16_t)data[6] * 10;
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case sRLE: {
|
||||
if (data.size() < 4) return;
|
||||
for (auto* _rele : listaReles) {
|
||||
if (_rele->ID_Num == id) {
|
||||
_rele->AtualizarStatus((Estado)data[3]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case sFRO: {
|
||||
if (data.size() < 4) return;
|
||||
for (auto* _freio : listaServoFreios) {
|
||||
if (_freio->ID_Num == id) {
|
||||
_freio->AtualizarAngulo(data[3]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void LimparListasComponentes() {
|
||||
for (auto* rele : listaReles) {
|
||||
rele->Desligar();
|
||||
PrintTela("Rele " + rele->_ID + " desligado.");
|
||||
delete rele;
|
||||
}
|
||||
listaReles.clear();
|
||||
|
||||
for (auto* sinaleiro : listaSinaleiros) {
|
||||
sinaleiro->Desligar();
|
||||
PrintTela("Sinaleiro " + sinaleiro->_ID + " desligado.");
|
||||
delete sinaleiro;
|
||||
}
|
||||
listaSinaleiros.clear();
|
||||
|
||||
for (auto* servo : listaServoFreios) {
|
||||
servo->Desligar();
|
||||
PrintTela("Servo " + servo->_ID + " desligado.");
|
||||
delete servo;
|
||||
}
|
||||
listaServoFreios.clear();
|
||||
|
||||
for (auto* sensor : listaSensoresCorrente) {
|
||||
sensor->Desligar();
|
||||
PrintTela("Sensor de Corrente " + sensor->_ID + " desligado.");
|
||||
delete sensor;
|
||||
}
|
||||
listaSensoresCorrente.clear();
|
||||
|
||||
for (auto* sensor : listaSensoresTemperatura) {
|
||||
sensor->Desligar();
|
||||
PrintTela("Sensor de Temperatura " + sensor->_ID + " desligado.");
|
||||
delete sensor;
|
||||
}
|
||||
listaSensoresTemperatura.clear();
|
||||
|
||||
for (auto* sensor : listaSensoresPotenciometros) {
|
||||
sensor->Desligar();
|
||||
PrintTela("Sensor Potenciometro " + sensor->_ID + " desligado.");
|
||||
delete sensor;
|
||||
}
|
||||
listaSensoresPotenciometros.clear();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue