コード例 #1
0
ファイル: Parser.cs プロジェクト: jesumarquez/lt
        public override INode Factory(IFrame frame, int formerId)
        {
            var dc = new VirlocDeviceCommand(frame.Payload);

            if (!dc.hasIdNum())
            {
                var imei = ExtractIMEI(dc);
                if (imei != null)
                {
                    return(DataProvider.FindByIMEI(imei, this));
                }
                return(null);
            }

            return(DataProvider.FindByIdNum(dc.IdNum.Value, this));
        }
コード例 #2
0
ファイル: Parser.cs プロジェクト: jesumarquez/lt
        public IMessage Decode(IFrame frame, GPSPoint.SourceProviders provider)
        {
            IMessage salida      = null;
            var      tipoReporte = Reporte.SinNodo;
            var      msgId       = ParserUtils.MsgIdNotSet;

            var dc = new VirlocDeviceCommand(frame.Payload, this);

            if (dc.isValid()) // && _askedIMEI != null)
            {
                tipoReporte = GetTipoReporte(dc);
            }

            if (dc.hasMessasgeId())
            {
                msgId = dc.MessageId ?? 0;
            }

            switch (tipoReporte)
            {
            case Reporte.Nada:
                return(null);

            case Reporte.EventoGL:
            case Reporte.EventoGP:
                salida = GetSalida(dc, provider);
                break;

            case Reporte.SinNodo:
                if (!GetTipoReporte(dc).StartsWith(Reporte.IMEIReq))
                {
                    var askIMEIcmd = new VirlocDeviceCommand(Mensajes.AskIMEI, this, null);
                    askIMEIcmd.IdNum = new VirlocDeviceCommand(frame.Payload, this).IdNum;
                    var askIMEIcmdStr = askIMEIcmd.ToString(true);

                    salida = new UserMessage(Id, dc.MessageId ?? 0);
                    salida.AddStringToSend(askIMEIcmdStr);
                }
                else
                {
                    salida = new ConfigRequest(Id, dc.MessageId ?? 0);
                    var imei = ExtractIMEI(dc);
                    if (imei != null)
                    {
                        _askedIMEI = imei;
                    }
                }
                break;
            }

            if (!Reporte.SinNodo.Equals(tipoReporte))
            {
                // Replying with ACK if needed
                if (dc.hasIdNum() && dc.hasMessasgeId() && !salida.IsPending())
                {
                    if (salida == null)
                    {
                        salida = new UserMessage(Id, msgId);
                    }

                    var ackStr = dc.BuildAck().ToString(true);
                    salida.AddStringToSend(ackStr);
                }

                CheckLastSentAndDequeueIt(dc);

                if (LastSent == null)  //&& !(new String[] {Reporte.IdReq}.Any(r=> tipoReporte == r)))
                {
                    SendPendingFota(ref salida);
                }
            }
            return(salida);
        }