示例#1
0
        public static void ForceReplyCheckingFota(this IMessage msg, bool canappend, IFoteable dev)
        {
            if ((msg == null) || !canappend)
            {
                return;
            }

            var pending = Fota.Peek(dev);

            if (!String.IsNullOrEmpty(pending))
            {
                var lmid = dev.GetMessageId(pending);
                if (pending.Contains("///;#"))
                {
                    pending = pending.Substring(0, pending.IndexOf("///;#"));
                }

                var lastmsg = dev.LastSent.GetText(null);
                STrace.Debug(typeof(UnexUtils).FullName, dev.GetDeviceId(), String.Format("ForceReplyCheckingFota 2: lastmsg={0} pending={1}", lastmsg, pending));
                if (lastmsg != pending)
                {
                    dev.LastSent = new INodeMessage(lmid, pending, DateTime.UtcNow);
                }
                msg.AddStringToSend(pending);
            }
            else
            {
                //HACK: si no le respondo algo a estos equipos se cuelgan un rato y pasan a estar en amarillo
                if (String.IsNullOrEmpty(msg.GetPendingAsString()))
                {
                    msg.AddStringToSend("B");
                }
            }
        }
示例#2
0
文件: Fota.cs 项目: jesumarquez/lt
        public static void EnqueueOnTheFly(IFoteable Device, ulong MessageId, BaseDeviceCommand[] arrCmds, ref IMessage msg)
        {
            var reversed = arrCmds.Reverse();

            var commands = String.Join("", reversed.Select(bdc => bdc.ToString(false)).ToArray());

            var toSend    = reversed.Last();
            var toSendStr = toSend.ToString(true);

            if (msg != null)
            {
                msg.AddStringToSend(toSendStr);
            }

            if (Device.LastSent == null)
            {
                if (msg != null)
                {
                    Device.LastSent = new INodeMessage(toSend.MessageId ?? 0, toSendStr, DateTime.UtcNow);
                }
                EnqueuePrivate(Device, MessageId, commands, ".txR");
            }
            else
            {
                InsertAfterLastFotaCommand(Device, commands);
            }
        }
示例#3
0
        private bool CheckLastSentAndDequeueIt(String buffer, ulong msgId, ref IMessage salida)
        {
            var    result  = true;
            string LastCmd = LastSent.GetText(String.Empty);
            ulong  LastId  = LastSent.GetId();

            if (buffer.StartsWith(Reporte.SdLocked))
            {
                _sdSession = false;
                STrace.Debug(typeof(Parser).FullName, Id, "Sesion de escritura en sd BORRANDO_POR_LOCKED");
            }
            else if (buffer.StartsWith(Reporte.SdPassword))
            {
                //Debug.Assert(LastSent.IsOnTheFly() == true);
                if (LastCmd.StartsWith(Reporte.StartGgWriteSession) && (LastId == msgId))
                {
                    LastSent   = null;
                    _sdSession = true;
                    STrace.Debug(typeof(Parser).FullName, Id, "Sesion de escritura en sd ABIERTA");
                }
                else if (_sdSession)
                {
                    STrace.Debug(typeof(Parser).FullName, Id, "Sesion de escritura en sd NO_MANEJADO");
                }
                else if (LastId == msgId)
                {
                    ulong mid = NextSequence;


                    LastSent = new INodeMessage(mid,
                                                Mensaje.Factory(mid, this,
                                                                String.Format("{0}{1}",
                                                                              Reporte.StartGgWriteSession.TrimStart('>'),
                                                                              buffer.Substring(8, 8))),

                                                DateTime.MinValue)
                    {
                        IsOnTheFly = true
                    };

                    salida.AddStringToSend(LastSent.Text);

                    STrace.Debug(typeof(Parser).FullName, Id, "Sesion de escritura en sd ABRIENDO");
                }
                else
                {
                    STrace.Debug(typeof(Parser).FullName, Id,
                                 String.Format("Sesion de escritura en sd NADA (LastSent.GetId()={0} msgId={1})",
                                               LastSent.GetId(), msgId));
                }
            }
            else

            if (LastSent != null)
            {
                if (LastSent.IsExpired())
                {
                    LastSent = null;
                }
                else
                {
                    var lastDC     = BaseDeviceCommand.createFrom(LastCmd, this, null);
                    var respStatus = lastDC.isExpectedResponse(BaseDeviceCommand.createFrom(buffer, this, null));
                    switch (respStatus)
                    {
                    case DeviceCommandResponseStatus.Valid:
                        result = true;
                        Fota.Dequeue(this, lastDC.MessageId ?? null);
                        break;

                    case DeviceCommandResponseStatus.Invalid:
                        result = false;
                        break;

                    case DeviceCommandResponseStatus.Exception:
                        Fota.RollbackLastTransaction(this, lastDC.MessageId ?? null);
                        result = false;
                        break;
                    }
                }
            }
            return(result);
        }