216 lines
6.6 KiB
C#
216 lines
6.6 KiB
C#
using AgroBase.Services;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using static AgroBase.Models.Enums;
|
|
|
|
namespace AgroBase.Models
|
|
{
|
|
public class LoRaModel
|
|
{
|
|
}
|
|
|
|
public class LoRaParametrosModel
|
|
{
|
|
public DateTime UltimaLeitura { get; set; } = DateTime.MinValue;
|
|
public string PortaCOM
|
|
{
|
|
get
|
|
{
|
|
return LoRaService.PortaLoRa?.PortName ?? "";
|
|
}
|
|
}
|
|
public byte baudRate { get; set; }
|
|
public byte airRate { get; set; }
|
|
public byte baudAndAirRate
|
|
{
|
|
get
|
|
{
|
|
string _baudRate = Convert.ToInt32(baudRate.ToString("X")).ToString("00");
|
|
string _airRate = Convert.ToInt32(airRate.ToString("X")).ToString("00");
|
|
return Convert.ToByte(_baudRate[0].ToString() + _airRate[1].ToString(), 16);
|
|
}
|
|
}
|
|
public byte parity { get; set; }
|
|
public byte packetSize { get; set; }
|
|
public byte power { get; set; }
|
|
public byte packetSizeAndPower
|
|
{
|
|
get
|
|
{
|
|
string _packetSize = Convert.ToInt32(packetSize.ToString("X")).ToString("00");
|
|
string _power = Convert.ToInt32(power.ToString("X")).ToString("00");
|
|
return Convert.ToByte(_packetSize[0].ToString() + _power[1].ToString(), 16);
|
|
}
|
|
}
|
|
public byte tranMode { get; set; }
|
|
public byte worCycle { get; set; }
|
|
public byte tranModeAndWorCycle
|
|
{
|
|
get
|
|
{
|
|
string _tranMode = Convert.ToInt32(tranMode.ToString("X")).ToString("00");
|
|
string _worCycle = Convert.ToInt32(worCycle.ToString("X")).ToString("00");
|
|
return Convert.ToByte(_tranMode[0].ToString() + _worCycle[1].ToString(), 16);
|
|
}
|
|
}
|
|
public byte channelRssi { get; set; }
|
|
public byte lbt { get; set; }
|
|
public byte packetRssi { get; set; }
|
|
public byte address { get; set; }
|
|
public byte channel { get; set; }
|
|
public byte key { get; set; }
|
|
}
|
|
|
|
public class LoRaMensagemModel
|
|
{
|
|
public DateTime Momento { get; set; }
|
|
public byte channel { get; set; }
|
|
public byte Remetente { get; set; }
|
|
public byte Destinatario { get; set; }
|
|
public string Mensagem { get; set; }
|
|
public bool Lido { get; set; }
|
|
}
|
|
|
|
public class LoRaProtocoloModel
|
|
{
|
|
public List<byte> Cabecalho { get; set; }
|
|
public Dictionary<DateTime, List<byte>> Dados { get; set; }
|
|
public bool Parametrizacao
|
|
{
|
|
get
|
|
{
|
|
return Buffer[0] == LoRaService.CodigosFuncoes["RespostaConfiguracao"];
|
|
}
|
|
}
|
|
public byte[] Buffer
|
|
{
|
|
get
|
|
{
|
|
return Dados.SelectMany(x => x.Value).ToArray();
|
|
}
|
|
}
|
|
public byte Remtente
|
|
{
|
|
get
|
|
{
|
|
return Parametrizacao ? (byte)0 : Buffer[1];
|
|
}
|
|
}
|
|
public byte Destinatario
|
|
{
|
|
get
|
|
{
|
|
return Parametrizacao ? (byte)0 : Buffer[2];
|
|
}
|
|
}
|
|
public LoRaTipoProtocolo Tipo
|
|
{
|
|
get
|
|
{
|
|
return Parametrizacao ? LoRaTipoProtocolo.Parametrizacao : (LoRaTipoProtocolo)Buffer[3];
|
|
}
|
|
}
|
|
public string EmTexto
|
|
{
|
|
get
|
|
{
|
|
return Encoding.UTF8.GetString(Buffer);
|
|
}
|
|
}
|
|
public string Mensagem
|
|
{
|
|
get
|
|
{
|
|
if (Tipo == LoRaTipoProtocolo.MensagemTexto)
|
|
{
|
|
string msg = EmTexto.Replace(SerialService.BreakLine, "").Replace("\n", "");
|
|
|
|
int idxI = msg.Contains(SerialService.BeginLine) ? msg.IndexOf(SerialService.BeginLine) + 4 : 0;
|
|
int idxF = msg.Contains(SerialService.EndLine) ? msg.IndexOf(SerialService.EndLine) : msg.Length - 1;
|
|
int comprimento = idxF - idxI;
|
|
msg = msg.Substring(idxI, comprimento);
|
|
|
|
return msg;
|
|
}
|
|
return "";
|
|
}
|
|
}
|
|
private bool ComInicio
|
|
{
|
|
get
|
|
{
|
|
return EmTexto.Contains(SerialService.BeginLine);
|
|
}
|
|
}
|
|
private bool ComFim
|
|
{
|
|
get
|
|
{
|
|
return EmTexto.Contains(SerialService.EndLine);
|
|
}
|
|
}
|
|
public bool MensagemCompleta
|
|
{
|
|
get
|
|
{
|
|
return (ComInicio && ComFim) || Parametrizacao;
|
|
}
|
|
}
|
|
}
|
|
|
|
public class LoRaProtocoloTransmissaoModel
|
|
{
|
|
public DateTime Momento { get; set; }
|
|
public byte EnderecoCarro { get; set; }
|
|
public ulong CodigoFalha { get; set; }
|
|
public LoRaProtocoloTransmissaoCoordenadasModel Coordenadas { get; set; }
|
|
public LoRaProtocoloTransmissaoSensoresModel Sensores { get; set; }
|
|
public LoRaProtocoloTransmissaoOperacaoModel Operacao { get; set; }
|
|
}
|
|
|
|
public class LoRaProtocoloTransmissaoCoordenadasModel
|
|
{
|
|
public double Latitude { get; set; }
|
|
public double Longitude { get; set; }
|
|
public double Orientacao { get; set; }
|
|
}
|
|
|
|
public class LoRaProtocoloTransmissaoSensoresModel
|
|
{
|
|
public double PercentualBateria { get; set; }
|
|
public double PercentualReservatorio { get; set; }
|
|
public double PressaoLinha { get; set; }
|
|
public double DistanciaPercorrida { get; set; }
|
|
public double OrientacaoCaminho { get; set; }
|
|
public double Velocidade { get; set; }
|
|
public double ErvasIdentificadas { get; set; }
|
|
public double TemperaturaMotores { get; set; }
|
|
public double TemperaturaCampo { get; set; }
|
|
public double HerbicidaConsumido { get; set; }
|
|
public double HerbicidaPorErva { get; set; }
|
|
}
|
|
|
|
public class LoRaProtocoloTransmissaoOperacaoModel
|
|
{
|
|
public StatusOperacao statusOperacao { get; set; }
|
|
public StatusCarroMapa statusCarro { get; set; }
|
|
public int idxRuaAtual { get; set; }
|
|
public double PercentualOperacao { get; set; }
|
|
public double PercentualRua { get; set; }
|
|
public int TempoOperacao { get; set; }
|
|
public string TempoEstimado { get; set; }
|
|
}
|
|
|
|
public enum LoRaTipoProtocolo
|
|
{
|
|
Parametrizacao = 0x00,
|
|
MensagemTexto = 0x01,
|
|
DadosOperacao = 0x02,
|
|
PosicaoGPS = 0x03,
|
|
ComandoControle = 0x04,
|
|
}
|
|
|
|
}
|