ajustes
This commit is contained in:
parent
af744f21c3
commit
bfe0ca73a0
Binary file not shown.
Binary file not shown.
|
|
@ -2,21 +2,21 @@
|
||||||
"Version": 1,
|
"Version": 1,
|
||||||
"WorkspaceRootPath": "C:\\ZendionINC\\agrobot_base\\AgroBase\\",
|
"WorkspaceRootPath": "C:\\ZendionINC\\agrobot_base\\AgroBase\\",
|
||||||
"Documents": [
|
"Documents": [
|
||||||
|
{
|
||||||
|
"AbsoluteMoniker": "D:0:0:{C54B41C0-1D21-4E3E-949E-0F86BBC86A33}|AgroBase\\AgroBase.csproj|c:\\zendioninc\\agrobot_base\\agrobase\\agrobase\\models\\mpccontrolleraprimorado.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
||||||
|
"RelativeMoniker": "D:0:0:{C54B41C0-1D21-4E3E-949E-0F86BBC86A33}|AgroBase\\AgroBase.csproj|solutionrelative:agrobase\\models\\mpccontrolleraprimorado.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"AbsoluteMoniker": "D:0:0:{C54B41C0-1D21-4E3E-949E-0F86BBC86A33}|AgroBase\\AgroBase.csproj|c:\\zendioninc\\agrobot_base\\agrobase\\agrobase\\models\\modules\\sensoriamentomodel.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
"AbsoluteMoniker": "D:0:0:{C54B41C0-1D21-4E3E-949E-0F86BBC86A33}|AgroBase\\AgroBase.csproj|c:\\zendioninc\\agrobot_base\\agrobase\\agrobase\\models\\modules\\sensoriamentomodel.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
||||||
"RelativeMoniker": "D:0:0:{C54B41C0-1D21-4E3E-949E-0F86BBC86A33}|AgroBase\\AgroBase.csproj|solutionrelative:agrobase\\models\\modules\\sensoriamentomodel.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
"RelativeMoniker": "D:0:0:{C54B41C0-1D21-4E3E-949E-0F86BBC86A33}|AgroBase\\AgroBase.csproj|solutionrelative:agrobase\\models\\modules\\sensoriamentomodel.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"AbsoluteMoniker": "D:0:0:{C54B41C0-1D21-4E3E-949E-0F86BBC86A33}|AgroBase\\AgroBase.csproj|c:\\zendioninc\\agrobot_base\\agrobase\\agrobase\\models\\modules\\dispositivobasemodel.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
||||||
|
"RelativeMoniker": "D:0:0:{C54B41C0-1D21-4E3E-949E-0F86BBC86A33}|AgroBase\\AgroBase.csproj|solutionrelative:agrobase\\models\\modules\\dispositivobasemodel.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"AbsoluteMoniker": "D:0:0:{C54B41C0-1D21-4E3E-949E-0F86BBC86A33}|AgroBase\\AgroBase.csproj|C:\\ZendionINC\\agrobot_base\\AgroBase\\agrobase\\models\\modules\\atuadormodel.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
"AbsoluteMoniker": "D:0:0:{C54B41C0-1D21-4E3E-949E-0F86BBC86A33}|AgroBase\\AgroBase.csproj|C:\\ZendionINC\\agrobot_base\\AgroBase\\agrobase\\models\\modules\\atuadormodel.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
||||||
"RelativeMoniker": "D:0:0:{C54B41C0-1D21-4E3E-949E-0F86BBC86A33}|AgroBase\\AgroBase.csproj|solutionrelative:agrobase\\models\\modules\\atuadormodel.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
"RelativeMoniker": "D:0:0:{C54B41C0-1D21-4E3E-949E-0F86BBC86A33}|AgroBase\\AgroBase.csproj|solutionrelative:agrobase\\models\\modules\\atuadormodel.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
||||||
},
|
|
||||||
{
|
|
||||||
"AbsoluteMoniker": "D:0:0:{C54B41C0-1D21-4E3E-949E-0F86BBC86A33}|AgroBase\\AgroBase.csproj|C:\\ZendionINC\\agrobot_base\\AgroBase\\agrobase\\models\\operacoes\\operacaomodel.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
|
||||||
"RelativeMoniker": "D:0:0:{C54B41C0-1D21-4E3E-949E-0F86BBC86A33}|AgroBase\\AgroBase.csproj|solutionrelative:agrobase\\models\\operacoes\\operacaomodel.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"AbsoluteMoniker": "D:0:0:{C54B41C0-1D21-4E3E-949E-0F86BBC86A33}|AgroBase\\AgroBase.csproj|C:\\ZendionINC\\agrobot_base\\AgroBase\\agrobase\\services\\canservice.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
|
||||||
"RelativeMoniker": "D:0:0:{C54B41C0-1D21-4E3E-949E-0F86BBC86A33}|AgroBase\\AgroBase.csproj|solutionrelative:agrobase\\services\\canservice.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"DocumentGroupContainers": [
|
"DocumentGroupContainers": [
|
||||||
|
|
@ -31,53 +31,54 @@
|
||||||
{
|
{
|
||||||
"$type": "Document",
|
"$type": "Document",
|
||||||
"DocumentIndex": 0,
|
"DocumentIndex": 0,
|
||||||
|
"Title": "MPCControllerAprimorado.cs",
|
||||||
|
"DocumentMoniker": "C:\\ZendionINC\\agrobot_base\\AgroBase\\AgroBase\\Models\\MPCControllerAprimorado.cs",
|
||||||
|
"RelativeDocumentMoniker": "AgroBase\\Models\\MPCControllerAprimorado.cs",
|
||||||
|
"ToolTip": "C:\\ZendionINC\\agrobot_base\\AgroBase\\AgroBase\\Models\\MPCControllerAprimorado.cs",
|
||||||
|
"RelativeToolTip": "AgroBase\\Models\\MPCControllerAprimorado.cs",
|
||||||
|
"ViewState": "AQIAAAAAAAAAAAAAAAAAABoAAABcAAAA",
|
||||||
|
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
||||||
|
"WhenOpened": "2025-04-16T16:33:32.578Z",
|
||||||
|
"EditorCaption": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$type": "Document",
|
||||||
|
"DocumentIndex": 2,
|
||||||
|
"Title": "DispositivoBaseModel.cs",
|
||||||
|
"DocumentMoniker": "C:\\ZendionINC\\agrobot_base\\AgroBase\\AgroBase\\Models\\Modules\\DispositivoBaseModel.cs",
|
||||||
|
"RelativeDocumentMoniker": "AgroBase\\Models\\Modules\\DispositivoBaseModel.cs",
|
||||||
|
"ToolTip": "C:\\ZendionINC\\agrobot_base\\AgroBase\\AgroBase\\Models\\Modules\\DispositivoBaseModel.cs",
|
||||||
|
"RelativeToolTip": "AgroBase\\Models\\Modules\\DispositivoBaseModel.cs",
|
||||||
|
"ViewState": "AQIAAAAAAAAAAAAAAAAAAAgAAAAnAAAA",
|
||||||
|
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
||||||
|
"WhenOpened": "2025-04-16T13:20:21.786Z",
|
||||||
|
"EditorCaption": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$type": "Document",
|
||||||
|
"DocumentIndex": 1,
|
||||||
"Title": "SensoriamentoModel.cs",
|
"Title": "SensoriamentoModel.cs",
|
||||||
"DocumentMoniker": "C:\\ZendionINC\\agrobot_base\\AgroBase\\AgroBase\\Models\\Modules\\SensoriamentoModel.cs",
|
"DocumentMoniker": "C:\\ZendionINC\\agrobot_base\\AgroBase\\AgroBase\\Models\\Modules\\SensoriamentoModel.cs",
|
||||||
"RelativeDocumentMoniker": "AgroBase\\Models\\Modules\\SensoriamentoModel.cs",
|
"RelativeDocumentMoniker": "AgroBase\\Models\\Modules\\SensoriamentoModel.cs",
|
||||||
"ToolTip": "C:\\ZendionINC\\agrobot_base\\AgroBase\\AgroBase\\Models\\Modules\\SensoriamentoModel.cs",
|
"ToolTip": "C:\\ZendionINC\\agrobot_base\\AgroBase\\AgroBase\\Models\\Modules\\SensoriamentoModel.cs",
|
||||||
"RelativeToolTip": "AgroBase\\Models\\Modules\\SensoriamentoModel.cs",
|
"RelativeToolTip": "AgroBase\\Models\\Modules\\SensoriamentoModel.cs",
|
||||||
"ViewState": "AQIAAAAAAAAAAAAAAAAAALgEAAAhAAAA",
|
"ViewState": "AQIAABsHAAAAAAAAAAAuwEUIAAAOAAAA",
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
||||||
"WhenOpened": "2025-04-15T10:44:14.963Z",
|
"WhenOpened": "2025-04-15T10:44:14.963Z",
|
||||||
"EditorCaption": ""
|
"EditorCaption": ""
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"$type": "Document",
|
"$type": "Document",
|
||||||
"DocumentIndex": 1,
|
"DocumentIndex": 3,
|
||||||
"Title": "AtuadorModel.cs",
|
"Title": "AtuadorModel.cs",
|
||||||
"DocumentMoniker": "C:\\ZendionINC\\agrobot_base\\AgroBase\\AgroBase\\Models\\Modules\\AtuadorModel.cs",
|
"DocumentMoniker": "C:\\ZendionINC\\agrobot_base\\AgroBase\\AgroBase\\Models\\Modules\\AtuadorModel.cs",
|
||||||
"RelativeDocumentMoniker": "AgroBase\\Models\\Modules\\AtuadorModel.cs",
|
"RelativeDocumentMoniker": "AgroBase\\Models\\Modules\\AtuadorModel.cs",
|
||||||
"ToolTip": "C:\\ZendionINC\\agrobot_base\\AgroBase\\AgroBase\\Models\\Modules\\AtuadorModel.cs",
|
"ToolTip": "C:\\ZendionINC\\agrobot_base\\AgroBase\\AgroBase\\Models\\Modules\\AtuadorModel.cs",
|
||||||
"RelativeToolTip": "AgroBase\\Models\\Modules\\AtuadorModel.cs",
|
"RelativeToolTip": "AgroBase\\Models\\Modules\\AtuadorModel.cs",
|
||||||
"ViewState": "AQIAALcAAAAAAAAAAAAYwPQBAAAJAAAA",
|
"ViewState": "AQIAAAAAAAAAAAAAAAAAAAEAAAAYAAAA",
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
||||||
"WhenOpened": "2025-04-15T10:40:50.024Z",
|
"WhenOpened": "2025-04-15T10:40:50.024Z",
|
||||||
"EditorCaption": ""
|
"EditorCaption": ""
|
||||||
},
|
|
||||||
{
|
|
||||||
"$type": "Document",
|
|
||||||
"DocumentIndex": 3,
|
|
||||||
"Title": "CANService.cs",
|
|
||||||
"DocumentMoniker": "C:\\ZendionINC\\agrobot_base\\AgroBase\\AgroBase\\Services\\CANService.cs",
|
|
||||||
"RelativeDocumentMoniker": "AgroBase\\Services\\CANService.cs",
|
|
||||||
"ToolTip": "C:\\ZendionINC\\agrobot_base\\AgroBase\\AgroBase\\Services\\CANService.cs",
|
|
||||||
"RelativeToolTip": "AgroBase\\Services\\CANService.cs",
|
|
||||||
"ViewState": "AQIAAAAAAAAAAAAAAAAAADoAAAAlAAAA",
|
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
|
||||||
"WhenOpened": "2025-04-14T19:46:16.662Z"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"$type": "Document",
|
|
||||||
"DocumentIndex": 2,
|
|
||||||
"Title": "OperacaoModel.cs",
|
|
||||||
"DocumentMoniker": "C:\\ZendionINC\\agrobot_base\\AgroBase\\AgroBase\\Models\\Operacoes\\OperacaoModel.cs",
|
|
||||||
"RelativeDocumentMoniker": "AgroBase\\Models\\Operacoes\\OperacaoModel.cs",
|
|
||||||
"ToolTip": "C:\\ZendionINC\\agrobot_base\\AgroBase\\AgroBase\\Models\\Operacoes\\OperacaoModel.cs",
|
|
||||||
"RelativeToolTip": "AgroBase\\Models\\Operacoes\\OperacaoModel.cs",
|
|
||||||
"ViewState": "AQIAAAIAAAAAAAAAAAAswC4MAAAFAAAA",
|
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
|
||||||
"WhenOpened": "2025-04-14T16:46:36.149Z",
|
|
||||||
"EditorCaption": ""
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
using AgroBase.Forms.IHM;
|
using AgroBase.Forms.IHM;
|
||||||
using AgroBase.Services;
|
using AgroBase.Services;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
|
@ -532,57 +531,6 @@ namespace AgroBase.Models.Modules
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void RecebeProtocoloModulo(string Protocolo)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(Protocolo))
|
|
||||||
{
|
|
||||||
Console.WriteLine("Protocolo recebido está vazio ou nulo.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Protocolo = Protocolo.Substring(0, Protocolo.Length - 1);
|
|
||||||
|
|
||||||
// Valida se o protocolo possui um formato esperado
|
|
||||||
if (Protocolo.Length <= 1 || !Protocolo.EndsWith("}"))
|
|
||||||
{
|
|
||||||
Console.WriteLine("Protocolo recebido está em um formato inválido.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Console.WriteLine($"JSON recebido: {Protocolo}");
|
|
||||||
|
|
||||||
// Tenta desserializar o JSON
|
|
||||||
var dadosLeitura = JsonConvert.DeserializeObject<AtuadorMensagemJsonModel>(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}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void AtualizaDadosComponentes(AtuadorMensagemJsonModel dadosLeitura)
|
|
||||||
{
|
|
||||||
DadosLeitura = dadosLeitura;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void IniciarRegistrador()
|
public void IniciarRegistrador()
|
||||||
{
|
{
|
||||||
if (!(tmrRegistrador?.IsRunning ?? false))
|
if (!(tmrRegistrador?.IsRunning ?? false))
|
||||||
|
|
@ -631,8 +579,9 @@ namespace AgroBase.Models.Modules
|
||||||
|
|
||||||
VerificaControleLeitura();
|
VerificaControleLeitura();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
AtualizaComponentesIniciados();
|
||||||
|
}
|
||||||
|
|
||||||
public (bool, List<string>) StatusModulosATU()
|
public (bool, List<string>) StatusModulosATU()
|
||||||
{
|
{
|
||||||
|
|
@ -698,6 +647,28 @@ namespace AgroBase.Models.Modules
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void AtualizaComponentesIniciados()
|
||||||
|
{
|
||||||
|
DateTime Agora = DateTime.Now;
|
||||||
|
bool modConectado = DadosLeitura.UltimoComandoRespondido.AddMilliseconds(TempoLimiteConexao) > Agora;
|
||||||
|
if (!modConectado && DadosLeitura.Conectado)
|
||||||
|
{
|
||||||
|
DadosLeitura.Conectado = false;
|
||||||
|
}
|
||||||
|
foreach (var bomba in BombasPressurizadoras.Where(x => x.Inicializado && x.Leitura.Momento.AddMilliseconds(TempoLimiteConexao) < Agora))
|
||||||
|
{
|
||||||
|
bomba.Leitura.Iniciado = false;
|
||||||
|
}
|
||||||
|
foreach (var bico in BicosPulverizadores.Where(x => x.Inicializado && x.Leitura.Momento.AddMilliseconds(TempoLimiteConexao) < Agora))
|
||||||
|
{
|
||||||
|
bico.Leitura.Iniciado = false;
|
||||||
|
}
|
||||||
|
foreach (var sensor in Sensores.Where(x => x.Inicializado && x.Leitura.Momento.AddMilliseconds(TempoLimiteConexao) < Agora))
|
||||||
|
{
|
||||||
|
sensor.Leitura.Iniciado = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AtuadorBicoModel
|
public class AtuadorBicoModel
|
||||||
|
|
@ -737,7 +708,7 @@ namespace AgroBase.Models.Modules
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
_leitura = Variaveis.OperacaoEmAndamento.DispAtu?.Dados?.DadosLeitura?.BicosPulverizadores?.FirstOrDefault(x => x.ID == ID);
|
_leitura = Variaveis.OperacaoEmAndamento.DispAtu?.Dados?.DadosLeitura?.BicosPulverizadores?.FirstOrDefault(x => x.ID_Num == ID_Num);
|
||||||
return _leitura;
|
return _leitura;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
|
|
@ -881,7 +852,7 @@ namespace AgroBase.Models.Modules
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
_leitura = Variaveis.OperacaoEmAndamento.DispAtu?.Dados?.DadosLeitura?.BombasPressurizadoras?.FirstOrDefault(x => x.ID == ID);
|
_leitura = Variaveis.OperacaoEmAndamento.DispAtu?.Dados?.DadosLeitura?.BombasPressurizadoras?.FirstOrDefault(x => x.ID_Num == ID_Num);
|
||||||
return _leitura;
|
return _leitura;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
|
|
@ -922,11 +893,21 @@ namespace AgroBase.Models.Modules
|
||||||
(byte)(pinout.Pinos.FirstOrDefault(x => x.Funcao == FuncoesPinout.PWM)?.Pino ?? PinoutUtils.PINO_INVALIDO),
|
(byte)(pinout.Pinos.FirstOrDefault(x => x.Funcao == FuncoesPinout.PWM)?.Pino ?? PinoutUtils.PINO_INVALIDO),
|
||||||
};
|
};
|
||||||
|
|
||||||
return new List<byte[]>()
|
if (conectar)
|
||||||
{
|
{
|
||||||
config1.ToArray(),
|
return new List<byte[]>()
|
||||||
config2.ToArray()
|
{
|
||||||
};
|
config1.ToArray(),
|
||||||
|
config2.ToArray()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new List<byte[]>()
|
||||||
|
{
|
||||||
|
config1.ToArray()
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public (F_Code, byte[]) ProtocoloComando()
|
public (F_Code, byte[]) ProtocoloComando()
|
||||||
|
|
@ -1142,9 +1123,11 @@ namespace AgroBase.Models.Modules
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class FirmwareBombaPressurizadora
|
public class FirmwareBombaPressurizadora : IFirmwareSensorBase
|
||||||
{
|
{
|
||||||
|
public DateTime Momento { get; set; }
|
||||||
public string ID { get; set; }
|
public string ID { get; set; }
|
||||||
|
public int ID_Num { get; set; }
|
||||||
public bool Iniciado { get; set; }
|
public bool Iniciado { get; set; }
|
||||||
public Estado Estado { get; set; }
|
public Estado Estado { get; set; }
|
||||||
public double Potencia { get; set; }
|
public double Potencia { get; set; }
|
||||||
|
|
@ -1202,12 +1185,13 @@ namespace AgroBase.Models.Modules
|
||||||
case S_Code.sFLX:
|
case S_Code.sFLX:
|
||||||
{
|
{
|
||||||
var sensor = Disp.Dados.Sensores.FirstOrDefault(x => x.ID_Num == CompID_Num);
|
var sensor = Disp.Dados.Sensores.FirstOrDefault(x => x.ID_Num == CompID_Num);
|
||||||
var _sensor = item.SensoresFluxo.FirstOrDefault(x => x.ID == sensor.ID);
|
var _sensor = item.SensoresFluxo.FirstOrDefault(x => x.ID_Num == sensor.ID_Num);
|
||||||
if (_sensor == null)
|
if (_sensor == null)
|
||||||
{
|
{
|
||||||
_sensor = new FirmwareSensorFluxo()
|
_sensor = new FirmwareSensorFluxo()
|
||||||
{
|
{
|
||||||
ID = sensor.ID,
|
ID = sensor.ID,
|
||||||
|
ID_Num = CompID_Num,
|
||||||
Iniciado = false,
|
Iniciado = false,
|
||||||
Vazao = -1,
|
Vazao = -1,
|
||||||
};
|
};
|
||||||
|
|
@ -1228,18 +1212,20 @@ namespace AgroBase.Models.Modules
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_sensor.Momento = DateTime.Now;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case S_Code.sPRS:
|
case S_Code.sPRS:
|
||||||
{
|
{
|
||||||
var sensor = Disp.Dados.Sensores.FirstOrDefault(x => x.ID_Num == CompID_Num);
|
var sensor = Disp.Dados.Sensores.FirstOrDefault(x => x.ID_Num == CompID_Num);
|
||||||
var _sensor = item.SensoresPressao.FirstOrDefault(x => x.ID == sensor.ID);
|
var _sensor = item.SensoresPressao.FirstOrDefault(x => x.ID_Num == sensor.ID_Num);
|
||||||
if (_sensor == null)
|
if (_sensor == null)
|
||||||
{
|
{
|
||||||
_sensor = new FirmwareSensorPressao()
|
_sensor = new FirmwareSensorPressao()
|
||||||
{
|
{
|
||||||
ID = sensor.ID,
|
ID = sensor.ID,
|
||||||
|
ID_Num = CompID_Num,
|
||||||
Iniciado = false,
|
Iniciado = false,
|
||||||
Pressao = -1,
|
Pressao = -1,
|
||||||
};
|
};
|
||||||
|
|
@ -1260,18 +1246,20 @@ namespace AgroBase.Models.Modules
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_sensor.Momento = DateTime.Now;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case S_Code.sMAS:
|
case S_Code.sMAS:
|
||||||
{
|
{
|
||||||
var sensor = Disp.Dados.Sensores.FirstOrDefault(x => x.ID_Num == CompID_Num);
|
var sensor = Disp.Dados.Sensores.FirstOrDefault(x => x.ID_Num == CompID_Num);
|
||||||
var _sensor = item.SensoresMassa.FirstOrDefault(x => x.ID == sensor.ID);
|
var _sensor = item.SensoresMassa.FirstOrDefault(x => x.ID_Num == sensor.ID_Num);
|
||||||
if (_sensor == null)
|
if (_sensor == null)
|
||||||
{
|
{
|
||||||
_sensor = new FirmwareSensorMassa()
|
_sensor = new FirmwareSensorMassa()
|
||||||
{
|
{
|
||||||
ID = sensor.ID,
|
ID = sensor.ID,
|
||||||
|
ID_Num = CompID_Num,
|
||||||
Iniciado = false,
|
Iniciado = false,
|
||||||
Massa = -1,
|
Massa = -1,
|
||||||
};
|
};
|
||||||
|
|
@ -1292,18 +1280,20 @@ namespace AgroBase.Models.Modules
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_sensor.Momento = DateTime.Now;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case S_Code.sBIC:
|
case S_Code.sBIC:
|
||||||
{
|
{
|
||||||
var sensor = Disp.Dados.BicosPulverizadores.FirstOrDefault(x => x.ID_Num == CompID_Num);
|
var sensor = Disp.Dados.BicosPulverizadores.FirstOrDefault(x => x.ID_Num == CompID_Num);
|
||||||
var _sensor = item.BicosPulverizadores.FirstOrDefault(x => x.ID == sensor.ID);
|
var _sensor = item.BicosPulverizadores.FirstOrDefault(x => x.ID_Num == sensor.ID_Num);
|
||||||
if (_sensor == null)
|
if (_sensor == null)
|
||||||
{
|
{
|
||||||
_sensor = new FirmwareRele()
|
_sensor = new FirmwareRele()
|
||||||
{
|
{
|
||||||
ID = sensor.ID,
|
ID = sensor.ID,
|
||||||
|
ID_Num = CompID_Num,
|
||||||
Iniciado = false,
|
Iniciado = false,
|
||||||
Leitura = Estado.Desligado,
|
Leitura = Estado.Desligado,
|
||||||
};
|
};
|
||||||
|
|
@ -1324,18 +1314,20 @@ namespace AgroBase.Models.Modules
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_sensor.Momento = DateTime.Now;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case S_Code.sBMB:
|
case S_Code.sBMB:
|
||||||
{
|
{
|
||||||
var sensor = Disp.Dados.BombasPressurizadoras.FirstOrDefault(x => x.ID_Num == CompID_Num);
|
var sensor = Disp.Dados.BombasPressurizadoras.FirstOrDefault(x => x.ID_Num == CompID_Num);
|
||||||
var _sensor = item.BombasPressurizadoras.FirstOrDefault(x => x.ID == sensor.ID);
|
var _sensor = item.BombasPressurizadoras.FirstOrDefault(x => x.ID_Num == sensor.ID_Num);
|
||||||
if (_sensor == null)
|
if (_sensor == null)
|
||||||
{
|
{
|
||||||
_sensor = new FirmwareBombaPressurizadora()
|
_sensor = new FirmwareBombaPressurizadora()
|
||||||
{
|
{
|
||||||
ID = sensor.ID,
|
ID = sensor.ID,
|
||||||
|
ID_Num = CompID_Num,
|
||||||
Iniciado = false,
|
Iniciado = false,
|
||||||
Estado = Estado.Desligado,
|
Estado = Estado.Desligado,
|
||||||
Potencia = -1,
|
Potencia = -1,
|
||||||
|
|
@ -1362,6 +1354,7 @@ namespace AgroBase.Models.Modules
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_sensor.Momento = DateTime.Now;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ namespace AgroBase.Models
|
||||||
bool Conectado { get; }
|
bool Conectado { get; }
|
||||||
int _TaxaAmostragem { get; set; }
|
int _TaxaAmostragem { get; set; }
|
||||||
byte _EnderecoCAN { get; set; }
|
byte _EnderecoCAN { get; set; }
|
||||||
void RecebeProtocoloModulo(string Protocolo);
|
|
||||||
List<byte[]> ProtocoloConfiguracao(bool Conectar);
|
List<byte[]> ProtocoloConfiguracao(bool Conectar);
|
||||||
void IniciarRegistrador();
|
void IniciarRegistrador();
|
||||||
void PararRegistrador();
|
void PararRegistrador();
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
using AgroBase.Forms.IHM;
|
using AgroBase.Forms.IHM;
|
||||||
using AgroBase.Services;
|
using AgroBase.Services;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
@ -8,6 +7,7 @@ using System.Threading.Tasks;
|
||||||
using static AgroBase.Models.Enums;
|
using static AgroBase.Models.Enums;
|
||||||
using System.IO.Ports;
|
using System.IO.Ports;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.Data;
|
||||||
|
|
||||||
namespace AgroBase.Models.Modules
|
namespace AgroBase.Models.Modules
|
||||||
{
|
{
|
||||||
|
|
@ -773,62 +773,6 @@ namespace AgroBase.Models.Modules
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void RecebeProtocoloModulo(string Protocolo)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(Protocolo))
|
|
||||||
{
|
|
||||||
Console.WriteLine("Protocolo recebido está vazio ou nulo.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Protocolo = Protocolo.Substring(0, Protocolo.Length - 1);
|
|
||||||
|
|
||||||
// Valida se o protocolo possui um formato esperado
|
|
||||||
if (Protocolo.Length <= 1 || !Protocolo.EndsWith("}"))
|
|
||||||
{
|
|
||||||
Console.WriteLine("Protocolo recebido está em um formato inválido.");
|
|
||||||
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}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void AtualizaDadosComponentes(SensoriamentoMensagemJsonModel dadosLeitura)
|
|
||||||
{
|
|
||||||
DadosLeitura = dadosLeitura;
|
|
||||||
|
|
||||||
if (Variaveis.OperacaoEmAndamento.DispMvd != null)
|
|
||||||
{
|
|
||||||
Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.ForEach(Modulo => Modulo.AtualizarSensoresMotor());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void IniciarRegistrador()
|
public void IniciarRegistrador()
|
||||||
{
|
{
|
||||||
if (!(tmrRegistrador?.IsRunning ?? false))
|
if (!(tmrRegistrador?.IsRunning ?? false))
|
||||||
|
|
@ -877,10 +821,10 @@ namespace AgroBase.Models.Modules
|
||||||
|
|
||||||
VerificaControleLeitura();
|
VerificaControleLeitura();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AtualizaComponentesIniciados();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public (bool, List<string>) StatusModulosSEN()
|
public (bool, List<string>) StatusModulosSEN()
|
||||||
{
|
{
|
||||||
var _Sensores = Sensores?.Where(x => x.Aferir).ToList();
|
var _Sensores = Sensores?.Where(x => x.Aferir).ToList();
|
||||||
|
|
@ -956,6 +900,32 @@ namespace AgroBase.Models.Modules
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void AtualizaComponentesIniciados()
|
||||||
|
{
|
||||||
|
DateTime Agora = DateTime.Now;
|
||||||
|
bool modConectado = DadosLeitura.UltimoComandoRespondido.AddMilliseconds(TempoLimiteConexao) > Agora;
|
||||||
|
if (!modConectado && DadosLeitura.Conectado)
|
||||||
|
{
|
||||||
|
DadosLeitura.Conectado = false;
|
||||||
|
}
|
||||||
|
foreach (var led in Sinaleiros.Where(x => x.Inicializado && x.Leitura.Momento.AddMilliseconds(TempoLimiteConexao) < Agora))
|
||||||
|
{
|
||||||
|
led.Leitura.Iniciado = false;
|
||||||
|
}
|
||||||
|
foreach (var rele in Reles.Where(x => x.Inicializado && x.Leitura.Momento.AddMilliseconds(TempoLimiteConexao) < Agora))
|
||||||
|
{
|
||||||
|
rele.Leitura.Iniciado = false;
|
||||||
|
}
|
||||||
|
foreach (var servo in Servos.Where(x => x.Inicializado && x.Leitura.Momento.AddMilliseconds(TempoLimiteConexao) < Agora))
|
||||||
|
{
|
||||||
|
servo.Leitura.Iniciado = false;
|
||||||
|
}
|
||||||
|
foreach (var sensor in Sensores.Where(x => x.Inicializado && x.Leitura.Momento.AddMilliseconds(TempoLimiteConexao) < Agora))
|
||||||
|
{
|
||||||
|
sensor.Leitura.Iniciado = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SensorModel
|
public class SensorModel
|
||||||
|
|
@ -966,29 +936,29 @@ namespace AgroBase.Models.Modules
|
||||||
public S_Code Componente { get; set; }
|
public S_Code Componente { get; set; }
|
||||||
public bool Aferir { get; set; } = false;
|
public bool Aferir { get; set; } = false;
|
||||||
private dynamic _leitura = null;
|
private dynamic _leitura = null;
|
||||||
public dynamic Leitura
|
public IFirmwareSensorBase Leitura
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
switch (Componente)
|
switch (Componente)
|
||||||
{
|
{
|
||||||
case S_Code.sTMP:
|
case S_Code.sTMP:
|
||||||
_leitura = Variaveis.OperacaoEmAndamento.DispSen?.Dados?.DadosLeitura?.SensoresTemperatura?.FirstOrDefault(x => x.ID == ID);
|
_leitura = Variaveis.OperacaoEmAndamento.DispSen?.Dados?.DadosLeitura?.SensoresTemperatura?.FirstOrDefault(x => x.ID_Num == ID_Num);
|
||||||
break;
|
break;
|
||||||
case S_Code.sCOR:
|
case S_Code.sCOR:
|
||||||
_leitura = Variaveis.OperacaoEmAndamento.DispSen?.Dados?.DadosLeitura?.SensoresCorrente?.FirstOrDefault(x => x.ID == ID);
|
_leitura = Variaveis.OperacaoEmAndamento.DispSen?.Dados?.DadosLeitura?.SensoresCorrente?.FirstOrDefault(x => x.ID_Num == ID_Num);
|
||||||
break;
|
break;
|
||||||
case S_Code.sFLX:
|
case S_Code.sFLX:
|
||||||
_leitura = Variaveis.OperacaoEmAndamento.DispAtu?.Dados?.DadosLeitura?.SensoresFluxo?.FirstOrDefault(x => x.ID == ID);
|
_leitura = Variaveis.OperacaoEmAndamento.DispAtu?.Dados?.DadosLeitura?.SensoresFluxo?.FirstOrDefault(x => x.ID_Num == ID_Num);
|
||||||
break;
|
break;
|
||||||
case S_Code.sPRS:
|
case S_Code.sPRS:
|
||||||
_leitura = Variaveis.OperacaoEmAndamento.DispAtu?.Dados?.DadosLeitura?.SensoresPressao?.FirstOrDefault(x => x.ID == ID);
|
_leitura = Variaveis.OperacaoEmAndamento.DispAtu?.Dados?.DadosLeitura?.SensoresPressao?.FirstOrDefault(x => x.ID_Num == ID_Num);
|
||||||
break;
|
break;
|
||||||
case S_Code.sMAS:
|
case S_Code.sMAS:
|
||||||
_leitura = Variaveis.OperacaoEmAndamento.DispAtu?.Dados?.DadosLeitura?.SensoresMassa?.FirstOrDefault(x => x.ID == ID);
|
_leitura = Variaveis.OperacaoEmAndamento.DispAtu?.Dados?.DadosLeitura?.SensoresMassa?.FirstOrDefault(x => x.ID_Num == ID_Num);
|
||||||
break;
|
break;
|
||||||
case S_Code.sIMU:
|
case S_Code.sIMU:
|
||||||
_leitura = Variaveis.OperacaoEmAndamento.DispSen?.Dados?.DadosLeitura?.SensoresIMU?.FirstOrDefault(x => x.ID == ID);
|
_leitura = Variaveis.OperacaoEmAndamento.DispSen?.Dados?.DadosLeitura?.SensoresIMU?.FirstOrDefault(x => x.ID_Num == ID_Num);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
_leitura = null;
|
_leitura = null;
|
||||||
|
|
@ -1067,7 +1037,7 @@ namespace AgroBase.Models.Modules
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
_leitura = Variaveis.OperacaoEmAndamento.DispSen?.Dados?.DadosLeitura?.Sinaleiros?.FirstOrDefault(x => x.ID == ID);
|
_leitura = Variaveis.OperacaoEmAndamento.DispSen?.Dados?.DadosLeitura?.Sinaleiros?.FirstOrDefault(x => x.ID_Num == ID_Num);
|
||||||
return _leitura;
|
return _leitura;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
|
|
@ -1146,7 +1116,7 @@ namespace AgroBase.Models.Modules
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
_leitura = Variaveis.OperacaoEmAndamento.DispSen?.Dados?.DadosLeitura?.Reles?.FirstOrDefault(x => x.ID == ID);
|
_leitura = Variaveis.OperacaoEmAndamento.DispSen?.Dados?.DadosLeitura?.Reles?.FirstOrDefault(x => x.ID_Num == ID_Num);
|
||||||
return _leitura;
|
return _leitura;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
|
|
@ -1222,7 +1192,7 @@ namespace AgroBase.Models.Modules
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
_leitura = Variaveis.OperacaoEmAndamento.DispSen?.Dados?.DadosLeitura?.ServoFreios?.FirstOrDefault(x => x.ID == ID);
|
_leitura = Variaveis.OperacaoEmAndamento.DispSen?.Dados?.DadosLeitura?.ServoFreios?.FirstOrDefault(x => x.ID_Num == ID_Num);
|
||||||
return _leitura;
|
return _leitura;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
|
|
@ -1384,7 +1354,9 @@ namespace AgroBase.Models.Modules
|
||||||
|
|
||||||
public class FirmwareSensorTemperatura : IFirmwareSensorBase
|
public class FirmwareSensorTemperatura : IFirmwareSensorBase
|
||||||
{
|
{
|
||||||
|
public DateTime Momento { get; set; }
|
||||||
public string ID { get; set; }
|
public string ID { get; set; }
|
||||||
|
public int ID_Num { get; set; }
|
||||||
public bool Iniciado { get; set; }
|
public bool Iniciado { get; set; }
|
||||||
private double _temperatura;
|
private double _temperatura;
|
||||||
public double Temperatura {
|
public double Temperatura {
|
||||||
|
|
@ -1404,7 +1376,7 @@ namespace AgroBase.Models.Modules
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var sensor = Variaveis.OperacaoEmAndamento.DispSen.Dados.Sensores.FirstOrDefault(x => x.ID == ID);
|
var sensor = Variaveis.OperacaoEmAndamento.DispSen.Dados.Sensores.FirstOrDefault(x => x.ID_Num == ID_Num);
|
||||||
if (sensor != null)
|
if (sensor != null)
|
||||||
{
|
{
|
||||||
return sensor.LimiteMaximo;
|
return sensor.LimiteMaximo;
|
||||||
|
|
@ -1416,7 +1388,7 @@ namespace AgroBase.Models.Modules
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var sensor = Variaveis.OperacaoEmAndamento.DispSen.Dados.Sensores.FirstOrDefault(x => x.ID == ID);
|
var sensor = Variaveis.OperacaoEmAndamento.DispSen.Dados.Sensores.FirstOrDefault(x => x.ID_Num == ID_Num);
|
||||||
if (sensor != null)
|
if (sensor != null)
|
||||||
{
|
{
|
||||||
return sensor.LimiteMinimo;
|
return sensor.LimiteMinimo;
|
||||||
|
|
@ -1440,7 +1412,9 @@ namespace AgroBase.Models.Modules
|
||||||
|
|
||||||
public class FirmwareSensorCorrente : IFirmwareSensorBase
|
public class FirmwareSensorCorrente : IFirmwareSensorBase
|
||||||
{
|
{
|
||||||
|
public DateTime Momento { get; set; }
|
||||||
public string ID { get; set; }
|
public string ID { get; set; }
|
||||||
|
public int ID_Num { get; set; }
|
||||||
public bool Iniciado { get; set; }
|
public bool Iniciado { get; set; }
|
||||||
public double BusVoltage { get; set; }
|
public double BusVoltage { get; set; }
|
||||||
public double ShuntVoltage { get; set; }
|
public double ShuntVoltage { get; set; }
|
||||||
|
|
@ -1465,7 +1439,7 @@ namespace AgroBase.Models.Modules
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var sensor = Variaveis.OperacaoEmAndamento.DispSen.Dados.Sensores.FirstOrDefault(x => x.ID == ID);
|
var sensor = Variaveis.OperacaoEmAndamento.DispSen.Dados.Sensores.FirstOrDefault(x => x.ID_Num == ID_Num);
|
||||||
if (sensor != null)
|
if (sensor != null)
|
||||||
{
|
{
|
||||||
return sensor.LimiteMaximo;
|
return sensor.LimiteMaximo;
|
||||||
|
|
@ -1477,7 +1451,7 @@ namespace AgroBase.Models.Modules
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var sensor = Variaveis.OperacaoEmAndamento.DispSen.Dados.Sensores.FirstOrDefault(x => x.ID == ID);
|
var sensor = Variaveis.OperacaoEmAndamento.DispSen.Dados.Sensores.FirstOrDefault(x => x.ID_Num == ID_Num);
|
||||||
if (sensor != null)
|
if (sensor != null)
|
||||||
{
|
{
|
||||||
return sensor.LimiteMinimo;
|
return sensor.LimiteMinimo;
|
||||||
|
|
@ -1503,7 +1477,9 @@ namespace AgroBase.Models.Modules
|
||||||
|
|
||||||
public class FirmwareSinaleiro : IFirmwareSensorBase
|
public class FirmwareSinaleiro : IFirmwareSensorBase
|
||||||
{
|
{
|
||||||
|
public DateTime Momento { get; set; }
|
||||||
public string ID { get; set; }
|
public string ID { get; set; }
|
||||||
|
public int ID_Num { get; set; }
|
||||||
public bool Iniciado { get; set; }
|
public bool Iniciado { get; set; }
|
||||||
public StatusLED Leitura { get; set; }
|
public StatusLED Leitura { get; set; }
|
||||||
public StatusLED Comando { get; set; }
|
public StatusLED Comando { get; set; }
|
||||||
|
|
@ -1511,21 +1487,27 @@ namespace AgroBase.Models.Modules
|
||||||
|
|
||||||
public class FirmwareRele : IFirmwareSensorBase
|
public class FirmwareRele : IFirmwareSensorBase
|
||||||
{
|
{
|
||||||
|
public DateTime Momento { get; set; }
|
||||||
public string ID { get; set; }
|
public string ID { get; set; }
|
||||||
|
public int ID_Num { get; set; }
|
||||||
public bool Iniciado { get; set; }
|
public bool Iniciado { get; set; }
|
||||||
public Estado Leitura { get; set; }
|
public Estado Leitura { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class FirmwareServoFreio : IFirmwareSensorBase
|
public class FirmwareServoFreio : IFirmwareSensorBase
|
||||||
{
|
{
|
||||||
|
public DateTime Momento { get; set; }
|
||||||
public string ID { get; set; }
|
public string ID { get; set; }
|
||||||
|
public int ID_Num { get; set; }
|
||||||
public bool Iniciado { get; set; }
|
public bool Iniciado { get; set; }
|
||||||
public int Angulo { get; set; }
|
public int Angulo { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class FirmwareSensorFluxo : IFirmwareSensorBase
|
public class FirmwareSensorFluxo : IFirmwareSensorBase
|
||||||
{
|
{
|
||||||
|
public DateTime Momento { get; set; }
|
||||||
public string ID { get; set; }
|
public string ID { get; set; }
|
||||||
|
public int ID_Num { get; set; }
|
||||||
public bool Iniciado { get; set; }
|
public bool Iniciado { get; set; }
|
||||||
private double _vazao;
|
private double _vazao;
|
||||||
public double Vazao
|
public double Vazao
|
||||||
|
|
@ -1546,7 +1528,7 @@ namespace AgroBase.Models.Modules
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var sensor = Variaveis.OperacaoEmAndamento.DispAtu.Dados.Sensores.FirstOrDefault(x => x.ID == ID);
|
var sensor = Variaveis.OperacaoEmAndamento.DispAtu.Dados.Sensores.FirstOrDefault(x => x.ID_Num == ID_Num);
|
||||||
if (sensor != null)
|
if (sensor != null)
|
||||||
{
|
{
|
||||||
return sensor.LimiteMaximo;
|
return sensor.LimiteMaximo;
|
||||||
|
|
@ -1558,7 +1540,7 @@ namespace AgroBase.Models.Modules
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var sensor = Variaveis.OperacaoEmAndamento.DispAtu.Dados.Sensores.FirstOrDefault(x => x.ID == ID);
|
var sensor = Variaveis.OperacaoEmAndamento.DispAtu.Dados.Sensores.FirstOrDefault(x => x.ID_Num == ID_Num);
|
||||||
if (sensor != null)
|
if (sensor != null)
|
||||||
{
|
{
|
||||||
return sensor.LimiteMinimo;
|
return sensor.LimiteMinimo;
|
||||||
|
|
@ -1583,7 +1565,9 @@ namespace AgroBase.Models.Modules
|
||||||
|
|
||||||
public class FirmwareSensorMassa : IFirmwareSensorBase
|
public class FirmwareSensorMassa : IFirmwareSensorBase
|
||||||
{
|
{
|
||||||
|
public DateTime Momento { get; set; }
|
||||||
public string ID { get; set; }
|
public string ID { get; set; }
|
||||||
|
public int ID_Num { get; set; }
|
||||||
public bool Iniciado { get; set; }
|
public bool Iniciado { get; set; }
|
||||||
private double _massa;
|
private double _massa;
|
||||||
public double Massa
|
public double Massa
|
||||||
|
|
@ -1604,7 +1588,7 @@ namespace AgroBase.Models.Modules
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var sensor = Variaveis.OperacaoEmAndamento.DispAtu.Dados.Sensores.FirstOrDefault(x => x.ID == ID);
|
var sensor = Variaveis.OperacaoEmAndamento.DispAtu.Dados.Sensores.FirstOrDefault(x => x.ID_Num == ID_Num);
|
||||||
if (sensor != null)
|
if (sensor != null)
|
||||||
{
|
{
|
||||||
return sensor.LimiteMaximo;
|
return sensor.LimiteMaximo;
|
||||||
|
|
@ -1616,7 +1600,7 @@ namespace AgroBase.Models.Modules
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var sensor = Variaveis.OperacaoEmAndamento.DispAtu.Dados.Sensores.FirstOrDefault(x => x.ID == ID);
|
var sensor = Variaveis.OperacaoEmAndamento.DispAtu.Dados.Sensores.FirstOrDefault(x => x.ID_Num == ID_Num);
|
||||||
if (sensor != null)
|
if (sensor != null)
|
||||||
{
|
{
|
||||||
return sensor.LimiteMinimo;
|
return sensor.LimiteMinimo;
|
||||||
|
|
@ -1641,14 +1625,18 @@ namespace AgroBase.Models.Modules
|
||||||
|
|
||||||
public class FirmwareSensorPressao : IFirmwareSensorBase
|
public class FirmwareSensorPressao : IFirmwareSensorBase
|
||||||
{
|
{
|
||||||
|
public DateTime Momento { get; set; }
|
||||||
public string ID { get; set; }
|
public string ID { get; set; }
|
||||||
|
public int ID_Num { get; set; }
|
||||||
public bool Iniciado { get; set; }
|
public bool Iniciado { get; set; }
|
||||||
public double Pressao { get; set; }
|
public double Pressao { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class FirmwareSensorPotenciometro : IFirmwareSensorBase
|
public class FirmwareSensorPotenciometro : IFirmwareSensorBase
|
||||||
{
|
{
|
||||||
|
public DateTime Momento { get; set; }
|
||||||
public string ID { get; set; }
|
public string ID { get; set; }
|
||||||
|
public int ID_Num { get; set; }
|
||||||
public bool Iniciado { get; set; }
|
public bool Iniciado { get; set; }
|
||||||
public int Leitura { get; set; }
|
public int Leitura { get; set; }
|
||||||
public double Angulo { get; set; }
|
public double Angulo { get; set; }
|
||||||
|
|
@ -1659,7 +1647,7 @@ namespace AgroBase.Models.Modules
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
// Verifica se há um sensor ativo
|
// Verifica se há um sensor ativo
|
||||||
SensorModel Sensor = Variaveis.OperacaoEmAndamento.DispSen?.Dados?.Sensores?.FirstOrDefault(x => x.ID == ID);
|
SensorModel Sensor = Variaveis.OperacaoEmAndamento.DispSen?.Dados?.Sensores?.FirstOrDefault(x => x.ID_Num == ID_Num);
|
||||||
if (Sensor == null)
|
if (Sensor == null)
|
||||||
{
|
{
|
||||||
return StatusSensorPotenciometro.Indefinido;
|
return StatusSensorPotenciometro.Indefinido;
|
||||||
|
|
@ -1700,7 +1688,7 @@ namespace AgroBase.Models.Modules
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var sensor = Variaveis.OperacaoEmAndamento.DispSen?.Dados?.Sensores?.FirstOrDefault(x => x.ID == ID);
|
var sensor = Variaveis.OperacaoEmAndamento.DispSen?.Dados?.Sensores?.FirstOrDefault(x => x.ID_Num == ID_Num);
|
||||||
if (sensor != null)
|
if (sensor != null)
|
||||||
{
|
{
|
||||||
return sensor.LimiteMaximo;
|
return sensor.LimiteMaximo;
|
||||||
|
|
@ -1712,7 +1700,7 @@ namespace AgroBase.Models.Modules
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var sensor = Variaveis.OperacaoEmAndamento.DispSen?.Dados?.Sensores?.FirstOrDefault(x => x.ID == ID);
|
var sensor = Variaveis.OperacaoEmAndamento.DispSen?.Dados?.Sensores?.FirstOrDefault(x => x.ID_Num == ID_Num);
|
||||||
if (sensor != null)
|
if (sensor != null)
|
||||||
{
|
{
|
||||||
return sensor.LimiteMinimo;
|
return sensor.LimiteMinimo;
|
||||||
|
|
@ -1724,7 +1712,9 @@ namespace AgroBase.Models.Modules
|
||||||
|
|
||||||
public class FirmwareSensorIMU : IFirmwareSensorBase
|
public class FirmwareSensorIMU : IFirmwareSensorBase
|
||||||
{
|
{
|
||||||
|
public DateTime Momento { get; set; }
|
||||||
public string ID { get; set; }
|
public string ID { get; set; }
|
||||||
|
public int ID_Num { get; set; }
|
||||||
public bool Iniciado { get; set; }
|
public bool Iniciado { get; set; }
|
||||||
public double AccX { get; set; }
|
public double AccX { get; set; }
|
||||||
public double AccY { get; set; }
|
public double AccY { get; set; }
|
||||||
|
|
@ -1776,7 +1766,7 @@ namespace AgroBase.Models.Modules
|
||||||
{
|
{
|
||||||
return new FirmwareSensorIMU()
|
return new FirmwareSensorIMU()
|
||||||
{
|
{
|
||||||
ID = ID,
|
ID_Num = ID_Num,
|
||||||
Iniciado = Iniciado,
|
Iniciado = Iniciado,
|
||||||
Pitch = Pitch,
|
Pitch = Pitch,
|
||||||
Roll = Roll,
|
Roll = Roll,
|
||||||
|
|
@ -1857,12 +1847,13 @@ namespace AgroBase.Models.Modules
|
||||||
case S_Code.sTMP:
|
case S_Code.sTMP:
|
||||||
{
|
{
|
||||||
var sensor = Disp.Dados.Sensores.FirstOrDefault(x => x.ID_Num == CompID_Num);
|
var sensor = Disp.Dados.Sensores.FirstOrDefault(x => x.ID_Num == CompID_Num);
|
||||||
var _sensor = item.SensoresTemperatura.FirstOrDefault(x => x.ID == sensor.ID);
|
var _sensor = item.SensoresTemperatura.FirstOrDefault(x => x.ID_Num == sensor.ID_Num);
|
||||||
if (_sensor == null)
|
if (_sensor == null)
|
||||||
{
|
{
|
||||||
_sensor = new FirmwareSensorTemperatura()
|
_sensor = new FirmwareSensorTemperatura()
|
||||||
{
|
{
|
||||||
ID = sensor.ID,
|
ID = sensor.ID,
|
||||||
|
ID_Num = CompID_Num,
|
||||||
Iniciado = false,
|
Iniciado = false,
|
||||||
Temperatura = -1,
|
Temperatura = -1,
|
||||||
};
|
};
|
||||||
|
|
@ -1883,18 +1874,20 @@ namespace AgroBase.Models.Modules
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_sensor.Momento = DateTime.Now;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case S_Code.sCOR:
|
case S_Code.sCOR:
|
||||||
{
|
{
|
||||||
var sensor = Disp.Dados.Sensores.FirstOrDefault(x => x.ID_Num == CompID_Num);
|
var sensor = Disp.Dados.Sensores.FirstOrDefault(x => x.ID_Num == CompID_Num);
|
||||||
var _sensor = item.SensoresCorrente.FirstOrDefault(x => x.ID == sensor.ID);
|
var _sensor = item.SensoresCorrente.FirstOrDefault(x => x.ID_Num == sensor.ID_Num);
|
||||||
if (_sensor == null)
|
if (_sensor == null)
|
||||||
{
|
{
|
||||||
_sensor = new FirmwareSensorCorrente()
|
_sensor = new FirmwareSensorCorrente()
|
||||||
{
|
{
|
||||||
ID = sensor.ID,
|
ID = sensor.ID,
|
||||||
|
ID_Num = CompID_Num,
|
||||||
Iniciado = false,
|
Iniciado = false,
|
||||||
BusVoltage = -1,
|
BusVoltage = -1,
|
||||||
Current = -1,
|
Current = -1,
|
||||||
|
|
@ -1920,18 +1913,20 @@ namespace AgroBase.Models.Modules
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_sensor.Momento = DateTime.Now;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case S_Code.sLED:
|
case S_Code.sLED:
|
||||||
{
|
{
|
||||||
var sensor = Disp.Dados.Sinaleiros.FirstOrDefault(x => x.ID_Num == CompID_Num);
|
var sensor = Disp.Dados.Sinaleiros.FirstOrDefault(x => x.ID_Num == CompID_Num);
|
||||||
var _sensor = item.Sinaleiros.FirstOrDefault(x => x.ID == sensor.ID);
|
var _sensor = item.Sinaleiros.FirstOrDefault(x => x.ID_Num == sensor.ID_Num);
|
||||||
if (_sensor == null)
|
if (_sensor == null)
|
||||||
{
|
{
|
||||||
_sensor = new FirmwareSinaleiro()
|
_sensor = new FirmwareSinaleiro()
|
||||||
{
|
{
|
||||||
ID = sensor.ID,
|
ID = sensor.ID,
|
||||||
|
ID_Num = CompID_Num,
|
||||||
Iniciado = false,
|
Iniciado = false,
|
||||||
Comando = StatusLED.Apagado,
|
Comando = StatusLED.Apagado,
|
||||||
Leitura = StatusLED.Apagado,
|
Leitura = StatusLED.Apagado,
|
||||||
|
|
@ -1954,18 +1949,20 @@ namespace AgroBase.Models.Modules
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_sensor.Momento = DateTime.Now;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case S_Code.sRLE:
|
case S_Code.sRLE:
|
||||||
{
|
{
|
||||||
var sensor = Disp.Dados.Reles.FirstOrDefault(x => x.ID_Num == CompID_Num);
|
var sensor = Disp.Dados.Reles.FirstOrDefault(x => x.ID_Num == CompID_Num);
|
||||||
var _sensor = item.Reles.FirstOrDefault(x => x.ID == sensor.ID);
|
var _sensor = item.Reles.FirstOrDefault(x => x.ID_Num == sensor.ID_Num);
|
||||||
if (_sensor == null)
|
if (_sensor == null)
|
||||||
{
|
{
|
||||||
_sensor = new FirmwareRele()
|
_sensor = new FirmwareRele()
|
||||||
{
|
{
|
||||||
ID = sensor.ID,
|
ID = sensor.ID,
|
||||||
|
ID_Num = CompID_Num,
|
||||||
Iniciado = false,
|
Iniciado = false,
|
||||||
Leitura = Estado.Desligado,
|
Leitura = Estado.Desligado,
|
||||||
};
|
};
|
||||||
|
|
@ -1986,18 +1983,20 @@ namespace AgroBase.Models.Modules
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_sensor.Momento = DateTime.Now;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case S_Code.sFRO:
|
case S_Code.sFRO:
|
||||||
{
|
{
|
||||||
var sensor = Disp.Dados.Servos.FirstOrDefault(x => x.ID_Num == CompID_Num);
|
var sensor = Disp.Dados.Servos.FirstOrDefault(x => x.ID_Num == CompID_Num);
|
||||||
var _sensor = item.ServoFreios.FirstOrDefault(x => x.ID == sensor.ID);
|
var _sensor = item.ServoFreios.FirstOrDefault(x => x.ID_Num == sensor.ID_Num);
|
||||||
if (_sensor == null)
|
if (_sensor == null)
|
||||||
{
|
{
|
||||||
_sensor = new FirmwareServoFreio()
|
_sensor = new FirmwareServoFreio()
|
||||||
{
|
{
|
||||||
ID = sensor.ID,
|
ID = sensor.ID,
|
||||||
|
ID_Num = CompID_Num,
|
||||||
Iniciado = false,
|
Iniciado = false,
|
||||||
Angulo = -1,
|
Angulo = -1,
|
||||||
};
|
};
|
||||||
|
|
@ -2018,18 +2017,20 @@ namespace AgroBase.Models.Modules
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_sensor.Momento = DateTime.Now;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case S_Code.sIMU:
|
case S_Code.sIMU:
|
||||||
{
|
{
|
||||||
var sensor = Disp.Dados.Sensores.FirstOrDefault(x => x.ID_Num == CompID_Num);
|
var sensor = Disp.Dados.Sensores.FirstOrDefault(x => x.ID_Num == CompID_Num);
|
||||||
var _sensor = item.SensoresIMU.FirstOrDefault(x => x.ID == sensor.ID);
|
var _sensor = item.SensoresIMU.FirstOrDefault(x => x.ID_Num == sensor.ID_Num);
|
||||||
if (_sensor == null)
|
if (_sensor == null)
|
||||||
{
|
{
|
||||||
_sensor = new FirmwareSensorIMU()
|
_sensor = new FirmwareSensorIMU()
|
||||||
{
|
{
|
||||||
ID = sensor.ID,
|
ID = sensor.ID,
|
||||||
|
ID_Num = CompID_Num,
|
||||||
Iniciado = false,
|
Iniciado = false,
|
||||||
AccX = -1,
|
AccX = -1,
|
||||||
AccY = -1,
|
AccY = -1,
|
||||||
|
|
@ -2046,6 +2047,7 @@ namespace AgroBase.Models.Modules
|
||||||
Pitch = -1,
|
Pitch = -1,
|
||||||
Roll = -1,
|
Roll = -1,
|
||||||
Yaw = -1,
|
Yaw = -1,
|
||||||
|
Offset = 0,
|
||||||
};
|
};
|
||||||
item.SensoresIMU.Add(_sensor);
|
item.SensoresIMU.Add(_sensor);
|
||||||
}
|
}
|
||||||
|
|
@ -2094,6 +2096,7 @@ namespace AgroBase.Models.Modules
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_sensor.Momento = DateTime.Now;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -2112,7 +2115,7 @@ namespace AgroBase.Models.Modules
|
||||||
|
|
||||||
S_Code componente = DetectarComponenteDoID_Num(ID_Num);
|
S_Code componente = DetectarComponenteDoID_Num(ID_Num);
|
||||||
|
|
||||||
Console.WriteLine($"[SEN] Componente={componente.ToString()}, ID_Num={ID_Num}, Posicao={posicao.ToString()}, Data={FuncoesGlobais.ConverterComandoBytesParaTexto(data)}");
|
//Console.WriteLine($"[SEN] Componente={componente.ToString()}, ID_Num={ID_Num}, Posicao={posicao.ToString()}, Data={FuncoesGlobais.ConverterComandoBytesParaTexto(data)}");
|
||||||
|
|
||||||
switch (posicao)
|
switch (posicao)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ public class EthernetService
|
||||||
|
|
||||||
if (completedTask == connectTaskCompletionSource.Task && await connectTaskCompletionSource.Task)
|
if (completedTask == connectTaskCompletionSource.Task && await connectTaskCompletionSource.Task)
|
||||||
{
|
{
|
||||||
if (_client.Connected)
|
if (_client?.Connected ?? false)
|
||||||
{
|
{
|
||||||
_networkStream = _client.GetStream();
|
_networkStream = _client.GetStream();
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -78,7 +78,7 @@ public class EthernetService
|
||||||
|
|
||||||
// Timeout foi atingido; limpa a conexão
|
// Timeout foi atingido; limpa a conexão
|
||||||
Console.WriteLine("Conexão cancelada devido ao timeout.");
|
Console.WriteLine("Conexão cancelada devido ao timeout.");
|
||||||
_client.Dispose();
|
_client?.Dispose();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,14 @@
|
||||||
using AgroBase.Models.Modules;
|
using AgroBase.Models.Modules;
|
||||||
|
using System;
|
||||||
using static AgroBase.Models.Enums;
|
using static AgroBase.Models.Enums;
|
||||||
|
|
||||||
namespace AgroBase.Services
|
namespace AgroBase.Services
|
||||||
{
|
{
|
||||||
public interface IFirmwareSensorBase
|
public interface IFirmwareSensorBase
|
||||||
{
|
{
|
||||||
|
DateTime Momento { get; set; }
|
||||||
string ID { get; set; }
|
string ID { get; set; }
|
||||||
|
int ID_Num { get; set; }
|
||||||
bool Iniciado { get; set; }
|
bool Iniciado { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -142,6 +142,7 @@ namespace AgroBase.Services
|
||||||
|
|
||||||
if (!EnviarComando(porta, comando))
|
if (!EnviarComando(porta, comando))
|
||||||
{
|
{
|
||||||
|
await AlterarStatusReleModo(Estado.Desligado);
|
||||||
porta.Close();
|
porta.Close();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -722,19 +723,27 @@ namespace AgroBase.Services
|
||||||
|
|
||||||
public static bool EnviarComando(SerialPort _Porta, byte[] Comando)
|
public static bool EnviarComando(SerialPort _Porta, byte[] Comando)
|
||||||
{
|
{
|
||||||
if (_Porta != null)
|
try
|
||||||
{
|
{
|
||||||
if (!_Porta.IsOpen)
|
if (_Porta != null)
|
||||||
{
|
{
|
||||||
_Porta.Open();
|
if (!_Porta.IsOpen)
|
||||||
}
|
{
|
||||||
if (_Porta.IsOpen)
|
_Porta.Open();
|
||||||
{
|
}
|
||||||
Console.WriteLine($"Dados enviados LoRa: {Comando.Length}");
|
if (_Porta.IsOpen)
|
||||||
MensagensEnviadas++;
|
{
|
||||||
return SerialService.EnviarDadosPortaSerial(_Porta, Comando, 0, Comando.Length);
|
Console.WriteLine($"Dados enviados LoRa: {Comando.Length}");
|
||||||
|
MensagensEnviadas++;
|
||||||
|
return SerialService.EnviarDadosPortaSerial(_Porta, Comando, 0, Comando.Length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -25,7 +25,7 @@
|
||||||
<meta name="viewport" content="width=device-width,
|
<meta name="viewport" content="width=device-width,
|
||||||
initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
||||||
<style>
|
<style>
|
||||||
#map_e4b836c188aa7a7f34596e791f687835 {
|
#map_d89f9773ee899027809e6745084649e1 {
|
||||||
position: relative;
|
position: relative;
|
||||||
width: 100.0%;
|
width: 100.0%;
|
||||||
height: 100.0%;
|
height: 100.0%;
|
||||||
|
|
@ -39,14 +39,14 @@
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
|
||||||
<div class="folium-map" id="map_e4b836c188aa7a7f34596e791f687835" ></div>
|
<div class="folium-map" id="map_d89f9773ee899027809e6745084649e1" ></div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
|
|
||||||
var map_e4b836c188aa7a7f34596e791f687835 = L.map(
|
var map_d89f9773ee899027809e6745084649e1 = L.map(
|
||||||
"map_e4b836c188aa7a7f34596e791f687835",
|
"map_d89f9773ee899027809e6745084649e1",
|
||||||
{
|
{
|
||||||
center: [0.0, 0.0],
|
center: [0.0, 0.0],
|
||||||
crs: L.CRS.EPSG3857,
|
crs: L.CRS.EPSG3857,
|
||||||
|
|
@ -60,13 +60,13 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var tile_layer_e22f90836b9c7fe4833b37ff793d8e6b = L.tileLayer(
|
var tile_layer_eb04a0a8d26a9cc90463b40733770d06 = L.tileLayer(
|
||||||
"https://tile.openstreetmap.org/{z}/{x}/{y}.png",
|
"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}
|
{"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_e22f90836b9c7fe4833b37ff793d8e6b.addTo(map_e4b836c188aa7a7f34596e791f687835);
|
tile_layer_eb04a0a8d26a9cc90463b40733770d06.addTo(map_d89f9773ee899027809e6745084649e1);
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
@ -87,7 +87,7 @@
|
||||||
}
|
}
|
||||||
trajeto_json_add({"features": []});
|
trajeto_json_add({"features": []});
|
||||||
|
|
||||||
trajeto_json.addTo(map_e4b836c188aa7a7f34596e791f687835);
|
trajeto_json.addTo(map_d89f9773ee899027809e6745084649e1);
|
||||||
|
|
||||||
function adicionarGeometria(novaGeometria) {
|
function adicionarGeometria(novaGeometria) {
|
||||||
trajeto_json.addData(novaGeometria);
|
trajeto_json.addData(novaGeometria);
|
||||||
|
|
@ -145,7 +145,7 @@
|
||||||
|
|
||||||
var marcadorDinamico = L.marker([0, 0], {
|
var marcadorDinamico = L.marker([0, 0], {
|
||||||
icon: customIcon
|
icon: customIcon
|
||||||
}).addTo(map_e4b836c188aa7a7f34596e791f687835);
|
}).addTo(map_d89f9773ee899027809e6745084649e1);
|
||||||
|
|
||||||
// Conectar ao broker MQTT
|
// Conectar ao broker MQTT
|
||||||
const client = mqtt.connect('ws://localhost:9001'); // Use wss para conexão segura
|
const client = mqtt.connect('ws://localhost:9001'); // Use wss para conexão segura
|
||||||
|
|
@ -183,7 +183,7 @@
|
||||||
marcadorDinamico.setRotationAngle(angulo);
|
marcadorDinamico.setRotationAngle(angulo);
|
||||||
|
|
||||||
adicionarCoordenada("Tj", [novaLongitude, novaLatitude]);
|
adicionarCoordenada("Tj", [novaLongitude, novaLatitude]);
|
||||||
map_e4b836c188aa7a7f34596e791f687835.setView(novaPosicao, map_e4b836c188aa7a7f34596e791f687835.getZoom());
|
map_d89f9773ee899027809e6745084649e1.setView(novaPosicao, map_d89f9773ee899027809e6745084649e1.getZoom());
|
||||||
});
|
});
|
||||||
|
|
||||||
function calcularOrientacao(P1latitude, P1longitude, P2latitude, P2longitude) {
|
function calcularOrientacao(P1latitude, P1longitude, P2latitude, P2longitude) {
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -26,11 +26,13 @@ const String Mod_ID = "Atu";
|
||||||
#define _pinoLED RGB_BUILTIN
|
#define _pinoLED RGB_BUILTIN
|
||||||
|
|
||||||
bool Conectado = false;
|
bool Conectado = false;
|
||||||
bool Verificando = false;
|
bool Conectar = false;
|
||||||
|
|
||||||
int _TaxaAmostragem = 1000;
|
int _TaxaAmostragem = 1000;
|
||||||
volatile bool RequisitarDados = false;
|
volatile bool RequisitarDados = false;
|
||||||
int latenciaLoop = 0;
|
int latenciaLoop = 0;
|
||||||
|
int qtdEnviosStatus = 0;
|
||||||
|
int maxEnviosStatus = 5;
|
||||||
|
|
||||||
PinoModel _pinoSDA = PinoModel(1, CONTROLADOR, _INPUT);
|
PinoModel _pinoSDA = PinoModel(1, CONTROLADOR, _INPUT);
|
||||||
PinoModel _pinoSCL = PinoModel(2, CONTROLADOR, _INPUT);
|
PinoModel _pinoSCL = PinoModel(2, CONTROLADOR, _INPUT);
|
||||||
|
|
@ -95,13 +97,18 @@ void enviarLogsPeriodicamente() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void enviarDadosSensores() {
|
void enviarDadosSensores() {
|
||||||
if (Conectado && !Verificando) {
|
if (Conectado) {
|
||||||
PrintTela("Atualizando dados dos sensores...");
|
PrintTela("Atualizando dados dos sensores...");
|
||||||
|
|
||||||
|
bool enviarStatus = qtdEnviosStatus >= maxEnviosStatus;
|
||||||
|
|
||||||
// Aferir dados dos sensores
|
// Aferir dados dos sensores
|
||||||
for (auto* bico : listaBicos) {
|
for (auto* bico : listaBicos) {
|
||||||
if (bico != nullptr) {
|
if (bico != nullptr) {
|
||||||
bico->RequisitarDados();
|
bico->RequisitarDados();
|
||||||
|
if (enviarStatus) {
|
||||||
|
EnviarDadosCAN(bico->MontarMensagemCAN(CanMessagePosicaoDados::Status));
|
||||||
|
}
|
||||||
EnviarDadosCAN(bico->MontarMensagemCAN(CanMessagePosicaoDados::Dados1));
|
EnviarDadosCAN(bico->MontarMensagemCAN(CanMessagePosicaoDados::Dados1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -110,6 +117,9 @@ void enviarDadosSensores() {
|
||||||
for (auto* sensor : listaSensoresFluxo) {
|
for (auto* sensor : listaSensoresFluxo) {
|
||||||
if (sensor != nullptr) {
|
if (sensor != nullptr) {
|
||||||
sensor->RequisitarDados();
|
sensor->RequisitarDados();
|
||||||
|
if (enviarStatus) {
|
||||||
|
EnviarDadosCAN(sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status));
|
||||||
|
}
|
||||||
EnviarDadosCAN(sensor->MontarMensagemCAN(CanMessagePosicaoDados::Dados1));
|
EnviarDadosCAN(sensor->MontarMensagemCAN(CanMessagePosicaoDados::Dados1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -118,6 +128,9 @@ void enviarDadosSensores() {
|
||||||
for (auto* sensor : listaSensoresMassa) {
|
for (auto* sensor : listaSensoresMassa) {
|
||||||
if (sensor != nullptr) {
|
if (sensor != nullptr) {
|
||||||
sensor->RequisitarDados();
|
sensor->RequisitarDados();
|
||||||
|
if (enviarStatus) {
|
||||||
|
EnviarDadosCAN(sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status));
|
||||||
|
}
|
||||||
EnviarDadosCAN(sensor->MontarMensagemCAN(CanMessagePosicaoDados::Dados1));
|
EnviarDadosCAN(sensor->MontarMensagemCAN(CanMessagePosicaoDados::Dados1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -126,6 +139,9 @@ void enviarDadosSensores() {
|
||||||
for (auto* sensor : listaSensoresPressao) {
|
for (auto* sensor : listaSensoresPressao) {
|
||||||
if (sensor != nullptr) {
|
if (sensor != nullptr) {
|
||||||
sensor->RequisitarDados();
|
sensor->RequisitarDados();
|
||||||
|
if (enviarStatus) {
|
||||||
|
EnviarDadosCAN(sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status));
|
||||||
|
}
|
||||||
EnviarDadosCAN(sensor->MontarMensagemCAN(CanMessagePosicaoDados::Dados1));
|
EnviarDadosCAN(sensor->MontarMensagemCAN(CanMessagePosicaoDados::Dados1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -134,9 +150,20 @@ void enviarDadosSensores() {
|
||||||
for (auto* bomba : listaBombas) {
|
for (auto* bomba : listaBombas) {
|
||||||
if (bomba != nullptr) {
|
if (bomba != nullptr) {
|
||||||
bomba->RequisitarDados();
|
bomba->RequisitarDados();
|
||||||
|
if (enviarStatus) {
|
||||||
|
EnviarDadosCAN(bomba->MontarMensagemCAN(CanMessagePosicaoDados::Status));
|
||||||
|
}
|
||||||
EnviarDadosCAN(bomba->MontarMensagemCAN(CanMessagePosicaoDados::Dados1));
|
EnviarDadosCAN(bomba->MontarMensagemCAN(CanMessagePosicaoDados::Dados1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (enviarStatus) {
|
||||||
|
qtdEnviosStatus = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
qtdEnviosStatus++;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -162,10 +189,8 @@ void ProcessarFrameCAN(std::vector<uint8_t> data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessarChk() {
|
void ProcessarChk() {
|
||||||
Verificando = true;
|
|
||||||
std::vector<uint8_t> data = canService.MontarFrameChk(D_Code, Conectado, VERSION);
|
std::vector<uint8_t> data = canService.MontarFrameChk(D_Code, Conectado, VERSION);
|
||||||
EnviarDadosCAN(data);
|
EnviarDadosCAN(data);
|
||||||
Verificando = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessarReq() {
|
void ProcessarReq() {
|
||||||
|
|
@ -188,7 +213,7 @@ void ProcessarCfg(std::vector<uint8_t> data) {
|
||||||
bool requisitar = data[6] == 1;
|
bool requisitar = data[6] == 1;
|
||||||
_TaxaAmostragem = taxa;
|
_TaxaAmostragem = taxa;
|
||||||
RequisitarDados = requisitar;
|
RequisitarDados = requisitar;
|
||||||
Conectado = conectar;
|
Conectar = conectar;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CanMessagePosicaoDados::Config2: {
|
case CanMessagePosicaoDados::Config2: {
|
||||||
|
|
@ -203,9 +228,9 @@ void ProcessarCfg(std::vector<uint8_t> data) {
|
||||||
PrintTela("I2C inicializado nos pinos SDA=" + String(pinoSDA) + " e SCL=" + String(pinoSCL));
|
PrintTela("I2C inicializado nos pinos SDA=" + String(pinoSDA) + " e SCL=" + String(pinoSCL));
|
||||||
}
|
}
|
||||||
vTaskDelay(pdMS_TO_TICKS(100));
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
Verificando = false;
|
|
||||||
_chkRx = canService.MontarFrameChk(D_Code, Conectado, VERSION);
|
_chkRx = canService.MontarFrameChk(D_Code, Conectado, VERSION);
|
||||||
LimparListasComponentes();
|
LimparListasComponentes();
|
||||||
|
Conectado = Conectar;
|
||||||
PrintTela("Configuracao do modulo concluida");
|
PrintTela("Configuracao do modulo concluida");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -195,6 +195,8 @@ std::vector<uint8_t> BombaPressurizadora::ConfigurarBomba(std::vector<BombaPress
|
||||||
uint8_t idNum = data[1];
|
uint8_t idNum = data[1];
|
||||||
CanMessagePosicaoDados posicao = (CanMessagePosicaoDados)data[2];
|
CanMessagePosicaoDados posicao = (CanMessagePosicaoDados)data[2];
|
||||||
auto it = std::find_if(lista.begin(), lista.end(), [idNum](BombaPressurizadora* s) { return s->ID_Num == idNum; });
|
auto it = std::find_if(lista.begin(), lista.end(), [idNum](BombaPressurizadora* s) { return s->ID_Num == idNum; });
|
||||||
|
bool jaExiste = it != lista.end();
|
||||||
|
BombaPressurizadora* bomba;
|
||||||
switch (posicao) {
|
switch (posicao) {
|
||||||
case CanMessagePosicaoDados::Config1: {
|
case CanMessagePosicaoDados::Config1: {
|
||||||
if (data.size() < 8) return status;
|
if (data.size() < 8) return status;
|
||||||
|
|
@ -203,8 +205,13 @@ std::vector<uint8_t> BombaPressurizadora::ConfigurarBomba(std::vector<BombaPress
|
||||||
int pinoEn = data[6];
|
int pinoEn = data[6];
|
||||||
int pinoCs = data[7];
|
int pinoCs = data[7];
|
||||||
if (conectar) {
|
if (conectar) {
|
||||||
if (it == lista.end()) {
|
if (!jaExiste) {
|
||||||
BombaPressurizadora* bomba = new BombaPressurizadora(Mod_ID, "sBMB_" + String(idNum));
|
bomba = new BombaPressurizadora(Mod_ID, "sBMB_" + String(idNum));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
bomba = *it;
|
||||||
|
}
|
||||||
|
if (!bomba->Iniciado) {
|
||||||
if (sensoresPressao.size() > 0) {
|
if (sensoresPressao.size() > 0) {
|
||||||
if (sensoresPressao[0]->Iniciado) {
|
if (sensoresPressao[0]->Iniciado) {
|
||||||
bomba->sensorPressao = sensoresPressao[0];
|
bomba->sensorPressao = sensoresPressao[0];
|
||||||
|
|
@ -219,12 +226,15 @@ std::vector<uint8_t> BombaPressurizadora::ConfigurarBomba(std::vector<BombaPress
|
||||||
bomba->_pinoEN = PinoModel(pinoEn, CONTROLADOR, _OUTPUT);
|
bomba->_pinoEN = PinoModel(pinoEn, CONTROLADOR, _OUTPUT);
|
||||||
bomba->_pinoCS = PinoModel(pinoCs, CONTROLADOR, _INPUT);
|
bomba->_pinoCS = PinoModel(pinoCs, CONTROLADOR, _INPUT);
|
||||||
bomba->_PressaoSP = (double)pressaoSp;
|
bomba->_PressaoSP = (double)pressaoSp;
|
||||||
lista.push_back(bomba);
|
if (!jaExiste) {
|
||||||
PrintTela("Bomba Pressurizadora adicionado via CAN: sBMB_" + String(idNum));
|
lista.push_back(bomba);
|
||||||
|
PrintTela("Bomba Pressurizadora adicionado via CAN: sBMB_" + String(idNum));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
//status = bomba->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
||||||
} else {
|
} else {
|
||||||
if (it != lista.end()) {
|
if (jaExiste) {
|
||||||
BombaPressurizadora* bomba = *it;
|
bomba = *it;
|
||||||
bomba->Desligar();
|
bomba->Desligar();
|
||||||
status = bomba->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
status = bomba->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
||||||
delete bomba;
|
delete bomba;
|
||||||
|
|
@ -236,18 +246,20 @@ std::vector<uint8_t> BombaPressurizadora::ConfigurarBomba(std::vector<BombaPress
|
||||||
}
|
}
|
||||||
case CanMessagePosicaoDados::Config2: {
|
case CanMessagePosicaoDados::Config2: {
|
||||||
if (data.size() < 7) return status;
|
if (data.size() < 7) return status;
|
||||||
if (it == lista.end()) return status;
|
if (!jaExiste) return status;
|
||||||
|
|
||||||
int pinoIna = data[4];
|
int pinoIna = data[4];
|
||||||
int pinoInb = data[5];
|
int pinoInb = data[5];
|
||||||
int pinoPwm = data[6];
|
int pinoPwm = data[6];
|
||||||
|
|
||||||
BombaPressurizadora* bomba = *it;
|
bomba = *it;
|
||||||
bomba->_pinoINA = PinoModel(pinoIna, CONTROLADOR, _OUTPUT);
|
if (!bomba->Iniciado) {
|
||||||
bomba->_pinoINB = PinoModel(pinoInb, CONTROLADOR, _OUTPUT);
|
bomba->_pinoINA = PinoModel(pinoIna, CONTROLADOR, _OUTPUT);
|
||||||
bomba->_pinoPWM = PinoModel(pinoPwm, CONTROLADOR, _PWM);
|
bomba->_pinoINB = PinoModel(pinoInb, CONTROLADOR, _OUTPUT);
|
||||||
bomba->Inicializar();
|
bomba->_pinoPWM = PinoModel(pinoPwm, CONTROLADOR, _PWM);
|
||||||
PrintTela("Bomba Pressurizadora adicionado via CAN: sBMB_" + String(bomba->ID_Num));
|
bomba->Inicializar();
|
||||||
|
PrintTela("Bomba Pressurizadora adicionado via CAN: sBMB_" + String(bomba->ID_Num));
|
||||||
|
}
|
||||||
status = bomba->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
status = bomba->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -111,6 +111,9 @@ std::vector<uint8_t> Rele::ConfigurarRele(std::vector<Rele*>& lista, std::vector
|
||||||
if (data.size() < 3) return status;
|
if (data.size() < 3) return status;
|
||||||
uint8_t idNum = data[1];
|
uint8_t idNum = data[1];
|
||||||
CanMessagePosicaoDados posicao = (CanMessagePosicaoDados)data[2];
|
CanMessagePosicaoDados posicao = (CanMessagePosicaoDados)data[2];
|
||||||
|
auto it = std::find_if(lista.begin(), lista.end(), [idNum](Rele* s) { return s->ID_Num == idNum; });
|
||||||
|
bool jaExiste = it != lista.end();
|
||||||
|
Rele* sensor;
|
||||||
switch (posicao) {
|
switch (posicao) {
|
||||||
case CanMessagePosicaoDados::Config1: {
|
case CanMessagePosicaoDados::Config1: {
|
||||||
if (data.size() < 8) return status;
|
if (data.size() < 8) return status;
|
||||||
|
|
@ -118,21 +121,27 @@ std::vector<uint8_t> Rele::ConfigurarRele(std::vector<Rele*>& lista, std::vector
|
||||||
bool atuacaoNivelAlto = data[5] == 1;
|
bool atuacaoNivelAlto = data[5] == 1;
|
||||||
TiposBarramentos tipoBarramento = (TiposBarramentos)data[6];
|
TiposBarramentos tipoBarramento = (TiposBarramentos)data[6];
|
||||||
int pino = data[7];
|
int pino = data[7];
|
||||||
auto it = std::find_if(lista.begin(), lista.end(), [idNum](Rele* s) { return s->ID_Num == idNum; });
|
|
||||||
if (conectar) {
|
if (conectar) {
|
||||||
if (it == lista.end()) {
|
if (!jaExiste) {
|
||||||
Rele* sensor = new Rele(Mod_ID, "sRLE_" + String(idNum));
|
sensor = new Rele(Mod_ID, "sRLE_" + String(idNum));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sensor = *it;
|
||||||
|
}
|
||||||
|
if (!sensor->Iniciado) {
|
||||||
sensor->ID_Num = idNum;
|
sensor->ID_Num = idNum;
|
||||||
sensor->_pino = PinoModel(pino, tipoBarramento, _OUTPUT);
|
sensor->_pino = PinoModel(pino, tipoBarramento, _OUTPUT);
|
||||||
sensor->AtuacaoNivelAlto = atuacaoNivelAlto;
|
sensor->AtuacaoNivelAlto = atuacaoNivelAlto;
|
||||||
sensor->Inicializar();
|
sensor->Inicializar();
|
||||||
lista.push_back(sensor);
|
if (!jaExiste) {
|
||||||
PrintTela("Rele adicionado via CAN: sRLE_" + String(idNum));
|
lista.push_back(sensor);
|
||||||
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
PrintTela("Rele adicionado via CAN: sRLE_" + String(idNum));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
||||||
} else {
|
} else {
|
||||||
if (it != lista.end()) {
|
if (jaExiste) {
|
||||||
Rele* sensor = *it;
|
sensor = *it;
|
||||||
sensor->Desligar();
|
sensor->Desligar();
|
||||||
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
||||||
delete sensor;
|
delete sensor;
|
||||||
|
|
|
||||||
|
|
@ -131,6 +131,9 @@ std::vector<uint8_t> SensorCorrente::ConfigurarSensor(std::vector<SensorCorrente
|
||||||
if (data.size() < 3) return status;
|
if (data.size() < 3) return status;
|
||||||
uint8_t idNum = data[1];
|
uint8_t idNum = data[1];
|
||||||
CanMessagePosicaoDados posicao = (CanMessagePosicaoDados)data[2];
|
CanMessagePosicaoDados posicao = (CanMessagePosicaoDados)data[2];
|
||||||
|
auto it = std::find_if(lista.begin(), lista.end(), [idNum](SensorCorrente* s) { return s->ID_Num == idNum; });
|
||||||
|
bool jaExiste = it != lista.end();
|
||||||
|
SensorCorrente* sensor;
|
||||||
switch (posicao) {
|
switch (posicao) {
|
||||||
case CanMessagePosicaoDados::Config1: {
|
case CanMessagePosicaoDados::Config1: {
|
||||||
if (data.size() < 8) return status;
|
if (data.size() < 8) return status;
|
||||||
|
|
@ -139,28 +142,27 @@ std::vector<uint8_t> SensorCorrente::ConfigurarSensor(std::vector<SensorCorrente
|
||||||
// _a_max vem como float*100 => uint16_t
|
// _a_max vem como float*100 => uint16_t
|
||||||
uint16_t aMaxInt = ((uint16_t)data[6] << 8) | data[7];
|
uint16_t aMaxInt = ((uint16_t)data[6] << 8) | data[7];
|
||||||
float aMax = aMaxInt / 100.0;
|
float aMax = aMaxInt / 100.0;
|
||||||
auto it = std::find_if(lista.begin(), lista.end(), [idNum](SensorCorrente* s) { return s->ID_Num == idNum; });
|
|
||||||
bool existente = (it != lista.end());
|
|
||||||
if (conectar) {
|
if (conectar) {
|
||||||
SensorCorrente* sensor;
|
if (!jaExiste) {
|
||||||
if (!existente) {
|
|
||||||
sensor = new SensorCorrente(Mod_ID, "sCOR_" + String(idNum));
|
sensor = new SensorCorrente(Mod_ID, "sCOR_" + String(idNum));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sensor = *it;
|
sensor = *it;
|
||||||
}
|
}
|
||||||
sensor->ID_Num = idNum;
|
if (!sensor->Iniciado) {
|
||||||
sensor->_Endereco = endereco;
|
sensor->ID_Num = idNum;
|
||||||
sensor->_A_Shunt = aMax;
|
sensor->_Endereco = endereco;
|
||||||
sensor->Inicializar();
|
sensor->_A_Shunt = aMax;
|
||||||
if (!existente) {
|
sensor->Inicializar();
|
||||||
lista.push_back(sensor);
|
if (!jaExiste) {
|
||||||
PrintTela("Sensor de corrente adicionado via CAN: sCOR_" + String(idNum));
|
lista.push_back(sensor);
|
||||||
|
PrintTela("Sensor de corrente adicionado via CAN: sCOR_" + String(idNum));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
||||||
} else {
|
} else {
|
||||||
if (existente) {
|
if (jaExiste) {
|
||||||
SensorCorrente* sensor = *it;
|
sensor = *it;
|
||||||
sensor->Desligar();
|
sensor->Desligar();
|
||||||
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
||||||
delete sensor;
|
delete sensor;
|
||||||
|
|
|
||||||
|
|
@ -159,25 +159,34 @@ std::vector<uint8_t> SensorFluxo::ConfigurarSensor(std::vector<SensorFluxo*>& li
|
||||||
if (data.size() < 3) return status;
|
if (data.size() < 3) return status;
|
||||||
uint8_t idNum = data[1];
|
uint8_t idNum = data[1];
|
||||||
CanMessagePosicaoDados posicao = (CanMessagePosicaoDados)data[2];
|
CanMessagePosicaoDados posicao = (CanMessagePosicaoDados)data[2];
|
||||||
|
auto it = std::find_if(lista.begin(), lista.end(), [idNum](SensorFluxo* s) { return s->ID_Num == idNum; });
|
||||||
|
bool jaExiste = it != lista.end();
|
||||||
|
SensorFluxo* sensor;
|
||||||
switch (posicao) {
|
switch (posicao) {
|
||||||
case CanMessagePosicaoDados::Config1: {
|
case CanMessagePosicaoDados::Config1: {
|
||||||
if (data.size() < 6) return status;
|
if (data.size() < 6) return status;
|
||||||
bool conectar = data[4] == 1;
|
bool conectar = data[4] == 1;
|
||||||
int pino = data[5];
|
int pino = data[5];
|
||||||
auto it = std::find_if(lista.begin(), lista.end(), [idNum](SensorFluxo* s) { return s->ID_Num == idNum; });
|
|
||||||
if (conectar) {
|
if (conectar) {
|
||||||
if (it == lista.end()) {
|
if (!jaExiste) {
|
||||||
SensorFluxo* sensor = new SensorFluxo(Mod_ID, "sFLX_" + String(idNum));
|
sensor = new SensorFluxo(Mod_ID, "sFLX_" + String(idNum));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sensor = *it;
|
||||||
|
}
|
||||||
|
if (!sensor->Iniciado) {
|
||||||
sensor->ID_Num = idNum;
|
sensor->ID_Num = idNum;
|
||||||
sensor->_pino = PinoModel(pino, CONTROLADOR, _INPUT, DIGITAL);
|
sensor->_pino = PinoModel(pino, CONTROLADOR, _INPUT, DIGITAL);
|
||||||
sensor->Inicializar();
|
sensor->Inicializar();
|
||||||
lista.push_back(sensor);
|
if (!jaExiste) {
|
||||||
PrintTela("Sensor de Fluxo adicionado via CAN: sFLX_" + String(idNum));
|
lista.push_back(sensor);
|
||||||
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
PrintTela("Sensor de Fluxo adicionado via CAN: sFLX_" + String(idNum));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
||||||
} else {
|
} else {
|
||||||
if (it != lista.end()) {
|
if (jaExiste) {
|
||||||
SensorFluxo* sensor = *it;
|
sensor = *it;
|
||||||
sensor->Desligar();
|
sensor->Desligar();
|
||||||
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
||||||
delete sensor;
|
delete sensor;
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@ class SensorIMU {
|
||||||
String _ID;
|
String _ID;
|
||||||
int ID_Num;
|
int ID_Num;
|
||||||
bool Iniciado = false;
|
bool Iniciado = false;
|
||||||
|
bool MpuIniciado = false;
|
||||||
|
bool BmpIniciado = false;
|
||||||
|
|
||||||
// Endereços I2C
|
// Endereços I2C
|
||||||
byte _EnderecoMPU; // 0x68
|
byte _EnderecoMPU; // 0x68
|
||||||
|
|
@ -53,22 +55,26 @@ class SensorIMU {
|
||||||
}
|
}
|
||||||
|
|
||||||
mpu = new MPU9250_WE(_EnderecoMPU);
|
mpu = new MPU9250_WE(_EnderecoMPU);
|
||||||
if (!mpu->init()) {
|
MpuIniciado = mpu->init();
|
||||||
|
if (!MpuIniciado) {
|
||||||
PrintTela("MPU9250 nao encontrado no endereco " + String(_EnderecoMPU));
|
PrintTela("MPU9250 nao encontrado no endereco " + String(_EnderecoMPU));
|
||||||
Iniciado = false;
|
delete mpu;
|
||||||
|
mpu = nullptr;
|
||||||
//return;
|
//return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mpu->autoOffsets();
|
if (MpuIniciado) {
|
||||||
mpu->setSampleRateDivider(5);
|
mpu->autoOffsets();
|
||||||
mpu->setAccRange(MPU9250_ACC_RANGE_2G);
|
mpu->setSampleRateDivider(5);
|
||||||
mpu->enableAccDLPF(true);
|
mpu->setAccRange(MPU9250_ACC_RANGE_2G);
|
||||||
mpu->setAccDLPF(MPU9250_DLPF_6);
|
mpu->enableAccDLPF(true);
|
||||||
|
mpu->setAccDLPF(MPU9250_DLPF_6);
|
||||||
|
}
|
||||||
|
|
||||||
if (!bmp.begin(_EnderecoBMP)) {
|
BmpIniciado = bmp.begin(_EnderecoBMP);
|
||||||
|
if (!BmpIniciado) {
|
||||||
PrintTela("BMP280 nao encontrado no endereco " + String(_EnderecoBMP));
|
PrintTela("BMP280 nao encontrado no endereco " + String(_EnderecoBMP));
|
||||||
Iniciado = false;
|
//return;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,
|
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,
|
||||||
|
|
@ -79,10 +85,11 @@ class SensorIMU {
|
||||||
|
|
||||||
filter.begin(100); // 100 Hz
|
filter.begin(100); // 100 Hz
|
||||||
|
|
||||||
xTaskCreatePinnedToCore(&SensorIMU::IMUTaskWrapper, "IMUTask", 5000, this, 20, &IMUTaskHandle, tskNO_AFFINITY);
|
Iniciado = MpuIniciado || BmpIniciado;
|
||||||
|
if (Iniciado) {
|
||||||
Iniciado = true;
|
xTaskCreatePinnedToCore(&SensorIMU::IMUTaskWrapper, "IMUTask", 5000, this, 20, &IMUTaskHandle, tskNO_AFFINITY);
|
||||||
PrintTela(_ID + " iniciado");
|
PrintTela(_ID + " iniciado");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Desligar() {
|
void Desligar() {
|
||||||
|
|
@ -91,8 +98,10 @@ class SensorIMU {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete mpu;
|
if (mpu != nullptr) {
|
||||||
mpu = nullptr;
|
delete mpu;
|
||||||
|
mpu = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
// Parar a execução das tarefas
|
// Parar a execução das tarefas
|
||||||
if (IMUTaskHandle != NULL) {
|
if (IMUTaskHandle != NULL) {
|
||||||
|
|
@ -198,38 +207,42 @@ class SensorIMU {
|
||||||
while (1) {
|
while (1) {
|
||||||
if (Iniciado) {
|
if (Iniciado) {
|
||||||
AferirDados();
|
AferirDados();
|
||||||
vTaskDelay(pdMS_TO_TICKS(10)); // 10ms → 100 Hz
|
|
||||||
}
|
}
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(10)); // 10ms → 100 Hz
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AferirDados() {
|
void AferirDados() {
|
||||||
if (!Iniciado) return;
|
if (!Iniciado) return;
|
||||||
|
|
||||||
xyzFloat acc = mpu->getGValues();
|
if (MpuIniciado && mpu != nullptr) {
|
||||||
xyzFloat gyr = mpu->getGyrValues();
|
xyzFloat acc = mpu->getGValues();
|
||||||
xyzFloat mag = mpu->getMagValues();
|
xyzFloat gyr = mpu->getGyrValues();
|
||||||
|
xyzFloat mag = mpu->getMagValues();
|
||||||
|
|
||||||
AccX = acc.x;
|
AccX = acc.x;
|
||||||
AccY = acc.y;
|
AccY = acc.y;
|
||||||
AccZ = acc.z;
|
AccZ = acc.z;
|
||||||
|
|
||||||
GyroX = gyr.x;
|
GyroX = gyr.x;
|
||||||
GyroY = gyr.y;
|
GyroY = gyr.y;
|
||||||
GyroZ = gyr.z;
|
GyroZ = gyr.z;
|
||||||
|
|
||||||
MagX = mag.x;
|
MagX = mag.x;
|
||||||
MagY = mag.y;
|
MagY = mag.y;
|
||||||
MagZ = mag.z;
|
MagZ = mag.z;
|
||||||
|
|
||||||
Temp = bmp.readTemperature();
|
filter.update(GyroX, GyroY, GyroZ, AccX, AccY, AccZ, MagX, MagY, MagZ);
|
||||||
Pressao = bmp.readPressure();
|
Roll = filter.getRoll();
|
||||||
Altitude = bmp.readAltitude();
|
Pitch = filter.getPitch();
|
||||||
|
Yaw = filter.getYaw();
|
||||||
|
}
|
||||||
|
|
||||||
filter.update(GyroX, GyroY, GyroZ, AccX, AccY, AccZ, MagX, MagY, MagZ);\
|
if (BmpIniciado) {
|
||||||
Roll = filter.getRoll();
|
Temp = bmp.readTemperature();
|
||||||
Pitch = filter.getPitch();
|
Pressao = bmp.readPressure();
|
||||||
Yaw = filter.getYaw();
|
Altitude = bmp.readAltitude();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -239,34 +252,36 @@ std::vector<uint8_t> SensorIMU::ConfigurarSensor(std::vector<SensorIMU*>& lista,
|
||||||
if (data.size() < 3) return status;
|
if (data.size() < 3) return status;
|
||||||
uint8_t idNum = data[1];
|
uint8_t idNum = data[1];
|
||||||
CanMessagePosicaoDados posicao = (CanMessagePosicaoDados)data[2];
|
CanMessagePosicaoDados posicao = (CanMessagePosicaoDados)data[2];
|
||||||
|
auto it = std::find_if(lista.begin(), lista.end(), [idNum](SensorIMU* s) { return s->ID_Num == idNum; });
|
||||||
|
bool jaExiste = it != lista.end();
|
||||||
|
SensorIMU* sensor;
|
||||||
switch (posicao) {
|
switch (posicao) {
|
||||||
case CanMessagePosicaoDados::Config1: {
|
case CanMessagePosicaoDados::Config1: {
|
||||||
if (data.size() < 7) return status;
|
if (data.size() < 7) return status;
|
||||||
bool conectar = data[4] == 1;
|
bool conectar = data[4] == 1;
|
||||||
uint8_t enderecoMpu = data[5];
|
uint8_t enderecoMpu = data[5];
|
||||||
uint8_t enderecoBmp = data[6];
|
uint8_t enderecoBmp = data[6];
|
||||||
auto it = std::find_if(lista.begin(), lista.end(), [idNum](SensorIMU* s) { return s->ID_Num == idNum; });
|
|
||||||
bool existente = (it != lista.end());
|
|
||||||
if (conectar) {
|
if (conectar) {
|
||||||
SensorIMU* sensor;
|
if (!jaExiste) {
|
||||||
if (!existente) {
|
|
||||||
sensor = new SensorIMU(Mod_ID, "sIMU_" + String(idNum));
|
sensor = new SensorIMU(Mod_ID, "sIMU_" + String(idNum));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sensor = *it;
|
sensor = *it;
|
||||||
}
|
}
|
||||||
sensor->ID_Num = idNum;
|
if (!sensor->Iniciado) {
|
||||||
sensor->_EnderecoMPU = enderecoMpu;
|
sensor->ID_Num = idNum;
|
||||||
sensor->_EnderecoBMP = enderecoBmp;
|
sensor->_EnderecoMPU = enderecoMpu;
|
||||||
sensor->Inicializar();
|
sensor->_EnderecoBMP = enderecoBmp;
|
||||||
if (!existente) {
|
sensor->Inicializar();
|
||||||
lista.push_back(sensor);
|
if (!jaExiste) {
|
||||||
PrintTela("Sensor IMU adicionado via CAN: sIMU_" + String(idNum));
|
lista.push_back(sensor);
|
||||||
|
PrintTela("Sensor IMU adicionado via CAN: sIMU_" + String(idNum));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
||||||
} else {
|
} else {
|
||||||
if (existente) {
|
if (jaExiste) {
|
||||||
SensorIMU* sensor = *it;
|
sensor = *it;
|
||||||
sensor->Desligar();
|
sensor->Desligar();
|
||||||
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
||||||
delete sensor;
|
delete sensor;
|
||||||
|
|
|
||||||
|
|
@ -122,6 +122,9 @@ std::vector<uint8_t> SensorMassa::ConfigurarSensor(std::vector<SensorMassa*>& li
|
||||||
if (data.size() < 3) return status;
|
if (data.size() < 3) return status;
|
||||||
uint8_t idNum = data[1];
|
uint8_t idNum = data[1];
|
||||||
CanMessagePosicaoDados posicao = (CanMessagePosicaoDados)data[2];
|
CanMessagePosicaoDados posicao = (CanMessagePosicaoDados)data[2];
|
||||||
|
auto it = std::find_if(lista.begin(), lista.end(), [idNum](SensorMassa* s) { return s->ID_Num == idNum; });
|
||||||
|
bool jaExiste = it != lista.end();
|
||||||
|
SensorMassa* sensor;
|
||||||
switch (posicao) {
|
switch (posicao) {
|
||||||
case CanMessagePosicaoDados::Config1: {
|
case CanMessagePosicaoDados::Config1: {
|
||||||
if (data.size() < 7) return status;
|
if (data.size() < 7) return status;
|
||||||
|
|
@ -130,22 +133,28 @@ std::vector<uint8_t> SensorMassa::ConfigurarSensor(std::vector<SensorMassa*>& li
|
||||||
int pinoSck = data[6];
|
int pinoSck = data[6];
|
||||||
//uint16_t offsetInt = ((uint16_t)data[6] << 8) | data[7];
|
//uint16_t offsetInt = ((uint16_t)data[6] << 8) | data[7];
|
||||||
//float offset = offsetInt / 100.0;
|
//float offset = offsetInt / 100.0;
|
||||||
auto it = std::find_if(lista.begin(), lista.end(), [idNum](SensorMassa* s) { return s->ID_Num == idNum; });
|
|
||||||
if (conectar) {
|
if (conectar) {
|
||||||
if (it == lista.end()) {
|
if (!jaExiste) {
|
||||||
SensorMassa* sensor = new SensorMassa(Mod_ID, "sMAS_" + String(idNum));
|
sensor = new SensorMassa(Mod_ID, "sMAS_" + String(idNum));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sensor = *it;
|
||||||
|
}
|
||||||
|
if (!sensor->Iniciado) {
|
||||||
sensor->ID_Num = idNum;
|
sensor->ID_Num = idNum;
|
||||||
sensor->_pinoDT = PinoModel(pinoDt, CONTROLADOR, _INPUT, DIGITAL);
|
sensor->_pinoDT = PinoModel(pinoDt, CONTROLADOR, _INPUT, DIGITAL);
|
||||||
sensor->_pinoSCK = PinoModel(pinoSck, CONTROLADOR, _OUTPUT);
|
sensor->_pinoSCK = PinoModel(pinoSck, CONTROLADOR, _OUTPUT);
|
||||||
//sensor->_Offset = offset;
|
//sensor->_Offset = offset;
|
||||||
sensor->Inicializar();
|
sensor->Inicializar();
|
||||||
lista.push_back(sensor);
|
if (!jaExiste) {
|
||||||
PrintTela("Sensor de Massa adicionado via CAN: sMAS_" + String(idNum));
|
lista.push_back(sensor);
|
||||||
|
PrintTela("Sensor de Massa adicionado via CAN: sMAS_" + String(idNum));
|
||||||
|
}
|
||||||
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (it != lista.end()) {
|
if (jaExiste) {
|
||||||
SensorMassa* sensor = *it;
|
sensor = *it;
|
||||||
sensor->Desligar();
|
sensor->Desligar();
|
||||||
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
||||||
delete sensor;
|
delete sensor;
|
||||||
|
|
|
||||||
|
|
@ -110,25 +110,34 @@ std::vector<uint8_t> SensorPressao::ConfigurarSensor(std::vector<SensorPressao*>
|
||||||
if (data.size() < 3) return status;
|
if (data.size() < 3) return status;
|
||||||
uint8_t idNum = data[1];
|
uint8_t idNum = data[1];
|
||||||
CanMessagePosicaoDados posicao = (CanMessagePosicaoDados)data[2];
|
CanMessagePosicaoDados posicao = (CanMessagePosicaoDados)data[2];
|
||||||
|
auto it = std::find_if(lista.begin(), lista.end(), [idNum](SensorPressao* s) { return s->ID_Num == idNum; });
|
||||||
|
bool jaExiste = it != lista.end();
|
||||||
|
SensorPressao* sensor;
|
||||||
switch (posicao) {
|
switch (posicao) {
|
||||||
case CanMessagePosicaoDados::Config1: {
|
case CanMessagePosicaoDados::Config1: {
|
||||||
if (data.size() < 6) return status;
|
if (data.size() < 6) return status;
|
||||||
bool conectar = data[4] == 1;
|
bool conectar = data[4] == 1;
|
||||||
int pino = data[5];
|
int pino = data[5];
|
||||||
auto it = std::find_if(lista.begin(), lista.end(), [idNum](SensorPressao* s) { return s->ID_Num == idNum; });
|
|
||||||
if (conectar) {
|
if (conectar) {
|
||||||
if (it == lista.end()) {
|
if (!jaExiste) {
|
||||||
SensorPressao* sensor = new SensorPressao(Mod_ID, "sPRS_" + String(idNum));
|
sensor = new SensorPressao(Mod_ID, "sPRS_" + String(idNum));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sensor = *it;
|
||||||
|
}
|
||||||
|
if (!sensor->Iniciado) {
|
||||||
sensor->ID_Num = idNum;
|
sensor->ID_Num = idNum;
|
||||||
sensor->_pino = PinoModel(pino, CONTROLADOR, _INPUT, ANALOGICO);
|
sensor->_pino = PinoModel(pino, CONTROLADOR, _INPUT, ANALOGICO);
|
||||||
sensor->Inicializar();
|
sensor->Inicializar();
|
||||||
lista.push_back(sensor);
|
if (!jaExiste) {
|
||||||
PrintTela("Sensor de Pressao adicionado via CAN: sPRS_" + String(idNum));
|
lista.push_back(sensor);
|
||||||
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
PrintTela("Sensor de Pressao adicionado via CAN: sPRS_" + String(idNum));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
||||||
} else {
|
} else {
|
||||||
if (it != lista.end()) {
|
if (jaExiste) {
|
||||||
SensorPressao* sensor = *it;
|
sensor = *it;
|
||||||
sensor->Desligar();
|
sensor->Desligar();
|
||||||
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
||||||
delete sensor;
|
delete sensor;
|
||||||
|
|
|
||||||
|
|
@ -125,28 +125,35 @@ std::vector<uint8_t> SensorTemperatura::ConfigurarSensor(std::vector<SensorTempe
|
||||||
if (data.size() < 3) return status;
|
if (data.size() < 3) return status;
|
||||||
uint8_t idNum = data[1];
|
uint8_t idNum = data[1];
|
||||||
CanMessagePosicaoDados posicao = (CanMessagePosicaoDados)data[2];
|
CanMessagePosicaoDados posicao = (CanMessagePosicaoDados)data[2];
|
||||||
|
auto it = std::find_if(lista.begin(), lista.end(), [idNum](SensorTemperatura* s) { return s->ID_Num == idNum; });
|
||||||
|
bool jaExiste = it != lista.end();
|
||||||
|
SensorTemperatura* sensor;
|
||||||
switch (posicao) {
|
switch (posicao) {
|
||||||
case CanMessagePosicaoDados::Config1: {
|
case CanMessagePosicaoDados::Config1: {
|
||||||
if (data.size() < 7) return status;
|
if (data.size() < 7) return status;
|
||||||
bool conectar = data[4] == 1;
|
bool conectar = data[4] == 1;
|
||||||
TiposBarramentos tipoBarramento = (TiposBarramentos)data[5];
|
TiposBarramentos tipoBarramento = (TiposBarramentos)data[5];
|
||||||
int pino = data[6];
|
int pino = data[6];
|
||||||
// Verifica se sensor já existe
|
|
||||||
auto it = std::find_if(lista.begin(), lista.end(), [idNum](SensorTemperatura* s) { return s->ID_Num == idNum; });
|
|
||||||
if (conectar) {
|
if (conectar) {
|
||||||
if (it == lista.end()) {
|
if (!jaExiste) {
|
||||||
SensorTemperatura* sensor = new SensorTemperatura(Mod_ID, "sTMP_" + String(idNum));
|
sensor = new SensorTemperatura(Mod_ID, "sTMP_" + String(idNum));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sensor = *it;
|
||||||
|
}
|
||||||
|
if (!sensor->Iniciado) {
|
||||||
sensor->ID_Num = idNum;
|
sensor->ID_Num = idNum;
|
||||||
sensor->_pino = PinoModel(pino, tipoBarramento, _INPUT, ANALOGICO);
|
sensor->_pino = PinoModel(pino, tipoBarramento, _INPUT, ANALOGICO);
|
||||||
sensor->Inicializar();
|
sensor->Inicializar();
|
||||||
lista.push_back(sensor);
|
if (!jaExiste) {
|
||||||
PrintTela("Sensor de temperatura adicionado via CAN: sTMP_" + String(idNum));
|
lista.push_back(sensor);
|
||||||
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
PrintTela("Sensor de temperatura adicionado via CAN: sTMP_" + String(idNum));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
||||||
} else {
|
} else {
|
||||||
// Desconectar sensor
|
if (jaExiste) {
|
||||||
if (it != lista.end()) {
|
sensor = *it;
|
||||||
SensorTemperatura* sensor = *it;
|
|
||||||
sensor->Desligar();
|
sensor->Desligar();
|
||||||
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
||||||
delete sensor;
|
delete sensor;
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,9 @@ std::vector<uint8_t> ServoFreio::ConfigurarServo(std::vector<ServoFreio*>& lista
|
||||||
if (data.size() < 3) return status;
|
if (data.size() < 3) return status;
|
||||||
uint8_t idNum = data[1];
|
uint8_t idNum = data[1];
|
||||||
CanMessagePosicaoDados posicao = (CanMessagePosicaoDados)data[2];
|
CanMessagePosicaoDados posicao = (CanMessagePosicaoDados)data[2];
|
||||||
|
auto it = std::find_if(lista.begin(), lista.end(), [idNum](ServoFreio* s) { return s->ID_Num == idNum; });
|
||||||
|
bool jaExiste = it != lista.end();
|
||||||
|
ServoFreio* sensor;
|
||||||
switch (posicao) {
|
switch (posicao) {
|
||||||
case CanMessagePosicaoDados::Config1: {
|
case CanMessagePosicaoDados::Config1: {
|
||||||
if (data.size() < 8) return status;
|
if (data.size() < 8) return status;
|
||||||
|
|
@ -111,21 +114,27 @@ std::vector<uint8_t> ServoFreio::ConfigurarServo(std::vector<ServoFreio*>& lista
|
||||||
bool incremental = data[5] == 1;
|
bool incremental = data[5] == 1;
|
||||||
TiposBarramentos tipoBarramento = (TiposBarramentos)data[6];
|
TiposBarramentos tipoBarramento = (TiposBarramentos)data[6];
|
||||||
int pino = data[7];
|
int pino = data[7];
|
||||||
auto it = std::find_if(lista.begin(), lista.end(), [idNum](ServoFreio* s) { return s->ID_Num == idNum; });
|
|
||||||
if (conectar) {
|
if (conectar) {
|
||||||
if (it == lista.end()) {
|
if (!jaExiste) {
|
||||||
ServoFreio* sensor = new ServoFreio(Mod_ID, "sFRO_" + String(idNum));
|
sensor = new ServoFreio(Mod_ID, "sFRO_" + String(idNum));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sensor = *it;
|
||||||
|
}
|
||||||
|
if (!sensor->Iniciado) {
|
||||||
sensor->ID_Num = idNum;
|
sensor->ID_Num = idNum;
|
||||||
sensor->Incremental = incremental;
|
sensor->Incremental = incremental;
|
||||||
sensor->_pino = PinoModel(pino, tipoBarramento, _OUTPUT);
|
sensor->_pino = PinoModel(pino, tipoBarramento, _OUTPUT);
|
||||||
sensor->Inicializar();
|
sensor->Inicializar();
|
||||||
lista.push_back(sensor);
|
if (!jaExiste) {
|
||||||
PrintTela("Servo Freio adicionado via CAN: sFRO_" + String(idNum));
|
lista.push_back(sensor);
|
||||||
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
PrintTela("Servo Freio adicionado via CAN: sFRO_" + String(idNum));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
||||||
} else {
|
} else {
|
||||||
if (it != lista.end()) {
|
if (jaExiste) {
|
||||||
ServoFreio* sensor = *it;
|
sensor = *it;
|
||||||
sensor->Desligar();
|
sensor->Desligar();
|
||||||
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
||||||
delete sensor;
|
delete sensor;
|
||||||
|
|
|
||||||
|
|
@ -148,26 +148,35 @@ std::vector<uint8_t> Sinaleiro::ConfigurarSinaleiro(std::vector<Sinaleiro*>& lis
|
||||||
if (data.size() < 3) return status;
|
if (data.size() < 3) return status;
|
||||||
uint8_t idNum = data[1];
|
uint8_t idNum = data[1];
|
||||||
CanMessagePosicaoDados posicao = (CanMessagePosicaoDados)data[2];
|
CanMessagePosicaoDados posicao = (CanMessagePosicaoDados)data[2];
|
||||||
|
auto it = std::find_if(lista.begin(), lista.end(), [idNum](Sinaleiro* s) { return s->ID_Num == idNum; });
|
||||||
|
bool jaExiste = it != lista.end();
|
||||||
|
Sinaleiro* sensor;
|
||||||
switch (posicao) {
|
switch (posicao) {
|
||||||
case CanMessagePosicaoDados::Config1: {
|
case CanMessagePosicaoDados::Config1: {
|
||||||
if (data.size() < 7) return status;
|
if (data.size() < 7) return status;
|
||||||
bool conectar = data[4] == 1;
|
bool conectar = data[4] == 1;
|
||||||
TiposBarramentos tipoBarramento = (TiposBarramentos)data[5];
|
TiposBarramentos tipoBarramento = (TiposBarramentos)data[5];
|
||||||
int pino = data[6];
|
int pino = data[6];
|
||||||
auto it = std::find_if(lista.begin(), lista.end(), [idNum](Sinaleiro* s) { return s->ID_Num == idNum; });
|
|
||||||
if (conectar) {
|
if (conectar) {
|
||||||
if (it == lista.end()) {
|
if (!jaExiste) {
|
||||||
Sinaleiro* sensor = new Sinaleiro(Mod_ID, "sLED_" + String(idNum));
|
sensor = new Sinaleiro(Mod_ID, "sLED_" + String(idNum));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sensor = *it;
|
||||||
|
}
|
||||||
|
if (!sensor->Iniciado) {
|
||||||
sensor->ID_Num = idNum;
|
sensor->ID_Num = idNum;
|
||||||
sensor->_pino = PinoModel(pino, tipoBarramento, _OUTPUT);
|
sensor->_pino = PinoModel(pino, tipoBarramento, _OUTPUT);
|
||||||
sensor->Inicializar();
|
sensor->Inicializar();
|
||||||
lista.push_back(sensor);
|
if (!jaExiste) {
|
||||||
PrintTela("Sinaleiro adicionado via CAN: sLED_" + String(idNum));
|
lista.push_back(sensor);
|
||||||
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
PrintTela("Sinaleiro adicionado via CAN: sLED_" + String(idNum));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
||||||
} else {
|
} else {
|
||||||
if (it != lista.end()) {
|
if (jaExiste) {
|
||||||
Sinaleiro* sensor = *it;
|
sensor = *it;
|
||||||
sensor->Desligar();
|
sensor->Desligar();
|
||||||
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
|
||||||
delete sensor;
|
delete sensor;
|
||||||
|
|
|
||||||
|
|
@ -28,11 +28,13 @@ String Mod_ID = "Sen";
|
||||||
#define _pinoLED RGB_BUILTIN
|
#define _pinoLED RGB_BUILTIN
|
||||||
|
|
||||||
bool Conectado = false;
|
bool Conectado = false;
|
||||||
bool Verificando = false;
|
bool Conectar = false;
|
||||||
|
|
||||||
int _TaxaAmostragem = 1000;
|
int _TaxaAmostragem = 1000;
|
||||||
volatile bool RequisitarDados = false;
|
volatile bool RequisitarDados = false;
|
||||||
int latenciaLoop = 0;
|
int latenciaLoop = 0;
|
||||||
|
int qtdEnviosStatus = 0;
|
||||||
|
int maxEnviosStatus = 5;
|
||||||
|
|
||||||
PinoModel _pinoSDA = PinoModel(1, CONTROLADOR, _INPUT);
|
PinoModel _pinoSDA = PinoModel(1, CONTROLADOR, _INPUT);
|
||||||
PinoModel _pinoSCL = PinoModel(2, CONTROLADOR, _INPUT);
|
PinoModel _pinoSCL = PinoModel(2, CONTROLADOR, _INPUT);
|
||||||
|
|
@ -94,12 +96,17 @@ void enviarLogsPeriodicamente() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void enviarDadosSensores() {
|
void enviarDadosSensores() {
|
||||||
if (Conectado && !Verificando) {
|
if (Conectado) {
|
||||||
PrintTela("Atualizando dados dos sensores...");
|
PrintTela("Atualizando dados dos sensores...");
|
||||||
|
|
||||||
|
bool enviarStatus = qtdEnviosStatus >= maxEnviosStatus;
|
||||||
|
|
||||||
for (auto* sensor : listaSensoresTemperatura) {
|
for (auto* sensor : listaSensoresTemperatura) {
|
||||||
if (sensor != nullptr) {
|
if (sensor != nullptr) {
|
||||||
sensor->RequisitarDados();
|
sensor->RequisitarDados();
|
||||||
|
if (enviarStatus) {
|
||||||
|
EnviarDadosCAN(sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status));
|
||||||
|
}
|
||||||
EnviarDadosCAN(sensor->MontarMensagemCAN(CanMessagePosicaoDados::Dados1));
|
EnviarDadosCAN(sensor->MontarMensagemCAN(CanMessagePosicaoDados::Dados1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -107,6 +114,9 @@ void enviarDadosSensores() {
|
||||||
for (auto* sensor : listaSensoresCorrente) {
|
for (auto* sensor : listaSensoresCorrente) {
|
||||||
if (sensor != nullptr) {
|
if (sensor != nullptr) {
|
||||||
sensor->RequisitarDados();
|
sensor->RequisitarDados();
|
||||||
|
if (enviarStatus) {
|
||||||
|
EnviarDadosCAN(sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status));
|
||||||
|
}
|
||||||
EnviarDadosCAN(sensor->MontarMensagemCAN(CanMessagePosicaoDados::Dados1));
|
EnviarDadosCAN(sensor->MontarMensagemCAN(CanMessagePosicaoDados::Dados1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -114,6 +124,9 @@ void enviarDadosSensores() {
|
||||||
for (auto* sensor : listaSinaleiros) {
|
for (auto* sensor : listaSinaleiros) {
|
||||||
if (sensor != nullptr) {
|
if (sensor != nullptr) {
|
||||||
sensor->RequisitarDados();
|
sensor->RequisitarDados();
|
||||||
|
if (enviarStatus) {
|
||||||
|
EnviarDadosCAN(sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status));
|
||||||
|
}
|
||||||
EnviarDadosCAN(sensor->MontarMensagemCAN(CanMessagePosicaoDados::Dados1));
|
EnviarDadosCAN(sensor->MontarMensagemCAN(CanMessagePosicaoDados::Dados1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -121,6 +134,9 @@ void enviarDadosSensores() {
|
||||||
for (auto* sensor : listaReles) {
|
for (auto* sensor : listaReles) {
|
||||||
if (sensor != nullptr) {
|
if (sensor != nullptr) {
|
||||||
sensor->RequisitarDados();
|
sensor->RequisitarDados();
|
||||||
|
if (enviarStatus) {
|
||||||
|
EnviarDadosCAN(sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status));
|
||||||
|
}
|
||||||
EnviarDadosCAN(sensor->MontarMensagemCAN(CanMessagePosicaoDados::Dados1));
|
EnviarDadosCAN(sensor->MontarMensagemCAN(CanMessagePosicaoDados::Dados1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -128,6 +144,9 @@ void enviarDadosSensores() {
|
||||||
for (auto* sensor : listaServoFreios) {
|
for (auto* sensor : listaServoFreios) {
|
||||||
if (sensor != nullptr) {
|
if (sensor != nullptr) {
|
||||||
sensor->RequisitarDados();
|
sensor->RequisitarDados();
|
||||||
|
if (enviarStatus) {
|
||||||
|
EnviarDadosCAN(sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status));
|
||||||
|
}
|
||||||
EnviarDadosCAN(sensor->MontarMensagemCAN(CanMessagePosicaoDados::Dados1));
|
EnviarDadosCAN(sensor->MontarMensagemCAN(CanMessagePosicaoDados::Dados1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -135,11 +154,20 @@ void enviarDadosSensores() {
|
||||||
for (auto* sensor : listaSensoresIMU) {
|
for (auto* sensor : listaSensoresIMU) {
|
||||||
if (sensor != nullptr) {
|
if (sensor != nullptr) {
|
||||||
sensor->RequisitarDados();
|
sensor->RequisitarDados();
|
||||||
|
if (enviarStatus) {
|
||||||
|
EnviarDadosCAN(sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status));
|
||||||
|
}
|
||||||
EnviarDadosCAN(sensor->MontarMensagemCAN(CanMessagePosicaoDados::Dados1));
|
EnviarDadosCAN(sensor->MontarMensagemCAN(CanMessagePosicaoDados::Dados1));
|
||||||
EnviarDadosCAN(sensor->MontarMensagemCAN(CanMessagePosicaoDados::Dados2));
|
EnviarDadosCAN(sensor->MontarMensagemCAN(CanMessagePosicaoDados::Dados2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (enviarStatus) {
|
||||||
|
qtdEnviosStatus = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
qtdEnviosStatus++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -165,10 +193,8 @@ void ProcessarFrameCAN(std::vector<uint8_t> data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessarChk() {
|
void ProcessarChk() {
|
||||||
Verificando = true;
|
|
||||||
std::vector<uint8_t> data = canService.MontarFrameChk(D_Code, Conectado, VERSION);
|
std::vector<uint8_t> data = canService.MontarFrameChk(D_Code, Conectado, VERSION);
|
||||||
EnviarDadosCAN(data);
|
EnviarDadosCAN(data);
|
||||||
Verificando = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessarReq() {
|
void ProcessarReq() {
|
||||||
|
|
@ -191,7 +217,7 @@ void ProcessarCfg(std::vector<uint8_t> data) {
|
||||||
bool requisitar = data[6] == 1;
|
bool requisitar = data[6] == 1;
|
||||||
_TaxaAmostragem = taxa;
|
_TaxaAmostragem = taxa;
|
||||||
RequisitarDados = requisitar;
|
RequisitarDados = requisitar;
|
||||||
Conectado = conectar;
|
Conectar = conectar;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CanMessagePosicaoDados::Config2: {
|
case CanMessagePosicaoDados::Config2: {
|
||||||
|
|
@ -206,9 +232,9 @@ void ProcessarCfg(std::vector<uint8_t> data) {
|
||||||
PrintTela("I2C inicializado nos pinos SDA=" + String(pinoSDA) + " e SCL=" + String(pinoSCL));
|
PrintTela("I2C inicializado nos pinos SDA=" + String(pinoSDA) + " e SCL=" + String(pinoSCL));
|
||||||
}
|
}
|
||||||
vTaskDelay(pdMS_TO_TICKS(100));
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
Verificando = false;
|
|
||||||
_chkRx = canService.MontarFrameChk(D_Code, Conectado, VERSION);
|
_chkRx = canService.MontarFrameChk(D_Code, Conectado, VERSION);
|
||||||
LimparListasComponentes();
|
LimparListasComponentes();
|
||||||
|
Conectado = Conectar;
|
||||||
PrintTela("Configuracao do modulo concluida");
|
PrintTela("Configuracao do modulo concluida");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -234,6 +260,7 @@ void ProcessarCfg(std::vector<uint8_t> data) {
|
||||||
case sFRO: {
|
case sFRO: {
|
||||||
_chkRx = ServoFreio::ConfigurarServo(listaServoFreios, data, Mod_ID);
|
_chkRx = ServoFreio::ConfigurarServo(listaServoFreios, data, Mod_ID);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
case sIMU: {
|
case sIMU: {
|
||||||
_chkRx = SensorIMU::ConfigurarSensor(listaSensoresIMU, data, Mod_ID);
|
_chkRx = SensorIMU::ConfigurarSensor(listaSensoresIMU, data, Mod_ID);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue