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